From patchwork Wed Mar 1 19:30:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13156353 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 CE63EC7EE36 for ; Wed, 1 Mar 2023 19:30:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229510AbjCATai (ORCPT ); Wed, 1 Mar 2023 14:30:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229617AbjCATag (ORCPT ); Wed, 1 Mar 2023 14:30:36 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2062.outbound.protection.outlook.com [40.107.93.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B99CD7ED6 for ; Wed, 1 Mar 2023 11:30:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jykKS8Pi91JpxLE2PibsQx9kIHhOUPyMQxZOlk9GnNizjSTlrjZAxnm5D4sCvefStOwWSs8JAvmTfY9sPXVuiQnOvFO9sITo2irI79plfKjf2MylbvNQ5eXW1dRozCrX750fbZh3xIplTNsRdtOedT6N3fhplIKJeXomPXoIMNyja9E1L4NS6dCRxxt7Q+jm9jq4zPYqoo+hwA8jixVLC9KBt4fSP/NMKFFxfTj3XWEyppt/D5iFBpT4TGUaYFgGHIEq6sOiFbuuILplTU8VNV3eaDpggIPV3+E5NvFMiY4kjhuH1yadRUYqBaIO321XAORQng2WIavaqv/cCoZt5Q== 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=J33EM8niFVAHF+/EU7iJ4w/x8NWYIsaXnpTM1TNRbgU=; b=GGmHj2aV0Gt+QRM8iIz1DtOPh44kvs5+kOiVXX3Gmq+yrWxt0FLAEUMexDQ1rHehU9pfpABIVgkN23q3myLPZ/droLtROk9QlifOWcB97yqT3SfpRcNG3j0ett8TK+cbK9jjZIdeyCNj3jiuzO6u0U3kGCrIAyJVZ+i3Rkaaio+r/S3Coi8OvGkyka4wrvhilxLIbsIhrhERQjahkFl/44MvqQ7umRpwd/X5lzAOnikn5uNta/NoJ3T41Xt2Y4h/OLLPfAn6ywxn5LtNHARwrALnfbVGJNQ1hETmhW3ZGK3R1ALpAVzgLX+0bgzKcLdsxLgK8Qj2A/OgVbKKFa8HHg== 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=J33EM8niFVAHF+/EU7iJ4w/x8NWYIsaXnpTM1TNRbgU=; b=khnpYJX+6P5AtpK5hdni9gGZmoehjOawKAVN0ktfDJUFgItxdBCQ61+VbiLb75hSp8gcw1VKKirIKt8PxO3ZkjE08XBygWbqOL/F/m5uXayEtBA6gY6KPjPeZ+zHQqlYNzkq17sE6AUaWqq1xu+SbI4nyaFE5PC9FuUHntTjKYM2ZU5gu8MsyzjQzQuRgjXYJhSIf+jxNeBbJZhl5WUlBkUtcoXnFdMshE6UXM7JhfLXtGyF3T05LpkF5pwmuRSyd9lwxFKCVaCIbRLgVxF6cEYHECg9FXQlplRkEZJ+VS3Pzu4NH8bGbaRn7aJPPks+LBVnqdhJ8WwJcuhgX8MUIg== 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 IA0PR12MB8086.namprd12.prod.outlook.com (2603:10b6:208:403::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.30; Wed, 1 Mar 2023 19:30:33 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3cb3:2fce:5c8f:82ee]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3cb3:2fce:5c8f:82ee%4]) with mapi id 15.20.6134.029; Wed, 1 Mar 2023 19:30:33 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Kevin Tian , linux-kselftest@vger.kernel.org, Shuah Khan Cc: Nicolin Chen , Yi Liu Subject: [PATCH v3 01/12] iommufd: Assert devices_lock for iommufd_hw_pagetable_has_group() Date: Wed, 1 Mar 2023 15:30:18 -0400 Message-Id: <1-v3-ae9c2975a131+2e1e8-iommufd_hwpt_jgg@nvidia.com> In-Reply-To: <0-v3-ae9c2975a131+2e1e8-iommufd_hwpt_jgg@nvidia.com> References: X-ClientProxiedBy: YT4PR01CA0066.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:111::17) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA0PR12MB8086:EE_ X-MS-Office365-Filtering-Correlation-Id: 4983240f-97b9-4fe9-15b6-08db1a8b6b85 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: leMzWlQuOdaU8NnuXAODX8KKGKLxDd0/60Ygzs71bX+zT50PXx41W6pijIdw8kRGdHBlXyIJKzbc01fO8fdMktU08lzxfirmiYe4I3Gikl3yxzNKc2+8kmCQ6z/fqpbeYCCdftfU6gXqLQiLqlVJjaNOLEDV2vwBvr9FQT+Ln1wBbao/lZSR7PF/gP9DTsL3VII//uxVz4Sxg0wAeQEr1t+5YzNPYbXKubukIL19M0YUjRqriL5/uI6MLzrmS+McrHFvt18HdCWj+KcpGDBPdaV4hPihT0bX9tHymuBcz/Oa/e7Lb7VoES2duj/Ez6bJ6bh1R/DQWaigtMbk187ozZLxVg8l6wHYZNVz0F8UgTfQFsVkVRuEOtIstUqf7Uo/t8wBAVhD5585vTZb50G2GmcSbdw4ppkMzZjcDvmSO3Y5PQgfQiDeJZtSrsbXcXDfQ0fc4LBiH/v3UHtq1LorAlegfsyPppj4qJKoR/1eFe3fQjQlqlMJBzHhYgVw/Dm2Kl1ba78vPOf+r/dDyGgSn+emv63FBEN1hGq0xwCbYv1pP+6AXk9FjNz+OHqDzM9KR1krgWz3++d4gm6ssUfXQhuMnvBZP68CM56UTp7+zR/O/CAEvF/d6iUX7FwOnVd34hgBNd3OfrE1yf0th77uFFyEAZeOX2FJjnXdz++WlrJGtkGpTZMJ4UzVNxdeX9qJ 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)(396003)(376002)(346002)(366004)(39860400002)(136003)(451199018)(186003)(2906002)(4744005)(6512007)(5660300002)(38100700002)(26005)(6506007)(8936002)(4326008)(6486002)(41300700001)(86362001)(2616005)(8676002)(66946007)(66556008)(66476007)(6666004)(110136005)(36756003)(54906003)(83380400001)(316002)(478600001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 11QWcVn+2WgzwRz6E2aAjVsqjldF125QlV1W/UDHJ/U9xSR5FoU6nDFvX1+STg86rbqjtDUxChHfc4JbKu8+BeATcGhtED2YWVPDk/mDhMXQs7zjEJ/4qn9NjYqpEzxqB0EAfxfFP671Qt4DCHIfJWu3FHXoQNt/fdvuOMVmzoNQWzupPqY1uN3/siSsptKykEX4M5Cyv4/PG7t8THvnY2YHG2FwBvxY/qeMnHbGeYedyT6yge/8gksSwIOcbLnaJuwyVpnCOvS/OjipxQK0kn9XAerViG2T83/patMhPHMxOiNPmsLX0a/aHsxrbSgDqYxg2rY7HqXnbMWQ8WNa1GI0YP/i59lmXN+DB1ZIifTed+fcmxbGpFWiWMjgkAsXv8pEvC2OsOsR2TPmmAIGS1DwGDAelmAQNCvqEkpjMvwdy3U/56jvx5XqIZ6F+3B15ElxaR9giGLWMZiRe/Llh1ztS0Q3qwMDhunBzl/Q9NV3BoLAkzImw8CNSDvAhvInplFRUbdCmTCz9lAtP00Gjofvwrej3xMpENqzDlAOyEaqTgR2xEGNXbTRgUEZie1jvgTsn1qd35dY5sL0gXeQe1kNwzcjEA3rbThg5uy4kEW2LpK4ERJhucU0ukOtZJjwUuPTZYDeU26F7UY1PVxGt/fDy7g4ZnQsP5+LRJgZljGtHKsxHz6RYAkmSZ2KpjqoyHY+giGsXidRpJT2THOwu2g7jQRU1CIpHAFQmZcYqaSEoodsbqx8TtOy9DTRQmHirQ7BdM/ZjP3u1cwjbt1BLP1rrwTk7D4HVL35jO4BrBwQ1Xn+JQVu1WLFZae++0wp0s7XQA1TPxDcY/VBzGbHmmfUgFXh0EYU0rTEONFiH1UiDyKm+um8vSqFhJCqPCf+pg1Sk1AlwFm94DNpGtt6LgYhjElCB0n7+/RVEn1YqeeKQyLHxWFELuVn+9igpGBIHRylU1/nP2J8lAF5zo5br9zpL1uAutj3Cjg+bs4tjyntPG5KNMTPSnq6aJJsjf4wyPqYNv5svP+EnaAom84h7CelvenSVZFBup2sIZXDmOgI4XNIfHCP7yf/jQHgvALkSXD57N6Q2xsV88dC3n3yQu4ccTjmbXIrHX2gwLxCUfS4U6r0v2vISAu38+3XFX7WoAo0Yc+7bUkeX44Um79PndcF9CWRi/yDO1r2taLtRSw3D8ctnnjSgh6UkRWSlv6XT9BBgRw22Q6Tz0/PiCGJpDlNE6orRZ0LxgNhU5FnUk6Ryr+S7UuQs5Q4qYOURPh6GxhYjAIUZshVEIdIdj+tm/4/SSm7EQSqjMOMbpMBNb05Nab5IQbZeQj7xdSOrYmiPp8nGXJdHoBLVVvMlFhRuvjuQZy/crfZXNLCJ507EDcDh4u/kd4FbQ5k0pkOk7w1vXIa5J1OgsRKiny5XjhUJD/OK3yLowjxPWB/0uHum2bmeGCnZD/bU+TccUI7bvf8m3YOdPJZdR+RQZK+pwL9iy4wU96NuaxuCyBQw5/Uhpm97zQdySYHRZm6Cjq7OvzBxLmvf1lURB5F9xiuVEnM/guvqjns4SdX4ZeQljB/LO9cOI5IFWSG0sl1lh17ypln X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4983240f-97b9-4fe9-15b6-08db1a8b6b85 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2023 19:30:31.1717 (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: 5hXNtyotZXL0U8YMggA6BAVCyYLsn9mUCrrVRfgv7lgm9ZY1C/GdmGXzB3o8a8Mw X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8086 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org The hwpt->devices list is locked by this, make it clearer. Reviewed-by: Kevin Tian Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommufd/device.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index a0c66f47a65ada..dcfaf6567420e0 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -186,6 +186,8 @@ static bool iommufd_hw_pagetable_has_group(struct iommufd_hw_pagetable *hwpt, { struct iommufd_device *cur_dev; + lockdep_assert_held(&hwpt->devices_lock); + list_for_each_entry(cur_dev, &hwpt->devices, devices_item) if (cur_dev->group == group) return true; From patchwork Wed Mar 1 19:30:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13156361 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 C3716C7EE30 for ; Wed, 1 Mar 2023 19:30:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229586AbjCATan (ORCPT ); Wed, 1 Mar 2023 14:30:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229667AbjCATal (ORCPT ); Wed, 1 Mar 2023 14:30:41 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2075.outbound.protection.outlook.com [40.107.93.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF45D2CC55 for ; Wed, 1 Mar 2023 11:30:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GW7NhgtZ4BRumSK53bCqM9IOMGzdbKP9zaSUOrPbKnn/NJ5Dgdj9C1O+9GKVRelZQILD9wK3rM/63D/YMt0XxkWOkHqz4pcz3wc18aNYuQhH1mIoxtWbzvXBGXTxSwbbt7vrfd3q5XM+/Xe/AW7n3Zpp/TAJvIYO7UOMA6db37cLy1omENq+KBciMjADSx4OEVrGFnrGtW6s6XamyTqjyTU1IM2EVMEEdDwN5NluTpddGSzgJrFOfN7CIS8TVOX0BHanB+YbejwBwH6/bPDqwif8VsKu9PFtpYBvkwL9rfJJT7rKpBwUwgWAwb4bqf6Mn3647zOv4BfwjwnjciSsPw== 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=kmbvk6MSIOPvSvISloY8rVrf4cMCwMHXNe6zriI88SU=; b=WiXdafyIt0P/nb2QaZORaeVGFeMRxB4QsyIW3oDZN9HZ4nRvPGkGCxCKrBtWnj0DxSYKggUAvDZgj6eUdNubb00kKy+6BQAZVgC89N1QwNh1kCZpmfcPrjqDQVEwkWQqj/Gn3oxpLcsOLB3WLbQTw4vGtgQUY+2v7C3xeY6sTRcOHhJNnjqx7o7AV/PvjxkE8EA2fvnerCTG4vpQRsfN4OYAQN2DTznGn17AZhY9er+uOSr/1bgxBPFafoe50hNrjCJkfRe3pyOsO+k5hLxpquW4cEkKo8mpGMRqUGe6RHLPKbLUnd5W0IWryMS+bUU8biUV/U1hb+z1GFc9aLYEsg== 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=kmbvk6MSIOPvSvISloY8rVrf4cMCwMHXNe6zriI88SU=; b=mrEd/vW9smynNigSmqo7nhm1Bm8zgGYM1ZbALSoHF1Z6l3nV21C5FaR44Ri3jfWCnaIZ0TEDHxyKtl/LntKCHF6MG7+tvoou5hI+hDrAOZ6W7Hpz0aNXVo465+B6NdBY90yHq3Y7k/8CBU0S8Xq5htb0rlZww21tAJjV1GqOPk6sy8vcF/xutYLV/OWFzZwUZ3xP2u1nbqUvuc5cxloO3KwSzMTT72IG614Ajmv2cWKdihHiVi6/qwJkYaJkjDyRUXA3RChNfsPoqWueM3B9rFkNO8yvjAZ/zCNX+YmfpcYMxBDE0e7nHvk130DgQOSj102snBrg8HZDO1FHEUEBZw== 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 IA0PR12MB8086.namprd12.prod.outlook.com (2603:10b6:208:403::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.30; Wed, 1 Mar 2023 19:30:35 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3cb3:2fce:5c8f:82ee]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3cb3:2fce:5c8f:82ee%4]) with mapi id 15.20.6134.029; Wed, 1 Mar 2023 19:30:35 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Kevin Tian , linux-kselftest@vger.kernel.org, Shuah Khan Cc: Nicolin Chen , Yi Liu Subject: [PATCH v3 02/12] iommufd: Add iommufd_lock_obj() around the auto-domains hwpts Date: Wed, 1 Mar 2023 15:30:19 -0400 Message-Id: <2-v3-ae9c2975a131+2e1e8-iommufd_hwpt_jgg@nvidia.com> In-Reply-To: <0-v3-ae9c2975a131+2e1e8-iommufd_hwpt_jgg@nvidia.com> References: X-ClientProxiedBy: YT1PR01CA0155.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2f::34) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA0PR12MB8086:EE_ X-MS-Office365-Filtering-Correlation-Id: 359d6280-6f72-4803-45b7-08db1a8b6cb6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: L9W0dyUy2kBIE6crvPQ48pMNcjP5vSe9oiIqwaHEvJFiA3d2AVRTD9HVAVCBQlUVEzFD0wbiDRNnlYcLqNy75Y1aE4E6DNIb9wHB37oVNMt1zjlWL0HAx4qUuMUU2PrZqpJQFe3Jwx2crAby02ixb8Ur9TyuEDTBrKOj4voi4InPv50lzD6J+OagopM6sSbVDxFdA1J8pGYw6p4bK7Qx0Mss3KiUeHsA7nO4ahFJ/jLDmN3S05sYdBwrry1qoRPUda+QwJN5vawE2t6sqnyzGlASvOY3RIAQ2VOIwCkIYSwqmKvIWMS2Jgh22A+ELOiCwFgpTYEfi2cRFT/v7L8BMSk1xRdnOmaaRej5+u1FS/Npk1c5Y0IC3veXYc9JeadVIlTYVOqS+Mem8blIoc2e9JjFE7/XoYLdkbdJyaFy3s5m1mK36ei0MChKNq1pzCpE+49crnIBfdGEnrg2SL1wCSmQhQA/lBSG5ifq0aGhTWXA+ErSIjF/D2wSz6ZSBI8lkJGe9YxqXrGa573CZcvOvVo9mZl9ZBArlFasSPvwrTyOI4AAcqf58rYyRkWRCRvJsdigQA7K7Ekpb7MJyN7YhFkZL4ZpoOOP0Kg2AWYwmin9248pZoULRI1TGS5gEf63zhbxbXxMuy2WDalRusSjiaUYz3edhnMM31wJksrZg/fAkKm361i885b16VXWy2yezlhHhtgOOD8L3+tzW8+rrg== 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)(396003)(376002)(346002)(366004)(39860400002)(136003)(451199018)(186003)(2906002)(4744005)(6512007)(5660300002)(38100700002)(26005)(6506007)(8936002)(4326008)(6486002)(41300700001)(86362001)(2616005)(8676002)(66946007)(66556008)(66476007)(6666004)(110136005)(36756003)(54906003)(83380400001)(316002)(478600001)(4216001)(17423001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: W3Jcng+jIWlkDB8R+jyV/fGMv65l0xyGcaUwO6ZFbvwcp40dP/9iKcQ1rceq16Hb2NFVYtHm6lI11VEhgXqG2DTBBF3GT9OSE1R/GNegoYRTSJau8NoZQUTYyBW0wbbLdmqJRWRuz2/lgZo4Fo74PSzhNFnCzr1RCTh+KeJ0/Y9z+oYHhqKxqDLTnxrF7q9Ln3N/HbUKabs+XLuN2Ud5/ikMsY982HhQcvqMPcBCZlysgXfZ96qi+ji51HpMvCsx/YWfqo/45iCBDGjc7ekiR1XKwOsrkynuWJbMFQnrAngdzpdOEmgwB1U/7utWPdJ2CZkURYc4Jd+0yL/NjB4u1qmscd3HohRuZKs9XrcVTF3zkQuAJEIisEsyvlgT6/Q5aXlKQVNGUi64MpUTK9shm3hVSIT0y+uiZBm5fBmvF4Ghy1xKz0FJYWjr2hZhNIUCA5iyMOEUQzjwtyoSnpMY2rxS7F98blIL6u2xo8e1+wK+FbrdNt+/AO+H2rMV7KizaACNwP9uL+RR4Ok+3RCRXiABMxLn+ayEA/CQHNR1NwUyCIki7DmmTrP+vXPc7FebSZGcbcQrcOdTH7xJ6T0rhMUunBEb9uy65usoZMqi1ANeuE6gCqsKjkevScx0bZY8q/NWiUy8PevEK/+mwGelySRVmB8VInJ1hXPoOF5e5UclbXFQLD/Vr9sCe/L+UWEFFWgMDfVkdDzAuaixiBqSKK9cag18+j5XrC+MX0E5zBJugwWZNcZV1kg5IthMcL5ZlT4CzUMVHWuQGgbJ9UlDKtmRYBLjc/3BEfRL6PLGKC59Us9vTGHGUmnk41zR4BOx/eh6yLvVWIk5BK92xG5NMhjwxWQ30yg0LZ5YG/Di7JAmCN1hEvi78T1szFEOFntKDGxiyId57RJuOQ1V8EWg5AlfH1t08BE1JNnb/uEyZ6YiFa2N2qEdQHOxbNT0gL04yE2MoBwSHl6efQ1cwZ90JYewFi9ir95Yd6tYrGhrPGCFRXaFikac8DID9Z+TpjBdXQMbDI82X4WZcPR3PcPZjSZWqMG4qs8+sP4FLUJILxPZtBgVvhFzfbytWBZcYcojDg/TLcb9M+E2NjLy32hpyQerYKlp3Ir7sp+8eBtK1qiC2EOd0Eg5peFL2P41cMr6Oonig5NobhBzXxZ/d0ryrQQj2GlN0H0JztkGp66RFbCc2x6di6DGlJjhNyMPp3uMpoj9jd7MBQx5sojb14gKYrhHEWoAShdRM9/oh5hsaCjghUTEgcjGxmroxdZesGzMcwLqCV8IpD+EKp1PorzM6hLl0RGVv06kAHr0oVmSZXn4w5AfMWNHgp26zBhs6Ao89PdEvbl9Hmx/vRHBQBWs2yWg9gPdBzhH/QfHJTnGc79Jy/1mK9i05Uzpvoo8PrchJ3lGvAlTc5H/LOeYFbAKBepTQFR5H77A9oDivarPQ6ctFQ/n9wfoyqpK64lyjREVtFSU/vlvg0wL9RsOgzSPYLQf0wQCNXr5P2wuKqg8J7GSnw37lIYrdnXX31s3ZH10wZ6AFVRaGCpgzBqL8pRZI7p5AR4i1TdYMmL51fDAY8rlaKED9+z8k29+DxjFDPRz X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 359d6280-6f72-4803-45b7-08db1a8b6cb6 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2023 19:30:33.0967 (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: vPrKoTGtNrbeWO5r0WGhHdI8FMA09DzVpQ6y0lytid6Ow9Qa+9QNOZIOn/fDqoqw X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8086 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org A later patch will require this locking - currently under the ioas mutex the hwpt can not have a 0 reference and be on the list. Reviewed-by: Kevin Tian Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommufd/device.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index dcfaf6567420e0..0a80ff7b2e0d79 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -282,7 +282,10 @@ static int iommufd_device_auto_get_domain(struct iommufd_device *idev, if (!hwpt->auto_domain) continue; + if (!iommufd_lock_obj(&hwpt->obj)) + continue; rc = iommufd_device_do_attach(idev, hwpt); + iommufd_put_object(&hwpt->obj); /* * -EINVAL means the domain is incompatible with the device. From patchwork Wed Mar 1 19:30:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13156351 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 F1CD2C7EE37 for ; Wed, 1 Mar 2023 19:30:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229437AbjCATah (ORCPT ); Wed, 1 Mar 2023 14:30:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229510AbjCATag (ORCPT ); Wed, 1 Mar 2023 14:30:36 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2075.outbound.protection.outlook.com [40.107.93.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95CF559F6 for ; Wed, 1 Mar 2023 11:30:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KFFC4VpFnizZESHhm5l7T6AVPG1P+CR//MD1uh7RT2F2zlQPp/j6REMqBf6D1gXvtBxY22RDV0M+ffgvm/qAHnxMA2f0xwi9rZPudJRuicTCwY0UoOs2F02E1Q6oTG+TwrFcvEpBarXXA3v6/geUN2YB+ekztDsWuL8xiPOgRjACPzno2JbOOGi9qclk0PQ8nFQiEJWfE4/Au2ZHBnRs0tk3n2R9emYYAw9uRlG1YQXISksPgxWHOh51SJlgU/iGj3Wc1etMI3rZQw6sQYYtxr5+coPgFydg+e+uXN8E2eSEv4W8fyLQTVGG4AcE5ZZKj3vR/CgzNdkoQ8hb1Nm/Aw== 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=4941AQ5PYzyxSDmSn9pZznk/aYIh0RcRcpoFFMQfPC4=; b=MAU2bvRbEEPbEj5FbTBy2UEJyVV4+XtISWB7CvCAAtjX05r107/yxabF/YMevwi336fqTVhVkH7S/zYLJNRX5oqqPF5DxS+y2mWhzDABr5ya0JeiUdOHqaQn3j3RCEjKghmFonYarDh4x09uOpetyA/asNBy1c24Ea6ItDfeEbb2UCQOHXWwMWpx6dUjNGxm/vL1AaGc2y3DYNfFaHQ1fJDGrxQJpe1Ajtlp2h1AVM7T7EDrw+rqbz3UDtxrFqghueWooLEGaLR+d0Cqwx0NmHV3/eY+hxhigo+NKWXV9ux8V24McvP8Vg41yVQwKbgCOIHpcyXBEsaetBuTeM3vXQ== 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=4941AQ5PYzyxSDmSn9pZznk/aYIh0RcRcpoFFMQfPC4=; b=RHmVbo3n20Jf3n33r5P07JDc2XqXEzp5xOvi+s76naiIH7y/Jv5AYGXpHTtqaN34h94YXSRrBg9mrNc5Lp332WAPR5dmrWbzHfOtDR99SgLEDCLVUmzyQ6ejSjz+umJGRrd03hZLja+bdUiowsRmWZT1eAqefK2rv5nsitfXAVni+W1CaKZVTqJhVbDSh8kjR2hHlDba7qcL/pnB66FuLi/CYqzcOLWV3aTqPQTMWFaoWpMSweT7sPHV6eJ18e/mwv/IIXe5gfAnvWElnYSO2osIowko11PzRNNWfnBStEnljAygoXMBfsrzNwNqfVWNJg4sj8STSgMBhm6u5ddojA== 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 IA0PR12MB8086.namprd12.prod.outlook.com (2603:10b6:208:403::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.30; Wed, 1 Mar 2023 19:30:31 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3cb3:2fce:5c8f:82ee]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3cb3:2fce:5c8f:82ee%4]) with mapi id 15.20.6134.029; Wed, 1 Mar 2023 19:30:31 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Kevin Tian , linux-kselftest@vger.kernel.org, Shuah Khan Cc: Nicolin Chen , Yi Liu Subject: [PATCH v3 03/12] iommufd: Consistently manage hwpt_item Date: Wed, 1 Mar 2023 15:30:20 -0400 Message-Id: <3-v3-ae9c2975a131+2e1e8-iommufd_hwpt_jgg@nvidia.com> In-Reply-To: <0-v3-ae9c2975a131+2e1e8-iommufd_hwpt_jgg@nvidia.com> References: X-ClientProxiedBy: YT4PR01CA0100.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:d7::21) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA0PR12MB8086:EE_ X-MS-Office365-Filtering-Correlation-Id: 1461981a-f6f3-421c-cb5b-08db1a8b6b57 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ByEN5sSgtsrDbQc/u+YjEFDQAfjsGhlzg5IxCxwRTZ63r/ih84295LQL+mQQB2S05DaNIv24RcLlqfyhYf5weczdV8dUk88E9MzcVRh+6PJkMgl2vV+jTPgq0ES3Vm2H/vksRhg9GYgD45Jz6az451foMgNe3EJtDZpdGsGKXkG8mSownE4Cl8KuVKWywV70WFVyrH1DPgZPtrMh6PCBafhhhtoN4n5ckTlSyIN9tYbNXtCDQ4Mp34u88RJ0iLQ4oTzR1snR7TfGPLV9cY6WM1KAqDPedDdPkgWluak0h9BUna0+SaJFRoPUcKivxEcv4+p/hi29ZxmZgAlbil0dZZ4ZJNmJNftrfB02Jdf4g1PZET/fZXmQugMO047pzkgknY2L4KMHnG2cJfTtIVpEc8RV3PSKdAtI4+K+qJmn5l2TZurbX8YybZwRQfjIgCkzGjy4fHwYsLfECBUNstntNa5Porzr3ZA4A4kLaXj2O7P+rEH8rGDdrN7Q+xzmQa8EQ1JcMRj7nFICrnQM2Q7ItWiI9stLtqygdd7VojTsBM8e5Qk9FZtQR45x9mjbnOedKrfJY2LlOdfSx9lZb+vB9XLwPPQKI7uHrQvm3Oaz/gIFMCU/oLzK+UeIDJB9TuPK7XUV4KBRmtIxzUvn9FDVXSZYui4d5zibaNZistnUVVMxT3Dt9i66mBOkzAjCsz0Y 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)(396003)(376002)(346002)(366004)(39860400002)(136003)(451199018)(186003)(2906002)(6512007)(5660300002)(38100700002)(26005)(6506007)(8936002)(4326008)(6486002)(41300700001)(86362001)(2616005)(8676002)(66946007)(66556008)(66476007)(6666004)(110136005)(36756003)(54906003)(83380400001)(316002)(478600001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: EJwvlDAJmeIQ97HeF2hQFnXOXLpCC0HZXFFhFRFnCW32hahCID4PTvy2O4/ohJpDyk4u7eahWgLR96c61lnZUxq/1ZHkByf4ECuad96FQtfm8Uq+JzyoWPyIZJJkJeYIL9xVuixiy+hSPh2LEVViIFeQgHgKz7RyosSK+ApMLGxEYcZB+MxubKItKD/jM7cg75QLmqsh5rfNafOwwUJzJsCu1fbdv0pf5IOOxHJ+o9HhWejD/3xVTvQe9jQozDj8Yok9S37sG3eJnkOeCguaq0+H5Y5GF7jRp5/GYOJ0qkQRdqxtqOvIdwRnRrKURua+KndP9X9frxo27RqtYHoVdhL6yrcs7FrAb8EMB28dO6OPiiR9NCDLT4cBNi8hS3WZo5qsRk8V00KH7KrvDOE+YcsR9rUUjrERvhtaHnEW92RvvG0i5chXKKmSktfxZ6yXSutSGX7dtJdV5w+bDogcqaS5QsAIMHfvTwSLUwtgnr5pbP+BpOtfDAb00TiDDC9Pv9WxZnmrsmonZ4jBKCUmag7zKU/xS/pl1MvHR3ew+EoSyi9KN8S2o6TxX+YnJVuX2G45ZcK0xVlASKqOOGpBaoV7Gq1UJ6kVSheicIzn6xAISybleMi5Uah37PsT2BZnRUc1ywXR31uYhPHBLa7eoJodymiuN7NtCKhG+wFHO7iPekFlpLW0GoYgfNyc9aFrMUYA5LRiYH/8NMiByvnFtHA8TUTDkk1663d3mWKHMArDr0NO1raodzd+ycY4QLR6bHAJEKzP7IIHsBXhB4WoL7fYOY2k8C1AMBRuZqVVh6KPcyWDPcsW4QH5bZmNuJSFWHLLH37jQuRNj2FZQ/5KEnvkGJH/yGrAywN8K7Ufv18mmLXvfaE83wSgi01/zssHJ/JwGWmjjmq3/HrSUh4U+fXwJhKlWjY7b4CMXCXiCoV4VWrtb4bQYMmLX2Sht8EgbwAxa1CvPMYdDL8SeRVVwbro3KsIaFMUzwt/07J4LX4UDPi6azYRwisivSiy1B45QXntPcWTMCTta98x55OtJU/nmipA9+3UvHplqDZr2ntKma0Mmfs5+8n6FROG7i1IkwBWMa7egWHusXSlRGfl564w3IHPEbk63kfNSoGVcEqFNGzUX0YZSIcWKEmbu+MT6MLsFWtj/+WAkfqv3nXPwT9OMGK95jslhWH/9gIdWH/mYuLdAlFs/Fv17RNr6Y5syNx9sTmGtgHb9FSBso4v2a5+eDRu3Pp4aUWBsmRDRP3rpKCWcTW4wlyHD7TjziNrYT7ZbSBDOnxPv1DKqItgnZExbUnuAEL14YMRyC+LyTKvFPpAMgzWLnVQ5vR+of6Xn5GiTE3JB5VuwPmvD236hqUEF8Fl7TWfUr8bWSqc+l3aPsy+0igT4+KEGDvgr4N4zmhLlhRLLFuNbFMDaKKjKyLJBqG7fosdrPUgR3J3LrPqcxYJiW/2NXWxewmn9/KFSOHQNrQIomvLzUg27EBziWzLhxjV9vXUsvqd8yJQ9tbMb4wMdF0O2auvzdbxNWjUwiZ44rMAHTk8QDGvIVqiqogn0dhBWnANr457q4b6n/RBs8Ox47JGkfGK8N9XEDLz X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1461981a-f6f3-421c-cb5b-08db1a8b6b57 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2023 19:30:30.7999 (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: lAG97VekCcUyKRcYBdVHfgbz4rCKgcpEcJrAUuPLR//q7yG4oAjftt59UTPDuh7z X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8086 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org This should be added immediately after every iopt_table_add_domain(), and deleted after every iopt_table_remove_domain() under the ioas->mutex. Tidy things to be consistent. Signed-off-by: Jason Gunthorpe Reviewed-by: Kevin Tian --- drivers/iommu/iommufd/device.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index 0a80ff7b2e0d79..adb73539b39c0c 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -243,6 +243,7 @@ static int iommufd_device_do_attach(struct iommufd_device *idev, hwpt->domain); if (rc) goto out_detach; + list_add_tail(&hwpt->hwpt_item, &hwpt->ioas->hwpt_list); } } @@ -307,7 +308,6 @@ static int iommufd_device_auto_get_domain(struct iommufd_device *idev, rc = iommufd_device_do_attach(idev, hwpt); if (rc) goto out_abort; - list_add_tail(&hwpt->hwpt_item, &ioas->hwpt_list); mutex_unlock(&ioas->mutex); iommufd_object_finalize(idev->ictx, &hwpt->obj); @@ -753,6 +753,10 @@ iommufd_device_selftest_attach(struct iommufd_ctx *ictx, if (rc) goto out_hwpt; + mutex_lock(&ioas->mutex); + list_add_tail(&hwpt->hwpt_item, &hwpt->ioas->hwpt_list); + mutex_unlock(&ioas->mutex); + refcount_inc(&hwpt->obj.users); iommufd_object_finalize(ictx, &hwpt->obj); return hwpt; @@ -765,7 +769,10 @@ iommufd_device_selftest_attach(struct iommufd_ctx *ictx, void iommufd_device_selftest_detach(struct iommufd_ctx *ictx, struct iommufd_hw_pagetable *hwpt) { + mutex_lock(&hwpt->ioas->mutex); iopt_table_remove_domain(&hwpt->ioas->iopt, hwpt->domain); + list_del(&hwpt->hwpt_item); + mutex_unlock(&hwpt->ioas->mutex); refcount_dec(&hwpt->obj.users); } #endif From patchwork Wed Mar 1 19:30:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13156352 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 658AAC7EE23 for ; Wed, 1 Mar 2023 19:30:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229649AbjCATag (ORCPT ); Wed, 1 Mar 2023 14:30:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229561AbjCATaf (ORCPT ); Wed, 1 Mar 2023 14:30:35 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2062.outbound.protection.outlook.com [40.107.93.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C95275FCC for ; Wed, 1 Mar 2023 11:30:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GtA71LIEA9JI3JmC1Ah1PeRZCg8G2QuJehuWkTqMCixCxmr1B96UX27gjRkbPD6CFr6hPPr2yY2DvYXkHziFaioD8WeB7NHpTBS++jltEmbzH7z9THVBovcML3kSQJDnRLHcl5chX/ZPIeLGrUurFeQiKRLqReQeZthydHwpb58QoRYDYeuO2csHaHn8tn4zAINSR2x2wEmVaSMsgEkY8HMr73PvJRWHxb1rs4XXrByRSf1vU4xrPG1Oc4JmNb9KvoyMcqmx+CJBwmkvoDgPkBtIA11He0p27voGubCxiHsyps9xJux0sWZBPStXW4y0LYkBt4HA2Vluw6EgP/MIvA== 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=5QubGYVFKToRpOqo23e7c6OHX38arz2HH1JaQG3zIZ4=; b=UW5i/RuvNaWIyjxra7NYCTcQ9lpvgpEjUDR1sAc+q/pqQrjI04ej4fWCiVUdUNoPMDw8Rn9s1/c2vhLhQ4oe0IH4jxj2JSzSleR9hcBD7fHL/sNsHRciNVwo5OB0xHdpMiNTJdkFdhtshYtNI+zZiopJ4B5AvunUOgMtFeJ4JsjBC0GUjlTZYH0HeZjsR5sOzxgNi9qdTGFtTzRZK9gV7hQfYJtja8rRWKjgV3M4BR9XixeTLqwfJC/H9m5mgIGj3ZHvKNEAlsnt/0fR7TW37q8jNvKSwalmeNx1dJSE7PwoSSSgLO52Pp1zXgP2gwXKL1XXsJfWBoUbZIRs8jxBPQ== 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=5QubGYVFKToRpOqo23e7c6OHX38arz2HH1JaQG3zIZ4=; b=PYlRBcXQLlCVvy2Kobfg6IuTQGaRb83FEXpLNtxWPFb/4YCsrDJhDR1vX37+YbByg1Mq/LJS5f3bqF6Et/J/qwr2X2YnCmWrJ5Qha8QeK0V9W8bwEafmqCetGXGX8QVHXrt1VMrjRzRsFzqnV8YD9l7CnQwgwU9X3Mq1u49BsHO2wYoSGq+E+XNlNnNwZeV8kZIdS3cXsofp1uWbxWDyhFRdhggdlBJPvbjd0u2HwqVnZnDMBgm71z2JPrnQ+kzBWxNza/E7p7f3wjdqoZT9XW52DRZ1JP7eSnvC+6KzXSbqe5zOR7kFoQuT+x/ygTwpBsdqToA25Ecmi7rZIGZ9MA== 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 IA0PR12MB8086.namprd12.prod.outlook.com (2603:10b6:208:403::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.30; Wed, 1 Mar 2023 19:30:32 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3cb3:2fce:5c8f:82ee]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3cb3:2fce:5c8f:82ee%4]) with mapi id 15.20.6134.029; Wed, 1 Mar 2023 19:30:32 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Kevin Tian , linux-kselftest@vger.kernel.org, Shuah Khan Cc: Nicolin Chen , Yi Liu Subject: [PATCH v3 04/12] iommufd: Move ioas related HWPT destruction into iommufd_hw_pagetable_destroy() Date: Wed, 1 Mar 2023 15:30:21 -0400 Message-Id: <4-v3-ae9c2975a131+2e1e8-iommufd_hwpt_jgg@nvidia.com> In-Reply-To: <0-v3-ae9c2975a131+2e1e8-iommufd_hwpt_jgg@nvidia.com> References: X-ClientProxiedBy: YT4PR01CA0106.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:d7::12) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA0PR12MB8086:EE_ X-MS-Office365-Filtering-Correlation-Id: 38b94baf-04c3-44c2-9eae-08db1a8b6b8e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HPwbdYtIMy5fLM8j6/BUTBHHQ4IR26OksW0qj+gWzIRsHVQjtUXNWhlNlQYv1fplgqusZ/AtsAES0w5b5TTFrUEyev49ODoSMau7kr6FstPxm5Sm7bWvFVjdy7vPacwLuw9UPBX1HA7p/BOy/wiBS35KeC+MO+Q6ZYttIdPIUNW5n16SI658svPR7TXNg7HEUfrEbOKNujC3q767BClAjfK2dy8V4pyPe3ruXvvruKVzaGNd1K2JqRA4TNavWDGXzPTRw6Ez3ZXD8zYVfR5WPN1mk22ZHhouf8/rZtuStDm5lQ4Jm8x7HrbMOLP1npKro4czYS6A/L0vo8OEHtPxOirhr0x9z06W0QfLXIgDEJAllRXfiVa0RVwUIU5uPVV4dBplrISZJwVVbBdCugHnTIdvnjvhi4K4SVq4S6KThXBL3wR31nAIvUquNHEd8lH/7kfGpIqiBZ3dXCL/9DMd3tp+aSphN1i+fTXc2IOg6gu17J7WM/tciu0nwTUFnAAS2nv209Q4S12nx5lYlr/RrS4dwlaCQR5A3hDbH6M3Q17QagGlZFj9c0t+4Zct0yg1ybgjNtRItQfr0THh8izMHtUanxNyP5JPVIFFpzSkpgsv5s1xohvsyYPZhJB7zYRPjmfX3+kaqIjUVat4mYDx7tuC+jVwhfsZO0HJwMG2CMe6IPi9yRuYMXEFli5O7Mpv 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)(396003)(376002)(346002)(366004)(39860400002)(136003)(451199018)(186003)(2906002)(6512007)(5660300002)(38100700002)(26005)(6506007)(8936002)(4326008)(6486002)(41300700001)(86362001)(2616005)(8676002)(66946007)(66556008)(66476007)(6666004)(110136005)(36756003)(54906003)(83380400001)(316002)(478600001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3yXc4wwl7QCuSKd8UfC6zU37WFwk+vFaQuwcwVRletgZKYU2cLFVzw6LMCzNJN64eMIO6UDcxeG8d8s+R1RRNx9+F/6UFSu7ahJUWvbvBAmc8napKKZ+s2me+B/0GxhNgd/LiUResG9P+n2y/Rc8crdkdXw6nn+kxTmhsNUQ0aMnc9DXdXX9ABynZsqcyaRAqRGylCOlQkEXMYujatDm/KIdqlrGDHxs7G5B47YKcEFmCQta+lhnS3rjbwPVyDI9nU7gzsfSW6cK26Rbn2hP6op5gV419nG8EAwdnNR8T91MxYufPT9HY/vttWZhBTkIGxTzi9aANku74wu+pw6iOolta4TpR/TvVgeZTZVqzlTvakcy/qUnnl+yhSocCQbfm//hsNw2rnLR5IgRnr+HmGu82f3CcoliWNb5fWElmeEK/KPASQzge+VM1pZH/iqo1lzArEEKWpDYLDBYBXqFc5U9zgNAggqbPeFnF+RXaEbr/lOwecgPPa8S05ZBu8NMpfQqDr06YtXPPNCn6blrcyaJWi+u96XqgVsIe4sT7rj2LwZCPYr8CFoywzMZ0MEN1AEivPpgMz7b3+VsLLJdw+XAQQp9skVWV3EzvOUtrvodRDR7EhCzkPBF0fMNvkErFhEtCh5oydrVy7thFR46Rk8TgM/5Oq0XN3/Ntrplxg5YppNrVRNhNSqeMAa1oXadNycyvPbNO2g5gHfQYaWoPBzCxldfcD1Ee0xJ1cgNsMGJUq+WCT2PLv9vxE31nhULB19mn6xupuwReGTfm8WZ63v3yvP/zH5Y1VHu8J19DmJix3BJvY9J6jqpWfrcbUdIT+KU9yPiQJtyXmFLKYNegU27X3dT9bthyVC15kENptaOlR/DwKrB396oy9/MLU2l65XF4DyozQlWWCmiotzOCwSnzbhPvtEJg3IiCqV72GhYhgbl9fRH2IUkpogz8t7FPAFXwdqhLniAZDgf53DgtDYnXDbh65yukrW5SYIVxad0SD2EvrZsmaxL42f+l8N4vwt0JycCkL+CBmUCGIlgS4z8FkGRxSXh+I3ybhrBMxFNi5ZPetlwXJn4MQZCDNm5swtBxJMfJcd7yiCZdFDVhmNU+suaYN38QKsVcuP6FYIdmpJH9fTHAAg38OKKN9zi5Gls7ZGjq5QjwITrjSH7X9Z4pmsomVAwookVlqU5AbR+I83gDqg2IymLw1lqcGn0ME9xOMmWo5vSrrqMZVts43JUT8Sm0XW9DdqkEgEqfFLmuqmR15pXgKMW/OgZf3K8jt9IPvgXFd64U1oAnfENdmBmakfhL7rTt7JWQVM52+N4tlBBtHUZtMyjqmp4l68SbhHZQ+G+2zY+L2pVrEPae0U5swM47sMqfmwA9GbKpiJQUgtGJGVP0WiDrv1T3XBxRKaziqad8NCEt9R/IcDD1XFHZfw+w6EO3y+ImAkQmv3jMtQUdgMphpJ2tX4bYxnhmMWRSILRQjQPX4WnSOKRC9tfP83Ezfvd2MV/nj7FNWi0p2wfkLgmorK2XBXcb41hLZribcXj5towp1iRKWo0Bq5Da+E9qH5Wtcsbs8CJQGzqdxqhi50shhSn3+1zQk7J X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 38b94baf-04c3-44c2-9eae-08db1a8b6b8e X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2023 19:30:31.1435 (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: 84OdcWa4SrjRDHbL4ZjdIXjBQkdGuc1ydSQEZisCtvuAprIglw46z0oUxcA0UmCV X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8086 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org A HWPT is permanently associated with an IOAS when it is created, remove the strange situation where a refcount != 0 HWPT can have been disconnected from the IOAS by putting all the IOAS related destruction in the object destroy function. Initializing a HWPT is two stages, we have to allocate it, attach it to a device and then populate the domain. Once the domain is populated it is fully linked to the IOAS. Arrange things so that all the error unwinds flow through the iommufd_hw_pagetable_destroy() and allow it to handle all cases. Signed-off-by: Jason Gunthorpe Reviewed-by: Kevin Tian --- drivers/iommu/iommufd/device.c | 17 ++--------------- drivers/iommu/iommufd/hw_pagetable.c | 27 +++++++++++++++++++-------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index adb73539b39c0c..6787a0d8d6e9f0 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -386,28 +386,19 @@ void iommufd_device_detach(struct iommufd_device *idev) { struct iommufd_hw_pagetable *hwpt = idev->hwpt; - mutex_lock(&hwpt->ioas->mutex); mutex_lock(&hwpt->devices_lock); list_del(&idev->devices_item); - if (!iommufd_hw_pagetable_has_group(hwpt, idev->group)) { - if (list_empty(&hwpt->devices)) { - iopt_table_remove_domain(&hwpt->ioas->iopt, - hwpt->domain); - list_del(&hwpt->hwpt_item); - } + if (!iommufd_hw_pagetable_has_group(hwpt, idev->group)) iommu_detach_group(hwpt->domain, idev->group); - } iopt_remove_reserved_iova(&hwpt->ioas->iopt, idev->dev); + idev->hwpt = NULL; mutex_unlock(&hwpt->devices_lock); - mutex_unlock(&hwpt->ioas->mutex); if (hwpt->auto_domain) iommufd_object_destroy_user(idev->ictx, &hwpt->obj); else refcount_dec(&hwpt->obj.users); - idev->hwpt = NULL; - refcount_dec(&idev->obj.users); } EXPORT_SYMBOL_NS_GPL(iommufd_device_detach, IOMMUFD); @@ -769,10 +760,6 @@ iommufd_device_selftest_attach(struct iommufd_ctx *ictx, void iommufd_device_selftest_detach(struct iommufd_ctx *ictx, struct iommufd_hw_pagetable *hwpt) { - mutex_lock(&hwpt->ioas->mutex); - iopt_table_remove_domain(&hwpt->ioas->iopt, hwpt->domain); - list_del(&hwpt->hwpt_item); - mutex_unlock(&hwpt->ioas->mutex); refcount_dec(&hwpt->obj.users); } #endif diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/hw_pagetable.c index 43d473989a0667..10db1359c067c1 100644 --- a/drivers/iommu/iommufd/hw_pagetable.c +++ b/drivers/iommu/iommufd/hw_pagetable.c @@ -13,7 +13,17 @@ void iommufd_hw_pagetable_destroy(struct iommufd_object *obj) WARN_ON(!list_empty(&hwpt->devices)); - iommu_domain_free(hwpt->domain); + if (!list_empty(&hwpt->hwpt_item)) { + mutex_lock(&hwpt->ioas->mutex); + list_del(&hwpt->hwpt_item); + mutex_unlock(&hwpt->ioas->mutex); + + iopt_table_remove_domain(&hwpt->ioas->iopt, hwpt->domain); + } + + if (hwpt->domain) + iommu_domain_free(hwpt->domain); + refcount_dec(&hwpt->ioas->obj.users); mutex_destroy(&hwpt->devices_lock); } @@ -37,21 +47,22 @@ iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, if (IS_ERR(hwpt)) return hwpt; - hwpt->domain = iommu_domain_alloc(dev->bus); - if (!hwpt->domain) { - rc = -ENOMEM; - goto out_abort; - } - INIT_LIST_HEAD(&hwpt->devices); INIT_LIST_HEAD(&hwpt->hwpt_item); mutex_init(&hwpt->devices_lock); /* Pairs with iommufd_hw_pagetable_destroy() */ refcount_inc(&ioas->obj.users); hwpt->ioas = ioas; + + hwpt->domain = iommu_domain_alloc(dev->bus); + if (!hwpt->domain) { + rc = -ENOMEM; + goto out_abort; + } + return hwpt; out_abort: - iommufd_object_abort(ictx, &hwpt->obj); + iommufd_object_abort_and_destroy(ictx, &hwpt->obj); return ERR_PTR(rc); } From patchwork Wed Mar 1 19:30:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13156350 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 69F06C7EE30 for ; Wed, 1 Mar 2023 19:30:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229613AbjCATaf (ORCPT ); Wed, 1 Mar 2023 14:30:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229510AbjCATae (ORCPT ); Wed, 1 Mar 2023 14:30:34 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2062.outbound.protection.outlook.com [40.107.93.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3A5659F6 for ; Wed, 1 Mar 2023 11:30:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DxtrHg5yWY8fNO0LTuG+4F8ELfQsYhet/3iyj9k0chN2my9SibylW0ixBjZPa755cGMhOYLPVKj9lQ23YpWolBO3Ki7JbcLKPCkG2z7kR8OhjUs0FkrMdhtJ0//xxc2nMurSQ/DurEVavAkbDnkSmhHljFSd4GlIVdfNVHCRgW8+SdaqDGYLGKyes4XTWH967MVaVEckPnQ859nPWBvPxTeOk7cGGi/IWzMQ5KLngnZdPAVGvtx+C1c2hh4Wd52QfDNGejusvnf12WEyIHpnQduoWJbT6hoO0vkPtIxc+iO93txRi5VkKqdw4OBHBGXFYK7Eu5sABj0w40Yj8lnaTg== 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=0gaGur/d3vIig+rSDq2d3qya2Ehj8K222XcjOQiNMrY=; b=IcFuazy/hkFZ7eoOQ8VgtTnGcVtxUvebJC+/PttH850heKmmTtC7JGWhmrBKyosOqzRXpG2WGFfokf2Xm0IditAHbD3b9CfOEYE8BRZyUTx9cIKSSHX7vZRrTSRvgM28tCpZjtOQ4tJ3JwdLt+jfImtv5Ee8fAa6P9tmwgbnYRZi70tfGbc5AfXsov3F2XqYi4agM745pKVi8KY6FHh5UnThHhw/O9NzHmdC5SUj2RYIMJGUpQuw0sDSRreM+sDKUCw3WE9EjzY8jHvW1oaIEaoqXtDS7bavfP3qVtJHHdI1RfSmx0GqFUy84qnUO/aU1xinWZ3lAGWI89IB4BSbtw== 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=0gaGur/d3vIig+rSDq2d3qya2Ehj8K222XcjOQiNMrY=; b=Oqq7RqR4YSYz5ieyfZKu24DCkSTY0hjT9BGEf3e3LFdwtR4RjtXBBEiFcz5ijF6Ko29fR5OP7xNQ1DCXnc+8W55h6tXxFT+2CIevOefC2q0rVQKM3y4vYlzM1SN9lz6ffORVuIcNbhLcbk0vX+8vIRYidctoNV6tF6rhp3kBamhJ9NXzoVMqApuPIehBT3IapG2J7XqxgiOzjnwvVersOK3OsnEj1sIi6L3dyAvu+fre9WpsgGCI/wnBDF46y4HwaC7QHsYUQ3Z7pJLi28AYi33pw4xCNsrf1Abln+UIqwwD5Ye36Aa4eRrqzgFN1p653+fyCkpoguHCRYy6AILiwA== 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 IA0PR12MB8086.namprd12.prod.outlook.com (2603:10b6:208:403::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.30; Wed, 1 Mar 2023 19:30:31 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3cb3:2fce:5c8f:82ee]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3cb3:2fce:5c8f:82ee%4]) with mapi id 15.20.6134.029; Wed, 1 Mar 2023 19:30:31 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Kevin Tian , linux-kselftest@vger.kernel.org, Shuah Khan Cc: Nicolin Chen , Yi Liu Subject: [PATCH v3 05/12] iommufd: Move iommufd_device to iommufd_private.h Date: Wed, 1 Mar 2023 15:30:22 -0400 Message-Id: <5-v3-ae9c2975a131+2e1e8-iommufd_hwpt_jgg@nvidia.com> In-Reply-To: <0-v3-ae9c2975a131+2e1e8-iommufd_hwpt_jgg@nvidia.com> References: X-ClientProxiedBy: YT4PR01CA0070.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:111::16) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA0PR12MB8086:EE_ X-MS-Office365-Filtering-Correlation-Id: 92cba08f-b4d4-46f0-6915-08db1a8b6b55 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Shw7guy9tXP+rjoFltczK+KZXlQCERyDSIhlyJ28I6I1zf5lCMXUoMqGLuZe3Dtvwt/0RJaqkHtjpVhddX3j8UM84/ZAeAKyOAjWjRauaQOW7NTX0o0T9B0EG+B5Aqafk8UEtFAU8cpO3CGenUa0MlpuogTe6mmowpMgnyfxWE+Cvanme5H0wf/uf0skDdCoyphQft54WdczQzOUaXtNKePY2hj+NHYUWFHdHM4eD3ze5zLN9e9NQ/3yVAXSITJX4WcuoGexDdYlB02HCk9WpfARxYdGdlU3PysN3aYCzRpUJj32uG3Me3oGY7r70SJCURI68TalwcPJxJwxkio8+dsvQi1YSlh5QQat4WJQBpjuONM+ne9jwFm/It62XgwbmyATzufgEXjXEWNnjCGag8CWPPtP3p+HGJ7qoUN52b0WZONCzAKqJ+o2Zrf+hH01up6rVJvxwC/jsksSSx3khAAjzo1RchArNaXBFbHObDl5sLckcwl55l3TFa6tFRjAf5CsWpRb1B23ySo8jHvxHkTvjlAtFJM0/e/XU9cJ+i3VQs0H/dH6izbSC2gyC8gMhYgPDGgVFNx4jarAhM8AtCZKPHAIwASY3x91iQR1AT8P6RKblIM0GjE/Yc1paqS3J2Y5E8kBbtN5MLbfVzZmoFT1mkH8/I6rw2ljlpxKkZ3carK8r5vN305SGjGY4l7n 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)(396003)(376002)(346002)(366004)(39860400002)(136003)(451199018)(186003)(2906002)(6512007)(5660300002)(38100700002)(26005)(6506007)(8936002)(4326008)(6486002)(41300700001)(86362001)(2616005)(8676002)(66946007)(66556008)(66476007)(6666004)(110136005)(36756003)(54906003)(83380400001)(316002)(478600001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NP7CagyYfcpxfyOnCPl5zAVijEKDcM3IsgAYTAuTHsaTj5pPuQ0Gq0soTiW2Nurv6uVivRTYW4c+yhxll+kddD4Kc4iwwzenyI+Ejxo9+jtJiC+RTXyN4QGsOnWtOY6KRcQcE8hWscHYZMcT5m8t8ZGGNIH6bfF+9biIuZZOEQAdX+nokKO5h5p1iyYsYVUKN86PDDVpAPxpFulWntqtlBqqA7ROgiwY7Tqbj7PT8qkmiHF3HO4gq9pHLpadze/KnvvuQb2T6ijb6ZEOTiO1QWs/mD8d11Knwr0YtYmWbgvCEcCDXq1NPG/M1rvlWn5UafbA8b5QIBMKg06BBnA42HaXaPztggDi50a7Cj3J6/qhTXQlirXMVdpT5DtFFCAG3lc/IvvDgqnt9HCwvzRwzLDqJpbrlGnUmvmWvrYFcAAWPgKVrLMp2CUxSHNhCr2AzYObzmhq4WOC7Oe994s/6kt61JQ86s0drtUD7cmmxHJLUFcat0dczjTWj8I0O07b8qk9IhvvHp6B6Loff2oFqzn+qr9sTDNRjWhcS4DwFw5PHuFePiLnO0lbhlrym49j948pOcCvs6aHtk+fVgHnO++qdmD7QchLaDh3pnm4iHNpNz/VwmKXQejG86EmKLS2ABin3oYNIMhcqrECwlO3sdRpyO7wREfGTXBaKmO/NjydEjif8ic4w/GpGv2YzaZfuXUyYAL7x1X/K/l3BaZYHFjY651cg7rJg9Md+pkn/6qjnPG9cUAoVvbgMkkyIsr6bP0IRRjC6MG26asYYkTRuYbCUMG3QQsd8ue37I9D6IyBf5LHcZpxcNKdgaZbGzldDQ3nLN2jB7ACyd+JwcE/RuavKKxtdkQZVjZiv+8rjFmp0047ZM7yt6NmKeBqC3EytQ86CQEz3kD6ebHzNAF1afawzhJ8q1rhg0egeJfzIqjjHR++PJJms6vOTnh7EvQntpomTQBrYNXn8tG5d+8Iut22bm8q/A7NjZ+SbJTVuHfsU/FJaEV/vYYr1Jqp2oqaAd7OGbRlO8DvhRG5tUvXreXZsHUDYnL+A1UipxcqvtmnmRr32KtwMyyH0xOL8Pspy1gItTHeHsH1DRFzepehkdey2jxZzl5IRULZ5A2TbTKpEg2jxNOc8yqZXL63htVghb2CpdNV14vng1JBwJWOHdOvtcWQGEuqrNUoF4DMTgYwpkJ2xMkxrSDMGHjyYfKBqNT82TENEoWc3e5NmtX6DFUWfL2KmADSNXIjogUdyF5aDJ843I0LgW9/05ZvUc+7DW/ZBlgdjbq06UGVhpIVeOIOvFyz7k0qVzPnTBwk01gxQs2G4C51BjG1YGxEwf/z3dTA5YeFItJ2Mk/UYa8/HwdtIeEIKjjHwysy7VP80np5OaRyKjItn2q0Tf0b9nFwFG/JDIKusTROS9eZxnVit0uOJES6I2ekU1IG43WTVM4gJdFnzdNZY+b0dI5iSh6D3hJ3zE0ATCz4cPUVv7zqy1kK+HYm554NrRJmSHjlUNH1GaAU/v6G6ZI19FIcEK5kF6kmdneIDwgaX2wsSW17TU6uvff2cdHEDbfBZ3lZuHYVpvQcyRittYlIZmDew48+ X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 92cba08f-b4d4-46f0-6915-08db1a8b6b55 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2023 19:30:30.7999 (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: vapVsD7OJxACAMUfgPt0da2fChw/WjWQMSdlqxUpLOuM8z0IdJV8l54KWfUsQhK0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8086 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org hw_pagetable.c will need this in the next patches. Reviewed-by: Kevin Tian Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommufd/device.c | 17 ----------------- drivers/iommu/iommufd/iommufd_private.h | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index 6787a0d8d6e9f0..4483c06e0ec38b 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -15,23 +15,6 @@ MODULE_PARM_DESC( "Allow IOMMUFD to bind to devices even if the platform cannot isolate " "the MSI interrupt window. Enabling this is a security weakness."); -/* - * A iommufd_device object represents the binding relationship between a - * consuming driver and the iommufd. These objects are created/destroyed by - * external drivers, not by userspace. - */ -struct iommufd_device { - struct iommufd_object obj; - struct iommufd_ctx *ictx; - struct iommufd_hw_pagetable *hwpt; - /* Head at iommufd_hw_pagetable::devices */ - struct list_head devices_item; - /* always the physical device */ - struct device *dev; - struct iommu_group *group; - bool enforce_cache_coherency; -}; - void iommufd_device_destroy(struct iommufd_object *obj) { struct iommufd_device *idev = diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index 9d7f71510ca1bc..84fe19a195466b 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -12,6 +12,7 @@ struct iommu_domain; struct iommu_group; struct iommu_option; +struct iommufd_device; struct iommufd_ctx { struct file *file; @@ -257,6 +258,23 @@ iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, struct device *dev); void iommufd_hw_pagetable_destroy(struct iommufd_object *obj); +/* + * A iommufd_device object represents the binding relationship between a + * consuming driver and the iommufd. These objects are created/destroyed by + * external drivers, not by userspace. + */ +struct iommufd_device { + struct iommufd_object obj; + struct iommufd_ctx *ictx; + struct iommufd_hw_pagetable *hwpt; + /* Head at iommufd_hw_pagetable::devices */ + struct list_head devices_item; + /* always the physical device */ + struct device *dev; + struct iommu_group *group; + bool enforce_cache_coherency; +}; + void iommufd_device_destroy(struct iommufd_object *obj); struct iommufd_access { From patchwork Wed Mar 1 19:30:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13156357 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 E4C9FC678D4 for ; Wed, 1 Mar 2023 19:30:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229653AbjCATak (ORCPT ); Wed, 1 Mar 2023 14:30:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229617AbjCATai (ORCPT ); Wed, 1 Mar 2023 14:30:38 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2062.outbound.protection.outlook.com [40.107.93.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9152D59F6 for ; Wed, 1 Mar 2023 11:30:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ov/AihjVM09Cx7On/WLjXLzWcYPC7QYpViDbq8MNxpZCP2APJiMvez3T4FnuLGqXUnalSB8u4bRAFbDrqkw2q9BfzHj4NR0ZJH+LaEttHkBngOjWjJ2Y3mNg5pPWyp8skKTalg4cf1ZvoNTcHTz/CZ5nCyMU8e2g/QT5DrsbJxqf7ElPEZ42GFdLNwCkRkWkSpK6X9kVChY9XUFz9PdjxlgXboGQEC6fLdxoD0Ef9DeBrkoEtU4QZD3bwuaj+Ssqas4Rqbr3D0lrPnv6b4Vwni4OHFYhQXpaC3diUWvzLGGUbnZNOKGaxnmZJPBsPQyHgC53f5AO3ntseCqU1gFjfA== 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=AP2vJ4pE+0nTVKgw9T6qdY1AufHcmJp///XQ6wrz9cg=; b=IdshJMJczjghPqbgbI2Rux1aPZLQk+Q1rhu7gpoMqs3OjLikifpwq8RFiQgqNgxvfzSxW7GThvOhROHrJb1ZGSyOveL6b9HRd9/KQlDS8dXv2oj5k9ZipdxuaI0d7megFmLPpTa24y5TNFH9X31tJXYL8v0Ay3cswuRE29iCjAYCxUalvfdbBGoDKiAUGIT14k7RFgzh4RomWkwDnwoTh3oRXf9yTj0ZBpouziow7uiXXLfa3nLytLtdmJeaZeUbr1afFNWRdVfrGboS1/6/s6Rc8qUYcFoYP5FxpGuzR9HRbRbbUNGkZaD+kLtHcpZKXQ9MZzT9fLsx/186/RHiug== 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=AP2vJ4pE+0nTVKgw9T6qdY1AufHcmJp///XQ6wrz9cg=; b=QjOCLMpmvE1yHlv1K1uKjYLGCAlf2hQZNn4Vxdst3F7I2T9cyva2JoFVHTEP3hK8kFPAYTDH0NoZg9PgRXQ498vzhGRhAWGco3qxavQDr/uWTbRw3JvrYeY5TFU+k5WM6ZnHSfpOkLwso2M1hkc4AzDYp3jwvRTqj5sSgplYOq2zb1MxiDx+morRWxjfjSHYGcSHfUTyAQnrv82RtU9t6+ZyU9Xf6K9ERM7SZnKC3n/PbVEMscE6TKUNZf6mcCYGFG/OSxBhL8epS4HX1M8mJ1Gi/mT9k6vDA+tqpi0xj1YTaT6ycRYaVGuqMLyFm7s7yuefxpEKSP8XjW9rs0UXKQ== 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 IA0PR12MB8086.namprd12.prod.outlook.com (2603:10b6:208:403::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.30; Wed, 1 Mar 2023 19:30:34 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3cb3:2fce:5c8f:82ee]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3cb3:2fce:5c8f:82ee%4]) with mapi id 15.20.6134.029; Wed, 1 Mar 2023 19:30:34 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Kevin Tian , linux-kselftest@vger.kernel.org, Shuah Khan Cc: Nicolin Chen , Yi Liu Subject: [PATCH v3 06/12] iommufd: Make iommufd_hw_pagetable_alloc() do iopt_table_add_domain() Date: Wed, 1 Mar 2023 15:30:23 -0400 Message-Id: <6-v3-ae9c2975a131+2e1e8-iommufd_hwpt_jgg@nvidia.com> In-Reply-To: <0-v3-ae9c2975a131+2e1e8-iommufd_hwpt_jgg@nvidia.com> References: X-ClientProxiedBy: YT1PR01CA0127.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2f::6) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA0PR12MB8086:EE_ X-MS-Office365-Filtering-Correlation-Id: 98872ac8-7b3b-4cb2-4b00-08db1a8b6bad X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: B0Ty30eQqC8Xyib1hzCb2E6HFSGZQDG0YcS+VwAv7DSrdXM6MlP4GGNUCxyitrj7T8wW5wlPAABQo4nUuAGBf+kfGa7c/nNZmmX81QwGl+N9vMG2jXFUS3aP0xEKb5wO26eya6TK926cQXfnV2ujshsKF1fjZfkNCrM+XTcdXzocw2ryj841DF8B+f6fUG+omgQCWyZRohl7vKq6O9lqvDNH7OsW5781/KpEHzHBQyAXFEKqcce4hj1dEoHzLrSkkowEBxud5YNsQvlCQIGeQzmg1aYjZO9imHcIaHVkmTgralSKyK4UnZC7R+wZSnlc5pVFsVqpYpBhhY9mbO1pOS4gDO6GsCJwMLaX5U7f+PcOEiZuZZujnAy+girDL1WsWQpFi+oB3matbrJNhhv/75ehMJJDcRBLzLtN+wiJpfwhQEvVI3OM+kHL8HZgM7aDpnQujjM7o8SZCXqtIve+1/aFT28P8WUG2untTzUsE/0ku+/EjsPgXiWpRCrZu/EttXGeGfVlFWbPyYHRQBgWZUb3P7m//1Y0L6h1C4DGj2C+IvqQ7fJqWyJDK0LOX8GwKtTQK+0wZ1IjqSrpARuagZceZFqDWK54FlE1kjPVGck7UsLq7Jh7sYb7gVQtUBL+t9dQestvGunbuZ9Q1zno8fozzEh4R0uYoZbsppR3dg63YqTCzHZExdg+kXAFIiSz 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)(396003)(376002)(346002)(366004)(39860400002)(136003)(451199018)(186003)(2906002)(6512007)(5660300002)(38100700002)(26005)(6506007)(8936002)(4326008)(6486002)(41300700001)(86362001)(2616005)(8676002)(66946007)(66556008)(66476007)(6666004)(110136005)(36756003)(54906003)(83380400001)(316002)(478600001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XCmS8W1fxBmaoLpDSe7bo0CLiNkUsHTMpmURlpd4OuJEMPqvPlwok0reGfxXrXKFJSLRWtdEalP1qC0SWox/YpQNPJwHeyojdQ6Yju1gfLisW9eTfgZcQMan9QR65+odGfjny77FxcVgx9iH+zpu2lMZ0jySprw3p3HcIqRxK+xVJmnU841fKFklsH1XvfP/ZLzsoPalMdUsrB8puLk/py20UIV/TC1D7eHJUGLQJ8oCOK1vf9xnLw4lIuu1ovJSgA4jzTEsx/JDodaihq9LnIZlz4UPha2w2BDB+SLo1FA0u9Kn5YAvfxNLJ3ws5TD1zaT9c8EMp8o/OjzhtzWLhufczIqQchXRZrPf9mpLzOD5dygU2u2LCFJRgq9neUpZdV93NuZ3CWsn2L1p0lmDV4IgbfJnPANKH7KJhhAua3HKtc5vRVnBr/zLC9u0W27GSN+mdykI3o5IZTekzDSHG0gs5kIkiS5PoUq9Xyc9EaEKAEcEbWSWcFLy104emHkVC5YQaj6C822YPDsKRoEYjcVRlvvdyFrNmx3rmKiRZy7iWT3Fy4Z5U0eiUAPU12ZD0g/OocjiRIrUPJ10x1fbAf6eal1QP1zVpb3/2ea2tuuvdi/QygeyAXrBroiyXeSTwTeP3pK2YL9cZjL7N3oOjq+JL2eyK80RBUhMd6tlNldyq6RfwOdqc9cjL6w/XQIO+/MmZxEZBBXzOm0sQJC57GpO8CKLfDbl8dAKgdWOq/t29sp1fsbftae+6UDuN2C7WZjUFwLs2+vyRwRtYgZkzf1U6Hp48b04b1gXWbqsy6Lg4BFU08XWyTigHRvFcLDwM18Svw5mhVZN2okb3T6YKXAfEo7ar2fHKBpW24c8cqzEtaTl7mHHz8wuINw7MHcI4A63LdAzZ5/rzHYiVXJrxNarzzX1Je09qHQK21/gKwmraJ7c3U8EWCNpEqYQRW3Q8lNUjxabUpJAHHJjD4UJAHp/2+SbH7Bgwdm8lhXKLQHNRTieiH8Nyt2EmIOQ6r5Le7htr5qL5xoTO7ZXb4U14zxKL2XIzsg9hzV0eETN6kArO7tFTp6t0YzVG8OYYNpgcpKIIsME3Bd6l3O23hYRf5xroIRKfwrRZGx3Q8CqAn6j/bZyqKhNtFtE6xSAcQ9hzzIDh+fbmTEPNFb/CstFPrRY5xi4IOOFHeueb61fkKZdf9lO7N0H93pib88ZfvlOhYNSyuAnLL8E+FChNJ5a5hQX8tHv2HUllXLhGfIwMRhpgWEYdrKZv2tI8TcrS8XYko/dJ8MAFCzGz/obTsp4DCctXL0F+8ZHkWaNvf1ZqNGjA/y4VEa9f0P+XC/rRCnzntCf+I836K/uJJ4c3AYjJjFNFX/g9x8lAkKrnAdIV/vC63p849wz9kqsDFDRxd7UUGW9nQR+bq8C4tOJJMxvlIXaZ4TVmrAdaN3Nv61ywLnQc3Rud2o0/Cq94MpUbPWvv1QHcHOGrSgGATv4R2NFhKZrAZC/zQ1KZt4MbWxyDNqkbgL0be8AXYKObyNYBmX/eWkgQwieDymBpHiUYX9RaZVwv7F5ZBWqg+b2NLjFsTN0/6zl02xgPLO1MJKzgypB X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 98872ac8-7b3b-4cb2-4b00-08db1a8b6bad X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2023 19:30:31.4383 (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: J5Lhybnbi63/Lb9FFMckxusPTRtdMGb4XV55+DfhkzA1rTfTQMBudvkPo+ShGyuK X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8086 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org The HWPT is always linked to an IOAS and once a HWPT exists its domain should be fully mapped. This ended up being split up into device.c during a two phase creation that was a bit confusing. Move the iopt_table_add_domain() into iommufd_hw_pagetable_alloc() by having it call back to device.c to complete the domain attach in the required order. Calling iommufd_hw_pagetable_alloc() with immediate_attach = false will work on most drivers, but notably the SMMU drivers will fail because they can't decide what kind of domain to create until they are attached. This will be fixed when the domain_alloc function can take in a struct device. Reviewed-by: Kevin Tian Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommufd/device.c | 87 +++++++++++-------------- drivers/iommu/iommufd/hw_pagetable.c | 45 +++++++++++-- drivers/iommu/iommufd/iommufd_private.h | 6 +- 3 files changed, 85 insertions(+), 53 deletions(-) diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index 4483c06e0ec38b..8dc7ed678e3fbb 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -177,13 +177,16 @@ static bool iommufd_hw_pagetable_has_group(struct iommufd_hw_pagetable *hwpt, return false; } -static int iommufd_device_do_attach(struct iommufd_device *idev, - struct iommufd_hw_pagetable *hwpt) +int iommufd_hw_pagetable_attach(struct iommufd_hw_pagetable *hwpt, + struct iommufd_device *idev) { phys_addr_t sw_msi_start = PHYS_ADDR_MAX; int rc; - mutex_lock(&hwpt->devices_lock); + lockdep_assert_held(&hwpt->devices_lock); + + if (WARN_ON(idev->hwpt)) + return -EINVAL; /* * Try to upgrade the domain we have, it is an iommu driver bug to @@ -198,19 +201,18 @@ static int iommufd_device_do_attach(struct iommufd_device *idev, hwpt->domain); if (!hwpt->enforce_cache_coherency) { WARN_ON(list_empty(&hwpt->devices)); - rc = -EINVAL; - goto out_unlock; + return -EINVAL; } } rc = iopt_table_enforce_group_resv_regions(&hwpt->ioas->iopt, idev->dev, idev->group, &sw_msi_start); if (rc) - goto out_unlock; + return rc; rc = iommufd_device_setup_msi(idev, hwpt, sw_msi_start); if (rc) - goto out_iova; + goto err_unresv; /* * FIXME: Hack around missing a device-centric iommu api, only attach to @@ -219,27 +221,35 @@ static int iommufd_device_do_attach(struct iommufd_device *idev, if (!iommufd_hw_pagetable_has_group(hwpt, idev->group)) { rc = iommu_attach_group(hwpt->domain, idev->group); if (rc) - goto out_iova; - - if (list_empty(&hwpt->devices)) { - rc = iopt_table_add_domain(&hwpt->ioas->iopt, - hwpt->domain); - if (rc) - goto out_detach; - list_add_tail(&hwpt->hwpt_item, &hwpt->ioas->hwpt_list); - } + goto err_unresv; } + return 0; +err_unresv: + iopt_remove_reserved_iova(&hwpt->ioas->iopt, idev->dev); + return rc; +} + +void iommufd_hw_pagetable_detach(struct iommufd_hw_pagetable *hwpt, + struct iommufd_device *idev) +{ + if (!iommufd_hw_pagetable_has_group(hwpt, idev->group)) + iommu_detach_group(hwpt->domain, idev->group); + iopt_remove_reserved_iova(&hwpt->ioas->iopt, idev->dev); +} + +static int iommufd_device_do_attach(struct iommufd_device *idev, + struct iommufd_hw_pagetable *hwpt) +{ + int rc; + + mutex_lock(&hwpt->devices_lock); + rc = iommufd_hw_pagetable_attach(hwpt, idev); + if (rc) + goto out_unlock; idev->hwpt = hwpt; refcount_inc(&hwpt->obj.users); list_add(&idev->devices_item, &hwpt->devices); - mutex_unlock(&hwpt->devices_lock); - return 0; - -out_detach: - iommu_detach_group(hwpt->domain, idev->group); -out_iova: - iopt_remove_reserved_iova(&hwpt->ioas->iopt, idev->dev); out_unlock: mutex_unlock(&hwpt->devices_lock); return rc; @@ -281,23 +291,16 @@ static int iommufd_device_auto_get_domain(struct iommufd_device *idev, goto out_unlock; } - hwpt = iommufd_hw_pagetable_alloc(idev->ictx, ioas, idev->dev); + hwpt = iommufd_hw_pagetable_alloc(idev->ictx, ioas, idev, true); if (IS_ERR(hwpt)) { rc = PTR_ERR(hwpt); goto out_unlock; } hwpt->auto_domain = true; - rc = iommufd_device_do_attach(idev, hwpt); - if (rc) - goto out_abort; - mutex_unlock(&ioas->mutex); iommufd_object_finalize(idev->ictx, &hwpt->obj); return 0; - -out_abort: - iommufd_object_abort_and_destroy(idev->ictx, &hwpt->obj); out_unlock: mutex_unlock(&ioas->mutex); return rc; @@ -371,10 +374,8 @@ void iommufd_device_detach(struct iommufd_device *idev) mutex_lock(&hwpt->devices_lock); list_del(&idev->devices_item); - if (!iommufd_hw_pagetable_has_group(hwpt, idev->group)) - iommu_detach_group(hwpt->domain, idev->group); - iopt_remove_reserved_iova(&hwpt->ioas->iopt, idev->dev); idev->hwpt = NULL; + iommufd_hw_pagetable_detach(hwpt, idev); mutex_unlock(&hwpt->devices_lock); if (hwpt->auto_domain) @@ -716,28 +717,18 @@ iommufd_device_selftest_attach(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, struct device *mock_dev) { + struct iommufd_device tmp_idev = { .dev = mock_dev }; struct iommufd_hw_pagetable *hwpt; - int rc; - - hwpt = iommufd_hw_pagetable_alloc(ictx, ioas, mock_dev); - if (IS_ERR(hwpt)) - return hwpt; - - rc = iopt_table_add_domain(&hwpt->ioas->iopt, hwpt->domain); - if (rc) - goto out_hwpt; mutex_lock(&ioas->mutex); - list_add_tail(&hwpt->hwpt_item, &hwpt->ioas->hwpt_list); + hwpt = iommufd_hw_pagetable_alloc(ictx, ioas, &tmp_idev, false); mutex_unlock(&ioas->mutex); + if (IS_ERR(hwpt)) + return hwpt; refcount_inc(&hwpt->obj.users); iommufd_object_finalize(ictx, &hwpt->obj); return hwpt; - -out_hwpt: - iommufd_object_abort_and_destroy(ictx, &hwpt->obj); - return ERR_PTR(rc); } void iommufd_device_selftest_detach(struct iommufd_ctx *ictx, diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/hw_pagetable.c index 10db1359c067c1..6cdb6749d359f3 100644 --- a/drivers/iommu/iommufd/hw_pagetable.c +++ b/drivers/iommu/iommufd/hw_pagetable.c @@ -32,17 +32,22 @@ void iommufd_hw_pagetable_destroy(struct iommufd_object *obj) * iommufd_hw_pagetable_alloc() - Get an iommu_domain for a device * @ictx: iommufd context * @ioas: IOAS to associate the domain with - * @dev: Device to get an iommu_domain for + * @idev: Device to get an iommu_domain for + * @immediate_attach: True if idev should be attached to the hwpt * - * Allocate a new iommu_domain and return it as a hw_pagetable. + * Allocate a new iommu_domain and return it as a hw_pagetable. The HWPT + * will be linked to the given ioas and upon return the underlying iommu_domain + * is fully popoulated. */ struct iommufd_hw_pagetable * iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, - struct device *dev) + struct iommufd_device *idev, bool immediate_attach) { struct iommufd_hw_pagetable *hwpt; int rc; + lockdep_assert_held(&ioas->mutex); + hwpt = iommufd_object_alloc(ictx, hwpt, IOMMUFD_OBJ_HW_PAGETABLE); if (IS_ERR(hwpt)) return hwpt; @@ -54,14 +59,46 @@ iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, refcount_inc(&ioas->obj.users); hwpt->ioas = ioas; - hwpt->domain = iommu_domain_alloc(dev->bus); + hwpt->domain = iommu_domain_alloc(idev->dev->bus); if (!hwpt->domain) { rc = -ENOMEM; goto out_abort; } + mutex_lock(&hwpt->devices_lock); + + /* + * immediate_attach exists only to accommodate iommu drivers that cannot + * directly allocate a domain. These drivers do not finish creating the + * domain until attach is completed. Thus we must have this call + * sequence. Once those drivers are fixed this should be removed. + */ + if (immediate_attach) { + rc = iommufd_hw_pagetable_attach(hwpt, idev); + if (rc) + goto out_unlock; + } + + rc = iopt_table_add_domain(&hwpt->ioas->iopt, hwpt->domain); + if (rc) + goto out_detach; + list_add_tail(&hwpt->hwpt_item, &hwpt->ioas->hwpt_list); + + if (immediate_attach) { + /* See iommufd_device_do_attach() */ + refcount_inc(&hwpt->obj.users); + idev->hwpt = hwpt; + list_add(&idev->devices_item, &hwpt->devices); + } + + mutex_unlock(&hwpt->devices_lock); return hwpt; +out_detach: + if (immediate_attach) + iommufd_hw_pagetable_detach(hwpt, idev); +out_unlock: + mutex_unlock(&hwpt->devices_lock); out_abort: iommufd_object_abort_and_destroy(ictx, &hwpt->obj); return ERR_PTR(rc); diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index 84fe19a195466b..331664e917b771 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -255,7 +255,11 @@ struct iommufd_hw_pagetable { struct iommufd_hw_pagetable * iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, - struct device *dev); + struct iommufd_device *idev, bool immediate_attach); +int iommufd_hw_pagetable_attach(struct iommufd_hw_pagetable *hwpt, + struct iommufd_device *idev); +void iommufd_hw_pagetable_detach(struct iommufd_hw_pagetable *hwpt, + struct iommufd_device *idev); void iommufd_hw_pagetable_destroy(struct iommufd_object *obj); /* From patchwork Wed Mar 1 19:30:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13156355 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 89391C7EE33 for ; Wed, 1 Mar 2023 19:30:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229693AbjCATam (ORCPT ); Wed, 1 Mar 2023 14:30:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229617AbjCATak (ORCPT ); Wed, 1 Mar 2023 14:30:40 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2075.outbound.protection.outlook.com [40.107.93.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AD6B392A9 for ; Wed, 1 Mar 2023 11:30:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XLs++cBeUCHOL1Gx5GLPJR6r+F56B5tbsoG2xP2nMI5O36So3l1EJqADAgaAaFf4xUMiKJrO6zeJCeRL/vybrMYELcfwWNMUwdOvLd3YvLiTAPu+q03Y0uNnm3bKooUByiI8Qv0OkJyxEhjVWUGuIbn/ddwt/WO7ZbGs+Qit8J/4SbZcMDS26HNNBglqPn8+I1/j0fXtLNNhK/gHdJBNQ3QXjM01gfNhMadbF6xDJlZbJ6ttsu81GPAfN4p+EEa4Q1Q6WI5d9nwEsE2iMLu6/fzkgCBArDx0wuIL8Y+0vRmUI3GuwM0fQbZUviLEg5nW3abGz5daXls6+nYaJHj52Q== 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=g1jfip3kaiixxARPeTAyk/c8f+gtmtxu46u/o2DHSVo=; b=C70ESpW3uxGwLxrKonb3ASDzwFSSo4qRMCOGesK+qE24zqbjJwt9vgxDCRNDq9siLZzxCTkig9VXMpR8jTkF4JmzwLLYdNGg8/D+MfuKSLabrTyy0r7xUa8nxXT2F7LdwaWlQFuzfLc956/ZgzUVY/Bdi7gV584jFvV2Hbx5p0xLcC1oMxcE88dewF6cpdpgTssDuhb5yQh2CkL3c3NMlm0JXfVxeb1a+AfrbchJiTPe3TNd99tNcFk+L6OUs7gmkS3uwhzWU68OT3M9C43iVb9dt333fFcZnjoUzxr0rj389phH3kf7qwLaI3hSbCA4BnkcbpuMdmFq8L9bQx+Yvw== 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=g1jfip3kaiixxARPeTAyk/c8f+gtmtxu46u/o2DHSVo=; b=p71XntdbS1uuHvUjxndkQiUTLbMYgDHyK0qx+SEKa5VEIMoEIWcPaL1uzjSm/jWnYKI4Z9EM5Aq9wAGfn0ycvklFKfga4Aqd+TTZoNJX9TnDvZaB54BvEQfMSrtVYpKFN4XZFIbSZuwwTLZVIVwaD8w9JKciCRFrGXAUqYbhtQR1KG4587FzNwdMgIn1IwI0I2WEjepk4laJ4lkU0tZzrwCZby9ttdQcdnfJ0krCcWI7nlhlCr6lm1/uTce6Zn29kVLGkZxP3X+FX4RaOQOZlgmpVG/IQUmDplBRdyUDfqa+j6H+h+JXpBOZSLcnVq6QlKGtNAz1xSMb3t7A4mi4Pw== 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 IA0PR12MB8086.namprd12.prod.outlook.com (2603:10b6:208:403::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.30; Wed, 1 Mar 2023 19:30:35 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3cb3:2fce:5c8f:82ee]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3cb3:2fce:5c8f:82ee%4]) with mapi id 15.20.6134.029; Wed, 1 Mar 2023 19:30:34 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Kevin Tian , linux-kselftest@vger.kernel.org, Shuah Khan Cc: Nicolin Chen , Yi Liu Subject: [PATCH v3 07/12] iommufd/selftest: Rename the sefltest 'device_id' to 'stdev_id' Date: Wed, 1 Mar 2023 15:30:24 -0400 Message-Id: <7-v3-ae9c2975a131+2e1e8-iommufd_hwpt_jgg@nvidia.com> In-Reply-To: <0-v3-ae9c2975a131+2e1e8-iommufd_hwpt_jgg@nvidia.com> References: X-ClientProxiedBy: YT1PR01CA0111.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2c::20) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA0PR12MB8086:EE_ X-MS-Office365-Filtering-Correlation-Id: 1363db98-8652-4505-c2c8-08db1a8b6c6e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iyVY6uCF77WBh1Utl7jbygFIZ+UiXj5L0MhRB5gKbKe2qmEo9yAOatiqdkOqQj+XBNhZru9vpiMr/prBAaanuOS371l4K8PdJndAK3+xn4sP6GNQ5Ey8EAlPpdfW8OZQRf4tP46tHCurDuRdmXK0JL5alKADnyiAqj1XAusjt8IZxi7ksAewAj1G7QtE2iO5OTtQRWWBCTVWIsCch2t7oxJnQ52zkoGu6zGktnowU+o+oE66KxgxH3f4lfl5hvA3f2GZTztF8MrFjtc2hXYBe3anTGYarSffdt/C5u9NPSZJrV/GKRy7f1dLGmL48CqKVMDvVNw/hMbAw5d/KfVw7iAQT+UIxu5YScxlY1PehCRc8GMBUqZ2qq9a4u++xr3uEmWgwUGsw0uC3QZR/O9EL7OSa2uppo3+9X0CjBoRo3zTOnCL47PGpZdLLpjgA/P86JpX0sRCCD+r2qtnhaN8OyZsuOJi2Xqf8Jg6qDG5H2tGl+RfeyvIPmy6xYDqYfQExEGMqB3+y1MsAtPOudP9sn2fpqrUfL23FZMc60z/8QD/n6kSrJyIKfFMM3lvkw+eyBVkFfWrm1P1VDZtFXKFI52fpmUR+c34nuhOAbmPB8Ayyz5ymypolb7IBZaSndQqOCHgL7cTfu3syeNhmHtVwUlCDAqEClO+LwkynLR+DnbNLI0uwl1ZCxXsgku3oFSv 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)(396003)(376002)(346002)(366004)(39860400002)(136003)(451199018)(186003)(2906002)(6512007)(5660300002)(38100700002)(26005)(6506007)(8936002)(4326008)(6486002)(41300700001)(86362001)(2616005)(8676002)(66946007)(66556008)(66476007)(6666004)(110136005)(36756003)(54906003)(83380400001)(316002)(478600001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: U6NV4aa73ISNaCAz74HT8/BcWLUC9vWt3JflYhMIynk+cAkM3XRNFxa2gMtR3CXsD6D1ICv/Whc37yAfpXLxySiJ04v7Ni8vdBXRfpvIa+i7l3xdXa0bq9eAXiHG57ic6FIGwZLPBaGWgQHbG3rgjmtqdCsrf7L0piDSJ6ET9OSc1IUxQgvIHyuemiptrKxcJ44wif2zzYksJBciECzx4jQzXP8IvT3sbrgz3Ekb+LJGerhb41uUuTjuQWklB+abT4E+QlbXADzz8Rr+QVzUP4rAT0AEJZvJPBEM46raPwkqpoa1nupm8P817d7Rf4WmFUmLlcPrOSEhHDfO7sYWQsoGNn9/Y5j40pZsEhcp3JnO04blInpXPniqyk5zzhVoAXQHyCyqZQInsjvqbv5kh3HGT6M8i+WM1UhfrSLrHOmMg+z3cAIY1J7MnlZNtUNi/SqPQMsEROHS9c78tnlmp6KXGk4HgjL/pVWQLiU9UKxPc56oXW/q3h00219fyHpZDdhDAZ7n9wiSrM1XoR6vkpIBOFMGxgDjVScuCD396jljF8TyoVpUns65L8t0jOiSlj2Fl2Nwt7fJGrdu21CEVnDvUTC6qMRL1dH4VawOHI0ruzqHVMM69/LxQ82OiyL6U6P+kQWTbLDe7KTARCZySDruF/HcaKgZwQFCcCO2s4QoxURiwXpzIHspj93Q6fLoHpjpYPgXPV8s/75iRPYWrEmbqHqybYW1io29/6DxYdjT3TMKCLOJUZQV9c5dZ796or+fG/bbw//oVcN+iyFsq6u28i1Tyc9jynr3FROqKzGiYuMELPCGbqYHtVSErb4bZRPFQJbO4ZIKDPWFzjq4esonOYy+v+lm4nA+NolX2DWsdL7nV6MjC0OZSd5+JJQ9B8onLU6InAFXQNsTfX+4yfFFo8z7KOYe4yk2AZe6u1Qw0eKjph9lCmTTNrJASTJSBItG0/LmwDOL8oeER5DdnAG/ErTmU5JGr09aBcpItVvN4fDsyUYbm4oinctLZs6FrF/+WQasNIZwrGQb4ncaVeS/nTBqhUStLsQDZXTOGv1IQt87nnjtgn7WE3Q/cusbZMNiUYSPUU0twOBvZsl7hthmclHt2N7OoExVYLruPrLhhliICzce+fncBqk4Fgyex9vtLwg2psChorkrnApXJCMk7RKVb/tF2Y1IyRWXHkYe92QpjLwk6AdoeLTmo+nJ1jvNRPzBhDLYkB9E5gLP5zLl0l+JbGESDYvidGCBYiaFABgfJzwTfiVEkTf+3P8dASVG8T0Y01U1rXcl/VMnxceTsQiVGbmpf4Kj+KfKXxSpfOPH+Sd7PK+RzswPU8XFxaa4dx3biuDbWUZfkCQdlG0vopLJNPNdhwhjsgB61YnvI6k55Fs3kX/XJBtNOpEyL83prvPIIjUbtvACdA5xp8jl4PLvA+mLibBc/Um6UHRO/CPOfouAqDTyWSQmwgUglNi4a7q5hY+ioBICMPyo7lwJZK7+dpXb6wcyUyN6aPT/1D6MO08HTXOT2Eq2gjIYIZzpZxMgYl82vYLqGA9Yqs6GDe71yjh3h2NclLPDqaoD6+m77NBi/b0bVsl2UtJV X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1363db98-8652-4505-c2c8-08db1a8b6c6e X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2023 19:30:32.6125 (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: x4AZjioGOHbWmYxOqSpXMCvZFjbjcK4UiAiqSIsXtyPDoSnGoq7jHjitusmGa2Ij X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8086 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org It is too confusing now that we have the 'dev_id' as part of the main interface. Make it clear this is the special selftest device object. This object is analogous to the VFIO device FD. Signed-off-by: Jason Gunthorpe Reviewed-by: Kevin Tian --- drivers/iommu/iommufd/iommufd_test.h | 2 +- drivers/iommu/iommufd/selftest.c | 2 +- tools/testing/selftests/iommu/iommufd_utils.h | 16 ++++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/iommu/iommufd/iommufd_test.h b/drivers/iommu/iommufd/iommufd_test.h index 1d96a8f466fd29..b3d69cca77295c 100644 --- a/drivers/iommu/iommufd/iommufd_test.h +++ b/drivers/iommu/iommufd/iommufd_test.h @@ -49,7 +49,7 @@ struct iommu_test_cmd { __aligned_u64 length; } add_reserved; struct { - __u32 out_device_id; + __u32 out_stdev_id; __u32 out_hwpt_id; } mock_domain; struct { diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index cfb5fe9a5e0ee8..e05b41059630a7 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -302,7 +302,7 @@ static int iommufd_test_mock_domain(struct iommufd_ucmd *ucmd, /* Userspace must destroy both of these IDs to destroy the object */ cmd->mock_domain.out_hwpt_id = hwpt->obj.id; - cmd->mock_domain.out_device_id = sobj->obj.id; + cmd->mock_domain.out_stdev_id = sobj->obj.id; iommufd_object_finalize(ucmd->ictx, &sobj->obj); iommufd_put_object(&ioas->obj); return iommufd_ucmd_respond(ucmd, sizeof(*cmd)); diff --git a/tools/testing/selftests/iommu/iommufd_utils.h b/tools/testing/selftests/iommu/iommufd_utils.h index 0d1f46369c2a30..85d6662ef8e867 100644 --- a/tools/testing/selftests/iommu/iommufd_utils.h +++ b/tools/testing/selftests/iommu/iommufd_utils.h @@ -38,7 +38,7 @@ static unsigned long BUFFER_SIZE; &test_cmd)); \ }) -static int _test_cmd_mock_domain(int fd, unsigned int ioas_id, __u32 *device_id, +static int _test_cmd_mock_domain(int fd, unsigned int ioas_id, __u32 *stdev_id, __u32 *hwpt_id) { struct iommu_test_cmd cmd = { @@ -52,19 +52,19 @@ static int _test_cmd_mock_domain(int fd, unsigned int ioas_id, __u32 *device_id, ret = ioctl(fd, IOMMU_TEST_CMD, &cmd); if (ret) return ret; - if (device_id) - *device_id = cmd.mock_domain.out_device_id; + if (stdev_id) + *stdev_id = cmd.mock_domain.out_stdev_id; assert(cmd.id != 0); if (hwpt_id) *hwpt_id = cmd.mock_domain.out_hwpt_id; return 0; } -#define test_cmd_mock_domain(ioas_id, device_id, hwpt_id) \ - ASSERT_EQ(0, _test_cmd_mock_domain(self->fd, ioas_id, device_id, \ - hwpt_id)) -#define test_err_mock_domain(_errno, ioas_id, device_id, hwpt_id) \ +#define test_cmd_mock_domain(ioas_id, stdev_id, hwpt_id) \ + ASSERT_EQ(0, \ + _test_cmd_mock_domain(self->fd, ioas_id, stdev_id, hwpt_id)) +#define test_err_mock_domain(_errno, ioas_id, stdev_id, hwpt_id) \ EXPECT_ERRNO(_errno, _test_cmd_mock_domain(self->fd, ioas_id, \ - device_id, hwpt_id)) + stdev_id, hwpt_id)) static int _test_cmd_create_access(int fd, unsigned int ioas_id, __u32 *access_id, unsigned int flags) From patchwork Wed Mar 1 19:30:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13156358 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 5ED93C7EE43 for ; Wed, 1 Mar 2023 19:30:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229689AbjCATak (ORCPT ); Wed, 1 Mar 2023 14:30:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229533AbjCATaj (ORCPT ); Wed, 1 Mar 2023 14:30:39 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2075.outbound.protection.outlook.com [40.107.93.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D8A05FCC for ; Wed, 1 Mar 2023 11:30:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HA4iVdcvnp4vpQ0dduoN2UsKpVubBxeR9QZVCYEqepKV5tpnpWXyHl640sbvc0h52RKMDePj8kMiBM6uP1uS78U9uwAIzw253GkzQsl836PvR9eXBrKLctRbAIpX9qvw3npv8z8nCFS2VXMsWGBA+0gg9TSjaa+IOC6Gc4FSq8dL8vPmf7hu08PSXE8NPW7+YtC+Gt4VNGI24h4wJhxEn8ffC8NY7xSxBXdmLLUYwBxZWREdTOsPgMW3qir1HfIQCDaq/5srG9dWBBfh5q0SaEKUovqPUQBj52PRB0vcy95A+liUlcAmnCXPUQtqDEWJczwMNusVIT7hJUAegzmlFw== 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=p2dMUdHgo5mRr5g/vACCk/f/a9jXivTNVGtvSI0QC2w=; b=hoRkgyKwrNqM1dttQYD43qqdPw6On3/+YWddHUei4/A2yyQF+XGwA0biBouxKaR452zC6zYEBkaRBMNOPWaJkfq+tD1fzeWafYvPleWdUuKjD79RwLFDfurw14jt8Oq0FwkawBgJftH2oTmj1y8XgVJPSo5VRzm/fR9Cy1Ip4HFf5RSX1eV6+q8jZxUevTCKbRI3O6zLz6hr5H4UqFkhHBjw/pKzPOkbusaDWsgt8xKxL1OnES52ew2iwHO4J+gDSX3yz2r+E6xpSlPAj0cuCj/AMoBQ4U+WVQBhOWcNpM6UTbJ6rqBs/weAcpb8fVcd7xNAuymHhe0Jyr1nkZcUSA== 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=p2dMUdHgo5mRr5g/vACCk/f/a9jXivTNVGtvSI0QC2w=; b=pKiyXa+6Zat689wefn/Qx35R3/D0rCq2isaU/VECuOQsWQUrx8QOWH2/CNVLaDor6uB+fZZvGXnz6TDidF+q+OZnEH3mAo9iYxpUAlsCJh00er01HRYjc8SLY/tq+WAcwnxH7+/ncOGuc/9XzSNy127Pt7/5ZdMF6ZaZlMren0wLzZXlgOgLG8oWn467v2ZClqRbxxOOT5frwF2uxfUySyv9nq2ncB/tLYVScPl32woKPTEWhi6UGKvKQBKjIWBP/BjB9ixchGy3cEqSsjqvkUAFbiJYmjmtAw0wDQ4Xe+oncu8tGVXnxVedUY9I2GnSXz7KKU0f1vvd9vbMNSDvFw== 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 IA0PR12MB8086.namprd12.prod.outlook.com (2603:10b6:208:403::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.30; Wed, 1 Mar 2023 19:30:34 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3cb3:2fce:5c8f:82ee]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3cb3:2fce:5c8f:82ee%4]) with mapi id 15.20.6134.029; Wed, 1 Mar 2023 19:30:34 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Kevin Tian , linux-kselftest@vger.kernel.org, Shuah Khan Cc: Nicolin Chen , Yi Liu Subject: [PATCH v3 08/12] iommufd/selftest: Rename domain_id to stdev_id for FIXTURE iommufd_ioas Date: Wed, 1 Mar 2023 15:30:25 -0400 Message-Id: <8-v3-ae9c2975a131+2e1e8-iommufd_hwpt_jgg@nvidia.com> In-Reply-To: <0-v3-ae9c2975a131+2e1e8-iommufd_hwpt_jgg@nvidia.com> References: X-ClientProxiedBy: YT4PR01CA0107.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:d7::16) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA0PR12MB8086:EE_ X-MS-Office365-Filtering-Correlation-Id: e0ce7b94-f9ce-4d43-3fc0-08db1a8b6c27 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sYY9Ekvct9ePtPQhEDfxz5F4hZ+sE8CYxR8EehmSuR9nDv23apRPA4UZudec5zi20el4cbr3RNxyqkz21cQz8xUloEKgODsG2CxlcCznVtFpVwP/p2O+PU7xe8hy4CPnd3KGzMg89MCGPtG/5GkMS/79mbAoevvfDtpLfTIFgvT+b+eSEForF0E9UfM26NVEEoX4zfo6qppPxckkgy5tWKu+NDuqiEUb30lpMTKC26FqFf+mEQ3MEq/qfUzw1sx+n3imyZt3F4NBhwO2Qf6+rPdkjU2mR8L5AyDp+9lU6XDHVLhAO8XcsCB/hepqooESQS4VgBp6pbzaPh8V7gkoxN0I/QiQHpugMdVllBCXEICj85RkMm6mNx/8giaefh4chepvSoB4xw/W4yNud3GjMRTAuiOo4kVV+9hA6zqTwPmIz700a9lhYgBOS+1zvBD27S1sh/cVCwq9lMZi0tIaUQM6yiVNHTRLRibI2df2eeKu0RPW8zxHp7qZ+pzhpzLupVeqLTljzIWi9isgG6NWyDcTCmqghCQaZ4Zhr/CqlAPcvzi12Qw9F7ApI0y46roOcstCMeUQ5lCtlO1BmF8f4wcsvDeVW6ZXzrR3iMnsIw9cBxe6EtXDBNcWb1YsU2E6x862wCmX0fvNIMnzPidWmYsAYBs7wsM6+9Y/BMr6rBjJfFbcs0u6jFrh2o+1yvSW 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)(396003)(376002)(346002)(366004)(39860400002)(136003)(451199018)(186003)(2906002)(6512007)(5660300002)(38100700002)(26005)(6506007)(8936002)(4326008)(6486002)(41300700001)(86362001)(2616005)(8676002)(66946007)(66556008)(66476007)(6666004)(110136005)(36756003)(54906003)(83380400001)(316002)(478600001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4hyl+d/Q274tQCSfbi0SQGgPt5eVJK0zkaDsMUrKxp5jd2CbpANsvfKrY1gc1/82BCQe66TF8Bsy6DIgMNqPlVMecrWseF7ndJDIbXbN+N2hwbysr0M3A+fgNVq2kbbkFHVHlGry4kV9rnWS+HjcwRghImsLqRQq+DaUZoOxu3mFORESovaV7SRm3FP/jMJx6bZnFxLYcVrDXZMUo4t59SUCe5sMRO20VzeR0mefd40vquu+h6G/T7eY18QO+NRCHxW5X7aRpTvC/vH3ka5zZTgikbHx7mHUbEjn2/CIK2gC+dgYuMxvkoqyrTvnm4Tlznh7YkVAuyxDvE8KpNwmhUCeSdSm857Lhd0Oc3PqhePFNzU8LrOISlTOL1knx9FeqIfHBWz38l/cJl8r/tVY7hfuhgxnX/Z/1eXeeOHrJ+XnXIsQkqM6492kooXzIupFwAlleZeKQ0YAjF3ngYuq05sQHRHf+1FfBcDDg9PqZHMJ/aYdiBEoK8vCOdGivxgvYtVTgNyW8jRnz/Z+Ol9l5UJ7/eCFiEYHpEs43Gd+GJ5TLd0Bem938FbhJ24V3jObr7SqG9+wI6LAyppu99kbOIIPlRqfjIuq2V8mj4HBgz8h1VgSpuaNgiK8NtkOv9dJwCOjWoGDWFexcH6ISO0OJvBTaG+FObFYlA8Zs7pk2fSIBBoZnwffUZK1h4etHYgpeDphH8wWKAEnuoINozoTlLPXMe0sPylwcWxbo7sR3hot87xT7UOYExPB6f6WfkOGwhZL6pUgnnRJZRM9y25YcKUt97V+sVyb1BXCWT5sUApWFOlZ6WU5ok3wGSuI+X7yF4Qn1zDPTVNNNz+aXGiU/mXNtQ9YPjvdp9Y+HRse8gqwfN1r6RlN2Z1p4IPk3AtTUHllCr980jy/j0Ri7bO+0QgnqiNhGErTle6/U1CBRvdR1V3VmW/3qHHXUByg+KJwhjHNrHzx3fOsU3wSFakTP+xZPBQqZUKcbmZCpg2E6ZiKxUlBU5xZRhh5Wwf4Ubx7ujMUBmzMeEJIb1LhuhlweYSkMd3mYvOhAuRQPLDgIM/UAknpBD2JPtLga8DuAQ97nz8RHwB7oInXpZQg66CmrZ3hrV/YoHb0pWER3PganT0Z3qfUX9iS3H0pcwHYf8UmdqGwOKN/+1/QItE9C91rlkqHC2HT+bur+x4sthNHJBG9EGfRcdhHIJ8NLvGayGzc4BxPDjhBaEfOxPTPFjb622o0YVm8eIBVpmXUcIiznnF7w2xpYQBLosRiWReuvHOGITPZ+DFelbvF01GHgz4TTOfcVFONroFdOu9xJoZtepWBwwV+mKoOXGzPEEkCc9f7umfHgh9jzNUqwyWr7ODVHinxYkCv6MVERKBmG+nYl5+skAJBocA0It+vbrhiXS0c60jkVJzoFjY3kE2zDXbnL4jT5IeYZ3TscfuOqrPaiUGAopEkUK5JsC6LE5sYpqQMazY1jm7+l1k9jSlhuu+TqVwEhFs0fsuvcITPWSaSjOE+Lq0LUhWTb1+9qXTZMB5NUWJckhpEHp4K75P3TsomnKQtKmmrXmulHsmz9h61PdUMLFvaqRYNe8IzkxUTY+tn X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e0ce7b94-f9ce-4d43-3fc0-08db1a8b6c27 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2023 19:30:32.1438 (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: jrpWZvNQftzOGzCEHZDqDqpDhgue2lB8J9LO63bjVXZGVl7YKlTA8Q5czZJtBLkl X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8086 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Nothing uses this for anything more than checking if a mock domain had been created. Rename it to stdev_id to match our naming system. Currently domain_id is the hwpt_id. Signed-off-by: Jason Gunthorpe Reviewed-by: Kevin Tian --- tools/testing/selftests/iommu/iommufd.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c index fa08209268c42f..000fadf8110833 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -186,7 +186,7 @@ FIXTURE(iommufd_ioas) { int fd; uint32_t ioas_id; - uint32_t domain_id; + uint32_t stdev_id; uint64_t base_iova; }; @@ -212,7 +212,7 @@ FIXTURE_SETUP(iommufd_ioas) } for (i = 0; i != variant->mock_domains; i++) { - test_cmd_mock_domain(self->ioas_id, NULL, &self->domain_id); + test_cmd_mock_domain(self->ioas_id, &self->stdev_id, NULL); self->base_iova = MOCK_APERTURE_START; } } @@ -249,7 +249,7 @@ TEST_F(iommufd_ioas, ioas_auto_destroy) TEST_F(iommufd_ioas, ioas_destroy) { - if (self->domain_id) { + if (self->stdev_id) { /* IOAS cannot be freed while a domain is on it */ EXPECT_ERRNO(EBUSY, _test_ioctl_destroy(self->fd, self->ioas_id)); @@ -263,7 +263,7 @@ TEST_F(iommufd_ioas, ioas_area_destroy) { /* Adding an area does not change ability to destroy */ test_ioctl_ioas_map_fixed(buffer, PAGE_SIZE, self->base_iova); - if (self->domain_id) + if (self->stdev_id) EXPECT_ERRNO(EBUSY, _test_ioctl_destroy(self->fd, self->ioas_id)); else @@ -382,7 +382,7 @@ TEST_F(iommufd_ioas, area_auto_iova) for (i = 0; i != 10; i++) { size_t length = PAGE_SIZE * (i + 1); - if (self->domain_id) { + if (self->stdev_id) { test_ioctl_ioas_map(buffer, length, &iovas[i]); } else { test_ioctl_ioas_map((void *)(1UL << 31), length, @@ -418,7 +418,7 @@ TEST_F(iommufd_ioas, area_auto_iova) ioctl(self->fd, IOMMU_IOAS_ALLOW_IOVAS, &allow_cmd)); /* Allocate from an allowed region */ - if (self->domain_id) { + if (self->stdev_id) { ranges[0].start = MOCK_APERTURE_START + PAGE_SIZE; ranges[0].last = MOCK_APERTURE_START + PAGE_SIZE * 600 - 1; } else { @@ -525,7 +525,7 @@ TEST_F(iommufd_ioas, iova_ranges) /* Range can be read */ ASSERT_EQ(0, ioctl(self->fd, IOMMU_IOAS_IOVA_RANGES, &ranges_cmd)); EXPECT_EQ(1, ranges_cmd.num_iovas); - if (!self->domain_id) { + if (!self->stdev_id) { EXPECT_EQ(0, ranges[0].start); EXPECT_EQ(SIZE_MAX, ranges[0].last); EXPECT_EQ(1, ranges_cmd.out_iova_alignment); @@ -550,7 +550,7 @@ TEST_F(iommufd_ioas, iova_ranges) &test_cmd)); ranges_cmd.num_iovas = BUFFER_SIZE / sizeof(*ranges); ASSERT_EQ(0, ioctl(self->fd, IOMMU_IOAS_IOVA_RANGES, &ranges_cmd)); - if (!self->domain_id) { + if (!self->stdev_id) { EXPECT_EQ(2, ranges_cmd.num_iovas); EXPECT_EQ(0, ranges[0].start); EXPECT_EQ(PAGE_SIZE - 1, ranges[0].last); @@ -565,7 +565,7 @@ TEST_F(iommufd_ioas, iova_ranges) /* Buffer too small */ memset(ranges, 0, BUFFER_SIZE); ranges_cmd.num_iovas = 1; - if (!self->domain_id) { + if (!self->stdev_id) { EXPECT_ERRNO(EMSGSIZE, ioctl(self->fd, IOMMU_IOAS_IOVA_RANGES, &ranges_cmd)); EXPECT_EQ(2, ranges_cmd.num_iovas); @@ -789,7 +789,7 @@ TEST_F(iommufd_ioas, fork_gone) ASSERT_NE(-1, child); ASSERT_EQ(child, waitpid(child, NULL, 0)); - if (self->domain_id) { + if (self->stdev_id) { /* * If a domain already existed then everything was pinned within * the fork, so this copies from one domain to another. From patchwork Wed Mar 1 19:30:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13156354 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 4A9A2C7EE39 for ; Wed, 1 Mar 2023 19:30:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229615AbjCATai (ORCPT ); Wed, 1 Mar 2023 14:30:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229561AbjCATah (ORCPT ); Wed, 1 Mar 2023 14:30:37 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2062.outbound.protection.outlook.com [40.107.93.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 854D95FCC for ; Wed, 1 Mar 2023 11:30:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D/O2dxrMTVJ3lrGgTLcBYZMCwunvefWPg6kvN+cQQ/p2Unwuv8ltl/dM135BFuVQYa821s6W+iFqkqFwmgM41EnwfH6Z3Neht+tthQE7zLUdpDXQ5CEBq4vUa6kEeghhUmbrfTGsBfdK6LHRkoL5x9zJe73W4QJicIYTtzkKzhkbyDonDp8ZWkSif+kHhf3DdWJhY6rCjzniHoVb/FyNzu4h3+rMppDupFAm5SnPMQAWNq6RbX5JubaAdhGfVNSwPaFBspW0ZRhSL7bxRsyoOGZ5xDYDWOya/NJGArdlGUqZUVrz/SKYWhZLzHs2sOWaQ51VvKu2X7mrts3oaqsPEQ== 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=wn5X/PSKoS7df8S2eEJYAT732Xmw580UmfHwDMGBDM4=; b=BxheienQW0bb3/lRGd0NuN3BWlVNhH18v5s7WRY+57kjEYvERGVv2N4Ny7/z9Jea06KB4SsO1IBH61YGCWdIYXFAvrQ0uDxy6/CayLs+aBV5z1D4V29sTO27vSs+ORFplV3ZawgVNe8T+JDea4a9uZ5GxTY35BaoiRR+1SwwKkH2+uEry+ylFwgA1qiesl8eq9f2aEKW6xpsfnKggBElwGNqzF/ah3545IpvTCSuNOfQd/xCOPb5fRLU9PP4GtoTaFPYzouYxYLT0CxA2/8OGoUDbJtKUd9PFwGYFVwNYmqWmXOlFW305yEuS6eyD+LbcIMlFhtwO3CtBv2hZGZoqA== 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=wn5X/PSKoS7df8S2eEJYAT732Xmw580UmfHwDMGBDM4=; b=nK72OWahDcVPVvznqsniV5ovy2M0Vg6OPFteyRSp3QpWeOo9dtN104rzbQLq0UtgzA5XflanueRU5X/r05NkYbfzFutTjueKrUjzUlRvS8NyaF9+kNoJkDvB4tRPRS3zzYLiM96go3HuGCcJo+cmx0f+icUR6ONxn5CokUuRGHdL/WTCSvcHM90+hwocb/aKQHdkuUVhz9Eh4yh4NpncpeYJ9blboTTqor32oA76nR1BpPBYKLfpkMYCdSELvY11TbfbfZOo5QxyYj3GJN1GRx6TEyFlSoXY6Ztej2deN4PcaExlXYIHKag4/zfDKX+zr4vLHVtsgg1BJB6Qg6Zt0A== 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 IA0PR12MB8086.namprd12.prod.outlook.com (2603:10b6:208:403::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.30; Wed, 1 Mar 2023 19:30:33 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3cb3:2fce:5c8f:82ee]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3cb3:2fce:5c8f:82ee%4]) with mapi id 15.20.6134.029; Wed, 1 Mar 2023 19:30:33 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Kevin Tian , linux-kselftest@vger.kernel.org, Shuah Khan Cc: Nicolin Chen , Yi Liu Subject: [PATCH v3 09/12] iommufd/selftest: Rename domain_id to hwpt_id for FIXTURE iommufd_mock_domain Date: Wed, 1 Mar 2023 15:30:26 -0400 Message-Id: <9-v3-ae9c2975a131+2e1e8-iommufd_hwpt_jgg@nvidia.com> In-Reply-To: <0-v3-ae9c2975a131+2e1e8-iommufd_hwpt_jgg@nvidia.com> References: X-ClientProxiedBy: YT1PR01CA0153.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2f::32) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA0PR12MB8086:EE_ X-MS-Office365-Filtering-Correlation-Id: 50fc81a9-3d89-4b4e-71a6-08db1a8b6bb4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IrfIKBBcki+o+bILCtSLZ0Fud7ww/uoPvIygk/8XApmcoI2FjASbbFMgeNsLxo/C3xWc3XAoCQvcx5wAqPKexPFesqg/jTfCxFU9vBXwyFvTRIMBjtpWXJzOsAj+1IsXZMGzqiM4zh+FsDOlHQJ+toqlGBxNX856Scmx4UH/5l/3U/JiwMOwXn6zCSuwvj2JBe98Ka8tG+YRqWB3Q6XGMdmI0+lvbFoeQhx3Q9r0dMeHZXoqUA3LFThbSG4ImbnIxJh/rRDpn61taX3cg/rc5ngo7Z5/kx8ZfyAkCh1Y9tjRec4qs0v5OrfcxD5wZVxKlbmcJ53Z08BTh1PahhN+tfIqkU194+JmzAjC6tX3TyZInSQr6OT0MNAI36FtPxcqh3q/TraVMkbQQVm579a+c5BOVmB/Wvd17hziU8F0HXj2mNvBW79Rt/4LWpb/8eVDRg7Lc8jh/rHIS6HdAcinZ9GIJhTqVYuW7pYAqAjcIjIm/ttdH+7z9UmQuxMS1np4PN/3ZiZ/nRr1JH/Sqb3telejoOG+IBh/i4kR496upKVRFIDvtEawChLxX1mdAA7TalEWluVKdO0xZUK1imlaV+iQplyrLueourzsKf5bq3Y9aT9GssFMT3JyLWiozVLHDhgqOXszrz0FDLXi9qt9qKG3aRJqcQTp2kXKGZjUKe9Y2Y9m3f3RcL7XNaopZwsx 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)(396003)(376002)(346002)(366004)(39860400002)(136003)(451199018)(186003)(2906002)(6512007)(5660300002)(38100700002)(26005)(6506007)(8936002)(4326008)(6486002)(41300700001)(86362001)(2616005)(8676002)(66946007)(66556008)(66476007)(6666004)(110136005)(36756003)(54906003)(83380400001)(316002)(478600001)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: i8hSSz109ul6DhgWPPXr+ak3tXy/+feCiIfJryYsNoS/BQU7sTvuKaPlxHpw8Aaomuab3dmh30dGtFPlxfXD9n85qUfKuqM9RyQXCFg4g0pQB1kBLiQ8mpqcpRTKphCCiTJ26AJqwNM2CVDoxV5QMXiLyAVBCV5GLiibVCmw3Gb1c71ITMLZnv5PzQyyRo/GhzuvKKqZXxuwV0+iseNLFRfVhxjICV+/uFPW+akWT4VgfISdMjR8EgiG8ZtNo976+z8y9MRpV+r4A4hrl5zwX0J/HLiFGlpa5SXEjH2iBo2spRMn3qGHVw/MklLAbYhmzPvQJ9ZkjqCnUwnR4FqOR51xYdRUomwL1eV36p/J1U+OK4yxEZJjvCQuOhjxobB9S0GAZLp0hqFVXqyRUjegap66xLJ0TQnyxb32M8BTbcvDOnxbuR9SvWW1osgF7H/dcJEyzkWf2Ub2iCHbLvPQ6a3gaQSyEBx8fAUsM0/WZt47IEAjJ5zPuxxLc3c21uKbquK2l+yZb/UF/1sM8geb6EXkuTVi5KPl/P7+dNAuIF2dmvL+QKAvqf7xOlZ+oKBqhFwaGSF//YhhyLDd1Q2cUftrEVwq73WKYnTiQNVBYHo8wcAPESnlC6r25Rw62wWgYCNfDsIr0TMaJAcggTK7AvlLjy+vXV+RRbIHFQuZCuBj85Jt3wrw5vXtNk5oZrr4A5yYkRpzYgVMlShfaUjxG2xadGc6lERqFyTkJl3ts66eZzP5+ftmau/FlPB9qvKpsUBJmSh27zw82TpXJeroeNl7mLTxd1/qGOjkwS8q/RBcGxwaeJjGvhMOflqng6PWIheWQHCkOjgfWLRIbRq/YkAV9pKj9sGPnnVd+DIzEjnT1ZREauhfRXItzl0eOTU6ZfnkR3WrLLTBLkp7EXmC706ooZTjpzLPiu4R3aS+SqOA1A7eMLfzcBzgYouF5k894SuPvpZj27BtemZvg26F27mTP+hCB39EPuHj18EMV3TgfywScUqysiT+Hr+MiwSZo+khu2ZLxHBtvE+ZHj6k8EWwwf6/Cwm4oi8mfYuSX98mZCQn5zBrllTSawmWuJXY65oMVmshlnXwrYJjgRVGRsybnwJnUpwmCmJeg2+JmYR06B1PLymLSF+V4F7w13nr45laFyfuGIHkWQXz2Tt3j1oEfVwbKZ8BCpjeSdCAMxKztwZxgRmEnhQPiOaqVUgBxDi5EwIYBdoJl5oGxbm5VcRciYIQTWSdRme0xge81gKP6syORvwfXAlxFka6ICiAFjmcQCSlCB3Cp1J6hTMsbFY7mQDkQ9cABuqXsCXv16y2htJHefzwYqxZ4Vsnw/Onn8Yc3IoLK+Abcq7mn4rvqzUH+8wqcw89uvVAjrvzFHHRnwLQY8AsLBg7SI0/r0F9MR/neHk4hFEzn74lM8fLoG4rC+2H/m8g9wxeGE0N2zX8BOqecnv2U8CGGAye0S/WMoDX+UQY8EK+bfUpPA1R+AcoUYlIyCZ4iSQ9QHau3eDmkUY8EQk/jBu0y4MOlq3HJhoV3W9ExBdnRYSoNtp4zL40K/Yfi9hVnqV2/r45YSZ2MYQyXFbN8DsFfBxN+IrA X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 50fc81a9-3d89-4b4e-71a6-08db1a8b6bb4 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2023 19:30:31.4227 (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: FHSS4Yoq+a45mlpjUN4JbqQW+nRo35gkOKkvRviMd4ooxGHo5Lm1egho4d0WWx2s X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8086 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org In this case the domain_id was acting as the hwpt_id, so be clearer. Signed-off-by: Jason Gunthorpe Reviewed-by: Kevin Tian --- tools/testing/selftests/iommu/iommufd.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c index 000fadf8110833..6a61ec84243572 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -988,8 +988,8 @@ FIXTURE(iommufd_mock_domain) { int fd; uint32_t ioas_id; - uint32_t domain_id; - uint32_t domain_ids[2]; + uint32_t hwpt_id; + uint32_t hwpt_ids[2]; int mmap_flags; size_t mmap_buf_size; }; @@ -1008,11 +1008,11 @@ FIXTURE_SETUP(iommufd_mock_domain) ASSERT_NE(-1, self->fd); test_ioctl_ioas_alloc(&self->ioas_id); - ASSERT_GE(ARRAY_SIZE(self->domain_ids), variant->mock_domains); + ASSERT_GE(ARRAY_SIZE(self->hwpt_ids), variant->mock_domains); for (i = 0; i != variant->mock_domains; i++) - test_cmd_mock_domain(self->ioas_id, NULL, &self->domain_ids[i]); - self->domain_id = self->domain_ids[0]; + test_cmd_mock_domain(self->ioas_id, NULL, &self->hwpt_ids[i]); + self->hwpt_id = self->hwpt_ids[0]; self->mmap_flags = MAP_SHARED | MAP_ANONYMOUS; self->mmap_buf_size = PAGE_SIZE * 8; @@ -1061,7 +1061,7 @@ FIXTURE_VARIANT_ADD(iommufd_mock_domain, two_domains_hugepage) struct iommu_test_cmd check_map_cmd = { \ .size = sizeof(check_map_cmd), \ .op = IOMMU_TEST_OP_MD_CHECK_MAP, \ - .id = self->domain_id, \ + .id = self->hwpt_id, \ .check_map = { .iova = _iova, \ .length = _length, \ .uptr = (uintptr_t)(_ptr) }, \ @@ -1070,8 +1070,8 @@ FIXTURE_VARIANT_ADD(iommufd_mock_domain, two_domains_hugepage) ioctl(self->fd, \ _IOMMU_TEST_CMD(IOMMU_TEST_OP_MD_CHECK_MAP), \ &check_map_cmd)); \ - if (self->domain_ids[1]) { \ - check_map_cmd.id = self->domain_ids[1]; \ + if (self->hwpt_ids[1]) { \ + check_map_cmd.id = self->hwpt_ids[1]; \ ASSERT_EQ(0, \ ioctl(self->fd, \ _IOMMU_TEST_CMD( \ @@ -1203,9 +1203,9 @@ TEST_F(iommufd_mock_domain, all_aligns_copy) test_ioctl_ioas_map(buf + start, length, &iova); /* Add and destroy a domain while the area exists */ - old_id = self->domain_ids[1]; + old_id = self->hwpt_ids[1]; test_cmd_mock_domain(self->ioas_id, &mock_device_id, - &self->domain_ids[1]); + &self->hwpt_ids[1]); check_mock_iova(buf + start, iova, length); check_refs(buf + start / PAGE_SIZE * PAGE_SIZE, @@ -1214,8 +1214,8 @@ TEST_F(iommufd_mock_domain, all_aligns_copy) 1); test_ioctl_destroy(mock_device_id); - test_ioctl_destroy(self->domain_ids[1]); - self->domain_ids[1] = old_id; + test_ioctl_destroy(self->hwpt_ids[1]); + self->hwpt_ids[1] = old_id; test_ioctl_ioas_unmap(iova, length); } From patchwork Wed Mar 1 19:30:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13156356 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 ECA57C7EE45 for ; Wed, 1 Mar 2023 19:30:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229533AbjCATal (ORCPT ); Wed, 1 Mar 2023 14:30:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229667AbjCATak (ORCPT ); Wed, 1 Mar 2023 14:30:40 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2062.outbound.protection.outlook.com [40.107.93.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAF8438EB7 for ; Wed, 1 Mar 2023 11:30:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ItOK84QX7CwAyoV2sa+Z7hd+KbC3s9e+1LgeIHlmAfok5GSY/SJbhlf2koDHkCuZ5ZjGd2grNRBWYiN7hDwejN06TM2BerhlUfteusbM3Kn4mIYXLr7DG0j3QRZXqsf49HeFPWLJqwrYTu+Fe8jsGJp2TWoazWy7pcmJMA9MhjDxrOCJpC58+We+204ns5ULd1d6OiDnuOEabVFRIyA6VsYbycz87bEtpf0XyrkZRkFNm6RZEpAQyefInHa3iwBEaHh8MP3bp7eW/Bc/kRVqYZxyKiFvbmikT2+LeChCocjuhqusi2e/7QkYLwjQ51vS2sLvMbWQywKeN1Q1XM4weQ== 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=6AB7dOaZggIQRsdIHBoUQaO85PFcCCbbJxJCyNAb/Pw=; b=YZPdBVtp9f2tlLBBSniq+pSOOzSy5dLa47XWMDKyn/1+S+3GRK/9BxvFNExDUZ2Qcn8/upUv1dCbRJks49eXFrZ1FL3X+3BNjB+5SpUciXvGqRJVbJbgkchGkiFo1tKWkvXAZ9h5JcvmcwfeHxBOHCs3cYw3v7bA9Aq9rxElLTjDU5mNcxy46h8vlqU/KA5czOcRUYH4HK9l45IOLCWkNVcWhxHbstZyWVZY6sIJpqD283akvYb981rF137CtLpAf48tPfZVXotpZOKgEFUke7ATzeCAlJVInwC2MwdrwqwAsv+W71/dIu8XQbQbPkRqv2jqf3Z61YC7btAYzlkbbw== 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=6AB7dOaZggIQRsdIHBoUQaO85PFcCCbbJxJCyNAb/Pw=; b=bk2Eies1wUFtTNlohNZ7xRGH4wTmG+lKzhvuiqrEqpwFz5UfobN7TWljzJbIdYCg6ZgAtH7tq9OkT7QXjVktKljGDLN9oD4MLiHkLZBQJ7vVpE1FiAtwPZOxs2NVmBrS4XOywPds+47/Evrix1t5yPsqcnalDMy7u54KraG0f6PxVCR9Em5X7KPZZ//nvuYvqOKt+lJpxKlpsdfPJsXUnSZMwG9doWkEY2iRbnwLPmXWAUy3VI8dXhBcB4fEzL64BcDkHSoYTJe5bkzu6KeJpM7gONLPNeXmv5VxXpuOrDklD8XaYDhBYDkk5sAD+1HMahvM+Gmlc6T3DayV7+8uNQ== 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 IA0PR12MB8086.namprd12.prod.outlook.com (2603:10b6:208:403::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.30; Wed, 1 Mar 2023 19:30:34 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3cb3:2fce:5c8f:82ee]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3cb3:2fce:5c8f:82ee%4]) with mapi id 15.20.6134.029; Wed, 1 Mar 2023 19:30:34 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Kevin Tian , linux-kselftest@vger.kernel.org, Shuah Khan Cc: Nicolin Chen , Yi Liu Subject: [PATCH v3 10/12] iommufd/selftest: Rename the remaining mock device_id's to stdev_id Date: Wed, 1 Mar 2023 15:30:27 -0400 Message-Id: <10-v3-ae9c2975a131+2e1e8-iommufd_hwpt_jgg@nvidia.com> In-Reply-To: <0-v3-ae9c2975a131+2e1e8-iommufd_hwpt_jgg@nvidia.com> References: X-ClientProxiedBy: YT4PR01CA0101.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:d7::17) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA0PR12MB8086:EE_ X-MS-Office365-Filtering-Correlation-Id: 989d79d5-483b-479f-7b4a-08db1a8b6c22 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3pQPYgqyXk2eO2LG4G/Vz45F+ga1G2kHk/109AyARRAi7jG6GSMnhJvhcryJROKla1MKEbuiQ43pGPnJlSdORRGxuitNwXRRQ0A1VlUZUlFPqN57AmpXP6ESrykNCrG/Ks1Vy5Qv3HVnGI8mrQqfpBEGQuvBumXlMkD1p6EtIY8Tr56hPBHJ/BsinSnb3qGr5T1s9AHDNM3P8LAIOngWgdNadTCS3xTh7KXDfC5sxiBd4CSH6kGrdlmJLiU2EkIrhfOA9opbNRcYNuSfIq0Mn8oGaHvHYxq6txUwuwbKHBvDLdMB6z3PidyCd8u28CzBibXCCI3cRpuGALTWaZUuk6T6wys3udo9T1qk5cdGqkjfMgLgKH/tF89epbzjbm6tBPCZb6axW4hErrjXn5Wv7urItb2DMq9ILrvuv/sPlO+5g3T7h7mkVQAmZZ4VpB4R0yiPBloNc3q0Prc6WCXxvAQT2ls9t5aQFGxcJr0kIIkjDbkj7o0DGPHD738ATynOPsspZrKN3S5HGT9DFql38LKRjZTXlYXvHNymILRFlRJtUd4Z8Ock4oAzLtSgdIeOXMJ1BNvS7L8GIBmsFKhCWocyQYCwARcBlkZ+ukA3c3xpe1jQnHWEO0zzfjwb7uuO3MRH8unaEVG0uZmGZPxLMQ== 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)(396003)(376002)(346002)(366004)(39860400002)(136003)(451199018)(186003)(2906002)(6512007)(5660300002)(38100700002)(26005)(6506007)(8936002)(4326008)(6486002)(41300700001)(86362001)(2616005)(8676002)(66946007)(66556008)(66476007)(6666004)(110136005)(36756003)(54906003)(83380400001)(316002)(478600001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cbGtZI6iwAN6PjB1iXjtvAxvEgMjxpp3qYo4WX7K8Cd4lS8QbBYc1PLlgKbrRG1J/L+eAioYfud2wnsUe0CQM16N6jROcKaQnVayGonhKqKE61VR4DU1E7Xq4PhsyDM9M5cB3FJFLu6zVpGHDHofF8HxmttPyNgLHtanrBGv8TBTnLv7O5cW2ZSJbWsVEb+bR7XSOXXojK6KTYvlj25JFxf2MMAgKHWmamIiA3U2uPlcWAq7UlwssRFPbp0Q22bWic1yAYTyqTI0IR7a1jo8AZgf7ov+/XBkzJRsxHQlzp2tFB8mGFX0FByGuLeHQ/JqBv3ihZvysBBU9e2WH/eXHRf90Qcu7vy+ukYcx9xmqfmcuCjtvSYgzK9aw6dWmzqZuFcZO1VVXcu8bMVmWHdKW1iI2lh/Z878EhD1X1fARLlVTj22HOFePlk5gbgWO6UBWzhh+xyl8z07a2j8XSfP/mDXBAYmcZc/X1usYme2u6Jf5szySXlCu8dOCAbB9eh9sZB4Op84fAdFcHRiatM04ncSiY+J2Mqhd50+g7uxjxWh/17JXLGDHz4QMMLO8nkmiVCgBIvOTuQNWe6YuhiNsN4DC51UqMDxiIHIplZrFzyQ7/IrIZngDv7siiqFXY5bsGsaqnTD2aiOOGpnw+BSnW7F1bG6J5XJLz4Wit2CSihYE4ZXcsAKbb0uWUsfIaHSSRT5HGv0nehqpf5yrIlCvSrYUsGU7VXTtpf+Bx8d/g4YJkXSjETSdfdGuftKrjsRnafQrGuyEti792P8onA+RV4Dq0MvL+g/oiG84+rr+0xP1jYt/3wR8a13DfDl3A63tTsZnqU/LMUzu0TZlxaeAnbG6FpHh7P3iZ1Ssa5Hfd+LcB+joRc+kr1mXOkZE4IrGoBZdgyAite0HEsd88exmCz+HSuOScW7KCs+tTasirVP2dllzO8D3lHNHf5UIDKfcqHMKBX3A7KtyzVLSijN0PHJ6BqjAl8kaqbRBU9eH7YmmAsHs6ycwrVn1+bgCB3rYcGs45p8RAgHGjF3kM6Jy7Jjm5NDf/8YHuaYezSack6mY/6X8LiSV3vt5UBQDovUR3OfRhJDc+tahBZ0yb6nbk/lLzMZVABpyghjkE2Rp19zq+NuFgd2Phuc0oJQRuFdty2Xn8EA2WXYk1r0lM7ii33OHhoXT/YyDEVj5HZELwMU4JMYZHCUStKRZl5+j7u3OhHB2clmh5nfCDAq+imgZbNv5cVRRxLmtcalC6f7NWe+GNxUzdxLNhBZa7gc5z7F/fjF2EIyacSIh65W9sql8VFN6H5kcBowh2SUXs+NuzRsmnGXyBpnSQ+Wrq9M2J31oKUJ695IrDIcFQ6KEkmw5mp37/IvlwPl9q2uwaVq59nTTuTNIPFrFk4WLbK8Lmngiflmb3JbB5S+Kr159hTiUva3UvIn5jVd07wYi5S93jrwlrf+dwsyqx4Vlkkea1b/oY5PSxvTEYdE+3Y/4+nOQXvtMnoOnF9fcxYOqGOgRkCdfsAfcmDiVsbAgbRskHvnR4RyxgK3LBwV8R7H57c8Wli/meYO426No5npvIkcfOwaEnQG9hwVVaYV2mnaN8bo X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 989d79d5-483b-479f-7b4a-08db1a8b6c22 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2023 19:30:32.1594 (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: 0p7vdtUZsC3Ppubx24OWCieQfQOA+eRBK7nidbtP+v1sIsn8qwYhtYVk7slPTfcM X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8086 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org For consistency. Signed-off-by: Jason Gunthorpe Reviewed-by: Kevin Tian --- tools/testing/selftests/iommu/iommufd.c | 12 ++++---- .../selftests/iommu/iommufd_fail_nth.c | 30 +++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c index 6a61ec84243572..a9b232c281c02f 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -605,7 +605,7 @@ TEST_F(iommufd_ioas, access_pin) MOCK_FLAGS_ACCESS_CREATE_NEEDS_PIN_PAGES); for (npages = 1; npages < BUFFER_SIZE / PAGE_SIZE; npages++) { - uint32_t mock_device_id; + uint32_t mock_stdev_id; uint32_t mock_hwpt_id; access_cmd.access_pages.length = npages * PAGE_SIZE; @@ -637,14 +637,14 @@ TEST_F(iommufd_ioas, access_pin) ASSERT_EQ(0, ioctl(self->fd, _IOMMU_TEST_CMD(IOMMU_TEST_OP_ACCESS_PAGES), &access_cmd)); - test_cmd_mock_domain(self->ioas_id, &mock_device_id, + test_cmd_mock_domain(self->ioas_id, &mock_stdev_id, &mock_hwpt_id); check_map_cmd.id = mock_hwpt_id; ASSERT_EQ(0, ioctl(self->fd, _IOMMU_TEST_CMD(IOMMU_TEST_OP_MD_CHECK_MAP), &check_map_cmd)); - test_ioctl_destroy(mock_device_id); + test_ioctl_destroy(mock_stdev_id); test_ioctl_destroy(mock_hwpt_id); test_cmd_destroy_access_pages( access_cmd.id, @@ -1197,14 +1197,14 @@ TEST_F(iommufd_mock_domain, all_aligns_copy) for (; end < buf_size; end += MOCK_PAGE_SIZE) { size_t length = end - start; unsigned int old_id; - uint32_t mock_device_id; + uint32_t mock_stdev_id; __u64 iova; test_ioctl_ioas_map(buf + start, length, &iova); /* Add and destroy a domain while the area exists */ old_id = self->hwpt_ids[1]; - test_cmd_mock_domain(self->ioas_id, &mock_device_id, + test_cmd_mock_domain(self->ioas_id, &mock_stdev_id, &self->hwpt_ids[1]); check_mock_iova(buf + start, iova, length); @@ -1213,7 +1213,7 @@ TEST_F(iommufd_mock_domain, all_aligns_copy) start / PAGE_SIZE * PAGE_SIZE, 1); - test_ioctl_destroy(mock_device_id); + test_ioctl_destroy(mock_stdev_id); test_ioctl_destroy(self->hwpt_ids[1]); self->hwpt_ids[1] = old_id; diff --git a/tools/testing/selftests/iommu/iommufd_fail_nth.c b/tools/testing/selftests/iommu/iommufd_fail_nth.c index 9713111b820dd7..e7d535680721b2 100644 --- a/tools/testing/selftests/iommu/iommufd_fail_nth.c +++ b/tools/testing/selftests/iommu/iommufd_fail_nth.c @@ -297,7 +297,7 @@ TEST_FAIL_NTH(basic_fail_nth, basic) TEST_FAIL_NTH(basic_fail_nth, map_domain) { uint32_t ioas_id; - __u32 device_id; + __u32 stdev_id; __u32 hwpt_id; __u64 iova; @@ -313,7 +313,7 @@ TEST_FAIL_NTH(basic_fail_nth, map_domain) fail_nth_enable(); - if (_test_cmd_mock_domain(self->fd, ioas_id, &device_id, &hwpt_id)) + if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id, &hwpt_id)) return -1; if (_test_ioctl_ioas_map(self->fd, ioas_id, buffer, 262144, &iova, @@ -321,12 +321,12 @@ TEST_FAIL_NTH(basic_fail_nth, map_domain) IOMMU_IOAS_MAP_READABLE)) return -1; - if (_test_ioctl_destroy(self->fd, device_id)) + if (_test_ioctl_destroy(self->fd, stdev_id)) return -1; if (_test_ioctl_destroy(self->fd, hwpt_id)) return -1; - if (_test_cmd_mock_domain(self->fd, ioas_id, &device_id, &hwpt_id)) + if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id, &hwpt_id)) return -1; return 0; } @@ -334,8 +334,8 @@ TEST_FAIL_NTH(basic_fail_nth, map_domain) TEST_FAIL_NTH(basic_fail_nth, map_two_domains) { uint32_t ioas_id; - __u32 device_id2; - __u32 device_id; + __u32 stdev_id2; + __u32 stdev_id; __u32 hwpt_id2; __u32 hwpt_id; __u64 iova; @@ -350,12 +350,12 @@ TEST_FAIL_NTH(basic_fail_nth, map_two_domains) if (_test_ioctl_set_temp_memory_limit(self->fd, 32)) return -1; - if (_test_cmd_mock_domain(self->fd, ioas_id, &device_id, &hwpt_id)) + if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id, &hwpt_id)) return -1; fail_nth_enable(); - if (_test_cmd_mock_domain(self->fd, ioas_id, &device_id2, &hwpt_id2)) + if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id2, &hwpt_id2)) return -1; if (_test_ioctl_ioas_map(self->fd, ioas_id, buffer, 262144, &iova, @@ -363,19 +363,19 @@ TEST_FAIL_NTH(basic_fail_nth, map_two_domains) IOMMU_IOAS_MAP_READABLE)) return -1; - if (_test_ioctl_destroy(self->fd, device_id)) + if (_test_ioctl_destroy(self->fd, stdev_id)) return -1; if (_test_ioctl_destroy(self->fd, hwpt_id)) return -1; - if (_test_ioctl_destroy(self->fd, device_id2)) + if (_test_ioctl_destroy(self->fd, stdev_id2)) return -1; if (_test_ioctl_destroy(self->fd, hwpt_id2)) return -1; - if (_test_cmd_mock_domain(self->fd, ioas_id, &device_id, &hwpt_id)) + if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id, &hwpt_id)) return -1; - if (_test_cmd_mock_domain(self->fd, ioas_id, &device_id2, &hwpt_id2)) + if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id2, &hwpt_id2)) return -1; return 0; } @@ -518,7 +518,7 @@ TEST_FAIL_NTH(basic_fail_nth, access_pin_domain) { uint32_t access_pages_id; uint32_t ioas_id; - __u32 device_id; + __u32 stdev_id; __u32 hwpt_id; __u64 iova; @@ -532,7 +532,7 @@ TEST_FAIL_NTH(basic_fail_nth, access_pin_domain) if (_test_ioctl_set_temp_memory_limit(self->fd, 32)) return -1; - if (_test_cmd_mock_domain(self->fd, ioas_id, &device_id, &hwpt_id)) + if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id, &hwpt_id)) return -1; if (_test_ioctl_ioas_map(self->fd, ioas_id, buffer, BUFFER_SIZE, &iova, @@ -570,7 +570,7 @@ TEST_FAIL_NTH(basic_fail_nth, access_pin_domain) return -1; self->access_id = 0; - if (_test_ioctl_destroy(self->fd, device_id)) + if (_test_ioctl_destroy(self->fd, stdev_id)) return -1; if (_test_ioctl_destroy(self->fd, hwpt_id)) return -1; From patchwork Wed Mar 1 19:30:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13156359 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 5CD06C7EE3A for ; Wed, 1 Mar 2023 19:30:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229561AbjCATaj (ORCPT ); Wed, 1 Mar 2023 14:30:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229563AbjCATai (ORCPT ); Wed, 1 Mar 2023 14:30:38 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2075.outbound.protection.outlook.com [40.107.93.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 976A172B4 for ; Wed, 1 Mar 2023 11:30:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T8k23N+B+MCVmM9T3qNocVnxb2SC4897Z1suHYA8q4dJ1CF8N6G4phecbX5E3H/bcLzclLj78j+/nkSOY77BFg6+rYl2Tveb5WKWlZ+LbuIEO4xEEsMqFzbNZ7BBuFuv9QvQWr+6auds8DwYjPIp+KosJLLdXcfcNULA4rR82VFOOu7qSNXAaHgF1FZ2NE+tXVzEhQaQzE2/iQ7J/qqNRZTJ25J7OZY286RiBJsPN16ASN0vBeJo9EGMihB6K0oKRXt/o6LvDtAux+cRYSz7Fx+JREDf912gkzGixNM3Ft4Fonvlm39iI6/TIMtgXyX5NGNWlIHFdoK4tfFdm51mXQ== 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=9TiEY2h4OTbLT6U40o0056k/YqqESe64u5Isx6Cn9dk=; b=f6IYTOmx928p4dEW1fTqgK24po+YojSHz10oOkuQQBCmfy0yCHtuS/6nXuUXldSe5DVESDo9pCGPRazDDInrBXmFtl+Jw6X3lUKK9Dasl4beyw8BRwE2J+LbzPzV427pIgEB+5PV7JPADS+uqYSEGHS0uv34QIGzUucfxWYwdO75Imi8qKIk9pnidLksQBokX9+vxUa22Brbn660QHbAFiWg9mUQibyo2IMk2/41yLCrZ1Xo8jbu9sjD56T+mU/P80SrXGPlsjdxt3xtc9vq0F4WzR1HaZg9MRkEJ4wb5UWR6HgalfVQCaADQr0qj12RHoKUrjPzdaLHJYv7LjQ4VA== 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=9TiEY2h4OTbLT6U40o0056k/YqqESe64u5Isx6Cn9dk=; b=IgtSIjrNtxMloJE1Ni6OZA0IXDUKUZ9gPl+p+VNwhTpumjWTMFmXM8qyvOCEDCl0xVdugzzG32GSKFLWYX7Gk9CSrAmhZxG8Hdb9OQIGVMXGcbuLjfkYBQkk4JU+2bxAkYGsQ38yZ//4RpgKL1uwk44QBlK6nw3mh6F2R4hHbh+Kf55r7xVGsHs4gk3cDEAGgsZHLwX3CcNZZFUF/LjLxZ94A37yfmlaHwi6KwAb+R4OFRVrU5VCNArUXGgSPbVShxQ5POhu6gwR74tAqKSnUwaJjqZh+Vwk+31C/eK8GdR9RNJ1lnxHvhCOLisVFwt8wJ0jPsNgxWhDD5M5e2duSw== 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 IA0PR12MB8086.namprd12.prod.outlook.com (2603:10b6:208:403::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.30; Wed, 1 Mar 2023 19:30:33 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3cb3:2fce:5c8f:82ee]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3cb3:2fce:5c8f:82ee%4]) with mapi id 15.20.6134.029; Wed, 1 Mar 2023 19:30:33 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Kevin Tian , linux-kselftest@vger.kernel.org, Shuah Khan Cc: Nicolin Chen , Yi Liu Subject: [PATCH v3 11/12] iommufd/selftest: Make selftest create a more complete mock device Date: Wed, 1 Mar 2023 15:30:28 -0400 Message-Id: <11-v3-ae9c2975a131+2e1e8-iommufd_hwpt_jgg@nvidia.com> In-Reply-To: <0-v3-ae9c2975a131+2e1e8-iommufd_hwpt_jgg@nvidia.com> References: X-ClientProxiedBy: YT4PR01CA0120.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:d7::22) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA0PR12MB8086:EE_ X-MS-Office365-Filtering-Correlation-Id: dd21df5b-13e6-483f-8cd3-08db1a8b6b7b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gt7gStWSX2eBoGlLzgRvx87F8tNC6Ida047a7yRqDNYjscwfcPPdscaetYyZVeG5yOAcuNBl74Y5755LPBNeyL1yff8IgPlZCvI0GylxkHCIocLf4TUQwOQPeBVYPBjUsoPvlnggpq/hjm4tZH17NZgicv5L6R7xHbU9FQVYVb0YKm/YalWPwPXHY3Rbc/6PPriUgTQDHJqD9SnpYdx0IOIVNOLFapsXqShsWZBbMPeaUNNFnmJbqsRcjhTM7dxpcN5Gnv9NIyi/YzS1fbrI+V5zN+589kUKXT1TtPXB71hDvg67ueJtp1D4nddxzXkBaaVXxrf7TtP6nYcXm/S35rihyu2fASZ4HtnHeH902lwzDpKQPb0wyeUH5JWVgVF8IjHjdC0g64xqm4rNHjGc3husxlB0+t12ufxQpUW3rq+Lv2bun8AIrhzgEEEiXEl6V6fV/P0lVF+Zh++UMkU1ttI4qdDjeJ/hGLbAgX1k5zcH5t0D+6QrD8sbEFQVlJ0QhGCtcIfamr/h955ZwhRHvcVhQr8nErZ7rxRNvpiuRyQxaB3vj83mrSXdjLWfMLCARIYBc+ePQVS/HS4WGv/KN5CB78YqsMtKGMuFMJ7b6RTsDRnFKEdcFNT8ZUCv8rofB9nOvZep1qeQ/YLFOPWXkg== 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)(396003)(376002)(346002)(366004)(39860400002)(136003)(451199018)(186003)(2906002)(30864003)(6512007)(5660300002)(38100700002)(26005)(6506007)(8936002)(4326008)(6486002)(41300700001)(86362001)(2616005)(8676002)(66946007)(66556008)(66476007)(6666004)(110136005)(36756003)(54906003)(83380400001)(316002)(478600001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: SKA7IdPVa8JCsBe0hSZPo75XDrNk99iVNhLdUBPwmaMuF7K2MM0ErCP/IsAviScvz3NLIlUMG0qenFCRkWcisEESrSAykgVkBn+OQWrQRVEWiTWTpu/iztRhVrcOOS4AU1hXK9AhUv4v1LM2i6oDuPEknkofG9yuSY5P5NdYwtcA7Zdcrwpu5bnLYb2MN0jJmINerdT5NJLtV8D1CEZeYGhbLySoQJ1pN+7/20vjYjyHGOow5gHE4pBkCaYW+KxK39jo3cuCw2OzM0jUgyfPWWxiWXEMIybAQD19dna2ApE9JTvXLDDfZC2xVFFzfhF4yawP5MnIr4wbCn7sTH59IFAIze4TtV7U/kae9RhcXf8cyJEnZGADq8kkdnPetDQzCYDmNzIWbagHcSOgX8FjmWWwjyJHcLJfbt/bTNlFpWuLDmAIwLHj2cGYLgPkKfF6KFGqw5wCGxLk4npqSiXUnnk6r+OCGXgTWJYYv1aA24I+8KhTxu4FuvkrVG7s1wjjkrvNmLfcYhz2NNxELpP4tgRsQlf+zn2AMhPPKroBlKFYrs5ffsTfK3JsJz4WQpU3DznFhOGmt92+N+9kvKI2GBSdcx7iEfH1yL1Z91t0D3fwtz2Ort1zCB64Qo6+ZEuELJl8r06DspvX6MxU333dULdfuYbgl+cmExqJy3dFTaLZ6JX4q5+ItZzjcv2Sf8b2oIRisQXZhzMUJWRSf4CQOR3IglVpVKdoRchG/u2jiLCMRkiAF/N+bCOjGP93YQBCy7jrtZm8oaqa0+/lltyhUfdgvd+rSiLUzGd+52H0+yhVYKlKMj8U+wIoIHdIUDH3tgJePbhe9OXEZDN7NiaaS6IvKQuyI8imB9IN+nu3YEpoIkECnaAmF8uIkqEdVVdoP3PYBXITgJFuoHwxqhx5XTlmBAE6tm8TkS3xnjGD568pi+yx2c96yD9LVtohy+vQ5YtZ4M9K4oPSOhqKpG17sTJYx1d4qeTQjxMzt5j2a7oYUsBxmmfYZt1ffXCdM2C1dfCKyfmHAf4imtOeVI4VODYSX4lvH+FDbjzVEzFMDdUfcGk8XC9b/FQyBaLmQ/sq3HqnpZlhZu1e8ewbtafpzW1ncDsmaf7QqKYag/Y2Hn8Hbjrdi1t4q54G7vbWQhVTvcmeaKlUtJ/DRZg/g3+91yLLP+ZBPVZCoSV1dki2FdwGG3qDp65czdEEidwPIefwRKqDoTSeZNu6EHlBGLKiZW/DmO3WpKz1k2dtlBZtiyRGgkymjTU3a5f4Sw0Fwto2WpXrOcseEIx+vEkBYW6HMXT3awQ4F3m+9RqjG0d+hCHPOXpRvjRj8Zm1KwFdZpUN3fIAhAwmj4uZgIVI6fUFYHQS5anDofxe/6dkc13fYWSGsoN4U1NoLfNtixZ/gzKs9s2yPccVUruIn7UqlwHeUTMLQQYN+byGgM8saC1AAzYco8bSRHE7xJIzriFExsYGigzS+WrxjfZ2yxajWiFRUhcbRS5PtGYYWr71eIZ8sc/j7zZhpaMKovtq+KxLKOG0HBfszmeusGqdkxxdhMvp9vnOJmS6LD9Y5oUGQTMnJCuwAnM6dNQo7/+rVth83xeK X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: dd21df5b-13e6-483f-8cd3-08db1a8b6b7b X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2023 19:30:31.1883 (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: y29MyJzWY8fe3+yPhboPOxz67yhlx7un13ryAu5Hr7KdtBl5kZLrLukD7M7Jiev7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8086 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org iommufd wants to use more infrastructure, like the iommu_group, that the mock device does not support. Create a more complete mock device that can go through the whole cycle of ownership, blocking domain, and has an iommu_group. This requires creating a real struct device on a real bus to be able to connect it to a iommu_group. Unfortunately we cannot formally attach the mock iommu driver as an actual driver as the iommu core does not allow more than one driver or provide a general way for busses to link to iommus. This can be solved with a little hack to open code the dev_iommus struct. With this infrastructure things work exactly the same as the normal domain path, including the auto domains mechanism and direct attach of hwpts. As the created hwpt is now an autodomain it is no longer required to destroy it and trying to do so will trigger a failure. Reviewed-by: Kevin Tian Signed-off-by: Jason Gunthorpe --- drivers/iommu/iommufd/device.c | 40 +--- drivers/iommu/iommufd/iommufd_private.h | 11 +- drivers/iommu/iommufd/selftest.c | 196 +++++++++++++++--- tools/testing/selftests/iommu/iommufd.c | 2 - .../selftests/iommu/iommufd_fail_nth.c | 8 - 5 files changed, 181 insertions(+), 76 deletions(-) diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index 8dc7ed678e3fbb..c6f4852a8a0c08 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -22,7 +22,8 @@ void iommufd_device_destroy(struct iommufd_object *obj) iommu_device_release_dma_owner(idev->dev); iommu_group_put(idev->group); - iommufd_ctx_put(idev->ictx); + if (!iommufd_selftest_is_mock_dev(idev->dev)) + iommufd_ctx_put(idev->ictx); } /** @@ -69,7 +70,8 @@ struct iommufd_device *iommufd_device_bind(struct iommufd_ctx *ictx, goto out_release_owner; } idev->ictx = ictx; - iommufd_ctx_get(ictx); + if (!iommufd_selftest_is_mock_dev(dev)) + iommufd_ctx_get(ictx); idev->dev = dev; idev->enforce_cache_coherency = device_iommu_capable(dev, IOMMU_CAP_ENFORCE_CACHE_COHERENCY); @@ -151,7 +153,8 @@ static int iommufd_device_setup_msi(struct iommufd_device *idev, * operation from the device (eg a simple DMA) cannot trigger an * interrupt outside this iommufd context. */ - if (!iommu_group_has_isolated_msi(idev->group)) { + if (!iommufd_selftest_is_mock_dev(idev->dev) && + !iommu_group_has_isolated_msi(idev->group)) { if (!allow_unsafe_interrupts) return -EPERM; @@ -706,34 +709,3 @@ int iommufd_access_rw(struct iommufd_access *access, unsigned long iova, return rc; } EXPORT_SYMBOL_NS_GPL(iommufd_access_rw, IOMMUFD); - -#ifdef CONFIG_IOMMUFD_TEST -/* - * Creating a real iommufd_device is too hard, bypass creating a iommufd_device - * and go directly to attaching a domain. - */ -struct iommufd_hw_pagetable * -iommufd_device_selftest_attach(struct iommufd_ctx *ictx, - struct iommufd_ioas *ioas, - struct device *mock_dev) -{ - struct iommufd_device tmp_idev = { .dev = mock_dev }; - struct iommufd_hw_pagetable *hwpt; - - mutex_lock(&ioas->mutex); - hwpt = iommufd_hw_pagetable_alloc(ictx, ioas, &tmp_idev, false); - mutex_unlock(&ioas->mutex); - if (IS_ERR(hwpt)) - return hwpt; - - refcount_inc(&hwpt->obj.users); - iommufd_object_finalize(ictx, &hwpt->obj); - return hwpt; -} - -void iommufd_device_selftest_detach(struct iommufd_ctx *ictx, - struct iommufd_hw_pagetable *hwpt) -{ - refcount_dec(&hwpt->obj.users); -} -#endif diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index 331664e917b771..d523ef12890e1e 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -297,12 +297,6 @@ void iopt_remove_access(struct io_pagetable *iopt, void iommufd_access_destroy_object(struct iommufd_object *obj); #ifdef CONFIG_IOMMUFD_TEST -struct iommufd_hw_pagetable * -iommufd_device_selftest_attach(struct iommufd_ctx *ictx, - struct iommufd_ioas *ioas, - struct device *mock_dev); -void iommufd_device_selftest_detach(struct iommufd_ctx *ictx, - struct iommufd_hw_pagetable *hwpt); int iommufd_test(struct iommufd_ucmd *ucmd); void iommufd_selftest_destroy(struct iommufd_object *obj); extern size_t iommufd_test_memory_limit; @@ -311,6 +305,7 @@ void iommufd_test_syz_conv_iova_id(struct iommufd_ucmd *ucmd, bool iommufd_should_fail(void); void __init iommufd_test_init(void); void iommufd_test_exit(void); +bool iommufd_selftest_is_mock_dev(struct device *dev); #else static inline void iommufd_test_syz_conv_iova_id(struct iommufd_ucmd *ucmd, unsigned int ioas_id, @@ -327,5 +322,9 @@ static inline void __init iommufd_test_init(void) static inline void iommufd_test_exit(void) { } +static inline bool iommufd_selftest_is_mock_dev(struct device *dev) +{ + return false; +} #endif #endif diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index e05b41059630a7..17cb7b95eb2757 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -91,23 +91,50 @@ enum selftest_obj_type { TYPE_IDEV, }; +struct mock_dev { + struct device dev; +}; + struct selftest_obj { struct iommufd_object obj; enum selftest_obj_type type; union { struct { - struct iommufd_hw_pagetable *hwpt; + struct iommufd_device *idev; struct iommufd_ctx *ictx; - struct device mock_dev; + struct mock_dev *mock_dev; } idev; }; }; +static void mock_domain_blocking_free(struct iommu_domain *domain) +{ +} + +static int mock_domain_nop_attach(struct iommu_domain *domain, + struct device *dev) +{ + return 0; +} + +static const struct iommu_domain_ops mock_blocking_ops = { + .free = mock_domain_blocking_free, + .attach_dev = mock_domain_nop_attach, +}; + +static struct iommu_domain mock_blocking_domain = { + .type = IOMMU_DOMAIN_BLOCKED, + .ops = &mock_blocking_ops, +}; + static struct iommu_domain *mock_domain_alloc(unsigned int iommu_domain_type) { struct mock_iommu_domain *mock; + if (iommu_domain_type == IOMMU_DOMAIN_BLOCKED) + return &mock_blocking_domain; + if (WARN_ON(iommu_domain_type != IOMMU_DOMAIN_UNMANAGED)) return NULL; @@ -236,19 +263,39 @@ static phys_addr_t mock_domain_iova_to_phys(struct iommu_domain *domain, return (xa_to_value(ent) & MOCK_PFN_MASK) * MOCK_IO_PAGE_SIZE; } +static bool mock_domain_capable(struct device *dev, enum iommu_cap cap) +{ + return cap == IOMMU_CAP_CACHE_COHERENCY; +} + +static void mock_domain_set_plaform_dma_ops(struct device *dev) +{ + /* + * mock doesn't setup default domains because we can't hook into the + * normal probe path + */ +} + static const struct iommu_ops mock_ops = { .owner = THIS_MODULE, .pgsize_bitmap = MOCK_IO_PAGE_SIZE, .domain_alloc = mock_domain_alloc, + .capable = mock_domain_capable, + .set_platform_dma_ops = mock_domain_set_plaform_dma_ops, .default_domain_ops = &(struct iommu_domain_ops){ .free = mock_domain_free, + .attach_dev = mock_domain_nop_attach, .map_pages = mock_domain_map_pages, .unmap_pages = mock_domain_unmap_pages, .iova_to_phys = mock_domain_iova_to_phys, }, }; +struct iommu_device mock_iommu_device = { + .ops = &mock_ops, +}; + static inline struct iommufd_hw_pagetable * get_md_pagetable(struct iommufd_ucmd *ucmd, u32 mockpt_id, struct mock_iommu_domain **mock) @@ -269,48 +316,142 @@ get_md_pagetable(struct iommufd_ucmd *ucmd, u32 mockpt_id, return hwpt; } +static struct bus_type iommufd_mock_bus_type = { + .name = "iommufd_mock", + .iommu_ops = &mock_ops, +}; + +static void mock_dev_release(struct device *dev) +{ + struct mock_dev *mdev = container_of(dev, struct mock_dev, dev); + + kfree(mdev); +} + +static struct mock_dev *mock_dev_create(void) +{ + struct iommu_group *iommu_group; + struct dev_iommu *dev_iommu; + struct mock_dev *mdev; + int rc; + + mdev = kzalloc(sizeof(*mdev), GFP_KERNEL); + if (!mdev) + return ERR_PTR(-ENOMEM); + + device_initialize(&mdev->dev); + mdev->dev.release = mock_dev_release; + mdev->dev.bus = &iommufd_mock_bus_type; + + iommu_group = iommu_group_alloc(); + if (IS_ERR(iommu_group)) { + rc = PTR_ERR(iommu_group); + goto err_put; + } + + rc = dev_set_name(&mdev->dev, "iommufd_mock%u", + iommu_group_id(iommu_group)); + if (rc) + goto err_group; + + /* + * The iommu core has no way to associate a single device with an iommu + * driver (heck currently it can't even support two iommu_drivers + * registering). Hack it together with an open coded dev_iommu_get(). + * Notice that the normal notifier triggered iommu release process also + * does not work here because this bus is not in iommu_buses. + */ + mdev->dev.iommu = kzalloc(sizeof(*dev_iommu), GFP_KERNEL); + if (!mdev->dev.iommu) { + rc = -ENOMEM; + goto err_group; + } + mutex_init(&mdev->dev.iommu->lock); + mdev->dev.iommu->iommu_dev = &mock_iommu_device; + + rc = device_add(&mdev->dev); + if (rc) + goto err_dev_iommu; + + rc = iommu_group_add_device(iommu_group, &mdev->dev); + if (rc) + goto err_del; + iommu_group_put(iommu_group); + return mdev; + +err_del: + device_del(&mdev->dev); +err_dev_iommu: + kfree(mdev->dev.iommu); + mdev->dev.iommu = NULL; +err_group: + iommu_group_put(iommu_group); +err_put: + put_device(&mdev->dev); + return ERR_PTR(rc); +} + +static void mock_dev_destroy(struct mock_dev *mdev) +{ + iommu_group_remove_device(&mdev->dev); + device_del(&mdev->dev); + kfree(mdev->dev.iommu); + mdev->dev.iommu = NULL; + put_device(&mdev->dev); +} + +bool iommufd_selftest_is_mock_dev(struct device *dev) +{ + return dev->release == mock_dev_release; +} + /* Create an hw_pagetable with the mock domain so we can test the domain ops */ static int iommufd_test_mock_domain(struct iommufd_ucmd *ucmd, struct iommu_test_cmd *cmd) { - static struct bus_type mock_bus = { .iommu_ops = &mock_ops }; - struct iommufd_hw_pagetable *hwpt; + struct iommufd_device *idev; struct selftest_obj *sobj; - struct iommufd_ioas *ioas; + u32 pt_id = cmd->id; + u32 idev_id; int rc; - ioas = iommufd_get_ioas(ucmd, cmd->id); - if (IS_ERR(ioas)) - return PTR_ERR(ioas); - sobj = iommufd_object_alloc(ucmd->ictx, sobj, IOMMUFD_OBJ_SELFTEST); - if (IS_ERR(sobj)) { - rc = PTR_ERR(sobj); - goto out_ioas; - } + if (IS_ERR(sobj)) + return PTR_ERR(sobj); + sobj->idev.ictx = ucmd->ictx; sobj->type = TYPE_IDEV; - sobj->idev.mock_dev.bus = &mock_bus; - hwpt = iommufd_device_selftest_attach(ucmd->ictx, ioas, - &sobj->idev.mock_dev); - if (IS_ERR(hwpt)) { - rc = PTR_ERR(hwpt); + sobj->idev.mock_dev = mock_dev_create(); + if (IS_ERR(sobj->idev.mock_dev)) { + rc = PTR_ERR(sobj->idev.mock_dev); goto out_sobj; } - sobj->idev.hwpt = hwpt; - /* Userspace must destroy both of these IDs to destroy the object */ - cmd->mock_domain.out_hwpt_id = hwpt->obj.id; + idev = iommufd_device_bind(ucmd->ictx, &sobj->idev.mock_dev->dev, + &idev_id); + if (IS_ERR(idev)) { + rc = PTR_ERR(idev); + goto out_mdev; + } + sobj->idev.idev = idev; + + rc = iommufd_device_attach(idev, &pt_id); + if (rc) + goto out_unbind; + + /* Userspace must destroy the device_id to destroy the object */ + cmd->mock_domain.out_hwpt_id = pt_id; cmd->mock_domain.out_stdev_id = sobj->obj.id; iommufd_object_finalize(ucmd->ictx, &sobj->obj); - iommufd_put_object(&ioas->obj); return iommufd_ucmd_respond(ucmd, sizeof(*cmd)); +out_unbind: + iommufd_device_unbind(idev); +out_mdev: + mock_dev_destroy(sobj->idev.mock_dev); out_sobj: iommufd_object_abort(ucmd->ictx, &sobj->obj); -out_ioas: - iommufd_put_object(&ioas->obj); return rc; } @@ -780,8 +921,9 @@ void iommufd_selftest_destroy(struct iommufd_object *obj) switch (sobj->type) { case TYPE_IDEV: - iommufd_device_selftest_detach(sobj->idev.ictx, - sobj->idev.hwpt); + iommufd_device_detach(sobj->idev.idev); + iommufd_device_unbind(sobj->idev.idev); + mock_dev_destroy(sobj->idev.mock_dev); break; } } @@ -845,9 +987,11 @@ void __init iommufd_test_init(void) { dbgfs_root = fault_create_debugfs_attr("fail_iommufd", NULL, &fail_iommufd); + WARN_ON(bus_register(&iommufd_mock_bus_type)); } void iommufd_test_exit(void) { debugfs_remove_recursive(dbgfs_root); + bus_unregister(&iommufd_mock_bus_type); } diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c index a9b232c281c02f..113dab3a0cd631 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -645,7 +645,6 @@ TEST_F(iommufd_ioas, access_pin) &check_map_cmd)); test_ioctl_destroy(mock_stdev_id); - test_ioctl_destroy(mock_hwpt_id); test_cmd_destroy_access_pages( access_cmd.id, access_cmd.access_pages.out_access_pages_id); @@ -1214,7 +1213,6 @@ TEST_F(iommufd_mock_domain, all_aligns_copy) 1); test_ioctl_destroy(mock_stdev_id); - test_ioctl_destroy(self->hwpt_ids[1]); self->hwpt_ids[1] = old_id; test_ioctl_ioas_unmap(iova, length); diff --git a/tools/testing/selftests/iommu/iommufd_fail_nth.c b/tools/testing/selftests/iommu/iommufd_fail_nth.c index e7d535680721b2..d9afcb23810e1a 100644 --- a/tools/testing/selftests/iommu/iommufd_fail_nth.c +++ b/tools/testing/selftests/iommu/iommufd_fail_nth.c @@ -323,8 +323,6 @@ TEST_FAIL_NTH(basic_fail_nth, map_domain) if (_test_ioctl_destroy(self->fd, stdev_id)) return -1; - if (_test_ioctl_destroy(self->fd, hwpt_id)) - return -1; if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id, &hwpt_id)) return -1; @@ -365,13 +363,9 @@ TEST_FAIL_NTH(basic_fail_nth, map_two_domains) if (_test_ioctl_destroy(self->fd, stdev_id)) return -1; - if (_test_ioctl_destroy(self->fd, hwpt_id)) - return -1; if (_test_ioctl_destroy(self->fd, stdev_id2)) return -1; - if (_test_ioctl_destroy(self->fd, hwpt_id2)) - return -1; if (_test_cmd_mock_domain(self->fd, ioas_id, &stdev_id, &hwpt_id)) return -1; @@ -572,8 +566,6 @@ TEST_FAIL_NTH(basic_fail_nth, access_pin_domain) if (_test_ioctl_destroy(self->fd, stdev_id)) return -1; - if (_test_ioctl_destroy(self->fd, hwpt_id)) - return -1; return 0; } From patchwork Wed Mar 1 19:30:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13156360 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 4583CC7EE23 for ; Wed, 1 Mar 2023 19:30:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229563AbjCATam (ORCPT ); Wed, 1 Mar 2023 14:30:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229586AbjCATak (ORCPT ); Wed, 1 Mar 2023 14:30:40 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2062.outbound.protection.outlook.com [40.107.93.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 369FB5FCC for ; Wed, 1 Mar 2023 11:30:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RlQOIqG0qZDTkj5s3XCrU52lWbypxfUCtjkjguuSYNQ++kdq+YfhyNH8pjCDapz2UHYyiQq9vMYxTONOQ+hotdClmecfQtCudT6nsM/iSUQ68HfmDpmZ723vGvOSki6Can3KCSF4Z4NHZYNoOX6pNyHu/UTMWpjuvMgnagnHWypriedD+x3jP7dWS9Xs5TVwRalQ8L9eMa0DpGNDzAs4kR54K0pnajT0aMiBkCT5o+KG8jlO8Zo9ezCNKblGOleMB+WZL/pdcYds/D7oZO+18ZstGU7xOFTfUCkMBpUtHfYKmPV9xrPaI+pp05TfDA3bPkXiM+UuHVWImpgDyFseoQ== 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=KzH44awttjEIYFB/9CCa7a822Kp/hPgtX2vkljezwKg=; b=jBo+cK5KESo5UUusXArgZS03o99imeBSuGU7iVetxrNajCbA4l8NYKZqNaZHR4Z1Lhzhbr2Uhw9IQ2Vil9iXeFkToCAhBoaimf6P8ZYdJRxEWtuTRT5aRPN8HRP2H8neMUl2KnOcQswpSnHtxJ9pwGr1J9+G1tr0jTJsd7Ua5pRsb2o32YT8TK3l3MKMuyIYEFm18H5SpmgVLmtSBQxsVi4FlMLPE/SoYZBgHSdR5fhGwuFX3fI4GuYvHegaosjfx+XcaTdrwjaKKQu6ApXcx7gjTRHj8IaYY+2ozSTv+qpOjD7xG69EUTDr1UrkEMJOmCI8nCRHVAr6th3gwhD1+Q== 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=KzH44awttjEIYFB/9CCa7a822Kp/hPgtX2vkljezwKg=; b=pWjo0dPa9bKMGO/X4359SANEYJAVRUZGfFR5hfSnTOqdVER3C1svTLGsHGhASOudPE16xv2dBlc4y1lGVuasCAFDpePixvCR5YLHKJ01L2sHZHojtmZ3Fif4FtcsxEkqUxOnFWAQ4vGa6Fp7ERf8Gga0Kgz54a7RPodYMXpG90BlFuX4EBV9dzX419wQLrEgbJU78TL41YByAxzNqhNFCUeXR3FRHVXTHrmOMoAaNlvtg3xIka5fy1ITvrw0DS1B08XVp+SGtDufOCv2WrH9z+A/1H+tLoJFq3jFtWM62VEY8XBF1hYPXNJjYuYqo1Ghb26I9hWjYjKTdsS8YJMjHw== 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 IA0PR12MB8086.namprd12.prod.outlook.com (2603:10b6:208:403::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.30; Wed, 1 Mar 2023 19:30:35 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3cb3:2fce:5c8f:82ee]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3cb3:2fce:5c8f:82ee%4]) with mapi id 15.20.6134.029; Wed, 1 Mar 2023 19:30:35 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Kevin Tian , linux-kselftest@vger.kernel.org, Shuah Khan Cc: Nicolin Chen , Yi Liu Subject: [PATCH v3 12/12] iommufd/selftest: Add a selftest for iommufd_device_attach() with a hwpt argument Date: Wed, 1 Mar 2023 15:30:29 -0400 Message-Id: <12-v3-ae9c2975a131+2e1e8-iommufd_hwpt_jgg@nvidia.com> In-Reply-To: <0-v3-ae9c2975a131+2e1e8-iommufd_hwpt_jgg@nvidia.com> References: X-ClientProxiedBy: YT4PR01CA0053.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:111::20) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|IA0PR12MB8086:EE_ X-MS-Office365-Filtering-Correlation-Id: dd099b2d-49d4-4cd3-45b7-08db1a8b6cb6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ukS+p4U3YvRJ7tM/V+AyeNR9H509udbfu9pZDJxi1z3RQOxnT0E4sLA2K3JuhjctYxUvZ4zqhlzzvgJ7DkVHI8i3knWjk66pj71WSvpgp4dy/1lXy4IFPF+fFjw9Xv+Jl8MiIbAEJeD5gf2+y8OFEH8szt1V7aZ0IFc/CDsz9hLeBJlXKnU8zbl5VdqssyDwMrRiNpdM/oLk4ynUek+/fziXpTNk1xb0XeEeoG69zdEMFKsQv3a3LnjUKq2WyYylXfigTBEcHZzvQlTXZnVwYFIGSTMw41Sy9IYACcdh5WrqwNonT+3z1FtdhYqvPxd2xAWSsvWsEK4tJehvj3yksGlvJGR5bHRWIYQzx6av/svfogYJjW2UGxPgr7tZ2VjUN8EyTMwpM7P7R3pf108dT5yPHoa00sgx43xYVN/kvBvo9pCSc/01Iky0F/VvhZ0RNGvKgbiqJDMP3NCOEyfMgV2KIdTobKOFLV0hGulWT8jW2+1S8T0AmPRzMYDv6PwpS2Vw/l+o72yMP/NDm94LJ9KdAX/V/ktAYigFZNi63FtCs9FUxeitfuN34prBwbYn6RHCrgWw8EqFT7eyRdVROXUkaAK5WcFwP3JYv+7cGc/10Ckh8OtkizYP1f8+ejoR4t14FJIRDGZZQntSFNTl6A== 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)(396003)(376002)(346002)(366004)(39860400002)(136003)(451199018)(186003)(2906002)(6512007)(5660300002)(38100700002)(26005)(6506007)(8936002)(4326008)(6486002)(41300700001)(86362001)(2616005)(8676002)(66946007)(66556008)(66476007)(6666004)(110136005)(36756003)(54906003)(83380400001)(316002)(478600001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: So4hTuD/E9/jrk84Eld6j7fVt8rjDTZiPu15aFn1wpUQI3fy8OJGVZUqcDnC5IfkKVH4JfkPfJFKFLFYYFGdqNxwMyUt+biXUm6HZyuNBcxr8gE3TIxN8j75G57x2jdVSWnTjgounWlDkFql140oguod2kNx7te/p0L5e3HYn04ydlG9tfO7lGOCRptJFIq3CLW2UbVtd1kBa8m6vsxFogBdxQOC5yPogBgUnRRWtepbRU2c86hgn0Irdx1prhNu712hDipCSMPd/WrF0JLS5DPfi9YVD27V1sEbdaH1Eap+rVi4e2nFDi6B43cVjng2v3o22L0+NBW5kIIR1FWMjXzZ4Tinfc5u2aN4OrZWJ0DVb0+tYdixgFx2fkV6LAaY6F3uVdNRQ4TrPoTzlhkOc+PGc5tOnBSLO1KFZ85Vokt+RHWHL4cmaWWEZ9YN9JtWpakVXwUvUvxG8+1sXP6UeXljYAxif72eqp2kPKkFUYyOvuYXnIJxCZyKYTIMg7kPYtc0xwUCdhPbF3Iz7cbAnTRi/jeEFVmGG/4hevJvl8539Ei9E57MU5NgV4beB9BFGC5ERiCEUqWHw/td8WMzt7UcrYESgAttKZX+h1P6e+NLh9OlVbnQbQfQDVYXGuks9MRLm8znXdUIC3iLoyVxyfuXV9wMFdWO03wlWYNR4DNM8r55klqS8EvYeMaRqvcWhRo8W4JlILEovnGUd4yeDQgNI384/8pvlesAHaCtdEbF3g4aJTsrm3dtV78XP6440wdv2giCuhlGCPyC1uJEzpFZlrAZNmZU8i8nXLFD3lLLl6nfuQ05Nj7rDbQTntVkwkmEKKDoykVNeKSTpIhLqFdTiZeeN5rC9TgOfsnzbpdPzBFXvfZg/b/wNeOMLft0PDsfnObX1SrfwLUyFGp8lWV68BBdMn+I4kKPXEqaQfeqdjDpjVEcShnkHLA0sMaAacantDz0Caori+wgy3I9oJWQXGwfv1qVrgk9pl1dvVFsZNhGNyWVkkBM0PvZaiKGGOxwgQwYbhoeUGN2kAvS4Q1i0QiMaoFDdAqke6oDxitARi2qAYnLSoubFeiVORS9DhycCr6Kto7KDLVTsNC7cvhRtNSs4qavPgtzpeZRFrvpknO+o5jL/rFUE8VlevtG1PS6n5VNeRfiGfNnYLQGzsc5weTbLPPoli04NFs8hBLwbJHfSkhe6pkMD7wB2i2EThBgwKcFMgD6Ay8pGks3OLD85jm9KaEIeqxndgIXroPgMug9wOyr89iVqGYAh+0yBE/ii8sayx01CbNUNh8y88x/gQUMXuO0R+Tp5QDIRsbeDPVHpjOhwKxImSYeKD0FElUUoIywnqEzn0i8udmAPqulFtWXK+pNyF21vR8TQRrC2MnZadP0F5B71jR2VBBAWVINdk/igEMD/VHMCivX/q42DBAdz2z0hvMLrLEWBi0sHM1GF+S6RCZbfgPl1+pNOM7jlQC92n8pKGFy17BNt1mNfh4Ti8vIW+P9dYav5wLqtu/4HYCm1syoHPCKFER23EuAhGpoODgYjFVkQTO5JUV/QK2pOlKAH+nRcg3Rsk8OeMSVNkQMIc88sONdt17L X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: dd099b2d-49d4-4cd3-45b7-08db1a8b6cb6 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2023 19:30:33.0655 (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: czV+sAYL1/d6JXrw8OSxnkVyWYE/Mic47RkF1nSM4pE3MP3g0jgV1Vq4MvDCBPRq X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8086 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org This can now be covered since we have a full struct device. Signed-off-by: Jason Gunthorpe Reviewed-by: Kevin Tian --- tools/testing/selftests/iommu/iommufd.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c index 113dab3a0cd631..7aec1d5386d9bf 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -187,6 +187,7 @@ FIXTURE(iommufd_ioas) int fd; uint32_t ioas_id; uint32_t stdev_id; + uint32_t hwpt_id; uint64_t base_iova; }; @@ -212,7 +213,8 @@ FIXTURE_SETUP(iommufd_ioas) } for (i = 0; i != variant->mock_domains; i++) { - test_cmd_mock_domain(self->ioas_id, &self->stdev_id, NULL); + test_cmd_mock_domain(self->ioas_id, &self->stdev_id, + &self->hwpt_id); self->base_iova = MOCK_APERTURE_START; } } @@ -259,6 +261,16 @@ TEST_F(iommufd_ioas, ioas_destroy) } } +TEST_F(iommufd_ioas, hwpt_attach) +{ + /* Create a device attached directly to a hwpt */ + if (self->stdev_id) { + test_cmd_mock_domain(self->hwpt_id, NULL, NULL); + } else { + test_err_mock_domain(ENOENT, self->hwpt_id, NULL, NULL); + } +} + TEST_F(iommufd_ioas, ioas_area_destroy) { /* Adding an area does not change ability to destroy */