From patchwork Wed Jan 24 14:02:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 191645 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp1106411dyi; Wed, 24 Jan 2024 08:32:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IH5EeNOB6BQCkTXeM3Qpu2RXkMrTJWPBGUjR1giJHQZrmUgkav1OF6852zpt3WDGA4dowCf X-Received: by 2002:a05:6a00:1da3:b0:6dd:9e8f:3f57 with SMTP id z35-20020a056a001da300b006dd9e8f3f57mr919070pfw.67.1706113957201; Wed, 24 Jan 2024 08:32:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706113957; cv=pass; d=google.com; s=arc-20160816; b=AzsQQTn+rGBTIMjve5thn5S5ZYBBRd400toQbiK4CFLlMXjhiSHPiCwOW3GCeoufYN HQxGZppD4o5jyxtOzlU7M7tbkreOZjNyBmmEcLLoTTiMn/1emIcQ1hlznIEMR52HlW+w vt14K5ZQ4CoFciocL0gYMO3iJJgRgvqF0C5A6DQENVnGYw5Z8C+BpVn/PTWxjlVo69c0 U6jyS0arDFAZietmnfzkrrGXWCSQ/z/eKnYRRtgOVnSevkVwr0oGQbi5+gU88uNRJAqc PTmmeTmleo822jv4z5w54IXuM3Qff8US51LzFjsn22ViFuKSjJ01o8zrHcIfJUzvXrHp YNkQ== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=PyOo/R/4zOp1mncjGw9rrHFC4pBK07Y+VKz6hwbKtak=; fh=e2OP1yM1F5redrYxqTJzQjOAuu/ynB/KeSpWJozAtdM=; b=ovZ7TZVeMG6VREQM+rK5rJS1QfibOw/AMySHD1lQv7UHrp9HTH3rywDYnP8TX/ZOte 6TcrnrYfPdph54TFPm7iEI01Jt/rWOMoIXx3f7ymmMsKHQK8gmJjvo12pS1P3uXFv2GC 3b7HPT7EHMFJnnBXohshLYf4SXAk7tvUyFhzWSeM0+56+8Mt+4QKESPlCtP458RIC4mS Ai+/XvsCfq1APAh/J3CmCKxV7Eg/xuIcvJrzkXa4IU4AUusRthlW2pyZY3SGXhSPOK4R 31gGZwScGLL7gtcPm4nnK2LEt7/G4olmkOzYcfa5i0E8xQhHDH8IooLTVey3dS8uyaCO 4U9Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Tr6kEbpZ; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-37084-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37084-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id y3-20020a63fa03000000b005cfbd190e58si8136414pgh.115.2024.01.24.08.32.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 08:32:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37084-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Tr6kEbpZ; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-37084-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37084-ouuuleilei=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 67B9DB28A12 for ; Wed, 24 Jan 2024 14:02:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BD9BA7A718; Wed, 24 Jan 2024 14:02:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Tr6kEbpZ" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) (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 7D4AC22084 for ; Wed, 24 Jan 2024 14:02:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.55.52.120 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706104948; cv=none; b=DfWZVuiDix65tP9XLHrJeScVdboB/qBERHa8U3gxIKFM8EuNLrOCMhInMzX5qUFqVzcB3r3MWpz+Y2rJWhkmi65TLlsj9jeipT+YdNdFSPi8psoDIROYQp8kRXjPKwLwA1ys120EmIFhBUgUOpXaaeXw4OUZuUkDr24AgoWQHWE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706104948; c=relaxed/simple; bh=kMLlSWZyVMHXVTtl/OfZFuYeY/EXz2BpA61dEoPloQE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=cehh4w7KTtXTZWHh2jKiqD+6lxOf9fVYkc2DWYIMkn2neBvejK7T1tU9wmseDEANKPygrYWGenuZprgbMTKqWNoSN0CREAkcDHcREnvowrR4b+jftf1mZCoyGaoi5X/ryO32vDqRS74TOaY03494wUNFtsfiK40FrQFk02zVDBA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.helo=mgamail.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Tr6kEbpZ; arc=none smtp.client-ip=192.55.52.120 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.helo=mgamail.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706104946; x=1737640946; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=kMLlSWZyVMHXVTtl/OfZFuYeY/EXz2BpA61dEoPloQE=; b=Tr6kEbpZzLlmIsMdpPOSNUoM+b23+pWULVRJsX7ScKqCzxSx24wRbL3a 8VV10f8ZQirSD0oWpolNRxEMSPwO/ZDiFLVGv9IvIHp5wAobrORi5OqBW xRfuMfxxkYouxD6T7YxcdN0/MivPMJPK9bUeiHnbSGXmJUcxPXd18yS03 NM9wpLZ35gPY5ZzRK1ChLm+kJp9wSQYMxehvtgHY+XrGz75n6w8Fy1JpU SNnL4khow/POMqY9o8WmhV/+QD2xb0ok3rjlsHAw8hQK6ZABDwS7Wg1CS 20SegcwfctVhiNNUeYQyL67mM0lDtNQCj8onpekplJbqu5XA+/AZtONHi w==; X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="400704262" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="400704262" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2024 06:02:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="909667796" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="909667796" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga004.jf.intel.com with ESMTP; 24 Jan 2024 06:02:21 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 2B41587; Wed, 24 Jan 2024 16:02:20 +0200 (EET) From: "Kirill A. Shutemov" To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen Cc: x86@kernel.org, "H. Peter Anvin" , Tom Lendacky , linux-kernel@vger.kernel.org, "Kirill A. Shutemov" , Jeremi Piotrowski , Kuppuswamy Sathyanarayanan , Kai Huang , Dexuan Cui Subject: [PATCHv2, RESEND] x86/mm: Fix memory encryption features advertisement Date: Wed, 24 Jan 2024 16:02:16 +0200 Message-ID: <20240124140217.533748-1-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788990148762360998 X-GMAIL-MSGID: 1788990148762360998 When memory encryption is enabled, the kernel prints the encryption flavor that the system supports. The check assumes that everything is AMD SME/SEV if it doesn't have the TDX CPU feature set. Hyper-V vTOM sets cc_vendor to CC_VENDOR_INTEL when it runs as L2 guest on top of TDX, but not X86_FEATURE_TDX_GUEST. Hyper-V only needs memory encryption enabled for I/O without the rest of CoCo enabling. To avoid confusion, check the cc_vendor directly. Possible alternative is to completely removing the print statement. For a regular TDX guest, the kernel already prints a message indicating that it is booting on TDX. Similarly, AMD and Hyper-V can also display a message during their enumeration process. Signed-off-by: Kirill A. Shutemov Reviewed-by: Jeremi Piotrowski Reviewed-by: Kuppuswamy Sathyanarayanan Acked-by: Tom Lendacky Acked-by: Kai Huang Cc: Dexuan Cui --- arch/x86/mm/mem_encrypt.c | 56 +++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index c290c55b632b..d035bce3a2b0 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -42,38 +42,42 @@ bool force_dma_unencrypted(struct device *dev) static void print_mem_encrypt_feature_info(void) { - pr_info("Memory Encryption Features active:"); + pr_info("Memory Encryption Features active: "); - if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) { - pr_cont(" Intel TDX\n"); - return; - } + switch (cc_vendor) { + case CC_VENDOR_INTEL: + pr_cont("Intel TDX\n"); + break; + case CC_VENDOR_AMD: + pr_cont("AMD"); - pr_cont(" AMD"); - - /* Secure Memory Encryption */ - if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT)) { + /* Secure Memory Encryption */ + if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT)) { /* * SME is mutually exclusive with any of the SEV * features below. - */ - pr_cont(" SME\n"); - return; + */ + pr_cont(" SME\n"); + return; + } + + /* Secure Encrypted Virtualization */ + if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) + pr_cont(" SEV"); + + /* Encrypted Register State */ + if (cc_platform_has(CC_ATTR_GUEST_STATE_ENCRYPT)) + pr_cont(" SEV-ES"); + + /* Secure Nested Paging */ + if (cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) + pr_cont(" SEV-SNP"); + + pr_cont("\n"); + break; + default: + pr_cont("Unknown\n"); } - - /* Secure Encrypted Virtualization */ - if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) - pr_cont(" SEV"); - - /* Encrypted Register State */ - if (cc_platform_has(CC_ATTR_GUEST_STATE_ENCRYPT)) - pr_cont(" SEV-ES"); - - /* Secure Nested Paging */ - if (cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) - pr_cont(" SEV-SNP"); - - pr_cont("\n"); } /* Architecture __weak replacement functions */