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

[Xen-changelog] [xen staging] x86/mtrr: split "enabled" field into two boolean flags



commit 8ebc60e0274b770743e59256f665789d4308b188
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Mon Jul 16 15:09:12 2018 +0200
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Mon Jul 16 15:09:12 2018 +0200

    x86/mtrr: split "enabled" field into two boolean flags
    
    The code hopefully is more readable this way.
    
    Also switch have_fixed to bool, seeing that it already is used as a
    boolean.
    
    Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
    [switched to use MASK_*]
    Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
 xen/arch/x86/cpu/mtrr/generic.c | 14 +++++++++-----
 xen/arch/x86/hvm/hvm.c          |  6 ++++--
 xen/arch/x86/hvm/mtrr.c         | 23 ++++++++++++++---------
 xen/include/asm-x86/msr-index.h |  2 ++
 xen/include/asm-x86/mtrr.h      |  5 +++--
 5 files changed, 32 insertions(+), 18 deletions(-)

diff --git a/xen/arch/x86/cpu/mtrr/generic.c b/xen/arch/x86/cpu/mtrr/generic.c
index 7ba0c3f0fe..09763654be 100644
--- a/xen/arch/x86/cpu/mtrr/generic.c
+++ b/xen/arch/x86/cpu/mtrr/generic.c
@@ -80,7 +80,8 @@ void __init get_mtrr_state(void)
 
        rdmsrl(MSR_MTRRdefType, msr_content);
        mtrr_state.def_type = (msr_content & 0xff);
-       mtrr_state.enabled = (msr_content & 0xc00) >> 10;
+       mtrr_state.enabled = MASK_EXTR(msr_content, MTRRdefType_E);
+       mtrr_state.fixed_enabled = MASK_EXTR(msr_content, MTRRdefType_FE);
 
        /* Store mtrr_cap for HVM MTRR virtualisation. */
        rdmsrl(MSR_MTRRcap, mtrr_state.mtrr_cap);
@@ -159,7 +160,7 @@ static void __init print_mtrr_state(const char *level)
                unsigned int base = 0, step = 0x10000;
 
                printk("%sMTRR fixed ranges %sabled:\n", level,
-                      mtrr_state.enabled & 1 ? "en" : "dis");
+                      mtrr_state.fixed_enabled ? "en" : "dis");
                for (; block->ranges; ++block, step >>= 2) {
                        for (i = 0; i < block->ranges; ++i, fr += 8) {
                                print_fixed(base, step, fr, level);
@@ -169,7 +170,7 @@ static void __init print_mtrr_state(const char *level)
                print_fixed_last(level);
        }
        printk("%sMTRR variable ranges %sabled:\n", level,
-              mtrr_state.enabled & 2 ? "en" : "dis");
+              mtrr_state.enabled ? "en" : "dis");
        width = (paddr_bits - PAGE_SHIFT + 3) / 4;
 
        for (i = 0; i < num_var_ranges; ++i) {
@@ -383,8 +384,11 @@ static unsigned long set_mtrr_state(void)
        /*  Set_mtrr_restore restores the old value of MTRRdefType,
           so to set it we fiddle with the saved value  */
        if ((deftype & 0xff) != mtrr_state.def_type
-           || ((deftype & 0xc00) >> 10) != mtrr_state.enabled) {
-               deftype = (deftype & ~0xcff) | mtrr_state.def_type | 
(mtrr_state.enabled << 10);
+           || MASK_EXTR(deftype, MTRRdefType_E) != mtrr_state.enabled
+           || MASK_EXTR(deftype, MTRRdefType_FE) != mtrr_state.fixed_enabled) {
+               deftype = (deftype & ~0xcff) | mtrr_state.def_type |
+                         MASK_INSR(mtrr_state.enabled, MTRRdefType_E) |
+                         MASK_INSR(mtrr_state.fixed_enabled, MTRRdefType_FE);
                change_mask |= MTRR_CHANGE_MASK_DEFTYPE;
        }
 
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index e022f5ab0e..3e2abeb274 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -3453,8 +3453,10 @@ int hvm_msr_read_intercept(unsigned int msr, uint64_t 
*msr_content)
     case MSR_MTRRdefType:
         if ( !d->arch.cpuid->basic.mtrr )
             goto gp_fault;
-        *msr_content = v->arch.hvm_vcpu.mtrr.def_type
-                        | (v->arch.hvm_vcpu.mtrr.enabled << 10);
+        *msr_content = v->arch.hvm_vcpu.mtrr.def_type |
+                       MASK_INSR(v->arch.hvm_vcpu.mtrr.enabled, MTRRdefType_E) 
|
+                       MASK_INSR(v->arch.hvm_vcpu.mtrr.fixed_enabled,
+                                 MTRRdefType_FE);
         break;
     case MSR_MTRRfix64K_00000:
         if ( !d->arch.cpuid->basic.mtrr )
diff --git a/xen/arch/x86/hvm/mtrr.c b/xen/arch/x86/hvm/mtrr.c
index a636012388..d74b363851 100644
--- a/xen/arch/x86/hvm/mtrr.c
+++ b/xen/arch/x86/hvm/mtrr.c
@@ -195,11 +195,11 @@ static int get_mtrr_type(const struct mtrr_state *m,
    uint64_t    mask = -(uint64_t)PAGE_SIZE << order;
    unsigned int seg, num_var_ranges = MASK_EXTR(m->mtrr_cap, MTRRcap_VCNT);
 
-   if ( unlikely(!(m->enabled & 0x2)) )
+   if ( unlikely(!m->enabled) )
        return MTRR_TYPE_UNCACHABLE;
 
    pa &= mask;
-   if ( (pa < 0x100000) && (m->enabled & 1) )
+   if ( (pa < 0x100000) && m->fixed_enabled )
    {
        /* Fixed range MTRR takes effect. */
        uint32_t addr = (uint32_t)pa, index;
@@ -391,7 +391,8 @@ bool_t mtrr_def_type_msr_set(struct domain *d, struct 
mtrr_state *m,
                              uint64_t msr_content)
 {
     uint8_t def_type = msr_content & 0xff;
-    uint8_t enabled = (msr_content >> 10) & 0x3;
+    bool fixed_enabled = MASK_EXTR(msr_content, MTRRdefType_FE);
+    bool enabled = MASK_EXTR(msr_content, MTRRdefType_E);
 
     if ( unlikely(!valid_mtrr_type(def_type)) )
     {
@@ -406,10 +407,12 @@ bool_t mtrr_def_type_msr_set(struct domain *d, struct 
mtrr_state *m,
          return 0;
     }
 
-    if ( m->enabled != enabled || m->def_type != def_type )
+    if ( m->enabled != enabled || m->fixed_enabled != fixed_enabled ||
+         m->def_type != def_type )
     {
         m->enabled = enabled;
         m->def_type = def_type;
+        m->fixed_enabled = fixed_enabled;
         memory_type_changed(d);
     }
 
@@ -478,10 +481,10 @@ bool mtrr_pat_not_equal(const struct vcpu *vd, const 
struct vcpu *vs)
     const struct mtrr_state *md = &vd->arch.hvm_vcpu.mtrr;
     const struct mtrr_state *ms = &vs->arch.hvm_vcpu.mtrr;
 
-    if ( (md->enabled ^ ms->enabled) & 2 )
+    if ( md->enabled != ms->enabled )
         return true;
 
-    if ( md->enabled & 2 )
+    if ( md->enabled )
     {
         unsigned int num_var_ranges = MASK_EXTR(md->mtrr_cap, MTRRcap_VCNT);
 
@@ -490,10 +493,10 @@ bool mtrr_pat_not_equal(const struct vcpu *vd, const 
struct vcpu *vs)
             return true;
 
         /* Test fixed ranges. */
-        if ( (md->enabled ^ ms->enabled) & 1 )
+        if ( md->fixed_enabled != ms->fixed_enabled )
             return true;
 
-        if ( (md->enabled & 1) &&
+        if ( md->fixed_enabled &&
              memcmp(md->fixed_ranges, ms->fixed_ranges,
                     sizeof(md->fixed_ranges)) )
             return true;
@@ -681,7 +684,9 @@ static int hvm_save_mtrr_msr(struct domain *d, 
hvm_domain_context_t *h)
         const struct mtrr_state *mtrr_state = &v->arch.hvm_vcpu.mtrr;
         struct hvm_hw_mtrr hw_mtrr = {
             .msr_mtrr_def_type = mtrr_state->def_type |
-                                 (mtrr_state->enabled << 10),
+                                 MASK_INSR(mtrr_state->fixed_enabled,
+                                           MTRRdefType_FE) |
+                                 MASK_INSR(mtrr_state->enabled, MTRRdefType_E),
             .msr_mtrr_cap      = mtrr_state->mtrr_cap,
         };
         unsigned int i;
diff --git a/xen/include/asm-x86/msr-index.h b/xen/include/asm-x86/msr-index.h
index 95bb66916c..94bccf73a1 100644
--- a/xen/include/asm-x86/msr-index.h
+++ b/xen/include/asm-x86/msr-index.h
@@ -98,6 +98,8 @@
 #define MSR_MTRRfix4K_F0000            0x0000026e
 #define MSR_MTRRfix4K_F8000            0x0000026f
 #define MSR_MTRRdefType                        0x000002ff
+#define MTRRdefType_FE                 (1u << 10)
+#define MTRRdefType_E                  (1u << 11)
 
 #define MSR_IA32_DEBUGCTLMSR           0x000001d9
 #define IA32_DEBUGCTLMSR_LBR           (1<<0) /* Last Branch Record */
diff --git a/xen/include/asm-x86/mtrr.h b/xen/include/asm-x86/mtrr.h
index 5cdc5d4fe3..b1f7af6396 100644
--- a/xen/include/asm-x86/mtrr.h
+++ b/xen/include/asm-x86/mtrr.h
@@ -50,8 +50,9 @@ struct mtrr_var_range {
 struct mtrr_state {
        struct mtrr_var_range *var_ranges;
        mtrr_type fixed_ranges[NUM_FIXED_RANGES];
-       unsigned char enabled;
-       unsigned char have_fixed;
+       bool enabled;
+       bool fixed_enabled;
+       bool have_fixed;
        mtrr_type def_type;
 
        u64       mtrr_cap;
--
generated by git-patchbot for /home/xen/git/xen.git#staging

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

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