virtio: graceful failure with get == NULL
Subsystems (11)
Michael S. Tsirkin
maintainercover virtio: graceful failure with get == NULL
virtio 1.0 says device configuration is optional, but most drivers treat it as mandatory. Even if presented by device, guest bios might disable the BAR holding that configuration, so we can't assume it's there, but we also don't want to fail if not in case drivers can cope with it's absence - such as caif or rng.
Add code to drivers to check presence of get callback and fail gracefully.
Michael S. Tsirkin (6):
virtio/9p: verify device has config space
virtio/blk: verify device has config space
virtio/console: verify device has config space
virtio/net: verify device has config space
virtio/scsi: verify device has config space
virtio/balloon: verify device has config space
drivers/block/virtio_blk.c | 6 ++++++ drivers/char/virtio_console.c | 6 ++++++ drivers/net/virtio_net.c | 6 ++++++ drivers/scsi/virtio_scsi.c | 6 ++++++ drivers/virtio/virtio_balloon.c | 6 ++++++ net/9p/trans_virtio.c | 6 ++++++ 6 files changed, 36 insertions(+)
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH 1/6 virtio/9p: verify device has config space
Some devices might not implement config space access (e.g. remoteproc used not to - before 3.9). virtio/9p needs config space access so make it fail gracefully if not there.
--- net/9p/trans_virtio.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/9p/trans_virtio.c +6 -0
@@ -524,6 +524,12 @@ static int p9_virtio_probe(struct virtio_device *vdev)int err;struct virtio_chan *chan; +if (!vdev->config->get) { +dev_err (&vdev->dev,"%s failure: config access disabled\n" , + __func__); +return -EINVAL ; + } + chan =kmalloc (sizeof (struct virtio_chan ),GFP_KERNEL );if (!chan) {pr_err ("Failed to allocate virtio 9P channel\n" );
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH 1/6 virtio/9p: verify device has config space
In reply to Michael S. TsirkinSome devices might not implement config space access (e.g. remoteproc used not to - before 3.9). virtio/9p needs config space access so make it fail gracefully if not there.
--- net/9p/trans_virtio.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/9p/trans_virtio.c +6 -0
@@ -524,6 +524,12 @@ static int p9_virtio_probe(struct virtio_device *vdev)int err;struct virtio_chan *chan; +if (!vdev->config->get) { +dev_err (&vdev->dev,"%s failure: config access disabled\n" , + __func__); +return -EINVAL ; + } + chan =kmalloc (sizeof (struct virtio_chan ),GFP_KERNEL );if (!chan) {pr_err ("Failed to allocate virtio 9P channel\n" );
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH 2/6 virtio/blk: verify device has config space
In reply to Michael S. TsirkinSome devices might not implement config space access (e.g. remoteproc used not to - before 3.9). virtio/blk needs config space access so make it fail gracefully if not there.
--- drivers/block/virtio_blk.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/block/virtio_blk.c +6 -0
@@ -575,6 +575,12 @@ static int virtblk_probe(struct virtio_device *vdev)u16 min_io_size;u8 physical_block_exp, alignment_offset; +if (!vdev->config->get) { +dev_err (&vdev->dev,"%s failure: config access disabled\n" , + __func__); +return -EINVAL ; + } + err =ida_simple_get (&vd_index_ida,0 ,minor_to_index (1 <<MINORBITS ),GFP_KERNEL );if (err <0 )
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH 3/6 virtio/console: verify device has config space
In reply to Michael S. TsirkinSome devices might not implement config space access (e.g. remoteproc used not to - before 3.9). virtio/console needs config space access so make it fail gracefully if not there.
--- drivers/char/virtio_console.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/char/virtio_console.c +6 -0
@@ -1986,6 +1986,12 @@ static int virtcons_probe(struct virtio_device *vdev)bool multiport;bool early = early_put_chars !=NULL ; +if (!vdev->config->get) { +dev_err (&vdev->dev,"%s failure: config access disabled\n" , + __func__); +return -EINVAL ; + } +/* Ensure to read early_put_chars now */ barrier ();
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH 4/6 virtio/net: verify device has config space
In reply to Michael S. TsirkinSome devices might not implement config space access (e.g. remoteproc used not to - before 3.9). virtio/net needs config space access so make it fail gracefully if not there.
--- drivers/net/virtio_net.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/virtio_net.c +6 -0
@@ -1713,6 +1713,12 @@ static int virtnet_probe(struct virtio_device *vdev)struct virtnet_info *vi;u16 max_queue_pairs; +if (!vdev->config->get) { +dev_err (&vdev->dev,"%s failure: config access disabled\n" , + __func__); +return -EINVAL ; + } +if (!virtnet_validate_features (vdev))return -EINVAL ;
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH 5/6 virtio/scsi: verify device has config space
In reply to Michael S. TsirkinSome devices might not implement config space access (e.g. remoteproc used not to - before 3.9). virtio/scsi needs config space access so make it fail gracefully if not there.
--- drivers/scsi/virtio_scsi.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/scsi/virtio_scsi.c +6 -0
@@ -950,6 +950,12 @@ static int virtscsi_probe(struct virtio_device *vdev)u32 num_queues;struct scsi_host_template *hostt; +if (!vdev->config->get) { +dev_err (&vdev->dev,"%s failure: config access disabled\n" , + __func__); +return -EINVAL ; + } +/* We need to know how many queues before we allocate. */ num_queues =virtscsi_config_get (vdev, num_queues) ? :1 ;
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH 5/6 virtio/scsi: verify device has config space
In reply to Michael S. TsirkinSome devices might not implement config space access (e.g. remoteproc used not to - before 3.9). virtio/scsi needs config space access so make it fail gracefully if not there.
--- drivers/scsi/virtio_scsi.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/scsi/virtio_scsi.c +6 -0
@@ -950,6 +950,12 @@ static int virtscsi_probe(struct virtio_device *vdev)u32 num_queues;struct scsi_host_template *hostt; +if (!vdev->config->get) { +dev_err (&vdev->dev,"%s failure: config access disabled\n" , + __func__); +return -EINVAL ; + } +/* We need to know how many queues before we allocate. */ num_queues =virtscsi_config_get (vdev, num_queues) ? :1 ;
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH 6/6 virtio/balloon: verify device has config space
In reply to Michael S. TsirkinSome devices might not implement config space access (e.g. remoteproc used not to - before 3.9). virtio/balloon needs config space access so make it fail gracefully if not there.
--- drivers/virtio/virtio_balloon.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/virtio/virtio_balloon.c +6 -0
@@ -466,6 +466,12 @@ static int virtballoon_probe(struct virtio_device *vdev)struct virtio_balloon *vb;int err; +if (!vdev->config->get) { +dev_err (&vdev->dev,"%s failure: config access disabled\n" , + __func__); +return -EINVAL ; + } + vdev->priv = vb =kmalloc (sizeof (*vb),GFP_KERNEL );if (!vb) { err = -ENOMEM ;
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH 6/6 virtio/balloon: verify device has config space
In reply to Michael S. TsirkinSome devices might not implement config space access (e.g. remoteproc used not to - before 3.9). virtio/balloon needs config space access so make it fail gracefully if not there.
--- drivers/virtio/virtio_balloon.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/virtio/virtio_balloon.c +6 -0
@@ -466,6 +466,12 @@ static int virtballoon_probe(struct virtio_device *vdev)struct virtio_balloon *vb;int err; +if (!vdev->config->get) { +dev_err (&vdev->dev,"%s failure: config access disabled\n" , + __func__); +return -EINVAL ; + } + vdev->priv = vb =kmalloc (sizeof (*vb),GFP_KERNEL );if (!vb) { err = -ENOMEM ;
Signature · 1 line
MST
Michael S. Tsirkin
maintainerPATCH 6/6 virtio/balloon: verify device has config space
In reply to Michael S. TsirkinSome devices might not implement config space access (e.g. remoteproc used not to - before 3.9). virtio/balloon needs config space access so make it fail gracefully if not there.
--- drivers/virtio/virtio_balloon.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/virtio/virtio_balloon.c +6 -0
@@ -466,6 +466,12 @@ static int virtballoon_probe(struct virtio_device *vdev)struct virtio_balloon *vb;int err; +if (!vdev->config->get) { +dev_err (&vdev->dev,"%s failure: config access disabled\n" , + __func__); +return -EINVAL ; + } + vdev->priv = vb =kmalloc (sizeof (*vb),GFP_KERNEL );if (!vb) { err = -ENOMEM ;
Signature · 1 line
MST
Michael S. Tsirkin
maintainerQuoted 7 lines · Michael S. Tsirkin
virtio 1.0 says device configuration is optional, but most drivers treat it as mandatory. Even if presented by device, guest bios might disable the BAR holding that configuration, so we can't assume it's there, but we also don't want to fail if not in case drivers can cope with it's absence - such as caif or rng.
Add code to drivers to check presence of get callback and fail gracefully.
Rusty, in case it's not clear: I'd like to hear your opinion on these patches, since virtio pci modern driver I'm now preparing for submission, depends on this.
Quoted 19 lines
Michael S. Tsirkin (6):
virtio/9p: verify device has config space
virtio/blk: verify device has config space
virtio/console: verify device has config space
virtio/net: verify device has config space
virtio/scsi: verify device has config space
virtio/balloon: verify device has config spacedrivers/block/virtio_blk.c | 6 ++++++ drivers/char/virtio_console.c | 6 ++++++ drivers/net/virtio_net.c | 6 ++++++ drivers/scsi/virtio_scsi.c | 6 ++++++ drivers/virtio/virtio_balloon.c | 6 ++++++ net/9p/trans_virtio.c | 6 ++++++ 6 files changed, 36 insertions(+)Signature · 1 line
MST
Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Michael S. Tsirkin
virtio 1.0 says device configuration is optional, but most drivers treat it as mandatory. Even if presented by device, guest bios might disable the BAR holding that configuration, so we can't assume it's there, but we also don't want to fail if not in case drivers can cope with it's absence - such as caif or rng.
Quoted 5 lines
Quoted 1 line
Add code to drivers to check presence of get callback and fail gracefully.
Rusty, in case it's not clear: I'd like to hear your opinion on these patches, since virtio pci modern driver I'm now preparing for submission, depends on this.
Just to note for anyone following, that these are now in my virtio-next tree.
Cheers,
Rusty.