Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1806113pxb; Fri, 10 Sep 2021 14:37:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqJtbjYt6ZVWpDVShInBnOB5nWx87ilsOgizQAaKuQ1omM/GTC5Ey0HcmwIfA2pi8Dm1yW X-Received: by 2002:a17:906:a0c:: with SMTP id w12mr11336461ejf.376.1631309878776; Fri, 10 Sep 2021 14:37:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631309878; cv=none; d=google.com; s=arc-20160816; b=lrzGhPK6AQwVavHx9cK+Cr9MwL2aMe0vfOLvU+wPZMWeyXr+DgibGYZBPhLVH9UNNL BU65XH9OIVHV7OsjBRBMqQAD7+bf6SZwF0W4CfkHEcyvRz2th0M8IUCgmmRMDklR/TOL mY6acq3cbDXMy0ivxytwi9idFp3hqyd1dDmKVS4YI5NEQT22BQ2RKpwBmBWqz/Hofmzn lPeP9nLBQY/NoTtfR1JYoMyUl+5mvwo+rc7NqF+1J6G6iaCVD3fxqq4FEOm2zpk1Rq4g nLsouK2t39XKqnSbH7gMKRt8sXlwwVJmHU60MAkA0hg+MzHOa8FJGwsgNwnry9S5OcQL DySg== 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=osMYYNGSd/Wjj+GEQ9AnjZzDNQa5kCk+UK3hUXrWsLk=; b=CGLvQeWIUfuhFQ7J/w05F4socv4LMlfVmh24ROqU4cnDF2Ux5ulnGRJMklPkZkxFwj N0vAydl7wHm98YfRTcrsRNfwuVn46WV0iE8oUeG7HEdkWXFQTxt3gpyNagNS9Gd8BiI1 HN0i09nV7rh8BjcZFAE1XosqHS6xoNccCLeuNGWZwbxb7WqZYHe6nlpseafp9xja3AEK oa+Knq8eurCJH8klgZq1Cl1O4nCkWnC+41vJ+3SJkiKCM7QmlI1wG33ERID5GXZBtdeq vg5PluN2XQPzpXq74QtGcC+YbTcu/N90DkAP1OnWNEVBtRO0qdxz6iYyw600YiR3r9Pr dZRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=IXUbRyP+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id de4si4256945ejc.615.2021.09.10.14.37.34; Fri, 10 Sep 2021 14:37:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=IXUbRyP+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S234539AbhIJVhP (ORCPT + 99 others); Fri, 10 Sep 2021 17:37:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230010AbhIJVhL (ORCPT ); Fri, 10 Sep 2021 17:37:11 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67A2AC061756 for ; Fri, 10 Sep 2021 14:36:00 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id n30so339863pfq.5 for ; Fri, 10 Sep 2021 14:36:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=osMYYNGSd/Wjj+GEQ9AnjZzDNQa5kCk+UK3hUXrWsLk=; b=IXUbRyP+p3BXmkawxfs/aq7YDdpzZnyWexYE0UEPyjiWqxO3uGv9NI9++wqMbnMmdH 3URAQ0FTb3EoySjHEvif6yG26N0NTBuDCOa0+xUMSoL1kD8TWU+Cvqyf8ztuC8N+f2TB EGHCxLcoAtBYIBEsTVA6wx+OPCFIWJzjQgsQEeIAqAXb0WPjXJVNzmcFkrBbEqAQguNF VRrrFmw43kb02a+KMCmooXTiiOhguXeBswP4JApCFDBI1lH40MlwzKc+OGWsuMJgK+or jUGOgbz+BaUESiviGAL6LjfDuVwnplOX94CrlNPxus1lFxQudezL9FmIk0zlXa/v58sV q1OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=osMYYNGSd/Wjj+GEQ9AnjZzDNQa5kCk+UK3hUXrWsLk=; b=tFhq3g123I/Rrp03Le+755SXVYhXF+BDnO/vy64C/PiWX9uo9C3I8RhDoeR6zJdCN6 dlpK9VfCQJ+/Qg60UN0HSTM7foT/qveBIgErfNwr2ZRaL/aUzyC2mMwKburBggejX1wl t4YwyceFuxaMzhBYYBzYmdiqFkrdzdOPCggTg2jqZoi3fipZGzipObf0yqqQ7pZi2c5I 6cS+uMPk4Z8gOX3PXRziPXltYAyFtADQjHMaUY94ZDxH5BnsKu5yYXDcw5GUA4PpfQq+ V7TClbIfY3CopER5yVsG1ZFLij/26RWe8LarABf4kSzPYU/jrMyQFVyvXcwmVzDNv12+ YSSg== X-Gm-Message-State: AOAM530f7AO9Rb8gudvDcnZQJ5eMLcd8u4EYdqk9hzxxdFzrsNHhj6eD iaFMkfQhZR2opWR3SKUElLHpmg== X-Received: by 2002:a05:6a00:814:b0:40d:563a:a7ce with SMTP id m20-20020a056a00081400b0040d563aa7cemr10118324pfk.60.1631309759677; Fri, 10 Sep 2021 14:35:59 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id h16sm5826014pfn.215.2021.09.10.14.35.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 14:35:59 -0700 (PDT) Date: Fri, 10 Sep 2021 21:35:55 +0000 From: Sean Christopherson To: Zeng Guang Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, Dave Hansen , Tony Luck , Kan Liang , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Kim Phillips , Jarkko Sakkinen , Jethro Beekman , Kai Huang , x86@kernel.org, linux-kernel@vger.kernel.org, Robert Hu , Gao Chao , Robert Hoo Subject: Re: [PATCH v4 3/6] KVM: VMX: Detect Tertiary VM-Execution control when setup VMCS config Message-ID: References: <20210809032925.3548-1-guang.zeng@intel.com> <20210809032925.3548-4-guang.zeng@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210809032925.3548-4-guang.zeng@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 09, 2021, Zeng Guang wrote: > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index 927a552393b9..ee8c5664dc95 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -2391,6 +2391,23 @@ static __init int adjust_vmx_controls(u32 ctl_min, u32 ctl_opt, > return 0; > } > > +static __init int adjust_vmx_controls_64(u64 ctl_min, u64 ctl_opt, > + u32 msr, u64 *result) > +{ > + u64 vmx_msr; > + u64 ctl = ctl_min | ctl_opt; > + > + rdmsrl(msr, vmx_msr); > + ctl &= vmx_msr; /* bit == 1 means it can be set */ > + > + /* Ensure minimum (required) set of control bits are supported. */ > + if (ctl_min & ~ctl) > + return -EIO; > + > + *result = ctl; > + return 0; > +} More succinctly, since we don't need to force-set bits in the final value: u64 allowed1; rdmsrl(msr, allowed1); /* Ensure minimum (required) set of control bits are supported. */ if (ctl_min & ~allowed1) return -EIO; *result = (ctl_min | ctl_opt) & allowed1; return 0; > static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, > struct vmx_capability *vmx_cap) > {