From: "Kirill A. Shutemov" <kirill@shutemov.name>
To: Borislav Petkov <bp@alien8.de>, Andy Lutomirski <luto@kernel.org>,
Sean Christopherson <seanjc@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
Joerg Roedel <jroedel@suse.de>
Cc: Andi Kleen <ak@linux.intel.com>,
Kuppuswamy Sathyanarayanan
<sathyanarayanan.kuppuswamy@linux.intel.com>,
David Rientjes <rientjes@google.com>,
Vlastimil Babka <vbabka@suse.cz>,
Tom Lendacky <thomas.lendacky@amd.com>,
Thomas Gleixner <tglx@linutronix.de>,
Peter Zijlstra <peterz@infradead.org>,
Paolo Bonzini <pbonzini@redhat.com>,
Ingo Molnar <mingo@redhat.com>,
Varad Gautam <varad.gautam@suse.com>,
Dario Faggioli <dfaggioli@suse.com>,
x86@kernel.org, linux-mm@kvack.org, linux-coco@lists.linux.dev,
linux-kernel@vger.kernel.org,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Subject: [PATCH 5/5] x86/tdx: Unaccepted memory support
Date: Tue, 10 Aug 2021 09:26:26 +0300 [thread overview]
Message-ID: <20210810062626.1012-6-kirill.shutemov@linux.intel.com> (raw)
In-Reply-To: <20210810062626.1012-1-kirill.shutemov@linux.intel.com>
All preparation is complete. Hookup TDX-specific code to accept memory.
There are two tdg_accept_memory() implementations: one in main kernel
and one in the decompresser.
The implementation in core kernel uses tdx_hcall_gpa_intent(). The
helper is not available in the decompresser, self-contained
implementation added there instead.
Note that tdx_hcall_gpa_intent() is going to be more complex once we
teach it to accept in 1G and 2M chunks.
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
---
arch/x86/Kconfig | 1 +
arch/x86/boot/compressed/tdx.c | 29 ++++++++++++++++++++
arch/x86/boot/compressed/unaccepted_memory.c | 5 +++-
arch/x86/include/asm/tdx.h | 2 ++
arch/x86/kernel/tdx.c | 8 ++++++
arch/x86/mm/unaccepted_memory.c | 6 +++-
6 files changed, 49 insertions(+), 2 deletions(-)
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index c0261cc72449..5b1b3dc84c7d 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -874,6 +874,7 @@ config INTEL_TDX_GUEST
select ARCH_HAS_PROTECTED_GUEST
select X86_MEM_ENCRYPT_COMMON
select ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS
+ select UNACCEPTED_MEMORY
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/boot/compressed/tdx.c b/arch/x86/boot/compressed/tdx.c
index 88ed6465405b..6f13bdaf327f 100644
--- a/arch/x86/boot/compressed/tdx.c
+++ b/arch/x86/boot/compressed/tdx.c
@@ -5,6 +5,10 @@
#include "../cpuflags.h"
#include "../string.h"
+#include "error.h"
+
+#include <asm/page_types.h>
+#include <asm/tdx.h>
#define TDX_CPUID_LEAF_ID 0x21
@@ -32,3 +36,28 @@ bool early_is_tdx_guest(void)
return !!tdx_guest;
}
+
+#define TDACCEPTPAGE 6
+#define TDVMCALL_MAP_GPA 0x10001
+
+void tdg_accept_memory(phys_addr_t start, phys_addr_t end)
+{
+ struct tdx_hypercall_output outl = {0};
+ int i;
+
+ if (__tdx_hypercall(TDX_HYPERCALL_STANDARD, TDVMCALL_MAP_GPA,
+ start, end, 0, 0, &outl)) {
+ error("Cannot accept memory: MapGPA failed\n");
+ }
+
+ /*
+ * For shared->private conversion, accept the page using TDACCEPTPAGE
+ * TDX module call.
+ */
+ for (i = 0; i < (end - start) / PAGE_SIZE; i++) {
+ if (__tdx_module_call(TDACCEPTPAGE, start + i * PAGE_SIZE,
+ 0, 0, 0, NULL)) {
+ error("Cannot accept memory: page accept failed\n");
+ }
+ }
+}
diff --git a/arch/x86/boot/compressed/unaccepted_memory.c b/arch/x86/boot/compressed/unaccepted_memory.c
index 818d32169eef..146a3a6968a8 100644
--- a/arch/x86/boot/compressed/unaccepted_memory.c
+++ b/arch/x86/boot/compressed/unaccepted_memory.c
@@ -4,7 +4,10 @@
static inline void __accept_memory(phys_addr_t start, phys_addr_t end)
{
/* Platform-specific memory-acceptance call goes here */
- error("Cannot accept memory");
+ if (early_is_tdx_guest())
+ tdg_accept_memory(start, end);
+ else
+ error("Cannot accept memory");
}
void mark_unaccepted(struct boot_params *params, u64 start, u64 num)
diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h
index af6e4cd8078d..f74b6cfde205 100644
--- a/arch/x86/include/asm/tdx.h
+++ b/arch/x86/include/asm/tdx.h
@@ -97,6 +97,8 @@ extern phys_addr_t tdg_shared_mask(void);
extern int tdx_hcall_gpa_intent(phys_addr_t gpa, int numpages,
enum tdx_map_type map_type);
+extern void tdg_accept_memory(phys_addr_t start, phys_addr_t end);
+
int tdx_mcall_tdreport(u64 data, u64 reportdata);
int tdx_mcall_rtmr_extend(u64 data, u64 rmtr);
diff --git a/arch/x86/kernel/tdx.c b/arch/x86/kernel/tdx.c
index dc6d9441f3be..75f3804f86da 100644
--- a/arch/x86/kernel/tdx.c
+++ b/arch/x86/kernel/tdx.c
@@ -372,6 +372,14 @@ int tdx_hcall_gpa_intent(phys_addr_t gpa, int numpages,
return 0;
}
+void tdg_accept_memory(phys_addr_t start, phys_addr_t end)
+{
+ if (tdx_hcall_gpa_intent(start, (end - start) / PAGE_SIZE,
+ TDX_MAP_PRIVATE)) {
+ panic("Accepting memory failed\n");
+ }
+}
+
static __cpuidle void tdg_halt(void)
{
u64 ret;
diff --git a/arch/x86/mm/unaccepted_memory.c b/arch/x86/mm/unaccepted_memory.c
index e11933f62ead..19e0309e128b 100644
--- a/arch/x86/mm/unaccepted_memory.c
+++ b/arch/x86/mm/unaccepted_memory.c
@@ -5,6 +5,7 @@
#include <asm/io.h>
#include <asm/setup.h>
+#include <asm/tdx.h>
#include <asm/unaccepted_memory.h>
static DEFINE_SPINLOCK(unaccepted_memory_lock);
@@ -21,7 +22,10 @@ static void __accept_memory(phys_addr_t start, phys_addr_t end)
start / PMD_SIZE,
DIV_ROUND_UP(end, PMD_SIZE)) {
/* Platform-specific memory-acceptance call goes here */
- panic("Cannot accept memory");
+ if (prot_guest_has(PATTR_GUEST_TDX))
+ tdg_accept_memory(rs * PMD_SIZE, re * PMD_SIZE);
+ else
+ panic("Cannot accept memory");
bitmap_clear(unaccepted_memory, rs, re - rs);
}
}
--
2.31.1
next prev parent reply other threads:[~2021-08-10 6:26 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-10 6:26 [PATCH 0/5] x86: Impplement support for unaccepted memory Kirill A. Shutemov
2021-08-10 6:26 ` [PATCH 1/5] mm: Add " Kirill A. Shutemov
2021-08-10 7:48 ` David Hildenbrand
2021-08-10 15:02 ` Kirill A. Shutemov
2021-08-10 15:21 ` David Hildenbrand
2021-08-12 20:34 ` Kirill A. Shutemov
2021-08-10 18:13 ` Dave Hansen
2021-08-10 18:30 ` Andi Kleen
2021-08-10 18:56 ` Dave Hansen
2021-08-10 19:23 ` Andi Kleen
2021-08-10 19:46 ` Dave Hansen
2021-08-10 21:20 ` Andi Kleen
2021-08-12 8:19 ` Joerg Roedel
2021-08-12 14:14 ` Dave Hansen
2021-08-12 20:49 ` Kirill A. Shutemov
2021-08-12 20:59 ` Dave Hansen
2021-08-12 21:23 ` Kirill A. Shutemov
2021-08-13 14:49 ` Joerg Roedel
2021-08-17 15:00 ` David Hildenbrand
2021-08-19 9:55 ` Joerg Roedel
2021-08-19 10:06 ` David Hildenbrand
2021-08-10 20:50 ` Dave Hansen
2021-08-12 21:08 ` Kirill A. Shutemov
2021-08-10 6:26 ` [PATCH 2/5] efi/x86: Implement " Kirill A. Shutemov
2021-08-10 17:50 ` Dave Hansen
2021-08-12 21:14 ` Kirill A. Shutemov
2021-08-12 21:43 ` Dave Hansen
2021-08-10 18:30 ` Dave Hansen
2021-08-10 19:08 ` Kirill A. Shutemov
2021-08-10 19:19 ` Dave Hansen
2021-08-12 21:17 ` Kirill A. Shutemov
2021-08-10 6:26 ` [PATCH 3/5] x86/boot/compressed: Handle " Kirill A. Shutemov
2021-08-10 6:26 ` [PATCH 4/5] x86/mm: Provide helpers for " Kirill A. Shutemov
2021-08-10 18:16 ` Dave Hansen
2021-08-12 20:31 ` Kirill A. Shutemov
2021-08-10 6:26 ` Kirill A. Shutemov [this message]
2021-08-10 14:08 ` [PATCH 0/5] x86: Impplement support " Dave Hansen
2021-08-10 15:15 ` Kirill A. Shutemov
2021-08-10 15:51 ` Dave Hansen
2021-08-10 17:31 ` Kirill A. Shutemov
2021-08-10 17:36 ` Dave Hansen
2021-08-10 17:51 ` Kirill A. Shutemov
2021-08-10 18:19 ` Dave Hansen
2021-08-10 18:39 ` Kirill A. Shutemov
2021-08-12 8:23 ` Joerg Roedel
2021-08-12 10:10 ` Kirill A. Shutemov
2021-08-12 19:33 ` Andi Kleen
2021-08-12 20:22 ` Kirill A. Shutemov
2021-08-13 14:56 ` Joerg Roedel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210810062626.1012-6-kirill.shutemov@linux.intel.com \
--to=kirill@shutemov.name \
--cc=ak@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=bp@alien8.de \
--cc=dfaggioli@suse.com \
--cc=jroedel@suse.de \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-coco@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=rientjes@google.com \
--cc=sathyanarayanan.kuppuswamy@linux.intel.com \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=thomas.lendacky@amd.com \
--cc=varad.gautam@suse.com \
--cc=vbabka@suse.cz \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).