Message ID | 20230510205054.2667898-1-mshavit@google.com |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3918190vqo; Wed, 10 May 2023 14:04:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Kp1P2a9QB/WgRTZyJqDB7PlS0ZZ2Vf+AL930y0gXP276TQ2z8A5mv7ViU2NFRUbLIYCr1 X-Received: by 2002:a05:6a20:72a2:b0:100:c4f1:72a0 with SMTP id o34-20020a056a2072a200b00100c4f172a0mr14277841pzk.3.1683752642389; Wed, 10 May 2023 14:04:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683752642; cv=none; d=google.com; s=arc-20160816; b=NWZOT3ZdKVzbFfui5IcaHd+m9lyLFnpuahuAq+SK/AezlEN7i8WaBVlc/bPQ1qIBXG /9JbD5eEjPQf6mLGfcxUTkBaXOh9ibAgdXJmfCdaVt4gVuETeFPGnjYNqqA72wr0EFEr SKESKB6oxgnR6i4J4P3genb9b2rSPLPGpNQ2Ck3zhSUhEnQVtLHefGSQEEwRz9DFwTlJ ltdEpimAk+QvjPnF4gBo68ZV131Y7STsVneOaXbnlx7Fr51ylNhClEOc6TmPO+hdti0A UYEbkCwptx+Up7PMrXlYnSdsVkW/p1F9FW3w8oOpymATYAjvQPdra2XKK+HAO6cwJrQK mbPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=0aTcNguqiO/niELSSlE0no2SkBRP8ATZbw67QF2nRQk=; b=WWMMaKekmm2yorRUK8wkl51ntqNGUd1UDSAHtAz2pxxqfbgHNS79i2A06zL3sFGVvQ 2PUTLfqBT303wUwD51RfMunOZt7XBz2jL1rqS6pdkLte7SlQYPwZUT6HCQFc+F8bRrs9 KGrzjdHVlgYQ//8Ha0UJk7Pc6C433Ev9j0nAjmNt+SWChJcBxND1aXZnooivLmZGDbhl 0DKxMcBOS/p26QCwiZ6aw/SmngmRfoOk+r/aJhrPbjxPBhTcvKmGWaVM/AdUOhtywtYq 9RS67xP64Lt755ALf+iF59GilSADJGOzpChsItC9ZRT0gogMdRV8CMgCO7LQ0WaIjBIm 3+Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=InN7niDj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e1-20020a63ae41000000b00524cf947602si4793381pgp.686.2023.05.10.14.03.50; Wed, 10 May 2023 14:04:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=InN7niDj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237154AbjEJUwZ (ORCPT <rfc822;jeantsuru.cumc.mandola@gmail.com> + 99 others); Wed, 10 May 2023 16:52:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237106AbjEJUvp (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 10 May 2023 16:51:45 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9EE57A9D for <linux-kernel@vger.kernel.org>; Wed, 10 May 2023 13:51:16 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba6386e6f7aso2797595276.3 for <linux-kernel@vger.kernel.org>; Wed, 10 May 2023 13:51:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683751860; x=1686343860; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=0aTcNguqiO/niELSSlE0no2SkBRP8ATZbw67QF2nRQk=; b=InN7niDjvzNlMwZgp0X9PCi1hbm0hme3DLwHHM5cbEXnMvmESf+lItvZ2we7PiP1Jd iLasW0mWeEsw/7kx+e6+kKCfDxx7N2Hl7BcQmGrR/74N30v/F/dWlu/SF+UaIO8w2XBB idN/Ia6wRZOmZs/VXu3MDhsdNVyujZDnTEiue2pDp6fIfpSOieczl3CwyRbg+5BrpkXC ySVpOJjpzRVdtPumfPRya4b3kryklFvW/BIEu8ip0n1Dl3pc7L6IdHwgFv2o30B7W5hO eN3QoISqVFpr/AJINCNJjcbi6smtzfWkgmXLKHmXoWBpHs4OwLFy4+S8LwoRg/J+1nUA nkmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683751860; x=1686343860; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=0aTcNguqiO/niELSSlE0no2SkBRP8ATZbw67QF2nRQk=; b=gCZH1PfyKx4n6BrNZ5HsRTddU0asifKquHZRC5zQR53JXzHgqZ+Cmn4RvgDBtUdNBN 9YFb5YoFHzo4zry6/hLxTN7U9YQ91BxeU2G9ZVIdts40AVl692EIMUw5ossWRKaXOCBG DIzik5n3K727lrJNgiOQPjzOJYzMx+j5P1s6UaEKTM/vMtBbmHzEFIXhMqcy0kYQE1QY uvUQ6GRD4J7qMSucQg59rjeXSP6X/yIQWVkpGC5pNEo30rdNTqUYBceHqDd+DYczBN6A gvHynPfPcwwHtXKZHL2BMEIec79iKwAuKWELs4BjJKDH+JNMfhP2x2tSy0Um/DwLNJ9H LC9A== X-Gm-Message-State: AC+VfDzHOg1sTv/pl5Vb4ELuKSFT/qhmag0vQNxEfXxo9d5Tfa5VSAdn JqlD1oaLQ3z06gTaJjtL8ikRZZgBI9M7 X-Received: from mshavit.ntc.corp.google.com ([2401:fa00:95:20c:2b1f:8d06:7923:f154]) (user=mshavit job=sendgmr) by 2002:a25:6782:0:b0:b9d:894f:c9a8 with SMTP id b124-20020a256782000000b00b9d894fc9a8mr8218792ybc.0.1683751859947; Wed, 10 May 2023 13:50:59 -0700 (PDT) Date: Thu, 11 May 2023 04:50:47 +0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.40.1.521.gf1e218fcd8-goog Message-ID: <20230510205054.2667898-1-mshavit@google.com> Subject: [PATCH v1 0/5] Add PASID support to SMMUv3 unmanaged domains From: Michael Shavit <mshavit@google.com> To: Will Deacon <will@kernel.org>, Robin Murphy <robin.murphy@arm.com>, Joerg Roedel <joro@8bytes.org> Cc: Michael Shavit <mshavit@google.com>, jean-philippe@linaro.org, nicolinc@nvidia.com, jgg@nvidia.com, baolu.lu@linux.intel.com, linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765542610758953681?= X-GMAIL-MSGID: =?utf-8?q?1765542610758953681?= |
Series |
Add PASID support to SMMUv3 unmanaged domains
|
|
Message
Michael Shavit
May 10, 2023, 8:50 p.m. UTC
Hi all, This patch series refactors the arm-smmu-v3 driver and implements the set_dev_pasid functionality for DMA and UNMANAGED iommu domains. As part of this effort, we also refactor the arm-smmu-v3 driver such that each iommu domain represent a single address space. In particular, stage 1 domains hold a single ContextDescriptor instead of the entire STE entry. The refactor is arguably valuable independently from the set_dev_pasid feature since an iommu_domain is conceptually closer to a single address space than an entire STE. In addition this unlocks some nice clean-up of the arm SVA implementation which today piggybacks SVA domains on the "primary" domain. This patch series makes some changes to SVA and PCIe, but I haven't tested those features. The cd table allocations could also be further optimized for masters that don't support multiple context. However, the SMMUv3 Nested translation patch series has me worried about this change. At a glance, it seems like this refactor conflicts with its proposed uAPI. Is this refactor no longer an appropriate clean-up or path forward for set_dev_pasid support? Or could a uAPI that only exposes a single CD instead of the entire STE be an appropriate fit for the nesting use cases? Thanks, Michael Shavit Link: https://lore.kernel.org/all/CAKHBV24u9b-=cJCF=Kt=3B4hynOyNr6gmi0F6zpO6b1mHc0Z7g@mail.gmail.com Link: https://lore.kernel.org/all/cover.1683688960.git.nicolinc@nvidia.com/ Michael Shavit (5): iommu/arm-smmu-v3: Move cdtable to arm_smmu_master iommu/arm-smmu-v3: Add has_stage1 field iommu/arm-smmu-v3: Simplify arm_smmu_enable_ats iommu/arm-smmu-v3: Keep track of attached ssids iommu/arm-smmu-v3: Implement set_dev_pasid .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 46 +- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 432 ++++++++++++------ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 44 +- 3 files changed, 344 insertions(+), 178 deletions(-)
Comments
On Thu, May 11, 2023 at 04:50:47AM +0800, Michael Shavit wrote: > Hi all, > > This patch series refactors the arm-smmu-v3 driver and implements the > set_dev_pasid functionality for DMA and UNMANAGED iommu domains. As part > of this effort, we also refactor the arm-smmu-v3 driver such that each > iommu domain represent a single address space. In particular, stage 1 > domains hold a single ContextDescriptor instead of the entire STE entry. I'm not sure what you mean "holds" a ContextDescriptor? Ideally the iommu_domain should only hold a pointer to some table top. Depending on the domain type this would be a S1 IOPTE table, S2 IOPTE table or a CD table. Plus the non-table domains like IDENTITY and blocked. Logically when an iommu_domain is attached to a device or a PASID a STE or CD is generated from the iommu_domain's configuration but the iommu_domain doesn't "hold" it When a kernel-owned CD table is used it should be held someplace else, certianly not in the iommu_domain. Logically as a per-device structure, but maybe with optimizations for sharing. > The refactor is arguably valuable independently from the set_dev_pasid > feature since an iommu_domain is conceptually closer to a single address > space than an entire STE. In addition this unlocks some nice clean-up of > the arm SVA implementation which today piggybacks SVA domains on the > "primary" domain. I always thought of this as sort of a pre-calculation of the STE, that gets cached in the iommu_domain? Not sure the pre-calculation is that valuable though.. > path forward for set_dev_pasid support? Or could a uAPI that only > exposes a single CD instead of the entire STE be an appropriate fit for > the nesting use cases? The uAPI is to create an iommu_domain that holds a CD Table Top located in user memory, it cannot deviate from this. These kinds of iommu_domain's can only be pointed at by STEs. Again it doesnt really "hold" the STE, but we can compute a STE that points to the SD Table that it does hold. Other than this, it is good to take this project on, getting PASID support aligned with the new API is something that needs to be done here! Thanks, Jason
> Logically when an iommu_domain is attached to a device or a PASID a > STE or CD is generated from the iommu_domain's configuration but the > iommu_domain doesn't "hold" it > Ah yes, I was using iommu domain and arm_smmu_domain interchangeably here since there's a 1:1 mapping between the two. In the current smmuv3 implementation, arm_smmu_domain holds the s1cfg structure which represents the s1 portion of an STE. > I always thought of this as sort of a pre-calculation of the STE, that > gets cached in the iommu_domain? Not sure the pre-calculation is that > valuable though.. I think we can consider the case where an iommu domain is attached to multiple masters as a form of pre-calculation and resource sharing. When attaching an iommu domain that has been attached before, its arm_smmu_domain contains an already finalized STE configuration that can be immediately written to the smmu. I don't think there's anything specific to SVA about this behavior however, SVA will do the same amount of work whether the cd table is owned by some special iommu domain or by the arm_smmu_master (since we require that special iommu domain be attached to the master and disallow detaching it). > Ideally the iommu_domain should only hold a pointer to some table top. Depending on the domain type this would be a S1 IOPTE table, S2 IOPTE table or a CD table. Plus the non-table domains like IDENTITY and blocked. Gotcha. So this patch series should be less aggressive, but is probably still workable with the nested domain patch series: 1. For (stage 1) unmanaged/dma and sva domains, arm_smmu_domains should hold a single CD. For the nested domain series, arm_smmu_domain can alternatively hold an entire s1cfg. 2. arm_smmu_master should own an s1cfg (which holds a cdtable) that is used by unmanaged/dma and sva domains attached to this master. 3. arm_smmu_master also holds a pointer to the live s1cfg, which may either points to its owned s1cfg, or the nested domain's s1cfg, or null (bypass or stage2) > > path forward for set_dev_pasid support? Or could a uAPI that only > > exposes a single CD instead of the entire STE be an appropriate fit for > > the nesting use cases? > > The uAPI is to create an iommu_domain that holds a CD Table Top > located in user memory, it cannot deviate from this. These kinds of > iommu_domain's can only be pointed at by STEs. > > Again it doesnt really "hold" the STE, but we can compute a STE that > points to the SD Table that it does hold. > > Other than this, it is good to take this project on, getting PASID > support aligned with the new API is something that needs to be done > here! > > Thanks, > Jason
On Thu, May 11, 2023 at 11:52:41AM +0800, Michael Shavit wrote: > > Logically when an iommu_domain is attached to a device or a PASID a > > STE or CD is generated from the iommu_domain's configuration but the > > iommu_domain doesn't "hold" it > > > > Ah yes, I was using iommu domain and arm_smmu_domain interchangeably > here since there's a 1:1 mapping between the two. In the current > smmuv3 implementation, arm_smmu_domain holds the s1cfg structure which > represents the s1 portion of an STE. I mean to include the arm_smmu_domain too.. Generally this sort of seemed OK in the code, I just wouldn't use the word 'hold' - the iommu_domain may cache a computed STE or CD value but that the actual steering or context tables are held else where ie you insert an iommu_domain into a steering or context table, it does not 'hold' a table entry. > specific to SVA about this behavior however, SVA will do the same > amount of work whether the cd table is owned by some special iommu > domain or by the arm_smmu_master (since we require that special iommu > domain be attached to the master and disallow detaching it). The CD table for SVA definately should not be part of an iommu_domain, moving it to the master seems reasonable. > Gotcha. So this patch series should be less aggressive, but is > probably still workable with the nested domain patch series: > 1. For (stage 1) unmanaged/dma and sva domains, arm_smmu_domains > should hold a single CD. For the nested domain series, arm_smmu_domain > can alternatively hold an entire s1cfg. These are just pre computed values the can help when inserting the iommu_domain into a steering or CD table > 2. arm_smmu_master should own an s1cfg (which holds a cdtable) that is > used by unmanaged/dma and sva domains attached to this master. The arm_smmu_master's cd table can be inserted into a steering table > 3. arm_smmu_master also holds a pointer to the live s1cfg, which may > either points to its owned s1cfg, or the nested domain's s1cfg, or > null (bypass or stage2) The steering table either points to the CD table owned by the arm_smmu_master, a S1 domain held by an iommu_domain, or a S1 & CD table owned by userspace represented by a special nested iommu_domain and its internal parent. If a kernel owned S2 it attached then the S1 points at the CD table owned by the arm_smmu_master and the CD table points to the S2, same as if there was PASID (IIRC, from memory I don't have the spec here right now) Think about it in terms of what object owns the table and what other object(s) are inserted into the the table. Nothing "holds" a table entry. Jason
On 2023-05-11 05:33, Jason Gunthorpe wrote: > On Thu, May 11, 2023 at 11:52:41AM +0800, Michael Shavit wrote: >>> Logically when an iommu_domain is attached to a device or a PASID a >>> STE or CD is generated from the iommu_domain's configuration but the >>> iommu_domain doesn't "hold" it >>> >> >> Ah yes, I was using iommu domain and arm_smmu_domain interchangeably >> here since there's a 1:1 mapping between the two. In the current >> smmuv3 implementation, arm_smmu_domain holds the s1cfg structure which >> represents the s1 portion of an STE. > > I mean to include the arm_smmu_domain too.. > > Generally this sort of seemed OK in the code, I just wouldn't use the > word 'hold' - the iommu_domain may cache a computed STE or CD value > but that the actual steering or context tables are held else where > > ie you insert an iommu_domain into a steering or context table, it > does not 'hold' a table entry. > >> specific to SVA about this behavior however, SVA will do the same >> amount of work whether the cd table is owned by some special iommu >> domain or by the arm_smmu_master (since we require that special iommu >> domain be attached to the master and disallow detaching it). > > The CD table for SVA definately should not be part of an iommu_domain, > moving it to the master seems reasonable. > >> Gotcha. So this patch series should be less aggressive, but is >> probably still workable with the nested domain patch series: >> 1. For (stage 1) unmanaged/dma and sva domains, arm_smmu_domains >> should hold a single CD. For the nested domain series, arm_smmu_domain >> can alternatively hold an entire s1cfg. > > These are just pre computed values the can help when inserting the > iommu_domain into a steering or CD table Right, a stage 1 domain still logically owns the *contents* of a corresponding CD, however in this design it can no longer own a physical CD structure, because now every device attached to the same domain must maintain its own distinct copy. >> 2. arm_smmu_master should own an s1cfg (which holds a cdtable) that is >> used by unmanaged/dma and sva domains attached to this master. > > The arm_smmu_master's cd table can be inserted into a steering table Not sure what you mean there... STE.S1ContextPtr is essentially just a pointer to an array of CD structures (which only contains 1 element when PASIDs aren't enabled), so every master must own its own CD table directly. There is no viable indirection if you want the abstraction to bear any relation to reality. >> 3. arm_smmu_master also holds a pointer to the live s1cfg, which may >> either points to its owned s1cfg, or the nested domain's s1cfg, or >> null (bypass or stage2) > > The steering table either points to the CD table owned by the > arm_smmu_master, a S1 domain held by an iommu_domain, or a S1 & CD > table owned by userspace represented by a special nested iommu_domain > and its internal parent. > > If a kernel owned S2 it attached then the S1 points at the CD table > owned by the arm_smmu_master and the CD table points to the S2, same > as if there was PASID (IIRC, from memory I don't have the spec here > right now) Nope, CDs *only* represent stage 1 domains, stage 2 configuration is a property of the STE, i.e. is directly connected to the arm_smmu_master. Thanks, Robin.
On Thu, May 11, 2023 at 01:33:58PM +0100, Robin Murphy wrote: > > > 2. arm_smmu_master should own an s1cfg (which holds a cdtable) that is > > > used by unmanaged/dma and sva domains attached to this master. > > > > The arm_smmu_master's cd table can be inserted into a steering table > > Not sure what you mean there... STE.S1ContextPtr is essentially just a > pointer to an array of CD structures (which only contains 1 element when > PASIDs aren't enabled), so every master must own its own CD table directly. > There is no viable indirection if you want the abstraction to bear any > relation to reality. Yes, this is what I mean. Whenever we need a kernel owned CD table it comes from the smmu master and is inserted into the steering table owned by the arm_smmu_device. "Insert" is just the usual verb we tend to use when talking about these kinds of structures. Ie a PTE is inserted into a page table and points at a page - a page table doesn't hold a PTE owned by the page. So we have, basically, three kinds of tables, Steering/CD/IOPTE, they are owned by their respective objects arm_smmu_device/arm_smmu_master/arm_smmu_domain And we insert pointers from Steering -> CD -> IOPTE as appropriate. The only case a CD table is not in the arm_smmu_master is for nesting, but we can still say that the nesting domain is inserted into the steering table. Jason