From nobody Fri Dec 19 04:53:09 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6EE5FEE3F3F for ; Tue, 12 Sep 2023 23:44:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237923AbjILXob (ORCPT ); Tue, 12 Sep 2023 19:44:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235706AbjILXoZ (ORCPT ); Tue, 12 Sep 2023 19:44:25 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B29631705; Tue, 12 Sep 2023 16:44:21 -0700 (PDT) Date: Tue, 12 Sep 2023 23:44:19 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694562260; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RZfpFEZqxiG28iaHo1HAONvFQhCKjL16UIOL0uhKqPs=; b=bVnoVoxUkMHKWf1JaiX89ZVpggkFZ2tbqkoibPCAjy1EQ7xuQL1uAaeRPE1wdTf9Afj15S OjkOJS9golHl3Tt3jcLvPNKO49Gh6JkbsOr9PVn/iLMYqhNhwn0gPQVlIR5wbPffGR+LKO El12qUOqkzkVnOOWgszJ1bqlPoRQg8/tDwrIRQidOUOrpkU4DaaTGYcA0xv2EfAA+EK4UX ZQp5ClwZ/0Hva7lMY2IJcvr9EDMmFLoTqSeieYe44r22YVeu/OL5OVZFfQxtjFqVvYaPZu XJT1jenLdW2yW+bZ14jbYQ3jj9tnHKDA+omRasLSpRBQe+KgqVSnGeKZvQNa6w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694562260; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RZfpFEZqxiG28iaHo1HAONvFQhCKjL16UIOL0uhKqPs=; b=DKiSDJz5RG257mXLGWgKopRLFprhb3Ai84nhA2DbRaGwtZFJgQP6U/WSFgI3Sas8xpbsaJ aHUdEFPk74JUoYAA== From: "tip-bot2 for Kai Huang" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/tdx] x86/tdx: Remove 'struct tdx_hypercall_args' Cc: Peter Zijlstra , Kai Huang , Dave Hansen , "Kirill A. Shutemov" , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <169456225971.27769.51743966979126683.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/tdx branch of tip: Commit-ID: 8a8544bde858e5d62d79df6baaa387e0b6587dc7 Gitweb: https://git.kernel.org/tip/8a8544bde858e5d62d79df6baaa387e0b= 6587dc7 Author: Kai Huang AuthorDate: Tue, 15 Aug 2023 23:02:03 +12:00 Committer: Dave Hansen CommitterDate: Tue, 12 Sep 2023 16:30:14 -07:00 x86/tdx: Remove 'struct tdx_hypercall_args' Now 'struct tdx_hypercall_args' is basically 'struct tdx_module_args' minus RCX. Although from __tdx_hypercall()'s perspective RCX isn't used as shared register thus not part of input/output registers, it's not worth to have a separate structure just due to one register. Remove the 'struct tdx_hypercall_args' and use 'struct tdx_module_args' instead in __tdx_hypercall() related code. This also saves the memory copy between the two structures within __tdx_hypercall(). Suggested-by: Peter Zijlstra Signed-off-by: Kai Huang Signed-off-by: Dave Hansen Reviewed-by: Kirill A. Shutemov Acked-by: Peter Zijlstra (Intel) Link: https://lore.kernel.org/all/798dad5ce24e9d745cf0e16825b75ccc433ad065.= 1692096753.git.kai.huang%40intel.com --- arch/x86/boot/compressed/tdx.c | 4 +-- arch/x86/coco/tdx/tdx-shared.c | 37 +++++------------------------- arch/x86/coco/tdx/tdx.c | 18 +++++++-------- arch/x86/hyperv/ivm.c | 6 ++--- arch/x86/include/asm/shared/tdx.h | 25 +------------------- 5 files changed, 23 insertions(+), 67 deletions(-) diff --git a/arch/x86/boot/compressed/tdx.c b/arch/x86/boot/compressed/tdx.c index bc03eae..8451d6a 100644 --- a/arch/x86/boot/compressed/tdx.c +++ b/arch/x86/boot/compressed/tdx.c @@ -18,7 +18,7 @@ void __tdx_hypercall_failed(void) =20 static inline unsigned int tdx_io_in(int size, u16 port) { - struct tdx_hypercall_args args =3D { + struct tdx_module_args args =3D { .r10 =3D TDX_HYPERCALL_STANDARD, .r11 =3D hcall_func(EXIT_REASON_IO_INSTRUCTION), .r12 =3D size, @@ -34,7 +34,7 @@ static inline unsigned int tdx_io_in(int size, u16 port) =20 static inline void tdx_io_out(int size, u16 port, u32 value) { - struct tdx_hypercall_args args =3D { + struct tdx_module_args args =3D { .r10 =3D TDX_HYPERCALL_STANDARD, .r11 =3D hcall_func(EXIT_REASON_IO_INSTRUCTION), .r12 =3D size, diff --git a/arch/x86/coco/tdx/tdx-shared.c b/arch/x86/coco/tdx/tdx-shared.c index 344b381..78e4132 100644 --- a/arch/x86/coco/tdx/tdx-shared.c +++ b/arch/x86/coco/tdx/tdx-shared.c @@ -70,45 +70,22 @@ bool tdx_accept_memory(phys_addr_t start, phys_addr_t e= nd) return true; } =20 -noinstr u64 __tdx_hypercall(struct tdx_hypercall_args *args) +noinstr u64 __tdx_hypercall(struct tdx_module_args *args) { - struct tdx_module_args margs =3D { - .rcx =3D TDVMCALL_EXPOSE_REGS_MASK, - .rdx =3D args->rdx, - .r8 =3D args->r8, - .r9 =3D args->r9, - .r10 =3D args->r10, - .r11 =3D args->r11, - .r12 =3D args->r12, - .r13 =3D args->r13, - .r14 =3D args->r14, - .r15 =3D args->r15, - .rbx =3D args->rbx, - .rdi =3D args->rdi, - .rsi =3D args->rsi, - }; + /* + * For TDVMCALL explicitly set RCX to the bitmap of shared registers. + * The caller isn't expected to set @args->rcx anyway. + */ + args->rcx =3D TDVMCALL_EXPOSE_REGS_MASK; =20 /* * Failure of __tdcall_saved_ret() indicates a failure of the TDVMCALL * mechanism itself and that something has gone horribly wrong with * the TDX module. __tdx_hypercall_failed() never returns. */ - if (__tdcall_saved_ret(TDG_VP_VMCALL, &margs)) + if (__tdcall_saved_ret(TDG_VP_VMCALL, args)) __tdx_hypercall_failed(); =20 - args->r8 =3D margs.r8; - args->r9 =3D margs.r9; - args->r10 =3D margs.r10; - args->r11 =3D margs.r11; - args->r12 =3D margs.r12; - args->r13 =3D margs.r13; - args->r14 =3D margs.r14; - args->r15 =3D margs.r15; - args->rdi =3D margs.rdi; - args->rsi =3D margs.rsi; - args->rbx =3D margs.rbx; - args->rdx =3D margs.rdx; - /* TDVMCALL leaf return code is in R10 */ return args->r10; } diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 26b6c3d..3e6dbd2 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -48,7 +48,7 @@ noinstr void __noreturn __tdx_hypercall_failed(void) long tdx_kvm_hypercall(unsigned int nr, unsigned long p1, unsigned long p2, unsigned long p3, unsigned long p4) { - struct tdx_hypercall_args args =3D { + struct tdx_module_args args =3D { .r10 =3D nr, .r11 =3D p1, .r12 =3D p2, @@ -108,7 +108,7 @@ EXPORT_SYMBOL_GPL(tdx_mcall_get_report0); =20 static void __noreturn tdx_panic(const char *msg) { - struct tdx_hypercall_args args =3D { + struct tdx_module_args args =3D { .r10 =3D TDX_HYPERCALL_STANDARD, .r11 =3D TDVMCALL_REPORT_FATAL_ERROR, .r12 =3D 0, /* Error code: 0 is Panic */ @@ -230,7 +230,7 @@ static int ve_instr_len(struct ve_info *ve) =20 static u64 __cpuidle __halt(const bool irq_disabled) { - struct tdx_hypercall_args args =3D { + struct tdx_module_args args =3D { .r10 =3D TDX_HYPERCALL_STANDARD, .r11 =3D hcall_func(EXIT_REASON_HLT), .r12 =3D irq_disabled, @@ -274,7 +274,7 @@ void __cpuidle tdx_safe_halt(void) =20 static int read_msr(struct pt_regs *regs, struct ve_info *ve) { - struct tdx_hypercall_args args =3D { + struct tdx_module_args args =3D { .r10 =3D TDX_HYPERCALL_STANDARD, .r11 =3D hcall_func(EXIT_REASON_MSR_READ), .r12 =3D regs->cx, @@ -295,7 +295,7 @@ static int read_msr(struct pt_regs *regs, struct ve_inf= o *ve) =20 static int write_msr(struct pt_regs *regs, struct ve_info *ve) { - struct tdx_hypercall_args args =3D { + struct tdx_module_args args =3D { .r10 =3D TDX_HYPERCALL_STANDARD, .r11 =3D hcall_func(EXIT_REASON_MSR_WRITE), .r12 =3D regs->cx, @@ -315,7 +315,7 @@ static int write_msr(struct pt_regs *regs, struct ve_in= fo *ve) =20 static int handle_cpuid(struct pt_regs *regs, struct ve_info *ve) { - struct tdx_hypercall_args args =3D { + struct tdx_module_args args =3D { .r10 =3D TDX_HYPERCALL_STANDARD, .r11 =3D hcall_func(EXIT_REASON_CPUID), .r12 =3D regs->ax, @@ -357,7 +357,7 @@ static int handle_cpuid(struct pt_regs *regs, struct ve= _info *ve) =20 static bool mmio_read(int size, unsigned long addr, unsigned long *val) { - struct tdx_hypercall_args args =3D { + struct tdx_module_args args =3D { .r10 =3D TDX_HYPERCALL_STANDARD, .r11 =3D hcall_func(EXIT_REASON_EPT_VIOLATION), .r12 =3D size, @@ -486,7 +486,7 @@ static int handle_mmio(struct pt_regs *regs, struct ve_= info *ve) =20 static bool handle_in(struct pt_regs *regs, int size, int port) { - struct tdx_hypercall_args args =3D { + struct tdx_module_args args =3D { .r10 =3D TDX_HYPERCALL_STANDARD, .r11 =3D hcall_func(EXIT_REASON_IO_INSTRUCTION), .r12 =3D size, @@ -723,7 +723,7 @@ static bool tdx_map_gpa(phys_addr_t start, phys_addr_t = end, bool enc) } =20 while (retry_count < max_retries_per_page) { - struct tdx_hypercall_args args =3D { + struct tdx_module_args args =3D { .r10 =3D TDX_HYPERCALL_STANDARD, .r11 =3D TDVMCALL_MAP_GPA, .r12 =3D start, diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index e489835..c1088d3 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -384,7 +384,7 @@ static inline void hv_ghcb_msr_read(u64 msr, u64 *value= ) {} #ifdef CONFIG_INTEL_TDX_GUEST static void hv_tdx_msr_write(u64 msr, u64 val) { - struct tdx_hypercall_args args =3D { + struct tdx_module_args args =3D { .r10 =3D TDX_HYPERCALL_STANDARD, .r11 =3D EXIT_REASON_MSR_WRITE, .r12 =3D msr, @@ -398,7 +398,7 @@ static void hv_tdx_msr_write(u64 msr, u64 val) =20 static void hv_tdx_msr_read(u64 msr, u64 *val) { - struct tdx_hypercall_args args =3D { + struct tdx_module_args args =3D { .r10 =3D TDX_HYPERCALL_STANDARD, .r11 =3D EXIT_REASON_MSR_READ, .r12 =3D msr, @@ -414,7 +414,7 @@ static void hv_tdx_msr_read(u64 msr, u64 *val) =20 u64 hv_tdx_hypercall(u64 control, u64 param1, u64 param2) { - struct tdx_hypercall_args args =3D { }; + struct tdx_module_args args =3D { }; =20 args.r10 =3D control; args.rdx =3D param1; diff --git a/arch/x86/include/asm/shared/tdx.h b/arch/x86/include/asm/share= d/tdx.h index f53a419..b69886e 100644 --- a/arch/x86/include/asm/shared/tdx.h +++ b/arch/x86/include/asm/shared/tdx.h @@ -85,29 +85,8 @@ u64 __tdcall(u64 fn, struct tdx_module_args *args); u64 __tdcall_ret(u64 fn, struct tdx_module_args *args); u64 __tdcall_saved_ret(u64 fn, struct tdx_module_args *args); =20 -/* - * Used in __tdx_hypercall() to pass down and get back registers' values of - * the TDCALL instruction when requesting services from the VMM. - * - * This is a software only structure and not part of the TDX module/VMM AB= I. - */ -struct tdx_hypercall_args { - u64 r8; - u64 r9; - u64 r10; - u64 r11; - u64 r12; - u64 r13; - u64 r14; - u64 r15; - u64 rdi; - u64 rsi; - u64 rbx; - u64 rdx; -}; - /* Used to request services from the VMM */ -u64 __tdx_hypercall(struct tdx_hypercall_args *args); +u64 __tdx_hypercall(struct tdx_module_args *args); =20 /* * Wrapper for standard use of __tdx_hypercall with no output aside from @@ -115,7 +94,7 @@ u64 __tdx_hypercall(struct tdx_hypercall_args *args); */ static inline u64 _tdx_hypercall(u64 fn, u64 r12, u64 r13, u64 r14, u64 r1= 5) { - struct tdx_hypercall_args args =3D { + struct tdx_module_args args =3D { .r10 =3D TDX_HYPERCALL_STANDARD, .r11 =3D fn, .r12 =3D r12,