Received: by 2002:ab2:715a:0:b0:1fd:c064:50c with SMTP id l26csp119311lqm; Mon, 10 Jun 2024 15:01:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXGgaWqXBQAndT9iq9VqFnBJqjkT5kDV8Ak+GQ+whDRlF+IqzmNoBP7q1rD8Bjo3J/f6au0Iv19z+GOAoUSkW5QLVHFfoYAQlV24WnMxw== X-Google-Smtp-Source: AGHT+IHvD95XRTZXSDFTn27kPBLvkjO5xrYD6h5n5ElX5LrQvP0iImMPAsqYBgpIIYpyF65Z+oAs X-Received: by 2002:a17:90b:788:b0:2c2:c74d:303 with SMTP id 98e67ed59e1d1-2c2c74d0373mr8340084a91.48.1718056888461; Mon, 10 Jun 2024 15:01:28 -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 98e67ed59e1d1-2c2d0e58307si5598418a91.64.2024.06.10.15.01.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 15:01:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208975-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=Z2xcouPw; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-208975-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208975-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 CB5BE28119A for ; Mon, 10 Jun 2024 22:01:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AF9BE14387C; Mon, 10 Jun 2024 22:01:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="Z2xcouPw" Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2074.outbound.protection.outlook.com [40.107.101.74]) (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 7AE2863D0; Mon, 10 Jun 2024 22:01:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.101.74 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718056878; cv=fail; b=k1Bix4gG3FdjPAVUvO/vHzRnhkrRuHAL01GHnMSVG5uoUcCRhCPQAf+OMnnadWoF30wDT5ZDeRUfCyCiVqsbAmJbRzB7ET8biFBvwlMYBoheW9Zhxfh1qXh1Pxlpl8YedSoFBIDehVartbCl4rVQyYyNGFhJghWeksO3M3dCazk= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718056878; c=relaxed/simple; bh=Z0yvtg9hQNRmlfpOK8eh6pTvEcoyHGBNZb/L2b6MQVo=; h=Date:From:To:Cc:Subject:Message-ID:References:Content-Type: Content-Disposition:In-Reply-To:MIME-Version; b=FWnptgqZPI1VQPzNwP9YRIjscwxnowjhO6kDXwBv2xFV9QzBLSm6tOaCrrx4z1yIQEm+xemPmbKU5iZfwBqFMMkxpIsfcSTXb8YpsNw+IP9raXCmoQDtaFaFL6mozkiavkcPlfR1eaBt3I+dvc5d9HXojSezS0zO0XPaMx+81A0= 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=Z2xcouPw; arc=fail smtp.client-ip=40.107.101.74 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=I1fscPRc4EbWx4R7ukKMzbyT0YkBheKd2qkd5DenfDnSNcet1Sm9RFWy5WDfSbHxT/j55zAkIbKO01PPiS4YNlarVr4/2tfDLCc1+xAH415l03IWcLSmsnMMZ+Vzjd/4mi55yawFb2qXX3Put8wX7AWivbWl4oTes1hN/tQJ0T9HjrgidtuEFACnTVUDtExAfAakqqswlGt+WHZHacSrh+7RTTMI0flNMiBCjaeHDE/ij4HihlUSejuLTeBsRpDUK+RbrUffIf0ooOFuCKicvfwGebGATUSJ2XrAwx0UBi8zetJmFKVtC88rkWh5CR0Pehi5p+3HKBN789yJzY35XQ== 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=6ukzsYhJXL5GOFFSR1rVCr4sC/DcByiTzKV4AJMocSY=; b=VB/LYeKAa3/AbIfDJXvt9H88iMwg6apcSCHOTSnRFmJQ6ipyFFW2SSLtSB6SwPjCqGqILCUzwzbtU8D9rncpZnmu/tNBGlVpC8Ia5ixbe5wuG+veV9oHB1R8AXm5mJElnjt5+MntcWITeN+SPU5Cd/M8sT9a9AMphXp1l0CCheW/15i59AMlZnwJxYWUJhAvpxOmXXNoH7tzql+X8ZsXBuQ8x2xo3w3mbRaXX/0SNk8jis+gDgCd5l1ruXxTsOfrmjFb4q6ewIVjaZxDcNpvPEXQcfeNDCxGVgHypLgRDvja0ZKeykk74tfZintDrL3/JDnFmVvYZyYymr+aRnaKKQ== 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=6ukzsYhJXL5GOFFSR1rVCr4sC/DcByiTzKV4AJMocSY=; b=Z2xcouPwVkHxFP3EccG1I/78NGtccnQt8RGXul/YsF6OMqf+1uupqT+gv1oMbJtSfJ9ND5FgITBVai3UrJ21Cwi1xEXc06Q90wDSlWoz7Qv+MWjCe7SVeOJGVyjGpq3hbf0/aob8gXS4z1sKXOx1MZP7EjRVZA0QI/y5WLK9BpkcrJmNqa56SZu9tVb2kwvu+LoOG3bVWh5rUuLiMNaHZM6sHkMYN2bCNojNhm9JCEKWzIwethqRzYCAenMjSS8jDEvRZD9slVZ7Y8UHSKBdN0d/U2LdWWnsOFVj24MHli1wCC24pJMEBBlxDjSKhj7qiOYJj2MCqqRevsSlcRZYQw== 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 DM4PR12MB7549.namprd12.prod.outlook.com (2603:10b6:8:10f::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.36; Mon, 10 Jun 2024 22:01:12 +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.7633.036; Mon, 10 Jun 2024 22:01:12 +0000 Date: Mon, 10 Jun 2024 19:01:10 -0300 From: Jason Gunthorpe To: Nicolin Chen Cc: "Tian, Kevin" , "will@kernel.org" , "robin.murphy@arm.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" , "Liu, Yi L" , "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 08/14] iommufd: Add IOMMU_VIOMMU_SET_DEV_ID ioctl Message-ID: <20240610220110.GQ19897@nvidia.com> References: <20240606182423.GF19897@nvidia.com> <20240607002707.GJ19897@nvidia.com> <20240607144917.GK19897@nvidia.com> <20240610120446.GP19897@nvidia.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: BL1PR13CA0237.namprd13.prod.outlook.com (2603:10b6:208:2bf::32) 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_|DM4PR12MB7549:EE_ X-MS-Office365-Filtering-Correlation-Id: caa1658c-6d95-453d-2db7-08dc8998d763 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?/t9zYv1f78ZQ6J2/pozjiyvlQxi5XYYlXvqbxsyYKJJJgK8X/O0/qQmXcyyn?= =?us-ascii?Q?THQ2/ka10SDC9pe34g9u+mhlImqw8oSSLghJrtafYQw5q72WNs5ArHnHlgWi?= =?us-ascii?Q?iuxRVH3GGXkQutt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yUSB+iy4j?= =?us-ascii?Q?qBkREannZ4gwLnO2Snq6kfircJXm1PeGQVZLTqd56Imzp6zGV5P5hCFkyuDA?= =?us-ascii?Q?xOYRteNVLtMZvaj6KyZs/pBizvb09bX3T9tSRmqur4LH0cfequLq6Qpq06sk?= =?us-ascii?Q?LQi3rDZyjmBzCqEBTxloNG98nHRwFONZVPpaJ0E7SbvvvoyQBNyDnkoU06yv?= =?us-ascii?Q?Dy2pE0JxLDf5KXxf9Cn6/oxUc/g1LZCk0a2+cAjcQWTAsYZLOXDksyXqkgcR?= =?us-ascii?Q?TpxCHUy65VE/F/RskTDTMVmS/pFajZEb9ZgUwiczyoN59mkLBxlHG+rujb/7?= =?us-ascii?Q?wVnQ5khJlCrWBcxethl3xi3y?= 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)(1800799015)(376005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?MGXkUGmGN1ZhPjSx0bEFdr8N2Tlb6kG6oe2gRKUSBWKc3U0rn8D5ZwXGWZWF?= =?us-ascii?Q?bK2C7HufJ4lPQ0ElmObfgw+pYjf6UPDMhK251nZzv/ftgvEMtIvyyxJP3xIG?= =?us-ascii?Q?30z6/vnqV6wkArTOQ5aNZ/6AjtVw6CmS8Vk9L5AuhszmbKMIKPc9uxzJUCxn?= =?us-ascii?Q?vxs5//y+mPoVz9YR5EmQqY+dUpw66NjeJaG99I4WEHw5aJX38B/dvBSPlhNA?= =?us-ascii?Q?qsXlgV62B1jEZFsbEev3fX3SKYI9mNcJFGl5bzc4YZy85gF3nxqb8AxsWlMh?= =?us-ascii?Q?Vyqfp3oujLQfIUmG9eJaNa4FZxYqSwBjxk2/oalIGdQQpytRS44IeVaTcp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D4EUaogOhaf0eVIMSktEKWkTnwqg4z0?= =?us-ascii?Q?LNXulkuROTx79PlqN7CtAezv2XdyM+XDmnUFzaSBFBFIe4tzFEi2/7Dn+o4C?= =?us-ascii?Q?ducjUF/Wyfid8pMKnkwSXMlIyZkXGNwfw1Pfw4aPyx8buI6FbN0y0wtBxwB6?= =?us-ascii?Q?bNabeOgK4ikf2NDJClGA160mETDMxP2Q9epMuRkx8GMgP+g5A/MeLgHxWhLp?= =?us-ascii?Q?aaEJpdkz9FXF8676+nUlX3IGAI7J+o7LyTGFYRUrmIDfUTI3XCo68TBKGIWX?= =?us-ascii?Q?n6Is9Nk8LKz/vy8020f4P8UlWcEMT75p16+Aj/1I2cz6MDogLjA+exvfi4+m?= =?us-ascii?Q?wVArFJTGVgUfKFdppdJMVgBbHHiU8Q0iOPwaj0Pg?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: caa1658c-6d95-453d-2db7-08dc8998d763 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2024 22:01:12.2565 (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: BzJwMHo5JDWZQMMu5BoRXR0mqH9hrdkdeefUqpsx/62lP+uuEjAzUBss5OhINfzJ X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7549 On Mon, Jun 10, 2024 at 01:01:32PM -0700, Nicolin Chen wrote: > On Mon, Jun 10, 2024 at 09:04:46AM -0300, Jason Gunthorpe wrote: > > On Fri, Jun 07, 2024 at 02:19:21PM -0700, Nicolin Chen wrote: > > > > > > IOTLB efficiency will suffer though when splitting 1p -> 2v while > > > > invalidation performance will suffer when joining 2p -> 1v. > > > > > > I think the invalidation efficiency is actually solvable. So, > > > basically viommu_invalidate would receive a whole batch of cmds > > > and dispatch them to different pSMMUs (nested_domains/devices). > > > We already have a vdev_id table for devices, yet we just need a > > > new vasid table for nested_domains. Right? > > > > You can't know the ASID usage of the hypervisor from the VM, unless > > you also inspect the CD table memory in the guest. That seems like > > something we should try hard to avoid. > > Actually, even now as we put a dispatcher in VMM, VMM still does > decode the CD table to link ASID to s1_hwpt. Otherwise, it could > only broadcast a TLBI cmd to all pSMMUs. No, there should be no CD table decoding and no linking ASID to anything by the VMM. The ARM architecture is clean, the ASID can remain private to the VM, there is no reason for the VMM to understand it. The s1_hwpt is derived only from the vSTE and nothing more. It would be fine for all the devices to have their own s1_hwpts with their own vSTE's inside it. > > > With that being said, it would make the kernel design a bit more > > > complicated. And the VMM still has to separate the commands for > > > passthrough devices (HW iotlb) from commands for emulated devices > > > (emulated iotlb), unless we further split the topology at the VM > > > level to have a dedicated vSMMU for all passthrough devices -- > > > then VMM could just forward its entire cmdq to the kernel without > > > deciphering every command (likely?). > > > > I would not include the emulated devices in a shared SMMU.. For the > > same reason, we should try hard to avoid inspecting the page table > > memory. > > I wouldn't like the idea of attaching emulated devices to a shared > vSMMU. Yet, mind elaborating why this would inspect the page table > memory? Or do you mean we should avoid VMM inspecting user tables? Emulated devices can't use the HW page table walker in the SMMU since they won't get a clean CD linkage they can use. They have to manually walk the page tables and convert them into an IOAS. It is a big PITA, best to be avoided. > > If a viommu is needed for emulated then virtio-iommu may be more > > appropriate.. > > > > That said I'm sure someone will want to do this, so as long as it is > > possible in the VMM, as slow as it may be, then it is fine. > > Eric hasn't replied my previous query regarding how to design this, > yet I guess the same. And looks like Intel is doing so for emulated > devices, since there is only one intel_iommu instance in a VM. Yes, Intel has long has this code to build VFIO containers from page table walks. Jason