From patchwork Fri Apr 29 12:11:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dong Jia Shi X-Patchwork-Id: 8983101 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id EEC5FBF29F for ; Fri, 29 Apr 2016 13:57:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A7AF0201CE for ; Fri, 29 Apr 2016 13:57:37 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D9D4C20142 for ; Fri, 29 Apr 2016 13:57:36 +0000 (UTC) Received: from localhost ([::1]:54672 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aw8vF-00012s-5G for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 Apr 2016 09:57:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39974) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aw7IJ-0001uN-5L for qemu-devel@nongnu.org; Fri, 29 Apr 2016 08:13:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aw7I3-00035Z-Cp for qemu-devel@nongnu.org; Fri, 29 Apr 2016 08:13:09 -0400 Received: from e19.ny.us.ibm.com ([129.33.205.209]:36867) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aw7I3-0002vE-8x for qemu-devel@nongnu.org; Fri, 29 Apr 2016 08:12:59 -0400 Received: from localhost by e19.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 29 Apr 2016 08:12:22 -0400 Received: from d01dlp01.pok.ibm.com (9.56.250.166) by e19.ny.us.ibm.com (146.89.104.206) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 29 Apr 2016 08:12:18 -0400 X-IBM-Helo: d01dlp01.pok.ibm.com X-IBM-MailFrom: bjsdjshi@linux.vnet.ibm.com X-IBM-RcptTo: qemu-devel@nongnu.org; alex.williamson@redhat.com; agraf@suse.com; kvm@vger.kernel.org; linux-s390@vger.kernel.org Received: from b01cxnp23032.gho.pok.ibm.com (b01cxnp23032.gho.pok.ibm.com [9.57.198.27]) by d01dlp01.pok.ibm.com (Postfix) with ESMTP id 1546E38C8054; Fri, 29 Apr 2016 08:12:18 -0400 (EDT) Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u3TCC6M737224470; Fri, 29 Apr 2016 12:12:17 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 415D42803A; Fri, 29 Apr 2016 08:12:15 -0400 (EDT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTP id 31B9D2803F; Fri, 29 Apr 2016 08:12:14 -0400 (EDT) From: Dong Jia Shi To: kvm@vger.kernel.org, linux-s390@vger.kernel.org, qemu-devel@nongnu.org Date: Fri, 29 Apr 2016 14:11:52 +0200 Message-Id: <1461931915-22397-6-git-send-email-bjsdjshi@linux.vnet.ibm.com> X-Mailer: git-send-email 2.6.6 In-Reply-To: <1461931915-22397-1-git-send-email-bjsdjshi@linux.vnet.ibm.com> References: <1461931915-22397-1-git-send-email-bjsdjshi@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16042912-0057-0000-0000-0000042FDCB7 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 129.33.205.209 Subject: [Qemu-devel] [PATCH RFC 5/8] vfio: ccw: realize VFIO_DEVICE_CCW_HOT_RESET ioctl X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: borntraeger@de.ibm.com, alex.williamson@redhat.com, renxiaof@linux.vnet.ibm.com, cornelia.huck@de.ibm.com, bjsdjshi@linux.vnet.ibm.com, agraf@suse.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Pierre Morel --- 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 */