Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp235738rwb; Wed, 14 Dec 2022 16:39:09 -0800 (PST) X-Google-Smtp-Source: AA0mqf7q0BluqonEi1O0o0DTuudb7B6K75/FaPJtiwm7gJePB6ZB1bLur41QLDzgo45q8OGuck+u X-Received: by 2002:a62:33c4:0:b0:56c:7216:fbc6 with SMTP id z187-20020a6233c4000000b0056c7216fbc6mr23334703pfz.30.1671064749558; Wed, 14 Dec 2022 16:39:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671064749; cv=none; d=google.com; s=arc-20160816; b=W5Y1Lrhn/loTgQOWhNVaHEnra5xaU+9BFR6Wj9XEvz2aniIjF8Zy2h8WgpWEsJYFsJ uDFV6ZYqGPCtNfG95cbEXS8Y2WAWvnCaMcATuVNPjQuSeUi4v4FgttAOzF0scTzhcEyx 8gAMXXTdPjF050ugDoystdIBGleOHF7BWM8XeEKyC6sfPDrVadV+9XxMSsNV7xNFdrtJ 0z50rmwCHzx2C1pZ5xyMTVNRnGmBNvanMcGdbgnwe0+RLU9BzwFSydJ6w/lXPhcr1LCp EVD1tFeIyJd/fmhkDxtY8b0WT91IiRMzFUuE5/BGRlSQOsVDkgXJadMrsXkJieNrIARJ ZRVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=VfaOSQ2xG8DIX0I09VkRkjUWo+7u1oLgyWYfkHD5CW8=; b=fwQe3h5Qz9H2WQtxi9jr1J7viO+jl9FUdE+fjd2JOvcbq+Tu0El6VIZbHoGpzkNO+b GYRzjOS9NF7pXsc01IWkyxy2dntfX0x68YDt8bws70B6nWDGSnpdWNsh0Jsl41HQwoG9 IrayFXBh2mSxgSCq8qE9DZf+2DcyrxlJ+Q3G0CzT6xRUREtO9uR51o9ju6vpjj3meoxy /9mxTjUcT68Z80reDKtDPkyazImaK2WLofpSjKyLtPsNhGzIL3fdV5jccHUsmjH9n/LH thm2k0vDVuwF4RaNHNyg4mHoI8noPpH3vrMiYxE3DAWLOo5dbNPDK6JZUUMxDPTqG6Wa pBkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=X4tD6tmg; 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 z2-20020a056a00240200b0057731e4f624si1336279pfh.83.2022.12.14.16.39.00; Wed, 14 Dec 2022 16:39:09 -0800 (PST) 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=X4tD6tmg; 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 S230178AbiLOATu (ORCPT + 69 others); Wed, 14 Dec 2022 19:19:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229718AbiLOATD (ORCPT ); Wed, 14 Dec 2022 19:19:03 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5681F0C for ; Wed, 14 Dec 2022 16:18:38 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id z8-20020a17090abd8800b00219ed30ce47so1016747pjr.3 for ; Wed, 14 Dec 2022 16:18:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=VfaOSQ2xG8DIX0I09VkRkjUWo+7u1oLgyWYfkHD5CW8=; b=X4tD6tmgrNH2TDpX4AlIvBGdOre7Ry0pC56VGpdfGcJ9/gg+ixgN1gsHXAfGs9R1kf 0D05tyqtriMul8D7dSCDnzbfcNoYes7aR/4pECmX1wY/7J5qbkEKSHmutnR+RsIlbxBr enDNJYveWpbRsvGxAd7jA2gwFIgt4iVf0175YjDl/fQJKaRtx/9akHM3ME6sm+Eeuabl UP1ulkUZ3s4JeocRnljEYaCcjol+OGKTKdJqvMzFVFM5LNMTptsWE54oV2auFokBV9J9 qPbGaXykmPUAd5N0q9uytv8tqLWI8MD3OoF7rE5haY58FkOwt3izOrtjMHV5werBFq3U +ZbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=VfaOSQ2xG8DIX0I09VkRkjUWo+7u1oLgyWYfkHD5CW8=; b=iSJ8C69DzCPOApvLnxYDz5HFD5V+cb5gx8vh0JAjPCUQ4mDx1vGHe5sr3Wz+J7iRY4 CdiQrgbULwskDxUqAqZ1tkX4mjKCrbHXLMrScbbVrsnAcGSvTxFas8HZNUk5VH3RRIsb knXtOqUR7npsXTptgo8w4GSMANSbg/NQ0t4R/RLZjSrsvcNvMt/HHn35Vincw4CpRUYe 5E/+HE42ZP+/PY4yldwAS7k3Bs1rBhu1NdEuxiDsLjVo55Z2nEIRIOX+sPxLpL4oE1mU fdPnExssTXE1zQV14kbibwfyeBzSd42oL3A+PzENMAAk00WkZ0s8hOxMBGd1I2O031Ni V1pQ== X-Gm-Message-State: AFqh2kp7egOSA3x3JPQkLdnXByCGIkysjR3ae/S+qmI/IgqlYIqySPt9 /+stQjf8qxMHFiMlAJD4BVzQs0I+vt+2GwjD X-Received: by 2002:a17:903:18e:b0:189:6624:58c0 with SMTP id z14-20020a170903018e00b00189662458c0mr792919plg.3.1671063518250; Wed, 14 Dec 2022 16:18:38 -0800 (PST) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id g1-20020a170902c38100b00187197c499asm2406961plg.164.2022.12.14.16.18.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Dec 2022 16:18:37 -0800 (PST) Date: Thu, 15 Dec 2022 00:18:33 +0000 From: Sean Christopherson To: Yu Zhang Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Aaron Lewis Subject: Re: [PATCH v2 0/4] KVM: nVMX: Fix 2nd exec controls override goofs Message-ID: References: <20221213062306.667649-1-seanjc@google.com> <20221214030037.4qz6v6fvfx6of32n@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221214030037.4qz6v6fvfx6of32n@linux.intel.com> 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, 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 Wed, Dec 14, 2022, Yu Zhang wrote: > On Tue, Dec 13, 2022 at 06:23:02AM +0000, Sean Christopherson wrote: > > Fix bugs in KVM's (mis)handling of secondary execution controls. > > > > KVM overrides the secondary execution control VMX MSR during KVM_SET_CPUID. > > Similar to the somewhat recent reverts > > > > 8805875aa473 ("Revert "KVM: nVMX: Do not expose MPX VMX controls when guest MPX disabled"") > > 9389d5774aca ("Revert "KVM: nVMX: Expose load IA32_PERF_GLOBAL_CTRL VM-{Entry,Exit} control"") > > > > undo misguided KVM behavior where KVM overrides allowed-1 settings in the > > secondary execution controls in response to changes to the guest's CPUID > > model. To avoid breaking userspace that doesn't take ownership of the > > VMX MSRs, go hands off if and only if userpace sets the MSR in question. > > > > Before fixing that, fix another bug it was hiding where the umwait/tpause > > control was being exposed to L1 for nVMX only after KVM_SET_CPUID, and > > harden KVM against similar bugs in the future. > > > > v2: Fix the ENABLE_USR_WAIT_PAUSE bug too. [Aaron] > > > > v1: https://lore.kernel.org/all/20221110005706.1064832-1-seanjc@google.com > > > > Sean Christopherson (4): > > KVM: nVMX: Properly expose ENABLE_USR_WAIT_PAUSE control to L1 > > KVM: nVMX: Don't stuff secondary execution control if it's not > > supported > > KVM: nVMX: Don't muck with allowed sec exec controls on CPUID changes > > KVM: selftests: Test KVM's handling of VMX's sec exec MSR on > > KVM_SET_CPUID > > BTW, we may need another patch to remove the obsolete comments in > nested_vmx_setup_ctls_msrs(): Ouch, indeed. Want to send a proper patch? Or provide your SoB and I'll write a changelog? The comment was added by commit 80154d77c922 ("KVM: VMX: cache secondary exec controls"), but arguably the below is the appropriate Fixes, as it's the commit that fixed the existing cases where KVM didn't enumerate supported-but-conditional controls. Fixes: 6defc591846d ("KVM: nVMX: include conditional controls in /dev/kvm KVM_GET_MSRS") > diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c > index b6f4411b613e..42ceddcafd3e 100644 > --- a/arch/x86/kvm/vmx/nested.c > +++ b/arch/x86/kvm/vmx/nested.c > @@ -6854,11 +6854,6 @@ void nested_vmx_setup_ctls_msrs(struct vmcs_config *vmcs_conf, u32 ept_caps) > msrs->procbased_ctls_low &= > ~(CPU_BASED_CR3_LOAD_EXITING | CPU_BASED_CR3_STORE_EXITING); > > - /* > - * secondary cpu-based controls. Do not include those that > - * depend on CPUID bits, they are added later by > - * vmx_vcpu_after_set_cpuid. > - */ > msrs->secondary_ctls_low = 0; > > msrs->secondary_ctls_high = vmcs_conf->cpu_based_2nd_exec_ctrl; > > B.R. > Yu