From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.201.48 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1793110387; b=UZRcoU08X69hbQ5YK1hfbiCHVhXITxa9IO6y6luB2UtufArizGU/wb+fHHRBMnk2ptXF mZim70AyyPYcqhZbud76vkaBSsaUesJ8BWpfYO9myxeJvb8IXLFkqVcf43rbKU8sFyUTM jTEzwB6Ta0QoPkCgT1QNNRl/qRKBV8rZvDio2b//z3vhFeoodUJB/m1WpRQH08YRhlRzb k/VBbjDVF3UvN4Oq4CJfwfA9tdQH6RSPe0jU6Dqon4xS+jj5jFyI16oAEujBkgwMZRDAH t6LyAGL44Rv3g8jF/w3HgsAdWOhO34Vn/rAQu0K4GvnKrFffOBUEkTlPP8KZrCxu/wg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793110387; h=DMARC-Filter:DKIM-Signature:Received:Received:Date:From:To:Cc: Subject:Message-ID:References:Content-Type:Content-Disposition: In-Reply-To:X-ClientProxiedBy:MIME-Version:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=m252L1yGfPzKK9vRZFfuJTcivjrY7diGrC57vJPHvmE=; b=tf2OrhcPdWB0ST1ON7+hhUQ6pcZJzqhsAjZh1GDZK/o5JG3y5/tJjN7xqNMHrqeGMQY/ cVT9GWAyPL3Diue+uXp59pIw6irtOz6M2Rol5Ib985XbJ8weQdXbiFm2q4eaLL45lCaCJ akUDgDYsGzXqUEaJ1z0Vqciuo4lSs2hu1D0+zFy9h12N5WB460HuZQCk9d5EKGQz59oDZ GTH07IA9Tx9ldvENRLXZiZ7tmTL/+CtL2mhSmvKJM8JmqIEb2ghGD1Zr+3w0XYF7U9AzG 9kUf1LNnWxyyRZUF4OJZFaJzd5pEAjQZHDeZfB3y1LpgNAJiAYKOI88Zr0QrQUgMRpg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=QWk1k0xb; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.201.48 Received: from CY3PR05CU001.outbound.protection.outlook.com (mail-westcentralusazon11013048.outbound.protection.outlook.com [40.93.201.48]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C83F606A31A for ; Tue, 27 Oct 2026 14:13:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9C83F606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=QWk1k0xb ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sY3bRVsb65/Qf7Rxs4iKJnFP1nIU7dZzJHnXLy2nrrcuzlmfbBWrb1Wj9wNND3uOB+toBoP8wju8DcqAYrK5STX264wyT4AeipuN8XpOB2VeEefIU37rP/DASR96Xb1DPibKLUwdNdLIE9dg2WcoPWJna8TLge2DEaj4iSO4q0BJFjxysKSlzNClZ26cwNeu49X8RPiubzuJOUw60HsXEo/puMvlGOWeE4c/tJFUDR3azxeTodJxaPzcpwa92ffQZxk6gPH5hryvhokMptgDz89z8GK5S4uRnaucTkHmI33hCI4pB9EZ5I+DUJSp48KQrvLOhXSjcmpwZ33QMlUeFw== 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=m252L1yGfPzKK9vRZFfuJTcivjrY7diGrC57vJPHvmE=; b=XEHJqWTlcfkgiutib6VOFXWWQrGlv7r2ox7DvYba2Dv2IuKA+csey6HmTkXHbJBLHt+ilCVmYfAMiwxjqVLL5GOLj/pgvIqXPkPS8gdK9pu9nwcZO1GYeg8TcDpSsDzUcvf0+z41B1t29lWYSkepcuppBVuVjGOm5ae6Fz0c1M0UWmMa+iGazUmqG/gtT9AhJL/C2B2ran5kVuXU99M2XqdSsjrCB1gDVeu0gT3YsBx1kzz6264PwMUshbgIV3EC7ZgZ5yD0SBuGx7nYWbm1uiyiqMeXbvnRCX6UO0WiQfpYsve+4vKcZvS193YyJcLGD7i4O/SJfUZMvvS6u6mPrg== 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=m252L1yGfPzKK9vRZFfuJTcivjrY7diGrC57vJPHvmE=; b=QWk1k0xbILlR92dybMheV01ktYdWyoweetGK2huhPPii5Sw47/2l5t93JoVUASeXGX6jO697bIskLTw31uwxg7SHbS2fB32K+2HME366X7nLaFvqt189jF7u+FARnZs7KnxT7imtwvhW6LVzdH9DijbaqJasNV2ayEzKo0O1Ta+sz5i6tWk2QwM3KG9Wg8PBGS2IvpyAI9c27YRKIdNqHW6MKq0GLImZnQlKONVpN7AYvGDR7jLCAXBYs/ZAA7CP2CC+1GO/P+UylPCEFmD2DurkeHRwsVk8Ljs6a4VH1bMbGL2JviokPwgI9Ua/YyTQ4JbrA+1ukSC/5Vsy5VZNDw== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CHBPR12MB731189.namprd12.prod.outlook.com (2603:10b6:610:33d::12) by SJ2PR12MB7821.namprd12.prod.outlook.com (2603:10b6:a03:4d2::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.546.22; Tue, 27 Oct 2026 14:13:01 +0000 Received: from CHBPR12MB731189.namprd12.prod.outlook.com ([fe80::b0e5:123d:fe06:e10d]) by CHBPR12MB731189.namprd12.prod.outlook.com ([fe80::b0e5:123d:fe06:e10d%6]) with mapi id 15.21.0546.021; Tue, 27 Oct 2026 14:13:01 +0000 Date: Tue, 27 Oct 2026 11:13:00 -0300 From: Jason Gunthorpe To: fangyu.yu@linux.alibaba.com Cc: gong.shuai@sanechips.com.cn, alex@ghiti.fr, andrew.jones@oss.qualcomm.com, aou@eecs.berkeley.edu, gsh517025@gmail.com, guoren@kernel.org, iommu@lists.linux.dev, joro@8bytes.org, jroedel@suse.de, kvm-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, palmer@dabbelt.com, pjw@kernel.org, robin.murphy@arm.com, tomasz.jeznach@linux.dev, will@kernel.org, zong.li@sifive.com Subject: Re: [RFC PATCH v2 3/4] iommu/riscv: Add guest IMSIC GPA mapping helpers Message-ID: <20261027141300.GB2338330@nvidia.com> References: <20261026080604.184574-1-gong.shuai@sanechips.com.cn> <20261027140837.84112-1-fangyu.yu@linux.alibaba.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261027140837.84112-1-fangyu.yu@linux.alibaba.com> X-ClientProxiedBy: CH5P222CA0007.NAMP222.PROD.OUTLOOK.COM (2603:10b6:610:1ee::19) To CHBPR12MB731189.namprd12.prod.outlook.com (2603:10b6:610:33d::12) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CHBPR12MB731189:EE_|SJ2PR12MB7821:EE_ X-MS-Office365-Filtering-Correlation-Id: b0d87452-abdf-4a4f-af28-08df343468de X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|23010399003|1800799024|7416014|366016|11063799006|4143699003|56012099006|261022105027099003|261026121527099003|261026140227099003|10067099003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: nDOt8ZzMoIYW7+sbHfOYBK9jlcumDHq5iPvI3LX4kyvU1aaaK4SlKU7q6Auvw392motPJkRk5Jbyda0b3bxssiqLtLQzwUrH86tJMg38CrcKiZ2GHhZYiF7uSrzqcNI5l3YIO7juHTF5UCjs35/OXBXta4PQhaJ0xZlyyFn+A576mRQqWPkILusoP3TmR6Pcz79tDoKM52Ft6akG5hym9Y0t5fcPneRzZ8Ld5Tn+ESuu/UGXx5gfjCcjl4Oi8kiSFnkK1dOZJGUPzl1X1MOMTdWKxbKYzA4j/yWBpNw3++iyfC1eJa8U/qgrq3eqG+4dZS46YFlw0YYGssKEg9VnAZ0KuUv7E2gYvqBbhCcfkG5Dmt1pKhFghtRjY8tN3ZHxvvzUX8BbmxyH+CSoFHocaXcLr+20P1WbcJ9w3zOLozzGo2M1MZ5/wlyhdlPmEIbmJcbiJM8OevO2boyRAYJGkl1hPUtjWdMf8uhQr4gKa1FKaYb/2/LwGR2z5kSowAi7V0r0s5RQ9qwMVsdnqWoFCYeTiWiab/TKS896QYD3FTqeMQ/wlWEZCiO4gLdp1BT2Y9O5y8uIMTAafeCHEz2Ft/7O3UQiJs5PvvDtsz6SthsJRuQeNvX+H5AToBI021tI6Al8zmq82a5OMwt4L2aGy2u2b8YmdqKDrtVc3j24Wpk= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CHBPR12MB731189.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(23010399003)(1800799024)(7416014)(366016)(11063799006)(4143699003)(56012099006)(261022105027099003)(261026121527099003)(261026140227099003)(10067099003)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?+kWYzt4FHmycec37JSVXzEWk8HF5zoW8XbkLlUlPV2n6nTVT68U+51k3Xhfi?= =?us-ascii?Q?iNt540wzeau3I02WfiUw0FBfw4kn3NUJYBVRRKL5KMcmSpWKltgU2UGIH/wc?= =?us-ascii?Q?94+9sKByj1pdxw3Lq6xuUIT6xL4dve7NsCnXX3fyPQDtHxkMllqz95nCCNq1?= =?us-ascii?Q?BL6qLwI2k2a0RZ+Wo1eTgp/aeWLvvzThCitcva9P1WrrKAVtythwa+nM9+47?= =?us-ascii?Q?zRU5jCWwbj2ToJgYR/n4VF3cBfYlS8dLNcKWwM4IHpCnw4W3iDdLhWyea83Z?= =?us-ascii?Q?xDpvIK5j84MpfuX5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hh/Kz3B2k95ZQ?= =?us-ascii?Q?vYn+79VfMKG2vS69z0i4MCGXi5fh4atzByuqDwjBaC5EHHqZEU+pkthNxIlH?= =?us-ascii?Q?uDuH72wdQoJ2sIdxwWhGJW9NqmIhQaEH9r2CUUzEAnX6aPPNKD3obW4LAxUW?= =?us-ascii?Q?zKN6LAKQI9lq+c5y7rZyu3LUObYnfUCMRddsqWLJHVcMaltn01HXZWRZFHlF?= =?us-ascii?Q?bpI04XUhmZk6x1fAFqA2+XlgpHrHK8UfMENdci9+jEPPrHq+SnmRwfx3Cguz?= =?us-ascii?Q?A9ZMFLlchmst9zkwXqAUtB8Vt6mrgB2R70cC0hD0LSSagwEporwNCNUnyMwT?= =?us-ascii?Q?wwAbGUY3y2Z6zSGsGaCUbd0liiF87wj/CgxQhINX9NT/o2TBelFbom2zZV/z?= =?us-ascii?Q?nDlOzt8aguShXibQ5VbA+yaMIA60u6ZYTLvuVb4wN+QrQ3EZnn0BbYd04SlT?= =?us-ascii?Q?WPgcbowCD19ZabUs7lBtnwQG/9BkZYEPB0P47mhvFgM/mU91aEbfAyDOB3u2?= =?us-ascii?Q?/2XWgjQXQ77zu6eYXdafjN4TFKb3lo9MIbHfh6oKMoCZ4C4i?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b0d87452-abdf-4a4f-af28-08df343468de X-MS-Exchange-CrossTenant-AuthSource: CHBPR12MB731189.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2026 14:13:01.2990 (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: tj8jHnGveHY+6gD/LDX4QjikglwEYbqOe6RKIamtXrzkf1133pQRbSX6fRYhWUra X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB7821 On Tue, Oct 27, 2026 at 10:08:37PM +0800, fangyu.yu@linux.alibaba.com wrote: > >His concern seems to be about who owns and maintains these mappings. > >When the RISC-V IOMMU driver calls iommu_map directly on a paging > >domain managed by iommufd, the mappings are not visible to the domain > >owner. This makes it difficult to handle mapping lifetime and > >hardware page table replacement correctly. > > > > Hi Shuai, > > Thanks for the review. > > Before going further, I want to make sure I answer the actual > question. If the concern is about who owns and maintains these > mappings, I address that below. > > The iommu_map() and replace_leaf() calls are not a separate > mapping facility added next to the forwarding code. They are > two steps in the existing interrupt-forwarding state machine > driven from iommu-ir.c: > > - first FORWARD: flat -> MSIPTE written / > noflat -> S2 PTE installed > - UPDATE_TARGET: flat -> MSIPTE updated / > noflat -> replace_leaf() > (only if the VS-file page moved) > - last unforward: flat -> MSI table deactivated / > noflat -> S2 PTE removed > > So the lifetime of the S2 mapping matches the lifetime of the > forwarding session, which is the same rule the MSI page table > already follows. The driver is the only layer that sees both > the forwarding session (device <-> vCPU) and the paging domain > used to translate guest MSI writes, so it is also the only > layer that can maintain this mapping. > > Note that the noflat column of the last row is not in v2: v2 > only frees the bookkeeping when the domain is torn down. In > v3, I revoke the S2 entries both when the last forwarded IRQ > in the domain is released and at domain free, so the entry > lifetime becomes identical to the MSIPTE lifetime. The big point is interrupt code has to live in an irq_domain, not in the iommu driver, and the IOVA allocator is not part of either irq or iommu drivers. So you have to layer this properly if you are going to even attempt it. It sounds complicated. Jason