* [PATCH] Fix mpage_writepage() for pages with buffers
@ 2017-10-06 21:15 Matthew Wilcox
2017-10-09 10:41 ` Johannes Thumshirn
2017-10-10 19:44 ` Andrew Morton
0 siblings, 2 replies; 5+ messages in thread
From: Matthew Wilcox @ 2017-10-06 21:15 UTC (permalink / raw)
To: Linus Torvalds
Cc: Johannes Thumshirn, linux-fsdevel, linux-nvdimm, OGAWA Hirofumi,
Ross Zwisler, Toshi Kani, linux-kernel
When using FAT on a block device which supports rw_page, we can hit
BUG_ON(!PageLocked(page)) in try_to_free_buffers(). This is because we
call clean_buffers() after unlocking the page we've written. Introduce a
new clean_page_buffers() which cleans all buffers associated with a page
and call it from within bdev_write_page().
Reported-by: Toshi Kani <toshi.kani@hpe.com>
Reported-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Tested-by: Toshi Kani <toshi.kani@hpe.com>
Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
Cc: stable@vger.kernel.org
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 9941dc8342df..3fbe75bdd257 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -716,10 +716,12 @@ int bdev_write_page(struct block_device *bdev, sector_t sector,
set_page_writeback(page);
result = ops->rw_page(bdev, sector + get_start_sect(bdev), page, true);
- if (result)
+ if (result) {
end_page_writeback(page);
- else
+ } else {
+ clean_page_buffers(page);
unlock_page(page);
+ }
blk_queue_exit(bdev->bd_queue);
return result;
}
diff --git a/fs/mpage.c b/fs/mpage.c
index 2e4c41ccb5c9..d97b003f1607 100644
--- a/fs/mpage.c
+++ b/fs/mpage.c
@@ -468,6 +468,16 @@ static void clean_buffers(struct page *page, unsigned first_unmapped)
try_to_free_buffers(page);
}
+/*
+ * For situations where we want to clean all buffers attached to a page.
+ * We don't need to calculate how many buffers are attached to the page,
+ * we just need to specify a number larger than the maximum number of buffers.
+ */
+void clean_page_buffers(struct page *page)
+{
+ clean_buffers(page, PAGE_SIZE);
+}
+
static int __mpage_writepage(struct page *page, struct writeback_control *wbc,
void *data)
{
@@ -605,10 +615,8 @@ static int __mpage_writepage(struct page *page, struct writeback_control *wbc,
if (bio == NULL) {
if (first_unmapped == blocks_per_page) {
if (!bdev_write_page(bdev, blocks[0] << (blkbits - 9),
- page, wbc)) {
- clean_buffers(page, first_unmapped);
+ page, wbc))
goto out;
- }
}
bio = mpage_alloc(bdev, blocks[0] << (blkbits - 9),
BIO_MAX_PAGES, GFP_NOFS|__GFP_HIGH);
diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h
index c8dae555eccf..446b24cac67d 100644
--- a/include/linux/buffer_head.h
+++ b/include/linux/buffer_head.h
@@ -232,6 +232,7 @@ int generic_write_end(struct file *, struct address_space *,
loff_t, unsigned, unsigned,
struct page *, void *);
void page_zero_new_buffers(struct page *page, unsigned from, unsigned to);
+void clean_page_buffers(struct page *page);
int cont_write_begin(struct file *, struct address_space *, loff_t,
unsigned, unsigned, struct page **, void **,
get_block_t *, loff_t *);
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix mpage_writepage() for pages with buffers
2017-10-06 21:15 [PATCH] Fix mpage_writepage() for pages with buffers Matthew Wilcox
@ 2017-10-09 10:41 ` Johannes Thumshirn
2017-10-10 19:44 ` Andrew Morton
1 sibling, 0 replies; 5+ messages in thread
From: Johannes Thumshirn @ 2017-10-09 10:41 UTC (permalink / raw)
To: Matthew Wilcox
Cc: Linus Torvalds, linux-fsdevel, linux-nvdimm, OGAWA Hirofumi,
Ross Zwisler, Toshi Kani, linux-kernel
Acked-by: Johannes Thumshirn <jthumshirn@suse.de>
--
Johannes Thumshirn Storage
jthumshirn@suse.de +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix mpage_writepage() for pages with buffers
2017-10-06 21:15 [PATCH] Fix mpage_writepage() for pages with buffers Matthew Wilcox
2017-10-09 10:41 ` Johannes Thumshirn
@ 2017-10-10 19:44 ` Andrew Morton
2017-10-10 20:31 ` Linus Torvalds
1 sibling, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2017-10-10 19:44 UTC (permalink / raw)
To: Matthew Wilcox
Cc: Linus Torvalds, Johannes Thumshirn, linux-fsdevel, linux-nvdimm,
OGAWA Hirofumi, Ross Zwisler, Toshi Kani, linux-kernel
On Fri, 6 Oct 2017 14:15:41 -0700 Matthew Wilcox <willy@infradead.org> wrote:
> When using FAT on a block device which supports rw_page, we can hit
> BUG_ON(!PageLocked(page)) in try_to_free_buffers(). This is because we
> call clean_buffers() after unlocking the page we've written. Introduce a
> new clean_page_buffers() which cleans all buffers associated with a page
> and call it from within bdev_write_page().
This is all pretty mature code (isn't it?). Any idea why this bug
popped up now?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix mpage_writepage() for pages with buffers
2017-10-10 19:44 ` Andrew Morton
@ 2017-10-10 20:31 ` Linus Torvalds
2017-10-11 15:40 ` Matthew Wilcox
0 siblings, 1 reply; 5+ messages in thread
From: Linus Torvalds @ 2017-10-10 20:31 UTC (permalink / raw)
To: Andrew Morton
Cc: Matthew Wilcox, Johannes Thumshirn, linux-fsdevel, linux-nvdimm,
OGAWA Hirofumi, Ross Zwisler, Toshi Kani,
Linux Kernel Mailing List
On Tue, Oct 10, 2017 at 12:44 PM, Andrew Morton
<akpm@linux-foundation.org> wrote:
>
> This is all pretty mature code (isn't it?). Any idea why this bug
> popped up now?
Also, while the patch looks sane, the
clean_buffers(page, PAGE_SIZE);
line really threw me. That's an insane value to pick, it looks like
"bytes in page", but it isn't. It's just a random value that is bigger
than "PAGE_SIZE >> SECTOR_SHIFT".
I'd prefer to see just ~0u if the intention is just "bigger than
anything possible".
Linus
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix mpage_writepage() for pages with buffers
2017-10-10 20:31 ` Linus Torvalds
@ 2017-10-11 15:40 ` Matthew Wilcox
0 siblings, 0 replies; 5+ messages in thread
From: Matthew Wilcox @ 2017-10-11 15:40 UTC (permalink / raw)
To: Linus Torvalds
Cc: Andrew Morton, Johannes Thumshirn, linux-fsdevel, linux-nvdimm,
OGAWA Hirofumi, Ross Zwisler, Toshi Kani,
Linux Kernel Mailing List
On Tue, Oct 10, 2017 at 01:31:44PM -0700, Linus Torvalds wrote:
> On Tue, Oct 10, 2017 at 12:44 PM, Andrew Morton
> <akpm@linux-foundation.org> wrote:
> >
> > This is all pretty mature code (isn't it?). Any idea why this bug
> > popped up now?
I have no idea why it's suddenly popped up. It looks like it should
be a bohrbug, but it's actually a heisenbug, and I don't understand
that either.
> Also, while the patch looks sane, the
>
> clean_buffers(page, PAGE_SIZE);
>
> line really threw me. That's an insane value to pick, it looks like
> "bytes in page", but it isn't. It's just a random value that is bigger
> than "PAGE_SIZE >> SECTOR_SHIFT".
>
> I'd prefer to see just ~0u if the intention is just "bigger than
> anything possible".
Actually, I did choose it to be "number of bytes in the page", based on
the reasoning that I didn't want to calculate what the actual block size
was, and the block size surely couldn't be any smaller than one byte. I
forgot about the SECTOR_SIZE limit on filesystem block size, so your
spelling of "big enough" does look better.
Now that I think about it some more, I suppose we might end up with a
situation where we're eventually passing a hugepage to this routine,
and futureproofing it with ~0U probably makes more sense.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-10-11 15:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-06 21:15 [PATCH] Fix mpage_writepage() for pages with buffers Matthew Wilcox
2017-10-09 10:41 ` Johannes Thumshirn
2017-10-10 19:44 ` Andrew Morton
2017-10-10 20:31 ` Linus Torvalds
2017-10-11 15:40 ` Matthew Wilcox
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).