Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4073449rdb; Mon, 11 Dec 2023 08:08:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IF/P868G5utLYvBXoO960STPTgcid7NgyiiBYHstjcCapRRnrEz81Rw4Z7cK8kgMpXvrh7P X-Received: by 2002:a17:903:452:b0:1d0:7d9e:e727 with SMTP id iw18-20020a170903045200b001d07d9ee727mr4165924plb.14.1702310901773; Mon, 11 Dec 2023 08:08:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702310901; cv=pass; d=google.com; s=arc-20160816; b=wduXCmEE2yc1ePLXEf8u38FSskyx9PBOYI6av8agOZ1yiI42wIymXxv8T9vGFGnrQu /AcJwMTm4LOuuQtJQ2c67cnhM2zMuAN6KiNKdrb/I5JXN9bbp0TASOJvT5KO56adctS2 TZu/HXrEJmGO9EaQFG7obaoI7VGxUIX5ZTAe6OOhSLMRadv9NamiMEcPlqBKBTL/vytE XnCKVsalXEeadtCNb7245a54KD9/SopA6Q5PpBOYkOTSyS2btz3ClHmodSww6fSI2tI7 Iq2AquduAXFakrbqC3/VIqwSjMMnR6TRyuxjE5s23nDnnuWxSU+OJPM2b2H+xXG7nNio LtrQ== 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=pE3O+0ZvK2JD1c9JBdJx+fcCBvqyhVcUf5l6qIdyJ8s=; fh=Gu2unqSY2vEB90zAm4PMIDTrJ+8VABDy2uc/4NBIl1U=; b=st7qse2DoWiNE+mXppfXekRQ8ll1KViUEMrCB0j8D9givx5iINuCumAeDWFvPD6nv0 aAb2Sck638CEVYFWUUqB6q3CyWTwAe3rx8xnkownnjCFDZZxqtAFFzxJNpeweY1oKVF5 PPC0WFhB4byyKX8DFcSzjF+l2INtqaFRFvVJnXc/CDAeoCJ+AybwpiHzvcin7Go/svlb osLob2vwM7AziwGamqZyAeHvkVpDHGdNB8cCo9yAwC9Dio4Lp7mUbYicChq5FjKEN/RQ taTuowNhZ7m+KuwwBsJadue5slh6Pbiy7KjYS3NlezCLf+XAKlmCZ+3v8K9kfLN6rd6x meRg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=hYtrLQn4; 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 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id c5-20020a170902d90500b001d04d35a88bsi6214201plz.187.2023.12.11.08.08.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 08:08:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=hYtrLQn4; 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 23.128.96.38 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 out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 21B0580972AC; Mon, 11 Dec 2023 08:08:15 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344368AbjLKQH4 (ORCPT + 99 others); Mon, 11 Dec 2023 11:07:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344075AbjLKQHh (ORCPT ); Mon, 11 Dec 2023 11:07:37 -0500 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2053.outbound.protection.outlook.com [40.107.237.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 649CB137; Mon, 11 Dec 2023 08:06:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e/Sst4XnnHKVKYyWpD0f/XHpptoIQKSdkzjQ5B0h2YqYSygzGIvxWkM4r1qKTMGzkUFUJnEJt3Anp4wlvR917XDKZtxMfdeYC91PwNVJUcGyXaVmK6Uqnma3syKFvbM3VZt4GF2E/sbAcWmmRHWNUkSykyY2lA7nPFgn8hIl5fOAjS+CMwL9TJ88iYL9CEKwcdg2rdtRoIGj+2bVH0bEOpbe9zIm/uqiFvd4hOZGK000gRIeAsWnNcf72Fnuh8xge12qzPzNMWuzk7j/USLe8E8CqvEh+7BlzuR9wXlv34hapJ3NiCvF754WxKeWXuYRWUaZCUt6XIfd0utffDjSMA== 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=pE3O+0ZvK2JD1c9JBdJx+fcCBvqyhVcUf5l6qIdyJ8s=; b=idZyZNiOzQOfKfdZjtSn7QxUyIYw11WfhNiB2Rnd1Fyvlq11KhrFGgdH3ISs/0qYry1zvcBGDknvmkfo8AT3mzuUJp1ZAPBwvoTnAR/EnT8G1sFL5qPbYUFk3DILPV0CJCyi75MYZTNsW/FTFZP97TSv888vEUwsedwkS8Oo4mEQDSjCUTz4axfURjO396guwY/S5EOUN8gKzb3LiGZqiV8alnb16p/+vG6nMLMGgL+W5KIiGgcvWRau6+O+Y6x1q9+U7B4tqYA/PklXZbe4gme5/nkwAB9iH02Np7f7e/arxD9r9FuQBCpG9byD3yBkMpim+UElv3iUCvIaLFiq9A== 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=pE3O+0ZvK2JD1c9JBdJx+fcCBvqyhVcUf5l6qIdyJ8s=; b=hYtrLQn4zXy+CGeRJFgC7v+sNRwcUVOh/+tveAAr70r89pBdMOydfGNx0hpemexCocjD3lRGcvAZzGNMOLj3cDlSrnmwVNLcsVl+EpB0FN3azcpuVloYXgNjbnSPPvQPK4YkPKBkvaKFXjygd0ZbVDB8GjhiZB5iDaaSWIqiFXcbtgjqap8iJefo0QgzVqr8Diy+J1Nm28qU9Mg+xtq5YqbXf6lgOzCXaXCdekvHafHmHruiiljfNhWSCx0UX9WqOisROkZkiSf5HfFW60nGZRHUcSozcfr2001b7nUm8beB/cFE0+caEK3L8aFUkuQDbQom5JPNyANdro2pUiqQng== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by CH0PR12MB8552.namprd12.prod.outlook.com (2603:10b6:610:18e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.32; Mon, 11 Dec 2023 16:06:33 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::60d4:c1e3:e1aa:8f93%4]) with mapi id 15.20.7068.031; Mon, 11 Dec 2023 16:06:33 +0000 Date: Mon, 11 Dec 2023 12:06:32 -0400 From: Jason Gunthorpe To: "Suthikulpanit, Suravee" Cc: Yi Liu , "Tian, Kevin" , "Giani, Dhaval" , Vasant Hegde , "joro@8bytes.org" , "alex.williamson@redhat.com" , "robin.murphy@arm.com" , "baolu.lu@linux.intel.com" , "cohuck@redhat.com" , "eric.auger@redhat.com" , "nicolinc@nvidia.com" , "kvm@vger.kernel.org" , "mjrosato@linux.ibm.com" , "chao.p.peng@linux.intel.com" , "yi.y.sun@linux.intel.com" , "peterx@redhat.com" , "jasowang@redhat.com" , "shameerali.kolothum.thodi@huawei.com" , "lulu@redhat.com" , "iommu@lists.linux.dev" , "linux-kernel@vger.kernel.org" , "linux-kselftest@vger.kernel.org" , "Duan, Zhenzhong" , "joao.m.martins@oracle.com" , "Zeng, Xin" , "Zhao, Yan Y" Subject: Re: [PATCH v6 0/6] iommufd: Add nesting infrastructure (part 2/2) Message-ID: <20231211160632.GI2944114@nvidia.com> References: <20231117130717.19875-1-yi.l.liu@intel.com> <20231209014726.GA2945299@nvidia.com> <3e77a4a3-3be8-4e04-9435-1f66df93078d@intel.com> <20231211130555.GB2944114@nvidia.com> <509489ce-0169-4021-ad56-a31544752aa4@amd.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <509489ce-0169-4021-ad56-a31544752aa4@amd.com> X-ClientProxiedBy: BLAPR03CA0137.namprd03.prod.outlook.com (2603:10b6:208:32e::22) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|CH0PR12MB8552:EE_ X-MS-Office365-Filtering-Correlation-Id: 4e197839-b503-45df-2c2b-08dbfa63253d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YKWb7Tu5iDs7HVw6oSLxWXLhNua5tbWA+6VrmFXPOW0mBO5ngr9MU0lqzAGBhBEwOtt0CuyZBkoyptwRPJnXdHsBPDvvAWTuHcnxJJpRQc+i/qbxTNESUVBZdnAN+9SKT/YCwrCLs+5OYOPIwivZi7gMyXJBMYyWISUJu2D3rxCrxmieGDhXeE5mHBPf/QFXMKCUL5TMcl6JBPXDTb26gOQZ+wwQqsJt6Ha0Y4HH2XVbm9hbxX7IrTqVxX33wcWiTIb2Vu2UNVzglS8fuKW8sJAcLaCUnX5c+V3CWjSkf4/QKD/Zwx240N1b3yVeilIqUNQE1MpFkrDCgmpZ9jmZ54Ou7fqjU+luaH4FZo5tsIXBWCoE1v2wwj2q0OxwkVoVs7TjIuNoJ7ET1u5XwLfiYkEyVQ26xP3nrozg4DJkMhsQyW2JAAiDLHynqN73Yedl2oVdQ7fuVXWgaBz1+PgGyCY6biYzrzJB/oRJGGxkc6MKS8DvXrP6ULNFxPcvEEWNNVFlMo+MSSzY09DM/aq3yJLxtHlIO9w/N6d56+65Mys3eeUCqTW+wCPYpi+woktm X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(136003)(366004)(396003)(376002)(346002)(230922051799003)(1800799012)(451199024)(64100799003)(186009)(6512007)(6506007)(5660300002)(1076003)(26005)(2616005)(33656002)(36756003)(7416002)(66946007)(6486002)(54906003)(66476007)(66556008)(6916009)(2906002)(41300700001)(478600001)(86362001)(8676002)(8936002)(4326008)(316002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?lFP0vGsC4zehtiAhMdxq14tLgWuBlaaZAKu88GIBYLA2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LVgZqg+DoHmubsTP6u7UxYNz2/kAPNwuYXeQu3W?= =?us-ascii?Q?kbDwi4jqRS7iowwp1UTMx1pVjmh8ZsKBCkUX3krABKe7TcQQpcQAbaKqj6Rj?= =?us-ascii?Q?Il0TM4IK8tuZ5xq+ASQcVzu8itYvJEWsue4VY757h/Lj7Df9nlJZ7mA0PCVF?= =?us-ascii?Q?zytZcsUmhgLVc6NH/craoGOuon2Kb18E2PVN6zTL0AiUYbPKbYSdt0B6E/il?= =?us-ascii?Q?0booimHuRCtaSwVoifzVIFh0ZjxoCUvaLBrhXWeM6PceXpa69as2e4tayFKH?= =?us-ascii?Q?HZGKXHLJYM4bRa9gOMqnDB9ao4AalwnBtzmbMgS117dWZabciZCytLAQcxTi?= =?us-ascii?Q?iin/XHyQBfrL2YK0pau9jNFR8hYtEe8u3bXYjplfsqVC1pWHjEMztda8306M?= =?us-ascii?Q?2QZuPjS3Cwt7P/Uohh75mTauFylhHYoBv1dMfn4o6OGYWQYyKgnXoTu3vMM2?= =?us-ascii?Q?QgmOoffsZWsJ+/dy1AJSetWbcVMmx3Swxd1bdBfUOElKS21TEU1qtcqlGSSM?= =?us-ascii?Q?lyYEJieS2xXaSuJKDCSdXS4p/nbRY1EbHON+M19lSkVjD6ceagmum605Q9pN?= =?us-ascii?Q?6zTupLnDkvcwQu+yJEUBRIjImgEFVoH4SFDaMkqb3VspiZAO06CvNfgmy6kf?= =?us-ascii?Q?/GyycwcW2rVfdTY+0+/ggUDxmbl+hiwkGnfABI6U?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4e197839-b503-45df-2c2b-08dbfa63253d X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2023 16:06:33.8155 (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: 65Qa78exazLFvvK1hxxYCD/TOqzb8emCXSyOh67a6MiRE9JgdvNZnplARv82kzff X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB8552 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 11 Dec 2023 08:08:15 -0800 (PST) On Mon, Dec 11, 2023 at 10:34:09PM +0700, Suthikulpanit, Suravee wrote: > Currently, the AMD IOMMU driver allocates a DomainId per IOMMU group. > One issue with this is when we have nested translation where we could end up > with multiple devices (RIDs) sharing same PASID and the same hDomainID. Which means you also create multiple GCR3 tables since those are (soon) per-device and we end up with the situation I described for a functional legitimate reason :( It is just wasting memory by duplicating GCR3 tables. > For example: > > - Host view > Device1 (RID 1) w/ hDomainId 1 > Device2 (RID 2) w/ hDomainId 1 So.. Groups are another ugly mess that we may have to do something more robust about. The group infrastructure assumes that all devices in the group have the same translation. This is not how the VM communicates, each member of the group gets to have its own DTE and there are legitimate cases where the DTEs will be different (even if just temporarily) How to mesh this is not yet solved (most likely we need to allow group members to have temporarily different translation). But in the long run the group should definately not be providing the cache tag, the driver has to be smarter than this. I think we talked about this before.. For the AMD driver the v1 page table should store the domainid in the iommu_domain and that value should be used everywhere For modes with a GCR3 table the best you can do is to de-duplicate the GCR3 tables and assign identical GCR3 tables to identical domain ids. Ie all devices in a group will eventually share GCR3 tables so they can converge on the same domain id. > - Guest view > Pass-through Device1 (vRID 3) w/ vDomainID A + PASID 0 > Pass-through Device2 (vRID 4) w/ vDomainID B + PASID 0 > > We should be able to workaround this by changing the way we assign hDomainId > to be per-device for VFIO pass-through devices although sharing the same v1 > (stage-2) page table. This would look like. As I said, this doesn't quite work since the VM could do other things. The kernel must be aware of the vDomainID and must select an appropriate hDomainID with that knowledge in mind, otherwise multi-device-groups in guests are fully broken. > - Guest view > Pass-through Device1 (vRID 3) w/ vDomainID A + PASID 0 > Pass-through Device2 (vRID 4) w/ vDomainID B + PASID 0 > > This should avoid the IOMMU TLB conflict. However, the invalidation would > need to be done for both DomainId 1 and 2 when updating the v1 (stage-2) > page table. Which is the key problem, if the VM thinks it has only one vDomainID the VMM can't split that into two hDomainID's and expect the viommu acceleration will work - so we shouldn't try to make it work in SW either, IMHO. Jason