public inbox for [email protected]
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <[email protected]>
To: Bob Liu <[email protected]>
Cc: [email protected], [email protected],
	[email protected], [email protected],
	[email protected]
Subject: Re: [PATCH 2/4] bio-integrity: introduce two funcs handle protect information
Date: Wed, 26 Feb 2020 08:03:10 -0800	[thread overview]
Message-ID: <20200226160310.GA8044@magnolia> (raw)
In-Reply-To: <[email protected]>

On Wed, Feb 26, 2020 at 04:37:17PM +0800, Bob Liu wrote:
> 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(+)
> 
> diff --git a/block/bio-integrity.c b/block/bio-integrity.c
> index 575df98..0b22c5d 100644
> --- a/block/bio-integrity.c
> +++ b/block/bio-integrity.c
> @@ -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;

I would've thought this would be -EINVAL or something given the -ENOMEM
below...?

> +	}
> +
> +	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.

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

> + */
> +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
>   *
> diff --git a/include/linux/bio.h b/include/linux/bio.h
> index 3cdb84c..6172b13 100644
> --- a/include/linux/bio.h
> +++ b/include/linux/bio.h
> @@ -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)
>  {
> -- 
> 2.9.5
> 

  reply	other threads:[~2020-02-26 16:03 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-26  8:37 [RFC PATCH 0/4] userspace PI passthrough via io_uring Bob Liu
2020-02-26  8:37 ` [PATCH 1/4] io_uring: add IORING_OP_READ{WRITE}V_PI cmd Bob Liu
2020-02-26 14:24   ` Jens Axboe
2020-02-26 15:57     ` Christoph Hellwig
2020-02-26 15:58       ` Jens Axboe
2020-02-26 16:03         ` Darrick J. Wong
2020-02-26 16:53         ` Christoph Hellwig
2020-02-27  9:19           ` Bob Liu
2020-02-27  9:05     ` Bob Liu
2020-02-26  8:37 ` [PATCH 2/4] bio-integrity: introduce two funcs handle protect information Bob Liu
2020-02-26 16:03   ` Darrick J. Wong [this message]
2020-02-27  9:23     ` Bob Liu
2020-02-26  8:37 ` [PATCH 3/4] block_dev: support protect information passthrough Bob Liu
2020-02-26 16:04   ` Darrick J. Wong
2020-02-26  8:37 ` [PATCH 4/4] liburing/test: add testcase for " Bob Liu
2020-02-26 14:25 ` [RFC PATCH 0/4] userspace PI passthrough via io_uring Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200226160310.GA8044@magnolia \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox