All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: "Richard Weinberger" <richard@nod.at>,
	"Johannes Berg" <johannes@sipsolutions.net>,
	"Josef Bacik" <josef@toxicpanda.com>,
	"Md. Haris Iqbal" <haris.iqbal@ionos.com>,
	"Jack Wang" <jinpu.wang@ionos.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Jason Wang" <jasowang@redhat.com>,
	"Roger Pau Monné" <roger.pau@citrix.com>,
	"Mike Snitzer" <snitzer@kernel.org>, "Song Liu" <song@kernel.org>,
	"Stefan Haberland" <sth@linux.ibm.com>,
	"Jan Hoeppner" <hoeppner@linux.ibm.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	linux-um@lists.infradead.org, linux-block@vger.kernel.org,
	nbd@other.debian.org, virtualization@lists.linux-foundation.org,
	xen-devel@lists.xenproject.org, linux-raid@vger.kernel.org,
	linux-nvme@lists.infradead.org, linux-s390@vger.kernel.org,
	dm-devel@redhat.com
Subject: [PATCH 04/11] virtio_blk: fix the discard_granularity and discard_alignment queue limits
Date: Mon, 18 Apr 2022 06:53:07 +0200	[thread overview]
Message-ID: <20220418045314.360785-5-hch@lst.de> (raw)
In-Reply-To: <20220418045314.360785-1-hch@lst.de>

The discard_alignment queue limit is named a bit misleading means the
offset into the block device at which the discard granularity starts.

On the other hand the discard_sector_alignment from the virtio 1.1 looks
similar to what Linux uses as discard granularity (even if not very well
described):

  "discard_sector_alignment can be used by OS when splitting a request
   based on alignment. "

And at least qemu does set it to the discard granularity.

So stop setting the discard_alignment and use the virtio
discard_sector_alignment to set the discard granularity.

Fixes: 1f23816b8eb8 ("virtio_blk: add discard and write zeroes support")
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/block/virtio_blk.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 6ccf15253dee1..d624cc8eddc3c 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -867,11 +867,12 @@ static int virtblk_probe(struct virtio_device *vdev)
 		blk_queue_io_opt(q, blk_size * opt_io_size);
 
 	if (virtio_has_feature(vdev, VIRTIO_BLK_F_DISCARD)) {
-		q->limits.discard_granularity = blk_size;
-
 		virtio_cread(vdev, struct virtio_blk_config,
 			     discard_sector_alignment, &v);
-		q->limits.discard_alignment = v ? v << SECTOR_SHIFT : 0;
+		if (v)
+			q->limits.discard_granularity = v << SECTOR_SHIFT;
+		else
+			q->limits.discard_granularity = blk_size;
 
 		virtio_cread(vdev, struct virtio_blk_config,
 			     max_discard_sectors, &v);
-- 
2.30.2


WARNING: multiple messages have this Message-ID (diff)
From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: "Jan Hoeppner" <hoeppner@linux.ibm.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	linux-nvme@lists.infradead.org,
	virtualization@lists.linux-foundation.org,
	"Song Liu" <song@kernel.org>,
	dm-devel@redhat.com, "Md. Haris Iqbal" <haris.iqbal@ionos.com>,
	"Jack Wang" <jinpu.wang@ionos.com>,
	linux-s390@vger.kernel.org, "Richard Weinberger" <richard@nod.at>,
	xen-devel@lists.xenproject.org, linux-um@lists.infradead.org,
	"Mike Snitzer" <snitzer@kernel.org>,
	"Josef Bacik" <josef@toxicpanda.com>,
	nbd@other.debian.org, linux-block@vger.kernel.org,
	"Stefan Haberland" <sth@linux.ibm.com>,
	linux-raid@vger.kernel.org,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	"Johannes Berg" <johannes@sipsolutions.net>,
	"Roger Pau Monné" <roger.pau@citrix.com>
Subject: [PATCH 04/11] virtio_blk: fix the discard_granularity and discard_alignment queue limits
Date: Mon, 18 Apr 2022 06:53:07 +0200	[thread overview]
Message-ID: <20220418045314.360785-5-hch@lst.de> (raw)
In-Reply-To: <20220418045314.360785-1-hch@lst.de>

The discard_alignment queue limit is named a bit misleading means the
offset into the block device at which the discard granularity starts.

On the other hand the discard_sector_alignment from the virtio 1.1 looks
similar to what Linux uses as discard granularity (even if not very well
described):

  "discard_sector_alignment can be used by OS when splitting a request
   based on alignment. "

And at least qemu does set it to the discard granularity.

So stop setting the discard_alignment and use the virtio
discard_sector_alignment to set the discard granularity.

Fixes: 1f23816b8eb8 ("virtio_blk: add discard and write zeroes support")
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/block/virtio_blk.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 6ccf15253dee1..d624cc8eddc3c 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -867,11 +867,12 @@ static int virtblk_probe(struct virtio_device *vdev)
 		blk_queue_io_opt(q, blk_size * opt_io_size);
 
 	if (virtio_has_feature(vdev, VIRTIO_BLK_F_DISCARD)) {
-		q->limits.discard_granularity = blk_size;
-
 		virtio_cread(vdev, struct virtio_blk_config,
 			     discard_sector_alignment, &v);
-		q->limits.discard_alignment = v ? v << SECTOR_SHIFT : 0;
+		if (v)
+			q->limits.discard_granularity = v << SECTOR_SHIFT;
+		else
+			q->limits.discard_granularity = blk_size;
 
 		virtio_cread(vdev, struct virtio_blk_config,
 			     max_discard_sectors, &v);
-- 
2.30.2

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

WARNING: multiple messages have this Message-ID (diff)
From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: "Jan Hoeppner" <hoeppner@linux.ibm.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Jason Wang" <jasowang@redhat.com>,
	linux-nvme@lists.infradead.org,
	virtualization@lists.linux-foundation.org,
	"Song Liu" <song@kernel.org>,
	dm-devel@redhat.com, "Md. Haris Iqbal" <haris.iqbal@ionos.com>,
	"Jack Wang" <jinpu.wang@ionos.com>,
	linux-s390@vger.kernel.org, "Richard Weinberger" <richard@nod.at>,
	xen-devel@lists.xenproject.org, linux-um@lists.infradead.org,
	"Mike Snitzer" <snitzer@kernel.org>,
	"Josef Bacik" <josef@toxicpanda.com>,
	nbd@other.debian.org, linux-block@vger.kernel.org,
	"Stefan Haberland" <sth@linux.ibm.com>,
	linux-raid@vger.kernel.org,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	"Johannes Berg" <johannes@sipsolutions.net>,
	"Roger Pau Monné" <roger.pau@citrix.com>
Subject: [dm-devel] [PATCH 04/11] virtio_blk: fix the discard_granularity and discard_alignment queue limits
Date: Mon, 18 Apr 2022 06:53:07 +0200	[thread overview]
Message-ID: <20220418045314.360785-5-hch@lst.de> (raw)
In-Reply-To: <20220418045314.360785-1-hch@lst.de>

The discard_alignment queue limit is named a bit misleading means the
offset into the block device at which the discard granularity starts.

On the other hand the discard_sector_alignment from the virtio 1.1 looks
similar to what Linux uses as discard granularity (even if not very well
described):

  "discard_sector_alignment can be used by OS when splitting a request
   based on alignment. "

And at least qemu does set it to the discard granularity.

So stop setting the discard_alignment and use the virtio
discard_sector_alignment to set the discard granularity.

Fixes: 1f23816b8eb8 ("virtio_blk: add discard and write zeroes support")
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/block/virtio_blk.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 6ccf15253dee1..d624cc8eddc3c 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -867,11 +867,12 @@ static int virtblk_probe(struct virtio_device *vdev)
 		blk_queue_io_opt(q, blk_size * opt_io_size);
 
 	if (virtio_has_feature(vdev, VIRTIO_BLK_F_DISCARD)) {
-		q->limits.discard_granularity = blk_size;
-
 		virtio_cread(vdev, struct virtio_blk_config,
 			     discard_sector_alignment, &v);
-		q->limits.discard_alignment = v ? v << SECTOR_SHIFT : 0;
+		if (v)
+			q->limits.discard_granularity = v << SECTOR_SHIFT;
+		else
+			q->limits.discard_granularity = blk_size;
 
 		virtio_cread(vdev, struct virtio_blk_config,
 			     max_discard_sectors, &v);
-- 
2.30.2

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


WARNING: multiple messages have this Message-ID (diff)
From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: "Richard Weinberger" <richard@nod.at>,
	"Johannes Berg" <johannes@sipsolutions.net>,
	"Josef Bacik" <josef@toxicpanda.com>,
	"Md. Haris Iqbal" <haris.iqbal@ionos.com>,
	"Jack Wang" <jinpu.wang@ionos.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Jason Wang" <jasowang@redhat.com>,
	"Roger Pau Monné" <roger.pau@citrix.com>,
	"Mike Snitzer" <snitzer@kernel.org>, "Song Liu" <song@kernel.org>,
	"Stefan Haberland" <sth@linux.ibm.com>,
	"Jan Hoeppner" <hoeppner@linux.ibm.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	linux-um@lists.infradead.org, linux-block@vger.kernel.org,
	nbd@other.debian.org, virtualization@lists.linux-foundation.org,
	xen-devel@lists.xenproject.org, linux-raid@vger.kernel.org,
	linux-nvme@lists.infradead.org, linux-s390@vger.kernel.org,
	dm-devel@redhat.com
Subject: [PATCH 04/11] virtio_blk: fix the discard_granularity and discard_alignment queue limits
Date: Mon, 18 Apr 2022 06:53:07 +0200	[thread overview]
Message-ID: <20220418045314.360785-5-hch@lst.de> (raw)
In-Reply-To: <20220418045314.360785-1-hch@lst.de>

The discard_alignment queue limit is named a bit misleading means the
offset into the block device at which the discard granularity starts.

On the other hand the discard_sector_alignment from the virtio 1.1 looks
similar to what Linux uses as discard granularity (even if not very well
described):

  "discard_sector_alignment can be used by OS when splitting a request
   based on alignment. "

And at least qemu does set it to the discard granularity.

So stop setting the discard_alignment and use the virtio
discard_sector_alignment to set the discard granularity.

Fixes: 1f23816b8eb8 ("virtio_blk: add discard and write zeroes support")
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/block/virtio_blk.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 6ccf15253dee1..d624cc8eddc3c 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -867,11 +867,12 @@ static int virtblk_probe(struct virtio_device *vdev)
 		blk_queue_io_opt(q, blk_size * opt_io_size);
 
 	if (virtio_has_feature(vdev, VIRTIO_BLK_F_DISCARD)) {
-		q->limits.discard_granularity = blk_size;
-
 		virtio_cread(vdev, struct virtio_blk_config,
 			     discard_sector_alignment, &v);
-		q->limits.discard_alignment = v ? v << SECTOR_SHIFT : 0;
+		if (v)
+			q->limits.discard_granularity = v << SECTOR_SHIFT;
+		else
+			q->limits.discard_granularity = blk_size;
 
 		virtio_cread(vdev, struct virtio_blk_config,
 			     max_discard_sectors, &v);
-- 
2.30.2


_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um


  parent reply	other threads:[~2022-04-18  4:53 UTC|newest]

Thread overview: 99+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-18  4:53 fix and cleanup discard_alignment handling Christoph Hellwig
2022-04-18  4:53 ` Christoph Hellwig
2022-04-18  4:53 ` [dm-devel] " Christoph Hellwig
2022-04-18  4:53 ` Christoph Hellwig
2022-04-18  4:53 ` [PATCH 01/11] ubd: don't set the discard_alignment queue limit Christoph Hellwig
2022-04-18  4:53   ` Christoph Hellwig
2022-04-18  4:53   ` [dm-devel] " Christoph Hellwig
2022-04-18  4:53   ` Christoph Hellwig
2022-04-18  4:53 ` [PATCH 02/11] nbd: " Christoph Hellwig
2022-04-18  4:53   ` Christoph Hellwig
2022-04-18  4:53   ` [dm-devel] " Christoph Hellwig
2022-04-18  4:53   ` Christoph Hellwig
2022-04-18  4:53 ` [PATCH 03/11] null_blk: " Christoph Hellwig
2022-04-18  4:53   ` Christoph Hellwig
2022-04-18  4:53   ` [dm-devel] " Christoph Hellwig
2022-04-18  4:53   ` Christoph Hellwig
2022-04-18  8:01   ` [dm-devel] " Damien Le Moal
2022-04-18  8:01     ` Damien Le Moal
2022-04-18  8:01     ` Damien Le Moal
2022-04-18 21:22   ` Chaitanya Kulkarni
2022-04-18 21:22     ` Chaitanya Kulkarni
2022-04-18 21:22     ` [dm-devel] " Chaitanya Kulkarni
2022-04-18  4:53 ` Christoph Hellwig [this message]
2022-04-18  4:53   ` [PATCH 04/11] virtio_blk: fix the discard_granularity and discard_alignment queue limits Christoph Hellwig
2022-04-18  4:53   ` [dm-devel] " Christoph Hellwig
2022-04-18  4:53   ` Christoph Hellwig
2022-04-18  4:53 ` [PATCH 05/11] dm-zoned: don't set the discard_alignment queue limit Christoph Hellwig
2022-04-18  4:53   ` Christoph Hellwig
2022-04-18  4:53   ` [dm-devel] " Christoph Hellwig
2022-04-18  4:53   ` Christoph Hellwig
2022-04-18  8:00   ` [dm-devel] " Damien Le Moal
2022-04-18  8:00     ` Damien Le Moal
2022-04-18  8:00     ` Damien Le Moal
2022-04-18  4:53 ` [PATCH 06/11] raid5: " Christoph Hellwig
2022-04-18  4:53   ` Christoph Hellwig
2022-04-18  4:53   ` [dm-devel] " Christoph Hellwig
2022-04-18  4:53   ` Christoph Hellwig
2022-04-25 21:08   ` Song Liu
2022-04-25 21:08     ` Song Liu
2022-04-25 21:08     ` [dm-devel] " Song Liu
2022-04-18  4:53 ` [PATCH 07/11] dasd: " Christoph Hellwig
2022-04-18  4:53   ` Christoph Hellwig
2022-04-18  4:53   ` [dm-devel] " Christoph Hellwig
2022-04-18  4:53   ` Christoph Hellwig
2022-05-06 12:56   ` Jan Höppner
2022-05-06 12:56     ` Jan Höppner
2022-05-06 12:56     ` [dm-devel] " Jan Höppner
2022-04-18  4:53 ` [PATCH 08/11] loop: remove a spurious clear of discard_alignment Christoph Hellwig
2022-04-18  4:53   ` Christoph Hellwig
2022-04-18  4:53   ` [dm-devel] " Christoph Hellwig
2022-04-18  4:53   ` Christoph Hellwig
2022-04-18  8:04   ` [dm-devel] " Damien Le Moal
2022-04-18  8:04     ` Damien Le Moal
2022-04-18  8:04     ` Damien Le Moal
2022-04-18 21:21   ` Chaitanya Kulkarni
2022-04-18 21:21     ` Chaitanya Kulkarni
2022-04-18 21:21     ` [dm-devel] " Chaitanya Kulkarni
2022-04-18  4:53 ` [PATCH 09/11] nvme: " Christoph Hellwig
2022-04-18  4:53   ` Christoph Hellwig
2022-04-18  4:53   ` [dm-devel] " Christoph Hellwig
2022-04-18  4:53   ` Christoph Hellwig
2022-04-18  8:02   ` [dm-devel] " Damien Le Moal
2022-04-18  8:02     ` Damien Le Moal
2022-04-18  8:02     ` Damien Le Moal
2022-04-18 21:23   ` Chaitanya Kulkarni
2022-04-18 21:23     ` Chaitanya Kulkarni
2022-04-18 21:23     ` [dm-devel] " Chaitanya Kulkarni
2022-04-26 14:25   ` Sagi Grimberg
2022-04-26 14:25     ` Sagi Grimberg
2022-04-26 14:25     ` [dm-devel] " Sagi Grimberg
2022-04-18  4:53 ` [PATCH 10/11] rnbd-srv: use bdev_discard_alignment Christoph Hellwig
2022-04-18  4:53   ` Christoph Hellwig
2022-04-18  4:53   ` [dm-devel] " Christoph Hellwig
2022-04-18  4:53   ` Christoph Hellwig
2022-04-18  8:02   ` [dm-devel] " Damien Le Moal
2022-04-18  8:02     ` Damien Le Moal
2022-04-18  8:02     ` Damien Le Moal
2022-04-19  4:51   ` Jinpu Wang
2022-04-19  4:51     ` Jinpu Wang
2022-04-19  4:51     ` [dm-devel] " Jinpu Wang
2022-04-18  4:53 ` [PATCH 11/11] xen-blkback: " Christoph Hellwig
2022-04-18  4:53   ` Christoph Hellwig
2022-04-18  4:53   ` [dm-devel] " Christoph Hellwig
2022-04-18  4:53   ` Christoph Hellwig
2022-04-18  8:03   ` [dm-devel] " Damien Le Moal
2022-04-18  8:03     ` Damien Le Moal
2022-04-18  8:03     ` Damien Le Moal
2022-04-26  4:16 ` fix and cleanup discard_alignment handling Martin K. Petersen
2022-04-26  4:16   ` Martin K. Petersen
2022-04-26  4:16   ` [dm-devel] " Martin K. Petersen
2022-04-26  4:16   ` Martin K. Petersen
2022-05-02 16:46 ` Christoph Hellwig
2022-05-02 16:46   ` Christoph Hellwig
2022-05-02 16:46   ` [dm-devel] " Christoph Hellwig
2022-05-02 16:46   ` Christoph Hellwig
2022-05-03 16:39 ` Jens Axboe
2022-05-03 16:39   ` Jens Axboe
2022-05-03 16:39   ` [dm-devel] " Jens Axboe
2022-05-03 16:39   ` Jens Axboe

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=20220418045314.360785-5-hch@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=dm-devel@redhat.com \
    --cc=haris.iqbal@ionos.com \
    --cc=hoeppner@linux.ibm.com \
    --cc=jasowang@redhat.com \
    --cc=jinpu.wang@ionos.com \
    --cc=johannes@sipsolutions.net \
    --cc=josef@toxicpanda.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=linux-um@lists.infradead.org \
    --cc=martin.petersen@oracle.com \
    --cc=mst@redhat.com \
    --cc=nbd@other.debian.org \
    --cc=richard@nod.at \
    --cc=roger.pau@citrix.com \
    --cc=snitzer@kernel.org \
    --cc=song@kernel.org \
    --cc=sth@linux.ibm.com \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=xen-devel@lists.xenproject.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.