Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1023935lqo; Fri, 17 May 2024 08:31:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWhRV5O3UcBM+v8OBTYHjNp1HCyFtb5khz/wmskqdnPEiKmpmuLJTwdfnzocYoEQ/Mm/vq7qo5sTHwEHRCBcFdBLex5uJW/SpH1sGqoJg== X-Google-Smtp-Source: AGHT+IE+FZVzgW9F/nbsNwzF3+og47tpKJUUauSXF9mWBV/RyPH2FIRlmkwoUVabZZWGGQ2hkps7 X-Received: by 2002:a05:6a20:3212:b0:1af:86e4:bc99 with SMTP id adf61e73a8af0-1afde0b727bmr26553816637.10.1715959879671; Fri, 17 May 2024 08:31:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715959879; cv=pass; d=google.com; s=arc-20160816; b=Sip5D6VcqnFS+QQytMA04nLGPnjTMpehmXBVBn3XHjOGhrTCHenfiGf8waypa+vyk8 Dsz66Yd2U6zOI+SpULD3vvJANH4chyhfsHWwxddAscxtpYeqB5Z+OYk/8QxHIWXllmCD Rp0IjbqMLUPGtoMZKofpNdctzMMcNggHjrafSFflpI1RszSVXRlFS7yF8lAEdAgJ+Vl6 IXHuFjmStNtAbTFrZb/A9UhlEPMGJb72DyfjeGWR1QxsYg4KQ3py3g3zBomq02QDFejP ThHeKwOnXrDQBp3zlWfnQGzzkYKmV7wKIpfcPAt8zYB9/AL26VLCpsBPX7VTCUHaqI9w wU8Q== 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=Dp2DMdUh+AVk2e/ZwWPNOHZyw9kzpWrgpxbPwtnfR0Y=; fh=hXU1gnBYTQtxPAarsVIsRjsd20EbUeSZmvMOiujEIyU=; b=N6IA6A77pJRSyjivguzRot+XZnboYm0UHvz/Ji8ziM4Bd+uCufDXG4WNmUKpLCR7+Y oofRJdCw8ZOsO6dU4/EuHr4u0bJvupe9aHMdMUw4JiHen4gXG36V2eH+uJ/ZriyZeRxT gI5ZYfqFs/vuv0hnxv0oJLAv2KEnzJCqw88EyjHboaJI56cCfiPOHGDykTQrWmcWXMzF 2H5ZiumFOlev16V5MS/JJ9Y3SLK2hdgtiwlLgnqw36wA1AU+/7dBiPuXSQY9oJS73iea mV/1HNAocy8QfXJjsjyhdiXNBNaNFcVOKIObSvV9uXuGFyHMxVTRrYSzPbYK5yOO7DJ4 yslQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MnYNdrRH; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-182187-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182187-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. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6576d277482si4606860a12.190.2024.05.17.08.31.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 08:31:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-182187-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MnYNdrRH; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-182187-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182187-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 69495285808 for ; Fri, 17 May 2024 14:21:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 558966BFA2; Fri, 17 May 2024 14:20:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="MnYNdrRH" 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 E6C1061694; Fri, 17 May 2024 14:20:00 +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=1715955602; cv=none; b=nnL6UdK1q/7aklS9OL+1uR4dmQtV9UrWEIWlOBA7FeMlO1d4yhGIPHmIUqHA491BoMntE7+X7rZSruBvhnv01EWqVIpCO4dsYiuVfV6D48KG6KiR60yFNW7v7gpxfYJverHBq4sDSwtNGgUBzHmWPT/MJZe/xVyoJ8f7Pdv9agA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715955602; c=relaxed/simple; bh=9o7OkNWhk4M5OjqgrrOwQuKgzxn4CUBaIjbPSPykHS4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cetbAIkq8hnowhAg1LKDlRd1LWRBBBjMn1dWEVODXhp+BhVpq5kiljbbIHe8bgzAQ5+hRouF+TLn7Wfj/TdxxGHF7fZZB1NehILu/Efgk9J678VrG2OoPq2ETlHjsi03H2c4YsZuqPRfBFdB56Qdcyr0sx4E5COlJ/xFyyapH2g= 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=MnYNdrRH; 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=9o7OkNWhk4M5OjqgrrOwQuKgzxn4CUBaIjbPSPykHS4=; b=MnYNdrRHV1Y7iKeb+qMPtn8O4YaqY2bW+JuP+7QRW8aAKWs3XWe7U34i dngtM7wQMWpAdXdn/oNaTOCEymGX4XpO3FOW2jJDXuGGmvbUog/ejvGjm lXfvVGKm0S5tVDdHHLFlmTVV48rcxweUmBmBuBRYCoqhEr7MTK8eDYZfm 3cBfWEFMLs5PssmcNhUgiyihci886pYJXNr/OZfooYVW2EfCe0sitimHC TChlr+9/g3w2VM8AaLPPkmNHXx3DQr7+O7QLKkCMyShkmhTE/xm2kWE9O kGylq0WV94KZ7PdbItNQgcTScWIgg1IGOFXRW9Y1A7MpvQSex/Krogil3 w==; X-CSE-ConnectionGUID: +pNCB1DYQdiQIVK7aZD9Mg== X-CSE-MsgGUID: 2ifYq6vCTqahhvFy5Es+Tw== X-IronPort-AV: E=McAfee;i="6600,9927,11075"; a="22808620" X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="22808620" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 May 2024 07:20:00 -0700 X-CSE-ConnectionGUID: ttjwq58OTeayZh8UADZ9+Q== X-CSE-MsgGUID: GVV75GydQySnzWchBoQHbg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,167,1712646000"; d="scan'208";a="31944615" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa009.jf.intel.com with ESMTP; 17 May 2024 07:19:56 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id CE720C04; 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 05/20] x86/tdx: Convert MSR read handling to use new TDVMCALL_1() Date: Fri, 17 May 2024 17:19:23 +0300 Message-ID: <20240517141938.4177174-6-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_1() instead of __tdx_hypercall() to handle MSR read emulation. It cuts code bloat substantially: Function old new delta tdx_handle_virt_exception 2052 1947 -105 Signed-off-by: Kirill A. Shutemov --- arch/x86/coco/tdx/tdx.c | 15 +++++++-------- arch/x86/hyperv/ivm.c | 10 ++-------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index dce7d6f9f895..32c519d096de 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -379,22 +379,21 @@ void __cpuidle tdx_safe_halt(void) static int read_msr(struct pt_regs *regs, struct ve_info *ve) { - struct tdx_module_args args = { - .r10 = TDX_HYPERCALL_STANDARD, - .r11 = hcall_func(EXIT_REASON_MSR_READ), - .r12 = regs->cx, - }; + u64 val; /* * Emulate the MSR read 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_1(hcall_func(EXIT_REASON_MSR_READ), + regs->cx, 0, 0, 0, val)) { return -EIO; + } + + regs->ax = lower_32_bits(val); + regs->dx = upper_32_bits(val); - regs->ax = lower_32_bits(args.r11); - regs->dx = upper_32_bits(args.r11); return ve_instr_len(ve); } diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index b4a851d27c7c..3e2cbfb2203d 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -399,18 +399,12 @@ static void hv_tdx_msr_write(u64 msr, u64 val) static void hv_tdx_msr_read(u64 msr, u64 *val) { - struct tdx_module_args args = { - .r10 = TDX_HYPERCALL_STANDARD, - .r11 = EXIT_REASON_MSR_READ, - .r12 = msr, - }; + u64 ret; - u64 ret = __tdx_hypercall(&args); + ret = TDVMCALL_1(hcall_func(EXIT_REASON_MSR_READ), msr, 0, 0, 0, *val); if (WARN_ONCE(ret, "Failed to emulate MSR read: %lld\n", ret)) *val = 0; - else - *val = args.r11; } u64 hv_tdx_hypercall(u64 control, u64 param1, u64 param2) -- 2.43.0