From nobody Wed Dec 17 10:44:35 2025 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 56716267F58; Fri, 2 May 2025 07:48:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746172109; cv=none; b=fBd6s3CtZluCMrAWiQLII+LFewojDJNPQD0VdkEP08owBje+h//8kicahkkwDRVzgLcQQQwoYmc0aNy8K9EniZxgX7F2XyBj/n8+b2gZN0HDIbivBG6xbVXlSalfXOB7VbX4Ov5lPck9++SB2neheFOJaychN8pkp96XDth6JW0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746172109; c=relaxed/simple; bh=mxyR+kcfs4gYf4C/qdGU1nWBoEqDv33owM86B43qDuI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SAC2/nXTTdvfSml3wlaJvUC4zZveW75cX/xD15sA/K59u7d5oN/Vm6NRzttQoN+NbhPzJNxyJnFtyxzmLvGpFWTaxC+vjR4u0XXVO7SzIlGWE7D72cj8x+2APCHGmwwP8HmkRVB2aGB+Jz5x+5vZ8wE2Houh0I06LcELD/h2oT0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=JVb1NQ0u; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="JVb1NQ0u" Received: from namjain-Virtual-Machine.mshome.net (unknown [167.220.238.139]) by linux.microsoft.com (Postfix) with ESMTPSA id EDC6F211156B; Fri, 2 May 2025 00:48:24 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com EDC6F211156B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1746172108; bh=DxEb4vtiVOwiGpqVi88QcpiTQSzDde9JS49NUzWo868=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JVb1NQ0uppbGPofuFwvyponJm59pdkBbPgGH7EuM7kYkFwpmWRB88n5pWghpCe4rm rre9vnZHlQDrRTTJjf5zP51f8Y4qTDAAjGUYIOZL44UvmjYb5SERTE1KRiqrrIwOFb fwFLRPkvQtlYsf/DfbbcXvAdLRCBSJxU0+47QhJg= From: Naman Jain To: "K . Y . Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Greg Kroah-Hartman , Stephen Hemminger Cc: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, stable@kernel.org, Saurabh Sengar , Michael Kelley , Naman Jain Subject: [PATCH v7 2/2] Drivers: hv: Make the sysfs node size for the ring buffer dynamic Date: Fri, 2 May 2025 13:18:11 +0530 Message-Id: <20250502074811.2022-3-namjain@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250502074811.2022-1-namjain@linux.microsoft.com> References: <20250502074811.2022-1-namjain@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Tested-by: Michael Kelley Reviewed-by: Dexuan Cui Signed-off-by: Naman Jain --- drivers/hv/vmbus_drv.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 0f16a83cc2d6..e3d51a316316 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -1820,7 +1820,6 @@ static struct bin_attribute chan_attr_ring_buffer =3D= { .name =3D "ring", .mode =3D 0600, }, - .size =3D 2 * SZ_2M, .mmap =3D hv_mmap_ring_buffer_wrapper, }; static struct attribute *vmbus_chan_attrs[] =3D { @@ -1880,11 +1879,21 @@ static umode_t vmbus_chan_bin_attr_is_visible(struc= t kobject *kobj, return attr->attr.mode; } =20 +static size_t vmbus_chan_bin_size(struct kobject *kobj, + const struct bin_attribute *bin_attr, int a) +{ + const struct vmbus_channel *channel =3D + container_of(kobj, struct vmbus_channel, kobj); + + return channel->ringbuffer_pagecount << PAGE_SHIFT; +} + static const struct attribute_group vmbus_chan_group =3D { .attrs =3D vmbus_chan_attrs, .bin_attrs =3D vmbus_chan_bin_attrs, .is_visible =3D vmbus_chan_attr_is_visible, .is_bin_visible =3D vmbus_chan_bin_attr_is_visible, + .bin_size =3D vmbus_chan_bin_size, }; =20 static const struct kobj_type vmbus_chan_ktype =3D { --=20 2.34.1