Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp3256235lqo; Tue, 21 May 2024 11:06:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWtj2jnwRPghjwtKbaQCBNmQWElDrjxdK8yD2QRoqWQr5xKVg/GaU+TzMEFboc1htUuJ7KgGTCJNZGu7uzrLsxv4Mtk2HKAATPAbi+4ug== X-Google-Smtp-Source: AGHT+IGYssMzIqfb5p+jinAhgE+HikHpU3mSqlngm4szog2lQhFLjc/lqM5g7E98aCdMPhU+v1cI X-Received: by 2002:a05:6102:c4a:b0:47b:9fd6:233b with SMTP id ada2fe7eead31-48077eae71cmr33380225137.31.1716314777135; Tue, 21 May 2024 11:06:17 -0700 (PDT) Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ada2fe7eead31-480789e1599si5337009137.251.2024.05.21.11.06.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 11:06:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-185306-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=XY4LxHbS; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-185306-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185306-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B69CA1C2153E for ; Tue, 21 May 2024 18:06:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7DB2A146D4C; Tue, 21 May 2024 18:06:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="XY4LxHbS" Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2064.outbound.protection.outlook.com [40.107.237.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A56423775; Tue, 21 May 2024 18:06:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.64 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716314769; cv=fail; b=iP8WNWaZfA/o6xkn7klILZ5zqBECMR3XrQ/PuYzkI1nJb/TwVtRX/5au1Rkq+DqCs/JT38zYz+gHAOlMjB7w/tWPmeTceysqylEPOx2/2fG78NnlIwMbXpjW7aNiSK9m1nck3a53KLSbK4GZOM9imxT9OaaqxyhwJF5sQcti+7M= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716314769; c=relaxed/simple; bh=lgLkjMHmvlmrYUtHvNjMIz/sTL/fRRrNmoKnjrtelFc=; h=Date:From:To:Cc:Subject:Message-ID:References:Content-Type: Content-Disposition:In-Reply-To:MIME-Version; b=DcYsoEec+HbWfJ1dwLUZsy16v+YiuuphozC2NGKtj+eYm+bVcIT6pAp3lMKTZ3b8jPHJgVLTFgEWOABSexJuNJ280RjA78sHGCGQpWC5oYtyqfgNbh8QpMLPIEYpMvfP588hO54B9ZmpX1+LLvXguUFUgR6dI2mJXw89wRaZAGA= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=XY4LxHbS; arc=fail smtp.client-ip=40.107.237.64 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 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BhcpOadtTEYB68NGjUVp//LDU1mV3BV0fFBLRIVEgtNrWBW2NmKMy518M78bISgUX45Q2PtOx6rsLVKVOmQpyVZ4FNlGhz1EAiKeHN4Ixp60gI17lvYULc8hahmHXIbP4VbE8P8XfkPkZXkJ3do99Tv1Me/oKOEqm6lj5J46Djm069LUyadQvangswwJ8VamR0xae7fP9ZTlKtVIGPv73JLB+YRntMWtbd7FjvsvYK0/947TrFcv8pgh1o3mq/2UIP+yna6m/isV95YbwO76Z5l5dvwbTrCm3GYj1VD63WEBfnEP34ncxztGey2OOk3lyKkQgmJWyGvn3xb1sti1EQ== 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=5QOd09pozZbiNHC3TBMpqrbSLHpKuyyBijKeCefCoCI=; b=FdAdQdzbNzWYbcCVc3TIrEVW1uAxd74xj49H10UlU1W9+2vKV6gIrrl9hs3HvzKwWTXSWaEEsAmWg3b9U9dCGhmEwnRwSRa9MYYS4QJQXthJ6K4+A+oBLAXSIqWgwa+FKGokmryMZjJhPzeirMVE+WmwLWFlxOIALCi3I7lbVZXme7cBIErM8Hxp/CRm1M9gQCI0Vt6ci4QkzTm/qvpfdimWY7/G2ilcLFURGlTYYo0MJLNTm+xK1ShKkbOAafyt1T9R8klbaGFHVsh5UE8IbHPxo4GNhQTRSulI0UD/Lhdsxwm0sxBPB9SskMv4x2G/JzAkuvl4uX2kuhs/2RxYJw== 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=5QOd09pozZbiNHC3TBMpqrbSLHpKuyyBijKeCefCoCI=; b=XY4LxHbSoZCYMhe3aam1P88Eg4MjdYO2C6HNNAJ1GgqZiOiztXFJNlwHx9APPKGJeLlDSmGzCrLZ5AxfSh9RooyNE5suYjTUy9f+F5QaIf8sN82jd6jeC0EdiTX4CtPGYqjiSie4UgUy8NrmleFqa7QC6KBy9VMjhtWkAECBsT6bN6LrF+YXtb5jx4bqmA0tXEnEVYMMxlc80O36efzgNoqCGR9EE2YOU6iGXBdg8W7/i+kKTrq0kaWuFGvDPHrJe2E7SKe8Qy9//P/6Ulb73p4HdYamHI9o7rBP6rah3tw1Fs9CDsIeio5KS1/82Od+jnOvYtqzSzZs8Q3YwIE2uA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BY5PR12MB3843.namprd12.prod.outlook.com (2603:10b6:a03:1a4::17) by PH8PR12MB7184.namprd12.prod.outlook.com (2603:10b6:510:227::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.35; Tue, 21 May 2024 18:05:59 +0000 Received: from BY5PR12MB3843.namprd12.prod.outlook.com ([fe80::efc8:672:884:fafe]) by BY5PR12MB3843.namprd12.prod.outlook.com ([fe80::efc8:672:884:fafe%4]) with mapi id 15.20.7587.035; Tue, 21 May 2024 18:05:58 +0000 Date: Tue, 21 May 2024 15:05:55 -0300 From: Jason Gunthorpe To: Nicolin Chen Cc: will@kernel.org, robin.murphy@arm.com, kevin.tian@intel.com, suravee.suthikulpanit@amd.com, joro@8bytes.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-tegra@vger.kernel.org, yi.l.liu@intel.com, eric.auger@redhat.com, vasant.hegde@amd.com, jon.grimm@amd.com, santosh.shukla@amd.com, Dhaval.Giani@amd.com, shameerali.kolothum.thodi@huawei.com Subject: Re: [PATCH RFCv1 05/14] iommufd: Add IOMMUFD_OBJ_VIOMMU and IOMMUFD_CMD_VIOMMU_ALLOC Message-ID: <20240521180555.GM20229@nvidia.com> References: <3aa9bc1df6a2ee58a03c6ea6ededbc210a2d23a8.1712978212.git.nicolinc@nvidia.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: MN2PR19CA0043.namprd19.prod.outlook.com (2603:10b6:208:19b::20) To BY5PR12MB3843.namprd12.prod.outlook.com (2603:10b6:a03:1a4::17) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BY5PR12MB3843:EE_|PH8PR12MB7184:EE_ X-MS-Office365-Filtering-Correlation-Id: 72ebb558-685b-4f1b-dd5e-08dc79c0aa98 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|366007|1800799015|376005; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?PV7uwjO2I7n0y2Dtt5GwKSVJYhR8GQXeVJXlt7tBQHVbM2e8+4T2/rIiCPxt?= =?us-ascii?Q?Hr7BcPZiZPo84bviTLL70vqBDKdUyQO4yfaHdH9nB0JCQPyHMqeGnWZSbuN4?= =?us-ascii?Q?O7sW/qvD7RQsMsXVXP0uh1VTLaIO7NSYScBr0iCo3V3a5P9MucJWf2z+P0KT?= =?us-ascii?Q?bfbnb1GcgIaKoNGjejTgNIIqIqS3zL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-ascii?Q?J9JTMg4Mz7vW3fpekS2z+FBOqT3Xq2LWUkfVF+ZKy46XUULqrfziqsbtq0kv?= =?us-ascii?Q?mX8BGG0tTgGR7saaZAqdSGZ4sdV+cllvrvbQCUd09qEN0kP4uDx+odpd2Jsi?= =?us-ascii?Q?cl6gunQzdmMMZtXDGOWS91+9SNVqo7ZHJk8Jjn/0B0Y3B4VvUHdMjiZ2o+3W?= =?us-ascii?Q?ScpOf1JjM6NpfK75Bjs8dN6dULP76pECk2p4rrOjzA=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR12MB3843.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(7416005)(366007)(1800799015)(376005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?acBHvC3IHsc99Bxde/IglpNJ4i7e7RBFQYfKOySthy6lRQ6fTvoWDx29R5vC?= =?us-ascii?Q?W948Q3Hs+srCu15iUwZxcsixC0PABSxoSRfT8r8Z8C/ae8Cnhlkn5ErXaMcI?= =?us-ascii?Q?XWdRrTzLN2sWxaWoCjeFPyvtAgPE3OZpfLWWLZ6P1Y/31Wes8sh34sZbAR10?= =?us-ascii?Q?37fdaRJzlymzQf38FIL1n3dWjaratBUSURv6w0Z6uls/qrHDT+/WnhoAjURn?= =?us-ascii?Q?/AYSG2ME3f7HtI4laeRNXs4zBmBOcAEkgkimYNaiJpkXnTEFwAG8WrWH+oxh?= =?us-ascii?Q?TYNjk9udSFVil4Nj2Q2U2w5b+0Go94KJ9gztW0Iw4woAmyWq+/CjTqpEdWxL?= =?us-ascii?Q?HPQe/29oJiAB2Z9viQYmg+tZixIa68F+3aX+T2Yj9BS7Zm7CsaAEAfK4Phkw?= =?us-ascii?Q?LRCtV8DXsSP6POOy4hDWVhMtpHGlsbgML6XxlCeBRV5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n/TbmwApzLDzGVS0SVoVyer9Q5fVbVHP+3Wbu2rC81IgCPDwFC2QFN?= =?us-ascii?Q?nwAU/XH3CYzHRx1WPzMHLM1BkqgdbNw67Iu/V2zjE5ghsb7BX8+Ax0uiQVrD?= =?us-ascii?Q?FKAgMPnpJT7NAEbAvNK7iVo2zY2S0kP/9rAIocdd36Md9oS6q6gJEbzKHQ0K?= =?us-ascii?Q?01XwHvRuE9GTDFkA3LjXVAicj6JEcZoLjR8Um33RFTimvWlCoXL1T+wmlJWJ?= =?us-ascii?Q?ARgvEylRBEVbsJgvODg=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 72ebb558-685b-4f1b-dd5e-08dc79c0aa98 X-MS-Exchange-CrossTenant-AuthSource: BY5PR12MB3843.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 May 2024 18:05:58.4008 (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: QH/9foUSZSIU7r3ROldXT/Et2C9/+lOyH9Ti4J+mqWySSXVJpnyPIa2t1QInn+tQ X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB7184 On Tue, May 14, 2024 at 06:20:06PM -0700, Nicolin Chen wrote: > > I suspect 0 should be reserved as a non-set value for some > > basic sanity in all these driver type enums. > > We have an IOMMU_HWPT_DATA_NONE for HWPT_ALLOC to compatible > with an S2 hwpt, since it doesn't need a data. > > Maybe we can have an IOMMU_VIOMMU_TYPE_DEFAULT to be 0, for > an IOMMU driver (e.g. VT-d) that doesn't need to handle nor > be aware of any viommu object? Seems like a good practice, and perhaps userspace will find value in a generic viommu object that is always present. > That makes a lot sense. I'd need to go through QEMU code and > see how we will accommodate these two more naturally: likely > the QEMU core should allocate an S2 HWPT for a VM, while the > viommu code should allocate a VIOMMU for each instance. I'd suggest that core qemu should allocate the S2 IOAS and pass that to the qemu viommu driver The qemu viommu driver should create the hwpt and then the viommu and perhaps return the viommu or hwpt back to the core code. If the vSTE flow above is used for identity then the qemu viommu driver would also have to go an create vSTEs for identity and attach them to all devices before the VM starts up. Then when the OS activates the SMMU it would have to mirror the real vSTE from guest memory to the kernel. Not sure there is value in having the core qemu code directly access the hwpt/viommu? Jason