From patchwork Wed Jul 19 14:41:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Binbin Wu X-Patchwork-Id: 13319069 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D529C0015E for ; Wed, 19 Jul 2023 14:41:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231405AbjGSOlz (ORCPT ); Wed, 19 Jul 2023 10:41:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231389AbjGSOlu (ORCPT ); Wed, 19 Jul 2023 10:41:50 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAB2F171D; Wed, 19 Jul 2023 07:41:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689777704; x=1721313704; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Uh0yjAnR4cEuJzdK/Be8m4hQOV6Rgcwh/xcJkz0LoDE=; b=SnADuKLsJ7qv7FLoQznDQSbEAnVXxvkciAw6roq/Rw+fb3BTj623LhwB ZqpnKIpnmhIsZ6UrX3TLKWZ+Vyu7l5uV53a1XBQy9PLpON+fYn5I7uGkl xiyXdkO/YNYywItGB4WCJWrCm/v750jnFMSNGnnOjC8Dw9cYEDjAcYLpl Oql83b+41lFgbNnalLZKhwKMRZC+OEmeXxbowwWBGDl1AFnkdatvWzu1H tAvbR7KYYqLpkuYMIVeiBrfst0310zFXhcKRIvkrA+qhgyO+Fjn/WZ74U ZpVRS/tz+FpyAZbHNpyvm+2oZyeKvGEcCjotTnFkMLEiCqBPHXWshMFAg A==; X-IronPort-AV: E=McAfee;i="6600,9927,10776"; a="346788159" X-IronPort-AV: E=Sophos;i="6.01,216,1684825200"; d="scan'208";a="346788159" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jul 2023 07:41:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="867503272" Received: from binbinwu-mobl.ccr.corp.intel.com ([10.249.173.69]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jul 2023 07:41:42 -0700 From: Binbin Wu To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: seanjc@google.com, pbonzini@redhat.com, chao.gao@intel.com, kai.huang@intel.com, David.Laight@ACULAB.COM, robert.hu@linux.intel.com, guang.zeng@intel.com, binbin.wu@linux.intel.com Subject: [PATCH v10 3/9] KVM: x86: Use KVM-governed feature framework to track "LAM enabled" Date: Wed, 19 Jul 2023 22:41:25 +0800 Message-Id: <20230719144131.29052-4-binbin.wu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230719144131.29052-1-binbin.wu@linux.intel.com> References: <20230719144131.29052-1-binbin.wu@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Use the governed feature framework to track if Linear Address Masking (LAM) is "enabled", i.e. if LAM can be used by the guest. So that guest_can_use() can be used to support LAM virtualization. LAM modifies the checking that is applied to 64-bit linear addresses, allowing software to use of the untranslated address bits for metadata and masks the metadata bits before using them as linear addresses to access memory. Signed-off-by: Binbin Wu --- arch/x86/kvm/governed_features.h | 2 ++ arch/x86/kvm/vmx/vmx.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/arch/x86/kvm/governed_features.h b/arch/x86/kvm/governed_features.h index 40ce8e6608cd..708578d60e6f 100644 --- a/arch/x86/kvm/governed_features.h +++ b/arch/x86/kvm/governed_features.h @@ -5,5 +5,7 @@ BUILD_BUG() #define KVM_GOVERNED_X86_FEATURE(x) KVM_GOVERNED_FEATURE(X86_FEATURE_##x) +KVM_GOVERNED_X86_FEATURE(LAM) + #undef KVM_GOVERNED_X86_FEATURE #undef KVM_GOVERNED_FEATURE diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 0ecf4be2c6af..ae47303c88d7 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7783,6 +7783,9 @@ static void vmx_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) vmx->msr_ia32_feature_control_valid_bits &= ~FEAT_CTL_SGX_LC_ENABLED; + if (boot_cpu_has(X86_FEATURE_LAM)) + kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_LAM); + /* Refresh #PF interception to account for MAXPHYADDR changes. */ vmx_update_exception_bitmap(vcpu); }