Skip to content

Commit 147d4a0

Browse files
riteshharjanitytso
authored andcommitted
jbd2: Remove page size assumptions
jbd2_alloc() allocates a buffer from slab when the block size is smaller than PAGE_SIZE, and slab may be using a compound page. Before commit 8147c4c, we set b_page to the precise page containing the buffer and this code worked well. Now we set b_page to the head page of the allocation, so we can no longer use offset_in_page(). While we could do a 1:1 replacement with offset_in_folio(), use the more idiomatic bh_offset() and the folio APIs to map the buffer. This isn't enough to support a b_size larger than PAGE_SIZE on HIGHMEM machines, but this is good enough to fix the actual bug we're seeing. Fixes: 8147c4c ("jbd2: use a folio in jbd2_journal_write_metadata_buffer()") Reported-by: Zorro Lang <zlang@kernel.org> Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com> [converted to be more folio] Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
1 parent f94cf22 commit 147d4a0

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

fs/jbd2/commit.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -298,14 +298,12 @@ static int journal_finish_inode_data_buffers(journal_t *journal,
298298

299299
static __u32 jbd2_checksum_data(__u32 crc32_sum, struct buffer_head *bh)
300300
{
301-
struct page *page = bh->b_page;
302301
char *addr;
303302
__u32 checksum;
304303

305-
addr = kmap_atomic(page);
306-
checksum = crc32_be(crc32_sum,
307-
(void *)(addr + offset_in_page(bh->b_data)), bh->b_size);
308-
kunmap_atomic(addr);
304+
addr = kmap_local_folio(bh->b_folio, bh_offset(bh));
305+
checksum = crc32_be(crc32_sum, addr, bh->b_size);
306+
kunmap_local(addr);
309307

310308
return checksum;
311309
}
@@ -322,7 +320,6 @@ static void jbd2_block_tag_csum_set(journal_t *j, journal_block_tag_t *tag,
322320
struct buffer_head *bh, __u32 sequence)
323321
{
324322
journal_block_tag3_t *tag3 = (journal_block_tag3_t *)tag;
325-
struct page *page = bh->b_page;
326323
__u8 *addr;
327324
__u32 csum32;
328325
__be32 seq;
@@ -331,11 +328,10 @@ static void jbd2_block_tag_csum_set(journal_t *j, journal_block_tag_t *tag,
331328
return;
332329

333330
seq = cpu_to_be32(sequence);
334-
addr = kmap_atomic(page);
331+
addr = kmap_local_folio(bh->b_folio, bh_offset(bh));
335332
csum32 = jbd2_chksum(j, j->j_csum_seed, (__u8 *)&seq, sizeof(seq));
336-
csum32 = jbd2_chksum(j, csum32, addr + offset_in_page(bh->b_data),
337-
bh->b_size);
338-
kunmap_atomic(addr);
333+
csum32 = jbd2_chksum(j, csum32, addr, bh->b_size);
334+
kunmap_local(addr);
339335

340336
if (jbd2_has_feature_csum3(j))
341337
tag3->t_checksum = cpu_to_be32(csum32);

fs/jbd2/transaction.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -935,19 +935,15 @@ static void warn_dirty_buffer(struct buffer_head *bh)
935935
/* Call t_frozen trigger and copy buffer data into jh->b_frozen_data. */
936936
static void jbd2_freeze_jh_data(struct journal_head *jh)
937937
{
938-
struct page *page;
939-
int offset;
940938
char *source;
941939
struct buffer_head *bh = jh2bh(jh);
942940

943941
J_EXPECT_JH(jh, buffer_uptodate(bh), "Possible IO failure.\n");
944-
page = bh->b_page;
945-
offset = offset_in_page(bh->b_data);
946-
source = kmap_atomic(page);
942+
source = kmap_local_folio(bh->b_folio, bh_offset(bh));
947943
/* Fire data frozen trigger just before we copy the data */
948-
jbd2_buffer_frozen_trigger(jh, source + offset, jh->b_triggers);
949-
memcpy(jh->b_frozen_data, source + offset, bh->b_size);
950-
kunmap_atomic(source);
944+
jbd2_buffer_frozen_trigger(jh, source, jh->b_triggers);
945+
memcpy(jh->b_frozen_data, source, bh->b_size);
946+
kunmap_local(source);
951947

952948
/*
953949
* Now that the frozen data is saved off, we need to store any matching

0 commit comments

Comments
 (0)