[PATCH v2 13/26] xen/domctl: wrap sched_adjust() with CONFIG_MGMT_HYPERCALLS

Penny Zheng posted 26 patches 3 days, 22 hours ago
[PATCH v2 13/26] xen/domctl: wrap sched_adjust() with CONFIG_MGMT_HYPERCALLS
Posted by Penny Zheng 3 days, 22 hours ago
Function sched_adjust() is responsible for XEN_DOMCTL_scheduler_op domctl-op,
so it could be wrapped with CONFIG_MGMT_HYPERCALLS.
Tracing its calling chain, the following functions shall be wrapped with
CONFIG_MGMT_HYPERCALLS too:
- sched_adjust_dom()
- scheduler-specific .adjust() callback
- xsm_sysctl_scheduler_op()
Wrap XEN_DOMCTL_scheduler_op-case transiently with CONFIG_MGMT_HYPERCALLS,
and it will be removed when introducing CONFIG_MGMT_HYPERCALLS on the
common/domctl.c in the last.

Signed-off-by: Penny Zheng <Penny.Zheng@amd.com>
---
v1 -> v2:
- adapt to changes of "unify DOMCTL to MGMT_HYPERCALLS"
- wrap XEN_DOMCTL_scheduler_op-case transiently
---
 xen/common/domctl.c         | 2 +-
 xen/common/sched/arinc653.c | 2 +-
 xen/common/sched/core.c     | 2 --
 xen/common/sched/credit.c   | 4 ++++
 xen/common/sched/credit2.c  | 4 ++++
 xen/common/sched/private.h  | 4 +++-
 xen/common/sched/rt.c       | 4 ++++
 xen/include/xsm/xsm.h       | 4 ++--
 xen/xsm/dummy.c             | 2 +-
 xen/xsm/flask/hooks.c       | 4 ++--
 10 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/xen/common/domctl.c b/xen/common/domctl.c
index 4a35c17060..6660f13e9e 100644
--- a/xen/common/domctl.c
+++ b/xen/common/domctl.c
@@ -520,12 +520,12 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
     case XEN_DOMCTL_getvcpuaffinity:
         ret = vcpu_affinity_domctl(d, op->cmd, &op->u.vcpuaffinity);
         break;
-#endif /* CONFIG_MGMT_HYPERCALLS */
 
     case XEN_DOMCTL_scheduler_op:
         ret = sched_adjust(d, &op->u.scheduler_op);
         copyback = 1;
         break;
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
     case XEN_DOMCTL_getdomaininfo:
         ret = xsm_getdomaininfo(XSM_XS_PRIV, d);
diff --git a/xen/common/sched/arinc653.c b/xen/common/sched/arinc653.c
index 7d6c40d800..484591a977 100644
--- a/xen/common/sched/arinc653.c
+++ b/xen/common/sched/arinc653.c
@@ -735,8 +735,8 @@ static const struct scheduler sched_arinc653_def = {
 
     .switch_sched   = a653_switch_sched,
 
-    .adjust         = NULL,
 #ifdef CONFIG_MGMT_HYPERCALLS
+    .adjust         = NULL,
     .adjust_global  = a653sched_adjust_global,
 #endif
 
diff --git a/xen/common/sched/core.c b/xen/common/sched/core.c
index 69972147db..8a3251ce5f 100644
--- a/xen/common/sched/core.c
+++ b/xen/common/sched/core.c
@@ -2078,7 +2078,6 @@ int scheduler_id(void)
 {
     return operations.sched_id;
 }
-#endif
 
 /* Adjust scheduling parameter for a given domain. */
 long sched_adjust(struct domain *d, struct xen_domctl_scheduler_op *op)
@@ -2115,7 +2114,6 @@ long sched_adjust(struct domain *d, struct xen_domctl_scheduler_op *op)
     return ret;
 }
 
-#ifdef CONFIG_MGMT_HYPERCALLS
 long sched_adjust_global(struct xen_sysctl_scheduler_op *op)
 {
     struct cpupool *pool;
diff --git a/xen/common/sched/credit.c b/xen/common/sched/credit.c
index 0cbec2a9c0..da57350cae 100644
--- a/xen/common/sched/credit.c
+++ b/xen/common/sched/credit.c
@@ -1183,6 +1183,7 @@ csched_unit_yield(const struct scheduler *ops, struct sched_unit *unit)
     set_bit(CSCHED_FLAG_UNIT_YIELD, &svc->flags);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static int cf_check
 csched_dom_cntl(
     const struct scheduler *ops,
@@ -1227,6 +1228,7 @@ csched_dom_cntl(
 
     return rc;
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static void cf_check
 csched_aff_cntl(const struct scheduler *ops, struct sched_unit *unit,
@@ -2288,7 +2290,9 @@ static const struct scheduler sched_credit_def = {
     .wake           = csched_unit_wake,
     .yield          = csched_unit_yield,
 
+#ifdef CONFIG_MGMT_HYPERCALLS
     .adjust         = csched_dom_cntl,
+#endif
     .adjust_affinity= csched_aff_cntl,
 #ifdef CONFIG_MGMT_HYPERCALLS
     .adjust_global  = csched_sys_cntl,
diff --git a/xen/common/sched/credit2.c b/xen/common/sched/credit2.c
index 307e63ebd8..73df429b42 100644
--- a/xen/common/sched/credit2.c
+++ b/xen/common/sched/credit2.c
@@ -2909,6 +2909,7 @@ static void cf_check csched2_unit_migrate(
         sched_set_res(unit, get_sched_res(new_cpu));
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static int cf_check
 csched2_dom_cntl(
     const struct scheduler *ops,
@@ -3114,6 +3115,7 @@ csched2_dom_cntl(
 
     return rc;
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 static void cf_check
 csched2_aff_cntl(const struct scheduler *ops, struct sched_unit *unit,
@@ -4246,7 +4248,9 @@ static const struct scheduler sched_credit2_def = {
     .wake           = csched2_unit_wake,
     .yield          = csched2_unit_yield,
 
+#ifdef CONFIG_MGMT_HYPERCALLS
     .adjust         = csched2_dom_cntl,
+#endif
     .adjust_affinity= csched2_aff_cntl,
 #ifdef CONFIG_MGMT_HYPERCALLS
     .adjust_global  = csched2_sys_cntl,
diff --git a/xen/common/sched/private.h b/xen/common/sched/private.h
index b7ff67200b..15e69f5c2d 100644
--- a/xen/common/sched/private.h
+++ b/xen/common/sched/private.h
@@ -349,9 +349,11 @@ struct scheduler {
     void         (*migrate)        (const struct scheduler *ops,
                                     struct sched_unit *unit,
                                     unsigned int new_cpu);
+#ifdef CONFIG_MGMT_HYPERCALLS
     int          (*adjust)         (const struct scheduler *ops,
                                     struct domain *d,
                                     struct xen_domctl_scheduler_op *op);
+#endif
     void         (*adjust_affinity)(const struct scheduler *ops,
                                     struct sched_unit *unit,
                                     const struct cpumask *hard,
@@ -506,13 +508,13 @@ static inline void sched_adjust_affinity(const struct scheduler *s,
         s->adjust_affinity(s, unit, hard, soft);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static inline int sched_adjust_dom(const struct scheduler *s, struct domain *d,
                                    struct xen_domctl_scheduler_op *op)
 {
     return s->adjust ? s->adjust(s, d, op) : 0;
 }
 
-#ifdef CONFIG_MGMT_HYPERCALLS
 static inline int sched_adjust_cpupool(const struct scheduler *s,
                                        struct xen_sysctl_scheduler_op *op)
 {
diff --git a/xen/common/sched/rt.c b/xen/common/sched/rt.c
index 7b1f64a779..a42040b259 100644
--- a/xen/common/sched/rt.c
+++ b/xen/common/sched/rt.c
@@ -1362,6 +1362,7 @@ out:
     unit_schedule_unlock_irq(lock, unit);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 /*
  * set/get each unit info of each domain
  */
@@ -1471,6 +1472,7 @@ rt_dom_cntl(
 
     return rc;
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 /*
  * The replenishment timer handler picks units
@@ -1572,7 +1574,9 @@ static const struct scheduler sched_rtds_def = {
     .insert_unit    = rt_unit_insert,
     .remove_unit    = rt_unit_remove,
 
+#ifdef CONFIG_MGMT_HYPERCALLS
     .adjust         = rt_dom_cntl,
+#endif
 
     .pick_resource  = rt_res_pick,
     .do_schedule    = rt_schedule,
diff --git a/xen/include/xsm/xsm.h b/xen/include/xsm/xsm.h
index 1e4647f7db..4d332ceca2 100644
--- a/xen/include/xsm/xsm.h
+++ b/xen/include/xsm/xsm.h
@@ -56,8 +56,8 @@ struct xsm_ops {
                                 struct xen_domctl_getdomaininfo *info);
     int (*domain_create)(struct domain *d, uint32_t ssidref);
     int (*getdomaininfo)(struct domain *d);
-    int (*domctl_scheduler_op)(struct domain *d, int op);
 #ifdef CONFIG_MGMT_HYPERCALLS
+    int (*domctl_scheduler_op)(struct domain *d, int op);
     int (*sysctl_scheduler_op)(int op);
 #endif
     int (*set_target)(struct domain *d, struct domain *e);
@@ -240,13 +240,13 @@ static inline int xsm_get_domain_state(xsm_default_t def, struct domain *d)
     return alternative_call(xsm_ops.get_domain_state, d);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static inline int xsm_domctl_scheduler_op(
     xsm_default_t def, struct domain *d, int cmd)
 {
     return alternative_call(xsm_ops.domctl_scheduler_op, d, cmd);
 }
 
-#ifdef CONFIG_MGMT_HYPERCALLS
 static inline int xsm_sysctl_scheduler_op(xsm_default_t def, int cmd)
 {
     return alternative_call(xsm_ops.sysctl_scheduler_op, cmd);
diff --git a/xen/xsm/dummy.c b/xen/xsm/dummy.c
index 2c70b979d6..2c878999a3 100644
--- a/xen/xsm/dummy.c
+++ b/xen/xsm/dummy.c
@@ -18,8 +18,8 @@ static const struct xsm_ops __initconst_cf_clobber dummy_ops = {
     .security_domaininfo           = xsm_security_domaininfo,
     .domain_create                 = xsm_domain_create,
     .getdomaininfo                 = xsm_getdomaininfo,
-    .domctl_scheduler_op           = xsm_domctl_scheduler_op,
 #ifdef CONFIG_MGMT_HYPERCALLS
+    .domctl_scheduler_op           = xsm_domctl_scheduler_op,
     .sysctl_scheduler_op           = xsm_sysctl_scheduler_op,
 #endif
     .set_target                    = xsm_set_target,
diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c
index ec3880f631..e8a4deb2ea 100644
--- a/xen/xsm/flask/hooks.c
+++ b/xen/xsm/flask/hooks.c
@@ -609,6 +609,7 @@ static int cf_check flask_getdomaininfo(struct domain *d)
     return current_has_perm(d, SECCLASS_DOMAIN, DOMAIN__GETDOMAININFO);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 static int cf_check flask_domctl_scheduler_op(struct domain *d, int op)
 {
     switch ( op )
@@ -626,7 +627,6 @@ static int cf_check flask_domctl_scheduler_op(struct domain *d, int op)
     }
 }
 
-#ifdef CONFIG_MGMT_HYPERCALLS
 static int cf_check flask_sysctl_scheduler_op(int op)
 {
     switch ( op )
@@ -1888,8 +1888,8 @@ static const struct xsm_ops __initconst_cf_clobber flask_ops = {
     .security_domaininfo = flask_security_domaininfo,
     .domain_create = flask_domain_create,
     .getdomaininfo = flask_getdomaininfo,
-    .domctl_scheduler_op = flask_domctl_scheduler_op,
 #ifdef CONFIG_MGMT_HYPERCALLS
+    .domctl_scheduler_op = flask_domctl_scheduler_op,
     .sysctl_scheduler_op = flask_sysctl_scheduler_op,
 #endif
     .set_target = flask_set_target,
-- 
2.34.1
Re: [PATCH v2 13/26] xen/domctl: wrap sched_adjust() with CONFIG_MGMT_HYPERCALLS
Posted by Jan Beulich 2 days, 19 hours ago
On 10.09.2025 09:38, Penny Zheng wrote:
> --- a/xen/common/sched/arinc653.c
> +++ b/xen/common/sched/arinc653.c
> @@ -735,8 +735,8 @@ static const struct scheduler sched_arinc653_def = {
>  
>      .switch_sched   = a653_switch_sched,
>  
> -    .adjust         = NULL,

This line can just be dropped, can't it? It doesn't need ...

>  #ifdef CONFIG_MGMT_HYPERCALLS
> +    .adjust         = NULL,

... re-adding here.

> @@ -2288,7 +2290,9 @@ static const struct scheduler sched_credit_def = {
>      .wake           = csched_unit_wake,
>      .yield          = csched_unit_yield,
>  
> +#ifdef CONFIG_MGMT_HYPERCALLS
>      .adjust         = csched_dom_cntl,
> +#endif
>      .adjust_affinity= csched_aff_cntl,
>  #ifdef CONFIG_MGMT_HYPERCALLS
>      .adjust_global  = csched_sys_cntl,

Again better to get away with just a single #ifdef, I suppose.

> @@ -4246,7 +4248,9 @@ static const struct scheduler sched_credit2_def = {
>      .wake           = csched2_unit_wake,
>      .yield          = csched2_unit_yield,
>  
> +#ifdef CONFIG_MGMT_HYPERCALLS
>      .adjust         = csched2_dom_cntl,
> +#endif
>      .adjust_affinity= csched2_aff_cntl,
>  #ifdef CONFIG_MGMT_HYPERCALLS
>      .adjust_global  = csched2_sys_cntl,

Same here.

> --- a/xen/common/sched/private.h
> +++ b/xen/common/sched/private.h
> @@ -349,9 +349,11 @@ struct scheduler {
>      void         (*migrate)        (const struct scheduler *ops,
>                                      struct sched_unit *unit,
>                                      unsigned int new_cpu);
> +#ifdef CONFIG_MGMT_HYPERCALLS
>      int          (*adjust)         (const struct scheduler *ops,
>                                      struct domain *d,
>                                      struct xen_domctl_scheduler_op *op);
> +#endif
>      void         (*adjust_affinity)(const struct scheduler *ops,
>                                      struct sched_unit *unit,
>                                      const struct cpumask *hard,

And here, even if the other #ifdef is (just) out of context.

Jan
Re: [PATCH v2 13/26] xen/domctl: wrap sched_adjust() with CONFIG_MGMT_HYPERCALLS
Posted by Stefano Stabellini 3 days, 4 hours ago
On Wed, 10 Sep 2025, Penny Zheng wrote:
> Function sched_adjust() is responsible for XEN_DOMCTL_scheduler_op domctl-op,
> so it could be wrapped with CONFIG_MGMT_HYPERCALLS.
> Tracing its calling chain, the following functions shall be wrapped with
> CONFIG_MGMT_HYPERCALLS too:
> - sched_adjust_dom()
> - scheduler-specific .adjust() callback
> - xsm_sysctl_scheduler_op()
> Wrap XEN_DOMCTL_scheduler_op-case transiently with CONFIG_MGMT_HYPERCALLS,
> and it will be removed when introducing CONFIG_MGMT_HYPERCALLS on the
> common/domctl.c in the last.
> 
> Signed-off-by: Penny Zheng <Penny.Zheng@amd.com>

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>