From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6249BCCD193 for ; Mon, 20 Oct 2025 16:28:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1ZL0Tbgb/zBW0F3CBgkUdYl404rg0JHEnhVQKYu2z8A=; b=YmalmgA0fyNCyh HS/cpcmsN1+Fd32ZN5m0ghaz69k/fApiqYS3J13UgfiaOQqFzCk1KhO1lmYSRXGEgIYMxSX98OUEH 16u7VA8p4Y3xkDWYIBfYt3I+CJa2cEBwo0oyxOV+6Sq/P8rvuuryZ4XQAgYAU0u5gniBdcwVsnY54 tkV5rjOtivY6FXZDjk42J/FSCAa9Mivf8f58GCRcJkY6wOu0KfnMXJbEksFq4YR395ZEGVirj4XH2 zMg3nJUX3bzRAoDkNHksL24Iowq5xwIArbPFlpDiGdTYbXp9JHS6KwV7iPHp8ouNFsFRZKLRmxbaL FuEBijIu3Kthl90euFyA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vAsjp-0000000EIrh-340U; Mon, 20 Oct 2025 16:28:01 +0000 Received: from mail-westusazon11012064.outbound.protection.outlook.com ([52.101.43.64] helo=SJ2PR03CU001.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vAsjl-0000000EIp8-1vAt; Mon, 20 Oct 2025 16:27:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=OJaaWin26By2w1D1mbMv6hfAqRbKY8Uh4+EGBqrLidpZILzA25gXAk1l2CxtZHZLS8EbT2rFbo8jBLA23cJUR7uJF+hAs7j6VGXiYdGepHywZ834UeF7AnyfE83SonQEEw8Yf45/QgyKm7P7UJe49dQgEQBd19xo8H8etfZRAOAGQ4BsRnBzCiQ3kCGVQ5gAg/nPFXmL6xaeCFE6vs3yeHQtAtUcGruYARulSQVsP/FRzaOUDOewTJcQS/kb2V+xlSg8hW4Sm3RnkiDI/6oLDFlOYrdE7gVUbWJFN7iGXw18TIn+TLT3Q3n6sD9ItSLmemHEQWAcQBkECuWKOgJ4jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=ZCI2fysfQw4vTLfosKtDgdFQ/XeP5lvETNUUOuL9I3w=; b=XNP+upAZVZ7qAykep+sUaX5CldYxfp0FWsxTkJNSyrwo+HV2Yptjeo8Zb2kc/0lP8LoNNVX4Im/dPUSOq4FWAk2Y5F1Zk0H44W9ZpwL9LbKWLaIUm0KxFgMyyUqKzo0jwny1mHvTd/2jRhKcETpMpIT/DJZqAlwzDSAHrcv9QE3RkrUNrVfqsjImOwh//RGsjfexuoksfVK11GH7NTKC+WEc/t+SfGfAzkR/ngJ3CF8VdZ7aUj/rp6rDmFox9CW7CEHSdAXMO0gJoMow/tBeeOEl09CwbyHxdl8UVB5Fyxg7tsJ1J+cj7lPReQfrWsvTeyAS5TQdcQLCkgKuXqye8w== 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=ZCI2fysfQw4vTLfosKtDgdFQ/XeP5lvETNUUOuL9I3w=; b=iwFMcVH2hFMGaLbttDSJB/lH2Gl5CKcgskbPO6x2bSawsq96RRwQYqkz0sDzQtknvhxrBpW/YSazsJBWHrbRpJCUFCvAz5S0MknLH1uRwA1duMJ1tf2ZWFh9Er7eS6OsIlQPc7kXnb4mQgGuQACOC0oexO4zG9WQmkz9RzC9EqMheSjWEKFqQ/eI3C8Q3eWsNR+5yrYBMJIL7R0ySJrMPxKBWTfbq8CWgY2PtBR8x4tc7in/icLjPvPDp5JFTQyRAFzEfjKlXMOFzVmhWXKEiXXmHv0T8apT61j+zt+95boNEY+eTOshYK3P+lrauVO2xUhvdljB3KA2gv9g4+cA4g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from MN2PR12MB3613.namprd12.prod.outlook.com (2603:10b6:208:c1::17) by DS4PR12MB9794.namprd12.prod.outlook.com (2603:10b6:8:2a7::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9228.16; Mon, 20 Oct 2025 16:27:37 +0000 Received: from MN2PR12MB3613.namprd12.prod.outlook.com ([fe80::1b3b:64f5:9211:608b]) by MN2PR12MB3613.namprd12.prod.outlook.com ([fe80::1b3b:64f5:9211:608b%4]) with mapi id 15.20.9228.015; Mon, 20 Oct 2025 16:27:37 +0000 Date: Mon, 20 Oct 2025 13:27:36 -0300 From: Jason Gunthorpe To: Nicolin Chen Cc: joro@8bytes.org, kevin.tian@intel.com, suravee.suthikulpanit@amd.com, will@kernel.org, robin.murphy@arm.com, sven@kernel.org, j@jannau.net, jean-philippe@linaro.org, robin.clark@oss.qualcomm.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, yong.wu@mediatek.com, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, tjeznach@rivosinc.com, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, heiko@sntech.de, schnelle@linux.ibm.com, mjrosato@linux.ibm.com, wens@csie.org, jernej.skrabec@gmail.com, samuel@sholland.org, thierry.reding@gmail.com, jonathanh@nvidia.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-riscv@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, virtualization@lists.linux.dev, patches@lists.linux.dev Subject: Re: [PATCH v1 02/20] iommu: Introduce a test_dev domain op and an internal helper Message-ID: <20251020162736.GW316284@nvidia.com> References: <32ce256a2ece5d63e99d5858f953586859818ffc.1760312725.git.nicolinc@nvidia.com> Content-Disposition: inline In-Reply-To: <32ce256a2ece5d63e99d5858f953586859818ffc.1760312725.git.nicolinc@nvidia.com> X-ClientProxiedBy: MN0P223CA0013.NAMP223.PROD.OUTLOOK.COM (2603:10b6:208:52b::15) To MN2PR12MB3613.namprd12.prod.outlook.com (2603:10b6:208:c1::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR12MB3613:EE_|DS4PR12MB9794:EE_ X-MS-Office365-Filtering-Correlation-Id: af5b0ee5-6490-4ab5-ee25-08de0ff594df X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?tYiImuhGeOvt6zVjD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vS2/urPwh?= =?us-ascii?Q?fhpx8gXnLFqnVLmkTkr8mrq+6r+KRmvrqcO1e0lJE3Qc9Ozy1T5AsSIqtQfC?= =?us-ascii?Q?3ohTEE2nyxkslcP6ba2rXqdXjFbCUcAUU8unRkL+HHGzeoA3fZcBw2loNuAJ?= =?us-ascii?Q?nn3tGiPooo6dB5i9URIgzW8oTmK7YZnAGJPu1LLj5+iaBf59bZe3+fSIhBF0?= =?us-ascii?Q?J52Dxsv2gQvkL/Wilu9IDtWCGAuMBFdQpoHiiq/+lliJ9Pw36PIrSE5pwCol?= =?us-ascii?Q?WmJt4M3aOuQtEE3bcT/2s8dSnvtZKGZRwn3CKb8/7ggcMOSJCbak1xKPbvf2?= =?us-ascii?Q?EAIazuRf0pqrsXGUoN+cpffAwUi1LzfI1sRQsFLO5zPzA2U+xwTSTlx7ijqh?= =?us-ascii?Q?6So1gcLd707EGOuU1+KGXczrsq1MxtN/+RU/fGUYC2jHnYn6DZCXzKSOlPrU?= =?us-ascii?Q?cYMnc6N8G+U/Dsip9O9dj1dq4VvLQXT0hTp5BSl2A5n191PYHg4f+yYC/o23?= =?us-ascii?Q?JQCM8PunXW9JzPTJVKXugBKJe+lsrcwazJylib+3Dzs/OBoH/AbuHkvq8lkL?= =?us-ascii?Q?vkfmu5uAi6FX5t+tBvIRnueEF4TCyF41?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR12MB3613.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?CeHosNkGyQoRNL5gKjF+EVnIbbRnRaOmuCTURBOzNVFRUszuASeqcnfhx7Tu?= =?us-ascii?Q?byu1xpZgtXWw6GJ8QWk3Ieb8VJeGJszqH6CxUXUdqX2J+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rSF6U3p0I3Xq7gjGJ+2a2Z0hidr2bk0w7b28bT4l4MqaLtD8I9Wi5?= =?us-ascii?Q?1sFH8bj6H2Rv3h5otCjPT6A8UCCKflXJEutydoHReWVeDgJYWDypqQQ8DVw5?= =?us-ascii?Q?UtCRs7WT3bX56sonnQNeqIkMqOI0yGxg2SlQMJOoECnKg3QvsxIF7nbhNbjN?= =?us-ascii?Q?ZBzSb5p6W00D4RgoGHceAjMVmoCsoTD9ock6EfqQdYfnD4B8gxBFG1JK5X/Q?= =?us-ascii?Q?tQGLfHxzFFGRgw/PDrgr9PVm8H693Q7wH1o2KKIDEdmAMGZtlPG88Iq2eIfu?= =?us-ascii?Q?5kEbLpzpncJTmvjOmwwJFBmEAVsTFKKqF3KA9a0SyFmdQOF3F08mmgqA6KKy?= =?us-ascii?Q?HMOBKtPqJbtUWfN3NCxu6ME2Q6svZBcxUnsAN47V1V1p1jp4Pb3MK2s45Nf9?= =?us-ascii?Q?umF3RuI+F5+DnqSuVsiH0mo2J3SEayEnchZHxNBehEhc770xLebH54lJdkR+?= =?us-ascii?Q?uNy151ihMlvYVBRZuqCEKv6gtOe6mFitdy/tp4cMOnlwuW4WbdMTui/Olitj?= =?us-ascii?Q?y65ssYbT8Pm2CscsjW6HzliqL8eX4mr5AcopwHjSdXCYeOsmVEpBAQMUMng2?= =?us-ascii?Q?X20OXCiTmWkFgv57aZ1fOf8uAMhYlWbJoyTcYqjS?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: af5b0ee5-6490-4ab5-ee25-08de0ff594df X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB3613.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Oct 2025 16:27:37.4480 (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: 9epYrVHT03u4Yl9aaZICDSYPZrolT0OyGQEXguCil3RKJhEWWjSxNzVjE6kQi4nw X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS4PR12MB9794 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251020_092757_491956_8BF17BB0 X-CRM114-Status: GOOD ( 23.65 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org On Sun, Oct 12, 2025 at 05:04:59PM -0700, Nicolin Chen wrote: > And keep them within the group->mutex, so drivers can simply move all the > sanity and compatibility tests from their attach_dev callbacks to the new > test_dev callbacks without concerning about a race condition. I'm not sure about this.. For the problem we are trying to solve this would be racy as the test would be done and the group mutex unlocked. Then later it will be re-tested and attached. > /** > * struct iommu_domain_ops - domain specific operations > - * @attach_dev: attach an iommu domain to a device > + * @test_dev: Test compatibility prior to an @attach_dev or @set_dev_pasid call. > + * A driver-level callback of this op should do a thorough sanity, to > + * make sure a device is compatible with the domain. So the following > + * @attach_dev and @set_dev_pasid functions would likely succeed with > + * only one exception due to a temporary failure like out of memory. > + * It's suggested to avoid the kernel prints in this op. This is a general rule, even normal attach should be following it or iommufd will be spamming the log. > * Return: > * * 0 - success > * * EINVAL - can indicate that device and domain are incompatible due to > @@ -722,11 +727,15 @@ struct iommu_ops { > * driver shouldn't log an error, since it is legitimate for a > * caller to test reuse of existing domains. Otherwise, it may > * still represent some other fundamental problem > - * * ENOMEM - out of memory > - * * ENOSPC - non-ENOMEM type of resource allocation failures > * * EBUSY - device is attached to a domain and cannot be changed > * * ENODEV - device specific errors, not able to be attached > * * - treated as ENODEV by the caller. Use is discouraged > + * @attach_dev: attach an iommu domain to a device > + * Return: > + * * 0 - success > + * * ENOMEM - out of memory > + * * ENOSPC - non-ENOMEM type of resource allocation failures > + * * - Use is discouraged > * @set_dev_pasid: set or replace an iommu domain to a pasid of device. The pasid of > * the device should be left in the old config in error case. > * @map_pages: map a physically contiguous set of pages of the same size to > @@ -751,6 +760,8 @@ struct iommu_ops { > * @free: Release the domain after use. > */ > struct iommu_domain_ops { > + int (*test_dev)(struct iommu_domain *domain, struct device *dev, > + ioasid_t pasid, struct iommu_domain *old); Because of the starting remark I'm skeptical that old should be included here. The rest looks OK Jason _______________________________________________ Linux-rockchip mailing list Linux-rockchip@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-rockchip