Skip to contentSkip to conversation

x86/mem-sharing: Bulk mem-sharing entire domains

PATCH In review Tamas K Lengyel 5 participants 13 messages Jun 11, 2016 – Jul 5, 2016 4 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/2 x86/mem-sharing: Bulk mem-sharing entire domains

Currently mem-sharing can be performed on a page-by-page base from the control domain. However, when completely deduplicating (cloning) a VM, this requires at least 3 hypercalls per page. As the user has to loop through all pages up to max_gpfn, this process is very slow and wasteful.

This patch introduces a new mem_sharing memop for bulk deduplication where the user doesn't have to separately nominate each page in both the source and destination domain, and the looping over all pages happen in the hypervisor. This significantly reduces the overhead of completely deduplicating entire domains.

---
Ian Jackson <[email protected]>
George Dunlap <[email protected]>
Jan Beulich <[email protected]>
Andrew Cooper <[email protected]>

v4: Add padding to bulk op and enforce it being 0
Use correct XSM permission check

---
 tools/libxc/include/xenctrl.h |  15 ++++++
 tools/libxc/xc_memshr.c       |  19 +++++++
 xen/arch/x86/mm/mem_sharing.c | 121 ++++++++++++++++++++++++++++++++++++++++++
 xen/include/public/memory.h   |  15 +++++-
 4 files changed, 169 insertions(+), 1 deletion(-)
tools/libxc/include/xenctrl.h +15 -0
index 6ae1a2b..34dcc72 100644
@@ -2327,6 +2327,21 @@ int xc_memshr_add_to_physmap(xc_interface *xch,
                     domid_t client_domain,
                     unsigned long client_gfn);
 
+/* Allows to deduplicate the entire memory of a client domain in bulk. Using
+ * this function is equivalent of calling xc_memshr_nominate_gfn for each gfn
+ * in the two domains followed by xc_memshr_share_gfns. If successfull,
+ * returns the number of shared pages in 'shared'. Both domains must be paused.
+ *
+ * May fail with -EINVAL if the source and client domain have different
+ * memory size or if memory sharing is not enabled on either of the domains.
+ * May also fail with -ENOMEM if there isn't enough memory available to store
+ * the sharing metadata before deduplication can happen.
+ */
+int xc_memshr_bulk_share(xc_interface *xch,
+                         domid_t source_domain,
+                         domid_t client_domain,
+                         uint64_t *shared);
+
 /* Debug calls: return the number of pages referencing the shared frame backing
  * the input argument. Should be one or greater. 
  *
tools/libxc/xc_memshr.c +19 -0
index deb0aa4..71350d2 100644
@@ -181,6 +181,25 @@ int xc_memshr_add_to_physmap(xc_interface *xch,
     return xc_memshr_memop(xch, source_domain, &mso);
 }
 
+int xc_memshr_bulk_share(xc_interface *xch,
+                         domid_t source_domain,
+                         domid_t client_domain,
+                         uint64_t *shared)
+{
+    int rc;
+    xen_mem_sharing_op_t mso;
+
+    memset(&mso, 0, sizeof(mso));
+
+    mso.op = XENMEM_sharing_op_bulk_share;
+    mso.u.bulk.client_domain = client_domain;
+
+    rc = xc_memshr_memop(xch, source_domain, &mso);
+    if ( !rc && shared ) *shared = mso.u.bulk.shared;
+
+    return rc;
+}
+
 int xc_memshr_domain_resume(xc_interface *xch,
                             domid_t domid)
 {
xen/arch/x86/mm/mem_sharing.c +121 -0

133 lines not on this page · raw message

xen/include/public/memory.h +14 -1
index 29ec571..084f06e 100644
@@ -465,6 +465,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_mem_access_op_t);
 #define XENMEM_sharing_op_debug_gref        5
 #define XENMEM_sharing_op_add_physmap       6
 #define XENMEM_sharing_op_audit             7
+#define XENMEM_sharing_op_bulk_share        8
 
 #define XENMEM_SHARING_OP_S_HANDLE_INVALID  (-10)
 #define XENMEM_SHARING_OP_C_HANDLE_INVALID  (-9)
@@ -500,7 +501,19 @@ struct xen_mem_sharing_op {
             uint64_aligned_t client_gfn;    /* IN: the client gfn */
             uint64_aligned_t client_handle; /* IN: handle to the client page */
             domid_t  client_domain; /* IN: the client domain id */
-        } share; 
+        } share;
+        struct mem_sharing_op_bulk {         /* OP_BULK_SHARE */
+            uint64_aligned_t start;          /* IN: start gfn. Set to 0 for
+                                                full deduplication. Field is
+                                                reset to 0 when hypercall
+                                                completes */
+            uint64_aligned_t shared;         /* OUT: the number of gfns
+                                                that are shared after this
+                                                operation, including pages
+                                                that were already shared */
+            domid_t client_domain;           /* IN: the client domain id */
+            uint16_t _pad[3];
+        } bulk;
         struct mem_sharing_op_debug {     /* OP_DEBUG_xxx */
             union {
                 uint64_aligned_t gfn;      /* IN: gfn to debug          */
Signature · 7 lines
2.8.1


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

PATCH v5 2/2 tests/mem-sharing: Add bulk option to memshrtool

Add the bulk option to the test tool to perform complete deduplication between domains.

---
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Ian Campbell <[email protected]>

---
 tools/tests/mem-sharing/memshrtool.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
tools/tests/mem-sharing/memshrtool.c +22 -0
index 437c7c9..3e8f467 100644
@@ -24,6 +24,8 @@ static int usage(const char* prog)
     printf("  nominate <domid> <gfn>  - Nominate a page for sharing.\n");
     printf("  share <domid> <gfn> <handle> <source> <source-gfn> <source-handle>\n");
     printf("                          - Share two pages.\n");
+    printf("  bulk <source-domid> <destination-domid>\n");
+    printf("                          - Share all pages between domains.\n");
     printf("  unshare <domid> <gfn>   - Unshare a page by grabbing a writable map.\n");
     printf("  add-to-physmap <domid> <gfn> <source> <source-gfn> <source-handle>\n");
     printf("                          - Populate a page in a domain with a shared page.\n");
@@ -180,6 +182,26 @@ int main(int argc, const char** argv)
         }
         printf("Audit returned %d errors.\n", rc);
     }
+    else if( !strcasecmp(cmd, "bulk") )
+    {
+        domid_t sdomid, cdomid;
+        int rc;
+        unsigned long shared;
+
+        if( argc != 4 )
+            return usage(argv[0]);
+
+        sdomid = strtol(argv[2], NULL, 0);
+        cdomid = strtol(argv[3], NULL, 0);
 
+        rc = xc_memshr_bulk_share(xch, sdomid, cdomid, &shared);
+        if ( rc < 0 )
+        {
+            printf("error executing xc_memshr_bulk_dedup: %s\n", strerror(errno));
+            return rc;
+        }
+
+        printf("Successfully shared %lu pages between the domains\n", shared);
+    }
     return 0;
 }
Signature · 7 lines
2.8.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#2 lore raw
In reply to Tamas K Lengyel
Quoted 11 lines · Tamas K Lengyel

Currently mem-sharing can be performed on a page-by-page base from the control domain. However, when completely deduplicating (cloning) a VM, this requires at least 3 hypercalls per page. As the user has to loop through all pages up to max_gpfn, this process is very slow and wasteful.

This patch introduces a new mem_sharing memop for bulk deduplication where the user doesn't have to separately nominate each page in both the source and destination domain, and the looping over all pages happen in the hypervisor. This significantly reduces the overhead of completely deduplicating entire domains.

Quoted 7 lines

---
Ian Jackson <[email protected]>
George Dunlap <[email protected]>
Jan Beulich <[email protected]>
Andrew Cooper <[email protected]>

Missed Cc: here.

Quoted 239 lines

v4: Add padding to bulk op and enforce it being 0
Use correct XSM permission check

---
 tools/libxc/include/xenctrl.h |  15 ++++++
 tools/libxc/xc_memshr.c       |  19 +++++++
 xen/arch/x86/mm/mem_sharing.c | 121 ++++++++++++++++++++++++++++++++++++++++++
 xen/include/public/memory.h   |  15 +++++-
 4 files changed, 169 insertions(+), 1 deletion(-)
tools/libxc/include/xenctrl.h +15 -0
index 6ae1a2b..34dcc72 100644
@@ -2327,6 +2327,21 @@ int xc_memshr_add_to_physmap(xc_interface *xch,
                     domid_t client_domain,
                     unsigned long client_gfn);
 
+/* Allows to deduplicate the entire memory of a client domain in bulk. Using
+ * this function is equivalent of calling xc_memshr_nominate_gfn for each gfn
+ * in the two domains followed by xc_memshr_share_gfns. If successfull,
+ * returns the number of shared pages in 'shared'. Both domains must be paused.
+ *
+ * May fail with -EINVAL if the source and client domain have different
+ * memory size or if memory sharing is not enabled on either of the domains.
+ * May also fail with -ENOMEM if there isn't enough memory available to store
+ * the sharing metadata before deduplication can happen.
+ */
+int xc_memshr_bulk_share(xc_interface *xch,
+                         domid_t source_domain,
+                         domid_t client_domain,
+                         uint64_t *shared);
+
 /* Debug calls: return the number of pages referencing the shared frame backing
  * the input argument. Should be one or greater.
  *
tools/libxc/xc_memshr.c +19 -0
index deb0aa4..71350d2 100644
@@ -181,6 +181,25 @@ int xc_memshr_add_to_physmap(xc_interface *xch,
     return xc_memshr_memop(xch, source_domain, &mso);
 }
 
+int xc_memshr_bulk_share(xc_interface *xch,
+                         domid_t source_domain,
+                         domid_t client_domain,
+                         uint64_t *shared)
+{
+    int rc;
+    xen_mem_sharing_op_t mso;
+
+    memset(&mso, 0, sizeof(mso));
+
+    mso.op = XENMEM_sharing_op_bulk_share;
+    mso.u.bulk.client_domain = client_domain;
+
+    rc = xc_memshr_memop(xch, source_domain, &mso);
+    if ( !rc && shared ) *shared = mso.u.bulk.shared;
+
+    return rc;
+}
+
 int xc_memshr_domain_resume(xc_interface *xch,
                             domid_t domid)
 {
xen/arch/x86/mm/mem_sharing.c +121 -0
index a522423..ba06fb0 100644
@@ -1294,6 +1294,54 @@ int relinquish_shared_pages(struct domain *d)
     return rc;
 }
 
+static int bulk_share(struct domain *d, struct domain *cd, unsigned long limit,
+                      struct mem_sharing_op_bulk *bulk)
+{
+    int rc = 0;
+    shr_handle_t sh, ch;
+
+    while( limit > bulk->start )
+    {
+        /*
+         * We only break out if we run out of memory as individual pages may
+         * legitimately be unsharable and we just want to skip over those.
+         */
+        rc = mem_sharing_nominate_page(d, bulk->start, 0, &sh);
+        if ( rc == -ENOMEM )
+            break;
+        if ( !rc )
+        {
+            rc = mem_sharing_nominate_page(cd, bulk->start, 0, &ch);
+            if ( rc == -ENOMEM )
+                break;
+            if ( !rc )
+            {
+                /* If we get here this should be guaranteed to succeed. */
+                rc = mem_sharing_share_pages(d, bulk->start, sh,
+                                             cd, bulk->start, ch);
+                ASSERT(!rc);
+            }
+        }
+
+        /* Check for continuation if it's not the last iteration. */
+        if ( limit > ++bulk->start && hypercall_preempt_check() )
+        {
+            rc = 1;
+            break;
+        }
+    }
+
+    /*
+     * We only propagate -ENOMEM as individual pages may fail with -EINVAL,
+     * and for bulk sharing we only care if -ENOMEM was encountered so we reset
+     * rc here.
+     */
+    if ( rc < 0 && rc != -ENOMEM )
+        rc = 0;
+
+    return rc;
+}
+
 int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg)
 {
     int rc;
@@ -1468,6 +1516,79 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg)
         }
         break;
 
+        case XENMEM_sharing_op_bulk_share:
+        {
+            unsigned long max_sgfn, max_cgfn;
+            struct domain *cd;
+
+            rc = -EINVAL;
+            if( mso.u.bulk._pad[0] || mso.u.bulk._pad[1] || mso.u.bulk._pad[2] )
+                goto out;
+
+            if ( !mem_sharing_enabled(d) )
+                goto out;
+
+            rc = rcu_lock_live_remote_domain_by_id(mso.u.bulk.client_domain,
+                                                   &cd);
+            if ( rc )
+                goto out;
+
+            /*
+             * We reuse XENMEM_sharing_op_share XSM check here as this is essentially
+             * the same concept repeated over multiple pages.
+             */
+            rc = xsm_mem_sharing_op(XSM_DM_PRIV, d, cd, XENMEM_sharing_op_share);
+            if ( rc )
+            {
+                rcu_unlock_domain(cd);
+                goto out;
+            }
+
+            if ( !mem_sharing_enabled(cd) )
+            {
+                rcu_unlock_domain(cd);
+                rc = -EINVAL;
+                goto out;
+            }
+
+            if ( !atomic_read(&d->pause_count) ||
+                 !atomic_read(&cd->pause_count) )
+            {
+                rcu_unlock_domain(cd);
+                rc = -EINVAL;
+                goto out;
+            }
+
+            max_sgfn = domain_get_maximum_gpfn(d);
+            max_cgfn = domain_get_maximum_gpfn(cd);
+
+            if ( max_sgfn != max_cgfn || max_sgfn < mso.u.bulk.start )
+            {
+                rcu_unlock_domain(cd);
+                rc = -EINVAL;
+                goto out;
+            }
+
+            rc = bulk_share(d, cd, max_sgfn + 1, &mso.u.bulk);
+            if ( rc > 0 )
+            {
+                if ( __copy_to_guest(arg, &mso, 1) )
+                    rc = -EFAULT;
+                else
+                    rc = hypercall_create_continuation(__HYPERVISOR_memory_op,
+                                                       "lh", XENMEM_sharing_op,
+                                                       arg);
+            }
+            else
+            {
+                mso.u.bulk.start = 0;
+                mso.u.bulk.shared = atomic_read(&cd->shr_pages);
+            }
+
+            rcu_unlock_domain(cd);
+        }
+        break;
+
         case XENMEM_sharing_op_debug_gfn:
         {
             unsigned long gfn = mso.u.debug.u.gfn;
xen/include/public/memory.h +14 -2
index 29ec571..084f06e 100644
@@ -465,6 +465,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_mem_access_op_t);
 #define XENMEM_sharing_op_debug_gref        5
 #define XENMEM_sharing_op_add_physmap       6
 #define XENMEM_sharing_op_audit             7
+#define XENMEM_sharing_op_bulk_share        8
 
 #define XENMEM_SHARING_OP_S_HANDLE_INVALID  (-10)
 #define XENMEM_SHARING_OP_C_HANDLE_INVALID  (-9)
@@ -500,7 +501,19 @@ struct xen_mem_sharing_op {
             uint64_aligned_t client_gfn;    /* IN: the client gfn */
             uint64_aligned_t client_handle; /* IN: handle to the client page */
             domid_t  client_domain; /* IN: the client domain id */
-        } share;
+        } share;
+        struct mem_sharing_op_bulk {         /* OP_BULK_SHARE */
+            uint64_aligned_t start;          /* IN: start gfn. Set to 0 for
+                                                full deduplication. Field is
+                                                reset to 0 when hypercall
+                                                completes */
+            uint64_aligned_t shared;         /* OUT: the number of gfns
+                                                that are shared after this
+                                                operation, including pages
+                                                that were already shared */
+            domid_t client_domain;           /* IN: the client domain id */
+            uint16_t _pad[3];
+        } bulk;
         struct mem_sharing_op_debug {     /* OP_DEBUG_xxx */
             union {
                 uint64_aligned_t gfn;      /* IN: gfn to debug          */
--
Quoted 2 lines

2.8.1

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

Reviewed-by on v5 1/2
#3 lore raw
In reply to Tamas K Lengyel

xen/arch/x86/mm/mem_sharing.c int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg) · line 1525

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 12.06.16 at 01:24, <[email protected]> wrote:
xen/arch/x86/mm/mem_sharing.c +7 -0
@@ -1468,6 +1516,79 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg)
         }
         break;
 
+        case XENMEM_sharing_op_bulk_share:
+        {
+            unsigned long max_sgfn, max_cgfn;
+            struct domain *cd;
+
+            rc = -EINVAL;
+            if( mso.u.bulk._pad[0] || mso.u.bulk._pad[1] || mso.u.bulk._pad[2] )

With the missing blank added here (doable on commit as well), hypervisor side

xen/arch/x86/mm/mem_sharing.c int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg) · line 1529

Quoted 4 lines
xen/arch/x86/mm/mem_sharing.c +4 -0
+                goto out;
+
+            if ( !mem_sharing_enabled(d) )
+                goto out;

Irrespective of the above I think a more descriptive error than -EINVAL would be quite reasonable to expect for a sharing operation attempted without having enabled sharing. By the name of it (but not by its conventional meaning) -EILSEQ might be a candidate.

Quoted 27 lines
xen/arch/x86/mm/mem_sharing.c +27 -0
+            rc = rcu_lock_live_remote_domain_by_id(mso.u.bulk.client_domain,
+                                                   &cd);
+            if ( rc )
+                goto out;
+
+            /*
+             * We reuse XENMEM_sharing_op_share XSM check here as this is essentially
+             * the same concept repeated over multiple pages.
+             */
+            rc = xsm_mem_sharing_op(XSM_DM_PRIV, d, cd, XENMEM_sharing_op_share);
+            if ( rc )
+            {
+                rcu_unlock_domain(cd);
+                goto out;
+            }
+
+            if ( !mem_sharing_enabled(cd) )
+            {
+                rcu_unlock_domain(cd);
+                rc = -EINVAL;
+                goto out;
+            }
+
+            if ( !atomic_read(&d->pause_count) ||
+                 !atomic_read(&cd->pause_count) )
+            {
+                rcu_unlock_domain(cd);

xen/arch/x86/mm/mem_sharing.c int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg) · line 1567

Quoted 10 lines
xen/arch/x86/mm/mem_sharing.c +10 -0
+                rc = -EINVAL;
+                goto out;
+            }
+
+            max_sgfn = domain_get_maximum_gpfn(d);
+            max_cgfn = domain_get_maximum_gpfn(cd);
+
+            if ( max_sgfn != max_cgfn || max_sgfn < mso.u.bulk.start )
+            {
+                rcu_unlock_domain(cd);

I'd also recommend adding a new label below to avoid these repeated rcu_unlock_domain(cd) invocations.

But for both of these - you're the maintainer, so you know best.

Jan

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

#4 lore raw
In reply to Tamas K Lengyel
Quoted 5 lines
xen/arch/x86/mm/mem_sharing.c +0 -0
index a522423..ba06fb0 100644

xen/arch/x86/mm/mem_sharing.c int relinquish_shared_pages(struct domain *d) · line 1303

Quoted 10 lines
xen/arch/x86/mm/mem_sharing.c +7 -0
@@ -1294,6 +1294,54 @@ int relinquish_shared_pages(struct domain *d)
     return rc;
 }
 
+static int bulk_share(struct domain *d, struct domain *cd, unsigned long limit,
+                      struct mem_sharing_op_bulk *bulk)
+{
+    int rc = 0;
+    shr_handle_t sh, ch;
+
+    while( limit > bulk->start )

You are missing a space there.

Quoted 14 lines
xen/arch/x86/mm/mem_sharing.c +14 -0
+    {
+        /*
+         * We only break out if we run out of memory as individual pages may
+         * legitimately be unsharable and we just want to skip over those.
+         */
+        rc = mem_sharing_nominate_page(d, bulk->start, 0, &sh);
+        if ( rc == -ENOMEM )
+            break;
+        if ( !rc )
+        {
+            rc = mem_sharing_nominate_page(cd, bulk->start, 0, &ch);
+            if ( rc == -ENOMEM )
+                break;
+            if ( !rc )

xen/arch/x86/mm/mem_sharing.c int relinquish_shared_pages(struct domain *d) · line 1327

Quoted 10 lines
xen/arch/x86/mm/mem_sharing.c +10 -0
+            {
+                /* If we get here this should be guaranteed to succeed. */
+                rc = mem_sharing_share_pages(d, bulk->start, sh,
+                                             cd, bulk->start, ch);
+                ASSERT(!rc);
+            }
+        }
+
+        /* Check for continuation if it's not the last iteration. */
+        if ( limit > ++bulk->start && hypercall_preempt_check() )

I surprised the compiler didn't complain to you about lack of parenthesis.

Quoted 21 lines
xen/arch/x86/mm/mem_sharing.c +17 -0
+        {
+            rc = 1;
+            break;
+        }
+    }
+
+    /*
+     * We only propagate -ENOMEM as individual pages may fail with -EINVAL,
+     * and for bulk sharing we only care if -ENOMEM was encountered so we reset
+     * rc here.
+     */
+    if ( rc < 0 && rc != -ENOMEM )
+        rc = 0;
+
+    return rc;
+}
+
 int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg)
 {
     int rc;

xen/arch/x86/mm/mem_sharing.c int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg) · line 1525

Quoted 10 lines
xen/arch/x86/mm/mem_sharing.c +7 -0
@@ -1468,6 +1516,79 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg)
         }
         break;
 
+        case XENMEM_sharing_op_bulk_share:
+        {
+            unsigned long max_sgfn, max_cgfn;
+            struct domain *cd;
+
+            rc = -EINVAL;
+            if( mso.u.bulk._pad[0] || mso.u.bulk._pad[1] || mso.u.bulk._pad[2] )

The "if("..

_______________________________________________
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): CABfawhmqhAsEk=J5F3y0tAvd74xfi1_2-A+tfKzwCapcmL1zPg@mail.gmail.com

A message that is not in the archive (sent off-list or not yet received): CABfawh=Hw-mZi+d751pRhA-C-wLOJ3TQPkW6rLAYp+GGGbxx1Q@mail.gmail.com

A message that is not in the archive (sent off-list or not yet received): CABfawhnZVFt2Hwrfb+DNH3ft3gbB3Bc4+h7EpJfXbf=1_P-LWQ@mail.gmail.com

A message that is not in the archive (sent off-list or not yet received): CABfawhkTvytb7NvHJ-AHJBCxA3wJ5Fo-ciV66JpSY-xdK+3v5Q@mail.gmail.com

#9 lore raw
Quoted 2 lines · Konrad Rzeszutek Wilk

Review

Quoted 2 lines
(quoted diff) +0 -0

b/xen/arch/x86/mm/mem_sharing.c

Quoted 8 lines

xen/arch/x86/mm/mem_sharing.c int relinquish_shared_pages(struct domain *d) · line 1297

Quoted 8 lines

index a522423..ba06fb0 100644

xen/arch/x86/mm/mem_sharing.c +1 -0
@@ -1294,6 +1294,54 @@ int relinquish_shared_pages(struct domain *d)
     return rc;
 }
 
+static int bulk_share(struct domain *d, struct domain *cd, unsigned

long limit,

Quoted 8 lines

xen/arch/x86/mm/mem_sharing.c int relinquish_shared_pages(struct domain *d) · line 1303

Quoted 6 lines
xen/arch/x86/mm/mem_sharing.c +6 -0
+                      struct mem_sharing_op_bulk *bulk)
+{
+    int rc = 0;
+    shr_handle_t sh, ch;
+
+    while( limit > bulk->start )

You are missing a space there.

Ack.

Quoted 3 lines

xen/arch/x86/mm/mem_sharing.c int relinquish_shared_pages(struct domain *d)

Quoted 3 lines
xen/arch/x86/mm/mem_sharing.c +3 -0
+    {
+        /*
+         * We only break out if we run out of memory as individual

pages may

Quoted 1 line

xen/arch/x86/mm/mem_sharing.c int relinquish_shared_pages(struct domain *d) · line 1307

Quoted 1 line
xen/arch/x86/mm/mem_sharing.c +1 -0
+         * legitimately be unsharable and we just want to skip over

those.

Quoted 4 lines
Quoted 4 lines
xen/arch/x86/mm/mem_sharing.c +4 -0
+         */
+        rc = mem_sharing_nominate_page(d, bulk->start, 0, &sh);
+        if ( rc == -ENOMEM )
+            break;
Quoted 8 lines

xen/arch/x86/mm/mem_sharing.c int relinquish_shared_pages(struct domain *d)

Quoted 8 lines
xen/arch/x86/mm/mem_sharing.c +8 -0
+        if ( !rc )
+        {
+            rc = mem_sharing_nominate_page(cd, bulk->start, 0, &ch);
+            if ( rc == -ENOMEM )
+                break;
+            if ( !rc )
+            {
+                /* If we get here this should be guaranteed to

succeed. */

Quoted 10 lines

xen/arch/x86/mm/mem_sharing.c int relinquish_shared_pages(struct domain *d) · line 1327

Quoted 8 lines
xen/arch/x86/mm/mem_sharing.c +8 -0
+                rc = mem_sharing_share_pages(d, bulk->start, sh,
+                                             cd, bulk->start, ch);
+                ASSERT(!rc);
+            }
+        }
+
+        /* Check for continuation if it's not the last iteration. */
+        if ( limit > ++bulk->start && hypercall_preempt_check() )

I surprised the compiler didn't complain to you about lack of parenthesis.

This seems to be standard way to create continuation used in multiple places throughout Xen. I don't personally like it much but I guess it's better to be consistent.

Quoted 9 lines

xen/arch/x86/mm/mem_sharing.c int relinquish_shared_pages(struct domain *d)

Quoted 9 lines
xen/arch/x86/mm/mem_sharing.c +8 -0
+        {
+            rc = 1;
+            break;
+        }
+    }
+
+    /*
+     * We only propagate -ENOMEM as individual pages may fail with

-EINVAL,

Quoted 1 line

xen/arch/x86/mm/mem_sharing.c int relinquish_shared_pages(struct domain *d) · line 1336

Quoted 1 line
xen/arch/x86/mm/mem_sharing.c +1 -0
+     * and for bulk sharing we only care if -ENOMEM was encountered so

we reset

Quoted 4 lines
Quoted 4 lines
xen/arch/x86/mm/mem_sharing.c +4 -0
+     * rc here.
+     */
+    if ( rc < 0 && rc != -ENOMEM )
+        rc = 0;
Quoted 8 lines

xen/arch/x86/mm/mem_sharing.c int

Quoted 8 lines
xen/arch/x86/mm/mem_sharing.c +4 -0
+
+    return rc;
+}
+
 int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg)
 {
     int rc;
@@ -1468,6 +1516,79 @@ int

mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg)

Quoted 10 lines

xen/arch/x86/mm/mem_sharing.c int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg)

Quoted 10 lines
xen/arch/x86/mm/mem_sharing.c +7 -0
         }
         break;
 
+        case XENMEM_sharing_op_bulk_share:
+        {
+            unsigned long max_sgfn, max_cgfn;
+            struct domain *cd;
+
+            rc = -EINVAL;
+            if( mso.u.bulk._pad[0] || mso.u.bulk._pad[1] ||

mso.u.bulk._pad[2] )

Quoted 2 lines

The "if("..

Ack.

Thanks,
Tamas

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

#10 lore raw
In reply to Konrad Rzeszutek Wilk
Quoted 5 lines

xen/arch/x86/mm/mem_sharing.c int relinquish_shared_pages(struct domain *d) · line 1327

Quoted 3 lines
Quoted 1 line · On 14.06.16 at 18:33, <[email protected]> wrote:
xen/arch/x86/mm/mem_sharing.c +2 -0
+        /* Check for continuation if it's not the last iteration. */
+        if ( limit > ++bulk->start && hypercall_preempt_check() )

I surprised the compiler didn't complain to you about lack of parenthesis.

I'm puzzled - what kind of warning would you expect here? The compiler - afaik - treats relational operators vs logical AND/OR as having well known precedence wrt to one another; what iirc it would warn about is lack of parentheses in an expression using both of the logical operators, as people frequently don't know that && has higher precedence than ||.

Jan

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

#11 lore raw
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 3 lines
Quoted 1 line · On 14.06.16 at 18:33, <[email protected]> wrote:
xen/arch/x86/mm/mem_sharing.c +2 -0
+        /* Check for continuation if it's not the last iteration. */
+        if ( limit > ++bulk->start && hypercall_preempt_check() )
Quoted 8 lines
Quoted 1 line

I surprised the compiler didn't complain to you about lack of parenthesis.

I'm puzzled - what kind of warning would you expect here? The compiler - afaik - treats relational operators vs logical AND/OR as having well known precedence wrt to one another; what iirc it would warn about is lack of parentheses in an expression using both of the logical operators, as people frequently don't know that && has higher precedence than ||.

Maybe those are the warnings I had seen in the past. I recall that with a more modern compiler it would give me suggestions to use parenthesis. But I honestly can't recall the details.

Either way - the code is fine.

Quoted 3 lines

Jan

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

#12 lore raw
In reply to Tamas K Lengyel
Quoted 11 lines · Tamas K Lengyel

Currently mem-sharing can be performed on a page-by-page base from the control domain. However, when completely deduplicating (cloning) a VM, this requires at least 3 hypercalls per page. As the user has to loop through all pages up to max_gpfn, this process is very slow and wasteful.

This patch introduces a new mem_sharing memop for bulk deduplication where the user doesn't have to separately nominate each page in both the source and destination domain, and the looping over all pages happen in the hypervisor. This significantly reduces the overhead of completely deduplicating entire domains.

Quoted 7 lines

---
Ian Jackson <[email protected]>
George Dunlap <[email protected]>
Jan Beulich <[email protected]>
Andrew Cooper <[email protected]>

I'm sorry I'm a bit late to this party -- I'm not sure how I managed to miss the earlier posts of this. A couple of questions...

Quoted 36 lines
xen/arch/x86/mm/mem_sharing.c +32 -0
@@ -1468,6 +1516,79 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg)
         }
         break;
 
+        case XENMEM_sharing_op_bulk_share:
+        {
+            unsigned long max_sgfn, max_cgfn;
+            struct domain *cd;
+
+            rc = -EINVAL;
+            if( mso.u.bulk._pad[0] || mso.u.bulk._pad[1] || mso.u.bulk._pad[2] )
+                goto out;
+
+            if ( !mem_sharing_enabled(d) )
+                goto out;
+
+            rc = rcu_lock_live_remote_domain_by_id(mso.u.bulk.client_domain,
+                                                   &cd);
+            if ( rc )
+                goto out;
+
+            /*
+             * We reuse XENMEM_sharing_op_share XSM check here as this is essentially
+             * the same concept repeated over multiple pages.
+             */
+            rc = xsm_mem_sharing_op(XSM_DM_PRIV, d, cd, XENMEM_sharing_op_share);
+            if ( rc )
+            {
+                rcu_unlock_domain(cd);
+                goto out;
+            }
+
+            if ( !mem_sharing_enabled(cd) )
+            {
+                rcu_unlock_domain(cd);
+                rc = -EINVAL;

xen/arch/x86/mm/mem_sharing.c int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg) · line 1560

Quoted 10 lines
xen/arch/x86/mm/mem_sharing.c +10 -0
+                goto out;
+            }
+
+            if ( !atomic_read(&d->pause_count) ||
+                 !atomic_read(&cd->pause_count) )
+            {
+                rcu_unlock_domain(cd);
+                rc = -EINVAL;
+                goto out;
+            }

I realize that Jan asked for this, but I'm really not sure what good this is supposed to do, since the guest can be un-paused at any point halfway through the transaction.

Wouldn't it make more sense to have this function pause and unpause the domains itself?

Quoted 47 lines
xen/arch/x86/mm/mem_sharing.c +31 -0
+
+            max_sgfn = domain_get_maximum_gpfn(d);
+            max_cgfn = domain_get_maximum_gpfn(cd);
+
+            if ( max_sgfn != max_cgfn || max_sgfn < mso.u.bulk.start )
+            {
+                rcu_unlock_domain(cd);
+                rc = -EINVAL;
+                goto out;
+            }
+
+            rc = bulk_share(d, cd, max_sgfn + 1, &mso.u.bulk);
+            if ( rc > 0 )
+            {
+                if ( __copy_to_guest(arg, &mso, 1) )
+                    rc = -EFAULT;
+                else
+                    rc = hypercall_create_continuation(__HYPERVISOR_memory_op,
+                                                       "lh", XENMEM_sharing_op,
+                                                       arg);
+            }
+            else
+            {
+                mso.u.bulk.start = 0;
+                mso.u.bulk.shared = atomic_read(&cd->shr_pages);
+            }
+
+            rcu_unlock_domain(cd);
+        }
+        break;
+
         case XENMEM_sharing_op_debug_gfn:
         {
             unsigned long gfn = mso.u.debug.u.gfn;
xen/include/public/memory.h +1 -0
index 29ec571..084f06e 100644
@@ -465,6 +465,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_mem_access_op_t);
 #define XENMEM_sharing_op_debug_gref        5
 #define XENMEM_sharing_op_add_physmap       6
 #define XENMEM_sharing_op_audit             7
+#define XENMEM_sharing_op_bulk_share        8
 
 #define XENMEM_SHARING_OP_S_HANDLE_INVALID  (-10)
 #define XENMEM_SHARING_OP_C_HANDLE_INVALID  (-9)

xen/include/public/memory.h struct xen_mem_sharing_op { · line 509

Quoted 10 lines
xen/include/public/memory.h +6 -1
@@ -500,7 +501,19 @@ struct xen_mem_sharing_op {
             uint64_aligned_t client_gfn;    /* IN: the client gfn */
             uint64_aligned_t client_handle; /* IN: handle to the client page */
             domid_t  client_domain; /* IN: the client domain id */
-        } share;
+        } share;
+        struct mem_sharing_op_bulk {         /* OP_BULK_SHARE */
+            uint64_aligned_t start;          /* IN: start gfn. Set to 0 for
+                                                full deduplication. Field is
+                                                reset to 0 when hypercall
+                                                completes */

It took me a while to figure out that this value isn't actually intended to be used as described. You're actually intended to always set this to zero, and the hypervisor just uses it for scratch space.

To start with, it seems like having a "bulk share" option which could do just a specific range would be useful as well as a "bulk share" which automatically deduped the entire set of memory.

Secondly, structuring the information like the other memory operations -- for example, "nr_extents" and "nr_done" -- would make it more consistent, and would allow you to also to avoid overwriting one of the "in" values and having to restore it when you were done.

Other than that, it looks OK.

-George

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

#13 lore raw
Quoted 75 lines · George Dunlap
Quoted 11 lines · Tamas K Lengyel

Currently mem-sharing can be performed on a page-by-page base from the control domain. However, when completely deduplicating (cloning) a VM, this requires at least 3 hypercalls per page. As the user has to loop through all pages up to max_gpfn, this process is very slow and wasteful.

This patch introduces a new mem_sharing memop for bulk deduplication where the user doesn't have to separately nominate each page in both the source and destination domain, and the looping over all pages happen in the hypervisor. This significantly reduces the overhead of completely deduplicating entire domains.

Quoted 7 lines

---
Ian Jackson <[email protected]>
George Dunlap <[email protected]>
Jan Beulich <[email protected]>
Andrew Cooper <[email protected]>

I'm sorry I'm a bit late to this party -- I'm not sure how I managed to miss the earlier posts of this. A couple of questions...

Quoted 36 lines
xen/arch/x86/mm/mem_sharing.c +32 -0
@@ -1468,6 +1516,79 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg)
         }
         break;
 
+        case XENMEM_sharing_op_bulk_share:
+        {
+            unsigned long max_sgfn, max_cgfn;
+            struct domain *cd;
+
+            rc = -EINVAL;
+            if( mso.u.bulk._pad[0] || mso.u.bulk._pad[1] || mso.u.bulk._pad[2] )
+                goto out;
+
+            if ( !mem_sharing_enabled(d) )
+                goto out;
+
+            rc = rcu_lock_live_remote_domain_by_id(mso.u.bulk.client_domain,
+                                                   &cd);
+            if ( rc )
+                goto out;
+
+            /*
+             * We reuse XENMEM_sharing_op_share XSM check here as this is essentially
+             * the same concept repeated over multiple pages.
+             */
+            rc = xsm_mem_sharing_op(XSM_DM_PRIV, d, cd, XENMEM_sharing_op_share);
+            if ( rc )
+            {
+                rcu_unlock_domain(cd);
+                goto out;
+            }
+
+            if ( !mem_sharing_enabled(cd) )
+            {
+                rcu_unlock_domain(cd);
+                rc = -EINVAL;

xen/arch/x86/mm/mem_sharing.c int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg) · line 1560

Quoted 10 lines
xen/arch/x86/mm/mem_sharing.c +10 -0
+                goto out;
+            }
+
+            if ( !atomic_read(&d->pause_count) ||
+                 !atomic_read(&cd->pause_count) )
+            {
+                rcu_unlock_domain(cd);
+                rc = -EINVAL;
+                goto out;
+            }

I realize that Jan asked for this, but I'm really not sure what good this is supposed to do, since the guest can be un-paused at any point halfway through the transaction.

Quoted 2 lines

Wouldn't it make more sense to have this function pause and unpause the domains itself?

The domains are paused by the user when this op is called, so this is just a sanity check ensuring you are not issuing the op on some other domain. So if this function would pause the domain as well all it would do is increase the pause count. This is the only intended use-case for this function at this time. It would make no sense to try to issue this op on domains that are running, as that pretty much guarantee that some of their memory has already diverged, and thus bulk-sharing their memory would have some unintended side-effects.

Quoted 54 lines
Quoted 54 lines
xen/arch/x86/mm/mem_sharing.c +31 -0
+
+            max_sgfn = domain_get_maximum_gpfn(d);
+            max_cgfn = domain_get_maximum_gpfn(cd);
+
+            if ( max_sgfn != max_cgfn || max_sgfn < mso.u.bulk.start )
+            {
+                rcu_unlock_domain(cd);
+                rc = -EINVAL;
+                goto out;
+            }
+
+            rc = bulk_share(d, cd, max_sgfn + 1, &mso.u.bulk);
+            if ( rc > 0 )
+            {
+                if ( __copy_to_guest(arg, &mso, 1) )
+                    rc = -EFAULT;
+                else
+                    rc = hypercall_create_continuation(__HYPERVISOR_memory_op,
+                                                       "lh", XENMEM_sharing_op,
+                                                       arg);
+            }
+            else
+            {
+                mso.u.bulk.start = 0;
+                mso.u.bulk.shared = atomic_read(&cd->shr_pages);
+            }
+
+            rcu_unlock_domain(cd);
+        }
+        break;
+
         case XENMEM_sharing_op_debug_gfn:
         {
             unsigned long gfn = mso.u.debug.u.gfn;
xen/include/public/memory.h +3 -1
index 29ec571..084f06e 100644
@@ -465,6 +465,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_mem_access_op_t);
 #define XENMEM_sharing_op_debug_gref        5
 #define XENMEM_sharing_op_add_physmap       6
 #define XENMEM_sharing_op_audit             7
+#define XENMEM_sharing_op_bulk_share        8
 
 #define XENMEM_SHARING_OP_S_HANDLE_INVALID  (-10)
 #define XENMEM_SHARING_OP_C_HANDLE_INVALID  (-9)
@@ -500,7 +501,19 @@ struct xen_mem_sharing_op {
             uint64_aligned_t client_gfn;    /* IN: the client gfn */
             uint64_aligned_t client_handle; /* IN: handle to the client page */
             domid_t  client_domain; /* IN: the client domain id */
-        } share;
+        } share;
+        struct mem_sharing_op_bulk {         /* OP_BULK_SHARE */
Quoted 8 lines

xen/include/public/memory.h struct xen_mem_sharing_op { · line 509

Quoted 4 lines
xen/include/public/memory.h +4 -0
+            uint64_aligned_t start;          /* IN: start gfn. Set to 0 for
+                                                full deduplication. Field is
+                                                reset to 0 when hypercall
+                                                completes */

It took me a while to figure out that this value isn't actually intended to be used as described. You're actually intended to always set this to zero, and the hypervisor just uses it for scratch space.

In my original patch there was no field such as this but was requested by other Maintainers. So technically it is now possible to start bulk-sharing at a pfn other then 0 and the op would work, it would just result in less then full sharing. I certainly have no use-case for it but it is possible to use it that way so I simply documented that unintended "feature".

Quoted 4 lines

To start with, it seems like having a "bulk share" option which could do just a specific range would be useful as well as a "bulk share" which automatically deduped the entire set of memory.

I have no need for such options.

Quoted 5 lines

Secondly, structuring the information like the other memory operations -- for example, "nr_extents" and "nr_done" -- would make it more consistent, and would allow you to also to avoid overwriting one of the "in" values and having to restore it when you were done.

I don't see any harm in clearing this value to 0 when the op finishes so I don't think it would really make much difference if we have another field just for scratch-space use. I'm fine with adding that but it just seems a bit odd to me.

Tamas

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

#14 lore raw
Quoted 15 lines · Tamas K Lengyel
Quoted 8 lines

xen/arch/x86/mm/mem_sharing.c int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg) · line 1560

Quoted 7 lines
xen/arch/x86/mm/mem_sharing.c +7 -0
+            if ( !atomic_read(&d->pause_count) ||
+                 !atomic_read(&cd->pause_count) )
+            {
+                rcu_unlock_domain(cd);
+                rc = -EINVAL;
+                goto out;
+            }
Quoted 6 lines

I realize that Jan asked for this, but I'm really not sure what good this is supposed to do, since the guest can be un-paused at any point halfway through the transaction.

Wouldn't it make more sense to have this function pause and unpause the domains itself?

Quoted 8 lines

The domains are paused by the user when this op is called, so this is just a sanity check ensuring you are not issuing the op on some other domain. So if this function would pause the domain as well all it would do is increase the pause count. This is the only intended use-case for this function at this time. It would make no sense to try to issue this op on domains that are running, as that pretty much guarantee that some of their memory has already diverged, and thus bulk-sharing their memory would have some unintended side-effects.

Yes, I understand all that. But what I'm saying (and mostly this is actually to Jan that I'm saying it) is that this check, as written, seems pointless to me. We're effectively *not* trusting the toolstack to pause the domain, but we *are* trust the toolstack not to unpause the domain before the operation is completed. It seems to me we should either trust the toolstack to pause the domain and leave it paused -- letting it suffer the consequences if it fails to do so -- or we should pause and unpause the domain ourselves.

Adding an extra pause count is simple and harmless. If we're going to make an effort to think about buggy toolstacks, we might as well just make it 100% safe.

Quoted 5 lines
Quoted 3 lines

To start with, it seems like having a "bulk share" option which could do just a specific range would be useful as well as a "bulk share" which automatically deduped the entire set of memory.

I have no need for such options.

Yes, but it's not unlikely that somebody else may need them at some point in the future; and it's only a tiny bit of adjustment to make them more generally useful than just your current specific use case, so that we can avoid changing the interface, or adding yet another hypercall in the future.

Quoted 9 lines
Quoted 4 lines

Secondly, structuring the information like the other memory operations -- for example, "nr_extents" and "nr_done" -- would make it more consistent, and would allow you to also to avoid overwriting one of the "in" values and having to restore it when you were done.

I don't see any harm in clearing this value to 0 when the op finishes so I don't think it would really make much difference if we have another field just for scratch-space use. I'm fine with adding that but it just seems a bit odd to me.

Well clearing the value to zero seems a bit odd to me. :-) But more to the point, it's valuable to have the interface 1) be flexible enough to bulk-share a range but not the entire address space 2) be similar enough to existing interfaces that nobody needs to figure out how it works.

-George

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

#15 lore raw
Quoted 34 lines · George Dunlap
Quoted 15 lines · Tamas K Lengyel
Quoted 8 lines

xen/arch/x86/mm/mem_sharing.c int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg) · line 1560

Quoted 7 lines
xen/arch/x86/mm/mem_sharing.c +7 -0
+            if ( !atomic_read(&d->pause_count) ||
+                 !atomic_read(&cd->pause_count) )
+            {
+                rcu_unlock_domain(cd);
+                rc = -EINVAL;
+                goto out;
+            }
Quoted 6 lines

I realize that Jan asked for this, but I'm really not sure what good this is supposed to do, since the guest can be un-paused at any point halfway through the transaction.

Wouldn't it make more sense to have this function pause and unpause the domains itself?

Quoted 8 lines

The domains are paused by the user when this op is called, so this is just a sanity check ensuring you are not issuing the op on some other domain. So if this function would pause the domain as well all it would do is increase the pause count. This is the only intended use-case for this function at this time. It would make no sense to try to issue this op on domains that are running, as that pretty much guarantee that some of their memory has already diverged, and thus bulk-sharing their memory would have some unintended side-effects.

Yes, I understand all that. But what I'm saying (and mostly this is actually to Jan that I'm saying it) is that this check, as written, seems pointless to me. We're effectively *not* trusting the toolstack to pause the domain, but we *are* trust the toolstack not to unpause the domain before the operation is completed. It seems to me we should either trust the toolstack to pause the domain and leave it paused -- letting it suffer the consequences if it fails to do so -- or we should pause and unpause the domain ourselves.

Quoted 3 lines

Adding an extra pause count is simple and harmless. If we're going to make an effort to think about buggy toolstacks, we might as well just make it 100% safe.

Well, there are many many more ways the toolstack could cause issues for this op so I would say let's just trust the toolstack to behave as intended so I'll remove the pause check and point out in a comment that the intended usecase assumes both domains are paused and remain paused for the duration of the op.

Quoted 23 lines
Quoted 6 lines
Quoted 4 lines

To start with, it seems like having a "bulk share" option which could do just a specific range would be useful as well as a "bulk share" which automatically deduped the entire set of memory.

I have no need for such options.

Yes, but it's not unlikely that somebody else may need them at some point in the future; and it's only a tiny bit of adjustment to make them more generally useful than just your current specific use case, so that we can avoid changing the interface, or adding yet another hypercall in the future.

Quoted 9 lines
Quoted 4 lines

Secondly, structuring the information like the other memory operations -- for example, "nr_extents" and "nr_done" -- would make it more consistent, and would allow you to also to avoid overwriting one of the "in" values and having to restore it when you were done.

I don't see any harm in clearing this value to 0 when the op finishes so I don't think it would really make much difference if we have another field just for scratch-space use. I'm fine with adding that but it just seems a bit odd to me.

Quoted 5 lines

Well clearing the value to zero seems a bit odd to me. :-) But more to the point, it's valuable to have the interface 1) be flexible enough to bulk-share a range but not the entire address space 2) be similar enough to existing interfaces that nobody needs to figure out how it works.

I really doubt there will be any users for this feature but it's simple enough of an adjustment that I'm fine with the change.

Thanks,
Tamas

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

#16 lore raw
In reply to George Dunlap
Quoted 43 lines
Quoted 1 line
Quoted 1 line · On 05.07.16 at 16:35, <[email protected]> wrote:
Quoted 15 lines · Tamas K Lengyel
Quoted 8 lines

xen/arch/x86/mm/mem_sharing.c int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg) · line 1560

Quoted 7 lines
xen/arch/x86/mm/mem_sharing.c +7 -0
+            if ( !atomic_read(&d->pause_count) ||
+                 !atomic_read(&cd->pause_count) )
+            {
+                rcu_unlock_domain(cd);
+                rc = -EINVAL;
+                goto out;
+            }
Quoted 6 lines

I realize that Jan asked for this, but I'm really not sure what good this is supposed to do, since the guest can be un-paused at any point halfway through the transaction.

Wouldn't it make more sense to have this function pause and unpause the domains itself?

Quoted 8 lines

The domains are paused by the user when this op is called, so this is just a sanity check ensuring you are not issuing the op on some other domain. So if this function would pause the domain as well all it would do is increase the pause count. This is the only intended use-case for this function at this time. It would make no sense to try to issue this op on domains that are running, as that pretty much guarantee that some of their memory has already diverged, and thus bulk-sharing their memory would have some unintended side-effects.

Yes, I understand all that. But what I'm saying (and mostly this is actually to Jan that I'm saying it) is that this check, as written, seems pointless to me. We're effectively *not* trusting the toolstack to pause the domain, but we *are* trust the toolstack not to unpause the domain before the operation is completed. It seems to me we should either trust the toolstack to pause the domain and leave it paused -- letting it suffer the consequences if it fails to do so -- or we should pause and unpause the domain ourselves.

Adding an extra pause count is simple and harmless. If we're going to make an effort to think about buggy toolstacks, we might as well just make it 100% safe.

Quoted 4 lines
Quoted 3 lines

To start with, it seems like having a "bulk share" option which could do just a specific range would be useful as well as a "bulk share" which automatically deduped the entire set of memory.

Quoted 7 lines
Quoted 1 line

I have no need for such options.

Yes, but it's not unlikely that somebody else may need them at some point in the future; and it's only a tiny bit of adjustment to make them more generally useful than just your current specific use case, so that we can avoid changing the interface, or adding yet another hypercall in the future.

Well, I don't view it as a guarantee, but simply a sanity check. Iirc I did ask for it simply because similar checks exist elsewhere.

Jan

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