virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC 1/3] virtio: add API to detect legacy devices
@ 2014-12-04 17:26 Michael S. Tsirkin
  2014-12-04 17:26 ` [PATCH RFC 2/3] virtio_ccw: legacy: don't negotiate rev 1/features Michael S. Tsirkin
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Michael S. Tsirkin @ 2014-12-04 17:26 UTC (permalink / raw)
  To: linux-kernel; +Cc: David Hildenbrand, virtualization

transports need to be able to detect legacy-only
devices (ATM balloon only) to use legacy path
to drive them.

Add a core API to do just that.
The implementation just blacklists balloon:
not too pretty, but let's not over-engineer.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/linux/virtio.h  | 2 ++
 drivers/virtio/virtio.c | 6 ++++++
 2 files changed, 8 insertions(+)

diff --git a/include/linux/virtio.h b/include/linux/virtio.h
index 2bbf626..d666bcb 100644
--- a/include/linux/virtio.h
+++ b/include/linux/virtio.h
@@ -108,6 +108,8 @@ struct virtio_device {
 	void *priv;
 };
 
+bool virtio_device_is_legacy_only(struct virtio_device_id id);
+
 static inline struct virtio_device *dev_to_virtio(struct device *_dev)
 {
 	return container_of(_dev, struct virtio_device, dev);
diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index fa6b75d..6b4c1113 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -267,6 +267,12 @@ static struct bus_type virtio_bus = {
 	.remove = virtio_dev_remove,
 };
 
+bool virtio_device_is_legacy_only(struct virtio_device_id id)
+{
+	return id.device == VIRTIO_ID_BALLOON;
+}
+EXPORT_SYMBOL_GPL(register_virtio_driver);
+
 int register_virtio_driver(struct virtio_driver *driver)
 {
 	/* Catch this early. */
-- 
MST

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH RFC 2/3] virtio_ccw: legacy: don't negotiate rev 1/features
  2014-12-04 17:26 [PATCH RFC 1/3] virtio: add API to detect legacy devices Michael S. Tsirkin
@ 2014-12-04 17:26 ` Michael S. Tsirkin
  2014-12-04 17:56   ` Cornelia Huck
  2014-12-04 17:26 ` [PATCH RFC 3/3] virtio_ccw: rev 1 devices set VIRTIO_F_VERSION_1 Michael S. Tsirkin
  2014-12-04 17:54 ` [PATCH RFC 1/3] virtio: add API to detect legacy devices Cornelia Huck
  2 siblings, 1 reply; 9+ messages in thread
From: Michael S. Tsirkin @ 2014-12-04 17:26 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-s390, Christian Borntraeger, Heiko Carstens, virtualization,
	David Hildenbrand, linux390, Martin Schwidefsky

Legacy balloon device doesn't pretend to support revision 1 or 64 bit
features.

But just in case someone implements a broken one that does, let's not
even try to drive legacy only devices using revision 1, and let's not
give them a chance to say they support VIRTIO_F_VERSION_1 by not reading
high feature bits.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 drivers/s390/kvm/virtio_ccw.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/s390/kvm/virtio_ccw.c b/drivers/s390/kvm/virtio_ccw.c
index 4a3e6e5..088bdf1 100644
--- a/drivers/s390/kvm/virtio_ccw.c
+++ b/drivers/s390/kvm/virtio_ccw.c
@@ -733,6 +733,9 @@ static u64 virtio_ccw_get_features(struct virtio_device *vdev)
 
 	rc = le32_to_cpu(features->features);
 
+	if (vcdev->revision == 0)
+		goto out_free;
+
 	/* Read second half of the feature bits from the host. */
 	features->index = 1;
 	ccw->cmd_code = CCW_CMD_READ_FEAT;
@@ -1182,9 +1185,13 @@ static int virtio_ccw_online(struct ccw_device *cdev)
 	vcdev->vdev.id.vendor = cdev->id.cu_type;
 	vcdev->vdev.id.device = cdev->id.cu_model;
 
-	ret = virtio_ccw_set_transport_rev(vcdev);
-	if (ret)
-		goto out_free;
+	if (virtio_device_is_legacy_only(vcdev->vdev.id)) {
+		ret = virtio_ccw_set_transport_rev(vcdev);
+		if (ret)
+			goto out_free;
+	} else {
+		vcdev->revision = 0;
+	}
 
 	ret = register_virtio_device(&vcdev->vdev);
 	if (ret) {
-- 
MST

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH RFC 3/3] virtio_ccw: rev 1 devices set VIRTIO_F_VERSION_1
  2014-12-04 17:26 [PATCH RFC 1/3] virtio: add API to detect legacy devices Michael S. Tsirkin
  2014-12-04 17:26 ` [PATCH RFC 2/3] virtio_ccw: legacy: don't negotiate rev 1/features Michael S. Tsirkin
@ 2014-12-04 17:26 ` Michael S. Tsirkin
  2014-12-04 17:59   ` Cornelia Huck
  2014-12-04 17:54 ` [PATCH RFC 1/3] virtio: add API to detect legacy devices Cornelia Huck
  2 siblings, 1 reply; 9+ messages in thread
From: Michael S. Tsirkin @ 2014-12-04 17:26 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-s390, Christian Borntraeger, Heiko Carstens, virtualization,
	David Hildenbrand, linux390, Martin Schwidefsky

What does it mean if rev 1 device does not set
VIRTIO_F_VERSION_1? E.g. is it native endian?

Let's not even try to drive such devices:
skip attempts to finalize features or set status.
virtio core will detect this and bail out.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 drivers/s390/kvm/virtio_ccw.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/s390/kvm/virtio_ccw.c b/drivers/s390/kvm/virtio_ccw.c
index 088bdf1..0ceeb25 100644
--- a/drivers/s390/kvm/virtio_ccw.c
+++ b/drivers/s390/kvm/virtio_ccw.c
@@ -65,6 +65,7 @@ struct virtio_ccw_device {
 	bool is_thinint;
 	bool going_away;
 	bool device_lost;
+	bool features_invalid;
 	void *airq_info;
 };
 
@@ -746,6 +747,12 @@ static u64 virtio_ccw_get_features(struct virtio_device *vdev)
 	if (ret == 0)
 		rc |= (u64)le32_to_cpu(features->features) << 32;
 
+	/* Devices MUST set VIRTIO_F_VERSION_1 */
+	if (!(rc & BIT_ULL(VIRTIO_F_VERSION_1))) {
+		vcdev->features_invalid = true;
+		rc |= BIT_ULL(VIRTIO_F_VERSION_1);
+	}
+
 out_free:
 	kfree(features);
 	kfree(ccw);
@@ -758,6 +765,10 @@ static void virtio_ccw_finalize_features(struct virtio_device *vdev)
 	struct virtio_feature_desc *features;
 	struct ccw1 *ccw;
 
+	/* Invalid features? Let's not try to drive this device. */
+	if (vcdev->features_invalid)
+		return;
+
 	ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
 	if (!ccw)
 		return;
@@ -869,6 +880,10 @@ static void virtio_ccw_set_status(struct virtio_device *vdev, u8 status)
 	struct ccw1 *ccw;
 	int ret;
 
+	/* Invalid features? Let's not try to drive this device. */
+	if (vcdev->features_invalid)
+		return;
+
 	ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
 	if (!ccw)
 		return;
-- 
MST

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH RFC 1/3] virtio: add API to detect legacy devices
  2014-12-04 17:26 [PATCH RFC 1/3] virtio: add API to detect legacy devices Michael S. Tsirkin
  2014-12-04 17:26 ` [PATCH RFC 2/3] virtio_ccw: legacy: don't negotiate rev 1/features Michael S. Tsirkin
  2014-12-04 17:26 ` [PATCH RFC 3/3] virtio_ccw: rev 1 devices set VIRTIO_F_VERSION_1 Michael S. Tsirkin
@ 2014-12-04 17:54 ` Cornelia Huck
  2 siblings, 0 replies; 9+ messages in thread
From: Cornelia Huck @ 2014-12-04 17:54 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: David Hildenbrand, linux-kernel, virtualization

On Thu, 4 Dec 2014 19:26:42 +0200
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> transports need to be able to detect legacy-only
> devices (ATM balloon only) to use legacy path
> to drive them.
> 
> Add a core API to do just that.
> The implementation just blacklists balloon:
> not too pretty, but let's not over-engineer.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  include/linux/virtio.h  | 2 ++
>  drivers/virtio/virtio.c | 6 ++++++
>  2 files changed, 8 insertions(+)

Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH RFC 2/3] virtio_ccw: legacy: don't negotiate rev 1/features
  2014-12-04 17:26 ` [PATCH RFC 2/3] virtio_ccw: legacy: don't negotiate rev 1/features Michael S. Tsirkin
@ 2014-12-04 17:56   ` Cornelia Huck
  2014-12-04 18:09     ` Michael S. Tsirkin
  0 siblings, 1 reply; 9+ messages in thread
From: Cornelia Huck @ 2014-12-04 17:56 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: linux-s390, Christian Borntraeger, Heiko Carstens, linux-kernel,
	virtualization, David Hildenbrand, Martin Schwidefsky, linux390

On Thu, 4 Dec 2014 19:26:45 +0200
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> Legacy balloon device doesn't pretend to support revision 1 or 64 bit
> features.
> 
> But just in case someone implements a broken one that does, let's not
> even try to drive legacy only devices using revision 1, and let's not
> give them a chance to say they support VIRTIO_F_VERSION_1 by not reading
> high feature bits.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  drivers/s390/kvm/virtio_ccw.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/s390/kvm/virtio_ccw.c b/drivers/s390/kvm/virtio_ccw.c
> index 4a3e6e5..088bdf1 100644
> --- a/drivers/s390/kvm/virtio_ccw.c
> +++ b/drivers/s390/kvm/virtio_ccw.c
> @@ -733,6 +733,9 @@ static u64 virtio_ccw_get_features(struct virtio_device *vdev)
> 
>  	rc = le32_to_cpu(features->features);
> 
> +	if (vcdev->revision == 0)
> +		goto out_free;
> +
>  	/* Read second half of the feature bits from the host. */
>  	features->index = 1;
>  	ccw->cmd_code = CCW_CMD_READ_FEAT;
> @@ -1182,9 +1185,13 @@ static int virtio_ccw_online(struct ccw_device *cdev)
>  	vcdev->vdev.id.vendor = cdev->id.cu_type;
>  	vcdev->vdev.id.device = cdev->id.cu_model;
> 
> -	ret = virtio_ccw_set_transport_rev(vcdev);
> -	if (ret)
> -		goto out_free;
> +	if (virtio_device_is_legacy_only(vcdev->vdev.id)) {

Inverted logic?

> +		ret = virtio_ccw_set_transport_rev(vcdev);
> +		if (ret)
> +			goto out_free;
> +	} else {
> +		vcdev->revision = 0;
> +	}
> 
>  	ret = register_virtio_device(&vcdev->vdev);
>  	if (ret) {

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH RFC 3/3] virtio_ccw: rev 1 devices set VIRTIO_F_VERSION_1
  2014-12-04 17:26 ` [PATCH RFC 3/3] virtio_ccw: rev 1 devices set VIRTIO_F_VERSION_1 Michael S. Tsirkin
@ 2014-12-04 17:59   ` Cornelia Huck
  2014-12-04 18:09     ` Michael S. Tsirkin
  2014-12-04 18:15     ` Michael S. Tsirkin
  0 siblings, 2 replies; 9+ messages in thread
From: Cornelia Huck @ 2014-12-04 17:59 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: linux-s390, Christian Borntraeger, Heiko Carstens, linux-kernel,
	virtualization, David Hildenbrand, Martin Schwidefsky, linux390

On Thu, 4 Dec 2014 19:26:50 +0200
"Michael S. Tsirkin" <mst@redhat.com> wrote:

> What does it mean if rev 1 device does not set
> VIRTIO_F_VERSION_1? E.g. is it native endian?
> 
> Let's not even try to drive such devices:
> skip attempts to finalize features or set status.

Why not set status_failed?

> virtio core will detect this and bail out.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  drivers/s390/kvm/virtio_ccw.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 

I'm not sure yet whether I like this approach. I'll think about it over
the weekend.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH RFC 2/3] virtio_ccw: legacy: don't negotiate rev 1/features
  2014-12-04 17:56   ` Cornelia Huck
@ 2014-12-04 18:09     ` Michael S. Tsirkin
  0 siblings, 0 replies; 9+ messages in thread
From: Michael S. Tsirkin @ 2014-12-04 18:09 UTC (permalink / raw)
  To: Cornelia Huck
  Cc: linux-s390, Christian Borntraeger, Heiko Carstens, linux-kernel,
	virtualization, David Hildenbrand, Martin Schwidefsky, linux390

On Thu, Dec 04, 2014 at 06:56:06PM +0100, Cornelia Huck wrote:
> On Thu, 4 Dec 2014 19:26:45 +0200
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
> 
> > Legacy balloon device doesn't pretend to support revision 1 or 64 bit
> > features.
> > 
> > But just in case someone implements a broken one that does, let's not
> > even try to drive legacy only devices using revision 1, and let's not
> > give them a chance to say they support VIRTIO_F_VERSION_1 by not reading
> > high feature bits.
> > 
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> >  drivers/s390/kvm/virtio_ccw.c | 13 ++++++++++---
> >  1 file changed, 10 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/s390/kvm/virtio_ccw.c b/drivers/s390/kvm/virtio_ccw.c
> > index 4a3e6e5..088bdf1 100644
> > --- a/drivers/s390/kvm/virtio_ccw.c
> > +++ b/drivers/s390/kvm/virtio_ccw.c
> > @@ -733,6 +733,9 @@ static u64 virtio_ccw_get_features(struct virtio_device *vdev)
> > 
> >  	rc = le32_to_cpu(features->features);
> > 
> > +	if (vcdev->revision == 0)
> > +		goto out_free;
> > +
> >  	/* Read second half of the feature bits from the host. */
> >  	features->index = 1;
> >  	ccw->cmd_code = CCW_CMD_READ_FEAT;
> > @@ -1182,9 +1185,13 @@ static int virtio_ccw_online(struct ccw_device *cdev)
> >  	vcdev->vdev.id.vendor = cdev->id.cu_type;
> >  	vcdev->vdev.id.device = cdev->id.cu_model;
> > 
> > -	ret = virtio_ccw_set_transport_rev(vcdev);
> > -	if (ret)
> > -		goto out_free;
> > +	if (virtio_device_is_legacy_only(vcdev->vdev.id)) {
> 
> Inverted logic?

Ugh, clearly.

> > +		ret = virtio_ccw_set_transport_rev(vcdev);
> > +		if (ret)
> > +			goto out_free;
> > +	} else {
> > +		vcdev->revision = 0;
> > +	}
> > 
> >  	ret = register_virtio_device(&vcdev->vdev);
> >  	if (ret) {

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH RFC 3/3] virtio_ccw: rev 1 devices set VIRTIO_F_VERSION_1
  2014-12-04 17:59   ` Cornelia Huck
@ 2014-12-04 18:09     ` Michael S. Tsirkin
  2014-12-04 18:15     ` Michael S. Tsirkin
  1 sibling, 0 replies; 9+ messages in thread
From: Michael S. Tsirkin @ 2014-12-04 18:09 UTC (permalink / raw)
  To: Cornelia Huck
  Cc: linux-s390, Christian Borntraeger, Heiko Carstens, linux-kernel,
	virtualization, David Hildenbrand, Martin Schwidefsky, linux390

On Thu, Dec 04, 2014 at 06:59:14PM +0100, Cornelia Huck wrote:
> On Thu, 4 Dec 2014 19:26:50 +0200
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
> 
> > What does it mean if rev 1 device does not set
> > VIRTIO_F_VERSION_1? E.g. is it native endian?
> > 
> > Let's not even try to drive such devices:
> > skip attempts to finalize features or set status.
> 
> Why not set status_failed?

What's status_failed?

> > virtio core will detect this and bail out.
> > 
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> >  drivers/s390/kvm/virtio_ccw.c | 15 +++++++++++++++
> >  1 file changed, 15 insertions(+)
> > 
> 
> I'm not sure yet whether I like this approach. I'll think about it over
> the weekend.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH RFC 3/3] virtio_ccw: rev 1 devices set VIRTIO_F_VERSION_1
  2014-12-04 17:59   ` Cornelia Huck
  2014-12-04 18:09     ` Michael S. Tsirkin
@ 2014-12-04 18:15     ` Michael S. Tsirkin
  1 sibling, 0 replies; 9+ messages in thread
From: Michael S. Tsirkin @ 2014-12-04 18:15 UTC (permalink / raw)
  To: Cornelia Huck
  Cc: linux-s390, Christian Borntraeger, Heiko Carstens, linux-kernel,
	virtualization, David Hildenbrand, Martin Schwidefsky, linux390

On Thu, Dec 04, 2014 at 06:59:14PM +0100, Cornelia Huck wrote:
> On Thu, 4 Dec 2014 19:26:50 +0200
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
> 
> > What does it mean if rev 1 device does not set
> > VIRTIO_F_VERSION_1? E.g. is it native endian?
> > 
> > Let's not even try to drive such devices:
> > skip attempts to finalize features or set status.
> 
> Why not set status_failed?

It might be cleanest to just teach core that finalize_features
can fail.
I'll look into this.

> > virtio core will detect this and bail out.
> > 
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> >  drivers/s390/kvm/virtio_ccw.c | 15 +++++++++++++++
> >  1 file changed, 15 insertions(+)
> > 
> 
> I'm not sure yet whether I like this approach. I'll think about it over
> the weekend.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-12-04 18:15 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-04 17:26 [PATCH RFC 1/3] virtio: add API to detect legacy devices Michael S. Tsirkin
2014-12-04 17:26 ` [PATCH RFC 2/3] virtio_ccw: legacy: don't negotiate rev 1/features Michael S. Tsirkin
2014-12-04 17:56   ` Cornelia Huck
2014-12-04 18:09     ` Michael S. Tsirkin
2014-12-04 17:26 ` [PATCH RFC 3/3] virtio_ccw: rev 1 devices set VIRTIO_F_VERSION_1 Michael S. Tsirkin
2014-12-04 17:59   ` Cornelia Huck
2014-12-04 18:09     ` Michael S. Tsirkin
2014-12-04 18:15     ` Michael S. Tsirkin
2014-12-04 17:54 ` [PATCH RFC 1/3] virtio: add API to detect legacy devices Cornelia Huck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).