From patchwork Tue Oct 25 18:17:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13019672 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C484FA373E for ; Tue, 25 Oct 2022 18:17:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232720AbiJYSR1 (ORCPT ); Tue, 25 Oct 2022 14:17:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232563AbiJYSRW (ORCPT ); Tue, 25 Oct 2022 14:17:22 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2085.outbound.protection.outlook.com [40.107.93.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBF8ED6BB3; Tue, 25 Oct 2022 11:17:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jltL4NFia//kVX6S/boPq1+j9SeA5DpsvLZeUai7cmiYwY9AeILICeXZVLUc+Tu6dfNyIu/WqFRO3t3qimBOQIXx/+Q7etlWtgK7RdPrW/2K/v0BvVcwBox+8wkqANaytuz2SkK4nsIi2WdREGzYSYDRfCQv8TPZ5T1kkicbtSYBwjM2Bz2fPSsDhgY8g3Mw0shHOTVuBa3I2r0Vqfqwu2C6HoEMWPEle1gppBu10GkvSaBynOkZ81n0j98ZpApbTdTMKKiJaTi3CFajThqXD/KQe098+QKNP6HGhOmaPOu1PFhsgRVq4M8qYbeh6GobWfV/40BRRJKMXVZKAwTyBQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=qqy41RsJ59plGnr0Sz/HYmsF1ZxLtZtCZq74kh633lY=; b=k5gRD7/V9pHNKoO92yisWqoKWYx2Ef3nCH9+s0guPb1izdo4NKu6C+O0rJmN6CN8Vr5tWp5kIVKRajLbuRIMEeoqlXQENC6FQxix51yI47kqxJo4oQxIzTeq04tEl9x0EXVdG3rmYaid7N/gqM/xmK48lZEnZw2REThA6RxLFa9ctbIAPds+CTkuPpbIDm/vtVBn2tAJYnGQVmZl3brFAaDLdWdQz+ZQFWMdky7YovItlGImAPxrOX/S8NlyXP2XOCKy6ca7NMmY9z3fFJAXZ4q6yTiiA5eS7PhV+D5yQR1SEv4sHV0blCZfb7bsOfmQ9NULSycQV1XOBv2l6Dc2JA== 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=qqy41RsJ59plGnr0Sz/HYmsF1ZxLtZtCZq74kh633lY=; b=tfeOYq6/4Oshc6UTe3AvIN0+FrnJ9Lneoi2FA4VlDMWH0JjeTygEvNem4ZzWzR/JSoK0nIpgXrITHdlGZoLUixqTeBoBwDClgOjVx8pjwHoFFemYnXddt9vuMOLi+nXvqACWZLFPdbQW64eDNNqw81Szg3zWD7l6e51Q/9VEgJ6Jn9X3ynxlHLm/NYaV9QULh/eXQMRWlemUg9FeX97EWIYwHAaTbxkV7fdw4bg0qy8Vdew20n9X7Xr9KzcvZNeyk42+gC3sFZkigX0oFSS1eM7Qf3sXPBcrOUjA7m0COg3X+qFXJSRgfKrkXX+tWRJZNlR6nXyXX1Mjz6y4Y7CGTw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SN7PR12MB7201.namprd12.prod.outlook.com (2603:10b6:806:2a8::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.28; Tue, 25 Oct 2022 18:17:18 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::7a81:a4e4:bb9c:d1de]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::7a81:a4e4:bb9c:d1de%6]) with mapi id 15.20.5746.021; Tue, 25 Oct 2022 18:17:18 +0000 From: Jason Gunthorpe To: Alexander Gordeev , David Airlie , Tony Krowiak , Alex Williamson , Christian Borntraeger , Cornelia Huck , 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, iommu@lists.linux.dev, Jani Nikula , Jason Herne , Joonas Lahtinen , Joerg Roedel , Kevin Tian , kvm@vger.kernel.org, linux-s390@vger.kernel.org, Longfang Liu , Matthew Rosato , Peter Oberparleiter , Halil Pasic , Robin Murphy , Rodrigo Vivi , Shameer Kolothum , Sven Schnelle , Tvrtko Ursulin , Vineeth Vijayan , Will Deacon , Yishai Hadas , Zhenyu Wang , Zhi Wang Cc: Lu Baolu , Nicolin Chen , Yi Liu Subject: [PATCH 03/10] vfio: Rename vfio_device_assign/unassign_container() Date: Tue, 25 Oct 2022 15:17:09 -0300 Message-Id: <3-v1-4991695894d8+211-vfio_iommufd_jgg@nvidia.com> In-Reply-To: <0-v1-4991695894d8+211-vfio_iommufd_jgg@nvidia.com> References: X-ClientProxiedBy: BL0PR02CA0130.namprd02.prod.outlook.com (2603:10b6:208:35::35) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SN7PR12MB7201:EE_ X-MS-Office365-Filtering-Correlation-Id: 063380cd-945f-465b-3081-08dab6b52643 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AIdbPsTprh99gAget98F6ZXbDdEKPLc2/HO4/Q7ey7CwILX2XCGCBFwM6jDaaRRBBeGvuvIn4mfrITaKucduji+E73zgmthROm+X/kL6Zfd5E3XJrYsKnK5Tv4ytcgukiE+wyQeRM1icqntghoycQjFVXRuKm7At0G55OQ1SFWXNUS10Vzz7Uvc8s886zB7hZQdyWSlC5iuyVIhssAi0eQbU+QWNrkdpNqU8RBUa89+yhQE0l0bbmtdOlWqmFTBWmjNfc9nuWi32Khm1BIegz+7lKwMvXH+A6467ZGR0sQ4VuI/oOv+hc8/ZudbJb8w24CRU1OWCgM00ZGT3MqcOyfj8v6JCXCPCpnbqWZAWO9Ksck3dT7fgD7DqzaoMIu2xGvKZW+5GWS4dD3RPFebyYlxdN+kpiw5bRn3/W2kkkFmfGJnPk+aHJzaIuUSyhpwGhpCGcRst+ZTlqR+gC4j0sV+aecFlHbHU7j/mppDS9G2a+ahl4JebslvWErsCfv1rznwXpKYxqNT12BhOoaLVfPEgIFxKCIYbTFse+ZzatbBWG8YT4CWvhJyDprzpmgAUrCsPgc/RlsHT3f1cPpZ+otMHMBv0u2PmMOEUmhYFN7yF9zcwgkr5bZO4faaEO3OW+GYsr6+4XdQhgRUqHKq4L7QLml6fwM5mImLQ4quXRkmYT4kHIVQnSHMuuhp6QXhW5YziHxDLcjqsFGlGiykSyz3e1pdUonVeqhshze9QemCJaeBLgZSogNVsaj4DljR7mth0T2nOU6xE35gww1n7+w== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(366004)(39860400002)(376002)(396003)(136003)(451199015)(110136005)(8936002)(54906003)(41300700001)(6666004)(6506007)(921005)(86362001)(38100700002)(5660300002)(7406005)(7416002)(66476007)(66556008)(66946007)(4326008)(8676002)(316002)(2906002)(478600001)(36756003)(2616005)(6486002)(83380400001)(186003)(26005)(6512007)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: uQmAz4OOmrMeXo+SOORHINU+/KR9BUMjJ8yodE9k2BCXvvK8Xp0RPC/Vvz41UGypM+jghicR0A6lipn77YFdduGrVhxKJYY1pUqNU8qTEdZyM+Jk673RYYc4IYG0UKyZqNvASUjejiq/l5yBfyScpAcBW1NYloI0Trb/jxpUmxp6erh5wKTX9+QUyRA+5gk1wJ0f3zNPyVSkQ+DOrE0fxZwPKffD66ysb+MnBRX2VvNmZ2ilsadPP4oFr/htKSxX4VKtIT2/6TQj1wLwlIrAkEeutgXsOV7b7blWdRn/A9P7/EG60nvhmOiKFjmuwxA6zwgeTIWvqU7U5R8Ly5gkSMMwbTMhqRXsBz1cZqnzcUsfuf2NPO+avvlyqQ5RurOp9bTZ4THvfCDLun1TZnBPDKcoDxI0jdsgkC4WYQD19ulWPNA+GCm2T4LI0Mhx/7UScZR40dS6G3j+8gUOfPe4SuaiYGU8rlH/6FrDHVuWTt5ezODIYwXAPkTTLV4Pz3cg5VVOUsy89IVTTnqdrFRTC9dEBbtDPyfyaKLcE6CjjtZjRxIrZfirEGoJQytaWuZIRcwg2fqnjAfyVZ6u0OE/lW96t4hsIu+RhE59U2kgWswOY84TTiTRNHsVm/wKqAraUOEqpXnmVFjyDYsPuRLqoc0LErhW3Y7gkJ1aSY8g9mawoJ2m9Zz6kxJmH8EK5TdZibvwbqIgPgYfJO7637a4aR55n5lUEb4MO0wTWgd5tfxuzUSBmFqkUfB4V8EFjyx49mxQfhFaXMo3FtwrUGCNt9k3w1Cj7kp1KuolJ4dFvolMeLffvlDqt9pvLwYqNtk7gm114xUP5xCi1YV+sxrycIva5rvhzMSVIs5Gj9PrdEHjINVIDd14vd3vBOZ2LVYBBGMFnb33Kd6O5ORunJgJztfm5cgsqOhVyEV2bC0OyrFEGO4cx4hfC5Khj8Hj4nyN2geOWyPZ1qAfFBnugVdXTxNjq5LUZYbcoROnLj46pvoBHCCiLCmajKX2hwKKC+d3A4O0y59DLHfHMuN4axyIO4g4r1SR1FJ8wY+ah0FWDUMNA6T9oNXzVV8KrxRxnf7UDpnYg5L8FdUgzcD13yHNWoaBoP5nwfWCzugqYS7W1BTjgC0CvlJ4BWpZI672uhZlgIaSBYJ760iz7EsFXTx2vPve+j6oRDEmytK5qigpbg8aUhjhz49sRCQ9zJhnNSQn7SbQ6woG4GDekHjttdZobvtla/01yUltr75T+UbK21dvoWEgJH6C4CDYYl9DBT3qVEVbIgoZ1O5fK3OpOoORcjnojPu+uwt4kYDY5FG5ttij0mTFQAMzGnGVU0wI0jqrZlsWfNDiXsg8fRpQEqnuyO4V1OYPy77p81/PXujFWvRvhG2hH6WxUrr1g6Daj+X08GFmzw1IkcKG3LZ47RHhjp1UHq6tgMMmMM2je8CDx5eqKe/+0HeZfUpTKcNjYi6uUf9k5dtWVOM43z5hFnoOz1KU7tTrI5Z5XTHxBp7aprpt4O7kpzGJcDjy8j/r0lkF5TCAFvXSEO6MmeSIb0g/GBTtMhQV2PaSsyuX6q4cBz8= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 063380cd-945f-465b-3081-08dab6b52643 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2022 18:17:17.5110 (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: bPg3B3wJp8PKPbc8s7T4FJeENNIZUBMNNU54mBr5V3sR+qkVUO/pI3waRCaAGyXa X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7201 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org These functions don't really assign anything anymore, they just increment some refcounts and do a sanity check. Call them vfio_group_[un]use_container() Signed-off-by: Jason Gunthorpe Reviewed-by: Kevin Tian Reviewed-by: Yi Liu --- drivers/vfio/container.c | 14 ++++++-------- drivers/vfio/vfio.h | 4 ++-- drivers/vfio/vfio_main.c | 6 +++--- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/drivers/vfio/container.c b/drivers/vfio/container.c index dd79a66ec62cad..499777930b08fa 100644 --- a/drivers/vfio/container.c +++ b/drivers/vfio/container.c @@ -511,10 +511,8 @@ void vfio_group_detach_container(struct vfio_group *group) vfio_container_put(container); } -int vfio_device_assign_container(struct vfio_device *device) +int vfio_group_use_container(struct vfio_group *group) { - struct vfio_group *group = device->group; - lockdep_assert_held(&group->group_lock); if (!group->container || !group->container->iommu_driver || @@ -529,13 +527,13 @@ int vfio_device_assign_container(struct vfio_device *device) return 0; } -void vfio_device_unassign_container(struct vfio_device *device) +void vfio_group_unuse_container(struct vfio_group *group) { - lockdep_assert_held_write(&device->group->group_lock); + lockdep_assert_held(&group->group_lock); - WARN_ON(device->group->container_users <= 1); - device->group->container_users--; - fput(device->group->opened_file); + WARN_ON(group->container_users <= 1); + group->container_users--; + fput(group->opened_file); } /* diff --git a/drivers/vfio/vfio.h b/drivers/vfio/vfio.h index bcad54bbab08c4..f95f4925b83bbd 100644 --- a/drivers/vfio/vfio.h +++ b/drivers/vfio/vfio.h @@ -112,8 +112,8 @@ void vfio_unregister_iommu_driver(const struct vfio_iommu_driver_ops *ops); bool vfio_assert_device_open(struct vfio_device *device); struct vfio_container *vfio_container_from_file(struct file *filep); -int vfio_device_assign_container(struct vfio_device *device); -void vfio_device_unassign_container(struct vfio_device *device); +int vfio_group_use_container(struct vfio_group *group); +void vfio_group_unuse_container(struct vfio_group *group); int vfio_container_attach_group(struct vfio_container *container, struct vfio_group *group); void vfio_group_detach_container(struct vfio_group *group); diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c index 204443ba3b3cd9..8d809ecd982b39 100644 --- a/drivers/vfio/vfio_main.c +++ b/drivers/vfio/vfio_main.c @@ -749,7 +749,7 @@ static int vfio_device_first_open(struct vfio_device *device) * it during close_device. */ mutex_lock(&device->group->group_lock); - ret = vfio_device_assign_container(device); + ret = vfio_group_use_container(device->group); if (ret) goto err_module_put; @@ -764,7 +764,7 @@ static int vfio_device_first_open(struct vfio_device *device) return 0; err_container: - vfio_device_unassign_container(device); + vfio_group_unuse_container(device->group); err_module_put: device->kvm = NULL; mutex_unlock(&device->group->group_lock); @@ -781,7 +781,7 @@ static void vfio_device_last_close(struct vfio_device *device) if (device->ops->close_device) device->ops->close_device(device); device->kvm = NULL; - vfio_device_unassign_container(device); + vfio_group_unuse_container(device->group); mutex_unlock(&device->group->group_lock); module_put(device->dev->driver->owner); }