From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8F3269D31 for ; Fri, 17 May 2024 14:20:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715955603; cv=none; b=HoOxps++1gD29nlWM5eMjVZkM3L+iug6IrBPPrcAhjumoeCLV2J/iV9polP27jRU/vVf1xW3KwUADZIJOU2hyXGsNWNK7KihOim1WW4l/rKzlqYH3o93PwAouqV7FjMVQFoFsfWSPUQlsOWqISmIUE/plfjDJlYaUUAK8ztJYZ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715955603; c=relaxed/simple; bh=CcujIUVW1JuDql5JHxHA+AIa8M0XntpfPmL9/r3uwTE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jHuqPEkyN6p+BP1OnwGbgA8U1tMswwKGoB4SVmf7k2ZBhWk81o2dw9uMRYsSEP/tLe7092SslE7G+Zpi/KsskDZZDGX5z4FyvTqOrBTMbTNyhyDXnexyc4oXEY44+gGB/tqMDAg/lGth+PWzRMWOboVXfO2drxcElAO0O7IzKB0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.helo=mgamail.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ZnC+YYC6; arc=none smtp.client-ip=192.198.163.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.helo=mgamail.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ZnC+YYC6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715955602; x=1747491602; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CcujIUVW1JuDql5JHxHA+AIa8M0XntpfPmL9/r3uwTE=; b=ZnC+YYC610PccH4IYQecFO5JgjzVsAmoPxuIi/yPCFMPMpKLiGQHDlaq QgLns4JWs4G1Zo4+ASW+RMPH4cf3JiQ2ZlT6FW+IZOtYIAprg9q2iq35D 3yjyCBitMOTK+ZlKPVD+n3ZqtzTTKnPRSEr5OfexpF9sVwSnELFbfv9bn ouTxB6SDjU/FFz7TIkrXPdOiuGUvL2AwpVQN7G9SjSMiEoqRgEXpm4gnd J19MOpwR1r2OXjGTPYipHwfg4u9acDKfIl4cgMjnWCLyOvkj+c26dZGW8 Njr9XcpsIbmcGzIaA4RSX59/0CZH/hzVhKDofKUDt3Pns89DJcFpCnvQg w==; X-CSE-ConnectionGUID: XNhl0/EpTDKZJhWPLjjOjg== X-CSE-MsgGUID: PQtJ6/62SEuvMUcCjkhUSw== X-IronPort-AV: E=McAfee;i="6600,9927,11075"; a="22808649" X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="22808649" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 May 2024 07:20:00 -0700 X-CSE-ConnectionGUID: IOisXNc3SImubkKPm9L17Q== X-CSE-MsgGUID: tE0r8QJERR+mBnF5pQKlxA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="69253385" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa001.jf.intel.com with ESMTP; 17 May 2024 07:19:56 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 4D265AD3; Fri, 17 May 2024 17:19:50 +0300 (EEST) From: "Kirill A. Shutemov" To: Sean Christopherson , Paolo Bonzini , Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Josh Poimboeuf , Peter Zijlstra Cc: linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCH 13/20] x86/tdx: Rewrite hv_tdx_hypercall() without __tdx_hypercall() Date: Fri, 17 May 2024 17:19:31 +0300 Message-ID: <20240517141938.4177174-14-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240517141938.4177174-1-kirill.shutemov@linux.intel.com> References: <20240517141938.4177174-1-kirill.shutemov@linux.intel.com> Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Rewrite hv_tdx_hypercall() in assembly to remove one more __tdx_hypercall() user. tdvmcall_trampoline() cannot be used here as Hyper-V uses R8 and RDX to pass down parameters which is incompatible with tdvmcall_trampoline() The rewrite cuts code bloat substantially: Function old new delta hv_tdx_hypercall 171 42 -129 Signed-off-by: Kirill A. Shutemov --- arch/x86/coco/tdx/tdcall.S | 30 ++++++++++++++++++++++++++++++ arch/x86/hyperv/ivm.c | 14 -------------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/arch/x86/coco/tdx/tdcall.S b/arch/x86/coco/tdx/tdcall.S index 269e5789672a..5b60b9c8799f 100644 --- a/arch/x86/coco/tdx/tdcall.S +++ b/arch/x86/coco/tdx/tdcall.S @@ -138,3 +138,33 @@ SYM_FUNC_START(tdvmcall_report_fatal_error) ud2 SYM_FUNC_END(tdvmcall_report_fatal_error) + +#ifdef CONFIG_HYPERV +/* + * hv_tdx_hypercall() - Issue Hyper-V hypercall + * + * RDI - Hypercall ID + * RSI - Parameter 1 + * RCX - Parameter 2 + */ +SYM_FUNC_START(hv_tdx_hypercall) + movq %rdi, %r10 + movq %rsi, %rdx + movq %rcx, %r8 + + movq $TDG_VP_VMCALL, %rax + movq $(TDX_R8 | TDX_R10 | TDX_RDX), %rcx + + tdcall + + /* TDG.VP.VMCALL never fails on correct use. Panic if it fails. */ + testq %rax, %rax + jnz .Lpanic_hv + + movq %r11, %rax + + RET +.Lpanic_hv: + ud2 +SYM_FUNC_END(hv_tdx_hypercall) +#endif diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index 18d0892d9fc4..562980e19d68 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -401,20 +401,6 @@ static void hv_tdx_msr_read(u64 msr, u64 *val) if (WARN_ONCE(ret, "Failed to emulate MSR read: %lld\n", ret)) *val = 0; } - -u64 hv_tdx_hypercall(u64 control, u64 param1, u64 param2) -{ - struct tdx_module_args args = { }; - - args.r10 = control; - args.rdx = param1; - args.r8 = param2; - - (void)__tdx_hypercall(&args); - - return args.r11; -} - #else static inline void hv_tdx_msr_write(u64 msr, u64 value) {} static inline void hv_tdx_msr_read(u64 msr, u64 *value) {} -- 2.43.0