Skip to contentSkip to conversation

x86/msr: Correct the emulation behaviour of MSR_PRED_CMD

PATCH In review Andrew Cooper 3 participants 5 messages Apr 16, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/msr: Correct the emulation behaviour of MSR_PRED_CMD

The behaviour of reserved bits in MSR_PRED_CMD changed between beta and production microcode, and now raises a #GP fault for set reserved bits. The AMD spec for future hardware also specifies this behaviour.

---
CC: Jan Beulich <[email protected]>
CC: Juergen Gross <[email protected]>

This wants backporting to all trees which gained Spectre workarounds, and therefore wants including in 4.11 at this point.

---
 xen/arch/x86/msr.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
xen/arch/x86/msr.c +4 -5
index 369b475..d034561 100644
@@ -243,11 +243,10 @@ int guest_wrmsr(struct vcpu *v, uint32_t msr, uint64_t val)
         if ( !cp->feat.ibrsb && !cp->extd.ibpb )
             goto gp_fault; /* MSR available? */
 
-        /*
-         * The only defined behaviour is when writing PRED_CMD_IBPB.  In
-         * practice, real hardware accepts any value without faulting.
-         */
-        if ( v == curr && (val & PRED_CMD_IBPB) )
+        if ( val & ~PRED_CMD_IBPB )
+            goto gp_fault; /* Rsvd bit set? */
+
+        if ( v == curr )
             wrmsrl(MSR_PRED_CMD, PRED_CMD_IBPB);
         break;
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 16.04.18 at 12:56, <[email protected]> wrote:

The behaviour of reserved bits in MSR_PRED_CMD changed between beta and production microcode, and now raises a #GP fault for set reserved bits.

Interesting - quite unfortunate a change. Plus - I can't find where this is being said.

Quoted 1 line

The AMD spec for future hardware also specifies this behaviour.

I can find this one (albeit not in the PRM).

Quoted 1 line

With some clarification on the origin of the Intel related information

Jan

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

#2 lore raw
Quoted 5 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 16.04.18 at 12:56, <[email protected]> wrote:

The behaviour of reserved bits in MSR_PRED_CMD changed between beta and production microcode, and now raises a #GP fault for set reserved bits.

Interesting - quite unfortunate a change. Plus - I can't find where this is being said.

Its not, but the new behaviour can be demonstrated easily.  Those with the beta microcode can confirm that the old behaviour was to ignore.

FWIW, ignoring reserved bits was always dubious, and I only implemented it like that to match how hardware behaved.  This new behaviour is far more sane.

Quoted 3 lines
Quoted 2 lines

The AMD spec for future hardware also specifies this behaviour.

I can find this one (albeit not in the PRM).

Its still in whitepaper form.

https://developer.amd.com/wp-content/resources/Architecture_Guidelines_Update_Indirect_Branch_Control.pdf

"Indirect branch prediction barrier (IBPB) exists at MSR 0x49 (PRED_CMD) bit 0. This is a write only MSR that both GP faults when software reads it or if software tries to write any of the bits in 63:1"

~Andrew

Quoted 8 lines
Quoted 2 lines

With some clarification on the origin of the Intel related information

Jan

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

#3 lore raw
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 16.04.18 at 13:19, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 16.04.18 at 12:56, <[email protected]> wrote:

The behaviour of reserved bits in MSR_PRED_CMD changed between beta and production microcode, and now raises a #GP fault for set reserved bits.

Interesting - quite unfortunate a change. Plus - I can't find where this is being said.

Quoted 6 lines

Its not, but the new behaviour can be demonstrated easily. Those with the beta microcode can confirm that the old behaviour was to ignore.

FWIW, ignoring reserved bits was always dubious, and I only implemented it like that to match how hardware behaved. This new behaviour is far more sane.

Fully agree - should have been that way from the beginning.

Jan

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

#4 lore raw
In reply to Andrew Cooper
Quoted 5 lines · Andrew Cooper

The behaviour of reserved bits in MSR_PRED_CMD changed between beta and production microcode, and now raises a #GP fault for set reserved bits. The AMD spec for future hardware also specifies this behaviour.

Juergen

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