Skip to contentSkip to conversation

Modifications to mem_event_enable API and addition of teardown routine.

PATCH Superseded Dushyant Behl 3 participants 9 messages Aug 13, 2014 – Aug 26, 2014 2 messages not in the archive

v0 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Modifications to mem_event_enable API and addition of teardown routine.

This patch series is the corrected version of the following patch series,
http://lists.xenproject.org/archives/html/xen-devel/2014-08/msg00847.html
http://lists.xenproject.org/archives/html/xen-devel/2014-08/msg00848.html
http://lists.xenproject.org/archives/html/xen-devel/2014-08/msg00846.html
http://lists.xenproject.org/archives/html/xen-devel/2014-08/msg00849.html

The previous patch series had some code which was actually present in the tree after addition of XSA-99. Please ignore the older patch series and have a look at this patch series.

[PATCH v0 1/3] mem_access: modifications to mem_event enable API. This patch modifies the xc_mem_event_enable API by -
1. adding shared ring init.
2. clearing ring page.
3. replacing calls to deprecated API's.
4. updating the xc_mem_event_enable API to have simmilar signature with other mem_event API's (This was my personal choice and is certainly debatable).

[PATCH v0 2/3] mem_event: Added new helper API to teardown mem event and unmap ring_page. This patch adds a new xc_mem_event_teardown API to teardown the mem event setup for the PAGING, ACCESS and SHARING HVM params.

[PATCH v0 3/3] xenpaging: updated code to use safer mem_event API's for setup and teardown. This patch simply updates the code to use the newly created API's.

#1 lore raw

PATCH 1/3 mem_access: modifications to mem_event enable API.

tools/libxc/:
1. Modified the API xc_mem_event_enable to initialize
shared ring to communicate with the hypervisor along with enabling mem_event.
2. Added memset to clear the ring_page of any bogus input before enabling any events.
3. Replaced calls to deprecated function xc_map_foreign_batch with calls to xc_map_foreign_bulk. The function xc_map_foreign_bulk has a cleaner error reporting interface than xc_map_foreign_batch.
4. The API xc_mem_event_enable is now modified to return int rather than void *, this was done to synchronize this API's behaviour with other mem_event API's.

tools/tests/xen-access/: Updated code to use the new helper API.

tools/ocaml/libs/xc/xenctrl_stubs.c: Changed the name of a macro from RING_SIZE to BUF_RING_SIZE because the earlier name collided with xen shared ring deinitions in io/ring.h

---
 tools/libxc/xc_mem_access.c         |  8 ++++--
 tools/libxc/xc_mem_event.c          | 49 +++++++++++++++++++++++++++----------
 tools/libxc/xc_private.h            | 10 +++++---
 tools/libxc/xenctrl.h               |  9 ++++---
 tools/ocaml/libs/xc/xenctrl_stubs.c |  6 ++---
 tools/tests/xen-access/xen-access.c | 17 +++++--------
 6 files changed, 64 insertions(+), 35 deletions(-)
tools/libxc/xc_mem_access.c +6 -2
index 461f0e9..89050be 100644
@@ -24,9 +24,13 @@
 #include "xc_private.h"
 #include <xen/memory.h>
 
-void *xc_mem_access_enable(xc_interface *xch, domid_t domain_id, uint32_t *port)
+int xc_mem_access_enable(xc_interface *xch, domid_t domain_id,
+                         uint32_t *port, void *ring_page,
+                         mem_event_back_ring_t *back_ring)
 {
-    return xc_mem_event_enable(xch, domain_id, HVM_PARAM_ACCESS_RING_PFN, port);
+    return xc_mem_event_enable(xch, domain_id,
+                               HVM_PARAM_ACCESS_RING_PFN,
+                               port, ring_page, back_ring);
 }
 
 int xc_mem_access_disable(xc_interface *xch, domid_t domain_id)
tools/libxc/xc_mem_event.c +36 -13

106 lines not on this page · raw message

tools/libxc/xc_private.h +7 -3
index c50a7c9..cf9b223 100644
@@ -32,6 +32,7 @@
 #include "xenctrl.h"
 #include "xenctrlosdep.h"
 
+#include <xen/mem_event.h>
 #include <xen/sys/privcmd.h>
 
 #if defined(HAVE_VALGRIND_MEMCHECK_H) && !defined(NDEBUG) && !defined(__MINIOS__)
@@ -377,10 +378,13 @@ int xc_mem_event_memop(xc_interface *xch, domid_t domain_id,
                         unsigned int op, unsigned int mode,
                         uint64_t gfn, void *buffer);
 /*
- * Enables mem_event and returns the mapped ring page indicated by param.
+ * Enables mem_event and initializes shared ring to communicate with hypervisor
+ * sets ring_page equal to mapped page.
+ * Returns 0 if success and if failure returns -errno with errno properly set.
  * param can be HVM_PARAM_PAGING/ACCESS/SHARING_RING_PFN
  */
-void *xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param,
-                          uint32_t *port);
+int xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param,
+                        uint32_t *port, void *ring_page,
+                        mem_event_back_ring_t *back_ring);
 
 #endif /* __XC_PRIVATE_H__ */
tools/libxc/xenctrl.h +6 -3
index 1c5d0db..d21f026 100644
@@ -47,6 +47,7 @@
 #include <xen/xsm/flask_op.h>
 #include <xen/tmem.h>
 #include <xen/kexec.h>
+#include <xen/mem_event.h>
 
 #include "xentoollog.h"
 
@@ -2258,11 +2259,13 @@ int xc_mem_paging_load(xc_interface *xch, domid_t domain_id,
  */
 
 /*
- * Enables mem_access and returns the mapped ring page.
- * Will return NULL on error.
+ * Enables mem_access and sets arg ring page equal to mapped page.
+ * Will return 0 on success and -errno on error.
  * Caller has to unmap this page when done.
  */
-void *xc_mem_access_enable(xc_interface *xch, domid_t domain_id, uint32_t *port);
+int xc_mem_access_enable(xc_interface *xch, domid_t domain_id,
+                         uint32_t *port, void *ring_page,
+                         mem_event_back_ring_t *back_ring);
 int xc_mem_access_disable(xc_interface *xch, domid_t domain_id);
 int xc_mem_access_resume(xc_interface *xch, domid_t domain_id);
 
tools/ocaml/libs/xc/xenctrl_stubs.c +3 -3
index f0810eb..beccb38 100644
@@ -526,12 +526,12 @@ CAMLprim value stub_xc_evtchn_reset(value xch, value domid)
 }
 
 
-#define RING_SIZE 32768
-static char ring[RING_SIZE];
+#define BUF_RING_SIZE 32768
+static char ring[BUF_RING_SIZE];
 
 CAMLprim value stub_xc_readconsolering(value xch)
 {
-	unsigned int size = RING_SIZE - 1;
+	unsigned int size = BUF_RING_SIZE - 1;
 	char *ring_ptr = ring;
 	int retval;
 
tools/tests/xen-access/xen-access.c +6 -11
index 090df5f..9242f86 100644
@@ -245,11 +245,12 @@ xenaccess_t *xenaccess_init(xc_interface **xch_r, domid_t domain_id)
     mem_event_ring_lock_init(&xenaccess->mem_event);
 
     /* Enable mem_access */
-    xenaccess->mem_event.ring_page =
-            xc_mem_access_enable(xenaccess->xc_handle,
-                                 xenaccess->mem_event.domain_id,
-                                 &xenaccess->mem_event.evtchn_port);
-    if ( xenaccess->mem_event.ring_page == NULL )
+    rc = xc_mem_access_enable(xenaccess->xc_handle,
+                              xenaccess->mem_event.domain_id,
+                              &xenaccess->mem_event.evtchn_port,
+                              xenaccess->mem_event.ring_page,
+                              &xenaccess->mem_event.back_ring);
+    if ( rc < 0 )
     {
         switch ( errno ) {
             case EBUSY:
@@ -287,12 +288,6 @@ xenaccess_t *xenaccess_init(xc_interface **xch_r, domid_t domain_id)
     evtchn_bind = 1;
     xenaccess->mem_event.port = rc;
 
-    /* Initialise ring */
-    SHARED_RING_INIT((mem_event_sring_t *)xenaccess->mem_event.ring_page);
-    BACK_RING_INIT(&xenaccess->mem_event.back_ring,
-                   (mem_event_sring_t *)xenaccess->mem_event.ring_page,
-                   XC_PAGE_SIZE);
-
     /* Get domaininfo */
     xenaccess->domain_info = malloc(sizeof(xc_domaininfo_t));
     if ( xenaccess->domain_info == NULL )
Signature · 1 line
1.9.1

A message that is not in the archive (sent off-list or not yet received): CAGU+auvmQOWp8VH5bt+yh55iyJxLOV6Hd8ZfvAsdyuOOZ3fBNQ@mail.gmail.com

#3 lore raw

Re: [PATCH v0 1/3] mem_access: modifications to mem_event enable API.

Quoted 4 lines

4. The API xc_mem_event_enable is now modified to return int rather than void *,
this was done to synchronize this API's behaviour with other mem_event
API's.

FWIW, since I am the one that introduced this... I am fine with the change. Though I did think that the norm was to return -1 on error and set errno to the appropriate value.

Quoted 4 lines
tools/libxc/xc_mem_event.c +0 -0
index faf1cc6..3525a83 100644

<snip>

tools/libxc/xc_mem_event.c void *xc_mem_event_enable(xc_interface *xch, · line 106

Quoted 13 lines
tools/libxc/xc_mem_event.c +3 -3
@@ -89,9 +98,9 @@ void *xc_mem_event_enable(xc_interface *xch,
 domid_t domain_id, int param,
 
    ring_pfn = pfn;
    mmap_pfn = pfn;
-    ring_page = xc_map_foreign_batch(xch, domain_id, PROT_READ |
 PROT_WRITE,
-                                     &mmap_pfn, 1);
-    if ( mmap_pfn & XEN_DOMCTL_PFINFO_XTAB )
+    ring_page = xc_map_foreign_bulk(xch, domain_id,
+                                    PROT_READ | PROT_WRITE,
 &mmap_pfn, &err, 1);
+    if ( (err != 0) || (ring_page == NULL) )

Please remove the redundant brackets.

Quoted 14 lines
    {
        /* Map failed, populate ring page */
        rc1 = xc_domain_populate_physmap_exact(xch, domain_id, 1, 0, 0, @@ -
103,15 +112,23 @@ void *xc_mem_event_enable(xc_interface *xch,
domid_t domain_id, int param,
        }

        mmap_pfn = ring_pfn;

- ring_page = xc_map_foreign_batch(xch, domain_id, PROT_READ |
PROT_WRITE,

tools/libxc/xc_mem_event.c +1 -2
-                                         &mmap_pfn, 1);
-        if ( mmap_pfn & XEN_DOMCTL_PFINFO_XTAB )
+        ring_page = xc_map_foreign_bulk(xch, domain_id, PROT_READ |

PROT_WRITE,

tools/libxc/xc_mem_event.c void *xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param, · line 117

Quoted 2 lines
tools/libxc/xc_mem_event.c +2 -0
+                                        &mmap_pfn, &err, 1);
+        if ( (err != 0) || (ring_page == NULL) )

Please remove the redundant brackets.

Quoted 19 lines
tools/libxc/xc_private.h index renamed from tools/libxc/xc_private.h +0 -0

c50a7c9..cf9b223 100644

tools/libxc/xc_private.h +1 -0
@@ -32,6 +32,7 @@
 #include "xenctrl.h"
 #include "xenctrlosdep.h"
 
+#include <xen/mem_event.h>
 #include <xen/sys/privcmd.h>
 
 #if defined(HAVE_VALGRIND_MEMCHECK_H) && !defined(NDEBUG) &&

!defined(__MINIOS__)

tools/libxc/xc_private.h +0 -1
@@ -377,10 +378,13 @@ int xc_mem_event_memop(xc_interface *xch,
 domid_t domain_id,
                        unsigned int op, unsigned int mode,
                        uint64_t gfn, void *buffer);
 /*
- * Enables mem_event and returns the mapped ring page indicated by
Quoted 3 lines

param.
+ * Enables mem_event and initializes shared ring to communicate with
+ hypervisor

Full stop or and.

Quoted 26 lines

+ * sets ring_page equal to mapped page.
+ * Returns 0 if success and if failure returns -errno with errno properly set.
* param can be HVM_PARAM_PAGING/ACCESS/SHARING_RING_PFN
*/
-void *xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param,

tools/libxc/xc_private.h +1 -1
-                          uint32_t *port);
+int xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int

param,

tools/libxc/xc_private.h +2 -0
+                        uint32_t *port, void *ring_page,
+                        mem_event_back_ring_t *back_ring);

#endif /* __XC_PRIVATE_H__ */

tools/libxc/xenctrl.h index 1c5d0db..d21f026 renamed from tools/libxc/xenctrl.h +0 -0

100644

tools/libxc/xenctrl.h +1 -0
@@ -47,6 +47,7 @@
 #include <xen/xsm/flask_op.h>
 #include <xen/tmem.h>
 #include <xen/kexec.h>
+#include <xen/mem_event.h>
 
 #include "xentoollog.h"
 

tools/libxc/xenctrl.h int xc_mem_paging_load(xc_interface *xch, · line 2263

Quoted 7 lines
tools/libxc/xenctrl.h +1 -2
@@ -2258,11 +2259,13 @@ int xc_mem_paging_load(xc_interface *xch,
 domid_t domain_id,
 */
 
 /*
- * Enables mem_access and returns the mapped ring page.
- * Will return NULL on error.
+ * Enables mem_access and sets arg ring page equal to mapped page.

ring_page in the above line. I would leave arg out like you did in the previous comment.

Quoted 10 lines
tools/libxc/xenctrl.h +4 -1
+ * Will return 0 on success and -errno on error.
 * Caller has to unmap this page when done.
 */
-void *xc_mem_access_enable(xc_interface *xch, domid_t domain_id,
 uint32_t *port);
+int xc_mem_access_enable(xc_interface *xch, domid_t domain_id,
+                         uint32_t *port, void *ring_page,
+                         mem_event_back_ring_t *back_ring);

int xc_mem_access_disable(xc_interface *xch, domid_t domain_id); int xc_mem_access_resume(xc_interface *xch, domid_t domain_id);

Thanks,
Aravindh

#4 lore raw

Re: [PATCH v0 1/3] mem_access: modifications to mem_event enable API.

Hi Aravindh,

Thank you for taking time to review the patches, I have updated the patches according to your comments.
I actually looked in the code after your comment and thought that since returning -1 was present mostly so I have changed the functions to return -1 with errno properly set, Hope this is fine.
Please have a look at the v2 of patch series.

Thanks and Regards,
Dushyant Behl

Quoted 116 lines · Aravindh Puthiyaparambil (aravindp)
Quoted 4 lines

4. The API xc_mem_event_enable is now modified to return int rather than void *,
this was done to synchronize this API's behaviour with other mem_event
API's.

FWIW, since I am the one that introduced this... I am fine with the change. Though I did think that the norm was to return -1 on error and set errno to the appropriate value.

Quoted 4 lines
tools/libxc/xc_mem_event.c +0 -0
index faf1cc6..3525a83 100644

<snip>

tools/libxc/xc_mem_event.c void *xc_mem_event_enable(xc_interface *xch, · line 106

Quoted 13 lines
tools/libxc/xc_mem_event.c +3 -3
@@ -89,9 +98,9 @@ void *xc_mem_event_enable(xc_interface *xch,
 domid_t domain_id, int param,
 
    ring_pfn = pfn;
    mmap_pfn = pfn;
-    ring_page = xc_map_foreign_batch(xch, domain_id, PROT_READ |
 PROT_WRITE,
-                                     &mmap_pfn, 1);
-    if ( mmap_pfn & XEN_DOMCTL_PFINFO_XTAB )
+    ring_page = xc_map_foreign_bulk(xch, domain_id,
+                                    PROT_READ | PROT_WRITE,
 &mmap_pfn, &err, 1);
+    if ( (err != 0) || (ring_page == NULL) )

Please remove the redundant brackets.

Quoted 3 lines
    {
        /* Map failed, populate ring page */
        rc1 = xc_domain_populate_physmap_exact(xch, domain_id, 1, 0, 0,

@@ -

tools/libxc/xc_mem_event.c void *xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param, · line 117

Quoted 13 lines

103,15 +112,23 @@ void *xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param,

        }

        mmap_pfn = ring_pfn;

- ring_page = xc_map_foreign_batch(xch, domain_id, PROT_READ |
PROT_WRITE,

tools/libxc/xc_mem_event.c +1 -2
-                                         &mmap_pfn, 1);
-        if ( mmap_pfn & XEN_DOMCTL_PFINFO_XTAB )
+        ring_page = xc_map_foreign_bulk(xch, domain_id, PROT_READ |

PROT_WRITE,

tools/libxc/xc_mem_event.c +2 -0
+                                        &mmap_pfn, &err, 1);
+        if ( (err != 0) || (ring_page == NULL) )

Please remove the redundant brackets.

Quoted 19 lines
tools/libxc/xc_private.h index renamed from tools/libxc/xc_private.h +0 -0

c50a7c9..cf9b223 100644

tools/libxc/xc_private.h +1 -0
@@ -32,6 +32,7 @@
 #include "xenctrl.h"
 #include "xenctrlosdep.h"
 
+#include <xen/mem_event.h>
 #include <xen/sys/privcmd.h>
 
 #if defined(HAVE_VALGRIND_MEMCHECK_H) && !defined(NDEBUG) &&

!defined(__MINIOS__)

tools/libxc/xc_private.h +0 -1
@@ -377,10 +378,13 @@ int xc_mem_event_memop(xc_interface *xch,
 domid_t domain_id,
                        unsigned int op, unsigned int mode,
                        uint64_t gfn, void *buffer);
 /*
- * Enables mem_event and returns the mapped ring page indicated by
Quoted 3 lines

param.
+ * Enables mem_event and initializes shared ring to communicate with
+ hypervisor

Full stop or and.

Quoted 2 lines

+ * sets ring_page equal to mapped page.
+ * Returns 0 if success and if failure returns -errno with errno

properly set.

tools/libxc/xenctrl.h index

Quoted 12 lines

* param can be HVM_PARAM_PAGING/ACCESS/SHARING_RING_PFN */
-void *xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param,

tools/libxc/xc_private.h +1 -1
-                          uint32_t *port);
+int xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int

param,

tools/libxc/xc_private.h +2 -0
+                        uint32_t *port, void *ring_page,
+                        mem_event_back_ring_t *back_ring);

#endif /* __XC_PRIVATE_H__ */

tools/libxc/xenctrl.h index renamed from tools/libxc/xenctrl.h +0 -0

1c5d0db..d21f026

Quoted 12 lines

100644

tools/libxc/xenctrl.h +1 -0
@@ -47,6 +47,7 @@
 #include <xen/xsm/flask_op.h>
 #include <xen/tmem.h>
 #include <xen/kexec.h>
+#include <xen/mem_event.h>
 
 #include "xentoollog.h"
 

tools/libxc/xenctrl.h int xc_mem_paging_load(xc_interface *xch, · line 2263

Quoted 7 lines
tools/libxc/xenctrl.h +1 -2
@@ -2258,11 +2259,13 @@ int xc_mem_paging_load(xc_interface *xch,
 domid_t domain_id,
 */
 
 /*
- * Enables mem_access and returns the mapped ring page.
- * Will return NULL on error.
+ * Enables mem_access and sets arg ring page equal to mapped page.

ring_page in the above line. I would leave arg out like you did in the previous comment.

Quoted 15 lines
Quoted 10 lines
tools/libxc/xenctrl.h +4 -1
+ * Will return 0 on success and -errno on error.
 * Caller has to unmap this page when done.
 */
-void *xc_mem_access_enable(xc_interface *xch, domid_t domain_id,
 uint32_t *port);
+int xc_mem_access_enable(xc_interface *xch, domid_t domain_id,
+                         uint32_t *port, void *ring_page,
+                         mem_event_back_ring_t *back_ring);

int xc_mem_access_disable(xc_interface *xch, domid_t domain_id); int xc_mem_access_resume(xc_interface *xch, domid_t domain_id);

Thanks,
Aravindh

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

#5 lore raw

Re: [PATCH v0 1/3] mem_access: modifications to mem_event enable API.

Thank you for taking time to review the patches, I have updated the patches according to your comments.

Not a problem. Glad to be of some help.

I actually looked in the code after your comment and thought that since returning -1 was present mostly so I have changed the functions to return -1 with errno properly set, Hope this is fine. Please have a look at the v2 of patch series.

In future while sending out newer patches in the series, please don’t skip patch version numbers. This is just to reduce confusion among the reviewers and maintainers.

Thanks,
Aravindh

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

#6 lore raw

Re: [PATCH v0 1/3] mem_access: modifications to mem_event enable API.

In reply to Aravindh Puthiyaparambil (aravindp)
Quoted 8 lines · Aravindh Puthiyaparambil (aravindp)
Quoted 4 lines

4. The API xc_mem_event_enable is now modified to return int rather than void *,
this was done to synchronize this API's behaviour with other mem_event
API's.

FWIW, since I am the one that introduced this... I am fine with the change. Though I did think that the norm was to return -1 on error and set errno to the appropriate value.

Sadly there isn't really a norm in libxc now, we use basically every possible way of returning errors.

In so far as we are moving in any particular direction to try and rationalise this I think we are trying to get to set errno and return -1 (like a normal POSIXy library)

Ian.

#7 lore raw

PATCH 2/3 mem_event: Added new helper API to teardown mem event setup and unmap ring_page.

In reply to Dushyant Behl

tools/libxc/xc_mem_event.c: Added new generic API to teardown mem event setup, the API supports hvm params PAGING, ACCESS and SHARING and also completes the obvious job of unmapping ring_page.

tools/libxc/xc_mem_access.c: Modified mem_event_disable to use the new teardown API.

tools/tests/xen-access/: Updated code to use the new API's.

---
 tools/libxc/xc_mem_access.c         |  9 +++---
 tools/libxc/xc_mem_event.c          | 59 +++++++++++++++++++++++++++++++++++++
 tools/libxc/xc_private.h            |  8 +++++
 tools/libxc/xenctrl.h               |  3 +-
 tools/tests/xen-access/xen-access.c |  6 ++--
 5 files changed, 74 insertions(+), 11 deletions(-)
tools/libxc/xc_mem_access.c +4 -5
index 89050be..ea24689 100644
@@ -33,12 +33,11 @@ int xc_mem_access_enable(xc_interface *xch, domid_t domain_id,
                                port, ring_page, back_ring);
 }
 
-int xc_mem_access_disable(xc_interface *xch, domid_t domain_id)
+int xc_mem_access_disable(xc_interface *xch, domid_t domain_id, void *ring_page)
 {
-    return xc_mem_event_control(xch, domain_id,
-                                XEN_DOMCTL_MEM_EVENT_OP_ACCESS_DISABLE,
-                                XEN_DOMCTL_MEM_EVENT_OP_ACCESS,
-                                NULL);
+    return xc_mem_event_teardown(xch, domain_id,
+                                HVM_PARAM_ACCESS_RING_PFN,
+                                ring_page);
 }
 
 int xc_mem_access_resume(xc_interface *xch, domid_t domain_id)
tools/libxc/xc_mem_event.c +59 -0

62 lines not on this page · raw message

tools/libxc/xc_private.h +8 -0
index cf9b223..7120a08 100644
@@ -387,4 +387,12 @@ int xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param,
                         uint32_t *port, void *ring_page,
                         mem_event_back_ring_t *back_ring);
 
+/*
+ * Teardown mem_event
+ * returns 0 on success, if failure returns -errno with errno properly set.
+ * param can be HVM_PARAM_PAGING/ACCESS/SHARING_RING_PFN
+ */
+int xc_mem_event_teardown(xc_interface *xch, domid_t domain_id,
+                          int param, void *ring_page);
+
 #endif /* __XC_PRIVATE_H__ */
tools/libxc/xenctrl.h +1 -2
index d21f026..cfd6019 100644
@@ -2261,12 +2261,11 @@ int xc_mem_paging_load(xc_interface *xch, domid_t domain_id,
 /*
  * Enables mem_access and sets arg ring page equal to mapped page.
  * Will return 0 on success and -errno on error.
- * Caller has to unmap this page when done.
  */
 int xc_mem_access_enable(xc_interface *xch, domid_t domain_id,
                          uint32_t *port, void *ring_page,
                          mem_event_back_ring_t *back_ring);
-int xc_mem_access_disable(xc_interface *xch, domid_t domain_id);
+int xc_mem_access_disable(xc_interface *xch, domid_t domain_id, void *ring_page);
 int xc_mem_access_resume(xc_interface *xch, domid_t domain_id);
 
 /*
tools/tests/xen-access/xen-access.c +2 -4
index 9242f86..a4ef578 100644
@@ -170,13 +170,11 @@ int xenaccess_teardown(xc_interface *xch, xenaccess_t *xenaccess)
         return 0;
 
     /* Tear down domain xenaccess in Xen */
-    if ( xenaccess->mem_event.ring_page )
-        munmap(xenaccess->mem_event.ring_page, XC_PAGE_SIZE);
-
     if ( mem_access_enable )
     {
         rc = xc_mem_access_disable(xenaccess->xc_handle,
-                                   xenaccess->mem_event.domain_id);
+                                   xenaccess->mem_event.domain_id,
+                                   xenaccess->mem_event.ring_page);
         if ( rc != 0 )
         {
             ERROR("Error tearing down domain xenaccess in xen");
Signature · 1 line
1.9.1

A message that is not in the archive (sent off-list or not yet received): CAGU+auudSP7mXfGzMzhDm4WkwS7icGy_rFCAWHhN85xe_pF=Og@mail.gmail.com

#9 lore raw

Re: [PATCH v0 2/3] mem_event: Added new helper API to teardown mem event setup and unmap ring_page.

Quoted 138 lines

tools/libxc/xc_mem_access.c int xc_mem_access_enable(xc_interface *xch,

Quoted 5 lines
tools/libxc/xc_mem_access.c +0 -0
index 89050be..ea24689 100644
@@ -33,12 +33,11 @@ int xc_mem_access_enable(xc_interface *xch,

domid_t

Quoted 5 lines
tools/libxc/xc_mem_access.c +1 -1
 domain_id,
                               port, ring_page, back_ring);  }
 
-int xc_mem_access_disable(xc_interface *xch, domid_t domain_id)
+int xc_mem_access_disable(xc_interface *xch, domid_t domain_id, void

tools/libxc/xc_mem_access.c int xc_mem_access_enable(xc_interface *xch, domid_t domain_id, · line 41

Quoted 10 lines
tools/libxc/xc_mem_access.c +3 -4
 *ring_page)
 {
-    return xc_mem_event_control(xch, domain_id,
-                                XEN_DOMCTL_MEM_EVENT_OP_ACCESS_DISABLE,
-                                XEN_DOMCTL_MEM_EVENT_OP_ACCESS,
-                                NULL);
+    return xc_mem_event_teardown(xch, domain_id,
+                                HVM_PARAM_ACCESS_RING_PFN,
+                                ring_page);
 }

Coding style. Please line up the parameters after the "(".

tools/libxc/xc_mem_event.c int xc_mem_event_enable(xc_interface *xch,

Quoted 6 lines

int xc_mem_access_resume(xc_interface *xch, domid_t domain_id) diff --git a/tools/libxc/xc_mem_event.c b/tools/libxc/xc_mem_event.c index 3525a83..6cd1894 100644

tools/libxc/xc_mem_event.c +0 -0
@@ -196,3 +196,62 @@ int xc_mem_event_enable(xc_interface *xch,

domid_t

tools/libxc/xc_mem_event.c int xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param, · line 204

Quoted 10 lines
tools/libxc/xc_mem_event.c +0 -0
 domain_id, int param,
 
    return rc1;

}

tools/libxc/xc_mem_event.c +6 -0
+
+/*
+ * Teardown mem_event
+ * returns 0 on success, if failure returns -errno with errno properly set.
+ * param can be HVM_PARAM_PAGING/ACCESS/SHARING_RING_PFN
+ */

Same comment as in the previous review. I did think that the norm was to return -1 on error and set errno to the appropriate value. I guess a maintainer could confirm this.

Quoted 26 lines
tools/libxc/xc_mem_event.c +23 -0
+int xc_mem_event_teardown(xc_interface *xch, domid_t domain_id,
+                          int param, void *ring_page) {
+    int rc;
+    unsigned int op, mode;
+    switch ( param )
+    {
+        case HVM_PARAM_PAGING_RING_PFN:
+            op = XEN_DOMCTL_MEM_EVENT_OP_PAGING_DISABLE;
+            mode = XEN_DOMCTL_MEM_EVENT_OP_PAGING;
+            break;
+
+        case HVM_PARAM_ACCESS_RING_PFN:
+            op = XEN_DOMCTL_MEM_EVENT_OP_ACCESS_DISABLE;
+            mode = XEN_DOMCTL_MEM_EVENT_OP_ACCESS;
+            break;
+
+        case HVM_PARAM_SHARING_RING_PFN:
+            op = XEN_DOMCTL_MEM_EVENT_OP_SHARING_DISABLE;
+            mode = XEN_DOMCTL_MEM_EVENT_OP_SHARING;
+            break;
+
+        /*
+         * This is for the outside chance that the HVM_PARAM is valid

but is invalid

tools/libxc/xc_mem_event.c +2 -0
+         * as far as mem_event goes.
+         */

tools/libxc/xc_mem_event.c int xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param, · line 241

Quoted 10 lines
tools/libxc/xc_mem_event.c +10 -0
+        default:
+            errno = EINVAL;
+            rc = -1;
+            goto out;
+    }
+
+    /* Remove the ring page. */
+    rc = munmap(ring_page, PAGE_SIZE);
+    if ( rc < 0 )
+        PERROR("Error while disabling paging in xen");

You could say error in munmap instead of a generic statement. And if you are going to display a error message here you should add one in the error path of xc_mem_event_enable() too.

tools/libxc/xc_mem_event.c int xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param, · line 249

Quoted 7 lines
tools/libxc/xc_mem_event.c +7 -0
+    ring_page = NULL;
+
+    rc = xc_mem_event_control(xch, domain_id, op, mode, NULL);
+    if ( rc != 0 )
+    {
+        PERROR("Failed to disable mem_event\n");
+        goto out;

Why do you need a goto here? You could set rc to -errno in default case of the "switch" statement and in the above "if" and just have a "return rc" at the out label.

tools/libxc/xc_mem_event.c int xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param, · line 253

Quoted 4 lines
tools/libxc/xc_mem_event.c +4 -0
+    }
+
+  out:
+    if (rc != 0)

Coding style.

tools/libxc/xc_private.h int xc_mem_event_enable(xc_interface *xch,

Quoted 9 lines
tools/libxc/xc_mem_event.c +4 -0
+        rc = -errno;
+
+    return rc;
+}
tools/libxc/xc_private.h index renamed from tools/libxc/xc_private.h +0 -0

cf9b223..7120a08 100644

tools/libxc/xc_private.h +0 -0
@@ -387,4 +387,12 @@ int xc_mem_event_enable(xc_interface *xch,

domid_t

tools/libxc/xc_private.h int xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param, · line 391

Quoted 6 lines
tools/libxc/xc_private.h +2 -0
 domain_id, int param,
                        uint32_t *port, void *ring_page,
                        mem_event_back_ring_t *back_ring);
 
+/*
+ * Teardown mem_event

Fullstop.

tools/libxc/xc_private.h int xc_mem_event_enable(xc_interface *xch, · line 393

Quoted 1 line
tools/libxc/xc_private.h +1 -0
+ * returns 0 on success, if failure returns -errno with errno properly set.

Please capitalize the "r".

tools/libxc/xc_private.h int xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param, · line 397

Quoted 5 lines
tools/libxc/xc_private.h +5 -0
+ * param can be HVM_PARAM_PAGING/ACCESS/SHARING_RING_PFN
+ */
+int xc_mem_event_teardown(xc_interface *xch, domid_t domain_id,
+                          int param, void *ring_page);
+

Why is this called mem_event_teardown()? Won't mem_event_disable() be more appropriate?

Quoted 2 lines

Thanks,
Aravindh

Adding xen-devel back as I dropped it accidently.

#10 lore raw

PATCH 3/3 xenpaging: updated code to use safer mem_event API's for setup and teardown.

In reply to Dushyant Behl

tools/libxc/xc_mem_paging.c: updated mem_paging enable and disable API's to use the mem event enable and disable routines. The mem event API's take care of security issues mentioned in XSA-99 and also provide more coarse grained behaviour.

tools/xenpaging/xenpaging.c: added calls to the new API's and removed the code which duplicated the new API behaviour.

---
 tools/libxc/xc_mem_paging.c | 34 ++++++++++++++---------------
 tools/libxc/xenctrl.h       | 14 ++++++++++--
 tools/xenpaging/xenpaging.c | 52 ++++++---------------------------------------
 3 files changed, 36 insertions(+), 64 deletions(-)
tools/libxc/xc_mem_paging.c +17 -17
index 8aa7d4d..826bdb7 100644
@@ -23,28 +23,28 @@
 
 #include "xc_private.h"
 
-
+/*
+ * Enables mem_paging and sets arg ring page equal to mapped page.
+ * Will return 0 on success and -errno on error.
+ */
 int xc_mem_paging_enable(xc_interface *xch, domid_t domain_id,
-                         uint32_t *port)
+                         uint32_t *port,  void *ring_page,
+                         mem_event_back_ring_t *back_ring)
 {
-    if ( !port )
-    {
-        errno = EINVAL;
-        return -1;
-    }
-        
-    return xc_mem_event_control(xch, domain_id,
-                                XEN_DOMCTL_MEM_EVENT_OP_PAGING_ENABLE,
-                                XEN_DOMCTL_MEM_EVENT_OP_PAGING,
-                                port);
+    return xc_mem_event_enable(xch, domain_id,
+                               HVM_PARAM_PAGING_RING_PFN,
+                               port, ring_page, back_ring);
 }
 
-int xc_mem_paging_disable(xc_interface *xch, domid_t domain_id)
+/*
+ * Disable mem_paging and unmap ring page.
+ * Will return 0 on success and -errno on error.
+ */
+int xc_mem_paging_disable(xc_interface *xch, domid_t domain_id, void *ring_page)
 {
-    return xc_mem_event_control(xch, domain_id,
-                                XEN_DOMCTL_MEM_EVENT_OP_PAGING_DISABLE,
-                                XEN_DOMCTL_MEM_EVENT_OP_PAGING,
-                                NULL);
+    return xc_mem_event_teardown(xch, domain_id,
+                                 HVM_PARAM_ACCESS_RING_PFN,
+                                 ring_page);
 }
 
 int xc_mem_paging_nominate(xc_interface *xch, domid_t domain_id, unsigned long gfn)
tools/libxc/xenctrl.h +12 -2
index cfd6019..6acbfa9 100644
@@ -2244,8 +2244,18 @@ int xc_tmem_restore_extra(xc_interface *xch, int dom, int fd);
  * Hardware-Assisted Paging (i.e. Intel EPT, AMD NPT). Moreover, AMD NPT
  * support is considered experimental.
  */
-int xc_mem_paging_enable(xc_interface *xch, domid_t domain_id, uint32_t *port);
-int xc_mem_paging_disable(xc_interface *xch, domid_t domain_id);
+/*
+ * Enables mem_paging and sets arg ring page equal to mapped page.
+ * returns 0 on success and -errno on error.
+ */
+int xc_mem_paging_enable(xc_interface *xch, domid_t domain_id,
+                         uint32_t *port,  void *ring_page,
+                         mem_event_back_ring_t *back_ring);
+/*
+ * Disables mem_paging and unmaps ring page.
+ * returns 0 on success and -errno on error.
+ */
+int xc_mem_paging_disable(xc_interface *xch, domid_t domain_id, void *ring_page);
 int xc_mem_paging_nominate(xc_interface *xch, domid_t domain_id,
                            unsigned long gfn);
 int xc_mem_paging_evict(xc_interface *xch, domid_t domain_id, unsigned long gfn);
tools/xenpaging/xenpaging.c +7 -45

73 lines not on this page · raw message

Signature · 1 line
1.9.1