Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp29689pxb; Fri, 17 Sep 2021 17:48:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFWf11EdYkY5gh29Zg2YO+umziL0CnkBO0UqhdVgrZ4/9eAUSQAfMTT18NZKrHiRImLqcd X-Received: by 2002:a50:d4dc:: with SMTP id e28mr15242132edj.106.1631926097895; Fri, 17 Sep 2021 17:48:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631926097; cv=none; d=google.com; s=arc-20160816; b=avl7mFPtgiCR3tK1+ithyYIIO3fe+rh4uFd4FdhKKsXNcSVMJ/8QHZvpsc5JF0MB+R gPxM0MpVkZegDZZTVW+BEwO6Fb97BNL9pkMwmUEL9xF2ZIl94RMnTDeFRTvVyphoKCmu gIjiYyxUjFTucfIILRKTOQKmjTEoSlb/oKzmOPsmnRQVuJea1seWYg+wnnGGFr/UwNNY K1ckPaij4yRADmDnkQUJ34Tik75JE7v8+lqWroW8L3ug7dzkO1cM89/N3s58vwH+SYpd 3+eA+9+6FHGKx9a2GPSp7bgem64UEnK2efuv4IEVn05uTLXR8GBnvEgb9HD6nKnyoh6j C2Hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=w8inP5QaNnV7t494RTE/RO6uBQ0Vpm4F5Xrhxrs6CHM=; b=MWwoM6nZ/05Er35Ir+8P6UmAkfBdeXw3xEFpS2ow9qw6Y1rX/8DzobzQqxDBr7ZLEj MfFZU0DXbqSQ3sSFNlDj3Wbfav+k72/pP9w2LyBiRmAP4hZrbdV58kNiUyoXa4ZmY90C 5ATn6i6ztf8Yt2gSB/sVZ4Rx4tsJeAjrUEkQ6yc1LBH4Cu+BGtVud2VfepqoRtR6iFqQ Snp3JOS8ty989O7StavbLp2zdOkznQC5uqzb+/GChF8V4uzANM9rEgna1tjrR8rT+7mO VYicDDnZtra859y0Y3Nqz979Hnm7EbdMb7wufg0Vvf/Y20u9XasfbOWN/NvwLfIpNkdt Kz4A== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cr15si1076819ejc.470.2021.09.17.17.47.54; Fri, 17 Sep 2021 17:48:17 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243366AbhIQQRZ (ORCPT + 99 others); Fri, 17 Sep 2021 12:17:25 -0400 Received: from mga02.intel.com ([134.134.136.20]:26386 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242090AbhIQQRU (ORCPT ); Fri, 17 Sep 2021 12:17:20 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10110"; a="210059600" X-IronPort-AV: E=Sophos;i="5.85,301,1624345200"; d="scan'208";a="210059600" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Sep 2021 09:15:57 -0700 X-IronPort-AV: E=Sophos;i="5.85,301,1624345200"; d="scan'208";a="546478915" Received: from zengguan-mobl.ccr.corp.intel.com (HELO [10.254.208.219]) ([10.254.208.219]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Sep 2021 09:15:52 -0700 Subject: Re: [PATCH v4 3/6] KVM: VMX: Detect Tertiary VM-Execution control when setup VMCS config To: Sean Christopherson Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , "kvm@vger.kernel.org" , Dave Hansen , "Luck, Tony" , Kan Liang , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Kim Phillips , Jarkko Sakkinen , Jethro Beekman , "Huang, Kai" , "x86@kernel.org" , "linux-kernel@vger.kernel.org" , "Hu, Robert" , "Gao, Chao" , Robert Hoo References: <20210809032925.3548-1-guang.zeng@intel.com> <20210809032925.3548-4-guang.zeng@intel.com> From: Zeng Guang Message-ID: <60d6f343-058a-5fbe-5265-ccb38689bb93@intel.com> Date: Sat, 18 Sep 2021 00:15:50 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/11/2021 5:35 AM, Sean Christopherson wrote: > 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; Yes, it becomes more concise. I will change it . Thanks. >> static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, >> struct vmx_capability *vmx_cap) >> {