From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1977EC47DDF for ; Thu, 1 Feb 2024 12:18:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=aH/jOXtB9IDKuZcnTagC2XGhsOO1wpUiOADILSszHWA=; b=VuoX0b62cKS1EF t30J6soEc841oNrafRuEzr2JzJiDQNhdmUuQgX01tKAigwoiienJwgsJtjpGVfVLq23dPp8WGQ/cg 4E0YBvV6cx3xoMdChhOybatVfPm5U/RLUxv0i5sr+BCaB688oy+kKcKd4vAv3bbV4TEPDiLIjJQJw pjN0kMyHRkZnfWjwt6LBUgcgnd9xL7A7usjGvJqSEhliCGdHxq6QXmBhEgr6Zus7DkFpBZGj87lrs YbCDOAZyLbpKLBkcHEGQQ7apJ6r9h18ztkEEwJk+IxhloCeu35W9Hgz7DrWtC5MA+YXr1Ta1A1We3 7HiRKYIWqcxx8Oc1gUdA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVW1M-00000007j1f-0yXq; Thu, 01 Feb 2024 12:18:20 +0000 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVW1J-00000007izk-2eL8 for linux-arm-kernel@lists.infradead.org; Thu, 01 Feb 2024 12:18:18 +0000 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-40f00adacfeso31975e9.1 for ; Thu, 01 Feb 2024 04:18:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706789895; x=1707394695; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=etlYPvb4uOjdfz/Zs8jzDsz/Zvk0DcrwunGCl+SdTFk=; b=e5Rh9TpMCP46NWyF9mvGdDlvoOM4u5Oee4ksCVo0W52h9jdYQF6DZh95Qhv4yhYJgK 9KfRrzn/ULinNLuZKUGA0XkiGgR8Vz50SctSBDLW7xmDI17Qk+H1jWd1yDgBgKEPVH78 jTB6ZqnYHmufwvZ6NGNAf5pMgecQbG9wjgmn4tjmIdNYV+/F8Z/+fbfVTUdPiXpTrPi2 jdNjK+alaMIrQyei8kVnqRq05235H7M3rRpAdP0IZof6vQn2bJd6XO0PXs60Dy6+1ksU AW+MGe3C1C0eYCmJKLFkIH6Ogf8i7h0qkDgZ8bdx0jmTYDSlOsURnrqwYOOaTKZz13Kx lgfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706789895; x=1707394695; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=etlYPvb4uOjdfz/Zs8jzDsz/Zvk0DcrwunGCl+SdTFk=; b=UjUurxKkCvr9yg2lo44wJ3tMMX1t5x5JxSdB3h93BNP0JAexZQaifP0DRMlObD7pkt fsc/vBExYnXRocy/ka+hXPekGplr+ehXzK2x3aYoXlpuMdjVoekaSxoD4B/j9cR9O4kx /VONEzFGzmO3CQos33e2f3mDyJ+s9w+seokd93WOHDW5nAasSYMF157hqRU6XFNI0G/B SqoBpdf6nAwtXe26JgBAnyS7z6EXSDBY/hi1e94Pv+FkfW9fgoa1oBNtHSba2XtCy/5m Mm4Qc6SgSBRt1EyX1jXFa0uOfc3XmyPSwX3WlrFcCxyzEKo2M9xEpunkJBBvNEt3Fkkq FWYQ== X-Gm-Message-State: AOJu0YzkKyfBvK0U8hzvBddWIvj3f87o2ETlZLX0dAv0rVStUHKvJc7U JKbd9+9pt9c2IbYriWgz6kC5NWUBqVE4LMxDv9rDKl2Zo6+ehqMtPgydaEliCA== X-Google-Smtp-Source: AGHT+IH4n+wXp33JvUNh1CjnR39qfCbYHdkrCfVHZ8bVkGTaBcNE54nTX17nUCCe5TU5kIZolzN4rQ== X-Received: by 2002:a05:600c:b8b:b0:40e:f8fa:1dd2 with SMTP id fl11-20020a05600c0b8b00b0040ef8fa1dd2mr145491wmb.6.1706789894956; Thu, 01 Feb 2024 04:18:14 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXCDCsNICh+ywfn69HqrWUJdmj4HMdNklHHAWPDNYP7USkFX8lsXUaUIvDbBXiEFd51hNBw7T5kjZBdk7NTrYxdmmPSqNkfcx90gFyzFXbdIs3OuNX1K7V9BpXjqgBduN80JMInZajcXSwqAY5y0HWvEH+8NHLXSOnISZxDhyE6Rhw/zqJh2gi1gV8Yqd2I4UDUGlsKTFvKGn+o5VC7AKuhhCjjZJHNyUeZlE9gBi8KhN/ZEBsWQucJaJGuVyMnmlRA20kt29u+CjRhnuSTEP3xiUSpEFG4jGcSVCTWb4uYtkMswEubsRIt2RnTFEmr1j1AVZwVC8sdC6O8syr5+BkLW48Y2ixv0GmS/7TsmbzFd4iK06+rOJym Received: from google.com (185.83.140.34.bc.googleusercontent.com. [34.140.83.185]) by smtp.gmail.com with ESMTPSA id c17-20020a5d5291000000b00337d980a68asm13613302wrv.106.2024.02.01.04.18.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 04:18:14 -0800 (PST) Date: Thu, 1 Feb 2024 12:18:10 +0000 From: Mostafa Saleh To: Jason Gunthorpe Cc: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon , Moritz Fischer , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameer Kolothum Subject: Re: [PATCH v4 07/16] iommu/arm-smmu-v3: Compute the STE only once for each master Message-ID: References: <0-v4-c93b774edcc4+42d2b-smmuv3_newapi_p1_jgg@nvidia.com> <7-v4-c93b774edcc4+42d2b-smmuv3_newapi_p1_jgg@nvidia.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <7-v4-c93b774edcc4+42d2b-smmuv3_newapi_p1_jgg@nvidia.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240201_041817_696577_CD51A991 X-CRM114-Status: GOOD ( 26.99 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Jason, On Thu, Jan 25, 2024 at 07:57:17PM -0400, Jason Gunthorpe wrote: > Currently arm_smmu_install_ste_for_dev() iterates over every SID and > computes from scratch an identical STE. Every SID should have the same STE > contents. Turn this inside out so that the STE is supplied by the caller > and arm_smmu_install_ste_for_dev() simply installs it to every SID. > > This is possible now that the STE generation does not inform what sequence > should be used to program it. > > This allows splitting the STE calculation up according to the call site, > which following patches will make use of, and removes the confusing NULL > domain special case that only supported arm_smmu_detach_dev(). > > Reviewed-by: Michael Shavit > Reviewed-by: Nicolin Chen > Tested-by: Shameer Kolothum > Tested-by: Nicolin Chen > Tested-by: Moritz Fischer > Signed-off-by: Jason Gunthorpe > --- > drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 57 ++++++++------------- > 1 file changed, 22 insertions(+), 35 deletions(-) > > diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > index 539ef380f457fa..cf3e348cb9abe1 100644 > --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > @@ -1588,35 +1588,6 @@ static void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, > STRTAB_STE_3_S2TTB_MASK); > } > > -static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, > - struct arm_smmu_ste *dst) > -{ > - struct arm_smmu_domain *smmu_domain = master->domain; > - struct arm_smmu_ste target = {}; > - > - if (!smmu_domain) { > - if (disable_bypass) > - arm_smmu_make_abort_ste(&target); > - else > - arm_smmu_make_bypass_ste(&target); > - arm_smmu_write_ste(master, sid, dst, &target); > - return; > - } > - > - switch (smmu_domain->stage) { > - case ARM_SMMU_DOMAIN_S1: > - arm_smmu_make_cdtable_ste(&target, master, &master->cd_table); > - break; > - case ARM_SMMU_DOMAIN_S2: > - arm_smmu_make_s2_domain_ste(&target, master, smmu_domain); > - break; > - case ARM_SMMU_DOMAIN_BYPASS: > - arm_smmu_make_bypass_ste(&target); > - break; > - } > - arm_smmu_write_ste(master, sid, dst, &target); > -} > - > static void arm_smmu_init_bypass_stes(struct arm_smmu_ste *strtab, > unsigned int nent) > { > @@ -2439,7 +2410,8 @@ arm_smmu_get_step_for_sid(struct arm_smmu_device *smmu, u32 sid) > } > } > > -static void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master) > +static void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master, > + const struct arm_smmu_ste *target) > { > int i, j; > struct arm_smmu_device *smmu = master->smmu; > @@ -2456,7 +2428,7 @@ static void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master) > if (j < i) > continue; > > - arm_smmu_write_strtab_ent(master, sid, step); > + arm_smmu_write_ste(master, sid, step, target); > } > } > > @@ -2563,6 +2535,7 @@ static void arm_smmu_disable_pasid(struct arm_smmu_master *master) > static void arm_smmu_detach_dev(struct arm_smmu_master *master) > { > unsigned long flags; > + struct arm_smmu_ste target; > struct arm_smmu_domain *smmu_domain = master->domain; > > if (!smmu_domain) > @@ -2576,7 +2549,11 @@ static void arm_smmu_detach_dev(struct arm_smmu_master *master) > > master->domain = NULL; > master->ats_enabled = false; > - arm_smmu_install_ste_for_dev(master); > + if (disable_bypass) > + arm_smmu_make_abort_ste(&target); > + else > + arm_smmu_make_bypass_ste(&target); > + arm_smmu_install_ste_for_dev(master, &target); > /* > * Clearing the CD entry isn't strictly required to detach the domain > * since the table is uninstalled anyway, but it helps avoid confusion > @@ -2591,6 +2568,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) > { > int ret = 0; > unsigned long flags; > + struct arm_smmu_ste target; > struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); > struct arm_smmu_device *smmu; > struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); > @@ -2652,7 +2630,8 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) > list_add(&master->domain_head, &smmu_domain->devices); > spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); > > - if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) { > + switch (smmu_domain->stage) { > + case ARM_SMMU_DOMAIN_S1: > if (!master->cd_table.cdtab) { > ret = arm_smmu_alloc_cd_tables(master); > if (ret) { > @@ -2666,9 +2645,17 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) > master->domain = NULL; > goto out_list_del; > } > - } > > - arm_smmu_install_ste_for_dev(master); > + arm_smmu_make_cdtable_ste(&target, master, &master->cd_table); > + break; > + case ARM_SMMU_DOMAIN_S2: > + arm_smmu_make_s2_domain_ste(&target, master, smmu_domain); > + break; > + case ARM_SMMU_DOMAIN_BYPASS: > + arm_smmu_make_bypass_ste(&target); > + break; > + } > + arm_smmu_install_ste_for_dev(master, &target); > > arm_smmu_enable_ats(master); > goto out_unlock; > -- > 2.43.0 > Reviewed-by: Mostafa Saleh Thanks, Mostafa _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel