]> xenbits.xensource.com Git - people/aperard/xen-arm.git/commitdiff
x86: miscellaneous mm.c cleanup
authorJan Beulich <jbeulich@suse.com>
Thu, 2 May 2013 15:05:05 +0000 (17:05 +0200)
committerJan Beulich <jbeulich@suse.com>
Thu, 2 May 2013 15:05:05 +0000 (17:05 +0200)
This simply streamlines code in a few places, where room for
improvement was noticed during the earlier here and the patches in
the XSA-45 series.

This also drops the bogus use of the domain lock in the CR3 write
emulation (which protected against nothing).

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Tim Deegan <tim@xen.org>
xen/arch/x86/mm.c
xen/arch/x86/traps.c
xen/include/asm-x86/config.h

index dd890793974556c915c781cfa1e04fe5ddf5309b..5123860ffd82da4705ea488ad4fb8a7d3d0ebc8e 100644 (file)
@@ -2077,19 +2077,17 @@ static int alloc_page_type(struct page_info *page, unsigned long type,
 
     /* No need for atomic update of type_info here: noone else updates it. */
     wmb();
-    if ( rc == -EAGAIN )
-    {
-        get_page_light(page);
-        page->u.inuse.type_info |= PGT_partial;
-    }
-    else if ( rc == -EINTR )
+    switch ( rc )
     {
+    case 0:
+        page->u.inuse.type_info |= PGT_validated;
+        break;
+    case -EINTR:
         ASSERT((page->u.inuse.type_info &
                 (PGT_count_mask|PGT_validated|PGT_partial)) == 1);
         page->u.inuse.type_info &= ~PGT_count_mask;
-    }
-    else if ( rc )
-    {
+        break;
+    default:
         ASSERT(rc < 0);
         MEM_LOG("Error while validating mfn %lx (pfn %lx) for type %"
                 PRtype_info ": caf=%08lx taf=%" PRtype_info,
@@ -2101,13 +2099,11 @@ static int alloc_page_type(struct page_info *page, unsigned long type,
         {
             ASSERT((page->u.inuse.type_info &
                     (PGT_count_mask | PGT_validated)) == 1);
+    case -EAGAIN:
             get_page_light(page);
             page->u.inuse.type_info |= PGT_partial;
         }
-    }
-    else
-    {
-        page->u.inuse.type_info |= PGT_validated;
+        break;
     }
 
     return rc;
@@ -2886,7 +2882,7 @@ long do_mmuext_op(
 {
     struct mmuext_op op;
     unsigned long type;
-    unsigned int i = 0, done = 0;
+    unsigned int i, done = 0;
     struct vcpu *curr = current;
     struct domain *d = curr->domain;
     struct domain *pg_owner;
@@ -2919,22 +2915,16 @@ long do_mmuext_op(
         perfc_incr(calls_to_mmuext_op);
 
     if ( unlikely(!guest_handle_okay(uops, count)) )
-    {
-        rc = -EFAULT;
-        goto out;
-    }
+        return -EFAULT;
 
     if ( (pg_owner = get_pg_owner(foreigndom)) == NULL )
-    {
-        rc = -ESRCH;
-        goto out;
-    }
+        return -ESRCH;
 
     rc = xsm_mmuext_op(XSM_TARGET, d, pg_owner);
     if ( rc )
     {
-        rcu_unlock_domain(pg_owner);
-        goto out;
+        put_pg_owner(pg_owner);
+        return rc;
     }
 
     for ( i = 0; i < count; i++ )
@@ -3406,7 +3396,6 @@ long do_mmuext_op(
 
     perfc_add(num_mmuext_ops, i);
 
- out:
     /* Add incremental work we have done to the @done output parameter. */
     if ( unlikely(!guest_handle_is_null(pdone)) )
     {
@@ -3462,22 +3451,17 @@ long do_mmu_update(
         perfc_incr(calls_to_mmu_update);
 
     if ( unlikely(!guest_handle_okay(ureqs, count)) )
-    {
-        rc = -EFAULT;
-        goto out;
-    }
+        return -EFAULT;
 
     if ( (pt_dom = foreigndom >> 16) != 0 )
     {
         /* Pagetables belong to a foreign domain (PFD). */
         if ( (pt_owner = rcu_lock_domain_by_id(pt_dom - 1)) == NULL )
-        {
-            rc = -EINVAL;
-            goto out;
-        }
+            return -EINVAL;
+
         if ( pt_owner == d )
             rcu_unlock_domain(pt_owner);
-        if ( (v = pt_owner->vcpu ? pt_owner->vcpu[0] : NULL) == NULL )
+        else if ( !pt_owner->vcpu || (v = pt_owner->vcpu[0]) == NULL )
         {
             rc = -EINVAL;
             goto out;
index 4de9313c7467dc987eccdabb8c3e32a8927029e0..fbbe31d6fc4c2f6d8571c14e0729f79bcf49ff14 100644 (file)
@@ -2318,7 +2318,7 @@ static int emulate_privileged_op(struct cpu_user_regs *regs)
         case 3: {/* Write CR3 */
             unsigned long gfn;
             struct page_info *page;
-            domain_lock(v->domain);
+
             gfn = !is_pv_32on64_vcpu(v)
                 ? xen_cr3_to_pfn(*reg) : compat_cr3_to_pfn(*reg);
             page = get_page_from_gfn(v->domain, gfn, NULL, P2M_ALLOC);
@@ -2329,7 +2329,7 @@ static int emulate_privileged_op(struct cpu_user_regs *regs)
             }
             else
                 rc = -EINVAL;
-            domain_unlock(v->domain);
+
             switch ( rc )
             {
             case 0:
index cf93bd5d68bbf5553f3b108f16d79a04344cc1d2..bd8f61c21e63bbcd2ba4b6c0c7b090a2f3df8550 100644 (file)
@@ -273,8 +273,6 @@ extern unsigned char boot_edid_info[128];
 
 #endif
 
-#define PGT_base_page_table     PGT_l4_page_table
-
 #define __HYPERVISOR_CS64 0xe008
 #define __HYPERVISOR_CS32 0xe038
 #define __HYPERVISOR_CS   __HYPERVISOR_CS64