Skip to content

Commit bf1acf8

Browse files
cris-masudeep-holla
authored andcommitted
firmware: arm_scmi: Add proper barriers to scmi virtio device
Only one single SCMI Virtio device is currently supported by this driver and it is referenced using a static global variable which is initialized once for all during probing and nullified at virtio device removal. Add proper SMP barriers to protect accesses to such device reference to ensure that the initialzation state of such device is correctly observed by all PEs at any time. Return -EBUSY, instead of -EINVAL, and a descriptive error message if more than one SCMI Virtio device is ever found and probed. Link: https://lore.kernel.org/r/[email protected] Cc: "Michael S. Tsirkin" <[email protected]> Cc: Sudeep Holla <[email protected]> Signed-off-by: Cristian Marussi <[email protected]> Signed-off-by: Sudeep Holla <[email protected]>
1 parent a14a145 commit bf1acf8

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

drivers/firmware/arm_scmi/virtio.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,11 @@ static int scmi_vio_probe(struct virtio_device *vdev)
390390
struct virtqueue *vqs[VIRTIO_SCMI_VQ_MAX_CNT];
391391

392392
/* Only one SCMI VirtiO device allowed */
393-
if (scmi_vdev)
394-
return -EINVAL;
393+
if (scmi_vdev) {
394+
dev_err(dev,
395+
"One SCMI Virtio device was already initialized: only one allowed.\n");
396+
return -EBUSY;
397+
}
395398

396399
have_vq_rx = scmi_vio_have_vq_rx(vdev);
397400
vq_cnt = have_vq_rx ? VIRTIO_SCMI_VQ_MAX_CNT : 1;
@@ -434,7 +437,8 @@ static int scmi_vio_probe(struct virtio_device *vdev)
434437
}
435438

436439
vdev->priv = channels;
437-
scmi_vdev = vdev;
440+
/* Ensure initialized scmi_vdev is visible */
441+
smp_store_mb(scmi_vdev, vdev);
438442

439443
return 0;
440444
}
@@ -450,7 +454,8 @@ static void scmi_vio_remove(struct virtio_device *vdev)
450454
*/
451455
vdev->config->reset(vdev);
452456
vdev->config->del_vqs(vdev);
453-
scmi_vdev = NULL;
457+
/* Ensure scmi_vdev is visible as NULL */
458+
smp_store_mb(scmi_vdev, NULL);
454459
}
455460

456461
static int scmi_vio_validate(struct virtio_device *vdev)

0 commit comments

Comments
 (0)