From patchwork Tue Apr 12 15:53:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12810920 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A1E0DC4332F for ; Tue, 12 Apr 2022 15:53:53 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1466F10E629; Tue, 12 Apr 2022 15:53:43 +0000 (UTC) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2057.outbound.protection.outlook.com [40.107.93.57]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3EECF10E589; Tue, 12 Apr 2022 15:53:40 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cbek2IcKC92bgHPPGT1K85QmEC+hit+cQOlIOS5GHVgZV8wtnarlO0tQw4PYeD8mx7o7gAGNG3Jzrv1PEt4hrs/5Z4Y7zMe1RIAC25ODYuE0H+8cXnRJjCx/bojjYPLbvAl7eSUGUeVikScJnp5gIhwkJRCSJd4GnMorcqG/HIMXx+ID1728FJEIeO8Fgcavszf8z6me/gSgUpgG3yL6ufmV3I6CrF6vg3aJLivK/7HiaTz5LL2jJmtdMsl6tqHK93R6bMXGsmVavNL2iYJQnNYiZDeDR6SfScF77Ysa6gpBJEI2QjfhpC2KLUdUV3ioMUFaytyScyuqIEprqb7r/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=8PEjkobyvXuYb5cQFa0iZCp/D8cFwN6cS9HgIe1OHag=; b=QmdhhSLUuxNyIhrwxHTn4ooHortMWEDGdiEJUMYWvkSYYHOVjYr2VURgi90xakI8W5F3znrIlTOO+PJCHyhRy34Xni2FV0mrzOqnSfpI3+cpAEL0McgnDOAP+ESCTuwroqSXbZ2RVfJ42eEuBvjYrAVS+xKWuwFB+yFEAoPv3jEctWH+IO6Pw/rJgctOvbYizUIGjoiOgCVeYhLC2dat1TJ4cYMZa1A2O6Mc2CbV/7v9zhEWX7BS+DJFXLZ5GCoYl7089EOHLURJWqc0MvLX5CSBhY85VKgTd8L7GgPlQhY81fmHBp8alycFXdWpOrnuQdL8OVpKU23Vk6GrlVHBRg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8PEjkobyvXuYb5cQFa0iZCp/D8cFwN6cS9HgIe1OHag=; b=Llil5kvOB9qgkz15zOWe0LqXdsDWCMx1SHW3+YtPDWZuQfnFpnZ6DxIusqtxyv3MWWToMSANWSzWBukgAOjCCJKlVv0cSblbBFypXDh/YYXJPl9khRTGppkQC6/vZZOJbecLQzVQvo8udUP3pcdUfvU715o5eCvf3X3ujCgPD6zGCdp8SlhZcRv+IIv2JgibPLp9UMCqkHo/Wo/lOAyXhMf0lbkuVImluskXuul6PQ0YOwJXlb2XpoSEHdXd6o5WSoeDCAb5QCa4oST6jvb0XlzQ5wuLz9e1oV+T0/uTq/hJulz6Q9L+osd/mIYtROX7LK1VhbtlcO/CIpio//F/XQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) by DM6PR12MB4172.namprd12.prod.outlook.com (2603:10b6:5:212::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Tue, 12 Apr 2022 15:53:39 +0000 Received: from CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c911:71b5:78e6:3a38]) by CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c911:71b5:78e6:3a38%8]) with mapi id 15.20.5144.029; Tue, 12 Apr 2022 15:53:38 +0000 From: Jason Gunthorpe To: Alexander Gordeev , David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , Daniel Vetter , dri-devel@lists.freedesktop.org, Eric Farman , Harald Freudenberger , Vasily Gorbik , Heiko Carstens , intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, Jani Nikula , Jason Herne , Joonas Lahtinen , kvm@vger.kernel.org, Kirti Wankhede , linux-doc@vger.kernel.org, linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Sven Schnelle , Tvrtko Ursulin , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Date: Tue, 12 Apr 2022 12:53:28 -0300 Message-Id: <1-v1-a8faf768d202+125dd-vfio_mdev_no_group_jgg@nvidia.com> In-Reply-To: <0-v1-a8faf768d202+125dd-vfio_mdev_no_group_jgg@nvidia.com> References: X-ClientProxiedBy: BLAPR03CA0133.namprd03.prod.outlook.com (2603:10b6:208:32e::18) To CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4e17776c-9202-4099-a647-08da1c9c9b61 X-MS-TrafficTypeDiagnostic: DM6PR12MB4172:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KZfJdqvTXbkw9AXuuoEVmMSVqfwjtavftzCljQALOsb9UpfsW+/mqfKSYpt1NH7zmwAsibHdRmxvPKxHcbVyG1oEPkoQ6BwOBTPV0Pgwt//NltzZepERBPNbrzuHfxdxd5LB4tiU7qZk2MtSFkaq6Y6H/jaLx1T3y5Ov3kAFdsR3zpsCE72kzgYhG2DdaxEnc3C2lHtN+EHKn3eUkWzu+phprT/QGaUvxNxCBcw+KWGU1N/AIPnwWfMhEaX7USUkkCJrxOHstjgQlXpf4Hn3ZTnjYsV6sDKkBQV0LYJ2uR6By2+xsLK1W5VYMij5X7WX4ckgF/vvJzV+hQWMscaWSpu1gOmOztIXVBUB7K3nDdHmGZqDf1I4bWQpcteQ2eLWB8PazW/1I0Y93tWK5LwiO9M/Gr0pJhqlkgBq+3hgs5uIZHCp25SSCfbY3aCesW1FeJXwvx0V/ZRhW2TyHBB1H14AnY9+QJyHnFgfubsrlCbwpY8a+TLx8k4Y8sqNoHiZvi/J+5Iba1ljcVEab15AIIwW8iP4jKJzrCk5/xIZvky+J1y6usLW9opdyK5KfQUd//ljNe1G7mnMgBobe0Rosddn8r++BP7hXT2K+NYFi011SclQfDjswTJYz/YgG1Ijcu6kneEoi4VpUBSuXZtdDVY/GkOsXcqpEfYbCw0pkMtUbg1K2vpwnzIsjmvl0oBDVS5MLB9h6GLv9ibXX13/rA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR12MB4181.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(508600001)(6486002)(6506007)(6666004)(66946007)(66476007)(4326008)(66556008)(26005)(186003)(36756003)(83380400001)(8676002)(316002)(54906003)(86362001)(8936002)(6512007)(2616005)(921005)(110136005)(7416002)(5660300002)(38100700002)(2906002)(7406005)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: j2eGSonroG5dDVB1IFHBlyl2Lni7Unzf2e6OUB4SMdSmMWNBZVq7d0FMNo6R2YOyAANTHKOcHejA/SEZIejF4EbSBtr5WpMPPGH1nU0Avu72C4C8OLMPmXZ7pQK0e0e3ap3pkCWV+e3JJr+NGGDTVdd5r2tbb02R9VUMOWRSTXtAUPYODwlprw/lXuqUi86yTkQwbEbRo8iuKL2Jgbrg/9hEFX/kajouL2E0j49+56owiCjoaBsci/O2rmbR/JwU4RZQGTeHpi7TZn1JrAIujUlvgV5vB/0gjY3MHz80sAig9SdcNmURauKPDBotLT6Z/1uQLBPAkzjOU+evpTof2RPXlcRmhnjpulVS1CUpEC7VW0paqkasgdPrrq3pS8QEGW1wAM0eOh06ZxNIgnJYDB0fuaGPkXa4fGYXatGXx/DSmAVUgEVjDiU6psQSmPVY4DA3ftvT9TmOYqMtAcO+el9TDUfb3OxSyd+gzdTHSAZzXaxnG900UJdIXXhJ3tvBagXJ9e7d3LlivpOYIsJkCmkNpZa5nS4QOB0E0Jvci+bvASMOxPEJOAOT/qhQN3YEWqDCS8SjzIICVm3my4ap4X/iOb3IKuqg8UCcqTcDsfw7NcZPtoL5aOL32R1Pz95YaIu6YB8VCaAL3IyxhvGEA8IG8IYfRszPHnhkOR0UKr5D+V5pUcYBi9MVKZXl5fb5UdgvSrJ1Mut0987wa8JRqrc1khIJtKMaKS6GzLFLwMcUTwFKNgVpsmd66atpsN6YdGRqb/X/rYACnmywdSzGNB9gzsy/aMdNMEzHYhDRd/2iUXOs/pfa0cj+p6u6BeoXVx7WxSnocUjHTJEpICpKVlOiEpA49bGVgS6t+ZpAh3vHjawBF5bDKoDBluTHSSFEzG+LizbwYcJH6WonOK+SefmStzTSwTRe89qhApsN7H7pWhe38TYfmG+KCnOBkOuHl+G5+aN3xpEmzcGpVgz275iUrpQopC5HFQSURqzGF7Ev6iaxfzZ9Uqov8P81OJcvT1RpEx5kFmYjIFU9hXa/kFOuTgH98z0Gyfxloh+6QcBW1MzuK4qlt4SkCR30/upqPPMPbmi/G5R4LBbXkxKS6Bw9PJ5uZRTH37ONEjITyxieF0StUm8RS8psSGf7Ggka+mK3ZUxN7CoRLWn3pAhQagRZPxadbiMQ8gjMPWzE+7yvqG5ix9+XAHAAt3eXO/SjRiNlYzcDl8IIN8FqyxVY1CJkwObpnYs3nOYsVZu3YVYg5U5KFuuO75x94iLxmILDQM0QPKGrqvtxr+DFLTBocoJEaRgoCHLroMGGNfOwgDXHY9IIWqdJbSDDbtcCqoJcnw1vsRV+8HOnMIJ4GbWJLwKVYmcGC+lZ0gnlLzGJIE9e0eszwsy1PjwH4ELfCYwtHDZFjh/I7kpV0kFpDK9KXsvjPo8qpiaeyrIeGMdRoKwVvrdNKD0YlI3r/rPp6vzfAPDr1LjT7SgPDF+6Z/NA0YVpmCphSgCbkpYedDk4C8BBQzTX7s/XkG/uTnsDSJBDBPnTyWJQ+2ERXT68OLxaDrmq/KmA9EyAL7KdexZg2aKH2TOSrrvtDOB/JyM0cZ9asjNwao+L3zjcrz3VGTOmmC0mSiIEz124d4k/l3tPNDOTUqzZ4XbaVuagMIS6xzuWucz4OpMEzkZZT76ZYwKEU7yok9Yntggi0kbH2xL2WhIRLxuxS99cRyYBhXrvASzybZj+yKBRcDjogNqmg3r1Cg== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4e17776c-9202-4099-a647-08da1c9c9b61 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4181.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2022 15:53:37.6034 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: RC5x9C5aeJ4EIRC6TeRU8X9NHFtoOw1Mwrr1VixJuhbDT3GvWV1T9VqkU2fCmf/F X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4172 Subject: [Intel-gfx] [PATCH 1/9] vfio: Make vfio_(un)register_notifier accept a vfio_device X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Liu, Yi L" , Christoph Hellwig Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" All callers have a struct vfio_device trivially available, pass it in directly and avoid calling the expensive vfio_group_get_from_dev(). To support the unconverted kvmgt mdev driver add mdev_legacy_get_vfio_device() which will return the vfio_device pointer vfio_mdev.c puts in the drv_data. Signed-off-by: Jason Gunthorpe Acked-by: Eric Farman Reviewed-by: Jason J. Herne Reviewed-by: Tony Krowiak --- drivers/gpu/drm/i915/gvt/kvmgt.c | 15 +++++++++------ drivers/s390/cio/vfio_ccw_ops.c | 7 +++---- drivers/s390/crypto/vfio_ap_ops.c | 14 +++++++------- drivers/vfio/mdev/vfio_mdev.c | 12 ++++++++++++ drivers/vfio/vfio.c | 25 +++++++------------------ include/linux/mdev.h | 1 + include/linux/vfio.h | 4 ++-- 7 files changed, 41 insertions(+), 37 deletions(-) diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c index 057ec449010458..bb59d21cf898ab 100644 --- a/drivers/gpu/drm/i915/gvt/kvmgt.c +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c @@ -904,6 +904,7 @@ static int intel_vgpu_group_notifier(struct notifier_block *nb, static int intel_vgpu_open_device(struct mdev_device *mdev) { + struct vfio_device *vfio_dev = mdev_legacy_get_vfio_device(mdev); struct intel_vgpu *vgpu = mdev_get_drvdata(mdev); struct kvmgt_vdev *vdev = kvmgt_vdev(vgpu); unsigned long events; @@ -914,7 +915,7 @@ static int intel_vgpu_open_device(struct mdev_device *mdev) vdev->group_notifier.notifier_call = intel_vgpu_group_notifier; events = VFIO_IOMMU_NOTIFY_DMA_UNMAP; - ret = vfio_register_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY, &events, + ret = vfio_register_notifier(vfio_dev, VFIO_IOMMU_NOTIFY, &events, &vdev->iommu_notifier); if (ret != 0) { gvt_vgpu_err("vfio_register_notifier for iommu failed: %d\n", @@ -923,7 +924,7 @@ static int intel_vgpu_open_device(struct mdev_device *mdev) } events = VFIO_GROUP_NOTIFY_SET_KVM; - ret = vfio_register_notifier(mdev_dev(mdev), VFIO_GROUP_NOTIFY, &events, + ret = vfio_register_notifier(vfio_dev, VFIO_GROUP_NOTIFY, &events, &vdev->group_notifier); if (ret != 0) { gvt_vgpu_err("vfio_register_notifier for group failed: %d\n", @@ -961,11 +962,11 @@ static int intel_vgpu_open_device(struct mdev_device *mdev) vdev->vfio_group = NULL; undo_register: - vfio_unregister_notifier(mdev_dev(mdev), VFIO_GROUP_NOTIFY, + vfio_unregister_notifier(vfio_dev, VFIO_GROUP_NOTIFY, &vdev->group_notifier); undo_iommu: - vfio_unregister_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY, + vfio_unregister_notifier(vfio_dev, VFIO_IOMMU_NOTIFY, &vdev->iommu_notifier); out: return ret; @@ -988,6 +989,7 @@ static void __intel_vgpu_release(struct intel_vgpu *vgpu) struct kvmgt_vdev *vdev = kvmgt_vdev(vgpu); struct drm_i915_private *i915 = vgpu->gvt->gt->i915; struct kvmgt_guest_info *info; + struct vfio_device *vfio_dev; int ret; if (!handle_valid(vgpu->handle)) @@ -998,12 +1000,13 @@ static void __intel_vgpu_release(struct intel_vgpu *vgpu) intel_gvt_ops->vgpu_release(vgpu); - ret = vfio_unregister_notifier(mdev_dev(vdev->mdev), VFIO_IOMMU_NOTIFY, + vfio_dev = mdev_legacy_get_vfio_device(vdev->mdev); + ret = vfio_unregister_notifier(vfio_dev, VFIO_IOMMU_NOTIFY, &vdev->iommu_notifier); drm_WARN(&i915->drm, ret, "vfio_unregister_notifier for iommu failed: %d\n", ret); - ret = vfio_unregister_notifier(mdev_dev(vdev->mdev), VFIO_GROUP_NOTIFY, + ret = vfio_unregister_notifier(vfio_dev, VFIO_GROUP_NOTIFY, &vdev->group_notifier); drm_WARN(&i915->drm, ret, "vfio_unregister_notifier for group failed: %d\n", ret); diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index d8589afac272f1..e1ce24d8fb2555 100644 --- a/drivers/s390/cio/vfio_ccw_ops.c +++ b/drivers/s390/cio/vfio_ccw_ops.c @@ -183,7 +183,7 @@ static int vfio_ccw_mdev_open_device(struct vfio_device *vdev) private->nb.notifier_call = vfio_ccw_mdev_notifier; - ret = vfio_register_notifier(vdev->dev, VFIO_IOMMU_NOTIFY, + ret = vfio_register_notifier(vdev, VFIO_IOMMU_NOTIFY, &events, &private->nb); if (ret) return ret; @@ -204,8 +204,7 @@ static int vfio_ccw_mdev_open_device(struct vfio_device *vdev) out_unregister: vfio_ccw_unregister_dev_regions(private); - vfio_unregister_notifier(vdev->dev, VFIO_IOMMU_NOTIFY, - &private->nb); + vfio_unregister_notifier(vdev, VFIO_IOMMU_NOTIFY, &private->nb); return ret; } @@ -223,7 +222,7 @@ static void vfio_ccw_mdev_close_device(struct vfio_device *vdev) cp_free(&private->cp); vfio_ccw_unregister_dev_regions(private); - vfio_unregister_notifier(vdev->dev, VFIO_IOMMU_NOTIFY, &private->nb); + vfio_unregister_notifier(vdev, VFIO_IOMMU_NOTIFY, &private->nb); } static ssize_t vfio_ccw_mdev_read_io_region(struct vfio_ccw_private *private, diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c index 6e08d04b605d6e..69768061cd7bd9 100644 --- a/drivers/s390/crypto/vfio_ap_ops.c +++ b/drivers/s390/crypto/vfio_ap_ops.c @@ -1406,21 +1406,21 @@ static int vfio_ap_mdev_open_device(struct vfio_device *vdev) matrix_mdev->group_notifier.notifier_call = vfio_ap_mdev_group_notifier; events = VFIO_GROUP_NOTIFY_SET_KVM; - ret = vfio_register_notifier(vdev->dev, VFIO_GROUP_NOTIFY, - &events, &matrix_mdev->group_notifier); + ret = vfio_register_notifier(vdev, VFIO_GROUP_NOTIFY, &events, + &matrix_mdev->group_notifier); if (ret) return ret; matrix_mdev->iommu_notifier.notifier_call = vfio_ap_mdev_iommu_notifier; events = VFIO_IOMMU_NOTIFY_DMA_UNMAP; - ret = vfio_register_notifier(vdev->dev, VFIO_IOMMU_NOTIFY, - &events, &matrix_mdev->iommu_notifier); + ret = vfio_register_notifier(vdev, VFIO_IOMMU_NOTIFY, &events, + &matrix_mdev->iommu_notifier); if (ret) goto out_unregister_group; return 0; out_unregister_group: - vfio_unregister_notifier(vdev->dev, VFIO_GROUP_NOTIFY, + vfio_unregister_notifier(vdev, VFIO_GROUP_NOTIFY, &matrix_mdev->group_notifier); return ret; } @@ -1430,9 +1430,9 @@ static void vfio_ap_mdev_close_device(struct vfio_device *vdev) struct ap_matrix_mdev *matrix_mdev = container_of(vdev, struct ap_matrix_mdev, vdev); - vfio_unregister_notifier(vdev->dev, VFIO_IOMMU_NOTIFY, + vfio_unregister_notifier(vdev, VFIO_IOMMU_NOTIFY, &matrix_mdev->iommu_notifier); - vfio_unregister_notifier(vdev->dev, VFIO_GROUP_NOTIFY, + vfio_unregister_notifier(vdev, VFIO_GROUP_NOTIFY, &matrix_mdev->group_notifier); vfio_ap_mdev_unset_kvm(matrix_mdev); } diff --git a/drivers/vfio/mdev/vfio_mdev.c b/drivers/vfio/mdev/vfio_mdev.c index a90e24b0c851d3..91605c1e8c8f94 100644 --- a/drivers/vfio/mdev/vfio_mdev.c +++ b/drivers/vfio/mdev/vfio_mdev.c @@ -17,6 +17,18 @@ #include "mdev_private.h" +/* + * Return the struct vfio_device for the mdev when using the legacy + * vfio_mdev_dev_ops path. No new callers to this function should be added. + */ +struct vfio_device *mdev_legacy_get_vfio_device(struct mdev_device *mdev) +{ + if (WARN_ON(mdev->dev.driver != &vfio_mdev_driver.driver)) + return NULL; + return dev_get_drvdata(&mdev->dev); +} +EXPORT_SYMBOL_GPL(mdev_legacy_get_vfio_device); + static int vfio_mdev_open_device(struct vfio_device *core_vdev) { struct mdev_device *mdev = to_mdev_device(core_vdev->dev); diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index a4555014bd1e72..8a5c46aa2bef61 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -2484,19 +2484,15 @@ static int vfio_unregister_group_notifier(struct vfio_group *group, return ret; } -int vfio_register_notifier(struct device *dev, enum vfio_notify_type type, +int vfio_register_notifier(struct vfio_device *dev, enum vfio_notify_type type, unsigned long *events, struct notifier_block *nb) { - struct vfio_group *group; + struct vfio_group *group = dev->group; int ret; - if (!dev || !nb || !events || (*events == 0)) + if (!nb || !events || (*events == 0)) return -EINVAL; - group = vfio_group_get_from_dev(dev); - if (!group) - return -ENODEV; - switch (type) { case VFIO_IOMMU_NOTIFY: ret = vfio_register_iommu_notifier(group, events, nb); @@ -2507,25 +2503,20 @@ int vfio_register_notifier(struct device *dev, enum vfio_notify_type type, default: ret = -EINVAL; } - - vfio_group_put(group); return ret; } EXPORT_SYMBOL(vfio_register_notifier); -int vfio_unregister_notifier(struct device *dev, enum vfio_notify_type type, +int vfio_unregister_notifier(struct vfio_device *dev, + enum vfio_notify_type type, struct notifier_block *nb) { - struct vfio_group *group; + struct vfio_group *group = dev->group; int ret; - if (!dev || !nb) + if (!nb) return -EINVAL; - group = vfio_group_get_from_dev(dev); - if (!group) - return -ENODEV; - switch (type) { case VFIO_IOMMU_NOTIFY: ret = vfio_unregister_iommu_notifier(group, nb); @@ -2536,8 +2527,6 @@ int vfio_unregister_notifier(struct device *dev, enum vfio_notify_type type, default: ret = -EINVAL; } - - vfio_group_put(group); return ret; } EXPORT_SYMBOL(vfio_unregister_notifier); diff --git a/include/linux/mdev.h b/include/linux/mdev.h index 15d03f6532d073..67d07220a28f29 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -29,6 +29,7 @@ static inline struct mdev_device *to_mdev_device(struct device *dev) unsigned int mdev_get_type_group_id(struct mdev_device *mdev); unsigned int mtype_get_type_group_id(struct mdev_type *mtype); struct device *mtype_get_parent_dev(struct mdev_type *mtype); +struct vfio_device *mdev_legacy_get_vfio_device(struct mdev_device *mdev); /** * struct mdev_parent_ops - Structure to be registered for each parent device to diff --git a/include/linux/vfio.h b/include/linux/vfio.h index 66dda06ec42d1b..748ec0e0293aea 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -178,11 +178,11 @@ enum vfio_notify_type { /* events for VFIO_GROUP_NOTIFY */ #define VFIO_GROUP_NOTIFY_SET_KVM BIT(0) -extern int vfio_register_notifier(struct device *dev, +extern int vfio_register_notifier(struct vfio_device *dev, enum vfio_notify_type type, unsigned long *required_events, struct notifier_block *nb); -extern int vfio_unregister_notifier(struct device *dev, +extern int vfio_unregister_notifier(struct vfio_device *dev, enum vfio_notify_type type, struct notifier_block *nb); From patchwork Tue Apr 12 15:53:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12810921 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 17BB3C43217 for ; Tue, 12 Apr 2022 15:53:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 38BDF10E6CA; Tue, 12 Apr 2022 15:53:43 +0000 (UTC) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2058.outbound.protection.outlook.com [40.107.93.58]) by gabe.freedesktop.org (Postfix) with ESMTPS id F05A710E629; Tue, 12 Apr 2022 15:53:41 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R14vHWLBd/ZVMlIZwv5GbPRCGwq95frVyo/GdYMD8XMI405X9LoLzRRwY7uxyIJaNYeWhlU+IRWwiCNNk8XNB3mXpIYoE3srM92K/4twPgFs0Ce1satvkfR/d3p8m0CO6lPoJ1z39J8U+9ulPU7i8gQ3RrpIC0RrlwwsavKNf4Om0NtZotWO6dwg7tIrE2iO7Z0qhIde0gnK6buh4+qGTYOGSGxlgH3S6lUWj+Q4V43suQJ5N7zKbfWx5HP+fsOAzgIgPOdPr3Sj5p0WvMe30RXbkaeR76eVJrSjHpWjdfiOf+yFg2tjG13CxsVKI9tvUJezaQ3yod9zQTd+69YcEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=HjvmS5gymLmSXA2dZfrbGEmaqLx3V3n3q8Gv1W9bqcY=; b=IGIQAnB8GWENSJsW8TE1Q353BINlnspQLAGj4vEIMklAMX7b8ZWuUS+2zMJdKuap+wV+Q1a6Fye2W8SQZa1xyRo1o0ONZZs2HFavStKjK/pgvpZW7brLkqfnD5dXBDW3l+/eOS5aK0NQX90x9XSyUxYeH9o2oNV+tsju4UX4byPMxsRPZCQpRtDbOf6To3wI23hn63J7QiuzgWDH67vuarM7+zyj+hS0CCc3WH6UrZxMzaZnCvQVJN2dSoq4yBhL7ZA+fB42uW+Ri4k2MyEXHoHS6mcR0jhJ7L0OrhF+jBV231aGcST4dARlRK8kaDqzfz+SCbWPpb+3VMH2wX+uCg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HjvmS5gymLmSXA2dZfrbGEmaqLx3V3n3q8Gv1W9bqcY=; b=g/APUWSUQO/yDiSrUJ9IbDGP29Eg0Qh6H2SYC0I4HDBa+qeeDieR8qgx20/Oy3NLkEkNHJ38UgP1tfUhfPXv2aOxCt0jxR6Glb5kePki0kUkn3tNyc799rKFT7ea2AAWrKqlHX6TGz2l3jexCMifjodzqGPA9TR+P32p+7Sjicjw4+SROPBb1TKwPCoBM75nVwx7oKUD3Qsbmxlg5wBgPtztBhBjpyefGkYuYWBb58dhraX5bAm0nXBArfBHiKJM29xxmJjUWIFyME5lluBBNaaJ7pFFtUFkWuZ/FmU6s6eD9pjDLOu7JzsuFFsqq3yotBMFD0JFRzTk/j1okqORxg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) by DM6PR12MB4172.namprd12.prod.outlook.com (2603:10b6:5:212::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Tue, 12 Apr 2022 15:53:41 +0000 Received: from CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c911:71b5:78e6:3a38]) by CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c911:71b5:78e6:3a38%8]) with mapi id 15.20.5144.029; Tue, 12 Apr 2022 15:53:41 +0000 From: Jason Gunthorpe To: Alexander Gordeev , David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , Daniel Vetter , dri-devel@lists.freedesktop.org, Eric Farman , Harald Freudenberger , Vasily Gorbik , Heiko Carstens , intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, Jani Nikula , Jason Herne , Joonas Lahtinen , kvm@vger.kernel.org, Kirti Wankhede , linux-doc@vger.kernel.org, linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Sven Schnelle , Tvrtko Ursulin , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Date: Tue, 12 Apr 2022 12:53:29 -0300 Message-Id: <2-v1-a8faf768d202+125dd-vfio_mdev_no_group_jgg@nvidia.com> In-Reply-To: <0-v1-a8faf768d202+125dd-vfio_mdev_no_group_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0172.namprd13.prod.outlook.com (2603:10b6:208:2bd::27) To CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9f14f956-4892-4c36-7a55-08da1c9c9c65 X-MS-TrafficTypeDiagnostic: DM6PR12MB4172:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9mIcE9180Eh16V3McjHdsq6PZvQg8kHiFhtRxJy1xZWpO3hHOp6lLLb1IuqvX+jLU8oEEmFhs4w8wGjIxhLzdqhWPRZQHXwr0+odpzqB2ETLXkEIYZvcMql3yrrhiXBn58xXLU+dmD6jqD5QFjI7geh3ALsfcgXm0bwDvA/pnRRxkBkL5kalKTSL65tXgBt7fO02dgbb6bIcfRvYXfLEZAoJGiyYNYtexFVTtGrZ71/wdKZSNEa+ZC2gSKo5qgR5Jo8peUbrJynoKe/WN825nvR3hRNYWWfbQKDaIKOXShR9u0p3sPCE5wU1Dz+fuw4Aj8UaUKwRtUqmBD6y8r34VvV1YrUuU/o3uuWGb6+WClhinq1XNpqGaPEewAGiWYUPWiwxB7dxpRrBJjmNyKFrJ+T3gSxy3IeL7TvV0kgYM5j9zAlv4WMOqcQN1LQVUTOEZ1hQB0TRbmhAOkeiPSHcQUX6di3prgbBEYhzwWQDcW1DI3B1pIwa5FaAIXVZIXB5/fRNXxl13LPfHLBuO9woLD4Fhh3gDGdV2zy7uR2Kmg32jXq2BaHm7I2HV6EbQI1MI7wYbtnFT0xx8dOPWCzKZ74OCoHBSJR2bkwPOfr4drX3iHtHTIH6cagSpKLxn49tuo8i/K6gGR5B5ecAmUe/dRdKRl2LzGNwOHtSYkwIXZkTUDLacFqY49c5i+AMwMTWXxqcpPt/qwqlJJEAhkjJeQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR12MB4181.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(508600001)(6486002)(6506007)(6666004)(66946007)(66476007)(4326008)(66556008)(26005)(186003)(36756003)(83380400001)(8676002)(316002)(54906003)(86362001)(8936002)(6512007)(2616005)(921005)(110136005)(7416002)(5660300002)(38100700002)(2906002)(7406005)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: vhbt2dwhWyvYf8vt3DgLdO+rPrfBeqkAyD5agtKunajk66dLu84nOui6hHeCtWImUJd/nd5hH/B+AxOQ1JnJPlwFmwg17LQdXTb9fZMHOoqmfAj03S2rbLtUY9a4kD4Z/K9cMbeE+t1IunPnwLj8som48caskW2YnOicVovjk+InG6/hSQ9i+owFcd4SQamMVVyEzgWpklw2TJcYksjqAcAzjjWUWxxZEchsunaHGuxuOc44O6O35LbiToiEgUJFyJrEC3Blj6kzz5ovQ6lL0dz4MXuBShuY0H1uBgjDpQBd9Yx4QvWZgswZwyLi5ShswaoZ4CUbtpMGY5wKpJEZ0WdteCky8LLtS9vlGzUx08qkj3iX5GtvEoL4ZRHsYjvIroMn//uqsEv9LSwHujPwNbftaycSsid7BbybnSLp6y3qRHT6IHxqlOd7hzAzztTEtuEMaqUYpv+WmgxFTABuHY/HylUN04f5LxFlkuflA4Ccl6oXkWDVTCDsB1EDyxP5teuGai2DnInVjDPMuWHvjnYUGn+432F61An9QWiBWRs4f0MKcei1neJvUjWzq/E8Pft/hs3VyJcR48C54HJ9fIWdPQQiZ0SMA9YJr4D/XuHXJqdk0LVFPBubL39Q9cOVyoA2fchi6JWsrn8P/C23dn4JotMHd7qiZRZJWk47DfGeftYqRMnwuHSQU8iyrAwiOoBqCDDe0zAxeIhpfECZmCHPiP0+zr0mH7w1I4l4kjw9CC/l46R0RCwLAIyP+iK0lqF+HYMN0vbJfkmxBVvdDIID/J/DBvckXK71S6Rhn8E0lYgR1PrF2nlsIFifXyXQcyqtoyXDUN6dzjIMDLzIWkdmYTq/WqYFD8pliqn2yh1EIXW2hVR2fPNJMMLUnw2eh1Q4k0OCbeBa57gqpi1IOfmQhalqgSABaASCZvurCp4Li2qZEe7a7DeHMP88m/j8GE0oDKf59K4umpBLG3Mt1ZB6/TTEDTDuhUqgUA7Zix2EqBdFKrrA6oy7SAvNwnpr2TwfVwQkxVf1XGHOVl/1SkjboKyy83m1kXNOLs29aZHz9zeON5I1waMWqMi+OqSBHlKH2HC449a/sVvedz8IApo3+CeK/St8l/cwkwbF15R5xqh9LcczFdR1OBFtvji7nyLcNOHkjwAQHdpg4cFScSv1zf2qSPvhcXzOO5apH3/nZY+Jxia7bk/885tRh9etqEHHlV67yn9riZNlfTZH/+BfD9YdXLl4zo8HunkT8hup744NsdVmMk3DSwFYjUDLwdPFJWvHqjpfnomdwxG3/wfKfex1v0Ee+kDRhd3AJkexGiFg/8+v/e54QRvFQs1/ZXIPi/KUan96vNT+Q7eXbRzZiFxndtzNlfPVPAg8izcQQwaO/XDUR68dfYcquWJkW/2xS/P44zo2y4ZYjouMaw5CwV+5Pe8JqYtb8L+3nh6WEnXhPyd8ntg/CyRdzW8PNrNDuzToPzlcibHodEZGXwVVdlxyy9PdTrxUKQSFusq0E6ko7j7kmhnVU3lbRSWvnDB3Bg7LD3Eb9Q6TP7oC+HO9mPL9EeSHbHJ/RKa5NOr7Lbo0zCgk+kaj3XDoslWDMwszEPZaFtQ+XM3Bh+e11mQ1/W5Itr31/G3SSzuTGuaJfpghPBt1MQAdGAInNa0GEtmtE771IqIZ9nd6ni0ilK3skQVdnDgIv3fBsMam58t6z1nnuBp9qiXGIZyuRBHmbakmWd6KvhacyYJCSJOXww== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9f14f956-4892-4c36-7a55-08da1c9c9c65 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4181.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2022 15:53:39.1968 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 1i9XCzSTgYUQfil+KYp1+uouW2hXyWMFmg3ssDbyrx7SrCbdfZOBCUwCiSoR2HRy X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4172 Subject: [Intel-gfx] [PATCH 2/9] vfio/ccw: Remove mdev from struct channel_program X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Liu, Yi L" , Christoph Hellwig Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" The next patch wants the vfio_device instead. There is no reason to store a pointer here since we can container_of back to the vfio_device. Signed-off-by: Jason Gunthorpe Reviewed-by: Eric Farman --- drivers/s390/cio/vfio_ccw_cp.c | 44 +++++++++++++++++++-------------- drivers/s390/cio/vfio_ccw_cp.h | 4 +-- drivers/s390/cio/vfio_ccw_fsm.c | 3 +-- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c index 8d1b2771c1aa02..af5048a1ba8894 100644 --- a/drivers/s390/cio/vfio_ccw_cp.c +++ b/drivers/s390/cio/vfio_ccw_cp.c @@ -16,6 +16,7 @@ #include #include "vfio_ccw_cp.h" +#include "vfio_ccw_private.h" struct pfn_array { /* Starting guest physical I/O address. */ @@ -98,17 +99,17 @@ static int pfn_array_alloc(struct pfn_array *pa, u64 iova, unsigned int len) * If the pin request partially succeeds, or fails completely, * all pages are left unpinned and a negative error value is returned. */ -static int pfn_array_pin(struct pfn_array *pa, struct device *mdev) +static int pfn_array_pin(struct pfn_array *pa, struct vfio_device *vdev) { int ret = 0; - ret = vfio_pin_pages(mdev, pa->pa_iova_pfn, pa->pa_nr, + ret = vfio_pin_pages(vdev->dev, pa->pa_iova_pfn, pa->pa_nr, IOMMU_READ | IOMMU_WRITE, pa->pa_pfn); if (ret < 0) { goto err_out; } else if (ret > 0 && ret != pa->pa_nr) { - vfio_unpin_pages(mdev, pa->pa_iova_pfn, ret); + vfio_unpin_pages(vdev->dev, pa->pa_iova_pfn, ret); ret = -EINVAL; goto err_out; } @@ -122,11 +123,11 @@ static int pfn_array_pin(struct pfn_array *pa, struct device *mdev) } /* Unpin the pages before releasing the memory. */ -static void pfn_array_unpin_free(struct pfn_array *pa, struct device *mdev) +static void pfn_array_unpin_free(struct pfn_array *pa, struct vfio_device *vdev) { /* Only unpin if any pages were pinned to begin with */ if (pa->pa_nr) - vfio_unpin_pages(mdev, pa->pa_iova_pfn, pa->pa_nr); + vfio_unpin_pages(vdev->dev, pa->pa_iova_pfn, pa->pa_nr); pa->pa_nr = 0; kfree(pa->pa_iova_pfn); } @@ -190,7 +191,7 @@ static void convert_ccw0_to_ccw1(struct ccw1 *source, unsigned long len) * Within the domain (@mdev), copy @n bytes from a guest physical * address (@iova) to a host physical address (@to). */ -static long copy_from_iova(struct device *mdev, +static long copy_from_iova(struct vfio_device *vdev, void *to, u64 iova, unsigned long n) { @@ -203,9 +204,9 @@ static long copy_from_iova(struct device *mdev, if (ret < 0) return ret; - ret = pfn_array_pin(&pa, mdev); + ret = pfn_array_pin(&pa, vdev); if (ret < 0) { - pfn_array_unpin_free(&pa, mdev); + pfn_array_unpin_free(&pa, vdev); return ret; } @@ -226,7 +227,7 @@ static long copy_from_iova(struct device *mdev, break; } - pfn_array_unpin_free(&pa, mdev); + pfn_array_unpin_free(&pa, vdev); return l; } @@ -423,11 +424,13 @@ static int ccwchain_loop_tic(struct ccwchain *chain, static int ccwchain_handle_ccw(u32 cda, struct channel_program *cp) { + struct vfio_device *vdev = + &container_of(cp, struct vfio_ccw_private, cp)->vdev; struct ccwchain *chain; int len, ret; /* Copy 2K (the most we support today) of possible CCWs */ - len = copy_from_iova(cp->mdev, cp->guest_cp, cda, + len = copy_from_iova(vdev, cp->guest_cp, cda, CCWCHAIN_LEN_MAX * sizeof(struct ccw1)); if (len) return len; @@ -508,6 +511,8 @@ static int ccwchain_fetch_direct(struct ccwchain *chain, int idx, struct channel_program *cp) { + struct vfio_device *vdev = + &container_of(cp, struct vfio_ccw_private, cp)->vdev; struct ccw1 *ccw; struct pfn_array *pa; u64 iova; @@ -526,7 +531,7 @@ static int ccwchain_fetch_direct(struct ccwchain *chain, if (ccw_is_idal(ccw)) { /* Read first IDAW to see if it's 4K-aligned or not. */ /* All subsequent IDAws will be 4K-aligned. */ - ret = copy_from_iova(cp->mdev, &iova, ccw->cda, sizeof(iova)); + ret = copy_from_iova(vdev, &iova, ccw->cda, sizeof(iova)); if (ret) return ret; } else { @@ -555,7 +560,7 @@ static int ccwchain_fetch_direct(struct ccwchain *chain, if (ccw_is_idal(ccw)) { /* Copy guest IDAL into host IDAL */ - ret = copy_from_iova(cp->mdev, idaws, ccw->cda, idal_len); + ret = copy_from_iova(vdev, idaws, ccw->cda, idal_len); if (ret) goto out_unpin; @@ -574,7 +579,7 @@ static int ccwchain_fetch_direct(struct ccwchain *chain, } if (ccw_does_data_transfer(ccw)) { - ret = pfn_array_pin(pa, cp->mdev); + ret = pfn_array_pin(pa, vdev); if (ret < 0) goto out_unpin; } else { @@ -590,7 +595,7 @@ static int ccwchain_fetch_direct(struct ccwchain *chain, return 0; out_unpin: - pfn_array_unpin_free(pa, cp->mdev); + pfn_array_unpin_free(pa, vdev); out_free_idaws: kfree(idaws); out_init: @@ -632,8 +637,10 @@ static int ccwchain_fetch_one(struct ccwchain *chain, * Returns: * %0 on success and a negative error value on failure. */ -int cp_init(struct channel_program *cp, struct device *mdev, union orb *orb) +int cp_init(struct channel_program *cp, union orb *orb) { + struct vfio_device *vdev = + &container_of(cp, struct vfio_ccw_private, cp)->vdev; /* custom ratelimit used to avoid flood during guest IPL */ static DEFINE_RATELIMIT_STATE(ratelimit_state, 5 * HZ, 1); int ret; @@ -650,11 +657,10 @@ int cp_init(struct channel_program *cp, struct device *mdev, union orb *orb) * the problem if something does break. */ if (!orb->cmd.pfch && __ratelimit(&ratelimit_state)) - dev_warn(mdev, "Prefetching channel program even though prefetch not specified in ORB"); + dev_warn(vdev->dev, "Prefetching channel program even though prefetch not specified in ORB"); INIT_LIST_HEAD(&cp->ccwchain_list); memcpy(&cp->orb, orb, sizeof(*orb)); - cp->mdev = mdev; /* Build a ccwchain for the first CCW segment */ ret = ccwchain_handle_ccw(orb->cmd.cpa, cp); @@ -682,6 +688,8 @@ int cp_init(struct channel_program *cp, struct device *mdev, union orb *orb) */ void cp_free(struct channel_program *cp) { + struct vfio_device *vdev = + &container_of(cp, struct vfio_ccw_private, cp)->vdev; struct ccwchain *chain, *temp; int i; @@ -691,7 +699,7 @@ void cp_free(struct channel_program *cp) cp->initialized = false; list_for_each_entry_safe(chain, temp, &cp->ccwchain_list, next) { for (i = 0; i < chain->ch_len; i++) { - pfn_array_unpin_free(chain->ch_pa + i, cp->mdev); + pfn_array_unpin_free(chain->ch_pa + i, vdev); ccwchain_cda_free(chain, i); } ccwchain_free(chain); diff --git a/drivers/s390/cio/vfio_ccw_cp.h b/drivers/s390/cio/vfio_ccw_cp.h index ba31240ce96594..e4c436199b4cda 100644 --- a/drivers/s390/cio/vfio_ccw_cp.h +++ b/drivers/s390/cio/vfio_ccw_cp.h @@ -37,13 +37,11 @@ struct channel_program { struct list_head ccwchain_list; union orb orb; - struct device *mdev; bool initialized; struct ccw1 *guest_cp; }; -extern int cp_init(struct channel_program *cp, struct device *mdev, - union orb *orb); +extern int cp_init(struct channel_program *cp, union orb *orb); extern void cp_free(struct channel_program *cp); extern int cp_prefetch(struct channel_program *cp); extern union orb *cp_get_orb(struct channel_program *cp, u32 intparm, u8 lpm); diff --git a/drivers/s390/cio/vfio_ccw_fsm.c b/drivers/s390/cio/vfio_ccw_fsm.c index e435a9cd92dacf..8483a266051c21 100644 --- a/drivers/s390/cio/vfio_ccw_fsm.c +++ b/drivers/s390/cio/vfio_ccw_fsm.c @@ -262,8 +262,7 @@ static void fsm_io_request(struct vfio_ccw_private *private, errstr = "transport mode"; goto err_out; } - io_region->ret_code = cp_init(&private->cp, mdev_dev(mdev), - orb); + io_region->ret_code = cp_init(&private->cp, orb); if (io_region->ret_code) { VFIO_CCW_MSG_EVENT(2, "%pUl (%x.%x.%04x): cp_init=%d\n", From patchwork Tue Apr 12 15:53:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12810919 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 72CFFC433FE for ; Tue, 12 Apr 2022 15:53:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F301C10E656; Tue, 12 Apr 2022 15:53:41 +0000 (UTC) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2057.outbound.protection.outlook.com [40.107.93.57]) by gabe.freedesktop.org (Postfix) with ESMTPS id 160E110E37F; Tue, 12 Apr 2022 15:53:40 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z6Ia3JQ6d5uRBIkY1fVpAVTIgEG9mORn1b5AMy0DCvVynu8WWY5TTotX7ma8QATHo2kK/udQe3hL+dny7/bxE9GyAal1kUrjPehiB7VfbphM+dv+9hefKwmRdp7G8bQWdfm4+vxJ7X7EMRX5SIPzN9t5NGZB4RsRQ4hI/5OpVmzKF99eUkruJzeVIrVHkfP6nO06oS3x65O8+NQaHo+tLkjia5NrHSb/OUH7XGfPRfZLGhr0PByzde0h6AUKkii08uiF68z88igNohYrK4h4RVic4djRw1fOTOw2dzrSbgTWfXAakNOiKCg+8urvEDDOJJAlruULLsEGXdR5fBkgsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=zhaO8AuSVmWbnf6E1oY44JxzaoPb5BuPccs9/AMBcBs=; b=PUU1P2Bcd46hxofgxygeuVv1jbqRY8i5XtYMK7H92qzYDDRsXhxLQdCtDuzxgA5+/g1cEQlIrH/sdDhM9ZxpBfRZhGPDqXdSJLDK6SQIWYRxkS/9SaPLKxWMfpClUXK1U+jPVsyYG9YNw5rReGOUSERfCBlIsUt9Ajv71sC8PjAgV5zlCOPHP1Zk5j71hjtNHRz6yVsVFkutmLJ1iavEwV5gBc4VmqYdRg7i6SSRH0XHwP9D0h/lR4md9/QTRE0BFg+1igZ2i9M3dIg+MOOExQGTRAxrdtNtjXlnx2XKMw67ZLVOwj2i631SY7h8k9xn2bPnyFMsSKsApdwFB41jcQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zhaO8AuSVmWbnf6E1oY44JxzaoPb5BuPccs9/AMBcBs=; b=HJ8uA72j8sqzUQ5mBYy4hwkl3YtIllrqRWzZkz732rrOMh5dgiACVK2ZZU1d1qp8hKY4qNy8+hO/YmAnr61o246eUCup5NUsIPumO1WvVjpo6xOtIHnivjWUhJHJEbhz9aZily2Pf7+zMLiEOleWlEukR23vsOScVw9C2+cjOT/62wT9fCwbYNb/psz+fCT6ND8mnWvXumNPSD0tmlVqQEyGSYZHxnp+auotT4nhu8rgXhkbnM0WdQ7moexVSHFPmx/UbmnSA7lUYV+lk6qfGfWMND7o/mFg48xJUkShXqmxziPCfHplk2Gs1yIfdH4L1q6e5AXByOcb2FvFM6Kaqw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) by DM6PR12MB4172.namprd12.prod.outlook.com (2603:10b6:5:212::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Tue, 12 Apr 2022 15:53:38 +0000 Received: from CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c911:71b5:78e6:3a38]) by CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c911:71b5:78e6:3a38%8]) with mapi id 15.20.5144.029; Tue, 12 Apr 2022 15:53:38 +0000 From: Jason Gunthorpe To: Alexander Gordeev , David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , Daniel Vetter , dri-devel@lists.freedesktop.org, Eric Farman , Harald Freudenberger , Vasily Gorbik , Heiko Carstens , intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, Jani Nikula , Jason Herne , Joonas Lahtinen , kvm@vger.kernel.org, Kirti Wankhede , linux-doc@vger.kernel.org, linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Sven Schnelle , Tvrtko Ursulin , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Date: Tue, 12 Apr 2022 12:53:30 -0300 Message-Id: <3-v1-a8faf768d202+125dd-vfio_mdev_no_group_jgg@nvidia.com> In-Reply-To: <0-v1-a8faf768d202+125dd-vfio_mdev_no_group_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0173.namprd13.prod.outlook.com (2603:10b6:208:2bd::28) To CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a0ec39e7-6949-4f89-a647-08da1c9c9b61 X-MS-TrafficTypeDiagnostic: DM6PR12MB4172:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ihyN3bchJ3Ctm+ldZqfC1RHmDUZkf4c0fRY6OhALj6A5KYB4+bE4T9ZFeylz6PXdxgSKTK4D12ayMUmTk97EOY1wuLA+YV08P80ggWV4UWaImDvLjMDVaMfMlmXEYEBedlg9+jQEEfMM44c9Ct6plwZG1ExxsWO1n8tN9TRzf3knTx3S7vMrAx/q7j5v1ErP4uB6HQW4T25m07Nl/FU2lmPMcLgxXB+6CqHbE1k2/uw8IXMl1r58oj/GvuTVV5kW/54GEcaqHz8M245r70qWkt1cBmFyG0VrpmYHo8AO3Q8QRdXyQ+krKV5mPdXp4196LC8CgnBF9dFl+3bl0S9qXlLIztfvT/1hMj/wBaPBBlaH0ej0wGEDN/Lh9Wno//B7KJCeRGQDT3RZHmwvPq6N2xlRw22JlYKqVYYVtfVfe6WFK8T1XReZGXxKS54iheu7VCtjFEj+0jS0eVlRwJ6XgboYzi4edq/yCiJHC9oXZd5qmWkjs2nk8fW8EH5GipvqgfsVZvht5DWd2Y24viWoQGdtlVd1o+mu/D8lk0dhJV2trWmn+nXAhK1OWNGqKee2s8y2sL2HpLn3dk/V1y2R3kYheWfkWFtm0fWRwYRfLj7mBLjPaHTrykERobCzEHks+QCE6D4P0ZDvpfLLGV3yHb+K2wfFBCrz+Dso4vIiUyXBbbPuD+BszrXaRtJV9S+rFfiWHzLzrVXN+ozbe5FiPw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR12MB4181.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(508600001)(6486002)(6506007)(6666004)(66946007)(66476007)(4326008)(66556008)(26005)(186003)(36756003)(83380400001)(8676002)(316002)(54906003)(86362001)(8936002)(6512007)(2616005)(921005)(110136005)(7416002)(5660300002)(38100700002)(2906002)(7406005)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: kkYqN+hCN77JO8WLil/UtA/3aRebl05uo+PK8X1JaxyKg8l64g7rFGRDvJr/1lPt2TzDfVdh8kqVaB6H5TG8rQy4Mvbe5JVx0juoeDLXxD4UUPkAq5JbfMFoWT1HnQIIqNQ20VMwZxAxTqg3AIOIFcFFhaviNIvj+ku6WOvehMADRC07IGRugJkX8a3fWWmxc4Vp0sWtfZ8X64mHP0wm4mJ47sLDgf5JtJEsyqzTpTZS+PQXbuePo4SWjkmqSzUvvFUONy4bWaB5l+lmEsyW/rKPdLtVJIcGfSypd6yOTOFN0Is/i4k25FF51tFTtmQW1exgm6SCYyf6hd5kX1WeQgxFOVX+b/mFOvH1h+eJDj1qNeZmmGHosyIgsCtZRVUHCThEQ6W56+h4m92uHzia+3cNV3BSEvXKNMFmEySwbz8VmEH5NmFwky8IOPhB0CSwhz4P7deDqcIeAaRFgzyOICwnyVB7cAJ2dCT7CLZ3EalvmaglPSSYxkUcHZAgrYRDSL8oOwaHIRCB1poZUffQWTOCsfNPlOReOwnpYPj6zKGSsgtqoF5rY0nS7msRB82etAeDXWJpVu20FDyWuwiKcnJJJXDiNCG+RsjKtf9N6TaoZ/+IrAqaR+s5sm549yU/PHcxwAF5pd6BoUEp4JZmf9KBIvrNr9o2HnlgYMjGzFdSqCdB9EmcpZdbovdymNDJj7SmcAz+Wi9Ht0cr4B6CoyMq2ekxkYLz4LbKxVlJzXC0uD1AyLLEGFSYiRplHr8Lm9RmGKfBTWeNyZv9Czvr6bPDnPJwWUbsbZvY8pM/NJPkPem+sqFbYALngxXYe87tpa8CyO7PkdEt/sP5H6FLXTLENdhVUBsSV9VEGdsYHYWX1cEthMegzJiWsdRsbFX07Zo1wIttjJbokUTNRSM7/p7Hr78ybeiTK+tnBCLPu1xFsphx3x127bWlfDA892/vvVmBvUORxVe/cEOYS7bo7DWIGLrm447prXrsPPlRw7xRJc8FgEw17kT9VYj5KUvUu8TGfCtt/Wc2KRNokphNGkV5e9MsShYXURdh/Pw9vNOI8tBXH+FonqXK4n3W+4nPb9NeyQUBry8bTTq7uvjLfJt+u4+TBo5HQIa4tS2jeIQJB1TBqITopX5K2ghicWzb3F7NS1gabZWrgVvSF9G+kLZnkBD3gPwwm99JV2Dankp6D2sILWJ+oigh7J4AW23J1fMEsHkqC21xBr+U4IPkflWJI18w8RhTkvdE09RHfVrD6iMFIIOZ18DO9cZb9M3sFNu1Zye3wZc42eKUWrWjOE97YyoW3aHjTQF86XMPWKKg6/NqM8j9HxyNl17g5oV3FOChhVw2MvDAs69Ydf/1AfS1kYMHVsY3ciBByJkHiqiA8kpo1iHqo7TIEKCiRM7MUFgg1oLNJPOLB2tA/oMLyJfUkHcjkvXHPj+frSZeEBBMz5uCHffPpf+hRVb1PyJTm4lOmGvPfqlgfFerou0KyVz9GiLfnu52utpa16JYElzdzaQMCsl2PDbflmyxvCFr3IMCDn4YMBnqVuIQagp2l+Bej3Hk3XMXSk6ECKIV+wE5skp/glwD22j9mqBgtQz+fAb1/wNRcaP3RUjRjCFgvPX5qhKgnrqvTQDMvPuwogCeUNJz/nrfgri/ecFy0eo5sFmVI8RWhi6P7w4eeH7RqeIDD4Ali52VAaTI4j4Oa00VKKU+v/69VqYw9No3xYWlWgoxajkY2l5XqzGgTl7/iQ== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: a0ec39e7-6949-4f89-a647-08da1c9c9b61 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4181.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2022 15:53:37.5721 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: H35NTmW0Zo3huFL8xVKx0A/Z0BCmhGkge5WwKlrAz9f+Ufzl53v5fm/bIII9IGLZ X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4172 Subject: [Intel-gfx] [PATCH 3/9] vfio/mdev: Pass in a struct vfio_device * to vfio_pin/unpin_pages() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Liu, Yi L" , Christoph Hellwig Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Every caller has a readily available vfio_device pointer, use that instead of passing in a generic struct device. The struct vfio_device already contains the group we need so this avoids complexity, extra refcountings, and a confusing lifecycle model. Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig Acked-by: Eric Farman Reviewed-by: Jason J. Herne Reviewed-by: Tony Krowiak --- .../driver-api/vfio-mediated-device.rst | 4 +- drivers/s390/cio/vfio_ccw_cp.c | 6 +-- drivers/s390/crypto/vfio_ap_ops.c | 8 ++-- drivers/vfio/vfio.c | 40 ++++++------------- include/linux/vfio.h | 4 +- 5 files changed, 24 insertions(+), 38 deletions(-) diff --git a/Documentation/driver-api/vfio-mediated-device.rst b/Documentation/driver-api/vfio-mediated-device.rst index 9f26079cacae35..6aeca741dc9be1 100644 --- a/Documentation/driver-api/vfio-mediated-device.rst +++ b/Documentation/driver-api/vfio-mediated-device.rst @@ -279,10 +279,10 @@ Translation APIs for Mediated Devices The following APIs are provided for translating user pfn to host pfn in a VFIO driver:: - extern int vfio_pin_pages(struct device *dev, unsigned long *user_pfn, + extern int vfio_pin_pages(struct vfio_device *vdev, unsigned long *user_pfn, int npage, int prot, unsigned long *phys_pfn); - extern int vfio_unpin_pages(struct device *dev, unsigned long *user_pfn, + extern int vfio_unpin_pages(struct vfio_device *vdev, unsigned long *user_pfn, int npage); These functions call back into the back-end IOMMU module by using the pin_pages diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c index af5048a1ba8894..e362cb962a7234 100644 --- a/drivers/s390/cio/vfio_ccw_cp.c +++ b/drivers/s390/cio/vfio_ccw_cp.c @@ -103,13 +103,13 @@ static int pfn_array_pin(struct pfn_array *pa, struct vfio_device *vdev) { int ret = 0; - ret = vfio_pin_pages(vdev->dev, pa->pa_iova_pfn, pa->pa_nr, + ret = vfio_pin_pages(vdev, pa->pa_iova_pfn, pa->pa_nr, IOMMU_READ | IOMMU_WRITE, pa->pa_pfn); if (ret < 0) { goto err_out; } else if (ret > 0 && ret != pa->pa_nr) { - vfio_unpin_pages(vdev->dev, pa->pa_iova_pfn, ret); + vfio_unpin_pages(vdev, pa->pa_iova_pfn, ret); ret = -EINVAL; goto err_out; } @@ -127,7 +127,7 @@ static void pfn_array_unpin_free(struct pfn_array *pa, struct vfio_device *vdev) { /* Only unpin if any pages were pinned to begin with */ if (pa->pa_nr) - vfio_unpin_pages(vdev->dev, pa->pa_iova_pfn, pa->pa_nr); + vfio_unpin_pages(vdev, pa->pa_iova_pfn, pa->pa_nr); pa->pa_nr = 0; kfree(pa->pa_iova_pfn); } diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c index 69768061cd7bd9..a10b3369d76c41 100644 --- a/drivers/s390/crypto/vfio_ap_ops.c +++ b/drivers/s390/crypto/vfio_ap_ops.c @@ -124,7 +124,7 @@ static void vfio_ap_free_aqic_resources(struct vfio_ap_queue *q) q->saved_isc = VFIO_AP_ISC_INVALID; } if (q->saved_pfn && !WARN_ON(!q->matrix_mdev)) { - vfio_unpin_pages(mdev_dev(q->matrix_mdev->mdev), + vfio_unpin_pages(&q->matrix_mdev->vdev, &q->saved_pfn, 1); q->saved_pfn = 0; } @@ -258,7 +258,7 @@ static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q, return status; } - ret = vfio_pin_pages(mdev_dev(q->matrix_mdev->mdev), &g_pfn, 1, + ret = vfio_pin_pages(&q->matrix_mdev->vdev, &g_pfn, 1, IOMMU_READ | IOMMU_WRITE, &h_pfn); switch (ret) { case 1: @@ -301,7 +301,7 @@ static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q, break; case AP_RESPONSE_OTHERWISE_CHANGED: /* We could not modify IRQ setings: clear new configuration */ - vfio_unpin_pages(mdev_dev(q->matrix_mdev->mdev), &g_pfn, 1); + vfio_unpin_pages(&q->matrix_mdev->vdev, &g_pfn, 1); kvm_s390_gisc_unregister(kvm, isc); break; default: @@ -1250,7 +1250,7 @@ static int vfio_ap_mdev_iommu_notifier(struct notifier_block *nb, struct vfio_iommu_type1_dma_unmap *unmap = data; unsigned long g_pfn = unmap->iova >> PAGE_SHIFT; - vfio_unpin_pages(mdev_dev(matrix_mdev->mdev), &g_pfn, 1); + vfio_unpin_pages(&matrix_mdev->vdev, &g_pfn, 1); return NOTIFY_OK; } diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index 8a5c46aa2bef61..24b92a45cfc8f1 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -2142,32 +2142,26 @@ EXPORT_SYMBOL(vfio_set_irqs_validate_and_prepare); * @phys_pfn[out]: array of host PFNs * Return error or number of pages pinned. */ -int vfio_pin_pages(struct device *dev, unsigned long *user_pfn, int npage, +int vfio_pin_pages(struct vfio_device *vdev, unsigned long *user_pfn, int npage, int prot, unsigned long *phys_pfn) { struct vfio_container *container; - struct vfio_group *group; + struct vfio_group *group = vdev->group; struct vfio_iommu_driver *driver; int ret; - if (!dev || !user_pfn || !phys_pfn || !npage) + if (!user_pfn || !phys_pfn || !npage) return -EINVAL; if (npage > VFIO_PIN_PAGES_MAX_ENTRIES) return -E2BIG; - group = vfio_group_get_from_dev(dev); - if (!group) - return -ENODEV; - - if (group->dev_counter > 1) { - ret = -EINVAL; - goto err_pin_pages; - } + if (group->dev_counter > 1) + return -EINVAL; ret = vfio_group_add_container_user(group); if (ret) - goto err_pin_pages; + return ret; container = group->container; driver = container->iommu_driver; @@ -2180,8 +2174,6 @@ int vfio_pin_pages(struct device *dev, unsigned long *user_pfn, int npage, vfio_group_try_dissolve_container(group); -err_pin_pages: - vfio_group_put(group); return ret; } EXPORT_SYMBOL(vfio_pin_pages); @@ -2195,28 +2187,24 @@ EXPORT_SYMBOL(vfio_pin_pages); * be greater than VFIO_PIN_PAGES_MAX_ENTRIES. * Return error or number of pages unpinned. */ -int vfio_unpin_pages(struct device *dev, unsigned long *user_pfn, int npage) +int vfio_unpin_pages(struct vfio_device *vdev, unsigned long *user_pfn, + int npage) { struct vfio_container *container; - struct vfio_group *group; struct vfio_iommu_driver *driver; int ret; - if (!dev || !user_pfn || !npage) + if (!user_pfn || !npage) return -EINVAL; if (npage > VFIO_PIN_PAGES_MAX_ENTRIES) return -E2BIG; - group = vfio_group_get_from_dev(dev); - if (!group) - return -ENODEV; - - ret = vfio_group_add_container_user(group); + ret = vfio_group_add_container_user(vdev->group); if (ret) - goto err_unpin_pages; + return ret; - container = group->container; + container = vdev->group->container; driver = container->iommu_driver; if (likely(driver && driver->ops->unpin_pages)) ret = driver->ops->unpin_pages(container->iommu_data, user_pfn, @@ -2224,10 +2212,8 @@ int vfio_unpin_pages(struct device *dev, unsigned long *user_pfn, int npage) else ret = -ENOTTY; - vfio_group_try_dissolve_container(group); + vfio_group_try_dissolve_container(vdev->group); -err_unpin_pages: - vfio_group_put(group); return ret; } EXPORT_SYMBOL(vfio_unpin_pages); diff --git a/include/linux/vfio.h b/include/linux/vfio.h index 748ec0e0293aea..8f2a09801a660b 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -150,9 +150,9 @@ extern long vfio_external_check_extension(struct vfio_group *group, #define VFIO_PIN_PAGES_MAX_ENTRIES (PAGE_SIZE/sizeof(unsigned long)) -extern int vfio_pin_pages(struct device *dev, unsigned long *user_pfn, +extern int vfio_pin_pages(struct vfio_device *vdev, unsigned long *user_pfn, int npage, int prot, unsigned long *phys_pfn); -extern int vfio_unpin_pages(struct device *dev, unsigned long *user_pfn, +extern int vfio_unpin_pages(struct vfio_device *vdev, unsigned long *user_pfn, int npage); extern int vfio_group_pin_pages(struct vfio_group *group, From patchwork Tue Apr 12 15:53:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12810925 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8B59BC4332F for ; Tue, 12 Apr 2022 15:54:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7CAF710E720; Tue, 12 Apr 2022 15:53:44 +0000 (UTC) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2058.outbound.protection.outlook.com [40.107.93.58]) by gabe.freedesktop.org (Postfix) with ESMTPS id D031210E5AB; Tue, 12 Apr 2022 15:53:41 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kvinM1LG5DPY3k3lZmYcnnj3DgS9Losf51sTHbvYVss3/0yfC+g9iiOfd8J4+d3rw2H6pF1gfGQ2ZDDsOVVSEqQLzsHfYXOPpFPI/5YjO1D9yf34zPfis+8NMmcQbHl0tLpQySaatZPAl0aX7ag/z/Iw2Pep+Y9Q05x248Pph++wj+JEPSyxeF4L2+dO5QaA9lQHLygUiJVrOYKO+7BD6R+XHzaCq+6S3Mgen5Xobm04QE0KkDmMaYBeYMPn2kqzgbpHtpAurPBOCWHSPi94gUjpSrBY/FV5L3/ITkB3rgJ7eLckCG4rs1xOl3H4Ao2m9JJqZCpqmREFHOlYHzWuRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=165cxE3j48rjWOpL5YV2nUjVC6sTOAkTPUOysCsI6R8=; b=NsSOH95IX2s6dbkewSrit2iqRyYSEUoszhY7JyEFYAAD/bM9RmJLeHO2ujWEJREBRb4kTYU70G9KBPOMgjrEv1d4N8v9QBVhMn0xb31dnLbbt2OyJ8L6MgDB6PBn2elpv1XVMay4zbr8HzYyWJfT8r1/V3iQeHQijNRz8hsjRRDmhfr6rgmRXsKxkXyCZIcomzy0Rp/uHeDySL7nTBIlZUXhtWK1963KkQR6BnYMJw2xRdBXXAdcg7mxKZd8lu0ZQnIerW/y3CWKo7GKxgsGzWnts738tk62gu+9MNVbUD8yZdkUng1k8BT1Taj9ey7sK6Jx3ISPa+S8sMuxP5TsYg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=165cxE3j48rjWOpL5YV2nUjVC6sTOAkTPUOysCsI6R8=; b=ODi4drdEGkDDgUtjUQh5njO5TlU43Vhkp2888PKCgN0vrFncLWnIE5ipp8AxPRw9gTPvWoWDXhoeBh2pwu/0cSHTlz3Oee4/MMs5QKBo95fqk3hUBgM7PxPxnpiLb3oEeA6gShEQUGE+oaV8TmFjB8757tTVTEPyIN1ZkT2V0JtsevTu/zDJNcCnZNylf8jN/EK8oRwnoox0aMGNEGDycCcXLJT9A0NI/2HIanu9Oj9e3svyv5df0ZKn1tYG+xtyeQ3qgxJFcaKf2IpAyp9L3DN80YXTMhckZRFWkdzJvqp+Rbdm3/X0M+fCj0RSudavFbcMwIoQp6RgVvWF2PbK8w== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) by DM6PR12MB4172.namprd12.prod.outlook.com (2603:10b6:5:212::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Tue, 12 Apr 2022 15:53:40 +0000 Received: from CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c911:71b5:78e6:3a38]) by CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c911:71b5:78e6:3a38%8]) with mapi id 15.20.5144.029; Tue, 12 Apr 2022 15:53:40 +0000 From: Jason Gunthorpe To: Alexander Gordeev , David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , Daniel Vetter , dri-devel@lists.freedesktop.org, Eric Farman , Harald Freudenberger , Vasily Gorbik , Heiko Carstens , intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, Jani Nikula , Jason Herne , Joonas Lahtinen , kvm@vger.kernel.org, Kirti Wankhede , linux-doc@vger.kernel.org, linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Sven Schnelle , Tvrtko Ursulin , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Date: Tue, 12 Apr 2022 12:53:31 -0300 Message-Id: <4-v1-a8faf768d202+125dd-vfio_mdev_no_group_jgg@nvidia.com> In-Reply-To: <0-v1-a8faf768d202+125dd-vfio_mdev_no_group_jgg@nvidia.com> References: X-ClientProxiedBy: BLAPR03CA0146.namprd03.prod.outlook.com (2603:10b6:208:32e::31) To CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ccf611eb-eaf9-4544-684c-08da1c9c9c52 X-MS-TrafficTypeDiagnostic: DM6PR12MB4172:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cwPgiEXpCI2EjuuK366lTRlwstJ/vtv/IFxDoUtcyn47qwqT3ySkHxw6uAlXAjAEqxuvt5PnNis1LWfvD98q+8H81eIS1df8HRWFmPcHihDHhapG/ZaR2SaU1AUFNOoi1fwiWbWNthzjofvbcR8XIRc2ek0IqIBVjcRKKHy3KWXZIVmqyeuXGzoNa0pG5RxcOlTZUfvtC4yPQUrYl1q8SI0tFGEYK0EhR8ZxJ2MlxnYxFAKCGZedaXgyEuu/BXi1tsXfgQc6sgdtGsuqXhSurKvApkdUm1pPGmO7gr8WFafNayGSOb/UW5A/pOqp7lUloOmzC/ZRIQMXgmEwI5jJEw7+zPpet5AkUDGG7+JTILGnUmVNfcEdkutezo83uQClQGTlPZcosUjBSN2E9nCVt6SwfTxTeCzFoTQ3jAvA7Sk1wffZ+rM2++1rDWUJ4qY7H9qBTAXPVk9OKraIRjfpJNlq9gseCVvO859Id0InDlHNTbJAWo8HAPzSRb2Bbjodesa+61PPAnhB9CPxAnSeO8nLc7nxPo5JpeBG/fqliiobyFwcvKWwYYudirs2jrI8b3ZTi3GL5GD2s2l0Qzod2zQShvaLadZjcQ5u5Kt9qqoKcUgYxJu59eP4awLeNQxGmXqy163o5YOIXL+uElkeKhxE36MLQomZNauYR2bKulssAtURKl61Z9C7Oe+d4M3Nnx7W2yZdWCoI0/PsulstJA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR12MB4181.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(508600001)(6486002)(6506007)(6666004)(66946007)(66476007)(4326008)(66556008)(26005)(186003)(36756003)(83380400001)(8676002)(316002)(54906003)(86362001)(8936002)(6512007)(2616005)(921005)(110136005)(7416002)(5660300002)(38100700002)(2906002)(7406005)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GMeC/x9yVw/fhXSWSEi7dA68O0qtD1oCAHr9dPn35+bADaSmIyKGcwb2m3hRQZkL3pTPj9Q6TPt1D3oe64epyoDHvQV6s8Wq/K2g1St22QoKtqz7lvSUU5+kssHhsMAFyXeqHi6zqJZ6qTaqUC6yAJskFHFKAyfetlJyL7EqZ717UAxOHC2/AOIKuHzJXuVHJUZu3Y5uivgGtY32NEp37V43rnnm0bqMKFlXs/beAgOCfypRKR7lFOknl5AAi/sH0sMgNYmjKELMx91mjdZMgL6INB0LRyNkIaQw4EHfvuQh1bGmP4C3pfexlz7+wBZZTZJU1tMCF503B82DFKJAh2xfPEomtJ1F2mAlzck7pTufnC1V14plfE5mfNQVjbDVeymdq4Oub3PN6sEZa5eJANwDx82q5J70cBrAWoM5RSDYjuAfxM1BETTX+qnoQf9vjz1B+3nOC6N23gybAoDWRJR4glZwHs+0zeX3ys+zXTtCZpntaEWBWQFLNehv9hfqAsxjLQWnZKRf/lGytNl07/lKE3CF7etdZlw+b8ziTfpxHrXwI9YWXta7xCZV9wAKX0B1KKFDMPC6th+CWKPyJ41MS8ylCgQ5CwgO24I5Vw9ApILmoJKNm0V2aiZ91X9NgB6dHHkO4mTB+W4OegF2srzAg5tKnNjEFaya+bbvtaZkXzf3Jntvo43GJa3POh5icpxCZKAVy8Od/UKIonWUHJxaGtQah9CV6lak1Erm07B8TMHkXtNrHQc64l5TNejeMe73S3wK9QHUYNJ/AS97U9fEl1Cu834gJTbvtxMU9IzQqvbNFr/+oSjKl387Grul5YwYKUCum6LQ6qG+esICw5WmstootDtcTm3x25zv2lyC7qXJdAubNUMk35Q1xYpzX+/X5+XcRUr/f/qbbnU7XJUQRnW/XXNiPsC8BgXKBJNRjiULbVXfOrTQVKpW+I1J4uhkllxaKYWsaK4NSINI6YldYQStTCp1CB80qCn3yctWLT4ijCSJSisyNT5t+hASon6ck/NTprhuJj+WY3mxLQ8xRUGXfCU5JNPzc3kFjlxToBN9w6bysrvIGLxqde/mVEd8MJDrltwPP9gckp/Ai61NLQ7zNg3Gll8sByYNLIH3KMh/xKuvfKcJWkBzLENnpVGaNsml7tkAGCBcu8e/+e5owH0O3cFlzuwFz7SnM0QdrT8irkeuquQGI07vVgHc2bZOKKHUuZMX2RDGnjaVb/7gC6qu2tcPHEqhlORthCXkqs9mKcRy3cNNzThxuXpZpZaHzCdLETqJMBGdAZU2CnLc9FfYo6KwqMIcuDhbF4dnxmJdfRv/+SZlzhntm6MpQciI2cq80iiZ1kyO1rFHTaKTD2Qpk/urrJdcrldMQAKIHo1TjRQlOEANrflZ4jDSuNEn6+C2g2wgsLp1dWAHhLEWSpc+i2yOIyEW4P1kKVQSx6Ib/yJ9OdshF1L8GMUs/Sp2JApSM86RNtkipmD3r0dBdIPIaQKP7O6vuUPtFskqc7LOAKVBNGA0COJDZBB2lejYN7vzoFIzwjr/yJk7oqgv9+tqfaq4ogyDLZ642PPGjcxZwUhSt9fCcsl6wROqwve/3jvKu2uI1rPIH87dOHhohFG3K5OHk/wLfS/mIiuq1x2s1BTiGfW1QAKHhxfvTMelYIB/SAGDYNS1ye60JYIuCyJtILLa2REjp3cYeQe6SHxn4dcn81/DzM06eh6BnZZN2LV83LXp2PSM8sG4mQ== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ccf611eb-eaf9-4544-684c-08da1c9c9c52 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4181.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2022 15:53:39.0249 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: wweErmvglIV8qm8HMFshGhrTT1lqh2fdXtJsPXMnvE7SdMGr8vXi0GST2n3WbDSV X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4172 Subject: [Intel-gfx] [PATCH 4/9] drm/i915/gvt: Change from vfio_group_(un)pin_pages to vfio_(un)pin_pages X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Liu, Yi L" , Christoph Hellwig Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Use the existing vfio_device versions of vfio_(un)pin_pages(). There is no reason to use a group interface here, kvmgt has easy access to a vfio_device. Signed-off-by: Jason Gunthorpe --- drivers/gpu/drm/i915/gvt/kvmgt.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c index bb59d21cf898ab..df7d87409e3a9c 100644 --- a/drivers/gpu/drm/i915/gvt/kvmgt.c +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c @@ -268,6 +268,7 @@ static void gvt_unpin_guest_page(struct intel_vgpu *vgpu, unsigned long gfn, { struct drm_i915_private *i915 = vgpu->gvt->gt->i915; struct kvmgt_vdev *vdev = kvmgt_vdev(vgpu); + struct vfio_device *vfio_dev = mdev_legacy_get_vfio_device(vdev->mdev); int total_pages; int npage; int ret; @@ -277,7 +278,7 @@ static void gvt_unpin_guest_page(struct intel_vgpu *vgpu, unsigned long gfn, for (npage = 0; npage < total_pages; npage++) { unsigned long cur_gfn = gfn + npage; - ret = vfio_group_unpin_pages(vdev->vfio_group, &cur_gfn, 1); + ret = vfio_unpin_pages(vfio_dev, &cur_gfn, 1); drm_WARN_ON(&i915->drm, ret != 1); } } @@ -287,6 +288,7 @@ static int gvt_pin_guest_page(struct intel_vgpu *vgpu, unsigned long gfn, unsigned long size, struct page **page) { struct kvmgt_vdev *vdev = kvmgt_vdev(vgpu); + struct vfio_device *vfio_dev = mdev_legacy_get_vfio_device(vdev->mdev); unsigned long base_pfn = 0; int total_pages; int npage; @@ -301,8 +303,8 @@ static int gvt_pin_guest_page(struct intel_vgpu *vgpu, unsigned long gfn, unsigned long cur_gfn = gfn + npage; unsigned long pfn; - ret = vfio_group_pin_pages(vdev->vfio_group, &cur_gfn, 1, - IOMMU_READ | IOMMU_WRITE, &pfn); + ret = vfio_pin_pages(vfio_dev, &cur_gfn, 1, + IOMMU_READ | IOMMU_WRITE, &pfn); if (ret != 1) { gvt_vgpu_err("vfio_pin_pages failed for gfn 0x%lx, ret %d\n", cur_gfn, ret); From patchwork Tue Apr 12 15:53:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12810928 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EBD56C433EF for ; Tue, 12 Apr 2022 15:54:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D965210E6C5; Tue, 12 Apr 2022 15:53:45 +0000 (UTC) Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam08on2075.outbound.protection.outlook.com [40.107.102.75]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8E40110E37F; Tue, 12 Apr 2022 15:53:40 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hbIOCtf3pyQiN/qRL7Pc1BWtc1RbVDIs0hfVBiTExHcK9G4f/YjAK/Jkt7L/2MGdK7B1FsWempiEbFoeoBnW6GIOZjD/JMHb11ojzw0Nr0CBX6gn50Le532L4gunLFMjdC04iGH1NiNnFbWnC4r4Bbsbvqonl1xLNiHUyK1DZg2NSlktLQGOjq8d5NRqR5+iN+Rn5/0+tZmlq7vMIeWlyeoHAcRos/lDzaB2WClLlF+U/FfaTMEzK7e8aCid3TW+K4nPZ27Y8ZT8/4O0HT3O33BfhyRnQdbK1Zc6NDiL93DohIqMn1EMslA9qnBbvHWUrF1KfIoibuFkeV65w6+Nvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ipBz6zUEzjNlBfn0keRHBKDv3oVAdL4US7ij5der/Fs=; b=Cq5hvQMKJBk9hTeb9QvumXRR1jzqVO3uXhUr4A6pwoXJIg3yysoNOPhWRSrzJnUBwwhJugOfPcxSFWJ8X1yK6GKDjJ3qLkp4tL/Q4FSmVbir9hiBi8raNDgPjQwWMjBamE2SyZNLMHy2dRGCLD2kGgsJyvuApPC8kp/S6WvuMGtHvAk+gFFSQ1mwuvm15NRpL2CQQZzDChkAZAfK72K1uUaE5Ud0+otXbUeqQkR8eIIO5QhRQd+kIsO7Zx1hGVe3K+l6SXIMqgOhQ+hJGh9AEziqG/w8FFSP4lUmDu/ug3sgfz/3duKrmIuo2DIj99/85QkyxZ68HrXa/YrqQAaSpw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ipBz6zUEzjNlBfn0keRHBKDv3oVAdL4US7ij5der/Fs=; b=nXpouJ5dJisZdHWVn3g8Ih2bT0DOm9BN15MJ2NZ4wE13hV0SWmcBFatzl9JbfHl2GQvihLLwywNzFEfIFT2MDVpSrKleAfX8fgGaM7Dmd8vYQv5Hm25AnTNL7csLe4rah2fA5mo1W5lj6E214EgHQOqcDMnoygU/M+KZoRVDS9tUj+weXAaW+GPxinOI9NiQvsLoV8XAjIRZ/NDYrmZEkzUD3tntpuvprbvp1BRb8Q/V3d1VarD/CJEZrW1teqd6QD7vUTPr337FtGeRkY60l0UBmVfCXP2Hze4CRX4Wr53ZlD7nR4FqlHJoY1/ard4gpr4DMoxubiPQL7dMAc8Qow== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) by MN2PR12MB4045.namprd12.prod.outlook.com (2603:10b6:208:1d6::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Tue, 12 Apr 2022 15:53:38 +0000 Received: from CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c911:71b5:78e6:3a38]) by CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c911:71b5:78e6:3a38%8]) with mapi id 15.20.5144.029; Tue, 12 Apr 2022 15:53:37 +0000 From: Jason Gunthorpe To: Alexander Gordeev , David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , Daniel Vetter , dri-devel@lists.freedesktop.org, Eric Farman , Harald Freudenberger , Vasily Gorbik , Heiko Carstens , intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, Jani Nikula , Jason Herne , Joonas Lahtinen , kvm@vger.kernel.org, Kirti Wankhede , linux-doc@vger.kernel.org, linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Sven Schnelle , Tvrtko Ursulin , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Date: Tue, 12 Apr 2022 12:53:32 -0300 Message-Id: <5-v1-a8faf768d202+125dd-vfio_mdev_no_group_jgg@nvidia.com> In-Reply-To: <0-v1-a8faf768d202+125dd-vfio_mdev_no_group_jgg@nvidia.com> References: X-ClientProxiedBy: BL1P222CA0003.NAMP222.PROD.OUTLOOK.COM (2603:10b6:208:2c7::8) To CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5c50d941-b512-4790-917f-08da1c9c9b6d X-MS-TrafficTypeDiagnostic: MN2PR12MB4045:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: J/2eaJ+Y58hXP9ec6JHG6xGLZ7jdiAjbAyp2b6RsQfOQCizWkmMt8ONxRE4zs8uDyO6TNVzD95T4UHQSdssX7faXVzbL1qQkZLJ4z52eLg2U70zarWkd5SDHpsK1vYD61IPKpQuRXINfpkYKFsod0aiqTyqIMY+6E+o4LWow9BI/3nf2TsbXS4wdoKme4tpNQca2TUJchhWqax56xEUffoCaTTQA789CJUHt9xFrqfOGWjWvkAK87I167J5TqjSE2KWJ8SDtL18ppy1fVaW1GVhkqdxTiEV35HoZZh6VCUWxpotuVM0Y5N30EKbiRa1JaxsmwuLHvdwSZDX1MgSuoiKqF5OSnk+VlxWo0nsF8FiRW31y+p7BdfDiLKvdEQUKTtV1vWP2KpbeFa1FotJXB0Ei9aUuaOy6MktSm8+TvBZfZaExk58AFFb/Coz2EjrKXFW+7h820PjP50lcULA+3TxBc4bz9++ERUIs8dTMcYjCNbpruvi5/DtIgsRxL7KoOWinTD0mhyjPYEjJKu6pDyfl4y+TYs2LtuIfkEooTh1cgB05sKIfFp86b34D2hzhmIvQY88Q/T7vyINVBx/NjNYi1aH1VUGR2eEisgNApbLptZCdysI2Iw+1R+CmaxFnqmpSbOG4muGG7XVl2cBrGRf68j7h/e2oohYxnz/yXz75lHR/m3BbFck7fPpcpicCx8MPJrpo4sMfbtz4iOfMBg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR12MB4181.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(36756003)(4326008)(8676002)(66946007)(7416002)(2906002)(5660300002)(38100700002)(7406005)(921005)(83380400001)(316002)(2616005)(508600001)(186003)(8936002)(26005)(6512007)(86362001)(6666004)(6506007)(66476007)(6486002)(54906003)(110136005)(66556008)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1tZ4TL1/AEwusqC9PDUcR2zgaAr68+UprHnq9kNcUko72YKFymWTRQMgvjUTStV9dPfSXeM+M+XB8I3vFY0Np6jzLRd5lzV8W+suv2mpaeN+HAfkqNvTebM7zLdjHaCfG5WhjDF20gS/s39P68Y0PNWh/8DhvYCOgeEw/T67Nb7KLLNqO+iDAnyMmjbEZVrxGbGXXdBSbDspVZfsShHE1noDJGEiDD1eS7WQJbYgZ7+tQWHNrpviYcLQAHJgKKLsiONmvyzd+kYmIgy1qBoe8p42Ggm2HkSvb4sDUNqwSo2pInH8HBUUcaYZn7rfDhrUTH52t4lYGR6Fe6joXdcBvF+Kr+Vot95TB4UQb0r3wsX/qIBe2b5+Q1ETSmJiWBkDeH4UdjBlYBeBhnzZDoOL4bVyttHwmGSm8sUSPsr98sZ3/kSJ7B39CoJC3oBYaCoxidmd3JQhwmQTkZkDPNndSH7uWQO+XCf4ARqJkie3qdG3vrnKFMPO54QLfm5tFq7dblA6ilVxyiDQhhD93AlMs5nzDWFqDHDiW1H9mefloJcKndufo7uaFjqqDa9CiXHvyAXw6IMhAM0FPX80n01bpY2P0M+6IL2UiFo4rM2v6KagqgMahPIeO8u8nUY8LYj2XH3wnbZ1nHFaP3+FFbYjVdJN6mU/D40Ivc+LG9gOucrFEIlB29Uv3+z5ykJVhJ94wPIposIsUrLKLDHVtNxeSIROv6Jo556TPJpcx3w3uM/tthAQJUstXsoFeJP5zNb+5upwhIoR4uDlhMLIsPk5nJoW+KmNPuGe8anhS5jqNRP2vjcXgsZXJ/rvjjBhZrfz9RB193rvjTNeFS8EepPkg1VgSVh1iKVoW5szNvVJQb34iXVBhjs7GB2OlkbCWzVToUCpZ9FfHnz+TgAz5rUp7kYTTuD66/jAzI1c80zmgelTGBWNi4SG+MxrKh2tXwTcR/Dr3p/YWHxNYEQ21R7lWiX6qlVYctylvNe8W4uJoRhJdHme0gtuzyMsGsT1k7StOdbtgULJcwMdYf1XE+xdTYlKfiZGFwK9yQWXhf3LU1Y+bcet9oVNT5TNuKcIeiSNgVwF+eB8lYH1XyjWW63HaGIoPObxloxGwBmEToPCsceUPMm2c/in/2EDTOZmbtDKVuAhcToUHkd+m6FPGR4YwOnujMTdchAfird6EOCN50Gw7bQbeK+b3nZDO4UoWZYZoVHF156t0LGR2qUb5x++oURV3HpDBvhPKqOcVTgpy0G1r9y5vuiPnGEU4s0qY6lnAW+SAYo57LrjS8nQwUn1Pm0VIf+n8rD+ZK6x2nXPbf3EYC4+s7RPV/OUaLcX8I6h3TQWg3tOFKxynaEwVw24nKYSdc33cJKrx4txEfGPrfGo249bL9tLtvvWLE38UeYvw6J6K+8bui3Zdvs8wuBMO/AvQd/uj0zhpfCfpWhghkdlhpBoY3eH7l9+yPwga0yGex7MbEzlmgE64jdyKW93ADbFg1unF7Pam07Y+z+hi6gK13S9tKrcZKesHJc1gP0VMumjSzd8qNGa2v/5GObqkTdgIXWt66HjkNWLvyHB5F+uKqv16h4bmotS3IoGmCF4tIO18SEQt95ncueN4VoWChyPYwsPpxeQSAPs0LZnppidMhPCz0H+ZWxmhqTRdB8x+/pYM9qFMzRgWU2xpMy92i7rtB19nk4jLZRX1Ib9m4Is7dYuv1mNXQuMzzqweoRSkRBISWhWFlr8Ol1BjuoR/Q== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5c50d941-b512-4790-917f-08da1c9c9b6d X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4181.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2022 15:53:37.5565 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: N2+AFwymYMaDbcHTsvWxuCnq5dPH3Hv9zNFKKQiIS3aGqzdgcRFdQcbDqCoaBEGH X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4045 Subject: [Intel-gfx] [PATCH 5/9] vfio: Pass in a struct vfio_device * to vfio_dma_rw() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Liu, Yi L" , Christoph Hellwig Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Every caller has a readily available vfio_device pointer, use that instead of passing in a generic struct device. The struct vfio_device already contains the group we need so this avoids complexity, extra refcountings, and a confusing lifecycle model. Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig --- drivers/gpu/drm/i915/gvt/kvmgt.c | 5 +++-- drivers/vfio/vfio.c | 22 ++++++++++------------ include/linux/vfio.h | 2 +- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c index df7d87409e3a9c..3302d5d4d92146 100644 --- a/drivers/gpu/drm/i915/gvt/kvmgt.c +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c @@ -2184,8 +2184,9 @@ static int kvmgt_rw_gpa(unsigned long handle, unsigned long gpa, info = (struct kvmgt_guest_info *)handle; - return vfio_dma_rw(kvmgt_vdev(info->vgpu)->vfio_group, - gpa, buf, len, write); + return vfio_dma_rw( + mdev_legacy_get_vfio_device(kvmgt_vdev(info->vgpu)->mdev), + gpa, buf, len, write); } static int kvmgt_read_gpa(unsigned long handle, unsigned long gpa, diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index 24b92a45cfc8f1..e6e102e017623b 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -2323,32 +2323,28 @@ EXPORT_SYMBOL(vfio_group_unpin_pages); * As the read/write of user space memory is conducted via the CPUs and is * not a real device DMA, it is not necessary to pin the user space memory. * - * The caller needs to call vfio_group_get_external_user() or - * vfio_group_get_external_user_from_dev() prior to calling this interface, - * so as to prevent the VFIO group from disposal in the middle of the call. - * But it can keep the reference to the VFIO group for several calls into - * this interface. - * After finishing using of the VFIO group, the caller needs to release the - * VFIO group by calling vfio_group_put_external_user(). - * - * @group [in] : VFIO group + * @vdev [in] : VFIO device * @user_iova [in] : base IOVA of a user space buffer * @data [in] : pointer to kernel buffer * @len [in] : kernel buffer length * @write : indicate read or write * Return error code on failure or 0 on success. */ -int vfio_dma_rw(struct vfio_group *group, dma_addr_t user_iova, +int vfio_dma_rw(struct vfio_device *vdev, dma_addr_t user_iova, void *data, size_t len, bool write) { struct vfio_container *container; struct vfio_iommu_driver *driver; int ret = 0; - if (!group || !data || len <= 0) + if (!data || len <= 0) return -EINVAL; - container = group->container; + ret = vfio_group_add_container_user(vdev->group); + if (ret) + return ret; + + container = vdev->group->container; driver = container->iommu_driver; if (likely(driver && driver->ops->dma_rw)) @@ -2357,6 +2353,8 @@ int vfio_dma_rw(struct vfio_group *group, dma_addr_t user_iova, else ret = -ENOTTY; + vfio_group_try_dissolve_container(vdev->group); + return ret; } EXPORT_SYMBOL(vfio_dma_rw); diff --git a/include/linux/vfio.h b/include/linux/vfio.h index 8f2a09801a660b..91d46e532ca104 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -161,7 +161,7 @@ extern int vfio_group_pin_pages(struct vfio_group *group, extern int vfio_group_unpin_pages(struct vfio_group *group, unsigned long *user_iova_pfn, int npage); -extern int vfio_dma_rw(struct vfio_group *group, dma_addr_t user_iova, +extern int vfio_dma_rw(struct vfio_device *vdev, dma_addr_t user_iova, void *data, size_t len, bool write); extern struct iommu_domain *vfio_group_iommu_domain(struct vfio_group *group); From patchwork Tue Apr 12 15:53:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12810927 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 39983C433FE for ; Tue, 12 Apr 2022 15:54:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F1AE810E735; Tue, 12 Apr 2022 15:53:44 +0000 (UTC) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2077.outbound.protection.outlook.com [40.107.93.77]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1F01510E5AB; Tue, 12 Apr 2022 15:53:41 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mg4eDx9HY6YewhVJNyxx4DQjZXAmtkNrZPSiD0GFuvlfDrZvXMlAUnkLc7Tfg1N2ea7yjn0EAdPFksib0qejesD9u0VangWgaGzPpH1WPN6LP0MReC5wBONeiAogTHjyOdg2hFqPyCtNmwd5tJ8Lj8l72+1S13oOUGdmAYy4V32z3RXwCIVVS5MdmqYAwrps1qZ0+eoWozMFYHf1e2qm3yxXcHu3n/RQhZvIpPWvr7PLAoDhcG1RNa7Abm+8D9S23LbpHup5trkYNZmXPFzdmZHEa4ddstw9z//oQf/CfkbZTw8mlrvunaEqzRVmkhiu+evh4IA4ZFwokoHwaDwuVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=81XbNUgtumQh6yJj34o05O/PNajhc+ES4mVJ0ZY78aQ=; b=OVYvs2CfbXcKL76YbpEMJox//ZK8YHBiUY5WTbSjrmI4dmgt/ievudTgh99WVVUB8yjRzH08RQowsQULtx9gu8gtYHDBGxQ1KyQ60EdoRd8RBoslmjDroW0TBNpWsb9t/W0RPJPco09FCYi+dGBMSB4HG5eXU5wA73L+Vof3Uhnpv6JM/0UtHG4GMSw1caHT95BFkKCUPqe2qUMX0hpAxQNNZdx7UApTPDt4b6S1fhKpJ9LhEaC9KUSyLVLsRPejnr/AiCCPOgUkaQrKzSKXKptU3RJOdY40/VCkh72m0w1+SyzKL5J7F6sWnq/yaZNElsL7sM9j3/XSeKn12u32Bw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=81XbNUgtumQh6yJj34o05O/PNajhc+ES4mVJ0ZY78aQ=; b=jxX34NfrDeFU4RBJhvvvvG/n+zEUEw1kKNnRvVamcHxhrGDsuWDIJqI7C5xlcRVUyTmehS9vf+20xOZXcp81/a4Qhodc+ZgiDeKemOQ7lmgVsCI1TzaPkwXnXmge6nenKWXEEo+1EmEfeGGecFM1G28YoBbSQvFJGCWPFa86VRiXoOlw75avB7Zr9gXuEGIuZD2kxfUDwxykMS3NmPc8VsLXndR150cWSuZSBQvcPD62nXku4iq7OAVDEM/DDLgMUdk9u7ELhXk3tU5V6R/KpOJdaymH21CcrahUBoaT2POpXekSarKy6FmDBoN04cg13H7uSGDDqjq3Su8Etq3lmQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) by DM6PR12MB4172.namprd12.prod.outlook.com (2603:10b6:5:212::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Tue, 12 Apr 2022 15:53:40 +0000 Received: from CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c911:71b5:78e6:3a38]) by CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c911:71b5:78e6:3a38%8]) with mapi id 15.20.5144.029; Tue, 12 Apr 2022 15:53:40 +0000 From: Jason Gunthorpe To: Alexander Gordeev , David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , Daniel Vetter , dri-devel@lists.freedesktop.org, Eric Farman , Harald Freudenberger , Vasily Gorbik , Heiko Carstens , intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, Jani Nikula , Jason Herne , Joonas Lahtinen , kvm@vger.kernel.org, Kirti Wankhede , linux-doc@vger.kernel.org, linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Sven Schnelle , Tvrtko Ursulin , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Date: Tue, 12 Apr 2022 12:53:33 -0300 Message-Id: <6-v1-a8faf768d202+125dd-vfio_mdev_no_group_jgg@nvidia.com> In-Reply-To: <0-v1-a8faf768d202+125dd-vfio_mdev_no_group_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0156.namprd13.prod.outlook.com (2603:10b6:208:2bd::11) To CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b4954cd0-529f-44f9-cd70-08da1c9c9c35 X-MS-TrafficTypeDiagnostic: DM6PR12MB4172:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zjYUw658ss6Grdjf9VqDxzXYrfg7CZBhdjF2/PJgDwBExZAxcCUaGnZ0nQht3eXRb+TOIina1yo0beEdVqNs0HMkroy4FNwgBW4H8guPGlGuRCndWu4Pgh0busVKh1buW8ow34+0CvyXrTcHHfw8LCisEANot/+PbTLU+Hm/cv7VncJwZDsmCu9cWCkm3E2gdln1sc6A37nwVyT4XTT0VGBpRtny42XlP0XPclvvhp4sRNrWbzbzbFj3vFpYKmvF92KWv9AxOf9DEhKroCXGyr3ULQpDDb/CttDPzcfj53VP3/YXeXfIH6g+XMKC96E7YTg294eO2yNRyrV0FNhqHxmRfOE1BagIbHQeqcUh0eAGVr37tfnFKdjnUnXqNycQ0AWothKEznHiXZSgDvr+Uy8mpSqAjgaBeLe30t7tqPTwEHWLpfBLGOiN7CCIdbbuxb4hVW4Vg6v0WWpdQmLS6nTDrimKzhBnZv/eFgwHQfPSLzHIp8wFdPTShudvKeXwzoSL9T8sUvzmJF0rT1zWcKxly5fnvwTeqmIDbIJ4L2vIfbQM4dXE6vVPoY45Dn/vNPW8bbbebSZ7gQQcH1jLEh4CmZnhjb1DeKILlKB7TDEhRhgOOGXUfYxLKYl7cN8QG/19CSb63jfGhFv2lP9C9AblH/ZcEiRSZiyOSl2Ii78xu9bB4aIA5nKJ1KHHI+wZCfnT7NZk15BWhlNwviv6qA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR12MB4181.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(508600001)(6486002)(6506007)(6666004)(66946007)(66476007)(4326008)(66556008)(26005)(186003)(36756003)(83380400001)(8676002)(316002)(54906003)(86362001)(8936002)(6512007)(2616005)(921005)(110136005)(7416002)(5660300002)(38100700002)(4744005)(2906002)(7406005)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: j1zUVehbyTbfWu8XuvnAtqaC14Msy0Eg36tl3Ccf6Mj4jkScPvBAdpVRKucxwC6m9Dz8MvnBGoH39s6rTZZheO39sSEPBspriu336tbYFCA2CVQRFdZDsLZCbWa3K2LR59AS7d7OkGhdVZZc8GwL1IdLIc084h586SEmloM1ECYm+QLd/PbhpO5vVSCHYvpqE8jg8Sy1vKHnnvwqCz63zC9S4nR/bd+IAh7h0JkrPrxiCjGqBww/mn6BUChhZkhYiCRs1+3uGraX8wA05HpZFp9A4JJ2lr7+KwIpOR/16W6ZQc0Ii68Qc+ZawaWlIgL92l7/Sw4mT0RElgZFn4L6fUyg8bDtC3RV8N9LVGSJbEoSo68gaLsn+CtuZm+bPZDvjY7piXUyZrNqT3bjCVgItR08D1S6dtPgK+PlLPTU6oM6xtwZxmMDBAmp+UQqmlM/2Ij12DzKNYOMAq0K5MfYA2E5wECBjm5XKGISZNR3fvaO0C+Cb7CE5f4YON1oxg6ySJKJnHXEXQjilixaXd1Dd2l6g0iE/wVcwyes62sOzmnhlclYi+ZusrG2uDpswgHc9nQL9EtTSrbsQ7kSh8R0yUU2VDN+I1dn9BLV0T3uVS51OVR6Y+AJIRoKCTt25Wt57XRh9f0E+umZuSoqUUSkio7CJGWy8QEAlgWzR1jSFtJb4az5S0XnKCatGaWT+WjIbjaFoseZ+hNJFt/0Pp4PghCRwY5yEp4XJlJrqqD8qfT3PyHzJhAm4dNnfKlSWa10DMnjBITb18pKpVfeUjqJewGl51RpOCaOf2ejRwf4fDLgPBN+xCsZfqXpqpSUSWUYL++haVJNHX1u9sFLuXqHNUr4orQaglNQ5YRQcsL+Tfp3C8RMSOlxqXXPuIhqwpiPrfCdW06k/iAAvDqCegIzz5ZJ14B1tLeq5DHIKNxG1kF7VFgz3gOOORLfSy7/EG+9Mh1GzrHV63QkGXhxaPWZvlaYbA092ma5Zzp4q+kCaNCEihft8Wl6dpDSwDazJe0dz+PgKnhpgi1KmhTCPp4YxmS0qYu94GyFcPk7bm08QCdx4nFvhZjDpVSltPMY1lPBl6fi94Ut1IcWkgOkoeH7ZHFY7rIcsoSY9Y06rF40IqNJ8H5XsifLfx3cBIxl5LfBSWAoi+8gZh316YuPsqg8h6CahUkkjr4T0oHwm/kVNEctGZUwB0lQEhRC4A2GRyE5qPBzSqr+bC/Wd10xqKo8Ic9Tc9Osjg1Hb5LE5A9yPnLzMJhmUTtWQCWsIobUQZvG+DINn2mMwk4ICenyYAmmhNiRRpBRULIsGI/K2t/hopPa6fpItqylQRwams0J9Xl5FTKI/bVSXgWyjZlBIJNCfP8Cd5KBu5MUT4MhqDJfC5Gr9Pj6c1eDM4OTkXyVMWMdz4olohnQVm5fHvCUTqx4GMWDDLSInivJYwzoDaYXI8cHMK30bQ0o82Nlz3tE2ycJO7CN+iC9Ekn3LdysjhMCOoj8jVzMBle5hx2Xp9lHXC5Aoyil0ih34mx5KG10mbDauAHI95HyQa1Dwn1ZzxWbQZqNn6kWBDyKs4Rkpl9twYQLo1vGLT/V0BY72WgWA9yBV39Mgg8ToMXfxw2h3blJz9whlAnC/i1RQdiwX3HiwBeLrryPXXkecEh2ZwSkVjUBA4SP29RGhJxkyWW/BQwKrRwtRF/48HM78MARpQW1ZfVEFcSMI7e9dPYG642YBr15o7berd49GP2SPjVhBqh3tw== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b4954cd0-529f-44f9-cd70-08da1c9c9c35 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4181.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2022 15:53:38.9156 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: lXRECZ8xJsY9rhSLT+ZmT5goehhIoKKnESV1tHLJ/6cJwrbI06pf5iRYDT02OuQG X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4172 Subject: [Intel-gfx] [PATCH 6/9] drm/i915/gvt: Add missing module_put() in error unwind X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Liu, Yi L" , Christoph Hellwig Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" try_module_get() must be undone if kvmgt_guest_init() fails or we leak the module reference count on the failure path since the close_device op is never called in this case. Fixes: 9bdb073464d6 ("drm/i915/gvt: Change KVMGT as self load module") Signed-off-by: Jason Gunthorpe --- drivers/gpu/drm/i915/gvt/kvmgt.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c index 3302d5d4d92146..d7c22a2601f3ad 100644 --- a/drivers/gpu/drm/i915/gvt/kvmgt.c +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c @@ -952,13 +952,16 @@ static int intel_vgpu_open_device(struct mdev_device *mdev) ret = kvmgt_guest_init(mdev); if (ret) - goto undo_group; + goto undo_module_get; intel_gvt_ops->vgpu_activate(vgpu); atomic_set(&vdev->released, 0); return ret; +undo_module_get: + module_put(THIS_MODULE); + undo_group: vfio_group_put_external_user(vdev->vfio_group); vdev->vfio_group = NULL; From patchwork Tue Apr 12 15:53:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12810926 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 602D9C433F5 for ; Tue, 12 Apr 2022 15:54:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 03A7910E741; Tue, 12 Apr 2022 15:53:45 +0000 (UTC) Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam08on2075.outbound.protection.outlook.com [40.107.102.75]) by gabe.freedesktop.org (Postfix) with ESMTPS id B9F1F10E5AB; Tue, 12 Apr 2022 15:53:40 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BxvAZk6BwFOihfMNufU0JTJBg5kjllEOBTrw51GCov+rVYTfaN3TdlSCAsnhCuv6yUu+Z7kvkyf4vcUvRY6LjN22pCILVPiM2aaMJDzi25ORqmkhp+RujFUGvUv790ulKEF2sgKVHsUwW2TxC5KQE/uZRnVQmA9K+h5AwsaXMshW7RTHb9kp/jhnJV4kYnlJ9ZSTis49oaR2xmCYsg+x4/HFnTVxS1eCW7AHr30HQ2Mj+kqgZdvMg5o75HTiKTF7dknU+N9D9IMr1qPnKCgjQyifsc+K+3YI5PMQtkm1V+YoXZsMW7e1b3LCTU/qmVHZIdSS5A8qtbD/s9OnIvjkng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=PrZ9g3FaZI20+0MWXqn4DjRgP3laNrkGpp4uvldcai4=; b=Xcvv0mMxndYrokMsE8a92AsDGEFFAnZGottin27FTgopfvckwq0eOE5tnYZm8LRIOwY51UU+B5sgqDU7jQNIH6kNc8KlWY3r9kheECQfuJ36luVJLutFEBBf77X/evTNYoiJEn3+N8gJHGASMLoz+bJe3pjr68PnEU/soshsHsGykHwqUaN1CSJPeB0QtMA6LIhiccj0EBrEMDLYfBpApxOC9zTKUrALq0uGcgr+CeCFAd5KEckUASZ9Bcp65s2NyxZQdJ3eROyvaqmnmVNXHOHaCf2qEHUFdsncxZdq1mhI2bVIf7JUsZmL0QhL0BYwVzSWLoNjqSIbt5YCzWYpDw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PrZ9g3FaZI20+0MWXqn4DjRgP3laNrkGpp4uvldcai4=; b=cICATLSsSyMVY/PVkzZKXqvZK5e5JSe+Fr8zbdArfnmO+gMDJBJq/eaTuotdVDMWtcaLyHKU4E2AkdQyNoVwuanfdQOHw47JNGMc5WKFIPt4HkXW3POKGqe8PE6TVH6GuGXd5ln3X9vnoBprUO8DII8OmQVQo0EsMfyLZ1IF7LVLKN3CRV2mxjRruMCJGeDg5R5utN7/T4DA/PngLciMrDF6yLcQ5/TH/FBYuvofmdAtpGkmtcon85B0s0S29evOOgu7iHRFm93kmfKb4c1axQdy//zs5vYTqzah/Dx/H/DTrQ+wY+pChlYrdnHiMQZPDwnmjD8W0sBYUOviNILw2g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) by MN2PR12MB4045.namprd12.prod.outlook.com (2603:10b6:208:1d6::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Tue, 12 Apr 2022 15:53:39 +0000 Received: from CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c911:71b5:78e6:3a38]) by CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c911:71b5:78e6:3a38%8]) with mapi id 15.20.5144.029; Tue, 12 Apr 2022 15:53:39 +0000 From: Jason Gunthorpe To: Alexander Gordeev , David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , Daniel Vetter , dri-devel@lists.freedesktop.org, Eric Farman , Harald Freudenberger , Vasily Gorbik , Heiko Carstens , intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, Jani Nikula , Jason Herne , Joonas Lahtinen , kvm@vger.kernel.org, Kirti Wankhede , linux-doc@vger.kernel.org, linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Sven Schnelle , Tvrtko Ursulin , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Date: Tue, 12 Apr 2022 12:53:34 -0300 Message-Id: <7-v1-a8faf768d202+125dd-vfio_mdev_no_group_jgg@nvidia.com> In-Reply-To: <0-v1-a8faf768d202+125dd-vfio_mdev_no_group_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR0102CA0019.prod.exchangelabs.com (2603:10b6:207:18::32) To CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 12731ccf-7502-469d-336b-08da1c9c9bc3 X-MS-TrafficTypeDiagnostic: MN2PR12MB4045:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +1gdDE79vCFuQf11Djx/m8F0jcbZ77MZRaRVeehD6jMoo/3mrXF7NZMHz031TpUU0WJ1A2d0gUBuihI7kr7K1F6iZKK2V8gIuMyKCDM6jPwi+VgC0INqxRbWYpjGLpQJxsoQu0iIC70xETFhTKMtapG47ZFom1gyN3mDVvbca7pA9ujkWIRRJ13c0wstHQV7TbQWksMasTWHxk5TXsYXC19W4AAc52ex6yyvNQznBvBWKI968Y0j+KOAj+g6wGixTvjs2qkdTJKjXxetsxqibrIl5n+4BLo+WhsxGvP3rJJAvxWd+f5yx45L02Inx1Bba/RTa+L1Ohk6exQGOW0VDexSi5kVPljUeb0hshcA7A3CqQBqkLCofG/2J2suKgl2s3MJ+/+9pqBFGqBeiuYNXQWlKyN9wkSDJQgqT2E0+A5Yz94Ng4jsAzWC7K9G2NdbrQlZMoSGOpTBbolMQIJtuGZesh7EbC5mu3XeNj+XSU4aFzZmOifKg4WP163wT66I3oVjbeBVBIX++B3FfJU+xpG3k4yZ8L/RAd40D2beZbQFJPbcJlwYwo31sj1mLCZbqGMssJdMft2oxXylfPJlXbWyfjyP05VswBvmt07xr5+fBwHLplMi66d/H+KzfBfIoQdXPghcCS3RuwYAFv0KN/ziRKJmonwIDlnY0OEWn0ZkKVzuTNE4Oa2jBaizS6tap3WTXCa8ituB1ABUZTU7rg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR12MB4181.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(36756003)(4326008)(8676002)(66946007)(7416002)(2906002)(5660300002)(38100700002)(7406005)(921005)(83380400001)(316002)(2616005)(508600001)(186003)(8936002)(26005)(6512007)(86362001)(6666004)(6506007)(66476007)(6486002)(54906003)(110136005)(66556008)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: w2mc698qaOXV/yqNqXC3HxmeDdDK5u7mQUmop/Hr/3Xkxi4R3Dg7p9R4Ofg2tBqUQyEJrR4gquF3spYRRFF+H6MLzcB/om642PkM6MmWyFSbp7UK+uy8pKUwse5t0Rt+zbniTDZ/x5yDoOSaphA24opBSkSErg+n2wBrxHDgiPn8sZSkZ/vDaRxlZF04xMoeDrjZRCaAdPgsk13asDGi3j0tQ7+hWRrYbXXD+1LVWBQi7khQggbhOCPLiUgGyTR2v4HOqs9mLRmqZHe6izlUnSYLEFZfg/56YTbOjhzyuEuCE9DjglJxJ2Vaovhhd+mWfQFI9JiaQYZSa3mjWopeddC09cf9m+gZ/bUfzv/kyKSrKFpKWy2DXo8l+9pEhBMV3HlfL3pQybLbKC77Uf9NxHBoRTsJkkslZbiVsscjUii7G3WsdzAz3Houeif5vMscgFnJZTo68hcolbHwp6keFYhfXUTvg8MmBkDrnceCsbN18po3eTtQ5/5gctedvewVByJSdxzT1K0Y4dkJwiOY0uXCsA9WfW6dMpXTGBBOuQUHW9KvPjeGMFulFOLLNY0twNb1P27cR/BdbHzlQ1M5MJCz65L0BChH/5enqYX0Q1czAIPipcILNiky3zCtnJcHOVGqkJuBj64Hxs2ko3JFxpVqWFpu63rmzFeiqqjsPYJlH9bXUqvMxLuwK8uRP4DbGkw3F6mGchsUzvC3dRxh6WhmGfS0QpGjwSn953ydBqG/pWUEU2/kaUhQSsUj/GyjbkFDxWf6cCWE8U096aHkoeHcRld3ec3XVu/IEkHBanWGPO7ynuWPH4QynUFavL3l8ZakXZvmuItGltG478wxuHHi+FbN0brP10Vha4XVEWEHEdQkaB8cSADUgqJ8MgF7OJCZSfQ4tN4q3Fzc5N6+c6aj9w0qGrWboHTPe1omJq8JYJLVMRDODJWkM4HauLXn9/3fa3XnULLEjvIasosi+oDMWZyVLxnh3BOREoaCsFo7PyVlIchWUCz/HHflg7yZDd6gHh9unhW/DFvFLnAQk24MKLLFi6hTFiX+tQdPWQDu3Lo0y7c3fh2LAggDhDTIDbmIUustSl3rQEMQkFJEJ/Rhd/Yq6jLjq3+7YglXIETbK0UtBf83EKdHuHiahfPYzz1BKk8YrItSNQGdXLJdP7QQE4U7JoOFgvRdaOnAi6ZBT4U/+ZobHi8MbQ5lV3WYTkVCQKsgApL5hDIBv7/N4FM7TbjOnOp14flKDERb5mUbOWRsq+tHD5A4DTcjbuXWYFpElxw3IX9jBFc6YJeBctQbZUr/D8gxuSVxTHphgxVpVytL37xJjPhRenhiDYMB+pUPofbEI1OcfCj7XSVcUv8FkArL4jLRHewiCkkvZu2Dsb2sbZZv9/wgPE5HuHKcSyzZn2VmJPlYMoHoPc3U9YYCxaK6Rr3llLH25PxpywNSywP7t33EYumOHt/jCjCRgM5Nzn2K6HV86HyOUfKDj1FfDlcIFNpWkdGp5i8yTYsrnrJU/kpNpXJXo3gFyzHRw0eX4f/kUYRHl9ej157qreLktC1t2w+FH7qpDqRCbVERAiZ+2ggLcw5YAtOOS+hD2J9QY1wQpNu53Bx1CNkdt7yU3K5NlhfrNwX/NTAAISZWNH6hkCtLxU3Gf1AA6uZ6/0UJqtNfXH8TU3traU2wkFPCYWtNrNeuNBwlmnUt/lbyKgyPTsEScD2FysFJe+eAi/7HFCyJGCAHyk+FOJBhhg== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 12731ccf-7502-469d-336b-08da1c9c9bc3 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4181.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2022 15:53:38.1032 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: VT4kOgz3l/NY16q9GFz/3cJdwkg2rxt3QqbZvjPN22MNHRKzDP+PmEVhlJLiiSM/ X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4045 Subject: [Intel-gfx] [PATCH 7/9] drm/i915/gvt: Delete kvmgt_vdev::vfio_group X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Liu, Yi L" , Christoph Hellwig Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Nothing references this struct member any more, delete it completely. Signed-off-by: Jason Gunthorpe --- drivers/gpu/drm/i915/gvt/kvmgt.c | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c index d7c22a2601f3ad..b15dbe9ecd7e15 100644 --- a/drivers/gpu/drm/i915/gvt/kvmgt.c +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c @@ -133,7 +133,6 @@ struct kvmgt_vdev { struct work_struct release_work; atomic_t released; struct vfio_device *vfio_device; - struct vfio_group *vfio_group; }; static inline struct kvmgt_vdev *kvmgt_vdev(struct intel_vgpu *vgpu) @@ -911,7 +910,6 @@ static int intel_vgpu_open_device(struct mdev_device *mdev) struct kvmgt_vdev *vdev = kvmgt_vdev(vgpu); unsigned long events; int ret; - struct vfio_group *vfio_group; vdev->iommu_notifier.notifier_call = intel_vgpu_iommu_notifier; vdev->group_notifier.notifier_call = intel_vgpu_group_notifier; @@ -934,20 +932,12 @@ static int intel_vgpu_open_device(struct mdev_device *mdev) goto undo_iommu; } - vfio_group = vfio_group_get_external_user_from_dev(mdev_dev(mdev)); - if (IS_ERR_OR_NULL(vfio_group)) { - ret = !vfio_group ? -EFAULT : PTR_ERR(vfio_group); - gvt_vgpu_err("vfio_group_get_external_user_from_dev failed\n"); - goto undo_register; - } - vdev->vfio_group = vfio_group; - /* Take a module reference as mdev core doesn't take * a reference for vendor driver. */ if (!try_module_get(THIS_MODULE)) { ret = -ENODEV; - goto undo_group; + goto undo_register; } ret = kvmgt_guest_init(mdev); @@ -962,10 +952,6 @@ static int intel_vgpu_open_device(struct mdev_device *mdev) undo_module_get: module_put(THIS_MODULE); -undo_group: - vfio_group_put_external_user(vdev->vfio_group); - vdev->vfio_group = NULL; - undo_register: vfio_unregister_notifier(vfio_dev, VFIO_GROUP_NOTIFY, &vdev->group_notifier); @@ -1023,7 +1009,6 @@ static void __intel_vgpu_release(struct intel_vgpu *vgpu) kvmgt_guest_exit(info); intel_vgpu_release_msi_eventfd_ctx(vgpu); - vfio_group_put_external_user(vdev->vfio_group); vdev->kvm = NULL; vgpu->handle = 0; From patchwork Tue Apr 12 15:53:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12810924 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C93C2C433EF for ; Tue, 12 Apr 2022 15:54:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A2A1310E725; Tue, 12 Apr 2022 15:53:44 +0000 (UTC) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2073.outbound.protection.outlook.com [40.107.93.73]) by gabe.freedesktop.org (Postfix) with ESMTPS id A042A10E69A; Tue, 12 Apr 2022 15:53:42 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=elbzJg7q52Yna75xhswCgx49AEOuLqVTRvsjHsLpY0iWLsmIonJiqjnyQyX+Qi8RTk+gk1UNZ4F/U1/8TwqC6BAt90BP3tIfJCaliG+HPQdwiMeMLCzndm8TvzHYqoUKqkBDuSvSHxJ9fofAMrEp01O9jZtE4R1J2F8Bb+CF8SrVBXpLaEW9UtSBG5i+FWjOIssl8s3jKosBgB7SQOHXDfxwBnjcn77/LzL8PjwpW9dS4kPdmRqfrzoeEV5KmBHc21lYl17C4wBiACUD69yI/TXfAzp4VvSWt9ui7/1oexCbilcErwAso+JenTsOFtE37Xw3mhSuyfcc9jkw70fSZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dUm89Wvcl/c0WqbqRLZLTxPH9jHz+NnwQfWw/QQQtr0=; b=bELek9ocGs1Ssx6sg6rz9q8EpACedsLAPqu0Jha1qboWTAHzYQPGhGS7xHZVgn9AsrELtQOyQ89zsanchLWGGHUDZoYsS0qhd0UdwcoJVg0+/SK3O+q2go9dlbedf7oVecLYlHt/Qs3zEyeA1UWZ4rNVmwi+XuNjhtlIDo2iOzD2loC8X8RHwTyBGM0pSZ+vS1GHvQFKy+LVJdIIzk0/eDfKt2fnTkUdvck4By83AZsQqq6HwDvQwCmTPtVgAfu73WJZL34UBfx3hHXG/KRdQPU5fVdVpiUn+gD19pfdZi7CmaFAc21pLAJCLOtXbW6T/mNd8UV5WX2D3CiOAckLhw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dUm89Wvcl/c0WqbqRLZLTxPH9jHz+NnwQfWw/QQQtr0=; b=fHHz/8H0b8exzrYmxcMsFEH7+7vymoyZduXUhBxegCNNX7rtehjKSPnPImcNNMo0vVUUa+D1QBq+YOu7+G74qyW0ivuyxxACeJr6pAyvVLgZRLGpdRwQIDKTKG2uKJkxiDKRP/o1fX2HupzUXPZJ24KFgE0lG03/AoHntJne+nDMedPxozmLYDtcXQVGagnFX5PHz6urjrDgGSykuWeyJIpSVuR/yGPVDE0F3im2wFKsUEdQJu8TtbS5VZoKXxbwLmeWBxCUhwMqs7/G0hyKNp4Ehp4WDrjNNnq3LS/WBaraL1Cs3WL8bVOFQ9y2irjv3+xxUqtlbFbriRkQtpJadw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) by DM6PR12MB4172.namprd12.prod.outlook.com (2603:10b6:5:212::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Tue, 12 Apr 2022 15:53:41 +0000 Received: from CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c911:71b5:78e6:3a38]) by CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c911:71b5:78e6:3a38%8]) with mapi id 15.20.5144.029; Tue, 12 Apr 2022 15:53:41 +0000 From: Jason Gunthorpe To: Alexander Gordeev , David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , Daniel Vetter , dri-devel@lists.freedesktop.org, Eric Farman , Harald Freudenberger , Vasily Gorbik , Heiko Carstens , intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, Jani Nikula , Jason Herne , Joonas Lahtinen , kvm@vger.kernel.org, Kirti Wankhede , linux-doc@vger.kernel.org, linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Sven Schnelle , Tvrtko Ursulin , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Date: Tue, 12 Apr 2022 12:53:35 -0300 Message-Id: <8-v1-a8faf768d202+125dd-vfio_mdev_no_group_jgg@nvidia.com> In-Reply-To: <0-v1-a8faf768d202+125dd-vfio_mdev_no_group_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0151.namprd13.prod.outlook.com (2603:10b6:208:2bd::6) To CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5ae43c12-059d-44d7-bf36-08da1c9c9cd0 X-MS-TrafficTypeDiagnostic: DM6PR12MB4172:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eIlfLsTm5EMgpAAuYEUh0h9ziOK4AkLMvaWatquwJ89511UBEw+ZtGv05J6MraDoUyL1/njivMI6fDxyNt9zSU40v+suKrGV2sVRGywnCrpAw2I2wUR9dWO+6u3t87qKnPDZc1KuyAHaqIzelDeXh38SBMPScUjDpfNQ6eM5umzdRazX0Kn8N7NX/42DDG0nlBpTkVx5vWygBAamnigyK8FOLj1jM6xJ5AVSrmJE+KPPKF5IMt9K+vyr1LIxOpbv8MZfNq0AVt3J564HWd91ey7t/ddQhcKxWoV9VUL+x8Q7LMFgxxVdfimjtIEWX9cDKjb7XZbge9+HoMqjU/1D8RPiaboQzd6FB35VREbwhB+QjZMzbKuXDkQJLOIpjvExmig4DAhVVrf7V9YJ5bTj3dkQLoP04ZloP9cQX4WhQZ4Ph+pZOsZvCi/kltrgVYBO7gVCt/yCiEXGdlyRGvp/fgN3LC5Uzv5Ax9m+pyUzgbqk3O5YhVDyeRV/SuuJDna91b19s6pw+WN78juub+zK7Xo51vj6n5XmheHMhpk9+08KabYqHXQXUgn5AiTpcqbsWPpkB78wTQuMaT1dJmaiwEQGhusEXOIixsqCh+NDI/Zf89rA3PT0XUhkwnulIHD0CI9onsJ0kwfJ0h+nRkgalYBi9L5UVDRAVv3irqdxGBUHVjoyfpT3gGyNPMCZ36rTMdu52lFh5ggUYFIp7e1r9g== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR12MB4181.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(508600001)(6486002)(6506007)(6666004)(66946007)(66476007)(4326008)(66556008)(26005)(186003)(36756003)(83380400001)(8676002)(316002)(54906003)(86362001)(8936002)(6512007)(2616005)(921005)(110136005)(7416002)(5660300002)(38100700002)(2906002)(7406005)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +l0mgVg4gB6ZBlcrh36n0FFm1QhYDS9e7QzU6iVzUhs4G8kxggO+w8voJ+vv/49lANs5OxVuSqrrm7EkwW/2P1MZ0b2KTjlgDW4EZYk7ol1NkAX0bfIprWqHSfOK+5ThNc7554qrjkIF2nVKwe6A3SU+uWJN0vM9Mx2dAsBbROTPd/bKtgiybgF9bOniVPVvVNhIHWfiITxKbVaGwmMwaJrgc/f0BVWsP7enxUsoDtuBH9wlao/hF5ud56kVDxrYq59ROgujb0VFlC2mKPMpqI/GkOhh99ZwF4GHcT2UH+KRPpAxss0cSuKyZwX5OSNlaEZbVnDzWg4ghpDMaNEB3nyvewiWy6jt6J+4blGqnD+bj2Ey98GX1XnK2wVRi8DV6PAdNpUM+fJ7WOlPh/b90iyZKMZWxSSgrVjstu7miyPcBEnJKmBSn1zL0Hr+A/NFnZRGt2fWJznWNHM5eNIMXMf+XlJWfwMC3WIPDozsrM+PGTGwXeupiLqv99UF1DIf0WPEzduTZHXecMyHo9c51S28G0QAehBUlOPqt7MUw1EJJ/OHlDjtBbkIBiU+eEo/sWxNnZ/aEKvnkJbs1uYE1fE2n2NmZiBu6Dev5+IE0s62S/G09eujOf9JtV30E2GACFc2yEliw2kpRrMBMOiE1ajN/b0R6EExakJnfCg6AvLQTqFV+/OD/kR2bGFUCSxv6afjMKYqGilfHVsT512QMlEpSWFPbKXfOu+HSUUptWxlTfyPFRBc/dgqFAlarWz1rwzukO3CkbtAzJ2MmbtVguUdADjyVXTl8NHkHK3cUKrp4azEWH8YZNa6xM3xc89mQyOUBUafufEyFk0Qc+O/BgTjhqtnsZJBZJ9Pc+gnWaLBESK14lkUxv7wJVhscs2UNK2crpcskfowIc7lEXpCh/HPdxvTft7gw/bItWOCg6tFncGJJlpHrHHr8kiiGZ7CW753Mzza5slbF1AaIwUJaShdmU0a8Q0BXXCSKbZKaV3iIYRXOyAuqLL6o5WuWbcscou08VSSFHWvgZ0+osbn6D96IqwWSDsNbD1HT4+9JMy6NQ+rN5vgeZ6Fj+wQvEJ7sva0cBHKSWfRSZxgJa6nAfwiZzoFB+0llSNkLqGDMEuPffBmae6XaX5fMh7613cTSE8Ml82oXWeejJaDsPoPlc4ZRCbkqhJtXwJH6xFShyO+ZARj46vhr2ZPKi5LZV0fBn5Ygpci6lxsO0fBS5U6L64henn1pht55n4nYtghVGdc63hWQVuzte+DrRkmiYXS6QsFpeUUdOI3LMyFEvlMVygfWUOPmNIarsHO3j2vr51dbQZ5k6Y9KIGcXvpGYfKkYmGuF2y+woe2TX/QuTe2U3th0fwRtVu+DAZj6XUCBdSzoYfqaQgSWio6tfdBgTfsRgcA/aQKy6PpSj/ovhGULMliX4BvlcytkT1mOIC5wK6zRRYIXwp+fg3EIlfmRFVi/0xyWbc+qAAVjqdE3LLRIzCUHwLqC4trWuixp5m5rxenYxncm92DZlmQD8uIehtIv+TWKQWPQLpf+Tm6wtoq7cmTStVV/sO7Y91dJXx4aN1gHkQFPL2pXJFlh7j+9BoH4ghuNT0FPkNGH9kStfvS2qL0Jk7cEaXs7x0b0qSQILguMRVGZYD1VPbMEFYgGfhywqPII6iAECk3wMgdzr0vNfliuDByH81jOv9rQfisFWW6oCWjdq+mZZN8qcmOf4JSWG/HbP0boJjEzzSfcxjUZA== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5ae43c12-059d-44d7-bf36-08da1c9c9cd0 X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4181.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2022 15:53:39.8998 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: sb3Nv8PIjwWiS4I/41ZHsZs6gQSBSKhnp2knfNRZaazSyjwY3WAtR+g0XH4ddk3W X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4172 Subject: [Intel-gfx] [PATCH 8/9] vfio: Remove dead code X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Liu, Yi L" , Christoph Hellwig Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Now that callers have been updated to use the vfio_device APIs the driver facing group interface is no longer used, delete it: - vfio_group_get_external_user_from_dev() - vfio_group_pin_pages() - vfio_group_unpin_pages() - vfio_group_iommu_domain() Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig --- drivers/vfio/vfio.c | 151 ------------------------------------------- include/linux/vfio.h | 11 ---- 2 files changed, 162 deletions(-) diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index e6e102e017623b..3d75505bf3cc26 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -1947,44 +1947,6 @@ struct vfio_group *vfio_group_get_external_user(struct file *filep) } EXPORT_SYMBOL_GPL(vfio_group_get_external_user); -/* - * External user API, exported by symbols to be linked dynamically. - * The external user passes in a device pointer - * to verify that: - * - A VFIO group is assiciated with the device; - * - IOMMU is set for the group. - * If both checks passed, vfio_group_get_external_user_from_dev() - * increments the container user counter to prevent the VFIO group - * from disposal before external user exits and returns the pointer - * to the VFIO group. - * - * When the external user finishes using the VFIO group, it calls - * vfio_group_put_external_user() to release the VFIO group and - * decrement the container user counter. - * - * @dev [in] : device - * Return error PTR or pointer to VFIO group. - */ - -struct vfio_group *vfio_group_get_external_user_from_dev(struct device *dev) -{ - struct vfio_group *group; - int ret; - - group = vfio_group_get_from_dev(dev); - if (!group) - return ERR_PTR(-ENODEV); - - ret = vfio_group_add_container_user(group); - if (ret) { - vfio_group_put(group); - return ERR_PTR(ret); - } - - return group; -} -EXPORT_SYMBOL_GPL(vfio_group_get_external_user_from_dev); - void vfio_group_put_external_user(struct vfio_group *group) { vfio_group_try_dissolve_container(group); @@ -2218,101 +2180,6 @@ int vfio_unpin_pages(struct vfio_device *vdev, unsigned long *user_pfn, } EXPORT_SYMBOL(vfio_unpin_pages); -/* - * Pin a set of guest IOVA PFNs and return their associated host PFNs for a - * VFIO group. - * - * The caller needs to call vfio_group_get_external_user() or - * vfio_group_get_external_user_from_dev() prior to calling this interface, - * so as to prevent the VFIO group from disposal in the middle of the call. - * But it can keep the reference to the VFIO group for several calls into - * this interface. - * After finishing using of the VFIO group, the caller needs to release the - * VFIO group by calling vfio_group_put_external_user(). - * - * @group [in] : VFIO group - * @user_iova_pfn [in] : array of user/guest IOVA PFNs to be pinned. - * @npage [in] : count of elements in user_iova_pfn array. - * This count should not be greater - * VFIO_PIN_PAGES_MAX_ENTRIES. - * @prot [in] : protection flags - * @phys_pfn [out] : array of host PFNs - * Return error or number of pages pinned. - */ -int vfio_group_pin_pages(struct vfio_group *group, - unsigned long *user_iova_pfn, int npage, - int prot, unsigned long *phys_pfn) -{ - struct vfio_container *container; - struct vfio_iommu_driver *driver; - int ret; - - if (!group || !user_iova_pfn || !phys_pfn || !npage) - return -EINVAL; - - if (group->dev_counter > 1) - return -EINVAL; - - if (npage > VFIO_PIN_PAGES_MAX_ENTRIES) - return -E2BIG; - - container = group->container; - driver = container->iommu_driver; - if (likely(driver && driver->ops->pin_pages)) - ret = driver->ops->pin_pages(container->iommu_data, - group->iommu_group, user_iova_pfn, - npage, prot, phys_pfn); - else - ret = -ENOTTY; - - return ret; -} -EXPORT_SYMBOL(vfio_group_pin_pages); - -/* - * Unpin a set of guest IOVA PFNs for a VFIO group. - * - * The caller needs to call vfio_group_get_external_user() or - * vfio_group_get_external_user_from_dev() prior to calling this interface, - * so as to prevent the VFIO group from disposal in the middle of the call. - * But it can keep the reference to the VFIO group for several calls into - * this interface. - * After finishing using of the VFIO group, the caller needs to release the - * VFIO group by calling vfio_group_put_external_user(). - * - * @group [in] : vfio group - * @user_iova_pfn [in] : array of user/guest IOVA PFNs to be unpinned. - * @npage [in] : count of elements in user_iova_pfn array. - * This count should not be greater than - * VFIO_PIN_PAGES_MAX_ENTRIES. - * Return error or number of pages unpinned. - */ -int vfio_group_unpin_pages(struct vfio_group *group, - unsigned long *user_iova_pfn, int npage) -{ - struct vfio_container *container; - struct vfio_iommu_driver *driver; - int ret; - - if (!group || !user_iova_pfn || !npage) - return -EINVAL; - - if (npage > VFIO_PIN_PAGES_MAX_ENTRIES) - return -E2BIG; - - container = group->container; - driver = container->iommu_driver; - if (likely(driver && driver->ops->unpin_pages)) - ret = driver->ops->unpin_pages(container->iommu_data, - user_iova_pfn, npage); - else - ret = -ENOTTY; - - return ret; -} -EXPORT_SYMBOL(vfio_group_unpin_pages); - - /* * This interface allows the CPUs to perform some sort of virtual DMA on * behalf of the device. @@ -2515,24 +2382,6 @@ int vfio_unregister_notifier(struct vfio_device *dev, } EXPORT_SYMBOL(vfio_unregister_notifier); -struct iommu_domain *vfio_group_iommu_domain(struct vfio_group *group) -{ - struct vfio_container *container; - struct vfio_iommu_driver *driver; - - if (!group) - return ERR_PTR(-EINVAL); - - container = group->container; - driver = container->iommu_driver; - if (likely(driver && driver->ops->group_iommu_domain)) - return driver->ops->group_iommu_domain(container->iommu_data, - group->iommu_group); - - return ERR_PTR(-ENOTTY); -} -EXPORT_SYMBOL_GPL(vfio_group_iommu_domain); - /* * Module/class support */ diff --git a/include/linux/vfio.h b/include/linux/vfio.h index 91d46e532ca104..9a9981c2622896 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -140,8 +140,6 @@ int vfio_mig_get_next_state(struct vfio_device *device, */ extern struct vfio_group *vfio_group_get_external_user(struct file *filep); extern void vfio_group_put_external_user(struct vfio_group *group); -extern struct vfio_group *vfio_group_get_external_user_from_dev(struct device - *dev); extern bool vfio_external_group_match_file(struct vfio_group *group, struct file *filep); extern int vfio_external_user_iommu_id(struct vfio_group *group); @@ -154,18 +152,9 @@ extern int vfio_pin_pages(struct vfio_device *vdev, unsigned long *user_pfn, int npage, int prot, unsigned long *phys_pfn); extern int vfio_unpin_pages(struct vfio_device *vdev, unsigned long *user_pfn, int npage); - -extern int vfio_group_pin_pages(struct vfio_group *group, - unsigned long *user_iova_pfn, int npage, - int prot, unsigned long *phys_pfn); -extern int vfio_group_unpin_pages(struct vfio_group *group, - unsigned long *user_iova_pfn, int npage); - extern int vfio_dma_rw(struct vfio_device *vdev, dma_addr_t user_iova, void *data, size_t len, bool write); -extern struct iommu_domain *vfio_group_iommu_domain(struct vfio_group *group); - /* each type has independent events */ enum vfio_notify_type { VFIO_IOMMU_NOTIFY = 0, From patchwork Tue Apr 12 15:53:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12810923 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F2B01C433F5 for ; Tue, 12 Apr 2022 15:54:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2E1DC10E708; Tue, 12 Apr 2022 15:53:44 +0000 (UTC) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2077.outbound.protection.outlook.com [40.107.93.77]) by gabe.freedesktop.org (Postfix) with ESMTPS id D83B510E37F; Tue, 12 Apr 2022 15:53:40 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YY9zcyssM3PwfIdYdogYTRn5fIgnwaXb60ylq8YG2jzhzk+g7d8oNhN8BJ/gqytGLtUBJd4bnM1nqa2XtMq1c59CSJ71DP4pGGQRjT9y4aOLCXuaB8EucppRQE3IJ0rDMiIgw2XLGazZwFZciV9D3XfcC0Spdq2b8LLMpcenYY3r9lOUTI6p7P0Bsyhu4pL1/9veg4jrC2G68QhuS8F8AN+NOsyFPNhyEOoD0S2OpPpoHisHO9hCoA2//lebdd3vtk9UohkPCFor1oyYapvc2S1ETgjOc1Nbx+lmMyehU3mzLQnyWsYQKu42m4DH4QxyepZVTAz9Z2GDvie98SK0iA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pL6fMmsy3sjaZPRWSMFgOEgjLTB+AnOQW85MOhaJYWU=; b=nRvH6/mII8p4TLT0Aql9BrC55BtEj/3NsT314/rf4Pzj88olYLHJvKCtWTRPoZrnwWOqUFcFNBVe0ssOWul510fCXTZ32VI3mEFfRNkJpuep38gA+HgafdmzyqI2nS53WuKXlpPROnkCtRGNK1FTjBb+FhL3G8gqQOYdKF0rbiq6YJ/DmGZjNScxdv6bwkDAPZ7GoGRgk6+hEG14U7mJjQoSUQrLUyZJ9zLDRvaFEU2AXZutlf33GsruGmK63sYVuaV26lhSJx9gdX8f7HzPK67cdycJC6xk9sZIIvZxLyR44zLcSxqb8ax7qDRDwwt3h14E5LX2uJ60Mk9CxPu10g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pL6fMmsy3sjaZPRWSMFgOEgjLTB+AnOQW85MOhaJYWU=; b=AFLwff/K+WGG2QPO8ZqJ+BfWpvlPt+84S+m1jzm6TM1YtLw/nmFD637+zWeW41K45ItlLNDOCbgBHThpR++RfrtbcoSIuBhFcZGk6pTS7Sk2H9vWunPaNcEZld/ZoOZ7Q0R6uQddwzfyRwu4kMFikNDfAsU91TFBiJwYlYH5GB3Omwxl6haqRTaEImM39lhQu1H6NqwTul9gZFj7PsxavqcyZ1HfEpR1jidFIlp1UZYfw5V27K9NLuVTOk6r7jYwmKm6Lb7lGpe4BsT8V6IIrOXGxKH7iPLtpWpgeUVTM7SfoqzMOB3FKOdjDAWOv89b9TDgI409t+YuryZf1usnnQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) by DM6PR12MB4172.namprd12.prod.outlook.com (2603:10b6:5:212::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Tue, 12 Apr 2022 15:53:39 +0000 Received: from CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c911:71b5:78e6:3a38]) by CH2PR12MB4181.namprd12.prod.outlook.com ([fe80::c911:71b5:78e6:3a38%8]) with mapi id 15.20.5144.029; Tue, 12 Apr 2022 15:53:39 +0000 From: Jason Gunthorpe To: Alexander Gordeev , David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , Daniel Vetter , dri-devel@lists.freedesktop.org, Eric Farman , Harald Freudenberger , Vasily Gorbik , Heiko Carstens , intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, Jani Nikula , Jason Herne , Joonas Lahtinen , kvm@vger.kernel.org, Kirti Wankhede , linux-doc@vger.kernel.org, linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Sven Schnelle , Tvrtko Ursulin , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Date: Tue, 12 Apr 2022 12:53:36 -0300 Message-Id: <9-v1-a8faf768d202+125dd-vfio_mdev_no_group_jgg@nvidia.com> In-Reply-To: <0-v1-a8faf768d202+125dd-vfio_mdev_no_group_jgg@nvidia.com> References: X-ClientProxiedBy: BLAPR03CA0132.namprd03.prod.outlook.com (2603:10b6:208:32e::17) To CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: adaa8adb-2860-4c57-f709-08da1c9c9c1d X-MS-TrafficTypeDiagnostic: DM6PR12MB4172:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sC43+zzKfIVxLbRhIEbF+OsW2Yb6wtlm4oKcbylG5oVe3A1Nt+YoqUKO10qYEmXb5FuaDWJvgf8LIQSHq5CA4ziG+iXcFwAk3cMdzsk4aU2Wk3s3QnoMTT00cbUf5VdSpiyNWcmTAYo6nduuVDu0yevimzm57y0qq4VBVFQ3hRtQ3oeIw5PJYMtPLfNhsbnAWCdHgSYiX819i5e9KAfHvTXQQv/szD4VzvismnZ2PKPq0dWjK1A1nHbUbJni77iStAHq1OHcHLY+6SS/W8sDV0bYlHhquZ3sHrFd5//wqu8T1+TdjxK+16lv+UYae2jX5Ni8qmMqk3c/L7bXQMnP6aVDgNzofZyIjOdM3iGIuKonLcBxUC9B3KSzEHwuIyBcTVQVzaFuA2Q0uTpVyEEHerbomF2PrpomUhoQ2tZ1ih2ktaDjTfm9RM8jpzDM5UdfUTG31CPD5/Ud1oLFkApgxxDlGkhuH+ub8Z52FN5zAPq64B955XCfACd9kHzC5ZllGYNqOu/OtNAqvY2PzCTBXoot33UXtdTvlW1m4QKg6yBQ1gp68kgkoX6ML6LhIWKGAC/RqqhhH7EyMszDmhd9Y7YwoCncsZM/gUKpZFg0yds3J5HRKEmzb+170UTDiImT89TlvyuuJK0+xgs6BLK/zlCLiToMfdXrGNmeAbTUyRd1/jnSmJRRdxwlP4Se8lHrxh4mkk8ru7p4JfpmFIA+DA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR12MB4181.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(508600001)(6486002)(6506007)(6666004)(66946007)(66476007)(4326008)(66556008)(26005)(186003)(36756003)(83380400001)(8676002)(316002)(54906003)(86362001)(8936002)(6512007)(2616005)(921005)(110136005)(7416002)(5660300002)(38100700002)(2906002)(7406005)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: eWXmhOGX7sQUzgq5DYvFOHFc9HL3WGG9FlOIWFQp/F7GXODhKYyCBK0c6VM0P//0+NSGg6D+QJSQlBN05jzptloikpGnWiahQ2TPAoesuXxQv9pI4RsvQvEcB3OiKeA41xlP5VQ9ucPZNduU4SaR6t4EXP5MuKcRRPzkxpION9v5tAS9WHd8qOnnDZFed80hFPFQfD45MngJ4kQfqMWIOGxkhaPackUp1Z4/AWcnLZ0xDpRudb4864YQTGXMML6IG0U+DYGKuTHgOprI/2Um9Z23c0G7ethBGKzWfSfiVTTHXiBf5kQtoDQ6LdUjubFHEziAQuU5NY3YukzmGiZxid/s9J+XmyEiryiT3/gGNlXgYkcNNGG/xsjlOWNr6cUKlKxGbU4MROdq8+QbuW11t6B0x35TwaWxbgy76W/N37Ql/gUeqwFCfwZDDB6L2wrZdL7TWb3k9PugVpvt3MuKW52VSS/kpJudLYognTLov63gT5YwBgWRhw0bIaQ4B4pTz/f/YQO5Citve25PVBMiV94Qbqojv/nC2oICphqfKZqdcRMJgRsCmSfUxc2pHbJL0v/rVW5FcGlCx+DEdrIRlZtTc5woofJ+JfXZMbckta7wGFJzjQGocQPzqCN3oh/ajNoMKxLGEc/cy1C+KC2ofhnkr7i+Kn5msicOLTcvPCIk/ncatchm/vYnS8fGB8PMA0evDXNuD37U3zWVsaWKxF1NNwO6rDmpRaIZoel0MSlvJRXQkAF9WwdTzafpAwS7iiexX9Hdg8dYXdf2Lehz0VwwCT2qXOqeKHVV7YVaSjfPocJCJSUT/jvxDTpkSHQFfderrQjOI7ILKh5ouk8uhz/1W43H5Y5zNlk2hIT/nnqkC8PWAO+R249EIc8wOPckmG76+CbtCazxbq8t3UlqVqF5WFxS/JId/wnBSIF2A9oS2jfHWhbM6pKCj+1YG4VMvH75Pnb4TyzF00tDAdOqg23WuBPHLdD6buGp3KgY/WEFdwNyuSS+bPFyBwK0uBbRvJyacrVpyRvsytymGdzdI7KDnOBDulzvAaaPX07KEal1M3MJhr2WhbIrNxv82extd4aO79usoBcNilKjq/YY7jFZ/eFdu4nDVlfnpMY3QlW+Giz9gLsWjGhUMmyPCDaSbjr+0X/qSYFT2Qolh5aZitajz0vDv5sC/c8AwCTF2NM+RQmgzPbYxiirF7zwsWbJV+THCAdv7AE9NW2n7dCuTMkuDwRJzaTZy0dxgeBv/2e4l660C0GzlCB7MjRuTsAmW5oFuphs3ceCQf+sQUwXRFUGuqLXCwB7KOFJE2MWAVqyCb1Korr9zE2mTxjGCaoqEeu4KaLencj7ROmmW9NNvhaIjncCRglyyg47gph/8GnnRHiCUyAzBTkB03/B+EHKMbXyKO06wBqTzAALdazGvuMv8Z5PZ2Znx5680uJVw1pVW+OwO5bQTA6d+7IBCb94YdBiZkjo2MfKSy97uulZveIFXX/Y9bH52FhbEQ09is9fc8tMaxju3jDLh1lf182WuI74+7/jxQHY34Zr92LbCYV0MH3RBjoztrPkKv8wVStxexgFlrC8Yu4Ci2fdvNAFLt4oruqIGxqpM533JZNd0+ZORXTCXqVkPiyLdLcmUHnpXR9EpaC/RVF3UfL4yTbyvSN/45gC/VdNhM4ZXgju9Qgg0qb85TG6E9lRTb1UATKT9pa386qPtlrq0joLuaxo/2D7ktxD35dgREPLpsjXGQ== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: adaa8adb-2860-4c57-f709-08da1c9c9c1d X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB4181.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2022 15:53:38.7281 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: h6t5RNUhDQezu6Efm9GKlNGtZuKdLzzba4TDw0wrw376aZke9dJQ5mtNvC+Q8g1i X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4172 Subject: [Intel-gfx] [PATCH 9/9] vfio: Remove calls to vfio_group_add_container_user() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Liu, Yi L" , Christoph Hellwig Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" When the open_device() op is called the container_users is incremented and held incremented until close_device(). Thus, so long as drivers call functions within their open_device()/close_device() region they do not need to worry about the container_users. These functions can all only be called between open_device()/close_device(): vfio_pin_pages() vfio_unpin_pages() vfio_dma_rw() vfio_register_notifier() vfio_unregister_notifier() So eliminate the calls to vfio_group_add_container_user() and add a simple WARN_ON to detect mis-use by drivers. Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig Reviewed-by: Christoph Hellwig --- drivers/vfio/vfio.c | 67 +++++++++------------------------------------ 1 file changed, 13 insertions(+), 54 deletions(-) diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index 3d75505bf3cc26..ab0c3f5635905c 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -2121,9 +2121,8 @@ int vfio_pin_pages(struct vfio_device *vdev, unsigned long *user_pfn, int npage, if (group->dev_counter > 1) return -EINVAL; - ret = vfio_group_add_container_user(group); - if (ret) - return ret; + if (WARN_ON(!READ_ONCE(vdev->open_count))) + return -EINVAL; container = group->container; driver = container->iommu_driver; @@ -2134,8 +2133,6 @@ int vfio_pin_pages(struct vfio_device *vdev, unsigned long *user_pfn, int npage, else ret = -ENOTTY; - vfio_group_try_dissolve_container(group); - return ret; } EXPORT_SYMBOL(vfio_pin_pages); @@ -2162,9 +2159,8 @@ int vfio_unpin_pages(struct vfio_device *vdev, unsigned long *user_pfn, if (npage > VFIO_PIN_PAGES_MAX_ENTRIES) return -E2BIG; - ret = vfio_group_add_container_user(vdev->group); - if (ret) - return ret; + if (WARN_ON(!READ_ONCE(vdev->open_count))) + return -EINVAL; container = vdev->group->container; driver = container->iommu_driver; @@ -2174,8 +2170,6 @@ int vfio_unpin_pages(struct vfio_device *vdev, unsigned long *user_pfn, else ret = -ENOTTY; - vfio_group_try_dissolve_container(vdev->group); - return ret; } EXPORT_SYMBOL(vfio_unpin_pages); @@ -2207,9 +2201,8 @@ int vfio_dma_rw(struct vfio_device *vdev, dma_addr_t user_iova, if (!data || len <= 0) return -EINVAL; - ret = vfio_group_add_container_user(vdev->group); - if (ret) - return ret; + if (WARN_ON(!READ_ONCE(vdev->open_count))) + return -EINVAL; container = vdev->group->container; driver = container->iommu_driver; @@ -2219,9 +2212,6 @@ int vfio_dma_rw(struct vfio_device *vdev, dma_addr_t user_iova, user_iova, data, len, write); else ret = -ENOTTY; - - vfio_group_try_dissolve_container(vdev->group); - return ret; } EXPORT_SYMBOL(vfio_dma_rw); @@ -2234,10 +2224,6 @@ static int vfio_register_iommu_notifier(struct vfio_group *group, struct vfio_iommu_driver *driver; int ret; - ret = vfio_group_add_container_user(group); - if (ret) - return -EINVAL; - container = group->container; driver = container->iommu_driver; if (likely(driver && driver->ops->register_notifier)) @@ -2245,9 +2231,6 @@ static int vfio_register_iommu_notifier(struct vfio_group *group, events, nb); else ret = -ENOTTY; - - vfio_group_try_dissolve_container(group); - return ret; } @@ -2258,10 +2241,6 @@ static int vfio_unregister_iommu_notifier(struct vfio_group *group, struct vfio_iommu_driver *driver; int ret; - ret = vfio_group_add_container_user(group); - if (ret) - return -EINVAL; - container = group->container; driver = container->iommu_driver; if (likely(driver && driver->ops->unregister_notifier)) @@ -2269,9 +2248,6 @@ static int vfio_unregister_iommu_notifier(struct vfio_group *group, nb); else ret = -ENOTTY; - - vfio_group_try_dissolve_container(group); - return ret; } @@ -2300,10 +2276,6 @@ static int vfio_register_group_notifier(struct vfio_group *group, if (*events) return -EINVAL; - ret = vfio_group_add_container_user(group); - if (ret) - return -EINVAL; - ret = blocking_notifier_chain_register(&group->notifier, nb); /* @@ -2313,25 +2285,6 @@ static int vfio_register_group_notifier(struct vfio_group *group, if (!ret && set_kvm && group->kvm) blocking_notifier_call_chain(&group->notifier, VFIO_GROUP_NOTIFY_SET_KVM, group->kvm); - - vfio_group_try_dissolve_container(group); - - return ret; -} - -static int vfio_unregister_group_notifier(struct vfio_group *group, - struct notifier_block *nb) -{ - int ret; - - ret = vfio_group_add_container_user(group); - if (ret) - return -EINVAL; - - ret = blocking_notifier_chain_unregister(&group->notifier, nb); - - vfio_group_try_dissolve_container(group); - return ret; } @@ -2344,6 +2297,9 @@ int vfio_register_notifier(struct vfio_device *dev, enum vfio_notify_type type, if (!nb || !events || (*events == 0)) return -EINVAL; + if (WARN_ON(!READ_ONCE(dev->open_count))) + return -EINVAL; + switch (type) { case VFIO_IOMMU_NOTIFY: ret = vfio_register_iommu_notifier(group, events, nb); @@ -2368,12 +2324,15 @@ int vfio_unregister_notifier(struct vfio_device *dev, if (!nb) return -EINVAL; + if (WARN_ON(!READ_ONCE(dev->open_count))) + return -EINVAL; + switch (type) { case VFIO_IOMMU_NOTIFY: ret = vfio_unregister_iommu_notifier(group, nb); break; case VFIO_GROUP_NOTIFY: - ret = vfio_unregister_group_notifier(group, nb); + ret = blocking_notifier_chain_unregister(&group->notifier, nb); break; default: ret = -EINVAL;