From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC3A9ECAAD8 for ; Thu, 22 Sep 2022 17:58:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232206AbiIVR6d (ORCPT ); Thu, 22 Sep 2022 13:58:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232212AbiIVR62 (ORCPT ); Thu, 22 Sep 2022 13:58:28 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F27D310652D for ; Thu, 22 Sep 2022 10:58:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663869504; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=g4NUGUXkPyLpfZsihmjyO9VtgQj5aWbqHvYtbi+s6OQ=; b=QRTp4VGsmIF6wFgOpwcacy5nlVLDFxUsTzcTWMkPL5sHeJ/UsLJvQLeuGES77VMKLt+7Nw ma1oxU0QC3YYBDZWOjchtk3Emo94AsaxjlzRwPKSy93ikI83wsP0bNSa4F67WQ08T/5f8e lDsBnvMst131nUzb/NLhd+JRsy4hZuw= Received: from mail-il1-f200.google.com (mail-il1-f200.google.com [209.85.166.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-588-PiFvazUkMVCJ7nPfkLm3rg-1; Thu, 22 Sep 2022 13:58:23 -0400 X-MC-Unique: PiFvazUkMVCJ7nPfkLm3rg-1 Received: by mail-il1-f200.google.com with SMTP id k12-20020a92c24c000000b002f18edda397so6125683ilo.13 for ; Thu, 22 Sep 2022 10:58:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date; bh=g4NUGUXkPyLpfZsihmjyO9VtgQj5aWbqHvYtbi+s6OQ=; b=QCjX9q4lBVm7y5J8dBD+dXM7kt+BeawOim0NMaDgcmmifNvj6IL5bXOsy9QwGvfTAB 0mIrbYgU2mmmQ5evgcV3WHbDa5pCNwH7arIfSoCNy96Sbj4TlgI70I+SYgOj/Ck56K5V gWnC3h7Bl1yasoXEKqyI3J9NnuuYadFOmWnXFGgn2JH9yI6mCXY2uMLWuGxiFy14sZ/G Th1srXfEjuhBdjHjTw0509XzMY7ra8zBM0McqmK12w0h0cAAvuOlrKMzfP6aOlheeiL+ eWx3JNYHp4orm/MMmC9QL5JY+jDEWm+adQqFoNxAxGhOpDgKDWX4AZnMNai6QLtE5Iri 8B9A== X-Gm-Message-State: ACrzQf0j+PBhZSNZhAeo2FtDpvxAVeZINWjhl1IW91pqwpbYXB1dDcpL eDttEHIqVkGZNu4kn96BHXYT3xquTM6OUmaFaAhkrlMAjIpRHs5MZtvF4lOmfFkmFsumyG05ETe Pyj52grYF8EuYiazXc5vhgQfq X-Received: by 2002:a05:6638:1305:b0:35a:6a4e:9e57 with SMTP id r5-20020a056638130500b0035a6a4e9e57mr2680880jad.126.1663869503057; Thu, 22 Sep 2022 10:58:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM530vCbzgK3QTaLWq3W4wuBNaUAkWaoYeBZZnU7wvG9GWi4I/K5zklV/6TeHh+w/3LQU5zx2g== X-Received: by 2002:a05:6638:1305:b0:35a:6a4e:9e57 with SMTP id r5-20020a056638130500b0035a6a4e9e57mr2680865jad.126.1663869502854; Thu, 22 Sep 2022 10:58:22 -0700 (PDT) Received: from redhat.com ([38.15.36.239]) by smtp.gmail.com with ESMTPSA id p5-20020a056638216500b0035a498d222asm2456730jak.35.2022.09.22.10.58.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Sep 2022 10:58:22 -0700 (PDT) Date: Thu, 22 Sep 2022 11:58:20 -0600 From: Alex Williamson To: Kevin Tian Cc: Zhenyu Wang , Zhi Wang , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Eric Farman , Matthew Rosato , Halil Pasic , Vineeth Vijayan , Peter Oberparleiter , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Tony Krowiak , Jason Herne , Harald Freudenberger , Diana Craciun , Cornelia Huck , Longfang Liu , Shameer Kolothum , Jason Gunthorpe , Yishai Hadas , Eric Auger , Kirti Wankhede , Leon Romanovsky , Abhishek Sahu , Christoph Hellwig , intel-gvt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, kvm@vger.kernel.org, Yi Liu Subject: Re: [PATCH v4 00/15] Tidy up vfio_device life cycle Message-ID: <20220922115820.5ac023ab.alex.williamson@redhat.com> In-Reply-To: <20220921104401.38898-1-kevin.tian@intel.com> References: <20220921104401.38898-1-kevin.tian@intel.com> X-Mailer: Claws Mail 4.1.0 (GTK 3.24.34; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 21 Sep 2022 18:43:46 +0800 Kevin Tian wrote: > The idea is to let vfio core manage the vfio_device life cycle instead > of duplicating the logic cross drivers. Besides cleaner code in driver > side this also allows adding struct device to vfio_device as the first > step toward adding cdev uAPI in the future. Another benefit is that > user can now look at sysfs to decide whether a device is bound to > vfio [1], e.g.: > > /sys/devices/pci0000\:6f/0000\:6f\:01.0/vfio-dev/vfio0 > > Though most drivers can fit the new model naturally: > > - vfio_alloc_device() to allocate and initialize vfio_device > - vfio_put_device() to release vfio_device > - dev_ops->init() for driver private initialization > - dev_ops->release() for driver private cleanup > > vfio-ccw is the only exception due to a life cycle mess that its private > structure mixes both parent and mdev info hence must be alloc/freed > outside of the life cycle of vfio device. > > Per prior discussions this won't be fixed in short term by IBM folks [2]. > > Instead of waiting this series introduces a few tricks to move forward: > > - vfio_init_device() to initialize a pre-allocated device structure; > > - require *EVERY* driver to implement @release and free vfio_device > inside. Then vfio-ccw can use a completion mechanism to delay the > free to css driver; > > The second trick is not a real burden to other drivers because they > all require a @release for private cleanup anyway. Later once the ccw > mess is fixed a simple cleanup can be done by moving free from @release > to vfio core. > > Thanks > Kevin > > [1] https://listman.redhat.com/archives/libvir-list/2022-August/233482.html > [2] https://lore.kernel.org/all/0ee29bd6583f17f0ee4ec0769fa50e8ea6703623.camel@linux.ibm.com/ > > v4: > - fix use-after-free issue in @release of mtty/mbochs and also change > mdpy/ap to free vfio-device as the last thing in @release (Alex) > - revert the rename from 'vfio' to 'vfio_group' in procfs (Alex) Applied to vfio next branch for v6.1. Thanks, Alex