Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp295329pxt; Wed, 4 Aug 2021 23:17:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwa3DbJPF3kFhnTEVwbdlC5n8nYKli8LMwu4lUf1iyrpjyVwSIvEmwq2k7wwtJ29XD5wXl6 X-Received: by 2002:aa7:d709:: with SMTP id t9mr4298435edq.384.1628144274801; Wed, 04 Aug 2021 23:17:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628144274; cv=none; d=google.com; s=arc-20160816; b=EC49aO4Z8lU2qIOG8UDMdqZfKs3LOQRby20LGdS3wHmac+b9xoVI3Nd6GSCCnII4Zi lq+Zwhpj+T4ZV4qxFucb73+7lwV2sVdD+6N+mmHTe0p10zUXbrNU9khEgoaebTbOAP3K DEWWSBpZVVv6wOAjyuft5UocBnlskdPFgPpsbDbwDK8nihdS+8LCUssIa9pwuj+ROjEg eW1HJ5RQAW+dmcfad/p4NluqnVPikQ6J8jFS/Pjb3Gb2QCWrHxKUl92RZ7ldwC8IyuV7 zhJxWjrBkw06ydk+XNV9uNrQgQTdATceEuJKRYoWJ+oNbT0z3iVTlb+D5z0jJ/u33fVK rtPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Xxj8nxfoJucd2VsNL1TdMdn1JUTnG1Sy+hxTfl51uYI=; b=dc8RCcoStA2ehLJPK0LHOBcT642a1j1LMZTlt9IBZlUgkLjEx1QKG25/Il46Zgv2OP sudAUk+NxPOuDCj4YFyLGRLeEaEu5ap9Ta//45RthM4Pw9KlJSeCsqY+DyF5cEKw5biH Y6IbyidJrf374qlGM/8SM3/kq9Xcl3sokamCa/cXW+kT0FrvTmpFYp1LpYQjWNkdliyw Mkjhq/2LLiEnh3/QgBiHiRz3qEOnwOAZSb3WKAYeuet3EvhSIATrLhBc/YvqTFy+GxUu FTqdsARLrJcf6/XCceeiwTdPoD5JrJxh1LzWReUDJDUSne6GJsM/pklK6WXI7Kb11HjP cnAw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k13si4860693ejp.411.2021.08.04.23.17.31; Wed, 04 Aug 2021 23:17:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236658AbhHEAxq (ORCPT + 99 others); Wed, 4 Aug 2021 20:53:46 -0400 Received: from mga02.intel.com ([134.134.136.20]:12125 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234968AbhHEAxi (ORCPT ); Wed, 4 Aug 2021 20:53:38 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10066"; a="201215423" X-IronPort-AV: E=Sophos;i="5.84,296,1620716400"; d="scan'208";a="201215423" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Aug 2021 17:53:25 -0700 X-IronPort-AV: E=Sophos;i="5.84,296,1620716400"; d="scan'208";a="437617186" Received: from mjkendri-mobl.amr.corp.intel.com (HELO skuppusw-desk1.amr.corp.intel.com) ([10.254.17.117]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Aug 2021 17:53:22 -0700 From: Kuppuswamy Sathyanarayanan To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Peter Zijlstra , Andy Lutomirski , Bjorn Helgaas , Richard Henderson , Thomas Bogendoerfer , James E J Bottomley , Helge Deller , "David S . Miller" , Arnd Bergmann , Jonathan Corbet , "Michael S . Tsirkin" Cc: Peter H Anvin , Dave Hansen , Tony Luck , Dan Williams , Andi Kleen , Kirill Shutemov , Sean Christopherson , Kuppuswamy Sathyanarayanan , x86@kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-alpha@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, sparclinux@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v4 02/15] x86/tdx: Exclude Shared bit from physical_mask Date: Wed, 4 Aug 2021 17:52:05 -0700 Message-Id: <20210805005218.2912076-3-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210805005218.2912076-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20210805005218.2912076-1-sathyanarayanan.kuppuswamy@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Kirill A. Shutemov" Just like MKTME, TDX reassigns bits of the physical address for metadata. MKTME used several bits for an encryption KeyID. TDX uses a single bit in guests to communicate whether a physical page should be protected by TDX as private memory (bit set to 0) or unprotected and shared with the VMM (bit set to 1). Add a helper, tdg_shared_mask() to generate the mask. The processor enumerates its physical address width to include the shared bit, which means it gets included in __PHYSICAL_MASK by default. Remove the shared mask from 'physical_mask' since any bits in tdg_shared_mask() are not used for physical addresses in page table entries. Also, note that shared mapping configuration cannot be clubbed between AMD SME and Intel TDX Guest platforms in common function. SME has to do it very early in __startup_64() as it sets the bit on all memory, except what is used for communication. TDX can postpone it, as it don't need any shared mapping in very early boot. Signed-off-by: Kirill A. Shutemov Reviewed-by: Andi Kleen Reviewed-by: Tony Luck Signed-off-by: Kuppuswamy Sathyanarayanan --- Changes since v3: * None Changes since v1: * Fixed format issues in commit log. arch/x86/Kconfig | 1 + arch/x86/include/asm/tdx.h | 4 ++++ arch/x86/kernel/tdx.c | 9 +++++++++ 3 files changed, 14 insertions(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index d66a8a2f3c97..8eada36694b6 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -872,6 +872,7 @@ config INTEL_TDX_GUEST select X86_X2APIC select SECURITY_LOCKDOWN_LSM select ARCH_HAS_PROTECTED_GUEST + select X86_MEM_ENCRYPT_COMMON help Provide support for running in a trusted domain on Intel processors equipped with Trusted Domain eXtensions. TDX is a new Intel diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h index 72154d3f63c2..1e2a1c6a1898 100644 --- a/arch/x86/include/asm/tdx.h +++ b/arch/x86/include/asm/tdx.h @@ -77,6 +77,8 @@ int tdg_handle_virtualization_exception(struct pt_regs *regs, bool tdg_early_handle_ve(struct pt_regs *regs); +extern phys_addr_t tdg_shared_mask(void); + /* * To support I/O port access in decompressor or early kernel init * code, since #VE exception handler cannot be used, use paravirt @@ -145,6 +147,8 @@ static inline bool tdx_prot_guest_has(unsigned long flag) { return false; } static inline bool tdg_early_handle_ve(struct pt_regs *regs) { return false; } +static inline phys_addr_t tdg_shared_mask(void) { return 0; } + #endif /* CONFIG_INTEL_TDX_GUEST */ #ifdef CONFIG_INTEL_TDX_GUEST_KVM diff --git a/arch/x86/kernel/tdx.c b/arch/x86/kernel/tdx.c index 0c24439774b4..d316fe33f52f 100644 --- a/arch/x86/kernel/tdx.c +++ b/arch/x86/kernel/tdx.c @@ -75,6 +75,12 @@ bool tdx_prot_guest_has(unsigned long flag) } EXPORT_SYMBOL_GPL(tdx_prot_guest_has); +/* The highest bit of a guest physical address is the "sharing" bit */ +phys_addr_t tdg_shared_mask(void) +{ + return 1ULL << (td_info.gpa_width - 1); +} + static void tdg_get_info(void) { u64 ret; @@ -86,6 +92,9 @@ static void tdg_get_info(void) td_info.gpa_width = out.rcx & GENMASK(5, 0); td_info.attributes = out.rdx; + + /* Exclude Shared bit from the __PHYSICAL_MASK */ + physical_mask &= ~tdg_shared_mask(); } static __cpuidle void tdg_halt(void) -- 2.25.1