Skip to contentSkip to conversation

x86/AMD: Add support for AMD's OSVW feature in guests

PATCH In review Boris Ostrovsky 3 participants 10 messages Jan 16, 2012 – Jan 19, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/AMD: Add support for AMD's OSVW feature in guests

# HG changeset patch
# User Boris Ostrovsky <[email protected]> # Date 1326748089 -3600
# Node ID f157d40df95aa3b8becb970968d33f4eca6c7e75 # Parent 5b2676ac13218951698c49fa0350f2ac48220f3d x86/AMD: Add support for AMD's OSVW feature in guests.

In some cases guests should not provide workarounds for errata even when the physical processor is affected. For example, because of erratum 400 on family 10h processors a Linux guest will read an MSR (resulting in VMEXIT) before going to idle in order to avoid getting stuck in a non-C0 state. This is not
necessary: HLT and IO instructions are intercepted and therefore there is no reason for erratum 400 workaround in the guest.

This patch allows us to present a guest with certain errata as fixed, regardless of the state of actual hardware.

tools/libxc/xc_cpuid_x86.c +1 -1
diff -r 5b2676ac1321 -r f157d40df95a tools/libxc/xc_cpuid_x86.c
@@ -108,6 +108,7 @@ static void amd_xc_cpuid_policy(
                     bitmaskof(X86_FEATURE_SSE4A) |
                     bitmaskof(X86_FEATURE_MISALIGNSSE) |
                     bitmaskof(X86_FEATURE_3DNOWPREFETCH) |
+		    bitmaskof(X86_FEATURE_OSVW) |
                     bitmaskof(X86_FEATURE_XOP) |
                     bitmaskof(X86_FEATURE_FMA4) |
                     bitmaskof(X86_FEATURE_TBM) |
@@ -524,7 +525,6 @@ static void xc_cpuid_pv_policy(
         clear_bit(X86_FEATURE_RDTSCP, regs[3]);
 
         clear_bit(X86_FEATURE_SVM, regs[2]);
-        clear_bit(X86_FEATURE_OSVW, regs[2]);
         clear_bit(X86_FEATURE_IBS, regs[2]);
         clear_bit(X86_FEATURE_SKINIT, regs[2]);
         clear_bit(X86_FEATURE_WDT, regs[2]);
xen/arch/x86/cpu/amd.c +60 -0

78 lines not on this page · raw message

xen/arch/x86/domain.c +4 -0
diff -r 5b2676ac1321 -r f157d40df95a xen/arch/x86/domain.c
@@ -422,6 +422,10 @@ int vcpu_initialise(struct vcpu *v)
     if ( (rc = vcpu_init_fpu(v)) != 0 )
         return rc;
 
+    /* Vendor-specific initialization */
+    if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
+        amd_vcpu_initialise(v);
+
     if ( is_hvm_domain(d) )
     {
         rc = hvm_vcpu_initialise(v);
xen/arch/x86/hvm/svm/svm.c +35 -0
diff -r 5b2676ac1321 -r f157d40df95a xen/arch/x86/hvm/svm/svm.c
@@ -1044,6 +1044,27 @@ static void svm_init_erratum_383(struct 
     }
 }
 
+static int svm_handle_osvw(struct vcpu *v, uint32_t msr, uint64_t *val, uint read)
+{
+    uint eax, ebx, ecx, edx;
+     
+    /* Guest OSVW support */
+    hvm_cpuid(0x80000001, &eax, &ebx, &ecx, &edx);
+    if (!test_bit((X86_FEATURE_OSVW & 31), &ecx))
+        return -1;
+
+    if (read) {
+        if (msr == MSR_AMD_OSVW_ID_LENGTH)
+            *val = v->arch.amd.osvw.length;
+        else
+            *val = v->arch.amd.osvw.status;
+    } 
+    /* Writes are ignored */
+
+    return 0;
+}
+
+
 static int svm_cpu_up(void)
 {
     uint64_t msr_content;
@@ -1385,6 +1406,13 @@ static int svm_msr_read_intercept(unsign
         vpmu_do_rdmsr(msr, msr_content);
         break;
 
+    case MSR_AMD_OSVW_ID_LENGTH:
+    case MSR_AMD_OSVW_STATUS:
+        ret = svm_handle_osvw(v, msr, msr_content, 1);
+        if (ret < 0)
+            goto gpf;
+        break;
+
     default:
         ret = nsvm_rdmsr(v, msr, msr_content);
         if ( ret < 0 )
@@ -1509,6 +1537,13 @@ static int svm_msr_write_intercept(unsig
          */
         break;
 
+    case MSR_AMD_OSVW_ID_LENGTH:
+    case MSR_AMD_OSVW_STATUS:
+        ret = svm_handle_osvw(v, msr, &msr_content, 0);
+        if (ret < 0)
+            goto gpf;
+        break;
+
     default:
         ret = nsvm_wrmsr(v, msr, msr_content);
         if ( ret < 0 )
xen/arch/x86/traps.c +28 -1
diff -r 5b2676ac1321 -r f157d40df95a xen/arch/x86/traps.c
@@ -71,6 +71,7 @@
 #include <asm/apic.h>
 #include <asm/mc146818rtc.h>
 #include <asm/hpet.h>
+#include <asm/amd.h>
 #include <public/arch-x86/cpuid.h>
 #include <xsm/xsm.h>
 
@@ -889,7 +890,6 @@ static void pv_cpuid(struct cpu_user_reg
         __clear_bit(X86_FEATURE_SVM % 32, &c);
         if ( !cpu_has_apic )
            __clear_bit(X86_FEATURE_EXTAPIC % 32, &c);
-        __clear_bit(X86_FEATURE_OSVW % 32, &c);
         __clear_bit(X86_FEATURE_IBS % 32, &c);
         __clear_bit(X86_FEATURE_SKINIT % 32, &c);
         __clear_bit(X86_FEATURE_WDT % 32, &c);
@@ -2542,6 +2542,15 @@ static int emulate_privileged_op(struct 
             if ( wrmsr_safe(regs->ecx, msr_content) != 0 )
                 goto fail;
             break;
+        case MSR_AMD_OSVW_ID_LENGTH:
+        case MSR_AMD_OSVW_STATUS:
+            if ( boot_cpu_data.x86_vendor == X86_VENDOR_AMD ) {
+                if (!boot_cpu_has(X86_FEATURE_OSVW))
+                    goto fail;
+                else
+                    break; /* Writes are ignored */
+            }
+            /* Fall through to default case */
         default:
             if ( wrmsr_hypervisor_regs(regs->ecx, msr_content) )
                 break;
@@ -2573,6 +2582,7 @@ static int emulate_privileged_op(struct 
         break;
 
     case 0x32: /* RDMSR */
+
         switch ( (u32)regs->ecx )
         {
 #ifdef CONFIG_X86_64
@@ -2632,6 +2642,23 @@ static int emulate_privileged_op(struct 
             regs->eax = (uint32_t)msr_content;
             regs->edx = (uint32_t)(msr_content >> 32);
             break;
+        case MSR_AMD_OSVW_ID_LENGTH:
+        case MSR_AMD_OSVW_STATUS:
+            if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) {
+                if (!boot_cpu_has(X86_FEATURE_OSVW))
+                    goto fail;
+                else {
+                    if ((u32)regs->ecx == MSR_AMD_OSVW_ID_LENGTH)
+                        msr_content = v->arch.amd.osvw.length;
+                    else
+                        msr_content = v->arch.amd.osvw.status;
+
+                    regs->eax = (uint32_t)msr_content;
+                    regs->edx = (uint32_t)(msr_content >> 32);
+                }
+            } else
+                goto rdmsr_normal;
+            break;
         default:
             if ( rdmsr_hypervisor_regs(regs->ecx, &val) )
             {
xen/include/asm-x86/amd.h +10 -0
diff -r 5b2676ac1321 -r f157d40df95a xen/include/asm-x86/amd.h
@@ -140,7 +140,17 @@
                        AMD_MODEL_RANGE(0x11, 0x0, 0x0, 0xff, 0xf),	\
                        AMD_MODEL_RANGE(0x12, 0x0, 0x0, 0xff, 0xf))
 
+struct vcpu_amd {
+
+    /* OSVW MSRs */
+    struct {
+	u64 length;
+	u64 status;
+    } osvw;
+};
+
 struct cpuinfo_x86;
+void amd_vcpu_initialise(struct vcpu *);
 int cpu_has_amd_erratum(const struct cpuinfo_x86 *, int, ...);
 
 #ifdef __x86_64__
xen/include/asm-x86/domain.h +6 -0
diff -r 5b2676ac1321 -r f157d40df95a xen/include/asm-x86/domain.h
@@ -8,6 +8,7 @@
 #include <asm/hvm/domain.h>
 #include <asm/e820.h>
 #include <asm/mce.h>
+#include <asm/amd.h>
 #include <public/vcpu.h>
 
 #define has_32bit_shinfo(d)    ((d)->arch.has_32bit_shinfo)
@@ -495,6 +496,11 @@ struct arch_vcpu
 
     uint32_t gdbsx_vcpu_event;
 
+    /* Vendor-specific data */
+    union {
+        struct vcpu_amd amd;
+    };
+
     /* A secondary copy of the vcpu time info. */
     XEN_GUEST_HANDLE(vcpu_time_info_t) time_info_guest;
#1 lore raw

tools/libxc/xc_cpuid_x86.c static void amd_xc_cpuid_policy( · line 111

Quoted 8 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky
tools/libxc/xc_cpuid_x86.c +1 -0
@@ -108,6 +108,7 @@ static void amd_xc_cpuid_policy(
                     bitmaskof(X86_FEATURE_SSE4A) |
                     bitmaskof(X86_FEATURE_MISALIGNSSE) |
                     bitmaskof(X86_FEATURE_3DNOWPREFETCH) |
+		    bitmaskof(X86_FEATURE_OSVW) |

Indentation.

Also, is this really meaningful to PV guests? And valid for pre-Fam10?

xen/arch/x86/cpu/amd.c line 38

Quoted 13 lines
tools/libxc/xc_cpuid_x86.c +0 -0
                     bitmaskof(X86_FEATURE_XOP) |
                     bitmaskof(X86_FEATURE_FMA4) |
                     bitmaskof(X86_FEATURE_TBM) |
xen/arch/x86/cpu/amd.c +4 -0
@@ -32,6 +32,13 @@
 static char opt_famrev[14];
 string_param("cpuid_mask_cpu", opt_famrev);
 
+/*
+ * Set osvw_len to higher number when updated Revision Guides
+ * are published and we know what the new status bits are
+ */

This is ugly, as it requires permanent attention. The value to start with should really be 64 (beyond which other code adjustments are going to be necessary anyway).

Quoted 7 lines
xen/arch/x86/cpu/amd.c +3 -0
+static uint64_t osvw_length = 4, osvw_status;
+static DEFINE_SPINLOCK(amd_lock);
+
 static inline void wrmsr_amd(unsigned int index, unsigned int lo, 
 		unsigned int hi)
 {

xen/arch/x86/cpu/amd.c static void __devinit set_cpuidmask(cons · line 195

Quoted 7 lines
xen/arch/x86/cpu/amd.c +4 -0
@@ -182,6 +189,35 @@ static void __devinit set_cpuidmask(cons
 	}
 }
 
+static void amd_guest_osvw_init(struct vcpu *vcpu)
+{
+    if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
+	return;

Shouldn't we bail here for pre-Fam10 CPUs too?

Further, as asked above already - is all this really meaningful to PV guests? Otherwise the code would better go somewhere under xen/arch/x86/hvm/svm/ ...

Also, throughout this file indentation needs to be changed to Linux style (tabs instead of spaces), unless you want to contribute a patch to convert the whole file to Xen style (in which case you'd still need to make adjustments here).

xen/arch/x86/cpu/amd.c static void __devinit set_cpuidmask(cons · line 201

Quoted 6 lines
xen/arch/x86/cpu/amd.c +6 -0
+
+    /*
+     * Guests should see errata 400 and 415 as fixed (assuming that
+     * HLT and IO instructions are intercepted).
+     */
+    vcpu->arch.amd.osvw.length = (osvw_length >= 3) ? (osvw_length) : 3;

An expression consisting of just an identifier for sure doesn't need parentheses.

xen/arch/x86/cpu/amd.c static void __devinit set_cpuidmask(cons · line 212

Quoted 11 lines
xen/arch/x86/cpu/amd.c +11 -0
+    vcpu->arch.amd.osvw.status = osvw_status & ~(6ULL);
+
+    /*
+     * By increasing VCPU's osvw.length to 3 we are telling the guest that
+     * all osvw.status bits inside that length, including bit 0 (which is
+     * reserved for erratum 298), are valid. However, if host processor's
+     * osvw_len is 0 then osvw_status[0] carries no information. We need to
+     * be conservative here and therefore we tell the guest that erratum 298
+     * is present (because we really don't know).
+     */
+    if (osvw_length == 0 && boot_cpu_data.x86 == 0x10)

Why do you check the family here? If osvw_length can only ever be zero on Fam10, then the first check is sufficient. If osvw_length can be zero on other than Fam10 (no matter whether we bail early older CPUs), then the check is actually wrong.

Quoted 20 lines
xen/arch/x86/cpu/amd.c +8 -0
+	vcpu->arch.amd.osvw.status |= 1;
+}
+
+void amd_vcpu_initialise(struct vcpu *vcpu)
+{
+    amd_guest_osvw_init(vcpu);
+}
+
 /*
  * Check for the presence of an AMD erratum. Arguments are defined in amd.h 
 

* for each known erratum. Return 1 if erratum is found.

xen/arch/x86/cpu/amd.c +4 -0
@@ -512,6 +548,30 @@ static void __devinit init_amd(struct cp
 	set_cpuidmask(c);
 
 	check_syscfg_dram_mod_en();
+
+    /* 
+     * Get OSVW bits. If bits are not the same on different processors then
+     * choose the worst case (i.e. if erratum is present on one processor and

xen/arch/x86/cpu/amd.c static void __devinit init_amd(struct cp · line 564

Quoted 10 lines
xen/arch/x86/cpu/amd.c +10 -0
+     * not on another assume that the erratum is present everywhere).
+     */
+     if (test_bit(X86_FEATURE_OSVW, &boot_cpu_data.x86_capability)) {
+         uint64_t len, status;
+
+        if (rdmsr_safe(MSR_AMD_OSVW_ID_LENGTH, len) ||
+            rdmsr_safe(MSR_AMD_OSVW_STATUS, status))
+            len = status = 0;
+
+        spin_lock(&amd_lock);

What is the locking here supposed to protect against? The AP call tree is smp_callin() -> identify_cpu() -> init_amd(), which cannot race with anything (as the initiating processor is waiting for cpu_state to change to CPU_STATE_CALLIN).

Quoted 16 lines
xen/arch/x86/cpu/amd.c +10 -0
+        
+        if (len < osvw_length)
+            osvw_length = len;
+
+        osvw_status |= status;
+        osvw_status &= (1ULL << osvw_length) - 1;
+
+        spin_unlock(&amd_lock);
+    } else
+	 osvw_length = osvw_status = 0;
 }
 
 static struct cpu_dev amd_cpu_dev __cpuinitdata = {

xen/arch/x86/domain.c int vcpu_initialise(struct vcpu *v) · line 426

Quoted 5 lines
xen/arch/x86/domain.c +2 -0
@@ -422,6 +422,10 @@ int vcpu_initialise(struct vcpu *v)
     if ( (rc = vcpu_init_fpu(v)) != 0 )
         return rc;
 
+    /* Vendor-specific initialization */
+    if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD)

If you check the vendor here, you don't need to anywhere in the descendant functions.

Quoted 8 lines
xen/arch/x86/domain.c +2 -0
+        amd_vcpu_initialise(v);
+
     if ( is_hvm_domain(d) )
     {
         rc = hvm_vcpu_initialise(v);

xen/arch/x86/hvm/svm/svm.c static void svm_init_erratum_383(struct · line 1053

Quoted 10 lines
xen/arch/x86/hvm/svm/svm.c +7 -0
@@ -1044,6 +1044,27 @@ static void svm_init_erratum_383(struct 
     }
 }
 
+static int svm_handle_osvw(struct vcpu *v, uint32_t msr, uint64_t *val, uint read)
+{
+    uint eax, ebx, ecx, edx;
+     
+    /* Guest OSVW support */
+    hvm_cpuid(0x80000001, &eax, &ebx, &ecx, &edx);
+    if (!test_bit((X86_FEATURE_OSVW & 31), &ecx))

Formatting of changes to this file should be changed to Xen style.

Quoted 20 lines
xen/arch/x86/hvm/svm/svm.c +14 -0
+        return -1;
+
+    if (read) {
+        if (msr == MSR_AMD_OSVW_ID_LENGTH)
+            *val = v->arch.amd.osvw.length;
+        else
+            *val = v->arch.amd.osvw.status;
+    } 
+    /* Writes are ignored */
+
+    return 0;
+}
+
+
 static int svm_cpu_up(void)
 {
     uint64_t msr_content;

xen/arch/x86/traps.c static int emulate_privileged_op(struct · line 2550

Quoted 9 lines
xen/arch/x86/traps.c +6 -0
@@ -2542,6 +2542,15 @@ static int emulate_privileged_op(struct 
             if ( wrmsr_safe(regs->ecx, msr_content) != 0 )
                 goto fail;
             break;
+        case MSR_AMD_OSVW_ID_LENGTH:
+        case MSR_AMD_OSVW_STATUS:
+            if ( boot_cpu_data.x86_vendor == X86_VENDOR_AMD ) {
+                if (!boot_cpu_has(X86_FEATURE_OSVW))
+                    goto fail;
+                else

Bogus "else" after a "goto". And I wonder, provided there is some point in doing all this for PV guests in the first place, whether this shouldn't be kept getting handled by the default case.

xen/arch/x86/traps.c static int emulate_privileged_op(struct · line 2585

Quoted 11 lines
xen/arch/x86/traps.c +4 -0
+                    break; /* Writes are ignored */
+            }
+            /* Fall through to default case */
         default:
             if ( wrmsr_hypervisor_regs(regs->ecx, msr_content) )
                 break;
@@ -2573,6 +2582,7 @@ static int emulate_privileged_op(struct 
         break;
 
     case 0x32: /* RDMSR */
+

Stray addition of a newline.

xen/arch/x86/traps.c static int emulate_privileged_op(struct · line 2650

Quoted 13 lines
xen/arch/x86/traps.c +6 -0
         switch ( (u32)regs->ecx )
         {
 #ifdef CONFIG_X86_64
@@ -2632,6 +2642,23 @@ static int emulate_privileged_op(struct 
             regs->eax = (uint32_t)msr_content;
             regs->edx = (uint32_t)(msr_content >> 32);
             break;
+        case MSR_AMD_OSVW_ID_LENGTH:
+        case MSR_AMD_OSVW_STATUS:
+            if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) {
+                if (!boot_cpu_has(X86_FEATURE_OSVW))
+                    goto fail;
+                else {

Bogus "else" after a "goto".

Jan

Quoted 14 lines
xen/arch/x86/traps.c +11 -0
+                    if ((u32)regs->ecx == MSR_AMD_OSVW_ID_LENGTH)
+                        msr_content = v->arch.amd.osvw.length;
+                    else
+                        msr_content = v->arch.amd.osvw.status;
+
+                    regs->eax = (uint32_t)msr_content;
+                    regs->edx = (uint32_t)(msr_content >> 32);
+                }
+            } else
+                goto rdmsr_normal;
+            break;
         default:
             if ( rdmsr_hypervisor_regs(regs->ecx, &val) )
             {
#2 lore raw

Responses inline.

Quoted 11 lines · Jan Beulich

tools/libxc/xc_cpuid_x86.c static void amd_xc_cpuid_policy( · line 111

Quoted 8 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky
tools/libxc/xc_cpuid_x86.c +1 -0
@@ -108,6 +108,7 @@ static void amd_xc_cpuid_policy(
                      bitmaskof(X86_FEATURE_SSE4A) |
                      bitmaskof(X86_FEATURE_MISALIGNSSE) |
                      bitmaskof(X86_FEATURE_3DNOWPREFETCH) |
+		    bitmaskof(X86_FEATURE_OSVW) |

Indentation.

Quoted 1 line

Also, is this really meaningful to PV guests?

Does amd_xc_cpuid_policy() get called for PV guests? I thought this is HVM path only.

xc_cpuid_pv_policy() is where clear_bit(X86_FEATURE_OSVW, regs[2]) was removed to handle PV.

I believe this (i.e. OSVW changes) is meaningful for PV. Taking erratum 400 as an example -- we don't need a Linux PV guest reading an MSR before going to idle (in amd_e400_idle()).

Quoted 1 line

And valid for pre-Fam10?

No, it indeed shouldn't be set in those cases.

I could set the bit conditionally, based on host family but the trouble is I don't necessarily know what family the guest will be. Or is this known at this point?

Quoted 10 lines
Quoted 10 lines
tools/libxc/xc_cpuid_x86.c +0 -0
                      bitmaskof(X86_FEATURE_XOP) |
                      bitmaskof(X86_FEATURE_FMA4) |
                      bitmaskof(X86_FEATURE_TBM) |
xen/arch/x86/cpu/amd.c +0 -0
@@ -32,6 +32,13 @@
  static char opt_famrev[14];
  string_param("cpuid_mask_cpu", opt_famrev);
 
Quoted 8 lines

xen/arch/x86/cpu/amd.c line 38

Quoted 4 lines
xen/arch/x86/cpu/amd.c +4 -0
+/*
+ * Set osvw_len to higher number when updated Revision Guides
+ * are published and we know what the new status bits are
+ */

This is ugly, as it requires permanent attention. The value to start with should really be 64 (beyond which other code adjustments are going to be necessary anyway).

I went back and forth on this. The reason I settled on 4 is because we obviously don't know what errata the higher bits will cover and because it is (at least theoretically) possible that a guest shouldn't see the same status bits as the host.

But maybe code maintenance is more burden than it's worth?

Quoted 11 lines
Quoted 11 lines
xen/arch/x86/cpu/amd.c +3 -0
+static uint64_t osvw_length = 4, osvw_status;
+static DEFINE_SPINLOCK(amd_lock);
+
  static inline void wrmsr_amd(unsigned int index, unsigned int lo,
  		unsigned int hi)
  {
@@ -182,6 +189,35 @@ static void __devinit set_cpuidmask(cons
  	}
  }
 
Quoted 6 lines

xen/arch/x86/cpu/amd.c static void __devinit set_cpuidmask(cons · line 195

Quoted 4 lines
xen/arch/x86/cpu/amd.c +4 -0
+static void amd_guest_osvw_init(struct vcpu *vcpu)
+{
+    if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
+	return;

Shouldn't we bail here for pre-Fam10 CPUs too?

As you noted below the vendor check should be removed anyway since this is being called from under such a check already.

As for family --- I think I need to solve how X86_FEATURE_OSVW is set and that will take care of whether anything that gets initialized in this routine is ever used.

Quoted 32 lines

Further, as asked above already - is all this really meaningful to PV guests? Otherwise the code would better go somewhere under xen/arch/x86/hvm/svm/ ...

Also, throughout this file indentation needs to be changed to Linux style (tabs instead of spaces), unless you want to contribute a patch to convert the whole file to Xen style (in which case you'd still need to make adjustments here).

xen/arch/x86/cpu/amd.c static void __devinit set_cpuidmask(cons

Quoted 6 lines
xen/arch/x86/cpu/amd.c +6 -0
+
+    /*
+     * Guests should see errata 400 and 415 as fixed (assuming that
+     * HLT and IO instructions are intercepted).
+     */
+    vcpu->arch.amd.osvw.length = (osvw_length>= 3) ? (osvw_length) : 3;

An expression consisting of just an identifier for sure doesn't need parentheses.

xen/arch/x86/cpu/amd.c static void __devinit set_cpuidmask(cons

Quoted 11 lines
xen/arch/x86/cpu/amd.c +11 -0
+    vcpu->arch.amd.osvw.status = osvw_status&  ~(6ULL);
+
+    /*
+     * By increasing VCPU's osvw.length to 3 we are telling the guest that
+     * all osvw.status bits inside that length, including bit 0 (which is
+     * reserved for erratum 298), are valid. However, if host processor's
+     * osvw_len is 0 then osvw_status[0] carries no information. We need to
+     * be conservative here and therefore we tell the guest that erratum 298
+     * is present (because we really don't know).
+     */
+    if (osvw_length == 0&&  boot_cpu_data.x86 == 0x10)
Quoted 4 lines

Why do you check the family here? If osvw_length can only ever be zero on Fam10, then the first check is sufficient. If osvw_length can be zero on other than Fam10 (no matter whether we bail early older CPUs), then the check is actually wrong.

10h is the only family affected by this erratum.

Quoted 108 lines
Quoted 21 lines
xen/arch/x86/cpu/amd.c +8 -0
+	vcpu->arch.amd.osvw.status |= 1;
+}
+
+void amd_vcpu_initialise(struct vcpu *vcpu)
+{
+    amd_guest_osvw_init(vcpu);
+}
+
  /*
   * Check for the presence of an AMD erratum. Arguments are defined in amd.h
 

* for each known erratum. Return 1 if erratum is found.

xen/arch/x86/cpu/amd.c +4 -0
@@ -512,6 +548,30 @@ static void __devinit init_amd(struct cp
  	set_cpuidmask(c);
 
  	check_syscfg_dram_mod_en();
+
+    /*
+     * Get OSVW bits. If bits are not the same on different processors then
+     * choose the worst case (i.e. if erratum is present on one processor and

xen/arch/x86/cpu/amd.c static void __devinit init_amd(struct cp · line 564

Quoted 10 lines
xen/arch/x86/cpu/amd.c +10 -0
+     * not on another assume that the erratum is present everywhere).
+     */
+     if (test_bit(X86_FEATURE_OSVW,&boot_cpu_data.x86_capability)) {
+         uint64_t len, status;
+
+        if (rdmsr_safe(MSR_AMD_OSVW_ID_LENGTH, len) ||
+            rdmsr_safe(MSR_AMD_OSVW_STATUS, status))
+            len = status = 0;
+
+        spin_lock(&amd_lock);

What is the locking here supposed to protect against? The AP call tree is smp_callin() -> identify_cpu() -> init_amd(), which cannot race with anything (as the initiating processor is waiting for cpu_state to change to CPU_STATE_CALLIN).

Quoted 16 lines
xen/arch/x86/cpu/amd.c +10 -0
+
+        if (len<  osvw_length)
+            osvw_length = len;
+
+        osvw_status |= status;
+        osvw_status&= (1ULL<<  osvw_length) - 1;
+
+        spin_unlock(&amd_lock);
+    } else
+	 osvw_length = osvw_status = 0;
  }
 
  static struct cpu_dev amd_cpu_dev __cpuinitdata = {

xen/arch/x86/domain.c int vcpu_initialise(struct vcpu *v) · line 426

Quoted 5 lines
xen/arch/x86/domain.c +2 -0
@@ -422,6 +422,10 @@ int vcpu_initialise(struct vcpu *v)
      if ( (rc = vcpu_init_fpu(v)) != 0 )
          return rc;
 
+    /* Vendor-specific initialization */
+    if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD)

If you check the vendor here, you don't need to anywhere in the descendant functions.

Quoted 8 lines
xen/arch/x86/domain.c +2 -0
+        amd_vcpu_initialise(v);
+
      if ( is_hvm_domain(d) )
      {
          rc = hvm_vcpu_initialise(v);

xen/arch/x86/hvm/svm/svm.c static void svm_init_erratum_383(struct · line 1053

Quoted 10 lines
xen/arch/x86/hvm/svm/svm.c +7 -0
@@ -1044,6 +1044,27 @@ static void svm_init_erratum_383(struct
      }
  }
 
+static int svm_handle_osvw(struct vcpu *v, uint32_t msr, uint64_t *val, uint read)
+{
+    uint eax, ebx, ecx, edx;
+
+    /* Guest OSVW support */
+    hvm_cpuid(0x80000001,&eax,&ebx,&ecx,&edx);
+    if (!test_bit((X86_FEATURE_OSVW&  31),&ecx))

Formatting of changes to this file should be changed to Xen style.

Quoted 25 lines
xen/arch/x86/hvm/svm/svm.c +14 -0
+        return -1;
+
+    if (read) {
+        if (msr == MSR_AMD_OSVW_ID_LENGTH)
+            *val = v->arch.amd.osvw.length;
+        else
+            *val = v->arch.amd.osvw.status;
+    }
+    /* Writes are ignored */
+
+    return 0;
+}
+
+
  static int svm_cpu_up(void)
  {
      uint64_t msr_content;
xen/arch/x86/traps.c +2 -0
@@ -2542,6 +2542,15 @@ static int emulate_privileged_op(struct
              if ( wrmsr_safe(regs->ecx, msr_content) != 0 )
                  goto fail;
              break;
+        case MSR_AMD_OSVW_ID_LENGTH:
+        case MSR_AMD_OSVW_STATUS:
Quoted 8 lines

xen/arch/x86/traps.c static int emulate_privileged_op(struct · line 2550

Quoted 4 lines
xen/arch/x86/traps.c +4 -0
+            if ( boot_cpu_data.x86_vendor == X86_VENDOR_AMD ) {
+                if (!boot_cpu_has(X86_FEATURE_OSVW))
+                    goto fail;
+                else

Bogus "else" after a "goto". And I wonder, provided there is some point in doing all this for PV guests in the first place, whether this shouldn't be kept getting handled by the default case.

If we go into default case we will emit "Domain attempted WRMSR ..." message in the log. I was trying to avoid that since writing to these registers is not really an error, it just gets ignored.

I'll fix the rest.

Thanks for review.
-boris

Quoted 49 lines

xen/arch/x86/traps.c static int emulate_privileged_op(struct · line 2585

Quoted 12 lines
xen/arch/x86/traps.c +4 -0
+                    break; /* Writes are ignored */
+            }
+            /* Fall through to default case */
          default:
              if ( wrmsr_hypervisor_regs(regs->ecx, msr_content) )
                  break;
@@ -2573,6 +2582,7 @@ static int emulate_privileged_op(struct
          break;
 
      case 0x32: /* RDMSR */
+

Stray addition of a newline.

xen/arch/x86/traps.c static int emulate_privileged_op(struct · line 2650

Quoted 13 lines
xen/arch/x86/traps.c +6 -0
          switch ( (u32)regs->ecx )
          {
  #ifdef CONFIG_X86_64
@@ -2632,6 +2642,23 @@ static int emulate_privileged_op(struct
              regs->eax = (uint32_t)msr_content;
              regs->edx = (uint32_t)(msr_content>>  32);
              break;
+        case MSR_AMD_OSVW_ID_LENGTH:
+        case MSR_AMD_OSVW_STATUS:
+            if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) {
+                if (!boot_cpu_has(X86_FEATURE_OSVW))
+                    goto fail;
+                else {

Bogus "else" after a "goto".

Jan

Quoted 14 lines
xen/arch/x86/traps.c +11 -0
+                    if ((u32)regs->ecx == MSR_AMD_OSVW_ID_LENGTH)
+                        msr_content = v->arch.amd.osvw.length;
+                    else
+                        msr_content = v->arch.amd.osvw.status;
+
+                    regs->eax = (uint32_t)msr_content;
+                    regs->edx = (uint32_t)(msr_content>>  32);
+                }
+            } else
+                goto rdmsr_normal;
+            break;
          default:
              if ( rdmsr_hypervisor_regs(regs->ecx,&val) )
              {
#3 lore raw
Quoted 13 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky
Quoted 11 lines · Jan Beulich

tools/libxc/xc_cpuid_x86.c static void amd_xc_cpuid_policy( · line 111

Quoted 8 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky
tools/libxc/xc_cpuid_x86.c +1 -0
@@ -108,6 +108,7 @@ static void amd_xc_cpuid_policy(
                      bitmaskof(X86_FEATURE_SSE4A) |
                      bitmaskof(X86_FEATURE_MISALIGNSSE) |
                      bitmaskof(X86_FEATURE_3DNOWPREFETCH) |
+		    bitmaskof(X86_FEATURE_OSVW) |

Indentation.

Quoted 4 lines
Quoted 1 line

Also, is this really meaningful to PV guests?

Does amd_xc_cpuid_policy() get called for PV guests? I thought this is HVM path only.

In that case I simply misplaced the comment.

Quoted 6 lines

xc_cpuid_pv_policy() is where clear_bit(X86_FEATURE_OSVW, regs[2]) was removed to handle PV.

I believe this (i.e. OSVW changes) is meaningful for PV. Taking erratum 400 as an example -- we don't need a Linux PV guest reading an MSR before going to idle (in amd_e400_idle()).

It is bogus in the first place if a pv guest does so - after all, not doing stuff like this is the nature of being pv.

Quoted 7 lines
Quoted 1 line

And valid for pre-Fam10?

No, it indeed shouldn't be set in those cases.

I could set the bit conditionally, based on host family but the trouble is I don't necessarily know what family the guest will be. Or is this known at this point?

I think basing this on the host family is a good first shot. I would hope others could comment on how to properly deal with a dependency like this...

Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
xen/arch/x86/cpu/amd.c +0 -0
@@ -32,6 +32,13 @@
  static char opt_famrev[14];
  string_param("cpuid_mask_cpu", opt_famrev);
 
Quoted 8 lines

xen/arch/x86/cpu/amd.c line 38

Quoted 4 lines
xen/arch/x86/cpu/amd.c +4 -0
+/*
+ * Set osvw_len to higher number when updated Revision Guides
+ * are published and we know what the new status bits are
+ */

This is ugly, as it requires permanent attention. The value to start with should really be 64 (beyond which other code adjustments are going to be necessary anyway).

Quoted 4 lines

I went back and forth on this. The reason I settled on 4 is because we obviously don't know what errata the higher bits will cover and because it is (at least theoretically) possible that a guest shouldn't see the same status bits as the host.

I think allowing the guest to know of (not) worked around errata is even desirable (aiui in the worst case it'll apply a redundant fix).

Quoted 13 lines
Quoted 8 lines

xen/arch/x86/cpu/amd.c static void __devinit set_cpuidmask(cons

Quoted 8 lines
xen/arch/x86/cpu/amd.c +8 -0
+    vcpu->arch.amd.osvw.status = osvw_status&  ~(6ULL);
+
+    /*
+     * By increasing VCPU's osvw.length to 3 we are telling the guest that
+     * all osvw.status bits inside that length, including bit 0 (which is
+     * reserved for erratum 298), are valid. However, if host processor's
+     * osvw_len is 0 then osvw_status[0] carries no information. We need to
+     * be conservative here and therefore we tell the guest that erratum 

298

Quoted 4 lines
Quoted 3 lines
xen/arch/x86/cpu/amd.c +3 -0
+     * is present (because we really don't know).
+     */
+    if (osvw_length == 0&&  boot_cpu_data.x86 == 0x10)
Quoted 6 lines
Quoted 4 lines

Why do you check the family here? If osvw_length can only ever be zero on Fam10, then the first check is sufficient. If osvw_length can be zero on other than Fam10 (no matter whether we bail early older CPUs), then the check is actually wrong.

10h is the only family affected by this erratum.

What is "this erratum" here? My comment was to suggest that either of the two conditions can likely be eliminated for being redundant.

Quoted 18 lines
Quoted 8 lines
Quoted 8 lines
xen/arch/x86/traps.c +2 -0
@@ -2542,6 +2542,15 @@ static int emulate_privileged_op(struct
              if ( wrmsr_safe(regs->ecx, msr_content) != 0 )
                  goto fail;
              break;
+        case MSR_AMD_OSVW_ID_LENGTH:
+        case MSR_AMD_OSVW_STATUS:
Quoted 8 lines

xen/arch/x86/traps.c static int emulate_privileged_op(struct · line 2550

Quoted 4 lines
xen/arch/x86/traps.c +4 -0
+            if ( boot_cpu_data.x86_vendor == X86_VENDOR_AMD ) {
+                if (!boot_cpu_has(X86_FEATURE_OSVW))
+                    goto fail;
+                else

Bogus "else" after a "goto". And I wonder, provided there is some point in doing all this for PV guests in the first place, whether this shouldn't be kept getting handled by the default case.

Quoted 3 lines

If we go into default case we will emit "Domain attempted WRMSR ..." message in the log. I was trying to avoid that since writing to these registers is not really an error, it just gets ignored.

The documentation says that both MSRs are read/write, so issuing a message here appears to be The Right Thing (tm). Kernels shouldn't be doing this in general, and for PV kernels imo it is definitely a bug.

Jan

#4 lore raw
Quoted 23 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky
Quoted 11 lines · Jan Beulich

tools/libxc/xc_cpuid_x86.c static void amd_xc_cpuid_policy( · line 111

Quoted 8 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky
tools/libxc/xc_cpuid_x86.c +1 -0
@@ -108,6 +108,7 @@ static void amd_xc_cpuid_policy(
                       bitmaskof(X86_FEATURE_SSE4A) |
                       bitmaskof(X86_FEATURE_MISALIGNSSE) |
                       bitmaskof(X86_FEATURE_3DNOWPREFETCH) |
+		    bitmaskof(X86_FEATURE_OSVW) |

Indentation.

Quoted 4 lines
Quoted 1 line

Also, is this really meaningful to PV guests?

Does amd_xc_cpuid_policy() get called for PV guests? I thought this is HVM path only.

In that case I simply misplaced the comment.

Quoted 3 lines

xc_cpuid_pv_policy() is where clear_bit(X86_FEATURE_OSVW, regs[2]) was removed to handle PV.

Quoted 6 lines
Quoted 3 lines

I believe this (i.e. OSVW changes) is meaningful for PV. Taking erratum 400 as an example -- we don't need a Linux PV guest reading an MSR before going to idle (in amd_e400_idle()).

It is bogus in the first place if a pv guest does so - after all, not doing stuff like this is the nature of being pv.

It was actually a bad example --- the guest is not using amd_e400_idle() and so there are no extra MSR accesses.

However, without this change OSVW bit will not show up in the guest's CPUID and I think guests should be able to see it. One could argue whether or not we should mask off status bits for the two errata (400 and 415) since they are not currently used; I'd mask them off just to be consistent with HVM, it won't affect anything.

Quoted 19 lines
Quoted 19 lines
Quoted 9 lines

tools/libxc/xc_cpuid_x86.c static void amd_xc_cpuid_policy(

Quoted 9 lines
tools/libxc/xc_cpuid_x86.c +9 -0
+    vcpu->arch.amd.osvw.length = (osvw_length >= 3) ? (osvw_length) : 3
+    vcpu->arch.amd.osvw.status = osvw_status&   ~(6ULL);
+
+    /*
+     * By increasing VCPU's osvw.length to 3 we are telling the guest that
+     * all osvw.status bits inside that length, including bit 0 (which is
+     * reserved for erratum 298), are valid. However, if host processor's
+     * osvw_len is 0 then osvw_status[0] carries no information. We need to
+     * be conservative here and therefore we tell the guest that erratum

298

Quoted 8 lines

tools/libxc/xc_cpuid_x86.c

Quoted 3 lines
tools/libxc/xc_cpuid_x86.c +3 -0
+     * is present (because we really don't know).
+     */
+    if (osvw_length == 0&&   boot_cpu_data.x86 == 0x10)

Why do you check the family here? If osvw_length can only ever be zero on Fam10, then the first check is sufficient. If osvw_length can be zero on other than Fam10 (no matter whether we bail early older CPUs), then the check is actually wrong.

Quoted 4 lines
Quoted 1 line

10h is the only family affected by this erratum.

What is "this erratum" here? My comment was to suggest that either of the two conditions can likely be eliminated for being redundant.

("This erratum" is erratum 298, which is bit 0)

If osvw_length!=0 then we don't need to do anything since bit 0 is already valid.

If osvw_length==0 then -- since we just made the guest's version of this register 3 and thus turned bit 0 from being invalid to valid -- we need to do something about bit 0. But the bit can only be set on family 10h, thus both checks.

Thanks.
-boris

#5 lore raw
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky
Quoted 7 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky

I believe this (i.e. OSVW changes) is meaningful for PV. Taking erratum 400 as an example -- we don't need a Linux PV guest reading an MSR before going to idle (in amd_e400_idle()).

It is bogus in the first place if a pv guest does so - after all, not doing stuff like this is the nature of being pv.

Quoted 8 lines

It was actually a bad example --- the guest is not using amd_e400_idle() and so there are no extra MSR accesses.

However, without this change OSVW bit will not show up in the guest's CPUID and I think guests should be able to see it. One could argue whether or not we should mask off status bits for the two errata (400 and 415) since they are not currently used; I'd mask them off just to be consistent with HVM, it won't affect anything.

I continue to think otherwise - knowing of and dealing with this is supposed to be entirely hidden from PV guests, unless and until you can provide a counter example. Therefore I am likely to nak this part of future revisions of the patch (which Keir could certainly override), up to and including ripping out the PV part (and adjusting the rest accordingly) if I would go for committing it.

Quoted 14 lines
Quoted 11 lines
Quoted 8 lines
Quoted 6 lines
Quoted 1 line

+ if (osvw_length == 0&& boot_cpu_data.x86 == 0x10)

Why do you check the family here? If osvw_length can only ever be zero on Fam10, then the first check is sufficient. If osvw_length can be zero on other than Fam10 (no matter whether we bail early older CPUs), then the check is actually wrong.

10h is the only family affected by this erratum.

What is "this erratum" here? My comment was to suggest that either of the two conditions can likely be eliminated for being redundant.

("This erratum" is erratum 298, which is bit 0)

Quoted 7 lines

If osvw_length!=0 then we don't need to do anything since bit 0 is already valid.

If osvw_length==0 then -- since we just made the guest's version of this register 3 and thus turned bit 0 from being invalid to valid -- we need to do something about bit 0. But the bit can only be set on family 10h, thus both checks.

Okay, got you. However, the whole thing will become superfluous anyway if you bail on family less than 0x10 right at the start of the function.

Btw., one more comment on the change to init_amd(): You will likely need to distinguish BP and AP cases here - on the BP you want to plainly write the values read from the MSRs to the global variables, but on APs (with possibly different settings) you need to work towards a setting of the global variables that apply to all of the CPUs. This is not just for the (theoretical only?) hotplug case, but particularly the one of a soft-offlined CPU that had its microcode updated already in a way affecting the OSVW bits and is subsequently being brought back online.

Which reminds you and me that the patch is missing integration with the microcode update loader (as that one may alter the OSVW bits iiuc).

Jan

#6 lore raw
Quoted 19 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky
Quoted 7 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky

I believe this (i.e. OSVW changes) is meaningful for PV. Taking erratum 400 as an example -- we don't need a Linux PV guest reading an MSR before going to idle (in amd_e400_idle()).

It is bogus in the first place if a pv guest does so - after all, not doing stuff like this is the nature of being pv.

Quoted 8 lines

It was actually a bad example --- the guest is not using amd_e400_idle() and so there are no extra MSR accesses.

However, without this change OSVW bit will not show up in the guest's CPUID and I think guests should be able to see it. One could argue whether or not we should mask off status bits for the two errata (400 and 415) since they are not currently used; I'd mask them off just to be consistent with HVM, it won't affect anything.

Quoted 6 lines

I continue to think otherwise - knowing of and dealing with this is supposed to be entirely hidden from PV guests, unless and until you can provide a counter example. Therefore I am likely to nak this part of future revisions of the patch (which Keir could certainly override), up to and including ripping out the PV part (and adjusting the rest accordingly) if I would go for committing it.

Well, the general principle of exposing OSVW to PV guests doesn't seem terrible. It's just the current specific motivation for exposing to HVM guests does not apply to PV guests.

Are *any* of the current OSVW defined bits at all useful or applicable to PV guests?

-- Keir

Quoted 47 lines
Quoted 14 lines
Quoted 11 lines
Quoted 8 lines
Quoted 6 lines
Quoted 1 line

+ if (osvw_length == 0&& boot_cpu_data.x86 == 0x10)

Why do you check the family here? If osvw_length can only ever be zero on Fam10, then the first check is sufficient. If osvw_length can be zero on other than Fam10 (no matter whether we bail early older CPUs), then the check is actually wrong.

10h is the only family affected by this erratum.

What is "this erratum" here? My comment was to suggest that either of the two conditions can likely be eliminated for being redundant.

("This erratum" is erratum 298, which is bit 0)

Quoted 7 lines

If osvw_length!=0 then we don't need to do anything since bit 0 is already valid.

If osvw_length==0 then -- since we just made the guest's version of this register 3 and thus turned bit 0 from being invalid to valid -- we need to do something about bit 0. But the bit can only be set on family 10h, thus both checks.

Okay, got you. However, the whole thing will become superfluous anyway if you bail on family less than 0x10 right at the start of the function.

Btw., one more comment on the change to init_amd(): You will likely need to distinguish BP and AP cases here - on the BP you want to plainly write the values read from the MSRs to the global variables, but on APs (with possibly different settings) you need to work towards a setting of the global variables that apply to all of the CPUs. This is not just for the (theoretical only?) hotplug case, but particularly the one of a soft-offlined CPU that had its microcode updated already in a way affecting the OSVW bits and is subsequently being brought back online.

Which reminds you and me that the patch is missing integration with the microcode update loader (as that one may alter the OSVW bits iiuc).

Jan

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

#7 lore raw
Quoted 28 lines · Keir Fraser
Quoted 19 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky
Quoted 7 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky

I believe this (i.e. OSVW changes) is meaningful for PV. Taking erratum 400 as an example -- we don't need a Linux PV guest reading an MSR before going to idle (in amd_e400_idle()).

It is bogus in the first place if a pv guest does so - after all, not doing stuff like this is the nature of being pv.

Quoted 8 lines

It was actually a bad example --- the guest is not using amd_e400_idle() and so there are no extra MSR accesses.

However, without this change OSVW bit will not show up in the guest's CPUID and I think guests should be able to see it. One could argue whether or not we should mask off status bits for the two errata (400 and 415) since they are not currently used; I'd mask them off just to be consistent with HVM, it won't affect anything.

Quoted 6 lines

I continue to think otherwise - knowing of and dealing with this is supposed to be entirely hidden from PV guests, unless and until you can provide a counter example. Therefore I am likely to nak this part of future revisions of the patch (which Keir could certainly override), up to and including ripping out the PV part (and adjusting the rest accordingly) if I would go for committing it.

Quoted 7 lines

Well, the general principle of exposing OSVW to PV guests doesn't seem terrible. It's just the current specific motivation for exposing to HVM guests does not apply to PV guests.

Are *any* of the current OSVW defined bits at all useful or applicable to PV guests?

(Wrong "Reply" button)

Probably not with current bits, at least for Linux PV guests.

-boris

#8 lore raw
In reply to Jan Beulich
Quoted 10 lines · Jan Beulich

Btw., one more comment on the change to init_amd(): You will likely need to distinguish BP and AP cases here - on the BP you want to plainly write the values read from the MSRs to the global variables, but on APs (with possibly different settings) you need to work towards a setting of the global variables that apply to all of the CPUs. This is not just for the (theoretical only?) hotplug case, but particularly the one of a soft-offlined CPU that had its microcode updated already in a way affecting the OSVW bits and is subsequently being brought back online.

Not sure I follow you. There is no difference in how BIOS/microcode sets OSVW bits on AP or BP, that's based on silicon version (i.e. stepping) and not where that silicon is plugged in.

If a core is offlined that will presumably happen after it has already gone through init_amd() and therefore global versions of the registers already accounted for that processor's values. (The downside is that if the offlined processors has more bugs than the rest then everyone is considered as bad even though the bad processor is out of the action. But I think the positives of updating global variables after a cpu is offlined are not worth the complexity.)

Quoted 4 lines

Which reminds you and me that the patch is missing integration with the microcode update loader (as that one may alter the OSVW bits iiuc).

That's a good point --- I should re-initialize the global variables after a patch is loaded.

Thanks.
-boris

#9 lore raw
Quoted 15 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky
Quoted 10 lines · Jan Beulich

Btw., one more comment on the change to init_amd(): You will likely need to distinguish BP and AP cases here - on the BP you want to plainly write the values read from the MSRs to the global variables, but on APs (with possibly different settings) you need to work towards a setting of the global variables that apply to all of the CPUs. This is not just for the (theoretical only?) hotplug case, but particularly the one of a soft-offlined CPU that had its microcode updated already in a way affecting the OSVW bits and is subsequently being brought back online.

Quoted 3 lines

Not sure I follow you. There is no difference in how BIOS/microcode sets OSVW bits on AP or BP, that's based on silicon version (i.e. stepping) and not where that silicon is plugged in.

But mixed stepping systems could have values in an AP that are different from what the BP (and earlier APs) had.

Quoted 7 lines

If a core is offlined that will presumably happen after it has already gone through init_amd() and therefore global versions of the registers already accounted for that processor's values. (The downside is that if the offlined processors has more bugs than the rest then everyone is considered as bad even though the bad processor is out of the action. But I think the positives of updating global variables after a cpu is offlined are not worth the complexity.)

Yes, optimizing for this case is very unlikely to be necessary.

Jan