* [PATCH v5] xen/domain: introduce DOMID_ANY
@ 2026-02-05 23:51 dmukhin
2026-02-17 15:31 ` Stefano Stabellini
2026-03-02 14:25 ` Anthony PERARD
0 siblings, 2 replies; 5+ messages in thread
From: dmukhin @ 2026-02-05 23:51 UTC (permalink / raw)
To: xen-devel
Cc: andrew.cooper3, anthony.perard, jbeulich, julien, michal.orzel,
roger.pau, sstabellini, dmukhin
From: Denis Mukhin <dmukhin@ford.com>
Add a new symbol DOMID_ANY to improve the readability of the code.
Update all relevant domid_alloc() call sites and harden the domid_alloc()
input value check.
Also, fix problem with passing invalid domain IDs in
XEN_DOMCTL_createdomain: turns out libxl__domain_make() (toolstack)
uses 0xffff as domain ID.
Amends: 2d5065060710 ("xen/domain: unify domain ID allocation")
Signed-off-by: Denis Mukhin <dmukhin@ford.com>
---
Changes since v4:
- dropped ifdefery for DOMID_ANY in public header since symbol is
needed in toolstack and stubdom code
- fixed commentary for DOMID_ANY
- fixed check do_domctl()
- fixed libxl__domain_make() is toolstack which can pass invalid
domain ID
- hardended domain ID check in domid_alloc()
- CI run: https://gitlab.com/xen-project/people/dmukhin/xen/-/pipelines/2308917328
---
tools/libs/light/libxl_create.c | 9 ++++-----
tools/tests/domid/harness.h | 1 +
tools/tests/domid/test-domid.c | 12 ++++++------
xen/common/device-tree/dom0less-build.c | 2 +-
xen/common/domctl.c | 3 +--
xen/common/domid.c | 5 ++++-
xen/include/public/xen.h | 7 +++++++
7 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/tools/libs/light/libxl_create.c b/tools/libs/light/libxl_create.c
index bfc9149096a3..714e71441498 100644
--- a/tools/libs/light/libxl_create.c
+++ b/tools/libs/light/libxl_create.c
@@ -676,15 +676,14 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config,
if (ret < 0)
break;
- v &= DOMID_MASK;
- if (!libxl_domid_valid_guest(v))
- continue;
-
- local_domid = v;
+ local_domid = v & DOMID_MASK;
} else {
local_domid = info->domid; /* May not be valid */
}
+ if (!libxl_domid_valid_guest(local_domid))
+ local_domid = DOMID_ANY;
+
ret = xc_domain_create(ctx->xch, &local_domid, &create);
if (ret < 0) {
/*
diff --git a/tools/tests/domid/harness.h b/tools/tests/domid/harness.h
index 17eb22a9a854..65da0d075a2b 100644
--- a/tools/tests/domid/harness.h
+++ b/tools/tests/domid/harness.h
@@ -41,6 +41,7 @@ extern unsigned long find_next_zero_bit(const unsigned long *addr,
#define DOMID_FIRST_RESERVED (100)
#define DOMID_INVALID (101)
+#define DOMID_ANY (102)
#endif /* _TEST_HARNESS_ */
diff --git a/tools/tests/domid/test-domid.c b/tools/tests/domid/test-domid.c
index 5915c4699a5c..71cc4e7fd86d 100644
--- a/tools/tests/domid/test-domid.c
+++ b/tools/tests/domid/test-domid.c
@@ -41,20 +41,20 @@ int main(int argc, char **argv)
domid_free(expected);
/*
- * Test that that two consecutive calls of domid_alloc(DOMID_INVALID)
+ * Test that that two consecutive calls of domid_alloc(DOMID_ANY)
* will never return the same ID.
* NB: ID#0 is reserved and shall not be allocated by
- * domid_alloc(DOMID_INVALID).
+ * domid_alloc(DOMID_ANY).
*/
for ( expected = 1; expected < DOMID_FIRST_RESERVED; expected++ )
{
- allocated = domid_alloc(DOMID_INVALID);
+ allocated = domid_alloc(DOMID_ANY);
verify(allocated == expected,
"TEST 3: expected %u allocated %u\n", expected, allocated);
}
for ( expected = 1; expected < DOMID_FIRST_RESERVED; expected++ )
{
- allocated = domid_alloc(DOMID_INVALID);
+ allocated = domid_alloc(DOMID_ANY);
verify(allocated == DOMID_INVALID,
"TEST 4: expected %u allocated %u\n", DOMID_INVALID, allocated);
}
@@ -64,7 +64,7 @@ int main(int argc, char **argv)
domid_free(expected);
for ( expected = 1; expected < DOMID_FIRST_RESERVED / 2; expected++ )
{
- allocated = domid_alloc(DOMID_INVALID);
+ allocated = domid_alloc(DOMID_ANY);
verify(allocated == expected,
"TEST 5: expected %u allocated %u\n", expected, allocated);
}
@@ -72,7 +72,7 @@ int main(int argc, char **argv)
/* Re-allocate last ID from [1..DOMID_FIRST_RESERVED - 1]. */
expected = DOMID_FIRST_RESERVED - 1;
domid_free(DOMID_FIRST_RESERVED - 1);
- allocated = domid_alloc(DOMID_INVALID);
+ allocated = domid_alloc(DOMID_ANY);
verify(allocated == expected,
"TEST 6: expected %u allocated %u\n", expected, allocated);
diff --git a/xen/common/device-tree/dom0less-build.c b/xen/common/device-tree/dom0less-build.c
index 840d14419da2..3c18dae5e625 100644
--- a/xen/common/device-tree/dom0less-build.c
+++ b/xen/common/device-tree/dom0less-build.c
@@ -852,7 +852,7 @@ void __init create_domUs(void)
if ( (max_init_domid + 1) >= DOMID_FIRST_RESERVED )
panic("No more domain IDs available\n");
- domid = domid_alloc(DOMID_INVALID);
+ domid = domid_alloc(DOMID_ANY);
if ( domid == DOMID_INVALID )
panic("Error allocating ID for domain %s\n", dt_node_name(node));
diff --git a/xen/common/domctl.c b/xen/common/domctl.c
index 29a7726d32d0..35fa60e74d74 100644
--- a/xen/common/domctl.c
+++ b/xen/common/domctl.c
@@ -409,8 +409,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
case XEN_DOMCTL_createdomain:
{
- /* NB: ID#0 is reserved, find the first suitable ID instead. */
- domid_t domid = domid_alloc(op->domain ?: DOMID_INVALID);
+ domid_t domid = domid_alloc(op->domain);
if ( domid == DOMID_INVALID )
{
diff --git a/xen/common/domid.c b/xen/common/domid.c
index 2387ddb08300..b0258e477c1a 100644
--- a/xen/common/domid.c
+++ b/xen/common/domid.c
@@ -19,7 +19,7 @@ static DECLARE_BITMAP(domid_bitmap, DOMID_FIRST_RESERVED);
* @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,
+ * - If DOMID_ANY 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
@@ -31,6 +31,9 @@ domid_t domid_alloc(domid_t domid)
{
static domid_t domid_last;
+ if ( domid >= DOMID_FIRST_RESERVED && domid != DOMID_ANY )
+ return DOMID_INVALID;
+
spin_lock(&domid_lock);
/* Exact match. */
diff --git a/xen/include/public/xen.h b/xen/include/public/xen.h
index b12fd10e6315..f35a6f21f063 100644
--- a/xen/include/public/xen.h
+++ b/xen/include/public/xen.h
@@ -608,6 +608,13 @@ DEFINE_XEN_GUEST_HANDLE(mmuext_op_t);
/* DOMID_INVALID is used to identify pages with unknown owner. */
#define DOMID_INVALID xen_mk_uint(0x7FF4)
+/*
+ * DOMID_ANY is used to signal no specific domain ID requested.
+ * Handler should pick a valid ID, or handle it as a broadcast value
+ * depending on the context.
+ */
+#define DOMID_ANY xen_mk_uint(0x7FF5)
+
/* Idle domain. */
#define DOMID_IDLE xen_mk_uint(0x7FFF)
--
2.52.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v5] xen/domain: introduce DOMID_ANY
2026-02-05 23:51 [PATCH v5] xen/domain: introduce DOMID_ANY dmukhin
@ 2026-02-17 15:31 ` Stefano Stabellini
2026-02-25 23:54 ` Stefano Stabellini
2026-03-02 14:25 ` Anthony PERARD
1 sibling, 1 reply; 5+ messages in thread
From: Stefano Stabellini @ 2026-02-17 15:31 UTC (permalink / raw)
To: dmukhin
Cc: xen-devel, andrew.cooper3, anthony.perard, jbeulich, julien,
michal.orzel, roger.pau, sstabellini
On Thu, 5 Feb 2026, dmukhin@ford.com wrote:
> From: Denis Mukhin <dmukhin@ford.com>
>
> Add a new symbol DOMID_ANY to improve the readability of the code.
>
> Update all relevant domid_alloc() call sites and harden the domid_alloc()
> input value check.
>
> Also, fix problem with passing invalid domain IDs in
> XEN_DOMCTL_createdomain: turns out libxl__domain_make() (toolstack)
> uses 0xffff as domain ID.
>
> Amends: 2d5065060710 ("xen/domain: unify domain ID allocation")
> Signed-off-by: Denis Mukhin <dmukhin@ford.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v5] xen/domain: introduce DOMID_ANY
2026-02-17 15:31 ` Stefano Stabellini
@ 2026-02-25 23:54 ` Stefano Stabellini
0 siblings, 0 replies; 5+ messages in thread
From: Stefano Stabellini @ 2026-02-25 23:54 UTC (permalink / raw)
To: anthony.perard
Cc: dmukhin, xen-devel, andrew.cooper3, jbeulich, julien,
michal.orzel, roger.pau, sstabellini
Anthony, we need to tools ack for this patch
On Tue, 17 Feb 2026, Stefano Stabellini wrote:
> On Thu, 5 Feb 2026, dmukhin@ford.com wrote:
> > From: Denis Mukhin <dmukhin@ford.com>
> >
> > Add a new symbol DOMID_ANY to improve the readability of the code.
> >
> > Update all relevant domid_alloc() call sites and harden the domid_alloc()
> > input value check.
> >
> > Also, fix problem with passing invalid domain IDs in
> > XEN_DOMCTL_createdomain: turns out libxl__domain_make() (toolstack)
> > uses 0xffff as domain ID.
> >
> > Amends: 2d5065060710 ("xen/domain: unify domain ID allocation")
> > Signed-off-by: Denis Mukhin <dmukhin@ford.com>
>
>
> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v5] xen/domain: introduce DOMID_ANY
2026-02-05 23:51 [PATCH v5] xen/domain: introduce DOMID_ANY dmukhin
2026-02-17 15:31 ` Stefano Stabellini
@ 2026-03-02 14:25 ` Anthony PERARD
2026-03-03 6:23 ` dmukhin
1 sibling, 1 reply; 5+ messages in thread
From: Anthony PERARD @ 2026-03-02 14:25 UTC (permalink / raw)
To: dmukhin
Cc: xen-devel, andrew.cooper3, jbeulich, julien, michal.orzel,
roger.pau, sstabellini
On Thu, Feb 05, 2026 at 03:51:26PM -0800, dmukhin@ford.com wrote:
> diff --git a/tools/libs/light/libxl_create.c b/tools/libs/light/libxl_create.c
> index bfc9149096a3..714e71441498 100644
> --- a/tools/libs/light/libxl_create.c
> +++ b/tools/libs/light/libxl_create.c
> @@ -676,15 +676,14 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config,
> if (ret < 0)
> break;
>
> - v &= DOMID_MASK;
> - if (!libxl_domid_valid_guest(v))
> - continue;
> -
> - local_domid = v;
> + local_domid = v & DOMID_MASK;
> } else {
> local_domid = info->domid; /* May not be valid */
> }
>
> + if (!libxl_domid_valid_guest(local_domid))
> + local_domid = DOMID_ANY;
Well, that make it possible to have DOMID_ANY selected when a "random"
domid was asked for, and this value is more likely than any other domid.
I don't think it's wise to change that. The domid generated in the
random case was already valid, no need to check again.
Coud you move the new validity check into the case where domid isn't
"random" or introduce a new case in the if/else chain ?
(something like that for the second option: if (domid==random) elif
(domid.is_valid) else (use domid))
Thanks,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v5] xen/domain: introduce DOMID_ANY
2026-03-02 14:25 ` Anthony PERARD
@ 2026-03-03 6:23 ` dmukhin
0 siblings, 0 replies; 5+ messages in thread
From: dmukhin @ 2026-03-03 6:23 UTC (permalink / raw)
To: Anthony PERARD
Cc: dmukhin, xen-devel, andrew.cooper3, jbeulich, julien,
michal.orzel, roger.pau, sstabellini
On Mon, Mar 02, 2026 at 02:25:33PM +0000, Anthony PERARD wrote:
> On Thu, Feb 05, 2026 at 03:51:26PM -0800, dmukhin@ford.com wrote:
> > diff --git a/tools/libs/light/libxl_create.c b/tools/libs/light/libxl_create.c
> > index bfc9149096a3..714e71441498 100644
> > --- a/tools/libs/light/libxl_create.c
> > +++ b/tools/libs/light/libxl_create.c
> > @@ -676,15 +676,14 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config,
> > if (ret < 0)
> > break;
> >
> > - v &= DOMID_MASK;
> > - if (!libxl_domid_valid_guest(v))
> > - continue;
> > -
> > - local_domid = v;
> > + local_domid = v & DOMID_MASK;
> > } else {
> > local_domid = info->domid; /* May not be valid */
> > }
> >
> > + if (!libxl_domid_valid_guest(local_domid))
> > + local_domid = DOMID_ANY;
>
> Well, that make it possible to have DOMID_ANY selected when a "random"
> domid was asked for, and this value is more likely than any other domid.
> I don't think it's wise to change that. The domid generated in the
> random case was already valid, no need to check again.
>
> Coud you move the new validity check into the case where domid isn't
> "random" or introduce a new case in the if/else chain ?
> (something like that for the second option: if (domid==random) elif
> (domid.is_valid) else (use domid))
Will do, thanks.
--
Denis
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-03-03 6:24 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-05 23:51 [PATCH v5] xen/domain: introduce DOMID_ANY dmukhin
2026-02-17 15:31 ` Stefano Stabellini
2026-02-25 23:54 ` Stefano Stabellini
2026-03-02 14:25 ` Anthony PERARD
2026-03-03 6:23 ` dmukhin
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.