x86/shadow: Tweak some initialisation in sh_page_fault()
authorAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 5 Dec 2016 11:32:59 +0000 (11:32 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 13 Dec 2016 10:02:50 +0000 (10:02 +0000)
sh_page_fault() is a complicated function.  It aids clarity for the reader if
constant data is declared as such.

Declare struct npfec access and fetch_type_t ft as const, which requires
initialising them during declaration.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Tim Deegan <tim@xen.org>
xen/arch/x86/mm/shadow/multi.c

index f494f7bd38b3913f9b22812e130c59db5bb8928f..67c98b96e1cf4dcd98ac0c55dd91ea970f414e09 100644 (file)
@@ -2860,15 +2860,17 @@ static int sh_page_fault(struct vcpu *v,
     struct sh_emulate_ctxt emul_ctxt;
     const struct x86_emulate_ops *emul_ops;
     int r;
-    fetch_type_t ft = 0;
     p2m_type_t p2mt;
     uint32_t rc;
     int version;
-    struct npfec access = {
+    const struct npfec access = {
          .read_access = 1,
+         .write_access = !!(regs->error_code & PFEC_write_access),
          .gla_valid = 1,
          .kind = npfec_kind_with_gla
     };
+    const fetch_type_t ft =
+        access.write_access ? ft_demand_write : ft_demand_read;
 #if SHADOW_OPTIMIZATIONS & SHOPT_FAST_EMULATION
     int fast_emul = 0;
 #endif
@@ -2878,9 +2880,6 @@ static int sh_page_fault(struct vcpu *v,
 
     perfc_incr(shadow_fault);
 
-    if ( regs->error_code & PFEC_write_access )
-        access.write_access = 1;
-
 #if SHADOW_OPTIMIZATIONS & SHOPT_FAST_EMULATION
     /* If faulting frame is successfully emulated in last shadow fault
      * it's highly likely to reach same emulation action for this frame.
@@ -3050,10 +3049,6 @@ static int sh_page_fault(struct vcpu *v,
         goto propagate;
     }
 
-    /* What kind of access are we dealing with? */
-    ft = ((regs->error_code & PFEC_write_access)
-          ? ft_demand_write : ft_demand_read);
-
     /* What mfn is the guest trying to access? */
     gfn = guest_l1e_get_gfn(gw.l1e);
     gmfn = get_gfn(d, gfn, &p2mt);