Skip to contentSkip to conversation

x86/HVM: further do_hvm_op() adjustments

PATCH Applied Jan Beulich 3 participants 9 messages Apr 2, 2014 – Apr 9, 2014 2 messages not in the archive

lore
Share & tools
lore
#1 lore raw

PATCH 1/2 x86/HVM: fix preemption handling in do_hvm_op() (try 2)

Just like previously done for some mem-op hypercalls, undo preemption using the interface structures (altering it in ways the caller may not expect) and replace it by storing the continuation point in the high bits of sub-operation argument.

This also changes the "nr" fields of struct xen_hvm_track_dirty_vram (operation already limited to 1Gb worth of pages) and struct xen_hvm_modified_memory to be only 32 bits wide, consistent with those of struct xen_set_mem{type,access}. If that's not acceptable for some reason, we'd need to shrink the HVMOP_op_bits (while still enforcing the [then higher] limit resulting from the need to be able to encode the continuation).

Whether (and if so how) to adjust xc_hvm_track_dirty_vram(), xc_hvm_modified_memory(), xc_hvm_set_mem_type(), and xc_hvm_set_mem_access() to reflect the 32-bit restriction on "nr" is
unclear: If the APIs need to remain stable, all four functions should probably check that there was no truncation. Preferably their parameters would be changed to uint32_t or unsigned int, though.

---
v2: Avoid double increment of pfn in HVMOP_modified_memory and
HVMOP_set_mem_type handling. Change preemption logic to also work for 32-bit callers. Drop unrelated cleanup.

xen/arch/x86/hvm/hvm.c +29 -33
@@ -4047,13 +4047,16 @@ static int hvm_replace_event_channel(str
     return 0;
 }
 
+#define HVMOP_op_mask 0xff
+
 long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)
 
 {
     struct domain *curr_d = current->domain;
+    unsigned long start_iter = op & ~HVMOP_op_mask;
     long rc = 0;
 
-    switch ( op )
+    switch ( op &= HVMOP_op_mask )
     {
     case HVMOP_set_param:
     case HVMOP_get_param:
@@ -4383,7 +4386,8 @@ long do_hvm_op(unsigned long op, XEN_GUE
             goto param_fail3;
 
         rc = -EINVAL;
-        if ( ((a.first_pfn + a.nr - 1) < a.first_pfn) ||
+        if ( a.nr < start_iter ||
+             ((a.first_pfn + a.nr - 1) < a.first_pfn) ||
              ((a.first_pfn + a.nr - 1) > domain_get_maximum_gpfn(d)) )
             goto param_fail3;
 
@@ -4391,9 +4395,9 @@ long do_hvm_op(unsigned long op, XEN_GUE
         if ( !paging_mode_log_dirty(d) )
             goto param_fail3;
 
-        while ( a.nr > 0 )
+        while ( a.nr > start_iter )
         {
-            unsigned long pfn = a.first_pfn;
+            unsigned long pfn = a.first_pfn + start_iter;
             struct page_info *page;
 
             page = get_page_from_gfn(d, pfn, NULL, P2M_UNSHARE);
@@ -4406,16 +4410,11 @@ long do_hvm_op(unsigned long op, XEN_GUE
                 put_page(page);
             }
 
-            a.first_pfn++;
-            a.nr--;
-
             /* Check for continuation if it's not the last interation */
-            if ( a.nr > 0 && hypercall_preempt_check() )
+            if ( a.nr > ++start_iter && !(start_iter & HVMOP_op_mask) &&
+                 hypercall_preempt_check() )
             {
-                if ( __copy_to_guest(arg, &a, 1) )
-                    rc = -EFAULT;
-                else
-                    rc = -EAGAIN;
+                rc = -EAGAIN;
                 break;
             }
         }
@@ -4497,16 +4496,17 @@ long do_hvm_op(unsigned long op, XEN_GUE
             goto param_fail4;
 
         rc = -EINVAL;
-        if ( ((a.first_pfn + a.nr - 1) < a.first_pfn) ||
+        if ( a.nr < start_iter ||
+             ((a.first_pfn + a.nr - 1) < a.first_pfn) ||
              ((a.first_pfn + a.nr - 1) > domain_get_maximum_gpfn(d)) )
             goto param_fail4;
             
         if ( a.hvmmem_type >= ARRAY_SIZE(memtype) )
             goto param_fail4;
 
-        while ( a.nr )
+        while ( a.nr > start_iter )
         {
-            unsigned long pfn = a.first_pfn;
+            unsigned long pfn = a.first_pfn + start_iter;
             p2m_type_t t;
             p2m_type_t nt;
             mfn_t mfn;
@@ -4547,16 +4547,11 @@ long do_hvm_op(unsigned long op, XEN_GUE
             }
             put_gfn(d, pfn);
 
-            a.first_pfn++;
-            a.nr--;
-
             /* Check for continuation if it's not the last interation */
-            if ( a.nr > 0 && hypercall_preempt_check() )
+            if ( a.nr > ++start_iter && !(start_iter & HVMOP_op_mask) &&
+                 hypercall_preempt_check() )
             {
-                if ( __copy_to_guest(arg, &a, 1) )
-                    rc = -EFAULT;
-                else
-                    rc = -EAGAIN;
+                rc = -EAGAIN;
                 goto param_fail4;
             }
         }
@@ -4590,19 +4585,17 @@ long do_hvm_op(unsigned long op, XEN_GUE
 
         rc = -EINVAL;
         if ( (a.first_pfn != ~0ull) &&
-             (((a.first_pfn + a.nr - 1) < a.first_pfn) ||
+             (a.nr < start_iter ||
+              ((a.first_pfn + a.nr - 1) < a.first_pfn) ||
               ((a.first_pfn + a.nr - 1) > domain_get_maximum_gpfn(d))) )
             goto param_fail5;
             
-        rc = p2m_set_mem_access(d, a.first_pfn, a.nr, a.hvmmem_access);
+        rc = p2m_set_mem_access(d, a.first_pfn, a.nr, start_iter,
+                                HVMOP_op_mask, a.hvmmem_access);
         if ( rc > 0 )
         {
-            a.first_pfn += a.nr - rc;
-            a.nr = rc;
-            if ( __copy_to_guest(arg, &a, 1) )
-                rc = -EFAULT;
-            else
-                rc = -EAGAIN;
+            start_iter = rc;
+            rc = -EAGAIN;
         }
 
     param_fail5:
@@ -4751,8 +4744,11 @@ long do_hvm_op(unsigned long op, XEN_GUE
     }
 
     if ( rc == -EAGAIN )
-        rc = hypercall_create_continuation(
-            __HYPERVISOR_hvm_op, "lh", op, arg);
+    {
+        ASSERT(!(start_iter & HVMOP_op_mask));
+        rc = hypercall_create_continuation(__HYPERVISOR_hvm_op, "lh",
+                                           op | start_iter, arg);
+    }
 
     return rc;
 }
xen/arch/x86/mm/p2m.c +5 -8
@@ -1334,13 +1334,13 @@ void p2m_mem_access_resume(struct domain
 /* Set access type for a region of pfns.
  * If start_pfn == -1ul, sets the default access type */
 long p2m_set_mem_access(struct domain *d, unsigned long pfn, uint32_t nr,
-                        hvmmem_access_t access)
+                        uint32_t start, uint32_t mask, hvmmem_access_t access)
 {
     struct p2m_domain *p2m = p2m_get_hostp2m(d);
     p2m_access_t a, _a;
     p2m_type_t t;
     mfn_t mfn;
-    long rc;
+    long rc = 0;
 
     /* N.B. _not_ static: initializer depends on p2m->default_access */
     p2m_access_t memaccess[] = {
@@ -1369,11 +1369,8 @@ long p2m_set_mem_access(struct domain *d
         return 0;
     }
 
-    if ( !nr )
-        return 0;
-
     p2m_lock(p2m);
-    for ( ; ; ++pfn )
+    for ( pfn += start; nr > start; ++pfn )
     {
         mfn = p2m->get_entry(p2m, pfn, &t, &_a, 0, NULL);
         if ( p2m->set_entry(p2m, pfn, mfn, PAGE_ORDER_4K, t, a) == 0 )
@@ -1383,9 +1380,9 @@ long p2m_set_mem_access(struct domain *d
         }
 
         /* Check for continuation if it's not the last interation. */
-        if ( !--nr || hypercall_preempt_check() )
+        if ( nr > ++start && !(start & mask) && hypercall_preempt_check() )
         {
-            rc = nr;
+            rc = start;
             break;
         }
     }
xen/include/asm-x86/p2m.h +2 -2
@@ -576,8 +576,8 @@ void p2m_mem_access_resume(struct domain
 
 /* Set access type for a region of pfns.
  * If start_pfn == -1ul, sets the default access type */
-long p2m_set_mem_access(struct domain *d, unsigned long start_pfn,
-                        uint32_t nr, hvmmem_access_t access);
+long p2m_set_mem_access(struct domain *d, unsigned long start_pfn, uint32_t nr,
+                        uint32_t start, uint32_t mask, hvmmem_access_t access);
 
 /* Get access type for a pfn
  * If pfn == -1ul, gets the default access type */
xen/include/public/hvm/hvm_op.h +4 -4
@@ -90,10 +90,10 @@ typedef enum {
 struct xen_hvm_track_dirty_vram {
     /* Domain to be tracked. */
     domid_t  domid;
+    /* Number of pages to track. */
+    uint32_t nr;
     /* First pfn to track. */
     uint64_aligned_t first_pfn;
-    /* Number of pages to track. */
-    uint64_aligned_t nr;
     /* OUT variable. */
     /* Dirty bitmap buffer. */
     XEN_GUEST_HANDLE_64(uint8) dirty_bitmap;
@@ -106,10 +106,10 @@ DEFINE_XEN_GUEST_HANDLE(xen_hvm_track_di
 struct xen_hvm_modified_memory {
     /* Domain to be updated. */
     domid_t  domid;
+    /* Number of pages. */
+    uint32_t nr;
     /* First pfn. */
     uint64_aligned_t first_pfn;
-    /* Number of pages. */
-    uint64_aligned_t nr;
 };
 typedef struct xen_hvm_modified_memory xen_hvm_modified_memory_t;
 DEFINE_XEN_GUEST_HANDLE(xen_hvm_modified_memory_t);

x86/HVM: fix preemption handling in do_hvm_op() (try 2)

Just like previously done for some mem-op hypercalls, undo preemption using the interface structures (altering it in ways the caller may not expect) and replace it by storing the continuation point in the high bits of sub-operation argument.

This also changes the "nr" fields of struct xen_hvm_track_dirty_vram (operation already limited to 1Gb worth of pages) and struct xen_hvm_modified_memory to be only 32 bits wide, consistent with those of struct xen_set_mem{type,access}. If that's not acceptable for some reason, we'd need to shrink the HVMOP_op_bits (while still enforcing the [then higher] limit resulting from the need to be able to encode the continuation).

Whether (and if so how) to adjust xc_hvm_track_dirty_vram(), xc_hvm_modified_memory(), xc_hvm_set_mem_type(), and xc_hvm_set_mem_access() to reflect the 32-bit restriction on "nr" is
unclear: If the APIs need to remain stable, all four functions should probably check that there was no truncation. Preferably their parameters would be changed to uint32_t or unsigned int, though.

---
v2: Avoid double increment of pfn in HVMOP_modified_memory and
HVMOP_set_mem_type handling. Change preemption logic to also work for 32-bit callers. Drop unrelated cleanup.

xen/arch/x86/hvm/hvm.c +29 -33

133 lines not on this page · raw message

xen/arch/x86/mm/p2m.c +5 -8
@@ -1334,13 +1334,13 @@ void p2m_mem_access_resume(struct domain
 /* Set access type for a region of pfns.
  * If start_pfn == -1ul, sets the default access type */
 long p2m_set_mem_access(struct domain *d, unsigned long pfn, uint32_t nr,
-                        hvmmem_access_t access)
+                        uint32_t start, uint32_t mask, hvmmem_access_t access)
 {
     struct p2m_domain *p2m = p2m_get_hostp2m(d);
     p2m_access_t a, _a;
     p2m_type_t t;
     mfn_t mfn;
-    long rc;
+    long rc = 0;
 
     /* N.B. _not_ static: initializer depends on p2m->default_access */
     p2m_access_t memaccess[] = {
@@ -1369,11 +1369,8 @@ long p2m_set_mem_access(struct domain *d
         return 0;
     }
 
-    if ( !nr )
-        return 0;
-
     p2m_lock(p2m);
-    for ( ; ; ++pfn )
+    for ( pfn += start; nr > start; ++pfn )
     {
         mfn = p2m->get_entry(p2m, pfn, &t, &_a, 0, NULL);
         if ( p2m->set_entry(p2m, pfn, mfn, PAGE_ORDER_4K, t, a) == 0 )
@@ -1383,9 +1380,9 @@ long p2m_set_mem_access(struct domain *d
         }
 
         /* Check for continuation if it's not the last interation. */
-        if ( !--nr || hypercall_preempt_check() )
+        if ( nr > ++start && !(start & mask) && hypercall_preempt_check() )
         {
-            rc = nr;
+            rc = start;
             break;
         }
     }
xen/include/asm-x86/p2m.h +2 -2
@@ -576,8 +576,8 @@ void p2m_mem_access_resume(struct domain
 
 /* Set access type for a region of pfns.
  * If start_pfn == -1ul, sets the default access type */
-long p2m_set_mem_access(struct domain *d, unsigned long start_pfn,
-                        uint32_t nr, hvmmem_access_t access);
+long p2m_set_mem_access(struct domain *d, unsigned long start_pfn, uint32_t nr,
+                        uint32_t start, uint32_t mask, hvmmem_access_t access);
 
 /* Get access type for a pfn
  * If pfn == -1ul, gets the default access type */
xen/include/public/hvm/hvm_op.h +4 -4
@@ -90,10 +90,10 @@ typedef enum {
 struct xen_hvm_track_dirty_vram {
     /* Domain to be tracked. */
     domid_t  domid;
+    /* Number of pages to track. */
+    uint32_t nr;
     /* First pfn to track. */
     uint64_aligned_t first_pfn;
-    /* Number of pages to track. */
-    uint64_aligned_t nr;
     /* OUT variable. */
     /* Dirty bitmap buffer. */
     XEN_GUEST_HANDLE_64(uint8) dirty_bitmap;
@@ -106,10 +106,10 @@ DEFINE_XEN_GUEST_HANDLE(xen_hvm_track_di
 struct xen_hvm_modified_memory {
     /* Domain to be updated. */
     domid_t  domid;
+    /* Number of pages. */
+    uint32_t nr;
     /* First pfn. */
     uint64_aligned_t first_pfn;
-    /* Number of pages. */
-    uint64_aligned_t nr;
 };
 typedef struct xen_hvm_modified_memory xen_hvm_modified_memory_t;
 DEFINE_XEN_GUEST_HANDLE(xen_hvm_modified_memory_t);

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

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

#3 lore raw

Re: [PATCH 1/2] x86/HVM: fix preemption handling in do_hvm_op() (try 2)

Quoted 9 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Date: Wed, Apr 2, 2014 at 1:09 AM
Subject: [Xen-devel] [PATCH 1/2] x86/HVM: fix preemption handling in do_hvm_op() (try 2)
To: xen-devel <[email protected]>
Cc: Tim Deegan <[email protected]>, Keir Fraser <[email protected]>

Quoted 4 lines

Just like previously done for some mem-op hypercalls, undo preemption using the interface structures (altering it in ways the caller may not expect) and replace it by storing the continuation point in the high bits of sub- operation argument.

As part of my PV mem_access work, I am moving HVMOP_set_mem_access in to mem_access_memop() as XENMEM_access_op_set_access, to make it more generic. I am not sure how to go about doing the preemption handling here. I am not able to do something similar as the mem_access ops is a subarch_memory_op, so I was thinking of using the interface structures but the above comment has me worried. Is it not safe to do this for _set_mem_access op? I will send out an RFC patch to make it clear as to what I am doing. Please take a look and advise as to how I should proceed.

Thanks,
Aravindh

Quoted 258 lines

This also changes the "nr" fields of struct xen_hvm_track_dirty_vram (operation already limited to 1Gb worth of pages) and struct xen_hvm_modified_memory to be only 32 bits wide, consistent with those of struct xen_set_mem{type,access}. If that's not acceptable for some reason, we'd need to shrink the HVMOP_op_bits (while still enforcing the [then higher] limit resulting from the need to be able to encode the continuation).

Whether (and if so how) to adjust xc_hvm_track_dirty_vram(), xc_hvm_modified_memory(), xc_hvm_set_mem_type(), and xc_hvm_set_mem_access() to reflect the 32-bit restriction on "nr" is
unclear: If the APIs need to remain stable, all four functions should probably check that there was no truncation. Preferably their parameters would be changed to uint32_t or unsigned int, though.

---
v2: Avoid double increment of pfn in HVMOP_modified_memory and
HVMOP_set_mem_type handling. Change preemption logic to also work for 32-bit callers. Drop unrelated cleanup.

xen/arch/x86/hvm/hvm.c +8 -4
@@ -4047,13 +4047,16 @@ static int hvm_replace_event_channel(str
    return 0;
 }
 
+#define HVMOP_op_mask 0xff
+
 long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)
 
 {
    struct domain *curr_d = current->domain;
+    unsigned long start_iter = op & ~HVMOP_op_mask;
    long rc = 0;
 
-    switch ( op )
+    switch ( op &= HVMOP_op_mask )
    {
    case HVMOP_set_param:
    case HVMOP_get_param:
@@ -4383,7 +4386,8 @@ long do_hvm_op(unsigned long op, XEN_GUE
            goto param_fail3;
 
        rc = -EINVAL;
-        if ( ((a.first_pfn + a.nr - 1) < a.first_pfn) ||
+        if ( a.nr < start_iter ||
+             ((a.first_pfn + a.nr - 1) < a.first_pfn) ||
             ((a.first_pfn + a.nr - 1) > domain_get_maximum_gpfn(d)) )
            goto param_fail3;
 
@@ -4391,9 +4395,9 @@ long do_hvm_op(unsigned long op, XEN_GUE
        if ( !paging_mode_log_dirty(d) )
            goto param_fail3;
 
-        while ( a.nr > 0 )
+        while ( a.nr > start_iter )
        {
-            unsigned long pfn = a.first_pfn;
+            unsigned long pfn = a.first_pfn + start_iter;
            struct page_info *page;
 
            page = get_page_from_gfn(d, pfn, NULL, P2M_UNSHARE); @@ -

4406,16 +4410,11 @@ long do_hvm_op(unsigned long op, XEN_GUE

                put_page(page);
            }
xen/arch/x86/hvm/hvm.c +21 -29
-            a.first_pfn++;
-            a.nr--;
-
            /* Check for continuation if it's not the last interation */
-            if ( a.nr > 0 && hypercall_preempt_check() )
+            if ( a.nr > ++start_iter && !(start_iter & HVMOP_op_mask) &&
+                 hypercall_preempt_check() )
            {
-                if ( __copy_to_guest(arg, &a, 1) )
-                    rc = -EFAULT;
-                else
-                    rc = -EAGAIN;
+                rc = -EAGAIN;
                break;
            }
        }
@@ -4497,16 +4496,17 @@ long do_hvm_op(unsigned long op, XEN_GUE
            goto param_fail4;
 
        rc = -EINVAL;
-        if ( ((a.first_pfn + a.nr - 1) < a.first_pfn) ||
+        if ( a.nr < start_iter ||
+             ((a.first_pfn + a.nr - 1) < a.first_pfn) ||
             ((a.first_pfn + a.nr - 1) > domain_get_maximum_gpfn(d)) )
            goto param_fail4;
 
        if ( a.hvmmem_type >= ARRAY_SIZE(memtype) )
            goto param_fail4;
 
-        while ( a.nr )
+        while ( a.nr > start_iter )
        {
-            unsigned long pfn = a.first_pfn;
+            unsigned long pfn = a.first_pfn + start_iter;
            p2m_type_t t;
            p2m_type_t nt;
            mfn_t mfn;
@@ -4547,16 +4547,11 @@ long do_hvm_op(unsigned long op, XEN_GUE
            }
            put_gfn(d, pfn);
 
-            a.first_pfn++;
-            a.nr--;
-
            /* Check for continuation if it's not the last interation */
-            if ( a.nr > 0 && hypercall_preempt_check() )
+            if ( a.nr > ++start_iter && !(start_iter & HVMOP_op_mask) &&
+                 hypercall_preempt_check() )
            {
-                if ( __copy_to_guest(arg, &a, 1) )
-                    rc = -EFAULT;
-                else
-                    rc = -EAGAIN;
+                rc = -EAGAIN;
                goto param_fail4;
            }
        }
@@ -4590,19 +4585,17 @@ long do_hvm_op(unsigned long op, XEN_GUE
 
        rc = -EINVAL;
        if ( (a.first_pfn != ~0ull) &&
-             (((a.first_pfn + a.nr - 1) < a.first_pfn) ||
+             (a.nr < start_iter ||
+              ((a.first_pfn + a.nr - 1) < a.first_pfn) ||
              ((a.first_pfn + a.nr - 1) > domain_get_maximum_gpfn(d))) )
            goto param_fail5;
 
-        rc = p2m_set_mem_access(d, a.first_pfn, a.nr, a.hvmmem_access);
+        rc = p2m_set_mem_access(d, a.first_pfn, a.nr, start_iter,
+                                HVMOP_op_mask, a.hvmmem_access);
        if ( rc > 0 )
        {
-            a.first_pfn += a.nr - rc;
-            a.nr = rc;
-            if ( __copy_to_guest(arg, &a, 1) )
-                rc = -EFAULT;
-            else
-                rc = -EAGAIN;
+            start_iter = rc;
+            rc = -EAGAIN;
        }
 
    param_fail5:
@@ -4751,8 +4744,11 @@ long do_hvm_op(unsigned long op, XEN_GUE
    }
 
    if ( rc == -EAGAIN )
-        rc = hypercall_create_continuation(
-            __HYPERVISOR_hvm_op, "lh", op, arg);
+    {
+        ASSERT(!(start_iter & HVMOP_op_mask));
+        rc = hypercall_create_continuation(__HYPERVISOR_hvm_op, "lh",
+                                           op | start_iter, arg);
+    }
 
    return rc;
 }
xen/arch/x86/mm/p2m.c +4 -6
@@ -1334,13 +1334,13 @@ void p2m_mem_access_resume(struct domain
 /* Set access type for a region of pfns.
 * If start_pfn == -1ul, sets the default access type */  long
 p2m_set_mem_access(struct domain *d, unsigned long pfn, uint32_t nr,
-                        hvmmem_access_t access)
+                        uint32_t start, uint32_t mask, hvmmem_access_t
+ access)
 {
    struct p2m_domain *p2m = p2m_get_hostp2m(d);
    p2m_access_t a, _a;
    p2m_type_t t;
    mfn_t mfn;
-    long rc;
+    long rc = 0;
 
    /* N.B. _not_ static: initializer depends on p2m->default_access */
    p2m_access_t memaccess[] = {
@@ -1369,11 +1369,8 @@ long p2m_set_mem_access(struct domain *d
        return 0;
    }
 
-    if ( !nr )
-        return 0;
-
    p2m_lock(p2m);
-    for ( ; ; ++pfn )
+    for ( pfn += start; nr > start; ++pfn )
    {
        mfn = p2m->get_entry(p2m, pfn, &t, &_a, 0, NULL);
        if ( p2m->set_entry(p2m, pfn, mfn, PAGE_ORDER_4K, t, a) == 0 ) @@ -

1383,9 +1380,9 @@ long p2m_set_mem_access(struct domain *d

        }

        /* Check for continuation if it's not the last interation. */
xen/arch/x86/mm/p2m.c +3 -2
-        if ( !--nr || hypercall_preempt_check() )
+        if ( nr > ++start && !(start & mask) &&
+ hypercall_preempt_check() )
        {
-            rc = nr;
+            rc = start;
            break;
        }
    }
xen/include/asm-x86/p2m.h +3 -1
@@ -576,8 +576,8 @@ void p2m_mem_access_resume(struct domain
 
 /* Set access type for a region of pfns.
 * If start_pfn == -1ul, sets the default access type */ -long
 p2m_set_mem_access(struct domain *d, unsigned long start_pfn,
-                        uint32_t nr, hvmmem_access_t access);
+long p2m_set_mem_access(struct domain *d, unsigned long start_pfn,
 uint32_t nr,
+                        uint32_t start, uint32_t mask, hvmmem_access_t
+access);

/* Get access type for a pfn
* If pfn == -1ul, gets the default access type */

xen/include/public/hvm/hvm_op.h +2 -2
@@ -90,10 +90,10 @@ typedef enum {
 struct xen_hvm_track_dirty_vram {
    /* Domain to be tracked. */
    domid_t  domid;
+    /* Number of pages to track. */
+    uint32_t nr;
    /* First pfn to track. */
    uint64_aligned_t first_pfn;
-    /* Number of pages to track. */
-    uint64_aligned_t nr;
    /* OUT variable. */
    /* Dirty bitmap buffer. */
    XEN_GUEST_HANDLE_64(uint8) dirty_bitmap; @@ -106,10 +106,10 @@

DEFINE_XEN_GUEST_HANDLE(xen_hvm_track_di

struct xen_hvm_modified_memory {
    /* Domain to be updated. */
    domid_t  domid;
xen/include/public/hvm/hvm_op.h +2 -2
+    /* Number of pages. */
+    uint32_t nr;
    /* First pfn. */
    uint64_aligned_t first_pfn;
-    /* Number of pages. */
-    uint64_aligned_t nr;

};
typedef struct xen_hvm_modified_memory xen_hvm_modified_memory_t; DEFINE_XEN_GUEST_HANDLE(xen_hvm_modified_memory_t);

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

#4 lore raw

Re: [PATCH 1/2] x86/HVM: fix preemption handling in do_hvm_op() (try 2)

Quoted 9 lines
Quoted 8 lines
Quoted 1 line · On 09.04.14 at 07:32, <[email protected]> wrote:

From: Jan Beulich <[email protected]>
Date: Wed, Apr 2, 2014 at 1:09 AM

Just like previously done for some mem-op hypercalls, undo preemption using the interface structures (altering it in ways the caller may not expect) and replace it by storing the continuation point in the high bits of sub- operation argument.

Quoted 8 lines

As part of my PV mem_access work, I am moving HVMOP_set_mem_access in to mem_access_memop() as XENMEM_access_op_set_access, to make it more generic. I am not sure how to go about doing the preemption handling here. I am not able to do something similar as the mem_access ops is a subarch_memory_op, so I was thinking of using the interface structures but the above comment has me worried. Is it not safe to do this for _set_mem_access op? I will send out an RFC patch to make it clear as to what I am doing. Please take a look and advise as to how I should proceed.

Without seeing what you refer to I can't really comment; in any event I can't offhand see why you shouldn't be able to follow the existing preemption model used for other mem ops.

Also please remember to strip quotes from the responded to mail that aren't relevant for your reply.

Jan

#5 lore raw

PATCH 2/2 x86/HVM: fix setting mem access to default

In reply to Jan Beulich

commit 3b0bcb89 ("x86/mm/p2m: Move p2m code in HVMOP_[gs]et_mem_access into p2m.c") introduced an off-by-one mistake forcing an input of HVMMEM_access_default to always fail. Since related, also eliminate the inefficient setup of an on-stack array for each function invocation.

xen/arch/x86/mm/p2m.c +23 -16
@@ -1342,25 +1342,32 @@ long p2m_set_mem_access(struct domain *d
     mfn_t mfn;
     long rc = 0;
 
-    /* N.B. _not_ static: initializer depends on p2m->default_access */
-    p2m_access_t memaccess[] = {
-        p2m_access_n,
-        p2m_access_r,
-        p2m_access_w,
-        p2m_access_rw,
-        p2m_access_x,
-        p2m_access_rx,
-        p2m_access_wx,
-        p2m_access_rwx,
-        p2m_access_rx2rw,
-        p2m_access_n2rwx,
-        p2m->default_access,
+    static const p2m_access_t memaccess[] = {
+#define ACCESS(ac) [HVMMEM_access_##ac] = p2m_access_##ac
+        ACCESS(n),
+        ACCESS(r),
+        ACCESS(w),
+        ACCESS(rw),
+        ACCESS(x),
+        ACCESS(rx),
+        ACCESS(wx),
+        ACCESS(rwx),
+        ACCESS(rx2rw),
+        ACCESS(n2rwx),
+#undef ACCESS
     };
 
-    if ( (unsigned) access >= HVMMEM_access_default )
+    switch ( access )
+    {
+    case 0 ... ARRAY_SIZE(memaccess) - 1:
+        a = memaccess[access];
+        break;
+    case HVMMEM_access_default:
+        a = p2m->default_access;
+        break;
+    default:
         return -EINVAL;
-
-    a = memaccess[access];
+    }
 
     /* If request to set default access */
     if ( pfn == ~0ul )

x86/HVM: fix setting mem access to default

commit 3b0bcb89 ("x86/mm/p2m: Move p2m code in HVMOP_[gs]et_mem_access into p2m.c") introduced an off-by-one mistake forcing an input of HVMMEM_access_default to always fail. Since related, also eliminate the inefficient setup of an on-stack array for each function invocation.

xen/arch/x86/mm/p2m.c +23 -16
@@ -1342,25 +1342,32 @@ long p2m_set_mem_access(struct domain *d
     mfn_t mfn;
     long rc = 0;
 
-    /* N.B. _not_ static: initializer depends on p2m->default_access */
-    p2m_access_t memaccess[] = {
-        p2m_access_n,
-        p2m_access_r,
-        p2m_access_w,
-        p2m_access_rw,
-        p2m_access_x,
-        p2m_access_rx,
-        p2m_access_wx,
-        p2m_access_rwx,
-        p2m_access_rx2rw,
-        p2m_access_n2rwx,
-        p2m->default_access,
+    static const p2m_access_t memaccess[] = {
+#define ACCESS(ac) [HVMMEM_access_##ac] = p2m_access_##ac
+        ACCESS(n),
+        ACCESS(r),
+        ACCESS(w),
+        ACCESS(rw),
+        ACCESS(x),
+        ACCESS(rx),
+        ACCESS(wx),
+        ACCESS(rwx),
+        ACCESS(rx2rw),
+        ACCESS(n2rwx),
+#undef ACCESS
     };
 
-    if ( (unsigned) access >= HVMMEM_access_default )
+    switch ( access )
+    {
+    case 0 ... ARRAY_SIZE(memaccess) - 1:
+        a = memaccess[access];
+        break;
+    case HVMMEM_access_default:
+        a = p2m->default_access;
+        break;
+    default:
         return -EINVAL;
-
-    a = memaccess[access];
+    }
 
     /* If request to set default access */
     if ( pfn == ~0ul )

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

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

#7 lore raw

Re: [PATCH 2/2] x86/HVM: fix setting mem access to default

Quoted 5 lines

commit 3b0bcb89 ("x86/mm/p2m: Move p2m code in HVMOP_[gs]et_mem_access into p2m.c") introduced an off-by-one mistake forcing an input of HVMMEM_access_default to always fail. Since related, also eliminate the inefficient setup of an on-stack array for each function invocation.

Thanks for catching this. I do have a question. If the caller wants to set the default access by specifying pfn == ~0ul, the call could be made with access = HVMMEM_access_default. Should this be allowed?

Thanks,
Aravindh

Quoted 61 lines
xen/arch/x86/mm/p2m.c +23 -16
@@ -1342,25 +1342,32 @@ long p2m_set_mem_access(struct domain *d
    mfn_t mfn;
    long rc = 0;
 
-    /* N.B. _not_ static: initializer depends on p2m->default_access */
-    p2m_access_t memaccess[] = {
-        p2m_access_n,
-        p2m_access_r,
-        p2m_access_w,
-        p2m_access_rw,
-        p2m_access_x,
-        p2m_access_rx,
-        p2m_access_wx,
-        p2m_access_rwx,
-        p2m_access_rx2rw,
-        p2m_access_n2rwx,
-        p2m->default_access,
+    static const p2m_access_t memaccess[] = { #define ACCESS(ac)
+[HVMMEM_access_##ac] = p2m_access_##ac
+        ACCESS(n),
+        ACCESS(r),
+        ACCESS(w),
+        ACCESS(rw),
+        ACCESS(x),
+        ACCESS(rx),
+        ACCESS(wx),
+        ACCESS(rwx),
+        ACCESS(rx2rw),
+        ACCESS(n2rwx),
+#undef ACCESS
    };
 
-    if ( (unsigned) access >= HVMMEM_access_default )
+    switch ( access )
+    {
+    case 0 ... ARRAY_SIZE(memaccess) - 1:
+        a = memaccess[access];
+        break;
+    case HVMMEM_access_default:
+        a = p2m->default_access;
+        break;
+    default:
        return -EINVAL;
-
-    a = memaccess[access];
+    }
 
    /* If request to set default access */
    if ( pfn == ~0ul )

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

#8 lore raw

Re: [PATCH 2/2] x86/HVM: fix setting mem access to default

Quoted 10 lines
Quoted 6 lines
Quoted 1 line · On 03.04.14 at 02:13, <[email protected]> wrote:

commit 3b0bcb89 ("x86/mm/p2m: Move p2m code in HVMOP_[gs]et_mem_access into p2m.c") introduced an off-by-one mistake forcing an input of HVMMEM_access_default to always fail. Since related, also eliminate the inefficient setup of an on-stack array for each function invocation.

Thanks for catching this. I do have a question. If the caller wants to set the default access by specifying pfn == ~0ul, the call could be made with access = HVMMEM_access_default. Should this be allowed?

I asked myself this question too, but wasn't really decided about the usefulness of this, so left the behavior unchanged (i.e. allow this pointless operation). I'll leave the decision whether to disable this to the mm maintainers.

Jan

#9 lore raw

Re: [PATCH 2/2] x86/HVM: fix setting mem access to default

Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 6 lines
Quoted 1 line · On 03.04.14 at 02:13, <[email protected]> wrote:

commit 3b0bcb89 ("x86/mm/p2m: Move p2m code in HVMOP_[gs]et_mem_access into p2m.c") introduced an off-by-one mistake forcing an input of HVMMEM_access_default to always fail. Since related, also eliminate the inefficient setup of an on-stack array for each function invocation.

Quoted 8 lines
Quoted 3 lines

Thanks for catching this. I do have a question. If the caller wants to set the default access by specifying pfn == ~0ul, the call could be made with access = HVMMEM_access_default. Should this be allowed?

I asked myself this question too, but wasn't really decided about the usefulness of this, so left the behavior unchanged (i.e. allow this pointless operation). I'll leave the decision whether to disable this to the mm maintainers.

Seems harmless enough, and has well-defined (if admittedly pointless) semantics. I'd accept a patch to disable it if anyone feels strongly enough about it to write one. :)

Tim.