From patchwork Wed May 13 14:29:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Farman X-Patchwork-Id: 11546553 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 40624739 for ; Wed, 13 May 2020 14:29:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CAE102065C for ; Wed, 13 May 2020 14:29:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389002AbgEMO3q (ORCPT ); Wed, 13 May 2020 10:29:46 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:29118 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388740AbgEMO3o (ORCPT ); Wed, 13 May 2020 10:29:44 -0400 Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 04DEA8Ig071505; Wed, 13 May 2020 10:29:44 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3101m23555-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 May 2020 10:29:43 -0400 Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 04DEA8Q3071527; Wed, 13 May 2020 10:29:43 -0400 Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0a-001b2d01.pphosted.com with ESMTP id 3101m2353k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 May 2020 10:29:43 -0400 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.16.0.27/8.16.0.27) with SMTP id 04DEL0s0030083; Wed, 13 May 2020 14:29:39 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma01fra.de.ibm.com with ESMTP id 3100ubgq3w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 May 2020 14:29:38 +0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 04DETaji25690322 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 May 2020 14:29:36 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0938642049; Wed, 13 May 2020 14:29:36 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F33A042042; Wed, 13 May 2020 14:29:35 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Wed, 13 May 2020 14:29:35 +0000 (GMT) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 4958) id A6917E02BA; Wed, 13 May 2020 16:29:35 +0200 (CEST) From: Eric Farman To: Cornelia Huck Cc: Jared Rossi , Halil Pasic , linux-s390@vger.kernel.org, kvm@vger.kernel.org, Eric Farman Subject: [RFC PATCH v2 1/4] vfio-ccw: Do not reset FSM state for unsolicited interrupts Date: Wed, 13 May 2020 16:29:31 +0200 Message-Id: <20200513142934.28788-2-farman@linux.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200513142934.28788-1-farman@linux.ibm.com> References: <20200513142934.28788-1-farman@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216,18.0.676 definitions=2020-05-13_06:2020-05-13,2020-05-13 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 spamscore=0 phishscore=0 mlxscore=0 suspectscore=0 malwarescore=0 clxscore=1015 mlxlogscore=762 adultscore=0 priorityscore=1501 lowpriorityscore=0 impostorscore=0 cotscore=-2147483648 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005130121 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The interrupt handler in vfio_ccw_sch_io_todo() presumes that every interrupt should reset the FSM state back to IDLE. But this means that an unsolicited interrupt will cause the FSM to be reset, such that an in-flight I/O (either still being built, or out on the wire) will cause a solicited interrupt for which vfio-ccw is no longer expecting. Example IRB, while state=CP_PROCESSING: irb.w0=00c00011 irb.cpa=02f420f8 irb.w2=85000000 Simply check that the interrupt is solicited before touching the FSM state. Fixes: bbe37e4cb8970 ("vfio: ccw: introduce a finite state machine") Signed-off-by: Eric Farman --- drivers/s390/cio/vfio_ccw_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c index 339a6bc0339b..7dd3efa1ccb8 100644 --- a/drivers/s390/cio/vfio_ccw_drv.c +++ b/drivers/s390/cio/vfio_ccw_drv.c @@ -98,7 +98,7 @@ static void vfio_ccw_sch_io_todo(struct work_struct *work) memcpy(private->io_region->irb_area, irb, sizeof(*irb)); mutex_unlock(&private->io_mutex); - if (private->mdev && is_final) + if (private->mdev && scsw_is_solicited(&irb->scsw) && is_final) private->state = VFIO_CCW_STATE_IDLE; if (private->io_trigger) From patchwork Wed May 13 14:29:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Farman X-Patchwork-Id: 11546549 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F081660D for ; Wed, 13 May 2020 14:29:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8687220659 for ; Wed, 13 May 2020 14:29:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388994AbgEMO3o (ORCPT ); Wed, 13 May 2020 10:29:44 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:51548 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388740AbgEMO3m (ORCPT ); Wed, 13 May 2020 10:29:42 -0400 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 04DEANjK047553; Wed, 13 May 2020 10:29:41 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3101m966xe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 May 2020 10:29:41 -0400 Received: from m0098416.ppops.net (m0098416.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 04DEAXuX048599; Wed, 13 May 2020 10:29:40 -0400 Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0b-001b2d01.pphosted.com with ESMTP id 3101m966wr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 May 2020 10:29:40 -0400 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.0.27/8.16.0.27) with SMTP id 04DEL5fc015403; Wed, 13 May 2020 14:29:39 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma03ams.nl.ibm.com with ESMTP id 3100ub9rgt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 May 2020 14:29:38 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 04DESPhm35062088 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 May 2020 14:28:25 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 157C7A4067; Wed, 13 May 2020 14:29:36 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EFA52A4062; Wed, 13 May 2020 14:29:35 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Wed, 13 May 2020 14:29:35 +0000 (GMT) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 4958) id A9320E02BB; Wed, 13 May 2020 16:29:35 +0200 (CEST) From: Eric Farman To: Cornelia Huck Cc: Jared Rossi , Halil Pasic , linux-s390@vger.kernel.org, kvm@vger.kernel.org, Eric Farman Subject: [RFC PATCH v2 2/4] vfio-ccw: Utilize scsw actl to serialize start operations Date: Wed, 13 May 2020 16:29:32 +0200 Message-Id: <20200513142934.28788-3-farman@linux.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200513142934.28788-1-farman@linux.ibm.com> References: <20200513142934.28788-1-farman@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216,18.0.676 definitions=2020-05-13_06:2020-05-13,2020-05-13 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 priorityscore=1501 suspectscore=0 clxscore=1015 spamscore=0 mlxlogscore=999 impostorscore=0 malwarescore=0 bulkscore=0 phishscore=0 cotscore=-2147483648 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005130121 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org We need a convenient way to manage the fact that a START SUBCHANNEL command is synchronous, the HALT SUBCHANNEL and CLEAR SUBCHANNEL commands are asynchronous, and the interrupts for all three are also asynchronous and unstacked from a workqueue. Fortunately, the POPS does provide a mechanism to serialize the operations, in the form of the activity control flags of the SCSW. Since we initialize the private->scsw from the guest io_region for each new START (done under the protection of the io_mutex), and then never touch it again, we can use that as a space to indicate which commands are active at the device. For a START SUBCHANNEL command, the POPS states: > Condition code 2 is set, and no other action is > taken, when a start, halt, or clear function is currently > in progress at the subchannel So, mark START PENDING in this copy of the SCSW Activity Controls, and use it to track when a command has started versus when its interrupt has been unstacked from the workqueue and processed. It's a bit unnatural, in that this doesn't transition the flags to Subchannel/Device Active once the command has been accepted. Since this is only in our local copy of the SCSW, and not the actual contents of the SCHIB, this is fine enough. Signed-off-by: Eric Farman --- drivers/s390/cio/vfio_ccw_drv.c | 4 +++- drivers/s390/cio/vfio_ccw_fsm.c | 12 ++++++++++++ drivers/s390/cio/vfio_ccw_ops.c | 4 +++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c index 7dd3efa1ccb8..ee153fa72a0f 100644 --- a/drivers/s390/cio/vfio_ccw_drv.c +++ b/drivers/s390/cio/vfio_ccw_drv.c @@ -98,8 +98,10 @@ static void vfio_ccw_sch_io_todo(struct work_struct *work) memcpy(private->io_region->irb_area, irb, sizeof(*irb)); mutex_unlock(&private->io_mutex); - if (private->mdev && scsw_is_solicited(&irb->scsw) && is_final) + if (private->mdev && scsw_is_solicited(&irb->scsw) && is_final) { private->state = VFIO_CCW_STATE_IDLE; + private->scsw.cmd.actl &= ~SCSW_ACTL_START_PEND; + } if (private->io_trigger) eventfd_signal(private->io_trigger, 1); diff --git a/drivers/s390/cio/vfio_ccw_fsm.c b/drivers/s390/cio/vfio_ccw_fsm.c index 23e61aa638e4..258ce32549f3 100644 --- a/drivers/s390/cio/vfio_ccw_fsm.c +++ b/drivers/s390/cio/vfio_ccw_fsm.c @@ -246,8 +246,20 @@ static void fsm_io_request(struct vfio_ccw_private *private, char *errstr = "request"; struct subchannel_id schid = get_schid(private); + if (scsw_actl(scsw) & SCSW_ACTL_START_PEND) { + io_region->ret_code = -EBUSY; + VFIO_CCW_MSG_EVENT(2, + "%pUl (%x.%x.%04x): actl %x pending\n", + mdev_uuid(mdev), schid.cssid, + schid.ssid, schid.sch_no, + scsw_actl(scsw)); + errstr = "pending"; + goto err_out; + } + private->state = VFIO_CCW_STATE_CP_PROCESSING; memcpy(scsw, io_region->scsw_area, sizeof(*scsw)); + scsw->cmd.actl |= SCSW_ACTL_START_PEND; if (scsw->cmd.fctl & SCSW_FCTL_START_FUNC) { orb = (union orb *)io_region->orb_area; diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index f0d71ab77c50..d2f9babb751c 100644 --- a/drivers/s390/cio/vfio_ccw_ops.c +++ b/drivers/s390/cio/vfio_ccw_ops.c @@ -269,8 +269,10 @@ static ssize_t vfio_ccw_mdev_write_io_region(struct vfio_ccw_private *private, } vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_IO_REQ); - if (region->ret_code != 0) + if (region->ret_code != 0) { private->state = VFIO_CCW_STATE_IDLE; + private->scsw.cmd.actl &= ~SCSW_ACTL_START_PEND; + } ret = (region->ret_code != 0) ? region->ret_code : count; out_unlock: From patchwork Wed May 13 14:29:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Farman X-Patchwork-Id: 11546547 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 45512112E for ; Wed, 13 May 2020 14:29:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D0D9E2065C for ; Wed, 13 May 2020 14:29:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388986AbgEMO3n (ORCPT ); Wed, 13 May 2020 10:29:43 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:14230 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388837AbgEMO3n (ORCPT ); Wed, 13 May 2020 10:29:43 -0400 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 04DEAJNC047398; Wed, 13 May 2020 10:29:42 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 31016kx9ww-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 May 2020 10:29:41 -0400 Received: from m0098404.ppops.net (m0098404.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 04DELHDJ106866; Wed, 13 May 2020 10:29:41 -0400 Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 31016kx9w2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 May 2020 10:29:41 -0400 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.0.27/8.16.0.27) with SMTP id 04DEL0Mo015360; Wed, 13 May 2020 14:29:38 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma03ams.nl.ibm.com with ESMTP id 3100ub9rgr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 May 2020 14:29:38 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 04DETaX533685728 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 May 2020 14:29:36 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 06CE1A4053; Wed, 13 May 2020 14:29:36 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E583EA404D; Wed, 13 May 2020 14:29:35 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Wed, 13 May 2020 14:29:35 +0000 (GMT) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 4958) id ABD29E030A; Wed, 13 May 2020 16:29:35 +0200 (CEST) From: Eric Farman To: Cornelia Huck Cc: Jared Rossi , Halil Pasic , linux-s390@vger.kernel.org, kvm@vger.kernel.org, Eric Farman Subject: [RFC PATCH v2 3/4] vfio-ccw: Expand SCSW usage to HALT and CLEAR Date: Wed, 13 May 2020 16:29:33 +0200 Message-Id: <20200513142934.28788-4-farman@linux.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200513142934.28788-1-farman@linux.ibm.com> References: <20200513142934.28788-1-farman@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216,18.0.676 definitions=2020-05-13_06:2020-05-13,2020-05-13 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 phishscore=0 lowpriorityscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 malwarescore=0 adultscore=0 spamscore=0 clxscore=1015 impostorscore=0 cotscore=-2147483648 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005130126 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Expand the Activity Control flags to include HALT/CLEAR PENDING, in the same way as is done for the START PENDING flag. The POPS states that for HALT SUBCHANNEL: > Condition code 2 is set, and no other action is > taken, ... when a halt function or clear function is > already in progress at the subchannel. So take that into account in fsm_do_halt(). CLEAR SUBCHANNEL is the biggest hammer, and always gets to happen, so no corresponding check is added to fsm_do_clear(). But it does reset both START and HALT functions that may be active, which is why it incorporates the resetting of the HALT bit on the interrupt path. FIXME: What happens if a guest hammers a bunch of CSCH in a row? We clear this for the first interrupt; is that fine? Signed-off-by: Eric Farman --- drivers/s390/cio/vfio_ccw_drv.c | 6 ++++++ drivers/s390/cio/vfio_ccw_fsm.c | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c index ee153fa72a0f..55051972325f 100644 --- a/drivers/s390/cio/vfio_ccw_drv.c +++ b/drivers/s390/cio/vfio_ccw_drv.c @@ -101,6 +101,12 @@ static void vfio_ccw_sch_io_todo(struct work_struct *work) if (private->mdev && scsw_is_solicited(&irb->scsw) && is_final) { private->state = VFIO_CCW_STATE_IDLE; private->scsw.cmd.actl &= ~SCSW_ACTL_START_PEND; + if (scsw_fctl(&irb->scsw) & SCSW_FCTL_HALT_FUNC) + private->scsw.cmd.actl &= ~SCSW_ACTL_HALT_PEND; + if (scsw_fctl(&irb->scsw) & SCSW_FCTL_CLEAR_FUNC) { + private->scsw.cmd.actl &= ~SCSW_ACTL_HALT_PEND; + private->scsw.cmd.actl &= ~SCSW_ACTL_CLEAR_PEND; + } } if (private->io_trigger) diff --git a/drivers/s390/cio/vfio_ccw_fsm.c b/drivers/s390/cio/vfio_ccw_fsm.c index 258ce32549f3..d8075a56eb9b 100644 --- a/drivers/s390/cio/vfio_ccw_fsm.c +++ b/drivers/s390/cio/vfio_ccw_fsm.c @@ -86,6 +86,14 @@ static int fsm_do_halt(struct vfio_ccw_private *private) sch = private->sch; + if (scsw_actl(&private->scsw) & (SCSW_ACTL_HALT_PEND | SCSW_ACTL_CLEAR_PEND)) { + VFIO_CCW_MSG_EVENT(2, + "%pUl: actl %x pending\n", + mdev_uuid(private->mdev), + scsw_actl(&private->scsw)); + return -EBUSY; + } + spin_lock_irqsave(sch->lock, flags); VFIO_CCW_TRACE_EVENT(2, "haltIO"); @@ -102,6 +110,7 @@ static int fsm_do_halt(struct vfio_ccw_private *private) * Initialize device status information */ sch->schib.scsw.cmd.actl |= SCSW_ACTL_HALT_PEND; + private->scsw.cmd.actl |= SCSW_ACTL_HALT_PEND; ret = 0; break; case 1: /* Status pending */ @@ -143,6 +152,7 @@ static int fsm_do_clear(struct vfio_ccw_private *private) * Initialize device status information */ sch->schib.scsw.cmd.actl = SCSW_ACTL_CLEAR_PEND; + private->scsw.cmd.actl |= SCSW_ACTL_CLEAR_PEND; /* TODO: check what else we might need to clear */ ret = 0; break; @@ -246,7 +256,7 @@ static void fsm_io_request(struct vfio_ccw_private *private, char *errstr = "request"; struct subchannel_id schid = get_schid(private); - if (scsw_actl(scsw) & SCSW_ACTL_START_PEND) { + if (scsw_actl(scsw) & (SCSW_ACTL_START_PEND | SCSW_ACTL_HALT_PEND | SCSW_ACTL_CLEAR_PEND)) { io_region->ret_code = -EBUSY; VFIO_CCW_MSG_EVENT(2, "%pUl (%x.%x.%04x): actl %x pending\n", From patchwork Wed May 13 14:29:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Farman X-Patchwork-Id: 11546545 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CCC9C60D for ; Wed, 13 May 2020 14:29:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 60F66205ED for ; Wed, 13 May 2020 14:29:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388976AbgEMO3m (ORCPT ); Wed, 13 May 2020 10:29:42 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:42210 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388777AbgEMO3m (ORCPT ); Wed, 13 May 2020 10:29:42 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 04DEAsI9156835; Wed, 13 May 2020 10:29:41 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3101knnxk3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 May 2020 10:29:41 -0400 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 04DEDArk166387; Wed, 13 May 2020 10:29:40 -0400 Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 3101knnxjc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 May 2020 10:29:40 -0400 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.0.27/8.16.0.27) with SMTP id 04DEL1jB015395; Wed, 13 May 2020 14:29:39 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma03ams.nl.ibm.com with ESMTP id 3100ub9rgu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 May 2020 14:29:38 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 04DESPUV59703582 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 May 2020 14:28:25 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 064DAA4064; Wed, 13 May 2020 14:29:36 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F2936A4060; Wed, 13 May 2020 14:29:35 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Wed, 13 May 2020 14:29:35 +0000 (GMT) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 4958) id AE6D6E0338; Wed, 13 May 2020 16:29:35 +0200 (CEST) From: Eric Farman To: Cornelia Huck Cc: Jared Rossi , Halil Pasic , linux-s390@vger.kernel.org, kvm@vger.kernel.org, Eric Farman Subject: [RFC PATCH v2 4/4] vfio-ccw: Clean up how to react to a failed START Date: Wed, 13 May 2020 16:29:34 +0200 Message-Id: <20200513142934.28788-5-farman@linux.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200513142934.28788-1-farman@linux.ibm.com> References: <20200513142934.28788-1-farman@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216,18.0.676 definitions=2020-05-13_06:2020-05-13,2020-05-13 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 impostorscore=0 lowpriorityscore=0 mlxscore=0 bulkscore=0 cotscore=-2147483648 mlxlogscore=999 adultscore=0 clxscore=1015 suspectscore=0 spamscore=0 phishscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005130121 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is a fixup to the previous commits, and should be merged as such. It's just left out to show that vfio-ccw needs to tell the difference between getting a CC2 from a SSCH instruction, and creating a CC2 because there's another (probably asynchronous) command still outstanding. Without it, the FSM state would be reset to IDLE and things would be no better than before. Signed-off-by: Eric Farman --- drivers/s390/cio/vfio_ccw_fsm.c | 6 +++++- drivers/s390/cio/vfio_ccw_ops.c | 5 +---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_fsm.c b/drivers/s390/cio/vfio_ccw_fsm.c index d8075a56eb9b..7d1c7031079c 100644 --- a/drivers/s390/cio/vfio_ccw_fsm.c +++ b/drivers/s390/cio/vfio_ccw_fsm.c @@ -264,7 +264,7 @@ static void fsm_io_request(struct vfio_ccw_private *private, schid.ssid, schid.sch_no, scsw_actl(scsw)); errstr = "pending"; - goto err_out; + goto err_out_nochange; } private->state = VFIO_CCW_STATE_CP_PROCESSING; @@ -340,6 +340,10 @@ static void fsm_io_request(struct vfio_ccw_private *private, } err_out: + private->scsw.cmd.actl &= ~SCSW_ACTL_START_PEND; + private->state = VFIO_CCW_STATE_IDLE; + +err_out_nochange: trace_vfio_ccw_fsm_io_request(scsw->cmd.fctl, schid, io_region->ret_code, errstr); } diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index d2f9babb751c..d01d7abe6b00 100644 --- a/drivers/s390/cio/vfio_ccw_ops.c +++ b/drivers/s390/cio/vfio_ccw_ops.c @@ -269,10 +269,7 @@ static ssize_t vfio_ccw_mdev_write_io_region(struct vfio_ccw_private *private, } vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_IO_REQ); - if (region->ret_code != 0) { - private->state = VFIO_CCW_STATE_IDLE; - private->scsw.cmd.actl &= ~SCSW_ACTL_START_PEND; - } + ret = (region->ret_code != 0) ? region->ret_code : count; out_unlock: