* [PATCH 4/5] block: Fix zero_fill_bio()
[not found] <20200516001914.17138-1-bvanassche@acm.org>
@ 2020-05-16 0:19 ` Bart Van Assche
2020-05-16 5:50 ` Ming Lei
0 siblings, 1 reply; 2+ messages in thread
From: Bart Van Assche @ 2020-05-16 0:19 UTC (permalink / raw)
To: Jens Axboe
Cc: linux-block, Christoph Hellwig, Ming Lei, Bart Van Assche, stable
Multiple block drivers use zero_fill_bio() to zero-initialize the data
buffer used for read operations. Make sure that all pages are zeroed
instead of only the first if one or more multi-page bvecs are used to
describe the data buffer.
Cc: Christoph Hellwig <hch@lst.de>
Cc: Ming Lei <ming.lei@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
block/bio.c | 27 ++++++++++++++++++++++-----
include/linux/bio.h | 1 +
2 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/block/bio.c b/block/bio.c
index 1594804fe8bc..48fcafbdae70 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -527,17 +527,34 @@ struct bio *bio_alloc_bioset(gfp_t gfp_mask, unsigned int nr_iovecs,
}
EXPORT_SYMBOL(bio_alloc_bioset);
+void zero_fill_bvec(const struct bio_vec *bvec)
+{
+ struct page *page = bvec->bv_page;
+ u32 offset = bvec->bv_offset;
+ u32 left = bvec->bv_len;
+
+ while (left) {
+ u32 len = min_t(u32, left, PAGE_SIZE - offset);
+ void *kaddr;
+
+ kaddr = kmap_atomic(page);
+ memset(kaddr + offset, 0, len);
+ flush_dcache_page(page);
+ kunmap_atomic(kaddr);
+ page++;
+ left -= len;
+ offset = 0;
+ }
+}
+EXPORT_SYMBOL(zero_fill_bvec);
+
void zero_fill_bio_iter(struct bio *bio, struct bvec_iter start)
{
- unsigned long flags;
struct bio_vec bv;
struct bvec_iter iter;
__bio_for_each_segment(bv, bio, iter, start) {
- char *data = bvec_kmap_irq(&bv, &flags);
- memset(data, 0, bv.bv_len);
- flush_dcache_page(bv.bv_page);
- bvec_kunmap_irq(data, &flags);
+ zero_fill_bvec(&bv);
}
}
EXPORT_SYMBOL(zero_fill_bio_iter);
diff --git a/include/linux/bio.h b/include/linux/bio.h
index 58e6134b1c05..9438cbdfa19e 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -455,6 +455,7 @@ extern void bio_copy_data_iter(struct bio *dst, struct bvec_iter *dst_iter,
extern void bio_copy_data(struct bio *dst, struct bio *src);
extern void bio_list_copy_data(struct bio *dst, struct bio *src);
extern void bio_free_pages(struct bio *bio);
+void zero_fill_bvec(const struct bio_vec *bvec);
void zero_fill_bio_iter(struct bio *bio, struct bvec_iter iter);
void bio_truncate(struct bio *bio, unsigned new_size);
void guard_bio_eod(struct bio *bio);
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 4/5] block: Fix zero_fill_bio()
2020-05-16 0:19 ` [PATCH 4/5] block: Fix zero_fill_bio() Bart Van Assche
@ 2020-05-16 5:50 ` Ming Lei
0 siblings, 0 replies; 2+ messages in thread
From: Ming Lei @ 2020-05-16 5:50 UTC (permalink / raw)
To: Bart Van Assche; +Cc: Jens Axboe, linux-block, Christoph Hellwig, stable
On Fri, May 15, 2020 at 05:19:13PM -0700, Bart Van Assche wrote:
> Multiple block drivers use zero_fill_bio() to zero-initialize the data
> buffer used for read operations. Make sure that all pages are zeroed
> instead of only the first if one or more multi-page bvecs are used to
> describe the data buffer.
>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Ming Lei <ming.lei@redhat.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
> block/bio.c | 27 ++++++++++++++++++++++-----
> include/linux/bio.h | 1 +
> 2 files changed, 23 insertions(+), 5 deletions(-)
>
> diff --git a/block/bio.c b/block/bio.c
> index 1594804fe8bc..48fcafbdae70 100644
> --- a/block/bio.c
> +++ b/block/bio.c
> @@ -527,17 +527,34 @@ struct bio *bio_alloc_bioset(gfp_t gfp_mask, unsigned int nr_iovecs,
> }
> EXPORT_SYMBOL(bio_alloc_bioset);
>
> +void zero_fill_bvec(const struct bio_vec *bvec)
> +{
> + struct page *page = bvec->bv_page;
> + u32 offset = bvec->bv_offset;
> + u32 left = bvec->bv_len;
> +
> + while (left) {
> + u32 len = min_t(u32, left, PAGE_SIZE - offset);
> + void *kaddr;
> +
> + kaddr = kmap_atomic(page);
> + memset(kaddr + offset, 0, len);
> + flush_dcache_page(page);
> + kunmap_atomic(kaddr);
> + page++;
> + left -= len;
> + offset = 0;
> + }
> +}
> +EXPORT_SYMBOL(zero_fill_bvec);
> +
> void zero_fill_bio_iter(struct bio *bio, struct bvec_iter start)
> {
> - unsigned long flags;
> struct bio_vec bv;
> struct bvec_iter iter;
>
> __bio_for_each_segment(bv, bio, iter, start) {
The 'bv' from __bio_for_each_segment() is single page bvec, and so far
only [__]bio_for_each_bvec iterates over multi-page bvec.
So nothing to be fixed and this patch isn't necessary.
Thanks,
Ming
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-05-16 5:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20200516001914.17138-1-bvanassche@acm.org>
2020-05-16 0:19 ` [PATCH 4/5] block: Fix zero_fill_bio() Bart Van Assche
2020-05-16 5:50 ` Ming Lei
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).