From nobody Tue Dec 16 23:40:37 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 F0C54C3DA6F for ; Fri, 25 Aug 2023 10:32:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243158AbjHYKcW (ORCPT ); Fri, 25 Aug 2023 06:32:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234077AbjHYKcB (ORCPT ); Fri, 25 Aug 2023 06:32:01 -0400 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on20603.outbound.protection.outlook.com [IPv6:2a01:111:f400:7ea9::603]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A084133 for ; Fri, 25 Aug 2023 03:31:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ng3M8ntryBW5g/HfW0IiXDDS979wtUPJFxCA87RMGmxn0SDM3fosOHkvp7wzvlXT1ItrWzbQuE3GFInRCU5yf0rK+mqCdFh2U8OvZIdEZWK65u8KM+/xYiHestK0fmpmeIIiOjKnJ6kS9jAKCnZ2bpWQWLME57ncuhNgPTgBiLY4DbQ5utBlRu5dhmXEOFaOecGvyZTys9zmzhEEFgISKTHpDvwDiI7Ah0o9aH7K9RNKACs2uTr01hu9fdWTIr2ZyGxCqjUaOUShdGr1xb3JPBXDwoaZVrcB2YXpGScXTIzZYzTI14ikThreGdjGOux0xPfs7DIayUqESDM/5rFIBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=AbCaYsxCTvP6rgJooO2hh9lUv7cAU8Qf2+1cQBH1qHY=; b=DxfBQm4HfigPUa7P0W8nOt6gGxRoForYTgzfdMuMUGOEWmKIRPRrg/qCrHwL5obVRsWjfDkKvW1T7Touo/GEnS3Xlcuj+ZRKA/Q5zo7mrSlz8t1NNE0FlB5j1KGgSJ47O4kPlVKQ97IO0hhRSVrIoO4n9vpUs8sB0RK1HU9XVLXHWJ5zb3v39js9aF4UeZatJtNgeu+JVD0jXG77rrjx71SPjv08S+H1NN/grn6FnPnblz+UpnG3rXzOUReu7e1rFOTUvfhbRf7eHEGDUwJlWczQGyl5Qk8EbgECVSD2jFMYEwUsbEzbhMGTLiY3pdxws+VFXBmD5XDV+4WyHg9Gzw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AbCaYsxCTvP6rgJooO2hh9lUv7cAU8Qf2+1cQBH1qHY=; b=O/emNH1br/axSPmCW0wyKyPvK44/h0tC6n6ajzmbELatcqsSXvlyEKGA2n+IyBuMCrvdUMUSEJ9iCkWn4GrXP7G7B1uHB5LJkrSryf3g5grBBTJJYOO6ClgGXbOCiYQWvMDzZO3Ip2JU3Hq6DWH1GWxXtCM+ChG2KN9tfpXeh4zyC9tLqAqF7blh08aWa1phtoiOh6aMmU/nYU7oFxpamB1TwZMbW753PmAQn096O+/dzCm3CSUyh5fFtfLYMCmlCbsx87nRnnmyn7JUxdlwe+ArlVnTVI9G4Hic2TzB0OHB9SRhySJFQXBRuCI2fPTvCx7er/uZoRhXNroUNWBdLw== Received: from MW2PR16CA0035.namprd16.prod.outlook.com (2603:10b6:907::48) by SJ0PR12MB6927.namprd12.prod.outlook.com (2603:10b6:a03:483::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.27; Fri, 25 Aug 2023 10:31:50 +0000 Received: from CO1PEPF000044F8.namprd21.prod.outlook.com (2603:10b6:907:0:cafe::5c) by MW2PR16CA0035.outlook.office365.com (2603:10b6:907::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.30 via Frontend Transport; Fri, 25 Aug 2023 10:31:50 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by CO1PEPF000044F8.mail.protection.outlook.com (10.167.241.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.2 via Frontend Transport; Fri, 25 Aug 2023 10:31:50 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Fri, 25 Aug 2023 03:31:41 -0700 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Fri, 25 Aug 2023 03:31:41 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.13) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Fri, 25 Aug 2023 03:31:40 -0700 From: Nicolin Chen To: , , CC: , , , , Subject: [PATCH v3 1/2] iommu/arm-smmu-v3: Add boolean bypass_ste and skip_cdtab flags Date: Fri, 25 Aug 2023 03:31:23 -0700 Message-ID: X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044F8:EE_|SJ0PR12MB6927:EE_ X-MS-Office365-Filtering-Correlation-Id: 5ee07a61-e34b-4eb6-829b-08dba5567df1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HUsN8vvYi7CESkLJg4UDSVp4O0NPKhtfpHFn/hJpipnSAveURPrbrAgUANlAmZFWE/mh0ynn+kmeQ/R514j2cTTpNrxcIkGWMN8gkQZJ3/GCl9Fp6lPK7VKabMK8p29f57zixmcIvsa9JqxXKKdFt2glp3yA061cxM6FgnbFNLe9bz+jXdAnZUwcWVSvzwIHCTnSCilC7RieWGTFBpqPHuN6KjWa0PePrXXN80LLvBRzKGaO2/GP8mSEZpLmLYLYzk0Chl3sHSz04MvcWEv4VAVtxMcy6z4e6CsZMs2mbmus5zBvur7eTJuKCk0ZWWOqhNVXqilZKbV3zIutc2qD5OFCdyzEvUs8NTtOZztE9ceYURzg1zlAXbXdFvbJZx2q7wZI6td0tQM4g9fR3YI5Am6W6gvGa+b62RemciFtqRtyabZhNO21PTK335dXEfSgfR+7McZ2i2IEmSvbZaGW5o5koGbtcO+k7FQFbVWdmEKqiP/D9/05zWl5//brcw+Vuehpf8CAWeF0aEs8EPrDl775G38rX8bSlJfDAtSH8OLpOZUcQ+MsX1t4bZ8SmbaNH7CIUjk8Re6xuWT1afUL2qWwKLtsHscUaaGmpIwncbBuqZHDyIknrzW/PFx8/ZvhsG3EZRI/9X2FCzADk0Yr+7zKtBvZDG9IV3QoxOGMeh+nAFwxx3nfTtSpYzSjpy/NzBPnr2wU3nU9B0DKNmErhAlaY26gfxQuvA612JPthobDkwHI/bzHQCTc0Rh+mUlR X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230031)(4636009)(346002)(396003)(376002)(136003)(39860400002)(82310400011)(1800799009)(451199024)(186009)(36840700001)(46966006)(40470700004)(336012)(36860700001)(83380400001)(26005)(478600001)(47076005)(40480700001)(2616005)(5660300002)(426003)(2906002)(8936002)(4326008)(8676002)(356005)(7636003)(82740400003)(40460700003)(6636002)(110136005)(70206006)(70586007)(86362001)(41300700001)(54906003)(36756003)(7696005)(6666004)(316002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2023 10:31:50.1026 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5ee07a61-e34b-4eb6-829b-08dba5567df1 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000044F8.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6927 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" If a master has only a default substream, it can skip CD/translation table allocations when being attached to an IDENTITY domain, by simply setting STE to the "bypass" mode (STE.Config[2:0] =3D=3D 0b100). If a master has multiple substreams, it will still need a CD table for the non-default substreams when being attached to an IDENTITY domain, in which case the STE.Config is set to the "stage-1 translate" mode while STE.S1DSS field instead is set to the "bypass" mode (STE.S1DSS[1:0] =3D=3D 0b01). If a master is attached to a stage-2 domain, it does not need a CD table, while the STE.Config is set to the "stage-2 translate" mode. Add boolean bypass_ste and skip_cdtab flags in arm_smmu_attach_dev(), to handle clearly the cases above, which also corrects the conditions at the ats_enabled setting and arm_smmu_alloc_cd_tables() callback to cover the second use case. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 35 ++++++++++++++++----- 1 file changed, 27 insertions(+), 8 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 ffd430948e9e..de8bc4c3ad7a 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2406,6 +2406,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *d= omain, struct device *dev) struct arm_smmu_device *smmu; struct arm_smmu_domain *smmu_domain =3D to_smmu_domain(domain); struct arm_smmu_master *master; + bool byapss_ste, skip_cdtab; =20 if (!fwspec) return -ENOENT; @@ -2441,6 +2442,24 @@ static int arm_smmu_attach_dev(struct iommu_domain *= domain, struct device *dev) =20 master->domain =3D smmu_domain; =20 + /* + * When master attaches ARM_SMMU_DOMAIN_BYPASS to its single substream, + * set STE.Config to "bypass" and skip a CD table allocation. Otherwise, + * set STE.Config to "stage-1 translate" and allocate a CD table for its + * multiple stage-1 substream support, unless with a stage-2 domain in + * which case set STE.config to "stage-2 translate" and skip a CD table. + */ + if (smmu_domain->stage =3D=3D ARM_SMMU_DOMAIN_BYPASS && !master->ssid_bit= s) { + byapss_ste =3D true; + skip_cdtab =3D true; + } else { + byapss_ste =3D false; + if (smmu_domain->stage =3D=3D ARM_SMMU_DOMAIN_S2) + skip_cdtab =3D true; + else + skip_cdtab =3D false; + } + /* * The SMMU does not support enabling ATS with bypass. When the STE is * in bypass (STE.Config[2:0] =3D=3D 0b100), ATS Translation Requests and @@ -2448,22 +2467,22 @@ static int arm_smmu_attach_dev(struct iommu_domain = *domain, struct device *dev) * stream (STE.EATS =3D=3D 0b00), causing F_BAD_ATS_TREQ and * F_TRANSL_FORBIDDEN events (IHI0070Ea 5.2 Stream Table Entry). */ - if (smmu_domain->stage !=3D ARM_SMMU_DOMAIN_BYPASS) + if (!byapss_ste) master->ats_enabled =3D arm_smmu_ats_supported(master); =20 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; - } + if (!skip_cdtab && !master->cd_table.cdtab) { + ret =3D arm_smmu_alloc_cd_tables(master); + if (ret) { + master->domain =3D NULL; + goto out_list_del; } + } =20 + if (smmu_domain->stage =3D=3D ARM_SMMU_DOMAIN_S1) { /* * Prevent SVA from concurrently modifying the CD or writing to * the CD entry --=20 2.42.0 From nobody Tue Dec 16 23:40:37 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 D0DC1C7EE2C for ; Fri, 25 Aug 2023 10:32:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242589AbjHYKcV (ORCPT ); Fri, 25 Aug 2023 06:32:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242559AbjHYKb4 (ORCPT ); Fri, 25 Aug 2023 06:31:56 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2040.outbound.protection.outlook.com [40.107.94.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 685ECE7F for ; Fri, 25 Aug 2023 03:31:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aN7eN5eIaN+yQbdaOtfaT9CVaxYlCbKKMhMFRsNr0HEEBb+Jf7MIxVpezS/j0OU7JK81DPCDAQsNXMomGCNBN3FrrUgpUdkZsSxN+dJEoaltcKVErwICXglIyjCG6JoT2k3fqVHuD3sA4aGJGwFx+niO2kzO94nYIsOo2HFWdE51zhcsJbsqkZQlPxttmQcDifvKxpbddjzyDGS+c3banvD1I70Ty/8r4zEMSdKdeno5/BpsxacOWPXemcrx/4ZlBmof45bCJ7KTF5f9uEASkjN9OJ6InLgIiVTaGGnNJ0HKZFQeonSPy14spfxs/kcsa7Q6ENotiX9aEcjhicZxUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wceeVQfcetdakbjQHEAWnZkEkV8Nu2st7X9BJ/4mAbo=; b=oB21ouyMtZzIPHjulNIjm+vXRVYd5/a397zwNLTcxY7THj1IIY/3sG8/QM22gxivUbzPpHfPazEGYbvw3FJA3/L1myaXAr/tSsaJ0Zy/FsewHs9sSFhUfelbmXz+978JL0gQRyrb2l6AFUJVE4iAdFsNRfVvpApzJpxqr6JS+inkt42MqHi9NSwUHP6YRvgkBA5x7kUFEyMPhK9nLoKJMDdGNLu6vovI3etKjLT27G/ljAD/k2sFOj8afvL3mtMgdR2DDaOjMCXWZLb2aVjRmWgrIN7aOcncCal+FMGgX2zipCHWR421nVmcOQw9aItsT4KZob8kGqxBB4ZwLqUSEA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wceeVQfcetdakbjQHEAWnZkEkV8Nu2st7X9BJ/4mAbo=; b=RR3/CzcXKwAiOWbven+t/Ov8mPcT9yAGMK9Cyg4Ju/FUp2+mZSsYwhG1X5zcE5AVj8U//vI7weHxvVaMsQpRPB6qD02kQF7KbGR5xiHsV1pd2u5PJ++Gqzk/zmqKZ1jNCAbKipa8zpFZkaswEnjAS0Rq50IF7ea+nLIn8F40YdrzSFnIjy19KHKt8/plh3i1gWLnzByLRvZ6gsaR1Po8bx5ZmeL3GcnR9Hve898CoApAoifnGnMMi5xFGPYJxBV6S5i5l/VFDvaQGkFzQQAw5QimIXS+tqmEuy/tRVue7dS7cgcHUICOMkq2Bbtwx8V9wbeY1Ujc9WUOwrvRL0jUXA== Received: from CYZPR12CA0017.namprd12.prod.outlook.com (2603:10b6:930:8b::14) by CH3PR12MB8211.namprd12.prod.outlook.com (2603:10b6:610:125::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.29; Fri, 25 Aug 2023 10:31:51 +0000 Received: from CY4PEPF0000E9DB.namprd05.prod.outlook.com (2603:10b6:930:8b:cafe::1f) by CYZPR12CA0017.outlook.office365.com (2603:10b6:930:8b::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.30 via Frontend Transport; Fri, 25 Aug 2023 10:31:51 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by CY4PEPF0000E9DB.mail.protection.outlook.com (10.167.241.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.14 via Frontend Transport; Fri, 25 Aug 2023 10:31:51 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Fri, 25 Aug 2023 03:31:42 -0700 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Fri, 25 Aug 2023 03:31:41 -0700 Received: from Asurada-Nvidia.nvidia.com (10.127.8.13) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Fri, 25 Aug 2023 03:31:41 -0700 From: Nicolin Chen To: , , CC: , , , , Subject: [PATCH v3 2/2] iommu/arm-smmu-v3: Refactor arm_smmu_write_strtab_ent() Date: Fri, 25 Aug 2023 03:31:24 -0700 Message-ID: X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9DB:EE_|CH3PR12MB8211:EE_ X-MS-Office365-Filtering-Correlation-Id: 1c503336-8e55-4c57-47ff-08dba5567e89 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OYQBZfTGe/ZTM35TZXQ1c0CK1NtVomaQeq2DWLtj/c7iAmRQuY2kwT+Fe0OlrIpaV+1PRsb6qC97ZIg1YCa93zDJiMHWEJ0exI7tZYvciDsfixPAEHZNtZYgbxVx51Uqt/qvjquKfP8ddQiqyYhmGA/id1pHFLpdmgZk5te3jmNvIZQv9MTvmjjQlMlYUim5u+grrhlDSuFlDRQLFClsDEXXMegJl80tAkzHWTyOfQBv6fpfNwhjYrBjasi2PeuDE7DdXSlSmELmXXcGeBUF83icCajX6ydLzoIuETdctLB78sA66l0MtRDY8r2Nc6HgQ2O2OpZnli3f8h/qcyHc0BY8OXHE9g4U+gN4uuHjp2Kz2pYqdC5/UDX5JQJ2wbO9ESLa4LGEIpIbBMcmBjLb7ODxqPYfSR5KmWtvtQhoFcunUNF4M+pBdAHEOYgL3zOEdPkzh4Vw89c11F3CvTWavtmK3yWW/zQJRzSFumvQlyoOnN4lSU4TlbtoP4lAevAEdpCwMZO/3CAWAHozDNnBBGd5Bh/xo8EdhsWt8+zXTzItG1mEMbKbWtVnK8bItqRmNQRZBhS6QRKBgCbmo3/rRr7cR98CZurs5GQblhgwbj6s8J14uVRcBRiaiGsoq9I1tIa/4QCaXMFsRb9U7ydMDO0oWfBaOKzcu0oui5vk98qkJfJL0lkza2SE6tuhlAfniHcNoTGHEQ65e9TWNx7HhAIzdBr70AEAo56LLt4ED0nDtn6TPZd2pPdTFhG65Zj2zv3AqmaQPCLxWWzjpJZ7Sg== X-Forefront-Antispam-Report: CIP:216.228.118.232;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge1.nvidia.com;CAT:NONE;SFS:(13230031)(4636009)(376002)(39860400002)(396003)(136003)(346002)(1800799009)(82310400011)(186009)(451199024)(36840700001)(40470700004)(46966006)(86362001)(40460700003)(336012)(426003)(2906002)(47076005)(36756003)(36860700001)(83380400001)(6666004)(40480700001)(8676002)(4326008)(478600001)(26005)(41300700001)(8936002)(2616005)(82740400003)(7636003)(5660300002)(6636002)(356005)(316002)(110136005)(70206006)(70586007)(54906003)(7696005)(473944003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2023 10:31:51.0347 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1c503336-8e55-4c57-47ff-08dba5567e89 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.232];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000E9DB.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8211 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" A stream table entry generally can be configured for the following cases: Case #1: STE Stage-1 Translate Only The master has a CD table and attached to an S1 or BYPASS domain. [Config #1] Set STE.Config to S1_TRANS. And set STE.SHCFG to INCOMING, required by a BYPASS domain and ignored by an S1 domain. Then follow the CD table to set the other fields. Case #2: STE Stage-2 Translate Only The master doesn't have a CD table and attached to an S2 domain. [Config #2] Set STE.Config to S2_TRANS. Then follow the s2_cfg to set the other fields. Case #3: STE Stage-1 and Stage-2 Translate The master allocated a CD table and attached to a NESTED domain that has an s2_cfg somewhere for stage-2 fields. [Config #4] Set STE.Config to S1_TRANS | S2_TRANS. Then follow both the CD table and the s2_cfg to set the other fields. Case #4: STE Bypass The master doesn't have a CD table and attached to an INDENTITY domain. [Config #3] Set STE.Config to BYPASS and set STE.SHCFG to INCOMING. Case #5: STE Abort The master is not attached to any domain, and the "disable_bypass" param is set to "true". [Config #4] Set STE.Config to ABORT After the recent refactor of moving cd/cd_table ownerships, things in the arm_smmu_write_strtab_ent() are a bit out of date, e.g. master pointer now is always available. And it doesn't support a special case of attaching a BYPASS domain to a multi-ssid master in the case #1. Add helpers by naming them clearly for the first four STE.Config settings. The case #5 can be covered by calling Config #2 at the end of Config #1, though the driver currently doesn't really use it and should be updated to the ongoing nesting design in the IOMMUFD. Yet, the helpers would be able to simply support that in the future by adding very limited changes in the switch-case in arm_smmu_ste_stage2_translate(). Suggested-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 201 +++++++++++--------- 1 file changed, 112 insertions(+), 89 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 de8bc4c3ad7a..c2ebbc916a2e 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1251,6 +1251,91 @@ static void arm_smmu_sync_ste_for_sid(struct arm_smm= u_device *smmu, u32 sid) arm_smmu_cmdq_issue_cmd_with_sync(smmu, &cmd); } =20 +static void arm_smmu_ste_stage2_translate(struct arm_smmu_master *master, + u64 *ste) +{ + struct arm_smmu_domain *smmu_domain =3D master->domain; + struct arm_smmu_device *smmu =3D master->smmu; + struct arm_smmu_s2_cfg *s2_cfg; + + switch (smmu_domain->stage) { + case ARM_SMMU_DOMAIN_NESTED: + case ARM_SMMU_DOMAIN_S2: + s2_cfg =3D &smmu_domain->s2_cfg; + break; + default: + WARN_ON(1); + return; + } + + ste[0] |=3D FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_S2_TRANS); + + if (smmu->features & ARM_SMMU_FEAT_STALLS && !master->stall_enabled) + ste[1] |=3D STRTAB_STE_1_S1STALLD; + + if (master->ats_enabled) + ste[1] |=3D FIELD_PREP(STRTAB_STE_1_EATS, STRTAB_STE_1_EATS_TRANS); + + ste[2] |=3D FIELD_PREP(STRTAB_STE_2_S2VMID, s2_cfg->vmid) | + FIELD_PREP(STRTAB_STE_2_VTCR, s2_cfg->vtcr) | +#ifdef __BIG_ENDIAN + STRTAB_STE_2_S2ENDI | +#endif + STRTAB_STE_2_S2PTW | STRTAB_STE_2_S2AA64 | STRTAB_STE_2_S2R; + + ste[3] |=3D s2_cfg->vttbr & STRTAB_STE_3_S2TTB_MASK; +} + +static void arm_smmu_ste_stage1_translate(struct arm_smmu_master *master, + u64 *ste) +{ + struct arm_smmu_ctx_desc_cfg *cd_table =3D &master->cd_table; + struct arm_smmu_device *smmu =3D master->smmu; + __le64 *cdptr =3D arm_smmu_get_cd_ptr(master, 0); + + WARN_ON_ONCE(!cdptr); + + ste[0] |=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, cd_table->s1cdmax) | + FIELD_PREP(STRTAB_STE_0_S1FMT, cd_table->s1fmt); + + if (FIELD_GET(CTXDESC_CD_0_ASID, le64_to_cpu(cdptr[0]))) + ste[1] |=3D FIELD_PREP(STRTAB_STE_1_S1DSS, STRTAB_STE_1_S1DSS_SSID0); + else + ste[1] |=3D FIELD_PREP(STRTAB_STE_1_S1DSS, STRTAB_STE_1_S1DSS_BYPASS); + + ste[1] |=3D FIELD_PREP(STRTAB_STE_1_SHCFG, STRTAB_STE_1_SHCFG_INCOMING) | + FIELD_PREP(STRTAB_STE_1_S1CIR, STRTAB_STE_1_S1C_CACHE_WBRA) | + FIELD_PREP(STRTAB_STE_1_S1COR, STRTAB_STE_1_S1C_CACHE_WBRA) | + FIELD_PREP(STRTAB_STE_1_S1CSH, ARM_SMMU_SH_ISH); + + if (smmu->features & ARM_SMMU_FEAT_E2H) + ste[1] |=3D FIELD_PREP(STRTAB_STE_1_STRW, STRTAB_STE_1_STRW_EL2); + else + ste[1] |=3D FIELD_PREP(STRTAB_STE_1_STRW, STRTAB_STE_1_STRW_NSEL1); + + if (smmu->features & ARM_SMMU_FEAT_STALLS && !master->stall_enabled) + ste[1] |=3D STRTAB_STE_1_S1STALLD; + + if (master->ats_enabled) + ste[1] |=3D FIELD_PREP(STRTAB_STE_1_EATS, STRTAB_STE_1_EATS_TRANS); + + if (master->domain->stage =3D=3D ARM_SMMU_DOMAIN_NESTED) + arm_smmu_ste_stage2_translate(master, ste); +} + +static void arm_smmu_ste_abort(u64 *ste) +{ + ste[0] |=3D FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_ABORT); +} + +static void arm_smmu_ste_bypass(u64 *ste) +{ + ste[0] |=3D FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_BYPASS); + ste[1] |=3D FIELD_PREP(STRTAB_STE_1_SHCFG, STRTAB_STE_1_SHCFG_INCOMING); +} + static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 = sid, __le64 *dst) { @@ -1270,12 +1355,11 @@ static void arm_smmu_write_strtab_ent(struct arm_sm= mu_master *master, u32 sid, * 2. Write everything apart from dword 0, sync, write dword 0, sync * 3. Update Config, sync */ - u64 val =3D le64_to_cpu(dst[0]); + int i; + u64 ste[4] =3D {0}; + bool ste_sync_all =3D false; bool ste_live =3D false; - struct arm_smmu_device *smmu =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_device *smmu =3D master->smmu; struct arm_smmu_cmdq_ent prefetch_cmd =3D { .opcode =3D CMDQ_OP_PREFETCH_CFG, .prefetch =3D { @@ -1283,27 +1367,8 @@ static void arm_smmu_write_strtab_ent(struct arm_smm= u_master *master, u32 sid, }, }; =20 - if (master) { - smmu_domain =3D master->domain; - smmu =3D master->smmu; - } - - if (smmu_domain) { - switch (smmu_domain->stage) { - case ARM_SMMU_DOMAIN_S1: - cd_table =3D &master->cd_table; - break; - case ARM_SMMU_DOMAIN_S2: - case ARM_SMMU_DOMAIN_NESTED: - s2_cfg =3D &smmu_domain->s2_cfg; - break; - default: - break; - } - } - - if (val & STRTAB_STE_0_V) { - switch (FIELD_GET(STRTAB_STE_0_CFG, val)) { + if (le64_to_cpu(dst[0]) & STRTAB_STE_0_V) { + switch (FIELD_GET(STRTAB_STE_0_CFG, le64_to_cpu(dst[0]))) { case STRTAB_STE_0_CFG_BYPASS: break; case STRTAB_STE_0_CFG_S1_TRANS: @@ -1318,78 +1383,36 @@ static void arm_smmu_write_strtab_ent(struct arm_sm= mu_master *master, u32 sid, } } =20 - /* Nuke the existing STE_0 value, as we're going to rewrite it */ - val =3D STRTAB_STE_0_V; - - /* Bypass/fault */ - 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 - val |=3D FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_BYPASS); - - dst[0] =3D cpu_to_le64(val); - dst[1] =3D cpu_to_le64(FIELD_PREP(STRTAB_STE_1_SHCFG, - STRTAB_STE_1_SHCFG_INCOMING)); - dst[2] =3D 0; /* Nuke the VMID */ - /* - * The SMMU can perform negative caching, so we must sync - * the STE regardless of whether the old value was live. - */ - if (smmu) - arm_smmu_sync_ste_for_sid(smmu, sid); - master->cd_table.installed =3D false; - return; - } - - if (cd_table) { - u64 strw =3D smmu->features & ARM_SMMU_FEAT_E2H ? - STRTAB_STE_1_STRW_EL2 : STRTAB_STE_1_STRW_NSEL1; + ste[0] =3D STRTAB_STE_0_V; =20 + if (master->cd_table.cdtab && master->domain) { + BUG_ON(ste_live); + arm_smmu_ste_stage1_translate(master, ste); + master->cd_table.installed =3D true; + } else if (master->domain && + master->domain->stage =3D=3D ARM_SMMU_DOMAIN_S2) { BUG_ON(ste_live); - dst[1] =3D cpu_to_le64( - FIELD_PREP(STRTAB_STE_1_S1DSS, STRTAB_STE_1_S1DSS_SSID0) | - FIELD_PREP(STRTAB_STE_1_S1CIR, STRTAB_STE_1_S1C_CACHE_WBRA) | - FIELD_PREP(STRTAB_STE_1_S1COR, STRTAB_STE_1_S1C_CACHE_WBRA) | - FIELD_PREP(STRTAB_STE_1_S1CSH, ARM_SMMU_SH_ISH) | - FIELD_PREP(STRTAB_STE_1_STRW, strw)); - - if (smmu->features & ARM_SMMU_FEAT_STALLS && - !master->stall_enabled) - dst[1] |=3D cpu_to_le64(STRTAB_STE_1_S1STALLD); - - 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, cd_table->s1cdmax) | - FIELD_PREP(STRTAB_STE_0_S1FMT, cd_table->s1fmt); - cd_table->installed =3D true; + arm_smmu_ste_stage2_translate(master, ste); + master->cd_table.installed =3D false; + } else if (!master->domain && disable_bypass) { /* Master is detached */ + arm_smmu_ste_abort(ste); + master->cd_table.installed =3D false; } else { + arm_smmu_ste_bypass(ste); master->cd_table.installed =3D false; } =20 - if (s2_cfg) { - BUG_ON(ste_live); - dst[2] =3D cpu_to_le64( - FIELD_PREP(STRTAB_STE_2_S2VMID, s2_cfg->vmid) | - FIELD_PREP(STRTAB_STE_2_VTCR, s2_cfg->vtcr) | -#ifdef __BIG_ENDIAN - STRTAB_STE_2_S2ENDI | -#endif - STRTAB_STE_2_S2PTW | STRTAB_STE_2_S2AA64 | - STRTAB_STE_2_S2R); - - dst[3] =3D cpu_to_le64(s2_cfg->vttbr & STRTAB_STE_3_S2TTB_MASK); - - val |=3D FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_S2_TRANS); + for (i =3D 1; i < 4; i++) { + if (dst[i] =3D=3D cpu_to_le64(ste[i])) + continue; + dst[i] =3D cpu_to_le64(ste[i]); + ste_sync_all =3D true; } =20 - if (master->ats_enabled) - dst[1] |=3D cpu_to_le64(FIELD_PREP(STRTAB_STE_1_EATS, - STRTAB_STE_1_EATS_TRANS)); - - arm_smmu_sync_ste_for_sid(smmu, sid); + if (ste_sync_all) + arm_smmu_sync_ste_for_sid(smmu, sid); /* See comment in arm_smmu_write_ctx_desc() */ - WRITE_ONCE(dst[0], cpu_to_le64(val)); + WRITE_ONCE(dst[0], cpu_to_le64(ste[0])); arm_smmu_sync_ste_for_sid(smmu, sid); =20 /* It's likely that we'll want to use the new STE soon */ --=20 2.42.0