From patchwork Wed Nov 3 18:32:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 12601455 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F371CC433EF for ; Wed, 3 Nov 2021 18:34:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CD4F360F5A for ; Wed, 3 Nov 2021 18:34:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231266AbhKCSgd (ORCPT ); Wed, 3 Nov 2021 14:36:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229837AbhKCSg1 (ORCPT ); Wed, 3 Nov 2021 14:36:27 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D83E6C061714 for ; Wed, 3 Nov 2021 11:33:50 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id n9-20020a170902968900b0013f23b51142so1502450plp.8 for ; Wed, 03 Nov 2021 11:33:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=J5vfKF6W1D5gAeKm4lwrd0QK8zJYwxNEd4UBSUYOqrg=; b=To0pew1bYcekjF4Ldq5rjlQpbzzSeeCXehNV77kz2dvXRRMBkbbIm6yMN4WnRfwQzq s1/Hnpi9zbJ6ULjoqxYkxerz8TvwSqQ4j6oSJ3ZYKTO7gOUs7Sn3vIA7+ZAIAtEtNVAT fSPrXdhlZb4Xi890mAC2fRXzuYdNRpv/1czBHMZKiUgwOvJ2CQxhwTON1bO2MlLX91th JHHv6kvT84/PyjSCGCwfXiCNzDlkkEqcHr52wt3t9TXjJMF6scvmSAFprAuuruy9LxBO UgW4l9LQ7VgbdO3h4Nd+l5r6059C1CP9D7FMRIeMvGovYJY49BjemuNqaD5dWngY+tbP xGXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=J5vfKF6W1D5gAeKm4lwrd0QK8zJYwxNEd4UBSUYOqrg=; b=UMnCemlaAdp4GGtk3HssfPKrvHvLRB0UvbtB5GHPRzjlzcpK0R702sjR+dFsCk7Qi7 /8Ng5m7cMAsShC1G172neYOQoxvTC75timYfHB7B2x0NFU9hhgbC8yFY7oAWKmbcsgtm DOxSBqwvcZkXXSmVO27c4skat5rKQPF2RozH2AwlfD5rvOslRxVpd/yOqO8UlIU0LBwC 8aDTCEp3WKBQyajrmnWY2pHHCq7N6xelyGZvvHRo/lu1DwVW4E/QgWF5BdtKEv+GK/LH XkYGMRnVmWKjE1l8uJW2hvrIrfdIR/7R3VnUAEpUeZFbDANB5QePtWzD+VwCYr+u6MhL P9/g== X-Gm-Message-State: AOAM531z6rT+IYtDl2UAQdsciEuJdPXJvv00jS1aMHHLFSs2dsfzrjBW OP47hbTjzJGrXvFdxb0Ab97sFMPXDyrU X-Google-Smtp-Source: ABdhPJwC4fvy2sGmysq37/bAuht9+nkpD/vRteKePPgPc/w35pQ2gLI8Z0wLKbfoL1Y90YyHELXppPMrt35o X-Received: from vipinsh.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:36b0]) (user=vipinsh job=sendgmr) by 2002:a05:6a00:2293:b0:481:fe4:c9df with SMTP id f19-20020a056a00229300b004810fe4c9dfmr22559109pfe.69.1635964430317; Wed, 03 Nov 2021 11:33:50 -0700 (PDT) Date: Wed, 3 Nov 2021 18:32:31 +0000 In-Reply-To: <20211103183232.1213761-1-vipinsh@google.com> Message-Id: <20211103183232.1213761-2-vipinsh@google.com> Mime-Version: 1.0 References: <20211103183232.1213761-1-vipinsh@google.com> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog Subject: [PATCH v2 1/2] KVM: VMX: Add a wrapper to read index of GPR for INVPCID, INVVPID, and INVEPT From: Vipin Sharma To: pbonzini@redhat.com, seanjc@google.com, jmattson@google.com Cc: dmatlack@google.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org handle_invept(), handle_invvpid(), handle_invpcid() read the same reg2 on VM exit. Move them to a common wrapper function. Signed-off-by: Vipin Sharma Reviewed-by: Sean Christopherson --- arch/x86/kvm/vmx/nested.c | 10 ++++++---- arch/x86/kvm/vmx/vmx.c | 4 +++- arch/x86/kvm/vmx/vmx.h | 5 +++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index b4ee5e9f9e20..f73d4e31dd99 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -5379,7 +5379,7 @@ static int handle_invept(struct kvm_vcpu *vcpu) struct { u64 eptp, gpa; } operand; - int i, r; + int i, r, gpr_index; if (!(vmx->nested.msrs.secondary_ctls_high & SECONDARY_EXEC_ENABLE_EPT) || @@ -5392,7 +5392,8 @@ static int handle_invept(struct kvm_vcpu *vcpu) return 1; vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO); - type = kvm_register_read(vcpu, (vmx_instruction_info >> 28) & 0xf); + gpr_index = vmx_get_instr_info_reg2(vmx_instruction_info); + type = kvm_register_read(vcpu, gpr_index); types = (vmx->nested.msrs.ept_caps >> VMX_EPT_EXTENT_SHIFT) & 6; @@ -5459,7 +5460,7 @@ static int handle_invvpid(struct kvm_vcpu *vcpu) u64 gla; } operand; u16 vpid02; - int r; + int r, gpr_index; if (!(vmx->nested.msrs.secondary_ctls_high & SECONDARY_EXEC_ENABLE_VPID) || @@ -5472,7 +5473,8 @@ static int handle_invvpid(struct kvm_vcpu *vcpu) return 1; vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO); - type = kvm_register_read(vcpu, (vmx_instruction_info >> 28) & 0xf); + gpr_index = vmx_get_instr_info_reg2(vmx_instruction_info); + type = kvm_register_read(vcpu, gpr_index); types = (vmx->nested.msrs.vpid_caps & VMX_VPID_EXTENT_SUPPORTED_MASK) >> 8; diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 71f54d85f104..e41d207e3298 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -5494,6 +5494,7 @@ static int handle_invpcid(struct kvm_vcpu *vcpu) u64 pcid; u64 gla; } operand; + int gpr_index; if (!guest_cpuid_has(vcpu, X86_FEATURE_INVPCID)) { kvm_queue_exception(vcpu, UD_VECTOR); @@ -5501,7 +5502,8 @@ static int handle_invpcid(struct kvm_vcpu *vcpu) } vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO); - type = kvm_register_read(vcpu, (vmx_instruction_info >> 28) & 0xf); + gpr_index = vmx_get_instr_info_reg2(vmx_instruction_info); + type = kvm_register_read(vcpu, gpr_index); if (type > 3) { kvm_inject_gp(vcpu, 0); diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h index e7db42e3b0ce..95c9bca45cdd 100644 --- a/arch/x86/kvm/vmx/vmx.h +++ b/arch/x86/kvm/vmx/vmx.h @@ -522,4 +522,9 @@ static inline bool vmx_guest_state_valid(struct kvm_vcpu *vcpu) void dump_vmcs(struct kvm_vcpu *vcpu); +static inline int vmx_get_instr_info_reg2(u32 vmx_instr_info) +{ + return (vmx_instr_info >> 28) & 0xf; +} + #endif /* __KVM_X86_VMX_H */ From patchwork Wed Nov 3 18:32:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 12601457 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7249EC433EF for ; Wed, 3 Nov 2021 18:34:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 56F5C60F5A for ; Wed, 3 Nov 2021 18:34:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231474AbhKCSgl (ORCPT ); Wed, 3 Nov 2021 14:36:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231211AbhKCSga (ORCPT ); Wed, 3 Nov 2021 14:36:30 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2067C061203 for ; Wed, 3 Nov 2021 11:33:53 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id hg9-20020a17090b300900b001a6aa0b7d8cso1389214pjb.2 for ; Wed, 03 Nov 2021 11:33:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=OlHAqqU2TheCKRbtoKErhWOTUsWwfnc35tms2ZBHd5Q=; b=kh9+dLdjtxAPihCGtfVuX/FN1/EC0cmISDZJ1SAjQZrt2KWL6jL5YvrHCbdsFFT8ph CC3/JoqRSQp1BmmqW8DNC5w8IL6g0uXSqPaPChgT3Sgr3YOYCBtQ2NLv2V+zgy7C9l4g gHOD2S4ivcsnDHqD1/lzbGkYAgAJXtMXNH3ajmNE8K30/KeX9Kp5mAR3J383w3yuBOAx BwTgomWiAbY8a3sa9Sc0QvbYOU9llKxJEUJP20JWVUpohQ+576iXpQ8RMp4cvkY5DPCE dSStnvIvy4FCjbnzoTYgpFffdjV3lZT45/XE9iRkfv+42jRnu+Po8S1+6z1C59kOrXJG c3gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=OlHAqqU2TheCKRbtoKErhWOTUsWwfnc35tms2ZBHd5Q=; b=oI32hFoN/7Z/szdyNHUU/CE7Zx86kX+zOYjSpV8g5CkpjOKy5wUWf8CP5WYXNb+/2z BBjy/iOq72JJwv0nMpqwsrYSQFM+NcOOC6En7/B5LfG1Y5c/erazXSmpsSTR/ErMhMV5 hj4VzqJg2y80CV/kCh4LU0AFDuVWNFcjZKI6Cknfqj2R7Ko1tsyesrvEhX4xBCGxhbIm kJlDYuYeSK3/Sq7p7tthTR4Q0odQPf+DyVhFW7XtIVoQA9mvsI00SzkA333zl4IurF8e FjuWCwI5kbobCLk5jGYejMz+GnXKYYf4k8/jaEqtgsv7nUb6j+iDyr9G/kyyOyIarCWc R98A== X-Gm-Message-State: AOAM533V/sEl/+oqwimZxAanxzVhUVx6vFx5Ea+x31G5zffoZXvU/EGA bmerLcRWD50ZckfXgWZnT/pNiQyc+l2T X-Google-Smtp-Source: ABdhPJydw8wL5wpiEWFxnBPPsArRY1Rud9a1UMXMzjKks9ifhZxNcejfeX53ueIDLpjfSsggZ/sF/FlCnLkf X-Received: from vipinsh.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:36b0]) (user=vipinsh job=sendgmr) by 2002:a17:903:1207:b0:13d:b9b1:ead7 with SMTP id l7-20020a170903120700b0013db9b1ead7mr39915184plh.63.1635964433179; Wed, 03 Nov 2021 11:33:53 -0700 (PDT) Date: Wed, 3 Nov 2021 18:32:32 +0000 In-Reply-To: <20211103183232.1213761-1-vipinsh@google.com> Message-Id: <20211103183232.1213761-3-vipinsh@google.com> Mime-Version: 1.0 References: <20211103183232.1213761-1-vipinsh@google.com> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog Subject: [PATCH v2 2/2] KVM: Move INVPCID type check from vmx and svm to the common kvm_handle_invpcid() From: Vipin Sharma To: pbonzini@redhat.com, seanjc@google.com, jmattson@google.com Cc: dmatlack@google.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This check will be done in switch statement of kvm_handle_invpcid(), used by both VMX and SVM. It also removes (type > 3) check. Signed-off-by: Vipin Sharma Reviewed-by: Sean Christopherson --- arch/x86/kvm/svm/svm.c | 5 ----- arch/x86/kvm/vmx/vmx.c | 5 ----- arch/x86/kvm/x86.c | 3 ++- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 21bb81710e0f..ccbf96876ec6 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3119,11 +3119,6 @@ static int invpcid_interception(struct kvm_vcpu *vcpu) type = svm->vmcb->control.exit_info_2; gva = svm->vmcb->control.exit_info_1; - if (type > 3) { - kvm_inject_gp(vcpu, 0); - return 1; - } - return kvm_handle_invpcid(vcpu, type, gva); } diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index e41d207e3298..a3bb9854f4d2 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -5505,11 +5505,6 @@ static int handle_invpcid(struct kvm_vcpu *vcpu) gpr_index = vmx_get_instr_info_reg2(vmx_instruction_info); type = kvm_register_read(vcpu, gpr_index); - if (type > 3) { - kvm_inject_gp(vcpu, 0); - return 1; - } - /* According to the Intel instruction reference, the memory operand * is read even if it isn't needed (e.g., for type==all) */ diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index ac83d873d65b..134585027e92 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -12443,7 +12443,8 @@ int kvm_handle_invpcid(struct kvm_vcpu *vcpu, unsigned long type, gva_t gva) return kvm_skip_emulated_instruction(vcpu); default: - BUG(); /* We have already checked above that type <= 3 */ + kvm_inject_gp(vcpu, 0); + return 1; } } EXPORT_SYMBOL_GPL(kvm_handle_invpcid);