From patchwork Thu Jan 25 23:57:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13531920 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 6DA15C48285 for ; Fri, 26 Jan 2024 01:05:03 +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=8uHiRDCG9Ca5ex//StQFvhvv7I5VNNkAgKEnOf+4zF8=; b=1CCBGJ3Ip78sC2 7ERxj+ZdrnVrSYIuNufF5K7mjxLCrcZ+3iakxR5GXDwDMAOkyJtK88+HpcZMwPu5EH3Fmp0JVn3i+ tHGtFmx7DQUs6ygFtbk9pR3DXQfBK87NYndH6Qrh9tQ+ICSheMcFzi06ky1clTU00C6DFkEyAB2U7 MItlQ9C9TRSaByPJ6FgKSJi0OdlAT9kvbIVVkPVZLnr4thNPzVQGJfU1+5IAHJw6dNTAlJawp6tuz NlYXlChNPUnHtLtkn9j9LnEe0OYiwe/eOJfA2cGyHrO1yH2a2oDNh0zWJR8gQLOCi2fD4kmqZj5ms K/8HjGid1E9xpgGTT9Rg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rTAeJ-00000002hQo-3JiR; Fri, 26 Jan 2024 01:04:51 +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 1rT9bR-00000002XD8-09aB for linux-arm-kernel@lists.infradead.org; Thu, 25 Jan 2024 23:57:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fliMKW6wFo3KqxhnZeLChftZCrlaD5KCOdpIEr+rdovurosTNoRrwsPQqN4hKiHlszZBDwCb3X2Opdq5F/s4PeSU9A/r6Fxu3JO/1WQr6dR2Rm6oimY13sNYigXGUbIntM+yY9xvf3FPmn9eCqpiaLsHDofBwZ0mXmHnYqq/gJuNwu//WKJ+GpHWDoqYVmdiSbaLAvICbnOBPdsaCtOOXo6KA/59hr+/eBPsLIJFZjJT6sXkTTAA6ynG2UEMcsPewx7uJYes96G6lFr/WePi4i5L70qJAc3a/57lHVr+u8uEPLFl7VrsjPRg1eoH7LiWvdgLvO7q/ZPHnVTvpocgog== 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=EXBdG6x59BYBIEfcytUTgWGIVzbNdAceHkSaMhsELPE=; b=MuU4XX4ynXlAqU5sozauD4DUc2DjrelNUnUQC2C15c6D3qj9cKS9Y1OKzoAk9vqpndxtS2/QQ9WJfqtzpkgMsU4O71m+XnrOZK9dXYKaHzAN9E1VbN8vIiFQBNI4XFpg3LH1rQneVyi++F9090SHGEVR+C06DSI2vH0ExxDp/TvRwZ4TYgghBQ0yTz87SCXvnuoIcrsWwP12iJsaCd9ye4F9TYk7NxHDge4i5EYbasc1dgke5k2URLHE43aYVtY5gzpCY/Aa7kbNBwDDxOV/rYa+hKnv1hOt2cwph6KpIzyaY+4DHikvQy0TMSQ03mGMbPlb/uOm4gUw/3mLnHsvuQ== 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=EXBdG6x59BYBIEfcytUTgWGIVzbNdAceHkSaMhsELPE=; b=q5s105plSfCm146esfLpnNVnv84cFjPgzz0DqHJjZxdd3Oxgoen5TZ2jwISv6i3A7ZbdLqh+qvXnSP0uYiVO73a7S2dw6qS14CN4dkBqOkMWKuPHR/11MHHphnEfLnyamQRISDormgo8xusWyeNRAG3eYjNSgw9vyb4sa/AB6eXP6XkAmEuX+KkqqcL5aSD/Md1dSxqjVr/dbvF0EONIStfMz/r9of0NgLu5i1UPDb1yfGF1c4/irNqd4qXtdJYPD+IsoddVEiDYs4y56ZxuRJONAiHifN4VPW5y1f33QCcRXoHDzKq3rwnZJhXkBdN6tdZc7qv/TxGljHSdGdtd8A== 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:37 +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:37 +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 02/16] iommu/arm-smmu-v3: Consolidate the STE generation for abort/bypass Date: Thu, 25 Jan 2024 19:57:12 -0400 Message-ID: <2-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: SA0PR11CA0047.namprd11.prod.outlook.com (2603:10b6:806:d0::22) 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: e7b3d1e2-420d-47b9-8c29-08dc1e01641e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DVI3vzvM1Sp2+qZNFjPRxRa8o+PbBZxzjwoAJyNG2u/C/g0/8vnR4F4Jt8vqqc7PRAka84iw++K9WXjO2Tp2UEtESCe70pwCYaI3jM6xS4AX4wzXnL0Kd4GFQQC012SPX1vYfh0N3GYrNyt/HlnkHS0oPU3c7yvXRgYQsQjoAK5PNKZlfAY8wZH+kMcb+SDacMWTzcMIfrYjA/YprwjFcxH+m6sh9EbYtJtrMKYGTxOYCnrreRKZEcWf1RcJs1h52D8GqBTzEEd5Eg7JrwhJ1Nn3LJ0Bgd48s6R6v4qOSoVg1F43yxl7GLF6b2ucGc26dvVQV0ImuPiAEOtXa4fYpmXBQ9LmlRehfcUbIdfOUPFCg2IWI7vz+WLWoFbTadUEOOs2kChSunsbl8xf1w6F1ZYkqqalT1A6QYMzCl5qxWG8DBGtOrARsrzB56RTAaUO38HKYcxn8gsh2nECuRDPxBdrGL1j8bdvbQ5wDmSiPCDCDS+2F/6vEc0ZTQBlHATr8zFXITY6eL+3SkK0UPdAneobDOvYtRpKP867rLiWlXURj92iuEJ7zYVMXxktPfcld4lHLhD+YHHUBQXEBpOVkVgpgpKyuApV/QqaeRBqR5E= 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);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: IyL/rDvnRf1u7GRWRB6Y3kMoFhi22238lOt0//pn4A96Lt3eJ6vtijkpVUBO+EtcS9vyXcBnyRePsjT6tLrsHKrByT6BQFCUfZTGfuhbQhfM3T3yz1BAMyQFB45heCf1xjdI6Tfd6Cw7WO+v8GI/zMkTuFE94BrtofYb+Tt7we5GsmgwxcFOAZvl21Ih78nS+W0Xg/zBcmhfcTZq3YyDK2n7Z2yKurFp5Nuruinx/G8h+Gtjg2YCo4nQ6lQ5RxFYiOcbbM+1jZR18xUSWRUnnz1o4W+sd2lw5zJ+oDFw2614bBTNumJBrsGXcle/nuPXjBBboy80P1UnIf8/5D00eeuFhYGw2YfUq3Zu6X6/8CbWtg1l8ZZypO07Ayd5TbogHTpdYudywQ9AETBH8Na74PdYQEPQS3mEkDbe/tP1PPEYQ4iXo0XtY3lqsvYwNWpo36uqtRPJtpfOkjeqIhlZvw714g5EDeHpThoSBpKmiAN1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3qQtqI8xKWTPrjrFRcHldF3F66 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e7b3d1e2-420d-47b9-8c29-08dc1e01641e 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:30.4185 (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: 6In3mdzTNEK0HAHfFWjA6phm8l4hAyP9rqnQsbbXvBKC95GKdD9538kADwbnq3dJ X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7881 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240125_155749_181429_F3A06227 X-CRM114-Status: GOOD ( 15.19 ) 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 allows writing the flow of arm_smmu_write_strtab_ent() around abort and bypass domains more naturally. Note that the core code no longer supplies NULL domains, though there is still a flow in the driver that end up in arm_smmu_write_strtab_ent() with NULL. A later patch will remove it. Remove the duplicate calculation of the STE in arm_smmu_init_bypass_stes() and remove the force parameter. arm_smmu_rmr_install_bypass_ste() can now simply invoke arm_smmu_make_bypass_ste() directly. 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 | 89 +++++++++++---------- 1 file changed, 47 insertions(+), 42 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 690742e8f173eb..38bcb4ed1fccc1 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1496,6 +1496,24 @@ static void arm_smmu_write_ste(struct arm_smmu_master *master, u32 sid, } } +static void arm_smmu_make_abort_ste(struct arm_smmu_ste *target) +{ + 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_ABORT)); +} + +static void arm_smmu_make_bypass_ste(struct arm_smmu_ste *target) +{ + 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_BYPASS)); + target->data[1] = cpu_to_le64( + 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, struct arm_smmu_ste *dst) { @@ -1506,37 +1524,31 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, struct arm_smmu_domain *smmu_domain = master->domain; struct arm_smmu_ste target = {}; - if (smmu_domain) { - switch (smmu_domain->stage) { - case ARM_SMMU_DOMAIN_S1: - cd_table = &master->cd_table; - break; - case ARM_SMMU_DOMAIN_S2: - s2_cfg = &smmu_domain->s2_cfg; - break; - default: - break; - } + 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: + cd_table = &master->cd_table; + break; + case ARM_SMMU_DOMAIN_S2: + s2_cfg = &smmu_domain->s2_cfg; + break; + case ARM_SMMU_DOMAIN_BYPASS: + arm_smmu_make_bypass_ste(&target); + arm_smmu_write_ste(master, sid, dst, &target); + return; } /* Nuke the existing STE_0 value, as we're going to rewrite it */ val = STRTAB_STE_0_V; - /* Bypass/fault */ - if (!smmu_domain || !(cd_table || s2_cfg)) { - if (!smmu_domain && disable_bypass) - val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_ABORT); - else - val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_BYPASS); - - target.data[0] = cpu_to_le64(val); - target.data[1] = cpu_to_le64(FIELD_PREP(STRTAB_STE_1_SHCFG, - STRTAB_STE_1_SHCFG_INCOMING)); - target.data[2] = 0; /* Nuke the VMID */ - arm_smmu_write_ste(master, sid, dst, &target); - return; - } - if (cd_table) { u64 strw = smmu->features & ARM_SMMU_FEAT_E2H ? STRTAB_STE_1_STRW_EL2 : STRTAB_STE_1_STRW_NSEL1; @@ -1582,21 +1594,15 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid, } static void arm_smmu_init_bypass_stes(struct arm_smmu_ste *strtab, - unsigned int nent, bool force) + unsigned int nent) { unsigned int i; - u64 val = STRTAB_STE_0_V; - - if (disable_bypass && !force) - val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_ABORT); - else - val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_BYPASS); for (i = 0; i < nent; ++i) { - strtab->data[0] = cpu_to_le64(val); - strtab->data[1] = cpu_to_le64(FIELD_PREP( - STRTAB_STE_1_SHCFG, STRTAB_STE_1_SHCFG_INCOMING)); - strtab->data[2] = 0; + if (disable_bypass) + arm_smmu_make_abort_ste(strtab); + else + arm_smmu_make_bypass_ste(strtab); strtab++; } } @@ -1624,7 +1630,7 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) return -ENOMEM; } - arm_smmu_init_bypass_stes(desc->l2ptr, 1 << STRTAB_SPLIT, false); + arm_smmu_init_bypass_stes(desc->l2ptr, 1 << STRTAB_SPLIT); arm_smmu_write_strtab_l1_desc(strtab, desc); return 0; } @@ -3243,7 +3249,7 @@ static int arm_smmu_init_strtab_linear(struct arm_smmu_device *smmu) reg |= FIELD_PREP(STRTAB_BASE_CFG_LOG2SIZE, smmu->sid_bits); cfg->strtab_base_cfg = reg; - arm_smmu_init_bypass_stes(strtab, cfg->num_l1_ents, false); + arm_smmu_init_bypass_stes(strtab, cfg->num_l1_ents); return 0; } @@ -3954,7 +3960,6 @@ static void arm_smmu_rmr_install_bypass_ste(struct arm_smmu_device *smmu) iort_get_rmr_sids(dev_fwnode(smmu->dev), &rmr_list); list_for_each_entry(e, &rmr_list, list) { - struct arm_smmu_ste *step; struct iommu_iort_rmr_data *rmr; int ret, i; @@ -3967,8 +3972,8 @@ static void arm_smmu_rmr_install_bypass_ste(struct arm_smmu_device *smmu) continue; } - step = arm_smmu_get_step_for_sid(smmu, rmr->sids[i]); - arm_smmu_init_bypass_stes(step, 1, true); + arm_smmu_make_bypass_ste( + arm_smmu_get_step_for_sid(smmu, rmr->sids[i])); } }