[PATCH v2 00/10] Read/Write with meta/integrity
Anuj Gupta
anuj20.g at samsung.com
Wed Jun 26 03:06:50 PDT 2024
This adds a new io_uring interface to exchange meta along with read/write.
Interface:
Meta information is represented using a newly introduced 'struct io_uring_meta'.
Application sets up a SQE128 ring, and prepares io_uring_meta within unused
portion of SQE. Application populates 'struct io_uring_meta' fields as below:
* meta_type: describes type of meta that is passed. Currently one type
"Integrity" is supported.
* meta_flags: these are meta-type specific flags. Three flags are exposed for
integrity type, namely INTEGRITY_CHK_GUARD/APPTAG/REFTAG.
* meta_len: length of the meta buffer
* meta_addr: address of the meta buffer
* apptag: optional application-specific 16b value; this goes along with
INTEGRITY_CHK_APPTAG flag.
Block path (direct IO) and NVMe driver are modified to support
this.
The first patch is borrowed from Mikulas series[1] to make the metadata split
work correctly.
Next 5 patches are enhancements in the block/nvme so that user meta buffer
is handled correctly (mostly when it gets split).
Patch 8 adds the io_uring support.
Patch 9 adds the support for block direct IO, and patch 10 for NVMe.
Example program on how to use the interface is appended below [2]
Tree:
https://github.com/SamsungDS/linux/tree/feat/pi_us_v2
Testing:
has been done by modifying fio to use this interface.
https://github.com/samsungds/fio/commits/feat/test-meta-v3
Changes since v1:
https://lore.kernel.org/linux-block/20240425183943.6319-1-joshi.k@samsung.com/
- Do not use new opcode for meta, and also add the provision to introduce new
meta types beyond integrity (Pavel)
- Stuff IOCB_HAS_META check in need_complete_io (Jens)
- Split meta handling in NVMe into a separate handler (Keith)
- Add meta handling for __blkdev_direct_IO too (Keith)
- Don't inherit BIP_COPY_USER flag for cloned bio's (Christoph)
- Better commit descriptions (Christoph)
Changes since RFC:
- modify io_uring plumbing based on recent async handling state changes
- fixes/enhancements to correctly handle the split for meta buffer
- add flags to specify guard/reftag/apptag checks
- add support to send apptag
[1] https://lore.kernel.org/linux-block/719d2e-b0e6-663c-ec38-acf939e4a04b@redhat.com/
[2]
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <linux/io_uring.h>
#include <linux/types.h>
#include "liburing.h"
/* write data/meta. read both. compare. send apptag too.
* prerequisite:
* unprotected xfer: format namespace with 4KB + 8b, pi_type = 0
* protected xfer: format namespace with 4KB + 8b, pi_type = 1
*/
#define DATA_LEN 4096
#define META_LEN 8
struct t10_pi_tuple {
__be16 guard;
__be16 apptag;
__be32 reftag;
};
int main(int argc, char *argv[])
{
struct io_uring ring;
struct io_uring_sqe *sqe = NULL;
struct io_uring_cqe *cqe = NULL;
void *wdb,*rdb;
char wmb[META_LEN], rmb[META_LEN];
char *data_str = "data buffer";
char *meta_str = "meta";
int fd, ret, blksize;
struct stat fstat;
unsigned long long offset = DATA_LEN;
struct t10_pi_tuple *pi;
struct io_uring_meta *md;
if (argc != 2) {
fprintf(stderr, "Usage: %s <block-device>", argv[0]);
return 1;
};
if (stat(argv[1], &fstat) == 0) {
blksize = (int)fstat.st_blksize;
} else {
perror("stat");
return 1;
}
if (posix_memalign(&wdb, blksize, DATA_LEN)) {
perror("posix_memalign failed");
return 1;
}
if (posix_memalign(&rdb, blksize, DATA_LEN)) {
perror("posix_memalign failed");
return 1;
}
strcpy(wdb, data_str);
strcpy(wmb, meta_str);
fd = open(argv[1], O_RDWR | O_DIRECT);
if (fd < 0) {
printf("Error in opening device\n");
return 0;
}
ret = io_uring_queue_init(8, &ring, IORING_SETUP_SQE128);
if (ret) {
fprintf(stderr, "ring setup failed: %d\n", ret);
return 1;
}
/* write data + meta-buffer to device */
sqe = io_uring_get_sqe(&ring);
if (!sqe) {
fprintf(stderr, "get sqe failed\n");
return 1;
}
io_uring_prep_write(sqe, fd, wdb, DATA_LEN, offset);
md = (struct io_uring_meta *) sqe->cmd;
md->meta_type = META_TYPE_INTEGRITY;
md->meta_addr = (__u64)wmb;
md->meta_len = META_LEN;
/* flags to ask for guard/reftag/apptag*/
md->meta_flags = INTEGRITY_CHK_APPTAG;
md->apptag = 0x1234;
pi = (struct t10_pi_tuple *)wmb;
pi->apptag = 0x3412;
ret = io_uring_submit(&ring);
if (ret <= 0) {
fprintf(stderr, "sqe submit failed: %d\n", ret);
return 1;
}
ret = io_uring_wait_cqe(&ring, &cqe);
if (!cqe) {
fprintf(stderr, "cqe is NULL :%d\n", ret);
return 1;
}
if (cqe->res < 0) {
fprintf(stderr, "write cqe failure: %d", cqe->res);
return 1;
}
io_uring_cqe_seen(&ring, cqe);
/* read data + meta-buffer back from device */
sqe = io_uring_get_sqe(&ring);
if (!sqe) {
fprintf(stderr, "get sqe failed\n");
return 1;
}
io_uring_prep_read(sqe, fd, rdb, DATA_LEN, offset);
md = (struct io_uring_meta *) sqe->cmd;
md->meta_type = META_TYPE_INTEGRITY;
md->meta_addr = (__u64)rmb;
md->meta_len = META_LEN;
md->meta_flags = INTEGRITY_CHK_APPTAG;
md->apptag = 0x1234;
ret = io_uring_submit(&ring);
if (ret <= 0) {
fprintf(stderr, "sqe submit failed: %d\n", ret);
return 1;
}
ret = io_uring_wait_cqe(&ring, &cqe);
if (!cqe) {
fprintf(stderr, "cqe is NULL :%d\n", ret);
return 1;
}
if (cqe->res < 0) {
fprintf(stderr, "read cqe failure: %d", cqe->res);
return 1;
}
io_uring_cqe_seen(&ring, cqe);
if (strncmp(wmb, rmb, META_LEN))
printf("Failure: meta mismatch!, wmb=%s, rmb=%s\n", wmb, rmb);
if (strncmp(wdb, rdb, DATA_LEN))
printf("Failure: data mismatch!\n");
io_uring_queue_exit(&ring);
free(rdb);
free(wdb);
return 0;
}
Anuj Gupta (5):
block: set bip_vcnt correctly
block: copy bip_max_vcnt vecs instead of bip_vcnt during clone
block: Handle meta bounce buffer correctly in case of split
block: modify bio_integrity_map_user to accept iov_iter as argument
io_uring/rw: add support to send meta along with read/write
Kanchan Joshi (4):
block: introduce BIP_CLONED flag
block: define meta io descriptor
block: add support to pass user meta buffer
nvme: add handling for user integrity buffer
Mikulas Patocka (1):
block: change rq_integrity_vec to respect the iterator
block/bio-integrity.c | 75 ++++++++++++++++++++++++++-----
block/fops.c | 28 +++++++++++-
block/t10-pi.c | 6 +++
drivers/nvme/host/core.c | 85 ++++++++++++++++++++++++-----------
drivers/nvme/host/ioctl.c | 11 ++++-
drivers/nvme/host/pci.c | 6 +--
include/linux/bio.h | 25 +++++++++--
include/linux/blk-integrity.h | 16 +++----
include/linux/fs.h | 1 +
include/uapi/linux/io_uring.h | 30 ++++++++++++-
io_uring/io_uring.c | 7 +++
io_uring/rw.c | 68 ++++++++++++++++++++++++++--
io_uring/rw.h | 9 +++-
13 files changed, 308 insertions(+), 59 deletions(-)
--
2.25.1
More information about the Linux-nvme
mailing list