Skip to content

Commit 65995e9

Browse files
Naman Jaingregkh
authored andcommitted
Drivers: hv: Make the sysfs node size for the ring buffer dynamic
The ring buffer size varies across VMBus channels. The size of sysfs node for the ring buffer is currently hardcoded to 4 MB. Userspace clients either use fstat() or hardcode this size for doing mmap(). To address this, make the sysfs node size dynamic to reflect the actual ring buffer size for each channel. This will ensure that fstat() on ring sysfs node always returns the correct size of ring buffer. Reviewed-by: Michael Kelley <mhklinux@outlook.com> Tested-by: Michael Kelley <mhklinux@outlook.com> Reviewed-by: Dexuan Cui <decui@microsoft.com> Signed-off-by: Naman Jain <namjain@linux.microsoft.com> Link: https://lore.kernel.org/r/20250502074811.2022-3-namjain@linux.microsoft.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f31fe81 commit 65995e9

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

drivers/hv/vmbus_drv.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1820,7 +1820,6 @@ static struct bin_attribute chan_attr_ring_buffer = {
18201820
.name = "ring",
18211821
.mode = 0600,
18221822
},
1823-
.size = 2 * SZ_2M,
18241823
.mmap = hv_mmap_ring_buffer_wrapper,
18251824
};
18261825
static struct attribute *vmbus_chan_attrs[] = {
@@ -1880,11 +1879,21 @@ static umode_t vmbus_chan_bin_attr_is_visible(struct kobject *kobj,
18801879
return attr->attr.mode;
18811880
}
18821881

1882+
static size_t vmbus_chan_bin_size(struct kobject *kobj,
1883+
const struct bin_attribute *bin_attr, int a)
1884+
{
1885+
const struct vmbus_channel *channel =
1886+
container_of(kobj, struct vmbus_channel, kobj);
1887+
1888+
return channel->ringbuffer_pagecount << PAGE_SHIFT;
1889+
}
1890+
18831891
static const struct attribute_group vmbus_chan_group = {
18841892
.attrs = vmbus_chan_attrs,
18851893
.bin_attrs = vmbus_chan_bin_attrs,
18861894
.is_visible = vmbus_chan_attr_is_visible,
18871895
.is_bin_visible = vmbus_chan_bin_attr_is_visible,
1896+
.bin_size = vmbus_chan_bin_size,
18881897
};
18891898

18901899
static const struct kobj_type vmbus_chan_ktype = {

0 commit comments

Comments
 (0)