From nobody Mon Oct 6 19:04:39 2025 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4EA531D54F7; Fri, 18 Jul 2025 04:55:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752814561; cv=none; b=EsSG+oIMP7LBAiuxgHBXuuUJQ9Rn2AyJELmULmQBTehkqswQEVR/0Pg+V23GJfS1mj5JxtxWgxcgwW3uX27wHr4i6FDyxSuwKLIzlpJhvphYyz6T4vEY/f3mSa41nNCccam05MLwU/wZp9yGmVtXJ1dOrC0cpbXEdhB4T0/XVls= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752814561; c=relaxed/simple; bh=/nSmzi7ZSZH4+6XtdEnOIi7u0oPSqZBU/xgwFOgJtCs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gYmYUKGB/VEQWsruf2lwBhqXvNhJ9gREJIrJDNZEJ1+PitFl61RPzPJIh788gt5MABNzKtQBEullI43iUNaYizZkSxEMjGraYgIbnneyd62XG6qG8Lcewlw6wSqYFbubIn5iBGhahAc5vhBKzJZO37ztD7QvQIsJLVhcYH7IbAw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CCgYnM/f; arc=none smtp.client-ip=209.85.216.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CCgYnM/f" Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-3122368d7c4so1504113a91.1; Thu, 17 Jul 2025 21:55:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752814558; x=1753419358; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=RioRFmC4CQK8fObPILD0UjambwVuEnHzjRU9SKz6wEo=; b=CCgYnM/fRaEEp/+SxuFN6DpOpdi3OcrsRjlwWtXgggXULv2EWYkJ9GwfpfsNVWbAWb zNka9G5UXTowzN6Ett8wgs0rZSdKN/+E4wHnVE3gqggRhQ+TIxETi0JXR0IlZUezQKHP QIUFy3dj1rggvou2J/WUjXS/0d3Rlp6S5AJo+Le14qAN3qTu9jrVDoh6blJVw+uf5YT6 YUOiWYUlz/TcKyRET6wKEO7mT8xinOY2AK+O36I2KAKECHm9ZMxg3hMBOhx2mu/kVwRN 1diDiOIg5Uqf7FbVTr2ypZ2juv54ZJ+0sK07mMpHhwBFxlSMJhNEsxx8/jQCwqO6E4xI ULIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752814558; x=1753419358; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=RioRFmC4CQK8fObPILD0UjambwVuEnHzjRU9SKz6wEo=; b=QNIfSiQNDIiyO0KnG5Bj1zqY7rkHAjhh+Nb9UTGspYekFioGMRStyAYLP5lSXpro9P O4GKWO8LUouhDSYesNkQlC6kI0G1VNgPC3pJhTwdOZFtw7YgiJGLZGKWw+aCvWdHU6p7 ZiEO/MX7AQ3rn/40kxKklsHaAuCJmElo9YhyCi5nmh7npKnZETrJpIwozfBbWegHv717 h9CK/W1LMaVdeKdlVJm2iQip1iI/bH9QMlReHF0c+pE9S5i2G6pZultkfRbBPOeFEB2T O+WbOZJdB7gQQYFQ0EkzstuGd1dvx5W54uGYGYRtYFGbJxe+Ze6epT2FvwrJzdYo+Go/ OHTw== X-Forwarded-Encrypted: i=1; AJvYcCV2br7KvH1TrDVgsAANk8yRj18wQ6NPzZfbDvAi2yC2C7ngVoEJB+H4kMsDe9zsMhbVuzaGapDc5AaTAUfb@vger.kernel.org, AJvYcCVGtobj+w6gNA41JGZ44KSNLcjIyZnvvjr4YE7lyuu2KcCwFhBz1+2ve3QI8gFk1nHVlh4NqZL9mBcv@vger.kernel.org, AJvYcCVHq9BGqUvVKYRfvyD318JVg+HJIp8vsEFZyWRog58cHE9uKiP8WFtXtROjdLVHAiA/4wBgGI2lkqcl@vger.kernel.org, AJvYcCXAqr7fBoGHD1k3Sg9ZmY2dERS/uNyGv+DiY89MCkem9J0/ejSZ6jv8jcspVMt66Ib+qox4ZQwSIqwBesrV@vger.kernel.org X-Gm-Message-State: AOJu0Yye0khjrKhg5hgHJ7lwJctG2FqWI5u8pMY145mEhoTKjlI1FN/z gm6KJuTiF5N0/aEdeqFr3/368d682CN6Lm3NHOY1FvVHeNOjvq3khese X-Gm-Gg: ASbGnctNPGaU6JXwZVmVAjOjvZIWEKGSN6yq1TUOsBdPXuFhkhMtYOeE+jwZrNF397q cJgnMuly5IVhPQbGwXDnQihBDDumPgwz2S5CKJ+AkYNPoFtdGlQs1KVsGQsyjUiHZSFzLGfLFa+ UCNNASE7x0lAPTTlyPwXDsZLRwC7FX9Ybdalzqt6qnSMMsqZyqSiNCcY3dHMZbKARUW84cq0/LU hBAH0I7aaJlb1G+q5R3fhz3gZCyAOsn2QMYuhxmdP1pu+IBW5KHwAX+JnB4Di4DPdaw1JbEpFhn Vrg9wJiLCP6VZkFmbNQLy//G4ESsW8DGdpgTeKw+kEf6Xuiu1NEYpvikZOjNzSQrSpxdopY5lL5 g+0GKy+MPWy1fsOqpAGbs7G0A+xlSgzIB5B4ByeZagSyLjz5ykI5ql8xYBYDdwh0yg1JSQIYGE/ +uYQ== X-Google-Smtp-Source: AGHT+IHVSH6/x2vlhrQxJuVcUqnGpg7+BdJ+u4LhBtRTN0p+TGZT1V18DDmHjrGDje2A72rbEMyOXA== X-Received: by 2002:a17:90a:d44c:b0:2f8:34df:5652 with SMTP id 98e67ed59e1d1-31c9e761788mr13469858a91.21.1752814558157; Thu, 17 Jul 2025 21:55:58 -0700 (PDT) Received: from localhost.localdomain (c-67-160-120-253.hsd1.wa.comcast.net. [67.160.120.253]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-31cc33715b2sm476907a91.24.2025.07.17.21.55.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jul 2025 21:55:57 -0700 (PDT) From: mhkelley58@gmail.com X-Google-Original-From: mhklinux@outlook.com To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, lpieralisi@kernel.org, kw@linux.com, mani@kernel.org, robh@kernel.org, bhelgaas@google.com, arnd@arndb.de Cc: x86@kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org Subject: [PATCH v4 1/7] Drivers: hv: Introduce hv_setup_*() functions for hypercall arguments Date: Thu, 17 Jul 2025 21:55:39 -0700 Message-Id: <20250718045545.517620-2-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250718045545.517620-1-mhklinux@outlook.com> References: <20250718045545.517620-1-mhklinux@outlook.com> Reply-To: mhklinux@outlook.com Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Michael Kelley Current code allocates the "hyperv_pcpu_input_arg", and in some configurations, the "hyperv_pcpu_output_arg". Each is a 4 KiB page of memory allocated per-vCPU. A hypercall call site disables interrupts, then uses this memory to set up the input parameters for the hypercall, read the output results after hypercall execution, and re-enable interrupts. The open coding of these steps leads to inconsistencies, and in some cases, violation of the generic requirements for the hypercall input and output as described in the Hyper-V Top Level Functional Spec (TLFS)[1]. To reduce these kinds of problems, introduce a family of inline functions to replace the open coding. The functions provide a new way to manage the use of this per-vCPU memory that is usually the input and output arguments to Hyper-V hypercalls. The functions encapsulate key aspects of the usage and ensure that the TLFS requirements are met (max size of 1 page each for input and output, no overlap of input and output, aligned to 8 bytes, etc.). Conceptually, there is no longer a difference between the "per-vCPU input page" and "per-vCPU output page". Only a single per-vCPU page is allocated, and it provides both hypercall input and output memory. All current hypercalls can fit their input and output within that single page, though the new code allows easy changing to two pages should a future hypercall require a full page for each of the input and output. The new functions always zero the fixed-size portion of the hypercall input area so that uninitialized memory is not inadvertently passed to the hypercall. Current open-coded hypercall call sites are inconsistent on this point, and use of the new functions addresses that inconsistency. The output area is not zero'ed by the new code as it is Hyper-V's responsibility to provide legal output. When the input or output (or both) contain an array, the new functions calculate and return how many array entries fit within the per-vCPU memory page, which is effectively the "batch size" for the hypercall processing multiple entries. This batch size can then be used in the hypercall control word to specify the repetition count. This calculation of the batch size replaces current open coding of the batch size, which is prone to errors. Note that the array portion of the input area is *not* zero'ed. The arrays are almost always 64-bit GPAs or something similar, and zero'ing that much memory seems wasteful at runtime when it will all be overwritten. The hypercall call site is responsible for ensuring that no part of the array is left uninitialized (just as with current code). The new functions are realized as a single inline function that handles the most complex case, which is a hypercall with input and output, both of which contain arrays. Simpler cases are mapped to this most complex case with #define wrappers that provide zero or NULL for some arguments. Several of the arguments to this new function must be compile-time constants generated by "sizeof()" expressions. As such, most of the code in the new function can be evaluated by the compiler, with the result that the code paths are no longer than with the current open coding. The one exception is new code generated to zero the fixed-size portion of the input area in cases where it is not currently done. [1] https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/tlf= s/tlfs Signed-off-by: Michael Kelley Reviewed-by: Nuno Das Neves Reviewed-by: Easwar Hariharan Reviewed-by: Tianyu Lan --- Notes: Changes in v4: * Rename hv_hvcall_*() functions to hv_setup_*() [Easwar Hariharan] * Rename hv_hvcall_in_batch_size() to hv_get_input_batch_size() [Easwar Hariharan] =20 Changes in v3: * Added wrapper #define hv_hvcall_in_batch_size() to get the batch size without setting up hypercall input/output parameters. This call can be used when the batch size is needed for validation checks or memory allocations prior to disabling interrupts. =20 Changes in v2: * Added comment that hv_hvcall_inout_array() should always be called wi= th interrupts disabled because it is returning pointers to per-cpu memory [Nuno Das Neves] include/asm-generic/mshyperv.h | 106 +++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h index a729b77983fa..040c4650f411 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -151,6 +151,112 @@ static inline u64 hv_do_rep_hypercall(u16 code, u16 r= ep_count, u16 varhead_size, return status; } =20 +/* + * Hypercall input and output argument setup + */ + +/* Temporary mapping to be removed at the end of the patch series */ +#define hyperv_pcpu_arg hyperv_pcpu_input_arg + +/* + * Allocate one page that is shared between input and output args, which is + * sufficient for all current hypercalls. If a future hypercall requires + * more space, change this value to "2" and everything will work. + */ +#define HV_HVCALL_ARG_PAGES 1 + +/* + * Allocate space for hypercall input and output arguments from the + * pre-allocated per-cpu hyperv_pcpu_args page(s). A NULL value for the in= put + * or output indicates to allocate no space for that argument. For input a= nd + * for output, specify the size of the fixed portion, and the size of an + * element in a variable size array. A zero value for entry_size indicates + * there is no array. The fixed size space for the input is zero'ed. + * + * When variable size arrays are present, the function returns the number = of + * elements (i.e, the batch size) that fit in the available space. + * + * The four "size" arguments must be constants so the compiler can do most= of + * the calculations. Then the generated inline code is no larger than if o= pen + * coding the access to the hyperv_pcpu_arg and doing memset() on the inpu= t. + * + * This function must be called with interrupts disabled so the thread is = not + * rescheduled onto another vCPU while accessing the per-cpu args page. + */ +static inline int hv_setup_inout_array(void *input, u32 in_size, u32 in_en= try_size, + void *output, u32 out_size, u32 out_entry_size) +{ + u32 in_batch_count =3D 0, out_batch_count =3D 0, batch_count; + u32 in_total_size, out_total_size, offset; + u32 batch_space =3D HV_HYP_PAGE_SIZE * HV_HVCALL_ARG_PAGES; + void *space; + + /* + * If input and output have arrays, allocate half the space to input + * and half to output. If only input has an array, the array can use + * all the space except for the fixed size output (but not to exceed + * one page), and vice versa. + */ + if (in_entry_size && out_entry_size) + batch_space =3D batch_space / 2; + else if (in_entry_size) + batch_space =3D min(HV_HYP_PAGE_SIZE, batch_space - out_size); + else if (out_entry_size) + batch_space =3D min(HV_HYP_PAGE_SIZE, batch_space - in_size); + + if (in_entry_size) + in_batch_count =3D (batch_space - in_size) / in_entry_size; + if (out_entry_size) + out_batch_count =3D (batch_space - out_size) / out_entry_size; + + /* + * If input and output have arrays, use the smaller of the two batch + * counts, in case they are different. If only one has an array, use + * that batch count. batch_count will be zero if neither has an array. + */ + if (in_batch_count && out_batch_count) + batch_count =3D min(in_batch_count, out_batch_count); + else + batch_count =3D in_batch_count | out_batch_count; + + in_total_size =3D ALIGN(in_size + (in_entry_size * batch_count), 8); + out_total_size =3D ALIGN(out_size + (out_entry_size * batch_count), 8); + + space =3D *this_cpu_ptr(hyperv_pcpu_arg); + if (input) { + *(void **)input =3D space; + if (space) + /* Zero the fixed size portion, not any array portion */ + memset(space, 0, ALIGN(in_size, 8)); + } + + if (output) { + if (in_total_size + out_total_size <=3D HV_HYP_PAGE_SIZE) { + offset =3D in_total_size; + } else { + offset =3D HV_HYP_PAGE_SIZE; + /* Need more than 1 page, but only 1 was allocated */ + BUILD_BUG_ON(HV_HVCALL_ARG_PAGES =3D=3D 1); + } + *(void **)output =3D space + offset; + } + + return batch_count; +} + +/* Wrappers for some of the simpler cases with only input, or with no arra= ys */ +#define hv_setup_in(input, in_size) \ + hv_setup_inout_array(input, in_size, 0, NULL, 0, 0) + +#define hv_setup_inout(input, in_size, output, out_size) \ + hv_setup_inout_array(input, in_size, 0, output, out_size, 0) + +#define hv_setup_in_array(input, in_size, in_entry_size) \ + hv_setup_inout_array(input, in_size, in_entry_size, NULL, 0, 0) + +#define hv_get_input_batch_size(in_size, in_entry_size) \ + hv_setup_inout_array(NULL, in_size, in_entry_size, NULL, 0, 0) + /* Generate the guest OS identifier as described in the Hyper-V TLFS */ static inline u64 hv_generate_guest_id(u64 kernel_version) { --=20 2.25.1 From nobody Mon Oct 6 19:04:39 2025 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50D211DF261; Fri, 18 Jul 2025 04:56:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752814561; cv=none; b=Gu27BfkHmcuR06XfrJ0egMk9Micg4LrXrnZdNxm1S/ruOtyTAR45Vn8ItliYxVq/ivS8136nzIw2zwiOjnDgohw6DJ1kdcmEDUZDxpWZ6HPPAePyTj+b490nJXkKS8Kzbe5ENakHyLlBTAowgNW32Z2aQKA/1gKZ0U9ceHWhjzI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752814561; c=relaxed/simple; bh=xPesFCUozidUZ3QZc767Lb5uZZJrIdrIuqrKnh3yL3w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=G8OGGCf73PvlKHS4RbE+4Ock5LPzCM3rhviVmFoN6OZP9LLoroWmLoOQGxe2ofhg6BV4q3D1Ts7grZU62+0zTfHSvXCUU1kv8Ga65q8xLsuEMgwZsrIwBCW/cIkdJdjOI1UOj6dNOVUys82AGhhxevUDclCLAaRltGEYzjqrPrk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=YDp0qMZO; arc=none smtp.client-ip=209.85.215.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YDp0qMZO" Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-b31c978688dso823575a12.1; Thu, 17 Jul 2025 21:56:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752814560; x=1753419360; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=3SOSm0yfOejyCAi5SQeXb76AJ/w/XqxC5rGprpKDvac=; b=YDp0qMZOjYdmfE1KyiTWKCj7B3MGsBBOZFINLa2wpm/SXqepFi1+cpxEjGa6XVfOm8 QPrRIN365s2wCtQ4gty/DCV8J8uS1AM5Zvld0gI8pKTKUPCXuq8UCsiQvmhx8H95FDIb Cid+zSUkFUFbajiC5ySvOi4JMf23dpJjsqMgRbkpz//FHzHEXR7bDoE99P+hRNTrYh7W pIPOgdE0nVQuH53Rzb7G7ErXUM1AUccQAXXwrgQgxtkqpyFr4dDHyyf++txJqxtpn4hB 13o/VL5Qb8WYCxIx+auVzyiM17VEw0p3vxGr9qN7XgVNGoHzkFIzKRP5OjlcT2juSgXL wLhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752814560; x=1753419360; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=3SOSm0yfOejyCAi5SQeXb76AJ/w/XqxC5rGprpKDvac=; b=gtf75pXTrxJgzjFp/nz/fAWgHScQlyi/quW8REx1x22exHl9F18s7n7xyPzAUUw69J mE3dRuhliDsyDE1WCEF2QlBuwFfVpGgq/anQYKqfufAhxi+KaNJ+CWJD+oEzpNf77mSS EwMjMfhir/JO3BUze3pZKLIs8V5Dncke8L3UYbKBPUR19AJlM8BnVvt7UcbLGLrozgRJ pEcZmxDsSXFv86m6IwvbsO3W9iCvUsZuj5B22DaEMWEVgRusphEUvU/iXjNxuZ4Fn5iY +c7RsC+PKhoFVEO/Fxk3VrgiLbM+WdP1FbHG4eDwNT29ONVs4D/RrRZaTA/Kb+nkQSsI EdRg== X-Forwarded-Encrypted: i=1; AJvYcCX82YPAXvjsQpjARX8WvCSWSFWkVCB5gldbaDR8qzoXg/fLt3zVide64qqPjsZ22MkLSSy976+k8MZZcfD0@vger.kernel.org, AJvYcCXAsMPS1cTFfBt1K5CMMNH73Wmhffinfi8ilrhiYtSiHdBOXv0SCeDWeNiVOIwyWhTjUN+FXLcvOasy+hxP@vger.kernel.org, AJvYcCXOD9K6OOWmjNSZD1I/QCUICdvC/u/L4Halaah39tAefzae5ge337ZxIxcc8ZxvPQUzDIhdmvwgmWUp@vger.kernel.org, AJvYcCXPf0KdZTChaTTzSImllkOjkCZZFIspwqrf1cpikfzeZdNt2fS73UH7eGd0KfSXoajYux8JoYvHiPYi@vger.kernel.org X-Gm-Message-State: AOJu0Yz/EU5/c/hE7GtCqYZCa+ewwxSQHJiVFiuLcAYwiBf4sP6gJTSC ichblgDH8OWI5l3tNNQgHAV6BJAkHhH+Gr3d4zVWbTN/eHuWU3W1/HGh X-Gm-Gg: ASbGncvXwUTChXKmp3h9Kvyfj/kg3LQyMkgrihg692dwcCAI27LVAzA5bLL+BEXZSr8 bm6I9Gov/zlqzlQXF3LqBsBw/x9eZ3T7TnelrWZa8LahANwKzsE0cqtmlBvpnvEF+3oZTUyMjvO rkrzBXTsrdH9MKpZoLnaSW1UFQwXL8LvUi+/YyjxM2FG18BUGacKq7HuUnKg4M2/Akoi+RiB96J 97NPMLcP+nUgEwb4y45H63Yx02OwEjoydzN0bonrrtPJcO3PLLeuAXAt09y2TkFDjQwmgZmK1sy v17LF61M5+gb7fi8k+QhRPnOnlM/eZ5+ApTfX/41S9W37/Z6R9QeOXNimuNDg7V2Rgn27CRzVMm D1ExygfEO34IeeALIWzzzoHc8RKzqyFkMYD8D1asuK9MGTrRaN2Rkw480KyUD6KuInH3fRW6/1A pIykZTN74NdJB5 X-Google-Smtp-Source: AGHT+IHoe9x5uTof8QDzxezIFS33hnbeXPYR7thO6gnxlwgvMM2NRy7MwFCxNEosmf+hf7J45ly4nQ== X-Received: by 2002:a17:90b:4acf:b0:31c:c434:dec8 with SMTP id 98e67ed59e1d1-31cc434decemr1447635a91.20.1752814559370; Thu, 17 Jul 2025 21:55:59 -0700 (PDT) Received: from localhost.localdomain (c-67-160-120-253.hsd1.wa.comcast.net. [67.160.120.253]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-31cc33715b2sm476907a91.24.2025.07.17.21.55.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jul 2025 21:55:59 -0700 (PDT) From: mhkelley58@gmail.com X-Google-Original-From: mhklinux@outlook.com To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, lpieralisi@kernel.org, kw@linux.com, mani@kernel.org, robh@kernel.org, bhelgaas@google.com, arnd@arndb.de Cc: x86@kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org Subject: [PATCH v4 2/7] x86/hyperv: Use hv_setup_*() to set up hypercall arguments -- part 1 Date: Thu, 17 Jul 2025 21:55:40 -0700 Message-Id: <20250718045545.517620-3-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250718045545.517620-1-mhklinux@outlook.com> References: <20250718045545.517620-1-mhklinux@outlook.com> Reply-To: mhklinux@outlook.com Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Michael Kelley Update hypercall call sites to use the new hv_setup_*() functions to set up hypercall arguments. Since these functions zero the fixed portion of input memory, remove now redundant calls to memset() and explicit zero'ing of input fields. Signed-off-by: Michael Kelley Reviewed-by: Nuno Das Neves Reviewed-by: Easwar Hariharan --- Notes: Changes in v4: * Rename hv_hvcall_*() functions to hv_setup_*() [Easwar Hariharan] * Rename hv_hvcall_in_batch_size() to hv_get_input_batch_size() [Easwar Hariharan] =20 Changes in v2: * Fixed get_vtl() and hv_vtl_apicid_to_vp_id() to properly treat the in= put and output arguments as arrays [Nuno Das Neves] * Enhanced __send_ipi_mask_ex() and hv_map_interrupt() to check the num= ber of computed banks in the hv_vpset against the batch_size. Since an hv_vpset currently represents a maximum of 4096 CPUs, the hv_vpset si= ze does not exceed 512 bytes and there should always be sufficent space.= But do the check just in case something changes. [Nuno Das Neves] arch/x86/hyperv/hv_apic.c | 10 ++++------ arch/x86/hyperv/hv_init.c | 6 ++---- arch/x86/hyperv/hv_vtl.c | 3 +-- arch/x86/hyperv/irqdomain.c | 17 ++++++++++------- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/arch/x86/hyperv/hv_apic.c b/arch/x86/hyperv/hv_apic.c index bfde0a3498b9..bafb5dceb5d6 100644 --- a/arch/x86/hyperv/hv_apic.c +++ b/arch/x86/hyperv/hv_apic.c @@ -109,21 +109,19 @@ static bool __send_ipi_mask_ex(const struct cpumask *= mask, int vector, { struct hv_send_ipi_ex *ipi_arg; unsigned long flags; - int nr_bank =3D 0; + int batch_size, nr_bank =3D 0; u64 status =3D HV_STATUS_INVALID_PARAMETER; =20 if (!(ms_hyperv.hints & HV_X64_EX_PROCESSOR_MASKS_RECOMMENDED)) return false; =20 local_irq_save(flags); - ipi_arg =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - + batch_size =3D hv_setup_in_array(&ipi_arg, sizeof(*ipi_arg), + sizeof(ipi_arg->vp_set.bank_contents[0])); if (unlikely(!ipi_arg)) goto ipi_mask_ex_done; =20 ipi_arg->vector =3D vector; - ipi_arg->reserved =3D 0; - ipi_arg->vp_set.valid_bank_mask =3D 0; =20 /* * Use HV_GENERIC_SET_ALL and avoid converting cpumask to VP_SET @@ -140,7 +138,7 @@ static bool __send_ipi_mask_ex(const struct cpumask *ma= sk, int vector, * represented in VP_SET. Return an error and fall back to * native (architectural) method of sending IPIs. */ - if (nr_bank <=3D 0) + if (nr_bank <=3D 0 || nr_bank > batch_size) goto ipi_mask_ex_done; } else { ipi_arg->vp_set.format =3D HV_GENERIC_SET_ALL; diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index afdbda2dd7b7..b7a2877c2a92 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -685,13 +685,11 @@ int hv_apicid_to_vp_index(u32 apic_id) =20 local_irq_save(irq_flags); =20 - input =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - memset(input, 0, sizeof(*input)); + hv_setup_inout_array(&input, sizeof(*input), sizeof(input->apic_ids[0]), + &output, 0, sizeof(*output)); input->partition_id =3D HV_PARTITION_ID_SELF; input->apic_ids[0] =3D apic_id; =20 - output =3D *this_cpu_ptr(hyperv_pcpu_output_arg); - control =3D HV_HYPERCALL_REP_COMP_1 | HVCALL_GET_VP_INDEX_FROM_APIC_ID; status =3D hv_do_hypercall(control, input, output); ret =3D output[0]; diff --git a/arch/x86/hyperv/hv_vtl.c b/arch/x86/hyperv/hv_vtl.c index 042e8712d8de..fc523a5096f4 100644 --- a/arch/x86/hyperv/hv_vtl.c +++ b/arch/x86/hyperv/hv_vtl.c @@ -131,8 +131,7 @@ static int hv_vtl_bringup_vcpu(u32 target_vp_index, int= cpu, u64 eip_ignored) =20 local_irq_save(irq_flags); =20 - input =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - memset(input, 0, sizeof(*input)); + hv_setup_in(&input, sizeof(*input)); =20 input->partition_id =3D HV_PARTITION_ID_SELF; input->vp_index =3D target_vp_index; diff --git a/arch/x86/hyperv/irqdomain.c b/arch/x86/hyperv/irqdomain.c index 090f5ac9f492..87ebe43f58cf 100644 --- a/arch/x86/hyperv/irqdomain.c +++ b/arch/x86/hyperv/irqdomain.c @@ -21,15 +21,15 @@ static int hv_map_interrupt(union hv_device_id device_i= d, bool level, struct hv_device_interrupt_descriptor *intr_desc; unsigned long flags; u64 status; - int nr_bank, var_size; + int batch_size, nr_bank, var_size; =20 local_irq_save(flags); =20 - input =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - output =3D *this_cpu_ptr(hyperv_pcpu_output_arg); + batch_size =3D hv_setup_inout_array(&input, sizeof(*input), + sizeof(input->interrupt_descriptor.target.vp_set.bank_contents[0]), + &output, sizeof(*output), 0); =20 intr_desc =3D &input->interrupt_descriptor; - memset(input, 0, sizeof(*input)); input->partition_id =3D hv_current_partition_id; input->device_id =3D device_id.as_uint64; intr_desc->interrupt_type =3D HV_X64_INTERRUPT_TYPE_FIXED; @@ -41,7 +41,6 @@ static int hv_map_interrupt(union hv_device_id device_id,= bool level, else intr_desc->trigger_mode =3D HV_INTERRUPT_TRIGGER_MODE_EDGE; =20 - intr_desc->target.vp_set.valid_bank_mask =3D 0; intr_desc->target.vp_set.format =3D HV_GENERIC_SET_SPARSE_4K; nr_bank =3D cpumask_to_vpset(&(intr_desc->target.vp_set), cpumask_of(cpu)= ); if (nr_bank < 0) { @@ -49,6 +48,11 @@ static int hv_map_interrupt(union hv_device_id device_id= , bool level, pr_err("%s: unable to generate VP set\n", __func__); return -EINVAL; } + if (nr_bank > batch_size) { + local_irq_restore(flags); + pr_err("%s: nr_bank too large\n", __func__); + return -EINVAL; + } intr_desc->target.flags =3D HV_DEVICE_INTERRUPT_TARGET_PROCESSOR_SET; =20 /* @@ -78,9 +82,8 @@ static int hv_unmap_interrupt(u64 id, struct hv_interrupt= _entry *old_entry) u64 status; =20 local_irq_save(flags); - input =3D *this_cpu_ptr(hyperv_pcpu_input_arg); =20 - memset(input, 0, sizeof(*input)); + hv_setup_in(&input, sizeof(*input)); intr_entry =3D &input->interrupt_entry; input->partition_id =3D hv_current_partition_id; input->device_id =3D id; --=20 2.25.1 From nobody Mon Oct 6 19:04:39 2025 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E20D1E3772; Fri, 18 Jul 2025 04:56:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752814563; cv=none; b=BszfNBZAQUxecsjP7z5mSBoMQWRkYTH27BNk2st9tBtHmj9vLTh5a/AGwjKeO1BzaKzmjMZ1WW9O9IeUQD0hR0HLB/9mCIPxxMKyPkEr7KFWCARRc/5enaKYmOCxExNMkKUKY91qObioCOXV2sFMSOsyTejhiXF6dnYTS1t2KIQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752814563; c=relaxed/simple; bh=57en2IJxk+KdHVqMRBLLkwKBtaix6U/yRmwdbJZuI18=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qZdpf+fwqo13kH/MTVjNEb+TIJjeCiae6Dhx3SCDQ/5AZxhUzyuFhgwKi+FWc2CmNmuZIbPy2GnzgLxred7S5rTEusKDRobxvzh7GTAsYYbeU80cY42wR0asrz95XtiMpu0b4fbuyc4W/7dwhTy52ke8XgMHq3pFXFzGa324gEU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hwgxO+YN; arc=none smtp.client-ip=209.85.216.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hwgxO+YN" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-3139027b825so1432305a91.0; Thu, 17 Jul 2025 21:56:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752814561; x=1753419361; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=ag+Imn96kUjagix1W68j1TuvFRsLmLRe1HdtHqE/NkE=; b=hwgxO+YNwFbZzcFz46md+yHcR7XsBLMEwXQrzIhwQZQFY2q+QSiY/QH4S1s8348s81 iRyX0yuWfRbaPcSMUq2ZLQEl4eYj1QMvBIgG9XiVDLRtAjJgLBr9iqWREayzUKni+YY6 YVZY+OeFcNpYji/sbhSmRAjXzbZPWcphBGAINYCYuoXzSZPmkjgH7zdlIiypM9SDUkTD HsPzr9NJTcSvm+B75+WiKlXPGuE90X4SkFaYSuf3YiRKzv0CXzBvoXhtwGH3FmACT33l 3WNdn0PQOZ5OVSoYPJY1xTZsqTxkxxbxjlS/SWpNT2ywtO9/p7VBR3310aPD+q9gsMfk HjPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752814561; x=1753419361; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ag+Imn96kUjagix1W68j1TuvFRsLmLRe1HdtHqE/NkE=; b=U86BVfm8Dk9OZqx/Ikre3pEO38Kh7vL5AtCga0U+JxA0e/6Z3wCbYOiJ8nJOV6ZyWk AwqQxYpUcxNMEBaqCzmXPT/1gsBwSohBhh8NhiNBj5Q5dSLko6z7CU40BLw8LRsH0LHd r61XNIdT6CFeeJkDPv19+z8A3FFe61u6JESLs0PfB7x06Hjg8nx61NETvKtkRaSMNofO pzKukpZzNM+Cy7flo3x+gShgcwYtoVkMJAt4orGJtjrxz2VaXB412LVleSRlDuDNLhxB 28dYenGz1xnKHv0rWafgPvuXlvsO+6ZRQnMBGZNV6A1hNhi29GeEyncn0TkQpBLXrgOw Zwqw== X-Forwarded-Encrypted: i=1; AJvYcCUVynyofZY7eHzQ7zFKYIqcQ72CdjUXbIhVu+cRub+d+lELWUo8af3N5cqIlG3pdEmQEcKzz2yfFOeRKVge@vger.kernel.org, AJvYcCW5anThH+293S66ErSg1RN0NLA0B2g4IcKbGl/RM9+IP/YNNiwavW6esSDY8hFmzovbz2hV3nGQIvqd@vger.kernel.org, AJvYcCWuOMmdq7jxzjVQJkGcHdcBRduBBuZQl08O+PzvYskwycKqzpXfJJZAUrH0glV5jvpvbiRVLbODMJAo@vger.kernel.org, AJvYcCXOz4FBu5FvU4876biN0PN/dXJrSZ+W8SrSUJBJ3S5QIsfnSaGj6znqKa1nhzWatEIPWQnTb7EGsqidN9wt@vger.kernel.org X-Gm-Message-State: AOJu0YyXzp5lfpAvOZNYEWM9tTXhb4QmK++u22sis2xIRARGHEhI0xT9 jzTC89ZAEIWzghFTnss7BeUJaNnZPbc5eInEJapbJekol187rA3lxhH9 X-Gm-Gg: ASbGncuuHheGnvVQ7Xj9APnXOoRznwt2SyxVVSQY+MXnnmlp0/e1Ge99WHjSvngjzlo uNnpQe4C4AvxfkBbw8/Oo7iRkQqBvjSzptA0dBC2/gj+QU/tXsqB1RaESw65NuhdvwSkYk8MkSi OPQyi9g4NcbBK2/mw9+4mZmXmnqeGOtQwoJ7yufP7/SuBnYF+ugJKAsnJl5uSSLFQ2ytjWc20fe J69Qm6CoT7nu0s+27/ZTDwYtJJId3jSGLrl98WCazkC7JbVcH6cVBdOMc+746FAlvp7OBuNZnZm FbGRfi+cWPgHhKHV8RCGkm1QIDGj3W9I0K2ivvd5GYatsJMX6IRUYvChrhZaplakM+dKdtAkvSY oj88jrUrvhVY1MDQCt+pu0HIT5vitwEXiGBqVCCnKGFiE8C9k3Jxrnq2RNxPJc1x7gxjvlw6qX/ Exjg== X-Google-Smtp-Source: AGHT+IFOkH/8qlGUUajIKL5gtflNPGsfw+mTEWcc1scJHMs/VPU0KwYm/k0splhQ+YRskYo6zlhwqQ== X-Received: by 2002:a17:90b:1e07:b0:311:9c9a:58d7 with SMTP id 98e67ed59e1d1-31c9f42e8a1mr13006308a91.19.1752814560834; Thu, 17 Jul 2025 21:56:00 -0700 (PDT) Received: from localhost.localdomain (c-67-160-120-253.hsd1.wa.comcast.net. [67.160.120.253]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-31cc33715b2sm476907a91.24.2025.07.17.21.55.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jul 2025 21:56:00 -0700 (PDT) From: mhkelley58@gmail.com X-Google-Original-From: mhklinux@outlook.com To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, lpieralisi@kernel.org, kw@linux.com, mani@kernel.org, robh@kernel.org, bhelgaas@google.com, arnd@arndb.de Cc: x86@kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org Subject: [PATCH v4 3/7] x86/hyperv: Use hv_setup_*() to set up hypercall arguments -- part 2 Date: Thu, 17 Jul 2025 21:55:41 -0700 Message-Id: <20250718045545.517620-4-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250718045545.517620-1-mhklinux@outlook.com> References: <20250718045545.517620-1-mhklinux@outlook.com> Reply-To: mhklinux@outlook.com Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Michael Kelley Update hypercall call sites to use the new hv_setup_*() functions to set up hypercall arguments. Since these functions zero the fixed portion of input memory, remove now redundant calls to memset() and explicit zero'ing of input fields. For hv_mark_gpa_visibility(), use the computed batch_size instead of HV_MAX_MODIFY_GPA_REP_COUNT. Also update the associated gpa_page_list[] field to have zero size, which is more consistent with other array arguments to hypercalls. Due to the interaction with the calling hv_vtom_set_host_visibility(), HV_MAX_MODIFY_GPA_REP_COUNT cannot be completely eliminated without some further restructuring, but that's for another patch set. Similarly, for the nested flush functions, update the gpa_list[] to have zero size. Again, separate restructuring would be required to completely eliminate the need for HV_MAX_FLUSH_REP_COUNT. Finally, hyperv_flush_tlb_others_ex() requires special handling because the input consists of two arrays -- one for the hv_vp_set and another for the gva list. The batch_size computed by hv_setup_in_array() is adjusted to account for the number of entries in the hv_vp_set. Signed-off-by: Michael Kelley Reviewed-by: Nuno Das Neves Reviewed-by: Easwar Hariharan --- Notes: Changes in v4: * Rename hv_hvcall_*() functions to hv_setup_*() [Easwar Hariharan] * Rename hv_hvcall_in_batch_size() to hv_get_input_batch_size() [Easwar Hariharan] =20 Changes in v2: * In hyperv_flush_tlb_others_ex(), added check of the adjusted max_gvas to make sure it doesn't go to zero or negative, which would happen if there is insufficient space to hold the hv_vpset and have at least one entry in the gva list. Since an hv_vpset currently represents a maximum of 4096 CPUs, the hv_vpset size does not exceed 512 bytes and there should always be sufficent space. But do the check just in case something changes. [Nuno Das Neves] arch/x86/hyperv/ivm.c | 18 +++++++++--------- arch/x86/hyperv/mmu.c | 19 +++++-------------- arch/x86/hyperv/nested.c | 14 +++++--------- include/hyperv/hvgdk_mini.h | 4 ++-- 4 files changed, 21 insertions(+), 34 deletions(-) diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index ade6c665c97e..3084ae8a3eed 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -474,30 +474,30 @@ static int hv_mark_gpa_visibility(u16 count, const u6= 4 pfn[], { struct hv_gpa_range_for_visibility *input; u64 hv_status; + int batch_size; unsigned long flags; =20 /* no-op if partition isolation is not enabled */ if (!hv_is_isolation_supported()) return 0; =20 - if (count > HV_MAX_MODIFY_GPA_REP_COUNT) { - pr_err("Hyper-V: GPA count:%d exceeds supported:%lu\n", count, - HV_MAX_MODIFY_GPA_REP_COUNT); + local_irq_save(flags); + batch_size =3D hv_setup_in_array(&input, sizeof(*input), + sizeof(input->gpa_page_list[0])); + if (unlikely(!input)) { + local_irq_restore(flags); return -EINVAL; } =20 - local_irq_save(flags); - input =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - - if (unlikely(!input)) { + if (count > batch_size) { + pr_err("Hyper-V: GPA count:%d exceeds supported:%u\n", count, + batch_size); local_irq_restore(flags); return -EINVAL; } =20 input->partition_id =3D HV_PARTITION_ID_SELF; input->host_visibility =3D visibility; - input->reserved0 =3D 0; - input->reserved1 =3D 0; memcpy((void *)input->gpa_page_list, pfn, count * sizeof(*pfn)); hv_status =3D hv_do_rep_hypercall( HVCALL_MODIFY_SPARSE_GPA_PAGE_HOST_VISIBILITY, count, diff --git a/arch/x86/hyperv/mmu.c b/arch/x86/hyperv/mmu.c index cfcb60468b01..f1aeb5bdb29a 100644 --- a/arch/x86/hyperv/mmu.c +++ b/arch/x86/hyperv/mmu.c @@ -72,7 +72,7 @@ static void hyperv_flush_tlb_multi(const struct cpumask *= cpus, =20 local_irq_save(flags); =20 - flush =3D *this_cpu_ptr(hyperv_pcpu_input_arg); + max_gvas =3D hv_setup_in_array(&flush, sizeof(*flush), sizeof(flush->gva_= list[0])); =20 if (unlikely(!flush)) { local_irq_restore(flags); @@ -86,13 +86,10 @@ static void hyperv_flush_tlb_multi(const struct cpumask= *cpus, */ flush->address_space =3D virt_to_phys(info->mm->pgd); flush->address_space &=3D CR3_ADDR_MASK; - flush->flags =3D 0; } else { - flush->address_space =3D 0; flush->flags =3D HV_FLUSH_ALL_VIRTUAL_ADDRESS_SPACES; } =20 - flush->processor_mask =3D 0; if (cpumask_equal(cpus, cpu_present_mask)) { flush->flags |=3D HV_FLUSH_ALL_PROCESSORS; } else { @@ -139,8 +136,6 @@ static void hyperv_flush_tlb_multi(const struct cpumask= *cpus, * We can flush not more than max_gvas with one hypercall. Flush the * whole address space if we were asked to do more. */ - max_gvas =3D (PAGE_SIZE - sizeof(*flush)) / sizeof(flush->gva_list[0]); - if (info->end =3D=3D TLB_FLUSH_ALL) { flush->flags |=3D HV_FLUSH_NON_GLOBAL_MAPPINGS_ONLY; status =3D hv_do_hypercall(HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE, @@ -179,7 +174,7 @@ static u64 hyperv_flush_tlb_others_ex(const struct cpum= ask *cpus, if (!(ms_hyperv.hints & HV_X64_EX_PROCESSOR_MASKS_RECOMMENDED)) return HV_STATUS_INVALID_PARAMETER; =20 - flush =3D *this_cpu_ptr(hyperv_pcpu_input_arg); + max_gvas =3D hv_setup_in_array(&flush, sizeof(*flush), sizeof(flush->gva_= list[0])); =20 if (info->mm) { /* @@ -188,14 +183,10 @@ static u64 hyperv_flush_tlb_others_ex(const struct cp= umask *cpus, */ flush->address_space =3D virt_to_phys(info->mm->pgd); flush->address_space &=3D CR3_ADDR_MASK; - flush->flags =3D 0; } else { - flush->address_space =3D 0; flush->flags =3D HV_FLUSH_ALL_VIRTUAL_ADDRESS_SPACES; } =20 - flush->hv_vp_set.valid_bank_mask =3D 0; - flush->hv_vp_set.format =3D HV_GENERIC_SET_SPARSE_4K; nr_bank =3D cpumask_to_vpset_skip(&flush->hv_vp_set, cpus, info->freed_tables ? NULL : cpu_is_lazy); @@ -210,10 +201,10 @@ static u64 hyperv_flush_tlb_others_ex(const struct cp= umask *cpus, * of flush->hv_vp_set as part of the fixed size input header. * So the variable input header size is equal to nr_bank. */ - max_gvas =3D - (PAGE_SIZE - sizeof(*flush) - nr_bank * - sizeof(flush->hv_vp_set.bank_contents[0])) / + max_gvas -=3D (nr_bank * sizeof(flush->hv_vp_set.bank_contents[0])) / sizeof(flush->gva_list[0]); + if (max_gvas <=3D 0) + return HV_STATUS_INVALID_PARAMETER; =20 if (info->end =3D=3D TLB_FLUSH_ALL) { flush->flags |=3D HV_FLUSH_NON_GLOBAL_MAPPINGS_ONLY; diff --git a/arch/x86/hyperv/nested.c b/arch/x86/hyperv/nested.c index 8ccbb7c4fc27..8eeda2e2ad29 100644 --- a/arch/x86/hyperv/nested.c +++ b/arch/x86/hyperv/nested.c @@ -30,15 +30,13 @@ int hyperv_flush_guest_mapping(u64 as) =20 local_irq_save(flags); =20 - flush =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - + hv_setup_in(&flush, sizeof(*flush)); if (unlikely(!flush)) { local_irq_restore(flags); goto fault; } =20 flush->address_space =3D as; - flush->flags =3D 0; =20 status =3D hv_do_hypercall(HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE, flush, NULL); @@ -91,25 +89,23 @@ int hyperv_flush_guest_mapping_range(u64 as, u64 status; unsigned long flags; int ret =3D -ENOTSUPP; - int gpa_n =3D 0; + int batch_size, gpa_n =3D 0; =20 if (!hv_hypercall_pg || !fill_flush_list_func) goto fault; =20 local_irq_save(flags); =20 - flush =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - + batch_size =3D hv_setup_in_array(&flush, sizeof(*flush), + sizeof(flush->gpa_list[0])); if (unlikely(!flush)) { local_irq_restore(flags); goto fault; } =20 flush->address_space =3D as; - flush->flags =3D 0; - gpa_n =3D fill_flush_list_func(flush, data); - if (gpa_n < 0) { + if (gpa_n < 0 || gpa_n > batch_size) { local_irq_restore(flags); goto fault; } diff --git a/include/hyperv/hvgdk_mini.h b/include/hyperv/hvgdk_mini.h index 1be7f6a02304..5590b5fe318c 100644 --- a/include/hyperv/hvgdk_mini.h +++ b/include/hyperv/hvgdk_mini.h @@ -557,7 +557,7 @@ union hv_gpa_page_range { struct hv_guest_mapping_flush_list { u64 address_space; u64 flags; - union hv_gpa_page_range gpa_list[HV_MAX_FLUSH_REP_COUNT]; + union hv_gpa_page_range gpa_list[]; }; =20 struct hv_tlb_flush { /* HV_INPUT_FLUSH_VIRTUAL_ADDRESS_LIST */ @@ -1244,7 +1244,7 @@ struct hv_gpa_range_for_visibility { u32 host_visibility : 2; u32 reserved0 : 30; u32 reserved1; - u64 gpa_page_list[HV_MAX_MODIFY_GPA_REP_COUNT]; + u64 gpa_page_list[]; } __packed; =20 #if defined(CONFIG_X86) --=20 2.25.1 From nobody Mon Oct 6 19:04:39 2025 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF22F1E98FB; Fri, 18 Jul 2025 04:56:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752814564; cv=none; b=CGbMEFxDJMtMZ3aN1D1nRuJ4VKeCI8bwvGoB4C8nxORHkEw1YAh9Eorba5DUegWQCxr1mTUgXvXE/730pIoBumF9ovmUSvebO2dgwctAGiEXtBfXpvtqe01ZEnr0zPTNKTqjOoKl71sGDy2SIcuegX6pstmvFRqVANBiMaZXjgI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752814564; c=relaxed/simple; bh=OGH6Bpc/OE9X847x/L6VlIAm+mIYXNXdMu5o6YkG6RY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=J/+htlCXP/exsNYkR3rtcb6tOnAZ3JxxVcjytisbyLUz5F01Vty0/n1YTVQtqMLgCdyA+FHeX17BsenxPVMPBNKLPLhwxszTEGyegIPkqm5Jl6NpDR16rD5ikR42RodxPvxhE7Ue4hP24DAqZm2VYALaiLfY+9xrPbGG4lh0ukg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=EUGAmlOA; arc=none smtp.client-ip=209.85.216.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EUGAmlOA" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-31329098ae8so1528764a91.1; Thu, 17 Jul 2025 21:56:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752814562; x=1753419362; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=Z4YwSGg1tUe7fu/pS83WCt5l9SC+9AOdn2iyI4phc/4=; b=EUGAmlOAtzRwsa0E3CJxiyNSIZ4CirbH+jBiDzwNDbLje7REE8oFuPHfHD/qCPP20f f5s9rJ6xdRTJT5mOlWB8qJDE7eMSEU7D5Rh+OqRRTB5aJsQxQEtFHSSeaxpcesfRkz1l dOMlmjmvG+rvDE4FBwjJF+2odrCRFG7/E59x/3PTZxcduCEOUWzzFqyCOIlQefsVTiaI f23YwzO2EWyeX0bnjjDPL8WyyX2DttYAn9g7LK48buz7wJMgraWUXVwv0PPRUVDiUqR0 tp8Jw0zD/NkPmWDCoceTE1avQk9hX4NWXQ568MzwH6+/S0OYN2PCJ1Z/Y9m+j9Zp5J4Z e2AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752814562; x=1753419362; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Z4YwSGg1tUe7fu/pS83WCt5l9SC+9AOdn2iyI4phc/4=; b=oSjJcJQVRpLGP4Im0fGLw5NSYGuDZFUEIEUMsxqXe+eyFfDjmAk6uGkV9ALXMnmz2N JkeYtaOnb42wfPsRUgRDsiZBhzcvrxI2hFB7iQkGnG7OGM6vFLPkqXjJFXwT0aDDCDUs mjC3y6PC0nWi9Ryglh63tjjrJhVjSjBxkQJSylPvt3LEFaAynVAnFwyLW0zDDXh6/JxA oFDfwf/vIST3pXzAg2IiOEa3j4+vIxZTV9VfZ+h+Pwtp8Mq33Bd4R6Of+a6xSvOFME0b Wn2yRoPZKAZZVz2Wr3iagsXsF96zdeDIUvbQNs52dOnhWYtv69208dr0kXviSQUkaqza ThTw== X-Forwarded-Encrypted: i=1; AJvYcCWMRwp0U1TiZS7ySEF4JJtuP2QEZulbay9TadBTkz0yTZMPm7ZAtUYyraJ2nkZo0EQzEVA30A+AaORA0B37@vger.kernel.org, AJvYcCWOpyk5x/4T4o/PqZjo3+mj7B3p4+nAGiJGRTqthwXdOSnB+KNggq7Q4jobewFCubMAam7B0x6qR3oq@vger.kernel.org, AJvYcCXH3l2C2aiam/4I4jWW+9aPC+bbAPPHuTeu7Bg2dj0Te5adxWohhaSQMw+i6trwHzNulKNUaf4DzvOtvYmL@vger.kernel.org, AJvYcCXSqRLqOK/iXbWH5yfJoP+wVhk19k4CZ/eSaCwk4U1EEZA1+GgYamFCCSA+JbXUnURo4aTj2o3zbqRc@vger.kernel.org X-Gm-Message-State: AOJu0Yw2U/66nAARhwyOluCdiBuyQ022rd/IlSD95OgBi+brjXUKaNTZ MwB/N865Qeep9m9HH4nPcf2/gSYcpKEIi2q4hOL38WvSrlXMSwlItE2y X-Gm-Gg: ASbGncts7xVae50BD8HQaSI2NKIFNjOtFQ5flO+MIjwZb0wOfoEkXlds3Y2pdbgIpvu nanWl6XWl1stLMt3j3krFSBLASdJaeWwFFDmR9ZV/a76pr1hvL3UEL9p3GJrcdHhdycybjXZPSu iPx1yR6XznzL70BBQF5UTwNbPSgIFKyPTE7p8jbKt7uoNPZq23uHQ3SWFDrDZ/ypdxt9zwt0iBh 0f0lF3ipdecHnvWHbyoTQDwXVtrnt1vB3Ts9RSnXIU4oWgAy5Bb/GJj9jqka48FqiN1Ts5kz4Lj A2SEtm0Zz1adIeWU3jvUt2ZyUj5LNbJogImBWPQhmetEtvqb4j8COcImkQvkigEienpcN0vduO5 PzaM+S4CkTh5mf7KdzyFuFgkvQYVWlxdULT9B0f+vaJH6Ffk5q7WwyWKgd1Khld6IGIOKqUd3zG BHzQ== X-Google-Smtp-Source: AGHT+IEMhEWEmZEPqhGpJ6GpUMjFMgAHKc3+3eXHQhJ1faHyqk1AKFMu1lSvB5lOekVZAimbBZUNBA== X-Received: by 2002:a17:90b:3d8a:b0:312:e73e:cded with SMTP id 98e67ed59e1d1-31cc045b2dcmr3314232a91.16.1752814562083; Thu, 17 Jul 2025 21:56:02 -0700 (PDT) Received: from localhost.localdomain (c-67-160-120-253.hsd1.wa.comcast.net. [67.160.120.253]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-31cc33715b2sm476907a91.24.2025.07.17.21.56.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jul 2025 21:56:01 -0700 (PDT) From: mhkelley58@gmail.com X-Google-Original-From: mhklinux@outlook.com To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, lpieralisi@kernel.org, kw@linux.com, mani@kernel.org, robh@kernel.org, bhelgaas@google.com, arnd@arndb.de Cc: x86@kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org Subject: [PATCH v4 4/7] Drivers: hv: Use hv_setup_*() to set up hypercall arguments Date: Thu, 17 Jul 2025 21:55:42 -0700 Message-Id: <20250718045545.517620-5-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250718045545.517620-1-mhklinux@outlook.com> References: <20250718045545.517620-1-mhklinux@outlook.com> Reply-To: mhklinux@outlook.com Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Michael Kelley Update hypercall call sites to use the new hv_setup_*() functions to set up hypercall arguments. Since these functions zero the fixed portion of input memory, remove now redundant zero'ing of input fields. In hv_post_message(), the payload area is treated as an array to avoid wasting cycles on zero'ing it and then overwriting with memcpy(). Signed-off-by: Michael Kelley Reviewed-by: Easwar Hariharan --- Notes: Changes in v4: * Rename hv_hvcall_*() functions to hv_setup_*() [Easwar Hariharan] * Rename hv_hvcall_in_batch_size() to hv_get_input_batch_size() [Easwar Hariharan] =20 Changes in v3: * Removed change to definition of struct hv_input_post_message so the 'payload' remains a fixed size array. Adjust hv_post_message() so that the 'payload' array is not zero'ed. [Nuno Das Neves] * Added check of the batch size in hv_free_page_report(). [Nuno Das Nev= es] * In hv_call_deposit_pages(), use the new hv_hvcall_in_batch_size() to get the batch size at the start of the function, and check the 'num_pages' input parameter against that batch size instead of against a separately defined constant. Also use the batch size to compute the size of the memory allocation. [Nuno Das Neves] drivers/hv/hv.c | 4 +++- drivers/hv/hv_balloon.c | 8 ++++---- drivers/hv/hv_common.c | 9 +++------ drivers/hv/hv_proc.c | 23 ++++++++++------------- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index b14c5f9e0ef2..ad063f535f95 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -66,7 +66,9 @@ int hv_post_message(union hv_connection_id connection_id, if (hv_isolation_type_tdx() && ms_hyperv.paravisor_present) aligned_msg =3D this_cpu_ptr(hv_context.cpu_context)->post_msg_page; else - aligned_msg =3D *this_cpu_ptr(hyperv_pcpu_input_arg); + hv_setup_in_array(&aligned_msg, + offsetof(typeof(*aligned_msg), payload), + sizeof(aligned_msg->payload[0])); =20 aligned_msg->connectionid =3D connection_id; aligned_msg->reserved =3D 0; diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c index 2b4080e51f97..d9b569b204d2 100644 --- a/drivers/hv/hv_balloon.c +++ b/drivers/hv/hv_balloon.c @@ -1577,21 +1577,21 @@ static int hv_free_page_report(struct page_reportin= g_dev_info *pr_dev_info, { unsigned long flags; struct hv_memory_hint *hint; - int i, order; + int i, order, batch_size; u64 status; struct scatterlist *sg; =20 - WARN_ON_ONCE(nents > HV_MEMORY_HINT_MAX_GPA_PAGE_RANGES); WARN_ON_ONCE(sgl->length < (HV_HYP_PAGE_SIZE << page_reporting_order)); local_irq_save(flags); - hint =3D *this_cpu_ptr(hyperv_pcpu_input_arg); + + batch_size =3D hv_setup_in_array(&hint, sizeof(*hint), sizeof(hint->range= s[0])); if (!hint) { local_irq_restore(flags); return -ENOSPC; } + WARN_ON_ONCE(nents > batch_size); =20 hint->heat_type =3D HV_EXTMEM_HEAT_HINT_COLD_DISCARD; - hint->reserved =3D 0; for_each_sg(sgl, sg, nents, i) { union hv_gpa_page_range *range; =20 diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c index 49898d10faff..ae56397af1ed 100644 --- a/drivers/hv/hv_common.c +++ b/drivers/hv/hv_common.c @@ -267,7 +267,7 @@ void __init hv_get_partition_id(void) u64 status, pt_id; =20 local_irq_save(flags); - output =3D *this_cpu_ptr(hyperv_pcpu_input_arg); + hv_setup_inout(NULL, 0, &output, sizeof(*output)); status =3D hv_do_hypercall(HVCALL_GET_PARTITION_ID, NULL, output); pt_id =3D output->partition_id; local_irq_restore(flags); @@ -288,13 +288,10 @@ u8 __init get_vtl(void) u64 ret; =20 local_irq_save(flags); - input =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - output =3D *this_cpu_ptr(hyperv_pcpu_output_arg); - - memset(input, 0, struct_size(input, names, 1)); + hv_setup_inout_array(&input, sizeof(*input), sizeof(input->names[0]), + &output, sizeof(*output), sizeof(output->values[0])); input->partition_id =3D HV_PARTITION_ID_SELF; input->vp_index =3D HV_VP_INDEX_SELF; - input->input_vtl.as_uint8 =3D 0; input->names[0] =3D HV_REGISTER_VSM_VP_STATUS; =20 ret =3D hv_do_hypercall(control, input, output); diff --git a/drivers/hv/hv_proc.c b/drivers/hv/hv_proc.c index fbb4eb3901bb..bd63830b4141 100644 --- a/drivers/hv/hv_proc.c +++ b/drivers/hv/hv_proc.c @@ -9,12 +9,6 @@ #include #include =20 -/* - * See struct hv_deposit_memory. The first u64 is partition ID, the rest - * are GPAs. - */ -#define HV_DEPOSIT_MAX (HV_HYP_PAGE_SIZE / sizeof(u64) - 1) - /* Deposits exact number of pages. Must be called with interrupts enabled.= */ int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages) { @@ -25,11 +19,13 @@ int hv_call_deposit_pages(int node, u64 partition_id, u= 32 num_pages) int order; u64 status; int ret; - u64 base_pfn; + u64 base_pfn, batch_size; struct hv_deposit_memory *input_page; unsigned long flags; =20 - if (num_pages > HV_DEPOSIT_MAX) + batch_size =3D hv_get_input_batch_size(sizeof(*input_page), + sizeof(input_page->gpa_page_list[0])); + if (num_pages > batch_size) return -E2BIG; if (!num_pages) return 0; @@ -40,7 +36,7 @@ int hv_call_deposit_pages(int node, u64 partition_id, u32= num_pages) return -ENOMEM; pages =3D page_address(page); =20 - counts =3D kcalloc(HV_DEPOSIT_MAX, sizeof(int), GFP_KERNEL); + counts =3D kcalloc(batch_size, sizeof(int), GFP_KERNEL); if (!counts) { free_page((unsigned long)pages); return -ENOMEM; @@ -74,7 +70,9 @@ int hv_call_deposit_pages(int node, u64 partition_id, u32= num_pages) =20 local_irq_save(flags); =20 - input_page =3D *this_cpu_ptr(hyperv_pcpu_input_arg); + /* Batch size is checked at the start of function; no need to repeat */ + hv_setup_in_array(&input_page, sizeof(*input_page), + sizeof(input_page->gpa_page_list[0])); =20 input_page->partition_id =3D partition_id; =20 @@ -126,9 +124,8 @@ int hv_call_add_logical_proc(int node, u32 lp_index, u3= 2 apic_id) do { local_irq_save(flags); =20 - input =3D *this_cpu_ptr(hyperv_pcpu_input_arg); /* We don't do anything with the output right now */ - output =3D *this_cpu_ptr(hyperv_pcpu_output_arg); + hv_setup_inout(&input, sizeof(*input), &output, sizeof(*output)); =20 input->lp_index =3D lp_index; input->apic_id =3D apic_id; @@ -169,7 +166,7 @@ int hv_call_create_vp(int node, u64 partition_id, u32 v= p_index, u32 flags) do { local_irq_save(irq_flags); =20 - input =3D *this_cpu_ptr(hyperv_pcpu_input_arg); + hv_setup_in(&input, sizeof(*input)); =20 input->partition_id =3D partition_id; input->vp_index =3D vp_index; --=20 2.25.1 From nobody Mon Oct 6 19:04:39 2025 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31AE71F4C85; Fri, 18 Jul 2025 04:56:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752814565; cv=none; b=uD88c07uUeRxHRtLONfIU6YdSrR1XC31BNMpsdx6rdHlicQvD0IkLLlEb9o7kKel/RYUm43Lg+XJ0Zy4VOw3I0bou+GhkaBblM7GLTijc/V7tWxXoO7qqUfPymZj7Xt2N5ZUlDsBkKOlmCLyMq50Us/o3Q14pUvm5YtPsSn4LAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752814565; c=relaxed/simple; bh=BKaWIB2wgYVNtYQhaONki9R26s0WjL2v0ItYEtgD5Fs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mpQjgmoUBnkgHczDmYCHGTMUnTR2A+cXY2fde1A95i/ms0+yn2mtvSRFRlsBlBGuW4eAUbcR2KY+YKFgjWqTU03iFTgw/EsWK0rouasGP7Hc6UqfPOLlOVfwGW//vQFxnkoPVoRWhI8dD+5J68Wp7NpH7TaMqghfeLoPqXyC0wI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=F21PP2Qm; arc=none smtp.client-ip=209.85.216.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="F21PP2Qm" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-313bb9b2f5bso1730465a91.3; Thu, 17 Jul 2025 21:56:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752814563; x=1753419363; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=OELaLUArYgl6Nbrrs2otOCrr4yJAcP+COHiIGixloOU=; b=F21PP2QmDkAGCzDElJtz5bsTkmqBWH7iVD77e1386HNMS4cbJCdwc+uUdft6B+/l7V VFixLUPo1ABNij2Wa1ayMiGwjxCrnzcfV2LycknCMs0Qif3vzo12AXMOuuPrQxr0QQdV 9+p2GAL0Cb7T/cWYRXf9+E3Ri4Yhoja9yEy98BQHgPuhuyBp1lLYmXBllnTZiCzN7A11 SYYSE7P5L45F/PYdpSZ1+wUxfJAsQFbit3HXE8BBCGr3zd6WdqP3OfImi/pCJEkRfII2 OyPkW0G2XsLAZ7KERRAlLDT+T+XoQVFbl+nBAoTGCHbFOZGJKl+rVt6HMX04YWPdjVKg 4vwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752814563; x=1753419363; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=OELaLUArYgl6Nbrrs2otOCrr4yJAcP+COHiIGixloOU=; b=sfXADfW4dFbqREVM7Xjj16mVCesiEMNRwnlRGG8cIwX4l6J/snS9LE9j5Vzb3TwBDp 7H7okc6FtvZldZM7PTMI44YKtN4THWaqiLeW5SS/12aQ5V0XODouj8LsVq+CVB002KIE djGtkp11cgLSUE4I90VUt83d1gwp63qSj4RMA/g4BFPY62GcJG8KWEdFV6Qp1rFiDH23 2MNfxkdp/zyJRBaKKP+8FiUUzFKm/Gin0Zwaq9sB/yKXJ4YQ9/357El1d4llXq43ELZ6 a8zzs23TOOAZNjhG4rqHqEBnDw5YINjuTfTHayqZH4TlUxuAXspNnCUiiJYs3qxLi/yW se5g== X-Forwarded-Encrypted: i=1; AJvYcCUZ96eToMeVDjN/OqU9+RR0GqeKrXGgGrWU/Zega91N9A4UgVCIT5etJmq3rPHMwW+7nInZqjR/wFijUXVZ@vger.kernel.org, AJvYcCVNM+hHv9+wXhRcOH0ZFx750aXzBz4BoWNTTURi/JVS/Nz0O27lpqfi7wJ2tkPfZkDc4xv+6UkOKiBt@vger.kernel.org, AJvYcCWSpiEk1FgahXrOMRMM0AcNd1am5UWYOdxxDJGngMbSSLfSty5EfjGnuc5ygVKUL9GPfYyL/4v93I6NmEUL@vger.kernel.org, AJvYcCXWWMiY0G40ig7+kvUySjtfnv8Wshi28zLDVm/UCekzWMl1E5Qbg4R5vcXZubvL/wiaG76tuJ0J9W7C@vger.kernel.org X-Gm-Message-State: AOJu0Yyoe3MS6/fWpfad0PRYSEuJw23j+ZommhNqbp1D/zVyWLXB05Mc 3SC3nXa2G6aZEVUEvusepXf8NIKncH+9X+2fpl4RSUjuAi+qKL6siM44 X-Gm-Gg: ASbGnctw3I10+MFHw0UdMLo5hVGmRevWokxxKtiy7/qA5F/u651vmr6JH9uzyPZo3WR tCXAiLVU/IIwgyxLyUp0DWwBlRxambGF0q5pd0HfFrW5VNAXYU4nhTD9Mvnc4mT3knA6d8QROlH jQJdYCiWbw0OwL2HT9b93JBbN4+Y4OHd+mLV0q+MXfvP0WIVMTjxTdYzKxjiNQ8DIN41td1nRkm +3y0anuIs36prOcMg6OmzvJUAJo2LSDBHPsmCZrjtQsnlGe9mQb4SwMyg1+e0ise5DbttrmZ/WU ST/F3e+N3F4bI5C1XBIlqeaR78op+ZaYVafPwwEBqXRlK66UqP5nfNSU6vp4v82Yjs5V/dkiA4U 4SfkK53iOTI6rI0JJqoNW62ANz/UhFAMDF4Q5XKe2R+ZYN8Ko0cGzrEqWVcVQ99IdWYYoWYBWVk 41Aw== X-Google-Smtp-Source: AGHT+IFB4pKgv+NsYZFlQrIsfY406acCVGR4YZib65yN3O+pU6FCfbS2MibN7/36bzl4d5JgsYpoAA== X-Received: by 2002:a17:90b:2542:b0:313:d6ce:6c6e with SMTP id 98e67ed59e1d1-31caf8433admr8045510a91.8.1752814563364; Thu, 17 Jul 2025 21:56:03 -0700 (PDT) Received: from localhost.localdomain (c-67-160-120-253.hsd1.wa.comcast.net. [67.160.120.253]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-31cc33715b2sm476907a91.24.2025.07.17.21.56.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jul 2025 21:56:03 -0700 (PDT) From: mhkelley58@gmail.com X-Google-Original-From: mhklinux@outlook.com To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, lpieralisi@kernel.org, kw@linux.com, mani@kernel.org, robh@kernel.org, bhelgaas@google.com, arnd@arndb.de Cc: x86@kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org Subject: [PATCH v4 5/7] PCI: hv: Use hv_setup_*() to set up hypercall arguments Date: Thu, 17 Jul 2025 21:55:43 -0700 Message-Id: <20250718045545.517620-6-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250718045545.517620-1-mhklinux@outlook.com> References: <20250718045545.517620-1-mhklinux@outlook.com> Reply-To: mhklinux@outlook.com Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Michael Kelley Update hypercall call sites to use the new hv_setup_*() functions to set up hypercall arguments. Since these functions zero the fixed portion of input memory, remove now redundant calls to memset(). Signed-off-by: Michael Kelley Acked-by: Bjorn Helgaas Reviewed-by: Easwar Hariharan Reviewed-by: Nuno Das Neves --- Notes: Changes in v4: * Rename hv_hvcall_*() functions to hv_setup_*() [Easwar Hariharan] * Rename hv_hvcall_in_batch_size() to hv_get_input_batch_size() [Easwar Hariharan] =20 Changes in v3: * Removed change to definition of struct hv_mmio_write_input so it rema= ins consistent with original Hyper-V definitions. Adjusted argument to hv_hvcall_in_array() accordingly so that the 64 byte 'data' array is not zero'ed. [Nuno Das Neves] =20 Changes in v2: * In hv_arch_irq_unmask(), added check of the number of computed banks in the hv_vpset against the batch_size. Since an hv_vpset currently represents a maximum of 4096 CPUs, the hv_vpset size does not exceed 512 bytes and there should always be sufficent space. But do the check just in case something changes. [Nuno Das Neves] drivers/pci/controller/pci-hyperv.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/p= ci-hyperv.c index d2b7e8ea710b..79de85d1d68b 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -620,7 +620,7 @@ static void hv_irq_retarget_interrupt(struct irq_data *= data) struct pci_dev *pdev; unsigned long flags; u32 var_size =3D 0; - int cpu, nr_bank; + int cpu, nr_bank, batch_size; u64 res; =20 dest =3D irq_data_get_effective_affinity_mask(data); @@ -636,8 +636,8 @@ static void hv_irq_retarget_interrupt(struct irq_data *= data) =20 local_irq_save(flags); =20 - params =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - memset(params, 0, sizeof(*params)); + batch_size =3D hv_setup_in_array(¶ms, sizeof(*params), + sizeof(params->int_target.vp_set.bank_contents[0])); params->partition_id =3D HV_PARTITION_ID_SELF; params->int_entry.source =3D HV_INTERRUPT_SOURCE_MSI; params->int_entry.msi_entry.address.as_uint32 =3D int_desc->address & 0xf= fffffff; @@ -669,7 +669,7 @@ static void hv_irq_retarget_interrupt(struct irq_data *= data) nr_bank =3D cpumask_to_vpset(¶ms->int_target.vp_set, tmp); free_cpumask_var(tmp); =20 - if (nr_bank <=3D 0) { + if (nr_bank <=3D 0 || nr_bank > batch_size) { res =3D 1; goto out; } @@ -1102,11 +1102,9 @@ static void hv_pci_read_mmio(struct device *dev, phy= s_addr_t gpa, int size, u32 =20 /* * Must be called with interrupts disabled so it is safe - * to use the per-cpu input argument page. Use it for - * both input and output. + * to use the per-cpu argument page. */ - in =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - out =3D *this_cpu_ptr(hyperv_pcpu_input_arg) + sizeof(*in); + hv_setup_inout(&in, sizeof(*in), &out, sizeof(*out)); in->gpa =3D gpa; in->size =3D size; =20 @@ -1135,9 +1133,9 @@ static void hv_pci_write_mmio(struct device *dev, phy= s_addr_t gpa, int size, u32 =20 /* * Must be called with interrupts disabled so it is safe - * to use the per-cpu input argument memory. + * to use the per-cpu argument page. */ - in =3D *this_cpu_ptr(hyperv_pcpu_input_arg); + hv_setup_in_array(&in, offsetof(typeof(*in), data), sizeof(in->data[0])); in->gpa =3D gpa; in->size =3D size; switch (size) { --=20 2.25.1 From nobody Mon Oct 6 19:04:39 2025 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 684A51FDA8C; Fri, 18 Jul 2025 04:56:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752814567; cv=none; b=bICDGcrrAkNAwVW8i1Az2znfRxlHcliBQ4VufaRUOHS6E8c451+FpSKMa5cH9XP/WJ22CthMmCAjqvAsYC9bq5tiqBoGvn/+2S1jSVkOMHK9dCRitwE7lywM309WieroXbAVhm+W5N0CmqjgXzPV0nVmAeieBdxxRt+l5iwWQ7E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752814567; c=relaxed/simple; bh=2FW3b9hlDy2QfBlyM6L0eddthNqwJjvInvNdiM1fCpk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=C3upSorpd7gn8kRxAUP0ktS62cBKmtva8fwOsG50E+Ki0KasYy79cra18lHVeJOxzPk3A8d7k11K1MK2+SR8Ye7e9PlBsR8gDUaaSk0eUTRnBBT5x5DbUxscbmOq3yVSMjMwyHUW2tSj/o3KYHWvlC5AQCOtvolOFWTsUBoo7Hc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Dco5QqMh; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Dco5QqMh" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-23c703c471dso30174575ad.0; Thu, 17 Jul 2025 21:56:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752814565; x=1753419365; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=um63o3hQyH8ovYbmWh8CYFrfthG6rWsgdULfDJ9kl7o=; b=Dco5QqMhoHOB0e4cuLLqzd7gtqm4PH7OpuCrCFxGcoMEdMbH48kPFcgDvJIvb3ctM9 GchRl2fYP7GSJiK5WuPA7KpzkteZOCrWwyUipP7yUupp+BJ9NXW0iwH9eCEd2RdinEMM myC9KN6y7aMO5DiV9dW/NN0AizrvOQdCT6Odx5OYX1ZPsBhzgdkBnk57NqHLpcJZCL9Y uww4c1vR59U21D0dMkTkFnJkfIYlrB4xOwACML7iFA7SgPuH4xg5EMGJ47F6GT4vzh9Q bg9sxWh9ISvquyZW/i/lrZIBHjk+IEGhc0nkXWUckNIR0UGwT+lRzW2/lSYg12/HruiW fG0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752814565; x=1753419365; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=um63o3hQyH8ovYbmWh8CYFrfthG6rWsgdULfDJ9kl7o=; b=fZX6sPDJ6VSJAx6RdpwQcFAx1UMnBaCfHxoEvypZcC0hnytp1hlozhn+fl8ZE3Ugfv uVxDmhzC1Y0v3o1y3cSqxMCBDWHUKJCOOcRhaNnN0drgAQDz8+WYxOBBpSpYW1ETMc4K RnQoYRMYv9Un5bFuKaBaXo8RCG0duec9kqVSCbtUnugBB1/77MJVtzeRwLl2gadMgOUR PxBayn9gR0H5khxJuAlpWRbVACAADKaY0qm98jbvD9dOJ7vVYsoyoEdkgL5zU7TYsisf jvGvk/v8RZbgwxPAuox1Xdi8VarLILuUrbDIEfODvzCk0XI4tzWswtvRxk6CIoBpEqzj zRhw== X-Forwarded-Encrypted: i=1; AJvYcCUwIQOg5emexfG8TP8QtVe5K5+oBfHJ38ZP0LBct7sXLoCcK+jTjPuWrKttnw29lGxXtbnt8+YDBBWch5/R@vger.kernel.org, AJvYcCVWt0TnJgMJMeanCDMdMDZJmLdqesBe5zvk1XZONDcpy/3zJRz9BZ8zhzzhMh/AqXqsXoEghlDO/fOe@vger.kernel.org, AJvYcCW0USi/cWcWDj7REQfvVSjpoamnARAUUUl2uuTG+ahBGSedG6nZCKHel3PTPXrdytTlIAvv91ul6nNHG5jk@vger.kernel.org, AJvYcCXOyRqX2ncuxHIyfrpYw+WBVLqbVsxPbOLDsIReZ4Lr6Ymk6r6AV59lRqv7lwswoZcB7qgsxnvQdLFU@vger.kernel.org X-Gm-Message-State: AOJu0Ywa1QE7cFZMp0pl52/+drgDXEAtGzmVYmCPc3Q2LBbF0qtU6ar/ vi+sEevPPjCFve5rnnfsUne2m33vibBB/3ZUp2VvIqOA2XxBpQPeJDpc X-Gm-Gg: ASbGncuwdUOR8tzgmEl1sgGU0rSgoeoUkUWLYHQh6uHx0l3WcYpaJjdMsMF/OOqx6hc HpzW/GEr2ov5wL1dYd4B112nqhce4rOC5r24xQFFgYFFDn1+2ykgDtxUbywQ98Yy6Bm0LaETAFE gQG+u17CSxmmCPAesfdeOjN1Sd4v0jJyN2rRQ0IsY6HCtiyWSKWvU545wCacZ2Osu5mLrcuoCMx ULQ7lNDHHpDB2kQlzU6zY30BWwdBAZBwNx7OgfzI70SuIQMFbMbSxDWFhn4K4Pvp/ql/84oeDEC 9/afJfnzUFZdI3Nx4+1gYGxRZecYjaWMfOANW/gFaYH+3/kXv9GYAMwHrtyFGZGVzSsjtZ7m7Kt 8q8Qmcc8Ol+bIyLa5qf7eGemS/5Th+XxEX38T/XUX42wOlY3DzqWje022tIJnO43jRxnD0VH/OA R3fw== X-Google-Smtp-Source: AGHT+IEv8vxyq+Vqm9GE2JQvjGRhBxcA9Y9DKTDvqZ5aTZDDy0mu7oqw7p73s43/a/E/vIvAkVt9bw== X-Received: by 2002:a17:902:d4c1:b0:234:595d:a58e with SMTP id d9443c01a7336-23e38fb11efmr35671815ad.25.1752814564606; Thu, 17 Jul 2025 21:56:04 -0700 (PDT) Received: from localhost.localdomain (c-67-160-120-253.hsd1.wa.comcast.net. [67.160.120.253]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-31cc33715b2sm476907a91.24.2025.07.17.21.56.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jul 2025 21:56:04 -0700 (PDT) From: mhkelley58@gmail.com X-Google-Original-From: mhklinux@outlook.com To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, lpieralisi@kernel.org, kw@linux.com, mani@kernel.org, robh@kernel.org, bhelgaas@google.com, arnd@arndb.de Cc: x86@kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org Subject: [PATCH v4 6/7] Drivers: hv: Use hv_setup_*() to set up hypercall arguments for mshv code Date: Thu, 17 Jul 2025 21:55:44 -0700 Message-Id: <20250718045545.517620-7-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250718045545.517620-1-mhklinux@outlook.com> References: <20250718045545.517620-1-mhklinux@outlook.com> Reply-To: mhklinux@outlook.com Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Michael Kelley Update hypercall call sites to use the new hv_setup_*() functions to set up hypercall arguments. Since these functions zero the fixed portion of input memory, remove now redundant calls to memset() and explicit zero'ing of input fields. Where feasible use batch size returned by hv_setup_inout_array() instead of separate #define value. Signed-off-by: Michael Kelley Reviewed-by: Easwar Hariharan Reviewed-by: Nuno Das Neves Tested-by: Nuno Das Neves --- Notes: Changes in v4: * Rename hv_hvcall_*() functions to hv_setup_*() [Easwar Hariharan] * Rename hv_hvcall_in_batch_size() to hv_get_input_batch_size() [Easwar Hariharan] =20 Changes in v3: * This patch is new in v3 due to rebasing on 6.15-rc1, which has new mshv-related hypercalls. drivers/hv/mshv_common.c | 31 +++------ drivers/hv/mshv_root_hv_call.c | 121 +++++++++++++-------------------- drivers/hv/mshv_root_main.c | 5 +- 3 files changed, 60 insertions(+), 97 deletions(-) diff --git a/drivers/hv/mshv_common.c b/drivers/hv/mshv_common.c index 6f227a8a5af7..94f8de66c096 100644 --- a/drivers/hv/mshv_common.c +++ b/drivers/hv/mshv_common.c @@ -17,12 +17,6 @@ =20 #include "mshv.h" =20 -#define HV_GET_REGISTER_BATCH_SIZE \ - (HV_HYP_PAGE_SIZE / sizeof(union hv_register_value)) -#define HV_SET_REGISTER_BATCH_SIZE \ - ((HV_HYP_PAGE_SIZE - sizeof(struct hv_input_set_vp_registers)) \ - / sizeof(struct hv_register_assoc)) - int hv_call_get_vp_registers(u32 vp_index, u64 partition_id, u16 count, union hv_input_vtl input_vtl, struct hv_register_assoc *registers) @@ -30,24 +24,23 @@ int hv_call_get_vp_registers(u32 vp_index, u64 partitio= n_id, u16 count, struct hv_input_get_vp_registers *input_page; union hv_register_value *output_page; u16 completed =3D 0; - unsigned long remaining =3D count; + unsigned long batch_size, remaining =3D count; int rep_count, i; u64 status =3D HV_STATUS_SUCCESS; unsigned long flags; =20 local_irq_save(flags); =20 - input_page =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - output_page =3D *this_cpu_ptr(hyperv_pcpu_output_arg); + batch_size =3D hv_setup_inout_array(&input_page, sizeof(*input_page), + sizeof(input_page->names[0]), + &output_page, 0, sizeof(*output_page)); =20 input_page->partition_id =3D partition_id; input_page->vp_index =3D vp_index; input_page->input_vtl.as_uint8 =3D input_vtl.as_uint8; - input_page->rsvd_z8 =3D 0; - input_page->rsvd_z16 =3D 0; =20 while (remaining) { - rep_count =3D min(remaining, HV_GET_REGISTER_BATCH_SIZE); + rep_count =3D min(remaining, batch_size); for (i =3D 0; i < rep_count; ++i) input_page->names[i] =3D registers[i].name; =20 @@ -76,21 +69,19 @@ int hv_call_set_vp_registers(u32 vp_index, u64 partitio= n_id, u16 count, struct hv_input_set_vp_registers *input_page; u16 completed =3D 0; unsigned long remaining =3D count; - int rep_count; + unsigned long rep_count, batch_size; u64 status =3D HV_STATUS_SUCCESS; unsigned long flags; =20 local_irq_save(flags); - input_page =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - + batch_size =3D hv_setup_in_array(&input_page, sizeof(*input_page), + sizeof(input_page->elements[0])); input_page->partition_id =3D partition_id; input_page->vp_index =3D vp_index; input_page->input_vtl.as_uint8 =3D input_vtl.as_uint8; - input_page->rsvd_z8 =3D 0; - input_page->rsvd_z16 =3D 0; =20 while (remaining) { - rep_count =3D min(remaining, HV_SET_REGISTER_BATCH_SIZE); + rep_count =3D min(remaining, batch_size); memcpy(input_page->elements, registers, sizeof(struct hv_register_assoc) * rep_count); =20 @@ -120,9 +111,7 @@ int hv_call_get_partition_property(u64 partition_id, struct hv_output_get_partition_property *output; =20 local_irq_save(flags); - input =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - output =3D *this_cpu_ptr(hyperv_pcpu_output_arg); - memset(input, 0, sizeof(*input)); + hv_setup_inout(&input, sizeof(*input), &output, sizeof(*output)); input->partition_id =3D partition_id; input->property_code =3D property_code; status =3D hv_do_hypercall(HVCALL_GET_PARTITION_PROPERTY, input, output); diff --git a/drivers/hv/mshv_root_hv_call.c b/drivers/hv/mshv_root_hv_call.c index c9c274f29c3c..7217310b8fc3 100644 --- a/drivers/hv/mshv_root_hv_call.c +++ b/drivers/hv/mshv_root_hv_call.c @@ -22,22 +22,6 @@ #define HV_PAGE_COUNT_2M_ALIGNED(pg_count) (!((pg_count) & (0x200 - 1))) =20 #define HV_WITHDRAW_BATCH_SIZE (HV_HYP_PAGE_SIZE / sizeof(u64)) -#define HV_MAP_GPA_BATCH_SIZE \ - ((HV_HYP_PAGE_SIZE - sizeof(struct hv_input_map_gpa_pages)) \ - / sizeof(u64)) -#define HV_GET_VP_STATE_BATCH_SIZE \ - ((HV_HYP_PAGE_SIZE - sizeof(struct hv_input_get_vp_state)) \ - / sizeof(u64)) -#define HV_SET_VP_STATE_BATCH_SIZE \ - ((HV_HYP_PAGE_SIZE - sizeof(struct hv_input_set_vp_state)) \ - / sizeof(u64)) -#define HV_GET_GPA_ACCESS_STATES_BATCH_SIZE \ - ((HV_HYP_PAGE_SIZE - sizeof(union hv_gpa_page_access_state)) \ - / sizeof(union hv_gpa_page_access_state)) -#define HV_MODIFY_SPARSE_SPA_PAGE_HOST_ACCESS_MAX_PAGE_COUNT \ - ((HV_HYP_PAGE_SIZE - \ - sizeof(struct hv_input_modify_sparse_spa_page_host_access)) / \ - sizeof(u64)) =20 int hv_call_withdraw_memory(u64 count, int node, u64 partition_id) { @@ -58,9 +42,7 @@ int hv_call_withdraw_memory(u64 count, int node, u64 part= ition_id) while (remaining) { local_irq_save(flags); =20 - input_page =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - - memset(input_page, 0, sizeof(*input_page)); + hv_setup_in(&input_page, sizeof(*input_page)); input_page->partition_id =3D partition_id; status =3D hv_do_rep_hypercall(HVCALL_WITHDRAW_MEMORY, min(remaining, HV_WITHDRAW_BATCH_SIZE), @@ -99,10 +81,7 @@ int hv_call_create_partition(u64 flags, =20 do { local_irq_save(irq_flags); - input =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - output =3D *this_cpu_ptr(hyperv_pcpu_output_arg); - - memset(input, 0, sizeof(*input)); + hv_setup_inout(&input, sizeof(*input), &output, sizeof(*output)); input->flags =3D flags; input->compatibility_version =3D HV_COMPATIBILITY_21_H2; =20 @@ -206,11 +185,12 @@ static int hv_do_map_gpa_hcall(u64 partition_id, u64 = gfn, u64 page_struct_count, =20 while (done < page_count) { ulong i, completed, remain =3D page_count - done; - int rep_count =3D min(remain, HV_MAP_GPA_BATCH_SIZE); + ulong rep_count, batch_size; =20 local_irq_save(irq_flags); - input_page =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - + batch_size =3D hv_setup_in_array(&input_page, sizeof(*input_page), + sizeof(input_page->source_gpa_page_list[0])); + rep_count =3D min(remain, batch_size); input_page->target_partition_id =3D partition_id; input_page->target_gpa_base =3D gfn + (done << large_shift); input_page->map_flags =3D flags; @@ -311,7 +291,7 @@ int hv_call_unmap_gpa_pages(u64 partition_id, u64 gfn, = u64 page_count_4k, int rep_count =3D min(remain, HV_UMAP_GPA_PAGES); =20 local_irq_save(irq_flags); - input_page =3D *this_cpu_ptr(hyperv_pcpu_input_arg); + hv_setup_in(&input_page, sizeof(*input_page)); =20 input_page->target_partition_id =3D partition_id; input_page->target_gpa_base =3D gfn + (done << large_shift); @@ -340,7 +320,7 @@ int hv_call_get_gpa_access_states(u64 partition_id, u32= count, u64 gpa_base_pfn, struct hv_input_get_gpa_pages_access_state *input_page; union hv_gpa_page_access_state *output_page; int completed =3D 0; - unsigned long remaining =3D count; + unsigned long batch_size, remaining =3D count; int rep_count, i; u64 status =3D 0; unsigned long flags; @@ -348,13 +328,13 @@ int hv_call_get_gpa_access_states(u64 partition_id, u= 32 count, u64 gpa_base_pfn, *written_total =3D 0; while (remaining) { local_irq_save(flags); - input_page =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - output_page =3D *this_cpu_ptr(hyperv_pcpu_output_arg); + batch_size =3D hv_setup_inout_array(&input_page, sizeof(*input_page), + 0, &output_page, 0, sizeof(*output_page)); =20 input_page->partition_id =3D partition_id; input_page->hv_gpa_page_number =3D gpa_base_pfn + *written_total; input_page->flags =3D state_flags; - rep_count =3D min(remaining, HV_GET_GPA_ACCESS_STATES_BATCH_SIZE); + rep_count =3D min(remaining, batch_size); =20 status =3D hv_do_rep_hypercall(HVCALL_GET_GPA_PAGES_ACCESS_STATES, rep_c= ount, 0, input_page, output_page); @@ -384,8 +364,7 @@ int hv_call_assert_virtual_interrupt(u64 partition_id, = u32 vector, u64 status; =20 local_irq_save(flags); - input =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - memset(input, 0, sizeof(*input)); + hv_setup_in(&input, sizeof(*input)); input->partition_id =3D partition_id; input->vector =3D vector; input->dest_addr =3D dest_addr; @@ -422,21 +401,21 @@ int hv_call_get_vp_state(u32 vp_index, u64 partition_= id, u64 status; int i; u64 control; - unsigned long flags; + unsigned long flags, batch_size; int ret =3D 0; =20 - if (page_count > HV_GET_VP_STATE_BATCH_SIZE) - return -EINVAL; - if (!page_count && !ret_output) return -EINVAL; =20 do { local_irq_save(flags); - input =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - output =3D *this_cpu_ptr(hyperv_pcpu_output_arg); - memset(input, 0, sizeof(*input)); - memset(output, 0, sizeof(*output)); + batch_size =3D hv_setup_inout_array(&input, sizeof(*input), + sizeof(input->output_data_pfns[0]), + &output, sizeof(*output), 0); + if (page_count > batch_size) { + local_irq_restore(flags); + return -EINVAL; + } =20 input->partition_id =3D partition_id; input->vp_index =3D vp_index; @@ -478,11 +457,7 @@ int hv_call_set_vp_state(u32 vp_index, u64 partition_i= d, unsigned long flags; int ret =3D 0; u16 varhead_sz; - - if (page_count > HV_SET_VP_STATE_BATCH_SIZE) - return -EINVAL; - if (sizeof(*input) + num_bytes > HV_HYP_PAGE_SIZE) - return -EINVAL; + u64 batch_size; =20 if (num_bytes) /* round up to 8 and divide by 8 */ @@ -494,18 +469,26 @@ int hv_call_set_vp_state(u32 vp_index, u64 partition_= id, =20 do { local_irq_save(flags); - input =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - memset(input, 0, sizeof(*input)); =20 - input->partition_id =3D partition_id; - input->vp_index =3D vp_index; - input->state_data =3D state_data; if (num_bytes) { + batch_size =3D hv_setup_in_array(&input, sizeof(*input), + sizeof(input->data[0].bytes)); + if (num_bytes > batch_size) + goto size_error; + memcpy((u8 *)input->data, bytes, num_bytes); } else { + batch_size =3D hv_setup_in_array(&input, sizeof(*input), + sizeof(input->data[0].pfns)); + if (page_count > batch_size) + goto size_error; + for (i =3D 0; i < page_count; i++) input->data[i].pfns =3D page_to_pfn(pages[i]); } + input->partition_id =3D partition_id; + input->vp_index =3D vp_index; + input->state_data =3D state_data; =20 control =3D (HVCALL_SET_VP_STATE) | (varhead_sz << HV_HYPERCALL_VARHEAD_OFFSET); @@ -524,6 +507,10 @@ int hv_call_set_vp_state(u32 vp_index, u64 partition_i= d, } while (!ret); =20 return ret; + +size_error: + local_irq_restore(flags); + return -EINVAL; } =20 int hv_call_map_vp_state_page(u64 partition_id, u32 vp_index, u32 type, @@ -539,8 +526,7 @@ int hv_call_map_vp_state_page(u64 partition_id, u32 vp_= index, u32 type, do { local_irq_save(flags); =20 - input =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - output =3D *this_cpu_ptr(hyperv_pcpu_output_arg); + hv_setup_inout(&input, sizeof(*input), &output, sizeof(*output)); =20 input->partition_id =3D partition_id; input->vp_index =3D vp_index; @@ -574,9 +560,7 @@ int hv_call_unmap_vp_state_page(u64 partition_id, u32 v= p_index, u32 type, =20 local_irq_save(flags); =20 - input =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - - memset(input, 0, sizeof(*input)); + hv_setup_in(&input, sizeof(*input)); =20 input->partition_id =3D partition_id; input->vp_index =3D vp_index; @@ -614,8 +598,7 @@ hv_call_create_port(u64 port_partition_id, union hv_por= t_id port_id, =20 do { local_irq_save(flags); - input =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - memset(input, 0, sizeof(*input)); + hv_setup_in(&input, sizeof(*input)); =20 input->port_partition_id =3D port_partition_id; input->port_id =3D port_id; @@ -668,8 +651,7 @@ hv_call_connect_port(u64 port_partition_id, union hv_po= rt_id port_id, =20 do { local_irq_save(flags); - input =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - memset(input, 0, sizeof(*input)); + hv_setup_in(&input, sizeof(*input)); input->port_partition_id =3D port_partition_id; input->port_id =3D port_id; input->connection_partition_id =3D connection_partition_id; @@ -736,10 +718,7 @@ int hv_call_map_stat_page(enum hv_stats_object_type ty= pe, =20 do { local_irq_save(flags); - input =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - output =3D *this_cpu_ptr(hyperv_pcpu_output_arg); - - memset(input, 0, sizeof(*input)); + hv_setup_inout(&input, sizeof(*input), &output, sizeof(*output)); input->type =3D type; input->identity =3D *identity; =20 @@ -773,9 +752,7 @@ int hv_call_unmap_stat_page(enum hv_stats_object_type t= ype, u64 status; =20 local_irq_save(flags); - input =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - - memset(input, 0, sizeof(*input)); + hv_setup_in(&input, sizeof(*input)); input->type =3D type; input->identity =3D *identity; =20 @@ -808,14 +785,14 @@ int hv_call_modify_spa_host_access(u64 partition_id, = struct page **pages, } =20 while (done < page_count) { - ulong i, completed, remain =3D page_count - done; - int rep_count =3D min(remain, - HV_MODIFY_SPARSE_SPA_PAGE_HOST_ACCESS_MAX_PAGE_COUNT); + ulong i, batch_size, completed, remain =3D page_count - done; + ulong rep_count; =20 local_irq_save(irq_flags); - input_page =3D *this_cpu_ptr(hyperv_pcpu_input_arg); + batch_size =3D hv_setup_in_array(&input_page, sizeof(*input_page), + sizeof(input_page->spa_page_list[0])); + rep_count =3D min(remain, batch_size); =20 - memset(input_page, 0, sizeof(*input_page)); /* Only set the partition id if you are making the pages * exclusive */ diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c index 72df774e410a..aca3331ad516 100644 --- a/drivers/hv/mshv_root_main.c +++ b/drivers/hv/mshv_root_main.c @@ -2051,11 +2051,8 @@ static int __init hv_retrieve_scheduler_type(enum hv= _scheduler_type *out) u64 status; =20 local_irq_save(flags); - input =3D *this_cpu_ptr(hyperv_pcpu_input_arg); - output =3D *this_cpu_ptr(hyperv_pcpu_output_arg); =20 - memset(input, 0, sizeof(*input)); - memset(output, 0, sizeof(*output)); + hv_setup_inout(&input, sizeof(*input), &output, sizeof(*output)); input->property_id =3D HV_SYSTEM_PROPERTY_SCHEDULER_TYPE; =20 status =3D hv_do_hypercall(HVCALL_GET_SYSTEM_PROPERTY, input, output); --=20 2.25.1 From nobody Mon Oct 6 19:04:39 2025 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D92F220B7FE; Fri, 18 Jul 2025 04:56:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752814568; cv=none; b=lLDi36uChCUbsvoZA0us8ymCkdrtnoKJg3O3KMmLZh4juJAY4zpIZOjiWqFXNrsAj8qGFy7srMRBS6SKKJN7UQQ+hAJ6RRTnrrFvRQ6rqYqn/aaRmsdAd0HhZSKkIF3sj5X0DoKn6z2YfpQ1HqyS3IajILPrphFl4PH34QsIRCA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752814568; c=relaxed/simple; bh=qWNTk3s5NMApXRRxOjCX+WO/fKr3OFV7Wg0UAiRzQiU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TijvBLiyoaGSeqhXJnX4ks7MxSIV2KygQ9mbqsUOoNQoiPEPBaxrbY7FTLsMtkAJp9EQebaypr+WS4zHqfRTqsh1jhtpnKHJrEXYzU66ftalbyTqE5oatlNRUfg3FsxfZuR8jrP5H22mQuEWLxQy0YzYRqYdryudrWvF7eVqHzs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MAD+mSg2; arc=none smtp.client-ip=209.85.215.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MAD+mSg2" Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-b3be5c0eb99so1326313a12.1; Thu, 17 Jul 2025 21:56:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752814566; x=1753419366; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=aiqelOOvokSP2vkZ7DaRUC0h4xNTtXyC0hk2XiiiVRw=; b=MAD+mSg2VvMCII/xudgNR6JWR843jI3mrEswkr4fKeKlCzTBO2oqaF5Zonti+y3kiY j1Xv/drxuxV3Ro0xhgd8CXwzQgWApJWRkaRNkll7iXl6Kvl70eY+6PdXzazGKFOs3Ey0 9Tu5cxamq4KHD8SDKnGh7dUME50St60fKRjRQbfiRggv5WXZmFtp1DAglh9N3UjTkiYM /VqAZJQdkHYHakllpFB5GCg5Eb+ciAuIyhgHixMdSg8YN440zNLa72cEvIKSxEJ5u68e C1/bW6YL15a6V8Bi89CYIGyyBYGl/QWCGEb6uegIDAMZKr1r1NUiwizWFr2x8aPP8DsG YsyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752814566; x=1753419366; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=aiqelOOvokSP2vkZ7DaRUC0h4xNTtXyC0hk2XiiiVRw=; b=R93ZyAbwI7ApNDSiouC9hIhnDgH039V5ojHCfWyfJFRWMmXouLxFmPldx4JwWHoQCA KyFl6gTAb/ZeEKCo5hhyTFIxr81YViHsrI9kYLGNgJGsJsxDTmkNrPyudU6rp1ZGlcbE dlpRYBFPaXf9Ce1zoBfrlas/soZiVqNA3J/kI73AfqVRurdIXoeBCTq5HQ6b0Vs2JqO2 Bc0VpNp50U7vvTxE5ni9aDuwh+cGXkSZe4WJLkeJwrQUga9bqWtey8LIt3w0QCcpE1xZ S2ijgZtcVIcEmC1LBVoZQRrCgQlM7iVsjkQ+gZdqHKU/hrc+BpHjlO2Klvxblgcjkc46 xauQ== X-Forwarded-Encrypted: i=1; AJvYcCU5s91JZou9XBQZZWNb/RBOZnP34/qnqkmJjXdHs01b/lmRdPxBWeVOpcdLqTjpk91PVGByTmq+RcDfhngU@vger.kernel.org, AJvYcCUkpNH5zlLk8BoLE+F1k5fjAa3PAADBzEt0+N9NOgTTQy8tGhlK5W96YCe4khp/q2BT6CmHT8NMtXBG@vger.kernel.org, AJvYcCWPYyGkgxOfNaWGz2STsV6fq/++BZhrdXEov3qFs73lgDsph5sgBz4M2VxGRWXkq9K2FmHqHJOGAftQ@vger.kernel.org, AJvYcCXwPxzvD6m4AanXXsDtsCnPr5MzrMfHabiiiwktDsHYKn76rAZRP9gZ24JBlP0KYbyBym84H76SFhcle0hE@vger.kernel.org X-Gm-Message-State: AOJu0YwnQZfiGZ/SszFY2aab+2XKNzAmz1uegYFEtde8enHbcGAYtQQR 37W9h5s0IljjafJ/lg8cVCvNa3+Erh5vad/UKLxCLsWgvw8lmBho3eQU X-Gm-Gg: ASbGncuLAggrKN/Wr4I67IX0CURDOpVgZ23nLVst3znuxfsp4bj7ECOPbfKdvnVgVyi 6LCVjG1Cw52dXYPpYLu2CAM715CCauFy045kLtJ1L+59IIoi1msdrwa5axJLcLy0epMnJSmZsGV Vr8plqYqnBmkcwrojdcHcyRmV+2U4LJ30p5nM3iKbm9HNAXbRT41tQrVB1Z8L82Wsb3whWpbQP7 TkfPdOxL4hlgQ3v9sP4JFcc06AO47cL0cAMwUfmC/8u3DGCr3+hjsQbXoiREKbgGX8LgnWP7X9u eilirqMimr+7iq6GGYJ42G0u0NnoiUVLGV8DlZa8MT0cVc5NWCKHAOi95e3ikU0kDzMn91pclXa UER2U+ykLKtRRehraICAV/nMwD6ZwnBHoKdWk/Qq7DguZkU7BLikNZATXfW21I47fhTGdAuGjrN CSUQ== X-Google-Smtp-Source: AGHT+IGDjq2DhqSuXgN/POALmXPVtNVWI+Et+6g2VTK4Goj/AQzWa3UeW+fqHh7e9/h5vhGmctCDVQ== X-Received: by 2002:a17:90b:1c04:b0:312:e9bd:5d37 with SMTP id 98e67ed59e1d1-31cc2515a29mr2420920a91.6.1752814565898; Thu, 17 Jul 2025 21:56:05 -0700 (PDT) Received: from localhost.localdomain (c-67-160-120-253.hsd1.wa.comcast.net. [67.160.120.253]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-31cc33715b2sm476907a91.24.2025.07.17.21.56.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jul 2025 21:56:05 -0700 (PDT) From: mhkelley58@gmail.com X-Google-Original-From: mhklinux@outlook.com To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, lpieralisi@kernel.org, kw@linux.com, mani@kernel.org, robh@kernel.org, bhelgaas@google.com, arnd@arndb.de Cc: x86@kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org Subject: [PATCH v4 7/7] Drivers: hv: Replace hyperv_pcpu_input/output_arg with hyperv_pcpu_arg Date: Thu, 17 Jul 2025 21:55:45 -0700 Message-Id: <20250718045545.517620-8-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250718045545.517620-1-mhklinux@outlook.com> References: <20250718045545.517620-1-mhklinux@outlook.com> Reply-To: mhklinux@outlook.com Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Michael Kelley All open coded uses of hyperv_pcpu_input_arg and hyperv_pcpu_ouput_arg have been replaced by hv_setup_*() functions. So combine hyperv_pcpu_input_arg and hyperv_pcpu_output_arg in a single hyperv_pcpu_arg. Remove logic for managing a separate output arg. Fixup comment references to the old variable names. Signed-off-by: Michael Kelley Reviewed-by: Easwar Hariharan Reviewed-by: Nuno Das Neves --- arch/x86/hyperv/hv_init.c | 6 ++-- drivers/hv/hv.c | 2 +- drivers/hv/hv_common.c | 55 ++++++++++------------------------ drivers/hv/hyperv_vmbus.h | 2 +- include/asm-generic/mshyperv.h | 6 +--- 5 files changed, 22 insertions(+), 49 deletions(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index b7a2877c2a92..2979d15223cf 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -453,16 +453,16 @@ void __init hyperv_init(void) * A TDX VM with no paravisor only uses TDX GHCI rather than hv_hypercall= _pg: * when the hypercall input is a page, such a VM must pass a decrypted * page to Hyper-V, e.g. hv_post_message() uses the per-CPU page - * hyperv_pcpu_input_arg, which is decrypted if no paravisor is present. + * hyperv_pcpu_arg, which is decrypted if no paravisor is present. * * A TDX VM with the paravisor uses hv_hypercall_pg for most hypercalls, * which are handled by the paravisor and the VM must use an encrypted - * input page: in such a VM, the hyperv_pcpu_input_arg is encrypted and + * input page: in such a VM, the hyperv_pcpu_arg is encrypted and * used in the hypercalls, e.g. see hv_mark_gpa_visibility() and * hv_arch_irq_unmask(). Such a VM uses TDX GHCI for two hypercalls: * 1. HVCALL_SIGNAL_EVENT: see vmbus_set_event() and _hv_do_fast_hypercal= l8(). * 2. HVCALL_POST_MESSAGE: the input page must be a decrypted page, i.e. - * hv_post_message() in such a VM can't use the encrypted hyperv_pcpu_inp= ut_arg; + * hv_post_message() in such a VM can't use the encrypted hyperv_pcpu_arg; * instead, hv_post_message() uses the post_msg_page, which is decrypted * in such a VM and is only used in such a VM. */ diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index ad063f535f95..3b5dfdecdfe7 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -60,7 +60,7 @@ int hv_post_message(union hv_connection_id connection_id, /* * A TDX VM with the paravisor must use the decrypted post_msg_page: see * the comment in struct hv_per_cpu_context. A SNP VM with the paravisor - * can use the encrypted hyperv_pcpu_input_arg because it copies the + * can use the encrypted hyperv_pcpu_arg because it copies the * input into the GHCB page, which has been decrypted by the paravisor. */ if (hv_isolation_type_tdx() && ms_hyperv.paravisor_present) diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c index ae56397af1ed..cbe4a954ad46 100644 --- a/drivers/hv/hv_common.c +++ b/drivers/hv/hv_common.c @@ -58,11 +58,8 @@ EXPORT_SYMBOL_GPL(hv_vp_index); u32 hv_max_vp_index; EXPORT_SYMBOL_GPL(hv_max_vp_index); =20 -void * __percpu *hyperv_pcpu_input_arg; -EXPORT_SYMBOL_GPL(hyperv_pcpu_input_arg); - -void * __percpu *hyperv_pcpu_output_arg; -EXPORT_SYMBOL_GPL(hyperv_pcpu_output_arg); +void * __percpu *hyperv_pcpu_arg; +EXPORT_SYMBOL_GPL(hyperv_pcpu_arg); =20 static void hv_kmsg_dump_unregister(void); =20 @@ -95,11 +92,8 @@ void __init hv_common_free(void) kfree(hv_vp_index); hv_vp_index =3D NULL; =20 - free_percpu(hyperv_pcpu_output_arg); - hyperv_pcpu_output_arg =3D NULL; - - free_percpu(hyperv_pcpu_input_arg); - hyperv_pcpu_input_arg =3D NULL; + free_percpu(hyperv_pcpu_arg); + hyperv_pcpu_arg =3D NULL; =20 free_percpu(hv_synic_eventring_tail); hv_synic_eventring_tail =3D NULL; @@ -255,11 +249,6 @@ static void hv_kmsg_dump_register(void) } } =20 -static inline bool hv_output_page_exists(void) -{ - return hv_root_partition() || IS_ENABLED(CONFIG_HYPERV_VTL_MODE); -} - void __init hv_get_partition_id(void) { struct hv_output_get_partition_id *output; @@ -365,14 +354,8 @@ int __init hv_common_init(void) * (per-CPU) hypercall input page and thus this failure is * fatal on Hyper-V. */ - hyperv_pcpu_input_arg =3D alloc_percpu(void *); - BUG_ON(!hyperv_pcpu_input_arg); - - /* Allocate the per-CPU state for output arg for root */ - if (hv_output_page_exists()) { - hyperv_pcpu_output_arg =3D alloc_percpu(void *); - BUG_ON(!hyperv_pcpu_output_arg); - } + hyperv_pcpu_arg =3D alloc_percpu(void *); + BUG_ON(!hyperv_pcpu_arg); =20 if (hv_root_partition()) { hv_synic_eventring_tail =3D alloc_percpu(u8 *); @@ -466,33 +449,28 @@ void __init ms_hyperv_late_init(void) =20 int hv_common_cpu_init(unsigned int cpu) { - void **inputarg, **outputarg; + void **inputarg; u8 **synic_eventring_tail; u64 msr_vp_index; gfp_t flags; - const int pgcount =3D hv_output_page_exists() ? 2 : 1; + const int pgcount =3D HV_HVCALL_ARG_PAGES; void *mem; int ret =3D 0; =20 /* hv_cpu_init() can be called with IRQs disabled from hv_resume() */ flags =3D irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL; =20 - inputarg =3D (void **)this_cpu_ptr(hyperv_pcpu_input_arg); + inputarg =3D (void **)this_cpu_ptr(hyperv_pcpu_arg); =20 /* - * The per-cpu memory is already allocated if this CPU was previously - * online and then taken offline + * hyperv_pcpu_arg memory is already allocated if this CPU was + * previously online and then taken offline */ if (!*inputarg) { mem =3D kmalloc(pgcount * HV_HYP_PAGE_SIZE, flags); if (!mem) return -ENOMEM; =20 - if (hv_output_page_exists()) { - outputarg =3D (void **)this_cpu_ptr(hyperv_pcpu_output_arg); - *outputarg =3D (char *)mem + HV_HYP_PAGE_SIZE; - } - if (!ms_hyperv.paravisor_present && (hv_isolation_type_snp() || hv_isolation_type_tdx())) { ret =3D set_memory_decrypted((unsigned long)mem, pgcount); @@ -506,13 +484,13 @@ int hv_common_cpu_init(unsigned int cpu) =20 /* * In a fully enlightened TDX/SNP VM with more than 64 VPs, if - * hyperv_pcpu_input_arg is not NULL, set_memory_decrypted() -> + * hyperv_pcpu_arg is not NULL, set_memory_decrypted() -> * ... -> cpa_flush()-> ... -> __send_ipi_mask_ex() tries to - * use hyperv_pcpu_input_arg as the hypercall input page, which + * use hyperv_pcpu_arg as the hypercall input page, which * must be a decrypted page in such a VM, but the page is still * encrypted before set_memory_decrypted() returns. Fix this by * setting *inputarg after the above set_memory_decrypted(): if - * hyperv_pcpu_input_arg is NULL, __send_ipi_mask_ex() returns + * hyperv_pcpu_arg is NULL, __send_ipi_mask_ex() returns * HV_STATUS_INVALID_PARAMETER immediately, and the function * hv_send_ipi_mask() falls back to orig_apic.send_IPI_mask(), * which may be slightly slower than the hypercall, but still @@ -544,9 +522,8 @@ int hv_common_cpu_die(unsigned int cpu) { u8 **synic_eventring_tail; /* - * The hyperv_pcpu_input_arg and hyperv_pcpu_output_arg memory - * is not freed when the CPU goes offline as the hyperv_pcpu_input_arg - * may be used by the Hyper-V vPCI driver in reassigning interrupts + * The hyperv_pcpu_arg memory is not freed when the CPU goes offline as + * it may be used by the Hyper-V vPCI driver in reassigning interrupts * as part of the offlining process. The interrupt reassignment * happens *after* the CPUHP_AP_HYPERV_ONLINE state has run and * called this function. diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h index 0b450e53161e..bef8a57100ec 100644 --- a/drivers/hv/hyperv_vmbus.h +++ b/drivers/hv/hyperv_vmbus.h @@ -126,7 +126,7 @@ struct hv_per_cpu_context { /* * The page is only used in hv_post_message() for a TDX VM (with the * paravisor) to post a messages to Hyper-V: when such a VM calls - * HVCALL_POST_MESSAGE, it can't use the hyperv_pcpu_input_arg (which + * HVCALL_POST_MESSAGE, it can't use the hyperv_pcpu_arg (which * is encrypted in such a VM) as the hypercall input page, because * the input page for HVCALL_POST_MESSAGE must be decrypted in such a * VM, so post_msg_page (which is decrypted in hv_synic_alloc()) is diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h index 040c4650f411..3ce5b94ad41e 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -67,8 +67,7 @@ extern bool hv_nested; extern u64 hv_current_partition_id; extern enum hv_partition_type hv_curr_partition_type; =20 -extern void * __percpu *hyperv_pcpu_input_arg; -extern void * __percpu *hyperv_pcpu_output_arg; +extern void * __percpu *hyperv_pcpu_arg; =20 u64 hv_do_hypercall(u64 control, void *inputaddr, void *outputaddr); u64 hv_do_fast_hypercall8(u16 control, u64 input8); @@ -155,9 +154,6 @@ static inline u64 hv_do_rep_hypercall(u16 code, u16 rep= _count, u16 varhead_size, * Hypercall input and output argument setup */ =20 -/* Temporary mapping to be removed at the end of the patch series */ -#define hyperv_pcpu_arg hyperv_pcpu_input_arg - /* * Allocate one page that is shared between input and output args, which is * sufficient for all current hypercalls. If a future hypercall requires --=20 2.25.1