Received: by 2002:a05:7412:2a8a:b0:fc:a2b0:25d7 with SMTP id u10csp477109rdh; Wed, 7 Feb 2024 10:04:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IGUe/FuuA0sV2Z45FwwXUFZaAInI6/NTxWrJoEo7VHxTf0JDBrVX4N35h/DVerIORBE8QlI X-Received: by 2002:a2e:9417:0:b0:2d0:aa66:43de with SMTP id i23-20020a2e9417000000b002d0aa6643demr4362228ljh.1.1707329047409; Wed, 07 Feb 2024 10:04:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707329047; cv=pass; d=google.com; s=arc-20160816; b=aqA1HtP9UikgS6zA2XvGMiFDpDUIdAv/mOwuPCrMp81dZBe9zDj+rwz3FaKlEMB56d YjPBdjinsCP0EeCmMz+39yvcrk4kTahjHEKg+EQqYvJCnx9fRvWGodCiIonCFTGrhS56 7LrrkUm5NiV6F5wS9u458iwZQFXdsm4IL3evph79UT+8gfFmovrZd/wOy0A+TJTIMaVs eezv6ncmSk4pL7j3gQ61keI6AG6JBnPRE0EBkGfEmrg25vV52eZtVL728cJXFpC5GmnO za/jG6krwQ0TK1SsfskGiRRcXHn7xwBndzKZUBl7OQkBnxJRKW5EiJGao2aZk4Unp4bc No3g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ItYiO89XXonjbBMGkjDbXnR4McxkibpxA64VrR7S6jg=; fh=krr8DAL6NLvr2jzahfqIvrqSKh3uL4mHE8Bbk9PhVrs=; b=Lf6lhk+fXKP+8m3tZv973Mh2hnvxkRRci4dcV/zJ0wfCXiP4n9/gUge10yboCNATag 6hLsyWrWHAy85V8dU9eYdguVg15Bx2H8vJbFH366iSYS0jj//qQL5On0QvE+yeuWOCJP J3hCk0dLlYWmXSlHJxbFE+29tVQ2NhpsFb21ebXgVy4BRDxbbXBnRj4Mrt9/RC5kcQj+ VBQBU7MMs8d1556DF43eyIvEEbD3D3Lp2eFd4GBidp3qDqna+uN2FenLDlUn1pm/mVSA l6CJQeGI6iLUIlAzHHvbr5q/MLYyh1AFngNR5kzU3Oh3SFk2vKHuT+JYz7OozPYpkMgz 1w2g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OCB9h80F; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-56866-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56866-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCVR/kUeLAFTF5WD3qqYUy1F+Te14zsS62awMo6BSHFMRRbD4/xt1m3wEQXg2Z2E1QC7Z1960Ktq3Fdmesu68YPZC7xCjoOofLgv0xt0CQ== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id y24-20020aa7c258000000b0055a38adfcd5si1098684edo.547.2024.02.07.10.04.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 10:04:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56866-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OCB9h80F; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-56866-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56866-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 2908A1F2145B for ; Wed, 7 Feb 2024 18:04:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7A6A612D749; Wed, 7 Feb 2024 17:59:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="OCB9h80F" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D10E127B40; Wed, 7 Feb 2024 17:59:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707328754; cv=none; b=NhpX6zDodKTMSnKnai/ywGt+We0mUna8mztBlNTB1Pwjwsykf6FU96a/uFf88XzvRadnkCA35VbF/FjiXSbzPJRzxXs608/FN5Hk3wifXjycZLmoTdt/whdKisAWWf1UIprwK6eqlhOPSq2MH4o5cWr9US3Y7HBVpjsmvqNgCcI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707328754; c=relaxed/simple; bh=yTi4kr3PlzXNPrwqknVaKsYqhBkec/CNGRO3VuNenIU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D128TCLDPMq5OzUb+E8n/Nz0S6jcS2Kv9j6EOygWpihi5cpIMSfwMLzoPksuDe/un7MgeaZmXZYtGvmdiUpA3a39hP0jNZjosR+15MzmVPocLhOcqr3o1IDykYnRL8egcKSwqJG0jte/dO8VhlO81zbTphxjwNABvaC6hgYhxUY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=OCB9h80F; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707328749; x=1738864749; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yTi4kr3PlzXNPrwqknVaKsYqhBkec/CNGRO3VuNenIU=; b=OCB9h80F7FAanD2ydW1HwX83AWeHVomZP1XI5gtKVGBrJ6QMXttwHb2+ Hed4Wl0a2WKc+5Kvf74/AsOfCe76wej4ZwEOPCqdNUk14GIljTH2GAXy0 wYhbpIb9sS7eD0W/hC1QtunqirRyCuGqbp+ZtpXpz7d0DI1g8WU97wc++ OCqNNm5+oaBk10c/CiwZiM54hjf4aUzKGFh2gyJLHC7kZQnTMSPXPHPiG vxrMGHwg3Dla5aS2vR68X2F7FQsGonot5rNn9DQse3lFLguRlhI0QC44t qnZWsrdftvuP7K9o84sqA89HvThib+nmZ3tSgCwX6l1cNKen5s/zk+zM1 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10977"; a="11622567" X-IronPort-AV: E=Sophos;i="6.05,251,1701158400"; d="scan'208";a="11622567" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2024 09:58:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,251,1701158400"; d="scan'208";a="6020727" Received: from unknown (HELO fred..) ([172.25.112.68]) by fmviesa004.fm.intel.com with ESMTP; 07 Feb 2024 09:58:56 -0800 From: Xin Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: seanjc@google.com, pbonzini@redhat.com, corbet@lwn.net, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, shuah@kernel.org, vkuznets@redhat.com, peterz@infradead.org, ravi.v.shankar@intel.com, xin@zytor.com Subject: [PATCH v2 11/25] KVM: x86: Add kvm_is_fred_enabled() Date: Wed, 7 Feb 2024 09:26:31 -0800 Message-ID: <20240207172646.3981-12-xin3.li@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240207172646.3981-1-xin3.li@intel.com> References: <20240207172646.3981-1-xin3.li@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add kvm_is_fred_enabled() to get if FRED is enabled on a vCPU. Signed-off-by: Xin Li Tested-by: Shan Kang --- Change since v1: * Explain why it is ok to only check CR4.FRED (Chao Gao). --- arch/x86/kvm/kvm_cache_regs.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/arch/x86/kvm/kvm_cache_regs.h b/arch/x86/kvm/kvm_cache_regs.h index 75eae9c4998a..1d431c703fdf 100644 --- a/arch/x86/kvm/kvm_cache_regs.h +++ b/arch/x86/kvm/kvm_cache_regs.h @@ -187,6 +187,23 @@ static __always_inline bool kvm_is_cr4_bit_set(struct kvm_vcpu *vcpu, return !!kvm_read_cr4_bits(vcpu, cr4_bit); } +/* + * It's enough to check just CR4.FRED (X86_CR4_FRED) to tell if + * a vCPU is running with FRED enabled, because: + * 1) CR4.FRED can be set to 1 only _after_ IA32_EFER.LMA = 1. + * 2) To leave IA-32e mode, CR4.FRED must be cleared first. + * + * More details at FRED Spec 6.0 Section 4.2 Enabling in CR4. + */ +static __always_inline bool kvm_is_fred_enabled(struct kvm_vcpu *vcpu) +{ +#ifdef CONFIG_X86_64 + return kvm_is_cr4_bit_set(vcpu, X86_CR4_FRED); +#else + return false; +#endif +} + static inline ulong kvm_read_cr3(struct kvm_vcpu *vcpu) { if (!kvm_register_is_available(vcpu, VCPU_EXREG_CR3)) -- 2.43.0