From patchwork Thu Jul 15 00:20:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12378149 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1D1EC1B08C for ; Thu, 15 Jul 2021 00:20:49 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 73A2F613C2 for ; Thu, 15 Jul 2021 00:20:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 73A2F613C2 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8B02F6E4F4; Thu, 15 Jul 2021 00:20:48 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2070.outbound.protection.outlook.com [40.107.94.70]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2A77E6E4EC; Thu, 15 Jul 2021 00:20:47 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KXbQap2NCDvolvcGLZynkAOKh5Np55oArsqu4xXdsfe2hy9PPs0C3ApgDZgJ4ixEPIEwBU4+KRBgglgaj66icMNt6CJQJYsRVb1tKYVOq06FQOpmffeMEZ/PgSNFkZCUPPuNaiaI737oGciyLEHGQZzvHEMDJ7sycYgQcRGrLCV+aO50jmzUFYWiTUR9A14CPI8jugLoa0oH30FIThfooKfr1IJGhix/YmScz6cPr+SwE2Uqcuxu5+lpEEkruqHCocs7/3/WtHX385aq46aCvB6HODLvg0ZJ7timhwitKf+cPjBQM8mtXYX7Xqdd3BpxG+ciyP46P8quO18HeJUH4Q== 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-SenderADCheck; bh=UAymuJm+QAd3Drot5Ks5S5cKvfiu78o9bP2liwNXxHQ=; b=dZhXfK90C7oO716+kchJ95zxG7Or6y22Kw++e597N8Lv6WTlSM95TQNRsS/HT9KUJvdy8+8wC0jw/hwnB7RJNrhH1ct40ChppEm7TKhXF1aEEiWSGixtuI54Fed3hzhkfvAr1IFPs3gSfjm8m8zoNBIC4XF86XXPcqyK4Iy/DCT+fShT2oD2S3Gb61fxuWESQ76Z5zs0Ktd8dgJrFkzG2DZpyxWqFUhgxwoD9XVtL2ybCCq3IVYrhI17q5Ck4/AmZ1/FJg8VdQhii8rRrVe2lg4GN3s0sMWjfdy4bCHMCNLMzq5C3yhw2PELUUsIow0eqGbUQrZo0G//upk+9q7ovg== 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=UAymuJm+QAd3Drot5Ks5S5cKvfiu78o9bP2liwNXxHQ=; b=CtZcCbTGllqWnGFyWm6NSs3npGW94lE+Aq5UqxQqW1+MJpshGfdRoVGuPxW4RdmAdSEHMg/7zvk7q6jSdeBr2a1PE5SoU4sAvfgwdvd79umAep0qAhUBM8y4H2IK5vgoRtFcP1v9w9MjitTTEl8OumnUFmCgUP0Yksv2g4o73cl8jcv57/8kaDsnZSP/f2IOcZOdz75hOaPJrd11PyJxi3nfmtEBYhCMRz/QvYEiLVWW4W1ATNmZxr/dyqsrUop8G/BtfokVO6Nk2ytOTBQBAmD+LdjwCSR84dOR/Y6icObXQR+ohQvubZI2sjrvDxwPNf5MD0BpiuzTox2vN+WijQ== Authentication-Results: linux.ie; dkim=none (message not signed) header.d=none;linux.ie; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL1PR12MB5334.namprd12.prod.outlook.com (2603:10b6:208:31d::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.20; Thu, 15 Jul 2021 00:20:45 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482%5]) with mapi id 15.20.4331.021; Thu, 15 Jul 2021 00:20:44 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , Daniel Vetter , Diana Craciun , dri-devel@lists.freedesktop.org, Eric Auger , 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 , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Date: Wed, 14 Jul 2021 21:20:30 -0300 Message-Id: <1-v1-eaf3ccbba33c+1add0-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v1-eaf3ccbba33c+1add0-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: CH2PR08CA0026.namprd08.prod.outlook.com (2603:10b6:610:5a::36) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by CH2PR08CA0026.namprd08.prod.outlook.com (2603:10b6:610:5a::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Thu, 15 Jul 2021 00:20:43 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m3p7K-002Ux7-Bv; Wed, 14 Jul 2021 21:20:42 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0bb048a2-d0e7-4cb1-85a6-08d94726627f X-MS-TrafficTypeDiagnostic: BL1PR12MB5334: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WcKwzDdvpL8v+yjXSepjfAwgEQFZfH+Ngd33SL0S2ZF2d909hXc7FT93LVDx+9mmdnGNTTxMzpu9q+RHshxuy7fpiyO5ia3Las6ikAxyNKDHYjPKARCrQiq6ImYVyvoczSPVTV8kW1c7Mjh5TS+RYfgrsrHpWAkJRqSYapWRRu46Ske7ylHPW5onCm0spvbd/MEzYp9rKJcLWeKW04LI1W/zRQVi84tiAg3wcrpC4oCgXjLTu8bYQKi0o8ld33sqVh1fVmqLeawULTNoqvAqeKWKflDjrQ9eI2QPQgOxbeNO85JxWxzaWno+saoPmi+B67izw1RewT6QM0OHnM3itk42kUEL0qduhJDg4F6+ijWeEV6rsN09d15Up0q/Xlr7KTOheiUZqCa2o7sosm5MMv1JVLqTQREclJK4q6xMgknINGISdySc6bpc8ivkXouadKujgae9RfL5+oWW0LpdyjOdhHm9yF/Lf+6Rxb+NaZspuTqNif63WXXlFyuU2q3ienbF4ovYj5zkvWaSmYle/YTWqNPStMwm+T0DY/a8gv36amzdYIZgqZgjUY7+urCrTpnARZtmlgBlbccG7iLH6O7elnY/djllQjpfskGvqOn8fxAhLHqC6nsVYNE4DFBPAYaJ6HgUNdMRtVNvG+HJFDvMw38Ea/8l4M+6ULhOi4xCJvcuQiOZRxxzEUKUCtJXBsO6F/Q6TVCnhIqagdYpFQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL0PR12MB5506.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(366004)(376002)(396003)(346002)(39860400002)(107886003)(86362001)(66556008)(66476007)(54906003)(5660300002)(36756003)(2906002)(26005)(6666004)(4326008)(7416002)(9746002)(426003)(9786002)(186003)(66946007)(110136005)(2616005)(316002)(7406005)(83380400001)(8936002)(38100700002)(921005)(8676002)(478600001)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xAdi3WD9B+DoG/HTFQ+MihmFAOVKAP3XZe5zBhgj+/QgwZOq6QOVTB25OrBr3GmJ1Z2LFHloKkTQTL6n/mwyOKfVxBz08pPyIMgYTOOE/UfBoFhr55zePSb2CSdoVUvp9N4oLk8GyvW1PpNQMwRuP2dzfahiXe47/b0ib+wFme5GHfqRzPvcJDJFeQ7yGsEHKxc0gslZh883aaI8ewL+Y1Rr6IfWtM7kZ9W5sEU0oQGLgjWzA/NLiOCIL5gO1MAvltJqzKergXVfz4CPYEGiVTkH1sZnNwgF75PU8YRSH3qW6CG8ZTDPvFvXHmg9cDFsE/HAuC/YChH02KvY16zz7PdUy+cZKCU3QSU0+ZAS8HPLkxgdEcbB6R+8+ouNSPdg1vIELzIMvCXXUABTclVIWP5OS47t3/US7jdSSChHi84/akZIsqGZGv4kZh3OPFANkQr2jC/cNvdisgaXyGjzPDAE03QZavDkDdTYU3nuzFg4/VdSTzQzJCrMr4+HIvoTnMlt/6ohEYML9Suh/mdQZ/UrLj5nDCLlDeu+XG2DR9pYEX6NPIjMbUvXgPhUkjNxoAqBgAVnn/sgJAZGEPeyptMxsrqiyVeAqK98/bHMIhR9Vy3ex/NCZRprATvNlCpqXxEr28s8AgTud1hiUZEHLa6Ah1QA4O0rYPbSMOtFOYv4C0E7x8L1SG31MHHGQM386c6ZwuwQ3Eyc1aLcekuw/HKILj+d4PCvUiW4XoHIUgNDWt0RnmYx21mxzP6nVRkztqZt7SieUav2FH3LHD+Rp/ktIVO9BGors11Z9ebwkuPa6EPnrR93E3BrrnbBn0+Y7pk23FPSAsBdIC7s/lkdoFWZW053eedqxXfNmT/MJyl6VYZUzfFqKf92eecm9eDcJl2JZ5RvtHReH45yG8ESwUXkLOojjq5ci4XaX/Nu/FPybmmiFB6nGcYuii5bYpCuIPu10HLE4pagPSzsdnoQSrOmg6ilAnDW+oJ07EDRxorGyg/MmiLYYZP0iLK69b8QjR5nN1ymgI2sh7slZI5b+iylBC7bY3dVfTYhwT/cRAjuFi/sg6FQhoichT/KMyNX4vyO5D+wnTONOSnzdBWaSeLINmm9MeuS1HNHnSDZufL6k+1di6y/90VGUfw8P54Kcai9xNm0zrS3keCL0OBpHX0W7aKXzhK1oSNie7xtsPfjL79ZcfgPA23e4E0wD68DRr7gmRbb8ncBC31TIf0oysjawN1mHOYIhaAi8yanFiEAfq41f5Ip1U38S/hzo8kEBZTANmQWaxe4i/cCwXsvCX5K+xNew1B5AXqMFbdw6cO2FNTa6dBfswScKBcAxmRJ X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0bb048a2-d0e7-4cb1-85a6-08d94726627f X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2021 00:20:43.8361 (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: 58+IiegTQZXKp3Ar1SrFzsyUmelvPnHBXCDqQ7lj15IyhqW/qb5vXs95g/YcEOak X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5334 Subject: [Intel-gfx] [PATCH 01/13] vfio/samples: Remove module get/put 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: Max Gurtovoy , Yishai Hadas , Leon Romanovsky , "Raj, Ashok" , Christoph Hellwig Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" The patch to move the get/put to core and the patch to convert the samples to use vfio_device crossed in a way that this was missed. When both patches are together the samples do not need their own get/put. Fixes: 437e41368c01 ("vfio/mdpy: Convert to use vfio_register_group_dev()") Fixes: 681c1615f891 ("vfio/mbochs: Convert to use vfio_register_group_dev()") Signed-off-by: Jason Gunthorpe Reviewed-by: Cornelia Huck --- samples/vfio-mdev/mbochs.c | 4 ---- samples/vfio-mdev/mdpy.c | 4 ---- 2 files changed, 8 deletions(-) diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c index 6c0f229db36a1a..e81b875b4d87b4 100644 --- a/samples/vfio-mdev/mbochs.c +++ b/samples/vfio-mdev/mbochs.c @@ -1274,9 +1274,6 @@ static long mbochs_ioctl(struct vfio_device *vdev, unsigned int cmd, static int mbochs_open(struct vfio_device *vdev) { - if (!try_module_get(THIS_MODULE)) - return -ENODEV; - return 0; } @@ -1300,7 +1297,6 @@ static void mbochs_close(struct vfio_device *vdev) mbochs_put_pages(mdev_state); mutex_unlock(&mdev_state->ops_lock); - module_put(THIS_MODULE); } static ssize_t diff --git a/samples/vfio-mdev/mdpy.c b/samples/vfio-mdev/mdpy.c index 393c9df6f6a010..a7d4ed28d66411 100644 --- a/samples/vfio-mdev/mdpy.c +++ b/samples/vfio-mdev/mdpy.c @@ -611,15 +611,11 @@ static long mdpy_ioctl(struct vfio_device *vdev, unsigned int cmd, static int mdpy_open(struct vfio_device *vdev) { - if (!try_module_get(THIS_MODULE)) - return -ENODEV; - return 0; } static void mdpy_close(struct vfio_device *vdev) { - module_put(THIS_MODULE); } static ssize_t From patchwork Thu Jul 15 00:20:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12378151 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98368C47E5F for ; Thu, 15 Jul 2021 00:20:58 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 62675613C2 for ; Thu, 15 Jul 2021 00:20:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 62675613C2 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 74E956E511; Thu, 15 Jul 2021 00:20:49 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2070.outbound.protection.outlook.com [40.107.94.70]) by gabe.freedesktop.org (Postfix) with ESMTPS id 74AD76E4EC; Thu, 15 Jul 2021 00:20:47 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TMYgFfXEsJAkdfVlwczHXtNYmLVRVUKObyk7FVzuhuGJtJr6nIzlxWsX1n886oyPRCDbfkImGBVAciDCYzdV5UjX3I4JOlX2MbatSZJ2JwNTQ9tBHdmgPCeGEgQU7GHm4IEBlFZ1DeDO6bwJ2TAPPsg1856mBP6YNHav7nBpiTiRW40ba1hvGu1lDgpPHPu6nNWQwRLxnluphVU37HTvh4uyVwiglVWL6862SzxiG29Q/R1+8TURU6H7BKDuOv4b/Mv2ex8DcGfFI0KuvlvTxjZTy9oFw3VIVb/9mRSIcCWMQWpCz19j+atGQIIGXnoMYU4CIkGnQesrzaH64a0A3w== 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-SenderADCheck; bh=y58XH6B5leRrAkCjhNRFq2+KjJytKzlisU2xTX3BnkE=; b=BXfK2rTqpBfruWUAsyxbU4y+Ai7Y8ZUhADCgE+3D0DWV3lWBwxSXjIDMp0kkA2KVaPYbxRhIURjFFFS3qiuRJzrO+SQOW/8NqcQHjhtC2WY3pPAtTD/B31Wf73liTMT6pfALLrm6jrZPsHRGZrZzZE64gDDvnzZz1MnCjEYKpHu4JaMWxnJZFkiFo7gvYoR7O6AXMb9UuXeoaHIrW1OVBoOuI852xyJj1XwDgxUt3b7lk6bYk44BkYxy1NOjua+i8HZVim+5TPcUDf3L1GLZIHEu8dt3UdK0H0us/SvcdfqHfAS7g5W5YviG+8qyf9Kn03QEPHwTo78UtOGHQqkYsA== 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=y58XH6B5leRrAkCjhNRFq2+KjJytKzlisU2xTX3BnkE=; b=ZpCEBQAlbFFro3CypyAMDxJnVrJS8kdgQoRlqsI/CMsOapQPR9nJThNdZkJbsUddCEoOdPKuzIEvAgX3RWt7rwNTp4RQmpK+IpPHWMtH0YtTXfatqkSPs3Lwqai00GxKDSByzXJ6drveVO/2Z/41aDavL+GRsLgyXU6K0Lgs6RXv/NJRVrWyHAmHBVTB+2ghzv0X9bz0sLTk8xtdKt+7iEBWCdibOXI+lHxZEqd2Y4O1EU++mIgJaOgqWWkuM57M4yyuFfFuNj822GT1M6/1Km6YICS1vnF1LSwJxa5i0Bz1VRltRjeljH+b9aASj5SXnSKAzflriPE8mBiAu/+DhQ== Authentication-Results: linux.ie; dkim=none (message not signed) header.d=none;linux.ie; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL1PR12MB5334.namprd12.prod.outlook.com (2603:10b6:208:31d::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.20; Thu, 15 Jul 2021 00:20:45 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482%5]) with mapi id 15.20.4331.021; Thu, 15 Jul 2021 00:20:45 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , Daniel Vetter , Diana Craciun , dri-devel@lists.freedesktop.org, Eric Auger , 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 , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Date: Wed, 14 Jul 2021 21:20:31 -0300 Message-Id: <2-v1-eaf3ccbba33c+1add0-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v1-eaf3ccbba33c+1add0-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: CH0PR03CA0011.namprd03.prod.outlook.com (2603:10b6:610:b0::16) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by CH0PR03CA0011.namprd03.prod.outlook.com (2603:10b6:610:b0::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Thu, 15 Jul 2021 00:20:43 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m3p7K-002UxB-D3; Wed, 14 Jul 2021 21:20:42 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 22e0e1ef-1338-4453-a23c-08d947266270 X-MS-TrafficTypeDiagnostic: BL1PR12MB5334: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1850; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: N9DkRUMfSB1QSDw1iwlrvHNaBMWUX8GsXCgfAKBd0KFZjGgn4o01OD1y5MB3ruO8x3/+bUNOXrxGRGiL0iYTmLGP9cUIVLrgkJsEHn3DIbxzKoEelX0v8impL29vhg1n6w1PQ2bQJ5lyRW5HsGyQd3Pw32tpQDsk7V5u+mqE4+c10YHskIXpvIu87QpRKt8Gstd3Wgna3R3kU1b2+E94QMhwwriCAHLe6VfjTpTenJhbiIeAtLlixhK5n553yvJqBMkuuZZXeSx5uYEt+zLiYL1X+qpSSjBxPVbeYgqhkC5vE11Oi68nlcWm1NUOpmJnn3LBx+7Im2cPaOAc0C9MY6hmZMiChmEImCQ0c3E8uBElMtP6B7Fip10Hkq2o+Xq1y9R03U0OS98y6vUWWiQKSm6uuw3AYpEByUlygFkpUkwDIPKkGN044bmo/9ZG8rdMdPticFJLhcI++5ov19xVPhHV9ltWvIuH1XDWcGBcZrFvC8EBak9ceRQ4YHICVYod4V6q/4iZBcoYOzAJDFaWz0AFOoDBkYSbL9LIWTZdV3puQbsRCdPHuhqibACpvhPyRTfAaxy85+BYlInBaqHEJ8q27oLveg9A6RPU3LSWwHj0p8mW8oGOdfZ15SO66RFlrxAugYYR7c97mrP5uMXaCabaKWemY1JktEm3v8IoFwbxLg6w6mzWJiWBQTbBqFei3Q5e/h6ZWGPnXzrESlv6Tg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL0PR12MB5506.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(366004)(376002)(396003)(346002)(39860400002)(107886003)(86362001)(66556008)(66476007)(54906003)(5660300002)(36756003)(2906002)(26005)(6666004)(4326008)(7416002)(9746002)(426003)(9786002)(186003)(66946007)(110136005)(2616005)(316002)(7406005)(30864003)(83380400001)(8936002)(38100700002)(921005)(8676002)(478600001)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9JuEFhVJoEQwN+i9GfSrmB9x1bjmTes4ESFW8chuF9eyi2N0LhtxrGPylEXzh1DWVjImhpKmuapSjlU+W/65zlCu4VIS23Mi1ILNIu20DOeqOVhVcILUx9kv0Mx+TezK4FAmotf4lKpRyF13yfnmocgleKLLjVE+qc7J7uzc8UdKPFatMkb0QIMWyo5xXRsjOSI1CDafpL98eD++TfnxDm/9d6J61xIBPyXp+D0C4ik6Wy3QT4+NQhI/TUf60Kipb4+3Ub26+FfDnirUmwAN5SbiW36j+seoY5cFG+OI234pNC308L1BCDy6UbrBQ+sePJCRawqQSakrLMp0BWjRB0HTrdISgL0ONaxsp7z0eqIyOzHmzBBqFhGwqde/KqwkqyYVvchzss1bXL5pmduAWUGy1EKrTOlek/ZPNVF5rq8VzvBNxUTLD5Z3+qJZi+Q79w6YsxJLCwgOw41oiAL1eHR8q16hBzeJF0TKFAC7wXWh4cUg6M5Zx6NmKxAB61iHzkqW8nK89gyjRIC3vZjOUDqf/fRLw7WcOt88qT/yTX3W9MXwCtWFVF9svxmj4PvqV1OdLLMfpKk0N1Ihql8ZPlKI/n0g63py1tpo42XN0hUNzo9HI2o3oMuN6lGvxTKIsj9+b8P0AKofurE6pff6UETZeXBr4nJp47+3eszj01nRGqFhBZgQZ1dmKSHE43FCMmIBXU8ZRrkYr316qXTrXm+FesTe8BSwAqaFDbJwRmYK30pI91PlC+dGicd51uy4HtymdpTdgzwHsYi9phDKEvL7GAHAwg+eeQwFxl9D8zhftjTwpt/70MGmdpOCE3xHTjHmz45FjPFD+vnwcgU61hEV+YaLmA/ogzWSx0+9CmtNzN8WjeAF9abNgu7riqQuRbj3yj+BysqTRob0kzLjVuU7u8MKYqBPFOGM/x5tJgHT55sfayGA/kSr5FjJlMoM0ZHB4Nh2XXAHlHAOevqCCvm0Hk/P4fbjvEkk6BDyO8CE9QUZyv58qHNJu4/a31TtiHS1ik7L+FBNqgBppQ0A1YxfT5FDTmbIPvzprYLOJQnvhdBaH+KJSlT9XWnFHu1vDIjzjmkyi5xfqUU2UaKXD95RLpJkAowGXa9buGitUo7WYLpqCMPcZbzY0B83MqLkzhMzKA5Az7Bk1+RGXT0F4gPU9875CXquRe8zMq/0jn7J2RGzDrJokNiX+I0HxLDVbQt5gnIKo1zcDQQswDoGuHxOgaSUTUvS+L2sG9dPqL3d5ooTSXIlSCPIZGqN20LgmDSYdzLjX9SgYe+zrQfPkYwZf4kJXI0GEKv8jlA+Jxp9h+Y+8ixMOH47076Wi/Sy X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 22e0e1ef-1338-4453-a23c-08d947266270 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2021 00:20:43.8470 (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: WLTwS4qFIwZiccw7ozzZc71ts8FCDo/PmoR6KGucvZextIEDsQcsHuA31UWGEiSb X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5334 Subject: [Intel-gfx] [PATCH 02/13] vfio: Introduce a vfio_uninit_group_dev() API call 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: Max Gurtovoy , Yishai Hadas , Leon Romanovsky , "Raj, Ashok" , Christoph Hellwig Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Max Gurtovoy This pairs with vfio_init_group_dev() and allows undoing any state that is stored in the vfio_device unrelated to registration. Add appropriately placed calls to all the drivers. The following patch will use this to add pre-registration state for the device set. Signed-off-by: Max Gurtovoy Signed-off-by: Jason Gunthorpe --- Documentation/driver-api/vfio.rst | 4 ++- drivers/vfio/fsl-mc/vfio_fsl_mc.c | 6 +++-- drivers/vfio/mdev/vfio_mdev.c | 13 +++++++--- drivers/vfio/pci/vfio_pci.c | 6 +++-- drivers/vfio/platform/vfio_platform_common.c | 7 +++-- drivers/vfio/vfio.c | 5 ++++ include/linux/vfio.h | 1 + samples/vfio-mdev/mbochs.c | 2 ++ samples/vfio-mdev/mdpy.c | 25 ++++++++++-------- samples/vfio-mdev/mtty.c | 27 ++++++++++++-------- 10 files changed, 64 insertions(+), 32 deletions(-) diff --git a/Documentation/driver-api/vfio.rst b/Documentation/driver-api/vfio.rst index 606eed8823ceab..c663b6f978255b 100644 --- a/Documentation/driver-api/vfio.rst +++ b/Documentation/driver-api/vfio.rst @@ -255,11 +255,13 @@ vfio_unregister_group_dev() respectively:: void vfio_init_group_dev(struct vfio_device *device, struct device *dev, const struct vfio_device_ops *ops); + void vfio_uninit_group_dev(struct vfio_device *device); int vfio_register_group_dev(struct vfio_device *device); void vfio_unregister_group_dev(struct vfio_device *device); The driver should embed the vfio_device in its own structure and call -vfio_init_group_dev() to pre-configure it before going to registration. +vfio_init_group_dev() to pre-configure it before going to registration +and call vfio_uninit_group_dev() after completing the un-registration. vfio_register_group_dev() indicates to the core to begin tracking the iommu_group of the specified dev and register the dev as owned by a VFIO bus driver. Once vfio_register_group_dev() returns it is possible for userspace to diff --git a/drivers/vfio/fsl-mc/vfio_fsl_mc.c b/drivers/vfio/fsl-mc/vfio_fsl_mc.c index 90cad109583b80..3d2be06e1bc146 100644 --- a/drivers/vfio/fsl-mc/vfio_fsl_mc.c +++ b/drivers/vfio/fsl-mc/vfio_fsl_mc.c @@ -627,7 +627,7 @@ static int vfio_fsl_mc_probe(struct fsl_mc_device *mc_dev) ret = vfio_fsl_mc_reflck_attach(vdev); if (ret) - goto out_kfree; + goto out_uninit; ret = vfio_fsl_mc_init_device(vdev); if (ret) @@ -657,7 +657,8 @@ static int vfio_fsl_mc_probe(struct fsl_mc_device *mc_dev) vfio_fsl_uninit_device(vdev); out_reflck: vfio_fsl_mc_reflck_put(vdev->reflck); -out_kfree: +out_uninit: + vfio_uninit_group_dev(&vdev->vdev); kfree(vdev); out_group_put: vfio_iommu_group_put(group, dev); @@ -674,6 +675,7 @@ static int vfio_fsl_mc_remove(struct fsl_mc_device *mc_dev) dprc_remove_devices(mc_dev, NULL, 0); vfio_fsl_uninit_device(vdev); + vfio_uninit_group_dev(&vdev->vdev); vfio_fsl_mc_reflck_put(vdev->reflck); kfree(vdev); diff --git a/drivers/vfio/mdev/vfio_mdev.c b/drivers/vfio/mdev/vfio_mdev.c index 39ef7489fe4719..a5c77ccb24f70a 100644 --- a/drivers/vfio/mdev/vfio_mdev.c +++ b/drivers/vfio/mdev/vfio_mdev.c @@ -120,12 +120,16 @@ static int vfio_mdev_probe(struct mdev_device *mdev) vfio_init_group_dev(vdev, &mdev->dev, &vfio_mdev_dev_ops); ret = vfio_register_group_dev(vdev); - if (ret) { - kfree(vdev); - return ret; - } + if (ret) + goto out_uninit; + dev_set_drvdata(&mdev->dev, vdev); return 0; + +out_uninit: + vfio_uninit_group_dev(vdev); + kfree(vdev); + return ret; } static void vfio_mdev_remove(struct mdev_device *mdev) @@ -133,6 +137,7 @@ static void vfio_mdev_remove(struct mdev_device *mdev) struct vfio_device *vdev = dev_get_drvdata(&mdev->dev); vfio_unregister_group_dev(vdev); + vfio_uninit_group_dev(vdev); kfree(vdev); } diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index 318864d5283782..fab3715d60d4ba 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -2022,7 +2022,7 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) ret = vfio_pci_reflck_attach(vdev); if (ret) - goto out_free; + goto out_uninit; ret = vfio_pci_vf_init(vdev); if (ret) goto out_reflck; @@ -2059,7 +2059,8 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) vfio_pci_vf_uninit(vdev); out_reflck: vfio_pci_reflck_put(vdev->reflck); -out_free: +out_uninit: + vfio_uninit_group_dev(&vdev->vdev); kfree(vdev->pm_save); kfree(vdev); out_group_put: @@ -2077,6 +2078,7 @@ static void vfio_pci_remove(struct pci_dev *pdev) vfio_pci_vf_uninit(vdev); vfio_pci_reflck_put(vdev->reflck); + vfio_uninit_group_dev(&vdev->vdev); vfio_pci_vga_uninit(vdev); vfio_iommu_group_put(pdev->dev.iommu_group, &pdev->dev); diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c index 703164df7637db..bdde8605178cd2 100644 --- a/drivers/vfio/platform/vfio_platform_common.c +++ b/drivers/vfio/platform/vfio_platform_common.c @@ -667,7 +667,7 @@ int vfio_platform_probe_common(struct vfio_platform_device *vdev, ret = vfio_platform_of_probe(vdev, dev); if (ret) - return ret; + goto out_uninit; vdev->device = dev; @@ -675,7 +675,7 @@ int vfio_platform_probe_common(struct vfio_platform_device *vdev, if (ret && vdev->reset_required) { dev_err(dev, "No reset function found for device %s\n", vdev->name); - return ret; + goto out_uninit; } group = vfio_iommu_group_get(dev); @@ -698,6 +698,8 @@ int vfio_platform_probe_common(struct vfio_platform_device *vdev, vfio_iommu_group_put(group, dev); put_reset: vfio_platform_put_reset(vdev); +out_uninit: + vfio_uninit_group_dev(&vdev->vdev); return ret; } EXPORT_SYMBOL_GPL(vfio_platform_probe_common); @@ -708,6 +710,7 @@ void vfio_platform_remove_common(struct vfio_platform_device *vdev) pm_runtime_disable(vdev->device); vfio_platform_put_reset(vdev); + vfio_uninit_group_dev(&vdev->vdev); vfio_iommu_group_put(vdev->vdev.dev->iommu_group, vdev->vdev.dev); } EXPORT_SYMBOL_GPL(vfio_platform_remove_common); diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index 02cc51ce6891a9..cc375df0fd5dda 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -749,6 +749,11 @@ void vfio_init_group_dev(struct vfio_device *device, struct device *dev, } EXPORT_SYMBOL_GPL(vfio_init_group_dev); +void vfio_uninit_group_dev(struct vfio_device *device) +{ +} +EXPORT_SYMBOL_GPL(vfio_uninit_group_dev); + int vfio_register_group_dev(struct vfio_device *device) { struct vfio_device *existing_device; diff --git a/include/linux/vfio.h b/include/linux/vfio.h index a2c5b30e1763ba..b0875cf8e496bb 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -61,6 +61,7 @@ extern void vfio_iommu_group_put(struct iommu_group *group, struct device *dev); void vfio_init_group_dev(struct vfio_device *device, struct device *dev, const struct vfio_device_ops *ops); +void vfio_uninit_group_dev(struct vfio_device *device); int vfio_register_group_dev(struct vfio_device *device); void vfio_unregister_group_dev(struct vfio_device *device); extern struct vfio_device *vfio_device_get_from_dev(struct device *dev); diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c index e81b875b4d87b4..cf264d0bf11053 100644 --- a/samples/vfio-mdev/mbochs.c +++ b/samples/vfio-mdev/mbochs.c @@ -558,6 +558,7 @@ static int mbochs_probe(struct mdev_device *mdev) return 0; err_mem: + vfio_uninit_group_dev(&mdev_state->vdev); kfree(mdev_state->vconfig); kfree(mdev_state); return ret; @@ -571,6 +572,7 @@ static void mbochs_remove(struct mdev_device *mdev) vfio_unregister_group_dev(&mdev_state->vdev); kfree(mdev_state->pages); kfree(mdev_state->vconfig); + vfio_uninit_group_dev(&mdev_state->vdev); kfree(mdev_state); } diff --git a/samples/vfio-mdev/mdpy.c b/samples/vfio-mdev/mdpy.c index a7d4ed28d66411..57334034cde6dd 100644 --- a/samples/vfio-mdev/mdpy.c +++ b/samples/vfio-mdev/mdpy.c @@ -235,17 +235,16 @@ static int mdpy_probe(struct mdev_device *mdev) mdev_state->vconfig = kzalloc(MDPY_CONFIG_SPACE_SIZE, GFP_KERNEL); if (mdev_state->vconfig == NULL) { - kfree(mdev_state); - return -ENOMEM; + ret = -ENOMEM; + goto err_state; } fbsize = roundup_pow_of_two(type->width * type->height * type->bytepp); mdev_state->memblk = vmalloc_user(fbsize); if (!mdev_state->memblk) { - kfree(mdev_state->vconfig); - kfree(mdev_state); - return -ENOMEM; + ret = -ENOMEM; + goto err_vconfig; } dev_info(dev, "%s: %s (%dx%d)\n", __func__, type->name, type->width, type->height); @@ -260,13 +259,18 @@ static int mdpy_probe(struct mdev_device *mdev) mdpy_count++; ret = vfio_register_group_dev(&mdev_state->vdev); - if (ret) { - kfree(mdev_state->vconfig); - kfree(mdev_state); - return ret; - } + if (ret) + goto err_mem; dev_set_drvdata(&mdev->dev, mdev_state); return 0; +err_mem: + vfree(mdev_state->memblk); +err_vconfig: + kfree(mdev_state->vconfig); +err_state: + vfio_uninit_group_dev(&mdev_state->vdev); + kfree(mdev_state); + return ret; } static void mdpy_remove(struct mdev_device *mdev) @@ -278,6 +282,7 @@ static void mdpy_remove(struct mdev_device *mdev) vfio_unregister_group_dev(&mdev_state->vdev); vfree(mdev_state->memblk); kfree(mdev_state->vconfig); + vfio_uninit_group_dev(&mdev_state->vdev); kfree(mdev_state); mdpy_count--; diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c index 8b26fecc4afedd..37cc9067e1601d 100644 --- a/samples/vfio-mdev/mtty.c +++ b/samples/vfio-mdev/mtty.c @@ -718,8 +718,8 @@ static int mtty_probe(struct mdev_device *mdev) mdev_state = kzalloc(sizeof(struct mdev_state), GFP_KERNEL); if (mdev_state == NULL) { - atomic_add(nr_ports, &mdev_avail_ports); - return -ENOMEM; + ret = -ENOMEM; + goto err_nr_ports; } vfio_init_group_dev(&mdev_state->vdev, &mdev->dev, &mtty_dev_ops); @@ -732,9 +732,8 @@ static int mtty_probe(struct mdev_device *mdev) mdev_state->vconfig = kzalloc(MTTY_CONFIG_SPACE_SIZE, GFP_KERNEL); if (mdev_state->vconfig == NULL) { - kfree(mdev_state); - atomic_add(nr_ports, &mdev_avail_ports); - return -ENOMEM; + ret = -ENOMEM; + goto err_state; } mutex_init(&mdev_state->ops_lock); @@ -743,14 +742,19 @@ static int mtty_probe(struct mdev_device *mdev) mtty_create_config_space(mdev_state); ret = vfio_register_group_dev(&mdev_state->vdev); - if (ret) { - kfree(mdev_state); - atomic_add(nr_ports, &mdev_avail_ports); - return ret; - } - + if (ret) + goto err_vconfig; dev_set_drvdata(&mdev->dev, mdev_state); return 0; + +err_vconfig: + kfree(mdev_state->vconfig); +err_state: + vfio_uninit_group_dev(&mdev_state->vdev); + kfree(mdev_state); +err_nr_ports: + atomic_add(nr_ports, &mdev_avail_ports); + return ret; } static void mtty_remove(struct mdev_device *mdev) @@ -761,6 +765,7 @@ static void mtty_remove(struct mdev_device *mdev) vfio_unregister_group_dev(&mdev_state->vdev); kfree(mdev_state->vconfig); + vfio_uninit_group_dev(&mdev_state->vdev); kfree(mdev_state); atomic_add(nr_ports, &mdev_avail_ports); } From patchwork Thu Jul 15 00:20:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12378157 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9ABD0C47E53 for ; Thu, 15 Jul 2021 00:21:05 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 6170861374 for ; Thu, 15 Jul 2021 00:21:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6170861374 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 887606E51C; Thu, 15 Jul 2021 00:20:51 +0000 (UTC) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2056.outbound.protection.outlook.com [40.107.236.56]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4F37D6E50D; Thu, 15 Jul 2021 00:20:49 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gpZ/ZiZDfNt9Y15zxAkGIliyQWPZEUjRKaQ0IZWGkZs892wYyweFm9lN2vntc/kbN1K/kgU5N9ebBfGx1XjBD9yVDnzxHicgK0GnZsUntCmGe5W6EwRd60GJoMwn3lxJajFZnjREhAtmJbEmV7JC7uurBQ0Ub8IHCLTf38lD8v/lmUAVc3XyY3yDkmpF4oxO1cEcm60Zkb8Y2xyuPRccSjxEyzPbh3cV0guAX0jaBlo2Ejlg/grFcl1/Aq9C7Fd/3tkQ0Ey5mo6f3jYdI05tj8tHhGQqFfnXAa6f9eWZwc+UzqqB6bTksBTSqH/F0VPkyMrPWWG2lrdFH25XJkfvgQ== 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-SenderADCheck; bh=AJPAm2QI0LQQw4M7Eo31B6OAx+ud8GUHZgfpPhVVEcU=; b=LpkS4aoL1fCK1AVlOYmuNc3ymrtudE9raYjuJi5XH/Uuju6Kis29TjCvIqvT1Z+qMFyn8OrVmYRuq5bD5K71k4IlVQbZHANyjzCxYx8DPxlQTuK3uZvJWOk1P4lpNAsfNOcyAeKrlg1RCk3sd5X8yASk9kFjFDHuoGtAabom3lij2WYb31BXNj48sDm43qQAYpb5UXIOGbCsoZxcyYFCN7blamdXrGNcCj/ZECdGl/bcL3RrZ4H9v6spJEsLixL5Pvela/g8QXQDqmvk7WEMXW6u40LyndOchIZxUXi4/UZRGzpwvaowsCEhIO9kXRLAmomdvdE7thqoHZ/5olJsxA== 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=AJPAm2QI0LQQw4M7Eo31B6OAx+ud8GUHZgfpPhVVEcU=; b=KnlmQKAXh/LrJQoiPdlt/053os9cgmbom4LpzNDtks0czXRDbhqi7maXDVfRE3i1IAQy3XoJudQMeQiVTLTAiYtXtVO/NGa8U6yUZe1KIXZFx/uQtCsJohFLQ6qrM4Gx/mWwpJs6UIBJnga/uuPW54WPE4ywRvqgqu2bpqwqHfsuLecAGgG5ZXFjtD4ohgGuh21YAkjC/9/ju3gjI7rgQk5sP6U25BHaLbYgY397DxhBPKIU8jSiIL7h7qhIWbka/AgrmMZ3U3RQ/TlbHbFXtjKw0HxAgBJQczKBXmhKY+4u+GcjB3JNo7HEgzyuh5dGUJfNcnAa/Y5NLQEB1D4BGw== Authentication-Results: linux.ie; dkim=none (message not signed) header.d=none;linux.ie; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL0PR12MB5555.namprd12.prod.outlook.com (2603:10b6:208:1c2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.26; Thu, 15 Jul 2021 00:20:46 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482%5]) with mapi id 15.20.4331.021; Thu, 15 Jul 2021 00:20:46 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , Daniel Vetter , Diana Craciun , dri-devel@lists.freedesktop.org, Eric Auger , 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 , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Date: Wed, 14 Jul 2021 21:20:32 -0300 Message-Id: <3-v1-eaf3ccbba33c+1add0-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v1-eaf3ccbba33c+1add0-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: CH0PR04CA0061.namprd04.prod.outlook.com (2603:10b6:610:74::6) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by CH0PR04CA0061.namprd04.prod.outlook.com (2603:10b6:610:74::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.22 via Frontend Transport; Thu, 15 Jul 2021 00:20:43 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m3p7K-002UxF-FR; Wed, 14 Jul 2021 21:20:42 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ae43550d-9129-4f96-50f6-08d94726626b X-MS-TrafficTypeDiagnostic: BL0PR12MB5555: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MJrQLStFm+wHXUnr4soVnFSAeyG3/2g5rKsupx2XnGC5LF0p1XAp1muQGMBUbCqfROjYxyGg9/196iQpdHh59Z77SVDq49vS8vo2yUbviVzLoGbx3ZwuijQv3MaJ2BZCQzfBvXA3waom+AwIi/cjjMvNhobTB/OWK6uTT2X84avM0Ix2jXBnxKj4/rZm23kWSvZvoQco4HA4dvB68C1os2oXXEMB+OEWLxEQIZoFf2e56dHQk8e6/nzHFtJ0ipBhEHeABL9IO5tLTItDbKmYTf33c/3AHW5yvL8POonp99lTT3YXK3Ogtc/p9MK3fZZ7u0SDyF7XBLIjCX0gMw6WLzji4ZQLSvazi3jt1uLEpp3oc34MzWf6LYujR1qcNvz7I5gnHGe8VZE9rLzb6LdS5b5JieVqLibptK9XmAQcdBaszL45nFCncBLZ7YUde2RMuO1gCOD6qJaaydS7ICjdP6eAiFwX4jQ74gdEupZAR68r1GjxnxeMD1/0EuvgZuP9wy9LNuCFCqprj5OzVC0BnHdecszv2nE2WB3TILNiXGTE140lsx1G7FjXizn7hlQiaF7C1GHBXvZxn2nAy3kx5deC2heGx84E128vjZC/+MhK1gLi3CXQKY0J8WXVlS5kEKn7pp1MYkIDJy8dBBRm67Gre+45SSb7FwFcwD31g0QvhKwhfZeyN8rZwvJ1Th20NkT1V83+vhPZf4HnrrFosB2i3KEeRZ45r5g33UYEmSTbi8le5X+ppL4P5Mh/6OJv X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL0PR12MB5506.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(39860400002)(346002)(376002)(396003)(366004)(83380400001)(2616005)(426003)(316002)(107886003)(2906002)(478600001)(4326008)(7416002)(30864003)(7406005)(38100700002)(36756003)(5660300002)(66556008)(66476007)(66946007)(921005)(9746002)(26005)(8936002)(110136005)(54906003)(8676002)(9786002)(86362001)(6666004)(186003)(4216001)(41533002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: papJLHftwil39tQdUnwQZmfAlluLKsSfn9vthEnt5Xox/Wte0bDQayihtDKbuSSmdQruDyDQPYMjpotYpG3aVq2cI47etPr79amcxNJQ2wWqA8xXnfYyN46C8o1glFo5Qghjk5zlqfa84IC1p9um+B4D8XhT+6MYJ/7h/vxPK2+1GExhDY3dg8IdGqNJnktFguJp9LrlcFmnwX0Bi15oActxoaZwwdKq5ndJRnxvIg5zVe0Z5hNUN+jnBFDd2RC1ab0JVrzC5uzvDrKxZ4xMdEOEhD+PEjW6T4M6yb0fZADSIKhcphFfz9Zx1/Xu2NtRGeuc0IeFpM3QUtscFwXDHyz7sfpRcG2LCl6e6cxUslqVLqpiqaoBsMFItiQgsM1HuuIdWsajOXsT+6Wk4gfN6aLxdgMqaeL3PymBX7b6J4bXVf0TIjlqj71FX/cDzEDhTDTS5MuZ32ceWcymaNBstaoD399famQPGyReaGtT9tkT9J0O6myJzSk+wGDBZ0CqjLnXzBPFXlR/RPbOOP7cl1GJlhgc2yDv3jH7+/6LLlpRaZCFtNRrYQB/AdiXfCmQX1cIhf3J78FNqedrulEH9PQdmISc0UOk5W3zcvJSXAyNUvkDX6/tBQCxOUwNxIlZKDJ/Y5c4NgZbk8Z48wFX+8+Wvl7zQpX71VEAA++/Y+09WWfSsc6WaWFjhXcw8zYHd6mhtfZ5Ev1GyvHvyG9gP9dspyahxpudEaFs184qNiEaDuflYbv0iT4BM07vxWLjObKzHLMiv2swBMrhj1SXMG9Wq7qqdfq1ZcDCNO8K0TTrYCvauMWl1833MMHbvzqj2Qce8l02Rf/rtt3JTpUelFYBXH6nifDcQVcS/+MGgARagKtUtNd7HkfKlNs0g9zZ6zi2pbr+2ZCP5WjDgZbJaeC/+p7ZdLKDO1fQt5jPZW1WyZmXx+q9+iWteuXfvKrw/srpNv8IbQ4SX1lvBLWNJddpGnLt5UQeYmVOO1M/L1lsNuA87Fftl4SjtudtTtysrW/+QTc9qAbBo6dPKafA+NwyQaISfZpkxZUCShXp56xBqVWUhJW6P7tR5EhMUGrLLZrkogPkHABtf/1bvASIIkbtJmthG+Xg+pagQejjnXtdomV7D8ie2o+3GBF+PO825ftlcBQwFYbEQljyhH2yDXtMym/iIeDAgvdLwGDFuQqTz/n1CMwlIgA1jR7E90NkQKWygrtceZbEHG0n7VRl6sUKftLAKzno8tBV9HyvetixKNaTj6RvEUWX4EP3lTCa3hcD3FY1k03Lf27rmCQtkOV/5pzC4ug8MCJrDIUB/BmN6NyVB9fgECeu8J/EWm97 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ae43550d-9129-4f96-50f6-08d94726626b X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2021 00:20:43.9018 (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: 5dnbW2oqJ0vKdYlRSstTja22JfMSig56nlk5+e7tEMbr5hZ9Yp462iNQwy2GBFKW X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5555 Subject: [Intel-gfx] [PATCH 03/13] vfio: Provide better generic support for open/release vfio_device_ops 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: Max Gurtovoy , Yishai Hadas , Leon Romanovsky , "Raj, Ashok" , Christoph Hellwig Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Currently the driver ops have an open/release pair that is called once each time a device FD is opened or closed. Add an additional set of open/close_device() ops which are called when the device FD is opened for the first time and closed for the last time. An analysis shows that all of the drivers require this semantic. Some are open coding it as part of their reflck implementation, and some are just buggy and miss it completely. To retain the current semantics PCI and FSL depend on, introduce the idea of a "device set" which is a grouping of vfio_device's that share the same lock around opening. The device set is established by providing a 'set_id' pointer. All vfio_device's that provide the same pointer will be joined to the same singleton memory and lock across the whole set. This effectively replaces the oddly named reflck. After conversion the set_id will be sourced from: - A struct device from a fsl_mc_device (fsl) - A struct pci_slot (pci) - A struct pci_bus (pci) - The struct vfio_device (everything) The design ensures that the above pointers are live as long as the vfio_device is registered, so they form reliable unique keys to group vfio_devices into sets. This implementation uses xarray instead of searching through the driver core structures, which simplifies the somewhat tricky locking in this area. Following patches convert all the drivers. Signed-off-by: Yishai Hadas Signed-off-by: Jason Gunthorpe --- drivers/vfio/mdev/vfio_mdev.c | 22 ++++++ drivers/vfio/vfio.c | 144 ++++++++++++++++++++++++++++------ include/linux/mdev.h | 2 + include/linux/vfio.h | 19 +++++ 4 files changed, 165 insertions(+), 22 deletions(-) diff --git a/drivers/vfio/mdev/vfio_mdev.c b/drivers/vfio/mdev/vfio_mdev.c index a5c77ccb24f70a..3c384d2350b64a 100644 --- a/drivers/vfio/mdev/vfio_mdev.c +++ b/drivers/vfio/mdev/vfio_mdev.c @@ -17,6 +17,26 @@ #include "mdev_private.h" +static int vfio_mdev_open_device(struct vfio_device *core_vdev) +{ + struct mdev_device *mdev = to_mdev_device(core_vdev->dev); + struct mdev_parent *parent = mdev->type->parent; + + if (unlikely(!parent->ops->open_device)) + return -EINVAL; + + return parent->ops->open_device(mdev); +} + +static void vfio_mdev_close_device(struct vfio_device *core_vdev) +{ + struct mdev_device *mdev = to_mdev_device(core_vdev->dev); + struct mdev_parent *parent = mdev->type->parent; + + if (likely(parent->ops->close_device)) + parent->ops->close_device(mdev); +} + static int vfio_mdev_open(struct vfio_device *core_vdev) { struct mdev_device *mdev = to_mdev_device(core_vdev->dev); @@ -100,6 +120,8 @@ static void vfio_mdev_request(struct vfio_device *core_vdev, unsigned int count) static const struct vfio_device_ops vfio_mdev_dev_ops = { .name = "vfio-mdev", + .open_device = vfio_mdev_open_device, + .close_device = vfio_mdev_close_device, .open = vfio_mdev_open, .release = vfio_mdev_release, .ioctl = vfio_mdev_unlocked_ioctl, diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index cc375df0fd5dda..6908c2ae9b36f6 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -96,6 +96,74 @@ module_param_named(enable_unsafe_noiommu_mode, MODULE_PARM_DESC(enable_unsafe_noiommu_mode, "Enable UNSAFE, no-IOMMU mode. This mode provides no device isolation, no DMA translation, no host kernel protection, cannot be used for device assignment to virtual machines, requires RAWIO permissions, and will taint the kernel. If you do not know what this is for, step away. (default: false)"); #endif +static DEFINE_XARRAY(vfio_device_set_xa); + +int vfio_assign_device_set(struct vfio_device *device, void *set_id) +{ + struct vfio_device_set *alloc_dev_set = NULL; + struct vfio_device_set *dev_set; + + if (WARN_ON(!set_id)) + return -EINVAL; + + /* + * Atomically acquire a singleton object in the xarray for this set_id + */ +again: + xa_lock(&vfio_device_set_xa); + if (alloc_dev_set) { + dev_set = __xa_cmpxchg(&vfio_device_set_xa, + (unsigned long)set_id, NULL, + alloc_dev_set, GFP_KERNEL); + if (xa_is_err(dev_set)) { + xa_unlock(&vfio_device_set_xa); + kfree(alloc_dev_set); + return xa_err(dev_set); + } + if (!dev_set) + dev_set = alloc_dev_set; + } else + dev_set = xa_load(&vfio_device_set_xa, (unsigned long)set_id); + if (dev_set) { + dev_set->device_count++; + xa_unlock(&vfio_device_set_xa); + device->dev_set = dev_set; + if (dev_set != alloc_dev_set) + kfree(alloc_dev_set); + return 0; + } + xa_unlock(&vfio_device_set_xa); + + if (WARN_ON(alloc_dev_set)) + return -EINVAL; + + alloc_dev_set = kzalloc(sizeof(*alloc_dev_set), GFP_KERNEL); + if (!alloc_dev_set) + return -ENOMEM; + mutex_init(&alloc_dev_set->lock); + alloc_dev_set->set_id = set_id; + goto again; +} +EXPORT_SYMBOL_GPL(vfio_assign_device_set); + +static void vfio_release_device_set(struct vfio_device *device) +{ + struct vfio_device_set *dev_set = device->dev_set; + + if (!dev_set) + return; + + xa_lock(&vfio_device_set_xa); + dev_set->device_count--; + if (!dev_set->device_count) { + __xa_erase(&vfio_device_set_xa, + (unsigned long)dev_set->set_id); + mutex_destroy(&dev_set->lock); + kfree(dev_set); + } + xa_unlock(&vfio_device_set_xa); +} + /* * vfio_iommu_group_{get,put} are only intended for VFIO bus driver probe * and remove functions, any use cases other than acquiring the first @@ -751,6 +819,7 @@ EXPORT_SYMBOL_GPL(vfio_init_group_dev); void vfio_uninit_group_dev(struct vfio_device *device) { + vfio_release_device_set(device); } EXPORT_SYMBOL_GPL(vfio_uninit_group_dev); @@ -760,6 +829,13 @@ int vfio_register_group_dev(struct vfio_device *device) struct iommu_group *iommu_group; struct vfio_group *group; + /* + * If the driver doesn't specify a set then the device is added to a + * signleton set just for itself. + */ + if (!device->dev_set) + vfio_assign_device_set(device, device); + iommu_group = iommu_group_get(device->dev); if (!iommu_group) return -EINVAL; @@ -1361,7 +1437,8 @@ static int vfio_group_get_device_fd(struct vfio_group *group, char *buf) { struct vfio_device *device; struct file *filep; - int ret; + int fdno; + int ret = 0; if (0 == atomic_read(&group->container_users) || !group->container->iommu_driver || !vfio_group_viable(group)) @@ -1375,38 +1452,38 @@ static int vfio_group_get_device_fd(struct vfio_group *group, char *buf) return PTR_ERR(device); if (!try_module_get(device->dev->driver->owner)) { - vfio_device_put(device); - return -ENODEV; + ret = -ENODEV; + goto err_device_put; } - ret = device->ops->open(device); - if (ret) { - module_put(device->dev->driver->owner); - vfio_device_put(device); - return ret; + mutex_lock(&device->dev_set->lock); + device->open_count++; + if (device->open_count == 1 && device->ops->open_device) { + ret = device->ops->open_device(device); + if (ret) + goto err_undo_count; + } + mutex_unlock(&device->dev_set->lock); + + if (device->ops->open) { + ret = device->ops->open(device); + if (ret) + goto err_close_device; } /* * We can't use anon_inode_getfd() because we need to modify * the f_mode flags directly to allow more than just ioctls */ - ret = get_unused_fd_flags(O_CLOEXEC); - if (ret < 0) { - device->ops->release(device); - module_put(device->dev->driver->owner); - vfio_device_put(device); - return ret; - } + fdno = ret = get_unused_fd_flags(O_CLOEXEC); + if (ret < 0) + goto err_release; filep = anon_inode_getfile("[vfio-device]", &vfio_device_fops, device, O_RDWR); if (IS_ERR(filep)) { - put_unused_fd(ret); ret = PTR_ERR(filep); - device->ops->release(device); - module_put(device->dev->driver->owner); - vfio_device_put(device); - return ret; + goto err_fd; } /* @@ -1418,12 +1495,28 @@ static int vfio_group_get_device_fd(struct vfio_group *group, char *buf) atomic_inc(&group->container_users); - fd_install(ret, filep); + fd_install(fdno, filep); if (group->noiommu) dev_warn(device->dev, "vfio-noiommu device opened by user " "(%s:%d)\n", current->comm, task_pid_nr(current)); + return fdno; +err_fd: + put_unused_fd(fdno); +err_release: + if (device->ops->release) + device->ops->release(device); +err_close_device: + mutex_lock(&device->dev_set->lock); + if (device->open_count == 1 && device->ops->close_device) + device->ops->close_device(device); +err_undo_count: + device->open_count--; + mutex_unlock(&device->dev_set->lock); + module_put(device->dev->driver->owner); +err_device_put: + vfio_device_put(device); return ret; } @@ -1561,7 +1654,13 @@ static int vfio_device_fops_release(struct inode *inode, struct file *filep) { struct vfio_device *device = filep->private_data; - device->ops->release(device); + if (device->ops->release) + device->ops->release(device); + + mutex_lock(&device->dev_set->lock); + if (!--device->open_count && device->ops->close_device) + device->ops->close_device(device); + mutex_unlock(&device->dev_set->lock); module_put(device->dev->driver->owner); @@ -2364,6 +2463,7 @@ static void __exit vfio_cleanup(void) class_destroy(vfio.class); vfio.class = NULL; misc_deregister(&vfio_dev); + xa_destroy(&vfio_device_set_xa); } module_init(vfio_init); diff --git a/include/linux/mdev.h b/include/linux/mdev.h index 3a38598c260559..cb5b7ed1d7c30d 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -111,6 +111,8 @@ struct mdev_parent_ops { int (*create)(struct mdev_device *mdev); int (*remove)(struct mdev_device *mdev); + int (*open_device)(struct mdev_device *mdev); + void (*close_device)(struct mdev_device *mdev); int (*open)(struct mdev_device *mdev); void (*release)(struct mdev_device *mdev); ssize_t (*read)(struct mdev_device *mdev, char __user *buf, diff --git a/include/linux/vfio.h b/include/linux/vfio.h index b0875cf8e496bb..128b4db00adc57 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -15,13 +15,26 @@ #include #include +/* + * VFIO devices can be placed in a set, this allows all devices to share this + * structure and the VFIO core will provide a lock that is held around + * open_device()/close_device() for all devices in the set. + */ +struct vfio_device_set { + void *set_id; + struct mutex lock; + unsigned int device_count; +}; + struct vfio_device { struct device *dev; const struct vfio_device_ops *ops; struct vfio_group *group; + struct vfio_device_set *dev_set; /* Members below here are private, not for driver use */ refcount_t refcount; + unsigned int open_count; struct completion comp; struct list_head group_next; }; @@ -29,6 +42,8 @@ struct vfio_device { /** * struct vfio_device_ops - VFIO bus driver device callbacks * + * @open_device: Called when the first file descriptor is opened for this device + * @close_device: Opposite of open_device * @open: Called when userspace creates new file descriptor for device * @release: Called when userspace releases file descriptor for device * @read: Perform read(2) on device file descriptor @@ -43,6 +58,8 @@ struct vfio_device { */ struct vfio_device_ops { char *name; + int (*open_device)(struct vfio_device *vdev); + void (*close_device)(struct vfio_device *vdev); int (*open)(struct vfio_device *vdev); void (*release)(struct vfio_device *vdev); ssize_t (*read)(struct vfio_device *vdev, char __user *buf, @@ -67,6 +84,8 @@ void vfio_unregister_group_dev(struct vfio_device *device); extern struct vfio_device *vfio_device_get_from_dev(struct device *dev); extern void vfio_device_put(struct vfio_device *device); +int vfio_assign_device_set(struct vfio_device *device, void *set_id); + /* events for the backend driver notify callback */ enum vfio_iommu_notify_type { VFIO_IOMMU_CONTAINER_CLOSE = 0, From patchwork Thu Jul 15 00:20:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12378165 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77EDFC47E4B for ; Thu, 15 Jul 2021 00:21:19 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 4A657613CC for ; Thu, 15 Jul 2021 00:21:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4A657613CC Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 292206E526; Thu, 15 Jul 2021 00:20:56 +0000 (UTC) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2056.outbound.protection.outlook.com [40.107.236.56]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2F9B76E50D; Thu, 15 Jul 2021 00:20:50 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Zl1d8e8p6xRJSnnNpYXwAzZHt8Zbyh7yiGRWB8jQhsfmRWnZF5i79XkqmrS9/laHNdQjKJOnSiXNVM2LtJmbGWB0FnuOKY4tF4VCKONkoX1sw+lxAMRIlTBcPF0w1re4R/NKNNDMxDnHfinvygwo3t1MnWPotNggGdB1z9++mneLlObpJFoDS0wfmI5G6xRpBjZLtbRKMWkL6/mDWQNLrUtyMRjIiiq34F7Z3tgThgavyJ+diFCjsMMldpMAnZVwY7D0MK0GCL584LJu8FNW4/dXAQiADz9phai76XXgTrlH+EnWW9hyfMGZd4bYkTicl+tQ/a3L8vEtKPfqCh2E7A== 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-SenderADCheck; bh=xIc2oCm8m6pW9fubLZi0TSzG4l2OL+6bcDFd5Way0kU=; b=NidO0Jc28HqYdwY668rfOw79YKrbtWuBkUU9UJoC2USMb9JPkxuPVrNqDXvVh+ELkEWj3ldJKBAxM1/S8iikZCOPoVh2EC29c07pjxj286VG3kn+s8waoWYBhVTC6YQNhc+1PvQiv5zLQ1rrqEVczfG1s+0npr+DPcb2SvsYhnNWgIFRPpMvcGUd0IeGQa/5Bb2P+4bDKdDw/uodPC2fwgClSVskkDXtEjNb2N+hsgOT6YVToxgX+oYtHCpTqAZv1j2YrPwWVq292e0qVDeSXdb+DWXDF6CvJ0+PLyA4ZP8m4m8dscwrpMnCQASwf1zqEZWGd1ABKDT79zgAdj9dpg== 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=xIc2oCm8m6pW9fubLZi0TSzG4l2OL+6bcDFd5Way0kU=; b=WLZFIQLyjzlgc5GRUnUa1vfRBC3jH7RV0AssVuV1RZh25CVM8wlqOCNJXwoIhrXTxuEsBf2Gi6cNHEHAlmbdQxaqY1Fp2tKGOyLBmyYjuUo6PYx+5NerJSUNudb2BYbWMZQSbPpPJ01XIfzMi7LeOsiD+8BHtNCPJpYyPnIoBsZGatFksil2JahYUUiC2AwQ1dXF4IiIZU84ZCUyjxlr7MegwGcFUcfGHGtEGc/ffWR4bSxFVs56SD9jkJN75KovHKkDbKiJz3cqB46syTVELDowtb1IZ7uhi6KXhFJ5/iwGI4uwfyzUsFhTuxXMfLf06tcothMlsPVPYsP74Z2Usw== Authentication-Results: linux.ie; dkim=none (message not signed) header.d=none;linux.ie; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL0PR12MB5555.namprd12.prod.outlook.com (2603:10b6:208:1c2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.26; Thu, 15 Jul 2021 00:20:48 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482%5]) with mapi id 15.20.4331.021; Thu, 15 Jul 2021 00:20:48 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , Daniel Vetter , Diana Craciun , dri-devel@lists.freedesktop.org, Eric Auger , 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 , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Date: Wed, 14 Jul 2021 21:20:33 -0300 Message-Id: <4-v1-eaf3ccbba33c+1add0-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v1-eaf3ccbba33c+1add0-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: CH0PR03CA0004.namprd03.prod.outlook.com (2603:10b6:610:b0::9) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by CH0PR03CA0004.namprd03.prod.outlook.com (2603:10b6:610:b0::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Thu, 15 Jul 2021 00:20:45 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m3p7K-002UxJ-Go; Wed, 14 Jul 2021 21:20:42 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5b169f0c-bb3a-4045-bb8f-08d947266355 X-MS-TrafficTypeDiagnostic: BL0PR12MB5555: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:191; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8V7q5539RgvyV8M5pD+2f/CSMwHTrdtwlyfXxAJ7dSuyw+UqJGYa3KYxfk3Pjn4jOgEf7Rf3ILfLLkdTGlWpkGQupZmughh7IcDJVpaU3iw8KHqcdmykzLpvukAbE8MbCaMwgxNqXykJwFlYgqjNHIENODw0f3HPAUFLt4xrkqcTXpV1z9Uwbhgnj18paxQrdTHfMf5WBQ/GNsxWnUvIfbnt+Ti0j73D5zkf2h3USkgHtGLKl1Cu9KtuvHwgWPYVLizSy24O0VBpmZLIk1+1ex/ugrcQsXKMqq5A4GPJVyf1fvR5R5XOphkPP5hHgV4YNseAhETNzznii1FpWs8jYMNeer3hXiBhytJqz5KikV1/bfZ9D7g638pVbWHoit1v4x33enYG+Sk1fSjx4lJ2cBkObnzSMYz4cyy1kK5Fk7UcveP57z5nP2JFwqKJtJpgb+8LanhA0HR3/SOcMq6QhpkPug9lydtvRpBmebluc0FgxfblvlhYzYY++CJEnLZ+wHwSCzPCyr3HO3oii4NeoHEddQaP8kjOTLv3UmrtZJ0Hl/zcqZExTwu/IukRDPT5ipqW1d6vSBvx0AMMgHC4Y1ISh28xRJjk+ARq6XarlkBvwqKbf1hizvYWTkjxsWkeZezEBfJqvwjCJpxIRgEtYDNSDXbx+/3lHRnIISL9Qg9oEJJultgBAloqkji1wKUOse+yK5Clqc2uh0lojnAEaA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL0PR12MB5506.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(39860400002)(346002)(376002)(396003)(366004)(83380400001)(2616005)(426003)(316002)(107886003)(2906002)(478600001)(4326008)(7416002)(7406005)(38100700002)(36756003)(5660300002)(66556008)(66476007)(66946007)(921005)(9746002)(26005)(8936002)(110136005)(54906003)(8676002)(9786002)(86362001)(6666004)(186003)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HY+cnBGqfVdIL9Y2dxWgnnRwJQ571yok669wjONRNkrdohvu61KZ3O1jvGVpdjfwZhPQk8ZrF0YfBj5pjaNUDH5On6kWKr/fR6xk7He9FQRmGZHLW7Emo11GppYDWDAmrZMrGEcoILQf3G4hxShc/Fyy8hWXOxy+AD9AJOVtX3iv48z/1PxJEqUBzS5syngMgunrHrW/dtfAciApIWhMZ2ws48Vm3eSjMjzgtwp+tyADfNw0dpjGoPMk5ZoEoJgWyKh5Tt1yeU6upV2Irs38HCLi6KbSikEd05VU0FEz0wuSYba8wFWJAFEjH0kXynXbKLtNtlQMiqwHmDoDLiGtKGBR9UIOJzKKtlgjU4LtGPQeWApzYzDjxTvJ9enQfytcDm6Sc8ShwjvMk0OWpOOlFkhjGXApx2mnOzPhIZ3hnD8Myu/Nek/TcM9FiwpajuzNZG5hO5JUdx182QYBZ+M5WauerY3bf4e7lH5kXSFOA1fBlGRlxg0SQUP0Xi7X7JkK/BELxyY8UmSfsNAbfjOoQY7MLSt4MzyYXWQQHF3JbPTYuUzuPDea3YiydHF3U2WdvwjL4it7MbmKtzl6VLuF9ao1eGR7dvYRFy9CHcVitrS5XBdg0JEDnJFF3FasQEUUedh9ZLtqGDixBVifGMzSHDTsrzapRwbuDIInvr+9jyUuHUG061OexRzuUWIkCL8f5bNczcDeXhuZT7+nbEqttGEdSpL5Xb8TN4h1M8ed2rvrbTfC9wH31wchByvVbuz3fiY0JcslZSkDneMSv+43wl18QWHhDSq+Nk5UvxfAxcmbGngR/gG9M9rFmbggdfvYd6WjuoPrg2hzya9wwthSa8LrwmZvVzNTKJF/wpbrNZnsgH0SZ5eJzeH6zbxhqFvmWcFQTV619EPOHq+vyMQ5BmHq47d9F5InBZSp/l9kPV/HRpJC7DRC0g1f0fIcimrLomu1yju2r9fXy1/28t+PuHKDHr1nJOJM4DzUgNUu7MHhj+kb3ct5lqWE+dDwasxxHoneDzPlH3qdtPeAgyvLGsDczVVsSmCLNEX1EgBv9wPA7dcIes7TlV4ruJ8f71V4ZZHr9kXm0zzMoKBUL0dJtQoHaau5mIni+s/oA0eVLHtb4px6nJzvDAw9Dd3rgPwQh1x441wV2lUvTrNduQUkzVYlDUJ7NXQvU8UQQQRVs+lFQ4S3wbPZ3OYKMbkPfA3leTM/Zp1hsZzPDGjGhn8B9ryq+2PKVCzDLpfJCFromOq7+6CD07Z/lsdEwaG/HKX2xaCueVF1onoP4nspJ52BIBaT048JxpGnqy3PAchg6cLaUrtzdmfOYoYVL44QCzfD X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5b169f0c-bb3a-4045-bb8f-08d947266355 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2021 00:20:45.1772 (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: i9hFacJR5P+I1CYOcgGHvk3Qv0URWvZv9izThXG2q/UWmBssXLIodQpELbnKjMgU X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5555 Subject: [Intel-gfx] [PATCH 04/13] vfio/samples: Delete useless open/close 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: Max Gurtovoy , Yishai Hadas , Leon Romanovsky , "Raj, Ashok" , Christoph Hellwig Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" The core code no longer requires these ops to be defined, so delete these empty functions and leave the op as NULL. mtty's functions only log a pointless message, delete that entirely. Signed-off-by: Yishai Hadas Signed-off-by: Jason Gunthorpe Reviewed-by: Cornelia Huck --- samples/vfio-mdev/mbochs.c | 6 ------ samples/vfio-mdev/mdpy.c | 11 ----------- samples/vfio-mdev/mtty.c | 13 ------------- 3 files changed, 30 deletions(-) diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c index cf264d0bf11053..199273bebcc0e2 100644 --- a/samples/vfio-mdev/mbochs.c +++ b/samples/vfio-mdev/mbochs.c @@ -1274,11 +1274,6 @@ static long mbochs_ioctl(struct vfio_device *vdev, unsigned int cmd, return -ENOTTY; } -static int mbochs_open(struct vfio_device *vdev) -{ - return 0; -} - static void mbochs_close(struct vfio_device *vdev) { struct mdev_state *mdev_state = @@ -1397,7 +1392,6 @@ static struct attribute_group *mdev_type_groups[] = { }; static const struct vfio_device_ops mbochs_dev_ops = { - .open = mbochs_open, .release = mbochs_close, .read = mbochs_read, .write = mbochs_write, diff --git a/samples/vfio-mdev/mdpy.c b/samples/vfio-mdev/mdpy.c index 57334034cde6dd..8d1a80a0722aa9 100644 --- a/samples/vfio-mdev/mdpy.c +++ b/samples/vfio-mdev/mdpy.c @@ -614,15 +614,6 @@ static long mdpy_ioctl(struct vfio_device *vdev, unsigned int cmd, return -ENOTTY; } -static int mdpy_open(struct vfio_device *vdev) -{ - return 0; -} - -static void mdpy_close(struct vfio_device *vdev) -{ -} - static ssize_t resolution_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -717,8 +708,6 @@ static struct attribute_group *mdev_type_groups[] = { }; static const struct vfio_device_ops mdpy_dev_ops = { - .open = mdpy_open, - .release = mdpy_close, .read = mdpy_read, .write = mdpy_write, .ioctl = mdpy_ioctl, diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c index 37cc9067e1601d..5983cdb16e3d1d 100644 --- a/samples/vfio-mdev/mtty.c +++ b/samples/vfio-mdev/mtty.c @@ -1207,17 +1207,6 @@ static long mtty_ioctl(struct vfio_device *vdev, unsigned int cmd, return -ENOTTY; } -static int mtty_open(struct vfio_device *vdev) -{ - pr_info("%s\n", __func__); - return 0; -} - -static void mtty_close(struct vfio_device *mdev) -{ - pr_info("%s\n", __func__); -} - static ssize_t sample_mtty_dev_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -1325,8 +1314,6 @@ static struct attribute_group *mdev_type_groups[] = { static const struct vfio_device_ops mtty_dev_ops = { .name = "vfio-mtty", - .open = mtty_open, - .release = mtty_close, .read = mtty_read, .write = mtty_write, .ioctl = mtty_ioctl, From patchwork Thu Jul 15 00:20:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12378161 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CCAE9C12002 for ; Thu, 15 Jul 2021 00:21:17 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 9D73161374 for ; Thu, 15 Jul 2021 00:21:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9D73161374 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3D7226E52F; Thu, 15 Jul 2021 00:20:55 +0000 (UTC) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2056.outbound.protection.outlook.com [40.107.236.56]) by gabe.freedesktop.org (Postfix) with ESMTPS id CF81B6E516; Thu, 15 Jul 2021 00:20:49 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OM0ZcKR5yN5O2is0Nl+N1SO9aj25RxokStFiSlQZXGSRg8Ba11JbwXKt9Af96s+RLstzuftWbl9SGzVOCIh4TMjKDOHj7qxjU6t7oanzatm57+l7YMW3p4DaUiZQBKMNFhUG8KrEuMtNvVMjc0HPGIig+scKMWr+x0QiFCM5/zmFDjOMz6OvWBs8lvBw1w4yPBUK9cFJp5ALBcttGlrW+9FRlOKj6+WYkQ/975/2quq5doFhcRnsE7q0ib8hEWubswCVJog4QWov/iM3AnK2ldrwpqOOC4b/bw4l+LPBhSvpPeEF0yyjybNSVM6VV48l7jPcaVEVDnfKYQKSEJ8iew== 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-SenderADCheck; bh=TM2PVJURkDWq6j7394ivSAZ1BdF4hej2yhw25SJ2dmA=; b=QK6urmmqJ9/evaPW1iIYw+R//n469pnUgwZ6ZKyX0cYc6/P0XdlKGvJQ8YlilGHRl16/gNtLP6VD0OdnFjMx1YRb6g70DICAJg7NSZvIX7GaLG4jYxyLLS12WldKL/V2qPyWO/VakwvYsgJ7JfbF10mOxPkabIgtnMFowh22MhbyQbW62o3wOxEV1owZzQn7O+sTT4EcyabT2FE1HP6tkuge70zdhhnoSJ3NXyNVoaEjo2eC69pb6+jdpjPQyOfTXWaKylHXSbEvPl+myOa7Qtf7E3Rdqg8t71DPn0jnCJDiD11e3RBZI6v3//4HLvFBXDDfSUBqS2AhLg7g2h3UNA== 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=TM2PVJURkDWq6j7394ivSAZ1BdF4hej2yhw25SJ2dmA=; b=iw1r0Z9RmEnA3nARa0M0cgtpl0g59bQf5wzBAJ+++n2PgsW9ctbXBE0cInHtJPaoo5+2xd1Pye9aepM/uIu/4T37D0OFMDQp2ua4EnSsIWmDVM65AgIBCdeG8b3mt3f6FTADEFvSvt+SBJxBHE1qhvqz6O7eNv37DRkvRUdJyoceKTshu4QB9qlguHkrKhVS+txafWg+0Nzm1dBI06ZT64Zjvg4+HEjFKiawYdq7Nt1ODsKUJCe32g3IqwBXa+mdkOfLYDytooxrQf1Tw9FfReu8Wcne6Mf4cMMo2pDaYhb2OuLuqGyl9SP5tq2coOmmS6dLPqhpBCUelWKaHopyxA== Authentication-Results: linux.ie; dkim=none (message not signed) header.d=none;linux.ie; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL0PR12MB5555.namprd12.prod.outlook.com (2603:10b6:208:1c2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.26; Thu, 15 Jul 2021 00:20:48 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482%5]) with mapi id 15.20.4331.021; Thu, 15 Jul 2021 00:20:47 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , Daniel Vetter , Diana Craciun , dri-devel@lists.freedesktop.org, Eric Auger , 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 , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Date: Wed, 14 Jul 2021 21:20:34 -0300 Message-Id: <5-v1-eaf3ccbba33c+1add0-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v1-eaf3ccbba33c+1add0-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: CH0PR04CA0117.namprd04.prod.outlook.com (2603:10b6:610:75::32) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by CH0PR04CA0117.namprd04.prod.outlook.com (2603:10b6:610:75::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Thu, 15 Jul 2021 00:20:44 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m3p7K-002UxO-IT; Wed, 14 Jul 2021 21:20:42 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6be95ccb-b601-47e2-0cf4-08d9472662bd X-MS-TrafficTypeDiagnostic: BL0PR12MB5555: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: C6IAKcv8yyQQ1jk+WEgHbh6+9fqE7onQXWfj7W8uMVNIK6YITeDclLrSaUsksyW3zJ64PDVtqdCp/Og3nDLy3PyFmkV/XOCeebV3pwsH/IOTV/7j4N+u9e2O9DU+Y756yxSSR4muL+hjT+/vH35WLhtrGGbAOHIUFNa7CJn6EmGw2HRvgoDscf9aOvjLS/gtRZjRyeihUxdDHX4aDalo6HiTAihJR0E01xCDFXKcVB29fodr8XlwFPrEm6mz8xkkkGKa8lNG5Pf8pUKNwCp6pHKt5eibJ8q/SlnK7O+dqEN1PWE1Tbc1x0CrAJn3oi5KXAEyDJLOl3mkt5EeLsTjzPaKj7z9X2s5WsJ0ogz1jlrg8VcEADMAk1W0WKYnWjwhkyZe+A8ryjSKhkvr7LaoddW8nGiaT50IoMqWfAyUDb6dHqhifXaf5LflePYBAWDGVUgw7moFPe/vKx3jmQMING8YVMQAUjuvgHjsph1U5b5bC+zD7VaKpB39LK1l9pIL5Gfth7iwnXccUt7n01FCaRYKX+kjfXYwLOr5J2tOa3EEwd8YLhlBxb5yZFN2xNozHZxVKZqgFaLx0UEg2d/8e5SukuZg0S98vxSDLhOa3kSOxO7Ge80KqW3Dq7QneHwgijNo7LYBjMLkW7VwLXGiHupvtNvy9XNRel0XuI8Km/xafjr75u7n6GmT73ndmTMGmAm9stu/xMse3n/qxPUb4Q== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL0PR12MB5506.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(39860400002)(346002)(376002)(396003)(366004)(83380400001)(2616005)(426003)(316002)(107886003)(2906002)(478600001)(4326008)(7416002)(7406005)(38100700002)(36756003)(5660300002)(66556008)(66476007)(66946007)(921005)(9746002)(26005)(8936002)(110136005)(54906003)(8676002)(9786002)(86362001)(6666004)(186003)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: qQBq3nmJFheJP+uqj5CphcsdsXIcbWAbYDxcDsfTXgvyktJWVmIC15MPl12dH/uBGXHuSsWNEd3jf0cuU+QfeBskrRyc3FbXEJ1rmmmbJ61uQklB6q8Ycxe7MqtHx3G990llyZ0GA6vAKvhQfX9VOwZtpMQQyqXhc4WfM6O4laWWzbg5prr764tVTgIIgeM7NWIJ70YIPoixU0BhdmcyXprGHqtSKBtORYfTU/+VrEfamQ7sLsWRgvtOv4fOpcO8qqb9pD8LBTXSop3/tiyxzaVY/LdIK/rgeVQLnmOusSroA/QmB9Lb2KVjRTkSkvcfS3FMqFlWRvyb3Be/jz01dIeS4ArzMTQ62UXY11JGxLWzzX0ka+AjRQ8lTcvf8GK057FOLVfPKmDvvr2tiNp3XwzpxSij1k1KiT2pb9j3EC088+ULmyesvnSbyFvctgTwbE1uSvOxqNS45dwz2QRnTcbpwWatg8A3FRqy5YhetegOsTnPKeaiYFEkD9KQddAHyqlsn0AlGBHVQBph7FNpn5/xL2qp1UmF46sDqUy3ofa8KYLiVsA73DrntplpFWkZ68Mtdq4s1dO3ltz/kZ2du1XQeSe/F4RFkkdxhb6iUjLi9ivC7V7vxtmpPCWhbQBb1r7ObuzbxMapHc3oPCYJl5DUvE7WeVYJDWoPSeFnABwMWHR5v6lD+fR8cZdYvm2rafMbu01u0wxSFKsUxHhuJ3qbz9KTKLWCyH7/7odazL/mgUCCZ1C0qpdUwXxIu9PjXsLKkpCrmlRIlsFX3TnI8aJ0jE76wKLRJzhq2eMr06P8AJ8Loy2nlIA949r0hlwEjS37g4dAGzeHOie12bxMYhd44r0oqM+S1VaXdijtfvKO30Pfb7wOErQP78+epG1IzrFtXAQlfyVKK/qfjB4rlgSWpHwaZhKkBmO22Pl0aZLc/7wAIhiX9rvOHprHqvtQG2JfdMm9hKv6Z8M9V3l3uFXNudXFZwQVBhHjitlQODQ4VOOl28fP63lvlB0hXYW31vUV+Y0ahu1xwDUfyRWBOQTPan9H7L2B9cbLcKOztF0bRv60yJn8T9O/sMdJOJxYRFbn3E2T6kYyscchC++LJ8r/knW8x0hZOUE4qs4MeBGJN4S/GdoAlP26MPYLGfDklB/Sd7ZVBfYbszvsiijX2BBRHrxT1UGILbUqkivFODyo0bthlnR0hAHmijmo53DJI6rUmiXPjfFYTQU5wr0MVeUwKK1dvsRbD7S7XvDt1nG/jed/ctu3EZ4ob4tdbqT3SAyNl/gYUZGccNMY8Q1z1zjoOkDqvy0qrpN4jL6sIXxM5i4NwXnYlvSAbAuuDk86 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6be95ccb-b601-47e2-0cf4-08d9472662bd X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2021 00:20:44.3439 (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: uBBOvKMy5INt8TollOU5tfkC+j0z8Kq3OEvAL+wcA8bWprItofj8N0J3WqNN1ff+ X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5555 Subject: [Intel-gfx] [PATCH 05/13] vfio/fsl: Move to the device set infrastructure 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: Max Gurtovoy , Yishai Hadas , Leon Romanovsky , "Raj, Ashok" , Christoph Hellwig Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" FSL uses the internal reflck to implement the open_device() functionality, conversion to the core code is straightforward. The decision on which set to be part of is trivially based on the is_fsl_mc_bus_dprc() and we use a 'struct device *' pointer as the set_id. It isn't entirely clear what the device set lock is actually protecting, but I think it is related to the interrupt setup. Signed-off-by: Yishai Hadas Signed-off-by: Jason Gunthorpe --- drivers/vfio/fsl-mc/vfio_fsl_mc.c | 152 ++++------------------ drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c | 6 +- drivers/vfio/fsl-mc/vfio_fsl_mc_private.h | 7 - 3 files changed, 26 insertions(+), 139 deletions(-) diff --git a/drivers/vfio/fsl-mc/vfio_fsl_mc.c b/drivers/vfio/fsl-mc/vfio_fsl_mc.c index 3d2be06e1bc146..49b93de05d5d62 100644 --- a/drivers/vfio/fsl-mc/vfio_fsl_mc.c +++ b/drivers/vfio/fsl-mc/vfio_fsl_mc.c @@ -19,81 +19,10 @@ static struct fsl_mc_driver vfio_fsl_mc_driver; -static DEFINE_MUTEX(reflck_lock); - -static void vfio_fsl_mc_reflck_get(struct vfio_fsl_mc_reflck *reflck) -{ - kref_get(&reflck->kref); -} - -static void vfio_fsl_mc_reflck_release(struct kref *kref) -{ - struct vfio_fsl_mc_reflck *reflck = container_of(kref, - struct vfio_fsl_mc_reflck, - kref); - - mutex_destroy(&reflck->lock); - kfree(reflck); - mutex_unlock(&reflck_lock); -} - -static void vfio_fsl_mc_reflck_put(struct vfio_fsl_mc_reflck *reflck) -{ - kref_put_mutex(&reflck->kref, vfio_fsl_mc_reflck_release, &reflck_lock); -} - -static struct vfio_fsl_mc_reflck *vfio_fsl_mc_reflck_alloc(void) -{ - struct vfio_fsl_mc_reflck *reflck; - - reflck = kzalloc(sizeof(*reflck), GFP_KERNEL); - if (!reflck) - return ERR_PTR(-ENOMEM); - - kref_init(&reflck->kref); - mutex_init(&reflck->lock); - - return reflck; -} - -static int vfio_fsl_mc_reflck_attach(struct vfio_fsl_mc_device *vdev) -{ - int ret = 0; - - mutex_lock(&reflck_lock); - if (is_fsl_mc_bus_dprc(vdev->mc_dev)) { - vdev->reflck = vfio_fsl_mc_reflck_alloc(); - ret = PTR_ERR_OR_ZERO(vdev->reflck); - } else { - struct device *mc_cont_dev = vdev->mc_dev->dev.parent; - struct vfio_device *device; - struct vfio_fsl_mc_device *cont_vdev; - - device = vfio_device_get_from_dev(mc_cont_dev); - if (!device) { - ret = -ENODEV; - goto unlock; - } - - cont_vdev = - container_of(device, struct vfio_fsl_mc_device, vdev); - if (!cont_vdev || !cont_vdev->reflck) { - vfio_device_put(device); - ret = -ENODEV; - goto unlock; - } - vfio_fsl_mc_reflck_get(cont_vdev->reflck); - vdev->reflck = cont_vdev->reflck; - vfio_device_put(device); - } - -unlock: - mutex_unlock(&reflck_lock); - return ret; -} - -static int vfio_fsl_mc_regions_init(struct vfio_fsl_mc_device *vdev) +static int vfio_fsl_mc_open_device(struct vfio_device *core_vdev) { + struct vfio_fsl_mc_device *vdev = + container_of(core_vdev, struct vfio_fsl_mc_device, vdev); struct fsl_mc_device *mc_dev = vdev->mc_dev; int count = mc_dev->obj_desc.region_count; int i; @@ -136,58 +65,30 @@ static void vfio_fsl_mc_regions_cleanup(struct vfio_fsl_mc_device *vdev) kfree(vdev->regions); } -static int vfio_fsl_mc_open(struct vfio_device *core_vdev) -{ - struct vfio_fsl_mc_device *vdev = - container_of(core_vdev, struct vfio_fsl_mc_device, vdev); - int ret = 0; - - mutex_lock(&vdev->reflck->lock); - if (!vdev->refcnt) { - ret = vfio_fsl_mc_regions_init(vdev); - if (ret) - goto out; - } - vdev->refcnt++; -out: - mutex_unlock(&vdev->reflck->lock); - return ret; -} - -static void vfio_fsl_mc_release(struct vfio_device *core_vdev) +static void vfio_fsl_mc_close_device(struct vfio_device *core_vdev) { struct vfio_fsl_mc_device *vdev = container_of(core_vdev, struct vfio_fsl_mc_device, vdev); + struct fsl_mc_device *mc_dev = vdev->mc_dev; + struct device *cont_dev = fsl_mc_cont_dev(&mc_dev->dev); + struct fsl_mc_device *mc_cont = to_fsl_mc_device(cont_dev); int ret; - mutex_lock(&vdev->reflck->lock); + vfio_fsl_mc_regions_cleanup(vdev); - if (!(--vdev->refcnt)) { - struct fsl_mc_device *mc_dev = vdev->mc_dev; - struct device *cont_dev = fsl_mc_cont_dev(&mc_dev->dev); - struct fsl_mc_device *mc_cont = to_fsl_mc_device(cont_dev); - - vfio_fsl_mc_regions_cleanup(vdev); + /* reset the device before cleaning up the interrupts */ + ret = dprc_reset_container(mc_cont->mc_io, 0, mc_cont->mc_handle, + mc_cont->obj_desc.id, + DPRC_RESET_OPTION_NON_RECURSIVE); - /* reset the device before cleaning up the interrupts */ - ret = dprc_reset_container(mc_cont->mc_io, 0, - mc_cont->mc_handle, - mc_cont->obj_desc.id, - DPRC_RESET_OPTION_NON_RECURSIVE); + if (WARN_ON(ret)) + dev_warn(&mc_cont->dev, + "VFIO_FLS_MC: reset device has failed (%d)\n", ret); - if (ret) { - dev_warn(&mc_cont->dev, "VFIO_FLS_MC: reset device has failed (%d)\n", - ret); - WARN_ON(1); - } + vfio_fsl_mc_irqs_cleanup(vdev); - vfio_fsl_mc_irqs_cleanup(vdev); - - fsl_mc_cleanup_irq_pool(mc_cont); - } - - mutex_unlock(&vdev->reflck->lock); + fsl_mc_cleanup_irq_pool(mc_cont); } static long vfio_fsl_mc_ioctl(struct vfio_device *core_vdev, @@ -504,8 +405,8 @@ static int vfio_fsl_mc_mmap(struct vfio_device *core_vdev, static const struct vfio_device_ops vfio_fsl_mc_ops = { .name = "vfio-fsl-mc", - .open = vfio_fsl_mc_open, - .release = vfio_fsl_mc_release, + .open_device = vfio_fsl_mc_open_device, + .close_device = vfio_fsl_mc_close_device, .ioctl = vfio_fsl_mc_ioctl, .read = vfio_fsl_mc_read, .write = vfio_fsl_mc_write, @@ -625,13 +526,15 @@ static int vfio_fsl_mc_probe(struct fsl_mc_device *mc_dev) vdev->mc_dev = mc_dev; mutex_init(&vdev->igate); - ret = vfio_fsl_mc_reflck_attach(vdev); + ret = vfio_assign_device_set(&vdev->vdev, is_fsl_mc_bus_dprc(mc_dev) ? + &mc_dev->dev : + mc_dev->dev.parent); if (ret) goto out_uninit; ret = vfio_fsl_mc_init_device(vdev); if (ret) - goto out_reflck; + goto out_uninit; ret = vfio_register_group_dev(&vdev->vdev); if (ret) { @@ -639,12 +542,6 @@ static int vfio_fsl_mc_probe(struct fsl_mc_device *mc_dev) goto out_device; } - /* - * This triggers recursion into vfio_fsl_mc_probe() on another device - * and the vfio_fsl_mc_reflck_attach() must succeed, which relies on the - * vfio_add_group_dev() above. It has no impact on this vdev, so it is - * safe to be after the vfio device is made live. - */ ret = vfio_fsl_mc_scan_container(mc_dev); if (ret) goto out_group_dev; @@ -655,8 +552,6 @@ static int vfio_fsl_mc_probe(struct fsl_mc_device *mc_dev) vfio_unregister_group_dev(&vdev->vdev); out_device: vfio_fsl_uninit_device(vdev); -out_reflck: - vfio_fsl_mc_reflck_put(vdev->reflck); out_uninit: vfio_uninit_group_dev(&vdev->vdev); kfree(vdev); @@ -676,7 +571,6 @@ static int vfio_fsl_mc_remove(struct fsl_mc_device *mc_dev) dprc_remove_devices(mc_dev, NULL, 0); vfio_fsl_uninit_device(vdev); vfio_uninit_group_dev(&vdev->vdev); - vfio_fsl_mc_reflck_put(vdev->reflck); kfree(vdev); vfio_iommu_group_put(mc_dev->dev.iommu_group, dev); diff --git a/drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c b/drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c index 0d9f3002df7f51..77e584093a233d 100644 --- a/drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c +++ b/drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c @@ -120,7 +120,7 @@ static int vfio_fsl_mc_set_irq_trigger(struct vfio_fsl_mc_device *vdev, if (start != 0 || count != 1) return -EINVAL; - mutex_lock(&vdev->reflck->lock); + mutex_lock(&vdev->vdev.dev_set->lock); ret = fsl_mc_populate_irq_pool(mc_cont, FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS); if (ret) @@ -129,7 +129,7 @@ static int vfio_fsl_mc_set_irq_trigger(struct vfio_fsl_mc_device *vdev, ret = vfio_fsl_mc_irqs_allocate(vdev); if (ret) goto unlock; - mutex_unlock(&vdev->reflck->lock); + mutex_unlock(&vdev->vdev.dev_set->lock); if (flags & VFIO_IRQ_SET_DATA_EVENTFD) { s32 fd = *(s32 *)data; @@ -154,7 +154,7 @@ static int vfio_fsl_mc_set_irq_trigger(struct vfio_fsl_mc_device *vdev, return 0; unlock: - mutex_unlock(&vdev->reflck->lock); + mutex_unlock(&vdev->vdev.dev_set->lock); return ret; } diff --git a/drivers/vfio/fsl-mc/vfio_fsl_mc_private.h b/drivers/vfio/fsl-mc/vfio_fsl_mc_private.h index 89700e00e77d10..4ad63ececb914b 100644 --- a/drivers/vfio/fsl-mc/vfio_fsl_mc_private.h +++ b/drivers/vfio/fsl-mc/vfio_fsl_mc_private.h @@ -22,11 +22,6 @@ struct vfio_fsl_mc_irq { char *name; }; -struct vfio_fsl_mc_reflck { - struct kref kref; - struct mutex lock; -}; - struct vfio_fsl_mc_region { u32 flags; u32 type; @@ -39,9 +34,7 @@ struct vfio_fsl_mc_device { struct vfio_device vdev; struct fsl_mc_device *mc_dev; struct notifier_block nb; - int refcnt; struct vfio_fsl_mc_region *regions; - struct vfio_fsl_mc_reflck *reflck; struct mutex igate; struct vfio_fsl_mc_irq *mc_irqs; }; From patchwork Thu Jul 15 00:20:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12378171 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 962FEC47E4E for ; Thu, 15 Jul 2021 00:21:26 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 6F4E2613D1 for ; Thu, 15 Jul 2021 00:21:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6F4E2613D1 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C18456E52D; Thu, 15 Jul 2021 00:21:00 +0000 (UTC) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2056.outbound.protection.outlook.com [40.107.236.56]) by gabe.freedesktop.org (Postfix) with ESMTPS id 592636E51B; Thu, 15 Jul 2021 00:20:50 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UHxV2/RzbBn/UKk8XTrBPDeHXR0JqOhK6ShmYM46FDgoVQ48fXXzpRp1i+HTRbhT/aavBtZ8i3uy0LV997v9fkM+flRsr9wDqWT+I/O40jMW1UAIYA4wI1Jrkvc9ItXvRYC2DlYO+1MEIrWT3iz2i11sKhhhau2FNOPpqkSysFP8ZCoLENzb3UOrlGDC5hxL8jf+ek8P+XGcolvkjOpEglBu+ZsPGCHWXlZPKfkQ2+FYDMZvnnLme2XWnW0cPKlxUdUKE75jV5ZIb0vSH8NDt9+Lotr2cvobgHEYupLdAXzZGM95apMXJd4oyLJ2DZFSP2updmzsVwPejqGMdydZmQ== 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-SenderADCheck; bh=g+yjMYhEcWEUEqiPJn9wZH0hUqIDhNY47wOx5CFzXys=; b=mO66F2a90khiqR5w5hX2a3uNRGLAYezU23s2ntXbJaMMIwMScky4umcWvxPUFaLpzdUZWCYKZ6Wj2CuN3UHbyZqbuHeAPLKhuD1U7xuwamS3Gf+ZEyFuoWD3RWZLwjRMFUeWwWLIH+IF50CPTp4a97nom55IyXu91ikmi/LKBZIuS3mYQsVvqqMBfpQ7sWd0Y74QXhM63KzfR9EFOW0enHazNSMgWqDbvB4FvGspC+AuTSCq7xzKsWnBl2eT4yxPB5EbLAZbJQ43IV7vnwrcuGDfjHOQJ/xTDFji5sYgai7l7KqlJzDr/VMdoX3V9F5ZhC3ur3KkBkaHBthFwVPmtQ== 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=g+yjMYhEcWEUEqiPJn9wZH0hUqIDhNY47wOx5CFzXys=; b=bOpw6r8nH3/yPKPbeUrDdrvMOvheXiTIJGFLDGUmFZ2Xyhgm0RpKha+6pbhJCltKzjIQerYHm+l4yloLmQFkhGeYFGyWEUkd8d7afooWDlQQfBFVllolU5R2T2gsGOzGUEXiiUtY1/Waie1aSAYPmH5lEMDJh8AnHVKOC+ng5qlZX79Oe2DL5Xo3jSFGVFaUKuEWHl+tckNbYruoaS4FC4gyjFIoQVNm7AHUyCYTXtlCSJlQva/oMKcas2WK939q24ICnZbUh20gZGT5qTg/UOWRoFsN45229qXfJ9PEePJ32g65zAjRA1J7d38KYSByOmpz03VZk0yFGxRhQislTQ== Authentication-Results: linux.ie; dkim=none (message not signed) header.d=none;linux.ie; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL0PR12MB5555.namprd12.prod.outlook.com (2603:10b6:208:1c2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.26; Thu, 15 Jul 2021 00:20:49 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482%5]) with mapi id 15.20.4331.021; Thu, 15 Jul 2021 00:20:49 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , Daniel Vetter , Diana Craciun , dri-devel@lists.freedesktop.org, Eric Auger , 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 , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Date: Wed, 14 Jul 2021 21:20:35 -0300 Message-Id: <6-v1-eaf3ccbba33c+1add0-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v1-eaf3ccbba33c+1add0-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: CH0PR03CA0013.namprd03.prod.outlook.com (2603:10b6:610:b0::18) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by CH0PR03CA0013.namprd03.prod.outlook.com (2603:10b6:610:b0::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Thu, 15 Jul 2021 00:20:45 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m3p7K-002UxR-Kq; Wed, 14 Jul 2021 21:20:42 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cdf05dac-0aaa-42e1-e5e4-08d94726635a X-MS-TrafficTypeDiagnostic: BL0PR12MB5555: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:826; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZrtXtPts6iNtcVUbj87slgKqm9fnkc3a02GPBJTis7YRIQ5QUw6C9/lre5AXIsP92h8VB4Vonn7bKnBUYsf0m6/FH9jS6Stu9xkmqqXD2GYn0CkBEGTerqju/rWBHZ6lUzX9bm6r9jHIAQh1OId7U6TxtZRFKxtLZPn3uiGih9Ah9oI9UxQH1+SG+INypsR/4A3LSwqKLd8A8OETY5q+ZmouiZRZSI0PFpEvIUFC3SgpyNsvT1LVnsC8VPXAGq4ViWCwQKWgRFNg6f8/2vYrndXWISMBD6pmMTggveiSVaGQZWcIr+BmNjBaWBmi2HjV5MwlbYI/lUu9c2l/Z4HVw6DED9jrIXbuuqxyHveSd4lzzhut749+3LkjZZC0NvEhF5OLlutPbefeEgdtuubChwFAmmyTFXqhrYCMRdgbCUGpdTYy7jZRZSYEcaRSdUgD99qT4wKEHba98LjPJBDP5wZOWfWuIEMcpQhVCLFtawD7afen8foe2dCD6ZEGFtZnJOFR1DOwkCMylJM8UF6rPH6GifdAeEZC1EvBCctct7HeU8zk02TTGPRKT3WJ0KX0E7yZqTeV8uxFRejNSNSicjQ+DWn1LkWvjBr9d1ttP+zWJ3zPBPEFgjzwzQJuVpnyLsrEGUSZ89pH9yjsqY202iZlAg21HzX5JgioBZ44w8z5Zg3Csz8I38adwgNTSmdJyUuhNlG25lVdPygOTBAdUQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL0PR12MB5506.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(39860400002)(346002)(376002)(396003)(366004)(83380400001)(2616005)(426003)(316002)(107886003)(2906002)(478600001)(4326008)(7416002)(7406005)(38100700002)(36756003)(5660300002)(66556008)(66476007)(66946007)(921005)(9746002)(26005)(8936002)(110136005)(54906003)(8676002)(9786002)(86362001)(6666004)(186003)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DxO8l6w6dcxn9b+0UyRXv6l2djI/YMJxbaFqLO0KXzN1wysiMdb8+1JOkFremja7PLXXhGC9HdNw6RogjRlQ2Tjioyarn8yufnmso8FKXRbXvuqbP315yp31Po6Sa93rmQ2Pi+12xdDPyiCa3JDmtEwz8DajBanfQH7ZFyKHRKim9Aj20XmLEgmcjTwMWjOadJRCXkvavSCPZomT9wWQkYKbtkChNtME4FgCNMWXJ91JcmwNLrq75N0Ow8+4Rh79sJqumz/Lu4W0wJWV2p6LGBq7iaF0UjqpzrlBO7MGURUng/rUbotD9Rzl+vpgKz3uGyOOBEUCB1e4K8aV45hsxLk96IHeo2yFyBHWyqsPHgK0Px+tP6ln8RLato908gGSfZWtFft+hnEaaxS6fNPxCn0lCd0x6B9CcJgfAPQa8qogHWNCfD3zUt3a6d+brKb69bDK+5WTdbbmNTMvuxxcKWs+BttElBeS0jj4NwIsLE+pe8y3qPHMsg7QzYdReqcfAybx8W8LGGECn3pr/SqwdGubeuagQEvZpBqLCELkCZ3VwcezzLctsd/rQde3Nw1F/Ii0rNkf+nY5YIUEDDuIDGGr4XxbZZZhS4VgdXFSoSOcNWccaC1tKma1CRYgC0t4mIynDgXEUHC1xtTABhesvR9xwnyMErifQySEB0eaL3dTQI4rGGX8b60n99BhoXku0V30Lxt2QzhvsiruhliJ/+3avi5Bl0fRPh2sOgqbullpJI2Flmf3JAfMHBVXnJr+YFlhR9rTxv0IgKBOTB6GLjc+xf7H/mL4WiS0LrsXvp6G9d593y58U/6hXOKyGTuZl3j0Cjpv3XWyNBiNldoEYfc80fOAJohKKpxUDMamSYz2w2/v0plVS1aX7g1BhZrFAsLjwVyfmA2TiaFxMaVA99+yvM0Z3MTV4UW1XZpVW0p/OSWcLAZGwgRtKEzb87eT76nqNh2tkrQ94H4Hx84DCOw36/kjPDkzDDt9XaS20xaoAhD7AzbREyNzC6fcnDitDieNY53ZWf3lO7wQdAefyT6cwvHor0+hnsu8Grak5rIMwl7+WHYDnExcqJ6E19z/LsD6CdoiH2VLI3P5/eeJ63VN25k6K28cW+l5HspI8QiguDvzGvElIj6mBu6Qiu1sIBT5AIC7/qqcZtrcV0xQMBEDu6H0uD7loyB7NRXa3knQFLo/psozi1euIvR+kwKApFp4K0pYhhWKjntMGnmP7hUyXuRsf7s+seAbnn2tYJbi1lYutnnesPTm3g8VcisIXILT4N4WalumDDvJ8S/TgRLRbQE0XpWcnCSgfgOQFqomOABcGJp97qyNJ5+hoqy+ X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: cdf05dac-0aaa-42e1-e5e4-08d94726635a X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2021 00:20:45.2011 (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: +ZqH0BUQeSxZ/bVs4yAW9L4GYsr62W2vdnHYU0Kq/IwlwRDAJh5ccLyVDlsg0TOC X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5555 Subject: [Intel-gfx] [PATCH 06/13] vfio/platform: Use open_device() instead of open coding a refcnt scheme 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: Max Gurtovoy , Yishai Hadas , Leon Romanovsky , "Raj, Ashok" , Christoph Hellwig Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Platform simply wants to run some code when the device is first opened/last closed. Use the core framework and locking for this. Aside from removing a bit of code this narrows the locking scope from a global lock. Signed-off-by: Yishai Hadas Signed-off-by: Jason Gunthorpe --- drivers/vfio/platform/vfio_platform_common.c | 79 ++++++++----------- drivers/vfio/platform/vfio_platform_private.h | 1 - 2 files changed, 32 insertions(+), 48 deletions(-) diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c index bdde8605178cd2..6af7ce7d619c25 100644 --- a/drivers/vfio/platform/vfio_platform_common.c +++ b/drivers/vfio/platform/vfio_platform_common.c @@ -218,65 +218,52 @@ static int vfio_platform_call_reset(struct vfio_platform_device *vdev, return -EINVAL; } -static void vfio_platform_release(struct vfio_device *core_vdev) +static void vfio_platform_close_device(struct vfio_device *core_vdev) { struct vfio_platform_device *vdev = container_of(core_vdev, struct vfio_platform_device, vdev); + const char *extra_dbg = NULL; + int ret; - mutex_lock(&driver_lock); - - if (!(--vdev->refcnt)) { - const char *extra_dbg = NULL; - int ret; - - ret = vfio_platform_call_reset(vdev, &extra_dbg); - if (ret && vdev->reset_required) { - dev_warn(vdev->device, "reset driver is required and reset call failed in release (%d) %s\n", - ret, extra_dbg ? extra_dbg : ""); - WARN_ON(1); - } - pm_runtime_put(vdev->device); - vfio_platform_regions_cleanup(vdev); - vfio_platform_irq_cleanup(vdev); + ret = vfio_platform_call_reset(vdev, &extra_dbg); + if (WARN_ON(ret && vdev->reset_required)) { + dev_warn( + vdev->device, + "reset driver is required and reset call failed in release (%d) %s\n", + ret, extra_dbg ? extra_dbg : ""); } - - mutex_unlock(&driver_lock); + pm_runtime_put(vdev->device); + vfio_platform_regions_cleanup(vdev); + vfio_platform_irq_cleanup(vdev); } -static int vfio_platform_open(struct vfio_device *core_vdev) +static int vfio_platform_open_device(struct vfio_device *core_vdev) { struct vfio_platform_device *vdev = container_of(core_vdev, struct vfio_platform_device, vdev); + const char *extra_dbg = NULL; int ret; - mutex_lock(&driver_lock); - - if (!vdev->refcnt) { - const char *extra_dbg = NULL; - - ret = vfio_platform_regions_init(vdev); - if (ret) - goto err_reg; + ret = vfio_platform_regions_init(vdev); + if (ret) + return ret; - ret = vfio_platform_irq_init(vdev); - if (ret) - goto err_irq; + ret = vfio_platform_irq_init(vdev); + if (ret) + goto err_irq; - ret = pm_runtime_get_sync(vdev->device); - if (ret < 0) - goto err_rst; + ret = pm_runtime_get_sync(vdev->device); + if (ret < 0) + goto err_rst; - ret = vfio_platform_call_reset(vdev, &extra_dbg); - if (ret && vdev->reset_required) { - dev_warn(vdev->device, "reset driver is required and reset call failed in open (%d) %s\n", - ret, extra_dbg ? extra_dbg : ""); - goto err_rst; - } + ret = vfio_platform_call_reset(vdev, &extra_dbg); + if (ret && vdev->reset_required) { + dev_warn( + vdev->device, + "reset driver is required and reset call failed in open (%d) %s\n", + ret, extra_dbg ? extra_dbg : ""); + goto err_rst; } - - vdev->refcnt++; - - mutex_unlock(&driver_lock); return 0; err_rst: @@ -284,8 +271,6 @@ static int vfio_platform_open(struct vfio_device *core_vdev) vfio_platform_irq_cleanup(vdev); err_irq: vfio_platform_regions_cleanup(vdev); -err_reg: - mutex_unlock(&driver_lock); return ret; } @@ -616,8 +601,8 @@ static int vfio_platform_mmap(struct vfio_device *core_vdev, struct vm_area_stru static const struct vfio_device_ops vfio_platform_ops = { .name = "vfio-platform", - .open = vfio_platform_open, - .release = vfio_platform_release, + .open_device = vfio_platform_open_device, + .close_device = vfio_platform_close_device, .ioctl = vfio_platform_ioctl, .read = vfio_platform_read, .write = vfio_platform_write, diff --git a/drivers/vfio/platform/vfio_platform_private.h b/drivers/vfio/platform/vfio_platform_private.h index dfb834c1365946..520d2a8e8375b2 100644 --- a/drivers/vfio/platform/vfio_platform_private.h +++ b/drivers/vfio/platform/vfio_platform_private.h @@ -48,7 +48,6 @@ struct vfio_platform_device { u32 num_regions; struct vfio_platform_irq *irqs; u32 num_irqs; - int refcnt; struct mutex igate; const char *compat; const char *acpihid; From patchwork Thu Jul 15 00:20:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12378173 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E318C47E4B for ; Thu, 15 Jul 2021 00:21:26 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 042F761374 for ; Thu, 15 Jul 2021 00:21:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 042F761374 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 85C216E4EC; Thu, 15 Jul 2021 00:21:00 +0000 (UTC) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) by gabe.freedesktop.org (Postfix) with ESMTPS id 74E956E516; Thu, 15 Jul 2021 00:20:51 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WEci8HHNGvoA0aKiYSRiAmaEnzwTtdZTKhuT2IukIHVY+Bnfh0nw7asIEEVSEYstTRByIMaKR5SWyo60c25OA3eAnSoL7XNdEggUC5y3GupHFIglwAjLOtoN2s8qHsjoPPfmRKCwB9lgsDKUmjaAhGpw90feZGYO04yReSipg01QsnXxm3vw4AHMQarVg2QUmzVWKMFTltohlCHlxgjsKqYfrmXz3yPjjGRC0dMouyMtGci+KX5DONMRqyeeio8j0pp5CL54D3Zbh/u6VzoIZgQ7qUWASvjzTc6gH0DUMMG8/egJvPnSlqIV8DDk6Uj8dhf/1ArJQQCOp2UxdgGc2w== 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-SenderADCheck; bh=pfSzLrWx9phOGS1Ir9TXtZygWdUrRCe/TL6aPalVd/Q=; b=eDE5LasGq6rCZwzcsZYd3ZieXzYWlaAaRI/lUitRnvjap8SKFXBE4RUQCRhTPlixMDDZvBX9v/bjlgJGd0pnL+z7TFpN4QQUDbNk/5RmG6BKj55Bvio0rNNhACV6QkUEPmOyWjZjBgWWIy9uaxUd29rQHBjBFg86hsQvsUU0ojeuftAV/bOj4lrl0z5sdJHDSZ/T8wup7txY4Ih/gygjEayvXmWaQlPTwumhCEnzUEaHlomHNi35zty77h96Ucyy3wmXTINcly17viK2xgDb5s2PNPM3k99uORUHtXsNHNF6Mnrzu4fjQ+s0kbvHwuz0kaMZi8ve1kkhmrtGJ0JfXg== 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=pfSzLrWx9phOGS1Ir9TXtZygWdUrRCe/TL6aPalVd/Q=; b=IdX99UaGupvmFeDH0ltspNAuUdVGQRCTJzVzkLvKCphk6acC66+iD2qr35uPimeSHClmeIycZ4F7repeDaha+L0yTboTSSxNI428nxe/SX7A3AKC+yrCsGlukvp4xuat8PUfU9baCcCFo6S8di2NeM6fYseBio3ZMzsvZlbcGcIM08ab89B6frbheW/Usbw1LXylQ/Pv1C/XVTmJyz1UV5vFry5laqHxm5eUYfexUzjYqJOYCqZiaPIvRU9FuPkk6yqTRDSk5GmGOdjet/FOpwuxcVR6UT8mFIiwmYC6Pj1waEbadEWM7QnhAABT/UeyCNQJyZl02Ht6hZW6nL+Mqg== Authentication-Results: linux.ie; dkim=none (message not signed) header.d=none;linux.ie; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL0PR12MB5555.namprd12.prod.outlook.com (2603:10b6:208:1c2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.26; Thu, 15 Jul 2021 00:20:49 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482%5]) with mapi id 15.20.4331.021; Thu, 15 Jul 2021 00:20:49 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , Daniel Vetter , Diana Craciun , dri-devel@lists.freedesktop.org, Eric Auger , 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 , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Date: Wed, 14 Jul 2021 21:20:36 -0300 Message-Id: <7-v1-eaf3ccbba33c+1add0-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v1-eaf3ccbba33c+1add0-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: CH2PR08CA0025.namprd08.prod.outlook.com (2603:10b6:610:5a::35) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by CH2PR08CA0025.namprd08.prod.outlook.com (2603:10b6:610:5a::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.22 via Frontend Transport; Thu, 15 Jul 2021 00:20:45 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m3p7K-002UxV-MR; Wed, 14 Jul 2021 21:20:42 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 551bdec9-9e25-4c31-3d0c-08d947266352 X-MS-TrafficTypeDiagnostic: BL0PR12MB5555: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: r1YJrV+YfpAFHSADfVEwSZyQTQFqXQCiMDki1VO+hEPKHRwuP9EheuLyPSPIWCqaCfG6NJze7DTV75l55I1cYlYnjXJH5FTRnoL+SRQl+S4Sg8TCnBNbT8Ko07xxffb8A2niUNwTGWr/Hz/fJuCi5LQm85vTNETMn2eoMkmnEDKXLOPtgGENH+82H9EUjrQ9qdaep8gpwvZGPxxrcHXs1wfhBmweaVJ7dXvd4pX1xikN/0npZ1HCOSD3tAgT/6gy/O0mdKkIlimLk/f7Cp2JicJRk1H/WGr+45hWfHxOK9cpsgBkmkv4UuHf1WXIhTTL4/Ewrp692e0TheUYsh6f+XfFBR4SQXGnkbsdDSMJbGLF6qJDW0KbcrVhjKluj7vWP1bz776zNE8arJ42x0Cy5tcpH8f9wRLupn90Ah3CDgt2o/nFRTZmq4r7FNR0VkijOYeLCkSVZyI3H1roczah4UjUgTY2/IGfJ3/olE6cb168k4ORjIz2XIczb0kN5UXfZ+UMm00h4KTr3BlORRnAcMu59WOGonLSr3AKn2IS4pfiJLX6KeuAPDFGzl9Koed0cbitce8clhxHdi0KSsyWEFr2/IS6d0FcCC8wA82AUtNSwX1ED/j5k9qCWXmWuvAy2/xe3w6tmw0vg7hfKhv1s3Kozniy+YZxQy3AaSlHd2et7I9xwUCcykeUXJc0FV9MY69OxaNWCzKQqECERVxsUg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL0PR12MB5506.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(39860400002)(346002)(376002)(396003)(366004)(83380400001)(2616005)(426003)(316002)(107886003)(2906002)(478600001)(4326008)(7416002)(7406005)(38100700002)(36756003)(5660300002)(66556008)(66476007)(66946007)(921005)(9746002)(26005)(8936002)(110136005)(54906003)(8676002)(9786002)(86362001)(6666004)(186003)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QZeAaeEDYX6NMy3eXhUUCu86jGiIBWvUnt2xJbKaULZprjZyccgUQ9yHX3QmeeqnkAkCJbp7HG1stmjgMbmCPm+MghTLetgcjdOqhVGvnuPIRd3lvA0u8BNyILBNAje8nc/LNdxeL/C9iIrj7rlWsyEZhi25gRRuAYwtAWZhXUrW78b1EggasiOlnsBSLiSoiiiloVXysw7gVnDTIWCL5vbKK3RWT9QADRtGcRQvyvcgrhMPR5D79gYrH3POQEpLEygjN7HGlV544y7ts92Xz1L3e/CpqlY8g6usdr6OKsL6SUliUT3Mhqk0rs5LordIkGsHI7xotbAsN+/IzwQkOZuXMIA9ERpDT4YoOJPCvaKIzI51pCfLNbD+tKwC9lo0GPTu9YFKRdYyR5Rv0JEVn52J9Ms2fpkSS0YCtTgeRz/99GaV8j7UEiRvWI7o8adrHmCN8IGg2RMRfc5XZOl23VAOfBDNz8fcBjx5OglGb01K5kaCGIsefqktaZHAqGKB51a0412x1cJ8vnN/K1syKNJnq3KvVV8hcS4Cr0OG0hIXsA/Qu8HI9+Q7pntwa+RX/isXtHtXFxzyl19hcf3yMAs/jOnyutWxQswGYL3Jn6IMcmSBvm34WZRrQJaBFAwuUavemttPTDNgFhlH7RlP3NPjLjWVSJ3Lb/dVDhSYiUizmzRXxj174vBGTD1jkHNkxbvKna821/HpJstMr++kKL3SsvnxCf78HCAZtNW1pf/0cBk8C/ZYgU8jc3VHj/i2gM6Kv8yW+nCPpgA02BDLVAFaXe+5CeItlUchiCCxLnAUBEJudGe+rMu32j4jZ7hOCG7uv0wH4JAza9baUgMWMGldjH/obnpLPRoEUVJaXOq+zj08oWm3CQHwCGYLENrredW3uCIuEEDRgVoxHzrQbt6+N48mThy1uJcYq/Fm+InH2TUjv/N2x3Re0BDTD2YUweY5RzJir21ligP3YdkKC9LCRERede8SlGzduIK1KjfUuZM+Z61Cl7cjo88fQrGumGQMlJ/4GXafoyXq1ZlO2H0OjdfDgmU0KAhYKnBOq7A34jngBMLn3YquTz0YZ3TMfVfYflTyd81Ni7ZI/GE/cj3zQp+jh8ew3qswbZbqP29KyrPVBEznHS+EFITeGwL9NdbITL3e/Ca/QTeDO5xIOqPeXupLLgZSyBukxqCiKUuiIgQ6VfMcKNBDGfLIL+rVIHPngYjLzROSU8SM9HjT5Qz9I/N7H4INaXK913FAs5UywT8LXWOASOiIe2KhxR+r3pDm72yogt77F62OjUIf7kv/4vWr3QfHSTmecT7XPVuy2u+RTFk21YpT/5oJQGtw X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 551bdec9-9e25-4c31-3d0c-08d947266352 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2021 00:20:45.2350 (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: E6lBRbPCxLhI3SHB0akiV6pe2eUkkA3noBnuq7dNiOo7YE8/dC1/4duUR5rPzreA X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5555 Subject: [Intel-gfx] [PATCH 07/13] vfio/pci: Move to the device set infrastructure 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: Max Gurtovoy , Yishai Hadas , Leon Romanovsky , "Raj, Ashok" , Christoph Hellwig Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Yishai Hadas PCI wants to have the usual open/close_device() logic with the slight twist that the open/close_device() must be done under a singelton lock shared by all of the vfio_devices that are in the PCI "reset group". The reset group, and thus the device set, is determined by what devices pci_reset_bus() touches, which is either the entire bus or only the slot. Rely on the core code to do everything reflck was doing and delete reflck entirely. Signed-off-by: Yishai Hadas Signed-off-by: Jason Gunthorpe --- drivers/vfio/pci/vfio_pci.c | 156 ++++++---------------------- drivers/vfio/pci/vfio_pci_private.h | 7 -- 2 files changed, 31 insertions(+), 132 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index fab3715d60d4ba..22774e447b5f4a 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -530,53 +530,40 @@ static void vfio_pci_vf_token_user_add(struct vfio_pci_device *vdev, int val) vfio_device_put(&pf_vdev->vdev); } -static void vfio_pci_release(struct vfio_device *core_vdev) +static void vfio_pci_close_device(struct vfio_device *core_vdev) { struct vfio_pci_device *vdev = container_of(core_vdev, struct vfio_pci_device, vdev); - mutex_lock(&vdev->reflck->lock); - - if (!(--vdev->refcnt)) { - vfio_pci_vf_token_user_add(vdev, -1); - vfio_spapr_pci_eeh_release(vdev->pdev); - vfio_pci_disable(vdev); + vfio_pci_vf_token_user_add(vdev, -1); + vfio_spapr_pci_eeh_release(vdev->pdev); + vfio_pci_disable(vdev); - mutex_lock(&vdev->igate); - if (vdev->err_trigger) { - eventfd_ctx_put(vdev->err_trigger); - vdev->err_trigger = NULL; - } - if (vdev->req_trigger) { - eventfd_ctx_put(vdev->req_trigger); - vdev->req_trigger = NULL; - } - mutex_unlock(&vdev->igate); + mutex_lock(&vdev->igate); + if (vdev->err_trigger) { + eventfd_ctx_put(vdev->err_trigger); + vdev->err_trigger = NULL; } - - mutex_unlock(&vdev->reflck->lock); + if (vdev->req_trigger) { + eventfd_ctx_put(vdev->req_trigger); + vdev->req_trigger = NULL; + } + mutex_unlock(&vdev->igate); } -static int vfio_pci_open(struct vfio_device *core_vdev) +static int vfio_pci_open_device(struct vfio_device *core_vdev) { struct vfio_pci_device *vdev = container_of(core_vdev, struct vfio_pci_device, vdev); int ret = 0; - mutex_lock(&vdev->reflck->lock); - - if (!vdev->refcnt) { - ret = vfio_pci_enable(vdev); - if (ret) - goto error; + ret = vfio_pci_enable(vdev); + if (ret) + return ret; - vfio_spapr_pci_eeh_open(vdev->pdev); - vfio_pci_vf_token_user_add(vdev, 1); - } - vdev->refcnt++; -error: - mutex_unlock(&vdev->reflck->lock); - return ret; + vfio_spapr_pci_eeh_open(vdev->pdev); + vfio_pci_vf_token_user_add(vdev, 1); + return 0; } static int vfio_pci_get_irq_count(struct vfio_pci_device *vdev, int irq_type) @@ -1870,8 +1857,8 @@ static int vfio_pci_match(struct vfio_device *core_vdev, char *buf) static const struct vfio_device_ops vfio_pci_ops = { .name = "vfio-pci", - .open = vfio_pci_open, - .release = vfio_pci_release, + .open_device = vfio_pci_open_device, + .close_device = vfio_pci_close_device, .ioctl = vfio_pci_ioctl, .read = vfio_pci_read, .write = vfio_pci_write, @@ -1880,9 +1867,6 @@ static const struct vfio_device_ops vfio_pci_ops = { .match = vfio_pci_match, }; -static int vfio_pci_reflck_attach(struct vfio_pci_device *vdev); -static void vfio_pci_reflck_put(struct vfio_pci_reflck *reflck); - static int vfio_pci_bus_notifier(struct notifier_block *nb, unsigned long action, void *data) { @@ -2020,12 +2004,17 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) INIT_LIST_HEAD(&vdev->vma_list); init_rwsem(&vdev->memory_lock); - ret = vfio_pci_reflck_attach(vdev); + if (pci_is_root_bus(pdev->bus)) + ret = vfio_assign_device_set(&vdev->vdev, vdev); + else if (!pci_probe_reset_slot(pdev->slot)) + ret = vfio_assign_device_set(&vdev->vdev, pdev->slot); + else + ret = vfio_assign_device_set(&vdev->vdev, pdev->bus); if (ret) goto out_uninit; ret = vfio_pci_vf_init(vdev); if (ret) - goto out_reflck; + goto out_uninit; ret = vfio_pci_vga_init(vdev); if (ret) goto out_vf; @@ -2057,8 +2046,6 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) vfio_pci_set_power_state(vdev, PCI_D0); out_vf: vfio_pci_vf_uninit(vdev); -out_reflck: - vfio_pci_reflck_put(vdev->reflck); out_uninit: vfio_uninit_group_dev(&vdev->vdev); kfree(vdev->pm_save); @@ -2077,7 +2064,6 @@ static void vfio_pci_remove(struct pci_dev *pdev) vfio_unregister_group_dev(&vdev->vdev); vfio_pci_vf_uninit(vdev); - vfio_pci_reflck_put(vdev->reflck); vfio_uninit_group_dev(&vdev->vdev); vfio_pci_vga_uninit(vdev); @@ -2153,86 +2139,6 @@ static struct pci_driver vfio_pci_driver = { .err_handler = &vfio_err_handlers, }; -static DEFINE_MUTEX(reflck_lock); - -static struct vfio_pci_reflck *vfio_pci_reflck_alloc(void) -{ - struct vfio_pci_reflck *reflck; - - reflck = kzalloc(sizeof(*reflck), GFP_KERNEL); - if (!reflck) - return ERR_PTR(-ENOMEM); - - kref_init(&reflck->kref); - mutex_init(&reflck->lock); - - return reflck; -} - -static void vfio_pci_reflck_get(struct vfio_pci_reflck *reflck) -{ - kref_get(&reflck->kref); -} - -static int vfio_pci_reflck_find(struct pci_dev *pdev, void *data) -{ - struct vfio_pci_reflck **preflck = data; - struct vfio_device *device; - struct vfio_pci_device *vdev; - - device = vfio_device_get_from_dev(&pdev->dev); - if (!device) - return 0; - - if (pci_dev_driver(pdev) != &vfio_pci_driver) { - vfio_device_put(device); - return 0; - } - - vdev = container_of(device, struct vfio_pci_device, vdev); - - if (vdev->reflck) { - vfio_pci_reflck_get(vdev->reflck); - *preflck = vdev->reflck; - vfio_device_put(device); - return 1; - } - - vfio_device_put(device); - return 0; -} - -static int vfio_pci_reflck_attach(struct vfio_pci_device *vdev) -{ - bool slot = !pci_probe_reset_slot(vdev->pdev->slot); - - mutex_lock(&reflck_lock); - - if (pci_is_root_bus(vdev->pdev->bus) || - vfio_pci_for_each_slot_or_bus(vdev->pdev, vfio_pci_reflck_find, - &vdev->reflck, slot) <= 0) - vdev->reflck = vfio_pci_reflck_alloc(); - - mutex_unlock(&reflck_lock); - - return PTR_ERR_OR_ZERO(vdev->reflck); -} - -static void vfio_pci_reflck_release(struct kref *kref) -{ - struct vfio_pci_reflck *reflck = container_of(kref, - struct vfio_pci_reflck, - kref); - - kfree(reflck); - mutex_unlock(&reflck_lock); -} - -static void vfio_pci_reflck_put(struct vfio_pci_reflck *reflck) -{ - kref_put_mutex(&reflck->kref, vfio_pci_reflck_release, &reflck_lock); -} - static int vfio_pci_get_unused_devs(struct pci_dev *pdev, void *data) { struct vfio_devices *devs = data; @@ -2254,7 +2160,7 @@ static int vfio_pci_get_unused_devs(struct pci_dev *pdev, void *data) vdev = container_of(device, struct vfio_pci_device, vdev); /* Fault if the device is not unused */ - if (vdev->refcnt) { + if (device->open_count) { vfio_device_put(device); return -EBUSY; } @@ -2303,7 +2209,7 @@ static int vfio_pci_try_zap_and_vma_lock_cb(struct pci_dev *pdev, void *data) * - At least one of the affected devices is marked dirty via * needs_reset (such as by lack of FLR support) * Then attempt to perform that bus or slot reset. Callers are required - * to hold vdev->reflck->lock, protecting the bus/slot reset group from + * to hold vdev->dev_set->lock, protecting the bus/slot reset group from * concurrent opens. A vfio_device reference is acquired for each device * to prevent unbinds during the reset operation. * diff --git a/drivers/vfio/pci/vfio_pci_private.h b/drivers/vfio/pci/vfio_pci_private.h index 5a36272cecbf94..ae83c2eada3a64 100644 --- a/drivers/vfio/pci/vfio_pci_private.h +++ b/drivers/vfio/pci/vfio_pci_private.h @@ -83,11 +83,6 @@ struct vfio_pci_dummy_resource { struct list_head res_next; }; -struct vfio_pci_reflck { - struct kref kref; - struct mutex lock; -}; - struct vfio_pci_vf_token { struct mutex lock; uuid_t uuid; @@ -130,8 +125,6 @@ struct vfio_pci_device { bool needs_pm_restore; struct pci_saved_state *pci_saved_state; struct pci_saved_state *pm_save; - struct vfio_pci_reflck *reflck; - int refcnt; int ioeventfds_nr; struct eventfd_ctx *err_trigger; struct eventfd_ctx *req_trigger; From patchwork Thu Jul 15 00:20:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12378159 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD583C1B08C for ; Thu, 15 Jul 2021 00:21:13 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 9F21761374 for ; Thu, 15 Jul 2021 00:21:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9F21761374 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CC10D6E52C; Thu, 15 Jul 2021 00:20:54 +0000 (UTC) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2077.outbound.protection.outlook.com [40.107.236.77]) by gabe.freedesktop.org (Postfix) with ESMTPS id 291276E520; Thu, 15 Jul 2021 00:20:53 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Vl1HOsAHGzH+LTohJeq27/dJEmA/Nbam8pXDmkUKshZpbdNNP2yVw3OxMaOEG79oTt+ySs9l+wMyklnG1jK2X5LP0ixTUzN8+1Y1bwNzfKO/4PA41A9RUrZ21LeAZlKtcK7BJ9iMs4CjUjFJJ7HtmjzsR/eOa2ORswIwx0Y6KkqGkFWWlDYXQmJRdjZke/3jopbeR4bsj8AyZzJIJg9dckDsHSq2rguxRHwurA4sF3yg44N0oYVfNkKU+UNiqXiidJ7E4zCUQcDbn1GdIgYhTzb1d0MEgRvJIAB+nOJaTaGrmITm+tl83AQDjqU6a0M7119pX9iaygUQT8McpV1BWA== 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-SenderADCheck; bh=UD/1ND3WjMAvCzEW8ntZtZuwg29W/AC0FqTAlDAgfwk=; b=iuLQ1y/uUhGX4QLOblb0Xv4gEVzYJU5Iz6BINt9Dh880R1Y7NtUSczM7uUaSl3FH7+cGUSNJOtvyZznZDUKrlSN7MMqiQ2RBxMCzybDtQxntmL5KhmYdeq70w2J0Tsy1gZineTUWh5gdklMI8+I0oIk96NMvNrbVYBCo2jDNISMEJ2Lz0fU02bGd7hAhUDaHUaeniFuZ5Z+zUSK/ng4zSWoK5NCVzJ8XW5rmgErzXsNRPHsPFvkGUgQriNmM3/s14zjkbFKXw+mupwqGtcXrjZKeT9q6jQ0w4+8465evBsxIYI+EzA+DTQyraHs+tVPxcznLC2RDdoY7RXyW6UWK0Q== 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=UD/1ND3WjMAvCzEW8ntZtZuwg29W/AC0FqTAlDAgfwk=; b=g1kSjd1LjflMlDf/6r6WiApGaf/OwyvqpJOpt0a7sWXemLGNscXnGqqEe0RDg53FApqaa4B3q7V7kmY9ZkwmE/dAVOQ03LeTQfJYNsHsW91xGcy7r3Hppe3HJnK+d+KPEPCtaNzoeKjvenL+/tPzrnOvOWLf0pPaO+89fVM3Ij0RqYKV4Y/7cGz6uIyVMCbGJzUL35U/13bU0vZoVnR5BMwIAZobBs4FhYldU8mxHjCWz5oY5hajmBAQ5QOWeEII8PY5hWesMxrlhPV7CPQPpPYM2fQHNmvQtU5Cx2dvRkmiINXd6oSxsdr2OqEecsMof5cBIIOEPDTNzn5GWb0u3w== Authentication-Results: linux.ie; dkim=none (message not signed) header.d=none;linux.ie; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL0PR12MB5555.namprd12.prod.outlook.com (2603:10b6:208:1c2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.26; Thu, 15 Jul 2021 00:20:52 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482%5]) with mapi id 15.20.4331.021; Thu, 15 Jul 2021 00:20:52 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , Daniel Vetter , Diana Craciun , dri-devel@lists.freedesktop.org, Eric Auger , 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 , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Date: Wed, 14 Jul 2021 21:20:37 -0300 Message-Id: <8-v1-eaf3ccbba33c+1add0-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v1-eaf3ccbba33c+1add0-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: CH0PR03CA0024.namprd03.prod.outlook.com (2603:10b6:610:b0::29) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by CH0PR03CA0024.namprd03.prod.outlook.com (2603:10b6:610:b0::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Thu, 15 Jul 2021 00:20:46 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m3p7K-002Uxa-OP; Wed, 14 Jul 2021 21:20:42 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5526b35a-5120-4646-5b56-08d947266411 X-MS-TrafficTypeDiagnostic: BL0PR12MB5555: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: x7sxUDEbZ65OhRBf+mkmYWnBFoEbL92mSKkdHxNEJjrEoavcWcQ1bSvExiBVpnFLOh3id2UBcSRdCevcW+wE9Zb7oeYlImBecb9h9tsqv0Fd/hXsbzwA1bAo4XphIt1H56lfaBOf9SIBU3HgxsrcM9FDdUAEPdg+HEtrptKVOI5CKBtcwclKxZw3VLuT2w3gmdK9Ii6q8YFR1yEVhZL/8rhlCqddT/0pRs4tfl6lcJvs0JxfLxg7KHGJskxDAQ2aVfy7k3n5Gbm36D05JtQ8nX9UWxzZUvyzxPiG2ZFA/cIZ1xhrEXG1Ut4OLyIJK9axTql0PSSdcrE8bh9DUWkuh+eXTKX9AD9bCltSKp9Q3RQ3bzgTlQUWGUcpDsORtdqRB/wXdGpcCxWO1vHR7S5F32xd4OHybfCeeZkLuba5dEUUKXrXXt2FCrFz1biB+HMZZx5S8QMj8W875SK4i+AV4qo1PPk4PE4uuFqSdrJZrQ9l1uKH04tzljuPgnT0EDRMrDvOkz2Ist/QrifdRg+hjm/Z8HoiipT0VKYK71bwKnM0LJePOC1Sg+u+GFzyw3bELY0Kwpj0rdlbZvUZ1Hfd2eFIzYLo8+2kO8bj5R/lu5fOqChXy56ZsWZAuV4lVBXHUPwq5hxemWRbyAMx8Qvwa6tZBmiypE20y9TVM5EfUYh4Z1RI8QHnNgtD8HkxDsSs2d6gxMClhHqhIie6907oRw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL0PR12MB5506.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(39860400002)(346002)(376002)(396003)(366004)(83380400001)(2616005)(426003)(316002)(107886003)(2906002)(478600001)(4326008)(7416002)(7406005)(38100700002)(36756003)(5660300002)(66556008)(66476007)(66946007)(921005)(9746002)(26005)(8936002)(110136005)(54906003)(8676002)(9786002)(86362001)(6666004)(186003)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TipHyy3AIPmn9pT5Nh4lwqVDjIKTWS72euvzmw+GPCCaa1JImtn7TyyeXoJdchB2FgCAHkShxKn1kxGhXGWmp/r9IzkKHF2aT81p3ApH3lRC/jXTl6F6O+bMbVmvamYzCEKkQcWq7gZcIIjOth+CCjkJPBv/YUbWHDPkIwaf20EbpQ0JrJTva/3Co/RbcQXfuAagkRjEOIox73xXT0qVZEwftpdLKDZCS50BoI5YAFdqseGygFrJ7nBfmOIYxjLGhl2olzDMLxFCSqOzZJBbILFUKi5blEUK4oJPgCG27tbUr8EnrD+f5EvrzJShvEAtuLraUtm1x0BpWt3CCWMJtE6GiNdl7BMvR973oyXaye3JEzgBGkPd2crEam0PKGbKtEX5C936ZJ6paFKAzNmgJh/ppQFfSf7HxGiWZKiIwChOB9ez3NKM/cu3BSN4PL9PK71Xo5AdkSo7ttpmYsB8iDMoNPJAu5ga1U8Wm0ZairMpi1SJMarBVBLP7NF4b/aF08pZFxk6OCXX0nzdDxRVrv9SBfyLSeUTccD8nYH/es2TrjM+ia+7ih8YWRQTp/3CaKreempHPvhZ7ZcqM4GBfwuK2MxwlXfaPgT/eg/9eF5rZXWqD8IkPT85Zp9xqju6XDnOUNOyBDXB5GDmCfrYh4G789YvM7RAW3CIs/Fs61dUm4+QA/MvvZaF/Eu/uIH6weCBxfZyIVDG+PpWpMJZ72QhvWF0QeQ+tS9xjRlhB93Wb8gp9WnPRP/u9MjuEF340eQPa7zhCSDkEh7fryt+ieZBDvlb3V6ydAsUXLyiKrjYy7jSXw39mbIUrtyZol28KnOdtt0cyvaKfZRO6PY8UoLJFc75/BWX7By9hMCoxJfrANtuaXc11NDB+fpKtMu/fvhIS9t1MEV2OXrdCYpUJAiZs0JwwLK9LUYtBuUG6G0Xh0mTJFONAaseiyEBb6QVq0Z3g3xQnMmNFUzInB4IVcNHS4oCBBeBvvcrRfNZZXQZB8phm1mrlxvncjoARehjrLoIRlPefyIuyDB/Z/BSE0/2TdjqeQ2m07yPzKjNiLEqk8BE754/1/n/IWEjdsGqXPXqECIUv9x+OD+wdlJks7LsFBOKx2HhkEi1xciKwWXxI4zc/BjRcZWKUkdNJ414whqIvBzKLPLk+EYEH//JZvZ534T3AbI9qFIL90k4lCR0KMjFWJ1fqAZhQKJ72DC4WyK9ZB0blNtImTbZMyvj91a+wBJQigI2KhtPdriJZSsCOK0Hfm+Uya1FO6T8ai7KztkTUOGdxb8nQQ5VFQiaNp0BjrOi2BhVVwpHx/UZ4bMxThod15yi1rGcKV7w7KpL X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5526b35a-5120-4646-5b56-08d947266411 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2021 00:20:46.4467 (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: PoirCNknu0MDVW9iX+I3cWFUd98vrxoo9bV5hXkuzyI3MfOf56dsMgq1iY8h1jjP X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5555 Subject: [Intel-gfx] [PATCH 08/13] vfio/pci: Change vfio_pci_try_bus_reset() to use the dev_set 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: Max Gurtovoy , Yishai Hadas , Leon Romanovsky , "Raj, Ashok" , Christoph Hellwig Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Keep track of all the vfio_devices that have been added to the device set and use this list in vfio_pci_try_bus_reset() instead of trying to work backwards from the pci_device. The dev_set->lock directly prevents devices from joining/leaving the set, which further implies the pci_device cannot change drivers or that the vfio_device be freed, eliminating the need for get/put's. Completeness of the device set can be directly measured by checking if every PCI device in the reset group is also in the device set - which proves that VFIO drivers are attached to everything. This restructuring corrects a call to pci_dev_driver() without holding the device_lock() and removes a hard wiring to &vfio_pci_driver. Signed-off-by: Jason Gunthorpe --- drivers/vfio/pci/vfio_pci.c | 110 ++++++++++++++---------------------- drivers/vfio/vfio.c | 10 ++++ include/linux/vfio.h | 2 + 3 files changed, 53 insertions(+), 69 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index 22774e447b5f4a..fbc20f6d2dd412 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -404,6 +404,9 @@ static void vfio_pci_disable(struct vfio_pci_device *vdev) struct vfio_pci_ioeventfd *ioeventfd, *ioeventfd_tmp; int i, bar; + /* For needs_reset */ + lockdep_assert_held(&vdev->vdev.dev_set->lock); + /* Stop the device from further DMA */ pci_clear_master(pdev); @@ -2139,34 +2142,17 @@ static struct pci_driver vfio_pci_driver = { .err_handler = &vfio_err_handlers, }; -static int vfio_pci_get_unused_devs(struct pci_dev *pdev, void *data) +static int vfio_pci_check_all_devices_bound(struct pci_dev *pdev, void *data) { - struct vfio_devices *devs = data; - struct vfio_device *device; - struct vfio_pci_device *vdev; - - if (devs->cur_index == devs->max_index) - return -ENOSPC; + struct vfio_device_set *dev_set = data; + struct vfio_device *cur; - device = vfio_device_get_from_dev(&pdev->dev); - if (!device) - return -EINVAL; - - if (pci_dev_driver(pdev) != &vfio_pci_driver) { - vfio_device_put(device); - return -EBUSY; - } - - vdev = container_of(device, struct vfio_pci_device, vdev); - - /* Fault if the device is not unused */ - if (device->open_count) { - vfio_device_put(device); - return -EBUSY; - } + lockdep_assert_held(&dev_set->lock); - devs->devices[devs->cur_index++] = vdev; - return 0; + list_for_each_entry(cur, &dev_set->device_list, dev_set_list) + if (cur->dev == &pdev->dev) + return 0; + return -EBUSY; } static int vfio_pci_try_zap_and_vma_lock_cb(struct pci_dev *pdev, void *data) @@ -2210,8 +2196,7 @@ static int vfio_pci_try_zap_and_vma_lock_cb(struct pci_dev *pdev, void *data) * needs_reset (such as by lack of FLR support) * Then attempt to perform that bus or slot reset. Callers are required * to hold vdev->dev_set->lock, protecting the bus/slot reset group from - * concurrent opens. A vfio_device reference is acquired for each device - * to prevent unbinds during the reset operation. + * concurrent opens. * * NB: vfio-core considers a group to be viable even if some devices are * bound to drivers like pci-stub or pcieport. Here we require all devices @@ -2220,61 +2205,48 @@ static int vfio_pci_try_zap_and_vma_lock_cb(struct pci_dev *pdev, void *data) */ static void vfio_pci_try_bus_reset(struct vfio_pci_device *vdev) { - struct vfio_devices devs = { .cur_index = 0 }; - int i = 0, ret = -EINVAL; - bool slot = false; - struct vfio_pci_device *tmp; - - if (!pci_probe_reset_slot(vdev->pdev->slot)) - slot = true; - else if (pci_probe_reset_bus(vdev->pdev->bus)) - return; + struct vfio_device_set *dev_set = vdev->vdev.dev_set; + struct vfio_pci_device *to_reset = NULL; + struct vfio_pci_device *cur; + int ret; - if (vfio_pci_for_each_slot_or_bus(vdev->pdev, vfio_pci_count_devs, - &i, slot) || !i) + if (pci_probe_reset_slot(vdev->pdev->slot) && + pci_probe_reset_bus(vdev->pdev->bus)) return; - devs.max_index = i; - devs.devices = kcalloc(i, sizeof(struct vfio_device *), GFP_KERNEL); - if (!devs.devices) - return; + lockdep_assert_held(&vdev->vdev.dev_set->lock); - if (vfio_pci_for_each_slot_or_bus(vdev->pdev, - vfio_pci_get_unused_devs, - &devs, slot)) - goto put_devs; + /* All VFIO devices have a closed FD */ + list_for_each_entry(cur, &dev_set->device_list, vdev.dev_set_list) + if (cur->vdev.open_count) + return; + + /* All devices in the group to be reset need VFIO devices */ + if (vfio_pci_for_each_slot_or_bus( + vdev->pdev, vfio_pci_check_all_devices_bound, dev_set, + !pci_probe_reset_slot(vdev->pdev->slot))) + return; /* Does at least one need a reset? */ - for (i = 0; i < devs.cur_index; i++) { - tmp = devs.devices[i]; - if (tmp->needs_reset) { - ret = pci_reset_bus(vdev->pdev); + list_for_each_entry(cur, &dev_set->device_list, vdev.dev_set_list) { + if (cur->needs_reset) { + to_reset = cur; break; } } + if (!to_reset) + return; -put_devs: - for (i = 0; i < devs.cur_index; i++) { - tmp = devs.devices[i]; - - /* - * If reset was successful, affected devices no longer need - * a reset and we should return all the collateral devices - * to low power. If not successful, we either didn't reset - * the bus or timed out waiting for it, so let's not touch - * the power state. - */ - if (!ret) { - tmp->needs_reset = false; + ret = pci_reset_bus(to_reset->pdev); + if (ret) + return; - if (tmp != vdev && !disable_idle_d3) - vfio_pci_set_power_state(tmp, PCI_D3hot); - } + list_for_each_entry(cur, &dev_set->device_list, vdev.dev_set_list) { + cur->needs_reset = false; - vfio_device_put(&tmp->vdev); + if (cur != to_reset && !disable_idle_d3) + vfio_pci_set_power_state(cur, PCI_D3hot); } - - kfree(devs.devices); } static void __exit vfio_pci_cleanup(void) diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index 6908c2ae9b36f6..26d340283044e7 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -127,7 +127,12 @@ int vfio_assign_device_set(struct vfio_device *device, void *set_id) if (dev_set) { dev_set->device_count++; xa_unlock(&vfio_device_set_xa); + + mutex_lock(&dev_set->lock); device->dev_set = dev_set; + list_add_tail(&device->dev_set_list, &dev_set->device_list); + mutex_unlock(&dev_set->lock); + if (dev_set != alloc_dev_set) kfree(alloc_dev_set); return 0; @@ -141,6 +146,7 @@ int vfio_assign_device_set(struct vfio_device *device, void *set_id) if (!alloc_dev_set) return -ENOMEM; mutex_init(&alloc_dev_set->lock); + INIT_LIST_HEAD(&alloc_dev_set->device_list); alloc_dev_set->set_id = set_id; goto again; } @@ -153,6 +159,10 @@ static void vfio_release_device_set(struct vfio_device *device) if (!dev_set) return; + mutex_lock(&dev_set->lock); + list_del(&device->dev_set_list); + mutex_unlock(&dev_set->lock); + xa_lock(&vfio_device_set_xa); dev_set->device_count--; if (!dev_set->device_count) { diff --git a/include/linux/vfio.h b/include/linux/vfio.h index 128b4db00adc57..f0e6a72875e471 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -23,6 +23,7 @@ struct vfio_device_set { void *set_id; struct mutex lock; + struct list_head device_list; unsigned int device_count; }; @@ -31,6 +32,7 @@ struct vfio_device { const struct vfio_device_ops *ops; struct vfio_group *group; struct vfio_device_set *dev_set; + struct list_head dev_set_list; /* Members below here are private, not for driver use */ refcount_t refcount; From patchwork Thu Jul 15 00:20:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12378167 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC617C1B08C for ; Thu, 15 Jul 2021 00:21:18 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id C3FFB613CF for ; Thu, 15 Jul 2021 00:21:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C3FFB613CF Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 121526E51D; Thu, 15 Jul 2021 00:20:56 +0000 (UTC) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2077.outbound.protection.outlook.com [40.107.236.77]) by gabe.freedesktop.org (Postfix) with ESMTPS id DF6436E51D; Thu, 15 Jul 2021 00:20:52 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HHFJXDf4amty2+zOEmTeUqg0kawvWU/a/8bAuPzD4B1twqJrYYQbHsDkUfTiDp1RItSRTDFbxNnTjIUIEPi2QsOUTKVoCHWjuFBFQVN7ruBWyxrfbOXqRTPfsHTF3kbZQ5x/P5KAbSbUC/HSMDnCOcey2IYtm8ogkBA9a3J/f710mWDwovwz6m2RNtbkpoeqrJxf2TjunLHRrnCetXq9KuPxVMrq21AlqGZXqxaEZj+YFZQ3cphbiJFFiu4PrgfwFL2B7qjY0FVVyKufjyATWEpxWP4Pt8smpX5yCn4AHvMhRURfjr6OG+7moSk/f8JLnJpnlWsgofNLQbEetZcEJg== 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-SenderADCheck; bh=+VGW7wr/BkFmokiMOi9zUR4JROkKeHfKGvBjk3PptLg=; b=X5xX80oduBQxb4s7Y5MbEdnwQk3dnYQPnpxMG52OAdBSYqhaZFgAqwdXQiZ3d8AERxlV3SMBjUu7YCo4N5kWXEAqVA3GsEBZOSnxaJTGgMLBsoAiKJQ1N9iXPLSQKqbppgenGGNbfnquWb3F8h5HZ8fnyE6O4HsH/1VNeUBq8w85DJZIONK4WpFwL1wVA0XtsaYnmRWreiWrZTJ0JQ60kW0fEu+58E+A5zyE8yIdJfB7kY9+qTJs4e/J9cNY+CYGtlay/CWMp2V/y44RTrgDueRqu3RzKTgXM7eT1tO+xm3+2nxS28kIX4uhAiRUfaXW+kwEa7+EY6d6Se+qL21J5g== 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=+VGW7wr/BkFmokiMOi9zUR4JROkKeHfKGvBjk3PptLg=; b=BsGB1r1xsQNMiGEmXm/PxNA9Ni6Eo3sSpY97/I1kKtkFWKqTzXdb+yWFIaq1w18NuGvKjGNflaLFSNE6l1H7i/yI4R5oepQh2+XrrTZXw7nn4X6da97M9GmyzXYuZREacsneJU8jwpAnDhSCdXc59DbMOi3O3soP/VgmR0D/YOUkXPW7URs2nB8LCd09kYi+UreSEsUJF7yAySvvYPXFxMoe6lkO1euozw7jc97KgxVlvE/g8gQZzV9SL1MoA85LlqgfETkoRKz2XxUu3ArqURd5qkOoJH5yMvrHHka5J5qng1E4/79lTvrDCG6+dIHD2qgRDPg5le9PpWv/UfWfRw== Authentication-Results: linux.ie; dkim=none (message not signed) header.d=none;linux.ie; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL0PR12MB5555.namprd12.prod.outlook.com (2603:10b6:208:1c2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.26; Thu, 15 Jul 2021 00:20:51 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482%5]) with mapi id 15.20.4331.021; Thu, 15 Jul 2021 00:20:51 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , Daniel Vetter , Diana Craciun , dri-devel@lists.freedesktop.org, Eric Auger , 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 , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Date: Wed, 14 Jul 2021 21:20:38 -0300 Message-Id: <9-v1-eaf3ccbba33c+1add0-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v1-eaf3ccbba33c+1add0-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: CH0PR03CA0011.namprd03.prod.outlook.com (2603:10b6:610:b0::16) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by CH0PR03CA0011.namprd03.prod.outlook.com (2603:10b6:610:b0::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Thu, 15 Jul 2021 00:20:46 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m3p7K-002Uxd-Q9; Wed, 14 Jul 2021 21:20:42 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 017de31f-b664-4048-6824-08d94726640d X-MS-TrafficTypeDiagnostic: BL0PR12MB5555: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +RYE+64cSU46/9muguWmX7fNBoawaDOhh8YOmI3lets8U6X3d0Kcs0v3BZ0w/cwdufaiOVnK3ThxCsatGP71a4URImuCA7hwSeygJe6vWLZBB6mhvvbQAaTRaYe643jjQrfx/tMzdZ6ybZ6LTKV15BW38aEK9TmxEpwpJlvwjVyYJelUAjTHhgevUx1MEaackXhoDUccRAivN/GuZ3PT50EFXHTMiv9C/fKKcNr1RsNSeItM1qu9IcEyKbUzv5R1XoOP6O+4vhXPTCr0buBImjz44Uoj5E3cZzQbnXTe2nVb0keOs2lJIMAQg3hkBYrgittUt296V4qV/3ao+/eYYetFfnhP2polaO3BZesfBi18T/vb8Pjpj7cHvtQ8JdO1ijSOJQ/ipCOgpL8/9nfGxF/KN76F+X4g/9OfFO/qX3+iCBqvwp+kDTNU1p1Nw+5cButXhVAj7VLn4WWgre9kGWSvMGL5lPJGEZM3eH6P0m5nuwu0ZzU7Ml8/qVsm0/snvxOJ+uchscMh14jTG1sZOb5gZgbFGSrPKlMcOkaEQMdMQw6g1oYdhJrBl6BpQ1bxMV1VaAY6seip4Swf77HnnnFWSsl9qiBoiug1oBf96QuzQXAoXcTmK+tLa2faCagBBqNSic43vBIo9hJERoN6PrMuZAbfzy/iSOIoibGz2KPDamrc6GkZAWOKmt+sw6cHbGQWUHvKa0zhRi25DjwZsQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL0PR12MB5506.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(39860400002)(346002)(376002)(396003)(366004)(83380400001)(2616005)(426003)(316002)(107886003)(2906002)(478600001)(4326008)(7416002)(7406005)(38100700002)(36756003)(5660300002)(66556008)(66476007)(66946007)(921005)(9746002)(26005)(8936002)(110136005)(54906003)(8676002)(9786002)(86362001)(6666004)(186003)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tdMlDvy83TROOkXgfgz1xV+tIK8S2qzW1PTvwBHydaBhyMVOeXxqLOkFPUT9d+i3r5vVvRX0d8Sb4UOPt9lsq8Y4XV9/exSkvih9K7/c+W94H/xao1oqKXuied0Fxy17uowS9keWgwGgZLLW+Acpt+QqRjwWrQFgyJ+FUN9DjJATkkYtlncjjlJHbg5Ccl7mc23hpzFQA+tvepI+0kvsvNRQMh5hap7SQphHrFOTFwP+uOHwO8CRVOVnHd5b08rzhySB/3lTHT4uynlAiO5d3q1GNk0NDl3fOpcN6uz0iQhvxlwwyVJDCNp2FB3aYEySseHD7hYtnX2htrp+A5YHmh19+fAB42UjTCTGc74cgXF+61325wwyxOZiwq3Bhryjfpp6yGzagsVphVlYdkcXxe1A9ApFscFdchWACJFKwmF+7xtNSjuxpGzDbIHL9ClHJmgjpZwR9sQim7fg1l6JmLutnD6awkiUMS3IWoEBvPHeqNgix8qEg52t2WzBctT3OdV3gLjCtz8Jv1roLWbnhS57s4+XTWqIxHydExG0LciwELLG45lRhZgl4yOMA4jGCFlSQCoNuTl5rsUGg31OoCSCCWiB06DcwFnDyHrrYKDL9yPrqDxImAs5KovWe+fHZm6Aprt/Rh34Y5zjd2DErclMHCNcx/1bOFAMFOXzY6MPcXpe14qGbEYXzoj5+sWPMLL3M0KM0vaia8s+LK2k7ElvBnaPOjgD1klOs0QL9DaF2YlAAGGe5oTdEtK4cARif5oejopBLM8ucVu3kgxr8Wvb0QxHlVw/6pLqxHZ5Pt+eqgwSxZhFIkhKwN10CHB3oy1MJwtL9IUjYyn3rsPdouoGCcvo/lXK481Kh6tumhiKXSUIVFyhOJfVTkcLbVysrKK7mhVVAv9bZPD25n32/jbMoAuMmjM0pC3u3HTdGwiOrEbH93q4/yI9DxKqQ1o/ekccDHfVirGC67irUSL72PAIkv/BUqeYuSnKhkY7YmqGMOKVAI1ZRLh7/ZoHX9cYOTpVjM/ARlP4ar/AIkx/xOCaUHfNKYnbAPg5Q61FOZVHivW4d0sBuZbNud94sDTBL37cC1ly5S/2WV5JMJZyAoh/L2SCTZ1L1Fe7YqJ9Xuu6ypVOAGdG4dvBfSgJddfPlcvdtDw+VBaEPM7R3wh6Q/FsWWITljxVCQu8QVHto40ty5rOMZ7N5YAobFhov1iCzRuzAWuO5VGuVZ4iZ+RioL+Gf8/rjMyGwEB2aJCvkWPOvIe89QQly4GbqOOKbsWBouLSUm4MY+dlnhW4MYhE1VmKaZOJSCaJgUcvaZUuSXuHvm9L8a+8+6WfSd3HYUKm X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 017de31f-b664-4048-6824-08d94726640d X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2021 00:20:46.4228 (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: crdvZ9E4+bPCAmUTeGR4gL2A9MHjuak1C4wJez41HjTTGZ97YfMb/cGX+efAel0X X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5555 Subject: [Intel-gfx] [PATCH 09/13] vfio/pci: Reorganize VFIO_DEVICE_PCI_HOT_RESET to use the device set 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: Max Gurtovoy , Yishai Hadas , Leon Romanovsky , "Raj, Ashok" , Christoph Hellwig Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Like vfio_pci_try_bus_reset() this code wants to reset all of the devices in the "reset group" which is the same membership as the device set. Instead of trying to reconstruct the device set from the PCI list go directly from the device set's device list to execute the reset. The same basic structure as vfio_pci_try_bus_reset() is used. The 'vfio_devices' struct is replaced with the device set linked list and we simply sweep it multiple times under the lock. This eliminates a memory allocation and get/put traffic and another improperly locked test of pci_dev_driver(). Signed-off-by: Jason Gunthorpe --- drivers/vfio/pci/vfio_pci.c | 205 ++++++++++++++++-------------------- 1 file changed, 88 insertions(+), 117 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index fbc20f6d2dd412..ff23168b8dc551 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -223,9 +223,11 @@ static void vfio_pci_probe_mmaps(struct vfio_pci_device *vdev) } } +struct vfio_pci_group_info; static void vfio_pci_try_bus_reset(struct vfio_pci_device *vdev); static void vfio_pci_disable(struct vfio_pci_device *vdev); -static int vfio_pci_try_zap_and_vma_lock_cb(struct pci_dev *pdev, void *data); +static int vfio_hot_reset_device_set(struct vfio_pci_device *vdev, + struct vfio_pci_group_info *groups); /* * INTx masking requires the ability to disable INTx signaling via PCI_COMMAND @@ -645,37 +647,11 @@ static int vfio_pci_fill_devs(struct pci_dev *pdev, void *data) return 0; } -struct vfio_pci_group_entry { - struct vfio_group *group; - int id; -}; - struct vfio_pci_group_info { int count; - struct vfio_pci_group_entry *groups; + struct vfio_group **groups; }; -static int vfio_pci_validate_devs(struct pci_dev *pdev, void *data) -{ - struct vfio_pci_group_info *info = data; - struct iommu_group *group; - int id, i; - - group = iommu_group_get(&pdev->dev); - if (!group) - return -EPERM; - - id = iommu_group_id(group); - - for (i = 0; i < info->count; i++) - if (info->groups[i].id == id) - break; - - iommu_group_put(group); - - return (i == info->count) ? -EINVAL : 0; -} - static bool vfio_pci_dev_below_slot(struct pci_dev *pdev, struct pci_slot *slot) { for (; pdev; pdev = pdev->bus->self) @@ -753,12 +729,6 @@ int vfio_pci_register_dev_region(struct vfio_pci_device *vdev, return 0; } -struct vfio_devices { - struct vfio_pci_device **devices; - int cur_index; - int max_index; -}; - static long vfio_pci_ioctl(struct vfio_device *core_vdev, unsigned int cmd, unsigned long arg) { @@ -1127,11 +1097,10 @@ static long vfio_pci_ioctl(struct vfio_device *core_vdev, } else if (cmd == VFIO_DEVICE_PCI_HOT_RESET) { struct vfio_pci_hot_reset hdr; int32_t *group_fds; - struct vfio_pci_group_entry *groups; + struct vfio_group **groups; struct vfio_pci_group_info info; - struct vfio_devices devs = { .cur_index = 0 }; bool slot = false; - int i, group_idx, mem_idx = 0, count = 0, ret = 0; + int group_idx, count = 0, ret = 0; minsz = offsetofend(struct vfio_pci_hot_reset, count); @@ -1198,9 +1167,7 @@ static long vfio_pci_ioctl(struct vfio_device *core_vdev, break; } - groups[group_idx].group = group; - groups[group_idx].id = - vfio_external_user_iommu_id(group); + groups[group_idx] = group; } kfree(group_fds); @@ -1212,64 +1179,11 @@ static long vfio_pci_ioctl(struct vfio_device *core_vdev, info.count = hdr.count; info.groups = groups; - /* - * Test whether all the affected devices are contained - * by the set of groups provided by the user. - */ - ret = vfio_pci_for_each_slot_or_bus(vdev->pdev, - vfio_pci_validate_devs, - &info, slot); - if (ret) - goto hot_reset_release; - - devs.max_index = count; - devs.devices = kcalloc(count, sizeof(struct vfio_device *), - GFP_KERNEL); - if (!devs.devices) { - ret = -ENOMEM; - goto hot_reset_release; - } - - /* - * We need to get memory_lock for each device, but devices - * can share mmap_lock, therefore we need to zap and hold - * the vma_lock for each device, and only then get each - * memory_lock. - */ - ret = vfio_pci_for_each_slot_or_bus(vdev->pdev, - vfio_pci_try_zap_and_vma_lock_cb, - &devs, slot); - if (ret) - goto hot_reset_release; - - for (; mem_idx < devs.cur_index; mem_idx++) { - struct vfio_pci_device *tmp = devs.devices[mem_idx]; - - ret = down_write_trylock(&tmp->memory_lock); - if (!ret) { - ret = -EBUSY; - goto hot_reset_release; - } - mutex_unlock(&tmp->vma_lock); - } - - /* User has access, do the reset */ - ret = pci_reset_bus(vdev->pdev); + ret = vfio_hot_reset_device_set(vdev, &info); hot_reset_release: - for (i = 0; i < devs.cur_index; i++) { - struct vfio_pci_device *tmp = devs.devices[i]; - - if (i < mem_idx) - up_write(&tmp->memory_lock); - else - mutex_unlock(&tmp->vma_lock); - vfio_device_put(&tmp->vdev); - } - kfree(devs.devices); - for (group_idx--; group_idx >= 0; group_idx--) - vfio_group_put_external_user(groups[group_idx].group); + vfio_group_put_external_user(groups[group_idx]); kfree(groups); return ret; @@ -2155,37 +2069,94 @@ static int vfio_pci_check_all_devices_bound(struct pci_dev *pdev, void *data) return -EBUSY; } -static int vfio_pci_try_zap_and_vma_lock_cb(struct pci_dev *pdev, void *data) +static bool vfio_dev_in_groups(struct vfio_pci_device *vdev, + struct vfio_pci_group_info *groups) { - struct vfio_devices *devs = data; - struct vfio_device *device; - struct vfio_pci_device *vdev; + unsigned int i; - if (devs->cur_index == devs->max_index) - return -ENOSPC; + for (i = 0; i < groups->count; i++) + if (groups->groups[i] == vdev->vdev.group) + return true; + return false; +} - device = vfio_device_get_from_dev(&pdev->dev); - if (!device) - return -EINVAL; +/* + * We need to get memory_lock for each device, but devices can share mmap_lock, + * therefore we need to zap and hold the vma_lock for each device, and only then + * get each memory_lock. + */ +static int vfio_hot_reset_device_set(struct vfio_pci_device *vdev, + struct vfio_pci_group_info *groups) +{ + struct vfio_device_set *dev_set = vdev->vdev.dev_set; + struct vfio_pci_device *cur_mem = + list_first_entry(&dev_set->device_list, struct vfio_pci_device, + vdev.dev_set_list); + struct vfio_pci_device *cur_vma; + struct vfio_pci_device *cur; + bool is_mem = true; + int ret; - if (pci_dev_driver(pdev) != &vfio_pci_driver) { - vfio_device_put(device); - return -EBUSY; + mutex_lock(&dev_set->lock); + + /* All devices in the group to be reset need VFIO devices */ + if (vfio_pci_for_each_slot_or_bus( + vdev->pdev, vfio_pci_check_all_devices_bound, dev_set, + !pci_probe_reset_slot(vdev->pdev->slot))) { + ret = -EINVAL; + goto err_unlock; } - vdev = container_of(device, struct vfio_pci_device, vdev); + list_for_each_entry(cur_vma, &dev_set->device_list, vdev.dev_set_list) { + /* + * Test whether all the affected devices are contained by the + * set of groups provided by the user. + */ + if (!vfio_dev_in_groups(cur_vma, groups)) { + ret = -EINVAL; + goto err_undo; + } - /* - * Locking multiple devices is prone to deadlock, runaway and - * unwind if we hit contention. - */ - if (!vfio_pci_zap_and_vma_lock(vdev, true)) { - vfio_device_put(device); - return -EBUSY; + /* + * Locking multiple devices is prone to deadlock, runaway and + * unwind if we hit contention. + */ + if (!vfio_pci_zap_and_vma_lock(cur_vma, true)) { + ret = -EBUSY; + goto err_undo; + } } - devs->devices[devs->cur_index++] = vdev; - return 0; + list_for_each_entry(cur_mem, &dev_set->device_list, vdev.dev_set_list) { + if (!down_write_trylock(&cur_mem->memory_lock)) { + ret = -EBUSY; + goto err_undo; + } + mutex_unlock(&cur_mem->vma_lock); + } + + ret = pci_reset_bus(vdev->pdev); + + list_for_each_entry(cur, &dev_set->device_list, vdev.dev_set_list) + up_write(&cur->memory_lock); + mutex_unlock(&dev_set->lock); + + return ret; + +err_undo: + list_for_each_entry(cur, &dev_set->device_list, vdev.dev_set_list) { + if (cur == cur_mem) + is_mem = false; + if (cur == cur_vma) + break; + if (is_mem) + up_write(&cur->memory_lock); + else + mutex_unlock(&cur->vma_lock); + } +err_unlock: + mutex_unlock(&dev_set->lock); + return ret; } /* From patchwork Thu Jul 15 00:20:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12378163 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67A1FC47E48 for ; Thu, 15 Jul 2021 00:21:18 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 37108613CB for ; Thu, 15 Jul 2021 00:21:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 37108613CB Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 895E26E532; Thu, 15 Jul 2021 00:20:55 +0000 (UTC) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2056.outbound.protection.outlook.com [40.107.236.56]) by gabe.freedesktop.org (Postfix) with ESMTPS id A660D6E513; Thu, 15 Jul 2021 00:20:49 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g2Z/t/07UclULvm6Zytb0LMXAAHHKxsbPZqgKXf+xKSY8mhRQOnBwRP5DzljDthMfX8PdTJVsoiBdRLZtVpQg+l0Q6mfxdZfdZMMW2sGemI/jI28BdZdwYFZajPb7Wi9+fU5HJjH846j0L9lFGKgV/RhLiWuvmQnSNWvYB9eZTygmDXgrZbczMpQ1eK6SC5c8lATe2G1HLGJeTPgG5BRBt726M7ELVGycS2XHOcGPsLFTacfVwjQClKSUCspDirBC7b0jEOLrW5yglZkY4cQhJ5DipoAY+uWYK+mAz3E71066qk1hsGrlLgfaS0uQzKMGFlsTlwsQfQDx6uNl6ud6Q== 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-SenderADCheck; bh=8TI2Ea3BCnpMJtPQTi7ZpZoDXqgi9wwRJ0CJqM3YOZE=; b=QrfHbt6vvY3sRGZ2SdIXKS4tfhC2kDWYo5dJWoUmrd6gaLglafISQmN7/FARi32QlQC5MVSn3Vy3KgMq6Uo46bVIuhgokk4XhycT9vliGiYqaQWwyN23DywzFBexVIbzzlmlgWQ8QUskVl6mqCNzK8kJbuwTBAJ//eEvDNKQr39gVbcTX/3lbt9VN97kCzPiaVkKsIqUnOnR5MQlo4uaMenM/E091qwUR9TC7qPrbL6GsLOWf4T2yxV9r3AcRWRW7ZNNxWVf/BZhLB1MPmobSkZ9O+0rSwULprFBt3qgYgtVlBZx6GadzmaIg3E+mm9h1n5SLC1yDXnQPBhJm+9oYg== 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=8TI2Ea3BCnpMJtPQTi7ZpZoDXqgi9wwRJ0CJqM3YOZE=; b=ifIyfs03qlbfZ1FQBeQyIwt1/NHj30trE303NDNFCX8ZUzhrOgk8XERXg4qywCh98+I/lMxkGP6nd7Xe4sPiaP1TBVCS6cq2VodQRYfILXm7oZKRYOA5qSFBsD1+MO2PJSBUcCdeh9y+mukRf7LpgW3w4JLyrDIsbeY+XokXQEEL4PHVEccOE0c/cRlHplVKzqZwbaE+ZvGpnJdVJ/RuASmW0MKby/WAtcvv+pK0raKwhmrr9Pp2t/Gkku72lcrQgDA6FL0wwdaS4ZcKk0sj7000edGJnuTrqgFWdCTLA91Rq2Y0Zi2jEONcEB2BjRczVUEoZsmFHOtELr77D0MJsA== Authentication-Results: linux.ie; dkim=none (message not signed) header.d=none;linux.ie; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL0PR12MB5555.namprd12.prod.outlook.com (2603:10b6:208:1c2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.26; Thu, 15 Jul 2021 00:20:47 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482%5]) with mapi id 15.20.4331.021; Thu, 15 Jul 2021 00:20:47 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , Daniel Vetter , Diana Craciun , dri-devel@lists.freedesktop.org, Eric Auger , 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 , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Date: Wed, 14 Jul 2021 21:20:39 -0300 Message-Id: <10-v1-eaf3ccbba33c+1add0-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v1-eaf3ccbba33c+1add0-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: CH0PR04CA0118.namprd04.prod.outlook.com (2603:10b6:610:75::33) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by CH0PR04CA0118.namprd04.prod.outlook.com (2603:10b6:610:75::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Thu, 15 Jul 2021 00:20:44 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m3p7K-002Uxi-SQ; Wed, 14 Jul 2021 21:20:42 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f9e3d6f8-eec1-4a4b-c607-08d9472662c6 X-MS-TrafficTypeDiagnostic: BL0PR12MB5555: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2582; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uuZ3WE1GS8Qf9leKhYqh2ACY9H2dWiG9291zHTadGdj78FDFrwCCcPZyV1D3kZ9Xsr3TaOQW7WL0RLebEEpJFFlz82BjAvOOKL7yR4W1WkVC/gRsHGGfmER84+YD8xUxu8elrBDyjz14rRcjVm6/XF9qF+G1rGGhFKQ0HyK47zM8095iGRk1+KFM9wJUEFzhGFcEw+tikL6NZ3KbdAF4ESE2KIBj7j82TAwrq+ZVWTOE88q/xfs7e6OLYMY6in/xZl0Wa/hcbEz3dwCCmFz/elZHIwkumSV1wi4YrjhBaOsse+iaHIlyLpvnOojuAI3UGH0C02DH2LhotELI5q2QSMRWVHS46jrjEKl3qX4kjzAvo7iGGZLtTL0G4jojPLxnfCB3s9oIrZR/xOWA61e+EdPl2C6b4181y11k+2kEpqptz387ZP1QzzpDZv+Ji/ApZagmvVkcGOC2BPi0pbPMrnY5rwcGFC8hF8ieaggFz0GDDQGC6RS59Kcdku1UWHQpEQmbOMexrBb7Ho5w+MLmWECEfokMnuhG43v1ga6Zsw5mAVMTjby7X2pnZix2pMZKkQAKd8T2RI8ryolwn9lxlI03O69Nqab89M2od7pYtjJlQGAkbn3VBfg4+UJtdno4dZVS8aD8CZZIkYKoGLR+gb+yCwZOL41A3xVwJFZhd1pDBXqiC0OMGTc3N8H3LMd6 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL0PR12MB5506.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(39860400002)(346002)(376002)(396003)(366004)(83380400001)(2616005)(426003)(316002)(107886003)(2906002)(478600001)(4326008)(7416002)(7406005)(38100700002)(36756003)(5660300002)(66556008)(66476007)(66946007)(921005)(9746002)(26005)(8936002)(110136005)(54906003)(8676002)(9786002)(86362001)(6666004)(186003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: a7UCNAQBOdzXVo/gdEQiiptGZ0kfwpD9YuJz6vhr2yxu1i0L1kKGwoLGLe9OR0PuVukpk9GbdXt65Va9PscM146HzT82n7o/n24cYlIuXMEFCqn0kGmGDLRYnzSO4/knLMBNB+h9vUIWGY4eQRUj0C9RWRavupXHmVIRYfegdIz2DVdjts5we3d9rbZXZMo6CfuAVQ1tLUxi8p4NaPMGc+W5mMJqmTN6zUPib4s2LYk8jKMtKsBi3SwSjMQzwu3gYjE4ywlDmBLAgIPp5uTYoeXquGJGI5l2pkviw95xxt2IcFCnYgifYWnZEJbAEpC9B7Vg/B3SV61VsuoOGFHjjcLKYyOmRbFhG7MjSz8vLWEdgN/BfJH9QVxxKROBIeJs5XDXMZVpZ17by4UWnuc1l/VvC9U8SJ62dOO+2/FPJUKuhXSbikcg99cIfa1nH5nVKV9PO3TZQj0PI3ZPfBLlHRjE0A274HEly2b9Hmj23AnBcQPiNkZzAdDvRU3aZVMAeU3o2gBC1+3DXLsVt5K8rW5G/ypJPRSn4E6mUftpMCW0mkwqrvQcsBv94ij9LkmM7cuLH2+CWsAZ5pj9ll62VEpXFrRoWoIE4bz13MhhNnFFRTaWG/Ow7EDAdfRgfncGP6nvj/shfpnloQBLC5ThusKciK+O1iIo+h1rPtS4vxY7kX7hJn9L1LTL06eCLaY/B5kyX3E6crkw5BVVxbRPt/5PLym8iVDTEu9EMoO5OtZ/HJBWmcK8afQ2/tS/Q/yOWjXYCV8lyq9GlZuLOBiSTtinN6OffJUYgwFLZSPAaSblu+MSGc8BfJOe2hR7+G9X3qoLhVLrc9+lWdQraPbQl2wWuiUPv9RP27uvi01zXQ6A3sLpoCFX7oMl0IjzqwF6vM589Xjmlz2nmw/hmgBhbDrX8BgdpGTs04fsl1b5hKAJYw20S5wvKtfFS4uxmmnSXZNDLxTAcbRIzcsqbaz5m5hgdc748aNO3SDh70BAWZls6rcaiiDGvgS0raSQefnR0a0fEdX1LM6zlFXo9VH3bmtCYfkRaljSGBJUsj/XWhqVKAcNGCnGnDPDaf1uIamuJajDNBCBVQxHdPNkuwfsclpZQN2pwkafZsYeNSwPDJ7koxHog/Wrm1BFFQH3UevjIIeOtFtWLiyHfITyr3L0HYmr5z5o1gmGNL78IdJ5bPu9JBaEWIlAQvxt+7egS4xAn1K4koFJooGFRjOKctMjqEPKU1LPKIuPEvOfElgNb7FyNnR/GH5V3U0j9/J94AmNcHkmd8DG18zakG96+V19qqPcvM8Op6mIH8fJsNzQazdvb47oW+qaFBL1VJzgThDD X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f9e3d6f8-eec1-4a4b-c607-08d9472662c6 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2021 00:20:44.3359 (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: Ki3GThN1F1zFf+p+MLpbwMRfPHP75T0Oq7KuM9Q5yboKmP+EU/Rpi3EOsBLDN1NF X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5555 Subject: [Intel-gfx] [PATCH 10/13] vfio/mbochs: Fix close when multiple device FDs are open 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: Max Gurtovoy , Yishai Hadas , Leon Romanovsky , "Raj, Ashok" , Christoph Hellwig Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" mbochs_close() iterates over global device state and frees it. Currently this is done every time a device FD is closed, but if multiple device FDs are open this could corrupt other still active FDs. Change this to use close_device() so it only runs on the last close. Signed-off-by: Jason Gunthorpe Reviewed-by: Cornelia Huck --- samples/vfio-mdev/mbochs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c index 199273bebcc0e2..0137494c203aa2 100644 --- a/samples/vfio-mdev/mbochs.c +++ b/samples/vfio-mdev/mbochs.c @@ -1274,7 +1274,7 @@ static long mbochs_ioctl(struct vfio_device *vdev, unsigned int cmd, return -ENOTTY; } -static void mbochs_close(struct vfio_device *vdev) +static void mbochs_close_device(struct vfio_device *vdev) { struct mdev_state *mdev_state = container_of(vdev, struct mdev_state, vdev); @@ -1392,7 +1392,7 @@ static struct attribute_group *mdev_type_groups[] = { }; static const struct vfio_device_ops mbochs_dev_ops = { - .release = mbochs_close, + .close_device = mbochs_close_device, .read = mbochs_read, .write = mbochs_write, .ioctl = mbochs_ioctl, From patchwork Thu Jul 15 00:20:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12378169 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6719C47E48 for ; Thu, 15 Jul 2021 00:21:25 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 96F1E613CF for ; Thu, 15 Jul 2021 00:21:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 96F1E613CF Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AD1686E52A; Thu, 15 Jul 2021 00:21:00 +0000 (UTC) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) by gabe.freedesktop.org (Postfix) with ESMTPS id B782E6E513; Thu, 15 Jul 2021 00:20:51 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Rz/cYWCzazEACVwZSW3ew24n3hh6YzyK5hOaIRtBFzuJnZ6lI5IAxva2GuWoINyem0oLLv6LYFW9L0RlyU8fQhfymtPr+CkrwniAKASGrKlSy71uYyCXfRhIW83HIWNTIyb066GJez3SuMV1pgZRpjVxOpWPGbicpyXDH0haCbkVYwKm5fcy5z0ni6Fo6hpKWrffvlgrzo3WaF54bmNvVRw+jtEpPOPLu8+VgEU8SwdFHp7iRSGrvwcmB/txjhX2+yicAPNvppq5NKIyMhv3lIyeWEYLJuUzHBEB6ko4MBr+7ZMfi0fWQyWjzm2oD343uCTmyLYVMXnhooJd+TnGSA== 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-SenderADCheck; bh=dl++p2mqgSkgtxbxzA1c4mbO75hETCVTZq0tQWzbH3Q=; b=TfJJkZvL5QhDJyfwaru+HVvu1qpLavrSTUppDLFBWQAihPF10q4jvoJcx4sH17ssEGSibBuM2iZU/l8P24uvQxb+zYsHULPYWBGOjtZIBjmC+DHarIn6eftg7R6ASz5P+wv+blXDPj69zds+Rp/kHz51gVWV7tR8WCdBXfnUg7d6KLQloFIRKuU0mFwk4Jbn3WNzRNWnhtPnUfm3UWt/dtoNPRuS9r9j9GKI9/4cnP3sVjE8RALOUKr6PEt34WS9fc0+KTn0Hqc0nhmSbioorIeGUF/NJpS4tT56jJxuOhB1ViVdoIHH5trTicMTV0fz+Cs+8cnl8J0/SqLS/eTbmw== 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=dl++p2mqgSkgtxbxzA1c4mbO75hETCVTZq0tQWzbH3Q=; b=BpXFs9ntVTCEF/NIbS1AwtgqrL7D4BFuB/JlQC3rGo1ykwNdS1qovcyJneJaBsKu53M/ftLC+iVkfCj2ciHCp4YWDX0fCgV3b9FhJeXz9M7Hr659fQhT/+DkPqWOI/tL0vgk9LeMCMuzHJ+OFzAd3xT8voRXtW5xEOmhljY9zQxDSJcEvzfRVx4sSm/3i6T/kZ12F8LS+3ev/tMzWuAA8ML5dChIhzOYDeQcOje/wFgyP40faVMuKKzt1fQZWlX3ubFNCIDDJp/tWMEqSX3p+lotfdXww5pjeFdGN0ejFZMLICtDWSTBuWCrHqCbfPJCVdy9vXhPAJvHbpgVr/K9Gg== Authentication-Results: linux.ie; dkim=none (message not signed) header.d=none;linux.ie; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL0PR12MB5555.namprd12.prod.outlook.com (2603:10b6:208:1c2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.26; Thu, 15 Jul 2021 00:20:50 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482%5]) with mapi id 15.20.4331.021; Thu, 15 Jul 2021 00:20:50 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , Daniel Vetter , Diana Craciun , dri-devel@lists.freedesktop.org, Eric Auger , 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 , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Date: Wed, 14 Jul 2021 21:20:40 -0300 Message-Id: <11-v1-eaf3ccbba33c+1add0-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v1-eaf3ccbba33c+1add0-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: CH2PR08CA0021.namprd08.prod.outlook.com (2603:10b6:610:5a::31) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by CH2PR08CA0021.namprd08.prod.outlook.com (2603:10b6:610:5a::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Thu, 15 Jul 2021 00:20:45 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m3p7K-002Uxm-VN; Wed, 14 Jul 2021 21:20:42 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b67b33f3-a416-46c6-2bc0-08d947266388 X-MS-TrafficTypeDiagnostic: BL0PR12MB5555: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2089; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LzA3M10skBpdCQY10cYOMzvmjn6IQ2SvU16LKWhsM20bsSEHK9AH7dm4LYPZOBbY2Wyz6jFUOoQ7kPi27fBfFNR192cbR3tWIU3DbnTtksfug9gwFv7BY+puTxA4EmgvHiqWuL7xuRwrohktZsigd++sh6V1QWe/tGBODrVOTcbvYuR9BXrwfsfxB4ieH41Rb6n4UU0vEXr8e0GwYH73BF+J2lb+8OUNc850LxS73yg350taGYDcrg/+hGTpxN+Vhw4J71PuBjUpuEFeimjp88si92XF+yVSQiKM6pZB6FVwqmKrqsPq9tkTeDxzAfMqQdte6vwQ4DixSQ//o6CN+UAX/7lNeeT74MqEB2cwI9iA6MnC1m5RbkE4ChyOp9fCU1GfUORENQyuSQ7TSUys26t6MSMzs8FMRBjXhO1SCmR8rRni1bOqxQtAmNRMDXjp+HLTvSWGAtM6pWGXP8ZiFYms6KqG0g1Tep3H/mgycntZXBX2C/aXNy8Hzkq+ztpD70qT+8ErS68UruUVhm4/3VR+wS34JfNSO76EBEE+Rm43Dp5LX9ATNFU6K3j0g3tT1pjQjp0e3WF5qp8FqnyYs5YqxpHV5E44kjiRfFGZQyPywy2lj+qFBlXzuuau2ZFBdqT/2zW0xWVvJJneWZ5SZgWQnJygRdXKBSeHPXy+dxHWdhudG+B6OLWfX2WKxesk X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL0PR12MB5506.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(39860400002)(346002)(376002)(396003)(366004)(83380400001)(2616005)(426003)(316002)(107886003)(2906002)(478600001)(4326008)(7416002)(7406005)(38100700002)(36756003)(5660300002)(66556008)(66476007)(66946007)(921005)(9746002)(26005)(8936002)(110136005)(54906003)(8676002)(9786002)(86362001)(186003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HVDSh9XFw+89KNVKag6eKI0GSNEoQ7Xb/BevIu/ntl9b0KG9dOr2yt6eDT4iDGTmEtzK1ZriN/8G/30dKhF1rBnPkSscLfK6o/kF/PfpTMQ0fM30vx40cupxIYUvv2Sd9qcYiwhrdv4jvsyYk7pdobR6C32wM6MO4vVhETpDTitqDOSJLpnkXP23joeynhn9AKaophp/192CLIhxprpoKPdYhC9s9GI5yRYRU467j06OGu0pqbQe2G3egepufXZcJCBiLXPRn/ivQBqojZudeMXESV0zw9kHieyvM7Q6e/oM43Qk94qRp6FAAA5ubslPhw9l46ksoOIDRt5UbnkqB7NBGJqR8nzV8oFFDt4UTYytuRdDAMBapjEFm7jBfgoog7QsmXacYN95QdrGRH+tJ0Iiqu/rz2VJSgci6KsDTA+hEtByB6h0b2qxKqae36SiuXX8XOF2snWKIh2k1rVAOX9wkhofo0yalnWpNCXTsb1WeLzUu4LxFaN+fvkEkdQCmnLFo7QRtCT5X6jDtZTABOeHu86JwQtvPsjitmJ0nfdVENDhwRkKXYuj3aDztFhVhhoqVGMRRYjVxokvUtfz1C50XnFBc6ErIE27NFx7+IPCvU9R+Q2OKWJI/7hvxDcJuTuWL0Qv0KFcS+JEBYUPjkUp5UddvdsahweFMNurEy3sjSOePLO1qVeVN2+NOcDo5v03wxBWLvIHybwFTr/Q9qXTdGWUCp8ixxmhU3gWqmlBU29rBtYpmPbfRZMLVXiwv6eVmNZf2ksFo1TeTou8euY99THCLk4cuod6w766WfLqXIaTucgkl5/RqffL780dqz10aWehvo5Yj39lj2hLUGGlGv9GKeTFQ/f6tF+MwhtZRgpbWiRnyXA0SmmMGWIwyV8Q1ldvJn53teG1P5nncK3UlyMh6XHng2uJfV+gO7n+JOJFNsbq4FXUj7Db9pKSNERPiiJqKKN0rrHR7HCOa3NhQxZuXmDYY2iyJsrPsTH3/jV514gjRLLFfngYCfKThmh3TjnZpXBGgewKMFhqQkut0amQHtQfbTO5jxHNI0BLBOoPuduHS4AoFfb79Oy4E/uRln2BBZ21bPg4wJii75E/3lfZ0yfFVLDfzChohgYAPoXk20t7DBtORw2sf6e988VzWBYUp4lVccBpPC97dhtjHHAMGbuwHzqmKFZOzjx1SAw2p/iPIjLx450Ss8SWxv4QbuViSqXx0Qc8vdNAF+WlLI8SoSetgzmgxBJf/FHjIjvdBOP5PBOWyzd1wUg2+/nW/Ru89oi8i0iz7rK8JM2WwAqnqhmzgalp+bEB0D2X6OWoe3IHOIJLClNIghbK X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b67b33f3-a416-46c6-2bc0-08d947266388 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2021 00:20:45.5058 (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: eOxdT5EreDyWpZmRqgMXMDmg61U3lnagee1KkHz2zS5l1SRfg8o1mvXBysw53g8c X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5555 Subject: [Intel-gfx] [PATCH 11/13] vfio/ap, ccw: Fix open/close when multiple device FDs are open 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: Max Gurtovoy , Yishai Hadas , Leon Romanovsky , "Raj, Ashok" , Christoph Hellwig Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" The user can open multiple device FDs if it likes, however these open() functions call vfio_register_notifier() on some device global state. Calling vfio_register_notifier() twice in will trigger a WARN_ON from notifier_chain_register() and the first close will wrongly delete the notifier and more. Since these really want the new open/close_device() semantics just change the functions over. Signed-off-by: Jason Gunthorpe Reviewed-by: Cornelia Huck --- drivers/s390/cio/vfio_ccw_ops.c | 8 ++++---- drivers/s390/crypto/vfio_ap_ops.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index c57d2a7f091975..7f540ad0b568bc 100644 --- a/drivers/s390/cio/vfio_ccw_ops.c +++ b/drivers/s390/cio/vfio_ccw_ops.c @@ -159,7 +159,7 @@ static int vfio_ccw_mdev_remove(struct mdev_device *mdev) return 0; } -static int vfio_ccw_mdev_open(struct mdev_device *mdev) +static int vfio_ccw_mdev_open_device(struct mdev_device *mdev) { struct vfio_ccw_private *private = dev_get_drvdata(mdev_parent_dev(mdev)); @@ -194,7 +194,7 @@ static int vfio_ccw_mdev_open(struct mdev_device *mdev) return ret; } -static void vfio_ccw_mdev_release(struct mdev_device *mdev) +static void vfio_ccw_mdev_close_device(struct mdev_device *mdev) { struct vfio_ccw_private *private = dev_get_drvdata(mdev_parent_dev(mdev)); @@ -638,8 +638,8 @@ static const struct mdev_parent_ops vfio_ccw_mdev_ops = { .supported_type_groups = mdev_type_groups, .create = vfio_ccw_mdev_create, .remove = vfio_ccw_mdev_remove, - .open = vfio_ccw_mdev_open, - .release = vfio_ccw_mdev_release, + .open_device = vfio_ccw_mdev_open_device, + .close_device = vfio_ccw_mdev_close_device, .read = vfio_ccw_mdev_read, .write = vfio_ccw_mdev_write, .ioctl = vfio_ccw_mdev_ioctl, diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c index 122c85c224695e..cee5626fe0a4ef 100644 --- a/drivers/s390/crypto/vfio_ap_ops.c +++ b/drivers/s390/crypto/vfio_ap_ops.c @@ -1315,7 +1315,7 @@ static int vfio_ap_mdev_reset_queues(struct mdev_device *mdev) return rc; } -static int vfio_ap_mdev_open(struct mdev_device *mdev) +static int vfio_ap_mdev_open_device(struct mdev_device *mdev) { struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev); unsigned long events; @@ -1348,7 +1348,7 @@ static int vfio_ap_mdev_open(struct mdev_device *mdev) return ret; } -static void vfio_ap_mdev_release(struct mdev_device *mdev) +static void vfio_ap_mdev_close_device(struct mdev_device *mdev) { struct ap_matrix_mdev *matrix_mdev = mdev_get_drvdata(mdev); @@ -1427,8 +1427,8 @@ static const struct mdev_parent_ops vfio_ap_matrix_ops = { .mdev_attr_groups = vfio_ap_mdev_attr_groups, .create = vfio_ap_mdev_create, .remove = vfio_ap_mdev_remove, - .open = vfio_ap_mdev_open, - .release = vfio_ap_mdev_release, + .open_device = vfio_ap_mdev_open_device, + .close_device = vfio_ap_mdev_close_device, .ioctl = vfio_ap_mdev_ioctl, }; From patchwork Thu Jul 15 00:20:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12378175 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0FE30C1B08C for ; Thu, 15 Jul 2021 00:21:27 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id D675B613CB for ; Thu, 15 Jul 2021 00:21:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D675B613CB Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 256E46E566; Thu, 15 Jul 2021 00:21:01 +0000 (UTC) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) by gabe.freedesktop.org (Postfix) with ESMTPS id E92616E509; Thu, 15 Jul 2021 00:20:51 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fVxKnbPS7xp82y+m3M0uOQLyfXFAzjsfvhLTQoqyGnnOTycQIat6YM/ORbRSjYWCXgqFxaOFRQmdz6QQrRNz3xtcBhqE/0MKzp4XxQ/rqnaPBlsVfUWB49jXCysUAj6lWlUIKExQACIFFnO/dG08BzUPzY8L1cddi4sEqlQFFtelUZyn9y2EV0xdSwdSiIFb9usNd+7WG3n8qmGwgqUCiT6KphE/Z8Gb5Ue2WRPpkusKhisG5sIC+liHrpRh6PneslMPpIqITj2Qe2BHvDXQ4dpGiuMiE3H1ctNyMqlIq39dtMvXvR5Otn2v2gnqFg/zhhz3bVNUB/N7RsdmugBgag== 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-SenderADCheck; bh=pj5tHqtZZfmXNCPWoIxbB0j4cm9g6t/Q3wEIFPP1DuU=; b=ndO1C5ESw9nnK3HuKXHXlr7fh4ccK5LFUaP88w7rp2oHjDDOIwmdTaCCLi0iDjl3o+zOs4qLuFA0nifOSoWku78G8N+RUPc0TrbTPK+J50IVQGjeOPGlbiib5+kZUWAmZVNGEqrJmdKey8tLl9jpfMJ4QisLAv3WirTfaWxRBIx4cQYWO6aOwEc+dYV7/DjCKDUdd6cp3Da4V7F82ZLzqoSlfngKd+YHUVwDe9IrfRFGD0QMGV4PsQsmfGmDReBpk1Ju1iLTvFZPR/0LVoYtAPC4zcUmpoZuVtdnj6gQeqaOv+i6fI5578TdFsqfBN3qYrg6Qifi4e+My6NQfTVoMA== 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=pj5tHqtZZfmXNCPWoIxbB0j4cm9g6t/Q3wEIFPP1DuU=; b=mIvT5HNo3yPKHuiwycjoVCmTOMLPf/3U6r/6lgXd4ySnYRQfnbNEHjU+h3uHL4yGZztVF6LXoIlvmb5jYpnrUMnSmNTRc1z3X73V7xnpIWLoQ51rOBArKXo5z3ruMEsJAtqS/mNa6qSxpDqa/lSqpO432KOGKgli3oPHs2x9X1xpMBLzQlC74Ag02OjkYQ06hRd5jygItzplxkycUFCNeIVRSQ1ahW+bhqz+TatF6y70eLfeQpn8vXKdmyNMJHA4OSNYT/qQXIqnQUz2j9S6LePAB6EE4yUDa+nDdPkC+B+PFI0mfnudTC40f1t/6dL9QrN+UNhdNydQ73qaoBD9Uw== Authentication-Results: linux.ie; dkim=none (message not signed) header.d=none;linux.ie; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL0PR12MB5555.namprd12.prod.outlook.com (2603:10b6:208:1c2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.26; Thu, 15 Jul 2021 00:20:50 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482%5]) with mapi id 15.20.4331.021; Thu, 15 Jul 2021 00:20:50 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , Daniel Vetter , Diana Craciun , dri-devel@lists.freedesktop.org, Eric Auger , 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 , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Date: Wed, 14 Jul 2021 21:20:41 -0300 Message-Id: <12-v1-eaf3ccbba33c+1add0-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v1-eaf3ccbba33c+1add0-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: CH0PR04CA0090.namprd04.prod.outlook.com (2603:10b6:610:74::35) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by CH0PR04CA0090.namprd04.prod.outlook.com (2603:10b6:610:74::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Thu, 15 Jul 2021 00:20:45 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m3p7L-002Uxq-2X; Wed, 14 Jul 2021 21:20:43 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c8bfd7d8-83d0-44ae-f9fe-08d9472663bb X-MS-TrafficTypeDiagnostic: BL0PR12MB5555: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:608; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mq6qyZ86c8jKMfF0rx5PJoMEqF7xQFR5WpHWuiguLrCspPB72MYS15io8lumYMaAPh4L4V2bxQflzPKVaiEyqyrSUNyUnWbYwdih0St04F5SALCyssYFsbsYBBGCtrWTeSGwvv6s6zUiNRZVHDzijh7Y6ak5bq3zrS6eUIAxMMWKSM3VOVm43KSASFvMjAhNYUdprVRppK9Kb8Y3ILWmrDZ28nw2JWZAToyh9OQzlZIEAfKjgw4OISGn4GXjfYBxc+dD1LLIIoH0T3Svo7ccvRZyRxei/7nIdOU4OYv/AE0dOsp0kzd2RzukHQ3j4XKrzedZOuwIXlcZwbCySmWOQn20AMV4tHHuoPQkvTPuYM4iZXg6BVWoTwTaeKVVD2+EhoyeFIj4TVuFBQHNfMMjaoX/iiFAHBb7XZS+IWns226+x0+TKxssNrK6kOk3gDCjIG0mJe9EbZiJ6OG6uq0o9R4Xs9iWa/1WnJvUAMc+AiNp7BOITHRsUrsJtlbF2vE/AfRZ1m54AUk8DBWuddvlqb9LLFhllh8ywDjLKw4tGFfwAqBGxSszbN697vy/uZ0FG1W1kqruZK2n2CuT4sS/tjV4ZJYHMg1wwuJIohVpK+6/u1ewNTyycxMwmYT9rAzonV5HK0DL2x77m/TfQhM8QTGsNSo5tXJniSlDWnpSmM34QkNyq5mVtpgA6fubhBvL X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL0PR12MB5506.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(39860400002)(346002)(376002)(396003)(366004)(83380400001)(2616005)(426003)(316002)(107886003)(2906002)(478600001)(4326008)(7416002)(7406005)(38100700002)(36756003)(5660300002)(66556008)(66476007)(66946007)(921005)(9746002)(26005)(8936002)(110136005)(54906003)(8676002)(9786002)(86362001)(186003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: mzXUpv6JrI+Z0zYw4lRZYv5so0SZcdPnHDXDK1B0aAFDoTKtyxd4U0kUuqL/E195nRx+Kw6yPww8GwCYUHESZrKBPy21XE8RVkO/aciMm7/OnihORPzhxB2B/zlmdrCihy+Ainabj8D8/p9KT9wsfsqXFYkF+if9OLxgr84okSri2VRdnqYsNSAhdXDM5sWRYF2FUwGo3gNRHDBZsSrGu6cP7C0i6p89du3V4bY61IP8pR4the3U1YJGlmppbFfzCNUf10iiT5c6bCohmz0UM4Jlxwcr5/WVfEKqMcmHdbEBUaLJE0xM2eVjfnrZG4I+/0IcqM5X43SyzPrxldiQt7DiCydA7RXaB5A/AtEdqvFu+X47/PtfHjvlGNy3BzCBobJevYiU7t5s1Qeeav3sF3SEekPFqFX+l3MxqXY9EsxeEtWjm+h8JBgfV+XZ6kUbSrmb/sxGjVxwaNWod3QEJhbi9x82DxjA8ZePNxcJE8u8EVEyHsLQ3xndt/EgvZFgm5akF2Tm4ekc7PD49ZVVqaPJn2xfH47D5j1r2YRyPS2U87HVf1m4MG9hBsA00YEhcyFSC0fXJqABdO+2WOBWpn52+Qqop4kDpezA/+dMkL7Bgyvh+FoEi4wa1Ew69QAgZcZq+GoFTZgHSeESyqkUkRZe/qK6SEWGIzPD3KlYeXUHLgOxG2JiCB+os0uA3F3el/QgDQBBB57vZpvSkemLorCLMPxsZIZvILqkRFGRAarDq+sHU6qoogDlaStTTcTLeXgqeb7Wq8NGmF6n3TI3dVLz/eFhmica6T58LT4ynr698X7OCWNlXcuF8iCgBrZzidnu20t/5zRu7CQJue9ep5FAvRey/HJHzinmlsDE+fgzmu6ap6xn/OebOpvM8mPRk/5xpkfr2hMLKcAa5LtSadWgM9KueKsDN8/ewTPBNC7sBPqKwEfgqKGB0/jGHsJIf8uhCYZl7lceECHh2RkaR6FR5WucGewW1tLZ37ybcUzvVXrthVdwzvHdg7AI2JrwRpeO3i0YKD7NLERyB+NpKOBScmGWUjUYR6/PaiYAS3giYxsMDDN8VDXwfzpiF4lCrkFej/25rBtbcr+C+r73b5/Kt3yn4lr7IG1JJcD8HfcdMk+QY4f/0BgBB14SzUtCjoWc2vonPnk+m9vPZ/YiqlgNLCcipn2DKq7tFLfMYGnwDHI368732Y25cPJB3Z4WehIw0hzIaKDqbvhQyyxE64YaDv244dMU5YFs6srj753kj4UeAcs1DPzwyqrjXdLmvyhpgtzAWlJJ3Ylx06aAOKIIi6Qp2zLEFPEeoCvMJZ3lLUQd/EhjW4F5Onw9hWoa X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: c8bfd7d8-83d0-44ae-f9fe-08d9472663bb X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2021 00:20:45.8543 (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: CZRAfDgxwaXinE0ioUuNzWuTFmTaXmf5uXXwv31rtBSDuEN/jvU5gdqcK1HyPNxM X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5555 Subject: [Intel-gfx] [PATCH 12/13] vfio/gvt: Fix open/close when multiple device FDs are open 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: Max Gurtovoy , Yishai Hadas , Leon Romanovsky , "Raj, Ashok" , Christoph Hellwig Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" The user can open multiple device FDs if it likes, however the open function calls vfio_register_notifier() on device global state. Calling vfio_register_notifier() twice will trigger a WARN_ON from notifier_chain_register() and the first close will wrongly delete the notifier and more. Since these really want the new open/close_device() semantics just change the function over. Signed-off-by: Jason Gunthorpe Reviewed-by: Zhenyu Wang Reviewed-by: Cornelia Huck --- drivers/gpu/drm/i915/gvt/kvmgt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c index 1ac98f8aba31e6..7efa386449d104 100644 --- a/drivers/gpu/drm/i915/gvt/kvmgt.c +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c @@ -885,7 +885,7 @@ static int intel_vgpu_group_notifier(struct notifier_block *nb, return NOTIFY_OK; } -static int intel_vgpu_open(struct mdev_device *mdev) +static int intel_vgpu_open_device(struct mdev_device *mdev) { struct intel_vgpu *vgpu = mdev_get_drvdata(mdev); struct kvmgt_vdev *vdev = kvmgt_vdev(vgpu); @@ -1004,7 +1004,7 @@ static void __intel_vgpu_release(struct intel_vgpu *vgpu) vgpu->handle = 0; } -static void intel_vgpu_release(struct mdev_device *mdev) +static void intel_vgpu_close_device(struct mdev_device *mdev) { struct intel_vgpu *vgpu = mdev_get_drvdata(mdev); @@ -1753,8 +1753,8 @@ static struct mdev_parent_ops intel_vgpu_ops = { .create = intel_vgpu_create, .remove = intel_vgpu_remove, - .open = intel_vgpu_open, - .release = intel_vgpu_release, + .open_device = intel_vgpu_open_device, + .close_device = intel_vgpu_close_device, .read = intel_vgpu_read, .write = intel_vgpu_write, From patchwork Thu Jul 15 00:20:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12378153 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA6F8C47E56 for ; Thu, 15 Jul 2021 00:21:04 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 78FDF613C2 for ; Thu, 15 Jul 2021 00:21:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 78FDF613C2 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 76FA66E519; Thu, 15 Jul 2021 00:20:51 +0000 (UTC) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2056.outbound.protection.outlook.com [40.107.236.56]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0531D6E519; Thu, 15 Jul 2021 00:20:50 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z7ts2h6hX79aIciH4XzLTjhzwfARdAvrG/ybrqC8/YNoFMB8DgG1jGAcuoIgMpvxAXyABIxB9JHe0QBlfkPN1fWI9Brguce790/PX4vcACJRv3WftTWv6wIGh8Bx0i8PHvAdRwLGeoTzaMbjqEjkLcOC9wUILGZRtur6YB+D1GNKi303JDNJyognChCDoXlL3L0YFvUk48uCYgrBJ9hn53wVvGHcW29IAtvb7PfmzCZ4GP6hNfiqksHqXxgfcGNnxYf3NGPa1Sy/oqG3no40jDG2LEODayxyzgx6w2x2RtDuCWRjNHsYKdjZfxU9JnhRftZ3idvR9s6a+4VV5eUC3Q== 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-SenderADCheck; bh=Auqkl+rokSHj5l9mCa24igTtZT4ZWOHO3IXhLaR0Z54=; b=jNbRUTae8nARiemlb6ZsJxIJRWXrakUziuOixqc9xB6KPY+Di1jD/kQVPmVAGEynSejPKyrnu7KaXDY2C0we0jE4/9Fy/pw/XbgCswi7wTT2srtHGifoTlZzYg2evyzEzwB1ctFGwnRiuuS+gyCtoUUSxu5uyEUWDXf4k7/ei3Vmg2/XWgkHq456kdg4vCc/FsC6LgFdLK8YCbEQuEO0D3fPkI4YbTMYnqXdatpMWx+Bz9DwRHxitjYSH7tzYxkAO8c/t4u9dD4gg4GjAzqr2I1v2nD10O21g03g5hItZx6aiqgZiDvQ9LNhr2c9tlOdh/9oDNEQJ7fBdqsRwyNi+A== 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=Auqkl+rokSHj5l9mCa24igTtZT4ZWOHO3IXhLaR0Z54=; b=SuzG6SfSjmtMp8jq6ewDjTewCN80vG5gS4v8nvh0mHe/hXZdlYOfi9UpNcLc5bd9iXQL+B30n6FtK3ecgVGxttbKyIBPBb0dM26Dne0y72RWoazI88A7QYyLPuZ6ecAqneTurSaKbLBhQ0awEkqxM4SQdg9LR7NZKSXYXFqybrTURV1AG5M6DLnjgiSUmmrMkaA+AGqj2rFcQnhEdhVBq7VOs3/OKVaPD/clTJlG78aewelOGgpNfSFL5MNj7RTieHHCyZEpSDjjMnh7RfaDIGiZNFRIngyK/u4shv12Xt3mqdg2M/YXW8Jgn4oHFhIeptUWUOrSUtxMBTXE/VW+dw== Authentication-Results: linux.ie; dkim=none (message not signed) header.d=none;linux.ie; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL0PR12MB5555.namprd12.prod.outlook.com (2603:10b6:208:1c2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.26; Thu, 15 Jul 2021 00:20:48 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482%5]) with mapi id 15.20.4331.021; Thu, 15 Jul 2021 00:20:48 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , Daniel Vetter , Diana Craciun , dri-devel@lists.freedesktop.org, Eric Auger , 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 , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Date: Wed, 14 Jul 2021 21:20:42 -0300 Message-Id: <13-v1-eaf3ccbba33c+1add0-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v1-eaf3ccbba33c+1add0-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: CH2PR08CA0025.namprd08.prod.outlook.com (2603:10b6:610:5a::35) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by CH2PR08CA0025.namprd08.prod.outlook.com (2603:10b6:610:5a::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.22 via Frontend Transport; Thu, 15 Jul 2021 00:20:44 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m3p7L-002Uxu-4K; Wed, 14 Jul 2021 21:20:43 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 21dfe0e1-d42a-4473-75c8-08d9472662d9 X-MS-TrafficTypeDiagnostic: BL0PR12MB5555: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5pctMBqs8wGC2K3EdG7gJlsAVCRFyiDgNQ072PtIjdGN49q1bVsyjYw088Oy1D6iDL0BSZqSvDGH4xgsfyk1mxhL3kt8lxGbLComXULc7EQL+tEymWcDQ+1cOe68jHw11660QS1RL6h13Veo9ShKlmxOQROb8Q4zFGzn/gi7DlLKYpZTJ4jRxHvvBeSckRhC9MlwaTemswSAehmP1AnPQTwG7EC8j31b7cYbEoi9SQ0sPv4o3TbHxBId1CyyFs5PPPBnXZHVs0OSrBQnNDQCvpdbUiEMy1Z+sUxcl8HMZIxpXOXf5/gXrSDIq0Ye4dBK9OdVcGsqyGxb/H3oF3T/LmzrqoJvilxe717iCEiH0XbjOzT8IKRvHFnmpUN4FI6NaLL0FEIjnzmf+lyQEQ9S9GDQy9WkLZRxrd/kRF0sAqLtP+rVIBUFugPLo1Td4X2fNJQHVflKLlZJpwEnS2hIFFIRznn4tzQ9hHD2aNSLCiC5XLgxDglkAbQ/Fhv8XrsM0S4w4YvUwbbBErUhn+F+aEG0d06H4R9SiHQre7Vs3g2kG9ANFnCg77qVrmZ7F0C5CH75HPxpL57sheJmsvKZx0zTH69xYVINh9CWvd8ATTJudq7iInFWa534uiguba587qqEqBzb5F1RFES78usqMZwwYgpdAl7JkHgCJxP6rnLscTn4sQr0Pz5NKtWNm45X X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL0PR12MB5506.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(39860400002)(346002)(376002)(396003)(366004)(83380400001)(2616005)(426003)(316002)(107886003)(2906002)(478600001)(4326008)(7416002)(7406005)(38100700002)(36756003)(5660300002)(66556008)(66476007)(66946007)(921005)(9746002)(26005)(8936002)(110136005)(54906003)(8676002)(9786002)(86362001)(186003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nkADaqwYe+pzWhpUqF7Op09XUR10GMqIo/gjNwoIi1kNhwe1WyNAm/YVUwtpD8JnJURq6T1Xs5CWEln+0gqDVVDf3R/0gglErCPQzo0oMyC+wwRfy0Eya48X+8v3UL2GF+X9DU8RL9I76JS8NZv8Qf+GEuTzZ1GuA9wpp/bS4voSf0kTIi06NWFuYCka7rRhkl4vVz7mjrkNYfm+a4D8xpcT75mYdyyrhrrIrHumFk+ft8tx2ktb0kyp2iZaSiPA9P3hmOH66IM4PqWnl4tVKceF4OzTVm2cvyaGPokxoNkNaj7NCrEgZ4nwZ8zCIvT9WeWGofKKGWz5jHmMymmt9WJ1LFqqJoJP/12fGyTfwlNGnwqk+LhoUs5Z9fYdMbparBKzM2lK3hA95t1nXFQX/Y/8xMjJWI1yE4m1J1y94cZHJf7dm1CkOD72SDKhP8TBtacnjIMwGPpglToCVkK1RwC4bVScv5KlD2aitOeBRVI/eco9Mh0prs0a7ucsyh7MnzUKCgFE0vio6BBUS9OaK8OLTrsyLCNn9cqH0i365MioiZUMQNFUfqdS6M/0tvS0HZ0ZH1oWxDgF46OE0ruX0EHGPDrYX1j4fmf14nM00cFa6rj1qPDeaRmD8EgTe5BVRXxPd4rNfDZaDtUhYi7JEuf/9mgC37k1RUoF6uL8POzAggvLTScvJEQmRlQoSJ1aFfImAzd+oOYDvUaAznP18dqk0/zWcqV3vJkVa7QfddJFM2Bq1uuX6j8o234Y6rt0Oz8udSNnSf1//92IQizBPF+zLVyZh2BZLeO1vH6Y/G4pW3hPp7k6oBJd9EmCVAxaFobdIoRUnzZMlXLDg6A2f6lacS6ZZd6oWNTVkm8bE4WayXqTpV7r+cg/BESc0a1Tp3M69QOpv3lu0yyUjjw/JBYSt3JJ+H2GIDpjMaivYzKi45PmAfXCMy8bdvL1VbA6iS0coPeYlhj8EU+T/UL8U58jrDsBXaP/BDqsqbrOvF5Cua/zSOFShFvpAqLBjrLDDxQ608RdM68cWlRCDf1aZ7bRyJ1orC+2E6kC+GflUYaI6kPAHi/n6iCgjvBrL4HZIxNvp1rhR/dZkhZhFbE7GY4Orq5DW1qLj2pQcrkT69ZFyA8xPB0NA0bL0IQ5ue4nPn8N1U42k3GuaYpfvFQTkvC+unhKdX6zrtbUPhqIBz/1n0xa6LuW/3y3d0vWjJSaBPUdeOEicxvRqBZtYVmkzUqTp8IGEVXpEs/7F9mh0xFcLiSIw4r2AOeuutGGR0i8OMsYajxUkloBNpPWrEmbrF2pviw6nUyCx6BiwkmmjsLbaKsVQl4cqMgJcgCrblG1 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 21dfe0e1-d42a-4473-75c8-08d9472662d9 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2021 00:20:44.4166 (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: bdSFu6CrWc4OvzZCjXa0wGsgrOGAiUiL9/Z4edVflNA1f60ITQt4sMnQHirYSRCp X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5555 Subject: [Intel-gfx] [PATCH 13/13] vfio: Remove struct vfio_device_ops open/release 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: Max Gurtovoy , Yishai Hadas , Leon Romanovsky , "Raj, Ashok" , Christoph Hellwig Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Nothing uses this anymore, delete it. Signed-off-by: Yishai Hadas Signed-off-by: Jason Gunthorpe --- drivers/vfio/mdev/vfio_mdev.c | 22 ---------------------- drivers/vfio/vfio.c | 14 +------------- include/linux/mdev.h | 7 ------- include/linux/vfio.h | 4 ---- 4 files changed, 1 insertion(+), 46 deletions(-) diff --git a/drivers/vfio/mdev/vfio_mdev.c b/drivers/vfio/mdev/vfio_mdev.c index 3c384d2350b64a..9e39f23ca2f546 100644 --- a/drivers/vfio/mdev/vfio_mdev.c +++ b/drivers/vfio/mdev/vfio_mdev.c @@ -37,26 +37,6 @@ static void vfio_mdev_close_device(struct vfio_device *core_vdev) parent->ops->close_device(mdev); } -static int vfio_mdev_open(struct vfio_device *core_vdev) -{ - struct mdev_device *mdev = to_mdev_device(core_vdev->dev); - struct mdev_parent *parent = mdev->type->parent; - - if (unlikely(!parent->ops->open)) - return -EINVAL; - - return parent->ops->open(mdev); -} - -static void vfio_mdev_release(struct vfio_device *core_vdev) -{ - struct mdev_device *mdev = to_mdev_device(core_vdev->dev); - struct mdev_parent *parent = mdev->type->parent; - - if (likely(parent->ops->release)) - parent->ops->release(mdev); -} - static long vfio_mdev_unlocked_ioctl(struct vfio_device *core_vdev, unsigned int cmd, unsigned long arg) { @@ -122,8 +102,6 @@ static const struct vfio_device_ops vfio_mdev_dev_ops = { .name = "vfio-mdev", .open_device = vfio_mdev_open_device, .close_device = vfio_mdev_close_device, - .open = vfio_mdev_open, - .release = vfio_mdev_release, .ioctl = vfio_mdev_unlocked_ioctl, .read = vfio_mdev_read, .write = vfio_mdev_write, diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index 26d340283044e7..1d68e82137a735 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -1475,19 +1475,13 @@ static int vfio_group_get_device_fd(struct vfio_group *group, char *buf) } mutex_unlock(&device->dev_set->lock); - if (device->ops->open) { - ret = device->ops->open(device); - if (ret) - goto err_close_device; - } - /* * We can't use anon_inode_getfd() because we need to modify * the f_mode flags directly to allow more than just ioctls */ fdno = ret = get_unused_fd_flags(O_CLOEXEC); if (ret < 0) - goto err_release; + goto err_close_device; filep = anon_inode_getfile("[vfio-device]", &vfio_device_fops, device, O_RDWR); @@ -1514,9 +1508,6 @@ static int vfio_group_get_device_fd(struct vfio_group *group, char *buf) err_fd: put_unused_fd(fdno); -err_release: - if (device->ops->release) - device->ops->release(device); err_close_device: mutex_lock(&device->dev_set->lock); if (device->open_count == 1 && device->ops->close_device) @@ -1664,9 +1655,6 @@ static int vfio_device_fops_release(struct inode *inode, struct file *filep) { struct vfio_device *device = filep->private_data; - if (device->ops->release) - device->ops->release(device); - mutex_lock(&device->dev_set->lock); if (!--device->open_count && device->ops->close_device) device->ops->close_device(device); diff --git a/include/linux/mdev.h b/include/linux/mdev.h index cb5b7ed1d7c30d..68427e8fadebd6 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -72,11 +72,6 @@ struct device *mtype_get_parent_dev(struct mdev_type *mtype); * @mdev: mdev_device device structure which is being * destroyed * Returns integer: success (0) or error (< 0) - * @open: Open mediated device. - * @mdev: mediated device. - * Returns integer: success (0) or error (< 0) - * @release: release mediated device - * @mdev: mediated device. * @read: Read emulation callback * @mdev: mediated device structure * @buf: read buffer @@ -113,8 +108,6 @@ struct mdev_parent_ops { int (*remove)(struct mdev_device *mdev); int (*open_device)(struct mdev_device *mdev); void (*close_device)(struct mdev_device *mdev); - int (*open)(struct mdev_device *mdev); - void (*release)(struct mdev_device *mdev); ssize_t (*read)(struct mdev_device *mdev, char __user *buf, size_t count, loff_t *ppos); ssize_t (*write)(struct mdev_device *mdev, const char __user *buf, diff --git a/include/linux/vfio.h b/include/linux/vfio.h index f0e6a72875e471..b53a9557884ada 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -46,8 +46,6 @@ struct vfio_device { * * @open_device: Called when the first file descriptor is opened for this device * @close_device: Opposite of open_device - * @open: Called when userspace creates new file descriptor for device - * @release: Called when userspace releases file descriptor for device * @read: Perform read(2) on device file descriptor * @write: Perform write(2) on device file descriptor * @ioctl: Perform ioctl(2) on device file descriptor, supporting VFIO_DEVICE_* @@ -62,8 +60,6 @@ struct vfio_device_ops { char *name; int (*open_device)(struct vfio_device *vdev); void (*close_device)(struct vfio_device *vdev); - int (*open)(struct vfio_device *vdev); - void (*release)(struct vfio_device *vdev); ssize_t (*read)(struct vfio_device *vdev, char __user *buf, size_t count, loff_t *ppos); ssize_t (*write)(struct vfio_device *vdev, const char __user *buf,