diff options
author | Mel Gorman <mgorman@suse.de> | 2012-12-05 17:01:41 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-12-06 14:56:43 -0500 |
commit | 18a2f371f5edf41810f6469cb9be39931ef9deb9 (patch) | |
tree | 4e4ec26f13273b36fc7203d2084ea09f14c5f0f7 /mm/mempolicy.c | |
parent | c702418f8a2fa6cc92e84a39880d458faf7af9cc (diff) |
tmpfs: fix shared mempolicy leak
This fixes a regression in 3.7-rc, which has since gone into stable.
Commit 00442ad04a5e ("mempolicy: fix a memory corruption by refcount
imbalance in alloc_pages_vma()") changed get_vma_policy() to raise the
refcount on a shmem shared mempolicy; whereas shmem_alloc_page() went
on expecting alloc_page_vma() to drop the refcount it had acquired.
This deserves a rework: but for now fix the leak in shmem_alloc_page().
Hugh: shmem_swapin() did not need a fix, but surely it's clearer to use
the same refcounting there as in shmem_alloc_page(), delete its onstack
mempolicy, and the strange mpol_cond_copy() and __mpol_cond_copy() -
those were invented to let swapin_readahead() make an unknown number of
calls to alloc_pages_vma() with one mempolicy; but since 00442ad04a5e,
alloc_pages_vma() has kept refcount in balance, so now no problem.
Reported-and-tested-by: Tommi Rantala <tt.rantala@gmail.com>
Signed-off-by: Mel Gorman <mgorman@suse.de>
Signed-off-by: Hugh Dickins <hughd@google.com>
Cc: stable@vger.kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/mempolicy.c')
-rw-r--r-- | mm/mempolicy.c | 22 |
1 files changed, 0 insertions, 22 deletions
diff --git a/mm/mempolicy.c b/mm/mempolicy.c index d04a8a54c294..4ea600da8940 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c | |||
@@ -2037,28 +2037,6 @@ struct mempolicy *__mpol_dup(struct mempolicy *old) | |||
2037 | return new; | 2037 | return new; |
2038 | } | 2038 | } |
2039 | 2039 | ||
2040 | /* | ||
2041 | * If *frompol needs [has] an extra ref, copy *frompol to *tompol , | ||
2042 | * eliminate the * MPOL_F_* flags that require conditional ref and | ||
2043 | * [NOTE!!!] drop the extra ref. Not safe to reference *frompol directly | ||
2044 | * after return. Use the returned value. | ||
2045 | * | ||
2046 | * Allows use of a mempolicy for, e.g., multiple allocations with a single | ||
2047 | * policy lookup, even if the policy needs/has extra ref on lookup. | ||
2048 | * shmem_readahead needs this. | ||
2049 | */ | ||
2050 | struct mempolicy *__mpol_cond_copy(struct mempolicy *tompol, | ||
2051 | struct mempolicy *frompol) | ||
2052 | { | ||
2053 | if (!mpol_needs_cond_ref(frompol)) | ||
2054 | return frompol; | ||
2055 | |||
2056 | *tompol = *frompol; | ||
2057 | tompol->flags &= ~MPOL_F_SHARED; /* copy doesn't need unref */ | ||
2058 | __mpol_put(frompol); | ||
2059 | return tompol; | ||
2060 | } | ||
2061 | |||
2062 | /* Slow path of a mempolicy comparison */ | 2040 | /* Slow path of a mempolicy comparison */ |
2063 | bool __mpol_equal(struct mempolicy *a, struct mempolicy *b) | 2041 | bool __mpol_equal(struct mempolicy *a, struct mempolicy *b) |
2064 | { | 2042 | { |