public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bio_integrity_add_page: check for BIO_POOL_NONE before determining nr_vecs on slab
@ 2014-01-29 16:45 David Milburn
  2014-02-04  3:55 ` Martin K. Petersen
  0 siblings, 1 reply; 3+ messages in thread
From: David Milburn @ 2014-01-29 16:45 UTC (permalink / raw)
  To: axboe, martin.petersen, JBottomley; +Cc: linux-kernel, linux-scsi

When enabling DIX T10-DIF-TYPE1-IP protection you can hit the
bip_vec full condition which fails to attach the integrity metadata
and returns 0 back to bio_integrity_prep()

[    3.837493] sd 0:0:17:1089486880: [sda] Enabling DIX T10-DIF-TYPE1-IP protection
[    3.839089] sd 0:0:17:1089486880: [sda] Attached SCSI disk
[    3.841309] bio_integrity_add_page: bip_vec full

<debug>
[  439.180928] bio_integrity_prep: sectors 8 len 64
[  439.180929] bio_integrity_prep: nr_pages 1 end 706577 start 706576
[  439.180930] bio_integrity_alloc: bs 00000000b2c87880 nr_vecs 1
[  439.180931] bio_integrity_alloc: nr_vecs 1 inline_vecs 4
[  439.180932] bio_integrity_alloc: bip->bip_vec 00000000aeaf9158 bip->bip_slab 15
[  439.180933] bio_integrity_prep: offset 704 nr_pages 1
[  439.180934] bio_integrity_add_page: len 64 offset 704
[  439.180935] bio_integrity_add_page: bip_vec full bip_vcnt 0 bvec_nr_vecs 0 bip_slab 15
<debug>

Ultimately you can BUG_ON(!nents) in scsi_alloc_sgtable()

scsi_init_io
 blk_integrity_rq
  scsi_alloc_sgtable

With attached patch device functions normally

<dmesg>
[  198.481838] sd 0:0:24:1089486880: [sda] Enabling DIF Type 1 protection
[  198.481845] sd 0:0:24:1089486880: [sda] 209715200 512-byte logical blocks: (107 GB/100 GiB)
[  198.482552] sd 0:0:24:1089486880: [sda] Write Protect is off
[  198.482556] sd 0:0:24:1089486880: [sda] Mode Sense: ed 00 00 08
[  198.482889] sd 0:0:24:1089486880: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[  198.485850]  sda: sda1
[  198.485926] sd 0:0:24:1089486880: [sda] Enabling DIX T10-DIF-TYPE1-IP protection
[  198.487652] sd 0:0:24:1089486880: [sda] Attached SCSI disk
[  276.566682] XFS (sda1): Mounting Filesystem
[  276.576558] XFS (sda1): Ending clean mount
<dmesg>

Signed-off-by: David Milburn <dmilburn@redhat.com>
---
 fs/bio-integrity.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/fs/bio-integrity.c b/fs/bio-integrity.c
index 45e944f..9d36a09 100644
--- a/fs/bio-integrity.c
+++ b/fs/bio-integrity.c
@@ -129,7 +129,8 @@ int bio_integrity_add_page(struct bio *bio, struct page *page,
 	struct bio_integrity_payload *bip = bio->bi_integrity;
 	struct bio_vec *iv;
 
-	if (bip->bip_vcnt >= bvec_nr_vecs(bip->bip_slab)) {
+	if (bip->bip_slab != BIO_POOL_NONE && 
+	    bip->bip_vcnt >= bvec_nr_vecs(bip->bip_slab)) {
 		printk(KERN_ERR "%s: bip_vec full\n", __func__);
 		return 0;
 	}

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

* Re: [PATCH] bio_integrity_add_page: check for BIO_POOL_NONE before determining nr_vecs on slab
  2014-01-29 16:45 [PATCH] bio_integrity_add_page: check for BIO_POOL_NONE before determining nr_vecs on slab David Milburn
@ 2014-02-04  3:55 ` Martin K. Petersen
  2014-02-05 14:32   ` David Milburn
  0 siblings, 1 reply; 3+ messages in thread
From: Martin K. Petersen @ 2014-02-04  3:55 UTC (permalink / raw)
  To: David Milburn
  Cc: axboe, martin.petersen, JBottomley, linux-kernel, linux-scsi

>>>>> "David" == David Milburn <dmilburn@redhat.com> writes:

David> When enabling DIX T10-DIF-TYPE1-IP protection you can hit the
David> bip_vec full condition which fails to attach the integrity
David> metadata and returns 0 back to bio_integrity_prep()

Looks like Kent accidentally broke this when he changed the bvec pool
setup.

David> - if (bip->bip_vcnt >= bvec_nr_vecs(bip->bip_slab)) {
David> + if (bip->bip_slab != BIO_POOL_NONE &&
David> +     bip->bip_vcnt >= bvec_nr_vecs(bip->bip_slab)) {
David>  		printk(KERN_ERR "%s: bip_vec full\n", __func__);
David>  		return 0;
David>  	}

We still need to check that the page will actually fit, though:


block: Fix nr_vecs for inline integrity vectors

Commit 9f060e2231ca changed the way we handle allocations for the
integrity vectors. When the vectors are inline there is no associated
slab and consequently bvec_nr_vecs() returns 0. Ensure that we check
against BIP_INLINE_VECS in that case.

Reported-by: David Milburn <dmilburn@redhat.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

diff --git a/fs/bio-integrity.c b/fs/bio-integrity.c
index fc60b31453ee..6dea2b90b4d5 100644
--- a/fs/bio-integrity.c
+++ b/fs/bio-integrity.c
@@ -114,6 +114,14 @@ void bio_integrity_free(struct bio *bio)
 }
 EXPORT_SYMBOL(bio_integrity_free);
 
+static inline unsigned int bip_integrity_vecs(struct bio_integrity_payload *bip)
+{
+	if (bip->bip_slab == BIO_POOL_NONE)
+		return BIP_INLINE_VECS;
+
+	return bvec_nr_vecs(bip->bip_slab);
+}
+
 /**
  * bio_integrity_add_page - Attach integrity metadata
  * @bio:	bio to update
@@ -129,7 +137,7 @@ int bio_integrity_add_page(struct bio *bio, struct page *page,
 	struct bio_integrity_payload *bip = bio->bi_integrity;
 	struct bio_vec *iv;
 
-	if (bip->bip_vcnt >= bvec_nr_vecs(bip->bip_slab)) {
+	if (bip->bip_vcnt >= bip_integrity_vecs(bip)) {
 		printk(KERN_ERR "%s: bip_vec full\n", __func__);
 		return 0;
 	}

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

* Re: [PATCH] bio_integrity_add_page: check for BIO_POOL_NONE before determining nr_vecs on slab
  2014-02-04  3:55 ` Martin K. Petersen
@ 2014-02-05 14:32   ` David Milburn
  0 siblings, 0 replies; 3+ messages in thread
From: David Milburn @ 2014-02-05 14:32 UTC (permalink / raw)
  To: Martin K. Petersen; +Cc: axboe, JBottomley, linux-kernel, linux-scsi

On 02/03/2014 09:55 PM, Martin K. Petersen wrote:
>>>>>> "David" == David Milburn <dmilburn@redhat.com> writes:
>
> David> When enabling DIX T10-DIF-TYPE1-IP protection you can hit the
> David> bip_vec full condition which fails to attach the integrity
> David> metadata and returns 0 back to bio_integrity_prep()
>
> Looks like Kent accidentally broke this when he changed the bvec pool
> setup.
>
> David> - if (bip->bip_vcnt >= bvec_nr_vecs(bip->bip_slab)) {
> David> + if (bip->bip_slab != BIO_POOL_NONE &&
> David> +     bip->bip_vcnt >= bvec_nr_vecs(bip->bip_slab)) {
> David>  		printk(KERN_ERR "%s: bip_vec full\n", __func__);
> David>  		return 0;
> David>  	}
>
> We still need to check that the page will actually fit, though:
>
>
> block: Fix nr_vecs for inline integrity vectors
>
> Commit 9f060e2231ca changed the way we handle allocations for the
> integrity vectors. When the vectors are inline there is no associated
> slab and consequently bvec_nr_vecs() returns 0. Ensure that we check
> against BIP_INLINE_VECS in that case.
>
> Reported-by: David Milburn <dmilburn@redhat.com>
> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
>
> diff --git a/fs/bio-integrity.c b/fs/bio-integrity.c
> index fc60b31453ee..6dea2b90b4d5 100644
> --- a/fs/bio-integrity.c
> +++ b/fs/bio-integrity.c
> @@ -114,6 +114,14 @@ void bio_integrity_free(struct bio *bio)
>   }
>   EXPORT_SYMBOL(bio_integrity_free);
>
> +static inline unsigned int bip_integrity_vecs(struct bio_integrity_payload *bip)
> +{
> +	if (bip->bip_slab == BIO_POOL_NONE)
> +		return BIP_INLINE_VECS;
> +
> +	return bvec_nr_vecs(bip->bip_slab);
> +}
> +
>   /**
>    * bio_integrity_add_page - Attach integrity metadata
>    * @bio:	bio to update
> @@ -129,7 +137,7 @@ int bio_integrity_add_page(struct bio *bio, struct page *page,
>   	struct bio_integrity_payload *bip = bio->bi_integrity;
>   	struct bio_vec *iv;
>
> -	if (bip->bip_vcnt >= bvec_nr_vecs(bip->bip_slab)) {
> +	if (bip->bip_vcnt >= bip_integrity_vecs(bip)) {
>   		printk(KERN_ERR "%s: bip_vec full\n", __func__);
>   		return 0;
>   	}
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>

Hi Martin,

Your patch has been tested successfully.

Thanks for your help,
David


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

end of thread, other threads:[~2014-02-05 14:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-29 16:45 [PATCH] bio_integrity_add_page: check for BIO_POOL_NONE before determining nr_vecs on slab David Milburn
2014-02-04  3:55 ` Martin K. Petersen
2014-02-05 14:32   ` David Milburn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox