Skip to contentSkip to conversation

xen/domain: introduce DOMID_ANY

PATCH Superseded [email protected] 2 participants 5 messages Sep 20, 2025 – Sep 24, 2025

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xen/domain: introduce DOMID_ANY

From: Denis Mukhin <[email protected]>

Add a new symbol DOMID_ANY aliasing DOMID_INVALID to improve the readability of the code.

Update all relevant domid_alloc() call sites.

Amends: 2d5065060710 ("xen/domain: unify domain ID allocation")

---
Changes since v1:
- moved DOMID_ANY from the public header

---
 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                     |  2 +-
 xen/common/domid.c                      |  2 +-
 xen/include/xen/domain.h                |  3 +++
 6 files changed, 13 insertions(+), 9 deletions(-)
tools/tests/domid/harness.h +1 -0
index 17eb22a9a854..610b564d4061 100644
@@ -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                       DOMID_INVALID
 
 #endif /* _TEST_HARNESS_ */
 
tools/tests/domid/test-domid.c +6 -6
index 5915c4699a5c..71cc4e7fd86d 100644
@@ -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);
 
xen/common/device-tree/dom0less-build.c +1 -1
index 9fd004c42af7..e2764768c983 100644
@@ -848,7 +848,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));
 
xen/common/domctl.c +1 -1
index 954d79022645..ca91686a03d8 100644
@@ -410,7 +410,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 ?: DOMID_ANY);
 
         if ( domid == DOMID_INVALID )
         {
xen/common/domid.c +1 -1
index 2387ddb08300..76b7f3e7ae6e 100644
@@ -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
xen/include/xen/domain.h +3 -0
index 8aab05ae93c8..cd3e32d17683 100644
@@ -15,6 +15,9 @@ struct guest_area {
 
 #include <asm/domain.h>
 
+/* Domain ID allocator: search [1..DOMID_FIRST_RESERVED-1] range. */
+#define DOMID_ANY            DOMID_INVALID
+
 typedef union {
     struct vcpu_guest_context *nat;
     struct compat_vcpu_guest_context *cmp;
Signature · 1 line
2.51.0
#1 lore raw
Quoted 5 lines · On 20.09.2025 19:47, [email protected] wrote:

From: Denis Mukhin <[email protected]>

Add a new symbol DOMID_ANY aliasing DOMID_INVALID to improve the readability of the code.

Quoted 7 lines

Update all relevant domid_alloc() call sites.

Amends: 2d5065060710 ("xen/domain: unify domain ID allocation")

---
Changes since v1:
- moved DOMID_ANY from the public header

This addresses my comment, but not Andrew's subsequent response, specifically aiming at ...

tools/tests/domid/harness.h extern unsigned long find_next_zero_bit(const unsigned long *addr, · line 44

Quoted 7 lines
tools/tests/domid/harness.h +1 -0
@@ -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                       DOMID_INVALID

... avoiding the need for any such secondary definitions.

Jan

#2 lore raw
Quoted 8 lines · Jan Beulich
Quoted 7 lines · On 20.09.2025 19:47, [email protected] wrote:

From: Denis Mukhin <[email protected]>

Add a new symbol DOMID_ANY aliasing DOMID_INVALID to improve the readability of the code.

Update all relevant domid_alloc() call sites.

Quoted 8 lines
Quoted 5 lines

Amends: 2d5065060710 ("xen/domain: unify domain ID allocation")

---
Changes since v1:
- moved DOMID_ANY from the public header

This addresses my comment, but not Andrew's subsequent response, specifically aiming at ...

AFAIU, toolstack should start using DOMID_ANY instead of 0 in XEN_DOMCTL_createdomain.

I was planning to send a separate patch to address it if that's OK.

Quoted 10 lines

tools/tests/domid/harness.h extern unsigned long find_next_zero_bit(const unsigned long *addr, · line 44

Quoted 8 lines
tools/tests/domid/harness.h +1 -0
@@ -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                       DOMID_INVALID

... avoiding the need for any such secondary definitions.

In the current design, unit test harness.h has to define DOMID_ANY. Enabling xen/domain.h to compile for unit test is a separate task, IMO.

Quoted 2 lines

Jan

#3 lore raw
Quoted 28 lines · On 22.09.2025 23:56, [email protected] wrote:
Quoted 8 lines · Jan Beulich
Quoted 7 lines · On 20.09.2025 19:47, [email protected] wrote:

From: Denis Mukhin <[email protected]>

Add a new symbol DOMID_ANY aliasing DOMID_INVALID to improve the readability of the code.

Update all relevant domid_alloc() call sites.

Quoted 8 lines
Quoted 5 lines

Amends: 2d5065060710 ("xen/domain: unify domain ID allocation")

---
Changes since v1:
- moved DOMID_ANY from the public header

This addresses my comment, but not Andrew's subsequent response, specifically aiming at ...

AFAIU, toolstack should start using DOMID_ANY instead of 0 in XEN_DOMCTL_createdomain.

I was planning to send a separate patch to address it if that's OK.

Quoted 5 lines
Quoted 5 lines
tools/tests/domid/harness.h +0 -0
@@ -41,6 +41,7 @@ extern unsigned long find_next_zero_bit(const unsigned long *addr,
 
Quoted 8 lines
Quoted 5 lines

tools/tests/domid/harness.h extern unsigned long find_next_zero_bit(const unsigned long *addr, · line 44

Quoted 3 lines
tools/tests/domid/harness.h +1 -0
 #define DOMID_FIRST_RESERVED            (100)
 #define DOMID_INVALID                   (101)
+#define DOMID_ANY                       DOMID_INVALID

... avoiding the need for any such secondary definitions.

In the current design, unit test harness.h has to define DOMID_ANY. Enabling xen/domain.h to compile for unit test is a separate task, IMO.

That wasn't suggested as an option. The #define wants to move back to the public header, but be properly guarded there. See the v1 replies you got.

Jan

#4 lore raw
Quoted 35 lines · Jan Beulich
Quoted 34 lines · On 22.09.2025 23:56, [email protected] wrote:
Quoted 8 lines · Jan Beulich
Quoted 7 lines · On 20.09.2025 19:47, [email protected] wrote:

From: Denis Mukhin <[email protected]>

Add a new symbol DOMID_ANY aliasing DOMID_INVALID to improve the readability of the code.

Update all relevant domid_alloc() call sites.

Quoted 8 lines
Quoted 5 lines

Amends: 2d5065060710 ("xen/domain: unify domain ID allocation")

---
Changes since v1:
- moved DOMID_ANY from the public header

This addresses my comment, but not Andrew's subsequent response, specifically aiming at ...

AFAIU, toolstack should start using DOMID_ANY instead of 0 in XEN_DOMCTL_createdomain.

I was planning to send a separate patch to address it if that's OK.

Quoted 10 lines

tools/tests/domid/harness.h extern unsigned long find_next_zero_bit(const unsigned long *addr, · line 44

Quoted 8 lines
tools/tests/domid/harness.h +1 -0
@@ -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                       DOMID_INVALID

... avoiding the need for any such secondary definitions.

Quoted 6 lines
Quoted 2 lines

In the current design, unit test harness.h has to define DOMID_ANY. Enabling xen/domain.h to compile for unit test is a separate task, IMO.

That wasn't suggested as an option. The #define wants to move back to the public header, but be properly guarded there. See the v1 replies you got.

Got it, thanks.
Will send v3.