consolidate vm event subsystem
v4 cover consolidate vm event subsystem
This patch serie originates from "Disable domctl-op via CONFIG_MGMT_HYPERCALLS" [1], and focuses on consolidating vm event subsystem (i.e. VM_EVENT), and its derived features, like memory paging, etc.
[1] https://www.mail-archive.com/[email protected]/msg200843.html
---
Happy 2026!
Sorry for the late response to this patch serie and the domctl one. v4 is just doing a rebase on the latest staging, and one comment fix. I still need 2 acks for commit "xen/p2m: move xenmem_access_to_p2m_access() to common p2m.c" and "xen/mem_access: wrap memory access when VM_EVENT=n".
---
Penny Zheng (6):
xen/x86: move declaration from mem_access.h to altp2m.h x86/vm_event: introduce vm_event_is_enabled() x86/monitor: wrap monitor_op under CONFIG_VM_EVENT xen/p2m: move xenmem_access_to_p2m_access() to common p2m.c xen/mem_access: wrap memory access when VM_EVENT=n xen/vm_event: consolidate CONFIG_VM_EVENT
xen/arch/x86/Makefile | 2 +- xen/arch/x86/hvm/Kconfig | 1 - xen/arch/x86/hvm/Makefile | 4 +- xen/arch/x86/hvm/emulate.c | 67 ++++++++++++------------ xen/arch/x86/hvm/hvm.c | 51 ++++++++++++++++--- xen/arch/x86/hvm/svm/intr.c | 2 +- xen/arch/x86/hvm/svm/svm.c | 54 ++++++++++++-------- xen/arch/x86/hvm/vmx/intr.c | 2 +- xen/arch/x86/hvm/vmx/vmx.c | 73 ++++++++++++++++++--------- xen/arch/x86/include/asm/altp2m.h | 10 ++++ xen/arch/x86/include/asm/hvm/hvm.h | 18 ++++--- xen/arch/x86/include/asm/mem_access.h | 20 ++++---- xen/arch/x86/include/asm/monitor.h | 9 ++++ xen/arch/x86/include/asm/vm_event.h | 5 ++ xen/arch/x86/mm/mem_access.c | 36 ------------- xen/arch/x86/mm/mem_sharing.c | 3 ++ xen/arch/x86/mm/p2m.c | 40 +++++++++++++++ xen/common/Kconfig | 7 +-- xen/include/xen/mem_access.h | 5 -- xen/include/xen/p2m-common.h | 3 ++ xen/include/xen/vm_event.h | 7 +++ 21 files changed, 266 insertions(+), 153 deletions(-)
Signature · 1 line
2.34.1
PATCH v4 1/6 xen/x86: move declaration from mem_access.h to altp2m.h
Memory access and ALTP2M are two seperate features, and each could be controlled via VM_EVENT or ALTP2M. In order to avoid implicit declaration when ALTP2M=y and VM_EVENT=n on compiling hvm.o/altp2m.o, we move declaration of the following functions from <asm/mem_access.h> to <asm/altp2m.h>:
- p2m_set_suppress_ve
- p2m_set_suppress_ve_multi
- p2m_get_suppress_ve
Potential error on altp2m.c also breaks Misra Rule 8.4.
--- xen/arch/x86/include/asm/altp2m.h | 10 ++++++++++ xen/arch/x86/include/asm/mem_access.h | 10 ---------- 2 files changed, 10 insertions(+), 10 deletions(-)
xen/arch/x86/include/asm/altp2m.h +10 -0
@@ -46,6 +46,16 @@ void altp2m_vcpu_destroy(struct vcpu *v);int altp2m_vcpu_enable_ve (struct vcpu *v,gfn_t gfn);void altp2m_vcpu_disable_ve (struct vcpu *v); +int p2m_set_suppress_ve (struct domain *d,gfn_t gfn,bool suppress_ve, +unsigned int altp2m_idx); + +struct xen_hvm_altp2m_suppress_ve_multi ; +int p2m_set_suppress_ve_multi (struct domain *d, +struct xen_hvm_altp2m_suppress_ve_multi *sve); + +int p2m_get_suppress_ve (struct domain *d,gfn_t gfn,bool *suppress_ve, +unsigned int altp2m_idx); +#else static inline bool altp2m_is_eptp_valid(const struct domain *d,
xen/arch/x86/include/asm/mem_access.h +0 -10
@@ -34,16 +34,6 @@ bool p2m_mem_access_emulate_check(struct vcpu *v,/* Sanity check for mem_access hardware support */ bool p2m_mem_access_sanity_check (const struct domain *d); -int p2m_set_suppress_ve (struct domain *d,gfn_t gfn,bool suppress_ve, -unsigned int altp2m_idx); - -struct xen_hvm_altp2m_suppress_ve_multi ; -int p2m_set_suppress_ve_multi (struct domain *d, -struct xen_hvm_altp2m_suppress_ve_multi *sve); - -int p2m_get_suppress_ve (struct domain *d,gfn_t gfn,bool *suppress_ve, -unsigned int altp2m_idx); -#endif /*__ASM_X86_MEM_ACCESS_H__ */ /*
Signature · 1 line
2.34.1
Re: [PATCH v4 1/6] xen/x86: move declaration from mem_access.h to altp2m.h
Quoted 9 lines · Penny Zheng
Memory access and ALTP2M are two seperate features, and each could be controlled via
VM_EVENTor ALTP2M. In order to avoid implicit declaration when ALTP2M=y and VM_EVENT=n on compilinghvm.o/altp2m.o, we move declaration of the following functions from <asm/mem_access.h> to <asm/altp2m.h>:
-p2m_set_suppress_ve
-p2m_set_suppress_ve_multi
-p2m_get_suppress_ve
Potential error onaltp2m.calso breaks Misra Rule 8.4.
Quoted 7 lines
Signed-off-by Penny Zheng <[email protected]>Reviewed-by Jan Beulich <[email protected]>Reviewed-by Jason Andryuk <[email protected]>--- xen/arch/x86/include/asm/altp2m.h | 10 ++++++++++ xen/arch/x86/include/asm/mem_access.h | 10 ---------- 2 files changed, 10 insertions(+), 10 deletions(-)
Tamas - can we please get an ack here? I guess I'll time out on waiting for one in a day or two.
Penny - may I remind you that it is on you to chase missing acks?
Jan
Re: [PATCH v4 1/6] xen/x86: move declaration from mem_access.h to altp2m.h
In reply to Penny ZhengQuoted 10 lines · Penny Zheng
Memory access and ALTP2M are two seperate features, and each could be controlled via
VM_EVENTor ALTP2M. In order to avoid implicit declaration when ALTP2M=y and VM_EVENT=n on compilinghvm.o/altp2m.o, we move declaration
of the following functions from <asm/mem_access.h> to <asm/altp2m.h>:
-p2m_set_suppress_ve
-p2m_set_suppress_ve_multi
-p2m_get_suppress_ve
Potential error onaltp2m.calso breaks Misra Rule 8.4.
Quoted 3 lines
Signed-off-by Penny Zheng <[email protected]>Reviewed-by Jan Beulich <[email protected]>Reviewed-by Jason Andryuk <[email protected]>
Re: [PATCH v4 1/6] xen/x86: move declaration from mem_access.h to altp2m.h
Quoted 12 lines · Tamas K Lengyel
Quoted 10 lines · Penny Zheng
Memory access and ALTP2M are two seperate features, and each could be controlled via
VM_EVENTor ALTP2M. In order to avoid implicit declaration when ALTP2M=y and VM_EVENT=n on compilinghvm.o/altp2m.o, we move declaration
of the following functions from <asm/mem_access.h> to <asm/altp2m.h>:
-p2m_set_suppress_ve
-p2m_set_suppress_ve_multi
-p2m_get_suppress_ve
Potential error onaltp2m.calso breaks Misra Rule 8.4.
Quoted 5 lines
Quoted 3 lines
Signed-off-by Penny Zheng <[email protected]>Reviewed-by Jan Beulich <[email protected]>Reviewed-by Jason Andryuk <[email protected]>Acked-by Tamas K Lengyel <[email protected]>
Thanks for the ack here as well as the ones for 4 and 6. What about 2, 3, and 5 though?
Jan
PATCH v4 3/6 x86/monitor: wrap monitor_op under CONFIG_VM_EVENT
In reply to Penny ZhengFeature monitor_op is based on vm event subsystem, so monitor.o shall be wrapped under CONFIG_VM_EVENT.
The following functions are only invoked by monitor-op, so they all shall be wrapped with CONFIG_VM_EVENT (otherwise they will become unreachable and violate Misra rule 2.1 when VM_EVENT=n):
- hvm_enable_msr_interception
- hvm_function_table.enable_msr_interception
- hvm_has_set_descriptor_access_existing
- hvm_function_table.set_descriptor_access_existi
- arch_monitor_get_capabilities
Function monitored_msr() still needs a stub to pass compilation when VM_EVENT=n.
--- xen/arch/x86/hvm/Makefile | 2 +- xen/arch/x86/hvm/svm/svm.c | 8 +++++++- xen/arch/x86/hvm/vmx/vmx.c | 10 ++++++++++ xen/arch/x86/include/asm/hvm/hvm.h | 18 +++++++++++------- xen/arch/x86/include/asm/monitor.h | 9 +++++++++ 5 files changed, 38 insertions(+), 9 deletions(-)
xen/arch/x86/hvm/Makefile +1 -1
@@ -16,7 +16,7 @@ obj-y += io.o obj-y += ioreq.o obj-y += irq.o obj-y += mmio.o -obj-y += monitor.o +obj-$(CONFIG_VM_EVENT) += monitor.o obj-y += mtrr.o obj-y += nestedhvm.o obj-y += pmtimer.o
xen/arch/x86/hvm/svm/svm.c +7 -1
@@ -297,6 +297,7 @@ void svm_intercept_msr(struct vcpu *v, uint32_t msr, int flags)__clear_bit (msr *2 +1 , msr_bit); } +#ifdef CONFIG_VM_EVENT static void cf_check svm_enable_msr_interception(struct domain *d, uint32_t msr) {struct vcpu *v;
@@ -304,6 +305,7 @@ static void cf_check svm_enable_msr_interception(struct domain *d, uint32_t msr) for_each_vcpu ( d, v ) svm_intercept_msr(v, msr, MSR_INTERCEPT_WRITE); } +#endif /* CONFIG_VM_EVENT */ static void svm_save_dr (struct vcpu *v) {
@@ -824,6 +826,7 @@ static void cf_check svm_set_rdtsc_exiting(struct vcpu *v, bool enable)vmcb_set_general2_intercepts (vmcb, general2_intercepts); } +#ifdef CONFIG_VM_EVENT static void cf_check svm_set_descriptor_access_exiting(struct vcpu *v,bool enable) {
@@ -841,6 +844,7 @@ static void cf_check svm_set_descriptor_access_exiting(vmcb_set_general1_intercepts (vmcb, general1_intercepts); } +#endif /* CONFIG_VM_EVENT */ static unsigned int cf_check svm_get_insn_bytes(struct vcpu *v, uint8_t *buf) {
@@ -2454,9 +2458,11 @@ static struct hvm_function_table __initdata_cf_clobber svm_function_table = { .fpu_dirty_intercept = svm_fpu_dirty_intercept, .msr_read_intercept = svm_msr_read_intercept, .msr_write_intercept = svm_msr_write_intercept, +#ifdef CONFIG_VM_EVENT .enable_msr_interception = svm_enable_msr_interception, - .set_rdtsc_exiting = svm_set_rdtsc_exiting, .set_descriptor_access_exiting = svm_set_descriptor_access_exiting, +#endif + .set_rdtsc_exiting = svm_set_rdtsc_exiting, .get_insn_bytes = svm_get_insn_bytes, .nhvm_vcpu_initialise = nsvm_vcpu_initialise,
xen/arch/x86/hvm/vmx/vmx.c +10 -0
@@ -1581,6 +1581,7 @@ static void cf_check vmx_set_rdtsc_exiting(struct vcpu *v, bool enable)vmx_vmcs_exit (v); } +#ifdef CONFIG_VM_EVENT static void cf_check vmx_set_descriptor_access_exiting(struct vcpu *v,bool enable) {
@@ -1595,6 +1596,7 @@ static void cf_check vmx_set_descriptor_access_exiting(vmx_update_secondary_exec_control (v);vmx_vmcs_exit (v); } +#endif /* CONFIG_VM_EVENT */ static void cf_check vmx_init_hypercall_page(void *p) {
@@ -2474,6 +2476,7 @@ static void cf_check vmx_handle_eoi(uint8_t vector, int isr)printk_once (XENLOG_WARNING "EOI for %02x but SVI=%02x\n" , vector, old_svi); } +#ifdef CONFIG_VM_EVENT static void cf_check vmx_enable_msr_interception(struct domain *d, uint32_t msr) {struct vcpu *v;
@@ -2481,6 +2484,7 @@ static void cf_check vmx_enable_msr_interception(struct domain *d, uint32_t msr) for_each_vcpu ( d, v ) vmx_set_msr_intercept(v, msr, VMX_MSR_W); } +#endif /* CONFIG_VM_EVENT */ #ifdef CONFIG_ALTP2M
@@ -2932,7 +2936,9 @@ static struct hvm_function_table __initdata_cf_clobber vmx_function_table = { .nhvm_domain_relinquish_resources = nvmx_domain_relinquish_resources, .update_vlapic_mode = vmx_vlapic_msr_changed, .nhvm_hap_walk_L1_p2m = nvmx_hap_walk_L1_p2m, +#ifdef CONFIG_VM_EVENT .enable_msr_interception = vmx_enable_msr_interception, +#endif #ifdef CONFIG_ALTP2M .altp2m_vcpu_update_p2m = vmx_vcpu_update_eptp, .altp2m_vcpu_update_vmfunc_ve = vmx_vcpu_update_vmfunc_ve,
@@ -3141,9 +3147,11 @@ const struct hvm_function_table * __init start_vmx(void) vmx_function_table.caps.singlestep = cpu_has_monitor_trap_flag; +#ifdef CONFIG_VM_EVENT if ( cpu_has_vmx_dt_exiting ) vmx_function_table.set_descriptor_access_exiting = vmx_set_descriptor_access_exiting; +#endif /* * Do not enable EPT when (!cpu_has_vmx_pat), to prevent security hole
@@ -3214,8 +3222,10 @@ void __init vmx_fill_funcs(void)if ( !cpu_has_xen_ibt )return ; +#ifdef CONFIG_VM_EVENT vmx_function_table.set_descriptor_access_exiting = vmx_set_descriptor_access_exiting; +#endif vmx_function_table.update_eoi_exit_bitmap = vmx_update_eoi_exit_bitmap; vmx_function_table.process_isr = vmx_process_isr;
xen/arch/x86/include/asm/hvm/hvm.h +11 -7
@@ -192,7 +192,11 @@ struct hvm_function_table {void (*handle_cd)(struct vcpu *v,unsigned long value);void (*set_info_guest)(struct vcpu *v);void (*set_rdtsc_exiting)(struct vcpu *v,bool enable); + +#ifdef CONFIG_VM_EVENT void (*set_descriptor_access_exiting)(struct vcpu *v,bool enable); +void (*enable_msr_interception)(struct domain *d,uint32_t msr); +#endif /* Nested HVM */ int (*nhvm_vcpu_initialise)(struct vcpu *v);
@@ -224,8 +228,6 @@ struct hvm_function_table { paddr_t *L1_gpa, unsigned int *page_order, uint8_t *p2m_acc, struct npfec npfec); -void (*enable_msr_interception)(struct domain *d,uint32_t msr); -#ifdef CONFIG_ALTP2M /* Alternate p2m */ void (*altp2m_vcpu_update_p2m)(struct vcpu *v);
@@ -435,11 +437,18 @@ static inline bool using_svm(void)#define hvm_long_mode_active (v) (!!((v)->arch.hvm.guest_efer & EFER_LMA)) +#ifdef CONFIG_VM_EVENT static inline bool hvm_has_set_descriptor_access_exiting (void ) {return hvm_funcs.set_descriptor_access_exiting; } +static inline void hvm_enable_msr_interception (struct domain *d,uint32_t msr) +{ +alternative_vcall (hvm_funcs.enable_msr_interception, d, msr); +} +#endif /* CONFIG_VM_EVENT */ +static inline void hvm_domain_creation_finished (struct domain *d) {if ( hvm_funcs.domain_creation_finished )
@@ -681,11 +690,6 @@ static inline int nhvm_hap_walk_L1_p2m( v, L2_gpa, L1_gpa, page_order, p2m_acc, npfec); } -static inline void hvm_enable_msr_interception (struct domain *d,uint32_t msr) -{ -alternative_vcall (hvm_funcs.enable_msr_interception, d, msr); -} -static inline bool hvm_is_singlestep_supported (void ) {return hvm_funcs.caps.singlestep;
xen/arch/x86/include/asm/monitor.h +9 -0
@@ -71,6 +71,7 @@ int arch_monitor_domctl_op(struct domain *d, struct xen_domctl_monitor_op *mop)return rc; } +#ifdef CONFIG_VM_EVENT static inline uint32_t arch_monitor_get_capabilities (struct domain *d) {uint32_t capabilities =0 ;
@@ -102,6 +103,7 @@ static inline uint32_t arch_monitor_get_capabilities(struct domain *d) return capabilities; } +#endif /* CONFIG_VM_EVENT */ int arch_monitor_domctl_event (struct domain *d,struct xen_domctl_monitor_op *mop);
@@ -123,7 +125,14 @@ static inline void arch_monitor_cleanup_domain(struct domain *d) {}#endif +#ifdef CONFIG_VM_EVENT bool monitored_msr (const struct domain *d,u32 msr); +#else +static inline bool monitored_msr (const struct domain *d,u32 msr) +{ +return false; +} +#endif bool monitored_msr_onchangeonly (const struct domain *d,u32 msr);#endif /* __ASM_X86_MONITOR_H__ */
Signature · 1 line
2.34.1
RE: [PATCH v4 3/6] x86/monitor: wrap monitor_op under CONFIG_VM_EVENT
[Public]
Hi, Tamas
May I ask for a review on this commit?
Many thanks
Penny Zheng
Quoted 255 lines
-----Original Message-----
From: Penny, Zheng <[email protected]>
Sent: Thursday, January 15, 2026 5:29 PM
To: [email protected]; Andryuk, Jason <[email protected]>
Cc: Huang, Ray <[email protected]>; Penny, Zheng <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Tamas K Lengyel <[email protected]>; Alexandru Isaila <[email protected]>; Petre Pircalabu <[email protected]>
Subject: [PATCH v4 3/6] x86/monitor: wrapmonitor_opunderCONFIG_VM_EVENTFeature
monitor_opis based on vm event subsystem, so monitor.o shall be wrapped underCONFIG_VM_EVENT.
The following functions are only invoked by monitor-op, so they all shall be wrapped withCONFIG_VM_EVENT(otherwise they will become unreachable and violate Misra rule 2.1 when VM_EVENT=n):
-hvm_enable_msr_interception
- hvm_function_table.enable_msr_interception
-hvm_has_set_descriptor_access_existing
- hvm_function_table.set_descriptor_access_existi
-arch_monitor_get_capabilities
Functionmonitored_msr()still needs a stub to pass compilation when VM_EVENT=n.Signed-off-by Penny Zheng <[email protected]>Acked-by Jan Beulich <[email protected]>Reviewed-by Jason Andryuk <[email protected]>--- xen/arch/x86/hvm/Makefile | 2 +- xen/arch/x86/hvm/svm/svm.c | 8 +++++++- xen/arch/x86/hvm/vmx/vmx.c | 10 ++++++++++ xen/arch/x86/include/asm/hvm/hvm.h | 18 +++++++++++------- xen/arch/x86/include/asm/monitor.h | 9 +++++++++ 5 files changed, 38 insertions(+), 9 deletions(-)xen/arch/x86/hvm/Makefile index renamed from xen/arch/x86/hvm/Makefile +0
-0
1b97bdc624..ee4b45a4ee100644xen/arch/x86/hvm/Makefile +1
-1@@ -16,7 +16,7 @@ obj-y += io.o obj-y += ioreq.o obj-y += irq.o obj-y += mmio.o -obj-y += monitor.o +obj-$(CONFIG_VM_EVENT) += monitor.o obj-y += mtrr.o obj-y += nestedhvm.o obj-y += pmtimer.oxen/arch/x86/hvm/svm/svm.c index renamed from xen/arch/x86/hvm/svm/svm.c +0
-0
21f355a657..5d23603fc1100644xen/arch/x86/hvm/svm/svm.c +2
-0@@ -297,6 +297,7 @@ void svm_intercept_msr(struct vcpu *v, uint32_t msr, int flags) __clear_bit(msr * 2 + 1, msr_bit); } +#ifdef CONFIG_VM_EVENT static void cf_check svm_enable_msr_interception(struct domain *d, uint32_t msr) {struct vcpu *v;@@ -304,6 +305,7 @@ static void cf_check svm_enable_msr_interception(struct domain *d, uint32_t msr) for_each_vcpu ( d, v ) svm_intercept_msr(v, msr, MSR_INTERCEPT_WRITE); } +#endif /* CONFIG_VM_EVENT */ static void svm_save_dr(struct vcpu *v) { @@ -824,6 +826,7 @@ static void cf_check svm_set_rdtsc_exiting(struct vcpu *v, bool enable)vmcb_set_general2_intercepts(vmcb, general2_intercepts); }xen/arch/x86/hvm/svm/svm.c +2
-0+#ifdef CONFIG_VM_EVENT static void cf_check svm_set_descriptor_access_exiting(struct vcpu *v,bool enable) {@@ -841,6 +844,7 @@ static void cf_check svm_set_descriptor_access_exiting( vmcb_set_general1_intercepts(vmcb, general1_intercepts); } +#endif /* CONFIG_VM_EVENT */ static unsigned int cf_check svm_get_insn_bytes(struct vcpu *v, uint8_t *buf){ @@ -2454,9 +2458,11 @@ static struct
hvm_function_table__initdata_cf_clobbersvm_function_table= {.fpu_dirty_intercept = svm_fpu_dirty_intercept, .msr_read_intercept = svm_msr_read_intercept, .msr_write_intercept = svm_msr_write_intercept,xen/arch/x86/hvm/svm/svm.c +3
-1+#ifdef CONFIG_VM_EVENT .enable_msr_interception = svm_enable_msr_interception, - .set_rdtsc_exiting = svm_set_rdtsc_exiting, .set_descriptor_access_exiting = svm_set_descriptor_access_exiting, +#endif + .set_rdtsc_exiting = svm_set_rdtsc_exiting, .get_insn_bytes = svm_get_insn_bytes, .nhvm_vcpu_initialise = nsvm_vcpu_initialise, diff --git
a/xen/arch/x86/hvm/vmx/vmx.cb/xen/arch/x86/hvm/vmx/vmx.cindex89f9d9c7f6..40e4c71244100644xen/arch/x86/hvm/vmx/vmx.c +1
-0@@ -1581,6 +1581,7 @@ static void cf_check vmx_set_rdtsc_exiting(struct vcpu *v, bool enable)vmx_vmcs_exit (v); } +#ifdef CONFIG_VM_EVENT static void cf_check vmx_set_descriptor_access_exiting(struct vcpu *v,bool enable){
xen/arch/x86/hvm/vmx/vmx.c +0
-0@@ -1595,6 +1596,7 @@ static void cf_checkvmx_set_descriptor_access_exiting(
vmx_update_secondary_exec_control(v); vmx_vmcs_exit(v);}
+#endif /*CONFIG_VM_EVENT*/static void
cf_checkvmx_init_hypercall_page(void *p){ @@ -2474,6 +2476,7 @@
static voidcf_checkvmx_handle_eoi(uint8_t vector, int isr)
printk_once(XENLOG_WARNING "EOI for %02x but SVI=%02x\n", vector,old_svi); }+#ifdef
CONFIG_VM_EVENT
static voidcf_checkvmx_enable_msr_interception(struct domain *d, uint32_t msr){ struct vcpu *v;xen/arch/x86/hvm/vmx/vmx.c +3
-0@@ -2481,6 +2484,7 @@ static void cf_check vmx_enable_msr_interception(struct domain *d, uint32_t msr) for_each_vcpu ( d, v ) vmx_set_msr_intercept(v, msr, VMX_MSR_W); } +#endif /* CONFIG_VM_EVENT */ #ifdef CONFIG_ALTP2M@@ -2932,7 +2936,9 @@ static struct hvm_function_table __initdata_cf_clobber vmx_function_table = { .nhvm_domain_relinquish_resources = nvmx_domain_relinquish_resources, .update_vlapic_mode = vmx_vlapic_msr_changed, .nhvm_hap_walk_L1_p2m = nvmx_hap_walk_L1_p2m, +#ifdef CONFIG_VM_EVENT .enable_msr_interception = vmx_enable_msr_interception, +#endif #ifdef CONFIG_ALTP2M .altp2m_vcpu_update_p2m = vmx_vcpu_update_eptp,.altp2m_vcpu_update_vmfunc_ve =
vmx_vcpu_update_vmfunc_ve, @@ -
3141,9 +3147,11 @@ const structhvm_function_table*__initstart_vmx(void)vmx_function_table.caps.singlestep = cpu_has_monitor_trap_flag;xen/arch/x86/hvm/vmx/vmx.c +2
-0+#ifdef CONFIG_VM_EVENT if ( cpu_has_vmx_dt_exiting ) vmx_function_table.set_descriptor_access_exiting = vmx_set_descriptor_access_exiting; +#endif /* * Do not enable EPT when (!cpu_has_vmx_pat), to prevent security hole @@ - 3214,8 +3222,10 @@ void
__initvmx_fill_funcs(void)if ( !cpu_has_xen_ibt ) return;xen/arch/x86/hvm/vmx/vmx.c +2
-0+#ifdef CONFIG_VM_EVENT vmx_function_table.set_descriptor_access_exiting = vmx_set_descriptor_access_exiting; +#endif vmx_function_table.update_eoi_exit_bitmap = vmx_update_eoi_exit_bitmap; vmx_function_table.process_isr = vmx_process_isr;xen/arch/x86/include/asm/hvm/hvm.h +4
-0@@ -192,7 +192,11 @@ struct hvm_function_table {void (*handle_cd)(struct vcpu *v,unsigned long value);void (*set_info_guest)(struct vcpu *v);void (*set_rdtsc_exiting)(struct vcpu *v,bool enable); + +#ifdef CONFIG_VM_EVENT void (*set_descriptor_access_exiting)(struct vcpu *v,bool enable); +void (*enable_msr_interception)(struct domain *d,uint32_t msr); +#endif /* Nested HVM */ int (*nhvm_vcpu_initialise)(struct vcpu *v); @@ -224,8 +228,6 @@ struct
hvm_function_table{
paddr_t*L1_gpa, unsigned int*page_order,uint8_t*p2m_acc, struct npfec npfec);xen/arch/x86/include/asm/hvm/hvm.h +0
-2-void (*enable_msr_interception)(struct domain *d,uint32_t msr); -#ifdef CONFIG_ALTP2M /* Alternate p2m */ void (*altp2m_vcpu_update_p2m)(struct vcpu *v); @@ -435,11 +437,18 @@static inline bool
using_svm(void)#define
hvm_long_mode_active(v)(!!((v)->arch.hvm.guest_efer &EFER_LMA))xen/arch/x86/include/asm/hvm/hvm.h +6
-0+#ifdef CONFIG_VM_EVENT static inline bool hvm_has_set_descriptor_access_exiting (void ) {return hvm_funcs.set_descriptor_access_exiting; } +static inline void hvm_enable_msr_interception (struct domain *d, +uint32_t msr) { +alternative_vcall (hvm_funcs.enable_msr_interception, d, msr); } +#endif /* CONFIG_VM_EVENT */ +static inline void hvm_domain_creation_finished (struct domain *d) { if ( hvm_funcs.domain_creation_finished ) @@ -681,11 +690,6 @@ static inlineint nhvm_hap_walk_L1_p2m(
v, L2_gpa, L1_gpa, page_order, p2m_acc, npfec); }xen/arch/x86/include/asm/hvm/hvm.h +0
-4-static inline void hvm_enable_msr_interception(struct domain *d, uint32_t msr) -{ -alternative_vcall (hvm_funcs.enable_msr_interception, d, msr); -} -static inline bool hvm_is_singlestep_supported (void ) {return hvm_funcs.caps.singlestep;xen/arch/x86/include/asm/monitor.h +2
-0@@ -71,6 +71,7 @@ int arch_monitor_domctl_op(struct domain *d, struct xen_domctl_monitor_op *mop)return rc; } +#ifdef CONFIG_VM_EVENT static inline uint32_t arch_monitor_get_capabilities (struct domain *d) {uint32_t capabilities =0 ;@@ -102,6 +103,7 @@ static inline uint32_t arch_monitor_get_capabilities(struct domain *d)return capabilities; } +#endif /* CONFIG_VM_EVENT */ int arch_monitor_domctl_event(struct domain *d,struct xen_domctl_monitor_op *mop); @@ -123,7 +125,14@@ static inline void
arch_monitor_cleanup_domain(struct domain *d){}#endif
xen/arch/x86/include/asm/monitor.h +6
-1+#ifdef CONFIG_VM_EVENT bool monitored_msr (const struct domain *d,u32 msr); +#else +static inline bool monitored_msr (const struct domain *d,u32 msr) { +return false; +} +#endif bool monitored_msr_onchangeonly (const struct domain *d,u32 msr);#endif /* __ASM_X86_MONITOR_H__ */ --2.34.1
Re: [PATCH v4 3/6] x86/monitor: wrap monitor_op under CONFIG_VM_EVENT
In reply to Penny ZhengQuoted 14 lines · Penny Zheng
Feature
monitor_opis based on vm event subsystem, so monitor.o shall be wrapped underCONFIG_VM_EVENT.
The following functions are only invoked by monitor-op, so they all shall be
wrapped withCONFIG_VM_EVENT(otherwise they will become unreachable and violate Misra rule 2.1 when VM_EVENT=n):
-hvm_enable_msr_interception
- hvm_function_table.enable_msr_interception
-hvm_has_set_descriptor_access_existing
- hvm_function_table.set_descriptor_access_existi
-arch_monitor_get_capabilities
Functionmonitored_msr()still needs a stub to pass compilation when VM_EVENT=n.
Quoted 3 lines
Signed-off-by Penny Zheng <[email protected]>Acked-by Jan Beulich <[email protected]>Reviewed-by Jason Andryuk <[email protected]>
PATCH v4 4/6 xen/p2m: move xenmem_access_to_p2m_access() to common p2m.c
In reply to Penny ZhengMemory access and ALTP2M are two seperate features, while both depending on helper xenmem_access_to_p2m_access(). So it betters lives in common p2m.c, other than mem_access.c which will be compiled out when VM_EVENT=n && ALTP2M=y. Guard xenmem_access_to_p2m_access() with VM_EVENT || ALTP2M, otherwise it will become unreachable when both VM_EVENT=n and ALTP2M=n, and hence violating Misra rule 2.1
We also need to move declaration from mem_access.h to p2m-common.h An extra blank line is inserted after each case-block to correct coding style at the same time.
---
v1 -> v3:
- Guard xenmem_access_to_p2m_access() with VM_EVENT || ALTP2M
- Move declaration from mem_access.h to p2m-common.h
- refine commit message
--- xen/arch/x86/mm/mem_access.c | 36 -------------------------------- xen/arch/x86/mm/p2m.c | 40 ++++++++++++++++++++++++++++++++++++ xen/include/xen/mem_access.h | 5 ----- xen/include/xen/p2m-common.h | 3 +++ 4 files changed, 43 insertions(+), 41 deletions(-)
xen/arch/x86/mm/mem_access.c +0 -36
@@ -298,42 +298,6 @@ static int set_mem_access(struct domain *d, struct p2m_domain *p2m,return rc; } -bool xenmem_access_to_p2m_access (const struct p2m_domain *p2m, -xenmem_access_t xaccess, -p2m_access_t *paccess) -{ -static const p2m_access_t memaccess[] = { -#define ACCESS(ac) [XENMEM_access_##ac] = p2m_access_##ac - ACCESS(n), - ACCESS(r), - ACCESS(w), - ACCESS(rw), - ACCESS(x), - ACCESS(rx), - ACCESS(wx), - ACCESS(rwx), - ACCESS(rx2rw), - ACCESS(n2rwx), - ACCESS(r_pw), -#undef ACCESS - }; - -switch ( xaccess ) - { - case 0 ... ARRAY_SIZE(memaccess) - 1: - xaccess =array_index_nospec (xaccess,ARRAY_SIZE (memaccess)); - *paccess = memaccess[xaccess]; -break ; -case XENMEM_access_default: - *paccess = p2m->default_access; -break ; -default : -return false; - } - -return true; -} -/* * Set access type for a region of gfns. * If gfn == INVALID_GFN, sets the default access type.
xen/arch/x86/mm/p2m.c +40 -0
@@ -2203,6 +2203,46 @@ void p2m_log_dirty_range(struct domain *d, unsigned long begin_pfn,guest_flush_tlb_mask (d, d->dirty_cpumask); } +#if defined(CONFIG_VM_EVENT ) || defined(CONFIG_ALTP2M ) +bool xenmem_access_to_p2m_access (const struct p2m_domain *p2m, +xenmem_access_t xaccess, +p2m_access_t *paccess) +{ +static const p2m_access_t memaccess[] = { +#define ACCESS(ac) [XENMEM_access_##ac] = p2m_access_##ac + ACCESS(n), + ACCESS(r), + ACCESS(w), + ACCESS(rw), + ACCESS(x), + ACCESS(rx), + ACCESS(wx), + ACCESS(rwx), + ACCESS(rx2rw), + ACCESS(n2rwx), + ACCESS(r_pw), +#undef ACCESS + }; + +switch ( xaccess ) + { + case 0 ... ARRAY_SIZE(memaccess) - 1: + xaccess =array_index_nospec (xaccess,ARRAY_SIZE (memaccess)); + *paccess = memaccess[xaccess]; +break ; + +case XENMEM_access_default: + *paccess = p2m->default_access; +break ; + +default : +return false; + } + +return true; +} +#endif /* VM_EVENT || ALTP2M */ +/* * Local variables: * mode: C
xen/include/xen/mem_access.h +0 -5
@@ -73,11 +73,6 @@ typedef enum {/* NOTE: Assumed to be only 4 bits right now on x86. */ } p2m_access_t; -struct p2m_domain ; -bool xenmem_access_to_p2m_access (const struct p2m_domain *p2m, -xenmem_access_t xaccess, -p2m_access_t *paccess); -/* * Set access type for a region of gfns. * If gfn == INVALID_GFN, sets the default access type.
xen/include/xen/p2m-common.h +3 -0
@@ -43,5 +43,8 @@ int __must_check check_get_page_from_gfn(struct domain *d, gfn_t gfn, bool readonly, p2m_type_t *p2mt_p, struct page_info **page_p); +bool xenmem_access_to_p2m_access (const struct p2m_domain *p2m, +xenmem_access_t xaccess, +p2m_access_t *paccess);#endif /* _XEN_P2M_COMMON_H */
Signature · 1 line
2.34.1
Re: [PATCH v4 4/6] xen/p2m: move xenmem_access_to_p2m_access() to common p2m.c
Quoted 10 lines · Penny Zheng
Memory access and ALTP2M are two seperate features, while both depending on helper
xenmem_access_to_p2m_access(). So it betters lives in commonp2m.c, other thanmem_access.cwhich will be compiled out when VM_EVENT=n && ALTP2M=y. Guardxenmem_access_to_p2m_access()withVM_EVENT|| ALTP2M, otherwise it will become unreachable when both VM_EVENT=n and ALTP2M=n, and hence violating Misra rule 2.1
We also need to move declaration frommem_access.htop2m-common.hAn extra blank line is inserted after each case-block to correct coding style at the same time.
Quoted 2 lines
Signed-off-by Penny Zheng <[email protected]>Acked-by Jan Beulich <[email protected]>
Tamas K Lengyel
Acked-byRe: [PATCH v4 4/6] xen/p2m: move xenmem_access_to_p2m_access() to common p2m.c
Quoted 14 lines · Jason Andryuk
Quoted 1 line · Penny Zheng
Memory access and ALTP2M are two seperate features, while both depending
on
Quoted 1 line
helper
xenmem_access_to_p2m_access(). So it betters lives in common
p2m.c,Quoted 1 line
other than
mem_access.cwhich will be compiled out when VM_EVENT=n &&ALTP2M=y.
Quoted 7 lines
Guard
xenmem_access_to_p2m_access()withVM_EVENT|| ALTP2M, otherwise it will become unreachable when both VM_EVENT=n and ALTP2M=n, and hence violating Misra rule 2.1
We also need to move declaration frommem_access.htop2m-common.hAn extra blank line is inserted after each case-block to correct coding style at the same time.
Quoted 5 lines
Quoted 2 lines
Signed-off-by Penny Zheng <[email protected]>Acked-by Jan Beulich <[email protected]>Reviewed-by Jason Andryuk <[email protected]>
Re: [PATCH v4 4/6] xen/p2m: move xenmem_access_to_p2m_access() to common p2m.c
In reply to Penny ZhengQuoted 70 lines · Penny Zheng
xen/arch/x86/mm/p2m.c +40
-0@@ -2203,6 +2203,46 @@ void p2m_log_dirty_range(struct domain *d, unsigned long begin_pfn,guest_flush_tlb_mask (d, d->dirty_cpumask); } +#if defined(CONFIG_VM_EVENT ) || defined(CONFIG_ALTP2M ) +bool xenmem_access_to_p2m_access (const struct p2m_domain *p2m, +xenmem_access_t xaccess, +p2m_access_t *paccess) +{ +static const p2m_access_t memaccess[] = { +#define ACCESS(ac) [XENMEM_access_##ac] = p2m_access_##ac + ACCESS(n), + ACCESS(r), + ACCESS(w), + ACCESS(rw), + ACCESS(x), + ACCESS(rx), + ACCESS(wx), + ACCESS(rwx), + ACCESS(rx2rw), + ACCESS(n2rwx), + ACCESS(r_pw), +#undef ACCESS + }; + +switch ( xaccess ) + { + case 0 ... ARRAY_SIZE(memaccess) - 1: + xaccess =array_index_nospec (xaccess,ARRAY_SIZE (memaccess)); + *paccess = memaccess[xaccess]; +break ; + +case XENMEM_access_default: + *paccess = p2m->default_access; +break ; + +default : +return false; + } + +return true; +} +#endif /* VM_EVENT || ALTP2M */ +/* * Local variables: * mode: C xen/include/xen/mem_access.h +0
-5@@ -73,11 +73,6 @@ typedef enum {/* NOTE: Assumed to be only 4 bits right now on x86. */ } p2m_access_t; -struct p2m_domain ; -bool xenmem_access_to_p2m_access (const struct p2m_domain *p2m, -xenmem_access_t xaccess, -p2m_access_t *paccess); -/* * Set access type for a region of gfns. * If gfn == INVALID_GFN, sets the default access type. xen/include/xen/p2m-common.h +0
-0
xen/include/xen/p2m-common.h int __must_check check_get_page_from_gfn(struct domain *d, gfn_t gfn, · line 48
Quoted 6 lines
xen/include/xen/p2m-common.h +3
-0@@ -43,5 +43,8 @@ int __must_check check_get_page_from_gfn(struct domain *d, gfn_t gfn, bool readonly, p2m_type_t *p2mt_p, struct page_info **page_p); +bool xenmem_access_to_p2m_access (const struct p2m_domain *p2m, +xenmem_access_t xaccess, +p2m_access_t *paccess);
CI says "no" on both PPC and RISC-V. I wouldn't be surprised of build issues on Arm or x86 either, seeing that p2m-common.h doesn't (and shouldn't) include xen/mem_access.h. It's arch/<arch>/include/asm/p2m.h which is responsible for the inclusion ahead of including p2m-common.h. Question though is: If this is an x86-only function, why was its decl put in xen/mem_access.h rather than x86'es asm/mem_access.h. I'll try that before giving up and handing this back to you, but may I stress again that you please properly test your changes? It is not the responsibility of the committer to deal with such fallout.
Jan
PATCH v4 5/6 xen/mem_access: wrap memory access when VM_EVENT=n
In reply to Penny ZhengFeature memory access is based on vm event subsystem, and it could be disabled in the future. So a few switch-blocks in do_altp2m_op() need vm_event_is_enabled() condition check to pass compilation when ALTP2M=y and VM_EVENT=n(, hence MEM_ACCESS=n), like HVMOP_altp2m_set_mem_access, etc. Function p2m_mem_access_check() still needs stub when VM_EVENT=n to pass compilation.
Although local variable "req_ptr" still remains NULL throughout its lifetime, with the change of NULL assignment, we will face runtime undefined error only when CONFIG_USBAN is on. So we strengthen the condition check via adding vm_event_is_enabled() for the special case.
---
v1 -> v3:
- a comment next to the excessive condition
- use vm_event_is_enabled() instead
- avoid heavy churn by using the inverted condition plus break
---
v3 - v4:
- refine comment
--- xen/arch/x86/hvm/hvm.c | 26 +++++++++++++++++++++++++- xen/arch/x86/include/asm/mem_access.h | 10 ++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/hvm.c +25 -1
@@ -52,6 +52,7 @@#include <asm/i387.h> #include <asm/mc146818rtc.h> #include <asm/mce.h> +#include <asm/mem_access.h> #include <asm/monitor.h> #include <asm/msr.h> #include <asm/mtrr.h>
@@ -2082,7 +2083,12 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned long gla,#endif } -if ( req_ptr ) +/* +* req_ptr being constant NULL when !CONFIG_VM_EVENT, CONFIG_UBSAN=y +* builds have been observed to still hit undefined-ness at runtime. +* Hence do a seemingly redundant vm_event_is_enabled() check here. +*/ +if ( req_ptr &&vm_event_is_enabled (curr) ) {if (monitor_traps (curr, sync, req_ptr) <0 ) rc =0 ;
@@ -4804,6 +4810,12 @@ static int do_altp2m_op(break ;case HVMOP_altp2m_set_mem_access: +if ( !vm_event_is_enabled (current) ) + { + rc = -EOPNOTSUPP ; +break ; + } +if ( a.u.mem_access.pad ) rc = -EINVAL ;else
@@ -4813,6 +4825,12 @@ static int do_altp2m_op(break ;case HVMOP_altp2m_set_mem_access_multi: +if ( !vm_event_is_enabled (current) ) + { + rc = -EOPNOTSUPP ; +break ; + } +if ( a.u.set_mem_access_multi.pad || a.u.set_mem_access_multi.opaque > a.u.set_mem_access_multi.nr ) {
@@ -4844,6 +4862,12 @@ static int do_altp2m_op(break ;case HVMOP_altp2m_get_mem_access: +if ( !vm_event_is_enabled (current) ) + { + rc = -EOPNOTSUPP ; +break ; + } +if ( a.u.mem_access.pad ) rc = -EINVAL ;else
xen/arch/x86/include/asm/mem_access.h +10 -0
@@ -14,6 +14,7 @@#ifndef __ASM_X86_MEM_ACCESS_H__#define __ASM_X86_MEM_ACCESS_H__ +#ifdef CONFIG_VM_EVENT /* * Setup vm_event request based on the access (gla is -1ull if not available). * Handles the rw2rx conversion. Boolean return value indicates if event type
@@ -25,6 +26,15 @@bool p2m_mem_access_check (paddr_t gpa,unsigned long gla,struct npfec npfec,struct vm_event_st **req_ptr); +#else +static inline bool p2m_mem_access_check (paddr_t gpa,unsigned long gla, +struct npfec npfec, +struct vm_event_st **req_ptr) +{ + *req_ptr =NULL ; +return false; +} +#endif /* CONFIG_VM_EVENT */ /* Check for emulation and mark vcpu for skipping one instruction * upon rescheduling if required. */
Signature · 1 line
2.34.1
Re: [PATCH v4 5/6] xen/mem_access: wrap memory access when VM_EVENT=n
Quoted 11 lines · Penny Zheng
Feature memory access is based on vm event subsystem, and it could be disabled in the future. So a few switch-blocks in
do_altp2m_op()needvm_event_is_enabled()condition check to pass compilation when ALTP2M=y and VM_EVENT=n(, hence MEM_ACCESS=n), likeHVMOP_altp2m_set_mem_access, etc. Functionp2m_mem_access_check()still needs stub when VM_EVENT=n to pass compilation.
Although local variable "req_ptr" still remains NULL throughout its lifetime, with the change of NULL assignment, we will face runtime undefined error only whenCONFIG_USBANis on. So we strengthen the condition check via addingvm_event_is_enabled()for the special case.
Quoted 2 lines
Signed-off-by Penny Zheng <[email protected]>Acked-by Jan Beulich <[email protected]>
Tamas K Lengyel
Acked-byRe: [PATCH v4 5/6] xen/mem_access: wrap memory access when VM_EVENT=n
Quoted 12 lines · Jason Andryuk
Quoted 1 line · Penny Zheng
Feature memory access is based on vm event subsystem, and it could be
disabled
Quoted 2 lines
in the future. So a few switch-blocks in
do_altp2m_op()needvm_event_is_enabled()condition check to pass compilation when ALTP2M=yand
Quoted 4 lines
VM_EVENT=n(, hence MEM_ACCESS=n), like
HVMOP_altp2m_set_mem_access, etc. Functionp2m_mem_access_check()still needs stub when VM_EVENT=n to pass compilation.
Although local variable "req_ptr" still remains NULL throughout itslifetime,
Quoted 1 line
with the change of NULL assignment, we will face runtime undefined error
Quoted 9 lines
only
Quoted 5 lines
when
CONFIG_USBANis on. So we strengthen the condition check via addingvm_event_is_enabled()for the special case.Signed-off-by Penny Zheng <[email protected]>Acked-by Jan Beulich <[email protected]>Reviewed-by Jason Andryuk <[email protected]>
RE: [PATCH v4 5/6] xen/mem_access: wrap memory access when VM_EVENT=n
In reply to Penny Zheng[Public]
Hi, Tamas
May I ask a review on this commit?
Many thanks,
Penny Zheng
Quoted 134 lines
-----Original Message-----
From: Penny, Zheng <[email protected]>
Sent: Thursday, January 15, 2026 5:29 PM
To: [email protected]; Andryuk, Jason <[email protected]>
Cc: Huang, Ray <[email protected]>; Penny, Zheng <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Tamas K Lengyel <[email protected]>; Alexandru Isaila <[email protected]>; Petre Pircalabu <[email protected]>
Subject: [PATCH v4 5/6] xen/mem_access: wrap memory access when VM_EVENT=nFeature memory access is based on vm event subsystem, and it could be disabled in the future. So a few switch-blocks in
do_altp2m_op()needvm_event_is_enabled()condition check to pass compilation when ALTP2M=y and VM_EVENT=n(, hence MEM_ACCESS=n), likeHVMOP_altp2m_set_mem_access, etc.
Functionp2m_mem_access_check()still needs stub when VM_EVENT=n to pass compilation.
Although local variable "req_ptr" still remains NULL throughout its lifetime, with the change of NULL assignment, we will face runtime undefined error only whenCONFIG_USBANis on. So we strengthen the condition check via addingvm_event_is_enabled()for the special case.Signed-off-by Penny Zheng <[email protected]>Acked-by Jan Beulich <[email protected]>---
v1 -> v3:
- a comment next to the excessive condition
- usevm_event_is_enabled()instead
- avoid heavy churn by using the inverted condition plus break
---
v3 - v4:
- refine comment--- xen/arch/x86/hvm/hvm.c | 26 +++++++++++++++++++++++++- xen/arch/x86/include/asm/mem_access.h | 10 ++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-)xen/arch/x86/hvm/hvm.c index renamed from xen/arch/x86/hvm/hvm.c +0
-0
07e54890d9..b34cd29629100644xen/arch/x86/hvm/hvm.c +1
-0@@ -52,6 +52,7 @@#include <asm/i387.h> #include <asm/mc146818rtc.h> #include <asm/mce.h> +#include <asm/mem_access.h> #include <asm/monitor.h> #include <asm/msr.h> #include <asm/mtrr.h> @@ -2082,7 +2083,12 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsignedlong gla, #endif
}xen/arch/x86/hvm/hvm.c +2
-1-if ( req_ptr ) +/* +* req_ptr being constant NULL when !CONFIG_VM_EVENT,
CONFIG_UBSAN=yxen/arch/x86/hvm/hvm.c +22
-0+* builds have been observed to still hit undefined-ness at runtime. +* Hence do a seemingly redundant vm_event_is_enabled() check here. +*/ +if ( req_ptr &&vm_event_is_enabled (curr) ) {if (monitor_traps (curr, sync, req_ptr) <0 ) rc =0 ;@@ -4804,6 +4810,12 @@ static int do_altp2m_op(break ;case HVMOP_altp2m_set_mem_access: +if ( !vm_event_is_enabled (current) ) + { + rc = -EOPNOTSUPP ; +break ; + } +if ( a.u.mem_access.pad ) rc = -EINVAL ;else @@ -4813,6 +4825,12 @@ static int do_altp2m_op(break ;case HVMOP_altp2m_set_mem_access_multi: +if ( !vm_event_is_enabled (current) ) + { + rc = -EOPNOTSUPP ; +break ; + } +if ( a.u.set_mem_access_multi.pad || a.u.set_mem_access_multi.opaque > a.u.set_mem_access_multi.nr ) {@@ -4844,6 +4862,12 @@ static int do_altp2m_op(break ;case HVMOP_altp2m_get_mem_access: +if ( !vm_event_is_enabled (current) ) + { + rc = -EOPNOTSUPP ; +break ; + } +if ( a.u.mem_access.pad ) rc = -EINVAL ;else xen/arch/x86/include/asm/mem_access.h +1
-0@@ -14,6 +14,7 @@#ifndef __ASM_X86_MEM_ACCESS_H__#define __ASM_X86_MEM_ACCESS_H__ +#ifdef CONFIG_VM_EVENT /* * Setup vm_event request based on the access (gla is -1ull if not available). * Handles the rw2rx conversion. Boolean return value indicates if event type @@ - 25,6 +26,15 @@ bool p2m_mem_access_check(paddr_t gpa, unsigned long gla,
struct npfec npfec,
structvm_event_st**req_ptr);xen/arch/x86/include/asm/mem_access.h +8
-1+#else +static inline bool p2m_mem_access_check (paddr_t gpa,unsigned long gla, +struct npfec npfec, +struct vm_event_st **req_ptr) { + *req_ptr =NULL ; +return false; +} +#endif /* CONFIG_VM_EVENT */ /* Check for emulation and mark vcpu for skipping one instruction * upon rescheduling if required. */ --2.34.1
[4.22 BLOCKER] Re: [PATCH v4 5/6] xen/mem_access: wrap memory access when VM_EVENT=n
In reply to Penny ZhengQuoted 33 lines · Penny Zheng
xen/arch/x86/hvm/hvm.c +12
-0@@ -4804,6 +4810,12 @@ static int do_altp2m_op(break ;case HVMOP_altp2m_set_mem_access: +if ( !vm_event_is_enabled (current) ) + { + rc = -EOPNOTSUPP ; +break ; + } +if ( a.u.mem_access.pad ) rc = -EINVAL ;else @@ -4813,6 +4825,12 @@ static int do_altp2m_op(break ;case HVMOP_altp2m_set_mem_access_multi: +if ( !vm_event_is_enabled (current) ) + { + rc = -EOPNOTSUPP ; +break ; + } +if ( a.u.set_mem_access_multi.pad || a.u.set_mem_access_multi.opaque > a.u.set_mem_access_multi.nr ) {@@ -4844,6 +4862,12 @@ static int do_altp2m_op(break ;
xen/arch/x86/hvm/hvm.c static int do_altp2m_op( · line 4873
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +6
-0case HVMOP_altp2m_get_mem_access: +if ( !vm_event_is_enabled (current) ) + { + rc = -EOPNOTSUPP ; +break ; + } +if ( a.u.mem_access.pad ) rc = -EINVAL ;else
(Forwarding a report from Hady Azzam, CC'd).
This breaks introspection generally. It is (mostly) erroneous to check current like this; it's checking dom0's vm_event-ness, not the target of the altp2m op.
P2M changes are also inherently domain-scope, not vcpu scope, further calling into question the use of a vcpu-oriented check.
As far as I can tell, the misuse of vm_event_is_enabled() is just to wrap the IS_ENABLED(CONFIG_VM_EVENT) condition.
~Andrew
PATCH v4 6/6 xen/vm_event: consolidate CONFIG_VM_EVENT
In reply to Penny ZhengFile hvm/vm_event.c and x86/vm_event.c are the extend to vm_event handling routines, and its compilation shall be guarded by CONFIG_VM_EVENT too.
Although CONFIG_VM_EVENT is right now forcibly enabled on x86 via MEM_ACCESS_ALWAYS_ON, we could disable it through disabling CONFIG_MGMT_HYPERCALLS later. So we remove MEM_ACCESS_ALWAYS_ON and make VM_EVENT=y on default only on x86 to retain the same.
The following functions are developed on the basis of vm event framework, or only invoked by vm_event.c, so they all shall be wrapped with CONFIG_VM_EVENT (otherwise they will become unreachable and
violate Misra rule 2.1 when VM_EVENT=n):
- hvm_toggle_singlestep
- hvm_fast_singlestep
- hvm_emulate_one_vm_event
- hvmemul_write{,cmpxchg,rep_ins,rep_outs,rep_movs,rep_stos,read_io,write_io}_discard
And Function vm_event_check_ring() needs stub to pass compilation when VM_EVENT=n.
---
As the last commit, plz be commited either in the last, or shall be commited together with prereq commit 8d708e98ad, 8b4147009f, dbfccb5918, ae931f63a0, 37ec0e2b75.
--- xen/arch/x86/Makefile | 2 +- xen/arch/x86/hvm/Kconfig | 1 - xen/arch/x86/hvm/Makefile | 2 +- xen/arch/x86/hvm/emulate.c | 58 ++++++++++++++++++++------------------ xen/arch/x86/hvm/hvm.c | 2 ++ xen/common/Kconfig | 7 ++--- xen/include/xen/vm_event.h | 7 +++++ 7 files changed, 44 insertions(+), 35 deletions(-)
xen/arch/x86/Makefile +1 -1
@@ -69,7 +69,7 @@ obj-$(CONFIG_INTEL) += tsx.o obj-y += x86_emulate.o obj-$(CONFIG_TBOOT) += tboot.o obj-y += hpet.o -obj-y += vm_event.o +obj-$(CONFIG_VM_EVENT) += vm_event.o obj-y += xstate.o ifneq ($(CONFIG_PV_SHIM_EXCLUSIVE),y)
xen/arch/x86/hvm/Kconfig +0 -1
@@ -4,7 +4,6 @@ menuconfig HVM default !PV_SHIM select COMPAT select IOREQ_SERVER - select MEM_ACCESS_ALWAYS_ON help Interfaces to support HVM domains. HVM domains require hardware virtualisation extensions (e.g. Intel VT-x, AMD SVM), but can boot
xen/arch/x86/hvm/Makefile +1 -1
@@ -26,7 +26,7 @@ obj-y += save.o obj-y += stdvga.o obj-y += vioapic.o obj-y += vlapic.o -obj-y += vm_event.o +obj-$(CONFIG_VM_EVENT) += vm_event.o obj-y += vmsi.o obj-y += vpic.o obj-y += vpt.o
xen/arch/x86/hvm/emulate.c +31 -27
88 lines not on this page · raw message
xen/arch/x86/hvm/hvm.c +2 -0
@@ -5250,6 +5250,7 @@ int hvm_debug_op(struct vcpu *v, int32_t op)return rc; } +#ifdef CONFIG_VM_EVENT void hvm_toggle_singlestep (struct vcpu *v) {ASSERT (atomic_read (&v->pause_count));
@@ -5276,6 +5277,7 @@ void hvm_fast_singlestep(struct vcpu *v, uint16_t p2midx) v->arch.hvm.fast_single_step.p2midx = p2midx; }#endif +#endif /* CONFIG_VM_EVENT */ /* * Segment caches in VMCB/VMCS are inconsistent about which bits are checked,
xen/common/Kconfig +2 -5
@@ -173,13 +173,10 @@ config HAS_VMAP config LIBFDT bool -config MEM_ACCESS_ALWAYS_ON - bool - config VM_EVENT - def_bool MEM_ACCESS_ALWAYS_ON - prompt "Memory Access and VM events" if !MEM_ACCESS_ALWAYS_ON + bool "Memory Access and VM events" depends on HVM + default X86 help Framework to configure memory access types for guests and receive
xen/include/xen/vm_event.h +7 -0
@@ -51,7 +51,14 @@ struct vm_event_domain };/* Returns whether a ring has been set up */ +#ifdef CONFIG_VM_EVENT bool vm_event_check_ring (struct vm_event_domain *ved); +#else +static inline bool vm_event_check_ring (struct vm_event_domain *ved) +{ +return false; +} +#endif /* CONFIG_VM_EVENT */ /* Returns 0 on success, -ENOSYS if there is no ring, -EBUSY if there is no * available space and the caller is a foreign domain. If the guest itself
Signature · 1 line
2.34.1
Re: [PATCH v4 6/6] xen/vm_event: consolidate CONFIG_VM_EVENT
Quoted 19 lines · Penny Zheng
File
hvm/vm_event.candx86/vm_event.care the extend tovm_eventhandling routines, and its compilation shall be guarded byCONFIG_VM_EVENTtoo.Although
CONFIG_VM_EVENTis right now forcibly enabled on x86 viaMEM_ACCESS_ALWAYS_ON, we could disable it through disablingCONFIG_MGMT_HYPERCALLSlater. So we removeMEM_ACCESS_ALWAYS_ONand make VM_EVENT=y on default only on x86 to retain the same.The following functions are developed on the basis of vm event framework, or only invoked by
vm_event.c, so they all shall be wrapped withCONFIG_VM_EVENT(otherwise they will become unreachable and
violate Misra rule 2.1 when VM_EVENT=n):
-hvm_toggle_singlestep
-hvm_fast_singlestep
-hvm_emulate_one_vm_event
- hvmemul_write{,cmpxchg,rep_ins,rep_outs,rep_movs,rep_stos,read_io,write_io}_discard
And Functionvm_event_check_ring()needs stub to pass compilation when VM_EVENT=n.
Quoted 7 lines
Signed-off-by Penny Zheng <[email protected]>Acked-by Jan Beulich <[email protected]>Reviewed-by Jason Andryuk <[email protected]>---
As the last commit, plz be commited either in the last, or shall be commited together with prereq commit8d708e98ad,8b4147009f,dbfccb5918,ae931f63a0,37ec0e2b75.
What do these hashes refer to? Also (assuming these might be the hashes of the commits in your private tree), as I'm pretty sure I said before, committing a series in-order is the default thing to happen. It's patches that are independent of earlier ones which may want to call out that fact, for them to possibly go in early.
Jan
Re: [PATCH v4 6/6] xen/vm_event: consolidate CONFIG_VM_EVENT
In reply to Penny ZhengQuoted 17 lines · Penny Zheng
File
hvm/vm_event.candx86/vm_event.care the extend tovm_eventhandling routines, and its compilation shall be guarded byCONFIG_VM_EVENTtoo.Although
CONFIG_VM_EVENTis right now forcibly enabled on x86 viaMEM_ACCESS_ALWAYS_ON, we could disable it through disablingCONFIG_MGMT_HYPERCALLSlater. So we removeMEM_ACCESS_ALWAYS_ONand make VM_EVENT=y on default only on x86 to retain the same.The following functions are developed on the basis of vm event framework, or
only invoked byvm_event.c, so they all shall be wrapped withCONFIG_VM_EVENT
(otherwise they will become unreachable and
violate Misra rule 2.1 when VM_EVENT=n):
-hvm_toggle_singlestep
-hvm_fast_singlestep
-hvm_emulate_one_vm_event
Quoted 9 lines
-hvmemul_write{,cmpxchg,rep_ins,rep_outs,rep_movs,rep_stos,read_io,write_io}_discard And Function
vm_event_check_ring()needs stub to pass compilation when VM_EVENT=n.Signed-off-by Penny Zheng <[email protected]>Acked-by Jan Beulich <[email protected]>Reviewed-by Jason Andryuk <[email protected]>
RE: [PATCH v4 6/6] xen/vm_event: consolidate CONFIG_VM_EVENT
In reply to Penny Zheng[Public]
Hi, Tamas,
May I ask a review on this commit?
Many thanks
Penny Zheng
Quoted 242 lines
-----Original Message-----
From: Penny, Zheng <[email protected]>
Sent: Thursday, January 15, 2026 5:29 PM
To: [email protected]; Andryuk, Jason <[email protected]>
Cc: Huang, Ray <[email protected]>; Penny, Zheng <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Anthony PERARD <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Tamas K Lengyel <[email protected]>; Alexandru Isaila <[email protected]>; Petre Pircalabu <[email protected]>
Subject: [PATCH v4 6/6] xen/vm_event: consolidateCONFIG_VM_EVENTFile
hvm/vm_event.candx86/vm_event.care the extend tovm_eventhandling routines, and its compilation shall be guarded byCONFIG_VM_EVENTtoo.Although
CONFIG_VM_EVENTis right now forcibly enabled on x86 viaMEM_ACCESS_ALWAYS_ON, we could disable it through disablingCONFIG_MGMT_HYPERCALLSlater. So we removeMEM_ACCESS_ALWAYS_ONand make VM_EVENT=y on default only on x86 to retain the same.The following functions are developed on the basis of vm event framework, or only invoked by
vm_event.c, so they all shall be wrapped withCONFIG_VM_EVENT(otherwise they will become unreachable and violate Misra rule 2.1 when VM_EVENT=n):
-hvm_toggle_singlestep
-hvm_fast_singlestep
-hvm_emulate_one_vm_event-hvmemul_write{,cmpxchg,rep_ins,rep_outs,rep_movs,rep_stos,read_io,write_io}_dis card
And Functionvm_event_check_ring()needs stub to pass compilation when VM_EVENT=n.Signed-off-by Penny Zheng <[email protected]>Acked-by Jan Beulich <[email protected]>Reviewed-by Jason Andryuk <[email protected]>---
As the last commit, plz be commited either in the last, or shall be commited together with prereq commit8d708e98ad,8b4147009f,dbfccb5918,ae931f63a0,37ec0e2b75.--- xen/arch/x86/Makefile | 2 +- xen/arch/x86/hvm/Kconfig | 1 - xen/arch/x86/hvm/Makefile | 2 +- xen/arch/x86/hvm/emulate.c | 58 ++++++++++++++++++++------------------ xen/arch/x86/hvm/hvm.c | 2 ++ xen/common/Kconfig | 7 ++--- xen/include/xen/vm_event.h | 7 +++++ 7 files changed, 44 insertions(+), 35 deletions(-)xen/arch/x86/Makefile index renamed from xen/arch/x86/Makefile +0
-0
d8b41cec16..5bf3578983100644xen/arch/x86/Makefile +1
-1@@ -69,7 +69,7 @@ obj-$(CONFIG_INTEL) += tsx.o obj-y += x86_emulate.o obj-$(CONFIG_TBOOT) += tboot.o obj-y += hpet.o -obj-y += vm_event.o +obj-$(CONFIG_VM_EVENT) += vm_event.o obj-y += xstate.o ifneq ($(CONFIG_PV_SHIM_EXCLUSIVE),y)xen/arch/x86/hvm/Kconfig index renamed from xen/arch/x86/hvm/Kconfig +0
-0
c1a131d185..25eb3e374f100644xen/arch/x86/hvm/Kconfig +0
-1@@ -4,7 +4,6 @@ menuconfig HVM default !PV_SHIM select COMPAT select IOREQ_SERVER - select MEM_ACCESS_ALWAYS_ON help Interfaces to support HVM domains. HVM domains require hardware virtualisation extensions (e.g. Intel VT-x, AMD SVM), but can boot diff --gita/xen/arch/x86/hvm/Makefile b/xen/arch/x86/hvm/Makefile index
ee4b45a4ee..f34fb03934100644xen/arch/x86/hvm/Makefile +1
-1@@ -26,7 +26,7 @@ obj-y += save.o obj-y += stdvga.o obj-y += vioapic.o obj-y += vlapic.o -obj-y += vm_event.o +obj-$(CONFIG_VM_EVENT) += vm_event.o obj-y += vmsi.o obj-y += vpic.o obj-y += vpt.oxen/arch/x86/hvm/emulate.c index renamed from xen/arch/x86/hvm/emulate.c +0
-0
fe75b0516d..d56ef02baf100644xen/arch/x86/hvm/emulate.c +2
-27@@ -1615,6 +1615,7 @@ static int cf_check hvmemul_blk(return rc; } +#ifdef CONFIG_VM_EVENT static int cf_check hvmemul_write_discard( enum x86_segment seg, unsigned long offset,@@ -1717,6 +1718,7 @@ static int cf_check hvmemul_cache_op_discard( {return X86EMUL_OKAY ; } +#endif /* CONFIG_VM_EVENT */ static int cf_check hvmemul_cmpxchg( enum x86_segment seg,@@ -2750,33 +2752,6 @@ static const struct x86_emulate_ops hvm_emulate_ops = { .vmfunc = hvmemul_vmfunc, }; -static const struct x86_emulate_ops hvm_emulate_ops_no_write = { - .read = hvmemul_read, - .insn_fetch = hvmemul_insn_fetch, - .write = hvmemul_write_discard, - .cmpxchg = hvmemul_cmpxchg_discard, - .rep_ins = hvmemul_rep_ins_discard, - .rep_outs = hvmemul_rep_outs_discard, - .rep_movs = hvmemul_rep_movs_discard, - .rep_stos = hvmemul_rep_stos_discard, - .read_segment = hvmemul_read_segment, - .write_segment = hvmemul_write_segment, - .read_io = hvmemul_read_io_discard, - .write_io = hvmemul_write_io_discard, - .read_cr = hvmemul_read_cr, - .write_cr = hvmemul_write_cr, - .read_xcr = hvmemul_read_xcr, - .write_xcr = hvmemul_write_xcr, - .read_msr = hvmemul_read_msr, - .write_msr = hvmemul_write_msr_discard, - .cache_op = hvmemul_cache_op_discard, - .tlb_op = hvmemul_tlb_op, - .cpuid = x86emul_cpuid, - .get_fpu = hvmemul_get_fpu, - .put_fpu = hvmemul_put_fpu, - .vmfunc = hvmemul_vmfunc, -}; -/* * Note that passing VIO_no_completion into this function serves as kind * of (but not fully) an "auto select completion" indicator. When there's @@ -
2887,6 +2862,34 @@ int hvm_emulate_one(return _hvm_emulate_one(hvmemul_ctxt, &hvm_emulate_ops, completion); }xen/arch/x86/hvm/emulate.c +29
-0+#ifdef CONFIG_VM_EVENT +static const struct x86_emulate_ops hvm_emulate_ops_no_write = { + .read = hvmemul_read, + .insn_fetch = hvmemul_insn_fetch, + .write = hvmemul_write_discard, + .cmpxchg = hvmemul_cmpxchg_discard, + .rep_ins = hvmemul_rep_ins_discard, + .rep_outs = hvmemul_rep_outs_discard, + .rep_movs = hvmemul_rep_movs_discard, + .rep_stos = hvmemul_rep_stos_discard, + .read_segment = hvmemul_read_segment, + .write_segment = hvmemul_write_segment, + .read_io = hvmemul_read_io_discard, + .write_io = hvmemul_write_io_discard, + .read_cr = hvmemul_read_cr, + .write_cr = hvmemul_write_cr, + .read_xcr = hvmemul_read_xcr, + .write_xcr = hvmemul_write_xcr, + .read_msr = hvmemul_read_msr, + .write_msr = hvmemul_write_msr_discard, + .cache_op = hvmemul_cache_op_discard, + .tlb_op = hvmemul_tlb_op, + .cpuid = x86emul_cpuid, + .get_fpu = hvmemul_get_fpu, + .put_fpu = hvmemul_put_fpu, + .vmfunc = hvmemul_vmfunc, +}; +void hvm_emulate_one_vm_event (enum emul_kind kind,unsigned int trapnr,unsigned int errcode) {@@ -2949,6 +2952,7 @@ void hvm_emulate_one_vm_event(enum emul_kind kind, unsigned int trapnr,hvm_emulate_writeback (&ctx); } +#endif /* CONFIG_VM_EVENT */ void hvm_emulate_init_once(struct hvm_emulate_ctxt *hvmemul_ctxt, diff --git a/xen/arch/x86/hvm/hvm.c
b/xen/arch/x86/hvm/hvm.cindexb34cd29629..4d37a93c57100644xen/arch/x86/hvm/hvm.c +2
-0@@ -5250,6 +5250,7 @@ int hvm_debug_op(struct vcpu *v, int32_t op)return rc; } +#ifdef CONFIG_VM_EVENT void hvm_toggle_singlestep (struct vcpu *v) {ASSERT (atomic_read (&v->pause_count));@@ -5276,6 +5277,7 @@ void hvm_fast_singlestep(struct vcpu *v, uint16_t p2midx) v->arch.hvm.fast_single_step.p2midx = p2midx; } #endif +#endif /* CONFIG_VM_EVENT */ /* * Segment caches in VMCB/VMCS are inconsistent about which bits are checked, xen/common/Kconfig index renamed from xen/common/Kconfig +0
-0
38320b248a..d7e79e752a100644xen/common/Kconfig +2
-5@@ -173,13 +173,10 @@ config HAS_VMAP config LIBFDT bool -config MEM_ACCESS_ALWAYS_ON - bool - config VM_EVENT - def_bool MEM_ACCESS_ALWAYS_ON - prompt "Memory Access and VM events" if !MEM_ACCESS_ALWAYS_ON + bool "Memory Access and VM events" depends on HVM + default X86 help Framework to configure memory access types for guests and receive diff --git
a/xen/include/xen/vm_event.hb/xen/include/xen/vm_event.hindex27d0c74216..1b76ce632e100644xen/include/xen/vm_event.h +6
-1@@ -51,7 +51,14 @@ struct vm_event_domain };/* Returns whether a ring has been set up */ +#ifdef CONFIG_VM_EVENT bool vm_event_check_ring (struct vm_event_domain *ved); +#else +static inline bool vm_event_check_ring (struct vm_event_domain *ved) { +return false; +} +#endif /* CONFIG_VM_EVENT */ /* Returns 0 on success, -ENOSYS if there is no ring, -EBUSY if there is no * available space and the caller is a foreign domain. If the guest itself -- 2.34.1
Quoted 11 lines · Penny Zheng
This patch serie originates from "Disable domctl-op via
CONFIG_MGMT_HYPERCALLS" [1], and focuses on consolidating vm event subsystem (i.e.VM_EVENT), and its derived features, like memory paging, etc.[1] https://www.mail-archive.com/[email protected]/msg200843.html
---
Happy 2026!
Sorry for the late response to this patch serie and the domctl one. v4 is just doing a rebase on the latest staging, and one comment fix. I still need 2 acks for commit "xen/p2m: movexenmem_access_to_p2m_access()to commonp2m.c" and "xen/mem_access: wrap memory access when VM_EVENT=n".
Is this true? I'm under the impression that strictly speaking every one of the patches needs Tamas'es ack.
Jan
A message that is not in the archive (sent off-list or not yet received): [email protected]
Tamas K Lengyel
Acked-byRe: [PATCH v4 2/6] x86/vm_event: introduce vm_event_is_enabled()
Quoted 10 lines · Penny Zheng
Function
vm_event_is_enabled()is introduced to check if vm event is enabled,
and also make the checking conditional uponCONFIG_VM_EVENT, which could help
DCE a lot unreachable calls/codes, such ashvm_monitor_io(), etc, when having VM_EVENT=n.Signed-off-by Penny Zheng <[email protected]>Acked-by Jan Beulich <[email protected]>Reviewed-by Jason Andryuk <[email protected]>