riscv: Enable HAVE_ARCH_HUGE_VMAP for 64BIT
Subsystems (3)
PATCH v2 1/1 riscv: Enable HAVE_ARCH_HUGE_VMAP for 64BIT
This sets the HAVE_ARCH_HUGE_VMAP option. Enable pmd vmap support and define the required page table functions(Currently, riscv has only three-level page tables support for 64BIT).
--- .../features/vm/huge-vmap/arch-support.txt | 2 +- arch/riscv/Kconfig | 1 + arch/riscv/include/asm/vmalloc.h | 12 ++++++ arch/riscv/mm/Makefile | 1 + arch/riscv/mm/pgtable.c | 38 +++++++++++++++++++ include/linux/pgtable.h | 14 ++++++- 6 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 arch/riscv/mm/pgtable.c
Documentation/features/vm/huge-vmap/arch-support.txt +1 -1
@@ -22,7 +22,7 @@ | openrisc: | TODO | | parisc: | TODO | | powerpc: | ok | - | riscv: | TODO | + | riscv: | ok | | s390: | TODO | | sh: | TODO | | sparc: | TODO |
arch/riscv/Kconfig +1 -0
@@ -62,6 +62,7 @@ config RISCV select GENERIC_TIME_VSYSCALL if MMU && 64BIT select HANDLE_DOMAIN_IRQ select HAVE_ARCH_AUDITSYSCALL + select HAVE_ARCH_HUGE_VMAP if MMU && 64BIT select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL select HAVE_ARCH_JUMP_LABEL_RELATIVE if !XIP_KERNEL select HAVE_ARCH_KASAN if MMU && 64BIT
arch/riscv/include/asm/vmalloc.h +12 -0
@@ -1,4 +1,16 @@#ifndef _ASM_RISCV_VMALLOC_H#define _ASM_RISCV_VMALLOC_H +#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP + +#define IOREMAP_MAX_ORDER (PMD_SHIFT) + +#define arch_vmap_pmd_supported arch_vmap_pmd_supported +static inline bool __init arch_vmap_pmd_supported (pgprot_t prot) +{ +return true; +} + +#endif +#endif /* _ASM_RISCV_VMALLOC_H */
arch/riscv/mm/Makefile +1 -0
@@ -13,6 +13,7 @@ obj-y += extable.o obj-$(CONFIG_MMU) += fault.o pageattr.o obj-y += cacheflush.o obj-y += context.o +obj-y += pgtable.o ifeq ($(CONFIG_MMU),y) obj-$(CONFIG_SMP) += tlbflush.o
arch/riscv/mm/pgtable.c new file +38 -0
@@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <asm/pgalloc.h> +#include <linux/gfp.h> +#include <linux/kernel.h> +#include <linux/pgtable.h> + +#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP + +int pmd_set_huge (pmd_t *pmd,phys_addr_t phys,pgprot_t prot) +{ +pmd_t new_pmd =pfn_pmd (__phys_to_pfn (phys), prot); + +set_pmd (pmd, new_pmd); +return 1 ; +} + +int pmd_clear_huge (pmd_t *pmd) +{ +if (!pmd_leaf (READ_ONCE (*pmd))) +return 0 ; +pmd_clear (pmd); +return 1 ; +} + +int pmd_free_pte_page (pmd_t *pmd,unsigned long addr) +{ +pte_t *pte; + + pte = (pte_t *)pmd_page_vaddr (*pmd); +pmd_clear (pmd); + +flush_tlb_kernel_range (addr, addr +PMD_SIZE ); +pte_free_kernel (NULL , pte); +return 1 ; +} + +#endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */
include/linux/pgtable.h +13 -1
@@ -1397,9 +1397,21 @@ static inline int p4d_clear_huge(p4d_t *p4d) }#endif /* !__PAGETABLE_P4D_FOLDED */ +#ifndef __PAGETABLE_PUD_FOLDEDint pud_set_huge (pud_t *pud,phys_addr_t addr,pgprot_t prot); -int pmd_set_huge (pmd_t *pmd,phys_addr_t addr,pgprot_t prot);int pud_clear_huge (pud_t *pud); +#else +static inline int pud_set_huge (pud_t *pud,phys_addr_t addr,pgprot_t prot) +{ +return 0 ; +} +static inline int pud_clear_huge (pud_t *pud) +{ +return 0 ; +} +#endif /* !__PAGETABLE_PUD_FOLDED */ + +int pmd_set_huge (pmd_t *pmd,phys_addr_t addr,pgprot_t prot);int pmd_clear_huge (pmd_t *pmd);int p4d_free_pud_page (p4d_t *p4d,unsigned long addr);int pud_free_pmd_page (pud_t *pud,unsigned long addr);
Signature · 1 line
2.18.0.huawei.25
kernel test robot
build botThank you for the patch! Yet something to improve:
Hi Liu,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on next-20210831]
url: https://github.com/0day-ci/linux/commits/Liu-Shixin/riscv-Enable-HAVE_ARCH_HUGE_VMAP-for-64BIT/20210831-202818 base: 52c7b727581fe725f8b8a283af21fe0651c73c48 config: arm64-buildonly-randconfig-r006-20210831 (attached as .config) compiler: aarch64-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/56c97e9d9ededae88111ef9b72e88de4c0d85b29
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Liu-Shixin/riscv-Enable-HAVE_ARCH_HUGE_VMAP-for-64BIT/20210831-202818 git checkout 56c97e9d9ededae88111ef9b72e88de4c0d85b29
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=arm64 SHELL=/bin/bash arch/arm64/mm/
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> arch/arm64/mm/mmu.c:1342:5: error: redefinition of 'pud_set_huge'
1342 | int pud_set_huge(pud_t *pudp, phys_addr_t phys, pgprot_t prot)
| ^~~~~~~~~~~~
In file included from include/linux/mm.h:33,
from include/linux/pid_namespace.h:7,
from include/linux/ptrace.h:10,
from include/linux/elfcore.h:11,
from include/linux/crash_core.h:6,
from include/linux/kexec.h:18,
from arch/arm64/mm/mmu.c:15:
include/linux/pgtable.h:1404:19: note: previous definition of 'pud_set_huge' with type 'int(pud_t *, phys_addr_t, pgprot_t)' {aka 'int(pud_t *, long long unsigned int, pgprot_t)'}
1404 | static inline int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot)
| ^~~~~~~~~~~~
>> arch/arm64/mm/mmu.c:1370:5: error: redefinition of 'pud_clear_huge'
1370 | int pud_clear_huge(pud_t *pudp)
| ^~~~~~~~~~~~~~
In file included from include/linux/mm.h:33,
from include/linux/pid_namespace.h:7,
from include/linux/ptrace.h:10,
from include/linux/elfcore.h:11,
from include/linux/crash_core.h:6,
from include/linux/kexec.h:18,
from arch/arm64/mm/mmu.c:15: include/linux/pgtable.h:1408:19: note: previous definition of 'pud_clear_huge' with type 'int(pud_t *)'
1408 | static inline int pud_clear_huge(pud_t *pud)
| ^~~~~~~~~~~~~~
vim +/pud_set_huge +1342 arch/arm64/mm/mmu.c
61bd93ce801bb6 Ard Biesheuvel 2015-06-01 1341
20a004e7b017cc Will Deacon 2018-02-15 @1342 int pud_set_huge(pud_t *pudp, phys_addr_t phys, pgprot_t prot)
324420bf91f605 Ard Biesheuvel 2016-02-16 1343 {
f7f0097af67c3c Anshuman Khandual 2019-05-27 1344 pud_t new_pud = pfn_pud(__phys_to_pfn(phys), mk_pud_sect_prot(prot));
15122ee2c515a2 Will Deacon 2018-02-21 1345
82034c23fcbc23 Laura Abbott 2018-05-23 1346 /* Only allow permission changes for now */
82034c23fcbc23 Laura Abbott 2018-05-23 1347 if (!pgattr_change_is_safe(READ_ONCE(pud_val(*pudp)),
82034c23fcbc23 Laura Abbott 2018-05-23 1348 pud_val(new_pud)))
15122ee2c515a2 Will Deacon 2018-02-21 1349 return 0;
15122ee2c515a2 Will Deacon 2018-02-21 1350
87dedf7c61ab07 Anshuman Khandual 2019-05-27 1351 VM_BUG_ON(phys & ~PUD_MASK);
82034c23fcbc23 Laura Abbott 2018-05-23 1352 set_pud(pudp, new_pud);
324420bf91f605 Ard Biesheuvel 2016-02-16 1353 return 1;
324420bf91f605 Ard Biesheuvel 2016-02-16 1354 }
324420bf91f605 Ard Biesheuvel 2016-02-16 1355
20a004e7b017cc Will Deacon 2018-02-15 1356 int pmd_set_huge(pmd_t *pmdp, phys_addr_t phys, pgprot_t prot)
324420bf91f605 Ard Biesheuvel 2016-02-16 1357 {
f7f0097af67c3c Anshuman Khandual 2019-05-27 1358 pmd_t new_pmd = pfn_pmd(__phys_to_pfn(phys), mk_pmd_sect_prot(prot));
15122ee2c515a2 Will Deacon 2018-02-21 1359
82034c23fcbc23 Laura Abbott 2018-05-23 1360 /* Only allow permission changes for now */
82034c23fcbc23 Laura Abbott 2018-05-23 1361 if (!pgattr_change_is_safe(READ_ONCE(pmd_val(*pmdp)),
82034c23fcbc23 Laura Abbott 2018-05-23 1362 pmd_val(new_pmd)))
15122ee2c515a2 Will Deacon 2018-02-21 1363 return 0;
15122ee2c515a2 Will Deacon 2018-02-21 1364
87dedf7c61ab07 Anshuman Khandual 2019-05-27 1365 VM_BUG_ON(phys & ~PMD_MASK);
82034c23fcbc23 Laura Abbott 2018-05-23 1366 set_pmd(pmdp, new_pmd);
324420bf91f605 Ard Biesheuvel 2016-02-16 1367 return 1;
324420bf91f605 Ard Biesheuvel 2016-02-16 1368 }
324420bf91f605 Ard Biesheuvel 2016-02-16 1369
d8a719059b9dc9 Jonathan Marek 2021-07-21 @1370 int pud_clear_huge(pud_t *pudp)
d8a719059b9dc9 Jonathan Marek 2021-07-21 1371 {
d8a719059b9dc9 Jonathan Marek 2021-07-21 1372 if (!pud_sect(READ_ONCE(*pudp)))
d8a719059b9dc9 Jonathan Marek 2021-07-21 1373 return 0;
d8a719059b9dc9 Jonathan Marek 2021-07-21 1374 pud_clear(pudp);
d8a719059b9dc9 Jonathan Marek 2021-07-21 1375 return 1;
d8a719059b9dc9 Jonathan Marek 2021-07-21 1376 }
d8a719059b9dc9 Jonathan Marek 2021-07-21 1377 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botThank you for the patch! Yet something to improve:
Hi Liu,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on next-20210831]
url: https://github.com/0day-ci/linux/commits/Liu-Shixin/riscv-Enable-HAVE_ARCH_HUGE_VMAP-for-64BIT/20210831-202818 base: 52c7b727581fe725f8b8a283af21fe0651c73c48 config: i386-randconfig-a011-20210831 (attached as .config) compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 4b1fde8a2b681dad2ce0c082a5d6422caa06b0bc)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/56c97e9d9ededae88111ef9b72e88de4c0d85b29
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Liu-Shixin/riscv-Enable-HAVE_ARCH_HUGE_VMAP-for-64BIT/20210831-202818 git checkout 56c97e9d9ededae88111ef9b72e88de4c0d85b29
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross O=build_dir ARCH=i386 SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> arch/x86/mm/pgtable.c:703:5: error: redefinition of 'pud_set_huge'
int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot)
^
include/linux/pgtable.h:1404:19: note: previous definition is here
static inline int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot)
^
>> arch/x86/mm/pgtable.c:758:5: error: redefinition of 'pud_clear_huge'
int pud_clear_huge(pud_t *pud)
^
include/linux/pgtable.h:1408:19: note: previous definition is here
static inline int pud_clear_huge(pud_t *pud)
^2 errors generated.
vim +/pud_set_huge +703 arch/x86/mm/pgtable.c
b8504058a06bd1 Kirill A. Shutemov 2017-03-30 684
3d3ca416d9b078 Toshi Kani 2015-05-26 685 /**
3d3ca416d9b078 Toshi Kani 2015-05-26 686 * pud_set_huge - setup kernel PUD mapping
3d3ca416d9b078 Toshi Kani 2015-05-26 687 *
b73522e0c1be58 Toshi Kani 2015-05-26 688 * MTRRs can override PAT memory types with 4KiB granularity. Therefore, this
b73522e0c1be58 Toshi Kani 2015-05-26 689 * function sets up a huge page only if any of the following conditions are met:
b73522e0c1be58 Toshi Kani 2015-05-26 690 *
b73522e0c1be58 Toshi Kani 2015-05-26 691 * - MTRRs are disabled, or
b73522e0c1be58 Toshi Kani 2015-05-26 692 *
b73522e0c1be58 Toshi Kani 2015-05-26 693 * - MTRRs are enabled and the range is completely covered by a single MTRR, or
b73522e0c1be58 Toshi Kani 2015-05-26 694 *
b73522e0c1be58 Toshi Kani 2015-05-26 695 * - MTRRs are enabled and the corresponding MTRR memory type is WB, which
b73522e0c1be58 Toshi Kani 2015-05-26 696 * has no effect on the requested PAT memory type.
b73522e0c1be58 Toshi Kani 2015-05-26 697 *
b73522e0c1be58 Toshi Kani 2015-05-26 698 * Callers should try to decrease page size (1GB -> 2MB -> 4K) if the bigger
b73522e0c1be58 Toshi Kani 2015-05-26 699 * page mapping attempt fails.
3d3ca416d9b078 Toshi Kani 2015-05-26 700 *
3d3ca416d9b078 Toshi Kani 2015-05-26 701 * Returns 1 on success and 0 on failure.
3d3ca416d9b078 Toshi Kani 2015-05-26 702 */
6b6378355b9250 Toshi Kani 2015-04-14 @703 int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot)
6b6378355b9250 Toshi Kani 2015-04-14 704 {
b73522e0c1be58 Toshi Kani 2015-05-26 705 u8 mtrr, uniform;
6b6378355b9250 Toshi Kani 2015-04-14 706
b73522e0c1be58 Toshi Kani 2015-05-26 707 mtrr = mtrr_type_lookup(addr, addr + PUD_SIZE, &uniform);
b73522e0c1be58 Toshi Kani 2015-05-26 708 if ((mtrr != MTRR_TYPE_INVALID) && (!uniform) &&
b73522e0c1be58 Toshi Kani 2015-05-26 709 (mtrr != MTRR_TYPE_WRBACK))
6b6378355b9250 Toshi Kani 2015-04-14 710 return 0;
6b6378355b9250 Toshi Kani 2015-04-14 711
e3e288121408c3 Joerg Roedel 2018-04-11 712 /* Bail out if we are we on a populated non-leaf entry: */
e3e288121408c3 Joerg Roedel 2018-04-11 713 if (pud_present(*pud) && !pud_huge(*pud))
e3e288121408c3 Joerg Roedel 2018-04-11 714 return 0;
e3e288121408c3 Joerg Roedel 2018-04-11 715
6b6378355b9250 Toshi Kani 2015-04-14 716 set_pte((pte_t *)pud, pfn_pte(
6b6378355b9250 Toshi Kani 2015-04-14 717 (u64)addr >> PAGE_SHIFT,
d073569363d9f0 Christoph Hellwig 2020-04-08 718 __pgprot(protval_4k_2_large(pgprot_val(prot)) | _PAGE_PSE)));
6b6378355b9250 Toshi Kani 2015-04-14 719
6b6378355b9250 Toshi Kani 2015-04-14 720 return 1;
6b6378355b9250 Toshi Kani 2015-04-14 721 }
6b6378355b9250 Toshi Kani 2015-04-14 722
3d3ca416d9b078 Toshi Kani 2015-05-26 723 /**
3d3ca416d9b078 Toshi Kani 2015-05-26 724 * pmd_set_huge - setup kernel PMD mapping
3d3ca416d9b078 Toshi Kani 2015-05-26 725 *
b73522e0c1be58 Toshi Kani 2015-05-26 726 * See text over pud_set_huge() above.
3d3ca416d9b078 Toshi Kani 2015-05-26 727 *
3d3ca416d9b078 Toshi Kani 2015-05-26 728 * Returns 1 on success and 0 on failure.
3d3ca416d9b078 Toshi Kani 2015-05-26 729 */
6b6378355b9250 Toshi Kani 2015-04-14 730 int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot)
6b6378355b9250 Toshi Kani 2015-04-14 731 {
b73522e0c1be58 Toshi Kani 2015-05-26 732 u8 mtrr, uniform;
6b6378355b9250 Toshi Kani 2015-04-14 733
b73522e0c1be58 Toshi Kani 2015-05-26 734 mtrr = mtrr_type_lookup(addr, addr + PMD_SIZE, &uniform);
b73522e0c1be58 Toshi Kani 2015-05-26 735 if ((mtrr != MTRR_TYPE_INVALID) && (!uniform) &&
b73522e0c1be58 Toshi Kani 2015-05-26 736 (mtrr != MTRR_TYPE_WRBACK)) {
b73522e0c1be58 Toshi Kani 2015-05-26 737 pr_warn_once("%s: Cannot satisfy [mem %#010llx-%#010llx] with a huge-page mapping due to MTRR override.\n",
b73522e0c1be58 Toshi Kani 2015-05-26 738 __func__, addr, addr + PMD_SIZE);
6b6378355b9250 Toshi Kani 2015-04-14 739 return 0;
b73522e0c1be58 Toshi Kani 2015-05-26 740 }
6b6378355b9250 Toshi Kani 2015-04-14 741
e3e288121408c3 Joerg Roedel 2018-04-11 742 /* Bail out if we are we on a populated non-leaf entry: */
e3e288121408c3 Joerg Roedel 2018-04-11 743 if (pmd_present(*pmd) && !pmd_huge(*pmd))
e3e288121408c3 Joerg Roedel 2018-04-11 744 return 0;
e3e288121408c3 Joerg Roedel 2018-04-11 745
6b6378355b9250 Toshi Kani 2015-04-14 746 set_pte((pte_t *)pmd, pfn_pte(
6b6378355b9250 Toshi Kani 2015-04-14 747 (u64)addr >> PAGE_SHIFT,
d073569363d9f0 Christoph Hellwig 2020-04-08 748 __pgprot(protval_4k_2_large(pgprot_val(prot)) | _PAGE_PSE)));
6b6378355b9250 Toshi Kani 2015-04-14 749
6b6378355b9250 Toshi Kani 2015-04-14 750 return 1;
6b6378355b9250 Toshi Kani 2015-04-14 751 }
6b6378355b9250 Toshi Kani 2015-04-14 752
d8a719059b9dc9 Jonathan Marek 2021-07-21 753 /**
d8a719059b9dc9 Jonathan Marek 2021-07-21 754 * pud_clear_huge - clear kernel PUD mapping when it is set
d8a719059b9dc9 Jonathan Marek 2021-07-21 755 *
d8a719059b9dc9 Jonathan Marek 2021-07-21 756 * Returns 1 on success and 0 on failure (no PUD map is found).
d8a719059b9dc9 Jonathan Marek 2021-07-21 757 */
d8a719059b9dc9 Jonathan Marek 2021-07-21 @758 int pud_clear_huge(pud_t *pud)
d8a719059b9dc9 Jonathan Marek 2021-07-21 759 {
d8a719059b9dc9 Jonathan Marek 2021-07-21 760 if (pud_large(*pud)) {
d8a719059b9dc9 Jonathan Marek 2021-07-21 761 pud_clear(pud);
d8a719059b9dc9 Jonathan Marek 2021-07-21 762 return 1;
d8a719059b9dc9 Jonathan Marek 2021-07-21 763 }
d8a719059b9dc9 Jonathan Marek 2021-07-21 764
d8a719059b9dc9 Jonathan Marek 2021-07-21 765 return 0;
d8a719059b9dc9 Jonathan Marek 2021-07-21 766 }
d8a719059b9dc9 Jonathan Marek 2021-07-21 767 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org