x86/mm: Suppresses vm_events caused by page-walks
PATCH v6 1/1 x86/mm: Suppresses vm_events caused by page-walks
This patch is adding a way to enable/disable inguest pagefault events. It introduces the xc_monitor_inguest_pagefault function and adds the inguest_pagefault_disabled in the monitor structure. This is needed by the introspection so it will only get gla faults and not get spammed with other faults.
In p2m_mem_access_check() we emulate so no event will get sent.
---
Changes since V5:
- Add comment for the xc_monitor_inguest_pagefault() func.
- Add altp2m_write_no_gpt test in xen_access
--- tools/libxc/include/xenctrl.h | 7 +++++++ tools/libxc/xc_monitor.c | 14 ++++++++++++++ tools/tests/xen-access/xen-access.c | 36 +++++++++++++++++++++++++++++++++++- xen/arch/x86/mm/mem_access.c | 9 +++++++++ xen/arch/x86/monitor.c | 13 +++++++++++++ xen/include/asm-x86/domain.h | 5 +++++ xen/include/asm-x86/monitor.h | 3 ++- xen/include/public/domctl.h | 2 ++ 8 files changed, 87 insertions(+), 2 deletions(-)
tools/libxc/include/xenctrl.h +7 -0
@@ -2056,6 +2056,13 @@ int xc_monitor_descriptor_access(xc_interface *xch, uint32_t domain_id, bool enable);int xc_monitor_guest_request (xc_interface *xch,uint32_t domain_id,bool enable,bool sync,bool allow_userspace); +/* +* Disables page-walk mem_access events by emulating. If the +* emulation can not be performed then a VM_EVENT_REASON_EMUL_UNIMPLEMENTED +* event will be issued. +*/ +int xc_monitor_inguest_pagefault (xc_interface *xch,uint32_t domain_id, +bool disable);int xc_monitor_debug_exceptions (xc_interface *xch,uint32_t domain_id,bool enable,bool sync);int xc_monitor_cpuid (xc_interface *xch,uint32_t domain_id,bool enable);
tools/libxc/xc_monitor.c +14 -0
@@ -163,6 +163,20 @@ int xc_monitor_guest_request(xc_interface *xch, uint32_t domain_id, bool enable,return do_domctl (xch, &domctl); } +int xc_monitor_inguest_pagefault (xc_interface *xch,uint32_t domain_id, +bool disable) +{ +DECLARE_DOMCTL ; + + domctl.cmd = XEN_DOMCTL_monitor_op; + domctl.domain = domain_id; + domctl.u.monitor_op.op = disable ?XEN_DOMCTL_MONITOR_OP_ENABLE + :XEN_DOMCTL_MONITOR_OP_DISABLE ; + domctl.u.monitor_op.event =XEN_DOMCTL_MONITOR_EVENT_INGUEST_PAGEFAULT ; + +return do_domctl (xch, &domctl); +} +int xc_monitor_emulate_each_rep (xc_interface *xch,uint32_t domain_id,bool enable) {
tools/tests/xen-access/xen-access.c +35 -1
@@ -362,7 +362,7 @@ void usage(char* progname) {fprintf (stderr,"Usage: %s [-m] <domain_id> write|exec" , progname);#if defined(__i386__) || defined(__x86_64__) -fprintf (stderr,"|breakpoint|altp2m_write|altp2m_exec|debug|cpuid|desc_access|write_ctrlreg_cr4" ); +fprintf (stderr,"|breakpoint|altp2m_write|altp2m_exec|debug|cpuid|desc_access|write_ctrlreg_cr4|altp2m_write_no_gpt" );#elif defined(__arm__) || defined(__aarch64__)fprintf (stderr,"|privcall" );#endif
@@ -395,6 +395,7 @@ int main(int argc, char *argv[])int cpuid =0 ;int desc_access =0 ;int write_ctrlreg_cr4 =0 ; +int altp2m_write_no_gpt =0 ;uint16_t altp2m_view_id =0 ;char * progname = argv[0 ];
@@ -453,6 +454,13 @@ int main(int argc, char *argv[]) altp2m =1 ; memaccess =1 ; } +else if ( !strcmp (argv[0 ],"altp2m_write_no_gpt" ) ) + { + default_access = XENMEM_access_rw; + altp2m_write_no_gpt =1 ; + memaccess =1 ; + altp2m =1 ; + }else if ( !strcmp (argv[0 ],"debug" ) ) { debug =1 ;
@@ -513,6 +521,22 @@ int main(int argc, char *argv[])xen_pfn_t gfn =0 ;unsigned long perm_set =0 ; +if ( altp2m_write_no_gpt ) + { + rc =xc_monitor_inguest_pagefault (xch, domain_id,1 ); +if ( rc <0 ) + { +ERROR ("Error %d setting inguest pagefault\n" , rc); + goto exit; + } + rc =xc_monitor_emul_unimplemented (xch, domain_id,1 ); +if ( rc <0 ) + { +ERROR ("Error %d failed to enable emul unimplemented\n" , rc); + goto exit; + } + } + rc =xc_altp2m_set_domain_state ( xch, domain_id,1 );if ( rc <0 ) {
@@ -857,6 +881,16 @@ int main(int argc, char *argv[]) req.u.write_ctrlreg.old_value, req.u.write_ctrlreg.new_value);break ; +case VM_EVENT_REASON_EMUL_UNIMPLEMENTED : +if ( altp2m_write_no_gpt && req.flags &VM_EVENT_FLAG_ALTERNATE_P2M ) + { +DPRINTF ("\tSwitching back to default view!\n" ); + + rsp.flags |= (VM_EVENT_FLAG_ALTERNATE_P2M | +VM_EVENT_FLAG_TOGGLE_SINGLESTEP ); + rsp.altp2m_idx =0 ; + } +break ;default :fprintf (stderr,"UNKNOWN REASON CODE %d\n" , req.reason); }
xen/arch/x86/mm/mem_access.c +9 -0
@@ -28,6 +28,7 @@#include <public/vm_event.h> #include <asm/p2m.h> #include <asm/altp2m.h> +#include <asm/hvm/emulate.h> #include <asm/vm_event.h> #include "mm-locks.h"
@@ -207,6 +208,14 @@ bool p2m_mem_access_check(paddr_t gpa, unsigned long gla,return true; } } +if (vm_event_check_ring (d->vm_event_monitor) && + d->arch.monitor.inguest_pagefault_disabled && + npfec.kind != npfec_kind_with_gla )/* don't send a mem_event */ + { +hvm_emulate_one_vm_event (EMUL_KIND_NORMAL , TRAP_invalid_op,X86_EVENT_NO_EC ); + +return true; + } *req_ptr =NULL ; req =xzalloc (vm_event_request_t);
xen/arch/x86/monitor.c +13 -0
@@ -241,6 +241,19 @@ int arch_monitor_domctl_event(struct domain *d,break ; } +case XEN_DOMCTL_MONITOR_EVENT_INGUEST_PAGEFAULT : + { +bool old_status = ad->monitor.inguest_pagefault_disabled; + +if (unlikely (old_status == requested_status) ) +return -EEXIST ; + +domain_pause (d); + ad->monitor.inguest_pagefault_disabled = requested_status; +domain_unpause (d); +break ; + } +case XEN_DOMCTL_MONITOR_EVENT_DESC_ACCESS : {bool old_status = ad->monitor.descriptor_access_enabled;
xen/include/asm-x86/domain.h +5 -0
@@ -412,6 +412,11 @@ struct arch_domain unsigned int descriptor_access_enabled : 1; unsigned int guest_request_userspace_enabled : 1; unsigned int emul_unimplemented_enabled : 1; +/* +* By default all events are sent. +* This is used to filter out pagefaults. +*/ + unsigned int inguest_pagefault_disabled : 1;struct monitor_msr_bitmap *msr_bitmap;uint64_t write_ctrlreg_mask[4 ]; } monitor;
xen/include/asm-x86/monitor.h +2 -1
@@ -84,7 +84,8 @@ static inline uint32_t arch_monitor_get_capabilities(struct domain *d) (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 ); + (1U <<XEN_DOMCTL_MONITOR_EVENT_EMUL_UNIMPLEMENTED ) | + (1U <<XEN_DOMCTL_MONITOR_EVENT_INGUEST_PAGEFAULT );/* Since we know this is on VMX, we can just call the hvm func */ if (hvm_is_singlestep_supported () )
xen/include/public/domctl.h +2 -0
@@ -1014,6 +1014,8 @@ struct xen_domctl_psr_cmt_op {#define XEN_DOMCTL_MONITOR_EVENT_INTERRUPT 8#define XEN_DOMCTL_MONITOR_EVENT_DESC_ACCESS 9#define XEN_DOMCTL_MONITOR_EVENT_EMUL_UNIMPLEMENTED 10 +/* Enabled by default */ +#define XEN_DOMCTL_MONITOR_EVENT_INGUEST_PAGEFAULT 11struct xen_domctl_monitor_op {uint32_t op;/* XEN_DOMCTL_MONITOR_OP_* */
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 6 lines · Alexandru Isaila
This patch is adding a way to enable/disable inguest pagefault events. It introduces the
xc_monitor_inguest_pagefaultfunction and adds theinguest_pagefault_disabledin the monitor structure. This is needed by the introspection so it will only get gla faults and not get spammed with other faults.
Inp2m_mem_access_check()we emulate so no event will get sent.
Thanks for the changes!
Quoted 230 lines
Signed-off-by Alexandru Isaila <[email protected]>---
Changes since V5:
- Add comment for thexc_monitor_inguest_pagefault()func.
- Addaltp2m_write_no_gpttest inxen_access--- tools/libxc/include/xenctrl.h | 7 +++++++ tools/libxc/xc_monitor.c | 14 ++++++++++++++ tools/tests/xen-access/xen-access.c | 36 +++++++++++++++++++++++++++++++++++- xen/arch/x86/mm/mem_access.c | 9 +++++++++ xen/arch/x86/monitor.c | 13 +++++++++++++ xen/include/asm-x86/domain.h | 5 +++++ xen/include/asm-x86/monitor.h | 3 ++- xen/include/public/domctl.h | 2 ++ 8 files changed, 87 insertions(+), 2 deletions(-)tools/libxc/include/xenctrl.h +7
-0@@ -2056,6 +2056,13 @@ int xc_monitor_descriptor_access(xc_interface *xch, uint32_t domain_id, bool enable);int xc_monitor_guest_request (xc_interface *xch,uint32_t domain_id,bool enable,bool sync,bool allow_userspace); +/* +* Disables page-walk mem_access events by emulating. If the +* emulation can not be performed then a VM_EVENT_REASON_EMUL_UNIMPLEMENTED +* event will be issued. +*/ +int xc_monitor_inguest_pagefault (xc_interface *xch,uint32_t domain_id, +bool disable);int xc_monitor_debug_exceptions (xc_interface *xch,uint32_t domain_id,bool enable,bool sync);int xc_monitor_cpuid (xc_interface *xch,uint32_t domain_id,bool enable);tools/libxc/xc_monitor.c +14
-0@@ -163,6 +163,20 @@ int xc_monitor_guest_request(xc_interface *xch, uint32_t domain_id, bool enable,return do_domctl (xch, &domctl); } +int xc_monitor_inguest_pagefault (xc_interface *xch,uint32_t domain_id, +bool disable) +{ +DECLARE_DOMCTL ; + + domctl.cmd = XEN_DOMCTL_monitor_op; + domctl.domain = domain_id; + domctl.u.monitor_op.op = disable ?XEN_DOMCTL_MONITOR_OP_ENABLE + :XEN_DOMCTL_MONITOR_OP_DISABLE ; + domctl.u.monitor_op.event =XEN_DOMCTL_MONITOR_EVENT_INGUEST_PAGEFAULT ; + +return do_domctl (xch, &domctl); +} +int xc_monitor_emulate_each_rep (xc_interface *xch,uint32_t domain_id,bool enable) {tools/tests/xen-access/xen-access.c +35
-1@@ -362,7 +362,7 @@ void usage(char* progname) {fprintf (stderr,"Usage: %s [-m] <domain_id> write|exec" , progname);#if defined(__i386__) || defined(__x86_64__) -fprintf (stderr,"|breakpoint|altp2m_write|altp2m_exec|debug|cpuid|desc_access|write_ctrlreg_cr4" ); +fprintf (stderr,"|breakpoint|altp2m_write|altp2m_exec|debug|cpuid|desc_access|write_ctrlreg_cr4|altp2m_write_no_gpt" );#elif defined(__arm__) || defined(__aarch64__)fprintf (stderr,"|privcall" );#endif @@ -395,6 +395,7 @@ int main(int argc, char *argv[])int cpuid =0 ;int desc_access =0 ;int write_ctrlreg_cr4 =0 ; +int altp2m_write_no_gpt =0 ;uint16_t altp2m_view_id =0 ;char * progname = argv[0 ];@@ -453,6 +454,13 @@ int main(int argc, char *argv[]) altp2m =1 ; memaccess =1 ; } +else if ( !strcmp (argv[0 ],"altp2m_write_no_gpt" ) ) + { + default_access = XENMEM_access_rw; + altp2m_write_no_gpt =1 ; + memaccess =1 ; + altp2m =1 ; + }else if ( !strcmp (argv[0 ],"debug" ) ) { debug =1 ;@@ -513,6 +521,22 @@ int main(int argc, char *argv[])xen_pfn_t gfn =0 ;unsigned long perm_set =0 ; +if ( altp2m_write_no_gpt ) + { + rc =xc_monitor_inguest_pagefault (xch, domain_id,1 ); +if ( rc <0 ) + { +ERROR ("Error %d setting inguest pagefault\n" , rc); + goto exit; + } + rc =xc_monitor_emul_unimplemented (xch, domain_id,1 ); +if ( rc <0 ) + { +ERROR ("Error %d failed to enable emul unimplemented\n" , rc); + goto exit; + } + } + rc =xc_altp2m_set_domain_state ( xch, domain_id,1 );if ( rc <0 ) {@@ -857,6 +881,16 @@ int main(int argc, char *argv[]) req.u.write_ctrlreg.old_value, req.u.write_ctrlreg.new_value);break ; +case VM_EVENT_REASON_EMUL_UNIMPLEMENTED : +if ( altp2m_write_no_gpt && req.flags &VM_EVENT_FLAG_ALTERNATE_P2M ) + { +DPRINTF ("\tSwitching back to default view!\n" ); + + rsp.flags |= (VM_EVENT_FLAG_ALTERNATE_P2M | +VM_EVENT_FLAG_TOGGLE_SINGLESTEP ); + rsp.altp2m_idx =0 ; + } +break ;default :fprintf (stderr,"UNKNOWN REASON CODE %d\n" , req.reason); }xen/arch/x86/mm/mem_access.c +9
-0@@ -28,6 +28,7 @@#include <public/vm_event.h> #include <asm/p2m.h> #include <asm/altp2m.h> +#include <asm/hvm/emulate.h> #include <asm/vm_event.h> #include "mm-locks.h" @@ -207,6 +208,14 @@ bool p2m_mem_access_check(paddr_t gpa, unsigned long gla,return true; } } +if (vm_event_check_ring (d->vm_event_monitor) && + d->arch.monitor.inguest_pagefault_disabled && + npfec.kind != npfec_kind_with_gla )/* don't send a mem_event */ + { +hvm_emulate_one_vm_event (EMUL_KIND_NORMAL , TRAP_invalid_op,X86_EVENT_NO_EC ); + +return true; + } *req_ptr =NULL ; req =xzalloc (vm_event_request_t);xen/arch/x86/monitor.c +13
-0@@ -241,6 +241,19 @@ int arch_monitor_domctl_event(struct domain *d,break ; } +case XEN_DOMCTL_MONITOR_EVENT_INGUEST_PAGEFAULT : + { +bool old_status = ad->monitor.inguest_pagefault_disabled; + +if (unlikely (old_status == requested_status) ) +return -EEXIST ; + +domain_pause (d); + ad->monitor.inguest_pagefault_disabled = requested_status; +domain_unpause (d); +break ; + } +case XEN_DOMCTL_MONITOR_EVENT_DESC_ACCESS : {bool old_status = ad->monitor.descriptor_access_enabled;xen/include/asm-x86/domain.h +5
-0@@ -412,6 +412,11 @@ struct arch_domain unsigned int descriptor_access_enabled : 1; unsigned int guest_request_userspace_enabled : 1; unsigned int emul_unimplemented_enabled : 1; +/* +* By default all events are sent. +* This is used to filter out pagefaults. +*/ + unsigned int inguest_pagefault_disabled : 1;struct monitor_msr_bitmap *msr_bitmap;uint64_t write_ctrlreg_mask[4 ]; } monitor;xen/include/asm-x86/monitor.h +2
-1@@ -84,7 +84,8 @@ static inline uint32_t arch_monitor_get_capabilities(struct domain *d) (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 ); + (1U <<XEN_DOMCTL_MONITOR_EVENT_EMUL_UNIMPLEMENTED ) | + (1U <<XEN_DOMCTL_MONITOR_EVENT_INGUEST_PAGEFAULT );/* Since we know this is on VMX, we can just call the hvm func */ if (hvm_is_singlestep_supported () )xen/include/public/domctl.h +2
-1@@ -1014,6 +1014,8 @@ struct xen_domctl_psr_cmt_op {#define XEN_DOMCTL_MONITOR_EVENT_INTERRUPT 8#define XEN_DOMCTL_MONITOR_EVENT_DESC_ACCESS 9#define XEN_DOMCTL_MONITOR_EVENT_EMUL_UNIMPLEMENTED 10 +/* Enabled by default */ +#define XEN_DOMCTL_MONITOR_EVENT_INGUEST_PAGEFAULT 11struct xen_domctl_monitor_op {uint32_t op;/* XEN_DOMCTL_MONITOR_OP_* */ --
Quoted 1 line
2.7.4
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 9 lines · Alexandru Isaila
This patch is adding a way to enable/disable inguest pagefault events. It introduces the
xc_monitor_inguest_pagefaultfunction and adds theinguest_pagefault_disabledin the monitor structure. This is needed by the introspection so it will only get gla faults and not get spammed with other faults.
Inp2m_mem_access_check()we emulate so no event will get sent.Signed-off-by Alexandru Isaila <[email protected]>
Quoted 7 lines
---
Changes since V5:
- Add comment for thexc_monitor_inguest_pagefault()func.
- Addaltp2m_write_no_gpttest inxen_access--- tools/libxc/include/xenctrl.h | 7 +++++++ tools/libxc/xc_monitor.c | 14 ++++++++++++++
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
xen/include/asm-x86/monitor.h static inline uint32_t arch_monitor_get_capabilities(struct domain *d) · line 91
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 07.05.18 at 15:40, <[email protected]> wrote:
xen/include/asm-x86/monitor.h +2
-1@@ -84,7 +84,8 @@ static inline uint32_t arch_monitor_get_capabilities(struct domain *d) (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 ); + (1U <<XEN_DOMCTL_MONITOR_EVENT_EMUL_UNIMPLEMENTED ) | + (1U <<XEN_DOMCTL_MONITOR_EVENT_INGUEST_PAGEFAULT );/* Since we know this is on VMX, we can just call the hvm func */ if (hvm_is_singlestep_supported () )
So this change looks to depend on some random version of "hvm/svm: Enable EMUL_UNIMPLEMENTED events on svm", but this isn't mentioned anywhere, and it's also not the version that I've just managed to apply. Please can you spell out such dependencies?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel