From patchwork Thu Mar 13 06:19:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Kelley X-Patchwork-Id: 14014380 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8AAE1581E0; Thu, 13 Mar 2025 06:19:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741846769; cv=none; b=OuphhdmdaFoMKO0q1z777yOmcMe6rYF0NVNGaFZEzEuNuIpD45/k6Z/YQUIO4moodyGtB0VVN57arbyxm1k9VJ2I/q8AwfQp9fKLFUSKwka32bku7eZqn3kBpXbGBf4c8lB019IHyWUbmbBWwguFleRFJPi+Nx3htTNwVefNpL8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741846769; c=relaxed/simple; bh=XSyAkO4twTo9IZqS1Bu+JLzxWClBEdmJveCI8GP9Ux4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EoqotXse4wJ5EEl8FiYk3liokKZ6tbMVmjb3qoJ/e41/zjp4MQ9fpYkbeoLbgiMbMr4lRO2egtzKP6hn/9Ml/EvXuzeo5TFWX2oNhQrPhtyVwYhF37b5Isz2MKSnPvdRyP9wuNJtbpN8DjDY/guM+oY+kfx7T+nvOkT3ytRVgsA= 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=m/orWJA8; arc=none smtp.client-ip=209.85.216.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="m/orWJA8" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-2fe9759e5c1so1117216a91.0; Wed, 12 Mar 2025 23:19:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741846767; x=1742451567; 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=1Byx2CnzFrqBVJ2qAPjeuNBafe/kCjDnEFkW40jwLzk=; b=m/orWJA8skJlsXR2xoyw9GzCDIOLWWlpuHtgf4OhD+x4eKBJY8XV4hbjgCw8cRhb3W /47nkuXfKkxhedCynso/cbAjeStePBLBOPXf+g1PzvT6rd9kIpX0B6YXgvjjGnTF9Oan P+NLnwGxYooaZIdWqhog3U3W5XUDq8l1ZZJ1stcCB4tXF2rY6p/M7LxsYWDD+BdUqmAw AVem/9hCj4giDNkfPVM7J1TXDP2YyTAefEQiLuQGbiY5bqVOkGOtx3uYaLZ1HZVQ9Dqn CXmtVy78QawgNsFS2c4F2gVwtayOChPockXcwd+jZcJPzVSVrxZpV244xIxgm0mREbET Yodw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741846767; x=1742451567; 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=1Byx2CnzFrqBVJ2qAPjeuNBafe/kCjDnEFkW40jwLzk=; b=WHqYJRCGpWIaT+sYCeyFEaOvnHjfeJZdXdukEAy3RCyZ7UGwPrSIgougapBP6MfqL9 nqY++g9PmhsD60Z7+M8BvEE8TPoVbTleH7p6NIZDETgft12oNdcIQ9aHbctvzG4gPAr5 cPWoneHNah4cHfEG4Jd3i+Q0DT+d4Yv1kbXzOdiPlaf859/wcrXW+4KNFboPzjLSt9Rs qrpS1102qTVrGtSPDE3BpAI6PCayCt/Qk+FL+nbPt5XunHIF+nW/L3Y8YKySaITqqf57 pcpctJzF8U3t7nWWKvkMCLIAFJZzJyAVbo5PIUsVRC6CXI2k3aiWcyfxlMfS2cG2VV3C HsnA== X-Forwarded-Encrypted: i=1; AJvYcCVHylqTLtdUXwnU2I3Tfl+4H76WI1Csr757JuIhn0+voybRHWimRyhuP2gmScm3gzZ2jOSU/6m/gIKL@vger.kernel.org, AJvYcCVkcgwJVRXi3qJ7ANCXvpHJ2TTSDQfpwzWaXVzUCjzYbRYwoaNnA8Ka9fHzW7pgoQhwMp/6l9Yu1mFV@vger.kernel.org, AJvYcCVt7sLBni44ZNDBRDbzmBD5FtYwRJHNqnR3gpgFCbBNzPwlvQZEC/JfpjAlwgAImB//Zor69EliADMllS4L@vger.kernel.org, AJvYcCX5laVOr+Ul8T9oXxnNRMh18kHMlpy+Iy1jzmeEWZF7m+kB2RerfpZGBka+c8Vp03uvDKIvRVZmlw4jqtH6@vger.kernel.org X-Gm-Message-State: AOJu0YytoIKBXr5ZVUpf4gehcWJUYkG0Kgp0x9OGaM9YXoZYhbPKHNr6 nJK6NMs9tsMudrmzfKQZmvoZvvkmExe2R6UjkZJK9wKjW144GWm3 X-Gm-Gg: ASbGnctZQSvHYfTMBQRhT9sYUTDfAyW+FF3kVbeyX2RZxx23B00gCshyt52G37E4QYT 8UnKZ2acljhe90DGK/eSdy8gqBuUZMTq+UI9R1pLUc8OQfuUgthE0BcGSaIG25/X8F3RpzOEvtK NS1/eUjLKUIrA1dKRqBMfW0KRXpmjxDDQ3XJDq5oZqPY0zNdlEl4F79o/SRgRFMdHO7cMBqFLjK Xuxt1QP3OB4kBdU94dvYNi/baJ7+EoNFPTGcKwgfyexpK46XYKwc6EEeMjTKXkxzlN2PcFH7ifA +hwcrTgQyHHnPjraviAxbWqhKHqEnDIqAV/osTrkG8SLnKLWPKrfMV9MDrzNLNS4guJxOm025dA UqM4QilEl8u0j1kAYM5mzwX7y/WE9Fiq65A== X-Google-Smtp-Source: AGHT+IF/3JN2QdSkwNktsQBwiziRRmD9A0XgfQDo9Z9D84tlJ9BsGNr95AcTum+g7gcQX99Ng7ysbw== X-Received: by 2002:a17:90b:2f46:b0:2fa:157e:c790 with SMTP id 98e67ed59e1d1-300ff0aa1cdmr12880995a91.5.1741846766937; Wed, 12 Mar 2025 23:19:26 -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-225c68880dfsm5856985ad.38.2025.03.12.23.19.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Mar 2025 23:19:26 -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 v2 1/6] Drivers: hv: Introduce hv_hvcall_*() functions for hypercall arguments Date: Wed, 12 Mar 2025 23:19:06 -0700 Message-Id: <20250313061911.2491-2-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250313061911.2491-1-mhklinux@outlook.com> References: <20250313061911.2491-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-cpu 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 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 | 103 +++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h index b13b0cda4ac8..01e8763edc2c 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -135,6 +135,109 @@ 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) + /* Generate the guest OS identifier as described in the Hyper-V TLFS */ static inline u64 hv_generate_guest_id(u64 kernel_version) { From patchwork Thu Mar 13 06:19:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Kelley X-Patchwork-Id: 14014381 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 1290A1FBC93; Thu, 13 Mar 2025 06:19:28 +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=1741846770; cv=none; b=W+5Z1ZStVEP7uNYIUlgLKvXPC+lssuIE9ybueKB7vhS3Nj/qWrKA6bmv61y/t7619dvmrFBDWHe+mD4lrpclV4Rh/BnnIYEy4QRyPfxiGrJIE1LHR0reCitA2CRoVmxvaIvvsM/bqoxxdcT+0Bd4y8jUN2wjnZDZDcGBQKv3b4U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741846770; c=relaxed/simple; bh=sNeLHLvS125UjEyglhRWjiSngcYQFEuWWCeGSQELdfE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=b9A+GCx3rzsUA3LlpgBUTQfoE6mgaKbqjABLQQhpivjVMyKiTgTWzTCk4elQLxFmvLgA2jyAZwSUtpgNt3B5sR4e8UP/YTCaqN2Y/nKvgAvb8cIO8I27TR9TFF1878BlECiv4fhGW5c5O+XlUKnoCcDdiLxVhnKz1bkRE2RYUek= 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=Y1DDhJHD; 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="Y1DDhJHD" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-223a7065ff8so15982775ad.0; Wed, 12 Mar 2025 23:19:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741846768; x=1742451568; 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=lVILxdziP1NvabNMhmzXbXNckUkSyJVqto36jQ3zFgM=; b=Y1DDhJHD+4AwNBNT9xAvVoyOi1L+LoTJwQQXQiz9BkHqOGStWNACpAV36LY7vEvbL8 PyGROfsnN3+DIBt2tNarTgHa1xlEcKuW1BQNfq/NUdK6ZREwBE4Yu4Z0Zh2pp1gcdSXx SXcd63CZHbRiI7tceNc1I5z3rYyUYPCxGJHbq3zrisJ30AGqfEKYvJKqmgmXr8cjk4Lh 9K+osoUEcqEp9WgmEUDTa5twDTHOdFVIKGoArM6pl3DWD/k1WSyLAI+mPyNmG6Oh6B21 eOdEQmXHfJ4dvONbMT4cEQw9V/GaHmy673vUeheu2iFfZxHOaPzo+lY02D4ewzlw5z/E y2ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741846768; x=1742451568; 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=lVILxdziP1NvabNMhmzXbXNckUkSyJVqto36jQ3zFgM=; b=vyX30qRaS334NRhQP/WPH1Rd89KKMpAiNl3FxWpv565T1mC3dIr9mSvC522i6zuuwu h1MuqT5VwPYTZrzEVX7FHBmz/thUcvG4gZ8Gkca7pUxiSeGQux+lqAtCizhTwC/Jmkd/ 7XI6ysRVc+W5lqVaPyiqXykadXe7p+atIeUz4c4l7vbLhdP9OXQRWJmXm7BNgTyzCEmi 6OvrAr4DCyyeE4D8oiKovDibFllJ3+YE+nO9liF9DVI4ShR9iislre4yA/Gc1MrznS37 yfKJ6Oe0soHi2iyK44sV9/4ep/Qf87jDH3jdbwdMTe6YLrbZmjuIV2R/7F69EpTMGHqs 3BRg== X-Forwarded-Encrypted: i=1; AJvYcCU2Zw98BDSQ9v9jJhKpElJRDWO7GZMrz5ZuZUXwuJn52jH22blDlrtlfJn/Sf/g+E1fSgBSfGxj8y+G@vger.kernel.org, AJvYcCUgUT1YW9AUuZ8s9l0MTZGn3gPDf/10fh4pEwvLM2R2OiaR7bph04a7VOQM2o2H5Dcu3U0dOMhFdUq+@vger.kernel.org, AJvYcCW5UhuiXhhJ+W2+sB3JlmtGRAPZqchdmiKdXvjN7JmOiaUq+BG0O/+B+6WGs2mEk6wpkJ4K+XlHbcOkHz1X@vger.kernel.org, AJvYcCXEqZz3HQn6o2OAw+qwvtA9uaraRzpirhoIrnFXIUdO8La529O2xe2IiANyVjOtO1L0Wu35GmVjycqVoV+q@vger.kernel.org X-Gm-Message-State: AOJu0YzgGPA7VUxOAsvtReneo/WNWk7+JM26Snr/AjybaMYsBivgdwaE 19Ebf3rjdiBNT999mzb3myEtH6CcmuxEwT0ILwrxLjLasRXBzUzx X-Gm-Gg: ASbGncuVNgGtGjP7OejBhz6kL1cFKwQsHpA2OoLMdHrnM//6xCAAF90+sdutBNI5PkE gDLMLSeyQ6/7pJiFtiF3Z6c1tumP6TQHirwujPjL1BlbeS18bPfG+buzNi88BQ+5eP6Xdz5wzTj Lks5sZ0MbstT2Tj88MsxewXhPUiCKJo7Jq1qa74l0bKVFqBI1XxpEBWXqQ7G3utSHgSN3GMla6e G67xU0feLNnXM+WBa2rJK7xmB13YDlHBc6Q6B+vXOvFxoxlmCH7bPaVTWc4rl/1n9ct3iiuAezN NU/Jl4WK8QjgqNP+kJHd+u8KMDqPNPkv5gjf/cWBZ7tqLZSl+F7Ok2JAIY/6SBRkfiTd89jFk/1 P+nLVVTwlSR+izO1cmPt+8klhfdarkAdLkg== X-Google-Smtp-Source: AGHT+IHEh7ADj6YUcs5SkzzWI6HIZQv7Vk+Z1XYToZrip4ImNRNrlQOURmLAvEwjkVdtY6foxXTY1Q== X-Received: by 2002:a17:902:f70c:b0:223:f408:c3e2 with SMTP id d9443c01a7336-2242888a8bbmr415883375ad.14.1741846768228; Wed, 12 Mar 2025 23:19:28 -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-225c68880dfsm5856985ad.38.2025.03.12.23.19.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Mar 2025 23:19:27 -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 v2 2/6] x86/hyperv: Use hv_hvcall_*() to set up hypercall arguments -- part 1 Date: Wed, 12 Mar 2025 23:19:07 -0700 Message-Id: <20250313061911.2491-3-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250313061911.2491-1-mhklinux@outlook.com> References: <20250313061911.2491-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 --- 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 f022d5f64fb6..b5d6a9b2e17a 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 3f4e20d7b724..5d9aaebe5709 100644 --- a/arch/x86/hyperv/hv_vtl.c +++ b/arch/x86/hyperv/hv_vtl.c @@ -94,8 +94,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; @@ -185,13 +184,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 64b921360b0f..1f78b2ea7489 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 Thu Mar 13 06:19:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Kelley X-Patchwork-Id: 14014382 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4833D1FBCBD; Thu, 13 Mar 2025 06:19:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741846772; cv=none; b=fF7xsCH+/F+boa90YFHVIfQj12X8780T3yH2zqOXys/7NHqUqUMdL3JKdQvt2Nvn+2nEzb6CSJXGW0GAf6qVqt8Q6czy2FWVLdPQoHgh2P/aI6CqBsQJURe69POLE5sASVytoBlvYQrs2HhO+jN6X1Sa87XQJk2LiiW/fuXQqt4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741846772; c=relaxed/simple; bh=4jsTUcjJjVFIMH9g9y1/okRRumLPNOpO9g9cC+yb4OU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QtY2p3KioFfgP7FKIrVCSktRFYwhP2WhvElAWUIQZtmz1W5Z2c4tE4pbfRGPy9YszWxXObo3DM4a1+c2lK7HtXyJr2VcTZ0a6m4F4a/3uI3iOCEulsLjSnhu5YykRrpESCigEuQQJBov/U6xKAYmBNZOH0TATUF/qniI5DQC+ns= 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=BC8FbGx+; arc=none smtp.client-ip=209.85.216.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BC8FbGx+" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-301302a328bso1313701a91.2; Wed, 12 Mar 2025 23:19:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741846769; x=1742451569; 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=Vzcvg/Hf2sEphvsPXXpr9HDwxrRjFXsmG/n/jmKN/8M=; b=BC8FbGx+dZiJeEsDqQqsBK3F43NEv4o5fTq1QNm/8Otujwt5jCgnMaVp1POrQ8UriY ViahSTRkGElW7bz/1Wv97TnPdcUy170aWDgFI/rj6egH4YORWha28fINsbvZqHLAocxi 5QAizXmR2o07gPuwfwQgH34474P1yj3iM3RAN3YMNxZVKkqggtyezIAGuXyOGi3yvEsU 04YMINVsatyq69P+GMqXgeNABXTWN9/MuI5b76m+2nCK653ueMk0U8FubqYLF84dpZ5s Tvt2B8Y7BazfOvDp6wqXDWWZqfL1SMlxiUsZ6OpmSS4XJXUGQzJUxNaanCMKcCsLXlF2 V8yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741846769; x=1742451569; 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=Vzcvg/Hf2sEphvsPXXpr9HDwxrRjFXsmG/n/jmKN/8M=; b=hVfQ7daF3eBgGO+ShRK23aP9pM0PRJ2+Ni+iL5A7EbxiEhySN3BFWJE6T1QVux43gN /aipzl7JPP4eX75rqAYk0MOyIzQSFeh0C6W9tmulOOXFA9efEbKbwN0CzzBBVBEAfkkV ojjtkUiHjcV9P84OYCX9JyoWpncEXe06ZZhQylVXSs1gCUt7ylZlKfWw5T3iIdGyQkC5 aYxgRcx7ddaAsb5H2Zo/ijee/GCYsabOSeyIyV3hhFbeBlxbN6+QnC+u95TUEi5rLQJa yi6OqFpCwwuMD5JizEyzkEUjyuwyStcyo8cTqM/TYpfxVQvhDdw6gKXwxXjOOz6md+rU G9nQ== X-Forwarded-Encrypted: i=1; AJvYcCUpCuYpUDfPZXi9kNBgfDkkfzslOakilA3SvsAU+XXJRCZ2Nk1HtiZoutMU1pWKWfh9RTn7gTQH7R5y@vger.kernel.org, AJvYcCVrP5SfNg1XNyPVKyGV7pPhdYGXvVEQ5Y/GVN7/pwmOTEfDflXCiDSY20xA3kyUhvYZYWD1lFeh9tyK@vger.kernel.org, AJvYcCVs1Ob0C82RRj2tsbshGp1tO7mhqzcSD4Yb+vEuc0z/Ait7MpmMH8lx5x4Vss0vLZM8DN2IdsWOEr4xJlK8@vger.kernel.org, AJvYcCW7ETLM/ofFama+cdaDMXg5/ZFfxq+aQVPcJotodx00VZiOFX5eCLfksKDhcaF5Ge9Lb/scEhorho0kkghj@vger.kernel.org X-Gm-Message-State: AOJu0YytZSV3dMq9W8YVji5gAXJxV5zE+bU5vSTgurT9rG3Aii/dDqRj i8aNWKUAtETdFs31GrJ4jc7YQECrJRFZ/xMZjhlxqqUlKeq8rApA X-Gm-Gg: ASbGncsunEUoth/7HKVq/XVej5ygHoaOUJgC8934Uzea9YdKCogNj0zvTy6hXBUYbK3 dh0PxtbslgernNuUkx3hBjDqZYbZqxqn73eTED562Y5Gq2vWtEsjxqHpECEDOesF+Uhta8m4dyB SEoO9tGMdNQ5FxqEhMw8zJKBShJaJYPmYuNmcGV0ohWujv+iAgn8pQ6CKrar4bLKunMpkeqk720 pvrU7Iv0IK/cyvqTdYAyWGK5+JIFwUEIrhiq9TMBnrjLKDwsc6at2p+cabd63N8q93V5IvWzswX DGC0MG2+/Rp+0AivmEcJZldhdu+lRoqJnFpIc3ll+5shBWRaiBO5bBKk4cOwvluYQcqbZaYlk1k bRvL5YbQIIS3vFAwV7OVcbqk= X-Google-Smtp-Source: AGHT+IHr0vatWAvabq/sI3Lc64UdX6DFlgVugn5vr4pfUctiAylSgqQEAqUI4p/yVlJP0ier3Rfk0A== X-Received: by 2002:a17:90b:1a86:b0:2ee:53b3:3f1c with SMTP id 98e67ed59e1d1-2ff7ce59755mr33687899a91.5.1741846769393; Wed, 12 Mar 2025 23:19:29 -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-225c68880dfsm5856985ad.38.2025.03.12.23.19.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Mar 2025 23:19:29 -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 v2 3/6] x86/hyperv: Use hv_hvcall_*() to set up hypercall arguments -- part 2 Date: Wed, 12 Mar 2025 23:19:08 -0700 Message-Id: <20250313061911.2491-4-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250313061911.2491-1-mhklinux@outlook.com> References: <20250313061911.2491-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 --- 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 ec7880271cf9..de983aae0cbe 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 1f7c3082a36d..7d143826e5dc 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); @@ -206,10 +197,10 @@ static u64 hyperv_flush_tlb_others_ex(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) - 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 58895883f636..70e5d7ee40c8 100644 --- a/include/hyperv/hvgdk_mini.h +++ b/include/hyperv/hvgdk_mini.h @@ -533,7 +533,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 */ @@ -1218,7 +1218,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 Thu Mar 13 06:19:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Kelley X-Patchwork-Id: 14014383 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 388F21FBEA4; Thu, 13 Mar 2025 06:19:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741846772; cv=none; b=msmPyMxwIc005R6Q1VDb9ECFYav246JyFA+bkAT7sC6Cx33Sy8Y0ziwjlpVU8rfL02LHNkZ+YvE7BmGJ6mPujMKkgMW5GEntWPeY59PB6Qcq+7+BjSdfCCucDF9sS7Z5kILCjNslAP7gQuFpqEQ26ND/AWk+qngzhym1nRnVTqk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741846772; c=relaxed/simple; bh=BxXwt1RFwOu0MSLelU4BCKZTl9E4XVzmHyRKUsL8J1E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cxaBL566hcB21/OUVgrkH9f35SgAhJ2UEuVdoeDxOuc0C+6wUmsh2y/bPu/Il2EyHUaGdSGTVDNb5wIiuQ6q43WVCwrYinV8UDH1QPgy1AUgkhsSDV8KJUMbT2o80uuWy4ukZU0HfUocee7GM6MHpkpO2OEq3EQAyNjTc0w9mvE= 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=kbc/1frz; arc=none smtp.client-ip=209.85.214.180 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="kbc/1frz" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-225b5448519so10446555ad.0; Wed, 12 Mar 2025 23:19:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741846770; x=1742451570; 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=yx8VsN7yGLgKybxAFVxT0ZvluwG4iDYRWCfAUwNv+m0=; b=kbc/1frzyjH/6C5Ux9S1I+FOBaYdsw5gpvbjQlQtC4g3cOJUk0qG44F9cOTjD1QOLg pipsvDDTo/wHrUSv0HMHkEhv1LwbNZPnkC0dPLT1ktil7AY3wUH3uZ32J3v5DwEzb40J WI5uqolkx5jg2Ske8Gvhqp/ioVfHce6Lnix8VYVC8/keTka+LslP1ecU9NC87oomVTuu naALlEVJ400UIwz3NM4PodnPWm0ehlAI1m+paqsHKjHBD+FOEAl36zQiOMRYL41nNyDN 9TtjtTYyp01aQz38AIz+KZyrFYxgT9RN+BGoa00s+O8FyAG6QYEgKYMgFfZGyHRfH7RT fMyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741846770; x=1742451570; 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=yx8VsN7yGLgKybxAFVxT0ZvluwG4iDYRWCfAUwNv+m0=; b=ZPK1XaViTalm+k9r3f0LKjd3WQyQtNqaR9DT4109lN2q9MWvD1hhoGgknSh0oso9eQ y+kWhKH7gJYwlHE5bPfpQaTA/HXDGMCiYkFItGDPW+KFH4lNJa+2ue0Kk+H0HYhsURrD nGaDYxdURqsAyRIw2zKDtOknHua/CA2z7j28nF8waNbOXZyvAwDge98Se3Hz9K9WqPHt b020Zu4VW+H4Kf4N/KdlUfO4Wu5AtXX6J/f8VP4e3qdL2pETP8Vm4tXGSuIHs38tqs2J AWQ6vqH0Meht5U4uh8jj0pxCjX6cEzVCsa3MOfco2RvUJdN62X+OxPVXcL81vkl4YGPZ YGtg== X-Forwarded-Encrypted: i=1; AJvYcCUYU2XPT3zfCVbQv7y9WM8ea7Yin5ZqrwmUMO8O9AZA2Adn+2gm+rNWx2qbn3rKduPJE4/KkZpUQbifmW5r@vger.kernel.org, AJvYcCVWMPYw4fNdTm4R2gImfVSWUkeQUg8Pgs3XDgKB6aT/54sa5bAu3PdalJ12W4+TfTeM5mnlswyroFAkmytp@vger.kernel.org, AJvYcCVbmKNXmy869K3mzCGMbGwBEJe4MUpEw3VRd00rglLb5AVHngGTebuhSch5y/5gv2CDPgnhpJsW295H@vger.kernel.org, AJvYcCVjr+iJEP2zXt8yYkOD8e2UOt+gwkdrMz/Z/X9T089D9UXV6JUg2TeLXcaLVIRnx7u9QO7crtQrHkxn@vger.kernel.org X-Gm-Message-State: AOJu0YzppZM1OwYDILW68R0VqLRY01mcd2n/BNyMmvwM6+PMizINHBSy YHpk0aRYlwzs/FMoRJwtlcufnEtH/5ATC+1xT+VLQhCkyeVZXMmG X-Gm-Gg: ASbGncubW/E8qBHtAy9oAOzM+Hp9M7HyeiB5aZ3ttvVMdTHB5pVE3G2A4b8LYAfRYVY H6VB870pYo5ZHWsb4q2S74YpXiW/3uVzt+nnTUZF/HupGd+1RyJTKtHJYHUuqoJgGWF/POicmS0 4IjiCoqPPcIe9CdLBoFL1IULYZOWrKKGHFhk2MpqSTotYDJq0wujmBwidV8TXrZEnUrZIKPv15b ByRwSR6ojYVcnIY77uOSMVt0Fc2atY05YsHkEuUzQLJX/amNkUaSQNV4/A4c15gzrJ3QbLgxS+w pNifeq8aSxNazUF5hOHADM7kbyQED3+NEos3OuVrHoSgJ1n6lOqQC66PwdP0GQg9UgrOhRy5k/M KtAIDFz/Ko78JubmnFpLr7jY= X-Google-Smtp-Source: AGHT+IE6UKl7Uvq210+i03o+UjxWHO2oYjEqA1mXi8pFkQBgjxvNsZpyJC1+UyCmim7KTX72J52OIA== X-Received: by 2002:a17:903:2405:b0:21b:d2b6:ca7f with SMTP id d9443c01a7336-22428be5c24mr374574255ad.32.1741846770520; Wed, 12 Mar 2025 23:19:30 -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-225c68880dfsm5856985ad.38.2025.03.12.23.19.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Mar 2025 23:19:30 -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 v2 4/6] Drivers: hv: Use hv_hvcall_*() to set up hypercall arguments Date: Wed, 12 Mar 2025 23:19:09 -0700 Message-Id: <20250313061911.2491-5-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250313061911.2491-1-mhklinux@outlook.com> References: <20250313061911.2491-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. hv_post_message() requires additional updates. The payload area is treated as an array to avoid wasting cycles on zero'ing it and then overwriting with memcpy(). To allow treatment as an array, the corresponding payload[] field is updated to have zero size. Signed-off-by: Michael Kelley --- drivers/hv/hv.c | 9 ++++++--- drivers/hv/hv_balloon.c | 4 ++-- drivers/hv/hv_common.c | 2 +- drivers/hv/hv_proc.c | 8 ++++---- drivers/hv/hyperv_vmbus.h | 2 +- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index a38f84548bc2..e2dcbc816fc5 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -66,7 +66,8 @@ 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, sizeof(*aligned_msg), + sizeof(aligned_msg->payload[0])); aligned_msg->connectionid = connection_id; aligned_msg->reserved = 0; @@ -80,8 +81,10 @@ int hv_post_message(union hv_connection_id connection_id, virt_to_phys(aligned_msg), 0); else if (hv_isolation_type_snp()) status = hv_ghcb_hypercall(HVCALL_POST_MESSAGE, - aligned_msg, NULL, - sizeof(*aligned_msg)); + aligned_msg, + NULL, + struct_size(aligned_msg, payload, + HV_MESSAGE_PAYLOAD_QWORD_COUNT)); else status = HV_STATUS_INVALID_PARAMETER; } else { diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c index fec2f18679e3..2def8b8794ee 100644 --- a/drivers/hv/hv_balloon.c +++ b/drivers/hv/hv_balloon.c @@ -1582,14 +1582,14 @@ static int hv_free_page_report(struct page_reporting_dev_info *pr_dev_info, 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); + + hv_hvcall_in_array(&hint, sizeof(*hint), sizeof(hint->ranges[0])); if (!hint) { local_irq_restore(flags); return -ENOSPC; } 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 9804adb4cc56..a6b1cdfbc8d4 100644 --- a/drivers/hv/hv_common.c +++ b/drivers/hv/hv_common.c @@ -293,7 +293,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 2fae18e4f7d2..5c580ee1c23f 100644 --- a/drivers/hv/hv_proc.c +++ b/drivers/hv/hv_proc.c @@ -73,7 +73,8 @@ 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); + hv_hvcall_in_array(&input_page, sizeof(*input_page), + sizeof(input_page->gpa_page_list[0])); input_page->partition_id = partition_id; @@ -124,9 +125,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; @@ -167,7 +167,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; diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h index 29780f3a7478..44b5e8330d9d 100644 --- a/drivers/hv/hyperv_vmbus.h +++ b/drivers/hv/hyperv_vmbus.h @@ -101,7 +101,7 @@ struct hv_input_post_message { u32 reserved; u32 message_type; u32 payload_size; - u64 payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT]; + u64 payload[]; }; From patchwork Thu Mar 13 06:19:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Kelley X-Patchwork-Id: 14014384 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C6011FC102; Thu, 13 Mar 2025 06:19:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741846774; cv=none; b=aCNZNezoRmZWxGPkOT60K+X3vpHQ5X7o2dyo/lb3E8TiNiPO0SGkSUkDqw8Ok0T8WAcAFd3EBGRDETgk9Dg8SAIBX3tnKEdgRX55RHMXF0pH9IL8cVzuNzH81zLP+u4VP853htrhFEPzRJ5tEZ51S3M2YMSPB2iLRGqqXo2p6rc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741846774; c=relaxed/simple; bh=MBsWXYwv2VcUzCKC7z2YB1m56xcFcfFX3itPj/cZh6o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bZS/trw10Usf6IyNngVsEaxO6V8ssJDYwKBRqz6XUMqmsXH97C+VGnhonGmXUox53w0BcGX/u+o1MsueDdB2yB9Gc6plXZSTljjfGB/sXOuKHnCOOxeNVbyfJkUQjm9kgWusxglhEoVh8bbsz6POV4HJvPxivqJjT7K94bSqp6U= 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=BSpA4FzX; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BSpA4FzX" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-223f4c06e9fso10593505ad.1; Wed, 12 Mar 2025 23:19:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741846772; x=1742451572; 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=oz05HLp3NblZaI9ceF6GSEmcnmK2sGIqBfO9rFYxlJw=; b=BSpA4FzXQvXzwGN2L0wDKhAEZWdVupd8bu+jCjQ8Fue7VgjNq9DpKpuOtoz5Z/6r12 4+gdQpeOrwOA1Glet5LrrVdDeVyQXlog709LBvz3vTqayiqvyl6L3JM85bJItG2k8kfL K79hcLOasJxSkVeaQdw5PfhqAroEkrl6WovGpxtCHXq/mL3p71C0b1bRyIzopM2R55n+ 2L020bCOS+653GvqJOwfwB/aUHhtgs85VaNR6wcH6smKSJ7Fz59YyKvTfAgJ5T4HSiIA oznyC25iHdKZNX1WHJhgkCj8JxsAIGM7E+/N57p9MdfaF4JHezbRygZkHpZM0SkpRvFj KgNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741846772; x=1742451572; 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=oz05HLp3NblZaI9ceF6GSEmcnmK2sGIqBfO9rFYxlJw=; b=m+4lMmGX4qEny8LoQseIqnPyDPPuX2duG963rBwL0bSiV2whguP6f7q8/uSaaV+wcr 6XOT/pqGoFhyHbS2vtZTuKCgqWV3755Kl/piYJsd2oxpk6sl0+7h7UaQRtskXEeI89Hl WHN80anWe91wpFsh4Xz9GZwVOhPFYu3pz4jTvwtjS7ARUKmTqydOch2Enw3TP5LMQiUi 5ACTT19oEJ0v3ojTORk1AvgweQzCGytPZN5oxDaruvstCoeufGXkLjU5zbgk4Yd2X+GO bFkg+TxpIJQluaaXlUdE7zBSAiq5Ev4Kx/z198igLOUvsbKFgxpoCwWQIi6fOSV/FgSf /WKg== X-Forwarded-Encrypted: i=1; AJvYcCUZOjM1SwejBriAwhtuUqg5GI0zt3GpkpvhDc8oNYCz2mRb3sSwUXGI2YuSTaEIVVn4R5Uek5Vm++Jv@vger.kernel.org, AJvYcCVJGpD74I3czJqavloFgZlMgPC7XyuFHXYygTbFI0nw66iL/puOZWbU9iTYWD2v9jTDLMOFcFI2T0mv1aNj@vger.kernel.org, AJvYcCWv/tMzkiM4+/lOKlO/G5MWVKLpbwVEp92kKK+IS09s18pd16GPEIA6TDU8ZMzpf8J2yYTOH/Kt2prIi5dy@vger.kernel.org, AJvYcCXNxUPC+CT+pym1RT3Kq2SAWcaqtt0pw3ksDqEkVY0j3Q00sHsEK5HkDWxzRgrVbimgVhMdDKcqbvAv@vger.kernel.org X-Gm-Message-State: AOJu0Yxegsd2jluIVcIx+HtZfk54L6+V0UsbAEiA1i5J5GnpLXj1sj3h UAiHPiCNbKhyTHBb+AX5cpmPJaTjVYTxwa6XlFMRc9atu96N2j5b X-Gm-Gg: ASbGncth0Lvd57PUrqbOeYRbG7VKRNr0Iv8GJ8i1xt6WqBNDYGbn6mu2L0YBVb+sh+Q Gb4hC5uKZKwoA2Q888vQTggJ05gEn0qAx23W7E4JK3CMVRipYXG4kMsA7qfacgvCJrvDufjKknm cnW8H4p4NdwRe7opGn0Y5sjG+adZN9PWVFp79yyK7kwQlc2tOgkTpWofAw1aoE8xqJV0M6FUEbV txa5P/HwdybfIcti2P47gzCZbc4I2InqrZSpK9JfoQ4lLwLw0/9ITmJslQN4O2x9BK6reOi3jFl 9RGE2EVW+5XXMENAd5plxWou6//EPkj/T4ubRcKRod071zazhQXXnPpMugj1imzd83Utqy6bUR6 MvAWrxAlkJv+y2CUasrLDcxQ= X-Google-Smtp-Source: AGHT+IGWWEw4YJmPUWWdWOZCtx2jqKvh3NNjsC0GjhIUGfB2i9nD1wziWUWDOAcLHVhn/w/FyBZO9Q== X-Received: by 2002:a17:903:8ce:b0:223:607c:1d99 with SMTP id d9443c01a7336-225c641e9d1mr23875815ad.0.1741846771715; Wed, 12 Mar 2025 23:19:31 -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-225c68880dfsm5856985ad.38.2025.03.12.23.19.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Mar 2025 23:19:31 -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 v2 5/6] PCI: hv: Use hv_hvcall_*() to set up hypercall arguments Date: Wed, 12 Mar 2025 23:19:10 -0700 Message-Id: <20250313061911.2491-6-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250313061911.2491-1-mhklinux@outlook.com> References: <20250313061911.2491-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 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 ++++++++---------- include/hyperv/hvgdk_mini.h | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index ac27bda5ba26..82ac0e09943b 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, sizeof(*in), sizeof(in->data[0])); in->gpa = gpa; in->size = size; switch (size) { diff --git a/include/hyperv/hvgdk_mini.h b/include/hyperv/hvgdk_mini.h index 70e5d7ee40c8..cb25ac1e3ac5 100644 --- a/include/hyperv/hvgdk_mini.h +++ b/include/hyperv/hvgdk_mini.h @@ -1342,7 +1342,7 @@ struct hv_mmio_write_input { u64 gpa; u32 size; u32 reserved; - u8 data[HV_HYPERCALL_MMIO_MAX_DATA_LENGTH]; + u8 data[]; } __packed; #endif /* _HV_HVGDK_MINI_H */ From patchwork Thu Mar 13 06:19:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Kelley X-Patchwork-Id: 14014385 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A2D861FC7D7; Thu, 13 Mar 2025 06:19:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741846775; cv=none; b=bnXrSy6ClJo0i/YPbg1YoN/ChVFu5UaJk0ePv6yFgIJG4+0oi7uUjD1QPRWYBq3pMugpCqdx0rpyXTmB646pnhabVyd247WzA0hGgKEu+IMDFySmw2BlXGXrjOpPK8B6eKlPgfWmXWmr4gIVF+eRfoTry7xPnMPVdeGLImZUJTs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741846775; c=relaxed/simple; bh=D9tV1fNaeEavI8kgVzOD/UPEqZFk3aiyKOW25HgURJg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KXJ/mGMSqNO7VkOOJ+lL4j3THRmZHAgqvOk5CVXkUUUMRdfHCpy8Gwz1MID6F+BYapdfCY8d3+DuIeEj3p9nG+OheFrpgmQfWkXtt9HkBXmtkAO/2Ldy2kldsJGMTU+5sTUtQlGmkfiUKMMGdlO9TgyhpqBL22wQpVvL+KliPvc= 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=FzD35sGe; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FzD35sGe" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-22398e09e39so10722505ad.3; Wed, 12 Mar 2025 23:19:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741846773; x=1742451573; 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=CDn/tUUQAJnXzR6AU14kpCd/xpQ2+Hi/FbJxM9Yhnsk=; b=FzD35sGe2L+1OFo0A9e7kwBbR2WfOT2WqVrnpnUocSgu+TdKMeOXwoxRKAXotrHejM P/Khbaqp9yQ7woi/z6efigVjjf2U8cZmVdOWHCmWtb/Tjxl2vagGEHN/BvKR5M/tIVA/ SXGBRYICJafyMyTlKhEgoPN4zeeZ8BjGQOxiYR/TGrYynRERjUaSQVg747YCdZXiFRA9 WjT7/fL2yq3rfTL6NQGMpeK6bDjbRUuNGMFAqZ/y9+bBS8HHa9yOR/64rzXya/uMG4q2 5Qr1/EEukRJIRNsRylggSWpX82eDrHqGrwOWTsKIsiiesq94212fRjM36MWQj3tQk34Z e2ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741846773; x=1742451573; 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=CDn/tUUQAJnXzR6AU14kpCd/xpQ2+Hi/FbJxM9Yhnsk=; b=O7/BbZHdsHh+NC+9AXvZgoB+hZbzyFfq2GOjOOpTi+1EX+zY/1N9esCcmhbiwySZM4 lP0RGj+9WrfMAF9vqU2KlaZSP3IbQKk6RsKbFSN1kkEPQRH1KiMZ5poCYSe1KLTOceO6 uDQmG6j1Xkz7ypmiYXRk+NBnuTvxl1vtfmlguko3ZvY4TVa6CW66GAOmhs4jaa0hbw1K pADQP1FZXtejW0m1bx3AbIEGgF7WqFPuRL4GfHptnHw1yvHldSZDIUkDOBkp4461Fp+v KhWpWQRVYwHT9TRz57zgFAm/EYtiHEGBS6fNUHfbbzup6W/gBLC2G+ffYb692QUJE3Ye 4+GA== X-Forwarded-Encrypted: i=1; AJvYcCU1HSD3WoQh1zHKMhhDCJkPqMFASJE3f4BLL4RD3oV7Vyox/hF3xygMVnwUZG46WQ2828nLwfoDB5kbUhxJ@vger.kernel.org, AJvYcCVZY8CFRDUY3r72TBkqzalmFLGKDo5X+Z65waooPipSRIPyhK6Fu++5NSlmSfINzPcUsYPskUaMpYR/@vger.kernel.org, AJvYcCVi7EQdchalDdb9SICCUnpg6S9ANr7j0nH3HymGaTu/OGr/jgsu/tKH7q29teAWvWogbMBPwuujUB2Z@vger.kernel.org, AJvYcCW623LgNdhMCTYRhYT8VEHwnl4G2gY9S2M/aNDbOxfTrjJkQOkeiWNzhKl6KiDn5XQ06WrHp2Gsd2I7YH/F@vger.kernel.org X-Gm-Message-State: AOJu0Yy+NF+8JOhR2ooqde2gaJiF60Ko67m6yVPWPp2psDD7qj3UfkvC MLRKhHfBN8q1KasWOrHMpf3GGtrLjXxIS7cRcHrEd9eIlg+gfUWK X-Gm-Gg: ASbGncvKgRXNpstgFslxzPQKwewga0fsdp5xMbWPyGto0VQSZHcpH79h1GoTryyNDHq aPECPr8K7A5xjNc7vwLqsBHKUUTxNObT8KxH1s0wUE1rW28UBQC5/dVhI7ISTNmiZI4C56m+VWS tmOaEDH8cmeeoIpxDPVLofNkTAhOM+v0ojHSlUS16lZoT0RrNpoL9RPAyhkUYzZf3thh7FUdid4 tjnTKi6uGdG+oKpOyPLET2B+tvgyn5p0KtKuVe4uIH+raG6I4MmTSymgb9xn7en9wLbofJ98Z0u xOMrwTSrHdJwM4ewbj/LhKZ7jccGrQdlDt2UH1WZoZQ4kQooRb/lccOWwydsaiVC+QEsQQ0eaht 8EAXkLp6nw7ncRw0Foep8rOI= X-Google-Smtp-Source: AGHT+IH82KRGe+NjN4a9AuNj2WKlUNAuqSAMKc4lgjdhO9N+B3gSv2uaj1xcoy9UNuuxNsOvBMDqHw== X-Received: by 2002:a17:903:4407:b0:224:721:ed9 with SMTP id d9443c01a7336-22428c12cfdmr428144735ad.44.1741846772858; Wed, 12 Mar 2025 23:19:32 -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-225c68880dfsm5856985ad.38.2025.03.12.23.19.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Mar 2025 23:19:32 -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 v2 6/6] Drivers: hv: Replace hyperv_pcpu_input/output_arg with hyperv_pcpu_arg Date: Wed, 12 Mar 2025 23:19:11 -0700 Message-Id: <20250313061911.2491-7-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250313061911.2491-1-mhklinux@outlook.com> References: <20250313061911.2491-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 e2dcbc816fc5..854ef5d82807 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 a6b1cdfbc8d4..f3e219daf9fe 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); @@ -85,11 +82,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; } /* @@ -281,11 +275,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; @@ -363,14 +352,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); hv_vp_index = kmalloc_array(nr_cpu_ids, sizeof(*hv_vp_index), GFP_KERNEL); @@ -459,32 +442,27 @@ void __init ms_hyperv_late_init(void) int hv_common_cpu_init(unsigned int cpu) { - void **inputarg, **outputarg; + void **inputarg; 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; /* 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); /* - * hyperv_pcpu_input_arg and hyperv_pcpu_output_arg 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); @@ -498,13 +476,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 @@ -526,9 +504,8 @@ int hv_common_cpu_init(unsigned int cpu) int hv_common_cpu_die(unsigned int cpu) { /* - * 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 01e8763edc2c..015f87e35b5a 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -66,8 +66,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; extern u64 hv_do_hypercall(u64 control, void *inputaddr, void *outputaddr); extern u64 hv_do_fast_hypercall8(u16 control, u64 input8); @@ -139,9 +138,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