public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] scsi: storvsc: Fix ring buffer size calculation
@ 2024-01-22 17:09 mhkelley58
  2024-01-24  3:00 ` Martin K. Petersen
  0 siblings, 1 reply; 2+ messages in thread
From: mhkelley58 @ 2024-01-22 17:09 UTC (permalink / raw)
  To: haiyangz, wei.liu, decui, jejb, martin.petersen, linux-kernel,
	linux-hyperv, linux-scsi

From: Michael Kelley <mhklinux@outlook.com>

Current code uses the specified ring buffer size (either the default of
128 Kbytes or a module parameter specified value) to encompass the one page
ring buffer header plus the actual ring itself.  When the page size is
4K, carving off one page for the header isn't significant.  But when the
page size is 64K on ARM64, only half of the default 128 Kbytes is left
for the actual ring.  While this doesn't break anything, the smaller
ring size could be a performance bottleneck.

Fix this by applying the VMBUS_RING_SIZE macro to the specified ring
buffer size.  This macro adds a page for the header, and rounds up
the size to a page boundary, using the page size for which the kernel
is built.  Use this new size for subsequent ring buffer calculations.
For example, on ARM64 with 64K page size and the default ring size,
this results in the actual ring being 128 Kbytes, which is intended.

Cc: <stable@vger.kernel.org> # 5.15.x
Signed-off-by: Michael Kelley <mhklinux@outlook.com>
---
 drivers/scsi/storvsc_drv.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
index a95936b18f69..7ceb982040a5 100644
--- a/drivers/scsi/storvsc_drv.c
+++ b/drivers/scsi/storvsc_drv.c
@@ -330,6 +330,7 @@ enum storvsc_request_type {
  */
 
 static int storvsc_ringbuffer_size = (128 * 1024);
+static int aligned_ringbuffer_size;
 static u32 max_outstanding_req_per_channel;
 static int storvsc_change_queue_depth(struct scsi_device *sdev, int queue_depth);
 
@@ -687,8 +688,8 @@ static void handle_sc_creation(struct vmbus_channel *new_sc)
 	new_sc->next_request_id_callback = storvsc_next_request_id;
 
 	ret = vmbus_open(new_sc,
-			 storvsc_ringbuffer_size,
-			 storvsc_ringbuffer_size,
+			 aligned_ringbuffer_size,
+			 aligned_ringbuffer_size,
 			 (void *)&props,
 			 sizeof(struct vmstorage_channel_properties),
 			 storvsc_on_channel_callback, new_sc);
@@ -1973,7 +1974,7 @@ static int storvsc_probe(struct hv_device *device,
 	dma_set_min_align_mask(&device->device, HV_HYP_PAGE_SIZE - 1);
 
 	stor_device->port_number = host->host_no;
-	ret = storvsc_connect_to_vsp(device, storvsc_ringbuffer_size, is_fc);
+	ret = storvsc_connect_to_vsp(device, aligned_ringbuffer_size, is_fc);
 	if (ret)
 		goto err_out1;
 
@@ -2164,7 +2165,7 @@ static int storvsc_resume(struct hv_device *hv_dev)
 {
 	int ret;
 
-	ret = storvsc_connect_to_vsp(hv_dev, storvsc_ringbuffer_size,
+	ret = storvsc_connect_to_vsp(hv_dev, aligned_ringbuffer_size,
 				     hv_dev_is_fc(hv_dev));
 	return ret;
 }
@@ -2198,8 +2199,9 @@ static int __init storvsc_drv_init(void)
 	 * the ring buffer indices) by the max request size (which is
 	 * vmbus_channel_packet_multipage_buffer + struct vstor_packet + u64)
 	 */
+	aligned_ringbuffer_size = VMBUS_RING_SIZE(storvsc_ringbuffer_size);
 	max_outstanding_req_per_channel =
-		((storvsc_ringbuffer_size - PAGE_SIZE) /
+		((aligned_ringbuffer_size - PAGE_SIZE) /
 		ALIGN(MAX_MULTIPAGE_BUFFER_PACKET +
 		sizeof(struct vstor_packet) + sizeof(u64),
 		sizeof(u64)));
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/1] scsi: storvsc: Fix ring buffer size calculation
  2024-01-22 17:09 [PATCH 1/1] scsi: storvsc: Fix ring buffer size calculation mhkelley58
@ 2024-01-24  3:00 ` Martin K. Petersen
  0 siblings, 0 replies; 2+ messages in thread
From: Martin K. Petersen @ 2024-01-24  3:00 UTC (permalink / raw)
  To: haiyangz, wei.liu, decui, jejb, linux-kernel, linux-hyperv,
	linux-scsi, mhkelley58
  Cc: Martin K . Petersen

On Mon, 22 Jan 2024 09:09:56 -0800, mhkelley58@gmail.com wrote:

> Current code uses the specified ring buffer size (either the default of
> 128 Kbytes or a module parameter specified value) to encompass the one page
> ring buffer header plus the actual ring itself.  When the page size is
> 4K, carving off one page for the header isn't significant.  But when the
> page size is 64K on ARM64, only half of the default 128 Kbytes is left
> for the actual ring.  While this doesn't break anything, the smaller
> ring size could be a performance bottleneck.
> 
> [...]

Applied to 6.8/scsi-fixes, thanks!

[1/1] scsi: storvsc: Fix ring buffer size calculation
      https://git.kernel.org/mkp/scsi/c/f4469f385835

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-01-24  3:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-22 17:09 [PATCH 1/1] scsi: storvsc: Fix ring buffer size calculation mhkelley58
2024-01-24  3:00 ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox