Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2126387rwb; Fri, 12 Aug 2022 12:32:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR6usGR6Gv/hcDgFSuVjuC5k0eB2/ZMqG99mzmnpiqyL2rWYEmGp/8FlfzPssv0FBOZNcE/C X-Received: by 2002:a17:90b:4ac7:b0:1f6:82bb:d132 with SMTP id mh7-20020a17090b4ac700b001f682bbd132mr15099449pjb.19.1660332746350; Fri, 12 Aug 2022 12:32:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660332746; cv=none; d=google.com; s=arc-20160816; b=x7z+E/+08yiG98w3d9heNSfc85PBMXx9DWDN1Sp1b/S8HqDGhM3BaTJBgcGXFebFap r/MFdNZAEvI1FYFEoLnuYxMnYtxpXB3R+MqkCQZXlwkuuWLlV1ZvWQJq7OLGly/G/1IL OtZL5T2hTHWS7+03hDrHLEu12Uuf9mrZIgF5tIuIokhD7kEeFVrJZHT1JkE/XL+ZRW2e yCnl9yp3n0bA+ycHrhfS1kA0YQyV8l9u645JWZ9fHoJ7qXRJcSQZmC0gqaQik36FxWu2 Cws2t+v6G8ltZTsP44sjaJkChQEGbUWL4qfFc/dulpe1EC3JapvxSS+UuCWzRGLlDmnP n3+g== 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=RFQCcD+o7jwAXDtp4U1/kPCj0a6x0GtskgYZEyvj9NE=; b=Ug5FRnjRdxNV2m7oxSN9HlB8EO7QpwQlx/61icxKqLFKPj4GGU+i8/BgJhUyDBeo/4 E/x4bgv8M/j7am3HDkoj9dgQNTxr2T8Z6odhnE3Xm/hqC43Hh89GHrt7t9fXFTq6ZnxD MoAggJUEc+wELtHi9XzBoc9BBvuX5DZ4RttQzz1HNXHyf4OEftwtmxwnEW+gS/AeXuTc 2fCyHR6bD5PfpWg7sVSRu98Sjxk5+/YY78aSdJri2/XlhD2opH7C6ukm6okZ3lgOGHZX Rfm4jyufQLQu+EFcH/MZq5MqRwSFtu7cvAM2Zsvj3442cOG9L0cQF2MiTFQfkdhLyKf+ 6j4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="VN5AtKQ/"; 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 k10-20020a63d84a000000b0041ce5893ffbsi3250758pgj.401.2022.08.12.12.32.14; Fri, 12 Aug 2022 12:32:26 -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="VN5AtKQ/"; 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 S237374AbiHLT12 (ORCPT + 99 others); Fri, 12 Aug 2022 15:27:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236041AbiHLT1Z (ORCPT ); Fri, 12 Aug 2022 15:27:25 -0400 Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0F6BB08AD for ; Fri, 12 Aug 2022 12:27:24 -0700 (PDT) Received: by mail-oi1-x22d.google.com with SMTP id j5so2184180oih.6 for ; Fri, 12 Aug 2022 12:27:24 -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=RFQCcD+o7jwAXDtp4U1/kPCj0a6x0GtskgYZEyvj9NE=; b=VN5AtKQ/0zk7x64khzHNWqzjm0YpR7+d4JF2kbafdw/v3J3hYRIdcNzqJ8FPF4RhUs QxLkUT7lD4USFVw1hxOGVaETi0LiAOQ7Se5IDMBtHLQrqUhWO9QFA1vmg/sR7Jva4mUN bXy3mS5hSvGH8qcmVfFGwtUzPTOuRVmUxe35w4vwvoeQRrC2muArkWZIRADALVts/l9C r0DlbDCVBXh4HDqzsk0LtHtUdWg1S2ZSvpJr8uxePjMrBacUFb0muvGa4vGkooI5euss QoKyMZdVvCNs8rQQAH6gfCe3pffgGNcqP5ZaavIFXTBtopeW3+iI8Oi2RHV4K9kHIxKw ADXw== 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=RFQCcD+o7jwAXDtp4U1/kPCj0a6x0GtskgYZEyvj9NE=; b=HXEqY+Do0lyoP7uItWWKludpd8pHfnVSesVgNbBiBHs5xw3OJ38DjYBLqlN5vpJOk8 kWOToANyfn9qI/WfKZ9tnGD8OL3bAq8gd2nEarl9/RPucQTs34bj6PmHgk9IeMQ/wUp4 AsWY6DyieOEZfYafh5Sfa47VJ1j621ELh9VPmBb8i+QV0xbzFgO15M4TJALOWStcN/vM XzmDHJueihV/SivzyB4034lm3TeR2aS0YcqYaDPLxggUFcVlRWAeGggNVk2XQx6BMorL inSrDD1tFv8IV9r7cjcgpFJVlXJiT6hiFbS5XSPv7xkhl3Lb8KKtrOb5rtDNqRAFtGp2 Xn7A== X-Gm-Message-State: ACgBeo2tMHkRI/VXfET8PAL9Wohu1dEkho+6Rrk82yjnsV4Fs98IxXFt 0KwjG1ed+cQ3D/BitNG2CZWsMMjChXMwjIxY/9CX0w== X-Received: by 2002:a05:6808:150f:b0:343:3202:91cf with SMTP id u15-20020a056808150f00b00343320291cfmr5737538oiw.112.1660332443800; Fri, 12 Aug 2022 12:27:23 -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:27:12 -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); > > > > -- > > 2.27.0 > >