From patchwork Tue Mar 21 19:14:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13183098 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 90E2EC761AF for ; Tue, 21 Mar 2023 19:15:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230239AbjCUTPO (ORCPT ); Tue, 21 Mar 2023 15:15:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229892AbjCUTPJ (ORCPT ); Tue, 21 Mar 2023 15:15:09 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2056.outbound.protection.outlook.com [40.107.93.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 085D4AD11; Tue, 21 Mar 2023 12:14:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CiltC9Yq8uWMSpA1gNacjKX5kNZ0CvacY0p4EqiXoIpx/gsii/PDgUUg9C+0y1ZWTy6+Cgke6KCgjOJVmcJl0xu5AHXuTdUuohsx4+somZtfUfwk6trqKwlyLjkw0PapAaMo/WRJBGE4Qdf6GbxiYvpPNpXp/WMACuQ1aR6C4H1pXg4BDbtZtcfWY15FBbEUVwLY7HrnyZqht2aB4ukDxTmYqXPNBdQB2sPYyx9b//oTfsOe/1W1s8fQaWk2XqD9C9+BWFTfxLGXK0gP9TpaP5lKMiO8g/HX0XxYwEczhyaadVqWpgxOkHEC8yjL4WsA23zWFy/ednIcwRoOrtpzwg== 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=wfvhZui57nmqhoohYoRzvsiDaJdNrn5U2mmVXiFjE/M=; b=MpLsT781eCtr9fLwUCTmbI34YnHWPMjxWybtHTg4lpZcttzghOEsmOHVtfibT/1mn9w6HhXwp3KDUB0kshnvORD54wpogRGpn8Ze/Wb2l5nVaHTzdrhr10D/1dV0xHN8rWHQTPyW3i4oNDcz0i1P1EdHc4DhX+S7020/YoHhRDgcRpU17GWMT6uG873UMvestWhwNddygCqQ29/GgFAXEJTWWvQ/6na9D1YZT0GUStAUteEi/S0Zm6qMdxqMsv0x4QbGu67YT6mjzud33fojvNR6Mvi2VzL2zWagN1a1Ca203KAkMcf5KSV0+W4PSBZ86c1zwULaLb5ZuMzi3Yt0fw== 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=wfvhZui57nmqhoohYoRzvsiDaJdNrn5U2mmVXiFjE/M=; b=GHmMBFm0Jb2hwMMMdJcjiIV68ytnO3c2nc9sbhb+QUfpu/rl9Uc1kBrxtpsa49FwJr7R56AAgKS5p8HZFaSnS13VcQ9lQLkfLCik5c/bvwW493ieRH6EsHAlS3VNIJJ3uFIcAQHBqkBX784rM/4803/+7FjGQtbamTQ+Vq4ME2sxhn1UoCHUvYX5U9hB5odd6U0Iw6SvXDqKlzlnwwiysa7HQfmFd4tsOIUvV43NfqjUz4ENCyWOL/onvw+vDPw9XRtlCYFQS8D9uHIOvPVO+Z5MkX03/rF0PqSEQagnIG6xpNDhTAAqc9LDU05a6UsHYc3cnHuBXOpGoGgZEP5RMw== 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 IA1PR12MB8237.namprd12.prod.outlook.com (2603:10b6:208:3f3::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37; Tue, 21 Mar 2023 19:14:55 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::ef6d:fdf6:352f:efd1]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::ef6d:fdf6:352f:efd1%3]) with mapi id 15.20.6178.037; Tue, 21 Mar 2023 19:14:55 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Kevin Tian , linux-kselftest@vger.kernel.org Cc: Lu Baolu , kvm@vger.kernel.org, Nicolin Chen , Yi Liu Subject: [PATCH v3 06/17] iommufd: Use the iommufd_group to avoid duplicate MSI setup Date: Tue, 21 Mar 2023 16:14:40 -0300 Message-Id: <6-v3-61d41fd9e13e+1f5-iommufd_alloc_jgg@nvidia.com> In-Reply-To: <0-v3-61d41fd9e13e+1f5-iommufd_alloc_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR22CA0025.namprd22.prod.outlook.com (2603:10b6:208:238::30) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA1PR12MB8237:EE_ X-MS-Office365-Filtering-Correlation-Id: 6fba391a-d49c-427d-3d3a-08db2a408d39 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TBQYTZKJHrNnq1/bJVUVb1pK9ekXLTBmKEFrrNG+4SFf3ulLfDtUyQOhLHOjhzDwpjfpGkh/akk/dXqbqVYQ2F80xL9Be496hkuw23UQ2nVZvNxmI5I9yttiCCyq91tFPM/hUO7mL+MIjT8Oqdbzuwiwbj8ggt5KEgtyZnBVjStyPOtYTSXX2530aFvbZSv4iYFBd6gh9aS4wkDyowc82+5UfdE3xAWxyvoUBw4HxDSyEGXsNNffG+sMD6FHbpmw9tBPEJB/Rgp05sxur9hBD3cJI8U1yoM/X1yfVJFlr9qEPCLPprlspxqWoQsRVvszR7ka/EwMjuIWGLXX2K+BCahVWcOSnEErHfYr+cbo5FUAkWDfdaLqjyGtb90QO4dLU6Wp7ZKlQxNcyPCCZwI1PKRcmCaSfhTlR/ATTpizxp0pEzrBohj6YXs3tfoK6FhNng4AnxhOBlL8xxLd6pQsva7SJ9bvikYEgQiC7oB10BvuZEQaBBp4R1Kf8r74VBTmwfP2dW6x5JGyS+KM3I4ov9trLGJ56r+xRy4HYMcX31GEQTPA0NDUr3MWMzI8aJlPL5vvrqVoJwjYxRQWMQHIbv0iIOXt1w9WW3w8dPppXI6szl0uvhi0Hc03okBvNTtxNojNI5/nsgEdMOQZBIbBmaOxgH6+auv4rLhoai2QhTUq46CEpe5h2QiqhhNV0e1N 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:(13230025)(4636009)(136003)(366004)(376002)(39860400002)(346002)(396003)(451199018)(38100700002)(36756003)(86362001)(83380400001)(26005)(6506007)(6512007)(186003)(6666004)(2616005)(6486002)(8676002)(66476007)(66946007)(4326008)(66556008)(478600001)(316002)(54906003)(5660300002)(8936002)(2906002)(41300700001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: MF2Ka/c9Ecnk3JiNPKGBnmhN/Gex/cufT9Bdrw/0JlxmHmVeA4p48hF5vO5iD+kBuJfy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H5fD3GTdm4srLJWUditfBqWcZyCkxYdrbnRIE4+rUPE/gaBX4KxfKL1JQCIeCZ12VIbGaDUIDoGqZxBLh+EPwEmHMwdHKAel05Q2MDqlmxbfFK26B3amaC4NiVNzv+YFPXgwso0GNl3Ut0fBJbpAqyJ4xRI4DMGwYF/yqXv67+Kk2v+IXxpARnykFLQHvi7Xe55IXfvYqUxLpmpgwUCnOMx3di40BgQElDj6OMA8FsXhHyrCn7wdrgM5o5VLk9QmbU1ZtJxRoKhsrM4dZ9tj75ItpiF7QIlBbRG1sItleRLotxjl9IJJJdQgAq0SgFETLC/Qb9/T1VoziITE9O/cj/iNoYny2Lw1lVdHPyjjG2/qWuH3YwLuk64FogS/i3RXFH6iTmklTHu+kZLBPWmjTr439mRT9gwV979jprJTiZ0pDNv1+bvKPRdfAUqtmAaO0A6OLz X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6fba391a-d49c-427d-3d3a-08db2a408d39 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Mar 2023 19:14:54.0231 (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: jaadGP32ev6HJjtVFSRpWsBQRvUMNkjePhlZ2Fv7Ba7HEp8iCxE/RU6cT2O6ccvT X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8237 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This only needs to be done once per group, not once per device. The once per device was a way to make the device list work. Since we are abandoning this we can optimize things a bit. Reviewed-by: Kevin Tian Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommufd/device.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index 4566833494e076..7f063b679a24be 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -315,10 +315,6 @@ int iommufd_hw_pagetable_attach(struct iommufd_hw_pagetable *hwpt, if (rc) return rc; - rc = iommufd_device_setup_msi(idev, hwpt, sw_msi_start); - if (rc) - goto err_unresv; - /* * Only attach to the group once for the first device that is in the * group. All the other devices will follow this attachment. The user @@ -326,6 +322,10 @@ int iommufd_hw_pagetable_attach(struct iommufd_hw_pagetable *hwpt, * regions are only updated during individual device attachment. */ if (list_empty(&idev->igroup->device_list)) { + rc = iommufd_device_setup_msi(idev, hwpt, sw_msi_start); + if (rc) + goto err_unresv; + rc = iommu_attach_group(hwpt->domain, idev->igroup->group); if (rc) goto err_unresv;