All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dm: don't overallocate the tags space
@ 2019-02-08 15:52 Mikulas Patocka
  2019-02-08 15:58 ` Bart Van Assche
  2019-02-08 18:06 ` [PATCH] " Milan Broz
  0 siblings, 2 replies; 4+ messages in thread
From: Mikulas Patocka @ 2019-02-08 15:52 UTC (permalink / raw)
  To: Milan Broz, Mike Snitzer, Ming Lei; +Cc: dm-devel

bio_sectors returns the value in the units of 512-byte sectors (no matter
what's the real sector size of the device). dm-crypt multiplies
bio_sectors by on_disk_tag_size to calculate the space allocated for
integrity tags. If dm-crypt is running with sector size larger than 512,
it allocates more data than what's needed.

Device mapper trimmed this extra space when passing the bio to
dm-integrity, so this bug didn't result in any visible misbehavior. This
bug showed up when device mapper stopped trimming the bio.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Reported-by: Milan Broz <mbroz@redhat.com>

---
 drivers/md/dm-crypt.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux-2.6/drivers/md/dm-crypt.c
===================================================================
--- linux-2.6.orig/drivers/md/dm-crypt.c	2019-02-08 14:12:19.000000000 +0100
+++ linux-2.6/drivers/md/dm-crypt.c	2019-02-08 14:12:19.000000000 +0100
@@ -932,7 +932,7 @@ static int dm_crypt_integrity_io_alloc(s
 	if (IS_ERR(bip))
 		return PTR_ERR(bip);
 
-	tag_len = io->cc->on_disk_tag_size * bio_sectors(bio);
+	tag_len = io->cc->on_disk_tag_size * (bio_sectors(bio) >> io->cc->sector_shift);
 
 	bip->bip_iter.bi_size = tag_len;
 	bip->bip_iter.bi_sector = io->cc->start + io->sector;

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

* Re: [PATCH] dm: don't overallocate the tags space
  2019-02-08 15:52 [PATCH] dm: don't overallocate the tags space Mikulas Patocka
@ 2019-02-08 15:58 ` Bart Van Assche
  2019-02-08 16:02   ` Mike Snitzer
  2019-02-08 18:06 ` [PATCH] " Milan Broz
  1 sibling, 1 reply; 4+ messages in thread
From: Bart Van Assche @ 2019-02-08 15:58 UTC (permalink / raw)
  To: Mikulas Patocka, Milan Broz, Mike Snitzer, Ming Lei; +Cc: dm-devel

On Fri, 2019-02-08 at 10:52 -0500, Mikulas Patocka wrote:
> bio_sectors returns the value in the units of 512-byte sectors (no matter
> what's the real sector size of the device). dm-crypt multiplies
> bio_sectors by on_disk_tag_size to calculate the space allocated for
> integrity tags. If dm-crypt is running with sector size larger than 512,
> it allocates more data than what's needed.
> 
> Device mapper trimmed this extra space when passing the bio to
> dm-integrity, so this bug didn't result in any visible misbehavior. This
> bug showed up when device mapper stopped trimming the bio.
> 
> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> Reported-by: Milan Broz <mbroz@redhat.com>

Hi Mikulas,

Is this a fix for commit fa8db4948f52 ("dm: don't use bio_trim() afterall")?
If so, please consider adding a "Fixes:" tag.

Thanks,

Bart.

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

* Re: dm: don't overallocate the tags space
  2019-02-08 15:58 ` Bart Van Assche
@ 2019-02-08 16:02   ` Mike Snitzer
  0 siblings, 0 replies; 4+ messages in thread
From: Mike Snitzer @ 2019-02-08 16:02 UTC (permalink / raw)
  To: Bart Van Assche; +Cc: Ming Lei, Mikulas Patocka, dm-devel, Milan Broz

On Fri, Feb 08 2019 at 10:58am -0500,
Bart Van Assche <bvanassche@acm.org> wrote:

> On Fri, 2019-02-08 at 10:52 -0500, Mikulas Patocka wrote:
> > bio_sectors returns the value in the units of 512-byte sectors (no matter
> > what's the real sector size of the device). dm-crypt multiplies
> > bio_sectors by on_disk_tag_size to calculate the space allocated for
> > integrity tags. If dm-crypt is running with sector size larger than 512,
> > it allocates more data than what's needed.
> > 
> > Device mapper trimmed this extra space when passing the bio to
> > dm-integrity, so this bug didn't result in any visible misbehavior. This
> > bug showed up when device mapper stopped trimming the bio.
> > 
> > Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> > Reported-by: Milan Broz <mbroz@redhat.com>
> 
> Hi Mikulas,
> 
> Is this a fix for commit fa8db4948f52 ("dm: don't use bio_trim() afterall")?
> If so, please consider adding a "Fixes:" tag.

No, it isn't.  It stands on its own.

But yes, it could serve as a replacement for fa8db4948f52 ("dm: don't
use bio_trim() afterall").  But using bio_trim() isn't critical, and I
intend to remove all of DM's internal bio splitting for 5.1 or later
anyway.

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

* Re: [PATCH] dm: don't overallocate the tags space
  2019-02-08 15:52 [PATCH] dm: don't overallocate the tags space Mikulas Patocka
  2019-02-08 15:58 ` Bart Van Assche
@ 2019-02-08 18:06 ` Milan Broz
  1 sibling, 0 replies; 4+ messages in thread
From: Milan Broz @ 2019-02-08 18:06 UTC (permalink / raw)
  To: Mikulas Patocka, Mike Snitzer, Ming Lei; +Cc: dm-devel

On 08/02/2019 16:52, Mikulas Patocka wrote:
> bio_sectors returns the value in the units of 512-byte sectors (no matter
> what's the real sector size of the device). dm-crypt multiplies
> bio_sectors by on_disk_tag_size to calculate the space allocated for
> integrity tags. If dm-crypt is running with sector size larger than 512,
> it allocates more data than what's needed.
> 
> Device mapper trimmed this extra space when passing the bio to
> dm-integrity, so this bug didn't result in any visible misbehavior. This
> bug showed up when device mapper stopped trimming the bio.
> 
> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> Reported-by: Milan Broz <mbroz@redhat.com>
> 
> ---
>  drivers/md/dm-crypt.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> Index: linux-2.6/drivers/md/dm-crypt.c
> ===================================================================
> --- linux-2.6.orig/drivers/md/dm-crypt.c	2019-02-08 14:12:19.000000000 +0100
> +++ linux-2.6/drivers/md/dm-crypt.c	2019-02-08 14:12:19.000000000 +0100
> @@ -932,7 +932,7 @@ static int dm_crypt_integrity_io_alloc(s
>  	if (IS_ERR(bip))
>  		return PTR_ERR(bip);
>  
> -	tag_len = io->cc->on_disk_tag_size * bio_sectors(bio);
> +	tag_len = io->cc->on_disk_tag_size * (bio_sectors(bio) >> io->cc->sector_shift);
>  
>  	bip->bip_iter.bi_size = tag_len;
>  	bip->bip_iter.bi_sector = io->cc->start + io->sector;
> 

Yes, this was the problem (perhaps introduced by me since the first commit implementing
authenticated encryption).

With patch above even the bio_trim() works properly.

Tested-and-Reviewed-by: Milan Broz <gmazyland@gmail.com>

Thanks!
Milan

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

end of thread, other threads:[~2019-02-08 18:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-08 15:52 [PATCH] dm: don't overallocate the tags space Mikulas Patocka
2019-02-08 15:58 ` Bart Van Assche
2019-02-08 16:02   ` Mike Snitzer
2019-02-08 18:06 ` [PATCH] " Milan Broz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.