All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: Daniel Smith <dpsmith@apertussolutions.com>
Subject: [PATCH v2 04/14] x86: restrict PHYSDEVOP_* when PV=n
Date: Mon, 17 Aug 2026 10:52:28 +0200	[thread overview]
Message-ID: <664d2a63-2745-4c33-9748-283aefce2433@suse.com> (raw)
In-Reply-To: <ef09b072-c935-459e-bf8b-81c96ff9cc46@suse.com>

hvm_physdev_op() permits through only a subset of sub-ops. The code
handling other sub-ops is therefore unreachable when PV=n, violating MISRA
C:2012 rule 2.1. With that the XSM .apic() hook also becomes unreachable /
dead when PV=n.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Daniel P. Smith <dpsmith@apertussolutions.com>
---
At least for the sub-ops using xsm_apic() IS_ENABLED() cannot be used.
Therefore #ifdef is used throughout.
---
v2: Re-base over re-ordering of series.

--- a/xen/arch/x86/physdev.c
+++ b/xen/arch/x86/physdev.c
@@ -233,6 +233,8 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_H
         break;
     }
 
+#ifdef CONFIG_PV
+
     case PHYSDEVOP_pirq_eoi_gmfn_v2:
     case PHYSDEVOP_pirq_eoi_gmfn_v1: {
         struct physdev_pirq_eoi_gmfn info;
@@ -281,6 +283,8 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_H
         break;
     }
 
+#endif /* CONFIG_PV */
+
     case PHYSDEVOP_irq_status_query: {
         struct physdev_irq_status_query irq_status_query;
         ret = -EFAULT;
@@ -379,6 +383,8 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_H
         break;
     }
 
+#ifdef CONFIG_PV
+
     case PHYSDEVOP_apic_read: {
         struct physdev_apic apic;
         ret = -EFAULT;
@@ -526,6 +532,8 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_H
         break;
     }
 
+#endif /* CONFIG_PV */
+
     case PHYSDEVOP_pci_mmcfg_reserved: {
         struct physdev_pci_mmcfg_reserved info;
 
@@ -560,6 +568,8 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_H
         break;
     }
 
+#ifdef CONFIG_PV
+
     case PHYSDEVOP_restore_msi: {
         struct physdev_restore_msi restore_msi;
         struct pci_dev *pdev;
@@ -591,6 +601,8 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_H
         break;
     }
 
+#endif /* CONFIG_PV */
+
     case PHYSDEVOP_setup_gsi: {
         struct physdev_setup_gsi setup_gsi;
 
@@ -610,6 +622,7 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_H
                               setup_gsi.polarity);
         break; 
     }
+
     case PHYSDEVOP_get_free_pirq: {
         struct physdev_get_free_pirq out;
 
--- a/xen/include/xsm/dummy.h
+++ b/xen/include/xsm/dummy.h
@@ -644,13 +644,6 @@ static XSM_INLINE int xsm_mem_sharing_op
     return xsm_default_action(action, current->domain, cd);
 }
 
-static XSM_INLINE int xsm_apic(
-    XSM_DEFAULT_ARG struct domain *d, int cmd)
-{
-    XSM_ASSERT_ACTION(XSM_PRIV);
-    return xsm_default_action(action, d, NULL);
-}
-
 static XSM_INLINE int xsm_machine_memory_map(XSM_DEFAULT_VOID)
 {
     XSM_ASSERT_ACTION(XSM_PRIV);
@@ -666,6 +659,13 @@ static XSM_INLINE int xsm_domain_memory_
 
 #ifdef CONFIG_PV
 
+static XSM_INLINE int xsm_apic(
+    XSM_DEFAULT_ARG struct domain *d, int cmd)
+{
+    XSM_ASSERT_ACTION(XSM_PRIV);
+    return xsm_default_action(action, d, NULL);
+}
+
 static XSM_INLINE int xsm_do_mca(XSM_DEFAULT_VOID)
 {
     XSM_ASSERT_ACTION(XSM_PRIV);
--- a/xen/include/xsm/hooks.h
+++ b/xen/include/xsm/hooks.h
@@ -131,10 +131,10 @@ XSM_HOOK(int, mem_sharing_op, struct dom
 XSM_HOOK(int, platform_op, uint32_t)
 
 #ifdef CONFIG_X86
-XSM_HOOK(int, apic, struct domain *, int)
 XSM_HOOK(int, machine_memory_map)
 XSM_HOOK(int, domain_memory_map, struct domain *)
 #ifdef CONFIG_PV
+XSM_HOOK(int, apic, struct domain *, int)
 XSM_HOOK(int, do_mca)
 XSM_HOOK(int, mmu_update, struct domain *, struct domain *, struct domain *,
                           uint32_t)
--- a/xen/xsm/flask/hooks.c
+++ b/xen/xsm/flask/hooks.c
@@ -1750,6 +1750,19 @@ static int cf_check flask_mem_sharing_op
 }
 #endif
 
+static int cf_check flask_machine_memory_map(void)
+{
+    return avc_current_has_perm(SECINITSID_XEN, SECCLASS_MMU, MMU__MEMORYMAP,
+                                NULL);
+}
+
+static int cf_check flask_domain_memory_map(struct domain *d)
+{
+    return current_has_perm(d, SECCLASS_MMU, MMU__MEMORYMAP);
+}
+
+#ifdef CONFIG_PV
+
 static int cf_check flask_apic(struct domain *d, int cmd)
 {
     uint32_t perm;
@@ -1770,18 +1783,6 @@ static int cf_check flask_apic(struct do
     return domain_has_xen(d, perm);
 }
 
-static int cf_check flask_machine_memory_map(void)
-{
-    return avc_current_has_perm(SECINITSID_XEN, SECCLASS_MMU, MMU__MEMORYMAP, NULL);
-}
-
-static int cf_check flask_domain_memory_map(struct domain *d)
-{
-    return current_has_perm(d, SECCLASS_MMU, MMU__MEMORYMAP);
-}
-
-#ifdef CONFIG_PV
-
 static int cf_check flask_do_mca(void)
 {
     return domain_has_xen(current->domain, XEN__MCA_OP);



  parent reply	other threads:[~2026-08-17  8:52 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-17  8:49 [PATCH v2 00/14] XSM: follow-on to XSAs 492 and 499 Jan Beulich
2026-08-17  8:51 ` [PATCH v2 01/14] XSM: make xsm_default_action() const-correct Jan Beulich
2026-08-27 18:19   ` Daniel P. Smith
2026-08-17  8:51 ` [PATCH v2 02/14] XSM: convert "allow" (Flask: "access") parameters to bool Jan Beulich
2026-08-17  8:52 ` [PATCH v2 03/14] x86/mm: get_page_from_l1e() is PV-or-shadow-only Jan Beulich
2026-08-17  8:52 ` Jan Beulich [this message]
2026-08-17  8:53 ` [PATCH v2 05/14] XSM: make Argo hooks well-formed ones Jan Beulich
2026-08-27 18:24   ` Daniel P. Smith
2026-08-17  8:53 ` [PATCH v2 06/14] XSM: fold xsm_{,un}map_domain_pirq() hooks Jan Beulich
2026-08-27 18:25   ` Daniel P. Smith
2026-08-17  8:54 ` [PATCH v2 07/14] x86: type-correct last parameter of map_domain_pirq() Jan Beulich
2026-08-17  8:54 ` [PATCH v2 08/14] XSM: pass just SBDF to xsm_{,un}map_domain_irq() Jan Beulich
2026-08-17  8:55 ` [PATCH v2 09/14] XSM: fold xsm_{,un}map_domain_irq() hooks Jan Beulich
2026-08-17  8:56 ` [PATCH v2 10/14] XSM: fold xsm_{,un}bind_pt_irq() hooks Jan Beulich
2026-08-17  8:56 ` [PATCH v2 11/14] XSM: convert remaining event channel hooks Jan Beulich
2026-08-17  8:57 ` [PATCH v2 12/14] XSM: convert remaining domain-related hooks Jan Beulich
2026-08-17  8:58 ` [PATCH v2 13/14] XSM: convert remaining miscellaneous hooks Jan Beulich
2026-08-17  8:58 ` [PATCH RFC v2 14/14] XSM: avoid fragile assumptions in xsm_fixup_ops() Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=664d2a63-2745-4c33-9748-283aefce2433@suse.com \
    --to=jbeulich@suse.com \
    --cc=dpsmith@apertussolutions.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.