From nobody Fri Dec 19 03:42:41 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5E79C83F35 for ; Thu, 31 Aug 2023 17:45:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346702AbjHaRp5 (ORCPT ); Thu, 31 Aug 2023 13:45:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346586AbjHaRpz (ORCPT ); Thu, 31 Aug 2023 13:45:55 -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 28B4EE61 for ; Thu, 31 Aug 2023 10:45:52 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d7bb58517b8so892685276.0 for ; Thu, 31 Aug 2023 10:45:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1693503951; x=1694108751; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Om100NGxhCXQ+8JyGsMousRdI1nQoY3IqmfotP3Xvhs=; b=vjH8t2y48+RPbCnGhVYQCWMyXK4GUp3mFPpUOcQz2cF8I1Ufm2e5BQfzVGHzGiGvzS w4zvlqbekX+BhSuDF2typiekDsh8BN8gn9pmyh+Wr+afcBVvq4qXqxj2rEe3QnsM76uJ rJEvForQ3BZrnsHu8gjKdRRRqx+BiU06FFonhiRt7vbB/ghIGNFHmEPJNu7FFnkeRSvp NLwzRJbLKc5nDVK5zkOW7xAgmyW1KV0WDACWt3rPK5nNUkuaQzHe9TGbuXZrb5gEFWql ENOTlk+6tS899Zkt98wn6/WB1aOzowvpCyII9MaRHlWnCOPx+ZzJbsvvX6BpsJp0z3d5 U8PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693503951; x=1694108751; 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=Om100NGxhCXQ+8JyGsMousRdI1nQoY3IqmfotP3Xvhs=; b=LrCNge6sSWBe2vG0e79nnrESxz4roDsnGd4wS3OXi4Y867CH3HbqJ5yQtOxm3XEXun mqPnJtkZKj9YW5ZJkzc47L+w9voEsoAur+oxybzAx8LFfXaCHxM+cqAwMEj3k9CfhEtk 2B1kTt9XKQrDKNfKWDa+Dqvn8ai2D+NgYlQo7R7F1XnPUzi/8ZzIrkbHZCk7+AjkU3fX jxbsqLXMysPFcw1sBtFnUsljCtBkAOvsd3NxI0tG4ywdSp0tKkmCMiUWeSwRLnleULJw z1Entq0ut8W4tt90dV1EKmqSMfAoQQBNn97YUJXF8AXL6mcsDD37aC+y57Y2Cg8qblxF UxZw== X-Gm-Message-State: AOJu0Yx7lka9t2Mc2XNTg1pPjs5Er7Mn+1gNJJsKbOIe2wOaUCuYHefQ KNEPkrEGdv7xCMFqytsBMqlXZtTweyXl X-Google-Smtp-Source: AGHT+IHrnnomXpv9Dmqwq9lxKsegFA5Pqwm8VPJal1ouPnka4Mo6v0mS7xEia44W4SDR47RoUCCJqUv+Y3Pt X-Received: from mshavit.ntc.corp.google.com ([2401:fa00:95:20c:1a0a:7338:4a5a:5f83]) (user=mshavit job=sendgmr) by 2002:a25:8906:0:b0:d67:5d71:d81a with SMTP id e6-20020a258906000000b00d675d71d81amr8840ybl.13.1693503951463; Thu, 31 Aug 2023 10:45:51 -0700 (PDT) Date: Fri, 1 Sep 2023 01:44:30 +0800 In-Reply-To: <20230831174536.103472-1-mshavit@google.com> Mime-Version: 1.0 References: <20230831174536.103472-1-mshavit@google.com> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog Message-ID: <20230901014413.v7.1.I67ab103c18d882aedc8a08985af1fba70bca084e@changeid> Subject: [PATCH v7 1/9] iommu/arm-smmu-v3: Move ctx_desc out of s1_cfg From: Michael Shavit To: iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: will@kernel.org, robin.murphy@arm.com, jean-philippe@linaro.org, jgg@nvidia.com, nicolinc@nvidia.com, Michael Shavit , Jason Gunthorpe , Joerg Roedel , Kevin Tian , "Kirill A. Shutemov" , Lu Baolu , Mark Brown , Yicong Yang Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" s1_cfg describes the CD table that is inserted into an SMMU's STEs. It's weird for s1_cfg to also own ctx_desc which describes a CD that is inserted into that table. It is more appropriate for arm_smmu_domain to own ctx_desc. Reviewed-by: Jason Gunthorpe Reviewed-by: Nicolin Chen Signed-off-by: Michael Shavit Tested-by: Nicolin Chen --- (no changes since v2) Changes in v2: - Undo over-reaching column alignment change .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 2 +- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 23 ++++++++++--------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 6 +++-- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iomm= u/arm/arm-smmu-v3/arm-smmu-v3-sva.c index a5a63b1c947eb..968559d625c40 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 @@ -62,7 +62,7 @@ arm_smmu_share_asid(struct mm_struct *mm, u16 asid) return cd; } =20 - smmu_domain =3D container_of(cd, struct arm_smmu_domain, s1_cfg.cd); + smmu_domain =3D container_of(cd, struct arm_smmu_domain, cd); smmu =3D smmu_domain->smmu; =20 ret =3D xa_alloc(&arm_smmu_asid_xa, &new_asid, cd, diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.c index 9b0dc35056019..bb277ff86f65f 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1869,7 +1869,7 @@ static void arm_smmu_tlb_inv_context(void *cookie) * careful, 007. */ if (smmu_domain->stage =3D=3D ARM_SMMU_DOMAIN_S1) { - arm_smmu_tlb_inv_asid(smmu, smmu_domain->s1_cfg.cd.asid); + arm_smmu_tlb_inv_asid(smmu, smmu_domain->cd.asid); } else { cmd.opcode =3D CMDQ_OP_TLBI_S12_VMALL; cmd.tlbi.vmid =3D smmu_domain->s2_cfg.vmid; @@ -1957,7 +1957,7 @@ static void arm_smmu_tlb_inv_range_domain(unsigned lo= ng iova, size_t size, if (smmu_domain->stage =3D=3D ARM_SMMU_DOMAIN_S1) { cmd.opcode =3D smmu_domain->smmu->features & ARM_SMMU_FEAT_E2H ? CMDQ_OP_TLBI_EL2_VA : CMDQ_OP_TLBI_NH_VA; - cmd.tlbi.asid =3D smmu_domain->s1_cfg.cd.asid; + cmd.tlbi.asid =3D smmu_domain->cd.asid; } else { cmd.opcode =3D CMDQ_OP_TLBI_S2_IPA; cmd.tlbi.vmid =3D smmu_domain->s2_cfg.vmid; @@ -2088,7 +2088,7 @@ static void arm_smmu_domain_free(struct iommu_domain = *domain) mutex_lock(&arm_smmu_asid_lock); if (cfg->cdcfg.cdtab) arm_smmu_free_cd_tables(smmu_domain); - arm_smmu_free_asid(&cfg->cd); + arm_smmu_free_asid(&smmu_domain->cd); mutex_unlock(&arm_smmu_asid_lock); } else { struct arm_smmu_s2_cfg *cfg =3D &smmu_domain->s2_cfg; @@ -2107,13 +2107,14 @@ static int arm_smmu_domain_finalise_s1(struct arm_s= mmu_domain *smmu_domain, u32 asid; struct arm_smmu_device *smmu =3D smmu_domain->smmu; struct arm_smmu_s1_cfg *cfg =3D &smmu_domain->s1_cfg; + struct arm_smmu_ctx_desc *cd =3D &smmu_domain->cd; typeof(&pgtbl_cfg->arm_lpae_s1_cfg.tcr) tcr =3D &pgtbl_cfg->arm_lpae_s1_c= fg.tcr; =20 - refcount_set(&cfg->cd.refs, 1); + refcount_set(&cd->refs, 1); =20 /* Prevent SVA from modifying the ASID until it is written to the CD */ mutex_lock(&arm_smmu_asid_lock); - ret =3D xa_alloc(&arm_smmu_asid_xa, &asid, &cfg->cd, + ret =3D xa_alloc(&arm_smmu_asid_xa, &asid, cd, XA_LIMIT(1, (1 << smmu->asid_bits) - 1), GFP_KERNEL); if (ret) goto out_unlock; @@ -2126,23 +2127,23 @@ static int arm_smmu_domain_finalise_s1(struct arm_s= mmu_domain *smmu_domain, if (ret) goto out_free_asid; =20 - cfg->cd.asid =3D (u16)asid; - cfg->cd.ttbr =3D pgtbl_cfg->arm_lpae_s1_cfg.ttbr; - cfg->cd.tcr =3D FIELD_PREP(CTXDESC_CD_0_TCR_T0SZ, tcr->tsz) | + cd->asid =3D (u16)asid; + cd->ttbr =3D pgtbl_cfg->arm_lpae_s1_cfg.ttbr; + cd->tcr =3D FIELD_PREP(CTXDESC_CD_0_TCR_T0SZ, tcr->tsz) | FIELD_PREP(CTXDESC_CD_0_TCR_TG0, tcr->tg) | FIELD_PREP(CTXDESC_CD_0_TCR_IRGN0, tcr->irgn) | FIELD_PREP(CTXDESC_CD_0_TCR_ORGN0, tcr->orgn) | FIELD_PREP(CTXDESC_CD_0_TCR_SH0, tcr->sh) | FIELD_PREP(CTXDESC_CD_0_TCR_IPS, tcr->ips) | CTXDESC_CD_0_TCR_EPD1 | CTXDESC_CD_0_AA64; - cfg->cd.mair =3D pgtbl_cfg->arm_lpae_s1_cfg.mair; + cd->mair =3D pgtbl_cfg->arm_lpae_s1_cfg.mair; =20 /* * Note that this will end up calling arm_smmu_sync_cd() before * the master has been added to the devices list for this domain. * This isn't an issue because the STE hasn't been installed yet. */ - ret =3D arm_smmu_write_ctx_desc(smmu_domain, 0, &cfg->cd); + ret =3D arm_smmu_write_ctx_desc(smmu_domain, 0, cd); if (ret) goto out_free_cd_tables; =20 @@ -2152,7 +2153,7 @@ static int arm_smmu_domain_finalise_s1(struct arm_smm= u_domain *smmu_domain, out_free_cd_tables: arm_smmu_free_cd_tables(smmu_domain); out_free_asid: - arm_smmu_free_asid(&cfg->cd); + arm_smmu_free_asid(cd); out_unlock: mutex_unlock(&arm_smmu_asid_lock); return ret; diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.h index dcab85698a4e2..f841383a55a35 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -599,7 +599,6 @@ struct arm_smmu_ctx_desc_cfg { =20 struct arm_smmu_s1_cfg { struct arm_smmu_ctx_desc_cfg cdcfg; - struct arm_smmu_ctx_desc cd; u8 s1fmt; u8 s1cdmax; }; @@ -724,7 +723,10 @@ struct arm_smmu_domain { =20 enum arm_smmu_domain_stage stage; union { - struct arm_smmu_s1_cfg s1_cfg; + struct { + struct arm_smmu_ctx_desc cd; + struct arm_smmu_s1_cfg s1_cfg; + }; struct arm_smmu_s2_cfg s2_cfg; }; =20 --=20 2.42.0.283.g2d96d420d3-goog From nobody Fri Dec 19 03:42:41 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF9FBC83F35 for ; Thu, 31 Aug 2023 17:46:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346850AbjHaRqB (ORCPT ); Thu, 31 Aug 2023 13:46:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346586AbjHaRp7 (ORCPT ); Thu, 31 Aug 2023 13:45:59 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C8CAE5F for ; Thu, 31 Aug 2023 10:45:56 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d7493fcd829so887889276.3 for ; Thu, 31 Aug 2023 10:45:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1693503955; x=1694108755; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=/UmdxN+8ylNah8moUuj24oyiX59sPo0MS6NJA0OXuqw=; b=i1oRaymeTwTH96h5K5O6FlZLkKyDTXqWv1Hgu9ZmMwDpSXOW04cK0SAnAI5rnjVHYz nU8spOt13ek7wenuh7DcKHK2pxcDlYONv7XnaQkAG2VcdpwXmHQMTnqI3HiDwdkqKvqq SOwGtmzH/eznncEhpo8OYlhDofXa1CF2CRYPqd+bPHJ5RvTTJp5LTP+n6bnPgK5+rEC7 X0ujTh8wpl2JWWo2iFz8+xu8QIaeldFaN9pgwLgJDzxB7mjTaNTxCLmvNDZkn1paeiuY oCjvXe0MlwyZvtOoN4u5vkAiS/t7qrzqU511b+oXYE/MlC1i/+1IDXp1IwM0ekUoFTH6 fUqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693503955; x=1694108755; 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=/UmdxN+8ylNah8moUuj24oyiX59sPo0MS6NJA0OXuqw=; b=iFaLVPqSpRfoZBPcnVp74lwOvD61PNNsEpY3Q9+Vh9gg6cOoVCwFySsCE9mZy2H2ld Lw7k9DcToavah8P62W1vxzPIZAGbT13V2moBoYibxXXrbZtxbtsNNH4V+fj4NmnmjQs/ xrrqXkiQbm4nUbI8XQeKyHityIXXDSFHKvjBQ8MuR602/HRd0QCoGpK1ZvkhsEOH54mr QSheiwOSD0TwjLTALupNNdJGACMwtgZSToankOzt2u3/c8wGw8XkLZ9cmVlgmE9HlWaU K5fki7c2HSS5/gWdIzHiYefXDiVn3Y7MFsWJBI6hDBp6Qoo6ACANc+0UqOlkwmRJUbIm WMKQ== X-Gm-Message-State: AOJu0Yw/g39aKbLEnQ80WQXYEvudQ4xaYYSh+N2fH+TYPmDkCkStASxy jP3Nk4urWZuJOybhR8mjAuUmtumGuHsl X-Google-Smtp-Source: AGHT+IFbVe1Kg6huy9v256Tez77tO4o5KYmlUs+wZYMpSlkA9YIpHTcHyw9Y67Decm4phPI+gCC8eRe3x+R/ X-Received: from mshavit.ntc.corp.google.com ([2401:fa00:95:20c:1a0a:7338:4a5a:5f83]) (user=mshavit job=sendgmr) by 2002:a05:6902:11c9:b0:d20:7752:e384 with SMTP id n9-20020a05690211c900b00d207752e384mr11159ybu.3.1693503955616; Thu, 31 Aug 2023 10:45:55 -0700 (PDT) Date: Fri, 1 Sep 2023 01:44:31 +0800 In-Reply-To: <20230831174536.103472-1-mshavit@google.com> Mime-Version: 1.0 References: <20230831174536.103472-1-mshavit@google.com> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog Message-ID: <20230901014413.v7.2.I1ef1ed19d7786c8176a0d05820c869e650c8d68f@changeid> Subject: [PATCH v7 2/9] iommu/arm-smmu-v3: Replace s1_cfg with cdtab_cfg From: Michael Shavit To: iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: will@kernel.org, robin.murphy@arm.com, jean-philippe@linaro.org, jgg@nvidia.com, nicolinc@nvidia.com, Michael Shavit , Jason Gunthorpe , Joerg Roedel , Kevin Tian , "Kirill A. Shutemov" , Lu Baolu , Mark Brown , Yicong Yang Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove struct arm_smmu_s1_cfg. This is really just a CD table with a bit of extra information. Move other attributes of the CD table that were held there into the existing CD table structure, struct arm_smmu_ctx_desc_cfg, and replace all usages of arm_smmu_s1_cfg with arm_smmu_ctx_desc_cfg. For clarity, use the name "cd_table" for the variables pointing to arm_smmu_ctx_desc_cfg in the new code instead of cdcfg. A later patch will make this fully consistent. Reviewed-by: Jason Gunthorpe Reviewed-by: Nicolin Chen Signed-off-by: Michael Shavit Tested-by: Nicolin Chen --- (no changes since v6) Changes in v6: - Undo removal of s1fmt and renaming of s1cdmax Changes in v3: - Updated commit messages again - Replace more usages of cdcfg with cdtable (lines that were already touched by this commit anyways). Changes in v2: - Updated commit message drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 41 ++++++++++----------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 7 +--- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.c index bb277ff86f65f..5d1977027d2c4 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1033,9 +1033,9 @@ static __le64 *arm_smmu_get_cd_ptr(struct arm_smmu_do= main *smmu_domain, unsigned int idx; struct arm_smmu_l1_ctx_desc *l1_desc; struct arm_smmu_device *smmu =3D smmu_domain->smmu; - struct arm_smmu_ctx_desc_cfg *cdcfg =3D &smmu_domain->s1_cfg.cdcfg; + struct arm_smmu_ctx_desc_cfg *cdcfg =3D &smmu_domain->cd_table; =20 - if (smmu_domain->s1_cfg.s1fmt =3D=3D STRTAB_STE_0_S1FMT_LINEAR) + if (cdcfg->s1fmt =3D=3D STRTAB_STE_0_S1FMT_LINEAR) return cdcfg->cdtab + ssid * CTXDESC_CD_DWORDS; =20 idx =3D ssid >> CTXDESC_SPLIT; @@ -1071,7 +1071,7 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_domain *s= mmu_domain, int ssid, bool cd_live; __le64 *cdptr; =20 - if (WARN_ON(ssid >=3D (1 << smmu_domain->s1_cfg.s1cdmax))) + if (WARN_ON(ssid >=3D (1 << smmu_domain->cd_table.s1cdmax))) return -E2BIG; =20 cdptr =3D arm_smmu_get_cd_ptr(smmu_domain, ssid); @@ -1138,19 +1138,18 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu= _domain *smmu_domain) size_t l1size; size_t max_contexts; struct arm_smmu_device *smmu =3D smmu_domain->smmu; - struct arm_smmu_s1_cfg *cfg =3D &smmu_domain->s1_cfg; - struct arm_smmu_ctx_desc_cfg *cdcfg =3D &cfg->cdcfg; + struct arm_smmu_ctx_desc_cfg *cdcfg =3D &smmu_domain->cd_table; =20 - max_contexts =3D 1 << cfg->s1cdmax; + max_contexts =3D 1 << cdcfg->s1cdmax; =20 if (!(smmu->features & ARM_SMMU_FEAT_2_LVL_CDTAB) || max_contexts <=3D CTXDESC_L2_ENTRIES) { - cfg->s1fmt =3D STRTAB_STE_0_S1FMT_LINEAR; + cdcfg->s1fmt =3D STRTAB_STE_0_S1FMT_LINEAR; cdcfg->num_l1_ents =3D max_contexts; =20 l1size =3D max_contexts * (CTXDESC_CD_DWORDS << 3); } else { - cfg->s1fmt =3D STRTAB_STE_0_S1FMT_64K_L2; + cdcfg->s1fmt =3D STRTAB_STE_0_S1FMT_64K_L2; cdcfg->num_l1_ents =3D DIV_ROUND_UP(max_contexts, CTXDESC_L2_ENTRIES); =20 @@ -1186,7 +1185,7 @@ static void arm_smmu_free_cd_tables(struct arm_smmu_d= omain *smmu_domain) int i; size_t size, l1size; struct arm_smmu_device *smmu =3D smmu_domain->smmu; - struct arm_smmu_ctx_desc_cfg *cdcfg =3D &smmu_domain->s1_cfg.cdcfg; + struct arm_smmu_ctx_desc_cfg *cdcfg =3D &smmu_domain->cd_table; =20 if (cdcfg->l1_desc) { size =3D CTXDESC_L2_ENTRIES * (CTXDESC_CD_DWORDS << 3); @@ -1276,7 +1275,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu= _master *master, u32 sid, u64 val =3D le64_to_cpu(dst[0]); bool ste_live =3D false; struct arm_smmu_device *smmu =3D NULL; - struct arm_smmu_s1_cfg *s1_cfg =3D NULL; + struct arm_smmu_ctx_desc_cfg *cd_table =3D NULL; struct arm_smmu_s2_cfg *s2_cfg =3D NULL; struct arm_smmu_domain *smmu_domain =3D NULL; struct arm_smmu_cmdq_ent prefetch_cmd =3D { @@ -1294,7 +1293,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu= _master *master, u32 sid, if (smmu_domain) { switch (smmu_domain->stage) { case ARM_SMMU_DOMAIN_S1: - s1_cfg =3D &smmu_domain->s1_cfg; + cd_table =3D &smmu_domain->cd_table; break; case ARM_SMMU_DOMAIN_S2: case ARM_SMMU_DOMAIN_NESTED: @@ -1325,7 +1324,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu= _master *master, u32 sid, val =3D STRTAB_STE_0_V; =20 /* Bypass/fault */ - if (!smmu_domain || !(s1_cfg || s2_cfg)) { + if (!smmu_domain || !(cd_table || s2_cfg)) { if (!smmu_domain && disable_bypass) val |=3D FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_ABORT); else @@ -1344,7 +1343,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu= _master *master, u32 sid, return; } =20 - if (s1_cfg) { + if (cd_table) { u64 strw =3D smmu->features & ARM_SMMU_FEAT_E2H ? STRTAB_STE_1_STRW_EL2 : STRTAB_STE_1_STRW_NSEL1; =20 @@ -1360,10 +1359,10 @@ static void arm_smmu_write_strtab_ent(struct arm_sm= mu_master *master, u32 sid, !master->stall_enabled) dst[1] |=3D cpu_to_le64(STRTAB_STE_1_S1STALLD); =20 - val |=3D (s1_cfg->cdcfg.cdtab_dma & STRTAB_STE_0_S1CTXPTR_MASK) | + val |=3D (cd_table->cdtab_dma & STRTAB_STE_0_S1CTXPTR_MASK) | FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_S1_TRANS) | - FIELD_PREP(STRTAB_STE_0_S1CDMAX, s1_cfg->s1cdmax) | - FIELD_PREP(STRTAB_STE_0_S1FMT, s1_cfg->s1fmt); + FIELD_PREP(STRTAB_STE_0_S1CDMAX, cd_table->s1cdmax) | + FIELD_PREP(STRTAB_STE_0_S1FMT, cd_table->s1fmt); } =20 if (s2_cfg) { @@ -2082,11 +2081,11 @@ static void arm_smmu_domain_free(struct iommu_domai= n *domain) =20 /* Free the CD and ASID, if we allocated them */ if (smmu_domain->stage =3D=3D ARM_SMMU_DOMAIN_S1) { - struct arm_smmu_s1_cfg *cfg =3D &smmu_domain->s1_cfg; + struct arm_smmu_ctx_desc_cfg *cd_table =3D &smmu_domain->cd_table; =20 /* Prevent SVA from touching the CD while we're freeing it */ mutex_lock(&arm_smmu_asid_lock); - if (cfg->cdcfg.cdtab) + if (cd_table->cdtab) arm_smmu_free_cd_tables(smmu_domain); arm_smmu_free_asid(&smmu_domain->cd); mutex_unlock(&arm_smmu_asid_lock); @@ -2106,7 +2105,7 @@ static int arm_smmu_domain_finalise_s1(struct arm_smm= u_domain *smmu_domain, int ret; u32 asid; struct arm_smmu_device *smmu =3D smmu_domain->smmu; - struct arm_smmu_s1_cfg *cfg =3D &smmu_domain->s1_cfg; + struct arm_smmu_ctx_desc_cfg *cd_table =3D &smmu_domain->cd_table; struct arm_smmu_ctx_desc *cd =3D &smmu_domain->cd; typeof(&pgtbl_cfg->arm_lpae_s1_cfg.tcr) tcr =3D &pgtbl_cfg->arm_lpae_s1_c= fg.tcr; =20 @@ -2119,7 +2118,7 @@ static int arm_smmu_domain_finalise_s1(struct arm_smm= u_domain *smmu_domain, if (ret) goto out_unlock; =20 - cfg->s1cdmax =3D master->ssid_bits; + cd_table->s1cdmax =3D master->ssid_bits; =20 smmu_domain->stall_enabled =3D master->stall_enabled; =20 @@ -2457,7 +2456,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *d= omain, struct device *dev) ret =3D -EINVAL; goto out_unlock; } else if (smmu_domain->stage =3D=3D ARM_SMMU_DOMAIN_S1 && - master->ssid_bits !=3D smmu_domain->s1_cfg.s1cdmax) { + master->ssid_bits !=3D smmu_domain->cd_table.s1cdmax) { ret =3D -EINVAL; goto out_unlock; } else if (smmu_domain->stage =3D=3D ARM_SMMU_DOMAIN_S1 && diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.h index f841383a55a35..5f0e7468db5f3 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -595,11 +595,8 @@ struct arm_smmu_ctx_desc_cfg { dma_addr_t cdtab_dma; struct arm_smmu_l1_ctx_desc *l1_desc; unsigned int num_l1_ents; -}; - -struct arm_smmu_s1_cfg { - struct arm_smmu_ctx_desc_cfg cdcfg; u8 s1fmt; + /* log2 of the maximum number of CDs supported by this table */ u8 s1cdmax; }; =20 @@ -725,7 +722,7 @@ struct arm_smmu_domain { union { struct { struct arm_smmu_ctx_desc cd; - struct arm_smmu_s1_cfg s1_cfg; + struct arm_smmu_ctx_desc_cfg cd_table; }; struct arm_smmu_s2_cfg s2_cfg; }; --=20 2.42.0.283.g2d96d420d3-goog From nobody Fri Dec 19 03:42:41 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9E2BC83F35 for ; Thu, 31 Aug 2023 17:46:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346919AbjHaRqK (ORCPT ); Thu, 31 Aug 2023 13:46:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346965AbjHaRqH (ORCPT ); Thu, 31 Aug 2023 13:46:07 -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 7C5E6E7C for ; Thu, 31 Aug 2023 10:46:01 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-58f9db8bc1dso13768977b3.3 for ; Thu, 31 Aug 2023 10:46:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1693503960; x=1694108760; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ByI1wEibb2VTlOST1QE2nymSPLoO1tZHs3WuW7YknC4=; b=Dpkn72Njeaw/NHD7HGE77sAWsit8z0YsFeQI2QL2BlaHijvsS411joYD82mmxQUNr7 C7o8LsSL9YAAnHm9JfDeuirR8sLx6qjmRxcfZyB/e4/eCRL8jZXa81atHXM9ukPWvsK5 eZjDnhI5raJv06drh6MPgkpbPcYqq7cqT97SNtTIDIkQ7J8trjVe5cFXrC+C6+ySCcma vWe3RguaPUA5Mz6skPdL4znIhHwtXuqYRYRb/c3B6seDW2dLPt/os52Wacv/66B/z8GY w/C1WTXmWdiKhR0BO3GS5iu43mScvVVUGu0hGyJo5LZNNmDBRCR4qHry7B59SOouCtA6 vHpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693503960; x=1694108760; 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=ByI1wEibb2VTlOST1QE2nymSPLoO1tZHs3WuW7YknC4=; b=iAM+UF2RLIcOsuVpkbZanNdvjpw+6cfwTcZkuxE7RiJKfw2bDpZmEbf9/hMmGPCLWk kkCH4yXy/Ik12ISELoAM1jehF54if0jzBuiS0ms3JFhYv19zjXNFOGwS1nPvJwOTPo3y 42NLldQHdDD1lJBztakjcEbu6Kbmd3RpWMPVqn3yhXKzYUUjE9vw4hhzfMYBpXhd2eAp HQq0jtVaCbw3nD8uzyJ+TmWdCC9ogAZfe2pxVpjPqmj/wT27x+AdQl2qHgc8BveyptGK 5IWopchclDdqlSokKuLoFPM+wj2Bru2hafnkCdi3NEjn7Xhv53GMh1oiKDqHe3ICbPJx qrew== X-Gm-Message-State: AOJu0Ywtb8suh20Ys27j3opxQSEdmUA2ICD/J1+RGef9/ZO4TpBE03w7 TJq08xvymlvIGiu5UsePMZETOKIfgE6b X-Google-Smtp-Source: AGHT+IETeP/TvPNLQEuYy1USk5YI0K7POPLA/zLoU/1XNZBN0JFR3w9Gk0WHW9caWehCDRFFCCFE2F0gY1LX X-Received: from mshavit.ntc.corp.google.com ([2401:fa00:95:20c:1a0a:7338:4a5a:5f83]) (user=mshavit job=sendgmr) by 2002:a81:eb0a:0:b0:576:8cb6:62a9 with SMTP id n10-20020a81eb0a000000b005768cb662a9mr2924ywm.6.1693503960746; Thu, 31 Aug 2023 10:46:00 -0700 (PDT) Date: Fri, 1 Sep 2023 01:44:32 +0800 In-Reply-To: <20230831174536.103472-1-mshavit@google.com> Mime-Version: 1.0 References: <20230831174536.103472-1-mshavit@google.com> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog Message-ID: <20230901014413.v7.3.I875254464d044a8ce8b3a2ad6beb655a4a006456@changeid> Subject: [PATCH v7 3/9] iommu/arm-smmu-v3: Encapsulate ctx_desc_cfg init in alloc_cd_tables From: Michael Shavit To: iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: will@kernel.org, robin.murphy@arm.com, jean-philippe@linaro.org, jgg@nvidia.com, nicolinc@nvidia.com, Michael Shavit , Jason Gunthorpe , Joerg Roedel , Kevin Tian , "Kirill A. Shutemov" , Lu Baolu , Mark Brown , Yicong Yang Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This is slighlty cleaner: arm_smmu_ctx_desc_cfg is initialized in a single function instead of having pieces set ahead-of time by its caller. Reviewed-by: Jason Gunthorpe Reviewed-by: Nicolin Chen Signed-off-by: Michael Shavit Tested-by: Nicolin Chen --- (no changes since v1) drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.c index 5d1977027d2c4..5bb13fadb41ad 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1132,7 +1132,8 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_domain *s= mmu_domain, int ssid, return 0; } =20 -static int arm_smmu_alloc_cd_tables(struct arm_smmu_domain *smmu_domain) +static int arm_smmu_alloc_cd_tables(struct arm_smmu_domain *smmu_domain, + struct arm_smmu_master *master) { int ret; size_t l1size; @@ -1140,6 +1141,7 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_d= omain *smmu_domain) struct arm_smmu_device *smmu =3D smmu_domain->smmu; struct arm_smmu_ctx_desc_cfg *cdcfg =3D &smmu_domain->cd_table; =20 + cdcfg->s1cdmax =3D master->ssid_bits; max_contexts =3D 1 << cdcfg->s1cdmax; =20 if (!(smmu->features & ARM_SMMU_FEAT_2_LVL_CDTAB) || @@ -2105,7 +2107,6 @@ static int arm_smmu_domain_finalise_s1(struct arm_smm= u_domain *smmu_domain, int ret; u32 asid; struct arm_smmu_device *smmu =3D smmu_domain->smmu; - struct arm_smmu_ctx_desc_cfg *cd_table =3D &smmu_domain->cd_table; struct arm_smmu_ctx_desc *cd =3D &smmu_domain->cd; typeof(&pgtbl_cfg->arm_lpae_s1_cfg.tcr) tcr =3D &pgtbl_cfg->arm_lpae_s1_c= fg.tcr; =20 @@ -2118,11 +2119,9 @@ static int arm_smmu_domain_finalise_s1(struct arm_sm= mu_domain *smmu_domain, if (ret) goto out_unlock; =20 - cd_table->s1cdmax =3D master->ssid_bits; - smmu_domain->stall_enabled =3D master->stall_enabled; =20 - ret =3D arm_smmu_alloc_cd_tables(smmu_domain); + ret =3D arm_smmu_alloc_cd_tables(smmu_domain, master); if (ret) goto out_free_asid; =20 --=20 2.42.0.283.g2d96d420d3-goog From nobody Fri Dec 19 03:42:41 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73D65C83F35 for ; Thu, 31 Aug 2023 17:46:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346950AbjHaRqO (ORCPT ); Thu, 31 Aug 2023 13:46:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346586AbjHaRqN (ORCPT ); Thu, 31 Aug 2023 13:46:13 -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 AD60510DD for ; Thu, 31 Aug 2023 10:46:05 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-58fbfcb8d90so14711617b3.1 for ; Thu, 31 Aug 2023 10:46:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1693503965; x=1694108765; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=o+w3KBHikFTGwIimaQYuBypMhrw19N7uERmLhmvMz58=; b=dH6aTw0EwoDFhyUD+8hisSUQiBZBgeXEFgJiTXnqe1/H4xq5oDDOq6ocIbNx4HSRe/ ICK6l5HmYmdUY73z52rp8qGGXtEJEiCam+lTTFmmcAOzkgbosBSAPs0nhfAq8A12R+5a uImhjUkTm2zmczOXo40Lj7iKPkN1lyNe4dtnd2/BUkkr4FdXR4dOhEtY82ylEe8FeXnU 6ho0AWEQKlWa67Z+or1tdcEKhD5qjtZ6qCYvEeu2grDW+V7ub29chtuHonUUKfr3CeO3 ZGb/m4Tit532B8s0mLMJ9kNtzIY5g48b3Z9aNhPE/0yQqNIqGpN0Sr6EbzLELjZhxDxt UJNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693503965; x=1694108765; 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=o+w3KBHikFTGwIimaQYuBypMhrw19N7uERmLhmvMz58=; b=NxCsne/NunltMFYaZ78xmBuyChjnZlDzk5ijzW1S6pNdSFYNK4sjhPob21NV05eyEg cMUdHndWaJeXpksaPGjkbR4GG5MjxX424X3BCmXPYz1BUH00q4HYIT7+JkGVPgz6c5Uh SPozBpAOXUkkYh9HvpH23xCukfw2ITpuTdTnNpDEosuZOY6qX2YAPyf+frzGBzb2qU5H zfdETLxo2Y5rvL4pGSuPb8fORxxJ3dYXURdNSwIO1I08XFaTdan1AtucypW9B7Hl3aQO DilDO5cEgzmIr5wEi6QPfkEbEN+d+yhan2J0YfwHDoMRj0UGkzTAKoG2hL5Jy50mnXcX rYmA== X-Gm-Message-State: AOJu0YyIb3nI5aGSRzMvdQDZpn/zTLinxCvVGdgJcy6F430dbp88Lpi7 73IXvbViGnvdzGaimBtneC9k013Hbq2P X-Google-Smtp-Source: AGHT+IFAWVZV2caLtc+pnQCsFawM0vj56icg1pDwBPCBAR0uE5NsLxwemjROnxuZAPffh9wiN1C0yPtzEIKV X-Received: from mshavit.ntc.corp.google.com ([2401:fa00:95:20c:1a0a:7338:4a5a:5f83]) (user=mshavit job=sendgmr) by 2002:a81:b61f:0:b0:56f:f62b:7a11 with SMTP id u31-20020a81b61f000000b0056ff62b7a11mr2293ywh.8.1693503964944; Thu, 31 Aug 2023 10:46:04 -0700 (PDT) Date: Fri, 1 Sep 2023 01:44:33 +0800 In-Reply-To: <20230831174536.103472-1-mshavit@google.com> Mime-Version: 1.0 References: <20230831174536.103472-1-mshavit@google.com> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog Message-ID: <20230901014413.v7.4.I5aa89c849228794a64146cfe86df21fb71629384@changeid> Subject: [PATCH v7 4/9] iommu/arm-smmu-v3: move stall_enabled to the cd table From: Michael Shavit To: iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: will@kernel.org, robin.murphy@arm.com, jean-philippe@linaro.org, jgg@nvidia.com, nicolinc@nvidia.com, Michael Shavit , Jason Gunthorpe , Joerg Roedel , Kevin Tian , "Kirill A. Shutemov" , Lu Baolu , Mark Brown , Yicong Yang Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A domain can be attached to multiple masters with different master->stall_enabled values. The stall bit of a CD entry should follow master->stall_enabled and has an inverse relationship with the STE.S1STALLD bit. The stall_enabled bit does not depend on any property of the domain, so move it out of the arm_smmu_domain struct. Move it to the CD table struct so that it can fully describe how CD entries should be written to it. Reviewed-by: Jason Gunthorpe Reviewed-by: Nicolin Chen Signed-off-by: Michael Shavit Tested-by: Nicolin Chen --- (no changes since v5) Changes in v5: - Reword commit Changes in v2: - Use a bitfield instead of a bool for stall_enabled drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 8 ++++---- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.c index 5bb13fadb41ad..44df7c0926802 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1114,7 +1114,7 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_domain *s= mmu_domain, int ssid, FIELD_PREP(CTXDESC_CD_0_ASID, cd->asid) | CTXDESC_CD_0_V; =20 - if (smmu_domain->stall_enabled) + if (smmu_domain->cd_table.stall_enabled) val |=3D CTXDESC_CD_0_S; } =20 @@ -1141,6 +1141,7 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_d= omain *smmu_domain, struct arm_smmu_device *smmu =3D smmu_domain->smmu; struct arm_smmu_ctx_desc_cfg *cdcfg =3D &smmu_domain->cd_table; =20 + cdcfg->stall_enabled =3D master->stall_enabled; cdcfg->s1cdmax =3D master->ssid_bits; max_contexts =3D 1 << cdcfg->s1cdmax; =20 @@ -2119,8 +2120,6 @@ static int arm_smmu_domain_finalise_s1(struct arm_smm= u_domain *smmu_domain, if (ret) goto out_unlock; =20 - smmu_domain->stall_enabled =3D master->stall_enabled; - ret =3D arm_smmu_alloc_cd_tables(smmu_domain, master); if (ret) goto out_free_asid; @@ -2459,7 +2458,8 @@ static int arm_smmu_attach_dev(struct iommu_domain *d= omain, struct device *dev) ret =3D -EINVAL; goto out_unlock; } else if (smmu_domain->stage =3D=3D ARM_SMMU_DOMAIN_S1 && - smmu_domain->stall_enabled !=3D master->stall_enabled) { + smmu_domain->cd_table.stall_enabled !=3D + master->stall_enabled) { ret =3D -EINVAL; goto out_unlock; } diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.h index 5f0e7468db5f3..007758df57610 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -598,6 +598,8 @@ struct arm_smmu_ctx_desc_cfg { u8 s1fmt; /* log2 of the maximum number of CDs supported by this table */ u8 s1cdmax; + /* Whether CD entries in this table have the stall bit set. */ + u8 stall_enabled:1; }; =20 struct arm_smmu_s2_cfg { @@ -715,7 +717,6 @@ struct arm_smmu_domain { struct mutex init_mutex; /* Protects smmu pointer */ =20 struct io_pgtable_ops *pgtbl_ops; - bool stall_enabled; atomic_t nr_ats_masters; =20 enum arm_smmu_domain_stage stage; --=20 2.42.0.283.g2d96d420d3-goog From nobody Fri Dec 19 03:42:41 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E0ABC83F35 for ; Thu, 31 Aug 2023 17:46:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346958AbjHaRq0 (ORCPT ); Thu, 31 Aug 2023 13:46:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233316AbjHaRqZ (ORCPT ); Thu, 31 Aug 2023 13:46:25 -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 7487A10E6 for ; Thu, 31 Aug 2023 10:46:10 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-58fb9323a27so14064747b3.1 for ; Thu, 31 Aug 2023 10:46:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1693503969; x=1694108769; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=w3I8Ygy6DcsMLN55whhxyEbEgQo4X2xjrF5n3oW9r44=; b=tKuMMl84dMzmWMxa3EinR3o7Pf9mJHhRM+sDPH5fwI27cz+NrmS5eORp8EVC8tD3eF XElE6MKrRUasDfAWSginbwtnVyH440AB3z/alzRFxU13yYmPjXddqNd7LG0anmCswhIk 80Vo7l6A7QT0EDigaFTVK3C9nhqNnUtwhNf6RmSQJN6R9V5RhALLf/Vm/X40NtwzerPq k2m8/xqBjz54LOc0etVXUnO6EZx36ZcMP+TESei/p/SdAj1AZLqmHmnsB6gIEknH5noL tuwNw8h/FOkHDWeulPM/bCF9PAKs5Ds9U8SERrbjT/3TNglsEloY/QrhxraJ+seVp3+J uuPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693503969; x=1694108769; 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=w3I8Ygy6DcsMLN55whhxyEbEgQo4X2xjrF5n3oW9r44=; b=UQVjkAXsb9oii2JSCZm8j0Ubv7mMkp+Hv63Tqoe91eM1SdRl1vCqc6ke+JY4J5A4XG HS4UMDhK3A5lYmf0fJqfEb1ii3qy53f1KZe5n1kVrM2//KY5ARpyEFA2ezl0uZ1yNmB8 xeCeoc9dyPiCnyfIwQNSW+3/EkY3YnF12cPMcDjE4euDhWtlftBO+BOu6x/HIVm20LIe AxMoyBCNERes7AfuBV6p5zntyJo4d0XQ++gKX28zQzPFO/hxHVxIEKDVBjGHL3/ZJbUZ HGfBLTSd73meugof25rL0hNL6RoZdMqiWWpeGFBoMJmkndyAlK+mnK46LdQ/8CmtsQB4 QkJw== X-Gm-Message-State: AOJu0YyRp4tABgGi7vTAVFNwQxd6YRJsCpiW8cSwKmmRGI5WRHmw1AfB cl2BwgnUeDDwT/mMvGZ7tt1MeqYihZXV X-Google-Smtp-Source: AGHT+IF5B4he3eZkDz7k0UdFEAerRxOqKdFQx4AkB65eUUUR5N6V3kELU3i1Q1XEtQh94nXA1dIB3LoASzwp X-Received: from mshavit.ntc.corp.google.com ([2401:fa00:95:20c:1a0a:7338:4a5a:5f83]) (user=mshavit job=sendgmr) by 2002:a25:7343:0:b0:d77:df8a:389a with SMTP id o64-20020a257343000000b00d77df8a389amr10244ybc.3.1693503969439; Thu, 31 Aug 2023 10:46:09 -0700 (PDT) Date: Fri, 1 Sep 2023 01:44:34 +0800 In-Reply-To: <20230831174536.103472-1-mshavit@google.com> Mime-Version: 1.0 References: <20230831174536.103472-1-mshavit@google.com> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog Message-ID: <20230901014413.v7.5.I219054a6cf538df5bb22f4ada2d9933155d6058c@changeid> Subject: [PATCH v7 5/9] iommu/arm-smmu-v3: Refactor write_ctx_desc From: Michael Shavit To: iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: will@kernel.org, robin.murphy@arm.com, jean-philippe@linaro.org, jgg@nvidia.com, nicolinc@nvidia.com, Michael Shavit , Jason Gunthorpe , Joerg Roedel , Kevin Tian , "Kirill A. Shutemov" , Lu Baolu , Mark Brown , Yicong Yang Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Update arm_smmu_write_ctx_desc and downstream functions to operate on a master instead of an smmu domain. We expect arm_smmu_write_ctx_desc() to only be called to write a CD entry into a CD table owned by the master. Under the hood, arm_smmu_write_ctx_desc still fetches the CD table from the domain that is attached to the master, but a subsequent commit will move that table's ownership to the master. Note that this change isn't a nop refactor since SVA will call arm_smmu_write_ctx_desc in a loop for every master the domain is attached to despite the fact that they all share the same CD table. This loop may look weird but becomes necessary when the CD table becomes per-master in a subsequent commit. Reviewed-by: Jason Gunthorpe Reviewed-by: Nicolin Chen Signed-off-by: Michael Shavit Tested-by: Nicolin Chen --- Changes in v7: - Change the amr_smmu_write_ctx_desc_devices helper introduced to arm_smmu_update_ctx_desc_devices to distinguish from the case where a potentially new CD entry is written to. Add a comment to clarify that it is assumed that the operation can't fail and that it's therefore safe not to handle the return. In contrast, the case where a new CD entry is written-to does not use the helper and does have to handle failure. - Remove unintended formatting change in this commit. Changes in v6: - Unwind the loop in amr_smmu_write_ctx_desc_devices to NULL out the CD entries we succesfully wrote on failure. - Add a comment clarifying the different usages of amr_smmu_write_ctx_desc_devices Changes in v3: - Add a helper to write a CD to all masters that a domain is attached to. - Fixed an issue where an arm_smmu_write_ctx_desc error return wasn't correctly handled by its caller. Changes in v2: - minor style fixes Changes in v1: - arm_smmu_write_ctx_desc now get's the CD table to write to from the master parameter instead of a distinct parameter. This works well because the CD table being written to should always be owned by the master by the end of this series. This version no longer allows master to be NULL. .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 39 +++++++++++++-- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 48 +++++++------------ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 +- 3 files changed, 54 insertions(+), 35 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iomm= u/arm/arm-smmu-v3/arm-smmu-v3-sva.c index 968559d625c40..c89cd8877c891 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 @@ -37,6 +37,25 @@ struct arm_smmu_bond { =20 static DEFINE_MUTEX(sva_lock); =20 +/* + * Write the CD to the CD tables for all masters that this domain is attac= hed + * to. Note that this is only used to update existing CD entries in the ta= rget + * CD table, for which it's assumed that arm_smmu_write_ctx_desc can't fai= l. + */ +static void arm_smmu_update_ctx_desc_devices(struct arm_smmu_domain *smmu_= domain, + int ssid, + struct arm_smmu_ctx_desc *cd) +{ + struct arm_smmu_master *master; + unsigned long flags; + + spin_lock_irqsave(&smmu_domain->devices_lock, flags); + list_for_each_entry(master, &smmu_domain->devices, domain_head) { + arm_smmu_write_ctx_desc(master, ssid, cd); + } + spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); +} + /* * Check if the CPU ASID is available on the SMMU side. If a private conte= xt * descriptor is using it, try to replace it. @@ -80,7 +99,7 @@ arm_smmu_share_asid(struct mm_struct *mm, u16 asid) * be some overlap between use of both ASIDs, until we invalidate the * TLB. */ - arm_smmu_write_ctx_desc(smmu_domain, 0, cd); + arm_smmu_update_ctx_desc_devices(smmu_domain, 0, cd); =20 /* Invalidate TLB entries previously associated with that context */ arm_smmu_tlb_inv_asid(smmu, asid); @@ -222,7 +241,7 @@ static void arm_smmu_mm_release(struct mmu_notifier *mn= , struct mm_struct *mm) * DMA may still be running. Keep the cd valid to avoid C_BAD_CD events, * but disable translation. */ - arm_smmu_write_ctx_desc(smmu_domain, mm->pasid, &quiet_cd); + arm_smmu_update_ctx_desc_devices(smmu_domain, mm->pasid, &quiet_cd); =20 arm_smmu_tlb_inv_asid(smmu_domain->smmu, smmu_mn->cd->asid); arm_smmu_atc_inv_domain(smmu_domain, mm->pasid, 0, 0); @@ -248,8 +267,10 @@ arm_smmu_mmu_notifier_get(struct arm_smmu_domain *smmu= _domain, struct mm_struct *mm) { int ret; + unsigned long flags; struct arm_smmu_ctx_desc *cd; struct arm_smmu_mmu_notifier *smmu_mn; + struct arm_smmu_master *master; =20 list_for_each_entry(smmu_mn, &smmu_domain->mmu_notifiers, list) { if (smmu_mn->mn.mm =3D=3D mm) { @@ -279,7 +300,16 @@ arm_smmu_mmu_notifier_get(struct arm_smmu_domain *smmu= _domain, goto err_free_cd; } =20 - ret =3D arm_smmu_write_ctx_desc(smmu_domain, mm->pasid, cd); + spin_lock_irqsave(&smmu_domain->devices_lock, flags); + list_for_each_entry(master, &smmu_domain->devices, domain_head) { + ret =3D arm_smmu_write_ctx_desc(master, mm->pasid, cd); + if (ret) { + list_for_each_entry_from_reverse(master, &smmu_domain->devices, domain_= head) + arm_smmu_write_ctx_desc(master, mm->pasid, NULL); + break; + } + } + spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); if (ret) goto err_put_notifier; =20 @@ -304,7 +334,8 @@ static void arm_smmu_mmu_notifier_put(struct arm_smmu_m= mu_notifier *smmu_mn) return; =20 list_del(&smmu_mn->list); - arm_smmu_write_ctx_desc(smmu_domain, mm->pasid, NULL); + + arm_smmu_update_ctx_desc_devices(smmu_domain, mm->pasid, NULL); =20 /* * If we went through clear(), we've already invalidated, and no diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.c index 44df7c0926802..69b9bb5c7f773 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -971,14 +971,12 @@ void arm_smmu_tlb_inv_asid(struct arm_smmu_device *sm= mu, u16 asid) arm_smmu_cmdq_issue_cmd_with_sync(smmu, &cmd); } =20 -static void arm_smmu_sync_cd(struct arm_smmu_domain *smmu_domain, +static void arm_smmu_sync_cd(struct arm_smmu_master *master, int ssid, bool leaf) { size_t i; - unsigned long flags; - struct arm_smmu_master *master; struct arm_smmu_cmdq_batch cmds; - struct arm_smmu_device *smmu =3D smmu_domain->smmu; + struct arm_smmu_device *smmu =3D master->smmu; struct arm_smmu_cmdq_ent cmd =3D { .opcode =3D CMDQ_OP_CFGI_CD, .cfgi =3D { @@ -988,15 +986,10 @@ static void arm_smmu_sync_cd(struct arm_smmu_domain *= smmu_domain, }; =20 cmds.num =3D 0; - - spin_lock_irqsave(&smmu_domain->devices_lock, flags); - list_for_each_entry(master, &smmu_domain->devices, domain_head) { - for (i =3D 0; i < master->num_streams; i++) { - cmd.cfgi.sid =3D master->streams[i].id; - arm_smmu_cmdq_batch_add(smmu, &cmds, &cmd); - } + for (i =3D 0; i < master->num_streams; i++) { + cmd.cfgi.sid =3D master->streams[i].id; + arm_smmu_cmdq_batch_add(smmu, &cmds, &cmd); } - spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); =20 arm_smmu_cmdq_batch_submit(smmu, &cmds); } @@ -1026,14 +1019,13 @@ static void arm_smmu_write_cd_l1_desc(__le64 *dst, WRITE_ONCE(*dst, cpu_to_le64(val)); } =20 -static __le64 *arm_smmu_get_cd_ptr(struct arm_smmu_domain *smmu_domain, - u32 ssid) +static __le64 *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, u32 ssi= d) { __le64 *l1ptr; unsigned int idx; struct arm_smmu_l1_ctx_desc *l1_desc; - struct arm_smmu_device *smmu =3D smmu_domain->smmu; - struct arm_smmu_ctx_desc_cfg *cdcfg =3D &smmu_domain->cd_table; + struct arm_smmu_device *smmu =3D master->smmu; + struct arm_smmu_ctx_desc_cfg *cdcfg =3D &master->domain->cd_table; =20 if (cdcfg->s1fmt =3D=3D STRTAB_STE_0_S1FMT_LINEAR) return cdcfg->cdtab + ssid * CTXDESC_CD_DWORDS; @@ -1047,13 +1039,13 @@ static __le64 *arm_smmu_get_cd_ptr(struct arm_smmu_= domain *smmu_domain, l1ptr =3D cdcfg->cdtab + idx * CTXDESC_L1_DESC_DWORDS; arm_smmu_write_cd_l1_desc(l1ptr, l1_desc); /* An invalid L1CD can be cached */ - arm_smmu_sync_cd(smmu_domain, ssid, false); + arm_smmu_sync_cd(master, ssid, false); } idx =3D ssid & (CTXDESC_L2_ENTRIES - 1); return l1_desc->l2ptr + idx * CTXDESC_CD_DWORDS; } =20 -int arm_smmu_write_ctx_desc(struct arm_smmu_domain *smmu_domain, int ssid, +int arm_smmu_write_ctx_desc(struct arm_smmu_master *master, int ssid, struct arm_smmu_ctx_desc *cd) { /* @@ -1070,11 +1062,12 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_domain = *smmu_domain, int ssid, u64 val; bool cd_live; __le64 *cdptr; + struct arm_smmu_ctx_desc_cfg *cd_table =3D &master->domain->cd_table; =20 - if (WARN_ON(ssid >=3D (1 << smmu_domain->cd_table.s1cdmax))) + if (WARN_ON(ssid >=3D (1 << cd_table->s1cdmax))) return -E2BIG; =20 - cdptr =3D arm_smmu_get_cd_ptr(smmu_domain, ssid); + cdptr =3D arm_smmu_get_cd_ptr(master, ssid); if (!cdptr) return -ENOMEM; =20 @@ -1102,7 +1095,7 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_domain *s= mmu_domain, int ssid, * order. Ensure that it observes valid values before reading * V=3D1. */ - arm_smmu_sync_cd(smmu_domain, ssid, true); + arm_smmu_sync_cd(master, ssid, true); =20 val =3D cd->tcr | #ifdef __BIG_ENDIAN @@ -1114,7 +1107,7 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_domain *s= mmu_domain, int ssid, FIELD_PREP(CTXDESC_CD_0_ASID, cd->asid) | CTXDESC_CD_0_V; =20 - if (smmu_domain->cd_table.stall_enabled) + if (cd_table->stall_enabled) val |=3D CTXDESC_CD_0_S; } =20 @@ -1128,7 +1121,7 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_domain *s= mmu_domain, int ssid, * without first making the structure invalid. */ WRITE_ONCE(cdptr[0], cpu_to_le64(val)); - arm_smmu_sync_cd(smmu_domain, ssid, true); + arm_smmu_sync_cd(master, ssid, true); return 0; } =20 @@ -1138,7 +1131,7 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_d= omain *smmu_domain, int ret; size_t l1size; size_t max_contexts; - struct arm_smmu_device *smmu =3D smmu_domain->smmu; + struct arm_smmu_device *smmu =3D master->smmu; struct arm_smmu_ctx_desc_cfg *cdcfg =3D &smmu_domain->cd_table; =20 cdcfg->stall_enabled =3D master->stall_enabled; @@ -2135,12 +2128,7 @@ static int arm_smmu_domain_finalise_s1(struct arm_sm= mu_domain *smmu_domain, CTXDESC_CD_0_TCR_EPD1 | CTXDESC_CD_0_AA64; cd->mair =3D pgtbl_cfg->arm_lpae_s1_cfg.mair; =20 - /* - * Note that this will end up calling arm_smmu_sync_cd() before - * the master has been added to the devices list for this domain. - * This isn't an issue because the STE hasn't been installed yet. - */ - ret =3D arm_smmu_write_ctx_desc(smmu_domain, 0, cd); + ret =3D arm_smmu_write_ctx_desc(master, 0, cd); if (ret) goto out_free_cd_tables; =20 diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.h index 007758df57610..00f8e6388848e 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -745,7 +745,7 @@ extern struct xarray arm_smmu_asid_xa; extern struct mutex arm_smmu_asid_lock; extern struct arm_smmu_ctx_desc quiet_cd; =20 -int arm_smmu_write_ctx_desc(struct arm_smmu_domain *smmu_domain, int ssid, +int arm_smmu_write_ctx_desc(struct arm_smmu_master *smmu_master, int ssid, struct arm_smmu_ctx_desc *cd); void arm_smmu_tlb_inv_asid(struct arm_smmu_device *smmu, u16 asid); void arm_smmu_tlb_inv_range_asid(unsigned long iova, size_t size, int asid, --=20 2.42.0.283.g2d96d420d3-goog From nobody Fri Dec 19 03:42:41 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1516C83F37 for ; Thu, 31 Aug 2023 17:46:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346961AbjHaRqm (ORCPT ); Thu, 31 Aug 2023 13:46:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233316AbjHaRqk (ORCPT ); Thu, 31 Aug 2023 13:46:40 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A34FF1704 for ; Thu, 31 Aug 2023 10:46:14 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d7493303b5cso940586276.2 for ; Thu, 31 Aug 2023 10:46:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1693503974; x=1694108774; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=i7VjOD8paVBTT/i2kkoQBwaJlSloOfoXnTHQ1Eza9rY=; b=caytXUIXpvgER0McdFHicRzq9EIoWKxXrt52BsiSo2OOOcthCVCCD1DH0+Hv17v+ez ZQ+omL5eCQ33ZmzgHNdnp+Qo7F5EmNUy6dTrseLgUYAi1nzm912f8QxJ9dxA5WhUbdq+ dZHn8Qz6U8vLbX/gx846ALWeWeM9AfJuEtGtnJmK/0jDy7cSydUfVzpuF4XkMGv89EQt 9CkIZZccepTXQHrcuncGYXq9guaEfTKLgJcnkaBKrJvMJv7LCvPULspD9Dlh5nuC97nQ FBwkylKiIWLumtAewiHH0x9/QeE30SWoaWL84mk3hL6pu3Iq1bmKbK57LR2O+b7zYvWB I4yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693503974; x=1694108774; 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=i7VjOD8paVBTT/i2kkoQBwaJlSloOfoXnTHQ1Eza9rY=; b=LzUk1SQOezdofj63ENApDSWgT/jUffGn4AfU5UmcqXTKXqjCBQi9f+7yAI7T8QzlDf vR19f1MaCxiR6dGcW/fu0nM77yjh4pLwJ/eetpqg9w6czFVUa6gCdlNZ2W7z445/TMhu w+55La40h8eXi0N+Uy8lI9ugVjB+CRIN47p2qrqwXUZO26kDzBaWXaUhxBHEu7ZaK/rd vPsuV67LvX//ZxfxNkHqyJ3y+38wNGSHmfuMC10oCje9puRMD14VU4gSGDuFNJgc7EME p7BzibctVv1dqxmnHoQ+I2LXQxzXisyWnyhmjtyilkQ6H/I5+JHgZDXSLcRJ1luJ4mCr RauA== X-Gm-Message-State: AOJu0YyryA/Fj18CN2I6b8vklgqSSnFiwTJg8FTUuTwXbdP0XnDXZdxz TfYktzEfmCLY2fUDIXq6lW75/qTcsxsM X-Google-Smtp-Source: AGHT+IHRa4lOvgolrcThFwuiSmnWSM47tU5dtwzo9XjBsvC5OMF90W0tNaj+15w7MHzP+4BubJnyK4n2OPmz X-Received: from mshavit.ntc.corp.google.com ([2401:fa00:95:20c:1a0a:7338:4a5a:5f83]) (user=mshavit job=sendgmr) by 2002:a25:ba90:0:b0:d72:8661:ee29 with SMTP id s16-20020a25ba90000000b00d728661ee29mr9278ybg.2.1693503973962; Thu, 31 Aug 2023 10:46:13 -0700 (PDT) Date: Fri, 1 Sep 2023 01:44:35 +0800 In-Reply-To: <20230831174536.103472-1-mshavit@google.com> Mime-Version: 1.0 References: <20230831174536.103472-1-mshavit@google.com> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog Message-ID: <20230901014413.v7.6.Ice063dcf87d1b777a72e008d9e3406d2bcf6d876@changeid> Subject: [PATCH v7 6/9] iommu/arm-smmu-v3: Move CD table to arm_smmu_master From: Michael Shavit To: iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: will@kernel.org, robin.murphy@arm.com, jean-philippe@linaro.org, jgg@nvidia.com, nicolinc@nvidia.com, Michael Shavit , Jason Gunthorpe , Joerg Roedel , Kevin Tian , "Kirill A. Shutemov" , Lu Baolu , Mark Brown , Yicong Yang Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" With this change, each master will now own its own CD table instead of sharing one with other masters attached to the same domain. Attaching a stage 1 domain installs CD entries into the master's CD table. SVA writes its CD entries into each master's CD table if the domain is shared across masters. Also add the device to the devices list before writing the CD to the table so that SVA will know that the CD needs to be re-written to this device's CD table as well if it decides to update the CD's ASID concurrently with this function. Tested-by: Nicolin Chen Reviewed-by: Jason Gunthorpe Signed-off-by: Michael Shavit --- Changes in v7: - Update commit message to be more clear about locking purpose. - Removed redundant newline Changes in v6: - Grab the asid lock while writing the RID CD to prevent a race with SVA. - Add the device to the devices list before writing the CD to the table and installing the CD table. - Undo arm_smmu_finalise_s1 rename - Minor comment fix - Consistently check cdtab pointer instead of cdtab_dma Changes in v5: - Clear the 0th CD entry when the domain is detached. Not clearing it caused a bug in arm_smmu_write_ctx_desc which doesn't expect the entry to already be set. Changes in v4: - Added comment about the cd_table's dependency on the iommu core's group mutex. - Narrowed the range of code for which the domain's init_mutex is held on attach since it now only protects the arm_smmu_domain_finalise call. Changes in v2: - Allocate CD table when it's first needed instead of on probe. Changes in v1: - The master's CD table allocation was previously split to a different commit. This change now atomically allocates the new CD table, uses it, and removes the old one. drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 100 +++++++++++--------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 7 +- 2 files changed, 58 insertions(+), 49 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.c index 69b9bb5c7f773..bcc94a67640d6 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1025,7 +1025,7 @@ static __le64 *arm_smmu_get_cd_ptr(struct arm_smmu_ma= ster *master, u32 ssid) unsigned int idx; struct arm_smmu_l1_ctx_desc *l1_desc; struct arm_smmu_device *smmu =3D master->smmu; - struct arm_smmu_ctx_desc_cfg *cdcfg =3D &master->domain->cd_table; + struct arm_smmu_ctx_desc_cfg *cdcfg =3D &master->cd_table; =20 if (cdcfg->s1fmt =3D=3D STRTAB_STE_0_S1FMT_LINEAR) return cdcfg->cdtab + ssid * CTXDESC_CD_DWORDS; @@ -1062,7 +1062,7 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_master *m= aster, int ssid, u64 val; bool cd_live; __le64 *cdptr; - struct arm_smmu_ctx_desc_cfg *cd_table =3D &master->domain->cd_table; + struct arm_smmu_ctx_desc_cfg *cd_table =3D &master->cd_table; =20 if (WARN_ON(ssid >=3D (1 << cd_table->s1cdmax))) return -E2BIG; @@ -1125,14 +1125,13 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_master = *master, int ssid, return 0; } =20 -static int arm_smmu_alloc_cd_tables(struct arm_smmu_domain *smmu_domain, - struct arm_smmu_master *master) +static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master) { int ret; size_t l1size; size_t max_contexts; struct arm_smmu_device *smmu =3D master->smmu; - struct arm_smmu_ctx_desc_cfg *cdcfg =3D &smmu_domain->cd_table; + struct arm_smmu_ctx_desc_cfg *cdcfg =3D &master->cd_table; =20 cdcfg->stall_enabled =3D master->stall_enabled; cdcfg->s1cdmax =3D master->ssid_bits; @@ -1176,12 +1175,12 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu= _domain *smmu_domain, return ret; } =20 -static void arm_smmu_free_cd_tables(struct arm_smmu_domain *smmu_domain) +static void arm_smmu_free_cd_tables(struct arm_smmu_master *master) { int i; size_t size, l1size; - struct arm_smmu_device *smmu =3D smmu_domain->smmu; - struct arm_smmu_ctx_desc_cfg *cdcfg =3D &smmu_domain->cd_table; + struct arm_smmu_device *smmu =3D master->smmu; + struct arm_smmu_ctx_desc_cfg *cdcfg =3D &master->cd_table; =20 if (cdcfg->l1_desc) { size =3D CTXDESC_L2_ENTRIES * (CTXDESC_CD_DWORDS << 3); @@ -1289,7 +1288,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu= _master *master, u32 sid, if (smmu_domain) { switch (smmu_domain->stage) { case ARM_SMMU_DOMAIN_S1: - cd_table =3D &smmu_domain->cd_table; + cd_table =3D &master->cd_table; break; case ARM_SMMU_DOMAIN_S2: case ARM_SMMU_DOMAIN_NESTED: @@ -2075,14 +2074,10 @@ static void arm_smmu_domain_free(struct iommu_domai= n *domain) =20 free_io_pgtable_ops(smmu_domain->pgtbl_ops); =20 - /* Free the CD and ASID, if we allocated them */ + /* Free the ASID or VMID */ if (smmu_domain->stage =3D=3D ARM_SMMU_DOMAIN_S1) { - struct arm_smmu_ctx_desc_cfg *cd_table =3D &smmu_domain->cd_table; - /* Prevent SVA from touching the CD while we're freeing it */ mutex_lock(&arm_smmu_asid_lock); - if (cd_table->cdtab) - arm_smmu_free_cd_tables(smmu_domain); arm_smmu_free_asid(&smmu_domain->cd); mutex_unlock(&arm_smmu_asid_lock); } else { @@ -2113,10 +2108,6 @@ static int arm_smmu_domain_finalise_s1(struct arm_sm= mu_domain *smmu_domain, if (ret) goto out_unlock; =20 - ret =3D arm_smmu_alloc_cd_tables(smmu_domain, master); - if (ret) - goto out_free_asid; - cd->asid =3D (u16)asid; cd->ttbr =3D pgtbl_cfg->arm_lpae_s1_cfg.ttbr; cd->tcr =3D FIELD_PREP(CTXDESC_CD_0_TCR_T0SZ, tcr->tsz) | @@ -2128,17 +2119,9 @@ static int arm_smmu_domain_finalise_s1(struct arm_sm= mu_domain *smmu_domain, CTXDESC_CD_0_TCR_EPD1 | CTXDESC_CD_0_AA64; cd->mair =3D pgtbl_cfg->arm_lpae_s1_cfg.mair; =20 - ret =3D arm_smmu_write_ctx_desc(master, 0, cd); - if (ret) - goto out_free_cd_tables; - mutex_unlock(&arm_smmu_asid_lock); return 0; =20 -out_free_cd_tables: - arm_smmu_free_cd_tables(smmu_domain); -out_free_asid: - arm_smmu_free_asid(cd); out_unlock: mutex_unlock(&arm_smmu_asid_lock); return ret; @@ -2400,6 +2383,14 @@ static void arm_smmu_detach_dev(struct arm_smmu_mast= er *master) master->domain =3D NULL; master->ats_enabled =3D false; arm_smmu_install_ste_for_dev(master); + /* + * Clearing the CD entry isn't strictly required to detach the domain + * since the table is uninstalled anyway, but it helps avoid confusion + * in the call to arm_smmu_write_ctx_desc on the next attach (which + * expects the entry to be empty). + */ + if (smmu_domain->stage =3D=3D ARM_SMMU_DOMAIN_S1 && master->cd_table.cdta= b) + arm_smmu_write_ctx_desc(master, 0, NULL); } =20 static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device = *dev) @@ -2434,23 +2425,14 @@ static int arm_smmu_attach_dev(struct iommu_domain = *domain, struct device *dev) if (!smmu_domain->smmu) { smmu_domain->smmu =3D smmu; ret =3D arm_smmu_domain_finalise(domain, master); - if (ret) { + if (ret) smmu_domain->smmu =3D NULL; - goto out_unlock; - } - } else if (smmu_domain->smmu !=3D smmu) { - ret =3D -EINVAL; - goto out_unlock; - } else if (smmu_domain->stage =3D=3D ARM_SMMU_DOMAIN_S1 && - master->ssid_bits !=3D smmu_domain->cd_table.s1cdmax) { + } else if (smmu_domain->smmu !=3D smmu) ret =3D -EINVAL; - goto out_unlock; - } else if (smmu_domain->stage =3D=3D ARM_SMMU_DOMAIN_S1 && - smmu_domain->cd_table.stall_enabled !=3D - master->stall_enabled) { - ret =3D -EINVAL; - goto out_unlock; - } + + mutex_unlock(&smmu_domain->init_mutex); + if (ret) + return ret; =20 master->domain =3D smmu_domain; =20 @@ -2464,16 +2446,42 @@ static int arm_smmu_attach_dev(struct iommu_domain = *domain, struct device *dev) if (smmu_domain->stage !=3D ARM_SMMU_DOMAIN_BYPASS) master->ats_enabled =3D arm_smmu_ats_supported(master); =20 - arm_smmu_install_ste_for_dev(master); - spin_lock_irqsave(&smmu_domain->devices_lock, flags); list_add(&master->domain_head, &smmu_domain->devices); spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); =20 + if (smmu_domain->stage =3D=3D ARM_SMMU_DOMAIN_S1) { + if (!master->cd_table.cdtab) { + ret =3D arm_smmu_alloc_cd_tables(master); + if (ret) { + master->domain =3D NULL; + goto out_list_del; + } + } + + /* + * Prevent SVA from concurrently modifying the CD or writing to + * the CD entry + */ + mutex_lock(&arm_smmu_asid_lock); + ret =3D arm_smmu_write_ctx_desc(master, 0, &smmu_domain->cd); + mutex_unlock(&arm_smmu_asid_lock); + if (ret) { + master->domain =3D NULL; + goto out_list_del; + } + } + + arm_smmu_install_ste_for_dev(master); + arm_smmu_enable_ats(master); + return 0; + +out_list_del: + spin_lock_irqsave(&smmu_domain->devices_lock, flags); + list_del(&master->domain_head); + spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); =20 -out_unlock: - mutex_unlock(&smmu_domain->init_mutex); return ret; } =20 @@ -2718,6 +2726,8 @@ static void arm_smmu_release_device(struct device *de= v) arm_smmu_detach_dev(master); arm_smmu_disable_pasid(master); arm_smmu_remove_master(master); + if (master->cd_table.cdtab) + arm_smmu_free_cd_tables(master); kfree(master); } =20 diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.h index 00f8e6388848e..2f4b832e0deb4 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -695,6 +695,8 @@ struct arm_smmu_master { struct arm_smmu_domain *domain; struct list_head domain_head; struct arm_smmu_stream *streams; + /* Locked by the iommu core using the group mutex */ + struct arm_smmu_ctx_desc_cfg cd_table; unsigned int num_streams; bool ats_enabled; bool stall_enabled; @@ -721,11 +723,8 @@ struct arm_smmu_domain { =20 enum arm_smmu_domain_stage stage; union { - struct { struct arm_smmu_ctx_desc cd; - struct arm_smmu_ctx_desc_cfg cd_table; - }; - struct arm_smmu_s2_cfg s2_cfg; + struct arm_smmu_s2_cfg s2_cfg; }; =20 struct iommu_domain domain; --=20 2.42.0.283.g2d96d420d3-goog From nobody Fri Dec 19 03:42:41 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87848C83F37 for ; Thu, 31 Aug 2023 17:46:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346972AbjHaRqy (ORCPT ); Thu, 31 Aug 2023 13:46:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346970AbjHaRqt (ORCPT ); Thu, 31 Aug 2023 13:46:49 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6709E6E for ; Thu, 31 Aug 2023 10:46:18 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-58e4d2b7d16so14055127b3.0 for ; Thu, 31 Aug 2023 10:46:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1693503978; x=1694108778; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=HUyVKDl0lhQ7W0ufBBYFd9SmCuZO/76W4U+SUNg412A=; b=2pC6UwRq3dLfYZLDtVd+m9INKixPp5qGsfYqrbyt3oIF57NuiRySvo3DcXVskB10U9 p3Jjxqfjj2Ktxu+m0V0/hliCaAhF36oR4wK6Pr/VLcKyLr9tPuoY28jEquopRliByldh zz8jkREvP7q+3SsYRDuEmJnjQ6oNl7XHI41Wtw3h0/Un0dHu0lKUPYnSMcyq0Gsr2nBj 5XGuXydcVdFzbpkLvQ+Ks/o+60bkJRluSNg40VB8zFOmJkBKvyoUMK8oCLKxw3NlVECa 9E7mKEaf2dDEb0JFUbTLRk4CKXCRZqFRxQolGpdKNxNqv8g4R/Ih0ZmhxnTPPlhExOxa 6Ukw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693503978; x=1694108778; 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=HUyVKDl0lhQ7W0ufBBYFd9SmCuZO/76W4U+SUNg412A=; b=kiOuQ23QHMeuYQ/jztfrWV/7HvsqvfjhMy9iA2SCh4rl+sbCjKIb7ZHqd3WaXmg7r6 W7JYoFy0upqO2NJPxSXgNNC0WynfP6tEB4r6pGoQ07KaI3ZNF39x+y6OqmAPv+hADegD r7nhSt3zm39lGS8irH5YbnOYgaCz41nXaY1HA3/Y8Vyke1wrMVf8ZNu5JDj2lawl45fX xnc6C6LHi1lCqPLV8O5ebVoWOWvWid/BaEFAmKc/zLfaa4zIiBn8Ctk3BpE2IfLhRBu8 /UkAGug+XsMzY14t8V5ySY9ds3Pc32p+R++yjNIK+98h7iQO8VrLLkBQo2v4omqEx3+7 lRyQ== X-Gm-Message-State: AOJu0YyA4bmMynOcmrM0Fsrsh79RIJe6EJKpMOgUCDKI9CDSmECTAoLJ E7+yCYa8e1URZ01gvNqtqHn9LOCdAzDO X-Google-Smtp-Source: AGHT+IEMJF3dc+25Kv4DjBVppSk/8Bx2EoVHGZaHW80P0+xgsookLYMJvqJ8CPuNFyU7AvC8AVo2BLS8XijP X-Received: from mshavit.ntc.corp.google.com ([2401:fa00:95:20c:1a0a:7338:4a5a:5f83]) (user=mshavit job=sendgmr) by 2002:a81:ae1f:0:b0:592:7a39:e4b4 with SMTP id m31-20020a81ae1f000000b005927a39e4b4mr3028ywh.6.1693503977969; Thu, 31 Aug 2023 10:46:17 -0700 (PDT) Date: Fri, 1 Sep 2023 01:44:36 +0800 In-Reply-To: <20230831174536.103472-1-mshavit@google.com> Mime-Version: 1.0 References: <20230831174536.103472-1-mshavit@google.com> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog Message-ID: <20230901014413.v7.7.Iff18df41564b9df82bf40b3ec7af26b87f08ef6e@changeid> Subject: [PATCH v7 7/9] iommu/arm-smmu-v3: Cleanup arm_smmu_domain_finalise From: Michael Shavit To: iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: will@kernel.org, robin.murphy@arm.com, jean-philippe@linaro.org, jgg@nvidia.com, nicolinc@nvidia.com, Michael Shavit , Jason Gunthorpe , Joerg Roedel , Kevin Tian , "Kirill A. Shutemov" , Lu Baolu , Mark Brown , Yicong Yang Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove unused master parameter now that the CD table is allocated elsewhere. Reviewed-by: Nicolin Chen Reviewed-by: Jason Gunthorpe Signed-off-by: Michael Shavit Tested-by: Nicolin Chen --- (no changes since v5) Changes in v5: - New commit drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.c index bcc94a67640d6..8d177ed550054 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2090,7 +2090,6 @@ static void arm_smmu_domain_free(struct iommu_domain = *domain) } =20 static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain, - struct arm_smmu_master *master, struct io_pgtable_cfg *pgtbl_cfg) { int ret; @@ -2128,7 +2127,6 @@ static int arm_smmu_domain_finalise_s1(struct arm_smm= u_domain *smmu_domain, } =20 static int arm_smmu_domain_finalise_s2(struct arm_smmu_domain *smmu_domain, - struct arm_smmu_master *master, struct io_pgtable_cfg *pgtbl_cfg) { int vmid; @@ -2153,8 +2151,7 @@ static int arm_smmu_domain_finalise_s2(struct arm_smm= u_domain *smmu_domain, return 0; } =20 -static int arm_smmu_domain_finalise(struct iommu_domain *domain, - struct arm_smmu_master *master) +static int arm_smmu_domain_finalise(struct iommu_domain *domain) { int ret; unsigned long ias, oas; @@ -2162,7 +2159,6 @@ static int arm_smmu_domain_finalise(struct iommu_doma= in *domain, struct io_pgtable_cfg pgtbl_cfg; struct io_pgtable_ops *pgtbl_ops; int (*finalise_stage_fn)(struct arm_smmu_domain *, - struct arm_smmu_master *, struct io_pgtable_cfg *); struct arm_smmu_domain *smmu_domain =3D to_smmu_domain(domain); struct arm_smmu_device *smmu =3D smmu_domain->smmu; @@ -2214,7 +2210,7 @@ static int arm_smmu_domain_finalise(struct iommu_doma= in *domain, domain->geometry.aperture_end =3D (1UL << pgtbl_cfg.ias) - 1; domain->geometry.force_aperture =3D true; =20 - ret =3D finalise_stage_fn(smmu_domain, master, &pgtbl_cfg); + ret =3D finalise_stage_fn(smmu_domain, &pgtbl_cfg); if (ret < 0) { free_io_pgtable_ops(pgtbl_ops); return ret; @@ -2424,7 +2420,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *d= omain, struct device *dev) =20 if (!smmu_domain->smmu) { smmu_domain->smmu =3D smmu; - ret =3D arm_smmu_domain_finalise(domain, master); + ret =3D arm_smmu_domain_finalise(domain); if (ret) smmu_domain->smmu =3D NULL; } else if (smmu_domain->smmu !=3D smmu) --=20 2.42.0.283.g2d96d420d3-goog From nobody Fri Dec 19 03:42:41 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E31BBC83F37 for ; Thu, 31 Aug 2023 17:47:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238608AbjHaRrG (ORCPT ); Thu, 31 Aug 2023 13:47:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346967AbjHaRrE (ORCPT ); Thu, 31 Aug 2023 13:47:04 -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 32DB710F0 for ; Thu, 31 Aug 2023 10:46:34 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-58fb8933e18so14092417b3.3 for ; Thu, 31 Aug 2023 10:46:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1693503982; x=1694108782; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=97NbLwOzwX2yfBkjP3g3hHfcNULS8xoy6ngi79VwyiQ=; b=AE+smRv5i96FT04jYkeVnOVvzd5x5oaGXCtO66a8tPSS2t6vTo4ZNk0Ti75M8Hbfxn ECroSLtD1dlR++iM622BfTjCErm+7Gc68pVR7j5pL2PkYtwzwgvVM4utrv3PPDntGAlj v1+yzx8EQMD5Z/0TGZ2btpRORPQSCJMkGXdGs/s70I+MLVxm+bPvbyCfoH0t/Ghb45dK p94MAb/6zYjr/qOmWkJ+zXQb2eCke62bQWqQI/OogNNsUIeuRjBZ+uckmUSmk0FFXO0z +OfZET1fKWI5ERrUiqo6Nu0OUAv9ojv/zuQ5DgLVAM0hy4SzIVJsfHqPNoJUvRUXI6a8 OcmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693503982; x=1694108782; 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=97NbLwOzwX2yfBkjP3g3hHfcNULS8xoy6ngi79VwyiQ=; b=gRfytKi9D/a8+71DxrmsAqLEEhyZ7Vezfbp/6+O2quMfuUL+Sbf7J1N4ALV4UnAmGH 2KxbY/cNFo1rsoA4+vGk8uZPNeCV0LBOl2X+jTbqsOjHde6Z8f3zcTkPMiP6dO5UywXX pF+iQLfjSXtNrZ/Yi6wNsT46hQoGqML+tRBnIrFVYUKpbVdIVsgyKEYFwp2FBUdxOgG/ I66vzeujCRuIshRby0WdbL1fUuN0UjwNYQVzM8rgN6l9/jvGCPpawiDRi8qGmOpdgP37 TOvYRogj5MmDkeomKjjJCkhvfwvwgPD/2qmqdYX5007DyS6+2q2EPLSbflYB4a0DuJBB N0cA== X-Gm-Message-State: AOJu0Yx/VEgDFIqwrDeZ385acnxWBa9tEoH+CeOb7d5Az8zMecZzgXvU LJTbEpeNzRhKE44JBqOZuzKw+GjvXWHQ X-Google-Smtp-Source: AGHT+IFnAn3Jgebhh43eiBoBmSBDyph6RaR6op6wjUZNKsymtjXCclD9kKZcfRwzPgCeOQNDjo1qmsyY58LY X-Received: from mshavit.ntc.corp.google.com ([2401:fa00:95:20c:1a0a:7338:4a5a:5f83]) (user=mshavit job=sendgmr) by 2002:a81:e40b:0:b0:592:8069:540a with SMTP id r11-20020a81e40b000000b005928069540amr2213ywl.8.1693503982384; Thu, 31 Aug 2023 10:46:22 -0700 (PDT) Date: Fri, 1 Sep 2023 01:44:37 +0800 In-Reply-To: <20230831174536.103472-1-mshavit@google.com> Mime-Version: 1.0 References: <20230831174536.103472-1-mshavit@google.com> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog Message-ID: <20230901014413.v7.8.I7a8beb615e2520ad395d96df94b9ab9708ee0d9c@changeid> Subject: [PATCH v7 8/9] iommu/arm-smmu-v3: Update comment about STE liveness From: Michael Shavit To: iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: will@kernel.org, robin.murphy@arm.com, jean-philippe@linaro.org, jgg@nvidia.com, nicolinc@nvidia.com, Michael Shavit , Jason Gunthorpe , Joerg Roedel , Kevin Tian , "Kirill A. Shutemov" , Lu Baolu , Mark Brown , Yicong Yang Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Update the comment to reflect the fact that the STE is not always installed. arm_smmu_domain_finalise_s1 intentionnaly calls arm_smmu_write_ctx_desc while the STE is not installed. Reviewed-by: Nicolin Chen Reviewed-by: Jason Gunthorpe Signed-off-by: Michael Shavit Tested-by: Nicolin Chen --- (no changes since v6) Changes in v6: - New commit drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.c index 8d177ed550054..adede66621163 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1091,7 +1091,7 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_master *m= aster, int ssid, cdptr[3] =3D cpu_to_le64(cd->mair); =20 /* - * STE is live, and the SMMU might read dwords of this CD in any + * STE may be live, and the SMMU might read dwords of this CD in any * order. Ensure that it observes valid values before reading * V=3D1. */ --=20 2.42.0.283.g2d96d420d3-goog From nobody Fri Dec 19 03:42:41 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 864ABC83F35 for ; Thu, 31 Aug 2023 17:47:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346967AbjHaRrV (ORCPT ); Thu, 31 Aug 2023 13:47:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242635AbjHaRrU (ORCPT ); Thu, 31 Aug 2023 13:47:20 -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 D9B81E6B for ; Thu, 31 Aug 2023 10:46:48 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d7bb58517b8so893167276.0 for ; Thu, 31 Aug 2023 10:46:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1693503987; x=1694108787; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=BVGe3ocDlSgxiMEa8lcY/QWlgjj80MFNgCzLX2p0tDY=; b=0Fx8dl1aqF23kEmufwHH2miiRB2Ilt7OX5dD4rNWFh/RKDyEopoSlIsV82tCZyjX/a gABl5SXgL2lsyGYh/yyboL4D28yrQqdAmSkRHFcFU11siVRHM0++fuPiPsl5umdkOz0b TAlNkVwhJpdwwUu6hknNJjKjNsyv+znUGU6F0qlcMwzZl739tQhzVXNUCY7k8iSrk7wE S9Fm3QYLoI63auC5GBg9nGlTAa3X1xBDe6LG9lBsx9+DC/e6zsxJ/FC6QPexZ0uXagBY 5NFJjwJI7CccJjVHUwZf76OlMxIfc71o1v78mDw1bsodzqexeNRSp3J5xObZTcbjIcxY HULA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693503987; x=1694108787; 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=BVGe3ocDlSgxiMEa8lcY/QWlgjj80MFNgCzLX2p0tDY=; b=Ov7xzfVCK5Vr/pB6GZieC/6xMBxgU5TIl5avxwYYWcfIxuPekTRmVup6FikSJ9I4r0 tV9dKqaQbDUTnQSjPPxGF5wOpNinCsJG+6FtOxQEOdBji+w6Fcb9+GXeXqE2igaGWAbt iy3Z995Nag3Rpk/hGCDXq0IFUChCV8AQFgui1sSk1xkZypXyX0XWFgVvi33GfVf+QBxF gn5ItFNOG42/nnTq0G2gdwJ07tLnuaxAXy9VIXNMO/Br+y7K63fCGRAXRvwToW2xwG17 QjTkcCJ3sQbJkEiLcSHzmBEevV1mqOSvoMbqCrhGvnlcnfAKvrumUJ2CA8TivTil1hbM 4IYA== X-Gm-Message-State: AOJu0YxCqYRuRARM36kiUhITqTc59/L0SxG+qRx9rDWrfF13jMHoQ42P oq0BMAAGzSSltIcvXkdQB/bXTls/bjn4 X-Google-Smtp-Source: AGHT+IFaSB6HBgvhLtm2ZCYKoljlP2y2v5i6TCK+iey0s2bWUEUuQTMR+PajRcXkL3yK+J7lDuMudjIUVdFR X-Received: from mshavit.ntc.corp.google.com ([2401:fa00:95:20c:1a0a:7338:4a5a:5f83]) (user=mshavit job=sendgmr) by 2002:a5b:81:0:b0:d77:ab03:790c with SMTP id b1-20020a5b0081000000b00d77ab03790cmr12667ybp.0.1693503987381; Thu, 31 Aug 2023 10:46:27 -0700 (PDT) Date: Fri, 1 Sep 2023 01:44:38 +0800 In-Reply-To: <20230831174536.103472-1-mshavit@google.com> Mime-Version: 1.0 References: <20230831174536.103472-1-mshavit@google.com> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog Message-ID: <20230901014413.v7.9.I5ee79793b444ddb933e8bc1eb7b77e728d7f8350@changeid> Subject: [PATCH v7 9/9] iommu/arm-smmu-v3: Rename cdcfg to cd_table From: Michael Shavit To: iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: will@kernel.org, robin.murphy@arm.com, jean-philippe@linaro.org, jgg@nvidia.com, nicolinc@nvidia.com, Michael Shavit , Jason Gunthorpe , Joerg Roedel , Kevin Tian , "Kirill A. Shutemov" , Lu Baolu , Mark Brown , Yicong Yang Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" cdcfg is a confusing name, especially given other variables with the cfg suffix in this driver. cd_table more clearly describes what is being operated on. Tested-by: Nicolin Chen Reviewed-by: Jason Gunthorpe Reviewed-by: Nicolin Chen Signed-off-by: Michael Shavit --- (no changes since v3) Changes in v3: - Commit message update Changes in v2: - New commit drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 70 ++++++++++----------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.c index adede66621163..0a9b832f8bd81 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1025,18 +1025,18 @@ static __le64 *arm_smmu_get_cd_ptr(struct arm_smmu_= master *master, u32 ssid) unsigned int idx; struct arm_smmu_l1_ctx_desc *l1_desc; struct arm_smmu_device *smmu =3D master->smmu; - struct arm_smmu_ctx_desc_cfg *cdcfg =3D &master->cd_table; + struct arm_smmu_ctx_desc_cfg *cd_table =3D &master->cd_table; =20 - if (cdcfg->s1fmt =3D=3D STRTAB_STE_0_S1FMT_LINEAR) - return cdcfg->cdtab + ssid * CTXDESC_CD_DWORDS; + if (cd_table->s1fmt =3D=3D STRTAB_STE_0_S1FMT_LINEAR) + return cd_table->cdtab + ssid * CTXDESC_CD_DWORDS; =20 idx =3D ssid >> CTXDESC_SPLIT; - l1_desc =3D &cdcfg->l1_desc[idx]; + l1_desc =3D &cd_table->l1_desc[idx]; if (!l1_desc->l2ptr) { if (arm_smmu_alloc_cd_leaf_table(smmu, l1_desc)) return NULL; =20 - l1ptr =3D cdcfg->cdtab + idx * CTXDESC_L1_DESC_DWORDS; + l1ptr =3D cd_table->cdtab + idx * CTXDESC_L1_DESC_DWORDS; arm_smmu_write_cd_l1_desc(l1ptr, l1_desc); /* An invalid L1CD can be cached */ arm_smmu_sync_cd(master, ssid, false); @@ -1131,35 +1131,35 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu= _master *master) size_t l1size; size_t max_contexts; struct arm_smmu_device *smmu =3D master->smmu; - struct arm_smmu_ctx_desc_cfg *cdcfg =3D &master->cd_table; + struct arm_smmu_ctx_desc_cfg *cd_table =3D &master->cd_table; =20 - cdcfg->stall_enabled =3D master->stall_enabled; - cdcfg->s1cdmax =3D master->ssid_bits; - max_contexts =3D 1 << cdcfg->s1cdmax; + cd_table->stall_enabled =3D master->stall_enabled; + cd_table->s1cdmax =3D master->ssid_bits; + max_contexts =3D 1 << cd_table->s1cdmax; =20 if (!(smmu->features & ARM_SMMU_FEAT_2_LVL_CDTAB) || max_contexts <=3D CTXDESC_L2_ENTRIES) { - cdcfg->s1fmt =3D STRTAB_STE_0_S1FMT_LINEAR; - cdcfg->num_l1_ents =3D max_contexts; + cd_table->s1fmt =3D STRTAB_STE_0_S1FMT_LINEAR; + cd_table->num_l1_ents =3D max_contexts; =20 l1size =3D max_contexts * (CTXDESC_CD_DWORDS << 3); } else { - cdcfg->s1fmt =3D STRTAB_STE_0_S1FMT_64K_L2; - cdcfg->num_l1_ents =3D DIV_ROUND_UP(max_contexts, + cd_table->s1fmt =3D STRTAB_STE_0_S1FMT_64K_L2; + cd_table->num_l1_ents =3D DIV_ROUND_UP(max_contexts, CTXDESC_L2_ENTRIES); =20 - cdcfg->l1_desc =3D devm_kcalloc(smmu->dev, cdcfg->num_l1_ents, - sizeof(*cdcfg->l1_desc), + cd_table->l1_desc =3D devm_kcalloc(smmu->dev, cd_table->num_l1_ents, + sizeof(*cd_table->l1_desc), GFP_KERNEL); - if (!cdcfg->l1_desc) + if (!cd_table->l1_desc) return -ENOMEM; =20 - l1size =3D cdcfg->num_l1_ents * (CTXDESC_L1_DESC_DWORDS << 3); + l1size =3D cd_table->num_l1_ents * (CTXDESC_L1_DESC_DWORDS << 3); } =20 - cdcfg->cdtab =3D dmam_alloc_coherent(smmu->dev, l1size, &cdcfg->cdtab_dma, + cd_table->cdtab =3D dmam_alloc_coherent(smmu->dev, l1size, &cd_table->cdt= ab_dma, GFP_KERNEL); - if (!cdcfg->cdtab) { + if (!cd_table->cdtab) { dev_warn(smmu->dev, "failed to allocate context descriptor\n"); ret =3D -ENOMEM; goto err_free_l1; @@ -1168,9 +1168,9 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_m= aster *master) return 0; =20 err_free_l1: - if (cdcfg->l1_desc) { - devm_kfree(smmu->dev, cdcfg->l1_desc); - cdcfg->l1_desc =3D NULL; + if (cd_table->l1_desc) { + devm_kfree(smmu->dev, cd_table->l1_desc); + cd_table->l1_desc =3D NULL; } return ret; } @@ -1180,30 +1180,30 @@ static void arm_smmu_free_cd_tables(struct arm_smmu= _master *master) int i; size_t size, l1size; struct arm_smmu_device *smmu =3D master->smmu; - struct arm_smmu_ctx_desc_cfg *cdcfg =3D &master->cd_table; + struct arm_smmu_ctx_desc_cfg *cd_table =3D &master->cd_table; =20 - if (cdcfg->l1_desc) { + if (cd_table->l1_desc) { size =3D CTXDESC_L2_ENTRIES * (CTXDESC_CD_DWORDS << 3); =20 - for (i =3D 0; i < cdcfg->num_l1_ents; i++) { - if (!cdcfg->l1_desc[i].l2ptr) + for (i =3D 0; i < cd_table->num_l1_ents; i++) { + if (!cd_table->l1_desc[i].l2ptr) continue; =20 dmam_free_coherent(smmu->dev, size, - cdcfg->l1_desc[i].l2ptr, - cdcfg->l1_desc[i].l2ptr_dma); + cd_table->l1_desc[i].l2ptr, + cd_table->l1_desc[i].l2ptr_dma); } - devm_kfree(smmu->dev, cdcfg->l1_desc); - cdcfg->l1_desc =3D NULL; + devm_kfree(smmu->dev, cd_table->l1_desc); + cd_table->l1_desc =3D NULL; =20 - l1size =3D cdcfg->num_l1_ents * (CTXDESC_L1_DESC_DWORDS << 3); + l1size =3D cd_table->num_l1_ents * (CTXDESC_L1_DESC_DWORDS << 3); } else { - l1size =3D cdcfg->num_l1_ents * (CTXDESC_CD_DWORDS << 3); + l1size =3D cd_table->num_l1_ents * (CTXDESC_CD_DWORDS << 3); } =20 - dmam_free_coherent(smmu->dev, l1size, cdcfg->cdtab, cdcfg->cdtab_dma); - cdcfg->cdtab_dma =3D 0; - cdcfg->cdtab =3D NULL; + dmam_free_coherent(smmu->dev, l1size, cd_table->cdtab, cd_table->cdtab_dm= a); + cd_table->cdtab_dma =3D 0; + cd_table->cdtab =3D NULL; } =20 bool arm_smmu_free_asid(struct arm_smmu_ctx_desc *cd) --=20 2.42.0.283.g2d96d420d3-goog