All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: dmkhn@proton.me
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,
	Julien Grall <jgrall@amazon.com>,
	xen-devel@lists.xenproject.org
Subject: Re: [PATCH v15 1/4] xen/domain: unify domain ID allocation
Date: Mon, 11 Aug 2025 13:14:49 +0200	[thread overview]
Message-ID: <db85bafd-c2f8-4aa0-9cf4-0529b0a39bcd@suse.com> (raw)
In-Reply-To: <20250809170747.1836880-2-dmukhin@ford.com>

On 09.08.2025 19:08, dmkhn@proton.me wrote:
> --- /dev/null
> +++ b/xen/common/domid.c
> @@ -0,0 +1,95 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * Domain ID allocator.
> + *
> + * Covers dom0 or late hwdom, predefined domains, post-boot domains.
> + * Excludes system domains (ID >= DOMID_FIRST_RESERVED).
> + *
> + * Copyright 2025 Ford Motor Company
> + */
> +
> +#include <xen/domain.h>
> +
> +static DEFINE_SPINLOCK(domid_lock);
> +static DECLARE_BITMAP(domid_bitmap, DOMID_FIRST_RESERVED);
> +
> +/*
> + * Allocate domain ID.
> + *
> + * @param domid Domain ID hint:
> + * - If an explicit domain ID is provided, verify its availability and use it
> + *   if ID is not used;
> + * - If DOMID_INVALID is provided, search [1..DOMID_FIRST_RESERVED-1] range,
> + *   starting from the last used ID. Implementation guarantees that two
> + *   consecutive calls will never return the same ID. ID#0 is reserved for
> + *   the first boot domain (currently, dom0) and excluded from the allocation
> + *   range.
> + * @return Valid domain ID in case of successful allocation,
> + *         DOMID_INVALID - otherwise.
> + */
> +domid_t domid_alloc(domid_t domid)
> +{
> +    static domid_t domid_last;
> +
> +    spin_lock(&domid_lock);
> +
> +    /* Exact match. */
> +    if ( domid < DOMID_FIRST_RESERVED )
> +    {
> +        if ( __test_and_set_bit(domid, domid_bitmap) )
> +            domid = DOMID_INVALID;
> +    }
> +    /*
> +     * Exhaustive search.
> +     *
> +     * Domain ID#0 is reserved for the first boot domain (e.g. control domain)
> +     * and excluded from allocation.
> +     */
> +    else
> +    {
> +        domid_t num = DOMID_FIRST_RESERVED;
> +
> +        domid = find_next_zero_bit(domid_bitmap, num, domid_last + 1);
> +        if ( domid == num && domid_last != 0 )

I'm pretty sure I commented on this before, yet then maybe it was in the context
of another patch: Using == here isn't sufficient; it needs to be >=. See e.g.
cpumask_next().

Jan


  parent reply	other threads:[~2025-08-11 11:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-09 17:07 [PATCH v15 0/4] xen/domain: domain ID allocation dmkhn
2025-08-09 17:08 ` [PATCH v15 1/4] xen/domain: unify " dmkhn
2025-08-11 11:00   ` Alejandro Vallejo
2025-08-11 23:47     ` dmkhn
2025-08-11 11:14   ` Jan Beulich [this message]
2025-08-11 23:46     ` dmkhn
2025-08-09 17:08 ` [PATCH v15 2/4] tools/include: move xc_bitops.h to xen-tools/bitops.h dmkhn
2025-08-09 17:08 ` [PATCH v15 3/4] tools/tests: introduce unit tests for domain ID allocator dmkhn
2025-08-11  7:58   ` Jan Beulich
2025-08-11 23:53     ` dmkhn
2025-08-09 17:08 ` [PATCH v15 4/4] xen/domain: update create_dom0() messages dmkhn

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=db85bafd-c2f8-4aa0-9cf4-0529b0a39bcd@suse.com \
    --to=jbeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=anthony.perard@vates.tech \
    --cc=dmkhn@proton.me \
    --cc=dmukhin@ford.com \
    --cc=jgrall@amazon.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.