From patchwork Tue Jun 11 00:31:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13692717 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 8E36BC27C4F for ; Tue, 11 Jun 2024 00:31:59 +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=NIJ/gNENhSQfo1DN5Z52HaW1R/494n6JaN9LvW8m+Pw=; b=ZakR6W6lakDyc3 j68IP0ByVCAIdr+l20YXRC9w6cPpSXh8ddyTR2XeKWsEuys4dltpAHEvRbCPlqy/BmxMqVBFLy//X R7n26wEgnUmdhOWvZhCLs2vtNw5o1mjDdjCHwZGVJD+xT/7iQWTpek9zZ6jzNBVjjPPmfZgtY5nPj jBTvIwbIKL6aPJNsuo5Kn2N/DLuQ59PnWYTY4YO74aBVKVlTJRN1UHHjcApdY/DSKyuiiDkIlAtxn GZTb9MsdbShkXyQFPFsrv5mUmcg/nQnvZUOSECgmAdspKQ3sAK0QRIODk1SVtLe9ZDCrERGUm1SZM 5WbBOMXJbkO7aRmGJfxQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sGpQO-00000006yWB-01Xg; Tue, 11 Jun 2024 00:31:44 +0000 Received: from mail-mw2nam12on20629.outbound.protection.outlook.com ([2a01:111:f403:200a::629] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sGpQF-00000006yMq-2fHm for linux-arm-kernel@lists.infradead.org; Tue, 11 Jun 2024 00:31:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bswq4Gf7lvVrW35i5obRzmIrj1nhAcdZbgF9Dk1xSpG4HEt6e5+vBJcFKQpJkXbWXxScJxd8gf22BfCD/FCW6BNp8r1wDUwDY2dxXA7V8/Zj6V3q6yiaLOA8r4XvCqEqBxCqZa6+pKbI5MTOrRxpFYKFq7RlGxri0mYajskxXfGa/U2BHz9V1jlE1jcrG48hePAvDKNGS0rL9JD0gzLTKH9vZFKYBdRcM4dFerCJb5ismtD5JRqAPxaD2+Fd+0pd6q3s6ePSBE/XMGSIGonShs7ttIa2Zk29PU9bMwjyBGOa6a477Df9Pf088qtOKHCwaMpRoXCdevI9vola6BgHBg== 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=oYTgEj35A0f91/EyyxlcXOxicqIPPwHiJLPWeuNG3E4=; b=aZOVKturi54bWsfOOJw6LaQbYgPkFcYFMVM6cSl4x7ZEt8YNkbkYPZ9fW/XlGIzRneBJ3qTRNwWhlq4ZW+nYBUxGUegxxMRAx2x9tZuNSQ1yBktguN0lkqw5LZWJnbTWaMPrIzIR1YdpDg3DqiK/iYich9aM9fAOPalz2hdOkzab6yHRDvSrjI+LR9/oZPDJGCXORLxhjzlfWrg7E0IXP9aID7tnpDjKyVvh3unFO/a1x/ZT4cX4pOQd6YQ4QS0PkwrkLbj6kYnVoIOCmX7YU+/xZQ/7jPz6D+8v4XWUfa7rSj4gOA3bGAhoAZLNygV7ld4obqC9GM7TF9M8XdTxpQ== 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=oYTgEj35A0f91/EyyxlcXOxicqIPPwHiJLPWeuNG3E4=; b=Nc7UQQ4FgrFKuEWOee4SZnLc6+nResOLPjGeNQVlWUbhCIll4m98CTSDZlk303NukUPgEmbXNlp96vIRBV9RrNenzNJkgkhP2Me3I0qbO0xlSboZrmWcm+P4coS90ILjchM3n3yp1Om4CSQhy4GSjV9NTuMxjCqYQx9FZxmL6cDyMT7Io26PNK7WWzTjV+FT9I9VDycITi2b4k4XVQo/egDWhUToq1zOQ0/eFs33RLQxbjOgtwdFgPXh5EfbAWdSElYvOM17PqxQjnIVoWiMk6WLaLXbwIw5J5B4TqSDd8TAoZRu7YBJPdlQ0nPPw3Jvsxj+KAngfoNjvnnM+mOWzg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) by MN6PR12MB8565.namprd12.prod.outlook.com (2603:10b6:208:47d::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.36; Tue, 11 Jun 2024 00:31:25 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e%4]) with mapi id 15.20.7633.036; Tue, 11 Jun 2024 00:31:25 +0000 From: Jason Gunthorpe To: iommu@lists.linux.dev, Joerg Roedel , linux-arm-kernel@lists.infradead.org, Robin Murphy , Will Deacon Cc: Michael Shavit , Nicolin Chen , patches@lists.linux.dev, Ryan Roberts , Mostafa Saleh Subject: [PATCH v2 01/10] iommu/arm-smmu-v3: Do not zero the strtab twice Date: Mon, 10 Jun 2024 21:31:10 -0300 Message-ID: <1-v2-318ed5f6983b+198f-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v2-318ed5f6983b+198f-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0449.namprd13.prod.outlook.com (2603:10b6:208:2c3::34) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|MN6PR12MB8565:EE_ X-MS-Office365-Filtering-Correlation-Id: bb2680e8-9555-4fe0-c8e8-08dc89add16c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|1800799015|366007; X-Microsoft-Antispam-Message-Info: kpsLZ37GTlYpD1JQPy6osr7BCwcq4wGQUiFoO4btRzzh4ANUe6xME+mle8BPcw2oA+b+SdV+X/T5Djy9AURYolWazT7UVwUXYl+cKMEmc1N46F4eWUB5APPR+sr8FFAx/nb+ucxTXgWxtmp3tk6AmD6rW71tNaDjNiYBUv7LaGaOJoDrTil3p04GdjqzlzWVVLHTed6QflUDJZ/7xi+xL5/yzI3AXs+qCuLUUpWzkp4QRBKtNV0U7uYDg7WY5A3L5mdCS9emmnBtM2BU9AZy5v4kiriGwBMFv2d6dyHzCvWDAG+eQdnAtot8AULrbXogsRhhfMvoAZi5mdSGYPco+E2Tcb8jqrqf8mQwLlUNRTVYGkVMAXz69oLmnp9Z2UQhkFKLPZibliyiom7somUyfZBK+V3tbuYPvfuJJQNS6Wf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DqqqBJE017uCxdE20w2THEEN1Ci21C1o3nGkbhPHqNHV+PNaVmktoyW2k9FZLJo99J5mXNZidsvSw3oG9O5qEsFROdnvyv/blLYW3sciZ8RzEqc4R0gPdBcAOxMA4vTM+Ls1Zp2x2DvplseMAZQjGNmsJ48yn+yqCY86D+n6nStyeM2FM7QeCJs/jJuXokjKwFuoL3KR6G1WY9v0LAEn61jP7wMRxAyknOD/mKNlHQa1AOqZCaO2UrjjHl1Un0aH+bVAr2eFG3XydLFtaFUW2tDK/WJuu/TF1nfCCiOdUYaSSWLcGnNU2zoXiplz0hAwsrL6X933HJ1CqF3mkpqGP4V0OfoitcQrherS3XKc5vZde8EejJ/ml6hVyFiOmoPujejAyy+ZN7H6tiwBZEEpbc4qYlbUHaN58fPwDN7sb3lj6j2PLsfi0UCpzyRRdML4gBFq6Db8brcX4Fs1qbkdAe4s/4X+Hme/2Lz1LmuEJ0Vo00TXpCPTQRLz3N8Lr6+ZAJlGwi+eUsNdbr8JsYbx4ft/dD489DsFOM3E9TbRH4= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: bb2680e8-9555-4fe0-c8e8-08dc89add16c X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jun 2024 00:31:21.6679 (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: JycvZKpOqNm9Upm5JVKUVHoSnHbu6y4EaV14Ouis4kMIvkEEPOwg3pT254Yua3mB X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN6PR12MB8565 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240610_173135_749752_7663C73F X-CRM114-Status: GOOD ( 11.54 ) 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 dmam_alloc_coherent() already returns zero'd memory so cfg->strtab.l1_desc (the list of DMA addresses for the L2 entries) is already zero'd. arm_smmu_init_l1_strtab() goes through and calls arm_smmu_write_strtab_l1_desc() on the newly allocated (and zero'd) struct arm_smmu_strtab_l1_desc, which ends up computing 'val = 0' and zeroing it again. Remove arm_smmu_init_l1_strtab() and just call devm_kcalloc() from arm_smmu_init_strtab_2lvl to allocate the companion struct. Tested-by: Nicolin Chen Reviewed-by: Mostafa Saleh Signed-off-by: Jason Gunthorpe Reviewed-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 29 +++++++-------------- 1 file changed, 9 insertions(+), 20 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 ec8c7b7f4cb9c1..d56e19ca6ef6c5 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3215,25 +3215,6 @@ static int arm_smmu_init_queues(struct arm_smmu_device *smmu) PRIQ_ENT_DWORDS, "priq"); } -static int arm_smmu_init_l1_strtab(struct arm_smmu_device *smmu) -{ - unsigned int i; - struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; - void *strtab = smmu->strtab_cfg.strtab; - - cfg->l1_desc = devm_kcalloc(smmu->dev, cfg->num_l1_ents, - sizeof(*cfg->l1_desc), GFP_KERNEL); - if (!cfg->l1_desc) - return -ENOMEM; - - for (i = 0; i < cfg->num_l1_ents; ++i) { - arm_smmu_write_strtab_l1_desc(strtab, &cfg->l1_desc[i]); - strtab += STRTAB_L1_DESC_DWORDS << 3; - } - - return 0; -} - static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) { void *strtab; @@ -3269,7 +3250,15 @@ static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) reg |= FIELD_PREP(STRTAB_BASE_CFG_SPLIT, STRTAB_SPLIT); cfg->strtab_base_cfg = reg; - return arm_smmu_init_l1_strtab(smmu); + cfg->l1_desc = devm_kcalloc(smmu->dev, cfg->num_l1_ents, + sizeof(*cfg->l1_desc), GFP_KERNEL); + if (!cfg->l1_desc) { + dev_err(smmu->dev, + "failed to allocate l1 stream table (%zu bytes)\n", + cfg->num_l1_ents * sizeof(*cfg->l1_desc)); + return -ENOMEM; + } + return 0; } static int arm_smmu_init_strtab_linear(struct arm_smmu_device *smmu)