Linux block layer
 help / color / mirror / Atom feed
* [PATCH v3] block: fix lbmd_guard_tag_type assignment in FS_IOC_GETLBMD_CAP
       [not found] <CGME20250722120822epcas5p100667bdb8c199361a66dcef2ae09fdd1@epcas5p1.samsung.com>
@ 2025-07-22 12:07 ` Anuj Gupta
  2025-07-23 12:56   ` Christian Brauner
  0 siblings, 1 reply; 2+ messages in thread
From: Anuj Gupta @ 2025-07-22 12:07 UTC (permalink / raw)
  To: vincent.fu, anuj1072538, axboe, hch, martin.petersen, viro,
	brauner, jack
  Cc: linux-fsdevel, linux-block, joshi.k, Anuj Gupta,
	Christoph Hellwig

The blk_get_meta_cap() implementation directly assigns bi->csum_type to
the UAPI field lbmd_guard_tag_type. This is not right as the kernel enum
blk_integrity_checksum values are not guaranteed to match the UAPI
defined values.

Fix this by explicitly mapping internal checksum types to UAPI-defined
constants to ensure compatibility and correctness, especially for the
devices using CRC64 PI.

Fixes: 9eb22f7fedfc ("fs: add ioctl to query metadata and protection info capabilities")
Reported-by: Vincent Fu <vincent.fu@samsung.com>
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Jens Axboe <axboe@kernel.dk>
---
 block/blk-integrity.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/block/blk-integrity.c b/block/blk-integrity.c
index 61a79e19c78f..056b8948369d 100644
--- a/block/blk-integrity.c
+++ b/block/blk-integrity.c
@@ -83,7 +83,21 @@ int blk_get_meta_cap(struct block_device *bdev, unsigned int cmd,
 	if (meta_cap.lbmd_opaque_size && !bi->pi_offset)
 		meta_cap.lbmd_opaque_offset = bi->pi_tuple_size;
 
-	meta_cap.lbmd_guard_tag_type = bi->csum_type;
+	switch (bi->csum_type) {
+	case BLK_INTEGRITY_CSUM_NONE:
+		meta_cap.lbmd_guard_tag_type = LBMD_PI_CSUM_NONE;
+		break;
+	case BLK_INTEGRITY_CSUM_IP:
+		meta_cap.lbmd_guard_tag_type = LBMD_PI_CSUM_IP;
+		break;
+	case BLK_INTEGRITY_CSUM_CRC:
+		meta_cap.lbmd_guard_tag_type = LBMD_PI_CSUM_CRC16_T10DIF;
+		break;
+	case BLK_INTEGRITY_CSUM_CRC64:
+		meta_cap.lbmd_guard_tag_type = LBMD_PI_CSUM_CRC64_NVME;
+		break;
+	}
+
 	if (bi->csum_type != BLK_INTEGRITY_CSUM_NONE)
 		meta_cap.lbmd_app_tag_size = 2;
 
-- 
2.25.1


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

* Re: [PATCH v3] block: fix lbmd_guard_tag_type assignment in FS_IOC_GETLBMD_CAP
  2025-07-22 12:07 ` [PATCH v3] block: fix lbmd_guard_tag_type assignment in FS_IOC_GETLBMD_CAP Anuj Gupta
@ 2025-07-23 12:56   ` Christian Brauner
  0 siblings, 0 replies; 2+ messages in thread
From: Christian Brauner @ 2025-07-23 12:56 UTC (permalink / raw)
  To: Anuj Gupta
  Cc: Christian Brauner, linux-fsdevel, linux-block, joshi.k,
	Christoph Hellwig, vincent.fu, anuj1072538, axboe, hch,
	martin.petersen, viro, jack

On Tue, 22 Jul 2025 17:37:55 +0530, Anuj Gupta wrote:
> The blk_get_meta_cap() implementation directly assigns bi->csum_type to
> the UAPI field lbmd_guard_tag_type. This is not right as the kernel enum
> blk_integrity_checksum values are not guaranteed to match the UAPI
> defined values.
> 
> Fix this by explicitly mapping internal checksum types to UAPI-defined
> constants to ensure compatibility and correctness, especially for the
> devices using CRC64 PI.
> 
> [...]

Applied to the vfs-6.17.integrity branch of the vfs/vfs.git tree.
Patches in the vfs-6.17.integrity branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-6.17.integrity

[1/1] block: fix lbmd_guard_tag_type assignment in FS_IOC_GETLBMD_CAP
      https://git.kernel.org/vfs/vfs/c/bc5b0c8febcc

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

end of thread, other threads:[~2025-07-23 12:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CGME20250722120822epcas5p100667bdb8c199361a66dcef2ae09fdd1@epcas5p1.samsung.com>
2025-07-22 12:07 ` [PATCH v3] block: fix lbmd_guard_tag_type assignment in FS_IOC_GETLBMD_CAP Anuj Gupta
2025-07-23 12:56   ` Christian Brauner

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