Merge misc fixes from Andrew Morton: "8 fixes" * emailed patches from Andrew Morton <akpm@linux-foundation.org>: lib/test_kmod.c: fix limit check on number of test devices created selftests/vm/run_vmtests: adjust hugetlb size according to nr_cpus mm/page_alloc: fix memmap_init_zone pageblock alignment mm/memblock.c: hardcode the end_pfn being -1 mm/gup.c: teach get_user_pages_unlocked to handle FOLL_NOWAIT lib/bug.c: exclude non-BUG/WARN exceptions from report_bug() bug: use %pB in BUG and stack protector failure hugetlb: fix surplus pages accounting
Unified · Split
| @@ -640,7 +640,7 @@ device_initcall(register_warn_debugfs); · 639 unmodified lines | ||
| 640 | 640 | */ |
| 641 | 641 | __visible void __stack_chk_fail(void) |
| 642 | 642 | { |
| 643 | − panic("stack-protector: Kernel stack is corrupted in: %p\n", | |
| 643 | + panic("stack-protector: Kernel stack is corrupted in: %pB\n", | |
| 644 | 644 | __builtin_return_address(0)); |
| 645 | 645 | } |
| 646 | 646 | EXPORT_SYMBOL(__stack_chk_fail); |
| @@ -150,6 +150,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs) · 149 unmodified lines | ||
| 150 | 150 | return BUG_TRAP_TYPE_NONE; |
| 151 | 151 | |
| 152 | 152 | bug = find_bug(bugaddr); |
| 153 | + if (!bug) | |
| 154 | + return BUG_TRAP_TYPE_NONE; | |
| 153 | 155 | |
| 154 | 156 | file = NULL; |
| 155 | 157 | line = 0; |
| @@ -191,7 +193,7 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs) · 35 unmodified lines | ||
| 191 | 193 | if (file) |
| 192 | 194 | pr_crit("kernel BUG at %s:%u!\n", file, line); |
| 193 | 195 | else |
| 194 | − pr_crit("Kernel BUG at %p [verbose debug info unavailable]\n", | |
| 196 | + pr_crit("Kernel BUG at %pB [verbose debug info unavailable]\n", | |
| 195 | 197 | (void *)bugaddr); |
| 196 | 198 | |
| 197 | 199 | return BUG_TRAP_TYPE_BUG; |
| @@ -1141,7 +1141,7 @@ static struct kmod_test_device *register_test_dev_kmod(void) · 1140 unmodified lines | ||
| 1141 | 1141 | mutex_lock(®_dev_mutex); |
| 1142 | 1142 | |
| 1143 | 1143 | /* int should suffice for number of devices, test for wrap */ |
| 1144 | − if (unlikely(num_test_devs + 1) < 0) { | |
| 1144 | + if (num_test_devs + 1 == INT_MAX) { | |
| 1145 | 1145 | pr_err("reached limit of number of test devices\n"); |
| 1146 | 1146 | goto out; |
| 1147 | 1147 | } |
| @@ -516,7 +516,7 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma, · 515 unmodified lines | ||
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | if (ret & VM_FAULT_RETRY) { |
| 519 | − if (nonblocking) | |
| 519 | + if (nonblocking && !(fault_flags & FAULT_FLAG_RETRY_NOWAIT)) | |
| 520 | 520 | *nonblocking = 0; |
| 521 | 521 | return -EBUSY; |
| 522 | 522 | } |
| @@ -890,7 +890,10 @@ static __always_inline long __get_user_pages_locked(struct task_struct *tsk, · 367 unmodified lines | ||
| 890 | 890 | break; |
| 891 | 891 | } |
| 892 | 892 | if (*locked) { |
| 893 | − /* VM_FAULT_RETRY didn't trigger */ | |
| 893 | + /* | |
| 894 | + * VM_FAULT_RETRY didn't trigger or it was a | |
| 895 | + * FOLL_NOWAIT. | |
| 896 | + */ | |
| 894 | 897 | if (!pages_done) |
| 895 | 898 | pages_done = ret; |
| 896 | 899 | break; |
| @@ -1583,7 +1583,7 @@ static struct page *alloc_surplus_huge_page(struct hstate *h, gfp_t gfp_mask, · 1582 unmodified lines | ||
| 1583 | 1583 | page = NULL; |
| 1584 | 1584 | } else { |
| 1585 | 1585 | h->surplus_huge_pages++; |
| 1586 | − h->nr_huge_pages_node[page_to_nid(page)]++; | |
| 1586 | + h->surplus_huge_pages_node[page_to_nid(page)]++; | |
| 1587 | 1587 | } |
| 1588 | 1588 | |
| 1589 | 1589 | out_unlock: |
| @@ -1107,7 +1107,7 @@ unsigned long __init_memblock memblock_next_valid_pfn(unsigned long pfn, · 1106 unmodified lines | ||
| 1107 | 1107 | struct memblock_type *type = &memblock.memory; |
| 1108 | 1108 | unsigned int right = type->cnt; |
| 1109 | 1109 | unsigned int mid, left = 0; |
| 1110 | − phys_addr_t addr = PFN_PHYS(pfn + 1); | |
| 1110 | + phys_addr_t addr = PFN_PHYS(++pfn); | |
| 1111 | 1111 | |
| 1112 | 1112 | do { |
| 1113 | 1113 | mid = (right + left) / 2; |
| @@ -1118,15 +1118,15 @@ unsigned long __init_memblock memblock_next_valid_pfn(unsigned long pfn, · 4 unmodified lines | ||
| 1118 | 1118 | type->regions[mid].size)) |
| 1119 | 1119 | left = mid + 1; |
| 1120 | 1120 | else { |
| 1121 | − /* addr is within the region, so pfn + 1 is valid */ | |
| 1122 | − return min(pfn + 1, max_pfn); | |
| 1121 | + /* addr is within the region, so pfn is valid */ | |
| 1122 | + return pfn; | |
| 1123 | 1123 | } |
| 1124 | 1124 | } while (left < right); |
| 1125 | 1125 | |
| 1126 | 1126 | if (right == type->cnt) |
| 1127 | − return max_pfn; | |
| 1127 | + return -1UL; | |
| 1128 | 1128 | else |
| 1129 | − return min(PHYS_PFN(type->regions[right].base), max_pfn); | |
| 1129 | + return PHYS_PFN(type->regions[right].base); | |
| 1130 | 1130 | } |
| 1131 | 1131 | |
| 1132 | 1132 | /** |
| @@ -5359,9 +5359,14 @@ void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone, · 5358 unmodified lines | ||
| 5359 | 5359 | /* |
| 5360 | 5360 | * Skip to the pfn preceding the next valid one (or |
| 5361 | 5361 | * end_pfn), such that we hit a valid pfn (or end_pfn) |
| 5362 | − * on our next iteration of the loop. | |
| 5362 | + * on our next iteration of the loop. Note that it needs | |
| 5363 | + * to be pageblock aligned even when the region itself | |
| 5364 | + * is not. move_freepages_block() can shift ahead of | |
| 5365 | + * the valid region but still depends on correct page | |
| 5366 | + * metadata. | |
| 5363 | 5367 | */ |
| 5364 | − pfn = memblock_next_valid_pfn(pfn, end_pfn) - 1; | |
| 5368 | + pfn = (memblock_next_valid_pfn(pfn, end_pfn) & | |
| 5369 | + ~(pageblock_nr_pages-1)) - 1; | |
| 5365 | 5370 | #endif |
| 5366 | 5371 | continue; |
| 5367 | 5372 | } |
| @@ -2,25 +2,33 @@ · 1 unmodified line | ||
| 2 | 2 | # SPDX-License-Identifier: GPL-2.0 |
| 3 | 3 | #please run as root |
| 4 | 4 | |
| 5 | −#we need 256M, below is the size in kB | |
| 6 | −needmem=262144 | |
| 7 | 5 | mnt=./huge |
| 8 | 6 | exitcode=0 |
| 9 | 7 | |
| 10 | −#get pagesize and freepages from /proc/meminfo | |
| 8 | +#get huge pagesize and freepages from /proc/meminfo | |
| 11 | 9 | while read name size unit; do |
| 12 | 10 | if [ "$name" = "HugePages_Free:" ]; then |
| 13 | 11 | freepgs=$size |
| 14 | 12 | fi |
| 15 | 13 | if [ "$name" = "Hugepagesize:" ]; then |
| 16 | − pgsize=$size | |
| 14 | + hpgsize_KB=$size | |
| 17 | 15 | fi |
| 18 | 16 | done < /proc/meminfo |
| 19 | 17 | |
| 18 | +# Simple hugetlbfs tests have a hardcoded minimum requirement of | |
| 19 | +# huge pages totaling 256MB (262144KB) in size. The userfaultfd | |
| 20 | +# hugetlb test requires a minimum of 2 * nr_cpus huge pages. Take | |
| 21 | +# both of these requirements into account and attempt to increase | |
| 22 | +# number of huge pages available. | |
| 23 | +nr_cpus=$(nproc) | |
| 24 | +hpgsize_MB=$((hpgsize_KB / 1024)) | |
| 25 | +half_ufd_size_MB=$((((nr_cpus * hpgsize_MB + 127) / 128) * 128)) | |
| 26 | +needmem_KB=$((half_ufd_size_MB * 2 * 1024)) | |
| 27 | + | |
| 20 | 28 | #set proper nr_hugepages |
| 21 | −if [ -n "$freepgs" ] && [ -n "$pgsize" ]; then | |
| 29 | +if [ -n "$freepgs" ] && [ -n "$hpgsize_KB" ]; then | |
| 22 | 30 | nr_hugepgs=`cat /proc/sys/vm/nr_hugepages` |
| 23 | − needpgs=`expr $needmem / $pgsize` | |
| 31 | + needpgs=$((needmem_KB / hpgsize_KB)) | |
| 24 | 32 | tries=2 |
| 25 | 33 | while [ $tries -gt 0 ] && [ $freepgs -lt $needpgs ]; do |
| 26 | 34 | lackpgs=$(( $needpgs - $freepgs )) |
| @@ -107,8 +115,9 @@ fi · 80 unmodified lines | ||
| 107 | 115 | echo "---------------------------" |
| 108 | 116 | echo "running userfaultfd_hugetlb" |
| 109 | 117 | echo "---------------------------" |
| 110 | −# 256MB total huge pages == 128MB src and 128MB dst | |
| 111 | −./userfaultfd hugetlb 128 32 $mnt/ufd_test_file | |
| 118 | +# Test requires source and destination huge pages. Size of source | |
| 119 | +# (half_ufd_size_MB) is passed as argument to test. | |
| 120 | +./userfaultfd hugetlb $half_ufd_size_MB 32 $mnt/ufd_test_file | |
| 112 | 121 | if [ $? -ne 0 ]; then |
| 113 | 122 | echo "[FAIL]" |
| 114 | 123 | exitcode=1 |