]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
Drivers: hv: vmbus: Add utility function for querying ring size
authorSaurabh Sengar <ssengar@linux.microsoft.com>
Sat, 30 Mar 2024 08:51:57 +0000 (01:51 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 17 Jul 2025 16:27:40 +0000 (18:27 +0200)
[ Upstream commit e8c4bd6c6e6b7e7b416c42806981c2a81370001e ]

Add a function to query for the preferred ring buffer size of VMBus
device. This will allow the drivers (eg. UIO) to allocate the most
optimized ring buffer size for devices.

Signed-off-by: Saurabh Sengar <ssengar@linux.microsoft.com>
Reviewed-by: Long Li <longli@microsoft.com>
Link: https://lore.kernel.org/r/1711788723-8593-2-git-send-email-ssengar@linux.microsoft.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Stable-dep-of: 0315fef2aff9 ("uio_hv_generic: Align ring size to system page")
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/hv/channel_mgmt.c
drivers/hv/hyperv_vmbus.h
include/linux/hyperv.h

index 4ee8b9b22bb9d8f10bae8547219378bc22c20af6..8300ffb1ea9ae1b42be1c2339ea80aae94a4fbbe 100644 (file)
@@ -106,7 +106,9 @@ const struct vmbus_device vmbus_devs[] = {
        },
 
        /* File copy */
-       { .dev_type = HV_FCOPY,
+       /* fcopy always uses 16KB ring buffer size and is working well for last many years */
+       { .pref_ring_size = 0x4000,
+         .dev_type = HV_FCOPY,
          HV_FCOPY_GUID,
          .perf_device = false,
        },
@@ -123,11 +125,18 @@ const struct vmbus_device vmbus_devs[] = {
          .perf_device = false,
        },
 
-       /* Unknown GUID */
-       { .dev_type = HV_UNKNOWN,
+       /*
+        * Unknown GUID
+        * 64 KB ring buffer + 4 KB header should be sufficient size for any Hyper-V device apart
+        * from HV_NIC and HV_SCSI. This case avoid the fallback for unknown devices to allocate
+        * much bigger (2 MB) of ring size.
+        */
+       { .pref_ring_size = 0x11000,
+         .dev_type = HV_UNKNOWN,
          .perf_device = false,
        },
 };
+EXPORT_SYMBOL_GPL(vmbus_devs);
 
 static const struct {
        guid_t guid;
index 323c56152fa1be71918b8633b539925f2e3a7bb0..1137c25d9a7aee83a0e950e63b74b69836e9b5b2 100644 (file)
@@ -406,6 +406,11 @@ static inline bool hv_is_perf_channel(struct vmbus_channel *channel)
        return vmbus_devs[channel->device_id].perf_device;
 }
 
+static inline size_t hv_dev_ring_size(struct vmbus_channel *channel)
+{
+       return vmbus_devs[channel->device_id].pref_ring_size;
+}
+
 static inline bool hv_is_allocated_cpu(unsigned int cpu)
 {
        struct vmbus_channel *channel, *sc;
index 5e019d26b5b729c98110bb808716ae34c9102988..987cc04f13182087e6bc866617c5ce77a32b9a67 100644 (file)
@@ -802,6 +802,8 @@ struct vmbus_requestor {
 #define VMBUS_RQST_ID_NO_RESPONSE (U64_MAX - 2)
 
 struct vmbus_device {
+       /* preferred ring buffer size in KB, 0 means no preferred size for this device */
+       size_t pref_ring_size;
        u16  dev_type;
        guid_t guid;
        bool perf_device;