Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1194066rwe; Sat, 27 Aug 2022 02:52:25 -0700 (PDT) X-Google-Smtp-Source: AA6agR40BxKYXxOeSFk+Y3GUgbBwo/zjSilAIDBq+iNS3qhPXPxj9qeHgHqJox2dBYU+v0GP9yVH X-Received: by 2002:a05:6402:530c:b0:43b:c6bf:a496 with SMTP id eo12-20020a056402530c00b0043bc6bfa496mr9499495edb.282.1661593945617; Sat, 27 Aug 2022 02:52:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661593945; cv=none; d=google.com; s=arc-20160816; b=qDzqiT2D2oq9MtgmScGvwmymdGiTJWtqvHavXRxoBMsQnXCfAFhlkaai639vvyARus LHpOeaSGvXjcLws7RdL9RT7BkfCPT8EWTXHIhEF7n1LyZQR1jjgZ/d7SE6FNZdQZ9hwC tzgF47yVxjzkJfJxavhF2IpUcLdEECcGjyWjv3Kj2tx5bluN+Di2G3we5aaoO84a7YRq RDuBU7//DlL/SHMB3udZn0ebyGyI2SomgKrD5DYOkZjTc38D85DcumnHnHfsCs91QmNz R62ylRu1lWIwnyECqjGveNmAre+hzwQNyC9Bi3yu8/G4N7I8/RzWWaHK2+x426+4zV4H AMJg== 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=CK/WFsKPW2VweSo2DIxa/Agrdc4ETX1+yR2P4IQcsoM=; b=KFcAe0LrSLCF9YQRJSnb18WdIW2/oiJHj/zXPwn/wu5LL41mEgt0JIkCsyC3z5ZrQD z+DOHIgOoKXX1Yqk1DMycs4gccrIlDmmgIyZF6a1fc909zwN+7wVJu1nB7/HV5qbM8F1 HkxQGkgsnKaKVAtCYVvc3PzMG9CkgScRKV8KpU3t5a3GN5vwCrf8REPIIsw0yFj8SicZ OqVM3PMR7srfF36EIG7+crJZJNUtVm3nVtQoVs037nY2JkMu/6UJI1gxNIDfEuu/pRsH I7EZA5mNafFfBF/N2sn0qu5WOBzLX5vg5alxCLmEFQTf76Ou/3T0tcPc3a7W767IdRaw 73VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BDLoQ8z8; 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 gt17-20020a1709072d9100b0073d7ad9607bsi2827577ejc.551.2022.08.27.02.51.59; Sat, 27 Aug 2022 02:52:25 -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=BDLoQ8z8; 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 S232770AbiH0Jtw (ORCPT + 99 others); Sat, 27 Aug 2022 05:49:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230226AbiH0Jtt (ORCPT ); Sat, 27 Aug 2022 05:49:49 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B4BA282; Sat, 27 Aug 2022 02:49:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661593787; x=1693129787; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=uvIblq34aYIPJlbRVx73G0ZjG5Pc8EFbqlJh/UMzIhQ=; b=BDLoQ8z8xR74yTmC6sfSDyZkdpky0EZrFHA/xyDtzU2ZlPDsO7nsJo58 ymh64BBngCVEJDCfFJwldBLiASD366HEzJnT+Tdfcnkjh1P9iF3fOEq7h KYuu2sNmvT6kBtgnKu83AyyvKnXsXd5uv9hzurGUjhxAd1qZl+fwkkm0C 3GdtOjdW7GuNuTvJSnEUi1evC6CKeG9gXInanUvplJXQbmIufwMMgwRek x4Ell/ecic4HU+PfpjI5GfIuFfVF3wwbELONbl3MLH322f1VjXTTT8aUO Ri4qXZRPZ7FS7ia1k66kNrBLooTYiqFR1tI48SdlwLSQP2QfAVuurLWvK A==; X-IronPort-AV: E=McAfee;i="6500,9779,10451"; a="356365703" X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="356365703" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Aug 2022 02:49:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,267,1654585200"; d="scan'208";a="640353741" Received: from sqa-gate.sh.intel.com (HELO michael.clx.dev.tsp.org) ([10.239.48.212]) by orsmga008.jf.intel.com with ESMTP; 27 Aug 2022 02:49:38 -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 00/15] Tidy up vfio_device life cycle Date: Sun, 28 Aug 2022 01:10:22 +0800 Message-Id: <20220827171037.30297-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/free'ed 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. 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 drivers/gpu/drm/i915/gvt/gvt.h | 5 +- drivers/gpu/drm/i915/gvt/kvmgt.c | 52 ++++-- drivers/gpu/drm/i915/gvt/vgpu.c | 31 ++-- 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 | 87 +++++---- .../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 | 61 +++---- drivers/vfio/platform/vfio_platform_private.h | 18 +- drivers/vfio/vfio_main.c | 165 +++++++++++++++--- include/linux/vfio.h | 29 ++- 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 ++++--- 21 files changed, 724 insertions(+), 366 deletions(-) base-commit: 1c23f9e627a7b412978b4e852793c5e3c3efc555 -- 2.21.3