All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rusty Russell <rusty@rustcorp.com.au>
To: virtualization@lists.linux-foundation.org
Subject: [PATCH 22/22] virtio_pci: fix finalize_features in modern driver.
Date: Thu, 21 Mar 2013 18:59:43 +1030	[thread overview]
Message-ID: <1363854584-25795-23-git-send-email-rusty@rustcorp.com.au> (raw)
In-Reply-To: <1363854584-25795-1-git-send-email-rusty@rustcorp.com.au>

Because we have potentially-infinite feature bits, it's hard for the device
to know when features are finalized.

This adds a new status bit, VIRTIO_CONFIG_S_FEATURES_DONE, which is only
set by the modern virtio_pci driver at the moment.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 drivers/virtio/virtio_pci-common.c |   28 --------------
 drivers/virtio/virtio_pci-common.h |    1 -
 drivers/virtio/virtio_pci.c        |   73 ++++++++++++++++++++++++++----------
 drivers/virtio/virtio_pci_legacy.c |   27 +++++++++++++
 include/uapi/linux/virtio_config.h |    2 +
 5 files changed, 83 insertions(+), 48 deletions(-)

diff --git a/drivers/virtio/virtio_pci-common.c b/drivers/virtio/virtio_pci-common.c
index d4e33ad..d2c78c8 100644
--- a/drivers/virtio/virtio_pci-common.c
+++ b/drivers/virtio/virtio_pci-common.c
@@ -392,32 +392,4 @@ int virtio_pci_freeze(struct device *dev)
 		pci_disable_device(pci_dev);
 	return ret;
 }
-
-int virtio_pci_restore(struct device *dev)
-{
-	struct pci_dev *pci_dev = to_pci_dev(dev);
-	struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
-	struct virtio_driver *drv;
-	int ret;
-
-	drv = container_of(vp_dev->vdev.dev.driver,
-			   struct virtio_driver, driver);
-
-	ret = pci_enable_device(pci_dev);
-	if (ret)
-		return ret;
-
-	pci_set_master(pci_dev);
-	vp_dev->vdev.config->finalize_features(&vp_dev->vdev);
-
-	if (drv && drv->restore)
-		ret = drv->restore(&vp_dev->vdev);
-
-	/* Finally, tell the device we're all set */
-	if (!ret)
-		vp_dev->vdev.config->set_status(&vp_dev->vdev,
-						vp_dev->saved_status);
-
-	return ret;
-}
 #endif
diff --git a/drivers/virtio/virtio_pci-common.h b/drivers/virtio/virtio_pci-common.h
index 146c3be..dac434e 100644
--- a/drivers/virtio/virtio_pci-common.h
+++ b/drivers/virtio/virtio_pci-common.h
@@ -118,5 +118,4 @@ int virtio_pci_set_vq_affinity(struct virtqueue *vq, int cpu);
 
 #ifdef CONFIG_PM
 int virtio_pci_freeze(struct device *dev);
-int virtio_pci_restore(struct device *dev);
 #endif
diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c
index 97d9b54..4614a15 100644
--- a/drivers/virtio/virtio_pci.c
+++ b/drivers/virtio/virtio_pci.c
@@ -50,6 +50,21 @@ static u64 ioread64(__le64 *addr)
 	return ioread32(addr) | ((u64)ioread32((__le32 *)addr + 1) << 32);
 }
 
+/* config->{get,set}_status() implementations */
+static u8 vp_get_status(struct virtio_device *vdev)
+{
+	struct virtio_pci_device *vp_dev = to_vp_device(vdev);
+	return ioread8(&vp_dev->common->device_status);
+}
+
+static void vp_set_status(struct virtio_device *vdev, u8 status)
+{
+	struct virtio_pci_device *vp_dev = to_vp_device(vdev);
+	/* We should never be setting status to 0. */
+	BUG_ON(status == 0);
+	iowrite8(status, &vp_dev->common->device_status);
+}
+
 static u64 vp_get_features(struct virtio_device *vdev)
 {
 	struct virtio_pci_device *vp_dev = to_vp_device(vdev);
@@ -62,19 +77,27 @@ static u64 vp_get_features(struct virtio_device *vdev)
 	return features;
 }
 
-static void vp_finalize_features(struct virtio_device *vdev)
+static void write_features(struct virtio_device *vdev)
 {
 	struct virtio_pci_device *vp_dev = to_vp_device(vdev);
 
-	/* Give virtio_ring a chance to accept features. */
-	vring_transport_features(vdev);
-
 	iowrite32(0, &vp_dev->common->guest_feature_select);
 	iowrite32((u32)vdev->features, &vp_dev->common->guest_feature);
 	iowrite32(1, &vp_dev->common->guest_feature_select);
 	iowrite32(vdev->features >> 32, &vp_dev->common->guest_feature);
 }
 
+static void vp_finalize_features(struct virtio_device *vdev)
+{
+	/* Give virtio_ring a chance to accept features. */
+	vring_transport_features(vdev);
+
+	write_features(vdev);
+
+	/* Update status to lock it in. */
+	vp_set_status(vdev, vp_get_status(vdev)|VIRTIO_CONFIG_S_FEATURES_DONE);
+}
+
 /* virtio config is little-endian for virtio_pci (vs guest-endian for legacy) */
 static u8 vp_get8(struct virtio_device *vdev, unsigned offset)
 {
@@ -132,21 +155,6 @@ static void vp_set64(struct virtio_device *vdev, unsigned offset, u64 val)
 	iowrite64(val, vp_dev->device + offset);
 }
 
-/* config->{get,set}_status() implementations */
-static u8 vp_get_status(struct virtio_device *vdev)
-{
-	struct virtio_pci_device *vp_dev = to_vp_device(vdev);
-	return ioread8(&vp_dev->common->device_status);
-}
-
-static void vp_set_status(struct virtio_device *vdev, u8 status)
-{
-	struct virtio_pci_device *vp_dev = to_vp_device(vdev);
-	/* We should never be setting status to 0. */
-	BUG_ON(status == 0);
-	iowrite8(status, &vp_dev->common->device_status);
-}
-
 static void vp_reset(struct virtio_device *vdev)
 {
 	struct virtio_pci_device *vp_dev = to_vp_device(vdev);
@@ -571,6 +579,33 @@ static void virtio_pci_remove(struct pci_dev *pci_dev)
 }
 
 #ifdef CONFIG_PM
+static int virtio_pci_restore(struct device *dev)
+{
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
+	struct virtio_driver *drv;
+	int ret;
+
+	drv = container_of(vp_dev->vdev.dev.driver,
+			   struct virtio_driver, driver);
+
+	ret = pci_enable_device(pci_dev);
+	if (ret)
+		return ret;
+
+	pci_set_master(pci_dev);
+	write_features(&vp_dev->vdev);
+
+	if (drv && drv->restore)
+		ret = drv->restore(&vp_dev->vdev);
+
+	/* Finally, tell the device we're all set */
+	if (!ret)
+		vp_set_status(&vp_dev->vdev, vp_dev->saved_status);
+
+	return ret;
+}
+
 static const struct dev_pm_ops virtio_pci_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(virtio_pci_freeze, virtio_pci_restore)
 };
diff --git a/drivers/virtio/virtio_pci_legacy.c b/drivers/virtio/virtio_pci_legacy.c
index f78a858..cfff009 100644
--- a/drivers/virtio/virtio_pci_legacy.c
+++ b/drivers/virtio/virtio_pci_legacy.c
@@ -436,6 +436,33 @@ static void virtio_pci_remove(struct pci_dev *pci_dev)
 }
 
 #ifdef CONFIG_PM
+static int virtio_pci_restore(struct device *dev)
+{
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
+	struct virtio_driver *drv;
+	int ret;
+
+	drv = container_of(vp_dev->vdev.dev.driver,
+			   struct virtio_driver, driver);
+
+	ret = pci_enable_device(pci_dev);
+	if (ret)
+		return ret;
+
+	pci_set_master(pci_dev);
+	vp_finalize_features(&vp_dev->vdev);
+
+	if (drv && drv->restore)
+		ret = drv->restore(&vp_dev->vdev);
+
+	/* Finally, tell the device we're all set */
+	if (!ret)
+		vp_set_status(&vp_dev->vdev, vp_dev->saved_status);
+
+	return ret;
+}
+
 static const struct dev_pm_ops virtio_pci_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(virtio_pci_freeze, virtio_pci_restore)
 };
diff --git a/include/uapi/linux/virtio_config.h b/include/uapi/linux/virtio_config.h
index b7cda39..83848b7 100644
--- a/include/uapi/linux/virtio_config.h
+++ b/include/uapi/linux/virtio_config.h
@@ -36,6 +36,8 @@
 #define VIRTIO_CONFIG_S_ACKNOWLEDGE	1
 /* We have found a driver for the device. */
 #define VIRTIO_CONFIG_S_DRIVER		2
+/* Features are finalized (only for new virtio_pci) */
+#define VIRTIO_CONFIG_S_FEATURES_DONE	8
 /* Driver has used its parts of the config, and is happy */
 #define VIRTIO_CONFIG_S_DRIVER_OK	4
 /* We've given up on this device. */
-- 
1.7.10.4

      parent reply	other threads:[~2013-03-21  8:29 UTC|newest]

Thread overview: 94+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-21  8:29 [PATCH 00/22] New virtio PCI layout Rusty Russell
2013-03-21  8:29 ` [PATCH 01/22] virtio_config: introduce size-based accessors Rusty Russell
2013-03-21  8:29 ` [PATCH 02/22] virtio_config: use " Rusty Russell
2013-03-21  8:29 ` [PATCH 03/22] virtio_config: make transports implement accessors Rusty Russell
2013-03-21  9:09   ` Cornelia Huck
2013-03-22  0:31     ` Rusty Russell
2013-03-22  9:13       ` Cornelia Huck
2013-03-22 14:43   ` Sjur Brændeland
2013-03-24  4:24     ` Rusty Russell
2013-04-03 15:58       ` Sjur Brændeland
2013-04-02 17:16   ` Pawel Moll
2013-03-21  8:29 ` [PATCH 04/22] virtio: use u32, not bitmap for struct virtio_device's features Rusty Russell
2013-03-21 10:00   ` Cornelia Huck
2013-03-22  0:48     ` Rusty Russell
2013-03-21  8:29 ` [PATCH 05/22] virtio: add support for 64 bit features Rusty Russell
2013-03-21 10:06   ` Cornelia Huck
2013-03-22  0:50     ` Rusty Russell
2013-03-22  9:15       ` Cornelia Huck
2013-03-22 14:50     ` Sjur Brændeland
2013-03-22 20:12       ` Ohad Ben-Cohen
2013-03-25  8:30         ` Rusty Russell
2013-04-02 17:09   ` Pawel Moll
2013-03-21  8:29 ` [PATCH 06/22] virtio: move vring structure into struct virtqueue Rusty Russell
2013-03-21  8:29 ` [PATCH 07/22] pci: add pci_iomap_range Rusty Russell
2013-03-21  8:29 ` [PATCH 08/22] virtio-pci: define layout for virtio vendor-specific capabilities Rusty Russell
2013-03-21  8:29 ` [PATCH 09/22] virtio_pci: move old defines to legacy, introduce new structure Rusty Russell
2013-03-21  8:29 ` [PATCH 10/22] virtio_pci: use _LEGACY_ defines in virtio_pci_legacy.c Rusty Russell
2013-03-21  8:29 ` [PATCH 11/22] virtio_pci: don't use the legacy driver if we find the new PCI capabilities Rusty Russell
2013-03-21  8:29 ` [PATCH 12/22] virtio_pci: allow duplicate capabilities Rusty Russell
2013-03-21 10:28   ` Michael S. Tsirkin
2013-03-21 14:26     ` H. Peter Anvin
2013-03-21 14:43       ` Michael S. Tsirkin
2013-03-21 14:45         ` H. Peter Anvin
2013-03-21 15:19           ` Michael S. Tsirkin
2013-03-21 15:26             ` H. Peter Anvin
2013-03-21 15:58               ` Michael S. Tsirkin
2013-03-21 16:04                 ` H. Peter Anvin
2013-03-21 16:11                   ` Michael S. Tsirkin
2013-03-21 16:15                     ` H. Peter Anvin
2013-03-21 16:26                       ` Michael S. Tsirkin
2013-03-21 16:32                         ` H. Peter Anvin
2013-03-21 17:07                           ` Michael S. Tsirkin
2013-03-21 17:09                             ` H. Peter Anvin
2013-03-21 17:13                               ` Michael S. Tsirkin
2013-03-21 17:49                                 ` Michael S. Tsirkin
2013-03-21 17:54                                   ` H. Peter Anvin
2013-03-21 18:01                                     ` Michael S. Tsirkin
2013-03-22  0:57                                     ` Rusty Russell
2013-03-22  3:17                                       ` H. Peter Anvin
2013-03-24 13:14                                       ` Michael S. Tsirkin
2013-03-24 23:23                                         ` H. Peter Anvin
2013-03-25  6:53                                           ` Michael S. Tsirkin
2013-03-25  6:54                                             ` H. Peter Anvin
2013-03-25 10:03                                               ` Rusty Russell
2013-03-21  8:29 ` [PATCH 13/22] virtio_pci: new, capability-aware driver Rusty Russell
2013-03-21 10:24   ` Michael S. Tsirkin
2013-03-22  1:02     ` Rusty Russell
2013-03-24 13:08       ` Michael S. Tsirkin
2013-03-21  8:29 ` [PATCH 14/22] virtio_pci: layout changes as per hpa's suggestions Rusty Russell
2013-03-21  8:29 ` [PATCH 15/22] virtio_pci: use little endian for config space Rusty Russell
2013-03-21  8:29 ` [PATCH 16/22] virtio_pci: use separate notification offsets for each vq Rusty Russell
2013-03-21 10:13   ` Michael S. Tsirkin
2013-03-21 10:35     ` Michael S. Tsirkin
2013-03-22  2:52     ` Rusty Russell
2013-03-24 14:38       ` Michael S. Tsirkin
2013-03-24 20:19       ` Michael S. Tsirkin
2013-03-24 23:27         ` H. Peter Anvin
2013-03-25  7:05           ` Michael S. Tsirkin
2013-03-25 10:00         ` Rusty Russell
2013-03-26 19:39           ` Michael S. Tsirkin
2013-03-27  0:07             ` Rusty Russell
2013-03-27  0:22               ` H. Peter Anvin
2013-03-27  2:31                 ` H. Peter Anvin
2013-03-27 11:26                   ` Michael S. Tsirkin
2013-03-27 14:21                     ` H. Peter Anvin
2013-03-27 11:25               ` Michael S. Tsirkin
2013-03-28  4:50                 ` H. Peter Anvin
2013-03-30  3:19                   ` Rusty Russell
2013-04-02 22:51                     ` H. Peter Anvin
2013-04-03  6:10                       ` Rusty Russell
2013-04-03 11:22                         ` Michael S. Tsirkin
2013-04-03 14:10                           ` H. Peter Anvin
2013-04-03 14:35                             ` Michael S. Tsirkin
2013-04-03 14:35                               ` H. Peter Anvin
2013-04-03 17:02                                 ` Michael S. Tsirkin
2013-04-04  5:48                           ` Rusty Russell
2013-04-04  8:25                             ` Michael S. Tsirkin
2013-04-05  1:25                               ` Rusty Russell
2013-03-21  8:29 ` [PATCH 17/22] virtio_pci_legacy: cleanup struct virtio_pci_vq_info Rusty Russell
2013-03-21  8:29 ` [PATCH 18/22] virtio_pci: share structure between legacy and modern Rusty Russell
2013-03-21  8:29 ` [PATCH 19/22] virtio_pci: share interrupt/notify handlers " Rusty Russell
2013-03-21  8:29 ` [PATCH 20/22] virtio_pci: share virtqueue setup/teardown between modern and legacy driver Rusty Russell
2013-03-21  8:29 ` [PATCH 21/22] virtio_pci: simplify common helpers Rusty Russell
2013-03-21  8:29 ` Rusty Russell [this message]

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=1363854584-25795-23-git-send-email-rusty@rustcorp.com.au \
    --to=rusty@rustcorp.com.au \
    --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.