Skip to contentSkip to conversation

x86/HVM: clean up HVMOP_set_mem_type processing

PATCH In review Jan Beulich 3 participants 3 messages Apr 30, 2014 – May 1, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/HVM: clean up HVMOP_set_mem_type processing

- drop unused variable "mfn"
- consistently do not use "else" when the prior "if" ends in "goto"
- use printk() referencing the target domain instead of gdprintk() (which references the current domain) and slightly shorten message
- annotate -EINVAL results in paging/shared paths to actually need switching to -EAGAIN (possible only when preemption logic got fixed to use -ERESTART)

xen/arch/x86/hvm/hvm.c +12 -17
@@ -4522,21 +4522,20 @@ long do_hvm_op(unsigned long op, XEN_GUE
         while ( a.nr > start_iter )
         {
             unsigned long pfn = a.first_pfn + start_iter;
-            p2m_type_t t;
-            p2m_type_t nt;
-            mfn_t mfn;
-            mfn = get_gfn_unshare(d, pfn, &t);
+            p2m_type_t t, nt;
+
+            get_gfn_unshare(d, pfn, &t);
             if ( p2m_is_paging(t) )
             {
                 put_gfn(d, pfn);
                 p2m_mem_paging_populate(d, pfn);
-                rc = -EINVAL;
+                rc = -EINVAL; /* XXX EAGAIN */
                 goto param_fail4;
             }
             if ( p2m_is_shared(t) )
             {
                 put_gfn(d, pfn);
-                rc = -EINVAL;
+                rc = -EINVAL; /* XXX EAGAIN */
                 goto param_fail4;
             } 
             if ( !p2m_is_ram(t) &&
@@ -4545,18 +4544,14 @@ long do_hvm_op(unsigned long op, XEN_GUE
                 put_gfn(d, pfn);
                 goto param_fail4;
             }
-            else
+            nt = p2m_change_type(d, pfn, t, memtype[a.hvmmem_type]);
+            if ( nt != t )
             {
-                nt = p2m_change_type(d, pfn, t, memtype[a.hvmmem_type]);
-                if ( nt != t )
-                {
-                    put_gfn(d, pfn);
-                    gdprintk(XENLOG_WARNING,
-                             "type of pfn %#lx changed from %d to %d while "
-                             "we were trying to change it to %d\n",
-                             pfn, t, nt, memtype[a.hvmmem_type]);
-                    goto param_fail4;
-                }
+                put_gfn(d, pfn);
+                printk(XENLOG_G_WARNING
+                       "d%d: GFN %#lx type changed from %d to %d while trying to change it to %d\n",
+                       d->domain_id, pfn, t, nt, memtype[a.hvmmem_type]);
+                goto param_fail4;
             }
             put_gfn(d, pfn);
 

x86/HVM: clean up HVMOP_set_mem_type processing

- drop unused variable "mfn"
- consistently do not use "else" when the prior "if" ends in "goto"
- use printk() referencing the target domain instead of gdprintk() (which references the current domain) and slightly shorten message
- annotate -EINVAL results in paging/shared paths to actually need switching to -EAGAIN (possible only when preemption logic got fixed to use -ERESTART)

xen/arch/x86/hvm/hvm.c +12 -17
@@ -4522,21 +4522,20 @@ long do_hvm_op(unsigned long op, XEN_GUE
         while ( a.nr > start_iter )
         {
             unsigned long pfn = a.first_pfn + start_iter;
-            p2m_type_t t;
-            p2m_type_t nt;
-            mfn_t mfn;
-            mfn = get_gfn_unshare(d, pfn, &t);
+            p2m_type_t t, nt;
+
+            get_gfn_unshare(d, pfn, &t);
             if ( p2m_is_paging(t) )
             {
                 put_gfn(d, pfn);
                 p2m_mem_paging_populate(d, pfn);
-                rc = -EINVAL;
+                rc = -EINVAL; /* XXX EAGAIN */
                 goto param_fail4;
             }
             if ( p2m_is_shared(t) )
             {
                 put_gfn(d, pfn);
-                rc = -EINVAL;
+                rc = -EINVAL; /* XXX EAGAIN */
                 goto param_fail4;
             } 
             if ( !p2m_is_ram(t) &&
@@ -4545,18 +4544,14 @@ long do_hvm_op(unsigned long op, XEN_GUE
                 put_gfn(d, pfn);
                 goto param_fail4;
             }
-            else
+            nt = p2m_change_type(d, pfn, t, memtype[a.hvmmem_type]);
+            if ( nt != t )
             {
-                nt = p2m_change_type(d, pfn, t, memtype[a.hvmmem_type]);
-                if ( nt != t )
-                {
-                    put_gfn(d, pfn);
-                    gdprintk(XENLOG_WARNING,
-                             "type of pfn %#lx changed from %d to %d while "
-                             "we were trying to change it to %d\n",
-                             pfn, t, nt, memtype[a.hvmmem_type]);
-                    goto param_fail4;
-                }
+                put_gfn(d, pfn);
+                printk(XENLOG_G_WARNING
+                       "d%d: GFN %#lx type changed from %d to %d while trying to change it to %d\n",
+                       d->domain_id, pfn, t, nt, memtype[a.hvmmem_type]);
+                goto param_fail4;
             }
             put_gfn(d, pfn);
 

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

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

- drop unused variable "mfn"
- consistently do not use "else" when the prior "if" ends in "goto"
- use printk() referencing the target domain instead of gdprintk() (which references the current domain) and slightly shorten message
- annotate -EINVAL results in paging/shared paths to actually need switching to -EAGAIN (possible only when preemption logic got fixed to use -ERESTART)

xen/arch/x86/hvm/hvm.c +3 -5
@@ -4522,21 +4522,20 @@ long do_hvm_op(unsigned long op, XEN_GUE
         while ( a.nr > start_iter )
         {
             unsigned long pfn = a.first_pfn + start_iter;
-            p2m_type_t t;
-            p2m_type_t nt;
-            mfn_t mfn;
-            mfn = get_gfn_unshare(d, pfn, &t);
+            p2m_type_t t, nt;
+
+            get_gfn_unshare(d, pfn, &t);
             if ( p2m_is_paging(t) )
             {
                 put_gfn(d, pfn);
                 p2m_mem_paging_populate(d, pfn);
-                rc = -EINVAL;

xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUE · line 4540

Quoted 10 lines
xen/arch/x86/hvm/hvm.c +2 -1
+                rc = -EINVAL; /* XXX EAGAIN */
                 goto param_fail4;
             }
             if ( p2m_is_shared(t) )
             {
                 put_gfn(d, pfn);
-                rc = -EINVAL;
+                rc = -EINVAL; /* XXX EAGAIN */
                 goto param_fail4;
             } 

Could you nuke the trailing piece of whitespace on this brace as this is a cleanup patch and it is within-context.

xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUE · line 4548

Quoted 6 lines
xen/arch/x86/hvm/hvm.c +0 -1
             if ( !p2m_is_ram(t) &&
@@ -4545,18 +4544,14 @@ long do_hvm_op(unsigned long op, XEN_GUE
                 put_gfn(d, pfn);
                 goto param_fail4;
             }
-            else

I know this is inconsistently applied, but a line before setting nt would look neater.

Quoted 11 lines
xen/arch/x86/hvm/hvm.c +2 -8
+            nt = p2m_change_type(d, pfn, t, memtype[a.hvmmem_type]);
+            if ( nt != t )
             {
-                nt = p2m_change_type(d, pfn, t, memtype[a.hvmmem_type]);
-                if ( nt != t )
-                {
-                    put_gfn(d, pfn);
-                    gdprintk(XENLOG_WARNING,
-                             "type of pfn %#lx changed from %d to %d while "
-                             "we were trying to change it to %d\n",
-                             pfn, t, nt, memtype[a.hvmmem_type]);

xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUE · line 4557

Quoted 10 lines
xen/arch/x86/hvm/hvm.c +5 -2
-                    goto param_fail4;
-                }
+                put_gfn(d, pfn);
+                printk(XENLOG_G_WARNING
+                       "d%d: GFN %#lx type changed from %d to %d while trying to change it to %d\n",
+                       d->domain_id, pfn, t, nt, memtype[a.hvmmem_type]);
+                goto param_fail4;
             }
             put_gfn(d, pfn);
 

Other than those two nits, content wise

Acked-by on v1 1/1
#2 lore raw
In reply to Jan Beulich
Quoted 9 lines · Jan Beulich

- drop unused variable "mfn"
- consistently do not use "else" when the prior "if" ends in "goto"
- use printk() referencing the target domain instead of gdprintk() (which references the current domain) and slightly shorten message
- annotate -EINVAL results in paging/shared paths to actually need switching to -EAGAIN (possible only when preemption logic got fixed to use -ERESTART)