[v3,vfio,1/3] pds/vfio: Fix spinlock bad magic BUG

Message ID 20231027223651.36047-2-brett.creeley@amd.com
State New
Headers
Series pds/vfio: Fixes for locking bugs |

Commit Message

Brett Creeley Oct. 27, 2023, 10:36 p.m. UTC
  The following BUG was found when running on a kernel with
CONFIG_DEBUG_SPINLOCK=y set:

BUG: spinlock bad magic on CPU#2, bash/2481
 lock: 0xffff8d6052a88f50, .magic: 00000000, .owner: <none>/-1, .owner_cpu: 0
Call Trace:
 <TASK>
 dump_stack_lvl+0x36/0x50
 do_raw_spin_lock+0x79/0xc0
 pds_vfio_reset+0x1d/0x60 [pds_vfio_pci]
 pci_reset_function+0x4b/0x70
 reset_store+0x5b/0xa0
 kernfs_fop_write_iter+0x137/0x1d0
 vfs_write+0x2de/0x410
 ksys_write+0x5d/0xd0
 do_syscall_64+0x3b/0x90
 entry_SYSCALL_64_after_hwframe+0x6e/0xd8

As shown, the .magic: 00000000, does not match the expected value. This
is because spin_lock_init() is never called for the reset_lock. Fix
this by calling spin_lock_init(&pds_vfio->reset_lock) when initializing
the device.

Signed-off-by: Brett Creeley <brett.creeley@amd.com>
Reviewed-by: Shannon Nelson <shannon.nelson@amd.com>
---
 drivers/vfio/pci/pds/vfio_dev.c | 2 ++
 1 file changed, 2 insertions(+)
  

Comments

Tian, Kevin Oct. 31, 2023, 6:13 a.m. UTC | #1
> From: Brett Creeley <brett.creeley@amd.com>
> Sent: Saturday, October 28, 2023 6:37 AM
> 
> The following BUG was found when running on a kernel with
> CONFIG_DEBUG_SPINLOCK=y set:
> 
> BUG: spinlock bad magic on CPU#2, bash/2481
>  lock: 0xffff8d6052a88f50, .magic: 00000000, .owner: <none>/-1, .owner_cpu:
> 0
> Call Trace:
>  <TASK>
>  dump_stack_lvl+0x36/0x50
>  do_raw_spin_lock+0x79/0xc0
>  pds_vfio_reset+0x1d/0x60 [pds_vfio_pci]
>  pci_reset_function+0x4b/0x70
>  reset_store+0x5b/0xa0
>  kernfs_fop_write_iter+0x137/0x1d0
>  vfs_write+0x2de/0x410
>  ksys_write+0x5d/0xd0
>  do_syscall_64+0x3b/0x90
>  entry_SYSCALL_64_after_hwframe+0x6e/0xd8
> 
> As shown, the .magic: 00000000, does not match the expected value. This
> is because spin_lock_init() is never called for the reset_lock. Fix
> this by calling spin_lock_init(&pds_vfio->reset_lock) when initializing
> the device.
> 
> Signed-off-by: Brett Creeley <brett.creeley@amd.com>
> Reviewed-by: Shannon Nelson <shannon.nelson@amd.com>

is this patch still required with patch3?
  
Brett Creeley Nov. 1, 2023, 7:18 p.m. UTC | #2
On 10/30/2023 11:13 PM, Tian, Kevin wrote:
> Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
> 
> 
>> From: Brett Creeley <brett.creeley@amd.com>
>> Sent: Saturday, October 28, 2023 6:37 AM
>>
>> The following BUG was found when running on a kernel with
>> CONFIG_DEBUG_SPINLOCK=y set:
>>
>> BUG: spinlock bad magic on CPU#2, bash/2481
>>   lock: 0xffff8d6052a88f50, .magic: 00000000, .owner: <none>/-1, .owner_cpu:
>> 0
>> Call Trace:
>>   <TASK>
>>   dump_stack_lvl+0x36/0x50
>>   do_raw_spin_lock+0x79/0xc0
>>   pds_vfio_reset+0x1d/0x60 [pds_vfio_pci]
>>   pci_reset_function+0x4b/0x70
>>   reset_store+0x5b/0xa0
>>   kernfs_fop_write_iter+0x137/0x1d0
>>   vfs_write+0x2de/0x410
>>   ksys_write+0x5d/0xd0
>>   do_syscall_64+0x3b/0x90
>>   entry_SYSCALL_64_after_hwframe+0x6e/0xd8
>>
>> As shown, the .magic: 00000000, does not match the expected value. This
>> is because spin_lock_init() is never called for the reset_lock. Fix
>> this by calling spin_lock_init(&pds_vfio->reset_lock) when initializing
>> the device.
>>
>> Signed-off-by: Brett Creeley <brett.creeley@amd.com>
>> Reviewed-by: Shannon Nelson <shannon.nelson@amd.com>
> 
> is this patch still required with patch3?

Good point. It's not required anymore since there is no spinlock.

Thanks,

Brett
  

Patch

diff --git a/drivers/vfio/pci/pds/vfio_dev.c b/drivers/vfio/pci/pds/vfio_dev.c
index 649b18ee394b..c351f588fa13 100644
--- a/drivers/vfio/pci/pds/vfio_dev.c
+++ b/drivers/vfio/pci/pds/vfio_dev.c
@@ -155,6 +155,8 @@  static int pds_vfio_init_device(struct vfio_device *vdev)
 
 	pds_vfio->vf_id = vf_id;
 
+	spin_lock_init(&pds_vfio->reset_lock);
+
 	vdev->migration_flags = VFIO_MIGRATION_STOP_COPY | VFIO_MIGRATION_P2P;
 	vdev->mig_ops = &pds_vfio_lm_ops;
 	vdev->log_ops = &pds_vfio_log_ops;