[PATCH v5 20/24] xen/x86: wrap x86-specific domctl-op with CONFIG_MGMT_HYPERCALLS

Penny Zheng posted 24 patches 2 days, 1 hour ago
[PATCH v5 20/24] xen/x86: wrap x86-specific domctl-op with CONFIG_MGMT_HYPERCALLS
Posted by Penny Zheng 2 days, 1 hour ago
Function arch_do_domctl() is responsible for arch-specific domctl-op,
and shall be wrapped with CONFIG_MGMT_HYPERCALLS
We focus on x86 implementation here only. Tracking its calling chain and the
following functions shall be wrapped with CONFIG_MGMT_HYPERCALLS too.
Otherwise they will all become unreachable when MGMT_HYPERCALLS=n, and hence
violating Misra Rule 2.1.
- hvm_acpi_power_button
- hvm_acpi_sleep_button
- hvm_debug_op
- make P2M_AUDIT depend on CONFIG_MGMT_HYPERCALLS
- make PG_log_dirty depend on CONFIG_MGMT_HYPERCALLS
- make policy.o/msr.o depend on CONFIG_MGMT_HYPERCALLS
- make cpuid-cp2buf.o/cpuid-cpfrbuf.o/cpupolicy-clr.o depend on CONFIG_MGMT_HYPERCALLS
- make HAS_SOFT_RESET depend on CONFIG_MGMT_HYPERCALLS
- make VMTRACE depend on CONFIG_MGMT_HYPERCALLS
- paging_domctl_cont
We put the guardian in Makefile for the arch-specific domctl.o compilation.

Signed-off-by: Penny Zheng <Penny.Zheng@amd.com>
---
v1 -> v2:
- split out xsm parts
- adapt to changes of "unify DOMCTL to MGMT_HYPERCALLS"
- wrap default-case and arch_get_domain_info() transiently
---
v2 -> v3:
- add missing guardian in arm/Makefile
- cover RTIT_CTL{,STATUS}_MASK #define-s
- add missing guardian for .vmtrace_output_position
- guard the whole static inline function
- address "violating Misra rule 2.1" in commit message
- remove transient wrapping around default-case and arch_get_domain_info()
---
v3 -> v4:
- make HAS_SOFT_RESET depend on CONFIG_MGMT_HYPERCALLS
- make VMTRACE depend on CONFIG_MGMT_HYPERCALLS
- seperate depends on condition for future convenience
- split arch-specific domctl-op into x86 and arm
---
v4 -> v5:
- do not undo imply and add "depends on MGMT_HYPERCALLS" in option
- use IS_ENABLED(...) to avoid too long line
- move paging_domctl_cont hypercall-def closer to avoid scattering #ifdef
---
 xen/Kconfig.debug                 | 1 +
 xen/arch/x86/Makefile             | 2 +-
 xen/arch/x86/hvm/Kconfig          | 1 +
 xen/arch/x86/hvm/hvm.c            | 2 ++
 xen/arch/x86/hvm/pmtimer.c        | 2 ++
 xen/arch/x86/include/asm/p2m.h    | 2 +-
 xen/arch/x86/include/asm/paging.h | 3 ++-
 xen/common/Kconfig                | 1 +
 xen/include/hypercall-defs.c      | 8 ++++----
 xen/lib/Makefile                  | 6 +++---
 xen/lib/x86/Makefile              | 4 ++--
 11 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/xen/Kconfig.debug b/xen/Kconfig.debug
index a69615cd63..c078c6bf2e 100644
--- a/xen/Kconfig.debug
+++ b/xen/Kconfig.debug
@@ -15,6 +15,7 @@ if DEBUG || EXPERT
 
 config GDBSX
 	bool "Guest debugging with gdbsx"
+	depends on MGMT_HYPERCALLS
 	depends on X86
 	default y
 	help
diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile
index 1e2ce8e72c..d389787bb3 100644
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -80,7 +80,7 @@ obj-$(CONFIG_VM_EVENT) += vm_event.o
 obj-y += xstate.o
 
 ifneq ($(CONFIG_PV_SHIM_EXCLUSIVE),y)
-obj-y += domctl.o
+obj-$(CONFIG_MGMT_HYPERCALLS) += domctl.o
 obj-y += platform_hypercall.o
 obj-$(CONFIG_COMPAT) += x86_64/platform_hypercall.o
 endif
diff --git a/xen/arch/x86/hvm/Kconfig b/xen/arch/x86/hvm/Kconfig
index df9bea65b0..1989808810 100644
--- a/xen/arch/x86/hvm/Kconfig
+++ b/xen/arch/x86/hvm/Kconfig
@@ -54,6 +54,7 @@ config HVM_FEP
 config ALTP2M
 	bool "Alternate P2M support" if EXPERT
 	depends on INTEL_VMX
+	depends on MGMT_HYPERCALLS
 	default y
 	help
 	  Alternate-p2m allows a guest to manage multiple p2m guest physical
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 5d297fb42a..ce75fb7839 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -5208,6 +5208,7 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)
     return rc;
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 int hvm_debug_op(struct vcpu *v, int32_t op)
 {
     int rc = 0;
@@ -5250,6 +5251,7 @@ int hvm_debug_op(struct vcpu *v, int32_t op)
 
     return rc;
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 #ifdef CONFIG_VM_EVENT
 void hvm_toggle_singlestep(struct vcpu *v)
diff --git a/xen/arch/x86/hvm/pmtimer.c b/xen/arch/x86/hvm/pmtimer.c
index 87a7a01c9f..f080f7561d 100644
--- a/xen/arch/x86/hvm/pmtimer.c
+++ b/xen/arch/x86/hvm/pmtimer.c
@@ -56,6 +56,7 @@ static void pmt_update_sci(PMTState *s)
         hvm_isa_irq_deassert(s->vcpu->domain, SCI_IRQ);
 }
 
+#ifdef CONFIG_MGMT_HYPERCALLS
 void hvm_acpi_power_button(struct domain *d)
 {
     PMTState *s = &d->arch.hvm.pl_time->vpmt;
@@ -81,6 +82,7 @@ void hvm_acpi_sleep_button(struct domain *d)
     pmt_update_sci(s);
     spin_unlock(&s->lock);
 }
+#endif /* CONFIG_MGMT_HYPERCALLS */
 
 /* Set the correct value in the timer, accounting for time elapsed
  * since the last time we did that. */
diff --git a/xen/arch/x86/include/asm/p2m.h b/xen/arch/x86/include/asm/p2m.h
index 9016e88411..3574e2eecd 100644
--- a/xen/arch/x86/include/asm/p2m.h
+++ b/xen/arch/x86/include/asm/p2m.h
@@ -20,7 +20,7 @@
 #include <asm/page.h>    /* for pagetable_t */
 
 /* Debugging and auditing of the P2M code? */
-#if !defined(NDEBUG) && defined(CONFIG_HVM)
+#if !defined(NDEBUG) && defined(CONFIG_HVM) && defined(CONFIG_MGMT_HYPERCALLS)
 #define P2M_AUDIT     1
 #else
 #define P2M_AUDIT     0
diff --git a/xen/arch/x86/include/asm/paging.h b/xen/arch/x86/include/asm/paging.h
index 0c06b0a7a8..b95d80e75a 100644
--- a/xen/arch/x86/include/asm/paging.h
+++ b/xen/arch/x86/include/asm/paging.h
@@ -57,7 +57,8 @@
 #endif
 #if defined(CONFIG_PAGING) && !defined(CONFIG_PV_SHIM_EXCLUSIVE)
 /* Enable log dirty mode */
-#define PG_log_dirty   (XEN_DOMCTL_SHADOW_ENABLE_LOG_DIRTY << PG_mode_shift)
+#define PG_log_dirty   IS_ENABLED(CONFIG_MGMT_HYPERCALLS) &&                \
+                        (XEN_DOMCTL_SHADOW_ENABLE_LOG_DIRTY << PG_mode_shift)
 #else
 #define PG_log_dirty   0
 #endif
diff --git a/xen/common/Kconfig b/xen/common/Kconfig
index 2914508a8f..64023703ae 100644
--- a/xen/common/Kconfig
+++ b/xen/common/Kconfig
@@ -157,6 +157,7 @@ config HAS_SCHED_GRANULARITY
 
 config HAS_SOFT_RESET
 	bool
+	depends on MGMT_HYPERCALLS
 
 config HAS_STACK_PROTECTOR
 	bool
diff --git a/xen/include/hypercall-defs.c b/xen/include/hypercall-defs.c
index 4840de805b..a08e80ed59 100644
--- a/xen/include/hypercall-defs.c
+++ b/xen/include/hypercall-defs.c
@@ -196,10 +196,10 @@ dm_op(domid_t domid, unsigned int nr_bufs, xen_dm_op_buf_t *bufs)
 #endif
 #ifdef CONFIG_MGMT_HYPERCALLS
 sysctl(xen_sysctl_t *u_sysctl)
-#endif
 #if defined(CONFIG_X86) && defined(CONFIG_PAGING) && !defined(CONFIG_PV_SHIM_EXCLUSIVE)
 paging_domctl_cont(xen_domctl_t *u_domctl)
 #endif
+#endif
 #ifndef CONFIG_PV_SHIM_EXCLUSIVE
 domctl(xen_domctl_t *u_domctl)
 platform_op(xen_platform_op_t *u_xenpf_op)
@@ -279,6 +279,9 @@ hvm_op                             do       do       do       do       do
 #endif
 #ifdef CONFIG_MGMT_HYPERCALLS
 sysctl                             do       do       do       do       do
+#if defined(CONFIG_X86) && defined(CONFIG_PAGING) && !defined(CONFIG_PV_SHIM_EXCLUSIVE)
+paging_domctl_cont                 do       do       do       do       -
+#endif
 #endif
 #ifndef CONFIG_PV_SHIM_EXCLUSIVE
 domctl                             do       do       do       do       do
@@ -298,8 +301,5 @@ dm_op                              compat   do       compat   do       do
 hypfs_op                           do       do       do       do       do
 #endif
 mca                                do       do       -        -        -
-#if defined(CONFIG_X86) && defined(CONFIG_PAGING) && !defined(CONFIG_PV_SHIM_EXCLUSIVE)
-paging_domctl_cont                 do       do       do       do       -
-#endif
 
 #endif /* !CPPCHECK */
diff --git a/xen/lib/Makefile b/xen/lib/Makefile
index 9b3e03a511..26c6a0de33 100644
--- a/xen/lib/Makefile
+++ b/xen/lib/Makefile
@@ -46,7 +46,7 @@ lib32-y := divmod.o
 lib32-$(CONFIG_64BIT) :=
 lib-y += $(lib32-y)
 
-libx86-y := x86/cpuid-cp2buf.o
-libx86-y += x86/cpuid-cpfrbuf.o
-libx86-y += x86/cpupolicy-clr.o
+libx86-$(CONFIG_MGMT_HYPERCALLS) := x86/cpuid-cp2buf.o
+libx86-$(CONFIG_MGMT_HYPERCALLS) += x86/cpuid-cpfrbuf.o
+libx86-$(CONFIG_MGMT_HYPERCALLS) += x86/cpupolicy-clr.o
 lib-$(CONFIG_X86) += $(libx86-y)
diff --git a/xen/lib/x86/Makefile b/xen/lib/x86/Makefile
index 780ea05db1..89fb4bba27 100644
--- a/xen/lib/x86/Makefile
+++ b/xen/lib/x86/Makefile
@@ -1,3 +1,3 @@
 obj-y += cpuid.o
-obj-y += msr.o
-obj-y += policy.o
+obj-$(CONFIG_MGMT_HYPERCALLS) += msr.o
+obj-$(CONFIG_MGMT_HYPERCALLS) += policy.o
-- 
2.34.1