diff mbox series

lightnvm: pblk: Fix freeing merged pages

Message ID 20190515003952.12541-1-hlitz@ucsc.edu (mailing list archive)
State New, archived
Headers show
Series lightnvm: pblk: Fix freeing merged pages | expand

Commit Message

Heiner Litz May 15, 2019, 12:39 a.m. UTC
bio_add_pc_page() may merge pages when a bio is padded due to a flush.
Fix iteration over the bio to free the correct pages in case of a merge.

Signed-off-by: Heiner Litz <hlitz@ucsc.edu>
---
 drivers/lightnvm/pblk-core.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

Comments

Javier González May 15, 2019, 9:12 a.m. UTC | #1
> On 15 May 2019, at 02.39, Heiner Litz <hlitz@ucsc.edu> wrote:
> 
> bio_add_pc_page() may merge pages when a bio is padded due to a flush.
> Fix iteration over the bio to free the correct pages in case of a merge.
> 
> Signed-off-by: Heiner Litz <hlitz@ucsc.edu>
> ---
> drivers/lightnvm/pblk-core.c | 18 ++++++++++--------
> 1 file changed, 10 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/lightnvm/pblk-core.c b/drivers/lightnvm/pblk-core.c
> index 773537804319..88d61b27a9ab 100644
> --- a/drivers/lightnvm/pblk-core.c
> +++ b/drivers/lightnvm/pblk-core.c
> @@ -323,14 +323,16 @@ void pblk_free_rqd(struct pblk *pblk, struct nvm_rq *rqd, int type)
> void pblk_bio_free_pages(struct pblk *pblk, struct bio *bio, int off,
> 			 int nr_pages)
> {
> -	struct bio_vec bv;
> -	int i;
> -
> -	WARN_ON(off + nr_pages != bio->bi_vcnt);
> -
> -	for (i = off; i < nr_pages + off; i++) {
> -		bv = bio->bi_io_vec[i];
> -		mempool_free(bv.bv_page, &pblk->page_bio_pool);
> +	struct bio_vec *bv;
> +	struct page *page;
> +	int i,e, nbv = 0;
> +
> +	for (i = 0; i < bio->bi_vcnt; i++) {
> +		bv = &bio->bi_io_vec[i];
> +		page = bv->bv_page;
> +		for (e = 0; e < bv->bv_len; e += PBLK_EXPOSED_PAGE_SIZE, nbv++)
> +			if (nbv >= off)
> +				mempool_free(page++, &pblk->page_bio_pool);
> 	}
> }
> 
> --
> 2.17.1

Looks good to me.

Reviewed-by: Javier González <javier@javigon.com>
Matias Bjorling May 24, 2019, 2:10 p.m. UTC | #2
On 5/15/19 2:39 AM, Heiner Litz wrote:
> bio_add_pc_page() may merge pages when a bio is padded due to a flush.
> Fix iteration over the bio to free the correct pages in case of a merge.
> 
> Signed-off-by: Heiner Litz <hlitz@ucsc.edu>
> ---
>   drivers/lightnvm/pblk-core.c | 18 ++++++++++--------
>   1 file changed, 10 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/lightnvm/pblk-core.c b/drivers/lightnvm/pblk-core.c
> index 773537804319..88d61b27a9ab 100644
> --- a/drivers/lightnvm/pblk-core.c
> +++ b/drivers/lightnvm/pblk-core.c
> @@ -323,14 +323,16 @@ void pblk_free_rqd(struct pblk *pblk, struct nvm_rq *rqd, int type)
>   void pblk_bio_free_pages(struct pblk *pblk, struct bio *bio, int off,
>   			 int nr_pages)
>   {
> -	struct bio_vec bv;
> -	int i;
> -
> -	WARN_ON(off + nr_pages != bio->bi_vcnt);
> -
> -	for (i = off; i < nr_pages + off; i++) {
> -		bv = bio->bi_io_vec[i];
> -		mempool_free(bv.bv_page, &pblk->page_bio_pool);
> +	struct bio_vec *bv;
> +	struct page *page;
> +	int i,e, nbv = 0;
> +
> +	for (i = 0; i < bio->bi_vcnt; i++) {
> +		bv = &bio->bi_io_vec[i];
> +		page = bv->bv_page;
> +		for (e = 0; e < bv->bv_len; e += PBLK_EXPOSED_PAGE_SIZE, nbv++)
> +			if (nbv >= off)
> +				mempool_free(page++, &pblk->page_bio_pool);
>   	}
>   }
>   
> 

Thanks Heiner. Picked up for 5.3.
diff mbox series

Patch

diff --git a/drivers/lightnvm/pblk-core.c b/drivers/lightnvm/pblk-core.c
index 773537804319..88d61b27a9ab 100644
--- a/drivers/lightnvm/pblk-core.c
+++ b/drivers/lightnvm/pblk-core.c
@@ -323,14 +323,16 @@  void pblk_free_rqd(struct pblk *pblk, struct nvm_rq *rqd, int type)
 void pblk_bio_free_pages(struct pblk *pblk, struct bio *bio, int off,
 			 int nr_pages)
 {
-	struct bio_vec bv;
-	int i;
-
-	WARN_ON(off + nr_pages != bio->bi_vcnt);
-
-	for (i = off; i < nr_pages + off; i++) {
-		bv = bio->bi_io_vec[i];
-		mempool_free(bv.bv_page, &pblk->page_bio_pool);
+	struct bio_vec *bv;
+	struct page *page;
+	int i,e, nbv = 0;
+
+	for (i = 0; i < bio->bi_vcnt; i++) {
+		bv = &bio->bi_io_vec[i];
+		page = bv->bv_page;
+		for (e = 0; e < bv->bv_len; e += PBLK_EXPOSED_PAGE_SIZE, nbv++)
+			if (nbv >= off)
+				mempool_free(page++, &pblk->page_bio_pool);
 	}
 }