userspace PI passthrough via io_uring
Subsystems (3)
cover userspace PI passthrough via io_uring
This RFC provides a rough implementation of a mechanism to allow userspace to attach protection information (e.g. T10 DIF) data to a disk write and to receive the information alongside a disk read. The interface is an extension to the io_uring interface:
two new commands (IORING_OP_READV{WRITEV}_PI) are provided. The last struct iovec in the arg list is interpreted to point to a buffer containing the the PI data.
Patch #1 add two new commands to io_uring.
Patch #2 introduces two helper funcs in bio-integrity. Patch #3 implement the PI passthrough in direct-io of block-dev. (Similar extensions may add to fs/direct-io.c and fs/maps/directio.c) Patch #4 add io_uring use space test case to liburing.
Welcome any feedbacks.
Thanks!
There was attempt before[1], but was based on AIO at that time.
[1] https://www.mail-archive.com/[email protected]/msg27537.html
Bob Liu (3):
io_uring: add IORING_OP_READ{WRITE}V_PI cmd
bio-integrity: introduce two funcs handle protect information
block_dev: support protect information passthrough
block/bio-integrity.c | 77 +++++++++++++++++++++++++++++++++++++++++++ fs/block_dev.c | 17 ++++++++++ fs/io_uring.c | 12 +++++++ include/linux/bio.h | 14 ++++++++ include/linux/fs.h | 1 + include/uapi/linux/io_uring.h | 2 ++ 6 files changed, 123 insertions(+)
Signature · 1 line
2.9.5
PATCH 1/4 io_uring: add IORING_OP_READ{WRITE}V_PI cmd
Add read and write with protect information command.
--- fs/io_uring.c | 12 ++++++++++++ include/linux/fs.h | 1 + include/uapi/linux/io_uring.h | 2 ++ 3 files changed, 15 insertions(+)
fs/io_uring.c +12 -0
@@ -630,12 +630,14 @@ static inline bool io_prep_async_work(struct io_kiocb *req,switch (req->opcode) {case IORING_OP_WRITEV : +case IORING_OP_WRITEV_PI :case IORING_OP_WRITE_FIXED :/* only regular files should be hashed for writes */ if (req->flags &REQ_F_ISREG ) do_hashed = true;/* fall-through */ case IORING_OP_READV : +case IORING_OP_READV_PI :case IORING_OP_READ_FIXED :case IORING_OP_SENDMSG :case IORING_OP_RECVMSG :
@@ -1505,6 +1507,12 @@ static int io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe, kiocb->ki_pos =READ_ONCE (sqe->off); kiocb->ki_flags =iocb_flags (kiocb->ki_filp); kiocb->ki_hint =ki_hint_validate (file_write_hint (kiocb->ki_filp)); +if (req->opcode ==IORING_OP_READV_PI || + req->opcode ==IORING_OP_WRITEV_PI ) { +if (!(req->file->f_flags &O_DIRECT )) +return -EINVAL ; + kiocb->ki_flags |=IOCB_USE_PI ; + } ioprio =READ_ONCE (sqe->ioprio);if (ioprio) {
@@ -3065,10 +3073,12 @@ static int io_req_defer_prep(struct io_kiocb *req,case IORING_OP_NOP :break ;case IORING_OP_READV : +case IORING_OP_READV_PI :case IORING_OP_READ_FIXED : ret =io_read_prep (req, sqe, true);break ;case IORING_OP_WRITEV : +case IORING_OP_WRITEV_PI :case IORING_OP_WRITE_FIXED : ret =io_write_prep (req, sqe, true);break ;
@@ -3156,6 +3166,7 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,case IORING_OP_NOP : ret =io_nop (req);break ; +case IORING_OP_READV_PI :case IORING_OP_READV :case IORING_OP_READ_FIXED :if (sqe) {
@@ -3166,6 +3177,7 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe, ret =io_read (req, nxt, force_nonblock);break ;case IORING_OP_WRITEV : +case IORING_OP_WRITEV_PI :case IORING_OP_WRITE_FIXED :if (sqe) { ret =io_write_prep (req, sqe, force_nonblock);
include/linux/fs.h +1 -0
@@ -314,6 +314,7 @@ enum rw_hint {#define IOCB_SYNC (1 << 5)#define IOCB_WRITE (1 << 6)#define IOCB_NOWAIT (1 << 7) +#define IOCB_USE_PI (1 << 8)struct kiocb {struct file *ki_filp;
include/uapi/linux/io_uring.h +2 -0
@@ -62,6 +62,8 @@ enum {IORING_OP_NOP ,IORING_OP_READV ,IORING_OP_WRITEV , +IORING_OP_READV_PI , +IORING_OP_WRITEV_PI ,IORING_OP_FSYNC ,IORING_OP_READ_FIXED , IORING_OP_WRITE_FIXED,
Signature · 1 line
2.9.5
Jens Axboe
maintainerRe: [PATCH 1/4] io_uring: add IORING_OP_READ{WRITE}V_PI cmd
include/uapi/linux/io_uring.h enum { · line 69
Quoted 13 lines · Bob Liu
include/uapi/linux/io_uring.h +2
-0@@ -62,6 +62,8 @@ enum {IORING_OP_NOP ,IORING_OP_READV ,IORING_OP_WRITEV , +IORING_OP_READV_PI , +IORING_OP_WRITEV_PI ,IORING_OP_FSYNC ,IORING_OP_READ_FIXED , IORING_OP_WRITE_FIXED,
So this one renumbers everything past IORING_OP_WRITEV, breaking the ABI in a very bad way. I'm guessing that was entirely unintentional? Any new command must go at the end of the list.
You're also not updating io_op_defs[] with the two new commands, which means it won't compile at all. I'm guessing you tested this on an older version of the kernel which didn't have io_op_defs[]?
Signature · 1 line
Jens Axboe
Re: [PATCH 1/4] io_uring: add IORING_OP_READ{WRITE}V_PI cmd
Quoted 19 lines · Jens Axboe
include/uapi/linux/io_uring.h enum { · line 69
Quoted 13 lines · Bob Liu
include/uapi/linux/io_uring.h +2
-0@@ -62,6 +62,8 @@ enum {IORING_OP_NOP ,IORING_OP_READV ,IORING_OP_WRITEV , +IORING_OP_READV_PI , +IORING_OP_WRITEV_PI ,IORING_OP_FSYNC ,IORING_OP_READ_FIXED , IORING_OP_WRITE_FIXED,So this one renumbers everything past
IORING_OP_WRITEV, breaking the ABI in a very bad way. I'm guessing that was entirely unintentional? Any new command must go at the end of the list.
Quoted 3 lines
You're also not updating io_op_defs[] with the two new commands, which means it won't compile at all. I'm guessing you tested this on an older version of the kernel which didn't have io_op_defs[]?
And the real question is why we need ops insted of just a flag and using previously reserved fields for the PI pointer.
Jens Axboe
maintainerRe: [PATCH 1/4] io_uring: add IORING_OP_READ{WRITE}V_PI cmd
Quoted 20 lines · Christoph Hellwig
Quoted 19 lines · Jens Axboe
include/uapi/linux/io_uring.h enum { · line 69
Quoted 13 lines · Bob Liu
include/uapi/linux/io_uring.h +2
-0@@ -62,6 +62,8 @@ enum {IORING_OP_NOP ,IORING_OP_READV ,IORING_OP_WRITEV , +IORING_OP_READV_PI , +IORING_OP_WRITEV_PI ,IORING_OP_FSYNC ,IORING_OP_READ_FIXED , IORING_OP_WRITE_FIXED,So this one renumbers everything past
IORING_OP_WRITEV, breaking the ABI in a very bad way. I'm guessing that was entirely unintentional? Any new command must go at the end of the list.
Quoted 6 lines
Quoted 3 lines
You're also not updating io_op_defs[] with the two new commands, which means it won't compile at all. I'm guessing you tested this on an older version of the kernel which didn't have io_op_defs[]?
And the real question is why we need ops insted of just a flag and using previously reserved fields for the PI pointer.
Yeah, should probably be a RWF_ flag instead, and a 64-bit SQE field for the PI data. The 'last iovec is PI' is kind of icky.
Signature · 1 line
Jens Axboe
Re: [PATCH 1/4] io_uring: add IORING_OP_READ{WRITE}V_PI cmd
Quoted 25 lines · Jens Axboe
Quoted 24 lines · Christoph Hellwig
Quoted 22 lines · Jens Axboe
include/uapi/linux/io_uring.h enum { · line 69
Quoted 13 lines · Bob Liu
include/uapi/linux/io_uring.h +2
-0@@ -62,6 +62,8 @@ enum {IORING_OP_NOP ,IORING_OP_READV ,IORING_OP_WRITEV , +IORING_OP_READV_PI , +IORING_OP_WRITEV_PI ,IORING_OP_FSYNC ,IORING_OP_READ_FIXED , IORING_OP_WRITE_FIXED,So this one renumbers everything past
IORING_OP_WRITEV, breaking the ABI in a very bad way. I'm guessing that was entirely unintentional? Any new command must go at the end of the list.You're also not updating io_op_defs[] with the two new commands, which means it won't compile at all. I'm guessing you tested this on an older version of the kernel which didn't have io_op_defs[]?
Quoted 5 lines
Quoted 2 lines
And the real question is why we need ops insted of just a flag and using previously reserved fields for the PI pointer.
Yeah, should probably be a
RWF_flag instead, and a 64-bit SQE field for the PI data. The 'last iovec is PI' is kind of icky.
Heh, I was about to send in nearly the same comment. :)
--D
Quoted 3 lines
Signature · 1 line
Jens Axboe
Re: [PATCH 1/4] io_uring: add IORING_OP_READ{WRITE}V_PI cmd
In reply to Jens AxboeQuoted 2 lines · Jens Axboe
Yeah, should probably be a
RWF_flag instead, and a 64-bit SQE field for the PI data. The 'last iovec is PI' is kind of icky.
Abusing an iovec (although I though of the first once when looking into it) looks really horrible, but has two huge advantages:
- it doesn't require passing another argument all the way down the I/O stack
- it works with all the vectored interfaces that take a flag argument, so not just io_uring, but also preadv2/pwritev2 and aio. And while I don't care too much about the last I think preadv2 and pwritev2 are valuable to support.
Re: [PATCH 1/4] io_uring: add IORING_OP_READ{WRITE}V_PI cmd
Quoted 7 lines · Christoph Hellwig
Quoted 2 lines · Jens Axboe
Yeah, should probably be a
RWF_flag instead, and a 64-bit SQE field for the PI data. The 'last iovec is PI' is kind of icky.Abusing an iovec (although I though of the first once when looking into it) looks really horrible, but has two huge advantages:
Quoted 7 lines
- it doesn't require passing another argument all the way down the I/O stack
- it works with all the vectored interfaces that take a flag argument, so not justio_uring, but also preadv2/pwritev2 and aio. And while I don't care too much about the last I think preadv2 and pwritev2 are valuable to support.
Indeed, actually the 'last iovec is PI' idea was learned from Darrick's original patch which support PI passthrough via aio.
https://www.mail-archive.com/[email protected]/msg27537.html
Re: [PATCH 1/4] io_uring: add IORING_OP_READ{WRITE}V_PI cmd
In reply to Jens AxboeQuoted 19 lines · Jens Axboe
include/uapi/linux/io_uring.h enum { · line 69
Quoted 13 lines · Bob Liu
include/uapi/linux/io_uring.h +2
-0@@ -62,6 +62,8 @@ enum {IORING_OP_NOP ,IORING_OP_READV ,IORING_OP_WRITEV , +IORING_OP_READV_PI , +IORING_OP_WRITEV_PI ,IORING_OP_FSYNC ,IORING_OP_READ_FIXED , IORING_OP_WRITE_FIXED,So this one renumbers everything past
IORING_OP_WRITEV, breaking the ABI in a very bad way. I'm guessing that was entirely unintentional? Any new command must go at the end of the list.
Quoted 4 lines
You're also not updating io_op_defs[] with the two new commands, which means it won't compile at all. I'm guessing you tested this on an older version of the kernel which didn't have io_op_defs[]?
Yep, will rebase to the latest version next time.
PATCH 2/4 bio-integrity: introduce two funcs handle protect information
In reply to Bob LiuIntroduce two funcs handle protect information passthrough from user space.
iter_slice_protect_info() will slice the last segment as protect information.
bio_integrity_prep_from_iovec() attach the protect information to a bio.
--- block/bio-integrity.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/bio.h | 14 ++++++++++ 2 files changed, 91 insertions(+)
block/bio-integrity.c +77 -0
@@ -12,6 +12,7 @@#include <linux/bio.h> #include <linux/workqueue.h> #include <linux/slab.h> +#include <linux/uio.h> #include "blk.h" #define BIP_INLINE_VECS 4
@@ -305,6 +306,53 @@ bool bio_integrity_prep(struct bio *bio) }EXPORT_SYMBOL (bio_integrity_prep); +int bio_integrity_prep_from_iovec (struct bio *bio,struct iovec *pi_iov) +{ +struct blk_integrity *bi =blk_get_integrity (bio->bi_disk); +struct bio_integrity_payload *bip; +struct page *user_pi_page; +int nr_vec_page =0 ; +int ret =0 , interval =0 ; + +if (!pi_iov || !pi_iov->iov_base) +return 1 ; + + nr_vec_page = (pi_iov->iov_len +PAGE_SIZE -1 ) >>PAGE_SHIFT ; +if (nr_vec_page >1 ) { +printk ("Now only support 1 page containing integrity " +"metadata, while requires %d pages.\n" , nr_vec_page); +return 1 ; + } + + interval =bio_integrity_intervals (bi,bio_sectors (bio)); +if ((interval * bi->tuple_size) != pi_iov->iov_len) +return 1 ; + + bip =bio_integrity_alloc (bio,GFP_NOIO , nr_vec_page); +if (IS_ERR (bip)) +return PTR_ERR (bip); + + bip->bip_iter.bi_size = pi_iov->iov_len; + bip->bio_iter = bio->bi_iter; +bip_set_seed (bip, bio->bi_iter.bi_sector); + +if (bi->flags &BLK_INTEGRITY_IP_CHECKSUM ) + bip->bip_flags |=BIP_IP_CHECKSUM ; + + ret =get_user_pages_fast ((unsigned long )(pi_iov->iov_base), nr_vec_page, +op_is_write (bio_op (bio)) ?FOLL_WRITE :0 , + &user_pi_page); +if (unlikely (ret <0 )) +return 1 ; + + ret =bio_integrity_add_page (bio, user_pi_page, pi_iov->iov_len,0 ); +if (unlikely (ret != pi_iov->iov_len)) +return -ENOMEM ; + +return 0 ; +} +EXPORT_SYMBOL (bio_integrity_prep_from_iovec); +/** * bio_integrity_verify_fn - Integrity I/O completion worker * @work: Work struct stored in bio to be verified
@@ -378,6 +426,35 @@ void bio_integrity_advance(struct bio *bio, unsigned int bytes_done) }/** +* iter_slice_protect_info +* +* Description: slice protection information from iter. +* The last iovec contains protection information pass from user space. +*/ +int iter_slice_protect_info (struct iov_iter *iter,int nr_pages, +struct iovec **pi_iov) +{ +size_t len =0 ; + +/* TBD: now only support one bio. */ +if (!iter_is_iovec (iter) || nr_pages >=BIO_MAX_PAGES -1 ) +return 1 ; + +/* Last iovec contains protection information. */ + iter->nr_segs--; + *pi_iov = (struct iovec *)(iter->iov + iter->nr_segs); + + len = (*pi_iov)->iov_len; +if (len >0 && len < iter->count) { + iter->count -= len; +return 0 ; + } + +return 1 ; +} +EXPORT_SYMBOL (iter_slice_protect_info); + +/** * bio_integrity_trim - Trim integrity vector * @bio: bio whose integrity vector to update *
include/linux/bio.h +14 -0
@@ -749,6 +749,8 @@ static inline bool bioset_initialized(struct bio_set *bs)extern struct bio_integrity_payload *bio_integrity_alloc (struct bio *,gfp_t ,unsigned int );extern int bio_integrity_add_page (struct bio *,struct page *,unsigned int ,unsigned int );extern bool bio_integrity_prep (struct bio *); +extern int bio_integrity_prep_from_iovec (struct bio *bio,struct iovec *pi_iov); +extern int iter_slice_protect_info (struct iov_iter *iter,int nr_pages,struct iovec **pi_iov);extern void bio_integrity_advance (struct bio *,unsigned int );extern void bio_integrity_trim (struct bio *);extern int bio_integrity_clone (struct bio *,struct bio *,gfp_t );
@@ -778,6 +780,18 @@ static inline bool bio_integrity_prep(struct bio *bio)return true; } +static inline int bio_integrity_prep_from_iovec (struct bio *bio, +struct iovec *pi_iov) +{ +return 0 ; +} + +static inline int iter_slice_protect_info (struct iov_iter *iter,int nr_pages, +struct iovec **pi_iov) +{ +return 0 ; +} +static inline int bio_integrity_clone (struct bio *bio,struct bio *bio_src,gfp_t gfp_mask) {
Signature · 1 line
2.9.5
Re: [PATCH 2/4] bio-integrity: introduce two funcs handle protect information
Quoted 37 lines · Bob Liu
Introduce two funcs handle protect information passthrough from user space.
iter_slice_protect_info()will slice the last segment as protect information.
bio_integrity_prep_from_iovec()attach the protect information to a bio.Signed-off-by Bob Liu <[email protected]>--- block/bio-integrity.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/bio.h | 14 ++++++++++ 2 files changed, 91 insertions(+)block/bio-integrity.c +7
-0@@ -12,6 +12,7 @@#include <linux/bio.h> #include <linux/workqueue.h> #include <linux/slab.h> +#include <linux/uio.h> #include "blk.h" #define BIP_INLINE_VECS 4@@ -305,6 +306,53 @@ bool bio_integrity_prep(struct bio *bio) }EXPORT_SYMBOL (bio_integrity_prep); +int bio_integrity_prep_from_iovec (struct bio *bio,struct iovec *pi_iov) +{ +struct blk_integrity *bi =blk_get_integrity (bio->bi_disk); +struct bio_integrity_payload *bip; +struct page *user_pi_page; +int nr_vec_page =0 ;
block/bio-integrity.c bool bio_integrity_prep(struct bio *bio) · line 324
Quoted 10 lines
block/bio-integrity.c +10
-0+int ret =0 , interval =0 ; + +if (!pi_iov || !pi_iov->iov_base) +return 1 ; + + nr_vec_page = (pi_iov->iov_len +PAGE_SIZE -1 ) >>PAGE_SHIFT ; +if (nr_vec_page >1 ) { +printk ("Now only support 1 page containing integrity " +"metadata, while requires %d pages.\n" , nr_vec_page); +return 1 ;
I would've thought this would be -EINVAL or something given the -ENOMEM below...?
Quoted 35 lines
block/bio-integrity.c +31
-0+ } + + interval =bio_integrity_intervals (bi,bio_sectors (bio)); +if ((interval * bi->tuple_size) != pi_iov->iov_len) +return 1 ; + + bip =bio_integrity_alloc (bio,GFP_NOIO , nr_vec_page); +if (IS_ERR (bip)) +return PTR_ERR (bip); + + bip->bip_iter.bi_size = pi_iov->iov_len; + bip->bio_iter = bio->bi_iter; +bip_set_seed (bip, bio->bi_iter.bi_sector); + +if (bi->flags &BLK_INTEGRITY_IP_CHECKSUM ) + bip->bip_flags |=BIP_IP_CHECKSUM ; + + ret =get_user_pages_fast ((unsigned long )(pi_iov->iov_base), nr_vec_page, +op_is_write (bio_op (bio)) ?FOLL_WRITE :0 , + &user_pi_page); +if (unlikely (ret <0 )) +return 1 ; + + ret =bio_integrity_add_page (bio, user_pi_page, pi_iov->iov_len,0 ); +if (unlikely (ret != pi_iov->iov_len)) +return -ENOMEM ; + +return 0 ; +} +EXPORT_SYMBOL (bio_integrity_prep_from_iovec); +/** * bio_integrity_verify_fn - Integrity I/O completion worker * @work: Work struct stored in bio to be verified
block/bio-integrity.c void bio_integrity_advance(struct bio *bio, unsigned int bytes_done) · line 432
Quoted 7 lines
block/bio-integrity.c +4
-0@@ -378,6 +426,35 @@ void bio_integrity_advance(struct bio *bio, unsigned int bytes_done) }/** +* iter_slice_protect_info +* +* Description: slice protection information from iter. +* The last iovec contains protection information pass from user space.
What do the return values here mean?
Also kinda wondering about the slice & dice of the iovec here, but <shrug> I guess this is RFC. :)
--D
Quoted 63 lines
block/bio-integrity.c +25
-0+*/ +int iter_slice_protect_info (struct iov_iter *iter,int nr_pages, +struct iovec **pi_iov) +{ +size_t len =0 ; + +/* TBD: now only support one bio. */ +if (!iter_is_iovec (iter) || nr_pages >=BIO_MAX_PAGES -1 ) +return 1 ; + +/* Last iovec contains protection information. */ + iter->nr_segs--; + *pi_iov = (struct iovec *)(iter->iov + iter->nr_segs); + + len = (*pi_iov)->iov_len; +if (len >0 && len < iter->count) { + iter->count -= len; +return 0 ; + } + +return 1 ; +} +EXPORT_SYMBOL (iter_slice_protect_info); + +/** * bio_integrity_trim - Trim integrity vector * @bio: bio whose integrity vector to update * include/linux/bio.h +14
-0@@ -749,6 +749,8 @@ static inline bool bioset_initialized(struct bio_set *bs)extern struct bio_integrity_payload *bio_integrity_alloc (struct bio *,gfp_t ,unsigned int );extern int bio_integrity_add_page (struct bio *,struct page *,unsigned int ,unsigned int );extern bool bio_integrity_prep (struct bio *); +extern int bio_integrity_prep_from_iovec (struct bio *bio,struct iovec *pi_iov); +extern int iter_slice_protect_info (struct iov_iter *iter,int nr_pages,struct iovec **pi_iov);extern void bio_integrity_advance (struct bio *,unsigned int );extern void bio_integrity_trim (struct bio *);extern int bio_integrity_clone (struct bio *,struct bio *,gfp_t );@@ -778,6 +780,18 @@ static inline bool bio_integrity_prep(struct bio *bio)return true; } +static inline int bio_integrity_prep_from_iovec (struct bio *bio, +struct iovec *pi_iov) +{ +return 0 ; +} + +static inline int iter_slice_protect_info (struct iov_iter *iter,int nr_pages, +struct iovec **pi_iov) +{ +return 0 ; +} +static inline int bio_integrity_clone (struct bio *bio,struct bio *bio_src,gfp_t gfp_mask) {Signature · 1 line
2.9.5
Re: [PATCH 2/4] bio-integrity: introduce two funcs handle protect information
Quoted 89 lines · Darrick J. Wong
Quoted 37 lines · Bob Liu
Introduce two funcs handle protect information passthrough from user space.
iter_slice_protect_info()will slice the last segment as protect information.
bio_integrity_prep_from_iovec()attach the protect information to a bio.Signed-off-by Bob Liu <[email protected]>--- block/bio-integrity.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/bio.h | 14 ++++++++++ 2 files changed, 91 insertions(+)block/bio-integrity.c +7
-0@@ -12,6 +12,7 @@#include <linux/bio.h> #include <linux/workqueue.h> #include <linux/slab.h> +#include <linux/uio.h> #include "blk.h" #define BIP_INLINE_VECS 4@@ -305,6 +306,53 @@ bool bio_integrity_prep(struct bio *bio) }EXPORT_SYMBOL (bio_integrity_prep); +int bio_integrity_prep_from_iovec (struct bio *bio,struct iovec *pi_iov) +{ +struct blk_integrity *bi =blk_get_integrity (bio->bi_disk); +struct bio_integrity_payload *bip; +struct page *user_pi_page; +int nr_vec_page =0 ;block/bio-integrity.c bool bio_integrity_prep(struct bio *bio) · line 324
Quoted 10 lines
block/bio-integrity.c +10
-0+int ret =0 , interval =0 ; + +if (!pi_iov || !pi_iov->iov_base) +return 1 ; + + nr_vec_page = (pi_iov->iov_len +PAGE_SIZE -1 ) >>PAGE_SHIFT ; +if (nr_vec_page >1 ) { +printk ("Now only support 1 page containing integrity " +"metadata, while requires %d pages.\n" , nr_vec_page); +return 1 ;I would've thought this would be
-EINVALor something given the-ENOMEMbelow...?Quoted 37 lines
block/bio-integrity.c +31
-0+ } + + interval =bio_integrity_intervals (bi,bio_sectors (bio)); +if ((interval * bi->tuple_size) != pi_iov->iov_len) +return 1 ; + + bip =bio_integrity_alloc (bio,GFP_NOIO , nr_vec_page); +if (IS_ERR (bip)) +return PTR_ERR (bip); + + bip->bip_iter.bi_size = pi_iov->iov_len; + bip->bio_iter = bio->bi_iter; +bip_set_seed (bip, bio->bi_iter.bi_sector); + +if (bi->flags &BLK_INTEGRITY_IP_CHECKSUM ) + bip->bip_flags |=BIP_IP_CHECKSUM ; + + ret =get_user_pages_fast ((unsigned long )(pi_iov->iov_base), nr_vec_page, +op_is_write (bio_op (bio)) ?FOLL_WRITE :0 , + &user_pi_page); +if (unlikely (ret <0 )) +return 1 ; + + ret =bio_integrity_add_page (bio, user_pi_page, pi_iov->iov_len,0 ); +if (unlikely (ret != pi_iov->iov_len)) +return -ENOMEM ; + +return 0 ; +} +EXPORT_SYMBOL (bio_integrity_prep_from_iovec); +/** * bio_integrity_verify_fn - Integrity I/O completion worker * @work: Work struct stored in bio to be verified @@ -378,6 +426,35 @@ void bio_integrity_advance(struct bio *bio, unsigned int bytes_done) }
Quoted 8 lines
block/bio-integrity.c void bio_integrity_advance(struct bio *bio, unsigned int bytes_done) · line 432
Quoted 5 lines
block/bio-integrity.c +4
-0/** +* iter_slice_protect_info +* +* Description: slice protection information from iter. +* The last iovec contains protection information pass from user space. What do the return values here mean?
Will update.
Quoted 3 lines
Also kinda wondering about the slice & dice of the iovec here, but <shrug> I guess this is RFC. :)
Hmm, I also very hesitate to put it here or lib/iov_iter.c.
Quoted 65 lines
--D
Quoted 63 lines
block/bio-integrity.c +25
-0+*/ +int iter_slice_protect_info (struct iov_iter *iter,int nr_pages, +struct iovec **pi_iov) +{ +size_t len =0 ; + +/* TBD: now only support one bio. */ +if (!iter_is_iovec (iter) || nr_pages >=BIO_MAX_PAGES -1 ) +return 1 ; + +/* Last iovec contains protection information. */ + iter->nr_segs--; + *pi_iov = (struct iovec *)(iter->iov + iter->nr_segs); + + len = (*pi_iov)->iov_len; +if (len >0 && len < iter->count) { + iter->count -= len; +return 0 ; + } + +return 1 ; +} +EXPORT_SYMBOL (iter_slice_protect_info); + +/** * bio_integrity_trim - Trim integrity vector * @bio: bio whose integrity vector to update * include/linux/bio.h +14
-0@@ -749,6 +749,8 @@ static inline bool bioset_initialized(struct bio_set *bs)extern struct bio_integrity_payload *bio_integrity_alloc (struct bio *,gfp_t ,unsigned int );extern int bio_integrity_add_page (struct bio *,struct page *,unsigned int ,unsigned int );extern bool bio_integrity_prep (struct bio *); +extern int bio_integrity_prep_from_iovec (struct bio *bio,struct iovec *pi_iov); +extern int iter_slice_protect_info (struct iov_iter *iter,int nr_pages,struct iovec **pi_iov);extern void bio_integrity_advance (struct bio *,unsigned int );extern void bio_integrity_trim (struct bio *);extern int bio_integrity_clone (struct bio *,struct bio *,gfp_t );@@ -778,6 +780,18 @@ static inline bool bio_integrity_prep(struct bio *bio)return true; } +static inline int bio_integrity_prep_from_iovec (struct bio *bio, +struct iovec *pi_iov) +{ +return 0 ; +} + +static inline int iter_slice_protect_info (struct iov_iter *iter,int nr_pages, +struct iovec **pi_iov) +{ +return 0 ; +} +static inline int bio_integrity_clone (struct bio *bio,struct bio *bio_src,gfp_t gfp_mask) {Signature · 1 line
2.9.5
PATCH 3/4 block_dev: support protect information passthrough
In reply to Bob LiuSupport protect information passed from use sapce, on direct io is considered now.
--- fs/block_dev.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
fs/block_dev.c +17 -0
@@ -348,6 +348,13 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, int nr_pages)loff_t pos = iocb->ki_pos;blk_qc_t qc =BLK_QC_T_NONE ;int ret =0 ; +struct iovec *pi_iov; + +if (iocb->ki_flags &IOCB_USE_PI ) { + ret =iter_slice_protect_info (iter, nr_pages, &pi_iov); +if (ret) +return -EINVAL ; + }if ((pos |iov_iter_alignment (iter)) & (bdev_logical_block_size (bdev) -1 ))
@@ -411,6 +418,16 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, int nr_pages) polled = true; } +/* Add protection information to bio */ +if (iocb->ki_flags &IOCB_USE_PI ) { + ret =bio_integrity_prep_from_iovec (bio, pi_iov); +if (ret) { + bio->bi_status =BLK_STS_IOERR ; +bio_endio (bio); +break ; + } + } + qc =submit_bio (bio);if (polled)
Signature · 1 line
2.9.5
Re: [PATCH 3/4] block_dev: support protect information passthrough
Quoted 27 lines · Bob Liu
Support protect information passed from use sapce, on direct io is considered now.
Signed-off-by Bob Liu <[email protected]>--- fs/block_dev.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)fs/block_dev.c +7
-0@@ -348,6 +348,13 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, int nr_pages)loff_t pos = iocb->ki_pos;blk_qc_t qc =BLK_QC_T_NONE ;int ret =0 ; +struct iovec *pi_iov; + +if (iocb->ki_flags &IOCB_USE_PI ) { + ret =iter_slice_protect_info (iter, nr_pages, &pi_iov); +if (ret) +return -EINVAL ; + }if ((pos |iov_iter_alignment (iter)) & (bdev_logical_block_size (bdev) -1 ))
fs/block_dev.c __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, int nr_pages) · line 426
Quoted 9 lines
fs/block_dev.c +6
-0@@ -411,6 +418,16 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, int nr_pages) polled = true; } +/* Add protection information to bio */ +if (iocb->ki_flags &IOCB_USE_PI ) { + ret =bio_integrity_prep_from_iovec (bio, pi_iov); +if (ret) { + bio->bi_status =BLK_STS_IOERR ; +bio_endio (bio);
If you're just going to mash all the error codes into IOERR, then this could very well become bio_io_error() ?
--D
Quoted 10 lines
fs/block_dev.c +4
-0+break ; + } + } + qc =submit_bio (bio);if (polled)Signature · 1 line
2.9.5
PATCH 4/4 liburing/test: add testcase for protect information passthrough
In reply to Bob LiuDemonstrate how to use IORING_OP_READ{WRITE}V_PI cmd.
Write data together with protection information, then read back and compare results.
--- src/include/liburing.h | 16 ++ src/include/liburing/io_uring.h | 2 + test/Makefile | 4 +- test/pi_passthrough.c | 267 ++++++++++++++++++++++++++++++++ 4 files changed, 287 insertions(+), 2 deletions(-) create mode 100644 test/pi_passthrough.c
src/include/liburing.h +16 -0
@@ -206,6 +206,14 @@ static inline void io_uring_prep_rw(int op, struct io_uring_sqe *sqe, int fd, sqe->__pad2[0 ] = sqe->__pad2[1 ] = sqe->__pad2[2 ] =0 ; } +static inline void io_uring_prep_readv_pi (struct io_uring_sqe *sqe,int fd, +const struct iovec *iovecs, +unsigned nr_vecs,off_t offset) +{ +io_uring_prep_rw (IORING_OP_READV_PI , sqe, fd, iovecs, nr_vecs, offset); +} + +static inline void io_uring_prep_readv (struct io_uring_sqe *sqe,int fd,const struct iovec *iovecs,unsigned nr_vecs,off_t offset)
@@ -228,6 +236,14 @@ static inline void io_uring_prep_writev(struct io_uring_sqe *sqe, int fd,io_uring_prep_rw (IORING_OP_WRITEV , sqe, fd, iovecs, nr_vecs, offset); } +static inline void io_uring_prep_writev_pi (struct io_uring_sqe *sqe,int fd, +const struct iovec *iovecs, +unsigned nr_vecs,off_t offset) +{ +io_uring_prep_rw (IORING_OP_WRITEV_PI , sqe, fd, iovecs, nr_vecs, offset); +} + +static inline void io_uring_prep_write_fixed (struct io_uring_sqe *sqe,int fd,const void *buf,unsigned nbytes,off_t offset,int buf_index)
src/include/liburing/io_uring.h +2 -0
@@ -86,6 +86,8 @@ enum {IORING_OP_NOP ,IORING_OP_READV ,IORING_OP_WRITEV , +IORING_OP_READV_PI , +IORING_OP_WRITEV_PI ,IORING_OP_FSYNC ,IORING_OP_READ_FIXED , IORING_OP_WRITE_FIXED,
test/Makefile +2 -2
@@ -13,7 +13,7 @@ all_targets += poll poll-cancel ring-leak fsync io_uring_setup io_uring_register send_recvmsg a4c0b3decb33-test 500f9fbadef8-test timeout \ sq-space_left stdout cq-ready cq-peek-batch file-register \ cq-size 8a9973408177-test a0908ae19763-test 232c93d07b74-test \ - socket-rw accept timeout-overflow defer read-write io-cancel \ + socket-rw accept timeout-overflow defer read-write pi_passthrough io-cancel \ link-timeout cq-overflow link_drain fc2a85cb02ef-test \ poll-link accept-link fixed-link poll-cancel-ton teardowns \ poll-many b5837bd5311d-test accept-test d77a67ed5f27-test \
@@ -40,7 +40,7 @@ test_srcs := poll.c poll-cancel.c ring-leak.c fsync.c io_uring_setup.c \ 500f9fbadef8-test.c timeout.c sq-space_left.c stdout.c cq-ready.c\ cq-peek-batch.c file-register.c cq-size.c 8a9973408177-test.c \ a0908ae19763-test.c 232c93d07b74-test.c socket-rw.c accept.c \ - timeout-overflow.c defer.c read-write.c io-cancel.c link-timeout.c \ + timeout-overflow.c defer.c read-write.c pi_passthrough.c io-cancel.c link-timeout.c \ cq-overflow.c link_drain.c fc2a85cb02ef-test.c poll-link.c \ accept-link.c fixed-link.c poll-cancel-ton.c teardowns.c poll-many.c \ b5837bd5311d-test.c accept-test.c d77a67ed5f27-test.c connect.c \
test/pi_passthrough.c new file +267 -0
267 lines not on this page · raw message
Signature · 1 line
2.17.1
Jens Axboe
maintainerQuoted 8 lines · Bob Liu
This RFC provides a rough implementation of a mechanism to allow userspace to attach protection information (e.g. T10 DIF) data to a disk write and to receive the information alongside a disk read. The interface is an extension to the
io_uringinterface:
two new commands (IORING_OP_READV{WRITEV}_PI) are provided. The last struct iovec in the arg list is interpreted to point to a buffer containing the the PI data.
Quoted 5 lines
Patch #1 add two new commands to
io_uring.
Patch #2 introduces two helper funcs in bio-integrity. Patch #3 implement the PI passthrough in direct-io of block-dev. (Similar extensions may add tofs/direct-io.candfs/maps/directio.c) Patch #4 addio_uringuse space test case to liburing.
No strong feelings on the support in general, the io_uring bits are trivial enough (once fixed up, per comments in that patch) that I have no objections on that front.
I'd really like Martin to render an opinion on the API (PI info in last vec), since he's the integrity guy.
Signature · 1 line
Jens Axboe