[v1,3/3] x86/tdx: Provide stub tdx_accept_memory() for non-TDX configs

Message ID 20231122170106.270266-3-jpiotrowski@linux.microsoft.com
State New
Headers
Series [v1,1/3] x86/tdx: Check for TDX partitioning during early TDX init |

Commit Message

Jeremi Piotrowski Nov. 22, 2023, 5:01 p.m. UTC
  When CONFIG_INTEL_TDX_GUEST is not defined but CONFIG_UNACCEPTED_MEMORY=y is,
the kernel fails to link with an undefined reference to tdx_accept_memory from
arch_accept_memory. Provide a stub for tdx_accept_memory to fix the build for
that configuration.

CONFIG_UNACCEPTED_MEMORY is also selected by CONFIG_AMD_MEM_ENCRYPT, and there
are stubs for snp_accept_memory for when it is not defined. Previously this did
not result in an error when CONFIG_INTEL_TDX_GUEST was not defined because the
branch that references tdx_accept_memory() was being discarded due to
DISABLE_TDX_GUEST being set.

Cc: <stable@vger.kernel.org> # v6.5+
Fixes: 75d090fd167a ("x86/tdx: Add unaccepted memory support")
Signed-off-by: Jeremi Piotrowski <jpiotrowski@linux.microsoft.com>
---
 arch/x86/include/asm/shared/tdx.h | 4 ++++
 1 file changed, 4 insertions(+)
  

Comments

Kirill A. Shutemov Nov. 23, 2023, 2:11 p.m. UTC | #1
On Wed, Nov 22, 2023 at 06:01:06PM +0100, Jeremi Piotrowski wrote:
> When CONFIG_INTEL_TDX_GUEST is not defined but CONFIG_UNACCEPTED_MEMORY=y is,
> the kernel fails to link with an undefined reference to tdx_accept_memory from
> arch_accept_memory. Provide a stub for tdx_accept_memory to fix the build for
> that configuration.
> 
> CONFIG_UNACCEPTED_MEMORY is also selected by CONFIG_AMD_MEM_ENCRYPT, and there
> are stubs for snp_accept_memory for when it is not defined. Previously this did
> not result in an error when CONFIG_INTEL_TDX_GUEST was not defined because the
> branch that references tdx_accept_memory() was being discarded due to
> DISABLE_TDX_GUEST being set.

And who unsets it now?
  
Jeremi Piotrowski Nov. 24, 2023, 10 a.m. UTC | #2
On 23/11/2023 15:11, Kirill A. Shutemov wrote:
> On Wed, Nov 22, 2023 at 06:01:06PM +0100, Jeremi Piotrowski wrote:
>> When CONFIG_INTEL_TDX_GUEST is not defined but CONFIG_UNACCEPTED_MEMORY=y is,
>> the kernel fails to link with an undefined reference to tdx_accept_memory from
>> arch_accept_memory. Provide a stub for tdx_accept_memory to fix the build for
>> that configuration.
>>
>> CONFIG_UNACCEPTED_MEMORY is also selected by CONFIG_AMD_MEM_ENCRYPT, and there
>> are stubs for snp_accept_memory for when it is not defined. Previously this did
>> not result in an error when CONFIG_INTEL_TDX_GUEST was not defined because the
>> branch that references tdx_accept_memory() was being discarded due to
>> DISABLE_TDX_GUEST being set.
> 
> And who unsets it now?
> 

Who unsets what now? DISABLE_TDX_GUEST still works the same as before, but patch 2
changed the check in arch_accept_memory() to be more specific
(cc_platform_has(CC_ATTR_TDX_MODULE_CALLS)). The stub should have been there all
along for CONFIG_AMD_MEM_ENCRPYT=y && CONFIG_INTEL_TDX_GUEST=n configs, but it
happened to work without it.
  

Patch

diff --git a/arch/x86/include/asm/shared/tdx.h b/arch/x86/include/asm/shared/tdx.h
index 7513b3bb69b7..58cdbaac3d5b 100644
--- a/arch/x86/include/asm/shared/tdx.h
+++ b/arch/x86/include/asm/shared/tdx.h
@@ -91,7 +91,11 @@  struct tdx_module_output {
 u64 __tdx_module_call(u64 fn, u64 rcx, u64 rdx, u64 r8, u64 r9,
 		      struct tdx_module_output *out);
 
+#ifdef CONFIG_INTEL_TDX_GUEST
 bool tdx_accept_memory(phys_addr_t start, phys_addr_t end);
+#else
+static inline bool tdx_accept_memory(phys_addr_t start, phys_addr_t end) { return false; }
+#endif
 
 /*
  * The TDG.VP.VMCALL-Instruction-execution sub-functions are defined