From patchwork Tue Apr 15 18:07:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Kelley X-Patchwork-Id: 14052533 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 94FDC220694; Tue, 15 Apr 2025 18:07:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744740474; cv=none; b=j96YruBIlMkeIGwBqf8w6DFS2wCa08ai3ZH9Z2cqQgMyKJZrxCPohIn7DhF4kApTw1VW2hw9xJVYulMR/oUe0b9YagKYcGrLkOZv1yw4BG/MUa80Evn/XhXc0Jd0PotKsBsdLndp7tTu1pu+XlUbtIoi9XWmpyvRbGwIUiY0t4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744740474; c=relaxed/simple; bh=MIdo8wWB+nWkjRShAhT6PWpG1r+kClw3NkgN2Yk49h8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=P6jNr/o/zVga459xCuhKiTSQ2PHu1q7FNbTVzJjewl870d/SA50bigdqZqqL4lYTsHJYgpKTf1+320RhOWJ7ZY6kClhP+m1Wh6sh33d+TwaELr/Vdaznq3CIrTDvg8udQ/cA+hAX9GIu7cpFhgZqvsQGs+7DH20p2LVeNl1j0XE= 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=J5NXeHbe; arc=none smtp.client-ip=209.85.214.178 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="J5NXeHbe" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-22548a28d0cso85250015ad.3; Tue, 15 Apr 2025 11:07:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744740472; x=1745345272; 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=T2Uucqf74/AJpdwAAeV0TOpvsswe9NobdikB/z3wisY=; b=J5NXeHbe+RJFpNZQ87l8Q7O1BEk5zTAo1UMQEUDjYIGibrJmAK5X69dRx8pfQYEGzH 7kNJ45eHu/D1kKyr8r/cmkGN1QVSks245Sfn/i0JSr62PrOUiIl0+CfYBeFuIvw9xl2a g6lFRFBJnbBiK9ZEhZnyJ0jlQgtV62jH3se8FvAtEGDEmzUw9oMF1SCn/i3dD30mryve wVugf9cv1/8Xl8bCEbKxgw2zshO1xEGjLyfHwf9g6cMu/EFIrTo9CcLXRzqQg0swrvr6 x4YyOyI9OgjNOK7Tt8viWu5xyRb8dQZjM/cwO3BO03+toU4aYkjRDHgFFHFlL1NbYwpf OeWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744740472; x=1745345272; 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=T2Uucqf74/AJpdwAAeV0TOpvsswe9NobdikB/z3wisY=; b=HSg6UjWIVGQePqePTyHhJ+yOZsPtrthtNjDHoKvRBxD6K5nXJ1g1Jd48cG9eQzrNX1 5H8pQsAnjiIteqE7dwzL/7Cey/bGCcUWFiZZYXkzU31usC/Qnpb+BBWlFBzDJRuA/kWR fm97VPnim9NcyptkcCzVb0n0XmQw8EXP3ISYx/dsaGE82YQBGwUOA0wSkMRC+r3s8uiI eySB/hVPmdemvqkfJxl8EmkXXy4a1SzfUI4svyzKubiktbFUUCHPWIExANl0Rs2NqxJO 07VJmkNH0ZZNr3a8Cw0Y69Lv0ShFH6KM23Q6GDLwbhuNTBg34YgaI1ldcypOPSNP46dV lRVA== X-Forwarded-Encrypted: i=1; AJvYcCUEEbXbswWNTjnCwriVNCQ9TQVe6TvtH2wpZgxY7fd5c2cC+NPAEKM+pPIIqJ4JgvAKgJpZPLPGEFR9@vger.kernel.org, AJvYcCUN9F6fOnk5Ovdtu1jZRKr+PY3QxNA5JN8Y+MzPeR5lnEe6BYizdkPgr4IoAejYGYH31boSn6sxvtVHzPKH@vger.kernel.org, AJvYcCWkR8XyHs5n020YGcz0KRwRQCYF1yfbF/0r55KbxUPpw8Xgsgmz+CHj7VgwNkl5D3IvxlVZ8+1+hFMZEndT@vger.kernel.org, AJvYcCXZgIp5VpjyIKU1+YyEnSJNzGbqspYDltW3nbtBKkt/OHBFDtDJ9e2/PrVWuHKXpGDkNF7oos+Ra3Tb@vger.kernel.org X-Gm-Message-State: AOJu0YwOhQTdzBC2VwFuThDAPXFMTHEE67zBuGSWu6NUOaF5vAoNqe+V 9eh6uBx8UWUaxi0C3mqEfF/dlYTBUJQSleqHB1Ts97j21oSny3tX X-Gm-Gg: ASbGnctosq85L7fyNh7EDr+n7HaZUublB3ZHxBYIgRSbyDVimJ7oj/6QkI/zw6yXjkH 2Ma/I4qH+oOrKv5GBXVaepeY9G0FLJ+kKnvTPloZ5CaGjZ9Kl7oC9ArWqR31gZNO+j0Hb7yttjM vyxlNcSpuyO0U9Ic2cNE39z+5FvzqKnNDWJ8KVE1JcFFC4pfKX3qazh9w2BiGzMXyWZQjA6gJgo ClJhigY3V3RT+SmEmBYQ3JfWGPH5sF/G1vB2FhGGL5AddF2qXaSooOcHwoZ33QzCLkd3LEi2iEr VAKUU7rA+lLZl7NtSOaN+zFn6hsjTD7Lmz+iTYEYaRLdmkyYPzdVQlSlCNchh1j+i/kuTepmgSQ XNLGQFzAymn+n1fLNgh0= X-Google-Smtp-Source: AGHT+IF1/vheVTcuheGVrtTM6KH6ZS2IPTooMAcnPogcoQNfL/JE08+57t9/OXv09JX2K7B0vU7WTw== X-Received: by 2002:a17:903:2a8f:b0:21d:dfae:300c with SMTP id d9443c01a7336-22c318a9320mr1903625ad.3.1744740471578; Tue, 15 Apr 2025 11:07:51 -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 d9443c01a7336-22ac7cb52c2sm120168425ad.194.2025.04.15.11.07.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Apr 2025 11:07:51 -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, manivannan.sadhasivam@linaro.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 v3 1/7] Drivers: hv: Introduce hv_hvcall_*() functions for hypercall arguments Date: Tue, 15 Apr 2025 11:07:22 -0700 Message-Id: <20250415180728.1789-2-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250415180728.1789-1-mhklinux@outlook.com> References: <20250415180728.1789-1-mhklinux@outlook.com> Reply-To: mhklinux@outlook.com Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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/tlfs/tlfs Signed-off-by: Michael Kelley Reviewed-by: Nuno Das Neves --- Notes: 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. Changes in v2: * Added comment that hv_hvcall_inout_array() should always be called with 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 ccccb1cbf7df..504c44b1ab9e 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 rep_count, u16 varhead_size, return status; } +/* + * 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 input + * or output indicates to allocate no space for that argument. For input and + * 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 open + * coding the access to the hyperv_pcpu_arg and doing memset() on the input. + * + * 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_hvcall_inout_array(void *input, u32 in_size, u32 in_entry_size, + void *output, u32 out_size, u32 out_entry_size) +{ + u32 in_batch_count = 0, out_batch_count = 0, batch_count; + u32 in_total_size, out_total_size, offset; + u32 batch_space = 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 = batch_space / 2; + else if (in_entry_size) + batch_space = min(HV_HYP_PAGE_SIZE, batch_space - out_size); + else if (out_entry_size) + batch_space = min(HV_HYP_PAGE_SIZE, batch_space - in_size); + + if (in_entry_size) + in_batch_count = (batch_space - in_size) / in_entry_size; + if (out_entry_size) + out_batch_count = (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 = min(in_batch_count, out_batch_count); + else + batch_count = in_batch_count | out_batch_count; + + in_total_size = ALIGN(in_size + (in_entry_size * batch_count), 8); + out_total_size = ALIGN(out_size + (out_entry_size * batch_count), 8); + + space = *this_cpu_ptr(hyperv_pcpu_arg); + if (input) { + *(void **)input = 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 <= HV_HYP_PAGE_SIZE) { + offset = in_total_size; + } else { + offset = HV_HYP_PAGE_SIZE; + /* Need more than 1 page, but only 1 was allocated */ + BUILD_BUG_ON(HV_HVCALL_ARG_PAGES == 1); + } + *(void **)output = space + offset; + } + + return batch_count; +} + +/* Wrappers for some of the simpler cases with only input, or with no arrays */ +#define hv_hvcall_in(input, in_size) \ + hv_hvcall_inout_array(input, in_size, 0, NULL, 0, 0) + +#define hv_hvcall_inout(input, in_size, output, out_size) \ + hv_hvcall_inout_array(input, in_size, 0, output, out_size, 0) + +#define hv_hvcall_in_array(input, in_size, in_entry_size) \ + hv_hvcall_inout_array(input, in_size, in_entry_size, NULL, 0, 0) + +#define hv_hvcall_in_batch_size(in_size, in_entry_size) \ + hv_hvcall_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) { From patchwork Tue Apr 15 18:07:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Kelley X-Patchwork-Id: 14052534 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.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 D3EDC2253BB; Tue, 15 Apr 2025 18:07:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744740476; cv=none; b=YEsrxgxlm/hHQL2m6GtcMVPbFxyNYObBkrWvEcI+go2m3ZGUeMQhryuMMwR8wo6hAJaWCU6isHwiEDyq8I+NdOZDtoKrdATGYGCoWqCr/Fx/6JqTB0WgJAdhraKd6wYPdwFQO2gVg07qX3d4BI7XDJbCrFVd+exgenzCh8sHNHM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744740476; c=relaxed/simple; bh=HqP29UM9WTwkhhOVyDYPq9uHobiLRZYmeg5rOM3U9CU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bk2iEo/RfJFal6/qzye9EWfnEOn/FQeGgUcY9m9Hb5n/Qt/8VYcnDarYNkqhwyDBypgB9ZAjHpUJslpBZKfkfVOOOxN7FoUmgpQIpFhDAKCKj0sJVQywLcZke0e58Li+Fgif3F95kLQI0asglUYc3S82h/AtK2DvpZ6TgFKRpgU= 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=ho1Szp54; arc=none smtp.client-ip=209.85.214.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="ho1Szp54" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2241053582dso81675615ad.1; Tue, 15 Apr 2025 11:07:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744740473; x=1745345273; 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=M3jQ8j3ltfDdE83JponI6X0TRjneHIZzSPt8rmBXSPA=; b=ho1Szp54SiOYKR2paHzh//T2VNuoIX3gDRh0/2CueN3VYeaEvza1S20rupAxeKA0PQ zO/LVPFLcfRA+461FH68XBR7BOltDCKiDxE55tocc3+1GwtBy+vrePpKeudEcQU7V+Pl Dz+DXGkjctDVOkbDBH6hX9G+H8NV+6b+D993U0CQN48Nqvcc8H9Tz0o17STWfZNKO5hg ao0Ole/Q1mZj4Dogj/IZcuVASzlUeilqhiC67ZiUFptFTfS1bM7FIlyyAuK8cYKI/YcP Q1bU4NrSz7oVltn/7Q4oUr5jFj26zxDGdGZO78li69SeweSB08vxx629qWocvGBBhiK0 03KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744740473; x=1745345273; 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=M3jQ8j3ltfDdE83JponI6X0TRjneHIZzSPt8rmBXSPA=; b=Rimnq5hKPkoyw3Gi8Dn6TEnDAs3X7jRMuDWtKRHS/6kSJhAH8bs1KSWq8D0uw29qmU p9474brGS3xHwl2O03X+uIX68IaBBojVGbm79Uz3yHMk69Ec2KVtDShQIg9RoDprqh4C 9/g9i7w1LDOKvnedRLjN7Fbi8EjRHSBM2+vvQN1lhZ6ZPnV0YXNsBRVRPkE8aV8NGbYY 6CdHstHB2HYJ3aKOpwMxFvPi1ka4LP7FjKIMhjpZRkfdyRfEGqbIgzAF96Z9R8dgALHb Cvf8lpM7zlLdyDC8B2xGyUy97kyy16wY1kGqqh/cqGqdQiHpKHQJrxhZCnUy4tdt5QET aQZA== X-Forwarded-Encrypted: i=1; AJvYcCUBXTOgwFwoGzWdvzVuqx/5buqQEmXFGGHeEaQyQa2qGwkpAUyMC8LbZuPog/Z3BRi70X7kOxNk3tUi@vger.kernel.org, AJvYcCWd6VnHFM+k6iP0PnLpBxs8sCy9QgNR+RQcgJH5GSIbbm4NxusAROF0Nw+Xdbvq13b+xJMF6bA0b/KA5AlO@vger.kernel.org, AJvYcCXWiSSiZwSHlt3cVQbEkc1rwPklAQgt6q1ji8HkKJxQ059fbnGU5N/FZU6qTRDl9pw0WBjf4FeNxoAQ@vger.kernel.org, AJvYcCXmI01wuAsG1MsYjh9hPMlvErMm6cW2suRHy/EWmvPI0pvYGXDwV1kkh2AnDX0xmKVKnKjRo60Lg9p1QZS0@vger.kernel.org X-Gm-Message-State: AOJu0YwVOvrAIx1N4tZJq94oUwIQwskCEJFTTQXRzR3L6WU26YtuTuUQ Mz370uLbJF68vDHUy7PC6aNgqvWq5XomhP2Poi+y7PHxmPzu6iVq X-Gm-Gg: ASbGnctQWWAuFc28nsUuFqiYlbipEmselB1spR+IoHFXvePWP9paAMYPvb9d3OJsbOF lHq2J98a/CF0TRe0RJtXIhst/PdT636PG39A+v3xGkkcD6c/p+0F+Z5fgYu0xqI7PuvwusTZ/xa 6SImP7kwPHxHJ1coAppZU/pRvyEvQ3caWXZnxNOusZ5a5FSmhU56ZVIiyA/lU+gz54wj1RyHAlg E8AQ9Sjsq83KBG8peqX1qpe/i8i2mrhhPnqqxJ2sIAN/xLQqQtn8Dy5dn9Q+w2whQ+AQBNpzE+I +DaGln8q1b1LfVNJXE3x+VPzuro22PzahtxwKNFQIfgiFctfsCoGxtETFKJoLfABOsmtOZwV2im AF3TajXVGRyNXk7gY4U4= X-Google-Smtp-Source: AGHT+IEMxysTi3FUHFr3RwKNcy7O705ie5TcwDsgpfUdTDjlk+dAuGCmKwDaRys95Y06UoYi6VC4xg== X-Received: by 2002:a17:902:f710:b0:224:1ef:1e00 with SMTP id d9443c01a7336-22c318d0837mr1956765ad.19.1744740472798; Tue, 15 Apr 2025 11:07:52 -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 d9443c01a7336-22ac7cb52c2sm120168425ad.194.2025.04.15.11.07.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Apr 2025 11:07:52 -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, manivannan.sadhasivam@linaro.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 v3 2/7] x86/hyperv: Use hv_hvcall_*() to set up hypercall arguments -- part 1 Date: Tue, 15 Apr 2025 11:07:23 -0700 Message-Id: <20250415180728.1789-3-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250415180728.1789-1-mhklinux@outlook.com> References: <20250415180728.1789-1-mhklinux@outlook.com> Reply-To: mhklinux@outlook.com Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Michael Kelley Update hypercall call sites to use the new hv_hvcall_*() 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 --- Notes: Changes in v2: * Fixed get_vtl() and hv_vtl_apicid_to_vp_id() to properly treat the input and output arguments as arrays [Nuno Das Neves] * Enhanced __send_ipi_mask_ex() and hv_map_interrupt() to check 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] arch/x86/hyperv/hv_apic.c | 10 ++++------ arch/x86/hyperv/hv_init.c | 6 ++---- arch/x86/hyperv/hv_vtl.c | 9 +++------ arch/x86/hyperv/irqdomain.c | 17 ++++++++++------- 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/arch/x86/hyperv/hv_apic.c b/arch/x86/hyperv/hv_apic.c index 6d91ac5f9836..cd794baaa636 100644 --- a/arch/x86/hyperv/hv_apic.c +++ b/arch/x86/hyperv/hv_apic.c @@ -108,21 +108,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 = 0; + int batch_size, nr_bank = 0; u64 status = HV_STATUS_INVALID_PARAMETER; if (!(ms_hyperv.hints & HV_X64_EX_PROCESSOR_MASKS_RECOMMENDED)) return false; local_irq_save(flags); - ipi_arg = *this_cpu_ptr(hyperv_pcpu_input_arg); - + batch_size = hv_hvcall_in_array(&ipi_arg, sizeof(*ipi_arg), + sizeof(ipi_arg->vp_set.bank_contents[0])); if (unlikely(!ipi_arg)) goto ipi_mask_ex_done; ipi_arg->vector = vector; - ipi_arg->reserved = 0; - ipi_arg->vp_set.valid_bank_mask = 0; /* * Use HV_GENERIC_SET_ALL and avoid converting cpumask to VP_SET @@ -139,7 +137,7 @@ static bool __send_ipi_mask_ex(const struct cpumask *mask, int vector, * represented in VP_SET. Return an error and fall back to * native (architectural) method of sending IPIs. */ - if (nr_bank <= 0) + if (nr_bank <= 0 || nr_bank > batch_size) goto ipi_mask_ex_done; } else { ipi_arg->vp_set.format = HV_GENERIC_SET_ALL; diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index ddeb40930bc8..cc843905c23a 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -400,13 +400,11 @@ static u8 __init get_vtl(void) u64 ret; local_irq_save(flags); - input = *this_cpu_ptr(hyperv_pcpu_input_arg); - output = *this_cpu_ptr(hyperv_pcpu_output_arg); - memset(input, 0, struct_size(input, names, 1)); + hv_hvcall_inout_array(&input, sizeof(*input), sizeof(input->names[0]), + &output, sizeof(*output), sizeof(output->values[0])); input->partition_id = HV_PARTITION_ID_SELF; input->vp_index = HV_VP_INDEX_SELF; - input->input_vtl.as_uint8 = 0; input->names[0] = HV_REGISTER_VSM_VP_STATUS; ret = hv_do_hypercall(control, input, output); diff --git a/arch/x86/hyperv/hv_vtl.c b/arch/x86/hyperv/hv_vtl.c index 13242ed8ff16..ccd9c24722f9 100644 --- a/arch/x86/hyperv/hv_vtl.c +++ b/arch/x86/hyperv/hv_vtl.c @@ -125,8 +125,7 @@ static int hv_vtl_bringup_vcpu(u32 target_vp_index, int cpu, u64 eip_ignored) local_irq_save(irq_flags); - input = *this_cpu_ptr(hyperv_pcpu_input_arg); - memset(input, 0, sizeof(*input)); + hv_hvcall_in(&input, sizeof(*input)); input->partition_id = HV_PARTITION_ID_SELF; input->vp_index = target_vp_index; @@ -216,13 +215,11 @@ static int hv_vtl_apicid_to_vp_id(u32 apic_id) local_irq_save(irq_flags); - input = *this_cpu_ptr(hyperv_pcpu_input_arg); - memset(input, 0, sizeof(*input)); + hv_hvcall_inout_array(&input, sizeof(*input), sizeof(input->apic_ids[0]), + &output, 0, sizeof(*output)); input->partition_id = HV_PARTITION_ID_SELF; input->apic_ids[0] = apic_id; - output = *this_cpu_ptr(hyperv_pcpu_output_arg); - control = HV_HYPERCALL_REP_COMP_1 | HVCALL_GET_VP_ID_FROM_APIC_ID; status = hv_do_hypercall(control, input, output); ret = output[0]; diff --git a/arch/x86/hyperv/irqdomain.c b/arch/x86/hyperv/irqdomain.c index 31f0d29cbc5e..82c4e84541ab 100644 --- a/arch/x86/hyperv/irqdomain.c +++ b/arch/x86/hyperv/irqdomain.c @@ -20,15 +20,15 @@ static int hv_map_interrupt(union hv_device_id device_id, 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; local_irq_save(flags); - input = *this_cpu_ptr(hyperv_pcpu_input_arg); - output = *this_cpu_ptr(hyperv_pcpu_output_arg); + batch_size = hv_hvcall_inout_array(&input, sizeof(*input), + sizeof(input->interrupt_descriptor.target.vp_set.bank_contents[0]), + &output, sizeof(*output), 0); intr_desc = &input->interrupt_descriptor; - memset(input, 0, sizeof(*input)); input->partition_id = hv_current_partition_id; input->device_id = device_id.as_uint64; intr_desc->interrupt_type = HV_X64_INTERRUPT_TYPE_FIXED; @@ -40,7 +40,6 @@ static int hv_map_interrupt(union hv_device_id device_id, bool level, else intr_desc->trigger_mode = HV_INTERRUPT_TRIGGER_MODE_EDGE; - intr_desc->target.vp_set.valid_bank_mask = 0; intr_desc->target.vp_set.format = HV_GENERIC_SET_SPARSE_4K; nr_bank = cpumask_to_vpset(&(intr_desc->target.vp_set), cpumask_of(cpu)); if (nr_bank < 0) { @@ -48,6 +47,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 = HV_DEVICE_INTERRUPT_TARGET_PROCESSOR_SET; /* @@ -77,9 +81,8 @@ static int hv_unmap_interrupt(u64 id, struct hv_interrupt_entry *old_entry) u64 status; local_irq_save(flags); - input = *this_cpu_ptr(hyperv_pcpu_input_arg); - memset(input, 0, sizeof(*input)); + hv_hvcall_in(&input, sizeof(*input)); intr_entry = &input->interrupt_entry; input->partition_id = hv_current_partition_id; input->device_id = id; From patchwork Tue Apr 15 18:07:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Kelley X-Patchwork-Id: 14052535 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 7D1CD225A3C; Tue, 15 Apr 2025 18:07:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744740477; cv=none; b=YAPTJiKIi6o7Fy86GhW4sg3NWpyHlFJl+Mi9SSGt+F5a/q2N+3lvUvz1NR5+JloyXg74JlYrpUfqs8vBpWQZRviRTi7KD4mNs99sKpm3lUpL69vPVTP8I1ne668B05uk0xl+93MTpoeBTtXg3rR9tmtBXLGl/7u9OKpgr0ChWzc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744740477; c=relaxed/simple; bh=27C8tIHjv58CNuFZk1TDQWetCQU5lgdT5avZ8qfxlHo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pps7T08nXyQT7zdwBp8wqNCWIr91a/qtSGieiTfR9QKzRAouNpaAJz7Kkjr1m/T1sReSpTVU5PDoINfnIFZYIInqaIsB8Gcf2ThlxZTUFf+a7+xzIcFk5Q07tbd5R9SGKg8rwMpmPiaewFfYWkMbC0O4Bi6voq1i/nMHHmuyJpQ= 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=Dh2HsTcZ; arc=none smtp.client-ip=209.85.214.172 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="Dh2HsTcZ" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-225477548e1so57802785ad.0; Tue, 15 Apr 2025 11:07:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744740475; x=1745345275; 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=dJwyxq/vZAtGG9biUw9wns3867DjvVOyohb6sLwPjKc=; b=Dh2HsTcZTjmjxD1Y0h8GRQLa8mL8/HoUPGBKk4+5oMW3svoBCFum5I+BEDxw480SsJ Veu9rG38soZw7IumX64b1DtG93y6H4eHWITwt6lLyCwohJ4ukd8akB5wg5mnWlNuQHqL uOq78o9bmgppP+mAtKho2Zt7rXXemGXib8Oj+xDH6sVjHbk8Dh7xV2JgO5iNzpdMEGqQ 3TBXzkHs2k9r/ZOajIIYS0umjxxFJqniVwPsf4qOxuLUniaWYzcddCWVTPtPyRSGG/Ar S4iXcVzW9eYXFxnBO1e+h2zIN0ucJzPxheGvD5AF/xXx2wVzaN1UwXZJMyAraMpqglTl sY/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744740475; x=1745345275; 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=dJwyxq/vZAtGG9biUw9wns3867DjvVOyohb6sLwPjKc=; b=kWg0ITzAvuLkouEMh94luZsP0VF3V2PNZ+iWG0J178EfXWl4ZOP1jIM7maw6WR4fIB 0nYXzvyH9U37o/Wxd/TRSXFsbhjmtHmIS8M9SEQkzA6XJhEBfo3UiCPkPDWFTEOoC98i 1ODH7MhE0vXSqb+vTPKEsJ1mQTfX4dgrCs+dlWV5C5E8aRIBZiEJY7aFzBPUmlZqyqve DJE7OS5Vh7+3V01ZUalG3yrjMo4vp9HnBWml5cELLw8xsBk6UB0NzkbK06tKFhnR08Is oFK8lRuHoWjhOG/76kJNwlJMj9Fn02iCpekUKvBkiKekoQ+4GkFOC9+l5sb+AyUmxcp4 FdeA== X-Forwarded-Encrypted: i=1; AJvYcCUNnkv+uH0OLLBVAvkwdneiAcBK5QMeI4g1DxttBU0x360txBK+Ht3to0efT/bWjzoV2T4BNGsRPKm0@vger.kernel.org, AJvYcCV2Bx2T4JiC5lD7W/mMioqbUgpVP0ScqahkD6qc9nQfkujhhQJN6NCcv5CXUQviZ4jpPs/vVitMxvpr6W2A@vger.kernel.org, AJvYcCWDGMB/MrWre2CEsOhocjVf9LZcfMfApTelKGDZG6o1ZoBTtFKArRyxZXF7Qt6M9z2BAL5rauxRWja1Jt+r@vger.kernel.org, AJvYcCWOwSzD3GqeKZNTEiSu9N4zQeiI2V5WYcXAtKUI5irsYKIjAxxsziBhCcZT0xR9P+aPYiWZXdXsZoHo@vger.kernel.org X-Gm-Message-State: AOJu0YwTHwQn42lW/x5jOx/D1LqdRscpRGXmxEeW71loV0TE2tBz4qT7 ix3KWSEWWKCmo7rtqzmqwJI9Igdd63MWN9SWuQVUJ4n3T8SuC7ie X-Gm-Gg: ASbGncst1BIK6/oAQFFODnhttm5MP7LFKrtSA5mO8TU++zro0aWtlj19ewN3xzfHtCM o29zBlyWGJtcYHxxKvMAMN93bKuthuFkhYs2J5DkCPH/HIGQUv81IgpO0+V6huSLhaCqVudx6Vs epZr5B8YOfX+JWCqDo9cNgBoMignG4wV+r11B9LLpxapk4jNUItOxzk4w+vlVjdZc8hDcFReaUf wzmp+eougWGOkoO6qCn0/sQudbVBciUG0f85XHUqo252yquicPSrpsdfpnEB88UamJvfG8O6WC1 +6aBU80U6y3il8hmPjv9ANw0ujv8+roueUtCQrS4NrEgbfRhg47eFQnc+PqIO7tfPTOkF3F7QRP BUgiZh76lnVMh9hW5bUY= X-Google-Smtp-Source: AGHT+IECvG4G9aa8G/Hhe+MiLgkTyvPU3uYXFSQvxk3QVybJ2VjR5VHrJiiEh794Fnmo1x7RdwU4jA== X-Received: by 2002:a17:903:228e:b0:223:66a1:4503 with SMTP id d9443c01a7336-22c31a6e008mr1477975ad.30.1744740474016; Tue, 15 Apr 2025 11:07:54 -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 d9443c01a7336-22ac7cb52c2sm120168425ad.194.2025.04.15.11.07.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Apr 2025 11:07:53 -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, manivannan.sadhasivam@linaro.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 v3 3/7] x86/hyperv: Use hv_hvcall_*() to set up hypercall arguments -- part 2 Date: Tue, 15 Apr 2025 11:07:24 -0700 Message-Id: <20250415180728.1789-4-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250415180728.1789-1-mhklinux@outlook.com> References: <20250415180728.1789-1-mhklinux@outlook.com> Reply-To: mhklinux@outlook.com Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Michael Kelley Update hypercall call sites to use the new hv_hvcall_*() 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_hvcall_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 --- Notes: 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 77bf05f06b9e..f99b7f4482d3 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -465,30 +465,30 @@ static int hv_mark_gpa_visibility(u16 count, const u64 pfn[], { struct hv_gpa_range_for_visibility *input; u64 hv_status; + int batch_size; unsigned long flags; /* no-op if partition isolation is not enabled */ if (!hv_is_isolation_supported()) return 0; - 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 = hv_hvcall_in_array(&input, sizeof(*input), + sizeof(input->gpa_page_list[0])); + if (unlikely(!input)) { + local_irq_restore(flags); return -EINVAL; } - local_irq_save(flags); - input = *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; } input->partition_id = HV_PARTITION_ID_SELF; input->host_visibility = visibility; - input->reserved0 = 0; - input->reserved1 = 0; memcpy((void *)input->gpa_page_list, pfn, count * sizeof(*pfn)); hv_status = 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..7eaa34ce2f5f 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, local_irq_save(flags); - flush = *this_cpu_ptr(hyperv_pcpu_input_arg); + max_gvas = hv_hvcall_in_array(&flush, sizeof(*flush), sizeof(flush->gva_list[0])); if (unlikely(!flush)) { local_irq_restore(flags); @@ -86,13 +86,10 @@ static void hyperv_flush_tlb_multi(const struct cpumask *cpus, */ flush->address_space = virt_to_phys(info->mm->pgd); flush->address_space &= CR3_ADDR_MASK; - flush->flags = 0; } else { - flush->address_space = 0; flush->flags = HV_FLUSH_ALL_VIRTUAL_ADDRESS_SPACES; } - flush->processor_mask = 0; if (cpumask_equal(cpus, cpu_present_mask)) { flush->flags |= 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 = (PAGE_SIZE - sizeof(*flush)) / sizeof(flush->gva_list[0]); - if (info->end == TLB_FLUSH_ALL) { flush->flags |= HV_FLUSH_NON_GLOBAL_MAPPINGS_ONLY; status = hv_do_hypercall(HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE, @@ -179,7 +174,7 @@ static u64 hyperv_flush_tlb_others_ex(const struct cpumask *cpus, if (!(ms_hyperv.hints & HV_X64_EX_PROCESSOR_MASKS_RECOMMENDED)) return HV_STATUS_INVALID_PARAMETER; - flush = *this_cpu_ptr(hyperv_pcpu_input_arg); + max_gvas = hv_hvcall_in_array(&flush, sizeof(*flush), sizeof(flush->gva_list[0])); if (info->mm) { /* @@ -188,14 +183,10 @@ static u64 hyperv_flush_tlb_others_ex(const struct cpumask *cpus, */ flush->address_space = virt_to_phys(info->mm->pgd); flush->address_space &= CR3_ADDR_MASK; - flush->flags = 0; } else { - flush->address_space = 0; flush->flags = HV_FLUSH_ALL_VIRTUAL_ADDRESS_SPACES; } - flush->hv_vp_set.valid_bank_mask = 0; - flush->hv_vp_set.format = HV_GENERIC_SET_SPARSE_4K; nr_bank = 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 cpumask *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 = - (PAGE_SIZE - sizeof(*flush) - nr_bank * - sizeof(flush->hv_vp_set.bank_contents[0])) / + max_gvas -= (nr_bank * sizeof(flush->hv_vp_set.bank_contents[0])) / sizeof(flush->gva_list[0]); + if (max_gvas <= 0) + return HV_STATUS_INVALID_PARAMETER; if (info->end == TLB_FLUSH_ALL) { flush->flags |= HV_FLUSH_NON_GLOBAL_MAPPINGS_ONLY; diff --git a/arch/x86/hyperv/nested.c b/arch/x86/hyperv/nested.c index 1083dc8646f9..88c39ac8d0aa 100644 --- a/arch/x86/hyperv/nested.c +++ b/arch/x86/hyperv/nested.c @@ -29,15 +29,13 @@ int hyperv_flush_guest_mapping(u64 as) local_irq_save(flags); - flush = *this_cpu_ptr(hyperv_pcpu_input_arg); - + hv_hvcall_in(&flush, sizeof(*flush)); if (unlikely(!flush)) { local_irq_restore(flags); goto fault; } flush->address_space = as; - flush->flags = 0; status = hv_do_hypercall(HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE, flush, NULL); @@ -90,25 +88,23 @@ int hyperv_flush_guest_mapping_range(u64 as, u64 status; unsigned long flags; int ret = -ENOTSUPP; - int gpa_n = 0; + int batch_size, gpa_n = 0; if (!hv_hypercall_pg || !fill_flush_list_func) goto fault; local_irq_save(flags); - flush = *this_cpu_ptr(hyperv_pcpu_input_arg); - + batch_size = hv_hvcall_in_array(&flush, sizeof(*flush), + sizeof(flush->gpa_list[0])); if (unlikely(!flush)) { local_irq_restore(flags); goto fault; } flush->address_space = as; - flush->flags = 0; - gpa_n = 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 abf0bd76e370..5a89120ba1a6 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[]; }; 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; #if defined(CONFIG_X86) From patchwork Tue Apr 15 18:07:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Kelley X-Patchwork-Id: 14052536 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 EC860226CF0; Tue, 15 Apr 2025 18:07:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744740477; cv=none; b=ArPxoOb7hMr76hVGbxEDQ5IY9vOfCQnk4z1vjUJn5m+cu4O5GOPigGLxthrdactR2T6lySv9eDFbHebo8JE233iHDrdYGg3gA+pgbs5AqsyqLZz2qkk0Xq1Z0Nytv2bsJdmqXUU+r70y/pWKiuZVJyFY8hAB5ayCi3qeI9NXMzM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744740477; c=relaxed/simple; bh=PVq45EJryN0baNfrDzWcCyc+ciSw5qcADqeFGudXY5M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WMLSCJHzh/DpnCfPNNGVCDdGqBDueYT5+vMuQ06rYefyk3aQdzbrliOCKryswidyTOkwu4TQjtZ+zmFjQnj1B4CRG+ogfUvyKxzh/EiOzAUhLczRcUme4+/nVEM25XxByOcxpB8/LToAgc7mH0+1Vs5gx4DB7fsirRe81m38RyM= 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=G8NdThnA; arc=none smtp.client-ip=209.85.214.181 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="G8NdThnA" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2295d78b433so62135025ad.2; Tue, 15 Apr 2025 11:07:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744740475; x=1745345275; 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=CuTip/h4L4y1gLplPd0zYkyfMFr9unWCWC/uusRHlzs=; b=G8NdThnAhSD4iN2aMoPHR8LeSgyXHi55QmZrXb1Q/UPz+xFcaRoQIau+B4o0SWH0Qp 7MIB/ooT0tvszMOQpe6Y8jI1znNoUDd9KKSMW3W2VmhojpSATv5o7kdZpOVnXf7HZjP0 UEk+VcoUky/kIRrHd7CBi3m5nA2+FSOHO3cD9PrVcNRgTcfsB8F+mB1g+IvlnjFk8bEA tbHLce56R2gNQCO7qf9qx5hHPjqipcm3P2E/yu6sSRxSy5koFGNEEdKqL+ikFGwvDkl6 bLqCF4m1acb6MV6EzQoY1hv2NuCnuYtiu1Al2zD+TpuzbQCbnUFsI/3/WiBx4Y6wvRH/ c+Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744740475; x=1745345275; 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=CuTip/h4L4y1gLplPd0zYkyfMFr9unWCWC/uusRHlzs=; b=L0Xc7oLJqC1JGEJPHnSFzPHncXTXxLEiuVRwp0jjOMPVfW5/jV5o8rxmCLjW3PkAWO IZ6K59bmZcRENTwn6Fx45AzXDy8icnlB8uxwwnJ2lBmnVatnX1EqMso2prtoHSmaae5u KgJXug7A+RCu+6Or/zDzdAaZ+k0tjHthtNUOd/ZbCVHZgx0hqIloViRLrzc31gHpPmih P5dr+oja+1McAqV2usz+dpYF4U1S7sJ59msCB1Q2W5Ya1Weu0O9rLfBk/F5jNDLGxJTZ hNgOR5luddF29gAa8zGkEs2jOsDlbbp1G41NwP4F+JHCbjBNrX02wKsUn5B+OmOAucae xkWw== X-Forwarded-Encrypted: i=1; AJvYcCU7YQF6SqknttWG51llgZPdO03XXURDrq70oRyb0LqnQWSV74430oDdX5VG5999Bf+htCVkkS2PTBgz@vger.kernel.org, AJvYcCV3HqeJprtNoirbO157n4jk44D6XABPFs8SzLkF79IIi2dzm87+7CbMcvvY5qSHwQiNIFOWb8bcoxdx+uFe@vger.kernel.org, AJvYcCVPVm/UlV5JAskYrM8l38fTUO1KpH/48N7d619VxjxUkuNM4R8EDfs9wV+gi1CIkm+MLdBtB2oF2lnd@vger.kernel.org, AJvYcCXZahV+HjjKS4RMQLb0kiHFkS4qrp4rFcnB8DqHuWYEbLiudALME8vxtmjbNuHJqbzD2yK90+KR54TLuGDT@vger.kernel.org X-Gm-Message-State: AOJu0YyT3U9cKlewvca7O5iV7EJmjWSYvFGY/NbrvPerlPJ9lknu9Xqt idbXZ5PhFYXIabkNNZBboRFhfrsMukjvYVsXUh2wYyflPeCVMpz1T6q1kg== X-Gm-Gg: ASbGncsEUIp3Y8kURMLtyrr/qv6ipF82enRhKxIlUbpI3Mm4cS/pDnpCH5dOWLovJxf FnXt7KeaQnLDQbb/fxmDy+CWY5nxhxR5/IkZg3n9q7ZktNFy3uf5IjAplggVwhAJcEK5G38hMUl ZmsWiNEl9INgpQrzOFL1yztjp3sWQ8CKwZ5E9ksN4r8P3ZRF6nX/TR+ZoYmDsz45XwknBsPMxLg KskfivXl7gy8odAPWxz6+mu+J6ulVDDBu969HP+pKJZb70aBV337tNEWFO/RDx+uhMYSBzTcu63 D2CyhZk5Winwu9nMGwr4FEeeuQvMY0ILQ1oE/b0BToNp6uxlESxWNDR2tWn60dsHqwImJsETaMa 6iccMoUMk2Ri1+6WuTfo= X-Google-Smtp-Source: AGHT+IEvXshEYRrrGB61pmgi3piIsJRkMfRvD+Osw+HeayU3VTDAQLzHVkQYYIYV/TTllO2U6s2ehQ== X-Received: by 2002:a17:903:32d0:b0:215:8809:b3b7 with SMTP id d9443c01a7336-22c318b10d7mr1919555ad.7.1744740475201; Tue, 15 Apr 2025 11:07:55 -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 d9443c01a7336-22ac7cb52c2sm120168425ad.194.2025.04.15.11.07.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Apr 2025 11:07:54 -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, manivannan.sadhasivam@linaro.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 v3 4/7] Drivers: hv: Use hv_hvcall_*() to set up hypercall arguments Date: Tue, 15 Apr 2025 11:07:25 -0700 Message-Id: <20250415180728.1789-5-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250415180728.1789-1-mhklinux@outlook.com> References: <20250415180728.1789-1-mhklinux@outlook.com> Reply-To: mhklinux@outlook.com Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Michael Kelley Update hypercall call sites to use the new hv_hvcall_*() 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 --- Notes: 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 Neves] * 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 | 2 +- drivers/hv/hv_proc.c | 23 ++++++++++------------- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index 308c8f279df8..3e7d681ff2b7 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 = this_cpu_ptr(hv_context.cpu_context)->post_msg_page; else - aligned_msg = *this_cpu_ptr(hyperv_pcpu_input_arg); + hv_hvcall_in_array(&aligned_msg, + offsetof(typeof(*aligned_msg), payload), + sizeof(aligned_msg->payload[0])); aligned_msg->connectionid = connection_id; aligned_msg->reserved = 0; diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c index 2b4080e51f97..801c03fe10f8 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_reporting_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; - 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 = *this_cpu_ptr(hyperv_pcpu_input_arg); + + batch_size = hv_hvcall_in_array(&hint, sizeof(*hint), sizeof(hint->ranges[0])); if (!hint) { local_irq_restore(flags); return -ENOSPC; } + WARN_ON_ONCE(nents > batch_size); hint->heat_type = HV_EXTMEM_HEAT_HINT_COLD_DISCARD; - hint->reserved = 0; for_each_sg(sgl, sg, nents, i) { union hv_gpa_page_range *range; diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c index a7d7494feaca..895448954f37 100644 --- a/drivers/hv/hv_common.c +++ b/drivers/hv/hv_common.c @@ -306,7 +306,7 @@ void __init hv_get_partition_id(void) u64 status, pt_id; local_irq_save(flags); - output = *this_cpu_ptr(hyperv_pcpu_input_arg); + hv_hvcall_inout(NULL, 0, &output, sizeof(*output)); status = hv_do_hypercall(HVCALL_GET_PARTITION_ID, NULL, output); pt_id = output->partition_id; local_irq_restore(flags); diff --git a/drivers/hv/hv_proc.c b/drivers/hv/hv_proc.c index 7d7ecb6f6137..e85d9dd08a9d 100644 --- a/drivers/hv/hv_proc.c +++ b/drivers/hv/hv_proc.c @@ -8,12 +8,6 @@ #include #include -/* - * 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) { @@ -24,11 +18,13 @@ int hv_call_deposit_pages(int node, u64 partition_id, u32 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; - if (num_pages > HV_DEPOSIT_MAX) + batch_size = hv_hvcall_in_batch_size(sizeof(*input_page), + sizeof(input_page->gpa_page_list[0])); + if (num_pages > batch_size) return -E2BIG; if (!num_pages) return 0; @@ -39,7 +35,7 @@ int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages) return -ENOMEM; pages = page_address(page); - counts = kcalloc(HV_DEPOSIT_MAX, sizeof(int), GFP_KERNEL); + counts = kcalloc(batch_size, sizeof(int), GFP_KERNEL); if (!counts) { free_page((unsigned long)pages); return -ENOMEM; @@ -73,7 +69,9 @@ int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages) local_irq_save(flags); - input_page = *this_cpu_ptr(hyperv_pcpu_input_arg); + /* Batch size is checked at the start of function; no need to repeat */ + hv_hvcall_in_array(&input_page, sizeof(*input_page), + sizeof(input_page->gpa_page_list[0])); input_page->partition_id = partition_id; @@ -125,9 +123,8 @@ int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id) do { local_irq_save(flags); - input = *this_cpu_ptr(hyperv_pcpu_input_arg); /* We don't do anything with the output right now */ - output = *this_cpu_ptr(hyperv_pcpu_output_arg); + hv_hvcall_inout(&input, sizeof(*input), &output, sizeof(*output)); input->lp_index = lp_index; input->apic_id = apic_id; @@ -168,7 +165,7 @@ int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags) do { local_irq_save(irq_flags); - input = *this_cpu_ptr(hyperv_pcpu_input_arg); + hv_hvcall_in(&input, sizeof(*input)); input->partition_id = partition_id; input->vp_index = vp_index; From patchwork Tue Apr 15 18:07:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Kelley X-Patchwork-Id: 14052537 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.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 3941222B8D0; Tue, 15 Apr 2025 18:07:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744740478; cv=none; b=p/uVeJbQVWgAuZpD5Fz414bSNMxLbV5MXZ40ivjgZWKRrfDkYka2qE0elEILew78oG/jFeUkJoa0W73wPWhqOZusDc21UK2qM70RthtUQm7F7aPYYD72xqhE/9JzxdDnHyaIKOTgLE7RArDN86MWoTG3mt0ZWNTNB+LOFTFNgn4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744740478; c=relaxed/simple; bh=tHvS4sD7u8RlP/7Sm+j33Q/6kIaZHzfT/DVYlUSooK4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=e/Y8IeZr5vVghmXEUG+qqAQzbQ7xXIpNjkRJNSJYMBQKB/mDtcgVo4y4VQVmHzQDvV+JjoUr+n/66R/16put6ALEYS8zKScIzYRl8jkSYvIn3VA3fgkOB7Y73U6VrCok+RU7z6CDs/HVGBOY95FrOE94B+cV9w50x4/Nunx71w4= 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=Fu/wpZHz; arc=none smtp.client-ip=209.85.214.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="Fu/wpZHz" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2295d78b433so62135195ad.2; Tue, 15 Apr 2025 11:07:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744740476; x=1745345276; 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=4HcM3/w5HL+RHoej1RKlo/mHsgL2Lr/8Mc/iXAK+U3I=; b=Fu/wpZHznhRsSKdPnrKicF+WwrzrX42gre/vxClFLDIFma6EPmfLEqDgQDgJzgDQNv DXqljy8Ru9BvQlJ9SPGZrOjhsBGl2NnH2MFUMqGgwB2WwXFicrncyAKuxoCgmQjNLciw buEMYhqV7+cMTVlqqKGciENseN0AwmT/gPJJGJjmThbgP9I2XKH+hGq+PJQNUt4wOT8M BDyXn7cq6WisUApAz3mJSP+EJEXjHjcCUcuJq6d1W9rlKrYkWqug3iZEHDWJbywT1Ln+ Kg82N/F7iWQr2qeG1mzng0VCAhA28jdkGrEysNeftfFv24jfEPh54+V2dQ9hMeQXBbk6 qOSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744740476; x=1745345276; 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=4HcM3/w5HL+RHoej1RKlo/mHsgL2Lr/8Mc/iXAK+U3I=; b=YqXFNNORUjvvmhRjSnoo6U2QdPe22xXcl0qYQWFvBBlBuZZmL0kkwbSF+glFZ0VGlN y7FeEv3uBPqSF5/zjyRYOI+kwrmjPRvSnwoXiLqhARViop3NPDgU470N0dM0owGVBWp6 AG/5nXI7cONGGewjqssSZWjaaYSZQou7dxRPiHApIo09mMJXx/oWe451u59EByNfuYRI IZAwrh7n0CiYKVTzq+jR+s84SR+5P71c+MbT2FkYfliAohmiOxjqdn0IffTl4YRjVSI4 VlK+/oNJnEvahbAqYrZt+ZggXUTXcqICOyxNcPkLOuRZFrqfUisp/OfWZSm8OQhVKvfq +iOw== X-Forwarded-Encrypted: i=1; AJvYcCU32wGdt8vz1k0noeirZgvyN9tqbAPukb05L7wwDWCX90anufAMw6xtFwvQ/rMRh8FBBo4SweHRKkbo@vger.kernel.org, AJvYcCUO3ZMN9DARULvaaVZ5YoOkASzdLjbBc0Bu3Dg1q361mhtRxB9cM60rahZCv+JK7CGQ7dC04o7Yegse6fY0@vger.kernel.org, AJvYcCUaR2xXoABi0rjZdesvbCulvWpbif7S0XQKHhM8+wdbNVhh+eayAkvZmKOPnuCEoVUdP35lrm5ye/Y4@vger.kernel.org, AJvYcCWTpifQaaQEdqChiwphBCV4m9XaeXHIO7YBEy8Jodj/obZzmc/w/u3H4+YFQlQyWiVDuN6x9v3NArCEHAjH@vger.kernel.org X-Gm-Message-State: AOJu0Yw96PmgIWuw+PbNDgtkH0SUu+CFgeX4GMSaVIj3yUbP47+H+ZPs GPmkdtshP5f4elgswzbi2oCbDdBzWlndM87OkLIEyEDYxR4Si6Uz X-Gm-Gg: ASbGncvQgHylMF38xrlqYTvo2s7tateGaC3eG3o0T+9vMufJGNm+qdUWOaI/cG2c034 b4pke7G8TmGuDR0inw2P4scW+Tu+tHgyabvMohVJcsuDPWQ960PkwXnDDXoQ1rNB+nDXj5G7f6k yAhAYSRDQH9N7NTOCyaJLMthlBeMmFTLwseLiXrkMh3Gj0tfCKfl9CpIJEozXvQflMzXVcgPZUA pMXZei1FfqwKjgu7F7y3kZuSFHzDOp0jaV8hTolVeJX9nz3KmjSFOwPMStipnIK2EWm5+smDTBZ hA+vWyJGQWs1tcjz2VNhddKgAFDYX9M+6XwU8uIRYtPlx7zTn8p4Xe/K8Ek2crIQiVtcujYYjqo cHQEBveIDwBpT1/S0v18= X-Google-Smtp-Source: AGHT+IF7nmoqXsUryR0Xgsda8/UJFBbejHAoiXc5leJyjQhDOw1gsSFxcS69JUGK9LMmq5/eiBrOKQ== X-Received: by 2002:a17:903:1946:b0:224:1221:1ab4 with SMTP id d9443c01a7336-22c319fa063mr1640305ad.22.1744740476399; Tue, 15 Apr 2025 11:07:56 -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 d9443c01a7336-22ac7cb52c2sm120168425ad.194.2025.04.15.11.07.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Apr 2025 11:07:56 -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, manivannan.sadhasivam@linaro.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 v3 5/7] PCI: hv: Use hv_hvcall_*() to set up hypercall arguments Date: Tue, 15 Apr 2025 11:07:26 -0700 Message-Id: <20250415180728.1789-6-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250415180728.1789-1-mhklinux@outlook.com> References: <20250415180728.1789-1-mhklinux@outlook.com> Reply-To: mhklinux@outlook.com Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Michael Kelley Update hypercall call sites to use the new hv_hvcall_*() 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 --- Notes: Changes in v3: * Removed change to definition of struct hv_mmio_write_input so it remains 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] 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/pci-hyperv.c index e1eaa24559a2..32cceceff062 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -622,7 +622,7 @@ static void hv_arch_irq_unmask(struct irq_data *data) struct pci_dev *pdev; unsigned long flags; u32 var_size = 0; - int cpu, nr_bank; + int cpu, nr_bank, batch_size; u64 res; dest = irq_data_get_effective_affinity_mask(data); @@ -638,8 +638,8 @@ static void hv_arch_irq_unmask(struct irq_data *data) local_irq_save(flags); - params = *this_cpu_ptr(hyperv_pcpu_input_arg); - memset(params, 0, sizeof(*params)); + batch_size = hv_hvcall_in_array(¶ms, sizeof(*params), + sizeof(params->int_target.vp_set.bank_contents[0])); params->partition_id = HV_PARTITION_ID_SELF; params->int_entry.source = HV_INTERRUPT_SOURCE_MSI; params->int_entry.msi_entry.address.as_uint32 = int_desc->address & 0xffffffff; @@ -671,7 +671,7 @@ static void hv_arch_irq_unmask(struct irq_data *data) nr_bank = cpumask_to_vpset(¶ms->int_target.vp_set, tmp); free_cpumask_var(tmp); - if (nr_bank <= 0) { + if (nr_bank <= 0 || nr_bank > batch_size) { res = 1; goto out; } @@ -1034,11 +1034,9 @@ static void hv_pci_read_mmio(struct device *dev, phys_addr_t gpa, int size, u32 /* * 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 = *this_cpu_ptr(hyperv_pcpu_input_arg); - out = *this_cpu_ptr(hyperv_pcpu_input_arg) + sizeof(*in); + hv_hvcall_inout(&in, sizeof(*in), &out, sizeof(*out)); in->gpa = gpa; in->size = size; @@ -1067,9 +1065,9 @@ static void hv_pci_write_mmio(struct device *dev, phys_addr_t gpa, int size, u32 /* * 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 = *this_cpu_ptr(hyperv_pcpu_input_arg); + hv_hvcall_in_array(&in, offsetof(typeof(*in), data), sizeof(in->data[0])); in->gpa = gpa; in->size = size; switch (size) { From patchwork Tue Apr 15 18:07:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Kelley X-Patchwork-Id: 14052538 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 716BF221F34; Tue, 15 Apr 2025 18:07:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744740480; cv=none; b=bQGsyr+zcDyXp0IFgr7PGRgOIpV3TWabRyRxhbKdA1v3h8iR9gsL3fC7xQT6Jr3FS+s4p+aj6p6Z3AaoW6pS/Umg+i/4I7sOxq++L/UVGrpPiHD0BS+3Q+4dtTkInkr7Nz0TtaeTv/fKg2xreC4ytVmIESf3wO16h1rqfe4HrSk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744740480; c=relaxed/simple; bh=9FqId/5/ba8YR+p0th4T7tMaodC+zyLP0BvrxVrZaqo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=b48kFBKg6Iwoo1FVQHWp4YuPZ5foVDZgsrpee5SgVqoXPBVhWK3msIKO0+iH0OtkacQovto3B4hTomgJWDzXChPzmNcInIIhbelcfzwOt12/zRxyFlSxsvxChHSYnj2MWbHnJTxCzoNHi3BuUerIMJZXOsvA4IR/ggiMXR684Ck= 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=agbYBgCA; arc=none smtp.client-ip=209.85.214.179 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="agbYBgCA" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-224191d92e4so58035145ad.3; Tue, 15 Apr 2025 11:07:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744740477; x=1745345277; 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=VghwjdcUo8DtpUK2nSJTdR8UnbIpOWOHtRZsZUW425Y=; b=agbYBgCA+4iaIYoP3rfy1iJNTNVbcIQE4xlcREwCuQv2oajfKSJSCMOW4QnBvyruNm wL499AcRFTP8jrgF3lE+/4jN+u+1zkBMcfH2sopmjxUiANl3vBeW+myzSl6U5iS2IOra LU5rgknyTLKCNQwtEBENaOIHXRyXiglTus9cZ3yo5A6FJ7YHMWmE661WC3ecw8DT0VHM QhnbSOTvGsaSpIB5uYbs3gJhdUTvtMd965NA730aNDAa6CDCfPnkaBi2ZfoKN8xVUDzQ CBvObFYvVsxjjDDLGC3kDcK9TsrWO5evSzThLVbhColzbHVjTrwJ6IvAGWVrUJT2aTPL hKyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744740477; x=1745345277; 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=VghwjdcUo8DtpUK2nSJTdR8UnbIpOWOHtRZsZUW425Y=; b=Aojb2dXicS7R/Skza2jw5oh5NPguUwGLQWFCkM45Pwkv4QmrMiROIkt+dGqNrUglEP EWKD09ZWUv6B4UyM8ayXxTt+noxscEeXXRuttyt5Iy2nFtaOrvBbZHNOQmago0XWW8/R I+Q8irBWD88ZFLBLmCt83rUpMK0jOgCotpPKwG2j1Yuzspj4KLt/aPfzvst9sSrjVoQF gZtdb8PXXHlrPYnK3IjgLoW5PJoKfjmx4JO7cTqYZ1G5L1Eayu1aksgw09Yzi63QWP7y oJxzi4xjrz533FIH4U7asgEfDWhQTdbLtX6mtpuhyt80AkiErGYS6RfCkSWfC/g9d8Jv ijUw== X-Forwarded-Encrypted: i=1; AJvYcCU8a5FkhGWNgx3MI5uEAjOvyphN9S216/6rBUgMbXO+V3rJjRgQBb+t/XwI1nX+xIkEsHTeHwhE30y4@vger.kernel.org, AJvYcCVwmxoVFY1q18r8/umLftQqJYkdlWEyAJ+8Ryl3zDiooRyeFyXRuVzPYS7rF/aYX1fUDtg1pYZoXcP/cJfM@vger.kernel.org, AJvYcCX1x+8TyuNaWSl+JRkuaKLX5dgVk1Vno/v1tAD41T/PTbrMnUZy4W4KItpUE9Xu/Qu/Wx06Z9RPw45ZOaOG@vger.kernel.org, AJvYcCXrehmcvPeSZ5H1sWIBWBF5zH/dBrwV0zmEiJ3+oy88OV9t4p8HQb3x3aCy15nccIpnbbv9lLPwNZtn@vger.kernel.org X-Gm-Message-State: AOJu0YzOsr20XSJLerfbLvPutgGY56cI5VA2JZql5GUmveQrOljPWBzV oPXMD3TodfMPwqx5nIZI0DX3VjClhTh1HKKf2LTAWPLVs/ZNZ9or X-Gm-Gg: ASbGnctg7Et1isBQSLUTtzkNWvHkO1C/1mN/02HihnX580dZDz9gpzzRaFvECtFqNKc eiH2jwm436sIH5uDuetbWBAY5mwslXHCBbCzdBsqsVPjAJn9PVAET5IflY6ItU1WbGV6qZ0cHR1 pHwYZEIavk0xAZupbK0M25ley8MTmeCcMnU0HAA73fPjj8u5XHHZwgDbJoWuOgTJgiTeBFgM94L HkIXaCf3J814S9NBB6wL65I0Q+qPDJgyoJkieNcCIlWXAZWloeafIO0rXDtJjyID9ASbryGe+OL uenxOiwqXMr3pJjiEXRGHv9XRs4FcWCTyDL7ke/VB7s9bRDMp9v0RIyMGOWnjDekilUJxJZhxn6 gVxKcbBJFwNthS4trK+thLqVjallJ2Q== X-Google-Smtp-Source: AGHT+IHiB/GQ8z/6fWgkQGagdEJTT0Owmgec+4AiveHrxLyNipS0r0YnRkLF/BvL25ftslAooeiNJA== X-Received: by 2002:a17:902:d4c5:b0:224:10b9:357a with SMTP id d9443c01a7336-22c31a7ef34mr1309685ad.32.1744740477592; Tue, 15 Apr 2025 11:07:57 -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 d9443c01a7336-22ac7cb52c2sm120168425ad.194.2025.04.15.11.07.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Apr 2025 11:07: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, manivannan.sadhasivam@linaro.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 v3 6/7] Drivers: hv: Use hv_hvcall_*() to set up hypercall arguments for mshv code Date: Tue, 15 Apr 2025 11:07:27 -0700 Message-Id: <20250415180728.1789-7-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250415180728.1789-1-mhklinux@outlook.com> References: <20250415180728.1789-1-mhklinux@outlook.com> Reply-To: mhklinux@outlook.com Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Michael Kelley Update hypercall call sites to use the new hv_hvcall_*() 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_hvcall_inout_array() instead of separate #define value. Signed-off-by: Michael Kelley --- Notes: 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 2575e6d7a71f..2ad36cc7a329 100644 --- a/drivers/hv/mshv_common.c +++ b/drivers/hv/mshv_common.c @@ -16,12 +16,6 @@ #include "mshv.h" -#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) @@ -29,24 +23,23 @@ int hv_call_get_vp_registers(u32 vp_index, u64 partition_id, u16 count, struct hv_input_get_vp_registers *input_page; union hv_register_value *output_page; u16 completed = 0; - unsigned long remaining = count; + unsigned long batch_size, remaining = count; int rep_count, i; u64 status = HV_STATUS_SUCCESS; unsigned long flags; local_irq_save(flags); - input_page = *this_cpu_ptr(hyperv_pcpu_input_arg); - output_page = *this_cpu_ptr(hyperv_pcpu_output_arg); + batch_size = hv_hvcall_inout_array(&input_page, sizeof(*input_page), + sizeof(input_page->names[0]), + &output_page, 0, sizeof(*output_page)); input_page->partition_id = partition_id; input_page->vp_index = vp_index; input_page->input_vtl.as_uint8 = input_vtl.as_uint8; - input_page->rsvd_z8 = 0; - input_page->rsvd_z16 = 0; while (remaining) { - rep_count = min(remaining, HV_GET_REGISTER_BATCH_SIZE); + rep_count = min(remaining, batch_size); for (i = 0; i < rep_count; ++i) input_page->names[i] = registers[i].name; @@ -75,21 +68,19 @@ int hv_call_set_vp_registers(u32 vp_index, u64 partition_id, u16 count, struct hv_input_set_vp_registers *input_page; u16 completed = 0; unsigned long remaining = count; - int rep_count; + unsigned long rep_count, batch_size; u64 status = HV_STATUS_SUCCESS; unsigned long flags; local_irq_save(flags); - input_page = *this_cpu_ptr(hyperv_pcpu_input_arg); - + batch_size = hv_hvcall_in_array(&input_page, sizeof(*input_page), + sizeof(input_page->elements[0])); input_page->partition_id = partition_id; input_page->vp_index = vp_index; input_page->input_vtl.as_uint8 = input_vtl.as_uint8; - input_page->rsvd_z8 = 0; - input_page->rsvd_z16 = 0; while (remaining) { - rep_count = min(remaining, HV_SET_REGISTER_BATCH_SIZE); + rep_count = min(remaining, batch_size); memcpy(input_page->elements, registers, sizeof(struct hv_register_assoc) * rep_count); @@ -119,9 +110,7 @@ int hv_call_get_partition_property(u64 partition_id, struct hv_output_get_partition_property *output; local_irq_save(flags); - input = *this_cpu_ptr(hyperv_pcpu_input_arg); - output = *this_cpu_ptr(hyperv_pcpu_output_arg); - memset(input, 0, sizeof(*input)); + hv_hvcall_inout(&input, sizeof(*input), &output, sizeof(*output)); input->partition_id = partition_id; input->property_code = property_code; status = 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 a222a16107f6..f14720de3248 100644 --- a/drivers/hv/mshv_root_hv_call.c +++ b/drivers/hv/mshv_root_hv_call.c @@ -21,22 +21,6 @@ #define HV_PAGE_COUNT_2M_ALIGNED(pg_count) (!((pg_count) & (0x200 - 1))) #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)) int hv_call_withdraw_memory(u64 count, int node, u64 partition_id) { @@ -57,9 +41,7 @@ int hv_call_withdraw_memory(u64 count, int node, u64 partition_id) while (remaining) { local_irq_save(flags); - input_page = *this_cpu_ptr(hyperv_pcpu_input_arg); - - memset(input_page, 0, sizeof(*input_page)); + hv_hvcall_in(&input_page, sizeof(*input_page)); input_page->partition_id = partition_id; status = hv_do_rep_hypercall(HVCALL_WITHDRAW_MEMORY, min(remaining, HV_WITHDRAW_BATCH_SIZE), @@ -98,10 +80,7 @@ int hv_call_create_partition(u64 flags, do { local_irq_save(irq_flags); - input = *this_cpu_ptr(hyperv_pcpu_input_arg); - output = *this_cpu_ptr(hyperv_pcpu_output_arg); - - memset(input, 0, sizeof(*input)); + hv_hvcall_inout(&input, sizeof(*input), &output, sizeof(*output)); input->flags = flags; input->compatibility_version = HV_COMPATIBILITY_21_H2; @@ -205,11 +184,12 @@ static int hv_do_map_gpa_hcall(u64 partition_id, u64 gfn, u64 page_struct_count, while (done < page_count) { ulong i, completed, remain = page_count - done; - int rep_count = min(remain, HV_MAP_GPA_BATCH_SIZE); + ulong rep_count, batch_size; local_irq_save(irq_flags); - input_page = *this_cpu_ptr(hyperv_pcpu_input_arg); - + batch_size = hv_hvcall_in_array(&input_page, sizeof(*input_page), + sizeof(input_page->source_gpa_page_list[0])); + rep_count = min(remain, batch_size); input_page->target_partition_id = partition_id; input_page->target_gpa_base = gfn + (done << large_shift); input_page->map_flags = flags; @@ -310,7 +290,7 @@ int hv_call_unmap_gpa_pages(u64 partition_id, u64 gfn, u64 page_count_4k, int rep_count = min(remain, HV_UMAP_GPA_PAGES); local_irq_save(irq_flags); - input_page = *this_cpu_ptr(hyperv_pcpu_input_arg); + hv_hvcall_in(&input_page, sizeof(*input_page)); input_page->target_partition_id = partition_id; input_page->target_gpa_base = gfn + (done << large_shift); @@ -339,7 +319,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 = 0; - unsigned long remaining = count; + unsigned long batch_size, remaining = count; int rep_count, i; u64 status = 0; unsigned long flags; @@ -347,13 +327,13 @@ int hv_call_get_gpa_access_states(u64 partition_id, u32 count, u64 gpa_base_pfn, *written_total = 0; while (remaining) { local_irq_save(flags); - input_page = *this_cpu_ptr(hyperv_pcpu_input_arg); - output_page = *this_cpu_ptr(hyperv_pcpu_output_arg); + batch_size = hv_hvcall_inout_array(&input_page, sizeof(*input_page), + 0, &output_page, 0, sizeof(*output_page)); input_page->partition_id = partition_id; input_page->hv_gpa_page_number = gpa_base_pfn + *written_total; input_page->flags = state_flags; - rep_count = min(remaining, HV_GET_GPA_ACCESS_STATES_BATCH_SIZE); + rep_count = min(remaining, batch_size); status = hv_do_rep_hypercall(HVCALL_GET_GPA_PAGES_ACCESS_STATES, rep_count, 0, input_page, output_page); @@ -383,8 +363,7 @@ int hv_call_assert_virtual_interrupt(u64 partition_id, u32 vector, u64 status; local_irq_save(flags); - input = *this_cpu_ptr(hyperv_pcpu_input_arg); - memset(input, 0, sizeof(*input)); + hv_hvcall_in(&input, sizeof(*input)); input->partition_id = partition_id; input->vector = vector; input->dest_addr = dest_addr; @@ -421,21 +400,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 = 0; - if (page_count > HV_GET_VP_STATE_BATCH_SIZE) - return -EINVAL; - if (!page_count && !ret_output) return -EINVAL; do { local_irq_save(flags); - input = *this_cpu_ptr(hyperv_pcpu_input_arg); - output = *this_cpu_ptr(hyperv_pcpu_output_arg); - memset(input, 0, sizeof(*input)); - memset(output, 0, sizeof(*output)); + batch_size = hv_hvcall_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; + } input->partition_id = partition_id; input->vp_index = vp_index; @@ -477,11 +456,7 @@ int hv_call_set_vp_state(u32 vp_index, u64 partition_id, unsigned long flags; int ret = 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; if (num_bytes) /* round up to 8 and divide by 8 */ @@ -493,18 +468,26 @@ int hv_call_set_vp_state(u32 vp_index, u64 partition_id, do { local_irq_save(flags); - input = *this_cpu_ptr(hyperv_pcpu_input_arg); - memset(input, 0, sizeof(*input)); - input->partition_id = partition_id; - input->vp_index = vp_index; - input->state_data = state_data; if (num_bytes) { + batch_size = hv_hvcall_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 = hv_hvcall_in_array(&input, sizeof(*input), + sizeof(input->data[0].pfns)); + if (page_count > batch_size) + goto size_error; + for (i = 0; i < page_count; i++) input->data[i].pfns = page_to_pfn(pages[i]); } + input->partition_id = partition_id; + input->vp_index = vp_index; + input->state_data = state_data; control = (HVCALL_SET_VP_STATE) | (varhead_sz << HV_HYPERCALL_VARHEAD_OFFSET); @@ -523,6 +506,10 @@ int hv_call_set_vp_state(u32 vp_index, u64 partition_id, } while (!ret); return ret; + +size_error: + local_irq_restore(flags); + return -EINVAL; } int hv_call_map_vp_state_page(u64 partition_id, u32 vp_index, u32 type, @@ -538,8 +525,7 @@ int hv_call_map_vp_state_page(u64 partition_id, u32 vp_index, u32 type, do { local_irq_save(flags); - input = *this_cpu_ptr(hyperv_pcpu_input_arg); - output = *this_cpu_ptr(hyperv_pcpu_output_arg); + hv_hvcall_inout(&input, sizeof(*input), &output, sizeof(*output)); input->partition_id = partition_id; input->vp_index = vp_index; @@ -573,9 +559,7 @@ int hv_call_unmap_vp_state_page(u64 partition_id, u32 vp_index, u32 type, local_irq_save(flags); - input = *this_cpu_ptr(hyperv_pcpu_input_arg); - - memset(input, 0, sizeof(*input)); + hv_hvcall_in(&input, sizeof(*input)); input->partition_id = partition_id; input->vp_index = vp_index; @@ -613,8 +597,7 @@ hv_call_create_port(u64 port_partition_id, union hv_port_id port_id, do { local_irq_save(flags); - input = *this_cpu_ptr(hyperv_pcpu_input_arg); - memset(input, 0, sizeof(*input)); + hv_hvcall_in(&input, sizeof(*input)); input->port_partition_id = port_partition_id; input->port_id = port_id; @@ -667,8 +650,7 @@ hv_call_connect_port(u64 port_partition_id, union hv_port_id port_id, do { local_irq_save(flags); - input = *this_cpu_ptr(hyperv_pcpu_input_arg); - memset(input, 0, sizeof(*input)); + hv_hvcall_in(&input, sizeof(*input)); input->port_partition_id = port_partition_id; input->port_id = port_id; input->connection_partition_id = connection_partition_id; @@ -735,10 +717,7 @@ int hv_call_map_stat_page(enum hv_stats_object_type type, do { local_irq_save(flags); - input = *this_cpu_ptr(hyperv_pcpu_input_arg); - output = *this_cpu_ptr(hyperv_pcpu_output_arg); - - memset(input, 0, sizeof(*input)); + hv_hvcall_inout(&input, sizeof(*input), &output, sizeof(*output)); input->type = type; input->identity = *identity; @@ -772,9 +751,7 @@ int hv_call_unmap_stat_page(enum hv_stats_object_type type, u64 status; local_irq_save(flags); - input = *this_cpu_ptr(hyperv_pcpu_input_arg); - - memset(input, 0, sizeof(*input)); + hv_hvcall_in(&input, sizeof(*input)); input->type = type; input->identity = *identity; @@ -807,14 +784,14 @@ int hv_call_modify_spa_host_access(u64 partition_id, struct page **pages, } while (done < page_count) { - ulong i, completed, remain = page_count - done; - int rep_count = min(remain, - HV_MODIFY_SPARSE_SPA_PAGE_HOST_ACCESS_MAX_PAGE_COUNT); + ulong i, batch_size, completed, remain = page_count - done; + ulong rep_count; local_irq_save(irq_flags); - input_page = *this_cpu_ptr(hyperv_pcpu_input_arg); + batch_size = hv_hvcall_in_array(&input_page, sizeof(*input_page), + sizeof(input_page->spa_page_list[0])); + rep_count = min(remain, batch_size); - 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..df6b0da4a9a8 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; local_irq_save(flags); - input = *this_cpu_ptr(hyperv_pcpu_input_arg); - output = *this_cpu_ptr(hyperv_pcpu_output_arg); - memset(input, 0, sizeof(*input)); - memset(output, 0, sizeof(*output)); + hv_hvcall_inout(&input, sizeof(*input), &output, sizeof(*output)); input->property_id = HV_SYSTEM_PROPERTY_SCHEDULER_TYPE; status = hv_do_hypercall(HVCALL_GET_SYSTEM_PROPERTY, input, output); From patchwork Tue Apr 15 18:07:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Kelley X-Patchwork-Id: 14052539 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 AB39C231A2D; Tue, 15 Apr 2025 18:07:59 +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=1744740481; cv=none; b=IqjSXntbpe+L2dO1CsBsHiQKebZAypvvPuZbWgESOTfWY/qIOij/5YVprrGJbqKeqd2mLvObxmu4aafL6M6lheOqXOgpOGuc28Dh9vaim7+6TtXbV6mzLrwYiWTeltMdeq7itY6NB9he4wW5yP/ZvGbda9e8MJ2Bvzhlj5vviv4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744740481; c=relaxed/simple; bh=UTsKyS2PlZZKA2o+79sqVDK3wxEkcbrub9V0HEY/95Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YMp+zlwOmx+RvM2EuMdWgueD4CpZ3JkWeg7NYNhfq2LOeTneSu93Tz1M0U4OV/ttcKhR9h+S5lxG2TJJ8VJZEdrPBEsTX9NCzDhuI/WQ0ZSyQGb7BZ0a0rHVUlXCGxX36F7/YtUNwc7Sw1hcvG9ALJSxiMPd3Ybb4Gln/TgSGWM= 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=Qs2yULY4; 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="Qs2yULY4" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-224100e9a5cso67669075ad.2; Tue, 15 Apr 2025 11:07:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744740479; x=1745345279; 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=3+u66A1OTRBxF+yfRSOAIfy+XQ205gLrpOaXRpAT3KM=; b=Qs2yULY4pHijn9aNDQVqtsYrj3dO0wg3qnagnPvO8wsL9rDiSiOFZDdGzij6Tf+G20 6vPVoMBki5en5fu9qP254qkwiIBXekedtZb762fDZeAskw35lEgyOU7nhMd6kU05NOi9 LH41DHVmsqs3GlpuseOYAWrGH4V95xpXlOEkCHTFxMLW1AT8cGwRRH1Dlu1qMpnd21Sf 27ZozTuukmr0By2O6+Viu87CzwDSzk+a+++7XC92gpJ9RLFkbXREn1Aq+zWIJmyY41Z6 IuVYzHv7wBAlK2Z4N51fzEWV0MF2JgUd/R/x2ymNypfC6dHeFmNMPYlEsbgXs5DbXP4J YY7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744740479; x=1745345279; 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=3+u66A1OTRBxF+yfRSOAIfy+XQ205gLrpOaXRpAT3KM=; b=tUFGc1Zj+4b38zWUwHW/JoM7Y6mRjt/4Dd0gHOqfvC772QboiA1/sSm4Ih8MyiQRkN kcT7nb/eQDagfN3Q8+hikg1YpmttPOkS1nu8ahCZrGzVrxPhENpgunBO27FC6894U02p 5cc3f1/YHBV1d5AjiRxocpmQV3xP9ZWYZ7yNEvM4Zt3faa7K0AZpCZwpl1mc6XxDSuhE +XCZvKIBVLDvv5k2jHwYGjnhemDmuQhGx4l+dbHwLC6Twm7tPkhXZfcbCNz+VgKsJUNR Fp3+ZyJA/lHrHAs7+i2Wx2BHY85NAHWZiUW2wG09lB9QopHvZRxY0VLY9ojZP57Bpfo8 E/2Q== X-Forwarded-Encrypted: i=1; AJvYcCUeXsiGKYz0TmDFi9WFvYKEeygqlp/rIRuA4gf2vCyqPZVHQgDf77sbd3AlIf/29xmJTHHnkDeYzIfP@vger.kernel.org, AJvYcCV3KxEa7VBXI7AVQtgumfFFwO8eCYVrScJ6JQSAjryCvDbNDxNdGp05w86S+LktFU+hBGGphaR1E4tUYyWh@vger.kernel.org, AJvYcCVQy19UtAekY9mOOcrmUf7VXBTcVWF4vsEADQTi8wXHCaTjBlKltYtuvB6i/dpkAH5CgGAWwFUF4DkB@vger.kernel.org, AJvYcCXMr91GpOlV+wuIie9lC5CcR3uNj1j/4/kEQq6X3ClpPeNiZ3L4FGgznhZgIYmenMw8BQJhitVGcj0IJFjZ@vger.kernel.org X-Gm-Message-State: AOJu0YzlCoriAtDcShbAshyLe5mGdDBQaqoMbcBrSzq/WRvKgI7CJavp YKvCPjpoQkXBIp5BwjzAR0INul94Oua7GtQ4X+NKigSKCftIVJ0X X-Gm-Gg: ASbGncuEqa/uiD9OFLiLkbxC+LqOrxfIQticePXfzrKO7KG85jd30DXMPfNB+yCE3qs RGtWmj0Q+X7+a732NGfIhVi5ZdPlwCXqnf2pRA0S7fhj0FItXmbQh+q/Jt4pqBCA/5+clSBrgdL MWC+wIYOts59FEVoT0+vPZOs288wUBxYVl7N1QaIaNnLyLEkEwXN1wpto1TOq3TImIQfuBBroTN ZS3tG7zUC3MehB19N9ZJLry9ynaSHi0AWX4uV7YcWHGe2UbTtD0rINSeG0C21Sv3pmJP+Hp3auX pAaIV0eiUo581xnW1SvRO9P0/C6ypIiHjaafEuveOEjwe52/Pdq6Bz4noiihJD9If0dIYYedi5p UePXKdHSZCw3fotncb4c= X-Google-Smtp-Source: AGHT+IE3KI5J87t62+O99Qs623myYy7MgdASGlwz3y7O+BXjNcAU9vBWFszNqHBSN6TQhEiF2gQpdQ== X-Received: by 2002:a17:902:c407:b0:223:4816:3e9e with SMTP id d9443c01a7336-22c31a37a1amr944205ad.13.1744740478893; Tue, 15 Apr 2025 11:07: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 d9443c01a7336-22ac7cb52c2sm120168425ad.194.2025.04.15.11.07.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Apr 2025 11:07:58 -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, manivannan.sadhasivam@linaro.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 v3 7/7] Drivers: hv: Replace hyperv_pcpu_input/output_arg with hyperv_pcpu_arg Date: Tue, 15 Apr 2025 11:07:28 -0700 Message-Id: <20250415180728.1789-8-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250415180728.1789-1-mhklinux@outlook.com> References: <20250415180728.1789-1-mhklinux@outlook.com> Reply-To: mhklinux@outlook.com Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Michael Kelley All open coded uses of hyperv_pcpu_input_arg and hyperv_pcpu_ouput_arg have been replaced by hv_hvcall_*() 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 --- arch/x86/hyperv/hv_init.c | 6 ++-- drivers/hv/hv.c | 2 +- drivers/hv/hv_common.c | 55 ++++++++++------------------------ include/asm-generic/mshyperv.h | 6 +--- 4 files changed, 21 insertions(+), 48 deletions(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index cc843905c23a..e930fe75f2ca 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -483,16 +483,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_hypercall8(). * 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_input_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 3e7d681ff2b7..c8bd40b797ba 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 895448954f37..712937c97fee 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); -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); static void hv_kmsg_dump_unregister(void); @@ -95,11 +92,8 @@ void __init hv_common_free(void) kfree(hv_vp_index); hv_vp_index = NULL; - free_percpu(hyperv_pcpu_output_arg); - hyperv_pcpu_output_arg = NULL; - - free_percpu(hyperv_pcpu_input_arg); - hyperv_pcpu_input_arg = NULL; + free_percpu(hyperv_pcpu_arg); + hyperv_pcpu_arg = NULL; free_percpu(hv_synic_eventring_tail); hv_synic_eventring_tail = NULL; @@ -294,11 +288,6 @@ static void hv_kmsg_dump_register(void) } } -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; @@ -376,14 +365,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 = 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 = alloc_percpu(void *); - BUG_ON(!hyperv_pcpu_output_arg); - } + hyperv_pcpu_arg = alloc_percpu(void *); + BUG_ON(!hyperv_pcpu_arg); if (hv_root_partition()) { hv_synic_eventring_tail = alloc_percpu(u8 *); @@ -477,33 +460,28 @@ void __init ms_hyperv_late_init(void) 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 = hv_output_page_exists() ? 2 : 1; + const int pgcount = HV_HVCALL_ARG_PAGES; void *mem; int ret = 0; /* hv_cpu_init() can be called with IRQs disabled from hv_resume() */ flags = irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL; - inputarg = (void **)this_cpu_ptr(hyperv_pcpu_input_arg); + inputarg = (void **)this_cpu_ptr(hyperv_pcpu_arg); /* - * 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 = kmalloc(pgcount * HV_HYP_PAGE_SIZE, flags); if (!mem) return -ENOMEM; - if (hv_output_page_exists()) { - outputarg = (void **)this_cpu_ptr(hyperv_pcpu_output_arg); - *outputarg = (char *)mem + HV_HYP_PAGE_SIZE; - } - if (!ms_hyperv.paravisor_present && (hv_isolation_type_snp() || hv_isolation_type_tdx())) { ret = set_memory_decrypted((unsigned long)mem, pgcount); @@ -517,13 +495,13 @@ int hv_common_cpu_init(unsigned int cpu) /* * 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 @@ -555,9 +533,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/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h index 504c44b1ab9e..a73ddee6d322 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; -extern void * __percpu *hyperv_pcpu_input_arg; -extern void * __percpu *hyperv_pcpu_output_arg; +extern void * __percpu *hyperv_pcpu_arg; 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 */ -/* 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