From patchwork Tue Jun 6 12:07:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Shavit X-Patchwork-Id: 103759 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3346538vqr; Tue, 6 Jun 2023 05:13:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6W90zGtgC1q7MYvedGyat9ZB+YWgOnc3sYkmUsM0c1ARC7oSa0u7NsGrMW5MQ1BMPAFDlJ X-Received: by 2002:a05:6a20:54a3:b0:100:efa1:eab0 with SMTP id i35-20020a056a2054a300b00100efa1eab0mr1717190pzk.2.1686053629238; Tue, 06 Jun 2023 05:13:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686053629; cv=none; d=google.com; s=arc-20160816; b=FZz5IFWST6swqneC9oCxIMoPO/D3pz7c9BLjpJEdX3NOQTG7QXjv6NClaJrjot/bUR f0ZyRRWIkRIl/TspwRIxqUQCVV0XIEYDdAiAv4fsvwq5GE2n1bz571zWlDmVHyay5JCR EeACv+C5xqFLQ4yE/2Br2XN18n8eGaVoFAeywOS4NT8mlDpXg3soZBO2+ueNGofDFOS8 S2oURNePP7qxZJA0xl+9dVGuvSE6dYv9Lm7E/iSWnphSyGM0QitEYlurDQdYGyMuWnrr 2aCRfDveB+IJ6KLE2sTmuVBsAbCV7UkC3aP5IQRAo7iOJb9gnGB5dond9RAs+K901yH4 QmAA== 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:references :mime-version:in-reply-to:date:dkim-signature; bh=FnWnvbHmIF1ltrhpko3AmatpWzsBYOi2I16/Atgd3Oo=; b=K+jvdTZt56bHQ/ds932FcHxzm2OvQImZN5zTUphzSsgOxIFArkIH+c8tJfmLhcQ8h8 dVPhvBGWkX3fpf8fwqapQnJ9kzWTIKfQeeh3SIBHKxhNGTMbL52xfFNAfI+3a3Y5MJmD YMMwRu82o2j1xNgGq+ioXrDKrsniOv77h7lXIG8gZ7P8rgLo3lPNFeaRhSAiZeiPM/il VChmcsq9namFn92KWkIJQMoRiXzyouEMLoSoogU8FxBITZQSAUUdbuVovQojO+caTfKM 0XNaMXmkHgBxJlUk/BhAsB1DamCCnYqV00ojspO8I/zDgQ3QP+xdRmVABN7ONSg5q7Lc Bg3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=OT+iGAb6; 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 x6-20020a170902a38600b001ab20d029e0si6891804pla.582.2023.06.06.05.13.35; Tue, 06 Jun 2023 05:13:49 -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=OT+iGAb6; 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 S237463AbjFFMLQ (ORCPT + 99 others); Tue, 6 Jun 2023 08:11:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237413AbjFFMLP (ORCPT ); Tue, 6 Jun 2023 08:11:15 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40443172C for ; Tue, 6 Jun 2023 05:10:48 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-1b04c328aa1so23992515ad.2 for ; Tue, 06 Jun 2023 05:10:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686053444; x=1688645444; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=FnWnvbHmIF1ltrhpko3AmatpWzsBYOi2I16/Atgd3Oo=; b=OT+iGAb66chgU7NBKy4tFHkZVVSeUEqENw2JBDh6NO0OJc11YO1CWkwgNkZjHtYtDP lZ7NxCAGg5dgVzWFUtOEhk2CWrx1Pfiqw0NYIcjLZSSHU16TLJ0GKWraeJX9Q0twcSP6 3YgWeiLUY98PryAP+mhZtWKw3M6BYA3n/XIGSGx3+UrSbGweWJffi8+xWt2FfV3NThzo XBXaKTbXD4ydtH9xv2nOk9efQS5Rjmd49C5Tsn1GOsK8wtmeQmZU8CsM5vSV2dmEDWv+ GKDEFYPFJzpH0Rq9Q4iEdy1A3yyzmEYO02gaGn+H03RDX5nInQ1OlVuD38G4glG62cFv r7RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686053444; x=1688645444; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FnWnvbHmIF1ltrhpko3AmatpWzsBYOi2I16/Atgd3Oo=; b=LXvalhbYiVGVSARRffSh/yASgUXkHLgpjSZKANX7DsZR+PZd/yw9SQpqymzztKU+l/ s+Kn1BZ08lpsCWh8PE/eu516AyhBqKiso7bTGnep/6vtaojwLmLk9zk7KWM547tz+Gzc 79p4jH+NmqUiu3JBXRTdHEYl33nF+ejQ58xku/TrmEkYMmS8SvsrOvDeUHHrsWNo/sPo uHYOxzMpTHWHltSE+qNNUWrZRPhXGkoAwO9mDUhR71Z0BK/530Ts4W+OuN/8Xu2uThS+ TG83YGuSI8qwV3hEEat2+8CubepfzuynnZjMMFdZTzofno4EQlq62uW9BL0etLKCOvNo p/UA== X-Gm-Message-State: AC+VfDyNSnI9Q8JgRoSglZ4akX98Ui78AuwwZ/Pv6thtcVaK3//aol7c HGXr9O7LgK72penmBecA+jMXstbRHGVj X-Received: from mshavit.ntc.corp.google.com ([2401:fa00:95:20c:a615:63d5:b54e:6919]) (user=mshavit job=sendgmr) by 2002:a17:902:8693:b0:1af:ff00:dfc2 with SMTP id g19-20020a170902869300b001afff00dfc2mr602005plo.5.1686053443904; Tue, 06 Jun 2023 05:10:43 -0700 (PDT) Date: Tue, 6 Jun 2023 20:07:48 +0800 In-Reply-To: <20230606120854.4170244-1-mshavit@google.com> Mime-Version: 1.0 References: <20230606120854.4170244-1-mshavit@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230606120854.4170244-13-mshavit@google.com> Subject: [PATCH v2 12/18] iommu/arm-smmu-v3-sva: Remove arm_smmu_bond From: Michael Shavit To: Will Deacon , Robin Murphy , Joerg Roedel Cc: Michael Shavit , 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 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767955370493701828?= X-GMAIL-MSGID: =?utf-8?q?1767955370493701828?= There's a 1:1 relationship between arm_smmu_bond and the iommu_domain used in set_dev_pasid/remove_dev_pasid. arm_smmu_bond has become an unnecessary complication. It's more natural to store any needed information at the iommu_domain container level. Signed-off-by: Michael Shavit --- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 69 +++++++------------ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 1 - drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 +- 3 files changed, 24 insertions(+), 48 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c index 650c9c9ad52f1..b615a85e6a54e 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c @@ -24,14 +24,13 @@ struct arm_smmu_mmu_notifier { #define mn_to_smmu(mn) container_of(mn, struct arm_smmu_mmu_notifier, mn) -struct arm_smmu_bond { - struct mm_struct *mm; +struct arm_smmu_sva_domain { + struct iommu_domain iommu_domain; struct arm_smmu_mmu_notifier *smmu_mn; - struct list_head list; }; -#define sva_to_bond(handle) \ - container_of(handle, struct arm_smmu_bond, sva) +#define to_sva_domain(domain) \ + container_of(domain, struct arm_smmu_sva_domain, iommu_domain) static DEFINE_MUTEX(sva_lock); @@ -363,10 +362,10 @@ static void arm_smmu_mmu_notifier_put(struct arm_smmu_mmu_notifier *smmu_mn) arm_smmu_free_shared_cd(cd); } -static int __arm_smmu_sva_bind(struct device *dev, struct mm_struct *mm) +static int __arm_smmu_sva_bind(struct device *dev, + struct arm_smmu_sva_domain *sva_domain, + struct mm_struct *mm) { - int ret; - struct arm_smmu_bond *bond; struct arm_smmu_master *master = dev_iommu_priv_get(dev); struct iommu_domain *domain = iommu_get_domain_for_dev(dev); struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); @@ -374,24 +373,14 @@ static int __arm_smmu_sva_bind(struct device *dev, struct mm_struct *mm) if (!master || !master->sva_enabled) return -ENODEV; - bond = kzalloc(sizeof(*bond), GFP_KERNEL); - if (!bond) - return -ENOMEM; - - bond->mm = mm; - - bond->smmu_mn = arm_smmu_mmu_notifier_get(smmu_domain, mm); - if (IS_ERR(bond->smmu_mn)) { - ret = PTR_ERR(bond->smmu_mn); - goto err_free_bond; + sva_domain->smmu_mn = arm_smmu_mmu_notifier_get(smmu_domain, + mm); + if (IS_ERR(sva_domain->smmu_mn)) { + sva_domain->smmu_mn = NULL; + return PTR_ERR(sva_domain->smmu_mn); } - - list_add(&bond->list, &master->bonds); + master->nr_attached_sva_domains += 1; return 0; - -err_free_bond: - kfree(bond); - return ret; } bool arm_smmu_sva_supported(struct arm_smmu_device *smmu) @@ -521,7 +510,7 @@ int arm_smmu_master_enable_sva(struct arm_smmu_master *master) int arm_smmu_master_disable_sva(struct arm_smmu_master *master) { mutex_lock(&sva_lock); - if (!list_empty(&master->bonds)) { + if (master->nr_attached_sva_domains != 0) { dev_err(master->dev, "cannot disable SVA, device is bound\n"); mutex_unlock(&sva_lock); return -EBUSY; @@ -545,23 +534,12 @@ void arm_smmu_sva_notifier_synchronize(void) void arm_smmu_sva_remove_dev_pasid(struct iommu_domain *domain, struct device *dev, ioasid_t id) { - struct mm_struct *mm = domain->mm; - struct arm_smmu_bond *bond = NULL, *t; + struct arm_smmu_sva_domain *sva_domain = to_sva_domain(domain); struct arm_smmu_master *master = dev_iommu_priv_get(dev); mutex_lock(&sva_lock); - list_for_each_entry(t, &master->bonds, list) { - if (t->mm == mm) { - bond = t; - break; - } - } - - if (!WARN_ON(!bond)) { - list_del(&bond->list); - arm_smmu_mmu_notifier_put(bond->smmu_mn); - kfree(bond); - } + master->nr_attached_sva_domains -= 1; + arm_smmu_mmu_notifier_put(sva_domain->smmu_mn); mutex_unlock(&sva_lock); } @@ -572,7 +550,7 @@ static int arm_smmu_sva_set_dev_pasid(struct iommu_domain *domain, struct mm_struct *mm = domain->mm; mutex_lock(&sva_lock); - ret = __arm_smmu_sva_bind(dev, mm); + ret = __arm_smmu_sva_bind(dev, to_sva_domain(domain), mm); mutex_unlock(&sva_lock); return ret; @@ -590,12 +568,11 @@ static const struct iommu_domain_ops arm_smmu_sva_domain_ops = { struct iommu_domain *arm_smmu_sva_domain_alloc(void) { - struct iommu_domain *domain; + struct arm_smmu_sva_domain *sva_domain; - domain = kzalloc(sizeof(*domain), GFP_KERNEL); - if (!domain) + sva_domain = kzalloc(sizeof(*sva_domain), GFP_KERNEL); + if (!sva_domain) return NULL; - domain->ops = &arm_smmu_sva_domain_ops; - - return domain; + sva_domain->iommu_domain.ops = &arm_smmu_sva_domain_ops; + return &sva_domain->iommu_domain; } 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 a6fa56585c219..b7f834dde85d1 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2784,7 +2784,6 @@ static struct iommu_device *arm_smmu_probe_device(struct device *dev) master->dev = dev; master->smmu = smmu; - INIT_LIST_HEAD(&master->bonds); dev_iommu_priv_set(dev, master); ret = arm_smmu_insert_master(smmu, master); 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 48795a7287b69..3525d60668c23 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -705,7 +705,7 @@ struct arm_smmu_master { bool stall_enabled; bool sva_enabled; bool iopf_enabled; - struct list_head bonds; + unsigned int nr_attached_sva_domains; unsigned int ssid_bits; unsigned int nr_attached_pasid_domains; };