From patchwork Wed Jan 10 19:35:14 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: 187007 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1012032dyi; Wed, 10 Jan 2024 11:36:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IESVR5RgDi5iQ2Ze01d13PaeBJEAgcW14P7TsXUy3fnvibB7MbJScP9VlQEVSJNGld70+HF X-Received: by 2002:a50:c01e:0:b0:556:ab59:fe7b with SMTP id r30-20020a50c01e000000b00556ab59fe7bmr299110edb.167.1704915372531; Wed, 10 Jan 2024 11:36:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704915372; cv=none; d=google.com; s=arc-20160816; b=ndcSA1syieeZ/kj+N8T5SxK7Qaldwaeghs1GP6AIZJBsAt+JTnCb2C470HNmZfnHF/ 8UwKnQu6S01XpCzLypNeIcqpxfgFg86I7yv2w62bW1vwdECeOyhsgNck+3Gf/Sl9I36N 9pYzm8jCEULhf2v7b2YKXjLmSm9cs/uITnge1Kp8hnuUrDEOHEaagU0eO2tzX/EQAbDX aSq7pBRamqypdpUgJ0wXl+c4iFWkAiwe7AGZEDZ1okv0+md/pgZOhoSzlO6psxc2o/gE 1c2+lZZI0ArpMbXQQ+3M2uR87DLWNk0PaO8l0aCXCsC3WNYT9/JCTVdW5ucf+DY8Cwb8 69zQ== ARC-Message-Signature: i=1; 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=ov7UwYLFo/6qgZXGCMSKuYHB8HiLivX57Hn+8YjJxpE=; fh=2ITiJeuR7N8hOdW6MANRZ43Rq56rSPE8F3t+IbyglgI=; b=zNsAuVnbsCFitM3at7WTN/uBmrEZ4KK+aqng5yj75IuMjowPr2KO8RzKKgPUGlPdvq fLUVPJeet3dEQwhC0dXx4OF9K6DJfDjgVatnj2JYx1/IV3ZNGA3xKZMuTwGzstKmlVbO HbB0QJ2PhR4YxGLUiFnPwpOINyBFN8PvQQ51C2Bno2GVkciDm/Cw3UzSoL4NufSOx4zm rfIUOtijAunBvDZB4SaamV3hmJcPT1hksI1hICc7FwdZKFMlBys0MYbCWGZBRvti/h6h jjxCyvuR5vxqqb6M/IZaTREFdt3V8EzSyY48oUi2uUbKBinj41SnEzVYgl0d0IQU8d2i bWcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="GO/bEydH"; spf=pass (google.com: domain of linux-kernel+bounces-22663-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22663-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id s1-20020a05640217c100b005576fae01fesi1940991edy.282.2024.01.10.11.36.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 11:36:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-22663-ouuuleilei=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="GO/bEydH"; spf=pass (google.com: domain of linux-kernel+bounces-22663-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22663-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 8D1E51F23A73 for ; Wed, 10 Jan 2024 19:36:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EEB664EB38; Wed, 10 Jan 2024 19:35:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="GO/bEydH" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.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 7BBFC4EB27 for ; Wed, 10 Jan 2024 19:35:34 +0000 (UTC) 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.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1704915334; x=1736451334; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=iOgBXT4oCCP14tPNy05HoJwBeWOx4dK8ykFicOjjzso=; b=GO/bEydHcguuLci+9xM+NtwY2es1C4oCN41MI0PEldxyK2GPE6HRUYHP 0N6HnUHQ1PfeCyF7sZDJM/1Ivx131xVWc/bUgBvlMEdUZUAzq74AFyPt/ z2te7/lyKFV2RGdHQa/0OqaVxYYIoUui2iz5jXTWPVjLhENCtxmpX+Pu6 Lk5vw0UPAsnUE3ruQDqQu4DzCXjviGO7GDd+Q+iyVe0esxe0eg3OE6jeo KihWDYt45I6eYAsYNYWi9Kk19YkZXiceiiAOK2HJ7LN9MdjKr3CMijO4F JTzh9MF5f+yvWPZzylbLJgcXB7HhJpK/p3OVe2VoSFTreuf9jwCn3AtUW w==; X-IronPort-AV: E=McAfee;i="6600,9927,10949"; a="5377875" X-IronPort-AV: E=Sophos;i="6.04,184,1695711600"; d="scan'208";a="5377875" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jan 2024 11:35:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10949"; a="775325186" X-IronPort-AV: E=Sophos;i="6.04,184,1695711600"; d="scan'208";a="775325186" Received: from jganji-mobl1.gar.corp.intel.com (HELO box.shutemov.name) ([10.249.37.201]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jan 2024 11:35:30 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id 8A36010A3F6; Wed, 10 Jan 2024 22:35:27 +0300 (+03) 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" , Dexuan Cui , Jeremi Piotrowski Subject: [PATCH] x86/mm: Fix memory encryption features advertisement Date: Wed, 10 Jan 2024 22:35:14 +0300 Message-ID: <20240110193514.15620-1-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.41.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: 1787733341155678338 X-GMAIL-MSGID: 1787733341155678338 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 has the TDX CPU feature set. To avoid confusion, check the cc_vendor directly. Signed-off-by: Kirill A. Shutemov Cc: Dexuan Cui Cc: Jeremi Piotrowski Signed-off-by: Kirill A. Shutemov --- 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 */