From patchwork Thu Jul 15 00:20:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12378129 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 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 B28D8C47E4E for ; Thu, 15 Jul 2021 00:20:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F341613C2 for ; Thu, 15 Jul 2021 00:20:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234332AbhGOAXp (ORCPT ); Wed, 14 Jul 2021 20:23:45 -0400 Received: from mail-bn8nam11on2068.outbound.protection.outlook.com ([40.107.236.68]:25056 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234624AbhGOAXm (ORCPT ); Wed, 14 Jul 2021 20:23:42 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g2Z/t/07UclULvm6Zytb0LMXAAHHKxsbPZqgKXf+xKSY8mhRQOnBwRP5DzljDthMfX8PdTJVsoiBdRLZtVpQg+l0Q6mfxdZfdZMMW2sGemI/jI28BdZdwYFZajPb7Wi9+fU5HJjH846j0L9lFGKgV/RhLiWuvmQnSNWvYB9eZTygmDXgrZbczMpQ1eK6SC5c8lATe2G1HLGJeTPgG5BRBt726M7ELVGycS2XHOcGPsLFTacfVwjQClKSUCspDirBC7b0jEOLrW5yglZkY4cQhJ5DipoAY+uWYK+mAz3E71066qk1hsGrlLgfaS0uQzKMGFlsTlwsQfQDx6uNl6ud6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8TI2Ea3BCnpMJtPQTi7ZpZoDXqgi9wwRJ0CJqM3YOZE=; b=QrfHbt6vvY3sRGZ2SdIXKS4tfhC2kDWYo5dJWoUmrd6gaLglafISQmN7/FARi32QlQC5MVSn3Vy3KgMq6Uo46bVIuhgokk4XhycT9vliGiYqaQWwyN23DywzFBexVIbzzlmlgWQ8QUskVl6mqCNzK8kJbuwTBAJ//eEvDNKQr39gVbcTX/3lbt9VN97kCzPiaVkKsIqUnOnR5MQlo4uaMenM/E091qwUR9TC7qPrbL6GsLOWf4T2yxV9r3AcRWRW7ZNNxWVf/BZhLB1MPmobSkZ9O+0rSwULprFBt3qgYgtVlBZx6GadzmaIg3E+mm9h1n5SLC1yDXnQPBhJm+9oYg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8TI2Ea3BCnpMJtPQTi7ZpZoDXqgi9wwRJ0CJqM3YOZE=; b=ifIyfs03qlbfZ1FQBeQyIwt1/NHj30trE303NDNFCX8ZUzhrOgk8XERXg4qywCh98+I/lMxkGP6nd7Xe4sPiaP1TBVCS6cq2VodQRYfILXm7oZKRYOA5qSFBsD1+MO2PJSBUcCdeh9y+mukRf7LpgW3w4JLyrDIsbeY+XokXQEEL4PHVEccOE0c/cRlHplVKzqZwbaE+ZvGpnJdVJ/RuASmW0MKby/WAtcvv+pK0raKwhmrr9Pp2t/Gkku72lcrQgDA6FL0wwdaS4ZcKk0sj7000edGJnuTrqgFWdCTLA91Rq2Y0Zi2jEONcEB2BjRczVUEoZsmFHOtELr77D0MJsA== Authentication-Results: linux.ie; dkim=none (message not signed) header.d=none;linux.ie; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL0PR12MB5555.namprd12.prod.outlook.com (2603:10b6:208:1c2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.26; Thu, 15 Jul 2021 00:20:47 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::d017:af2f:7049:5482%5]) with mapi id 15.20.4331.021; Thu, 15 Jul 2021 00:20:47 +0000 From: Jason Gunthorpe To: David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , Jonathan Corbet , Daniel Vetter , Diana Craciun , dri-devel@lists.freedesktop.org, Eric Auger , Eric Farman , Harald Freudenberger , Vasily Gorbik , Heiko Carstens , intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, Jani Nikula , Jason Herne , Joonas Lahtinen , kvm@vger.kernel.org, Kirti Wankhede , linux-doc@vger.kernel.org, linux-s390@vger.kernel.org, Matthew Rosato , Peter Oberparleiter , Halil Pasic , Rodrigo Vivi , Vineeth Vijayan , Zhenyu Wang , Zhi Wang Cc: "Raj, Ashok" , Christoph Hellwig , Leon Romanovsky , Max Gurtovoy , Yishai Hadas Subject: [PATCH 10/13] vfio/mbochs: Fix close when multiple device FDs are open Date: Wed, 14 Jul 2021 21:20:39 -0300 Message-Id: <10-v1-eaf3ccbba33c+1add0-vfio_reflck_jgg@nvidia.com> In-Reply-To: <0-v1-eaf3ccbba33c+1add0-vfio_reflck_jgg@nvidia.com> References: X-ClientProxiedBy: CH0PR04CA0118.namprd04.prod.outlook.com (2603:10b6:610:75::33) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (206.223.160.26) by CH0PR04CA0118.namprd04.prod.outlook.com (2603:10b6:610:75::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Thu, 15 Jul 2021 00:20:44 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1m3p7K-002Uxi-SQ; Wed, 14 Jul 2021 21:20:42 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f9e3d6f8-eec1-4a4b-c607-08d9472662c6 X-MS-TrafficTypeDiagnostic: BL0PR12MB5555: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2582; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uuZ3WE1GS8Qf9leKhYqh2ACY9H2dWiG9291zHTadGdj78FDFrwCCcPZyV1D3kZ9Xsr3TaOQW7WL0RLebEEpJFFlz82BjAvOOKL7yR4W1WkVC/gRsHGGfmER84+YD8xUxu8elrBDyjz14rRcjVm6/XF9qF+G1rGGhFKQ0HyK47zM8095iGRk1+KFM9wJUEFzhGFcEw+tikL6NZ3KbdAF4ESE2KIBj7j82TAwrq+ZVWTOE88q/xfs7e6OLYMY6in/xZl0Wa/hcbEz3dwCCmFz/elZHIwkumSV1wi4YrjhBaOsse+iaHIlyLpvnOojuAI3UGH0C02DH2LhotELI5q2QSMRWVHS46jrjEKl3qX4kjzAvo7iGGZLtTL0G4jojPLxnfCB3s9oIrZR/xOWA61e+EdPl2C6b4181y11k+2kEpqptz387ZP1QzzpDZv+Ji/ApZagmvVkcGOC2BPi0pbPMrnY5rwcGFC8hF8ieaggFz0GDDQGC6RS59Kcdku1UWHQpEQmbOMexrBb7Ho5w+MLmWECEfokMnuhG43v1ga6Zsw5mAVMTjby7X2pnZix2pMZKkQAKd8T2RI8ryolwn9lxlI03O69Nqab89M2od7pYtjJlQGAkbn3VBfg4+UJtdno4dZVS8aD8CZZIkYKoGLR+gb+yCwZOL41A3xVwJFZhd1pDBXqiC0OMGTc3N8H3LMd6 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR12MB5506.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(39860400002)(346002)(376002)(396003)(366004)(83380400001)(2616005)(426003)(316002)(107886003)(2906002)(478600001)(4326008)(7416002)(7406005)(38100700002)(36756003)(5660300002)(66556008)(66476007)(66946007)(921005)(9746002)(26005)(8936002)(110136005)(54906003)(8676002)(9786002)(86362001)(6666004)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: a7UCNAQBOdzXVo/gdEQiiptGZ0kfwpD9YuJz6vhr2yxu1i0L1kKGwoLGLe9OR0PuVukpk9GbdXt65Va9PscM146HzT82n7o/n24cYlIuXMEFCqn0kGmGDLRYnzSO4/knLMBNB+h9vUIWGY4eQRUj0C9RWRavupXHmVIRYfegdIz2DVdjts5we3d9rbZXZMo6CfuAVQ1tLUxi8p4NaPMGc+W5mMJqmTN6zUPib4s2LYk8jKMtKsBi3SwSjMQzwu3gYjE4ywlDmBLAgIPp5uTYoeXquGJGI5l2pkviw95xxt2IcFCnYgifYWnZEJbAEpC9B7Vg/B3SV61VsuoOGFHjjcLKYyOmRbFhG7MjSz8vLWEdgN/BfJH9QVxxKROBIeJs5XDXMZVpZ17by4UWnuc1l/VvC9U8SJ62dOO+2/FPJUKuhXSbikcg99cIfa1nH5nVKV9PO3TZQj0PI3ZPfBLlHRjE0A274HEly2b9Hmj23AnBcQPiNkZzAdDvRU3aZVMAeU3o2gBC1+3DXLsVt5K8rW5G/ypJPRSn4E6mUftpMCW0mkwqrvQcsBv94ij9LkmM7cuLH2+CWsAZ5pj9ll62VEpXFrRoWoIE4bz13MhhNnFFRTaWG/Ow7EDAdfRgfncGP6nvj/shfpnloQBLC5ThusKciK+O1iIo+h1rPtS4vxY7kX7hJn9L1LTL06eCLaY/B5kyX3E6crkw5BVVxbRPt/5PLym8iVDTEu9EMoO5OtZ/HJBWmcK8afQ2/tS/Q/yOWjXYCV8lyq9GlZuLOBiSTtinN6OffJUYgwFLZSPAaSblu+MSGc8BfJOe2hR7+G9X3qoLhVLrc9+lWdQraPbQl2wWuiUPv9RP27uvi01zXQ6A3sLpoCFX7oMl0IjzqwF6vM589Xjmlz2nmw/hmgBhbDrX8BgdpGTs04fsl1b5hKAJYw20S5wvKtfFS4uxmmnSXZNDLxTAcbRIzcsqbaz5m5hgdc748aNO3SDh70BAWZls6rcaiiDGvgS0raSQefnR0a0fEdX1LM6zlFXo9VH3bmtCYfkRaljSGBJUsj/XWhqVKAcNGCnGnDPDaf1uIamuJajDNBCBVQxHdPNkuwfsclpZQN2pwkafZsYeNSwPDJ7koxHog/Wrm1BFFQH3UevjIIeOtFtWLiyHfITyr3L0HYmr5z5o1gmGNL78IdJ5bPu9JBaEWIlAQvxt+7egS4xAn1K4koFJooGFRjOKctMjqEPKU1LPKIuPEvOfElgNb7FyNnR/GH5V3U0j9/J94AmNcHkmd8DG18zakG96+V19qqPcvM8Op6mIH8fJsNzQazdvb47oW+qaFBL1VJzgThDD X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f9e3d6f8-eec1-4a4b-c607-08d9472662c6 X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2021 00:20:44.3359 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Ki3GThN1F1zFf+p+MLpbwMRfPHP75T0Oq7KuM9Q5yboKmP+EU/Rpi3EOsBLDN1NF X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5555 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. Signed-off-by: Jason Gunthorpe Reviewed-by: Cornelia Huck --- samples/vfio-mdev/mbochs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c index 199273bebcc0e2..0137494c203aa2 100644 --- a/samples/vfio-mdev/mbochs.c +++ b/samples/vfio-mdev/mbochs.c @@ -1274,7 +1274,7 @@ static long mbochs_ioctl(struct vfio_device *vdev, unsigned int cmd, return -ENOTTY; } -static void mbochs_close(struct vfio_device *vdev) +static void mbochs_close_device(struct vfio_device *vdev) { struct mdev_state *mdev_state = container_of(vdev, struct mdev_state, vdev); @@ -1392,7 +1392,7 @@ static struct attribute_group *mdev_type_groups[] = { }; static const struct vfio_device_ops mbochs_dev_ops = { - .release = mbochs_close, + .close_device = mbochs_close_device, .read = mbochs_read, .write = mbochs_write, .ioctl = mbochs_ioctl,