From patchwork Fri Jul 28 06:33:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 127397 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp268935vqg; Fri, 28 Jul 2023 01:00:05 -0700 (PDT) X-Google-Smtp-Source: APBJJlF/Imln7CRAt1ayN7yF/CmiMePDJFuIMgchMwZ4uTs++IbIZ7UN+jTWxN/oHstAeKaZE0YD X-Received: by 2002:a17:907:a072:b0:99b:c2b2:e498 with SMTP id ia18-20020a170907a07200b0099bc2b2e498mr1324860ejc.52.1690531205338; Fri, 28 Jul 2023 01:00:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1690531205; cv=pass; d=google.com; s=arc-20160816; b=0oVJUh5y+XL6pxGIo4ml9HeZwaGuU0TqWGA386fYUCUyuIO0fV0duuz86dtu2iN7wq NNmphmZGxgek1VRAbufBaQ906Jp3NrTeH1xMHmgNx7eJHl0omSnrTyQYATWKD/VgVLSz L6WJU/DVkMwsnnV1XvZLW2E7FYxxliufrWmOHYvDHc05MlmQaKi5i8pWW5iXiOgWkMt8 XCBbE/UjE7XVkDmEg68WXwJ9DXhC6yw/NLVRkI71bXYOwpXNrIjIt7ZTe+OouAEsnPq3 eVs29HvHZoY7WWoROKuvi6pC0nMPR4buZlIlNmKBeT67TF2qHU45Qh8IzBavnZDYAPlO qTEQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FV0JrjUUwrn1J/lFH9ZY9xyoo1mCpvdd0c+a5ZoWLOg=; fh=qC2Tv3KKwVGixY6WZei9zODHRrUJaQPqzd5TxSwHSnU=; b=lGavmEU2++612aFR7rciEq4VrojejCDdJSl43kNxxoIb8CY59Ah9cXW7gq9Gfm3Evv C9KUJuhJYGNE0TJNRFwV3aoSgx+ZE9eePog5S9xigl3t8C908PmLQGO2J4Ay9jslvkY5 3FKunUiFCmxXzuFpKS9JFFI94TglsfSrYa+NHNGgp5KWBT/HfIzOGT1IQtvN+0Mh2Cn2 HqQeTpK9DE8fAlfcJdi/8Jo4F/luGwk6NXMJrJX2Iaz/JW4xLNfMQlqcwgUoaqCRDOC7 Ycex0Sh2c20FHq+/IdCfdXg15rOG9Jtw1CcR6+HyV3e0RPijZ3mGr7kss/G1FJVh7s15 sC3Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=Wvm6ZOb2; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p2-20020a1709061b4200b0099351214a94si2415878ejg.648.2023.07.28.00.59.41; Fri, 28 Jul 2023 01:00:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=Wvm6ZOb2; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233599AbjG1Ge3 (ORCPT + 99 others); Fri, 28 Jul 2023 02:34:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233618AbjG1GeX (ORCPT ); Fri, 28 Jul 2023 02:34:23 -0400 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2050.outbound.protection.outlook.com [40.107.96.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5D2E30ED; Thu, 27 Jul 2023 23:34:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=n3fqLlEWu5R2xIZtBZeo/RRyI8VrYKuNcFtVsgqM7cvzAvbwRNYa1NpZaKCRIKHdYwFJDf5TApAFTz7rmRimkQnVnGoNM6wtGbloSsMcUJaeEg/UyHE3M4RED61WNUe87YQUuX2swwY+irusw42PmHF9bFafsOcQWEH/N50GrRVd4Cky/1d8L42jWyYZuaB0zBfYgXZ08d768isUGM+jCXq9T1fsx3iaEtIqIQccop/frW5DdLPdlt6HsGJj1dr24Ap/gxeBcsEaGhUNq5MnG2IwuthQfx8iug2Rk1fwLWvUoO8x7k03+EsIMpQjaysYIDdTFjLtlCR/ew3x6FisZQ== 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=FV0JrjUUwrn1J/lFH9ZY9xyoo1mCpvdd0c+a5ZoWLOg=; b=F7FKJD3Wk8TC1cmrawKNQ5SFeUSqsJIVm1/IgXuX9Iia2drmDLzK6QsamhB+cZwTRiAbQ984TjO9rvzYupGAbfcNhJHiZTk2ul4ZpPMHgDja+p0nJM9daW+PnS6/MQ4QIh0CXHDhoM43HxclNvBPSBN9h2ARk5N58DS0Hmshacjs6Loo/O+Ky5wxEKSYPCz4so2dAe4flBwpgRMKeii0eCbTl7cxCDMxOM0c/3O3UP3ueJPeGTAV6F6MQZDo7GqcA30VIg7S8AMJ14dratir58Z5EQyCugq9Vy9pVWjbrC1FD3ZPZG7Qgxo32cXVt4sxfTx1cz7D3mri9SflsQqAOw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=intel.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); 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=FV0JrjUUwrn1J/lFH9ZY9xyoo1mCpvdd0c+a5ZoWLOg=; b=Wvm6ZOb2IncEik44+URc6bfTb8EgJ9VM6WCJAW0AIryZ5qJi9nfijBFkfq1s2pUmN05pleHKJGYMKir244AJsReMVikwzh0+LyDGsqtts+iBAWbLakM3MvcT7WuSKmcy5m+c424KVpfPsyc5+QDa4enphcIxoT/aj9/PbWQT7ibCkSfzBfuV2/7B/6oIKqw9H4XJcEsuRDQ5FfZ8OK1ir4oUJXHzM4di/GpFazxW4A0/JcrEzfP8DaCLKAH+vOvgFKr0WLagcsM/qmc4QyjejqzaUYn9vxuc8R5IXJZB0HwAe/oJe1IppYbH4w5PGeKzP/vn8ixQhwmmex/YmA4CXg== Received: from DS7PR05CA0061.namprd05.prod.outlook.com (2603:10b6:8:57::15) by CH0PR12MB5076.namprd12.prod.outlook.com (2603:10b6:610:e3::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29; Fri, 28 Jul 2023 06:34:08 +0000 Received: from DM6NAM11FT005.eop-nam11.prod.protection.outlook.com (2603:10b6:8:57:cafe::64) by DS7PR05CA0061.outlook.office365.com (2603:10b6:8:57::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.5 via Frontend Transport; Fri, 28 Jul 2023 06:34:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by DM6NAM11FT005.mail.protection.outlook.com (10.13.172.238) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.35 via Frontend Transport; Fri, 28 Jul 2023 06:34:07 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Thu, 27 Jul 2023 23:33:54 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Thu, 27 Jul 2023 23:33:54 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.13) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Thu, 27 Jul 2023 23:33:53 -0700 From: Nicolin Chen To: , CC: , , , , , , , , , , , Subject: [PATCH v11 2/7] iommufd: Allow passing in iopt_access_list_id to iopt_remove_access() Date: Thu, 27 Jul 2023 23:33:24 -0700 Message-ID: <7bb939b9e0102da0c099572bb3de78ab7622221e.1690523699.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT005:EE_|CH0PR12MB5076:EE_ X-MS-Office365-Filtering-Correlation-Id: 52379ce6-1a3c-46e6-b8bb-08db8f34a569 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sDpQ7LsrPz6f+AaeDmpIrC2oSJkaH6k3T1zqGHObOeERlVgj9L2R9MN4eB7L6Uu6mPY2zJ0wTy/v1IhjK05oxIMHyj0UCE3jGVHmqAictfujlyO6HcMcvwmNPHqWnnpCQE17kHNj0QGor28dr6TDohXFLFi7FiaFFtnt2duTSqHRXf3cAuAZ+q6C4t4/H7uMkkmrLKiD1iohMWttJYH2Wlx9apK6KXpc2LAoU88x6uwYKIaqVuHmSAoQqsv+2NvI0anSbMJZxhTtj4DHAMhoCwHVANIxZ5DYHuCx3Nl+jg26cKvpNe05CeB+Skp64IM+1Ygd2g9PGM0EjgyM4pXMOwfJaokIomUFF16a63AAmXtgSYABFLmKkrbMdD497TrVCGhNye3/z0HbU0FwqWs5zgelG+4m8q8AZBBAHbpwty2U163lj/Int3sS+/Etpx6gByUJPu9Fgf+VJKEoOUhz8fXtQMYKqkJdrmoAOdSSi2TLLP25p3MpLo7nrX6aInSZ4e5mJFn1HwUyOVgGZj/ZkMpMjzUdPVpLr8eTipPRod8Bg2UIufcTh/XRTQFNGl2AQ1GtgaBPXcXc85+t7+5CA8pvHjY0nzXOq4KCWxIil9K2ZT6+5nHYCjPA00cHCoLCBt59Mr3xI5KgFn8pUR0b46rSCn3CrBL23Ahm5DPp6Kg5ygpJW1waD72Pwt0CCz2Nv7OUrVFkYIjIE+H2AykjHFWcXiHe/D52J/QYeEXRnXvpceFSpOAKWqWY+jTARqOm X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(396003)(376002)(346002)(136003)(82310400008)(451199021)(36840700001)(40470700004)(46966006)(5660300002)(7636003)(336012)(41300700001)(26005)(36860700001)(86362001)(478600001)(36756003)(4326008)(8676002)(8936002)(70206006)(70586007)(82740400003)(316002)(186003)(40460700003)(2906002)(110136005)(47076005)(2616005)(356005)(83380400001)(54906003)(7416002)(7696005)(426003)(40480700001)(6666004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2023 06:34:07.7735 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 52379ce6-1a3c-46e6-b8bb-08db8f34a569 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT005.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5076 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772650449393033889 X-GMAIL-MSGID: 1772650449393033889 This is a preparatory change for ioas replacement support for access. The replacement routine does an iopt_add_access() at a new IOAS first and then iopt_remove_access() at the old IOAS upon the success of the first call. However, the first call overrides the iopt_access_list_id in the access struct, resulting in that id un-erased in the xarray. Add an iopt_access_list_id in iopt_remove_access, so the replacement routine can save the id before it gets overwritten, and pass the id in iopt_remove_access() for a proper cleanup. The existing callers should just pass in access->iopt_access_list_id. Suggested-by: Jason Gunthorpe Reviewed-by: Jason Gunthorpe Reviewed-by: Kevin Tian Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/device.c | 6 ++++-- drivers/iommu/iommufd/io_pagetable.c | 6 +++--- drivers/iommu/iommufd/iommufd_private.h | 3 ++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index 57c0e81f5073..7a3e8660b902 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -690,7 +690,8 @@ void iommufd_access_destroy_object(struct iommufd_object *obj) container_of(obj, struct iommufd_access, obj); if (access->ioas) { - iopt_remove_access(&access->ioas->iopt, access); + iopt_remove_access(&access->ioas->iopt, access, + access->iopt_access_list_id); refcount_dec(&access->ioas->obj.users); access->ioas = NULL; } @@ -776,7 +777,8 @@ void iommufd_access_detach(struct iommufd_access *access) access->ops->unmap(access->data, 0, ULONG_MAX); mutex_lock(&access->ioas_lock); } - iopt_remove_access(&cur_ioas->iopt, access); + iopt_remove_access(&cur_ioas->iopt, access, + access->iopt_access_list_id); refcount_dec(&cur_ioas->obj.users); out: access->ioas_unpin = NULL; diff --git a/drivers/iommu/iommufd/io_pagetable.c b/drivers/iommu/iommufd/io_pagetable.c index 4d095115c2d0..3a598182b761 100644 --- a/drivers/iommu/iommufd/io_pagetable.c +++ b/drivers/iommu/iommufd/io_pagetable.c @@ -1158,12 +1158,12 @@ int iopt_add_access(struct io_pagetable *iopt, struct iommufd_access *access) } void iopt_remove_access(struct io_pagetable *iopt, - struct iommufd_access *access) + struct iommufd_access *access, + u32 iopt_access_list_id) { down_write(&iopt->domains_rwsem); down_write(&iopt->iova_rwsem); - WARN_ON(xa_erase(&iopt->access_list, access->iopt_access_list_id) != - access); + WARN_ON(xa_erase(&iopt->access_list, iopt_access_list_id) != access); WARN_ON(iopt_calculate_iova_alignment(iopt)); up_write(&iopt->iova_rwsem); up_write(&iopt->domains_rwsem); diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index dba730129b8c..8ba786bc95ff 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -323,7 +323,8 @@ struct iommufd_access { int iopt_add_access(struct io_pagetable *iopt, struct iommufd_access *access); void iopt_remove_access(struct io_pagetable *iopt, - struct iommufd_access *access); + struct iommufd_access *access, + u32 iopt_access_list_id); void iommufd_access_destroy_object(struct iommufd_object *obj); #ifdef CONFIG_IOMMUFD_TEST