From dbb27c16721bfcb57c9e70fae78afbd5f9ae63b6 Mon Sep 17 00:00:00 2001 From: Sasha Levin Date: Sun, 19 Jan 2020 12:46:13 -0500 Subject: [PATCH] fixes for 4.19 Signed-off-by: Sasha Levin --- ...-make-__thp_get_unmapped_area-static.patch | 38 +++++ ...-thp-fix-conflict-of-above-47bit-hin.patch | 139 ++++++++++++++++++ queue-4.19/series | 2 + 3 files changed, 179 insertions(+) create mode 100644 queue-4.19/mm-huge_memory.c-make-__thp_get_unmapped_area-static.patch create mode 100644 queue-4.19/mm-huge_memory.c-thp-fix-conflict-of-above-47bit-hin.patch diff --git a/queue-4.19/mm-huge_memory.c-make-__thp_get_unmapped_area-static.patch b/queue-4.19/mm-huge_memory.c-make-__thp_get_unmapped_area-static.patch new file mode 100644 index 00000000000..d4b68f6d1de --- /dev/null +++ b/queue-4.19/mm-huge_memory.c-make-__thp_get_unmapped_area-static.patch @@ -0,0 +1,38 @@ +From 7868882c1492a438418049c38a098cbabc026abc Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Mon, 13 May 2019 17:23:17 -0700 +Subject: mm/huge_memory.c: make __thp_get_unmapped_area static + +From: Bharath Vedartham + +[ Upstream commit b3b07077b01ecbbd98efede778c195567de25b71 ] + +__thp_get_unmapped_area is only used in mm/huge_memory.c. Make it static. +Tested by building and booting the kernel. + +Link: http://lkml.kernel.org/r/20190504102353.GA22525@bharath12345-Inspiron-5559 +Signed-off-by: Bharath Vedartham +Acked-by: Michal Hocko +Signed-off-by: Andrew Morton +Signed-off-by: Linus Torvalds +Signed-off-by: Sasha Levin +--- + mm/huge_memory.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/mm/huge_memory.c b/mm/huge_memory.c +index 5a1771bd5d04..950466876625 100644 +--- a/mm/huge_memory.c ++++ b/mm/huge_memory.c +@@ -509,7 +509,7 @@ void prep_transhuge_page(struct page *page) + set_compound_page_dtor(page, TRANSHUGE_PAGE_DTOR); + } + +-unsigned long __thp_get_unmapped_area(struct file *filp, unsigned long len, ++static unsigned long __thp_get_unmapped_area(struct file *filp, unsigned long len, + loff_t off, unsigned long flags, unsigned long size) + { + unsigned long addr; +-- +2.20.1 + diff --git a/queue-4.19/mm-huge_memory.c-thp-fix-conflict-of-above-47bit-hin.patch b/queue-4.19/mm-huge_memory.c-thp-fix-conflict-of-above-47bit-hin.patch new file mode 100644 index 00000000000..7b451ab7eae --- /dev/null +++ b/queue-4.19/mm-huge_memory.c-thp-fix-conflict-of-above-47bit-hin.patch @@ -0,0 +1,139 @@ +From ad4e3cac8d1aac61a429a6e57e7dfcef11874f49 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Mon, 13 Jan 2020 16:29:10 -0800 +Subject: mm/huge_memory.c: thp: fix conflict of above-47bit hint address and + PMD alignment + +From: Kirill A. Shutemov + +[ Upstream commit 97d3d0f9a1cf132c63c0b8b8bd497b8a56283dd9 ] + +Patch series "Fix two above-47bit hint address vs. THP bugs". + +The two get_unmapped_area() implementations have to be fixed to provide +THP-friendly mappings if above-47bit hint address is specified. + +This patch (of 2): + +Filesystems use thp_get_unmapped_area() to provide THP-friendly +mappings. For DAX in particular. + +Normally, the kernel doesn't create userspace mappings above 47-bit, +even if the machine allows this (such as with 5-level paging on x86-64). +Not all user space is ready to handle wide addresses. It's known that +at least some JIT compilers use higher bits in pointers to encode their +information. + +Userspace can ask for allocation from full address space by specifying +hint address (with or without MAP_FIXED) above 47-bits. If the +application doesn't need a particular address, but wants to allocate +from whole address space it can specify -1 as a hint address. + +Unfortunately, this trick breaks thp_get_unmapped_area(): the function +would not try to allocate PMD-aligned area if *any* hint address +specified. + +Modify the routine to handle it correctly: + + - Try to allocate the space at the specified hint address with length + padding required for PMD alignment. + - If failed, retry without length padding (but with the same hint + address); + - If the returned address matches the hint address return it. + - Otherwise, align the address as required for THP and return. + +The user specified hint address is passed down to get_unmapped_area() so +above-47bit hint address will be taken into account without breaking +alignment requirements. + +Link: http://lkml.kernel.org/r/20191220142548.7118-2-kirill.shutemov@linux.intel.com +Fixes: b569bab78d8d ("x86/mm: Prepare to expose larger address space to userspace") +Signed-off-by: Kirill A. Shutemov +Reported-by: Thomas Willhalm +Tested-by: Dan Williams +Cc: "Aneesh Kumar K . V" +Cc: "Bruggeman, Otto G" +Cc: +Signed-off-by: Andrew Morton +Signed-off-by: Linus Torvalds +Signed-off-by: Sasha Levin +--- + mm/huge_memory.c | 38 ++++++++++++++++++++++++-------------- + 1 file changed, 24 insertions(+), 14 deletions(-) + +diff --git a/mm/huge_memory.c b/mm/huge_memory.c +index 950466876625..5bb93cf18009 100644 +--- a/mm/huge_memory.c ++++ b/mm/huge_memory.c +@@ -509,13 +509,13 @@ void prep_transhuge_page(struct page *page) + set_compound_page_dtor(page, TRANSHUGE_PAGE_DTOR); + } + +-static unsigned long __thp_get_unmapped_area(struct file *filp, unsigned long len, ++static unsigned long __thp_get_unmapped_area(struct file *filp, ++ unsigned long addr, unsigned long len, + loff_t off, unsigned long flags, unsigned long size) + { +- unsigned long addr; + loff_t off_end = off + len; + loff_t off_align = round_up(off, size); +- unsigned long len_pad; ++ unsigned long len_pad, ret; + + if (off_end <= off_align || (off_end - off_align) < size) + return 0; +@@ -524,30 +524,40 @@ static unsigned long __thp_get_unmapped_area(struct file *filp, unsigned long le + if (len_pad < len || (off + len_pad) < off) + return 0; + +- addr = current->mm->get_unmapped_area(filp, 0, len_pad, ++ ret = current->mm->get_unmapped_area(filp, addr, len_pad, + off >> PAGE_SHIFT, flags); +- if (IS_ERR_VALUE(addr)) ++ ++ /* ++ * The failure might be due to length padding. The caller will retry ++ * without the padding. ++ */ ++ if (IS_ERR_VALUE(ret)) + return 0; + +- addr += (off - addr) & (size - 1); +- return addr; ++ /* ++ * Do not try to align to THP boundary if allocation at the address ++ * hint succeeds. ++ */ ++ if (ret == addr) ++ return addr; ++ ++ ret += (off - ret) & (size - 1); ++ return ret; + } + + unsigned long thp_get_unmapped_area(struct file *filp, unsigned long addr, + unsigned long len, unsigned long pgoff, unsigned long flags) + { ++ unsigned long ret; + loff_t off = (loff_t)pgoff << PAGE_SHIFT; + +- if (addr) +- goto out; + if (!IS_DAX(filp->f_mapping->host) || !IS_ENABLED(CONFIG_FS_DAX_PMD)) + goto out; + +- addr = __thp_get_unmapped_area(filp, len, off, flags, PMD_SIZE); +- if (addr) +- return addr; +- +- out: ++ ret = __thp_get_unmapped_area(filp, addr, len, off, flags, PMD_SIZE); ++ if (ret) ++ return ret; ++out: + return current->mm->get_unmapped_area(filp, addr, len, pgoff, flags); + } + EXPORT_SYMBOL_GPL(thp_get_unmapped_area); +-- +2.20.1 + diff --git a/queue-4.19/series b/queue-4.19/series index a875029854d..bf2d7bbbdf6 100644 --- a/queue-4.19/series +++ b/queue-4.19/series @@ -46,3 +46,5 @@ arm-dts-imx6q-icore-mipi-use-1.5-version-of-i.core-mx6dl.patch arm-dts-imx7-fix-toradex-colibri-imx7s-256mb-nand-flash-support.patch net-stmmac-16kb-buffer-must-be-16-byte-aligned.patch net-stmmac-enable-16kb-buffer-size.patch +mm-huge_memory.c-make-__thp_get_unmapped_area-static.patch +mm-huge_memory.c-thp-fix-conflict-of-above-47bit-hin.patch -- 2.47.3