From: "Durrant, Paul" <pdurrant@amazon.co.uk>
To: Ian Jackson <ian.jackson@citrix.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
Julien Grall <julien@xen.org>, Wei Liu <wl@xen.org>,
Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
Andrew Cooper <Andrew.Cooper3@citrix.com>,
"jandryuk@gmail.com" <jandryuk@gmail.com>,
George Dunlap <George.Dunlap@citrix.com>,
Jan Beulich <jbeulich@suse.com>,
Anthony Perard <anthony.perard@citrix.com>,
"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Subject: Re: [Xen-devel] [PATCH v3 4/6] libxl: allow creation of domains with a specified or random domid
Date: Fri, 17 Jan 2020 09:37:58 +0000 [thread overview]
Message-ID: <402866798e2a40e192fd8052548374c5@EX13D32EUC003.ant.amazon.com> (raw)
In-Reply-To: <24096.44311.441643.264877@mariner.uk.xensource.com>
> -----Original Message-----
> From: Ian Jackson <ian.jackson@citrix.com>
> Sent: 16 January 2020 19:36
> To: Durrant, Paul <pdurrant@amazon.co.uk>
> Cc: xen-devel@lists.xenproject.org; Wei Liu <wl@xen.org>; Anthony Perard
> <anthony.perard@citrix.com>; Andrew Cooper <Andrew.Cooper3@citrix.com>;
> George Dunlap <George.Dunlap@citrix.com>; Jan Beulich <jbeulich@suse.com>;
> Julien Grall <julien@xen.org>; Konrad Rzeszutek Wilk
> <konrad.wilk@oracle.com>; Stefano Stabellini <sstabellini@kernel.org>;
> jandryuk@gmail.com
> Subject: Re: [PATCH v3 4/6] libxl: allow creation of domains with a
> specified or random domid
>
> Hi. This broadly contains what I expected, but:
>
> Paul Durrant writes ("[PATCH v3 4/6] libxl: allow creation of domains with
> a specified or random domid"):
>
> > + for (;;) {
> > + if (info->domid == RANDOM_DOMID) {
> > + uint16_t v;
> > +
> > + /* Randomize lower order bytes */
> > + ret = libxl__random_bytes(gc, (void *)&v, sizeof(v));
> > + if (ret < 0)
> > + break;
> > +
> > + v &= DOMID_MASK;
> > + if (!libxl_domid_valid_guest(v) ||
> > + libxl__is_retired_domid(gc, v))
> > + continue;
> > +
> > + *domid = v;
> > + }
> > +
> > + ret = xc_domain_create(ctx->xch, domid, &create);
> > + if (ret == 0 || errno != EEXIST || info->domid !=
> RANDOM_DOMID)
> > + break;
> > + }
>
> I think this has a race.
>
> Thread A, in domain destroy Thread B, in code above
>
> choose domid V
> check V in recent domid list
>
> add V to recent domid list
> destroy domain V in Xen
>
> create domain V in Xen
> continue constructing V
>
> Thread B improperly constructs a new guest using V, exposing anyone
> who was talking about V a moment ago to bugs. Some code might even
> fail to spot the interval where V does not exist and carry on talking
> to the new V as if it were the old one...
>
> I think there are only two possible solutions:
>
> - Check the domain's entry in the recent list *after* creating
> the domain in Xen. This involves accepting that we will
> reuse the domid but only for a domain we are in the early
> stages of constructing, so hopefully without bad consequence?
>
> - Take the recent domid lock.
>
Or take a global file lock in libxl around domain creation and destruction?
> Also, it seems to me that we should check the recent domid list if we
> let Xen choose the domid. Maybe that can be in a subsequent patch...
>
Well, we could solve all this, remove the need for a file and all the associated complexity by simply keeping history inside the hypervisor. I don't know how the Xen maintainers will feel about that though, as Xen itself shouldn't have a problem with eager domid re-use.
Paul
> Thanks,
> Ian.
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2020-01-17 9:38 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-16 9:35 [Xen-devel] [PATCH v3 0/6] xl/libxl: domid allocation/preservation changes Paul Durrant
2020-01-16 9:35 ` [Xen-devel] [PATCH v3 1/6] libxl: add definition of INVALID_DOMID to the API Paul Durrant
2020-01-16 9:35 ` [Xen-devel] [PATCH v3 2/6] libxl_create: make 'soft reset' explicit Paul Durrant
2020-01-16 9:35 ` [Xen-devel] [PATCH v3 3/6] libxl: add infrastructure to track and query 'retired' domids Paul Durrant
2020-01-16 18:27 ` Ian Jackson
2020-01-17 9:26 ` Durrant, Paul
2020-01-17 11:31 ` Ian Jackson
2020-01-16 9:36 ` [Xen-devel] [PATCH v3 4/6] libxl: allow creation of domains with a specified or random domid Paul Durrant
2020-01-16 9:40 ` Jan Beulich
2020-01-16 9:46 ` Durrant, Paul
2020-01-16 9:59 ` Jan Beulich
2020-01-16 15:53 ` Jason Andryuk
2020-01-16 18:36 ` Ian Jackson
2020-01-17 9:37 ` Durrant, Paul [this message]
2020-01-17 11:35 ` Ian Jackson
2020-01-17 12:06 ` Durrant, Paul
2020-01-17 15:30 ` Ian Jackson
2020-01-20 8:18 ` Durrant, Paul
2020-01-16 9:36 ` [Xen-devel] [PATCH v3 5/6] xl.conf: introduce 'domid_policy' Paul Durrant
2020-01-16 18:37 ` Ian Jackson
2020-01-16 9:36 ` [Xen-devel] [PATCH v3 6/6] xl: allow domid to be preserved on save/restore or migrate Paul Durrant
2020-01-16 18:39 ` Ian Jackson
2020-01-16 18:43 ` [Xen-devel] [PATCH v3 0/6] xl/libxl: domid allocation/preservation changes Ian Jackson
2020-01-17 9:11 ` Durrant, Paul
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=402866798e2a40e192fd8052548374c5@EX13D32EUC003.ant.amazon.com \
--to=pdurrant@amazon.co.uk \
--cc=Andrew.Cooper3@citrix.com \
--cc=George.Dunlap@citrix.com \
--cc=anthony.perard@citrix.com \
--cc=ian.jackson@citrix.com \
--cc=jandryuk@gmail.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=konrad.wilk@oracle.com \
--cc=sstabellini@kernel.org \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).