Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4686336rdb; Tue, 12 Dec 2023 06:46:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IEKvVEHoP+q68mSTzfr6SrYS2PSIM9siNWL/lRVGxTOcFhtLlFYDZdqOQRnSuqXDuAUeoDx X-Received: by 2002:a05:6a00:10d3:b0:68f:d1a7:1a3a with SMTP id d19-20020a056a0010d300b0068fd1a71a3amr6888278pfu.8.1702392379044; Tue, 12 Dec 2023 06:46:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702392379; cv=pass; d=google.com; s=arc-20160816; b=CrYidtt5qfr3Bm6LzDNEp1gvGftzfWSVfLgFzcY6saAwzH8CTk4ZFjMePD5b7UHOAB plo8apgXUwE251XbM51pgrX1vnrVkAOzD+hOdkJ4qr7k9jOSJU/lLXRHy2bl3WCSlt9e 7Hejs+cb+JLgA7rDAmhDkNGCDyGadoIqTyJcnKRWVNY5uRh/HaLWtv/HG29nE0tL36jE qYe4WB+0Wa9G4ZsE0L7e/s9k02BS9S6BtrEolZz4c8rk+R0DEI41jC427QWFBE13xgmL +XmyVbFMhF+SY0rhkFq2O3ix/K+ht9jcUUDpjGZtkBojhXiF8HhtsZSqNalGhxEB6lh0 KT8A== 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=vY2qKlJ9EbI1AwONZ6QBUFy6NGALblf6LOnRZbcu2EU=; fh=jbzFMiWpoaIZWDSUNY5tSpdjZ8nCzoyqVtg5Sako1Xs=; b=fovZSUEuypbgG/aO9zg7Y2UQW6v25AKxsFVeWtsFDeQxuUPc5/b3ESeqCmfoY7KjuU uILBcOGIZXsZABbTNEbdx+5rw2f3T2mc0nRENqK95Rzfea0NF8mcQCpJZoSBo/mEGHLs cAOvXgVFfKAfRNP5hPCzGoTYqLd9RGnrtpJNqaQuNck+OS3fhp9SRu6goZDI0ahnnxIO DCLm4Nx2ZXI+9U2LgvhSKEMnaGFcyCsdWWwHMbS/2WSVtDbXVa0a8Z2THz4Zh+VpK5Cr q1rnySfxbaIOpATAy4WYOn0Etth4FfYiyXL38jnXEBwI0PJdt7KC3/n4YSlLYjv18EpJ z/2g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=XpR3ehTc; 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.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id y186-20020a6364c3000000b005c6818b5a24si7825717pgb.245.2023.12.12.06.46.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 06:46:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=XpR3ehTc; 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.33 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 lipwig.vger.email (Postfix) with ESMTP id 8B2B3807C850; Tue, 12 Dec 2023 06:45:06 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376964AbjLLOoh (ORCPT + 99 others); Tue, 12 Dec 2023 09:44:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376912AbjLLOoU (ORCPT ); Tue, 12 Dec 2023 09:44:20 -0500 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2063.outbound.protection.outlook.com [40.107.220.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D537F4; Tue, 12 Dec 2023 06:44:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TTWGCckd9IafTFm2Hc2mSp2P7N/nLja25WlttUw8KEjboq80Aotgd5DcX/pkxdY/0UgANI2/Du7IoAAw4pQVqn8uu8GBG5UWXppMHjZ5qz14DcNpf1q13m6lyGDwjbTTDEIuPAXjHYKdqztNVQuEK7syb+HVDUj9NOekF44EzrH/tP/cKG3i4SUYq6ajR4uX+jpjFmq1BZNz3npN5Yfct0qhZqZ2GsfUMAGXJhLjUj8cG8EHek2YH4euEBT7UJ2PXFv78ms6b4l1zXeeRPQAaF/A9sZU5XtsWnjkzamTl/c6Mjvdf/y7Nprw7Tsw0Tg6IpRRsvQV9KR5yUCDIQ84QQ== 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=vY2qKlJ9EbI1AwONZ6QBUFy6NGALblf6LOnRZbcu2EU=; b=O5rv0nqSQy4/AZrhTDmVop89iofjBbjl5vwoFu5mJY3VT0NP4YjYjg3zB8Uw8YguWJvHps/qsoq0QrYbvOnFvduiOg4YMcAbkhQAWa+W640lJETMpahRtvO/ptE0Kc2+gdmmMkbE0tcK5n2fd9BF3LZsRRxj+qlbTxHrEV6vvSxPmKmW2XFSLaN+NTKIl8NonXAKO9lV87bX7OzRQ+FrqCAzaNbW5BpqGNPTH89uOL+TkafReTELu9RMfdGk3G2qVSQG4jXYuYJpuCTtpqi2B/MgX0hyXNnM+fUKG0pu2mcKDCrn6HK3B03xHOBzCJefBjzekMwsxQYvZkS7HmiSew== 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=vY2qKlJ9EbI1AwONZ6QBUFy6NGALblf6LOnRZbcu2EU=; b=XpR3ehTcoY1OlJs75J1u49Iy4v+QXGhNNOt6A5ayoPBMbdDbMLsQCR6Sl5G2/TbbRaJQSvtw7EyWXr3jHAOVz7mB1hMeb7wc6W7tEDr6jcs9VCOIdo3e09IbkGemJZXyN9wlOZMy7Aaa3HZcjUnFGqnnkL8PQDHvJ/8NIzYj+5aonOcLpJn8Vx0RjB+m0cfPBIgZ/ylvZb5mqU8snobi01pKGky5Qr0AmZyQDaKP+n837P/Uw1aJeDGJVoz8HPzFrRytV89eQCxUa4e6ZcB7qnqgQS9MYLEmskpvGwFrp4BsvMgJwZR8e+7KtAlbxL12+L702biPA5z02IDkLNdUzw== 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 MW4PR12MB6804.namprd12.prod.outlook.com (2603:10b6:303:20d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.33; Tue, 12 Dec 2023 14:44:22 +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.7091.022; Tue, 12 Dec 2023 14:44:22 +0000 Date: Tue, 12 Dec 2023 10:44:21 -0400 From: Jason Gunthorpe To: Nicolin Chen Cc: Yi Liu , "Giani, Dhaval" , Vasant Hegde , Suravee Suthikulpanit , joro@8bytes.org, alex.williamson@redhat.com, kevin.tian@intel.com, robin.murphy@arm.com, baolu.lu@linux.intel.com, cohuck@redhat.com, eric.auger@redhat.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, zhenzhong.duan@intel.com, joao.m.martins@oracle.com, xin.zeng@intel.com, yan.y.zhao@intel.com Subject: Re: [PATCH v6 0/6] iommufd: Add nesting infrastructure (part 2/2) Message-ID: <20231212144421.GH3014157@nvidia.com> References: <20231117130717.19875-1-yi.l.liu@intel.com> <20231209014726.GA2945299@nvidia.com> <20231211215738.GB3014157@nvidia.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: MN2PR06CA0021.namprd06.prod.outlook.com (2603:10b6:208:23d::26) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|MW4PR12MB6804:EE_ X-MS-Office365-Filtering-Correlation-Id: 3c772e91-8a67-4618-6820-08dbfb20d435 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1PFYaSaOtyyCbXYU3vj+4NuT9+ys9/91oBPei+G9QhsnrTGBvocgZmsZY38C241AbQhsGJkkrfiOo44uDH07ir5CXcq6RUnwON0kU0qeODPPxE7FUxLlDCK2BpKaSphtBuBaw3Er4XqzU1yOy1A0oyE4Npf93ZTVFAu8LdxLke9l1Q0NAV+sR0QrPNiXv2bfS3HMM0IgSH4ml/6ZEVujSv/qWD93CQDnY4M8EZwuq7xToo1NOnzD4/6K4+tiy2GxR6S2LLbqSLZiVjQArWsaoRg207WWrc8NqZ4icBH+YoeO5sGAJvjZkKvM/G2wRX0gPtUUkYB33sp4hYqPQvAn+DwYERIWgqZhfte1TSVRcrqxId218mHp9q416/nUjYFLQDB4cjP5bDfPSp3DgGhyGsgPqrZcbd3Qe19kuCFIpX7nHDl0gAQvWDClDAqjsUo4Q78QAJm88hU3IB+ATKSm2TigX9dRvJaaGL+IP9/XhjBJhfPc5wyLcXbLwU4NcKaEUJeIbbYWDwUJWFvX5ipcoa1/2PczHFrQoPKiv4tJoo2NoL7pJFx8Q48b3+7jkmps 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)(376002)(366004)(346002)(396003)(230922051799003)(1800799012)(186009)(451199024)(64100799003)(38100700002)(6636002)(66476007)(54906003)(66556008)(36756003)(33656002)(86362001)(66946007)(6506007)(83380400001)(1076003)(2616005)(6512007)(6486002)(2906002)(316002)(37006003)(26005)(478600001)(8676002)(5660300002)(4326008)(8936002)(41300700001)(7416002)(6862004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?PfYkKXHCJwfSJEXmj9f9/wvpAEtmhGkI6f4a/6Fh2XlmekyPCwPWNxyW2uwA?= =?us-ascii?Q?9CqSMfcFq0JeOnHCZQ5Tjl2L5258fm8egS3tJ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-ascii?Q?za+RIRqzFgWE+aHYHJfw04EEZD2wiRExay1V+pJMEhxfmdmXjlNiey7V1bJJ?= =?us-ascii?Q?76iSOd8yBLoSGuz77VDeeBcCgc6ZtnQV8zR69O1T6oXgtj3goO4kl+ucLqy2?= =?us-ascii?Q?kuo5dmxfcuGD00dEN+sY7ueLT9NvqOxeG1MoCtiLxFCddbFZHygbAbYiix2C?= =?us-ascii?Q?42FFv6E/1o5p4O7j5Xu9pwB4Uj50FbliQaOpthnLBa92KVhrea+iD6xb0Vxf?= =?us-ascii?Q?gTMHaPuqocC9Y8jpjtvCQe+71+R8QEZB2XTdcggIlFJl2n/DkKfFxOM3Xjip?= =?us-ascii?Q?NeHGypd59zynNOjYI+t4AGxQ1rROI4aUlsQk+9EYqz7SqWa1RxMaVWqzEhcx?= =?us-ascii?Q?u0QDC/K74RLxZ6RZclE15Src1b06okL6FCb0u7qJA0MOAcZo8h5tTYGFM5FI?= =?us-ascii?Q?YoMGmwD43I5B2WqFuApy0ObtbTfSnO9Tp36zMg7iUnt0RDdRokivIv08vCH1?= =?us-ascii?Q?RGbTdmt0Xmom/KIA2ASuJeDa0q0ZtBuGjQagOF2vRWiwjDPPyEwa6yn1Qm3E?= =?us-ascii?Q?aG+lXofnAiWKeGCLQqBVZ8waPgrOq9ZB0PEdK9DlxYlsFHXroSGOAeUesI1E?= =?us-ascii?Q?4vdpYEDBoi3wz7LPQ9EzBIIBxSJu3DfS7UNWyJJA?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3c772e91-8a67-4618-6820-08dbfb20d435 X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2023 14:44:22.2140 (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: YU6yEARZupR7scGTLFZJ44ctQMidS4rYJPnFTrkBD+pyFihyiL/9rXOqqQLQMu/q X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6804 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Tue, 12 Dec 2023 06:45:07 -0800 (PST) On Mon, Dec 11, 2023 at 11:30:00PM -0800, Nicolin Chen wrote: > > > Could the structure just look like this? > > > struct iommu_dev_assign_virtual_id { > > > __u32 size; > > > __u32 dev_id; > > > __u32 id_type; > > > __u32 id; > > > }; > > > > It needs to take in the viommu_id also, and I'd make the id 64 bits > > just for good luck. > > What is viommu_id required for in this context? I thought we > already know which SMMU instance to issue commands via dev_id? The viommu_id would be the container that holds the xarray that maps the vRID to pRID Logically we could have multiple mappings per iommufd as we could have multiple iommu instances working here. > > > > IOMMUFD_DEV_INVALIDATE should be introduced with the same design as > > > > HWPT invalidate. This would be used for AMD/ARM's ATC invalidation > > > > (and just force the stream ID, userspace must direct the vRID to the > > > > correct dev_id). > > > > > > SMMU's CD invalidations could fall into this category too. > > Do we need a different iommu API for this ioctl? We currently > have the cache_invalidate_user as a domain op. The new device > op will be an iommu op? Yes > And should we rename the "cache_invalidate_user"? Would VT-d > still uses it for device cache? I think vt-d will not implement it > > > I previously drafted something to test it out with iommufd. > > > Basically it needs the pairing of vRID/pRID in attach_dev() > > > and another ioctl to mmap/config user queue(s): > > > +struct iommu_hwpt_cache_config_tegra241_vcmdq { > > > + __u32 vcmdq_id; // queue id > > > + __u32 vcmdq_log2size; // queue size > > > + __aligned_u64 vcmdq_base; // queue guest PA > > > +}; > > > > vRID/pRID pairing should come from IOMMUFD_DEV_ASSIGN_VIRTUAL_ID. When > > a HWPT is allocated it would be connected to the viommu_id and then it > > would all be bundled together in the HW somehow > > Since we were talking about sharing stage-2 domain, the HWPT > to the stage-2 domain will be shared among the vIOMMU/pIOMMU > instances too? The HWPT for the stage 2 should be shared > I think I am not quite getting the viommu_id > part yet. From the other side of this thread, viommu object > is created per vIOMMU instance and each one actually tied to > a pIOMMU by nature? Yes Jason