* [PATCH] KVM: vmx: add mismatched size in vmcs_check32
@ 2021-04-08 7:54 lihaiwei.kernel
2021-04-08 16:05 ` Sean Christopherson
0 siblings, 1 reply; 4+ messages in thread
From: lihaiwei.kernel @ 2021-04-08 7:54 UTC (permalink / raw)
To: linux-kernel, kvm
Cc: pbonzini, seanjc, vkuznets, wanpengli, jmattson, joro, Haiwei Li
From: Haiwei Li <lihaiwei@tencent.com>
vmcs_check32 misses the check for 64-bit and 64-bit high.
Signed-off-by: Haiwei Li <lihaiwei@tencent.com>
---
arch/x86/kvm/vmx/vmx_ops.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/x86/kvm/vmx/vmx_ops.h b/arch/x86/kvm/vmx/vmx_ops.h
index 692b0c3..164b64f 100644
--- a/arch/x86/kvm/vmx/vmx_ops.h
+++ b/arch/x86/kvm/vmx/vmx_ops.h
@@ -37,6 +37,10 @@ static __always_inline void vmcs_check32(unsigned long field)
{
BUILD_BUG_ON_MSG(__builtin_constant_p(field) && ((field) & 0x6000) == 0,
"32-bit accessor invalid for 16-bit field");
+ BUILD_BUG_ON_MSG(__builtin_constant_p(field) && ((field) & 0x6001) == 0x2000,
+ "32-bit accessor invalid for 64-bit field");
+ BUILD_BUG_ON_MSG(__builtin_constant_p(field) && ((field) & 0x6001) == 0x2001,
+ "32-bit accessor invalid for 64-bit high field");
BUILD_BUG_ON_MSG(__builtin_constant_p(field) && ((field) & 0x6000) == 0x6000,
"32-bit accessor invalid for natural width field");
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] KVM: vmx: add mismatched size in vmcs_check32
2021-04-08 7:54 [PATCH] KVM: vmx: add mismatched size in vmcs_check32 lihaiwei.kernel
@ 2021-04-08 16:05 ` Sean Christopherson
2021-04-08 16:28 ` Paolo Bonzini
2021-04-09 1:57 ` Haiwei Li
0 siblings, 2 replies; 4+ messages in thread
From: Sean Christopherson @ 2021-04-08 16:05 UTC (permalink / raw)
To: lihaiwei.kernel
Cc: linux-kernel, kvm, pbonzini, vkuznets, wanpengli, jmattson, joro,
Haiwei Li
On Thu, Apr 08, 2021, lihaiwei.kernel@gmail.com wrote:
> From: Haiwei Li <lihaiwei@tencent.com>
>
> vmcs_check32 misses the check for 64-bit and 64-bit high.
Can you clarify in the changelog that, while it is architecturally legal to
access 64-bit and 64-bit high fields with a 32-bit read/write in 32-bit mode,
KVM should never do partial accesses to VMCS fields. And/or note that the
32-bit accesses are done in vmcs_{read,write}64() when necessary? Hmm, maybe:
Add compile-time assertions in vmcs_check32() to disallow accesses to
64-bit and 64-bit high fields via vmcs_{read,write}32(). Upper level
KVM code should never do partial accesses to VMCS fields. KVM handles
the split accesses automatically in vmcs_{read,write}64() when running
as a 32-bit kernel.
With something along those lines:
Reviewed-and-tested-by: Sean Christopherson <seanjc@google.com>
> Signed-off-by: Haiwei Li <lihaiwei@tencent.com>
> ---
> arch/x86/kvm/vmx/vmx_ops.h | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/arch/x86/kvm/vmx/vmx_ops.h b/arch/x86/kvm/vmx/vmx_ops.h
> index 692b0c3..164b64f 100644
> --- a/arch/x86/kvm/vmx/vmx_ops.h
> +++ b/arch/x86/kvm/vmx/vmx_ops.h
> @@ -37,6 +37,10 @@ static __always_inline void vmcs_check32(unsigned long field)
> {
> BUILD_BUG_ON_MSG(__builtin_constant_p(field) && ((field) & 0x6000) == 0,
> "32-bit accessor invalid for 16-bit field");
> + BUILD_BUG_ON_MSG(__builtin_constant_p(field) && ((field) & 0x6001) == 0x2000,
> + "32-bit accessor invalid for 64-bit field");
> + BUILD_BUG_ON_MSG(__builtin_constant_p(field) && ((field) & 0x6001) == 0x2001,
> + "32-bit accessor invalid for 64-bit high field");
> BUILD_BUG_ON_MSG(__builtin_constant_p(field) && ((field) & 0x6000) == 0x6000,
> "32-bit accessor invalid for natural width field");
> }
> --
> 1.8.3.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] KVM: vmx: add mismatched size in vmcs_check32
2021-04-08 16:05 ` Sean Christopherson
@ 2021-04-08 16:28 ` Paolo Bonzini
2021-04-09 1:57 ` Haiwei Li
1 sibling, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2021-04-08 16:28 UTC (permalink / raw)
To: Sean Christopherson, lihaiwei.kernel
Cc: linux-kernel, kvm, vkuznets, wanpengli, jmattson, joro, Haiwei Li
On 08/04/21 18:05, Sean Christopherson wrote:
> Add compile-time assertions in vmcs_check32() to disallow accesses to
> 64-bit and 64-bit high fields via vmcs_{read,write}32(). Upper level
> KVM code should never do partial accesses to VMCS fields. KVM handles
> the split accesses automatically in vmcs_{read,write}64() when running
> as a 32-bit kernel.
KVM also uses raw vmread/vmwrite (__vmcs_readl/__vmcs_writel) when
copying to and from the shadow VMCS, so that path will not go through
vmcs_check32 either.
Paolo
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] KVM: vmx: add mismatched size in vmcs_check32
2021-04-08 16:05 ` Sean Christopherson
2021-04-08 16:28 ` Paolo Bonzini
@ 2021-04-09 1:57 ` Haiwei Li
1 sibling, 0 replies; 4+ messages in thread
From: Haiwei Li @ 2021-04-09 1:57 UTC (permalink / raw)
To: Sean Christopherson
Cc: LKML, kvm list, Paolo Bonzini, Vitaly Kuznetsov, Wanpeng Li,
Jim Mattson, Joerg Roedel, Haiwei Li
On Fri, Apr 9, 2021 at 12:05 AM Sean Christopherson <seanjc@google.com> wrote:
>
> On Thu, Apr 08, 2021, lihaiwei.kernel@gmail.com wrote:
> > From: Haiwei Li <lihaiwei@tencent.com>
> >
> > vmcs_check32 misses the check for 64-bit and 64-bit high.
>
> Can you clarify in the changelog that, while it is architecturally legal to
> access 64-bit and 64-bit high fields with a 32-bit read/write in 32-bit mode,
> KVM should never do partial accesses to VMCS fields. And/or note that the
> 32-bit accesses are done in vmcs_{read,write}64() when necessary? Hmm, maybe:
>
> Add compile-time assertions in vmcs_check32() to disallow accesses to
> 64-bit and 64-bit high fields via vmcs_{read,write}32(). Upper level
> KVM code should never do partial accesses to VMCS fields. KVM handles
> the split accesses automatically in vmcs_{read,write}64() when running
> as a 32-bit kernel.
Good suggestion, thanks. I will send v2.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-04-09 1:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-08 7:54 [PATCH] KVM: vmx: add mismatched size in vmcs_check32 lihaiwei.kernel
2021-04-08 16:05 ` Sean Christopherson
2021-04-08 16:28 ` Paolo Bonzini
2021-04-09 1:57 ` Haiwei Li
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.