Re: [PATCH v2] block: only fail dma-buf bios that need block layer PI

From
Pavel Begunkov <asml.silence@gmail.com>
Date
2026-10-30 10:26:11
Also in
io-uring, linux-nvme, lkml
Reply to
Kyle Bader, 2026-10-29
On 10/29/26 15:58, Kyle Bader wrote:
From: Kyle Bader <redacted>

All dma-buf (P2P) I/O to a device with integrity data is rejected
today, at registration and in blk_mq_submit_bio(). Only a bio for which
the block layer generates or verifies PI needs that. The block layer
then walks the bio_vecs, and a dma-buf bio has none.

Reject only those bios, and remove the check at registration. Then a
submitter that attaches its own PI, for example with
IORING_RW_ATTR_FLAG_PI, can do dma-buf I/O to such a device.
Looks good,

Reviewed-by: Pavel Begunkov <asml.silence@gmail.com>

It's also enticing to shove it under the existing
bio_integrity_action() check, but it can be done later.

quoted hunk ↗ jump to hunk
Link: https://lore.kernel.org/all/bbb87d6b-b7a3-487a-8be4-27f3f9ce4a1b@samsung.com/ (local)
Assisted-by: LLM
Reviewed-by: Anuj Gupta <redacted>
Signed-off-by: Kyle Bader <redacted>
---
v2: a shorter commit message (Christoph), and Anuj's Reviewed-by. The
code is the same as in v1, so the tests of v1 still apply.

v1: https://lore.kernel.org/all/20261028181412.1919506-1-kbader@redhat.com/ (local)

  block/blk-mq.c | 9 ++++++++-
  block/fops.c   | 2 --
  2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 7fff1305b..3fc9fdeb3 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -3138,8 +3138,15 @@ void blk_mq_submit_bio(struct bio *bio)
  		goto queue_exit;
  	}
  
+	/*
+	 * The block layer cannot generate or verify PI for a dma-buf bio, as
+	 * that walks the data pages.  Only fail the bio if it needs that, not
+	 * if the submitter attached its own integrity payload or if PI
+	 * generation or verification is turned off for the device.
+	 */
  	if (unlikely(op_is_dmabuf(bio->bi_opf) &&
-		     bdev_has_integrity_csum(bio->bi_bdev))) {
+		     bdev_has_integrity_csum(bio->bi_bdev) &&
+		     (bio_integrity_action(bio) & BI_ACT_CHECK))) {
  		bio_endio_status(bio, BLK_STS_NOTSUPP);
  		goto queue_exit;
  	}
diff --git a/block/fops.c b/block/fops.c
index 01bc8afe3..5c8024011 100644
--- a/block/fops.c
+++ b/block/fops.c
@@ -947,8 +947,6 @@ static int blkdev_init_dma_buf_io_ctx(struct file *file,
  		return -EINVAL;
  	if (!disk->fops->init_dma_buf_io_ctx)
  		return -EOPNOTSUPP;
-	if (bdev_has_integrity_csum(bdev))
-		return -EOPNOTSUPP;
  	return disk->fops->init_dma_buf_io_ctx(bdev, ctx);
  }
  
base-commit: 45b716456dd99488a0cef58482120dc0474aa696
-- 
Pavel Begunkov
Thread (4 messages) 4 messages, 4 authors, last reply 13d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help