Skip to contentSkip to conversation

tools/libxc, xen/x86: Added xc_set_mem_access_multi()

PATCH Superseded Razvan Cojocaru 5 participants 22 messages Sep 2, 2016

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tools/libxc, xen/x86: Added xc_set_mem_access_multi()

Currently it is only possible to set mem_access restrictions only for a contiguous range of GFNs (or, as a particular case, for a single GFN). This patch introduces a new libxc function taking an array of GFNs. The alternative would be to set each page in turn, using a userspace-HV roundtrip for each call, and triggering a TLB flush per page set.

---
Changes since V1 / RFC:
- Renamed xc_set_mem_access_sparse() to xc_set_mem_access_multi(), and XENMEM_access_op_set_access_sparse to XENMEM_access_op_set_access_multi.
- Renamed the 'nr' parameter to 'size'.
- Wrapped long line in the implementation of xc_set_mem_access_multi().
- Factored out common code in _p2m_set_mem_access() (and modified p2m_set_altp2m_mem_access() in the process, to take an unsigned long argument instead of a gfn_t).
- Factored out xenmem_access_t to p2m_access_t conversion code in p2m_xenmem_access_to_p2m_access().
- Added hypercall continuation support.
- Added compat translation support.
- No longer allocating buffers (now using copy_from_guest_offset()).
- Added support for setting an array of access restrictions, as suggested by Tamas Lengyel.
- This patch incorporates Jan Beulich's "memory: fix compat handling of XENMEM_access_op".

---
 tools/libxc/include/xenctrl.h |   4 ++
 tools/libxc/xc_mem_access.c   |  38 ++++++++++
 xen/arch/x86/mm/p2m.c         | 161 ++++++++++++++++++++++++++++++++----------
 xen/common/compat/memory.c    |  24 +++++--
 xen/common/mem_access.c       |  11 +++
 xen/include/public/memory.h   |  14 +++-
 xen/include/xen/p2m-common.h  |   6 ++
 xen/include/xlat.lst          |   2 +-
 8 files changed, 215 insertions(+), 45 deletions(-)
tools/libxc/include/xenctrl.h +4 -0
index 560ce7b..c2f14a6 100644
@@ -2125,6 +2125,10 @@ int xc_set_mem_access(xc_interface *xch, domid_t domain_id,
                       xenmem_access_t access, uint64_t first_pfn,
                       uint32_t nr);
 
+int xc_set_mem_access_multi(xc_interface *xch, domid_t domain_id,
+                            uint8_t *access, uint64_t *pages,
+                            uint32_t size);
+
 /*
  * Gets the mem access for the given page (returned in access on success)
  */
tools/libxc/xc_mem_access.c +38 -0
index eee088c..d69d4f9 100644
@@ -41,6 +41,44 @@ int xc_set_mem_access(xc_interface *xch,
     return do_memory_op(xch, XENMEM_access_op, &mao, sizeof(mao));
 }
 
+int xc_set_mem_access_multi(xc_interface *xch,
+                            domid_t domain_id,
+                            uint8_t *access,
+                            uint64_t *pages,
+                            uint32_t size)
+{
+    DECLARE_HYPERCALL_BOUNCE(access, size, XC_HYPERCALL_BUFFER_BOUNCE_IN);
+    DECLARE_HYPERCALL_BOUNCE(pages, size * sizeof(uint64_t),
+                             XC_HYPERCALL_BUFFER_BOUNCE_IN);
+    int rc;
+
+    xen_mem_access_op_t mao =
+    {
+        .op       = XENMEM_access_op_set_access_multi,
+        .domid    = domain_id,
+        .access   = XENMEM_access_default + 1, /* Invalid value */
+        .pfn      = ~0UL, /* Invalid GFN */
+        .nr       = size,
+    };
+
+    if ( xc_hypercall_bounce_pre(xch, pages) ||
+         xc_hypercall_bounce_pre(xch, access) )
+    {
+        PERROR("Could not bounce memory for XENMEM_access_op_set_access_multi");
+        return -1;
+    }
+
+    set_xen_guest_handle(mao.pfn_list, pages);
+    set_xen_guest_handle(mao.access_list, access);
+
+    rc = do_memory_op(xch, XENMEM_access_op, &mao, sizeof(mao));
+
+    xc_hypercall_bounce_post(xch, access);
+    xc_hypercall_bounce_post(xch, pages);
+
+    return rc;
+}
+
 int xc_get_mem_access(xc_interface *xch,
                       domid_t domain_id,
                       uint64_t pfn,
xen/arch/x86/mm/p2m.c +123 -38

209 lines not on this page · raw message

xen/common/compat/memory.c +19 -5
index 20c7671..e9732df 100644
@@ -15,7 +15,6 @@ CHECK_TYPE(domid);
 #undef compat_domid_t
 #undef xen_domid_t
 
-CHECK_mem_access_op;
 CHECK_vmemrange;
 
 #ifdef CONFIG_HAS_PASSTHROUGH
@@ -71,6 +70,7 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat)
             struct xen_add_to_physmap_batch *atpb;
             struct xen_remove_from_physmap *xrfp;
             struct xen_vnuma_topology_info *vnuma;
+            struct xen_mem_access_op *mao;
         } nat;
         union {
             struct compat_memory_reservation rsrv;
@@ -78,6 +78,7 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat)
             struct compat_add_to_physmap atp;
             struct compat_add_to_physmap_batch atpb;
             struct compat_vnuma_topology_info vnuma;
+            struct compat_mem_access_op mao;
         } cmp;
 
         set_xen_guest_handle(nat.hnd, COMPAT_ARG_XLAT_VIRT_BASE);
@@ -320,6 +321,23 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat)
             break;
         }
 
+        case XENMEM_access_op:
+        {
+#define XLAT_mem_access_op_HNDL_pfn_list(_d_, _s_) \
+            guest_from_compat_handle((_d_)->pfn_list, (_s_)->pfn_list)
+#define XLAT_mem_access_op_HNDL_access_list(_d_, _s_) \
+            guest_from_compat_handle((_d_)->access_list, (_s_)->access_list)
+
+            XLAT_mem_access_op(nat.mao, &cmp.mao);
+
+#undef XLAT_mem_access_op_HNDL_pfn_list
+#undef XLAT_mem_access_op_HNDL_access_list
+
+            return mem_access_memop(cmd,
+                                    guest_handle_cast(compat,
+                                                      xen_mem_access_op_t));
+        }
+
         case XENMEM_get_vnumainfo:
         {
             enum XLAT_vnuma_topology_info_vdistance vdistance =
@@ -495,10 +513,6 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat)
             break;
         }
 
-        case XENMEM_access_op:
-            rc = mem_access_memop(cmd, guest_handle_cast(compat, xen_mem_access_op_t));
-            break;
-
         case XENMEM_add_to_physmap_batch:
             start_extent = end_extent;
             break;
xen/common/mem_access.c +11 -0
index b4033f0..18b908f 100644
@@ -76,6 +76,17 @@ int mem_access_memop(unsigned long cmd,
         }
         break;
 
+    case XENMEM_access_op_set_access_multi:
+        rc = p2m_set_mem_access_multi(d, mao.pfn_list, mao.access_list, mao.nr,
+                                      start_iter, MEMOP_CMD_MASK, 0);
+        if ( rc > 0 )
+        {
+            ASSERT(!(rc & MEMOP_CMD_MASK));
+            rc = hypercall_create_continuation(__HYPERVISOR_memory_op, "lh",
+                                               XENMEM_access_op | rc, arg);
+        }
+        break;
+
     case XENMEM_access_op_get_access:
     {
         xenmem_access_t access;
xen/include/public/memory.h +13 -1
index 3badfb9..9cb2568 100644
@@ -410,6 +410,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_mem_paging_op_t);
  * #define XENMEM_access_op_enable_emulate     2
  * #define XENMEM_access_op_disable_emulate    3
  */
+#define XENMEM_access_op_set_access_multi   4
 
 typedef enum {
     XENMEM_access_n,
@@ -442,7 +443,8 @@ struct xen_mem_access_op {
     uint8_t access;
     domid_t domid;
     /*
-     * Number of pages for set op
+     * Number of pages for set op (or size of pfn_list for
+     * XENMEM_access_op_set_access_multi)
      * Ignored on setting default access and other ops
      */
     uint32_t nr;
@@ -452,6 +454,16 @@ struct xen_mem_access_op {
      * ~0ull is used to set and get the default access for pages
      */
     uint64_aligned_t pfn;
+    /*
+     * List of pfns to set access for
+     * Used only with XENMEM_access_op_set_access_multi
+     */
+    XEN_GUEST_HANDLE(uint64_t) pfn_list;
+    /*
+     * Corresponding list of access settings for pfn_list
+     * Used only with XENMEM_access_op_set_access_multi
+     */
+    XEN_GUEST_HANDLE(uint8) access_list;
 };
 typedef struct xen_mem_access_op xen_mem_access_op_t;
 DEFINE_XEN_GUEST_HANDLE(xen_mem_access_op_t);
xen/include/xen/p2m-common.h +6 -0
index b4f9077..384d2bf 100644
@@ -53,6 +53,12 @@ long p2m_set_mem_access(struct domain *d, gfn_t gfn, uint32_t nr,
                         uint32_t start, uint32_t mask, xenmem_access_t access,
                         unsigned int altp2m_idx);
 
+long p2m_set_mem_access_multi(struct domain *d,
+                              XEN_GUEST_HANDLE(uint64_t) pfn_list,
+                              XEN_GUEST_HANDLE(uint8) access,
+                              uint32_t size, uint32_t start, uint32_t mask,
+                              unsigned int altp2m_idx);
+
 /*
  * Get access type for a gfn.
  * If gfn == INVALID_GFN, gets the default access type.
xen/include/xlat.lst +1 -1
index 801a1c1..bdf1d05 100644
@@ -68,7 +68,7 @@
 !	memory_exchange			memory.h
 !	memory_map			memory.h
 !	memory_reservation		memory.h
-?	mem_access_op			memory.h
+!	mem_access_op			memory.h
 !	pod_target			memory.h
 !	remove_from_physmap		memory.h
 !	reserved_device_memory_map	memory.h
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Acked-by on v2 1/1
#1 lore raw
Quoted 27 lines · Razvan Cojocaru

Currently it is only possible to set mem_access restrictions only for a contiguous range of GFNs (or, as a particular case, for a single GFN). This patch introduces a new libxc function taking an array of GFNs. The alternative would be to set each page in turn, using a userspace-HV roundtrip for each call, and triggering a TLB flush per page set.

---
Changes since V1 / RFC:
- Renamed xc_set_mem_access_sparse() to xc_set_mem_access_multi(), and XENMEM_access_op_set_access_sparse to XENMEM_access_op_set_access_multi.
- Renamed the 'nr' parameter to 'size'.
- Wrapped long line in the implementation of xc_set_mem_access_multi().
- Factored out common code in _p2m_set_mem_access() (and modified p2m_set_altp2m_mem_access() in the process, to take an unsigned long argument instead of a gfn_t).
- Factored out xenmem_access_t to p2m_access_t conversion code in p2m_xenmem_access_to_p2m_access().
- Added hypercall continuation support.
- Added compat translation support.
- No longer allocating buffers (now using copy_from_guest_offset()).
- Added support for setting an array of access restrictions, as suggested by Tamas Lengyel.
- This patch incorporates Jan Beulich's "memory: fix compat handling of XENMEM_access_op".

Quoted 3 lines
---
 tools/libxc/include/xenctrl.h |   4 ++
 tools/libxc/xc_mem_access.c   |  38 ++++++++++

FAOD I am happy with hv maintainers handle this patch.

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

#2 lore raw
In reply to Razvan Cojocaru
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 02.09.16 at 10:51, <[email protected]> wrote:

Changes since V1 / RFC:
- Renamed xc_set_mem_access_sparse() to xc_set_mem_access_multi(), and XENMEM_access_op_set_access_sparse to XENMEM_access_op_set_access_multi.
- Renamed the 'nr' parameter to 'size'.

Why?

Quoted 5 lines

- Wrapped long line in the implementation of xc_set_mem_access_multi().
- Factored out common code in _p2m_set_mem_access() (and modified p2m_set_altp2m_mem_access() in the process, to take an unsigned long argument instead of a gfn_t).
- Factored out xenmem_access_t to p2m_access_t conversion code in

Quoted 8 lines

p2m_xenmem_access_to_p2m_access().
- Added hypercall continuation support.
- Added compat translation support.
- No longer allocating buffers (now using copy_from_guest_offset()).
- Added support for setting an array of access restrictions, as suggested by Tamas Lengyel.
- This patch incorporates Jan Beulich's "memory: fix compat handling of XENMEM_access_op".

I'm not sure that's okay; I'd have preferred you make the other patch a prereq (not the least because that one may want backporting, while this one certainly won't). In no event should such a bug fix go without mentioning in the commit message.

xen/arch/x86/mm/p2m.c bool_t p2m_mem_access_check(paddr_t gpa, unsigned long gla, · line 1777

Quoted 7 lines
xen/arch/x86/mm/p2m.c +1 -1
@@ -1772,13 +1773,12 @@ bool_t p2m_mem_access_check(paddr_t gpa, unsigned long gla,
 static inline
 int p2m_set_altp2m_mem_access(struct domain *d, struct p2m_domain *hp2m,
                               struct p2m_domain *ap2m, p2m_access_t a,
-                              gfn_t gfn)
+                              unsigned long gfn_l)
 {

I'm not really happy about such a step backwards.

xen/arch/x86/mm/p2m.c int p2m_set_altp2m_mem_access(struct domain *d, struct p2m_domain *hp2m, · line 1815

Quoted 13 lines
xen/arch/x86/mm/p2m.c +2 -7
@@ -1811,21 +1811,39 @@ int p2m_set_altp2m_mem_access(struct domain *d, struct p2m_domain *hp2m,
                          (current->domain != d));
 }
 
-/*
- * Set access type for a region of gfns.
- * If gfn == INVALID_GFN, sets the default access type.
- */
-long p2m_set_mem_access(struct domain *d, gfn_t gfn, uint32_t nr,
-                        uint32_t start, uint32_t mask, xenmem_access_t access,
-                        unsigned int altp2m_idx)
+static inline
+int _p2m_set_mem_access(struct domain *d, struct p2m_domain *p2m,

Considering the file we're in, can't this just be set_mem_access()?

Also I'd leave the inlining decision completely to the compiler.

Quoted 7 lines
xen/arch/x86/mm/p2m.c +2 -4
+                        struct p2m_domain *ap2m, p2m_access_t a,
+                        unsigned long gfn_l)
 {
-    struct p2m_domain *p2m = p2m_get_hostp2m(d), *ap2m = NULL;
-    p2m_access_t a, _a;
-    p2m_type_t t;
-    mfn_t mfn;

xen/arch/x86/mm/p2m.c int p2m_set_altp2m_mem_access(struct domain *d, struct p2m_domain *hp2m, · line 1826

Quoted 10 lines
xen/arch/x86/mm/p2m.c +7 -2
-    unsigned long gfn_l;
-    long rc = 0;
+    int rc;
 
+    if ( ap2m )
+    {
+        rc = p2m_set_altp2m_mem_access(d, p2m, ap2m, a, gfn_l);
+        /* If the corresponding mfn is invalid we will want to just skip it */
+        if ( rc && rc != -ESRCH )
+            return rc;

If you just converted -ESRCH to 0 here, you could then ...

xen/arch/x86/mm/p2m.c int p2m_set_altp2m_mem_access(struct domain *d, struct p2m_domain *hp2m, · line 1836

Quoted 10 lines
xen/arch/x86/mm/p2m.c +10 -0
+    }
+    else
+    {
+        mfn_t mfn;
+        p2m_access_t _a;
+        p2m_type_t t;
+
+        mfn = p2m->get_entry(p2m, gfn_l, &t, &_a, 0, NULL, NULL);
+        rc = p2m->set_entry(p2m, gfn_l, mfn, PAGE_ORDER_4K, t, a, -1);
+        return rc;

... ditch this extra return path and ...

xen/arch/x86/mm/p2m.c int p2m_set_altp2m_mem_access(struct domain *d, struct p2m_domain *hp2m, · line 1839

Quoted 3 lines
xen/arch/x86/mm/p2m.c +3 -0
+    }
+
+    return 0;

... have both cases come here.

Quoted 5 lines
xen/arch/x86/mm/p2m.c +0 -1
@@ -1851,17 +1897,8 @@ long p2m_set_mem_access(struct domain *d, gfn_t gfn, uint32_t nr,
         ap2m = d->arch.altp2m_p2m[altp2m_idx];
     }
 
-    switch ( access )

xen/arch/x86/mm/p2m.c long p2m_set_mem_access(struct domain *d, gfn_t gfn, uint32_t nr, · line 1901

Quoted 10 lines
xen/arch/x86/mm/p2m.c +1 -8
-    {
-    case 0 ... ARRAY_SIZE(memaccess) - 1:
-        a = memaccess[access];
-        break;
-    case XENMEM_access_default:
-        a = p2m->default_access;
-        break;
-    default:
+    if ( p2m_xenmem_access_to_p2m_access(p2m, access, &a) )
         return -EINVAL;

Either you make the helper function return bool, or you pass on whatever value it returned instead of assuming it's -EINVAL.

Quoted 19 lines
xen/arch/x86/mm/p2m.c +19 -0
+long p2m_set_mem_access_multi(struct domain *d,
+                              XEN_GUEST_HANDLE(uint64_t) pfn_list,
+                              XEN_GUEST_HANDLE(uint8) access_list,
+                              uint32_t size, uint32_t start, uint32_t mask,
+                              unsigned int altp2m_idx)
+{
+    struct p2m_domain *p2m = p2m_get_hostp2m(d), *ap2m = NULL;
+    long rc = 0;
+
+    /* altp2m view 0 is treated as the hostp2m */
+    if ( altp2m_idx )
+    {
+        if ( altp2m_idx >= MAX_ALTP2M ||
+             d->arch.altp2m_eptp[altp2m_idx] == mfn_x(INVALID_MFN) )
+            return -EINVAL;
+
+        ap2m = d->arch.altp2m_p2m[altp2m_idx];
+    }
+

xen/arch/x86/mm/p2m.c long p2m_set_mem_access(struct domain *d, gfn_t gfn, uint32_t nr, · line 1964

Quoted 10 lines
xen/arch/x86/mm/p2m.c +10 -0
+    p2m_lock(p2m);
+    if ( ap2m )
+        p2m_lock(ap2m);
+
+    while ( start < size )
+    {
+        p2m_access_t a;
+
+        uint8_t access;
+        uint64_t gfn_l;

Stray blank line between declarations.

Quoted 10 lines
xen/common/compat/memory.c +6 -0
@@ -320,6 +321,23 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat)
             break;
         }
 
+        case XENMEM_access_op:
+        {
+#define XLAT_mem_access_op_HNDL_pfn_list(_d_, _s_) \
+            guest_from_compat_handle((_d_)->pfn_list, (_s_)->pfn_list)
+#define XLAT_mem_access_op_HNDL_access_list(_d_, _s_) \
+            guest_from_compat_handle((_d_)->access_list, (_s_)->access_list)

xen/common/compat/memory.c int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat) · line 339

Quoted 10 lines
xen/common/compat/memory.c +10 -0
+
+            XLAT_mem_access_op(nat.mao, &cmp.mao);
+
+#undef XLAT_mem_access_op_HNDL_pfn_list
+#undef XLAT_mem_access_op_HNDL_access_list
+
+            return mem_access_memop(cmd,
+                                    guest_handle_cast(compat,
+                                                      xen_mem_access_op_t));
+        }

You translate into native format, but then cast the compat handle to its native counterpart type. Such casting is okay only when accompanied by a respectively invoked CHECK_* macro. Please follow the model other code here uses.

And reviewing this I notice that my earlier bug fix also is still not really correct: It causes hypercall_xlat_continuation() to be bypassed.

xen/include/public/memory.h struct xen_mem_access_op { · line 461

Quoted 9 lines
xen/include/public/memory.h +5 -0
@@ -452,6 +454,16 @@ struct xen_mem_access_op {
      * ~0ull is used to set and get the default access for pages
      */
     uint64_aligned_t pfn;
+    /*
+     * List of pfns to set access for
+     * Used only with XENMEM_access_op_set_access_multi
+     */
+    XEN_GUEST_HANDLE(uint64_t) pfn_list;

I'm not sure why we even have this kind of handle - please use XEN_GUEST_HANDLE(uint64) instead.

xen/include/public/memory.h struct xen_mem_access_op { · line 466

Quoted 5 lines
xen/include/public/memory.h +5 -0
+    /*
+     * Corresponding list of access settings for pfn_list
+     * Used only with XENMEM_access_op_set_access_multi
+     */
+    XEN_GUEST_HANDLE(uint8) access_list;

And for both of them - I don't think the arrays are meant to be used for output? In which case they should be handles of const types.

Jan

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

#3 lore raw
Quoted 28 lines
Quoted 12 lines
Quoted 2 lines · On 02.09.16 at 12:02, <[email protected]> wrote:
Quoted 1 line · On 02.09.16 at 10:51, <[email protected]> wrote:
xen/common/compat/memory.c +6 -0
@@ -320,6 +321,23 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat)
             break;
         }
 
+        case XENMEM_access_op:
+        {
+#define XLAT_mem_access_op_HNDL_pfn_list(_d_, _s_) \
+            guest_from_compat_handle((_d_)->pfn_list, (_s_)->pfn_list)
+#define XLAT_mem_access_op_HNDL_access_list(_d_, _s_) \
+            guest_from_compat_handle((_d_)->access_list, (_s_)->access_list)

xen/common/compat/memory.c int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat) · line 339

Quoted 10 lines
xen/common/compat/memory.c +10 -0
+
+            XLAT_mem_access_op(nat.mao, &cmp.mao);
+
+#undef XLAT_mem_access_op_HNDL_pfn_list
+#undef XLAT_mem_access_op_HNDL_access_list
+
+            return mem_access_memop(cmd,
+                                    guest_handle_cast(compat,
+                                                      xen_mem_access_op_t));
+        }

You translate into native format, but then cast the compat handle to its native counterpart type. Such casting is okay only when accompanied by a respectively invoked CHECK_* macro. Please follow the model other code here uses.

Quoted 3 lines

And reviewing this I notice that my earlier bug fix also is still not really correct: It causes hypercall_xlat_continuation() to be bypassed.

Actually no, that patch is fine because it (legitimately) uses a cast. You would introduce the bypassing problem here as soon as you properly handed the native handle to mem_access_memop().

Jan

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

#4 lore raw
In reply to Jan Beulich
Quoted 8 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 02.09.16 at 10:51, <[email protected]> wrote:

Changes since V1 / RFC:
- Renamed xc_set_mem_access_sparse() to xc_set_mem_access_multi(), and XENMEM_access_op_set_access_sparse to XENMEM_access_op_set_access_multi.
- Renamed the 'nr' parameter to 'size'.

Why?

Tamas suggested it, size sounded more intuitive to him. I have no problem with either nr or size.

Quoted 14 lines
Quoted 5 lines

- Wrapped long line in the implementation of xc_set_mem_access_multi().
- Factored out common code in _p2m_set_mem_access() (and modified p2m_set_altp2m_mem_access() in the process, to take an unsigned long argument instead of a gfn_t).
- Factored out xenmem_access_t to p2m_access_t conversion code in

Quoted 8 lines

p2m_xenmem_access_to_p2m_access().
- Added hypercall continuation support.
- Added compat translation support.
- No longer allocating buffers (now using copy_from_guest_offset()).
- Added support for setting an array of access restrictions, as suggested by Tamas Lengyel.
- This patch incorporates Jan Beulich's "memory: fix compat handling of XENMEM_access_op".

Quoted 4 lines

I'm not sure that's okay; I'd have preferred you make the other patch a prereq (not the least because that one may want backporting, while this one certainly won't). In no event should such a bug fix go without mentioning in the commit message.

I agree, this is here simply because looking at the state of staging, the patch hadn't yet made it in, and I was trying to be efficient and have an intermediate review anyway. I'll manually apply your patch before mine and remove that code from this patch.

Quoted 9 lines

xen/arch/x86/mm/p2m.c bool_t p2m_mem_access_check(paddr_t gpa, unsigned long gla, · line 1777

Quoted 7 lines
xen/arch/x86/mm/p2m.c +1 -1
@@ -1772,13 +1773,12 @@ bool_t p2m_mem_access_check(paddr_t gpa, unsigned long gla,
 static inline
 int p2m_set_altp2m_mem_access(struct domain *d, struct p2m_domain *hp2m,
                               struct p2m_domain *ap2m, p2m_access_t a,
-                              gfn_t gfn)
+                              unsigned long gfn_l)
 {

I'm not really happy about such a step backwards.

I'll keep p2m_set_altp2m_mem_access() as it is then. I just thought that going from unsigned long to gfn_t just to have to go back to unsigned long slightly clutters up the code, but it's certainly not a huge difference.

Quoted 4 lines
Quoted 4 lines
xen/arch/x86/mm/p2m.c +0 -0
@@ -1811,21 +1811,39 @@ int p2m_set_altp2m_mem_access(struct domain *d, struct p2m_domain *hp2m,
                          (current->domain != d));
 }
 
Quoted 11 lines

xen/arch/x86/mm/p2m.c int p2m_set_altp2m_mem_access(struct domain *d, struct p2m_domain *hp2m, · line 1815

Quoted 9 lines
xen/arch/x86/mm/p2m.c +2 -7
-/*
- * Set access type for a region of gfns.
- * If gfn == INVALID_GFN, sets the default access type.
- */
-long p2m_set_mem_access(struct domain *d, gfn_t gfn, uint32_t nr,
-                        uint32_t start, uint32_t mask, xenmem_access_t access,
-                        unsigned int altp2m_idx)
+static inline
+int _p2m_set_mem_access(struct domain *d, struct p2m_domain *p2m,

Considering the file we're in, can't this just be set_mem_access()?

Of course, I'll rename it.

Quoted 1 line

Also I'd leave the inlining decision completely to the compiler.

I took that cue from p2m_set_altp2m_mem_access() above. I'll remove the inline.

Quoted 31 lines
Quoted 7 lines
xen/arch/x86/mm/p2m.c +2 -4
+                        struct p2m_domain *ap2m, p2m_access_t a,
+                        unsigned long gfn_l)
 {
-    struct p2m_domain *p2m = p2m_get_hostp2m(d), *ap2m = NULL;
-    p2m_access_t a, _a;
-    p2m_type_t t;
-    mfn_t mfn;

xen/arch/x86/mm/p2m.c int p2m_set_altp2m_mem_access(struct domain *d, struct p2m_domain *hp2m, · line 1826

Quoted 10 lines
xen/arch/x86/mm/p2m.c +7 -2
-    unsigned long gfn_l;
-    long rc = 0;
+    int rc;
 
+    if ( ap2m )
+    {
+        rc = p2m_set_altp2m_mem_access(d, p2m, ap2m, a, gfn_l);
+        /* If the corresponding mfn is invalid we will want to just skip it */
+        if ( rc && rc != -ESRCH )
+            return rc;

If you just converted -ESRCH to 0 here, you could then ...

xen/arch/x86/mm/p2m.c int p2m_set_altp2m_mem_access(struct domain *d, struct p2m_domain *hp2m, · line 1836

Quoted 10 lines
xen/arch/x86/mm/p2m.c +10 -0
+    }
+    else
+    {
+        mfn_t mfn;
+        p2m_access_t _a;
+        p2m_type_t t;
+
+        mfn = p2m->get_entry(p2m, gfn_l, &t, &_a, 0, NULL, NULL);
+        rc = p2m->set_entry(p2m, gfn_l, mfn, PAGE_ORDER_4K, t, a, -1);
+        return rc;
Quoted 7 lines

... ditch this extra return path and ...

xen/arch/x86/mm/p2m.c int p2m_set_altp2m_mem_access(struct domain *d, struct p2m_domain *hp2m, · line 1839

Quoted 3 lines
xen/arch/x86/mm/p2m.c +3 -0
+    }
+
+    return 0;

... have both cases come here.

I'll do that.

Quoted 4 lines
Quoted 4 lines
xen/arch/x86/mm/p2m.c +0 -0
@@ -1851,17 +1897,8 @@ long p2m_set_mem_access(struct domain *d, gfn_t gfn, uint32_t nr,
         ap2m = d->arch.altp2m_p2m[altp2m_idx];
     }
 
Quoted 14 lines

xen/arch/x86/mm/p2m.c long p2m_set_mem_access(struct domain *d, gfn_t gfn, uint32_t nr, · line 1901

Quoted 11 lines
xen/arch/x86/mm/p2m.c +1 -9
-    switch ( access )
-    {
-    case 0 ... ARRAY_SIZE(memaccess) - 1:
-        a = memaccess[access];
-        break;
-    case XENMEM_access_default:
-        a = p2m->default_access;
-        break;
-    default:
+    if ( p2m_xenmem_access_to_p2m_access(p2m, access, &a) )
         return -EINVAL;

Either you make the helper function return bool, or you pass on whatever value it returned instead of assuming it's -EINVAL.

Fair enough, I'll return bool.

Quoted 23 lines
Quoted 23 lines
xen/arch/x86/mm/p2m.c +23 -0
+long p2m_set_mem_access_multi(struct domain *d,
+                              XEN_GUEST_HANDLE(uint64_t) pfn_list,
+                              XEN_GUEST_HANDLE(uint8) access_list,
+                              uint32_t size, uint32_t start, uint32_t mask,
+                              unsigned int altp2m_idx)
+{
+    struct p2m_domain *p2m = p2m_get_hostp2m(d), *ap2m = NULL;
+    long rc = 0;
+
+    /* altp2m view 0 is treated as the hostp2m */
+    if ( altp2m_idx )
+    {
+        if ( altp2m_idx >= MAX_ALTP2M ||
+             d->arch.altp2m_eptp[altp2m_idx] == mfn_x(INVALID_MFN) )
+            return -EINVAL;
+
+        ap2m = d->arch.altp2m_p2m[altp2m_idx];
+    }
+
+    p2m_lock(p2m);
+    if ( ap2m )
+        p2m_lock(ap2m);
+
Quoted 8 lines

xen/arch/x86/mm/p2m.c long p2m_set_mem_access(struct domain *d, gfn_t gfn, uint32_t nr, · line 1964

Quoted 6 lines
xen/arch/x86/mm/p2m.c +6 -0
+    while ( start < size )
+    {
+        p2m_access_t a;
+
+        uint8_t access;
+        uint64_t gfn_l;

Stray blank line between declarations.

Will remove it.

Quoted 17 lines
Quoted 17 lines
xen/common/compat/memory.c +13 -0
@@ -320,6 +321,23 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat)
             break;
         }
 
+        case XENMEM_access_op:
+        {
+#define XLAT_mem_access_op_HNDL_pfn_list(_d_, _s_) \
+            guest_from_compat_handle((_d_)->pfn_list, (_s_)->pfn_list)
+#define XLAT_mem_access_op_HNDL_access_list(_d_, _s_) \
+            guest_from_compat_handle((_d_)->access_list, (_s_)->access_list)
+
+            XLAT_mem_access_op(nat.mao, &cmp.mao);
+
+#undef XLAT_mem_access_op_HNDL_pfn_list
+#undef XLAT_mem_access_op_HNDL_access_list
+
+            return mem_access_memop(cmd,
Quoted 8 lines

xen/common/compat/memory.c int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat) · line 339

Quoted 3 lines
xen/common/compat/memory.c +3 -0
+                                    guest_handle_cast(compat,
+                                                      xen_mem_access_op_t));
+        }

You translate into native format, but then cast the compat handle to its native counterpart type. Such casting is okay only when accompanied by a respectively invoked CHECK_* macro. Please follow the model other code here uses.

I'll follow the model.

Quoted 3 lines

And reviewing this I notice that my earlier bug fix also is still not really correct: It causes hypercall_xlat_continuation() to be bypassed.

Since you've addressed this comment in a subsequent reply, no need to continue here.

Quoted 4 lines
Quoted 4 lines
xen/include/public/memory.h +0 -0
@@ -452,6 +454,16 @@ struct xen_mem_access_op {
      * ~0ull is used to set and get the default access for pages
      */
     uint64_aligned_t pfn;
Quoted 8 lines

xen/include/public/memory.h struct xen_mem_access_op { · line 461

Quoted 5 lines
xen/include/public/memory.h +5 -0
+    /*
+     * List of pfns to set access for
+     * Used only with XENMEM_access_op_set_access_multi
+     */
+    XEN_GUEST_HANDLE(uint64_t) pfn_list;

I'm not sure why we even have this kind of handle - please use XEN_GUEST_HANDLE(uint64) instead.

I'll change it.

Quoted 9 lines

xen/include/public/memory.h struct xen_mem_access_op { · line 466

Quoted 5 lines
xen/include/public/memory.h +5 -0
+    /*
+     * Corresponding list of access settings for pfn_list
+     * Used only with XENMEM_access_op_set_access_multi
+     */
+    XEN_GUEST_HANDLE(uint8) access_list;

And for both of them - I don't think the arrays are meant to be used for output? In which case they should be handles of const types.

No, they're indeed not meant for output. I'll constify the code.

Thanks,
Razvan

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

#5 lore raw
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 02.09.16 at 13:18, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 02.09.16 at 10:51, <[email protected]> wrote:

Changes since V1 / RFC:
- Renamed xc_set_mem_access_sparse() to xc_set_mem_access_multi(), and XENMEM_access_op_set_access_sparse to XENMEM_access_op_set_access_multi.
- Renamed the 'nr' parameter to 'size'.

Quoted 4 lines
Quoted 1 line

Why?

Tamas suggested it, size sounded more intuitive to him. I have no problem with either nr or size.

Size to me means something in bytes, which clearly isn't the case here. There's not even support for other then 4k pages so far.

Jan

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

#6 lore raw
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 2 lines
Quoted 2 lines · On 02.09.16 at 13:18, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 02.09.16 at 10:51, <[email protected]> wrote:

Changes since V1 / RFC:
- Renamed xc_set_mem_access_sparse() to xc_set_mem_access_multi(), and XENMEM_access_op_set_access_sparse to XENMEM_access_op_set_access_multi.
- Renamed the 'nr' parameter to 'size'.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Why?

Tamas suggested it, size sounded more intuitive to him. I have no problem with either nr or size.

Size to me means something in bytes, which clearly isn't the case here. There's not even support for other then 4k pages so far.

Lets make it array_size then to clarify?

Tamas

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

#7 lore raw
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 02.09.16 at 16:50, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 2 lines
Quoted 2 lines · On 02.09.16 at 13:18, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 02.09.16 at 10:51, <[email protected]> wrote:

Changes since V1 / RFC:
- Renamed xc_set_mem_access_sparse() to xc_set_mem_access_multi(), and XENMEM_access_op_set_access_sparse to XENMEM_access_op_set_access_multi.
- Renamed the 'nr' parameter to 'size'.

Why?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Tamas suggested it, size sounded more intuitive to him. I have no problem with either nr or size.

Size to me means something in bytes, which clearly isn't the case here. There's not even support for other then 4k pages so far.

Lets make it array_size then to clarify?

What's wrong with "nr", matching the other (existing) function?

Jan

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

#8 lore raw
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 2 lines
Quoted 2 lines · On 02.09.16 at 16:50, <[email protected]> wrote:
Quoted 15 lines · Jan Beulich
Quoted 14 lines
Quoted 2 lines
Quoted 2 lines · On 02.09.16 at 13:18, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 02.09.16 at 10:51, <[email protected]> wrote:

Changes since V1 / RFC:
- Renamed xc_set_mem_access_sparse() to xc_set_mem_access_multi(), and XENMEM_access_op_set_access_sparse to XENMEM_access_op_set_access_multi.
- Renamed the 'nr' parameter to 'size'.

Why?

Tamas suggested it, size sounded more intuitive to him. I have no problem with either nr or size.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Size to me means something in bytes, which clearly isn't the case here. There's not even support for other then 4k pages so far.

Lets make it array_size then to clarify?

What's wrong with "nr", matching the other (existing) function?

IMHO it's too generic. So either a more descriptive name or a comment is warranted to explain the inputs.

Tamas

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

#9 lore raw
Quoted 27 lines · Tamas K Lengyel
Quoted 2 lines · On Sep 2, 2016 09:03, "Jan Beulich" <[email protected]…
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

On 02.09.16 at 16:50, <[email protected]

Quoted 1 line · <mailto:[email protected]>> wrote:
Quoted 1 line

On Sep 2, 2016 05:45, "Jan Beulich" <[email protected]

Quoted 2 lines · <mailto:[email protected]>> wrote:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

On 02.09.16 at 13:18, <[email protected]

Quoted 2 lines · <mailto:[email protected]>> wrote:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

On 02.09.16 at 10:51, <[email protected]

Quoted 14 lines · <mailto:[email protected]>> wrote:
Quoted 14 lines
Quoted 13 lines
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines

Changes since V1 / RFC:
- Renamed xc_set_mem_access_sparse() to xc_set_mem_access_multi(), and XENMEM_access_op_set_access_sparse to XENMEM_access_op_set_access_multi.
- Renamed the 'nr' parameter to 'size'.

Why?

Tamas suggested it, size sounded more intuitive to him. I have no problem with either nr or size.

Size to me means something in bytes, which clearly isn't the case here. There's not even support for other then 4k pages so far.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Lets make it array_size then to clarify?

What's wrong with "nr", matching the other (existing) function?

IMHO it's too generic. So either a more descriptive name or a comment is warranted to explain the inputs.

If this satisfies everybody, I'll keep 'nr' and add a comment describing the function and parameters (which is a good thing anyway).

Thanks,
Razvan

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

#10 lore raw
Quoted 10 lines · Razvan Cojocaru
Quoted 8 lines · Tamas K Lengyel
Quoted 2 lines · On Sep 2, 2016 09:03, "Jan Beulich" <[email protected]…
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

On 02.09.16 at 16:50, <[email protected]

Quoted 1 line · <mailto:[email protected]>> wrote:
Quoted 1 line

On Sep 2, 2016 05:45, "Jan Beulich" <[email protected]

Quoted 1 line · <mailto:[email protected]>> wrote:
Quoted 1 line
Quoted 1 line
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

On 02.09.16 at 13:18, <[email protected]

Quoted 2 lines · <mailto:[email protected]>> wrote:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

On 02.09.16 at 10:51, <[email protected]

Quoted 2 lines · <mailto:[email protected]>> wrote:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Changes since V1 / RFC:
- Renamed xc_set_mem_access_sparse() to

xc_set_mem_access_multi(),

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 11 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

and XENMEM_access_op_set_access_sparse to
XENMEM_access_op_set_access_multi.
- Renamed the 'nr' parameter to 'size'.

Why?

Tamas suggested it, size sounded more intuitive to him. I have no problem with either nr or size.

Size to me means something in bytes, which clearly isn't the case here. There's not even support for other then 4k pages so far.

Lets make it array_size then to clarify?

Quoted 10 lines
Quoted 5 lines
Quoted 2 lines

What's wrong with "nr", matching the other (existing) function?

IMHO it's too generic. So either a more descriptive name or a comment is warranted to explain the inputs.

If this satisfies everybody, I'll keep 'nr' and add a comment describing the function and parameters (which is a good thing anyway).

SGTM.

Thanks,
Tamas

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

#11 lore raw
In reply to Jan Beulich
Quoted 8 lines · Jan Beulich
Quoted 5 lines

+ /*

Quoted 4 lines
xen/include/public/memory.h +4 -0
+     * Corresponding list of access settings for pfn_list
+     * Used only with XENMEM_access_op_set_access_multi
+     */
+    XEN_GUEST_HANDLE(uint8) access_list;

And for both of them - I don't think the arrays are meant to be used for output? In which case they should be handles of const types.

Actually I can't seem to be able to find a magic combination that works.

XEN_GUEST_HANDLE(const uint8) access_list; tells me:

./public/arch-x86/xen.h:53:41: error: '__guest_handle_const' does not name a type
#define __XEN_GUEST_HANDLE(name) __guest_handle_ ## name

which is fair. I've tried:

XEN_GUEST_HANDLE(const_uint8) access_list;

which does go further with the compilation process, but still kills it with:

xen/include/compat/memory.h:154:5: error: unknown type name '__compat_handle_const_uint8'

     COMPAT_HANDLE(const_uint8) access_list;

What would be the appropriate const type to use here?

Thanks,
Razvan

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

#12 lore raw
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 02.09.16 at 14:21, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 5 lines

+ /*

Quoted 4 lines
xen/include/public/memory.h +4 -0
+     * Corresponding list of access settings for pfn_list
+     * Used only with XENMEM_access_op_set_access_multi
+     */
+    XEN_GUEST_HANDLE(uint8) access_list;

And for both of them - I don't think the arrays are meant to be used for output? In which case they should be handles of const types.

Actually I can't seem to be able to find a magic combination that works.

XEN_GUEST_HANDLE(const uint8) access_list; tells me:

./public/arch-x86/xen.h:53:41: error: '__guest_handle_const' does not name a type
#define __XEN_GUEST_HANDLE(name) __guest_handle_ ## name

which is fair. I've tried:

XEN_GUEST_HANDLE(const_uint8) access_list;

Quoted 7 lines

which does go further with the compilation process, but still kills it with:

xen/include/compat/memory.h:154:5: error: unknown type name '__compat_handle_const_uint8'

     COMPAT_HANDLE(const_uint8) access_list;

What would be the appropriate const type to use here?

This one. Did you check that handle actually gets created? Per my brief checking it doesn't look so. And neither the native one.

Jan

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

#13 lore raw
Quoted 25 lines · Jan Beulich
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 02.09.16 at 14:21, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 5 lines

+ /*

Quoted 4 lines
xen/include/public/memory.h +4 -0
+     * Corresponding list of access settings for pfn_list
+     * Used only with XENMEM_access_op_set_access_multi
+     */
+    XEN_GUEST_HANDLE(uint8) access_list;

And for both of them - I don't think the arrays are meant to be used for output? In which case they should be handles of const types.

Actually I can't seem to be able to find a magic combination that works.

XEN_GUEST_HANDLE(const uint8) access_list; tells me:

./public/arch-x86/xen.h:53:41: error: '__guest_handle_const' does not name a type
#define __XEN_GUEST_HANDLE(name) __guest_handle_ ## name

which is fair. I've tried:

XEN_GUEST_HANDLE(const_uint8) access_list;

which does go further with the compilation process, but still kills it with:

Quoted 8 lines
Quoted 5 lines

xen/include/compat/memory.h:154:5: error: unknown type name '__compat_handle_const_uint8'

     COMPAT_HANDLE(const_uint8) access_list;

What would be the appropriate const type to use here?

This one. Did you check that handle actually gets created? Per my brief checking it doesn't look so. And neither the native one.

Running ./configure again, followed by 'make clean' and a new 'make dist' didn't help, so if it's supposed to be generated automatically it doesn't seem to be (or I'm doing something wrong). I'll investigate more.

Thanks,
Razvan

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

#14 lore raw
Quoted 31 lines
Quoted 1 line
Quoted 1 line · On 02.09.16 at 14:41, <[email protected]> wrote:
Quoted 29 lines · Jan Beulich
Quoted 29 lines
Quoted 1 line
Quoted 1 line · On 02.09.16 at 14:21, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 5 lines

+ /*

Quoted 4 lines
xen/include/public/memory.h +4 -0
+     * Corresponding list of access settings for pfn_list
+     * Used only with XENMEM_access_op_set_access_multi
+     */
+    XEN_GUEST_HANDLE(uint8) access_list;

And for both of them - I don't think the arrays are meant to be used for output? In which case they should be handles of const types.

Actually I can't seem to be able to find a magic combination that works.

XEN_GUEST_HANDLE(const uint8) access_list; tells me:

./public/arch-x86/xen.h:53:41: error: '__guest_handle_const' does not name a type
#define __XEN_GUEST_HANDLE(name) __guest_handle_ ## name

which is fair. I've tried:

XEN_GUEST_HANDLE(const_uint8) access_list;

which does go further with the compilation process, but still kills it with:

xen/include/compat/memory.h:154:5: error: unknown type name '__compat_handle_const_uint8'

     COMPAT_HANDLE(const_uint8) access_list;
Quoted 8 lines
Quoted 4 lines
Quoted 1 line

What would be the appropriate const type to use here?

This one. Did you check that handle actually gets created? Per my brief checking it doesn't look so. And neither the native one.

Running ./configure again, followed by 'make clean' and a new 'make dist' didn't help, so if it's supposed to be generated automatically it doesn't seem to be (or I'm doing something wrong). I'll investigate more.

The compat one is supposed to get auto-generated once the native one is there.

Jan

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

#15 lore raw
Quoted 36 lines · Jan Beulich
Quoted 36 lines
Quoted 1 line
Quoted 1 line · On 02.09.16 at 14:41, <[email protected]> wrote:
Quoted 33 lines · Jan Beulich
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 02.09.16 at 14:21, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 5 lines

+ /*

Quoted 4 lines
xen/include/public/memory.h +4 -0
+     * Corresponding list of access settings for pfn_list
+     * Used only with XENMEM_access_op_set_access_multi
+     */
+    XEN_GUEST_HANDLE(uint8) access_list;

And for both of them - I don't think the arrays are meant to be used for output? In which case they should be handles of const types.

Actually I can't seem to be able to find a magic combination that works.

XEN_GUEST_HANDLE(const uint8) access_list; tells me:

./public/arch-x86/xen.h:53:41: error: '__guest_handle_const' does not name a type
#define __XEN_GUEST_HANDLE(name) __guest_handle_ ## name

which is fair. I've tried:

XEN_GUEST_HANDLE(const_uint8) access_list;

Quoted 7 lines

which does go further with the compilation process, but still kills it with:

xen/include/compat/memory.h:154:5: error: unknown type name '__compat_handle_const_uint8'

     COMPAT_HANDLE(const_uint8) access_list;

What would be the appropriate const type to use here?

This one. Did you check that handle actually gets created? Per my brief checking it doesn't look so. And neither the native one.

Quoted 6 lines
Quoted 3 lines

Running ./configure again, followed by 'make clean' and a new 'make dist' didn't help, so if it's supposed to be generated automatically it doesn't seem to be (or I'm doing something wrong). I'll investigate more.

The compat one is supposed to get auto-generated once the native one is there.

Changing both handles to XEN_GUEST_HANLDE(const_void) compiles cleanly. As soon as I change to either XEN_GUEST_HANLDE(const_uint8) or XEN_GUEST_HANLDE(const_uint64) I start getting errors.

Previously the auto-generation seems to have worked fine, so this is likely something more subtle.

Thanks,
Razvan

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

#16 lore raw
Quoted 45 lines
Quoted 1 line
Quoted 1 line · On 02.09.16 at 15:03, <[email protected]> wrote:
Quoted 36 lines · Jan Beulich
Quoted 36 lines
Quoted 1 line
Quoted 1 line · On 02.09.16 at 14:41, <[email protected]> wrote:
Quoted 33 lines · Jan Beulich
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 02.09.16 at 14:21, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 5 lines

+ /*

Quoted 4 lines
(quoted diff) +4 -0
+     * Corresponding list of access settings for pfn_list
+     * Used only with XENMEM_access_op_set_access_multi
+     */
+    XEN_GUEST_HANDLE(uint8) access_list;

And for both of them - I don't think the arrays are meant to be used for output? In which case they should be handles of const types.

Actually I can't seem to be able to find a magic combination that works.

XEN_GUEST_HANDLE(const uint8) access_list; tells me:

./public/arch-x86/xen.h:53:41: error: '__guest_handle_const' does not name a type
#define __XEN_GUEST_HANDLE(name) __guest_handle_ ## name

which is fair. I've tried:

XEN_GUEST_HANDLE(const_uint8) access_list;

Quoted 7 lines

which does go further with the compilation process, but still kills it with:

xen/include/compat/memory.h:154:5: error: unknown type name '__compat_handle_const_uint8'

     COMPAT_HANDLE(const_uint8) access_list;

What would be the appropriate const type to use here?

This one. Did you check that handle actually gets created? Per my brief checking it doesn't look so. And neither the native one.

Quoted 6 lines
Quoted 3 lines

Running ./configure again, followed by 'make clean' and a new 'make dist' didn't help, so if it's supposed to be generated automatically it doesn't seem to be (or I'm doing something wrong). I'll investigate more.

The compat one is supposed to get auto-generated once the native one is there.

Quoted 6 lines

Changing both handles to XEN_GUEST_HANLDE(const_void) compiles cleanly. As soon as I change to either XEN_GUEST_HANLDE(const_uint8) or XEN_GUEST_HANLDE(const_uint64) I start getting errors.

Previously the auto-generation seems to have worked fine, so this is likely something more subtle.

Oh, I see where the issue is: Both DEFINE_XEN_GUEST_HANDLE() and __DEFINE_XEN_GUEST_HANDLE() auto-magically produce const counterparts, but while DEFINE_COMPAT_HANDLE() does too, __DEFINE_COMPAT_HANDLE() doesn't. That'll need fixing, I think.

Jan

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

#17 lore raw
Quoted 49 lines · Jan Beulich
Quoted 49 lines
Quoted 1 line
Quoted 1 line · On 02.09.16 at 15:03, <[email protected]> wrote:
Quoted 36 lines · Jan Beulich
Quoted 36 lines
Quoted 1 line
Quoted 1 line · On 02.09.16 at 14:41, <[email protected]> wrote:
Quoted 33 lines · Jan Beulich
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 02.09.16 at 14:21, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 5 lines

+ /*

Quoted 4 lines
(quoted diff) +4 -0
+     * Corresponding list of access settings for pfn_list
+     * Used only with XENMEM_access_op_set_access_multi
+     */
+    XEN_GUEST_HANDLE(uint8) access_list;

And for both of them - I don't think the arrays are meant to be used for output? In which case they should be handles of const types.

Actually I can't seem to be able to find a magic combination that works.

XEN_GUEST_HANDLE(const uint8) access_list; tells me:

./public/arch-x86/xen.h:53:41: error: '__guest_handle_const' does not name a type
#define __XEN_GUEST_HANDLE(name) __guest_handle_ ## name

which is fair. I've tried:

XEN_GUEST_HANDLE(const_uint8) access_list;

Quoted 7 lines

which does go further with the compilation process, but still kills it with:

xen/include/compat/memory.h:154:5: error: unknown type name '__compat_handle_const_uint8'

     COMPAT_HANDLE(const_uint8) access_list;

What would be the appropriate const type to use here?

This one. Did you check that handle actually gets created? Per my brief checking it doesn't look so. And neither the native one.

Quoted 6 lines
Quoted 3 lines

Running ./configure again, followed by 'make clean' and a new 'make dist' didn't help, so if it's supposed to be generated automatically it doesn't seem to be (or I'm doing something wrong). I'll investigate more.

The compat one is supposed to get auto-generated once the native one is there.

Changing both handles to XEN_GUEST_HANLDE(const_void) compiles cleanly. As soon as I change to either XEN_GUEST_HANLDE(const_uint8) or XEN_GUEST_HANLDE(const_uint64) I start getting errors.

Quoted 7 lines
Quoted 2 lines

Previously the auto-generation seems to have worked fine, so this is likely something more subtle.

Oh, I see where the issue is: Both DEFINE_XEN_GUEST_HANDLE() and __DEFINE_XEN_GUEST_HANDLE() auto-magically produce const counterparts, but while DEFINE_COMPAT_HANDLE() does too, __DEFINE_COMPAT_HANDLE() doesn't. That'll need fixing, I think.

I see it, thanks! I'll submit a small patch shortly.

Thanks,
Razvan

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

#18 lore raw
In reply to Razvan Cojocaru

Hello Razvan,

Quoted 27 lines · Razvan Cojocaru

Currently it is only possible to set mem_access restrictions only for a contiguous range of GFNs (or, as a particular case, for a single GFN). This patch introduces a new libxc function taking an array of GFNs. The alternative would be to set each page in turn, using a userspace-HV roundtrip for each call, and triggering a TLB flush per page set.

---
Changes since V1 / RFC:
- Renamed xc_set_mem_access_sparse() to xc_set_mem_access_multi(), and XENMEM_access_op_set_access_sparse to XENMEM_access_op_set_access_multi.
- Renamed the 'nr' parameter to 'size'.
- Wrapped long line in the implementation of xc_set_mem_access_multi().
- Factored out common code in _p2m_set_mem_access() (and modified p2m_set_altp2m_mem_access() in the process, to take an unsigned long argument instead of a gfn_t).
- Factored out xenmem_access_t to p2m_access_t conversion code in p2m_xenmem_access_to_p2m_access().
- Added hypercall continuation support.
- Added compat translation support.
- No longer allocating buffers (now using copy_from_guest_offset()).
- Added support for setting an array of access restrictions, as suggested by Tamas Lengyel.
- This patch incorporates Jan Beulich's "memory: fix compat handling of XENMEM_access_op".

Quoted 8 lines
---
 tools/libxc/include/xenctrl.h |   4 ++
 tools/libxc/xc_mem_access.c   |  38 ++++++++++
 xen/arch/x86/mm/p2m.c         | 161 ++++++++++++++++++++++++++++++++----------
 xen/common/compat/memory.c    |  24 +++++--
 xen/common/mem_access.c       |  11 +++
 xen/include/public/memory.h   |  14 +++-
 xen/include/xen/p2m-common.h  |   6 ++

p2m-common.h contains prototype common between ARM and x86. I would have expected to see a change in the ARM port because of that.

Regards,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#19 lore raw
Quoted 1 line · Julien Grall

Hello Razvan,

Hello Julien, thanks for the email!

Quoted 38 lines · Razvan Cojocaru
Quoted 27 lines

Currently it is only possible to set mem_access restrictions only for a contiguous range of GFNs (or, as a particular case, for a single GFN). This patch introduces a new libxc function taking an array of GFNs. The alternative would be to set each page in turn, using a userspace-HV roundtrip for each call, and triggering a TLB flush per page set.

---
Changes since V1 / RFC:
- Renamed xc_set_mem_access_sparse() to xc_set_mem_access_multi(), and XENMEM_access_op_set_access_sparse to XENMEM_access_op_set_access_multi.
- Renamed the 'nr' parameter to 'size'.
- Wrapped long line in the implementation of xc_set_mem_access_multi().
- Factored out common code in _p2m_set_mem_access() (and modified p2m_set_altp2m_mem_access() in the process, to take an unsigned long argument instead of a gfn_t).
- Factored out xenmem_access_t to p2m_access_t conversion code in p2m_xenmem_access_to_p2m_access().
- Added hypercall continuation support.
- Added compat translation support.
- No longer allocating buffers (now using copy_from_guest_offset()).
- Added support for setting an array of access restrictions, as suggested by Tamas Lengyel.
- This patch incorporates Jan Beulich's "memory: fix compat handling of XENMEM_access_op".

Quoted 9 lines
---
 tools/libxc/include/xenctrl.h |   4 ++
 tools/libxc/xc_mem_access.c   |  38 ++++++++++
 xen/arch/x86/mm/p2m.c         | 161
++++++++++++++++++++++++++++++++----------
 xen/common/compat/memory.c    |  24 +++++--
 xen/common/mem_access.c       |  11 +++
 xen/include/public/memory.h   |  14 +++-
 xen/include/xen/p2m-common.h  |   6 ++
Quoted 2 lines

p2m-common.h contains prototype common between ARM and x86. I would have expected to see a change in the ARM port because of that.

The only change to p2m-common.h is the addition of a single function, p2m_set_mem_access_multi(). As long as the ARM bits don't make use of it, there's nothing to modify there.

Thanks,
Razvan

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

#20 lore raw
Quoted 43 lines · Razvan Cojocaru
Quoted 1 line · Julien Grall

Hello Razvan,

Hello Julien, thanks for the email!

Quoted 38 lines · Razvan Cojocaru
Quoted 36 lines

Currently it is only possible to set mem_access restrictions only for a contiguous range of GFNs (or, as a particular case, for a single GFN). This patch introduces a new libxc function taking an array of GFNs. The alternative would be to set each page in turn, using a userspace-HV roundtrip for each call, and triggering a TLB flush per page set.

---
Changes since V1 / RFC:
- Renamed xc_set_mem_access_sparse() to xc_set_mem_access_multi(), and XENMEM_access_op_set_access_sparse to XENMEM_access_op_set_access_multi.
- Renamed the 'nr' parameter to 'size'.
- Wrapped long line in the implementation of xc_set_mem_access_multi().
- Factored out common code in _p2m_set_mem_access() (and modified p2m_set_altp2m_mem_access() in the process, to take an unsigned long argument instead of a gfn_t).
- Factored out xenmem_access_t to p2m_access_t conversion code in p2m_xenmem_access_to_p2m_access().
- Added hypercall continuation support.
- Added compat translation support.
- No longer allocating buffers (now using copy_from_guest_offset()).
- Added support for setting an array of access restrictions, as suggested by Tamas Lengyel.
- This patch incorporates Jan Beulich's "memory: fix compat handling of XENMEM_access_op".

---
 tools/libxc/include/xenctrl.h |   4 ++
 tools/libxc/xc_mem_access.c   |  38 ++++++++++
 xen/arch/x86/mm/p2m.c         | 161
++++++++++++++++++++++++++++++++----------
 xen/common/compat/memory.c    |  24 +++++--
 xen/common/mem_access.c       |  11 +++
 xen/include/public/memory.h   |  14 +++-
 xen/include/xen/p2m-common.h  |   6 ++
Quoted 6 lines
Quoted 2 lines

p2m-common.h contains prototype common between ARM and x86. I would have expected to see a change in the ARM port because of that.

The only change to p2m-common.h is the addition of a single function, p2m_set_mem_access_multi(). As long as the ARM bits don't make use of it, there's nothing to modify there.

p2m_set_mem_access_multi is called from common code. If you had tried to build Xen on ARM you would have noticed a compilation error:

prelink.o: In function `mem_access_memop':
/local/home/julieng/works/xen/xen/common/mem_access.c:80: undefined reference to `p2m_set_mem_access_multi'
aarch64-linux-gnu-ld: /local/home/julieng/works/xen/xen/.xen-syms.0: hidden symbol `p2m_set_mem_access_multi' isn't defined

Regards,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#21 lore raw
Quoted 53 lines · Julien Grall
Quoted 43 lines · Razvan Cojocaru
Quoted 1 line · Julien Grall

Hello Razvan,

Hello Julien, thanks for the email!

Quoted 38 lines · Razvan Cojocaru
Quoted 36 lines

Currently it is only possible to set mem_access restrictions only for a contiguous range of GFNs (or, as a particular case, for a single GFN). This patch introduces a new libxc function taking an array of GFNs. The alternative would be to set each page in turn, using a userspace-HV roundtrip for each call, and triggering a TLB flush per page set.

---
Changes since V1 / RFC:
- Renamed xc_set_mem_access_sparse() to xc_set_mem_access_multi(), and XENMEM_access_op_set_access_sparse to XENMEM_access_op_set_access_multi.
- Renamed the 'nr' parameter to 'size'.
- Wrapped long line in the implementation of xc_set_mem_access_multi().
- Factored out common code in _p2m_set_mem_access() (and modified p2m_set_altp2m_mem_access() in the process, to take an unsigned long argument instead of a gfn_t).
- Factored out xenmem_access_t to p2m_access_t conversion code in p2m_xenmem_access_to_p2m_access().
- Added hypercall continuation support.
- Added compat translation support.
- No longer allocating buffers (now using copy_from_guest_offset()).
- Added support for setting an array of access restrictions, as suggested by Tamas Lengyel.
- This patch incorporates Jan Beulich's "memory: fix compat handling of XENMEM_access_op".

---
 tools/libxc/include/xenctrl.h |   4 ++
 tools/libxc/xc_mem_access.c   |  38 ++++++++++
 xen/arch/x86/mm/p2m.c         | 161
++++++++++++++++++++++++++++++++----------
 xen/common/compat/memory.c    |  24 +++++--
 xen/common/mem_access.c       |  11 +++
 xen/include/public/memory.h   |  14 +++-
 xen/include/xen/p2m-common.h  |   6 ++
Quoted 6 lines
Quoted 2 lines

p2m-common.h contains prototype common between ARM and x86. I would have expected to see a change in the ARM port because of that.

The only change to p2m-common.h is the addition of a single function, p2m_set_mem_access_multi(). As long as the ARM bits don't make use of it, there's nothing to modify there.

Quoted 6 lines

p2m_set_mem_access_multi is called from common code. If you had tried to build Xen on ARM you would have noticed a compilation error:

prelink.o: In function `mem_access_memop':
/local/home/julieng/works/xen/xen/common/mem_access.c:80: undefined reference to `p2m_set_mem_access_multi'
aarch64-linux-gnu-ld: /local/home/julieng/works/xen/xen/.xen-syms.0: hidden symbol `p2m_set_mem_access_multi' isn't defined

I see. Sorry about that. I'll fix that in V3.

Thanks,
Razvan

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