Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp385183rwe; Thu, 1 Sep 2022 00:44:35 -0700 (PDT) X-Google-Smtp-Source: AA6agR59sE7c2v8lqnANDprcSK4ZRxlcWOVoes8SZl6FrXUQup3U+I6eOXvijpCPZeqHLaCXQOHc X-Received: by 2002:a17:903:2410:b0:171:4bbc:2526 with SMTP id e16-20020a170903241000b001714bbc2526mr29417415plo.62.1662018274746; Thu, 01 Sep 2022 00:44:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662018274; cv=none; d=google.com; s=arc-20160816; b=MEP2YWDD6FleVTdcNkzRaIOfHxq6YKrCh3KKrg6MKx/L0BkONA1gIAN46u5Vacm4// 4UIqZItjuT6xlZC8HFYS2Ytpb9I/FYy8/H53nsQRhZ7tJCOAoRPtV2HEQVn/U2wj8YSA Te2XC52R8u4YImzMOylDbRT9uXfKwmnFuLoZdu1562smd6jl1Rp+yyYUjb51IxnW5v86 PdzRLyBX+EiMcBcwgrWkhCMF9WcSEBpVumdpuSJrSjIjVC/rTpzDN3gx0zLGmxV+1frm uJxs5fsHBQHBiFOUuUGt3IRnlFVzXKARuPpO5JhsnFQJFkhFmYST862pRI7L5VxPrQhR mlAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=2m+orUuKk3HoCxVTM7mZrJtjkblhJtMYRmohnd80790=; b=IjDiDy2bsmNk/SMsJk4dR5E7y5gO3tOE7489/JYIltS7qpiPUXm67gMVZT+KUDBINF nwULRA4a/JhgQN6rSDu3R+3IxYY6KSynFzieK3GG3cPpHg/XjAIqllAafPzuGejUJACR chwE4YPktBfAK1oKP3YnzY8vHMwO/sGqY+gRgWNMRUCf1GMQIE0oz5SpbnW7x8D59SVs 0iA90Mp+7DW9TZkDq1oFLfC5RLtBcFJukfYY4uFv+HmZ39km6CE304z5URJAPWvlkG9x U/vpMk2zRY9q/ZUhbjbl9H38O4ukSqLg+jLhkpTGd2MQ2jQpCozU++fctSvd42owWPeE WsNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BDtUxsYB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j14-20020a170902da8e00b00174cd29888bsi11527422plx.235.2022.09.01.00.44.23; Thu, 01 Sep 2022 00:44:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BDtUxsYB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233557AbiIAHRg (ORCPT + 99 others); Thu, 1 Sep 2022 03:17:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232562AbiIAHRf (ORCPT ); Thu, 1 Sep 2022 03:17:35 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63A65124847; Thu, 1 Sep 2022 00:17:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662016654; x=1693552654; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=/oWozjlSYSNeOLAebOKD/bZQo3WvQOnbYJ2YF9ryPU4=; b=BDtUxsYB3+SUBZFugfUuAzh1tm4VThi66OehwHL/D7EyxOYUgVi/n68N 4vyrQGNoKCAYhYV6mX8TngeMyyN/blfHVtRS9P7B5xMGtrut9s5XV82Y3 t8F1IaxXxcDP4VyJbrYTUNXahzJ+EB1M1xWUAbb0hkw6xok6/rm481T+c xHAltlJhdVpOjUjtnqZfRSc9XjZxC8ND/FPWYqvKQKItgyfBHNwWj1W1i Am/9+Fo8Nc7BgN+49qrV1GKYjayvSX9MQ4FcL3lRqqf3kBCqM6/CYuG0O kgDn2gDDInxaA9p1SXcje3Z2z8lA+4FObXvuvm22C+RIP9SfmH5Lt1zKc A==; X-IronPort-AV: E=McAfee;i="6500,9779,10456"; a="294378000" X-IronPort-AV: E=Sophos;i="5.93,280,1654585200"; d="scan'208";a="294378000" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Sep 2022 00:17:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,280,1654585200"; d="scan'208";a="673719782" Received: from sqa-gate.sh.intel.com (HELO michael.clx.dev.tsp.org) ([10.239.48.212]) by fmsmga008.fm.intel.com with ESMTP; 01 Sep 2022 00:17:25 -0700 From: Kevin Tian To: 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 , Alex Williamson , Cornelia Huck , Longfang Liu , Shameer Kolothum , Jason Gunthorpe , Yishai Hadas , Kevin Tian , Eric Auger , Kirti Wankhede , Leon Romanovsky , Abhishek Sahu , 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 Cc: Yi Liu Subject: [PATCH v2 00/15] Tidy up vfio_device life cycle Date: Thu, 1 Sep 2022 22:37:32 +0800 Message-Id: <20220901143747.32858-1-kevin.tian@intel.com> X-Mailer: git-send-email 2.21.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_06_12, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 anyay. Later once the ccw mess is fixed a simple cleanup can be done by moving free from @release to vfio core. v2: - rebase to 6.0-rc3 - fix build warnings (lkp) - patch1: remove unnecessary forward reference (Jason) - patch10: leave device_set released by vfio core (Jason) - patch13: add Suggested-by - patch15: add ABI file sysfs-devices-vfio-dev (Alex) - patch15: rename 'vfio' to 'vfio_group' in procfs (Jason) v1: https://lore.kernel.org/lkml/20220827171037.30297-1-kevin.tian@intel.com/ -- @Alex, before knowing your merging preference this is only rebased to 6.0-rc3. There is no conflict with: - Remove private items from linux/vfio_pci_core.h - Break up ioctl dispatch functions to one function per ioctl But conflict exists with Jason's two series: - Allow MMIO regions to be exported through dma-buf - vfio: Split the container code into a clean layer and dedicated file 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/ Kevin Tian (6): vfio: Add helpers for unifying vfio_device life cycle drm/i915/gvt: Use the new device life cycle helpers vfio/platform: Use the new device life cycle helpers vfio/amba: Use the new device life cycle helpers vfio/ccw: Use the new device life cycle helpers vfio: Rename vfio_device_put() and vfio_device_try_get() Yi Liu (9): vfio/pci: Use the new device life cycle helpers vfio/mlx5: Use the new device life cycle helpers vfio/hisi_acc: Use the new device life cycle helpers vfio/mdpy: Use the new device life cycle helpers vfio/mtty: Use the new device life cycle helpers vfio/mbochs: Use the new device life cycle helpers vfio/ap: Use the new device life cycle helpers vfio/fsl-mc: Use the new device life cycle helpers vfio: Add struct device to vfio_device .../ABI/testing/sysfs-devices-vfio-dev | 8 + drivers/gpu/drm/i915/gvt/gvt.h | 5 +- drivers/gpu/drm/i915/gvt/kvmgt.c | 52 ++++-- drivers/gpu/drm/i915/gvt/vgpu.c | 33 ++-- drivers/s390/cio/vfio_ccw_ops.c | 52 +++++- drivers/s390/cio/vfio_ccw_private.h | 3 + drivers/s390/crypto/vfio_ap_ops.c | 50 +++--- drivers/vfio/fsl-mc/vfio_fsl_mc.c | 85 +++++---- .../vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 80 ++++----- drivers/vfio/pci/mlx5/main.c | 49 +++-- drivers/vfio/pci/vfio_pci.c | 20 +-- drivers/vfio/pci/vfio_pci_core.c | 23 ++- drivers/vfio/platform/vfio_amba.c | 72 ++++++-- drivers/vfio/platform/vfio_platform.c | 66 +++++-- drivers/vfio/platform/vfio_platform_common.c | 71 +++----- drivers/vfio/platform/vfio_platform_private.h | 18 +- drivers/vfio/vfio_main.c | 167 +++++++++++++++--- include/linux/vfio.h | 28 ++- include/linux/vfio_pci_core.h | 6 +- samples/vfio-mdev/mbochs.c | 73 +++++--- samples/vfio-mdev/mdpy.c | 81 +++++---- samples/vfio-mdev/mtty.c | 67 ++++--- 22 files changed, 729 insertions(+), 380 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-devices-vfio-dev base-commit: b90cb1053190353cc30f0fef0ef1f378ccc063c5 -- 2.21.3