Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1023860lqo; Fri, 17 May 2024 08:31:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV/1UQPSLHXwadX1BAkvcRNH5mkwHX3GGLpbRZ9dbRrA90Eqcc+7MBq2E2ddxpjkTbKgYT94tGcDqNQ/C3btLfla346NVquZdkrYIIbog== X-Google-Smtp-Source: AGHT+IHqAunQwY1wB8wzxPMhB9WOY9cyAjWP4BNPIZuHbTZhA+crUzo6AVyAYuQVQtEQeXVXXIcv X-Received: by 2002:a05:6a20:f397:b0:1af:ad46:cd4a with SMTP id adf61e73a8af0-1afde09f3c5mr23061729637.12.1715959874054; Fri, 17 May 2024 08:31:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715959874; cv=pass; d=google.com; s=arc-20160816; b=fuC1Z/zg2QQoNQ7Cr4cvy6kg/ZtUPRnCvV5lVhBRdQpLbt4Jd+VcS37f/CgF8t7NmH 7moaFTHyL6Qrzn0ZSMCWE2Oa4mLCvmNM206Nk6zX/pCPnvokKVbAyX475tFHi27ttvzO CHYFWMojPG6ZiiFfAMXNbr5q/Wj5sIc8+04YgXecK8Nm3kYkpp4BQyvu77roXVzMwbu/ FdwMBCkNpAKTm1bCjfOZphu2PAbgcrpC4eaFErm2x5pRY2XDlsUUFtqH+MYgqg2eZNXu +AF3BOM7pimLGXBIJh6CMyMUVQyb12GCnSUBT2LFrPhrRmbqD12P1V8cVtP31S1U+wPC 7aDA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=EP9abt5CNc7z1+/5Ta9UTJ4ddUWJetcAofoFW8HTRVg=; fh=hXU1gnBYTQtxPAarsVIsRjsd20EbUeSZmvMOiujEIyU=; b=xVKRaQqUYmj7YlKQm3MMqI6vNbSSRMXXUP2Q+ocYd7iYRHJKWXSrkz4abawg5+5ocu chg6fIKYtMjkXTzxJ2OaFeN3TCRIYdwyXeqelfnm1X1ekWkKP2rhLPde0DZ9ruO4rKUM f2bXmaX7F2onH9UbolpSmDkfa4dEeBokhRb8+e5pC6Qd0wKvGICU5GI7Yb1YIP+1kQcq 12HCW29EqnFzmVk/eVIzgmb/BemHabzrS4g69+U/8vnw6sQ3EVYHxhGM7aFH7rawXJCo PVzEv/3ZhXNBkY0Oe3Wav9I/34oAfEr6XOn2VyJ7l0lPDBlv+5Xz9BBG1D8pAEcy71J1 9/hQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nApBNqp0; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-182188-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182188-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-6f4d2aeee63si17476338b3a.163.2024.05.17.08.31.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 08:31:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-182188-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nApBNqp0; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-182188-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182188-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 8E503285BD0 for ; Fri, 17 May 2024 14:21:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4544F5CDE6; Fri, 17 May 2024 14:20:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="nApBNqp0" 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 61EA165189; 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=E5mMhO5ugIjVmi9h1D5OjB+21qq54X4J9osPCeAI3ndzPJlPNXzKlGWvPtPmPnN9gXfw3pDsaanTnQcz4n5XFQ2GLL9s2uZb0YBmdlnf6Jci2KK97JHDut6+ixifYRrKzOEs/h7nDe1v1qs3lhCiFYdFmJvuUSTUuJmwJx/tRcE= 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=nApBNqp0; 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715955601; x=1747491601; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CcujIUVW1JuDql5JHxHA+AIa8M0XntpfPmL9/r3uwTE=; b=nApBNqp0+GlOPdZLvn6cE696oBdlX3yrlq+7lUsSJdUGsPtlXfDhAF9n OL3rBrtBe1z1M1mtWSHimm5L9f1NnXniFHB1UJVICWFr1nbmdYlLR79hx U9aC09ww6oEKh9DOB5S9xFdZisXRYzdarNA1orIJlkyOKB3UoiKALYThh mSWsW6Gd+K9voDtVRgAWPgOGsWd4K1ra/99XOg6DR9lEeRTdm4Bzr9sDM adeF3Q3pWmGPgovfqb9VVGL4d1sFwZc7UA3fENnBBB4RP4vTuACCQALMl xTm2hPHGqBuRlrcMRPwq5PZ1dFq+hBFYSZSmZ3aIREZpbPNt8TFiPJDZi g==; X-CSE-ConnectionGUID: SOBTzdVRSq2bDFaFWiT/0A== X-CSE-MsgGUID: Lx/P0NlGRfu3CNklrWwDRg== X-IronPort-AV: E=McAfee;i="6600,9927,11075"; a="22808642" X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="22808642" 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-kernel@vger.kernel.org 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