Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp570134iob; Wed, 18 May 2022 08:14:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmXPX5TZ/L40OnKsA7KXh8ED+IiBPciZYff6TvhAvX4xGU1L6+wox3MT8iZjc5GaJoBcAX X-Received: by 2002:a63:f50:0:b0:3db:48b1:a7e1 with SMTP id 16-20020a630f50000000b003db48b1a7e1mr24046163pgp.579.1652886881411; Wed, 18 May 2022 08:14:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1652886881; cv=pass; d=google.com; s=arc-20160816; b=ClHI7X1X+Q73j55biQ8qmG+bVgKUgP8WqPGoLMzsm5eMZ6r66vv2/TFuT8MbGZJYiL Sv60fhBh+048b9UsnGqepis2qfEiI2fFyDIDUtYGt97vkwI6tLaQRPYbpvThJmSltkWr MNs7RVbWFgRsKw1hAjYCH7Tv9CXrs96ipxgKE6q78J4zgnn6hCr4QqqRB6TgRgbUDjHW 0Vczcp8pYd6s9Z++aGNcKw4kpsqYaVr3BbQeBYmlXffB6SNW/MMqsaQ2NLj67i6t5DCP 9YxdvLWqVLRP3pT6dios8SObIepG8CHpiIsyBvRNqRlNzFed867BLbtZhNgLpAODOJai TCAQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:in-reply-to:content-disposition :references:message-id:subject:cc:to:from:date:dkim-signature; bh=wTGsz5wxR/hbfwvCtwIMRLzkaQrTyy4FyPBgjvizNmw=; b=hEAfU+xcaps5GomMTtgYsdhEkQ2MuChdu5pRGj/nUtmGUuouIwp5PiWi6hvreoYcdc 70U0Q/hqeOLd4MpQ0rQKqfiHQA5jgmADGAQ1YzMwxRUNAgCdpiDTgUrc0V9E2GpSsMB8 sVY1B0Dg6QcX6pyV+W1E1V2448jjNT4V+5sI/xIiKaoKXZVcBIeT7riYmy+B/LJAnUWR TKf2p/mpDqGsvHp+VyyRJ3y3M8EPkBfPFJlYcHPD87TOC6DajJCHEAzY80DVfhMQxFCC 88zgQ7ctCvtfncamBASaVB1dqIOewr6OgHEh+DIlFe2Lu79HSx71Yjc75UmpN/IAAFtb BcfA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b="ULdX2/EX"; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id e16-20020a17090a119000b001d984ab2d48si6514055pja.121.2022.05.18.08.14.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 08:14:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b="ULdX2/EX"; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 435DB1339E9; Wed, 18 May 2022 08:13:07 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239186AbiERPM7 (ORCPT + 99 others); Wed, 18 May 2022 11:12:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229496AbiERPMy (ORCPT ); Wed, 18 May 2022 11:12:54 -0400 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1anam02on2055.outbound.protection.outlook.com [40.107.96.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5B0827CE4; Wed, 18 May 2022 08:12:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gSSMBKvXfLjeITBsv0vmD/+sVos8ZgS2+TKe4AtrLPILeMy/3rGR2k9Pn/vdvUMIUJOM8zVHumLlWgl99TpVgPlOU6nqebIxtOoUqkKOx2nuAYr3UPaslmtSkwy2/y+ETLZIHJK7wsBgMLhEY/FhpjoB0SBzFMCELc6tG5McwM2uhqhT+/0ssb7KQfO1bOIm3rVjUkqOzFOOF346WoxO1nNuvmejHGMky/AIA2LKDMIP8zBGjHyuYaVLL1RwwmZPf6DGgsQmU88TYQSuLOhCYZ78Le7bOfPsarz27Ly/ESn6MbSTm+3QbLRBbQDUWHMUnylfFWq69H2ew+SclJolvw== 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=wTGsz5wxR/hbfwvCtwIMRLzkaQrTyy4FyPBgjvizNmw=; b=QFi5Ye/2rCyImWvCAz7jHs0f3rLocdwuCjv/eEJONPg1qdxl+TWh79gFIFK2i0Dmz0UWzlcyCIeGRpgXJ8jMCX2r8qL3Wrj5Py/frziSjSd0q997peDq6wnRpbNIopQ7byL4rO2KmGLPfqWuvxM+7wZnGb7EDFm0sG3aHIEwcodY5RyJIN08YkPzaContLxfSY833U0XsCxiijWmTJOxT/1STHTOVNW/CFx2CFslORT4pEjOhV03ID3BuaJYJFL9kDqun+QgTXdJpYWphb9PN2LFSdvXgU6tSS5rac5+l+9hcz2hYuFoVBi4mcguGdXi01sBlW4eX0SRN4MZnu6Dgw== 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=wTGsz5wxR/hbfwvCtwIMRLzkaQrTyy4FyPBgjvizNmw=; b=ULdX2/EXygPf8TXdAejoeAh42Y4coNVTvmNNIGcBErEjjWeTq8nEtP6+IU2H3Q3w/48SJXGbwSulGs3cN7uxW+gHHq8ZhP1fQV7vFfdrcrDc8TLjy9Di+FIbON7MbfobaX/wI/MksE+hgWk7m5YcfrTdHM6JItpClG1fldQTGvNic9/mTEkfQ2cS6Bf386jQ+IUMgxtkpb8KpxIgn1zNEClpVmBUXtL3VqUq6LyBuXsoSnY8q7K1beIcyfn3Fuy0vkHt/0XamxNK+DwV2ltzystHFKe7cqoD/ABproBb8OdxvzW2wg4JHtIlwg7dRj+Bz0PVaJGidWPkZB0ceDbW0Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from MN2PR12MB4192.namprd12.prod.outlook.com (2603:10b6:208:1d5::15) by BN8PR12MB2931.namprd12.prod.outlook.com (2603:10b6:408:6d::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5273.13; Wed, 18 May 2022 15:12:48 +0000 Received: from MN2PR12MB4192.namprd12.prod.outlook.com ([fe80::ec2d:9167:1b47:2db2]) by MN2PR12MB4192.namprd12.prod.outlook.com ([fe80::ec2d:9167:1b47:2db2%7]) with mapi id 15.20.5273.014; Wed, 18 May 2022 15:12:48 +0000 Date: Wed, 18 May 2022 12:12:47 -0300 From: Jason Gunthorpe To: Matthew Rosato Cc: alex.williamson@redhat.com, cohuck@redhat.com, borntraeger@linux.ibm.com, jjherne@linux.ibm.com, akrowiak@linux.ibm.com, pasic@linux.ibm.com, zhenyuw@linux.intel.com, zhi.a.wang@intel.com, hch@infradead.org, intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, linux-s390@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/1] vfio: remove VFIO_GROUP_NOTIFY_SET_KVM Message-ID: <20220518151247.GI1343366@nvidia.com> References: <20220517180851.166538-1-mjrosato@linux.ibm.com> <20220517180851.166538-2-mjrosato@linux.ibm.com> <2e51b388-48d0-4689-07f4-65f607dbce59@linux.ibm.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2e51b388-48d0-4689-07f4-65f607dbce59@linux.ibm.com> X-ClientProxiedBy: BLAPR03CA0093.namprd03.prod.outlook.com (2603:10b6:208:32a::8) To MN2PR12MB4192.namprd12.prod.outlook.com (2603:10b6:208:1d5::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0648f6e1-938c-4de5-5a37-08da38e0de67 X-MS-TrafficTypeDiagnostic: BN8PR12MB2931:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: I30a7tiJoE7nybazReDU8lkxpsCR+nE/H5B+FFu/zeVnLpw0NjP0c4UaDIOG3R9bl9XMRnIx4uWoaYjCOYiLHFx3qYmVg51gAhSWFoBVRmXnprCxxPQyXjNv7tPufrP9PfVTq27vTf8tr0kqfLVEaY711TEfPN7kCp/SMjLhh8O/S5j7CET7yN+x4SE9fa3cSLZBsZaMzk+jvAuVLaasSWD8rDV65hMhk9oyVwORIig0hfvQwr5nlEHZWyJ/oKzv6OoebL7Os793HVnvGGH6BEw6oRRoAJTsxL+8tYcgXDNRQXgG6cJlyPgn0DewO9rkTsdL6Br2S4eJlevAWlz8kXSIF7sseVNSvbm4ZbMOf9/JpqEqbCerIqggomu/J0HUo+b7VivXbs5sX0cDHZpUBkmhB3I2k+cyx5Gcd0MFf+goK09dNMfIZ/aYvfwHHxfbD0A0li+2GSABCYWGVmMQ2e8WNXnXJjUNTil5jsrdKmn2r2zmm55ltX0Vmd39c17efpU6W+OXyoBcyAobSC8s4Nk2V61Av9D4B/96Z7q5ndulrz//2lgOwkkHQq+Z+hhWpEKAGCoBA0mlMpG0+NCjAEDaEOrEqc2OKBkdnuS+kLTqFiXC2VtyIE6GGG7dEJ2P9gHtOs6pKS8EHTyppQvfOw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR12MB4192.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(53546011)(33656002)(36756003)(6506007)(1076003)(6512007)(83380400001)(6486002)(26005)(8676002)(4326008)(66476007)(66556008)(38100700002)(2616005)(508600001)(7416002)(8936002)(6916009)(86362001)(316002)(2906002)(186003)(5660300002)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?aTJwgm1jQ9CCs8YbRNzM7qyuwkEmzvBXUeyQATbuL3NhMdKnZtCvWK3bF6ei?= =?us-ascii?Q?haqiyZ2Pp2WyXvC+bJTWLsSQVkiE1RxVe2cZy2q8LDVXFej8bvi9zxENfusp?= =?us-ascii?Q?bDw70aG3Yx37zzlrODLOB+7g2jAcalWexC+D0MqwEA9m6eNb2x1jKxDr/cu1?= =?us-ascii?Q?+yl00NcqSAgu19mLJscJXsHY8xUW/hPjiXHYY6I7RBsgr3YrBaIfFLW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9G9x+dP4KSTbywu+beICeDPHMtZ?= =?us-ascii?Q?rSnLBrj0H2ENc42kND6eQsq37KOaPT1+6LvsHrXV7Tt7Cl3Ab37eVYHHX++Z?= =?us-ascii?Q?gpngL86/rOimKvFrWy5bDs7KlFwYKYnPl0oD8TREE+b9YG6AiO8P3F4syjzV?= =?us-ascii?Q?cJ5BXzbbvU4EHOaDrBv+cGYJ/O40lXQgUUjUwh+EW+wcZc3a1w4E38fr4Evn?= =?us-ascii?Q?mowd0ZGDA1tqto7OMkrGzoaOt+6b2RPwSkmnFHVp2Zxr5C8DYoL8FzF+pMS7?= =?us-ascii?Q?PX/hzycCcW5L/8KWEoETXJ6V8d4mfQE8SHY6fS8b9d5S7f+aL1jYi4QYz3aC?= =?us-ascii?Q?QeaqYDD1U3VzX663qneX3yqoy7pMBzMVgN5VaTB1FuOcrxYz04mezO79O2/Q?= =?us-ascii?Q?3cA7yxt8vQo8HJiBYp+kw0r3WESrB1FxZ/V6gFisXlBxwg1C9l8YfD7PVcVV?= =?us-ascii?Q?JTncL6meHtPHlIKsjw4nM3sE++kEqLPAtNgroAvS9AB2tj3+5t/um9YOyuMK?= =?us-ascii?Q?aqyMGt8z0DYra6wgEVadOciDKHZ+hl69vymkNky/xhIQ+kEguJxGxsKPqSH6?= =?us-ascii?Q?vEaEoTdjI+e3S//J8M70QQAw7y3D4UsjvPiJ/vOj42ohbQJ1PE7NYms0KwYr?= =?us-ascii?Q?l/i9H07d0g=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0648f6e1-938c-4de5-5a37-08da38e0de67 X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB4192.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 May 2022 15:12:48.2428 (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: Ur2wD2C+vfI4Da+JJ+v1NdVjt5a/iIH5AIP5TzNyCKIP6AEmZenfO++Fj2zakJb/ X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB2931 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 18, 2022 at 10:37:48AM -0400, Matthew Rosato wrote: > On 5/17/22 2:08 PM, Matthew Rosato wrote: > > Rather than relying on a notifier for associating the KVM with > > the group, let's assume that the association has already been > > made prior to device_open. The first time a device is opened > > associate the group KVM with the device. > > > > Suggested-by: Jason Gunthorpe > > Signed-off-by: Matthew Rosato > > ... > > > diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c > > index cfcff7764403..c5d421eda275 100644 > > +++ b/drivers/vfio/vfio.c > > @@ -10,6 +10,7 @@ > > * Author: Tom Lyon, pugs@cisco.com > > */ > > +#include "linux/kvm_host.h" > > #include > > #include > > #include > > @@ -1083,6 +1084,13 @@ static struct file *vfio_device_open(struct vfio_device *device) > > mutex_lock(&device->dev_set->lock); > > device->open_count++; > > + down_write(&device->group->group_rwsem); > > + if (device->open_count == 1 && device->group->kvm) { > > + device->kvm = device->group->kvm; > > + kvm_get_kvm(device->kvm); > > Did some more compile testing, since vfio has no hard kvm dependency, > kvm_get_kvm and kvm_put_kvm are an issue if KVM is a module while vfio is > built-in... Ugh, my other plan was to have the driver itself capture the kvm, ie we lock the group_rwsem to keep the group->kvm valid and then pass the kvm to open_device in some way, then the driver can kvm_get_kvm() it Alternatively, I don't know why kvm_get_kvm() is an exported symbol when it is just calling refcount_inc() - inlining it would be an improvement I think. Jason