All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
	dave.hansen@intel.com, luto@kernel.org, peterz@infradead.org
Cc: sathyanarayanan.kuppuswamy@linux.intel.com, aarcange@redhat.com,
	ak@linux.intel.com, dan.j.williams@intel.com, david@redhat.com,
	hpa@zytor.com, jmattson@google.com, seanjc@google.com,
	thomas.lendacky@amd.com, brijesh.singh@amd.com, x86@kernel.org,
	linux-kernel@vger.kernel.org,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Subject: [PATCH 3/4] x86/coco: Explicitly declare type of confidential computing platform
Date: Tue, 22 Feb 2022 21:57:39 +0300	[thread overview]
Message-ID: <20220222185740.26228-4-kirill.shutemov@linux.intel.com> (raw)
In-Reply-To: <20220222185740.26228-1-kirill.shutemov@linux.intel.com>

Kernel derives type of confidential computing platform from sme_me_mask
value and hv_is_isolation_supported(). This detection process will be
more complicated as more platforms get added.

Declare confidential computing vendor explicitly via cc_set_vendor().

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
---
 arch/x86/coco/core.c               | 29 +++++++++++++++++------------
 arch/x86/include/asm/coco.h        | 14 ++++++++++++++
 arch/x86/kernel/cpu/mshyperv.c     |  3 +++
 arch/x86/mm/mem_encrypt_identity.c | 11 +++++++----
 4 files changed, 41 insertions(+), 16 deletions(-)
 create mode 100644 arch/x86/include/asm/coco.h

diff --git a/arch/x86/coco/core.c b/arch/x86/coco/core.c
index 6a6ffcd978f6..476dcd198af5 100644
--- a/arch/x86/coco/core.c
+++ b/arch/x86/coco/core.c
@@ -9,18 +9,15 @@
 
 #include <linux/export.h>
 #include <linux/cc_platform.h>
-#include <linux/mem_encrypt.h>
 
-#include <asm/mshyperv.h>
+#include <asm/coco.h>
 #include <asm/processor.h>
 
-static bool __maybe_unused intel_cc_platform_has(enum cc_attr attr)
+static enum cc_vendor vendor __ro_after_init;
+
+static bool intel_cc_platform_has(enum cc_attr attr)
 {
-#ifdef CONFIG_INTEL_TDX_GUEST
-	return false;
-#else
 	return false;
-#endif
 }
 
 /*
@@ -74,12 +71,20 @@ static bool hyperv_cc_platform_has(enum cc_attr attr)
 
 bool cc_platform_has(enum cc_attr attr)
 {
-	if (sme_me_mask)
+	switch (vendor) {
+	case CC_VENDOR_AMD:
 		return amd_cc_platform_has(attr);
-
-	if (hv_is_isolation_supported())
+	case CC_VENDOR_INTEL:
+		return intel_cc_platform_has(attr);
+	case CC_VENDOR_HYPERV:
 		return hyperv_cc_platform_has(attr);
-
-	return false;
+	default:
+		return false;
+	}
 }
 EXPORT_SYMBOL_GPL(cc_platform_has);
+
+__init void cc_set_vendor(enum cc_vendor v)
+{
+	vendor = v;
+}
diff --git a/arch/x86/include/asm/coco.h b/arch/x86/include/asm/coco.h
new file mode 100644
index 000000000000..e49f9ddb6ae6
--- /dev/null
+++ b/arch/x86/include/asm/coco.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_X86_COCO_H
+#define _ASM_X86_COCO_H
+
+enum cc_vendor {
+	CC_VENDOR_NONE,
+	CC_VENDOR_AMD,
+	CC_VENDOR_HYPERV,
+	CC_VENDOR_INTEL,
+};
+
+void cc_set_vendor(enum cc_vendor v);
+
+#endif /* _ASM_X86_COCO_H */
diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index 5a99f993e639..c1c0123859b9 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -33,6 +33,7 @@
 #include <asm/nmi.h>
 #include <clocksource/hyperv_timer.h>
 #include <asm/numa.h>
+#include <asm/coco.h>
 
 /* Is Linux running as the root partition? */
 bool hv_root_partition;
@@ -344,6 +345,8 @@ static void __init ms_hyperv_init_platform(void)
 		 */
 		swiotlb_force = SWIOTLB_FORCE;
 #endif
+		if (hv_get_isolation_type() != HV_ISOLATION_TYPE_NONE)
+			cc_set_vendor(CC_VENDOR_HYPERV);
 	}
 
 	if (hv_max_functions_eax >= HYPERV_CPUID_NESTED_FEATURES) {
diff --git a/arch/x86/mm/mem_encrypt_identity.c b/arch/x86/mm/mem_encrypt_identity.c
index 3f0abb403340..06314ae3998e 100644
--- a/arch/x86/mm/mem_encrypt_identity.c
+++ b/arch/x86/mm/mem_encrypt_identity.c
@@ -44,6 +44,7 @@
 #include <asm/setup.h>
 #include <asm/sections.h>
 #include <asm/cmdline.h>
+#include <asm/coco.h>
 
 #include "mm_internal.h"
 
@@ -565,8 +566,7 @@ void __init sme_enable(struct boot_params *bp)
 	} else {
 		/* SEV state cannot be controlled by a command line option */
 		sme_me_mask = me_mask;
-		physical_mask &= ~sme_me_mask;
-		return;
+		goto out;
 	}
 
 	/*
@@ -600,6 +600,9 @@ void __init sme_enable(struct boot_params *bp)
 		sme_me_mask = 0;
 	else
 		sme_me_mask = active_by_default ? me_mask : 0;
-
-	physical_mask &= ~sme_me_mask;
+out:
+	if (sme_me_mask) {
+		physical_mask &= ~sme_me_mask;
+		cc_set_vendor(CC_VENDOR_AMD);
+	}
 }
-- 
2.34.1


  parent reply	other threads:[~2022-02-22 18:57 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-22 18:57 [PATCH 0/4] x86: Cleanup and extend computing computing API Kirill A. Shutemov
2022-02-22 18:57 ` [PATCH 1/4] x86/hyperv: Add missing ARCH_HAS_CC_PLATFORM dependency Kirill A. Shutemov
2022-02-22 20:08   ` Borislav Petkov
2022-02-23  7:04     ` Tianyu Lan
2022-02-23 10:41       ` Borislav Petkov
2022-02-23 10:43         ` Tianyu Lan
2022-02-23 10:56           ` Borislav Petkov
2022-02-23 11:02             ` Tianyu Lan
2022-02-23 11:47               ` Kirill A. Shutemov
2022-02-23 14:09                 ` Tianyu Lan
2022-02-23 15:46                   ` Kirill A. Shutemov
2022-02-22 18:57 ` [PATCH 2/4] x86: Rename cc_platform.c to arch/x86/coco/core.c Kirill A. Shutemov
2022-02-22 20:52   ` Borislav Petkov
2022-02-24 11:59   ` [tip: x86/cc] x86/cc: Move arch/x86/{kernel/cc_platform.c => coco/core.c} tip-bot2 for Kirill A. Shutemov
2022-02-22 18:57 ` Kirill A. Shutemov [this message]
2022-02-24 11:59   ` [tip: x86/cc] x86/coco: Explicitly declare type of confidential computing platform tip-bot2 for Kirill A. Shutemov
2022-02-22 18:57 ` [PATCH 4/4] x86/coco: Add API to handle encryption mask Kirill A. Shutemov
2022-02-24 11:59   ` [tip: x86/cc] " tip-bot2 for Kirill A. Shutemov
2022-02-22 21:56 ` [PATCH 0/4] x86: Cleanup and extend computing computing API Tom Lendacky
2022-02-23  4:35 ` [PATCH] x86/mm/cpa: Generalize __set_memory_enc_pgtable() Brijesh Singh
2022-02-23 11:31   ` Borislav Petkov
2022-02-23 11:55     ` Kirill A. Shutemov
2022-02-23 12:13       ` Borislav Petkov
2022-02-23 12:25         ` Kirill A. Shutemov
2022-02-23 12:38           ` Borislav Petkov
2022-02-23 12:54             ` Kirill A. Shutemov
2022-02-23 14:33             ` Brijesh Singh
2022-02-24 11:59   ` [tip: x86/cc] " tip-bot2 for Brijesh Singh
2022-02-23 19:10 ` [PATCH 0/4] x86: Cleanup and extend computing computing API Borislav Petkov
2022-02-23 19:17   ` [PATCH 1/4] x86/cc: Move arch/x86/{kernel/cc_platform.c => coco/core.c} Borislav Petkov
2022-02-23 19:17   ` [PATCH 2/4] x86/coco: Explicitly declare type of confidential computing platform Borislav Petkov
2022-02-23 19:17   ` [PATCH 3/4] x86/coco: Add API to handle encryption mask Borislav Petkov
2022-02-23 19:17   ` [PATCH 4/4] x86/mm/cpa: Generalize __set_memory_enc_pgtable() Borislav Petkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220222185740.26228-4-kirill.shutemov@linux.intel.com \
    --to=kirill.shutemov@linux.intel.com \
    --cc=aarcange@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=bp@alien8.de \
    --cc=brijesh.singh@amd.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.hansen@intel.com \
    --cc=david@redhat.com \
    --cc=hpa@zytor.com \
    --cc=jmattson@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=sathyanarayanan.kuppuswamy@linux.intel.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=thomas.lendacky@amd.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.