Skip to contentSkip to conversation

AMD VPMU fixes

PATCH In review Boris Ostrovsky 2 participants 15 messages Aug 8, 2016 – Aug 9, 2016

lore
Share & tools
lore
#0 lore raw

cover AMD VPMU fixes

A couple of AMD VPMU fixes
* Handle original (pre-family 15h) MSR range reserved for PMU use
* Stop reporting error back to the guest when reserved PMU MSR bits are modified since apparently guests (Linux at least) may assume those bits to be zero. Just make sure those bits are set/cleared prior to being written according to values discovered during initialization.

Boris Ostrovsky (2):
AMD/VPMU: 0xc0010000 - 0xc001007 MSRs are in PMU range AMD/VPMU: Keep reserved MSR bits untouched but allow the rest to be
written

 xen/arch/x86/cpu/vpmu_amd.c | 16 ++++------------
 xen/arch/x86/traps.c        |  2 ++
 2 files changed, 6 insertions(+), 12 deletions(-)
Signature · 7 lines
1.8.3.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw

PATCH 1/2 AMD/VPMU: 0xc0010000 - 0xc001007 MSRs are in PMU range

We need to check for older PMU MSR range when emulating MSR accesses for PV guests.

---
 xen/arch/x86/traps.c | 2 ++
 1 file changed, 2 insertions(+)
xen/arch/x86/traps.c +2 -0
index 767d0b0..79a3516 100644
@@ -2903,6 +2903,7 @@ static int emulate_privileged_op(struct cpu_user_regs *regs)
             {
                 vpmu_msr = 1;
         case MSR_AMD_FAM15H_EVNTSEL0...MSR_AMD_FAM15H_PERFCTR5:
+        case MSR_K7_EVNTSEL0...MSR_K7_PERFCTR3:
                 if ( vpmu_msr || (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) )
                 {
                     if ( (vpmu_mode & XENPMU_MODE_ALL) &&
@@ -3030,6 +3031,7 @@ static int emulate_privileged_op(struct cpu_user_regs *regs)
             {
                 vpmu_msr = 1;
         case MSR_AMD_FAM15H_EVNTSEL0...MSR_AMD_FAM15H_PERFCTR5:
+        case MSR_K7_EVNTSEL0...MSR_K7_PERFCTR3:
                 if ( vpmu_msr || (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) )
                 {
 
Signature · 7 lines
1.8.3.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#2 lore raw

Re: [PATCH 1/2] AMD/VPMU: 0xc0010000 - 0xc001007 MSRs are in PMU range

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 08.08.16 at 15:41, <[email protected]> wrote:
xen/arch/x86/traps.c +1 -0
@@ -2903,6 +2903,7 @@ static int emulate_privileged_op(struct cpu_user_regs *regs)
             {
                 vpmu_msr = 1;
         case MSR_AMD_FAM15H_EVNTSEL0...MSR_AMD_FAM15H_PERFCTR5:
+        case MSR_K7_EVNTSEL0...MSR_K7_PERFCTR3:
                 if ( vpmu_msr || (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) )
                 {
                     if ( (vpmu_mode & XENPMU_MODE_ALL) &&

xen/arch/x86/traps.c static int emulate_privileged_op(struct cpu_user_regs *regs) · line 3037

Quoted 7 lines
xen/arch/x86/traps.c +1 -0
@@ -3030,6 +3031,7 @@ static int emulate_privileged_op(struct cpu_user_regs *regs)
             {
                 vpmu_msr = 1;
         case MSR_AMD_FAM15H_EVNTSEL0...MSR_AMD_FAM15H_PERFCTR5:
+        case MSR_K7_EVNTSEL0...MSR_K7_PERFCTR3:
                 if ( vpmu_msr || (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) )
                 {
 

And all the logic in vpmu_amd.c is already in suitable shape? Namely I'm wondering whether CTRL_RSVD_MASK indeed applies uniformly to both the pre-Fam15 and Fam15+ MSRs.

Jan

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

#3 lore raw

Re: [PATCH 1/2] AMD/VPMU: 0xc0010000 - 0xc001007 MSRs are in PMU range

Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 08.08.16 at 15:41, <[email protected]> wrote:
xen/arch/x86/traps.c +1 -0
@@ -2903,6 +2903,7 @@ static int emulate_privileged_op(struct cpu_user_regs *regs)
             {
                 vpmu_msr = 1;
         case MSR_AMD_FAM15H_EVNTSEL0...MSR_AMD_FAM15H_PERFCTR5:
+        case MSR_K7_EVNTSEL0...MSR_K7_PERFCTR3:
                 if ( vpmu_msr || (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) )
                 {
                     if ( (vpmu_mode & XENPMU_MODE_ALL) &&
@@ -3030,6 +3031,7 @@ static int emulate_privileged_op(struct cpu_user_regs *regs)
             {
                 vpmu_msr = 1;
Quoted 8 lines

xen/arch/x86/traps.c static int emulate_privileged_op(struct cpu_user_regs *regs) · line 3037

Quoted 5 lines
xen/arch/x86/traps.c +1 -0
         case MSR_AMD_FAM15H_EVNTSEL0...MSR_AMD_FAM15H_PERFCTR5:
+        case MSR_K7_EVNTSEL0...MSR_K7_PERFCTR3:
                 if ( vpmu_msr || (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) )
                 {
 

And all the logic in vpmu_amd.c is already in suitable shape? Namely I'm wondering whether CTRL_RSVD_MASK indeed applies uniformly to both the pre-Fam15 and Fam15+ MSRs.

The reserved bits look the same on all supported families --- bits 63:42, 39:36, 21 and 19. Except apparently on family 12h bit 19 is MBZ.

-boris

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

#4 lore raw

Re: [PATCH 1/2] AMD/VPMU: 0xc0010000 - 0xc001007 MSRs are in PMU range

Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 08.08.16 at 16:06, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich

xen/arch/x86/traps.c static int emulate_privileged_op(struct cpu_user_regs

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 08.08.16 at 15:41, <[email protected]> wrote:
xen/arch/x86/traps.c +0 -0
@@ -2903,6 +2903,7 @@ static int emulate_privileged_op(struct cpu_user_regs 

*regs)

Quoted 5 lines

xen/arch/x86/traps.c static int emulate_privileged_op(struct cpu_user_regs *regs)

Quoted 5 lines
xen/arch/x86/traps.c +1 -0
             {
                 vpmu_msr = 1;
         case MSR_AMD_FAM15H_EVNTSEL0...MSR_AMD_FAM15H_PERFCTR5:
+        case MSR_K7_EVNTSEL0...MSR_K7_PERFCTR3:
                 if ( vpmu_msr || (boot_cpu_data.x86_vendor == 

X86_VENDOR_AMD) )

Quoted 3 lines

xen/arch/x86/traps.c static int emulate_privileged_op(struct cpu_user_regs

Quoted 3 lines
xen/arch/x86/traps.c +0 -0
                 {
                     if ( (vpmu_mode & XENPMU_MODE_ALL) &&
@@ -3030,6 +3031,7 @@ static int emulate_privileged_op(struct cpu_user_regs 

*regs)

Quoted 5 lines

xen/arch/x86/traps.c static int emulate_privileged_op(struct cpu_user_regs *regs)

Quoted 5 lines
xen/arch/x86/traps.c +1 -0
             {
                 vpmu_msr = 1;
         case MSR_AMD_FAM15H_EVNTSEL0...MSR_AMD_FAM15H_PERFCTR5:
+        case MSR_K7_EVNTSEL0...MSR_K7_PERFCTR3:
                 if ( vpmu_msr || (boot_cpu_data.x86_vendor == 

X86_VENDOR_AMD) )

Quoted 8 lines
Quoted 5 lines

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

Quoted 2 lines
xen/arch/x86/traps.c +0 -0
                 {
 

And all the logic in vpmu_amd.c is already in suitable shape? Namely I'm wondering whether CTRL_RSVD_MASK indeed applies uniformly to both the pre-Fam15 and Fam15+ MSRs.

The reserved bits look the same on all supported families --- bits 63:42, 39:36, 21 and 19. Except apparently on family 12h bit 19 is MBZ.

Isn't MBZ == reserved for all practical purposes? In any event the patch is fine then afaic.

Jan

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

#5 lore raw

Re: [PATCH 1/2] AMD/VPMU: 0xc0010000 - 0xc001007 MSRs are in PMU range

Quoted 3 lines · Jan Beulich
Quoted 2 lines

The reserved bits look the same on all supported families --- bits 63:42, 39:36, 21 and 19. Except apparently on family 12h bit 19 is MBZ.

Isn't MBZ == reserved for all practical purposes?

My understanding is that when something is MBZ we know we shouldn't write 1 there. Reserved can be either 1 or 0 --- that's what my system may have with bit 19 set. (Although it's also possible that POST or BIOS are sloppy).

-boris

Quoted 5 lines

In any event the
patch is fine then afaic.

Jan

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

#6 lore raw

Re: [PATCH 1/2] AMD/VPMU: 0xc0010000 - 0xc001007 MSRs are in PMU range

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 08.08.16 at 17:05, <[email protected]> wrote:
Quoted 3 lines · Jan Beulich
Quoted 2 lines

The reserved bits look the same on all supported families --- bits 63:42, 39:36, 21 and 19. Except apparently on family 12h bit 19 is MBZ.

Isn't MBZ == reserved for all practical purposes?

My understanding is that when something is MBZ we know we shouldn't write 1 there. Reserved can be either 1 or 0 --- that's what my system may have with bit 19 set. (Although it's also possible that POST or BIOS are sloppy).

All understood, yet for us it still means: Don't touch those bits.

Jan

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

#7 lore raw

PATCH 2/2 AMD/VPMU: Keep reserved MSR bits untouched but allow the rest to be written

In reply to Boris Ostrovsky

While AMD APM suggests that reserved MSR bits are not supposed to be touched, it is not clear how (or whether) HW enforces this for PMU registers. At least on some family 10h processors writes of these bits are apparently ignored: guests (such as Linux) assume that the bits are zero and write the MSRs with that assumption in mind even though the bits are set by the time OS/hypervisor starts runnning.

With that in mind, let's stop reporting an error to the guest if it tries to modify those bits and instead adjust the value to be written safely.

---
 xen/arch/x86/cpu/vpmu_amd.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
xen/arch/x86/cpu/vpmu_amd.c +4 -12
index 55d03b3..6147ec4 100644
@@ -247,15 +247,7 @@ static int amd_vpmu_load(struct vcpu *v, bool_t from_guest)
 
         for ( i = 0; i < num_counters; i++ )
         {
-            if ( (ctrl_regs[i] & CTRL_RSVD_MASK) != ctrl_rsvd[i] )
-            {
-                /*
-                 * Not necessary to re-init context since we should never load
-                 * it until guest provides valid values. But just to be safe.
-                 */
-                amd_vpmu_init_regs(ctxt);
-                return -EINVAL;
-            }
+            ctrl_regs[i] = (ctrl_regs[i] & ~CTRL_RSVD_MASK) | ctrl_rsvd[i];
 
             if ( is_pmu_enabled(ctrl_regs[i]) )
                 is_running = 1;
@@ -363,9 +355,9 @@ static int amd_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content,
 
     ASSERT(!supported);
 
-    if ( (type == MSR_TYPE_CTRL ) &&
-         ((msr_content & CTRL_RSVD_MASK) != ctrl_rsvd[idx]) )
-        return -EINVAL;
+    /* Make sure reserved bits are not touched */
+    if ( type == MSR_TYPE_CTRL )
+        msr_content = (msr_content & ~CTRL_RSVD_MASK) | ctrl_rsvd[idx];
 
     /* For all counters, enable guest only mode for HVM guest */
     if ( has_hvm_container_vcpu(v) && (type == MSR_TYPE_CTRL) &&
Signature · 7 lines
1.8.3.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#8 lore raw

Re: [PATCH 2/2] AMD/VPMU: Keep reserved MSR bits untouched but allow the rest to be written

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 08.08.16 at 15:41, <[email protected]> wrote:

While AMD APM suggests that reserved MSR bits are not supposed to be touched, it is not clear how (or whether) HW enforces this for PMU registers. At least on some family 10h processors writes of these bits are apparently ignored: guests (such as Linux) assume that the bits are zero and write the MSRs with that assumption in mind even though the bits are set by the time OS/hypervisor starts runnning.

So how did these bits become non-zero then?

Independent of that I think the relaxation would better only be done for those older CPUs.

Jan

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

#9 lore raw

Re: [PATCH 2/2] AMD/VPMU: Keep reserved MSR bits untouched but allow the rest to be written

Quoted 8 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 08.08.16 at 15:41, <[email protected]> wrote:

While AMD APM suggests that reserved MSR bits are not supposed to be touched, it is not clear how (or whether) HW enforces this for PMU registers. At least on some family 10h processors writes of these bits are apparently ignored: guests (such as Linux) assume that the bits are zero and write the MSRs with that assumption in mind even though the bits are set by the time OS/hypervisor starts runnning.

So how did these bits become non-zero then?

Apparently one of the systems in our lab always had somewhat strange post-BIOS state of these registers, with some bits (I think 19, can't remember now) set. I never picked this up before since we don't really test VPMU, we just initialize it and failure to initialize is non-fatal.

Quoted 3 lines

Independent of that I think the relaxation would better only be done for those older CPUs.

Why? This can easily happen on any family.

-boris

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

#10 lore raw

Re: [PATCH 2/2] AMD/VPMU: Keep reserved MSR bits untouched but allow the rest to be written

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 08.08.16 at 16:10, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 08.08.16 at 15:41, <[email protected]> wrote:

While AMD APM suggests that reserved MSR bits are not supposed to be touched, it is not clear how (or whether) HW enforces this for PMU registers. At least on some family 10h processors writes of these bits are apparently ignored: guests (such as Linux) assume that the bits are zero and write the MSRs with that assumption in mind even though the bits are set by the time OS/hypervisor starts runnning.

Quoted 6 lines
Quoted 1 line

So how did these bits become non-zero then?

Apparently one of the systems in our lab always had somewhat strange post-BIOS state of these registers, with some bits (I think 19, can't remember now) set. I never picked this up before since we don't really test VPMU, we just initialize it and failure to initialize is non-fatal.

Hm, if we find reserved bits set during boot, maybe we could simply record that and allow those bits to retain their non-zero value during later writes (along with getting cleared to zero)?

Quoted 4 lines
Quoted 2 lines

Independent of that I think the relaxation would better only be done for those older CPUs.

Why? This can easily happen on any family.

Can it? Your description reads more like this is an exception, not the rule. I'd prefer for us to be conservative here. Suravee?

Jan

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

#11 lore raw

Re: [PATCH 2/2] AMD/VPMU: Keep reserved MSR bits untouched but allow the rest to be written

Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 08.08.16 at 16:10, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 08.08.16 at 15:41, <[email protected]> wrote:

While AMD APM suggests that reserved MSR bits are not supposed to be touched, it is not clear how (or whether) HW enforces this for PMU registers. At least on some family 10h processors writes of these bits are apparently ignored: guests (such as Linux) assume that the bits are zero and write the MSRs with that assumption in mind even though the bits are set by the time OS/hypervisor starts runnning.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

So how did these bits become non-zero then?

Apparently one of the systems in our lab always had somewhat strange post-BIOS state of these registers, with some bits (I think 19, can't remember now) set. I never picked this up before since we don't really test VPMU, we just initialize it and failure to initialize is non-fatal.

Hm, if we find reserved bits set during boot, maybe we could simply record that and allow those bits to retain their non-zero value during later writes (along with getting cleared to zero)?

But that's exactly what I am trying to do, no? ctrl_rsvd[] is state of those bits when the hypervisor first reads the registers.

There is one hole here (and it always was there) in that we assume that all processors in the system behave the same in this regard. I.e. we only read ctrl_rsvd on the boot processor.

Quoted 6 lines
Quoted 4 lines
Quoted 3 lines

Independent of that I think the relaxation would better only be done for those older CPUs.

Why? This can easily happen on any family.

Can it? Your description reads more like this is an exception, not the rule. I'd prefer for us to be conservative here. Suravee?

So my theory is that even when bits are declared reserved, BIOS/POST (who presumably know exactly how HW behaves and therefore know that, for example, HW will ignore those bits) for whatever reason may flip those bits and not restore them to zero. So it's really not HW property but firmware not cleaning up. If that's the case, however, we know that it's safe to set the bits since BIOS just did that.
-boris

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

#12 lore raw

Re: [PATCH 2/2] AMD/VPMU: Keep reserved MSR bits untouched but allow the rest to be written

Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 08.08.16 at 17:28, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 08.08.16 at 16:10, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 08.08.16 at 15:41, <[email protected]> wrote:

While AMD APM suggests that reserved MSR bits are not supposed to be touched, it is not clear how (or whether) HW enforces this for PMU registers. At least on some family 10h processors writes of these bits are apparently ignored: guests (such as Linux) assume that the bits are zero and write the MSRs with that assumption in mind even though the bits are set by the time OS/hypervisor starts runnning.

So how did these bits become non-zero then?

Apparently one of the systems in our lab always had somewhat strange post-BIOS state of these registers, with some bits (I think 19, can't remember now) set. I never picked this up before since we don't really test VPMU, we just initialize it and failure to initialize is non-fatal.

Quoted 6 lines
Quoted 3 lines

Hm, if we find reserved bits set during boot, maybe we could simply record that and allow those bits to retain their non-zero value during later writes (along with getting cleared to zero)?

But that's exactly what I am trying to do, no? ctrl_rsvd[] is state of those bits when the hypervisor first reads the registers.

Not really - you always or in the settings you found on boot.

Quoted 3 lines

There is one hole here (and it always was there) in that we assume that all processors in the system behave the same in this regard. I.e. we only read ctrl_rsvd on the boot processor.

If the processors are of exactly the same stepping that shouldn't by itself not be a problem (and mixed steppings are frwoned upon anyway). However ...

Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

Independent of that I think the relaxation would better only be done for those older CPUs.

Why? This can easily happen on any family.

Can it? Your description reads more like this is an exception, not the rule. I'd prefer for us to be conservative here. Suravee?

Quoted 6 lines

So my theory is that even when bits are declared reserved, BIOS/POST (who presumably know exactly how HW behaves and therefore know that, for example, HW will ignore those bits) for whatever reason may flip those bits and not restore them to zero. So it's really not HW property but firmware not cleaning up. If that's the case, however, we know that it's safe to set the bits since BIOS just did that.

... this is not a really correct statement, as it neglects the possibility that certain bit combinations are invalid.

Jan

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

#13 lore raw

Re: [PATCH 2/2] AMD/VPMU: Keep reserved MSR bits untouched but allow the rest to be written

Quoted 16 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 08.08.16 at 17:28, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 08.08.16 at 16:10, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 08.08.16 at 15:41, <[email protected]> wrote:

While AMD APM suggests that reserved MSR bits are not supposed to be touched, it is not clear how (or whether) HW enforces this for PMU registers. At least on some family 10h processors writes of these bits are apparently ignored: guests (such as Linux) assume that the bits are zero and write the MSRs with that assumption in mind even though the bits are set by the time OS/hypervisor starts runnning.

So how did these bits become non-zero then?

Apparently one of the systems in our lab always had somewhat strange post-BIOS state of these registers, with some bits (I think 19, can't remember now) set. I never picked this up before since we don't really test VPMU, we just initialize it and failure to initialize is non-fatal.

Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

Hm, if we find reserved bits set during boot, maybe we could simply record that and allow those bits to retain their non-zero value during later writes (along with getting cleared to zero)?

But that's exactly what I am trying to do, no? ctrl_rsvd[] is state of those bits when the hypervisor first reads the registers.

Not really - you always or in the settings you found on boot.

But this is done after a register has its reserved bits cleared, so only reserved bits that were set on boot are set again:

    msr_content = (msr_content & ~CTRL_RSVD_MASK) | ctrl_rsvd[idx];
Quoted 13 lines
Quoted 4 lines

There is one hole here (and it always was there) in that we assume that all processors in the system behave the same in this regard. I.e. we only read ctrl_rsvd on the boot processor.

If the processors are of exactly the same stepping that shouldn't by itself not be a problem (and mixed steppings are frwoned upon anyway). However ...

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

Independent of that I think the relaxation would better only be done for those older CPUs.

Why? This can easily happen on any family.

Can it? Your description reads more like this is an exception, not the rule. I'd prefer for us to be conservative here. Suravee?

Quoted 8 lines
Quoted 6 lines

So my theory is that even when bits are declared reserved, BIOS/POST (who presumably know exactly how HW behaves and therefore know that, for example, HW will ignore those bits) for whatever reason may flip those bits and not restore them to zero. So it's really not HW property but firmware not cleaning up. If that's the case, however, we know that it's safe to set the bits since BIOS just did that.

... this is not a really correct statement, as it neglects the possibility that certain bit combinations are invalid.

Not sure I understand why: we save into ctrl_rsvd the combination (of reserved bits)
that we know is valid, otherwise we wouldn't have read it.

-boris

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

#14 lore raw

Re: [PATCH 2/2] AMD/VPMU: Keep reserved MSR bits untouched but allow the rest to be written

Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 08.08.16 at 19:00, <[email protected]> wrote:
Quoted 19 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 08.08.16 at 17:28, <[email protected]> wrote:
Quoted 17 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 08.08.16 at 16:10, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 08.08.16 at 15:41, <[email protected]> wrote:

While AMD APM suggests that reserved MSR bits are not supposed to be touched, it is not clear how (or whether) HW enforces this for PMU registers. At least on some family 10h processors writes of these bits are apparently ignored: guests (such as Linux) assume that the bits are zero and write the MSRs with that assumption in mind even though the bits are set by the time OS/hypervisor starts runnning.

Quoted 5 lines
Quoted 1 line

So how did these bits become non-zero then?

Apparently one of the systems in our lab always had somewhat strange post-BIOS state of these registers, with some bits (I think 19, can't remember now) set. I never picked this up before since we don't really test VPMU, we just initialize it and failure to initialize is non-fatal.

Hm, if we find reserved bits set during boot, maybe we could simply record that and allow those bits to retain their non-zero value during later writes (along with getting cleared to zero)?

Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

But that's exactly what I am trying to do, no? ctrl_rsvd[] is state of those bits when the hypervisor first reads the registers.

Not really - you always or in the settings you found on boot.

But this is done after a register has its reserved bits cleared, so only reserved bits that were set on boot are set again:

    msr_content = (msr_content & ~CTRL_RSVD_MASK) | ctrl_rsvd[idx];

But that's different from what I said we'd probably prefer: "allow those bits to retain their non-zero value during later writes (along with getting cleared to zero)".

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

Independent of that I think the relaxation would better only be done for those older CPUs.

Why? This can easily happen on any family.

Can it? Your description reads more like this is an exception, not the rule. I'd prefer for us to be conservative here. Suravee?

So my theory is that even when bits are declared reserved, BIOS/POST (who presumably know exactly how HW behaves and therefore know that, for example, HW will ignore those bits) for whatever reason may flip those bits and not restore them to zero. So it's really not HW property but firmware not cleaning up. If that's the case, however, we know that it's safe to set the bits since BIOS just did that.

Quoted 6 lines
Quoted 2 lines

... this is not a really correct statement, as it neglects the possibility that certain bit combinations are invalid.

Not sure I understand why: we save into ctrl_rsvd the combination (of reserved bits)
that we know is valid, otherwise we wouldn't have read it.

But those set bits in the reserved group could conflict with certain settings of non-reserved bits. Anyway, without input from AMD I don't think we're going to come to a conclusion here, not the least because I'm not convinced PRM and BKDG can really be relied upon wrt the distinction between "reserved" and "mbz".

Jan

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