* [PATCH] block: remove bio_rewind_iter()
@ 2018-09-05 3:33 Ming Lei
2018-09-05 3:52 ` Kent Overstreet
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Ming Lei @ 2018-09-05 3:33 UTC (permalink / raw)
To: Jens Axboe
Cc: linux-block, Ming Lei, Kent Overstreet, Dmitry Monakhov,
Christoph Hellwig, Hannes Reinecke
It is pointed that bio_rewind_iter() is one very bad API[1]:
1) bio size may not be restored after rewinding
2) it causes some bogus change, such as 5151842b9d8732 (block: reset
bi_iter.bi_done after splitting bio)
3) rewinding really makes things complicated wrt. bio splitting
4) unnecessary updating of .bi_done in fast path
[1] https://marc.info/?t=153549924200005&r=1&w=2
So this patch takes Kent's suggestion to restore one bio into its original
state via saving bio iterator(struct bvec_iter) in bio_integrity_prep(),
given now bio_rewind_iter() is only used by bio integrity code.
Suggested-by: Kent Overstreet <kent.overstreet@gmail.com>
Cc: Kent Overstreet <kent.overstreet@gmail.com>
Cc: Dmitry Monakhov <dmonakhov@openvz.org>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
block/bio-integrity.c | 10 +++-------
block/bio.c | 1 -
include/linux/bio.h | 22 ++++------------------
include/linux/bvec.h | 3 ---
4 files changed, 7 insertions(+), 29 deletions(-)
diff --git a/block/bio-integrity.c b/block/bio-integrity.c
index 67b5fb861a51..839c332069a9 100644
--- a/block/bio-integrity.c
+++ b/block/bio-integrity.c
@@ -306,6 +306,8 @@ bool bio_integrity_prep(struct bio *bio)
if (bio_data_dir(bio) == WRITE) {
bio_integrity_process(bio, &bio->bi_iter,
bi->profile->generate_fn);
+ } else {
+ bip->bio_iter = bio->bi_iter;
}
return true;
@@ -331,19 +333,13 @@ static void bio_integrity_verify_fn(struct work_struct *work)
container_of(work, struct bio_integrity_payload, bip_work);
struct bio *bio = bip->bip_bio;
struct blk_integrity *bi = blk_get_integrity(bio->bi_disk);
- struct bvec_iter iter = bio->bi_iter;
/*
* At the moment verify is called bio's iterator was advanced
* during split and completion, we need to rewind iterator to
* it's original position.
*/
- if (bio_rewind_iter(bio, &iter, iter.bi_done)) {
- bio->bi_status = bio_integrity_process(bio, &iter,
- bi->profile->verify_fn);
- } else {
- bio->bi_status = BLK_STS_IOERR;
- }
+ bio->bi_status = bio_integrity_process(bio, &bip->bio_iter, bi->profile->verify_fn);
bio_integrity_free(bio);
bio_endio(bio);
diff --git a/block/bio.c b/block/bio.c
index b12966e415d3..cc57cbbebbfd 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1807,7 +1807,6 @@ struct bio *bio_split(struct bio *bio, int sectors,
bio_integrity_trim(split);
bio_advance(bio, split->bi_iter.bi_size);
- bio->bi_iter.bi_done = 0;
if (bio_flagged(bio, BIO_TRACE_COMPLETION))
bio_set_flag(split, BIO_TRACE_COMPLETION);
diff --git a/include/linux/bio.h b/include/linux/bio.h
index 51371740d2a8..14b4fa266357 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -170,27 +170,11 @@ static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter,
{
iter->bi_sector += bytes >> 9;
- if (bio_no_advance_iter(bio)) {
+ if (bio_no_advance_iter(bio))
iter->bi_size -= bytes;
- iter->bi_done += bytes;
- } else {
+ else
bvec_iter_advance(bio->bi_io_vec, iter, bytes);
/* TODO: It is reasonable to complete bio with error here. */
- }
-}
-
-static inline bool bio_rewind_iter(struct bio *bio, struct bvec_iter *iter,
- unsigned int bytes)
-{
- iter->bi_sector -= bytes >> 9;
-
- if (bio_no_advance_iter(bio)) {
- iter->bi_size += bytes;
- iter->bi_done -= bytes;
- return true;
- }
-
- return bvec_iter_rewind(bio->bi_io_vec, iter, bytes);
}
#define __bio_for_each_segment(bvl, bio, iter, start) \
@@ -353,6 +337,8 @@ struct bio_integrity_payload {
unsigned short bip_max_vcnt; /* integrity bio_vec slots */
unsigned short bip_flags; /* control flags */
+ struct bvec_iter bio_iter; /* for rewinding parent bio */
+
struct work_struct bip_work; /* I/O completion */
struct bio_vec *bip_vec;
diff --git a/include/linux/bvec.h b/include/linux/bvec.h
index fe7a22dd133b..02c73c6aa805 100644
--- a/include/linux/bvec.h
+++ b/include/linux/bvec.h
@@ -40,8 +40,6 @@ struct bvec_iter {
unsigned int bi_idx; /* current index into bvl_vec */
- unsigned int bi_done; /* number of bytes completed */
-
unsigned int bi_bvec_done; /* number of bytes completed in
current bvec */
};
@@ -85,7 +83,6 @@ static inline bool bvec_iter_advance(const struct bio_vec *bv,
bytes -= len;
iter->bi_size -= len;
iter->bi_bvec_done += len;
- iter->bi_done += len;
if (iter->bi_bvec_done == __bvec_iter_bvec(bv, *iter)->bv_len) {
iter->bi_bvec_done = 0;
--
2.9.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] block: remove bio_rewind_iter()
2018-09-05 3:33 [PATCH] block: remove bio_rewind_iter() Ming Lei
@ 2018-09-05 3:52 ` Kent Overstreet
2018-09-05 13:19 ` Christoph Hellwig
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Kent Overstreet @ 2018-09-05 3:52 UTC (permalink / raw)
To: Ming Lei
Cc: Jens Axboe, linux-block, Dmitry Monakhov, Christoph Hellwig,
Hannes Reinecke
Thanks for doing this, Ming
On Wed, Sep 05, 2018 at 11:33:35AM +0800, Ming Lei wrote:
> It is pointed that bio_rewind_iter() is one very bad API[1]:
>
> 1) bio size may not be restored after rewinding
>
> 2) it causes some bogus change, such as 5151842b9d8732 (block: reset
> bi_iter.bi_done after splitting bio)
>
> 3) rewinding really makes things complicated wrt. bio splitting
>
> 4) unnecessary updating of .bi_done in fast path
>
> [1] https://marc.info/?t=153549924200005&r=1&w=2
>
> So this patch takes Kent's suggestion to restore one bio into its original
> state via saving bio iterator(struct bvec_iter) in bio_integrity_prep(),
> given now bio_rewind_iter() is only used by bio integrity code.
>
> Suggested-by: Kent Overstreet <kent.overstreet@gmail.com>
> Cc: Kent Overstreet <kent.overstreet@gmail.com>
> Cc: Dmitry Monakhov <dmonakhov@openvz.org>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Hannes Reinecke <hare@suse.com>
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
Acked-by: Kent Overstreet <kent.overstreet@gmail.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] block: remove bio_rewind_iter()
2018-09-05 3:33 [PATCH] block: remove bio_rewind_iter() Ming Lei
2018-09-05 3:52 ` Kent Overstreet
@ 2018-09-05 13:19 ` Christoph Hellwig
2018-09-05 21:46 ` Jens Axboe
2018-09-15 7:03 ` Christoph Hellwig
3 siblings, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2018-09-05 13:19 UTC (permalink / raw)
To: Ming Lei
Cc: Jens Axboe, linux-block, Kent Overstreet, Dmitry Monakhov,
Christoph Hellwig, Hannes Reinecke
> + bio->bi_status = bio_integrity_process(bio, &bip->bio_iter, bi->profile->verify_fn);
Please split the overly long line.
Otherwise this looks fine:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] block: remove bio_rewind_iter()
2018-09-05 3:33 [PATCH] block: remove bio_rewind_iter() Ming Lei
2018-09-05 3:52 ` Kent Overstreet
2018-09-05 13:19 ` Christoph Hellwig
@ 2018-09-05 21:46 ` Jens Axboe
2018-09-15 7:03 ` Christoph Hellwig
3 siblings, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2018-09-05 21:46 UTC (permalink / raw)
To: Ming Lei
Cc: linux-block, Kent Overstreet, Dmitry Monakhov, Christoph Hellwig,
Hannes Reinecke
On 9/4/18 9:33 PM, Ming Lei wrote:
> It is pointed that bio_rewind_iter() is one very bad API[1]:
>
> 1) bio size may not be restored after rewinding
>
> 2) it causes some bogus change, such as 5151842b9d8732 (block: reset
> bi_iter.bi_done after splitting bio)
>
> 3) rewinding really makes things complicated wrt. bio splitting
>
> 4) unnecessary updating of .bi_done in fast path
>
> [1] https://marc.info/?t=153549924200005&r=1&w=2
>
> So this patch takes Kent's suggestion to restore one bio into its original
> state via saving bio iterator(struct bvec_iter) in bio_integrity_prep(),
> given now bio_rewind_iter() is only used by bio integrity code.
Applied, thanks Ming.
--
Jens Axboe
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] block: remove bio_rewind_iter()
2018-09-05 3:33 [PATCH] block: remove bio_rewind_iter() Ming Lei
` (2 preceding siblings ...)
2018-09-05 21:46 ` Jens Axboe
@ 2018-09-15 7:03 ` Christoph Hellwig
2018-09-15 14:41 ` Jens Axboe
3 siblings, 1 reply; 6+ messages in thread
From: Christoph Hellwig @ 2018-09-15 7:03 UTC (permalink / raw)
To: Ming Lei
Cc: Jens Axboe, linux-block, Kent Overstreet, Dmitry Monakhov,
Christoph Hellwig, Hannes Reinecke
On Wed, Sep 05, 2018 at 11:33:35AM +0800, Ming Lei wrote:
> It is pointed that bio_rewind_iter() is one very bad API[1]:
>
> 1) bio size may not be restored after rewinding
>
> 2) it causes some bogus change, such as 5151842b9d8732 (block: reset
> bi_iter.bi_done after splitting bio)
>
> 3) rewinding really makes things complicated wrt. bio splitting
>
> 4) unnecessary updating of .bi_done in fast path
>
> [1] https://marc.info/?t=153549924200005&r=1&w=2
Based on that this is a bug fix and should go to 4.19 instead of 4.20
as it is queued up right now..
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] block: remove bio_rewind_iter()
2018-09-15 7:03 ` Christoph Hellwig
@ 2018-09-15 14:41 ` Jens Axboe
0 siblings, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2018-09-15 14:41 UTC (permalink / raw)
To: Christoph Hellwig, Ming Lei
Cc: linux-block, Kent Overstreet, Dmitry Monakhov, Christoph Hellwig,
Hannes Reinecke
On 9/15/18 1:03 AM, Christoph Hellwig wrote:
> On Wed, Sep 05, 2018 at 11:33:35AM +0800, Ming Lei wrote:
>> It is pointed that bio_rewind_iter() is one very bad API[1]:
>>
>> 1) bio size may not be restored after rewinding
>>
>> 2) it causes some bogus change, such as 5151842b9d8732 (block: reset
>> bi_iter.bi_done after splitting bio)
>>
>> 3) rewinding really makes things complicated wrt. bio splitting
>>
>> 4) unnecessary updating of .bi_done in fast path
>>
>> [1] https://marc.info/?t=153549924200005&r=1&w=2
>
> Based on that this is a bug fix and should go to 4.19 instead of 4.20
> as it is queued up right now..
It's not a new issue (in fact not even close, we're about a year back),
hence not a strong reason to shove it into 4.19 vs 4.20. I'm fine
with subsequently marking it for stable.
--
Jens Axboe
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-09-15 14:41 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-05 3:33 [PATCH] block: remove bio_rewind_iter() Ming Lei
2018-09-05 3:52 ` Kent Overstreet
2018-09-05 13:19 ` Christoph Hellwig
2018-09-05 21:46 ` Jens Axboe
2018-09-15 7:03 ` Christoph Hellwig
2018-09-15 14:41 ` Jens Axboe
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.