mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: John Garry <john.g.garry@oracle.com>
To: axboe@kernel.dk, mst@redhat.com, jasowang@redhat.com,
	xuanzhuo@linux.alibaba.com, eperezma@redhat.com,
	pbonzini@redhat.com, stefanha@redhat.com, hare@suse.de,
	kbusch@kernel.org, hch@lst.de
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	virtualization@lists.linux.dev,
	John Garry <john.g.garry@oracle.com>
Subject: [PATCH 2/5] block: Validate logical block size in blk_validate_limits()
Date: Fri,  5 Jul 2024 11:51:24 +0000	[thread overview]
Message-ID: <20240705115127.3417539-3-john.g.garry@oracle.com> (raw)
In-Reply-To: <20240705115127.3417539-1-john.g.garry@oracle.com>

Some drivers validate that their own logical block size. It is no harm to
always do this, so validate in blk_validate_limits().

This allows us to remove the validation in those drivers.

Add a comment to blk_validate_block_size() to inform users that self-
validation of LBS is unnecessary.

Signed-off-by: John Garry <john.g.garry@oracle.com>
---
 block/blk-settings.c   | 2 ++
 include/linux/blkdev.h | 1 +
 2 files changed, 3 insertions(+)

diff --git a/block/blk-settings.c b/block/blk-settings.c
index 9fa4eed4df06..55eef9541ce1 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -235,6 +235,8 @@ static int blk_validate_limits(struct queue_limits *lim)
 	 */
 	if (!lim->logical_block_size)
 		lim->logical_block_size = SECTOR_SIZE;
+	else if (blk_validate_block_size(lim->logical_block_size))
+		return -EINVAL;
 	if (lim->physical_block_size < lim->logical_block_size)
 		lim->physical_block_size = lim->logical_block_size;
 
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 02e04df27282..7eb165bcc069 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -268,6 +268,7 @@ static inline dev_t disk_devt(struct gendisk *disk)
 	return MKDEV(disk->major, disk->first_minor);
 }
 
+/* blk_validate_limits() validates bsize, so drivers don't need to */
 static inline int blk_validate_block_size(unsigned long bsize)
 {
 	if (bsize < 512 || bsize > PAGE_SIZE || !is_power_of_2(bsize))
-- 
2.31.1


  parent reply	other threads:[~2024-07-05 11:52 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-05 11:51 [PATCH 0/5] " John Garry
2024-07-05 11:51 ` [PATCH 1/5] virtio_blk: Fix default logical block size fallback John Garry
2024-07-05 12:14   ` Christoph Hellwig
2024-07-08  7:39   ` Stefan Hajnoczi
2024-07-05 11:51 ` John Garry [this message]
2024-07-05 12:16   ` [PATCH 2/5] block: Validate logical block size in blk_validate_limits() Christoph Hellwig
2024-07-05 12:34     ` John Garry
2024-07-05 12:38       ` Christoph Hellwig
2024-07-05 11:51 ` [PATCH 3/5] null_blk: Don't bother validating blocksize John Garry
2024-07-05 12:17   ` Christoph Hellwig
2024-07-05 11:51 ` [PATCH 4/5] virtio_blk: " John Garry
2024-07-05 12:17   ` Christoph Hellwig
2024-07-08  7:45   ` Stefan Hajnoczi
2024-07-05 11:51 ` [PATCH 5/5] loop: " John Garry
2024-07-05 12:18   ` Christoph Hellwig
2024-07-05 15:29 ` [PATCH 0/5] Validate logical block size in blk_validate_limits() Michael S. Tsirkin
2024-07-05 16:06   ` John Garry

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240705115127.3417539-3-john.g.garry@oracle.com \
    --to=john.g.garry@oracle.com \
    --cc=axboe@kernel.dk \
    --cc=eperezma@redhat.com \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=jasowang@redhat.com \
    --cc=kbusch@kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=stefanha@redhat.com \
    --cc=virtualization@lists.linux.dev \
    --cc=xuanzhuo@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®