Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1056338imm; Tue, 5 Jun 2018 08:27:57 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLQZUb/NixM46lEZz9w4tDHdsRmPvXHYpzc0IlmWOzmB86+6NPBFi1OAv1lweq9lC2pa2wx X-Received: by 2002:a17:902:bb0d:: with SMTP id l13-v6mr19722463pls.115.1528212477038; Tue, 05 Jun 2018 08:27:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528212477; cv=none; d=google.com; s=arc-20160816; b=I2aNNm+kTJk1QMA4TJlriJWgdSUHHESbn6RpwmBn9Svvp3qt0jnf1LBlvZH4a8kDW6 axx5X7xWii6uUvm2CgVvvxW4XEqJGVQOQW4XNm9CrnGkft3r/CFUVoIpH6eMjKPhgZWz 0bbBCESGj6SStrZ6PFpgdYP/z8Y0mRkXcXCXC1GvLvYAtxdaHUWVHiFpU7x+pNHcBAYE wClc/HXI/M5lRCWIRPze7W9CdetsXXx3HQdNSJcT+RxRAOpoVZtan9NG6lw3CETGUZG+ Y2yyDxNP3rez6K0VG3opPAub9chvQTqu5G/vFwHPntyOg6Zu5LiliPMGq7SOk19ppZp6 lBcg== 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=HyDqiWGOj8U40P7l5/UWXpVu2J+ETsP9NcB9T1H8xlo=; b=HxV85fZ9tZ0Q8hxgHURajpvJm9kzVYSqhrI6/AR56TouU/aOwrZExKFxWn4WZLy09Y gwqKjP5SkegEBYOd4XDu6Ddg9b5vlZnzeQlzCzWSisfV1dVxaxiv8okHgRnnq8zUaNew Bl7UK+9yfFBfboz1sl5OE8GizD6C49ljdVMNKWVKg1oJNCGbhbzNHn06gauN/Csz8nfH xqOUFDBQTeI+AdIvn96J0z8QFaiK1/TYN+O6EqQCHcHRMe5u4XKMVng8kdlE8qjVDhrd lk3vgGr5AiQBBfKEqlXs6pV0d221xXXtEGUwS2QYD7MOyWdW40D8jGP0qm14/bfjKcdl ysOA== 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 q15-v6si3209288pgr.507.2018.06.05.08.27.42; Tue, 05 Jun 2018 08:27:56 -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 S1751852AbeFEP1N convert rfc822-to-8bit (ORCPT + 99 others); Tue, 5 Jun 2018 11:27:13 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39350 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751637AbeFEP1M (ORCPT ); Tue, 5 Jun 2018 11:27:12 -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 8C568401EF0A; Tue, 5 Jun 2018 15:27:11 +0000 (UTC) Received: from gondolin (dhcp-192-222.str.redhat.com [10.33.192.222]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D8906B411; Tue, 5 Jun 2018 15:27:10 +0000 (UTC) Date: Tue, 5 Jun 2018 17:27:08 +0200 From: Cornelia Huck To: Pierre Morel Cc: Pierre Morel , 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 v2 08/10] vfio: ccw: Handling reset and shutdown with states Message-ID: <20180605172708.24bb7af2.cohuck@redhat.com> In-Reply-To: References: <1527243678-3140-1-git-send-email-pmorel@linux.vnet.ibm.com> <1527243678-3140-9-git-send-email-pmorel@linux.vnet.ibm.com> <20180605141827.6911fc74.cohuck@redhat.com> Organization: Red Hat GmbH MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8BIT 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]); Tue, 05 Jun 2018 15:27:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 05 Jun 2018 15:27:11 +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 Tue, 5 Jun 2018 16:10:52 +0200 Pierre Morel wrote: > On 05/06/2018 14:18, Cornelia Huck wrote: > > On Fri, 25 May 2018 12:21:16 +0200 > > Pierre Morel wrote: > >> +static int fsm_online(struct vfio_ccw_private *private) > >> +{ > >> + struct subchannel *sch = private->sch; > >> + int ret = VFIO_CCW_STATE_IDLE; > >> + > >> + spin_lock_irq(sch->lock); > >> + if (cio_enable_subchannel(sch, (u32)(unsigned long)sch)) > >> + ret = VFIO_CCW_STATE_NOT_OPER; > >> + spin_unlock_irq(sch->lock); > >> + > >> + return ret; > >> +} > >> +static int fsm_offline(struct vfio_ccw_private *private) > >> +{ > >> + struct subchannel *sch = private->sch; > >> + int ret = VFIO_CCW_STATE_STANDBY; > >> + > >> + spin_lock_irq(sch->lock); > >> + if (cio_disable_subchannel(sch)) > >> + ret = VFIO_CCW_STATE_NOT_OPER; > > So, what about a subchannel that is busy? Why should it go to the not > > oper state? > > right, thanks. > > > > > (And you should try to flush pending I/O and then try again in that > > case. Otherwise, you may have a still-enabled subchannel which may > > throw an interrupt.) > > What about letting the guest doing this. > After giving him the right information on what happened of course. Why should the guest know anything about this? Getting the device to a usable state respectively cleaning up is the responsibility of the host code. This processing will happen before the guest gets use of the device or after it has lost use of it already (or it is some internal handling like reset, which the guest should not be made aware of). > > > > >> + spin_unlock_irq(sch->lock); > >> + if (private->completion) > >> + complete(private->completion); > >> + > >> + return ret; > >> +} > >> +static int fsm_quiescing(struct vfio_ccw_private *private) > >> +{ > >> + struct subchannel *sch = private->sch; > >> + int ret = VFIO_CCW_STATE_STANDBY; > >> + int iretry = 255; > >> + > >> + spin_lock_irq(sch->lock); > >> + ret = cio_cancel_halt_clear(sch, &iretry); > >> + if (ret == -EBUSY) > >> + ret = VFIO_CCW_STATE_QUIESCING; > >> + else if (private->completion) > >> + complete(private->completion); > >> + spin_unlock_irq(sch->lock); > >> + return ret; > > If I read this correctly, you're calling cio_cancel_halt_clear() only > > once. What happened to the retry loop? > > Same as above, what about letting the guest doing this? See my reply above. > And there are already 255 retries as part of the interface to cio. From the kerneldoc comment for cio_cancel_halt_clear(): * This should be called repeatedly since halt/clear are asynchronous * operations. We do one try with cio_cancel, three tries with cio_halt, * 255 tries with cio_clear. The caller should initialize @iretry with * the value 255 for its first call to this, and keep using the same * @iretry in the subsequent calls until it gets a non -EBUSY return. > > > > >> +} > >> +static int fsm_quiescing_done(struct vfio_ccw_private *private) > >> +{ > >> + if (private->completion) > >> + complete(private->completion); > >> + return VFIO_CCW_STATE_STANDBY; > >> +} > >> /* > >> * No operation action. > >> */ > >> @@ -178,15 +225,10 @@ static int fsm_sch_event(struct vfio_ccw_private *private) > >> static int fsm_init(struct vfio_ccw_private *private) > >> { > >> struct subchannel *sch = private->sch; > >> - int ret = VFIO_CCW_STATE_STANDBY; > >> > >> - spin_lock_irq(sch->lock); > >> sch->isc = VFIO_CCW_ISC; > >> - if (cio_enable_subchannel(sch, (u32)(unsigned long)sch)) > >> - ret = VFIO_CCW_STATE_NOT_OPER; > >> - spin_unlock_irq(sch->lock); > >> > >> - return ret; > >> + return VFIO_CCW_STATE_STANDBY; > > Doesn't that change the semantic of the standby state? > > It changes the FSM: NOT_OPER and STANDBY are clearly different. > Part of the initialization is now done in when putting the device online. Hm, I think the changes to the fsm semantics are a bit mixed up between patches. I'll wait for an outline of how this is supposed to look in the end before commenting further :) > > Your idea here seems to be to go to either disabling the subchannel > > directly or flushing out I/O first, depending on the state you're in. > > The problem is that you may need retries in any case (the subchannel > > may be status pending if it is enabled; not necessarily by any I/O that > > had been started, but also from an unsolicited notification.) > > I wanted to let the guest do the retries as he wants to. > Somehow we must give the right response back to the guest > and take care of the error number we give back. As described above, we need to be clear on what should be guest-visible and what is just internal handling e.g. during initialization/removal. > > I will get a better look at this. > > > > >> }; > >> diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c > >> index ea8fd64..b202e73 100644 > >> --- a/drivers/s390/cio/vfio_ccw_ops.c > >> +++ b/drivers/s390/cio/vfio_ccw_ops.c > >> @@ -21,21 +21,14 @@ static int vfio_ccw_mdev_reset(struct mdev_device *mdev) > >> > >> private = dev_get_drvdata(mdev_parent_dev(mdev)); > >> sch = private->sch; > >> - /* > >> - * TODO: > >> - * In the cureent stage, some things like "no I/O running" and "no > >> - * interrupt pending" are clear, but we are not sure what other state > >> - * we need to care about. > >> - * There are still a lot more instructions need to be handled. We > >> - * should come back here later. > >> - */ > > This is still true, no? I'm thinking about things like channel monitors > > and the like (even if we don't support them yet). > > I think that this is not the place to put this remark since here > we should send an event to the FSM, having new states > will be handled as FSM states. > I put it back, here or where I think it belong if I find another > place after resolving the RESET problem. The comment basically refers to "we aren't quite sure whether there is more stuff we need to reset", so I think this is indeed the correct place.