diff --git a/patches/0001-cachyos-base-all.patch b/patches/0001-cachyos-base-all.patch index 83b4d00..7bd0007 100644 --- a/patches/0001-cachyos-base-all.patch +++ b/patches/0001-cachyos-base-all.patch @@ -1,6 +1,6 @@ -From 1ec94c7b86986796d5d14135302e81dd3ddbe223 Mon Sep 17 00:00:00 2001 +From bb47d9fb19e79f1962a974ae8dd30337c28713c4 Mon Sep 17 00:00:00 2001 From: Peter Jung -Date: Mon, 20 Jan 2025 13:21:23 +0100 +Date: Sun, 2 Feb 2025 13:53:06 +0100 Subject: [PATCH 01/12] amd-pstate Signed-off-by: Peter Jung @@ -1003,9 +1003,9 @@ index cd573bc6b6db..9747e3be6cee 100644 -- 2.48.0.rc1 -From b74b9b0459100443f73ce718d0191bf58d6cb4b4 Mon Sep 17 00:00:00 2001 +From 24387ecea1f69a77a6236c4584dc06ea79f4ef1b Mon Sep 17 00:00:00 2001 From: Peter Jung -Date: Mon, 20 Jan 2025 13:21:35 +0100 +Date: Sun, 2 Feb 2025 13:53:18 +0100 Subject: [PATCH 02/12] amd-tlb-broadcast Signed-off-by: Peter Jung @@ -1014,26 +1014,28 @@ 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 | 103 +++++ - arch/x86/include/asm/mmu.h | 6 + - arch/x86/include/asm/mmu_context.h | 14 + + 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/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 | 92 ++++- + arch/x86/include/asm/tlbflush.h | 94 ++++- + arch/x86/kernel/alternative.c | 10 +- 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 | 496 +++++++++++++++++++++++-- + arch/x86/mm/tlb.c | 540 ++++++++++++++++++++++--- 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 + - 23 files changed, 695 insertions(+), 79 deletions(-) + 25 files changed, 741 insertions(+), 97 deletions(-) create mode 100644 arch/x86/include/asm/invlpgb.h diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig @@ -1050,7 +1052,7 @@ index ef6cfea9df73..1f824dcab4dc 100644 select HAVE_POSIX_CPU_TIMERS_TASK_WORK select HAVE_REGS_AND_STACK_ACCESS_API diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu -index 2a7279d80460..bacdc502903f 100644 +index 2a7279d80460..abe013a1b076 100644 --- a/arch/x86/Kconfig.cpu +++ b/arch/x86/Kconfig.cpu @@ -395,6 +395,10 @@ config X86_VMX_FEATURE_NAMES @@ -1059,7 +1061,7 @@ index 2a7279d80460..bacdc502903f 100644 +config X86_BROADCAST_TLB_FLUSH + def_bool y -+ depends on CPU_SUP_AMD ++ depends on CPU_SUP_AMD && 64BIT + menuconfig PROCESSOR_SELECT bool "Supported processor vendors" if EXPERT @@ -1096,16 +1098,17 @@ 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..418402535319 +index 000000000000..5fba41671a6d --- /dev/null +++ b/arch/x86/include/asm/invlpgb.h -@@ -0,0 +1,103 @@ +@@ -0,0 +1,107 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_INVLPGB +#define _ASM_X86_INVLPGB + +#include +#include ++#include + +/* + * INVLPGB does broadcast TLB invalidation across all the CPUs in the system. @@ -1118,12 +1121,15 @@ index 000000000000..418402535319 + */ +static inline void __invlpgb(unsigned long asid, unsigned long pcid, + unsigned long addr, u16 extra_count, -+ bool pmd_stride, unsigned long flags) ++ bool pmd_stride, u8 flags) +{ + u32 edx = (pcid << 16) | asid; + u32 ecx = (pmd_stride << 31) | extra_count; + u64 rax = addr | flags; + ++ /* The low bits in rax are for flags. Verify addr is clean. */ ++ VM_WARN_ON_ONCE(addr & ~PAGE_MASK); ++ + /* INVLPGB; supported in binutils >= 2.36. */ + asm volatile(".byte 0x0f, 0x01, 0xfe" : : "a" (rax), "c" (ecx), "d" (edx)); +} @@ -1204,10 +1210,19 @@ index 000000000000..418402535319 + +#endif /* _ASM_X86_INVLPGB */ diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h -index ce4677b8b735..51f25d38de86 100644 +index ce4677b8b735..d71cd599fec4 100644 --- a/arch/x86/include/asm/mmu.h +++ b/arch/x86/include/asm/mmu.h -@@ -67,6 +67,12 @@ typedef struct { +@@ -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 { u16 pkey_allocation_map; s16 execute_only_pkey; #endif @@ -1221,7 +1236,7 @@ index ce4677b8b735..51f25d38de86 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..65f50464b5c3 100644 +index 2886cb668d7f..d670699d32c2 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) @@ -1233,7 +1248,15 @@ index 2886cb668d7f..65f50464b5c3 100644 /* * Init a new mm. Used on mm copies, like at fork() * and on mm's that are brand-new, like at execve(). -@@ -160,6 +162,14 @@ static inline int init_new_context(struct task_struct *tsk, +@@ -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, mm->context.execute_only_pkey = -1; } #endif @@ -1248,7 +1271,7 @@ index 2886cb668d7f..65f50464b5c3 100644 mm_reset_untag_mask(mm); init_new_context_ldt(mm); return 0; -@@ -169,6 +179,10 @@ static inline int init_new_context(struct task_struct *tsk, +@@ -169,6 +180,10 @@ static inline int init_new_context(struct task_struct *tsk, static inline void destroy_context(struct mm_struct *mm) { destroy_context_ldt(mm); @@ -1321,10 +1344,15 @@ index 1ad56eb3e8a8..f9a17edf63ad 100644 #endif /* _ARCH_X86_TLBBATCH_H */ diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h -index 69e79fff41b8..5490ca71e27f 100644 +index 69e79fff41b8..f8aaa4bcb4d8 100644 --- a/arch/x86/include/asm/tlbflush.h +++ b/arch/x86/include/asm/tlbflush.h -@@ -10,6 +10,7 @@ +@@ -6,10 +6,12 @@ + #include + #include + ++#include + #include #include #include #include @@ -1332,7 +1360,7 @@ index 69e79fff41b8..5490ca71e27f 100644 #include #include #include -@@ -183,6 +184,13 @@ static inline void cr4_init_shadow(void) +@@ -183,6 +185,13 @@ static inline void cr4_init_shadow(void) extern unsigned long mmu_cr4_features; extern u32 *trampoline_cr4_features; @@ -1346,7 +1374,15 @@ index 69e79fff41b8..5490ca71e27f 100644 extern void initialize_tlbstate_and_flush(void); /* -@@ -230,6 +238,78 @@ void flush_tlb_one_kernel(unsigned long addr); +@@ -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); void flush_tlb_multi(const struct cpumask *cpumask, const struct flush_tlb_info *info); @@ -1379,10 +1415,10 @@ index 69e79fff41b8..5490ca71e27f 100644 + if (!cpu_feature_enabled(X86_FEATURE_INVLPGB)) + return 0; + -+ asid = READ_ONCE(mm->context.global_asid); ++ asid = smp_load_acquire(&mm->context.global_asid); + + /* mm->context.global_asid is either 0, or a global ASID */ -+ VM_WARN_ON_ONCE(is_dyn_asid(asid)); ++ VM_WARN_ON_ONCE(asid && is_dyn_asid(asid)); + + return asid; +} @@ -1425,7 +1461,7 @@ index 69e79fff41b8..5490ca71e27f 100644 #ifdef CONFIG_PARAVIRT #include #endif -@@ -277,21 +357,15 @@ static inline u64 inc_mm_tlb_gen(struct mm_struct *mm) +@@ -277,21 +359,15 @@ static inline u64 inc_mm_tlb_gen(struct mm_struct *mm) return atomic64_inc_return(&mm->context.tlb_gen); } @@ -1450,6 +1486,39 @@ index 69e79fff41b8..5490ca71e27f 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 @@ -1578,7 +1647,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..6449ac701c88 100644 +index a2becb85bea7..682da8d0d1c9 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -74,13 +74,15 @@ @@ -1621,7 +1690,7 @@ index a2becb85bea7..6449ac701c88 100644 if (this_cpu_read(cpu_tlbstate.invalidate_other)) clear_asid_other(); -@@ -251,6 +267,290 @@ static void choose_new_asid(struct mm_struct *next, u64 next_tlb_gen, +@@ -251,6 +267,272 @@ static void choose_new_asid(struct mm_struct *next, u64 next_tlb_gen, *need_flush = true; } @@ -1665,23 +1734,28 @@ index a2becb85bea7..6449ac701c88 100644 + +static u16 get_global_asid(void) +{ ++ ++ u16 asid; ++ + lockdep_assert_held(&global_asid_lock); + -+ do { -+ u16 start = last_global_asid; -+ u16 asid = find_next_zero_bit(global_asid_used, MAX_ASID_AVAILABLE, start); ++ /* The previous allocated ASID is at the top of the address space. */ ++ if (last_global_asid >= MAX_ASID_AVAILABLE - 1) ++ reset_global_asid_space(); + -+ if (asid >= MAX_ASID_AVAILABLE) { -+ reset_global_asid_space(); -+ continue; -+ } ++ asid = find_next_zero_bit(global_asid_used, MAX_ASID_AVAILABLE, last_global_asid); + -+ /* Claim this global ASID. */ -+ __set_bit(asid, global_asid_used); -+ last_global_asid = asid; -+ global_asid_available--; -+ return asid; -+ } while (1); ++ if (asid >= MAX_ASID_AVAILABLE) { ++ /* This should never happen. */ ++ VM_WARN_ONCE(1, "Unable to allocate global ASID despite %d available\n", global_asid_available); ++ return 0; ++ } ++ ++ /* Claim this global ASID. */ ++ __set_bit(asid, global_asid_used); ++ last_global_asid = asid; ++ global_asid_available--; ++ return asid; +} + +/* @@ -1750,6 +1824,8 @@ index a2becb85bea7..6449ac701c88 100644 + */ +static void use_global_asid(struct mm_struct *mm) +{ ++ u16 asid; ++ + guard(raw_spinlock_irqsave)(&global_asid_lock); + + /* This process is already using broadcast TLB invalidation. */ @@ -1757,61 +1833,34 @@ index a2becb85bea7..6449ac701c88 100644 + return; + + /* The last global ASID was consumed while waiting for the lock. */ -+ if (!global_asid_available) ++ if (!global_asid_available) { ++ VM_WARN_ONCE(1, "Ran out of global ASIDs\n"); ++ return; ++ } ++ ++ asid = get_global_asid(); ++ if (!asid) + return; + + /* -+ * The transition from IPI TLB flushing, with a dynamic ASID, -+ * and broadcast TLB flushing, using a global ASID, uses memory -+ * ordering for synchronization. -+ * -+ * While the process has threads still using a dynamic ASID, -+ * TLB invalidation IPIs continue to get sent. -+ * -+ * This code sets asid_transition first, before assigning the -+ * global ASID. -+ * -+ * The TLB flush code will only verify the ASID transition -+ * after it has seen the new global ASID for the process. ++ * Notably flush_tlb_mm_range() -> broadcast_tlb_flush() -> ++ * finish_asid_transition() needs to observe asid_transition = true ++ * once it observes global_asid. + */ -+ WRITE_ONCE(mm->context.asid_transition, true); -+ WRITE_ONCE(mm->context.global_asid, get_global_asid()); ++ mm->context.asid_transition = true; ++ smp_store_release(&mm->context.global_asid, asid); +} + -+/* -+ * Figure out whether to assign a global ASID to a process. -+ * We vary the threshold by how empty or full global ASID space is. -+ * 1/4 full: >= 4 active threads -+ * 1/2 full: >= 8 active threads -+ * 3/4 full: >= 16 active threads -+ * 7/8 full: >= 32 active threads -+ * etc -+ * -+ * This way we should never exhaust the global ASID space, even on very -+ * large systems, and the processes with the largest number of active -+ * threads should be able to use broadcast TLB invalidation. -+ */ -+#define HALFFULL_THRESHOLD 8 +static bool meets_global_asid_threshold(struct mm_struct *mm) +{ -+ int avail = global_asid_available; -+ int threshold = HALFFULL_THRESHOLD; -+ -+ if (!avail) ++ if (!global_asid_available) + return false; + -+ if (avail > MAX_ASID_AVAILABLE * 3 / 4) { -+ threshold = HALFFULL_THRESHOLD / 4; -+ } else if (avail > MAX_ASID_AVAILABLE / 2) { -+ threshold = HALFFULL_THRESHOLD / 2; -+ } else if (avail < MAX_ASID_AVAILABLE / 3) { -+ do { -+ avail *= 2; -+ threshold *= 2; -+ } while ((avail + threshold) < MAX_ASID_AVAILABLE / 2); -+ } -+ -+ return mm_active_cpus_exceeds(mm, threshold); ++ /* ++ * Assign a global ASID if the process is active on ++ * 4 or more CPUs simultaneously. ++ */ ++ return mm_active_cpus_exceeds(mm, 3); +} + +static void consider_global_asid(struct mm_struct *mm) @@ -1888,7 +1937,7 @@ index a2becb85bea7..6449ac701c88 100644 + /* Do any CPUs supporting INVLPGB need PTI? */ + if (static_cpu_has(X86_FEATURE_PTI)) + invlpgb_flush_single_pcid_nosync(user_pcid(asid)); -+ } else for (; addr < info->end; addr += nr << info->stride_shift) { ++ } else do { + /* + * Calculate how many pages can be flushed at once; if the + * remainder of the range is less than one page, flush one. @@ -1900,7 +1949,9 @@ index a2becb85bea7..6449ac701c88 100644 + /* Do any CPUs supporting INVLPGB need PTI? */ + if (static_cpu_has(X86_FEATURE_PTI)) + invlpgb_flush_user_nr_nosync(user_pcid(asid), addr, nr, pmd, info->freed_tables); -+ } ++ ++ addr += nr << info->stride_shift; ++ } while (addr < info->end); + + finish_asid_transition(info); + @@ -1912,7 +1963,7 @@ index a2becb85bea7..6449ac701c88 100644 /* * Given an ASID, flush the corresponding user ASID. We can delay this * until the next time we switch to it. -@@ -556,8 +856,9 @@ void switch_mm_irqs_off(struct mm_struct *unused, struct mm_struct *next, +@@ -556,8 +838,9 @@ void switch_mm_irqs_off(struct mm_struct *unused, struct mm_struct *next, */ if (prev == next) { /* Not actually switching mm's */ @@ -1924,7 +1975,7 @@ index a2becb85bea7..6449ac701c88 100644 /* * If this races with another thread that enables lam, 'new_lam' -@@ -573,6 +874,23 @@ void switch_mm_irqs_off(struct mm_struct *unused, struct mm_struct *next, +@@ -573,6 +856,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)); @@ -1948,21 +1999,36 @@ index a2becb85bea7..6449ac701c88 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 -@@ -606,6 +924,13 @@ void switch_mm_irqs_off(struct mm_struct *unused, struct mm_struct *next, - */ +@@ -607,30 +907,32 @@ 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(); + - /* - * Stop remote flushes for the previous mm. - * Skip kernel threads; we never send init_mm TLB flushing IPIs, -@@ -623,14 +948,12 @@ void switch_mm_irqs_off(struct mm_struct *unused, struct mm_struct *next, ++ /* ++ * 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)); next_tlb_gen = atomic64_read(&next->context.tlb_gen); choose_new_asid(next, next_tlb_gen, &new_asid, &need_flush); @@ -1979,7 +2045,7 @@ index a2becb85bea7..6449ac701c88 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 +1072,7 @@ static void flush_tlb_func(void *info) +@@ -749,7 +1051,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); @@ -1988,7 +2054,22 @@ index a2becb85bea7..6449ac701c88 100644 bool local = smp_processor_id() == f->initiating_cpu; unsigned long nr_invalidate = 0; u64 mm_tlb_gen; -@@ -769,6 +1092,16 @@ static void flush_tlb_func(void *info) +@@ -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; + } + if (unlikely(loaded_mm == &init_mm)) return; @@ -2005,7 +2086,7 @@ index a2becb85bea7..6449ac701c88 100644 VM_WARN_ON(this_cpu_read(cpu_tlbstate.ctxs[loaded_mm_asid].ctx_id) != loaded_mm->context.ctx_id); -@@ -786,6 +1119,8 @@ static void flush_tlb_func(void *info) +@@ -786,6 +1101,8 @@ static void flush_tlb_func(void *info) return; } @@ -2014,7 +2095,46 @@ index a2becb85bea7..6449ac701c88 100644 if (unlikely(f->new_tlb_gen != TLB_GENERATION_INVALID && f->new_tlb_gen <= local_tlb_gen)) { /* -@@ -926,7 +1261,7 @@ STATIC_NOPV void native_flush_tlb_multi(const struct cpumask *cpumask, +@@ -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, * up on the new contents of what used to be page tables, while * doing a speculative memory access. */ @@ -2022,11 +2142,17 @@ index a2becb85bea7..6449ac701c88 100644 + if (info->freed_tables || in_asid_transition(info)) on_each_cpu_mask(cpumask, flush_tlb_func, (void *)info, true); else - on_each_cpu_cond_mask(tlb_is_not_lazy, flush_tlb_func, -@@ -981,6 +1316,15 @@ static struct flush_tlb_info *get_flush_tlb_info(struct mm_struct *mm, +- 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); + } + +@@ -980,6 +1324,16 @@ static struct flush_tlb_info *get_flush_tlb_info(struct mm_struct *mm, + info->freed_tables = freed_tables; info->new_tlb_gen = new_tlb_gen; info->initiating_cpu = smp_processor_id(); - ++ info->trim_cpumask = 0; ++ + /* + * If the number of flushes is so large that a full flush + * would be faster, do a full flush. @@ -2035,11 +2161,10 @@ index a2becb85bea7..6449ac701c88 100644 + info->start = 0; + info->end = TLB_FLUSH_ALL; + } -+ + return info; } - -@@ -998,17 +1342,8 @@ void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start, +@@ -998,17 +1352,8 @@ void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start, bool freed_tables) { struct flush_tlb_info *info; @@ -2058,7 +2183,7 @@ index a2becb85bea7..6449ac701c88 100644 /* This is also a barrier that synchronizes with switch_mm(). */ new_tlb_gen = inc_mm_tlb_gen(mm); -@@ -1021,8 +1356,11 @@ void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start, +@@ -1021,8 +1366,12 @@ 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. */ @@ -2066,12 +2191,13 @@ index a2becb85bea7..6449ac701c88 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 +1374,19 @@ void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start, +@@ -1036,6 +1385,19 @@ void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start, } @@ -2091,7 +2217,7 @@ index a2becb85bea7..6449ac701c88 100644 static void do_flush_tlb_all(void *info) { count_vm_tlb_event(NR_TLB_REMOTE_FLUSH_RECEIVED); -@@ -1044,10 +1395,36 @@ static void do_flush_tlb_all(void *info) +@@ -1044,10 +1406,36 @@ static void do_flush_tlb_all(void *info) void flush_tlb_all(void) { @@ -2128,7 +2254,7 @@ index a2becb85bea7..6449ac701c88 100644 static void do_kernel_range_flush(void *info) { struct flush_tlb_info *f = info; -@@ -1060,22 +1437,21 @@ static void do_kernel_range_flush(void *info) +@@ -1060,22 +1448,21 @@ static void do_kernel_range_flush(void *info) void flush_tlb_kernel_range(unsigned long start, unsigned long end) { @@ -2144,10 +2270,10 @@ index a2becb85bea7..6449ac701c88 100644 - 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); -+ + + if (broadcast_kernel_range_flush(info)) + ; /* Fall through. */ + else if (info->end == TLB_FLUSH_ALL) @@ -2162,7 +2288,7 @@ index a2becb85bea7..6449ac701c88 100644 } /* -@@ -1247,7 +1623,7 @@ void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch) +@@ -1247,7 +1634,7 @@ void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch) int cpu = get_cpu(); @@ -2171,7 +2297,7 @@ index a2becb85bea7..6449ac701c88 100644 TLB_GENERATION_INVALID); /* * flush_tlb_multi() is not optimized for the common case in which only -@@ -1263,12 +1639,62 @@ void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch) +@@ -1263,12 +1650,65 @@ void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch) local_irq_enable(); } @@ -2196,8 +2322,9 @@ index a2becb85bea7..6449ac701c88 100644 + struct mm_struct *mm, + unsigned long uaddr) +{ -+ if (static_cpu_has(X86_FEATURE_INVLPGB) && mm_global_asid(mm)) { -+ u16 asid = mm_global_asid(mm); ++ 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 @@ -2222,12 +2349,14 @@ index a2becb85bea7..6449ac701c88 100644 + * stragglers transition to the broadcast ASID. + */ + if (READ_ONCE(mm->context.asid_transition)) -+ goto also_send_ipi; -+ } else { -+also_send_ipi: ++ asid = 0; ++ } ++ ++ if (!asid) { + inc_mm_tlb_gen(mm); + cpumask_or(&batch->cpumask, &batch->cpumask, mm_cpumask(mm)); + } ++ + mmu_notifier_arch_invalidate_secondary_tlbs(mm, 0, -1UL); +} + @@ -2246,6 +2375,18 @@ 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 @@ -2333,9 +2474,9 @@ index 3ae84c3b8e6d..dc1c1057f26e 100644 -- 2.48.0.rc1 -From 1fc2e15c0c690b276928953ff73277b4d66e67f3 Mon Sep 17 00:00:00 2001 +From 3cfc3cd67b727b62206d7c97efd5ebf120e47555 Mon Sep 17 00:00:00 2001 From: Peter Jung -Date: Mon, 20 Jan 2025 13:21:45 +0100 +Date: Sun, 2 Feb 2025 13:53:27 +0100 Subject: [PATCH 03/12] bbr3 Signed-off-by: Peter Jung @@ -5719,9 +5860,9 @@ index b412ed88ccd9..d70f8b742b21 100644 -- 2.48.0.rc1 -From e01619bda1e69eea53c0f3ef61476fb02da06868 Mon Sep 17 00:00:00 2001 +From a3411065e4db0cdb3565bf9daf18b2ba8fe3b384 Mon Sep 17 00:00:00 2001 From: Peter Jung -Date: Mon, 20 Jan 2025 13:21:55 +0100 +Date: Sun, 2 Feb 2025 13:53:37 +0100 Subject: [PATCH 04/12] cachy Signed-off-by: Peter Jung @@ -5935,7 +6076,7 @@ index f48eaa98d22d..fc777c14cff6 100644 unprivileged_userfaultfd ======================== diff --git a/Makefile b/Makefile -index b9464c88ac72..ea555e6a8bf1 100644 +index 7bc322bc7ad8..aba8664829c0 100644 --- a/Makefile +++ b/Makefile @@ -860,11 +860,19 @@ KBUILD_CFLAGS += -fno-delete-null-pointer-checks @@ -5959,7 +6100,7 @@ index b9464c88ac72..ea555e6a8bf1 100644 # depends on `opt-level` and `debug-assertions`, respectively. KBUILD_RUSTFLAGS += -Cdebug-assertions=$(if $(CONFIG_RUST_DEBUG_ASSERTIONS),y,n) diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu -index bacdc502903f..f2c97bdcef58 100644 +index abe013a1b076..b4ee329777ae 100644 --- a/arch/x86/Kconfig.cpu +++ b/arch/x86/Kconfig.cpu @@ -155,9 +155,8 @@ config MPENTIUM4 @@ -6089,7 +6230,7 @@ index bacdc502903f..f2c97bdcef58 100644 + +config MZEN5 + bool "AMD Zen 5" -+ depends on (CC_IS_GCC && GCC_VERSION > 140000) || (CC_IS_CLANG && CLANG_VERSION >= 190000) ++ depends on (CC_IS_GCC && GCC_VERSION > 140000) || (CC_IS_CLANG && CLANG_VERSION >= 190100) + help + Select this for AMD Family 19h Zen 5 processors. + @@ -13912,9 +14053,9 @@ index 6872b5aff73e..1910fe1b2471 100644 -- 2.48.0.rc1 -From 7bc012030531a472b823293e167a86cd58da545c Mon Sep 17 00:00:00 2001 +From 6fe0c5e4544df7c64f9cdca4295e1c0e0c45740e Mon Sep 17 00:00:00 2001 From: Peter Jung -Date: Mon, 20 Jan 2025 13:22:05 +0100 +Date: Sun, 2 Feb 2025 13:54:07 +0100 Subject: [PATCH 05/12] crypto Signed-off-by: Peter Jung @@ -14686,25 +14827,26 @@ index fbf43482e1f5..11e95fc62636 100644 -- 2.48.0.rc1 -From 2f514dfe8b006e7fa976b6265bef4b8efb81ec11 Mon Sep 17 00:00:00 2001 +From 0be477e02bd37573754ab4fb4420929383b24b8c Mon Sep 17 00:00:00 2001 From: Peter Jung -Date: Mon, 20 Jan 2025 13:22:15 +0100 +Date: Sun, 2 Feb 2025 13:54:18 +0100 Subject: [PATCH 06/12] fixes Signed-off-by: Peter Jung --- arch/Kconfig | 4 +- - .../link/protocols/link_edp_panel_control.c | 3 +- + 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 | 4 +- + kernel/sched/ext.c | 7 +-- scripts/package/PKGBUILD | 5 ++ - sound/pci/hda/patch_realtek.c | 4 +- - 11 files changed, 105 insertions(+), 26 deletions(-) + 12 files changed, 113 insertions(+), 29 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index 6682b2a53e34..fe54298ae05c 100644 @@ -14728,20 +14870,54 @@ index 6682b2a53e34..fe54298ae05c 100644 depends on HAVE_ARCH_MMAP_RND_COMPAT_BITS help This value can be used to select the number of bits to use to -diff --git a/drivers/gpu/drm/amd/display/dc/link/protocols/link_edp_panel_control.c b/drivers/gpu/drm/amd/display/dc/link/protocols/link_edp_panel_control.c -index e0e3bb865359..ba98d56a0fe4 100644 ---- a/drivers/gpu/drm/amd/display/dc/link/protocols/link_edp_panel_control.c -+++ b/drivers/gpu/drm/amd/display/dc/link/protocols/link_edp_panel_control.c -@@ -187,7 +187,8 @@ bool edp_set_backlight_level_nits(struct dc_link *link, - (uint8_t *)(target_luminance), - sizeof(struct target_luminance_value)) != DC_OK) - return false; -- } else if (link->backlight_control_type == BACKLIGHT_CONTROL_AMD_AUX) { -+// } else if (link->backlight_control_type == BACKLIGHT_CONTROL_AMD_AUX) { -+ } else { - struct dpcd_source_backlight_set dpcd_backlight_set; - *(uint32_t *)&dpcd_backlight_set.backlight_level_millinits = backlight_millinits; - *(uint16_t *)&dpcd_backlight_set.backlight_transition_time_ms = (uint16_t)transition_time_in_ms; +diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile +index f2051644de94..606c74f27459 100644 +--- a/arch/x86/boot/compressed/Makefile ++++ b/arch/x86/boot/compressed/Makefile +@@ -25,6 +25,7 @@ targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \ + # avoid errors with '-march=i386', and future flags may depend on the target to + # be valid. + KBUILD_CFLAGS := -m$(BITS) -O2 $(CLANG_FLAGS) ++KBUILD_CFLAGS += -std=gnu11 + KBUILD_CFLAGS += -fno-strict-aliasing -fPIE + KBUILD_CFLAGS += -Wundef + KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING +diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile +index ed4e8ddbe76a..1141cd06011f 100644 +--- a/drivers/firmware/efi/libstub/Makefile ++++ b/drivers/firmware/efi/libstub/Makefile +@@ -11,7 +11,7 @@ cflags-y := $(KBUILD_CFLAGS) + + cflags-$(CONFIG_X86_32) := -march=i386 + cflags-$(CONFIG_X86_64) := -mcmodel=small +-cflags-$(CONFIG_X86) += -m$(BITS) -D__KERNEL__ \ ++cflags-$(CONFIG_X86) += -m$(BITS) -D__KERNEL__ -std=gnu11 \ + -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 @@ -14880,7 +15056,7 @@ index 506c6f377e7d..46e3e42f9eb5 100644 /* Initialize keyboard */ ret = asus_kbd_init(hdev, FEATURE_KBD_REPORT_ID); diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h -index 1f47fda809b9..6c2df0d37b3b 100644 +index d1d479ca50a2..d1ab021e4a6a 100644 --- a/drivers/hid/hid-ids.h +++ b/drivers/hid/hid-ids.h @@ -210,6 +210,7 @@ @@ -14998,18 +15174,20 @@ index b027a4030976..5cc750200f19 100644 return ret; diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c -index 19813b387ef9..29f9cf31dd34 100644 +index 19813b387ef9..2e07cb99cd4e 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c -@@ -5206,9 +5206,9 @@ static void scx_dump_task(struct seq_buf *s, struct scx_dump_ctx *dctx, +@@ -5206,9 +5206,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); - dump_line(s, " sticky/holding_cpu=%d/%d dsq_id=%s dsq_vtime=%llu", -+ dump_line(s, " sticky/holding_cpu=%d/%d dsq_id=%s dsq_vtime=%llu slice=%llu", - p->scx.sticky_cpu, p->scx.holding_cpu, dsq_id_buf, +- p->scx.sticky_cpu, p->scx.holding_cpu, dsq_id_buf, - p->scx.dsq_vtime); -+ p->scx.dsq_vtime, p->scx.slice); ++ dump_line(s, " sticky/holding_cpu=%d/%d dsq_id=%s", ++ p->scx.sticky_cpu, p->scx.holding_cpu, dsq_id_buf); ++ dump_line(s, " dsq_vtime=%llu slice=%llu weight=%u", ++ p->scx.dsq_vtime, p->scx.slice, p->scx.weight); dump_line(s, " cpus=%*pb", cpumask_pr_args(p->cpus_ptr)); if (SCX_HAS_OP(dump_task)) { @@ -15029,27 +15207,12 @@ index dca706617adc..89d3aef160b7 100644 echo "Installing System.map and config..." mkdir -p "${builddir}" cp System.map "${builddir}/System.map" -diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c -index ad66378d7321..4210bc8f12e1 100644 ---- a/sound/pci/hda/patch_realtek.c -+++ b/sound/pci/hda/patch_realtek.c -@@ -10641,8 +10641,8 @@ static const struct hda_quirk alc269_fixup_tbl[] = { - SND_PCI_QUIRK(0x1043, 0x1e1f, "ASUS Vivobook 15 X1504VAP", ALC2XX_FIXUP_HEADSET_MIC), - SND_PCI_QUIRK(0x1043, 0x1e51, "ASUS Zephyrus M15", ALC294_FIXUP_ASUS_GU502_PINS), - SND_PCI_QUIRK(0x1043, 0x1e5e, "ASUS ROG Strix G513", ALC294_FIXUP_ASUS_G513_PINS), -- SND_PCI_QUIRK(0x1043, 0x1e63, "ASUS H7606W", ALC285_FIXUP_ASUS_GU605_SPI_SPEAKER2_TO_DAC1), -- SND_PCI_QUIRK(0x1043, 0x1e83, "ASUS GA605W", ALC285_FIXUP_ASUS_GU605_SPI_SPEAKER2_TO_DAC1), -+ SND_PCI_QUIRK(0x1043, 0x1e63, "ASUS H7606W", ALC285_FIXUP_ASUS_GA403U_HEADSET_MIC), -+ SND_PCI_QUIRK(0x1043, 0x1e83, "ASUS GA605W", ALC285_FIXUP_ASUS_GA403U_HEADSET_MIC), - SND_PCI_QUIRK(0x1043, 0x1e8e, "ASUS Zephyrus G15", ALC289_FIXUP_ASUS_GA401), - SND_PCI_QUIRK(0x1043, 0x1eb3, "ASUS Ally RCLA72", ALC287_FIXUP_TAS2781_I2C), - SND_PCI_QUIRK(0x1043, 0x1ed3, "ASUS HN7306W", ALC287_FIXUP_CS35L41_I2C_2), -- 2.48.0.rc1 -From edca92ed206343ae09ee1af6ae0dfc26a68085b1 Mon Sep 17 00:00:00 2001 +From 775ce47a87b04e672a3cc3dbf8eb3e1f8dbc448a Mon Sep 17 00:00:00 2001 From: Peter Jung -Date: Mon, 20 Jan 2025 13:22:28 +0100 +Date: Sun, 2 Feb 2025 13:54:31 +0100 Subject: [PATCH 07/12] itmt-core-ranking Signed-off-by: Peter Jung @@ -15437,9 +15600,9 @@ index 9748a4c8d668..59b8157cb114 100644 -- 2.48.0.rc1 -From dad63380fd4bccaf1df47a5d2a14b3622a828bbf Mon Sep 17 00:00:00 2001 +From b70533fb4d77af574e32e3ab1e48756b99313cd9 Mon Sep 17 00:00:00 2001 From: Peter Jung -Date: Mon, 20 Jan 2025 13:22:39 +0100 +Date: Sun, 2 Feb 2025 13:54:42 +0100 Subject: [PATCH 08/12] ntsync Signed-off-by: Peter Jung @@ -15448,14 +15611,14 @@ Signed-off-by: Peter Jung Documentation/userspace-api/ntsync.rst | 385 +++++ MAINTAINERS | 9 + drivers/misc/Kconfig | 1 - - drivers/misc/ntsync.c | 992 +++++++++++- + drivers/misc/ntsync.c | 1000 +++++++++++- include/uapi/linux/ntsync.h | 42 +- tools/testing/selftests/Makefile | 1 + .../selftests/drivers/ntsync/.gitignore | 1 + .../testing/selftests/drivers/ntsync/Makefile | 7 + tools/testing/selftests/drivers/ntsync/config | 1 + .../testing/selftests/drivers/ntsync/ntsync.c | 1343 +++++++++++++++++ - 11 files changed, 2767 insertions(+), 16 deletions(-) + 11 files changed, 2772 insertions(+), 19 deletions(-) create mode 100644 Documentation/userspace-api/ntsync.rst create mode 100644 tools/testing/selftests/drivers/ntsync/.gitignore create mode 100644 tools/testing/selftests/drivers/ntsync/Makefile @@ -15898,7 +16061,7 @@ index 09cbe3f0ab1e..fb772bfe27c3 100644 This module provides kernel support for emulation of Windows NT synchronization primitives. It is not a hardware driver. diff --git a/drivers/misc/ntsync.c b/drivers/misc/ntsync.c -index 4954553b7baa..457ff28b789f 100644 +index 4954553b7baa..055395cde42b 100644 --- a/drivers/misc/ntsync.c +++ b/drivers/misc/ntsync.c @@ -6,11 +6,17 @@ @@ -16325,16 +16488,18 @@ index 4954553b7baa..457ff28b789f 100644 if (!ret && put_user(prev_count, user_args)) ret = -EFAULT; -@@ -97,6 +437,220 @@ static int ntsync_sem_post(struct ntsync_obj *sem, void __user *argp) +@@ -97,13 +437,229 @@ static int ntsync_sem_post(struct ntsync_obj *sem, void __user *argp) return ret; } +-static int ntsync_obj_release(struct inode *inode, struct file *file) +/* + * Actually change the mutex state, returning -EPERM if not the owner. + */ +static int unlock_mutex_state(struct ntsync_obj *mutex, + const struct ntsync_mutex_args *args) -+{ + { +- struct ntsync_obj *obj = file->private_data; + ntsync_assert_held(mutex); + + if (mutex->u.mutex.owner != args->owner) @@ -16496,7 +16661,7 @@ index 4954553b7baa..457ff28b789f 100644 + return -EFAULT; + return 0; +} -+ + +static int ntsync_mutex_read(struct ntsync_obj *mutex, void __user *argp) +{ + struct ntsync_mutex_args __user *user_args = argp; @@ -16543,10 +16708,19 @@ index 4954553b7baa..457ff28b789f 100644 + return 0; +} + - static int ntsync_obj_release(struct inode *inode, struct file *file) - { - struct ntsync_obj *obj = file->private_data; -@@ -114,8 +668,24 @@ static long ntsync_obj_ioctl(struct file *file, unsigned int cmd, ++static void ntsync_free_obj(struct ntsync_obj *obj) ++{ + fput(obj->dev->file); + kfree(obj); ++} + ++static int ntsync_obj_release(struct inode *inode, struct file *file) ++{ ++ ntsync_free_obj(file->private_data); + return 0; + } + +@@ -114,8 +670,24 @@ static long ntsync_obj_ioctl(struct file *file, unsigned int cmd, void __user *argp = (void __user *)parm; switch (cmd) { @@ -16573,7 +16747,7 @@ index 4954553b7baa..457ff28b789f 100644 default: return -ENOIOCTLCMD; } -@@ -140,6 +710,9 @@ static struct ntsync_obj *ntsync_alloc_obj(struct ntsync_device *dev, +@@ -140,6 +712,9 @@ static struct ntsync_obj *ntsync_alloc_obj(struct ntsync_device *dev, obj->dev = dev; get_file(dev->file); spin_lock_init(&obj->lock); @@ -16583,7 +16757,7 @@ index 4954553b7baa..457ff28b789f 100644 return obj; } -@@ -165,7 +738,6 @@ static int ntsync_obj_get_fd(struct ntsync_obj *obj) +@@ -165,7 +740,6 @@ static int ntsync_obj_get_fd(struct ntsync_obj *obj) static int ntsync_create_sem(struct ntsync_device *dev, void __user *argp) { @@ -16591,14 +16765,15 @@ index 4954553b7baa..457ff28b789f 100644 struct ntsync_sem_args args; struct ntsync_obj *sem; int fd; -@@ -182,12 +754,398 @@ static int ntsync_create_sem(struct ntsync_device *dev, void __user *argp) +@@ -182,12 +756,398 @@ static int ntsync_create_sem(struct ntsync_device *dev, void __user *argp) sem->u.sem.count = args.count; sem->u.sem.max = args.max; fd = ntsync_obj_get_fd(sem); - if (fd < 0) { -+ if (fd < 0) - kfree(sem); +- kfree(sem); - return fd; ++ if (fd < 0) ++ ntsync_free_obj(sem); + + return fd; +} @@ -16622,7 +16797,7 @@ index 4954553b7baa..457ff28b789f 100644 + mutex->u.mutex.owner = args.owner; + fd = ntsync_obj_get_fd(mutex); + if (fd < 0) -+ kfree(mutex); ++ ntsync_free_obj(mutex); + + return fd; +} @@ -16643,7 +16818,7 @@ index 4954553b7baa..457ff28b789f 100644 + event->u.event.signaled = args.signaled; + fd = ntsync_obj_get_fd(event); + if (fd < 0) -+ kfree(event); ++ ntsync_free_obj(event); + + return fd; +} @@ -16659,15 +16834,15 @@ index 4954553b7baa..457ff28b789f 100644 + if (file->f_op != &ntsync_obj_fops) { + fput(file); + return NULL; - } - -- return put_user(fd, &user_args->sem); ++ } ++ + obj = file->private_data; + if (obj->dev != dev) { + fput(file); + return NULL; -+ } -+ + } + +- return put_user(fd, &user_args->sem); + return obj; +} + @@ -16993,7 +17168,7 @@ index 4954553b7baa..457ff28b789f 100644 } static int ntsync_char_open(struct inode *inode, struct file *file) -@@ -198,6 +1156,8 @@ static int ntsync_char_open(struct inode *inode, struct file *file) +@@ -198,6 +1158,8 @@ static int ntsync_char_open(struct inode *inode, struct file *file) if (!dev) return -ENOMEM; @@ -17002,7 +17177,7 @@ index 4954553b7baa..457ff28b789f 100644 file->private_data = dev; dev->file = file; return nonseekable_open(inode, file); -@@ -219,8 +1179,16 @@ static long ntsync_char_ioctl(struct file *file, unsigned int cmd, +@@ -219,8 +1181,16 @@ static long ntsync_char_ioctl(struct file *file, unsigned int cmd, void __user *argp = (void __user *)parm; switch (cmd) { @@ -18467,9 +18642,9 @@ index 000000000000..3aad311574c4 -- 2.48.0.rc1 -From d0d15e3d79a2d5bb2c94b8ff3d2ab51f0b0100fe Mon Sep 17 00:00:00 2001 +From 11d0eb9308e917e02ad88da6964e7e685d09b79a Mon Sep 17 00:00:00 2001 From: Peter Jung -Date: Mon, 20 Jan 2025 13:22:50 +0100 +Date: Sun, 2 Feb 2025 13:54:54 +0100 Subject: [PATCH 09/12] perf-per-core Signed-off-by: Peter Jung @@ -19365,9 +19540,9 @@ index 8277c64f88db..b5a5e1411469 100644 -- 2.48.0.rc1 -From 6a7ea67c66634276802b4b9b0964a0b00db97d9c Mon Sep 17 00:00:00 2001 +From da4f2e91d18239b158f7f48b0bd718110ade01ff Mon Sep 17 00:00:00 2001 From: Peter Jung -Date: Mon, 20 Jan 2025 13:23:02 +0100 +Date: Sun, 2 Feb 2025 13:55:04 +0100 Subject: [PATCH 10/12] pksm Signed-off-by: Peter Jung @@ -19798,9 +19973,9 @@ index e9115b4d8b63..2afc778f2d17 100644 -- 2.48.0.rc1 -From 5e459e48f274c34d701726a61a96140381b1de2b Mon Sep 17 00:00:00 2001 +From 6a47e0ec10d0964d0447b57904e228d8b32b0de1 Mon Sep 17 00:00:00 2001 From: Peter Jung -Date: Mon, 20 Jan 2025 13:23:11 +0100 +Date: Sun, 2 Feb 2025 13:55:14 +0100 Subject: [PATCH 11/12] t2 Signed-off-by: Peter Jung @@ -19827,6 +20002,7 @@ Signed-off-by: Peter Jung drivers/hid/hid-quirks.c | 8 +- drivers/hwmon/applesmc.c | 1138 ++++++++++++----- drivers/input/mouse/bcm5974.c | 138 ++ + .../broadcom/brcm80211/brcmfmac/pcie.c | 4 +- drivers/pci/vgaarb.c | 1 + drivers/platform/x86/apple-gmux.c | 18 + drivers/staging/Kconfig | 2 + @@ -19861,7 +20037,7 @@ Signed-off-by: Peter Jung lib/test_printf.c | 20 +- lib/vsprintf.c | 36 +- scripts/checkpatch.pl | 2 +- - 56 files changed, 8348 insertions(+), 336 deletions(-) + 57 files changed, 8350 insertions(+), 338 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-driver-hid-appletb-kbd create mode 100644 drivers/gpu/drm/tiny/appletbdrm.c create mode 100644 drivers/hid/hid-appletb-bl.c @@ -21748,7 +21924,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 785743036647..2c3845cbb451 100644 +index 65023bfe30ed..42815300081a 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -73,6 +73,7 @@ MODULE_LICENSE("GPL"); @@ -21882,7 +22058,7 @@ index 785743036647..2c3845cbb451 100644 if (cls->is_indirect) app->mt_flags |= INPUT_MT_POINTER; -@@ -1770,6 +1792,15 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) +@@ -1769,6 +1791,15 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) } } @@ -21898,7 +22074,7 @@ index 785743036647..2c3845cbb451 100644 td = devm_kzalloc(&hdev->dev, sizeof(struct mt_device), GFP_KERNEL); if (!td) { dev_err(&hdev->dev, "cannot allocate multitouch data\n"); -@@ -1817,10 +1848,6 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) +@@ -1816,10 +1847,6 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) timer_setup(&td->release_timer, mt_expired_timeout, 0); @@ -21909,7 +22085,7 @@ index 785743036647..2c3845cbb451 100644 if (mtclass->quirks & MT_QUIRK_FIX_CONST_CONTACT_ID) mt_fix_const_fields(hdev, HID_DG_CONTACTID); -@@ -2305,6 +2332,11 @@ static const struct hid_device_id mt_devices[] = { +@@ -2301,6 +2328,11 @@ static const struct hid_device_id mt_devices[] = { MT_USB_DEVICE(USB_VENDOR_ID_XIROKU, USB_DEVICE_ID_XIROKU_CSR2) }, @@ -24096,6 +24272,28 @@ index dfdfb59cc8b5..e0da70576167 100644 {} }; +diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +index e4395b1f8c11..d2caa80e9412 100644 +--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c ++++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +@@ -2712,7 +2712,7 @@ static const struct pci_device_id brcmf_pcie_devid_table[] = { + BRCMF_PCIE_DEVICE(BRCM_PCIE_4350_DEVICE_ID, WCC), + BRCMF_PCIE_DEVICE_SUB(0x4355, BRCM_PCIE_VENDOR_ID_BROADCOM, 0x4355, WCC), + BRCMF_PCIE_DEVICE(BRCM_PCIE_4354_RAW_DEVICE_ID, WCC), +- BRCMF_PCIE_DEVICE(BRCM_PCIE_4355_DEVICE_ID, WCC), ++ BRCMF_PCIE_DEVICE(BRCM_PCIE_4355_DEVICE_ID, WCC_SEED), + BRCMF_PCIE_DEVICE(BRCM_PCIE_4356_DEVICE_ID, WCC), + BRCMF_PCIE_DEVICE(BRCM_PCIE_43567_DEVICE_ID, WCC), + BRCMF_PCIE_DEVICE(BRCM_PCIE_43570_DEVICE_ID, WCC), +@@ -2723,7 +2723,7 @@ static const struct pci_device_id brcmf_pcie_devid_table[] = { + BRCMF_PCIE_DEVICE(BRCM_PCIE_43602_2G_DEVICE_ID, WCC), + BRCMF_PCIE_DEVICE(BRCM_PCIE_43602_5G_DEVICE_ID, WCC), + BRCMF_PCIE_DEVICE(BRCM_PCIE_43602_RAW_DEVICE_ID, WCC), +- BRCMF_PCIE_DEVICE(BRCM_PCIE_4364_DEVICE_ID, WCC), ++ BRCMF_PCIE_DEVICE(BRCM_PCIE_4364_DEVICE_ID, WCC_SEED), + BRCMF_PCIE_DEVICE(BRCM_PCIE_4365_DEVICE_ID, BCA), + BRCMF_PCIE_DEVICE(BRCM_PCIE_4365_2G_DEVICE_ID, BCA), + BRCMF_PCIE_DEVICE(BRCM_PCIE_4365_5G_DEVICE_ID, BCA), diff --git a/drivers/pci/vgaarb.c b/drivers/pci/vgaarb.c index 78748e8d2dba..2b2b558cebe6 100644 --- a/drivers/pci/vgaarb.c @@ -30125,9 +30323,9 @@ index 9eed3683ad76..7ddbf75f4c26 100755 -- 2.48.0.rc1 -From 6f96c228cd968c7f47eb90d9e7ad6d679bf5a7f0 Mon Sep 17 00:00:00 2001 +From 7d65948abcfc815f56268ab3d7a90d175520536d Mon Sep 17 00:00:00 2001 From: Peter Jung -Date: Mon, 20 Jan 2025 13:23:20 +0100 +Date: Sun, 2 Feb 2025 13:55:24 +0100 Subject: [PATCH 12/12] zstd Signed-off-by: Peter Jung @@ -48776,4 +48974,3 @@ index 469fc3059be0..0ae819f0c927 100644 -- 2.48.0.rc1 -