]> xenbits.xensource.com Git - people/iwj/xen.git/commitdiff
x86/HVM: correct mtrr_pat_not_equal()
authorJan Beulich <jbeulich@suse.com>
Tue, 22 May 2018 14:01:26 +0000 (16:01 +0200)
committerJan Beulich <jbeulich@suse.com>
Tue, 22 May 2018 14:01:26 +0000 (16:01 +0200)
The two vCPU-s differing in MTRR-enabled state means MTRR settings are
not equal. Both vCPU-s having MTRRs disabled means only PAT needs to be
compared. Along those lines for fixed range MTRRs. Differing variable
range counts likewise mean settings are different overall (even if
that's not a very reasonable setup to have).

Constify types and convert bool_t to bool.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Release-acked-by: Juergen Gross <jgross@suse.com>
xen/arch/x86/hvm/mtrr.c
xen/include/asm-x86/mtrr.h

index b721c6330ffc087cf1e6284c683d0b44b1e8b99e..a61cc1e6dcaf9bb4acc4c3aa8c8b4cac1f7dbc55 100644 (file)
@@ -473,35 +473,40 @@ bool_t mtrr_var_range_msr_set(
     return 1;
 }
 
-bool_t mtrr_pat_not_equal(struct vcpu *vd, struct vcpu *vs)
+bool mtrr_pat_not_equal(const struct vcpu *vd, const struct vcpu *vs)
 {
-    struct mtrr_state *md = &vd->arch.hvm_vcpu.mtrr;
-    struct mtrr_state *ms = &vs->arch.hvm_vcpu.mtrr;
-    int32_t res;
-    uint8_t num_var_ranges = (uint8_t)md->mtrr_cap;
-
-    /* Test fixed ranges. */
-    res = memcmp(md->fixed_ranges, ms->fixed_ranges,
-            NUM_FIXED_RANGES*sizeof(mtrr_type));
-    if ( res )
-        return 1;
+    const struct mtrr_state *md = &vd->arch.hvm_vcpu.mtrr;
+    const struct mtrr_state *ms = &vs->arch.hvm_vcpu.mtrr;
 
-    /* Test var ranges. */
-    res = memcmp(md->var_ranges, ms->var_ranges,
-            num_var_ranges*sizeof(struct mtrr_var_range));
-    if ( res )
-        return 1;
+    if ( (md->enabled ^ ms->enabled) & 2 )
+        return true;
 
-    /* Test default type MSR. */
-    if ( (md->def_type != ms->def_type)
-            && (md->enabled != ms->enabled) )
-        return 1;
+    if ( md->enabled & 2 )
+    {
+        unsigned int num_var_ranges = (uint8_t)md->mtrr_cap;
+
+        /* Test default type MSR. */
+        if ( md->def_type != ms->def_type )
+            return true;
+
+        /* Test fixed ranges. */
+        if ( (md->enabled ^ ms->enabled) & 1 )
+            return true;
+
+        if ( (md->enabled & 1) &&
+             memcmp(md->fixed_ranges, ms->fixed_ranges,
+                    sizeof(md->fixed_ranges)) )
+            return true;
+
+        /* Test variable ranges. */
+        if ( num_var_ranges != (uint8_t)ms->mtrr_cap ||
+             memcmp(md->var_ranges, ms->var_ranges,
+                    num_var_ranges * sizeof(*md->var_ranges)) )
+            return true;
+    }
 
     /* Test PAT. */
-    if ( vd->arch.hvm_vcpu.pat_cr != vs->arch.hvm_vcpu.pat_cr )
-        return 1;
-
-    return 0;
+    return vd->arch.hvm_vcpu.pat_cr != vs->arch.hvm_vcpu.pat_cr;
 }
 
 struct hvm_mem_pinned_cacheattr_range {
index 69cf68cf7bcc97d2dc425f3f1be25872e130ffee..5cdc5d4fe3a39e65c47ef1e1c4e508b4228165c2 100644 (file)
@@ -92,6 +92,6 @@ extern void memory_type_changed(struct domain *);
 extern bool_t pat_msr_set(uint64_t *pat, uint64_t msr);
 
 bool_t is_var_mtrr_overlapped(const struct mtrr_state *m);
-bool_t mtrr_pat_not_equal(struct vcpu *vd, struct vcpu *vs);
+bool mtrr_pat_not_equal(const struct vcpu *vd, const struct vcpu *vs);
 
 #endif /* __ASM_X86_MTRR_H__ */