Skip to content

Commit af9a17d

Browse files
bibo-maomstsirkin
authored andcommitted
crypto: virtio: Add spinlock protection with virtqueue notification
When VM boots with one virtio-crypto PCI device and builtin backend, run openssl benchmark command with multiple processes, such as openssl speed -evp aes-128-cbc -engine afalg -seconds 10 -multi 32 openssl processes will hangup and there is error reported like this: virtio_crypto virtio0: dataq.0:id 3 is not a head! It seems that the data virtqueue need protection when it is handled for virtio done notification. If the spinlock protection is added in virtcrypto_done_task(), openssl benchmark with multiple processes works well. Fixes: fed93fb ("crypto: virtio - Handle dataq logic with tasklet") Cc: stable@vger.kernel.org Signed-off-by: Bibo Mao <maobibo@loongson.cn> Acked-by: Jason Wang <jasowang@redhat.com> Acked-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Message-Id: <20260113030556.3522533-2-maobibo@loongson.cn>
1 parent 7a9dc24 commit af9a17d

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

drivers/crypto/virtio/virtio_crypto_core.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,20 @@ static void virtcrypto_done_task(unsigned long data)
7575
struct data_queue *data_vq = (struct data_queue *)data;
7676
struct virtqueue *vq = data_vq->vq;
7777
struct virtio_crypto_request *vc_req;
78+
unsigned long flags;
7879
unsigned int len;
7980

81+
spin_lock_irqsave(&data_vq->lock, flags);
8082
do {
8183
virtqueue_disable_cb(vq);
8284
while ((vc_req = virtqueue_get_buf(vq, &len)) != NULL) {
85+
spin_unlock_irqrestore(&data_vq->lock, flags);
8386
if (vc_req->alg_cb)
8487
vc_req->alg_cb(vc_req, len);
88+
spin_lock_irqsave(&data_vq->lock, flags);
8589
}
8690
} while (!virtqueue_enable_cb(vq));
91+
spin_unlock_irqrestore(&data_vq->lock, flags);
8792
}
8893

8994
static void virtcrypto_dataq_callback(struct virtqueue *vq)

0 commit comments

Comments
 (0)