qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
To: kvm@vger.kernel.org, linux-s390@vger.kernel.org, qemu-devel@nongnu.org
Cc: bjsdjshi@linux.vnet.ibm.com, renxiaof@linux.vnet.ibm.com,
	cornelia.huck@de.ibm.com, borntraeger@de.ibm.com, agraf@suse.com,
	alex.williamson@redhat.com
Subject: [Qemu-devel] [PATCH RFC 5/8] vfio: ccw: realize VFIO_DEVICE_CCW_HOT_RESET ioctl
Date: Fri, 29 Apr 2016 14:11:52 +0200	[thread overview]
Message-ID: <1461931915-22397-6-git-send-email-bjsdjshi@linux.vnet.ibm.com> (raw)
In-Reply-To: <1461931915-22397-1-git-send-email-bjsdjshi@linux.vnet.ibm.com>

Introduce VFIO_DEVICE_CCW_HOT_RESET ioctl for vfio-ccw to make it
possible to hot-reset the device.

We try to achieve a hot reset by first offlining the device and then
onlining it again: this should clear all state at the subchannel.

Signed-off-by: Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
Reviewed-by: Pierre Morel <pmorel@linux.vnet.ibm.com>
---
 drivers/vfio/ccw/vfio_ccw.c | 50 ++++++++++++++++++++++++++++++++++++++++++++-
 include/uapi/linux/vfio.h   |  8 ++++++++
 2 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/drivers/vfio/ccw/vfio_ccw.c b/drivers/vfio/ccw/vfio_ccw.c
index 7331aed..9700448 100644
--- a/drivers/vfio/ccw/vfio_ccw.c
+++ b/drivers/vfio/ccw/vfio_ccw.c
@@ -22,10 +22,12 @@
  * struct vfio_ccw_device
  * @cdev: ccw device
  * @going_away: if an offline procedure was already ongoing
+ * @hot_reset: if hot-reset is ongoing
  */
 struct vfio_ccw_device {
 	struct ccw_device	*cdev;
 	bool			going_away;
+	bool			hot_reset;
 };
 
 enum vfio_ccw_device_type {
@@ -58,6 +60,7 @@ static void vfio_ccw_release(void *device_data)
 static long vfio_ccw_ioctl(void *device_data, unsigned int cmd,
 			   unsigned long arg)
 {
+	struct vfio_ccw_device *vcdev = device_data;
 	unsigned long minsz;
 
 	if (cmd == VFIO_DEVICE_GET_INFO) {
@@ -76,6 +79,34 @@ static long vfio_ccw_ioctl(void *device_data, unsigned int cmd,
 		info.num_irqs = 0;
 
 		return copy_to_user((void __user *)arg, &info, minsz);
+
+	} else if (cmd == VFIO_DEVICE_CCW_HOT_RESET) {
+		unsigned long flags;
+		int ret;
+
+		spin_lock_irqsave(get_ccwdev_lock(vcdev->cdev), flags);
+		if (!vcdev->cdev->online) {
+			spin_unlock_irqrestore(get_ccwdev_lock(vcdev->cdev),
+					       flags);
+			return -EINVAL;
+		}
+
+		if (vcdev->hot_reset) {
+			spin_unlock_irqrestore(get_ccwdev_lock(vcdev->cdev),
+					       flags);
+			return -EBUSY;
+		}
+		vcdev->hot_reset = true;
+		spin_unlock_irqrestore(get_ccwdev_lock(vcdev->cdev), flags);
+
+		ret = ccw_device_set_offline(vcdev->cdev);
+		if (!ret)
+			ret = ccw_device_set_online(vcdev->cdev);
+
+		spin_lock_irqsave(get_ccwdev_lock(vcdev->cdev), flags);
+		vcdev->hot_reset = false;
+		spin_unlock_irqrestore(get_ccwdev_lock(vcdev->cdev), flags);
+		return ret;
 	}
 
 	return -ENOTTY;
@@ -108,7 +139,7 @@ static int vfio_ccw_set_offline(struct ccw_device *cdev)
 
 	vdev = vfio_device_data(device);
 	vfio_device_put(device);
-	if (!vdev || vdev->going_away)
+	if (!vdev || vdev->hot_reset || vdev->going_away)
 		return 0;
 
 	vdev->going_away = true;
@@ -128,9 +159,26 @@ void vfio_ccw_remove(struct ccw_device *cdev)
 
 static int vfio_ccw_set_online(struct ccw_device *cdev)
 {
+	struct vfio_device *device = vfio_device_get_from_dev(&cdev->dev);
 	struct vfio_ccw_device *vdev;
 	int ret;
 
+	if (!device)
+		goto create_device;
+
+	vdev = vfio_device_data(device);
+	vfio_device_put(device);
+	if (!vdev)
+		goto create_device;
+
+	/*
+	 * During hot reset, we just want to disable/enable the
+	 * subchannel and need not setup anything again.
+	 */
+	if (vdev->hot_reset)
+		return 0;
+
+create_device:
 	vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
 	if (!vdev)
 		return -ENOMEM;
diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h
index aaedfcd..889a316 100644
--- a/include/uapi/linux/vfio.h
+++ b/include/uapi/linux/vfio.h
@@ -687,6 +687,14 @@ struct vfio_iommu_spapr_tce_remove {
 };
 #define VFIO_IOMMU_SPAPR_TCE_REMOVE	_IO(VFIO_TYPE, VFIO_BASE + 20)
 
+/**
+ * VFIO_DEVICE_CCW_HOT_RESET - _IOW(VFIO_TYPE, VFIO_BASE + 21)
+ *
+ * Hot reset the channel I/O device. All state of the subchannel will be
+ * cleared.
+ */
+#define VFIO_DEVICE_CCW_HOT_RESET	_IO(VFIO_TYPE, VFIO_BASE + 21)
+
 /* ***************************************************************** */
 
 #endif /* _UAPIVFIO_H */
-- 
2.6.6

  parent reply	other threads:[~2016-04-29 12:13 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-29 12:11 [Qemu-devel] [PATCH RFC 0/8] basic vfio-ccw infrastructure Dong Jia Shi
2016-04-29 12:11 ` [Qemu-devel] [PATCH RFC 1/8] iommu: s390: enable iommu api for s390 ccw devices Dong Jia Shi
2016-04-29 12:11 ` [Qemu-devel] [PATCH RFC 2/8] s390: move orb.h from drivers/s390/ to arch/s390/ Dong Jia Shi
2016-04-29 12:11 ` [Qemu-devel] [PATCH RFC 3/8] vfio: ccw: basic implementation for vfio_ccw driver Dong Jia Shi
2016-04-29 12:11 ` [Qemu-devel] [PATCH RFC 4/8] vfio: ccw: realize VFIO_DEVICE_GET_INFO ioctl Dong Jia Shi
2016-04-29 12:11 ` Dong Jia Shi [this message]
2016-04-29 12:11 ` [Qemu-devel] [PATCH RFC 6/8] vfio: ccw: introduce page array interfaces Dong Jia Shi
2016-04-29 12:11 ` [Qemu-devel] [PATCH RFC 7/8] vfio: ccw: introduce ccw chain interfaces Dong Jia Shi
2016-04-29 12:11 ` [Qemu-devel] [PATCH RFC 8/8] vfio: ccw: realize VFIO_DEVICE_CCW_CMD_REQUEST ioctl Dong Jia Shi
2016-04-29 17:17 ` [Qemu-devel] [PATCH RFC 0/8] basic vfio-ccw infrastructure Alex Williamson
2016-05-04  9:26   ` Dong Jia
2016-05-04 19:26     ` Alex Williamson
2016-05-05 10:29       ` Dong Jia
2016-05-05 19:19         ` Alex Williamson
2016-05-05 20:23           ` Neo Jia
2016-05-09  9:59             ` Dong Jia
2016-05-09  9:55           ` Dong Jia

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=1461931915-22397-6-git-send-email-bjsdjshi@linux.vnet.ibm.com \
    --to=bjsdjshi@linux.vnet.ibm.com \
    --cc=agraf@suse.com \
    --cc=alex.williamson@redhat.com \
    --cc=borntraeger@de.ibm.com \
    --cc=cornelia.huck@de.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=qemu-devel@nongnu.org \
    --cc=renxiaof@linux.vnet.ibm.com \
    /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).