Skip to content

Commit 17b17be

Browse files
committed
Merge tag 'vfio-v6.7-rc4' of https://github.com/awilliam/linux-vfio
Pull vfio fixes from Alex Williamson: - Fix the lifecycle of a mutex in the pds variant driver such that a reset prior to opening the device won't find it uninitialized. Implement the release path to symmetrically destroy the mutex. Also switch a different lock from spinlock to mutex as the code path has the potential to sleep and doesn't need the spinlock context otherwise (Brett Creeley) - Fix an issue detected via randconfig where KVM tries to symbol_get an undeclared function. The symbol is temporarily declared unconditionally here, which resolves the problem and avoids churn relative to a series pending for the next merge window which resolves some of this symbol ugliness, but also fixes Kconfig dependencies (Sean Christopherson) * tag 'vfio-v6.7-rc4' of https://github.com/awilliam/linux-vfio: vfio: Drop vfio_file_iommu_group() stub to fudge around a KVM wart vfio/pds: Fix possible sleep while in atomic context vfio/pds: Fix mutex lock->magic != lock warning
2 parents deb4b9d + 4ea95c0 commit 17b17be

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

drivers/vfio/pci/pds/pci_drv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ static void pds_vfio_recovery(struct pds_vfio_pci_device *pds_vfio)
5555
* VFIO_DEVICE_STATE_RUNNING.
5656
*/
5757
if (deferred_reset_needed) {
58-
spin_lock(&pds_vfio->reset_lock);
58+
mutex_lock(&pds_vfio->reset_mutex);
5959
pds_vfio->deferred_reset = true;
6060
pds_vfio->deferred_reset_state = VFIO_DEVICE_STATE_ERROR;
61-
spin_unlock(&pds_vfio->reset_lock);
61+
mutex_unlock(&pds_vfio->reset_mutex);
6262
}
6363
}
6464

drivers/vfio/pci/pds/vfio_dev.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct pds_vfio_pci_device *pds_vfio_pci_drvdata(struct pci_dev *pdev)
2929
void pds_vfio_state_mutex_unlock(struct pds_vfio_pci_device *pds_vfio)
3030
{
3131
again:
32-
spin_lock(&pds_vfio->reset_lock);
32+
mutex_lock(&pds_vfio->reset_mutex);
3333
if (pds_vfio->deferred_reset) {
3434
pds_vfio->deferred_reset = false;
3535
if (pds_vfio->state == VFIO_DEVICE_STATE_ERROR) {
@@ -39,23 +39,23 @@ void pds_vfio_state_mutex_unlock(struct pds_vfio_pci_device *pds_vfio)
3939
}
4040
pds_vfio->state = pds_vfio->deferred_reset_state;
4141
pds_vfio->deferred_reset_state = VFIO_DEVICE_STATE_RUNNING;
42-
spin_unlock(&pds_vfio->reset_lock);
42+
mutex_unlock(&pds_vfio->reset_mutex);
4343
goto again;
4444
}
4545
mutex_unlock(&pds_vfio->state_mutex);
46-
spin_unlock(&pds_vfio->reset_lock);
46+
mutex_unlock(&pds_vfio->reset_mutex);
4747
}
4848

4949
void pds_vfio_reset(struct pds_vfio_pci_device *pds_vfio)
5050
{
51-
spin_lock(&pds_vfio->reset_lock);
51+
mutex_lock(&pds_vfio->reset_mutex);
5252
pds_vfio->deferred_reset = true;
5353
pds_vfio->deferred_reset_state = VFIO_DEVICE_STATE_RUNNING;
5454
if (!mutex_trylock(&pds_vfio->state_mutex)) {
55-
spin_unlock(&pds_vfio->reset_lock);
55+
mutex_unlock(&pds_vfio->reset_mutex);
5656
return;
5757
}
58-
spin_unlock(&pds_vfio->reset_lock);
58+
mutex_unlock(&pds_vfio->reset_mutex);
5959
pds_vfio_state_mutex_unlock(pds_vfio);
6060
}
6161

@@ -155,6 +155,9 @@ static int pds_vfio_init_device(struct vfio_device *vdev)
155155

156156
pds_vfio->vf_id = vf_id;
157157

158+
mutex_init(&pds_vfio->state_mutex);
159+
mutex_init(&pds_vfio->reset_mutex);
160+
158161
vdev->migration_flags = VFIO_MIGRATION_STOP_COPY | VFIO_MIGRATION_P2P;
159162
vdev->mig_ops = &pds_vfio_lm_ops;
160163
vdev->log_ops = &pds_vfio_log_ops;
@@ -168,6 +171,17 @@ static int pds_vfio_init_device(struct vfio_device *vdev)
168171
return 0;
169172
}
170173

174+
static void pds_vfio_release_device(struct vfio_device *vdev)
175+
{
176+
struct pds_vfio_pci_device *pds_vfio =
177+
container_of(vdev, struct pds_vfio_pci_device,
178+
vfio_coredev.vdev);
179+
180+
mutex_destroy(&pds_vfio->state_mutex);
181+
mutex_destroy(&pds_vfio->reset_mutex);
182+
vfio_pci_core_release_dev(vdev);
183+
}
184+
171185
static int pds_vfio_open_device(struct vfio_device *vdev)
172186
{
173187
struct pds_vfio_pci_device *pds_vfio =
@@ -179,7 +193,6 @@ static int pds_vfio_open_device(struct vfio_device *vdev)
179193
if (err)
180194
return err;
181195

182-
mutex_init(&pds_vfio->state_mutex);
183196
pds_vfio->state = VFIO_DEVICE_STATE_RUNNING;
184197
pds_vfio->deferred_reset_state = VFIO_DEVICE_STATE_RUNNING;
185198

@@ -199,14 +212,13 @@ static void pds_vfio_close_device(struct vfio_device *vdev)
199212
pds_vfio_put_save_file(pds_vfio);
200213
pds_vfio_dirty_disable(pds_vfio, true);
201214
mutex_unlock(&pds_vfio->state_mutex);
202-
mutex_destroy(&pds_vfio->state_mutex);
203215
vfio_pci_core_close_device(vdev);
204216
}
205217

206218
static const struct vfio_device_ops pds_vfio_ops = {
207219
.name = "pds-vfio",
208220
.init = pds_vfio_init_device,
209-
.release = vfio_pci_core_release_dev,
221+
.release = pds_vfio_release_device,
210222
.open_device = pds_vfio_open_device,
211223
.close_device = pds_vfio_close_device,
212224
.ioctl = vfio_pci_core_ioctl,

drivers/vfio/pci/pds/vfio_dev.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct pds_vfio_pci_device {
1818
struct pds_vfio_dirty dirty;
1919
struct mutex state_mutex; /* protect migration state */
2020
enum vfio_device_mig_state state;
21-
spinlock_t reset_lock; /* protect reset_done flow */
21+
struct mutex reset_mutex; /* protect reset_done flow */
2222
u8 deferred_reset;
2323
enum vfio_device_mig_state deferred_reset_state;
2424
struct notifier_block nb;

include/linux/vfio.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,16 +289,12 @@ void vfio_combine_iova_ranges(struct rb_root_cached *root, u32 cur_nodes,
289289
/*
290290
* External user API
291291
*/
292-
#if IS_ENABLED(CONFIG_VFIO_GROUP)
293292
struct iommu_group *vfio_file_iommu_group(struct file *file);
293+
294+
#if IS_ENABLED(CONFIG_VFIO_GROUP)
294295
bool vfio_file_is_group(struct file *file);
295296
bool vfio_file_has_dev(struct file *file, struct vfio_device *device);
296297
#else
297-
static inline struct iommu_group *vfio_file_iommu_group(struct file *file)
298-
{
299-
return NULL;
300-
}
301-
302298
static inline bool vfio_file_is_group(struct file *file)
303299
{
304300
return false;

0 commit comments

Comments
 (0)