Message ID | 20230817182055.1770180-1-mshavit@google.com |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp1989030vqi; Sat, 19 Aug 2023 05:17:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFhJulr50GolO37Brk1VelhzTpJ2paFSClv0Tw4rB6rcSBR1a+9G6ZTr9ppd3VgfguIyPez X-Received: by 2002:a05:6871:146:b0:1bf:12ff:db2c with SMTP id z6-20020a056871014600b001bf12ffdb2cmr2155785oab.22.1692447434741; Sat, 19 Aug 2023 05:17:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692447434; cv=none; d=google.com; s=arc-20160816; b=jF+fYTCI21kdMyIBUnPCPeF7zv8NjgaK7/qhRWjrvI0RWT9g963NrUuh5IwCaDu/Q7 u6vP70HDe/RiTmziJGdp95HaHlgEyiNiLHo2yK0p99LzH08ADMGAvYyV+cvsmC/DRWOl eaIqlA1RbPgMQcNTXovK2vQOHE3VIODXD5tl3mEhrwSyHFA3NVYGF1fuzODR3M97WeVX lb/cgBJoVG8rztXslgTxhi7S/+SZFl0xGetY3zx4bvhpZgqcyJS05jA5H00W2m3dW/qi yU8H8RzZHnq1URP2p9FmkGRh+tk+kLwmrPJo3mHYvPX6LTt9Y2vaVCCuHlLLn/xCcOkE QJlw== 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=P1Ja32sydfixX+83wX7h07TiF6qtFK7RLvIEmQEzvNQ=; fh=tYpv6qsltcODcibInAuLkJrpWg7wzPyO6zvJCzf1BPg=; b=DCs8//ScWvjrkVxd13YxnUrhOMr1ysNMH1CJBdWS/Nmk8rQ3JyF2RdAn4tDUCZ79F2 NbslnpVYg+Y2fwwio8gwodehQ4M7+SY/Jh/CP5YDz7u+XWksoK2BIDNnag6spJ8wQUhs VWhu3C2tk1vRdi+s2aQKk9L5jiQpGf3I+slCCQDgdndiE7Wqm5GUefaz6Mp5tzq35SkJ eVGm0WdTo30zhS0V/cgeHMHuL4Bw0Hzzket706tBGgJyGF4MpJXBoT7UjXYnVhNDmvDy 9vIxVVBrFxfGLK8qNcb9P9bLLLIQA3PykXgKdCAXl0EAg/GNtxPqZ8Jcr5eSTO9f3kvf jvfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b="EGY/X/6Y"; 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=google.com Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id q9-20020a17090a9f4900b00262e1adb2c7si4946317pjv.51.2023.08.19.05.17.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Aug 2023 05:17:14 -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=@google.com header.s=20221208 header.b="EGY/X/6Y"; 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=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6F7C37D815; Sat, 19 Aug 2023 01:36:48 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354303AbjHQSWc (ORCPT <rfc822;shaohuahua6@gmail.com> + 99 others); Thu, 17 Aug 2023 14:22:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354385AbjHQSWR (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 17 Aug 2023 14:22:17 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 222333A80 for <linux-kernel@vger.kernel.org>; Thu, 17 Aug 2023 11:21:48 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-58ee4df08fbso1354117b3.3 for <linux-kernel@vger.kernel.org>; Thu, 17 Aug 2023 11:21:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692296468; x=1692901268; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=P1Ja32sydfixX+83wX7h07TiF6qtFK7RLvIEmQEzvNQ=; b=EGY/X/6YVNMl9wzbAPSer6AbPxtT5SVrmVIrLiBJ4HefEC6GJnzjLMx63wS78W8BZH ZO9oTY/H9wO9usAxg5l79kKbNGet0y3WIkBtpAWsgCn7Hj+1NdW7fQhkCVSJxyVPT5yu dlfwCrhLlEsovyvOhNMR7htDif1TP5vOX/VCy9+XPNJ0juLdtELvNQ45X4zZWNK6557O 1wW1MKBqJp+8NGvevNI48itGw+hQJj3lyhNkBQRxNx05/MvfElFUN4v24zbJ9cOiBaNr IyfMdlMTbRNI8c5EpG4lObiBkYhELtMefggRYEu1hh/UywHXvZge7lz5/bxxYOP+3Ara bOeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692296468; x=1692901268; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=P1Ja32sydfixX+83wX7h07TiF6qtFK7RLvIEmQEzvNQ=; b=YmmehCvBpdS6GOeAom2BiEawmJU0dlkqL4HKbLS94GNsHr6D7LROGxMC5wZgAwzVX4 f87gqu1Zh5YhF4Nu2nucQm8dpNye2g/CapoYHaUY/Fe4HSFXhZRQ2lPNqJUL8oKBoDYC sPQawUcDw8fFySWOjaQ9DdqXrBVLqflpZaVnBIUMa4leI+m1iHPl8vRvdxCeIBPdiZ4J igINrs/l/SaphhJn6bpvj0dwFli6bQSYzURLdlEaHDGvWfDLi+UuEHzsdPv7Rvcjpdny xOgWPcgzVdIx7nQaPBuMzg9Houf2G1/gxzjja/JOgJUi07TIKrqbPcrd34r27tkqkkdt evtw== X-Gm-Message-State: AOJu0YytyMS9oGz+fFOt1gFiKFgxvp2iNKDF6A43fyEWlQv/OJJwasne K1kvMxhEj/ahvpZRDwAZHhcYTavv0Ad5 X-Received: from mshavit.ntc.corp.google.com ([2401:fa00:95:20c:4a77:fd20:7069:bdf9]) (user=mshavit job=sendgmr) by 2002:a81:4304:0:b0:581:3939:59a2 with SMTP id q4-20020a814304000000b00581393959a2mr2498ywa.3.1692296468378; Thu, 17 Aug 2023 11:21:08 -0700 (PDT) Date: Fri, 18 Aug 2023 02:16:22 +0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.rc1.204.g551eb34607-goog Message-ID: <20230817182055.1770180-1-mshavit@google.com> Subject: [RFC PATCH v1 0/8] Install domain onto multiple smmus From: Michael Shavit <mshavit@google.com> To: iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: will@kernel.org, jgg@nvidia.com, nicolinc@nvidia.com, tina.zhang@intel.com, jean-philippe@linaro.org, robin.murphy@arm.com, Michael Shavit <mshavit@google.com> 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_BLOCKED,SPF_HELO_NONE,SPF_PASS,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: INBOX X-GMAIL-THRID: 1774659761092881230 X-GMAIL-MSGID: 1774659761092881230 |
Series |
Install domain onto multiple smmus
|
|
Message
Michael Shavit
Aug. 17, 2023, 6:16 p.m. UTC
Hi all, This series refactors the arm-smmu-v3 driver to support attaching domains onto masters belonging to different smmu devices. The main objective of this series is allow further refactorings of arm-smmu-v3-sva. Specifically, we'd like to reach the state where: 1. A single SVA domain is allocated per MM/ASID 2. arm-smmu-v3-sva's set_dev_pasid implementation directly attaches that SVA domain to different masters, regardless of whether those masters belong to different smmus. If armm-smmu-v3-sva is handed iommu_domains that have a 1:1 relationship with an MM struct, then it won't have to share a CD with multiple domains (or arm_smmu_mmu_notifiers). But to get there, the arm-smmu-v3 driver must first support domains installed on multiple SMMU devices. This series depends on the CD table ownership refactor: https://lore.kernel.org/all/20230816131925.2521220-1-mshavit@google.com/ as well as the VMID IDA patch: https://lore.kernel.org/all/169087904450.1290857.11726985177314533259.b4-ty@kernel.org/#r This series is also available on gerrit: https://linux-review.googlesource.com/c/linux/kernel/git/torvalds/linux/+/24829/6 Thanks, Michael Shavit Michael Shavit (8): iommu/arm-smmu-v3: Add list of installed_smmus iommu/arm-smmu-v3: Perform invalidations over installed_smmus iommu/arm-smmu-v3-sva: Allocate new ASID from installed_smmus iommu/arm-smmu-v3: check smmu compatibility on attach iommu/arm-smmu-v3: Add arm_smmu_device as a parameter to domain_finalise iommu/arm-smmu-v3: Free VMID when uninstalling domain from SMMU iommu/arm-smmu-v3: check for domain initialization using pgtbl_ops iommu/arm-smmu-v3: allow multi-SMMU domain installs. .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 62 +++- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 348 +++++++++++++----- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 21 +- 3 files changed, 320 insertions(+), 111 deletions(-) base-commit: 6eaae198076080886b9e7d57f4ae06fa782f90ef prerequisite-patch-id: f701e5ac2cce085366342edff287a35d1cb82b9c prerequisite-patch-id: c8d21ff19c2c1dd18799a6b83f483add654d187e prerequisite-patch-id: 6ebba95cb12a723645843b4bd1bc45c94779d853 prerequisite-patch-id: 3f767e1c37d2996323c4f6d2a2d1912ab75281f7 prerequisite-patch-id: 5a4109fa3e22e2399ad064951c2ca1aeba4a68f7 prerequisite-patch-id: c4b3bd34b8be7afebd3e44bc4ec218d74753ce77 prerequisite-patch-id: 6d89e53518d25ac983ac99786950ee1a558c271f prerequisite-patch-id: 447219e565cadc34b03db05dad58d8e5c4b5a382 prerequisite-patch-id: 63adb2c3f97d4948d96a0d5960184f5ac814d7f7 prerequisite-patch-id: e71195fcf1aa56d8ef9d7403b9e4492c17b8fb84 prerequisite-patch-id: ba82add44850bf8fb271292020edb746aef93a65
Comments
On 2023-08-17 19:16, Michael Shavit wrote: > Record the domain's pgtbl_cfg when it's being prepared so that it can > later be compared to the features an smmu supports. What's wrong with retrieving the existing config from the io_pgtable_ops, same as all the other io-pgtable code does? Thanks, Robin. > Verify a domain's compatibility with the smmu when it's being attached > to a master belong to a different smmu device. > > Signed-off-by: Michael Shavit <mshavit@google.com> > --- > > drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 103 ++++++++++++++++---- > drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 + > 2 files changed, 86 insertions(+), 19 deletions(-) > > diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > index 447af74dbe280..c0943cf3c09ca 100644 > --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > @@ -2195,17 +2195,48 @@ static int arm_smmu_domain_finalise_s2(struct arm_smmu_domain *smmu_domain, > return 0; > } > > +static int arm_smmu_prepare_pgtbl_cfg(struct arm_smmu_device *smmu, > + enum arm_smmu_domain_stage stage, > + struct io_pgtable_cfg *pgtbl_cfg) > +{ > + unsigned long ias, oas; > + > + switch (stage) { > + case ARM_SMMU_DOMAIN_S1: > + ias = (smmu->features & ARM_SMMU_FEAT_VAX) ? 52 : 48; > + ias = min_t(unsigned long, ias, VA_BITS); > + oas = smmu->ias; > + break; > + case ARM_SMMU_DOMAIN_NESTED: > + case ARM_SMMU_DOMAIN_S2: > + ias = smmu->ias; > + oas = smmu->oas; > + break; > + default: > + return -EINVAL; > + } > + > + *pgtbl_cfg = (struct io_pgtable_cfg) { > + .pgsize_bitmap = smmu->pgsize_bitmap, > + .ias = ias, > + .oas = oas, > + .coherent_walk = smmu->features & ARM_SMMU_FEAT_COHERENCY, > + .tlb = &arm_smmu_flush_ops, > + .iommu_dev = smmu->dev, > + }; > + return 0; > +} > + > static int arm_smmu_domain_finalise(struct iommu_domain *domain) > { > int ret; > - unsigned long ias, oas; > enum io_pgtable_fmt fmt; > - struct io_pgtable_cfg pgtbl_cfg; > struct io_pgtable_ops *pgtbl_ops; > int (*finalise_stage_fn)(struct arm_smmu_domain *, > struct io_pgtable_cfg *); > struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); > struct arm_smmu_device *smmu = smmu_domain->smmu; > + struct io_pgtable_cfg *pgtbl_cfg = &smmu_domain->pgtbl_cfg; > > if (domain->type == IOMMU_DOMAIN_IDENTITY) { > smmu_domain->stage = ARM_SMMU_DOMAIN_BYPASS; > @@ -2220,16 +2251,11 @@ static int arm_smmu_domain_finalise(struct iommu_domain *domain) > > switch (smmu_domain->stage) { > case ARM_SMMU_DOMAIN_S1: > - ias = (smmu->features & ARM_SMMU_FEAT_VAX) ? 52 : 48; > - ias = min_t(unsigned long, ias, VA_BITS); > - oas = smmu->ias; > fmt = ARM_64_LPAE_S1; > finalise_stage_fn = arm_smmu_domain_finalise_s1; > break; > case ARM_SMMU_DOMAIN_NESTED: > case ARM_SMMU_DOMAIN_S2: > - ias = smmu->ias; > - oas = smmu->oas; > fmt = ARM_64_LPAE_S2; > finalise_stage_fn = arm_smmu_domain_finalise_s2; > break; > @@ -2237,24 +2263,19 @@ static int arm_smmu_domain_finalise(struct iommu_domain *domain) > return -EINVAL; > } > > - pgtbl_cfg = (struct io_pgtable_cfg) { > - .pgsize_bitmap = smmu->pgsize_bitmap, > - .ias = ias, > - .oas = oas, > - .coherent_walk = smmu->features & ARM_SMMU_FEAT_COHERENCY, > - .tlb = &arm_smmu_flush_ops, > - .iommu_dev = smmu->dev, > - }; > + ret = arm_smmu_prepare_pgtbl_cfg(smmu, smmu_domain->stage, pgtbl_cfg); > + if (ret) > + return ret; > > - pgtbl_ops = alloc_io_pgtable_ops(fmt, &pgtbl_cfg, smmu_domain); > + pgtbl_ops = alloc_io_pgtable_ops(fmt, pgtbl_cfg, smmu_domain); > if (!pgtbl_ops) > return -ENOMEM; > > - domain->pgsize_bitmap = pgtbl_cfg.pgsize_bitmap; > - domain->geometry.aperture_end = (1UL << pgtbl_cfg.ias) - 1; > + domain->pgsize_bitmap = pgtbl_cfg->pgsize_bitmap; > + domain->geometry.aperture_end = (1UL << pgtbl_cfg->ias) - 1; > domain->geometry.force_aperture = true; > > - ret = finalise_stage_fn(smmu_domain, &pgtbl_cfg); > + ret = finalise_stage_fn(smmu_domain, pgtbl_cfg); > if (ret < 0) { > free_io_pgtable_ops(pgtbl_ops); > return ret; > @@ -2406,6 +2427,46 @@ static void arm_smmu_disable_pasid(struct arm_smmu_master *master) > pci_disable_pasid(pdev); > } > > +static int > +arm_smmu_verify_domain_compatible(struct arm_smmu_device *smmu, > + struct arm_smmu_domain *smmu_domain) > +{ > + struct io_pgtable_cfg pgtbl_cfg; > + int ret; > + > + if (smmu_domain->domain.type == IOMMU_DOMAIN_IDENTITY) > + return 0; > + > + if (smmu_domain->stage == ARM_SMMU_DOMAIN_S2) { > + if (!(smmu->features & ARM_SMMU_FEAT_TRANS_S2)) > + return -EINVAL; > + if (smmu_domain->s2_cfg.vmid >> smmu->vmid_bits) > + return -EINVAL; > + } else if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) { > + if (!(smmu->features & ARM_SMMU_FEAT_TRANS_S1)) > + return -EINVAL; > + if (smmu_domain->cd.asid >> smmu->asid_bits) > + return -EINVAL; > + } > + > + ret = arm_smmu_prepare_pgtbl_cfg(smmu, smmu_domain->stage, &pgtbl_cfg); > + if (ret) > + return ret; > + > + if (smmu_domain->pgtbl_cfg.ias > pgtbl_cfg.ias || > + smmu_domain->pgtbl_cfg.oas > pgtbl_cfg.oas || > + /* > + * The supported pgsize_bitmap must be a superset of the domain's > + * pgsize_bitmap. > + */ > + (smmu_domain->pgtbl_cfg.pgsize_bitmap ^ pgtbl_cfg.pgsize_bitmap) & > + smmu_domain->pgtbl_cfg.pgsize_bitmap || > + smmu_domain->pgtbl_cfg.coherent_walk != pgtbl_cfg.coherent_walk) > + return -EINVAL; > + > + return 0; > +} > + > static void arm_smmu_installed_smmus_remove_device( > struct arm_smmu_domain *smmu_domain, > struct arm_smmu_master *master) > @@ -2449,6 +2510,10 @@ arm_smmu_installed_smmus_add_device(struct arm_smmu_domain *smmu_domain, > } > } > if (!list_entry_found) { > + ret = arm_smmu_verify_domain_compatible(smmu, smmu_domain); > + if (ret) > + goto unlock; > + > installed_smmu = kzalloc(sizeof(*installed_smmu), GFP_KERNEL); > if (!installed_smmu) { > ret = -ENOMEM; > diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h > index 2ab23139c796e..143b287be2f8b 100644 > --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h > +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h > @@ -9,6 +9,7 @@ > #define _ARM_SMMU_V3_H > > #include <linux/bitfield.h> > +#include <linux/io-pgtable.h> > #include <linux/iommu.h> > #include <linux/kernel.h> > #include <linux/mmzone.h> > @@ -729,6 +730,7 @@ struct arm_smmu_domain { > struct mutex init_mutex; /* Protects smmu pointer */ > > struct io_pgtable_ops *pgtbl_ops; > + struct io_pgtable_cfg pgtbl_cfg; > atomic_t nr_ats_masters; > > enum arm_smmu_domain_stage stage;
On Fri, Aug 18, 2023 at 3:34 AM Robin Murphy <robin.murphy@arm.com> wrote: > > On 2023-08-17 19:16, Michael Shavit wrote: > > Add a new arm_smmu_installed_smmu class to aggregate masters belonging > > to the same SMMU that a domain is attached to. > > Update usages of the domain->devices list to first iterate over this > > parent installed_smmus list. > > > > This allows functions that batch commands to an SMMU to first iterate > > over the list of installed SMMUs before preparing the batched command > > from the set of attached masters. > > I get the feeling that any purpose this serves could be achieved far > more simply by just keeping the lists sorted by SMMU instance. I initially tried just that, but then you need more sophisticated code when iterating over the list to correctly batch operations by SMMU, which is the more common operation. That first hunk is very unfortunate though... Let me revive that version and send it out so we can better compare.