From patchwork Wed Feb 26 20:06: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: 13993134 X-Patchwork-Delegate: kw@linux.com 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 42DD12755E8; Wed, 26 Feb 2025 20:06:21 +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=1740600383; cv=none; b=uMS/cGjjikJcO+yS38IgEOgstK9jJjNdR6KpsQUb90CMw7zJDN6EAZpykG1/ceSCezUsEi1aUSdVJEutL1/ItwAdEU02IumIs+h7owOXhQKTOzBOl0IYG8M9mHrF/BD+wKl98Kwk5/w1pQcJi0PF5L9OG15r03+x9DgtvwFlzKc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740600383; c=relaxed/simple; bh=KnE1M4pDyDem1/WpZ046tGoH2Z26OE6TWYZHJPkydU8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mWvY4nCPaNarCHpbKRQpIxmk0NdNZITnpxhfLItSONSPRBx8Q2HC6h/4eeQD/8+mfsIYyKc8dDoFEq53cVfLn0eU9xa30pBewNYLKocLIh5wZnpjK/xmxwvkCli77R8ORsPCMWbxntnY92BMRvyTG8nVjryMxldP46DeCvVZVUE= 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=eGsI8jDS; 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="eGsI8jDS" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-220e989edb6so3557475ad.1; Wed, 26 Feb 2025 12:06:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740600381; x=1741205181; 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=XgJyZ7y87Cfn135tyI1dS2xkOMoi0hm5jbxPv0m7Eec=; b=eGsI8jDSlArWoQvsWPdagqKqv+6frGQ6Atvq7/AX9O3ocGmcQIQHeaq10tB+DGouzO SjsGxTeeK0NkXvwcS0cqnFvA8GLKr0rk+OCsXeOTLgLoN0Alm8R+u91npVoWYapCClxJ qZy5wwKiQzQSQ8eTYq2CDWBC4b5dKQgyiXe1G21MYDQdEBI22rLLrqb8RgPDidL36wbE ScgPRIHBh56bqLbwQSKXcsh7I5l3xI2yfH5oeM2QktMdgGclq6aqA3JaXEhba9XBm41m XnITyLt9UR1U8D17YuftVzIjgmQ40Q6OwgwrXYuBKG8uzojYb8gAYjU11UBo0sdZv2lL l9AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740600381; x=1741205181; 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=XgJyZ7y87Cfn135tyI1dS2xkOMoi0hm5jbxPv0m7Eec=; b=sJ8Uq766jZOEMoVfxLrjpn7FanX1GHxw0TUr3P/1GlNQGEXqCVbGWyK2zc0oogMs+L Qu7hrnXS6QoY3yJf7wYsfPBBLzaKg6YNSVGfgSUMjpjuWwBrgCKhiXHeCxPiP8QdnphC Vwro4UU01gExCDeXeifXXMD6MmHOwVdQzmeHoqQn+MOUMhvZX5wOqtfMytVnwELfoqyR zdCR3vwGKun2gyKXzyfs4aAhEGsZ3XvD4t+NFFLyU92rve6GS1BsTSI80ki38GA6LEKW tfS0SZmJrGMQ94zG0OuLatE7z+EYAY9FgZBLfYDBBe7KEocH811F6j0rm5B7tbEPffB5 1AdQ== X-Forwarded-Encrypted: i=1; AJvYcCUqytEEcMS1mqCwcMyzX1NNN09WnIk2Sa2oMTRgNqThHkGFDGTZ3/YhsRKfShgsfMhU3pMJH3sb6w++8NUr@vger.kernel.org, AJvYcCVOOnVmSVJ2cmHkcHBl+KMszHOMelOQ0yBnSuRr6sgpntOq0zWJOjvexuLe6y9hj7EMB7ORZ9X9OVAe@vger.kernel.org, AJvYcCX46Jwe3Ou8qV8X/ZgXoI4FBT7EDICi8SIII9F1zYzoTM/9FjvzqvLHlFNr9G8HgW3FT5Kq98e2vakQ@vger.kernel.org, AJvYcCXUVJ6pbtrhl+bpLihmPNa83pYEXkDT+lWlAYYyp/sLLmD4UGQ6UX3Mc0L7q1+Cd6yhOdYJhQXY/hNu6mwa@vger.kernel.org X-Gm-Message-State: AOJu0Yx5Gm2XSKbqFYQJgqDuGMzTE2RPa2uU1pS88j5lnsys3jYODLke AZ4JiDv6xMgolrNyZ9pdj3lEGS4EiyAxVQbmqsowdbu8CLcQgImm X-Gm-Gg: ASbGncvT7rMqKFs0YgW9AkHUx/lRICABf26xGyJ9yyYGg+HXoRNMFiMqd7UzqxyN5q4 Hm5P8eXAqkx0p/81kuLDwmsZzuTfaGzkm8m/J6EEjqvyMxXfsEwTb5nwJovmfJf2WQZ1IG0XIcx ectayvVTQunQ3z/Oal9d9Y0M7eIpbLtyXvoEXECjdyH80vmlOtONutNhQAC52XDxkkPaIGULFhd iJ2gmaxdAIu4f1YEXHyaGfu0Y6QojzPT6nmDcD02XCfYBkCb+PCRGUztYGvfvETLA56JsULo2X2 AO9SGKyjlNdtos2+P5dlPjVjLUbliPT3kRUdm9TwW2Gi8FTyWW2EHYUKARTzE9v8OgrViAw57P3 HH6Ou X-Google-Smtp-Source: AGHT+IEkTvSswxO7SHDrOXgfTx8tntlEBKUKPjfmvp+LW9KVLQneY3F5dVvMti+uUCbeeniPuo+e+Q== X-Received: by 2002:a05:6a20:12cb:b0:1ee:dd60:195b with SMTP id adf61e73a8af0-1f0fc98ea2amr15910629637.41.1740600381328; Wed, 26 Feb 2025 12:06:21 -0800 (PST) Received: from localhost.localdomain (c-67-160-120-253.hsd1.wa.comcast.net. [67.160.120.253]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7347a81bbc7sm3959455b3a.127.2025.02.26.12.06.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2025 12:06:21 -0800 (PST) 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 1/7] x86/hyperv: Fix output argument to hypercall that changes page visibility Date: Wed, 26 Feb 2025 12:06:06 -0800 Message-Id: <20250226200612.2062-2-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250226200612.2062-1-mhklinux@outlook.com> References: <20250226200612.2062-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 The hypercall in hv_mark_gpa_visibility() is invoked with an input argument and an output argument. The output argument ostensibly returns the number of pages that were processed. But in fact, the hypercall does not provide any output, so the output argument is spurious. The spurious argument is harmless because Hyper-V ignores it, but in the interest of correctness and to avoid the potential for future problems, remove it. Signed-off-by: Michael Kelley Reviewed-by: Nuno Das Neves --- I have not provided a "Fixes:" tag because the error causes no impact. There's no value in backporting the fix. arch/x86/hyperv/ivm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index dd68d9ad9b22..ec7880271cf9 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -464,7 +464,6 @@ static int hv_mark_gpa_visibility(u16 count, const u64 pfn[], enum hv_mem_host_visibility visibility) { struct hv_gpa_range_for_visibility *input; - u16 pages_processed; u64 hv_status; unsigned long flags; @@ -493,7 +492,7 @@ static int hv_mark_gpa_visibility(u16 count, const u64 pfn[], memcpy((void *)input->gpa_page_list, pfn, count * sizeof(*pfn)); hv_status = hv_do_rep_hypercall( HVCALL_MODIFY_SPARSE_GPA_PAGE_HOST_VISIBILITY, count, - 0, input, &pages_processed); + 0, input, NULL); local_irq_restore(flags); if (hv_result_success(hv_status)) From patchwork Wed Feb 26 20:06: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: 13993135 X-Patchwork-Delegate: kw@linux.com 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 8D938275602; Wed, 26 Feb 2025 20:06:23 +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=1740600385; cv=none; b=jV94JjpS53xZ2D4yynspMHv2q2tomZMvPTD1WgRllYO4FAebBsfTayOw1H7c7ZnFkwQazH9kBR2VWRI6MhQ4ihT45ZxEB5pQ+wyG2J1856xxR0XHQFeYijZPC4XPkEw0cstCocHOWM9XazYP0peLGPI7j8qV0AInufm/+BQ/oy8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740600385; c=relaxed/simple; bh=D79O1DEyIEg4TJGa5io8k0t+2+DbP5zL8a29fjZrBNM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FkgLl7voC0JH1dJK05WSTm4kQeVHtTUurgWuGVCDhI8lpim6FjjAcZQDCxsZW/yJtVcDrM0l18wxLo6OfqKyqLFA5kkCTrlM6qe1HdwvCbIUMro2J5oMilgoDXQxksNsImR7KVRIOEzA5YsBhyLljIxdDCpDLSIxvR3fP4JwiI8= 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=KzYw7PNn; 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="KzYw7PNn" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-220c92c857aso4261405ad.0; Wed, 26 Feb 2025 12:06:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740600383; x=1741205183; 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=eER/4O9RFncyjEvwtnVJeEu162TtYqwzXdX6/zSnIN8=; b=KzYw7PNna1VnLmJHKnzwuxsuw0mabmTtaK3sZDIX6Cmzls2O/lvm6QLRwDbPHXiIR3 oEvUp6MViuy38obbDtXUg0QrDigH4Mxb6JDz3hI3sto3yQdWXImoiSZ5hdNVdZ1V3yqw DjtBq5EN2GHS3a/uQKVLlPwa3JhBnpb+waWuOkNBHv1meOv16yPfYqXP78S8YiQgVnSe OZL/0HK8ZI/2eMlQueNwaC/+8m9d2g11UlbqOJERMRL2J47Z6LhRo+3Hb5gQ1IMPJV/G sdwxR95vXvG8LHRq2eaXLkyNy9N5JHNl/DWXx7m2YYnjuUucFnFI+1PGAQ5yNmfxSasW VnRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740600383; x=1741205183; 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=eER/4O9RFncyjEvwtnVJeEu162TtYqwzXdX6/zSnIN8=; b=r0X+DUir30Pybwv/jkyAxps6QPuG7YTjiO2hbejvoB5lCKVc0Aa32OFsFLlk4VL8+q uINA+svxWSZ96QG5Kr3pQuqMaHLI3SeaOaIuY2I63QND2MORerQd03kmC3yujfZIJoYq sWGvmImJK3MFXVhRa00P7hlvcQn+U9JZn/0Lr+b2z0BsMJDSRtUU6taoLyNfI4xG4mMm iWjoYKs9Qdi916QTE8m534YPU7u2DWgqZbZHDOMEqHNdAd9Kfc77JT8s0guRrRyt0M1k lqFc/z3GbMoX2HBIO41cdvu3qAUKY/lvTdZvl7ZD3m30EHdPjzk4PcdOimd95UGnwbg4 43QA== X-Forwarded-Encrypted: i=1; AJvYcCUDGszSVA6+QEdW5FExQkrDUNe/xoB5bUdqYwdpksyK2N1lCvCQ5ZGKw3fgBNch+qySU/JlMzpDUSWf@vger.kernel.org, AJvYcCVnVSqTlOWqfkn0JkQO7/17zgwn4KtL6/3tQ08Y83LSs28WrWE41uANkmDmInbAt+/615i1JkXgbC3Q@vger.kernel.org, AJvYcCWIlcKYoTqYHi1PN88E9Pjvlg+OADeUnVDhxTSevSGv5CZGkDsk91x6wkmrJ+sw4PIpszDG3IPjINPsk8Yc@vger.kernel.org, AJvYcCXIqXYiFzwBg1gBVDnpytAL4aUa4M/qyZNyjJVf4gHQ3RnCzO93Vw2qJbLd0grzgKNK8DJV2JZG2uE3b93C@vger.kernel.org X-Gm-Message-State: AOJu0YwF3Axjy3eqEVbEiFk8GTSMMyhbmJcT7r3reRW+FfRiLvAggpHa n7AoLtE6lAifYNSy5nb9YcF4pqJuodcy4ZwExSvJp1C1h8pMmC0E X-Gm-Gg: ASbGnctsFiF2n4okzKVvEFxRfw00dXnZQRrq4kcFGBU37KzpmRlL4BrU0rMojYAZpxJ IWTXTkMbFpT4V1IpsJOzLNjsIgKHIdH7JslZEDrxopM5waNqRumkfp/IqIOHP1U6sYhOwtwyxfg oy3V4hYe4X0SkyO3VEBtogTvYDM9RL+mKDrS7uv/XeBfWBCNoK+8Sh7TO5alKJxg99R9qeUuzoD BbrjFgfbzTaCpy5us42l2brG2ln8QYLeUkMoL920sicxpdHW8l4JtazCXIFo8YDgnRmHzLQiy70 tTSgKBR8HlHyG3ytFSwIDJIvf0yGDK0zJH8uqy90eVdWyGl/a1Td1l1Le9LkFRd9fxg2BrhrLT0 GNlmH X-Google-Smtp-Source: AGHT+IEJ6ItHX9/26SJE/XNGOBK9nlscjKes08hvTllBo7xuTRQKdMm6q6ZJlpNcOYLSYUR8GGZuqw== X-Received: by 2002:a17:903:1c6:b0:221:77d:3221 with SMTP id d9443c01a7336-2234a189710mr9853825ad.8.1740600382694; Wed, 26 Feb 2025 12:06:22 -0800 (PST) Received: from localhost.localdomain (c-67-160-120-253.hsd1.wa.comcast.net. [67.160.120.253]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7347a81bbc7sm3959455b3a.127.2025.02.26.12.06.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2025 12:06:22 -0800 (PST) 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 2/7] Drivers: hv: Introduce hv_hvcall_*() functions for hypercall arguments Date: Wed, 26 Feb 2025 12:06:07 -0800 Message-Id: <20250226200612.2062-3-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250226200612.2062-1-mhklinux@outlook.com> References: <20250226200612.2062-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 are expected to 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 --- include/asm-generic/mshyperv.h | 102 +++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h index b13b0cda4ac8..0c8a9133cf1a 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -135,6 +135,108 @@ 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 are expected to be constants, in which case the + * compiler does 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. + */ +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 Wed Feb 26 20:06: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: 13993136 X-Patchwork-Delegate: kw@linux.com Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 B2A7B25744B; Wed, 26 Feb 2025 20:06:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740600386; cv=none; b=Rf1qSmGEMv0aHHNKIA9bCZcKPSV0VXqjQIHeB80Q1g8FEAh6zcWj29y6emcEHw9notZi0FPmyzu6vLjytqgLpVB4KXMNDt7gZVh/2Xogaz1uDk5dY5YN0WMcPxejXR0O5DKp6PtgYHIQqMzVI1HHxzw92fcUK5qN6/XPzIArVgU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740600386; c=relaxed/simple; bh=k+V5fUKBx05yHfLoL5m76aeT57n+ZeCP/vw9Wp90kpg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JS9iEnhAfm9J069CJRnSJNyXzqUyZW2d+BpjRltYPpMDO1v/ez61A8mHxLqeHsHpbyH0tI4/Ic3/jyp6j4xD3x6c/fXIwWbN8C0WJa6Oy3WeiKj3Vm2mI5+8hH4Wk0A7g6MCOzUWTywGaTl1T2NjPiZFNzNOFgytgAZdwt0idIA= 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=Ke4Xplra; arc=none smtp.client-ip=209.85.214.171 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="Ke4Xplra" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-219f8263ae0so2664815ad.0; Wed, 26 Feb 2025 12:06:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740600384; x=1741205184; 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=qmlflR8I0V+Trqo6jOi+696C/+5CyLaGqLVJ7WAblLE=; b=Ke4Xplra4x3886jp6RmVWzCSJD7mcrPEKgFY3e3VUlaB2g5hlbX9C3qrJxcgUuIfEU Bt/K6vrxvbVg8RdnoOmDtgPi1zSh4FRJ1mIgphZ660p5wERTJhteRlpIwlrRZKFDzqLQ j2q9ygMxLLTmTpMcZR49ctoLGZ7mLFcvDcJ18XwVVZ8Dwl/6Mu81qjsuufGI6vwq29rd L8JbSywBxb4Heb1ZBukkwnbqMJxVmLeoSZURe45ya7PSV///e6T7zQocAvZt8gramRUN iYx1izyHdtbvnslbd/pvu0Tsu7le6MzQE7Kjd0mMS1kUpUSQW84+Zo/bdY5oeobMBefU f/gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740600384; x=1741205184; 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=qmlflR8I0V+Trqo6jOi+696C/+5CyLaGqLVJ7WAblLE=; b=k7LkO3NdJsaPkWcS5hQBzZhCfv0A0UHZaRw7+LY1ruvKRapW2AqA47BgXEoxbK0ADs hwzx2MSo0dHB90ZRLYe5A8HyJxtv/xJOF3gEXrN7OObxV4ITEeRuK83hfPOz2LOuc2dq txQXrWsmKF43qJQhjcnpdl9dCh7/MylatnmjxTrbErIkQPmgj45g2FzIt/A1442lWzuZ oxcAC0Qf/gpthrHwny3wEbpjoQLdA6BrSpGnZ+9IJ1TcKu65hMG2X6dZV5yDMmxNGl8v C8fNRede5oS6GXIMjJwf+N6Juz1MKrVWS9wmDkKVIIE0wrqTYcIlYRTItjsaz6d2MK6d AsnA== X-Forwarded-Encrypted: i=1; AJvYcCUs9giecivblu/1HZB8n0fGJyhAR1we4W/aY6CyC3+tstfw1UY6ElqrgXfdnCvS62HN6CaLrYvDuiZG@vger.kernel.org, AJvYcCUvTusvcDfyllBSEyI5lbEALMiP8At/C8BMVSXdgD7pA7uVsNdy20GuOkHcS+pbH4gYKX9CIOoj6vhb@vger.kernel.org, AJvYcCV/lls2Cz6M84XZsO6m4rlc5KvJErJeiGEGQjmWS5gEUR05Uy7veE2NCImcRlIxWtIK39k50BsWyxMd+Psf@vger.kernel.org, AJvYcCXdZ7einBZ+AIIHTBljOerH8d9hIse/z/Zqm+2h48YFGn81dk3yY/2BgtOiZUbkZSdipuCUvgteKZmqGU+5@vger.kernel.org X-Gm-Message-State: AOJu0YwxcZ3M3X7auSrbrAl6Ck10OuO2QEjnEZ6hJ3/JOhRAbZ+QhObF GXStKps4TxYPeqbqQfTNkokh94yOX+njuXeXcuvWEX4RRwfVWcZJ X-Gm-Gg: ASbGnctSdo9dHWmknIWCTV8xTqAJRqQi3vHVaxlKZkLqxCabsEwABVJKWsgIth65fTv q+v1518Du6+Fnb3emp1+J4et4FtXAUqrPNAfIG5Lv6XHa/d8kCWo0GlalSVBbBrwDFYOh0oMp1V ONhQUYr8qT3N39zeMYdlYjq6A+/yY1pyjc5E5M1M1Zrw8WsoW1gEB8AsyyDVh7vuvL6a8zIw26P GYlA7c6NuzuJzdlOEo3qasgmMBCNYx/7nL6gkPi+bQrUOw3hxLNHFv6TcGHGhovHIFolDPX1xt7 a5/oo2uIcmPHmwFTxNAWF+PGQf0NMLaCuvC6yoEuwiu9IDTsc6dqqvoNWtRdSiPJCJpoAJRya1A fnUpV X-Google-Smtp-Source: AGHT+IGgCrRzE7lCUq6yJr7vMJRE38h6tXtuzzjRC6JDbh4YFPRi6UksigebGzAnF/9qTlDhBEVBeA== X-Received: by 2002:a05:6a00:2441:b0:732:a24:734b with SMTP id d2e1a72fcca58-73426d7271emr35180911b3a.15.1740600383907; Wed, 26 Feb 2025 12:06:23 -0800 (PST) Received: from localhost.localdomain (c-67-160-120-253.hsd1.wa.comcast.net. [67.160.120.253]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7347a81bbc7sm3959455b3a.127.2025.02.26.12.06.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2025 12:06:23 -0800 (PST) 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 3/7] x86/hyperv: Use hv_hvcall_*() to set up hypercall arguments -- part 1 Date: Wed, 26 Feb 2025 12:06:08 -0800 Message-Id: <20250226200612.2062-4-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250226200612.2062-1-mhklinux@outlook.com> References: <20250226200612.2062-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 --- arch/x86/hyperv/hv_apic.c | 6 ++---- arch/x86/hyperv/hv_init.c | 5 +---- arch/x86/hyperv/hv_vtl.c | 8 ++------ arch/x86/hyperv/irqdomain.c | 10 ++++------ 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/arch/x86/hyperv/hv_apic.c b/arch/x86/hyperv/hv_apic.c index f022d5f64fb6..c16f81dd36fc 100644 --- a/arch/x86/hyperv/hv_apic.c +++ b/arch/x86/hyperv/hv_apic.c @@ -115,14 +115,12 @@ static bool __send_ipi_mask_ex(const struct cpumask *mask, int vector, return false; local_irq_save(flags); - ipi_arg = *this_cpu_ptr(hyperv_pcpu_input_arg); - + 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 diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index ddeb40930bc8..c5c9511cb7ed 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -400,13 +400,10 @@ 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(&input, sizeof(*input), &output, sizeof(*output)); 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..3dd27d548db6 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,10 @@ 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(&input, sizeof(*input), &output, 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..803b1a945c5c 100644 --- a/arch/x86/hyperv/irqdomain.c +++ b/arch/x86/hyperv/irqdomain.c @@ -24,11 +24,11 @@ static int hv_map_interrupt(union hv_device_id device_id, bool level, local_irq_save(flags); - input = *this_cpu_ptr(hyperv_pcpu_input_arg); - output = *this_cpu_ptr(hyperv_pcpu_output_arg); + 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) { @@ -77,9 +76,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 Wed Feb 26 20:06: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: 13993137 X-Patchwork-Delegate: kw@linux.com 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 CED8925A320; Wed, 26 Feb 2025 20:06:25 +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=1740600387; cv=none; b=Cppogz2aZha5fPECDkZ4L4oeTzggRht/Ua+FiA0MffeCMaHEnEcxkoDlM9Zqjta+VvM0H7kchISFrgNZFZzXLTiAgHg/pJ2unPYpvikyNrFX1mmIzpLhk3/E9DglaCdyFuMe2WbB9Z20vG0ry95oN4AWCkwGFGbXza1YPObQeqA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740600387; c=relaxed/simple; bh=cQHG3g1r38YJDnNG41nqfDZRX+Fhd7xpe66aiwM0lQY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MAP5gJlbaZT2978I0pyIHr8B8PZKOVcLQZtb3lwAvj4nSobHIGlut7rjKSM2ZCESnqhMZ6vrmY1FHU6xhLozdfbaB06utM7GG4V2IQsKqqhH59lH9KtaKZguNRggFmwg4yNigbU4erFEChN8esy95lq9zF9+cOsmccB+pWryhhY= 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=e25AnWkb; 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="e25AnWkb" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-220e989edb6so3562105ad.1; Wed, 26 Feb 2025 12:06:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740600385; x=1741205185; 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=Z/vUG3UQf9enQcfjnJw3LUMuFVnqA0Sb2HUdnSE0x+8=; b=e25AnWkby1BSSWTvj2KJAesszA7Z2URjJTV+edz6EZfQ3P2TR+BaX2BEqynJ6YrVD9 GtS2Ny3EQPuSZc2w1bUWVzfP0h3wBd4lJMkdtf/lCL+z9ouBMPNUaW+mrszEMoXMGqM+ rUzPAAqggxbUIpmBmVXrtsJtdLU/uBhQCUzFVgB90c0dq9AdJNFW1ndVSGKlxZGH7Llg Lb2A5s6dsWO6w+R7yjQYYijogwuo68LQMpUhPGc6lAmXHU7MYUMSYw58AC4h02lSc02m RIusCP2z6lAYa1I1ft/yzS4mXrTF4Xi3tqKl1RoGOBzUae29P6DxnMbFg4320ZImIf+w YVRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740600385; x=1741205185; 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=Z/vUG3UQf9enQcfjnJw3LUMuFVnqA0Sb2HUdnSE0x+8=; b=ukuK7Nm9Xq46T8FKleM2v2LPUVKsSydUauI0Bc+wmiB8w2ukLa6pydroV3sB1eJCSX f55Uwrp1TvVKwdHNcDzXL2XxmYBQCeyEY1Aldoz+76WOodBoJ3OKBcKniOkFK+uwEomH cmqgjdYw4xxzwEsVdU77cUZmoK9ZlVo4+lYIWV1OTygL5bsu3jdgEU7G5RS5rqGpRVcg cAbX9za43Ioj9ALJtpQeUhVyqtwAJ6Ng8q2ja70ztDM4KWBRUadfz81RwLL31pTB09Cr GVl+wBt+kfxjBPX4gDuEoVl0DkfqOa79xrwrSGuWFi7OnmxzWA3+Baf5CifU/8/YpHMf PYcg== X-Forwarded-Encrypted: i=1; AJvYcCV3TDt+awxsbLNNMi7kLS1vyFf+5iawUsscNKFbt0zUttu6sfS1/8JxeVZGtVMYjljSNXC78e8oiyGgYXeo@vger.kernel.org, AJvYcCVZXTO3/qh0GPb+ZQo6rWyICBtX2V7SE1yAy4knCWYcpP7MTVGJNin7JoZjs3SpSOljIHdiv8tZSPoW@vger.kernel.org, AJvYcCX+5coVYVBeqdhyfBW8F3A78g9muORPWX9Kmh8E/AOTyhnCkiJAaIW8zEeURkNDu+IDU8Rw+qhtJcEaw8SX@vger.kernel.org, AJvYcCXF4qy42ArLLzJ6+n2D+aQfgxjIG+0BjYdbZ6Rd1eDIrlh71MflGIno/Avt0wsqqQPmaqeRcZkR9veE@vger.kernel.org X-Gm-Message-State: AOJu0YxiAkNEtp9Tn8D/7cRYS9U28Ads+3kRqkZAawsh8V38fHf30hwH Qocp4iBQiGZQINoYIfXC2k1kWJWFTFmSLgP1cpyxGLvY276dWwY6 X-Gm-Gg: ASbGnctrD3M0APRoZgGPkEtaxd0gydIG539htIHRK54xnt8Mpoxgtfqigv2dGgklG4d jJzy52ITrHi9GAlauPLeH7tntIAUx+8Wz1ZEWTEIVpWzEYbsO0nqEhtUuKoUmutMBBixtR27Eq1 vZZXsf0ZUUSy5Uj23kgcaYN/aMb6nPRuh+vbQvCLNSknlwXzNxcELmOd3q/CyTfmxtRJmLBQ52C v54Njw5pfpUpthRdn1MKUkPFmuc3unZdDHOJfByzzClpy9PjBiG5NE00nZPdJRF5f9zo3d0+Y+P 8V8zntTrb6MKEj1P49mT1t/Na9RG4VNH3YvhkpqA9MKYVzmcbj5glgQrtrV233uoaEAtuD26OyZ I3Vnx X-Google-Smtp-Source: AGHT+IHy/rKJWflxjO2CYWjEzwlC1ugGoBV5DueR1VDTIbMe0tXx9+DJ84m4wOXWUhH3FkRLr6BgtA== X-Received: by 2002:a17:903:1984:b0:223:4b88:77ff with SMTP id d9443c01a7336-2234b887eb6mr6111025ad.6.1740600384997; Wed, 26 Feb 2025 12:06:24 -0800 (PST) Received: from localhost.localdomain (c-67-160-120-253.hsd1.wa.comcast.net. [67.160.120.253]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7347a81bbc7sm3959455b3a.127.2025.02.26.12.06.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2025 12:06:24 -0800 (PST) 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 4/7] x86/hyperv: Use hv_hvcall_*() to set up hypercall arguments -- part 2 Date: Wed, 26 Feb 2025 12:06:09 -0800 Message-Id: <20250226200612.2062-5-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250226200612.2062-1-mhklinux@outlook.com> References: <20250226200612.2062-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 --- arch/x86/hyperv/ivm.c | 18 +++++++++--------- arch/x86/hyperv/mmu.c | 17 +++-------------- arch/x86/hyperv/nested.c | 14 +++++--------- include/hyperv/hvgdk_mini.h | 4 ++-- 4 files changed, 19 insertions(+), 34 deletions(-) diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index ec7880271cf9..1e4f65aef09b 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..ab9db23247c1 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,9 +197,7 @@ 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 (info->end == TLB_FLUSH_ALL) { 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 Wed Feb 26 20:06: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: 13993138 X-Patchwork-Delegate: kw@linux.com Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 E758625B663; Wed, 26 Feb 2025 20:06:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740600388; cv=none; b=kaV5DfvBcAGfxEYxCogldWA8kr1ELTpfZo+159dAwi+Pw808wFmb6OrUbPRtx6i0PRnYbkPIefrLYAtbzHxgJIfIQHzOYE5gjKux71GHzIFq0+Oa2xPi/iT1TR1EZMiFvH2w0fWHbBYceTNsA/MBFtSk/pfHHe57yF0gD5A+4n8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740600388; c=relaxed/simple; bh=UTc/zIxMZzlnepV3eF829gkrOKS/3bcc1+fy1YyKaRA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mMIX+L1TjTfNj7q2iYkMJpPEjMLvbKV9c9YfQwwQ8cY8eWQA9+0GLr4Gq+ce1aDwnRyEIk5/JwqzjKFkTAGH1hfqyuRRd5enJJlKBVJG1m+1paSneFJjBUpKuBbaeBfEU898HguhmIlWKIyVaeXHoWunHSHmrDjV3hdcrGDxMhM= 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=h1O6Bxek; arc=none smtp.client-ip=209.85.214.177 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="h1O6Bxek" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2233622fdffso2546445ad.2; Wed, 26 Feb 2025 12:06:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740600386; x=1741205186; 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=mH64ves2q9+0JDxQKA5wFB9C86aVirya4owjszWIQYM=; b=h1O6BxekuYXimLJZs13M1OAW0ptceKxL5Dze3LDXSzkLNBQltpEqoDEzHIZp5gpWR1 mMRo03gS1zVGjeJWbS7e+PTjKADFU/5NyD+Mi+BrUfYA0pE9CGRrwwAnUfpbJaq9ju+M fKQYOwsgZTYoxtFNPYpMqn9KE2gRQMJ14gNpBIledNRF1FS3DIx8UwAZJAE+niJHSj5s VyhdfJKskQTY9xwTTuh8hI+C8Dp/XRM99ps8yv7QL7sNdPHxH/dEqEb1ZKm+Il0ki60U GnCAcAhHer8/1WljdlKlldgPJ9yj7vQkhG62IHAGx0HnN3VM+L+vi1IGbpAOW1PORST0 aHqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740600386; x=1741205186; 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=mH64ves2q9+0JDxQKA5wFB9C86aVirya4owjszWIQYM=; b=RsUgJmbusO9jcG5bb47dCYZ50jt83JZs3AFZRph95jdYxrO9GimC7vOerYRsAS/ZWX Tnpk1TuZGgu5azRiqnyjJocJqta8JYpbLtYC2ZV2mMuScxz3XGa2V4zWy7O+XRKoK6G/ oIMQ/WmRQgbHafOX3zgRu9s/h9SEyY9X8pK0qEKvBN8p71YcBN1F99iuX7TS7pcxcdn+ LAuVIn7WIGOyIbJtYLjIyzSjnn875jzefN0CE+GuA5L0MQPKvaxxt0flBZg7zSrFQMEX gituhQM1v2Jes22sw+ubLlU7RJ5KB6gtXwqh2qBiE5DVZNOFSehHLO5Y8JbSlQp3SeEc Fdmg== X-Forwarded-Encrypted: i=1; AJvYcCU8RP5TXiGR5Mgk0+Y/LqOaffSHnF1bnH53cAVLT2CFJjpawU88ISVNCuBBOMM75W9tNXvHKSNDMAvn@vger.kernel.org, AJvYcCUAuEi94yMobvarAJPherjqLVjRUjef43gc7FbFc9pyjOwY2RTCXsespQ+mEPrdlEOuIxejWDsmXGzaA4QY@vger.kernel.org, AJvYcCVora5bKRoMuPeM2lvDekyE5vayPbkQ/h5VbJC7fWzfWMkZTIwe37li0otNVz8yBbbufdZ06nkBo7B1u5Rc@vger.kernel.org, AJvYcCW6/oUQ8PFcqQA8Yw9TuiMTjnhUiwp4PvGwvZdyvzTYRLoctzzg7YmHnohgfJNG5fSbzoS9JzDciSuk@vger.kernel.org X-Gm-Message-State: AOJu0Yy+ByJ5na7fgieEs4dk+JkM+dwxS2kAnqgNlA0CK+Q3hK0RfLpp hw0eutwcR3Chj1uh8Zwty42clv3uJO4kg2hxGmbWn4Yd5BuIapi8qXlV/Q== X-Gm-Gg: ASbGnctTSDxpr3CFq6fa2gvbcictE4sPq5fpFEyLP4571g7Wg9t/S1m1T+daoEI0t7D y2F+mYcmzX6g0qujrpVnL0iGjaYQs4i2R1YL0Vp2t8sD8D8we/DIN6+0TqUFfEtSff+dfvJw1qF 8UkHMQIiDeA+frK/JU320bfi5x9b4x+7VqYulLZHCnYURof0C8dXbR89rT8OLWiXPCWfOaFsFYs 6vsjURHRhBbzdhIOaB0xaQLCKlmQAOANUogNBcn/c+kjwVXIi5OsMzYkfozao5DVdKoM6wXyMtp M8DmTQ2PaHGEHMgONK06+tNgLRNFDQsuKBmX+ObmdulICnJGCYXxp9bZ+BsxeD6pwXrYEZNyuPz 252iO X-Google-Smtp-Source: AGHT+IGzBwtzQDRDAs0JclxfPDV4nz4s+N8wLmnCj+U3UG0rX0BVn//fyDyApXzDXvU2Te59jwDqzQ== X-Received: by 2002:a05:6a00:929d:b0:730:9752:d02a with SMTP id d2e1a72fcca58-734790a81bcmr14110219b3a.4.1740600386108; Wed, 26 Feb 2025 12:06:26 -0800 (PST) Received: from localhost.localdomain (c-67-160-120-253.hsd1.wa.comcast.net. [67.160.120.253]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7347a81bbc7sm3959455b3a.127.2025.02.26.12.06.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2025 12:06:25 -0800 (PST) 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 5/7] Drivers: hv: Use hv_hvcall_*() to set up hypercall arguments Date: Wed, 26 Feb 2025 12:06:10 -0800 Message-Id: <20250226200612.2062-6-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250226200612.2062-1-mhklinux@outlook.com> References: <20250226200612.2062-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 | 8 +++++--- 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, 13 insertions(+), 11 deletions(-) diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index a38f84548bc2..d98e83b4a6fd 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,9 @@ 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..d8f3b74d5306 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 Wed Feb 26 20:06: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: 13993139 X-Patchwork-Delegate: kw@linux.com 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 2D31B25C6F6; Wed, 26 Feb 2025 20:06:27 +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=1740600389; cv=none; b=qB10aVfnW56ZPr2B7XH2NTbXG1R77jIiVfQXN/fvgPoMR0qgY/jkxFnJkAPS+XG9IISTT3WMpzBGkpiiyIKu4aWzEyGTNoXCx3dF3KtagavM7IKp+TGxPuAYEeoWvFFn1dQyoU9lR/eDU/zif6H1BGxk3+LTVJs/zH6wKLvwkNY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740600389; c=relaxed/simple; bh=M5iM+v3BE6xddWKmrkHslf0oPFkrxg8orhL4OW9AAeo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oYG1A8TS39t9jTZqaBiSBrsBFEddMnsABxuDQLRJ0/Q+zf51yp8XRDB4jIB1qRT5qtp4TY/rvloeTUiTzj2qKrIvzOZKqe6vcF06lGOPhveNSJcwX8CgWa6i3LY3o29fhohbI7zeIm8NLreSN/st83/AKeT4ZNcXZCU75KCU7eM= 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=CI/7btwn; 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="CI/7btwn" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-222e8d07dc6so4873105ad.1; Wed, 26 Feb 2025 12:06:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740600387; x=1741205187; 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=ELYv+am9ZuaVjiWbWFLOkRsJsowJRkAsb1c2IjCc1to=; b=CI/7btwnRApQ+SWSowIj2GPzT+XPhsuXtIx2v8G0q2tgzutiTDj+zkWyqZKkvehAD1 Bw01N0PZCDKIcHsLcJp+ylCyVfll41qOB3RXyW4vtefCxEpqsJIND3g3w/7EbXvXVHmd vxvQNdYHD10an4HzP+vw4EOMuvz7nyeNyYwGvFf4w5VaVRC0uTtSwn5edOXVaBu/LKOL nfq+e8fd6eFI2nHfGIZtlTRtwHMUaTwh2xZxxf9uBVXALmjYUg8+i3lJ0FUxSaX1doZk NKDob6H+K1x/DywErZpkZFw6ktQKH3xNlGsDz1D0gdDzNY80UDMUegmM/OR1bSDgwFWQ 7RhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740600387; x=1741205187; 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=ELYv+am9ZuaVjiWbWFLOkRsJsowJRkAsb1c2IjCc1to=; b=GzPqNuoiWYeYJ3LTpBuyNptW0tZGrfci5CrQVhf+DlxuP4xGRwFhdfaUzyLF3+Vn7E 9/iUTrsIcwVVtDcdHdVN5eU6esjwZJrd3LZhbHeEuGuLcmiOVb13qs96XLFXeOGde0yT ARLuXc/ynv1ymqcxz1ZNAh3SeyUrdF+yyVXAVGKcP0p6gdSqABhvku8NqHngc9wwM7L0 HVcSiAvmjnpPJkB+pRgXD4nAmILMDENUJzr8K+bpnNvl0aFMcs8Lwjqb2Ucdjpln/jFr 5lYsoCGWne3o781nj5Li5gPCKTz4bjJCg/X7Cc9T8gtw2aXPMpBguIZP9RloMQLMLOjr RduQ== X-Forwarded-Encrypted: i=1; AJvYcCU/f01Hp8hWewAMAaGnEnZuJoUyze6Oj7if3ZtsJEpWf3KVqGMbLwAxarb8/hCZc+lbb3KZrrcA/8HU@vger.kernel.org, AJvYcCUf97Zf9uC5InqAMKl7Nh4fZMXJ5d4khRHAcBnAIGr7ZFJMBLBGm2LJM6mAeUrkbPHuEbgM9vM186dX@vger.kernel.org, AJvYcCUznwb4QxCqYY3esdDet3XaF7fOjMfOTtT4AQe/mlemDqeEsfxyPmsFl1Ik9PVGj+bp8F4R3BkrvmsHg2Cn@vger.kernel.org, AJvYcCWC/llG700Jxhx7mh4rMbWH8M9ZfJbXqh9iYCe3PHUYHp+09ILqhbFD2sinSweud2iCR6AAqL5oMEKXhJB4@vger.kernel.org X-Gm-Message-State: AOJu0Yz9l0Oqsezp3QOYe4QfHms3oz6UiVp4wHIwhPsnuYga2UK5uZnH IhFAjWlba568tbHLu+vY0YO1lVOP8/aHBdYv9lAehMJua2L46quO X-Gm-Gg: ASbGncuGUOJ3mh4zg6FP63dT4648DPsM3Bew8KQPRYeMBHhAjpe+1ANQJb1OOrV4FzO FxDOcsx1yD89ubjtcoEH8hA4oBdurOlmK7pKQ95ei5oqg2KblV5WH3UpBpyZn67a9J7RP2q/C5K DUFtg0l8gfsqHIBqyE3tWgBQt9UqD/zG3Q2nN7j65IEDI0Kji3dXKW+6cF81NnKkEUpUmj2gFOY v1gPEz2LZFNUlCEwzToigXrU6gA24BAcDhW1rvccJJRflA/nAjUOzaOJw+cFSBxyGtbngkbtHwv /eIOWwCFFH3N06/kGrOWtqYICbl5eM6RUSzvXUmSmPdAXxIy72aeT3iBeqXXBNQvf5nPp0XydVG DXSnl X-Google-Smtp-Source: AGHT+IEF9gSycAUTpsQfXxyyfb4BCEiV6gy3DT9yWoYp/0qBCfPYI4EN3aEwUEcsNwLTBnte36b+ig== X-Received: by 2002:a17:902:ce8d:b0:220:e91f:4408 with SMTP id d9443c01a7336-2234b083b0bmr8783675ad.22.1740600387328; Wed, 26 Feb 2025 12:06:27 -0800 (PST) Received: from localhost.localdomain (c-67-160-120-253.hsd1.wa.comcast.net. [67.160.120.253]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7347a81bbc7sm3959455b3a.127.2025.02.26.12.06.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2025 12:06:27 -0800 (PST) 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 6/7] PCI: hv: Use hv_hvcall_*() to set up hypercall arguments Date: Wed, 26 Feb 2025 12:06:11 -0800 Message-Id: <20250226200612.2062-7-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250226200612.2062-1-mhklinux@outlook.com> References: <20250226200612.2062-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 --- drivers/pci/controller/pci-hyperv.c | 14 ++++++-------- include/hyperv/hvgdk_mini.h | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index 44d7f4339306..b7bfda00544d 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -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)); + 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; @@ -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 Wed Feb 26 20:06:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Kelley X-Patchwork-Id: 13993140 X-Patchwork-Delegate: kw@linux.com 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 749382561D6; Wed, 26 Feb 2025 20:06:29 +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=1740600391; cv=none; b=ce3J65CyxrlttIZc7p4EBAd7NwVJ+1UfL/1bNjiCTVn1JB7kMkkdEPNg6sm8NjAMrcpwBzDUAfHeY2q9YdbtfA18NcJNoO/eBMryOsyhBPr4rGpWw1R/94e1CdPppLCXtCFgMBCwKJH63r4YcGLqootsRKOy4FLlJ9qRlEiMpZQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740600391; c=relaxed/simple; bh=t7eiL7YZuyBFsdO9Fyr9zI0CWzs9OjCk+7iblQ/Zd2U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KglOuOFbFfWG3HgYNKCDtXsj0WW+ZLPDAXjkr60IzISTBJ8d/vRguOzk+a4Ceo4qqhYC0qZPlRS/TuDQX4Guaxp5LhZW8WxYgGL1M4mkGwKpzHcQmE8nEb78EKw432G35Pw0QdimSbyba+eYDL+ZFPpBm2xKjsKvA99VS5RSIfE= 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=nGzWV2vQ; 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="nGzWV2vQ" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-22185cddbffso23746455ad.1; Wed, 26 Feb 2025 12:06:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740600389; x=1741205189; 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=55rg1NeeMLGrUg0GStDtbSRwVMFym0JITZgogy/cZRs=; b=nGzWV2vQhHsjsooY6g0sGrbafZ/hIK/f4WCvrhW5CC8Y9brdoSoeVTvUSi1iXzRLBQ ulZBKECjRn+VeuLxz/sKYd37v5N3lT28TxzOGUtBHlH4Ko5zfmCmd5K1PirEafMYAOva Q4ZB1sWYxQss1XSk7fkx+3PQF59ZyaT+SH0QPiE7SKv8bd53QrvbtNmFb5E///q+R/B9 epZTI/ViYXbyQEZae8T+OacWZHLDQRiLUKoGPKqdWb3tD+YLHjnAqcNM4LX1mv79jJiS wV5x0cycP4m8mPpnHm9FxKpwX0HTfYOOyZzzxrnCophwOLL8vUGVrmK+FsPDBcw8aL2l Aqxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740600389; x=1741205189; 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=55rg1NeeMLGrUg0GStDtbSRwVMFym0JITZgogy/cZRs=; b=MBwwJs0zA3brxUVW40y6oYIoxzPeeU0vEkW0ZKhx89lc6djnpllqP55yjVXnL9PtKN s2v9gwzb31SKhjk9NqyhHlANEl4bJWcqrOlBrl/6jeB5bkO55pRTLL+bzpOB/vKyuYok gwDwpEo2fJ/ee4Tqb7pCvSsAA18jt+t86KdcJ453LyT7cfCRqqdh4dty39mVEmk6Ykl7 q4fkoVpM2yFwlavoqVElTQgjsgOcHo25l8JDpUIKtIYsBeFFAUo1wsZfeqSTDjMJ6U1c Zs5mC+mSBKKQklEGICWMPfk4iRc16XixJiUAIwGez02HiuDv5HbG7LkpnEkNcf194Ik+ BKyg== X-Forwarded-Encrypted: i=1; AJvYcCUhDOoB5PdeLF+0TDIa17QwCjppmP1iUx6EKNxsEfhSQst7OiEPBl0qEDwX6UGv+kcdtUmDsyHhfJEGNVMh@vger.kernel.org, AJvYcCUnERO4mY+rKIpVnk+QzeoakNvkPh3SJOrAhw1zQGqGGLnO1jWFj0QrJIfqBVPvs7Qar7tC5DOjKTor@vger.kernel.org, AJvYcCXHNqnceO4HeLBDYOnoiWRfhC4bxhgViobtrRFXxsy8GHHQ/EdddDihK+B9HQdRCpwfCGX/oNoxbWes@vger.kernel.org, AJvYcCXUlhXYnzh3BKASspHgEj9szT7X3uBkSm2V1uJDpdouLYptwtZaS2QIES0h6lObh/nTB1NJ+IZ4ZH86MIXW@vger.kernel.org X-Gm-Message-State: AOJu0YxcKaLI19wOOnjdk/9qAtT2S/JlQVwXuY4FL/wON67D3BWUk2DV s5vJa89dd+s3G0/rPHpHU1dUNULPeelD8f90cMs1ps7pntzm+9ZB X-Gm-Gg: ASbGnct72AKFq9jEkte02aGz+gCwE0vGZyadlJdXOkkUNaJyo7wbxkqqvIy+qN4ouet VM4K71BXJCXL1qOoCGBNXsUXF9A3ipuZ+MNw8iIvUHj/7eq1AmoG94DTq4Ru9V/hu5PAmXEVrFj LIB4WA3wyYmGfj7ZI8rQjFHJD1X8SzXwdd8Zv19OucVSW0CjSsH3gd+em7WbwYiz5jiRKobIxVL WlPmS8NRZnLDbmbTU5mfRctuFmKLNKK/mGDiAUtPNcWMY1ftoLrnwZtegIavsWHHG389TS01KBC BwlO1ty8dauYbAkziNylx33clQox0jVktdBNYKyuKhttBzS9wEHc9RPKG59VfqJQtTpaui51kSZ dc+WY X-Google-Smtp-Source: AGHT+IFfPHpLZQ4zp9jwd0HYPB//Ggor8yNfHICfLG5CBu7602xlko+J7WgrZ2Gftb+NHiZOSj9wFQ== X-Received: by 2002:aa7:8207:0:b0:734:26c6:26d3 with SMTP id d2e1a72fcca58-7349d1ec1a1mr1094802b3a.5.1740600388527; Wed, 26 Feb 2025 12:06:28 -0800 (PST) Received: from localhost.localdomain (c-67-160-120-253.hsd1.wa.comcast.net. [67.160.120.253]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7347a81bbc7sm3959455b3a.127.2025.02.26.12.06.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2025 12:06:28 -0800 (PST) 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 7/7] Drivers: hv: Replace hyperv_pcpu_input/output_arg with hyperv_pcpu_arg Date: Wed, 26 Feb 2025 12:06:12 -0800 Message-Id: <20250226200612.2062-8-mhklinux@outlook.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250226200612.2062-1-mhklinux@outlook.com> References: <20250226200612.2062-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 c5c9511cb7ed..c701d7601f48 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -482,16 +482,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 d98e83b4a6fd..cdd5dcbdee4e 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 0c8a9133cf1a..2f94020b4633 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