[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH for-4.17?] x86/paging: return -EINVAL for paging domctls for dying domains


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Wed, 9 Nov 2022 11:11:57 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ZvHwybfxsS/d38r0gvYyenMA2OtvdTDhqZl9pHKjHbI=; b=jTYyYOM9Sbn/98HhuV6e/nI0RW5WKP/Z+BYOgtXaBJFc3Bw++dFCNqy7qPqbZrbg7KdkzjpPZB5zcoiUO8ivoFoLhDYRxolin8N7Qtr5+nLN7eDdB0V213KXuR73wz4VDS1UoZMQrrJIfbiJGed2N4y9SscJuTreX2p6XIgyCFJ6zh2qNCHXTZoD1U74FC73gci0LuShzwcYuQeHL7km1Ol7Vnx8gDeNEXZhqe/Hn/9GjpuBJnYDlsnIarXSeWCMOmjMk0b5GZY/53EqOLoZ53CdEuobI19DWRiKOFooRjKyxm0r7Yl7K8VwM3mj2dbUbpz4TXbd+4b26uoxhW8Kjg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Qxk0SBGx/Ld0DzCGzOLgKD0yPdKx/vxbWSThlZg5fUtG0toZeovZvpcvaBXvyaxp4qyIZivI0Pyt+/0Sh3ld35pgQbMN3D9WzFFno5Eb7X9rblJBxX/uIxTT570mEM/Lisax+NEUhHokP8/fnbP6tCtpsuB6L1WJDS7aE6L86fEVGGQ3+oAPfCZ+d/RIlrLDfpL0vpOEO1tJQ5fq1eTv4L5fbzBF6CcyU32rs6kZz6KRMHvw7WF+JHwXzM/2jOyZ6+qB7P6zihsGzWBPH+AOHl9o+XePB8NgohNZzOM/sXf4KcPoS1Jkgs+uH5TPyLqTMopqcH1ANZL0aibsaE1ZUg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Henry.Wang@xxxxxxx, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Edwin Török <edvin.torok@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Wed, 09 Nov 2022 10:12:13 +0000
  • Ironport-data: A9a23:kqzW06+K6LXIWVQymqidDrUDs3+TJUtcMsCJ2f8bNWPcYEJGY0x3x zZNCmCHPa7cN2byc9ojPdvlphkOuZTcy4c3GlQ5pS48E34SpcT7XtnIdU2Y0wF+jCHgZBk+s 5hBMImowOQcFCK0SsKFa+C5xZVE/fjUAOG6UKucYHsZqTZMEE8JkQhkl/MynrlmiN24BxLlk d7pqojUNUTNNwRcawr40Ire7kIx1BjOkGlA5AZnPKga5AW2e0Q9V/rzG4ngdxMUfaEMdgKKb 76r5K20+Grf4yAsBruN+losWhRXKlJ6FVHmZkt+A8BOsDAbzsAB+v9T2M4nQVVWk120c+VZk 72hg3ASpTABZcUgkMxFO/VR/roX0aduoNcrKlDn2SCfItGvn9IBDJyCAWlvVbD09NqbDklf0 acEBmgDSyqy2cbp3Zu4VdNOudkaeZyD0IM34hmMzBn/JNN/G9XpZfWP4tVVmjAtmspJAPDSI dIDbiZiZwjBZBsJPUoLDJU5n6GjgXyXnz9w8QrJ4/ZopTWOilUujdABM/KMEjCObd9SkUuC4 HrP4kzyAw0ANczZwj2Amp6prr+TwX6qCdpKfFG+3sZpoUeilkAvMTc1S2OauN21jW6xY80Kf iT4/QJr98De7neDTNPwQhm5q36spQMHVpxbFOhSwCGAzLDFpTmQAGcsRyRELtchsaceWjgCx lKP2dTzClRHoLCTDH6Q6LqQhTezIjQOa38PYzceSgkI6MWlp5s85i8jVf5mGa+xy9fzSTf5x mnQqDBk3upOy8kWy6+84FbLxSq2oYTERRI04QORWX+56gR+Z8iuYInABUXn0Mus5b2xFjGp1 EXoUeDHhAzSJflhTBCwfdg=
  • Ironport-hdrordr: A9a23:NiVrT6tSFxzIkVTvRQKWPq2t7skDeNV00zEX/kB9WHVpmszxra GTdZMgpHnJYVcqKRYdcL+7Scq9qB/nmqKdgrNhWYtKPjOW2ldARbsKheCJrlHd8kXFh5dgPM xbE5SWZuefMbEDt7ee3DWF
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Wed, Nov 09, 2022 at 08:48:46AM +0100, Jan Beulich wrote:
> On 08.11.2022 18:15, Roger Pau Monné wrote:
> > On Tue, Nov 08, 2022 at 06:03:54PM +0100, Jan Beulich wrote:
> >> On 08.11.2022 17:43, Roger Pau Monné wrote:
> >>> On Tue, Nov 08, 2022 at 05:14:40PM +0100, Jan Beulich wrote:
> >>>> On 08.11.2022 12:38, Roger Pau Monne wrote:
> >>>>> Like on the Arm side, return -EINVAL when attempting to do a p2m
> >>>>> operation on dying domains.
> >>>>>
> >>>>> The current logic returns 0 and leaves the domctl parameter
> >>>>> uninitialized for any parameter fetching operations (like the
> >>>>> GET_ALLOCATION operation), which is not helpful from a toolstack point
> >>>>> of view, because there's no indication that the data hasn't been
> >>>>> fetched.
> >>>>
> >>>> While I can see how the present behavior is problematic when it comes
> >>>> to consuming supposedly returned data, ...
> >>>>
> >>>>> --- a/xen/arch/x86/mm/paging.c
> >>>>> +++ b/xen/arch/x86/mm/paging.c
> >>>>> @@ -694,9 +694,10 @@ int paging_domctl(struct domain *d, struct 
> >>>>> xen_domctl_shadow_op *sc,
> >>>>>  
> >>>>>      if ( unlikely(d->is_dying) )
> >>>>>      {
> >>>>> -        gdprintk(XENLOG_INFO, "Ignoring paging op on dying domain 
> >>>>> %u\n",
> >>>>> +        gdprintk(XENLOG_INFO,
> >>>>> +                 "Tried to do a paging domctl op on dying domain %u\n",
> >>>>>                   d->domain_id);
> >>>>> -        return 0;
> >>>>> +        return -EINVAL;
> >>>>>      }
> >>>>
> >>>> ... going from "success" to "failure" here has a meaningful risk of
> >>>> regressing callers. It is my understanding that it was deliberate to
> >>>> mimic success in this case (without meaning to assign "good" or "bad"
> >>>> to that decision).
> >>>
> >>> I would assume that was the original intention, yes, albeit the commit
> >>> message doesn't go into details about why mimicking success is
> >>> required, it's very well possible the code relying on this was xend.
> >>
> >> Quite possible, but you never know who else has cloned code from there.
> >>
> >>>> Can you instead fill the data to be returned in
> >>>> some simple enough way? I assume a mere memset() isn't going to be
> >>>> good enough, though (albeit public/domctl.h doesn't explicitly name
> >>>> any input-only fields, so it may not be necessary to preserve
> >>>> anything). Maybe zeroing ->mb and ->stats would do?
> >>>
> >>> Hm, it still feels kind of wrong.  We do return errors elsewhere for
> >>> operations attempted against dying domains, and that seems all fine,
> >>> not sure why paging operations need to be different in this regard.
> >>> Arm does also return -EINVAL in that case.
> >>>
> >>> So what about postponing this change to 4.18 in order to avoid
> >>> surprises, but then taking it in its current form at the start of the
> >>> development window, as to have time to detect any issues?
> >>
> >> Maybe, but to be honest I'm not convinced. Arm can't really be taken
> >> for comparison, since the op is pretty new there iirc.
> > 
> > Indeed, but the tools code paths are likely shared between x86 and
> > Arm, as the hypercalls are the same.
> 
> On x86 we have both xc_shadow_control() and (functional)
> xc_logdirty_control(); on Arm only the former is used, while the latter
> would also be impacted by your change. Plus you're not accounting for
> external tool stacks (like xend would be if anyone had cared to forward
> port it, when - as you said earlier - the suspicion is that the original
> change was made to "please" xend).

AFAICT XEN_DOMCTL_SHADOW_OP_{CLEAN,PEEK} are equally broken if no
error is returned when the domain is dying.  A caller might think the
bitmap has been fetched correctly when that's not the case, as the
bitmap buffer would be left untouched.

> > This is a domctl interface, so we are fine to do such changes.
> 
> We're fine to make changes to domctl which are either binary compatible
> with earlier versions or which are associated with a bump of the
> interface version. The latter wouldn't help in this case, while the
> former is simply not true here. For Andrew's proposed new paging pool
> interface the behavior suggested here would of course be fully
> appropriate, demanding that tool stack either don't issue such requests
> against dying domains or that they be prepared to get back errors.

I still think we need to fix this bug in Xen, and then fix any
toolstacks that rely on such bogus behavior.  Propagating such broken
interface is just going to cause more issues down the road.

> Thinking about it again I'm also not convinced EINVAL is an appropriate
> error code to use here. The operation isn't necessarily invalid; we
> only prefer to not carry out any such anymore. EOPNOTSUPP, EPERM, or
> EACCES would all seem more appropriate. Or, for ease of recognition, a
> rarely used one, e.g. ENODATA, EILSEQ, or EROFS.

I was about to use ESRCH, as that also used by track_dirty_vram() and
seems sensible.

> Finally I'm not convinced of the usefulness of this dying check in the
> first place: is_dying may become set immediately after the check was
> done.

While strictly true, this code is executed with the domain lock held,
so while is_dying might change, domain_kill() won't make progress
because of the barrier on the domain lock just after setting is_dying.

Thanks, Roger.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.