Skip to contentSkip to conversation

x86/pv: Make the PV default WRMSR path match the HVM default

PATCH In review Andrew Cooper 2 participants 2 messages Jul 23, 2020 – Jul 24, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/pv: Make the PV default WRMSR path match the HVM default

The current HVM default for writes to unknown MSRs is to inject #GP if the MSR is unreadable, and discard writes otherwise. While this behaviour isn't great, the PV default is even worse, because it swallows writes even to non-readable MSRs. i.e. A PV guest doesn't even get a #GP fault for a write to a totally bogus index.

Update PV to make it consistent with HVM, which will simplify the task of making other improvements to the default MSR behaviour.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>

---
 xen/arch/x86/pv/emul-priv-op.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
xen/arch/x86/pv/emul-priv-op.c +4 -1
index f14552cb4b..efeb2a727e 100644
@@ -1113,7 +1113,10 @@ static int write_msr(unsigned int reg, uint64_t val,
         }
         /* fall through */
     default:
-        if ( (rdmsr_safe(reg, temp) != 0) || (val != temp) )
+        if ( rdmsr_safe(reg, temp) )
+            break;
+
+        if ( val != temp )
     invalid:
             gdprintk(XENLOG_WARNING,
                      "Domain attempted WRMSR %08x from 0x%016"PRIx64" to 0x%016"PRIx64"\n",
Signature · 1 line
2.11.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Andrew Cooper

The current HVM default for writes to unknown MSRs is to inject #GP if the MSR is unreadable, and discard writes otherwise. While this behaviour isn't great, the PV default is even worse, because it swallows writes even to non-readable MSRs. i.e. A PV guest doesn't even get a #GP fault for a write to a totally bogus index.

Update PV to make it consistent with HVM, which will simplify the task of making other improvements to the default MSR behaviour.