linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Eschenbacher <stefan.eschenbacher@fau.de>
To: "K. Y. Srinivasan" <kys@microsoft.com>,
	Haiyang Zhang <haiyangz@microsoft.com>,
	Stephen Hemminger <sthemmin@microsoft.com>,
	Wei Liu <wei.liu@kernel.org>
Cc: Stefan Eschenbacher <stefan.eschenbacher@fau.de>,
	linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-kernel@i4.cs.fau.de, Max Stolze <max.stolze@fau.de>
Subject: [PATCH 1/3] drivers/hv: make max_num_channels_supported configurable
Date: Sat,  5 Dec 2020 18:30:02 +0100	[thread overview]
Message-ID: <20201205173002.2529-1-stefan.eschenbacher@fau.de> (raw)
In-Reply-To: <20201205172650.2290-1-stefan.eschenbacher@fau.de>

To make the number of supported channels configurable, this patch
introduces uint max_num_channels_supported as module parameter.
Also macro MAX_NUM_CHANNELS_SUPPORTED_DEFAULT is introduced with
value 256, which is the currently used macro value.
MAX_NUM_CHANNELS_SUPPORTED was found and replaced in two locations.

During module initialization sanity checks are applied which will result
in EINVAL or ERANGE if the given value is no multiple of 32 or larger than
MAX_NUM_CHANNELS.

Signed-off-by: Stefan Eschenbacher <stefan.eschenbacher@fau.de>
Co-developed-by: Max Stolze <max.stolze@fau.de>
Signed-off-by: Max Stolze <max.stolze@fau.de>
---
 drivers/hv/hyperv_vmbus.h |  6 +++---
 drivers/hv/vmbus_drv.c    | 20 +++++++++++++++++++-
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
index 02f3e8988836..edeee1c0497d 100644
--- a/drivers/hv/hyperv_vmbus.h
+++ b/drivers/hv/hyperv_vmbus.h
@@ -194,11 +194,11 @@ int hv_ringbuffer_read(struct vmbus_channel *channel,
 #define MAX_NUM_CHANNELS	((HV_HYP_PAGE_SIZE >> 1) << 3)
 
 /* The value here must be in multiple of 32 */
-/* TODO: Need to make this configurable */
-#define MAX_NUM_CHANNELS_SUPPORTED	256
+#define MAX_NUM_CHANNELS_SUPPORTED_DEFAULT	256
+extern uint max_num_channels_supported;
 
 #define MAX_CHANNEL_RELIDS					\
-	max(MAX_NUM_CHANNELS_SUPPORTED, HV_EVENT_FLAGS_COUNT)
+	max((ulong) max_num_channels_supported, (ulong) HV_EVENT_FLAGS_COUNT)
 
 enum vmbus_connect_state {
 	DISCONNECTED,
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 502f8cd95f6d..8f1c8a606b4a 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -48,6 +48,11 @@ static int hyperv_cpuhp_online;
 
 static void *hv_panic_page;
 
+uint max_num_channels_supported = MAX_NUM_CHANNELS_SUPPORTED_DEFAULT;
+module_param(max_num_channels_supported, uint, 0);
+MODULE_PARM_DESC(max_num_channels_supported,
+	"Number of supported vmbus channels. Must be a multiple of 32 and equal to or less than 16348");
+
 /* Values parsed from ACPI DSDT */
 static int vmbus_irq;
 int vmbus_interrupt;
@@ -1220,7 +1225,7 @@ static void vmbus_chan_sched(struct hv_per_cpu_context *hv_cpu)
 	u32 maxbits, relid;
 
 	if (vmbus_proto_version < VERSION_WIN8) {
-		maxbits = MAX_NUM_CHANNELS_SUPPORTED;
+		maxbits = max_num_channels_supported;
 		recv_int_page = vmbus_connection.recv_int_page;
 	} else {
 		/*
@@ -2620,6 +2625,17 @@ static int __init hv_acpi_init(void)
 	if (!hv_is_hyperv_initialized())
 		return -ENODEV;
 
+	// Check if max_num_channels_supported is a multiple of 32 and smaller MAX_NUM_CHANNELS
+	if (max_num_channels_supported % 32 != 0) {
+		pr_err("max_num_channels_supported is %u, but must be a multiple of 32\n",
+			max_num_channels_supported);
+		return -EINVAL;
+	} else if (max_num_channels_supported > MAX_NUM_CHANNELS) {
+		pr_err("max_num_channels_supported is %u which exceeds maximum of %lu\n",
+			max_num_channels_supported, MAX_NUM_CHANNELS);
+		return -ERANGE;
+	}
+
 	init_completion(&probe_event);
 
 	/*
@@ -2641,6 +2657,8 @@ static int __init hv_acpi_init(void)
 	if (ret)
 		goto cleanup;
 
+	pr_info("Supporting up to %u channels\n", max_num_channels_supported);
+
 	hv_setup_kexec_handler(hv_kexec_handler);
 	hv_setup_crash_handler(hv_crash_handler);
 
-- 
2.20.1


  reply	other threads:[~2020-12-05 18:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-05 17:26 [PATCH 0/3] drivers/hv: make max_num_channels_supported configurable Stefan Eschenbacher
2020-12-05 17:30 ` Stefan Eschenbacher [this message]
2020-12-05 17:30 ` [PATCH 2/3] drivers/hv: fix misleading typo in comment Stefan Eschenbacher
2020-12-05 17:30 ` [PATCH 3/3] drivers/hv: add default number of vmbus channels to Kconfig Stefan Eschenbacher
2020-12-05 18:27 ` [PATCH 0/3] drivers/hv: make max_num_channels_supported configurable Michael Kelley
2020-12-05 20:32   ` Max Stolze
2020-12-05 21:33     ` Michael Kelley
2020-12-06 10:48       ` [PATCH] drivers/hv: remove obsolete TODO and fix misleading typo in comment Stefan Eschenbacher
2020-12-07 11:25         ` Wei Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201205173002.2529-1-stefan.eschenbacher@fau.de \
    --to=stefan.eschenbacher@fau.de \
    --cc=haiyangz@microsoft.com \
    --cc=kys@microsoft.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@i4.cs.fau.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=max.stolze@fau.de \
    --cc=sthemmin@microsoft.com \
    --cc=wei.liu@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).