From: dmkhn@proton.me
To: Jan Beulich <jbeulich@suse.com>
Cc: andrew.cooper3@citrix.com, anthony.perard@vates.tech,
julien@xen.org, michal.orzel@amd.com, roger.pau@citrix.com,
sstabellini@kernel.org, dmukhin@ford.com,
xen-devel@lists.xenproject.org
Subject: Re: [PATCH v4] xen/domain: unify domain ID allocation
Date: Mon, 28 Apr 2025 20:00:39 +0000 [thread overview]
Message-ID: <aA/eZCg797KkhuiC@kraken> (raw)
In-Reply-To: <f8be084a-e259-456b-b30d-677b128978e3@suse.com>
On Mon, Apr 28, 2025 at 11:14:25AM +0200, Jan Beulich wrote:
> On 22.04.2025 23:54, dmkhn@proton.me wrote:
> > --- a/xen/common/domain.c
> > +++ b/xen/common/domain.c
> > @@ -66,6 +66,57 @@ DEFINE_RCU_READ_LOCK(domlist_read_lock);
> > static struct domain *domain_hash[DOMAIN_HASH_SIZE];
> > struct domain *domain_list;
> >
> > +/* Domain ID allocator */
> > +static unsigned int domid_last;
> > +
> > +static inline bool is_free_domid(domid_t dom)
> > +{
> > + struct domain *d = rcu_lock_domain_by_id(dom);
> > +
> > + if ( d )
> > + rcu_unlock_domain(d);
> > +
> > + return !d;
> > +}
> > +
> > +/*
> > + * Allocate new domain ID based on the hint.
> > + *
> > + * If hint is outside of valid [0..DOMID_FIRST_RESERVED - 1] range of IDs,
> > + * perform an exhaustive search starting from the end of the used domain ID
> > + * range, excluding hardware_domid.
> > + */
> > +domid_t domid_alloc(domid_t hint)
> > +{
> > + domid_t domid = DOMID_INVALID;
> > +
> > + if ( hint < DOMID_FIRST_RESERVED )
> > + {
> > + /* Exact match. */
> > + if ( is_free_domid(hint) )
> > + domid = hint;
> > + }
> > + else
> > + {
> > + for ( domid = domid_last + 1; domid != domid_last; domid++ )
> > + {
> > + if ( domid == DOMID_FIRST_RESERVED )
> > + domid = 0;
> > +
> > + if ( domid == hardware_domid )
> > + continue;
> > +
> > + if ( is_free_domid(domid) )
> > + break;
> > + }
> > +
> > + if ( domid != domid_last )
> > + domid_last = domid;
> > + }
> > +
> > + return domid;
> > +}
>
> The function name suggests the ID returned is firmly allocated by the time
> the caller gets to see / use it. Yet that's not the case. Two back-to-back
> calls here with the same argument will yield the same result, afaict. This
> supports my prior statement that I don't think it is a good idea to
> "centralize" things like this.
I agree, back-to-back call requirement is not implemented, I will fix that.
I think a library service for domain ID allocation will be useful since there
are 2 users of it already and there's one more user of similar functionality is
on review (hyperlauch DT parsing).
>
> Jan
prev parent reply other threads:[~2025-04-28 20:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-22 21:54 [PATCH v4] xen/domain: unify domain ID allocation dmkhn
2025-04-23 11:22 ` Julien Grall
2025-04-24 1:40 ` dmkhn
2025-04-28 9:08 ` Jan Beulich
2025-04-28 9:14 ` Jan Beulich
2025-04-28 20:00 ` dmkhn [this message]
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=aA/eZCg797KkhuiC@kraken \
--to=dmkhn@proton.me \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@vates.tech \
--cc=dmukhin@ford.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.