Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4860779rdb; Tue, 12 Dec 2023 11:14:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IFUa99A0ooNri0m9F+czraUCYup/Py6j6rvMH+yU1lhK+3tXWNjHj1zWYfUKlJwLHp4GUJj X-Received: by 2002:a17:90b:e8f:b0:28a:c110:e6e7 with SMTP id fv15-20020a17090b0e8f00b0028ac110e6e7mr923021pjb.56.1702408460491; Tue, 12 Dec 2023 11:14:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702408460; cv=pass; d=google.com; s=arc-20160816; b=fJ5vJ7ehhYbBuu4XmclmewZ3KTxlkZG9+7FBWODKiAKOXAx9uSxGJVaac3axR/lPj+ e/b3/2Tq7RHzU4DVQE6GP/4TKVp46aqky6buE8BaHyIgViJmU4GSpra5uZZsAF4e8S7P /qbIMu2Iq+dwYTuUCBXn4EtvQ/wjrcDgc6pUD3zNybx8PEgIvEn3gZtx1bkTRPWeIGkZ lmQrxrjgZw8GCCKkBeiYeNSV54UGiHbDq/+qg+ljM5orYcj0X78ItN9LJDmSDIDww6aa AX8RxzHO/RJqeV4wJ83V5k51MORHTR+vqARsOAG02wlPIQUeh+ZSlNpul7Znr06xMacb moDw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=qxIgn78l9TA3zeCregDIFyA6a17B6JaYjp616ND6rLA=; fh=ugZx6LhjCxrEZ2+wMd+ah5gpw1MPVUpk2PnbNjbIu4g=; b=YissVAkLdzV+ue7ApfOxsMel4DNbaFgO88JHEqmx3j8UVITqdWtFB7dsgXpvexMBxQ l68omgzdsFFmKhQUJgm7LesqNQHjgzDFhyFhsMtRB1uylfdtX/AWyZoGbFYNxgVtOw/0 Ak0Oc7hzUbgUbuHstE80IudDOfchiv9zU7A/XgNIj8GE74Vzjt+rnimkoFv8J/21vGU2 ipv2w4U5N70s3RoPE36KBgRLuXR2NH26tFKCmk80wJ/oVwQvzpkeqTbE1zUR4NKRM2Bd hxSyTyyegy5Sg4myFbkje2cWi+3bO8QgfXn1wNVgTgN+8whBEsDeWxjx9UK3ssAjK07U IupA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=GeoufRPj; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id v10-20020a17090a898a00b0028878f6a971si8332724pjn.99.2023.12.12.11.14.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 11:14:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=GeoufRPj; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id B6930802158B; Tue, 12 Dec 2023 11:14:17 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377280AbjLLTOB (ORCPT + 99 others); Tue, 12 Dec 2023 14:14:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235147AbjLLTNx (ORCPT ); Tue, 12 Dec 2023 14:13:53 -0500 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2089.outbound.protection.outlook.com [40.107.237.89]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7620E9; Tue, 12 Dec 2023 11:13:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RucWxNhADZcyCzzTNOnynGaQk+9VzqRsef2RBA5IavVsa2fh+tZhonq6CmKmWhLwaomxeii7GKBChXwaPx1gxwpNlGplgXznXMq8Ki0VqIUpO69aUTBXWYp1APqw2uE2BL8uVxfR0ACn86d6BHDvLPkU3SCUrcRY4C8+8JZolO+H4TWbtZGfYw2DnTrNEVG974zfjgWUrT44YFwIYON/JjPYPpNnso9p2IZnuY4DCs4BwGWX80fht5tEUZO0/hkvWmjLMUK+PI3djqgwK3LYej7QvSrx1f9jcCUNbYiUhUvQQy2g/fXKyO64x/YxxO1dcuzcLypdSUCwvREuhBZ/AQ== 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=qxIgn78l9TA3zeCregDIFyA6a17B6JaYjp616ND6rLA=; b=kmksvYvqyPlkZvINzNH0mTTYHNwmUGgvEJ8eNDUWYbVEyJth/MNifPwx/VhRi8D8x1CyqGF3qcFpxb7E8XR70eg8VMkOf3PSI7B6Ct8otm1cUzSBj9Xj53huUjxxjNMZs4cmixl+g9iLTVc3EDqCXkK5L0o7aWIOmm/HZsBtJeyCaPRzKWpmsXG3XOdtRbK+NIoy4F9+ZS7grshkQZbxSpQvYgd56mciuF7tHpIoEuPfliGJZGGDylapGZc3KSasa0hZkm7lam6KxmAat+hU5GkR/uUmGp6w4m7Xomuw/CWkeElWO+VPK+31e3URQhqNcVBaoFcUKBVo6jTsJwajwQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=oracle.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) 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=qxIgn78l9TA3zeCregDIFyA6a17B6JaYjp616ND6rLA=; b=GeoufRPjvyvlMzDrLYU2tHmWhKw285rMEryx2chPg8CIffCs4Onb8QvYdZRmOkynm/IH78Zb9YY+TC+kb18ikpctD2sOugM2A/Se4OJ7p+tuDC8NUKpoyxcjM8BOFC68xb5EYPwC1uEva9NDRYX6z9fYigcZgI4a9qU3MHP9HtkXWl7cvO7h3CT9v2g03YuebaXYL1Kp4nNBmsor1Et7OSru2JRpe/r6HfSLxFKf3c69zE6T52SBhWCf+wZ1umOv8tHLywbIJ2Stgs3EZja/ItWM/90I81D9vN4tCfkModolMKnu2NOZS5dKqCye3WCtH6tbxt8ZyxiECQ4eroO2xQ== Received: from CYZPR11CA0014.namprd11.prod.outlook.com (2603:10b6:930:8d::24) by MN2PR12MB4111.namprd12.prod.outlook.com (2603:10b6:208:1de::22) 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 19:13:43 +0000 Received: from CY4PEPF0000EDD7.namprd03.prod.outlook.com (2603:10b6:930:8d:cafe::62) by CYZPR11CA0014.outlook.office365.com (2603:10b6:930:8d::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.26 via Frontend Transport; Tue, 12 Dec 2023 19:13:41 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by CY4PEPF0000EDD7.mail.protection.outlook.com (10.167.241.211) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.18 via Frontend Transport; Tue, 12 Dec 2023 19:13:41 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Tue, 12 Dec 2023 11:13:40 -0800 Received: from drhqmail202.nvidia.com (10.126.190.181) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Tue, 12 Dec 2023 11:13:39 -0800 Received: from Asurada-Nvidia (10.127.8.9) by mail.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41 via Frontend Transport; Tue, 12 Dec 2023 11:13:38 -0800 Date: Tue, 12 Dec 2023 11:13:37 -0800 From: Nicolin Chen To: Jason Gunthorpe CC: Yi Liu , "Giani, Dhaval" , Vasant Hegde , Suravee Suthikulpanit , , , , , , , , , , , , , , , , , , , , , , Subject: Re: [PATCH v6 0/6] iommufd: Add nesting infrastructure (part 2/2) Message-ID: References: <20231117130717.19875-1-yi.l.liu@intel.com> <20231209014726.GA2945299@nvidia.com> <20231211215738.GB3014157@nvidia.com> <20231212144421.GH3014157@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20231212144421.GH3014157@nvidia.com> X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD7:EE_|MN2PR12MB4111:EE_ X-MS-Office365-Filtering-Correlation-Id: 40ed9ee7-b978-417e-b5e1-08dbfb4673dd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wqwPhiEjfLhOGTQ3FQn3n80PbFLpzpHEX2G41Bk1AKj5TiZwlAL1f7Hm/oI1q34U9pNiQfFRUNiERJxkNNliaubjidSF7eM4fbNWloz4csqACwrReNn++r0d8kJG58rAupO0P9CX95Sk4cph2QBTDc/aVHy9qi4VjJRFd8IGfQpJTUWyB933XYCcRoGFHgo5QtwrHnD2EPNjG4204P+7hFYYjQOWl88XOMmRkVuio9Xs/HfgqBLKdmXTTb7iGlJiLT4WhQe9Rq8h+sDL7bzHWpI6qk5kSjZckLc0C/qJM+5J//fxXCfCRNNu1n+WwWix++55gEowEgG+Q04JX3mLNNKtvUBr/G90xz9a8Z/ju8v13n40dh7cTYwDwyNZxV02+yM4E5lLgbj8i6UH/VDIxoam01HfojsK5vkBLbEU8B1N+9OCLj0fCn2EpEIzL0vTgYicBOd2oTUTaLqRAxIwssXYSpVJy2NONNkzEPdhIIRjd2cucvUzemeZvycV2EpGIP5PxEdGD8Nm/KfZVUIvBr/Qe/Fejyx21KxFS3rKcaL88wyiVDuWn14zvwO1HQhwhhixvijeBNegtynEQv/NuZ68cDUmcizU8AocIiWNTfnr0JNA9DswctDWfuPZhY/NXOAfBvIUeisBgu8qWNEt9DWZK4lB85rbWKbJSUONtSjdEHSpDWekAUZWh7btQP8AKZQubRc29OkFc3Vb4tZcKCsazZ48sXpXvIXrx5I3KLVlJNNvCEr0SeGBILFrbjcw X-Forefront-Antispam-Report: CIP:216.228.118.232;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge1.nvidia.com;CAT:NONE;SFS:(13230031)(4636009)(396003)(376002)(136003)(39860400002)(346002)(230922051799003)(451199024)(1800799012)(82310400011)(186009)(64100799003)(36840700001)(46966006)(40470700004)(82740400003)(41300700001)(8676002)(7636003)(356005)(316002)(8936002)(6636002)(70586007)(70206006)(478600001)(33716001)(7416002)(86362001)(54906003)(26005)(5660300002)(9686003)(336012)(426003)(36860700001)(6862004)(83380400001)(2906002)(4326008)(47076005)(40480700001)(55016003)(40460700003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2023 19:13:41.2155 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 40ed9ee7-b978-417e-b5e1-08dbfb4673dd X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.232];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD7.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4111 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 howler.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 (howler.vger.email [0.0.0.0]); Tue, 12 Dec 2023 11:14:17 -0800 (PST) On Tue, Dec 12, 2023 at 10:44:21AM -0400, Jason Gunthorpe wrote: > 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. I see. This is the object to hold a shared stage-2 HWPT/domain then. // iommufd_private.h enum iommufd_object_type { ... + IOMMUFD_OBJ_VIOMMU, ... }; +struct iommufd_viommu { + struct iommufd_object obj; + struct iommufd_hwpt_paging *hwpt; + struct xarray devices; +}; struct iommufd_hwpt_paging hwpt { ... + struct list_head viommu_list; ... }; struct iommufd_group { ... + struct iommufd_viommu *viommu; // should we attach to viommu instead of hwpt? ... }; Question to finalize how we maps vRID-pRID in the xarray: how should IOMMUFD_DEV_INVALIDATE work? The ioctl structure has a dev_id and a list of commands that belongs to the device. So, it forwards the struct device pointer to the driver along with the commands. Then, doesn't the driver already know the pRID from the dev pointer without looking up a vRID-pRID table? // uapi/linux/iommufd.h struct iommu_hwpt_alloc { ... + __u32 viommu_id; }; +enum iommu_dev_virtual_id_type { + IOMMU_DEV_VIRTUAL_ID_TYPE_AMD_VIOMMU_DID, // not sure how this fits the xarray in viommu obj. + IOMMU_DEV_VIRTUAL_ID_TYPE_AMD_VIOMMU_RID, + IOMMU_DEV_VIRTUAL_ID_TYPE_ARM_SMMU_SID, +}; + +struct iommu_dev_assign_virtual_id { + __u32 size; + __u32 dev_id; + __u32 viommu_id; + __u32 id_type; + __aligned_u64 id; +}; Then, I think that we also need an iommu_viommu_alloc structure and ioctl to allocate an object, and that VMM should know if it needs to allocate multiple viommu objects -- this probably needs the hw_info ioctl to return a piommu_id so VMM gets the list of piommus from the attached devices? Another question, introducing the viommu obj complicates things a lot. Do we want it to come with iommu_dev_assign_virtual_id, or maybe put in a later series? We could stage the xarray in the iommu_hwpt_paging struct for now, so a single-IOMMU system could still work with that. > > > > > 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 OK. FWIW, I think either VMM or iommufd core knows which nested HWPT the device is attached to. If we ever wanted to keep it in the domain op list, we could still do that by passing in extra domain pointer to the driver. > > 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 Then should we "s/cache_invalidate_user/iotlb_sync_user"? Thanks Nicolin