Skip to contentSkip to conversation

Align handling of domctl/sysctl unsupported commands

PATCH In review Milan Djokic 4 participants 17 messages Dec 5, 2025 – Dec 9, 2025

lore
Share & tools
lore
#1 lore raw

PATCH 1/4 arm/domain: Update SBSA_VUART_CONSOLE config option handling

In reply to Milan Djokic

Update XEN_DOMCTL_vuart_op command handling to return -EOPNOTSUPP when vpl011 is disabled, informing the control domain that this feature is unavailable.
Added dom0less config sanity check for vpl011 property

---
 xen/arch/arm/dom0less-build.c     | 4 ++++
 xen/arch/arm/domctl.c             | 3 +++
 xen/arch/arm/include/asm/vpl011.h | 2 +-
 3 files changed, 8 insertions(+), 1 deletion(-)
xen/arch/arm/dom0less-build.c +4 -0
index 4181c10538..57980d2abe 100644
@@ -322,6 +322,10 @@ int __init arch_parse_dom0less_node(struct dt_device_node *node,
     if ( domu_dt_sci_parse(node, d_cfg) )
         panic("Error getting SCI configuration\n");
 
+    if ( dt_property_read_bool(node, "vpl011") &&
+         !IS_ENABLED(CONFIG_SBSA_VUART_CONSOLE) )
+        panic("'vpl011' property found, but CONFIG_SBSA_VUART_CONSOLE not selected\n");
+
     if ( !dt_property_read_u32(node, "nr_spis", &d_cfg->arch.nr_spis) )
     {
         int vpl011_virq = GUEST_VPL011_SPI;
xen/arch/arm/domctl.c +3 -0
index ad914c915f..250e20a9fb 100644
@@ -156,6 +156,9 @@ long arch_do_domctl(struct xen_domctl *domctl, struct domain *d,
         unsigned int i;
         struct xen_domctl_vuart_op *vuart_op = &domctl->u.vuart_op;
 
+        if ( !IS_ENABLED(CONFIG_SBSA_VUART_CONSOLE) )
+            return -EOPNOTSUPP;
+
         /* check that structure padding must be 0. */
         for ( i = 0; i < sizeof(vuart_op->pad); i++ )
             if ( vuart_op->pad[i] )
xen/arch/arm/include/asm/vpl011.h +1 -1
index cc83868281..b8f4d85651 100644
@@ -74,7 +74,7 @@ int vpl011_rx_char_xen(struct domain *d, char c);
 static inline int domain_vpl011_init(struct domain *d,
                                      struct vpl011_init_info *info)
 {
-    return -ENOSYS;
+    return -EOPNOTSUPP;
 }
 
 static inline void domain_vpl011_deinit(struct domain *d) { }
Signature · 1 line
2.43.0
#9 lore raw

PATCH 3/4 domctl: Provide appropriate error code when VM events are not supported

In reply to Milan Djokic

Return -EOPNOTSUPP when XEN_DOMCTL_set_access_required command is invoked while VM events and monitoring support is disabled.

---
 xen/common/domctl.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
xen/common/domctl.c +11 -8
index 159864bc99..5284524b42 100644
@@ -787,19 +787,22 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
             copyback = true;
         break;
 
-#ifdef CONFIG_VM_EVENT
     case XEN_DOMCTL_set_access_required:
-        if ( unlikely(current->domain == d) ) /* no domain_pause() */
-            ret = -EPERM;
+        if ( !IS_ENABLED(CONFIG_VM_EVENT) )
+            ret = -EOPNOTSUPP;
         else
         {
-            domain_pause(d);
-            arch_p2m_set_access_required(d,
-                op->u.access_required.access_required);
-            domain_unpause(d);
+            if ( unlikely(current->domain == d) ) /* no domain_pause() */
+                ret = -EPERM;
+            else
+            {
+                domain_pause(d);
+                arch_p2m_set_access_required(d,
+                    op->u.access_required.access_required);
+                domain_unpause(d);
+            }
         }
         break;
-#endif
 
     case XEN_DOMCTL_set_virq_handler:
         ret = set_global_virq_handler(d, op->u.set_virq_handler.virq);
Signature · 1 line
2.43.0
#4 lore raw

PATCH 2/4 domctl: Provide appropriate error code when PIRQs are not supported

In reply to Milan Djokic

When PIRQs are not supported (e.g. for arm), XEN_DOMCTL_irq_permission command is not handled.
This results with default (-ENOSYS) error code returned to control domain. Update command handling to return -EOPNOTSUPP if control domain invokes it by mistake when PIRQs are not supported.
Also exclude xsm_irq_permission hooks from compilation when PIRQs are not supported.

---
 xen/common/domctl.c     | 6 ++++--
 xen/include/xsm/dummy.h | 4 ++--
 xen/include/xsm/xsm.h   | 6 ++++--
 xen/xsm/dummy.c         | 2 ++
 xen/xsm/flask/hooks.c   | 5 ++++-
 5 files changed, 16 insertions(+), 7 deletions(-)
xen/common/domctl.c +4 -2
index 29a7726d32..159864bc99 100644
@@ -638,9 +638,9 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
         }
         break;
 
-#ifdef CONFIG_HAS_PIRQ
     case XEN_DOMCTL_irq_permission:
     {
+#ifdef CONFIG_HAS_PIRQ
         unsigned int pirq = op->u.irq_permission.pirq, irq;
         int allow = op->u.irq_permission.allow_access;
 
@@ -656,9 +656,11 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
             ret = irq_permit_access(d, irq);
         else
             ret = irq_deny_access(d, irq);
+#else
+        ret = -EOPNOTSUPP;
+#endif
         break;
     }
-#endif
 
     case XEN_DOMCTL_iomem_permission:
     {
xen/include/xsm/dummy.h +2 -2
index e801dbcdba..6f6de161f9 100644
@@ -555,14 +555,14 @@ static XSM_INLINE int cf_check xsm_unmap_domain_irq(
     XSM_ASSERT_ACTION(XSM_HOOK);
     return xsm_default_action(action, current->domain, d);
 }
-
+#ifdef CONFIG_HAS_PIRQ
 static XSM_INLINE int cf_check xsm_irq_permission(
     XSM_DEFAULT_ARG struct domain *d, int pirq, uint8_t allow)
 {
     XSM_ASSERT_ACTION(XSM_HOOK);
     return xsm_default_action(action, current->domain, d);
 }
-
+#endif
 static XSM_INLINE int cf_check xsm_iomem_permission(
     XSM_DEFAULT_ARG struct domain *d, uint64_t s, uint64_t e, uint8_t allow)
 {
xen/include/xsm/xsm.h +4 -2
index 2d831d7745..b85cf9933a 100644
@@ -113,7 +113,9 @@ struct xsm_ops {
     int (*unmap_domain_irq)(struct domain *d, int irq, const void *data);
     int (*bind_pt_irq)(struct domain *d, struct xen_domctl_bind_pt_irq *bind);
     int (*unbind_pt_irq)(struct domain *d, struct xen_domctl_bind_pt_irq *bind);
+#ifdef CONFIG_HAS_PIRQ
     int (*irq_permission)(struct domain *d, int pirq, uint8_t allow);
+#endif
     int (*iomem_permission)(struct domain *d, uint64_t s, uint64_t e,
                             uint8_t allow);
     int (*iomem_mapping)(struct domain *d, uint64_t s, uint64_t e,
@@ -504,13 +506,13 @@ static inline int xsm_unbind_pt_irq(
 {
     return alternative_call(xsm_ops.unbind_pt_irq, d, bind);
 }
-
+#ifdef CONFIG_HAS_PIRQ
 static inline int xsm_irq_permission(
     xsm_default_t def, struct domain *d, int pirq, uint8_t allow)
 {
     return alternative_call(xsm_ops.irq_permission, d, pirq, allow);
 }
-
+#endif
 static inline int xsm_iomem_permission(
     xsm_default_t def, struct domain *d, uint64_t s, uint64_t e, uint8_t allow)
 {
xen/xsm/dummy.c +2 -0
index 96dc82ac2e..28ef4a0beb 100644
@@ -73,7 +73,9 @@ static const struct xsm_ops __initconst_cf_clobber dummy_ops = {
     .unmap_domain_irq              = xsm_unmap_domain_irq,
     .bind_pt_irq                   = xsm_bind_pt_irq,
     .unbind_pt_irq                 = xsm_unbind_pt_irq,
+#ifdef CONFIG_HAS_PIRQ
     .irq_permission                = xsm_irq_permission,
+#endif
     .iomem_permission              = xsm_iomem_permission,
     .iomem_mapping                 = xsm_iomem_mapping,
     .pci_config_permission         = xsm_pci_config_permission,
xen/xsm/flask/hooks.c +4 -1
index 9f3915617c..63e4b4c353 100644
@@ -1110,13 +1110,14 @@ static int cf_check flask_unbind_pt_irq(
 {
     return current_has_perm(d, SECCLASS_RESOURCE, RESOURCE__REMOVE);
 }
-
+#ifdef CONFIG_HAS_PIRQ
 static int cf_check flask_irq_permission(
     struct domain *d, int pirq, uint8_t access)
 {
     /* the PIRQ number is not useful; real IRQ is checked during mapping */
     return current_has_perm(d, SECCLASS_RESOURCE, resource_to_perm(access));
 }
+#endif
 
 struct iomem_has_perm_data {
     uint32_t ssid;
@@ -1943,7 +1944,9 @@ static const struct xsm_ops __initconst_cf_clobber flask_ops = {
     .unmap_domain_irq = flask_unmap_domain_irq,
     .bind_pt_irq = flask_bind_pt_irq,
     .unbind_pt_irq = flask_unbind_pt_irq,
+#ifdef CONFIG_HAS_PIRQ
     .irq_permission = flask_irq_permission,
+#endif
     .iomem_permission = flask_iomem_permission,
     .iomem_mapping = flask_iomem_mapping,
     .pci_config_permission = flask_pci_config_permission,
Signature · 1 line
2.43.0
#0 lore raw

cover Align handling of domctl/sysctl unsupported commands

This patch series provides minor updates to the domctl and sysctl handling of unsupported commands. Currently the behavior diverges: some commands return -EOPNOTSUPP, while others fall back to the generic -ENOSYS. This series aligns the behavior so that unsupported commands consistently return the appropriate error code, allowing the control domain to correctly identify unsupported operations.

Where possible, IS_ENABLED() is used to detect disabled commands at compile time, enabling dead code elimination. For commands where stubs are provided, the stub functions are updated to return the correct error code.

The only exception is XEN_DOMCTL_irq_permission, which cannot use IS_ENABLED() due to PIRQ-specific structures being unavailable when PIRQ support is off. In this case, classic #ifdef blocks remain in place.

There may be future updates in this regard. This initial series is intended to get maintainers' feedback on the approach taken.

Milan Djokic (4):
arm/domain: Update SBSA_VUART_CONSOLE config option handling
domctl: Provide appropriate error code when PIRQs are not supported
domctl: Provide appropriate error code when VM events are not
supported
sysctl: align handling of unsupported commands

 xen/arch/arm/dom0less-build.c     |  4 ++++
 xen/arch/arm/domctl.c             |  3 +++
 xen/arch/arm/include/asm/vpl011.h |  2 +-
 xen/common/domctl.c               | 25 ++++++++++++++---------
 xen/common/sysctl.c               | 34 ++++++++++++++++++-------------
 xen/include/xen/livepatch.h       |  2 +-
 xen/include/xen/perfc.h           |  4 +++-
 xen/include/xen/spinlock.h        |  6 +++---
 xen/include/xen/trace.h           |  2 +-
 xen/include/xsm/dummy.h           |  4 ++--
 xen/include/xsm/xsm.h             |  6 ++++--
 xen/xsm/dummy.c                   |  2 ++
 xen/xsm/flask/hooks.c             |  5 ++++-
 13 files changed, 63 insertions(+), 36 deletions(-)
Signature · 1 line
2.43.0
#12 lore raw

PATCH 4/4 sysctl: align handling of unsupported commands

Handling of unsupported sysctl commands currently diverges: some commands return -EOPNOTSUPP, while others fall back to generic -ENOSYS.

Unify the behavior so that unsupported commands consistently return the appropriate error code, allowing the control domain to correctly identify unsupported operations.

Using IS_ENABLED() macro to identify disabled commands, allowing dead code to be removed at compile time.

---
 xen/common/sysctl.c         | 34 ++++++++++++++++++++--------------
 xen/include/xen/livepatch.h |  2 +-
 xen/include/xen/perfc.h     |  4 +++-
 xen/include/xen/spinlock.h  |  6 +++---
 xen/include/xen/trace.h     |  2 +-
 5 files changed, 28 insertions(+), 20 deletions(-)
xen/common/sysctl.c +20 -14
index 5207664252..1c4e0b60d8 100644
@@ -113,17 +113,20 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
     }
     break;
 
-#ifdef CONFIG_PERF_COUNTERS
     case XEN_SYSCTL_perfc_op:
-        ret = perfc_control(&op->u.perfc_op);
+        if ( !IS_ENABLED(CONFIG_PERF_COUNTERS) )
+            ret = -EOPNOTSUPP;
+        else
+            ret = perfc_control(&op->u.perfc_op);
         break;
-#endif
 
-#ifdef CONFIG_DEBUG_LOCK_PROFILE
     case XEN_SYSCTL_lockprof_op:
-        ret = spinlock_profile_control(&op->u.lockprof_op);
+        if ( !IS_ENABLED(CONFIG_DEBUG_LOCK_PROFILE) )
+            ret = -EOPNOTSUPP;
+        else
+            ret = spinlock_profile_control(&op->u.lockprof_op);
         break;
-#endif
+
     case XEN_SYSCTL_debug_keys:
     {
         char c;
@@ -170,19 +173,22 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
         op->u.availheap.avail_bytes <<= PAGE_SHIFT;
         break;
 
-#ifdef CONFIG_PM_STATS
     case XEN_SYSCTL_get_pmstat:
-        ret = do_get_pm_info(&op->u.get_pmstat);
+        if ( !IS_ENABLED(CONFIG_PM_STATS) )
+            ret = -EOPNOTSUPP;
+        else
+            ret = do_get_pm_info(&op->u.get_pmstat);
         break;
-#endif
 
-#ifdef CONFIG_PM_OP
     case XEN_SYSCTL_pm_op:
-        ret = do_pm_op(&op->u.pm_op);
-        if ( ret == -EAGAIN )
-            copyback = 1;
+        if ( !IS_ENABLED(CONFIG_PM_OP) )
+            ret = -EOPNOTSUPP;
+        else {
+            ret = do_pm_op(&op->u.pm_op);
+            if ( ret == -EAGAIN )
+                copyback = 1;
+        }
         break;
-#endif
 
     case XEN_SYSCTL_page_offline_op:
     {
xen/include/xen/livepatch.h +1 -1
index d074a5bebe..1601b860d8 100644
@@ -157,7 +157,7 @@ void revert_payload_tail(struct payload *data);
 
 static inline int livepatch_op(struct xen_sysctl_livepatch_op *op)
 {
-    return -ENOSYS;
+    return -EOPNOTSUPP;
 }
 
 static inline void check_for_livepatch_work(void) {}
xen/include/xen/perfc.h +3 -1
index bf0eb032f7..a44c2f74a1 100644
@@ -92,7 +92,6 @@ DECLARE_PER_CPU(perfc_t[NUM_PERFCOUNTERS], perfcounters);
 #endif
 
 struct xen_sysctl_perfc_op;
-int perfc_control(struct xen_sysctl_perfc_op *pc);
 
 extern void cf_check perfc_printall(unsigned char key);
 extern void cf_check perfc_reset(unsigned char key);
@@ -114,4 +113,7 @@ extern void cf_check perfc_reset(unsigned char key);
 
 #endif /* CONFIG_PERF_COUNTERS */
 
+struct xen_sysctl_perfc_op;
+extern int perfc_control(struct xen_sysctl_perfc_op *pc);
+
 #endif /* __XEN_PERFC_H__ */
xen/include/xen/spinlock.h +3 -3
index ca9d8c7ec0..10ee81b7db 100644
@@ -7,6 +7,7 @@
 
 #include <asm/system.h>
 #include <asm/spinlock.h>
+#include <public/sysctl.h>
 
 #define SPINLOCK_CPU_BITS  16
 
@@ -40,8 +41,6 @@ union lock_debug { };
 
 #ifdef CONFIG_DEBUG_LOCK_PROFILE
 
-#include <public/sysctl.h>
-
 /*
     lock profiling on:
 
@@ -164,7 +163,6 @@ void _lock_profile_deregister_struct(int32_t type,
 #define lock_profile_deregister_struct(type, ptr)                             \
     _lock_profile_deregister_struct(type, &((ptr)->profile_head))
 
-extern int spinlock_profile_control(struct xen_sysctl_lockprof_op *pc);
 extern void cf_check spinlock_profile_printall(unsigned char key);
 extern void cf_check spinlock_profile_reset(unsigned char key);
 
@@ -360,4 +358,6 @@ static always_inline void nrspin_lock_irq(rspinlock_t *l)
 #define nrspin_unlock_irqrestore(l, f) _nrspin_unlock_irqrestore(l, f)
 #define nrspin_unlock_irq(l)           _nrspin_unlock_irq(l)
 
+extern int spinlock_profile_control(struct xen_sysctl_lockprof_op *pc);
+
 #endif /* __SPINLOCK_H__ */
xen/include/xen/trace.h +1 -1
index 30ebdcc47f..fff3a4f451 100644
@@ -48,7 +48,7 @@ void __trace_hypercall(uint32_t event, unsigned long op,
 
 static inline int tb_control(struct xen_sysctl_tbuf_op *tbc)
 {
-    return -ENOSYS;
+    return -EOPNOTSUPP;
 }
 
 static inline int trace_will_trace_event(uint32_t event)
Signature · 1 line
2.43.0
#5 lore raw

Re: [PATCH 2/4] domctl: Provide appropriate error code when PIRQs are not supported

In reply to Milan Djokic
Quoted 5 lines · Milan Djokic

When PIRQs are not supported (e.g. for arm), XEN_DOMCTL_irq_permission command is not handled.
This results with default (-ENOSYS) error code returned to control domain. Update command handling to return -EOPNOTSUPP if control domain invokes it by mistake when PIRQs are not supported.

Did you consider simply replacing the bogus ENOSYS by EOPNOTSUPP? (Assuming the difference in error code really makes a difference to callers.)

Quoted 9 lines
xen/include/xsm/dummy.h +1 -1
@@ -555,14 +555,14 @@ static XSM_INLINE int cf_check xsm_unmap_domain_irq(
     XSM_ASSERT_ACTION(XSM_HOOK);
     return xsm_default_action(action, current->domain, d);
 }
-
+#ifdef CONFIG_HAS_PIRQ
 static XSM_INLINE int cf_check xsm_irq_permission(

xen/include/xsm/dummy.h static XSM_INLINE int cf_check xsm_unmap_domain_irq( · line 568

Quoted 10 lines
xen/include/xsm/dummy.h +1 -1
     XSM_DEFAULT_ARG struct domain *d, int pirq, uint8_t allow)
 {
     XSM_ASSERT_ACTION(XSM_HOOK);
     return xsm_default_action(action, current->domain, d);
 }
-
+#endif
 static XSM_INLINE int cf_check xsm_iomem_permission(
     XSM_DEFAULT_ARG struct domain *d, uint64_t s, uint64_t e, uint8_t allow)
 {

Why would you zap blank lines like this (also elsewhere)?

Jan

#10 lore raw

Re: [PATCH 3/4] domctl: Provide appropriate error code when VM events are not supported

In reply to Milan Djokic
Quoted 2 lines · Milan Djokic

Return -EOPNOTSUPP when XEN_DOMCTL_set_access_required command is invoked while VM events and monitoring support is disabled.

This is more bounded than the pretty wide subject. Taking the subject and considering there are other VM_EVENT related domctl-s, is this one really the only one in need of adjustment?

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 793

Quoted 13 lines
xen/common/domctl.c +2 -3
@@ -787,19 +787,22 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
             copyback = true;
         break;
 
-#ifdef CONFIG_VM_EVENT
     case XEN_DOMCTL_set_access_required:
-        if ( unlikely(current->domain == d) ) /* no domain_pause() */
-            ret = -EPERM;
+        if ( !IS_ENABLED(CONFIG_VM_EVENT) )
+            ret = -EOPNOTSUPP;
         else

If you convert this to

        else if ( unlikely(current->domain == d) ) /* no domain_pause() */

then ...

Quoted 4 lines
xen/common/domctl.c +0 -3
         {
-            domain_pause(d);
-            arch_p2m_set_access_required(d,
-                op->u.access_required.access_required);

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 803

Quoted 10 lines
xen/common/domctl.c +9 -1
-            domain_unpause(d);
+            if ( unlikely(current->domain == d) ) /* no domain_pause() */
+                ret = -EPERM;
+            else
+            {
+                domain_pause(d);
+                arch_p2m_set_access_required(d,
+                    op->u.access_required.access_required);
+                domain_unpause(d);
+            }

... the need for re-indenting disappears, and we get away with less churn.

Jan

#13 lore raw

Re: [PATCH 4/4] sysctl: align handling of unsupported commands

In reply to Milan Djokic
Quoted 11 lines · Milan Djokic

Handling of unsupported sysctl commands currently diverges: some commands return -EOPNOTSUPP, while others fall back to generic -ENOSYS.

Unify the behavior so that unsupported commands consistently return the appropriate error code, allowing the control domain to correctly identify unsupported operations.

Using IS_ENABLED() macro to identify disabled commands, allowing dead code to be removed at compile time.

Overall quite okay imo, yet there are a number of small issues.

Quoted 12 lines
xen/common/sysctl.c +4 -2
@@ -170,19 +173,22 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
         op->u.availheap.avail_bytes <<= PAGE_SHIFT;
         break;
 
-#ifdef CONFIG_PM_STATS
     case XEN_SYSCTL_get_pmstat:
-        ret = do_get_pm_info(&op->u.get_pmstat);
+        if ( !IS_ENABLED(CONFIG_PM_STATS) )
+            ret = -EOPNOTSUPP;
+        else
+            ret = do_get_pm_info(&op->u.get_pmstat);
         break;

xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) · line 186

Quoted 10 lines
xen/common/sysctl.c +3 -5
-#endif
 
-#ifdef CONFIG_PM_OP
     case XEN_SYSCTL_pm_op:
-        ret = do_pm_op(&op->u.pm_op);
-        if ( ret == -EAGAIN )
-            copyback = 1;
+        if ( !IS_ENABLED(CONFIG_PM_OP) )
+            ret = -EOPNOTSUPP;
+        else {

Misplaced figure brace.

Quoted 11 lines
xen/include/xen/perfc.h +0 -1
@@ -92,7 +92,6 @@ DECLARE_PER_CPU(perfc_t[NUM_PERFCOUNTERS], perfcounters);
 #endif
 
 struct xen_sysctl_perfc_op;
-int perfc_control(struct xen_sysctl_perfc_op *pc);
 
 extern void cf_check perfc_printall(unsigned char key);
 extern void cf_check perfc_reset(unsigned char key);

xen/include/xen/perfc.h extern void cf_check perfc_reset(unsigned char key); · line 117

Quoted 5 lines
xen/include/xen/perfc.h +2 -0
@@ -114,4 +113,7 @@ extern void cf_check perfc_reset(unsigned char key);
 
 #endif /* CONFIG_PERF_COUNTERS */
 
+struct xen_sysctl_perfc_op;
+extern int perfc_control(struct xen_sysctl_perfc_op *pc);

Why would you move the function decl, but duplicate the struct forward decl?

xen/include/xen/spinlock.h line 10

Quoted 7 lines
xen/include/xen/spinlock.h +1 -0
@@ -7,6 +7,7 @@
 
 #include <asm/system.h>
 #include <asm/spinlock.h>
+#include <public/sysctl.h>

Why would this be needed? It means effectively the whole codebase gains a dependency on this header even when DEBUG_LOCK_PROFILE=n. Yes, you may need ...

Quoted 18 lines
xen/include/xen/spinlock.h +0 -3
@@ -40,8 +41,6 @@ union lock_debug { };
 
 #ifdef CONFIG_DEBUG_LOCK_PROFILE
 
-#include <public/sysctl.h>
-
 /*
     lock profiling on:
 
@@ -164,7 +163,6 @@ void _lock_profile_deregister_struct(int32_t type,
 #define lock_profile_deregister_struct(type, ptr)                             \
     _lock_profile_deregister_struct(type, &((ptr)->profile_head))
 
-extern int spinlock_profile_control(struct xen_sysctl_lockprof_op *pc);
 extern void cf_check spinlock_profile_printall(unsigned char key);
 extern void cf_check spinlock_profile_reset(unsigned char key);
 

xen/include/xen/spinlock.h static always_inline void nrspin_lock_irq(rspinlock_t *l) · line 363

Quoted 6 lines
xen/include/xen/spinlock.h +2 -0
@@ -360,4 +358,6 @@ static always_inline void nrspin_lock_irq(rspinlock_t *l)
 #define nrspin_unlock_irqrestore(l, f) _nrspin_unlock_irqrestore(l, f)
 #define nrspin_unlock_irq(l)           _nrspin_unlock_irq(l)
 
+extern int spinlock_profile_control(struct xen_sysctl_lockprof_op *pc);
+
 #endif /* __SPINLOCK_H__ */

... a forward decl of struct xen_sysctl_lockprof_op; I don't see what's wrong with doing just that.

Jan

#15 lore raw
In reply to Milan Djokic
Quoted 6 lines · Milan Djokic

This patch series provides minor updates to the domctl and sysctl handling of unsupported commands. Currently the behavior diverges: some commands return -EOPNOTSUPP, while others fall back to the generic -ENOSYS. This series aligns the behavior so that unsupported commands consistently return the appropriate error code, allowing the control domain to correctly identify unsupported operations.

What, even after having looked at all the patches (and their descriptions), still isn't clear to me is why the distinction ENOSYS vs EOPNOTSUPP would matter. Tool stacks still need to be prepared to get back ENOSYS, at the very least as long as they mean to run on older hypervisors as well. And with Penny's work to allow excluding domctl/sysctl altogether, I expect ENOSYS would then also be what results if that option is made use of.

Jan

#2 lore raw

Re: [PATCH 1/4] arm/domain: Update SBSA_VUART_CONSOLE config option handling

In reply to Milan Djokic
Quoted 17 lines · Milan Djokic

Update XEN_DOMCTL_vuart_op command handling to return -EOPNOTSUPP when vpl011 is disabled, informing the control domain that this feature is unavailable.
Added dom0less config sanity check for vpl011 property

---
 xen/arch/arm/dom0less-build.c     | 4 ++++
 xen/arch/arm/domctl.c             | 3 +++
 xen/arch/arm/include/asm/vpl011.h | 2 +-
 3 files changed, 8 insertions(+), 1 deletion(-)
xen/arch/arm/dom0less-build.c +0 -0
index 4181c10538..57980d2abe 100644

xen/arch/arm/dom0less-build.c int __init arch_parse_dom0less_node(struct dt_device_node *node, · line 327

Quoted 6 lines
xen/arch/arm/dom0less-build.c +3 -0
@@ -322,6 +322,10 @@ int __init arch_parse_dom0less_node(struct dt_device_node *node,
     if ( domu_dt_sci_parse(node, d_cfg) )
         panic("Error getting SCI configuration\n");
 
+    if ( dt_property_read_bool(node, "vpl011") &&
+         !IS_ENABLED(CONFIG_SBSA_VUART_CONSOLE) )
+        panic("'vpl011' property found, but CONFIG_SBSA_VUART_CONSOLE not selected\n");

I don't think there is a need for another dt property reading. In init_vuart() we read this property and if present we call domain_vpl011_init. This function returns (thanks to your change) -EOPNOTSUPP, so we already cover both cases. No need for an explicit panic.

Quoted 9 lines
xen/arch/arm/dom0less-build.c +1 -0
+
     if ( !dt_property_read_u32(node, "nr_spis", &d_cfg->arch.nr_spis) )
     {
         int vpl011_virq = GUEST_VPL011_SPI;
xen/arch/arm/domctl.c +0 -0
index ad914c915f..250e20a9fb 100644

xen/arch/arm/domctl.c long arch_do_domctl(struct xen_domctl *domctl, struct domain *d, · line 160

Quoted 5 lines
xen/arch/arm/domctl.c +2 -0
@@ -156,6 +156,9 @@ long arch_do_domctl(struct xen_domctl *domctl, struct domain *d,
         unsigned int i;
         struct xen_domctl_vuart_op *vuart_op = &domctl->u.vuart_op;
 
+        if ( !IS_ENABLED(CONFIG_SBSA_VUART_CONSOLE) )
+            return -EOPNOTSUPP;

Why is this needed? Later on in this path we will call domain_vpl011_init that will return exactly the same if CONFIG_SBSA_VUART_CONSOLE is not enabled.

Quoted 9 lines
xen/arch/arm/domctl.c +1 -0
+
         /* check that structure padding must be 0. */
         for ( i = 0; i < sizeof(vuart_op->pad); i++ )
             if ( vuart_op->pad[i] )
xen/arch/arm/include/asm/vpl011.h +0 -0
index cc83868281..b8f4d85651 100644

xen/arch/arm/include/asm/vpl011.h int vpl011_rx_char_xen(struct domain *d, char c); · line 77

Quoted 5 lines
xen/arch/arm/include/asm/vpl011.h +1 -1
@@ -74,7 +74,7 @@ int vpl011_rx_char_xen(struct domain *d, char c);
 static inline int domain_vpl011_init(struct domain *d,
                                      struct vpl011_init_info *info)
 {
-    return -ENOSYS;
+    return -EOPNOTSUPP;

This change is ok.

~Michal

#8 lore raw

Re: [PATCH 2/4] domctl: Provide appropriate error code when PIRQs are not supported

In reply to Milan Djokic

Hi Milan,

Thank you for your patch.

Quoted 8 lines · Milan Djokic

When PIRQs are not supported (e.g. for arm), XEN_DOMCTL_irq_permission command is not handled.
This results with default (-ENOSYS) error code returned to control domain. Update command handling to return -EOPNOTSUPP if control domain invokes it by mistake when PIRQs are not supported.

Also exclude xsm_irq_permission hooks from compilation when PIRQs are not supported.

Could you please do not mix such a clean up a changes with functional changes? It deserve to be standalone patch.

Quoted 55 lines
---
  xen/common/domctl.c     | 6 ++++--
  xen/include/xsm/dummy.h | 4 ++--
  xen/include/xsm/xsm.h   | 6 ++++--
  xen/xsm/dummy.c         | 2 ++
  xen/xsm/flask/hooks.c   | 5 ++++-
  5 files changed, 16 insertions(+), 7 deletions(-)
xen/common/domctl.c +4 -2
index 29a7726d32..159864bc99 100644
@@ -638,9 +638,9 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
          }
          break;
 
-#ifdef CONFIG_HAS_PIRQ
      case XEN_DOMCTL_irq_permission:
      {
+#ifdef CONFIG_HAS_PIRQ
          unsigned int pirq = op->u.irq_permission.pirq, irq;
          int allow = op->u.irq_permission.allow_access;
 
@@ -656,9 +656,11 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
              ret = irq_permit_access(d, irq);
          else
              ret = irq_deny_access(d, irq);
+#else
+        ret = -EOPNOTSUPP;
+#endif
          break;
      }
-#endif
 
      case XEN_DOMCTL_iomem_permission:
      {
xen/include/xsm/dummy.h +1 -2
index e801dbcdba..6f6de161f9 100644
@@ -555,14 +555,14 @@ static XSM_INLINE int cf_check xsm_unmap_domain_irq(
      XSM_ASSERT_ACTION(XSM_HOOK);
      return xsm_default_action(action, current->domain, d);
  }
-
+#ifdef CONFIG_HAS_PIRQ
  static XSM_INLINE int cf_check xsm_irq_permission(
      XSM_DEFAULT_ARG struct domain *d, int pirq, uint8_t allow)
  {
      XSM_ASSERT_ACTION(XSM_HOOK);
      return xsm_default_action(action, current->domain, d);
  }
-

[...]

Signature · 2 lines
Best regards,
-grygorii
#3 lore raw

Re: [PATCH 1/4] arm/domain: Update SBSA_VUART_CONSOLE config option handling

In reply to Orzel, Michal

Hi Michal,

Quoted 23 lines · Michal
Quoted 20 lines · Milan Djokic

Update XEN_DOMCTL_vuart_op command handling to return -EOPNOTSUPP when vpl011 is disabled, informing the control domain that this feature is unavailable.
Added dom0less config sanity check for vpl011 property

---
  xen/arch/arm/dom0less-build.c     | 4 ++++
  xen/arch/arm/domctl.c             | 3 +++
  xen/arch/arm/include/asm/vpl011.h | 2 +-
  3 files changed, 8 insertions(+), 1 deletion(-)
xen/arch/arm/dom0less-build.c +0 -0
index 4181c10538..57980d2abe 100644
@@ -322,6 +322,10 @@ int __init arch_parse_dom0less_node(struct dt_device_node *node,
      if ( domu_dt_sci_parse(node, d_cfg) )
          panic("Error getting SCI configuration\n");
 
Quoted 8 lines

xen/arch/arm/dom0less-build.c int __init arch_parse_dom0less_node(struct dt_device_node *node, · line 327

Quoted 3 lines
xen/arch/arm/dom0less-build.c +3 -0
+    if ( dt_property_read_bool(node, "vpl011") &&
+         !IS_ENABLED(CONFIG_SBSA_VUART_CONSOLE) )
+        panic("'vpl011' property found, but CONFIG_SBSA_VUART_CONSOLE not selected\n");

I don't think there is a need for another dt property reading. In init_vuart() we read this property and if present we call domain_vpl011_init. This function returns (thanks to your change) -EOPNOTSUPP, so we already cover both cases. No need for an explicit panic.

I added this check since it seemed to me that this specific case should be covered as part of the config sanity check. But yes, if there's no need for an explicit panic, it is handled later in domain_vpl011_init() anyway. Will remove it.

Quoted 12 lines
Quoted 12 lines
xen/arch/arm/dom0less-build.c +1 -0
+
      if ( !dt_property_read_u32(node, "nr_spis", &d_cfg->arch.nr_spis) )
      {
          int vpl011_virq = GUEST_VPL011_SPI;
xen/arch/arm/domctl.c +0 -0
index ad914c915f..250e20a9fb 100644
@@ -156,6 +156,9 @@ long arch_do_domctl(struct xen_domctl *domctl, struct domain *d,
          unsigned int i;
          struct xen_domctl_vuart_op *vuart_op = &domctl->u.vuart_op;
 
Quoted 5 lines

xen/arch/arm/domctl.c long arch_do_domctl(struct xen_domctl *domctl, struct domain *d, · line 160

Quoted 2 lines
xen/arch/arm/domctl.c +2 -0
+        if ( !IS_ENABLED(CONFIG_SBSA_VUART_CONSOLE) )
+            return -EOPNOTSUPP;

Why is this needed? Later on in this path we will call domain_vpl011_init that will return exactly the same if CONFIG_SBSA_VUART_CONSOLE is not enabled.

Yes, this is not necessary. I will exclude this part.

Quoted 16 lines
Quoted 9 lines
xen/arch/arm/domctl.c +1 -0
+
          /* check that structure padding must be 0. */
          for ( i = 0; i < sizeof(vuart_op->pad); i++ )
              if ( vuart_op->pad[i] )
xen/arch/arm/include/asm/vpl011.h +0 -0
index cc83868281..b8f4d85651 100644

xen/arch/arm/include/asm/vpl011.h int vpl011_rx_char_xen(struct domain *d, char c); · line 77

Quoted 5 lines
xen/arch/arm/include/asm/vpl011.h +1 -1
@@ -74,7 +74,7 @@ int vpl011_rx_char_xen(struct domain *d, char c);
  static inline int domain_vpl011_init(struct domain *d,
                                       struct vpl011_init_info *info)
  {
-    return -ENOSYS;
+    return -EOPNOTSUPP;

This change is ok.

Quoted 2 lines

~Michal

BR,
Milan

#16 lore raw
In reply to Jan Beulich

Hello Jan,

Quoted 8 lines · Jan Beulich
Quoted 6 lines · Milan Djokic

This patch series provides minor updates to the domctl and sysctl handling of unsupported commands. Currently the behavior diverges: some commands return -EOPNOTSUPP, while others fall back to the generic -ENOSYS. This series aligns the behavior so that unsupported commands consistently return the appropriate error code, allowing the control domain to correctly identify unsupported operations.

Quoted 7 lines

What, even after having looked at all the patches (and their descriptions), still isn't clear to me is why the distinction ENOSYS vs EOPNOTSUPP would matter. Tool stacks still need to be prepared to get back ENOSYS, at the very least as long as they mean to run on older hypervisors as well. And with Penny's work to allow excluding domctl/sysctl altogether, I expect ENOSYS would then also be what results if that option is made use of.

I think that ENOSYS and EOPNOTSUPP are both handled properly by the toolstack. This change is more related to control domains without standard tool stack (e.g. zephyr or xtf domain). Especially for xtf tests, we expect that consistent error code is provided for unsupported hypercall commands. Right now this is not the case. Still, this is not a ‘must’, but in my view it would be better if we had the handling aligned between different hypercalls and commands.

BR,
Milan

#6 lore raw

Re: [PATCH 2/4] domctl: Provide appropriate error code when PIRQs are not supported

In reply to Jan Beulich
Quoted 10 lines · Jan Beulich
Quoted 5 lines · Milan Djokic

When PIRQs are not supported (e.g. for arm), XEN_DOMCTL_irq_permission command is not handled.
This results with default (-ENOSYS) error code returned to control domain. Update command handling to return -EOPNOTSUPP if control domain invokes it by mistake when PIRQs are not supported.

Did you consider simply replacing the bogus ENOSYS by EOPNOTSUPP? (Assuming the difference in error code really makes a difference to callers.)

Yes, this is the simplest approach. I didn’t do it because I wanted to keep a distinction between commands that are part of the Xen interface but not supported on the current configuration/platform, and commands that don’t exist at all. I also tried to follow the existing pattern, where unsupported commands are handled explicitly rather than falling through to the default case (e.g. set_llc_colors, soft_reset, etc). If this distinction isn’t useful, then yes, I can definitely just rely on a default-case error.

Quoted 13 lines
Quoted 13 lines
xen/include/xsm/dummy.h +1 -1
@@ -555,14 +555,14 @@ static XSM_INLINE int cf_check xsm_unmap_domain_irq(
      XSM_ASSERT_ACTION(XSM_HOOK);
      return xsm_default_action(action, current->domain, d);
  }
-
+#ifdef CONFIG_HAS_PIRQ
  static XSM_INLINE int cf_check xsm_irq_permission(
      XSM_DEFAULT_ARG struct domain *d, int pirq, uint8_t allow)
  {
      XSM_ASSERT_ACTION(XSM_HOOK);
      return xsm_default_action(action, current->domain, d);
Quoted 8 lines

xen/include/xsm/dummy.h static XSM_INLINE int cf_check xsm_unmap_domain_irq( · line 568

Quoted 6 lines
xen/include/xsm/dummy.h +1 -1
  }
-
+#endif
  static XSM_INLINE int cf_check xsm_iomem_permission(
      XSM_DEFAULT_ARG struct domain *d, uint64_t s, uint64_t e, uint8_t allow)
  {

Why would you zap blank lines like this (also elsewhere)?

Will fix this.

#11 lore raw

Re: [PATCH 3/4] domctl: Provide appropriate error code when VM events are not supported

In reply to Jan Beulich
Quoted 8 lines · Jan Beulich
Quoted 2 lines · Milan Djokic

Return -EOPNOTSUPP when XEN_DOMCTL_set_access_required command is invoked while VM events and monitoring support is disabled.

This is more bounded than the pretty wide subject. Taking the subject and considering there are other VM_EVENT related domctl-s, is this one really the only one in need of adjustment?

I think that others, like monitor_op and event_op, already return -EOPNOTSUPP when CONFIG_VM_EVENT is disabled. I will check this, it could be that I missed some commands related to this context.

Quoted 35 lines

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 793

Quoted 13 lines
xen/common/domctl.c +2 -3
@@ -787,19 +787,22 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
              copyback = true;
          break;
 
-#ifdef CONFIG_VM_EVENT
      case XEN_DOMCTL_set_access_required:
-        if ( unlikely(current->domain == d) ) /* no domain_pause() */
-            ret = -EPERM;
+        if ( !IS_ENABLED(CONFIG_VM_EVENT) )
+            ret = -EOPNOTSUPP;
          else

If you convert this to

         else if ( unlikely(current->domain == d) ) /* no domain_pause() */

then ...

Quoted 4 lines
xen/common/domctl.c +0 -3
          {
-            domain_pause(d);
-            arch_p2m_set_access_required(d,
-                op->u.access_required.access_required);

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 803

Quoted 10 lines
xen/common/domctl.c +9 -1
-            domain_unpause(d);
+            if ( unlikely(current->domain == d) ) /* no domain_pause() */
+                ret = -EPERM;
+            else
+            {
+                domain_pause(d);
+                arch_p2m_set_access_required(d,
+                    op->u.access_required.access_required);
+                domain_unpause(d);
+            }
Quoted 2 lines

... the need for re-indenting disappears, and we get away with less churn.

I’ll do that, thanks.

BR,
Milan

#14 lore raw

Re: [PATCH 4/4] sysctl: align handling of unsupported commands

In reply to Jan Beulich
Quoted 92 lines · Jan Beulich
Quoted 11 lines · Milan Djokic

Handling of unsupported sysctl commands currently diverges: some commands return -EOPNOTSUPP, while others fall back to generic -ENOSYS.

Unify the behavior so that unsupported commands consistently return the appropriate error code, allowing the control domain to correctly identify unsupported operations.

Using IS_ENABLED() macro to identify disabled commands, allowing dead code to be removed at compile time.

Overall quite okay imo, yet there are a number of small issues.

Quoted 12 lines
xen/common/sysctl.c +4 -2
@@ -170,19 +173,22 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
          op->u.availheap.avail_bytes <<= PAGE_SHIFT;
          break;
 
-#ifdef CONFIG_PM_STATS
      case XEN_SYSCTL_get_pmstat:
-        ret = do_get_pm_info(&op->u.get_pmstat);
+        if ( !IS_ENABLED(CONFIG_PM_STATS) )
+            ret = -EOPNOTSUPP;
+        else
+            ret = do_get_pm_info(&op->u.get_pmstat);
          break;

xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) · line 186

Quoted 10 lines
xen/common/sysctl.c +3 -5
-#endif
 
-#ifdef CONFIG_PM_OP
      case XEN_SYSCTL_pm_op:
-        ret = do_pm_op(&op->u.pm_op);
-        if ( ret == -EAGAIN )
-            copyback = 1;
+        if ( !IS_ENABLED(CONFIG_PM_OP) )
+            ret = -EOPNOTSUPP;
+        else {

Misplaced figure brace.

Quoted 11 lines
xen/include/xen/perfc.h +0 -1
@@ -92,7 +92,6 @@ DECLARE_PER_CPU(perfc_t[NUM_PERFCOUNTERS], perfcounters);
  #endif
 
  struct xen_sysctl_perfc_op;
-int perfc_control(struct xen_sysctl_perfc_op *pc);
 
  extern void cf_check perfc_printall(unsigned char key);
  extern void cf_check perfc_reset(unsigned char key);

xen/include/xen/perfc.h extern void cf_check perfc_reset(unsigned char key); · line 117

Quoted 5 lines
xen/include/xen/perfc.h +2 -0
@@ -114,4 +113,7 @@ extern void cf_check perfc_reset(unsigned char key);
 
  #endif /* CONFIG_PERF_COUNTERS */
 
+struct xen_sysctl_perfc_op;
+extern int perfc_control(struct xen_sysctl_perfc_op *pc);

Why would you move the function decl, but duplicate the struct forward decl?

xen/include/xen/spinlock.h line 10

Quoted 7 lines
xen/include/xen/spinlock.h +1 -0
@@ -7,6 +7,7 @@
 
  #include <asm/system.h>
  #include <asm/spinlock.h>
+#include <public/sysctl.h>

Why would this be needed? It means effectively the whole codebase gains a dependency on this header even when DEBUG_LOCK_PROFILE=n. Yes, you may need ...

Quoted 21 lines
xen/include/xen/spinlock.h +0 -3
@@ -40,8 +41,6 @@ union lock_debug { };
 
  #ifdef CONFIG_DEBUG_LOCK_PROFILE
 
-#include <public/sysctl.h>
-
  /*
      lock profiling on:
 
@@ -164,7 +163,6 @@ void _lock_profile_deregister_struct(int32_t type,
  #define lock_profile_deregister_struct(type, ptr)                             \
      _lock_profile_deregister_struct(type, &((ptr)->profile_head))
 
-extern int spinlock_profile_control(struct xen_sysctl_lockprof_op *pc);
  extern void cf_check spinlock_profile_printall(unsigned char key);
  extern void cf_check spinlock_profile_reset(unsigned char key);
 
@@ -360,4 +358,6 @@ static always_inline void nrspin_lock_irq(rspinlock_t *l)
  #define nrspin_unlock_irqrestore(l, f) _nrspin_unlock_irqrestore(l, f)
  #define nrspin_unlock_irq(l)           _nrspin_unlock_irq(l)
 
Quoted 8 lines

xen/include/xen/spinlock.h static always_inline void nrspin_lock_irq(rspinlock_t *l) · line 363

Quoted 3 lines
xen/include/xen/spinlock.h +2 -0
+extern int spinlock_profile_control(struct xen_sysctl_lockprof_op *pc);
+
  #endif /* __SPINLOCK_H__ */

... a forward decl of struct xen_sysctl_lockprof_op; I don't see what's wrong with doing just that.

Jan

I’ll correct these mistakes. Thanks for the suggestions.

BR,
Milan

#7 lore raw

Re: [PATCH 2/4] domctl: Provide appropriate error code when PIRQs are not supported

In reply to Milan Djokic
Quoted 11 lines · Milan Djokic
Quoted 9 lines · Jan Beulich
Quoted 5 lines · Milan Djokic

When PIRQs are not supported (e.g. for arm), XEN_DOMCTL_irq_permission command is not handled.
This results with default (-ENOSYS) error code returned to control domain. Update command handling to return -EOPNOTSUPP if control domain invokes it by mistake when PIRQs are not supported.

Did you consider simply replacing the bogus ENOSYS by EOPNOTSUPP? (Assuming the difference in error code really makes a difference to callers.)

Quoted 8 lines

Yes, this is the simplest approach. I didn’t do it because I wanted to keep a distinction between commands that are part of the Xen interface but not supported on the current configuration/platform, and commands that don’t exist at all. I also tried to follow the existing pattern, where unsupported commands are handled explicitly rather than falling through to the default case (e.g. set_llc_colors, soft_reset, etc). If this distinction isn’t useful, then yes, I can definitely just rely on a default-case error.

Before you (possibly) follow this route, maybe I should mention that there have been discussions around this in the past (sorry, no pointers, too long ago). IOW ahead of any consolidation (and making things consistent), imo as a community we need to settle on where exactly we consider ENOSYS valid to be used. My take is that almost all of the uses we (still) have are wrong. In particular all the ones for "unknown sub-op".

Jan