diff --git a/patches.suse/kill-do_each_thread.patch b/patches.suse/kill-do_each_thread.patch new file mode 100644 index 0000000..078eb82 --- /dev/null +++ b/patches.suse/kill-do_each_thread.patch @@ -0,0 +1,130 @@ +From 75b7d18603920886787998652364d184946c1b0e Mon Sep 17 00:00:00 2001 +From: Oleg Nesterov +Date: Thu, 17 Aug 2023 18:37:08 +0200 +Subject: [PATCH] kill do_each_thread() + +References: bsc#1214683 (PREEMPT_RT prerequisite backports) +Patch-mainline: v6.6-rc1 +Git-commit: 5ffd2c37cb7a53d52099e5ed1fd7ccbc9e358791 + +Eric has pointed out that we still have 3 users of do_each_thread(). +Change them to use for_each_process_thread() and kill this helper. + +There is a subtle change, after do_each_thread/while_each_thread g == t == +&init_task, while after for_each_process_thread() they both point to +nowhere, but this doesn't matter. + +> Why is for_each_process_thread() better than do_each_thread()? + +Say, for_each_process_thread() is rcu safe, do_each_thread() is not. + +And certainly + + for_each_process_thread(p, t) { + do_something(p, t); + } + +looks better than + + do_each_thread(p, t) { + do_something(p, t); + } while_each_thread(p, t); + +And again, there are only 3 users of this awkward helper left. It should +have been killed years ago and in fact I thought it had already been +killed. It uses while_each_thread() which needs some changes. + +Link: https://lkml.kernel.org/r/20230817163708.GA8248@redhat.com +Signed-off-by: Oleg Nesterov +Reviewed-by: Kees Cook +Cc: "Christian Brauner (Microsoft)" +Cc: Eric W. Biederman +Cc: Jiri Slaby # tty/serial +Signed-off-by: Andrew Morton +Signed-off-by: Mel Gorman +--- + arch/ia64/kernel/mca.c | 4 ++-- + drivers/tty/tty_io.c | 4 ++-- + fs/fs_struct.c | 4 ++-- + include/linux/sched/signal.h | 7 ------- + 4 files changed, 6 insertions(+), 13 deletions(-) + +diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c +index 92ede80d17fe..2671688d349a 100644 +--- a/arch/ia64/kernel/mca.c ++++ b/arch/ia64/kernel/mca.c +@@ -1630,10 +1630,10 @@ default_monarch_init_process(struct notifier_block *self, unsigned long val, voi + } + printk("\n\n"); + if (read_trylock(&tasklist_lock)) { +- do_each_thread (g, t) { ++ for_each_process_thread(g, t) { + printk("\nBacktrace of pid %d (%s)\n", t->pid, t->comm); + show_stack(t, NULL, KERN_DEFAULT); +- } while_each_thread (g, t); ++ } + read_unlock(&tasklist_lock); + } + /* FIXME: This will not restore zapped printk locks. */ +diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c +index 68795761b76e..0b7dc62a32c8 100644 +--- a/drivers/tty/tty_io.c ++++ b/drivers/tty/tty_io.c +@@ -3021,7 +3021,7 @@ void __do_SAK(struct tty_struct *tty) + } while_each_pid_task(session, PIDTYPE_SID, p); + + /* Now kill any processes that happen to have the tty open */ +- do_each_thread(g, p) { ++ for_each_process_thread(g, p) { + if (p->signal->tty == tty) { + tty_notice(tty, "SAK: killed process %d (%s): by controlling tty\n", + task_pid_nr(p), p->comm); +@@ -3038,7 +3038,7 @@ void __do_SAK(struct tty_struct *tty) + PIDTYPE_SID); + } + task_unlock(p); +- } while_each_thread(g, p); ++ } + read_unlock(&tasklist_lock); + put_pid(session); + } +diff --git a/fs/fs_struct.c b/fs/fs_struct.c +index 04b3f5b9c629..64c2d0814ed6 100644 +--- a/fs/fs_struct.c ++++ b/fs/fs_struct.c +@@ -62,7 +62,7 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root) + int count = 0; + + read_lock(&tasklist_lock); +- do_each_thread(g, p) { ++ for_each_process_thread(g, p) { + task_lock(p); + fs = p->fs; + if (fs) { +@@ -79,7 +79,7 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root) + spin_unlock(&fs->lock); + } + task_unlock(p); +- } while_each_thread(g, p); ++ } + read_unlock(&tasklist_lock); + while (count--) + path_put(old_root); +diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h +index ef20447727c1..70e589cf1b01 100644 +--- a/include/linux/sched/signal.h ++++ b/include/linux/sched/signal.h +@@ -649,13 +649,6 @@ extern void flush_itimer_signals(void); + + extern bool current_is_single_threaded(void); + +-/* +- * Careful: do_each_thread/while_each_thread is a double loop so +- * 'break' will not work as expected - use goto instead. +- */ +-#define do_each_thread(g, t) \ +- for (g = t = &init_task ; (g = t = next_task(g)) != &init_task ; ) do +- + #define while_each_thread(g, t) \ + while ((t = next_thread(t)) != g) + diff --git a/patches.suse/lockdep-Add-lock_set_cmp_fn-annotation.patch b/patches.suse/lockdep-Add-lock_set_cmp_fn-annotation.patch new file mode 100644 index 0000000..6501f28 --- /dev/null +++ b/patches.suse/lockdep-Add-lock_set_cmp_fn-annotation.patch @@ -0,0 +1,434 @@ +From 7665eac2404ef2a2a1846af04b4cd347fdf9999c Mon Sep 17 00:00:00 2001 +From: Kent Overstreet +Date: Tue, 9 May 2023 15:58:46 -0400 +Subject: [PATCH] lockdep: Add lock_set_cmp_fn() annotation + +References: bsc#1214683 (PREEMPT_RT prerequisite backports) +Patch-mainline: v6.5-rc1 +Git-commit: eb1cfd09f788e39948a82be8063e54e40dd018d9 + +This implements a new interface to lockdep, lock_set_cmp_fn(), for +defining a custom ordering when taking multiple locks of the same +class. + +This is an alternative to subclasses, but can not fully replace them +since subclasses allow lock hierarchies with other clasees +inter-twined, while this relies on pure class nesting. + +Specifically, if A is our nesting class then: + + A/0 <- B <- A/1 + +Would be a valid lock order with subclasses (each subclass really is a +full class from the validation PoV) but not with this annotation, +which requires all nesting to be consecutive. + +Example output: + +| ============================================ +| WARNING: possible recursive locking detected +| 6.2.0-rc8-00003-g7d81e591ca6a-dirty #15 Not tainted +| -------------------------------------------- +| kworker/14:3/938 is trying to acquire lock: +| ffff8880143218c8 (&b->lock l=0 0:2803368){++++}-{3:3}, at: bch_btree_node_get.part.0+0x81/0x2b0 +| +| but task is already holding lock: +| ffff8880143de8c8 (&b->lock l=1 1048575:9223372036854775807){++++}-{3:3}, at: __bch_btree_map_nodes+0xea/0x1e0 +| and the lock comparison function returns 1: +| +| other info that might help us debug this: +| Possible unsafe locking scenario: +| +| CPU0 +| ---- +| lock(&b->lock l=1 1048575:9223372036854775807); +| lock(&b->lock l=0 0:2803368); +| +| *** DEADLOCK *** +| +| May be due to missing lock nesting notation +| +| 3 locks held by kworker/14:3/938: +| #0: ffff888005ea9d38 ((wq_completion)bcache){+.+.}-{0:0}, at: process_one_work+0x1ec/0x530 +| #1: ffff8880098c3e70 ((work_completion)(&cl->work)#3){+.+.}-{0:0}, at: process_one_work+0x1ec/0x530 +| #2: ffff8880143de8c8 (&b->lock l=1 1048575:9223372036854775807){++++}-{3:3}, at: __bch_btree_map_nodes+0xea/0x1e0 + +[peterz: extended changelog] +Signed-off-by: Kent Overstreet +Signed-off-by: Peter Zijlstra (Intel) +Link: https://lkml.kernel.org/r/20230509195847.1745548-1-kent.overstreet@linux.dev +Signed-off-by: Mel Gorman +--- + include/linux/lockdep.h | 8 +++ + include/linux/lockdep_types.h | 8 +++ + kernel/locking/lockdep.c | 118 +++++++++++++++++++++++++++++++----------- + 3 files changed, 103 insertions(+), 31 deletions(-) + +diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h +index 6f1210708fbd..dc2844b071c2 100644 +--- a/include/linux/lockdep.h ++++ b/include/linux/lockdep.h +@@ -447,6 +447,14 @@ extern int lockdep_is_held(const void *); + + #endif /* !LOCKDEP */ + ++#ifdef CONFIG_PROVE_LOCKING ++void lockdep_set_lock_cmp_fn(struct lockdep_map *, lock_cmp_fn, lock_print_fn); ++ ++#define lock_set_cmp_fn(lock, ...) lockdep_set_lock_cmp_fn(&(lock)->dep_map, __VA_ARGS__) ++#else ++#define lock_set_cmp_fn(lock, ...) do { } while (0) ++#endif ++ + enum xhlock_context_t { + XHLOCK_HARD, + XHLOCK_SOFT, +diff --git a/include/linux/lockdep_types.h b/include/linux/lockdep_types.h +index 59f4fb1626ea..2ebc323d345a 100644 +--- a/include/linux/lockdep_types.h ++++ b/include/linux/lockdep_types.h +@@ -85,6 +85,11 @@ struct lock_trace; + + #define LOCKSTAT_POINTS 4 + ++struct lockdep_map; ++typedef int (*lock_cmp_fn)(const struct lockdep_map *a, ++ const struct lockdep_map *b); ++typedef void (*lock_print_fn)(const struct lockdep_map *map); ++ + /* + * The lock-class itself. The order of the structure members matters. + * reinit_class() zeroes the key member and all subsequent members. +@@ -110,6 +115,9 @@ struct lock_class { + struct list_head locks_after, locks_before; + + const struct lockdep_subclass_key *key; ++ lock_cmp_fn cmp_fn; ++ lock_print_fn print_fn; ++ + unsigned int subclass; + unsigned int dep_gen_id; + +diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c +index d04d0f888231..151bd3de5936 100644 +--- a/kernel/locking/lockdep.c ++++ b/kernel/locking/lockdep.c +@@ -709,7 +709,7 @@ void get_usage_chars(struct lock_class *class, char usage[LOCK_USAGE_CHARS]) + usage[i] = '\0'; + } + +-static void __print_lock_name(struct lock_class *class) ++static void __print_lock_name(struct held_lock *hlock, struct lock_class *class) + { + char str[KSYM_NAME_LEN]; + const char *name; +@@ -724,17 +724,19 @@ static void __print_lock_name(struct lock_class *class) + printk(KERN_CONT "#%d", class->name_version); + if (class->subclass) + printk(KERN_CONT "/%d", class->subclass); ++ if (hlock && class->print_fn) ++ class->print_fn(hlock->instance); + } + } + +-static void print_lock_name(struct lock_class *class) ++static void print_lock_name(struct held_lock *hlock, struct lock_class *class) + { + char usage[LOCK_USAGE_CHARS]; + + get_usage_chars(class, usage); + + printk(KERN_CONT " ("); +- __print_lock_name(class); ++ __print_lock_name(hlock, class); + printk(KERN_CONT "){%s}-{%d:%d}", usage, + class->wait_type_outer ?: class->wait_type_inner, + class->wait_type_inner); +@@ -772,7 +774,7 @@ static void print_lock(struct held_lock *hlock) + } + + printk(KERN_CONT "%px", hlock->instance); +- print_lock_name(lock); ++ print_lock_name(hlock, lock); + printk(KERN_CONT ", at: %pS\n", (void *)hlock->acquire_ip); + } + +@@ -1860,7 +1862,7 @@ print_circular_bug_entry(struct lock_list *target, int depth) + if (debug_locks_silent) + return; + printk("\n-> #%u", depth); +- print_lock_name(target->class); ++ print_lock_name(NULL, target->class); + printk(KERN_CONT ":\n"); + print_lock_trace(target->trace, 6); + } +@@ -1891,11 +1893,11 @@ print_circular_lock_scenario(struct held_lock *src, + */ + if (parent != source) { + printk("Chain exists of:\n "); +- __print_lock_name(source); ++ __print_lock_name(src, source); + printk(KERN_CONT " --> "); +- __print_lock_name(parent); ++ __print_lock_name(NULL, parent); + printk(KERN_CONT " --> "); +- __print_lock_name(target); ++ __print_lock_name(tgt, target); + printk(KERN_CONT "\n\n"); + } + +@@ -1906,13 +1908,13 @@ print_circular_lock_scenario(struct held_lock *src, + printk(" rlock("); + else + printk(" lock("); +- __print_lock_name(target); ++ __print_lock_name(tgt, target); + printk(KERN_CONT ");\n"); + printk(" lock("); +- __print_lock_name(parent); ++ __print_lock_name(NULL, parent); + printk(KERN_CONT ");\n"); + printk(" lock("); +- __print_lock_name(target); ++ __print_lock_name(tgt, target); + printk(KERN_CONT ");\n"); + if (src_read != 0) + printk(" rlock("); +@@ -1920,7 +1922,7 @@ print_circular_lock_scenario(struct held_lock *src, + printk(" sync("); + else + printk(" lock("); +- __print_lock_name(source); ++ __print_lock_name(src, source); + printk(KERN_CONT ");\n"); + printk("\n *** DEADLOCK ***\n\n"); + } +@@ -2146,6 +2148,8 @@ check_path(struct held_lock *target, struct lock_list *src_entry, + return ret; + } + ++static void print_deadlock_bug(struct task_struct *, struct held_lock *, struct held_lock *); ++ + /* + * Prove that the dependency graph starting at can not + * lead to . If it can, there is a circle when adding +@@ -2177,7 +2181,10 @@ check_noncircular(struct held_lock *src, struct held_lock *target, + *trace = save_trace(); + } + +- print_circular_bug(&src_entry, target_entry, src, target); ++ if (src->class_idx == target->class_idx) ++ print_deadlock_bug(current, src, target); ++ else ++ print_circular_bug(&src_entry, target_entry, src, target); + } + + return ret; +@@ -2338,7 +2345,7 @@ static void print_lock_class_header(struct lock_class *class, int depth) + int bit; + + printk("%*s->", depth, ""); +- print_lock_name(class); ++ print_lock_name(NULL, class); + #ifdef CONFIG_DEBUG_LOCKDEP + printk(KERN_CONT " ops: %lu", debug_class_ops_read(class)); + #endif +@@ -2520,11 +2527,11 @@ print_irq_lock_scenario(struct lock_list *safe_entry, + */ + if (middle_class != unsafe_class) { + printk("Chain exists of:\n "); +- __print_lock_name(safe_class); ++ __print_lock_name(NULL, safe_class); + printk(KERN_CONT " --> "); +- __print_lock_name(middle_class); ++ __print_lock_name(NULL, middle_class); + printk(KERN_CONT " --> "); +- __print_lock_name(unsafe_class); ++ __print_lock_name(NULL, unsafe_class); + printk(KERN_CONT "\n\n"); + } + +@@ -2532,18 +2539,18 @@ print_irq_lock_scenario(struct lock_list *safe_entry, + printk(" CPU0 CPU1\n"); + printk(" ---- ----\n"); + printk(" lock("); +- __print_lock_name(unsafe_class); ++ __print_lock_name(NULL, unsafe_class); + printk(KERN_CONT ");\n"); + printk(" local_irq_disable();\n"); + printk(" lock("); +- __print_lock_name(safe_class); ++ __print_lock_name(NULL, safe_class); + printk(KERN_CONT ");\n"); + printk(" lock("); +- __print_lock_name(middle_class); ++ __print_lock_name(NULL, middle_class); + printk(KERN_CONT ");\n"); + printk(" \n"); + printk(" lock("); +- __print_lock_name(safe_class); ++ __print_lock_name(NULL, safe_class); + printk(KERN_CONT ");\n"); + printk("\n *** DEADLOCK ***\n\n"); + } +@@ -2580,20 +2587,20 @@ print_bad_irq_dependency(struct task_struct *curr, + pr_warn("\nand this task is already holding:\n"); + print_lock(prev); + pr_warn("which would create a new lock dependency:\n"); +- print_lock_name(hlock_class(prev)); ++ print_lock_name(prev, hlock_class(prev)); + pr_cont(" ->"); +- print_lock_name(hlock_class(next)); ++ print_lock_name(next, hlock_class(next)); + pr_cont("\n"); + + pr_warn("\nbut this new dependency connects a %s-irq-safe lock:\n", + irqclass); +- print_lock_name(backwards_entry->class); ++ print_lock_name(NULL, backwards_entry->class); + pr_warn("\n... which became %s-irq-safe at:\n", irqclass); + + print_lock_trace(backwards_entry->class->usage_traces[bit1], 1); + + pr_warn("\nto a %s-irq-unsafe lock:\n", irqclass); +- print_lock_name(forwards_entry->class); ++ print_lock_name(NULL, forwards_entry->class); + pr_warn("\n... which became %s-irq-unsafe at:\n", irqclass); + pr_warn("..."); + +@@ -2963,10 +2970,10 @@ print_deadlock_scenario(struct held_lock *nxt, struct held_lock *prv) + printk(" CPU0\n"); + printk(" ----\n"); + printk(" lock("); +- __print_lock_name(prev); ++ __print_lock_name(prv, prev); + printk(KERN_CONT ");\n"); + printk(" lock("); +- __print_lock_name(next); ++ __print_lock_name(nxt, next); + printk(KERN_CONT ");\n"); + printk("\n *** DEADLOCK ***\n\n"); + printk(" May be due to missing lock nesting notation\n\n"); +@@ -2976,6 +2983,8 @@ static void + print_deadlock_bug(struct task_struct *curr, struct held_lock *prev, + struct held_lock *next) + { ++ struct lock_class *class = hlock_class(prev); ++ + if (!debug_locks_off_graph_unlock() || debug_locks_silent) + return; + +@@ -2990,6 +2999,11 @@ print_deadlock_bug(struct task_struct *curr, struct held_lock *prev, + pr_warn("\nbut task is already holding lock:\n"); + print_lock(prev); + ++ if (class->cmp_fn) { ++ pr_warn("and the lock comparison function returns %i:\n", ++ class->cmp_fn(prev->instance, next->instance)); ++ } ++ + pr_warn("\nother info that might help us debug this:\n"); + print_deadlock_scenario(next, prev); + lockdep_print_held_locks(curr); +@@ -3011,6 +3025,7 @@ print_deadlock_bug(struct task_struct *curr, struct held_lock *prev, + static int + check_deadlock(struct task_struct *curr, struct held_lock *next) + { ++ struct lock_class *class; + struct held_lock *prev; + struct held_lock *nest = NULL; + int i; +@@ -3031,6 +3046,12 @@ check_deadlock(struct task_struct *curr, struct held_lock *next) + if ((next->read == 2) && prev->read) + continue; + ++ class = hlock_class(prev); ++ ++ if (class->cmp_fn && ++ class->cmp_fn(prev->instance, next->instance) < 0) ++ continue; ++ + /* + * We're holding the nest_lock, which serializes this lock's + * nesting behaviour. +@@ -3092,6 +3113,14 @@ check_prev_add(struct task_struct *curr, struct held_lock *prev, + return 2; + } + ++ if (prev->class_idx == next->class_idx) { ++ struct lock_class *class = hlock_class(prev); ++ ++ if (class->cmp_fn && ++ class->cmp_fn(prev->instance, next->instance) < 0) ++ return 2; ++ } ++ + /* + * Prove that the new -> dependency would not + * create a circular dependency in the graph. (We do this by +@@ -3569,7 +3598,7 @@ static void print_chain_keys_chain(struct lock_chain *chain) + hlock_id = chain_hlocks[chain->base + i]; + chain_key = print_chain_key_iteration(hlock_id, chain_key); + +- print_lock_name(lock_classes + chain_hlock_class_idx(hlock_id)); ++ print_lock_name(NULL, lock_classes + chain_hlock_class_idx(hlock_id)); + printk("\n"); + } + } +@@ -3926,11 +3955,11 @@ static void print_usage_bug_scenario(struct held_lock *lock) + printk(" CPU0\n"); + printk(" ----\n"); + printk(" lock("); +- __print_lock_name(class); ++ __print_lock_name(lock, class); + printk(KERN_CONT ");\n"); + printk(" \n"); + printk(" lock("); +- __print_lock_name(class); ++ __print_lock_name(lock, class); + printk(KERN_CONT ");\n"); + printk("\n *** DEADLOCK ***\n\n"); + } +@@ -4016,7 +4045,7 @@ print_irq_inversion_bug(struct task_struct *curr, + pr_warn("but this lock took another, %s-unsafe lock in the past:\n", irqclass); + else + pr_warn("but this lock was taken by another, %s-safe lock in the past:\n", irqclass); +- print_lock_name(other->class); ++ print_lock_name(NULL, other->class); + pr_warn("\n\nand interrupts could create inverse lock ordering between them.\n\n"); + + pr_warn("\nother info that might help us debug this:\n"); +@@ -4889,6 +4918,33 @@ EXPORT_SYMBOL_GPL(lockdep_init_map_type); + struct lock_class_key __lockdep_no_validate__; + EXPORT_SYMBOL_GPL(__lockdep_no_validate__); + ++#ifdef CONFIG_PROVE_LOCKING ++void lockdep_set_lock_cmp_fn(struct lockdep_map *lock, lock_cmp_fn cmp_fn, ++ lock_print_fn print_fn) ++{ ++ struct lock_class *class = lock->class_cache[0]; ++ unsigned long flags; ++ ++ raw_local_irq_save(flags); ++ lockdep_recursion_inc(); ++ ++ if (!class) ++ class = register_lock_class(lock, 0, 0); ++ ++ if (class) { ++ WARN_ON(class->cmp_fn && class->cmp_fn != cmp_fn); ++ WARN_ON(class->print_fn && class->print_fn != print_fn); ++ ++ class->cmp_fn = cmp_fn; ++ class->print_fn = print_fn; ++ } ++ ++ lockdep_recursion_finish(); ++ raw_local_irq_restore(flags); ++} ++EXPORT_SYMBOL_GPL(lockdep_set_lock_cmp_fn); ++#endif ++ + static void + print_lock_nested_lock_not_held(struct task_struct *curr, + struct held_lock *hlock) diff --git a/patches.suse/printk-Update-the-printk-series.patch b/patches.suse/printk-Update-the-printk-series.patch index 4887cb3..09d4018 100644 --- a/patches.suse/printk-Update-the-printk-series.patch +++ b/patches.suse/printk-Update-the-printk-series.patch @@ -1,14 +1,8 @@ -From 03b915f9ccbae411d862efbd74cf06f42f81a4ef Mon Sep 17 00:00:00 2001 +From 9da8b7d35670214ab5b90335ecbaae09cd6b301f Mon Sep 17 00:00:00 2001 From: Mel Gorman Date: Thu, 21 Mar 2024 12:04:09 +0000 Subject: [PATCH] printk: Update the printk series. -From 0c6e53883469d33bf8124250678eb5c2d64edca3 Mon Sep 17 00:00:00 2001 - -From 4869aab120ece7fde4b7dc442a1b326ab2b68585 Mon Sep 17 00:00:00 2001 - -From 7e82d0c17ecd3ff8f63a4e0a8a21144a204de534 Mon Sep 17 00:00:00 2001 - References: bsc#1214683 (PREEMPT_RT prerequisite backports) Git-commit: da042bbb7a3ffcb2d18fc69e01f8a2f1ff0f0aab Patch-mainline: v6.6.20 @@ -96,15 +90,15 @@ Signed-off-by: Mel Gorman drivers/tty/serial/ucc_uart.c | 5 +- drivers/tty/serial/vt8500_serial.c | 14 +- drivers/tty/serial/xilinx_uartps.c | 60 +- - drivers/tty/tty.h | 15 +- - drivers/tty/tty_audit.c | 45 +- - drivers/tty/tty_io.c | 91 +- + drivers/tty/tty.h | 13 +- + drivers/tty/tty_audit.c | 7 +- + drivers/tty/tty_io.c | 6 +- fs/proc/consoles.c | 6 +- include/linux/console.h | 235 ++-- include/linux/printk.h | 29 +- include/linux/serial_8250.h | 9 +- include/linux/serial_core.h | 97 +- - kernel/locking/lockdep.c | 123 +- + kernel/locking/lockdep.c | 5 + kernel/panic.c | 33 +- kernel/printk/Makefile | 2 +- kernel/printk/internal.h | 164 +-- @@ -115,7 +109,7 @@ Signed-off-by: Mel Gorman kernel/printk/printk_ringbuffer.h | 54 +- kernel/printk/printk_safe.c | 31 +- kernel/rcu/tree_stall.h | 5 +- - 94 files changed, 4992 insertions(+), 4840 deletions(-) + 94 files changed, 4843 insertions(+), 4746 deletions(-) diff --git a/drivers/tty/serial/21285.c b/drivers/tty/serial/21285.c index d756fcc884cb..4de0c975ebdc 100644 @@ -12106,18 +12100,9 @@ index 20a751663ef9..9c13dac1d4d1 100644 } diff --git a/drivers/tty/tty.h b/drivers/tty/tty.h -index 1e0d80e98d26..50862f98273e 100644 +index db7f3f87772f..50862f98273e 100644 --- a/drivers/tty/tty.h +++ b/drivers/tty/tty.h -@@ -63,7 +63,7 @@ int tty_check_change(struct tty_struct *tty); - void __stop_tty(struct tty_struct *tty); - void __start_tty(struct tty_struct *tty); - void tty_write_unlock(struct tty_struct *tty); --int tty_write_lock(struct tty_struct *tty, int ndelay); -+int tty_write_lock(struct tty_struct *tty, bool ndelay); - void tty_vhangup_session(struct tty_struct *tty); - void tty_open_proc_set_tty(struct file *filp, struct tty_struct *tty); - int tty_signal_session_leader(struct tty_struct *tty, int exit_session); @@ -99,14 +99,15 @@ extern int tty_ldisc_autoload; /* tty_audit.c */ @@ -12148,83 +12133,18 @@ index 1e0d80e98d26..50862f98273e 100644 #endif diff --git a/drivers/tty/tty_audit.c b/drivers/tty/tty_audit.c -index ca7afd7b2716..1d81eeefb068 100644 +index 3a50236f7e5e..67dc317161c8 100644 --- a/drivers/tty/tty_audit.c +++ b/drivers/tty/tty_audit.c -@@ -15,9 +15,9 @@ - struct tty_audit_buf { - struct mutex mutex; /* Protects all data below */ +@@ -17,7 +17,7 @@ struct tty_audit_buf { dev_t dev; /* The TTY which the data is from */ -- unsigned icanon:1; -+ bool icanon; + bool icanon; size_t valid; - unsigned char *data; /* Allocated size N_TTY_BUF_SIZE */ + u8 *data; /* Allocated size N_TTY_BUF_SIZE */ }; static struct tty_audit_buf *tty_audit_buf_ref(void) -@@ -33,16 +33,16 @@ static struct tty_audit_buf *tty_audit_buf_alloc(void) - { - struct tty_audit_buf *buf; - -- buf = kmalloc(sizeof(*buf), GFP_KERNEL); -+ buf = kzalloc(sizeof(*buf), GFP_KERNEL); - if (!buf) - goto err; -+ - buf->data = kmalloc(N_TTY_BUF_SIZE, GFP_KERNEL); - if (!buf->data) - goto err_buf; -+ - mutex_init(&buf->mutex); -- buf->dev = MKDEV(0, 0); -- buf->icanon = 0; -- buf->valid = 0; -+ - return buf; - - err_buf: -@@ -59,27 +59,27 @@ static void tty_audit_buf_free(struct tty_audit_buf *buf) - } - - static void tty_audit_log(const char *description, dev_t dev, -- unsigned char *data, size_t size) -+ const u8 *data, size_t size) - { - struct audit_buffer *ab; - pid_t pid = task_pid_nr(current); - uid_t uid = from_kuid(&init_user_ns, task_uid(current)); - uid_t loginuid = from_kuid(&init_user_ns, audit_get_loginuid(current)); - unsigned int sessionid = audit_get_sessionid(current); -+ char name[TASK_COMM_LEN]; - - ab = audit_log_start(audit_context(), GFP_KERNEL, AUDIT_TTY); -- if (ab) { -- char name[sizeof(current->comm)]; -- -- audit_log_format(ab, "%s pid=%u uid=%u auid=%u ses=%u major=%d" -- " minor=%d comm=", description, pid, uid, -- loginuid, sessionid, MAJOR(dev), MINOR(dev)); -- get_task_comm(name, current); -- audit_log_untrustedstring(ab, name); -- audit_log_format(ab, " data="); -- audit_log_n_hex(ab, data, size); -- audit_log_end(ab); -- } -+ if (!ab) -+ return; -+ -+ audit_log_format(ab, "%s pid=%u uid=%u auid=%u ses=%u major=%d minor=%d comm=", -+ description, pid, uid, loginuid, sessionid, -+ MAJOR(dev), MINOR(dev)); -+ get_task_comm(name, current); -+ audit_log_untrustedstring(ab, name); -+ audit_log_format(ab, " data="); -+ audit_log_n_hex(ab, data, size); -+ audit_log_end(ab); - } - - /* @@ -134,7 +134,7 @@ void tty_audit_fork(struct signal_struct *sig) /* * tty_audit_tiocsti - Log TIOCSTI @@ -12234,7 +12154,7 @@ index ca7afd7b2716..1d81eeefb068 100644 { dev_t dev; -@@ -199,11 +199,12 @@ static struct tty_audit_buf *tty_audit_buf_get(void) +@@ -199,7 +199,8 @@ static struct tty_audit_buf *tty_audit_buf_get(void) * * Audit @data of @size from @tty, if necessary. */ @@ -12243,241 +12163,12 @@ index ca7afd7b2716..1d81eeefb068 100644 + size_t size) { struct tty_audit_buf *buf; -- unsigned int icanon = !!L_ICANON(tty); unsigned int audit_tty; -+ bool icanon = L_ICANON(tty); - dev_t dev; - - audit_tty = READ_ONCE(current->signal->audit_tty); diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c -index c80b3ac4196e..383159639f65 100644 +index 0b7dc62a32c8..383159639f65 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c -@@ -101,6 +101,7 @@ - #include - #include - #include -+#include - - #include - #include -@@ -269,7 +270,7 @@ static int tty_paranoia_check(struct tty_struct *tty, struct inode *inode, - } - - /* Caller must hold tty_lock */ --static int check_tty_count(struct tty_struct *tty, const char *routine) -+static void check_tty_count(struct tty_struct *tty, const char *routine) - { - #ifdef CHECK_TTY_COUNT - struct list_head *p; -@@ -289,10 +290,8 @@ static int check_tty_count(struct tty_struct *tty, const char *routine) - if (tty->count != (count + kopen_count)) { - tty_warn(tty, "%s: tty->count(%d) != (#fd's(%d) + #kopen's(%d))\n", - routine, tty->count, count, kopen_count); -- return (count + kopen_count); - } - #endif -- return 0; - } - - /** -@@ -811,18 +810,26 @@ void start_tty(struct tty_struct *tty) - } - EXPORT_SYMBOL(start_tty); - --static void tty_update_time(struct timespec64 *time) -+static void tty_update_time(struct tty_struct *tty, bool mtime) - { - time64_t sec = ktime_get_real_seconds(); -+ struct tty_file_private *priv; - -- /* -- * We only care if the two values differ in anything other than the -- * lower three bits (i.e every 8 seconds). If so, then we can update -- * the time of the tty device, otherwise it could be construded as a -- * security leak to let userspace know the exact timing of the tty. -- */ -- if ((sec ^ time->tv_sec) & ~7) -- time->tv_sec = sec; -+ spin_lock(&tty->files_lock); -+ list_for_each_entry(priv, &tty->tty_files, list) { -+ struct inode *inode = file_inode(priv->file); -+ struct timespec64 *time = mtime ? &inode->i_mtime : &inode->i_atime; -+ -+ /* -+ * We only care if the two values differ in anything other than the -+ * lower three bits (i.e every 8 seconds). If so, then we can update -+ * the time of the tty device, otherwise it could be construded as a -+ * security leak to let userspace know the exact timing of the tty. -+ */ -+ if ((sec ^ time->tv_sec) & ~7) -+ time->tv_sec = sec; -+ } -+ spin_unlock(&tty->files_lock); - } - - /* -@@ -836,19 +843,18 @@ static void tty_update_time(struct timespec64 *time) - * data or clears the cookie. The cookie may be something that the - * ldisc maintains state for and needs to free. - */ --static int iterate_tty_read(struct tty_ldisc *ld, struct tty_struct *tty, -- struct file *file, struct iov_iter *to) -+static ssize_t iterate_tty_read(struct tty_ldisc *ld, struct tty_struct *tty, -+ struct file *file, struct iov_iter *to) - { -- int retval = 0; - void *cookie = NULL; - unsigned long offset = 0; - char kernel_buf[64]; -- size_t count = iov_iter_count(to); -+ ssize_t retval = 0; -+ size_t copied, count = iov_iter_count(to); - - do { -- int size, copied; -+ ssize_t size = min(count, sizeof(kernel_buf)); - -- size = count > sizeof(kernel_buf) ? sizeof(kernel_buf) : count; - size = ld->ops->read(tty, file, kernel_buf, size, &cookie, offset); - if (!size) - break; -@@ -905,11 +911,11 @@ static int iterate_tty_read(struct tty_ldisc *ld, struct tty_struct *tty, - */ - static ssize_t tty_read(struct kiocb *iocb, struct iov_iter *to) - { -- int i; - struct file *file = iocb->ki_filp; - struct inode *inode = file_inode(file); - struct tty_struct *tty = file_tty(file); - struct tty_ldisc *ld; -+ ssize_t ret; - - if (tty_paranoia_check(tty, inode, "tty_read")) - return -EIO; -@@ -922,15 +928,15 @@ static ssize_t tty_read(struct kiocb *iocb, struct iov_iter *to) - ld = tty_ldisc_ref_wait(tty); - if (!ld) - return hung_up_tty_read(iocb, to); -- i = -EIO; -+ ret = -EIO; - if (ld->ops->read) -- i = iterate_tty_read(ld, tty, file, to); -+ ret = iterate_tty_read(ld, tty, file, to); - tty_ldisc_deref(ld); - -- if (i > 0) -- tty_update_time(&inode->i_atime); -+ if (ret > 0) -+ tty_update_time(tty, false); - -- return i; -+ return ret; - } - - void tty_write_unlock(struct tty_struct *tty) -@@ -939,7 +945,7 @@ void tty_write_unlock(struct tty_struct *tty) - wake_up_interruptible_poll(&tty->write_wait, EPOLLOUT); - } - --int tty_write_lock(struct tty_struct *tty, int ndelay) -+int tty_write_lock(struct tty_struct *tty, bool ndelay) - { - if (!mutex_trylock(&tty->atomic_write_lock)) { - if (ndelay) -@@ -954,15 +960,11 @@ int tty_write_lock(struct tty_struct *tty, int ndelay) - * Split writes up in sane blocksizes to avoid - * denial-of-service type attacks - */ --static inline ssize_t do_tty_write( -- ssize_t (*write)(struct tty_struct *, struct file *, const unsigned char *, size_t), -- struct tty_struct *tty, -- struct file *file, -- struct iov_iter *from) -+static ssize_t iterate_tty_write(struct tty_ldisc *ld, struct tty_struct *tty, -+ struct file *file, struct iov_iter *from) - { -- size_t count = iov_iter_count(from); -+ size_t chunk, count = iov_iter_count(from); - ssize_t ret, written = 0; -- unsigned int chunk; - - ret = tty_write_lock(tty, file->f_flags & O_NDELAY); - if (ret < 0) -@@ -1006,16 +1008,13 @@ static inline ssize_t do_tty_write( - - /* Do the write .. */ - for (;;) { -- size_t size = count; -- -- if (size > chunk) -- size = chunk; -+ size_t size = min(chunk, count); - - ret = -EFAULT; - if (copy_from_iter(tty->write_buf, size, from) != size) - break; - -- ret = write(tty, file, tty->write_buf, size); -+ ret = ld->ops->write(tty, file, tty->write_buf, size); - if (ret <= 0) - break; - -@@ -1036,7 +1035,7 @@ static inline ssize_t do_tty_write( - cond_resched(); - } - if (written) { -- tty_update_time(&file_inode(file)->i_mtime); -+ tty_update_time(tty, true); - ret = written; - } - out: -@@ -1086,7 +1085,7 @@ static ssize_t file_tty_write(struct file *file, struct kiocb *iocb, struct iov_ - if (!ld->ops->write) - ret = -EIO; - else -- ret = do_tty_write(ld->ops->write, tty, file, from); -+ ret = iterate_tty_write(ld, tty, file, from); - tty_ldisc_deref(ld); - return ret; - } -@@ -1153,7 +1152,7 @@ int tty_send_xchar(struct tty_struct *tty, char ch) - return 0; - } - -- if (tty_write_lock(tty, 0) < 0) -+ if (tty_write_lock(tty, false) < 0) - return -ERESTARTSYS; - - down_read(&tty->termios_rwsem); -@@ -2479,7 +2478,7 @@ static int send_break(struct tty_struct *tty, unsigned int duration) - retval = tty->ops->break_ctl(tty, duration); - else { - /* Do the work ourselves */ -- if (tty_write_lock(tty, 0) < 0) -+ if (tty_write_lock(tty, false) < 0) - return -EINTR; - retval = tty->ops->break_ctl(tty, -1); - if (retval) -@@ -3022,7 +3021,7 @@ void __do_SAK(struct tty_struct *tty) - } while_each_pid_task(session, PIDTYPE_SID, p); - - /* Now kill any processes that happen to have the tty open */ -- do_each_thread(g, p) { -+ for_each_process_thread(g, p) { - if (p->signal->tty == tty) { - tty_notice(tty, "SAK: killed process %d (%s): by controlling tty\n", - task_pid_nr(p), p->comm); -@@ -3039,7 +3038,7 @@ void __do_SAK(struct tty_struct *tty) - PIDTYPE_SID); - } - task_unlock(p); -- } while_each_thread(g, p); -+ } - read_unlock(&tasklist_lock); - put_pid(session); - } -@@ -3541,9 +3540,11 @@ static ssize_t show_cons_active(struct device *dev, +@@ -3540,9 +3540,11 @@ static ssize_t show_cons_active(struct device *dev, for_each_console(c) { if (!c->device) continue; @@ -13198,7 +12889,7 @@ index e9f16ec252a0..245c11753eff 100644 #endif /* CONFIG_MAGIC_SYSRQ_SERIAL */ diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c -index d04d0f888231..5c21ba41e308 100644 +index 151bd3de5936..5c21ba41e308 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -56,6 +56,7 @@ @@ -13209,283 +12900,7 @@ index d04d0f888231..5c21ba41e308 100644 #include -@@ -709,7 +710,7 @@ void get_usage_chars(struct lock_class *class, char usage[LOCK_USAGE_CHARS]) - usage[i] = '\0'; - } - --static void __print_lock_name(struct lock_class *class) -+static void __print_lock_name(struct held_lock *hlock, struct lock_class *class) - { - char str[KSYM_NAME_LEN]; - const char *name; -@@ -724,17 +725,19 @@ static void __print_lock_name(struct lock_class *class) - printk(KERN_CONT "#%d", class->name_version); - if (class->subclass) - printk(KERN_CONT "/%d", class->subclass); -+ if (hlock && class->print_fn) -+ class->print_fn(hlock->instance); - } - } - --static void print_lock_name(struct lock_class *class) -+static void print_lock_name(struct held_lock *hlock, struct lock_class *class) - { - char usage[LOCK_USAGE_CHARS]; - - get_usage_chars(class, usage); - - printk(KERN_CONT " ("); -- __print_lock_name(class); -+ __print_lock_name(hlock, class); - printk(KERN_CONT "){%s}-{%d:%d}", usage, - class->wait_type_outer ?: class->wait_type_inner, - class->wait_type_inner); -@@ -772,7 +775,7 @@ static void print_lock(struct held_lock *hlock) - } - - printk(KERN_CONT "%px", hlock->instance); -- print_lock_name(lock); -+ print_lock_name(hlock, lock); - printk(KERN_CONT ", at: %pS\n", (void *)hlock->acquire_ip); - } - -@@ -1860,7 +1863,7 @@ print_circular_bug_entry(struct lock_list *target, int depth) - if (debug_locks_silent) - return; - printk("\n-> #%u", depth); -- print_lock_name(target->class); -+ print_lock_name(NULL, target->class); - printk(KERN_CONT ":\n"); - print_lock_trace(target->trace, 6); - } -@@ -1891,11 +1894,11 @@ print_circular_lock_scenario(struct held_lock *src, - */ - if (parent != source) { - printk("Chain exists of:\n "); -- __print_lock_name(source); -+ __print_lock_name(src, source); - printk(KERN_CONT " --> "); -- __print_lock_name(parent); -+ __print_lock_name(NULL, parent); - printk(KERN_CONT " --> "); -- __print_lock_name(target); -+ __print_lock_name(tgt, target); - printk(KERN_CONT "\n\n"); - } - -@@ -1906,13 +1909,13 @@ print_circular_lock_scenario(struct held_lock *src, - printk(" rlock("); - else - printk(" lock("); -- __print_lock_name(target); -+ __print_lock_name(tgt, target); - printk(KERN_CONT ");\n"); - printk(" lock("); -- __print_lock_name(parent); -+ __print_lock_name(NULL, parent); - printk(KERN_CONT ");\n"); - printk(" lock("); -- __print_lock_name(target); -+ __print_lock_name(tgt, target); - printk(KERN_CONT ");\n"); - if (src_read != 0) - printk(" rlock("); -@@ -1920,7 +1923,7 @@ print_circular_lock_scenario(struct held_lock *src, - printk(" sync("); - else - printk(" lock("); -- __print_lock_name(source); -+ __print_lock_name(src, source); - printk(KERN_CONT ");\n"); - printk("\n *** DEADLOCK ***\n\n"); - } -@@ -2146,6 +2149,8 @@ check_path(struct held_lock *target, struct lock_list *src_entry, - return ret; - } - -+static void print_deadlock_bug(struct task_struct *, struct held_lock *, struct held_lock *); -+ - /* - * Prove that the dependency graph starting at can not - * lead to . If it can, there is a circle when adding -@@ -2177,7 +2182,10 @@ check_noncircular(struct held_lock *src, struct held_lock *target, - *trace = save_trace(); - } - -- print_circular_bug(&src_entry, target_entry, src, target); -+ if (src->class_idx == target->class_idx) -+ print_deadlock_bug(current, src, target); -+ else -+ print_circular_bug(&src_entry, target_entry, src, target); - } - - return ret; -@@ -2338,7 +2346,7 @@ static void print_lock_class_header(struct lock_class *class, int depth) - int bit; - - printk("%*s->", depth, ""); -- print_lock_name(class); -+ print_lock_name(NULL, class); - #ifdef CONFIG_DEBUG_LOCKDEP - printk(KERN_CONT " ops: %lu", debug_class_ops_read(class)); - #endif -@@ -2520,11 +2528,11 @@ print_irq_lock_scenario(struct lock_list *safe_entry, - */ - if (middle_class != unsafe_class) { - printk("Chain exists of:\n "); -- __print_lock_name(safe_class); -+ __print_lock_name(NULL, safe_class); - printk(KERN_CONT " --> "); -- __print_lock_name(middle_class); -+ __print_lock_name(NULL, middle_class); - printk(KERN_CONT " --> "); -- __print_lock_name(unsafe_class); -+ __print_lock_name(NULL, unsafe_class); - printk(KERN_CONT "\n\n"); - } - -@@ -2532,18 +2540,18 @@ print_irq_lock_scenario(struct lock_list *safe_entry, - printk(" CPU0 CPU1\n"); - printk(" ---- ----\n"); - printk(" lock("); -- __print_lock_name(unsafe_class); -+ __print_lock_name(NULL, unsafe_class); - printk(KERN_CONT ");\n"); - printk(" local_irq_disable();\n"); - printk(" lock("); -- __print_lock_name(safe_class); -+ __print_lock_name(NULL, safe_class); - printk(KERN_CONT ");\n"); - printk(" lock("); -- __print_lock_name(middle_class); -+ __print_lock_name(NULL, middle_class); - printk(KERN_CONT ");\n"); - printk(" \n"); - printk(" lock("); -- __print_lock_name(safe_class); -+ __print_lock_name(NULL, safe_class); - printk(KERN_CONT ");\n"); - printk("\n *** DEADLOCK ***\n\n"); - } -@@ -2580,20 +2588,20 @@ print_bad_irq_dependency(struct task_struct *curr, - pr_warn("\nand this task is already holding:\n"); - print_lock(prev); - pr_warn("which would create a new lock dependency:\n"); -- print_lock_name(hlock_class(prev)); -+ print_lock_name(prev, hlock_class(prev)); - pr_cont(" ->"); -- print_lock_name(hlock_class(next)); -+ print_lock_name(next, hlock_class(next)); - pr_cont("\n"); - - pr_warn("\nbut this new dependency connects a %s-irq-safe lock:\n", - irqclass); -- print_lock_name(backwards_entry->class); -+ print_lock_name(NULL, backwards_entry->class); - pr_warn("\n... which became %s-irq-safe at:\n", irqclass); - - print_lock_trace(backwards_entry->class->usage_traces[bit1], 1); - - pr_warn("\nto a %s-irq-unsafe lock:\n", irqclass); -- print_lock_name(forwards_entry->class); -+ print_lock_name(NULL, forwards_entry->class); - pr_warn("\n... which became %s-irq-unsafe at:\n", irqclass); - pr_warn("..."); - -@@ -2963,10 +2971,10 @@ print_deadlock_scenario(struct held_lock *nxt, struct held_lock *prv) - printk(" CPU0\n"); - printk(" ----\n"); - printk(" lock("); -- __print_lock_name(prev); -+ __print_lock_name(prv, prev); - printk(KERN_CONT ");\n"); - printk(" lock("); -- __print_lock_name(next); -+ __print_lock_name(nxt, next); - printk(KERN_CONT ");\n"); - printk("\n *** DEADLOCK ***\n\n"); - printk(" May be due to missing lock nesting notation\n\n"); -@@ -2976,6 +2984,8 @@ static void - print_deadlock_bug(struct task_struct *curr, struct held_lock *prev, - struct held_lock *next) - { -+ struct lock_class *class = hlock_class(prev); -+ - if (!debug_locks_off_graph_unlock() || debug_locks_silent) - return; - -@@ -2990,6 +3000,11 @@ print_deadlock_bug(struct task_struct *curr, struct held_lock *prev, - pr_warn("\nbut task is already holding lock:\n"); - print_lock(prev); - -+ if (class->cmp_fn) { -+ pr_warn("and the lock comparison function returns %i:\n", -+ class->cmp_fn(prev->instance, next->instance)); -+ } -+ - pr_warn("\nother info that might help us debug this:\n"); - print_deadlock_scenario(next, prev); - lockdep_print_held_locks(curr); -@@ -3011,6 +3026,7 @@ print_deadlock_bug(struct task_struct *curr, struct held_lock *prev, - static int - check_deadlock(struct task_struct *curr, struct held_lock *next) - { -+ struct lock_class *class; - struct held_lock *prev; - struct held_lock *nest = NULL; - int i; -@@ -3031,6 +3047,12 @@ check_deadlock(struct task_struct *curr, struct held_lock *next) - if ((next->read == 2) && prev->read) - continue; - -+ class = hlock_class(prev); -+ -+ if (class->cmp_fn && -+ class->cmp_fn(prev->instance, next->instance) < 0) -+ continue; -+ - /* - * We're holding the nest_lock, which serializes this lock's - * nesting behaviour. -@@ -3092,6 +3114,14 @@ check_prev_add(struct task_struct *curr, struct held_lock *prev, - return 2; - } - -+ if (prev->class_idx == next->class_idx) { -+ struct lock_class *class = hlock_class(prev); -+ -+ if (class->cmp_fn && -+ class->cmp_fn(prev->instance, next->instance) < 0) -+ return 2; -+ } -+ - /* - * Prove that the new -> dependency would not - * create a circular dependency in the graph. (We do this by -@@ -3569,7 +3599,7 @@ static void print_chain_keys_chain(struct lock_chain *chain) - hlock_id = chain_hlocks[chain->base + i]; - chain_key = print_chain_key_iteration(hlock_id, chain_key); - -- print_lock_name(lock_classes + chain_hlock_class_idx(hlock_id)); -+ print_lock_name(NULL, lock_classes + chain_hlock_class_idx(hlock_id)); - printk("\n"); - } - } -@@ -3926,11 +3956,11 @@ static void print_usage_bug_scenario(struct held_lock *lock) - printk(" CPU0\n"); - printk(" ----\n"); - printk(" lock("); -- __print_lock_name(class); -+ __print_lock_name(lock, class); - printk(KERN_CONT ");\n"); - printk(" \n"); - printk(" lock("); -- __print_lock_name(class); -+ __print_lock_name(lock, class); - printk(KERN_CONT ");\n"); - printk("\n *** DEADLOCK ***\n\n"); - } -@@ -3942,6 +3972,8 @@ print_usage_bug(struct task_struct *curr, struct held_lock *this, +@@ -3971,6 +3972,8 @@ print_usage_bug(struct task_struct *curr, struct held_lock *this, if (!debug_locks_off() || debug_locks_silent) return; @@ -13494,7 +12909,7 @@ index d04d0f888231..5c21ba41e308 100644 pr_warn("\n"); pr_warn("================================\n"); pr_warn("WARNING: inconsistent lock state\n"); -@@ -3970,6 +4002,8 @@ print_usage_bug(struct task_struct *curr, struct held_lock *this, +@@ -3999,6 +4002,8 @@ print_usage_bug(struct task_struct *curr, struct held_lock *this, pr_warn("\nstack backtrace:\n"); dump_stack(); @@ -13503,49 +12918,6 @@ index d04d0f888231..5c21ba41e308 100644 } /* -@@ -4016,7 +4050,7 @@ print_irq_inversion_bug(struct task_struct *curr, - pr_warn("but this lock took another, %s-unsafe lock in the past:\n", irqclass); - else - pr_warn("but this lock was taken by another, %s-safe lock in the past:\n", irqclass); -- print_lock_name(other->class); -+ print_lock_name(NULL, other->class); - pr_warn("\n\nand interrupts could create inverse lock ordering between them.\n\n"); - - pr_warn("\nother info that might help us debug this:\n"); -@@ -4889,6 +4923,33 @@ EXPORT_SYMBOL_GPL(lockdep_init_map_type); - struct lock_class_key __lockdep_no_validate__; - EXPORT_SYMBOL_GPL(__lockdep_no_validate__); - -+#ifdef CONFIG_PROVE_LOCKING -+void lockdep_set_lock_cmp_fn(struct lockdep_map *lock, lock_cmp_fn cmp_fn, -+ lock_print_fn print_fn) -+{ -+ struct lock_class *class = lock->class_cache[0]; -+ unsigned long flags; -+ -+ raw_local_irq_save(flags); -+ lockdep_recursion_inc(); -+ -+ if (!class) -+ class = register_lock_class(lock, 0, 0); -+ -+ if (class) { -+ WARN_ON(class->cmp_fn && class->cmp_fn != cmp_fn); -+ WARN_ON(class->print_fn && class->print_fn != print_fn); -+ -+ class->cmp_fn = cmp_fn; -+ class->print_fn = print_fn; -+ } -+ -+ lockdep_recursion_finish(); -+ raw_local_irq_restore(flags); -+} -+EXPORT_SYMBOL_GPL(lockdep_set_lock_cmp_fn); -+#endif -+ - static void - print_lock_nested_lock_not_held(struct task_struct *curr, - struct held_lock *hlock) diff --git a/kernel/panic.c b/kernel/panic.c index 68c028c7790b..63b5d2f7eb72 100644 --- a/kernel/panic.c diff --git a/patches.suse/printk-nbcon-move-locked_port-flag-to-struct-uart_port.patch b/patches.suse/printk-nbcon-move-locked_port-flag-to-struct-uart_port.patch index d709c99..dc2fa08 100644 --- a/patches.suse/printk-nbcon-move-locked_port-flag-to-struct-uart_port.patch +++ b/patches.suse/printk-nbcon-move-locked_port-flag-to-struct-uart_port.patch @@ -1,8 +1,10 @@ -From fce60ec62bffefd5bf741742abc9b3eac7e1597b Mon Sep 17 00:00:00 2001 +From 8df8aa0fde50fae34cf5799698ab6ba1c3b337c2 Mon Sep 17 00:00:00 2001 From: Junxiao Chang -Date: Tue, 23 Jan 2024 13:40:32 +0800 +Date: Tue, 23 Jan 2024 05:40:32 +0000 Subject: [PATCH] printk: nbcon: move locked_port flag to struct uart_port +From fce60ec62bffefd5bf741742abc9b3eac7e1597b Mon Sep 17 00:00:00 2001 + References: bsc#1214683 (PREEMPT_RT prerequisite backports) Git-commit: b07c1d0e81140da5ac7871633737687213d1aadf Patch-mainline: v6.6.20 @@ -19,6 +21,7 @@ Link: https://lore.kernel.org/all/20240123054033.183114-2-junxiao.chang@intel.co (cherry picked from commit d4fb86a96cb4a1efd24ca13a2ac234a1c9a3fdc5) Signed-off-by: Clark Williams Signed-off-by: Mel Gorman + --- include/linux/console.h | 2 -- include/linux/serial_core.h | 1 + diff --git a/patches.suse/tty-change-tty_write_lock-s-ndelay-parameter-to-bool.patch b/patches.suse/tty-change-tty_write_lock-s-ndelay-parameter-to-bool.patch new file mode 100644 index 0000000..0d41435 --- /dev/null +++ b/patches.suse/tty-change-tty_write_lock-s-ndelay-parameter-to-bool.patch @@ -0,0 +1,78 @@ +From c3e3270a0d0d257b85801e8029d2b46c1d7d48bf Mon Sep 17 00:00:00 2001 +From: "Jiri Slaby (SUSE)" +Date: Thu, 10 Aug 2023 11:14:39 +0200 +Subject: [PATCH] tty: change tty_write_lock()'s ndelay parameter to bool + +References: bsc#1214683 (PREEMPT_RT prerequisite backports) +Patch-mainline: v6.6-rc1 +Git-commit: af815336556df28f800669c58ab3bdad7d786b98 + +It's a yes-no parameter, so convert it to bool to be obvious. + +Signed-off-by: "Jiri Slaby (SUSE)" +Link: https://lore.kernel.org/r/20230810091510.13006-6-jirislaby@kernel.org +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Mel Gorman +--- + drivers/tty/tty.h | 2 +- + drivers/tty/tty_io.c | 6 +++--- + drivers/tty/tty_ioctl.c | 2 +- + 3 files changed, 5 insertions(+), 5 deletions(-) + +diff --git a/drivers/tty/tty.h b/drivers/tty/tty.h +index 1e0d80e98d26..db7f3f87772f 100644 +--- a/drivers/tty/tty.h ++++ b/drivers/tty/tty.h +@@ -63,7 +63,7 @@ int tty_check_change(struct tty_struct *tty); + void __stop_tty(struct tty_struct *tty); + void __start_tty(struct tty_struct *tty); + void tty_write_unlock(struct tty_struct *tty); +-int tty_write_lock(struct tty_struct *tty, int ndelay); ++int tty_write_lock(struct tty_struct *tty, bool ndelay); + void tty_vhangup_session(struct tty_struct *tty); + void tty_open_proc_set_tty(struct file *filp, struct tty_struct *tty); + int tty_signal_session_leader(struct tty_struct *tty, int exit_session); +diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c +index b55a2c611a02..c0ba994fb1d0 100644 +--- a/drivers/tty/tty_io.c ++++ b/drivers/tty/tty_io.c +@@ -946,7 +946,7 @@ void tty_write_unlock(struct tty_struct *tty) + wake_up_interruptible_poll(&tty->write_wait, EPOLLOUT); + } + +-int tty_write_lock(struct tty_struct *tty, int ndelay) ++int tty_write_lock(struct tty_struct *tty, bool ndelay) + { + if (!mutex_trylock(&tty->atomic_write_lock)) { + if (ndelay) +@@ -1160,7 +1160,7 @@ int tty_send_xchar(struct tty_struct *tty, char ch) + return 0; + } + +- if (tty_write_lock(tty, 0) < 0) ++ if (tty_write_lock(tty, false) < 0) + return -ERESTARTSYS; + + down_read(&tty->termios_rwsem); +@@ -2486,7 +2486,7 @@ static int send_break(struct tty_struct *tty, unsigned int duration) + retval = tty->ops->break_ctl(tty, duration); + else { + /* Do the work ourselves */ +- if (tty_write_lock(tty, 0) < 0) ++ if (tty_write_lock(tty, false) < 0) + return -EINTR; + retval = tty->ops->break_ctl(tty, -1); + if (retval) +diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c +index fb679d161ac4..aa5a596337dc 100644 +--- a/drivers/tty/tty_ioctl.c ++++ b/drivers/tty/tty_ioctl.c +@@ -507,7 +507,7 @@ static int set_termios(struct tty_struct *tty, void __user *arg, int opt) + if (retval < 0) + return retval; + +- if (tty_write_lock(tty, 0) < 0) ++ if (tty_write_lock(tty, false) < 0) + goto retry_write_wait; + + /* Racing writer? */ diff --git a/patches.suse/tty-don-t-check-for-signal_pending-in-send_break.patch b/patches.suse/tty-don-t-check-for-signal_pending-in-send_break.patch new file mode 100644 index 0000000..b3d3115 --- /dev/null +++ b/patches.suse/tty-don-t-check-for-signal_pending-in-send_break.patch @@ -0,0 +1,38 @@ +From 62286ce0028c81d57c3bf67c6e853b7dc9d574e3 Mon Sep 17 00:00:00 2001 +From: "Jiri Slaby (SUSE)" +Date: Tue, 19 Sep 2023 10:51:55 +0200 +Subject: [PATCH] tty: don't check for signal_pending() in send_break() + +References: bsc#1214683 (PREEMPT_RT prerequisite backports) +Patch-mainline: v6.6.14 +Git-commit: eefdb1be0c8be48d260787a0aa404deef790dac9 + +[ Upstream commit fd99392b643b824813df2edbaebe26a2136d31e6 ] + +msleep_interruptible() will check on its own. So no need to do the check +in send_break() before calling the above. + +Signed-off-by: "Jiri Slaby (SUSE)" +Link: https://lore.kernel.org/r/20230919085156.1578-15-jirislaby@kernel.org +Signed-off-by: Greg Kroah-Hartman +Stable-dep-of: 66aad7d8d3ec ("usb: cdc-acm: return correct error code on unsupported break") +Signed-off-by: Sasha Levin +Signed-off-by: Mel Gorman +--- + drivers/tty/tty_io.c | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c +index 92d2da9256ef..db6dcc323a81 100644 +--- a/drivers/tty/tty_io.c ++++ b/drivers/tty/tty_io.c +@@ -2484,8 +2484,7 @@ static int send_break(struct tty_struct *tty, unsigned int duration) + retval = tty->ops->break_ctl(tty, -1); + if (retval) + goto out; +- if (!signal_pending(current)) +- msleep_interruptible(duration); ++ msleep_interruptible(duration); + retval = tty->ops->break_ctl(tty, 0); + out: + tty_write_unlock(tty); diff --git a/patches.suse/tty-don-t-pass-write-to-do_tty_write.patch b/patches.suse/tty-don-t-pass-write-to-do_tty_write.patch new file mode 100644 index 0000000..1de2039 --- /dev/null +++ b/patches.suse/tty-don-t-pass-write-to-do_tty_write.patch @@ -0,0 +1,58 @@ +From b87e3c9610e3ffb3a46db764578b71a8b991ec19 Mon Sep 17 00:00:00 2001 +From: "Jiri Slaby (SUSE)" +Date: Thu, 10 Aug 2023 11:14:55 +0200 +Subject: [PATCH] tty: don't pass write() to do_tty_write() + +References: bsc#1214683 (PREEMPT_RT prerequisite backports) +Patch-mainline: v6.6-rc1 +Git-commit: f47a4fd67f2a803f205db7a4136571c2bd487297 + +write() passed to do_tty_write() is always ld->ops->write(). Instead, +align with iterate_tty_read() and pass the whole ld instead. This makes +the code easier to follow as it is clear what the write is. And also the +function signature is more readable. + +Signed-off-by: "Jiri Slaby (SUSE)" +Link: https://lore.kernel.org/r/20230810091510.13006-22-jirislaby@kernel.org +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Mel Gorman +--- + drivers/tty/tty_io.c | 11 ++++------- + 1 file changed, 4 insertions(+), 7 deletions(-) + +diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c +index c0ba994fb1d0..2c4dfcbef725 100644 +--- a/drivers/tty/tty_io.c ++++ b/drivers/tty/tty_io.c +@@ -961,11 +961,8 @@ int tty_write_lock(struct tty_struct *tty, bool ndelay) + * Split writes up in sane blocksizes to avoid + * denial-of-service type attacks + */ +-static inline ssize_t do_tty_write( +- ssize_t (*write)(struct tty_struct *, struct file *, const unsigned char *, size_t), +- struct tty_struct *tty, +- struct file *file, +- struct iov_iter *from) ++static inline ssize_t do_tty_write(struct tty_ldisc *ld, struct tty_struct *tty, ++ struct file *file, struct iov_iter *from) + { + size_t count = iov_iter_count(from); + ssize_t ret, written = 0; +@@ -1022,7 +1019,7 @@ static inline ssize_t do_tty_write( + if (copy_from_iter(tty->write_buf, size, from) != size) + break; + +- ret = write(tty, file, tty->write_buf, size); ++ ret = ld->ops->write(tty, file, tty->write_buf, size); + if (ret <= 0) + break; + +@@ -1093,7 +1090,7 @@ static ssize_t file_tty_write(struct file *file, struct kiocb *iocb, struct iov_ + if (!ld->ops->write) + ret = -EIO; + else +- ret = do_tty_write(ld->ops->write, tty, file, from); ++ ret = do_tty_write(ld, tty, file, from); + tty_ldisc_deref(ld); + return ret; + } diff --git a/patches.suse/tty-early-return-from-send_break-on-TTY_DRIVER_HARDWARE_BREAK.patch b/patches.suse/tty-early-return-from-send_break-on-TTY_DRIVER_HARDWARE_BREAK.patch new file mode 100644 index 0000000..d99ffb4 --- /dev/null +++ b/patches.suse/tty-early-return-from-send_break-on-TTY_DRIVER_HARDWARE_BREAK.patch @@ -0,0 +1,75 @@ +From beb1479f6d8f359110ec334a972f979874cd7ad2 Mon Sep 17 00:00:00 2001 +From: "Jiri Slaby (SUSE)" +Date: Tue, 19 Sep 2023 10:51:54 +0200 +Subject: [PATCH] tty: early return from send_break() on + TTY_DRIVER_HARDWARE_BREAK + +References: bsc#1214683 (PREEMPT_RT prerequisite backports) +Patch-mainline: v6.6.14 +Git-commit: ecf27e4765875ca24ee2fd02edb90290f0e9dd8e + +[ Upstream commit 66619686d187b4a6395316b7f39881e945dce4bc ] + +If the driver sets TTY_DRIVER_HARDWARE_BREAK, we leave ops->break_ctl() +to the driver and return from send_break(). But we do it using a local +variable and keep the code flowing through the end of the function. +Instead, do 'return' immediately with the ops->break_ctl()'s return +value. + +This way, we don't have to stuff the 'else' branch of the 'if' with the +software break handling. And we can re-indent the function too. + +Signed-off-by: "Jiri Slaby (SUSE)" +Link: https://lore.kernel.org/r/20230919085156.1578-14-jirislaby@kernel.org +Signed-off-by: Greg Kroah-Hartman +Stable-dep-of: 66aad7d8d3ec ("usb: cdc-acm: return correct error code on unsupported break") +Signed-off-by: Sasha Levin +Signed-off-by: Mel Gorman +--- + drivers/tty/tty_io.c | 32 +++++++++++++++++--------------- + 1 file changed, 17 insertions(+), 15 deletions(-) + +diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c +index 383159639f65..92d2da9256ef 100644 +--- a/drivers/tty/tty_io.c ++++ b/drivers/tty/tty_io.c +@@ -2475,22 +2475,24 @@ static int send_break(struct tty_struct *tty, unsigned int duration) + return 0; + + if (tty->driver->flags & TTY_DRIVER_HARDWARE_BREAK) +- retval = tty->ops->break_ctl(tty, duration); +- else { +- /* Do the work ourselves */ +- if (tty_write_lock(tty, false) < 0) +- return -EINTR; +- retval = tty->ops->break_ctl(tty, -1); +- if (retval) +- goto out; +- if (!signal_pending(current)) +- msleep_interruptible(duration); +- retval = tty->ops->break_ctl(tty, 0); ++ return tty->ops->break_ctl(tty, duration); ++ ++ /* Do the work ourselves */ ++ if (tty_write_lock(tty, false) < 0) ++ return -EINTR; ++ ++ retval = tty->ops->break_ctl(tty, -1); ++ if (retval) ++ goto out; ++ if (!signal_pending(current)) ++ msleep_interruptible(duration); ++ retval = tty->ops->break_ctl(tty, 0); + out: +- tty_write_unlock(tty); +- if (signal_pending(current)) +- retval = -EINTR; +- } ++ tty_write_unlock(tty); ++ ++ if (signal_pending(current)) ++ retval = -EINTR; ++ + return retval; + } + diff --git a/patches.suse/tty-make-check_tty_count-void.patch b/patches.suse/tty-make-check_tty_count-void.patch new file mode 100644 index 0000000..0fd3a0f --- /dev/null +++ b/patches.suse/tty-make-check_tty_count-void.patch @@ -0,0 +1,43 @@ +From b70f58cf26ef9d75dffcb34c099c133fc8f1bf4f Mon Sep 17 00:00:00 2001 +From: Jiri Slaby +Date: Wed, 12 Jul 2023 10:58:30 +0200 +Subject: [PATCH] tty: make check_tty_count() void + +References: bsc#1214683 (PREEMPT_RT prerequisite backports) +Patch-mainline: v6.6-rc1 +Git-commit: b4940f6c3e0e021a8612e8eee5d93ecba9ec9f32 + +The return value is unused, so drop it. + +Signed-off-by: Jiri Slaby (SUSE) +Link: https://lore.kernel.org/r/20230712085830.4908-1-jirislaby@kernel.org +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Mel Gorman +--- + drivers/tty/tty_io.c | 4 +--- + 1 file changed, 1 insertion(+), 3 deletions(-) + +diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c +index 4778fc78daec..b55a2c611a02 100644 +--- a/drivers/tty/tty_io.c ++++ b/drivers/tty/tty_io.c +@@ -270,7 +270,7 @@ static int tty_paranoia_check(struct tty_struct *tty, struct inode *inode, + } + + /* Caller must hold tty_lock */ +-static int check_tty_count(struct tty_struct *tty, const char *routine) ++static void check_tty_count(struct tty_struct *tty, const char *routine) + { + #ifdef CHECK_TTY_COUNT + struct list_head *p; +@@ -290,10 +290,8 @@ static int check_tty_count(struct tty_struct *tty, const char *routine) + if (tty->count != (count + kopen_count)) { + tty_warn(tty, "%s: tty->count(%d) != (#fd's(%d) + #kopen's(%d))\n", + routine, tty->count, count, kopen_count); +- return (count + kopen_count); + } + #endif +- return 0; + } + + /** diff --git a/patches.suse/tty-rename-and-de-inline-do_tty_write.patch b/patches.suse/tty-rename-and-de-inline-do_tty_write.patch new file mode 100644 index 0000000..bbe2387 --- /dev/null +++ b/patches.suse/tty-rename-and-de-inline-do_tty_write.patch @@ -0,0 +1,47 @@ +From 140f468863b742fbe06582b080ee1289a16e83ba Mon Sep 17 00:00:00 2001 +From: "Jiri Slaby (SUSE)" +Date: Thu, 10 Aug 2023 11:14:56 +0200 +Subject: [PATCH] tty: rename and de-inline do_tty_write() + +References: bsc#1214683 (PREEMPT_RT prerequisite backports) +Patch-mainline: v6.6-rc1 +Git-commit: a32a672dc5aaec1ccd246b3a27cee8a367b822c1 + +Make do_tty_write()'s name sound similar to iterate_tty_read(). They +both do similar things, so there is no reason for so distinct names. The +new name is therefore iterate_tty_write(). + +Drop the unnedeed inline modifier too. Let the compiler decide. + +Signed-off-by: "Jiri Slaby (SUSE)" +Link: https://lore.kernel.org/r/20230810091510.13006-23-jirislaby@kernel.org +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Mel Gorman +--- + drivers/tty/tty_io.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c +index 2c4dfcbef725..4319a3e04fd9 100644 +--- a/drivers/tty/tty_io.c ++++ b/drivers/tty/tty_io.c +@@ -961,8 +961,8 @@ int tty_write_lock(struct tty_struct *tty, bool ndelay) + * Split writes up in sane blocksizes to avoid + * denial-of-service type attacks + */ +-static inline ssize_t do_tty_write(struct tty_ldisc *ld, struct tty_struct *tty, +- struct file *file, struct iov_iter *from) ++static ssize_t iterate_tty_write(struct tty_ldisc *ld, struct tty_struct *tty, ++ struct file *file, struct iov_iter *from) + { + size_t count = iov_iter_count(from); + ssize_t ret, written = 0; +@@ -1090,7 +1090,7 @@ static ssize_t file_tty_write(struct file *file, struct kiocb *iocb, struct iov_ + if (!ld->ops->write) + ret = -EIO; + else +- ret = do_tty_write(ld, tty, file, from); ++ ret = iterate_tty_write(ld, tty, file, from); + tty_ldisc_deref(ld); + return ret; + } diff --git a/patches.suse/tty-switch-size-and-count-types-in-iterate_tty_read-to-size_t.patch b/patches.suse/tty-switch-size-and-count-types-in-iterate_tty_read-to-size_t.patch new file mode 100644 index 0000000..88de4da --- /dev/null +++ b/patches.suse/tty-switch-size-and-count-types-in-iterate_tty_read-to-size_t.patch @@ -0,0 +1,41 @@ +From 48446b66fef7d5d38058ba5d670d86c1dc4f3402 Mon Sep 17 00:00:00 2001 +From: "Jiri Slaby (SUSE)" +Date: Thu, 10 Aug 2023 11:14:59 +0200 +Subject: [PATCH] tty: switch size and count types in iterate_tty_read() to + size_t + +References: bsc#1214683 (PREEMPT_RT prerequisite backports) +Patch-mainline: v6.6-rc1 +Git-commit: e3afc5b0d708e2ef389b9c7acd45d1e4fd2cb304 + +ld->ops->read() returns ssize_t. copy_to_iter() returns size_t. So +switch the variables ('size' and 'copied', respectively) to the +corresponding types. + +This allows for use of min() in the next patch. + +Signed-off-by: "Jiri Slaby (SUSE)" +Link: https://lore.kernel.org/r/20230810091510.13006-26-jirislaby@kernel.org +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Mel Gorman +--- + drivers/tty/tty_io.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c +index be88c86fb534..3a7055c5bbc2 100644 +--- a/drivers/tty/tty_io.c ++++ b/drivers/tty/tty_io.c +@@ -850,10 +850,10 @@ static ssize_t iterate_tty_read(struct tty_ldisc *ld, struct tty_struct *tty, + unsigned long offset = 0; + char kernel_buf[64]; + ssize_t retval = 0; +- size_t count = iov_iter_count(to); ++ size_t copied, count = iov_iter_count(to); + + do { +- int size, copied; ++ ssize_t size; + + size = count > sizeof(kernel_buf) ? sizeof(kernel_buf) : count; + size = ld->ops->read(tty, file, kernel_buf, size, &cookie, offset); diff --git a/patches.suse/tty-tty_io-update-timestamps-on-all-device-nodes.patch b/patches.suse/tty-tty_io-update-timestamps-on-all-device-nodes.patch new file mode 100644 index 0000000..172afe9 --- /dev/null +++ b/patches.suse/tty-tty_io-update-timestamps-on-all-device-nodes.patch @@ -0,0 +1,107 @@ +From 411142e6c92124862d0c475b38d9e9fa10fe5eed Mon Sep 17 00:00:00 2001 +From: Michal Sekletar +Date: Tue, 13 Jun 2023 19:21:06 +0200 +Subject: [PATCH] tty: tty_io: update timestamps on all device nodes + +References: bsc#1214683 (PREEMPT_RT prerequisite backports) +Patch-mainline: v6.5-rc1 +Git-commit: 360c11e2258ce4269441a5ab6d43d0b202f4261b + +User space applications watch for timestamp changes on character device +files in order to determine idle time of a given terminal session. For +example, "w" program uses this information to populate the IDLE column +of its output [1]. Similarly, systemd-logind has optional feature where +it uses atime of the tty character device to determine if there was +activity on the terminal associated with the logind's session object. If +there was no activity for a configured period of time then logind will +terminate such session [2]. + +Now, usually (e.g. bash running on the terminal) the use of the terminal +will update timestamps (atime and mtime) on the corresponding terminal +character device. However, if access to the terminal, e.g. /dev/pts/0, +is performed through magic character device /dev/tty then such access +obviously changes the state of the terminal, however timestamps on the +device that correspond to the terminal (/dev/pts/0) are not updated. + +This patch makes sure that we update timestamps on *all* character +devices that correspond to the given tty, because outside observers (w, +systemd-logind) are maybe checking these timestamps. Obviously, they can +not check timestamps on /dev/tty as that has per-process meaning. + +[1] https://gitlab.com/procps-ng/procps/-/blob/v4.0.0/w.c#L286 +[2] https://github.com/systemd/systemd/blob/v252/NEWS#L477 + +Signed-off-by: Michal Sekletar +Message-ID: <20230613172107.78138-1-msekleta@redhat.com> +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Mel Gorman +--- + drivers/tty/tty_io.c | 31 ++++++++++++++++++++----------- + 1 file changed, 20 insertions(+), 11 deletions(-) + +diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c +index c80b3ac4196e..4778fc78daec 100644 +--- a/drivers/tty/tty_io.c ++++ b/drivers/tty/tty_io.c +@@ -101,6 +101,7 @@ + #include + #include + #include ++#include + + #include + #include +@@ -811,18 +812,26 @@ void start_tty(struct tty_struct *tty) + } + EXPORT_SYMBOL(start_tty); + +-static void tty_update_time(struct timespec64 *time) ++static void tty_update_time(struct tty_struct *tty, bool mtime) + { + time64_t sec = ktime_get_real_seconds(); ++ struct tty_file_private *priv; + +- /* +- * We only care if the two values differ in anything other than the +- * lower three bits (i.e every 8 seconds). If so, then we can update +- * the time of the tty device, otherwise it could be construded as a +- * security leak to let userspace know the exact timing of the tty. +- */ +- if ((sec ^ time->tv_sec) & ~7) +- time->tv_sec = sec; ++ spin_lock(&tty->files_lock); ++ list_for_each_entry(priv, &tty->tty_files, list) { ++ struct inode *inode = file_inode(priv->file); ++ struct timespec64 *time = mtime ? &inode->i_mtime : &inode->i_atime; ++ ++ /* ++ * We only care if the two values differ in anything other than the ++ * lower three bits (i.e every 8 seconds). If so, then we can update ++ * the time of the tty device, otherwise it could be construded as a ++ * security leak to let userspace know the exact timing of the tty. ++ */ ++ if ((sec ^ time->tv_sec) & ~7) ++ time->tv_sec = sec; ++ } ++ spin_unlock(&tty->files_lock); + } + + /* +@@ -928,7 +937,7 @@ static ssize_t tty_read(struct kiocb *iocb, struct iov_iter *to) + tty_ldisc_deref(ld); + + if (i > 0) +- tty_update_time(&inode->i_atime); ++ tty_update_time(tty, false); + + return i; + } +@@ -1036,7 +1045,7 @@ static inline ssize_t do_tty_write( + cond_resched(); + } + if (written) { +- tty_update_time(&file_inode(file)->i_mtime); ++ tty_update_time(tty, true); + ret = written; + } + out: diff --git a/patches.suse/tty-use-if-in-send_break-instead-of-goto.patch b/patches.suse/tty-use-if-in-send_break-instead-of-goto.patch new file mode 100644 index 0000000..a4c4289 --- /dev/null +++ b/patches.suse/tty-use-if-in-send_break-instead-of-goto.patch @@ -0,0 +1,44 @@ +From c9a05d694d971f0270bcc503e0e23b14cc156ded Mon Sep 17 00:00:00 2001 +From: "Jiri Slaby (SUSE)" +Date: Tue, 19 Sep 2023 10:51:56 +0200 +Subject: [PATCH] tty: use 'if' in send_break() instead of 'goto' + +References: bsc#1214683 (PREEMPT_RT prerequisite backports) +Patch-mainline: v6.6.14 +Git-commit: 2433f050d31acf64fe340e28b0e41390ae871ca2 + +[ Upstream commit 24f2cd019946fc2e88e632d2e24a34c2cc3f2be4 ] + +Now, the "jumped-over" code is simple enough to be put inside an 'if'. +Do so to make it 'goto'-less. + +Signed-off-by: "Jiri Slaby (SUSE)" +Link: https://lore.kernel.org/r/20230919085156.1578-16-jirislaby@kernel.org +Signed-off-by: Greg Kroah-Hartman +Stable-dep-of: 66aad7d8d3ec ("usb: cdc-acm: return correct error code on unsupported break") +Signed-off-by: Sasha Levin +Signed-off-by: Mel Gorman +--- + drivers/tty/tty_io.c | 9 ++++----- + 1 file changed, 4 insertions(+), 5 deletions(-) + +diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c +index db6dcc323a81..86a6549c0928 100644 +--- a/drivers/tty/tty_io.c ++++ b/drivers/tty/tty_io.c +@@ -2482,11 +2482,10 @@ static int send_break(struct tty_struct *tty, unsigned int duration) + return -EINTR; + + retval = tty->ops->break_ctl(tty, -1); +- if (retval) +- goto out; +- msleep_interruptible(duration); +- retval = tty->ops->break_ctl(tty, 0); +-out: ++ if (!retval) { ++ msleep_interruptible(duration); ++ retval = tty->ops->break_ctl(tty, 0); ++ } + tty_write_unlock(tty); + + if (signal_pending(current)) diff --git a/patches.suse/tty-use-min-for-size-computation-in-iterate_tty_read.patch b/patches.suse/tty-use-min-for-size-computation-in-iterate_tty_read.patch new file mode 100644 index 0000000..7d5c9b0 --- /dev/null +++ b/patches.suse/tty-use-min-for-size-computation-in-iterate_tty_read.patch @@ -0,0 +1,34 @@ +From 736b99ca0146069ff38bb757b2e454622bf57c8c Mon Sep 17 00:00:00 2001 +From: "Jiri Slaby (SUSE)" +Date: Thu, 10 Aug 2023 11:15:00 +0200 +Subject: [PATCH] tty: use min() for size computation in iterate_tty_read() + +References: bsc#1214683 (PREEMPT_RT prerequisite backports) +Patch-mainline: v6.6-rc1 +Git-commit: 48a6ab8867eff61fa11d9e8f8e1c7327b135e689 + +The computation is more obvious with min(). + +Signed-off-by: "Jiri Slaby (SUSE)" +Link: https://lore.kernel.org/r/20230810091510.13006-27-jirislaby@kernel.org +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Mel Gorman +--- + drivers/tty/tty_io.c | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c +index 3a7055c5bbc2..68795761b76e 100644 +--- a/drivers/tty/tty_io.c ++++ b/drivers/tty/tty_io.c +@@ -853,9 +853,8 @@ static ssize_t iterate_tty_read(struct tty_ldisc *ld, struct tty_struct *tty, + size_t copied, count = iov_iter_count(to); + + do { +- ssize_t size; ++ ssize_t size = min(count, sizeof(kernel_buf)); + +- size = count > sizeof(kernel_buf) ? sizeof(kernel_buf) : count; + size = ld->ops->read(tty, file, kernel_buf, size, &cookie, offset); + if (!size) + break; diff --git a/patches.suse/tty-use-min-in-iterate_tty_write.patch b/patches.suse/tty-use-min-in-iterate_tty_write.patch new file mode 100644 index 0000000..ae8d6ca --- /dev/null +++ b/patches.suse/tty-use-min-in-iterate_tty_write.patch @@ -0,0 +1,47 @@ +From 7d3dec635561dc81aefe6e7002802dabc5dc22fc Mon Sep 17 00:00:00 2001 +From: "Jiri Slaby (SUSE)" +Date: Thu, 10 Aug 2023 11:14:57 +0200 +Subject: [PATCH] tty: use min() in iterate_tty_write() + +References: bsc#1214683 (PREEMPT_RT prerequisite backports) +Patch-mainline: v6.6-rc1 +Git-commit: ccc8dc00a24bb657b6a6f8adbfbb535365b4ba3d + +It simplifies the code. The "price" is we have to unify 'chunk' to be +size_t the same as 'count' is. But that change is actually correct. + +Signed-off-by: "Jiri Slaby (SUSE)" +Link: https://lore.kernel.org/r/20230810091510.13006-24-jirislaby@kernel.org +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Mel Gorman +--- + drivers/tty/tty_io.c | 8 ++------ + 1 file changed, 2 insertions(+), 6 deletions(-) + +diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c +index 4319a3e04fd9..692133715f0e 100644 +--- a/drivers/tty/tty_io.c ++++ b/drivers/tty/tty_io.c +@@ -964,9 +964,8 @@ int tty_write_lock(struct tty_struct *tty, bool ndelay) + static ssize_t iterate_tty_write(struct tty_ldisc *ld, struct tty_struct *tty, + struct file *file, struct iov_iter *from) + { +- size_t count = iov_iter_count(from); ++ size_t chunk, count = iov_iter_count(from); + ssize_t ret, written = 0; +- unsigned int chunk; + + ret = tty_write_lock(tty, file->f_flags & O_NDELAY); + if (ret < 0) +@@ -1010,10 +1009,7 @@ static ssize_t iterate_tty_write(struct tty_ldisc *ld, struct tty_struct *tty, + + /* Do the write .. */ + for (;;) { +- size_t size = count; +- +- if (size > chunk) +- size = chunk; ++ size_t size = min(chunk, count); + + ret = -EFAULT; + if (copy_from_iter(tty->write_buf, size, from) != size) diff --git a/patches.suse/tty-use-ssize_t-for-iterate_tty_read-returned-type.patch b/patches.suse/tty-use-ssize_t-for-iterate_tty_read-returned-type.patch new file mode 100644 index 0000000..02e65ae --- /dev/null +++ b/patches.suse/tty-use-ssize_t-for-iterate_tty_read-returned-type.patch @@ -0,0 +1,79 @@ +From 03627f6d441761691260c6c1ee92443cab0d9375 Mon Sep 17 00:00:00 2001 +From: "Jiri Slaby (SUSE)" +Date: Thu, 10 Aug 2023 11:14:58 +0200 +Subject: [PATCH] tty: use ssize_t for iterate_tty_read() returned type + +References: bsc#1214683 (PREEMPT_RT prerequisite backports) +Patch-mainline: v6.6-rc1 +Git-commit: 24b01c5d497ba422f34d381a693d0592e95ad5c3 + +tty_read() is supposed to return ssize_t. It takes the return value from +iterate_tty_read(). That currently returns int. On the top of that, +iterate_tty_write() already returns ssize_t. So switch +iterate_tty_read() to ssize_t too, so that all three are consistent. + +This means 'i' in tty_read() changes its type too. And while changing +that, rename this generic 'i' to more dedicated 'ret'. + +Signed-off-by: "Jiri Slaby (SUSE)" +Link: https://lore.kernel.org/r/20230810091510.13006-25-jirislaby@kernel.org +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Mel Gorman +--- + drivers/tty/tty_io.c | 16 ++++++++-------- + 1 file changed, 8 insertions(+), 8 deletions(-) + +diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c +index 692133715f0e..be88c86fb534 100644 +--- a/drivers/tty/tty_io.c ++++ b/drivers/tty/tty_io.c +@@ -843,13 +843,13 @@ static void tty_update_time(struct tty_struct *tty, bool mtime) + * data or clears the cookie. The cookie may be something that the + * ldisc maintains state for and needs to free. + */ +-static int iterate_tty_read(struct tty_ldisc *ld, struct tty_struct *tty, +- struct file *file, struct iov_iter *to) ++static ssize_t iterate_tty_read(struct tty_ldisc *ld, struct tty_struct *tty, ++ struct file *file, struct iov_iter *to) + { +- int retval = 0; + void *cookie = NULL; + unsigned long offset = 0; + char kernel_buf[64]; ++ ssize_t retval = 0; + size_t count = iov_iter_count(to); + + do { +@@ -912,11 +912,11 @@ static int iterate_tty_read(struct tty_ldisc *ld, struct tty_struct *tty, + */ + static ssize_t tty_read(struct kiocb *iocb, struct iov_iter *to) + { +- int i; + struct file *file = iocb->ki_filp; + struct inode *inode = file_inode(file); + struct tty_struct *tty = file_tty(file); + struct tty_ldisc *ld; ++ ssize_t ret; + + if (tty_paranoia_check(tty, inode, "tty_read")) + return -EIO; +@@ -929,15 +929,15 @@ static ssize_t tty_read(struct kiocb *iocb, struct iov_iter *to) + ld = tty_ldisc_ref_wait(tty); + if (!ld) + return hung_up_tty_read(iocb, to); +- i = -EIO; ++ ret = -EIO; + if (ld->ops->read) +- i = iterate_tty_read(ld, tty, file, to); ++ ret = iterate_tty_read(ld, tty, file, to); + tty_ldisc_deref(ld); + +- if (i > 0) ++ if (ret > 0) + tty_update_time(tty, false); + +- return i; ++ return ret; + } + + void tty_write_unlock(struct tty_struct *tty) diff --git a/patches.suse/tty_audit-invert-the-condition-in-tty_audit_log.patch b/patches.suse/tty_audit-invert-the-condition-in-tty_audit_log.patch new file mode 100644 index 0000000..15b3b71 --- /dev/null +++ b/patches.suse/tty_audit-invert-the-condition-in-tty_audit_log.patch @@ -0,0 +1,58 @@ +From 4b33c531832c55cacc3d1198c24e2ef741ed4433 Mon Sep 17 00:00:00 2001 +From: Jiri Slaby +Date: Wed, 21 Jun 2023 12:16:08 +0200 +Subject: [PATCH] tty_audit: invert the condition in tty_audit_log() + +References: bsc#1214683 (PREEMPT_RT prerequisite backports) +Patch-mainline: v6.5-rc1 +Git-commit: 94f94810efc4b4b337c9f2abc8b0188cef5ccb9b + +If we cannot obtain an audit buffer in tty_audit_log(), simply return +from the function. Apart this is mostly preferred in the kernel, it +allows to merge the split audit string while still keeping it readable. + +Signed-off-by: Jiri Slaby (SUSE) +Link: https://lore.kernel.org/r/20230621101611.10580-4-jirislaby@kernel.org +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Mel Gorman +--- + drivers/tty/tty_audit.c | 24 ++++++++++++------------ + 1 file changed, 12 insertions(+), 12 deletions(-) + +diff --git a/drivers/tty/tty_audit.c b/drivers/tty/tty_audit.c +index 43f34465b9df..c6c27acad2ad 100644 +--- a/drivers/tty/tty_audit.c ++++ b/drivers/tty/tty_audit.c +@@ -66,20 +66,20 @@ static void tty_audit_log(const char *description, dev_t dev, + uid_t uid = from_kuid(&init_user_ns, task_uid(current)); + uid_t loginuid = from_kuid(&init_user_ns, audit_get_loginuid(current)); + unsigned int sessionid = audit_get_sessionid(current); ++ char name[TASK_COMM_LEN]; + + ab = audit_log_start(audit_context(), GFP_KERNEL, AUDIT_TTY); +- if (ab) { +- char name[TASK_COMM_LEN]; +- +- audit_log_format(ab, "%s pid=%u uid=%u auid=%u ses=%u major=%d" +- " minor=%d comm=", description, pid, uid, +- loginuid, sessionid, MAJOR(dev), MINOR(dev)); +- get_task_comm(name, current); +- audit_log_untrustedstring(ab, name); +- audit_log_format(ab, " data="); +- audit_log_n_hex(ab, data, size); +- audit_log_end(ab); +- } ++ if (!ab) ++ return; ++ ++ audit_log_format(ab, "%s pid=%u uid=%u auid=%u ses=%u major=%d minor=%d comm=", ++ description, pid, uid, loginuid, sessionid, ++ MAJOR(dev), MINOR(dev)); ++ get_task_comm(name, current); ++ audit_log_untrustedstring(ab, name); ++ audit_log_format(ab, " data="); ++ audit_log_n_hex(ab, data, size); ++ audit_log_end(ab); + } + + /* diff --git a/patches.suse/tty_audit-make-data-of-tty_audit_log-const.patch b/patches.suse/tty_audit-make-data-of-tty_audit_log-const.patch new file mode 100644 index 0000000..ca535e9 --- /dev/null +++ b/patches.suse/tty_audit-make-data-of-tty_audit_log-const.patch @@ -0,0 +1,34 @@ +From d6131bccee85b3b9d102c424042882ff95a6148d Mon Sep 17 00:00:00 2001 +From: Jiri Slaby +Date: Wed, 21 Jun 2023 12:16:11 +0200 +Subject: [PATCH] tty_audit: make data of tty_audit_log() const + +References: bsc#1214683 (PREEMPT_RT prerequisite backports) +Patch-mainline: v6.5-rc1 +Git-commit: e534755c9412be07f579acd2947401a9f87a33c8 + +'data' are only read (passed down to audit_log_n_hex()), so they can be +const -- the same what is expected in audit_log_n_hex(). Only a minor +cleanup to be consistent. + +Signed-off-by: Jiri Slaby (SUSE) +Link: https://lore.kernel.org/r/20230621101611.10580-7-jirislaby@kernel.org +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Mel Gorman +--- + drivers/tty/tty_audit.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/drivers/tty/tty_audit.c b/drivers/tty/tty_audit.c +index 6cf8b63368ee..3a50236f7e5e 100644 +--- a/drivers/tty/tty_audit.c ++++ b/drivers/tty/tty_audit.c +@@ -59,7 +59,7 @@ static void tty_audit_buf_free(struct tty_audit_buf *buf) + } + + static void tty_audit_log(const char *description, dev_t dev, +- unsigned char *data, size_t size) ++ const unsigned char *data, size_t size) + { + struct audit_buffer *ab; + pid_t pid = task_pid_nr(current); diff --git a/patches.suse/tty_audit-make-icanon-a-bool.patch b/patches.suse/tty_audit-make-icanon-a-bool.patch new file mode 100644 index 0000000..324f1b1 --- /dev/null +++ b/patches.suse/tty_audit-make-icanon-a-bool.patch @@ -0,0 +1,43 @@ +From 4b8af241f493bbf203a4c5a139012a2e73ca7344 Mon Sep 17 00:00:00 2001 +From: Jiri Slaby +Date: Wed, 21 Jun 2023 12:16:09 +0200 +Subject: [PATCH] tty_audit: make icanon a bool + +References: bsc#1214683 (PREEMPT_RT prerequisite backports) +Patch-mainline: v6.5-rc1 +Git-commit: 3e540a7bad8534a9b8845defa051834c9694d86c + +Use bool for tty_audit_buf::icanon in favor of ugly bitfields. And get +rid of "!!" as that is completely unnecessary. + +Signed-off-by: Jiri Slaby (SUSE) +Link: https://lore.kernel.org/r/20230621101611.10580-5-jirislaby@kernel.org +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Mel Gorman +--- + drivers/tty/tty_audit.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/drivers/tty/tty_audit.c b/drivers/tty/tty_audit.c +index c6c27acad2ad..6cf8b63368ee 100644 +--- a/drivers/tty/tty_audit.c ++++ b/drivers/tty/tty_audit.c +@@ -15,7 +15,7 @@ + struct tty_audit_buf { + struct mutex mutex; /* Protects all data below */ + dev_t dev; /* The TTY which the data is from */ +- unsigned icanon:1; ++ bool icanon; + size_t valid; + unsigned char *data; /* Allocated size N_TTY_BUF_SIZE */ + }; +@@ -202,8 +202,8 @@ static struct tty_audit_buf *tty_audit_buf_get(void) + void tty_audit_add_data(struct tty_struct *tty, const void *data, size_t size) + { + struct tty_audit_buf *buf; +- unsigned int icanon = !!L_ICANON(tty); + unsigned int audit_tty; ++ bool icanon = L_ICANON(tty); + dev_t dev; + + audit_tty = READ_ONCE(current->signal->audit_tty); diff --git a/patches.suse/tty_audit-use-TASK_COMM_LEN-for-task-comm.patch b/patches.suse/tty_audit-use-TASK_COMM_LEN-for-task-comm.patch new file mode 100644 index 0000000..a0ef79c --- /dev/null +++ b/patches.suse/tty_audit-use-TASK_COMM_LEN-for-task-comm.patch @@ -0,0 +1,32 @@ +From 9eb92df559bec3254e593d951517aff221d32978 Mon Sep 17 00:00:00 2001 +From: Jiri Slaby +Date: Wed, 21 Jun 2023 12:16:06 +0200 +Subject: [PATCH] tty_audit: use TASK_COMM_LEN for task comm + +References: bsc#1214683 (PREEMPT_RT prerequisite backports) +Patch-mainline: v6.5-rc1 +Git-commit: 777e456852f729fa2942187a43a8eafbaecc6876 + +This is the preferred way of declaring an array for get_task_comm(). + +Signed-off-by: Jiri Slaby (SUSE) +Link: https://lore.kernel.org/r/20230621101611.10580-2-jirislaby@kernel.org +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Mel Gorman +--- + drivers/tty/tty_audit.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/drivers/tty/tty_audit.c b/drivers/tty/tty_audit.c +index ca7afd7b2716..b98b1aef5f6f 100644 +--- a/drivers/tty/tty_audit.c ++++ b/drivers/tty/tty_audit.c +@@ -69,7 +69,7 @@ static void tty_audit_log(const char *description, dev_t dev, + + ab = audit_log_start(audit_context(), GFP_KERNEL, AUDIT_TTY); + if (ab) { +- char name[sizeof(current->comm)]; ++ char name[TASK_COMM_LEN]; + + audit_log_format(ab, "%s pid=%u uid=%u auid=%u ses=%u major=%d" + " minor=%d comm=", description, pid, uid, diff --git a/patches.suse/tty_audit-use-kzalloc-in-tty_audit_buf_alloc.patch b/patches.suse/tty_audit-use-kzalloc-in-tty_audit_buf_alloc.patch new file mode 100644 index 0000000..7ce6f68 --- /dev/null +++ b/patches.suse/tty_audit-use-kzalloc-in-tty_audit_buf_alloc.patch @@ -0,0 +1,47 @@ +From ffd3d1f1e97e5ef68361ef78857adc21ba87faa5 Mon Sep 17 00:00:00 2001 +From: Jiri Slaby +Date: Wed, 21 Jun 2023 12:16:07 +0200 +Subject: [PATCH] tty_audit: use kzalloc() in tty_audit_buf_alloc() + +References: bsc#1214683 (PREEMPT_RT prerequisite backports) +Patch-mainline: v6.5-rc1 +Git-commit: e1488513abee9f34a7d0f3bd57ee65d2a7e13426 + +tty_audit_buf_alloc() manually erases most of the entries after +kmalloc(). So use kzalloc() and remove the manual sets to zero. + +That way, we are sure that we do not omit anything. + +Signed-off-by: Jiri Slaby (SUSE) +Link: https://lore.kernel.org/r/20230621101611.10580-3-jirislaby@kernel.org +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Mel Gorman +--- + drivers/tty/tty_audit.c | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/drivers/tty/tty_audit.c b/drivers/tty/tty_audit.c +index b98b1aef5f6f..43f34465b9df 100644 +--- a/drivers/tty/tty_audit.c ++++ b/drivers/tty/tty_audit.c +@@ -33,16 +33,16 @@ static struct tty_audit_buf *tty_audit_buf_alloc(void) + { + struct tty_audit_buf *buf; + +- buf = kmalloc(sizeof(*buf), GFP_KERNEL); ++ buf = kzalloc(sizeof(*buf), GFP_KERNEL); + if (!buf) + goto err; ++ + buf->data = kmalloc(N_TTY_BUF_SIZE, GFP_KERNEL); + if (!buf->data) + goto err_buf; ++ + mutex_init(&buf->mutex); +- buf->dev = MKDEV(0, 0); +- buf->icanon = 0; +- buf->valid = 0; ++ + return buf; + + err_buf: diff --git a/patches.suse/usb-cdc-acm-return-correct-error-code-on-unsupported-break.patch b/patches.suse/usb-cdc-acm-return-correct-error-code-on-unsupported-break.patch new file mode 100644 index 0000000..53b4b75 --- /dev/null +++ b/patches.suse/usb-cdc-acm-return-correct-error-code-on-unsupported-break.patch @@ -0,0 +1,62 @@ +From 0bbcdd47fac7fb758ba474cdc09b60303b417fab Mon Sep 17 00:00:00 2001 +From: Oliver Neukum +Date: Thu, 7 Dec 2023 14:26:30 +0100 +Subject: [PATCH] usb: cdc-acm: return correct error code on unsupported break + +References: bsc#1214683 (PREEMPT_RT prerequisite backports) +Patch-mainline: v6.6.14 +Git-commit: 19e321c3eedd4c681a49f532a196bead5d57205e + +[ Upstream commit 66aad7d8d3ec5a3a8ec2023841bcec2ded5f65c9 ] + +In ACM support for sending breaks to devices is optional. +If a device says that it doenot support sending breaks, +the host must respect that. +Given the number of optional features providing tty operations +for each combination is not practical and errors need to be +returned dynamically if unsupported features are requested. + +In case a device does not support break, we want the tty layer +to treat that like it treats drivers that statically cannot +support sending a break. It ignores the inability and does nothing. +This patch uses EOPNOTSUPP to indicate that. + +Signed-off-by: Oliver Neukum +Fixes: 9e98966c7bb94 ("tty: rework break handling") +Link: https://lore.kernel.org/r/20231207132639.18250-1-oneukum@suse.com +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Sasha Levin +Signed-off-by: Mel Gorman +--- + drivers/tty/tty_io.c | 3 +++ + drivers/usb/class/cdc-acm.c | 3 +++ + 2 files changed, 6 insertions(+) + +diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c +index 86a6549c0928..afa52883c498 100644 +--- a/drivers/tty/tty_io.c ++++ b/drivers/tty/tty_io.c +@@ -2485,6 +2485,9 @@ static int send_break(struct tty_struct *tty, unsigned int duration) + if (!retval) { + msleep_interruptible(duration); + retval = tty->ops->break_ctl(tty, 0); ++ } else if (retval == -EOPNOTSUPP) { ++ /* some drivers can tell only dynamically */ ++ retval = 0; + } + tty_write_unlock(tty); + +diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c +index 11da5fb284d0..00f4245d5ada 100644 +--- a/drivers/usb/class/cdc-acm.c ++++ b/drivers/usb/class/cdc-acm.c +@@ -892,6 +892,9 @@ static int acm_tty_break_ctl(struct tty_struct *tty, int state) + struct acm *acm = tty->driver_data; + int retval; + ++ if (!(acm->ctrl_caps & USB_CDC_CAP_BRK)) ++ return -EOPNOTSUPP; ++ + retval = acm_send_break(acm, state ? 0xffff : 0); + if (retval < 0) + dev_dbg(&acm->control->dev, diff --git a/series.conf b/series.conf index e113ba8..d1901f8 100644 --- a/series.conf +++ b/series.conf @@ -20486,6 +20486,7 @@ patches.suse/x86-tsc-Provide-sched_clock_noinstr.patch patches.suse/sched-clock-Provide-local_clock_noinstr.patch patches.suse/cpuidle-Use-local_clock_noinstr.patch + patches.suse/lockdep-Add-lock_set_cmp_fn-annotation.patch patches.suse/panic-hide-unused-global-functions.patch patches.suse/tty-serial-fsl_lpuart-optimize-the-timer-based-EOP-logic.patch patches.suse/serial-pl011-set-UART011_CR_RXE-in-pl011_set_termios-after-port-shutdown.patch @@ -20516,6 +20517,14 @@ patches.suse/serial-core-Fix-error-handling-for-serial_core_ctrl_device_add.patch patches.suse/serial-8250_mtk-Simplify-clock-sequencing-and-runtime-PM.patch patches.suse/serial-8250-Apply-FSL-workarounds-also-without-SERIAL_8250_CONSOLE.patch + patches.suse/tty-tty_io-update-timestamps-on-all-device-nodes.patch + patches.suse/tty_audit-use-TASK_COMM_LEN-for-task-comm.patch + patches.suse/tty_audit-use-kzalloc-in-tty_audit_buf_alloc.patch + patches.suse/tty_audit-invert-the-condition-in-tty_audit_log.patch + patches.suse/tty_audit-make-icanon-a-bool.patch + patches.suse/tty_audit-make-data-of-tty_audit_log-const.patch + patches.suse/kill-do_each_thread.patch + patches.suse/tty-make-check_tty_count-void.patch patches.suse/serial-arc_uart-simplify-flags-handling-in-arc_serial_rx_chars.patch patches.suse/serial-omap-serial-remove-flag-from-serial_omap_rdi.patch patches.suse/serial-drivers-switch-ch-and-flag-to-u8.patch @@ -20525,6 +20534,13 @@ patches.suse/8250_men_mcb-Make-UART-config-auto-configurable.patch patches.suse/tty-serial-8250-Define-earlycon-for-mrvl-mmp-uart.patch patches.suse/8250_men_mcb-fix-error-handling-in-read_uarts_available_from_reg.patch + patches.suse/tty-change-tty_write_lock-s-ndelay-parameter-to-bool.patch + patches.suse/tty-don-t-pass-write-to-do_tty_write.patch + patches.suse/tty-rename-and-de-inline-do_tty_write.patch + patches.suse/tty-use-min-in-iterate_tty_write.patch + patches.suse/tty-use-ssize_t-for-iterate_tty_read-returned-type.patch + patches.suse/tty-switch-size-and-count-types-in-iterate_tty_read-to-size_t.patch + patches.suse/tty-use-min-for-size-computation-in-iterate_tty_read.patch patches.suse/serial-8250_bcm7271-improve-bcm7271-8250-port.patch patches.suse/printk-Reduce-console_unblank-usage-in-unsafe-scenarios.patch patches.suse/printk-Keep-non-panic-CPUs-out-of-console-lock.patch @@ -20632,8 +20648,6 @@ # commit a27814b8cd8f89ad68e29d3d6f8f3b61c65aebf5 ################################################# - - # v6.6.20-rt25 patches.suse/printk-Add-non-BKL-console-basic-infrastructure.patch patches.suse/printk-nobkl-Add-acquire-release-logic.patch patches.suse/printk-nobkl-Add-buffer-management.patch @@ -20657,6 +20671,10 @@ patches.suse/printk-Update-the-printk-series.patch patches.suse/printk-nbcon-move-locked_port-flag-to-struct-uart_port.patch patches.suse/drm-i915-guc-Consider-also-RCU-depth-in-busy-loop.patch + patches.suse/tty-early-return-from-send_break-on-TTY_DRIVER_HARDWARE_BREAK.patch + patches.suse/tty-don-t-check-for-signal_pending-in-send_break.patch + patches.suse/tty-use-if-in-send_break-instead-of-goto.patch + patches.suse/usb-cdc-acm-return-correct-error-code-on-unsupported-break.patch ######################################################## # SLERT-specific patches