Thread (22 messages) 22 messages, 6 authors, 2023-05-17

Re: [PATCH 4/5] brd: limit maximal block size to 32M

From: Keith Busch <kbusch@kernel.org>
Date: 2023-03-06 18:02:32

On Mon, Mar 06, 2023 at 01:01:26PM +0100, Hannes Reinecke wrote:
quoted hunk ↗ jump to hunk
Use an arbitrary limit of 32M for the maximal blocksize so as not
to overflow the page cache.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/block/brd.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index 11bac3c3f1b6..1ed114cd5cb0 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -348,6 +348,7 @@ static int max_part = 1;
 module_param(max_part, int, 0444);
 MODULE_PARM_DESC(max_part, "Num Minors to reserve between devices");
 
+#define RD_MAX_SECTOR_SIZE 65536
 static unsigned int rd_blksize = PAGE_SIZE;
 module_param(rd_blksize, uint, 0444);
 MODULE_PARM_DESC(rd_blksize, "Blocksize of each RAM disk in bytes.");
@@ -410,15 +411,14 @@ static int brd_alloc(int i)
 	disk->private_data	= brd;
 	strscpy(disk->disk_name, buf, DISK_NAME_LEN);
 	set_capacity(disk, rd_size * 2);
-	
-	/*
-	 * This is so fdisk will align partitions on 4k, because of
-	 * direct_access API needing 4k alignment, returning a PFN
-	 * (This is only a problem on very small devices <= 4M,
-	 *  otherwise fdisk will align on 1M. Regardless this call
-	 *  is harmless)
-	 */
+
+	if (rd_blksize > RD_MAX_SECTOR_SIZE) {
rd_blkside is in bytes, but the above is ccomapring it to something in units of
SECTOR_SIZE.
+		/* Arbitrary limit maximum block size to 32M */
+		err = -EINVAL;
+		goto out_cleanup_disk;
+	}
rd_blksize also needs to be >= 512, and a power of 2.
 	blk_queue_physical_block_size(disk->queue, rd_blksize);
+	blk_queue_max_hw_sectors(disk->queue, RD_MAX_SECTOR_SIZE);
 
 	/* Tell the block layer that this is not a rotational device */
 	blk_queue_flag_set(QUEUE_FLAG_NONROT, disk->queue);
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help