From nobody Tue Dec 16 13:50:32 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 694E0C001E0 for ; Tue, 15 Aug 2023 11:03:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234141AbjHOLDd (ORCPT ); Tue, 15 Aug 2023 07:03:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236579AbjHOLCv (ORCPT ); Tue, 15 Aug 2023 07:02:51 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A996E6B for ; Tue, 15 Aug 2023 04:02:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692097370; x=1723633370; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=g+SdGmkhBqb4q9MhU3mskt3eoHzcTLLDhyiH7XROQZE=; b=RVeoa4qYkowLklS0FfYK29XFD4zDeGKWrl0EhxMzbY9fgxV9cV3ouVcM QD5aT4lrJFM6x0xZ/fsg/tuUh3p6JNoTWY9ofiU9yd1/bKtKYELJnlBJS HWQwPzoMNdOBM2Ab3Vkfkm7BXaiJCbs/xJLhcYqWBS+JQJ8x3xUrsteDr AAst+1DCbY7E9ejarH8Yc34uvmA1QwUJvLAzPwqgu5FKH4yKGqryfXSss qSl5Q+n723+uDlwohTo+vRgyz8RvXxuaPf8b4ERPqU3raViOoOzrDf3DM xpWHh5yJCqIQaJEmwCIUl7i1dKafMBUbno4n1WQk+zOscGcBIqLiPzz6T Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10802"; a="436148358" X-IronPort-AV: E=Sophos;i="6.01,174,1684825200"; d="scan'208";a="436148358" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Aug 2023 04:02:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10802"; a="763236174" X-IronPort-AV: E=Sophos;i="6.01,174,1684825200"; d="scan'208";a="763236174" Received: from fwafula-mobl.amr.corp.intel.com (HELO khuang2-desk.gar.corp.intel.com) ([10.212.73.197]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Aug 2023 04:02:46 -0700 From: Kai Huang To: peterz@infradead.org, kirill.shutemov@linux.intel.com, linux-kernel@vger.kernel.org Cc: dave.hansen@intel.com, tglx@linutronix.de, bp@alien8.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, seanjc@google.com, pbonzini@redhat.com, isaku.yamahata@intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, n.borisov.lkml@gmail.com, kai.huang@intel.com Subject: [PATCH v4 09/12] x86/tdx: Remove 'struct tdx_hypercall_args' Date: Tue, 15 Aug 2023 23:02:03 +1200 Message-ID: <798dad5ce24e9d745cf0e16825b75ccc433ad065.1692096753.git.kai.huang@intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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(). Cc: Kirill A. Shutemov Cc: Dave Hansen Cc: Peter Zijlstra Suggested-by: Peter Zijlstra Signed-off-by: Kai Huang Reviewed-by: Kirill A. Shutemov --- arch/x86/boot/compressed/tdx.c | 4 ++-- arch/x86/coco/tdx/tdx-shared.c | 37 ++++++------------------------- arch/x86/coco/tdx/tdx.c | 16 ++++++------- arch/x86/include/asm/shared/tdx.h | 25 ++------------------- 4 files changed, 19 insertions(+), 63 deletions(-) diff --git a/arch/x86/boot/compressed/tdx.c b/arch/x86/boot/compressed/tdx.c index bc03eae2c560..8451d6a1030c 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 344b3818f4c3..78e413269791 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 731d164e2421..6311d843cbc5 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, diff --git a/arch/x86/include/asm/shared/tdx.h b/arch/x86/include/asm/share= d/tdx.h index 188e8bf3332c..74fc466dfdcd 100644 --- a/arch/x86/include/asm/shared/tdx.h +++ b/arch/x86/include/asm/shared/tdx.h @@ -83,29 +83,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 @@ -113,7 +92,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, --=20 2.41.0