From patchwork Fri Aug 6 01:19:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12422483 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=-16.4 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 67AADC19F34 for ; Fri, 6 Aug 2021 01:19:26 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 25831611B0 for ; Fri, 6 Aug 2021 01:19:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 25831611B0 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 9D3E56E8FB; Fri, 6 Aug 2021 01:19:24 +0000 (UTC) Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2074.outbound.protection.outlook.com [40.107.223.74]) by gabe.freedesktop.org (Postfix) with ESMTPS id D59DF6E8FB; Fri, 6 Aug 2021 01:19:15 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hwASJRsoKGvyilfGbs99/coR3k5axUDFln++LzrWgoP1fPYmr3uW0jjsHdDcflQ4RMnxFz8GnBIfRV1hSIgeehEBUaMF+10LH9Ky4DK0t3ncI09qoqC7McROpICHwFPMZ12LGX1/BQJYMTQ8XzNzFfy6v8KQQ0HdghjsuvzMpEyZX/hPN9JyZ1fl0p+mYOB3IsOBOmcWPfMGmOIw7Uc9RQMw4/PFpXCOdAbG4uk6AoSIqNRn4DthC9WeKN/5tCf78UXhfug9VHIe8E8p4R/sS/6/5eE7O+ihrOZTE18z8zf3UYiCsZSl2N1LYDtMjWgt341ijyfWX0nz7QLK+SJDOQ== 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=ZYOiw0LCqAhzOoJg5UuBRyNMa1qAw60QwOAKEcSqffc=; b=cQA/Y9HCH9wblTBJ3q7j7THzH7Nrjqakf31iaN6/4DtMmv+f9f52qvYEBSdXBlueivFOY1ypvZieuYDxX/bgTK0VHPYEruJeljSYGKVvxvpl5kSpw/PZP+Qy/QxsJPuqpO1Ad/sOYAIHb8VYOZQbQfg52ZTNKKhbTmcjCZrfPvQv9Sox7pDT973UhOSvVMqnCKjjHF/PRBJGBcSQWEvaP3LyxRTd4x1e/DwpJ2e41BiDC3TKD9fdv2tkh3eZWgmMvY9R86aVFTQOvsvSiWzAUw2ePOovm84iyQlblgjT22E3ij2X4/PETY+p0ruzohF0fAQeRuXw+GlZwg6ZYLeiXA== 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=ZYOiw0LCqAhzOoJg5UuBRyNMa1qAw60QwOAKEcSqffc=; b=UJJeUVfrYggKGlfHnMkDap92usGvHaaF/ddeB/zxnj2e/xtAqLpyl0RteTB5Qv/WI4X3QXizq+rrW25F2/h55IXFljWwCcmco6wAEk9wYwnHofmvsNdk3GuG4WxdwbqRg7qI4LzV65SbJNhRIyKSMx5Llw7luZGUXbIaWvyGVWK90q6iuPF7gE5y8jCFQ/iXx1Wc2BgOhwC49PQHkE8bBhOVtHTEY8Qc5ZFRtkgUj00H/aSnLZUyPEbRnQOC3H8hSFEZ/568RPGqmoJ/74lO1+i9p+ccH7YYXVmXR/xKWK14vYmZrgxtlPCsPZhw2FFGOAgP4iz+HuQFb7BPHWKlRw== 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 11/14] vfio/mbochs: Fix close when multiple device FDs are open Date: Thu, 5 Aug 2021 22:19:07 -0300 Message-Id: <11-v4-9ea22c5e6afb+1adf-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v4-9ea22c5e6afb+1adf-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR02CA0057.namprd02.prod.outlook.com (2603:10b6:207:3d::34) 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 BL0PR02CA0057.namprd02.prod.outlook.com (2603:10b6:207:3d::34) 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-00Dt7W-Cr; Thu, 05 Aug 2021 22:19:11 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6fc76214-a49a-47d0-da49-08d9587832da X-MS-TrafficTypeDiagnostic: BL1PR12MB5206: 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: /auhA3zVzaCQ/44jT+EWv/g6VCKxNEP91itUNbIJWHtGOmMv55pbH0ccCgsc7E0wr5F01OdJJ1lcGE50bTsZKHMzBpvc+MmrBQsZBYuZBOmNoAOetY4ShMscG5CsCNd+ZwRgUWYwzvLx23CD/Ai1gtxaPwq/jGkWwOJLM17lYaluIrWVHaD4Qrlmgs1amGfaEzxmL39z3Kdw6RI88GGIdkG9nIXIaWJSN5mvRwbxAsA6sg69wu97bMI3XuBL241KAvQEShDW+pO5OceuA48ewhNo5nj+CNR9G6P3S1h+RAAnRfLiMQrUvU8pLZb62d1IDkgFXiTNYHJ740999DMcfok4zdtRxa3ooQNYlnCbG2E2RqOCUNA9b5HMJ0vJKi1jbo54mAKKfJU68fgg4WSrS1y8ZCtWPMFKmIUaRmKJkhZEnDEvjLGeBrol4dualjRYU72G6At3PYlfvkHxydhDHSuqCyIQahLjYjhF23NH6hfuzziyTQQ+/cWqNYBaJpLu84NUrHZPyOyd3r2zUIdrSGR9fIMQdiwl9B2+1gLAEucr9EiCM1Tv4ixN27QnNxgX1IjWCAPPL1o3W6oKGR0h/fCm+Ep6KN30mj7Z2nuA67stRUreuwqmnDICLcs9Ws6QeKdSG6Dsi27O9fba+ETLxH731vcaMmpizbldUhIvhHjM0CcyRnXekNxW5AycUsoT 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: KDGC9467/qEblDkRJzIDJ41P28c7/ohNJBVwP0J3SQX7t2SxFhw/V6bjJ9zjYxLBqXJDdvULjTO6qQyikbqt/QyPk5NOK4iLqqcMFJ6mJpVVfo1hjRSM34QMKPYH6NcB93dMhqvzfdHjYRNmIbm9E5tzCsl3ghreih5v5LpnlN62nMNILx49X6C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ek/Z3qal/tMjHBoThn2rE1fZ966/rtvI+vOKOuv0aV1SV0CobwidoUAbCT88ueY86onoTU4gmD0FKThz8EpB3gxLfzn7u X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6fc76214-a49a-47d0-da49-08d9587832da 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.3792 (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: KeZVMsalDXltvClbAn8ICoaYqbEIq+HOj9CXgJMAbR/7k/8ErG+ykn7UWfZfP2WG 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" mbochs_close() iterates over global device state and frees it. Currently this is done every time a device FD is closed, but if multiple device FDs are open this could corrupt other still active FDs. Change this to use close_device() so it only runs on the last close. Reviewed-by: Cornelia Huck Reviewed-by: Christoph Hellwig Signed-off-by: Jason Gunthorpe --- samples/vfio-mdev/mbochs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c index 7b2e12fe70827c..c313ab4d1f4e4e 100644 --- a/samples/vfio-mdev/mbochs.c +++ b/samples/vfio-mdev/mbochs.c @@ -1278,7 +1278,7 @@ static long mbochs_ioctl(struct vfio_device *vdev, unsigned int cmd, return -ENOTTY; } -static void mbochs_close(struct vfio_device *vdev) +static void mbochs_close_device(struct vfio_device *vdev) { struct mdev_state *mdev_state = container_of(vdev, struct mdev_state, vdev); @@ -1396,7 +1396,7 @@ static struct attribute_group *mdev_type_groups[] = { }; static const struct vfio_device_ops mbochs_dev_ops = { - .release = mbochs_close, + .close_device = mbochs_close_device, .read = mbochs_read, .write = mbochs_write, .ioctl = mbochs_ioctl,