From patchwork Fri Mar 17 03:17:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dong Jia Shi X-Patchwork-Id: 740115 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vkrQb61Q4z9s0Z for ; Fri, 17 Mar 2017 14:28:23 +1100 (AEDT) Received: from localhost ([::1]:46925 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coiYv-0006SB-51 for incoming@patchwork.ozlabs.org; Thu, 16 Mar 2017 23:28:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56979) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1coiPY-0006mB-AH for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:18:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1coiPT-0000Ru-9I for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:18:40 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:52560 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1coiPT-0000Rn-2a for qemu-devel@nongnu.org; Thu, 16 Mar 2017 23:18:35 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v2H3DtDH005158 for ; Thu, 16 Mar 2017 23:18:34 -0400 Received: from e31.co.us.ibm.com (e31.co.us.ibm.com [32.97.110.149]) by mx0b-001b2d01.pphosted.com with ESMTP id 297nkp1x6u-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Mar 2017 23:18:34 -0400 Received: from localhost by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Mar 2017 21:18:33 -0600 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Mar 2017 21:18:29 -0600 Received: from b03ledav003.gho.boulder.ibm.com (b03ledav003.gho.boulder.ibm.com [9.17.130.234]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v2H3ISbZ17170730; Thu, 16 Mar 2017 20:18:28 -0700 Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 561E96A043; Thu, 16 Mar 2017 21:18:28 -0600 (MDT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by b03ledav003.gho.boulder.ibm.com (Postfix) with ESMTP id 6A9116A03D; Thu, 16 Mar 2017 21:18:26 -0600 (MDT) From: Dong Jia Shi To: kvm@vger.kernel.org, linux-s390@vger.kernel.org, qemu-devel@nongnu.org Date: Fri, 17 Mar 2017 04:17:39 +0100 X-Mailer: git-send-email 2.8.4 In-Reply-To: <20170317031743.40128-1-bjsdjshi@linux.vnet.ibm.com> References: <20170317031743.40128-1-bjsdjshi@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17031703-8235-0000-0000-00000B240AA0 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006796; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000206; SDB=6.00834930; UDB=6.00410081; IPR=6.00612586; BA=6.00005215; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00014684; XFM=3.00000013; UTC=2017-03-17 03:18:31 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17031703-8236-0000-0000-00003A6432B9 Message-Id: <20170317031743.40128-13-bjsdjshi@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-17_01:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1703170025 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH v4 12/16] vfio: ccw: return I/O results asynchronously 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: pasic@linux.vnet.ibm.com, pmorel@linux.vnet.ibm.com, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Introduce a singlethreaded workqueue to handle the I/O interrupts. With the work added to this queue, we store the I/O results to the io_region of the subchannel, then signal the userspace program to handle the results. Signed-off-by: Dong Jia Shi --- drivers/s390/cio/vfio_ccw_drv.c | 58 ++++++++++++++++++++++--------------- drivers/s390/cio/vfio_ccw_ops.c | 3 -- drivers/s390/cio/vfio_ccw_private.h | 7 ++--- 3 files changed, 37 insertions(+), 31 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c index b5971d3..3e0a40e 100644 --- a/drivers/s390/cio/vfio_ccw_drv.c +++ b/drivers/s390/cio/vfio_ccw_drv.c @@ -20,6 +20,8 @@ #include "css.h" #include "vfio_ccw_private.h" +struct workqueue_struct *vfio_ccw_work_q; + /* * Helpers */ @@ -52,6 +54,7 @@ int vfio_ccw_sch_quiesce(struct subchannel *sch) spin_lock_irq(sch->lock); private->completion = NULL; + flush_workqueue(vfio_ccw_work_q); ret = cio_cancel_halt_clear(sch, &iretry); }; @@ -63,18 +66,12 @@ int vfio_ccw_sch_quiesce(struct subchannel *sch) return ret; } -static int doing_io(struct vfio_ccw_private *private, u32 intparm) -{ - return (private->intparm == intparm); -} - static int vfio_ccw_sch_io_helper(struct vfio_ccw_private *private) { struct subchannel *sch; union orb *orb; int ccode; __u8 lpm; - u32 intparm; sch = private->sch; @@ -89,7 +86,7 @@ static int vfio_ccw_sch_io_helper(struct vfio_ccw_private *private) * Initialize device status information */ sch->schib.scsw.cmd.actl |= SCSW_ACTL_START_PEND; - break; + return 0; case 1: /* Status pending */ case 2: /* Busy */ return -EBUSY; @@ -109,15 +106,26 @@ static int vfio_ccw_sch_io_helper(struct vfio_ccw_private *private) default: return ccode; } +} - intparm = (u32)(addr_t)sch; - private->intparm = 0; - wait_event(private->wait_q, doing_io(private, intparm)); +static void vfio_ccw_sch_io_todo(struct work_struct *work) +{ + struct vfio_ccw_private *private; + struct subchannel *sch; + struct irb *irb; - if (scsw_is_solicited(&private->irb.scsw)) - cp_update_scsw(&private->cp, &private->irb.scsw); + private = container_of(work, struct vfio_ccw_private, io_work); + irb = &private->irb; + sch = private->sch; - return 0; + if (scsw_is_solicited(&irb->scsw)) { + cp_update_scsw(&private->cp, &irb->scsw); + cp_free(&private->cp); + } + memcpy(private->io_region.irb_area, irb, sizeof(*irb)); + + if (private->io_trigger) + eventfd_signal(private->io_trigger, 1); } /* Deal with the ccw command request from the userspace. */ @@ -126,7 +134,6 @@ int vfio_ccw_sch_cmd_request(struct vfio_ccw_private *private) struct mdev_device *mdev = private->mdev; union orb *orb; union scsw *scsw = &private->scsw; - struct irb *irb = &private->irb; struct ccw_io_region *io_region = &private->io_region; int ret; @@ -147,12 +154,8 @@ int vfio_ccw_sch_cmd_request(struct vfio_ccw_private *private) /* Start channel program and wait for I/O interrupt. */ ret = vfio_ccw_sch_io_helper(private); - if (!ret) { - /* Get irb info and copy it to irb_area. */ - memcpy(io_region->irb_area, irb, sizeof(*irb)); - } - - cp_free(&private->cp); + if (!ret) + cp_free(&private->cp); } else if (scsw->cmd.fctl & SCSW_FCTL_HALT_FUNC) { /* XXX: Handle halt. */ ret = -EOPNOTSUPP; @@ -229,8 +232,8 @@ static void vfio_ccw_sch_irq(struct subchannel *sch) irb = this_cpu_ptr(&cio_irb); memcpy(&private->irb, irb, sizeof(*irb)); - private->intparm = (u32)(addr_t)sch; - wake_up(&private->wait_q); + + queue_work(vfio_ccw_work_q, &private->io_work); if (private->completion) complete(private->completion); @@ -269,7 +272,7 @@ static int vfio_ccw_sch_probe(struct subchannel *sch) if (ret) goto out_rm_group; - init_waitqueue_head(&private->wait_q); + INIT_WORK(&private->io_work, vfio_ccw_sch_io_todo); atomic_set(&private->avail, 1); return 0; @@ -367,10 +370,16 @@ static int __init vfio_ccw_sch_init(void) { int ret; + vfio_ccw_work_q = create_singlethread_workqueue("vfio-ccw"); + if (!vfio_ccw_work_q) + return -ENOMEM; + isc_register(VFIO_CCW_ISC); ret = css_driver_register(&vfio_ccw_sch_driver); - if (ret) + if (ret) { isc_unregister(VFIO_CCW_ISC); + destroy_workqueue(vfio_ccw_work_q); + } return ret; } @@ -379,6 +388,7 @@ static void __exit vfio_ccw_sch_exit(void) { css_driver_unregister(&vfio_ccw_sch_driver); isc_unregister(VFIO_CCW_ISC); + destroy_workqueue(vfio_ccw_work_q); } module_init(vfio_ccw_sch_init); module_exit(vfio_ccw_sch_exit); diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index 1294c53..d754d3d 100644 --- a/drivers/s390/cio/vfio_ccw_ops.c +++ b/drivers/s390/cio/vfio_ccw_ops.c @@ -202,9 +202,6 @@ static ssize_t vfio_ccw_mdev_write(struct mdev_device *mdev, if (region->ret_code != 0) return region->ret_code; - if (private->io_trigger) - eventfd_signal(private->io_trigger, 1); - return count; } diff --git a/drivers/s390/cio/vfio_ccw_private.h b/drivers/s390/cio/vfio_ccw_private.h index dddab52..2503797 100644 --- a/drivers/s390/cio/vfio_ccw_private.h +++ b/drivers/s390/cio/vfio_ccw_private.h @@ -12,6 +12,7 @@ #include #include +#include #include #include "css.h" @@ -25,12 +26,11 @@ * @mdev: pointer to the mediated device * @nb: notifier for vfio events * @io_region: MMIO region to input/output I/O arguments/results - * @wait_q: wait for interrupt - * @intparm: record current interrupt parameter, used for wait interrupt * @cp: channel program for the current I/O operation * @irb: irb info received from interrupt * @scsw: scsw info * @io_trigger: eventfd ctx for signaling userspace I/O results + * @io_work: work for deferral process of I/O handling */ struct vfio_ccw_private { struct subchannel *sch; @@ -40,13 +40,12 @@ struct vfio_ccw_private { struct notifier_block nb; struct ccw_io_region io_region; - wait_queue_head_t wait_q; - u32 intparm; struct channel_program cp; struct irb irb; union scsw scsw; struct eventfd_ctx *io_trigger; + struct work_struct io_work; } __aligned(8); extern int vfio_ccw_mdev_reg(struct subchannel *sch);