From patchwork Tue Jul 20 17:42:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12388959 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=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 4E2CAC636C9 for ; Tue, 20 Jul 2021 17:43:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3620D61003 for ; Tue, 20 Jul 2021 17:43:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231366AbhGTRCe (ORCPT ); Tue, 20 Jul 2021 13:02:34 -0400 Received: from mail-mw2nam10on2068.outbound.protection.outlook.com ([40.107.94.68]:52928 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229536AbhGTRC0 (ORCPT ); Tue, 20 Jul 2021 13:02:26 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cog5D0aX1dmEK59zHL73FhKpXF1baIaPstF6rQTAk3U3PVZ+arQYOIGdTKeE6T0sGShCPmKl9cRARMzI4uhqij7Swr5sdsuT8vWLGErSGuQLCrQtpy4iD1y/VqnkH1l6S5W4U4vXmLYQ6dSKouvkrqrx/LUankqCcfT2xUo5Q2UltjLuQYqra6ppUjJJleTmv3oR3bEz99NfjpVtAyLahFx/bhZWnlWtDzJ4uH7/ugQSIFt3boE5mrakPWhZjKRPI6fLSImlMwFxrqS99QhY549wTQ80SeVhu/QP/nJaQAPKqxmxu59wwc/A1P+s1OKxzQyXF1pMhy08rXbZSYITYQ== 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=Q+CqPWbRYNbM3kON0iD8CCcWDFjIjT7SkcujZ9stK/M=; b=jeRAHCzys6gy+zDT4eokhn8zS80JwlDJfGK3cs1A/jRsbo8DoOn/x069eNEydI7d+SQquyvnrMkpcRxm7nI4AHCCebGUva2t6nzI8lYqnT6cu/lnF0MoRJ/pVawT76WhMhseOGBA8bqVrajBgov5KzOr4js9TmO0HEZmTbzUKK/sOzUj+hAd/v1HGfpbrLVp1T5AqK+pyIiu2NLGLyNTSQ87z5vbZ01/NN3Xse9ird/l6qL0xW2l41BF002qHYcFZskESSqYU+fPoaZhMI/ifojDIgbJY956BVZat+ZhSOa3ZupR8iiqRkJCi11MpAFMk0E3XAS12XzTzL6N4FB+XQ== 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=Q+CqPWbRYNbM3kON0iD8CCcWDFjIjT7SkcujZ9stK/M=; b=DPHSlkn22cH5IbSknDVzyNKw/AkYuthN2jqN+JMFXO5BidUNTtJSDBwIdDZnqB//keTY+X0+Yh2MpGLNMje228KFcL7Kb8URS5LfJ46OAHcVHNee1ZgZ2hUgMT7nrBCRA7hVT8f9i7A640nlYVA7k077BKISWGnoLYx4KACiv5wGVgRTioknE2U4Cy89Jt8Cjn18+wMW0kX8xQv0bKNPiZFErEHwQKO24gZjxUmuB3+BXy3LQlrGEkHH6Lc/EdPdqvQMDCnKnfUMjQ2DC0j4Gb/b7zvR6T830TS/MMFqa/+soc8/u6S57hUaAim4ZCHvtpGCW0G5qNUsB1fd2keACQ== 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 BL1PR12MB5288.namprd12.prod.outlook.com (2603:10b6:208:314::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21; Tue, 20 Jul 2021 17:43:02 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482%5]) with mapi id 15.20.4331.034; Tue, 20 Jul 2021 17:43:02 +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 Cc: "Raj, Ashok" , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Yishai Hadas , Zhenyu Wang Subject: [PATCH v2 01/14] vfio/samples: Remove module get/put Date: Tue, 20 Jul 2021 14:42:47 -0300 Message-Id: <1-v2-b6a5582525c9+ff96-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v2-b6a5582525c9+ff96-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR02CA0026.namprd02.prod.outlook.com (2603:10b6:208:fc::39) 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 (142.162.113.129) by MN2PR02CA0026.namprd02.prod.outlook.com (2603:10b6:208:fc::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Tue, 20 Jul 2021 17:43:02 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m5tll-0051EY-29; Tue, 20 Jul 2021 14:43:01 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f86fb051-5233-4dfb-ffeb-08d94ba5d260 X-MS-TrafficTypeDiagnostic: BL1PR12MB5288: 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: e+1yBJ8wwcHelEz2s6GH38h+Gh6hYnIAt9EpYA/PWXmHP4sUR3P4O6fuE/hrcNCzjoGZgoB9q2EmH3f8J98yybzukmQZW1eVgsRjATjK0nlufXYbjEQinCKJF7IAQrFOxUx1kNl6uZ7Jy8Miai2W9NaPQW+CVKVJTbO2r+X+rzfQrGtLkEvz5zu++Wr4gLQXKll96FQ44v7bjVgK9xiXu4BSlc66C+kP1vwge0PQ9OW5Hu4XUS9/TTSUlVlS0enwcs1C+ZwR36Ppy6RwBCNnSf4e64Ceo9wGnjU3iEL8Lt5FrRr6ULbnJ5gKmWpIKrRpIDp5KL06qev5sEywysK0MGhLO0NTH+CID+ByJSS2LoY83pMg2TvxPJcap0CR+8SxGoJOsIYP7k+M8G56ocSspoJ6k+Q3LifCMAvmBvrV54iLxFWNu9OduUevS4sc0OYXKGYU2j9iUyxiZo3M43WfNZD1MsPxtufJPSNXKo/0A0eb9U/+3li01WYZI/DfD2NSXS3Xkku24fVsvImkdrerm80+ZwBSYGV7nkE0CqjIK9u2V1eMbKMQyI4kZ+j6NvAj+z7RgdNh3dkEEl6dY7aEVAj3V59MpKpQa747iyUevvTSSwm/Bhus14u4gYOvBw4efDKJzg8HCPeMWohTsscddcnoj2EttO4jEqhtzrrdG7fWleqVySZidMXDIIzQ7Y7HzFFvU8OkwbVzdubOutSmYA== 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)(396003)(136003)(376002)(366004)(39860400002)(346002)(6666004)(66946007)(7416002)(7406005)(86362001)(2906002)(66476007)(54906003)(38100700002)(83380400001)(8936002)(316002)(110136005)(478600001)(36756003)(66556008)(186003)(26005)(5660300002)(8676002)(921005)(9786002)(9746002)(4326008)(426003)(2616005)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hPDeo/17EFWnDXIJe0BsEJwx2v1L2N13jTpjzxsKA1zBaxIRo+JVt7O8ZsS0FAVMXwJFvhXZJp3B2K/je871XvMzsMTjETJKmgnbTdQXBOLBbSFRdInEubju13JUkl9rJ70FElFjaodlLBMLNWmLuZv9MjZ5VZY5asmf0s+/7wlGvcJA0FWJQLaC5jRVY1F+gNXEIANe6CwWqE+piH9N3pF7VsO6eCtXYpYdkCYmCoV5oaAmzKH6gcx/pwn41Jc6OUC2P/VkMrqCY+6Lt8qUMU1mwHTtp70zLRFTjN/th3wDMRaGSrIK4Uiq6dnr5evv3jEIiVAR/wzcTk35VRD+x8radRlAYRxhtzSCSx7HjFLe3Z0OmL0HICOuT8uMj3hbfp9dAU+v0478bIGI7Cv5wOLsMUWhLkBuLoXJjk/QGfAc2BJPx+uGZoeR0YVyNNFIBxWW+OJ9DDWUJPqg5y03vrh3j7/OPNDNYsKYlRU5gNnjYg972yB0McixKlGuqHxeLBzZa4+120qIfUY26UHIRjonEh9cTkvR4oi713KpYA0RzXu6aEMLBMsA1HLX5ZD8aZUhJ3tJ490FZREbK0pBu/FkxDrHgsELGwQ+tpNzG1zCZODff80EmDPl/IFJ2NXpxsw5PQTLr1Lu+/o43vZuTw4zhybfNRyJFdi4cWs+igbQBAK7Vte24XS+DxoxIf3rka9aBUoZ0HdGvGNZDdwBBtLKQcz6iPVr2NwgLNdndzMYpeKspXjPQabQk6bHNGGVsk1EEpHg3YGsMLAgs79jdOk6zhmlvfzcK/JzweZJHFz2pCo6LyC1Pvi9eivCF+Pnqoftnhxc4b78QWDupcAU5tX5b7W42HaMTOWZ3bq2Dvz26+BHGHcjsHdl7k8k0LKMc6wfJJOztYso+JhVjcE7TTOufn5cwH/UChBQlxgGOF2VLG7OSvrk05wVTOaik0o+Yw2Z8dCuJJuBVrbNzAVUMsBmoFsxuLrBFee6i/9SAQEEyIoMhrlLf0XocHTvHLyzP/i5ZXGqHulcL93gD2xuxOh8gihxWLZV7hm8pHKZQws6DLIHgIsP/2X1AtX/bjXksPzirva9VXWxzG6QaiIIgfa6zfNso1votv6Or6pcPhA4nN27EpmdSgar8HMLGl9OIjcZ9dQCOD9U7S8ab751z4lXy7ItkiGY82ODiVwLbJiCzOtWuj+goF8libqZe3gqDCnot9MSQLT88icv1atB21NY0IjG8F98u8V9ycrSImoDTRYG2JTcsq/N/V0Va0RSZh7zTuj7gG1Zxp2XyKkuZLIOr1vcZCO4tfwQ5gVI//9kdQsDVt+E7IsL0qyDmIWq X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f86fb051-5233-4dfb-ffeb-08d94ba5d260 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2021 17:43:02.3254 (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: X03RHXVdT9jQ3yyMa+0zkpM1MtM6pR7S5rjO9wPldPsn8A1SZHkk/ImCRYRVkp68 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5288 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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 Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig --- 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 Tue Jul 20 17:42:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12388961 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=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 1419CC6377C for ; Tue, 20 Jul 2021 17:43:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0164961004 for ; Tue, 20 Jul 2021 17:43:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232191AbhGTRCo (ORCPT ); Tue, 20 Jul 2021 13:02:44 -0400 Received: from mail-mw2nam10on2068.outbound.protection.outlook.com ([40.107.94.68]:52928 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229632AbhGTRC2 (ORCPT ); Tue, 20 Jul 2021 13:02:28 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HmKWcVvcvNZ8X1djkvd4eVgU4j+pkIobEi390SER0sAVR7nj2jsT81SEBQhI6/wI6Xj4oO3Acmv9FXK8IDQugskaLUdKrx6UnIX+qxzr2ReNIBlZMpvB7dBE5ZIthZouZFOzLRxZWFIb0Ly6Dsv9WxpjNcyQIaUTtFT88vRtsrv6KPEPoJogvdx00EwYZvVz/L29tYekJ4ErPOcqn7rYxpdYkZHwe5pghTJA7MnOAtDhzyv6kMYdOL2OFRt7soRcFdO4wZsoNMr/TSMFGj/zS4lcAnECR+NjVw7e72waQKLycAcMaP6btXxfYPhjZeyydJZ1sxJbAQxCGVeWNNQN9g== 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=Soe1koCxEVCqAD7BxIfZrOxErXa6yCaaYsp8qqxd+Mc=; b=YhsqOeA49fV9KwQzoDu0eokKHR2cjE7s67Z14HWjw1KlejedTYLLbUfRjFz0tI7AXQu4+hUTHssZ63jFe7zkKHAvB/zIU+ssHBbzNBNir+kn9Uj2+rybd5A4QV6XDcSK9hx+dz3ZZVeKTDsThd/dj0up6H1eo6U1fM8ukhiF3geoZ+TA/0Gb+9rpslDuK5LgVq+/qhH0cGnF6eZG5qXjCrGnWIwQxIKOmkSL2aj/GMPBlcKsvFSMsMCPKa9qBbg+WfUWl7T/3IRNtdmx1sFl+O33ZgKgOwKCgpF3efhewcUTh5L5z7owpSX5maTZEahcaQyQKJ/CVkTMm21YIMZUQw== 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=Soe1koCxEVCqAD7BxIfZrOxErXa6yCaaYsp8qqxd+Mc=; b=fXZGuuhMZtMsXc8BeefEykd3NlpjdXyVd+61anwXVyU7L2k6mhxBl/Web6Tex1MfwOjK7d6VBQSgwWp0waVlP6pe1es+M7CjSfp2/PcaDU/yK2FKah8nJp0MiybmmuAwVXGxD+bZD2g7Vbn3m8NZglALZhCUAlGLd/NNl7DKeMC+QorS3jQwvMmMxJkaGaMOQ9LNM/0LEyL6zw9dPSbRAOpkveqHQFW9M73EcT4iAQo5Tu0mRm36I7tHaiQZSDlagRLRr8Izy39SLrZb/w0dCI1GP1uUdHC5X4g8zqRMv4+OmBy2qDjti29q5e8Y0m6gXZ4rigfIjxP7LNkEZdotFQ== 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 BL1PR12MB5288.namprd12.prod.outlook.com (2603:10b6:208:314::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21; Tue, 20 Jul 2021 17:43:03 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482%5]) with mapi id 15.20.4331.034; Tue, 20 Jul 2021 17:43:03 +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 Cc: "Raj, Ashok" , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Yishai Hadas , Zhenyu Wang Subject: [PATCH v2 02/14] vfio/mbochs: Fix missing error unwind in mbochs_probe() Date: Tue, 20 Jul 2021 14:42:48 -0300 Message-Id: <2-v2-b6a5582525c9+ff96-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v2-b6a5582525c9+ff96-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR01CA0007.prod.exchangelabs.com (2603:10b6:208:71::20) 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 (142.162.113.129) by BL0PR01CA0007.prod.exchangelabs.com (2603:10b6:208:71::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Tue, 20 Jul 2021 17:43:02 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m5tll-0051Ec-3M; Tue, 20 Jul 2021 14:43:01 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b12af25a-1566-4731-abb9-08d94ba5d262 X-MS-TrafficTypeDiagnostic: BL1PR12MB5288: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3513; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: olcKR1i15x7AbkLVsk2jMXs0QIvRpi1S1tC+8HEPnjCYDJPUilKcBY9/WM5+EnEb/xHrTkYLxyikMHn6ppTyRofNNgbuqB43ugeWoKSzubFeKX9K8Bsptm4H9WTwW1z4c6iepLWjpyi3w9Iaab9h5AST04Fzugxe6aCRaXWNl8H0G5Hxd+Wq8g8o+cJpamviSicAAbcwpvt5mBMTDTxCkmgRuhvExEUw8xU6pyzp1Ny08Hv3Jwl66757hu1VpuLL/CCvvi6kS5flR6mjSlrDmHnc1g6J1q9kAcnQi8zxp3TJlpFy6nQRJwx6aeq3vqTKTwJebGOC2aAjPTWLZr9on0b8+Hovwv4A0ZfUCZbjxANLuV5V5XXnKpgNaDGLrTsswB+6vcZ1QL2chmgXmKjXI8YBDDpZKrzuZdzd8InCoDrBurMFsqejRNoRGmbxXcQS8IGLnpTf3yvzsDh6YE/YuRFBwHm9VPMh5KourdveuT0hP/2jZSHtsU0MZSt5pypJNNOdzOCKnaStVBjjiSlTtIfUqOx0Rcl+57IS9G2rH0PhvRwY3jYUCINfO3tKSwYPmFQlETm14E28ONpUGzwRUrQrI+vtfiqs2ft9nQB1cIAmtY74zcsMKqWQWdoUUD+Vsy7NNwi8IRUbJ/dEbSifwDBowT3LTLnGtLp79HPOmq0ickKqMW11Ck8pBoVUyZYnlbFSE4iyOm0RLL+CLWIAGw== 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)(396003)(136003)(376002)(366004)(39860400002)(346002)(6666004)(66946007)(7416002)(7406005)(86362001)(2906002)(66476007)(54906003)(38100700002)(83380400001)(8936002)(316002)(110136005)(478600001)(36756003)(66556008)(186003)(26005)(5660300002)(8676002)(921005)(9786002)(9746002)(4326008)(426003)(2616005)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DnY4VjZadMC8USAKoG/JsbJOO1WccfsLYf+xersxIw1Ie6Rvbv52dfE/M2/8s0haTpHS3wSNRuBbZT7JZnk7yaRHCm7L9SvyY14vObyFoNgXtUouoXS/NIADstCtB05BgvvrXhLGWnwZRtf8H0HpDTOeshUvgdvHPXUUz9hbii4Fc2uAr8Db5K0RUVKDOzVqUAr3cx6Td1/5V0/c340Q7nBmsexwRUQuMb5jrtl4c4l+66P7BygrVmBvQxfsNSWo1raqomNenXrISGjd+ji6t+8biC6bbgmh2KhBTl+nFCa7nSbBMXtEqvTV0hUCP9o3xTGbEOvUWI+VTxJQrFLPFw3MFfiJhxIwX51S3tHbVWd4cLDDGdNtkjGEE8PQy8YIZW+TgC/Do+qN+9c8RftgDysbyslu0fPMn5bF8Os01iiqyZH/xIFLkz0GYYhNgQtHM9XM/bFZ1zdSf8pSPFnwjwyjvQee4uR4YoNaFAuLrdhnX4M4+WSzAkoI0niQf9H68M9deFgFsR6WDq9CnSDZgr5MyWMBwUXS4HIsY3ALx89IlY+tz7DQhoMwnuHFbsqIxRKL/QcmHAcY8FVOyVJMqPyMDim7KDnMcPld0nlWqUdmGb1dizrjAjy41lfm5OlJ9p354HNyFqmiKOtjdmdpXkhF+fyycgYK6caoeIzARxUVF0uuXisHBrHAirsMfYJ+c+9bp7nvC9AL7khBrnRFpf0Orzzbbx2xPaz/cnMM+Jl9Vjk0dMOvXIL0zG3V+7GqhE0vcPTFx7aZ9orXIQglf8B6RbO2VRuw/leXlgm36SDJ9a6KY62VskQU0B1tnn1tsPNg6WE3OH7qVvyAcKvUK41rhR63BTKOvsfc3C3ltYZGsvqvJJ/73393oxOT+pnYTpZVo8r85jjNOZS0SCdDcIcnnefQxXiYtJ6eLRLt/zpCXbW+4/Or0H1XENHzsnF0yqjHQo5s8EauMcxLAsZjSyykalV2j5tT4USQLFwDTAuyDaYKYWfUijvxluM8LXg75RzNyWuh+NjhQYLw94M0xCpoTr6qrCsIInEOupK+WivWXyCdPum/Bc/SHehuPqnkdNemoKXTTDVRgv3bwpoAcxSQ5UfFUTShb5SEGISq4i+ImKTEWv/rXIQvpLlGjuvYT+hmf7wtG6kADWz9N+QTDkQazqxw6VvpbFlvQiYAmlJoDirDXoLzPZ/1FaHhzwM+8MH3nHoN90vliD/87ndu0NN6O0jwee0r2UhLXFgB/AOWg/z3Vks+kVOgPF/A4wm5Ur876tVH8uv84JCzRS8OTqRjtoricuGtyVeLLCIp8GM2zCp3JQJGFchXH0SuOYJc X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b12af25a-1566-4731-abb9-08d94ba5d262 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2021 17:43:02.3673 (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: Qhdek1nYIN4Z9bTLOrUAD5iHme5vLxAeKi1P+mbCVULEoujNcCjZ2hc20J//One7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5288 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Compared to mbochs_remove() two cases are missing from the vfio_register_group_dev() unwind. Add them in. Fixes: 681c1615f891 ("vfio/mbochs: Convert to use vfio_register_group_dev()") Reported-by: Cornelia Huck Signed-off-by: Jason Gunthorpe Reviewed-by: Cornelia Huck --- samples/vfio-mdev/mbochs.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c index e81b875b4d87b4..501845b08c0974 100644 --- a/samples/vfio-mdev/mbochs.c +++ b/samples/vfio-mdev/mbochs.c @@ -553,11 +553,14 @@ static int mbochs_probe(struct mdev_device *mdev) ret = vfio_register_group_dev(&mdev_state->vdev); if (ret) - goto err_mem; + goto err_bytes; dev_set_drvdata(&mdev->dev, mdev_state); return 0; +err_bytes: + mbochs_used_mbytes -= mdev_state->type->mbytes; err_mem: + kfree(mdev_state->pages); kfree(mdev_state->vconfig); kfree(mdev_state); return ret; @@ -567,8 +570,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); + mbochs_used_mbytes -= mdev_state->type->mbytes; kfree(mdev_state->pages); kfree(mdev_state->vconfig); kfree(mdev_state); From patchwork Tue Jul 20 17:42:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12388969 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=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 83C63C07E95 for ; Tue, 20 Jul 2021 17:45:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6D2C961004 for ; Tue, 20 Jul 2021 17:45:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230465AbhGTRE5 (ORCPT ); Tue, 20 Jul 2021 13:04:57 -0400 Received: from mail-mw2nam10on2078.outbound.protection.outlook.com ([40.107.94.78]:22145 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231452AbhGTRCe (ORCPT ); Tue, 20 Jul 2021 13:02:34 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TeMFacNfdA2ucd0+e1LAWCBUJnVd+O3Jxjs4K0svunHDh1otUQ6/HegL07z+4GTM6RDX08+FdOmFCO2UxxTSU/SOTjiBqWso4TeQ4m3oaaSVSgCMefy9M/UrsJbadmZPp0M6TcBSdzKlfp0dEz+yDhcF+obGBPYIHOAANw+V9wD6xYXcrHEvYA3ODUzmvzGcAsPVf5hG0VVhQFIZY3bZYZvNWCkDRfy0yJF7LdRFPBcy/BAKCHlmz+gXbFIDiBl7Ll/nFIHtEUPF2X3n1ovSYb6oL2bcFLZWNhy3XSWOmF5p8YdkYnDJxu2aFiR/ujGwYW+RWjCcIiDFPSzyoo/H8g== 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=AE8bje3xI5vscrN7ifPxIEPjenL15fcXNKHVbmaJqQU=; b=fTjd0MwMqOOJsh9MhfSELlXMIY+7sDsqWxh3qom/LuulgILpKmhPlZoWFyrxkk5pKqXyFd0fDzQbIhNhKQ967oP2hlb1M6PLkkktS7M0RVoAWtsT8ewcOY113EBlwk4VTOoDvvYS8dekiDHjdPfwJqjwBHmFBYsaF4OQDIQ/SZHwKlNOoTNXg0Q+mIrHqsz9Lh9TBAKQeapdjuDqyc20A3xxtezFLz+SXmNI0dfSnBswetWareEnT3tiUXoN7PXWOmTDLiAj0rKSqekhG6EksLGFYS9H/4Q6g/ljUH2ABhctURYkPJFW378XzbUE7Zo7eMt3s6IcSo5wpdfxuHGNPA== 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=AE8bje3xI5vscrN7ifPxIEPjenL15fcXNKHVbmaJqQU=; b=r7CLpnKa3xY7qSCqBe83Il0c1DzO9k7FGrpeg1zYnjbt/lR0spjxFeQKDRAaNhKQQpDyQ6S7eOv2uvnsfereS8HG5DPX2s/wOWfzZeeG7Nv02wySfC3w75b+0Lc3KeacA6CLBl7Z/OmapE+suLwyKOWy+D/iUsb18nAkpzmPPgwqStfSci1y0YnGFC+Q7+CcLP29Be2zIDD+mrNSPsBUnmca1sIKjXnaYlZPNcC1j2SsdXNvmR+ZXUH5LlhyvLLfC7ibuZMHqFOfBcEPnwfj/MhRpRyDZvxv55BHX7HR3DpKVVy8l2gOqZI6OzgWCyuXXkYO3I+Srihdm8qGfmazyA== 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 BL1PR12MB5288.namprd12.prod.outlook.com (2603:10b6:208:314::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21; Tue, 20 Jul 2021 17:43:04 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482%5]) with mapi id 15.20.4331.034; Tue, 20 Jul 2021 17:43:04 +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 Cc: "Raj, Ashok" , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Yishai Hadas , Zhenyu Wang Subject: [PATCH v2 03/14] vfio: Introduce a vfio_uninit_group_dev() API call Date: Tue, 20 Jul 2021 14:42:49 -0300 Message-Id: <3-v2-b6a5582525c9+ff96-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v2-b6a5582525c9+ff96-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR02CA0035.namprd02.prod.outlook.com (2603:10b6:208:fc::48) 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 (142.162.113.129) by MN2PR02CA0035.namprd02.prod.outlook.com (2603:10b6:208:fc::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Tue, 20 Jul 2021 17:43:02 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m5tll-0051Eg-5M; Tue, 20 Jul 2021 14:43:01 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4aab226e-440a-49a0-f159-08d94ba5d2de X-MS-TrafficTypeDiagnostic: BL1PR12MB5288: 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: /tYlu2Fr3WNoQGdZxTd7yh38h9H6LOeheEV0n4s4RM6JIwidWnUf0pPvQAbyLyyP94E9qUnq5amU/MIddmpQRhNGCD7a4U7I8i619fi8WI4fQV0X4J/2atwy5fNDAPnuGkDwIC77K4Yt3WJNsHVXRnJ+RXdEk371R2m7k8vrjVfu+bA0VS34khqct1ZHgk1VTOXW/MhOXvBaZP8jT6JNzU0wWOH64IUHH6obJwuJlSqqqyKsVYgETwhUoMkSErDk9+txarOpIQySiC37WI0GmlWB0hBJLPtewlHpr/NKE/oPb5xpP3neIz4vOOf4r99xm4pjHRaLuvz5t9wYvBEdP7VOuwAxL/wQ0jF+1Y79mCa2ka7vvufOCAUTQglRvc63o7q9P5bYcsH4yv9HfrI7RHc7VF+gDaiXd+HswlPgOU5y303JOUFfukEG1Wb8r8vja1cvskuwt50SHHx/ILNW7gytCHzVW817/Q+L2mQL5Ed/+F0AzhgyROPKWbycP9m9ZX+o+gZuu5ngqjIDC5A7lMS/2vsysY8/Ee6O1FQLTEByhQYau/kv21pzd0KhkHa2/TGTjwTsXKCgYKDbTC+aH9oSuq73dIF80wiW1MVTNPRHcGCYs2bC0ZYXDjlt33MzM/tRdpyPhG80yAJCt2K3VChbUCShgi0oNepzmo+FzK/Hn4J/B3u6WXQkv9mZySSioYAVD1lHdyXjS+TYxH1nNw== 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)(396003)(136003)(376002)(366004)(39860400002)(346002)(6666004)(66946007)(7416002)(7406005)(86362001)(2906002)(66476007)(54906003)(38100700002)(83380400001)(8936002)(316002)(110136005)(30864003)(478600001)(36756003)(66556008)(186003)(26005)(5660300002)(8676002)(921005)(9786002)(9746002)(4326008)(426003)(2616005)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6XaWOktU5mm1U5nK2Zt8FFi7iRQuqBSLOYbAjZSwdGlakYE9DUeenZs4FFYVgBTc/h+ktdPzyBOg3WrtYqqUNVY6WHLAh5wTOOp/OvFRzkA44gVlDpHqb/FMuAOxc06KMSqoqy3WfVZC4JEeCs4T6ivZwnJi4oL5OVkH62ysCEWEMKlXZtqBLB+LR0pyBNGuTdiix0aakGPwh92X6NwcQi/h0fPDO3ab7UCBoVVQ/ow6P9AOMIqJbp+eu+x7eQXSAlyzvvfZ3rEhha1yg8CA8WnY+gnLXqtiTcutVwvNqT1S7eg5UvNzdjz+uKi8aa7xqApGUnZF1g5qEljg+VqLiuMLOcI9D5+DvS0M8Jo+4wz0+Zn9mzhCs7Kh+dvBjAyAw/zaj6Bw8/lNdYaZ/34P76GqVlXv18+kDENkIl0JsW4sMDOF5QOU494u7onBWOQK+RJ1Y27Uyhi4tjt15TTrdbc15iq1NjmJF5d4n+BehSyl022ERuoA8w88m5b5IDV42bIENd/uW2//XPIo7QOLXndGifiuANdKT9f7YiDtPK+GSUXarvk34OwumNlA68ZzIsvlViucJ81/f30eOtWCkgYLHYAWNDze2HSyc6eEFwHQN6yr1ukXtd69Sx5FqMsuc+uunwDR7MTqbQXoAVkSvZICmJgpy1ljEzrCthW/i+u6x4LRWSfeOdVz5jFymccM5Mg8HAcfQkJhaTOK7ejXPCoQbEkomUkJW4kOJLaQFYFX5BVBGNtR54T6ErvByUKtd1P9vRPCBSfR4iU12X0K64+6RgotO9FDdCQX9zPj9airu6QVIyXnpK/DNZfEjFHjGRBAeJ8ML44JdSUg3mWBNXZoFaeBDHjY9FXu1VLUvOr9zGjVurnyedzeKfYmZs9iAuRJaz8GW8dGh33bRiYOfJ9vUNEJQjebOCwJPmeykkOpgEAdH8o35aZ58EJJVNRTJYMeEkfV57X5lsY/HtzwxWB5NwigdpXZ+SiDYUO/BDreiuv+GSuEqbjvCDFxEf4HWjrooNjo6SyVW+iKS3x3GD0kSVD3W8NvLM9P/RRRMHKFAlJk1dvfKwJFVvOSvPGdPHs2n9TE5nUze635qlfVhHKfT1cBnrRpEdhbpcpUxmdzsGNfsMbGorwUoxMaw8cfK2RxIQwD7YsehzpKn42Ove9L8bF1S4F316MA9pLBOg8R9ThzeD32O9mXMtRDQLRQ+1KxzbEQYS5EUvpLXbHzsakQTw0NbHRLT9QRevJXzTMFuRKlqBQwAabTkBnRgdOgElLnRBdFLrGdufOPvYtg5MnFxFoB0jcA2wkZOjmrbw1asEmdNoRcrc2mrcaeu6hv X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4aab226e-440a-49a0-f159-08d94ba5d2de X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2021 17:43:03.2135 (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: OER6UE1s9paog5W/7YwJD3M8QR61HnPzOxa2izCKJuzkDFmXR9xgDg7EE72g/RgI X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5288 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Max Gurtovoy This pairs with vfio_init_group_dev() and allows undoing any state that is stored in the vfio_device unrelated to registration. Add appropriately placed calls to all the drivers. The following patch will use this to add pre-registration state for the device set. Signed-off-by: Max Gurtovoy Signed-off-by: Jason Gunthorpe Reviewed-by: Cornelia Huck Reviewed-by: Christoph Hellwig --- 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 501845b08c0974..4ec4bc649351fc 100644 --- a/samples/vfio-mdev/mbochs.c +++ b/samples/vfio-mdev/mbochs.c @@ -560,6 +560,7 @@ static int mbochs_probe(struct mdev_device *mdev) err_bytes: mbochs_used_mbytes -= mdev_state->type->mbytes; 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) vfio_unregister_group_dev(&mdev_state->vdev); mbochs_used_mbytes -= mdev_state->type->mbytes; + vfio_uninit_group_dev(&mdev_state->vdev); kfree(mdev_state->pages); kfree(mdev_state->vconfig); kfree(mdev_state); diff --git a/samples/vfio-mdev/mdpy.c b/samples/vfio-mdev/mdpy.c index a7d4ed28d66411..57334034cde6dd 100644 --- a/samples/vfio-mdev/mdpy.c +++ b/samples/vfio-mdev/mdpy.c @@ -235,17 +235,16 @@ static int mdpy_probe(struct mdev_device *mdev) mdev_state->vconfig = kzalloc(MDPY_CONFIG_SPACE_SIZE, GFP_KERNEL); if (mdev_state->vconfig == NULL) { - kfree(mdev_state); - return -ENOMEM; + ret = -ENOMEM; + goto err_state; } fbsize = roundup_pow_of_two(type->width * type->height * type->bytepp); mdev_state->memblk = vmalloc_user(fbsize); if (!mdev_state->memblk) { - kfree(mdev_state->vconfig); - kfree(mdev_state); - return -ENOMEM; + ret = -ENOMEM; + goto err_vconfig; } dev_info(dev, "%s: %s (%dx%d)\n", __func__, type->name, type->width, type->height); @@ -260,13 +259,18 @@ static int mdpy_probe(struct mdev_device *mdev) mdpy_count++; ret = vfio_register_group_dev(&mdev_state->vdev); - if (ret) { - kfree(mdev_state->vconfig); - kfree(mdev_state); - return ret; - } + if (ret) + goto err_mem; dev_set_drvdata(&mdev->dev, mdev_state); return 0; +err_mem: + vfree(mdev_state->memblk); +err_vconfig: + kfree(mdev_state->vconfig); +err_state: + vfio_uninit_group_dev(&mdev_state->vdev); + kfree(mdev_state); + return ret; } static void mdpy_remove(struct mdev_device *mdev) @@ -278,6 +282,7 @@ static void mdpy_remove(struct mdev_device *mdev) vfio_unregister_group_dev(&mdev_state->vdev); vfree(mdev_state->memblk); kfree(mdev_state->vconfig); + vfio_uninit_group_dev(&mdev_state->vdev); kfree(mdev_state); mdpy_count--; diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c index 8b26fecc4afedd..37cc9067e1601d 100644 --- a/samples/vfio-mdev/mtty.c +++ b/samples/vfio-mdev/mtty.c @@ -718,8 +718,8 @@ static int mtty_probe(struct mdev_device *mdev) mdev_state = kzalloc(sizeof(struct mdev_state), GFP_KERNEL); if (mdev_state == NULL) { - atomic_add(nr_ports, &mdev_avail_ports); - return -ENOMEM; + ret = -ENOMEM; + goto err_nr_ports; } vfio_init_group_dev(&mdev_state->vdev, &mdev->dev, &mtty_dev_ops); @@ -732,9 +732,8 @@ static int mtty_probe(struct mdev_device *mdev) mdev_state->vconfig = kzalloc(MTTY_CONFIG_SPACE_SIZE, GFP_KERNEL); if (mdev_state->vconfig == NULL) { - kfree(mdev_state); - atomic_add(nr_ports, &mdev_avail_ports); - return -ENOMEM; + ret = -ENOMEM; + goto err_state; } mutex_init(&mdev_state->ops_lock); @@ -743,14 +742,19 @@ static int mtty_probe(struct mdev_device *mdev) mtty_create_config_space(mdev_state); ret = vfio_register_group_dev(&mdev_state->vdev); - if (ret) { - kfree(mdev_state); - atomic_add(nr_ports, &mdev_avail_ports); - return ret; - } - + if (ret) + goto err_vconfig; dev_set_drvdata(&mdev->dev, mdev_state); return 0; + +err_vconfig: + kfree(mdev_state->vconfig); +err_state: + vfio_uninit_group_dev(&mdev_state->vdev); + kfree(mdev_state); +err_nr_ports: + atomic_add(nr_ports, &mdev_avail_ports); + return ret; } static void mtty_remove(struct mdev_device *mdev) @@ -761,6 +765,7 @@ static void mtty_remove(struct mdev_device *mdev) vfio_unregister_group_dev(&mdev_state->vdev); kfree(mdev_state->vconfig); + vfio_uninit_group_dev(&mdev_state->vdev); kfree(mdev_state); atomic_add(nr_ports, &mdev_avail_ports); } From patchwork Tue Jul 20 17:42:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12388965 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=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 069B8C07E9B for ; Tue, 20 Jul 2021 17:44:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CE08361003 for ; Tue, 20 Jul 2021 17:44:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232318AbhGTRDO (ORCPT ); Tue, 20 Jul 2021 13:03:14 -0400 Received: from mail-mw2nam10on2078.outbound.protection.outlook.com ([40.107.94.78]:22145 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229643AbhGTRCb (ORCPT ); Tue, 20 Jul 2021 13:02:31 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NuqUMoc38dGBbEqhKhpaLbzeTV9KPNTcgcLe8YJOUn+53THPRq1H1g4Ghi0PkqpgFMTFdl1/8tGCykTCk7YsLWQH2OVmELYpChxHczUNDtJ/nOZlJZI5gWSLOXgvFAs293hrBWDSeegcmNU6ss18G2jkRZLLJL5v3gdfEMl3wwtAiDOZ7FnnVkozok5VeN8Kw47Hs+7v3qTPlOntSBQlJ5BRoOBiwxiJV+DJ6a35EYGd7cOzUtQIt9gGrAlGCT7AEXcaCe6tv4cM61V7SPEmn1vZhYtjzAZWGep4x0K52OTi29rWMS0zqg/it6xXfsqIQE2cLXGP1zkBB74yf3VS5g== 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=1wfi1e3jIbfgXw/VVQzuHe6iSz9OsFAUqnUBtq2yCag=; b=mUXKO3Gl+YXNH4XpiJlcC7Zyd3BqREI3Kto8YyQtyGgSKGB2efyePCVXrPKiNxbgV0HhVsqpgqAHXmv2pPPfO/VV/zl8m+CdW+s50KnfonSf9BpxnJWn9EYXzrxH+gzqfnmKOw82jS9fvFE2Mw5s/FgUxLIGspmFi/jxjxNYZlwb/MZ91ngphIfyc5hJDsd116HtA6yJ7J4LzuORvR0yZpz2HP7VZOUmY5yjbHZurFErBir9R/8kmETCMIg6SAdbOofPEcqWpkWrq+hD25G4NMZErRjum0KanjIuQSfKqlgRgKWSvse9duoJKJWnAfKieQUDxZIRsXuHuOvPTUmBRw== 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=1wfi1e3jIbfgXw/VVQzuHe6iSz9OsFAUqnUBtq2yCag=; b=NzYb3LB7zhkj3k3FHr14CzW+Bqx9KnnuBWyf8ZsF3rikHvChEDm8Yl2xzmGcM/5kCVlUFlgaKxZrbgWFuC29PX8jO1htm8rsE0+GsUa4UAnXt6GKLlfM/RpE1s4V1Ni6IaD/A1WS41+FhepoGGqot07C9em9ddhZqc/afRwRb8rJKDRwf0nhl6qrtk3ABGDn+/UhTDb/y2vLPX+QFvxPVFtDIXQbhZFloPD87fZ+jFteaSFYIel0BoXamgyJg5ERIWQ7MNMaMvau2J8te9BrFJkIk9W7+bl/wziSpLnSA4WU7mHJ31MD9y9b4gLp8KM6R2Q20nOC0zj1zvNuPXMAug== 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 BL1PR12MB5288.namprd12.prod.outlook.com (2603:10b6:208:314::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21; Tue, 20 Jul 2021 17:43:03 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482%5]) with mapi id 15.20.4331.034; Tue, 20 Jul 2021 17:43:03 +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 Cc: "Raj, Ashok" , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Yishai Hadas , Zhenyu Wang Subject: [PATCH v2 04/14] vfio: Provide better generic support for open/release vfio_device_ops Date: Tue, 20 Jul 2021 14:42:50 -0300 Message-Id: <4-v2-b6a5582525c9+ff96-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v2-b6a5582525c9+ff96-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR01CA0032.prod.exchangelabs.com (2603:10b6:208:71::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 (142.162.113.129) by BL0PR01CA0032.prod.exchangelabs.com (2603:10b6:208:71::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Tue, 20 Jul 2021 17:43:02 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m5tll-0051Ek-7i; Tue, 20 Jul 2021 14:43:01 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c9888313-3efa-4fb4-919e-08d94ba5d25e X-MS-TrafficTypeDiagnostic: BL1PR12MB5288: 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: QHcnqkzHBJP8fi+LbGf9UFHVvB1F2MyAz4HeIMR440hZadpub2OiCaKVcohG/soYz5h/sg1mmv0OM2DBHOBCPCBbxNZAHkyYCS+RjxsUuHwTHFVJfZ3D0NpQdNbnwfm84aPSSfv6p/io2VSHL22wVQmon+X7wVE2pTG6XR+uq+Zdv28Q4WjNcYd6V7eXt2MIUT5T2PAExHCyR2O8ePf88hv6mzb6qxMTAFE1rdLlZ7iSEjNYwYk483JSpY3KqkxBNmACPVjpzCGRAmwx6VxD/q4B4O1JeTKjTm6yAkQGg1mrCyb49C/eo5GK4ovjuQMKiutldbSV3QwOxAwUid9LatzhcioKTkaTN0LfMjfvs773hAOhLmQALEKZ1bPWCRCJgltamAowveVnWaX0PUNxprPSLGHK3q2sF2TSHF/n4aKpI1bGPaQIhnp7NmIvgXDOp2XP9NPPJC5TYobuXdDrPCRo0ed4cOl9jisoKIwuF5B6OZ1o75knsQMVnmp3t+R7mieoQyE/UHYX36VGB57Qvis8ObdZcZbhKPhGSYSLMvhan7LXcDnYS7zgkRQ5fESkRi4TWgH5JoJnPnmMo69RT/c76loJp5837CLIjHKWXGpED3xOlW+1jOCohYwbveZAtJO1f9FBjKPgH5yp9ap/SncCUtyI1Lmx24svrNq0vtESVZuXmhsLnqv1e0R1a/w9FVcps1Y8g0ulazOu18mCoHLp5XASgUJftL8TvSPqSlg= 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)(396003)(136003)(376002)(366004)(39860400002)(346002)(6666004)(66946007)(7416002)(7406005)(86362001)(2906002)(66476007)(54906003)(38100700002)(83380400001)(8936002)(316002)(110136005)(30864003)(478600001)(36756003)(66556008)(186003)(26005)(5660300002)(8676002)(921005)(9786002)(9746002)(4326008)(426003)(2616005)(4216001)(41533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dI3A7WqjCR1FW9DLOgzBfQZ6V3emnwyIWom2aUArDUQqB1fhGSZYCVyxoib9gTorRkn4ILYPW9dmLhuUKMu0XAMXpdU3OohyeYI36gcLDQnrDQCZAUPdzPDAaMa2b5Rn/lzYdDZGL9LgyHXN7uSOgWV/ZRTsd6mrHaKGe7ZJynePcG8vSnmlVGHtvdv7LsRQ2XdppsnJHv2Of3wiKyU2NC1arlT9IwCwT27rrI3UnWFB0Igf61OZAWISqXSqOdQSdsM79QJZ4PCjCjKTgtlGcsjc5lxhFfwO8W6EzgxkOSD0fg1JcXQE56+1CRaneRlQASkAgVlcefFxMaDGaev2v2Qcpbd0KptYPZ3uU0StsHDbqO7Hm1auetRyU96fNRcXWQiXh2oYErLM82bw5JMKUdcc/Ce7MUHrclOv63Z7qbDtNj4nnp9iFCj66CKqVTgiiL/KUrWSpP2ogi3mNEcCgH9gWRZFNPHOxotyebdMN2JbZ6XDJQ6KMztJmK/xGdUO/2uMHX3aB8uIQJ018eaZ9KTJkdWZTS/bvtmBxFKVAZdfmyOI3/M89ygo9By+vs8FwrXi15VqqN3pn2nluldIGgEaMFcmyZ4L+HMoZskbO4ZFN0bMIMNO6yP6IYlFm5fFUf28CuxnL0Q4Y/LIjUww3+j0p9sdL63mOtOc7B9RvYQdAF3SwD7NNpIN9OAPFhbaXYi0TdJU8t8KaC7pUm9v//PvXX53NuaB7PKIIcZAEm0tNxVM3eGUnJYeDfw63di8L1N/5SJ1qjxtzSowyTP1w28jbw2m8sMr8eTR1FOXzjdU/5GtAEhTiks9b9y1IP/NVNHU1ZgxATV9YK64y10ZDMgEH5w2qh/vu6J58q6KcNjRJ2jjEfNCR+LN+85qNXtP2dQpk9MXzhVrwvHt8B17ubWGWNJ404AtgTVcHoXc7Jq4QiHLwp676POv+Frvs2mARANf4mBc4neCk8jwZr7rPw75Kgy5Mejx3v2Kd3nqc3DiORJlcxQxddRBGzo7WCUZobSovBWrKXtB5Go4hydX/c42D+BhtifPvnrLi0SHbVy/jlTrwB6oW86gOR+UYJ+kcO2QxRHlcjU/BNhoS025XDVqIMd725FWX+tPeQKd3RPnrZLJvJ6p2QqmBGRPR7FCFXXpNlZlgjdAye6QzYtUaAjj02TYscZ40vrV9l1XXDfOG1tVcQMo/Wr5DcmLlPPwMVu8IWzepZlQNJR4/Pfl//Y0Mdq9Wl3T9TD9l0hKlAoxQFVOlPWypyrc/LnaQh0b2dBG0CF/p6hPHtA+hzyitva+0tZ3fJerkP3u4GHHZD2xM/KTSL0RwPRI8z9fbIFl X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: c9888313-3efa-4fb4-919e-08d94ba5d25e X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2021 17:43:02.3892 (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: r54xWb/vFbbNKY2GwTL11fekKj/8yrWYOuKS5IT5FUBRKEsMhXswto2mGMH0qr8W X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5288 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Currently the driver ops have an open/release pair that is called once each time a device FD is opened or closed. Add an additional set of open/close_device() ops which are called when the device FD is opened for the first time and closed for the last time. An analysis shows that all of the drivers require this semantic. Some are open coding it as part of their reflck implementation, and some are just buggy and miss it completely. To retain the current semantics PCI and FSL depend on, introduce the idea of a "device set" which is a grouping of vfio_device's that share the same lock around opening. The device set is established by providing a 'set_id' pointer. All vfio_device's that provide the same pointer will be joined to the same singleton memory and lock across the whole set. This effectively replaces the oddly named reflck. After conversion the set_id will be sourced from: - A struct device from a fsl_mc_device (fsl) - A struct pci_slot (pci) - A struct pci_bus (pci) - The struct vfio_device (everything) The design ensures that the above pointers are live as long as the vfio_device is registered, so they form reliable unique keys to group vfio_devices into sets. This implementation uses xarray instead of searching through the driver core structures, which simplifies the somewhat tricky locking in this area. Following patches convert all the drivers. Signed-off-by: Yishai Hadas Signed-off-by: Jason Gunthorpe Reviewed-by: Cornelia Huck --- drivers/vfio/mdev/vfio_mdev.c | 22 +++++ drivers/vfio/vfio.c | 146 +++++++++++++++++++++++++++++----- include/linux/mdev.h | 2 + include/linux/vfio.h | 19 +++++ 4 files changed, 167 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..8572d943320214 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -96,6 +96,76 @@ module_param_named(enable_unsafe_noiommu_mode, MODULE_PARM_DESC(enable_unsafe_noiommu_mode, "Enable UNSAFE, no-IOMMU mode. This mode provides no device isolation, no DMA translation, no host kernel protection, cannot be used for device assignment to virtual machines, requires RAWIO permissions, and will taint the kernel. If you do not know what this is for, step away. (default: false)"); #endif +static DEFINE_XARRAY(vfio_device_set_xa); + +int vfio_assign_device_set(struct vfio_device *device, void *set_id) +{ + struct vfio_device_set *alloc_dev_set = NULL; + struct vfio_device_set *dev_set; + + if (WARN_ON(!set_id)) + return -EINVAL; + + /* + * Atomically acquire a singleton object in the xarray for this set_id + */ +again: + xa_lock(&vfio_device_set_xa); + if (alloc_dev_set) { + dev_set = __xa_cmpxchg(&vfio_device_set_xa, + (unsigned long)set_id, NULL, + alloc_dev_set, GFP_KERNEL); + if (xa_is_err(dev_set)) { + xa_unlock(&vfio_device_set_xa); + kfree(alloc_dev_set); + return xa_err(dev_set); + } + if (!dev_set) + dev_set = alloc_dev_set; + } else { + dev_set = xa_load(&vfio_device_set_xa, (unsigned long)set_id); + } + + if (dev_set) { + dev_set->device_count++; + xa_unlock(&vfio_device_set_xa); + device->dev_set = dev_set; + if (dev_set != alloc_dev_set) + kfree(alloc_dev_set); + return 0; + } + xa_unlock(&vfio_device_set_xa); + + if (WARN_ON(alloc_dev_set)) + return -EINVAL; + + alloc_dev_set = kzalloc(sizeof(*alloc_dev_set), GFP_KERNEL); + if (!alloc_dev_set) + return -ENOMEM; + mutex_init(&alloc_dev_set->lock); + alloc_dev_set->set_id = set_id; + goto again; +} +EXPORT_SYMBOL_GPL(vfio_assign_device_set); + +static void vfio_release_device_set(struct vfio_device *device) +{ + struct vfio_device_set *dev_set = device->dev_set; + + if (!dev_set) + return; + + xa_lock(&vfio_device_set_xa); + dev_set->device_count--; + if (!dev_set->device_count) { + __xa_erase(&vfio_device_set_xa, + (unsigned long)dev_set->set_id); + mutex_destroy(&dev_set->lock); + kfree(dev_set); + } + xa_unlock(&vfio_device_set_xa); +} + /* * vfio_iommu_group_{get,put} are only intended for VFIO bus driver probe * and remove functions, any use cases other than acquiring the first @@ -751,6 +821,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 +831,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 +1439,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 +1454,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 +1497,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 +1656,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 +2465,7 @@ static void __exit vfio_cleanup(void) class_destroy(vfio.class); vfio.class = NULL; misc_deregister(&vfio_dev); + xa_destroy(&vfio_device_set_xa); } module_init(vfio_init); diff --git a/include/linux/mdev.h b/include/linux/mdev.h index 3a38598c260559..cb5b7ed1d7c30d 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h @@ -111,6 +111,8 @@ struct mdev_parent_ops { int (*create)(struct mdev_device *mdev); int (*remove)(struct mdev_device *mdev); + int (*open_device)(struct mdev_device *mdev); + void (*close_device)(struct mdev_device *mdev); int (*open)(struct mdev_device *mdev); void (*release)(struct mdev_device *mdev); ssize_t (*read)(struct mdev_device *mdev, char __user *buf, diff --git a/include/linux/vfio.h b/include/linux/vfio.h index b0875cf8e496bb..128b4db00adc57 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -15,13 +15,26 @@ #include #include +/* + * VFIO devices can be placed in a set, this allows all devices to share this + * structure and the VFIO core will provide a lock that is held around + * open_device()/close_device() for all devices in the set. + */ +struct vfio_device_set { + void *set_id; + struct mutex lock; + unsigned int device_count; +}; + struct vfio_device { struct device *dev; const struct vfio_device_ops *ops; struct vfio_group *group; + struct vfio_device_set *dev_set; /* Members below here are private, not for driver use */ refcount_t refcount; + unsigned int open_count; struct completion comp; struct list_head group_next; }; @@ -29,6 +42,8 @@ struct vfio_device { /** * struct vfio_device_ops - VFIO bus driver device callbacks * + * @open_device: Called when the first file descriptor is opened for this device + * @close_device: Opposite of open_device * @open: Called when userspace creates new file descriptor for device * @release: Called when userspace releases file descriptor for device * @read: Perform read(2) on device file descriptor @@ -43,6 +58,8 @@ struct vfio_device { */ struct vfio_device_ops { char *name; + int (*open_device)(struct vfio_device *vdev); + void (*close_device)(struct vfio_device *vdev); int (*open)(struct vfio_device *vdev); void (*release)(struct vfio_device *vdev); ssize_t (*read)(struct vfio_device *vdev, char __user *buf, @@ -67,6 +84,8 @@ void vfio_unregister_group_dev(struct vfio_device *device); extern struct vfio_device *vfio_device_get_from_dev(struct device *dev); extern void vfio_device_put(struct vfio_device *device); +int vfio_assign_device_set(struct vfio_device *device, void *set_id); + /* events for the backend driver notify callback */ enum vfio_iommu_notify_type { VFIO_IOMMU_CONTAINER_CLOSE = 0, From patchwork Tue Jul 20 17:42:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12388987 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=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 51207C07E9B for ; Tue, 20 Jul 2021 17:46:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 397706100C for ; Tue, 20 Jul 2021 17:46:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231847AbhGTRGG (ORCPT ); Tue, 20 Jul 2021 13:06:06 -0400 Received: from mail-mw2nam10on2078.outbound.protection.outlook.com ([40.107.94.78]:22145 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232273AbhGTRCr (ORCPT ); Tue, 20 Jul 2021 13:02:47 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Qgk7cu2grfEN61Qg3mDVmBtQwxv+KxvVLdFpO43kcRlGVp7RcRA9vf8D8TvxHYN6tyLnDNLjtXN6iAvfgaC5Yn+J1dGgr8F93v6AtO933t4s9WV9PJ1Qa1PBR7eodr0SFVyHs5HGRkuH6O0gh+uxyIyXORMNOAJPGrrtFEFGLm4gvHDV5RmZ0ramxHDEUOxWlmuSnQiF86ZNBxQp8nvoxJ6fcQvENdAn5O3lnLNzNPiTIsinucUd6ktQvEKllyESlyjhO6cyL2k3fJX2HZEuxPY52PU79KOcqxbTJlzBjQTJKSkdcavZiBX5Lse/7WCq+evg2f5jSwC7yP7Spr3QAw== 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=qJfLcGqFvnMOejTizEycjE8TKphpeJPX5UeS8fmgFOI=; b=F894YODjpMgn1d1HGXTa97uiZUo5JFaHxhOtXTuoPwF3wtnrp8nIXkF95X2BE7ybblQrAFK1AwJwR1NJurNosYz9rtoX9WA3Gz5ZQ1NvlLrG2UVYWWj/9pVCYi3b6kJwgNENgopDr/jB3bUbslS0TY5LYBZYnNmR/XURK8eQvcyc1yn4KGQs3rpEU8efr+JSVEKFhr1QHmI3U7etdtURtmpu1GWyE13QPJuyQdQMmYKdyF8IUIdBlH9/xg3Y7P70IcRgN16RuK0P9xuJVELXFtH1utbfPMxzUw2VPD+5XdUEaeY0JuQAWMytV83vHSUSoGtdrMXiWGRv57XdeJY4GQ== 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=qJfLcGqFvnMOejTizEycjE8TKphpeJPX5UeS8fmgFOI=; b=K2rHcloLoDXpdh9KjldBw52toffZWGowutLCNrfdGOUd+M1KtcrCbjYHqTEMDsN9NISeLs8WN207L2LfDICvkt9ooZGV4+hHiPZSNK7c8SKRvUCQNo52x/Fw8R7traLdb/amMQop0WFlvOyr0Y7oGUCVLn+aJSuqBnXhz+5Pqe1uRo1gAcnTRFz9Wt+tKA1V6nd9Fw3pNH5XyExzvJeKjpEsD26mIaZ1yK+oz8zuTU05BGS/4464pDlGBm2EF6IsFGfNltm7SBa5wFSMyYsq9cvAWBtadEEjg0f//tPLDE4s7ud8zVyYMX1rWGZNqlcjqqzqO2K4X/8PygjjEXxRiA== 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 BL1PR12MB5288.namprd12.prod.outlook.com (2603:10b6:208:314::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21; Tue, 20 Jul 2021 17:43:08 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482%5]) with mapi id 15.20.4331.034; Tue, 20 Jul 2021 17:43:08 +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 Cc: "Raj, Ashok" , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Yishai Hadas , Zhenyu Wang Subject: [PATCH v2 05/14] vfio/samples: Delete useless open/close Date: Tue, 20 Jul 2021 14:42:51 -0300 Message-Id: <5-v2-b6a5582525c9+ff96-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v2-b6a5582525c9+ff96-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR02CA0032.namprd02.prod.outlook.com (2603:10b6:208:fc::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 (142.162.113.129) by MN2PR02CA0032.namprd02.prod.outlook.com (2603:10b6:208:fc::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Tue, 20 Jul 2021 17:43:04 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m5tll-0051Eo-Ab; Tue, 20 Jul 2021 14:43:01 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 52ba9049-3ce9-4124-4185-08d94ba5d3c5 X-MS-TrafficTypeDiagnostic: BL1PR12MB5288: 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: aSZEMWaDv9G+Uv9SbE4aqAAZSNe3QyOX6ex5OlRuPihzEy4mAKnAeKg8LJpwlSfEFNxBCoDvhYO1qUgteB6BYT9LWbTnWzUqEqDcnWLAfs94Us6qi48HgkxhjMlQG1WxsBgFVHUvXeQYmcjz3Dqn2Yfe9ViG4pCUhOKD1NTxqYRbm+VOBBmaoGiHF/smIQLtFNJPQOA1ihPls6ScbJqcG7vr0PqAMIXsN8vlA0jMbn+XGL88y1cRUJAm/KPVE193M1WuoYiKanm7r53vjLfE2szp7wVjkdAy8H0wGcZ+5pduTq/ubk+h88S7G0egkmqW0UKyQyyahCR76Cz82Jbw8cklwQhS53ik1l6TJLw3vUM5VZTQ7miIMEtmbXcyXMGXvTXcHFYnk6GihVqxXEjbitmbgLujq0I/j5quIzaAlwe9D5WSfzcEgF8884uG1crKssyApXoocjnmYEjbATlsEpOetawGCtPKmhrS/EY0dod09WF7OOFMHnlgPEttrdLSYrlkchM7zrXl9iT5rBHtNrv5AK8UjtYszOUP29F2auHnU9ncH+Jwehxzw7dTZdVSbpM1OFmpM19j7/BEGDqW/MwqsCAHS+Y+BlxU0YRt7p3261q9r+CEaaX69ABuiSR2JU2J9NAZUEceRkAAUpn8oy14SRvKaP9m2zugVdfq7LuOHgrqsBI/DjRh6ZhQgPNZ4cb1vSj84ROfY5+NAnu4ZQ== 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)(396003)(136003)(376002)(366004)(39860400002)(346002)(6666004)(66946007)(7416002)(7406005)(86362001)(2906002)(66476007)(54906003)(38100700002)(83380400001)(8936002)(316002)(110136005)(478600001)(36756003)(66556008)(186003)(26005)(5660300002)(8676002)(921005)(9786002)(9746002)(4326008)(426003)(2616005)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: p+QIxOPQiJHgpTDxWeyeR3bUcWxFWFAhKXI7xD5Gn5zEzCdXGixN+HKs3vKaqEUtisqHQ4yfrtXvN7vaKakN8jxXKLM6av85swgt2TifjocJrbsyrK3oHHXdorhUzoRB9W5ry/v7j6TRK6j0zRf7VcqN7Aji1D1u4Vjx/0T9atxZNT5Qr5Dugz8jLuKLT8NbuYom8XHvcLMyLLSnDvOY8LnpB61lQt9WoYTMcIplxDpyE6u9DjfKq63jF0uDwPMIRZLBpCI5gjrjgm1+8z0RdhFSLIFgNvFN3jckaqHs6H0CrJrTgfSfhQ/OTlktNxbhVMe99IKgRzZNoSy1N3IASN5D8HHWIKUtdwvbDCLF2DGtkk9XXKk5eByoEGJ0rouDHH8Qf4SVdaeblLwRYAt2Na45FSrNHUNhVIEpR2qeUQURrskXNBRgWtupSCjnHmEL8YiSeM3ALjNzO+rWQLZ8oggx+5NG+xICLFkPMu2fwD4KtOXHgZ8tT7Vc81C8whulkNcXkDIG4od81r1NYJVzHbALEQbquvBiPteR+VnJN4wpsQcHY8S7G2GCU1MHPb1aQn6cstiGJ+KnvTyXN/hRUDHRCTBH9v7w3LRlY78+UrawfMdOrp73uhg5mWPuu2vdjArfG8HlAyx9nHpeFySk7UMyQDK0/In9YXNInPDWX/Dw0hZXdMdYIRRzS8FM8fDjTiPgyZhSoIuX7g1B5q/Z6tQW7f6frfGuPJkV5sZ1lhK65dPfBGXI52YK+JF9amfXRyo93rPpPoY32COG3xkfyg2zavrK7rPQR+1cSS8Hhcw2SBmkvJX2qL2VFcMLjcSurN0idXndhg4uC8OHhT3c9AuXnXeXAXNWmWeqdiLvOH0jAwG9UITFU51v5jzjGs9iZwotLgIhvFManx5mByBLeWeFNSx/R+gPZi6nkoUuT+0OsehMV2N3M0l4ZZURzWX6PPalMcYb3QQjHUMVhFiT224fbPtKk4kal6M7M0V3HqP8S1/mGqUZJZqlgnwJvIz/nVA3VNUXjDQNBOtGaryDIB+Obq2w3up9KxR6QtJS+Uzttq3D0t9DcKXm2NKjZO3NAwdxUh4GTiZ/JGOKxHBD3AWs85T+sgFvRWckKXfGwZHXf4T+FJCY3b/kuwfzYY675zIe7M+32iJUsSJqmokpub9ybaJf9T+0dLRTY8ANqZIHK7fFS5uGsB2GXacZ5chOx7utGSGtB/lECAIfDKr5e4u8fLwFv07vI423dAosTI6B59qQuclTAXCgf4eDT3SYpZghCZfutWPW3vNF/X5SLDR5evOSpON/3JeJW66Is1EiDbt3Bzg1ePBxbw2CpB2V X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 52ba9049-3ce9-4124-4185-08d94ba5d3c5 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2021 17:43:04.6054 (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: IjiUhI8UnjYGro5TBze6Xx1i927ZS8L9YF/ceBXunuUamy+MaOljg9MaJqQeEzQq X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5288 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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 Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig --- 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 4ec4bc649351fc..fb81d11029e8a5 100644 --- a/samples/vfio-mdev/mbochs.c +++ b/samples/vfio-mdev/mbochs.c @@ -1277,11 +1277,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 = @@ -1400,7 +1395,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 Tue Jul 20 17:42:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12388971 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=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 BB6BAC07E95 for ; Tue, 20 Jul 2021 17:45:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A5F816100C for ; Tue, 20 Jul 2021 17:45:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231310AbhGTRFN (ORCPT ); Tue, 20 Jul 2021 13:05:13 -0400 Received: from mail-mw2nam10on2078.outbound.protection.outlook.com ([40.107.94.78]:22145 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231829AbhGTRCh (ORCPT ); Tue, 20 Jul 2021 13:02:37 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WLhHc8qA+J5ZxrZBJnUKJMZ9x8w3cvSF7ek0+emdfJLmCITPui/UNkDiYEyhQubpDNU7t02DchP2FDlNbLGJ/Dv/aTjX0hzKZXw6KIkI+rg/rjEpRO4BmsTEak0oQi72kyaCLBBdGngdYzslJEJ/h3CLH9Aanmnj4oNe0zVb4+HVEkEdAAtecq/cUrerTOdx0A2kYCwjHKpg9WxJpTMxinZ77NQYn0NZ0YKy7Lmyr1mhsKrYMli4AwiloKltaQR5lmJ22d9dEF6xGFy2/Z0mVSCsqeLFlKPM/n194rr/jMYlPIv7B/51MX6jDBH2nHO8GJshcF9hJ+eMHksEYfIIBw== 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=SEW6a736NdKyaz8Ax/GwfdrWAK5zGMeI/ZEa/De9Uqg=; b=Guf92MHxve/nJWd1p1yvmzXyJFNBoVMPrSBM9MieLis+7aA7lBntlfE3gbnnKIf5DaCHLqEgWoCVpgAlFTEYsRQmt9Ijy/phZN+upStXKo2txyPNWyRG9kFDe5iGhfFcdDEjx+vbP7yCbmNun4sKypY64SwZSc0OtcVLi3JTppVLUANPNARWcok/UVIZ5JUBF8lh4vdUcJ2BIcwuNJNsdHXfe/AQa3X4NzByFs2DS3mijnxMy5syOllQ2iwykPNUDI6RVOZLayeqxBpyp33z2cw4G8slvJ/rDJ+/tGxLSRoh2fPb+ztVrY8ZeDHLIuUi5T0pzErErtqFVd+MTm7R6Q== 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=SEW6a736NdKyaz8Ax/GwfdrWAK5zGMeI/ZEa/De9Uqg=; b=ktMLKVvGd5+VXn7q8AoXEu6RyMnP1RwSRAj8PTZW7bBjhlsUVYrT8iZ2Mn0HN72mVT9/4gJ20Bb7bT3oI5hELm/2CwGFWl3Clp61n5mrs1ySsGNHA7kkdfsnJd3yiKtmXmpcYgXFzlcWsyNPgxowdTEQIp9dAYkqiChysYDpIlRchqpZzNbVmvXz1EuYoVUqmGnKwBsAazb8eJ3VUl5T9FAX9d38XCO+8Q7NEag61lGwwPX3W9ob+/wb4yUSDAmgLcg2R7+iUj/AyNWu2YpmRONC7hxq09hO2Hge887XwqOQu3zso8D6mSbuMnN/vsfMZ0SeJTO0BfJoBMJXsr9HTg== 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 BL1PR12MB5288.namprd12.prod.outlook.com (2603:10b6:208:314::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21; Tue, 20 Jul 2021 17:43:06 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482%5]) with mapi id 15.20.4331.034; Tue, 20 Jul 2021 17:43:06 +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 Cc: "Raj, Ashok" , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Yishai Hadas , Zhenyu Wang Subject: [PATCH v2 06/14] vfio/fsl: Move to the device set infrastructure Date: Tue, 20 Jul 2021 14:42:52 -0300 Message-Id: <6-v2-b6a5582525c9+ff96-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v2-b6a5582525c9+ff96-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR02CA0015.namprd02.prod.outlook.com (2603:10b6:208:fc::28) 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 (142.162.113.129) by MN2PR02CA0015.namprd02.prod.outlook.com (2603:10b6:208:fc::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.22 via Frontend Transport; Tue, 20 Jul 2021 17:43:03 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m5tll-0051Et-Bw; Tue, 20 Jul 2021 14:43:01 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f3f49cae-f730-4f31-6f33-08d94ba5d325 X-MS-TrafficTypeDiagnostic: BL1PR12MB5288: 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: BMCVBIxl1tPZC7AqHGjiOQP/Bf1F6u07WosE3bFkCith7JLyjPGYEpTxg9Npq4Tvs7FlinbtaPP1GkjVdQzocMq4XN4WCorDcQ8W/xNZJF2rxnk8IGDgIObcn1HSEKr1bDuDYDuKYPSvyqByTmZBhBP2npK80/3E3+oV9OTKjPMsvXSOYbQDjgXLTlisskMpdkEwRK56x09g3eCHhiR8CIBHdXKz1pEr9C/BzePyKommLaB3kYA/h3KHfmRfLExjV2SnC/xX406bYk6kakuu7nSQCCfdyywmcyrLC31PnMhTZuWgTiK+YzDsoBYlndT3ja2Os3UKduPCv0M0cGJxjk+6qePzVJghwxCrsz9IDoLUaK26z5eiYFKq9/fYafVh5rB2kgb644GUmTBqTho/1EUpipbT2EOIxURqz5XcPnn5f+EfarpOTyGSTFJZeCJHRxvhTCOuEklR/n3Qlg/aVV8ipbz0m6yb2MR6giQX/lYHhzLUDEG7m1mEaqWMI+i5le9Xcusrca81EVT6WvdkLdZLflifZtYCQiTZKgMuIXXqW9d9e48bs7nCIkNX4rVtMWXnnpMom4Eo1Q/QRCRxqpS5Rzbb1yOmUI3Ft3Cv3uNRg9vQKjtw17BJKarkkkwJTGHOzSdxcJPX+rakePUgq+ZKJ9KaWKTc80sdxztHncu8fO5gKmSTMeyrc1Xk4FSlxY2auqwczWH77QlVeXC9TQ== 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)(396003)(136003)(376002)(366004)(39860400002)(346002)(6666004)(66946007)(7416002)(7406005)(86362001)(2906002)(66476007)(54906003)(38100700002)(83380400001)(8936002)(316002)(110136005)(478600001)(36756003)(66556008)(186003)(26005)(5660300002)(8676002)(921005)(9786002)(9746002)(4326008)(426003)(2616005)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 61TgUyWCIFUtOu2ZdaFX6DAhJbxStyjiYYXHU3xWA48xVa+hg9U+7sE+K+Om/+HlJyaCfcilE+7wD/GjAFHhq1hRxtipE7LYQFC/C1Nq7fa/oM+NCCh0CbQ4SolDsnnYvUxB0gWWunoUefjoRyrOH/4Nyu8uU4QVaR25jH4N72VIYqLj6MqbymhTFUIfPLnlL1m1/eikF4rd3JwXtFiO0BwCyIbDXaMeJWt2VF7hGRi2pUx2TV5s9c49Ddg+6RbAwFDEZsIH7+wCpxzFJDPLBUBCskUmucBZpx2CesdAEVj9Zul0BVJTtpunxL84Keup3pACpJgLUaJvThqKSuOTAqTApHxZY1PlzSDaMuXYBxBTeF1OFFyC2HhrMsDlRT8FyWsLu5y8aCXsUeaR+DMwVQMulZserxNEb/yvhLs5qJ8/mMt+EJIoRkp7d6KT6UZP1NWNlLaPcZRk3/w/tfUnbbZYdtdAmOSxbeQ89dLNjV6B2It6h2htEHCCypPVWOfdqoZxl8SDe6yFqO8AaScSwAVwItUuTdLYN9Ljj2MlMIdm45aBaUGUZo/MV5gUamgsvT6rOjfBamuBIdpo5nKmIA7EShKRbnHJHXDPGCa7gntsWBQ95GAUl3afTrg6IFDASmDwk4w4V7dpJ9l5TAho/jgvq0XKwXbYPD0FWzV+qHIfvA9OMcpLSisgzYsxAMZTJo334a9VvVPv65eunaWvkB0ke7uzg3jPbtSdeIXFPwbVLmw6j7Yg62IHcBsuXgKcvo4b/9S58BdT0U5z9fjOPfZR9ggfqV44KQUFk4KRWMfAazxJ5NB4eOP0LaTf+uFiS9nHm5MO27e8AYYRkd+/+HD1vNbPBIFb0JrCwnUOXJno8xBJkLQuyNaMGyE4XuXM5PbJSLXIT8yPFV6AlStal5q0xNjC1iAFOPBNHAaj9ffgvvjvM3MjG2jC8RdJAVE0VOpkCWt2etJ2VudDIdB/NbfAEnWvXVoi/s9SFJrqbAyCnhACPF971aKkky1Y/5tm5Yc/3ITbxsJk8Lxa8Ww1JjzNDltpXKv753fJ2ooyRddCgCuPiF03DHoiAK9WPFvzsp4hxmUTwxVVy8w3aheYRbAxHXIopZLZvcQU1SOTc6PnQ3COe00lBkvqBPdqSVxzj7tKlFvvXPhahow/e3xn3qSdPY+jLtSu5WD2XTbrA3mbdJNXQVc9SxJZ58gmTqJSw6edvKeWg/kgW5b8NMr5H8kj6/4u5RtrMX1Af/RnKxfB18fTmLpPxy3mZlMAOkYol8zKtWZkZLZFEQq6ETVX65BIbCsXmbbqq3yFFXDAFCoULeLp8XT3dhlFzF9OTfhL X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f3f49cae-f730-4f31-6f33-08d94ba5d325 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2021 17:43:03.6357 (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: nbVtbNW36/6IqLeSeAH2M7ByaS1sHP01aZshiIxsp4VCZ6eFlnLJB6Jq+ejXe4zH X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5288 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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 | 153 ++++------------------ drivers/vfio/fsl-mc/vfio_fsl_mc_intr.c | 6 +- drivers/vfio/fsl-mc/vfio_fsl_mc_private.h | 7 - 3 files changed, 27 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..0dc87a23a51302 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,15 @@ static int vfio_fsl_mc_probe(struct fsl_mc_device *mc_dev) vdev->mc_dev = mc_dev; mutex_init(&vdev->igate); - ret = vfio_fsl_mc_reflck_attach(vdev); + ret = vfio_assign_device_set(&vdev->vdev, is_fsl_mc_bus_dprc(mc_dev) ? + &mc_dev->dev : + mc_dev->dev.parent); if (ret) goto out_uninit; ret = vfio_fsl_mc_init_device(vdev); if (ret) - goto out_reflck; + goto out_uninit; ret = vfio_register_group_dev(&vdev->vdev); if (ret) { @@ -639,12 +542,6 @@ static int vfio_fsl_mc_probe(struct fsl_mc_device *mc_dev) goto out_device; } - /* - * This triggers recursion into vfio_fsl_mc_probe() on another device - * and the vfio_fsl_mc_reflck_attach() must succeed, which relies on the - * vfio_add_group_dev() above. It has no impact on this vdev, so it is - * safe to be after the vfio device is made live. - */ ret = vfio_fsl_mc_scan_container(mc_dev); if (ret) goto out_group_dev; @@ -655,8 +552,6 @@ static int vfio_fsl_mc_probe(struct fsl_mc_device *mc_dev) vfio_unregister_group_dev(&vdev->vdev); out_device: vfio_fsl_uninit_device(vdev); -out_reflck: - vfio_fsl_mc_reflck_put(vdev->reflck); out_uninit: vfio_uninit_group_dev(&vdev->vdev); kfree(vdev); @@ -675,7 +570,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 Tue Jul 20 17:42:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12388977 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=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 1F7DFC07E95 for ; Tue, 20 Jul 2021 17:46:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0958E61004 for ; Tue, 20 Jul 2021 17:46:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234264AbhGTRFe (ORCPT ); Tue, 20 Jul 2021 13:05:34 -0400 Received: from mail-mw2nam10on2078.outbound.protection.outlook.com ([40.107.94.78]:22145 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231954AbhGTRCl (ORCPT ); Tue, 20 Jul 2021 13:02:41 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H95dtuokBbjAII+RzM1qzHHs5B2yJJiVJU7ikGKfzeyF9+XGf8wFaXKrgsRTKqkIfTY5CbTm0AlOS2svoE5i3oWjHTXXWqGNBZc1oBYIPC7JdJqLs3Kgokb455j0RwmQMUG3tgDMXTF1TnwDFO3ldKNYAI03JKBEVZ/O3aHl0lTGZvl/NoL7tgIJ7phcu1c14d5AsKIN+qeSHFF1FuUnJx2zdZzEok21wOoj06K0iTFkpRiZSsf+QriF8d2U6ssonrr/maE3xDlrYWiofFu7oO4MWL9Um+H1tRli9GBLJVU132kVZHlHzYvtSt74UcB6MzBVYlXaFRPU6aOctSGwdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=g+yjMYhEcWEUEqiPJn9wZH0hUqIDhNY47wOx5CFzXys=; b=WNq9vkJbbNQMF9Jad8UPChE0g3m5AbZKGzdDc1nxU/tOkwravRPkdz2Kg1vNpz3gzK3hqw/1MZ/+7bucxMlJN7lpQtdGgHsDNW3+z+qRVM0pjcbIA4jFjMmAvvvWjrX5OosejvWfPwoH5JVMa6Y/Bn8u2YffHhqvZKG63EzdENVXhLM5eVDSu4bjnlZenVGuNqAj7FeRsmiu7WDR1L9FPT7QgaHPvcR2v9/+v/YDsq0B6AqUXlvYk8NFnfJKUC6f7zlQt69BN/JVuVX5YtlnT7N6B3soW9Xr8OjIp3D3/v1ZbKiuZm/8PM9NhtL/W87AZsBrCitub4IrXWUcfkxdWg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=g+yjMYhEcWEUEqiPJn9wZH0hUqIDhNY47wOx5CFzXys=; b=GuCbhUSeFVEix59Iho7swLzubqExHEjOySZKWE0Cca9fLpvkwUdDN77qS75C1K5ExisapaCTFUT9oYClLglV06YNhU2mCmHB17KFwS8XiRE14WW9xEFd5vyRndeYDJ5CeH01lTB1sjgOaqoslUpthLPtR1peqfoXeFiBhJW7RArk1JDJr6gJ9LM3WkHtDme1d6+Uy4kcudd1m/Z4p8QYUWK4FHGdF2z0CgIt3Iqrdg+564YugHs+IqQXZ5ZH42DmTPp+xCAUUySsD8CLQ0Ccfe/ybm7D/+Rsh/EOzfx+1fdUKNb1X2u01uMbCrEvoDzQEMjBtbn+5Y/2heVAi7I9AQ== 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 BL1PR12MB5288.namprd12.prod.outlook.com (2603:10b6:208:314::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21; Tue, 20 Jul 2021 17:43:06 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482%5]) with mapi id 15.20.4331.034; Tue, 20 Jul 2021 17:43:06 +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 Cc: "Raj, Ashok" , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Yishai Hadas , Zhenyu Wang Subject: [PATCH v2 07/14] vfio/platform: Use open_device() instead of open coding a refcnt scheme Date: Tue, 20 Jul 2021 14:42:53 -0300 Message-Id: <7-v2-b6a5582525c9+ff96-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v2-b6a5582525c9+ff96-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR01CA0028.prod.exchangelabs.com (2603:10b6:208:71::41) 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 (142.162.113.129) by BL0PR01CA0028.prod.exchangelabs.com (2603:10b6:208:71::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.22 via Frontend Transport; Tue, 20 Jul 2021 17:43:03 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m5tll-0051Ew-Db; Tue, 20 Jul 2021 14:43:01 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2129b992-d23a-491b-a332-08d94ba5d37c X-MS-TrafficTypeDiagnostic: BL1PR12MB5288: 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: EJ2kh/dLJCF9YqHKYAhzG7hoUIY55U3WmpOdcMfgICwMYkENzhXG0TA/ix9z3thldg7By/cUnryskFWHj5i8bxSn/Q0eJw3Hrx9NXVnPAUFsbzXfL0KAfL9rr4dT+CLoFKff0pi8KwLbM9cwJmSiTwzTpeasuOAARhwzl2NwmMirtYdzbrHJB4atQpvXy1hlKcODQFbNXpP+6sRxvQs84Xc5xrKRKXlNvHmOzJJMePreg6xo3Q6BUgMaK4kHhDYflxfCA0BXRJMjpuSMrJMFh735Cr6wHkD0+GyM17ZkKG73GTEjxYL0JlFNAsM8aMX1vdI4qsFiEBIUw0BAHrmJEk2iFoT6js9KC+6siSzHAYiV2S6Tr1RuL5nen/avGteRxJAM4cTdOC3tMOV4cxQ5n0s0gCqRY5l2QCnuKkruM8AKF5GEB2nXLZCHvkCkrs57ZGj6vPtURRiJ4KxsBSvKjzeQiPuUkdXA1W8GWol6xwtyN/os5ZJpXb6n+A9bXw5Ml2m0+qGsPr70kAg4OEQci1olpduNzLLMyAX8m9ZxIA0aXeOG5iWyk2on23T7gRmBYhL/NItKTxuQLiEc7EnUdo5oSmRoE2ze/CpVhjVeZ6Y+MHSoxDJQvNoOtycD5mcPLfBDbL9KHuMBFRnGfDBoEdpKs2Otmox8aU1QlYvoH4Bkcgoff1Jjx2DsBRNfwhUdvOQ5OZrnIbQ3OXo2mp2lGg== 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)(396003)(136003)(376002)(366004)(39860400002)(346002)(6666004)(66946007)(7416002)(7406005)(86362001)(2906002)(66476007)(54906003)(38100700002)(83380400001)(8936002)(316002)(110136005)(478600001)(36756003)(66556008)(186003)(26005)(5660300002)(8676002)(921005)(9786002)(9746002)(4326008)(426003)(2616005)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: kjWwm5rC2V4+w8AmXDRx4SBAnGgZE5lpUud4hifjFUhiu8e/JDiROG2dlk8QXbmgtTKW5uwn/GziS39lewOj106yiDmJy3DbTDnKU8ZAfvY26muCYdcgoWuo9sDv7SsgAPsb4TDIju6V9ow20ncVIFG3oQjNbMakvmX27AMenDUgCrGefzMXGuM2jfZPNfu36WivqCLupHdG89KLz/oIZzUoAhZPF3noxtAClQf2ViogfdgiCi7ComdA0q7s6oSr12bKJ1TLlxRlD0nVxHEHBlmdDpyNY5WUqucm7zQ2/rbQHYTxCEfgPhq8OxtdAE4II+kZhefoCsrz69T7aaNae2Ou4An16tfXULfNAzD9IKYjrTlumZEP/Nu4nCn222q+regWG4i13t+ONbiBBkrQQhV94s+hKTPvoh6q+3VQuJlwN6W/ZFmor89fAmGvdt2RYOG0ZoMWWNWd1wUwyz9XiObDZ8l682jU6sMRHjRFV7Q2c0eCPGMZcwoArwRU50j9e3f614H4k+fAgfiV2ql6rf7le18IvlSVgcD/zd9s1i5RXOFUtIh+arkzvgKir36+gyzN63hjjnyoNJKe8Sm1OfstIoj6c2MrotU5QBQiG2IMuW9AlwKZ4fSdb8vFJFs04T+4bqNbpReifMQv6qUonvM/BWi+FFMNDUWkqpat0Zo2iA1XUXG3n392Fqro5pKIy9n1uHJFwCysZbHJKjalvTrXcqXAxhF0PqFpoUlsE2hQ8rUCbMgmkR855gM2dEA9+4IRr0Xlc0xx1ZrWdyN58047lHAFFjPvc0iTclZl4035eXP6etG3KaNW2b/2reVOV8wodB2+67r/oEXPlmI4xiOG+IQhZLLM/tT6ezb3dHNJm57EXLzq8sbsxlTmNvwGHbmRvaEBL4Y5wBaFcO9LEClxdVpjNQH6gRm3WEnZ8QC0ARmN0yK3OZNFok2WALK+oiUeQsdojuJ276e/qYNcLKll55uSRpcHQrs5VI0dEsjoT96dzkb6x5IyDh8bMi16Hw11dHIk+ulzjbM5HDoLGavoEQ1jakqfv0Uo2QXayZkOETeY6iaIckFxWguAZ+gsoBCnp0Yu2uncWUVI9ZhTFExZFuf7SdINcXfsV51uUGttHk7Qa1eF1M8D8sDnnPAb+nW4aspcMdXAZ+kPyAMO7cWHrbDi+3Gp1B7ItRY7m+zVlrX18kQ8hLs5GYN09w8Ad677FZV3/mqUVyncskoCmVlgP1/3xXwOfdRbi89LcFFrYd9j1KFrpU+wz8xn+mAzzB+S1j6u48oTov4RVcBh5eDk1bZ3LkYbv83/Lych8KA99R6MPhH6LkbcZo+AH5hH X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2129b992-d23a-491b-a332-08d94ba5d37c X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2021 17:43:04.1206 (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: ABir0nK7RzyTFx7sj1+Fx64SmOkxI1KZGLwFuIvTKOru33dulJOCJcMtIOVsRUtw X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5288 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Platform simply wants to run some code when the device is first opened/last closed. Use the core framework and locking for this. Aside from removing a bit of code this narrows the locking scope from a global lock. Signed-off-by: Yishai Hadas Signed-off-by: Jason Gunthorpe Reviewed-by: Cornelia Huck Reviewed-by: Christoph Hellwig --- 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 Tue Jul 20 17:42:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12388983 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=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 87C64C07E9B for ; Tue, 20 Jul 2021 17:46:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6D73B61004 for ; Tue, 20 Jul 2021 17:46:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229536AbhGTRFs (ORCPT ); Tue, 20 Jul 2021 13:05:48 -0400 Received: from mail-mw2nam10on2078.outbound.protection.outlook.com ([40.107.94.78]:22145 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232356AbhGTRCu (ORCPT ); Tue, 20 Jul 2021 13:02:50 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H+Qq6Ben4Myo4RFSuFvhUwVGYnSlNfoALBcmKgLBzIlfN9W1ICLU0AIUUMVmnZBPE342A92kJ4y5BvV/BgxBCPXMRCe6pugL1YnXu6dVeq4/Splu0+2+s4J9oGWeQ3/fD3BnWQly8Rqsk9+lodKymj8rDefJqzMZWRsjhyR7336zsfb/lwsTwaGiFxGjzDLRR4/iM4i46vds3LoyIzZgh1xXstoHWD66J7//vXssU9jplmHMdi7yD/r/+YblifkMhZuFdBn5COCYnB5a7jAgAr4zCrd8wCN6Bl5lFiUEUF7gRnDdZd/vSv0eBrojH7lbyx/HG9ABsmuVf4uD6BFqBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pfSzLrWx9phOGS1Ir9TXtZygWdUrRCe/TL6aPalVd/Q=; b=naZ8PO8Q2F08DWB9vhd0Bs0QGkdGoCNIcuP5DaGo7o/zmZ8zjbonUaLfD2XMr8V/B/k+sbdLL9E84I5aY2tkYW8u3bkWVr2Wz0mG1/kV9YT3Wx27SFS/7HYTek1Mepoy0QOW0H9FP+dq3OVisMsZ0Gvcd0wGBW0jqr9HlgTDN/Y+mJPC9QUve3ceiXyvmxt4XDKwwHDvbLJLmpplO3eApDrkbNZbDWyGX1fd5SOOolOl19MW/XVNYsmlpxkA7xsPCopvoDkbwTf8dwXFzmDmgIZTXjVeyDzn4x+vQRGfceHGqxHUFI37fJ/T3Oi4woOrQ3UVD7/w7js+UlyW2SRgNA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pfSzLrWx9phOGS1Ir9TXtZygWdUrRCe/TL6aPalVd/Q=; b=uqS3jydPp6CFFFfeulhVfFICWZuQbJXbAZAkw9vaxceKDB9ccF9XeymSCNGupCL2P17Nbzkw/a0zEm6/NHBozsqPcemcZkHvZJjz2p5YkYTBc+WG0w7wpG2lulArHWdCtEueSQyEbk6rQ4KvMESEN/cc3KnPZ6kT1cJaS2eGu5qktN3r4qRWAgelC9j8gzg7O1NBDTGo6Cxi4N4ITkdIChMtWg8VcBkE2hZuAT/23yb2JDMJEuV7jOwGlDFAggnC+CSu/1F6AgTr0DilLj9BCQ0oKan4xVFHh4iADIHo8xzhVR5uw6tpCYoateActycg4tC2Orm87YhbLGWvSJliCg== 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 BL1PR12MB5288.namprd12.prod.outlook.com (2603:10b6:208:314::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21; Tue, 20 Jul 2021 17:43:09 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482%5]) with mapi id 15.20.4331.034; Tue, 20 Jul 2021 17:43:09 +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 Cc: "Raj, Ashok" , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Yishai Hadas , Zhenyu Wang Subject: [PATCH v2 08/14] vfio/pci: Move to the device set infrastructure Date: Tue, 20 Jul 2021 14:42:54 -0300 Message-Id: <8-v2-b6a5582525c9+ff96-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v2-b6a5582525c9+ff96-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR22CA0019.namprd22.prod.outlook.com (2603:10b6:208:238::24) 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 (142.162.113.129) by MN2PR22CA0019.namprd22.prod.outlook.com (2603:10b6:208:238::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Tue, 20 Jul 2021 17:43:04 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m5tll-0051F0-FS; Tue, 20 Jul 2021 14:43:01 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7fa1c241-3e48-45ad-54ff-08d94ba5d41a X-MS-TrafficTypeDiagnostic: BL1PR12MB5288: 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: NQScLqjlmub14XzGHQmXkFB2AG1TZeGB+uUF5xcTGN3upzyQLXhndKb/rwj4jRFhIUoqRLPEK0wCTZXE8sWelDmJM4GsVJ/ixbATiPeTg8gkTHOxeFrkvPo/RDPoin78fCjlQ/1O/Jjtkh7nMohLxJ/pXlnUtWYb1hrgTOmm3lDUIBGahb0TfPsdg8Gb6iU20uiN6xeCQEGsJAS7K/ATsXLMxpmYnDLrH6sNMaz3Zt4kXrzU7RtxJsCXMjmChu0719Cfz1LeZOEqNgFH0NAjGz9rCWZm3jpuSIAJVhFAD4AY0zYLEYecE12+v3lLz+CxqVyPsjtmFC2NhWNl48WTeVf3lCyRip0sO73IB+HSeAWQoweYzg44i1fqIn9Lnv2E94BVZDbV3gA/6EEDRd97OFZErP+f6krQUq2oKgNeTzAPbd90dR/65juyeO26fjTxPCvqBwikggWjLL/aB7Zpjclftycf6u21qK5+mEtPySQ/YsobE6cl8g/K44LuITtmbQpMQsjNRyFU/+17v76isgJXP81KYOWPcQC2J+lh44tFcYgcvEJwtu7gW+DnQM5KWZM/5mnvynN/8PNbzXfv5NNBfAKoybiyLXdUd8dQxqQ1a9C2v7fRsSnlijnuulYHJwR4wkkgRdodSZsRFkf/PasDjTuFLREe4jftQhXt71iFMbpbk7Oct368K+A0iJQlXlpAQ19+BMxZdxrA9CjlPA== 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)(396003)(136003)(376002)(366004)(39860400002)(346002)(6666004)(66946007)(7416002)(7406005)(86362001)(2906002)(66476007)(54906003)(38100700002)(83380400001)(8936002)(316002)(110136005)(478600001)(36756003)(66556008)(186003)(26005)(5660300002)(8676002)(921005)(9786002)(9746002)(4326008)(426003)(2616005)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6xjNzB7o+9Uy0NQZFdsNKoNfCea5TQnXLnvDrPF5apFsXiAI+49M9op7aiig+8sWMM9cNUjaiqh9sKAiyh6Og89NDGL2sBtDMDBJl3YcRTwgbqKi2q1VdMrA7bnj6Ro8oMh70RMTtKptFCOznHmIwjzVFNKMeY2eDDKk7ELVdDBkKgDCYWnrPVaS6HhOuBO7kGgrqd1WQfXoYi7YgjdpseCRsYitky2RooociU+JObLTzLYhpw4KoccPrWZkFEeL+YyJ/WQIy2l0TVSzQkrqw1lXI+53RFSpuCoaOyuyg7pEAVI19xH1aBnIZ6I9xKoWn7TMQbJezDWHL2m+ei60xwcwa9TO3N+/UJPUyTVFVKlSgIKDzDd3APfV2vossimbGlhT6ODFzvg0tqcnq2nHj9Z0tnlFhqxMBNOk4BivHgqCm/3Cg+lb5zxtmaF6Gr4nVGukoL3yLybKt63jlk1HSxZ4QkPDZi+T6UAq++PB+CfaHZQAsC1tRjYu1QwjxJQ4jMLrQvoNMsATAoRNsJFcoNHznVivXEI2QhIDBc6G4apbPRscUT79DzsQBEqnvMS+EAIMVOT4MmLYdxxqJiQdrlQAJ9V+YctMuHi0E53w1F7RpGZ70JsS9nSSYWMW7aeiNqwYAgAQFnqsccStzhz1e92gbsnPmB9+HHbkgKDafc/8ndRLLgCwel2qcJjAScL9mzRqwm6t46W0rcqPnyOYVYno1OpoxEVOZzK4rzrVvNS7cHMwnkK8Tj/7LPWy+mXJN2s1VtHQis79NcpKdWrL7gvd/edrW7stykbK464dJEbkAB0etYvX74ndElNYgm4yOuISibMori2E1MbzJw1aUT3Te8Duej3OEDpUWpblexaecsxc8WMjoYA/nd8lTKFwo/8PLhxss6tJyglaAwYNxFA2th8choXtoN2g3SR0UCoBpo8UthlUAeJoajmb/ZFEVoLmgBMm6Qs5pB4spYz0VPv/tgjppaK/lH+SeyoIcUctacRGRnBSvMssIl9R/+z4sQGNWDAzZl8cFzDg4zyGqvue6xjpc8J64TIG/a4KC4D6HRpc6fw6MDJG6CoYbtjouS1UOcsMSs8KuUlpJqUrdsA5x0jxG+6/SCq+ALirwlMS3X0JIJZuzsf6yv3GE6GYdIIPERFLHHgt5jlo1TVXZwVVU5IJYLbKJHFgrjMrnfNfjnqYRvwX5ElJANPqB0i699Uy/qIRyDhK7meYajLjGH2HwypzqfDKX2Hi5qApN1j6KQT/28thZiOREmKV0e9RT6QaUai9V71coSfEciSrL26XmYZtmoz5TJ6UDw22PqyXD0U89pjUohu6HVtfD//O X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7fa1c241-3e48-45ad-54ff-08d94ba5d41a X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2021 17:43:05.2546 (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: HHyqU1DnSFmxUIS//C/QfIQw0YOx3AcbwqzQrvq+jW2YhQ4PZ8uirg3AGXwNNImW X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5288 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Yishai Hadas PCI wants to have the usual open/close_device() logic with the slight twist that the open/close_device() must be done under a singelton lock shared by all of the vfio_devices that are in the PCI "reset group". The reset group, and thus the device set, is determined by what devices pci_reset_bus() touches, which is either the entire bus or only the slot. Rely on the core code to do everything reflck was doing and delete reflck entirely. Signed-off-by: Yishai Hadas Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig --- drivers/vfio/pci/vfio_pci.c | 156 ++++++---------------------- drivers/vfio/pci/vfio_pci_private.h | 7 -- 2 files changed, 31 insertions(+), 132 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index fab3715d60d4ba..22774e447b5f4a 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -530,53 +530,40 @@ static void vfio_pci_vf_token_user_add(struct vfio_pci_device *vdev, int val) vfio_device_put(&pf_vdev->vdev); } -static void vfio_pci_release(struct vfio_device *core_vdev) +static void vfio_pci_close_device(struct vfio_device *core_vdev) { struct vfio_pci_device *vdev = container_of(core_vdev, struct vfio_pci_device, vdev); - mutex_lock(&vdev->reflck->lock); - - if (!(--vdev->refcnt)) { - vfio_pci_vf_token_user_add(vdev, -1); - vfio_spapr_pci_eeh_release(vdev->pdev); - vfio_pci_disable(vdev); + vfio_pci_vf_token_user_add(vdev, -1); + vfio_spapr_pci_eeh_release(vdev->pdev); + vfio_pci_disable(vdev); - mutex_lock(&vdev->igate); - if (vdev->err_trigger) { - eventfd_ctx_put(vdev->err_trigger); - vdev->err_trigger = NULL; - } - if (vdev->req_trigger) { - eventfd_ctx_put(vdev->req_trigger); - vdev->req_trigger = NULL; - } - mutex_unlock(&vdev->igate); + mutex_lock(&vdev->igate); + if (vdev->err_trigger) { + eventfd_ctx_put(vdev->err_trigger); + vdev->err_trigger = NULL; } - - mutex_unlock(&vdev->reflck->lock); + if (vdev->req_trigger) { + eventfd_ctx_put(vdev->req_trigger); + vdev->req_trigger = NULL; + } + mutex_unlock(&vdev->igate); } -static int vfio_pci_open(struct vfio_device *core_vdev) +static int vfio_pci_open_device(struct vfio_device *core_vdev) { struct vfio_pci_device *vdev = container_of(core_vdev, struct vfio_pci_device, vdev); int ret = 0; - mutex_lock(&vdev->reflck->lock); - - if (!vdev->refcnt) { - ret = vfio_pci_enable(vdev); - if (ret) - goto error; + ret = vfio_pci_enable(vdev); + if (ret) + return ret; - vfio_spapr_pci_eeh_open(vdev->pdev); - vfio_pci_vf_token_user_add(vdev, 1); - } - vdev->refcnt++; -error: - mutex_unlock(&vdev->reflck->lock); - return ret; + vfio_spapr_pci_eeh_open(vdev->pdev); + vfio_pci_vf_token_user_add(vdev, 1); + return 0; } static int vfio_pci_get_irq_count(struct vfio_pci_device *vdev, int irq_type) @@ -1870,8 +1857,8 @@ static int vfio_pci_match(struct vfio_device *core_vdev, char *buf) static const struct vfio_device_ops vfio_pci_ops = { .name = "vfio-pci", - .open = vfio_pci_open, - .release = vfio_pci_release, + .open_device = vfio_pci_open_device, + .close_device = vfio_pci_close_device, .ioctl = vfio_pci_ioctl, .read = vfio_pci_read, .write = vfio_pci_write, @@ -1880,9 +1867,6 @@ static const struct vfio_device_ops vfio_pci_ops = { .match = vfio_pci_match, }; -static int vfio_pci_reflck_attach(struct vfio_pci_device *vdev); -static void vfio_pci_reflck_put(struct vfio_pci_reflck *reflck); - static int vfio_pci_bus_notifier(struct notifier_block *nb, unsigned long action, void *data) { @@ -2020,12 +2004,17 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) INIT_LIST_HEAD(&vdev->vma_list); init_rwsem(&vdev->memory_lock); - ret = vfio_pci_reflck_attach(vdev); + if (pci_is_root_bus(pdev->bus)) + ret = vfio_assign_device_set(&vdev->vdev, vdev); + else if (!pci_probe_reset_slot(pdev->slot)) + ret = vfio_assign_device_set(&vdev->vdev, pdev->slot); + else + ret = vfio_assign_device_set(&vdev->vdev, pdev->bus); if (ret) goto out_uninit; ret = vfio_pci_vf_init(vdev); if (ret) - goto out_reflck; + goto out_uninit; ret = vfio_pci_vga_init(vdev); if (ret) goto out_vf; @@ -2057,8 +2046,6 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) vfio_pci_set_power_state(vdev, PCI_D0); out_vf: vfio_pci_vf_uninit(vdev); -out_reflck: - vfio_pci_reflck_put(vdev->reflck); out_uninit: vfio_uninit_group_dev(&vdev->vdev); kfree(vdev->pm_save); @@ -2077,7 +2064,6 @@ static void vfio_pci_remove(struct pci_dev *pdev) vfio_unregister_group_dev(&vdev->vdev); vfio_pci_vf_uninit(vdev); - vfio_pci_reflck_put(vdev->reflck); vfio_uninit_group_dev(&vdev->vdev); vfio_pci_vga_uninit(vdev); @@ -2153,86 +2139,6 @@ static struct pci_driver vfio_pci_driver = { .err_handler = &vfio_err_handlers, }; -static DEFINE_MUTEX(reflck_lock); - -static struct vfio_pci_reflck *vfio_pci_reflck_alloc(void) -{ - struct vfio_pci_reflck *reflck; - - reflck = kzalloc(sizeof(*reflck), GFP_KERNEL); - if (!reflck) - return ERR_PTR(-ENOMEM); - - kref_init(&reflck->kref); - mutex_init(&reflck->lock); - - return reflck; -} - -static void vfio_pci_reflck_get(struct vfio_pci_reflck *reflck) -{ - kref_get(&reflck->kref); -} - -static int vfio_pci_reflck_find(struct pci_dev *pdev, void *data) -{ - struct vfio_pci_reflck **preflck = data; - struct vfio_device *device; - struct vfio_pci_device *vdev; - - device = vfio_device_get_from_dev(&pdev->dev); - if (!device) - return 0; - - if (pci_dev_driver(pdev) != &vfio_pci_driver) { - vfio_device_put(device); - return 0; - } - - vdev = container_of(device, struct vfio_pci_device, vdev); - - if (vdev->reflck) { - vfio_pci_reflck_get(vdev->reflck); - *preflck = vdev->reflck; - vfio_device_put(device); - return 1; - } - - vfio_device_put(device); - return 0; -} - -static int vfio_pci_reflck_attach(struct vfio_pci_device *vdev) -{ - bool slot = !pci_probe_reset_slot(vdev->pdev->slot); - - mutex_lock(&reflck_lock); - - if (pci_is_root_bus(vdev->pdev->bus) || - vfio_pci_for_each_slot_or_bus(vdev->pdev, vfio_pci_reflck_find, - &vdev->reflck, slot) <= 0) - vdev->reflck = vfio_pci_reflck_alloc(); - - mutex_unlock(&reflck_lock); - - return PTR_ERR_OR_ZERO(vdev->reflck); -} - -static void vfio_pci_reflck_release(struct kref *kref) -{ - struct vfio_pci_reflck *reflck = container_of(kref, - struct vfio_pci_reflck, - kref); - - kfree(reflck); - mutex_unlock(&reflck_lock); -} - -static void vfio_pci_reflck_put(struct vfio_pci_reflck *reflck) -{ - kref_put_mutex(&reflck->kref, vfio_pci_reflck_release, &reflck_lock); -} - static int vfio_pci_get_unused_devs(struct pci_dev *pdev, void *data) { struct vfio_devices *devs = data; @@ -2254,7 +2160,7 @@ static int vfio_pci_get_unused_devs(struct pci_dev *pdev, void *data) vdev = container_of(device, struct vfio_pci_device, vdev); /* Fault if the device is not unused */ - if (vdev->refcnt) { + if (device->open_count) { vfio_device_put(device); return -EBUSY; } @@ -2303,7 +2209,7 @@ static int vfio_pci_try_zap_and_vma_lock_cb(struct pci_dev *pdev, void *data) * - At least one of the affected devices is marked dirty via * needs_reset (such as by lack of FLR support) * Then attempt to perform that bus or slot reset. Callers are required - * to hold vdev->reflck->lock, protecting the bus/slot reset group from + * to hold vdev->dev_set->lock, protecting the bus/slot reset group from * concurrent opens. A vfio_device reference is acquired for each device * to prevent unbinds during the reset operation. * diff --git a/drivers/vfio/pci/vfio_pci_private.h b/drivers/vfio/pci/vfio_pci_private.h index 5a36272cecbf94..ae83c2eada3a64 100644 --- a/drivers/vfio/pci/vfio_pci_private.h +++ b/drivers/vfio/pci/vfio_pci_private.h @@ -83,11 +83,6 @@ struct vfio_pci_dummy_resource { struct list_head res_next; }; -struct vfio_pci_reflck { - struct kref kref; - struct mutex lock; -}; - struct vfio_pci_vf_token { struct mutex lock; uuid_t uuid; @@ -130,8 +125,6 @@ struct vfio_pci_device { bool needs_pm_restore; struct pci_saved_state *pci_saved_state; struct pci_saved_state *pm_save; - struct vfio_pci_reflck *reflck; - int refcnt; int ioeventfds_nr; struct eventfd_ctx *err_trigger; struct eventfd_ctx *req_trigger; From patchwork Tue Jul 20 17:42:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12388975 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=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 CD20EC07E9B for ; Tue, 20 Jul 2021 17:46:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B7C55608FC for ; Tue, 20 Jul 2021 17:46:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233421AbhGTRFa (ORCPT ); Tue, 20 Jul 2021 13:05:30 -0400 Received: from mail-mw2nam10on2068.outbound.protection.outlook.com ([40.107.94.68]:52928 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232054AbhGTRCl (ORCPT ); Tue, 20 Jul 2021 13:02:41 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dOot55sPUp9de/iPPxLhd0Jw/7RjBYYusHYytQoNoxArojD1pt91DtP46lZVFrUrZaTQmqE3S3oNxvtJUG8jBJ7bqF+bHENBhaJ1lrNb/zj6YgOAhoxjk3ads0EdxrIiKHPrY1fCmOTvFLhaBPw9z8n2G4RFMuUhNGZl7b65NNuPNQLbz/NUiAwWMO1NgMVBgQj4HEWm8tiV44LaGAB4bCAzERf8Lu51E0YkGwOFFFTAi3fKw98sfPSDyQfHvWD7Da5qYr54TVYJ58ijOqbCYyWUjRlcwwdPyw2zwpEEHKdPUtxvcej5YRYFRAyvasuRPulGSda8M97cbGSXg52nqw== 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=t0lNkTQD1vanlR/Ltc7GgcGK4VYeDxLnG7YEUFQ6P7I=; b=Tnt/YNe9YGyTYoYoImoo1vus+zWTdEPSygIoVnW5u53OEMpPLzeWFpW73kEdPopY49sN3eXxuio1r8r/RoxFonk09pbSG3uy+VYYm4iUrEUtrlbMOruU/sStQb3pW4Fa+K/0SMfTdqz05Evo5iA98AKTVMfb0vV3h4nNuq5eiBkuZWAEBQsb4fSI4T1+jXah+g8kP7aCZWlhidUhT7PX/g6QRf40Jt7piajQADVK1PhpU1QFto2GfB3UuxmwEe2vKOuxYeOYvk60NzXSO2j1EbWBx4eX/PlG6IhuuVJ6cwex6h6z+D0UFI5ebnFM5M85sQ+JqCxr8971WmmsSulV0g== 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=t0lNkTQD1vanlR/Ltc7GgcGK4VYeDxLnG7YEUFQ6P7I=; b=Drjt+NWC7uSB1ZJJd9rrbnXP4r9iFUy8mUSVbOPysxmMGcGUKix7DuXXdc/x7Dpab8ydHa7g+WXCksm+s/huQyaDD77aU4ncH7jJS1qh6WDC0aTGw8uXuphUYAKCpbBrviCa3+zL54NrsyTxgEbEcMAS8fgLQjR8VJ0AHz8LibQQ5xvb75VbnyviJHMl3a31p0SPe+mKiAehBGh67d3rC2E2aJgQb7K4O0zbGn83eoWKL6QfG/roNcTRFSNaJxPZNOOibt5snB77T4ZdRiI0eJ25zl3si5JBpGlPtDDX2IDfkLrDaQ+U7imETXYwa9Q/qwwk2v3Faf4RooCU19OJzg== 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 BL1PR12MB5288.namprd12.prod.outlook.com (2603:10b6:208:314::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21; Tue, 20 Jul 2021 17:43:06 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482%5]) with mapi id 15.20.4331.034; Tue, 20 Jul 2021 17:43:06 +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 Cc: "Raj, Ashok" , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Yishai Hadas , Zhenyu Wang Subject: [PATCH v2 09/14] vfio/pci: Change vfio_pci_try_bus_reset() to use the dev_set Date: Tue, 20 Jul 2021 14:42:55 -0300 Message-Id: <9-v2-b6a5582525c9+ff96-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v2-b6a5582525c9+ff96-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR02CA0016.namprd02.prod.outlook.com (2603:10b6:208:fc::29) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (142.162.113.129) by MN2PR02CA0016.namprd02.prod.outlook.com (2603:10b6:208:fc::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Tue, 20 Jul 2021 17:43:03 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m5tll-0051F4-Ik; Tue, 20 Jul 2021 14:43:01 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2f3a4786-216b-4341-b370-08d94ba5d37d X-MS-TrafficTypeDiagnostic: BL1PR12MB5288: 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: oCayBSaOlurHVP3RgZL2gg9gqdn1a6Xi0XukFsjtZGVzGHx3N+5TvdKz9cfT6iUTPBnGqtvgU587od6/hIqLOh1DKWZ9zIy40w71aF4Ph86U0caXlyGBBhecGeYM7eFqUFLP+rFVF1NzV4wv3EAXT7LqEbnpv7ALuDprcUwp/wlyyd8ojsiaz0xXVga1or5ORCRN0wyqgG17rJXXLrDXcK+w+PcYiGeS9sVZkvR2toZpjYNMIlyAuJtGgvvWk4habyMr6pFXyyWSBs/WDQ7lCxHWdVjVI7hnYWsBiBGsdA5Wo+ra1NZCerMzN9LpzmN6E4rUSrajpQrnZlrLrCZ40VkYUVWiiawvQ/mSuq/ppJjsMH4l0GJe+EJU4oG/vXiI34xMRkekUYqTrh42XXEQHRio+XTNq5XAnM2S5JpMy6dpjlE0oWyC5Vvn5Obo3QQhn1namQ6UHMd/0FFrqgZJBNKNTjFdHPI+kEqpVt1rm+DFeW6uigw3s1oYU1SzNtEQJn/+LgbH3m3VNx62TXQSynVbOTuvbcOKhwADpx3zepg0i3bFxA3IdtiKqoroQm2+Fhzih2S5SrHY1b7EsPVgK91dSMDJJWIfFRcPDRhPuD/SJWlxO719JUHNcrWvWoVlQbRzNdO22IKY2XZSRC+j4/XMZp5/os7t5tf1teWW6pgfB3bN4ZHb9w7DM05O9uniZav7iUCyIXh56gMeRHeixQ== 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)(396003)(136003)(376002)(366004)(39860400002)(346002)(6666004)(66946007)(7416002)(7406005)(86362001)(2906002)(66476007)(54906003)(38100700002)(83380400001)(8936002)(316002)(110136005)(478600001)(36756003)(66556008)(186003)(26005)(5660300002)(8676002)(921005)(9786002)(9746002)(4326008)(426003)(2616005)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Uqsy6FaEsJykhpYzcxCmCpFT8zmxqiIXqUlH4SqP9k3YYrmnSNyBz9Swb3PPDx8JJnEbsceSuL0ghnMpSfu1ZxgT3AgYw98tGlvyHk+TUqYikkCqHQErpbx0xxAtIM+GU7Fat5jSu+tOya+gGIXKIuvbA+HmbxZwBk7piyoOc9QrBGek8bJb4hfYECNx4IShHhdbCobJP9GjwWUJO1PeTHQ8jrlMi9gpHjGI5IouZHyl9qBamxbLz/bLeEllPEgj0AMRxyAI/PV66JTRfgOlQpc8P82Os69mOGEsyD1/wqwvHm3S81owXZ2MVpXEHcZvL4nHQfB16HhDQFVO4ZlUdeOQrjmMcCHsDskeCtSRNVa3oGJw9ucNDQdQIR3k+EiOYj78BwOJ/Z6H3wQsyivIYcZzwGo71ho3QRxadJZFfklLZh8Fzyqr2y2uC2t35QyYoMSEft6JjlbH4DcPcNdmEuIwNrvVJSQHS+gZi6jhiudvl5trhSVdjw32vVqhAox4gmwA5crXuwBtZOQX2/ZKkeQY23oDIbWt1eUPK1hv7Q6QyrjbIzGmh5mZU3+nvHGg8WlqJWF3HRLf115IiaauukO5Vxto8raByUqfhk9tFsv2fJx1j9rZDn2SD1CNI1GkOgu4QgKXBP7CA8vMUx4tDrS7K3v0wkPxnrlt6w4KWlbjMBuR5eSQ3PBHYrMNZM7AP4KddrO+ax5AoyPm2l6forjaQX7hPVnCk+pEYS/PS/ANlNm7g3p7ktQS24ACjFKPqr+JDNRKbXW7vloqeTrhrIMeqffP+JVSM44iKSkz8X7+ZdXTAT66tp9+nfJoG/FAr1EofZ12Ooi3Eov4fsLsNOeCFz0KmGVlAuq1WNFKPRlVcLRy2yS0z82kjKnrinDOlbBcb4Xs3gCAr1MnoE92kTdVR0SnM4RagtyKfCquJDsMFu+HE7E4jQKY4yCoWPjfEXvXz0/x2xNixJB/+WE/NdhSzbCYpYoSkwigUkbc3Ti04ezsl4a4ig2J5B0dFBAkqveiKDnsrtBdmOTMBaItTzokgEdaohSopdve1hHqhCekh0RQzBupwlO9yD9nwQzCJzBtT+HmJFfywnJWuPGPRcmiGSxBofZmJisCw9N37stz0h7fboPifYdEOEqB9SlwkhNiWXxZq5xO0OGHAM8BQsUd/Z6L23LbRNOPKiveQzrdWWOuo8Trp4LeTl4OuiVjLO/ikXapTGaknxS0I6j9kobhPNJjTga1S1x0Y//Ff72tkjkIpJ/d3xRJIV0Js7PGG2wA8qQ6MMdzdxP91AtQ1Qk/XElqGmuX5s7XPfKwclvkAt7Tj47D0Y2GSVH2OH+C X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2f3a4786-216b-4341-b370-08d94ba5d37d X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2021 17:43:04.1753 (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: 1AoQE9gnktv0XmkWJQE5KwvwBvNW87dL8JTxLbKsFSZVpd1PyH1WxoIZwjw/6jxG X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5288 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Keep track of all the vfio_devices that have been added to the device set and use this list in vfio_pci_try_bus_reset() instead of trying to work backwards from the pci_device. The dev_set->lock directly prevents devices from joining/leaving the set, which further implies the pci_device cannot change drivers or that the vfio_device be freed, eliminating the need for get/put's. Completeness of the device set can be directly measured by checking if every PCI device in the reset group is also in the device set - which proves that VFIO drivers are attached to everything. This restructuring corrects a call to pci_dev_driver() without holding the device_lock() and removes a hard wiring to &vfio_pci_driver. Signed-off-by: Jason Gunthorpe --- drivers/vfio/pci/vfio_pci.c | 110 ++++++++++++++---------------------- drivers/vfio/vfio.c | 10 ++++ include/linux/vfio.h | 2 + 3 files changed, 53 insertions(+), 69 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index 22774e447b5f4a..fbc20f6d2dd412 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -404,6 +404,9 @@ static void vfio_pci_disable(struct vfio_pci_device *vdev) struct vfio_pci_ioeventfd *ioeventfd, *ioeventfd_tmp; int i, bar; + /* For needs_reset */ + lockdep_assert_held(&vdev->vdev.dev_set->lock); + /* Stop the device from further DMA */ pci_clear_master(pdev); @@ -2139,34 +2142,17 @@ static struct pci_driver vfio_pci_driver = { .err_handler = &vfio_err_handlers, }; -static int vfio_pci_get_unused_devs(struct pci_dev *pdev, void *data) +static int vfio_pci_check_all_devices_bound(struct pci_dev *pdev, void *data) { - struct vfio_devices *devs = data; - struct vfio_device *device; - struct vfio_pci_device *vdev; - - if (devs->cur_index == devs->max_index) - return -ENOSPC; + struct vfio_device_set *dev_set = data; + struct vfio_device *cur; - device = vfio_device_get_from_dev(&pdev->dev); - if (!device) - return -EINVAL; - - if (pci_dev_driver(pdev) != &vfio_pci_driver) { - vfio_device_put(device); - return -EBUSY; - } - - vdev = container_of(device, struct vfio_pci_device, vdev); - - /* Fault if the device is not unused */ - if (device->open_count) { - vfio_device_put(device); - return -EBUSY; - } + lockdep_assert_held(&dev_set->lock); - devs->devices[devs->cur_index++] = vdev; - return 0; + list_for_each_entry(cur, &dev_set->device_list, dev_set_list) + if (cur->dev == &pdev->dev) + return 0; + return -EBUSY; } static int vfio_pci_try_zap_and_vma_lock_cb(struct pci_dev *pdev, void *data) @@ -2210,8 +2196,7 @@ static int vfio_pci_try_zap_and_vma_lock_cb(struct pci_dev *pdev, void *data) * needs_reset (such as by lack of FLR support) * Then attempt to perform that bus or slot reset. Callers are required * to hold vdev->dev_set->lock, protecting the bus/slot reset group from - * concurrent opens. A vfio_device reference is acquired for each device - * to prevent unbinds during the reset operation. + * concurrent opens. * * NB: vfio-core considers a group to be viable even if some devices are * bound to drivers like pci-stub or pcieport. Here we require all devices @@ -2220,61 +2205,48 @@ static int vfio_pci_try_zap_and_vma_lock_cb(struct pci_dev *pdev, void *data) */ static void vfio_pci_try_bus_reset(struct vfio_pci_device *vdev) { - struct vfio_devices devs = { .cur_index = 0 }; - int i = 0, ret = -EINVAL; - bool slot = false; - struct vfio_pci_device *tmp; - - if (!pci_probe_reset_slot(vdev->pdev->slot)) - slot = true; - else if (pci_probe_reset_bus(vdev->pdev->bus)) - return; + struct vfio_device_set *dev_set = vdev->vdev.dev_set; + struct vfio_pci_device *to_reset = NULL; + struct vfio_pci_device *cur; + int ret; - if (vfio_pci_for_each_slot_or_bus(vdev->pdev, vfio_pci_count_devs, - &i, slot) || !i) + if (pci_probe_reset_slot(vdev->pdev->slot) && + pci_probe_reset_bus(vdev->pdev->bus)) return; - devs.max_index = i; - devs.devices = kcalloc(i, sizeof(struct vfio_device *), GFP_KERNEL); - if (!devs.devices) - return; + lockdep_assert_held(&vdev->vdev.dev_set->lock); - if (vfio_pci_for_each_slot_or_bus(vdev->pdev, - vfio_pci_get_unused_devs, - &devs, slot)) - goto put_devs; + /* All VFIO devices have a closed FD */ + list_for_each_entry(cur, &dev_set->device_list, vdev.dev_set_list) + if (cur->vdev.open_count) + return; + + /* All devices in the group to be reset need VFIO devices */ + if (vfio_pci_for_each_slot_or_bus( + vdev->pdev, vfio_pci_check_all_devices_bound, dev_set, + !pci_probe_reset_slot(vdev->pdev->slot))) + return; /* Does at least one need a reset? */ - for (i = 0; i < devs.cur_index; i++) { - tmp = devs.devices[i]; - if (tmp->needs_reset) { - ret = pci_reset_bus(vdev->pdev); + list_for_each_entry(cur, &dev_set->device_list, vdev.dev_set_list) { + if (cur->needs_reset) { + to_reset = cur; break; } } + if (!to_reset) + return; -put_devs: - for (i = 0; i < devs.cur_index; i++) { - tmp = devs.devices[i]; - - /* - * If reset was successful, affected devices no longer need - * a reset and we should return all the collateral devices - * to low power. If not successful, we either didn't reset - * the bus or timed out waiting for it, so let's not touch - * the power state. - */ - if (!ret) { - tmp->needs_reset = false; + ret = pci_reset_bus(to_reset->pdev); + if (ret) + return; - if (tmp != vdev && !disable_idle_d3) - vfio_pci_set_power_state(tmp, PCI_D3hot); - } + list_for_each_entry(cur, &dev_set->device_list, vdev.dev_set_list) { + cur->needs_reset = false; - vfio_device_put(&tmp->vdev); + if (cur != to_reset && !disable_idle_d3) + vfio_pci_set_power_state(cur, PCI_D3hot); } - - kfree(devs.devices); } static void __exit vfio_pci_cleanup(void) diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index 8572d943320214..7e352d68b1b01d 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -129,7 +129,12 @@ int vfio_assign_device_set(struct vfio_device *device, void *set_id) if (dev_set) { dev_set->device_count++; xa_unlock(&vfio_device_set_xa); + + mutex_lock(&dev_set->lock); device->dev_set = dev_set; + list_add_tail(&device->dev_set_list, &dev_set->device_list); + mutex_unlock(&dev_set->lock); + if (dev_set != alloc_dev_set) kfree(alloc_dev_set); return 0; @@ -143,6 +148,7 @@ int vfio_assign_device_set(struct vfio_device *device, void *set_id) if (!alloc_dev_set) return -ENOMEM; mutex_init(&alloc_dev_set->lock); + INIT_LIST_HEAD(&alloc_dev_set->device_list); alloc_dev_set->set_id = set_id; goto again; } @@ -155,6 +161,10 @@ static void vfio_release_device_set(struct vfio_device *device) if (!dev_set) return; + mutex_lock(&dev_set->lock); + list_del(&device->dev_set_list); + mutex_unlock(&dev_set->lock); + xa_lock(&vfio_device_set_xa); dev_set->device_count--; if (!dev_set->device_count) { diff --git a/include/linux/vfio.h b/include/linux/vfio.h index 128b4db00adc57..f0e6a72875e471 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -23,6 +23,7 @@ struct vfio_device_set { void *set_id; struct mutex lock; + struct list_head device_list; unsigned int device_count; }; @@ -31,6 +32,7 @@ struct vfio_device { const struct vfio_device_ops *ops; struct vfio_group *group; struct vfio_device_set *dev_set; + struct list_head dev_set_list; /* Members below here are private, not for driver use */ refcount_t refcount; From patchwork Tue Jul 20 17:42:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12388963 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=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 A27F5C636C8 for ; Tue, 20 Jul 2021 17:43:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9674D610D2 for ; Tue, 20 Jul 2021 17:43:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232320AbhGTRCt (ORCPT ); Tue, 20 Jul 2021 13:02:49 -0400 Received: from mail-bn8nam12on2065.outbound.protection.outlook.com ([40.107.237.65]:53184 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231305AbhGTRCb (ORCPT ); Tue, 20 Jul 2021 13:02:31 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T7KCd/8uRiaYJmx5KNwE8bdNfb8mcWdDigm7vqcuXHOlJI1qJukMZps8/lLd38dm5OC9RiG4XbF+jCcDO9FxzUNQ2pmGqd3GcXLdhC+dL5YKAle4Q8+vvzvvIkiYrv3sIbOOgQuOWLcfVKF6GW5yS4xiw5UWEuYP1D2/I/KfiftPIzxzaptv0gjgsxjsVq/b3SzRXByTzLcM6g8Q95bg4SXQDxdyaRg63CyjeaolDY+rxTON/KoOfNwmXslmc7h+OjxpJeaa58eKdiIvZnwrl4LuzGB7lUzeEEqSKxskZ2MHrZUSjDebYuYxg2JrtDjefIU5FpHyVSLpROmBojkrhA== 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=gEvzYizSfsJwbm1T2H0hgeWCBiAJ2Bm/jPsOCB9m9j8=; b=H1o9ZK7zduUE3rBCjO9cD/cjjLpOU2AZQeSdqVoEgUTNS9K94+7O8dbSkq3lDJ/Je53yYYMdRey3JPvXBso1MlRD4nWVohkNn5jvlZaSSCJYjgUE3sztmv3W0RGAoa6g7cGn1DHpHfffgBfyD+kMBXKKxu7OtdfV1i3Tain2tKl3gSZ2aKgkZacEQ0ReTY5xdIZ6FnqvJCAqYeKeiBiAome1VfGjWtEO5OHxORdh4GWok/5eSqqdjFjo/UZ1Pph9IlOKv+PDqjkozqxSbDjENerDslrhlRXENGLKhemstj7uRVY94DzxTON2ODTE65daSa0eCgCtExuR6X5lVUenUg== 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=gEvzYizSfsJwbm1T2H0hgeWCBiAJ2Bm/jPsOCB9m9j8=; b=UOP14Pjsz8xUuIB8ccBV45F0FwM0ctLsbkH9Cvi9D0cAz1ZIpqpnCGVVjLIYKdBfARbjnDEYWHN6Xhb3oeFGqjp4GSSfbmWuJ4CvT0hIBd9OqcW53TS5vseyjdd1hTmxWX+tHSExmlz6q8UIzQ/GmBsGdF+3FLQ2UDIM23VGWvywEYnKcgsIW4VPdfqNP3IGzG+GaH4JC6w3rM74HVaK0fE64Uz/mCtAZoYPZYdwxj56fyFlYcpFpN7Lv9mVWxXzV4M+w049UszwLuoykU11g+EwY7/BzWRwyida2dOmaMUTC4cZXgNjEDboi1U2d2F9xee9KJ1el8hLJWg/f+D4qw== 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 BL1PR12MB5125.namprd12.prod.outlook.com (2603:10b6:208:309::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21; Tue, 20 Jul 2021 17:43:07 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482%5]) with mapi id 15.20.4331.034; Tue, 20 Jul 2021 17:43:07 +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 Cc: "Raj, Ashok" , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Yishai Hadas , Zhenyu Wang Subject: [PATCH v2 10/14] vfio/pci: Reorganize VFIO_DEVICE_PCI_HOT_RESET to use the device set Date: Tue, 20 Jul 2021 14:42:56 -0300 Message-Id: <10-v2-b6a5582525c9+ff96-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v2-b6a5582525c9+ff96-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR02CA0013.namprd02.prod.outlook.com (2603:10b6:208:fc::26) 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 (142.162.113.129) by MN2PR02CA0013.namprd02.prod.outlook.com (2603:10b6:208:fc::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Tue, 20 Jul 2021 17:43:04 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m5tll-0051F8-L4; Tue, 20 Jul 2021 14:43:01 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 94613815-fd87-4ef4-dfa2-08d94ba5d3b2 X-MS-TrafficTypeDiagnostic: BL1PR12MB5125: 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: BwRq5fSxjGhil3uML9W8mTmuGu4jV7pQf0jy+h9x5PR/HGjo7yaaEQLU0SFN8IwNdSX3VlfglS2QvQN9admfGl0+JjANFQMyahjceZHfQQySlWmlUZBhpDT4fIWapX7DE3nZfOULBqHjbAh2IGbVB7329aAIEpBD4hRLgReM2LhmFA0lZaOKYmFhJKRhsOqh2+fWSZjgpvVWVRLrnmQ6Zgusog26RT6E5/4P7jtnO2uRhrzGWrs5+3+O8OlqxSyrB+aSUqxKooe7VymWrAn7CDl55u3eOEMgCWW0t+IACV3II7VZZGkCTsqsvmrJfxO1T9JSm5UiHyA7RQtQBf3yZ19MWvYNndgve1BU/n/Lgsr+/dowzVY3wvCun6gTtUs/aAsHjGhByO+HUX1exL4k1zfRFft3ZA6YCNlrKPwEPfJNrNIldUG55urqV7MEchFad7e6y0p21o4owo08VZ1ii6xf4uUfKb9GplXaVjYWIMZm2EnX4BtFqVvpjul3QY3sHTPy04Bk1lFuhS4qTeJHUCv19OtxYUc3TWYA4dAnV8BsE9h0HsWlLbxIpdcbkppG10D6Z21dDQQfx/WYuoMdEpR8vIcGwlxYnVJuphB0/zuqYUI5kL0bD6glsMSebedkwCcn939FL5dcSmoCrnCvA6PSdeUvDvuvD9kU04aqiGFRG78V6wlFFomRl+5sHaxo 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)(376002)(136003)(346002)(39860400002)(396003)(366004)(66946007)(316002)(66556008)(83380400001)(54906003)(6666004)(7406005)(38100700002)(26005)(66476007)(8676002)(9786002)(4326008)(8936002)(9746002)(2616005)(5660300002)(186003)(110136005)(36756003)(426003)(478600001)(921005)(86362001)(7416002)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: d+bKJZx+xn3vdLWP3cYBRx/gg/J2kp2stM+YLpkUc0HLwEGOi6ugplFo4/ujD8pGxX+1/3utKUgILBbs8DgdgzErKBjCDNTXc5ExCvJPznjGFCUbKVCyYI1zGayqLxcJ8+pU92fo+sf3cnTU54MKGrFjLQjJvY9mrXCKpdIKPB+I7NGwMNmwOMHd/oXY1fhwmsUcoSqc72GUYsC0BSR6BQZwtppNSxQMAoptss05YC+hWgjub5weDDcRs2rDF9DtsyCxrEygSYMq1SAi8O6OrSn+45+pT27tjmzk9wmI47mGtog5fwkiQcUCAM4OEFpTQadoEg3wWrbPprHICPcpSGLJ5XkU3zGZsAnL6hAJfgqZHfV4ScmBbE/urVceFA7sttGgXBMrNOoyW1vPNXwfyyq2uoJ1b/f28nOAZwjsLFOcz6uipSU7WRc3tlusJvWrsNqzFZtgji8ixzDZtsmTmX2tPPQDfQfVdLhoE90cVBeTPUnMMhuFv/KwKNOc+TuCM9up/fEngQV1/zu2XoFqefxl9vXg5HW2LBBVzOY6EgqV3UeB9Fn5Zn2gXncSeCFagTHwEGZ0q1GbQYTJlGndjv+WRJeKRJGQ2RW/p4rv3ykH22aBGBu3oCN5rz2QBy6FQ+pyt0CePTTGcIqkAl8Nw45D/QUXAXf9YeSmcUWfq5l2rwLNi2Qd10ymMopY1+Z24F5f3R/AnMHtDDPgT7jqnTvQkV9MdUNxZyYBIfyNE0vH+eLQYRNtwMFsQ87PjkiVb7Wq87NEJ9BhweW8akVmTXowiar562Hmj6gUWz25e+l+bm9znly8S+GeEXzyiOiaBuXutud8GtTMluqRLiGjuzXNkDs+cKvnnNML5wUIT3kUxkQyRrxIKfHKXd7Bq8bJnxyLHg7ApLwGGnsi/OjeGF+XeyY3nvkOaz9lL3hpjp3z0Bblr0sPclkt4Gwdapv4CVQ+q6a0uPq+ER4XD/ckjpw8/snnry6zshZihqNIVP8EmWZ4lAY5dEzb0qEKLEe/cgMr+WN+3ETAFOA5VokuH4+KurdrOoHs48rZg/Jyxc2R39VKTaiocZoMh3HIhUsrkgqxeRmMq7KUPiw0gpEB4FUEq646GGoyNaRaOr1f7Jmu6ORDbzCDivUygPjMITaSRwu8bjTbaJ8I8is9NrYk3wvQ+u/EggyGYfhV/FrJPjQdXql8fQOKxUwWHCJSvyOQyMF4Vzg/pqM9QPvu/boHBItxXkPuyFIhbzYDLtTBq0Z9GdqWgfS5uEbxPV9tPd03q4/PC36Qe8Y7iiWX2iPnVJU4LKOtK1342/rqJUIWzOguoUXLZXRHJz74beJeEd88 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 94613815-fd87-4ef4-dfa2-08d94ba5d3b2 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2021 17:43:04.5517 (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: +r7oOzLCSXgBo1u4nlD3cwtgT+Wiw7xlScNpxAZWQC+z780x6yUx5Psl/toIR+8t X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5125 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Like vfio_pci_try_bus_reset() this code wants to reset all of the devices in the "reset group" which is the same membership as the device set. Instead of trying to reconstruct the device set from the PCI list go directly from the device set's device list to execute the reset. The same basic structure as vfio_pci_try_bus_reset() is used. The 'vfio_devices' struct is replaced with the device set linked list and we simply sweep it multiple times under the lock. This eliminates a memory allocation and get/put traffic and another improperly locked test of pci_dev_driver(). Signed-off-by: Jason Gunthorpe Signed-off-by: Christoph Hellwig --- drivers/vfio/pci/vfio_pci.c | 201 +++++++++++++++--------------------- 1 file changed, 84 insertions(+), 117 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index fbc20f6d2dd412..d751d38f2175b6 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -223,9 +223,11 @@ static void vfio_pci_probe_mmaps(struct vfio_pci_device *vdev) } } +struct vfio_pci_group_info; static void vfio_pci_try_bus_reset(struct vfio_pci_device *vdev); static void vfio_pci_disable(struct vfio_pci_device *vdev); -static int vfio_pci_try_zap_and_vma_lock_cb(struct pci_dev *pdev, void *data); +static int vfio_hot_reset_device_set(struct vfio_pci_device *vdev, + struct vfio_pci_group_info *groups); /* * INTx masking requires the ability to disable INTx signaling via PCI_COMMAND @@ -645,37 +647,11 @@ static int vfio_pci_fill_devs(struct pci_dev *pdev, void *data) return 0; } -struct vfio_pci_group_entry { - struct vfio_group *group; - int id; -}; - struct vfio_pci_group_info { int count; - struct vfio_pci_group_entry *groups; + struct vfio_group **groups; }; -static int vfio_pci_validate_devs(struct pci_dev *pdev, void *data) -{ - struct vfio_pci_group_info *info = data; - struct iommu_group *group; - int id, i; - - group = iommu_group_get(&pdev->dev); - if (!group) - return -EPERM; - - id = iommu_group_id(group); - - for (i = 0; i < info->count; i++) - if (info->groups[i].id == id) - break; - - iommu_group_put(group); - - return (i == info->count) ? -EINVAL : 0; -} - static bool vfio_pci_dev_below_slot(struct pci_dev *pdev, struct pci_slot *slot) { for (; pdev; pdev = pdev->bus->self) @@ -753,12 +729,6 @@ int vfio_pci_register_dev_region(struct vfio_pci_device *vdev, return 0; } -struct vfio_devices { - struct vfio_pci_device **devices; - int cur_index; - int max_index; -}; - static long vfio_pci_ioctl(struct vfio_device *core_vdev, unsigned int cmd, unsigned long arg) { @@ -1127,11 +1097,10 @@ static long vfio_pci_ioctl(struct vfio_device *core_vdev, } else if (cmd == VFIO_DEVICE_PCI_HOT_RESET) { struct vfio_pci_hot_reset hdr; int32_t *group_fds; - struct vfio_pci_group_entry *groups; + struct vfio_group **groups; struct vfio_pci_group_info info; - struct vfio_devices devs = { .cur_index = 0 }; bool slot = false; - int i, group_idx, mem_idx = 0, count = 0, ret = 0; + int group_idx, count = 0, ret = 0; minsz = offsetofend(struct vfio_pci_hot_reset, count); @@ -1198,9 +1167,7 @@ static long vfio_pci_ioctl(struct vfio_device *core_vdev, break; } - groups[group_idx].group = group; - groups[group_idx].id = - vfio_external_user_iommu_id(group); + groups[group_idx] = group; } kfree(group_fds); @@ -1212,64 +1179,11 @@ static long vfio_pci_ioctl(struct vfio_device *core_vdev, info.count = hdr.count; info.groups = groups; - /* - * Test whether all the affected devices are contained - * by the set of groups provided by the user. - */ - ret = vfio_pci_for_each_slot_or_bus(vdev->pdev, - vfio_pci_validate_devs, - &info, slot); - if (ret) - goto hot_reset_release; - - devs.max_index = count; - devs.devices = kcalloc(count, sizeof(struct vfio_device *), - GFP_KERNEL); - if (!devs.devices) { - ret = -ENOMEM; - goto hot_reset_release; - } - - /* - * We need to get memory_lock for each device, but devices - * can share mmap_lock, therefore we need to zap and hold - * the vma_lock for each device, and only then get each - * memory_lock. - */ - ret = vfio_pci_for_each_slot_or_bus(vdev->pdev, - vfio_pci_try_zap_and_vma_lock_cb, - &devs, slot); - if (ret) - goto hot_reset_release; - - for (; mem_idx < devs.cur_index; mem_idx++) { - struct vfio_pci_device *tmp = devs.devices[mem_idx]; - - ret = down_write_trylock(&tmp->memory_lock); - if (!ret) { - ret = -EBUSY; - goto hot_reset_release; - } - mutex_unlock(&tmp->vma_lock); - } - - /* User has access, do the reset */ - ret = pci_reset_bus(vdev->pdev); + ret = vfio_hot_reset_device_set(vdev, &info); hot_reset_release: - for (i = 0; i < devs.cur_index; i++) { - struct vfio_pci_device *tmp = devs.devices[i]; - - if (i < mem_idx) - up_write(&tmp->memory_lock); - else - mutex_unlock(&tmp->vma_lock); - vfio_device_put(&tmp->vdev); - } - kfree(devs.devices); - for (group_idx--; group_idx >= 0; group_idx--) - vfio_group_put_external_user(groups[group_idx].group); + vfio_group_put_external_user(groups[group_idx]); kfree(groups); return ret; @@ -2155,37 +2069,90 @@ static int vfio_pci_check_all_devices_bound(struct pci_dev *pdev, void *data) return -EBUSY; } -static int vfio_pci_try_zap_and_vma_lock_cb(struct pci_dev *pdev, void *data) +static bool vfio_dev_in_groups(struct vfio_pci_device *vdev, + struct vfio_pci_group_info *groups) { - struct vfio_devices *devs = data; - struct vfio_device *device; - struct vfio_pci_device *vdev; + unsigned int i; - if (devs->cur_index == devs->max_index) - return -ENOSPC; + for (i = 0; i < groups->count; i++) + if (groups->groups[i] == vdev->vdev.group) + return true; + return false; +} - device = vfio_device_get_from_dev(&pdev->dev); - if (!device) - return -EINVAL; +/* + * We need to get memory_lock for each device, but devices can share mmap_lock, + * therefore we need to zap and hold the vma_lock for each device, and only then + * get each memory_lock. + */ +static int vfio_hot_reset_device_set(struct vfio_pci_device *vdev, + struct vfio_pci_group_info *groups) +{ + struct vfio_device_set *dev_set = vdev->vdev.dev_set; + struct vfio_pci_device *cur_mem; + struct vfio_pci_device *cur_vma; + struct vfio_pci_device *cur; + bool is_mem = true; + int ret; - if (pci_dev_driver(pdev) != &vfio_pci_driver) { - vfio_device_put(device); - return -EBUSY; + mutex_lock(&dev_set->lock); + 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_check_all_devices_bound, dev_set, + !pci_probe_reset_slot(vdev->pdev->slot))) { + ret = -EINVAL; + goto err_unlock; } - vdev = container_of(device, struct vfio_pci_device, vdev); + list_for_each_entry(cur_vma, &dev_set->device_list, vdev.dev_set_list) { + /* + * Test whether all the affected devices are contained by the + * set of groups provided by the user. + */ + if (!vfio_dev_in_groups(cur_vma, groups)) { + ret = -EINVAL; + goto err_undo; + } - /* - * Locking multiple devices is prone to deadlock, runaway and - * unwind if we hit contention. - */ - if (!vfio_pci_zap_and_vma_lock(vdev, true)) { - vfio_device_put(device); - return -EBUSY; + /* + * Locking multiple devices is prone to deadlock, runaway and + * unwind if we hit contention. + */ + if (!vfio_pci_zap_and_vma_lock(cur_vma, true)) { + ret = -EBUSY; + goto err_undo; + } } + cur_vma = NULL; - devs->devices[devs->cur_index++] = vdev; - return 0; + list_for_each_entry(cur_mem, &dev_set->device_list, vdev.dev_set_list) { + if (!down_write_trylock(&cur_mem->memory_lock)) { + ret = -EBUSY; + goto err_undo; + } + mutex_unlock(&cur_mem->vma_lock); + } + 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; } /* From patchwork Tue Jul 20 17:42:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12388979 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=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 0F63FC07E95 for ; Tue, 20 Jul 2021 17:46:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E77AF6100C for ; Tue, 20 Jul 2021 17:46:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234365AbhGTRFk (ORCPT ); Tue, 20 Jul 2021 13:05:40 -0400 Received: from mail-mw2nam10on2068.outbound.protection.outlook.com ([40.107.94.68]:52928 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232233AbhGTRCq (ORCPT ); Tue, 20 Jul 2021 13:02:46 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c6kAswu4MUX+Wd/xorIWxrmVRNn1gpWBgjJfVdGTXjLOeFDB30Z/ZMjJqGAe5oB2zZbqz1C8VY1E8CKPPtB5Aj7gynRe2O3/mIJbAFMZfe3m5jBJdbdllllMmsbGg7eoFEm5gdGOyStZ2fzsApLWvK5/A6MTfPqn4KlmJoLem2HGWuDm+bfqJEE6SOPf027JuzunZULBlwhlEz3eNNelOAq8Tc36yRypof6ElKKEQuDr1OhOP3y0Z4nmyWL+2CwR+d1dZSllIViPKAqvn6eA1oSmBKDCRYBczGvi6MD/XVvI4lFINxSfcB4qcNDDKQaYSi4fgbvUk+gHtJ6L9X69Ug== 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=gqlHfJixjAwv+9i3I7/fKkhdHEPsaBue8euAImr4B6k=; b=hUySbq4PgunKd7A21/6YcAQ/09SJWOz0RUm+Dt6FQzJhz90cba+Y66qydwGoudVLEJBgkJE4l3UuFiEmsFm/04MNGXnDfth2ViDowvxQnzcivxAQScLduMwY4JIFB9zk2mFdHoERcWKmhxVvLA8PBcEurN/7OfzdG2rUPGd7VFSCKALgWeFdqjWdYE1DWuxIcqSAj80xpqb4yGeld05B8AU8c0cX1Pe1IZ8jfLUurlRg4yO4KLaX7w2gy1shqACP6zl+3BKnYleoIVxW6sG5fnIrsSIWMeQ8FBA8qc2m7UgcrYbKDIoSg9zVjPmXejlN+9UOnDqB9jlMBbXnTqqZxg== 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=gqlHfJixjAwv+9i3I7/fKkhdHEPsaBue8euAImr4B6k=; b=Qpn+EkM49lYjG4zqpN8RyS4SHunSaLw8LCbnLrnS80kPmaxB0o1UglIpuVCMKrUvvJ8rIOAqfLLf44GKmgp80zxcTJrUPSduDu6Kf2ipU/sRzf4yiDSEfbe/HZuMcex5qb6n6hHxCKAC1Y+wcsdz8c5vvAkvUjVzrkj/etiOYkwzR0yY9cYOkuWbZrnXaCGaf2NNg4wfaLtqdjH3o7Gm1gPxlqwPkJdKJU9XxgFN91Vxpo0AWX5HHy19hbv7Elnfqw/ImnbUKXENngn9px+S9rjzi39HUgyUNkus9R6tgk3ezjZCeqG5MdqiEmIORCseikT0yb61CSD+iD5xZQWF+Q== 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 BL1PR12MB5288.namprd12.prod.outlook.com (2603:10b6:208:314::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21; Tue, 20 Jul 2021 17:43:07 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482%5]) with mapi id 15.20.4331.034; Tue, 20 Jul 2021 17:43:07 +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 Cc: "Raj, Ashok" , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Yishai Hadas , Zhenyu Wang Subject: [PATCH v2 11/14] vfio/mbochs: Fix close when multiple device FDs are open Date: Tue, 20 Jul 2021 14:42:57 -0300 Message-Id: <11-v2-b6a5582525c9+ff96-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v2-b6a5582525c9+ff96-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR22CA0025.namprd22.prod.outlook.com (2603:10b6:208:238::30) 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 (142.162.113.129) by MN2PR22CA0025.namprd22.prod.outlook.com (2603:10b6:208:238::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Tue, 20 Jul 2021 17:43:04 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m5tll-0051FC-NF; Tue, 20 Jul 2021 14:43:01 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2fa7b960-9b36-4501-11e5-08d94ba5d38b X-MS-TrafficTypeDiagnostic: BL1PR12MB5288: 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: xMBwSJNwIigG2nxEJr3beFLKcsrJ2dwDFR+Y/YQM9+P/jwwQMcuw3XJtJQ8KStlKbLkIDZfE46YuL5Oto68yuzoVeA8sxm3uQygXKZSmrL61DtUg9CKeG7A9TuU/6tvlCoV0lwgkaaAQ/TsvxDdxLvd8bLuihbreKWA5JWu5tcR81p2PLqhyQLvz04ANA3h6bzVedCSUvEkHV4ZVQ+LQhNN7P4w9cxrftnPj2J2AOhYSIAlOcBxhvqjZHtcS/GxYYvunfigsvrC3STcN2Imle9O4DPrbq4stTjy+AGR8TC59NSkwI5vYnRDffXXfE7DONoY3NVaDOhEoNC5TXNHQOpyelqjCVNYZb/2xMHiUZZhWFaE3w95mLNC3sMkuoZU1F/BZ3aQRllViNFJ+j4Nu4D8lcKIEFNgmYkFRggNIDgRkjkrxuBIRcbbZi5xm7vHYdkK07Ngaqq/gacuYboqWqXuXUcUlaV8j+Y+wCEA+8msZv36lGp/zHFuE2DM2+7AOaJFyfmeiWXfcZOyQ/H2GH//qyAflAQr7hiEMh2TfyUjTu5mBANAWPWDfu1/v80ue6uzkaHOtmXZ+fFALZLGbGInpW6zRqdjG15pCQPuMdtZxvnrIAz/83Ve6kC5XVrcQkzbtHMDY5KmU0CdRbkL9BReRBaHK/NfZorrOzOPfl/TZI4orvkjbu6NQQKGn1L8n 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)(396003)(136003)(376002)(366004)(39860400002)(346002)(6666004)(66946007)(7416002)(7406005)(86362001)(2906002)(66476007)(54906003)(38100700002)(83380400001)(8936002)(316002)(110136005)(478600001)(36756003)(66556008)(186003)(26005)(5660300002)(8676002)(921005)(9786002)(9746002)(4326008)(426003)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: WHJ/qiQBkql94CkecpfFftVx41Ks4EWRtDjXYYzelOe+EfG+DRwTsBpLzgd0FS2XTqRMRUE40QLfgCyFATu9huuh+UrrS7uu4oEmHhTH8taXROc+gPAD5waw+5d+E4z6cTh8WiORzlTRjD8pT4lxUyurfD4Fh/7nwRsDJg0Y1hlPd+g8mt7wU6X4KV6diAyeo7foBVX/FOx53dEpXeFsMWAa0PgjN2vGwZPwXJBsmIZP0UTbpo4667/5HQ04wyYv1zm3w4wpfUbiTcvWoW/GsYznU4bOSj95EOSOlXk2JmUN2uB4OnbUPdxo91vLeSbJAMPFdYA5JGvWyPLpx5jc46QpVfPlzkoMed+syKkOYmKVC5F7k5PbMwxGfi8e0qjgYCxf7A6GBDpxiwaATeJlL7Sk6ceg4mmR5AasSjAlhbyyU0vDyQQOsRYTw8gbj5gdZCPJtNUKxF7uIpduGWG7oBhbefT+iODvp7fxFuaR4eW0lr/o7on1+e3JjgOlaPu37BHHCtyGSSMofRoE/WQLi/Q5coq3+VZ4PZlDjow6luIbGRF/XDipasL+rS6GVRKRQq7poCAMQb3HCn2LqndhHyQ6Iq4vim5R2NIcTGf6EZtZOJ7kkSMTgQMIEkFh4r5Z4iX5Wrhe0Ue+i+n718mkDk8Z0OjSk86i3Es1LjuypnSrKVicPW9IPse3T5NMRbMO4Ya2mHmqmHiIYfM8tjXI4LKoQ929YWDD+nJmxHQlmKXJSdNMJYRyCJCuo+OkOE9KF1u8oy2kdtRdpYgsain8HztLpIcwb5dvTHAB/C7fwztF4R5lUurPGbUNB3NlYYSS3RMXHr1JESpy7rx5vltFr3kKGC0Z9TWFvdRj1q+IsEkIRvYt8JK2yy2TDeUqcvgB2C52thPO+mi0hGE6+skptAKvkUeFpPPEXHaMhSba7lYsuB3SaKEcxN0xTfbdTHBYONbbI5ZPoet9Or9SsPqQjbeDohji1ZqIHKHr/u/rTXnyt5nZ3Eo/b0lMmalsCMWsy7xzqKAEEOzbz7VstYG9LpFPCO93midUu1gWg17JYU2EctPCFWKsg8LlP+3NKfsY56EWwPkDcilpuGbOXyQas1jwfFuM9BEJaccd3KOmWaEg2PNF2rqn+1YWuxAPlvB4aejkY4dNM/Kf5R73u00OFq0Qv70lgJnxRJIqI1EptsF42tcy5JKArZmk/9plx1C7z1yNxyn/cjnGeokgkMgxD4GBLlQ2Qt652wjikQd/zAnJfcGHlNoO4mZk8jeVfZwEjk0hDUBVoSJacGw3w1caffUMHt3UDWJ1JmGeHzlKDWGb18Qm15a0uYf7bXa2nqsL X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2fa7b960-9b36-4501-11e5-08d94ba5d38b X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2021 17:43:04.2699 (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: iyxxAfxqkdQuPinYKu5XEpNeBOggpyTE+ZLIYMb5cGny/pGuEzqAM/lhv2K2CwF3 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5288 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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 Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig --- 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 fb81d11029e8a5..39002b07e692ac 100644 --- a/samples/vfio-mdev/mbochs.c +++ b/samples/vfio-mdev/mbochs.c @@ -1277,7 +1277,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); @@ -1395,7 +1395,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 Tue Jul 20 17:42:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12388981 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=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 6E9D7C07E9B for ; Tue, 20 Jul 2021 17:46:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 57BCA6100C for ; Tue, 20 Jul 2021 17:46:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234063AbhGTRFW (ORCPT ); Tue, 20 Jul 2021 13:05:22 -0400 Received: from mail-mw2nam10on2068.outbound.protection.outlook.com ([40.107.94.68]:52928 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229536AbhGTRCh (ORCPT ); Tue, 20 Jul 2021 13:02:37 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kiScgioDV4lb5kGTbpd8z3lGB+WLbs+34jvuHSpC/tv32PR7FmwlPo18VelM4MFBeldv0ZHPwwfcY47giFul1Pr/mEG1kbs0dXySs+3IxlomRW0kv0tEYsLcybtktcpsMHfmZkwARMrflBWX5ZgyeT6Aq19+j/hAE5dhocBA4vIxBeGwn3Vq1kEl3rU5xvVfBHjUc4xev7sk6UTdn7ETomZ0RRv53I/2evmgCz19hLQeRJRRJG7d91iluTRIW2fUZ0tokifhS1OBUu04jksSLKJLMG3zR38T5TqnvnZhzSJlksmINVd8a1ecvSlYP8xRSEAvep1oKeXpr5joefAmrA== 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=ihQJa6vcaC4hqq0e7kLa7T4PqEpapDkc8Hv5Xo7wTNTMCx15l327yRekjgbb9+v/nLGwU3vH6ZGkAF8d2qH+45rUWXTGN1G9dUUA5u+Y9+0re2GMFvETuJP2ks8CcHVeyFxKmIQoPGoqnCHA8Dl5Y8X2aX94YAZJYipuEgrSz4ONyWhwOL1jWlP2tN+DBzt4qFfQt7QZp9Hd6rYyTr5wJWqdnU14AaXnfN/od/o/AzcA2t0tmOPNbqbbme5X3/8kw8F3LuwjnS2GdDzatTuPW3gIC6QSNfrS005veDGwBrreM7gR6CMzgaITiALBuYCiKlNf0+Ynu//iV1vh9Pp1Ng== 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=j5kuaGYzf3GO45cktxrY94NkmzOQA/eYV6DR6G12fP4o1CAHzPoM6yPC9QA/kS+37ZCgJ3Z8ZuhgiWJQ2wdCyPcI83wom7j/pHoOHpPyRfASadijtI7IgkzbsMMw4ygPGmKj/GCNSNhdZKvQXqQg7nMwpaX377QkPmeq0ohlHfW4CPOUr3jF8oW3kV+2p+SB2ws+/g1BpM4xiEY95g9O22u5Cecn3Y0F50ky+8NafIvZx7ProLSfv6XUudywcLE9foWzi9T1ev1ItPSn11ySWm64k++o8p/yrqsz7sinOo1AMvm89I4lxYYcUvQV4YSzWUZY1+Z6sUSMo2anXcN3kg== 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 BL1PR12MB5288.namprd12.prod.outlook.com (2603:10b6:208:314::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21; Tue, 20 Jul 2021 17:43:05 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482%5]) with mapi id 15.20.4331.034; Tue, 20 Jul 2021 17:43:05 +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 Cc: "Raj, Ashok" , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Yishai Hadas , Zhenyu Wang Subject: [PATCH v2 12/14] vfio/ap,ccw: Fix open/close when multiple device FDs are open Date: Tue, 20 Jul 2021 14:42:58 -0300 Message-Id: <12-v2-b6a5582525c9+ff96-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v2-b6a5582525c9+ff96-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR02CA0014.namprd02.prod.outlook.com (2603:10b6:208:fc::27) 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 (142.162.113.129) by MN2PR02CA0014.namprd02.prod.outlook.com (2603:10b6:208:fc::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Tue, 20 Jul 2021 17:43:03 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m5tll-0051FG-P7; Tue, 20 Jul 2021 14:43:01 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a2bf8cce-6922-488d-f713-08d94ba5d31f X-MS-TrafficTypeDiagnostic: BL1PR12MB5288: 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: zaoKGOUd9zvDbgXSVs/ZxwTY5o6FeD5pIyh8g+G7YFEZAF6npQUU70yMWNYNmBFw6cXxXSp15ZKxuGqs0wipGCKdF0LmIJdSGmrAq6eVGipRD6CeetNsMUB8aNfUwa2JZspsTDk69iypUphVQi9jvY9EkFI1Xt2Srzg7fK+WRS2fVc0/Qec2xJxEhL9Y373lbYKw1teDgla+sD8vgCKq1Yrp/MVVB8bvMXLLqQYM32/MZlcTVZP5cCQ7GJ41hF1yXUchyJo1DtBIBzOj8KZZHz9nkGv/jjpgnDTxBWO/F9WFS9A/q74ca12x+i6zQM60zpcxT21/RR1clphA8VPe7vNSfZoNCVmHHp0uqbWyJMYL6s/k/Todyo9zqzp1DdMDdt0zAanxhjluNmnYuc8pCDB4eAjfYqbuBfd9jOa1upMF9pGuUEetIPCYqvNOJmeve94WiwgX9Ppx0nV5FrhPQqnyr7Tz7AAvNlIE9R1UKCwR08CUFBDor2DlcjgcqdNU3jPapsJkJSZYjoFRNN9u1YLMqQWYg8DIitr7R05iym9HOO5HG45S+6GFRm+wEtPgp5mkAISqTL+hBPRIoOXmVfRHrzB/TciENDgFr540dOChm6UNIDK0JU9dqA5h4Rd1a5maXIvuCyBaGMGZfphpxnEp5HxgLThanj+TCpXt/x96e9jXhIEfPDLxwIo0bWCV 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)(396003)(136003)(376002)(366004)(39860400002)(346002)(6666004)(66946007)(7416002)(7406005)(86362001)(2906002)(66476007)(54906003)(38100700002)(83380400001)(8936002)(316002)(110136005)(478600001)(36756003)(66556008)(186003)(26005)(5660300002)(8676002)(921005)(9786002)(9746002)(4326008)(426003)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +chi1yNcQrop+JNtaMsUesGaf0VgpTEogbrM9dAJ3FzwVoeLNiEN9hOBdoMN5DNrFmKGnnRO8WtwC0UB3FInApdJUOdCIw5QNPY/UGWwrqpvhMt/WIqEKaAqZYcDNfqT1u6OMeLPvwN1L+ngKu5HgQ9hEE48y4XTgqoSedV8/Vw1CGaWf7dbvISbWIBGz/myu6k9nP5DTJZT1MyrmyuT7MFut2ixc61xl5xr3OIv/+wyZfht2C0IC7SUsuQeqLvTDZJ1JTkyhxUBZ+p+uX/7TEvyvYFQZlD1DDx2N5RslwNb9PqN3vtGHl2cqrfi7fF6fMUVZgsG4H64BY3T3PprzAjpYEFQpODM41dbz+n32l28KtFeXtHvS5wFzX0hZIfSbdDSZ1oq/LsXMehQizHOI2sYoX/mTPFWHLjZBZKsmb/B3gVX5fYddrmyRspQOhdF0e5Ib+crVAwRgoHc4F31wdnp4zr//6LrOo+sriSvu8wdI3ANt+lQsY+QKT4veHTVv793P8Y2nP8twTcbSG0+ETaHZVp5Vf0MRDuX4Jutd5gJS+nXDWD7roweHS1m7BTZwb9hjTfAuFCov0Bbx4gyJMiPe3uwkqtCPCplYW3OUQVFzRaxEZjSE98gBD2hNqUkyqCKlVIRHXRbElkvlgY2ja+jBCxC7dgPXRm1c7W+6OoTYZJw6CbrwVC/fyPAySd/TRqyNPJClkPkBfZItOfq9Sp1y52sE0lV8VJJ8T6rMxMp+E8FfxEvEGijtq6XBYPR3HXZT7kak3CzwJk+1p/oa1HAYr/QKW6yBPxqDQgEe702AJ4QW5274IH4Bd1z//753r7WYZpRvl36AKKCxfLmP1y6S8xBJOrskYCsK6m0KHGDeoqi9XcMJ1stSHkp65CIKxgVPSO6Dl1NI6T3ZdkGAF61PSD/rUZBQdjfAamf1KoNfbiWZiBvcdVXgMtA22rQmw3cZjCRIl70czKNCbCX7vTHscMFhfGNsKUD/bHbDNZWqpecgoXtKFiweAxzbZlXR3YCd0KlDfMVzHL4D1xz4uEmKWJFLBMZeF8MvhRcOE6zZwvsjuP5CRt8gvuA3bwCJrIOsCE3/ULZrRpz76AQvVvc4qaicHl6B1ZO7iSrH+uI+60UGu/0a1WuGlfPDRg8/Xnyw36uQEmLfQYh7jiNy+BkuZf+NyJRLvEfRMWX72+e/IceAAzfsqR5LmradPNV/SUvboezEEgLN81kKbMdfDCVnWsZmt6apm4TTAbjvdR4RYC9wPTOjjNJNtYEuikYOsWRaIYC25O4fFExc0++7jBMTrnOaSxG/kj1ke+k4iTb4RB4Fh7gxsEJ+btZ5ACv X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: a2bf8cce-6922-488d-f713-08d94ba5d31f X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2021 17:43:03.5302 (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: vsE8qDlijTFay49Cr1QyQTl9YD1A8S7IVtA06Yc4PEWc9jwJOB1iu1tBshAI0leR X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5288 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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 Tue Jul 20 17:42:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12388985 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=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 4688DC07E9B for ; Tue, 20 Jul 2021 17:46:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2691C61004 for ; Tue, 20 Jul 2021 17:46:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233629AbhGTRGD (ORCPT ); Tue, 20 Jul 2021 13:06:03 -0400 Received: from mail-mw2nam10on2068.outbound.protection.outlook.com ([40.107.94.68]:52928 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232354AbhGTRCu (ORCPT ); Tue, 20 Jul 2021 13:02:50 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AQpBVhgIibZwQoD3n6UWz11+XfYkL+4X9u5eswEC/o/soj1yKIgJhqEmsZfNUIQs3Y1QEZEnw3CiTPiVymRkTkM3dD7gVyRVCEzDOlkrPGAhEjy4gRD28a/aTYCIEJO9cRrOsXEFS1ScpCAiMgXd9J8+F6aUU2DCFSpyR9a3j6MlMvZ3JrxD/88HvXFkRKJx8UObWQfiK58c+BYL11yOrunzbA/J4VYX22Sg8DgdgFRf43RSR7d0yGQ/RtB2aiUvFKNiqQD/5yoqKcB+Mm7bfpdTdV9SLOMEco499swOPJ5GjlGEntE5MhH6JExOXU1MRpAEsbzw1nHWGR7UZ4KpDw== 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=FLzSCfm46aaxgunSwJCbcPbWiLquGUluYNQWWJ5J2ns=; b=StWi9m5kaRwKr0q+I2p2FpLT3IlCxv9UynHdbM/IA/i2AlM0KoMgobPDDTmX4gyqfhAsJHRjjXIccTroA+Q+bBaP64T5cx25bVLfraL4AXSrM3P5ZsurknIBlzx3qcOJCfynOSCOuv3PQi8OM5Pa2H1ERKtEzp8LM65fJx+LPdkuYi88OT42gcudxkB/ZFnlOHqYFgG71XzVpAAMo7sJVlyJfMVdiJ+JvNJ4L/lE38hcGLZoQY/HX8PQlzB9VyRt1RcfQ5DwMIB6uhJEttyzQWwZnMwX//rtFxS5YzA1fpgfVO54ljbHgdC8i1fHKYYw4t5qiwAu8pWVtWGpxbZmlg== 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=FLzSCfm46aaxgunSwJCbcPbWiLquGUluYNQWWJ5J2ns=; b=L6vfJjoMn6cOrH0c+ljatMcGy+B8qmfWl7Jn8rxBDofioPO365hUh5oreWqFP2L9zgUTBtQSqqC5ExPnyGc1fjbZfh3ZYAE/BsZta/aOdofgIiC6yLn+yHxzzYjoNp1DX/b5LwkbxkPpqIVCmBusSv5V3NA/yFV2SGtL82nqyir8LOaYVJ3HX/PO30jDnyE4c0/FNmis22I0yYCB8ai7jmJ4Uyi7tc/jW7sLwbojLOmNqKM2ybJhjtEu8kzW0W31O1ebV+DtUfODpjahatyRCLCavn2Z2u39G76jXQSeAv3LIEDyOPtjYPkwI9fmkSnIbrsSptn6kLRvMs6EARsgkw== 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 BL1PR12MB5288.namprd12.prod.outlook.com (2603:10b6:208:314::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21; Tue, 20 Jul 2021 17:43:08 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482%5]) with mapi id 15.20.4331.034; Tue, 20 Jul 2021 17:43:08 +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 Cc: "Raj, Ashok" , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Yishai Hadas , Zhenyu Wang Subject: [PATCH v2 13/14] vfio/gvt: Fix open/close when multiple device FDs are open Date: Tue, 20 Jul 2021 14:42:59 -0300 Message-Id: <13-v2-b6a5582525c9+ff96-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v2-b6a5582525c9+ff96-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR22CA0018.namprd22.prod.outlook.com (2603:10b6:208:238::23) 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 (142.162.113.129) by MN2PR22CA0018.namprd22.prod.outlook.com (2603:10b6:208:238::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Tue, 20 Jul 2021 17:43:05 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m5tll-0051FK-RM; Tue, 20 Jul 2021 14:43:01 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 67c687d2-942a-44f2-5871-08d94ba5d41f X-MS-TrafficTypeDiagnostic: BL1PR12MB5288: 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: gSLqAvw+eXdB4K3t0+CEBOci/yS2fx0eeu6QL1IPVjbTgRiVr6uZ93czxG6Ta+PLLXOjCPpM1QSgnqbhRE6pWSWwGW3xIDUgTchdwtMrSEcSyG2hyLW5AdWtiubW4Yv5gsmii/g0hnurn+/HhCXNtUobs6v3RW/PP28Mb3EnI/fnVU+76R23fU4kmb1Lamq+CCZQHXPLpQYfjSKak5ETClFUdlFJIkZjDkUgl+/cJHw0uHfjbstfJ+nr4ngRIuFyWZhPZf2x6hkKZos5f0u183YVH2pI61o6LWaHEdjmQ4Sq7apmIIIWtNmRuxWcs5qIxptpYv/pKOhdz9SE1VUnjW2ES3Iv6yAzlgTht8c9pbDIp9DGEum+BCaGxY7/pqNNhSQMDMcIjqedonNXApicRyGf3Da9oZEln8lxHUiFaMoafYa27jCDanrod/+2pYB7YccaQjpVfP17EfPpxyHDA3D2aUKFIde56wzWf4ragh0gxqN4Y3RBeywLlx0cmCoy5mabqwjRkZp4fifSD1F4/Wd7l2WnCdCcRwZvt/yyEcS0iI/mT2V220JFUvtrTAeKffLSseMjsFHzmWCtyMAT9BZ3A/YieRdPPncg2CCFevawcUX6eltXJEGxsHCWy0t9bcbDW3OSB7bM1GWaLMlfriSR03xHrQQ5xYQd1dbsQFYVeLxslN5yJgu9UvKVI6hg 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)(396003)(136003)(376002)(366004)(39860400002)(346002)(66946007)(7416002)(7406005)(86362001)(2906002)(66476007)(54906003)(38100700002)(83380400001)(8936002)(316002)(110136005)(478600001)(36756003)(66556008)(186003)(26005)(5660300002)(8676002)(921005)(9786002)(9746002)(4326008)(426003)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VKf24NszFTp6+mvWF1sC1lgvCA2bK6drIHPPgHcTSijz0Zn/3La0iSMtdK9IvyktlSpfoHHKuWBj+dpuM6RtmqjIhe8lAKaDcfyhESdWfabrgUIWbb38/WFcxaZGaqGcRbh0U60X2lWmRj1RXycUmTmCvH2yG0cKkq9x+vLrIY1daZkfrIed6AJAShjx124vlGFE9Eujkf1yCl2X0gbrqchW2FLpgJDmWuon0vQieB5sD7UD5/bChbrm4T00Y5+nCEnmGvT88FTGF9mwI/ev9V4sKfJ1RyQkR2AFQoaIZlowOL+sGCnQFht+vjBSkflPxLiBIg5ZJQbZ1d7auRHe4cbndOn8/5Xm9L1eiPjYH3wn4p2AAAEtb6Z1snBofq0KJTTEHZbgn94g1YAKRkcsE4UKIaLuA6Am5hc/vUF9JZCDdvAju8hjdmRKnPPurI6DPrfSW1gBz3XkGZcGUg4kHXHNJS8jKWcpgpJmlplswWlMAuFfIDbBJvJYTaNSY33pNgGyT/Eq64draerasqpMM0s50dkvfCZmzeO7sv5O0mbd0hP7MVBSumVkPn4atpC1y3nuU0a8HZAAWCtAniMnzkxc9p/eZ3TJs4jmahWlm4jnaJzbEB0Tln2hA20QhvH01rIabV5pPYlDg2r/CuyXLfuT5A0TaJcSh7L2+qf26W1Cws35kqW2kKXb/mAzpZk2sHKxzKNsFaJF4/D9+/lA9IhC4qqd8S2xxdia7byUE4KWf2YxXs8bctSKHhldbpRSumTvJFkAmuosLPG3RpnjyrUQ7c4HCpgdmmf8ByYAx/Jyew04tbp8nOGkyTGf0BHnK346tIknzmN5KpVodx7KciTxfBHEAI+3yMkfEWZjrSRPYvt0odgrUnpVe9s1LrwbdoemB6gYTg4wjhwf6gTeGc050LSEGtlBVOOz/V18OZenm9s5Zt75qEK50pyexal2UY2ED6tkOZ1wPnCj3aPJaQ2i5pEe8jnhL8Pczu3WrzpaUQldHXZUHtPsGFCbcB8/0NqjFSHIeObRbN6CBiF0kVTzpPDnGVF5xtoFomkVFdPVRJpZqjUKgeFLoY6uMnODqYb3JCeasAfr5X09AS3Bya32bJk2b2drQLwYXvvgI7QRIBt6VKH/xHfJj7FBi6eAmDWNSm4Tevoa4+WocWdUY3MeTtWhiZX1YGWaxhD3PzdWW/a3nld7e46b3XczraW5Q0n5wDSdytY7ST39B64MWCwpJ7h1dU2dqz5lMcZcbryXhkFrp4XBYvwcwFJDffAwpbKm8mBSt+9eZhPirmDWp7ms4E1dk38/gyocAayZLlrC3rNovEwk+7EH7vw3ej6k X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 67c687d2-942a-44f2-5871-08d94ba5d41f X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2021 17:43:05.2018 (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: NdoOL+styLJQNHiZRvJ/2E5F0H2zJ6PacZgh+X0uYh/zg58WGcAwAIbTASMOlfrR X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5288 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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 Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig --- 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 Tue Jul 20 17:43:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12388967 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=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 6B707C6377A for ; Tue, 20 Jul 2021 17:45:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 513AA6113A for ; Tue, 20 Jul 2021 17:45:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233149AbhGTRD5 (ORCPT ); Tue, 20 Jul 2021 13:03:57 -0400 Received: from mail-mw2nam10on2068.outbound.protection.outlook.com ([40.107.94.68]:52928 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229650AbhGTRCb (ORCPT ); Tue, 20 Jul 2021 13:02:31 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RqzL8x0UO/SmddpwBNvlFZB4dClbcImqAXHh86Y6ntJWNQtJJQIpPbQtHwshkSpshA/q20Ada1JbqeZWuXo2tIYPic8loP8MKWrXwwlfjX/RIxkg/U83H2W3mLENe24ncz/vagn9LzSQ+nkCp9+AYbIdgecTN6LSO0Ve22raE4rAv31EJHFkEi6jhdcJaGfJlHgtPcwFOjO82V1Bky2kP/qF27t0GtIiaWkEKVpi+HFHe99zyAorEXbx3Oa4Knlz4InHa2dgnKS8J5M8H9eDJYi6U4glRX4Cy1HSG/gMWTzSkf7x4EEiCD7/FuPR+JyeWjZELsyCuQZVvzYcZxtNKA== 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=eJA9j/OugUqagLXMaaKxFUld5m4KW50elCDaxK70ehs=; b=gyeaCnvKpz12QdrWcOHY48aYnM/ure9+Q8SLRMXMV/bzj2TMWEKCqDmLVd4qlBYMlCLvMCPgjyFAmBYZ7+leLQ+XM39wv+8qer/PWEFhDNQpPAI5sk28XLnZNBUBF0f++RXdeSCW9xMu6omVgW3VFamBw2LbSV+j+MGjfe6tWTvfUBx7Y9bsJOJe/+KKo1dmCvA79FA185Fk4S8kYSbENrQLZ4m+c9HALzgKaBXOGYDBt5UVFmKf9eXPzubFYRwqeFfuM3z+LVxY/mdPmHUTajZKccDEDwhC+zNenVzRs1xRKegghuSwj2ogJdmRdf5iSbrYUXomaworRtbiAea0cg== 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=eJA9j/OugUqagLXMaaKxFUld5m4KW50elCDaxK70ehs=; b=AnwDS1ACvRDErN+oW/PzVI5Ef/ibK22ooahQ6bKXnBg3lrO6qpLtEykKXGzIL1FnzxOyXRUQ7NwX8ZyI4mIXZyZHksIK7IkNigC20bLri/K+Tqi4adcKmT+QBTb+DTta/GsB/E+lGdiG0AK6ta04uPAs4c1TVWeo6VsknFCBssa9VE0PClWDo8VdTn8njpD5BXaG9tn64ezY5z+9zZ+Ncgf4EEUbRNouupf88CMe/9hf3cWBYXlUfkocu4dOWMtEfn+e5pJGzEuZAewuzm79e5Qw+luv985LumogbjuQ8fCV8yvhAK8yCWpLYjD+RDPU/DhYkMvORjGLLGqh1vgspQ== 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 BL1PR12MB5288.namprd12.prod.outlook.com (2603:10b6:208:314::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21; Tue, 20 Jul 2021 17:43:04 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482%5]) with mapi id 15.20.4331.034; Tue, 20 Jul 2021 17:43:04 +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 Cc: "Raj, Ashok" , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Yishai Hadas , Zhenyu Wang Subject: [PATCH v2 14/14] vfio: Remove struct vfio_device_ops open/release Date: Tue, 20 Jul 2021 14:43:00 -0300 Message-Id: <14-v2-b6a5582525c9+ff96-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v2-b6a5582525c9+ff96-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR05CA0020.namprd05.prod.outlook.com (2603:10b6:208:91::30) 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 (142.162.113.129) by BL0PR05CA0020.namprd05.prod.outlook.com (2603:10b6:208:91::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.13 via Frontend Transport; Tue, 20 Jul 2021 17:43:02 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m5tll-0051FP-TU; Tue, 20 Jul 2021 14:43:01 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4842e168-0cc4-4db2-8f73-08d94ba5d2cc X-MS-TrafficTypeDiagnostic: BL1PR12MB5288: 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: pEtrm5ZlK/1uDeaYOjQYJN022DCvi1VSlKCYKAYHPQaHXJIkrKyY0X/ffFHb6N7ohyKMprydIfwGdONBDytKrmEZ+ySRHWL0Y2i7d7xV4nHfeYVcQO10F+uGCP9Rp3GIQ0+vvlBg0eT5UKHGd9j43/WYzKm2aQk/+PbKkEkrHINlI6ineU/L3Llxwc8BC+vhrfeoxZvLLQU+jNH45b0nt+4VDe/A7+G5KVsuiY93JnXhhcHSB+HOpuLUEzyzq1sjt7iQ8/am8efRdP9MUeGkykr/BrDoeFzaJWWpg0+fcThi0yKVLipkRby5H5nnLDkyaur43ucl1v7mbT3pu7idxg2Ey8YO5iA38eOvXAim52tEcmVY47pq/UgjCQDZOex5yXOEf+OBhy9LU4gEal2qOTNbLDMUK/NeLg01GgoKKiCE7AAdiYMWXvgcTkSRMOr2kT5/olfWPbi83E03edPp3ajF2m0lgnEqQr281KxyfQRDAHqFfXaAKG0wMutNG3vF7u5sEB7+FgBmKr3VCrknBOJ7kPcF5oH0nWzG94Jckl0LAsncb0UplONuGkQ7GWhyQB6Pe7GQoTqn/rsLgXhTHr0PdFIPuAcQsJDUMEvEZyrQWebFLhGSIFL3Vgkd8xyDBAfKWx+8OPYW7/b7vInEQQ3V17Rd6QyiCM+mv8mF06JBcMKmUDJNrfMEVWBNCUhe 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)(396003)(136003)(376002)(366004)(39860400002)(346002)(66946007)(7416002)(7406005)(86362001)(2906002)(66476007)(54906003)(38100700002)(83380400001)(8936002)(316002)(110136005)(478600001)(36756003)(66556008)(186003)(26005)(5660300002)(8676002)(921005)(9786002)(9746002)(4326008)(426003)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: SPWhJwl+SG9TIhUuO3Y7abLy+0BRFwCudQ7LUOZbARpIdu+9UyM7VjzMA9hbGJqHEUBbWs4iUeTf1HxW+/e2gsjWcl77v/v6QxMX49PdVNW7UA2vlHhjTJnV/aoLhNYqsnEW3Lw+wSdFQsKUIq1eh5bIMrfdfEL4QS7EMqoU/s/zrMkvdBYv64xkYMHcnfK3sQKh9Z2qgGLnZtWTai5giA1GKewosYYM6vJNgsgfnazc2fCk6zmyYmTOCmdkPR8eN+sRUgv+pVRa8rPH54AmFnqD3YFAKoRI1eZqTMBo8Lq+5Lqu3qnrpyDTTe9jiQgMSAWbogFB46qeu8F7H6vDEnkLnluYFJKuq5CpyC22dGnH2lFgr0Z8L+v5soFJClGQddf3a7FxvutyjA1nwuZ8lF4W90qYtrhkR6l06Mg1Z5c2p9vvGWR7htHrsqt7mwULGhRldvG71Jr1nvisLtKESXXddyjZU5+iIqS90JCLJr+WEAx5h0bd5dOwug1jnduDSFYF9HERKxwwimhIAdqBeR9VoF/yILWmvhuN4BHGhkmX+HZaT0XId07P3bBLoLtpVjDkbz5GcK/o7ahJ4SDs68jw7nHsxhAW/q6ZMtrrlvVSSekQoN3vAxEma4tUNtfEgvJM5zvO1YmIhKj27iQ3DkxYwDO1KVh3PrzrQCW3/D3LsQIgvmjakV7HPR32jzxlBkMKmvMg3DOCJVoXPod2CFB33qspb0I+ppEOs8LuhUSrOgP8XX7M+r5vNbt2hpCsaHytS1JZ6MIyQGIg3Q5CIiRpkPHJnSk5z6LbkpYvL6qS82IVXfKMG/WDOEl+f6Sl/PAxXlKgqJAx5xTQgJyCm91HuHicTYoWGVJAGtOUAvbAAYt0PYVz8t85l4K7cDJUtpRLBn9QOtM1qJVYitagWVRFWoli9mayeAlQQDy7Jxmk09RrDfk9VUKtKUQd13ZNfxFdzzbZurmZ48aB+uEg7UHB42rAFvMPMFI4bfbCONGcIHWMFaRX56hy6Fe52oAeFNoX/XaR7EJakkXUGQuG0xGbyvVB5sjW7veNIEymGTsrmoHQnxOIEcZ/BC6fOBBE0oD7kLFklbe2OQazwohHrIXwOXHx1348FEpcKByi058YFHSoRLSyktqsSmO/NEObsfYmtb+OF3N/J6GuJ3/M2+csPYx6lobN14ErcEXLBnF1Nrh4rhWLtG/FHl6bgLY/Yc1MSuwmRFklkNUP2UOTMcrgr408nOZCuEVkXNUAFgWYNGOuWl74WYzMkzcTb2RXm5DACIZ75SWYPZtSrnM/0qkn7n2rKcqQkUoWkUVHZzKMTHU33ul9AR6rZ4ZglFYT X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4842e168-0cc4-4db2-8f73-08d94ba5d2cc X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2021 17:43:03.0254 (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: 22pEo8/Y/WIs9Ap1P9GySkOW4gPGsyy4RblxVqQhDbHoA1WYnWj04Y/KOEeTw3lp X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5288 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Nothing uses this anymore, delete it. Signed-off-by: Yishai Hadas Signed-off-by: Jason Gunthorpe Reviewed-by: Christoph Hellwig --- 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 7e352d68b1b01d..bf06ab2d536997 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -1477,19 +1477,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); @@ -1516,9 +1510,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) @@ -1666,9 +1657,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,