]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
btrfs: add special case to setget helpers for 64k pages
authorDavid Sterba <dsterba@suse.com>
Wed, 23 Jun 2021 13:48:53 +0000 (15:48 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 23 Aug 2021 11:18:58 +0000 (13:18 +0200)
On 64K pages the size of the extent_buffer::pages array is 1 and
compilation with -Warray-bounds warns due to

  kaddr = page_address(eb->pages[idx + 1]);

when reading byte range crossing page boundary.

This does never actually overflow the array because on 64K because all
the data fit in one page and bounds are checked by check_setget_bounds.

To fix the reported overflows and warnings add a compile-time condition
that will allow compiler to eliminate the dead code that reads from the
idx + 1 page.

Link: https://lore.kernel.org/lkml/20210623083901.1d49d19d@canb.auug.org.au/
CC: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/struct-funcs.c

index 8260f8bb3ff088e39812d658ab6d756d8c2323c1..f429256f56dba1ae7482ef68bb7e6c44c8957e81 100644 (file)
@@ -73,7 +73,7 @@ u##bits btrfs_get_token_##bits(struct btrfs_map_token *token,         \
        }                                                               \
        token->kaddr = page_address(token->eb->pages[idx]);             \
        token->offset = idx << PAGE_SHIFT;                              \
-       if (oip + size <= PAGE_SIZE)                                    \
+       if (INLINE_EXTENT_BUFFER_PAGES == 1 || oip + size <= PAGE_SIZE ) \
                return get_unaligned_le##bits(token->kaddr + oip);      \
                                                                        \
        memcpy(lebytes, token->kaddr + oip, part);                      \
@@ -94,7 +94,7 @@ u##bits btrfs_get_##bits(const struct extent_buffer *eb,              \
        u8 lebytes[sizeof(u##bits)];                                    \
                                                                        \
        ASSERT(check_setget_bounds(eb, ptr, off, size));                \
-       if (oip + size <= PAGE_SIZE)                                    \
+       if (INLINE_EXTENT_BUFFER_PAGES == 1 || oip + size <= PAGE_SIZE) \
                return get_unaligned_le##bits(kaddr + oip);             \
                                                                        \
        memcpy(lebytes, kaddr + oip, part);                             \
@@ -124,7 +124,7 @@ void btrfs_set_token_##bits(struct btrfs_map_token *token,          \
        }                                                               \
        token->kaddr = page_address(token->eb->pages[idx]);             \
        token->offset = idx << PAGE_SHIFT;                              \
-       if (oip + size <= PAGE_SIZE) {                                  \
+       if (INLINE_EXTENT_BUFFER_PAGES == 1 || oip + size <= PAGE_SIZE) { \
                put_unaligned_le##bits(val, token->kaddr + oip);        \
                return;                                                 \
        }                                                               \
@@ -146,7 +146,7 @@ void btrfs_set_##bits(const struct extent_buffer *eb, void *ptr,    \
        u8 lebytes[sizeof(u##bits)];                                    \
                                                                        \
        ASSERT(check_setget_bounds(eb, ptr, off, size));                \
-       if (oip + size <= PAGE_SIZE) {                                  \
+       if (INLINE_EXTENT_BUFFER_PAGES == 1 || oip + size <= PAGE_SIZE) { \
                put_unaligned_le##bits(val, kaddr + oip);               \
                return;                                                 \
        }                                                               \