All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Anthony Liguori <aliguori@us.ibm.com>,
	Rusty Russell <rusty@rustcorp.com.au>,
	Alexander Graf <agraf@suse.de>,
	Anthony Liguori <aliguori@amazon.com>,
	Amit Shah <amit.shah@redhat.com>,
	Greg Kurz <gkurz@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PULL 33/37] virtio-serial-bus: use virtio wrappers to access headers
Date: Sun, 29 Jun 2014 20:00:02 +0300	[thread overview]
Message-ID: <1404060115-27410-34-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1404060115-27410-1-git-send-email-mst@redhat.com>

From: Rusty Russell <rusty@rustcorp.com.au>

We also fix max_nr_ports at reset time as the device endianness may have
changed.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
[ pass VirtIODevice * to memory accessors,
  fix max_nr_ports at reset time,
  Greg Kurz <gkurz@linux.vnet.ibm.com> ]
Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
Reviewed-by: Alexander Graf <agraf@suse.de>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/char/virtio-serial-bus.c | 46 ++++++++++++++++++++++++++++++---------------
 1 file changed, 31 insertions(+), 15 deletions(-)

diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index b8af1b1..07bebc0 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -24,6 +24,7 @@
 #include "hw/sysbus.h"
 #include "trace.h"
 #include "hw/virtio/virtio-serial.h"
+#include "hw/virtio/virtio-access.h"
 
 static VirtIOSerialPort *find_port_by_id(VirtIOSerial *vser, uint32_t id)
 {
@@ -183,11 +184,12 @@ static size_t send_control_msg(VirtIOSerial *vser, void *buf, size_t len)
 static size_t send_control_event(VirtIOSerial *vser, uint32_t port_id,
                                  uint16_t event, uint16_t value)
 {
+    VirtIODevice *vdev = VIRTIO_DEVICE(vser);
     struct virtio_console_control cpkt;
 
-    stl_p(&cpkt.id, port_id);
-    stw_p(&cpkt.event, event);
-    stw_p(&cpkt.value, value);
+    virtio_stl_p(vdev, &cpkt.id, port_id);
+    virtio_stw_p(vdev, &cpkt.event, event);
+    virtio_stw_p(vdev, &cpkt.value, value);
 
     trace_virtio_serial_send_control_event(port_id, event, value);
     return send_control_msg(vser, &cpkt, sizeof(cpkt));
@@ -278,6 +280,7 @@ void virtio_serial_throttle_port(VirtIOSerialPort *port, bool throttle)
 /* Guest wants to notify us of some event */
 static void handle_control_message(VirtIOSerial *vser, void *buf, size_t len)
 {
+    VirtIODevice *vdev = VIRTIO_DEVICE(vser);
     struct VirtIOSerialPort *port;
     VirtIOSerialPortClass *vsc;
     struct virtio_console_control cpkt, *gcpkt;
@@ -291,8 +294,8 @@ static void handle_control_message(VirtIOSerial *vser, void *buf, size_t len)
         return;
     }
 
-    cpkt.event = lduw_p(&gcpkt->event);
-    cpkt.value = lduw_p(&gcpkt->value);
+    cpkt.event = virtio_lduw_p(vdev, &gcpkt->event);
+    cpkt.value = virtio_lduw_p(vdev, &gcpkt->value);
 
     trace_virtio_serial_handle_control_message(cpkt.event, cpkt.value);
 
@@ -312,10 +315,10 @@ static void handle_control_message(VirtIOSerial *vser, void *buf, size_t len)
         return;
     }
 
-    port = find_port_by_id(vser, ldl_p(&gcpkt->id));
+    port = find_port_by_id(vser, virtio_ldl_p(vdev, &gcpkt->id));
     if (!port) {
         error_report("virtio-serial-bus: Unexpected port id %u for device %s",
-                     ldl_p(&gcpkt->id), vser->bus.qbus.name);
+                     virtio_ldl_p(vdev, &gcpkt->id), vser->bus.qbus.name);
         return;
     }
 
@@ -342,9 +345,9 @@ static void handle_control_message(VirtIOSerial *vser, void *buf, size_t len)
         }
 
         if (port->name) {
-            stl_p(&cpkt.id, port->id);
-            stw_p(&cpkt.event, VIRTIO_CONSOLE_PORT_NAME);
-            stw_p(&cpkt.value, 1);
+            virtio_stl_p(vdev, &cpkt.id, port->id);
+            virtio_stw_p(vdev, &cpkt.event, VIRTIO_CONSOLE_PORT_NAME);
+            virtio_stw_p(vdev, &cpkt.value, 1);
 
             buffer_len = sizeof(cpkt) + strlen(port->name) + 1;
             buffer = g_malloc(buffer_len);
@@ -510,6 +513,10 @@ static void vser_reset(VirtIODevice *vdev)
 
     vser = VIRTIO_SERIAL(vdev);
     guest_reset(vser);
+
+    /* In case we have switched endianness */
+    vser->config.max_nr_ports =
+        virtio_tswap32(vdev, vser->serial.max_virtserial_ports);
 }
 
 static void virtio_serial_save(QEMUFile *f, void *opaque)
@@ -532,7 +539,7 @@ static void virtio_serial_save_device(VirtIODevice *vdev, QEMUFile *f)
     qemu_put_be32s(f, &s->config.max_nr_ports);
 
     /* The ports map */
-    max_nr_ports = tswap32(s->config.max_nr_ports);
+    max_nr_ports = virtio_tswap32(vdev, s->config.max_nr_ports);
     for (i = 0; i < (max_nr_ports + 31) / 32; i++) {
         qemu_put_be32s(f, &s->ports_map[i]);
     }
@@ -688,6 +695,12 @@ static int virtio_serial_load_device(VirtIODevice *vdev, QEMUFile *f,
     qemu_get_be16s(f, (uint16_t *) &tmp);
     qemu_get_be32s(f, &tmp);
 
+    /* Note: this is the only location where we use tswap32() instead of
+     * virtio_tswap32() because:
+     * - virtio_tswap32() only makes sense when the device is fully restored
+     * - the target endianness that was used to populate s->config is
+     *   necessarly the default one
+     */
     max_nr_ports = tswap32(s->config.max_nr_ports);
     for (i = 0; i < (max_nr_ports + 31) / 32; i++) {
         qemu_get_be32s(f, &ports_map);
@@ -751,9 +764,10 @@ static void virtser_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent)
 /* This function is only used if a port id is not provided by the user */
 static uint32_t find_free_port_id(VirtIOSerial *vser)
 {
+    VirtIODevice *vdev = VIRTIO_DEVICE(vser);
     unsigned int i, max_nr_ports;
 
-    max_nr_ports = tswap32(vser->config.max_nr_ports);
+    max_nr_ports = virtio_tswap32(vdev, vser->config.max_nr_ports);
     for (i = 0; i < (max_nr_ports + 31) / 32; i++) {
         uint32_t map, bit;
 
@@ -806,6 +820,7 @@ static void virtser_port_device_realize(DeviceState *dev, Error **errp)
     VirtIOSerialPort *port = VIRTIO_SERIAL_PORT(dev);
     VirtIOSerialPortClass *vsc = VIRTIO_SERIAL_PORT_GET_CLASS(port);
     VirtIOSerialBus *bus = VIRTIO_SERIAL_BUS(qdev_get_parent_bus(dev));
+    VirtIODevice *vdev = VIRTIO_DEVICE(bus->vser);
     int max_nr_ports;
     bool plugging_port0;
     Error *err = NULL;
@@ -841,7 +856,7 @@ static void virtser_port_device_realize(DeviceState *dev, Error **errp)
         }
     }
 
-    max_nr_ports = tswap32(port->vser->config.max_nr_ports);
+    max_nr_ports = virtio_tswap32(vdev, port->vser->config.max_nr_ports);
     if (port->id >= max_nr_ports) {
         error_setg(errp, "virtio-serial-bus: Out-of-range port id specified, "
                          "max. allowed: %u", max_nr_ports - 1);
@@ -863,7 +878,7 @@ static void virtser_port_device_realize(DeviceState *dev, Error **errp)
     add_port(port->vser, port->id);
 
     /* Send an update to the guest about this new port added */
-    virtio_notify_config(VIRTIO_DEVICE(port->vser));
+    virtio_notify_config(vdev);
 }
 
 static void virtser_port_device_unrealize(DeviceState *dev, Error **errp)
@@ -942,7 +957,8 @@ static void virtio_serial_device_realize(DeviceState *dev, Error **errp)
         vser->ovqs[i] = virtio_add_queue(vdev, 128, handle_output);
     }
 
-    vser->config.max_nr_ports = tswap32(vser->serial.max_virtserial_ports);
+    vser->config.max_nr_ports =
+        virtio_tswap32(vdev, vser->serial.max_virtserial_ports);
     vser->ports_map = g_malloc0(((vser->serial.max_virtserial_ports + 31) / 32)
         * sizeof(vser->ports_map[0]));
     /*
-- 
MST

  parent reply	other threads:[~2014-06-29 16:59 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-29 16:58 [Qemu-devel] [PULL 00/37] pc,vhost,virtio fixes, enhancements Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 01/37] numa: fix comment Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 02/37] openrisc: " Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 03/37] numa: " Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 04/37] pc: Move q35 compat props to PC_COMPAT_* Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 05/37] pc: Fix "prog_if" typo on PC_COMPAT_2_0 Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 06/37] mc146818rtc: add rtc-reset-reinjection QMP command Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 07/37] vhost-user: fix wrong ids in documentation Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 08/37] pc: make isapc and pc-0.10 to pc-0.13 have 1.7.0 memory layout Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 09/37] Allow mismatched virtio config-len Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 10/37] numa: Keep track of NUMA nodes present on the command-line Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 11/37] numa: Reject duplicate node IDs Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 12/37] numa: Reject configuration if not all node IDs are present Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 13/37] vhost-user: fix regions provied with VHOST_USER_SET_MEM_TABLE message Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 14/37] vhost-user: typo fixups Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 15/37] virtio-net: byteswap virtio-net header Michael S. Tsirkin
2014-06-29 16:58 ` [Qemu-devel] [PULL 16/37] virtio-serial: don't migrate the config space Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 17/37] virtio: introduce device specific migration calls Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 18/37] virtio-net: implement per-device " Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 19/37] virtio-blk: " Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 20/37] virtio-serial: " Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 21/37] virtio-balloon: " Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 22/37] virtio-rng: " Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 23/37] virtio: add subsections to the migration stream Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 24/37] exec: introduce target_words_bigendian() helper Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 25/37] cpu: introduce CPUClass::virtio_is_big_endian() Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 26/37] virtio: add endian-ambivalent support to VirtIODevice Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 27/37] virtio: memory accessors for endian-ambivalent targets Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 28/37] virtio: allow byte swapping for vring Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 29/37] virtio-net: use virtio wrappers to access headers Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 30/37] virtio-balloon: use virtio wrappers to access page frame numbers Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 31/37] virtio-blk: use virtio wrappers to access headers Michael S. Tsirkin
2014-06-29 16:59 ` [Qemu-devel] [PULL 32/37] virtio-scsi: " Michael S. Tsirkin
2014-06-29 17:00 ` Michael S. Tsirkin [this message]
2014-06-29 17:00 ` [Qemu-devel] [PULL 34/37] virtio-9p: " Michael S. Tsirkin
2014-06-29 17:00 ` [Qemu-devel] [PULL 35/37] target-ppc: enable virtio endian ambivalent support Michael S. Tsirkin
2014-06-29 17:00 ` [Qemu-devel] [PULL 36/37] vhost-net: disable when cross-endian Michael S. Tsirkin
2014-06-29 17:00 ` [Qemu-devel] [PULL 37/37] tests: add human format test for string output visitor Michael S. Tsirkin
2014-07-09 19:14   ` Andreas Färber
2014-07-09 19:34     ` Peter Maydell
2014-06-29 17:36 ` [Qemu-devel] [PULL 00/37] pc,vhost,virtio fixes, enhancements Peter Maydell
2014-06-29 20:34   ` Michael S. Tsirkin
2014-06-29 20:41     ` Peter Maydell

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=1404060115-27410-34-git-send-email-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=agraf@suse.de \
    --cc=aliguori@amazon.com \
    --cc=aliguori@us.ibm.com \
    --cc=amit.shah@redhat.com \
    --cc=gkurz@linux.vnet.ibm.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rusty@rustcorp.com.au \
    /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.