x86: switch default MSR behavior
v3 cover x86: switch default MSR behavior
Hello,
The current series attempts to change the current MSR default handling behavior, which is to silently drop writes to writable MSRs, and allow reading any MSR not explicitly handled.
After this series access to MSRs not explicitly handled will trigger a #GP fault. I've tested this series with osstest and it doesn't introduce any regression, at least on the boxes selected for testing:
http://logs.test-lab.xenproject.org/osstest/logs/153391/
Thanks, Roger.
Andrew Cooper (2):
x86/hvm: Disallow access to unknown MSRs
x86/msr: Drop compatibility #GP handling in guest_{rd,wr}msr()
Roger Pau Monne (6):
x86/vmx: handle writes to MISC_ENABLE MSR x86/svm: silently drop writes to SYSCFG and related MSRs x86/msr: explicitly handle AMD DE_CFG
x86/svm: handle BU_CFG and BU_CFG2 with cases x86/pv: allow reading FEATURE_CONTROL MSR x86/pv: disallow access to unknown MSRs
xen/arch/x86/hvm/svm/svm.c | 59 +++++++++++++++++++--------- xen/arch/x86/hvm/vmx/vmx.c | 31 ++++++--------- xen/arch/x86/msr.c | 72 +++++++++++++--------------------- xen/arch/x86/pv/emul-priv-op.c | 18 +++++---- 4 files changed, 89 insertions(+), 91 deletions(-)
Signature · 1 line
2.28.0
PATCH v3 1/8 x86/vmx: handle writes to MISC_ENABLE MSR
Such handling consist in checking that no bits have been changed from the read value, if that's the case silently drop the write, otherwise inject a fault.
At least Windows guests will expect to write to the MISC_ENABLE MSR with the same value that's been read from it.
--- xen/arch/x86/hvm/vmx/vmx.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/vmx/vmx.c +8 -1
@@ -3163,7 +3163,7 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content)switch ( msr ) { -uint64_t rsvd; +uint64_t rsvd, tmp;case MSR_IA32_SYSENTER_CS :__vmwrite (GUEST_SYSENTER_CS , msr_content);
@@ -3301,6 +3301,13 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content)/* None of these MSRs are writeable. */ goto gp_fault; +case MSR_IA32_MISC_ENABLE : +/* Silently drop writes that don't change the reported value. */ +if (vmx_msr_read_intercept (msr, &tmp) !=X86EMUL_OKAY || + tmp != msr_content ) + goto gp_fault; +break ; + case MSR_P6_PERFCTR(0)...MSR_P6_PERFCTR(7): case MSR_P6_EVNTSEL(0)...MSR_P6_EVNTSEL(7): case MSR_CORE_PERF_FIXED_CTR0...MSR_CORE_PERF_FIXED_CTR2:
Signature · 1 line
2.28.0
Re: [PATCH v3 1/8] x86/vmx: handle writes to MISC_ENABLE MSR
Quoted 4 lines · Roger Pau Monne
Such handling consist in checking that no bits have been changed from the read value, if that's the case silently drop the write, otherwise inject a fault.
Quoted 8 lines
At least Windows guests will expect to write to the
MISC_ENABLEMSR with the same value that's been read from it.Signed-off-by Roger Pau Monné <[email protected]>Acked-by Andrew Cooper <[email protected]>--- xen/arch/x86/hvm/vmx/vmx.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
Btw - early next week I think I'll time out waiting for a VMX side ack for this change.
Jan
RE: [PATCH v3 1/8] x86/vmx: handle writes to MISC_ENABLE MSR
In reply to Roger Pau MonneQuoted 9 lines
From: Roger Pau Monne <[email protected]>
Sent: Tuesday, September 1, 2020 6:55 PMSuch handling consist in checking that no bits have been changed from the read value, if that's the case silently drop the write, otherwise inject a fault.
At least Windows guests will expect to write to the
MISC_ENABLEMSR with the same value that's been read from it.
for better readability could you also add this line to the code comment below?
with that:
Quoted 38 lines
Signed-off-by Roger Pau Monné <[email protected]>Acked-by Andrew Cooper <[email protected]>--- xen/arch/x86/hvm/vmx/vmx.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)xen/arch/x86/hvm/vmx/vmx.c +1
-1@@ -3163,7 +3163,7 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content)switch ( msr ) { -uint64_t rsvd; +uint64_t rsvd, tmp;case MSR_IA32_SYSENTER_CS :__vmwrite(GUEST_SYSENTER_CS, msr_content);xen/arch/x86/hvm/vmx/vmx.c +7
-0@@ -3301,6 +3301,13 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content)/* None of these MSRs are writeable. */ goto gp_fault; +case MSR_IA32_MISC_ENABLE : +/* Silently drop writes that don't change the reported value. */ +if (vmx_msr_read_intercept (msr, &tmp) !=X86EMUL_OKAY || + tmp != msr_content ) + goto gp_fault; +break ; + case MSR_P6_PERFCTR(0)...MSR_P6_PERFCTR(7): case MSR_P6_EVNTSEL(0)...MSR_P6_EVNTSEL(7):case MSR_CORE_PERF_FIXED_CTR0...MSR_CORE_PERF_FIXED_CTR2:
--
2.28.0
Re: [PATCH v3 1/8] x86/vmx: handle writes to MISC_ENABLE MSR
Quoted 10 lines · Kevin
Quoted 9 lines
From: Roger Pau Monne <[email protected]>
Sent: Tuesday, September 1, 2020 6:55 PMSuch handling consist in checking that no bits have been changed from the read value, if that's the case silently drop the write, otherwise inject a fault.
At least Windows guests will expect to write to the
MISC_ENABLEMSR with the same value that's been read from it.
Quoted 6 lines
for better readability could you also add this line to the code comment below?
with that:
Reviewed-by Kevin Tian <[email protected]>
I'll fold this in while committing.
Jan
PATCH v3 2/8 x86/svm: silently drop writes to SYSCFG and related MSRs
In reply to Roger Pau MonneThe SYSCFG, TOP_MEM1 and TOP_MEM2 MSRs are currently exposed to guests and writes are silently discarded. Make this explicit in the SVM code now, and just return default constant values when attempting to read any of the MSRs, while continuing to silently drop writes.
---
Changes since v2:
- Return 0 from SYSCFG.
- Merge switch cases.
Changes sincxe v1:
- Return MtrrFixDramEn in MSR_K8_SYSCFG.
--- xen/arch/x86/hvm/svm/svm.c | 6 ++++++ 1 file changed, 6 insertions(+)
xen/arch/x86/hvm/svm/svm.c +6 -0
@@ -1917,6 +1917,9 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content) goto gpf;break ; +case MSR_K8_SYSCFG : +case MSR_K8_TOP_MEM1 : +case MSR_K8_TOP_MEM2 :case MSR_K8_VM_CR : *msr_content =0 ;break ;
@@ -2094,6 +2097,9 @@ static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content) goto gpf;break ; +case MSR_K8_TOP_MEM1 : +case MSR_K8_TOP_MEM2 : +case MSR_K8_SYSCFG :case MSR_K8_VM_CR :/* ignore write. handle all bits as read-only. */ break ;
Signature · 1 line
2.28.0
Re: [PATCH v3 2/8] x86/svm: silently drop writes to SYSCFG and related MSRs
Quoted 6 lines · Roger Pau Monne
The SYSCFG,
TOP_MEM1andTOP_MEM2MSRs are currently exposed to guests and writes are silently discarded. Make this explicit in the SVM code now, and just return default constant values when attempting to read any of the MSRs, while continuing to silently drop writes.Signed-off-by Roger Pau Monné <[email protected]>
xen/arch/x86/hvm/svm/svm.c static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content) · line 1925
Quoted 12 lines
xen/arch/x86/hvm/svm/svm.c +3
-0@@ -1917,6 +1917,9 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content) goto gpf;break ; +case MSR_K8_SYSCFG : +case MSR_K8_TOP_MEM1 : +case MSR_K8_TOP_MEM2 :case MSR_K8_VM_CR : *msr_content =0 ;break ;
Andrew, since you did suggest otherwise before, may I ask for an explicit statement of yours here, be it in ack/nak form or something less formal?
Jan
Re: [PATCH v3 2/8] x86/svm: silently drop writes to SYSCFG and related MSRs
Quoted 15 lines · Jan Beulich
Quoted 6 lines · Roger Pau Monne
The SYSCFG,
TOP_MEM1andTOP_MEM2MSRs are currently exposed to guests and writes are silently discarded. Make this explicit in the SVM code now, and just return default constant values when attempting to read any of the MSRs, while continuing to silently drop writes.Signed-off-by Roger Pau Monné <[email protected]>Reviewed-by Jan Beulich <[email protected]>Quoted 6 lines
xen/arch/x86/hvm/svm/svm.c +0
-0@@ -1917,6 +1917,9 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content) goto gpf;break ;
Quoted 9 lines
xen/arch/x86/hvm/svm/svm.c static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content) · line 1925
Quoted 6 lines
xen/arch/x86/hvm/svm/svm.c +3
-0+case MSR_K8_SYSCFG : +case MSR_K8_TOP_MEM1 : +case MSR_K8_TOP_MEM2 :case MSR_K8_VM_CR : *msr_content =0 ;break ;Andrew, since you did suggest otherwise before, may I ask for an explicit statement of yours here, be it in ack/nak form or something less formal?
I'm not entirely convinced it is a safe thing to do, but lets see what happens.
There is likely to be a bug tail from the flipping the default behaviour at the end of the series, and this is certainly a simpler set of logic than the alternative.
~Andrew
PATCH v3 3/8 x86/msr: explicitly handle AMD DE_CFG
In reply to Roger Pau MonneReport LFENCE_SERIALISE unconditionally for DE_CFG on AMD hardware and silently drop writes.
---
Changes since v2:
- Drop the bot_cpu checks and don't attempt to read the MSR, just return LFENCE_SERIALISE unconditionally.
- Add a comment about OpenBSD panicking if writing to the MSR triggers a #GP.
Changes since v1:
- New in this version.
--- xen/arch/x86/msr.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
xen/arch/x86/msr.c +15 -0
@@ -292,6 +292,12 @@ int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val) *val = msrs->tsc_aux;break ; +case MSR_AMD64_DE_CFG : +if ( !(cp->x86_vendor & (X86_VENDOR_AMD |X86_VENDOR_HYGON )) ) + goto gp_fault; + *val =AMD64_DE_CFG_LFENCE_SERIALISE ; +break ; +case MSR_AMD64_DR0_ADDRESS_MASK : case MSR_AMD64_DR1_ADDRESS_MASK ... MSR_AMD64_DR3_ADDRESS_MASK:if ( !cp->extd.dbext )
@@ -517,6 +523,15 @@ int guest_wrmsr(struct vcpu *v, uint32_t msr, uint64_t val)wrmsr_tsc_aux (val);break ; +case MSR_AMD64_DE_CFG : +/* +* OpenBSD 6.7 will panic if writing to DE_CFG triggers a #GP: +* https://www.illumos.org/issues/12998 +*/ +if ( !(cp->x86_vendor & (X86_VENDOR_AMD |X86_VENDOR_HYGON )) ) + goto gp_fault; +break ; +case MSR_AMD64_DR0_ADDRESS_MASK : case MSR_AMD64_DR1_ADDRESS_MASK ... MSR_AMD64_DR3_ADDRESS_MASK:if ( !cp->extd.dbext || val != (uint32_t )val )
Signature · 1 line
2.28.0
Re: [PATCH v3 3/8] x86/msr: explicitly handle AMD DE_CFG
xen/arch/x86/msr.c int guest_wrmsr(struct vcpu *v, uint32_t msr, uint64_t val) · line 529
Quoted 8 lines · Roger Pau Monne
xen/arch/x86/msr.c +4
-0@@ -517,6 +523,15 @@ int guest_wrmsr(struct vcpu *v, uint32_t msr, uint64_t val)wrmsr_tsc_aux (val);break ; +case MSR_AMD64_DE_CFG : +/* +* OpenBSD 6.7 will panic if writing to DE_CFG triggers a #GP: +* https://www.illumos.org/issues/12998
"Drop writes", or some suitable equivalent, so it is clear what action Xen is trying to take in response to the bug.
Otherwise, Reviewed-by: Andrew Cooper <[email protected]>
Quoted 8 lines
xen/arch/x86/msr.c +5
-0+*/ +if ( !(cp->x86_vendor & (X86_VENDOR_AMD |X86_VENDOR_HYGON )) ) + goto gp_fault; +break ; +case MSR_AMD64_DR0_ADDRESS_MASK : case MSR_AMD64_DR1_ADDRESS_MASK ... MSR_AMD64_DR3_ADDRESS_MASK:if ( !cp->extd.dbext || val != (uint32_t )val )
PATCH v3 4/8 x86/svm: handle BU_CFG and BU_CFG2 with cases
In reply to Roger Pau MonneMove the special handling of reads to it's own switch case, and also add support for BU_CFG2. On the write side ignore writes if the MSR is readable, otherwise return a #GP.
This is in preparation for changing the default MSR read/write behavior, which will instead return #GP on not explicitly handled cases.
---
Changes since v2:
- Move the handling of reads to it's own case.
- Drop writes if the MSR is readable, else return a #GP.
Changes since v1:
- New in this version.
--- xen/arch/x86/hvm/svm/svm.c | 43 ++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 13 deletions(-)
xen/arch/x86/hvm/svm/svm.c +30 -13
@@ -1864,6 +1864,30 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content) *msr_content =1ULL <<61 ;/* MC4_MISC.Locked */ break ; +case MSR_F10_BU_CFG : +if ( !rdmsr_safe (msr, *msr_content) ) +break ; + +if ( boot_cpu_data.x86 ==0xf ) + { +/* +* Win2k8 x64 reads this MSR on revF chips, where it wasn't +* publically available; it uses a magic constant in %rdi as a +* password, which we don't have in rdmsr_safe(). Since we'll +* ignore the later writes, just use a plausible value here (the +* reset value from rev10h chips) if the real CPU didn't provide +* one. +*/ + *msr_content =0x0000000010200020ull ; +break ; + } + goto gpf; + +case MSR_F10_BU_CFG2 : +if (rdmsr_safe (msr, *msr_content) ) + goto gpf; +break ; +case MSR_IA32_EBC_FREQUENCY_ID :/* * This Intel-only register may be accessed if this HVM guest
@@ -1942,19 +1966,6 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content)default :if (rdmsr_safe (msr, *msr_content) ==0 )break ; - -if ( boot_cpu_data.x86 ==0xf && msr ==MSR_F10_BU_CFG ) - { -/* Win2k8 x64 reads this MSR on revF chips, where it -* wasn't publically available; it uses a magic constant -* in %rdi as a password, which we don't have in -* rdmsr_safe(). Since we'll ignore the later writes, -* just use a plausible value here (the reset value from -* rev10h chips) if the real CPU didn't provide one. */ - *msr_content =0x0000000010200020ull ; -break ; - } - goto gpf; }
@@ -2110,6 +2121,12 @@ static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content) nsvm->ns_msr_hsavepa = msr_content;break ; +case MSR_F10_BU_CFG : +case MSR_F10_BU_CFG2 : +if (rdmsr_safe (msr, msr_content) ) + goto gpf; +break ; +case MSR_AMD64_TSC_RATIO :if ( msr_content &TSC_RATIO_RSVD_BITS ) goto gpf;
Signature · 1 line
2.28.0
Re: [PATCH v3 4/8] x86/svm: handle BU_CFG and BU_CFG2 with cases
Quoted 21 lines · Roger Pau Monne
xen/arch/x86/hvm/svm/svm.c +0
-13@@ -1942,19 +1966,6 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content)default :if (rdmsr_safe (msr, *msr_content) ==0 )break ; - -if ( boot_cpu_data.x86 ==0xf && msr ==MSR_F10_BU_CFG ) - { -/* Win2k8 x64 reads this MSR on revF chips, where it -* wasn't publically available; it uses a magic constant -* in %rdi as a password, which we don't have in -* rdmsr_safe(). Since we'll ignore the later writes, -* just use a plausible value here (the reset value from -* rev10h chips) if the real CPU didn't provide one. */ - *msr_content =0x0000000010200020ull ; -break ; - } - goto gpf; }
xen/arch/x86/hvm/svm/svm.c static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content) · line 2127
Quoted 7 lines
xen/arch/x86/hvm/svm/svm.c +4
-0@@ -2110,6 +2121,12 @@ static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content) nsvm->ns_msr_hsavepa = msr_content;break ; +case MSR_F10_BU_CFG : +case MSR_F10_BU_CFG2 : +if (rdmsr_safe (msr, msr_content) ) + goto gpf;
The comment you've moved depends on this not having this behaviour, as you'll now hand #GP back to Win2k8 on its write.
Honestly, given that how obsolete both Win2k8 and K10's are, I'm seriously tempted to suggest dropping this workaround entirely.
~Andrew
Quoted 5 lines
xen/arch/x86/hvm/svm/svm.c +2
-0+break ; +case MSR_AMD64_TSC_RATIO :if ( msr_content &TSC_RATIO_RSVD_BITS ) goto gpf;
Re: [PATCH v3 4/8] x86/svm: handle BU_CFG and BU_CFG2 with cases
Quoted 25 lines · Andrew Cooper
Quoted 24 lines · Roger Pau Monne
xen/arch/x86/hvm/svm/svm.c +0
-13@@ -1942,19 +1966,6 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content)default :if (rdmsr_safe (msr, *msr_content) ==0 )break ; - -if ( boot_cpu_data.x86 ==0xf && msr ==MSR_F10_BU_CFG ) - { -/* Win2k8 x64 reads this MSR on revF chips, where it -* wasn't publically available; it uses a magic constant -* in %rdi as a password, which we don't have in -* rdmsr_safe(). Since we'll ignore the later writes, -* just use a plausible value here (the reset value from -* rev10h chips) if the real CPU didn't provide one. */ - *msr_content =0x0000000010200020ull ; -break ; - } - goto gpf; }@@ -2110,6 +2121,12 @@ static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content) nsvm->ns_msr_hsavepa = msr_content;break ;
Quoted 7 lines
xen/arch/x86/hvm/svm/svm.c static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content) · line 2127
Quoted 4 lines
xen/arch/x86/hvm/svm/svm.c +4
-0+case MSR_F10_BU_CFG : +case MSR_F10_BU_CFG2 : +if (rdmsr_safe (msr, msr_content) ) + goto gpf;The comment you've moved depends on this not having this behaviour, as you'll now hand #GP back to Win2k8 on its write.
Oh, unless I'm very confused the comment was already wrong, since svm_msr_write_intercept previous to this patch would return a #GP when trying to write to BU_CFG if the underlying MSR is not readable, so this just keeps the previous behavior.
Looking at the original commit (338db98dd8d) it seems the intention was to only handle reads and let writes return a #GP?
Maybe Win2k8 would only read the MSR?
Quoted 2 lines
Honestly, given that how obsolete both Win2k8 and K10's are, I'm seriously tempted to suggest dropping this workaround entirely.
I'm fine to just drop the workaround, but it seems quite trivial to just keep it as is (reads returns a know value, writes #GP). I can adjust the comment to be clearer.
Thanks, Roger.
Re: [PATCH v3 4/8] x86/svm: handle BU_CFG and BU_CFG2 with cases
Quoted 34 lines · Roger Pau Monné
Quoted 25 lines · Andrew Cooper
Quoted 24 lines · Roger Pau Monne
xen/arch/x86/hvm/svm/svm.c +0
-13@@ -1942,19 +1966,6 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content)default :if (rdmsr_safe (msr, *msr_content) ==0 )break ; - -if ( boot_cpu_data.x86 ==0xf && msr ==MSR_F10_BU_CFG ) - { -/* Win2k8 x64 reads this MSR on revF chips, where it -* wasn't publically available; it uses a magic constant -* in %rdi as a password, which we don't have in -* rdmsr_safe(). Since we'll ignore the later writes, -* just use a plausible value here (the reset value from -* rev10h chips) if the real CPU didn't provide one. */ - *msr_content =0x0000000010200020ull ; -break ; - } - goto gpf; }@@ -2110,6 +2121,12 @@ static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content) nsvm->ns_msr_hsavepa = msr_content;break ;Quoted 7 lines
xen/arch/x86/hvm/svm/svm.c static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content) · line 2127
Quoted 4 lines
xen/arch/x86/hvm/svm/svm.c +4
-0+case MSR_F10_BU_CFG : +case MSR_F10_BU_CFG2 : +if (rdmsr_safe (msr, msr_content) ) + goto gpf;The comment you've moved depends on this not having this behaviour, as you'll now hand #GP back to Win2k8 on its write.
Quoted 7 lines
Oh, unless I'm very confused the comment was already wrong, since
svm_msr_write_interceptprevious to this patch would return a #GP when trying to write toBU_CFGif the underlying MSR is not readable, so this just keeps the previous behavior.Looking at the original commit (
338db98dd8d) it seems the intention was to only handle reads and let writes return a #GP?
I agree. And hence while moving it I think you want to also adjust that comment.
Jan
Re: [PATCH v3 4/8] x86/svm: handle BU_CFG and BU_CFG2 with cases
In reply to Andrew CooperQuoted 33 lines · Andrew Cooper
Quoted 21 lines · Roger Pau Monne
xen/arch/x86/hvm/svm/svm.c +0
-13@@ -1942,19 +1966,6 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content)default :if (rdmsr_safe (msr, *msr_content) ==0 )break ; - -if ( boot_cpu_data.x86 ==0xf && msr ==MSR_F10_BU_CFG ) - { -/* Win2k8 x64 reads this MSR on revF chips, where it -* wasn't publically available; it uses a magic constant -* in %rdi as a password, which we don't have in -* rdmsr_safe(). Since we'll ignore the later writes, -* just use a plausible value here (the reset value from -* rev10h chips) if the real CPU didn't provide one. */ - *msr_content =0x0000000010200020ull ; -break ; - } - goto gpf; }xen/arch/x86/hvm/svm/svm.c static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content) · line 2127
Quoted 7 lines
xen/arch/x86/hvm/svm/svm.c +4
-0@@ -2110,6 +2121,12 @@ static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content) nsvm->ns_msr_hsavepa = msr_content;break ; +case MSR_F10_BU_CFG : +case MSR_F10_BU_CFG2 : +if (rdmsr_safe (msr, msr_content) ) + goto gpf;The comment you've moved depends on this not having this behaviour, as you'll now hand #GP back to Win2k8 on its write.
Quoted 2 lines
Honestly, given that how obsolete both Win2k8 and K10's are, I'm seriously tempted to suggest dropping this workaround entirely.
Let's not (yet). I'm told we (as a company) still support such guests.
Jan
PATCH v3 5/8 x86/pv: allow reading FEATURE_CONTROL MSR
In reply to Roger Pau MonneLinux PV guests will attempt to read the FEATURE_CONTROL MSR, so move the handling done in VMX code into guest_rdmsr as it can be shared between PV and HVM guests that way.
---
Changes from v1:
- Move the VMX implementation into guest_rdmsr.
--- xen/arch/x86/hvm/vmx/vmx.c | 8 +------- xen/arch/x86/msr.c | 13 +++++++++++++ 2 files changed, 14 insertions(+), 7 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +1 -7
@@ -2980,13 +2980,7 @@ static int vmx_msr_read_intercept(unsigned int msr, uint64_t *msr_content)case MSR_IA32_DEBUGCTLMSR :__vmread (GUEST_IA32_DEBUGCTL , msr_content);break ; -case MSR_IA32_FEATURE_CONTROL : - *msr_content =IA32_FEATURE_CONTROL_LOCK ; -if (vmce_has_lmce (curr) ) - *msr_content |=IA32_FEATURE_CONTROL_LMCE_ON ; -if (nestedhvm_enabled (curr->domain) ) - *msr_content |=IA32_FEATURE_CONTROL_ENABLE_VMXON_OUTSIDE_SMX ; -break ; + case MSR_IA32_VMX_BASIC...MSR_IA32_VMX_VMFUNC:if ( !nvmx_msr_read_intercept (msr, msr_content) ) goto gp_fault;
xen/arch/x86/msr.c +13 -0
@@ -25,6 +25,7 @@#include <xen/sched.h> #include <asm/debugreg.h> +#include <asm/hvm/nestedhvm.h> #include <asm/hvm/viridian.h> #include <asm/msr.h> #include <asm/setup.h>
@@ -197,6 +198,18 @@ int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val)/* Not offered to guests. */ goto gp_fault; +case MSR_IA32_FEATURE_CONTROL : +if ( !(cp->x86_vendor &X86_VENDOR_INTEL ) ) + goto gp_fault; + + *val =IA32_FEATURE_CONTROL_LOCK ; +if (vmce_has_lmce (v) ) + *val |=IA32_FEATURE_CONTROL_LMCE_ON ; +if (nestedhvm_enabled (d) ) + *val |=IA32_FEATURE_CONTROL_ENABLE_VMXON_OUTSIDE_SMX ; +break ; + +case MSR_IA32_PLATFORM_ID :if ( !(cp->x86_vendor &X86_VENDOR_INTEL ) || !(boot_cpu_data.x86_vendor &X86_VENDOR_INTEL ) )
Signature · 1 line
2.28.0
Re: [PATCH v3 5/8] x86/pv: allow reading FEATURE_CONTROL MSR
Quoted 45 lines · Roger Pau Monne
Linux PV guests will attempt to read the
FEATURE_CONTROLMSR, so move the handling done in VMX code intoguest_rdmsras it can be shared between PV and HVM guests that way.Signed-off-by Roger Pau Monné <[email protected]>---
Changes from v1:
- Move the VMX implementation intoguest_rdmsr.--- xen/arch/x86/hvm/vmx/vmx.c | 8 +------- xen/arch/x86/msr.c | 13 +++++++++++++ 2 files changed, 14 insertions(+), 7 deletions(-)xen/arch/x86/hvm/vmx/vmx.c +1
-7@@ -2980,13 +2980,7 @@ static int vmx_msr_read_intercept(unsigned int msr, uint64_t *msr_content)case MSR_IA32_DEBUGCTLMSR :__vmread (GUEST_IA32_DEBUGCTL , msr_content);break ; -case MSR_IA32_FEATURE_CONTROL : - *msr_content =IA32_FEATURE_CONTROL_LOCK ; -if (vmce_has_lmce (curr) ) - *msr_content |=IA32_FEATURE_CONTROL_LMCE_ON ; -if (nestedhvm_enabled (curr->domain) ) - *msr_content |=IA32_FEATURE_CONTROL_ENABLE_VMXON_OUTSIDE_SMX ; -break ; + case MSR_IA32_VMX_BASIC...MSR_IA32_VMX_VMFUNC:if ( !nvmx_msr_read_intercept (msr, msr_content) ) goto gp_fault;xen/arch/x86/msr.c +1
-0@@ -25,6 +25,7 @@#include <xen/sched.h> #include <asm/debugreg.h> +#include <asm/hvm/nestedhvm.h> #include <asm/hvm/viridian.h> #include <asm/msr.h> #include <asm/setup.h>
xen/arch/x86/msr.c int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val) · line 203
Quoted 6 lines
xen/arch/x86/msr.c +3
-0@@ -197,6 +198,18 @@ int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val)/* Not offered to guests. */ goto gp_fault; +case MSR_IA32_FEATURE_CONTROL : +if ( !(cp->x86_vendor &X86_VENDOR_INTEL ) ) + goto gp_fault;
The MSR is available if:
"If any one enumeration
condition for defined bit
field position greater than
bit 0 holds."
which for us means cp->basic.vmx || cp->feat.lmce at the moment, with perhaps some smx/sgx in the future.
In particular, this MSR is available on Centaur and Shanghai, which implement VT-x.
~Andrew
Quoted 12 lines
xen/arch/x86/msr.c +9
-0+ + *val =IA32_FEATURE_CONTROL_LOCK ; +if (vmce_has_lmce (v) ) + *val |=IA32_FEATURE_CONTROL_LMCE_ON ; +if (nestedhvm_enabled (d) ) + *val |=IA32_FEATURE_CONTROL_ENABLE_VMXON_OUTSIDE_SMX ; +break ; + +case MSR_IA32_PLATFORM_ID :if ( !(cp->x86_vendor &X86_VENDOR_INTEL ) || !(boot_cpu_data.x86_vendor &X86_VENDOR_INTEL ) )
Re: [PATCH v3 5/8] x86/pv: allow reading FEATURE_CONTROL MSR
Quoted 55 lines · Andrew Cooper
Quoted 45 lines · Roger Pau Monne
Linux PV guests will attempt to read the
FEATURE_CONTROLMSR, so move the handling done in VMX code intoguest_rdmsras it can be shared between PV and HVM guests that way.Signed-off-by Roger Pau Monné <[email protected]>---
Changes from v1:
- Move the VMX implementation intoguest_rdmsr.--- xen/arch/x86/hvm/vmx/vmx.c | 8 +------- xen/arch/x86/msr.c | 13 +++++++++++++ 2 files changed, 14 insertions(+), 7 deletions(-)xen/arch/x86/hvm/vmx/vmx.c +1
-7@@ -2980,13 +2980,7 @@ static int vmx_msr_read_intercept(unsigned int msr, uint64_t *msr_content)case MSR_IA32_DEBUGCTLMSR :__vmread (GUEST_IA32_DEBUGCTL , msr_content);break ; -case MSR_IA32_FEATURE_CONTROL : - *msr_content =IA32_FEATURE_CONTROL_LOCK ; -if (vmce_has_lmce (curr) ) - *msr_content |=IA32_FEATURE_CONTROL_LMCE_ON ; -if (nestedhvm_enabled (curr->domain) ) - *msr_content |=IA32_FEATURE_CONTROL_ENABLE_VMXON_OUTSIDE_SMX ; -break ; + case MSR_IA32_VMX_BASIC...MSR_IA32_VMX_VMFUNC:if ( !nvmx_msr_read_intercept (msr, msr_content) ) goto gp_fault;xen/arch/x86/msr.c +1
-0@@ -25,6 +25,7 @@#include <xen/sched.h> #include <asm/debugreg.h> +#include <asm/hvm/nestedhvm.h> #include <asm/hvm/viridian.h> #include <asm/msr.h> #include <asm/setup.h> xen/arch/x86/msr.c int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val) · line 203
Quoted 6 lines
xen/arch/x86/msr.c +3
-0@@ -197,6 +198,18 @@ int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val)/* Not offered to guests. */ goto gp_fault; +case MSR_IA32_FEATURE_CONTROL : +if ( !(cp->x86_vendor &X86_VENDOR_INTEL ) ) + goto gp_fault;The MSR is available if:
Quoted 7 lines
"If any one enumeration
condition for defined bit
field position greater than
bit 0 holds."which for us means
cp->basic.vmx||cp->feat.lmceat the moment, with perhaps some smx/sgx in the future.
I don't think there's a lmce cpu bit (seems to be signaled in IA32_MCG_CAP[27] = 1), maybe I should just use vmce_has_lmce?
if ( !cp->basic.vmx || !vmce_has_lmce(v) )
goto gp_fault;
Is it fine however to return a #GP if we don't provide any of those features to guests, but the underlying CPU does support them?
That seems to be slightly different from how we currently handle reads to FEATURE_CONTROL, since it will never fault on Intel (or compliant), even if we just return with bit 0 set alone. The new approach seems closer to what real hardware would do.
Thanks, Roger.
Re: [PATCH v3 5/8] x86/pv: allow reading FEATURE_CONTROL MSR
Quoted 60 lines · Roger Pau Monné
Quoted 59 lines · Andrew Cooper
Quoted 45 lines · Roger Pau Monne
Linux PV guests will attempt to read the
FEATURE_CONTROLMSR, so move the handling done in VMX code intoguest_rdmsras it can be shared between PV and HVM guests that way.Signed-off-by Roger Pau Monné <[email protected]>---
Changes from v1:
- Move the VMX implementation intoguest_rdmsr.--- xen/arch/x86/hvm/vmx/vmx.c | 8 +------- xen/arch/x86/msr.c | 13 +++++++++++++ 2 files changed, 14 insertions(+), 7 deletions(-)xen/arch/x86/hvm/vmx/vmx.c +1
-7@@ -2980,13 +2980,7 @@ static int vmx_msr_read_intercept(unsigned int msr, uint64_t *msr_content)case MSR_IA32_DEBUGCTLMSR :__vmread (GUEST_IA32_DEBUGCTL , msr_content);break ; -case MSR_IA32_FEATURE_CONTROL : - *msr_content =IA32_FEATURE_CONTROL_LOCK ; -if (vmce_has_lmce (curr) ) - *msr_content |=IA32_FEATURE_CONTROL_LMCE_ON ; -if (nestedhvm_enabled (curr->domain) ) - *msr_content |=IA32_FEATURE_CONTROL_ENABLE_VMXON_OUTSIDE_SMX ; -break ; + case MSR_IA32_VMX_BASIC...MSR_IA32_VMX_VMFUNC:if ( !nvmx_msr_read_intercept (msr, msr_content) ) goto gp_fault;xen/arch/x86/msr.c +1
-0@@ -25,6 +25,7 @@#include <xen/sched.h> #include <asm/debugreg.h> +#include <asm/hvm/nestedhvm.h> #include <asm/hvm/viridian.h> #include <asm/msr.h> #include <asm/setup.h> xen/arch/x86/msr.c int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val) · line 203
Quoted 6 lines
xen/arch/x86/msr.c +3
-0@@ -197,6 +198,18 @@ int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val)/* Not offered to guests. */ goto gp_fault; +case MSR_IA32_FEATURE_CONTROL : +if ( !(cp->x86_vendor &X86_VENDOR_INTEL ) ) + goto gp_fault;The MSR is available if:
"If any one enumeration
condition for defined bit
field position greater than
bit 0 holds."
Quoted 7 lines
Quoted 2 lines
which for us means
cp->basic.vmx||cp->feat.lmceat the moment, with perhaps some smx/sgx in the future.I don't think there's a lmce cpu bit (seems to be signaled in IA32_MCG_CAP[27] = 1), maybe I should just use
vmce_has_lmce?if ( !cp->basic.vmx || !vmce_has_lmce(v) )
goto gp_fault;
Ah yes, sorry.
Eventually that will be mp->mcg_cap.lmce, but use the predicate for now.
Quoted 2 lines
Is it fine however to return a #GP if we don't provide any of those features to guests, but the underlying CPU does support them?
Yes. That is literally how the availability of the MSR specified by Intel.
Any code which doesn't follow those rules will find #GP even on some recent CPUs.
Quoted 4 lines
That seems to be slightly different from how we currently handle reads to
FEATURE_CONTROL, since it will never fault on Intel (or compliant), even if we just return with bit 0 set alone. The new approach seems closer to what real hardware would do.
Don't fall into the trap of assuming that the current MSR behaviour is perfect, and something we wish to preserve. :)
~Andrew
Re: [PATCH v3 5/8] x86/pv: allow reading FEATURE_CONTROL MSR
Quoted 81 lines · Andrew Cooper
Quoted 60 lines · Roger Pau Monné
Quoted 59 lines · Andrew Cooper
Quoted 45 lines · Roger Pau Monne
Linux PV guests will attempt to read the
FEATURE_CONTROLMSR, so move the handling done in VMX code intoguest_rdmsras it can be shared between PV and HVM guests that way.Signed-off-by Roger Pau Monné <[email protected]>---
Changes from v1:
- Move the VMX implementation intoguest_rdmsr.--- xen/arch/x86/hvm/vmx/vmx.c | 8 +------- xen/arch/x86/msr.c | 13 +++++++++++++ 2 files changed, 14 insertions(+), 7 deletions(-)xen/arch/x86/hvm/vmx/vmx.c +1
-7@@ -2980,13 +2980,7 @@ static int vmx_msr_read_intercept(unsigned int msr, uint64_t *msr_content)case MSR_IA32_DEBUGCTLMSR :__vmread (GUEST_IA32_DEBUGCTL , msr_content);break ; -case MSR_IA32_FEATURE_CONTROL : - *msr_content =IA32_FEATURE_CONTROL_LOCK ; -if (vmce_has_lmce (curr) ) - *msr_content |=IA32_FEATURE_CONTROL_LMCE_ON ; -if (nestedhvm_enabled (curr->domain) ) - *msr_content |=IA32_FEATURE_CONTROL_ENABLE_VMXON_OUTSIDE_SMX ; -break ; + case MSR_IA32_VMX_BASIC...MSR_IA32_VMX_VMFUNC:if ( !nvmx_msr_read_intercept (msr, msr_content) ) goto gp_fault;xen/arch/x86/msr.c +1
-0@@ -25,6 +25,7 @@#include <xen/sched.h> #include <asm/debugreg.h> +#include <asm/hvm/nestedhvm.h> #include <asm/hvm/viridian.h> #include <asm/msr.h> #include <asm/setup.h> xen/arch/x86/msr.c int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val) · line 203
Quoted 6 lines
xen/arch/x86/msr.c +3
-0@@ -197,6 +198,18 @@ int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val)/* Not offered to guests. */ goto gp_fault; +case MSR_IA32_FEATURE_CONTROL : +if ( !(cp->x86_vendor &X86_VENDOR_INTEL ) ) + goto gp_fault;The MSR is available if:
"If any one enumeration
condition for defined bit
field position greater than
bit 0 holds."Quoted 7 lines
Quoted 2 lines
which for us means
cp->basic.vmx||cp->feat.lmceat the moment, with perhaps some smx/sgx in the future.I don't think there's a lmce cpu bit (seems to be signaled in IA32_MCG_CAP[27] = 1), maybe I should just use
vmce_has_lmce?if ( !cp->basic.vmx || !vmce_has_lmce(v) )
goto gp_fault;Ah yes, sorry.
Eventually that will be
mp->mcg_cap.lmce, but use the predicate for now.Quoted 2 lines
Is it fine however to return a #GP if we don't provide any of those features to guests, but the underlying CPU does support them?
Yes. That is literally how the availability of the MSR specified by Intel.
Any code which doesn't follow those rules will find #GP even on some recent CPUs.
Quoted 7 lines
Quoted 4 lines
That seems to be slightly different from how we currently handle reads to
FEATURE_CONTROL, since it will never fault on Intel (or compliant), even if we just return with bit 0 set alone. The new approach seems closer to what real hardware would do.Don't fall into the trap of assuming that the current MSR behaviour is perfect, and something we wish to preserve. :)
Sure, I've pointed out the changes on the commit message, since the behavior will be different now.
Thanks, Roger.
PATCH v3 6/8 x86/pv: disallow access to unknown MSRs
In reply to Roger Pau MonneChange the catch-all behavior for MSR not explicitly handled. Instead of allow full read-access to the MSR space and silently dropping writes return an exception when the MSR is not explicitly handled.
---
Changes since v2:
- Added missing 0x prefix.
--- xen/arch/x86/pv/emul-priv-op.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
xen/arch/x86/pv/emul-priv-op.c +10 -8
@@ -972,9 +972,10 @@ static int read_msr(unsigned int reg, uint64_t *val, }/* fall through */ default : +gdprintk (XENLOG_WARNING ,"RDMSR 0x%08x unimplemented\n" , reg); +break ; + normal: -/* Everyone can read the MSR space. */ -/* gdprintk(XENLOG_WARNING, "Domain attempted RDMSR %08x\n", reg); */ if (rdmsr_safe (reg, *val) )break ;return X86EMUL_OKAY ;
@@ -1141,14 +1142,15 @@ static int write_msr(unsigned int reg, uint64_t val, }/* fall through */ default : -if (rdmsr_safe (reg, temp) ) -break ; +gdprintk (XENLOG_WARNING , +"WRMSR 0x%08x val 0x%016" PRIx64" unimplemented\n" , + reg, val); +break ; -if ( val != temp ) invalid: -gdprintk (XENLOG_WARNING , -"Domain attempted WRMSR %08x from 0x%016" PRIx64" to 0x%016" PRIx64"\n" , - reg, temp, val); +gdprintk (XENLOG_WARNING , +"Domain attempted WRMSR 0x%08x from 0x%016" PRIx64" to 0x%016" PRIx64"\n" , + reg, temp, val);return X86EMUL_OKAY ; }
Signature · 1 line
2.28.0
PATCH v3 7/8 x86/hvm: Disallow access to unknown MSRs
In reply to Roger Pau MonneFrom: Andrew Cooper <[email protected]>
Change the catch-all behavior for MSR not explicitly handled. Instead of allow full read-access to the MSR space and silently dropping writes return an exception when the MSR is not explicitly handled.
---
Changes since v1:
- Fold chunk to remove explicit write handling of VMX MSRs just to #GP.
- Remove catch-all rdmsr_safe in svm_msr_read_intercept.
--- xen/arch/x86/hvm/svm/svm.c | 10 ++++------ xen/arch/x86/hvm/vmx/vmx.c | 16 ++++------------ 2 files changed, 8 insertions(+), 18 deletions(-)
xen/arch/x86/hvm/svm/svm.c +4 -6
@@ -1964,8 +1964,7 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content)break ;default : -if (rdmsr_safe (msr, *msr_content) ==0 ) -break ; +gdprintk (XENLOG_WARNING ,"RDMSR 0x%08x unimplemented\n" , msr); goto gpf; }
@@ -2150,10 +2149,9 @@ static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content)break ;default : -/* Match up with the RDMSR side; ultimately this should go away. */ -if (rdmsr_safe (msr, msr_content) ==0 ) -break ; - +gdprintk (XENLOG_WARNING , +"WRMSR 0x%08x val 0x%016" PRIx64" unimplemented\n" , + msr, msr_content); goto gpf; }
xen/arch/x86/hvm/vmx/vmx.c +4 -12
@@ -3015,9 +3015,7 @@ static int vmx_msr_read_intercept(unsigned int msr, uint64_t *msr_content)break ; } -if (rdmsr_safe (msr, *msr_content) ==0 ) -break ; - +gdprintk (XENLOG_WARNING ,"RDMSR 0x%08x unimplemented\n" , msr); goto gp_fault; }
@@ -3290,11 +3288,6 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content)__vmwrite (GUEST_IA32_DEBUGCTL , msr_content);break ; -case MSR_IA32_FEATURE_CONTROL : - case MSR_IA32_VMX_BASIC ... MSR_IA32_VMX_VMFUNC: -/* None of these MSRs are writeable. */ - goto gp_fault; -case MSR_IA32_MISC_ENABLE :/* Silently drop writes that don't change the reported value. */ if ( vmx_msr_read_intercept(msr, &tmp) != X86EMUL_OKAY ||
@@ -3320,10 +3313,9 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content) is_last_branch_msr(msr) )break ; -/* Match up with the RDMSR side; ultimately this should go away. */ -if (rdmsr_safe (msr, msr_content) ==0 ) -break ; - +gdprintk (XENLOG_WARNING , +"WRMSR 0x%08x val 0x%016" PRIx64" unimplemented\n" , + msr, msr_content); goto gp_fault; }
Signature · 1 line
2.28.0
Re: [PATCH v3 7/8] x86/hvm: Disallow access to unknown MSRs
xen/arch/x86/hvm/vmx/vmx.c static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content) · line 3296
Quoted 8 lines · Roger Pau Monne
xen/arch/x86/hvm/vmx/vmx.c +0
-4@@ -3290,11 +3288,6 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content)__vmwrite (GUEST_IA32_DEBUGCTL , msr_content);break ; -case MSR_IA32_FEATURE_CONTROL : - case MSR_IA32_VMX_BASIC ... MSR_IA32_VMX_VMFUNC: -/* None of these MSRs are writeable. */ - goto gp_fault;
I understand Andrew did ask for this (and I didn't look closely when I saw the comment), but ...
xen/arch/x86/hvm/vmx/vmx.c static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content) · line 3319
Quoted 12 lines
xen/arch/x86/hvm/vmx/vmx.c +3
-4@@ -3320,10 +3313,9 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content) is_last_branch_msr(msr) )break ; -/* Match up with the RDMSR side; ultimately this should go away. */ -if (rdmsr_safe (msr, msr_content) ==0 ) -break ; - +gdprintk (XENLOG_WARNING , +"WRMSR 0x%08x val 0x%016" PRIx64" unimplemented\n" , + msr, msr_content); goto gp_fault;
... above from here is logic that handling of these MSRs now goes through. I'm particularly worried about vmx_write_guest_msr(), which blindly updates the value of any MSR it can find, i.e. if any r/o MSR (from the set above, or even more generally) ever got added to this vCPU-specific set, the r/o-ness would no longer be maintained. Do we perhaps need to white-list MSRs for which vmx_write_guest_msr() may get called here?
Jan
Re: [PATCH v3 7/8] x86/hvm: Disallow access to unknown MSRs
Quoted 16 lines · Jan Beulich
xen/arch/x86/hvm/vmx/vmx.c static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content) · line 3296
Quoted 8 lines · Roger Pau Monne
xen/arch/x86/hvm/vmx/vmx.c +0
-4@@ -3290,11 +3288,6 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content)__vmwrite (GUEST_IA32_DEBUGCTL , msr_content);break ; -case MSR_IA32_FEATURE_CONTROL : - case MSR_IA32_VMX_BASIC ... MSR_IA32_VMX_VMFUNC: -/* None of these MSRs are writeable. */ - goto gp_fault;I understand Andrew did ask for this (and I didn't look closely when I saw the comment), but ...
Quoted 4 lines
xen/arch/x86/hvm/vmx/vmx.c +0
-0@@ -3320,10 +3313,9 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content) is_last_branch_msr(msr) )break ;
Quoted 15 lines
xen/arch/x86/hvm/vmx/vmx.c static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content) · line 3319
Quoted 8 lines
xen/arch/x86/hvm/vmx/vmx.c +3
-4-/* Match up with the RDMSR side; ultimately this should go away. */ -if (rdmsr_safe (msr, msr_content) ==0 ) -break ; - +gdprintk (XENLOG_WARNING , +"WRMSR 0x%08x val 0x%016" PRIx64" unimplemented\n" , + msr, msr_content); goto gp_fault;... above from here is logic that handling of these MSRs now goes through. I'm particularly worried about
vmx_write_guest_msr(), which blindly updates the value of any MSR it can find, i.e. if any r/o MSR (from the set above, or even more generally) ever got added to this vCPU-specific set, the r/o-ness would no longer be maintained. Do we perhaps need to white-list MSRs for whichvmx_write_guest_msr()may get called here?
If a read-only MSR ever actually gets into the load/save list, we'll take a VMEntry failure (guest load) or SHUTDOWN (host load) as a consequence of microcode takes a #GP fault.
However, restricting the content of this catch-all clause to nothing (but the printk) is something I have planned as part of the ongoing MSR cleanup work.
~Andrew
Jan Beulich
Reviewed-byRe: [PATCH v3 7/8] x86/hvm: Disallow access to unknown MSRs
Quoted 33 lines · Andrew Cooper
Quoted 16 lines · Jan Beulich
xen/arch/x86/hvm/vmx/vmx.c static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content) · line 3296
Quoted 8 lines · Roger Pau Monne
xen/arch/x86/hvm/vmx/vmx.c +0
-4@@ -3290,11 +3288,6 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content)__vmwrite (GUEST_IA32_DEBUGCTL , msr_content);break ; -case MSR_IA32_FEATURE_CONTROL : - case MSR_IA32_VMX_BASIC ... MSR_IA32_VMX_VMFUNC: -/* None of these MSRs are writeable. */ - goto gp_fault;I understand Andrew did ask for this (and I didn't look closely when I saw the comment), but ...
Quoted 4 lines
xen/arch/x86/hvm/vmx/vmx.c +0
-0@@ -3320,10 +3313,9 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content) is_last_branch_msr(msr) )break ;Quoted 15 lines
xen/arch/x86/hvm/vmx/vmx.c static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content) · line 3319
Quoted 8 lines
xen/arch/x86/hvm/vmx/vmx.c +3
-4-/* Match up with the RDMSR side; ultimately this should go away. */ -if (rdmsr_safe (msr, msr_content) ==0 ) -break ; - +gdprintk (XENLOG_WARNING , +"WRMSR 0x%08x val 0x%016" PRIx64" unimplemented\n" , + msr, msr_content); goto gp_fault;... above from here is logic that handling of these MSRs now goes through. I'm particularly worried about
vmx_write_guest_msr(), which blindly updates the value of any MSR it can find, i.e. if any r/o MSR (from the set above, or even more generally) ever got added to this vCPU-specific set, the r/o-ness would no longer be maintained. Do we perhaps need to white-list MSRs for whichvmx_write_guest_msr()may get called here?
Quoted 3 lines
If a read-only MSR ever actually gets into the load/save list, we'll take a VMEntry failure (guest load) or SHUTDOWN (host load) as a consequence of microcode takes a #GP fault.
Oh, of course. In order to surface a value different from the hardware's one has to intercept such MSRs.
Quoted 3 lines
However, restricting the content of this catch-all clause to nothing (but the printk) is something I have planned as part of the ongoing MSR cleanup work.
Good to know.
Jan
Re: [PATCH v3 7/8] x86/hvm: Disallow access to unknown MSRs
In reply to Jan BeulichQuoted 17 lines · Jan Beulich
xen/arch/x86/hvm/vmx/vmx.c static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content) · line 3296
Quoted 8 lines · Roger Pau Monne
xen/arch/x86/hvm/vmx/vmx.c +0
-4@@ -3290,11 +3288,6 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content)__vmwrite (GUEST_IA32_DEBUGCTL , msr_content);break ; -case MSR_IA32_FEATURE_CONTROL : - case MSR_IA32_VMX_BASIC ... MSR_IA32_VMX_VMFUNC: -/* None of these MSRs are writeable. */ - goto gp_fault;I understand Andrew did ask for this (and I didn't look closely when I saw the comment), but ...
Quoted 4 lines
xen/arch/x86/hvm/vmx/vmx.c +0
-0@@ -3320,10 +3313,9 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content) is_last_branch_msr(msr) )break ;
Quoted 15 lines
xen/arch/x86/hvm/vmx/vmx.c static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content) · line 3319
Quoted 8 lines
xen/arch/x86/hvm/vmx/vmx.c +3
-4-/* Match up with the RDMSR side; ultimately this should go away. */ -if (rdmsr_safe (msr, msr_content) ==0 ) -break ; - +gdprintk (XENLOG_WARNING , +"WRMSR 0x%08x val 0x%016" PRIx64" unimplemented\n" , + msr, msr_content); goto gp_fault;... above from here is logic that handling of these MSRs now goes through. I'm particularly worried about
vmx_write_guest_msr(), which blindly updates the value of any MSR it can find, i.e. if any r/o MSR (from the set above, or even more generally) ever got added to this vCPU-specific set, the r/o-ness would no longer be maintained.
But those MSRs need to be added to the list explicitly (using vmx_add_guest_msr) in order for the guest to be able to update them, and they are supposed to be owned by the guest?
I understand the concern, but AFAICT none of the MSRs handled by VMX_MSR_GUEST require such handling. Maybe it's worth adding something like VMX_MSR_GUEST_RO in the future if such need arises?
Quoted 2 lines
Do we perhaps need to white-list MSRs for which
vmx_write_guest_msr()may get called here?
When such MSRs are added such addition should make sure they are not allowed write permissions? You would have to do that now anyway AFAICT.
Roger.
RE: [PATCH v3 7/8] x86/hvm: Disallow access to unknown MSRs
In reply to Roger Pau MonneQuoted 5 lines
From: Roger Pau Monne <[email protected]>
Sent: Tuesday, September 1, 2020 6:55 PMFrom: Andrew Cooper <[email protected]>
Quoted 7 lines
Change the catch-all behavior for MSR not explicitly handled. Instead of allow full read-access to the MSR space and silently dropping writes return an exception when the MSR is not explicitly handled.
Signed-off-by Andrew Cooper <[email protected]>[remove rdmsr_safe from default case in svm_msr_read_intercept]Signed-off-by Roger Pau Monné <[email protected]>
Quoted 88 lines
---
Changes since v1:
- Fold chunk to remove explicit write handling of VMX MSRs just to #GP.
- Remove catch-allrdmsr_safeinsvm_msr_read_intercept.--- xen/arch/x86/hvm/svm/svm.c | 10 ++++------ xen/arch/x86/hvm/vmx/vmx.c | 16 ++++------------ 2 files changed, 8 insertions(+), 18 deletions(-)xen/arch/x86/hvm/svm/svm.c +1
-2@@ -1964,8 +1964,7 @@ static int svm_msr_read_intercept(unsigned int msr, uint64_t *msr_content)break ;default : -if (rdmsr_safe (msr, *msr_content) ==0 ) -break ; +gdprintk (XENLOG_WARNING ,"RDMSR 0x%08x unimplemented\n" , msr); goto gpf;}xen/arch/x86/hvm/svm/svm.c +3
-4@@ -2150,10 +2149,9 @@ static int svm_msr_write_intercept(unsigned int msr, uint64_t msr_content)break ;default : -/* Match up with the RDMSR side; ultimately this should go away. */ -if (rdmsr_safe (msr, msr_content) ==0 ) -break ; - +gdprintk (XENLOG_WARNING , +"WRMSR 0x%08x val 0x%016" PRIx64" unimplemented\n" , + msr, msr_content); goto gpf; }xen/arch/x86/hvm/vmx/vmx.c +1
-3@@ -3015,9 +3015,7 @@ static int vmx_msr_read_intercept(unsigned int msr, uint64_t *msr_content)break ; } -if (rdmsr_safe (msr, *msr_content) ==0 ) -break ; - +gdprintk (XENLOG_WARNING ,"RDMSR 0x%08x unimplemented\n" , msr); goto gp_fault;}xen/arch/x86/hvm/vmx/vmx.c +0
-5@@ -3290,11 +3288,6 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content)__vmwrite (GUEST_IA32_DEBUGCTL , msr_content);break ; -case MSR_IA32_FEATURE_CONTROL : - case MSR_IA32_VMX_BASIC ... MSR_IA32_VMX_VMFUNC: -/* None of these MSRs are writeable. */ - goto gp_fault; -case MSR_IA32_MISC_ENABLE :/* Silently drop writes that don't change the reported value. */ if ( vmx_msr_read_intercept(msr, &tmp) != X86EMUL_OKAY ||xen/arch/x86/hvm/vmx/vmx.c +3
-5@@ -3320,10 +3313,9 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content) is_last_branch_msr(msr) ) break; -/* Match up with the RDMSR side; ultimately this should go away. */ -if (rdmsr_safe (msr, msr_content) ==0 ) -break ; - +gdprintk (XENLOG_WARNING , +"WRMSR 0x%08x val 0x%016" PRIx64" unimplemented\n" , + msr, msr_content); goto gp_fault; } --2.28.0
PATCH v3 8/8 x86/msr: Drop compatibility #GP handling in guest_{rd, wr}msr()
In reply to Roger Pau MonneFrom: Andrew Cooper <[email protected]>
Now that the main PV/HVM MSR handlers raise #GP for all unknown MSRs, there is no need to special case these MSRs any more.
---
Changes since v1:
- New in this version.
--- xen/arch/x86/msr.c | 46 ---------------------------------------------- 1 file changed, 46 deletions(-)
xen/arch/x86/msr.c +0 -46
@@ -175,29 +175,6 @@ int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val)switch ( msr ) { -case MSR_AMD_PATCHLOADER : -case MSR_IA32_UCODE_WRITE : -case MSR_PRED_CMD : -case MSR_FLUSH_CMD : -/* Write-only */ -case MSR_TEST_CTRL : -case MSR_CORE_CAPABILITIES : -case MSR_TSX_FORCE_ABORT : -case MSR_TSX_CTRL : -case MSR_MCU_OPT_CTRL : - case MSR_RTIT_OUTPUT_BASE ... MSR_RTIT_ADDR_B(7): -case MSR_U_CET : -case MSR_S_CET : - case MSR_PL0_SSP ... MSR_INTERRUPT_SSP_TABLE: -case MSR_AMD64_LWP_CFG : -case MSR_AMD64_LWP_CBADDR : -case MSR_PPIN_CTL : -case MSR_PPIN : -case MSR_AMD_PPIN_CTL : -case MSR_AMD_PPIN : -/* Not offered to guests. */ - goto gp_fault; -case MSR_IA32_FEATURE_CONTROL :if ( !(cp->x86_vendor &X86_VENDOR_INTEL ) ) goto gp_fault;
@@ -365,29 +342,6 @@ int guest_wrmsr(struct vcpu *v, uint32_t msr, uint64_t val) {uint64_t rsvd; -case MSR_IA32_PLATFORM_ID : -case MSR_CORE_CAPABILITIES : -case MSR_INTEL_CORE_THREAD_COUNT : -case MSR_INTEL_PLATFORM_INFO : -case MSR_ARCH_CAPABILITIES : -/* Read-only */ -case MSR_TEST_CTRL : -case MSR_TSX_FORCE_ABORT : -case MSR_TSX_CTRL : -case MSR_MCU_OPT_CTRL : - case MSR_RTIT_OUTPUT_BASE ... MSR_RTIT_ADDR_B(7): -case MSR_U_CET : -case MSR_S_CET : - case MSR_PL0_SSP ... MSR_INTERRUPT_SSP_TABLE: -case MSR_AMD64_LWP_CFG : -case MSR_AMD64_LWP_CBADDR : -case MSR_PPIN_CTL : -case MSR_PPIN : -case MSR_AMD_PPIN_CTL : -case MSR_AMD_PPIN : -/* Not offered to guests. */ - goto gp_fault; -case MSR_AMD_PATCHLEVEL :BUILD_BUG_ON (MSR_IA32_UCODE_REV !=MSR_AMD_PATCHLEVEL );/*
Signature · 1 line
2.28.0