From patchwork Mon Jun 3 22:31:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13684420 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 1EB37C25B78 for ; Mon, 3 Jun 2024 22:32: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=FOhARvDiXej2d0eFaZG803yYIZ5wwcAvBIPaH1nfMCE=; b=1dspyXKPNEREEN ojMX2z9jdmWJi1iY0m9pWSTx73sSi3LUS+MqTHq2T3m7p75uWJF3CspI0DRCMx0tVW0uVmDcBHsl4 y+VY4asOrHhV2Mfi9lT6US3mkTaJnnyNHAiPJgkmgPvq0K64YfVmWajnD4Jsb/9l3bu3qGzHXvMwV 8H3bu3LJ5+rRMyiypQh8MqMVtM4SetHtKm6ywmqTxiJ7nMPvHSHOVPnobGZYipOIDFTc71GlYBIXz 6rWdyO7IXDvJ3s42uXMNy1ejmkPde5kVzLrv0goiw2B1B5nO1Fn9oZL98lIcBQsRNPZNCHOfAdvUS De2TGMW6MdaCjCqNNwPA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEGDb-00000000Ujh-3myq; Mon, 03 Jun 2024 22:31:55 +0000 Received: from mail-mw2nam04on20601.outbound.protection.outlook.com ([2a01:111:f403:240a::601] helo=NAM04-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEGDY-00000000UcR-3Oap for linux-arm-kernel@lists.infradead.org; Mon, 03 Jun 2024 22:31:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BsKuNipbZAPF/lbR9nRkLOCh39wuQ5DouLipnAQVPY0l/sXZ2DQ2J2srdMZtCMWpiq48V3n3XhjR3zt9V6Wn/VIss6VYsOJEfx63t1gFlXifLQ8vQZUQJlHRZx+8P+an9zVt/X+tfyhy/LLZGk9XmEzBjTmxe/k5lbp7xcRQfAavhK1cEQtAAYEJv9qHUWZKXdMynFs+P3dTwy7fNsvSJVPVhKFhD9ZktQxMJ69l8KHpslzqay8Wa2iziEh91nrxTLhvFmLDeSjC0AEQ5/ALIJFKDctXp1EVK0iPh3m4SqNiJTtw+8IpdVEygSHrANyESmez+qnnYXzLepxPmGkmuw== 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=lphU3KQKuRLndzzM5bkWVVObagvyxuP0pAYPwpGda5w=; b=e5CozVQruYLuVyXWI/on6DIQrNGuU5j/OU8YyVLLjxyGqC80mDDmlmsKFhAnhLktvlKGIb7KIejD+H8swMwDJesBvZHd5cfISt86Z2F5qrmXqCBOnyExNulYfpU/ouvSXkLm31k8NXnbY9u49KsxJwxFqhlFQlcZVtAsi1E5QH25G+RU23XjxBsgEy6oQiDeC+RZJlztvTTQGDNZ/arLPmCNJ5pO6q/0V7UCriF6QNm0V2hfQKnDYWbHQt1RLYQj7uUMkk2/lY9s0L50X+rn/vHx6NATyC2WK0o/y+XiwGm45j8+I/ffSyugD/RNh2GSNldo2Apa2D448G6HOa5yQA== 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=lphU3KQKuRLndzzM5bkWVVObagvyxuP0pAYPwpGda5w=; b=oHyKofr4mxA2FVWhrLAayfgaEQapQlgYBTzpQYMtjrPTsNxveb7Q2O7bjVQVAXoincdI4F46JWOgllGvQgzagzUS+l5ZuQz7UdH23n/iK++3TFX2TeSk+1DYodJ/PQN6S5YkgQNYBNaB2wbUWuRWuWKKiki6CZwWIlXmm1RpnptNwHxQK04OyCOY2t1Nka59+unn7Q9wY1PIMkmt+SLoXYfSnyazhuU6PFsU7wyTF5DV3X9YIy6A5B5630ySU1Bs61+grcT+tnsoApdhoTQSzOAQdPSQ5TWm5MjX+GETsQT9ObFOiI6stl1ew7ZtRItZ4nJ8YLLLgZtvs5UesaI71g== 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 MW4PR12MB6778.namprd12.prod.outlook.com (2603:10b6:303:1e8::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.25; Mon, 3 Jun 2024 22:31:38 +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.021; Mon, 3 Jun 2024 22:31:38 +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 2/7] iommu/arm-smmu-v3: Do not zero the strtab twice Date: Mon, 3 Jun 2024 19:31:28 -0300 Message-ID: <2-v1-1b720dce51d1+4f44-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v1-1b720dce51d1+4f44-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR11CA0018.namprd11.prod.outlook.com (2603:10b6:208:23b::23) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|MW4PR12MB6778:EE_ X-MS-Office365-Filtering-Correlation-Id: 7c36cf1d-f5ac-4821-6ee4-08dc841cedfe X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|366007|1800799015; X-Microsoft-Antispam-Message-Info: aPjU2KQAwEd/3yBx7qJw25JLRBnGtEUeSDioQAOFcfwhan2CJe2LPxrZtimNIS4zXCbUj2hPePKN4cy5pdGlxHs0lspdb/KRftf+qnJngV6CFuGnZll1uA3DKKgK10NJN2Xo13l5WMOSw8vds5y5L/Lvr5edYxxIR7aePWHL9O9zUfhTe9iOpMH53yqyXFPD77BRwYEW53AWHCT/x6NwlFfqmcbD05ALWN4H+rNxb2UO9Jgj4DVvLf8OORpXg5q2vS8wSN3qZU4Q58sSjjCBr4gsVqr6AnNSRbf1nkcPrEPkvIMD58KYLPcB5SPdGWBWXJLlXA5DIDbimaRGcO+PW+38iFS1EugRksVsfTpXMpeZHwGFuuLnuroGD5GjbuBa5EMeNWLjghB38mUU0PTqG8aapufBfy66jWtW3+uiPmbGTki8TPdkIP8mhgzsJyKU7aDLCkNPXeNVAjhNscqS3Zrc0szGhNQUgiUIYsQMIWTKbbOtpZVXsAeipGDW7Dx9tq2sU+VnrgWpqoS0v4iLeAU6gsKeH36inogvYboduGaWZbmnOU6oQs+YFVgh2e47ZiWcKUHq1KCeR8gtO0bMrDE+/w9qU93Bd7kSTrgJ0H9uZdxapR/11oU8Ro1L3FKmkzGhM049KlGcPjdW77UQzFUjA/W8OAzIsP3gVPRE8azRKm8NBcxe49IXPpurw+kD4LGLSjrph+oZLtUMz93IP5Uz2XTXFb/6lBHJ58ofqKV8N67HHJZylpukvwQrk+8NFZUHoiCK6YodzWl0zUkfRGJi229p2ykFmhAEkBz7wQw1PHgyTSrbozdXvaq8wBnW65UfizUNnkvcEiIFUsS3tuu0WST6cL2LIETCJazMw04p+a9df8wCxcS4j3/MDC5v0/bau2xmgUHGnUfS2q2ANMFV1qHY3chUaLXWQWIn/P97nBGeCvy3yrMcYvAXto6zsQ4ivXCngR8uAj2ff+FuZk9xaLY9CWb+CeyQRIQj8XYQuMyraPILIqoIJ87HxiQuVKKaw+o2waz+sXcLmOEtSDK8ou4eglP6lET6ViJOem+2j7p77TtnKQcChl0ygZoNMeKY0TOqjK41KPhxnsRJg3RwVt2vYAl1u+5IeOP+iN7hF/m8nX3ensZSAy4qnIYI6hiTGxtW5pu+Dl/Lwf4rHeueGMlhgQJe8b8uvbs7FPn0fjoqGkwAI1VKPs3IGMt8bYiLvw7+C1wjKxpoLC6woKTvW4cZHnnW4bB0l9E2vmWtPhWwDaT8W3yULC1AApdyLo/+r7LTzxCgHnTao1VLqw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376005)(366007)(1800799015);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: KB1b1KOpiubw8YsIMQ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RG5Ewy6yktu/U6jgr7ELvcZwYQWWY9yAAkk2faWcjutJ0XPo/PyJQ7xS7E8J9Et31HKMDcw+27CVqRoIy9WaJxsPX1NN9SEsPUcU7YnxOUnXzxxg5KeNNNh7tyj/LBuPiy7UT0sW4b2gLPV3YQ6/63X0fSLz34eGVYp07LptG+mHmasSWm4+JKgckaVCqiDKRl492qXFWB09/6sY/jTrZnIsW2AhfhIYoqvAdI36S9jrzFv0za/VEeyBa5sgxbKUWW0072a1sLMXtWJNloq7g2JMNvB+1QkhhVSotZN4WOyBwpJcrCJmU/gQeEfGYzPo2P70hbodteoNeI1NL0HbNCDbvn5yy7qMeDJFcAjOUNx6dz2+G9h+6AxpfIlHQ0tDsH0+5YEhIuzt3EQDoxVAMig/TNISSwFOp/mNqU4R+qpd2XBnLMw3vhhA7r4FNm0BQpt2vE6t4C6UXPWu5rAboLber1fmwt20wYFC9YOhCyfbMb2/MD/R5w= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7c36cf1d-f5ac-4821-6ee4-08dc841cedfe X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jun 2024 22:31:36.7838 (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: ap/V1o3mHQwDEcfJ0pFOvUkoOsE/VjKX5qHU8sRXJy+cPVkJ0AbF6qw+BQqvrgMt X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6778 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240603_153152_863082_88275272 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. Signed-off-by: Jason Gunthorpe Reviewed-by: Mostafa Saleh --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 27 +++++++-------------- 1 file changed, 9 insertions(+), 18 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 6b4f1a664288db..d27dd0600bf1df 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3220,23 +3220,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; - - 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( - &smmu->strtab_cfg.strtab.l1_desc[i], &cfg->l1_desc[i]); - - return 0; -} - static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) { void *strtab; @@ -3272,7 +3255,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)