Skip to contentSkip to conversation

x86/monitor: Disallow setting mem_access_emulate_each_rep when vm_event is NULL

PATCH In review Razvan Cojocaru 4 participants 6 messages Apr 9, 2016 – May 3, 2016

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 x86/monitor: Disallow setting mem_access_emulate_each_rep when vm_event is NULL

It is meaningless (and potentially dangerous - see hvmemul_virtual_to_linear()) to set mem_access_emulate_each_rep before xc_monitor_enable() (which allocates vcpu->arch.vm_event) has been called, so return an error from the XEN_DOMCTL_MONITOR_OP_EMULATE_EACH_REP hypercall when that is the case.

---
Changes since V2:
- Updated the if() condition as recommended by Andrew Cooper.
- Added Andrew Cooper's Reviewed-by.

---
 xen/include/asm-x86/monitor.h | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
xen/include/asm-x86/monitor.h +13 -3
index 0954b59..d367099 100644
@@ -32,19 +32,29 @@
 static inline
 int arch_monitor_domctl_op(struct domain *d, struct xen_domctl_monitor_op *mop)
 {
+    int rc = 0;
+
     switch ( mop->op )
     {
     case XEN_DOMCTL_MONITOR_OP_EMULATE_EACH_REP:
         domain_pause(d);
-        d->arch.mem_access_emulate_each_rep = !!mop->event;
+        /*
+         * 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 )
+            d->arch.mem_access_emulate_each_rep = !!mop->event;
+        else
+            rc = -EINVAL;
+
         domain_unpause(d);
         break;
 
     default:
-        return -EOPNOTSUPP;
+        rc = -EOPNOTSUPP;
     }
 
-    return 0;
+    return rc;
 }
 
 int arch_monitor_domctl_event(struct domain *d,
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#1 lore raw
Quoted 43 lines · Razvan Cojocaru

It is meaningless (and potentially dangerous - see hvmemul_virtual_to_linear()) to set mem_access_emulate_each_rep before xc_monitor_enable() (which allocates vcpu->arch.vm_event) has been called, so return an error from the XEN_DOMCTL_MONITOR_OP_EMULATE_EACH_REP hypercall when that is the case.

---
Changes since V2:
- Updated the if() condition as recommended by Andrew Cooper.
- Added Andrew Cooper's Reviewed-by.

---
 xen/include/asm-x86/monitor.h | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
xen/include/asm-x86/monitor.h +11 -1
index 0954b59..d367099 100644
@@ -32,19 +32,29 @@
 static inline
 int arch_monitor_domctl_op(struct domain *d, struct xen_domctl_monitor_op *mop)
 {
+    int rc = 0;
+
     switch ( mop->op )
     {
     case XEN_DOMCTL_MONITOR_OP_EMULATE_EACH_REP:
         domain_pause(d);
-        d->arch.mem_access_emulate_each_rep = !!mop->event;
+        /*
+         * 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 )
+            d->arch.mem_access_emulate_each_rep = !!mop->event;
+        else
+            rc = -EINVAL;
+
         domain_unpause(d);
         break;
 

xen/include/asm-x86/monitor.h line 60

Quoted 10 lines
xen/include/asm-x86/monitor.h +2 -2
     default:
-        return -EOPNOTSUPP;
+        rc = -EOPNOTSUPP;
     }
 
-    return 0;
+    return rc;
 }
 
 int arch_monitor_domctl_event(struct domain *d,

Hello,

According to the previous list discussion with Andrew Cooper, this fix might be considered for the 4.7 release, so CC-ing Wei for a release ack, as suggested.

Thanks,
Razvan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#2 lore raw
Quoted 8 lines · Razvan Cojocaru
Quoted 7 lines · Razvan Cojocaru

It is meaningless (and potentially dangerous - see hvmemul_virtual_to_linear()) to set mem_access_emulate_each_rep before xc_monitor_enable() (which allocates vcpu->arch.vm_event) has been called, so return an error from the XEN_DOMCTL_MONITOR_OP_EMULATE_EACH_REP hypercall when that is the case.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw
In reply to Razvan Cojocaru
Quoted 54 lines
Quoted 1 line
Quoted 1 line · On 29.04.16 at 18:12, <[email protected]> wrote:
Quoted 52 lines · Razvan Cojocaru

It is meaningless (and potentially dangerous - see hvmemul_virtual_to_linear()) to set mem_access_emulate_each_rep before xc_monitor_enable() (which allocates vcpu->arch.vm_event) has been called, so return an error from the XEN_DOMCTL_MONITOR_OP_EMULATE_EACH_REP hypercall when that is the case.

---
Changes since V2:
- Updated the if() condition as recommended by Andrew Cooper.
- Added Andrew Cooper's Reviewed-by.

---
 xen/include/asm-x86/monitor.h | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
xen/include/asm-x86/monitor.h +13 -3
index 0954b59..d367099 100644
@@ -32,19 +32,29 @@
 static inline
 int arch_monitor_domctl_op(struct domain *d, struct xen_domctl_monitor_op *mop)
 {
+    int rc = 0;
+
     switch ( mop->op )
     {
     case XEN_DOMCTL_MONITOR_OP_EMULATE_EACH_REP:
         domain_pause(d);
-        d->arch.mem_access_emulate_each_rep = !!mop->event;
+        /*
+         * 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 )
+            d->arch.mem_access_emulate_each_rep = !!mop->event;
+        else
+            rc = -EINVAL;
+
         domain_unpause(d);
         break;
 
     default:
-        return -EOPNOTSUPP;
+        rc = -EOPNOTSUPP;
     }
 
-    return 0;
+    return rc;
 }
 
Quoted 5 lines

xen/include/asm-x86/monitor.h line 60

Quoted 1 line
xen/include/asm-x86/monitor.h +0 -0
 int arch_monitor_domctl_event(struct domain *d,

According to the previous list discussion with Andrew Cooper, this fix might be considered for the 4.7 release, so CC-ing Wei for a release ack, as suggested.

Even if - without the pending ./MAINTAINERS adjustment - not formally required, I don't understand why you didn't Cc Tamas on this patch. I don't think this should go in without his ack.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#4 lore raw
Quoted 60 lines · Jan Beulich
Quoted 54 lines
Quoted 1 line
Quoted 1 line · On 29.04.16 at 18:12, <[email protected]> wrote:
Quoted 52 lines · Razvan Cojocaru

It is meaningless (and potentially dangerous - see hvmemul_virtual_to_linear()) to set mem_access_emulate_each_rep before xc_monitor_enable() (which allocates vcpu->arch.vm_event) has been called, so return an error from the XEN_DOMCTL_MONITOR_OP_EMULATE_EACH_REP hypercall when that is the case.

---
Changes since V2:
- Updated the if() condition as recommended by Andrew Cooper.
- Added Andrew Cooper's Reviewed-by.

---
 xen/include/asm-x86/monitor.h | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
xen/include/asm-x86/monitor.h +13 -3
index 0954b59..d367099 100644
@@ -32,19 +32,29 @@
 static inline
 int arch_monitor_domctl_op(struct domain *d, struct xen_domctl_monitor_op *mop)
 {
+    int rc = 0;
+
     switch ( mop->op )
     {
     case XEN_DOMCTL_MONITOR_OP_EMULATE_EACH_REP:
         domain_pause(d);
-        d->arch.mem_access_emulate_each_rep = !!mop->event;
+        /*
+         * 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 )
+            d->arch.mem_access_emulate_each_rep = !!mop->event;
+        else
+            rc = -EINVAL;
+
         domain_unpause(d);
         break;
 
     default:
-        return -EOPNOTSUPP;
+        rc = -EOPNOTSUPP;
     }
 
-    return 0;
+    return rc;
 }
 
Quoted 5 lines

xen/include/asm-x86/monitor.h line 60

Quoted 1 line
xen/include/asm-x86/monitor.h +0 -0
 int arch_monitor_domctl_event(struct domain *d,

According to the previous list discussion with Andrew Cooper, this fix might be considered for the 4.7 release, so CC-ing Wei for a release ack, as suggested.

Quoted 3 lines

Even if - without the pending ./MAINTAINERS adjustment - not formally required, I don't understand why you didn't Cc Tamas on this patch. I don't think this should go in without his ack.

Of course, I was under the impression that he was in the recipients list (I let scripts/maintaners.pl do the work and didn't pay much attention to its output).

By all means.

Thanks,
Razvan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#5 lore raw
Quoted 70 lines · Razvan Cojocaru
Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 29.04.16 at 18:12, <[email protected]> wrote:
Quoted 1 line · Razvan Cojocaru

It is meaningless (and potentially dangerous - see

hvmemul_virtual_to_linear())

Quoted 1 line
Quoted 1 line
Quoted 1 line

to set mem_access_emulate_each_rep before xc_monitor_enable() (which

allocates

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines

vcpu->arch.vm_event) has been called, so return an error from the XEN_DOMCTL_MONITOR_OP_EMULATE_EACH_REP hypercall when that is the case.

---
Changes since V2:
- Updated the if() condition as recommended by Andrew Cooper.
- Added Andrew Cooper's Reviewed-by.

---
 xen/include/asm-x86/monitor.h | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
Quoted 1 line
Quoted 1 line

Review

Quoted 1 line
(quoted diff) +0 -0

b/xen/include/asm-x86/monitor.h

Quoted 6 lines
Quoted 6 lines

xen/include/asm-x86/monitor.h line 33

Quoted 6 lines

index 0954b59..d367099 100644

xen/include/asm-x86/monitor.h +0 -0
@@ -32,19 +32,29 @@
 static inline
 int arch_monitor_domctl_op(struct domain *d, struct

xen_domctl_monitor_op *mop)

Quoted 10 lines
Quoted 10 lines

xen/include/asm-x86/monitor.h

Quoted 10 lines
xen/include/asm-x86/monitor.h +4 -1
 {
+    int rc = 0;
+
     switch ( mop->op )
     {
     case XEN_DOMCTL_MONITOR_OP_EMULATE_EACH_REP:
         domain_pause(d);
-        d->arch.mem_access_emulate_each_rep = !!mop->event;
+        /*
+         * Enabling mem_access_emulate_each_rep without a vm_event

subscriber

Quoted 21 lines
Quoted 21 lines
Quoted 20 lines
xen/include/asm-x86/monitor.h +9 -2
+         * is meaningless.
+         */
+        if ( d->max_vcpus && d->vcpu[0] && d->vcpu[0]->arch.vm_event )
+            d->arch.mem_access_emulate_each_rep = !!mop->event;
+        else
+            rc = -EINVAL;
+
         domain_unpause(d);
         break;
 
     default:
-        return -EOPNOTSUPP;
+        rc = -EOPNOTSUPP;
     }
 
-    return 0;
+    return rc;
 }
 
 int arch_monitor_domctl_event(struct domain *d,
Quoted 7 lines
Quoted 3 lines

According to the previous list discussion with Andrew Cooper, this fix might be considered for the 4.7 release, so CC-ing Wei for a release ack, as suggested.

Even if - without the pending ./MAINTAINERS adjustment - not formally required, I don't understand why you didn't Cc Tamas on this patch. I don't think this should go in without his ack.

Quoted 6 lines

Of course, I was under the impression that he was in the recipients list (I let scripts/maintaners.pl do the work and didn't pay much attention to its output).

By all means.

The maintainers file wasn't covering this header properly. Fixed in my other patch-set.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel