Si-Wei Liu
2021-Dec-22 01:55 UTC
[PATCH v5 04/13] vdpa: Read device configuration only if FEATURES_OK
On 12/21/2021 9:19 AM, Eli Cohen wrote:> Avoid reading device configuration during feature negotiation. Read > device status and verify that VIRTIO_CONFIG_S_FEATURES_OK is set. > > Otherwise, return -EAGAIN. > > Signed-off-by: Eli Cohen <elic at nvidia.com> > --- > drivers/vdpa/vdpa.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c > index 5134c83c4a22..3285cebd89c0 100644 > --- a/drivers/vdpa/vdpa.c > +++ b/drivers/vdpa/vdpa.c > @@ -838,8 +838,18 @@ vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, > { > u32 device_id; > void *hdr; > + u8 status; > int err; > > + mutex_lock(&vdev->cf_mutex); > + status = vdev->config->get_status(vdev);Atomicity and data consistency not guaranteed against vdpa_get_config and get_features in vdpa_dev_net_config_fill(). Need to use coarse locking. -Siwei> + if (!(status & VIRTIO_CONFIG_S_FEATURES_OK)) { > + NL_SET_ERR_MSG_MOD(extack, "Features negotiation not completed"); > + mutex_unlock(&vdev->cf_mutex); > + return -EAGAIN; > + } > + mutex_unlock(&vdev->cf_mutex); > + > hdr = genlmsg_put(msg, portid, seq, &vdpa_nl_family, flags, > VDPA_CMD_DEV_CONFIG_GET); > if (!hdr)