From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Andreas Faerber <afaerber@suse.de>,
Stefan Hajnoczi <stefanha@redhat.com>,
fred.konrad@greensocs.com
Subject: [Qemu-devel] [RFC 3/5] virtio: use child aliases for virtio-blk transport properties
Date: Wed, 19 Mar 2014 16:48:56 +0100 [thread overview]
Message-ID: <1395244138-8834-4-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1395244138-8834-1-git-send-email-stefanha@redhat.com>
PCI, CCW, and legacy s390 virtio kept their own copy of VirtIOBlkConf
and duplicated qdev properties from the virtio-blk device. The conf
struct was then memcpy into the VirtIOBlock object's VirtIOBlkConf.
This risks double-free since the same 'serial' property char* would be
duplicated and freed by both release functions.
Instead of making the conf struct memcpy smarter, avoid duplication
altogether and simply alias properties into the child object. Now there
is only one copy of VirtIOBlkConf and it lives inside the virtio device.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
hw/s390x/s390-virtio-bus.c | 3 +--
hw/s390x/s390-virtio-bus.h | 1 -
hw/s390x/virtio-ccw.c | 5 ++---
hw/s390x/virtio-ccw.h | 1 -
hw/virtio/virtio-pci.c | 5 ++---
hw/virtio/virtio-pci.h | 1 -
6 files changed, 5 insertions(+), 11 deletions(-)
diff --git a/hw/s390x/s390-virtio-bus.c b/hw/s390x/s390-virtio-bus.c
index e4fc353..064947b 100644
--- a/hw/s390x/s390-virtio-bus.c
+++ b/hw/s390x/s390-virtio-bus.c
@@ -179,7 +179,6 @@ static int s390_virtio_blk_init(VirtIOS390Device *s390_dev)
{
VirtIOBlkS390 *dev = VIRTIO_BLK_S390(s390_dev);
DeviceState *vdev = DEVICE(&dev->vdev);
- virtio_blk_set_conf(vdev, &(dev->blk));
qdev_set_parent_bus(vdev, BUS(&s390_dev->bus));
if (qdev_init(vdev) < 0) {
return -1;
@@ -525,7 +524,7 @@ static const TypeInfo s390_virtio_net = {
};
static Property s390_virtio_blk_properties[] = {
- DEFINE_VIRTIO_BLK_PROPERTIES(VirtIOBlkS390, blk),
+ DEFINE_VIRTIO_BLK_CHILD_ALIASES(VirtIOBlkS390, vdev),
DEFINE_PROP_END_OF_LIST(),
};
diff --git a/hw/s390x/s390-virtio-bus.h b/hw/s390x/s390-virtio-bus.h
index ac81bd8..ffd0df7 100644
--- a/hw/s390x/s390-virtio-bus.h
+++ b/hw/s390x/s390-virtio-bus.h
@@ -124,7 +124,6 @@ void s390_virtio_reset_idx(VirtIOS390Device *dev);
typedef struct VirtIOBlkS390 {
VirtIOS390Device parent_obj;
VirtIOBlock vdev;
- VirtIOBlkConf blk;
} VirtIOBlkS390;
/* virtio-scsi-s390 */
diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index a01801e..ba62dad 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -726,7 +726,6 @@ static int virtio_ccw_blk_init(VirtioCcwDevice *ccw_dev)
{
VirtIOBlkCcw *dev = VIRTIO_BLK_CCW(ccw_dev);
DeviceState *vdev = DEVICE(&dev->vdev);
- virtio_blk_set_conf(vdev, &(dev->blk));
qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
if (qdev_init(vdev) < 0) {
return -1;
@@ -1127,11 +1126,11 @@ static const TypeInfo virtio_ccw_net = {
static Property virtio_ccw_blk_properties[] = {
DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
DEFINE_VIRTIO_BLK_FEATURES(VirtioCcwDevice, host_features[0]),
- DEFINE_VIRTIO_BLK_PROPERTIES(VirtIOBlkCcw, blk),
+ DEFINE_VIRTIO_BLK_CHILD_ALIASES(VirtIOBlkCcw, vdev),
DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags,
VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true),
#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
- DEFINE_PROP_BIT("x-data-plane", VirtIOBlkCcw, blk.data_plane, 0, false),
+ DEFINE_PROP_CHILD_ALIAS("x-data-plane", VirtIOBlkCcw, vdev),
#endif
DEFINE_PROP_END_OF_LIST(),
};
diff --git a/hw/s390x/virtio-ccw.h b/hw/s390x/virtio-ccw.h
index 4393e44..7eea6b9 100644
--- a/hw/s390x/virtio-ccw.h
+++ b/hw/s390x/virtio-ccw.h
@@ -134,7 +134,6 @@ typedef struct VHostSCSICcw {
typedef struct VirtIOBlkCcw {
VirtioCcwDevice parent_obj;
VirtIOBlock vdev;
- VirtIOBlkConf blk;
} VirtIOBlkCcw;
/* virtio-balloon-ccw */
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 7b91841..ba86e1c 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -1068,10 +1068,10 @@ static Property virtio_blk_pci_properties[] = {
VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
- DEFINE_PROP_BIT("x-data-plane", VirtIOBlkPCI, blk.data_plane, 0, false),
+ DEFINE_PROP_CHILD_ALIAS("x-data-plane", VirtIOBlkPCI, vdev),
#endif
DEFINE_VIRTIO_BLK_FEATURES(VirtIOPCIProxy, host_features),
- DEFINE_VIRTIO_BLK_PROPERTIES(VirtIOBlkPCI, blk),
+ DEFINE_VIRTIO_BLK_CHILD_ALIASES(VirtIOBlkPCI, vdev),
DEFINE_PROP_END_OF_LIST(),
};
@@ -1079,7 +1079,6 @@ static int virtio_blk_pci_init(VirtIOPCIProxy *vpci_dev)
{
VirtIOBlkPCI *dev = VIRTIO_BLK_PCI(vpci_dev);
DeviceState *vdev = DEVICE(&dev->vdev);
- virtio_blk_set_conf(vdev, &(dev->blk));
qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
if (qdev_init(vdev) < 0) {
return -1;
diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h
index dc332ae..1cea157 100644
--- a/hw/virtio/virtio-pci.h
+++ b/hw/virtio/virtio-pci.h
@@ -131,7 +131,6 @@ struct VHostSCSIPCI {
struct VirtIOBlkPCI {
VirtIOPCIProxy parent_obj;
VirtIOBlock vdev;
- VirtIOBlkConf blk;
};
/*
--
1.8.5.3
next prev parent reply other threads:[~2014-03-19 15:49 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-19 15:48 [Qemu-devel] [RFC 0/5] virtio: use alias properties in transport devices Stefan Hajnoczi
2014-03-19 15:48 ` [Qemu-devel] [RFC 1/5] qdev: add child alias properties Stefan Hajnoczi
2014-05-14 13:27 ` Andreas Färber
2014-05-14 13:31 ` Paolo Bonzini
2014-05-14 14:13 ` Peter Crosthwaite
2014-05-14 14:17 ` Andreas Färber
2014-05-14 14:26 ` Peter Crosthwaite
2014-03-19 15:48 ` [Qemu-devel] [RFC 2/5] virtio: add child alias properties for virtio-blk Stefan Hajnoczi
2014-05-14 14:04 ` Peter Crosthwaite
2014-05-14 14:33 ` Stefan Hajnoczi
2014-05-14 14:38 ` Peter Crosthwaite
2014-03-19 15:48 ` Stefan Hajnoczi [this message]
2014-03-19 15:48 ` [Qemu-devel] [RFC 4/5] virtio-blk: drop virtio_blk_set_conf() Stefan Hajnoczi
2014-03-19 15:48 ` [Qemu-devel] [RFC 5/5] virtio: fix virtio-blk child refcount in transports Stefan Hajnoczi
2014-05-14 13:21 ` [Qemu-devel] [RFC 0/5] virtio: use alias properties in transport devices Stefan Hajnoczi
2014-05-16 15:08 ` Frederic Konrad
2014-05-19 14:21 ` Stefan Hajnoczi
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=1395244138-8834-4-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=afaerber@suse.de \
--cc=fred.konrad@greensocs.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.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 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).