Skip to contentSkip to conversation

Introduce CONFIG_PLATFORM_OP to disable platform_op hypercalls

PATCH In review Jiqian Chen 2 participants 14 messages Jul 25, 2025 – Jul 30, 2025

lore
Share & tools
lore
#0 lore raw

cover Introduce CONFIG_PLATFORM_OP to disable platform_op hypercalls

Hi all,
This is a continuation of the disabling some hypercalls handling code series.
https://lore.kernel.org/xen-devel/[email protected]/

It can be beneficial for some dom0less systems to further reduce Xen footprint via disabling some hypercalls handling code, which may not to be used & required in such systems. Each hypercall has a separate option to keep configuration flexible.

Options to disable hypercalls:
- sysctl
- domctl
- hvm
- physdev
- platform_op

This is for platform_op.
---
cc: Jan Beulich <[email protected]>
cc: Andrew Cooper <[email protected]>
cc: "Roger Pau Monné" <[email protected]>
cc: Anthony PERARD <[email protected]>
cc: Michal Orzel <[email protected]>
cc: Julien Grall <[email protected]>
cc: Stefano Stabellini <[email protected]>
cc: Lukasz Hawrylko <[email protected]>
cc: "Daniel P. Smith" <[email protected]>
cc: "Mateusz Mówka" <[email protected]>
cc: Dario Faggioli <[email protected]>
cc: Juergen Gross <[email protected]>
cc: George Dunlap <[email protected]>
cc: "Marek Marczykowski-Górecki" <[email protected]>
cc: Bertrand Marquis <[email protected]>
cc: Volodymyr Babchuk <[email protected]>
---
Jiqian Chen (11):
xen: Introduce CONFIG_PLATFORM_OP
xen/xsm: Wrap around xsm_platform_op with CONFIG_PLATFORM_OP xen/platform_op: Wrap around XENPF_microcode_update(2) xen/platform_op: Wrap around XENPF_firmware_info xen/platform_op: Wrap around XENPF_efi_runtime_call xen/platform_op: Wrap around XENPF_enter_acpi_sleep xen/platform_op: Wrap around XENPF_set_processor_pminfo xen/xsm: Wrap around xsm_resource_(un)plug_core xen/platform_op: Wrap around XENPF_mem_hotadd xen/platform_op: Wrap around XENPF_core_parking xen/platform_op: Wrap around platform_op hypercall

 xen/arch/arm/Makefile                 |  2 +-
 xen/arch/x86/Makefile                 |  2 ++
 xen/arch/x86/acpi/cpu_idle.c          |  6 ++++++
 xen/arch/x86/acpi/cpufreq/cpufreq.c   |  2 ++
 xen/arch/x86/acpi/lib.c               |  2 ++
 xen/arch/x86/acpi/power.c             |  4 ++++
 xen/arch/x86/apic.c                   |  4 ++++
 xen/arch/x86/configs/pvshim_defconfig |  1 +
 xen/arch/x86/cpu/microcode/core.c     |  6 ++++++
 xen/arch/x86/i8259.c                  |  2 ++
 xen/arch/x86/io_apic.c                |  2 ++
 xen/arch/x86/tboot.c                  |  2 ++
 xen/arch/x86/x86_64/Makefile          |  5 +++--
 xen/arch/x86/x86_64/mm.c              |  6 ++++++
 xen/common/Kconfig                    |  7 +++++++
 xen/common/core_parking.c             |  4 ++++
 xen/common/cpu.c                      |  2 ++
 xen/common/domain.c                   |  4 ++--
 xen/common/efi/common-stub.c          |  4 ++++
 xen/common/efi/compat.c               |  2 ++
 xen/common/efi/runtime.c              |  5 +++++
 xen/common/numa.c                     |  2 ++
 xen/common/sched/core.c               |  2 ++
 xen/drivers/char/console.c            |  6 ++++--
 xen/drivers/cpufreq/cpufreq.c         |  4 ++++
 xen/drivers/passthrough/iommu.c       |  2 ++
 xen/include/hypercall-defs.c          |  6 ++++--
 xen/include/xsm/xsm.h                 | 12 ++++++++++++
 xen/xsm/dummy.c                       |  5 +++++
 xen/xsm/flask/hooks.c                 |  5 +++++
 30 files changed, 109 insertions(+), 9 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/11 xen: Introduce CONFIG_PLATFORM_OP

Introduce a new Kconfig CONFIG_PLATFORM_OP, which shall only be disabled on some dom0less systems or PV shim on x86, to reduce Xen footprint.

The consequence of introducing "CONFIG_PLATFORM_OP=y" in .config file generated from pvshim_defconfig is transient, which will be adjusted in the final patch.

---
cc: Andrew Cooper <[email protected]>
cc: Anthony PERARD <[email protected]>
cc: Michal Orzel <[email protected]>
cc: Jan Beulich <[email protected]>
cc: Julien Grall <[email protected]>
cc: "Roger Pau Monné" <[email protected]>
cc: Stefano Stabellini <[email protected]>

---
 xen/common/Kconfig | 4 ++++
 1 file changed, 4 insertions(+)
xen/common/Kconfig +4 -0
index 2539a635f111..1a8f5ec93364 100644
@@ -627,6 +627,10 @@ config SYSCTL
 	  This option shall only be disabled on some dom0less systems, or
 	  PV shim on x86, to reduce Xen footprint.
 
+config PLATFORM_OP
+	bool "Enable Platform Operation hypercall"
+	default y
+
 endmenu
 
 config PM_OP
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/11 xen/xsm: Wrap around xsm_platform_op with CONFIG_PLATFORM_OP

In reply to Jiqian Chen

As function xsm_platform_op() is solely invoked in platform_hypercall.c, it needs to be wrapped around with CONFIG_PLATFORM_OP.

---
cc: "Daniel P. Smith" <[email protected]>

---
 xen/include/xsm/xsm.h | 4 ++++
 xen/xsm/dummy.c       | 3 +++
 xen/xsm/flask/hooks.c | 5 +++++
 3 files changed, 12 insertions(+)
xen/include/xsm/xsm.h +4 -0
index 9a23d2827cc0..bc0a0776c895 100644
@@ -678,7 +678,11 @@ static inline int xsm_mem_sharing(xsm_default_t def, struct domain *d)
 
 static inline int xsm_platform_op(xsm_default_t def, uint32_t op)
 {
+#ifdef CONFIG_PLATFORM_OP
     return alternative_call(xsm_ops.platform_op, op);
+#else
+    return -EOPNOTSUPP;
+#endif
 }
 
 #ifdef CONFIG_X86
xen/xsm/dummy.c +3 -0
index 8b7e01b50690..d9f4d3ee12b1 100644
@@ -129,7 +129,10 @@ static const struct xsm_ops __initconst_cf_clobber dummy_ops = {
     .mem_sharing                   = xsm_mem_sharing,
 #endif
 
+#ifdef CONFIG_PLATFORM_OP
     .platform_op                   = xsm_platform_op,
+#endif
+
 #ifdef CONFIG_X86
     .do_mca                        = xsm_do_mca,
     .shadow_control                = xsm_shadow_control,
xen/xsm/flask/hooks.c +5 -0
index b0308e1b26e0..a56a6d07475c 100644
@@ -1527,6 +1527,7 @@ static int cf_check flask_deassign_dtdevice(
 }
 #endif /* HAS_PASSTHROUGH && HAS_DEVICE_TREE_DISCOVERY */
 
+#ifdef CONFIG_PLATFORM_OP
 static int cf_check flask_platform_op(uint32_t op)
 {
     switch ( op )
@@ -1598,6 +1599,7 @@ static int cf_check flask_platform_op(uint32_t op)
         return avc_unknown_permission("platform_op", op);
     }
 }
+#endif /* CONFIG_PLATFORM_OP */
 
 #ifdef CONFIG_X86
 static int cf_check flask_do_mca(void)
@@ -2000,7 +2002,10 @@ static const struct xsm_ops __initconst_cf_clobber flask_ops = {
     .deassign_dtdevice = flask_deassign_dtdevice,
 #endif
 
+#ifdef CONFIG_PLATFORM_OP
     .platform_op = flask_platform_op,
+#endif
+
 #ifdef CONFIG_X86
     .do_mca = flask_do_mca,
     .shadow_control = flask_shadow_control,
Signature · 1 line
2.34.1
#3 lore raw

PATCH 3/11 xen/platform_op: Wrap around XENPF_microcode_update(2)

In reply to Jiqian Chen

ucode_update_hcall() is only used for XENPF_microcode_update and XENPF_microcode_update2, so wrap it and its call stack functions:
ucode_update_hcall
ucode_update_hcall_cont
do_microcode_update
control_thread_fn
microcode_nmi_callback
is_cpu_primary primary_thread_work secondary_nmi_work
wait_for_state
set_state wait_for_condition wait_cpu_callin wait_cpu_callout
primary_thread_fn secondary_thread_fn

---
cc: Jan Beulich <[email protected]>
cc: Andrew Cooper <[email protected]>
cc: "Roger Pau Monné" <[email protected]>

---
 xen/arch/x86/cpu/microcode/core.c | 6 ++++++
 1 file changed, 6 insertions(+)
xen/arch/x86/cpu/microcode/core.c +6 -0
index 816e9bfe40ba..ec306cea895e 100644
@@ -59,6 +59,7 @@
 #define MICROCODE_UPDATE_TIMEOUT_US 1000000
 
 static bool __initdata ucode_mod_forced;
+#ifdef CONFIG_PLATFORM_OP
 static unsigned int nr_cores;
 
 /*
@@ -76,6 +77,7 @@ static enum {
     LOADING_ENTER,
     LOADING_EXIT,
 } loading_state;
+#endif /* CONFIG_PLATFORM_OP */
 
 struct patch_with_flags {
     unsigned int flags;
@@ -167,6 +169,7 @@ static struct microcode_ops __ro_after_init ucode_ops;
 static DEFINE_SPINLOCK(microcode_mutex);
 
 DEFINE_PER_CPU(struct cpu_signature, cpu_sig);
+#ifdef CONFIG_PLATFORM_OP
 /* Store error code of the work done in NMI handler */
 static DEFINE_PER_CPU(int, loading_err);
 
@@ -183,6 +186,7 @@ static struct patch_with_flags nmi_patch =
 {
     .patch  = ZERO_BLOCK_PTR,
 };
+#endif /* CONFIG_PLATFORM_OP */
 
 /*
  * Return a patch that covers current CPU. If there are multiple patches,
@@ -195,6 +199,7 @@ static struct microcode_patch *parse_blob(const char *buf, size_t len)
     return alternative_call(ucode_ops.cpu_request_microcode, buf, len, true);
 }
 
+#ifdef CONFIG_PLATFORM_OP
 /* Returns true if ucode should be loaded on a given cpu */
 static bool is_cpu_primary(unsigned int cpu)
 {
@@ -646,6 +651,7 @@ int ucode_update_hcall(XEN_GUEST_HANDLE(const_void) buf,
      */
     return continue_hypercall_on_cpu(0, ucode_update_hcall_cont, buffer);
 }
+#endif /* CONFIG_PLATFORM_OP */
 
 /* Load a cached update to current cpu */
 int microcode_update_one(void)
Signature · 1 line
2.34.1
#4 lore raw

PATCH 4/11 xen/platform_op: Wrap around XENPF_firmware_info

In reply to Jiqian Chen

efi_get_info() is only used for XEN_FW_EFI_INFO of XENPF_firmware_info, so wrap it.
And wrap its compat function efi_compat_get_info().

---
cc: "Daniel P. Smith" <[email protected]>
cc: "Marek Marczykowski-Górecki" <[email protected]>
cc: Jan Beulich <[email protected]>

---
 xen/common/efi/common-stub.c | 4 ++++
 xen/common/efi/compat.c      | 2 ++
 xen/common/efi/runtime.c     | 3 +++
 3 files changed, 9 insertions(+)
xen/common/efi/common-stub.c +4 -0
index 77f138a6c574..05a84c60fb70 100644
@@ -21,10 +21,12 @@ unsigned long efi_get_time(void)
 void efi_halt_system(void) { }
 void efi_reset_system(bool warm) { }
 
+#ifdef CONFIG_PLATFORM_OP
 int efi_get_info(uint32_t idx, union xenpf_efi_info *info)
 {
     return -ENOSYS;
 }
+#endif /* CONFIG_PLATFORM_OP */
 
 int efi_runtime_call(struct xenpf_efi_runtime_call *op)
 {
@@ -33,8 +35,10 @@ int efi_runtime_call(struct xenpf_efi_runtime_call *op)
 
 #ifdef CONFIG_COMPAT
 
+#ifdef CONFIG_PLATFORM_OP
 int efi_compat_get_info(uint32_t idx, union compat_pf_efi_info *)
     __attribute__((__alias__("efi_get_info")));
+#endif /* CONFIG_PLATFORM_OP */
 
 int efi_compat_runtime_call(struct compat_pf_efi_runtime_call *)
     __attribute__((__alias__("efi_runtime_call")));
xen/common/efi/compat.c +2 -0
index 7cc6279b8f36..4f5f59fcac2e 100644
@@ -1,8 +1,10 @@
 #include <xen/guest_access.h>
 #include <compat/platform.h>
 
+#ifdef CONFIG_PLATFORM_OP
 #define efi_get_info efi_compat_get_info
 #define xenpf_efi_info compat_pf_efi_info
+#endif
 
 #define efi_runtime_call efi_compat_runtime_call
 #define xenpf_efi_runtime_call compat_pf_efi_runtime_call
xen/common/efi/runtime.c +3 -0
index 7e1fce291d92..ab63785397e2 100644
@@ -227,6 +227,8 @@ const CHAR16 *wmemchr(const CHAR16 *s, CHAR16 c, UINTN n)
 #endif /* COMPAT */
 
 #ifndef CONFIG_ARM /* TODO - disabled until implemented on ARM */
+
+#ifdef CONFIG_PLATFORM_OP
 int efi_get_info(uint32_t idx, union xenpf_efi_info *info)
 {
     unsigned int i, n;
@@ -325,6 +327,7 @@ int efi_get_info(uint32_t idx, union xenpf_efi_info *info)
 
     return 0;
 }
+#endif /* CONFIG_PLATFORM_OP */
 
 static long gwstrlen(XEN_GUEST_HANDLE_PARAM(CHAR16) str)
 {
Signature · 1 line
2.34.1
#5 lore raw

PATCH 5/11 xen/platform_op: Wrap around XENPF_efi_runtime_call

In reply to Jiqian Chen

efi_runtime_call() is only used for XENPF_efi_runtime_call, wrap it and its compat function and its calling functions:
efi_compat_runtime_call()
gwstrlen()
cast_time()
cast_guid()

---
cc: "Daniel P. Smith" <[email protected]>
cc: "Marek Marczykowski-Górecki" <[email protected]>
cc: Jan Beulich <[email protected]>

---
 xen/common/efi/common-stub.c | 4 ++--
 xen/common/efi/compat.c      | 2 +-
 xen/common/efi/runtime.c     | 2 ++
 3 files changed, 5 insertions(+), 3 deletions(-)
xen/common/efi/common-stub.c +2 -2
index 05a84c60fb70..f3fb9b77d426 100644
@@ -26,21 +26,21 @@ int efi_get_info(uint32_t idx, union xenpf_efi_info *info)
 {
     return -ENOSYS;
 }
-#endif /* CONFIG_PLATFORM_OP */
 
 int efi_runtime_call(struct xenpf_efi_runtime_call *op)
 {
     return -ENOSYS;
 }
+#endif /* CONFIG_PLATFORM_OP */
 
 #ifdef CONFIG_COMPAT
 
 #ifdef CONFIG_PLATFORM_OP
 int efi_compat_get_info(uint32_t idx, union compat_pf_efi_info *)
     __attribute__((__alias__("efi_get_info")));
-#endif /* CONFIG_PLATFORM_OP */
 
 int efi_compat_runtime_call(struct compat_pf_efi_runtime_call *)
     __attribute__((__alias__("efi_runtime_call")));
+#endif /* CONFIG_PLATFORM_OP */
 
 #endif
xen/common/efi/compat.c +1 -1
index 4f5f59fcac2e..f350958c96b3 100644
@@ -4,10 +4,10 @@
 #ifdef CONFIG_PLATFORM_OP
 #define efi_get_info efi_compat_get_info
 #define xenpf_efi_info compat_pf_efi_info
-#endif
 
 #define efi_runtime_call efi_compat_runtime_call
 #define xenpf_efi_runtime_call compat_pf_efi_runtime_call
+#endif
 
 #define xenpf_efi_guid compat_pf_efi_guid
 #define xenpf_efi_time compat_pf_efi_time
xen/common/efi/runtime.c +2 -0
index ab63785397e2..b1f1d677d2cb 100644
@@ -329,6 +329,7 @@ int efi_get_info(uint32_t idx, union xenpf_efi_info *info)
 }
 #endif /* CONFIG_PLATFORM_OP */
 
+#ifdef CONFIG_PLATFORM_OP
 static long gwstrlen(XEN_GUEST_HANDLE_PARAM(CHAR16) str)
 {
     unsigned long len;
@@ -715,4 +716,5 @@ int efi_runtime_call(struct xenpf_efi_runtime_call *op)
 
     return rc;
 }
+#endif /* CONFIG_PLATFORM_OP */
 #endif
Signature · 1 line
2.34.1
#6 lore raw

PATCH 6/11 xen/platform_op: Wrap around XENPF_enter_acpi_sleep

In reply to Jiqian Chen

Wrap call stack functions of XENPF_enter_acpi_sleep:
acpi_enter_sleep

	enter_state_helper
		enter_state
			freeze_domains
			scheduler_disable
				schedule_dummy
			disable_nonboot_cpus
			acpi_sleep_prepare
			device_power_down
				console_suspend
					console_steal
					suspend_steal_fn
					serial_suspend
				i8259A_suspend
					save_ELCR
				ioapic_suspend
				iommu_suspend
				lapic_suspend
			device_power_up
				lapic_resume
					resume_x2apic
				iommu_resume
				ioapic_resume
				i8259A_resume
				console_resume
					serial_resume
					console_giveback
			tboot_s3_resume
			tboot_s3_error
			acpi_sleep_post
			enable_nonboot_cpus
			thaw_domains

---
cc: Jan Beulich <[email protected]>
cc: Andrew Cooper <[email protected]>
cc: "Roger Pau Monné" <[email protected]>
cc: Anthony PERARD <[email protected]>
cc: Michal Orzel <[email protected]>
cc: Julien Grall <[email protected]>
cc: Stefano Stabellini <[email protected]>
cc: Lukasz Hawrylko <[email protected]>
cc: "Daniel P. Smith" <[email protected]>
cc: "Mateusz Mówka" <[email protected]>
cc: Dario Faggioli <[email protected]>
cc: Juergen Gross <[email protected]>
cc: George Dunlap <[email protected]>

---
 xen/arch/x86/acpi/power.c       | 4 ++++
 xen/arch/x86/apic.c             | 4 ++++
 xen/arch/x86/i8259.c            | 2 ++
 xen/arch/x86/io_apic.c          | 2 ++
 xen/arch/x86/tboot.c            | 2 ++
 xen/common/cpu.c                | 2 ++
 xen/common/domain.c             | 4 ++--
 xen/common/sched/core.c         | 2 ++
 xen/drivers/char/console.c      | 6 ++++--
 xen/drivers/passthrough/iommu.c | 2 ++
 10 files changed, 26 insertions(+), 4 deletions(-)
xen/arch/x86/acpi/power.c +4 -0
index 2ac162c997fe..a0c76a146793 100644
@@ -66,7 +66,9 @@ static int __init cf_check parse_acpi_sleep(const char *s)
 }
 custom_param("acpi_sleep", parse_acpi_sleep);
 
+#ifdef CONFIG_PLATFORM_OP
 static DEFINE_SPINLOCK(pm_lock);
+#endif
 
 struct acpi_sleep_info acpi_sinfo;
 
@@ -84,6 +86,7 @@ enum dev_power_saved
     SAVED_ALL,
 };
 
+#ifdef CONFIG_PLATFORM_OP
 static int device_power_down(void)
 {
     if ( console_suspend() )
@@ -376,6 +379,7 @@ int acpi_enter_sleep(const struct xenpf_enter_acpi_sleep *sleep)
 
     return continue_hypercall_on_cpu(0, enter_state_helper, &acpi_sinfo);
 }
+#endif /* CONFIG_PLATFORM_OP */
 
 static int acpi_get_wake_status(void)
 {
xen/arch/x86/apic.c +4 -0
index 0fd8bdba7067..1ee9ee120cb2 100644
@@ -479,12 +479,14 @@ static void __enable_x2apic(void)
     }
 }
 
+#ifdef CONFIG_PLATFORM_OP
 static void resume_x2apic(void)
 {
     if ( iommu_x2apic_enabled )
         iommu_enable_x2apic();
     __enable_x2apic();
 }
+#endif /* CONFIG_PLATFORM_OP */
 
 void setup_local_APIC(bool bsp)
 {
@@ -635,6 +637,7 @@ void setup_local_APIC(bool bsp)
     apic_pm_activate();
 }
 
+#ifdef CONFIG_PLATFORM_OP
 int lapic_suspend(void)
 {
     unsigned long flags;
@@ -727,6 +730,7 @@ int lapic_resume(void)
     local_irq_restore(flags);
     return 0;
 }
+#endif /* CONFIG_PLATFORM_OP */
 
 
 /*
xen/arch/x86/i8259.c +2 -0
index 5c7e21a7515c..8a7c89f3827e 100644
@@ -255,6 +255,7 @@ static bool _mask_and_ack_8259A_irq(unsigned int irq)
     return is_real_irq;
 }
 
+#ifdef CONFIG_PLATFORM_OP
 static char irq_trigger[2];
 /**
  * ELCR registers (0x4d0, 0x4d1) control edge/level of IRQ
@@ -284,6 +285,7 @@ int i8259A_suspend(void)
     save_ELCR(irq_trigger);
     return 0;
 }
+#endif
 
 void init_8259A(int auto_eoi)
 {
xen/arch/x86/io_apic.c +2 -0
index 1816e1c0b9f4..117ceeec633a 100644
@@ -2174,6 +2174,7 @@ void __init setup_IO_APIC(void)
     register_keyhandler('z', _print_IO_APIC_keyhandler, "dump IOAPIC info", 1);
 }
 
+#ifdef CONFIG_PLATFORM_OP
 void ioapic_suspend(void)
 {
     struct IO_APIC_route_entry *entry = ioapic_pm_state;
@@ -2211,6 +2212,7 @@ void ioapic_resume(void)
     }
     spin_unlock_irqrestore(&ioapic_lock, flags);
 }
+#endif /* CONFIG_PLATFORM_OP */
 
 /* --------------------------------------------------------------------------
                           ACPI-based IOAPIC Configuration
xen/arch/x86/tboot.c +2 -0
index d5db60d335e3..ee142759acda 100644
@@ -471,6 +471,7 @@ int __init cf_check tboot_parse_dmar_table(acpi_table_handler dmar_handler)
 
 static vmac_t orig_mac, resume_mac;
 
+#ifdef CONFIG_PLATFORM_OP
 int tboot_s3_resume(void)
 {
     if ( !tboot_in_measured_env() )
@@ -512,6 +513,7 @@ void tboot_s3_error(int error)
     printk("MAC for %s after S3 is: 0x%08"PRIx64"\n", what, resume_mac);
     panic("Memory integrity was lost on resume (%d)\n", error);
 }
+#endif /* CONFIG_PLATFORM_OP */
 
 int tboot_wake_ap(int apicid, unsigned long sipi_vec)
 {
xen/common/cpu.c +2 -0
index f09af0444b6a..32e803d65da3 100644
@@ -190,6 +190,7 @@ void notify_cpu_starting(unsigned int cpu)
     cpu_notifier_call_chain(cpu, CPU_STARTING, NULL, true);
 }
 
+#ifdef CONFIG_PLATFORM_OP
 static cpumask_t frozen_cpus;
 
 int disable_nonboot_cpus(void)
@@ -247,3 +248,4 @@ void enable_nonboot_cpus(void)
 
     cpumask_clear(&frozen_cpus);
 }
+#endif /* CONFIG_PLATFORM_OP */
xen/common/domain.c +2 -2
index 303c338ef293..5eeb3efdfad0 100644
@@ -2411,7 +2411,7 @@ domid_t get_initial_domain_id(void)
     return 0;
 }
 
-#ifdef CONFIG_SYSTEM_SUSPEND
+#if defined(CONFIG_SYSTEM_SUSPEND) && defined(CONFIG_PLATFORM_OP)
 
 void freeze_domains(void)
 {
@@ -2438,7 +2438,7 @@ void thaw_domains(void)
     rcu_read_unlock(&domlist_read_lock);
 }
 
-#endif /* CONFIG_SYSTEM_SUSPEND */
+#endif /* CONFIG_SYSTEM_SUSPEND and CONFIG_PLATFORM_OP*/
 
 /*
  * Local variables:
xen/common/sched/core.c +2 -0
index ea95dea65a58..2ab86e6227df 100644
@@ -2967,6 +2967,7 @@ const cpumask_t *sched_get_opt_cpumask(enum sched_gran opt, unsigned int cpu)
     return mask;
 }
 
+#ifdef CONFIG_PLATFORM_OP
 static void cf_check schedule_dummy(void)
 {
     sched_tasklet_check_cpu(smp_processor_id());
@@ -2978,6 +2979,7 @@ void scheduler_disable(void)
     open_softirq(SCHEDULE_SOFTIRQ, schedule_dummy);
     open_softirq(SCHED_SLAVE_SOFTIRQ, schedule_dummy);
 }
+#endif /* CONFIG_PLATFORM_OP */
 
 void scheduler_enable(void)
 {
xen/drivers/char/console.c +4 -2
index c5afac9f7259..83da6f095aff 100644
@@ -428,6 +428,7 @@ static unsigned int serial_rx_cons, serial_rx_prod;
 
 static void (*serial_steal_fn)(const char *str, size_t nr) = early_puts;
 
+#ifdef CONFIG_PLATFORM_OP
 int console_steal(int handle, void (*fn)(const char *str, size_t nr))
 {
     if ( (handle == -1) || (handle != sercon_handle) )
@@ -445,6 +446,7 @@ void console_giveback(int id)
     if ( id == 1 )
         serial_steal_fn = NULL;
 }
+#endif /* CONFIG_PLATFORM_OP */
 
 void console_serial_puts(const char *s, size_t nr)
 {
@@ -1367,7 +1369,7 @@ void panic(const char *fmt, ...)
         machine_restart(5000);
 }
 
-#ifdef CONFIG_SYSTEM_SUSPEND
+#if defined(CONFIG_SYSTEM_SUSPEND) && defined(CONFIG_PLATFORM_OP)
 
 /*
  * **************************************************************
@@ -1392,7 +1394,7 @@ int console_resume(void)
     return 0;
 }
 
-#endif /* CONFIG_SYSTEM_SUSPEND */
+#endif /* CONFIG_SYSTEM_SUSPEND and CONFIG_PLATFORM_OP*/
 
 /*
  * Local variables:
xen/drivers/passthrough/iommu.c +2 -0
index c9425d6971cb..0a0080452721 100644
@@ -611,6 +611,7 @@ int __init iommu_setup(void)
     return rc;
 }
 
+#ifdef CONFIG_PLATFORM_OP
 int iommu_suspend(void)
 {
     if ( iommu_enabled )
@@ -624,6 +625,7 @@ void iommu_resume(void)
     if ( iommu_enabled )
         iommu_vcall(iommu_get_ops(), resume);
 }
+#endif /* CONFIG_PLATFORM_OP */
 
 int iommu_do_domctl(
     struct xen_domctl *domctl, struct domain *d,
Signature · 1 line
2.34.1
#7 lore raw

PATCH 7/11 xen/platform_op: Wrap around XENPF_set_processor_pminfo

In reply to Jiqian Chen

Wrap around the call stack functions of XENPF_set_processor_pminfo:
set_px_pminfo
print_PCT
print_PSS
print_PSD
print_PPC
check_psd_pminfo
cpufreq_limit_change
cpufreq_cpu_init
set_cx_pminfo
copy_from_compat_state
set_cx
check_cx
acpi_processor_ffh_cstate_probe acpi_processor_power_init_bm_check
acpi_set_pdc_bits
arch_acpi_set_pdc_bits
get_mwait_ecx

And file xen/arch/x86/x86_64/cpufreq.c and xen/arch/x86/x86_64/cpu_idle.c only have compat_set_px_pminfo and compat_set_cx_pminfo related functions, also wrap them.

---
cc: Jan Beulich <[email protected]>
cc: Andrew Cooper <[email protected]>
cc: "Roger Pau Monné" <[email protected]>

---
 xen/arch/x86/acpi/cpu_idle.c        | 6 ++++++
 xen/arch/x86/acpi/cpufreq/cpufreq.c | 2 ++
 xen/arch/x86/acpi/lib.c             | 2 ++
 xen/arch/x86/x86_64/Makefile        | 5 +++--
 xen/drivers/cpufreq/cpufreq.c       | 4 ++++
 5 files changed, 17 insertions(+), 2 deletions(-)
xen/arch/x86/acpi/cpu_idle.c +6 -0
index d60a07bfd56b..37b3272473f3 100644
@@ -986,6 +986,7 @@ int cpuidle_init_cpu(unsigned int cpu)
     return 0;
 }
 
+#ifdef CONFIG_PLATFORM_OP
 static int acpi_processor_ffh_cstate_probe(xen_processor_cx_t *cx)
 {
     struct cpuinfo_x86 *c = &current_cpu_data;
@@ -1168,10 +1169,12 @@ static int check_cx(struct acpi_processor_power *power, xen_processor_cx_t *cx)
 
     return 0;
 }
+#endif /* CONFIG_PLATFORM_OP */
 
 static unsigned int latency_factor = 2;
 integer_param("idle_latency_factor", latency_factor);
 
+#ifdef CONFIG_PLATFORM_OP
 static void set_cx(
     struct acpi_processor_power *acpi_power,
     xen_processor_cx_t *xen_cx)
@@ -1230,6 +1233,7 @@ static void set_cx(
     if ( cx->type == ACPI_STATE_C1 || cx->type == ACPI_STATE_C2 )
         acpi_power->safe_state = cx;
 }
+#endif /* CONFIG_PLATFORM_OP */
 
 int get_cpu_id(u32 acpi_id)
 {
@@ -1302,6 +1306,7 @@ static void print_cx_pminfo(uint32_t cpu, struct xen_processor_power *power)
 #define print_cx_pminfo(c, p)
 #endif
 
+#ifdef CONFIG_PLATFORM_OP
 long set_cx_pminfo(uint32_t acpi_id, struct xen_processor_power *power)
 {
     XEN_GUEST_HANDLE(xen_processor_cx_t) states;
@@ -1389,6 +1394,7 @@ long set_cx_pminfo(uint32_t acpi_id, struct xen_processor_power *power)
 
     return 0;
 }
+#endif /* CONFIG_PLATFORM_OP */
 
 static void amd_cpuidle_init(struct acpi_processor_power *power)
 {
xen/arch/x86/acpi/cpufreq/cpufreq.c +2 -0
index 45f301f354ac..333b57f3e015 100644
@@ -179,6 +179,7 @@ static int __init cf_check cpufreq_driver_late_init(void)
 }
 __initcall(cpufreq_driver_late_init);
 
+#ifdef CONFIG_PLATFORM_OP
 int cpufreq_cpu_init(unsigned int cpu)
 {
     /* Currently we only handle Intel, AMD and Hygon processor */
@@ -188,3 +189,4 @@ int cpufreq_cpu_init(unsigned int cpu)
 
     return -EOPNOTSUPP;
 }
+#endif /* CONFIG_PLATFORM_OP */
xen/arch/x86/acpi/lib.c +2 -0
index 51cb082ca02a..06afc7f3f71a 100644
@@ -101,6 +101,7 @@ unsigned int acpi_get_processor_id(unsigned int cpu)
 	return INVALID_ACPIID;
 }
 
+#ifdef CONFIG_PLATFORM_OP
 static void cf_check get_mwait_ecx(void *info)
 {
 	*(u32 *)info = cpuid_ecx(CPUID_MWAIT_LEAF);
@@ -147,3 +148,4 @@ int arch_acpi_set_pdc_bits(u32 acpi_id, u32 *pdc, u32 mask)
 
 	return 0;
 }
+#endif /* CONFIG_PLATFORM_OP */
xen/arch/x86/x86_64/Makefile +3 -2
index 472b2bab523d..8778d49870a9 100644
@@ -9,6 +9,7 @@ obj-y += mmconf-fam10h.o
 obj-y += mmconfig_64.o
 obj-y += mmconfig-shared.o
 obj-$(CONFIG_COMPAT) += domain.o
-obj-$(CONFIG_COMPAT) += cpu_idle.o
-obj-$(CONFIG_COMPAT) += cpufreq.o
+ifeq ($(CONFIG_COMPAT)$(CONFIG_PLATFORM_OP),yy)
+obj-y += cpu_idle.o cpufreq.o
+endif
 obj-bin-$(CONFIG_KEXEC) += kexec_reloc.o
xen/drivers/cpufreq/cpufreq.c +4 -0
index efba1414188a..396a3a9fd092 100644
@@ -168,6 +168,7 @@ int __init cpufreq_register_governor(struct cpufreq_governor *governor)
     return 0;
 }
 
+#ifdef CONFIG_PLATFORM_OP
 int cpufreq_limit_change(unsigned int cpu)
 {
     struct processor_performance *perf;
@@ -190,6 +191,7 @@ int cpufreq_limit_change(unsigned int cpu)
 
     return __cpufreq_set_policy(data, &policy);
 }
+#endif /* CONFIG_PLATFORM_OP */
 
 static int get_psd_info(unsigned int cpu, unsigned int *shared_type,
                         const struct xen_psd_package **domain_info)
@@ -460,6 +462,7 @@ int cpufreq_del_cpu(unsigned int cpu)
     return 0;
 }
 
+#ifdef CONFIG_PLATFORM_OP
 static void print_PCT(struct xen_pct_register *ptr)
 {
     printk("\t_PCT: descriptor=%d, length=%d, space_id=%d, "
@@ -661,6 +664,7 @@ int acpi_set_pdc_bits(unsigned int acpi_id, XEN_GUEST_HANDLE(uint32) pdc)
 
     return ret;
 }
+#endif /* CONFIG_PLATFORM_OP */
 
 static void cpufreq_cmdline_common_para(struct cpufreq_policy *new_policy)
 {
Signature · 1 line
2.34.1
#8 lore raw

PATCH 8/11 xen/xsm: Wrap around xsm_resource_(un)plug_core

In reply to Jiqian Chen

Since xsm_resource_plug_core and xsm_resource_unplug_core are only used for arch/x86/platform_hypercall.c and arch/sysctl.c, so wrap around them with CONFIG_SYSCTL and CONFIG_PLATFORM_OP.

---
cc: "Daniel P. Smith" <[email protected]>

---
 xen/include/xsm/xsm.h | 8 ++++++++
 xen/xsm/dummy.c       | 2 ++
 2 files changed, 10 insertions(+)
xen/include/xsm/xsm.h +8 -0
index bc0a0776c895..546a1aa57e37 100644
@@ -577,12 +577,20 @@ static inline int xsm_resource_unplug_pci(
 
 static inline int xsm_resource_plug_core(xsm_default_t def)
 {
+#if defined(CONFIG_SYSCTL) || defined(CONFIG_PLATFORM_OP)
     return alternative_call(xsm_ops.resource_plug_core);
+#else
+    return -EOPNOTSUPP;
+#endif
 }
 
 static inline int xsm_resource_unplug_core(xsm_default_t def)
 {
+#if defined(CONFIG_SYSCTL) || defined(CONFIG_PLATFORM_OP)
     return alternative_call(xsm_ops.resource_unplug_core);
+#else
+    return -EOPNOTSUPP;
+#endif
 }
 
 static inline int xsm_resource_setup_pci(
xen/xsm/dummy.c +2 -0
index d9f4d3ee12b1..ab6eb2149376 100644
@@ -90,8 +90,10 @@ static const struct xsm_ops __initconst_cf_clobber dummy_ops = {
     .deassign_dtdevice             = xsm_deassign_dtdevice,
 #endif
 
+#if defined(CONFIG_SYSCTL) || defined(CONFIG_PLATFORM_OP)
     .resource_plug_core            = xsm_resource_plug_core,
     .resource_unplug_core          = xsm_resource_unplug_core,
+#endif
     .resource_plug_pci             = xsm_resource_plug_pci,
     .resource_unplug_pci           = xsm_resource_unplug_pci,
     .resource_setup_pci            = xsm_resource_setup_pci,
Signature · 1 line
2.34.1
#9 lore raw

PATCH 9/11 xen/platform_op: Wrap around XENPF_mem_hotadd

In reply to Jiqian Chen

Wrap around call stack functions of XENPF_mem_hotadd:
memory_add
mem_hotadd_check
valid_numa_range
extend_frame_table
setup_frametable_chunk
setup_m2p_table
m2p_mapped setup_compat_m2p_table
alloc_hotadd_mfn
share_hotadd_m2p_table transfer_pages_to_heap destroy_m2p_mapping
destroy_compat_m2p_mapping
cleanup_frame_table
hotadd_mem_valid

---
cc: Jan Beulich <[email protected]>
cc: Andrew Cooper <[email protected]>
cc: "Roger Pau Monné" <[email protected]>
cc: Anthony PERARD <[email protected]>
cc: Michal Orzel <[email protected]>
cc: Julien Grall <[email protected]>
cc: Stefano Stabellini <[email protected]>

---
 xen/arch/x86/x86_64/mm.c | 6 ++++++
 xen/common/numa.c        | 2 ++
 2 files changed, 8 insertions(+)
xen/arch/x86/x86_64/mm.c +6 -0
index d4e6a9c0a2e0..5952bca8cd84 100644
@@ -111,6 +111,7 @@ void *do_page_walk(struct vcpu *v, unsigned long addr)
     return map_domain_page(_mfn(mfn)) + (addr & ~PAGE_MASK);
 }
 
+#ifdef CONFIG_PLATFORM_OP
 /*
  * Allocate page table pages for m2p table
  */
@@ -496,6 +497,7 @@ error:
     unmap_domain_page(l3_ro_mpt);
     return ret;
 }
+#endif /* CONFIG_PLATFORM_OP */
 
 void __init paging_init(void)
 {
@@ -743,6 +745,7 @@ void free_compat_arg_xlat(struct vcpu *v)
                               PFN_UP(COMPAT_ARG_XLAT_SIZE));
 }
 
+#ifdef CONFIG_PLATFORM_OP
 static void cleanup_frame_table(struct mem_hotadd_info *info)
 {
     unsigned long sva, eva;
@@ -861,6 +864,7 @@ static int extend_frame_table(struct mem_hotadd_info *info)
            (unsigned long)mfn_to_page(epfn) - (unsigned long)mfn_to_page(spfn));
     return 0;
 }
+#endif /* CONFIG_PLATFORM_OP */
 
 void __init subarch_init_memory(void)
 {
@@ -1139,6 +1143,7 @@ unsigned int domain_clamp_alloc_bitsize(struct domain *d, unsigned int bits)
     return min(d->arch.physaddr_bitsize, bits);
 }
 
+#ifdef CONFIG_PLATFORM_OP
 static int transfer_pages_to_heap(struct mem_hotadd_info *info)
 {
     unsigned long i;
@@ -1360,6 +1365,7 @@ destroy_frametable:
 
     return ret;
 }
+#endif /* CONFIG_PLATFORM_OP */
 
 void set_gpfn_from_mfn(unsigned long mfn, unsigned long pfn)
 {
xen/common/numa.c +2 -0
index ad75955a1622..9a1b7e3a729c 100644
@@ -59,6 +59,7 @@ void __init numa_set_processor_nodes_parsed(nodeid_t node)
     node_set(node, processor_nodes_parsed);
 }
 
+#ifdef CONFIG_PLATFORM_OP
 bool valid_numa_range(paddr_t start, paddr_t end, nodeid_t node)
 {
     unsigned int i;
@@ -74,6 +75,7 @@ bool valid_numa_range(paddr_t start, paddr_t end, nodeid_t node)
 
     return false;
 }
+#endif /* CONFIG_PLATFORM_OP */
 
 static enum conflicts __init conflicting_memblks(
     nodeid_t nid, paddr_t start, paddr_t end, paddr_t nd_start,
Signature · 1 line
2.34.1
#10 lore raw

PATCH 10/11 xen/platform_op: Wrap around XENPF_core_parking

In reply to Jiqian Chen

core_parking_helper() and get_cur_idle_nums() are only used for XENPF_core_parking, so wrap them.

---
cc: Andrew Cooper <[email protected]>
cc: Anthony PERARD <[email protected]>
cc: Michal Orzel <[email protected]>
cc: Jan Beulich <[email protected]>
cc: Julien Grall <[email protected]>
cc: "Roger Pau Monné" <[email protected]>
cc: Stefano Stabellini <[email protected]>

---
 xen/common/core_parking.c | 4 ++++
 1 file changed, 4 insertions(+)
xen/common/core_parking.c +4 -0
index 7d6a18cdcf4c..2b763f83da93 100644
@@ -170,6 +170,7 @@ static unsigned int cf_check core_parking_power(unsigned int event)
     return cpu;
 }
 
+#ifdef CONFIG_PLATFORM_OP
 long cf_check core_parking_helper(void *data)
 {
     uint32_t idle_nums = (unsigned long)data;
@@ -213,6 +214,7 @@ long cf_check core_parking_helper(void *data)
 
     return ret;
 }
+#endif /* CONFIG_PLATFORM_OP */
 
 bool core_parking_remove(unsigned int cpu)
 {
@@ -237,10 +239,12 @@ bool core_parking_remove(unsigned int cpu)
     return found;
 }
 
+#ifdef CONFIG_PLATFORM_OP
 uint32_t get_cur_idle_nums(void)
 {
     return cur_idle_nums;
 }
+#endif /* CONFIG_PLATFORM_OP */
 
 static const struct cp_policy __initconst_cf_clobber power_first = {
     .name = "power",
Signature · 1 line
2.34.1
#11 lore raw

PATCH 11/11 xen/platform_op: Wrap around platform_op hypercall

In reply to Jiqian Chen

Wrap platform_op hypercall definition and platform_hypercall.o of arm and x86 with CONFIG_PLATFORM_OP, and since PV_SHIM_EXCLUSIVE needs sorting in the future, move them out of PV_SHIM_EXCLUSIVE condition at the same time.

And need to make PLATFORM_OP with help info. It shall at least provide "# CONFIG_PLATFORM_OP is not set" in preset configs for PV shim on x86. With that, all dependent option get covered and could be deleted.

---
cc: Stefano Stabellini <[email protected]>
cc: Julien Grall <[email protected]>
cc: Bertrand Marquis <[email protected]>
cc: Michal Orzel <[email protected]>
cc: Volodymyr Babchuk <[email protected]>
cc: Andrew Cooper <[email protected]>
cc: Anthony PERARD <[email protected]>
cc: Jan Beulich <[email protected]>
cc: "Roger Pau Monné" <[email protected]>

---
 xen/arch/arm/Makefile                 | 2 +-
 xen/arch/x86/Makefile                 | 2 ++
 xen/arch/x86/configs/pvshim_defconfig | 1 +
 xen/common/Kconfig                    | 3 +++
 xen/include/hypercall-defs.c          | 6 ++++--
 5 files changed, 11 insertions(+), 3 deletions(-)
xen/arch/arm/Makefile +1 -1
index f833cdf2078b..4f9290fe6345 100644
@@ -42,7 +42,7 @@ obj-$(CONFIG_VM_EVENT) += mem_access.o
 obj-y += mm.o
 obj-$(CONFIG_VM_EVENT) += monitor.o
 obj-y += p2m.o
-obj-y += platform.o
+obj-$(CONFIG_PLATFORM_OP) += platform.o
 obj-y += platform_hypercall.o
 obj-y += physdev.o
 obj-y += processor.o
xen/arch/x86/Makefile +2 -0
index 5aab30a0c4a4..e180ab1a0409 100644
@@ -80,6 +80,8 @@ obj-y += xstate.o
 
 ifneq ($(CONFIG_PV_SHIM_EXCLUSIVE),y)
 obj-y += domctl.o
+endif
+ifeq ($(CONFIG_PLATFORM_OP),y)
 obj-y += platform_hypercall.o
 obj-$(CONFIG_COMPAT) += x86_64/platform_hypercall.o
 endif
xen/arch/x86/configs/pvshim_defconfig +1 -0
index c58c29adb0bf..e9ede13250d8 100644
@@ -25,3 +25,4 @@ CONFIG_EXPERT=y
 # CONFIG_DEBUG is not set
 # CONFIG_GDBSX is not set
 # CONFIG_SYSCTL is not set
+# CONFIG_PLATFORM_OP is not set
xen/common/Kconfig +3 -0
index 1a8f5ec93364..13b544cbb1d5 100644
@@ -630,6 +630,9 @@ config SYSCTL
 config PLATFORM_OP
 	bool "Enable Platform Operation hypercall"
 	default y
+	help
+	  This option shall only be disabled on some dom0less systems, or
+	  PV shim on x86, to reduce Xen footprint.
 
 endmenu
 
xen/include/hypercall-defs.c +4 -2
index c1081d87a252..96ad6efacd5a 100644
@@ -150,7 +150,7 @@ update_va_mapping(unsigned int va, uint32_t lo, uint32_t hi, unsigned int flags)
 physdev_op_compat(physdev_op_compat_t *uop)
 update_va_mapping_otherdomain(unsigned int va, uint32_t lo, uint32_t hi, unsigned int flags, domid_t domid)
 #endif
-#ifndef CONFIG_PV_SHIM_EXCLUSIVE
+#ifdef CONFIG_PLATFORM_OP
 platform_op(compat_platform_op_t *u_xenpf_op)
 #endif
 #ifdef CONFIG_KEXEC
@@ -200,6 +200,8 @@ sysctl(xen_sysctl_t *u_sysctl)
 #ifndef CONFIG_PV_SHIM_EXCLUSIVE
 domctl(xen_domctl_t *u_domctl)
 paging_domctl_cont(xen_domctl_t *u_domctl)
+#endif
+#ifdef CONFIG_PLATFORM_OP
 platform_op(xen_platform_op_t *u_xenpf_op)
 #endif
 #ifdef CONFIG_HVM
@@ -236,7 +238,7 @@ stack_switch                       do:2     do:2     -        -        -
 set_callbacks                      compat   do       -        -        -
 fpu_taskswitch                     do       do       -        -        -
 sched_op_compat                    do       do       -        -        dep
-#ifndef CONFIG_PV_SHIM_EXCLUSIVE
+#ifdef CONFIG_PLATFORM_OP
 platform_op                        compat   do       compat   do       do
 #endif
 set_debugreg                       do       do       -        -        -
Signature · 1 line
2.34.1
#12 lore raw
In reply to Jiqian Chen
Quoted 4 lines · Jiqian Chen

Jiqian Chen (11):
xen: Introduce CONFIG_PLATFORM_OP
xen/xsm: Wrap around xsm_platform_op with CONFIG_PLATFORM_OP xen/platform_op: Wrap around XENPF_microcode_update(2)

Quoted 8 lines

xen/platform_op: Wrap around XENPF_firmware_info xen/platform_op: Wrap around XENPF_efi_runtime_call xen/platform_op: Wrap around XENPF_enter_acpi_sleep xen/platform_op: Wrap around XENPF_set_processor_pminfo xen/xsm: Wrap around xsm_resource_(un)plug_core xen/platform_op: Wrap around XENPF_mem_hotadd xen/platform_op: Wrap around XENPF_core_parking xen/platform_op: Wrap around platform_op hypercall

Except for extreme cases, unlike for e.g. sysctl, I think it is dangerous to compile this out altogether.

Further, nit: While I let Penny's use of "Wrap around ..." as subjects go as is, the massive use here makes it necessary to indicate that I don't consider these as meaningful subjects. They simply don't say what is actually being done by the patch. One possible meaning could be that you found line wrapping issues, and correct them step by step.

Jan

#13 lore raw
In reply to Jiqian Chen
Quoted 9 lines · Jiqian Chen

Hi all,
This is a continuation of the disabling some hypercalls handling code series.
https://lore.kernel.org/xen-devel/[email protected]/

It can be beneficial for some dom0less systems to further reduce Xen footprint via disabling some hypercalls handling code, which may not to be used & required in such systems. Each hypercall has a separate option to keep configuration flexible.

Quoted 4 lines

Options to disable hypercalls:
- sysctl
- domctl
- hvm

Is this hvmop? If so, how can it reasonably be disabled when the majority of guests are HVM ones these days? Some of the operations can be invoked by guests on themselves, iirc.

Quoted 2 lines

- physdev
- platform_op

For everything else, it's not clear whether it was conveyed to you that there is a more general argument against this fine-grained splitting at the Kconfig level. Already with domctl you've learned the hard way that it's intertwined with e.g. sysctl. The basic direction to move into appears to be to allow to exclude such special "management" operations via on single control.

In the light of this it's not quite clear how useful it would be to actually review this series. In any event, before anything further can go in, issues with what has already gone in will need sorting, imo.

Jan