Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp2783041lqo; Tue, 14 May 2024 09:01:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVxs3k2/Si3mu/mtk2Vbm5RrKz+rRSTywfDcSwJdM0y8b9buzvKaXOPHPxD/iI7bdwiNYHUN0iFQxo8E2Npojd1n8h8CEiFVa54Ndl3fw== X-Google-Smtp-Source: AGHT+IEe508ro/AH9L0KRIi9kkEUUrgIPhh0X7yE8YFdJZuzB2iPxVEYgbCG6lYMY0HsEXkWpTNA X-Received: by 2002:a17:902:f647:b0:1eb:3df4:e63b with SMTP id d9443c01a7336-1ef43c0958dmr213006395ad.7.1715702468013; Tue, 14 May 2024 09:01:08 -0700 (PDT) Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d9443c01a7336-1ef0bad7ffcsi111513825ad.142.2024.05.14.09.01.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 09:01:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-178888-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=FZuiVjXa; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-178888-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178888-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id A48A0285587 for ; Tue, 14 May 2024 15:53:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 938EA17F370; Tue, 14 May 2024 15:53:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="FZuiVjXa" Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2078.outbound.protection.outlook.com [40.107.93.78]) (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 D7FCF17EBA5; Tue, 14 May 2024 15:53:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.78 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715702011; cv=fail; b=uXwTP47h5+FXXols2ZdJjpymtir17Eijvsf3U4vLL9Fj1Gzk0xDx9m52AnGkT5/bnoxiT+jThrKVG6cmjZheV9E/Bz3stcPWmSWb9Zs0bFZGCikFCy5qpYk5nYdmeNq0fOQhMfX4X5l5wL1XD9oYmUVmQtZBTqeYTcU+lniXltU= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715702011; c=relaxed/simple; bh=7zRoEWUVU3mKwcYMr9VyLsDGQi+RQOUmlzXYl2bajTE=; h=Date:From:To:Cc:Subject:Message-ID:References:Content-Type: Content-Disposition:In-Reply-To:MIME-Version; b=jen+UCr08ZkC0F1aXyglRthNIXy414lZNjvkw2ZJuDWXZsnM7fZOxf45+H7xIEfAAtt4Jq6WzEDn6aZghkcHG62QBgCYM4Ofp7FYqeMCsnyGNQVyLSDotVjplJUIaFZNBQzoiFSoPOBw4VpeotaeUeF7p4a7kV02youPMlMCHyU= 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=FZuiVjXa; arc=fail smtp.client-ip=40.107.93.78 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=Z+m0yM/OQ/MlAqWeNazws7spAEJCHmJNMcUBcQPCiqJyyjBkJFD1QzCJPZmZYGNWDgfNPTc9EYwgQG/sm1AMcXOaK2dYK5gNZIwyXMwaUl1CupvEQTHrwRUSqL8Y4wb3i9DU787LM9bPTDkdTvxotQzXvYLV8ooD9qUkv7hvByByj0Cacu/Aop8P2a/eoV5EJ3bRlSG1v+hVqVQPRB9+v3TgWt+f+PWlE0XJa7FjdocwxxwiMiIWGq6MHu/6D65g/kHnnrz9/oDhi9ezCpIMpK2YQ9JKQOzRpSeUbsBpjVzC7VCPJyHtUmIYkA+nTDihaF48o1HP+elEa5tNOXNWSg== 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=WOANvG65P9Cbz7EDd7p28oCJJFW3rG4vuvjFizjTNJI=; b=TI8PNPRnpUYnlrfhGahOTIDYIMzMGaxjNNqCMG7HTo1Q871hqo/4TzO/5ZsHlk8z0z6gYS4JIHXOLlXCeTFseISjTf7WxGfR3L+7mL1mYmWeK0ezHPEcQLKt4jg+DxGafOD03oWFDxeGuqevvyAb92MqHWaZ5fgBOMWAWD72Jea8kiSV+SL3To7JaaIO5a/CtnXSRgMhFN9J+EJmNYqkb9a2d7UBRdaiIqF99Hgm61DA8MgjAffO+U0yPc4xYTkORE7DQ6l4vCHFrLbTR4sqAZD3dwOYkUvlOWpUGGR9l4NBVzfy39TSWc50S/zxJoJo+35QrJHqva3ZZwyOPA3NNA== 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=WOANvG65P9Cbz7EDd7p28oCJJFW3rG4vuvjFizjTNJI=; b=FZuiVjXa82xPHp2MyruQwTWQUZLopnwm13ldJZjuYLuaZFbetHtpG40g/VpIDleQX05jrcj3GibeyDVolVH/JW4qhx4Cltx7y8Mo58xW/+CusXCKHCovuViRcumsxAP4i3u5WfJUVRM2azcJhnWNmr4UFLD7h/SrQNjrmDSEFF5Gusba7f/BCFEbpL15Rj0D2BQJ6A7gHqjMDZqMlQONcqywrxWFK5xrpUisnAvq1fXdY0u3I+mB7ieWM2Q2Dr9Btkm72N880vM3i0dCrUvB6SWlK3pVKDVpmjj517D0mboNc/jkAujXWk0IX8SsNfqXFXw7mKlXCppB6kBCULQyXw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) by DM6PR12MB4369.namprd12.prod.outlook.com (2603:10b6:5:2a1::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.55; Tue, 14 May 2024 15:53:26 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e%4]) with mapi id 15.20.7544.052; Tue, 14 May 2024 15:53:26 +0000 Date: Tue, 14 May 2024 12:53:23 -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 07/14] iommufd: Add viommu set/unset_dev_id ops Message-ID: References: <6e57d7b5aa1705bdd547b1cd2aca93d3bf70dfa4.1712978212.git.nicolinc@nvidia.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: PH7P220CA0042.NAMP220.PROD.OUTLOOK.COM (2603:10b6:510:32b::25) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) 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: DM6PR12MB3849:EE_|DM6PR12MB4369:EE_ X-MS-Office365-Filtering-Correlation-Id: 8cf6ad9f-b3fa-4c9e-b8f8-08dc742dfdab X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|366007|376005|1800799015; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?35HfbVtNjeRtEQWHc8M26QuB5szOQTJkHh1m+3CF49ItbYh3WZI+x8adbbn2?= =?us-ascii?Q?njKraobfcBT0pQuBxzVZIsz0rZabxDbSp0NRM7khWgJtWn86OCpez0CL6KrN?= =?us-ascii?Q?dBLwlSEAUtF093A/3z0AivTu7rZ0GuI+7C2a07YaI0rwROdkSKQNalxt9pZH?= =?us-ascii?Q?oMYFw/M6hYsQQIxBW2UcwpxoWGqgZW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JFsHP0G3yoOMSOUhSdkYH3799JU/T2lrOzAa4HtbwdhTw2zKxzr41Q?= =?us-ascii?Q?EZQjLsIdxH2e6zB2cEQtQGZXQzDbNDlw6DSxwo95oVQjfD9Ic1oIjLZ6cbJ7?= =?us-ascii?Q?LPDMEHvN0iHNfF52IKWmnSusYWvqLIhaQkq3FSO57NwrM1HHM43gSmGPG/K7?= =?us-ascii?Q?nbyrf+QNhvAtZ60tO6CnfmeFWPD+GvZEnK47DCdCCA=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(7416005)(366007)(376005)(1800799015);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?spytAs+1nl+sRPb1dXgSinUmeHbCHqMAFKzGv9nXa/tNrdaTxh2kcG1ByT0V?= =?us-ascii?Q?qCHbsfZTzJ4Zba8HsAQACoTPQU0Th/B/9cybYOy57S74F+0lwtP2QEqcbnuB?= =?us-ascii?Q?VvrOPJ/AfQcNjj5g5XvKLBhzRWO2DOriDPJ6/S9iP3UnJfCE/EkHVxhS+cDV?= =?us-ascii?Q?J0x42bnTjcCvcnBgGxzVVK2NNFz5aRk3mLJ4pORaY4IjtB1k1ZSjlUdAjyuD?= =?us-ascii?Q?3OGWLp5NTRSkOmnqsBFY6N25robejsjNbLKpCfOp6zOfnnHgAKyXKUJ1GbHu?= =?us-ascii?Q?o3NkQ2TZYdYjwy0+afWQ4uhUIJca8u93wf15w/1hYtvJX+BSQ8ZeIZ2XPeWD?= =?us-ascii?Q?+J32RdM2SyZ5C8ajbs0CNvOeEuj3MG7fvN/sTt6Z3UqG06mYDa7wkPEKbDp0?= =?us-ascii?Q?h8zJ7IEEKTDuFPS9qXAyzxIL6nRyT3sQwg+dtqpjZ/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wBvn2R0n9Px6KsbvJbb3EoTEalbc8mN3YYNpCEPpLs?= =?us-ascii?Q?c0JKpGmXM7YSlRGy9beG5rjn7kZDvxsZ6EdIL7Ky5UNz/9E3U0yyxj/v5q+T?= =?us-ascii?Q?DnuqJrQrEPR5EuCh2xI/+pGcOAsQaqMwUqGhTH7ejscVRWMevoIC0N0QpQXE?= =?us-ascii?Q?+UK2/dFOMtWaG23NJV7m2l5ZxqDLKNIfuClESOvRRkUkHL7XnVaO1Sl6G0PZ?= =?us-ascii?Q?rc7vdzMGfTw0G2VqmfM=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8cf6ad9f-b3fa-4c9e-b8f8-08dc742dfdab X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2024 15:53:25.9178 (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: pdLP+UKgXsLYfizOIA01NiCq4giQ9XUoxAkKzzPRSsZeaqDXOSAJn36OCK6SssT9 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4369 On Sun, May 12, 2024 at 09:39:15PM -0700, Nicolin Chen wrote: > On Sun, May 12, 2024 at 11:46:54AM -0300, Jason Gunthorpe wrote: > > On Fri, Apr 12, 2024 at 08:47:04PM -0700, Nicolin Chen wrote: > > > Add a pair of ops to set and unet device's virtual ID that belongs to > > > a viommu object. They will be used, in the following patch, by iommufd > > > to support some HW-acceleration feature from the host level. > > > > > > For instance, every device behind an ARM SMMU has a Stream ID. The ID > > > is used by ATC invalidation commands so SMMU HW can direct invalidation > > > requests to the corresponding PCI device where the ID belongs to. In a > > > virtualization use case, a passthroughed device in the VM will have a > > > virtuail Stream ID, used by the ATC invalidation commands in the guest > > > system. NVIDIA's CMDQV extension for SMMUv3 provides a v-interface to > > > execute the guest-level ATC invalidation commands directly, yet needs > > > the HW to be aware of its virtual Stream ID so it can replace with its > > > physical Stream ID. > > > > I imagine using this as well for the ATC invalidation commands. It > > would be very easy and simplifying if the command fixup just extracted > > the vSID from the ATC invalidation and used an xarray to turn it into > > a pSID and then pushed the resulting command. > > You mean the nested SMMU series right? Actually the set_dev_id > ioctl was a part of that until we wanted to try DEV_INVALIDATE. Yes, there is nothing inherently wrong with DEV_INVALIDATE, we could continue to use that as the API and automatically pick up the VIOMMU instance from the nesting domain to process the ATS. The VMM needs a reliable place to send the CMDQ data, on ARM/AMD this needs to be an always available global-to-the-viommu thing. Intel needs to associate the virtual invalidation with the correct nesting domain as well. So I original thought it would nice and simple to have a VIOMMU_INVALIDATE as well. But.. If we need a nesting domain that is indentity (ie the S2) then when the VIOMMU is created then we'd also create an identity nesting domain as well. Functionally we could use that global nesting domain to deliver the DEV_INVALIDATE too. It is a bit quirky, but it would be OK. > So again, yes, it makes sense to me that we move viommu and the > set_dev_id to the nested series, and then drop DEV_INVALIDATE. I would like to do this bit by bit. viommu is a big series on its own. DEV_INVALIDATE is fine, it just can't do ATS invalidation. We can add ATS invalidation after either as an enhancement as part of adding the VIOMMU either as DEV_INVALIDATE or VIOMMU_INVALIDATE (or both) Jason