On Wed, 18 Jul 2018 11:22:36 -0700
Andrei Vagin <ava...@virtuozzo.com> wrote:

> On Tue, Jul 10, 2018 at 07:28:49PM -0700, Nambiar, Amritha wrote:
> > On 7/4/2018 12:20 AM, Andrei Vagin wrote:  
> > > Hello Amritha,
> > > 
> > > I see a following warning on 4.18.0-rc3-next-20180703.
> > > It looks like a problem is in this series.
> > > 
> > > [    1.084722] ============================================
> > > [    1.084797] WARNING: possible recursive locking detected
> > > [    1.084872] 4.18.0-rc3-next-20180703+ #1 Not tainted
> > > [    1.084949] --------------------------------------------
> > > [    1.085024] swapper/0/1 is trying to acquire lock:
> > > [    1.085100] 00000000cf973d46 (cpu_hotplug_lock.rw_sem){++++}, at: 
> > > static_key_slow_inc+0xe/0x20
> > > [    1.085189] 
> > > [    1.085189] but task is already holding lock:
> > > [    1.085271] 00000000cf973d46 (cpu_hotplug_lock.rw_sem){++++}, at: 
> > > init_vqs+0x513/0x5a0
> > > [    1.085357] 
> > > [    1.085357] other info that might help us debug this:
> > > [    1.085450]  Possible unsafe locking scenario:
> > > [    1.085450] 
> > > [    1.085531]        CPU0
> > > [    1.085605]        ----
> > > [    1.085679]   lock(cpu_hotplug_lock.rw_sem);
> > > [    1.085753]   lock(cpu_hotplug_lock.rw_sem);
> > > [    1.085828] 
> > > [    1.085828]  *** DEADLOCK ***
> > > [    1.085828] 
> > > [    1.085916]  May be due to missing lock nesting notation
> > > [    1.085916] 
> > > [    1.085998] 3 locks held by swapper/0/1:
> > > [    1.086074]  #0: 00000000244bc7da (&dev->mutex){....}, at: 
> > > __driver_attach+0x5a/0x110
> > > [    1.086164]  #1: 00000000cf973d46 (cpu_hotplug_lock.rw_sem){++++}, at: 
> > > init_vqs+0x513/0x5a0
> > > [    1.086248]  #2: 000000005cd8463f (xps_map_mutex){+.+.}, at: 
> > > __netif_set_xps_queue+0x8d/0xc60
> > > [    1.086336] 
> > > [    1.086336] stack backtrace:
> > > [    1.086419] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 
> > > 4.18.0-rc3-next-20180703+ #1
> > > [    1.086504] Hardware name: Google Google Compute Engine/Google Compute 
> > > Engine, BIOS Google 01/01/2011
> > > [    1.086587] Call Trace:
> > > [    1.086667]  dump_stack+0x85/0xcb
> > > [    1.086744]  __lock_acquire+0x68a/0x1330
> > > [    1.086821]  ? lock_acquire+0x9f/0x200
> > > [    1.086900]  ? find_held_lock+0x2d/0x90
> > > [    1.086976]  ? lock_acquire+0x9f/0x200
> > > [    1.087051]  lock_acquire+0x9f/0x200
> > > [    1.087126]  ? static_key_slow_inc+0xe/0x20
> > > [    1.087205]  cpus_read_lock+0x3e/0x80
> > > [    1.087280]  ? static_key_slow_inc+0xe/0x20
> > > [    1.087355]  static_key_slow_inc+0xe/0x20
> > > [    1.087435]  __netif_set_xps_queue+0x216/0xc60
> > > [    1.087512]  virtnet_set_affinity+0xf0/0x130
> > > [    1.087589]  init_vqs+0x51b/0x5a0
> > > [    1.087665]  virtnet_probe+0x39f/0x870
> > > [    1.087742]  virtio_dev_probe+0x170/0x220
> > > [    1.087819]  driver_probe_device+0x30b/0x480
> > > [    1.087897]  ? set_debug_rodata+0x11/0x11
> > > [    1.087972]  __driver_attach+0xe0/0x110
> > > [    1.088064]  ? driver_probe_device+0x480/0x480
> > > [    1.088141]  bus_for_each_dev+0x79/0xc0
> > > [    1.088221]  bus_add_driver+0x164/0x260
> > > [    1.088302]  ? veth_init+0x11/0x11
> > > [    1.088379]  driver_register+0x5b/0xe0
> > > [    1.088402]  ? veth_init+0x11/0x11
> > > [    1.088402]  virtio_net_driver_init+0x6d/0x90
> > > [    1.088402]  do_one_initcall+0x5d/0x34c
> > > [    1.088402]  ? set_debug_rodata+0x11/0x11
> > > [    1.088402]  ? rcu_read_lock_sched_held+0x6b/0x80
> > > [    1.088402]  kernel_init_freeable+0x1ea/0x27b
> > > [    1.088402]  ? rest_init+0xd0/0xd0
> > > [    1.088402]  kernel_init+0xa/0x110
> > > [    1.088402]  ret_from_fork+0x3a/0x50
> > > [    1.094190] i8042: PNP: PS/2 Controller [PNP0303:KBD,PNP0f13:MOU] at 
> > > 0x60,0x64 irq 1,12
> > > 
> > > 
> > > https://travis-ci.org/avagin/linux/jobs/399867744
> > >   
> > 
> > With this patch series, I introduced static_key for XPS maps
> > (xps_needed), so static_key_slow_inc() is used to switch branches. The
> > definition of static_key_slow_inc() has cpus_read_lock in place. In the
> > virtio_net driver, XPS queues are initialized after setting the
> > queue:cpu affinity in virtnet_set_affinity() which is already protected
> > within cpus_read_lock. Hence, the warning here trying to acquire
> > cpus_read_lock when it is already held.
> > 
> > A quick fix for this would be to just extract netif_set_xps_queue() out
> > of the lock by simply wrapping it with another put/get_online_cpus
> > (unlock right before and hold lock right after). But this may not a
> > clean solution. It'd help if I can get suggestions on what would be a
> > clean option to fix this without extensively changing the code in
> > virtio_net. Is it mandatory to protect the affinitization with
> > read_lock? I don't see similar lock in other drivers while setting the
> > affinity.  
> 
> > I understand this warning should go away, but isn't it safe to
> > have multiple readers.  
> 
> Peter and Ingo, maybe you could explain why it isn't safe to take one
> reader lock twice?
> 
> Thanks,
> Andrei

I think the issue was that some architectures, I think read lock is equivalent 
to a spin lock.
But maybe that is no longer true, or know one remembers.

Reply via email to