diff mbox series

[v2,3/7] xen/domain: introduce domid_top()

Message ID 20250331230508.440198-4-dmukhin@ford.com (mailing list archive)
State New
Headers show
Series xen/console: cleanup console input switch logic | expand

Commit Message

Denis Mukhin March 31, 2025, 11:05 p.m. UTC
From: Denis Mukhin <dmukhin@ford.com>

Introduce domid_top() in architecture-independent location to retrieve
the highest non-system domain ID for use in console input switch logic.

Replace max_init_domid with domid_top(), which obsoletes max_init_domid
in the code base.

Signed-off-by: Denis Mukhin <dmukhin@ford.com>
---
Changes since v1:
- promote domid_top to a function which walks through the list of domains
  to identify the highest non-system domain ID which should be considered
  for console input rotation
- elimitate use of max_init_domid
---
 xen/arch/arm/include/asm/setup.h   |  2 --
 xen/arch/arm/setup.c               |  2 --
 xen/arch/ppc/include/asm/setup.h   |  2 --
 xen/arch/riscv/include/asm/setup.h |  2 --
 xen/arch/x86/include/asm/setup.h   |  2 --
 xen/common/domain.c                | 23 +++++++++++++++++++++++
 xen/drivers/char/console.c         |  2 +-
 xen/include/xen/domain.h           |  1 +
 8 files changed, 25 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/setup.h
index 6cf272c160..f107e8eebb 100644
--- a/xen/arch/arm/include/asm/setup.h
+++ b/xen/arch/arm/include/asm/setup.h
@@ -25,8 +25,6 @@  struct map_range_data
     struct rangeset *irq_ranges;
 };
 
-extern domid_t max_init_domid;
-
 void copy_from_paddr(void *dst, paddr_t paddr, unsigned long len);
 
 size_t estimate_efi_size(unsigned int mem_nr_banks);
diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
index bf39d41e9b..143808f592 100644
--- a/xen/arch/arm/setup.c
+++ b/xen/arch/arm/setup.c
@@ -60,8 +60,6 @@  struct cpuinfo_arm __read_mostly system_cpuinfo;
 bool __read_mostly acpi_disabled;
 #endif
 
-domid_t __read_mostly max_init_domid;
-
 static __used void init_done(void)
 {
     int rc;
diff --git a/xen/arch/ppc/include/asm/setup.h b/xen/arch/ppc/include/asm/setup.h
index e4f64879b6..956fa6985a 100644
--- a/xen/arch/ppc/include/asm/setup.h
+++ b/xen/arch/ppc/include/asm/setup.h
@@ -1,6 +1,4 @@ 
 #ifndef __ASM_PPC_SETUP_H__
 #define __ASM_PPC_SETUP_H__
 
-#define max_init_domid (0)
-
 #endif /* __ASM_PPC_SETUP_H__ */
diff --git a/xen/arch/riscv/include/asm/setup.h b/xen/arch/riscv/include/asm/setup.h
index c9d69cdf51..d1fc64b673 100644
--- a/xen/arch/riscv/include/asm/setup.h
+++ b/xen/arch/riscv/include/asm/setup.h
@@ -5,8 +5,6 @@ 
 
 #include <xen/types.h>
 
-#define max_init_domid (0)
-
 void setup_mm(void);
 
 void copy_from_paddr(void *dst, paddr_t paddr, unsigned long len);
diff --git a/xen/arch/x86/include/asm/setup.h b/xen/arch/x86/include/asm/setup.h
index 5c2391a868..296348655b 100644
--- a/xen/arch/x86/include/asm/setup.h
+++ b/xen/arch/x86/include/asm/setup.h
@@ -69,6 +69,4 @@  extern bool opt_dom0_verbose;
 extern bool opt_dom0_cpuid_faulting;
 extern bool opt_dom0_msr_relaxed;
 
-#define max_init_domid (0)
-
 #endif
diff --git a/xen/common/domain.c b/xen/common/domain.c
index b07d70a7e3..8e8e784b46 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -111,6 +111,29 @@  int domid_alloc(int hint)
     return domid;
 }
 
+/*
+ * Retrieve the highest known non-system domain ID.
+ */
+domid_t domid_top(void)
+{
+    struct domain *d;
+    domid_t i = 0;
+
+    spin_lock(&domlist_update_lock);
+
+    for ( d = domain_list;
+          d && (d->domain_id < DOMID_FIRST_RESERVED);
+          d = d->next_in_list )
+    {
+        if ( i < d->domain_id )
+            i = d->domain_id;
+    }
+
+    spin_unlock(&domlist_update_lock);
+
+    return i;
+}
+
 /*
  * Insert a domain into the domlist/hash.  This allows the domain to be looked
  * up by domid, and therefore to be the subject of hypercalls/etc.
diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c
index b312a1223e..54163e93fb 100644
--- a/xen/drivers/char/console.c
+++ b/xen/drivers/char/console.c
@@ -472,7 +472,7 @@  static void cf_check dump_console_ring_key(unsigned char key)
  */
 static unsigned int __read_mostly console_rx = 0;
 
-#define max_console_rx (max_init_domid + 1)
+#define max_console_rx (domid_top() + 1)
 
 static struct domain *console_get_domain_by_id(domid_t domid)
 {
diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h
index 9b7159a743..c3dda8edf2 100644
--- a/xen/include/xen/domain.h
+++ b/xen/include/xen/domain.h
@@ -35,6 +35,7 @@  void getdomaininfo(struct domain *d, struct xen_domctl_getdomaininfo *info);
 void arch_get_domain_info(const struct domain *d,
                           struct xen_domctl_getdomaininfo *info);
 
+domid_t domid_top(void);
 domid_t get_initial_domain_id(void);
 
 #define DOMID_AUTO               (-1)