[PATCH v4 00/19] ublk: add support for integrity data

Caleb Sander Mateos posted 19 patches 4 weeks, 1 day ago
drivers/block/ublk_drv.c                     | 358 +++++++++++++------
include/linux/blk-integrity.h                |   6 +-
include/uapi/linux/ublk_cmd.h                |  25 ++
tools/testing/selftests/ublk/Makefile        |   7 +-
tools/testing/selftests/ublk/common.c        |   4 +-
tools/testing/selftests/ublk/fault_inject.c  |   1 +
tools/testing/selftests/ublk/file_backed.c   |  90 ++++-
tools/testing/selftests/ublk/kublk.c         |  90 ++++-
tools/testing/selftests/ublk/kublk.h         |  37 +-
tools/testing/selftests/ublk/metadata_size.c |  36 ++
tools/testing/selftests/ublk/null.c          |   1 +
tools/testing/selftests/ublk/stripe.c        |   6 +-
tools/testing/selftests/ublk/test_common.sh  |  10 +
tools/testing/selftests/ublk/test_loop_08.sh | 111 ++++++
tools/testing/selftests/ublk/test_null_04.sh | 166 +++++++++
15 files changed, 817 insertions(+), 131 deletions(-)
create mode 100644 tools/testing/selftests/ublk/metadata_size.c
create mode 100755 tools/testing/selftests/ublk/test_loop_08.sh
create mode 100755 tools/testing/selftests/ublk/test_null_04.sh
[PATCH v4 00/19] ublk: add support for integrity data
Posted by Caleb Sander Mateos 4 weeks, 1 day ago
Much work has recently gone into supporting block device integrity data
(sometimes called "metadata") in Linux. Many NVMe devices these days
support metadata transfers and/or automatic protection information
generation and verification. However, ublk devices can't yet advertise
integrity data capabilities. This patch series wires up support for
integrity data in ublk. The ublk feature is referred to as "integrity"
rather than "metadata" to match the block layer's name for it and to
avoid confusion with the existing and unrelated UBLK_IO_F_META.

To advertise support for integrity data, a ublk server fills out the
struct ublk_params's integrity field and sets UBLK_PARAM_TYPE_INTEGRITY.
The struct ublk_param_integrity flags and csum_type fields use the
existing LBMD_PI_* constants from the linux/fs.h UAPI header. The ublk
driver fills out a corresponding struct blk_integrity.

When a request with integrity data is issued to the ublk device, the
ublk driver sets UBLK_IO_F_INTEGRITY in struct ublksrv_io_desc's
op_flags field. This is necessary for a ublk server for which
bi_offload_capable() returns true to distinguish requests with integrity
data from those without.

Integrity data transfers can currently only be performed via the ublk
user copy mechanism. The overhead of zero-copy buffer registration makes
it less appealing for the small transfers typical of integrity data.
Additionally, neither io_uring NVMe passthru nor IORING_RW_ATTR_FLAG_PI
currently allow an io_uring registered buffer for the integrity data.
The ki_pos field of the struct kiocb passed to the user copy
->{read,write}_iter() callback gains a bit UBLKSRV_IO_INTEGRITY_FLAG for
a ublk server to indicate whether to access the request's data or
integrity data.

Not yet supported is an analogue for the IO_INTEGRITY_CHK_*/BIP_CHECK_*
flags to ask the ublk server to verify the guard, reftag, and/or apptag
of a request's protection information. The user copy mechanism currently
forbids a ublk server from reading the data/integrity buffer of a
read-direction request. We could potentially relax this restriction for
integrity data on reads. Alternatively, the ublk driver could verify the
requested fields as part of the user copy operation.

v4:
- Add max_integrity_segments to struct ublk_param_integrity (Ming)
- Move UBLKSRV_IO_INTEGRITY_FLAG to avoid overflow from
  QID + UBLKSRV_IO_BUF_OFFSET (Ming)
- Check UBLK_F_INTEGRITY when UBLKSRV_IO_INTEGRITY_FLAG is used (Ming)
- Initialize integrity backing file to disable integrity checks (Ming)

v3:
- Drop support for communicating BIP_CHECK_* for now until the interface
 is decided
- Add Reviewed-by tags

v2:
- Communicate BIP_CHECK_* flags and expected reftag seed and app tag to
  ublk server
- Add UBLK_F_INTEGRITY feature flag (Ming)
- Don't change the definition of UBLKSRV_IO_BUF_TOTAL_BITS (Ming)
- Drop patches already applied
- Add Reviewed-by tags

Caleb Sander Mateos (16):
  blk-integrity: take const pointer in blk_integrity_rq()
  ublk: move ublk flag check functions earlier
  ublk: set UBLK_IO_F_INTEGRITY in ublksrv_io_desc
  ublk: split out ublk_copy_user_bvec() helper
  ublk: split out ublk_user_copy() helper
  ublk: inline ublk_check_and_get_req() into ublk_user_copy()
  ublk: move offset check out of __ublk_check_and_get_req()
  ublk: optimize ublk_user_copy() on daemon task
  selftests: ublk: display UBLK_F_INTEGRITY support
  selftests: ublk: add utility to get block device metadata size
  selftests: ublk: add kublk support for integrity params
  selftests: ublk: implement integrity user copy in kublk
  selftests: ublk: support non-O_DIRECT backing files
  selftests: ublk: add integrity data support to loop target
  selftests: ublk: add integrity params test
  selftests: ublk: add end-to-end integrity test

Stanley Zhang (3):
  ublk: support UBLK_PARAM_TYPE_INTEGRITY in device creation
  ublk: implement integrity user copy
  ublk: support UBLK_F_INTEGRITY

 drivers/block/ublk_drv.c                     | 358 +++++++++++++------
 include/linux/blk-integrity.h                |   6 +-
 include/uapi/linux/ublk_cmd.h                |  25 ++
 tools/testing/selftests/ublk/Makefile        |   7 +-
 tools/testing/selftests/ublk/common.c        |   4 +-
 tools/testing/selftests/ublk/fault_inject.c  |   1 +
 tools/testing/selftests/ublk/file_backed.c   |  90 ++++-
 tools/testing/selftests/ublk/kublk.c         |  90 ++++-
 tools/testing/selftests/ublk/kublk.h         |  37 +-
 tools/testing/selftests/ublk/metadata_size.c |  36 ++
 tools/testing/selftests/ublk/null.c          |   1 +
 tools/testing/selftests/ublk/stripe.c        |   6 +-
 tools/testing/selftests/ublk/test_common.sh  |  10 +
 tools/testing/selftests/ublk/test_loop_08.sh | 111 ++++++
 tools/testing/selftests/ublk/test_null_04.sh | 166 +++++++++
 15 files changed, 817 insertions(+), 131 deletions(-)
 create mode 100644 tools/testing/selftests/ublk/metadata_size.c
 create mode 100755 tools/testing/selftests/ublk/test_loop_08.sh
 create mode 100755 tools/testing/selftests/ublk/test_null_04.sh

-- 
2.45.2
Re: [PATCH v4 00/19] ublk: add support for integrity data
Posted by Jens Axboe 3 weeks, 4 days ago
On Thu, 08 Jan 2026 02:19:28 -0700, Caleb Sander Mateos wrote:
> Much work has recently gone into supporting block device integrity data
> (sometimes called "metadata") in Linux. Many NVMe devices these days
> support metadata transfers and/or automatic protection information
> generation and verification. However, ublk devices can't yet advertise
> integrity data capabilities. This patch series wires up support for
> integrity data in ublk. The ublk feature is referred to as "integrity"
> rather than "metadata" to match the block layer's name for it and to
> avoid confusion with the existing and unrelated UBLK_IO_F_META.
> 
> [...]

Applied, thanks!

[01/19] blk-integrity: take const pointer in blk_integrity_rq()
        commit: 835042fb1971b1cc6acb46d53b8862643fd7d0a8
[02/19] ublk: move ublk flag check functions earlier
        commit: e859e7c26a5c4689083f161a52d039b9b454e403
[03/19] ublk: support UBLK_PARAM_TYPE_INTEGRITY in device creation
        commit: 98bf2256855eb682433a33e6a7c4bce35191ca99
[04/19] ublk: set UBLK_IO_F_INTEGRITY in ublksrv_io_desc
        commit: f82f0a16a8270b17211254beeb123d11a0f279cd
[05/19] ublk: split out ublk_copy_user_bvec() helper
        commit: fc652d415cd8b45e9a534d1c019da175cca4c95a
[06/19] ublk: split out ublk_user_copy() helper
        commit: 5bfbbc9938f5dee7f252ef05f47b9a26f05f281a
[07/19] ublk: inline ublk_check_and_get_req() into ublk_user_copy()
        commit: ca80afd8708fa22f6d3a1e0306ae12a64e5291b5
[08/19] ublk: move offset check out of __ublk_check_and_get_req()
        commit: fd5a005fa6a261762292a2d89ef8d0174b66f541
[09/19] ublk: implement integrity user copy
        commit: be82a89066d595da334f6e153ababcedc3f92ad6
[10/19] ublk: support UBLK_F_INTEGRITY
        commit: b2503e936b598b993cb09005194dc77d2fa3f082
[11/19] ublk: optimize ublk_user_copy() on daemon task
        commit: bfe1255712a3b1c1f7418c5504a1bf53735d3848
[12/19] selftests: ublk: display UBLK_F_INTEGRITY support
        commit: c1d7c0f9cdf6690eff4518f1c17a37d5ee647cd1
[13/19] selftests: ublk: add utility to get block device metadata size
        commit: 261b67f4e34716e793b0b95d2722b2fe780ed5f4
[14/19] selftests: ublk: add kublk support for integrity params
        commit: 6ed6476c4aefa9ee3ba90f39bcc002dd034f6e03
[15/19] selftests: ublk: implement integrity user copy in kublk
        commit: 24f8a44b797f03dfadb455138930523599d3c22a
[16/19] selftests: ublk: support non-O_DIRECT backing files
        commit: a1805442674b85ff9d626965f828e4fd71a82b28
[17/19] selftests: ublk: add integrity data support to loop target
        commit: f48250dc5ba8368ccb587093eb20d1c7baecaacf
[18/19] selftests: ublk: add integrity params test
        commit: 9e9f635525b12f055558a7cfe2e54d109839d030
[19/19] selftests: ublk: add end-to-end integrity test
        commit: 78796b6bae8684b753b658f431b5b1ee24300d64

Best regards,
-- 
Jens Axboe
Re: [PATCH v4 00/19] ublk: add support for integrity data
Posted by Ming Lei 3 weeks, 4 days ago
On Thu, Jan 08, 2026 at 02:19:28AM -0700, Caleb Sander Mateos wrote:
> Much work has recently gone into supporting block device integrity data
> (sometimes called "metadata") in Linux. Many NVMe devices these days
> support metadata transfers and/or automatic protection information
> generation and verification. However, ublk devices can't yet advertise
> integrity data capabilities. This patch series wires up support for
> integrity data in ublk. The ublk feature is referred to as "integrity"
> rather than "metadata" to match the block layer's name for it and to
> avoid confusion with the existing and unrelated UBLK_IO_F_META.
> 
> To advertise support for integrity data, a ublk server fills out the
> struct ublk_params's integrity field and sets UBLK_PARAM_TYPE_INTEGRITY.
> The struct ublk_param_integrity flags and csum_type fields use the
> existing LBMD_PI_* constants from the linux/fs.h UAPI header. The ublk
> driver fills out a corresponding struct blk_integrity.
> 
> When a request with integrity data is issued to the ublk device, the
> ublk driver sets UBLK_IO_F_INTEGRITY in struct ublksrv_io_desc's
> op_flags field. This is necessary for a ublk server for which
> bi_offload_capable() returns true to distinguish requests with integrity
> data from those without.
> 
> Integrity data transfers can currently only be performed via the ublk
> user copy mechanism. The overhead of zero-copy buffer registration makes
> it less appealing for the small transfers typical of integrity data.
> Additionally, neither io_uring NVMe passthru nor IORING_RW_ATTR_FLAG_PI
> currently allow an io_uring registered buffer for the integrity data.
> The ki_pos field of the struct kiocb passed to the user copy
> ->{read,write}_iter() callback gains a bit UBLKSRV_IO_INTEGRITY_FLAG for
> a ublk server to indicate whether to access the request's data or
> integrity data.
> 
> Not yet supported is an analogue for the IO_INTEGRITY_CHK_*/BIP_CHECK_*
> flags to ask the ublk server to verify the guard, reftag, and/or apptag
> of a request's protection information. The user copy mechanism currently
> forbids a ublk server from reading the data/integrity buffer of a
> read-direction request. We could potentially relax this restriction for
> integrity data on reads. Alternatively, the ublk driver could verify the
> requested fields as part of the user copy operation.
> 
> v4:
> - Add max_integrity_segments to struct ublk_param_integrity (Ming)
> - Move UBLKSRV_IO_INTEGRITY_FLAG to avoid overflow from
>   QID + UBLKSRV_IO_BUF_OFFSET (Ming)
> - Check UBLK_F_INTEGRITY when UBLKSRV_IO_INTEGRITY_FLAG is used (Ming)
> - Initialize integrity backing file to disable integrity checks (Ming)
 
Hi Jens,

Can you consider to queue V4 into for-7.0/block if you are fine? So I can rebase
my BATCH_IO patchset against this one.

Thanks,
Ming