mirror of
https://github.com/torvalds/linux.git
synced 2026-04-21 16:23:59 -04:00
The driver could possibly sleep while in atomic context resulting
in the following call trace while CONFIG_DEBUG_ATOMIC_SLEEP=y is
set:
BUG: sleeping function called from invalid context at kernel/locking/mutex.c:283
in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 2817, name: bash
preempt_count: 1, expected: 0
RCU nest depth: 0, expected: 0
Call Trace:
<TASK>
dump_stack_lvl+0x36/0x50
__might_resched+0x123/0x170
mutex_lock+0x1e/0x50
pds_vfio_put_lm_file+0x1e/0xa0 [pds_vfio_pci]
pds_vfio_put_save_file+0x19/0x30 [pds_vfio_pci]
pds_vfio_state_mutex_unlock+0x2e/0x80 [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
This can happen if pds_vfio_put_restore_file() and/or
pds_vfio_put_save_file() grab the mutex_lock(&lm_file->lock)
while the spin_lock(&pds_vfio->reset_lock) is held, which can
happen during while calling pds_vfio_state_mutex_unlock().
Fix this by changing the reset_lock to reset_mutex so there are no such
conerns. Also, make sure to destroy the reset_mutex in the driver specific
VFIO device release function.
This also fixes a spinlock bad magic BUG that was caused
by not calling spinlock_init() on the reset_lock. Since, the lock is
being changed to a mutex, make sure to call mutex_init() on it.
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/kvm/1f9bc27b-3de9-4891-9687-ba2820c1b390@moroto.mountain/
Fixes: bb500dbe2a ("vfio/pds: Add VFIO live migration support")
Signed-off-by: Brett Creeley <brett.creeley@amd.com>
Reviewed-by: Shannon Nelson <shannon.nelson@amd.com>
Link: https://lore.kernel.org/r/20231122192532.25791-3-brett.creeley@amd.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
40 lines
1.1 KiB
C
40 lines
1.1 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
/* Copyright(c) 2023 Advanced Micro Devices, Inc. */
|
|
|
|
#ifndef _VFIO_DEV_H_
|
|
#define _VFIO_DEV_H_
|
|
|
|
#include <linux/pci.h>
|
|
#include <linux/vfio_pci_core.h>
|
|
|
|
#include "dirty.h"
|
|
#include "lm.h"
|
|
|
|
struct pds_vfio_pci_device {
|
|
struct vfio_pci_core_device vfio_coredev;
|
|
|
|
struct pds_vfio_lm_file *save_file;
|
|
struct pds_vfio_lm_file *restore_file;
|
|
struct pds_vfio_dirty dirty;
|
|
struct mutex state_mutex; /* protect migration state */
|
|
enum vfio_device_mig_state state;
|
|
struct mutex reset_mutex; /* protect reset_done flow */
|
|
u8 deferred_reset;
|
|
enum vfio_device_mig_state deferred_reset_state;
|
|
struct notifier_block nb;
|
|
|
|
int vf_id;
|
|
u16 client_id;
|
|
};
|
|
|
|
void pds_vfio_state_mutex_unlock(struct pds_vfio_pci_device *pds_vfio);
|
|
|
|
const struct vfio_device_ops *pds_vfio_ops_info(void);
|
|
struct pds_vfio_pci_device *pds_vfio_pci_drvdata(struct pci_dev *pdev);
|
|
void pds_vfio_reset(struct pds_vfio_pci_device *pds_vfio);
|
|
|
|
struct pci_dev *pds_vfio_to_pci_dev(struct pds_vfio_pci_device *pds_vfio);
|
|
struct device *pds_vfio_to_dev(struct pds_vfio_pci_device *pds_vfio);
|
|
|
|
#endif /* _VFIO_DEV_H_ */
|