From patchwork Thu Jul 29 00:49:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12407175 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 5F9F7C432BE for ; Thu, 29 Jul 2021 00:50:03 +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 328EB6023B for ; Thu, 29 Jul 2021 00:50:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 328EB6023B Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 355A46EB70; Thu, 29 Jul 2021 00:49:36 +0000 (UTC) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2088.outbound.protection.outlook.com [40.107.237.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id C7CA96EADE; Thu, 29 Jul 2021 00:49:33 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K5p5KNKfs95FZ9UiCtUZlaid+68LBpOu3SkZY90tC+RfjP0IlyEzurU4dpWmMkSRmfzFfQOZ3e9RvGay/fcVWsG7tdFa+Rb15J/hGe8o+QQP5mj6mQE4N81O8N9HAiv7dUwBZU7u9mSQioUCPLLv/lVCPpPHczdAevxJRBtg8qF+tEwg/JfgWvR1jsafMVDi9K1TGVV+NSgZKdo8V5f9PHqI+li6p/HH2Z/xmL419/XjjJPSGjOdbTseXQkUYKyt2HA+inPf8uWPTI+JMb15EZoeFVSeoGYkNezvLyLcLog+6+p2mHlkXAiwPA2eCrzQvtL3/8cssEEpZaMb341y4w== 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=5T9Co41XNdb794U0C4CUNz9k6AqD0LbtOYmBf9HqKVE=; b=dgyorBQ4hOMDrlvYzLFsJwzcVBtQBKG+LKFSOH5tF4Nzif7ouw+xtdRVACe2svsveL7QwUHxpSXCOScTmpPH3Ev4Ww4tshIJhGsyAg9xJwM2QMWVdq2clCd68sU2zZBN0NKhgxFs8pJ28BSLZkPtlFE1KTJiAy8Dw+aSVJWpIgE4Dpij5Mzs8spOvzLc6Cb5eDGQmtfaLg2aTggY+2GM0RvzWWeOXeILdMPIYLmHBTTjK4+ogJFkqUX9iX5rRxxbVnS/s8hGIWWiiF9JhmKIWEhJh6Ho4oIieoRg1QTFG2MCWt7kogRWvui71md99CqsW2kAJehKiULcFenyZMTi+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=5T9Co41XNdb794U0C4CUNz9k6AqD0LbtOYmBf9HqKVE=; b=sBJ8ttHk9dvt+yjRu75P7zvQZQBkFnycNB/b4mb3WW8dzsaLAZccEDW/2BL+GgTCAzcQCdrJ58bJy9zjb+FyNFOEb6XCZFqN1x/3TZVVUmss1xUO0Yp+hfeioPv5uXZwg7wbv8wXLGFT6hyVuWOaytcJJeMEHTsaARNHpUOFEXkD+d1FCizKAfzM6SYriTf6eE0GU4qj49NR7Vk8stChENfHJpYUXDADCcAt+YTB2/jzmdYEC36QsYe+kpeEqWTMDquyKEM9H47xIMFF86AES0mKdzIrq4Uu7QrkyIxFmjdTDGGhg6SmTkXDykXCKnNvfgK9YMqtifIikKwvSBkM5w== 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 BL1PR12MB5160.namprd12.prod.outlook.com (2603:10b6:208:311::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.20; Thu, 29 Jul 2021 00:49:32 +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.4373.019; Thu, 29 Jul 2021 00:49:32 +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 , Zhi Wang Date: Wed, 28 Jul 2021 21:49:10 -0300 Message-Id: <1-v3-6c9e19cc7d44+15613-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v3-6c9e19cc7d44+15613-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: YT1PR01CA0044.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2e::13) 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 YT1PR01CA0044.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2e::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.18 via Frontend Transport; Thu, 29 Jul 2021 00:49:31 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m8uEl-009pmg-NH; Wed, 28 Jul 2021 21:49:23 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 932e60ed-2554-4aab-f231-08d9522ab9e2 X-MS-TrafficTypeDiagnostic: BL1PR12MB5160: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EhstPzCBDzRfQ7IIh7FwglopvD42DtD5xy+bz2btuDmuR+x4CKWddzCMRooedqI5PK0no8y8Am9Ok/gO2D6nYeNien7uJ+/5fEiVkyw5c+ueHYaPHGEfrwbgr/jgoDJEtduBm7dlQAS4wIZKBfWbF/dlc+mAekcYOsfiGeutDH63ULM6zBFjNF9PfIcTgd8+W3VE9BA2+YBYyYPch/yrsvPr8wO8OZXDrEnDJz9IjX2x70/lwuJloPvRdjmPwtIPvivn8ABz7uX2m8TKMDeLBJUsTr2QTW1dbQK9MuM3Hpv7Kp8CUs3xWZAhAxipxfOaNJOyr/JQBqY+e6myZYYcxSasp963gQXtzE9ak69qExAiTQ4u+fsW4XJzIQyUqztUbzsG5Az9gjmPs6B86p98fF2NVnTbQGclv6jn/jvSkAuV3pkr35I8alr7drVDqC5HXKtY4weejcBjNBIOSEbS8kgYvcE9ZcGWSCAJPScTctjtmfuyaZrbzTrBwfjSPKwexjt2VEPbC5+a3XKmLePXZbXfLy25vu8bNssipQzY2yNarL6/J35lPcjBW8lu12R5XJ3W/jja5+9t66qQkaGI//vCtbvWyQWvoqzz1J43lFSjdAS5XJ/QZvDslIU9Qw6UOh+rKKXXQwueNT6cSHedl+H5hruLhUOFu8JgBMWm8BP8A9Vs78GfmapJ3Pnlq0gNpzsNlFU/zopG91DBjoCkMw== 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)(396003)(376002)(366004)(39860400002)(346002)(8936002)(86362001)(2906002)(6666004)(426003)(921005)(8676002)(2616005)(5660300002)(316002)(186003)(7406005)(7416002)(54906003)(110136005)(26005)(66946007)(66556008)(66476007)(36756003)(9786002)(9746002)(4326008)(83380400001)(478600001)(38100700002)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nYlr9ZlnCm8QAjiDBpR6TJxVpwzvBAq7HiHpPGoFcw//VUFl7PP/c05hiEmAISleaUfgBvgav5gGyje/POi9s0H8RwtInjqBhJs5OJj1iZ+okTqRUWWtnYy08vkgkc/N/QmNhoo+JYX/0jscOmxWNiL9Fl16UpwqBkpe1wYMxznT+P5O/UEvopnqBhY5Tytds+07nQ3NVLvghE0PxaWkn9kV9xng3myRkoQYegP9JhuA1wI5JBAbnTObQv+WF4cS/6ReopHLS5rGo/BejctOjw90xfFc72/N+PapdpnnS/jvaa/cnRuc7gQ2FHdxjqOQ8tkpYQRvB6fXfMK4i2jSx9nkZWhi0f8EpsHYcffbqaY2QSL1Xw3Qzt10/n6NQ2QqLKnfhI+8NYw9kjxgzMdpZVw//HyA98vKogUpuYCs7uWBJb1IPdyzvdtsu1+yM+XkDvytGZWXQYne0InCLlxxvfrDLqgzToDmqHDHjgSgR8aJW4jvgHNeDAVEjOWZ5FepwsYYCWhEzfgmMT6IddWukoD4x/ynfJFKuMNY5T0s+3grrxwkSbdTvYGqZdWbbLp+cuKrdT4k/oVItevJDVas9EdCAExjgF8wwk6/q7uAT+vhu1CwQtzj/Af6Yw6vMKF9zW3a7MV0IGdI0D53yfXQhj6+eGpYyZNWa5jddyNPqrEuFaKIzgbiFVvb2MClFlXW/odoVHgo4+KS++DtReJSqkBTDJh+01qlyL0KghmeX/PCMSKFvtXXq22LumDCtqvDjKTWmJo1rypP4pqqGBVX8MRSZaHfHHUCgvZnzBz/+ll9jCH6aXWrRH5cYx8leWddwJJgEfhIHaKDDxKMhILKjDoJXt4Tn/jlvaqKE+pdPOauYpTtyvmeu8PIlNqrvwrftj/bsIbnKkcz4OyHBnpsa79GCMByn8ZjZ6g8q/H4cxpsoMcLpvysiYyuI0UOULs8aErOdkqvPfoWwhCqKXnjwY6y4mt3pFAjZl6JXA72WtvdgiaR7r4fM9tJRQr7vd0KYIz3ca+6m5x/Nbx60d3ojlyLPdH1jWEm/w/3QPI293n3ciYwzI+MxHCnv6hTnIb4mJZVwrdqBfqiHudAhhEsTXm7cpDIphWw5CZBVlSj3nKl1yTRbr/0L6YrzbxpefBd83jG1PLirexfHvSYXx4FP85nM4GzhpWvGEAlyg/tS14qgFZR1DJeFwg6S/BiYuQtFa0sZWM7qSjs7oVXeqFPULwmhli8iaA4sDwHxqlcdXYMxjJ38o+CNp0LEdxfnkvmnd9foFkTnbUjbXXlJj4kgrRsQPw4vcAXq/hDUNuuym9TP2Z/HvVP5NtZpvA6s8kn X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 932e60ed-2554-4aab-f231-08d9522ab9e2 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jul 2021 00:49:31.1891 (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: ecQ8LhzKP+1sNsd1KsG2CXGuE7mqR0DmBAFyKyu0sFqxiNLY9imkRwn30UrJP4nt X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5160 Subject: [Intel-gfx] [PATCH v3 01/14] 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 , "Raj, Ashok" , Leon Romanovsky , 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()") Reviewed-by: Cornelia Huck Reviewed-by: Christoph Hellwig Signed-off-by: Jason Gunthorpe --- 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 29 00:49:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12407155 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 92A66C4320A for ; Thu, 29 Jul 2021 00:49:35 +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 4899760FD7 for ; Thu, 29 Jul 2021 00:49:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4899760FD7 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A3B8A6E50B; Thu, 29 Jul 2021 00:49:31 +0000 (UTC) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2088.outbound.protection.outlook.com [40.107.237.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5F6C96E05A; Thu, 29 Jul 2021 00:49:30 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NfSjX/KI7dAa2J/UMJXIGB/3HNnhPXImMbUGhkX6NkDyfcTcyr67YzWcNXXCqOQnjvDeud07HQtbZsBCxVgP5ucGzog66v0jx+Y2bxy+SRyTMLdJHJrAHG23NOU8cByrlSSYaGChQ5Kipf91p6YRKzMM7L44qohisXWe4d3oBL9gOkTdIVU6Z7n82AAyFj5yRqZSDAzTN5kuFFVjhEPrFr20FtGDy3Ez11Ej8Sb6fkAkvyGItTCwc13MvYLDkvAjRugVH4tmhhap2QuQapiXtxpPeJO8pKTzOrB3qZmK4Swft7S8g0daFLhPXXkSVmGFcvDK2i6Qp69thOJIBcP8Ow== 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=aU3f9OuiUdmchkw+GXAfx5H8S4/WIy0aiIG/duzDst8=; b=kb0iOsuJfZksmx81YlMLrUrMgVdUV/JTSSPu/aRSoLxBFVA0mqJLvqj0fjzh3NmsccEie8jdSv9yB2gRBGrOb0+EC+jrJnwzKLZ6ltjF+n0PvLONt6iRAtaqLdBCM5E8kjPLL1Qt73nlBl9nydU15nyl+/7XJvQws6CXjT1m36ujEy2Q4J18IAxoQH2InbyY9+MgQU3zymj9pD73WSOCFj/lvbRoD3XGtMByenfvTSeZ5h1GHBB197ZGff4M3ktMHtAHiu/yvDTpiwgUv6pd1nLtGMou1BSrELGCjsgMsxUPlDeiw4VFvNASzCKCbLM1W9WX9ERAIbtOpj30QirxOA== 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=aU3f9OuiUdmchkw+GXAfx5H8S4/WIy0aiIG/duzDst8=; b=W4QqdZicHJqfPJKiIYgq9d7QGVonp4FSPlcPvJDzQbib7d18Wbfl8m2+0dR54bXyMp8GaY1GwkiJ0Nm9+yYJirapx+Br+Y4lm+xc3WKvadh0NiLay5liD+7ynTjf7TETasQzfMlAtfpCYptIpnH/vsFDng3evsr8V1i5QG8uQsvhsadyM4+gp5+M5YjcvYb3PJe+rC5oyD7//ftyCa2LwXhlS/XsAZq/OFxdL0xydVXi+9o0S/6R86b9+3qPi+dMq91U6+kdoR5Dudd6f4NSHfX5ABu2Kq2/3mMqx4YmaXA7NGWLqZjWcpwF9iv5fpkzWR8fL5GXZyVJwXHnY50eyw== 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 BL1PR12MB5160.namprd12.prod.outlook.com (2603:10b6:208:311::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.20; Thu, 29 Jul 2021 00:49:26 +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.4373.019; Thu, 29 Jul 2021 00:49:26 +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 , Zhi Wang Date: Wed, 28 Jul 2021 21:49:11 -0300 Message-Id: <2-v3-6c9e19cc7d44+15613-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v3-6c9e19cc7d44+15613-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: YT1PR01CA0042.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2e::11) 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 YT1PR01CA0042.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.18 via Frontend Transport; Thu, 29 Jul 2021 00:49:25 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m8uEl-009pmj-PB; Wed, 28 Jul 2021 21:49:23 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6daf7576-f776-4ea4-3842-08d9522ab66f X-MS-TrafficTypeDiagnostic: BL1PR12MB5160: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YrqAnGt9HLPaQbUgU6RaZinRdr9SYUGnQeEYv1k+KyXb0z4L+Ov1qZVLMZ48+7/kgmNghGfbzz/joKA/xvUQrpYFev2LN0UxP7PF55WUvlMNVHc3E9b8+Xm7a9YDZRRJvgrov4j+hXyUQsmFVxvTPxKsdd3+2XWxBEItnjThPL6GdGdjEoogpfwWs5f4evfl3ZZnPnUHQJDFVB8gZf32G3CFCkCaEDK9VG89zVflmolZsKkwOMrFhByq70gszqut2dgKRw+UBz0/0zV7T1doweEsyRuSi8KatlBEf4+voTQre4RE/7rNb7mmi6oQE30OoJaT76OCJzfjT54va/iULxgPEjf5QAodtuRKsmiIEkjtYMDPtGRZ/iLGxK6sn/WtRowIqxmdmxPpF2Y7L3STQSsy0lfTI+EWTJEvaYO9QVS1LEjEvUM2LPnqi1FXuZq7GiSXj64zKpvEJ/1LKMTwEhX2FvseXvORUAIxHbZ6zQQhyCWxYTy3syRUuvbtv7ecPDQ38OrfjSD3FuThWDI95yyMIU5nBB+nOTfsrVn1XBpklcxAdKaGF/DZnqjt3JFuzIfSkk1CnQ436zk+QVDEAY3apICA/m/k3iUDVFVM54ZlGrXihHhNR4C7V6RUaKsYPbaD1cxadPKIAWfoU5xPT7Pwh9K4v0U1OZ80ljEdg+RxB0BalSW/rJwy9zncn29UCnNK/Ec7TulFcQQaVcKS5Q== 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)(396003)(376002)(366004)(39860400002)(346002)(8936002)(86362001)(2906002)(6666004)(426003)(921005)(8676002)(2616005)(5660300002)(316002)(186003)(7406005)(7416002)(54906003)(110136005)(26005)(66946007)(66556008)(66476007)(36756003)(9786002)(9746002)(4326008)(83380400001)(478600001)(38100700002)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: v6xLb1zWkrZZahMpFF+b5tdxUmMXBcrr9LJcP2iltY4O6/3FS3MFAr8CNJXN0s2s8G6K8oU/t8CaBdpbQGs5PiFVI8+K0JfCY5Wo5Ea20m2/LjYgrjseDAQ1qVoyKcUnTMHeioQE545XsY5rglUXPPTY3OShp1ihJqiJcTELaHQ0RRG/7CUv2tTCAVy6Kw+dFdW7hwDuo1x6xmJLyiIZfnQZzoEn4fosEO3VPyqvdqqnzD8ansRtZMF2glEwd/biHJA6dyCLJlTfyBfnHbhE7ZSuq4HPmtlCUhwbPCBrchSnpK2dJQ42jRK11h+jsSohDPgYJaDO/z/4ZaF9tXdRVF9gOlrTfPKRLEhmireAcIuJtvcRsIThIIF08GX9kldwuc0lF6jw9w55Ypkdm0KCIemjqdCZhGdAlvfKiKLBaOAg1vqIBG5Eg18iALXsRuS2qBq2Z5V/fGGrmfS6y4DeRtHCjJQQWNzL3FGr8OGZPXtxY7Fguo1RS18bF7RxRgmYVSUQpxVhAsEppdQ9Dl20WY0Yln9HNddACwYw5bfyNp1IRiyDcjjcLgC02km0DiOUjzf+8XwLDdgNHtwxHNMPSfnALTHs/gImZR8XDvdhDef7rff0UwLwsAoYBwvHN6SpmBv4UIhrJm6X+63sToSf29BKvcDUJiypYka/50NuSl0kmqLVO9RUBNP6l+YetpPn6MqpJlceVsOWgBpJSwH9B6Fw4B/KuwS4t+lKy3OocN+1EhUMbB1trknMhyD2Sio2W78NGkl9OmDuYb2vcmrcSm+OBd6amN2ewArQqDaann+vjse5MnYI2QmZoYmkvWdVVMFFSTV0BuqbGGpJZrJ5BahxbFZg6zuEhtq0pnry4HaKKNwxqa9dmDGWz5SXKjUXnTjw/m5Np4EqKZGGjw7l0lQjLcVgIStyuvvkHi5cfFMnCxOBRyRINLOe4vpktPUAuUCp2VvuJ+lq/bg1u+9nE7IZgNvR6+0p5Q8x+LjObhJXqGpnIOugDMaZFU8mvbbpXY5bPqquKkgirnKl3fKbhhCByC6QNaePJQa39eBzWRxC9TEjCl4YNKWETo9T7AfxfBKWfkNXvFGishqGyqcyv032G7Md20GeEJDBhRNAqvQltKQMLcUXcPHaX9DOgxLdueJ5XqzcfwjG4z2x1dF83nF7m6khG3D/DudFjPkOYkjNiRhxB80u2R8cwra20uVQwPkdm+sOvC8I0JSsUiI3ZOlRBdScEXPDomCYx/JXjXdY/i2XGEgoXmOo/Xdx6LcavXtECHEZH5lfjuaF9AtL38rBuLZ1MN3X9YYmZnuUvKU566utlhdaZORwB2bmWMOd X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6daf7576-f776-4ea4-3842-08d9522ab66f X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jul 2021 00:49:25.7659 (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: z/NvBt8GiacMZ+bXmcFSetcC7VmO4wOH73xFJTBgNeMV5IhNNQtLfomTamQoI5/k X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5160 Subject: [Intel-gfx] [PATCH v3 02/14] vfio/mbochs: Fix missing error unwind of mbochs_used_mbytes 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 , "Raj, Ashok" , Leon Romanovsky , Christoph Hellwig Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Convert mbochs to use an atomic scheme for this like mtty was changed into. The atomic fixes various race conditions with probing. Add the missing error unwind. Also add the missing kfree of mdev_state->pages. Fixes: 681c1615f891 ("vfio/mbochs: Convert to use vfio_register_group_dev()") Reported-by: Cornelia Huck Co-developed-by: Alex Williamson Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig --- samples/vfio-mdev/mbochs.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c index e81b875b4d87b4..a12b1fc94ed402 100644 --- a/samples/vfio-mdev/mbochs.c +++ b/samples/vfio-mdev/mbochs.c @@ -129,7 +129,7 @@ static dev_t mbochs_devt; static struct class *mbochs_class; static struct cdev mbochs_cdev; static struct device mbochs_dev; -static int mbochs_used_mbytes; +static atomic_t mbochs_avail_mbytes; static const struct vfio_device_ops mbochs_dev_ops; struct vfio_region_info_ext { @@ -507,18 +507,22 @@ static int mbochs_reset(struct mdev_state *mdev_state) static int mbochs_probe(struct mdev_device *mdev) { + int avail_mbytes = atomic_read(&mbochs_avail_mbytes); const struct mbochs_type *type = &mbochs_types[mdev_get_type_group_id(mdev)]; struct device *dev = mdev_dev(mdev); struct mdev_state *mdev_state; int ret = -ENOMEM; - if (type->mbytes + mbochs_used_mbytes > max_mbytes) - return -ENOMEM; + do { + if (avail_mbytes < type->mbytes) + return -ENOSPC; + } while (!atomic_try_cmpxchg(&mbochs_avail_mbytes, &avail_mbytes, + avail_mbytes - type->mbytes)); mdev_state = kzalloc(sizeof(struct mdev_state), GFP_KERNEL); if (mdev_state == NULL) - return -ENOMEM; + goto err_avail; vfio_init_group_dev(&mdev_state->vdev, &mdev->dev, &mbochs_dev_ops); mdev_state->vconfig = kzalloc(MBOCHS_CONFIG_SPACE_SIZE, GFP_KERNEL); @@ -549,17 +553,17 @@ static int mbochs_probe(struct mdev_device *mdev) mbochs_create_config_space(mdev_state); mbochs_reset(mdev_state); - mbochs_used_mbytes += type->mbytes; - ret = vfio_register_group_dev(&mdev_state->vdev); if (ret) goto err_mem; dev_set_drvdata(&mdev->dev, mdev_state); return 0; - err_mem: + kfree(mdev_state->pages); kfree(mdev_state->vconfig); kfree(mdev_state); +err_avail: + atomic_add(mdev_state->type->mbytes, &mbochs_avail_mbytes); return ret; } @@ -567,8 +571,8 @@ static void mbochs_remove(struct mdev_device *mdev) { struct mdev_state *mdev_state = dev_get_drvdata(&mdev->dev); - mbochs_used_mbytes -= mdev_state->type->mbytes; vfio_unregister_group_dev(&mdev_state->vdev); + atomic_add(mdev_state->type->mbytes, &mbochs_avail_mbytes); kfree(mdev_state->pages); kfree(mdev_state->vconfig); kfree(mdev_state); @@ -1351,7 +1355,7 @@ static ssize_t available_instances_show(struct mdev_type *mtype, { const struct mbochs_type *type = &mbochs_types[mtype_get_type_group_id(mtype)]; - int count = (max_mbytes - mbochs_used_mbytes) / type->mbytes; + int count = atomic_read(&mbochs_avail_mbytes) / type->mbytes; return sprintf(buf, "%d\n", count); } @@ -1433,6 +1437,8 @@ static int __init mbochs_dev_init(void) { int ret = 0; + atomic_set(&mbochs_avail_mbytes, max_mbytes); + ret = alloc_chrdev_region(&mbochs_devt, 0, MINORMASK + 1, MBOCHS_NAME); if (ret < 0) { pr_err("Error: failed to register mbochs_dev, err: %d\n", ret); From patchwork Thu Jul 29 00:49:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12407173 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 CEA35C4338F for ; Thu, 29 Jul 2021 00:50:02 +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 A14056101C for ; Thu, 29 Jul 2021 00:50:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A14056101C Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 697A96EB7E; Thu, 29 Jul 2021 00:49:36 +0000 (UTC) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2088.outbound.protection.outlook.com [40.107.237.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6C4C46EB7C; Thu, 29 Jul 2021 00:49:33 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NcCYRzJBjTc8kxnRXh62Zh1MwVxHpcJrUogl5WSXsrzOhctRgWshLGmjNlfBaGTfvPxgWYFxT3XBYwiiWoPAytCJMY07Tnz8HW+1Kjm0synehOKc1vSOlhJDVDjyUX0StuzxdLoTOodPBcE91uKd9xpt1SLzLg6vNDJTsUQ3pKS40snxblfefjTl5i+9wgP+120MAeXHlg7r6npSzA7J/gAcGQrUaONbmmz41uHI9usV0CgA1QMXl31/naX9XKYK0VtpE4cMzj1Tm3TfTyzm7adWyjKE8MBBbcStFGceOXNox0HehR0SI+8h95no8fU18NaMDQkaWm2QTU+jw/cUTw== 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=QnG8FlFwgYzjJDxn7oxiEkBysHBsP4Kal0iunyEcLtg=; b=Wft97wi0Y00mMG1OMqle+OCy/rAcxFanTdFaseV3QEobKAyVhWgcDV5AbMlA53PGCQ4kWOn5qRKDsYH0tLCIhrnp/PidGBRA/W29pakMPhs/1ODNDWEGRSMz7g8JsfKC/Y3UXcWihtT/WO/ZPB+UbzTJvuIOIDHCGJuX9qf9IphFGOQ3RB+0QjcW4unYTGh4fGzci3Qi+Sz+vI/z0z2KrSLEGC6gUayAtMnJJRKYV3N+R9YPBEjJm1od31NhsRyRvo0zOU1Ve2+bp8qwJS8mWyfucb49dEnMsEoJHbvaE9F/hhjyttUl+fZztuSKPTAbb6vreAtDZLauIxuIwKcL8Q== 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=QnG8FlFwgYzjJDxn7oxiEkBysHBsP4Kal0iunyEcLtg=; b=CA7fY7f79K1vyBuAkBCVkz0HVrk9hlbKw78bC7pyRcc7y4FPjvQG8ICCFKp2XCF4HG6PYK5AZNz1mEupXmFyfM6Om5WF6vi7m6WfI0TCCNSrDXHCx6tfnQX3VqnvQvSW279Fjqb+r3Pqq/2hF1tb+NH7nwFj9FUoYEIdtxVaPsGjpqupo4JJwPolFHVosGumQAgQZ8JTXgOUFADDmeoaepRQlTtOUMLP+OJyjsghWyt8Pf1RbulS1UBavPSDWfhtbkHRnZincgkW/P8nVUdhQltAbyRW+6uvFAmZMiOTQvDH6C2SGaZdXSPweL1IIEo14C1ccraRjADguFVJTsHlMw== 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 BL1PR12MB5160.namprd12.prod.outlook.com (2603:10b6:208:311::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.20; Thu, 29 Jul 2021 00:49:32 +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.4373.019; Thu, 29 Jul 2021 00:49:32 +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 , Zhi Wang Date: Wed, 28 Jul 2021 21:49:12 -0300 Message-Id: <3-v3-6c9e19cc7d44+15613-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v3-6c9e19cc7d44+15613-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: YTBPR01CA0031.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:14::44) 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 YTBPR01CA0031.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:14::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.17 via Frontend Transport; Thu, 29 Jul 2021 00:49:28 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m8uEl-009pmo-QH; Wed, 28 Jul 2021 21:49:23 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 457b601d-b9f2-49c8-d5a6-08d9522ab89d X-MS-TrafficTypeDiagnostic: BL1PR12MB5160: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1850; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZrN2HygifvXKGlxRjDDe3M6iGjNETHKMo9vBLPx2E6hziYLGvCHk433iTkiNpLNP2W2+83KRW5m17hgEgWrh1uTc9FP7MSz8eEQUj7x6iQanlMpPMct9VRUodQrZyGiPPE7ulldu1i0R+AYGni2+eIqe1sOYDBmcyEo1tBb2aqVwUQmH/5ZOfxnsGHeTxLYyNjTPzTOYGzyvRV0RzGSIOFa+uc8Umk5nD7zxyF3cZR8I76IRx9TQJogxJCUmIhCsTTccFDXH5I9a9sLBVFIYF8Kk1dKpyUycaZKcinSPIXRyij5SrfDHHjY8//hpZHHQfkocZJY807w7FygstIXupZwkTDDDenlNz2JXQZVtO/ZOgoUxuHOHaHb9upiCfJX3Zj6nfpoVDOqreM6VAsE4QTa2/u9H3QP7wCOQQgnCTiNLkq2+jgqzZz29jabms8M8M3bBvbJyH4c/KEYyPwMjCXy4pMEq06qpgXLI40lznBH3bbE9e49qfmcp13IPSkT//mnbss0E98Gli2HVYqBlfRweSCAcJixjxI4UY8ZVTJOcpNgufIZS9i6B2ON505vfgrv4E5J/J6ssXZwwtiQJJciapkqxOlQ5dC4/VyNUVWDBm/mr+QlGBv3dlA8PRAmjJPd4ELUFagN6yldoF53AbpVVqVdZd6JQctnWL2C5w0f8D8Grm0EUJ8xrVFMwqVhYL9+43NXyU4RYkeHXb49mkw== 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)(396003)(376002)(366004)(39860400002)(346002)(8936002)(86362001)(2906002)(6666004)(426003)(921005)(8676002)(2616005)(5660300002)(30864003)(316002)(186003)(7406005)(7416002)(54906003)(110136005)(26005)(66946007)(66556008)(66476007)(36756003)(9786002)(9746002)(4326008)(83380400001)(478600001)(38100700002)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Puba/Za30lNmOxNksFiCOzxomlM0ZgEh8sPbhklT7WtwiH/umDIlkbJQLwOz3U0rJVzkAKbRNr45plD+GNBvh32t/a6SdK3+g2Dka0Yu71iQrWxJ2YtcPprTksalI6oHscrZC42Q82ZgMmbOgVfWRmdnmzrZR7NgJnwvVqdbYa+s6bTTlojNvQqQOxKKfusXZcS1D/hUR766A8EwXXpCh57UOV2/7lTFGxSZgDpAoIKJTeWlqwgC3jR9HfgI+qWyPGRCJyN6tJE/MwXMJJL+E+OGoqB5031MA8fjt5+o+w8YXTXLK+2yvbBtZOS+mqgQ/KrysQpHU4mnGQiBN1C5W3HV5DmyG/f/fX5oNOL7RtuPBrOK6I7knd1AdUvCbDLZAE+ns6i2TQBotUtH3r0KwwjP2CoRTgJYwiG5IfpQETOiVnz/yivaxKhhFKPeWkUs6V6Fgu9T7RIhNlS+oaBmln5RR//hy0WVH+WhCr55mmvEgtypoJC1p0sZ19L5quagWxTqjOFiGHx0hCKADipPOtniPejvMkle5CNdT8ZigVtTv/DxV8xZiNkcTams6+wWNcrwNiDBGUOETe2gJ+vOPjMYBgmejiEWL00jzm/ygcLUsoTn221P61xvneudkiJKuWdnulembj+TbfiNOOVrAj4ZxA+Tz390JHugqQXFRC87PQL7hZpTOAsm7cAyiO9xlMO5U//ofAx1W13QuoRijb69JXWMcFO/D7O714jDivSLhft1wVASLWguXFWp72kyVPJd9I88uo2HSlq7XsVXzMwLAncgAqpJU0ielcAIUUbKRDxuVfZjb3RK8/blt01uaxYBFNEtcmNp+kdgtyrWtetebSyYicQuLVebjrKsabAnJYxJEeq4vITJIPvFKJCLr25CqmA82gYCvHB9KlG1AnXLgcus9B/oYHSzr/khlliotsS2QNztQjdOF0R72oaF1CtomWOD0pa72h+L8OJyKJyuPsvL1dFPqM1q1sHNaV01klJw+PQjNtqt3ilUUp2abmhS/vys+zmNSNM2dyeTHaoOSGxBg+p0Y8ljtNdCzQ5q+O+d0vLCTHcGIM8gLCBeIb5Mn53dhIUHsIQeaRghyRMCZPaWvpEf5TDqFZupOu21Mux42Vq94YWhVdTmu0opvtPNmubKuz/O1bM3Y5at2v3QAoAkNgPoO9fLsA3Jthehn9rU+1YNOUjZMJS3A+h+TYg486cjgLcS4jvh/O3Tyws0ACWDOFyv96ae1n81KWYbazSY2/j9AjQb7Kvk3at+9wBaskO5IQUi+qiuBK4o1aIjEsHSJTNerjYQQZIgFDJyE3d/XPUIZIKyh8xnttR/ X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 457b601d-b9f2-49c8-d5a6-08d9522ab89d X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jul 2021 00:49:29.3651 (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: v3whN+4DSw05HaCfuu/s2JvhWHrA8QG1xFVsXrT+2F+s2iH/nJff3NoByZnJkDUl X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5160 Subject: [Intel-gfx] [PATCH v3 03/14] 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 , "Raj, Ashok" , Leon Romanovsky , 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 Reviewed-by: Cornelia Huck Reviewed-by: Christoph Hellwig Signed-off-by: Jason Gunthorpe --- Documentation/driver-api/vfio.rst | 4 ++- drivers/vfio/fsl-mc/vfio_fsl_mc.c | 7 ++--- 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(+), 33 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..122997c61ba450 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); @@ -675,7 +676,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_fsl_mc_reflck_put(vdev->reflck); - + vfio_uninit_group_dev(&vdev->vdev); kfree(vdev); vfio_iommu_group_put(mc_dev->dev.iommu_group, dev); 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 a12b1fc94ed402..3d02e8e5964be7 100644 --- a/samples/vfio-mdev/mbochs.c +++ b/samples/vfio-mdev/mbochs.c @@ -559,6 +559,7 @@ static int mbochs_probe(struct mdev_device *mdev) dev_set_drvdata(&mdev->dev, mdev_state); return 0; err_mem: + vfio_uninit_group_dev(&mdev_state->vdev); kfree(mdev_state->pages); kfree(mdev_state->vconfig); kfree(mdev_state); @@ -572,6 +573,7 @@ static void mbochs_remove(struct mdev_device *mdev) struct mdev_state *mdev_state = dev_get_drvdata(&mdev->dev); vfio_unregister_group_dev(&mdev_state->vdev); + vfio_uninit_group_dev(&mdev_state->vdev); atomic_add(mdev_state->type->mbytes, &mbochs_avail_mbytes); kfree(mdev_state->pages); kfree(mdev_state->vconfig); 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 29 00:49:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12407167 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 A2938C432BE for ; Thu, 29 Jul 2021 00:49:59 +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 71E7C60FD7 for ; Thu, 29 Jul 2021 00:49:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 71E7C60FD7 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4B8446EB97; Thu, 29 Jul 2021 00:49:35 +0000 (UTC) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2088.outbound.protection.outlook.com [40.107.237.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 739186E05A; Thu, 29 Jul 2021 00:49:31 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=L0tq9aOSYwQyknreeBGNeEeE+J+LP8Nd8PMetY1x2ovuzfHspHM/G5ikORmFU7EHWsWavK7m7F8HzWowjJR7jsAX3eHXzF4OmzJOs+s++019YpdXBf/9CfEEcnJixkMbzAdOnB5Rspopu12nlW0l7t8iv7mmc+0M4Ym9XDCYxHPHcbtnWRAn7AWbLeO5ToI4RBSfyBfa6UAmeb7QPj+lFsh1OlVJyqxVY5u7eNil/IHma3sGPS97BBDtpf0E+DAiFaDKDkCc6o/DA4ErGf+19esnO0fmVtcaBoKkROUSVRS0rZj+r6yPMUMHRcPWaOQiqGsSRtYKfwAEymN3k9LDLQ== 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=moxLV+hVhBsqbz6EaZ4AyQsrmAqI9phoBFzkze1TquE=; b=LTkeVlp4X9maEFR/sGVbItMsx97LQR1H0CT9caXr4TQwG0fn9xvSUCnylNmZzZrCRal0vYZeULsv/V7Zh23G1BtIqdpkuo7YqbUMqZFBhYQYCfOeOneFiszOnrmRmH2AsAScCZZznFMD5qIMzuu3jM6DVwyGnsVzcru/981fcH/UBto/E+OF92sDx49JybCjTKcBMbn8bw2mIWeRZFStcI1m2ho+XBE99jtzDbSNvmkaXyMz7M8PGvp1g1UPSlGWVCjBwGeZjwE6ULnb5SWnPAPVYzc5qhJkVg5dd48FnO6BGWzNnXItQijjw9zhCEg71KFP4Pojp+JHQ+RNj0453Q== 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=moxLV+hVhBsqbz6EaZ4AyQsrmAqI9phoBFzkze1TquE=; b=nwW+VPmQlJPmTJ0h39vrBISlxgIv1axz6LntpL/suqv9ejeCppWAMrRniExqWCKxcd7m6+0OPuYrVV4h3YWxSfVYwKBzfeSJF8tZ0FS4azAC7axpuZjrSEosOXEYdtJo0Wpu/IAcp2GO1nmswT2FPxrhB1NnPKQkQ/Xq87sWSLVuMLA6SRueDG+ZzjgisjziaNx3e+fqUVqV8/MLg3VttLJBH2+bP9Adi7QTgRFXIWynJNMnHMg3tHAIPKakOQPPCDkkXMxF78bUtPDcJ/8yZjG6mX4dWHzddxQu5u2OxVWqAtjH37ZLf13tvqwzhf84T2cr15vcgStAV/GT9VY6Cw== 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 BL1PR12MB5160.namprd12.prod.outlook.com (2603:10b6:208:311::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.20; Thu, 29 Jul 2021 00:49:29 +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.4373.019; Thu, 29 Jul 2021 00:49:29 +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 , Zhi Wang Date: Wed, 28 Jul 2021 21:49:13 -0300 Message-Id: <4-v3-6c9e19cc7d44+15613-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v3-6c9e19cc7d44+15613-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: YT1PR01CA0049.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2e::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 YT1PR01CA0049.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2e::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.17 via Frontend Transport; Thu, 29 Jul 2021 00:49:26 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m8uEl-009pms-RW; Wed, 28 Jul 2021 21:49:23 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5946cbcd-be98-4579-bf06-08d9522ab74a X-MS-TrafficTypeDiagnostic: BL1PR12MB5160: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RQAGUyL0Wboy2Am4NYF0EgvyHeMVF2+Nn32Wljzt69QRpU7Ll4Ejf+1gFS1LpA3udu4drXrsTX3NAb7c7hwwA+7eNiD4IEWUVNdEjdTCDRzC7KgxVXHqgudG4V8CsRuuPAShyYhMjjOKaOZ5yQa85edikx3fzwS0mLxaV/YsWvij3PFGyIKLKIGdf36UHDwR2urmp6Hj7JwaR+5Ldg+os0Mr7fEkWfwqbrmMBbqIydg8KznfLcJhOAGOovrw+4ERRo/eoch2d+zrAaCtFSG8AUsXI93eKmKNpiWL+GwsFKOWSEZFLzztILQNefZSI/66/qkJGt13pek2WZ19r1PeJVWE9w6dXAoRF64TvNYJyLYxQJhVgBeiBaZiuo9WfPmIaYSHD4jKLGt9IVQP+nU1cOIp+jUdz0ZTUTsZQb/uHs8o8E4PnNXYurElArvG1mFrRa1dJfNSNeQWiSN6MS7qrnduTyxt3iiUu2IBmWyrgMgnPztfHz40EhucS+7dKXfvvmDCs64BuoOHkfilpUynh9kWbxCIcF7rXb6fQ4kSeeN0KV/JQTvHEJRobNq5tYgoT+M5fwN1cDg6/3uE8XsF2kNwKlkBoZQmMNJa71eW/+6x9PUZ2QUYaNUPojeWGsqgBdIqp9Ns5xwa5NmEKxnOHfTn09YoDCav4zDWEGuYw5Xv0JRj5i9CUqb+7Pp4Gf2NWHn2fjVWaQWhpTKQOU3PCLIWrQZUG8/z3Pl3YXRIsns= 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)(396003)(376002)(366004)(39860400002)(346002)(8936002)(86362001)(2906002)(6666004)(426003)(921005)(8676002)(2616005)(5660300002)(30864003)(316002)(186003)(7406005)(7416002)(54906003)(110136005)(26005)(66946007)(66556008)(66476007)(36756003)(9786002)(9746002)(4326008)(83380400001)(478600001)(38100700002)(4216001)(41533002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gmiO2LvmgOqfZTx33JYipEGw8Ynfgsd0JWuNELKsI42TVBOTVQ64fd3waE+hahabks+Vv5I82m0m1g8u0f2YPgWdiMFFP6IpLtAKkIcp9h1Cq2OWMnM1ZR40BgRB19rpdMIW8FEq8nZAeGFsfQhp4nyKNoRSNY+gkb16dUzQRTcI133PhBr8ckaIx8DZpEILDmSXqtEsSm6FD315l4hiHDvThvPopdMA1MyeGq4MyxLcT2mjMZP4gV174KNdp6m7jqgU20Myif0wIYOfuFQqNVsngYcPWyXhUkAUdqdsUU+OnFjwUCfSK4jUXqWtIx2vyiCvUT+plxbwbnpnoV35yeK+c+px1YGqkSoB90UTGcVY0tYJ12rJHUBLzH+8z0myRYSEji/qUm9FumyH7c9oy1a+ozNI0BeKXG6AbHvHlX76Kk6yLgehJBMYjFcJKNiFTiZ4M8g44szYMd7VNXsLrfcjmrL+gi/z678fzi4zqTFyNeUHdkjfu+S1zOL/q7cT3wP88qoWSGStFb2PIpJSTd3FPIrkqk0U7lPz9PevMAXKfMf7CdNHrp+2xkcM3je3WJgEeyKZw4Z2FT1eiRfMZkrpEcclg32PP8g3bL7AOf/VfRONGR8nwJ9xuufQvifO4BTfoBX0/nPHEjTxKjLPqRd0G6E1S1+UWRyBW5mfI9P1sfRbIZirUwSp0x/mf6ISlh4U30cw+dGZEYqejSkvedudpBWHWIqA/S4S+cPBcAXryT4wm9NdwmHbXmgV0nuSIZBJSQzL8gkzSokPM+5xEfWheUN/b+j0EA12u9EDmggAcbbwSqJHnPVG4gGGoQXobLE9ZSgbDJstqw8iqTKB+CGx1B3FTxFSAPS0Kudh5wZy4dzn6N6xVGzD6oNbfHumXdu0uRJST5dEIRXzSEv22Nw6Ft0snLFEEDPDqFgaXyDK+/Tyfx8nfbAlp4mmfwNKtWccNBHqFpypJLIih0WjfRdKRFFLRFqq7qZj1VQncbZOGI0qPzK3bFa3wBacGQFsLTy6IW5EUHCRCl8Rt0Fbc33JaPvVK9SFnEV3k75t11hOi4JVJnbfnsL39U8GQXXMwbr12H0lDU+dRd/VzV1AOSNJJHRXW9wcIurT6QqIa2lHqbUG5GdmWnk1FKghWSFJ/bEOjNcqg4jFCt6o1plKxwOgi548D2Nd8azytxrYCZI90bzOf2AQJUU8cYXc1piw9gyiabztzho9AWvHkhoDfPX0YulufKT9+YJhIxxa/8xJXQlC4GDavS8X82G+7oFBZ0c0w3o1qWUrHdJJMlo7gn/xAM13QfE+D8Ct6Zrqc7eDsWNj3CyKJOFyvLW1y3t6 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5946cbcd-be98-4579-bf06-08d9522ab74a X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jul 2021 00:49:26.9129 (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: 22hDJ8zxb7rbAQIJkI4alq7UY6Ye053yy/4oVkYFZ4ZUq4q5JGOBcZ1bMNmkHILm X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5160 Subject: [Intel-gfx] [PATCH v3 04/14] 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 , "Raj, Ashok" , Leon Romanovsky , 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 Reviewed-by: Cornelia Huck Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig --- drivers/vfio/mdev/vfio_mdev.c | 22 +++++ drivers/vfio/vfio.c | 149 +++++++++++++++++++++++++++++----- include/linux/mdev.h | 2 + include/linux/vfio.h | 21 +++++ 4 files changed, 172 insertions(+), 22 deletions(-) diff --git a/drivers/vfio/mdev/vfio_mdev.c b/drivers/vfio/mdev/vfio_mdev.c index a5c77ccb24f70a..725cd2fe675190 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 0; + + 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..9cc17768c42554 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -96,6 +96,79 @@ 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) +{ + unsigned long idx = (unsigned long)set_id; + struct vfio_device_set *new_dev_set; + 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 + */ + xa_lock(&vfio_device_set_xa); + dev_set = xa_load(&vfio_device_set_xa, idx); + if (dev_set) + goto found_get_ref; + xa_unlock(&vfio_device_set_xa); + + new_dev_set = kzalloc(sizeof(*new_dev_set), GFP_KERNEL); + if (!new_dev_set) + return -ENOMEM; + mutex_init(&new_dev_set->lock); + INIT_LIST_HEAD(&new_dev_set->device_list); + new_dev_set->set_id = set_id; + + xa_lock(&vfio_device_set_xa); + dev_set = __xa_cmpxchg(&vfio_device_set_xa, idx, NULL, new_dev_set, + GFP_KERNEL); + if (!dev_set) { + dev_set = new_dev_set; + goto found_get_ref; + } + + kfree(new_dev_set); + if (xa_is_err(dev_set)) { + xa_unlock(&vfio_device_set_xa); + return xa_err(dev_set); + } + +found_get_ref: + 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); + return 0; +} +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; + + mutex_lock(&dev_set->lock); + list_del(&device->dev_set_list); + mutex_unlock(&dev_set->lock); + + xa_lock(&vfio_device_set_xa); + 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 +824,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 +834,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 + * singleton 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 +1442,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 +1457,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 +1500,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 +1659,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 +2468,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..f0e6a72875e471 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -15,13 +15,28 @@ #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; + struct list_head device_list; + 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; + struct list_head dev_set_list; /* 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 +44,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 +60,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 +86,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 29 00:49:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12407165 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 1FE2BC43214 for ; Thu, 29 Jul 2021 00:49:59 +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 E2A736023B for ; Thu, 29 Jul 2021 00:49:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E2A736023B Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 855C46EB98; Thu, 29 Jul 2021 00:49:35 +0000 (UTC) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2088.outbound.protection.outlook.com [40.107.237.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4832E6E958; Thu, 29 Jul 2021 00:49:32 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Mzs0lswnUSSWHlnOCNeK0aokOeXO0vkutzlYoPoDEEyLc4xtDyvMcyMb2eTK2PK+6zkQ9aGl7WIZxzha7YK8SPm18Wfdp+9f8sdxvILmyc0e04yT/Bh8K26YqM6ZIrHjBjaBS/kYrTJ6s2Mub24wPA8RkQI8yk4iTE9gktBp/PVAKSw7aMkWYNPv5zu9vwPLsLeJ92pGDCeKXJqpM/B3F2LSXZNd1dhQZQ30MmFOYtESs2Wual20b+jtq0I5MApAtarVglW5GjYOf3zJh9NzwO8a8svL/6xim3DjRZE1LGGfpYGlIDXqJ6poCfPIVza0VruMiLWP/HsflJF/UOWfTQ== 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=QLGplyUOI1vk2Tp1MTRUFrLoOOCdoTKaDLTz1c2M8/Y=; b=nQxjOuR/QOpmhOLOMHmYTPcI6w1ljsEzA/bhyJquJYkGdJfZ7eqh7rUcyLD/K4xmKew2Quhhn3uNP0nIIOYeQF1Ff/o56wshjZOw93DSl5JwEt2rIY3E4B5hKVnyxSA6DgXCgrxuZ3l3vmcD+rYlRQHgUb8agaMOg7IqtXLsy7TCKWq8P7+nTHz+fG0A0Ugx7T3NtKENMkmmZPS04R4gDUE4c94oMAVUAGSwoEcuet7U1ddQF6Kdri7AlImy6k+8/0pt+68G/CN++gWsF6P7eXxIpuhxeE6HuywtVIvPnL2E4TS+lz26j1MUVBq4AisgVHpaYKPJzvwbBgHbqRm0eg== 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=QLGplyUOI1vk2Tp1MTRUFrLoOOCdoTKaDLTz1c2M8/Y=; b=CXQMT1E9EfkYDsB+0GR4j7ouhRac2xRsCelNh8qGNCXA7W2+Wqb0kJm+kUxmCwZXx4uZqd3w76H/IqOJtUw4ftB6Yt3yEIPtrJPjDGEumPthuIs5UyRrjSDUwvNRmcHLlIy50DdP5GkxaTywKYlLIIN8xEYb9zUT8fyF7B1WxHbYa2YBuYVxJUZzXwdupJNYqXg+EZQYboJ8RYYdw+5+ORrMlgTVfHgoTXbXlwkNB6dElkM2aqPZYq6YMIhzrHGyhuq+u9UvySNr9XnwB4eD27Dvnud6KC5IgnA+YwG9Ox+l5dA1qGen4IIV48b5TjQoTSPRD6E93GbVmDelsUP7HQ== 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 BL1PR12MB5160.namprd12.prod.outlook.com (2603:10b6:208:311::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.20; Thu, 29 Jul 2021 00:49:30 +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.4373.019; Thu, 29 Jul 2021 00:49:30 +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 , Zhi Wang Date: Wed, 28 Jul 2021 21:49:14 -0300 Message-Id: <5-v3-6c9e19cc7d44+15613-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v3-6c9e19cc7d44+15613-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: YTBPR01CA0032.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:14::45) 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 YTBPR01CA0032.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:14::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.18 via Frontend Transport; Thu, 29 Jul 2021 00:49:26 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m8uEl-009pmw-Tn; Wed, 28 Jul 2021 21:49:23 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 77d7006d-bfa4-4dda-e746-08d9522ab76e X-MS-TrafficTypeDiagnostic: BL1PR12MB5160: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:191; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: X/yAAkafMjquHIkzNjkCqu4BNTX9nIsC43q3OgaIjHBl77s7RrNdnEmLm8iCD3s3QoEutjYO2iys/wPyGwaCocIOvmXmP7zrvV3dPQYtYvMQYSAoyjiHB7iXcE02DI2jBltM8yBiAOL+diFtRk6L5BxSFFWLc79cMC9rpFNcmdk7wG8jnIRAHBoBx5PTy42GKx9zBRWMmo5q9iZbxJHTmNh4Kn4BU/OEhdvxk+TJ/ARTe+fBgN9tE/6/aZDd6L2sQj05rxBE9Mxp1PS31eLTi/P4YBgX8YWCteaAa9j1ekKERuru5PLuPJFDbc3ezpXC50MljCDF5mYVGBzayPJxfULY4OYnTKsXdcT2UmkABOADjp1G4tOo7jvwz5hLUymV41UpTXBFYmgDkgrW0ez/OBjIdCwScGQ77zp4CcLr7rA+/EEc8An+3pFm3sUCjjNOwirml3Vnf1Xkti/wcGwsUJoiT1JUTkb9Zxwu3Z5NDSl+S40UVlaFLQrJdRlsZGphvsV4xOefiXQNj4+auCpu5Qb0R2HgqUNs2ONaVw6kyAbeRxnij31lqjfyXShUt4wJcKfAgXeED/vEsKYBfwJj5ZcnPGkBTzqgIyhyYA8ANkPGlcObTAeTTY7v1L5KH4WNB/SHv+1N1bYMqRLUr4PFbIecSQLN8GlcnK4RaVbdg3CxUaEfn/IYgo3PuJ3lNf/gnazHhP7w4K3xFyAtCMHARA== 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)(396003)(376002)(366004)(39860400002)(346002)(8936002)(86362001)(2906002)(6666004)(426003)(921005)(8676002)(2616005)(5660300002)(316002)(186003)(7406005)(7416002)(54906003)(110136005)(26005)(66946007)(66556008)(66476007)(36756003)(9786002)(9746002)(4326008)(83380400001)(478600001)(38100700002)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Niw/49XD85Vd2jAK4nwyZFoSFx6kE77OV83pDESk8qwo3JoU9pHyDAsfQ152eTI8bRPL4HoUu2vbUrp/XI1jl6hEOeqbjXOmV4NDLwXh7P3Vdo6aKnCcF7eC/HITDQKlPJdL/z0Fqoww22dwtkAyCD0/8tlDpPbUSQ3gtAT0Aukkw/w+NGD+8LRsDVxLPbaAx785Vs8jf+evWLapGiyUWPM9K+tKXeXWBLEcTBVaB0EG0eV/VrZXY1o1DmPsjZHbgeZIrsn9h1sjc5w9JnNzq8hoZHuSi8bP4VdTK3uRzDOpUQp68a95+G5M3GwB0tVw+v9dMP2xaTAAl2Pact8+DwFDOOHDjU0JpMGAw3LmKCL59/xxv3CSQyaAqJIfqafFKb7CXZsKmQXxPS++wE3TejzKteqzqokOYdhwkcW/bBsnkgi3rRuN8YtskSRtPdfJaiPqxvX1xnexUijCKw50BdSwChFC5qzLavmnI+k3bGQD8b/EPt21w21bLWIkzP0DsfTcsERN9tC2ahIqGM1KHJ1OTwVMJs+6HeE18wwjKhN51EAoAeW2O1mRYya7okG0fXoeDBwCXjNfujDr7HYhzWlmx0WxexV4yPKOOjR/T/xPtFRxBr4WMaIVfAEkZnA4HmzQvzfTzAIIUQz0dj3FKGh9QWo/33Ni8JdCVpBfC7DCOIrvhPZZEb7zSYw5SIiBa3ALmWJCMa93lAb2w4mmyQ5z77XvdHPnDfjkzZLD8m9cSkFb325JOC6o6prBSs/ULYapzD4C0044w2FKurqSK8zFkZWZMlAkAx0X7SRmIWOtbZUzsxDSQoGzSeaPozpUlrkRjKY6Pk7dI2tpDjqoI+NaDigS0IrxtC76ATIbV6T0i3oGwecVxSOGE+9endju6DWYJSriD3E9te46tHC+dGuNPljpAuoU0gGZ/F0GU4suPO+JfuLwjnr8kWXRc0zfwQ+4e+t/x4Boc9DvKxDk4q/csmo3UTx/QMJG/5hnbtW1QalI4FpwnRtdkRQyy70WH0IS7bhKVD1zkhuFTg0a+yDRZKgdaB2fVV3yg3/XcaxsIkxY2LrL40+03sNOVdBf0IrsmVrLJYz47LlBytqe/8OH09GQ86YjowYBDaTCrhjM9WNZaoDPvmk46nwMqfpubYXyG3XOYT1tVuKObN6WLBHr6A5DmAx5T20pL+SgFU0pfPAciihDViLtuR0QT2hedMR5B5CiwfANjSH+SH60uAQRHiJmgv8UqWYyUSNASF7FyGkbXGj70b+4DDzGd31Mu7LTrgjrqwP2kaqtqE1ojad/sqafI4d6NEKiCFlVNRuHggx0OvE05MizBNC54BUc X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 77d7006d-bfa4-4dda-e746-08d9522ab76e X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jul 2021 00:49:27.2573 (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: vBdzmc3SL9J2hHm5obWEh3RbM6EODekJDJczeEmRcm9yKnhXsBsMmV9/Stfy6/fY X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5160 Subject: [Intel-gfx] [PATCH v3 05/14] 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 , "Raj, Ashok" , Leon Romanovsky , 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 Reviewed-by: Cornelia Huck Reviewed-by: Christoph Hellwig Signed-off-by: Jason Gunthorpe --- 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 3d02e8e5964be7..5ac65894fcd38c 100644 --- a/samples/vfio-mdev/mbochs.c +++ b/samples/vfio-mdev/mbochs.c @@ -1278,11 +1278,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 = @@ -1401,7 +1396,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 29 00:49:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12407181 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 510DCC4320E for ; Thu, 29 Jul 2021 00:50:14 +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 1AF3F6023B for ; Thu, 29 Jul 2021 00:50:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1AF3F6023B Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E07A06EC26; Thu, 29 Jul 2021 00:49:40 +0000 (UTC) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2088.outbound.protection.outlook.com [40.107.237.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 989B76EB7E; Thu, 29 Jul 2021 00:49:33 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nSKveLdfbBr0H+1m9xZVRMoXzDUdZMXvvSZhg14o1vKZnKy5s+hkqR3PWh6fULrB/FZxZPSVDEvG+XWncf1pWvred5nEsGQ51zawzaxyo4eX79UrHNr0jYk/BD0HGjISfKjYuhNPecybDE1Qrc/0t8Lzd2JRzItN1DMR6YIKMXtHNqUrjVi7hmhmXAioSrHFPir/OlU+5Q0Lczhf+K2rXvO80dJEjy5XJhmi9uqDKxTAEGRcKSweX0Ikysig6+YtmFtcwIRD/Lw3QNbXGVxcm872fPCpIxmceUSNGlb1kZNkWJB5AIQ01AVnue0V31DMUABObFFXqWddrgfhhkh3Ag== 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=mkfoAJ4xhECdssjZdObBWe1NiwTtUKJep2eYcqBo5UI=; b=ALu+IBXLlkL3B5KV6spTWARelJZqKIoa3J/8JtDpXuR/t0nJPqFMdOnOOZ0zmGli0i+4n86kppB1MidJR3nTUlNl4WCpOAs7fSfWGhWwCduAFEYGJveDQJWfe2RNUyHoceg5D12Fb3QiQDUM1J2qIoeZaB5qWGqaTqfNx7WiXj4svhFL6BhSTvTsiE2GmC1QiN1GCB84Jr+D2CTUfPAZVtxyJtt+xML4aIh0iw8mPPoMGkjtT46hIOlFGyntdnfbLRW31HtIXaDTIHf+lO5S/7uP2QldWabpTk3YJiVA3c5ZDLfGlHLyzmZBsjsBHQ5TQUpLf7HEt9HXmLUPkeOajA== 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=mkfoAJ4xhECdssjZdObBWe1NiwTtUKJep2eYcqBo5UI=; b=GOmNsQl0YIpzoBf4v5rJN0T8bqc9mOz7bYQaEnHvOuNpmOHRdPjkZukM/dQjNcOioo3zcSWKiNI/NmtjohVJ5wX1VcbyY4my7sXXIH04KQj1xFsOyj/Xu85MI7fFf94wNrFpK9Vw0JmROtC4hsJGw3TxiJcc4z+s2NKPYaTJqZjJkDg/nEFlb5VL6/KtkOcI4b/5KbTq2DQ9/beNWwuR2C8MZtCZV0xbqEN1VoswrgwSEXjjekOWDjxKw+xpAbcONvYDPxdqAyJxjnQFreVEVHY5AcQNkTO51fC9qMJvIe8sIrVH1ebszAbwxUbd5bE7OfbcT9AcvVyhlmCuSzIKXw== 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 BL1PR12MB5160.namprd12.prod.outlook.com (2603:10b6:208:311::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.20; Thu, 29 Jul 2021 00:49:32 +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.4373.019; Thu, 29 Jul 2021 00:49:32 +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 , Zhi Wang Date: Wed, 28 Jul 2021 21:49:15 -0300 Message-Id: <6-v3-6c9e19cc7d44+15613-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v3-6c9e19cc7d44+15613-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: YT1PR01CA0080.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2d::19) 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 YT1PR01CA0080.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2d::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.18 via Frontend Transport; Thu, 29 Jul 2021 00:49:29 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m8uEm-009pn1-0Z; Wed, 28 Jul 2021 21:49:24 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 778d2109-2b3e-4b27-7f9a-08d9522ab919 X-MS-TrafficTypeDiagnostic: BL1PR12MB5160: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3383; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ny+JkgMsYJj7UwyIuRujhIZsXrGep2YOgYUWJ7uF1Pn/jpSog3/mafTGQslH54CcC8NKWxjcyGJUjmW2PB4siuBNToz7C4bD5NozOMwQj4qnQIFnhlfNzfGCRflyJNEPsHTTy1ia+7/xB2KufEe3pd9F8nAGpAlBUNRyxwfbLyGouZrtbLk+EVUvkUXG4FisVvvxsqR8xPNWZdwy2tW30MotRVFGcvIUsl8AYjyxO/mzcCAf3viDLYegttH22O6mvn6u+Uh/wTnTRDfmiZEwYiIJVYTPGxJHjfzUW0FMR4ftUmkr24w6xqO52GPQvKpbNVJqfqr5PsyJuqQbhu82Jubm6diXErrTVUZLmM7mKQdtHRXDl7AukEElR48wUBxzKkjdZaDS8dUL+C4lRaK/t5gZEWnPMOxsbBg6h5dnseblzyfJmjibeBtfmAOJR1K+lmdWzuOYI+JOaXsfaXRPE+Gj13yTbMzLn4XdNY82NtEMHuwJYkf3cMb6SUDF/ItPpm9LnR0/jn3fSI6YQSWBzvu95n2F64WhIRx6REzMrI6taPGoa2DFMP9TPLtt1wLL8srRE4Gi5Zdl7l3m/xTkXU810W21q/zVUEZ3/wjAUy/q9yXHWiufY/eVMM6XUJCEk5FEvDqA9ytceiIYvPcxaXfmsxHY7BRSIzzbzpM94PI/6rSm44CANpH1BC3Jbtozr+hurU8HU41RkzPK29cM5A== 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)(396003)(376002)(366004)(39860400002)(346002)(8936002)(86362001)(2906002)(6666004)(426003)(921005)(8676002)(2616005)(5660300002)(316002)(186003)(7406005)(7416002)(54906003)(110136005)(26005)(66946007)(66556008)(66476007)(36756003)(9786002)(9746002)(4326008)(83380400001)(478600001)(38100700002)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: MwUYxrzyLDh5tczP/RoovqhHRnZ0TgYWVXLm01/etwWQlxPwDY4W7Ib7sz5Nagk2BWCQsQHNPoq6Gwhytk1ypg3tnc3cVPcA5jYSr7WtaASTcvcrPqtX7i3MxZu421B5qTvSaKKNa4P9HDPGx3Jzw5W96Ya9f0RIXsCmrL6/3tKd7VkYdS6ZWQWGYrSvmJDeojUuREOhoMSSpsvp2S3U6Vc45D/Mazf5ikezZw4XdG1aDSY2MRiJLOKkc0Ut3XLP127WWsawMQc4waRuZM7duDptfnvxW+OjHY57KkAXXeTEJmBzlSooYfCyK/NMSAIjqtGVF4+vztRKf4GsVk8nMd+wpVTSAWIVDrda2wFHYJr+e5mhRCIaD1sASa5iVbHpMe7QCb10VXR6m/qxXlfOg7HeRGX52NLpmfSgW+OpZ3bgJaLCJT2HhxzceFo8lSHj3bnnoDJ5CIlFd23Z8MIuYSgjteXDfH+V/Dgc3j9a8kVfhwMIUzzqxT997d19wVkr2T9SvOLQs63XznEHP3APSX2hjVOjr9Q3PRLnRkf6RJxT6HaiuqdlsPRXMYx+KJLfRxidHFoh0epKdc8r5UOYDOcKw5l4cEYIWLckMCGjldk6jBHXp/u6r7lKZ0PixqDY0fTYWidPX1M491Y0EhTLKA0zDYk5L9vd6z83Qb5O3TSM8n3tXAlnezX/GIOlnSb5xVnR0hQTTGtzy26WR8Fwwgg625Hu8+A/di3u4K0TG/ATjlAr5JjYH+vhw9r5RjhnVRTYv5Xy6thl+WUfralz9BkVuSzuAryYzVttmwVxG/SOAuIcU060vO5nzfES0tMPLIkOanJn+KPA7HVFmWBuyUdMU+0Xy/HBgiN6a59GoGoItm+zaFF1CZLIBsfQ5W5AR+JNSOMSZNPCrvD3aUg+Fa3uRXTON8cqqjHIJt8PCn18a2yNxWopaUs2m4SsI0JHV5PI/+Ga2OT8xvC7WM45ttnU52aSLA8ly6TLQRH+0Hqey0xAGnUEmTv6hy6/wsDtcjQ8y1MaF6HMRmeRAq0Ebi6KXzVtTUzceNlO5MN8+0CpHCchZF2eXtNHqWrLD48FNgt7dLoY6viv634cssK8rr541fWvFCQGRZylm80mT6PXq/oL3BQCDMizY8or467r+lIYcOtTopvT8LxDT8DrC8AuSneFu40d9hP1qNYCILM1s5fbH4Kt1ixQf/4Hfz0JNXSjnp3vQUZaSaFHRw1vislHFAlm2It5drz7pOzniPwqKqlVsnqhxN1sKyF+hAm7emTwo9zEDlKGoYVBBLuBu3xmZb9vIgIqvJg6QbFhnaP8zrhXZcx2VSmCBhf1uKDt X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 778d2109-2b3e-4b27-7f9a-08d9522ab919 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jul 2021 00:49:29.9615 (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: 1XzF93ii8zQnv3IBZgN6tgBVMOSTpw0CsIEnO2zihyNXx48ZzAnSDpzEsgR6y0l1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5160 Subject: [Intel-gfx] [PATCH v3 06/14] 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 , "Raj, Ashok" , Leon Romanovsky , 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. The dev_set lock is protecting the interrupts setup. The FSL MC devices are using MSIs and only the DPRC device is allocating the MSIs from the MSI domain. The other devices just take interrupts from a pool. The lock is protecting the access to this pool. Signed-off-by: Yishai Hadas Tested-by: Diana Craciun OSS Signed-off-by: Jason Gunthorpe --- drivers/vfio/fsl-mc/vfio_fsl_mc.c | 154 ++++------------------ drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c | 6 +- drivers/vfio/fsl-mc/vfio_fsl_mc_private.h | 7 - 3 files changed, 28 insertions(+), 139 deletions(-) diff --git a/drivers/vfio/fsl-mc/vfio_fsl_mc.c b/drivers/vfio/fsl-mc/vfio_fsl_mc.c index 122997c61ba450..0ead91bfa83867 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); - - 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); + 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 (ret) { - dev_warn(&mc_cont->dev, "VFIO_FLS_MC: reset device has failed (%d)\n", - ret); - WARN_ON(1); - } + if (WARN_ON(ret)) + dev_warn(&mc_cont->dev, + "VFIO_FLS_MC: reset device has failed (%d)\n", ret); - 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,16 @@ 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); + if (is_fsl_mc_bus_dprc(mc_dev)) + ret = vfio_assign_device_set(&vdev->vdev, &mc_dev->dev); + else + ret = vfio_assign_device_set(&vdev->vdev, 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 +543,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 +553,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); @@ -675,7 +571,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_fsl_mc_reflck_put(vdev->reflck); + vfio_uninit_group_dev(&vdev->vdev); 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 29 00:49:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12407161 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 F333FC4338F for ; Thu, 29 Jul 2021 00:49:48 +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 C135B6101C for ; Thu, 29 Jul 2021 00:49:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C135B6101C Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 98CAD6E9E0; Thu, 29 Jul 2021 00:49:32 +0000 (UTC) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2088.outbound.protection.outlook.com [40.107.237.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 19F646E05A; Thu, 29 Jul 2021 00:49:31 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=odFQ7aZSGFeGL/FwbiAtj3LuvHeie9CSNp4WGsb5OLdwh/fCLIo3lGgGC6zDjM87n7L+GFFPwjbA43Fsu8dbjWL6XXhBvee5g5tF93S2TLLlzslzlzKG91ukmsk8DcNHG3s02OhHtb/EvxYIeEvLPeVqTRxnNWzG8wIqzy124XYt1TjTDHVW1NcJNQ/dhsmjm9NV/PxcjIGgW/Hr8KVRsdbWk3EXb4eguOYwJR2G9OEHXfIoy8P3zyoS36JB1GTuGUc0ZaPfWfhb2M+Ac7m31sVQkeGMO23ehSEaFD4qUkVxzOgX+1NlkAtj/jF++Np/MoTD2o6jbfpKEiK3aPDqJQ== 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=hXyefBkktVmWek9EregEH8TYMRyjC/vbPCkBhyk9gFE=; b=CeOEo4R74WYOU2EkBa1jpsjEMupXei0JurY79yY7dbIee810Ad6QZ7DJcJExKRjNijLkq14ds2GUyx3cIC4Gz/PwyYU56cyToNGjG7dW3fumjQJn431H4J0mQro1lxwFQRCawaQzqT8J4i9GsRPdhVqp68Kwig9ejG+Eb9zPfhVdORNQhrpEYi2Ycr7HU8yDy/me1+6mvYBpYykX04Q8cM3dP0iVcLY4GIXX44+/XfR6UVF/OWXGtiYOKikirO33w1KVWxu7u4c/w+o6E/zAaKY/uaDjXUQIx4yE8Eibl1Na66ilH+u8f1L4eKyHomcGL3OfZ4CEkHeOreLPiGPHCQ== 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=hXyefBkktVmWek9EregEH8TYMRyjC/vbPCkBhyk9gFE=; b=icoxScaRPAoKwAta/WCDRRBPmnFRQymNtB4ibaAZQKCDKp5NJHkhMmhvnP6yaFrVMo4VVDJ3YPoi4xasR5IZAM0mU7/is724A5OqWD3oqDWym7OG7LQpFgOAhZ1gjHY99bfVPGy02tSvEJf8L7DzO4E4SqOkcjM9CJ0Bn8TDnWZgh6tX+JxxmVT22xNPqYMO4YKYhMlfdu98xqGwS9UaYog1KxPfcPj5Q+uaBlQwCimbd9qz4pMzNH6gX42qt7HHeN2qJhzKl9XAhniUfnU8YiWhyoK3G0q3SIjSFeSLNdVpQPiOJ0CS1jlDV96YJ/mU1wojBPbFEEQRJvQfKyqV1A== 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 BL1PR12MB5160.namprd12.prod.outlook.com (2603:10b6:208:311::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.20; Thu, 29 Jul 2021 00:49:28 +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.4373.019; Thu, 29 Jul 2021 00:49:28 +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 , Zhi Wang Date: Wed, 28 Jul 2021 21:49:16 -0300 Message-Id: <7-v3-6c9e19cc7d44+15613-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v3-6c9e19cc7d44+15613-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: YT2PR01CA0002.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:38::7) 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 YT2PR01CA0002.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:38::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.20 via Frontend Transport; Thu, 29 Jul 2021 00:49:26 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m8uEm-009pn4-2X; Wed, 28 Jul 2021 21:49:24 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b855d8cb-1847-475a-49a7-08d9522ab6e3 X-MS-TrafficTypeDiagnostic: BL1PR12MB5160: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:826; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1pRshqt0Qzoociw+7OGsVQD1+FA7DrRztrPsjlJbh9RS/zrnOue3uZZW7g/JSkg9dxJuCofeJN+z0zSaHKUrgnQlj1JFal7i3Akyg2y4KkrGaZE91hkHfb/M0Cjf5baaoedOE9WW3fxP9rLipdh5RwnXHmQp11MTYkGWb22nvnRCPaOGoLWUf9qryj5UGD0gOrk17X/Nw7237ixveH6nYCeYRiUolp/eKERU/8xSScng3RGKpDiNdw2HHvPajPaH6TU59FiuU2wsJjo2DiHFWLTRgm6HfWq35JBTEsqpmReD0HN/3cyL0ejA9Kxur1NZDzUSC0Uw5Y0j362/pEhCxP36iDG/Q6fU6qe2eTIrDMmZhxemzceYMa9uKtvFOZVfSreMFnEk6sJfczPIIzT1gSqicezBGeiJV6QfAzF2dF6YVptrS3EDyC08fSCd6nOVOvK2XSremmDkwRkRdkkKUGAPUh87FKiCASxfEOf3jSEThEYDufZkzJkA4aPo1sOBrnobqV+iq41agxeRdOF3vVWZzTJMaAUPNOqnOLMx3ikcp6VQ6M0B3Bg59GuSAWc+70IyYiFn3v9/4XwnRN556lykPZrOfxqaWPJePGPb930/lFasevUsvEMZ2m8T0y2Pxjsg/9Nyjr/wXUkLaPs64BNFm4pTBedRcDiaJDmq5R+jmTFcVeDkOVcPn6x3dAyXZyccNddkqCQlXDjLWBFvlA== 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)(396003)(376002)(366004)(39860400002)(346002)(8936002)(86362001)(2906002)(6666004)(426003)(921005)(8676002)(2616005)(5660300002)(316002)(186003)(7406005)(7416002)(54906003)(110136005)(26005)(66946007)(66556008)(66476007)(36756003)(9786002)(9746002)(4326008)(83380400001)(478600001)(38100700002)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: LZ+AzuBeSJm1LLDt40aJY+T3/l+MpAam7iGA/r1ebE/MJEJToZ4cAMo9wxZQBkDFBLREcDVrmiOMlyMROAUEVdVnKmBrhqJg7tLq7OZ0oDXjgKYZt8K8XalmUiZJEXZgHJ7Pq7pkwE+9idH1jULIGXf1RbFZOjqJ/Yg/95WPuGh+msnxHiQwxI19yRmi5MU/xMENkO1S7xHCYsrKmwAHA9K0YYij+gJiwJRRRfXDm55USu+k/+mpLZ+bWlpj9iUvBYZJbD8Al12alUyFj1NnY+sV14oYNapRMzI2KXHEyK44G29WTBDDlm76MQIYucYD/OTMRxn9mmde+N9kvVdaj3iNXr0GkVTeDiVu/NpVYMmMnfrhjrTWLBm7K81HqpM5aMVDY3UZKq6H57LagXXkR4xlOR3GEMKL2+3a9Pv8XgL/lZi6VcO4bhBWInW4DZh8tnau7LjDo13e2hl1n4QBBTMNQ2BpCOiAisvmI85G94BKrjvZkDwMpQYGHHt/52EXaI/8DVwEm6GE/yPLDnZctnKf9VGLRMWDYXmND6PfDh/sdNyo08cyygRDHTbsBOylJzPR29gqVeooKWQ+oxDfbx4M1Hp4EJyvI8LuVXu3JuFcA2ChYqirM4rpuLHrvfs338XA94/Y1tQNvvB2U2DICy0B44Chy4XXVG66lI6O/AF+JiacYbO8iTaVnl/shLmdGptN0yBa41Jv/sRAhab48XF+jDuelHqjPcdVPKNxcMkJIwLYRHx6HPI+m6LTMuHyEnjDv1jMI/n9Q/OhI7m6Uba+Nss6rpzTqD+4VgHhFzbi02EgmKsmoo0clwNlqKiH0QRskdHaEqAVhe+jvroAmSfAnRJJ4rC2HvnAM9LgXMVGI7St3TN18rgqoT4zaXdLHR0Yr/j+if9ne6JHtGeho04YOtQldMTjt/I5fW/AwO4vE2dxuQ+T63Iy+AYAbJWl4Y7wfVj9HQvGjwrUzLCx/NCsXOBSFerjePn2KSIWKn8+dL47QF7hZYIntitEB6T0k7asSSu6msBQD7e5o1GFaUaHzlKy296T4iYNDaz2w/KQR213IECI0pGgNHnlwvKpORTpuc0XjPdlaPkB7w0PFRyAka1AeR1fhMbVSylWl3Zl4/L0l7oOG62V/Tr4XZmSsBsOaaudJcx4heB90HXxb9AGdSjgxltnQnI4ognFIhXISbvZ3ub2Tqa8KqpIMLAWXenFiwinq9YvUl+w7QukMrv+YqKNkmxQ75egF1FLBfM1xuYK2A8oXxUfpMaf68sdCJTt1JX1H7xlKtCtEgD81oLk7bRGVvzKPLNwinp8pwj4pdEXnRqXTCSQbR8TeXxN X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b855d8cb-1847-475a-49a7-08d9522ab6e3 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jul 2021 00:49:26.1552 (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: daxolzDYc2BtU5xeJEHE5kUdoYL/+iYMt9y89EUTVjwbp+kwadWGrt1ztDx6Hajc X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5160 Subject: [Intel-gfx] [PATCH v3 07/14] 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 , "Raj, Ashok" , Leon Romanovsky , 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: Jason Gunthorpe Signed-off-by: Yishai Hadas Reviewed-by: Cornelia Huck Reviewed-by: Christoph Hellwig Reviewed-by: Eric Auger --- 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 29 00:49:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12407159 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 03441C43214 for ; Thu, 29 Jul 2021 00:49:48 +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 BD4D260FD7 for ; Thu, 29 Jul 2021 00:49:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BD4D260FD7 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 182766E92F; Thu, 29 Jul 2021 00:49:32 +0000 (UTC) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2088.outbound.protection.outlook.com [40.107.237.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id B743B6E05A; Thu, 29 Jul 2021 00:49:30 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UbkNp+jZyYUZPu7Uq/uz4uhTQfQ2vLwqgJiQ//7FBzg2BgzYMGsbQFyheVILYCjECR1yGgOwdn4tju/TwaTzHqCplHe2lWJKr5za27rX0FQtWlg48ejiy7BVRniJ+1nwEfdQyoHwXH/3oYulYxZJA2TZA2fwx/IOxfwRviSmx1NIyyGyQeajYNEW4oNmV4kpMYSSqHZeREWc9THh3x8e5lJGRIRMkT1x3Xt4l7qrlaXp3C7F/hP6ljfXHgHTvwYS1HbxpM4liPHOUQY2N8449PoT4ayOECV2xcqmJ4R/7pt8U5dFDMkePe1sIooY6tqIQ9HmrCWtmk/CACFfhRON/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qw8nAUP0+Ikl43727+nr4qkb3CkEauo5R6GR9ALm5yo=; b=cXXxBt5Xsa7ofCcWrRX3B0Z+iu0bLufaDhPx9cJlOTwVWZw9mGgNSrU/5d1oAjG8EERx8Wo7FuIe5jT816eMCg6oJ5XT5HfEJPBnJwwMrD/nVHYU+H5NgXYryUTmd0cDnUwadLNBbwyxlY9ZtWfpf6zwY0f3pkEYafhnpOG9MsPreCid+63obOAb3asgIDPo3r6PS3vbJIZOCvfzQDixwogz8UEFEKrPNnzksZKa6D9nk8wIwTnR+bVrNXXNJNQ9XCJgVrtVMOiENH9n+OSNp/vwm9LnU0ekXo62KADfNqeM6+/4ySy9//+V/Wwi7Zoun3HyHZOsaZkMRMWnPXj2mQ== 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=qw8nAUP0+Ikl43727+nr4qkb3CkEauo5R6GR9ALm5yo=; b=UrO9BlXqxq2rRxp5ny7d/AKPcFQuaq/3CVsNkslp1o9zFSw6p9u7FN9jjQlBQ4A3uBFcdTZ9B28114EtbY9i//sjHoPPn6f9NgK960A2zzAvZZS/5ylGRFd2/lQIif1d1C6nw5SnPYZ06Q36whXQhsN90w3zyZ509HOyyXFn5biRopdFt4K7rREnly6rF+KxdILi4gsjY6XHFl/r5u4wdskdPq+1kX0OQHP9t+XLvDsvXX8o2JfyqbV5+yZl0FXhdxYbmO9X1IrSbfXo98mHrNVE/5B4neQkShXguNFbmvP0qyd9GpftNV/EADU2m9KpgKu3BebfI7BCMmnvAcWsBQ== 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 BL1PR12MB5160.namprd12.prod.outlook.com (2603:10b6:208:311::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.20; Thu, 29 Jul 2021 00:49:26 +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.4373.019; Thu, 29 Jul 2021 00:49:26 +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 , Zhi Wang Date: Wed, 28 Jul 2021 21:49:17 -0300 Message-Id: <8-v3-6c9e19cc7d44+15613-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v3-6c9e19cc7d44+15613-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: YTBPR01CA0022.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:14::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 YTBPR01CA0022.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:14::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.18 via Frontend Transport; Thu, 29 Jul 2021 00:49:25 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m8uEm-009pn9-3d; Wed, 28 Jul 2021 21:49:24 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0a080787-6755-42dc-e3aa-08d9522ab664 X-MS-TrafficTypeDiagnostic: BL1PR12MB5160: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ay7e1fBiO9EB8V3wMjv334hWNnqKj1Qee5FYyP6n8yihiINwdu9VyK1Pd6vafopsQsbk+Epd7lueUSQy3qnoT6x5XOF+9L7zRxk3JkKmvOGrwWp5p2Cr+Ikd2sgfC9ZKHjuRERHEjjICuIN1ETouiSztu5jvHlsgo5Gg08rPUAxu6GA5GRvAmvy0Oh2wuxKKWwvvZtUnXimOlC/LJxDG67kd29fZkj2E6UrzwCSj64GNKwozPwrYrQsGKlOWpbnHJ5g6lo1Mn7w2RiVG1Jm41g7I1WQoQWhkkOY5BAPQvetykyXgmqyKsfcwj7v6gIO97Fm41YI6BqNH0EGlArj4Kqx5enyqIo4S/e/Oey4spfNB59b0x+GIJWdLHMmYEB/YAkTdep7i8pgGAS7BYwwQlRdg9AqNGiJ9zya5soidm6cQ0Lugp5Jpgv4/qVbqO3GwPleONwjJIdiTQWj4C18oTh7VfgzqIoLknAwM7DjNJ0JGpxcPhqCSC3oW6Lr9s+62hN0aVHbLtPZgGDxwRGzBwyUfhajhyrJGK8k4Sbl5tCJmf8FkCs7/tnowu8Et/xRnee4QFOsy9LmukiCQYyARafPPZPbp3xWMwLHemLUYuYkYC4PoMRTzQP88eS6kNalLFAMBC6y3SiyL+ba2QlxkMd9ChsxVAs4I+m26+2BjANz9olmW0xWK3HLDQWsIkKmKf7qf6c6G1THXie3+NJ8esg== 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)(396003)(376002)(366004)(39860400002)(346002)(8936002)(86362001)(2906002)(6666004)(426003)(921005)(8676002)(2616005)(5660300002)(316002)(186003)(7406005)(7416002)(54906003)(110136005)(26005)(66946007)(66556008)(66476007)(36756003)(9786002)(9746002)(4326008)(83380400001)(478600001)(38100700002)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gHo2h/eI1nmNL1a/4TY38JIFyTB8ZokJm8zSP8e9hIbOk8QTogt0tBVGYV9JlMUKfyJBOfDYKpwroa9qNj+dHPxej24ExxtsuPGpjYT9kt2A1Snkk6eO/yh7zU9EBydFffYuRJAXf5uh70+3b2BpajxUj31vu+Ex54NqNs/f4I0k6GJWZfAEL4VtMcuRrfGUgM1sibueOKpTRsSwRw8XxxZGCeowuDEEencpb4Tmzl+30b8HyJ/vp/Ji2brnhFH0GtDt6CaMP9pozEXuw3oK+U/kTQrdUId9F5U/3YZ4OBhRLRgmLCSMREiCxPDEuozvjKSEEvmifcqtC2BoUUHSbsSA0WmSO4rOzRb+E7JJ687LlKDYOeTVji28qhrUg7iepnkgDGHL2qPGtU+MYTjYtJ0kqHAlXgpUvbjIJFDPh/gEjIorAOnQWv1StMVqGiZfCMMpGAlTBkCZG92XE/1mZtQPEIGptXT/o/5ANkg96X2cZQsS5e9bNMT6IqNDVzSJub8MdAZDMdm7GYRzDbjsN55WW5twYWviCSYY0YBpMQgcu0j+i07K20XnL/orTOfzFTgUO1VjEZPb6HYEVp9nBwO9ah5JTukgVEmM7J9GTY/caxhOeV+khPGuc1nSRWgcCAf1cGsg6SnI7s+cKX2FS7HU1fKborSodj60qdtR/K040BBRgXrOkUXaprm3Z4GrvvOjXind4SvQ1/00ZFLXs4oO92c9X5L5sx2qfAwasR3285iKoZAkKvtlE9dZJQdplBca7CD/2Xt10CyyFopLqeL+A/ugzoiuc/Y+vRHv9zJlSk0jFkDvTTD2He0AVr6cYGvZemPQdwEULjL38RcDWmO0O8pjdmQ9mxu1LS7OwLYtlrMFSBGc4XSVsyKRSJUbMORSY2JHvYNfKiQHSeerIv0HzcqdfF2d8he5Pnt39WEtk88ucXLfLShhJWZ4EDolKpRHmcOGUYX5SfRZRnWSr1W3dJWriBgBW+sMzW5Mjf6H4Ne3QXoSZ4aVj+LERLvUpwDaWOLIcCuwoYkJd3Q6/P0ZUp/Sl3uZvZBkgB8+CaMCe9ANs7U2Hg5wNTtmiZnVkUCt0YVjJaDQsRh7N0twcNZa4AgeUqAY7WSlwV9J0mEO5YNuyJ9gXi+LLlsXQNm+pfL3fSNy/A1IEF+q3kl7qtijxO5+Dg0ZtYjQZ4M2IDoJdpCyBjI0LY721dOeT8oz0DwfVk489l/cx0WTuUloXjl9DlJxZOUcJYN72TtNpJ5j6s8JOJ5DId3sk1YMFgqv4tEsn5MmksI5uZdEwFYkarqrxxEzVu7xRfd7KSHXIcQRs3hUDn62jY+S0O0dKUJ1 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0a080787-6755-42dc-e3aa-08d9522ab664 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jul 2021 00:49:25.8057 (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: N7UoJMLqEriE+b54CVywNt4zYFNjmn3NpcFvB7nfiqQL49oP4o6gwWe1rsrJgGVA X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5160 Subject: [Intel-gfx] [PATCH v3 08/14] 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 , "Raj, Ashok" , Leon Romanovsky , 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 Reviewed-by: Christoph Hellwig Signed-off-by: Jason Gunthorpe --- drivers/vfio/pci/vfio_pci.c | 162 +++++++--------------------- drivers/vfio/pci/vfio_pci_private.h | 7 -- 2 files changed, 37 insertions(+), 132 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index fab3715d60d4ba..5d6db93d6c680f 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,23 @@ 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 { + /* + * If there is no slot reset support for this device, the whole + * bus needs to be grouped together to support bus-wide resets. + */ + 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 +2052,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 +2070,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 +2145,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 +2166,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 +2215,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 bbc56c857ef081..70414b6c904d89 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 29 00:49:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12407177 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 273F0C43214 for ; Thu, 29 Jul 2021 00:50: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 F1A3A6023B for ; Thu, 29 Jul 2021 00:50:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org F1A3A6023B Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C14836EADE; Thu, 29 Jul 2021 00:49:37 +0000 (UTC) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2088.outbound.protection.outlook.com [40.107.237.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9E3C56EADE; Thu, 29 Jul 2021 00:49:32 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BY/asJAmR6pnTSVl5pKcH9WFKzi+QkR/QMurOQrM53d1fLNA64647tcVRRkCzz4FuSpbibPZLxru7ii1vLPPvMw+VTXpifsOk0QLx4EC1YTgw/1FU+JXjNKj5FCxs1kihwrVnGxX8K7g4NWMkRl2nwtp7IAmIVIOLtJ18xyUJNqJAKjqbMwf1cxHChco8gsaT2OYFpblDe0cKclLPVwB8Wj+kU0UkZB/WfLx3UxAovidcEkBlImLlhw3gkR39ris67XdD3PVfJPDVRKYuokuDw6oLd4jx7+LFJYab1X/XMyRSFVlrvwO/3Wi3q1cQFLVkxAGn6OEirNVxTR01x4JWA== 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=hof/NsuNeyebx2fUUhqtI9xMZq/oRkFXXmKUGTupaXQ=; b=nM1hiXX/JYunVAOvUdqucS5Sul7rAh033Dw0L9RsfOAbxvVEsnCnoNFMNVcrvgP2k8+x98a5IYjz3cm01iNd4I9dyGJUzXsZiKpFW6rcUhHRPUqXOnPYs/gKwcgu2PJa/yeVpzGyEiHMySp7sU77woFm49In5/9hPDxDl8psHrCyoWbWJHalzjFgeOxWK9i3Ffdjn9BaVpl0U2q3ogtbYVYkiDso9nWgxlbWo1ugpHRMD2o6ZOsx1+G/5vuZRuEiMWc2nrOpGmBpw//+3+v8eIXqR/i565kfwZkC8Ev+KYzQJRgRFBAf9kphVCTqsiopS9X/bxm45Nm16s1kCFXlhg== 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=hof/NsuNeyebx2fUUhqtI9xMZq/oRkFXXmKUGTupaXQ=; b=Ad9b8xCV4Cr6+qOmthE+u8hGbtUuJZVBUROkdXtX7vq+2od+l0PiiKru2wktwBzS7t+xmoBntsNU2b7rYZ9gkQr5XZr6o29muZbV2D3bC8Zq66gCNue7xYkspIVmcuk9yYdtXTy4bWDC/T6AT56bWH49qqCFnCd+zyDwUwqCINjPPhn3RuRJU382uwnOEPQ2vVwxbMgOKQuQigrHd1Y1xgoDsde0LGtJVxqMCnnewXzS7tgLde1QkWNjt/8iG9ClzC9XWDquFr4adWtc67CdnLM/a9GrG7OFwV6nAgxSfYdjhOg3O8Gozc7MpO2OASUsazeNeMqm0p9mva0mKnm2cg== 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 BL1PR12MB5160.namprd12.prod.outlook.com (2603:10b6:208:311::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.20; Thu, 29 Jul 2021 00:49:30 +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.4373.019; Thu, 29 Jul 2021 00:49:30 +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 , Zhi Wang Date: Wed, 28 Jul 2021 21:49:18 -0300 Message-Id: <9-v3-6c9e19cc7d44+15613-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v3-6c9e19cc7d44+15613-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: YT1PR01CA0096.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2d::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 YT1PR01CA0096.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2d::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.18 via Frontend Transport; Thu, 29 Jul 2021 00:49:26 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m8uEm-009pnC-4l; Wed, 28 Jul 2021 21:49:24 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1667eef3-ef20-4efe-3eea-08d9522ab772 X-MS-TrafficTypeDiagnostic: BL1PR12MB5160: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZpuJTjegfs5IX8bUih07NUIzRYsXz+C+OQTovO8ar5gz03y69MNNEqII5QWkSnLmw6ppcUP9FiIOqB/tF8hjC3z5iCT85gKvreYmzVQnGoIRYxJyspOx2Zq2Qrin0PwIR4qlHoMaQK+6bnkny3+cGwOWwZd1L6TY7mbBlxxjdZXDPdXuiv8G8G32kQKoWvnjDtGWAs9qEJGTU0lf8heHCORqgPEXGIYEnmNRJtVVRYND1lVxBILQ4MgSmpj0AELUdmi90ZYeIaJ5IXUTGBqr6uvXUnNPq7dMc+74CbYS/rWvksbOHVMowrzQm4P0xpsghj8eqB3DVaGpwZc/0toihBrhul1VQxcnCFokWz2od8Zsw2irQMKXeXuxL1fM3LdH6e+Y+sQW9PfAtWPc+jenmD0AEpb2gtmO3GOF7KOOorRzfj1MchLocA4aobMm1+T019ndjpdl0VQuKtK+27vnQQc/pcPHK+r8f/NkeVy5qK7wx5Ux84JVs/vW8RLGu762PP+wfIiuKywL9HcBYpCJvnFRpuzMxYapEvY09TT091FVVEn6gnjibGRGeX2zvpuy8LyBNtZA6358amkj0Zfnp9186G3/cLGwt0Pg9dQS/NNQEvB/5NezNJQX6c+rCAisn0oT7CUoDuKQk/VEVhQr4WZwZNzIzDyOVCl1ACR1+9bwZ7srjBt/lhwtqjW969rypvt8Kxhxhe556LFiLmAQCA== 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)(396003)(376002)(366004)(39860400002)(346002)(8936002)(86362001)(2906002)(6666004)(426003)(921005)(8676002)(2616005)(5660300002)(316002)(186003)(7406005)(7416002)(54906003)(110136005)(26005)(66946007)(66556008)(66476007)(36756003)(9786002)(9746002)(4326008)(83380400001)(478600001)(38100700002)(4216001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rYJlyRsIMrrCsfv5TOJVcC9RtH2j1Sgf5v2LsKkLn7mFZAyWuvt+ly/PpyJULU8mGAT+BiI1RqEW00uF5vTa+kG8MSVPXROkm/rIvG2/FMBidDQsNsCoiuEqfwcdUYF0U/MvnAPDd8I4eLnzqCozONW3i5LVCQr2VsheK6djGn0xYZTyUBvLG8usU0VZylhURf3du1iLIabAmg2SAiX9Q9f2yin5dUQhDZKKTv+0HkzVB4qANY4pHkaJoJtBxbrbq0/udXOHkXtSFHWL+cmRcJTZmCzmybG7h0tk4CRp5faYG9+dFPisdjWbCXJUcIWP4I8VUw/1n4hqySI4WcvcnTgKn2pmNq3+McmgesrGZpuHUsO0qSIV1y9ILexKKd//108XFYic9/4Mh9XEeIloK+LcAuq11PtWkwLOvU3PHlODXFwGbT368sbYzi5OBiNbkR4BDOKwOGjTp4nac+Ah8SVakUWYQsi7RKR57p0iSCYJnnQ9DRrNQ7IBGzAAukHAMQXTat+9/diopyRHGFLxNp7q2ebWT2FB39jcf7VIunsmnNOLAMm6hbaD0To2iAAlKnERBPUJbwUqexFZr0YyTEgrB84TmB3YiVkt/WrMSC8DHcKbosK5tvUlmu76T6Lj2V2+pM7e12NCh0oKJzQZY2zC9dlLe05sSvA/BygUm2evWxGg0Sw0bhrDjNWX3Zz/raNFTMSBEVWsFqucjX0v4XrNXfdmWm6fj4tbNgGJlFKt8YRhqMfdLhVk8w2c65mdzLR7l5LHGZtcP4dmet+1S1/QqEHWOxWkkLtOfOju0/h3HfMhbFYGarMsJfie3I3QwN57ciePr9NLx7ocGuLXhtrRqoG0rgm4ZecLZm6vrJrgxs4UgS5WxCZMYZYk+8NBF3qfHe8HdZl1S6Co6g2fA/EXs0bcr9aNo+Qex5x4/Ss7lGuxaOFuujL6QM/sL27RQVBR19j+rc6v9WHKnsGE6HleNwnuf2rPMLX3MACXaqHoay7Tbxeq7H4KM2yb0wf82CYqCCmYgHCWZRHwHHgkoGDhezk07P/64JBsIpQGzsKUgLteBRTvyDPr9cY1s/UaIqPJP8IFdU7DujLpJw7y79pneoes4odMXJCH2M+sWXkggkMv9tCEc2E+ikYxnb4K1OthsFrYqR39cVTuw5k7/CwP4k2w2RY2N3eOnhOy2ZisNTQd6MgWnubgUcIoSkqikE1LjshG8rjRNOcOTsadBqAyf3Z9HqNVpDjmmkhMXJ+NXer74YveqGJsqditz7oJQeUlroLJJbxggkHfamB3TmSliY35f+0jHf/sglOfZqk4Zotoccv2BOGDgX1RC7IT X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1667eef3-ef20-4efe-3eea-08d9522ab772 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jul 2021 00:49:27.7362 (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: FhO98UsIWrlRKuHGLLt/Cj3A9FSaKeeiFR/fOZA5rXIHXMgwPrpwTMVs01cWCPGk X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5160 Subject: [Intel-gfx] [PATCH v3 09/14] 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 , "Raj, Ashok" , Leon Romanovsky , 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 Reviewed-by: Christoph Hellwig --- drivers/vfio/pci/vfio_pci.c | 148 +++++++++++++++--------------------- 1 file changed, 62 insertions(+), 86 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index 5d6db93d6c680f..a1ae9a83a38621 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); @@ -2145,7 +2148,7 @@ 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_try_zap_and_vma_lock_cb(struct pci_dev *pdev, void *data) { struct vfio_devices *devs = data; struct vfio_device *device; @@ -2165,8 +2168,11 @@ 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 (device->open_count) { + /* + * 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; } @@ -2175,112 +2181,82 @@ static int vfio_pci_get_unused_devs(struct pci_dev *pdev, void *data) return 0; } -static int vfio_pci_try_zap_and_vma_lock_cb(struct pci_dev *pdev, void *data) +static int vfio_pci_is_device_in_set(struct pci_dev *pdev, void *data) { - struct vfio_devices *devs = data; - struct vfio_device *device; - struct vfio_pci_device *vdev; + struct vfio_device_set *dev_set = data; + struct vfio_device *cur; - if (devs->cur_index == devs->max_index) - return -ENOSPC; + lockdep_assert_held(&dev_set->lock); - 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); + list_for_each_entry(cur, &dev_set->device_list, dev_set_list) + if (cur->dev == &pdev->dev) + return 0; + return -EBUSY; +} - /* - * 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; +/* + * vfio-core considers a group to be viable and will create a vfio_device even + * if some devices are bound to drivers like pci-stub or pcieport. Here we + * require all PCI devices to be inside our dev_set since that ensures they stay + * put and that every driver controlling the device can co-ordinate with the + * device reset. + */ +static struct pci_dev *vfio_pci_find_reset_target(struct vfio_pci_device *vdev) +{ + struct vfio_device_set *dev_set = vdev->vdev.dev_set; + struct vfio_pci_device *cur; + bool needs_reset = false; + + /* No VFIO device has an open device FD */ + list_for_each_entry(cur, &dev_set->device_list, vdev.dev_set_list) { + if (cur->vdev.open_count) + return NULL; + needs_reset |= cur->needs_reset; } + if (!needs_reset) + return NULL; - devs->devices[devs->cur_index++] = vdev; - return 0; + /* All PCI devices in the group to be reset need to be in our dev_set */ + if (vfio_pci_for_each_slot_or_bus( + vdev->pdev, vfio_pci_is_device_in_set, dev_set, + !pci_probe_reset_slot(vdev->pdev->slot))) + return NULL; + return cur->pdev; } /* * If a bus or slot reset is available for the provided device and: * - All of the devices affected by that bus or slot reset are unused - * (!refcnt) * - 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->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. - * - * 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 - * to be bound to vfio_pci since that's the only way we can be sure they - * stay put. + * Then attempt to perform that bus or slot reset. */ 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 pci_dev *to_reset; + struct vfio_pci_device *cur; + int ret; - if (vfio_pci_for_each_slot_or_bus(vdev->pdev, vfio_pci_count_devs, - &i, slot) || !i) - return; + lockdep_assert_held(&vdev->vdev.dev_set->lock); - devs.max_index = i; - devs.devices = kcalloc(i, sizeof(struct vfio_device *), GFP_KERNEL); - if (!devs.devices) + if (pci_probe_reset_slot(vdev->pdev->slot) && + pci_probe_reset_bus(vdev->pdev->bus)) return; - if (vfio_pci_for_each_slot_or_bus(vdev->pdev, - vfio_pci_get_unused_devs, - &devs, slot)) - goto put_devs; - - /* 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); - break; - } - } - -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; + to_reset = vfio_pci_find_reset_target(vdev); + if (!to_reset) + return; - if (tmp != vdev && !disable_idle_d3) - vfio_pci_set_power_state(tmp, PCI_D3hot); - } + ret = pci_reset_bus(to_reset); + if (ret) + return; - vfio_device_put(&tmp->vdev); + list_for_each_entry(cur, &dev_set->device_list, vdev.dev_set_list) { + cur->needs_reset = false; + if (cur->pdev != to_reset && !disable_idle_d3) + vfio_pci_set_power_state(cur, PCI_D3hot); } - - kfree(devs.devices); } static void __exit vfio_pci_cleanup(void) From patchwork Thu Jul 29 00:49:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12407179 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 AF06DC4338F for ; Thu, 29 Jul 2021 00:50: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 822146101C for ; Thu, 29 Jul 2021 00:50:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 822146101C Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E93776EC27; Thu, 29 Jul 2021 00:49:40 +0000 (UTC) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2088.outbound.protection.outlook.com [40.107.237.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3FF6B6EB73; Thu, 29 Jul 2021 00:49:33 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FNAP8z+A5YAU0L4xBazNCmhTPQEFDkaH207SbS88gregcNDTc3+nohA+DB1QW9/69gpIvenRb0QWl1Srw8/wHJ8vuQdkM3h8dvapUpS4LbzDnmswQ/A3zZs78G+SimsZubwzfwrZdBVaLSFgS57S8KxMJZPCtYGlahmJ1RQyaEyogqAftrSDdzSCs4uIa2Y667zfQwdIz1u63VH63e5ZU7UhQw81TU/Fyn6v8hL7KnBjhNw7Jeqg8BiHhv4paJToJDPhPcQehyP3wJNboIlnKowtxiHWNRAIWHRFL7yP/+NKUn6/HQNYNBbDgXLFDo3FL5ooeTQYHPMdyrldKvnxGw== 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=jnKVdAMo4luuZ0vWRuSfT4gwgfX35JVY5NN0eRmXXok=; b=aEY2yR/QKOb3Va/Gy4dEYT9KyghwpUz21fErpXvWuh3bAdkhdnYgBHnjuZ8tIoXbiRGP/B19Avo8Fv3RDevCRrU00uoGLRBQB1VUexsWVUZws05j4z35sG5TTWVFF6i7eF4GqbRhdDIOKFka2loqNrCQlwAPlyHC49JFfKH5XbhqDIVWyWXdvJmqjqntVh/3MqcOz7D4H+hbj2QiKNNN10gUyR1VqYJWbEvr8Y/WSRucf+6ST93EFxkBmyVtCZW2Eg1SccS+d+dh6Nk49wYtvYEbjVFbEyAbPfCLRTKI151xspKMbgZI/aUtkSWf7YBbVBZSoud7H/EIDFDCIBN5cg== 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=jnKVdAMo4luuZ0vWRuSfT4gwgfX35JVY5NN0eRmXXok=; b=IqxqYEPJY4zBa/jZiNUZarQftdsgAXQE54LGamLSBP0OJRtWzI3AbOOz1/eBrWT6wjkBR2FHxO8KRifa69Yzqsjk6K6Rb2iNSpphDocBjuXIxgLK6+C8DXypjrGNSJnqe9HcteoB4I7Cv7tWKvuesYYHjdWtKHtSs9AoIsG6FUyUJfnnBJOoxBXvUsg6w2U9roGRbmythiY1Wk2B/s/n3R//AjD10AjCaeJDHxYhcsgx1gClkI/ZdzBCdlVWAwrXbe9HI0RDZOrWSa9SfIn+iBgRc40edadRr9PTxsBWcMNFbif6n+jjE8DbfFm7hsxMRAsCcvf//M1GG6XFSwwLrQ== 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 BL1PR12MB5160.namprd12.prod.outlook.com (2603:10b6:208:311::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.20; Thu, 29 Jul 2021 00:49:31 +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.4373.019; Thu, 29 Jul 2021 00:49:31 +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 , Zhi Wang Date: Wed, 28 Jul 2021 21:49:19 -0300 Message-Id: <10-v3-6c9e19cc7d44+15613-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v3-6c9e19cc7d44+15613-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: YT2PR01CA0002.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:38::7) 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 YT2PR01CA0002.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:38::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.20 via Frontend Transport; Thu, 29 Jul 2021 00:49:28 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m8uEm-009pnG-5r; Wed, 28 Jul 2021 21:49:24 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f9804c77-df24-485c-7937-08d9522ab871 X-MS-TrafficTypeDiagnostic: BL1PR12MB5160: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oBRsgGUCo9FlvgIHoj+B7eNNBz4rIyLDcwlmp5dPmjFrHQpFXB1/wGrikhBrY3/nYZTuKkVS4eW5JXVETX/5UT2RhFKlmPkypNf4BiNhl3NQ4Xk6O4N5x2TpRm1gr0akh6gq7eNvp9jZzFUuGas5XkDZQd73NZ892H/zfrJRfURqDVy8gh2XDgH3oLGONUC9H2ocaRx5p+GVGbsTuNiLpaWX3Tshi28ccwAXaPyhYLLwNlG3MCUfAuVmZjbDv9+r35CG1ivIH9mYDN6qQFZfEIL5TNOXy8bY9nONYaxLqNuve9piZMJvV75hKmzi17xGpPN4H2Sajm9ga8jsxXsDakXhUNYeqpihDpo2k9AjqHj2MNSzgXRn51neXu6MNNY6Aw2sQBURVEmMqDcCz3jAub6LN0xd1nQtEpqp7KTtUMTMdDruSJb7lOkL9Ns36lgDOqxVjge5MNFMppnq6es6WFqPgGdO42u2wsa7JkSSyxXgmAEalxnF5/Vi2W7rJprXoFL4W3xltaGHPYgNTQi+RP7iOoYXUtFfl96IF2uPmkh6wAXYratiHcR2OhuAU+iQbYpHEkc4WsAjf4nnCthD3renXln+/w79+GH7l1eBtV/XlnMXvtNqvXWY+0nsjK1W2Ela+wDmRDlBxb72/PPlmQLNALN+ftvWiBkjDmXKZ5BW7ECEngFI5gAKlBTywsZ9 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)(396003)(376002)(366004)(39860400002)(346002)(8936002)(86362001)(2906002)(6666004)(426003)(921005)(8676002)(2616005)(5660300002)(316002)(186003)(7406005)(7416002)(54906003)(110136005)(26005)(66946007)(66556008)(66476007)(36756003)(9786002)(9746002)(4326008)(83380400001)(478600001)(38100700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: KLQ3b0vIgEBLg5xoGscVAlK3MRCSCyGyrQ5KBTQtLXfiHfFz6vNlQPRbxM2o2ydCZ6IbRoZPnSZw/qw6rChN51OWrSFPa8REsD7O+9tFbgK/VH3S5e1pJR+S8c3T+q4YD4Cb6qIw9swwLRztPIszs3LuDXeFBd/ldFCvXs/C61tid7YZZZfbKe4XxhMCsrekkY3DEu1D3j9xUJjGhO5UAbAiPAhK4f5qNLssOdQc2HKSNOR5zlaRKUOWPUFZcLtVbskmL5rsx/Uxy/bugLc9I2ODjWiBCnrvjkFONb0A1nSNJESoKF+I9hh3EjNo8+d6OMEeYEDl0q86SaE5pSax1QWMiJPidMru+cMWQvVqQtTg2SK2ifvYv684Ti1E02ZRWmxL9jiTi+V9Bh3LgHuYsZYWTSKatCw1fHy4UOGh+87m0vM9QlfgOaZHWrHBhtT/Qs0usN8D/a5RcnL8VnPsIDTVEybKk9hhJ1PmDlUtRF6o8ZyHMku8dQBmDQ+6JdpQKrdPQkYtpcSl5CznFVWl1/6gIoq3/DNGQytZvkZg6SZ/cPVeV8IhCAeBps3Kz/CyXGswR333sjmogq5IVspcjSblD+GQo4zfmUWMlKw1bGn3Cg31qz7qAEa8fXVeybqjDtiHypU2tKbWcrOlJZlqnA3C4FUQSU3n8Ud2EwHA5loEj9gaI+cys4YWTCigvkvojSnXAZZoOitnLWJO4KtGcPZmrwFVd2nX1JMegT/MZI+iQE4C4Gy3+VnI+/a4uu5hbIZm5ConP0BOnDW5e21JWYxFr9B0Nw0xJiMqWMbtGwTRwODGcdoihpKkBCpuxggpj+lLhx2A68aZZxpP8e6KU1gSy17+Wo8gFlG2UfxQLurEHNxTSRvoQTkfSn7wX4DRupqy9pL0n6XJMejwM7zZ0Ez1BpubK+4sRBaaxnMfMaXxestwFMmPyxvuSFRioWN3TnPV0sUjPnwZsG2lEWy7FWAYBR858GYauGAjRg5WC1UhcuVfEdPf/e/7fHqtP1IzwIqqsA4BZUYnvFW7YLPxg9EGHZ2/pDdEHnBXJq0uBXlUsWA9D/9sF/ikitloZilgyYiakBh5oBJA+iapUQgRY1dxNyWKd49hByGIR30XbWdAQ+hAmkW8LC7U5uqBVybT7SP+q6bqcQfBhGL91R1yYJNVYzV1vdfHCindtXcDe6ocaA84LT7xytxMW2BCUprnh4fvHPG/xaglRGrA8CSRjL6TqN59HH27/Pv0m2ZL7wvfB7mzejjv8j8bTCsqy3uDRdGkuoAigOP4X4nA7alw4fcY8lA2eMqCvJ3/GsD64VDDspbg3lOKsnPEDcSoy5sM X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f9804c77-df24-485c-7937-08d9522ab871 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jul 2021 00:49:29.0365 (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: EdF8VVo2lOcIMRdNPwROGCY4AaU2wqrgFDKxU4uAtXmw3BKg+kUXgiiLigUcIhB2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5160 Subject: [Intel-gfx] [PATCH v3 10/14] 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 , "Raj, Ashok" , Leon Romanovsky , 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(). Reviewed-off-by: Christoph Hellwig Signed-off-by: Jason Gunthorpe --- drivers/vfio/pci/vfio_pci.c | 215 +++++++++++++++--------------------- 1 file changed, 91 insertions(+), 124 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index a1ae9a83a38621..721dcc99aaa042 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; @@ -2148,37 +2062,15 @@ static struct pci_driver vfio_pci_driver = { .err_handler = &vfio_err_handlers, }; -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; - - if (devs->cur_index == devs->max_index) - return -ENOSPC; - - 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); + unsigned int i; - /* - * 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; - } - - devs->devices[devs->cur_index++] = vdev; - return 0; + for (i = 0; i < groups->count; i++) + if (groups->groups[i] == vdev->vdev.group) + return true; + return false; } static int vfio_pci_is_device_in_set(struct pci_dev *pdev, void *data) @@ -2194,6 +2086,81 @@ static int vfio_pci_is_device_in_set(struct pci_dev *pdev, void *data) return -EBUSY; } +/* + * 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; + struct vfio_pci_device *cur_vma; + struct vfio_pci_device *cur; + bool is_mem = true; + int ret; + + mutex_lock(&dev_set->lock); + cur_mem = list_first_entry(&dev_set->device_list, + struct vfio_pci_device, vdev.dev_set_list); + + /* All devices in the group to be reset need VFIO devices */ + if (vfio_pci_for_each_slot_or_bus( + vdev->pdev, vfio_pci_is_device_in_set, dev_set, + !pci_probe_reset_slot(vdev->pdev->slot))) { + ret = -EINVAL; + goto err_unlock; + } + + 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(cur_vma, true)) { + ret = -EBUSY; + goto err_undo; + } + } + cur_vma = NULL; + + 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); + } + cur_mem = NULL; + + ret = pci_reset_bus(vdev->pdev); + +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; +} + /* * vfio-core considers a group to be viable and will create a vfio_device even * if some devices are bound to drivers like pci-stub or pcieport. Here we From patchwork Thu Jul 29 00:49:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12407169 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 3683EC4320A for ; Thu, 29 Jul 2021 00:50:00 +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 0C5D260FD7 for ; Thu, 29 Jul 2021 00:50:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0C5D260FD7 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 078BD6EBA5; Thu, 29 Jul 2021 00:49:36 +0000 (UTC) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2088.outbound.protection.outlook.com [40.107.237.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 45BDF6E372; Thu, 29 Jul 2021 00:49:31 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B6ehoD2urzH9Fe0SmXqdIn9NNo9ubTLkPZF2hVdMeMcjwRSAAf4EFc4Jia+FXrEUte4T/BTDTr7a5quh5ntD3jYSTPkh726KQCNPy9sinZL09s1B297GsNKmiA6nlz4qQuzrnuDtEOYiQbcne0iP7+WkK4gNe6TQo/498x4LAfSy4P5auXS4mD4srlAPvwQ0L4eZvMKJusw5zsI6w5AvCqV52Blnvn6kvS+ACsn/JgPxcorIXxplgL3bfCd8o+fxglXBiiST+KJgOiW0HJsvNVGQhenOGO2nNA2AcukPr0jSAV3kDRv2E88yPcbqHvplP/kLbpTdC290Cij1ZkBQsQ== 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=PP68ToLBFJ0Dwz5i+qGvcWDPVJAQD4k+3KgPTgp0iKg=; b=cQKB9BcgZU7aKn2VdhrxEjN0lvC7oBQxunQcM0zqc+lT87CeOOmmxpgnndqEz+y0lm4rhJzqm2OcE8qC03biNGvLCiiBlttrJaZr6FQJtorodFVDyqaOVu8ckPq3iEcAibf/cDqgh9CB7vh+6eJRtIlKrSrHC7C9qk4ZWOAZTDEgqnIL7A11yVqVek2AKmqFij1AVBhranKx9BnZu4DtEkxpbWDUMFhe5oPZZ77DFjyJH/En+mkC+iFQS3xt9zbvfy8ZXDBRcbv8R0hcDw2donzcmfEMXcMLQbqEPPGQKjXZkJkzG4zFbncKUJMEULr8DNHs0a9eujeDj1zWB5CcZw== 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=PP68ToLBFJ0Dwz5i+qGvcWDPVJAQD4k+3KgPTgp0iKg=; b=urlQScjMPwawIE0Pbya/yw6sj0AvzRJ21Jhy0WrR13RdbgM1JnSFEm4qxhWWIz+3qrOjGrxS7NC7nIoWabV5DBDuO6kcovrxmBmQhOUFxr3/3kyQyHew31TfBZGGhqD5vy5/XcZWU0Z3dxtsumchljLdJQKDSvUEFfk/Z0CaDY1f23bMhTfNVpv3o2N0tTvriH0CRCymGAWZNZmAhlL1um/bHDREm6047VH9/CI2SPb5dPrAXXSeZDvWDmuSsFQUV6R1+tvtG7ScxjUrDldWgJ/RFMUHXspdTFn+xdBGJU196V6Xs3nBl6gZbDtgbO0oRw6ZKUppyUrsZLuHQiO6EA== 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 BL1PR12MB5160.namprd12.prod.outlook.com (2603:10b6:208:311::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.20; Thu, 29 Jul 2021 00:49:29 +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.4373.019; Thu, 29 Jul 2021 00:49:29 +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 , Zhi Wang Date: Wed, 28 Jul 2021 21:49:20 -0300 Message-Id: <11-v3-6c9e19cc7d44+15613-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v3-6c9e19cc7d44+15613-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: YT1PR01CA0047.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2e::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 YT1PR01CA0047.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.17 via Frontend Transport; Thu, 29 Jul 2021 00:49:26 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m8uEm-009pnK-73; Wed, 28 Jul 2021 21:49:24 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a59ebd85-90e5-4287-546f-08d9522ab6fe X-MS-TrafficTypeDiagnostic: BL1PR12MB5160: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2582; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BbdmGvh5VjxpuGrRZFclnlZrHjF+/+F7vnnvhQIjIautlCYAbssgtB06lxgAwnLoYMPtRrYlFyuL8ixOiG+MJ8kSYXUhkuzic/X9fzvtxAhvN4TS3w6luAY36ZamSlp/uDSEn3VaAmyDDEhftLyLthITI2ep8fNenhDdT1NUex0qcCsAed4MexV6oDk9wF4MueNIjSZirFG3QuJtrAuAX7hzTuXjxLL++4whR5vSJ1DcLnrM9rjG7iy70ypSf6rqHtkAuVWqnNn9Duwnh/PSQWZ7D65Pn966/oHYz3AaaIYTse24WCmUkAPqlZBrhVEdVn/eK5vmK75HEVlzxF8Bewfylx+PjJ/CgaK824rW+nY5/bdU9X3AEGT+YARYGq2GMVlDVTudDLZgQmKbGAJTqJUO+2na//86eb6QzZRzBm94LRxCvHaDSPOnTFTQnt0VH9snQ4jPgYdV8zg0+qUU+ziUXEFDD7eTyh6A2ujOjZmZszsDiL/VrSu6BoBZt9WfbEzbzK+U2moVAVnkZ52Uo3ZhbzqgggGrrOzgg3DLfRp+BHycPD0gqTXf0spOHvQsQ+6fXUH/a3yv9TfjzqFUOhUL6DPIop7WrzO/vozOkWwC9/Ar7YxRP0qB6etyZ9Skr6y+UTvbAAziRqrYKVb0+t3YNI7XVeQlySswWFMZk6JpytQVz4zydHLiVmlGZ/Tf 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)(396003)(376002)(366004)(39860400002)(346002)(8936002)(86362001)(2906002)(6666004)(426003)(921005)(8676002)(2616005)(5660300002)(316002)(186003)(7406005)(7416002)(54906003)(110136005)(26005)(66946007)(66556008)(66476007)(36756003)(9786002)(9746002)(4326008)(83380400001)(478600001)(38100700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PpvsYv1q9LL0zkFVsT/Hfx3NeAaM7t2xCtxMmB99tAI8FeFsYdy2ZrsGXQ2w25Xn1T/v2jD+CAn74BYF0Mnju8jon9skuRjwiE9beE3CDN20ibK1lVLAiA7sCesoNM2XoU3M6ShSjoKrQ1EQqf4tOvD5Gg1bRl4DFhaPIViqYEB6nyTFn1VZTb7AYLiEplnh88LPktZM0stJ8qPgk/Y4EqxKhBNyIRJwj5u8fqOQWN9w9EO/4+AQObk7rsP/+bhN8E5AtnOYBCzitKxeKKVfeLtaJv4Bba8oJPyNkKSJfb+oEQSslmkTWAuLKiS2Hf6s+HxV3jdFqrEOn89/CyCBmIqJqqM3aPz7CslYnFr/LbUwvdHkdSrQ7GnGEmkybNoGoeYgfTdSVUKAKrts+X3fIRTmLUj9BEuUwyT+BlNjupI4JLKvOi60+emIZ06XHqzBP7Ikr46k0bdpAZMn1iwpj8EuE9aybA3i8h8gTy5H5vpTSmCK7X9i/OLH2XfezQcYwwY1jbh/pBkNaBWde2q+H8vzewE3v5+xIIhGnxwVNkWDDahJwfavQaijkW7MLlmZnk55z66QmNfVgxtLIptUwrFkmwVq4tmZ82OGFoTKYIl9xHsFT7qxkAcknk4TI3WqKFTHO+rdaE33ebkEBVHvu42mn9leduflBjslaguK2E6AFYv6inxBczTsOFfMl12T/KZkzYQWFZgRz0xMWsbdlx6Q4/M/1jpcw+oFpdsoVri0Wf2GeldijuSKT1dLAzqRBMUcNy2JJ/APDLeuo24aKe4SXTdvnifvctb8iF8pYFiJe3OlNyWEh31YVR61mCCIm9S6Xd03KTZU5pMzChUFbyHgD7NViV6keaDZXaWgi5Vpu/VbnLOgiAOop+RCJrNTepa9O+xdj/3p3z9qL46y92CZEyPgfvbB565YFT62RcTMLXsVM5QJA5nkaxAgqXVaDwNi/MeChyzb0IPf6p5RJNRGxAX+m5oriCCkg2Q8uPcuGYFQihDi9sSysXvYMBy+6LgLa9tidtUkubx38aFiTJk8Q/BKzhNieVkYDNnTP01nh2NMIfbmsayBgpIVMfLuv6aUOzUpwQJ56elx2AkC1sNJ4zZol6jhmw+qyLDWE98vFxhwXN3MjtUcxmbbAdEE/83XZNyhrrk4AeWAfWdQp9JdOuWPjmW7heCpKCln2/XFE+kqziq6p9AOhIcg+Vk9UpgI9FLCAh25YPILuTl9qH1adcmhssrSAK/HupOAeVVz/AfhDxKbf8kU7DvR9UfQe7Z7nCKRDCfl1r6Ix/XSInKASDjb2mFzTmGfVI6xuSW5hRuucGaxG1GTMrpiO6DY X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: a59ebd85-90e5-4287-546f-08d9522ab6fe X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jul 2021 00:49:26.4190 (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: oWFv6sjjM2pZ3Y4wVa/LtLC8UWnwosCr0kr6s2HdBH+dxHO81rtZz07RgbPKJ0I2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5160 Subject: [Intel-gfx] [PATCH v3 11/14] 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 , "Raj, Ashok" , Leon Romanovsky , 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. Reviewed-by: Cornelia Huck Reviewed-by: Christoph Hellwig Signed-off-by: Jason Gunthorpe --- 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 5ac65894fcd38c..6974626ec1c5d0 100644 --- a/samples/vfio-mdev/mbochs.c +++ b/samples/vfio-mdev/mbochs.c @@ -1278,7 +1278,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); @@ -1396,7 +1396,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 29 00:49:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12407163 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 C323BC19F31 for ; Thu, 29 Jul 2021 00:49:51 +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 88CC36023B for ; Thu, 29 Jul 2021 00:49:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 88CC36023B Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id ED7666EB6F; Thu, 29 Jul 2021 00:49:32 +0000 (UTC) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2088.outbound.protection.outlook.com [40.107.237.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id E28A16E372; Thu, 29 Jul 2021 00:49:30 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lfP8Chrr0rYAGpHGbzMn2ismO5XNJSvpJ1mOfxZWUarfvztykWkamQ1xzf9Jg9R5FNcxGqB2Ob15ryps752N5Pa0CVhnRbqT3kJPUMV2KyxNI7jyTH627Qm1rYYJf2IZ3wg/KA3CZWT9ePj16sV2UNCEncmd972c+4xWUl/AXHZHtlTUkUOodEpy/nbNp9Fj6Ic2Um8aEdgRKkNSXIuDOR7+XbCCo66hVecnceGGh19ULOy283+hJlVIbYMs5EJQjjD0aXfNoAXzsSNyxniodl+pApkcLyAHSLCQeZBanzXUqETwpCIje0jKHBu08k4JXyCBBVcqtOSqvYFocHWc8Q== 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=IJK14RuN27yL4pbSykuBL3LBGOhHR4BSiLIrEDi331s=; b=KYeNc6E2zuLhJelVdJTCjsg2kciSohpEO2B1C2/b3hReuwerf3ieort6faPZGgkq1jTXeBdMwqXnE7Xq3+/zNhNdjyM2HjOxGGT2cRc71A9HOrJOyN+8K8uOMLogVBTh2niqjELt57dt3mduuVibslPRQseMSryHrf4wE8SVGDyTHWQub12xBdS7owC2WC7W97e8ZOXKO2ZcCYxPCr30uj9zQ+bEF4x9wVRzQspNy0m6qjCQhygP/FTVGZG8RQbqo4fZmH5RGewMew78Odr5wzAceaACs8rHZnjrgnuLWcngO1EBv3MNFIS9gXdCfLfwRg2WSa1e2XfORc8xgiFCLw== 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=IJK14RuN27yL4pbSykuBL3LBGOhHR4BSiLIrEDi331s=; b=O9YfBu6SCLgYmhsHstSXBo62pIHA03ioTNCVy+pcRkN6yWAUbVA2DThuCrwZUiDIqcI7vS5IQjYIsZ4wpZCk9IZ+VZ9JnlcIgJWvVrqaQbd9uxKXf3KKmqm59HYGNZqR0QBWQZK0qbcxfMElKPQBjs+HqiB0Y58ZI5mOKoxHCyyRjtb7J9/rJWpOfGjW51LAJKV7dZ1ijeqda0TVx1AF3nTeLlYVuGETb9ULg9978wEy2UtBhyNl67q6l4Ts0tF2JfOmFbCQ9YNY8Wbk4h3TFwdAp/rF/iiHSZzDyiCCWQxlb3Fmpiqa6hnDFf/CQK5rcSAxxh5UaiwjQ87l+v8LRg== 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 BL1PR12MB5160.namprd12.prod.outlook.com (2603:10b6:208:311::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.20; Thu, 29 Jul 2021 00:49:28 +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.4373.019; Thu, 29 Jul 2021 00:49:27 +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 , Zhi Wang Date: Wed, 28 Jul 2021 21:49:21 -0300 Message-Id: <12-v3-6c9e19cc7d44+15613-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v3-6c9e19cc7d44+15613-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: YT1PR01CA0050.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2e::19) 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 YT1PR01CA0050.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.21 via Frontend Transport; Thu, 29 Jul 2021 00:49:25 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m8uEm-009pnO-8h; Wed, 28 Jul 2021 21:49:24 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 14a8f922-7b81-4ae6-2254-08d9522ab6d7 X-MS-TrafficTypeDiagnostic: BL1PR12MB5160: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2089; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ODM7/097UCSDrOAUsa7QObsnWV9BCgjdED3aagGgSJKVEDtaOtczCu9pV4ZgTPxucCZUhs0JW607bqzrnXd21vvnhKX3azpOSD7px2iP5oioYBoQfa49QV7b+hjVo01A3IG1xN4wLAbe2qtzMbCMrN6/EDYjffuGFzVe/1hoqG/BeiE99MElzZahNEgV9Jf8dqg2tsETG/LbImp0nolqRBjSY4ogm9Zgj7kO3dXz6nc1xIFQJD4Db0fQmeCAVLm189M22f7JW9x1Me14Ns89Fm9erNmDJpjeeL9uUpi4zPP4r8OahiBcy+sS3PsjnIOw/omEypCDE5W1HrBC4Q69DmXeU5IIPoxN6Gvr5PQMFv6XrBGMQ4UDdbR4uz7+Qgrt+DdN6wOxMg82o8/99cSfZSbiIQ/muVYYVYTjVmO6jy5f7T78u5fAO+kMSP60SC1l/7+j10AlkgcQ98rOcAVI95khfJHrIOso0mQYxE2kOF6iTw5fpvV+DimgFRUfb5By/QRx3jXtVNYhyk4ncS08GRuR1hYj3PhcJc35GumTnoScOndau668gXx2FhMBF7q4+1MUkBsS0CKFQX679KzAs/AtRatrr7XCUZHEQMkg3wtmQiHWI2CGDfcCr8q2mGSOpdofrp3zv2fbQnmlUhdbPzLn04XeEJdASAfEVhRS4p4zNWBDZ15LRt3NMILpZ1hT 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)(396003)(376002)(366004)(39860400002)(346002)(8936002)(86362001)(2906002)(6666004)(426003)(921005)(8676002)(2616005)(5660300002)(316002)(186003)(7406005)(7416002)(54906003)(110136005)(26005)(66946007)(66556008)(66476007)(36756003)(9786002)(9746002)(4326008)(83380400001)(478600001)(38100700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: znWA2lDXKXYjJ4CfDpqtyiV9wH8Jg7gkc4rG1kQAAik9p2UHrUMQ8FS8wqfz/rsLTpgyEm7L3lkdSmHAK/dD0HjVHOoWyxuYuDoSJS8wxRdAgT1geaqJlMxi7t+8IydBkqPptAH5c8Re3RSCXOEPTG8UgGV9BkVOamb8GN8xXeNj7ZVNYTvetwQefth0FYu2aXys7BCF0yaeEW2ztDsg3z+YOalhJ+b2A3YqJOvwLYoyuqwavClzinJMKbXUQpBlExPOy9hA0t2Bt9Khdl0IOnfrcTghewA8lH44x5You58EJv+RMyn5TvnsC2gHu2K6HXcLR05ARpyQS2R1bvNfsqywa1HxKsWe2wg8Vn1Kcawu9vqpfMSBMpjWTV+b4FAqBzqh/MtxPKlQMO37LzoMRSmBoheLtnSQJ9iz6dC+DnyQn7MmYd7Hxbqhl8F/clClxloUFTqnLzuMHIGOGNmTiH4Z+nQMQURsOLSsKe2156r/qwgr5taSINfo0Tl/yd13QJOFT2rSNTBNLoy48HRj2MssiWdzV66VJnF0gfKaYYNjZrSVTJnvfJ2POzxD+NhWoET8gzdFhT86kPJoZ2/qaitEpkhXalLCrFMu7LvsPgLkFtyy4NJ0oTjiJiAcGCKPEm79jvXerr/0gh9nBIcelHcaW39ma2E6DFsdioue+NDAFfHCb5n/Pytk2pptzRjy2zPPzOsk9fGRPn2t078FsXvjVF+efCNLBpzF4wzZURpIryw8dFyW2xk1j2tAgAAjQv1GRfqoGrg+jRhKbRQCWqjygd+7+jO8i96/Krj8bA3EQhOm7gf2HTG5rGXESD68dL7tQjsCyNUAEA99qiisRA3TcxOvqX6C7rbNK89ixbsNGCzIr+kSc1RU/974VHvusyvE6oaePDF11Ukyw94D9qSnt3PHqM/VJ8BbDsu+5v2hoGzV4ht8h93LYrd34sRy9SpYoSSzAbxRs35swoXwusirFB+Wrdp58L5i6TKPJ4q1OeTS9IdppCgbsD6mDEJDuqrLfmORmAmTvyni7zivQl1svPPQiOkKucnOEkqVVmU22ISRjvnZP3aWooOlxfXChHvCL6dz9azwVwbeG0talh6JyMt4p0VwgN0QPEB3ZxXQ5z/Www49oGmyI8rJ8zHk7b1SmuUe5KE68aEuHcQvnAaGQlCiJO5J7GDoBrrbA71yTlqUwzsaKmH3snmUujWcQHaa4ZQxWtEbRckBl2axkoLC/8mz8lGXfi7rwzaVGeqZLxUrW6bH0Zudce4R01Td9FsRNhE2ttgamFsYaHjaCYpKRQdbPZYDugazZ6svhY+dqRRF08344lrnqSlJMbEa X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 14a8f922-7b81-4ae6-2254-08d9522ab6d7 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jul 2021 00:49:26.0974 (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: HNG50LT0+rV2WamKAwS7Hq6huuDeZFKAVKuIPq1NdsNB4hWJ4UuXydecqEbFncwg X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5160 Subject: [Intel-gfx] [PATCH v3 12/14] 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 , "Raj, Ashok" , Leon Romanovsky , 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. Reviewed-by: Cornelia Huck Signed-off-by: Jason Gunthorpe --- 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 29 00:49:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12407171 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 C19C4C4320E for ; Thu, 29 Jul 2021 00:50:00 +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 931226023B for ; Thu, 29 Jul 2021 00:50:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 931226023B Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F21BE6EB72; Thu, 29 Jul 2021 00:49:35 +0000 (UTC) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2088.outbound.protection.outlook.com [40.107.237.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id DD0036E05A; Thu, 29 Jul 2021 00:49:32 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZLZSPOfXy3e9euEYni264fo2gw4nKSAA1Btl+37nSWnab/R7JyCP2e+zkYaPK2ZwpQAo29u1YKA2uWM1agYD0OkyK6LyykTVQYw1CY4J3qf+LpP9X19GDkZGXAHu5egBLJTrhGiSYC9y0QCrLboEWsc/DoPw8DtWWeKyR4UrRukIPm/beswg/lQ3HwXPLAyZhPu5MczrQU3Kbha/0K6SST6nieEpYTgTaykAumReqaMQ++Gl+5mGmy3vQyouPn9pgnTgT75mfp9OdBk/vBd2nwieBZ96M441FGznqaKj8xYTSY6y84D3svOLcsx0IaXf+eUIuSNY0xVXXvKtgZ+XdA== 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=AI0XRF8Cv8avivL91HbbxQabsbkHnmTi2xgNxzpks+I=; b=K7QEHogZv6RxrLL2A2rp01F3VcvRzLE1CFoFxLRJwhR8OBA+KRx9SJvPTz0ISfGDKziVEa4Vxa/Ms4XxpZReh5NOghuRVJDw+7ucdE417onHOhVgLyF6rTzz8wYcnWpQbHXepADUTdRXHlbZqTE2JyaROR5EsQiuoIikK6blDyxxNGUEIqWCpRIlJ8/cwxCkWeCkQzgL4er8LVxF+fjN/RQRa8N1xnB6TaDL7tqNMD22C3phRSpCJjbLhN9rBPD/6yk3kIlnIo6gqqd6VgHeDsz8/cq0OQhYatb6SyKog/e3M3AIfuK1XcVnADvsnl6M7zuvp/+yOwhwKAsT+TqNGw== 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=AI0XRF8Cv8avivL91HbbxQabsbkHnmTi2xgNxzpks+I=; b=Ph/r5Ok20CfveIwBZn/KAVqO1y03ULTySTJObgbLwIVzz/6YZMiG7nYctbtnfvATIOU+LDNKbomeoNae+G7Xz8M3wZs3WTlA1YYKBblP9p5HBgCP+nxdx8vxWNLIeXwdZ8wJONlDH3hUi2I8Yc7XBjRLylJdKn74Sl8XWtT982ogyUgdFWBCxmunA3oFhUURXkSq8+aZpx2EfIy/mf/A4ijyi+99ov8UMWxj50P7npeHoEqi/Ee6T7EgzJx9YFklytzHajSpgOA9Fur6m0YIqAzmmuVJkatZyBXppHB1LQDLP8ivqtzz5caLPMN/zbrwjFJy/l+B0SiYSROIihHbBw== 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 BL1PR12MB5160.namprd12.prod.outlook.com (2603:10b6:208:311::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.20; Thu, 29 Jul 2021 00:49:30 +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.4373.019; Thu, 29 Jul 2021 00:49:30 +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 , Zhi Wang Date: Wed, 28 Jul 2021 21:49:22 -0300 Message-Id: <13-v3-6c9e19cc7d44+15613-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v3-6c9e19cc7d44+15613-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: YTBPR01CA0009.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:14::22) 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 YTBPR01CA0009.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:14::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.17 via Frontend Transport; Thu, 29 Jul 2021 00:49:27 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m8uEm-009pnS-9n; Wed, 28 Jul 2021 21:49:24 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 04aa47a6-e6ea-4ac5-bcf1-08d9522ab813 X-MS-TrafficTypeDiagnostic: BL1PR12MB5160: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:608; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ummYtC6ipRe8JlezFNAweQDU/xHhg48fjZpv3CBrSDHvrlgEx7VIw6cMfQD0XdvnUaNq0iL4PNfTC9L5wyu8Gl7HwcdhmJzkNcyBsI9kIHfEzN+EI5kL2Nqfr27GwWUZENinemwgrwqiwfxo379AE+u03AbCA/Bn4YlFqmxt23Gw7uSzMUr4WsEfTVvaJh3X9maMJzmE2ra3b1XQO2x5EFhgatbSS7WUH4eA2i5Zc/sIPbFBpAGGVRfeOOcwbXYoftc9PdMg2QaFGMZ31qQhNQ7F2l3pr5TwKeYKrlpe4miLz2rrYE6REkFEuwCz4K7z7Jmd7p4EznF7m674hb2ipH6/qVZSj6HzSquQV3K82H4Ner86wpiCJ8WFaJXDhg4Q53YOvJ841F0+nLRp6ILeaszGzdj35BwfAYJCjLn9pHf6JZYVKOVIl7+qEeSLc1fMwLaBcr0Nxp+8EjM73J3OTxzTw/3GeNUiQ5Dcvla4PlK8pWvUazKLDTKWByMlVT6uHRVADwUb4jyEL/Z2VcKPdyT5aQ0l0pjIofwt7sCzPRUg2W44T+bnLu3ue7rr+F5pKxoQYijIxlH35ysNeGMMHcKuLxukaZuQhpwPnvHtRg0q5lmAkbMbY8VkHCzvxXoR7n/oFcgJamAZagywN8NVg7jkA16arJl7PrLiV5giNL81aUxEOYO7ITzEUbHkOMC9 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)(396003)(376002)(366004)(39860400002)(346002)(8936002)(86362001)(2906002)(426003)(921005)(8676002)(2616005)(5660300002)(316002)(186003)(7406005)(7416002)(54906003)(110136005)(26005)(66946007)(66556008)(66476007)(36756003)(9786002)(9746002)(4326008)(83380400001)(478600001)(38100700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bNRYMqCQUqnaccg9y7B4gWKGPCCfnF3mIhkCqtlZDFnfxtOJr7PTrXX0i/76UJUjDXnO7WtXnJI0nIzQcYu/cggdiV5IklLfQYJqJUMYdfarmnYt+Vrudy2As/pUyzCSrPAQgZGT2Bx3OyjzNLXtd1i9DLND6l48iSSddZM5EwCY6jPHPj/ROfSWrlT0eanLpBscV4YrFFlsVfFug5fB0xgLyWouzFzIAWMXFq+/oNh/Qm62VXsgmNwwk+JCL18pqlURi2kMToIoqEWWfjvmQVZf70m1OqLezM2WszquUabChY+N7rVwPPa2F4FrgRBdS3oRqnOJfeLM71g88uYe4oWlFLv7XAzRX445JCu0EJBSBACEuK66savKNZ6EEIyTd20UBC7L0gElHqhJauMnTUokxdhZ8CGgGQMuGLVJHHpe3/JJgP6TWJjRh/P/QIalIGKMj9zp4TwfaiZppzWf/m3rYqo8SDvSRj9mjSONTlnQ+Gw08KO6lEgKiLyQNF6gsYgpESg4XKE2596hS4cSUJbUAqSvD5+qd+OWq3+WhCOCjg/2cksxlBWwX0Q/hagkNeTME1qdUFp1r7GULzjpwel0jSZZV7JvyAyYH0+8bJvlmbDbw025eJGh+Gfj00i5TFO+G76gcH21wwuqjzzg805HgyWjBzDsuT7asU+LwamX7JBP//4CbodTyBDxXjA+CN14uSVi1v1j2+fg1CDMdDPxegaEuPoDUPvjFz/5H81Mfn+ChcIodC82sa5B4fWb765pdTlxR8VXjy6qlr78z2905PX3s1kdm8rfi+VO2W26CAKkagzU2Y9iu0Pgq3Mc+RnLcugxtFQ6X/+Q/Wi7OyJJZAeZW2pD57G4FFu0ZnsnAa8lt4NAakacrx+Olq1NoBlh1UgkZPkPcaocECxUjsja8ew30Le88Vbp8kzaHAJtDP0FDYs7mWw3qhD29jlif9K8cTGwp/Gn18HThiHLHi39mq4j1TmzLNkLAj0L1NrpGLoYVVg3beLz3iW9YAhqQmnXJpyjJSzfdGRQnM1YtVmGtF3yxCeXm1vkogwk29BPGT0xFF6/EUAoD+NYiVR1EEIBVXRxbIvgVZ6oj5n0mAkEe55tpXRmmZ3x63GbW0PAPsk6WhBuTiA5g3JpgdvZvKy0Zig0DQ+3p2Lj/goSHAQrhDEP0dBQNmm5peZuYKTLgKP7uZrHKVExKb11k0/yrtmIX/AH4hgWhjbmMNm8nzRIGkvb0AO/KHFePQS9uSaR+0eW42VAV3sLJIh12E16qc/ZmQE7YkoEHEr93WWarI5MEjDoJiKRvwSaW6LxMquElVYKFscCM8Rl+m8k7KtW X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 04aa47a6-e6ea-4ac5-bcf1-08d9522ab813 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jul 2021 00:49:28.1295 (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: yfCGSnsT2LXIcHbDkn6tQQXZp7w6vDa5U3tj3gHCzz49JFRh2DBsMa8f6spfIvio X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5160 Subject: [Intel-gfx] [PATCH v3 13/14] 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 , "Raj, Ashok" , Leon Romanovsky , 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. Reviewed-by: Zhenyu Wang Reviewed-by: Cornelia Huck Reviewed-by: Christoph Hellwig Signed-off-by: Jason Gunthorpe --- 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 29 00:49:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12407183 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 D971AC4338F for ; Thu, 29 Jul 2021 00:50:15 +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 AEA3D6104F for ; Thu, 29 Jul 2021 00:50:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org AEA3D6104F Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7FB166EC2F; Thu, 29 Jul 2021 00:49:41 +0000 (UTC) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2088.outbound.protection.outlook.com [40.107.237.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 148836EB72; Thu, 29 Jul 2021 00:49:33 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g4bKw0PQvg2tP6alGI8D6Ah0DZTyjgD4vYTy1DHRH8aFbNWmBdt4ekC2qYfmYgkfPfQK4+ZcVumHAAylQXSbw/AmlIfHdf49fB6cXuUC4ALFywQIf4O85bAdD4Lo+NE8pe+4NskOao62RpR/qJr05ThU9lxNY3/wCQO5XxYhNQeQH6gnvm7fC/qzeONqjS/fmxWG2n1mFrVU3m3En9X+SUoXOWmWY5+1E6wi446yGcM5IC2XZCK1V3bdlb6Aj9EnNGwgtlqi/W0B0r0Jdwg83tOgwTKAcMnQLhESMl9fZDBMO0lmZVnjaORbOlp/1IJzWw5HSPbbeOPqISUyBMDSWg== 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=0kGzbdLOAyqwMUL/7tzX4tOpWDuigyAjkq4OsdYLB+c=; b=Z+1LvznOkyzQgLtjAhk/JGl+tCDZAca4N/qdQ24tyy6D7MwfER58/swPa7JYv/9UlBRphR3oA/xzdomeetfVOsUCQNmsqk4D7I84Isrp4e6Ac9PyjZGPum+CUa0oIo76MhAvxKIEaeKBnQzOy1En3E4/yJZpTEFkBw4MO5xY5EKXASHJ+ED1H52C4nUGictKOUwRO1sXVypzNGJ5oiDeFLf+n3ORyp9mZU1GKXxkPhMJ17mzBRFmywY5TrsujDwtc+zLXHXtRYXww2x2XzjQmkgVsEYWiAchRrEBUml1z5dfE6z1/3kjB1P3q6TSOT21rMI7YANopnxL8ubyynC5hQ== 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=0kGzbdLOAyqwMUL/7tzX4tOpWDuigyAjkq4OsdYLB+c=; b=G37Jbyv1n7jAI7VEKbvZ02nw7qtmGxeXIBvsupA8eNCorKI8KTjFnTSCiaYgpO6mMqviIZ0XeCohRthM0HC1KPdEX/ntie/u0f301EGZ1GVQ1U9hu7gDxqowBwOH6fxz/ynCu3OnI6wcOsjudS1vCWZo4Lm3MPgBqUrGF/oxkaBAhqWbOrRmn0VXpF6+ziXdLvG39HcT2QOmIB/bnIKzLjCCOcyQsN/2nnNih1GRWDTCEZ4Xj4v/E70xoXFkOD6p994IPjZxpcTKJDiKqQh250nobbmvHxgZkLlLnz8kBbSa80NsZuegHllwRbY13zE7eQVInRV63H7PL2NV4TjW9w== 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 BL1PR12MB5160.namprd12.prod.outlook.com (2603:10b6:208:311::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.20; Thu, 29 Jul 2021 00:49:31 +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.4373.019; Thu, 29 Jul 2021 00:49:31 +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 , Zhi Wang Date: Wed, 28 Jul 2021 21:49:23 -0300 Message-Id: <14-v3-6c9e19cc7d44+15613-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v3-6c9e19cc7d44+15613-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: YT2PR01CA0017.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:38::22) 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 YT2PR01CA0017.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:38::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.20 via Frontend Transport; Thu, 29 Jul 2021 00:49:28 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m8uEm-009pnX-BZ; Wed, 28 Jul 2021 21:49:24 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 04bd2f64-b219-4afe-5254-08d9522ab871 X-MS-TrafficTypeDiagnostic: BL1PR12MB5160: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DtUbLP12ZMjwOvdmRlq3B0iZfDZXHLXsCMAbKEpBz0YIZUNuNkj1prCp272ixDFGCSdgye+OnUMSMoZLdZXbC1higb4cI0LNoig05vZL+xhZEY2zC0f6UTb9Pj3GiDVNdF++qrObbRCnhVTJ+TWcIBAefLFnAhSw6oRvJrCUg68RRkbDjcOj6A1niA/4DaZ5S6dSwIS3gs+617lpSWSD9dPghdhYP16jz5MknNksejBjcqU3oSaFAeYKLxTg8eaNAI8yvZw/DLsvvcuwNDRkbs0qYzYdRHV2asUPQTKC5kYhVG+sgHVb1qZtgvcvCPXuJ/jCUBGdZk3aaA3Tx16VRbvpFJ2RkE72YIK5mCRVrwtIrQqMpD2Bux/v0ocK2Qygc0fjMAqSIAE4SixReexxbauMlq+YNZnnh8sK0QFtku8fDb+bbIS24TGvyQbjPaVAgEchQPrT1lkxqkw9o0p/NjWfqcJHrglTSxEw65tdZ0b/H8I14FXCr86YEYUSCjXeZU3dB5spqiT+14yUeyocHUu+eMvDwrvuWzRcz+enRz6/IOMX35AcPSU3Uze+Io2eAIL6qf1fOPCNms4xX7ogz/D87M/FlBeJWj2GyQQqfTAwAh63fwAgde9LYSuMuEa2jZ3p1vZH1cHUkh1kfZFX2kYNQthv4faOnF6R4ykkuxsD74+KSEpaNS71+NCG28Pa 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)(396003)(376002)(366004)(39860400002)(346002)(8936002)(86362001)(2906002)(426003)(921005)(8676002)(2616005)(5660300002)(316002)(186003)(7406005)(7416002)(54906003)(110136005)(26005)(66946007)(66556008)(66476007)(36756003)(9786002)(9746002)(4326008)(83380400001)(478600001)(38100700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: EQvDIZ/FXUxZymMlmm/RbnDv5jX+Ety4YksUiCSNuL6/QIp0ky41yDb7EG+ctL2Udkuv6qku+ChibkTyqaIHKCP4aZEHFqTC/UV9UZvkipC9gtq23MLC9Mz4i6HmHvpJ/kxXJTQmd2ji9sZa50/QksmQKI8kL1SGCNvhjJoqWr2h6+dHMcX8rzsaPh2Fx6J15sTWnDd7+HUHtlotNJHLRtFC6ubVG3TU1G3Dcm83csQScRkBK1SgS+JD5WQjuDofQrdRdQ7hA9whxEPktIPManHESbb3MK0tQFwG2CRaDLO9wKs6LOncmw6AwUy74KD9rTZhpBRr49aFbNOldVLpkvfGpohQRsaNPH2KHmhol1HtEenO5ah4PjKzV0VLYbNB2tlrNfV+9wp8rr2Pe9lXiKfMaD1RghtTh0WOXRzEk9SCXWoXhnkQOsba6uX/f74kilkBd8V4QgqnN1zVdqRmskuyQuV7Ff7hSj/1wHLzqTMcFZAP/DqtSSRA/rbsjbTenPKXa18Fu4qxzpu5NrjQGW9QeZjA+Mxi9JRyinAic6EEbHLZ2YkRV3TrykSDsuc1GEun2BRYRKs5FvJGqW2ENG8jEjEqgTsJDixjg8x1eROxUg2P1yROpidv26vD8jtU35Hm/7wtRgKkKUSfAmmmklPHIL+3aDiWiRt+sioyBtdEDkfbCIRX3dInlG/AWodmoDk6wgGfBLSop1QX8/WqLsV5UItVt3AkM5lmrujwkmdFV6CFscN0rhQozFn4huH+Trm7uzDNsbX2NowciUbvqCGtaZmTsbIWAAeciytK0XtuW1ZxUWKCrOwpOz+yJMAeTiOADcUwnYsmQKemMRWPKVWzb2dpD4LlZcxtGBSRLE4c7kZ6u4XhIcuYn9yvPXeJGWYW6dWf9bTtP/fNLhPsiLt7f15nJP6tgRXieMrvvq97pF+Uo232Bef0gjG76YcoocJHtW+NzyWDbdjEf4C+CX0o8HGcWft0ULnjN72lrc3QArEeF2saMGGjxfK50bO0rzkSXMyoSHoSIn4eEW+3fA2wtLtGk3yQHs8M5DL27rEdBbo9fIuqmVeGzJlT5yi3i8K3e1HElw5OJ8gxwQp5q+P3ockHR7O1KJEVYmAE88qst5CFzoodcL4GaraJRC7x0ssCjSuc9hxTX504Xup+nOAywwSUC/vMPL7qT4aQWWqSkTrqxxYkO0CfE2QVhsx0v4zG7P+ip0/QbwkvA9BO6AsI6lPT9jePwQ64uwm3SJ6Lq7kYjmmk+J6oe9CQ7iGj+0Tzu6MuetUBVQEZso4zBkVWq6GO7ZrKk/h5rsVGwsJS6H1lzMxxbeL1VyZgQUux X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 04bd2f64-b219-4afe-5254-08d9522ab871 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jul 2021 00:49:28.9201 (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: yDDadHgydpi3D/gvClDRCmDl4MX2g3i2a8ZPzMKF8iQz+opEiGtiyXX2BpPiPXe/ X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5160 Subject: [Intel-gfx] [PATCH v3 14/14] 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 , "Raj, Ashok" , Leon Romanovsky , Christoph Hellwig Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Nothing uses this anymore, delete it. Signed-off-by: Yishai Hadas Reviewed-by: Christoph Hellwig 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 725cd2fe675190..5174974e5fb5f9 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 9cc17768c42554..3c034fe14ccb03 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -1470,19 +1470,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); @@ -1509,9 +1503,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) @@ -1659,9 +1650,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,