Skip to content

Commit fa2e694

Browse files
pizhenweimstsirkin
authored andcommitted
virtio-crypto: handle config changed by work queue
MST pointed out: config change callback is also handled incorrectly in this driver, it takes a mutex from interrupt context. Handle config changed by work queue instead. Cc: [email protected] Cc: Gonglei (Arei) <[email protected]> Cc: Halil Pasic <[email protected]> Cc: Michael S. Tsirkin <[email protected]> Signed-off-by: zhenwei pi <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent ca50ec3 commit fa2e694

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

drivers/crypto/virtio/virtio_crypto_common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ struct virtio_crypto {
3535
struct virtqueue *ctrl_vq;
3636
struct data_queue *data_vq;
3737

38+
/* Work struct for config space updates */
39+
struct work_struct config_work;
40+
3841
/* To protect the vq operations for the controlq */
3942
spinlock_t ctrl_lock;
4043

drivers/crypto/virtio/virtio_crypto_core.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,14 @@ static void virtcrypto_del_vqs(struct virtio_crypto *vcrypto)
335335
virtcrypto_free_queues(vcrypto);
336336
}
337337

338+
static void vcrypto_config_changed_work(struct work_struct *work)
339+
{
340+
struct virtio_crypto *vcrypto =
341+
container_of(work, struct virtio_crypto, config_work);
342+
343+
virtcrypto_update_status(vcrypto);
344+
}
345+
338346
static int virtcrypto_probe(struct virtio_device *vdev)
339347
{
340348
int err = -EFAULT;
@@ -454,6 +462,8 @@ static int virtcrypto_probe(struct virtio_device *vdev)
454462
if (err)
455463
goto free_engines;
456464

465+
INIT_WORK(&vcrypto->config_work, vcrypto_config_changed_work);
466+
457467
return 0;
458468

459469
free_engines:
@@ -490,6 +500,7 @@ static void virtcrypto_remove(struct virtio_device *vdev)
490500

491501
dev_info(&vdev->dev, "Start virtcrypto_remove.\n");
492502

503+
flush_work(&vcrypto->config_work);
493504
if (virtcrypto_dev_started(vcrypto))
494505
virtcrypto_dev_stop(vcrypto);
495506
virtio_reset_device(vdev);
@@ -504,14 +515,15 @@ static void virtcrypto_config_changed(struct virtio_device *vdev)
504515
{
505516
struct virtio_crypto *vcrypto = vdev->priv;
506517

507-
virtcrypto_update_status(vcrypto);
518+
schedule_work(&vcrypto->config_work);
508519
}
509520

510521
#ifdef CONFIG_PM_SLEEP
511522
static int virtcrypto_freeze(struct virtio_device *vdev)
512523
{
513524
struct virtio_crypto *vcrypto = vdev->priv;
514525

526+
flush_work(&vcrypto->config_work);
515527
virtio_reset_device(vdev);
516528
virtcrypto_free_unused_reqs(vcrypto);
517529
if (virtcrypto_dev_started(vcrypto))

0 commit comments

Comments
 (0)