nvdimm: virtio_pmem: publish done with release/acquire

virtio_pmem_host_ack() publishes the device response by setting done and
waking the submitter. The submitter reads resp.ret after wait_event()
observes done.

Use smp_store_release() on done and smp_load_acquire() in the wait
condition so the response read is ordered after completion.

Signed-off-by: Li Chen <me@linux.beauty>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Message-ID: <20260630092338.2094628-10-me@linux.beauty>
This commit is contained in:
Li Chen 2026-06-30 17:23:34 +08:00 committed by Michael S. Tsirkin
parent e57140944b
commit 3f14003ce7

View File

@ -23,6 +23,19 @@ static void virtio_pmem_req_release(struct kref *kref)
kfree(req);
}
static void virtio_pmem_signal_done(struct virtio_pmem_request *req)
{
/* Pairs with smp_load_acquire() in virtio_pmem_req_done(). */
smp_store_release(&req->done, true);
wake_up(&req->host_acked);
}
static bool virtio_pmem_req_done(struct virtio_pmem_request *req)
{
/* Pairs with smp_store_release() in virtio_pmem_signal_done(). */
return smp_load_acquire(&req->done);
}
static void virtio_pmem_wake_one_waiter(struct virtio_pmem *vpmem)
{
struct virtio_pmem_request *req_buf;
@ -48,8 +61,7 @@ void virtio_pmem_host_ack(struct virtqueue *vq)
spin_lock_irqsave(&vpmem->pmem_lock, flags);
while ((req_data = virtqueue_get_buf(vq, &len)) != NULL) {
virtio_pmem_wake_one_waiter(vpmem);
WRITE_ONCE(req_data->done, true);
wake_up(&req_data->host_acked);
virtio_pmem_signal_done(req_data);
kref_put(&req_data->kref, virtio_pmem_req_release);
}
spin_unlock_irqrestore(&vpmem->pmem_lock, flags);
@ -136,7 +148,8 @@ static int virtio_pmem_flush(struct nd_region *nd_region)
err = -EIO;
} else {
/* A host response results in "host_ack" getting called */
wait_event(req_data->host_acked, READ_ONCE(req_data->done));
wait_event(req_data->host_acked,
virtio_pmem_req_done(req_data));
err = le32_to_cpu(req_data->resp.ret);
}