hvm/svm: Enable vm events for SVM
v4 cover hvm/svm: Enable vm events for SVM
Hi all,
This series provides a skeleton for enabling vm_events on SVM. For the first step, the MSR, CR, Breakpoint and GuestRequest have been tested and added to the capabilities list.
Cheers,
Alexandru Isaila
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v4 1/3 hvm/svm: Enable Breakpoint events
This commit implements the breakpoint events for svm.
At the moment, the Breakpoint vmexit is not forwarded to the monitor layer.
This patch adds the hvm_monitor_debug call to the VMEXIT_EXCEPTION_BP. Also, the Software Breakpoint cap is moved from the Intel arch to the common part of the code.
---
Changes since V3:
-Rebase to the latest staging
--- xen/arch/x86/hvm/monitor.c | 5 +++++ xen/arch/x86/hvm/svm/svm.c | 50 +++++++++++++++++++++++++++++++++++-------- xen/arch/x86/hvm/vmx/vmx.c | 5 ----- xen/include/asm-x86/monitor.h | 4 ++-- 4 files changed, 48 insertions(+), 16 deletions(-)
xen/arch/x86/hvm/monitor.c +5 -0
@@ -133,6 +133,11 @@ static inline unsigned long gfn_of_rip(unsigned long rip)int hvm_monitor_debug (unsigned long rip,enum hvm_monitor_debug_type type,unsigned long trap_type,unsigned long insn_length) { +/* +* rc < 0 error in monitor/vm_event, crash +* !rc continue normally +* rc > 0 paused waiting for response, work here is done +*/ struct vcpu *curr = current;struct arch_domain *ad = &curr->domain->arch;vm_event_request_t req = {};
xen/arch/x86/hvm/svm/svm.c +41 -9
74 lines not on this page · raw message
xen/arch/x86/hvm/vmx/vmx.c +0 -5
@@ -3703,11 +3703,6 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs)HVM_MONITOR_DEBUG_EXCEPTION , trap_type, insn_len); -/* -* rc < 0 error in monitor/vm_event, crash -* !rc continue normally -* rc > 0 paused waiting for response, work here is done -*/ if ( rc <0 ) goto exit_and_crash;if ( !rc )
xen/include/asm-x86/monitor.h +2 -2
@@ -77,13 +77,13 @@ static inline uint32_t arch_monitor_get_capabilities(struct domain *d)if ( !is_hvm_domain (d) )return capabilities; - capabilities = (1U <<XEN_DOMCTL_MONITOR_EVENT_GUEST_REQUEST ); + capabilities = ((1U <<XEN_DOMCTL_MONITOR_EVENT_GUEST_REQUEST ) | + (1U <<XEN_DOMCTL_MONITOR_EVENT_SOFTWARE_BREAKPOINT ));if ( cpu_has_vmx ) { capabilities |= ((1U << XEN_DOMCTL_MONITOR_EVENT_WRITE_CTRLREG) | (1U << XEN_DOMCTL_MONITOR_EVENT_MOV_TO_MSR) | - (1U << XEN_DOMCTL_MONITOR_EVENT_SOFTWARE_BREAKPOINT) | (1U << XEN_DOMCTL_MONITOR_EVENT_DEBUG_EXCEPTION) | (1U << XEN_DOMCTL_MONITOR_EVENT_CPUID) | (1U << XEN_DOMCTL_MONITOR_EVENT_INTERRUPT) |
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v4 2/3 hvm/svm: Enable MSR events
In reply to Alexandru IsailaAt this moment there is no function to enable msr interception on svm.
This patch implements this function and moves the mov to msr monitor event
form the Intel arch side to the common capabilities.
---
Changes since V3:
-Rebase to the latest staging
--- xen/arch/x86/hvm/svm/svm.c | 9 +++++++++ xen/include/asm-x86/monitor.h | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/svm/svm.c +9 -0
@@ -163,6 +163,14 @@ void svm_intercept_msr(struct vcpu *v, uint32_t msr, int flags)__clear_bit (msr *2 +1 , msr_bit); } +static void svm_enable_msr_interception (struct domain *d,uint32_t msr) +{ +struct vcpu *v; + + for_each_vcpu ( d, v ) +svm_intercept_msr (v, msr,MSR_INTERCEPT_WRITE ); +} +static void svm_save_dr (struct vcpu *v) {struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
@@ -2457,6 +2465,7 @@ static struct hvm_function_table __initdata svm_function_table = { .fpu_dirty_intercept = svm_fpu_dirty_intercept, .msr_read_intercept = svm_msr_read_intercept, .msr_write_intercept = svm_msr_write_intercept, + .enable_msr_interception = svm_enable_msr_interception, .set_rdtsc_exiting = svm_set_rdtsc_exiting, .set_descriptor_access_exiting = svm_set_descriptor_access_exiting, .get_insn_bytes = svm_get_insn_bytes,
xen/include/asm-x86/monitor.h +2 -2
@@ -78,12 +78,12 @@ static inline uint32_t arch_monitor_get_capabilities(struct domain *d)return capabilities; capabilities = ((1U <<XEN_DOMCTL_MONITOR_EVENT_GUEST_REQUEST ) | - (1U <<XEN_DOMCTL_MONITOR_EVENT_SOFTWARE_BREAKPOINT )); + (1U <<XEN_DOMCTL_MONITOR_EVENT_SOFTWARE_BREAKPOINT ) | + (1U <<XEN_DOMCTL_MONITOR_EVENT_MOV_TO_MSR ));if ( cpu_has_vmx ) { capabilities |= ((1U << XEN_DOMCTL_MONITOR_EVENT_WRITE_CTRLREG) | - (1U << XEN_DOMCTL_MONITOR_EVENT_MOV_TO_MSR) | (1U << XEN_DOMCTL_MONITOR_EVENT_DEBUG_EXCEPTION) | (1U << XEN_DOMCTL_MONITOR_EVENT_CPUID) | (1U << XEN_DOMCTL_MONITOR_EVENT_INTERRUPT) |
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v4 3/3 hvm/svm: Enable CR events
In reply to Alexandru IsailaThe CR_INTERCEPT_CR3_WRITE intercept is out of the vmcb->_cr_intercepts so the AMD arch can't intercept CR events.
This patch implements the CR intercept by adding the flag on a write_ctrlreg event. The monitor write ctrlreg event is moved from the Intel side to the common capabilities side.
We just need to enable the SVM intercept and then hvm_mov_to_cr() will forward the event on to the monitor when appropriate.
---
Changes since V3:
-Rebase to the latest staging
--- xen/arch/x86/hvm/svm/svm.c | 11 +++++++++++ xen/include/asm-x86/monitor.h | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-)
xen/arch/x86/hvm/svm/svm.c +11 -0
@@ -60,6 +60,7 @@#include <asm/apic.h> #include <asm/debugger.h> #include <asm/hvm/monitor.h> +#include <asm/monitor.h> #include <asm/xstate.h> void svm_asm_do_resume (void );
@@ -560,6 +561,16 @@ void svm_update_guest_cr(struct vcpu *v, unsigned int cr)svm_fpu_enter (v); } +if (paging_mode_hap (v->domain) ) + { +uint32_t intercepts =vmcb_get_cr_intercepts (vmcb); + +/* Trap CR3 updates if CR3 memory events are enabled. */ +if ( v->domain->arch.monitor.write_ctrlreg_enabled & +monitor_ctrlreg_bitmask (VM_EVENT_X86_CR3 ) ) +vmcb_set_cr_intercepts (vmcb, intercepts |CR_INTERCEPT_CR3_WRITE ); + } + value = v->arch.hvm_vcpu.guest_cr[0 ] | hw_cr0_mask;if ( !paging_mode_hap (v->domain) ) value |=X86_CR0_PG |X86_CR0_WP ;
xen/include/asm-x86/monitor.h +3 -3
@@ -79,12 +79,12 @@ static inline uint32_t arch_monitor_get_capabilities(struct domain *d) capabilities = ((1U <<XEN_DOMCTL_MONITOR_EVENT_GUEST_REQUEST ) | (1U <<XEN_DOMCTL_MONITOR_EVENT_SOFTWARE_BREAKPOINT ) | - (1U <<XEN_DOMCTL_MONITOR_EVENT_MOV_TO_MSR )); + (1U <<XEN_DOMCTL_MONITOR_EVENT_MOV_TO_MSR ) | + (1U <<XEN_DOMCTL_MONITOR_EVENT_WRITE_CTRLREG ));if ( cpu_has_vmx ) { - capabilities |= ((1U <<XEN_DOMCTL_MONITOR_EVENT_WRITE_CTRLREG ) | - (1U <<XEN_DOMCTL_MONITOR_EVENT_DEBUG_EXCEPTION ) | + capabilities |= ((1U <<XEN_DOMCTL_MONITOR_EVENT_DEBUG_EXCEPTION ) | (1U <<XEN_DOMCTL_MONITOR_EVENT_CPUID ) | (1U <<XEN_DOMCTL_MONITOR_EVENT_INTERRUPT ) | (1U <<XEN_DOMCTL_MONITOR_EVENT_EMUL_UNIMPLEMENTED ));
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 5 lines · Alexandru Isaila
Hi all,
This series provides a skeleton for enabling
vm_eventson SVM. For the first step, the MSR, CR, Breakpoint and GuestRequest have been tested and added to the capabilities list.
Ok - this series is looking much clearer now. Thanks.
one trivial style issue in patch 1 I can fix on commit).
You are still waiting for SVM acks on patches 1 and 3 by the looks of things.
One thing I note however is that patch 2 and 3 both turn on intercepts and have no way of turning them back off. This appears to be consistent with the Intel side of things, but it is suboptimal for the guest when an introspection agent detaches.
For the CPUID/MSR policy side of things, Jan has talked me in to changing how cpuid_policy_updated() works, and implementing it as a recalculation of the intercepts on the return-to-guest path. It occurs to me that this usefully extends to changes requested by the introspection agent.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 4 lines · Andrew Cooper
One thing I note however is that patch 2 and 3 both turn on intercepts and have no way of turning them back off. This appears to be consistent with the Intel side of things, but it is suboptimal for the guest when an introspection agent detaches.
That's very true (I've also pointed this out to Bitweasil when we've discussed the CR3 intercept crash after the noflush bit started to get used).
I've also considered this when I've added the MSR write subscription code, however it didn't feel safe to just disable those exits when the introspection agent unplugs.
For one, we'd have to store the previous state somewhere (we might be interested in a MSR, for example, for which exits were already enabled before we subscribed to it - we shouldn't disable exits for it then).
And even if we did keep the previous state somewhere (with the assorted problems - where do we allocate space for it? etc.) - it's theoretically possible that some other Xen subsystem fiddles with the exits in the meantime, so the state we remember may not be the current state of affairs wrt exits.
Am I overthinking this?
Quoted 5 lines
For the CPUID/MSR policy side of things, Jan has talked me in to changing how
cpuid_policy_updated()works, and implementing it as a recalculation of the intercepts on the return-to-guest path. It occurs to me that this usefully extends to changes requested by the introspection agent.
Thanks, we'll look that up.
Thanks,
Razvan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 5 lines · Razvan Cojocaru
Quoted 4 lines · Andrew Cooper
One thing I note however is that patch 2 and 3 both turn on intercepts and have no way of turning them back off. This appears to be consistent with the Intel side of things, but it is suboptimal for the guest when an introspection agent detaches.
Quoted 7 lines
That's very true (I've also pointed this out to Bitweasil when we've discussed the CR3 intercept crash after the noflush bit started to get used).
I've also considered this when I've added the MSR write subscription code, however it didn't feel safe to just disable those exits when the introspection agent unplugs.
The problem is that we don't have a source of information to derive the intercepts from, which is also what is causing chaos trying to get nested virt working.
We only have what is programmed into the hardware structures, which suffers from "multiple-producers" syndrome.
Quoted 11 lines
For one, we'd have to store the previous state somewhere (we might be interested in a MSR, for example, for which exits were already enabled before we subscribed to it - we shouldn't disable exits for it then).
And even if we did keep the previous state somewhere (with the assorted problems - where do we allocate space for it? etc.) - it's theoretically possible that some other Xen subsystem fiddles with the exits in the meantime, so the state we remember may not be the current state of affairs wrt exits.
Am I overthinking this?
No - I don't think so.
The only way to solve this problem is to have all the information for each agent (including Xen itself) interested in controlling the behaviour of the guest to be available, hooked off struct domain/vcpu as appropriate, and one single function to combine everyones view of the world into the hardware configuration.
If you can't unambiguously recalculate the contents of the VMCS/VMCB, then something is broken.
Quoted 7 lines
Quoted 6 lines
For the CPUID/MSR policy side of things, Jan has talked me in to changing how
cpuid_policy_updated()works, and implementing it as a recalculation of the intercepts on the return-to-guest path. It occurs to me that this usefully extends to changes requested by the introspection agent.Thanks, we'll look that up.
It doesn't exist yet :)
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 6 lines · Alexandru Isaila
Hi all,
This series provides a skeleton for enabling
vm_eventson SVM. For the first step, the MSR, CR, Breakpoint and GuestRequest have been tested and added to the capabilities list.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel