Skip to contentSkip to conversation

domctl: don't truncate XEN_DOMCTL_max_mem requests

PATCH In review Jan Beulich 3 participants 5 messages Apr 22, 2015 – May 4, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 domctl: don't truncate XEN_DOMCTL_max_mem requests

Instead saturate the value if the input can't be represented in the respective struct domain field.

xen/common/domctl.c +2 -2
@@ -944,7 +944,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xe
 
     case XEN_DOMCTL_max_mem:
     {
-        unsigned long new_max = op->u.max_mem.max_memkb >> (PAGE_SHIFT - 10);
+        uint64_t new_max = op->u.max_mem.max_memkb >> (PAGE_SHIFT - 10);
 
         spin_lock(&d->page_alloc_lock);
         /*
@@ -952,7 +952,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xe
          * that the domain will now be allowed to "ratchet" down to new_max. In
          * the meantime, while tot > max, all new allocations are disallowed.
          */
-        d->max_pages = new_max;
+        d->max_pages = min(new_max, (uint64_t)(typeof(d->max_pages))-1);
         spin_unlock(&d->page_alloc_lock);
         break;
     }

domctl: don't truncate XEN_DOMCTL_max_mem requests

Instead saturate the value if the input can't be represented in the respective struct domain field.

xen/common/domctl.c +2 -2
@@ -944,7 +944,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xe
 
     case XEN_DOMCTL_max_mem:
     {
-        unsigned long new_max = op->u.max_mem.max_memkb >> (PAGE_SHIFT - 10);
+        uint64_t new_max = op->u.max_mem.max_memkb >> (PAGE_SHIFT - 10);
 
         spin_lock(&d->page_alloc_lock);
         /*
@@ -952,7 +952,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xe
          * that the domain will now be allowed to "ratchet" down to new_max. In
          * the meantime, while tot > max, all new allocations are disallowed.
          */
-        d->max_pages = new_max;
+        d->max_pages = min(new_max, (uint64_t)(typeof(d->max_pages))-1);
         spin_unlock(&d->page_alloc_lock);
         break;
     }

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

Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Jan Beulich

Instead saturate the value if the input can't be represented in the respective struct domain field.

Do I take it you have a 16TB guest to hand?

Quoted 26 lines
xen/common/domctl.c +2 -2
@@ -944,7 +944,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xe
 
     case XEN_DOMCTL_max_mem:
     {
-        unsigned long new_max = op->u.max_mem.max_memkb >> (PAGE_SHIFT - 10);
+        uint64_t new_max = op->u.max_mem.max_memkb >> (PAGE_SHIFT - 10);
 
         spin_lock(&d->page_alloc_lock);
         /*
@@ -952,7 +952,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xe
          * that the domain will now be allowed to "ratchet" down to new_max. In
          * the meantime, while tot > max, all new allocations are disallowed.
          */
-        d->max_pages = new_max;
+        d->max_pages = min(new_max, (uint64_t)(typeof(d->max_pages))-1);
         spin_unlock(&d->page_alloc_lock);
         break;
     }
Quoted 4 lines

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

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

#3 lore raw

Ping: [PATCH] domctl: don't truncate XEN_DOMCTL_max_mem requests

In reply to Jan Beulich

While I got a review from Andrew, I'm still waiting for an ack (or nak).

Thanks, Jan

Quoted 26 lines
Quoted 1 line
Quoted 1 line · On 22.04.15 at 13:56, <[email protected]> wrote:

Instead saturate the value if the input can't be represented in the respective struct domain field.

xen/common/domctl.c +2 -2
@@ -944,7 +944,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xe
 
     case XEN_DOMCTL_max_mem:
     {
-        unsigned long new_max = op->u.max_mem.max_memkb >> (PAGE_SHIFT - 10);
+        uint64_t new_max = op->u.max_mem.max_memkb >> (PAGE_SHIFT - 10);
 
         spin_lock(&d->page_alloc_lock);
         /*
@@ -952,7 +952,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xe
          * that the domain will now be allowed to "ratchet" down to new_max. In
          * the meantime, while tot > max, all new allocations are disallowed.
          */
-        d->max_pages = new_max;
+        d->max_pages = min(new_max, (uint64_t)(typeof(d->max_pages))-1);
         spin_unlock(&d->page_alloc_lock);
         break;
     }
Acked-by
#4 lore raw

Re: Ping: [PATCH] domctl: don't truncate XEN_DOMCTL_max_mem requests

Quoted 1 line · Jan Beulich

While I got a review from Andrew, I'm still waiting for an ack (or nak).

I expect Coverity will complain on architectures where this isn't necessary, but acked nonetheless.

Tim.