Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp882078imm; Tue, 5 Jun 2018 06:04:05 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLcpWMym6+yWfGVr//NfOu57qya9XRlmW2+stjgcTFcl94znW70PDIFOVQykXdMyaMwPp+5 X-Received: by 2002:a63:87c8:: with SMTP id i191-v6mr21020129pge.124.1528203845743; Tue, 05 Jun 2018 06:04:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528203845; cv=none; d=google.com; s=arc-20160816; b=XL9nXN7/2otu66o/GtyJhijnmC/6E1U3uQPNejuLGxf0DF/rTLU5fc1spl8qcTY/H2 KHcwWAezVdPU4PbhdKHVA0qN3BdIhp1qiDm5yYZZxt8x73i5Ny29r4txWMIuh8Iipb3x xM3kNPX63bKWpa8Uoak8S7SggIsu3mHdWN7gQEVrt2VnkqpRsL8kCPCr1ziuu5T2o26q NRaX6uJCFVij/klCpDcBVUZRVTU4w3WSBn1Hpc96qoaW1z23QwP1KWDtccMrV6PYYLPk QMfqsDk45yMuLKRmDUx68dxBgyj1oiFDXEanITuaFiv/ZV67abyu5MP2+vtP6Edgsfqk +d9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :from:references:cc:to:subject:reply-to:arc-authentication-results; bh=UstHretesAjY3V82JoNOxMvapdVsF+lNVkU8SK78PyM=; b=T9YAJ2jZH9I/4u6XV1GGlXjdSAHd1OiaZRlY51b/V+OPu/3prj/zFDLqBzkSAqXSgp /zHJ5XEfl/GS/SIVbEW92aRm2T6qeuL4z8giAbdQBsqt7usMOTqgKiPbYVnPZZwsxpmG uxKsH4Y2I26ezpvqFPFj5x/yE0vjW3tDLnpO3LyLBtMsHIYPhLT4TiydeCkB0MVCjwBM YJ3Xm0mfceYxg3eIh/agEcrwc+8MoOwGs7KDfSjyFu2tp0/bso2/XO3f15iTwueUSqOg zMIWs+7u8xzg2cf/HHioEIrYWC6/jIIHVU5Qv3Evzx/A/si49vVsw5hxOCL2fWvmpeQv vA/A== 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 e191-v6si39654955pgc.233.2018.06.05.06.03.51; Tue, 05 Jun 2018 06:04:05 -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 S1751895AbeFENDC (ORCPT + 99 others); Tue, 5 Jun 2018 09:03:02 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:51456 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751667AbeFENDB (ORCPT ); Tue, 5 Jun 2018 09:03:01 -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 w55Cxc6C143321 for ; Tue, 5 Jun 2018 09:03:00 -0400 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0b-001b2d01.pphosted.com with ESMTP id 2jdsfnmhpg-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 05 Jun 2018 09:02:46 -0400 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 5 Jun 2018 14:02:10 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp04.uk.ibm.com (192.168.101.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 5 Jun 2018 14:02:08 +0100 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w55D277r15335434 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 5 Jun 2018 13:02:07 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 75A5B52050; Tue, 5 Jun 2018 12:51:47 +0100 (BST) Received: from [9.152.224.33] (unknown [9.152.224.33]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 1B6F552047; Tue, 5 Jun 2018 12:51:47 +0100 (BST) Reply-To: pmorel@linux.ibm.com Subject: Re: [PATCH v2 10/10] vfio: ccw: Let user wait when busy on IO To: Heiko Carstens , 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 References: <1527243678-3140-1-git-send-email-pmorel@linux.vnet.ibm.com> <1527243678-3140-11-git-send-email-pmorel@linux.vnet.ibm.com> <20180525140418.GA17131@osiris> From: Pierre Morel Date: Tue, 5 Jun 2018 15:02:06 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180525140418.GA17131@osiris> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-TM-AS-GCONF: 00 x-cbid: 18060513-0016-0000-0000-000001D85A98 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18060513-0017-0000-0000-0000322B6097 Message-Id: <05ae3528-d4e9-3f0f-4585-8e209f9d9e22@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-06-05_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 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1805220000 definitions=main-1806050151 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 25/05/2018 16:04, Heiko Carstens wrote: > 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 ;) Right, completely false, I should pay a little more (at least) attention. Thanks to have had a very very short (but sharp)look. Pierre -- Pierre Morel Linux/KVM/QEMU in Böblingen - Germany