All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cornelia Huck <cornelia.huck@de.ibm.com>
To: virtualization@lists.linux-foundation.org, qemu-devel@nongnu.org,
	kvm@vger.kernel.org
Cc: thuth@linux.vnet.ibm.com, mst@redhat.com
Subject: [PATCH RFC v5 13/19] virtio: allow to fail setting status
Date: Tue,  2 Dec 2014 14:00:21 +0100	[thread overview]
Message-ID: <1417525227-14051-14-git-send-email-cornelia.huck__8483.38569417155$1417525394$gmane$org@de.ibm.com> (raw)
In-Reply-To: <1417525227-14051-1-git-send-email-cornelia.huck@de.ibm.com>

virtio-1 allow setting of the FEATURES_OK status bit to fail if
the negotiated feature bits are inconsistent: let's fail
virtio_set_status() in that case and update virtio-ccw to post an
error to the guest.

Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
 hw/s390x/virtio-ccw.c      |   20 ++++++++++++--------
 hw/virtio/virtio.c         |   24 +++++++++++++++++++++++-
 include/hw/virtio/virtio.h |    3 ++-
 3 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index 75c9ff9..ec492b8 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -555,15 +555,19 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
             if (!(status & VIRTIO_CONFIG_S_DRIVER_OK)) {
                 virtio_ccw_stop_ioeventfd(dev);
             }
-            virtio_set_status(vdev, status);
-            if (vdev->status == 0) {
-                virtio_reset(vdev);
-            }
-            if (status & VIRTIO_CONFIG_S_DRIVER_OK) {
-                virtio_ccw_start_ioeventfd(dev);
+            if (virtio_set_status(vdev, status) == 0) {
+                if (vdev->status == 0) {
+                    virtio_reset(vdev);
+                }
+                if (status & VIRTIO_CONFIG_S_DRIVER_OK) {
+                    virtio_ccw_start_ioeventfd(dev);
+                }
+                sch->curr_status.scsw.count = ccw.count - sizeof(status);
+                ret = 0;
+            } else {
+                /* Trigger a command reject. */
+                ret = -ENOSYS;
             }
-            sch->curr_status.scsw.count = ccw.count - sizeof(status);
-            ret = 0;
         }
         break;
     case CCW_CMD_SET_IND:
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 4f2dc48..be128f7 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -548,15 +548,37 @@ void virtio_update_irq(VirtIODevice *vdev)
     virtio_notify_vector(vdev, VIRTIO_NO_VECTOR);
 }
 
-void virtio_set_status(VirtIODevice *vdev, uint8_t val)
+static int virtio_validate_features(VirtIODevice *vdev)
+{
+    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
+
+    if (k->validate_features) {
+        return k->validate_features(vdev);
+    } else {
+        return 0;
+    }
+}
+
+int virtio_set_status(VirtIODevice *vdev, uint8_t val)
 {
     VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
     trace_virtio_set_status(vdev, val);
 
+    if (virtio_has_feature(vdev, VIRTIO_F_VERSION_1)) {
+        if (!(vdev->status & VIRTIO_CONFIG_S_FEATURES_OK) &&
+            val & VIRTIO_CONFIG_S_FEATURES_OK) {
+            int ret = virtio_validate_features(vdev);
+
+            if (ret) {
+                return ret;
+            }
+        }
+    }
     if (k->set_status) {
         k->set_status(vdev, val);
     }
     vdev->status = val;
+    return 0;
 }
 
 bool target_words_bigendian(void);
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index 9a984c2..e7bedd1 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -149,6 +149,7 @@ typedef struct VirtioDeviceClass {
     uint64_t (*get_features)(VirtIODevice *vdev, uint64_t requested_features);
     uint64_t (*bad_features)(VirtIODevice *vdev);
     void (*set_features)(VirtIODevice *vdev, uint64_t val);
+    int (*validate_features)(VirtIODevice *vdev);
     void (*get_config)(VirtIODevice *vdev, uint8_t *config);
     void (*set_config)(VirtIODevice *vdev, const uint8_t *config);
     void (*reset)(VirtIODevice *vdev);
@@ -232,7 +233,7 @@ void virtio_queue_set_align(VirtIODevice *vdev, int n, int align);
 void virtio_queue_notify(VirtIODevice *vdev, int n);
 uint16_t virtio_queue_vector(VirtIODevice *vdev, int n);
 void virtio_queue_set_vector(VirtIODevice *vdev, int n, uint16_t vector);
-void virtio_set_status(VirtIODevice *vdev, uint8_t val);
+int virtio_set_status(VirtIODevice *vdev, uint8_t val);
 void virtio_reset(void *opaque);
 void virtio_update_irq(VirtIODevice *vdev);
 int virtio_set_features(VirtIODevice *vdev, uint64_t val);
-- 
1.7.9.5

  parent reply	other threads:[~2014-12-02 13:00 UTC|newest]

Thread overview: 90+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-02 13:00 [PATCH RFC v5 00/19] qemu: towards virtio-1 host support Cornelia Huck
2014-12-02 13:00 ` [Qemu-devel] " Cornelia Huck
2014-12-02 13:00 ` [PATCH RFC v5 01/19] linux-headers/virtio_config: Update with VIRTIO_F_VERSION_1 Cornelia Huck
2014-12-02 13:00   ` [Qemu-devel] " Cornelia Huck
2014-12-02 13:00 ` [PATCH RFC v5 02/19] virtio: cull virtio_bus_set_vdev_features Cornelia Huck
2014-12-02 13:00   ` [Qemu-devel] " Cornelia Huck
2014-12-02 13:00 ` [PATCH RFC v5 03/19] virtio: feature bit manipulation helpers Cornelia Huck
2014-12-02 13:00   ` [Qemu-devel] " Cornelia Huck
2014-12-02 13:00 ` [PATCH RFC v5 04/19] virtio: add feature checking helpers Cornelia Huck
2014-12-02 13:00   ` [Qemu-devel] " Cornelia Huck
2014-12-02 13:00 ` Cornelia Huck
2014-12-02 13:00 ` [PATCH RFC v5 05/19] virtio: support more feature bits Cornelia Huck
2014-12-02 13:00   ` [Qemu-devel] " Cornelia Huck
2014-12-10 17:35   ` Cornelia Huck
2014-12-10 17:35     ` Cornelia Huck
2014-12-02 13:00 ` [PATCH RFC v5 06/19] virtio: endianness checks for virtio 1.0 devices Cornelia Huck
2014-12-02 13:00 ` Cornelia Huck
2014-12-02 13:00   ` [Qemu-devel] " Cornelia Huck
2014-12-02 13:00 ` [PATCH RFC v5 07/19] virtio: allow virtio-1 queue layout Cornelia Huck
2014-12-02 13:00   ` [Qemu-devel] " Cornelia Huck
2014-12-02 14:46   ` Michael S. Tsirkin
2014-12-02 14:46     ` [Qemu-devel] " Michael S. Tsirkin
2014-12-02 14:54     ` Cornelia Huck
2014-12-02 14:54       ` [Qemu-devel] " Cornelia Huck
2014-12-02 15:41       ` Cornelia Huck
2014-12-02 15:41       ` Cornelia Huck
2014-12-02 15:41         ` [Qemu-devel] " Cornelia Huck
2014-12-02 19:03         ` Michael S. Tsirkin
2014-12-02 19:03           ` [Qemu-devel] " Michael S. Tsirkin
2014-12-03  9:27           ` Cornelia Huck
2014-12-03  9:27             ` [Qemu-devel] " Cornelia Huck
2014-12-03  9:50             ` Cornelia Huck
2014-12-03  9:50             ` Cornelia Huck
2014-12-03  9:50               ` [Qemu-devel] " Cornelia Huck
2014-12-03 10:52               ` Michael S. Tsirkin
2014-12-03 10:52                 ` [Qemu-devel] " Michael S. Tsirkin
2014-12-03 11:14                 ` Cornelia Huck
2014-12-03 11:14                   ` [Qemu-devel] " Cornelia Huck
2014-12-03 11:19                   ` Michael S. Tsirkin
2014-12-03 11:19                     ` [Qemu-devel] " Michael S. Tsirkin
2014-12-03 11:44                     ` Cornelia Huck
2014-12-03 11:44                       ` [Qemu-devel] " Cornelia Huck
2014-12-02 13:00 ` [PATCH RFC v5 08/19] dataplane: allow virtio-1 devices Cornelia Huck
2014-12-02 13:00   ` [Qemu-devel] " Cornelia Huck
2014-12-02 13:00 ` Cornelia Huck
2014-12-02 13:00 ` [PATCH RFC v5 09/19] s390x/css: Add a callback for when subchannel gets disabled Cornelia Huck
2014-12-02 13:00   ` [Qemu-devel] " Cornelia Huck
2014-12-02 13:00 ` Cornelia Huck
2014-12-02 13:00 ` [PATCH RFC v5 10/19] s390x/virtio-ccw: add virtio set-revision call Cornelia Huck
2014-12-02 13:00 ` Cornelia Huck
2014-12-02 13:00   ` [Qemu-devel] " Cornelia Huck
2014-12-04 16:20   ` Michael S. Tsirkin
2014-12-04 16:20     ` [Qemu-devel] " Michael S. Tsirkin
2014-12-04 16:43     ` Cornelia Huck
2014-12-04 16:43       ` [Qemu-devel] " Cornelia Huck
2014-12-04 16:20   ` Michael S. Tsirkin
2014-12-02 13:00 ` [PATCH RFC v5 11/19] s390x/virtio-ccw: support virtio-1 set_vq format Cornelia Huck
2014-12-02 13:00 ` Cornelia Huck
2014-12-02 13:00   ` [Qemu-devel] " Cornelia Huck
2014-12-02 13:00 ` [PATCH RFC v5 12/19] virtio: disallow late feature changes for virtio-1 Cornelia Huck
2014-12-02 13:00 ` Cornelia Huck
2014-12-02 13:00   ` [Qemu-devel] " Cornelia Huck
2014-12-02 13:00 ` [PATCH RFC v5 13/19] virtio: allow to fail setting status Cornelia Huck
2014-12-02 13:00   ` [Qemu-devel] " Cornelia Huck
2014-12-02 13:00 ` Cornelia Huck [this message]
2014-12-02 13:00 ` [PATCH RFC v5 14/19] s390x/virtio-ccw: enable virtio 1.0 Cornelia Huck
2014-12-02 13:00 ` Cornelia Huck
2014-12-02 13:00   ` [Qemu-devel] " Cornelia Huck
2014-12-09 13:46   ` Michael S. Tsirkin
2014-12-09 13:46     ` [Qemu-devel] " Michael S. Tsirkin
2014-12-09 17:24     ` Cornelia Huck
2014-12-09 17:24       ` [Qemu-devel] " Cornelia Huck
2014-12-09 17:24     ` Cornelia Huck
2014-12-02 13:00 ` [PATCH RFC v5 15/19] virtio-net: no writeable mac for virtio-1 Cornelia Huck
2014-12-02 13:00   ` [Qemu-devel] " Cornelia Huck
2014-12-02 13:00 ` Cornelia Huck
2014-12-02 13:00 ` [PATCH RFC v5 16/19] virtio-net: support longer header Cornelia Huck
2014-12-02 13:00   ` [Qemu-devel] " Cornelia Huck
2014-12-02 13:00 ` Cornelia Huck
2014-12-02 13:00 ` [PATCH RFC v5 17/19] virtio-net: enable virtio 1.0 Cornelia Huck
2014-12-02 13:00 ` Cornelia Huck
2014-12-02 13:00   ` [Qemu-devel] " Cornelia Huck
2014-12-02 13:00 ` [PATCH RFC v5 18/19] virtio: support revision-specific features Cornelia Huck
2014-12-02 13:00   ` [Qemu-devel] " Cornelia Huck
2014-12-10 17:37   ` Cornelia Huck
2014-12-10 17:37     ` Cornelia Huck
2014-12-02 13:00 ` Cornelia Huck
2014-12-02 13:00 ` [PATCH RFC v5 19/19] virtio-blk: revision specific feature bits Cornelia Huck
2014-12-02 13:00   ` [Qemu-devel] " Cornelia Huck
2014-12-02 13:00 ` Cornelia Huck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='1417525227-14051-14-git-send-email-cornelia.huck__8483.38569417155$1417525394$gmane$org@de.ibm.com' \
    --to=cornelia.huck@de.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@linux.vnet.ibm.com \
    --cc=virtualization@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.