From patchwork Fri Aug 6 01:19:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12422515 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C4CEC4338F for ; Fri, 6 Aug 2021 01:21:34 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3FAA4611C3 for ; Fri, 6 Aug 2021 01:21:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3FAA4611C3 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 03E7F6E951; Fri, 6 Aug 2021 01:21:32 +0000 (UTC) Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2053.outbound.protection.outlook.com [40.107.92.53]) by gabe.freedesktop.org (Postfix) with ESMTPS id 593C06E902; Fri, 6 Aug 2021 01:19:19 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bRqgyDPLn8PTh7Yrz2QqVVPigP3YsbpVwwXSbr9EjjYOXi1FcS3kfQtqFE37D2n2c/pyT9Duu0m/iUcq2MxmFbf8dU+HuiA0Km8pPRWRY0CUlySiZG5F7LHaKh+si7sQ6s+t0IR6Kz5Jtn5meq4EBgHjxm2FaitvneUYnSfWYOIdQL/i48gZFvbfjuXiZbs/7uFBCG9DVfzUeO4QpdiUm+t5UmpEA09PMOPQ26Hww1iIDW/Y6Jaz11YjdTpPbxNHOkKoiKK+ouL5iSHK3M0aprRHESQJyCr6TYPoVBnwSs6fEnGDZlKu+KIc/kxo06WCunIughFVQxTFGeT0Tkc7yg== 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=OMjiMVD7ULtpq1Pd6nDXaqM+jFGdR4bdw/pr+HTq65hYI8yogpDAqgmT08OefdOWE3EpTB2oVKTEJVXbEy2UYX1pKLZ+Ssg9vNcYMjIECLXy34huvF0+XqMxPGVzx0ofT9pIGe/NHGOrM4WFTGnpW9sXgsOgs5dZ7vpUj7cjW9hl5DDs5UEW61+cLvRXcGXMpNO6aD61KgqR/NMFuux67rgb4xnfesvrRJust8Mb+cnaIu+dKoMal40lyt0r+8QyKOcVtaSTgWTa9tC1sUTII/y5UJALjvhapgjqHesq9WFHglw02Cm/mU297KvHBVDetUGsvNRat2VFNnEHkG7PDg== 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=hRkRoYvjlaoJoxCbPkNNbD6Mvu64hC1Pai9rTj8OoLjdVLamUOGN6xyXqxVasZMLTls+9NE1WBYQi4ca0gy0YV7wNUYtp73izOSVDaE00YAKC+zytxH8fwAatuFFk2adyDGzjXpAdwdi6KsgcxbilaBfLKHbrhjOdr5Nb11UNzd3lMEBmYb/CjCRHi06NK25lnuq5yY+Ev5t6sdh0GbTYyL4oxH3Aj40dHLjbTSnd3wTHjpJ44rarOIIbmDpJEOMVpdQkhSUNYsKHZm0Pz6Qdk2x78amKSlWju5Y0vSF2MtpJQOtrm1hixvHtglh4MfOL5/CK96t+i4S+VCNCEbegQ== 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 BL1PR12MB5206.namprd12.prod.outlook.com (2603:10b6:208:31c::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.21; Fri, 6 Aug 2021 01:19:13 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::1de1:52a9:cf66:f336]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::1de1:52a9:cf66:f336%7]) with mapi id 15.20.4394.018; Fri, 6 Aug 2021 01:19:13 +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 v4 12/14] vfio/ap, ccw: Fix open/close when multiple device FDs are open Date: Thu, 5 Aug 2021 22:19:08 -0300 Message-Id: <12-v4-9ea22c5e6afb+1adf-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v4-9ea22c5e6afb+1adf-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR07CA0003.namprd07.prod.outlook.com (2603:10b6:208:1a0::13) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (142.162.113.129) by MN2PR07CA0003.namprd07.prod.outlook.com (2603:10b6:208:1a0::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.17 via Frontend Transport; Fri, 6 Aug 2021 01:19:12 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1mBoVz-00Dt7b-Dt; Thu, 05 Aug 2021 22:19:11 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0265e3b2-c582-4d54-87e5-08d95878330c X-MS-TrafficTypeDiagnostic: BL1PR12MB5206: 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: bSHMcXkOCg3iSSPzTxHcyVqY7ZMBctNsyCOhuUzQxfclNoVj6kS55/BXgPaFfA21pEzuq1NbSrWc0DBGjeDFICcC+op/QV9dQBgrUTL9tMRqXcrDFNxZSgGirrMC2TGJ40O/vmbj0XY6NL3VDh94O50VDVw8eatpQz6k/m434yuGmeqbMtz2b6X5Bs07OrKk0PTpRm7CSKVwL+2QQJSL7hqd5q7OLS1XXXyai0dLuTNKIwubt4slmx6ymMUsBTpU9r3QTVQEdqiZzk/6Zbxs2RNTQkaikaPLW0DwGYkEa1/TTkC7NmDGs8/Vi9ruCfrppOjTQuZHkLIv3inBHRdhHiv+8st0UU6gwEg1ql6fVYasIVQxvDSwh3Io/rZ4k+WUGgM44X+bWX49EBfOGJzJtPzzryl0iClw8Oads4Gtjf/oAOTWUK0iGa68BXJR52eukEhxxqBgEhHPYkxaMylhfl1xS3R5uwcOYxHOEVO3a5e4DHovws32kDh1k0GhLPnsJMmHc40z2I8KMjFwLBCEUSZEySqFQ56HM5DIUaZaI1tApl5H3Wk2Yd5CZ8qQJc/l0bA0va4lSmVMKlWjVr0SBGDyKZQWi8VeCnsS1dPqV2cBtHrCWhgDUTuo+FtCbdxoFuwt/tjDruGT88rHkJ0PtVB2NWnWCAC+IshJvmVgz9Vs6B8oqg6uWwFO8Cf7F7uD 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)(366004)(9746002)(83380400001)(86362001)(9786002)(8936002)(426003)(2906002)(7416002)(38100700002)(7406005)(66946007)(921005)(8676002)(5660300002)(186003)(2616005)(26005)(36756003)(508600001)(6666004)(66476007)(316002)(4326008)(66556008)(110136005)(54906003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: feL0pT6rronCCs9j0+1zUphWrFGRBBUm4lImNknZlzJwh+Z+9W44v/LuHPzu5MCij1ucg79g/kczmxjoKCRGe2cnGIocK5SmPceWjYA9OgMz6n0VB39egN1FYybeiOy9UJ0PE1l72j7XTCBBrcoBKkDh7DxM5rNM96uoT+ZhTZz5PhR0IHCDL7UV2PhD+Dcf/nmcGJh7C6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pPosBPGXr6GQh8tRLz5j2sTMCoEpSdxxwODY5BBX5TZi7TaCCunLDV0TiLKZ/9FwMx0ksxdNx X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0265e3b2-c582-4d54-87e5-08d95878330c X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2021 01:19:12.7017 (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: AbSJGDM1DcrLi0wNYsXVf+O9tjxDG5pND/ZI/vG0IpexbMEFZJTdVNaqT8VQkqR+ X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5206 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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, };