Received: by 10.192.165.156 with SMTP id m28csp805780imm; Thu, 19 Apr 2018 07:52:45 -0700 (PDT) X-Google-Smtp-Source: AIpwx48VZMePxkYUxr3aN8Q0DPruIB0dSGGWUTZu1GfyCPyfTD8ka7CMeHXuAK8RFgROux6yqxKZ X-Received: by 10.99.105.196 with SMTP id e187mr1746118pgc.415.1524149565095; Thu, 19 Apr 2018 07:52:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524149565; cv=none; d=google.com; s=arc-20160816; b=ChdgYMq7RbxLOVq7EUL664TuSClKCUYucXK9ue6qCk+vU3nPgC5X4bezLEv77xp2U8 PvzBuEZykxTILWvfpvgLprTE8F2fLRaTKK30bPv0NA1u9wxY/Akya8Sso6PDdWPKtL4D d4EmAkvq38KWOK3ydMJ+2e0YwYi+5b4f2VtSHhN4nALM+5TY9IL0yDW60PLdDMUv6XMg 95x+fx3ND5dZfOjqoarf1D+dAAPyqR5Y9eMnP4UILfoU1xbakTZ35Lmhp5EtaeeyrJ6P D0drsMMgSuwD3AjlNXmTI0+QwD393vcyhePM+R4hW1nV+weVQECb0pI6+JaKHAVnqpEW BU4g== 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=pTy06Qo4lcTEjC14sOXg4XavV3d9f+/C7YgSfXKxHmQ=; b=JRWQKb7nCNSW5SybIhwOUEM7/9cfs2Q7eOVAc3YxuCZJRNcKlxOkcete5r2m6ApAQX 7EeR9hudV9/MiYifq/SDrhty1DW0dUl/+v21lSXyg5BIt5gw6nqY011TgGLdW8p4C+Gr JnoxkPp5qaMwv9ID/NoKRriZFa6mD/48mLqXgzuhPLI6ywEWXwRG91OxMhYO5gn5jv9I vmX2K/h956gZ3siuxkESro79sRKJCUiD117foE+ZA9CW1Rs0lZUYC9yjf4iob01ldqkS r83zFR+UNVVX6ntMXjKguWlx9KGS0PCC2yMSc6/mCzN5NlVSnh2bIRqwWNnwrDEgbsp1 rdtw== 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 r63-v6si3449310plb.366.2018.04.19.07.52.31; Thu, 19 Apr 2018 07:52:45 -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 S1753776AbeDSOtr (ORCPT + 99 others); Thu, 19 Apr 2018 10:49:47 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:47382 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753725AbeDSOtp (ORCPT ); Thu, 19 Apr 2018 10:49:45 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w3JEncbm056443 for ; Thu, 19 Apr 2018 10:49:44 -0400 Received: from e06smtp15.uk.ibm.com (e06smtp15.uk.ibm.com [195.75.94.111]) by mx0a-001b2d01.pphosted.com with ESMTP id 2hevc6tyxy-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Thu, 19 Apr 2018 10:49:42 -0400 Received: from localhost by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 19 Apr 2018 15:48:29 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp15.uk.ibm.com (192.168.101.145) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 19 Apr 2018 15:48:27 +0100 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w3JEmQtv9437544; Thu, 19 Apr 2018 14:48:26 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0DE1B5203F; Thu, 19 Apr 2018 14:39:13 +0100 (BST) Received: from morel-ThinkPad-W530.boeblingen.de.ibm.com (unknown [9.152.224.146]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id BE2A852043; Thu, 19 Apr 2018 14:39:12 +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 10/10] vfio: ccw: Let user wait when busy on IO Date: Thu, 19 Apr 2018 16:48:13 +0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524149293-12658-1-git-send-email-pmorel@linux.vnet.ibm.com> References: <1524149293-12658-1-git-send-email-pmorel@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18041914-0020-0000-0000-00000413BD3A X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18041914-0021-0000-0000-000042A80A4B Message-Id: <1524149293-12658-11-git-send-email-pmorel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-04-19_05:,, 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-1804190131 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the current implementation, we do not want to start a new SSCH command before the last one ends. Signed-off-by: Pierre Morel --- drivers/s390/cio/vfio_ccw_fsm.c | 3 +++ drivers/s390/cio/vfio_ccw_ops.c | 21 ++++++++++++++++++++- drivers/s390/cio/vfio_ccw_private.h | 4 +++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_fsm.c b/drivers/s390/cio/vfio_ccw_fsm.c index b77b8ad..4140292 100644 --- a/drivers/s390/cio/vfio_ccw_fsm.c +++ b/drivers/s390/cio/vfio_ccw_fsm.c @@ -195,6 +195,9 @@ static int fsm_irq(struct vfio_ccw_private *private) if (private->io_trigger) eventfd_signal(private->io_trigger, 1); + if (private->io_completion) + complete(private->io_completion); + return VFIO_CCW_STATE_IDLE; } diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index f0f4071..346532d 100644 --- a/drivers/s390/cio/vfio_ccw_ops.c +++ b/drivers/s390/cio/vfio_ccw_ops.c @@ -171,6 +171,8 @@ static ssize_t vfio_ccw_mdev_write(struct mdev_device *mdev, struct vfio_ccw_private *private; struct ccw_io_region *region; union scsw *scsw; + int max_retries = 5; + DECLARE_COMPLETION_ONSTACK(completion); if (*ppos + count > sizeof(*region)) return -EINVAL; @@ -185,7 +187,24 @@ static ssize_t vfio_ccw_mdev_write(struct mdev_device *mdev, if ((scsw->cmd.fctl & SCSW_FCTL_START_FUNC) != SCSW_FCTL_START_FUNC) return -EINVAL; - vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_SSCH_REQ); + do { + switch (private->state) { + case VFIO_CCW_STATE_BUSY: + private->io_completion = &completion; + wait_for_completion(&completion); + break; + case VFIO_CCW_STATE_IDLE: + if (!vfio_ccw_fsm_event(private, + VFIO_CCW_EVENT_SSCH_REQ)) + return count; + break; + default: + return -EBUSY; + } + } while (max_retries--); + + if (max_retries <= 0) + return -EBUSY; if (region->ret_code != 0) return region->ret_code; diff --git a/drivers/s390/cio/vfio_ccw_private.h b/drivers/s390/cio/vfio_ccw_private.h index dbef727..7cca078 100644 --- a/drivers/s390/cio/vfio_ccw_private.h +++ b/drivers/s390/cio/vfio_ccw_private.h @@ -39,6 +39,7 @@ struct vfio_ccw_private { struct subchannel *sch; int state; struct completion *completion; + struct completion *io_completion; atomic_t avail; struct mdev_device *mdev; struct notifier_block nb; @@ -93,12 +94,13 @@ enum vfio_ccw_event { typedef int (fsm_func_t)(struct vfio_ccw_private *); extern fsm_func_t *vfio_ccw_jumptable[NR_VFIO_CCW_STATES][NR_VFIO_CCW_EVENTS]; -static inline void vfio_ccw_fsm_event(struct vfio_ccw_private *private, +static inline int vfio_ccw_fsm_event(struct vfio_ccw_private *private, int event) { mutex_lock(&private->state_mutex); private->state = vfio_ccw_jumptable[private->state][event](private); mutex_unlock(&private->state_mutex); + return private->io_region.ret_code; } extern struct workqueue_struct *vfio_ccw_work_q; -- 2.7.4