Skip to contentSkip to conversation

is_system_domain: replace open-coded instances

PATCH Superseded Daniel P. Smith 2 participants 3 messages Dec 20, 2021 – Dec 21, 2021

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 is_system_domain: replace open-coded instances

From: Christopher Clark <[email protected]>

This is a split out of the hyperlaunch dom0 series.

There were several instances of open-coded domid range checking. This commit replaces those with the is_system_domain or is_system_domid inline function.

---
 xen/arch/x86/cpu/mcheck/mce.c | 2 +-
 xen/arch/x86/cpu/vpmu.c       | 2 +-
 xen/common/domain.c           | 2 +-
 xen/common/domctl.c           | 4 ++--
 xen/common/sched/core.c       | 4 ++--
 xen/include/xen/sched.h       | 7 ++++++-
 6 files changed, 13 insertions(+), 8 deletions(-)
xen/arch/x86/cpu/mcheck/mce.c +1 -1
index 7f433343bc..5c1df39075 100644
@@ -1518,7 +1518,7 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc)
             d = rcu_lock_domain_by_any_id(mc_msrinject->mcinj_domid);
             if ( d == NULL )
             {
-                if ( mc_msrinject->mcinj_domid >= DOMID_FIRST_RESERVED )
+                if ( is_system_domid(mc_msrinject->mcinj_domid) )
                     return x86_mcerr("do_mca inject: incompatible flag "
                                      "MC_MSRINJ_F_GPADDR with domain %d",
                                      -EINVAL, domid);
xen/arch/x86/cpu/vpmu.c +1 -1
index 8ec4547bed..c6bfa5a00e 100644
@@ -188,7 +188,7 @@ void vpmu_do_interrupt(struct cpu_user_regs *regs)
      * in XENPMU_MODE_ALL, for everyone.
      */
     if ( (vpmu_mode & XENPMU_MODE_ALL) ||
-         (sampled->domain->domain_id >= DOMID_FIRST_RESERVED) )
+         is_system_domain(sampled->domain) )
     {
         sampling = choose_hwdom_vcpu();
         if ( !sampling )
xen/common/domain.c +1 -1
index 093bb4403f..347cc073aa 100644
@@ -583,7 +583,7 @@ struct domain *domain_create(domid_t domid,
     /* Sort out our idea of is_hardware_domain(). */
     if ( domid == 0 || domid == hardware_domid )
     {
-        if ( hardware_domid < 0 || hardware_domid >= DOMID_FIRST_RESERVED )
+        if ( hardware_domid < 0 || is_system_domid(hardware_domid) )
             panic("The value of hardware_dom must be a valid domain ID\n");
 
         old_hwdom = hardware_domain;
xen/common/domctl.c +2 -2
index 879a2adcbe..a3ad1f62b6 100644
@@ -52,7 +52,7 @@ static inline int is_free_domid(domid_t dom)
 {
     struct domain *d;
 
-    if ( dom >= DOMID_FIRST_RESERVED )
+    if ( is_system_domid(dom) )
         return 0;
 
     if ( (d = rcu_lock_domain_by_id(dom)) == NULL )
@@ -536,7 +536,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
         if ( !d )
         {
             ret = -EINVAL;
-            if ( op->domain >= DOMID_FIRST_RESERVED )
+            if ( is_system_domid(op->domain) )
                 break;
 
             rcu_read_lock(&domlist_read_lock);
xen/common/sched/core.c +2 -2
index 8f4b1ca10d..6ea8bcf62f 100644
@@ -821,7 +821,7 @@ int sched_init_domain(struct domain *d, unsigned int poolid)
     int ret;
 
     ASSERT(d->cpupool == NULL);
-    ASSERT(d->domain_id < DOMID_FIRST_RESERVED);
+    ASSERT(!is_system_domain(d));
 
     if ( (ret = cpupool_add_domain(d, poolid)) )
         return ret;
@@ -845,7 +845,7 @@ int sched_init_domain(struct domain *d, unsigned int poolid)
 
 void sched_destroy_domain(struct domain *d)
 {
-    ASSERT(d->domain_id < DOMID_FIRST_RESERVED);
+    ASSERT(!is_system_domain(d));
 
     if ( d->cpupool )
     {
xen/include/xen/sched.h +6 -1
index 28146ee404..0df72baf2e 100644
@@ -613,9 +613,14 @@ extern struct vcpu *idle_vcpu[NR_CPUS];
 #define is_idle_domain(d) ((d)->domain_id == DOMID_IDLE)
 #define is_idle_vcpu(v)   (is_idle_domain((v)->domain))
 
+static inline bool is_system_domid(domid_t id)
+{
+    return (id >= DOMID_FIRST_RESERVED);
+}
+
 static inline bool is_system_domain(const struct domain *d)
 {
-    return d->domain_id >= DOMID_FIRST_RESERVED;
+    return is_system_domid(d->domain_id);
 }
 
 #define DOMAIN_DESTROYED (1u << 31) /* assumes atomic_t is >= 32 bits */
Signature · 1 line
2.20.1
#1 lore raw
Quoted 10 lines · Daniel P. Smith

From: Christopher Clark <[email protected]>

This is a split out of the hyperlaunch dom0 series.

There were several instances of open-coded domid range checking. This commit replaces those with the is_system_domain or is_system_domid inline function.

While I'm not outright opposed, I'd still like to raise the question whether we really want to intermix "is system domain" and "is in-range domain ID" predicates. Personally I'd prefer the latter to remain open-coded range checks.

xen/include/xen/sched.h extern struct vcpu *idle_vcpu[NR_CPUS]; · line 618

Quoted 9 lines
xen/include/xen/sched.h +3 -0
@@ -613,9 +613,14 @@ extern struct vcpu *idle_vcpu[NR_CPUS];
 #define is_idle_domain(d) ((d)->domain_id == DOMID_IDLE)
 #define is_idle_vcpu(v)   (is_idle_domain((v)->domain))
 
+static inline bool is_system_domid(domid_t id)
+{
+    return (id >= DOMID_FIRST_RESERVED);

Nit: Generally we omit parentheses in cases like this, ...

xen/include/xen/sched.h extern struct vcpu *idle_vcpu[NR_CPUS]; · line 618

Quoted 5 lines
xen/include/xen/sched.h +2 -1
+}
+
 static inline bool is_system_domain(const struct domain *d)
 {
-    return d->domain_id >= DOMID_FIRST_RESERVED;

... just like was the case here.

Jan

#2 lore raw
Quoted 23 lines · Jan Beulich
Quoted 10 lines · Daniel P. Smith

From: Christopher Clark <[email protected]>

This is a split out of the hyperlaunch dom0 series.

There were several instances of open-coded domid range checking. This commit replaces those with the is_system_domain or is_system_domid inline function.

While I'm not outright opposed, I'd still like to raise the question whether we really want to intermix "is system domain" and "is in-range domain ID" predicates. Personally I'd prefer the latter to remain open-coded range checks.

Quoted 6 lines
xen/include/xen/sched.h +0 -0
@@ -613,9 +613,14 @@ extern struct vcpu *idle_vcpu[NR_CPUS];
  #define is_idle_domain(d) ((d)->domain_id == DOMID_IDLE)
  #define is_idle_vcpu(v)   (is_idle_domain((v)->domain))
 
Quoted 5 lines

xen/include/xen/sched.h extern struct vcpu *idle_vcpu[NR_CPUS]; · line 618

Quoted 3 lines
xen/include/xen/sched.h +3 -0
+static inline bool is_system_domid(domid_t id)
+{
+    return (id >= DOMID_FIRST_RESERVED);

Nit: Generally we omit parentheses in cases like this, ...

ack

Quoted 10 lines

xen/include/xen/sched.h extern struct vcpu *idle_vcpu[NR_CPUS]; · line 618

Quoted 5 lines
xen/include/xen/sched.h +2 -1
+}
+
  static inline bool is_system_domain(const struct domain *d)
  {
-    return d->domain_id >= DOMID_FIRST_RESERVED;

... just like was the case here.

Jan