rcu: Fix __this_cpu_read() lockdep warning in rcu_force_quiescent_state()
Subsystems (7)
Sasha Levin
maintainerPATCH 1/5 rcu: Fix __this_cpu_read() lockdep warning in rcu_force_quiescent_state()
From: Zqiang <[email protected]>
[ Upstream commit ceb1c8c9b8aa9199da46a0f29d2d5f08d9b44c15 ]
Running rcutorture with non-zero fqs_duration module parameter in a kernel built with CONFIG_PREEMPTION=y results in the following splat:
BUG: using __this_cpu_read() in preemptible [00000000] code: rcu_torture_fqs/398 caller is __this_cpu_preempt_check+0x13/0x20 CPU: 3 PID: 398 Comm: rcu_torture_fqs Not tainted 6.0.0-rc1-yoctodev-standard+ Call Trace: <TASK> dump_stack_lvl+0x5b/0x86 dump_stack+0x10/0x16 check_preemption_disabled+0xe5/0xf0 __this_cpu_preempt_check+0x13/0x20 rcu_force_quiescent_state.part.0+0x1c/0x170 rcu_force_quiescent_state+0x1e/0x30 rcu_torture_fqs+0xca/0x160 ? rcu_torture_boost+0x430/0x430 kthread+0x192/0x1d0 ? kthread_complete_and_exit+0x30/0x30 ret_from_fork+0x22/0x30 </TASK>
The problem is that rcu_force_quiescent_state() uses __this_cpu_read() in preemptible code instead of the proper raw_cpu_read(). This commit therefore changes __this_cpu_read() to raw_cpu_read().
--- kernel/rcu/tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/tree.c +1 -1
@@ -2650,7 +2650,7 @@ void rcu_force_quiescent_state(void)struct rcu_node *rnp_old =NULL ;/* Funnel through hierarchy to reduce memory contention. */ - rnp =__this_cpu_read (rcu_data.mynode); + rnp =raw_cpu_read (rcu_data.mynode);for (; rnp !=NULL ; rnp = rnp->parent) { ret = (READ_ONCE (rcu_state.gp_flags) &RCU_GP_FLAG_FQS ) || !raw_spin_trylock (&rnp->fqslock);
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 2/5 arm64: make is_ttbrX_addr() noinstr-safe
From: Mark Rutland <[email protected]>
[ Upstream commit d8c1d798a2e5091128c391c6dadcc9be334af3f5 ]
We use is_ttbr0_addr() in noinstr code, but as it's only marked as inline, it's theoretically possible for the compiler to place it out-of-line and instrument it, which would be problematic.
Mark is_ttbr0_addr() as __always_inline such that that can safely be used from noinstr code. For consistency, do the same to is_ttbr1_addr(). Note that while is_ttbr1_addr() calls arch_kasan_reset_tag(), this is a macro (and its callees are either macros or __always_inline), so there is not a risk of transient instrumentation.
--- arch/arm64/include/asm/processor.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/include/asm/processor.h +2 -2
@@ -230,13 +230,13 @@ static inline void compat_start_thread(struct pt_regs *regs, unsigned long pc, }#endif -static inline bool is_ttbr0_addr (unsigned long addr) +static __always_inline bool is_ttbr0_addr(unsigned long addr) {/* entry assembly clears tags for TTBR0 addrs */ return addr <TASK_SIZE ; } -static inline bool is_ttbr1_addr (unsigned long addr) +static __always_inline bool is_ttbr1_addr(unsigned long addr) {/* TTBR1 addresses may have a tag if KASAN_SW_TAGS is in use */ return arch_kasan_reset_tag (addr) >=PAGE_OFFSET ;
Signature · 7 lines
2.35.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Sasha Levin
maintainerPATCH 3/5 video: hyperv_fb: Avoid taking busy spinlock on panic path
In reply to Sasha LevinFrom: "Guilherme G. Piccoli" <[email protected]>
[ Upstream commit 1d044ca035dc22df0d3b39e56f2881071d9118bd ]
The Hyper-V framebuffer code registers a panic notifier in order to try updating its fbdev if the kernel crashed. The notifier callback is straightforward, but it calls the vmbus_sendpacket() routine eventually, and such function takes a spinlock for the ring buffer operations.
Panic path runs in atomic context, with local interrupts and preemption disabled, and all secondary CPUs shutdown. That said, taking a spinlock might cause a lockup if a secondary CPU was disabled with such lock taken. Fix it here by checking if the ring buffer spinlock is busy on Hyper-V framebuffer panic notifier; if so, bail-out avoiding the potential lockup scenario.
--- drivers/hv/ring_buffer.c | 13 +++++++++++++ drivers/video/fbdev/hyperv_fb.c | 8 +++++++- include/linux/hyperv.h | 2 ++ 3 files changed, 22 insertions(+), 1 deletion(-)
drivers/hv/ring_buffer.c +13 -0
@@ -246,6 +246,19 @@ void hv_ringbuffer_cleanup(struct hv_ring_buffer_info *ring_info)mutex_unlock (&ring_info->ring_buffer_mutex); } +/* +* Check if the ring buffer spinlock is available to take or not; used on +* atomic contexts, like panic path (see the Hyper-V framebuffer driver). +*/ + +bool hv_ringbuffer_spinlock_busy (struct vmbus_channel *channel) +{ +struct hv_ring_buffer_info *rinfo = &channel->outbound; + +return spin_is_locked (&rinfo->ring_lock); +} +EXPORT_SYMBOL_GPL (hv_ringbuffer_spinlock_busy); +/* Write to the ring buffer. */ int hv_ringbuffer_write (struct vmbus_channel *channel,const struct kvec *kv_list,u32 kv_count)
drivers/video/fbdev/hyperv_fb.c +7 -1
@@ -798,12 +798,18 @@ static void hvfb_ondemand_refresh_throttle(struct hvfb_par *par,static int hvfb_on_panic (struct notifier_block *nb,unsigned long e,void *p) { +struct hv_device *hdev;struct hvfb_par *par;struct fb_info *info; par = container_of(nb, struct hvfb_par, hvfb_panic_nb); - par->synchronous_fb = true; info = par->info; + hdev =device_to_hv_device (info->device); + +if (hv_ringbuffer_spinlock_busy (hdev->channel)) +return NOTIFY_DONE ; + + par->synchronous_fb = true;if (par->need_docopy)hvfb_docopy (par,0 , dio_fb_size);synthvid_update (info,0 ,0 ,INT_MAX ,INT_MAX );
include/linux/hyperv.h +2 -0
@@ -1269,6 +1269,8 @@ struct hv_ring_buffer_debug_info {int hv_ringbuffer_get_debuginfo (struct hv_ring_buffer_info *ring_info,struct hv_ring_buffer_debug_info *debug_info); +bool hv_ringbuffer_spinlock_busy (struct vmbus_channel *channel); +/* Vmbus interface */ #define vmbus_driver_register (driver) \ __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 4/5 x86/hyperv: Remove unregister syscore call from Hyper-V cleanup
In reply to Sasha LevinFrom: Gaurav Kohli <[email protected]>
[ Upstream commit 32c97d980e2eef25465d453f2956a9ca68926a3c ]
Hyper-V cleanup code comes under panic path where preemption and irq is already disabled. So calling of unregister_syscore_ops might schedule out the thread even for the case where mutex lock is free. hyperv_cleanup
unregister_syscore_ops
mutex_lock(&syscore_ops_lock)
might_sleep
Here might_sleep might schedule out this thread, where voluntary preemption config is on and this thread will never comes back. And also this was added earlier to maintain the symmetry which is not required as this can comes during crash shutdown path only.
To prevent the same, removing unregister_syscore_ops function call.
--- arch/x86/hyperv/hv_init.c | 2 -- 1 file changed, 2 deletions(-)
arch/x86/hyperv/hv_init.c +0 -2
@@ -453,8 +453,6 @@ void hyperv_cleanup(void) {union hv_x64_msr_hypercall_contents hypercall_msr; -unregister_syscore_ops (&hv_syscore_ops); -/* Reset our OS id */ wrmsrl (HV_X64_MSR_GUEST_OS_ID ,0 );
Signature · 1 line
2.35.1
Sasha Levin
maintainerPATCH 5/5 binfmt_misc: fix shift-out-of-bounds in check_special_flags
In reply to Sasha LevinFrom: Liu Shixin <[email protected]>
[ Upstream commit 6a46bf558803dd2b959ca7435a5c143efe837217 ]
UBSAN reported a shift-out-of-bounds warning:
left shift of 1 by 31 places cannot be represented in type 'int'
Call Trace: <TASK> __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0x8d/0xcf lib/dump_stack.c:106 ubsan_epilogue+0xa/0x44 lib/ubsan.c:151 __ubsan_handle_shift_out_of_bounds+0x1e7/0x208 lib/ubsan.c:322 check_special_flags fs/binfmt_misc.c:241 [inline] create_entry fs/binfmt_misc.c:456 [inline] bm_register_write+0x9d3/0xa20 fs/binfmt_misc.c:654 vfs_write+0x11e/0x580 fs/read_write.c:582 ksys_write+0xcf/0x120 fs/read_write.c:637 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x34/0x80 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd RIP: 0033:0x4194e1
Since the type of Node's flags is unsigned long, we should define these macros with same type too.
--- fs/binfmt_misc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/binfmt_misc.c +4 -4
@@ -44,10 +44,10 @@ static LIST_HEAD(entries);static int enabled =1 ;enum {Enabled, Magic}; -#define MISC_FMT_PRESERVE_ARGV0 (1 << 31) -#define MISC_FMT_OPEN_BINARY (1 << 30) -#define MISC_FMT_CREDENTIALS (1 << 29) -#define MISC_FMT_OPEN_FILE (1 << 28) +#define MISC_FMT_PRESERVE_ARGV0 (1UL << 31) +#define MISC_FMT_OPEN_BINARY (1UL << 30) +#define MISC_FMT_CREDENTIALS (1UL << 29) +#define MISC_FMT_OPEN_FILE (1UL << 28) typedef struct { struct list_head list;
Signature · 1 line
2.35.1