From 2fa6e0b6a89929e16723e88846ab5e8444462197 Mon Sep 17 00:00:00 2001 From: "yang.yang29@zte.com.cn" Date: Thu, 8 Jun 2023 17:36:38 +0800 Subject: [PATCH 1/3] trace: Add migrate-disabled counter to tracing output commit 1425275046df0950d3bce5b586adf889c6d29aae upstream. Signed-off-by: Thomas Gleixner --- include/linux/trace_events.h | 2 ++ kernel/trace/trace.c | 26 +++++++++++++++++++------- kernel/trace/trace_events.c | 1 + kernel/trace/trace_output.c | 5 +++++ 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h index 36eebb055d79..fb5a55dcd071 100644 --- a/include/linux/trace_events.h +++ b/include/linux/trace_events.h @@ -68,6 +68,7 @@ struct trace_entry { unsigned char flags; unsigned char preempt_count; int pid; + unsigned char migrate_disable; }; #define TRACE_EVENT_TYPE_MAX \ @@ -156,6 +157,7 @@ static inline void tracing_generic_entry_update(struct trace_entry *entry, unsigned int trace_ctx) { entry->preempt_count = trace_ctx & 0xff; + entry->migrate_disable = (trace_ctx >> 8) & 0xff; entry->pid = current->pid; entry->type = type; entry->flags = trace_ctx >> 16; diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 6827f72c8179..873b0bba5347 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -2593,6 +2593,15 @@ enum print_line_t trace_handle_return(struct trace_seq *s) } EXPORT_SYMBOL_GPL(trace_handle_return); +static unsigned short migration_disable_value(void) +{ +#if defined(CONFIG_SMP) && defined(CONFIG_PREEMPT_RT) + return current->migration_disabled; +#else + return 0; +#endif +} + unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status) { unsigned int trace_flags = irqs_status; @@ -2611,7 +2620,8 @@ unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status) trace_flags |= TRACE_FLAG_NEED_RESCHED; if (test_preempt_need_resched()) trace_flags |= TRACE_FLAG_PREEMPT_RESCHED; - return (trace_flags << 16) | (pc & 0xff); + return (trace_flags << 16) | (pc & 0xff) | + (migration_disable_value() & 0xff) << 8; } struct ring_buffer_event * @@ -3812,9 +3822,10 @@ static void print_lat_help_header(struct seq_file *m) "# | / _----=> need-resched \n" "# || / _---=> hardirq/softirq \n" "# ||| / _--=> preempt-depth \n" - "# |||| / delay \n" - "# cmd pid ||||| time | caller \n" - "# \\ / ||||| \\ | / \n"); + "# |||| / _-=> migrate-disable \n" + "# ||||| / delay \n" + "# cmd pid |||||| time | caller \n" + "# \\ / |||||| \\ | / \n"); } static void print_event_info(struct array_buffer *buf, struct seq_file *m) @@ -3852,9 +3863,10 @@ static void print_func_help_header_irq(struct array_buffer *buf, struct seq_file seq_printf(m, "# %.*s / _----=> need-resched\n", prec, space); seq_printf(m, "# %.*s| / _---=> hardirq/softirq\n", prec, space); seq_printf(m, "# %.*s|| / _--=> preempt-depth\n", prec, space); - seq_printf(m, "# %.*s||| / delay\n", prec, space); - seq_printf(m, "# TASK-PID %.*s CPU# |||| TIMESTAMP FUNCTION\n", prec, " TGID "); - seq_printf(m, "# | | %.*s | |||| | |\n", prec, " | "); + seq_printf(m, "# %.*s||| / _-=> migrate-disable\n", prec, space); + seq_printf(m, "# %.*s|||| / delay\n", prec, space); + seq_printf(m, "# TASK-PID %.*s CPU# ||||| TIMESTAMP FUNCTION\n", prec, " TGID "); + seq_printf(m, "# | | %.*s | ||||| | |\n", prec, " | "); } void diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index 065ba69bde5e..cc8ce5d95e76 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c @@ -183,6 +183,7 @@ static int trace_define_common_fields(void) __common_field(unsigned char, flags); __common_field(unsigned char, preempt_count); __common_field(int, pid); + __common_field(unsigned char, migrate_disable); return ret; } diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c index 7042544c5bde..edc9e7c07170 100644 --- a/kernel/trace/trace_output.c +++ b/kernel/trace/trace_output.c @@ -487,6 +487,11 @@ int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry) else trace_seq_putc(s, '.'); + if (entry->migrate_disable) + trace_seq_printf(s, "%x", entry->migrate_disable); + else + trace_seq_putc(s, '.'); + return !trace_seq_has_overflowed(s); } -- Gitee From 5323fa9f99024d3ea9959b52a5250535a1a0d671 Mon Sep 17 00:00:00 2001 From: "yang.yang29@zte.com.cn" Date: Thu, 8 Jun 2023 17:39:44 +0800 Subject: [PATCH 2/3] locking: don't check for __LINUX_SPINLOCK_TYPES_H on -RT archs commit 8fb673bf14de13df961e2e2146b0ad8f061bac3d upstream. Upstream uses arch_spinlock_t within spinlock_t and requests that spinlock_types.h header file is included first. On -RT we have the rt_mutex with its raw_lock wait_lock which needs architectures' spinlock_types.h header file for its definition. However we need rt_mutex first because it is used to build the spinlock_t so that check does not work for us. Therefore I am dropping that check. Signed-off-by: Sebastian Andrzej Siewior --- arch/alpha/include/asm/spinlock_types.h | 4 ---- arch/arm/include/asm/spinlock_types.h | 4 ---- arch/arm64/include/asm/spinlock_types.h | 4 ---- arch/hexagon/include/asm/spinlock_types.h | 4 ---- arch/ia64/include/asm/spinlock_types.h | 4 ---- arch/powerpc/include/asm/spinlock_types.h | 4 ---- arch/s390/include/asm/spinlock_types.h | 4 ---- arch/sh/include/asm/spinlock_types.h | 4 ---- arch/xtensa/include/asm/spinlock_types.h | 4 ---- 9 files changed, 36 deletions(-) diff --git a/arch/alpha/include/asm/spinlock_types.h b/arch/alpha/include/asm/spinlock_types.h index 1d5716bc060b..6883bc952d22 100644 --- a/arch/alpha/include/asm/spinlock_types.h +++ b/arch/alpha/include/asm/spinlock_types.h @@ -2,10 +2,6 @@ #ifndef _ALPHA_SPINLOCK_TYPES_H #define _ALPHA_SPINLOCK_TYPES_H -#ifndef __LINUX_SPINLOCK_TYPES_H -# error "please don't include this file directly" -#endif - typedef struct { volatile unsigned int lock; } arch_spinlock_t; diff --git a/arch/arm/include/asm/spinlock_types.h b/arch/arm/include/asm/spinlock_types.h index 5976958647fe..a37c0803954b 100644 --- a/arch/arm/include/asm/spinlock_types.h +++ b/arch/arm/include/asm/spinlock_types.h @@ -2,10 +2,6 @@ #ifndef __ASM_SPINLOCK_TYPES_H #define __ASM_SPINLOCK_TYPES_H -#ifndef __LINUX_SPINLOCK_TYPES_H -# error "please don't include this file directly" -#endif - #define TICKET_SHIFT 16 typedef struct { diff --git a/arch/arm64/include/asm/spinlock_types.h b/arch/arm64/include/asm/spinlock_types.h index 18782f0c4721..6672b05350b4 100644 --- a/arch/arm64/include/asm/spinlock_types.h +++ b/arch/arm64/include/asm/spinlock_types.h @@ -5,10 +5,6 @@ #ifndef __ASM_SPINLOCK_TYPES_H #define __ASM_SPINLOCK_TYPES_H -#if !defined(__LINUX_SPINLOCK_TYPES_H) && !defined(__ASM_SPINLOCK_H) -# error "please don't include this file directly" -#endif - #include #include diff --git a/arch/hexagon/include/asm/spinlock_types.h b/arch/hexagon/include/asm/spinlock_types.h index 19d233497ba5..de72fb23016d 100644 --- a/arch/hexagon/include/asm/spinlock_types.h +++ b/arch/hexagon/include/asm/spinlock_types.h @@ -8,10 +8,6 @@ #ifndef _ASM_SPINLOCK_TYPES_H #define _ASM_SPINLOCK_TYPES_H -#ifndef __LINUX_SPINLOCK_TYPES_H -# error "please don't include this file directly" -#endif - typedef struct { volatile unsigned int lock; } arch_spinlock_t; diff --git a/arch/ia64/include/asm/spinlock_types.h b/arch/ia64/include/asm/spinlock_types.h index 6e345fefcdca..681408d6816f 100644 --- a/arch/ia64/include/asm/spinlock_types.h +++ b/arch/ia64/include/asm/spinlock_types.h @@ -2,10 +2,6 @@ #ifndef _ASM_IA64_SPINLOCK_TYPES_H #define _ASM_IA64_SPINLOCK_TYPES_H -#ifndef __LINUX_SPINLOCK_TYPES_H -# error "please don't include this file directly" -#endif - typedef struct { volatile unsigned int lock; } arch_spinlock_t; diff --git a/arch/powerpc/include/asm/spinlock_types.h b/arch/powerpc/include/asm/spinlock_types.h index c5d742f18021..cc6922a011ba 100644 --- a/arch/powerpc/include/asm/spinlock_types.h +++ b/arch/powerpc/include/asm/spinlock_types.h @@ -2,10 +2,6 @@ #ifndef _ASM_POWERPC_SPINLOCK_TYPES_H #define _ASM_POWERPC_SPINLOCK_TYPES_H -#ifndef __LINUX_SPINLOCK_TYPES_H -# error "please don't include this file directly" -#endif - #ifdef CONFIG_PPC_QUEUED_SPINLOCKS #include #include diff --git a/arch/s390/include/asm/spinlock_types.h b/arch/s390/include/asm/spinlock_types.h index cfed272e4fd5..8e28e8176ec8 100644 --- a/arch/s390/include/asm/spinlock_types.h +++ b/arch/s390/include/asm/spinlock_types.h @@ -2,10 +2,6 @@ #ifndef __ASM_SPINLOCK_TYPES_H #define __ASM_SPINLOCK_TYPES_H -#ifndef __LINUX_SPINLOCK_TYPES_H -# error "please don't include this file directly" -#endif - typedef struct { int lock; } __attribute__ ((aligned (4))) arch_spinlock_t; diff --git a/arch/sh/include/asm/spinlock_types.h b/arch/sh/include/asm/spinlock_types.h index e82369f286a2..22ca9a98bbb8 100644 --- a/arch/sh/include/asm/spinlock_types.h +++ b/arch/sh/include/asm/spinlock_types.h @@ -2,10 +2,6 @@ #ifndef __ASM_SH_SPINLOCK_TYPES_H #define __ASM_SH_SPINLOCK_TYPES_H -#ifndef __LINUX_SPINLOCK_TYPES_H -# error "please don't include this file directly" -#endif - typedef struct { volatile unsigned int lock; } arch_spinlock_t; diff --git a/arch/xtensa/include/asm/spinlock_types.h b/arch/xtensa/include/asm/spinlock_types.h index 64c9389254f1..dc846323b1cd 100644 --- a/arch/xtensa/include/asm/spinlock_types.h +++ b/arch/xtensa/include/asm/spinlock_types.h @@ -2,10 +2,6 @@ #ifndef __ASM_SPINLOCK_TYPES_H #define __ASM_SPINLOCK_TYPES_H -#if !defined(__LINUX_SPINLOCK_TYPES_H) && !defined(__ASM_SPINLOCK_H) -# error "please don't include this file directly" -#endif - #include #include -- Gitee From 5efab399e2700b2ecc37351fe3fedb601fa67e0f Mon Sep 17 00:00:00 2001 From: "yang.yang29@zte.com.cn" Date: Thu, 8 Jun 2023 17:39:55 +0800 Subject: [PATCH 3/3] locking: Make spinlock_t and rwlock_t a RCU section on RT commit c7fd6c36681b622aca780f43777d20fe1275a8f4 upstream. On !RT a locked spinlock_t and rwlock_t disables preemption which implies a RCU read section. There is code that relies on that behaviour. Add an explicit RCU read section on RT while a sleeping lock (a lock which would disables preemption on !RT) acquired. Signed-off-by: Sebastian Andrzej Siewior --- kernel/locking/rtmutex.c | 6 ++++++ kernel/locking/rwlock-rt.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c index 273f0865df0d..3356e0354013 100644 --- a/kernel/locking/rtmutex.c +++ b/kernel/locking/rtmutex.c @@ -1118,6 +1118,7 @@ void __lockfunc rt_spin_lock(spinlock_t *lock) { spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); rt_spin_lock_fastlock(&lock->lock, rt_spin_lock_slowlock); + rcu_read_lock(); migrate_disable(); } EXPORT_SYMBOL(rt_spin_lock); @@ -1132,6 +1133,7 @@ void __lockfunc rt_spin_lock_nested(spinlock_t *lock, int subclass) { spin_acquire(&lock->dep_map, subclass, 0, _RET_IP_); rt_spin_lock_fastlock(&lock->lock, rt_spin_lock_slowlock); + rcu_read_lock(); migrate_disable(); } EXPORT_SYMBOL(rt_spin_lock_nested); @@ -1141,6 +1143,7 @@ void __lockfunc rt_spin_lock_nest_lock(spinlock_t *lock, { spin_acquire_nest(&lock->dep_map, 0, 0, nest_lock, _RET_IP_); rt_spin_lock_fastlock(&lock->lock, rt_spin_lock_slowlock); + rcu_read_lock(); migrate_disable(); } EXPORT_SYMBOL(rt_spin_lock_nest_lock); @@ -1151,6 +1154,7 @@ void __lockfunc rt_spin_unlock(spinlock_t *lock) /* NOTE: we always pass in '1' for nested, for simplicity */ spin_release(&lock->dep_map, _RET_IP_); migrate_enable(); + rcu_read_unlock(); rt_spin_lock_fastunlock(&lock->lock, rt_spin_lock_slowunlock); } EXPORT_SYMBOL(rt_spin_unlock); @@ -1180,6 +1184,7 @@ int __lockfunc rt_spin_trylock(spinlock_t *lock) ret = __rt_mutex_trylock(&lock->lock); if (ret) { spin_acquire(&lock->dep_map, 0, 1, _RET_IP_); + rcu_read_lock(); migrate_disable(); } return ret; @@ -1194,6 +1199,7 @@ int __lockfunc rt_spin_trylock_bh(spinlock_t *lock) ret = __rt_mutex_trylock(&lock->lock); if (ret) { spin_acquire(&lock->dep_map, 0, 1, _RET_IP_); + rcu_read_lock(); migrate_disable(); } else { local_bh_enable(); diff --git a/kernel/locking/rwlock-rt.c b/kernel/locking/rwlock-rt.c index 16be7111aae7..3d2d1f14b513 100644 --- a/kernel/locking/rwlock-rt.c +++ b/kernel/locking/rwlock-rt.c @@ -270,6 +270,7 @@ int __lockfunc rt_read_trylock(rwlock_t *rwlock) ret = __read_rt_trylock(rwlock); if (ret) { rwlock_acquire_read(&rwlock->dep_map, 0, 1, _RET_IP_); + rcu_read_lock(); migrate_disable(); } return ret; @@ -283,6 +284,7 @@ int __lockfunc rt_write_trylock(rwlock_t *rwlock) ret = __write_rt_trylock(rwlock); if (ret) { rwlock_acquire(&rwlock->dep_map, 0, 1, _RET_IP_); + rcu_read_lock(); migrate_disable(); } return ret; @@ -293,6 +295,7 @@ void __lockfunc rt_read_lock(rwlock_t *rwlock) { rwlock_acquire_read(&rwlock->dep_map, 0, 0, _RET_IP_); __read_rt_lock(rwlock); + rcu_read_lock(); migrate_disable(); } EXPORT_SYMBOL(rt_read_lock); @@ -301,6 +304,7 @@ void __lockfunc rt_write_lock(rwlock_t *rwlock) { rwlock_acquire(&rwlock->dep_map, 0, 0, _RET_IP_); __write_rt_lock(rwlock); + rcu_read_lock(); migrate_disable(); } EXPORT_SYMBOL(rt_write_lock); @@ -309,6 +313,7 @@ void __lockfunc rt_read_unlock(rwlock_t *rwlock) { rwlock_release(&rwlock->dep_map, _RET_IP_); migrate_enable(); + rcu_read_unlock(); __read_rt_unlock(rwlock); } EXPORT_SYMBOL(rt_read_unlock); @@ -317,6 +322,7 @@ void __lockfunc rt_write_unlock(rwlock_t *rwlock) { rwlock_release(&rwlock->dep_map, _RET_IP_); migrate_enable(); + rcu_read_unlock(); __write_rt_unlock(rwlock); } EXPORT_SYMBOL(rt_write_unlock); -- Gitee