[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen stable-4.1] x86: make certain memory sub-ops return valid values



commit 44e4100a138b2caf6a0947ad7ddef65c7678dbf3
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Tue Mar 12 16:24:58 2013 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Tue Mar 12 16:24:58 2013 +0100

    x86: make certain memory sub-ops return valid values
    
    When a domain's shared info field "max_pfn" is zero,
    domain_get_maximum_gpfn() so far returned ULONG_MAX, which
    do_memory_op() in turn converted to -1 (i.e. -EPERM). Make the former
    always return a sensible number (i.e. zero if the field was zero) and
    have the latter no longer truncate return values.
    
    Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
    Acked-by: Tim Deegan <tim@xxxxxxx>
    master changeset: 7ffc9779aa5120c5098d938cb88f69a1dda9a0fe
    master date: 2013-03-04 10:16:04 +0100
---
 xen/arch/x86/mm.c          |    2 +-
 xen/common/compat/memory.c |   11 +++++++++--
 xen/common/memory.c        |    5 ++---
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index 30d281d..ca2c8f8 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -401,7 +401,7 @@ unsigned long domain_get_maximum_gpfn(struct domain *d)
     if ( is_hvm_domain(d) )
         return p2m_get_hostp2m(d)->max_mapped_pfn;
     /* NB. PV guests specify nr_pfns rather than max_pfn so we adjust here. */
-    return arch_get_max_pfn(d) - 1;
+    return (arch_get_max_pfn(d) ?: 1) - 1;
 }
 
 void share_xen_page_with_guest(
diff --git a/xen/common/compat/memory.c b/xen/common/compat/memory.c
index 5f494eb..d58fb50 100644
--- a/xen/common/compat/memory.c
+++ b/xen/common/compat/memory.c
@@ -15,7 +15,8 @@ CHECK_TYPE(domid);
 
 int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE(void) compat)
 {
-    int rc, split, op = cmd & MEMOP_CMD_MASK;
+    int split, op = cmd & MEMOP_CMD_MASK;
+    long rc;
     unsigned int start_extent = cmd >> MEMOP_EXTENT_SHIFT;
 
     do
@@ -191,7 +192,7 @@ int compat_memory_op(unsigned int cmd, 
XEN_GUEST_HANDLE(void) compat)
 
         rc = do_memory_op(cmd, nat.hnd);
         if ( rc < 0 )
-            return rc;
+            break;
 
         cmd = 0;
         if ( hypercall_xlat_continuation(&cmd, 0x02, nat.hnd, compat) )
@@ -304,5 +305,11 @@ int compat_memory_op(unsigned int cmd, 
XEN_GUEST_HANDLE(void) compat)
                 __HYPERVISOR_memory_op, "ih", cmd, compat);
     } while ( split > 0 );
 
+    if ( unlikely(rc > INT_MAX) )
+        return INT_MAX;
+
+    if ( unlikely(rc < INT_MIN) )
+        return INT_MIN;
+
     return rc;
 }
diff --git a/xen/common/memory.c b/xen/common/memory.c
index 51c3cc6..129f3d4 100644
--- a/xen/common/memory.c
+++ b/xen/common/memory.c
@@ -505,14 +505,13 @@ static long 
memory_exchange(XEN_GUEST_HANDLE(xen_memory_exchange_t) arg)
 long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE(void) arg)
 {
     struct domain *d;
-    int rc, op;
+    long rc;
     unsigned int address_bits;
     unsigned long start_extent;
     struct xen_memory_reservation reservation;
     struct memop_args args;
     domid_t domid;
-
-    op = cmd & MEMOP_CMD_MASK;
+    int op = cmd & MEMOP_CMD_MASK;
 
     switch ( op )
     {
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.1

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.