Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3518216imm; Fri, 25 May 2018 07:06:12 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpXS2qmSEWc990J6ZQl6gnUsGiwdAUqXWAQgaWVLsulu7M9hm8UFxzAqVZCLkpPEnlK/sVK X-Received: by 2002:a65:5b04:: with SMTP id y4-v6mr2190651pgq.238.1527257172227; Fri, 25 May 2018 07:06:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527257172; cv=none; d=google.com; s=arc-20160816; b=gfPs+kkVxWWYlhvOJNdYztGco/7/bUgTAiymOoT3PJnGWva45++uwqU7KIS6JDRJNQ PRtgaEYWi9zk0Q58fjrtz6NnkEWKUKslIEmzoa7pgv00Ys8IQvwYFhXK9JXnFcDptFXN TXPZIYagL251koyC89xlquM0wp4/az4x43uhpBrbb78i7kyG0WE9kPH00AlndGIPOZAl ybg3r9MGqYiu4SSSPgvKhSdMjsMAyu2dBF0YiMJCXGr7Qchuzkun5muwSM3fl6Z2szVD w93tlmNYfVvXKuJcEjeICmd5WeRDJEMyPWHYZhBxfAM6Oik85GDbDqbl1t7WWXjm9C6T 30lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:message-id:in-reply-to:mime-version :references:subject:cc:to:from:date:arc-authentication-results; bh=6eKOa1S8JtOL7weh6WNC9XqQGxIBxY1aQ+gXPCS3rIk=; b=Y6EHEbE5qBm40dv2SZG10+tmCJQg2VI75eXhktsL9a/TlzBuilcAcLjC/uuBo3aijj HrZ+a1P1bEKZLhJhsrwuN7YtdKwNV9poR0b/30cSfuO/gSnR6Gd5k3QLTx4DsgjxGFFS +Ig28WHp7e57tVHJNNiKW9ng8fF3OdySdNNwrhKFSm9E/Q//0DrlbI224kQ72CeCdRw6 4J0q6EMJyimVVGYSt4GqD3sE8qUe8jMuHLTYhlOXBdS1TznV0gUi0GxRnmg+6YDrnoRh VbYS0nBBcf9KU3pVndVcOmYLzRgaHpe4MCLulDqUndgDec4imVPa7/IWN9lhBj41M0zA vu1A== 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 e9-v6si23761260pln.72.2018.05.25.07.05.54; Fri, 25 May 2018 07:06:12 -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 S936184AbeEYOFD (ORCPT + 99 others); Fri, 25 May 2018 10:05:03 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:39784 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935737AbeEYOFB (ORCPT ); Fri, 25 May 2018 10:05:01 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4PE51RG099473 for ; Fri, 25 May 2018 10:05:01 -0400 Received: from e06smtp15.uk.ibm.com (e06smtp15.uk.ibm.com [195.75.94.111]) by mx0a-001b2d01.pphosted.com with ESMTP id 2j6gs08wph-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 25 May 2018 10:04:25 -0400 Received: from localhost by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 25 May 2018 15:04:22 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp15.uk.ibm.com (192.168.101.145) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 25 May 2018 15:04:20 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4PE4K2F5833028; Fri, 25 May 2018 14:04:20 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 22C2B11C052; Fri, 25 May 2018 14:55:23 +0100 (BST) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D440111C050; Fri, 25 May 2018 14:55:22 +0100 (BST) Received: from osiris (unknown [9.152.212.94]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Fri, 25 May 2018 14:55:22 +0100 (BST) Date: Fri, 25 May 2018 16:04:18 +0200 From: Heiko Carstens To: Pierre Morel Cc: pasic@linux.vnet.ibm.com, bjsdjshi@linux.vnet.ibm.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, cohuck@redhat.com Subject: Re: [PATCH v2 10/10] vfio: ccw: Let user wait when busy on IO References: <1527243678-3140-1-git-send-email-pmorel@linux.vnet.ibm.com> <1527243678-3140-11-git-send-email-pmorel@linux.vnet.ibm.com> MIME-Version: 1.0 In-Reply-To: <1527243678-3140-11-git-send-email-pmorel@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18052514-0020-0000-0000-000004213F74 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18052514-0021-0000-0000-000042B6881E Message-Id: <20180525140418.GA17131@osiris> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit Content-Disposition: inline X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-05-25_05:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1805250153 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 25, 2018 at 12:21:18PM +0200, Pierre Morel wrote: > In the current implementation, we do not want to start a new SSCH > command before the last one ends. > > Currently the user needs to poll on the -EBUSY error to > wait before sending a new request. > > Let's be friendly with global warming and let the user sleep > until he may send a new request. > > Let's make the caller wait until the last SSCH ends. > > Signed-off-by: Pierre Morel > --- > drivers/s390/cio/vfio_ccw_fsm.c | 4 ++++ > drivers/s390/cio/vfio_ccw_ops.c | 6 ++++++ > drivers/s390/cio/vfio_ccw_private.h | 1 + > 3 files changed, 11 insertions(+) > > diff --git a/drivers/s390/cio/vfio_ccw_fsm.c b/drivers/s390/cio/vfio_ccw_fsm.c > index c37052d..97b74a1 100644 > --- a/drivers/s390/cio/vfio_ccw_fsm.c > +++ b/drivers/s390/cio/vfio_ccw_fsm.c > @@ -200,6 +200,10 @@ 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 b202e73..39beb6e 100644 > --- a/drivers/s390/cio/vfio_ccw_ops.c > +++ b/drivers/s390/cio/vfio_ccw_ops.c > @@ -183,6 +183,7 @@ static ssize_t vfio_ccw_mdev_write(struct mdev_device *mdev, > struct vfio_ccw_private *private; > struct ccw_io_region *region; > union scsw *scsw; > + DECLARE_COMPLETION_ONSTACK(completion); > > if (*ppos + count > sizeof(*region)) > return -EINVAL; > @@ -196,6 +197,11 @@ static ssize_t vfio_ccw_mdev_write(struct mdev_device *mdev, > scsw = (union scsw *) ®ion->scsw_area; > switch (scsw->cmd.fctl) { > case SCSW_FCTL_START_FUNC: > + if (private->state == VFIO_CCW_STATE_BUSY) { > + private->io_completion = &completion; > + if (wait_for_completion_interruptible(&completion)) > + return -EINTR; > + } What prevents a state change between checking the state and before private->io_completion is set? If that happens you would end with an endless wait. Similarly, you would have memory corruption if the task would be interrupted and if the function would be left, ending up with a stale private->io_completion completion pointer. The complete(private->io_completion) call will then write to a memory location that might already be reused. Just my 0.02 after having a very very short look ;)