Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1155414pxb; Wed, 6 Apr 2022 10:01:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw335JpyrGrOp/xYj56RmPd5oeYs/wXx+LQcgx/I57MJb/uwKiqt91SHugrwpOWE0wY/Sax X-Received: by 2002:a17:903:244b:b0:154:4104:4668 with SMTP id l11-20020a170903244b00b0015441044668mr9635436pls.30.1649264512876; Wed, 06 Apr 2022 10:01:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1649264512; cv=pass; d=google.com; s=arc-20160816; b=PaRhO0uGd3DNBOj6jZcxhtb+hg4l99zCKvG3iVGDwtgp5O7SjZE+jPAtCm5U3jmsf3 uRHfGKYiamCYnjEcmuMXOWM2GtxDRYDBmus0+6e9q96dohe+bj0ZIhITddpEQi4N78Ih iYETf1zcA9BZNEpEiswKhhr3fPqYdjRKR7ltHY2GHYEtOI/g4nus02UadTIN2ZynOOr+ 02/3+tB4LUgS+oqXk7IFeiyLm21lihV5YHmqOAQKR7LgLm85BVAHiDDP3G+XtHwJN/01 yU8W6ygrIYPWjqvW7nxo/UBbJf2XSFtSk4gCRjLgTm50ZDDYcC/qUM2vIxy8rZs1OVAl U59w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:in-reply-to:content-disposition :references:message-id:subject:cc:to:from:date:dkim-signature; bh=KDhN0FPhMeObVac6cPS2p1KESO1mI0eIHt4wWyIJP9M=; b=NjnzyH5mdjJCIMvhpApGFB/Ozlzvh2YCsjhk/fzsG46YFaQPwLrtX92Kk3cLX3x2y7 OZlhvS9jr3s5+DTx5mM7INhu3xCyXqQY9/FhA4PdZU7m1PIqY+cuY9LBOkaVl/JTAINv EyWub2WEgigCmfLfTSSwRir7y1xqnmLT5g1fKqsCVjV4OXFdtKzSroWv5pQ4yaJcZu60 R6DV8IMfqPceww761eLR36uTs3Nv9oR1ZFb2VXqNjne2A661VJ1AVMZmg8SUmLTtorTx vwaL1ZhuSRe3ACjygRl5zWZLIZC7rGjUuWyhTJL0J4FaElBniRSFRybiehP6s90A+d66 e5lA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=rZCaC62i; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id j17-20020aa78dd1000000b004fa3a8e0078si14352758pfr.303.2022.04.06.10.01.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 10:01:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=rZCaC62i; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6D33415B84F; Wed, 6 Apr 2022 09:41:24 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237821AbiDFQnR (ORCPT + 99 others); Wed, 6 Apr 2022 12:43:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238086AbiDFQm3 (ORCPT ); Wed, 6 Apr 2022 12:42:29 -0400 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam07on2063.outbound.protection.outlook.com [40.107.212.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79E90312151 for ; Wed, 6 Apr 2022 07:01:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TUJGi8jCO1ud5bZQp2EBg04Q3+uWbAlOFU7G5a0aGeqCCws0/vRHGMcc753od+hsUYNTgsKejHgfkgR5duRKPWL2kvvnXfBmHrniMctYL6kmDVjfqfeOc2JnkO7PvD95aSp/ZkcgWSp7Yge/BrOTBBnIUx7sEFmZmmbyUGkyBbhX0aK6Nr+OYUPv74YfQyzHffFfjcmP7yztz6gs2YJmYzD5I3oKmtLBJlmnEDkyPHRxH22kiNP1ZQFJdF7X3xLXnrjicJVrpB1l4E4LljBL8L8ypoCCZzEnub8j65k9wkUf6NAIxA123DKWsox9yQ0m2CcfyZtGAQsFg45SDJFz2w== 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=KDhN0FPhMeObVac6cPS2p1KESO1mI0eIHt4wWyIJP9M=; b=XS77G+nAmA1j20syJxgmUdaAQnYng2FZnHrbK0agGLCtKU/PS2WXKHMPpKe3AOTRaIudhoFPZ6poKbJ8PXIZ9rnnqATrFU/SRrFOdmnegSu+7ecQ8OtVZu532lDgtinwb6B6+bahX4izb/+cF4VhVkmeu0JG4N7V7womaP2qEUTbWy7ZgljH79bBBuCADU1zQBjkpApjsJaXR6HOmrsWdoCVhN843mNbAVBY3bmsawkrdLZLj8WxmhteF8hHA2dtwLMAvZzJfdkyKKPCL+fHcCExqt+iGCMNU22MRZ81tpSIjpxCmRe7trYf1ChkjEt7IcW+q/4tDzKePsQR+6sMSw== 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=KDhN0FPhMeObVac6cPS2p1KESO1mI0eIHt4wWyIJP9M=; b=rZCaC62iJB6E2oZjhsIEwjhrWjtvqpTZtEITLwZ3YDs+if1+pcZvm14SzkWz81tUCqE8D1ciDJdR0+0U0Uw/SWrLi6BUhoQ22hPfJCu2NiIS8ET2sHHbhYONFRl0gTUAvMWS/u0dPg1UkcQ/kCUXQ/7Um90QmRhCzXBGtQ/a5d7kdYwtctOpEhwnX9ZQypclJaVdePPYzWS9hEazqUj0Ta9ENbejcNUmm9+er1aYGEOIyJJFJLPcn7KBuimfRhdBmJYhREonkWRVRs9/B/LjSHcZeqEvFyhnnx7Yra2iKKNkLiw4eAgOpbPhuqGlY1GCf2kk1fg5/r1UG/xXdiglKA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from MN2PR12MB4192.namprd12.prod.outlook.com (2603:10b6:208:1d5::15) by BY5PR12MB4967.namprd12.prod.outlook.com (2603:10b6:a03:1de::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.21; Wed, 6 Apr 2022 14:01:45 +0000 Received: from MN2PR12MB4192.namprd12.prod.outlook.com ([fe80::cdfb:f88e:410b:9374]) by MN2PR12MB4192.namprd12.prod.outlook.com ([fe80::cdfb:f88e:410b:9374%6]) with mapi id 15.20.5144.021; Wed, 6 Apr 2022 14:01:45 +0000 Date: Wed, 6 Apr 2022 11:01:44 -0300 From: Jason Gunthorpe To: Robin Murphy Cc: "Tian, Kevin" , Lu Baolu , Joerg Roedel , Christoph Hellwig , "Raj, Ashok" , Will Deacon , Jean-Philippe Brucker , Eric Auger , "Liu, Yi L" , "Pan, Jacob jun" , "iommu@lists.linux-foundation.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH RFC v2 03/11] iommu/sva: Add iommu_domain type for SVA Message-ID: <20220406140144.GD2120790@nvidia.com> References: <20220329053800.3049561-4-baolu.lu@linux.intel.com> <20220330190201.GB2120790@nvidia.com> <20220402233210.GM2120790@nvidia.com> <20220406012334.GZ2120790@nvidia.com> <20220406130614.GC2120790@nvidia.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: YT1PR01CA0037.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2e::6) To MN2PR12MB4192.namprd12.prod.outlook.com (2603:10b6:208:1d5::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 41368b38-ffca-4814-a3cd-08da17d5fc4c X-MS-TrafficTypeDiagnostic: BY5PR12MB4967:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bneYUgc1o8GQNIvmQ3wtyUcGFPLgNm0pcws/bDkfdvJaC2hv/lxgWyK5XeOhjiD6/fZkfBVj3CDFrSRcxRrWt5rZMe9N/ighl4UdeLoiV+rNmcTvj/4S8OhqVh+R3cApdboG4RqBwEGLdnhBTkJcFf3/bjoKw0E8Rik/XeQZkt1WTm+4Jh11k8KbEG+JVDeO1VQm/RyMKZxB5/zHBrZKhZc5kK4KwfMjKR+kr5H7P2OAJJOs1sWZ5KTbIBzxMzbBDWEgHUHfEgZHLBc1Gowk4JC1PvTgCGwL+axVkVdLvfTVV9kdqs5v3cJB4Wdi8pfqG9ajjjg5s4kuRhPpvWzEnrdbLXevlD0W1Uvj8LCqdGvjZJlk/250jDAdf3Nlip1b6gWyAEq7cGLNfS0hSUiubWNilYhhIoGd5EMfImGh55o/g3zvj6ElQsEYxLUDFe6JWpSrf3VbhBfv09+EMOQ2WafkCLGz33FpQCq/vz7ygvrSEJeei6qKCHrMh7YUrN2MN4LfjfBqgM8qR5pTZBfDgWR2deecJJMwpnMNcBkQEezypl+P5iH8Eszz08KyvnxlINsbnvasLaMi9JR3jfqLaJywoPf3K9Cb70Pqtx+86NGA51n1Na4/uUXfnUQNtNZshObHzn75+WRp306TdzyQJg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR12MB4192.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(33656002)(6506007)(53546011)(6512007)(2616005)(186003)(1076003)(26005)(8936002)(7416002)(38100700002)(36756003)(4326008)(8676002)(5660300002)(2906002)(316002)(6916009)(508600001)(54906003)(6486002)(86362001)(66946007)(66556008)(66476007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?/pm3d3X8D87CVeRh3HS9rvOtZ2GmS0aczeYSOarKE+VQgTqna2jk5LN9aK53?= =?us-ascii?Q?+4xRvxcjgU9QdftvL/41Ghv1HnYnfo8CLB5UGRzBnb2oLDU92GWgOjGw1472?= =?us-ascii?Q?HLj1M40r3skDeY8R8D4qOqxyv1pmJWj6g+hEPQrusS07VwdflzY3YfMSfq37?= =?us-ascii?Q?DFSxuZ87ufiBAdJlXk2OyZ22OsEtQyFIvQ6nBAjHQ9BQVIBYXu1YhuYbyZo6?= =?us-ascii?Q?LI+5e21SPBRaTLSfoiWdvh1PhDy6mVRDXoit3Y50K1GhJA97af4r15HLB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Dl5oXZsZHDZpPqzCzF1MQgdzdCztbLrYFhAzrE?= =?us-ascii?Q?mikoZa2RWkYJHIaQokCiyvUCx6dznZPUXdqFRC+3dCIZ9LBQFp4R3Wc3N5ui?= =?us-ascii?Q?B/CvwcBmjTQ+sZTj4JULstJN1+zMbW2eWcz7m1L3Cx8uJ2sxGuZY6xRPGHFW?= =?us-ascii?Q?TlGD0EBCEhkk3+0TqXY4wHdjtoaFfufMqB71WbU30JAIth4TcXZO4Zg/mtPO?= =?us-ascii?Q?28mfd0cxuskGiRes14qztuoW+Putl2K5fdtMfRBq4nUwvr5NP7+MB0FTPmxj?= =?us-ascii?Q?ykY1qFm5pU/eeLo8FLbMCAO60aaY20ypGtNCkniGMAWQvsTt1gtPP97XvhrC?= =?us-ascii?Q?Ah1A/jpDU5iyduKuG3xXH3eovFb7CqgvsvFkUtmq3Usvzt5P4jOEEZhy7yf9?= =?us-ascii?Q?mKzBkOgMN2RXwxRdlxrm2Hdi9L8YsWveb6HaeP23njyboDDvizr4QtXoY1fx?= =?us-ascii?Q?rMiFiHgZGjHymVmhiOz/46Nwb2JZQfuXAl50O3huQs7TOrFFn9gJj4bu/+qy?= =?us-ascii?Q?7Zg4tJ+yYW/nHLa5gAGEhDp3VrlPFuTxR6+mrJ6T9q9GgLr2Uzk4GP80o6sr?= =?us-ascii?Q?AKyfBsh6Pg=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 41368b38-ffca-4814-a3cd-08da17d5fc4c X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB4192.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2022 14:01:45.5481 (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: 1yPXeYD5nGVqu3vIlVZNNPrSa+fTzlrV9fUkbIUIRCj8wWcPgQpw804nI1jo3mrv X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4967 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 06, 2022 at 02:37:40PM +0100, Robin Murphy wrote: > On 2022-04-06 14:06, Jason Gunthorpe wrote: > > On Wed, Apr 06, 2022 at 01:32:07PM +0100, Robin Murphy wrote: > > > a particular IOMMU instance, and potentially allocate separate domains for > > > separate devices to represent the same address space, much like > > > vfio_iommu_type1_attach_group() does. > > > > I think this VFIO code also needs some more work, it currently assumes > > that if the domain ops are the same then the domains are compatible, > > and that is not true for ARM SMMU drivers. > > Well, strictly it uses the ops as a "negative" heuristic that the domains > are not definitely incompatible, and only then consolidates domains if > cross-attaching actually succeeds. So I don't think it's really so bad. Oh that is sneaky, I didn't appreciate that bit of logic.. > > I've been thinking of adding a domain callback 'can device attach' and > > replacing the ops compare with that instead. > > Previous comment notwithstanding, much as I do tend to prefer "just try the > operation and see what happens" APIs, that might be more reliable in the > long run than trying to encode specific "sorry, you'll need to allocate a > separate domain for this device" vs. "this should have worked but something > went wrong" semantics in the return value from attach. Overall the way vfio is doing this has alot of overhead. Not only does it create a domain it may not use it also does this: iommu_detach_group(domain->domain, group->iommu_group); if (!iommu_attach_group(d->domain, group->iommu_group)) { list_add(&group->next, &d->group_list); iommu_domain_free(domain->domain); kfree(domain); goto done; } ret = iommu_attach_group(domain->domain, group->iommu_group); So, if we already have a compatible domain VFIO does an extra domain alloc/dealloc and 3 extra attach/detatches per domain it tests. It is not very elegant at least.. > > > It's not really worth IOMMU drivers trying to support a domain spanning > > > potentially-heterogeneous instances internally, since they can't reasonably > > > know what matters in any particular situation. > > > > In the long run I think it will be worth optimizing. If the SMMU > > instances can share IOPTE memory then we get two wins - memory > > reduction and reduced work to read dirty bits. > > > > The dirty read in particular is very performance sensitive so if real > > work loads have many SMMUs per VM it will become a pain point. > > In the ideal case though, the SVA domains are only there to logically bridge > between an existing process pagetable and IOMMU instances at the API level, > right? Surely if we're shadowing physical pagetables for SVA we've basically > already lost the performance game? Sorry, I was not talking about SVA with that remark, speaking generally about normal iommu_domains and sharing between SMMU instances. For SVA I see no issue with duplicating it per instance since it is very small/etc - the only drawback is that the common code has to do the 'can device attach' dance and keep a domain list per mm-struct. Which seems OK to me. Jason