Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3302072imm; Fri, 25 May 2018 03:24:22 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrj9WiRGGd9xYr8eCEY6XhLvQvciJXWSBd3kBdh3o1ukhqTLs33m9xmZLefDYNwWS5qoq3f X-Received: by 2002:a62:9f15:: with SMTP id g21-v6mr1884363pfe.207.1527243862939; Fri, 25 May 2018 03:24:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527243862; cv=none; d=google.com; s=arc-20160816; b=sjLx6OxqWzkPpb8WeQOPmXgBWjyIPueqJHBT85OcsuP35Fj/MdJaVtTT1yB5vkf96E wHkVgNs+QETVqjuv16OlupBL4ef9NPw19LsxOACdBR+SDFemUV39cRgE9m0HwAaxoz/p inZW5aZKzVLs3cG5vv2nMS5xXMsnsLIMqd/Z1C+rpqrh1DdzKq43+q2R3ZTLMKR4gSAA LMes+mHzep4BYVl/ixc3nQcYsBmaczARL1cvX58HcekzNSGbxUBcpLCSB0Lnpf8aiOoN xdEcxwtK4IQshN3vYyZ9WklZBmLUV3KPPkRLtxoPkGbO7lomCAcaDw+B2ZKzbfkx360m ojEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=LgsKAeDWLxYDUBHEdTkm35UjdfQ6FOO8gcLqWrBYvnY=; b=WdT4mwcwTk5TwhJShsvojsiAGIlGF40UhV9rRRw+SFvYiGa6xpeUi/GpVZ9u4cDO8/ RDpRYugliqtYebbhgjvJsaAiUyskEmN1IKhaRoUf4I4mGwsvxQUL7vlA8z/oagQ0f395 IkSGiaarX37+6M4qmo6ff3vWQYCYU2k5r+4L6rlQC2gMsSe2YQNsHRy4odSuuklz4qlz wdIDTXSuDaz5bs+MHLRJH+VShlpegRLCNj0bTUtjsmrMvIS7OYq/76El9Yv5i16bxy4f /wXNg1RdG0GoFJtQrGrKKavbSYUP/HRIHhrpeQrQmE11nf9K2Vj7ZIF0/In0xAHenYTk PHIA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k4-v6si5300745pgf.47.2018.05.25.03.24.08; Fri, 25 May 2018 03:24:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966198AbeEYKWT (ORCPT + 99 others); Fri, 25 May 2018 06:22:19 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:54716 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S965962AbeEYKVf (ORCPT ); Fri, 25 May 2018 06:21:35 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4P9s9F6016931 for ; Fri, 25 May 2018 06:21:34 -0400 Received: from e06smtp13.uk.ibm.com (e06smtp13.uk.ibm.com [195.75.94.109]) by mx0b-001b2d01.pphosted.com with ESMTP id 2j6fk8tusq-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: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 }; -- 2.7.4