From a73409f6be35b0505330585e09422225d23bdc27 Mon Sep 17 00:00:00 2001 From: Shin'ichiro Kawasaki Date: Mon, 9 Jun 2025 20:58:35 +0900 Subject: [PATCH 1/3] adding ci files --- .github/workflows/kernel_build.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/kernel_build.yml diff --git a/.github/workflows/kernel_build.yml b/.github/workflows/kernel_build.yml new file mode 100644 index 0000000000000..cd0f9d145429c --- /dev/null +++ b/.github/workflows/kernel_build.yml @@ -0,0 +1,28 @@ +name: blktests-ci + +on: + pull_request: + +jobs: + build-kernel: + runs-on: ubuntu-latest + steps: + - name: Configure git + run: | + git config --global --add safe.directory '*' + - name: Checkout git + run: | + sudo apt-get install -y libelf-dev + mkdir -p linux + cd linux + git init + git remote add origin https://github.com/${{ github.repository }} + git fetch origin --depth=5 ${{ github.event.pull_request.head.sha }} + git reset --hard ${{ github.event.pull_request.head.sha }} + git log -1 + - name: Build kernel + run: | + cd linux + make defconfig + make -j 8 + From 76c7c44930e0156553772fbc3b1dc3fc6f16d389 Mon Sep 17 00:00:00 2001 From: Anuj Gupta Date: Thu, 5 Jun 2025 20:37:28 +0530 Subject: [PATCH 2/3] block: introduce pi_size field in blk_integrity Introduce a new pi_size field in struct blk_integrity to explicitly represent the size (in bytes) of the protection information (PI) tuple. This is a prep patch. Signed-off-by: Anuj Gupta Reviewed-by: Martin K. Petersen --- drivers/nvme/host/core.c | 1 + drivers/scsi/sd_dif.c | 1 + include/linux/blkdev.h | 1 + 3 files changed, 3 insertions(+) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 92697f98c601d..8eef2af1ccf5f 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1867,6 +1867,7 @@ static bool nvme_init_integrity(struct nvme_ns_head *head, } bi->tuple_size = head->ms; + bi->pi_size = head->pi_size; bi->pi_offset = info->pi_offset; return true; } diff --git a/drivers/scsi/sd_dif.c b/drivers/scsi/sd_dif.c index ae6ce6f5d622d..9c39a82298da5 100644 --- a/drivers/scsi/sd_dif.c +++ b/drivers/scsi/sd_dif.c @@ -53,6 +53,7 @@ void sd_dif_config_host(struct scsi_disk *sdkp, struct queue_limits *lim) bi->flags |= BLK_INTEGRITY_REF_TAG; bi->tuple_size = sizeof(struct t10_pi_tuple); + bi->pi_size = bi->tuple_size; if (dif && type) { bi->flags |= BLK_INTEGRITY_DEVICE_CAPABLE; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 332b56f323d92..1ed604b70e0f7 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -120,6 +120,7 @@ struct blk_integrity { unsigned char pi_offset; unsigned char interval_exp; unsigned char tag_size; + unsigned char pi_size; }; typedef unsigned int __bitwise blk_mode_t; From 2ad65c90da5a408e82df58754f21aad4f29d8a64 Mon Sep 17 00:00:00 2001 From: Anuj Gupta Date: Thu, 5 Jun 2025 20:37:29 +0530 Subject: [PATCH 3/3] fs: add ioctl to query protection info capabilities Add a new ioctl, FS_IOC_GETPICAP, to query protection info (PI) capabilities. This ioctl returns information about the files integrity profile. This is useful for userspace applications to understand a files end-to-end data protection support and configure the I/O accordingly. For now this interface is only supported by block devices. However the design and placement of this ioctl in generic FS ioctl space allows us to extend it to work over files as well. This maybe useful when filesystems start supporting PI-aware layouts. A new structure struct fs_pi_cap is introduced, which contains the following fields: 1. fpc_flags: bitmask of capability flags. 2. fpc_interval: the data block interval (in bytes) for which the protection information is generated. 3. fpc_csum type: type of checksum used. 4. fpc_metadata_size: size (in bytes) of the metadata associated with each interval. 5. fpc_pi_size: size (in bytes) of the PI associated with each interval. 6. fpc_tag_size: size (in bytes) of tag information. 7. pi_offset: offset of protection information tuple within the metadata. 8. fpc_ref_tag_size: size in bytes of the reference tag. 9. fpc_storage_tag_size: size in bytes of the storage tag. 10. fpc_rsvd: reserved for future use. The internal logic to fetch the capability is encapsulated in a helper function blk_get_pi_cap(), which uses the blk_integrity profile associated with the device. The ioctl returns -EOPNOTSUPP, if CONFIG_BLK_DEV_INTEGRITY is not enabled. Signed-off-by: Anuj Gupta Signed-off-by: Kanchan Joshi --- block/blk-integrity.c | 41 +++++++++++++++++++++++++++++++++++ block/ioctl.c | 3 +++ include/linux/blk-integrity.h | 6 +++++ include/uapi/linux/fs.h | 38 ++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+) diff --git a/block/blk-integrity.c b/block/blk-integrity.c index e4e2567061f9d..8f2c3a0173280 100644 --- a/block/blk-integrity.c +++ b/block/blk-integrity.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "blk.h" @@ -54,6 +55,46 @@ int blk_rq_count_integrity_sg(struct request_queue *q, struct bio *bio) return segments; } +int blk_get_pi_cap(struct block_device *bdev, struct fs_pi_cap __user *argp) +{ + struct blk_integrity *bi = blk_get_integrity(bdev->bd_disk); + struct fs_pi_cap pi_cap = {}; + + if (!bi) + goto out; + + if (bi->flags & BLK_INTEGRITY_DEVICE_CAPABLE) + pi_cap.fpc_flags |= FILE_PI_CAP_INTEGRITY; + if (bi->flags & BLK_INTEGRITY_REF_TAG) + pi_cap.fpc_flags |= FILE_PI_CAP_REFTAG; + pi_cap.fpc_csum_type = bi->csum_type; + pi_cap.fpc_metadata_size = bi->tuple_size; + pi_cap.fpc_tag_size = bi->tag_size; + pi_cap.fpc_interval = 1 << bi->interval_exp; + pi_cap.fpc_pi_offset = bi->pi_offset; + pi_cap.fpc_pi_size = bi->pi_size; + if (bi->flags & BLK_INTEGRITY_REF_TAG) { + switch (bi->csum_type) { + case BLK_INTEGRITY_CSUM_CRC64: + pi_cap.fpc_ref_tag_size = + sizeof_field(struct crc64_pi_tuple, ref_tag); + break; + case BLK_INTEGRITY_CSUM_CRC: + case BLK_INTEGRITY_CSUM_IP: + pi_cap.fpc_ref_tag_size = + sizeof_field(struct t10_pi_tuple, ref_tag); + break; + default: + break; + } + } + +out: + if (copy_to_user(argp, &pi_cap, sizeof(struct fs_pi_cap))) + return -EFAULT; + return 0; +} + /** * blk_rq_map_integrity_sg - Map integrity metadata into a scatterlist * @rq: request to map diff --git a/block/ioctl.c b/block/ioctl.c index e472cc1030c60..53b35bf3e6fa6 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "blk.h" #include "blk-crypto-internal.h" @@ -643,6 +644,8 @@ static int blkdev_common_ioctl(struct block_device *bdev, blk_mode_t mode, return blkdev_pr_preempt(bdev, mode, argp, true); case IOC_PR_CLEAR: return blkdev_pr_clear(bdev, mode, argp); + case FS_IOC_GETPICAP: + return blk_get_pi_cap(bdev, argp); default: return -ENOIOCTLCMD; } diff --git a/include/linux/blk-integrity.h b/include/linux/blk-integrity.h index c7eae0bfb013f..6118a0c28605b 100644 --- a/include/linux/blk-integrity.h +++ b/include/linux/blk-integrity.h @@ -29,6 +29,7 @@ int blk_rq_map_integrity_sg(struct request *, struct scatterlist *); int blk_rq_count_integrity_sg(struct request_queue *, struct bio *); int blk_rq_integrity_map_user(struct request *rq, void __user *ubuf, ssize_t bytes); +int blk_get_pi_cap(struct block_device *bdev, struct fs_pi_cap __user *argp); static inline bool blk_integrity_queue_supports_integrity(struct request_queue *q) @@ -92,6 +93,11 @@ static inline struct bio_vec rq_integrity_vec(struct request *rq) rq->bio->bi_integrity->bip_iter); } #else /* CONFIG_BLK_DEV_INTEGRITY */ +static inline int blk_get_pi_cap(struct block_device *bdev, + struct fs_pi_cap __user *argp) +{ + return -EOPNOTSUPP; +} static inline int blk_rq_count_integrity_sg(struct request_queue *q, struct bio *b) { diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index 0098b0ce8ccb1..5557a4598a38b 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -91,6 +91,42 @@ struct fs_sysfs_path { __u8 name[128]; }; +/* Protection info capability flags */ +#define FILE_PI_CAP_INTEGRITY (1 << 0) +#define FILE_PI_CAP_REFTAG (1 << 1) + +/* Checksum types for Protection Information */ +#define FS_PI_CSUM_NONE 0 +#define FS_PI_CSUM_IP 1 +#define FS_PI_CSUM_CRC16_T10DIF 2 +#define FS_PI_CSUM_CRC64_NVME 3 + +/* + * struct fs_pi_cap - protection information(PI) capability descriptor + * @fpc_flags: Bitmask of capability flags + * @fpc_interval: Number of bytes of data per PI tuple + * @fpc_csum_type: Checksum type + * @fpc_metadata_size: Size in bytes of the metadata associated with each interval + * @fpc_pi_size: Size in bytes of the PI associated with each interval + * @fpc_tag_size: Size of the tag area within the tuple + * @fpc_pi_offset: Offset of protection information tuple within the metadata + * @fpc_ref_tag_size: Size in bytes of the reference tag + * @fpc_storage_tag_size: Size in bytes of the storage tag + * @fpc_rsvd: Reserved for future use + */ +struct fs_pi_cap { + __u32 fpc_flags; + __u16 fpc_interval; + __u8 fpc_csum_type; + __u8 fpc_metadata_size; + __u8 fpc_pi_size; + __u8 fpc_tag_size; + __u8 fpc_pi_offset; + __u8 fpc_ref_tag_size; + __u8 fpc_storage_tag_size; + __u8 fpc_rsvd[19]; +}; + /* extent-same (dedupe) ioctls; these MUST match the btrfs ioctl definitions */ #define FILE_DEDUPE_RANGE_SAME 0 #define FILE_DEDUPE_RANGE_DIFFERS 1 @@ -247,6 +283,8 @@ struct fsxattr { * also /sys/kernel/debug/ for filesystems with debugfs exports */ #define FS_IOC_GETFSSYSFSPATH _IOR(0x15, 1, struct fs_sysfs_path) +/* Get protection info capability details */ +#define FS_IOC_GETPICAP _IOR(0x15, 2, struct fs_pi_cap) /* * Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS)