From: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
To: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.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>,
"K. Y. Srinivasan" <kys@microsoft.com>,
Haiyang Zhang <haiyangz@microsoft.com>,
Wei Liu <wei.liu@kernel.org>, Dexuan Cui <decui@microsoft.com>,
Josh Poimboeuf <jpoimboe@kernel.org>,
Peter Zijlstra <peterz@infradead.org>
Cc: linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-hyperv@vger.kernel.org,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Subject: [PATCH 03/20] x86/tdx: Convert port I/O handling to use new TDVMCALL macros
Date: Fri, 17 May 2024 17:19:21 +0300 [thread overview]
Message-ID: <20240517141938.4177174-4-kirill.shutemov@linux.intel.com> (raw)
In-Reply-To: <20240517141938.4177174-1-kirill.shutemov@linux.intel.com>
Use newly introduced TDVMCALL_0() and TDVMCALL_1() instead of
__tdx_hypercall() to handle port I/O in TDX guest.
It cuts handle_io() size in half:
Function old new delta
handle_io 436 202 -234
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
---
arch/x86/boot/compressed/tdx.c | 26 +++++++-------------------
arch/x86/coco/tdx/tdx.c | 23 +++++++----------------
arch/x86/include/asm/shared/tdx.h | 4 ++++
3 files changed, 18 insertions(+), 35 deletions(-)
diff --git a/arch/x86/boot/compressed/tdx.c b/arch/x86/boot/compressed/tdx.c
index 8451d6a1030c..0ae05edc7d42 100644
--- a/arch/x86/boot/compressed/tdx.c
+++ b/arch/x86/boot/compressed/tdx.c
@@ -18,32 +18,20 @@ void __tdx_hypercall_failed(void)
static inline unsigned int tdx_io_in(int size, u16 port)
{
- struct tdx_module_args args = {
- .r10 = TDX_HYPERCALL_STANDARD,
- .r11 = hcall_func(EXIT_REASON_IO_INSTRUCTION),
- .r12 = size,
- .r13 = 0,
- .r14 = port,
- };
+ u64 out;
- if (__tdx_hypercall(&args))
+ if (TDVMCALL_1(hcall_func(EXIT_REASON_IO_INSTRUCTION),
+ size, TDX_PORT_READ, port, 0, out)) {
return UINT_MAX;
+ }
- return args.r11;
+ return out;
}
static inline void tdx_io_out(int size, u16 port, u32 value)
{
- struct tdx_module_args args = {
- .r10 = TDX_HYPERCALL_STANDARD,
- .r11 = hcall_func(EXIT_REASON_IO_INSTRUCTION),
- .r12 = size,
- .r13 = 1,
- .r14 = port,
- .r15 = value,
- };
-
- __tdx_hypercall(&args);
+ TDVMCALL_0(hcall_func(EXIT_REASON_IO_INSTRUCTION),
+ size, TDX_PORT_WRITE, port, value);
}
static inline u8 tdx_inb(u16 port)
diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c
index cadd583d6f62..6e0e5648ebd1 100644
--- a/arch/x86/coco/tdx/tdx.c
+++ b/arch/x86/coco/tdx/tdx.c
@@ -21,10 +21,6 @@
#define EPT_READ 0
#define EPT_WRITE 1
-/* Port I/O direction */
-#define PORT_READ 0
-#define PORT_WRITE 1
-
/* See Exit Qualification for I/O Instructions in VMX documentation */
#define VE_IS_IO_IN(e) ((e) & BIT(3))
#define VE_GET_IO_SIZE(e) (((e) & GENMASK(2, 0)) + 1)
@@ -612,14 +608,7 @@ static int handle_mmio(struct pt_regs *regs, struct ve_info *ve)
static bool handle_in(struct pt_regs *regs, int size, int port)
{
- struct tdx_module_args args = {
- .r10 = TDX_HYPERCALL_STANDARD,
- .r11 = hcall_func(EXIT_REASON_IO_INSTRUCTION),
- .r12 = size,
- .r13 = PORT_READ,
- .r14 = port,
- };
- u64 mask = GENMASK(BITS_PER_BYTE * size, 0);
+ u64 mask, out;
bool success;
/*
@@ -627,12 +616,14 @@ static bool handle_in(struct pt_regs *regs, int size, int port)
* in TDX Guest-Host-Communication Interface (GHCI) section titled
* "TDG.VP.VMCALL<Instruction.IO>".
*/
- success = !__tdx_hypercall(&args);
+ success = !TDVMCALL_1(hcall_func(EXIT_REASON_IO_INSTRUCTION),
+ size, TDX_PORT_READ, port, 0, out);
/* Update part of the register affected by the emulated instruction */
+ mask = GENMASK(BITS_PER_BYTE * size, 0);
regs->ax &= ~mask;
if (success)
- regs->ax |= args.r11 & mask;
+ regs->ax |= out & mask;
return success;
}
@@ -646,8 +637,8 @@ static bool handle_out(struct pt_regs *regs, int size, int port)
* in TDX Guest-Host-Communication Interface (GHCI) section titled
* "TDG.VP.VMCALL<Instruction.IO>".
*/
- return !_tdx_hypercall(hcall_func(EXIT_REASON_IO_INSTRUCTION), size,
- PORT_WRITE, port, regs->ax & mask);
+ return !TDVMCALL_0(hcall_func(EXIT_REASON_IO_INSTRUCTION),
+ size, TDX_PORT_WRITE, port, regs->ax & mask);
}
/*
diff --git a/arch/x86/include/asm/shared/tdx.h b/arch/x86/include/asm/shared/tdx.h
index ddf2cc4a45da..46c299dc9cf0 100644
--- a/arch/x86/include/asm/shared/tdx.h
+++ b/arch/x86/include/asm/shared/tdx.h
@@ -72,6 +72,10 @@
#define TDX_PS_1G 2
#define TDX_PS_NR (TDX_PS_1G + 1)
+/* Port I/O direction */
+#define TDX_PORT_READ 0
+#define TDX_PORT_WRITE 1
+
#ifndef __ASSEMBLY__
#include <linux/compiler_attributes.h>
--
2.43.0
next prev parent reply other threads:[~2024-05-17 14:19 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-17 14:19 [PATCH 00/20] x86/tdx: Rewrite TDCALL wrappers Kirill A. Shutemov
2024-05-17 14:19 ` [PATCH 01/20] x86/tdx: Introduce tdvmcall_trampoline() Kirill A. Shutemov
2024-05-17 15:21 ` Dave Hansen
2024-05-20 10:32 ` Kirill A. Shutemov
2024-05-20 15:49 ` Dave Hansen
2024-05-17 17:02 ` Paolo Bonzini
2024-05-20 10:35 ` Kirill A. Shutemov
2024-05-17 14:19 ` [PATCH 02/20] x86/tdx: Add macros to generate TDVMCALL wrappers Kirill A. Shutemov
2024-05-17 16:54 ` Paolo Bonzini
2024-05-20 10:35 ` Kirill A. Shutemov
2024-05-17 14:19 ` Kirill A. Shutemov [this message]
2024-05-17 15:28 ` [PATCH 03/20] x86/tdx: Convert port I/O handling to use new TDVMCALL macros Dave Hansen
2024-05-17 17:37 ` Paolo Bonzini
2024-05-17 14:19 ` [PATCH 04/20] x86/tdx: Convert HLT handling to use new TDVMCALL_0() Kirill A. Shutemov
2024-05-17 14:19 ` [PATCH 05/20] x86/tdx: Convert MSR read handling to use new TDVMCALL_1() Kirill A. Shutemov
2024-05-28 5:33 ` Wei Liu
2024-05-17 14:19 ` [PATCH 06/20] x86/tdx: Convert MSR write handling to use new TDVMCALL_0() Kirill A. Shutemov
2024-05-28 5:33 ` Wei Liu
2024-05-17 14:19 ` [PATCH 07/20] x86/tdx: Convert CPUID handling to use new TDVMCALL_4() Kirill A. Shutemov
2024-05-17 14:19 ` [PATCH 08/20] x86/tdx: Convert MMIO handling to use new TDVMCALL macros Kirill A. Shutemov
2024-05-17 14:19 ` [PATCH 09/20] x86/tdx: Convert MAP_GPA hypercall " Kirill A. Shutemov
2024-05-17 14:19 ` [PATCH 10/20] x86/tdx: Convert GET_QUOTE " Kirill A. Shutemov
2024-05-17 14:19 ` [PATCH 11/20] x86/tdx: Rewrite tdx_panic() without __tdx_hypercall() Kirill A. Shutemov
2024-05-17 14:19 ` [PATCH 12/20] x86/tdx: Rewrite tdx_kvm_hypercall() " Kirill A. Shutemov
2024-05-17 14:19 ` [PATCH 13/20] x86/tdx: Rewrite hv_tdx_hypercall() " Kirill A. Shutemov
2024-05-17 14:19 ` [PATCH 14/20] x86/tdx: Add macros to generate TDCALL wrappers Kirill A. Shutemov
2024-05-17 17:04 ` Paolo Bonzini
2024-05-17 14:19 ` [PATCH 15/20] x86/tdx: Convert PAGE_ACCEPT tdcall to use new TDCALL_0() macro Kirill A. Shutemov
2024-05-17 14:19 ` [PATCH 16/20] x86/tdx: Convert VP_INFO tdcall to use new TDCALL_5() macro Kirill A. Shutemov
2024-05-17 15:57 ` Dave Hansen
2024-05-20 11:02 ` Kirill A. Shutemov
2024-05-17 14:19 ` [PATCH 17/20] x86/tdx: Convert VM_RD/VM_WR tdcalls to use new TDCALL macros Kirill A. Shutemov
2024-05-17 16:07 ` Dave Hansen
2024-05-17 14:19 ` [PATCH 18/20] x86/tdx: Convert VP_VEINFO_GET tdcall to use new TDCALL_5() macro Kirill A. Shutemov
2024-05-17 14:19 ` [PATCH 19/20] x86/tdx: Convert MR_REPORT tdcall to use new TDCALL_0() macro Kirill A. Shutemov
2024-05-17 14:19 ` [PATCH 20/20] x86/tdx: Remove old TDCALL wrappers Kirill A. Shutemov
2024-05-17 15:18 ` [PATCH 00/20] x86/tdx: Rewrite " Dave Hansen
2024-05-20 11:56 ` Huang, Kai
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=20240517141938.4177174-4-kirill.shutemov@linux.intel.com \
--to=kirill.shutemov@linux.intel.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=decui@microsoft.com \
--cc=haiyangz@microsoft.com \
--cc=hpa@zytor.com \
--cc=jpoimboe@kernel.org \
--cc=kys@microsoft.com \
--cc=linux-coco@lists.linux.dev \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=wei.liu@kernel.org \
--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