linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Btrfs: make sure there is always room for generation number
@ 2018-07-03  0:00 Zhihui Zhang
  2018-07-04 15:14 ` David Sterba
  2018-07-04 15:21 ` David Sterba
  0 siblings, 2 replies; 4+ messages in thread
From: Zhihui Zhang @ 2018-07-03  0:00 UTC (permalink / raw)
  To: jbacik, dsterba; +Cc: linux-btrfs

io_ctl_set_generation() assumes that the generation number shares
the same page with inline CRCs. Let's make sure this is always true.

Signed-off-by: Zhihui Zhang <zzhsuny@gmail.com>
---
 fs/btrfs/free-space-cache.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index d5f80cb300be..9aa0fbf16515 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -300,9 +300,9 @@ static int io_ctl_init(struct btrfs_io_ctl *io_ctl, struct inode *inode,
 	if (btrfs_ino(BTRFS_I(inode)) != BTRFS_FREE_INO_OBJECTID)
 		check_crcs = 1;
 
-	/* Make sure we can fit our crcs into the first page */
+	/* Make sure we can fit our crcs and generation # into the first page */
 	if (write && check_crcs &&
-	    (num_pages * sizeof(u32)) >= PAGE_SIZE)
+	    (num_pages * sizeof(u32) + sizeof(u64)) > PAGE_SIZE)
 		return -ENOSPC;
 
 	memset(io_ctl, 0, sizeof(struct btrfs_io_ctl));
-- 
2.17.1


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

* Re: [PATCH] Btrfs: make sure there is always room for generation number
  2018-07-03  0:00 [PATCH] Btrfs: make sure there is always room for generation number Zhihui Zhang
@ 2018-07-04 15:14 ` David Sterba
  2018-07-04 15:21 ` David Sterba
  1 sibling, 0 replies; 4+ messages in thread
From: David Sterba @ 2018-07-04 15:14 UTC (permalink / raw)
  To: Zhihui Zhang; +Cc: jbacik, dsterba, linux-btrfs

On Mon, Jul 02, 2018 at 08:00:54PM -0400, Zhihui Zhang wrote:
> io_ctl_set_generation() assumes that the generation number shares
> the same page with inline CRCs. Let's make sure this is always true.

Have you found this by code inspection or is it a fix for a bug that can
be reproduced?

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

* Re: [PATCH] Btrfs: make sure there is always room for generation number
  2018-07-03  0:00 [PATCH] Btrfs: make sure there is always room for generation number Zhihui Zhang
  2018-07-04 15:14 ` David Sterba
@ 2018-07-04 15:21 ` David Sterba
  2018-07-05 12:40   ` Zhihui Zhang
  1 sibling, 1 reply; 4+ messages in thread
From: David Sterba @ 2018-07-04 15:21 UTC (permalink / raw)
  To: Zhihui Zhang; +Cc: jbacik, dsterba, linux-btrfs

On Mon, Jul 02, 2018 at 08:00:54PM -0400, Zhihui Zhang wrote:
> io_ctl_set_generation() assumes that the generation number shares
> the same page with inline CRCs. Let's make sure this is always true.
> 
> Signed-off-by: Zhihui Zhang <zzhsuny@gmail.com>

Reviewed-by: David Sterba <dsterba@suse.com>

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

* Re: [PATCH] Btrfs: make sure there is always room for generation number
  2018-07-04 15:21 ` David Sterba
@ 2018-07-05 12:40   ` Zhihui Zhang
  0 siblings, 0 replies; 4+ messages in thread
From: Zhihui Zhang @ 2018-07-05 12:40 UTC (permalink / raw)
  To: dsterba, Zhihui Zhang, jbacik, dsterba, linux-btrfs

code inspection. If I understand it correctly, we are off by 4 bytes
because CRC is 32 bits and generation is 64 bits. But this bug might
never hit in practice.

thanks,

-Zhihui

On Wed, Jul 4, 2018 at 11:21 AM, David Sterba <dsterba@suse.cz> wrote:
> On Mon, Jul 02, 2018 at 08:00:54PM -0400, Zhihui Zhang wrote:
>> io_ctl_set_generation() assumes that the generation number shares
>> the same page with inline CRCs. Let's make sure this is always true.
>>
>> Signed-off-by: Zhihui Zhang <zzhsuny@gmail.com>
>
> Reviewed-by: David Sterba <dsterba@suse.com>

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

end of thread, other threads:[~2018-07-05 12:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-03  0:00 [PATCH] Btrfs: make sure there is always room for generation number Zhihui Zhang
2018-07-04 15:14 ` David Sterba
2018-07-04 15:21 ` David Sterba
2018-07-05 12:40   ` Zhihui Zhang

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