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>
This commit is contained in:
Guilherme G. Piccoli 2022-08-19 19:17:29 -03:00 committed by Wei Liu
parent dc60f2db39
commit 1d044ca035
3 changed files with 22 additions and 1 deletions

View File

@ -280,6 +280,19 @@ void hv_ringbuffer_cleanup(struct hv_ring_buffer_info *ring_info)
ring_info->pkt_buffer_size = 0; ring_info->pkt_buffer_size = 0;
} }
/*
* 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. */ /* Write to the ring buffer. */
int hv_ringbuffer_write(struct vmbus_channel *channel, int hv_ringbuffer_write(struct vmbus_channel *channel,
const struct kvec *kv_list, u32 kv_count, const struct kvec *kv_list, u32 kv_count,

View File

@ -780,12 +780,18 @@ static void hvfb_ondemand_refresh_throttle(struct hvfb_par *par,
static int hvfb_on_panic(struct notifier_block *nb, static int hvfb_on_panic(struct notifier_block *nb,
unsigned long e, void *p) unsigned long e, void *p)
{ {
struct hv_device *hdev;
struct hvfb_par *par; struct hvfb_par *par;
struct fb_info *info; struct fb_info *info;
par = container_of(nb, struct hvfb_par, hvfb_panic_nb); par = container_of(nb, struct hvfb_par, hvfb_panic_nb);
par->synchronous_fb = true;
info = par->info; 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) if (par->need_docopy)
hvfb_docopy(par, 0, dio_fb_size); hvfb_docopy(par, 0, dio_fb_size);
synthvid_update(info, 0, 0, INT_MAX, INT_MAX); synthvid_update(info, 0, 0, INT_MAX, INT_MAX);

View File

@ -1341,6 +1341,8 @@ struct hv_ring_buffer_debug_info {
int hv_ringbuffer_get_debuginfo(struct hv_ring_buffer_info *ring_info, int hv_ringbuffer_get_debuginfo(struct hv_ring_buffer_info *ring_info,
struct hv_ring_buffer_debug_info *debug_info); struct hv_ring_buffer_debug_info *debug_info);
bool hv_ringbuffer_spinlock_busy(struct vmbus_channel *channel);
/* Vmbus interface */ /* Vmbus interface */
#define vmbus_driver_register(driver) \ #define vmbus_driver_register(driver) \
__vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME) __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)