Linux-Block Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] lightnvm: pblk: Fix freeing merged pages
@ 2019-05-15  0:39 Heiner Litz
  2019-05-15  9:12 ` Javier González
  2019-05-24 14:10 ` Matias Bjørling
  0 siblings, 2 replies; 3+ messages in thread
From: Heiner Litz @ 2019-05-15  0:39 UTC (permalink / raw)
  To: mb
  Cc: javier, hans.holmberg, igor.j.konopko, linux-block, linux-kernel,
	Heiner Litz

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] lightnvm: pblk: Fix freeing merged pages
  2019-05-15  0:39 [PATCH] lightnvm: pblk: Fix freeing merged pages Heiner Litz
@ 2019-05-15  9:12 ` Javier González
  2019-05-24 14:10 ` Matias Bjørling
  1 sibling, 0 replies; 3+ messages in thread
From: Javier González @ 2019-05-15  9:12 UTC (permalink / raw)
  To: Heiner Litz
  Cc: Matias Bjørling, Hans Holmberg, Konopko, Igor J,
	linux-block, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1427 bytes --]

> 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>


[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] lightnvm: pblk: Fix freeing merged pages
  2019-05-15  0:39 [PATCH] lightnvm: pblk: Fix freeing merged pages Heiner Litz
  2019-05-15  9:12 ` Javier González
@ 2019-05-24 14:10 ` Matias Bjørling
  1 sibling, 0 replies; 3+ messages in thread
From: Matias Bjørling @ 2019-05-24 14:10 UTC (permalink / raw)
  To: Heiner Litz
  Cc: javier, Hans Holmberg, igor.j.konopko, linux-block, linux-kernel

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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-15  0:39 [PATCH] lightnvm: pblk: Fix freeing merged pages Heiner Litz
2019-05-15  9:12 ` Javier González
2019-05-24 14:10 ` Matias Bjørling

Linux-Block Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-block/0 linux-block/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-block linux-block/ https://lore.kernel.org/linux-block \
		linux-block@vger.kernel.org linux-block@archiver.kernel.org
	public-inbox-index linux-block


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-block


AGPL code for this site: git clone https://public-inbox.org/ public-inbox