aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Ryabinin <a.ryabinin@samsung.com>2014-07-30 19:08:35 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-07-30 20:16:13 -0400
commitb4903d6e8408e6137ee4666ee67ec566b74a0f05 (patch)
tree2db6b545dd1e56bac8602974fe74ca0cc773d67a
parent2bcf2e92c3918ce62ab4e934256e47e9a16d19c3 (diff)
mm: debugfs: move rounddown_pow_of_two() out from do_fault path
do_fault_around() expects fault_around_bytes rounded down to nearest page order. Instead of calling rounddown_pow_of_two every time in fault_around_pages()/fault_around_mask() we could do round down when user changes fault_around_bytes via debugfs interface. This also fixes bug when user set fault_around_bytes to 0. Result of rounddown_pow_of_two(0) is not defined, therefore fault_around_bytes == 0 doesn't work without this patch. Let's set fault_around_bytes to PAGE_SIZE if user sets to something less than PAGE_SIZE [akpm@linux-foundation.org: tweak code layout] Fixes: a9b0f861("mm: nominate faultaround area in bytes rather than page order") Signed-off-by: Andrey Ryabinin <a.ryabinin@samsung.com> Reported-by: Sasha Levin <sasha.levin@oracle.com> Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: <stable@vger.kernel.org> [3.15.x] Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--mm/memory.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/mm/memory.c b/mm/memory.c
index 7e8d8205b610..8b44f765b645 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2758,23 +2758,18 @@ void do_set_pte(struct vm_area_struct *vma, unsigned long address,
2758 update_mmu_cache(vma, address, pte); 2758 update_mmu_cache(vma, address, pte);
2759} 2759}
2760 2760
2761static unsigned long fault_around_bytes = 65536; 2761static unsigned long fault_around_bytes = rounddown_pow_of_two(65536);
2762 2762
2763/*
2764 * fault_around_pages() and fault_around_mask() round down fault_around_bytes
2765 * to nearest page order. It's what do_fault_around() expects to see.
2766 */
2767static inline unsigned long fault_around_pages(void) 2763static inline unsigned long fault_around_pages(void)
2768{ 2764{
2769 return rounddown_pow_of_two(fault_around_bytes) / PAGE_SIZE; 2765 return fault_around_bytes >> PAGE_SHIFT;
2770} 2766}
2771 2767
2772static inline unsigned long fault_around_mask(void) 2768static inline unsigned long fault_around_mask(void)
2773{ 2769{
2774 return ~(rounddown_pow_of_two(fault_around_bytes) - 1) & PAGE_MASK; 2770 return ~(fault_around_bytes - 1) & PAGE_MASK;
2775} 2771}
2776 2772
2777
2778#ifdef CONFIG_DEBUG_FS 2773#ifdef CONFIG_DEBUG_FS
2779static int fault_around_bytes_get(void *data, u64 *val) 2774static int fault_around_bytes_get(void *data, u64 *val)
2780{ 2775{
@@ -2782,11 +2777,19 @@ static int fault_around_bytes_get(void *data, u64 *val)
2782 return 0; 2777 return 0;
2783} 2778}
2784 2779
2780/*
2781 * fault_around_pages() and fault_around_mask() expects fault_around_bytes
2782 * rounded down to nearest page order. It's what do_fault_around() expects to
2783 * see.
2784 */
2785static int fault_around_bytes_set(void *data, u64 val) 2785static int fault_around_bytes_set(void *data, u64 val)
2786{ 2786{
2787 if (val / PAGE_SIZE > PTRS_PER_PTE) 2787 if (val / PAGE_SIZE > PTRS_PER_PTE)
2788 return -EINVAL; 2788 return -EINVAL;
2789 fault_around_bytes = val; 2789 if (val > PAGE_SIZE)
2790 fault_around_bytes = rounddown_pow_of_two(val);
2791 else
2792 fault_around_bytes = PAGE_SIZE; /* rounddown_pow_of_two(0) is undefined */
2790 return 0; 2793 return 0;
2791} 2794}
2792DEFINE_SIMPLE_ATTRIBUTE(fault_around_bytes_fops, 2795DEFINE_SIMPLE_ATTRIBUTE(fault_around_bytes_fops,