Received: by 2002:a05:6a10:87d6:0:0:0:0 with SMTP id g22csp859445pxr; Mon, 11 Apr 2022 08:56:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGxQfzYUbCqB+uxtMdDVo0VLyFTcz+bK187uyfLjlcU9MIkhId854jUPvYFRbgrUyHJInI X-Received: by 2002:a17:903:22c2:b0:154:565b:b273 with SMTP id y2-20020a17090322c200b00154565bb273mr33345719plg.115.1649692571731; Mon, 11 Apr 2022 08:56:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649692571; cv=none; d=google.com; s=arc-20160816; b=fpqRHAQ0kq6MARlo+DYtilzAl1m7VFjvdz6oD1E41yaBVcY+wbpUfN3gKkbLNmZZ4s F1R2CR4MJORQ7NA559NtnJ7o9nkVY+EjCBx0dzZYzGpMXnBVSlMhqgp7syhbylU4rdR+ 751mISa5QgfEkzOYcKj02S6fpXEi5g5b49wr9/h9HJ/0BFsIYcjic5vcgcgzrQKyncj3 ii75N+yOmN0/+isLo8E6C/9wdMLIN+kyd1BwOKIrrgg3FuWxyKAQ7TIKM0unqDsqBqSo B/qhTSSDS4H7WG5Q7FadKEnnZY6IRfxGp2vFTzzPEiTanLQkKTkAn4F7gSHMeknBplsQ zb9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=DIamPipLa2HMu6qbtf3UAGy0nEC+13pjmiWwezcteHo=; b=FLpnaHOF1eEguvEnok7Hfz1Y1kCtIg2grlpWRkIjTYfGi+Q/ivfgTRqL/GIniRakrj Bttor6CSsafXzhZy+tC+J2eT2lON4xKoMcwdXXv4SiDAj4SOY6WGYqwimnXYus6feT01 CR4cRLgYPAsyovokL3xWHk482aX7qUvQfKoRQsk1QlaWTisQkryPsuZWF7cYROMwVmW1 CL0QaYsvrYRdw2GtDfqxtOKXnlU1VevWNYRavnfwhbozchI/qzEXlfSSpFepS428QCSO xo8KIKSAAl6w9GO3PtoU4ro2xXeSesKfDipJK2uPf0Xz0RFBtnvYzS2pOGzBBaPnBvOJ AyRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=KK9DrPC2; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=JhzzKNfp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h11-20020a170902748b00b00153b2d16465si8393776pll.109.2022.04.11.08.55.56; Mon, 11 Apr 2022 08:56:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=KK9DrPC2; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=JhzzKNfp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230255AbiDIBbU (ORCPT + 99 others); Fri, 8 Apr 2022 21:31:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240393AbiDIBaZ (ORCPT ); Fri, 8 Apr 2022 21:30:25 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F363193F1; Fri, 8 Apr 2022 18:27:42 -0700 (PDT) Date: Sat, 09 Apr 2022 01:27:40 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1649467661; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DIamPipLa2HMu6qbtf3UAGy0nEC+13pjmiWwezcteHo=; b=KK9DrPC2KKMlNIwhkIlT31lDTJjxg/QBUTSjCyMc3ywPzshFDDlq14k+BvQvGXk27eVnZP JJ+N9l8/Vg5D7yc6VnRlyKXeegiyQumurr6d2L1j98+3Cbmh0Ih0NNWEusLexl+6seQoOd iTFHqju1qVcTVJf9Qw7rHGz+KJVWcBjD+e7+Jn+kTV5yazfw/StH6y9NJFqUuBueaIbtp6 uREPtsInAgkvAX2FRmVkE/fCmF246DlmMNWOpW5LtugLS1waOsdnFbRF6yQT6g7f9deMCR zYLnHQAzTCP/hVlTRxFZ2CBwuf2DPTCK//10yVoO/ULEdPMmFe7q3CXXmDGDsg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1649467661; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DIamPipLa2HMu6qbtf3UAGy0nEC+13pjmiWwezcteHo=; b=JhzzKNfpp8uMuONtbhimo2MAq3Fozn+FNKpTV36wPB1LKT53XssOPnwg1Rwx6ggByB/Zj0 IFLRUmxN06bu3/Cg== From: "tip-bot2 for Kirill A. Shutemov" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/tdx] x86/tdx: Exclude shared bit from __PHYSICAL_MASK Cc: Kuppuswamy Sathyanarayanan , "Kirill A. Shutemov" , Dave Hansen , Andi Kleen , Tony Luck , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220405232939.73860-6-kirill.shutemov@linux.intel.com> References: <20220405232939.73860-6-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Message-ID: <164946766003.4207.16570460228314176239.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/tdx branch of tip: Commit-ID: 65fab5bc033aad1a9faf976caec46558c2f88319 Gitweb: https://git.kernel.org/tip/65fab5bc033aad1a9faf976caec46558c2f88319 Author: Kirill A. Shutemov AuthorDate: Wed, 06 Apr 2022 02:29:14 +03:00 Committer: Dave Hansen CommitterDate: Thu, 07 Apr 2022 08:27:51 -07:00 x86/tdx: Exclude shared bit from __PHYSICAL_MASK In TDX guests, by default memory is protected from host access. If a guest needs to communicate with the VMM (like the I/O use case), it uses a single bit in the physical address to communicate the protected/shared attribute of the given page. In the x86 ARCH code, __PHYSICAL_MASK macro represents the width of the physical address in the given architecture. It is used in creating physical PAGE_MASK for address bits in the kernel. Since in TDX guest, a single bit is used as metadata, it needs to be excluded from valid physical address bits to avoid using incorrect addresses bits in the kernel. Enable DYNAMIC_PHYSICAL_MASK to support updating the __PHYSICAL_MASK. Co-developed-by: Kuppuswamy Sathyanarayanan Signed-off-by: Kuppuswamy Sathyanarayanan Signed-off-by: Kirill A. Shutemov Signed-off-by: Dave Hansen Reviewed-by: Andi Kleen Reviewed-by: Tony Luck Reviewed-by: Thomas Gleixner Link: https://lkml.kernel.org/r/20220405232939.73860-6-kirill.shutemov@linux.intel.com --- arch/x86/Kconfig | 1 + arch/x86/coco/tdx/tdx.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 984315c..aea4cc4 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -883,6 +883,7 @@ config INTEL_TDX_GUEST depends on X86_64 && CPU_SUP_INTEL depends on X86_X2APIC select ARCH_HAS_CC_PLATFORM + select DYNAMIC_PHYSICAL_MASK help Support running as a guest under Intel TDX. Without this support, the guest kernel can not boot or run under TDX. diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 96b2611..e84f6dd 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -89,5 +89,13 @@ void __init tdx_early_init(void) cc_mask = get_cc_mask(); cc_set_mask(cc_mask); + /* + * All bits above GPA width are reserved and kernel treats shared bit + * as flag, not as part of physical address. + * + * Adjust physical mask to only cover valid GPA bits. + */ + physical_mask &= cc_mask - 1; + pr_info("Guest detected\n"); }