Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753445AbdHXRmn (ORCPT ); Thu, 24 Aug 2017 13:42:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41266 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753815AbdHXRml (ORCPT ); Thu, 24 Aug 2017 13:42:41 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3C73A61480 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=david@redhat.com Subject: Re: [PATCH 3/4] kvm: vmx: Raise #UD on unsupported RDSEED To: Paolo Bonzini , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: jmattson@google.com References: <1503581879-52125-1-git-send-email-pbonzini@redhat.com> <1503581879-52125-4-git-send-email-pbonzini@redhat.com> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <6894e4a4-5ae2-7479-e60f-1677e5dee155@redhat.com> Date: Thu, 24 Aug 2017 19:42:39 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <1503581879-52125-4-git-send-email-pbonzini@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 24 Aug 2017 17:42:41 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2951 Lines: 86 On 24.08.2017 15:37, Paolo Bonzini wrote: > From: Jim Mattson > > A guest may not be configured to support RDSEED, even when the host > does. If the guest does not support RDSEED, intercept the instruction > and synthesize #UD. Also clear the "allowed-1" bit for RDSEED exiting > in the IA32_VMX_PROCBASED_CTLS2 MSR. > > Signed-off-by: Jim Mattson > Signed-off-by: Paolo Bonzini > --- > arch/x86/kvm/vmx.c | 24 +++++++++++++++++++++++- > 1 file changed, 23 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index 1f2c69de7872..954e26079cd6 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -2818,7 +2818,6 @@ static void nested_vmx_setup_ctls_msrs(struct vcpu_vmx *vmx) > vmx->nested.nested_vmx_secondary_ctls_high); > vmx->nested.nested_vmx_secondary_ctls_low = 0; > vmx->nested.nested_vmx_secondary_ctls_high &= > - SECONDARY_EXEC_RDSEED | > SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES | > SECONDARY_EXEC_DESC | > SECONDARY_EXEC_VIRTUALIZE_X2APIC_MODE | > @@ -3671,6 +3670,7 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf) > SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY | > SECONDARY_EXEC_SHADOW_VMCS | > SECONDARY_EXEC_XSAVES | > + SECONDARY_EXEC_RDSEED | > SECONDARY_EXEC_RDRAND | > SECONDARY_EXEC_ENABLE_PML | > SECONDARY_EXEC_TSC_SCALING | > @@ -5280,6 +5280,12 @@ static bool vmx_rdrand_supported(void) > SECONDARY_EXEC_RDRAND; > } > > +static bool vmx_rdseed_supported(void) > +{ > + return vmcs_config.cpu_based_2nd_exec_ctrl & > + SECONDARY_EXEC_RDSEED; > +} > + > static void vmx_compute_secondary_exec_control(struct vcpu_vmx *vmx) > { > struct kvm_vcpu *vcpu = &vmx->vcpu; > @@ -5364,6 +5370,21 @@ static void vmx_compute_secondary_exec_control(struct vcpu_vmx *vmx) > } > } > > + if (vmx_rdseed_supported()) { > + bool rdseed_enabled = guest_cpuid_has(vcpu, X86_FEATURE_RDSEED); > + if (rdseed_enabled) > + exec_control &= ~SECONDARY_EXEC_RDSEED; > + > + if (nested) { > + if (rdseed_enabled) > + vmx->nested.nested_vmx_secondary_ctls_high |= > + SECONDARY_EXEC_RDSEED; > + else > + vmx->nested.nested_vmx_secondary_ctls_high &= > + ~SECONDARY_EXEC_RDSEED; > + } > + } > + > vmx->secondary_exec_control = exec_control; > } > > @@ -8119,6 +8140,7 @@ static int (*const kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = { > [EXIT_REASON_INVEPT] = handle_invept, > [EXIT_REASON_INVVPID] = handle_invvpid, > [EXIT_REASON_RDRAND] = handle_invalid_op, > + [EXIT_REASON_RDSEED] = handle_invalid_op, > [EXIT_REASON_XSAVES] = handle_xsaves, > [EXIT_REASON_XRSTORS] = handle_xrstors, > [EXIT_REASON_PML_FULL] = handle_pml_full, > Reviewed-by: David Hildenbrand -- Thanks, David