Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1201834pxb; Thu, 16 Sep 2021 02:01:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWn6206Q3sSv37Wmx6/o+9tZTftXis5XRTD4Q4TXvnn598kSfvrcGthchPziQVfnrhPSc+ X-Received: by 2002:a5d:9355:: with SMTP id i21mr3611684ioo.12.1631782859909; Thu, 16 Sep 2021 02:00:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631782859; cv=none; d=google.com; s=arc-20160816; b=qDZKDQP020sYhf+31l4FDiEU8PLl6lEBIqTfkoA9R7CM+YPylFWziw+8Hmr+nyj/ZV dXvdt/AVj57yyJ0GmCApVWaKRatdY/relpibg7K8EgTCCHDZpEAWrPqbqDkvHUeT8nay IWetTns0Q1WiEByN+tVpIA4u84/9zJrsr/cU3qciQ7f4kiOF7XmnIuTHD0167Hd6xftf qjOOu/5nZ2t2P/XIDqjrU6OXSL4Td4P3BwSBk4b9hW+6jiFw6hDH/zIU80/OR5z7S4J/ J92kMAJYCU5jCm9+2kpdYe3PGEIdP9+6JWGdNEGy2Gm2Jz6eNfD18/vfnc9fWe7asrVK hZ5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:user-agent :references:organization:in-reply-to:subject:cc:to:from :dkim-signature; bh=t2Z/Tfws0/ZPIkBTJwi6vBLPKuMktwH7w8C6L94eoVM=; b=1GXhhTU1vJit4T3cKSkM8hVax7ckolQPqEZNT1hpXrP4qn26J2961+j2nKLoQ9wHN7 7Jp8NeQWEH5/moBGlGrkISaoSwOOibYfnqBnNxAuZljEcLFlQF/PFFhb/9w9XXBgLHVq +z8M5wcvgAlptJBbNcbg2s3gT/kJHVJh9F3xTvBzyNecFDEXbrHmz+ACLpDcWqvHfj/+ dDnDF5tozGAZq7RNvlwRXMxKenPSN+zk+Ih1AjzV5EqIiqxNB9PvtLAulvwRPGzPT9j8 s2SDFvfOcT2pB3kRtwXx/t7RxZc4p76O6Ao7IVRaevLvSV2AlcJGnBzzCPsoqx2Q+roI Eiug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=G37tWJXZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c39si2032035jaf.12.2021.09.16.02.00.47; Thu, 16 Sep 2021 02:00:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=G37tWJXZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235240AbhIPJAp (ORCPT + 99 others); Thu, 16 Sep 2021 05:00:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:27010 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233839AbhIPJAn (ORCPT ); Thu, 16 Sep 2021 05:00:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631782763; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=t2Z/Tfws0/ZPIkBTJwi6vBLPKuMktwH7w8C6L94eoVM=; b=G37tWJXZgJiTawDu+EWUQkxqQIqtNGr2OS2sboJ68TjLxP1BJ2HCchOBNR1RUpPpyE36Ra QFaEI7NxT9wzJIsXKdl/5Bfc+qjMBk/6JTZ0L6D9jxbVSYzK3SmwaWeAhouOhYyNzYymio sr8our5csTOncndMxOOJ0q5V+Q6PMbU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-54-GlU6ZhEVPs-lOiN55UKk5A-1; Thu, 16 Sep 2021 04:59:19 -0400 X-MC-Unique: GlU6ZhEVPs-lOiN55UKk5A-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 24861100CCC1; Thu, 16 Sep 2021 08:59:18 +0000 (UTC) Received: from localhost (unknown [10.39.192.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B554960FDD; Thu, 16 Sep 2021 08:59:17 +0000 (UTC) From: Cornelia Huck To: Halil Pasic , Halil Pasic , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Pierre Morel , Michael Mueller , linux-s390@vger.kernel.org, virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: bfu@redhat.com, Vineeth Vijayan Subject: Re: [PATCH 1/1] virtio/s390: fix vritio-ccw device teardown In-Reply-To: <20210915215742.1793314-1-pasic@linux.ibm.com> Organization: Red Hat GmbH References: <20210915215742.1793314-1-pasic@linux.ibm.com> User-Agent: Notmuch/0.32.1 (https://notmuchmail.org) Date: Thu, 16 Sep 2021 10:59:15 +0200 Message-ID: <87pmt8hp5o.fsf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 15 2021, Halil Pasic wrote: > Since commit 48720ba56891 ("virtio/s390: use DMA memory for ccw I/O and > classic notifiers") we were supposed to make sure that > virtio_ccw_release_dev() completes before the ccw device, and the > attached dma pool are torn down, but unfortunately we did not. > Before that commit it used to be OK to delay cleaning up the memory > allocated by virtio-ccw indefinitely (which isn't really intuitive for > guys used to destruction happens in reverse construction order). > > To accomplish this let us take a reference on the ccw device before we > allocate the dma_area and give it up after dma_area was freed. > > Signed-off-by: Halil Pasic > Fixes: 48720ba56891 ("virtio/s390: use DMA memory for ccw I/O and > classic notifiers") > Reported-by: bfu@redhat.com > --- > > I'm not certain this is the only hot-unplug and teardonw related problem > with virtio-ccw. > > Some things that are not perfectly clear to me: > * What would happen if we observed an hot-unplug while we are doing > wait_event() in ccw_io_helper()? Do we get stuck? I don't thin we > are guaranteed to receive an irq for a subchannel that is gone. Hm. I think we may need to do a wake_up during remove handling. > * cdev->online seems to be manipulated under cdev->ccwlock, but > in virtio_ccw_remove() we look at it to decide should we clean up > or not. What is the idea there? I guess we want to avoid doing > if nothing is there or twice. But I don't understand how stuff > interlocks. We only created the virtio device when we onlined the ccw device. Do you have a better idea how to check for that? (And yes, I'm not sure the locking is correct.) > * Can virtio_ccw_remove() get called while !cdev->online and > virtio_ccw_online() is running on a different cpu? If yes, what would > happen then? All of the remove/online/... etc. callbacks are invoked via the ccw bus code. We have to trust that it gets it correct :) (Or have the common I/O layer maintainers double-check it.) > > The main addresse of these questions is Conny ;). > > An alternative to this approach would be to inc and dec the refcount > in ccw_device_dma_zalloc() and ccw_device_dma_free() respectively. Yeah, I also thought about that. This would give us more get/put operations, but might be the safer option. > > --- > drivers/s390/virtio/virtio_ccw.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/s390/virtio/virtio_ccw.c b/drivers/s390/virtio/virtio_ccw.c > index d35e7a3f7067..99141df3259b 100644 > --- a/drivers/s390/virtio/virtio_ccw.c > +++ b/drivers/s390/virtio/virtio_ccw.c > @@ -1006,10 +1006,12 @@ static void virtio_ccw_release_dev(struct device *_d) > { > struct virtio_device *dev = dev_to_virtio(_d); > struct virtio_ccw_device *vcdev = to_vc_device(dev); > + struct ccw_device *cdev = READ_ONCE(vcdev->cdev); > > ccw_device_dma_free(vcdev->cdev, vcdev->dma_area, > sizeof(*vcdev->dma_area)); > kfree(vcdev); > + put_device(&cdev->dev); > } > > static int irb_is_error(struct irb *irb) > @@ -1262,6 +1264,7 @@ static int virtio_ccw_online(struct ccw_device *cdev) > struct virtio_ccw_device *vcdev; > unsigned long flags; > > + get_device(&cdev->dev); > vcdev = kzalloc(sizeof(*vcdev), GFP_KERNEL); > if (!vcdev) { > dev_warn(&cdev->dev, "Could not get memory for virtio\n"); > @@ -1315,6 +1318,7 @@ static int virtio_ccw_online(struct ccw_device *cdev) > sizeof(*vcdev->dma_area)); > } > kfree(vcdev); > + put_device(&cdev->dev); > return ret; > } > > > base-commit: 3ca706c189db861b2ca2019a0901b94050ca49d8 > -- > 2.25.1