Pull misc fixes from Andrew Morton: "21 hotfixes, 8 of which are cc:stable. 11 are for MM, the remainder are for other subsystems" * tag 'mm-hotfixes-stable-2023-03-24-17-09' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm: (21 commits) mm: mmap: remove newline at the end of the trace mailmap: add entries for Richard Leitner kcsan: avoid passing -g for test kfence: avoid passing -g for test mm: kfence: fix using kfence_metadata without initialization in show_object() lib: dhry: fix unstable smp_processor_id(_) usage mailmap: add entry for Enric Balletbo i Serra mailmap: map Sai Prakash Ranjan's old address to his current one mailmap: map Rajendra Nayak's old address to his current one Revert "kasan: drop skip_kasan_poison variable in free_pages_prepare" mailmap: add entry for Tobias Klauser kasan, powerpc: don't rename memintrinsics if compiler adds prefixes mm/ksm: fix race with VMA iteration and mm_struct teardown kselftest: vm: fix unused variable warning mm: fix error handling for map_deny_write_exec mm: deduplicate error handling for map_deny_write_exec checksyscalls: ignore fstat to silence build warning on LoongArch nilfs2: fix kernel-infoleak in nilfs_ioctl_wrap_copy() test_maple_tree: add more testing for mas_empty_area() maple_tree: fix mas_skip_node() end slot detection ...
Unified · Split
| @@ -133,6 +133,8 @@ Dmitry Safonov <0x7f454c46@gmail.com> <dsafonov@virtuozzo.com> · 132 unmodified lines | ||
| 133 | 133 | Domen Puncer <domen@coderock.org> |
| 134 | 134 | Douglas Gilbert <dougg@torque.net> |
| 135 | 135 | Ed L. Cashin <ecashin@coraid.com> |
| 136 | +Enric Balletbo i Serra <eballetbo@kernel.org> <enric.balletbo@collabora.com> | |
| 137 | +Enric Balletbo i Serra <eballetbo@kernel.org> <eballetbo@iseebcn.com> | |
| 136 | 138 | Erik Kaneda <erik.kaneda@intel.com> <erik.schmauss@intel.com> |
| 137 | 139 | Eugen Hristev <eugen.hristev@collabora.com> <eugen.hristev@microchip.com> |
| 138 | 140 | Evgeniy Polyakov <johnpol@2ka.mipt.ru> |
| @@ -379,6 +381,7 @@ Quentin Monnet <quentin@isovalent.com> <quentin.monnet@netronome.com> · 240 unmodified lines | ||
| 379 | 381 | Quentin Perret <qperret@qperret.net> <quentin.perret@arm.com> |
| 380 | 382 | Rafael J. Wysocki <rjw@rjwysocki.net> <rjw@sisk.pl> |
| 381 | 383 | Rajeev Nandan <quic_rajeevny@quicinc.com> <rajeevny@codeaurora.org> |
| 384 | +Rajendra Nayak <quic_rjendra@quicinc.com> <rnayak@codeaurora.org> | |
| 382 | 385 | Rajesh Shah <rajesh.shah@intel.com> |
| 383 | 386 | Ralf Baechle <ralf@linux-mips.org> |
| 384 | 387 | Ralf Wildenhues <Ralf.Wildenhues@gmx.de> |
| @@ -387,6 +390,9 @@ Rémi Denis-Courmont <rdenis@simphalempin.com> · 2 unmodified lines | ||
| 387 | 390 | Ricardo Ribalda <ribalda@kernel.org> <ricardo@ribalda.com> |
| 388 | 391 | Ricardo Ribalda <ribalda@kernel.org> Ricardo Ribalda Delgado <ribalda@kernel.org> |
| 389 | 392 | Ricardo Ribalda <ribalda@kernel.org> <ricardo.ribalda@gmail.com> |
| 393 | +Richard Leitner <richard.leitner@linux.dev> <dev@g0hl1n.net> | |
| 394 | +Richard Leitner <richard.leitner@linux.dev> <me@g0hl1n.net> | |
| 395 | +Richard Leitner <richard.leitner@linux.dev> <richard.leitner@skidata.com> | |
| 390 | 396 | Robert Foss <rfoss@kernel.org> <robert.foss@linaro.org> |
| 391 | 397 | Roman Gushchin <roman.gushchin@linux.dev> <guro@fb.com> |
| 392 | 398 | Roman Gushchin <roman.gushchin@linux.dev> <guroan@gmail.com> |
| @@ -397,6 +403,7 @@ Ross Zwisler <zwisler@kernel.org> <ross.zwisler@linux.intel.com> · 4 unmodified lines | ||
| 397 | 403 | Rudolf Marek <R.Marek@sh.cvut.cz> |
| 398 | 404 | Rui Saraiva <rmps@joel.ist.utl.pt> |
| 399 | 405 | Sachin P Sant <ssant@in.ibm.com> |
| 406 | +Sai Prakash Ranjan <quic_saipraka@quicinc.com> <saiprakash.ranjan@codeaurora.org> | |
| 400 | 407 | Sakari Ailus <sakari.ailus@linux.intel.com> <sakari.ailus@iki.fi> |
| 401 | 408 | Sam Ravnborg <sam@mars.ravnborg.org> |
| 402 | 409 | Sankeerth Billakanti <quic_sbillaka@quicinc.com> <sbillaka@codeaurora.org> |
| @@ -437,6 +444,10 @@ Thomas Graf <tgraf@suug.ch> · 34 unmodified lines | ||
| 437 | 444 | Thomas Körper <socketcan@esd.eu> <thomas.koerper@esd.eu> |
| 438 | 445 | Thomas Pedersen <twp@codeaurora.org> |
| 439 | 446 | Tiezhu Yang <yangtiezhu@loongson.cn> <kernelpatch@126.com> |
| 447 | +Tobias Klauser <tklauser@distanz.ch> <tobias.klauser@gmail.com> | |
| 448 | +Tobias Klauser <tklauser@distanz.ch> <klto@zhaw.ch> | |
| 449 | +Tobias Klauser <tklauser@distanz.ch> <tklauser@nuerscht.ch> | |
| 450 | +Tobias Klauser <tklauser@distanz.ch> <tklauser@xenon.tklauser.home> | |
| 440 | 451 | Todor Tomov <todor.too@gmail.com> <todor.tomov@linaro.org> |
| 441 | 452 | Tony Luck <tony.luck@intel.com> |
| 442 | 453 | TripleX Chung <xxx.phy@gmail.com> <triplex@zh-kernel.org> |
| @@ -2,7 +2,7 @@ · 1 unmodified line | ||
| 2 | 2 | #ifndef __ASM_KASAN_H |
| 3 | 3 | #define __ASM_KASAN_H |
| 4 | 4 | |
| 5 | −#ifdef CONFIG_KASAN | |
| 5 | +#if defined(CONFIG_KASAN) && !defined(CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX) | |
| 6 | 6 | #define _GLOBAL_KASAN(fn) _GLOBAL(__##fn) |
| 7 | 7 | #define _GLOBAL_TOC_KASAN(fn) _GLOBAL_TOC(__##fn) |
| 8 | 8 | #define EXPORT_SYMBOL_KASAN(fn) EXPORT_SYMBOL(__##fn) |
| @@ -30,11 +30,17 @@ extern int memcmp(const void *,const void *,__kernel_size_t); · 29 unmodified lines | ||
| 30 | 30 | extern void * memchr(const void *,int,__kernel_size_t); |
| 31 | 31 | void memcpy_flushcache(void *dest, const void *src, size_t size); |
| 32 | 32 | |
| 33 | +#ifdef CONFIG_KASAN | |
| 34 | +/* __mem variants are used by KASAN to implement instrumented meminstrinsics. */ | |
| 35 | +#ifdef CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX | |
| 36 | +#define __memset memset | |
| 37 | +#define __memcpy memcpy | |
| 38 | +#define __memmove memmove | |
| 39 | +#else /* CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX */ | |
| 33 | 40 | void *__memset(void *s, int c, __kernel_size_t count); |
| 34 | 41 | void *__memcpy(void *to, const void *from, __kernel_size_t n); |
| 35 | 42 | void *__memmove(void *to, const void *from, __kernel_size_t n); |
| 36 | − | |
| 37 | −#if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__) | |
| 43 | +#ifndef __SANITIZE_ADDRESS__ | |
| 38 | 44 | /* |
| 39 | 45 | * For files that are not instrumented (e.g. mm/slub.c) we |
| 40 | 46 | * should use not instrumented version of mem* functions. |
| @@ -46,8 +52,9 @@ void *__memmove(void *to, const void *from, __kernel_size_t n); · 5 unmodified lines | ||
| 46 | 52 | #ifndef __NO_FORTIFY |
| 47 | 53 | #define __NO_FORTIFY /* FORTIFY_SOURCE uses __builtin_memcpy, etc. */ |
| 48 | 54 | #endif |
| 49 | − | |
| 50 | −#endif | |
| 55 | +#endif /* !__SANITIZE_ADDRESS__ */ | |
| 56 | +#endif /* CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX */ | |
| 57 | +#endif /* CONFIG_KASAN */ | |
| 51 | 58 | |
| 52 | 59 | #ifdef CONFIG_PPC64 |
| 53 | 60 | #ifndef CONFIG_KASAN |
| @@ -13,8 +13,13 @@ · 12 unmodified lines | ||
| 13 | 13 | # If you really need to reference something from prom_init.o add |
| 14 | 14 | # it to the list below: |
| 15 | 15 | |
| 16 | −grep "^CONFIG_KASAN=y$" ${KCONFIG_CONFIG} >/dev/null | |
| 17 | −if [ $? -eq 0 ] | |
| 16 | +has_renamed_memintrinsics() | |
| 17 | +{ | |
| 18 | + grep -q "^CONFIG_KASAN=y$" ${KCONFIG_CONFIG} && \ | |
| 19 | + ! grep -q "^CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX=y" ${KCONFIG_CONFIG} | |
| 20 | +} | |
| 21 | + | |
| 22 | +if has_renamed_memintrinsics | |
| 18 | 23 | then |
| 19 | 24 | MEM_FUNCS="__memcpy __memset" |
| 20 | 25 | else |
| @@ -71,7 +71,7 @@ static int nilfs_ioctl_wrap_copy(struct the_nilfs *nilfs, · 70 unmodified lines | ||
| 71 | 71 | if (argv->v_index > ~(__u64)0 - argv->v_nmembs) |
| 72 | 72 | return -EINVAL; |
| 73 | 73 | |
| 74 | − buf = (void *)__get_free_pages(GFP_NOFS, 0); | |
| 74 | + buf = (void *)get_zeroed_page(GFP_NOFS); | |
| 75 | 75 | if (unlikely(!buf)) |
| 76 | 76 | return -ENOMEM; |
| 77 | 77 | maxmembs = PAGE_SIZE / argv->v_size; |
| @@ -35,7 +35,7 @@ TRACE_EVENT(vm_unmapped_area, · 34 unmodified lines | ||
| 35 | 35 | __entry->align_offset = info->align_offset; |
| 36 | 36 | ), |
| 37 | 37 | |
| 38 | − TP_printk("addr=0x%lx err=%ld total_vm=0x%lx flags=0x%lx len=0x%lx lo=0x%lx hi=0x%lx mask=0x%lx ofs=0x%lx\n", | |
| 38 | + TP_printk("addr=0x%lx err=%ld total_vm=0x%lx flags=0x%lx len=0x%lx lo=0x%lx hi=0x%lx mask=0x%lx ofs=0x%lx", | |
| 39 | 39 | IS_ERR_VALUE(__entry->addr) ? 0 : __entry->addr, |
| 40 | 40 | IS_ERR_VALUE(__entry->addr) ? __entry->addr : 0, |
| 41 | 41 | __entry->total_vm, __entry->flags, __entry->length, |
| @@ -110,7 +110,7 @@ TRACE_EVENT(exit_mmap, · 68 unmodified lines | ||
| 110 | 110 | __entry->mt = &mm->mm_mt; |
| 111 | 111 | ), |
| 112 | 112 | |
| 113 | − TP_printk("mt_mod %p, DESTROY\n", | |
| 113 | + TP_printk("mt_mod %p, DESTROY", | |
| 114 | 114 | __entry->mt |
| 115 | 115 | ) |
| 116 | 116 | ); |
| @@ -16,6 +16,6 @@ obj-y := core.o debugfs.o report.o · 15 unmodified lines | ||
| 16 | 16 | KCSAN_INSTRUMENT_BARRIERS_selftest.o := y |
| 17 | 17 | obj-$(CONFIG_KCSAN_SELFTEST) += selftest.o |
| 18 | 18 | |
| 19 | −CFLAGS_kcsan_test.o := $(CFLAGS_KCSAN) -g -fno-omit-frame-pointer | |
| 19 | +CFLAGS_kcsan_test.o := $(CFLAGS_KCSAN) -fno-omit-frame-pointer | |
| 20 | 20 | CFLAGS_kcsan_test.o += $(DISABLE_STRUCTLEAK_PLUGIN) |
| 21 | 21 | obj-$(CONFIG_KCSAN_KUNIT_TEST) += kcsan_test.o |
| @@ -31,6 +31,7 @@ MODULE_PARM_DESC(iterations, · 30 unmodified lines | ||
| 31 | 31 | |
| 32 | 32 | static void dhry_benchmark(void) |
| 33 | 33 | { |
| 34 | + unsigned int cpu = get_cpu(); | |
| 34 | 35 | int i, n; |
| 35 | 36 | |
| 36 | 37 | if (iterations > 0) { |
| @@ -45,9 +46,10 @@ static void dhry_benchmark(void) · 8 unmodified lines | ||
| 45 | 46 | } |
| 46 | 47 | |
| 47 | 48 | report: |
| 49 | + put_cpu(); | |
| 48 | 50 | if (n >= 0) |
| 49 | − pr_info("CPU%u: Dhrystones per Second: %d (%d DMIPS)\n", | |
| 50 | − smp_processor_id(), n, n / DHRY_VAX); | |
| 51 | + pr_info("CPU%u: Dhrystones per Second: %d (%d DMIPS)\n", cpu, | |
| 52 | + n, n / DHRY_VAX); | |
| 51 | 53 | else if (n == -EAGAIN) |
| 52 | 54 | pr_err("Please increase the number of iterations\n"); |
| 53 | 55 | else |
| @@ -5099,35 +5099,21 @@ static inline bool mas_rewind_node(struct ma_state *mas) · 5098 unmodified lines | ||
| 5099 | 5099 | */ |
| 5100 | 5100 | static inline bool mas_skip_node(struct ma_state *mas) |
| 5101 | 5101 | { |
| 5102 | − unsigned char slot, slot_count; | |
| 5103 | − unsigned long *pivots; | |
| 5104 | − enum maple_type mt; | |
| 5102 | + if (mas_is_err(mas)) | |
| 5103 | + return false; | |
| 5105 | 5104 | |
| 5106 | − mt = mte_node_type(mas->node); | |
| 5107 | − slot_count = mt_slots[mt] - 1; | |
| 5108 | 5105 | do { |
| 5109 | 5106 | if (mte_is_root(mas->node)) { |
| 5110 | − slot = mas->offset; | |
| 5111 | − if (slot > slot_count) { | |
| 5107 | + if (mas->offset >= mas_data_end(mas)) { | |
| 5112 | 5108 | mas_set_err(mas, -EBUSY); |
| 5113 | 5109 | return false; |
| 5114 | 5110 | } |
| 5115 | 5111 | } else { |
| 5116 | 5112 | mas_ascend(mas); |
| 5117 | − slot = mas->offset; | |
| 5118 | − mt = mte_node_type(mas->node); | |
| 5119 | − slot_count = mt_slots[mt] - 1; | |
| 5120 | 5113 | } |
| 5121 | − } while (slot > slot_count); | |
| 5122 | − | |
| 5123 | − mas->offset = ++slot; | |
| 5124 | − pivots = ma_pivots(mas_mn(mas), mt); | |
| 5125 | − if (slot > 0) | |
| 5126 | − mas->min = pivots[slot - 1] + 1; | |
| 5127 | − | |
| 5128 | − if (slot <= slot_count) | |
| 5129 | − mas->max = pivots[slot]; | |
| 5114 | + } while (mas->offset >= mas_data_end(mas)); | |
| 5130 | 5115 | |
| 5116 | + mas->offset++; | |
| 5131 | 5117 | return true; |
| 5132 | 5118 | } |
| 5133 | 5119 | |
| @@ -2670,6 +2670,49 @@ static noinline void check_empty_area_window(struct maple_tree *mt) · 2669 unmodified lines | ||
| 2670 | 2670 | rcu_read_unlock(); |
| 2671 | 2671 | } |
| 2672 | 2672 | |
| 2673 | +static noinline void check_empty_area_fill(struct maple_tree *mt) | |
| 2674 | +{ | |
| 2675 | + const unsigned long max = 0x25D78000; | |
| 2676 | + unsigned long size; | |
| 2677 | + int loop, shift; | |
| 2678 | + MA_STATE(mas, mt, 0, 0); | |
| 2679 | + | |
| 2680 | + mt_set_non_kernel(99999); | |
| 2681 | + for (shift = 12; shift <= 16; shift++) { | |
| 2682 | + loop = 5000; | |
| 2683 | + size = 1 << shift; | |
| 2684 | + while (loop--) { | |
| 2685 | + mas_set(&mas, 0); | |
| 2686 | + mas_lock(&mas); | |
| 2687 | + MT_BUG_ON(mt, mas_empty_area(&mas, 0, max, size) != 0); | |
| 2688 | + MT_BUG_ON(mt, mas.last != mas.index + size - 1); | |
| 2689 | + mas_store_gfp(&mas, (void *)size, GFP_KERNEL); | |
| 2690 | + mas_unlock(&mas); | |
| 2691 | + mas_reset(&mas); | |
| 2692 | + } | |
| 2693 | + } | |
| 2694 | + | |
| 2695 | + /* No space left. */ | |
| 2696 | + size = 0x1000; | |
| 2697 | + rcu_read_lock(); | |
| 2698 | + MT_BUG_ON(mt, mas_empty_area(&mas, 0, max, size) != -EBUSY); | |
| 2699 | + rcu_read_unlock(); | |
| 2700 | + | |
| 2701 | + /* Fill a depth 3 node to the maximum */ | |
| 2702 | + for (unsigned long i = 629440511; i <= 629440800; i += 6) | |
| 2703 | + mtree_store_range(mt, i, i + 5, (void *)i, GFP_KERNEL); | |
| 2704 | + /* Make space in the second-last depth 4 node */ | |
| 2705 | + mtree_erase(mt, 631668735); | |
| 2706 | + /* Make space in the last depth 4 node */ | |
| 2707 | + mtree_erase(mt, 629506047); | |
| 2708 | + mas_reset(&mas); | |
| 2709 | + /* Search from just after the gap in the second-last depth 4 */ | |
| 2710 | + rcu_read_lock(); | |
| 2711 | + MT_BUG_ON(mt, mas_empty_area(&mas, 629506048, 690000000, 0x5000) != 0); | |
| 2712 | + rcu_read_unlock(); | |
| 2713 | + mt_set_non_kernel(0); | |
| 2714 | +} | |
| 2715 | + | |
| 2673 | 2716 | static DEFINE_MTREE(tree); |
| 2674 | 2717 | static int maple_tree_seed(void) |
| 2675 | 2718 | { |
| @@ -2926,6 +2969,11 @@ static int maple_tree_seed(void) · 250 unmodified lines | ||
| 2926 | 2969 | check_empty_area_window(&tree); |
| 2927 | 2970 | mtree_destroy(&tree); |
| 2928 | 2971 | |
| 2972 | + mt_init_flags(&tree, MT_FLAGS_ALLOC_RANGE); | |
| 2973 | + check_empty_area_fill(&tree); | |
| 2974 | + mtree_destroy(&tree); | |
| 2975 | + | |
| 2976 | + | |
| 2929 | 2977 | #if defined(BENCH) |
| 2930 | 2978 | skip: |
| 2931 | 2979 | #endif |
| @@ -2,5 +2,5 @@ · 1 unmodified line | ||
| 2 | 2 | |
| 3 | 3 | obj-y := core.o report.o |
| 4 | 4 | |
| 5 | −CFLAGS_kfence_test.o := -g -fno-omit-frame-pointer -fno-optimize-sibling-calls | |
| 5 | +CFLAGS_kfence_test.o := -fno-omit-frame-pointer -fno-optimize-sibling-calls | |
| 6 | 6 | obj-$(CONFIG_KFENCE_KUNIT_TEST) += kfence_test.o |
| @@ -726,10 +726,14 @@ static const struct seq_operations objects_sops = { · 725 unmodified lines | ||
| 726 | 726 | }; |
| 727 | 727 | DEFINE_SEQ_ATTRIBUTE(objects); |
| 728 | 728 | |
| 729 | −static int __init kfence_debugfs_init(void) | |
| 729 | +static int kfence_debugfs_init(void) | |
| 730 | 730 | { |
| 731 | − struct dentry *kfence_dir = debugfs_create_dir("kfence", NULL); | |
| 731 | + struct dentry *kfence_dir; | |
| 732 | 732 | |
| 733 | + if (!READ_ONCE(kfence_enabled)) | |
| 734 | + return 0; | |
| 735 | + | |
| 736 | + kfence_dir = debugfs_create_dir("kfence", NULL); | |
| 733 | 737 | debugfs_create_file("stats", 0444, kfence_dir, NULL, &stats_fops); |
| 734 | 738 | debugfs_create_file("objects", 0400, kfence_dir, NULL, &objects_fops); |
| 735 | 739 | return 0; |
| @@ -883,6 +887,8 @@ static int kfence_init_late(void) · 147 unmodified lines | ||
| 883 | 887 | } |
| 884 | 888 | |
| 885 | 889 | kfence_init_enable(); |
| 890 | + kfence_debugfs_init(); | |
| 891 | + | |
| 886 | 892 | return 0; |
| 887 | 893 | } |
| 888 | 894 | |
| @@ -988,9 +988,15 @@ static int unmerge_and_remove_all_rmap_items(void) · 987 unmodified lines | ||
| 988 | 988 | |
| 989 | 989 | mm = mm_slot->slot.mm; |
| 990 | 990 | mmap_read_lock(mm); |
| 991 | + | |
| 992 | + /* | |
| 993 | + * Exit right away if mm is exiting to avoid lockdep issue in | |
| 994 | + * the maple tree | |
| 995 | + */ | |
| 996 | + if (ksm_test_exit(mm)) | |
| 997 | + goto mm_exiting; | |
| 998 | + | |
| 991 | 999 | for_each_vma(vmi, vma) { |
| 992 | − if (ksm_test_exit(mm)) | |
| 993 | − break; | |
| 994 | 1000 | if (!(vma->vm_flags & VM_MERGEABLE) || !vma->anon_vma) |
| 995 | 1001 | continue; |
| 996 | 1002 | err = unmerge_ksm_pages(vma, |
| @@ -999,6 +1005,7 @@ static int unmerge_and_remove_all_rmap_items(void) · 2 unmodified lines | ||
| 999 | 1005 | goto error; |
| 1000 | 1006 | } |
| 1001 | 1007 | |
| 1008 | +mm_exiting: | |
| 1002 | 1009 | remove_trailing_rmap_items(&mm_slot->rmap_list); |
| 1003 | 1010 | mmap_read_unlock(mm); |
| 1004 | 1011 | |
| @@ -2621,12 +2621,7 @@ cannot_expand: · 2620 unmodified lines | ||
| 2621 | 2621 | |
| 2622 | 2622 | if (map_deny_write_exec(vma, vma->vm_flags)) { |
| 2623 | 2623 | error = -EACCES; |
| 2624 | − if (file) | |
| 2625 | − goto close_and_free_vma; | |
| 2626 | − else if (vma->vm_file) | |
| 2627 | − goto unmap_and_free_vma; | |
| 2628 | − else | |
| 2629 | − goto free_vma; | |
| 2624 | + goto close_and_free_vma; | |
| 2630 | 2625 | } |
| 2631 | 2626 | |
| 2632 | 2627 | /* Allow architectures to sanity-check the vm_flags */ |
| @@ -805,7 +805,7 @@ static int do_mprotect_pkey(unsigned long start, size_t len, · 804 unmodified lines | ||
| 805 | 805 | |
| 806 | 806 | if (map_deny_write_exec(vma, newflags)) { |
| 807 | 807 | error = -EACCES; |
| 808 | − goto out; | |
| 808 | + break; | |
| 809 | 809 | } |
| 810 | 810 | |
| 811 | 811 | /* Allow architectures to sanity-check the new flags */ |
| @@ -1398,6 +1398,7 @@ static __always_inline bool free_pages_prepare(struct page *page, · 1397 unmodified lines | ||
| 1398 | 1398 | unsigned int order, bool check_free, fpi_t fpi_flags) |
| 1399 | 1399 | { |
| 1400 | 1400 | int bad = 0; |
| 1401 | + bool skip_kasan_poison = should_skip_kasan_poison(page, fpi_flags); | |
| 1401 | 1402 | bool init = want_init_on_free(); |
| 1402 | 1403 | |
| 1403 | 1404 | VM_BUG_ON_PAGE(PageTail(page), page); |
| @@ -1470,7 +1471,7 @@ static __always_inline bool free_pages_prepare(struct page *page, · 66 unmodified lines | ||
| 1470 | 1471 | * With hardware tag-based KASAN, memory tags must be set before the |
| 1471 | 1472 | * page becomes unavailable via debug_pagealloc or arch_free_page. |
| 1472 | 1473 | */ |
| 1473 | − if (!should_skip_kasan_poison(page, fpi_flags)) { | |
| 1474 | + if (!skip_kasan_poison) { | |
| 1474 | 1475 | kasan_poison_pages(page, order, init); |
| 1475 | 1476 | |
| 1476 | 1477 | /* Memory is already initialized if KASAN did it internally. */ |
| @@ -2883,6 +2883,8 @@ vm_area_alloc_pages(gfp_t gfp, int nid, · 2882 unmodified lines | ||
| 2883 | 2883 | unsigned int order, unsigned int nr_pages, struct page **pages) |
| 2884 | 2884 | { |
| 2885 | 2885 | unsigned int nr_allocated = 0; |
| 2886 | + gfp_t alloc_gfp = gfp; | |
| 2887 | + bool nofail = false; | |
| 2886 | 2888 | struct page *page; |
| 2887 | 2889 | int i; |
| 2888 | 2890 | |
| @@ -2893,6 +2895,7 @@ vm_area_alloc_pages(gfp_t gfp, int nid, · 4 unmodified lines | ||
| 2893 | 2895 | * more permissive. |
| 2894 | 2896 | */ |
| 2895 | 2897 | if (!order) { |
| 2898 | + /* bulk allocator doesn't support nofail req. officially */ | |
| 2896 | 2899 | gfp_t bulk_gfp = gfp & ~__GFP_NOFAIL; |
| 2897 | 2900 | |
| 2898 | 2901 | while (nr_allocated < nr_pages) { |
| @@ -2931,20 +2934,35 @@ vm_area_alloc_pages(gfp_t gfp, int nid, · 32 unmodified lines | ||
| 2931 | 2934 | if (nr != nr_pages_request) |
| 2932 | 2935 | break; |
| 2933 | 2936 | } |
| 2937 | + } else if (gfp & __GFP_NOFAIL) { | |
| 2938 | + /* | |
| 2939 | + * Higher order nofail allocations are really expensive and | |
| 2940 | + * potentially dangerous (pre-mature OOM, disruptive reclaim | |
| 2941 | + * and compaction etc. | |
| 2942 | + */ | |
| 2943 | + alloc_gfp &= ~__GFP_NOFAIL; | |
| 2944 | + nofail = true; | |
| 2934 | 2945 | } |
| 2935 | 2946 | |
| 2936 | 2947 | /* High-order pages or fallback path if "bulk" fails. */ |
| 2937 | − | |
| 2938 | 2948 | while (nr_allocated < nr_pages) { |
| 2939 | 2949 | if (fatal_signal_pending(current)) |
| 2940 | 2950 | break; |
| 2941 | 2951 | |
| 2942 | 2952 | if (nid == NUMA_NO_NODE) |
| 2943 | − page = alloc_pages(gfp, order); | |
| 2953 | + page = alloc_pages(alloc_gfp, order); | |
| 2944 | 2954 | else |
| 2945 | − page = alloc_pages_node(nid, gfp, order); | |
| 2946 | − if (unlikely(!page)) | |
| 2947 | − break; | |
| 2955 | + page = alloc_pages_node(nid, alloc_gfp, order); | |
| 2956 | + if (unlikely(!page)) { | |
| 2957 | + if (!nofail) | |
| 2958 | + break; | |
| 2959 | + | |
| 2960 | + /* fall back to the zero order allocations */ | |
| 2961 | + alloc_gfp |= __GFP_NOFAIL; | |
| 2962 | + order = 0; | |
| 2963 | + continue; | |
| 2964 | + } | |
| 2965 | + | |
| 2948 | 2966 | /* |
| 2949 | 2967 | * Higher order allocations must be able to be treated as |
| 2950 | 2968 | * indepdenent small pages by callers (as they can with |
| @@ -114,7 +114,6 @@ cat << EOF · 113 unmodified lines | ||
| 114 | 114 | #define __IGNORE_truncate |
| 115 | 115 | #define __IGNORE_stat |
| 116 | 116 | #define __IGNORE_lstat |
| 117 | −#define __IGNORE_fstat | |
| 118 | 117 | #define __IGNORE_fcntl |
| 119 | 118 | #define __IGNORE_fadvise64 |
| 120 | 119 | #define __IGNORE_newfstatat |
| @@ -255,6 +254,9 @@ cat << EOF · 134 unmodified lines | ||
| 255 | 254 | /* 64-bit ports never needed these, and new 32-bit ports can use statx */ |
| 256 | 255 | #define __IGNORE_fstat64 |
| 257 | 256 | #define __IGNORE_fstatat64 |
| 257 | + | |
| 258 | +/* Newer ports are not required to provide fstat in favor of statx */ | |
| 259 | +#define __IGNORE_fstat | |
| 258 | 260 | EOF |
| 259 | 261 | } |
| 260 | 262 | |
| @@ -163,9 +163,8 @@ TEST_F(mdwe, mprotect_WRITE_EXEC) · 162 unmodified lines | ||
| 163 | 163 | |
| 164 | 164 | TEST_F(mdwe, mmap_FIXED) |
| 165 | 165 | { |
| 166 | − void *p, *p2; | |
| 166 | + void *p; | |
| 167 | 167 | |
| 168 | − p2 = mmap(NULL, self->size, PROT_READ | PROT_EXEC, self->flags, 0, 0); | |
| 169 | 168 | self->p = mmap(NULL, self->size, PROT_READ, self->flags, 0, 0); |
| 170 | 169 | ASSERT_NE(self->p, MAP_FAILED); |
| 171 | 170 | |