From: Tim Merrifield <tim.merrifield@broadcom.com>
To: "Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
x86@kernel.org, "H . Peter Anvin" <hpa@zytor.com>,
Xin Li <xin3.li@intel.com>,
Tim Merrifield <tim.merrifield@broadcom.com>,
Ard Biesheuvel <ardb@kernel.org>, Kai Huang <kai.huang@intel.com>,
Kevin Loughlin <kevinloughlin@google.com>,
Thomas Zimmermann <tzimmermann@suse.de>,
Rick Edgecombe <rick.p.edgecombe@intel.com>,
Kees Cook <kees@kernel.org>, Mike Rapoport <rppt@kernel.org>,
Brian Gerst <brgerst@gmail.com>,
linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org,
Ajay Kaher <ajay.kaher@broadcom.com>,
Alexey Makhalov <alexey.amakhalov@broadcom.com>,
Broadcom internal kernel review list
<bcm-kernel-feedback-list@broadcom.com>,
virtualization@lists.linux.dev, alex.james@broadcom.com,
doug.covelli@broadcom.com, jeffrey.sheldon@broadcom.com
Subject: [PATCH 1/2] x86/tdx: Add prctl to allow userlevel TDX hypercalls
Date: Wed, 3 Jul 2024 23:36:00 +0000 [thread overview]
Message-ID: <90bf00599189c34e77aa77986674be2d5fc19f9c.1720046911.git.tim.merrifield@broadcom.com> (raw)
In-Reply-To: <cover.1720046911.git.tim.merrifield@broadcom.com>
Add a new prctl option to enable/disable user-level hypercalls when
running in a confidential VM. Add support for checking this flag on
VMCALL #VE for TDX and transfer control to a hypervisor
vendor-specific handler.
Signed-off-by: Tim Merrifield <tim.merrifield@broadcom.com>
---
arch/x86/coco/tdx/tdx.c | 18 ++++++++++++++++++
arch/x86/include/asm/thread_info.h | 2 ++
arch/x86/include/asm/x86_init.h | 1 +
arch/x86/include/uapi/asm/prctl.h | 3 +++
arch/x86/kernel/process.c | 20 ++++++++++++++++++++
5 files changed, 44 insertions(+)
diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c
index ef8ec2425998..23111e4c1f91 100644
--- a/arch/x86/coco/tdx/tdx.c
+++ b/arch/x86/coco/tdx/tdx.c
@@ -239,6 +239,7 @@ static int ve_instr_len(struct ve_info *ve)
case EXIT_REASON_MSR_WRITE:
case EXIT_REASON_CPUID:
case EXIT_REASON_IO_INSTRUCTION:
+ case EXIT_REASON_VMCALL:
/* It is safe to use ve->instr_len for #VE due instructions */
return ve->instr_len;
case EXIT_REASON_EPT_VIOLATION:
@@ -635,6 +636,21 @@ void tdx_get_ve_info(struct ve_info *ve)
ve->instr_info = upper_32_bits(args.r10);
}
+/*
+ * Handle user-initiated, hypervisor-specific VMCALLs.
+ */
+static int handle_user_vmcall(struct pt_regs *regs, struct ve_info *ve)
+{
+ if (x86_platform.hyper.tdx_hcall &&
+ test_thread_flag(TIF_COCO_USER_HCALL)) {
+ if (!x86_platform.hyper.tdx_hcall(regs))
+ return -EIO;
+ return ve_instr_len(ve);
+ } else {
+ return -EOPNOTSUPP;
+ }
+}
+
/*
* Handle the user initiated #VE.
*
@@ -646,6 +662,8 @@ static int virt_exception_user(struct pt_regs *regs, struct ve_info *ve)
switch (ve->exit_reason) {
case EXIT_REASON_CPUID:
return handle_cpuid(regs, ve);
+ case EXIT_REASON_VMCALL:
+ return handle_user_vmcall(regs, ve);
default:
pr_warn("Unexpected #VE: %lld\n", ve->exit_reason);
return -EIO;
diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
index 12da7dfd5ef1..9f69a26a5e68 100644
--- a/arch/x86/include/asm/thread_info.h
+++ b/arch/x86/include/asm/thread_info.h
@@ -106,6 +106,7 @@ struct thread_info {
#define TIF_BLOCKSTEP 25 /* set when we want DEBUGCTLMSR_BTF */
#define TIF_LAZY_MMU_UPDATES 27 /* task is updating the mmu lazily */
#define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
+#define TIF_COCO_USER_HCALL 30 /* Userland hypercalls allowed in CoCo */
#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
#define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
@@ -128,6 +129,7 @@ struct thread_info {
#define _TIF_BLOCKSTEP (1 << TIF_BLOCKSTEP)
#define _TIF_LAZY_MMU_UPDATES (1 << TIF_LAZY_MMU_UPDATES)
#define _TIF_ADDR32 (1 << TIF_ADDR32)
+#define _TIF_COCO_USER_HCALL (1 << TIF_COCO_USER_HCALL)
/* flags to check in __switch_to() */
#define _TIF_WORK_CTXSW_BASE \
diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
index 213cf5379a5a..52975bedd33e 100644
--- a/arch/x86/include/asm/x86_init.h
+++ b/arch/x86/include/asm/x86_init.h
@@ -282,6 +282,7 @@ struct x86_hyper_runtime {
void (*sev_es_hcall_prepare)(struct ghcb *ghcb, struct pt_regs *regs);
bool (*sev_es_hcall_finish)(struct ghcb *ghcb, struct pt_regs *regs);
bool (*is_private_mmio)(u64 addr);
+ bool (*tdx_hcall)(struct pt_regs *regs);
};
/**
diff --git a/arch/x86/include/uapi/asm/prctl.h b/arch/x86/include/uapi/asm/prctl.h
index 384e2cc6ac19..7fa289a1815b 100644
--- a/arch/x86/include/uapi/asm/prctl.h
+++ b/arch/x86/include/uapi/asm/prctl.h
@@ -16,6 +16,9 @@
#define ARCH_GET_XCOMP_GUEST_PERM 0x1024
#define ARCH_REQ_XCOMP_GUEST_PERM 0x1025
+#define ARCH_GET_COCO_USER_HCALL 0x1030
+#define ARCH_SET_COCO_USER_HCALL 0x1031
+
#define ARCH_XCOMP_TILECFG 17
#define ARCH_XCOMP_TILEDATA 18
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index 1b3d417cd6c4..16f8ab6cde2e 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -1039,6 +1039,21 @@ unsigned long __get_wchan(struct task_struct *p)
return addr;
}
+static int get_coco_user_hcall_mode(void)
+{
+ return !test_thread_flag(TIF_COCO_USER_HCALL);
+}
+
+static int set_coco_user_hcall_mode(unsigned long enabled)
+{
+ if (enabled)
+ set_thread_flag(TIF_COCO_USER_HCALL);
+ else
+ clear_thread_flag(TIF_COCO_USER_HCALL);
+
+ return 0;
+}
+
long do_arch_prctl_common(int option, unsigned long arg2)
{
switch (option) {
@@ -1052,6 +1067,11 @@ long do_arch_prctl_common(int option, unsigned long arg2)
case ARCH_GET_XCOMP_GUEST_PERM:
case ARCH_REQ_XCOMP_GUEST_PERM:
return fpu_xstate_prctl(option, arg2);
+ case ARCH_GET_COCO_USER_HCALL:
+ return get_coco_user_hcall_mode();
+ case ARCH_SET_COCO_USER_HCALL:
+ return set_coco_user_hcall_mode(arg2);
+
}
return -EINVAL;
--
2.40.1
next prev parent reply other threads:[~2024-07-03 23:28 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-03 23:35 [PATCH 0/2] Support userspace hypercalls for TDX Tim Merrifield
2024-07-03 23:36 ` Tim Merrifield [this message]
2024-07-08 12:19 ` [PATCH 1/2] x86/tdx: Add prctl to allow userlevel TDX hypercalls Kirill A . Shutemov
2024-07-23 5:04 ` Tim Merrifield
2024-07-23 9:10 ` Kirill A . Shutemov
2024-07-03 23:36 ` [PATCH 2/2] x86/vmware: VMware support for TDX userspace hypercalls Tim Merrifield
2024-07-08 12:23 ` Kirill A . Shutemov
2024-07-04 0:18 ` [PATCH 0/2] Support userspace hypercalls for TDX Dave Hansen
2024-07-05 16:04 ` Tim Merrifield
2024-07-04 13:05 ` Peter Zijlstra
2024-07-05 18:55 ` Tim Merrifield
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=90bf00599189c34e77aa77986674be2d5fc19f9c.1720046911.git.tim.merrifield@broadcom.com \
--to=tim.merrifield@broadcom.com \
--cc=ajay.kaher@broadcom.com \
--cc=alex.james@broadcom.com \
--cc=alexey.amakhalov@broadcom.com \
--cc=ardb@kernel.org \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=bp@alien8.de \
--cc=brgerst@gmail.com \
--cc=dave.hansen@linux.intel.com \
--cc=doug.covelli@broadcom.com \
--cc=hpa@zytor.com \
--cc=jeffrey.sheldon@broadcom.com \
--cc=kai.huang@intel.com \
--cc=kees@kernel.org \
--cc=kevinloughlin@google.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-coco@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=rick.p.edgecombe@intel.com \
--cc=rppt@kernel.org \
--cc=tglx@linutronix.de \
--cc=tzimmermann@suse.de \
--cc=virtualization@lists.linux.dev \
--cc=x86@kernel.org \
--cc=xin3.li@intel.com \
/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).