From 905889bba603c28fc5fe6a7c5cd1d1ee1fc9ff33 Mon Sep 17 00:00:00 2001 From: ferreo Date: Sat, 8 Feb 2025 19:54:43 +0100 Subject: [PATCH] Update patches/0001-cachyos-base-all.patch --- patches/0001-cachyos-base-all.patch | 676 ++++++++++++---------------- 1 file changed, 297 insertions(+), 379 deletions(-) diff --git a/patches/0001-cachyos-base-all.patch b/patches/0001-cachyos-base-all.patch index 7bd0007..4d8a3c0 100644 --- a/patches/0001-cachyos-base-all.patch +++ b/patches/0001-cachyos-base-all.patch @@ -1,15 +1,15 @@ -From bb47d9fb19e79f1962a974ae8dd30337c28713c4 Mon Sep 17 00:00:00 2001 +From dd5205fde48cf230cebc74befe37b40f7fa82e71 Mon Sep 17 00:00:00 2001 From: Peter Jung -Date: Sun, 2 Feb 2025 13:53:06 +0100 +Date: Sat, 8 Feb 2025 10:35:37 +0100 Subject: [PATCH 01/12] amd-pstate Signed-off-by: Peter Jung --- - drivers/cpufreq/amd-pstate-trace.h | 52 +++- + drivers/cpufreq/amd-pstate-trace.h | 52 ++- drivers/cpufreq/amd-pstate-ut.c | 12 +- - drivers/cpufreq/amd-pstate.c | 474 ++++++++++++++--------------- + drivers/cpufreq/amd-pstate.c | 490 ++++++++++++++--------------- drivers/cpufreq/amd-pstate.h | 3 - - 4 files changed, 276 insertions(+), 265 deletions(-) + 4 files changed, 284 insertions(+), 273 deletions(-) diff --git a/drivers/cpufreq/amd-pstate-trace.h b/drivers/cpufreq/amd-pstate-trace.h index 35f38ae67fb1..8d692415d905 100644 @@ -156,7 +156,7 @@ index a261d7300951..3a0a380c3590 100644 } } else { diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c -index 66e5dfc711c0..2330903a8b45 100644 +index f6d04eb40af9..6a1e02389831 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -22,6 +22,7 @@ @@ -488,13 +488,13 @@ index 66e5dfc711c0..2330903a8b45 100644 - if (value == prev) - goto cpufreq_policy_put; -+ amd_pstate_update_perf(cpudata, min_perf, des_perf, max_perf, 0, fast_switch); - +- - WRITE_ONCE(cpudata->cppc_req_cached, value); - - amd_pstate_update_perf(cpudata, min_perf, des_perf, - max_perf, fast_switch); -- ++ amd_pstate_update_perf(cpudata, min_perf, des_perf, max_perf, 0, fast_switch); + -cpufreq_policy_put: cpufreq_cpu_put(policy); } @@ -523,6 +523,15 @@ index 66e5dfc711c0..2330903a8b45 100644 WRITE_ONCE(cpudata->max_limit_perf, max_limit_perf); WRITE_ONCE(cpudata->min_limit_perf, min_limit_perf); +@@ -682,7 +699,7 @@ static void amd_pstate_adjust_perf(unsigned int cpu, + if (min_perf < lowest_nonlinear_perf) + min_perf = lowest_nonlinear_perf; + +- max_perf = cap_perf; ++ max_perf = cpudata->max_limit_perf; + if (max_perf < min_perf) + max_perf = min_perf; + @@ -704,8 +721,8 @@ static int amd_pstate_cpu_boost_update(struct cpufreq_policy *policy, bool on) if (on) @@ -534,7 +543,7 @@ index 66e5dfc711c0..2330903a8b45 100644 policy->max = policy->cpuinfo.max_freq; -@@ -727,12 +744,11 @@ static int amd_pstate_set_boost(struct cpufreq_policy *policy, int state) +@@ -727,12 +744,10 @@ static int amd_pstate_set_boost(struct cpufreq_policy *policy, int state) pr_err("Boost mode is not supported by this processor or SBIOS\n"); return -EOPNOTSUPP; } @@ -543,13 +552,13 @@ index 66e5dfc711c0..2330903a8b45 100644 + ret = amd_pstate_cpu_boost_update(policy, state); - WRITE_ONCE(cpudata->boost_state, !ret ? state : false); - policy->boost_enabled = !ret ? state : false; +- policy->boost_enabled = !ret ? state : false; refresh_frequency_limits(policy); - mutex_unlock(&amd_pstate_driver_lock); return ret; } -@@ -752,9 +768,6 @@ static int amd_pstate_init_boost_support(struct amd_cpudata *cpudata) +@@ -752,9 +767,6 @@ static int amd_pstate_init_boost_support(struct amd_cpudata *cpudata) goto exit_err; } @@ -559,26 +568,49 @@ index 66e5dfc711c0..2330903a8b45 100644 ret = rdmsrl_on_cpu(cpudata->cpu, MSR_K7_HWCR, &boost_val); if (ret) { pr_err_once("failed to read initial CPU boost state!\n"); -@@ -802,7 +815,7 @@ static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata) - * sched_set_itmt_support(true) has been called and it is valid to - * update them at any time after it has been called. - */ -- sched_set_itmt_core_prio((int)READ_ONCE(cpudata->highest_perf), cpudata->cpu); -+ sched_set_itmt_core_prio((int)READ_ONCE(cpudata->prefcore_ranking), cpudata->cpu); +@@ -809,24 +821,28 @@ static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata) - schedule_work(&sched_prefcore_work); - } -@@ -823,7 +836,8 @@ static void amd_pstate_update_limits(unsigned int cpu) - if (!amd_pstate_prefcore) + static void amd_pstate_update_limits(unsigned int cpu) + { +- struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); ++ struct cpufreq_policy *policy = NULL; + struct amd_cpudata *cpudata; + u32 prev_high = 0, cur_high = 0; + int ret; + bool highest_perf_changed = false; + ++ if (!amd_pstate_prefcore) ++ return; ++ ++ policy = cpufreq_cpu_get(cpu); + if (!policy) return; -- mutex_lock(&amd_pstate_driver_lock); + cpudata = policy->driver_data; + +- if (!amd_pstate_prefcore) +- return; + guard(mutex)(&amd_pstate_driver_lock); -+ + +- mutex_lock(&amd_pstate_driver_lock); ret = amd_get_highest_perf(cpu, &cur_high); - if (ret) - goto free_cpufreq_put; -@@ -843,7 +857,6 @@ static void amd_pstate_update_limits(unsigned int cpu) +- if (ret) +- goto free_cpufreq_put; ++ if (ret) { ++ cpufreq_cpu_put(policy); ++ return; ++ } + + prev_high = READ_ONCE(cpudata->prefcore_ranking); + highest_perf_changed = (prev_high != cur_high); +@@ -836,14 +852,11 @@ static void amd_pstate_update_limits(unsigned int cpu) + if (cur_high < CPPC_MAX_PERF) + sched_set_itmt_core_prio((int)cur_high, cpu); + } +- +-free_cpufreq_put: + cpufreq_cpu_put(policy); + if (!highest_perf_changed) cpufreq_update_policy(cpu); @@ -658,10 +690,10 @@ index 66e5dfc711c0..2330903a8b45 100644 - ret = amd_pstate_set_energy_pref_index(cpudata, ret); - mutex_unlock(&amd_pstate_limits_lock); + guard(mutex)(&amd_pstate_limits_lock); -+ -+ ret = amd_pstate_set_energy_pref_index(policy, ret); - return ret ?: count; ++ ret = amd_pstate_set_energy_pref_index(policy, ret); ++ + return ret ? ret : count; } @@ -1003,9 +1035,9 @@ index cd573bc6b6db..9747e3be6cee 100644 -- 2.48.0.rc1 -From 24387ecea1f69a77a6236c4584dc06ea79f4ef1b Mon Sep 17 00:00:00 2001 +From 767e13bd27f2b785fa83186a99106e5d349896cf Mon Sep 17 00:00:00 2001 From: Peter Jung -Date: Sun, 2 Feb 2025 13:53:18 +0100 +Date: Sat, 8 Feb 2025 10:36:03 +0100 Subject: [PATCH 02/12] amd-tlb-broadcast Signed-off-by: Peter Jung @@ -1014,28 +1046,25 @@ Signed-off-by: Peter Jung arch/x86/Kconfig.cpu | 5 + arch/x86/hyperv/mmu.c | 1 - arch/x86/include/asm/cpufeatures.h | 1 + - arch/x86/include/asm/invlpgb.h | 107 +++++ - arch/x86/include/asm/mmu.h | 8 + - arch/x86/include/asm/mmu_context.h | 15 + + arch/x86/include/asm/invlpgb.h | 106 +++++ + arch/x86/include/asm/mmu.h | 6 + + arch/x86/include/asm/mmu_context.h | 14 + arch/x86/include/asm/msr-index.h | 2 + arch/x86/include/asm/paravirt.h | 5 - arch/x86/include/asm/paravirt_types.h | 2 - - arch/x86/include/asm/tlbbatch.h | 1 + - arch/x86/include/asm/tlbflush.h | 94 ++++- - arch/x86/kernel/alternative.c | 10 +- + arch/x86/include/asm/tlbflush.h | 98 ++++- arch/x86/kernel/cpu/amd.c | 12 + arch/x86/kernel/kvm.c | 1 - arch/x86/kernel/paravirt.c | 6 - arch/x86/mm/pgtable.c | 16 +- - arch/x86/mm/tlb.c | 540 ++++++++++++++++++++++--- + arch/x86/mm/tlb.c | 518 +++++++++++++++++++++++-- arch/x86/xen/mmu_pv.c | 1 - - include/linux/mm_types.h | 1 + mm/memory.c | 1 - mm/mmap.c | 2 - mm/swap_state.c | 1 - mm/vma.c | 2 - tools/arch/x86/include/asm/msr-index.h | 2 + - 25 files changed, 741 insertions(+), 97 deletions(-) + 22 files changed, 723 insertions(+), 81 deletions(-) create mode 100644 arch/x86/include/asm/invlpgb.h diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig @@ -1098,10 +1127,10 @@ index 645aa360628d..989e4c9cad2e 100644 #define X86_FEATURE_AMD_IBPB (13*32+12) /* Indirect Branch Prediction Barrier */ diff --git a/arch/x86/include/asm/invlpgb.h b/arch/x86/include/asm/invlpgb.h new file mode 100644 -index 000000000000..5fba41671a6d +index 000000000000..9df559974f78 --- /dev/null +++ b/arch/x86/include/asm/invlpgb.h -@@ -0,0 +1,107 @@ +@@ -0,0 +1,106 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_INVLPGB +#define _ASM_X86_INVLPGB @@ -1135,9 +1164,8 @@ index 000000000000..5fba41671a6d +} + +/* Wait for INVLPGB originated by this CPU to complete. */ -+static inline void tlbsync(void) ++static inline void __tlbsync(void) +{ -+ cant_migrate(); + /* TLBSYNC: supported in binutils >= 0.36. */ + asm volatile(".byte 0x0f, 0x01, 0xff" ::: "memory"); +} @@ -1165,16 +1193,16 @@ index 000000000000..5fba41671a6d + unsigned long addr) +{ + __invlpgb(0, pcid, addr, 0, 0, INVLPGB_PCID | INVLPGB_VA); -+ tlbsync(); ++ __tlbsync(); +} + -+static inline void invlpgb_flush_user_nr_nosync(unsigned long pcid, -+ unsigned long addr, -+ u16 nr, -+ bool pmd_stride, -+ bool freed_tables) ++static inline void __invlpgb_flush_user_nr_nosync(unsigned long pcid, ++ unsigned long addr, ++ u16 nr, ++ bool pmd_stride, ++ bool freed_tables) +{ -+ unsigned long flags = INVLPGB_PCID | INVLPGB_VA; ++ u8 flags = INVLPGB_PCID | INVLPGB_VA; + + if (!freed_tables) + flags |= INVLPGB_FINAL_ONLY; @@ -1183,7 +1211,7 @@ index 000000000000..5fba41671a6d +} + +/* Flush all mappings for a given PCID, not including globals. */ -+static inline void invlpgb_flush_single_pcid_nosync(unsigned long pcid) ++static inline void __invlpgb_flush_single_pcid_nosync(unsigned long pcid) +{ + __invlpgb(0, pcid, 0, 0, 0, INVLPGB_PCID); +} @@ -1192,11 +1220,11 @@ index 000000000000..5fba41671a6d +static inline void invlpgb_flush_all(void) +{ + __invlpgb(0, 0, 0, 0, 0, INVLPGB_INCLUDE_GLOBAL); -+ tlbsync(); ++ __tlbsync(); +} + +/* Flush addr, including globals, for all PCIDs. */ -+static inline void invlpgb_flush_addr_nosync(unsigned long addr, u16 nr) ++static inline void __invlpgb_flush_addr_nosync(unsigned long addr, u16 nr) +{ + __invlpgb(0, 0, addr, nr - 1, 0, INVLPGB_INCLUDE_GLOBAL); +} @@ -1205,24 +1233,15 @@ index 000000000000..5fba41671a6d +static inline void invlpgb_flush_all_nonglobals(void) +{ + __invlpgb(0, 0, 0, 0, 0, 0); -+ tlbsync(); ++ __tlbsync(); +} + +#endif /* _ASM_X86_INVLPGB */ diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h -index ce4677b8b735..d71cd599fec4 100644 +index ce4677b8b735..51f25d38de86 100644 --- a/arch/x86/include/asm/mmu.h +++ b/arch/x86/include/asm/mmu.h -@@ -37,6 +37,8 @@ typedef struct { - */ - atomic64_t tlb_gen; - -+ unsigned long next_trim_cpumask; -+ - #ifdef CONFIG_MODIFY_LDT_SYSCALL - struct rw_semaphore ldt_usr_sem; - struct ldt_struct *ldt; -@@ -67,6 +69,12 @@ typedef struct { +@@ -67,6 +67,12 @@ typedef struct { u16 pkey_allocation_map; s16 execute_only_pkey; #endif @@ -1236,7 +1255,7 @@ index ce4677b8b735..d71cd599fec4 100644 #define INIT_MM_CONTEXT(mm) \ diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h -index 2886cb668d7f..d670699d32c2 100644 +index 2886cb668d7f..65f50464b5c3 100644 --- a/arch/x86/include/asm/mmu_context.h +++ b/arch/x86/include/asm/mmu_context.h @@ -139,6 +139,8 @@ static inline void mm_reset_untag_mask(struct mm_struct *mm) @@ -1248,15 +1267,7 @@ index 2886cb668d7f..d670699d32c2 100644 /* * Init a new mm. Used on mm copies, like at fork() * and on mm's that are brand-new, like at execve(). -@@ -151,6 +153,7 @@ static inline int init_new_context(struct task_struct *tsk, - - mm->context.ctx_id = atomic64_inc_return(&last_mm_ctx_id); - atomic64_set(&mm->context.tlb_gen, 0); -+ mm->context.next_trim_cpumask = jiffies + HZ; - - #ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS - if (cpu_feature_enabled(X86_FEATURE_OSPKE)) { -@@ -160,6 +163,14 @@ static inline int init_new_context(struct task_struct *tsk, +@@ -160,6 +162,14 @@ static inline int init_new_context(struct task_struct *tsk, mm->context.execute_only_pkey = -1; } #endif @@ -1271,7 +1282,7 @@ index 2886cb668d7f..d670699d32c2 100644 mm_reset_untag_mask(mm); init_new_context_ldt(mm); return 0; -@@ -169,6 +180,10 @@ static inline int init_new_context(struct task_struct *tsk, +@@ -169,6 +179,10 @@ static inline int init_new_context(struct task_struct *tsk, static inline void destroy_context(struct mm_struct *mm) { destroy_context_ldt(mm); @@ -1331,20 +1342,8 @@ index 8d4fbe1be489..13405959e4db 100644 /* Hook for intercepting the destruction of an mm_struct. */ void (*exit_mmap)(struct mm_struct *mm); void (*notify_page_enc_status_changed)(unsigned long pfn, int npages, bool enc); -diff --git a/arch/x86/include/asm/tlbbatch.h b/arch/x86/include/asm/tlbbatch.h -index 1ad56eb3e8a8..f9a17edf63ad 100644 ---- a/arch/x86/include/asm/tlbbatch.h -+++ b/arch/x86/include/asm/tlbbatch.h -@@ -10,6 +10,7 @@ struct arch_tlbflush_unmap_batch { - * the PFNs being flushed.. - */ - struct cpumask cpumask; -+ bool used_invlpgb; - }; - - #endif /* _ARCH_X86_TLBBATCH_H */ diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h -index 69e79fff41b8..f8aaa4bcb4d8 100644 +index 69e79fff41b8..30697dabf9e1 100644 --- a/arch/x86/include/asm/tlbflush.h +++ b/arch/x86/include/asm/tlbflush.h @@ -6,10 +6,12 @@ @@ -1360,7 +1359,15 @@ index 69e79fff41b8..f8aaa4bcb4d8 100644 #include #include #include -@@ -183,6 +185,13 @@ static inline void cr4_init_shadow(void) +@@ -104,6 +106,7 @@ struct tlb_state { + * need to be invalidated. + */ + bool invalidate_other; ++ bool need_tlbsync; + + #ifdef CONFIG_ADDRESS_MASKING + /* +@@ -183,6 +186,13 @@ static inline void cr4_init_shadow(void) extern unsigned long mmu_cr4_features; extern u32 *trampoline_cr4_features; @@ -1374,15 +1381,7 @@ index 69e79fff41b8..f8aaa4bcb4d8 100644 extern void initialize_tlbstate_and_flush(void); /* -@@ -222,6 +231,7 @@ struct flush_tlb_info { - unsigned int initiating_cpu; - u8 stride_shift; - u8 freed_tables; -+ u8 trim_cpumask; - }; - - void flush_tlb_local(void); -@@ -230,6 +240,78 @@ void flush_tlb_one_kernel(unsigned long addr); +@@ -230,6 +240,82 @@ void flush_tlb_one_kernel(unsigned long addr); void flush_tlb_multi(const struct cpumask *cpumask, const struct flush_tlb_info *info); @@ -1400,12 +1399,12 @@ index 69e79fff41b8..f8aaa4bcb4d8 100644 + return !is_dyn_asid(asid); +} + -+static inline bool in_asid_transition(const struct flush_tlb_info *info) ++static inline bool in_asid_transition(struct mm_struct *mm) +{ + if (!cpu_feature_enabled(X86_FEATURE_INVLPGB)) + return false; + -+ return info->mm && READ_ONCE(info->mm->context.asid_transition); ++ return mm && READ_ONCE(mm->context.asid_transition); +} + +static inline u16 mm_global_asid(struct mm_struct *mm) @@ -1433,7 +1432,7 @@ index 69e79fff41b8..f8aaa4bcb4d8 100644 + return false; +} + -+static inline bool in_asid_transition(const struct flush_tlb_info *info) ++static inline bool in_asid_transition(struct mm_struct *mm) +{ + return false; +} @@ -1456,12 +1455,16 @@ index 69e79fff41b8..f8aaa4bcb4d8 100644 +static inline void consider_global_asid(struct mm_struct *mm) +{ +} ++ ++static inline void tlbsync(void) ++{ ++} +#endif + #ifdef CONFIG_PARAVIRT #include #endif -@@ -277,21 +359,15 @@ static inline u64 inc_mm_tlb_gen(struct mm_struct *mm) +@@ -277,21 +363,15 @@ static inline u64 inc_mm_tlb_gen(struct mm_struct *mm) return atomic64_inc_return(&mm->context.tlb_gen); } @@ -1486,39 +1489,6 @@ index 69e79fff41b8..f8aaa4bcb4d8 100644 static inline bool pte_flags_need_flush(unsigned long oldflags, unsigned long newflags, -diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c -index 243843e44e89..c71b575bf229 100644 ---- a/arch/x86/kernel/alternative.c -+++ b/arch/x86/kernel/alternative.c -@@ -1854,11 +1854,18 @@ static inline temp_mm_state_t use_temporary_mm(struct mm_struct *mm) - return temp_state; - } - -+__ro_after_init struct mm_struct *poking_mm; -+__ro_after_init unsigned long poking_addr; -+ - static inline void unuse_temporary_mm(temp_mm_state_t prev_state) - { - lockdep_assert_irqs_disabled(); -+ - switch_mm_irqs_off(NULL, prev_state.mm, current); - -+ /* Clear the cpumask, to indicate no TLB flushing is needed anywhere */ -+ cpumask_clear_cpu(raw_smp_processor_id(), mm_cpumask(poking_mm)); -+ - /* - * Restore the breakpoints if they were disabled before the temporary mm - * was loaded. -@@ -1867,9 +1874,6 @@ static inline void unuse_temporary_mm(temp_mm_state_t prev_state) - hw_breakpoint_restore(); - } - --__ro_after_init struct mm_struct *poking_mm; --__ro_after_init unsigned long poking_addr; -- - static void text_poke_memcpy(void *dst, const void *src, size_t len) - { - memcpy(dst, src, len); diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index 79d2e17f6582..21076252a491 100644 --- a/arch/x86/kernel/cpu/amd.c @@ -1647,7 +1617,7 @@ index 5745a354a241..3dc4af1f7868 100644 #endif /* CONFIG_PGTABLE_LEVELS > 4 */ #endif /* CONFIG_PGTABLE_LEVELS > 3 */ diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c -index a2becb85bea7..682da8d0d1c9 100644 +index a2becb85bea7..e7f32b00d8fb 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -74,13 +74,15 @@ @@ -1690,7 +1660,7 @@ index a2becb85bea7..682da8d0d1c9 100644 if (this_cpu_read(cpu_tlbstate.invalidate_other)) clear_asid_other(); -@@ -251,6 +267,272 @@ static void choose_new_asid(struct mm_struct *next, u64 next_tlb_gen, +@@ -251,6 +267,304 @@ static void choose_new_asid(struct mm_struct *next, u64 next_tlb_gen, *need_flush = true; } @@ -1915,6 +1885,38 @@ index a2becb85bea7..682da8d0d1c9 100644 + WRITE_ONCE(mm->context.asid_transition, false); +} + ++static inline void tlbsync(void) ++{ ++ if (!this_cpu_read(cpu_tlbstate.need_tlbsync)) ++ return; ++ __tlbsync(); ++ this_cpu_write(cpu_tlbstate.need_tlbsync, false); ++} ++ ++static inline void invlpgb_flush_user_nr_nosync(unsigned long pcid, ++ unsigned long addr, ++ u16 nr, bool pmd_stride, ++ bool freed_tables) ++{ ++ __invlpgb_flush_user_nr_nosync(pcid, addr, nr, pmd_stride, freed_tables); ++ if (!this_cpu_read(cpu_tlbstate.need_tlbsync)) ++ this_cpu_write(cpu_tlbstate.need_tlbsync, true); ++} ++ ++static inline void invlpgb_flush_single_pcid_nosync(unsigned long pcid) ++{ ++ __invlpgb_flush_single_pcid_nosync(pcid); ++ if (!this_cpu_read(cpu_tlbstate.need_tlbsync)) ++ this_cpu_write(cpu_tlbstate.need_tlbsync, true); ++} ++ ++static inline void invlpgb_flush_addr_nosync(unsigned long addr, u16 nr) ++{ ++ __invlpgb_flush_addr_nosync(addr, nr); ++ if (!this_cpu_read(cpu_tlbstate.need_tlbsync)) ++ this_cpu_write(cpu_tlbstate.need_tlbsync, true); ++} ++ +static void broadcast_tlb_flush(struct flush_tlb_info *info) +{ + bool pmd = info->stride_shift == PMD_SHIFT; @@ -1963,7 +1965,16 @@ index a2becb85bea7..682da8d0d1c9 100644 /* * Given an ASID, flush the corresponding user ASID. We can delay this * until the next time we switch to it. -@@ -556,8 +838,9 @@ void switch_mm_irqs_off(struct mm_struct *unused, struct mm_struct *next, +@@ -512,6 +826,8 @@ void switch_mm_irqs_off(struct mm_struct *unused, struct mm_struct *next, + if (IS_ENABLED(CONFIG_PROVE_LOCKING)) + WARN_ON_ONCE(!irqs_disabled()); + ++ tlbsync(); ++ + /* + * Verify that CR3 is what we think it is. This will catch + * hypothetical buggy code that directly switches to swapper_pg_dir +@@ -556,8 +872,9 @@ void switch_mm_irqs_off(struct mm_struct *unused, struct mm_struct *next, */ if (prev == next) { /* Not actually switching mm's */ @@ -1975,7 +1986,7 @@ index a2becb85bea7..682da8d0d1c9 100644 /* * If this races with another thread that enables lam, 'new_lam' -@@ -573,6 +856,23 @@ void switch_mm_irqs_off(struct mm_struct *unused, struct mm_struct *next, +@@ -573,6 +890,23 @@ void switch_mm_irqs_off(struct mm_struct *unused, struct mm_struct *next, !cpumask_test_cpu(cpu, mm_cpumask(next)))) cpumask_set_cpu(cpu, mm_cpumask(next)); @@ -1999,36 +2010,21 @@ index a2becb85bea7..682da8d0d1c9 100644 /* * If the CPU is not in lazy TLB mode, we are just switching * from one thread in a process to another thread in the same -@@ -607,30 +907,32 @@ void switch_mm_irqs_off(struct mm_struct *unused, struct mm_struct *next, +@@ -606,6 +940,13 @@ void switch_mm_irqs_off(struct mm_struct *unused, struct mm_struct *next, + */ cond_mitigation(tsk); - /* -- * Stop remote flushes for the previous mm. -- * Skip kernel threads; we never send init_mm TLB flushing IPIs, -- * but the bitmap manipulation can cause cache line contention. ++ /* + * Let nmi_uaccess_okay() and finish_asid_transition() + * know that we're changing CR3. - */ -- if (prev != &init_mm) { -- VM_WARN_ON_ONCE(!cpumask_test_cpu(cpu, -- mm_cpumask(prev))); -- cpumask_clear_cpu(cpu, mm_cpumask(prev)); -- } ++ */ + this_cpu_write(cpu_tlbstate.loaded_mm, LOADED_MM_SWITCHING); + barrier(); + -+ /* -+ * Leave this CPU in prev's mm_cpumask. Atomic writes to -+ * mm_cpumask can be expensive under contention. The CPU -+ * will be removed lazily at TLB flush time. -+ */ -+ VM_WARN_ON_ONCE(prev != &init_mm && !cpumask_test_cpu(cpu, -+ mm_cpumask(prev))); - - /* Start receiving IPIs and then read tlb_gen (and LAM below) */ -- if (next != &init_mm) -+ if (next != &init_mm && !cpumask_test_cpu(cpu, mm_cpumask(next))) - cpumask_set_cpu(cpu, mm_cpumask(next)); + /* + * Stop remote flushes for the previous mm. + * Skip kernel threads; we never send init_mm TLB flushing IPIs, +@@ -623,14 +964,12 @@ void switch_mm_irqs_off(struct mm_struct *unused, struct mm_struct *next, next_tlb_gen = atomic64_read(&next->context.tlb_gen); choose_new_asid(next, next_tlb_gen, &new_asid, &need_flush); @@ -2045,7 +2041,16 @@ index a2becb85bea7..682da8d0d1c9 100644 this_cpu_write(cpu_tlbstate.ctxs[new_asid].ctx_id, next->context.ctx_id); this_cpu_write(cpu_tlbstate.ctxs[new_asid].tlb_gen, next_tlb_gen); load_new_mm_cr3(next->pgd, new_asid, new_lam, true); -@@ -749,7 +1051,7 @@ static void flush_tlb_func(void *info) +@@ -671,6 +1010,8 @@ void switch_mm_irqs_off(struct mm_struct *unused, struct mm_struct *next, + */ + void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk) + { ++ tlbsync(); ++ + if (this_cpu_read(cpu_tlbstate.loaded_mm) == &init_mm) + return; + +@@ -749,7 +1090,7 @@ static void flush_tlb_func(void *info) const struct flush_tlb_info *f = info; struct mm_struct *loaded_mm = this_cpu_read(cpu_tlbstate.loaded_mm); u32 loaded_mm_asid = this_cpu_read(cpu_tlbstate.loaded_mm_asid); @@ -2054,22 +2059,7 @@ index a2becb85bea7..682da8d0d1c9 100644 bool local = smp_processor_id() == f->initiating_cpu; unsigned long nr_invalidate = 0; u64 mm_tlb_gen; -@@ -760,15 +1062,28 @@ static void flush_tlb_func(void *info) - if (!local) { - inc_irq_stat(irq_tlb_count); - count_vm_tlb_event(NR_TLB_REMOTE_FLUSH_RECEIVED); -+ } - -- /* Can only happen on remote CPUs */ -- if (f->mm && f->mm != loaded_mm) -- return; -+ /* The CPU was left in the mm_cpumask of the target mm. Clear it. */ -+ if (f->mm && f->mm != loaded_mm) { -+ cpumask_clear_cpu(raw_smp_processor_id(), mm_cpumask(f->mm)); -+ trace_tlb_flush(TLB_REMOTE_WRONG_CPU, 0); -+ return; - } - +@@ -769,6 +1110,16 @@ static void flush_tlb_func(void *info) if (unlikely(loaded_mm == &init_mm)) return; @@ -2086,7 +2076,7 @@ index a2becb85bea7..682da8d0d1c9 100644 VM_WARN_ON(this_cpu_read(cpu_tlbstate.ctxs[loaded_mm_asid].ctx_id) != loaded_mm->context.ctx_id); -@@ -786,6 +1101,8 @@ static void flush_tlb_func(void *info) +@@ -786,6 +1137,8 @@ static void flush_tlb_func(void *info) return; } @@ -2095,63 +2085,37 @@ index a2becb85bea7..682da8d0d1c9 100644 if (unlikely(f->new_tlb_gen != TLB_GENERATION_INVALID && f->new_tlb_gen <= local_tlb_gen)) { /* -@@ -893,9 +1210,36 @@ static void flush_tlb_func(void *info) - nr_invalidate); - } - --static bool tlb_is_not_lazy(int cpu, void *data) -+static bool should_flush_tlb(int cpu, void *data) - { -- return !per_cpu(cpu_tlbstate_shared.is_lazy, cpu); -+ struct flush_tlb_info *info = data; -+ -+ /* Lazy TLB will get flushed at the next context switch. */ -+ if (per_cpu(cpu_tlbstate_shared.is_lazy, cpu)) -+ return false; -+ -+ /* No mm means kernel memory flush. */ -+ if (!info->mm) -+ return true; -+ -+ /* The target mm is loaded, and the CPU is not lazy. */ -+ if (per_cpu(cpu_tlbstate.loaded_mm, cpu) == info->mm) -+ return true; -+ -+ /* In cpumask, but not the loaded mm? Periodically remove by flushing. */ -+ if (info->trim_cpumask) -+ return true; -+ -+ return false; -+} -+ -+static bool should_trim_cpumask(struct mm_struct *mm) -+{ -+ if (time_after(jiffies, READ_ONCE(mm->context.next_trim_cpumask))) { -+ WRITE_ONCE(mm->context.next_trim_cpumask, jiffies + HZ); -+ return true; -+ } -+ return false; - } - - DEFINE_PER_CPU_SHARED_ALIGNED(struct tlb_state_shared, cpu_tlbstate_shared); -@@ -926,10 +1270,10 @@ STATIC_NOPV void native_flush_tlb_multi(const struct cpumask *cpumask, +@@ -926,7 +1279,7 @@ STATIC_NOPV void native_flush_tlb_multi(const struct cpumask *cpumask, * up on the new contents of what used to be page tables, while * doing a speculative memory access. */ - if (info->freed_tables) -+ if (info->freed_tables || in_asid_transition(info)) ++ if (info->freed_tables || in_asid_transition(info->mm)) on_each_cpu_mask(cpumask, flush_tlb_func, (void *)info, true); else -- on_each_cpu_cond_mask(tlb_is_not_lazy, flush_tlb_func, -+ on_each_cpu_cond_mask(should_flush_tlb, flush_tlb_func, - (void *)info, 1, cpumask); - } + on_each_cpu_cond_mask(tlb_is_not_lazy, flush_tlb_func, +@@ -973,14 +1326,32 @@ static struct flush_tlb_info *get_flush_tlb_info(struct mm_struct *mm, + BUG_ON(this_cpu_inc_return(flush_tlb_info_idx) != 1); + #endif -@@ -980,6 +1324,16 @@ static struct flush_tlb_info *get_flush_tlb_info(struct mm_struct *mm, +- info->start = start; +- info->end = end; ++ /* ++ * Round the start and end addresses to the page size specified ++ * by the stride shift. This ensures partial pages at the end of ++ * a range get fully invalidated. ++ */ ++ info->start = round_down(start, 1 << stride_shift); ++ info->end = round_up(end, 1 << stride_shift); + info->mm = mm; + info->stride_shift = stride_shift; info->freed_tables = freed_tables; info->new_tlb_gen = new_tlb_gen; info->initiating_cpu = smp_processor_id(); -+ info->trim_cpumask = 0; + ++ WARN_ONCE(start != info->start || end != info->end, ++ "TLB flush not stride %x aligned. Start %lx, end %lx\n", ++ 1 << stride_shift, start, end); + + /* + * If the number of flushes is so large that a full flush @@ -2161,10 +2125,11 @@ index a2becb85bea7..682da8d0d1c9 100644 + info->start = 0; + info->end = TLB_FLUSH_ALL; + } - ++ return info; } -@@ -998,17 +1352,8 @@ void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start, + +@@ -998,17 +1369,8 @@ void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start, bool freed_tables) { struct flush_tlb_info *info; @@ -2183,7 +2148,7 @@ index a2becb85bea7..682da8d0d1c9 100644 /* This is also a barrier that synchronizes with switch_mm(). */ new_tlb_gen = inc_mm_tlb_gen(mm); -@@ -1021,8 +1366,12 @@ void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start, +@@ -1021,8 +1383,11 @@ void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start, * a local TLB flush is needed. Optimize this use-case by calling * flush_tlb_func_local() directly in this case. */ @@ -2191,13 +2156,12 @@ index a2becb85bea7..682da8d0d1c9 100644 + if (mm_global_asid(mm)) { + broadcast_tlb_flush(info); + } else if (cpumask_any_but(mm_cpumask(mm), cpu) < nr_cpu_ids) { -+ info->trim_cpumask = should_trim_cpumask(mm); flush_tlb_multi(mm_cpumask(mm), info); + consider_global_asid(mm); } else if (mm == this_cpu_read(cpu_tlbstate.loaded_mm)) { lockdep_assert_irqs_enabled(); local_irq_disable(); -@@ -1036,6 +1385,19 @@ void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start, +@@ -1036,6 +1401,19 @@ void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start, } @@ -2217,7 +2181,7 @@ index a2becb85bea7..682da8d0d1c9 100644 static void do_flush_tlb_all(void *info) { count_vm_tlb_event(NR_TLB_REMOTE_FLUSH_RECEIVED); -@@ -1044,10 +1406,36 @@ static void do_flush_tlb_all(void *info) +@@ -1044,10 +1422,36 @@ static void do_flush_tlb_all(void *info) void flush_tlb_all(void) { @@ -2254,7 +2218,7 @@ index a2becb85bea7..682da8d0d1c9 100644 static void do_kernel_range_flush(void *info) { struct flush_tlb_info *f = info; -@@ -1060,22 +1448,21 @@ static void do_kernel_range_flush(void *info) +@@ -1060,22 +1464,21 @@ static void do_kernel_range_flush(void *info) void flush_tlb_kernel_range(unsigned long start, unsigned long end) { @@ -2265,12 +2229,12 @@ index a2becb85bea7..682da8d0d1c9 100644 - } else { - struct flush_tlb_info *info; + struct flush_tlb_info *info; ++ ++ guard(preempt)(); - preempt_disable(); - info = get_flush_tlb_info(NULL, start, end, 0, false, - TLB_GENERATION_INVALID); -+ guard(preempt)(); -+ + info = get_flush_tlb_info(NULL, start, end, PAGE_SHIFT, false, + TLB_GENERATION_INVALID); @@ -2288,7 +2252,7 @@ index a2becb85bea7..682da8d0d1c9 100644 } /* -@@ -1247,7 +1634,7 @@ void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch) +@@ -1247,7 +1650,7 @@ void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch) int cpu = get_cpu(); @@ -2297,7 +2261,7 @@ index a2becb85bea7..682da8d0d1c9 100644 TLB_GENERATION_INVALID); /* * flush_tlb_multi() is not optimized for the common case in which only -@@ -1263,12 +1650,65 @@ void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch) +@@ -1263,12 +1666,53 @@ void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch) local_irq_enable(); } @@ -2306,11 +2270,8 @@ index a2becb85bea7..682da8d0d1c9 100644 + * The cpumask above contains only CPUs that were running tasks + * not using broadcast TLB flushing. + */ -+ if (cpu_feature_enabled(X86_FEATURE_INVLPGB) && batch->used_invlpgb) { ++ if (cpu_feature_enabled(X86_FEATURE_INVLPGB)) + tlbsync(); -+ migrate_enable(); -+ batch->used_invlpgb = false; -+ } + cpumask_clear(&batch->cpumask); @@ -2325,15 +2286,6 @@ index a2becb85bea7..682da8d0d1c9 100644 + u16 asid = mm_global_asid(mm); + + if (asid) { -+ /* -+ * Queue up an asynchronous invalidation. The corresponding -+ * TLBSYNC is done in arch_tlbbatch_flush(), and must be done -+ * on the same CPU. -+ */ -+ if (!batch->used_invlpgb) { -+ batch->used_invlpgb = true; -+ migrate_disable(); -+ } + invlpgb_flush_user_nr_nosync(kern_pcid(asid), uaddr, 1, false, false); + /* Do any CPUs supporting INVLPGB need PTI? */ + if (static_cpu_has(X86_FEATURE_PTI)) @@ -2348,7 +2300,7 @@ index a2becb85bea7..682da8d0d1c9 100644 + * TLB invalidation, and send IPIs. The IPIs will help + * stragglers transition to the broadcast ASID. + */ -+ if (READ_ONCE(mm->context.asid_transition)) ++ if (in_asid_transition(mm)) + asid = 0; + } + @@ -2375,18 +2327,6 @@ index 55a4996d0c04..041e17282af0 100644 .pgd_alloc = xen_pgd_alloc, .pgd_free = xen_pgd_free, -diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h -index 332cee285662..29e6d8e6d0e5 100644 ---- a/include/linux/mm_types.h -+++ b/include/linux/mm_types.h -@@ -1401,6 +1401,7 @@ enum tlb_flush_reason { - TLB_LOCAL_SHOOTDOWN, - TLB_LOCAL_MM_SHOOTDOWN, - TLB_REMOTE_SEND_IPI, -+ TLB_REMOTE_WRONG_CPU, - NR_TLB_FLUSH_REASONS, - }; - diff --git a/mm/memory.c b/mm/memory.c index 398c031be9ba..3d98aaf9b939 100644 --- a/mm/memory.c @@ -2474,9 +2414,9 @@ index 3ae84c3b8e6d..dc1c1057f26e 100644 -- 2.48.0.rc1 -From 3cfc3cd67b727b62206d7c97efd5ebf120e47555 Mon Sep 17 00:00:00 2001 +From a801f55195137633b337b08ad9c5b18dc8eeb65b Mon Sep 17 00:00:00 2001 From: Peter Jung -Date: Sun, 2 Feb 2025 13:53:27 +0100 +Date: Sat, 8 Feb 2025 10:36:17 +0100 Subject: [PATCH 03/12] bbr3 Signed-off-by: Peter Jung @@ -5655,10 +5595,10 @@ index 7121d8573928..696afe8cfda8 100644 const struct tcp_congestion_ops *ca; diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c -index 0e5b9a654254..f7da9d719b25 100644 +index bc95d2a5924f..d4c45ca6fe06 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c -@@ -336,10 +336,9 @@ static void tcp_ecn_send_syn(struct sock *sk, struct sk_buff *skb) +@@ -339,10 +339,9 @@ static void tcp_ecn_send_syn(struct sock *sk, struct sk_buff *skb) bool bpf_needs_ecn = tcp_bpf_ca_needs_ecn(sk); bool use_ecn = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_ecn) == 1 || tcp_ca_needs_ecn(sk) || bpf_needs_ecn; @@ -5670,7 +5610,7 @@ index 0e5b9a654254..f7da9d719b25 100644 if (dst && dst_feature(dst, RTAX_FEATURE_ECN)) use_ecn = true; } -@@ -351,6 +350,9 @@ static void tcp_ecn_send_syn(struct sock *sk, struct sk_buff *skb) +@@ -354,6 +353,9 @@ static void tcp_ecn_send_syn(struct sock *sk, struct sk_buff *skb) tp->ecn_flags = TCP_ECN_OK; if (tcp_ca_needs_ecn(sk) || bpf_needs_ecn) INET_ECN_xmit(sk); @@ -5680,7 +5620,7 @@ index 0e5b9a654254..f7da9d719b25 100644 } } -@@ -388,7 +390,8 @@ static void tcp_ecn_send(struct sock *sk, struct sk_buff *skb, +@@ -391,7 +393,8 @@ static void tcp_ecn_send(struct sock *sk, struct sk_buff *skb, th->cwr = 1; skb_shinfo(skb)->gso_type |= SKB_GSO_TCP_ECN; } @@ -5690,7 +5630,7 @@ index 0e5b9a654254..f7da9d719b25 100644 /* ACK or retransmitted segment: clear ECT|CE */ INET_ECN_dontxmit(sk); } -@@ -1603,7 +1606,7 @@ int tcp_fragment(struct sock *sk, enum tcp_queue tcp_queue, +@@ -1606,7 +1609,7 @@ int tcp_fragment(struct sock *sk, enum tcp_queue tcp_queue, { struct tcp_sock *tp = tcp_sk(sk); struct sk_buff *buff; @@ -5699,7 +5639,7 @@ index 0e5b9a654254..f7da9d719b25 100644 long limit; int nlen; u8 flags; -@@ -1678,6 +1681,30 @@ int tcp_fragment(struct sock *sk, enum tcp_queue tcp_queue, +@@ -1681,6 +1684,30 @@ int tcp_fragment(struct sock *sk, enum tcp_queue tcp_queue, if (diff) tcp_adjust_pcount(sk, skb, diff); @@ -5730,7 +5670,7 @@ index 0e5b9a654254..f7da9d719b25 100644 } /* Link BUFF into the send queue. */ -@@ -2035,13 +2062,12 @@ static u32 tcp_tso_autosize(const struct sock *sk, unsigned int mss_now, +@@ -2038,13 +2065,12 @@ static u32 tcp_tso_autosize(const struct sock *sk, unsigned int mss_now, static u32 tcp_tso_segs(struct sock *sk, unsigned int mss_now) { const struct tcp_congestion_ops *ca_ops = inet_csk(sk)->icsk_ca_ops; @@ -5749,7 +5689,7 @@ index 0e5b9a654254..f7da9d719b25 100644 return min_t(u32, tso_segs, sk->sk_gso_max_segs); } -@@ -2767,6 +2793,7 @@ static bool tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle, +@@ -2770,6 +2796,7 @@ static bool tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle, skb_set_delivery_time(skb, tp->tcp_wstamp_ns, SKB_CLOCK_MONOTONIC); list_move_tail(&skb->tcp_tsorted_anchor, &tp->tsorted_sent_queue); tcp_init_tso_segs(skb, mss_now); @@ -5757,7 +5697,7 @@ index 0e5b9a654254..f7da9d719b25 100644 goto repair; /* Skip network transmission */ } -@@ -2979,6 +3006,7 @@ void tcp_send_loss_probe(struct sock *sk) +@@ -2982,6 +3009,7 @@ void tcp_send_loss_probe(struct sock *sk) if (WARN_ON(!skb || !tcp_skb_pcount(skb))) goto rearm_timer; @@ -5860,9 +5800,9 @@ index b412ed88ccd9..d70f8b742b21 100644 -- 2.48.0.rc1 -From a3411065e4db0cdb3565bf9daf18b2ba8fe3b384 Mon Sep 17 00:00:00 2001 +From ccbcd886d7323bbd9acae1ddc2906c177cc24ae4 Mon Sep 17 00:00:00 2001 From: Peter Jung -Date: Sun, 2 Feb 2025 13:53:37 +0100 +Date: Sat, 8 Feb 2025 10:36:27 +0100 Subject: [PATCH 04/12] cachy Signed-off-by: Peter Jung @@ -6076,7 +6016,7 @@ index f48eaa98d22d..fc777c14cff6 100644 unprivileged_userfaultfd ======================== diff --git a/Makefile b/Makefile -index 7bc322bc7ad8..aba8664829c0 100644 +index 9de0dc460a83..2b4204407087 100644 --- a/Makefile +++ b/Makefile @@ -860,11 +860,19 @@ KBUILD_CFLAGS += -fno-delete-null-pointer-checks @@ -7153,7 +7093,7 @@ index 11e3f2f3b174..7b1bd69dc29e 100644 + endmenu diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c -index 5f216d626cbb..382af92c4ff1 100644 +index 53694baca966..f836ab663568 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -177,6 +177,8 @@ static int amdgpu_dm_init(struct amdgpu_device *adev); @@ -13374,7 +13314,7 @@ index 54ea59ff8fbe..18f87e0dd137 100644 help This option turns the kernel into a real-time kernel by replacing diff --git a/kernel/fork.c b/kernel/fork.c -index 9b301180fd41..0cb5431b4d7e 100644 +index 9da032802e34..32bf5e30ba4a 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -106,6 +106,10 @@ @@ -13388,7 +13328,7 @@ index 9b301180fd41..0cb5431b4d7e 100644 #include #include #include -@@ -2158,6 +2162,10 @@ __latent_entropy struct task_struct *copy_process( +@@ -2169,6 +2173,10 @@ __latent_entropy struct task_struct *copy_process( if ((clone_flags & (CLONE_NEWUSER|CLONE_FS)) == (CLONE_NEWUSER|CLONE_FS)) return ERR_PTR(-EINVAL); @@ -13399,7 +13339,7 @@ index 9b301180fd41..0cb5431b4d7e 100644 /* * Thread groups must share signals as well, and detached threads * can only be started up within the thread group. -@@ -3311,6 +3319,12 @@ int ksys_unshare(unsigned long unshare_flags) +@@ -3322,6 +3330,12 @@ int ksys_unshare(unsigned long unshare_flags) if (unshare_flags & CLONE_NEWNS) unshare_flags |= CLONE_FS; @@ -13435,7 +13375,7 @@ index 2ddb827e3bea..464049c4af3f 100644 return state; diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c -index 26958431deb7..8c0f17a96d4f 100644 +index 8800679b508d..eb95f524bea4 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -73,10 +73,19 @@ unsigned int sysctl_sched_tunable_scaling = SCHED_TUNABLESCALING_LOG; @@ -14053,9 +13993,9 @@ index 6872b5aff73e..1910fe1b2471 100644 -- 2.48.0.rc1 -From 6fe0c5e4544df7c64f9cdca4295e1c0e0c45740e Mon Sep 17 00:00:00 2001 +From 8d2c24065426a10dbdc28e6dd390b67861d740c5 Mon Sep 17 00:00:00 2001 From: Peter Jung -Date: Sun, 2 Feb 2025 13:54:07 +0100 +Date: Sat, 8 Feb 2025 10:36:39 +0100 Subject: [PATCH 05/12] crypto Signed-off-by: Peter Jung @@ -14827,26 +14767,26 @@ index fbf43482e1f5..11e95fc62636 100644 -- 2.48.0.rc1 -From 0be477e02bd37573754ab4fb4420929383b24b8c Mon Sep 17 00:00:00 2001 +From 5b3c80caab0d7708c3a0ecc8b65c72f403fcd852 Mon Sep 17 00:00:00 2001 From: Peter Jung -Date: Sun, 2 Feb 2025 13:54:18 +0100 +Date: Sat, 8 Feb 2025 10:36:51 +0100 Subject: [PATCH 06/12] fixes Signed-off-by: Peter Jung --- - arch/Kconfig | 4 +- - arch/x86/boot/compressed/Makefile | 1 + - drivers/firmware/efi/libstub/Makefile | 2 +- - .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 12 +++-- - drivers/gpu/drm/drm_edid.c | 47 +++++++++++++++++-- - drivers/hid/hid-asus.c | 26 ++++++++++ - drivers/hid/hid-ids.h | 1 + - include/linux/platform_data/x86/asus-wmi.h | 5 ++ - kernel/fork.c | 9 ++-- - kernel/kprobes.c | 23 +++++---- - kernel/sched/ext.c | 7 +-- - scripts/package/PKGBUILD | 5 ++ - 12 files changed, 113 insertions(+), 29 deletions(-) + arch/Kconfig | 4 +- + arch/x86/boot/compressed/Makefile | 1 + + drivers/firmware/efi/libstub/Makefile | 2 +- + drivers/gpu/drm/drm_edid.c | 47 ++++++++++++++++++++-- + drivers/hid/hid-asus.c | 26 ++++++++++++ + drivers/hid/hid-ids.h | 1 + + fs/fuse/file.c | 6 ++- + include/linux/platform_data/x86/asus-wmi.h | 5 +++ + kernel/fork.c | 9 +++-- + kernel/kprobes.c | 23 +++++------ + kernel/sched/ext.c | 7 ++-- + scripts/package/PKGBUILD | 5 +++ + 12 files changed, 109 insertions(+), 27 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index 6682b2a53e34..fe54298ae05c 100644 @@ -14895,29 +14835,6 @@ index ed4e8ddbe76a..1141cd06011f 100644 -fPIC -fno-strict-aliasing -mno-red-zone \ -mno-mmx -mno-sse -fshort-wchar \ -Wno-pointer-sign \ -diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c -index 382af92c4ff1..f836ab663568 100644 ---- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c -+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c -@@ -12272,10 +12272,14 @@ void amdgpu_dm_update_freesync_caps(struct drm_connector *connector, - - if (edid && (sink->sink_signal == SIGNAL_TYPE_DISPLAY_PORT || - sink->sink_signal == SIGNAL_TYPE_EDP)) { -- amdgpu_dm_connector->min_vfreq = connector->display_info.monitor_range.min_vfreq; -- amdgpu_dm_connector->max_vfreq = connector->display_info.monitor_range.max_vfreq; -- if (amdgpu_dm_connector->max_vfreq - amdgpu_dm_connector->min_vfreq > 10) -- freesync_capable = true; -+ if (amdgpu_dm_connector->dc_link && -+ amdgpu_dm_connector->dc_link->dpcd_caps.allow_invalid_MSA_timing_param) { -+ amdgpu_dm_connector->min_vfreq = connector->display_info.monitor_range.min_vfreq; -+ amdgpu_dm_connector->max_vfreq = connector->display_info.monitor_range.max_vfreq; -+ if (amdgpu_dm_connector->max_vfreq - amdgpu_dm_connector->min_vfreq > 10) -+ freesync_capable = true; -+ } -+ - parse_amd_vsdb(amdgpu_dm_connector, edid, &vsdb_info); - - if (vsdb_info.replay_mode) { diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 855beafb76ff..ad78059ee954 100644 --- a/drivers/gpu/drm/drm_edid.c @@ -15067,6 +14984,31 @@ index d1d479ca50a2..d1ab021e4a6a 100644 #define USB_DEVICE_ID_ASUSTEK_ROG_NKEY_ALLY 0x1abe #define USB_DEVICE_ID_ASUSTEK_ROG_NKEY_ALLY_X 0x1b4c #define USB_DEVICE_ID_ASUSTEK_ROG_CLAYMORE_II_KEYBOARD 0x196b +diff --git a/fs/fuse/file.c b/fs/fuse/file.c +index 7d92a5479998..a40d65ffb94d 100644 +--- a/fs/fuse/file.c ++++ b/fs/fuse/file.c +@@ -955,8 +955,10 @@ static void fuse_readpages_end(struct fuse_mount *fm, struct fuse_args *args, + fuse_invalidate_atime(inode); + } + +- for (i = 0; i < ap->num_folios; i++) ++ for (i = 0; i < ap->num_folios; i++) { + folio_end_read(ap->folios[i], !err); ++ folio_put(ap->folios[i]); ++ } + if (ia->ff) + fuse_file_put(ia->ff, false); + +@@ -1048,7 +1050,7 @@ static void fuse_readahead(struct readahead_control *rac) + ap = &ia->ap; + + while (ap->num_folios < cur_pages) { +- folio = readahead_folio(rac); ++ folio = __readahead_folio(rac); + ap->folios[ap->num_folios] = folio; + ap->descs[ap->num_folios].length = folio_size(folio); + ap->num_folios++; diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/platform_data/x86/asus-wmi.h index 365e119bebaa..783e2a336861 100644 --- a/include/linux/platform_data/x86/asus-wmi.h @@ -15084,10 +15026,10 @@ index 365e119bebaa..783e2a336861 100644 .matches = { DMI_MATCH(DMI_BOARD_NAME, "GA403U"), diff --git a/kernel/fork.c b/kernel/fork.c -index 0cb5431b4d7e..e919c8c3a121 100644 +index 32bf5e30ba4a..e12de63bac76 100644 --- a/kernel/fork.c +++ b/kernel/fork.c -@@ -1518,12 +1518,13 @@ struct file *get_task_exe_file(struct task_struct *task) +@@ -1529,12 +1529,13 @@ struct file *get_task_exe_file(struct task_struct *task) struct file *exe_file = NULL; struct mm_struct *mm; @@ -15174,10 +15116,10 @@ index b027a4030976..5cc750200f19 100644 return ret; diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c -index 19813b387ef9..2e07cb99cd4e 100644 +index 76030e54a3f5..83cae9398987 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c -@@ -5206,9 +5206,10 @@ static void scx_dump_task(struct seq_buf *s, struct scx_dump_ctx *dctx, +@@ -5264,9 +5264,10 @@ static void scx_dump_task(struct seq_buf *s, struct scx_dump_ctx *dctx, scx_get_task_state(p), p->scx.flags & ~SCX_TASK_STATE_MASK, p->scx.dsq_flags, ops_state & SCX_OPSS_STATE_MASK, ops_state >> SCX_OPSS_QSEQ_SHIFT); @@ -15210,20 +15152,20 @@ index dca706617adc..89d3aef160b7 100644 -- 2.48.0.rc1 -From 775ce47a87b04e672a3cc3dbf8eb3e1f8dbc448a Mon Sep 17 00:00:00 2001 +From b2d119ea62964c08fda952ffc8b5860dc9c67990 Mon Sep 17 00:00:00 2001 From: Peter Jung -Date: Sun, 2 Feb 2025 13:54:31 +0100 +Date: Sat, 8 Feb 2025 10:37:07 +0100 Subject: [PATCH 07/12] itmt-core-ranking Signed-off-by: Peter Jung --- arch/x86/include/asm/topology.h | 4 +- arch/x86/kernel/itmt.c | 81 ++++++++++++++------------------- - arch/x86/kernel/smpboot.c | 19 +------- + arch/x86/kernel/smpboot.c | 8 +--- kernel/sched/fair.c | 42 +++++++++++++---- kernel/sched/sched.h | 1 - kernel/sched/topology.c | 15 +----- - 6 files changed, 70 insertions(+), 92 deletions(-) + 6 files changed, 69 insertions(+), 82 deletions(-) diff --git a/arch/x86/include/asm/topology.h b/arch/x86/include/asm/topology.h index fd41103ad342..63bab25a4896 100644 @@ -15396,7 +15338,7 @@ index 51b805c727fc..9cea1fc36c18 100644 int arch_asym_cpu_priority(int cpu) diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c -index b5a8f0891135..ef63b1c0b491 100644 +index f1fac08fdef2..ef63b1c0b491 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -482,12 +482,6 @@ static int x86_core_flags(void) @@ -15412,23 +15354,7 @@ index b5a8f0891135..ef63b1c0b491 100644 #ifdef CONFIG_SCHED_CLUSTER static int x86_cluster_flags(void) { -@@ -495,15 +489,6 @@ static int x86_cluster_flags(void) - } - #endif - --static int x86_die_flags(void) --{ -- if (cpu_feature_enabled(X86_FEATURE_HYBRID_CPU) || -- cpu_feature_enabled(X86_FEATURE_AMD_HETEROGENEOUS_CORES)) -- return x86_sched_itmt_flags(); -- -- return 0; --} -- - /* - * Set if a package/die has multiple NUMA nodes inside. - * AMD Magny-Cours, Intel Cluster-on-Die, and Intel -@@ -519,7 +504,7 @@ static void __init build_sched_topology(void) +@@ -510,7 +504,7 @@ static void __init build_sched_topology(void) #ifdef CONFIG_SCHED_SMT x86_topology[i++] = (struct sched_domain_topology_level){ @@ -15437,20 +15363,11 @@ index b5a8f0891135..ef63b1c0b491 100644 }; #endif #ifdef CONFIG_SCHED_CLUSTER -@@ -539,7 +524,7 @@ static void __init build_sched_topology(void) - */ - if (!x86_has_numa_in_package) { - x86_topology[i++] = (struct sched_domain_topology_level){ -- cpu_cpu_mask, x86_die_flags, SD_INIT_NAME(PKG) -+ cpu_cpu_mask, x86_sched_itmt_flags, SD_INIT_NAME(PKG) - }; - } - diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c -index 8c0f17a96d4f..c532ffb153b4 100644 +index eb95f524bea4..02c7cb4badea 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c -@@ -9836,6 +9836,8 @@ struct sg_lb_stats { +@@ -9845,6 +9845,8 @@ struct sg_lb_stats { unsigned int group_weight; enum group_type group_type; unsigned int group_asym_packing; /* Tasks should be moved to preferred CPU */ @@ -15459,7 +15376,7 @@ index 8c0f17a96d4f..c532ffb153b4 100644 unsigned int group_smt_balance; /* Task on busy SMT be moved */ unsigned long group_misfit_task_load; /* A CPU has a task too big for its capacity */ #ifdef CONFIG_NUMA_BALANCING -@@ -10165,7 +10167,7 @@ sched_group_asym(struct lb_env *env, struct sg_lb_stats *sgs, struct sched_group +@@ -10174,7 +10176,7 @@ sched_group_asym(struct lb_env *env, struct sg_lb_stats *sgs, struct sched_group (sgs->group_weight - sgs->idle_cpus != 1)) return false; @@ -15468,7 +15385,7 @@ index 8c0f17a96d4f..c532ffb153b4 100644 } /* One group has more than one SMT CPU while the other group does not */ -@@ -10246,6 +10248,17 @@ sched_reduced_capacity(struct rq *rq, struct sched_domain *sd) +@@ -10255,6 +10257,17 @@ sched_reduced_capacity(struct rq *rq, struct sched_domain *sd) return check_cpu_capacity(rq, sd); } @@ -15486,7 +15403,7 @@ index 8c0f17a96d4f..c532ffb153b4 100644 /** * update_sg_lb_stats - Update sched_group's statistics for load balancing. * @env: The load balancing environment. -@@ -10262,11 +10275,13 @@ static inline void update_sg_lb_stats(struct lb_env *env, +@@ -10271,11 +10284,13 @@ static inline void update_sg_lb_stats(struct lb_env *env, bool *sg_overloaded, bool *sg_overutilized) { @@ -15501,7 +15418,7 @@ index 8c0f17a96d4f..c532ffb153b4 100644 for_each_cpu_and(i, sched_group_span(group), env->cpus) { struct rq *rq = cpu_rq(i); -@@ -10280,16 +10295,12 @@ static inline void update_sg_lb_stats(struct lb_env *env, +@@ -10289,16 +10304,12 @@ static inline void update_sg_lb_stats(struct lb_env *env, nr_running = rq->nr_running; sgs->sum_nr_running += nr_running; @@ -15520,7 +15437,7 @@ index 8c0f17a96d4f..c532ffb153b4 100644 /* * No need to call idle_cpu() if nr_running is not 0 */ -@@ -10299,10 +10310,21 @@ static inline void update_sg_lb_stats(struct lb_env *env, +@@ -10308,10 +10319,21 @@ static inline void update_sg_lb_stats(struct lb_env *env, continue; } @@ -15543,7 +15460,7 @@ index 8c0f17a96d4f..c532ffb153b4 100644 /* Check for a misfit task on the cpu */ if (sgs->group_misfit_task_load < rq->misfit_task_load) { sgs->group_misfit_task_load = rq->misfit_task_load; -@@ -10397,7 +10419,7 @@ static bool update_sd_pick_busiest(struct lb_env *env, +@@ -10406,7 +10428,7 @@ static bool update_sd_pick_busiest(struct lb_env *env, case group_asym_packing: /* Prefer to move from lowest priority CPU's work */ @@ -15600,9 +15517,9 @@ index 9748a4c8d668..59b8157cb114 100644 -- 2.48.0.rc1 -From b70533fb4d77af574e32e3ab1e48756b99313cd9 Mon Sep 17 00:00:00 2001 +From 12158f3774a49a2f0931b1333a2cb00e0ca785ca Mon Sep 17 00:00:00 2001 From: Peter Jung -Date: Sun, 2 Feb 2025 13:54:42 +0100 +Date: Sat, 8 Feb 2025 10:37:31 +0100 Subject: [PATCH 08/12] ntsync Signed-off-by: Peter Jung @@ -18642,9 +18559,9 @@ index 000000000000..3aad311574c4 -- 2.48.0.rc1 -From 11d0eb9308e917e02ad88da6964e7e685d09b79a Mon Sep 17 00:00:00 2001 +From 0e80a2fcc5009eaa2a3eca340eae386a091c5778 Mon Sep 17 00:00:00 2001 From: Peter Jung -Date: Sun, 2 Feb 2025 13:54:54 +0100 +Date: Sat, 8 Feb 2025 10:37:46 +0100 Subject: [PATCH 09/12] perf-per-core Signed-off-by: Peter Jung @@ -19540,9 +19457,9 @@ index 8277c64f88db..b5a5e1411469 100644 -- 2.48.0.rc1 -From da4f2e91d18239b158f7f48b0bd718110ade01ff Mon Sep 17 00:00:00 2001 +From c48b9373a303bb377c7a27beb74c589ef190172a Mon Sep 17 00:00:00 2001 From: Peter Jung -Date: Sun, 2 Feb 2025 13:55:04 +0100 +Date: Sat, 8 Feb 2025 10:37:57 +0100 Subject: [PATCH 10/12] pksm Signed-off-by: Peter Jung @@ -19973,9 +19890,9 @@ index e9115b4d8b63..2afc778f2d17 100644 -- 2.48.0.rc1 -From 6a47e0ec10d0964d0447b57904e228d8b32b0de1 Mon Sep 17 00:00:00 2001 +From 470c59573e51507951213cec53c9183ed235648c Mon Sep 17 00:00:00 2001 From: Peter Jung -Date: Sun, 2 Feb 2025 13:55:14 +0100 +Date: Sat, 8 Feb 2025 10:38:07 +0100 Subject: [PATCH 11/12] t2 Signed-off-by: Peter Jung @@ -21924,7 +21841,7 @@ index 000000000000..fa28a691da6a +MODULE_DESCRIPTION("MacBookPro Touch Bar Keyboard Mode Driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c -index 65023bfe30ed..42815300081a 100644 +index 42c0bd9d2f31..c18e20175e9d 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -73,6 +73,7 @@ MODULE_LICENSE("GPL"); @@ -30323,9 +30240,9 @@ index 9eed3683ad76..7ddbf75f4c26 100755 -- 2.48.0.rc1 -From 7d65948abcfc815f56268ab3d7a90d175520536d Mon Sep 17 00:00:00 2001 +From 54a923413ce52908459fb465882fed6624c10318 Mon Sep 17 00:00:00 2001 From: Peter Jung -Date: Sun, 2 Feb 2025 13:55:24 +0100 +Date: Sat, 8 Feb 2025 10:38:19 +0100 Subject: [PATCH 12/12] zstd Signed-off-by: Peter Jung @@ -48974,3 +48891,4 @@ index 469fc3059be0..0ae819f0c927 100644 -- 2.48.0.rc1 +