arch/x86: Add registers to vm_event
PATCH v5 1/1 arch/x86: Add registers to vm_event
This patch adds a couple of regs to the vm_event that are used by the introspection. The base, limit and ar
bits are compressed into a uint64_t union so as not to enlarge the vm_event.
---
Changes since V4:
- Change the comment into one line
- Pull the base out of x86_selector_reg
- Renamed x86_selector_reg_32,64 into x86_selector_reg.
--- xen/arch/x86/vm_event.c | 71 +++++++++++++++++++++++++++++++---- xen/include/public/vm_event.h | 26 ++++++++++++- 2 files changed, 87 insertions(+), 10 deletions(-)
xen/arch/x86/vm_event.c +63 -8
@@ -122,11 +122,66 @@ void vm_event_monitor_next_interrupt(struct vcpu *v) v->arch.monitor.next_interrupt_enabled = true; } +static void vm_event_pack_segment_register (enum x86_segment segment, +struct vm_event_regs_x86 *reg) +{ +struct segment_register seg; + +hvm_get_segment_register (current, segment, &seg); + +switch ( segment ) + { +case x86_seg_ss: + reg->ss_base = seg.base; + reg->ss.limit = seg.g ? seg.limit >>12 : seg.limit; + reg->ss.ar = seg.attr; + reg->ss_sel = seg.sel; +break ; + +case x86_seg_fs: + reg->fs_base = seg.base; + reg->fs.limit = seg.g ? seg.limit >>12 : seg.limit; + reg->fs.ar = seg.attr; + reg->fs_sel = seg.sel; +break ; + +case x86_seg_gs: + reg->gs_base = seg.base; + reg->gs.limit = seg.g ? seg.limit >>12 : seg.limit; + reg->gs.ar = seg.attr; + reg->gs_sel = seg.sel; +break ; + +case x86_seg_cs: + reg->cs_base = seg.base; + reg->cs.limit = seg.g ? seg.limit >>12 : seg.limit; + reg->cs.ar = seg.attr; + reg->cs_sel = seg.sel; +break ; + +case x86_seg_ds: + reg->ds_base = seg.base; + reg->ds.limit = seg.g ? seg.limit >>12 : seg.limit; + reg->ds.ar = seg.attr; + reg->ds_sel = seg.sel; +break ; + +case x86_seg_es: + reg->es_base = seg.base; + reg->es.limit = seg.g ? seg.limit >>12 : seg.limit; + reg->es.ar = seg.attr; + reg->es_sel = seg.sel; +break ; + +default : +ASSERT_UNREACHABLE (); + } +} +void vm_event_fill_regs (vm_event_request_t *req) {#ifdef CONFIG_HVM const struct cpu_user_regs *regs =guest_cpu_user_regs (); -struct segment_register seg;struct hvm_hw_cpu ctxt = {};struct vcpu *curr = current;
@@ -170,14 +225,14 @@ void vm_event_fill_regs(vm_event_request_t *req) req->data.regs.x86.msr_star = ctxt.msr_star; req->data.regs.x86.msr_lstar = ctxt.msr_lstar; -hvm_get_segment_register (curr, x86_seg_fs, &seg); - req->data.regs.x86.fs_base = seg.base; - -hvm_get_segment_register (curr, x86_seg_gs, &seg); - req->data.regs.x86.gs_base = seg.base; +vm_event_pack_segment_register (x86_seg_fs, &req->data.regs.x86); +vm_event_pack_segment_register (x86_seg_gs, &req->data.regs.x86); +vm_event_pack_segment_register (x86_seg_cs, &req->data.regs.x86); +vm_event_pack_segment_register (x86_seg_ss, &req->data.regs.x86); +vm_event_pack_segment_register (x86_seg_ds, &req->data.regs.x86); +vm_event_pack_segment_register (x86_seg_es, &req->data.regs.x86); -hvm_get_segment_register (curr, x86_seg_cs, &seg); - req->data.regs.x86.cs_arbytes = seg.attr; + req->data.regs.x86.shadow_gs = ctxt.shadow_gs;#endif }
xen/include/public/vm_event.h +24 -2
@@ -29,7 +29,7 @@#include "xen.h" -#define VM_EVENT_INTERFACE_VERSION 0x00000003 +#define VM_EVENT_INTERFACE_VERSION 0x00000004#if defined(__XEN__) || defined(__XEN_TOOLS__)
@@ -157,6 +157,12 @@#define VM_EVENT_X86_CR4 2#define VM_EVENT_X86_XCR0 3 +/* The limit field is right-shifted by 12 bits if .ar.g is set. */ +struct x86_selector_reg { +uint32_t limit :20 ; +uint32_t ar :12 ; +}; +/* * Using custom vCPU structs (i.e. not hvm_hw_cpu) for both x86 and ARM * so as to not fill the vm_event ring buffer too quickly.
@@ -191,9 +197,25 @@ struct vm_event_regs_x86 {uint64_t msr_efer;uint64_t msr_star;uint64_t msr_lstar; +uint32_t cs_base; +uint32_t ss_base; +uint32_t ds_base; +uint32_t es_base;uint64_t fs_base;uint64_t gs_base; -uint32_t cs_arbytes; +struct x86_selector_reg cs; +struct x86_selector_reg ss; +struct x86_selector_reg ds; +struct x86_selector_reg es; +struct x86_selector_reg fs; +struct x86_selector_reg gs; +uint64_t shadow_gs; +uint16_t cs_sel; +uint16_t ss_sel; +uint16_t ds_sel; +uint16_t es_sel; +uint16_t fs_sel; +uint16_t gs_sel;uint32_t _pad; };
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 30.10.18 at 11:07, <[email protected]> wrote:
xen/include/public/vm_event.h +1
-1@@ -29,7 +29,7 @@#include "xen.h" -#define VM_EVENT_INTERFACE_VERSION 0x00000003 +#define VM_EVENT_INTERFACE_VERSION 0x00000004#if defined(__XEN__) || defined(__XEN_TOOLS__)
xen/include/public/vm_event.h line 161
Quoted 5 lines
xen/include/public/vm_event.h +2
-0@@ -157,6 +157,12 @@#define VM_EVENT_X86_CR4 2#define VM_EVENT_X86_XCR0 3 +/* The limit field is right-shifted by 12 bits if .ar.g is set. */ +struct x86_selector_reg {
I'm sorry for not having noticed this earlier, but this needs proper
prefixing: Matching struct vm_event_regs_x86, it should at least be prefixed by vm_event_. Strictly speaking xen_ as the very first thing would also be required, but I'll leave that to the VM event maintainers to decide. With this
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 24 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 30.10.18 at 11:07, <[email protected]> wrote:
xen/include/public/vm_event.h +1
-1@@ -29,7 +29,7 @@#include "xen.h" -#define VM_EVENT_INTERFACE_VERSION 0x00000003 +#define VM_EVENT_INTERFACE_VERSION 0x00000004#if defined(__XEN__) || defined(__XEN_TOOLS__)xen/include/public/vm_event.h line 161
Quoted 5 lines
xen/include/public/vm_event.h +2
-0@@ -157,6 +157,12 @@#define VM_EVENT_X86_CR4 2#define VM_EVENT_X86_XCR0 3 +/* The limit field is right-shifted by 12 bits if .ar.g is set. */ +struct x86_selector_reg {I'm sorry for not having noticed this earlier, but this needs proper
prefixing: Matching structvm_event_regs_x86, it should at least be prefixed byvm_event_. Strictly speakingxen_as the very first thing would also be required, but I'll leave that to the VM event maintainers to decide. With this
Quoted 1 line
Reviewed-by Jan Beulich <[email protected]>
I am fine with either approach (so leaving it as it is not a problem), so we'll go with Tamas' preference. Tamas, what's your opinion?
Thanks,
Razvan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 28 lines
Quoted 1 line
Quoted 1 line · On 30.10.18 at 13:26, <[email protected]> wrote:
Quoted 24 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 30.10.18 at 11:07, <[email protected]> wrote:
xen/include/public/vm_event.h +1
-1@@ -29,7 +29,7 @@#include "xen.h" -#define VM_EVENT_INTERFACE_VERSION 0x00000003 +#define VM_EVENT_INTERFACE_VERSION 0x00000004#if defined(__XEN__) || defined(__XEN_TOOLS__)xen/include/public/vm_event.h line 161
Quoted 5 lines
xen/include/public/vm_event.h +2
-0@@ -157,6 +157,12 @@#define VM_EVENT_X86_CR4 2#define VM_EVENT_X86_XCR0 3 +/* The limit field is right-shifted by 12 bits if .ar.g is set. */ +struct x86_selector_reg {I'm sorry for not having noticed this earlier, but this needs proper
prefixing: Matching structvm_event_regs_x86, it should at least be prefixed byvm_event_. Strictly speakingxen_as the very first thing would also be required, but I'll leave that to the VM event maintainers to decide. With thisQuoted 1 line
Reviewed-by Jan Beulich <[email protected]>
Quoted 2 lines
I am fine with either approach (so leaving it as it is not a problem), so we'll go with Tamas' preference. Tamas, what's your opinion?
FAOD leaving as is is not an option - at least vm_event_ needs to be added, to not chance collision with a future addition in Xen itself.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 29 lines · Jan Beulich
Quoted 29 lines
Quoted 2 lines
Quoted 2 lines · On 30.10.18 at 13:26, <[email protected]> wrote:
Quoted 25 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 30.10.18 at 11:07, <[email protected]> wrote:
xen/include/public/vm_event.h +1
-1@@ -29,7 +29,7 @@#include "xen.h" -#define VM_EVENT_INTERFACE_VERSION 0x00000003 +#define VM_EVENT_INTERFACE_VERSION 0x00000004#if defined(__XEN__) || defined(__XEN_TOOLS__)xen/include/public/vm_event.h line 161
Quoted 5 lines
xen/include/public/vm_event.h +2
-0@@ -157,6 +157,12 @@#define VM_EVENT_X86_CR4 2#define VM_EVENT_X86_XCR0 3 +/* The limit field is right-shifted by 12 bits if .ar.g is set. */ +struct x86_selector_reg {I'm sorry for not having noticed this earlier, but this needs proper
prefixing: Matching structvm_event_regs_x86, it should at least be prefixed byvm_event_. Strictly speakingxen_as the very first thing would also be required, but I'll leave that to the VM event maintainers to decide. With thisReviewed-by Jan Beulich <[email protected]>
Quoted 5 lines
Quoted 2 lines
I am fine with either approach (so leaving it as it is not a problem), so we'll go with Tamas' preference. Tamas, what's your opinion?
FAOD leaving as is is not an option - at least
vm_event_needs to be added, to not chance collision with a future addition in Xen itself.
I agree, we should keep things prefixed with vm_event_ in this header.
Tamas
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel