Re: [RFC v2 28/32] x86/tdx: Make pages shared in ioremap()

From: Kuppuswamy, Sathyanarayanan
Date: Mon May 31 2021 - 13:33:17 EST




On 5/31/21 8:13 AM, Borislav Petkov wrote:
On Tue, May 25, 2021 at 11:21:21AM -0700, Kuppuswamy, Sathyanarayanan wrote:
Following is the sample implementation. Please let me know your
comments.

Doesn't look like what I suggested here:

https://lkml.kernel.org/r/YKfPLlulaqwypNkO@xxxxxxx

IIUC, following are your design suggestions:

1. Define generic flags.

I think following flags are defined as you have suggested.

+++ b/include/linux/protected_guest.h
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef _LINUX_PROTECTED_GUEST_H
+#define _LINUX_PROTECTED_GUEST_H 1
+
+/* Protected Guest Feature Flags (leave 0-0xff for arch specific flags) */
+
+/* Support for guest encryption */
+#define VM_MEM_ENCRYPT 0x100
+/* Encryption support is active */
+#define VM_MEM_ENCRYPT_ACTIVE 0x101
+/* Support for unrolled string IO */
+#define VM_UNROLL_STRING_IO 0x102
+/* Support for host memory encryption */
+#define VM_HOST_MEM_ENCRYPT 0x103

2. Define generic functions and allow calls to arch specific implementations.

For above requirement, instead of calling arch specific functions from include/linux/protected_guest.h, I have directly included the arch specific file in linux/protected_guest.h

+#ifdef CONFIG_ARCH_HAS_PROTECTED_GUEST
+#include <asm/protected_guest.h>
+#else
+static inline bool is_protected_guest(void) { return false; }
+static inline bool protected_guest_has(unsigned long flag) { return false; }
+#endif

3. Implement arch specific implementations respond to protected_guest_has() calls right?

I think above requirement is satisfied in following implementation.

+++ b/arch/x86/include/asm/protected_guest.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2020 Intel Corporation */
+#ifndef _ASM_PROTECTED_GUEST
+#define _ASM_PROTECTED_GUEST 1
+
+#include <asm/cpufeature.h>
+#include <asm/tdx.h>
+
+/* Only include through linux/protected_guest.h */
+
+static inline bool is_protected_guest(void)
+{
+ return boot_cpu_has(X86_FEATURE_TDX_GUEST);
+}
+
+static inline bool protected_guest_has(unsigned long flag)
+{
+ if (boot_cpu_has(X86_FEATURE_TDX_GUEST))
+ return tdx_protected_guest_has(flag);
+
+ return false;
+}
+

Did I misunderstand anything ? Please let me know your comments.





--
Sathyanarayanan Kuppuswamy
Linux Kernel Developer