Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp7560rwb; Fri, 12 Aug 2022 13:11:44 -0700 (PDT) X-Google-Smtp-Source: AA6agR6AmvOzTFb8ytuYNre18XWq5/LnI02LYa0seIEiWfjO1yynR8OMaDV58Zcz3+3MuFp6hc2C X-Received: by 2002:aa7:d159:0:b0:43d:73ba:64cf with SMTP id r25-20020aa7d159000000b0043d73ba64cfmr5021167edo.36.1660335103874; Fri, 12 Aug 2022 13:11:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660335103; cv=none; d=google.com; s=arc-20160816; b=pX2Fri0qN3bEcfuphkGzxluu+5Fkc9Q7UIk4K3dJ3VW71albceEm8rwj0YFyIbDMii bmWB7orAMkfDJa76GhkKulbUrqRDo4FG27PXr9aTcuuq2LPtDwOmx5UrVMZ7vD70rdEW EVVWPPzg/7fFUeMbsWlNfwaeDnaEinoZt+FwX+H2p9AhdztnYwB4iIPykm0hYwvHjKsO lCAGSQQSnxvqe9qf5S4YNhrYQ432Gks9bRDM80fH3FyegPeiah4XIkjIONF7S/gyFD1Y 0GYXeAw2R0jHYawRkmjzuNAb/ZZU63gAKksBJsGb7B1ornvPONmO3ifDKiUkaZ+P7wU+ 2FPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=pyCzP0WJ+v7YYl7i0GdEcJsuc5xybpRZaZrTHBnUyuI=; b=xHTU/hULxOBMmfMC60f4pECCSmlcoxUJ0YcplgYocUJFYEEgydy8MfaTOyzi+E6+wH IJGvNx7uJjBv6IKXCA7xULJUQf/lHO/3nQM3kGdpEBmT05VOPCrCrH6iTjDxTdx95HE1 ainHoylARR+ZuA2aWdAzL1TCnOkIDqQr1/FNt0kG10611snPefHmRo2rdAv3jaGiWc5p S1fCChEQheiGC469ANjtBiI2XNhCS0NJX7mnyKlqAh14ECl70IqnNMZlaMyAorxTAW+v krwqORUvDEX5qQbqOrfDlvCr7pkgIS/zSvqRO9s3yjcbBZ5ejnHqougxx8vZ/Ee1/EQl hCUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=tjBxXmKu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cy6-20020a0564021c8600b0043d4f544304si2252984edb.342.2022.08.12.13.11.18; Fri, 12 Aug 2022 13:11:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=tjBxXmKu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236110AbiHLTdT (ORCPT + 99 others); Fri, 12 Aug 2022 15:33:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230433AbiHLTdR (ORCPT ); Fri, 12 Aug 2022 15:33:17 -0400 Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 985B2B0B3E for ; Fri, 12 Aug 2022 12:33:16 -0700 (PDT) Received: by mail-ot1-x32e.google.com with SMTP id q39-20020a056830442700b0063889adc0ddso292188otv.1 for ; Fri, 12 Aug 2022 12:33:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc; bh=pyCzP0WJ+v7YYl7i0GdEcJsuc5xybpRZaZrTHBnUyuI=; b=tjBxXmKuFTbo/X5C0AifdNg85hQbAM5FOzw7DFgL9vEIH0+EFxcG2KUUxhswBHH0RJ AxCBrTV2u74aJ1qjAwWd4l+TbydCdbBAL4YSXWaBntv8f3NaJPz/ykssjHULMNPf3BLK 1Gz+eE3jKkZFObGHsDXG6tQKqedsUiEpEhIrdt8nUeoXDHd1wWZ6gpWNhHJTD237nA5R ESMg/BtmQvp6kSM2e3D6zGTgo7NgIvwg7xP+6ISs8N2nJxOncgmPZQOkaxzM0KcwdreB 5q+A6A4tDa6vK8LK2+QDrt1vf1RZWewf80LKxMOksOEIbvZHF70DzTenT8LjOvQuuQKj g2Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc; bh=pyCzP0WJ+v7YYl7i0GdEcJsuc5xybpRZaZrTHBnUyuI=; b=CIQN/nkorJXQM/Rk5581qjSwDIdksmfS9FXoKnAgpz1Uq0oe8O9L+ESJcKe8x6j6aO vLaUKY8Oh9EtvlNpVgCtw+IVSclgEGUNsFEW4ZHypAQR8xpKCcCWQV0qmrvKmedpwcH5 WbDTAYo7dYiH+BtnE5MpSY1kSl3bSm8adcXQYQraPaVbcHDmFL2uR6Op/E9uAqvrSI3b loAwSaOGB1Edx7icjunI86E1s4333GpSLk8ST7ci+ymlRkhCcf23PYkKvHPIXH+lrrdc L9CalZmZJRdh1WWL4HbNZofTpcEvCoKLpJBWssWch4LxArz++Dyn7Z6vRLZhjJdaR50m BdZg== X-Gm-Message-State: ACgBeo2op7OcBerqGFMRGSQ72C/BOxQE1rdpRrZV2DeDltYIEMuQjQpN 8Ep1Jky/V7xtyWdocUuwJ6UoibEcbYk/cTxH1TMY/Q== X-Received: by 2002:a9d:6517:0:b0:636:a8e7:4e86 with SMTP id i23-20020a9d6517000000b00636a8e74e86mr2104096otl.367.1660332795744; Fri, 12 Aug 2022 12:33:15 -0700 (PDT) MIME-Version: 1.0 References: <20220812014706.43409-1-yuan.yao@intel.com> <20220812020206.foknky4hghgsadby@yy-desk-7060> In-Reply-To: <20220812020206.foknky4hghgsadby@yy-desk-7060> From: Jim Mattson Date: Fri, 12 Aug 2022 12:33:05 -0700 Message-ID: Subject: Re: [PATCH 1/1] kvm: nVMX: Checks "VMCS shadowing" with VMCS link pointer for non-root mode VM{READ,WRITE} To: Yuan Yao Cc: Yuan Yao , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Paolo Bonzini , Sean Christopherson , Jon Cargille , Peter Shier , Oliver Upton Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 11, 2022 at 7:02 PM Yuan Yao wrote: > > On Fri, Aug 12, 2022 at 09:47:06AM +0800, Yuan Yao wrote: > > Add checking to VMCS12's "VMCS shadowing", make sure the checking of > > VMCS12's vmcs_link_pointer for non-root mode VM{READ,WRITE} happens > > only if VMCS12's "VMCS shadowing" is 1. > > > > SDM says that for non-root mode the VMCS's "VMCS shadowing" must be 1 > > (and the corresponding bits in VMREAD/VMWRITE bitmap must be 0) when > > condition checking of [B] is reached(please refer [A]), which means > > checking to VMCS link pointer for non-root mode VM{READ,WRITE} should > > happen only when "VMCS shadowing" =3D 1. > > > > Description from SDM Vol3(April 2022) Chapter 30.3 VMREAD/VMWRITE: > > > > IF (not in VMX operation) > > or (CR0.PE =3D 0) > > or (RFLAGS.VM =3D 1) > > or (IA32_EFER.LMA =3D 1 and CS.L =3D 0) > > THEN #UD; > > ELSIF in VMX non-root operation > > AND (=E2=80=9CVMCS shadowing=E2=80=9D is 0 OR > > source operand sets bits in range 63:15 OR > > VMREAD bit corresponding to bits 14:0 of source > > operand is 1) <------[A] > > THEN VMexit; > > ELSIF CPL > 0 > > THEN #GP(0); > > ELSIF (in VMX root operation AND current-VMCS pointer is not valid) OR > > (in VMX non-root operation AND VMCS link pointer is not valid) > > THEN VMfailInvalid; <------ [B] > > ... > > > > Fixes: dd2d6042b7f4 ("kvm: nVMX: VMWRITE checks VMCS-link pointer befor= e VMCS field") > > Signed-off-by: Yuan Yao > > --- > > arch/x86/kvm/vmx/nested.c | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c > > index ddd4367d4826..30685be54c5d 100644 > > --- a/arch/x86/kvm/vmx/nested.c > > +++ b/arch/x86/kvm/vmx/nested.c > > @@ -5123,6 +5123,7 @@ static int handle_vmread(struct kvm_vcpu *vcpu) > > */ > > if (vmx->nested.current_vmptr =3D=3D INVALID_GPA || > > (is_guest_mode(vcpu) && > > + nested_cpu_has_shadow_vmcs(vcpu) && > > Oops, should be "nested_cpu_has_shadow_vmcs(get_vmcs12(vcpu))". > > > get_vmcs12(vcpu)->vmcs_link_pointer =3D=3D INVALID_G= PA)) > > return nested_vmx_failInvalid(vcpu); > > > > @@ -5233,6 +5234,7 @@ static int handle_vmwrite(struct kvm_vcpu *vcpu) > > */ > > if (vmx->nested.current_vmptr =3D=3D INVALID_GPA || > > (is_guest_mode(vcpu) && > > + nested_cpu_has_shadow_vmcs(vcpu) && > > Ditto. > > > get_vmcs12(vcpu)->vmcs_link_pointer =3D=3D INVALID_GPA)) > > return nested_vmx_failInvalid(vcpu); > > > > -- These checks are redundant, aren't they? That is, nested_vmx_exit_handled_vmcs_access() has already checked nested_cpu_has_shadow_vmcs(vmcs12).