Add synchornize_cbs to rproc_virtio_config_ops and a synchronize_vqs callback to the rproc_ops to ensure vqs' state changes are visible in vring_interrupts when the vq is broken or removed. And when VIRTIO_HARDEN_NOTIFICATION is not set, call rproc_virtio_synchronize_cbs directly in __rproc_virtio_del_vqs before virtqueue is free to ensure that rproc_vq_interrupt is aware of the virtqueue removal. The synchronized_vqs is expected to be implemented in rproc driver to ensure that all previous vring_interrupts are handled before the vqs are marked as broken or removed. Signed-off-by: Mark-PK Tsai <mark-pk.tsai@xxxxxxxxxxxx> --- drivers/remoteproc/remoteproc_virtio.c | 12 ++++++++++++ include/linux/remoteproc.h | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/drivers/remoteproc/remoteproc_virtio.c b/drivers/remoteproc/remoteproc_virtio.c index d3f39009b28e..e18258b69851 100644 --- a/drivers/remoteproc/remoteproc_virtio.c +++ b/drivers/remoteproc/remoteproc_virtio.c @@ -74,6 +74,14 @@ static bool rproc_virtio_notify(struct virtqueue *vq) return true; } +static void rproc_virtio_synchronize_cbs(struct virtio_device *vdev) +{ + struct rproc *rproc = vdev_to_rproc(vdev); + + if (rproc->ops->synchronize_vqs) + rproc->ops->synchronize_vqs(rproc); +} + /** * rproc_vq_interrupt() - tell remoteproc that a virtqueue is interrupted * @rproc: handle to the remote processor @@ -171,6 +179,9 @@ static void __rproc_virtio_del_vqs(struct virtio_device *vdev) list_for_each_entry_safe(vq, n, &vdev->vqs, list) { rvring = vq->priv; rvring->vq = NULL; +#ifndef CONFIG_VIRTIO_HARDEN_NOTIFICATION + rproc_virtio_synchronize_cbs(vdev); +#endif vring_del_virtqueue(vq); } } @@ -334,6 +345,7 @@ static const struct virtio_config_ops rproc_virtio_config_ops = { .get_status = rproc_virtio_get_status, .get = rproc_virtio_get, .set = rproc_virtio_set, + .synchronize_cbs = rproc_virtio_synchronize_cbs, }; /* diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index b4795698d8c2..73901678ac7d 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -381,6 +381,9 @@ enum rsc_handling_status { * @panic: optional callback to react to system panic, core will delay * panic at least the returned number of milliseconds * @coredump: collect firmware dump after the subsystem is shutdown + * @synchronize_vqs: optional callback to guarantee all memory operations + * on the virtqueue before it are visible to the + * rproc_vq_interrupt(). */ struct rproc_ops { int (*prepare)(struct rproc *rproc); @@ -403,6 +406,7 @@ struct rproc_ops { u64 (*get_boot_addr)(struct rproc *rproc, const struct firmware *fw); unsigned long (*panic)(struct rproc *rproc); void (*coredump)(struct rproc *rproc); + void (*synchronize_vqs)(struct rproc *rproc); }; /** -- 2.45.2