Received: by 10.192.165.148 with SMTP id m20csp435089imm; Wed, 25 Apr 2018 01:51:05 -0700 (PDT) X-Google-Smtp-Source: AIpwx48s5rqmvXI3ZFFelBP79JKF+vxvg0u0A05jHj7OZbQ1T/QOGudaZVcY8nlU3lO3idX/ZZlc X-Received: by 10.99.113.84 with SMTP id b20mr23544937pgn.426.1524646264909; Wed, 25 Apr 2018 01:51:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524646264; cv=none; d=google.com; s=arc-20160816; b=A5y8ZpJO3pPupLEd5MZSlXd01LIctryAwdBno/TVjTV2mQ6g8N+DOQN4ZkIC840nQI LIO61G4YHoKav7iVoLhgrX2UeGRJgiRHN2KVaSiif9CXBBdctw3tr8nqYl0FbhC++cGh tRkA08WimTvHyWMNz6dYUev5tDkkLrkBiUbCNq5IoaeB/98usEf4fekxZM4QxuSQ4mUR ZJCYsNvvKw3wXB83NE6f+L8rcIAuuV35p9EfhWyAp2nnD773592F657U1eUCIy0W/eDC lzcD78tiIY/jE+iWFGQqyj4dCgL4OO5wTKMG/vpnUKWTArpQLq1W9mEv4Pz4AO/BNTMs T4zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:arc-authentication-results; bh=8InX5jU0O5nMLyi8+Rszs2FagZ8msuvLdwmuhRxn51U=; b=wvdtvujZu/FrDvU8zbRXaixbdF9GYroX6GikXKffgo+qlwi/DYK+w4jzmxa+TFUd9h IWgOW9fhU4iQxsATqE8geP5gMQAXQWFB2mD5zJBpH+/+UX7ERyXuT358u6ky+4+/967B wTukLu/3ngnC0wCxYyn6WX7mLrlvDjXAUmbJaWg/LqE/a5dRYiCaCPTGsjccetcqOwNU deywLgYRvUsgdDw9K1sEKwWX1NCCz5cURP+IqbfyJA8zZ4KPVCBFNojuu2aZTQD449kK y8sVAiW7CbyMqhFeUmSpb/xfbGXYgU6oqDb/8OdCLGzz/fznsgIihujtQZAN+j8ighz1 TpTg== 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e71si9491523pfj.250.2018.04.25.01.50.50; Wed, 25 Apr 2018 01:51:04 -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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751428AbeDYIsw (ORCPT + 99 others); Wed, 25 Apr 2018 04:48:52 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55988 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751300AbeDYIsp (ORCPT ); Wed, 25 Apr 2018 04:48:45 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0F988406C743; Wed, 25 Apr 2018 08:48:45 +0000 (UTC) Received: from gondolin (dhcp-192-222.str.redhat.com [10.33.192.222]) by smtp.corp.redhat.com (Postfix) with ESMTP id 14D6915562; Wed, 25 Apr 2018 08:48:43 +0000 (UTC) Date: Wed, 25 Apr 2018 10:48:41 +0200 From: Cornelia Huck 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 Subject: Re: [PATCH 10/10] vfio: ccw: Let user wait when busy on IO Message-ID: <20180425104841.758a314d.cohuck@redhat.com> In-Reply-To: <1524149293-12658-11-git-send-email-pmorel@linux.vnet.ibm.com> References: <1524149293-12658-1-git-send-email-pmorel@linux.vnet.ibm.com> <1524149293-12658-11-git-send-email-pmorel@linux.vnet.ibm.com> Organization: Red Hat GmbH MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 25 Apr 2018 08:48:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 25 Apr 2018 08:48:45 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'cohuck@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 19 Apr 2018 16:48:13 +0200 Pierre Morel wrote: > 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--); I really don't think we want to go there. If we are busy, generate an indication to that respect, but don't retry. My preferred approach would be to keep the "we're busy" times as small as possible and let the host channel subsystem handle any further races. We can't make that bulletproof anyway, so no reason to make life more difficult for us. > + > + 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;