x86/vm-event: numerous adjustments & fixes
cover x86/vm-event: numerous adjustments & fixes
Adjustments & fixes to the vm-events code, mostly monitor-related. As I hadn't got the time/proper context to test these changes on a real machine, for now please consider them only for review, I'll let you know when and how actual testing went.
Thanks,
Corneliu ZUZU (16):
x86/vmx_update_guest_cr: minor optimization
x86: fix: make atomic_read() param const
x86/monitor: mechanical renames
x86/monitor: relocate vm_event_register_write_resume() function to
monitor code
x86/monitor: relocate code more appropriately
x86/monitor: fix: set msr_bitmap to NULL after xfree x86/vm-event: fix: call cleanup when init fails, to free partial
allocs
x86/vm-event: call monitor init & cleanup funcs from respective
vm_event funcs
arm/monitor: move d->monitor cleanup to monitor_cleanup_domain() x86/vm-event: centralize vcpu-destroy cleanup in vm-events code x86/monitor: fix: treat -monitor- properly, as a subsys of the
vm-event subsys
x86/vm-event: fix: move cleanup of mem_access_emulate_each_rep to
monitor stub
x86/monitor: introduce writes_pending field in monitor_write_data x86/monitor: clarify separation between monitor subsys and vm-event as
a whole
x86/monitor: fix: don't compromise a monitor_write_data with pending
CR writes
x86/monitor: fix: xc_monitor _write_ctrlreg w/o previous _enable must
fail
xen/arch/x86/domain.c | 4 +- xen/arch/x86/hvm/emulate.c | 11 +- xen/arch/x86/hvm/hvm.c | 92 ++++++++-------- xen/arch/x86/hvm/vmx/vmx.c | 64 +++++++++-- xen/arch/x86/mm/p2m.c | 7 +- xen/arch/x86/monitor.c | 218 +++++++++++++++++++++++++++++++++++--- xen/arch/x86/vm_event.c | 82 +++++++------- xen/common/monitor.c | 4 +- xen/common/vm_event.c | 37 ++++--- xen/include/asm-arm/monitor.h | 17 +-- xen/include/asm-arm/vm_event.h | 21 ++-- xen/include/asm-x86/atomic.h | 4 +- xen/include/asm-x86/domain.h | 31 ++++-- xen/include/asm-x86/hvm/vmx/vmx.h | 1 + xen/include/asm-x86/monitor.h | 32 ++++-- xen/include/asm-x86/vm_event.h | 27 ++--- xen/include/xen/monitor.h | 11 +- xen/include/xen/sched.h | 1 + 18 files changed, 473 insertions(+), 191 deletions(-)
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 1/16 x86/vmx_update_guest_cr: minor optimization
Minor optimization @ vmx_update_guest_cr: checks if v->arch.hvm_vmx.exec_control was modified before actually calling vmx_update_cpu_exec_control(v).
--- xen/arch/x86/hvm/vmx/vmx.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/vmx/vmx.c +4 -1
@@ -1433,8 +1433,10 @@ static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr)if (paging_mode_hap (v->domain) ) {/* Manage GUEST_CR3 when CR0.PE=0. */ +uint32_t old_ctls = v->arch.hvm_vmx.exec_control;uint32_t cr3_ctls = (CPU_BASED_CR3_LOAD_EXITING |CPU_BASED_CR3_STORE_EXITING ); + v->arch.hvm_vmx.exec_control &= ~cr3_ctls;if ( !hvm_paging_enabled (v) && !vmx_unrestricted_guest (v) ) v->arch.hvm_vmx.exec_control |= cr3_ctls;
@@ -1444,7 +1446,8 @@ static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr) monitor_ctrlreg_bitmask(VM_EVENT_X86_CR3) ) v->arch.hvm_vmx.exec_control |=CPU_BASED_CR3_LOAD_EXITING ; -vmx_update_cpu_exec_control (v); +if ( old_ctls != v->arch.hvm_vmx.exec_control ) +vmx_update_cpu_exec_control (v); }if ( !nestedhvm_vcpu_in_guestmode (v) )
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 01/16] x86/vmx_update_guest_cr: minor optimization
This was 1/8 in the old v3-series "x86/vm-event: Adjustments & fixes". Transferring code-review from "Tian, Kevin <[email protected]>" (July 11, 2016).
Quoted 24 lines · Corneliu ZUZU
Minor optimization @
vmx_update_guest_cr: checks ifv->arch.hvm_vmx.exec_controlwas modified before actually callingvmx_update_cpu_exec_control(v).Signed-off-by Corneliu ZUZU <[email protected]>--- xen/arch/x86/hvm/vmx/vmx.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)xen/arch/x86/hvm/vmx/vmx.c +2
-0@@ -1433,8 +1433,10 @@ static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr)if (paging_mode_hap (v->domain) ) {/* Manage GUEST_CR3 when CR0.PE=0. */ +uint32_t old_ctls = v->arch.hvm_vmx.exec_control;uint32_t cr3_ctls = (CPU_BASED_CR3_LOAD_EXITING |CPU_BASED_CR3_STORE_EXITING ); + v->arch.hvm_vmx.exec_control &= ~cr3_ctls;if ( !hvm_paging_enabled (v) && !vmx_unrestricted_guest (v) ) v->arch.hvm_vmx.exec_control |= cr3_ctls;
xen/arch/x86/hvm/vmx/vmx.c static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr) · line 1453
Quoted 9 lines
xen/arch/x86/hvm/vmx/vmx.c +2
-1@@ -1444,7 +1446,8 @@ static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr) monitor_ctrlreg_bitmask(VM_EVENT_X86_CR3) ) v->arch.hvm_vmx.exec_control |=CPU_BASED_CR3_LOAD_EXITING ; -vmx_update_cpu_exec_control (v); +if ( old_ctls != v->arch.hvm_vmx.exec_control ) +vmx_update_cpu_exec_control (v); }if ( !nestedhvm_vcpu_in_guestmode (v) )
[Kevin wrote]:
---
Thanks,
Zuzu C.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 2/16 x86: fix: make atomic_read() param const
In reply to Corneliu ZUZUThis wouldn't let me make a param of a function that used atomic_read() const.
--- xen/include/asm-x86/atomic.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
xen/include/asm-x86/atomic.h +2 -2
@@ -94,7 +94,7 @@ typedef struct { int counter; } atomic_t;* * Atomically reads the value of @v. */ -static inline int atomic_read (atomic_t *v) +static inline int atomic_read (const atomic_t *v) {return read_atomic (&v->counter); }
@@ -105,7 +105,7 @@ static inline int atomic_read(atomic_t *v)* * Non-atomically reads the value of @v */ -static inline int _atomic_read (atomic_t v) +static inline int _atomic_read (const atomic_t v) {return v.counter; }
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 02/16] x86: fix: make atomic_read() param const
Quoted 3 lines · Corneliu ZUZU
This wouldn't let me make a param of a function that used
atomic_read()const.Signed-off-by Corneliu ZUZU <[email protected]>
This is a good improvement, but you must make an identical adjustment to the arm code, otherwise you will end up with subtle build failures.
If you are really feeling up to it, having a common xen/atomic.h with
typedef struct { int counter; } atomic_t;
#define ATOMIC_INIT(i) { (i) }
and some prototypes such as:
static inline int atomic_read(const atomic_t *v);
would be great, but this looks like it has the possibility to turn into a rats nest. If it does, then just doubling up this code for arm is ok.
~Andrew
Quoted 18 lines
--- xen/include/asm-x86/atomic.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)xen/include/asm-x86/atomic.h +1
-1@@ -94,7 +94,7 @@ typedef struct { int counter; } atomic_t;* * Atomically reads the value of @v. */ -static inline int atomic_read (atomic_t *v) +static inline int atomic_read (const atomic_t *v) {return read_atomic (&v->counter); }
xen/include/asm-x86/atomic.h static inline int atomic_read(atomic_t *v) · line 111
Quoted 8 lines
xen/include/asm-x86/atomic.h +1
-1@@ -105,7 +105,7 @@ static inline int atomic_read(atomic_t *v)* * Non-atomically reads the value of @v */ -static inline int _atomic_read (atomic_t v) +static inline int _atomic_read (const atomic_t v) {return v.counter; }
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 02/16] x86: fix: make atomic_read() param const
Hi Andrew,
Quoted 6 lines · Andrew Cooper
Quoted 3 lines · Corneliu ZUZU
This wouldn't let me make a param of a function that used
atomic_read()const.Signed-off-by Corneliu ZUZU <[email protected]>This is a good improvement, but you must make an identical adjustment to the arm code, otherwise you will end up with subtle build failures.
Right, didn't even realize it was X86-specific.
Quoted 6 lines
If you are really feeling up to it, having a common
xen/atomic.hwithtypedef struct { int counter; }
atomic_t;
#defineATOMIC_INIT(i){ (i) }
Quoted 8 lines
and some prototypes such as:
static inline int
atomic_read(const atomic_t *v);would be great, but this looks like it has the possibility to turn into a rats nest. If it does, then just doubling up this code for arm is ok.
~Andrew
Yes, that might be more complicated than we expect and I don't know if making code such as this common would be a good idea, usually these functions are always architecture-specific. It might be better to keep them separate - they don't add much anyway since their implementation is short - than risk unexpected different behavior on a future arch. But then again I don't know much details of their implementation, so anyway, I'd surely prefer to do this kind of change in a separate patch.
Quoted 19 lines
Quoted 19 lines
--- xen/include/asm-x86/atomic.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)xen/include/asm-x86/atomic.h +1
-1@@ -94,7 +94,7 @@ typedef struct { int counter; } atomic_t;* * Atomically reads the value of @v. */ -static inline int atomic_read (atomic_t *v) +static inline int atomic_read (const atomic_t *v) {return read_atomic (&v->counter); }@@ -105,7 +105,7 @@ static inline int atomic_read(atomic_t *v)
Quoted 9 lines
xen/include/asm-x86/atomic.h static inline int atomic_read(atomic_t *v) · line 111
Quoted 8 lines
xen/include/asm-x86/atomic.h +1
-1* * Non-atomically reads the value of @v */ -static inline int _atomic_read (atomic_t v) +static inline int _atomic_read (const atomic_t v) {return v.counter; }
Thanks,
Zuzu C.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 02/16] x86: fix: make atomic_read() param const
Quoted 4 lines · Corneliu ZUZU
Hi Andrew,
Quoted 1 line · Andrew Cooper
On 09/07/16 05:12, Corneliu ZUZU wrote:
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
This wouldn't let me make a param of a function that used
atomic_read()const.Signed-off-by Corneliu ZUZU <[email protected]>This is a good improvement, but you must make an identical adjustment to the arm code, otherwise you will end up with subtle build failures.
Right, didn't even realize it was X86-specific.
It isn't x86 specific. (Which is what I presume you meant to say.)
Quoted 11 lines
Quoted 11 lines
If you are really feeling up to it, having a common
xen/atomic.hwithtypedef struct { int counter; }
atomic_t;
#defineATOMIC_INIT(i){ (i) }and some prototypes such as:
static inline int
atomic_read(const atomic_t *v);
Quoted 8 lines
Quoted 4 lines
would be great, but this looks like it has the possibility to turn into a rats nest. If it does, then just doubling up this code for arm is ok.
~Andrew
Yes, that might be more complicated than we expect and I don't know if making code such as this common would be a good idea, usually these functions are always architecture-specific.
I only suggested making the prototype common, not the implementation. As such, the issue you accidentally introduced would become a hard build failure on affected architectures, rather than a subtle build failure in common code at some point in the future.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 02/16] x86: fix: make atomic_read() param const
Quoted 5 lines · Andrew Cooper
Quoted 4 lines · Corneliu ZUZU
Hi Andrew,
Quoted 1 line · Andrew Cooper
On 09/07/16 05:12, Corneliu ZUZU wrote:
Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
This wouldn't let me make a param of a function that used
atomic_read()const.Signed-off-by Corneliu ZUZU <[email protected]>This is a good improvement, but you must make an identical adjustment to the arm code, otherwise you will end up with subtle build failures.
Right, didn't even realize it was X86-specific.
It isn't x86 specific. (Which is what I presume you meant to say.)
Heh, yes, depends how you look at it, I was referring precisely to (the implementation of) the function I've modified (which was X86-specific, called from common, which meant there's an ARM one as well).
Quoted 17 lines
Quoted 10 lines
Quoted 10 lines
If you are really feeling up to it, having a common
xen/atomic.hwithtypedef struct { int counter; }
atomic_t;
#defineATOMIC_INIT(i){ (i) }and some prototypes such as:
static inline int
atomic_read(const atomic_t *v);Quoted 7 lines
Quoted 4 lines
would be great, but this looks like it has the possibility to turn into a rats nest. If it does, then just doubling up this code for arm is ok.
~Andrew
Yes, that might be more complicated than we expect and I don't know if making code such as this common would be a good idea, usually these functions are always architecture-specific.
Quoted 7 lines
I only suggested making the prototype common, not the implementation. As such, the issue you accidentally introduced would become a hard build failure on affected architectures, rather than a subtle build failure in common code at some point in the future.
~Andrew
Oh, I see, good idea, I've just tested it and it works, what did you have in mind when you said it could cause problems?
Zuzu C.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 02/16] x86: fix: make atomic_read() param const
Quoted 25 lines · Corneliu ZUZU
Quoted 25 lines
Quoted 16 lines
Quoted 16 lines
If you are really feeling up to it, having a common
xen/atomic.hwithtypedef struct { int counter; }
atomic_t;
#defineATOMIC_INIT(i){ (i) }and some prototypes such as:
static inline int
atomic_read(const atomic_t *v);would be great, but this looks like it has the possibility to turn into
a rats nest. If it does, then just doubling up this code for arm is ok.Quoted 4 lines
Quoted 1 line
~Andrew
Yes, that might be more complicated than we expect and I don't know if making code such as this common would be a good idea, usually these functions are always architecture-specific.
I only suggested making the prototype common, not the implementation. As such, the issue you accidentally introduced would become a hard build failure on affected architectures, rather than a subtle build failure in common code at some point in the future.
Quoted 5 lines
Quoted 2 lines
~Andrew
Oh, I see, good idea, I've just tested it and it works, what did you have in mind when you said it could cause problems?
The build issues would come at some point later when someone attempts to atomic_read() a constant atomic_t in common code, when the ARM build would break.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 02/16] x86: fix: make atomic_read() param const
Quoted 26 lines · Andrew Cooper
Quoted 25 lines · Corneliu ZUZU
Quoted 25 lines
Quoted 14 lines
Quoted 14 lines
If you are really feeling up to it, having a common
xen/atomic.hwithtypedef struct { int counter; }
atomic_t;
#defineATOMIC_INIT(i){ (i) }and some prototypes such as:
static inline int
atomic_read(const atomic_t *v);would be great, but this looks like it has the possibility to turn into
a rats nest. If it does, then just doubling up this code for arm is ok.Quoted 4 lines
Quoted 1 line
~Andrew
Yes, that might be more complicated than we expect and I don't know if making code such as this common would be a good idea, usually these functions are always architecture-specific.
I only suggested making the prototype common, not the implementation. As such, the issue you accidentally introduced would become a hard build failure on affected architectures, rather than a subtle build failure in common code at some point in the future.
~Andrew
Quoted 7 lines
Quoted 2 lines
Oh, I see, good idea, I've just tested it and it works, what did you have in mind when you said it could cause problems?
The build issues would come at some point later when someone attempts to
atomic_read()a constantatomic_tin common code, when the ARM build would break.~Andrew
Sorry, could you rephrase this? When the ARM build would break (i.e. fail, I presume) because of what?
Zuzu C.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 02/16] x86: fix: make atomic_read() param const
In reply to Andrew CooperQuoted 26 lines · Andrew Cooper
Quoted 25 lines · Corneliu ZUZU
Quoted 25 lines
Quoted 14 lines
Quoted 14 lines
If you are really feeling up to it, having a common
xen/atomic.hwithtypedef struct { int counter; }
atomic_t;
#defineATOMIC_INIT(i){ (i) }and some prototypes such as:
static inline int
atomic_read(const atomic_t *v);would be great, but this looks like it has the possibility to turn into
a rats nest. If it does, then just doubling up this code for arm is ok.Quoted 4 lines
Quoted 1 line
~Andrew
Yes, that might be more complicated than we expect and I don't know if making code such as this common would be a good idea, usually these functions are always architecture-specific.
I only suggested making the prototype common, not the implementation. As such, the issue you accidentally introduced would become a hard build failure on affected architectures, rather than a subtle build failure in common code at some point in the future.
~Andrew
Quoted 7 lines
Quoted 2 lines
Oh, I see, good idea, I've just tested it and it works, what did you have in mind when you said it could cause problems?
The build issues would come at some point later when someone attempts to
atomic_read()a constantatomic_tin common code, when the ARM build would break.~Andrew
Ooh, no, I was asking what you meant when you said "this looks like it has the possibility to turn into a rats nest" in your first message, not the thing about hard build failure..
Zuzu C.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 02/16] x86: fix: make atomic_read() param const
Quoted 37 lines · Corneliu ZUZU
Quoted 36 lines · Andrew Cooper
Quoted 27 lines · Corneliu ZUZU
Quoted 27 lines
Quoted 15 lines
Quoted 15 lines
If you are really feeling up to it, having a common
xen/atomic.hwithtypedef struct { int counter; }
atomic_t;
#defineATOMIC_INIT(i){ (i) }and some prototypes such as:
static inline int
atomic_read(const atomic_t *v);would be great, but this looks like it has the possibility to turn into
a rats nest. If it does, then just doubling up this code for arm is ok.Quoted 5 lines
Quoted 1 line
~Andrew
Yes, that might be more complicated than we expect and I don't know if
making code such as this common would be a good idea, usually these functions are always architecture-specific.I only suggested making the prototype common, not the implementation. As such, the issue you accidentally introduced would become a hard build
failure on affected architectures, rather than a subtle build failure in
common code at some point in the future.Quoted 4 lines
Quoted 2 lines
~Andrew
Oh, I see, good idea, I've just tested it and it works, what did you have in mind when you said it could cause problems?
The build issues would come at some point later when someone attempts to
atomic_read()a constantatomic_tin common code, when the ARM build would break.
Quoted 5 lines
Quoted 1 line
~Andrew
Ooh, no, I was asking what you meant when you said "this looks like it has the possibility to turn into a rats nest" in your first message, not the thing about hard build failure..
Ah. sorry.
You would have to invert all the includes of atomic.h to include <xen/atomic.h> rather than <asm/atomic.h>, and have xen/atomic.h include asm/atomic.h towards the end, such that the common prototypes are first. I just suspect that this might not be completely trivial to untangle (of course, I could also be wrong).
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 02/16] x86: fix: make atomic_read() param const
Quoted 44 lines · Andrew Cooper
Quoted 33 lines · Corneliu ZUZU
Quoted 32 lines · Andrew Cooper
Quoted 31 lines · Corneliu ZUZU
Quoted 20 lines
Quoted 15 lines
Quoted 15 lines
If you are really feeling up to it, having a common
xen/atomic.hwithtypedef struct { int counter; }
atomic_t;
#defineATOMIC_INIT(i){ (i) }and some prototypes such as:
static inline int
atomic_read(const atomic_t *v);would be great, but this looks like it has the possibility to turn into
a rats nest. If it does, then just doubling up this code for arm is ok.Quoted 5 lines
Quoted 1 line
~Andrew
Yes, that might be more complicated than we expect and I don't know if
making code such as this common would be a good idea, usually these functions are always architecture-specific.Quoted 9 lines
I only suggested making the prototype common, not the implementation. As such, the issue you accidentally introduced would become a hard build
failure on affected architectures, rather than a subtle build failure in
common code at some point in the future.~Andrew
Oh, I see, good idea, I've just tested it and it works, what did you have in mind when you said it could cause problems?
Quoted 8 lines
Quoted 5 lines
The build issues would come at some point later when someone attempts to
atomic_read()a constantatomic_tin common code, when the ARM build would break.~Andrew
Ooh, no, I was asking what you meant when you said "this looks like it has the possibility to turn into a rats nest" in your first message, not the thing about hard build failure..
Ah. sorry.
Quoted 7 lines
You would have to invert all the includes of
atomic.hto include <xen/atomic.h> rather than <asm/atomic.h>, and havexen/atomic.hincludeasm/atomic.htowards the end, such that the common prototypes are first. I just suspect that this might not be completely trivial to untangle (of course, I could also be wrong).~Andrew
I did it the other way - included <xen/monitor.h> from <asm/monitor.h>.
Zuzu C.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 3/16 x86/monitor: mechanical renames
In reply to Corneliu ZUZUArch-specific vm-event functions in x86/vm_event.h -e.g. vm_event_init_domain()- don't have an 'arch_' prefix. Apply the same rule for monitor functions - originally the only two monitor functions that had an 'arch_' prefix were arch_monitor_domctl_event() and arch_monitor_domctl_op(), but I gave them that prefix because -they had a counterpart function in common code-, that being monitor_domctl().
Let this also be the rule for future 'arch_' functions additions, and with this patch remove the 'arch_' prefix from the monitor functions that don't have a counterpart in common-code (all but those 2 aforementioned).
--- xen/arch/x86/monitor.c | 4 ++-- xen/common/monitor.c | 4 ++-- xen/common/vm_event.c | 4 ++-- xen/include/asm-arm/monitor.h | 8 +++----- xen/include/asm-x86/monitor.h | 12 ++++++------ 5 files changed, 15 insertions(+), 17 deletions(-)
xen/arch/x86/monitor.c +2 -2
@@ -22,7 +22,7 @@#include <asm/monitor.h> #include <public/vm_event.h> -int arch_monitor_init_domain (struct domain *d) +int monitor_init_domain (struct domain *d) {if ( !d->arch.monitor.msr_bitmap ) d->arch.monitor.msr_bitmap = xzalloc(struct monitor_msr_bitmap);
@@ -33,7 +33,7 @@ int arch_monitor_init_domain(struct domain *d)return 0 ; } -void arch_monitor_cleanup_domain (struct domain *d) +void monitor_cleanup_domain (struct domain *d) {xfree (d->arch.monitor.msr_bitmap);
xen/common/monitor.c +2 -2
@@ -50,12 +50,12 @@ int monitor_domctl(struct domain *d, struct xen_domctl_monitor_op *mop)if (unlikely (mop->event >31 ) )return -EINVAL ;/* Check if event type is available. */ -if (unlikely (!(arch_monitor_get_capabilities (d) & (1U << mop->event))) ) +if (unlikely (!(monitor_get_capabilities (d) & (1U << mop->event))) )return -EOPNOTSUPP ;break ;case XEN_DOMCTL_MONITOR_OP_GET_CAPABILITIES : - mop->event =arch_monitor_get_capabilities (d); + mop->event =monitor_get_capabilities (d);return 0 ;default :
xen/common/vm_event.c +2 -2
@@ -669,7 +669,7 @@ int vm_event_domctl(struct domain *d, xen_domctl_vm_event_op_t *vec, {case XEN_VM_EVENT_ENABLE :/* domain_pause() not required here, see XSA-99 */ - rc =arch_monitor_init_domain (d); + rc =monitor_init_domain (d);if ( rc )break ; rc = vm_event_enable(d, vec, ved, _VPF_mem_access,
@@ -682,7 +682,7 @@ int vm_event_domctl(struct domain *d, xen_domctl_vm_event_op_t *vec, {domain_pause (d); rc =vm_event_disable (d, ved); -arch_monitor_cleanup_domain (d); +monitor_cleanup_domain (d);domain_unpause (d); }break ;
xen/include/asm-arm/monitor.h +3 -5
@@ -46,20 +46,18 @@ int arch_monitor_domctl_event(struct domain *d,return -EOPNOTSUPP ; } -static inline -int arch_monitor_init_domain (struct domain *d) +static inline int monitor_init_domain (struct domain *d) {/* No arch-specific domain initialization on ARM. */ return 0 ; } -static inline -void arch_monitor_cleanup_domain (struct domain *d) +static inline void monitor_cleanup_domain (struct domain *d) {/* No arch-specific domain cleanup on ARM. */ } -static inline uint32_t arch_monitor_get_capabilities (struct domain *d) +static inline uint32_t monitor_get_capabilities (struct domain *d) {uint32_t capabilities =0 ;
xen/include/asm-x86/monitor.h +6 -6
@@ -60,7 +60,10 @@ int arch_monitor_domctl_op(struct domain *d, struct xen_domctl_monitor_op *mop)return rc; } -static inline uint32_t arch_monitor_get_capabilities (struct domain *d) +int arch_monitor_domctl_event (struct domain *d, +struct xen_domctl_monitor_op *mop); + +static inline uint32_t monitor_get_capabilities (struct domain *d) {uint32_t capabilities =0 ;
@@ -84,12 +87,9 @@ static inline uint32_t arch_monitor_get_capabilities(struct domain *d)return capabilities; } -int arch_monitor_domctl_event (struct domain *d, -struct xen_domctl_monitor_op *mop); - -int arch_monitor_init_domain (struct domain *d); +int monitor_init_domain (struct domain *d); -void arch_monitor_cleanup_domain (struct domain *d); +void monitor_cleanup_domain (struct domain *d);bool_t monitored_msr (const struct domain *d,u32 msr);
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 03/16] x86/monitor: mechanical renames
Quoted 6 lines · Corneliu ZUZU
Arch-specific vm-event functions in
x86/vm_event.h-e.g. vm_event_init_domain()- don't have an 'arch_' prefix. Apply the same rule for monitor functions - originally the only two monitor functions that had an 'arch_' prefix werearch_monitor_domctl_event()andarch_monitor_domctl_op(), but I gave them that prefix because -they had a counterpart function in common code-, that beingmonitor_domctl().
This should actually be the other way around - ie adding the arch_ prefix to vm_event functions that lack it. Having the arch_ prefix is helpful to know that the function is dealing with the arch specific structs and not common. Similarly that's why we have the hvm_ prefix for functions in hvm/monitor.
Quoted 4 lines
Let this also be the rule for future '
arch_' functions additions, and with this patch remove the 'arch_' prefix from the monitor functions that don't have a counterpart in common-code (all but those 2 aforementioned).
Even if there are no common counter-parts to the function, the arch_ prefix should remain, so I won't be able to ack this patch.
Tamas
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 03/16] x86/monitor: mechanical renames
Quoted 9 lines · Tamas K Lengyel
Quoted 6 lines · Corneliu ZUZU
Arch-specific vm-event functions in
x86/vm_event.h-e.g. vm_event_init_domain()- don't have an 'arch_' prefix. Apply the same rule for monitor functions - originally the only two monitor functions that had an 'arch_' prefix werearch_monitor_domctl_event()andarch_monitor_domctl_op(), but I gave them that prefix because -they had a counterpart function in common code-, that beingmonitor_domctl().This should actually be the other way around - ie adding the
arch_prefix tovm_eventfunctions that lack it.
Given that the majority of the arch-specific functions called from common-code don't have an 'arch_' prefix unless they have a common counterpart, I was guessing that was the rule. It made sense in my head since I saw in that the intention of avoiding naming conflicts (i.e you can't have monitor_domctl() both on the common-side and on the arch-side, so prepend 'arch_' to the latter). I noticed you guys also 'skip' the prefix when sending patches, so that reinforced my assumption.
Quoted 3 lines
Having the
arch_prefix is
helpful to know that the function is dealing with the arch specific structs and not common.
Personally I don't see much use in 'knowing that the function is dealing with the arch structs' from the call-site and you can tell that from the implementation-site just by looking at the path of its source file. Also, the code is pretty much localized in the arch directory anyway so usually one wouldn't have to go back and forth between common and arch that often. What really bothers me though is always having to read 'arch_' when spelling a function-name and also that it makes the function name longer without much benefit. Your suggestion of adding it to pretty much all functions that make up the interface to common just adds to that headache. :-D
Quoted 2 lines
Similarly that's why we have the
hvm_prefix
for functions in hvm/monitor.
'hvm_' doesn't seem to me more special than 'monitor_', for instance, but maybe that's just me.
Quoted 7 lines
Quoted 3 lines
Let this also be the rule for future '
arch_' functions additions, and with this patch remove the 'arch_' prefix from the monitor functions that don't have a counterpart in common-code (all but those 2 aforementioned).Even if there are no common counter-parts to the function, the
arch_prefix should remain, so I won't be able to ack this patch.Tamas
Having said the above, are you still of the same opinion?
Zuzu.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 03/16] x86/monitor: mechanical renames
Quoted 55 lines · Corneliu ZUZU
Quoted 14 lines · Tamas K Lengyel
Quoted 10 lines · Corneliu ZUZU
Arch-specific vm-event functions in
x86/vm_event.h-e.g. vm_event_init_domain()-
don't have an 'arch_' prefix. Apply the same rule for monitor functions - originally the only two monitor functions that had an 'arch_' prefix werearch_monitor_domctl_event()andarch_monitor_domctl_op(), but I gave them that
prefix because -they had a counterpart function in common code-, that beingmonitor_domctl().Quoted 2 lines
This should actually be the other way around - ie adding the
arch_prefix tovm_eventfunctions that lack it.Given that the majority of the arch-specific functions called from common-code don't have an '
arch_' prefix unless they have a common counterpart, I was guessing that was the rule. It made sense in my head since I saw in that the intention of avoiding naming conflicts (i.e you can't havemonitor_domctl()both on the common-side and on the arch-side, so prepend 'arch_' to the latter). I noticed you guys also 'skip' the prefix when sending patches, so that reinforced my assumption.Quoted 3 lines
Having the
arch_prefix is
helpful to know that the function is dealing with the arch specific structs and not common.Personally I don't see much use in 'knowing that the function is dealing with the arch structs' from the call-site and you can tell that from the implementation-site just by looking at the path of its source file. Also, the code is pretty much localized in the arch directory anyway so usually one wouldn't have to go back and forth between common and arch that often. What really bothers me though is always having to read '
arch_' when spelling a function-name and also that it makes the function name longer without much benefit. Your suggestion of adding it to pretty much all functions that make up the interface to common just adds to that headache. :-DQuoted 2 lines
Similarly that's why we have the
hvm_prefix
for functions in hvm/monitor.'
hvm_' doesn't seem to me more special than 'monitor_', for instance, but maybe that's just me.Quoted 6 lines
Quoted 5 lines
Let this also be the rule for future '
arch_' functions additions, and with this
patch remove the 'arch_' prefix from the monitor functions that don't have a
counterpart in common-code (all but those 2 aforementioned).
Quoted 7 lines
Quoted 4 lines
Even if there are no common counter-parts to the function, the
arch_prefix should remain, so I won't be able to ack this patch.Tamas
Having said the above, are you still of the same opinion?
Yes, I am. While it's not a hard rule to always apply these prefix, it does make sense to have them so I don't see benefit in removing the existing prefixes. Adding arch_ prefix to the ones that don't already have one is optional, I was just pointing out that if you really feel like standardizing the naming convention, that's where I would like things to move towards to.
Tamas
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 03/16] x86/monitor: mechanical renames
Quoted 52 lines · Tamas K Lengyel
Quoted 51 lines · Corneliu ZUZU
Quoted 11 lines · Tamas K Lengyel
Quoted 9 lines · Corneliu ZUZU
Arch-specific vm-event functions in
x86/vm_event.h-e.g. vm_event_init_domain()-
don't have an 'arch_' prefix. Apply the same rule for monitor functions - originally the only two monitor functions that had an 'arch_' prefix werearch_monitor_domctl_event()andarch_monitor_domctl_op(), but I gave them that
prefix because -they had a counterpart function in common code-, that beingmonitor_domctl().Quoted 2 lines
This should actually be the other way around - ie adding the
arch_prefix tovm_eventfunctions that lack it.Given that the majority of the arch-specific functions called from common-code don't have an '
arch_' prefix unless they have a common counterpart, I was guessing that was the rule. It made sense in my head since I saw in that the intention of avoiding naming conflicts (i.e you can't havemonitor_domctl()both on the common-side and on the arch-side, so prepend 'arch_' to the latter). I noticed you guys also 'skip' the prefix when sending patches, so that reinforced my assumption.Quoted 3 lines
Having the
arch_prefix is
helpful to know that the function is dealing with the arch specific structs and not common.Personally I don't see much use in 'knowing that the function is dealing with the arch structs' from the call-site and you can tell that from the implementation-site just by looking at the path of its source file. Also, the code is pretty much localized in the arch directory anyway so usually one wouldn't have to go back and forth between common and arch that often. What really bothers me though is always having to read '
arch_' when spelling a function-name and also that it makes the function name longer without much benefit. Your suggestion of adding it to pretty much all functions that make up the interface to common just adds to that headache. :-DQuoted 2 lines
Similarly that's why we have the
hvm_prefix
for functions in hvm/monitor.'
hvm_' doesn't seem to me more special than 'monitor_', for instance, but maybe that's just me.Quoted 8 lines
Quoted 5 lines
Let this also be the rule for future '
arch_' functions additions, and with this
patch remove the 'arch_' prefix from the monitor functions that don't have a
counterpart in common-code (all but those 2 aforementioned).Even if there are no common counter-parts to the function, the
arch_prefix should remain, so I won't be able to ack this patch.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Tamas
Having said the above, are you still of the same opinion?
Yes, I am. While it's not a hard rule to always apply these prefix, it does make sense to have them so I don't see benefit in removing the existing prefixes.
Well, for one the benefit would be not confusing developers by creating inconsistencies: what's the rule here, i.e. why isn't a function such as alloc_domain_struct prefixed w/ 'arch_' but arch_domain_create is? The reason seems to be the latter having a common counterpart while the former not, at least that's what I see being done all over the code-base. Also, I've done this before and you seemed to agree: https://www.mail-archive.com/xen-devel%40lists.xen.org/msg57617.html (Q1). You also suggested creating arch-specific functions without the prefix: https://www.mail-archive.com/xen-devel%40lists.xen.org/msg57336.html . Why the sudden change of heart?
2ndly and obviously, removing the prefixes would make function names shorter and clearer (e.g. -read- "arch_vm_event_vcpu_unpause" and then read "vm_event_vcpu_unpause").
3rd reason is that adding the prefix to -all- arch-specific functions called from common would mean having a lot new functions with the prefix. I'd read the prefix over and over again and at some point I'd get annoyed and say "ok, ok, it's arch_, I get it; why use this prefix so much again?".
4th reason is that the advantage of telling that the function accesses arch structures is much too little considering that idk, >50% of the codebase is arch-specific, so it doesn't provide much information, this categorization is too broad to deserve a special prefix. Whereas using the prefix only for functions that do have a common counterpart gives you the extra information that the 'operation' is only -partly- arch-specific, i.e. to see the whole picture, look @ the common-side implementation. Keep in mind that we'd also be -losing that information- if we were to apply the 'go with arch_ for all' rule.. (this could be a 5th reason)
Quoted 6 lines
Adding
arch_prefix to the ones that don't already
have one is optional, I was just pointing out that if you really feel like standardizing the naming convention, that's where I would like things to move towards to.Tamas
I don't think I'd say this patch "standardizes the naming convention" but rather "fixes code that doesn't conform to the -already existing- standard naming convention". Above stated reasons explain why I'd rather -not- have this standard go in the direction of adding 'arch_' before a lot of functions.
Finally, I feel like asking for feedback as I don't like to insist when the majority agrees to disagree. Jan & others, what's the rule here and what's your view on this? :-)
Thanks,
Zuzu C.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 03/16] x86/monitor: mechanical renames
Quoted 73 lines · Corneliu ZUZU
Quoted 52 lines · Tamas K Lengyel
Quoted 51 lines · Corneliu ZUZU
Quoted 11 lines · Tamas K Lengyel
Quoted 9 lines · Corneliu ZUZU
Arch-specific vm-event functions in
x86/vm_event.h-e.g. vm_event_init_domain()-
don't have an 'arch_' prefix. Apply the same rule for monitor functions - originally the only two monitor functions that had an 'arch_' prefix werearch_monitor_domctl_event()andarch_monitor_domctl_op(), but I gave them that
prefix because -they had a counterpart function in common code-, that beingmonitor_domctl().Quoted 2 lines
This should actually be the other way around - ie adding the
arch_prefix tovm_eventfunctions that lack it.Given that the majority of the arch-specific functions called from common-code don't have an '
arch_' prefix unless they have a common counterpart, I was guessing that was the rule. It made sense in my head since I saw in that the intention of avoiding naming conflicts (i.e you can't havemonitor_domctl()both on the common-side and on the arch-side, so prepend 'arch_' to the latter). I noticed you guys also 'skip' the prefix when sending patches, so that reinforced my assumption.Quoted 3 lines
Having the
arch_prefix is
helpful to know that the function is dealing with the arch specific structs and not common.Personally I don't see much use in 'knowing that the function is dealing with the arch structs' from the call-site and you can tell that from the implementation-site just by looking at the path of its source file. Also, the code is pretty much localized in the arch directory anyway so usually one wouldn't have to go back and forth between common and arch that often. What really bothers me though is always having to read '
arch_' when spelling a function-name and also that it makes the function name longer without much benefit. Your suggestion of adding it to pretty much all functions that make up the interface to common just adds to that headache. :-DQuoted 2 lines
Similarly that's why we have the
hvm_prefix
for functions in hvm/monitor.'
hvm_' doesn't seem to me more special than 'monitor_', for instance, but maybe that's just me.Quoted 8 lines
Quoted 5 lines
Let this also be the rule for future '
arch_' functions additions, and with this
patch remove the 'arch_' prefix from the monitor functions that don't have a
counterpart in common-code (all but those 2 aforementioned).Even if there are no common counter-parts to the function, the
arch_prefix should remain, so I won't be able to ack this patch.Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Tamas
Having said the above, are you still of the same opinion?
Yes, I am. While it's not a hard rule to always apply these prefix, it does make sense to have them so I don't see benefit in removing the existing prefixes.
Well, for one the benefit would be not confusing developers by creating inconsistencies: what's the rule here, i.e. why isn't a function such as
alloc_domain_structprefixed w/ 'arch_' butarch_domain_createis? The reason seems to be the latter having a common counterpart while the former not, at least that's what I see being done all over the code-base. Also, I've done this before and you seemed to agree: https://www.mail-archive.com/xen-devel%40lists.xen.org/msg57617.html (Q1). You also suggested creating arch-specific functions without the prefix: https://www.mail-archive.com/xen-devel%40lists.xen.org/msg57336.html . Why the sudden change of heart?2ndly and obviously, removing the prefixes would make function names shorter and clearer (e.g. -read- "
arch_vm_event_vcpu_unpause" and then read "vm_event_vcpu_unpause").3rd reason is that adding the prefix to -all- arch-specific functions called from common would mean having a lot new functions with the prefix. I'd read the prefix over and over again and at some point I'd get annoyed and say "ok, ok, it's
arch_, I get it; why use this prefix so much again?".4th reason is that the advantage of telling that the function accesses arch structures is much too little considering that idk, >50% of the codebase is arch-specific, so it doesn't provide much information, this categorization is too broad to deserve a special prefix. Whereas using the prefix only for functions that do have a common counterpart gives you the extra information that the 'operation' is only -partly- arch-specific, i.e. to see the whole picture, look @ the common-side implementation. Keep in mind that we'd also be -losing that information- if we were to apply the 'go with
arch_for all' rule.. (this could be a 5th reason)Quoted 5 lines
Adding
arch_prefix to the ones that don't already
have one is optional, I was just pointing out that if you really feel like standardizing the naming convention, that's where I would like things to move towards to.
Quoted 8 lines
Quoted 1 line
Tamas
I don't think I'd say this patch "standardizes the naming convention" but rather "fixes code that doesn't conform to the -already existing- standard naming convention". Above stated reasons explain why I'd rather -not- have this standard go in the direction of adding '
arch_' before a lot of functions.Finally, I feel like asking for feedback as I don't like to insist when the majority agrees to disagree. Jan & others, what's the rule here and what's your view on this? :-)
Thanks,
Zuzu C.
Can I get some extra feedback on this (Andrew, Stefano, Julien)? :-) (btw, is Jan on vacation?)
Thanks,
Corneliu.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 03/16] x86/monitor: mechanical renames
Quoted 129 lines · Corneliu ZUZU
Quoted 128 lines · Corneliu ZUZU
Quoted 73 lines · Tamas K Lengyel
Quoted 71 lines · Corneliu ZUZU
Quoted 16 lines · Tamas K Lengyel
Quoted 5 lines · Corneliu ZUZU
Arch-specific vm-event functions in
x86/vm_event.h-e.g. vm_event_init_domain()-
don't have an 'arch_' prefix. Apply the same rule for monitor functions -
originally the only two monitor functions that had an 'arch_'Quoted 8 lines
prefix were
arch_monitor_domctl_event()andarch_monitor_domctl_op(), but I gave them
that
prefix because -they had a counterpart function in common code-, that
beingmonitor_domctl().Quoted 2 lines
This should actually be the other way around - ie adding the
arch_prefix tovm_eventfunctions that lack it.Given that the majority of the arch-specific functions called from common-code don't have an '
arch_' prefix unless they have a common counterpart, I was guessing that was the rule. It made sense in my head
since I saw in that the intention of avoiding naming conflicts (i.e you
can't havemonitor_domctl()both on the common-side and on the arch-side, so
prepend 'arch_' to the latter). I noticed you guys also 'skip' the prefix
when sending patches, so that reinforced my assumption.Quoted 3 lines
Having the
arch_prefix is
helpful to know that the function is dealing with the arch specific structs and not common.Personally I don't see much use in 'knowing that the function is dealing
with the arch structs' from the call-site and you can tell that from the
implementation-site just by looking at the path of its source file. Also,
the code is pretty much localized in the arch directory anyway so usually
one wouldn't have to go back and forth between common and arch that often.
What really bothers me though is always having to read 'arch_' when spelling
a function-name and also that it makes the function name longer without much
benefit. Your suggestion of adding it to pretty much all functions that make
up the interface to common just adds to that headache. :-DQuoted 2 lines
Similarly that's why we have the
hvm_prefix
for functions in hvm/monitor.'
hvm_' doesn't seem to me more special than 'monitor_', for instance, but
maybe that's just me.Quoted 10 lines
Quoted 7 lines
Let this also be the rule for future '
arch_' functions additions, and
with this
patch remove the 'arch_' prefix from the monitor functions that don't
have a
counterpart in common-code (all but those 2 aforementioned).Even if there are no common counter-parts to the function, the
arch_prefix should remain, so I won't be able to ack this patch.Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Tamas
Having said the above, are you still of the same opinion?
Yes, I am. While it's not a hard rule to always apply these prefix, it does make sense to have them so I don't see benefit in removing the existing prefixes.
Well, for one the benefit would be not confusing developers by creating inconsistencies: what's the rule here, i.e. why isn't a function such as
alloc_domain_structprefixed w/ 'arch_' butarch_domain_createis? The reason seems to be the latter having a common counterpart while the former not, at least that's what I see being done all over the code-base. Also, I've done this before and you seemed to agree:
https://www.mail-archive.com/xen-devel%40lists.xen.org/msg57617.html
(Q1). You also suggested creating arch-specific functions without the prefix:
https://www.mail-archive.com/xen-devel%40lists.xen.org/msg57336.html
. Why the sudden change of heart?2ndly and obviously, removing the prefixes would make function names shorter and clearer (e.g. -read- "
arch_vm_event_vcpu_unpause" and then read "vm_event_vcpu_unpause").3rd reason is that adding the prefix to -all- arch-specific functions called from common would mean having a lot new functions with the prefix. I'd read the prefix over and over again and at some point I'd get annoyed and say "ok, ok, it's
arch_, I get it; why use this prefix so much again?".4th reason is that the advantage of telling that the function accesses arch structures is much too little considering that idk,
Quoted 1 line
50% of the codebase is arch-specific, so it doesn't provide much
information, this categorization is too broad to deserve a special prefix. Whereas using the prefix only for functions that do have a common counterpart gives you the extra information that the 'operation' is only -partly- arch-specific, i.e. to see the whole picture, look @ the common-side implementation. Keep in mind that we'd also be -losing that information- if we were to apply the 'go with
arch_for all' rule.. (this could be a 5th reason)Quoted 6 lines
Adding
arch_prefix to the ones that don't already
have one is optional, I was just pointing out that if you really feel like standardizing the naming convention, that's where I would like things to move towards to.Tamas
I don't think I'd say this patch "standardizes the naming convention" but rather "fixes code that doesn't conform to the -already existing- standard naming convention". Above stated reasons explain why I'd rather -not- have this standard go in the direction of adding '
arch_' before a lot of functions.
Quoted 8 lines
Quoted 6 lines
Finally, I feel like asking for feedback as I don't like to insist when the majority agrees to disagree. Jan & others, what's the rule here and what's your view on this? :-)
Thanks,
Zuzu C.Can I get some extra feedback on this (Andrew, Stefano, Julien)?
Apologies for the delay.
There is sadly no hard and fast rule. Generally an arch_$FOO() exists when there is also a common $FOO() which does some setup, then passes to arch_$FOO() to do some more architecture specific setup.
One thing that we are currently bad at is having proper distinctions. Common code should never ever poke inside a .arch struct/union, and we should have architecture specific functions to make that happen.
However, I don't think it is wise to insist on an arch_ prefix for every per-arch helper.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 03/16] x86/monitor: mechanical renames
Quoted 128 lines · Andrew Cooper
Quoted 127 lines · Corneliu ZUZU
Quoted 126 lines · Corneliu ZUZU
Quoted 67 lines · Tamas K Lengyel
Quoted 65 lines · Corneliu ZUZU
Quoted 16 lines · Tamas K Lengyel
Quoted 5 lines · Corneliu ZUZU
Arch-specific vm-event functions in
x86/vm_event.h-e.g. vm_event_init_domain()-
don't have an 'arch_' prefix. Apply the same rule for monitor functions -
originally the only two monitor functions that had an 'arch_'Quoted 8 lines
prefix were
arch_monitor_domctl_event()andarch_monitor_domctl_op(), but I gave them
that
prefix because -they had a counterpart function in common code-, that
beingmonitor_domctl().Quoted 2 lines
This should actually be the other way around - ie adding the
arch_prefix tovm_eventfunctions that lack it.Given that the majority of the arch-specific functions called from common-code don't have an '
arch_' prefix unless they have a common counterpart, I was guessing that was the rule. It made sense in my head
since I saw in that the intention of avoiding naming conflicts (i.e you
can't havemonitor_domctl()both on the common-side and on the arch-side, so
prepend 'arch_' to the latter). I noticed you guys also 'skip' the prefix
when sending patches, so that reinforced my assumption.Quoted 3 lines
Having the
arch_prefix is
helpful to know that the function is dealing with the arch specific structs and not common.Personally I don't see much use in 'knowing that the function is dealing
with the arch structs' from the call-site and you can tell that from the
implementation-site just by looking at the path of its source file. Also,
the code is pretty much localized in the arch directory anyway so usually
one wouldn't have to go back and forth between common and arch that often.
What really bothers me though is always having to read 'arch_' when spelling
a function-name and also that it makes the function name longer without much
benefit. Your suggestion of adding it to pretty much all functions that make
up the interface to common just adds to that headache. :-DQuoted 2 lines
Similarly that's why we have the
hvm_prefix
for functions in hvm/monitor.'
hvm_' doesn't seem to me more special than 'monitor_', for instance, but
maybe that's just me.Quoted 7 lines
Quoted 7 lines
Let this also be the rule for future '
arch_' functions additions, and
with this
patch remove the 'arch_' prefix from the monitor functions that don't
have a
counterpart in common-code (all but those 2 aforementioned).Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Even if there are no common counter-parts to the function, the
arch_prefix should remain, so I won't be able to ack this patch.Tamas
Having said the above, are you still of the same opinion?
Yes, I am. While it's not a hard rule to always apply these prefix, it does make sense to have them so I don't see benefit in removing the existing prefixes.
Well, for one the benefit would be not confusing developers by creating inconsistencies: what's the rule here, i.e. why isn't a function such as
alloc_domain_structprefixed w/ 'arch_' butarch_domain_createis? The reason seems to be the latter having a common counterpart while the former not, at least that's what I see being done all over the code-base. Also, I've done this before and you seemed to agree:
https://www.mail-archive.com/xen-devel%40lists.xen.org/msg57617.html
(Q1). You also suggested creating arch-specific functions without the prefix:
https://www.mail-archive.com/xen-devel%40lists.xen.org/msg57336.html
. Why the sudden change of heart?2ndly and obviously, removing the prefixes would make function names shorter and clearer (e.g. -read- "
arch_vm_event_vcpu_unpause" and then read "vm_event_vcpu_unpause").3rd reason is that adding the prefix to -all- arch-specific functions called from common would mean having a lot new functions with the prefix. I'd read the prefix over and over again and at some point I'd get annoyed and say "ok, ok, it's
arch_, I get it; why use this prefix so much again?".4th reason is that the advantage of telling that the function accesses arch structures is much too little considering that idk,
Quoted 1 line
50% of the codebase is arch-specific, so it doesn't provide much
information, this categorization is too broad to deserve a special prefix. Whereas using the prefix only for functions that do have a common counterpart gives you the extra information that the 'operation' is only -partly- arch-specific, i.e. to see the whole picture, look @ the common-side implementation. Keep in mind that we'd also be -losing that information- if we were to apply the 'go with
arch_for all' rule.. (this could be a 5th reason)Quoted 6 lines
Adding
arch_prefix to the ones that don't already
have one is optional, I was just pointing out that if you really feel like standardizing the naming convention, that's where I would like things to move towards to.Tamas
I don't think I'd say this patch "standardizes the naming convention" but rather "fixes code that doesn't conform to the -already existing- standard naming convention". Above stated reasons explain why I'd rather -not- have this standard go in the direction of adding '
arch_' before a lot of functions.Finally, I feel like asking for feedback as I don't like to insist when the majority agrees to disagree. Jan & others, what's the rule here and what's your view on this? :-)
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines
Thanks,
Zuzu C.Can I get some extra feedback on this (Andrew, Stefano, Julien)?
Apologies for the delay.
There is sadly no hard and fast rule. Generally an arch_$FOO() exists when there is also a common $FOO() which does some setup, then passes to arch_$FOO() to do some more architecture specific setup.
Which is then indeed the "unspoken" rule that seemed to be respected throughout the code-base.
Quoted 1 line
One thing that we are currently bad at is having proper distinctions.
Which is why, to also avoid having to go through such back-and-forth discussions, I propose adding this rule in CODING_STYLE. There are, of course, other deviations from it, but doing this would make future deviations less likely and would encourage correcting existing ones.
Quoted 5 lines
Common code should never ever poke inside a .arch struct/union, and we should have architecture specific functions to make that happen.
However, I don't think it is wise to insist on an
arch_prefix for every per-arch helper.
I agree.
Quoted 1 line
~Andrew
Thanks for the feedback!
Corneliu.
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 4/16 x86/monitor: relocate vm_event_register_write_resume() function to monitor code
In reply to Corneliu ZUZUvm_event_register_write_resume is part of the monitor subsystem, relocate and rename appropriately.
--- xen/arch/x86/monitor.c | 38 ++++++++++++++++++++++++++++++++++++++ xen/arch/x86/vm_event.c | 37 ------------------------------------- xen/common/vm_event.c | 2 +- xen/include/asm-arm/monitor.h | 6 ++++++ xen/include/asm-arm/vm_event.h | 6 ------ xen/include/asm-x86/monitor.h | 2 ++ xen/include/asm-x86/vm_event.h | 2 -- 7 files changed, 47 insertions(+), 46 deletions(-)
xen/arch/x86/monitor.c +38 -0
@@ -20,6 +20,7 @@*/ #include <asm/monitor.h> +#include <asm/vm_event.h> #include <public/vm_event.h> int monitor_init_domain (struct domain *d)
@@ -41,6 +42,43 @@ void monitor_cleanup_domain(struct domain *d)memset (&d->monitor,0 ,sizeof (d->monitor)); } +void monitor_ctrlreg_write_resume (struct vcpu *v,vm_event_response_t *rsp) +{ +if ( rsp->flags &VM_EVENT_FLAG_DENY ) + { +struct monitor_write_data *w; + +ASSERT (v->arch.vm_event); + +/* deny flag requires the vCPU to be paused */ +if ( !atomic_read (&v->vm_event_pause_count) ) +return ; + + w = &v->arch.vm_event->write_data; + +switch ( rsp->reason ) + { +case VM_EVENT_REASON_MOV_TO_MSR : + w->do_write.msr =0 ; +break ; +case VM_EVENT_REASON_WRITE_CTRLREG : +switch ( rsp->u.write_ctrlreg.index ) + { +case VM_EVENT_X86_CR0 : + w->do_write.cr0 =0 ; +break ; +case VM_EVENT_X86_CR3 : + w->do_write.cr3 =0 ; +break ; +case VM_EVENT_X86_CR4 : + w->do_write.cr4 =0 ; +break ; + } +break ; + } + } +} +static unsigned long *monitor_bitmap_for_msr (const struct domain *d,u32 *msr) {ASSERT (d->arch.monitor.msr_bitmap && msr);
xen/arch/x86/vm_event.c +0 -37
@@ -66,43 +66,6 @@ void vm_event_toggle_singlestep(struct domain *d, struct vcpu *v)hvm_toggle_singlestep (v); } -void vm_event_register_write_resume (struct vcpu *v,vm_event_response_t *rsp) -{ -if ( rsp->flags &VM_EVENT_FLAG_DENY ) - { -struct monitor_write_data *w; - -ASSERT (v->arch.vm_event); - -/* deny flag requires the vCPU to be paused */ -if ( !atomic_read (&v->vm_event_pause_count) ) -return ; - - w = &v->arch.vm_event->write_data; - -switch ( rsp->reason ) - { -case VM_EVENT_REASON_MOV_TO_MSR : - w->do_write.msr =0 ; -break ; -case VM_EVENT_REASON_WRITE_CTRLREG : -switch ( rsp->u.write_ctrlreg.index ) - { -case VM_EVENT_X86_CR0 : - w->do_write.cr0 =0 ; -break ; -case VM_EVENT_X86_CR3 : - w->do_write.cr3 =0 ; -break ; -case VM_EVENT_X86_CR4 : - w->do_write.cr4 =0 ; -break ; - } -break ; - } - } -} -void vm_event_set_registers (struct vcpu *v,vm_event_response_t *rsp) {ASSERT (atomic_read (&v->vm_event_pause_count));
xen/common/vm_event.c +1 -1
@@ -397,7 +397,7 @@ void vm_event_resume(struct domain *d, struct vm_event_domain *ved)case VM_EVENT_REASON_MOV_TO_MSR :#endif case VM_EVENT_REASON_WRITE_CTRLREG : -vm_event_register_write_resume (v, &rsp); +monitor_ctrlreg_write_resume (v, &rsp);break ;#ifdef CONFIG_HAS_MEM_ACCESS
xen/include/asm-arm/monitor.h +6 -0
@@ -57,6 +57,12 @@ static inline void monitor_cleanup_domain(struct domain *d)/* No arch-specific domain cleanup on ARM. */ } +static inline +void monitor_ctrlreg_write_resume (struct vcpu *v,vm_event_response_t *rsp) +{ +/* Not supported on ARM. */ +} +static inline uint32_t monitor_get_capabilities (struct domain *d) {uint32_t capabilities =0 ;
xen/include/asm-arm/vm_event.h +0 -6
@@ -40,12 +40,6 @@ static inline void vm_event_toggle_singlestep(struct domain *d, struct vcpu *v) }static inline -void vm_event_register_write_resume (struct vcpu *v,vm_event_response_t *rsp) -{ -/* Not supported on ARM. */ -} - -static inline void vm_event_set_registers (struct vcpu *v,vm_event_response_t *rsp) {/* Not supported on ARM. */
xen/include/asm-x86/monitor.h +2 -0
@@ -91,6 +91,8 @@ int monitor_init_domain(struct domain *d);void monitor_cleanup_domain (struct domain *d); +void monitor_ctrlreg_write_resume (struct vcpu *v,vm_event_response_t *rsp); +bool_t monitored_msr (const struct domain *d,u32 msr);#endif /* __ASM_X86_MONITOR_H__ */
xen/include/asm-x86/vm_event.h +0 -2
@@ -37,8 +37,6 @@ void vm_event_cleanup_domain(struct domain *d);void vm_event_toggle_singlestep (struct domain *d,struct vcpu *v); -void vm_event_register_write_resume (struct vcpu *v,vm_event_response_t *rsp); -void vm_event_set_registers (struct vcpu *v,vm_event_response_t *rsp);void vm_event_fill_regs (vm_event_request_t *req);
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 04/16] x86/monitor: relocate vm_event_register_write_resume() function to monitor code
Quoted 19 lines · Corneliu ZUZU
vm_event_register_write_resumeis part of the monitor subsystem, relocate and rename appropriately.Signed-off-by Corneliu ZUZU <[email protected]>--- xen/arch/x86/monitor.c | 38 ++++++++++++++++++++++++++++++++++++++ xen/arch/x86/vm_event.c | 37 ------------------------------------- xen/common/vm_event.c | 2 +- xen/include/asm-arm/monitor.h | 6 ++++++ xen/include/asm-arm/vm_event.h | 6 ------ xen/include/asm-x86/monitor.h | 2 ++ xen/include/asm-x86/vm_event.h | 2 -- 7 files changed, 47 insertions(+), 46 deletions(-)xen/arch/x86/monitor.c +0
-0
xen/arch/x86/monitor.c line 23
Quoted 4 lines
xen/arch/x86/monitor.c +1
-0@@ -20,6 +20,7 @@*/ #include <asm/monitor.h> +#include <asm/vm_event.h>
I'm not sure, is this include necessary?
Tamas
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 04/16] x86/monitor: relocate vm_event_register_write_resume() function to monitor code
Quoted 22 lines · Tamas K Lengyel
Quoted 21 lines · Corneliu ZUZU
vm_event_register_write_resumeis part of the monitor subsystem, relocate and rename appropriately.Signed-off-by Corneliu ZUZU <[email protected]>--- xen/arch/x86/monitor.c | 38 ++++++++++++++++++++++++++++++++++++++ xen/arch/x86/vm_event.c | 37 ------------------------------------- xen/common/vm_event.c | 2 +- xen/include/asm-arm/monitor.h | 6 ++++++ xen/include/asm-arm/vm_event.h | 6 ------ xen/include/asm-x86/monitor.h | 2 ++ xen/include/asm-x86/vm_event.h | 2 -- 7 files changed, 47 insertions(+), 46 deletions(-)xen/arch/x86/monitor.c +0
-0@@ -20,6 +20,7 @@*/
Quoted 6 lines
xen/arch/x86/monitor.c line 23
Quoted 2 lines
xen/arch/x86/monitor.c +1
-0#include <asm/monitor.h> +#include <asm/vm_event.h> I'm not sure, is this include necessary?
Tamas
Yes, otherwise it complains about dereferencing an incomplete-typed pointer (arch_vm_event).
Zuzu.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 5/16 x86/monitor: relocate code more appropriately
In reply to Corneliu ZUZUFor readability:
* Add function monitor_ctrlreg_write_data() (in x86/monitor.c) and separate handling of monitor_write_data there (previously done directly in hvm_do_resume()).
* Separate enabling/disabling of CPU_BASED_CR3_LOAD_EXITING for CR3 monitor vm-events from CR0 node @ vmx_update_guest_cr(v, 0) into newly added function vmx_vm_event_update_cr3_traps(d); also, for a better interface, create generic functions monitor_ctrlreg_adjust_traps() and monitor_ctrlreg_disable_traps() (in x86/monitor.c) which deal with setting/unsetting any traps for cr-write monitor vm-events.
--- xen/arch/x86/hvm/hvm.c | 46 ++++++++++---------------- xen/arch/x86/hvm/vmx/vmx.c | 59 ++++++++++++++++++++++++++++++--- xen/arch/x86/monitor.c | 68 +++++++++++++++++++++++++++++++++++---- xen/include/asm-x86/hvm/vmx/vmx.h | 1 + xen/include/asm-x86/monitor.h | 2 ++ 5 files changed, 135 insertions(+), 41 deletions(-)
xen/arch/x86/hvm/hvm.c +17 -29
@@ -473,8 +473,6 @@ void hvm_do_resume(struct vcpu *v)if (unlikely (v->arch.vm_event) ) { -struct monitor_write_data *w = &v->arch.vm_event->write_data; -if (unlikely (v->arch.vm_event->emulate_flags) ) {enum emul_kind kind =EMUL_KIND_NORMAL ;
@@ -492,29 +490,7 @@ void hvm_do_resume(struct vcpu *v) v->arch.vm_event->emulate_flags =0 ; } -if ( w->do_write.msr ) - { -hvm_msr_write_intercept (w->msr, w->value,0 ); - w->do_write.msr =0 ; - } - -if ( w->do_write.cr0 ) - { -hvm_set_cr0 (w->cr0,0 ); - w->do_write.cr0 =0 ; - } - -if ( w->do_write.cr4 ) - { -hvm_set_cr4 (w->cr4,0 ); - w->do_write.cr4 =0 ; - } - -if ( w->do_write.cr3 ) - { -hvm_set_cr3 (w->cr3,0 ); - w->do_write.cr3 =0 ; - } +monitor_ctrlreg_write_data (v); }/* Inject pending hw/sw trap */
@@ -2204,7 +2180,10 @@ int hvm_set_cr0(unsigned long value, bool_t may_defer)if (hvm_monitor_crX (CR0 , value, old_value) ) { -/* The actual write will occur in hvm_do_resume(), if permitted. */ +/* +* The actual write will occur in monitor_ctrlreg_write_data(), if +* permitted. +*/ v->arch.vm_event->write_data.do_write.cr0 =1 ; v->arch.vm_event->write_data.cr0 = value;
@@ -2306,7 +2285,10 @@ int hvm_set_cr3(unsigned long value, bool_t may_defer)if (hvm_monitor_crX (CR3 , value, old) ) { -/* The actual write will occur in hvm_do_resume(), if permitted. */ +/* +* The actual write will occur in monitor_ctrlreg_write_data(), if +* permitted. +*/ v->arch.vm_event->write_data.do_write.cr3 =1 ; v->arch.vm_event->write_data.cr3 = value;
@@ -2386,7 +2368,10 @@ int hvm_set_cr4(unsigned long value, bool_t may_defer)if (hvm_monitor_crX (CR4 , value, old_cr) ) { -/* The actual write will occur in hvm_do_resume(), if permitted. */ +/* +* The actual write will occur in monitor_ctrlreg_write_data(), if +* permitted. +*/ v->arch.vm_event->write_data.do_write.cr4 =1 ; v->arch.vm_event->write_data.cr4 = value;
@@ -3765,7 +3750,10 @@ int hvm_msr_write_intercept(unsigned int msr, uint64_t msr_content, {ASSERT (v->arch.vm_event); -/* The actual write will occur in hvm_do_resume() (if permitted). */ +/* +* The actual write will occur in monitor_ctrlreg_write_data(), if +* permitted. +*/ v->arch.vm_event->write_data.do_write.msr =1 ; v->arch.vm_event->write_data.msr = msr; v->arch.vm_event->write_data.value = msr_content;
xen/arch/x86/hvm/vmx/vmx.c +54 -5
71 lines not on this page · raw message
xen/arch/x86/monitor.c +61 -7
96 lines not on this page · raw message
xen/include/asm-x86/hvm/vmx/vmx.h +1 -0
@@ -101,6 +101,7 @@ void vmx_update_debug_state(struct vcpu *v);void vmx_update_exception_bitmap (struct vcpu *v);void vmx_update_cpu_exec_control (struct vcpu *v);void vmx_update_secondary_exec_control (struct vcpu *v); +void vmx_vm_event_update_cr3_traps (const struct domain *d);#define POSTED_INTR_ON 0#define POSTED_INTR_SN 1
xen/include/asm-x86/monitor.h +2 -0
@@ -93,6 +93,8 @@ void monitor_cleanup_domain(struct domain *d);void monitor_ctrlreg_write_resume (struct vcpu *v,vm_event_response_t *rsp); +void monitor_ctrlreg_write_data (struct vcpu *v); +bool_t monitored_msr (const struct domain *d,u32 msr);#endif /* __ASM_X86_MONITOR_H__ */
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 05/16] x86/monitor: relocate code more appropriately
This was 2/8 in the old v3-series "x86/vm-event: Adjustments & fixes".
Transferring code-review from "Tian, Kevin <[email protected]>" (July 11, 2016) and responding...
Quoted 131 lines · Corneliu ZUZU
For readability:
* Add function
monitor_ctrlreg_write_data()(inx86/monitor.c) and separate handling ofmonitor_write_datathere (previously done directly inhvm_do_resume()).* Separate enabling/disabling of
CPU_BASED_CR3_LOAD_EXITINGfor CR3 monitor vm-events from CR0 node @vmx_update_guest_cr(v, 0)into newly added functionvmx_vm_event_update_cr3_traps(d); also, for a better interface, create generic functionsmonitor_ctrlreg_adjust_traps()andmonitor_ctrlreg_disable_traps()(inx86/monitor.c) which deal with setting/unsetting any traps for cr-write monitor vm-events.Signed-off-by Corneliu ZUZU <[email protected]>--- xen/arch/x86/hvm/hvm.c | 46 ++++++++++---------------- xen/arch/x86/hvm/vmx/vmx.c | 59 ++++++++++++++++++++++++++++++--- xen/arch/x86/monitor.c | 68 +++++++++++++++++++++++++++++++++++---- xen/include/asm-x86/hvm/vmx/vmx.h | 1 + xen/include/asm-x86/monitor.h | 2 ++ 5 files changed, 135 insertions(+), 41 deletions(-)xen/arch/x86/hvm/hvm.c +17
-29@@ -473,8 +473,6 @@ void hvm_do_resume(struct vcpu *v)if (unlikely (v->arch.vm_event) ) { -struct monitor_write_data *w = &v->arch.vm_event->write_data; -if (unlikely (v->arch.vm_event->emulate_flags) ) {enum emul_kind kind =EMUL_KIND_NORMAL ;@@ -492,29 +490,7 @@ void hvm_do_resume(struct vcpu *v) v->arch.vm_event->emulate_flags =0 ; } -if ( w->do_write.msr ) - { -hvm_msr_write_intercept (w->msr, w->value,0 ); - w->do_write.msr =0 ; - } - -if ( w->do_write.cr0 ) - { -hvm_set_cr0 (w->cr0,0 ); - w->do_write.cr0 =0 ; - } - -if ( w->do_write.cr4 ) - { -hvm_set_cr4 (w->cr4,0 ); - w->do_write.cr4 =0 ; - } - -if ( w->do_write.cr3 ) - { -hvm_set_cr3 (w->cr3,0 ); - w->do_write.cr3 =0 ; - } +monitor_ctrlreg_write_data (v); }/* Inject pending hw/sw trap */ @@ -2204,7 +2180,10 @@ int hvm_set_cr0(unsigned long value, bool_t may_defer)if (hvm_monitor_crX (CR0 , value, old_value) ) { -/* The actual write will occur in hvm_do_resume(), if permitted. */ +/* +* The actual write will occur in monitor_ctrlreg_write_data(), if +* permitted. +*/ v->arch.vm_event->write_data.do_write.cr0 =1 ; v->arch.vm_event->write_data.cr0 = value;@@ -2306,7 +2285,10 @@ int hvm_set_cr3(unsigned long value, bool_t may_defer)if (hvm_monitor_crX (CR3 , value, old) ) { -/* The actual write will occur in hvm_do_resume(), if permitted. */ +/* +* The actual write will occur in monitor_ctrlreg_write_data(), if +* permitted. +*/ v->arch.vm_event->write_data.do_write.cr3 =1 ; v->arch.vm_event->write_data.cr3 = value;@@ -2386,7 +2368,10 @@ int hvm_set_cr4(unsigned long value, bool_t may_defer)if (hvm_monitor_crX (CR4 , value, old_cr) ) { -/* The actual write will occur in hvm_do_resume(), if permitted. */ +/* +* The actual write will occur in monitor_ctrlreg_write_data(), if +* permitted. +*/ v->arch.vm_event->write_data.do_write.cr4 =1 ; v->arch.vm_event->write_data.cr4 = value;@@ -3765,7 +3750,10 @@ int hvm_msr_write_intercept(unsigned int msr, uint64_t msr_content, {ASSERT (v->arch.vm_event); -/* The actual write will occur in hvm_do_resume() (if permitted). */ +/* +* The actual write will occur in monitor_ctrlreg_write_data(), if +* permitted. +*/ v->arch.vm_event->write_data.do_write.msr =1 ; v->arch.vm_event->write_data.msr = msr; v->arch.vm_event->write_data.value = msr_content;xen/arch/x86/hvm/vmx/vmx.c +0
-5@@ -1441,11 +1441,6 @@ static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr)if ( !hvm_paging_enabled (v) && !vmx_unrestricted_guest (v) ) v->arch.hvm_vmx.exec_control |= cr3_ctls; -/* Trap CR3 updates if CR3 memory events are enabled. */ -if ( v->domain->arch.monitor.write_ctrlreg_enabled & -monitor_ctrlreg_bitmask (VM_EVENT_X86_CR3 ) ) - v->arch.hvm_vmx.exec_control |=CPU_BASED_CR3_LOAD_EXITING ; -if ( old_ctls != v->arch.hvm_vmx.exec_control )vmx_update_cpu_exec_control (v); }
xen/arch/x86/hvm/vmx/vmx.c void vmx_vmenter_helper(const struct cpu_user_regs *regs) · line 3902
Quoted 10 lines
xen/arch/x86/hvm/vmx/vmx.c +7
-0@@ -3898,6 +3893,60 @@ void vmx_vmenter_helper(const struct cpu_user_regs *regs) }/* +* Adjusts domain CR3 load-exiting execution control for CR3-write monitor +* vm-event. +*/ +void vmx_vm_event_update_cr3_traps (const struct domain *d) +{ +struct vcpu *v; +struct arch_vmx_struct *avmx;
[Kevin wrote]:
better move to inner later loop.
---
Ack.
xen/arch/x86/hvm/vmx/vmx.c void vmx_vmenter_helper(const struct cpu_user_regs *regs) · line 3907
Quoted 5 lines
xen/arch/x86/hvm/vmx/vmx.c +5
-0+unsigned int cr3_bitmask; +bool_t cr3_vmevent, cr3_ldexit; + +/* Domain must be paused. */ +ASSERT (atomic_read (&d->pause_count));
[Kevin wrote]:
The comment doesn't add more info than the code itself, unless you want to explain the reason why domain must be paused here.
---
Ack, will remove the comment (or explain why the domain is paused: probably because we're writing exec_control of all its vcpus).
Quoted 17 lines
xen/arch/x86/hvm/vmx/vmx.c +17
-0+ +/* Non-hap domains trap CR3 writes unconditionally. */ +if ( !paging_mode_hap (d) ) + { +#ifndef NDEBUG + for_each_vcpu ( d, v ) +ASSERT (v->arch.hvm_vmx.exec_control &CPU_BASED_CR3_LOAD_EXITING ); +#endif +return ; + } + + cr3_bitmask =monitor_ctrlreg_bitmask (VM_EVENT_X86_CR3 ); + cr3_vmevent = !!(d->arch.monitor.write_ctrlreg_enabled & cr3_bitmask); + + for_each_vcpu ( d, v ) + { + avmx = &v->arch.hvm_vmx;
xen/arch/x86/hvm/vmx/vmx.c void vmx_vmenter_helper(const struct cpu_user_regs *regs) · line 3934
Quoted 10 lines
xen/arch/x86/hvm/vmx/vmx.c +10
-0+ cr3_ldexit = !!(avmx->exec_control &CPU_BASED_CR3_LOAD_EXITING ); + +if ( cr3_vmevent == cr3_ldexit ) +continue ; + +/* +* If domain paging is disabled (CR0.PG=0) and +* the domain is not in real-mode, then CR3 load-exiting +* must remain enabled (see vmx_update_guest_cr(v, cr) when cr = 0). +*/
[Kevin wrote]:
Please give the real informative message here instead of asking people to look at other place
---
I only now realized I might have mistakenly assumed something when writing up this function.
I'll amend that in a v2 and consider making this comment clearer (will ask for feedback from you again here before sending v2).
xen/arch/x86/hvm/vmx/vmx.c void vmx_vmenter_helper(const struct cpu_user_regs *regs) · line 3936
Quoted 2 lines
xen/arch/x86/hvm/vmx/vmx.c +2
-0+if ( cr3_ldexit && !hvm_paging_enabled (v) && !vmx_unrestricted_guest (v) ) +continue ;
[Kevin wrote]:
if !cr3_ldexit is not expected to occur in such scenario, is it more strict as below?
if ( !hvm_paging_enabled(v) && !vmx_unrestricted_guest(v) )
{
ASSERT(cr3_ldexit);
continue;
}---
That actually seems to be correct, I thought it was possible to have CR3 load-exiting disabled with the above condition true (by looking @ old the code). I must attentively re-review this entire function so that it preserves the old behavior.
Quoted 28 lines
xen/arch/x86/hvm/vmx/vmx.c +13
-0+ +if ( cr3_vmevent ) + avmx->exec_control |=CPU_BASED_CR3_LOAD_EXITING ; +else + avmx->exec_control &= ~CPU_BASED_CR3_LOAD_EXITING ; + +vmx_vmcs_enter (v); +vmx_update_cpu_exec_control (v); +vmx_vmcs_exit (v); + } +} + +/* * Local variables: * mode: C * c-file-style: "BSD" xen/arch/x86/monitor.c +1
-0@@ -19,10 +19,39 @@* License along with this program; If not, see <http://www.gnu.org/licenses/>. */ +#include <asm/hvm/vmx/vmx.h> #include <asm/monitor.h> #include <asm/vm_event.h> #include <public/vm_event.h>
xen/arch/x86/monitor.c line 35
Quoted 10 lines
xen/arch/x86/monitor.c +9
-0+static inline +void monitor_ctrlreg_adjust_traps (struct domain *d,unsigned int index) +{ +/* For now, VMX only. */ +ASSERT (cpu_has_vmx); + +/* Other CRs than CR3 are always trapped. */ +if (VM_EVENT_X86_CR3 == index ) +vmx_vm_event_update_cr3_traps (d);
[Kevin wrote]:
Please add above into a hvm function instead of directly calling vmx in common file. (other arch can have it unimplemented). Then you don't need change this common code again later when other archs are added
---
This is not common code, it's in arch/x86/monitor.c (?) and currently, as the above ASSERT indicates, only VMX is supported. If in the future support for SVM for example will be added, then the hvm move you suggest must be done (Jan also suggested this). Or, I only now realize, if you guys prefer doing this now I could add a vm_event_update_cr3_traps field in hvm_function_table, but BUG() in the SVM one..
Quoted 99 lines
xen/arch/x86/monitor.c +51
-7+} + +static inline void monitor_ctrlreg_disable_traps (struct domain *d) +{ +unsigned int old = d->arch.monitor.write_ctrlreg_enabled; + + d->arch.monitor.write_ctrlreg_enabled =0 ; + +if ( old ) + { +/* For now, VMX only. */ +ASSERT (cpu_has_vmx); + +/* Was CR3 load-exiting enabled due to monitoring? */ +if ( old &monitor_ctrlreg_bitmask (VM_EVENT_X86_CR3 ) ) +vmx_vm_event_update_cr3_traps (d); + } +} +int monitor_init_domain (struct domain *d) {if ( !d->arch.monitor.msr_bitmap )@@ -38,6 +67,8 @@ void monitor_cleanup_domain(struct domain *d) {xfree (d->arch.monitor.msr_bitmap); +monitor_ctrlreg_disable_traps (d); +memset (&d->arch.monitor,0 ,sizeof (d->arch.monitor));memset (&d->monitor,0 ,sizeof (d->monitor)); }@@ -79,6 +110,35 @@ void monitor_ctrlreg_write_resume(struct vcpu *v, vm_event_response_t *rsp) } } +void monitor_ctrlreg_write_data (struct vcpu *v) +{ +struct monitor_write_data *w = &v->arch.vm_event->write_data; + +if ( w->do_write.msr ) + { +hvm_msr_write_intercept (w->msr, w->value,0 ); + w->do_write.msr =0 ; + } + +if ( w->do_write.cr0 ) + { +hvm_set_cr0 (w->cr0,0 ); + w->do_write.cr0 =0 ; + } + +if ( w->do_write.cr4 ) + { +hvm_set_cr4 (w->cr4,0 ); + w->do_write.cr4 =0 ; + } + +if ( w->do_write.cr3 ) + { +hvm_set_cr3 (w->cr3,0 ); + w->do_write.cr3 =0 ; + } +} +static unsigned long *monitor_bitmap_for_msr (const struct domain *d,u32 *msr) {ASSERT (d->arch.monitor.msr_bitmap && msr);@@ -197,13 +257,7 @@ int arch_monitor_domctl_event(struct domain *d,else ad->monitor.write_ctrlreg_enabled &= ~ctrlreg_bitmask; -if (VM_EVENT_X86_CR3 == mop->u.mov_to_cr.index ) - { -struct vcpu *v; -/* Latches new CR3 mask through CR0 code. */ - for_each_vcpu ( d, v ) -hvm_update_guest_cr (v,0 ); - } +monitor_ctrlreg_adjust_traps (d, mop->u.mov_to_cr.index);domain_unpause (d);xen/include/asm-x86/hvm/vmx/vmx.h +1
-0@@ -101,6 +101,7 @@ void vmx_update_debug_state(struct vcpu *v);void vmx_update_exception_bitmap (struct vcpu *v);void vmx_update_cpu_exec_control (struct vcpu *v);void vmx_update_secondary_exec_control (struct vcpu *v); +void vmx_vm_event_update_cr3_traps (const struct domain *d);#define POSTED_INTR_ON 0#define POSTED_INTR_SN 1xen/include/asm-x86/monitor.h +0
-0
xen/include/asm-x86/monitor.h void monitor_cleanup_domain(struct domain *d); · line 100
Quoted 8 lines
xen/include/asm-x86/monitor.h +2
-0@@ -93,6 +93,8 @@ void monitor_cleanup_domain(struct domain *d);void monitor_ctrlreg_write_resume (struct vcpu *v,vm_event_response_t *rsp); +void monitor_ctrlreg_write_data (struct vcpu *v); +bool_t monitored_msr (const struct domain *d,u32 msr);#endif /* __ASM_X86_MONITOR_H__ */
Thanks,
Zuzu C.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 05/16] x86/monitor: relocate code more appropriately
Quoted 22 lines
From: Corneliu ZUZU [mailto:[email protected]]
Sent: Monday, July 11, 2016 2:19 PMxen/arch/x86/monitor.c line 35
Quoted 10 lines
xen/arch/x86/monitor.c +9
-0+static inline +void monitor_ctrlreg_adjust_traps (struct domain *d,unsigned int index) +{ +/* For now, VMX only. */ +ASSERT (cpu_has_vmx); + +/* Other CRs than CR3 are always trapped. */ +if (VM_EVENT_X86_CR3 == index ) +vmx_vm_event_update_cr3_traps (d);[Kevin wrote]:
Please add above into a hvm function instead of directly calling vmx in common file. (other arch can have it unimplemented). Then you don't need change this common code again later when other archs are added
---
Quoted 8 lines
This is not common code, it's in
arch/x86/monitor.c(?) and currently, as the above ASSERT indicates, only VMX is supported. If in the future support for SVM for example will be added, then the hvm move you suggest must be done (Jan also suggested this).
Or, I only now realize, if you guys prefer doing this now I could add avm_event_update_cr3_trapsfield inhvm_function_table, butBUG()in the SVM one..
The latter is desired. Instead of BUG, it makes more sense to return error on an arch which doesn't register the callback.
Thanks
Kevin
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 05/16] x86/monitor: relocate code more appropriately
Quoted 29 lines · Kevin
Quoted 21 lines
From: Corneliu ZUZU [mailto:[email protected]]
Sent: Monday, July 11, 2016 2:19 PMxen/arch/x86/monitor.c line 35
Quoted 9 lines
xen/arch/x86/monitor.c +9
-0+static inline +void monitor_ctrlreg_adjust_traps (struct domain *d,unsigned int index) +{ +/* For now, VMX only. */ +ASSERT (cpu_has_vmx); + +/* Other CRs than CR3 are always trapped. */ +if (VM_EVENT_X86_CR3 == index ) +vmx_vm_event_update_cr3_traps (d);[Kevin wrote]:
Please add above into a hvm function instead of directly calling vmx in common file. (other arch can have it unimplemented). Then you don't need change this common code again later when other archs are added
---
Quoted 8 lines
This is not common code, it's in
arch/x86/monitor.c(?) and currently, as the above ASSERT indicates, only VMX is supported. If in the future support for SVM for example will be added, then the hvm move you suggest must be done (Jan also suggested this).
Or, I only now realize, if you guys prefer doing this now I could add avm_event_update_cr3_trapsfield inhvm_function_table, butBUG()in the SVM one..
Quoted 5 lines
The latter is desired. Instead of BUG, it makes more sense to return error on an arch which doesn't register the callback.
Thanks
Kevin
Will do.
Thanks,
Zuzu C.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 05/16] x86/monitor: relocate code more appropriately
Quoted 34 lines · Corneliu ZUZU
Quoted 33 lines · Kevin
Quoted 22 lines
From: Corneliu ZUZU [mailto:[email protected]]
Sent: Monday, July 11, 2016 2:19 PMxen/arch/x86/monitor.c line 35
Quoted 10 lines
(quoted diff) +2
-0+static inline +void monitor_ctrlreg_adjust_traps(struct domain *d, unsigned intindex)
xen/arch/x86/monitor.c +7
-0+{ +/* For now, VMX only. */ +ASSERT (cpu_has_vmx); + +/* Other CRs than CR3 are always trapped. */ +if (VM_EVENT_X86_CR3 == index ) +vmx_vm_event_update_cr3_traps (d);[Kevin wrote]:
Please add above into a hvm function instead of directly calling vmx in common file. (other arch can have it unimplemented). Then you don't need change this common code again later when other archs are added
---
Quoted 8 lines
This is not common code, it's in
arch/x86/monitor.c(?) and currently, as the above ASSERT indicates, only VMX is supported. If in the future support for SVM for example will be added, then the hvm move you suggest must be done (Jan also suggested this).
Or, I only now realize, if you guys prefer doing this now I could add avm_event_update_cr3_trapsfield inhvm_function_table, butBUG()in the SVM one..The latter is desired. Instead of BUG, it makes more sense to return error on an arch which doesn't register the callback.
Quoted 7 lines
Quoted 2 lines
Thanks
KevinWill do.
Thanks,
Zuzu C.
I've decided to discard separating CR3 load-exiting handling (i.e. discard vmx_vm_event_update_cr3_traps) entirely since I find that it's complicated to have to handle the bit from 2 different places (vmx_update_guest_cr and arch_monitor_domctl_event).
Normally such a situation is resolved by counting the number of subscribers to the resource (in this case counting the number of 'entities' that want to CR3 load-exiting enabled - i.e. just as we have a vCPU pause_count to count entities that want the vCPU to be paused), but it's just a single bit of a lot more and I don't think the overhead is worth.
Let me know if you disagree and I'm open to suggestions, if you guys have any.
Thanks,
Corneliu.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 6/16 x86/monitor: fix: set msr_bitmap to NULL after xfree
In reply to Corneliu ZUZUFix: set d->arch.monitor.msr_bitmap to NULL after xfree, as the equivalence of it being NULL and xfreed is repeatedly presumed in the codebase. Along with this change, also properly reposition an 'if' targeting the aforementioned msr_bitmap when it is allocated and add likely/unlikely accordingly.
--- xen/arch/x86/monitor.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
xen/arch/x86/monitor.c +6 -4
@@ -54,11 +54,12 @@ static inline void monitor_ctrlreg_disable_traps(struct domain *d)int monitor_init_domain (struct domain *d) { -if ( !d->arch.monitor.msr_bitmap ) +if (likely (!d->arch.monitor.msr_bitmap) ) + { d->arch.monitor.msr_bitmap = xzalloc(struct monitor_msr_bitmap); - -if ( !d->arch.monitor.msr_bitmap ) -return -ENOMEM ; +if (unlikely (!d->arch.monitor.msr_bitmap) ) +return -ENOMEM ; + }return 0 ; }
@@ -66,6 +67,7 @@ int monitor_init_domain(struct domain *d)void monitor_cleanup_domain (struct domain *d) {xfree (d->arch.monitor.msr_bitmap); + d->arch.monitor.msr_bitmap =NULL ;monitor_ctrlreg_disable_traps (d);
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 7/16 x86/vm-event: fix: call cleanup when init fails, to free partial allocs
In reply to Corneliu ZUZUFrom vm_event_init_domain(d), call vm_event_cleanup_domain(d) if per-vcpu allocations failed -at some point- to cleanup partial allocations, if any were done along the way.
Also minor adjustments: add unlikely in if's and add some comments.
--- xen/arch/x86/vm_event.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
xen/arch/x86/vm_event.c +15 -5
@@ -23,20 +23,29 @@/* Implicitly serialized by the domctl lock. */ int vm_event_init_domain (struct domain *d) { +int rc =0 ;struct vcpu *v; +/* Per-vcpu initializations. */ for_each_vcpu ( d, v ) { -if ( v->arch.vm_event ) +if (unlikely (v->arch.vm_event) )continue ; v->arch.vm_event = xzalloc(struct arch_vm_event); - -if ( !v->arch.vm_event ) -return -ENOMEM ; +if (unlikely (!v->arch.vm_event) ) + { + rc = -ENOMEM ; + goto err; + } } -return 0 ; +err: +if (unlikely (rc) ) +/* On fail cleanup whatever resources have been partially allocated. */ +vm_event_cleanup_domain (d); + +return rc; }/*
@@ -47,6 +56,7 @@ void vm_event_cleanup_domain(struct domain *d) {struct vcpu *v; +/* Per-vcpu uninitializations. */ for_each_vcpu ( d, v ) {xfree (v->arch.vm_event);
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 8/16 x86/vm-event: call monitor init & cleanup funcs from respective vm_event funcs
In reply to Corneliu ZUZUFor clarity: do init/cleanup of the vm-events subsystems (e.g. functions monitor_init,cleanup_domain()) from the vm-event_init,cleanup_domain() functions. Done by passing-on the ved param from vm_event_enable,disable() functions down to the vm_event_init,cleanup_domain() functions. This makes it easier to follow the init/cleanup sequences for all vm-events subsystems.
In the process, we also replace the vec param of vm_event_enable() with a port param, since the op/mode fields of vec are already handled before the function is called. This was also done because conceptually it was strange relying on the ved param in vm_event_init,cleanup_domain() to determine the target vm-event subsystem when we already had vec->mode in vm_event_enable().
--- xen/arch/x86/monitor.c | 5 +++++ xen/arch/x86/vm_event.c | 15 ++++++++++++--- xen/common/vm_event.c | 18 +++++++----------- xen/include/asm-arm/vm_event.h | 15 ++++++++++++--- xen/include/asm-x86/vm_event.h | 4 ++-- 5 files changed, 38 insertions(+), 19 deletions(-)
xen/arch/x86/monitor.c +5 -0
@@ -52,6 +52,7 @@ static inline void monitor_ctrlreg_disable_traps(struct domain *d) } } +/* Implicitly serialized by the domctl lock. */ int monitor_init_domain (struct domain *d) {if (likely (!d->arch.monitor.msr_bitmap) )
@@ -64,6 +65,10 @@ int monitor_init_domain(struct domain *d)return 0 ; } +/* +* Implicitly serialized by the domctl lock, +* or on domain cleanup paths only. +*/ void monitor_cleanup_domain (struct domain *d) {xfree (d->arch.monitor.msr_bitmap);
xen/arch/x86/vm_event.c +12 -3
@@ -18,10 +18,11 @@* License along with this program; If not, see <http://www.gnu.org/licenses/>. */ +#include <asm/monitor.h> #include <asm/vm_event.h> /* Implicitly serialized by the domctl lock. */ -int vm_event_init_domain (struct domain *d) +int vm_event_init_domain (struct domain *d,struct vm_event_domain *ved) {int rc =0 ;struct vcpu *v;
@@ -40,10 +41,14 @@ int vm_event_init_domain(struct domain *d) } } +/* Initialize specified subsystem. */ +if ( &d->vm_event->monitor == ved ) + rc =monitor_init_domain (d); + err:if (unlikely (rc) )/* On fail cleanup whatever resources have been partially allocated. */ -vm_event_cleanup_domain (d); +vm_event_cleanup_domain (d, ved);return rc; }
@@ -52,10 +57,14 @@ err:* Implicitly serialized by the domctl lock, * or on domain cleanup paths only. */ -void vm_event_cleanup_domain (struct domain *d) +void vm_event_cleanup_domain (struct domain *d,struct vm_event_domain *ved) {struct vcpu *v; +/* Uninitialize specified subsystem. */ +if ( &d->vm_event->monitor == ved ) +monitor_cleanup_domain (d); +/* Per-vcpu uninitializations. */ for_each_vcpu ( d, v ) {
xen/common/vm_event.c +7 -11
@@ -41,8 +41,8 @@static int vm_event_enable (struct domain *d, -xen_domctl_vm_event_op_t *vec,struct vm_event_domain *ved, +unsigned long xen_port,int pause_flag,int param,xen_event_channel_notification_t notification_fn)
@@ -64,7 +64,7 @@ static int vm_event_enable(vm_event_ring_lock_init (ved);vm_event_ring_lock (ved); - rc =vm_event_init_domain (d); + rc =vm_event_init_domain (d, ved);if ( rc <0 ) goto err;
@@ -83,7 +83,7 @@ static int vm_event_enable(if ( rc <0 ) goto err; - ved->xen_port = vec->port = rc; + ved->xen_port = xen_port = rc;/* Prepare ring buffer */ FRONT_RING_INIT(&ved->front_ring,
@@ -232,7 +232,7 @@ static int vm_event_disable(struct domain *d, struct vm_event_domain *ved)destroy_ring_for_helper (&ved->ring_page, ved->ring_pg_struct); -vm_event_cleanup_domain (d); +vm_event_cleanup_domain (d, ved);vm_event_ring_unlock (ved); }
@@ -630,7 +630,7 @@ int vm_event_domctl(struct domain *d, xen_domctl_vm_event_op_t *vec,break ;/* domain_pause() not required here, see XSA-99 */ - rc =vm_event_enable (d, vec, ved, _VPF_mem_paging, + rc =vm_event_enable (d, ved, vec->port, _VPF_mem_paging,HVM_PARAM_PAGING_RING_PFN , mem_paging_notification); }
@@ -669,10 +669,7 @@ int vm_event_domctl(struct domain *d, xen_domctl_vm_event_op_t *vec, {case XEN_VM_EVENT_ENABLE :/* domain_pause() not required here, see XSA-99 */ - rc =monitor_init_domain (d); -if ( rc ) -break ; - rc =vm_event_enable (d, vec, ved, _VPF_mem_access, + rc =vm_event_enable (d, ved, vec->port, _VPF_mem_access,HVM_PARAM_MONITOR_RING_PFN , monitor_notification);break ;
@@ -682,7 +679,6 @@ int vm_event_domctl(struct domain *d, xen_domctl_vm_event_op_t *vec, {domain_pause (d); rc =vm_event_disable (d, ved); -monitor_cleanup_domain (d);domain_unpause (d); }break ;
@@ -721,7 +717,7 @@ int vm_event_domctl(struct domain *d, xen_domctl_vm_event_op_t *vec,break ;/* domain_pause() not required here, see XSA-99 */ - rc =vm_event_enable (d, vec, ved, _VPF_mem_sharing, + rc =vm_event_enable (d, ved, vec->port, _VPF_mem_sharing,HVM_PARAM_SHARING_RING_PFN , mem_sharing_notification);break ;
xen/include/asm-arm/vm_event.h +12 -3
@@ -23,14 +23,23 @@#include <xen/vm_event.h> #include <public/domctl.h> -static inline int vm_event_init_domain (struct domain *d) +static inline +int vm_event_init_domain (struct domain *d,struct vm_event_domain *ved) { -/* Nothing to do. */ +/* Initialize specified subsystem. */ +if ( &d->vm_event->monitor == ved ) +return monitor_init_domain (d); +return 0 ; } -static inline void vm_event_cleanup_domain (struct domain *d) +static inline +void vm_event_cleanup_domain (struct domain *d,struct vm_event_domain *ved) { +/* Uninitialize specified subsystem. */ +if ( &d->vm_event->monitor == ved ) +monitor_cleanup_domain (d); +memset (&d->monitor,0 ,sizeof (d->monitor)); }
xen/include/asm-x86/vm_event.h +2 -2
@@ -31,9 +31,9 @@ struct arch_vm_event {struct monitor_write_data write_data; }; -int vm_event_init_domain (struct domain *d); +int vm_event_init_domain (struct domain *d,struct vm_event_domain *ved); -void vm_event_cleanup_domain (struct domain *d); +void vm_event_cleanup_domain (struct domain *d,struct vm_event_domain *ved);void vm_event_toggle_singlestep (struct domain *d,struct vcpu *v);
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 9/16 arm/monitor: move d->monitor cleanup to monitor_cleanup_domain()
In reply to Corneliu ZUZUd->monitor is a monitor subsystem resource, clean it up in the proper stub.
--- xen/include/asm-arm/monitor.h | 2 +- xen/include/asm-arm/vm_event.h | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-)
xen/include/asm-arm/monitor.h +1 -1
@@ -54,7 +54,7 @@ static inline int monitor_init_domain(struct domain *d)static inline void monitor_cleanup_domain (struct domain *d) { -/* No arch-specific domain cleanup on ARM. */ +memset (&d->monitor,0 ,sizeof (d->monitor)); } static inline
xen/include/asm-arm/vm_event.h +0 -2
@@ -39,8 +39,6 @@ void vm_event_cleanup_domain(struct domain *d, struct vm_event_domain *ved)/* Uninitialize specified subsystem. */ if ( &d->vm_event->monitor == ved )monitor_cleanup_domain (d); - -memset (&d->monitor,0 ,sizeof (d->monitor)); }static inline void vm_event_toggle_singlestep (struct domain *d,struct vcpu *v)
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 10/16 x86/vm-event: centralize vcpu-destroy cleanup in vm-events code
In reply to Corneliu ZUZUMove vm-event cleanup sequence on vcpu destroyal to vm_event.h along with the other vm-event functions.
--- xen/arch/x86/domain.c | 4 ++-- xen/arch/x86/vm_event.c | 5 +---- xen/include/asm-x86/vm_event.h | 10 ++++++++++ 3 files changed, 13 insertions(+), 6 deletions(-)
xen/arch/x86/domain.c +2 -2
@@ -56,6 +56,7 @@#include <asm/debugreg.h> #include <asm/msr.h> #include <asm/traps.h> +#include <asm/vm_event.h> #include <asm/nmi.h> #include <asm/mce.h> #include <asm/amd.h>
@@ -492,8 +493,7 @@ int vcpu_initialise(struct vcpu *v)void vcpu_destroy (struct vcpu *v) { -xfree (v->arch.vm_event); - v->arch.vm_event =NULL ; +vm_event_cleanup_vcpu_destroy (v);if (is_pv_32bit_vcpu (v) ) {
xen/arch/x86/vm_event.c +1 -4
@@ -67,10 +67,7 @@ void vm_event_cleanup_domain(struct domain *d, struct vm_event_domain *ved)/* Per-vcpu uninitializations. */ for_each_vcpu ( d, v ) - { -xfree (v->arch.vm_event); - v->arch.vm_event =NULL ; - } +vm_event_cleanup_vcpu_destroy (v); d->arch.mem_access_emulate_each_rep =0 ; }
xen/include/asm-x86/vm_event.h +10 -0
@@ -35,6 +35,16 @@ int vm_event_init_domain(struct domain *d, struct vm_event_domain *ved);void vm_event_cleanup_domain (struct domain *d,struct vm_event_domain *ved); +/* Called on vCPU destroy. */ +static inline void vm_event_cleanup_vcpu_destroy (struct vcpu *v) +{ +if (likely (!v->arch.vm_event) ) +return ; + +xfree (v->arch.vm_event); + v->arch.vm_event =NULL ; +} +void vm_event_toggle_singlestep (struct domain *d,struct vcpu *v);void vm_event_set_registers (struct vcpu *v,vm_event_response_t *rsp);
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 11/16 x86/monitor: fix: treat -monitor- properly, as a subsys of the vm-event subsys
In reply to Corneliu ZUZUAs it can be seen looking @ the vm_event_per_domain structure, there are 3 defined vm-event subsystems: share, paging and monitor. In a number of places in the codebase, the monitor vm-events subsystem is mistakenly confounded with the vm-event subsystem as a whole: i.e. it is wrongfully checked if v->arch.vm_event is allocated to determine if the monitor subsystem is initialized.
To fix that, add an 'initialised' bit in d->monitor which will determine if the monitor subsystem is initialised, create an inline stub monitor_domain_initialised() and use that instead where it applies.
--- xen/arch/x86/hvm/emulate.c | 3 ++- xen/arch/x86/hvm/hvm.c | 10 +++++----- xen/arch/x86/monitor.c | 3 +++ xen/include/asm-arm/monitor.h | 3 ++- xen/include/asm-x86/monitor.h | 9 ++++----- xen/include/xen/monitor.h | 11 +++++++---- xen/include/xen/sched.h | 1 + 7 files changed, 24 insertions(+), 16 deletions(-)
xen/arch/x86/hvm/emulate.c +2 -1
@@ -12,6 +12,7 @@#include <xen/config.h> #include <xen/init.h> #include <xen/lib.h> +#include <xen/monitor.h> #include <xen/sched.h> #include <xen/paging.h> #include <xen/trace.h>
@@ -73,7 +74,7 @@ static int set_context_data(void *buffer, unsigned int size) {struct vcpu *curr = current; -if ( curr->arch.vm_event ) +if (unlikely (monitor_domain_initialised (curr->domain)) ) {unsigned int safe_size =min (size, curr->arch.vm_event->emul_read_data.size);
xen/arch/x86/hvm/hvm.c +5 -5
@@ -471,7 +471,7 @@ void hvm_do_resume(struct vcpu *v)if ( !handle_hvm_io_completion (v) )return ; -if (unlikely (v->arch.vm_event) ) +if (unlikely (monitor_domain_initialised (v->domain)) ) {if (unlikely (v->arch.vm_event->emulate_flags) ) {
@@ -2176,7 +2176,7 @@ int hvm_set_cr0(unsigned long value, bool_t may_defer)if ( may_defer &&unlikely (v->domain->arch.monitor.write_ctrlreg_enabled &monitor_ctrlreg_bitmask (VM_EVENT_X86_CR0 )) ) { -ASSERT (v->arch.vm_event); +ASSERT (monitor_domain_initialised (v->domain));if (hvm_monitor_crX (CR0 , value, old_value) ) {
@@ -2281,7 +2281,7 @@ int hvm_set_cr3(unsigned long value, bool_t may_defer)if ( may_defer &&unlikely (v->domain->arch.monitor.write_ctrlreg_enabled &monitor_ctrlreg_bitmask (VM_EVENT_X86_CR3 )) ) { -ASSERT (v->arch.vm_event); +ASSERT (monitor_domain_initialised (v->domain));if (hvm_monitor_crX (CR3 , value, old) ) {
@@ -2364,7 +2364,7 @@ int hvm_set_cr4(unsigned long value, bool_t may_defer)if ( may_defer &&unlikely (v->domain->arch.monitor.write_ctrlreg_enabled &monitor_ctrlreg_bitmask (VM_EVENT_X86_CR4 )) ) { -ASSERT (v->arch.vm_event); +ASSERT (monitor_domain_initialised (v->domain));if (hvm_monitor_crX (CR4 , value, old_cr) ) {
@@ -3748,7 +3748,7 @@ int hvm_msr_write_intercept(unsigned int msr, uint64_t msr_content,if ( may_defer &&unlikely (monitored_msr (v->domain, msr)) ) { -ASSERT (v->arch.vm_event); +ASSERT (monitor_domain_initialised (v->domain));/* * The actual write will occur in monitor_ctrlreg_write_data(), if
xen/arch/x86/monitor.c +3 -0
@@ -62,6 +62,8 @@ int monitor_init_domain(struct domain *d)return -ENOMEM ; } + d->monitor.initialised =1 ; +return 0 ; }
@@ -78,6 +80,7 @@ void monitor_cleanup_domain(struct domain *d)memset (&d->arch.monitor,0 ,sizeof (d->arch.monitor));memset (&d->monitor,0 ,sizeof (d->monitor)); + d->monitor.initialised =0 ; }void monitor_ctrlreg_write_resume (struct vcpu *v,vm_event_response_t *rsp)
xen/include/asm-arm/monitor.h +2 -1
@@ -48,13 +48,14 @@ int arch_monitor_domctl_event(struct domain *d,static inline int monitor_init_domain (struct domain *d) { -/* No arch-specific domain initialization on ARM. */ + d->monitor.initialised =1 ;return 0 ; }static inline void monitor_cleanup_domain (struct domain *d) {memset (&d->monitor,0 ,sizeof (d->monitor)); + d->monitor.initialised =0 ; } static inline
xen/include/asm-x86/monitor.h +4 -5
@@ -22,6 +22,7 @@#ifndef __ASM_X86_MONITOR_H__#define __ASM_X86_MONITOR_H__ +#include <xen/monitor.h> #include <xen/sched.h> #define monitor_ctrlreg_bitmask (ctrlreg_index) (1U << (ctrlreg_index))
@@ -41,11 +42,9 @@ int arch_monitor_domctl_op(struct domain *d, struct xen_domctl_monitor_op *mop) {case XEN_DOMCTL_MONITOR_OP_EMULATE_EACH_REP :domain_pause (d); -/* -* Enabling mem_access_emulate_each_rep without a vm_event subscriber -* is meaningless. -*/ -if ( d->max_vcpus && d->vcpu[0 ] && d->vcpu[0 ]->arch.vm_event ) + +/* Meaningless without a monitor vm-events subscriber. */ +if (likely (monitor_domain_initialised (d)) ) d->arch.mem_access_emulate_each_rep = !!mop->event;else rc = -EINVAL ;
xen/include/xen/monitor.h +7 -4
@@ -22,12 +22,15 @@#ifndef __XEN_MONITOR_H__#define __XEN_MONITOR_H__ -#include <public/vm_event.h> - -struct domain ; -struct xen_domctl_monitor_op ; +#include <xen/sched.h> int monitor_domctl (struct domain *d,struct xen_domctl_monitor_op *op); + +static inline bool_t monitor_domain_initialised (const struct domain *d) +{ +return d->monitor.initialised; +} +void monitor_guest_request (void );int monitor_traps (struct vcpu *v,bool_t sync,vm_event_request_t *req);
xen/include/xen/sched.h +1 -0
@@ -472,6 +472,7 @@ struct domainstruct {unsigned int guest_request_enabled :1 ;unsigned int guest_request_sync :1 ; +unsigned int initialised :1 ; } monitor; };
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 11/16] x86/monitor: fix: treat -monitor- properly, as a subsys of the vm-event subsys
Quoted 14 lines
xen/arch/x86/monitor.c +2
-0@@ -62,6 +62,8 @@ int monitor_init_domain(struct domain *d)return -ENOMEM ; } + d->monitor.initialised =1 ; +return 0 ; }
xen/arch/x86/monitor.c void monitor_cleanup_domain(struct domain *d) · line 83
Quoted 4 lines
xen/arch/x86/monitor.c +1
-0@@ -78,6 +80,7 @@ void monitor_cleanup_domain(struct domain *d)memset (&d->arch.monitor,0 ,sizeof (d->arch.monitor));memset (&d->monitor,0 ,sizeof (d->monitor)); + d->monitor.initialised =0 ;
So d->monitor is already memset to zero above, thus this is not needed here.
Quoted 5 lines
xen/arch/x86/monitor.c +0
-0}void monitor_ctrlreg_write_resume (struct vcpu *v,vm_event_response_t *rsp)xen/include/asm-arm/monitor.h +0
-0
[snip]
Quoted 9 lines
xen/include/xen/monitor.h +0
-1@@ -22,12 +22,15 @@#ifndef __XEN_MONITOR_H__#define __XEN_MONITOR_H__ -#include <public/vm_event.h>
xen/include/xen/monitor.h line 31
Quoted 10 lines
xen/include/xen/monitor.h +5
-3- -struct domain ; -struct xen_domctl_monitor_op ; +#include <xen/sched.h> int monitor_domctl (struct domain *d,struct xen_domctl_monitor_op *op); + +static inline bool_t monitor_domain_initialised (const struct domain *d) +{ +return d->monitor.initialised;
This should be !!d->monitor.initialised.
xen/include/xen/monitor.h line 36
Quoted 5 lines
xen/include/xen/monitor.h +2
-0+} +void monitor_guest_request (void );int monitor_traps (struct vcpu *v,bool_t sync,vm_event_request_t *req);
Cheers,
Tamas
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 11/16] x86/monitor: fix: treat -monitor- properly, as a subsys of the vm-event subsys
Quoted 13 lines · Tamas K Lengyel
Quoted 13 lines
xen/arch/x86/monitor.c +2
-0@@ -62,6 +62,8 @@ int monitor_init_domain(struct domain *d)return -ENOMEM ; } + d->monitor.initialised =1 ; +return 0 ; }
Quoted 6 lines
xen/arch/x86/monitor.c void monitor_cleanup_domain(struct domain *d) · line 83
Quoted 5 lines
xen/arch/x86/monitor.c +1
-0@@ -78,6 +80,7 @@ void monitor_cleanup_domain(struct domain *d)memset (&d->arch.monitor,0 ,sizeof (d->arch.monitor));memset (&d->monitor,0 ,sizeof (d->monitor)); + d->monitor.initialised =0 ;So
d->monitoris already memset to zero above, thus this is not needed here.
Yep.
Quoted 7 lines
Quoted 6 lines
xen/arch/x86/monitor.c +0
-0}void monitor_ctrlreg_write_resume (struct vcpu *v,vm_event_response_t *rsp)xen/include/asm-arm/monitor.h +0
-0[snip]
I keep seeing '[snip]' lately but I don't know what it means.
Quoted 15 lines
Quoted 15 lines
xen/include/xen/monitor.h +1
-4@@ -22,12 +22,15 @@#ifndef __XEN_MONITOR_H__#define __XEN_MONITOR_H__ -#include <public/vm_event.h> - -struct domain ; -struct xen_domctl_monitor_op ; +#include <xen/sched.h>
Quoted 6 lines
xen/include/xen/monitor.h line 31
Quoted 5 lines
xen/include/xen/monitor.h +4
-0int monitor_domctl (struct domain *d,struct xen_domctl_monitor_op *op); + +static inline bool_t monitor_domain_initialised (const struct domain *d) +{ +return d->monitor.initialised;This should be !!d->monitor.initialised.
It's the value of a bit, thus should be 0 or 1. Am I missing something?
Quoted 9 lines
xen/include/xen/monitor.h line 36
Quoted 6 lines
xen/include/xen/monitor.h +2
-0+} +void monitor_guest_request (void );int monitor_traps (struct vcpu *v,bool_t sync,vm_event_request_t *req);Cheers,
Tamas
Thanks,
Zuzu.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 11/16] x86/monitor: fix: treat -monitor- properly, as a subsys of the vm-event subsys
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
xen/include/asm-arm/monitor.h +0
-0[snip]
I keep seeing '[snip]' lately but I don't know what it means.
Placeholder for "I've cut some of your patch content here to shorten the message I'm sending".
Quoted 25 lines
Quoted 16 lines
Quoted 16 lines
xen/include/xen/monitor.h +1
-4@@ -22,12 +22,15 @@#ifndef __XEN_MONITOR_H__#define __XEN_MONITOR_H__ -#include <public/vm_event.h> - -struct domain ; -struct xen_domctl_monitor_op ; +#include <xen/sched.h> Quoted 7 lines
xen/include/xen/monitor.h line 31
Quoted 5 lines
xen/include/xen/monitor.h +4
-0int monitor_domctl (struct domain *d,struct xen_domctl_monitor_op *op); + +static inline bool_t monitor_domain_initialised (const struct domain *d) +{ +return d->monitor.initialised;This should be !!d->monitor.initialised.
Quoted 1 line
It's the value of a bit, thus should be 0 or 1. Am I missing something?
Using a bitfield is effectively doing a bitmask for the bit(s). However, returning the value after applying a bitmask is not necessarily 0/1 (ie. bool_t). For example I ran into problems with this in the past (see
https://lists.xen.org/archives/html/xen-devel/2015-08/msg01948.html).
Tamas
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 11/16] x86/monitor: fix: treat -monitor- properly, as a subsys of the vm-event subsys
Quoted 30 lines · Tamas K Lengyel
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
xen/include/asm-arm/monitor.h +0
-0[snip]
I keep seeing '[snip]' lately but I don't know what it means.
Placeholder for "I've cut some of your patch content here to shorten the message I'm sending".
Quoted 21 lines
Quoted 20 lines
Quoted 9 lines
xen/include/xen/monitor.h +0
-1@@ -22,12 +22,15 @@#ifndef __XEN_MONITOR_H__#define __XEN_MONITOR_H__ -#include <public/vm_event.h> xen/include/xen/monitor.h line 31
Quoted 10 lines
xen/include/xen/monitor.h +5
-3- -struct domain ; -struct xen_domctl_monitor_op ; +#include <xen/sched.h> int monitor_domctl (struct domain *d,struct xen_domctl_monitor_op *op); + +static inline bool_t monitor_domain_initialised (const struct domain *d) +{ +return d->monitor.initialised;This should be !!d->monitor.initialised.
Quoted 8 lines
Quoted 1 line
It's the value of a bit, thus should be 0 or 1. Am I missing something?
Using a bitfield is effectively doing a bitmask for the bit(s). However, returning the value after applying a bitmask is not necessarily 0/1 (ie.
bool_t). For example I ran into problems with this in the past (see
https://lists.xen.org/archives/html/xen-devel/2015-08/msg01948.html).Tamas
The example you provided actually returns a value &-ed with a flag (bitmask), of course it returns either 0 or the flag itself :-). AFAIK a single-bit item in a bitfield (note a -bitfield-, not e.g. an unsigned int &-ed with (1<<x)) will always be either 0 or 1.
Corneliu.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 11/16] x86/monitor: fix: treat -monitor- properly, as a subsys of the vm-event subsys
Quoted 47 lines · Corneliu ZUZU
Quoted 46 lines · Tamas K Lengyel
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
xen/include/asm-arm/monitor.h +0
-0[snip]
I keep seeing '[snip]' lately but I don't know what it means.
Placeholder for "I've cut some of your patch content here to shorten the message I'm sending".
Quoted 25 lines
Quoted 14 lines
Quoted 14 lines
xen/include/xen/monitor.h +1
-4@@ -22,12 +22,15 @@#ifndef __XEN_MONITOR_H__#define __XEN_MONITOR_H__ -#include <public/vm_event.h> - -struct domain ; -struct xen_domctl_monitor_op ; +#include <xen/sched.h> Quoted 9 lines
xen/include/xen/monitor.h line 33
Quoted 7 lines
xen/include/xen/monitor.h +4
-0int monitor_domctl (struct domain *d,struct xen_domctl_monitor_op *op); + +static inline bool_t monitor_domain_initialised (const struct domain *d) +{ +return d->monitor.initialised;This should be !!d->monitor.initialised.
Quoted 1 line
It's the value of a bit, thus should be 0 or 1. Am I missing something?
Using a bitfield is effectively doing a bitmask for the bit(s). However, returning the value after applying a bitmask is not necessarily 0/1 (ie.
bool_t). For example I ran into problems with this in the past (see
https://lists.xen.org/archives/html/xen-devel/2015-08/msg01948.html).
Quoted 8 lines
Quoted 1 line
Tamas
The example you provided actually returns a value &-ed with a flag (bitmask), of course it returns either 0 or the flag itself :-). AFAIK a single-bit item in a bitfield (note a -bitfield-, not e.g. an unsigned int &-ed with (1<<x)) will always be either 0 or 1.
I would assume as well but I'm not actually sure if that's guaranteed or if it's only compiler defined behavior.
Tamas
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 11/16] x86/monitor: fix: treat -monitor- properly, as a subsys of the vm-event subsys
Quoted 48 lines · Tamas K Lengyel
Quoted 40 lines · Corneliu ZUZU
Quoted 39 lines · Tamas K Lengyel
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
xen/include/asm-arm/monitor.h +0
-0[snip]
I keep seeing '[snip]' lately but I don't know what it means.
Placeholder for "I've cut some of your patch content here to shorten the message I'm sending".
Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
xen/include/xen/monitor.h +1
-4@@ -22,12 +22,15 @@#ifndef __XEN_MONITOR_H__#define __XEN_MONITOR_H__ -#include <public/vm_event.h> - -struct domain ; -struct xen_domctl_monitor_op ; +#include <xen/sched.h> Quoted 8 lines
xen/include/xen/monitor.h line 33
Quoted 7 lines
xen/include/xen/monitor.h +4
-0int monitor_domctl (struct domain *d,struct xen_domctl_monitor_op *op); + +static inline bool_t monitor_domain_initialised (const struct domain *d) +{ +return d->monitor.initialised;This should be !!d->monitor.initialised.
Quoted 1 line
It's the value of a bit, thus should be 0 or 1. Am I missing something?
Using a bitfield is effectively doing a bitmask for the bit(s). However, returning the value after applying a bitmask is not necessarily 0/1 (ie.
bool_t). For example I ran into problems with this in the past (see
https://lists.xen.org/archives/html/xen-devel/2015-08/msg01948.html).Quoted 7 lines
Quoted 1 line
Tamas
The example you provided actually returns a value &-ed with a flag (bitmask), of course it returns either 0 or the flag itself :-). AFAIK a single-bit item in a bitfield (note a -bitfield-, not e.g. an unsigned int &-ed with (1<<x)) will always be either 0 or 1.
Quoted 5 lines
I would assume as well but I'm not actually sure if that's guaranteed or if it's only compiler defined behavior.
Tamas
As per http://en.cppreference.com/w/c/language/bit_field .
"The number of bits in a bit field (width) sets the limit to the range of values it can hold"
So if it's width is 1, it can either be 0 or 1.
Corneliu.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 12/16 x86/vm-event: fix: move cleanup of mem_access_emulate_each_rep to monitor stub
In reply to Corneliu ZUZUMove cleanup of mem_access_emulate_each_rep to monitor_cleanup_domain() as the field is part of the monitor subsystem's resources.
--- xen/arch/x86/monitor.c | 3 +++ xen/arch/x86/vm_event.c | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-)
xen/arch/x86/monitor.c +3 -0
@@ -80,6 +80,9 @@ void monitor_cleanup_domain(struct domain *d)memset (&d->arch.monitor,0 ,sizeof (d->arch.monitor));memset (&d->monitor,0 ,sizeof (d->monitor)); + + d->arch.mem_access_emulate_each_rep =0 ; + d->monitor.initialised =0 ; }
xen/arch/x86/vm_event.c +0 -2
@@ -68,8 +68,6 @@ void vm_event_cleanup_domain(struct domain *d, struct vm_event_domain *ved)/* Per-vcpu uninitializations. */ for_each_vcpu ( d, v )vm_event_cleanup_vcpu_destroy (v); - - d->arch.mem_access_emulate_each_rep =0 ; }void vm_event_toggle_singlestep (struct domain *d,struct vcpu *v)
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 13/16 x86/monitor: introduce writes_pending field in monitor_write_data
In reply to Corneliu ZUZUIntroduce writes_pending field in monitor_write_data structure to slightly optimize code @ monitor_write_data(): avoid having to check each bit when -all- bits are zero (which is likely).
--- xen/arch/x86/monitor.c | 3 +++ xen/include/asm-x86/domain.h | 17 +++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-)
xen/arch/x86/monitor.c +3 -0
@@ -127,6 +127,9 @@ void monitor_ctrlreg_write_data(struct vcpu *v) {struct monitor_write_data *w = &v->arch.vm_event->write_data; +if (likely (!w->writes_pending) ) +return ; +if ( w->do_write.msr ) {hvm_msr_write_intercept (w->msr, w->value,0 );
xen/include/asm-x86/domain.h +11 -6
@@ -260,12 +260,17 @@ struct pv_domain };struct monitor_write_data { -struct { -unsigned int msr :1 ; -unsigned int cr0 :1 ; -unsigned int cr3 :1 ; -unsigned int cr4 :1 ; - } do_write; +union { +struct { +unsigned int msr :1 ; +unsigned int cr0 :1 ; +unsigned int cr3 :1 ; +unsigned int cr4 :1 ; + } do_write; + +/* Non-zero when at least one of do_write fields is 1. */ +unsigned int writes_pending; + };uint32_t msr;uint64_t value;
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 14/16 x86/monitor: clarify separation between monitor subsys and vm-event as a whole
In reply to Corneliu ZUZUMove fields in arch_vm_event in a structure called arch_vm_event_monitor and refactor arch_vm_event to only hold a pointer to an instance of the aforementioned.
Done for a number of reasons:
* to make the separation of monitor resources from other vm-event resources clearly visible
* to be able to selectively allocate/free monitor-only resources in monitor init & cleanup stubs
* did _not_ do a v->arch.vm_event -to- v->arch.monitor transformation because we want the guarantee of not occupying more than 1 pointer in arch_vcpu, i.e. if in the future e.g. paging vm-events would need per-vcpu resources, one would make an arch_vm_event_paging structure and add a pointer to an instance of it as a arch_vm_event.paging field, in which case we will still have only 1 pointer (arch_vm_event) consuming memory in arch_vcpu for vm-event resources
Note also that this breaks the old implication 'vm-event initialized -> monitor resources (which were in arch_vm_event) initialized', so 2 extra checks on monitor_domain_initialised() had to be added:
i) in vm_event_resume() before calling monitor_ctrlreg_write_resume(), also an ASSERT in monitor_ctrlreg_write_resume()
ii) in vm_event_resume() before calling mem_access_resume(),
also an ASSERT on that code-path in p2m_mem_access_emulate_check()
Finally, also note that the definition of arch_vm_event had to be moved to asm-x86/domain.h due to a cyclic header dependency it caused between asm-x86/vm_event.h and asm-x86/monitor.h.
--- xen/arch/x86/hvm/emulate.c | 8 +++--- xen/arch/x86/hvm/hvm.c | 31 ++++++++++++------------ xen/arch/x86/mm/p2m.c | 7 ++++-- xen/arch/x86/monitor.c | 55 ++++++++++++++++++++++++++++++++++++------ xen/arch/x86/vm_event.c | 17 +++++++++++-- xen/common/vm_event.c | 17 +++++++++++++ xen/include/asm-x86/domain.h | 15 ++++++++++++ xen/include/asm-x86/monitor.h | 7 ++++++ xen/include/asm-x86/vm_event.h | 13 +++------- 9 files changed, 128 insertions(+), 42 deletions(-)
xen/arch/x86/hvm/emulate.c +4 -4
@@ -76,10 +76,10 @@ static int set_context_data(void *buffer, unsigned int size)if (unlikely (monitor_domain_initialised (curr->domain)) ) { -unsigned int safe_size = -min (size, curr->arch.vm_event->emul_read_data.size); +struct arch_vm_event_monitor *vem = curr->arch.vm_event->monitor; +unsigned int safe_size =min (size, vem->emul_read_data.size); -memcpy (buffer, curr->arch.vm_event->emul_read_data.data, safe_size); +memcpy (buffer, vem->emul_read_data.data, safe_size);memset (buffer + safe_size,0 , size - safe_size);return X86EMUL_OKAY ; }
@@ -524,7 +524,7 @@ static int hvmemul_virtual_to_linear(* vm_event being triggered for repeated writes to a whole page. */ if (unlikely (current->domain->arch.mem_access_emulate_each_rep) && - current->arch.vm_event->emulate_flags !=0 ) + current->arch.vm_event->monitor->emulate_flags !=0 ) max_reps =1 ;/*
xen/arch/x86/hvm/hvm.c +15 -16
@@ -65,7 +65,6 @@#include <asm/altp2m.h> #include <asm/mtrr.h> #include <asm/apic.h> -#include <asm/vm_event.h> #include <public/sched.h> #include <public/hvm/ioreq.h> #include <public/version.h>
@@ -473,21 +472,21 @@ void hvm_do_resume(struct vcpu *v)if (unlikely (monitor_domain_initialised (v->domain)) ) { -if (unlikely (v->arch.vm_event->emulate_flags) ) +struct arch_vm_event_monitor *vem = v->arch.vm_event->monitor; + +if (unlikely (vem->emulate_flags) ) {enum emul_kind kind =EMUL_KIND_NORMAL ; -if ( v->arch.vm_event->emulate_flags & -VM_EVENT_FLAG_SET_EMUL_READ_DATA ) +if ( vem->emulate_flags &VM_EVENT_FLAG_SET_EMUL_READ_DATA ) kind =EMUL_KIND_SET_CONTEXT ; -else if ( v->arch.vm_event->emulate_flags & -VM_EVENT_FLAG_EMULATE_NOWRITE ) +else if ( vem->emulate_flags &VM_EVENT_FLAG_EMULATE_NOWRITE ) kind =EMUL_KIND_NOWRITE ;hvm_mem_access_emulate_one (kind, TRAP_invalid_op,HVM_DELIVER_NO_ERROR_CODE ); - v->arch.vm_event->emulate_flags =0 ; + vem->emulate_flags =0 ; }monitor_ctrlreg_write_data (v);
@@ -2184,8 +2183,8 @@ int hvm_set_cr0(unsigned long value, bool_t may_defer)* The actual write will occur in monitor_ctrlreg_write_data(), if * permitted. */ - v->arch.vm_event->write_data.do_write.cr0 =1 ; - v->arch.vm_event->write_data.cr0 = value; + v->arch.vm_event->monitor->write_data.do_write.cr0 =1 ; + v->arch.vm_event->monitor->write_data.cr0 = value;return X86EMUL_OKAY ; }
@@ -2289,8 +2288,8 @@ int hvm_set_cr3(unsigned long value, bool_t may_defer)* The actual write will occur in monitor_ctrlreg_write_data(), if * permitted. */ - v->arch.vm_event->write_data.do_write.cr3 =1 ; - v->arch.vm_event->write_data.cr3 = value; + v->arch.vm_event->monitor->write_data.do_write.cr3 =1 ; + v->arch.vm_event->monitor->write_data.cr3 = value;return X86EMUL_OKAY ; }
@@ -2372,8 +2371,8 @@ int hvm_set_cr4(unsigned long value, bool_t may_defer)* The actual write will occur in monitor_ctrlreg_write_data(), if * permitted. */ - v->arch.vm_event->write_data.do_write.cr4 =1 ; - v->arch.vm_event->write_data.cr4 = value; + v->arch.vm_event->monitor->write_data.do_write.cr4 =1 ; + v->arch.vm_event->monitor->write_data.cr4 = value;return X86EMUL_OKAY ; }
@@ -3754,9 +3753,9 @@ int hvm_msr_write_intercept(unsigned int msr, uint64_t msr_content,* The actual write will occur in monitor_ctrlreg_write_data(), if * permitted. */ - v->arch.vm_event->write_data.do_write.msr =1 ; - v->arch.vm_event->write_data.msr = msr; - v->arch.vm_event->write_data.value = msr_content; + v->arch.vm_event->monitor->write_data.do_write.msr =1 ; + v->arch.vm_event->monitor->write_data.msr = msr; + v->arch.vm_event->monitor->write_data.value = msr_content;hvm_monitor_msr (msr, msr_content);return X86EMUL_OKAY ;
xen/arch/x86/mm/p2m.c +5 -2
@@ -1591,12 +1591,15 @@ void p2m_mem_paging_resume(struct domain *d, vm_event_response_t *rsp)void p2m_mem_access_emulate_check (struct vcpu *v,const vm_event_response_t *rsp) { +ASSERT (monitor_domain_initialised (v->domain)); +/* Mark vcpu for skipping one instruction upon rescheduling. */ if ( rsp->flags &VM_EVENT_FLAG_EMULATE ) {xenmem_access_t access;bool_t violation =1 ;const struct vm_event_mem_access *data = &rsp->u.mem_access; +struct arch_vm_event_monitor *vem = v->arch.vm_event->monitor;if (p2m_get_mem_access (v->domain,_gfn (data->gfn), &access) ==0 ) {
@@ -1639,10 +1642,10 @@ void p2m_mem_access_emulate_check(struct vcpu *v, } } - v->arch.vm_event->emulate_flags = violation ? rsp->flags :0 ; + vem->emulate_flags = violation ? rsp->flags :0 ;if ( (rsp->flags &VM_EVENT_FLAG_SET_EMUL_READ_DATA ) ) - v->arch.vm_event->emul_read_data = rsp->data.emul_read_data; + vem->emul_read_data = rsp->data.emul_read_data; } }
xen/arch/x86/monitor.c +47 -8
99 lines not on this page · raw message
xen/arch/x86/vm_event.c +15 -2
@@ -65,9 +65,22 @@ void vm_event_cleanup_domain(struct domain *d, struct vm_event_domain *ved)if ( &d->vm_event->monitor == ved )monitor_cleanup_domain (d); -/* Per-vcpu uninitializations. */ +/* +* Per-vCPU: if all resources of all vm-event subsystems were freed, +* also free v->arch.vm_event. +*/ for_each_vcpu ( d, v ) -vm_event_cleanup_vcpu_destroy (v); + { +if (unlikely (!v->arch.vm_event) ) +continue ; + +/* Are there resources of vm-event subsystems left unfreed? */ +if (unlikely (v->arch.vm_event->monitor) ) +continue ; + +xfree (v->arch.vm_event); + v->arch.vm_event =NULL ; + } }void vm_event_toggle_singlestep (struct domain *d,struct vcpu *v)
xen/common/vm_event.c +17 -0
@@ -22,6 +22,7 @@#include <xen/sched.h> #include <xen/event.h> +#include <xen/monitor.h> #include <xen/wait.h> #include <xen/vm_event.h> #include <xen/mem_access.h>
@@ -397,11 +398,27 @@ void vm_event_resume(struct domain *d, struct vm_event_domain *ved)case VM_EVENT_REASON_MOV_TO_MSR :#endif case VM_EVENT_REASON_WRITE_CTRLREG : +if (unlikely (!monitor_domain_initialised (d)) ) + { +printk (XENLOG_G_WARNING "Vm-event monitor subsystem not" +"initialized, cr-write ring response" +"ignored (hint: have you called" +"xc_monitor_enable()?).\n" ); +continue ; + }monitor_ctrlreg_write_resume (v, &rsp);break ;#ifdef CONFIG_HAS_MEM_ACCESS case VM_EVENT_REASON_MEM_ACCESS : +if (unlikely (!monitor_domain_initialised (d)) ) + { +printk (XENLOG_G_WARNING "Vm-event monitor subsystem not" +"initialized, mem-access ring response" +"ignored (hint: have you called" +"xc_monitor_enable()?).\n" ); +continue ; + }mem_access_resume (v, &rsp);break ;#endif
xen/include/asm-x86/domain.h +15 -0
@@ -9,6 +9,7 @@#include <asm/e820.h> #include <asm/mce.h> #include <public/vcpu.h> +#include <public/vm_event.h> #include <public/hvm/hvm_info_table.h> #define has_32bit_shinfo (d) ((d)->arch.has_32bit_shinfo)
@@ -503,6 +504,20 @@ typedef enum __packed {SMAP_CHECK_DISABLED ,/* disable the check */ } smap_check_policy_t; +/* +* Should we emulate the next matching instruction on VCPU resume +* after a vm_event? +*/ +struct arch_vm_event_monitor { +uint32_t emulate_flags; +struct vm_event_emul_read_data emul_read_data; +struct monitor_write_data write_data; +}; + +struct arch_vm_event { +struct arch_vm_event_monitor *monitor; +}; +struct arch_vcpu {/*
xen/include/asm-x86/monitor.h +7 -0
@@ -90,6 +90,13 @@ int monitor_init_domain(struct domain *d);void monitor_cleanup_domain (struct domain *d); +/* Called on vCPU destroy. */ +static inline void monitor_cleanup_vcpu_destroy (struct vcpu *v) +{ +ASSERT (v->arch.vm_event); +xfree (v->arch.vm_event->monitor); +} +void monitor_ctrlreg_write_resume (struct vcpu *v,vm_event_response_t *rsp);void monitor_ctrlreg_write_data (struct vcpu *v);
xen/include/asm-x86/vm_event.h +3 -10
@@ -20,16 +20,7 @@#define __ASM_X86_VM_EVENT_H__#include <xen/sched.h> - -/* -* Should we emulate the next matching instruction on VCPU resume -* after a vm_event? -*/ -struct arch_vm_event { -uint32_t emulate_flags; -struct vm_event_emul_read_data emul_read_data; -struct monitor_write_data write_data; -}; +#include <asm/monitor.h> int vm_event_init_domain (struct domain *d,struct vm_event_domain *ved);
@@ -41,6 +32,8 @@ static inline void vm_event_cleanup_vcpu_destroy(struct vcpu *v)if (likely (!v->arch.vm_event) )return ; +monitor_cleanup_vcpu_destroy (v); +xfree (v->arch.vm_event); v->arch.vm_event =NULL ; }
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 14/16] x86/monitor: clarify separation between monitor subsys and vm-event as a whole
Quoted 13 lines
xen/include/asm-x86/domain.h +1
-0@@ -9,6 +9,7 @@#include <asm/e820.h> #include <asm/mce.h> #include <public/vcpu.h> +#include <public/vm_event.h> #include <public/hvm/hvm_info_table.h> #define has_32bit_shinfo (d) ((d)->arch.has_32bit_shinfo)
xen/include/asm-x86/domain.h typedef enum __packed { · line 511
Quoted 8 lines
xen/include/asm-x86/domain.h +5
-0@@ -503,6 +504,20 @@ typedef enum __packed {SMAP_CHECK_DISABLED ,/* disable the check */ } smap_check_policy_t; +/* +* Should we emulate the next matching instruction on VCPU resume +* after a vm_event? +*/ +struct arch_vm_event_monitor {
This should be named struct arch_vcpu_monitor.
xen/include/asm-x86/domain.h typedef enum __packed { · line 513
Quoted 2 lines
xen/include/asm-x86/domain.h +2
-0+uint32_t emulate_flags; +struct vm_event_emul_read_data emul_read_data;
This should probably get renamed as well at some point to struct monitor_emul_read_data.
xen/include/asm-x86/domain.h typedef enum __packed { · line 519
Quoted 6 lines
xen/include/asm-x86/domain.h +6
-0+struct monitor_write_data write_data; +}; + +struct arch_vm_event { +struct arch_vm_event_monitor *monitor; +};
IMHO there is not much point in defining struct arch_vm_event this way, we could just as well store the pointer to the arch_monitor directly in arch_vcpu as we do right now.
xen/include/asm-x86/domain.h typedef enum __packed { · line 523
Quoted 4 lines
xen/include/asm-x86/domain.h +1
-0+struct arch_vcpu {/*
Tamas
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 14/16] x86/monitor: clarify separation between monitor subsys and vm-event as a whole
Quoted 16 lines · Tamas K Lengyel
Quoted 16 lines
xen/include/asm-x86/domain.h +1
-0@@ -9,6 +9,7 @@#include <asm/e820.h> #include <asm/mce.h> #include <public/vcpu.h> +#include <public/vm_event.h> #include <public/hvm/hvm_info_table.h> #define has_32bit_shinfo (d) ((d)->arch.has_32bit_shinfo)@@ -503,6 +504,20 @@ typedef enum __packed { SMAP_CHECK_DISABLED, /* disable the check */ } smap_check_policy_t;
Quoted 6 lines
xen/include/asm-x86/domain.h typedef enum __packed { · line 511
Quoted 5 lines
xen/include/asm-x86/domain.h +5
-0+/* +* Should we emulate the next matching instruction on VCPU resume +* after a vm_event? +*/ +struct arch_vm_event_monitor {This should be named struct
arch_vcpu_monitor.
Good idea.
Quoted 5 lines
xen/include/asm-x86/domain.h typedef enum __packed { · line 513
Quoted 3 lines
xen/include/asm-x86/domain.h +2
-0+uint32_t emulate_flags; +struct vm_event_emul_read_data emul_read_data;This should probably get renamed as well at some point to struct
monitor_emul_read_data.
Ack.
Quoted 10 lines
xen/include/asm-x86/domain.h typedef enum __packed { · line 519
Quoted 6 lines
xen/include/asm-x86/domain.h +6
-0+struct monitor_write_data write_data; +}; + +struct arch_vm_event { +struct arch_vm_event_monitor *monitor; +};IMHO there is not much point in defining struct
arch_vm_eventthis way, we could just as well store the pointer to thearch_monitordirectly inarch_vcpuas we do right now.
I stated the reason for that in the commit message (see 3rd '*'), Jan insists it would be preferable to occupy just one pointer in arch_vcpu (which would still hold if we do as you suggest but I was wondering how probable would it be in the future for one of the paging/share vm-event subsystems to need per-vCPU resources). But personally, yeah, I would have preferred what you suggest as well..
Zuzu.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 14/16] x86/monitor: clarify separation between monitor subsys and vm-event as a whole
Quoted 45 lines · Corneliu ZUZU
Quoted 16 lines · Tamas K Lengyel
Quoted 16 lines
xen/include/asm-x86/domain.h +1
-0@@ -9,6 +9,7 @@#include <asm/e820.h> #include <asm/mce.h> #include <public/vcpu.h> +#include <public/vm_event.h> #include <public/hvm/hvm_info_table.h> #define has_32bit_shinfo (d) ((d)->arch.has_32bit_shinfo)@@ -503,6 +504,20 @@ typedef enum __packed { SMAP_CHECK_DISABLED, /* disable the check */ } smap_check_policy_t;Quoted 6 lines
xen/include/asm-x86/domain.h typedef enum __packed { · line 511
Quoted 5 lines
xen/include/asm-x86/domain.h +5
-0+/* +* Should we emulate the next matching instruction on VCPU resume +* after a vm_event? +*/ +struct arch_vm_event_monitor {This should be named struct
arch_vcpu_monitor.Good idea.
Quoted 5 lines
xen/include/asm-x86/domain.h typedef enum __packed { · line 513
Quoted 3 lines
xen/include/asm-x86/domain.h +2
-0+uint32_t emulate_flags; +struct vm_event_emul_read_data emul_read_data;This should probably get renamed as well at some point to struct
monitor_emul_read_data.Ack.
Quoted 10 lines
xen/include/asm-x86/domain.h typedef enum __packed { · line 519
Quoted 6 lines
xen/include/asm-x86/domain.h +6
-0+struct monitor_write_data write_data; +}; + +struct arch_vm_event { +struct arch_vm_event_monitor *monitor; +};IMHO there is not much point in defining struct
arch_vm_eventthis way, we could just as well store the pointer to thearch_monitordirectly inarch_vcpuas we do right now.
Quoted 3 lines
I stated the reason for that in the commit message (see 3rd '*'), Jan insists it would be preferable to occupy just one pointer in
arch_vcpu(which would still hold if we do as you suggest but I was wondering how probable would it be in the future for one of the paging/share vm-event subsystems to need per-vCPU resources). But personally, yeah, I would have preferred what you suggest as well..Zuzu.
Tamas, any update on this? Do you think we should think now about per-vCPU resources being occupied in the future by paging/share or leave that for later and do what you suggested?
Thanks,
Corneliu.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH 14/16] x86/monitor: clarify separation between monitor subsys and vm-event as a whole
Quoted 60 lines · Corneliu ZUZU
Quoted 59 lines · Corneliu ZUZU
Quoted 17 lines · Tamas K Lengyel
Quoted 17 lines
xen/include/asm-x86/domain.h +1
-0@@ -9,6 +9,7 @@#include <asm/e820.h> #include <asm/mce.h> #include <public/vcpu.h> +#include <public/vm_event.h> #include <public/hvm/hvm_info_table.h> #define has_32bit_shinfo (d) ((d)->arch.has_32bit_shinfo)@@ -503,6 +504,20 @@ typedef enum __packed { SMAP_CHECK_DISABLED, /* disable the check */ } smap_check_policy_t;Quoted 7 lines
xen/include/asm-x86/domain.h typedef enum __packed { · line 511
Quoted 5 lines
xen/include/asm-x86/domain.h +5
-0+/* +* Should we emulate the next matching instruction on VCPU resume +* after a vm_event? +*/ +struct arch_vm_event_monitor {This should be named struct
arch_vcpu_monitor.Good idea.
Quoted 6 lines
xen/include/asm-x86/domain.h typedef enum __packed { · line 513
Quoted 3 lines
xen/include/asm-x86/domain.h +2
-0+uint32_t emulate_flags; +struct vm_event_emul_read_data emul_read_data;This should probably get renamed as well at some point to struct
monitor_emul_read_data.Ack.
Quoted 11 lines
xen/include/asm-x86/domain.h typedef enum __packed { · line 519
Quoted 6 lines
xen/include/asm-x86/domain.h +6
-0+struct monitor_write_data write_data; +}; + +struct arch_vm_event { +struct arch_vm_event_monitor *monitor; +};IMHO there is not much point in defining struct
arch_vm_eventthis way, we could just as well store the pointer to thearch_monitordirectly inarch_vcpuas we do right now.I stated the reason for that in the commit message (see 3rd '*'), Jan insists it would be preferable to occupy just one pointer in
arch_vcpu(which would still hold if we do as you suggest but I was wondering how probable would it be in the future for one of the paging/share vm-event subsystems to need per-vCPU resources). But personally, yeah, I would have preferred what you suggest as well..
Quoted 6 lines
Quoted 1 line
Zuzu.
Tamas, any update on this? Do you think we should think now about per-vCPU resources being occupied in the future by paging/share or leave that for later and do what you suggested?
It's highly unlikely that either paging or sharing will have any use of this struct in the near future provided but subsystems are pretty much orphaned at this point. If we ever going to need it it's an easy enough adjustment but for now it's not needed.
Tamas
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH 15/16 x86/monitor: fix: don't compromise a monitor_write_data with pending CR writes
In reply to Corneliu ZUZUThe arch_vm_event.monitor structure is dynamically allocated and freed e.g. when the toolstack user calls xc_monitor_disable(), which in turn effectively discards any information that was in arch_vm_event.monitor->write_data.
But this can yield unexpected behavior since if a CR-write was awaiting to be committed (non-zero write_data.writes_pending) on the scheduling tail (hvm_do_resume()->monitor_ctrlreg_write_data()) before xc_monitor_disable() is called, then the domain CR-write is wrongfully ignored, which of course, in these cases, can easily render a domain crash.
To fix the issue, this patch:
* makes arch_vm_event.monitor->emul_read_data dynamically allocated and only frees the entire arch_vm_event.monitor in monitor_cleanup_domain() if there are no pending CR-writes, otherwise it only frees emul_read_data
* if there were pending CR-writes when monitor_cleanup_domain() was called, arch_vm_event.monitor will eventually be freed either after the CR-writes are committed (monitor_ctrlreg_write_data()) or when the domain/vcpu is destroyed
* calls monitor_ctrlreg_write_data() even if the monitor subsystem is not initialized
--- xen/arch/x86/hvm/emulate.c | 4 ++-- xen/arch/x86/hvm/hvm.c | 7 ++++++- xen/arch/x86/mm/p2m.c | 2 +- xen/arch/x86/monitor.c | 49 +++++++++++++++++++++++++++++++++++++++----- xen/include/asm-x86/domain.h | 3 +-- 5 files changed, 54 insertions(+), 11 deletions(-)
xen/arch/x86/hvm/emulate.c +2 -2
@@ -77,9 +77,9 @@ static int set_context_data(void *buffer, unsigned int size)if (unlikely (monitor_domain_initialised (curr->domain)) ) {struct arch_vm_event_monitor *vem = curr->arch.vm_event->monitor; -unsigned int safe_size =min (size, vem->emul_read_data.size); +unsigned int safe_size =min (size, vem->emul_read_data->size); -memcpy (buffer, vem->emul_read_data.data, safe_size); +memcpy (buffer, vem->emul_read_data->data, safe_size);memset (buffer + safe_size,0 , size - safe_size);return X86EMUL_OKAY ; }
xen/arch/x86/hvm/hvm.c +6 -1
@@ -488,9 +488,14 @@ void hvm_do_resume(struct vcpu *v) vem->emulate_flags =0 ; } + } +/* +* Handle pending monitor CR-writes. Note that the monitor subsystem +* might be uninitialized. +*/ +if (unlikely (v->arch.vm_event && v->arch.vm_event->monitor) )monitor_ctrlreg_write_data (v); - }/* Inject pending hw/sw trap */ if ( v->arch.hvm_vcpu.inject_trap.vector !=-1 )
xen/arch/x86/mm/p2m.c +1 -1
@@ -1645,7 +1645,7 @@ void p2m_mem_access_emulate_check(struct vcpu *v, vem->emulate_flags = violation ? rsp->flags :0 ;if ( (rsp->flags &VM_EVENT_FLAG_SET_EMUL_READ_DATA ) ) - vem->emul_read_data = rsp->data.emul_read_data; + *vem->emul_read_data = rsp->data.emul_read_data; } }
xen/arch/x86/monitor.c +44 -5
80 lines not on this page · raw message
xen/include/asm-x86/domain.h +1 -2
@@ -9,7 +9,6 @@#include <asm/e820.h> #include <asm/mce.h> #include <public/vcpu.h> -#include <public/vm_event.h> #include <public/hvm/hvm_info_table.h> #define has_32bit_shinfo (d) ((d)->arch.has_32bit_shinfo)
@@ -510,7 +509,7 @@ typedef enum __packed {*/ struct arch_vm_event_monitor {uint32_t emulate_flags; -struct vm_event_emul_read_data emul_read_data; +struct vm_event_emul_read_data *emul_read_data;struct monitor_write_data write_data; };
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 16/16 x86/monitor: fix: xc_monitor _write_ctrlreg w/o previous _enable must fail
In reply to Corneliu ZUZUEnforce presence of a monitor vm-event subscriber when the toolstack user calls xc_monitor_write_ctrlreg() (XEN_DOMCTL_MONITOR_EVENT_WRITE_CTRLREG domctl). Without this change, "ASSERT(monitor_domain_initialised(v->domain));" @ hvm_set_cr0() and such would fail if the toolstack user calls xc_monitor_write_ctrlreg(...) w/ enable = true, without first calling xc_monitor_enable().
Also adjust returned error code for similar check from -EINVAL to more descriptive -ENODEV (XEN_DOMCTL_MONITOR_OP_EMULATE_EACH_REP).
--- xen/arch/x86/monitor.c | 4 ++++ xen/include/asm-x86/monitor.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-)
xen/arch/x86/monitor.c +4 -0
@@ -324,6 +324,10 @@ int arch_monitor_domctl_event(struct domain *d,unsigned int ctrlreg_bitmask;bool_t old_status; +/* Meaningless without a monitor vm-events subscriber. */ +if (unlikely (!monitor_domain_initialised (d)) ) +return -ENODEV ; +/* sanity check: avoid left-shift undefined behavior */ if (unlikely (mop->u.mov_to_cr.index >31 ) )return -EINVAL ;
xen/include/asm-x86/monitor.h +1 -1
@@ -47,7 +47,7 @@ int arch_monitor_domctl_op(struct domain *d, struct xen_domctl_monitor_op *mop)if (likely (monitor_domain_initialised (d)) ) d->arch.mem_access_emulate_each_rep = !!mop->event;else - rc = -EINVAL ; + rc = -ENODEV ;domain_unpause (d);break ;
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 16/16] x86/monitor: fix: xc_monitor _write_ctrlreg w/o previous _enable must fail
Quoted 36 lines · Corneliu ZUZU
Enforce presence of a monitor vm-event subscriber when the toolstack user calls
xc_monitor_write_ctrlreg()(XEN_DOMCTL_MONITOR_EVENT_WRITE_CTRLREGdomctl). Without this change, "ASSERT(monitor_domain_initialised(v->domain));" @hvm_set_cr0()and such would fail if the toolstack user callsxc_monitor_write_ctrlreg(...)w/ enable = true, without first callingxc_monitor_enable().Also adjust returned error code for similar check from
-EINVALto more descriptive-ENODEV(XEN_DOMCTL_MONITOR_OP_EMULATE_EACH_REP).Signed-off-by Corneliu ZUZU <[email protected]>--- xen/arch/x86/monitor.c | 4 ++++ xen/include/asm-x86/monitor.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-)xen/arch/x86/monitor.c +4
-0@@ -324,6 +324,10 @@ int arch_monitor_domctl_event(struct domain *d,unsigned int ctrlreg_bitmask;bool_t old_status; +/* Meaningless without a monitor vm-events subscriber. */ +if (unlikely (!monitor_domain_initialised (d)) ) +return -ENODEV ; +/* sanity check: avoid left-shift undefined behavior */ if (unlikely (mop->u.mov_to_cr.index >31 ) )return -EINVAL ;xen/include/asm-x86/monitor.h +0
-0
xen/include/asm-x86/monitor.h int arch_monitor_domctl_op(struct domain *d, struct xen_domctl_monitor_op *mop) · line 53
Quoted 8 lines
xen/include/asm-x86/monitor.h +1
-1@@ -47,7 +47,7 @@ int arch_monitor_domctl_op(struct domain *d, struct xen_domctl_monitor_op *mop)if (likely (monitor_domain_initialised (d)) ) d->arch.mem_access_emulate_each_rep = !!mop->event;else - rc = -EINVAL ; + rc = -ENODEV ;domain_unpause (d);break ;
I might have forgotten to think about domain pausing (for all patches), where it needs to be done. I'll leave that for v2 (obviously), I just wanted to let you know in case you guys have feedback on the matter until then.
Zuzu.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
what's the difference between this series and earlier one?
[PATCH v3 0/8] x86/vm-event: Adjustments & fixes
looks you have some patches cross-posted (e.g. 1/16)...
Quoted 62 lines
-----Original Message-----
From: Corneliu ZUZU [mailto:[email protected]]
Sent: Saturday, July 09, 2016 12:12 PM
To: [email protected]
Cc: Andrew Cooper; George Dunlap; Jan Beulich; Julien Grall; Nakajima, Jun; Tian, Kevin; Paul Durrant; Razvan Cojocaru; Stefano Stabellini; Tamas K Lengyel
Subject: [PATCH 00/16] x86/vm-event: numerous adjustments & fixesAdjustments & fixes to the vm-events code, mostly monitor-related. As I hadn't got the time/proper context to test these changes on a real machine, for now please consider them only for review, I'll let you know when and how actual testing went.
Thanks,
Corneliu ZUZU (16):
x86/vmx_update_guest_cr: minor optimization
x86: fix: makeatomic_read()param const
x86/monitor: mechanical renames
x86/monitor: relocatevm_event_register_write_resume()function to
monitor code
x86/monitor: relocate code more appropriately
x86/monitor: fix: setmsr_bitmapto NULL after xfree x86/vm-event: fix: call cleanup when init fails, to free partial
allocs
x86/vm-event: call monitor init & cleanup funcs from respective
vm_eventfuncs
arm/monitor: moved->monitorcleanup tomonitor_cleanup_domain()x86/vm-event: centralize vcpu-destroy cleanup in vm-events code x86/monitor: fix: treat -monitor- properly, as a subsys of the
vm-event subsys
x86/vm-event: fix: move cleanup ofmem_access_emulate_each_repto
monitor stub
x86/monitor: introducewrites_pendingfield inmonitor_write_datax86/monitor: clarify separation between monitor subsys and vm-event as
a whole
x86/monitor: fix: don't compromise amonitor_write_datawith pending
CR writes
x86/monitor: fix:xc_monitor_write_ctrlregw/o previous_enablemust
failxen/arch/x86/domain.c | 4 +- xen/arch/x86/hvm/emulate.c | 11 +- xen/arch/x86/hvm/hvm.c | 92 ++++++++-------- xen/arch/x86/hvm/vmx/vmx.c | 64 +++++++++-- xen/arch/x86/mm/p2m.c | 7 +- xen/arch/x86/monitor.c | 218 +++++++++++++++++++++++++++++++++++--- xen/arch/x86/vm_event.c | 82 +++++++------- xen/common/monitor.c | 4 +- xen/common/vm_event.c | 37 ++++--- xen/include/asm-arm/monitor.h | 17 +-- xen/include/asm-arm/vm_event.h | 21 ++-- xen/include/asm-x86/atomic.h | 4 +- xen/include/asm-x86/domain.h | 31 ++++-- xen/include/asm-x86/hvm/vmx/vmx.h | 1 + xen/include/asm-x86/monitor.h | 32 ++++-- xen/include/asm-x86/vm_event.h | 27 ++--- xen/include/xen/monitor.h | 11 +- xen/include/xen/sched.h | 1 + 18 files changed, 473 insertions(+), 191 deletions(-)
Quoted 2 lines
--
2.5.0
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 35 lines · Kevin
what's the difference between this series and earlier one?
[PATCH v3 0/8] x86/vm-event: Adjustments & fixes
looks you have some patches cross-posted (e.g. 1/16)...
Quoted 28 lines
Corneliu ZUZU (16):
x86/vmx_update_guest_cr: minor optimization
x86: fix: makeatomic_read()param const
x86/monitor: mechanical renames
x86/monitor: relocatevm_event_register_write_resume()function to
monitor code
x86/monitor: relocate code more appropriately
x86/monitor: fix: setmsr_bitmapto NULL after xfree x86/vm-event: fix: call cleanup when init fails, to free partial
allocs
x86/vm-event: call monitor init & cleanup funcs from respective
vm_eventfuncs
arm/monitor: moved->monitorcleanup tomonitor_cleanup_domain()x86/vm-event: centralize vcpu-destroy cleanup in vm-events code x86/monitor: fix: treat -monitor- properly, as a subsys of the
vm-event subsys
x86/vm-event: fix: move cleanup ofmem_access_emulate_each_repto
monitor stub
x86/monitor: introducewrites_pendingfield inmonitor_write_datax86/monitor: clarify separation between monitor subsys and vm-event as
a whole
x86/monitor: fix: don't compromise amonitor_write_datawith pending
CR writes
x86/monitor: fix:xc_monitor_write_ctrlregw/o previous_enablemust
fail--
2.5.0
Hi Kevin,
I'm sorry about the confusion, the _older v3 series is superseded by this 16-patches one_. I thought the latter was too complex to consider as a v4 over the former, but I should have at least stated something to lead you guys to that conclusion (and to specify changes..). The patches that are still in this series from the older one, the changes and the acks are as following:
- P 1/16, was 1/8 in v3
* changed since v3: nothing
* acked-by in old v3: Acked-by: Kevin Tian <[email protected]>
- P 5/16, was 2/8 in v3
* changed since v3:
- title slightly changed
- renames due to 3/16:
arch_monitor_write_data()->monitor_ctrlreg_write_data(), write_ctrlreg_adjust_traps()->monitor_ctrlreg_adjust_traps(), write_ctrlreg_disable_traps()->monitor_ctrlreg_disable_traps()
- added 'const' attribute to "struct *domain" param ofvmx_vm_event_update_cr3_traps
- 'index' param of monitor_ctrlreg_adjust_traps now of type
'unsigned int'
* acked-by in old v3: no-one
- P 15/16, was 3/8 in v3:
* changed since v3 (IMO changes are too many and depends on
previous patches in this 16-p-series and it would be better if the old v3 one is simply forgotten-about):
- separated fields in arch_vm_event in another structure andarch_vm_event only holds a pointer to that struct (arch_vm_event->monitor->...) - see 14/16 for details
- arch_vm_event.monitor freed entirely when the pending writes
are committed (monitor_ctrlreg_write_data()) or when the domain/vcpu is destroyed
* acked-by in old v3: no-one
- P 16/16, was 4/8 in v3:
* changed since v3: use ENODEV error code instead of ENOSYS
* acked-by in old v3: no-one
The rest of patches in v3 (P5-P8) already made it to staging.
Sorry again and thanks,
Zuzu C.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Thanks for explanation. It makes sense then.
From: Corneliu ZUZU [mailto:[email protected]]
Sent: Monday, July 11, 2016 1:32 PM
To: Tian, Kevin; [email protected]
Cc: Andrew Cooper; George Dunlap; Jan Beulich; Julien Grall; Nakajima, Jun; Paul Durrant; Razvan Cojocaru; Stefano Stabellini; Tamas K Lengyel
Subject: Re: [PATCH 00/16] x86/vm-event: numerous adjustments & fixes
On 7/11/2016 5:54 AM, Tian, Kevin wrote:
what's the difference between this series and earlier one?
[PATCH v3 0/8] x86/vm-event: Adjustments & fixes
looks you have some patches cross-posted (e.g. 1/16)...
Corneliu ZUZU (16):
x86/vmx_update_guest_cr: minor optimization
x86: fix: make atomic_read() param const
x86/monitor: mechanical renames
x86/monitor: relocate vm_event_register_write_resume() function to
monitor code
x86/monitor: relocate code more appropriately
x86/monitor: fix: set msr_bitmap to NULL after xfree
x86/vm-event: fix: call cleanup when init fails, to free partial
allocs
x86/vm-event: call monitor init & cleanup funcs from respective
vm_event funcs
arm/monitor: move d->monitor cleanup to monitor_cleanup_domain()
x86/vm-event: centralize vcpu-destroy cleanup in vm-events code
x86/monitor: fix: treat -monitor- properly, as a subsys of the
vm-event subsys
x86/vm-event: fix: move cleanup of mem_access_emulate_each_rep to
monitor stub
x86/monitor: introduce writes_pending field in monitor_write_data
x86/monitor: clarify separation between monitor subsys and vm-event as
a whole
x86/monitor: fix: don't compromise a monitor_write_data with pending
CR writes
x86/monitor: fix: xc_monitor _write_ctrlreg w/o previous _enable must
fail
--
2.5.0
Hi Kevin,
I'm sorry about the confusion, the _older v3 series is superseded by this 16-patches one_. I thought the latter was too complex to consider as a v4 over the former, but I should have at least stated something to lead you guys to that conclusion (and to specify changes..). The patches that are still in this series from the older one, the changes and the acks are as following:
- P 1/16, was 1/8 in v3
* changed since v3: nothing
* acked-by in old v3: Acked-by: Kevin Tian <[email protected]><mailto:[email protected]>
- P 5/16, was 2/8 in v3
* changed since v3:
- title slightly changed
- renames due to 3/16: arch_monitor_write_data()->monitor_ctrlreg_write_data(), write_ctrlreg_adjust_traps()->monitor_ctrlreg_adjust_traps(), write_ctrlreg_disable_traps()->monitor_ctrlreg_disable_traps()
- added 'const' attribute to "struct *domain" param of vmx_vm_event_update_cr3_traps
- 'index' param of monitor_ctrlreg_adjust_traps now of type 'unsigned int'
* acked-by in old v3: no-one
- P 15/16, was 3/8 in v3:
* changed since v3 (IMO changes are too many and depends on previous patches in this 16-p-series and it would be better if the old v3 one is simply forgotten-about):
- separated fields in arch_vm_event in another structure and arch_vm_event only holds a pointer to that struct (arch_vm_event->monitor->...) - see 14/16 for details
- arch_vm_event.monitor freed entirely when the pending writes are committed (monitor_ctrlreg_write_data()) or when the domain/vcpu is destroyed
* acked-by in old v3: no-one
- P 16/16, was 4/8 in v3:
* changed since v3: use ENODEV error code instead of ENOSYS
* acked-by in old v3: no-one
The rest of patches in v3 (P5-P8) already made it to staging.
Sorry again and thanks,
Zuzu C.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel