From patchwork Fri May 25 10:21:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Morel X-Patchwork-Id: 10426957 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 56692602D8 for ; Fri, 25 May 2018 10:22:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F13B2963B for ; Fri, 25 May 2018 10:22:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3409E29641; Fri, 25 May 2018 10:22:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 99ABC2963B for ; Fri, 25 May 2018 10:22:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965647AbeEYKWQ (ORCPT ); Fri, 25 May 2018 06:22:16 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:43538 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965977AbeEYKVf (ORCPT ); Fri, 25 May 2018 06:21:35 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4P9s8CB079014 for ; Fri, 25 May 2018 06:21:35 -0400 Received: from e06smtp13.uk.ibm.com (e06smtp13.uk.ibm.com [195.75.94.109]) by mx0a-001b2d01.pphosted.com with ESMTP id 2j6fmdtpwu-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 25 May 2018 06:21:34 -0400 Received: from localhost by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 25 May 2018 11:21:32 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 25 May 2018 11:21:30 +0100 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4PALTbD12058932; Fri, 25 May 2018 10:21:29 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A3966A4059; Fri, 25 May 2018 11:12:47 +0100 (BST) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 65F41A4051; Fri, 25 May 2018 11:12:47 +0100 (BST) Received: from morel-ThinkPad-W530.boeblingen.de.ibm.com (unknown [9.152.224.33]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 25 May 2018 11:12:47 +0100 (BST) From: Pierre Morel To: pasic@linux.vnet.ibm.com, bjsdjshi@linux.vnet.ibm.com Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, cohuck@redhat.com Subject: [PATCH v2 08/10] vfio: ccw: Handling reset and shutdown with states Date: Fri, 25 May 2018 12:21:16 +0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527243678-3140-1-git-send-email-pmorel@linux.vnet.ibm.com> References: <1527243678-3140-1-git-send-email-pmorel@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18052510-0012-0000-0000-000005DA7F93 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18052510-0013-0000-0000-00001957D350 Message-Id: <1527243678-3140-9-git-send-email-pmorel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-05-25_04:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1805250113 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Two new events, VFIO_CCW_EVENT_ONLINE and VFIO_CCW_EVENT_OFFLINE allow to handle the enabling and disabling of a Sub Channel and the init, shutdown, quiesce and reset operations are changed accordingly. Signed-off-by: Pierre Morel --- drivers/s390/cio/vfio_ccw_drv.c | 44 ++++------------------ drivers/s390/cio/vfio_ccw_fsm.c | 75 +++++++++++++++++++++++++++++++++---- drivers/s390/cio/vfio_ccw_ops.c | 15 ++------ drivers/s390/cio/vfio_ccw_private.h | 3 ++ 4 files changed, 82 insertions(+), 55 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c index 6fc7668..3e7b514 100644 --- a/drivers/s390/cio/vfio_ccw_drv.c +++ b/drivers/s390/cio/vfio_ccw_drv.c @@ -30,41 +30,13 @@ int vfio_ccw_sch_quiesce(struct subchannel *sch) { struct vfio_ccw_private *private = dev_get_drvdata(&sch->dev); DECLARE_COMPLETION_ONSTACK(completion); - int iretry, ret = 0; - - spin_lock_irq(sch->lock); - if (!sch->schib.pmcw.ena) - goto out_unlock; - ret = cio_disable_subchannel(sch); - if (ret != -EBUSY) - goto out_unlock; - - do { - iretry = 255; - - ret = cio_cancel_halt_clear(sch, &iretry); - while (ret == -EBUSY) { - /* - * Flush all I/O and wait for - * cancel/halt/clear completion. - */ - private->completion = &completion; - spin_unlock_irq(sch->lock); - - wait_for_completion_timeout(&completion, 3*HZ); - - spin_lock_irq(sch->lock); - private->completion = NULL; - flush_workqueue(vfio_ccw_work_q); - ret = cio_cancel_halt_clear(sch, &iretry); - }; - - ret = cio_disable_subchannel(sch); - } while (ret == -EBUSY); -out_unlock: - private->state = VFIO_CCW_STATE_NOT_OPER; - spin_unlock_irq(sch->lock); - return ret; + + private->completion = &completion; + vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_OFFLINE); + wait_for_completion_interruptible_timeout(&completion, jiffies + 3*HZ); + if (private->state != VFIO_CCW_STATE_STANDBY) + return -EFAULT; + return 0; } static void vfio_ccw_sch_io_todo(struct work_struct *work) @@ -95,8 +67,6 @@ static void vfio_ccw_sch_irq(struct subchannel *sch) memcpy(&private->irb, irb, sizeof(*irb)); queue_work(vfio_ccw_work_q, &private->io_work); - if (private->completion) - complete(private->completion); } static int vfio_ccw_sch_probe(struct subchannel *sch) diff --git a/drivers/s390/cio/vfio_ccw_fsm.c b/drivers/s390/cio/vfio_ccw_fsm.c index 20b909c..0acab2f 100644 --- a/drivers/s390/cio/vfio_ccw_fsm.c +++ b/drivers/s390/cio/vfio_ccw_fsm.c @@ -73,6 +73,53 @@ static int fsm_notoper(struct vfio_ccw_private *private) return VFIO_CCW_STATE_NOT_OPER; } +static int fsm_online(struct vfio_ccw_private *private) +{ + struct subchannel *sch = private->sch; + int ret = VFIO_CCW_STATE_IDLE; + + spin_lock_irq(sch->lock); + if (cio_enable_subchannel(sch, (u32)(unsigned long)sch)) + ret = VFIO_CCW_STATE_NOT_OPER; + spin_unlock_irq(sch->lock); + + return ret; +} +static int fsm_offline(struct vfio_ccw_private *private) +{ + struct subchannel *sch = private->sch; + int ret = VFIO_CCW_STATE_STANDBY; + + spin_lock_irq(sch->lock); + if (cio_disable_subchannel(sch)) + ret = VFIO_CCW_STATE_NOT_OPER; + spin_unlock_irq(sch->lock); + if (private->completion) + complete(private->completion); + + return ret; +} +static int fsm_quiescing(struct vfio_ccw_private *private) +{ + struct subchannel *sch = private->sch; + int ret = VFIO_CCW_STATE_STANDBY; + int iretry = 255; + + spin_lock_irq(sch->lock); + ret = cio_cancel_halt_clear(sch, &iretry); + if (ret == -EBUSY) + ret = VFIO_CCW_STATE_QUIESCING; + else if (private->completion) + complete(private->completion); + spin_unlock_irq(sch->lock); + return ret; +} +static int fsm_quiescing_done(struct vfio_ccw_private *private) +{ + if (private->completion) + complete(private->completion); + return VFIO_CCW_STATE_STANDBY; +} /* * No operation action. */ @@ -178,15 +225,10 @@ static int fsm_sch_event(struct vfio_ccw_private *private) static int fsm_init(struct vfio_ccw_private *private) { struct subchannel *sch = private->sch; - int ret = VFIO_CCW_STATE_STANDBY; - spin_lock_irq(sch->lock); sch->isc = VFIO_CCW_ISC; - if (cio_enable_subchannel(sch, (u32)(unsigned long)sch)) - ret = VFIO_CCW_STATE_NOT_OPER; - spin_unlock_irq(sch->lock); - return ret; + return VFIO_CCW_STATE_STANDBY; } @@ -196,6 +238,8 @@ static int fsm_init(struct vfio_ccw_private *private) fsm_func_t *vfio_ccw_jumptable[NR_VFIO_CCW_STATES][NR_VFIO_CCW_EVENTS] = { [VFIO_CCW_STATE_NOT_OPER] = { [VFIO_CCW_EVENT_INIT] = fsm_init, + [VFIO_CCW_EVENT_ONLINE] = fsm_nop, + [VFIO_CCW_EVENT_OFFLINE] = fsm_nop, [VFIO_CCW_EVENT_NOT_OPER] = fsm_nop, [VFIO_CCW_EVENT_SSCH_REQ] = fsm_nop, [VFIO_CCW_EVENT_INTERRUPT] = fsm_nop, @@ -203,13 +247,17 @@ fsm_func_t *vfio_ccw_jumptable[NR_VFIO_CCW_STATES][NR_VFIO_CCW_EVENTS] = { }, [VFIO_CCW_STATE_STANDBY] = { [VFIO_CCW_EVENT_INIT] = fsm_nop, + [VFIO_CCW_EVENT_ONLINE] = fsm_online, + [VFIO_CCW_EVENT_OFFLINE] = fsm_offline, [VFIO_CCW_EVENT_NOT_OPER] = fsm_notoper, [VFIO_CCW_EVENT_SSCH_REQ] = fsm_io_error, - [VFIO_CCW_EVENT_INTERRUPT] = fsm_irq, + [VFIO_CCW_EVENT_INTERRUPT] = fsm_disabled_irq, [VFIO_CCW_EVENT_SCHIB_CHANGED] = fsm_sch_event, }, [VFIO_CCW_STATE_IDLE] = { [VFIO_CCW_EVENT_INIT] = fsm_nop, + [VFIO_CCW_EVENT_ONLINE] = fsm_nop, + [VFIO_CCW_EVENT_OFFLINE] = fsm_offline, [VFIO_CCW_EVENT_NOT_OPER] = fsm_notoper, [VFIO_CCW_EVENT_SSCH_REQ] = fsm_io_request, [VFIO_CCW_EVENT_INTERRUPT] = fsm_irq, @@ -217,6 +265,8 @@ fsm_func_t *vfio_ccw_jumptable[NR_VFIO_CCW_STATES][NR_VFIO_CCW_EVENTS] = { }, [VFIO_CCW_STATE_BOXED] = { [VFIO_CCW_EVENT_INIT] = fsm_nop, + [VFIO_CCW_EVENT_ONLINE] = fsm_nop, + [VFIO_CCW_EVENT_OFFLINE] = fsm_quiescing, [VFIO_CCW_EVENT_NOT_OPER] = fsm_notoper, [VFIO_CCW_EVENT_SSCH_REQ] = fsm_io_busy, [VFIO_CCW_EVENT_INTERRUPT] = fsm_irq, @@ -224,9 +274,20 @@ fsm_func_t *vfio_ccw_jumptable[NR_VFIO_CCW_STATES][NR_VFIO_CCW_EVENTS] = { }, [VFIO_CCW_STATE_BUSY] = { [VFIO_CCW_EVENT_INIT] = fsm_nop, + [VFIO_CCW_EVENT_ONLINE] = fsm_nop, + [VFIO_CCW_EVENT_OFFLINE] = fsm_quiescing, [VFIO_CCW_EVENT_NOT_OPER] = fsm_notoper, [VFIO_CCW_EVENT_SSCH_REQ] = fsm_io_busy, [VFIO_CCW_EVENT_INTERRUPT] = fsm_irq, [VFIO_CCW_EVENT_SCHIB_CHANGED] = fsm_sch_event, }, + [VFIO_CCW_STATE_QUIESCING] = { + [VFIO_CCW_EVENT_INIT] = fsm_nop, + [VFIO_CCW_EVENT_ONLINE] = fsm_nop, + [VFIO_CCW_EVENT_OFFLINE] = fsm_nop, + [VFIO_CCW_EVENT_NOT_OPER] = fsm_notoper, + [VFIO_CCW_EVENT_SSCH_REQ] = fsm_io_busy, + [VFIO_CCW_EVENT_INTERRUPT] = fsm_quiescing_done, + [VFIO_CCW_EVENT_SCHIB_CHANGED] = fsm_sch_event, + }, }; diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index ea8fd64..b202e73 100644 --- a/drivers/s390/cio/vfio_ccw_ops.c +++ b/drivers/s390/cio/vfio_ccw_ops.c @@ -21,21 +21,14 @@ static int vfio_ccw_mdev_reset(struct mdev_device *mdev) private = dev_get_drvdata(mdev_parent_dev(mdev)); sch = private->sch; - /* - * TODO: - * In the cureent stage, some things like "no I/O running" and "no - * interrupt pending" are clear, but we are not sure what other state - * we need to care about. - * There are still a lot more instructions need to be handled. We - * should come back here later. - */ + ret = vfio_ccw_sch_quiesce(sch); if (ret) return ret; + vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_ONLINE); - ret = cio_enable_subchannel(sch, (u32)(unsigned long)sch); - if (!ret) - private->state = VFIO_CCW_STATE_IDLE; + if (!(private->state == VFIO_CCW_STATE_IDLE)) + ret = -EFAULT; return ret; } diff --git a/drivers/s390/cio/vfio_ccw_private.h b/drivers/s390/cio/vfio_ccw_private.h index c5455a9..ad59091 100644 --- a/drivers/s390/cio/vfio_ccw_private.h +++ b/drivers/s390/cio/vfio_ccw_private.h @@ -68,6 +68,7 @@ enum vfio_ccw_state { VFIO_CCW_STATE_IDLE, VFIO_CCW_STATE_BOXED, VFIO_CCW_STATE_BUSY, + VFIO_CCW_STATE_QUIESCING, /* last element! */ NR_VFIO_CCW_STATES }; @@ -81,6 +82,8 @@ enum vfio_ccw_event { VFIO_CCW_EVENT_SSCH_REQ, VFIO_CCW_EVENT_INTERRUPT, VFIO_CCW_EVENT_SCHIB_CHANGED, + VFIO_CCW_EVENT_ONLINE, + VFIO_CCW_EVENT_OFFLINE, /* last element! */ NR_VFIO_CCW_EVENTS };