Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1024688lqo; Fri, 17 May 2024 08:32:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX9FkBNk6wCTrlO7QvsIzNJheCJiih+jEqetlNWO6+o8djW3Rl11mZo4mbk/mDhfwdacV9nlntrTl5j5e6PJyqsG2YxK7NuhFeVZREIFQ== X-Google-Smtp-Source: AGHT+IFcCa4OROMJNlQfOZ7gee9691ou8KSniXVx8paEjjDXgn3AjII2Fg+8ed0+uLhHzI7HLgMp X-Received: by 2002:a05:6a20:9745:b0:1af:d44d:e7a6 with SMTP id adf61e73a8af0-1afde0af5e9mr19530936637.11.1715959943935; Fri, 17 May 2024 08:32:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715959943; cv=pass; d=google.com; s=arc-20160816; b=YClNLpp2gE8BuRGa1Qv8V5gmcx1/LrpIqljilEN0UgcEVZd57qrnAFR3W7bLdbFyLB b7fm5KpuBVpWWyU+mB/MmAOoNGnwhd5ri0DLtFHVo4TZxMfAHZZOt2TzqgAc8wghJqMw zVAM4eJNp2yLG0QMWuVaI1CICt5s3png3dlqJEGBBLFmiBEf4yCw2BV0r4nEPMqXiVOz g4RSbTIosHYz1Bw0por8wrMZuLSNpY6bLXKC8TzYu8XCWWR0/7UxeTpabcZEtOmYKK37 a7tq3k2HdEN195t7n4nXEXdW43L5o58P8snjOzbLk/pYQZpNb7ZIFw7OF9WHRNwCs/Gd V0vQ== 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=ryp3rjsprAoFnDYY+PFdoUs0WzkNVX18PvpJ2weJ9PI=; fh=hXU1gnBYTQtxPAarsVIsRjsd20EbUeSZmvMOiujEIyU=; b=sJ6XGCOW5V3VFNGcz4gaCGLehHFHR3opYJNAA5ADMme+G2KRUfrYV19IGSZ+BbJmpf 7vkWyGrVsP0oU9fAtDKVAO2sEIY7YhtB8Jn7nnnuzFzEEIx4mCUjv0OyXxqmb9BGzn3h H1H+GQrIxEPAViaalX2iB8XYYejDX0FS6VDnk5lmAk3+HjW5F1OIJKq/edTWGPW4G/19 2FBeQXZYYBV56IfcNfrLoFaQ/7LSf2oOTfx3ydDWNFnNPtpFDmmdZu+kRxvbhC3D2NdG E0rttCxZm3wd3oBVo5oA7aMfFo43yHX4CEpJ0oZUy1/zwVDMrW0SYxBKuiG/trnOPKFo d42w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="cfZGWAD/"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-182186-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182186-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-65a742ad5adsi3576082a12.654.2024.05.17.08.32.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 08:32:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-182186-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="cfZGWAD/"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-182186-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182186-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 38CF6B231E1 for ; Fri, 17 May 2024 14:20:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4F0046A33F; Fri, 17 May 2024 14:20:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="cfZGWAD/" 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 E77D56024B; Fri, 17 May 2024 14:19:59 +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=1715955601; cv=none; b=o0ZDC8bDokFascb4zrOm7da/Uegea7KaK/yZB40esYc/YGUDSy2WOMPN6+VDyDCsl7w0cT/9EEO1ydPOdvza52vipRVkPMoDtKOfc0g1hlPkw4B4re1M8qm1gH8GkSdgMzKwuTeDq6c4tjpYHeily9R8rBBnBjRkSAzD5mkUnkY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715955601; c=relaxed/simple; bh=C22Kxw6sw8vKzGrlwtwyA3njMblbtBv6zILkHx7dXVQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hh6WGZhrbnPpV0Ci2b9o+wOEnk1QZDIcwgjQk65V4CDi07mcaVCU5Yc/QR7i0yde0Dib4cBamLRNivpIr8sSN+JbvvgoOYruifduGZfQDEcTYtSNj+wLv7EGF2bSQFuqQJQqiTN8iz6z0qv0P8TnWpg4nl57uPYQR9jMAWU7rQ4= 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=cfZGWAD/; 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=1715955600; x=1747491600; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=C22Kxw6sw8vKzGrlwtwyA3njMblbtBv6zILkHx7dXVQ=; b=cfZGWAD/+kpV83pHG0qYw/YTYX39kFo/PUuNakrmYGaXLFnLW/wF97Od qNn2rT7aR/9z+al1eZWd9gG8pyXHZRgiDRQ5uj55/VfJlKB5YaqzU+Gn4 95JTAH+Vzp/QepdaCU0Nioy2eN5GCoWczhlHnJEyAqr9Q89pPkVuuUdBI fHlHDf5/B43x/x1DQoC3Q8fuI9HAoVBHIrWus6kkc7lod6tr+re6j32uq dbiCP0dPfG8ytL0hDx3Ir4QLmAmQE1XX9/FkGhz7MtOg4i0rGIeaBD7oL ZXFvkabk82RMJxdgbFtlnPi+KiB7JajSG1W0EhQRG0GUCyW3ITYLBOyMo g==; X-CSE-ConnectionGUID: yjNnK90jSGKtMY4N4OHp1w== X-CSE-MsgGUID: JBD6cxc9TFq6hou8nCvk0A== X-IronPort-AV: E=McAfee;i="6600,9927,11075"; a="22808611" X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="22808611" 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: eaFtlg1vR2Cyl5mlkS8bqA== X-CSE-MsgGUID: kCX6iRTtR7iVkWQawvVEgw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="69253380" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa001.jf.intel.com with ESMTP; 17 May 2024 07:19:55 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id DEBC4C4D; Fri, 17 May 2024 17:19:49 +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 06/20] x86/tdx: Convert MSR write handling to use new TDVMCALL_0() Date: Fri, 17 May 2024 17:19:24 +0300 Message-ID: <20240517141938.4177174-7-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 Use newly introduced TDVMCALL_0() instead of __tdx_hypercall() to handle MSR write emulation. It cuts code bloat substantially: Function old new delta tdx_handle_virt_exception 1947 1819 -128 Signed-off-by: Kirill A. Shutemov --- arch/x86/coco/tdx/tdx.c | 9 ++------- arch/x86/hyperv/ivm.c | 9 ++------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 32c519d096de..f59a2b3500db 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -399,19 +399,14 @@ static int read_msr(struct pt_regs *regs, struct ve_info *ve) static int write_msr(struct pt_regs *regs, struct ve_info *ve) { - struct tdx_module_args args = { - .r10 = TDX_HYPERCALL_STANDARD, - .r11 = hcall_func(EXIT_REASON_MSR_WRITE), - .r12 = regs->cx, - .r13 = (u64)regs->dx << 32 | regs->ax, - }; + u64 val = (u64)regs->dx << 32 | regs->ax; /* * Emulate the MSR write via hypercall. More info about ABI * can be found in TDX Guest-Host-Communication Interface * (GHCI) section titled "TDG.VP.VMCALL". */ - if (__tdx_hypercall(&args)) + if (TDVMCALL_0(hcall_func(EXIT_REASON_MSR_WRITE), regs->cx, val, 0, 0)) return -EIO; return ve_instr_len(ve); diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index 3e2cbfb2203d..18d0892d9fc4 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -385,14 +385,9 @@ 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_module_args args = { - .r10 = TDX_HYPERCALL_STANDARD, - .r11 = EXIT_REASON_MSR_WRITE, - .r12 = msr, - .r13 = val, - }; + u64 ret; - u64 ret = __tdx_hypercall(&args); + ret = TDVMCALL_0(hcall_func(EXIT_REASON_MSR_WRITE), msr, val, 0, 0); WARN_ONCE(ret, "Failed to emulate MSR write: %lld\n", ret); } -- 2.43.0