* [PATCH] block: clarify that bio_add_page() and related helpers can add multi pages
@ 2019-03-28 3:50 Ming Lei
2019-03-28 14:21 ` Jens Axboe
0 siblings, 1 reply; 7+ messages in thread
From: Ming Lei @ 2019-03-28 3:50 UTC (permalink / raw)
To: Jens Axboe
Cc: linux-block, Ming Lei, linux-xfs, linux-fsdevel, Christoph Hellwig
bio_add_page() and __bio_add_page() are capable of adding pages into
bio, and now we have at least two such usages alreay:
- __bio_iov_bvec_add_pages()
- nvmet_bdev_execute_rw().
So update comments on these two helpers.
The thing is a bit special for __bio_try_merge_page(), given the caller
needs to know if the new added page is same with the last added page,
then it isn't safe to pass multi-page in case that 'same_page' is true,
so adds warning on potential misuse, and updates comment on
__bio_try_merge_page().
Cc: linux-xfs@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org
Cc: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
block/bio.c | 40 ++++++++++++++++++++++------------------
include/linux/bio.h | 4 ++--
2 files changed, 24 insertions(+), 20 deletions(-)
diff --git a/block/bio.c b/block/bio.c
index b64cedc7f87c..0cfb2fd981c3 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -750,9 +750,9 @@ EXPORT_SYMBOL(bio_add_pc_page);
/**
* __bio_try_merge_page - try appending data to an existing bvec.
* @bio: destination bio
- * @page: page to add
+ * @start_page: start page to add
* @len: length of the data to add
- * @off: offset of the data in @page
+ * @off: offset of the data relative to @start_page
* @same_page: if %true only merge if the new data is in the same physical
* page as the last segment of the bio.
*
@@ -760,9 +760,11 @@ EXPORT_SYMBOL(bio_add_pc_page);
* a useful optimisation for file systems with a block size smaller than the
* page size.
*
+ * Warn if @same_page is true and (@len, @off) crosses pages.
+ *
* Return %true on success or %false on failure.
*/
-bool __bio_try_merge_page(struct bio *bio, struct page *page,
+bool __bio_try_merge_page(struct bio *bio, struct page *start_page,
unsigned int len, unsigned int off, bool same_page)
{
if (WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED)))
@@ -772,10 +774,12 @@ bool __bio_try_merge_page(struct bio *bio, struct page *page,
struct bio_vec *bv = &bio->bi_io_vec[bio->bi_vcnt - 1];
phys_addr_t vec_end_addr = page_to_phys(bv->bv_page) +
bv->bv_offset + bv->bv_len - 1;
- phys_addr_t page_addr = page_to_phys(page);
+ phys_addr_t page_addr = page_to_phys(start_page);
if (vec_end_addr + 1 != page_addr + off)
return false;
+
+ WARN_ON_ONCE(same_page && (len + off) > PAGE_SIZE);
if (same_page && (vec_end_addr & PAGE_MASK) != page_addr)
return false;
@@ -788,16 +792,16 @@ bool __bio_try_merge_page(struct bio *bio, struct page *page,
EXPORT_SYMBOL_GPL(__bio_try_merge_page);
/**
- * __bio_add_page - add page to a bio in a new segment
+ * __bio_add_page - add page(s) to a bio in a new segment
* @bio: destination bio
- * @page: page to add
- * @len: length of the data to add
- * @off: offset of the data in @page
+ * @start_page: start page to add
+ * @len: length of the data to add, may cross pages
+ * @off: offset of the data relative to @start_page, may cross pages
*
* Add the data at @page + @off to @bio as a new bvec. The caller must ensure
* that @bio has space for another bvec.
*/
-void __bio_add_page(struct bio *bio, struct page *page,
+void __bio_add_page(struct bio *bio, struct page *start_page,
unsigned int len, unsigned int off)
{
struct bio_vec *bv = &bio->bi_io_vec[bio->bi_vcnt];
@@ -805,7 +809,7 @@ void __bio_add_page(struct bio *bio, struct page *page,
WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED));
WARN_ON_ONCE(bio_full(bio));
- bv->bv_page = page;
+ bv->bv_page = start_page;
bv->bv_offset = off;
bv->bv_len = len;
@@ -815,22 +819,22 @@ void __bio_add_page(struct bio *bio, struct page *page,
EXPORT_SYMBOL_GPL(__bio_add_page);
/**
- * bio_add_page - attempt to add page to bio
+ * bio_add_page - attempt to add page(s) to bio
* @bio: destination bio
- * @page: page to add
- * @len: vec entry length
- * @offset: vec entry offset
+ * @start_page: start page to add
+ * @len: vec entry length, may cross pages
+ * @offset: vec entry offset relative to @start_page, may cross pages
*
- * Attempt to add a page to the bio_vec maplist. This will only fail
+ * Attempt to add page(s) to the bio_vec maplist. This will only fail
* if either bio->bi_vcnt == bio->bi_max_vecs or it's a cloned bio.
*/
-int bio_add_page(struct bio *bio, struct page *page,
+int bio_add_page(struct bio *bio, struct page *start_page,
unsigned int len, unsigned int offset)
{
- if (!__bio_try_merge_page(bio, page, len, offset, false)) {
+ if (!__bio_try_merge_page(bio, start_page, len, offset, false)) {
if (bio_full(bio))
return 0;
- __bio_add_page(bio, page, len, offset);
+ __bio_add_page(bio, start_page, len, offset);
}
return len;
}
diff --git a/include/linux/bio.h b/include/linux/bio.h
index bb6090aa165d..40acfe5dc99f 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -432,9 +432,9 @@ void bio_chain(struct bio *, struct bio *);
extern int bio_add_page(struct bio *, struct page *, unsigned int,unsigned int);
extern int bio_add_pc_page(struct request_queue *, struct bio *, struct page *,
unsigned int, unsigned int);
-bool __bio_try_merge_page(struct bio *bio, struct page *page,
+bool __bio_try_merge_page(struct bio *bio, struct page *start_page,
unsigned int len, unsigned int off, bool same_page);
-void __bio_add_page(struct bio *bio, struct page *page,
+void __bio_add_page(struct bio *bio, struct page *start_page,
unsigned int len, unsigned int off);
int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter);
struct rq_map_data;
--
2.9.5
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] block: clarify that bio_add_page() and related helpers can add multi pages
2019-03-28 3:50 [PATCH] block: clarify that bio_add_page() and related helpers can add multi pages Ming Lei
@ 2019-03-28 14:21 ` Jens Axboe
2019-03-28 15:03 ` Christoph Hellwig
0 siblings, 1 reply; 7+ messages in thread
From: Jens Axboe @ 2019-03-28 14:21 UTC (permalink / raw)
To: Ming Lei; +Cc: linux-block, linux-xfs, linux-fsdevel, Christoph Hellwig
On 3/27/19 9:50 PM, Ming Lei wrote:
> bio_add_page() and __bio_add_page() are capable of adding pages into
> bio, and now we have at least two such usages alreay:
>
> - __bio_iov_bvec_add_pages()
> - nvmet_bdev_execute_rw().
>
> So update comments on these two helpers.
>
> The thing is a bit special for __bio_try_merge_page(), given the caller
> needs to know if the new added page is same with the last added page,
> then it isn't safe to pass multi-page in case that 'same_page' is true,
> so adds warning on potential misuse, and updates comment on
> __bio_try_merge_page().
This is going to create a needless conflict between 5.1 and the 5.2
block tree. I haven't pushed the 5.2 tree out yet, plan to do so
this week after I've pushed the current 5.1 patches. Can you respin
this one on top of for-5.2/block when it comes out?
--
Jens Axboe
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] block: clarify that bio_add_page() and related helpers can add multi pages
2019-03-28 14:21 ` Jens Axboe
@ 2019-03-28 15:03 ` Christoph Hellwig
2019-03-28 15:07 ` Jens Axboe
2019-03-28 15:31 ` Ming Lei
0 siblings, 2 replies; 7+ messages in thread
From: Christoph Hellwig @ 2019-03-28 15:03 UTC (permalink / raw)
To: Jens Axboe
Cc: Ming Lei, linux-block, linux-xfs, linux-fsdevel, Christoph Hellwig
On Thu, Mar 28, 2019 at 08:21:55AM -0600, Jens Axboe wrote:
> This is going to create a needless conflict between 5.1 and the 5.2
> block tree. I haven't pushed the 5.2 tree out yet, plan to do so
> this week after I've pushed the current 5.1 patches. Can you respin
> this one on top of for-5.2/block when it comes out?
Can we also drop the parameter name rename and just add the comments?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] block: clarify that bio_add_page() and related helpers can add multi pages
2019-03-28 15:03 ` Christoph Hellwig
@ 2019-03-28 15:07 ` Jens Axboe
2019-03-28 15:31 ` Ming Lei
1 sibling, 0 replies; 7+ messages in thread
From: Jens Axboe @ 2019-03-28 15:07 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: Ming Lei, linux-block, linux-xfs, linux-fsdevel
On 3/28/19 9:03 AM, Christoph Hellwig wrote:
> On Thu, Mar 28, 2019 at 08:21:55AM -0600, Jens Axboe wrote:
>> This is going to create a needless conflict between 5.1 and the 5.2
>> block tree. I haven't pushed the 5.2 tree out yet, plan to do so
>> this week after I've pushed the current 5.1 patches. Can you respin
>> this one on top of for-5.2/block when it comes out?
>
> Can we also drop the parameter name rename and just add the comments?
Yeah, that might be better to avoid needless churn.
--
Jens Axboe
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] block: clarify that bio_add_page() and related helpers can add multi pages
2019-03-28 15:03 ` Christoph Hellwig
2019-03-28 15:07 ` Jens Axboe
@ 2019-03-28 15:31 ` Ming Lei
1 sibling, 0 replies; 7+ messages in thread
From: Ming Lei @ 2019-03-28 15:31 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Jens Axboe, Ming Lei, linux-block, open list:XFS FILESYSTEM,
Linux FS Devel
On Thu, Mar 28, 2019 at 11:04 PM Christoph Hellwig <hch@infradead.org> wrote:
>
> On Thu, Mar 28, 2019 at 08:21:55AM -0600, Jens Axboe wrote:
> > This is going to create a needless conflict between 5.1 and the 5.2
> > block tree. I haven't pushed the 5.2 tree out yet, plan to do so
> > this week after I've pushed the current 5.1 patches. Can you respin
> > this one on top of for-5.2/block when it comes out?
>
> Can we also drop the parameter name rename and just add the comments?
OK, I will drop the name rename change and send it out after for-5.2 comes out.
Thanks,
Ming Lei
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] block: clarify that bio_add_page() and related helpers can add multi pages
2019-04-02 2:36 Ming Lei
@ 2019-04-03 14:44 ` Christoph Hellwig
0 siblings, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2019-04-03 14:44 UTC (permalink / raw)
To: Ming Lei
Cc: Jens Axboe, linux-block, linux-xfs, linux-fsdevel, Christoph Hellwig
Looks good,
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] block: clarify that bio_add_page() and related helpers can add multi pages
@ 2019-04-02 2:36 Ming Lei
2019-04-03 14:44 ` Christoph Hellwig
0 siblings, 1 reply; 7+ messages in thread
From: Ming Lei @ 2019-04-02 2:36 UTC (permalink / raw)
To: Jens Axboe
Cc: linux-block, Ming Lei, linux-xfs, linux-fsdevel, Christoph Hellwig
bio_add_page() and __bio_add_page() are capable of adding pages into
bio, and now we have at least two such usages alreay:
- __bio_iov_bvec_add_pages()
- nvmet_bdev_execute_rw().
So update comments on these two helpers.
The thing is a bit special for __bio_try_merge_page(), given the caller
needs to know if the new added page is same with the last added page,
then it isn't safe to pass multi-page in case that 'same_page' is true,
so adds warning on potential misuse, and updates comment on
__bio_try_merge_page().
Cc: linux-xfs@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org
Cc: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
block/bio.c | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/block/bio.c b/block/bio.c
index 8d516d508ae3..07315056c2f6 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -662,6 +662,8 @@ static inline bool page_is_mergeable(const struct bio_vec *bv,
if (same_page && (vec_end_addr & PAGE_MASK) != page_addr)
return false;
+ WARN_ON_ONCE(same_page && (len + off) > PAGE_SIZE);
+
return true;
}
@@ -781,9 +783,9 @@ EXPORT_SYMBOL(bio_add_pc_page);
/**
* __bio_try_merge_page - try appending data to an existing bvec.
* @bio: destination bio
- * @page: page to add
+ * @page: start page to add
* @len: length of the data to add
- * @off: offset of the data in @page
+ * @off: offset of the data relative to @page
* @same_page: if %true only merge if the new data is in the same physical
* page as the last segment of the bio.
*
@@ -791,6 +793,8 @@ EXPORT_SYMBOL(bio_add_pc_page);
* a useful optimisation for file systems with a block size smaller than the
* page size.
*
+ * Warn if (@len, @off) crosses pages in case that @same_page is true.
+ *
* Return %true on success or %false on failure.
*/
bool __bio_try_merge_page(struct bio *bio, struct page *page,
@@ -813,11 +817,11 @@ bool __bio_try_merge_page(struct bio *bio, struct page *page,
EXPORT_SYMBOL_GPL(__bio_try_merge_page);
/**
- * __bio_add_page - add page to a bio in a new segment
+ * __bio_add_page - add page(s) to a bio in a new segment
* @bio: destination bio
- * @page: page to add
- * @len: length of the data to add
- * @off: offset of the data in @page
+ * @page: start page to add
+ * @len: length of the data to add, may cross pages
+ * @off: offset of the data relative to @page, may cross pages
*
* Add the data at @page + @off to @bio as a new bvec. The caller must ensure
* that @bio has space for another bvec.
@@ -840,13 +844,13 @@ void __bio_add_page(struct bio *bio, struct page *page,
EXPORT_SYMBOL_GPL(__bio_add_page);
/**
- * bio_add_page - attempt to add page to bio
+ * bio_add_page - attempt to add page(s) to bio
* @bio: destination bio
- * @page: page to add
- * @len: vec entry length
- * @offset: vec entry offset
+ * @page: start page to add
+ * @len: vec entry length, may cross pages
+ * @offset: vec entry offset relative to @page, may cross pages
*
- * Attempt to add a page to the bio_vec maplist. This will only fail
+ * Attempt to add page(s) to the bio_vec maplist. This will only fail
* if either bio->bi_vcnt == bio->bi_max_vecs or it's a cloned bio.
*/
int bio_add_page(struct bio *bio, struct page *page,
--
2.9.5
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-04-03 14:44 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-28 3:50 [PATCH] block: clarify that bio_add_page() and related helpers can add multi pages Ming Lei
2019-03-28 14:21 ` Jens Axboe
2019-03-28 15:03 ` Christoph Hellwig
2019-03-28 15:07 ` Jens Axboe
2019-03-28 15:31 ` Ming Lei
2019-04-02 2:36 Ming Lei
2019-04-03 14:44 ` Christoph Hellwig
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).