From patchwork Thu Jan 25 23:57:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13531900 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 587C7C48285 for ; Thu, 25 Jan 2024 23:58:07 +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:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=s1obmJvJSvRCcc7hku9RPqREaQprFRIW+1IisvnoyMs=; b=QNKlirEGbCSf9q n0G+4vC/EmAE6XsKriyqdTNGFGNPR6IOc+ODBGXL1cXp8ltJcMJ2DY/bAsTbe7SkB81DlTLMhSeRP QdGUMSUbr/tQKI0pf+uSMxvq4hanMJCP6pxBAMPMyXrOS8PRos4jDW7dx10ueHmN7lhpCs4nOdTL+ /UaD4DQtki6eI8j2KY1QZK3mraNIx3YrG5tWWAdJAS6TwctOu0KfQ9MT8F8WugPKsd+/cqRsiOFlX lyn4E0FqVXBQbVXzDF8pJSSnrxcpwJeJkEjE38bhmPpRJVWslMLJFwe9M8gFpRfxPTW+mS4aRHf8n soKQRfqaINDLjEm2pCbg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rT9bX-00000002XKN-1icE; Thu, 25 Jan 2024 23:57:55 +0000 Received: from mail-dm6nam12on20601.outbound.protection.outlook.com ([2a01:111:f403:2417::601] helo=NAM12-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rT9bK-00000002XA1-2whH for linux-arm-kernel@lists.infradead.org; Thu, 25 Jan 2024 23:57:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nNGjWwUMA5/SDu7rHoenPLLvzpbPLiKFSpyJHaAWz/6em+tPwFO07gTrrn3C3i7E/MOcQVhnbZdU7jULN1Zb3Mugexi5WKRxq4l0MPsCxe96i3RrJNqf0CbqETFhuJNRh9FaxID7Mh45USdL04emYNaUidwApW/kK0UEAZ2d5UP+MIihES+hnUbqx/oX56vjCSzyYsbXmP3ow7hJIGrap+f0bmqO/oBFMZ/PFZOJOd3LrhbycGYMdyuXwMN2LDNsMlXsUSodixy/L71deEHxBk4seQbtuNnUo9cL5PgoitcRP/GQqSVTEZzIj4uRiJKbZ3bvLRGI4de+1+BWaOXTCA== 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=VScJwSKYuH/PLSG5Eur7OXgttwJojTfNlgE+Ap0b6lk=; b=ZZMSYsdLgnEeHySlbFjavzBV8Pym7jtWgoWZrkvunA5TWYutqi3y2BJMkYeycwo87ZitLcbHTTQsqKfIR1DCBoR1vVM5eWj2uEQ0SBlXTmwyB+KjDyn5GypszVoj5flZo98JnGfVXQQvN+xLajezOsael/AHCyammDlqKsmgoThp1KJsRENpxapRDlRJuHAv4aYC1I7UOn8nqbDTfz6p8iH2KJKYyvTbgo/WbWVcxn8RZGQ6MGXPHUsdS7PQeryZwGVF04O6B4nhgbUjmebKTwM5a9bkz374G7m0EkQUMmGapfnL9NwaLhjxsVAA5zj2wMpAo5Lo0mnGjFFNEEwXiw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=VScJwSKYuH/PLSG5Eur7OXgttwJojTfNlgE+Ap0b6lk=; b=cVolLkQPQD6OM8/MxIiZgomjC9fZvrjQxxfS5nvIJSnnPi6ZRX4YtWhsffPLETp8rfyyUfx+e+yC+/bnI0hQf0ShOqolvRBGKCy6OKhWlYLqF1hUFbNN44BTfnVm1T2MnhPWF6rxfZOTyv5tkj6Tw5qVG4gjny3wBJezmCnn/ZfvfMXH/5rULlrMxVJTf+M/UdNnnQL9fHrpocuJ/xFmknohnER9jZvw2zRJ0Tz1lKqH0lxaL/adXcYqSBUc7a2h7IqzFwS0NpV8H5JshjTMQblEt1HMVOHZ2l5MuDszLkgi64lHH9Fa42Oa1icuSXUFI1oO9xlG/GdCbNcUNUcvaA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by SN7PR12MB7881.namprd12.prod.outlook.com (2603:10b6:806:34a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.24; Thu, 25 Jan 2024 23:57:32 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::96dd:1160:6472:9873%6]) with mapi id 15.20.7228.022; Thu, 25 Jan 2024 23:57:32 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Moritz Fischer , Moritz Fischer , Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Shameer Kolothum Subject: [PATCH v4 04/16] iommu/arm-smmu-v3: Move the STE generation for S1 and S2 domains into functions Date: Thu, 25 Jan 2024 19:57:14 -0400 Message-ID: <4-v4-c93b774edcc4+42d2b-smmuv3_newapi_p1_jgg@nvidia.com> In-Reply-To: <0-v4-c93b774edcc4+42d2b-smmuv3_newapi_p1_jgg@nvidia.com> References: X-ClientProxiedBy: SA0PR11CA0032.namprd11.prod.outlook.com (2603:10b6:806:d0::7) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SN7PR12MB7881:EE_ X-MS-Office365-Filtering-Correlation-Id: 5dbe8329-2820-4a30-d8bd-08dc1e0162fa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tkQWNLtJECFwVnMI7LMz89ejxspyUccV7/SX1u4x+YkVNwtZTz7CVHmz9Ae/rxhdvK9aWb826RnjvDjmc7VhYCvHUVW6iuNCQvkptadSnZY1sgAUUApWyFDYxE/H5iTHRzqfzxW4aXf95b74bJcNXWugo03TrEaGOnKMlH0S6UdNgdPFxEak01zXxTskg2sd+41U0FzkxvvVQRpnKKtJC1XHunAI48IyyiV89LVMt7g1KXyw8fV4k1UgwSNP9WbtX3NDcIuZamUnRrCUpIdAFQko8QVk2piUffJKmcr0FXdgqhVEcV3UXwASCUTc7uxr+XKZxS6hcmQgf9N2Yi3ZyFxnpsn+Dmrd015LY8+wDNmlHLCZ88y+ouNbbfXsvoTecLrCMCwSq31f2kz6McbiKhAo5IOrC0R4pIK4RrethzZqaO6AcG9Z/TRnCDSWyI+OmQ0DYctIDPVScDxNOEmCnMEZuNzwe1sMLnRzt6U4YVEiXLxBZKLaitQfXx3d2k4nnuSsYz4fIPsASVeMuroupU4YTLJbsy5dQ3cswQ9ZLVmZCU58gYMUwfkZoB8d+7mEDyxvDf58lOnI0lamxpjptW47JHwe8sxHNLyDX9gPO0dzD9wvfCkJtUwNpHqRPSBpygbi7L+QIljeWJCPI4plPA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(136003)(396003)(346002)(39860400002)(366004)(230922051799003)(451199024)(64100799003)(1800799012)(186009)(83380400001)(36756003)(66556008)(86362001)(54906003)(110136005)(66946007)(66476007)(26005)(38100700002)(6512007)(2906002)(2616005)(7416002)(478600001)(6666004)(41300700001)(6506007)(6486002)(5660300002)(316002)(8676002)(4326008)(8936002)(4216001)(473944003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hiUGw6JrjLzphdHcqyqzPLc+bu0Kpa+W8m/oH/9T9FdqguSk5b5IK77fcv7EgaLSaohHRcYabnOAajBEHG4AmM+Gb791cIcfDmmxFqGHPUeNngZxA8ZdCAzQW94IkMv9VWXmzGXlpoB1waFYYbdaFPUawmjycDYUDs33U4oXdj40ADsKvWa7YrZsUB2sJvLGsb06G4Fm4c0+RYucZ37uoPfKU+gi1rlBU0m9GWwUdbWNNuSQR7t67rgTFFM9vRCLredIlDJAww8c+Jrxs7XYLQJS2tRykn/bpMyTLxIyh/aQ6QdQX6HfgMpQ01ZmGX6O4F9HGHjuoPTrO3rRAXz2VvTO2u37WWUUUiNp7XoOnb4GkgVMc4LumMNgkMeY/iCKIgPmFPnT7mob1v98CIU61zZkfJxaNWqfEfvgDVdBZoge9EASBBjZ283fhPkWtqDBtSzS10MSSX9hPA59QYorKgahENH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tGNNbEFhEovZLOWcwBg5o4I97/mftd5ASWQss2H9g X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5dbe8329-2820-4a30-d8bd-08dc1e0162fa X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jan 2024 23:57:28.5307 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: wc2TXSO2f0/hydp1N8vLhm0rNZg0JQIb+AJ3D2xwfn+dqLFSdDnYymAqM3rvoSeG X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7881 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240125_155742_960242_35776993 X-CRM114-Status: GOOD ( 11.70 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This is preparation to move the STE calculation higher up in to the call chain and remove arm_smmu_write_strtab_ent(). These new functions will be called directly from attach_dev. Reviewed-by: Moritz Fischer 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 Reviewed-by: Mostafa Saleh --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 115 +++++++++++--------- 1 file changed, 62 insertions(+), 53 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 df8fc7b87a7907..910156881423e0 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1516,13 +1516,68 @@ static void arm_smmu_make_bypass_ste(struct arm_smmu_ste *target) FIELD_PREP(STRTAB_STE_1_SHCFG, STRTAB_STE_1_SHCFG_INCOMING)); } +static void arm_smmu_make_cdtable_ste(struct arm_smmu_ste *target, + struct arm_smmu_master *master, + struct arm_smmu_ctx_desc_cfg *cd_table) +{ + struct arm_smmu_device *smmu = master->smmu; + + memset(target, 0, sizeof(*target)); + target->data[0] = cpu_to_le64( + STRTAB_STE_0_V | + FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_S1_TRANS) | + FIELD_PREP(STRTAB_STE_0_S1FMT, cd_table->s1fmt) | + (cd_table->cdtab_dma & STRTAB_STE_0_S1CTXPTR_MASK) | + FIELD_PREP(STRTAB_STE_0_S1CDMAX, cd_table->s1cdmax)); + + target->data[1] = 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) | + ((smmu->features & ARM_SMMU_FEAT_STALLS && + !master->stall_enabled) ? + STRTAB_STE_1_S1STALLD : + 0) | + FIELD_PREP(STRTAB_STE_1_EATS, + master->ats_enabled ? STRTAB_STE_1_EATS_TRANS : 0) | + FIELD_PREP(STRTAB_STE_1_STRW, + (smmu->features & ARM_SMMU_FEAT_E2H) ? + STRTAB_STE_1_STRW_EL2 : + STRTAB_STE_1_STRW_NSEL1)); +} + +static void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, + struct arm_smmu_master *master, + struct arm_smmu_domain *smmu_domain) +{ + struct arm_smmu_s2_cfg *s2_cfg = &smmu_domain->s2_cfg; + + memset(target, 0, sizeof(*target)); + target->data[0] = cpu_to_le64( + STRTAB_STE_0_V | + FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_S2_TRANS)); + + target->data[1] = cpu_to_le64( + FIELD_PREP(STRTAB_STE_1_EATS, + master->ats_enabled ? STRTAB_STE_1_EATS_TRANS : 0)); + + target->data[2] = cpu_to_le64( + FIELD_PREP(STRTAB_STE_2_S2VMID, s2_cfg->vmid) | + FIELD_PREP(STRTAB_STE_2_VTCR, s2_cfg->vtcr) | + STRTAB_STE_2_S2AA64 | +#ifdef __BIG_ENDIAN + STRTAB_STE_2_S2ENDI | +#endif + STRTAB_STE_2_S2PTW | + STRTAB_STE_2_S2R); + + target->data[3] = cpu_to_le64(s2_cfg->vttbr & STRTAB_STE_3_S2TTB_MASK); +} + static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, struct arm_smmu_ste *dst) { - u64 val; - struct arm_smmu_device *smmu = master->smmu; - struct arm_smmu_ctx_desc_cfg *cd_table = NULL; - struct arm_smmu_s2_cfg *s2_cfg = NULL; struct arm_smmu_domain *smmu_domain = master->domain; struct arm_smmu_ste target = {}; @@ -1537,61 +1592,15 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, switch (smmu_domain->stage) { case ARM_SMMU_DOMAIN_S1: - cd_table = &master->cd_table; + arm_smmu_make_cdtable_ste(&target, master, &master->cd_table); break; case ARM_SMMU_DOMAIN_S2: - s2_cfg = &smmu_domain->s2_cfg; + arm_smmu_make_s2_domain_ste(&target, master, smmu_domain); break; case ARM_SMMU_DOMAIN_BYPASS: arm_smmu_make_bypass_ste(&target); - arm_smmu_write_ste(master, sid, dst, &target); - return; + break; } - - /* Nuke the existing STE_0 value, as we're going to rewrite it */ - val = STRTAB_STE_0_V; - - if (cd_table) { - u64 strw = smmu->features & ARM_SMMU_FEAT_E2H ? - STRTAB_STE_1_STRW_EL2 : STRTAB_STE_1_STRW_NSEL1; - - target.data[1] = 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) - target.data[1] |= cpu_to_le64(STRTAB_STE_1_S1STALLD); - - val |= (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 (s2_cfg) { - target.data[2] = 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); - - target.data[3] = cpu_to_le64(s2_cfg->vttbr & STRTAB_STE_3_S2TTB_MASK); - - val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_S2_TRANS); - } - - if (master->ats_enabled) - target.data[1] |= cpu_to_le64(FIELD_PREP(STRTAB_STE_1_EATS, - STRTAB_STE_1_EATS_TRANS)); - - target.data[0] = cpu_to_le64(val); arm_smmu_write_ste(master, sid, dst, &target); }