Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

video: hyperv_fb: Avoid taking busy spinlock on panic path

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.

Cc: Andrea Parri (Microsoft) <parri.andrea@gmail.com>
Cc: Dexuan Cui <decui@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Cc: "K. Y. Srinivasan" <kys@microsoft.com>
Cc: Michael Kelley <mikelley@microsoft.com>
Cc: Stephen Hemminger <sthemmin@microsoft.com>
Cc: Tianyu Lan <Tianyu.Lan@microsoft.com>
Cc: Wei Liu <wei.liu@kernel.org>
Tested-by: Fabio A M Martins <fabiomirmar@gmail.com>
Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
Link: https://lore.kernel.org/r/20220819221731.480795-10-gpiccoli@igalia.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>

authored by

Guilherme G. Piccoli and committed by
Wei Liu
1d044ca0 dc60f2db

+22 -1
+13
drivers/hv/ring_buffer.c
··· 280 280 ring_info->pkt_buffer_size = 0; 281 281 } 282 282 283 + /* 284 + * Check if the ring buffer spinlock is available to take or not; used on 285 + * atomic contexts, like panic path (see the Hyper-V framebuffer driver). 286 + */ 287 + 288 + bool hv_ringbuffer_spinlock_busy(struct vmbus_channel *channel) 289 + { 290 + struct hv_ring_buffer_info *rinfo = &channel->outbound; 291 + 292 + return spin_is_locked(&rinfo->ring_lock); 293 + } 294 + EXPORT_SYMBOL_GPL(hv_ringbuffer_spinlock_busy); 295 + 283 296 /* Write to the ring buffer. */ 284 297 int hv_ringbuffer_write(struct vmbus_channel *channel, 285 298 const struct kvec *kv_list, u32 kv_count,
+7 -1
drivers/video/fbdev/hyperv_fb.c
··· 780 780 static int hvfb_on_panic(struct notifier_block *nb, 781 781 unsigned long e, void *p) 782 782 { 783 + struct hv_device *hdev; 783 784 struct hvfb_par *par; 784 785 struct fb_info *info; 785 786 786 787 par = container_of(nb, struct hvfb_par, hvfb_panic_nb); 787 - par->synchronous_fb = true; 788 788 info = par->info; 789 + hdev = device_to_hv_device(info->device); 790 + 791 + if (hv_ringbuffer_spinlock_busy(hdev->channel)) 792 + return NOTIFY_DONE; 793 + 794 + par->synchronous_fb = true; 789 795 if (par->need_docopy) 790 796 hvfb_docopy(par, 0, dio_fb_size); 791 797 synthvid_update(info, 0, 0, INT_MAX, INT_MAX);
+2
include/linux/hyperv.h
··· 1341 1341 int hv_ringbuffer_get_debuginfo(struct hv_ring_buffer_info *ring_info, 1342 1342 struct hv_ring_buffer_debug_info *debug_info); 1343 1343 1344 + bool hv_ringbuffer_spinlock_busy(struct vmbus_channel *channel); 1345 + 1344 1346 /* Vmbus interface */ 1345 1347 #define vmbus_driver_register(driver) \ 1346 1348 __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)