Commit fb32975d authored by Ed Cashin's avatar Ed Cashin Committed by Linus Torvalds

aoe: adjust ref of head for compound page tails

Fix a BUG which can trigger when direct-IO is used with AOE.

As discussed previously, the fact that some users of the block layer
provide bios that point to pages with a zero _count means that it is not
OK for the network layer to do a put_page on the skb frags during an
skb_linearize, so the aoe driver gets a reference to pages in bios and
puts the reference before ending the bio.  And because it cannot use
get_page on a page with a zero _count, it manipulates the value
directly.

It is not OK to increment the _count of a compound page tail, though,
since the VM layer will VM_BUG_ON a non-zero _count.  Block users that
do direct I/O can result in the aoe driver seeing compound page tails in
bios.  In that case, the same logic works as long as the head of the
compound page is used instead of the tails.  This patch handles compound
pages and does not BUG.

It relies on the block layer user leaving the relationship between the
page tail and its head alone for the duration between the submission of
the bio and its completion, whether successful or not.
Signed-off-by: default avatarEd Cashin <ecashin@coraid.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent dfa9771a
...@@ -906,16 +906,10 @@ bio_pageinc(struct bio *bio) ...@@ -906,16 +906,10 @@ bio_pageinc(struct bio *bio)
int i; int i;
bio_for_each_segment(bv, bio, i) { bio_for_each_segment(bv, bio, i) {
page = bv->bv_page;
/* Non-zero page count for non-head members of /* Non-zero page count for non-head members of
* compound pages is no longer allowed by the kernel, * compound pages is no longer allowed by the kernel.
* but this has never been seen here.
*/ */
if (unlikely(PageCompound(page))) page = compound_trans_head(bv->bv_page);
if (compound_trans_head(page) != page) {
pr_crit("page tail used for block I/O\n");
BUG();
}
atomic_inc(&page->_count); atomic_inc(&page->_count);
} }
} }
...@@ -924,10 +918,13 @@ static void ...@@ -924,10 +918,13 @@ static void
bio_pagedec(struct bio *bio) bio_pagedec(struct bio *bio)
{ {
struct bio_vec *bv; struct bio_vec *bv;
struct page *page;
int i; int i;
bio_for_each_segment(bv, bio, i) bio_for_each_segment(bv, bio, i) {
atomic_dec(&bv->bv_page->_count); page = compound_trans_head(bv->bv_page);
atomic_dec(&page->_count);
}
} }
static void static void
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment