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) From patchwork Tue Jun 11 00:31:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13692715 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 F208BC27C55 for ; Tue, 11 Jun 2024 00:31:53 +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=PLPFT5AAgWpenaMl3GICWNRiFq5W1YEZt/19t4OrKlM=; b=HEGs3NQO+2ethH GK6r4OxFevbKDSu+ol3dHK/fyPJrhAxxpkxdZUr+WM6A4j52/xnR7hecw6Yg+z9V3BiWXlpKc3Cri FEumVcDxpjgDUAm4SqZY1tbE94I5OT3wB0MlVMk+n60n2GpyAc07dfUWkiGjhON4uhb3AqVi/TG++ LSYLEkJ6k1+sRYmGv+afm+bk9UEBzCcpOfyqS27cJSOi0EB+DCGeZ33nJZkDUIM0BW4hg+G4HF5p9 ahYUWaRVEx2ylIy4Zox4TX1dO0PgX+L2PLPgYnxD6qL6p0weB6W4rRE1idyOG2OruyPbFkQdfHN45 2vBewGDpColbLz+sefeg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sGpQK-00000006yTL-1djB; Tue, 11 Jun 2024 00:31:40 +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 1sGpQB-00000006yMq-3dtp for linux-arm-kernel@lists.infradead.org; Tue, 11 Jun 2024 00:31:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gtibeu8Nu7C42YsEqKBLMHnxGbNQuMDy1RauwpbqxHDnG66ebLRGncVHSzJiUyXIVv8Wm4pPI+VCpq2dGEzoj3nf7vUvzfzDazaMEctyp1xEoJZlAX6FFwJ3j2J31l6CcBGFCv5+2RWWtLCZ8TD3X3yLG4+aCPvpTRH09hvpCInsDXAm0GR41MuetkmrSWmN0kaZFM71sp9QWmvpRvmj0fvMk2NK8psmF28I233/MVFiCrZdWOirHZVbKwbkdAzvo11OzPfouUygWZQ15EKbQSt16wd6MCcjkZztq98eQuTL6E2klriw8YLeEWCNxSn3PVt3hXawJJkXnCiA0AiGxg== 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=9wicn8xpR+3lz8Lwtw6mtwa1S5KQEjSdyhRq590rrAw=; b=Ji/+2ttlfBU0bLGbLfC0o8A6hXjZO+49V/7OujSOMGjGkSHxWOvW4elSYhKdYkJc8RzYcx9ZKrctuoH/JlYdhl82oBOuRf5rrL9MN3ARqjER8DVEo3O5cUAzd3alu70MPjB/5sDioTw5RNDlYLTQX/XsYVwBemOPwlXuY6HnpXlXq/1zF6t/3woxsv6Scx/RvFl+VThI+tfcdECBof/Z8KkPpuRksVVZt/+0LqxiUSk8mGF8Sw46hQe8mFrDi9vSjk7jfpRdB6dSa4qNI1HTngCqhYK8Pp4gJ4Otn2Enm5MxKUbWExUgAemJRKwAKB/b8Encp2uD9Gann3MAZebGlw== 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=9wicn8xpR+3lz8Lwtw6mtwa1S5KQEjSdyhRq590rrAw=; b=gjSwGUMvGOccspGbFjwoiUJXi9lkjePMZ03G73UCjfUFoLvC7WBYky0gOjcsIBuWkHmpRCrKvJYcVHL4d4GeIlXuMDDFOlC2EQSHl2MGoTYb01xUtbG4MWF5LrqpF5nkHEl7XTc5GZTwAVienyCTJUcssSQgVovPY/8vAhSkHRl80P4pvti6nWd8gXqUgtv8MWRHoPwvdt8v7LNMbsmUFokXotkXElGl7Y8Jq8vRcoFqKzeFuLPs5nURlgaI/HGjm2EOdwBlQc2sQDeFncCjiafFp2T8haWBMQ3CjnndXe96EeJEPlpG6KiI/t9K4YY6+IwIGqi1b+hWyC6CZVvmGg== 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:22 +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:21 +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 02/10] iommu/arm-smmu-v3: Shrink the strtab l1_desc array Date: Mon, 10 Jun 2024 21:31:11 -0300 Message-ID: <2-v2-318ed5f6983b+198f-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v2-318ed5f6983b+198f-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR19CA0060.namprd19.prod.outlook.com (2603:10b6:208:19b::37) 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: 86da12e4-7ba3-4a3d-7380-08dc89add145 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|1800799015|366007; X-Microsoft-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isTBt1gcIbN2eEReHSKZRp8yV0c0Z9vEoDjPjfXDovltEcrujzQiK12Q7aimLdEm9jooJ2DYUR2UR4HbiQT/5s9QtcK+5K30v1EflSVyKQWlYHaaQx7xGygGh+t9HmNknZ4w4ycdayw2tPzZ3wc3XHpnVUtgWoGNpNy7jDcCEsk9YHKVh+BbqxN9MX4gwr4ab5yybpsLcaKA9fUUhQgqAjcg0LAydNbsbHEu5V00Y4a6HWxArHoquGU7XQdR6XL9pMUvudE= 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)(1800799015)(366007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: yanyrZ/UDtyxPs7LvFCj6vYqKWIuYp1C3lDL2D174Otae0Q/ThpMn2hZBfDX1Q0bZEsSNQCN83KgLWVOlvDHISkdb+PACH/PORAwhF96c6BEYuZ4g4QIh/ziNF+oLSUIzwr4Lua44PTrC4iCl19zm4ddyHdc2Q7QbPb7EsUpTYVNfq6BZNAauv/m+L+L0ASyNwrL7zyO4nQwSQaS72tQxrw24B8nwZqwZMeoecE8m9pze6KVD9B9yey/jsr90OgOOKrEeDMBCTP4iMHdU76ppERd0jgCySWiP76vWhtz2XD1zhMxNCN86K4kojpIoYJwvuK8a6WM3HrCWdmM5pADlH4vyJZIMEyNMzbaN/qKulXFD/QTWM4KsHsSM+OiE82kH4ngvO16jJ73SSjytv6Nga2oxCh+EzyLSxy1VNofA65Bdbis1HvFcbWOBI2p3WxFEE3qFTMy7DjjKxUy4aKaGjNc+tYilj6SdYL2NHUkXQ+pzg1355xgYdPIU4+JcV6IAF3Q3QbdZvxko6N2fJI130QacK/pDKcy9JPdl9VNMNmt/gFS2wMq8VZgrr3ciz5bsMngAqHQ0Tts52l2jUxbZzMSp8S58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rossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jun 2024 00:31:21.4513 (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: K1ilnvDcbZ+6siYuILljdIC6B7UOHJ19sw6iTSlfd8odHiOOlu0d5WSN7Te1uH81 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN6PR12MB8565 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240610_173131_961332_8BBA5C8F X-CRM114-Status: GOOD ( 12.67 ) 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 The top of the 2 level stream table is (at most) 128k entries big, and two high order allocations are required. One of __le64 which is programmed into the HW (1M), and one of struct arm_smmu_strtab_l1_desc which holds the CPU pointer (3M). There is no reason to store the l2ptr_dma as nothing reads it. devm stores a copy of it and the DMA memory will be freed via devm mechanisms. span is a constant of 8+1. Remove both. This removes 16 bytes from each arm_smmu_l1_ctx_desc and saves up to 2M of memory per iommu instance. 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 | 13 ++++++------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 3 --- 2 files changed, 6 insertions(+), 10 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 d56e19ca6ef6c5..95351c134c7c45 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1447,13 +1447,12 @@ bool arm_smmu_free_asid(struct arm_smmu_ctx_desc *cd) } /* Stream table manipulation functions */ -static void -arm_smmu_write_strtab_l1_desc(__le64 *dst, struct arm_smmu_strtab_l1_desc *desc) +static void arm_smmu_write_strtab_l1_desc(__le64 *dst, dma_addr_t l2ptr_dma) { u64 val = 0; - val |= FIELD_PREP(STRTAB_L1_DESC_SPAN, desc->span); - val |= desc->l2ptr_dma & STRTAB_L1_DESC_L2PTR_MASK; + val |= FIELD_PREP(STRTAB_L1_DESC_SPAN, STRTAB_SPLIT + 1); + val |= l2ptr_dma & STRTAB_L1_DESC_L2PTR_MASK; /* The HW has 64 bit atomicity with stores to the L2 STE table */ WRITE_ONCE(*dst, cpu_to_le64(val)); @@ -1655,6 +1654,7 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) { size_t size; void *strtab; + dma_addr_t l2ptr_dma; struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; struct arm_smmu_strtab_l1_desc *desc = &cfg->l1_desc[sid >> STRTAB_SPLIT]; @@ -1664,8 +1664,7 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) size = 1 << (STRTAB_SPLIT + ilog2(STRTAB_STE_DWORDS) + 3); strtab = &cfg->strtab[(sid >> STRTAB_SPLIT) * STRTAB_L1_DESC_DWORDS]; - desc->span = STRTAB_SPLIT + 1; - desc->l2ptr = dmam_alloc_coherent(smmu->dev, size, &desc->l2ptr_dma, + desc->l2ptr = dmam_alloc_coherent(smmu->dev, size, &l2ptr_dma, GFP_KERNEL); if (!desc->l2ptr) { dev_err(smmu->dev, @@ -1675,7 +1674,7 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) } arm_smmu_init_initial_stes(desc->l2ptr, 1 << STRTAB_SPLIT); - arm_smmu_write_strtab_l1_desc(strtab, desc); + arm_smmu_write_strtab_l1_desc(strtab, l2ptr_dma); return 0; } diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 1242a086c9f948..087733797f9087 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -579,10 +579,7 @@ struct arm_smmu_priq { /* High-level stream table and context descriptor structures */ struct arm_smmu_strtab_l1_desc { - u8 span; - struct arm_smmu_ste *l2ptr; - dma_addr_t l2ptr_dma; }; struct arm_smmu_ctx_desc { From patchwork Tue Jun 11 00:31: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: 13692714 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 1D8BCC27C4F for ; Tue, 11 Jun 2024 00:31:49 +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=irVOg/hZeKFe81uAdKC3Ci275UsUcaJIC0Z1rjwbEUo=; b=Xb9YOshyxFPBZ5 wSb3cMwMS8TRAvggIoz4nVW3Exm00VVQDnXERVkdC8Ka5SC6Gx+/boEhIvmV5YjCOOfRAFSuGNKtd JQT6N4e49PnRoPpxJu0uATELgfhvBvLTqt9yt3pBma1Lfbm+WGrNX/JauCd8AeV03b19DqBQXvOr/ slf2ATIjOHopUxuG/DgHBwX7JcifL0L1OZgh4WmBeeSrFUsOL9FpcJ4/31toT/jWdnU3+5cLboWPP /tXNfxhIUqJQ4ZQsfSS8yO6UpMZY1bi9ZLfKgoP+JobAdokCKcxngO/GTtraP4bFaTLowgZ7Fw438 0705NNYJQIlJsqYhX7Aw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sGpQD-00000006yOS-0hlA; Tue, 11 Jun 2024 00:31:33 +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 1sGpQA-00000006yMq-1LSu for linux-arm-kernel@lists.infradead.org; Tue, 11 Jun 2024 00:31:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bJ8MYglGTrb0v1dUtag20xzkX1UFWAZ4CMGosJCM/im/KYZ0FFAUOr7bsP7bZHnKgrdYlG6EBBq28zDOBngB2dtdy0VwqspQTJbImCJo5LUlXJ3cHMbni854NQv+/vzmWV+q8Ry/yz/sy9gN1m4qwIJoN3xnic1Hu4DbUl8IkWeU83qiawmPm8PlgYWfvsUyN7Vv+Icr/lH4GGxHvYPcFD7ZVrsS7n/ZujQ27FTHH49m05XGqBrJZm+CSsO8DdEWuDVI/N0Gw7w5y+vyRep7HYfwsQjNSGsApXFuIC+b0eBXXQvwnPsYfrMl/v8dw3UZSyp9y9SSWiCgzLM8e2jo2A== 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=XsziEwBeQqdRiACut6k2MY6n6cUizIl3zTxvH4FcLbg=; b=Wdu1mmToY2fdTVt2K13qFRrFnCoL5iNbsrJohppc8DKVUrD2bgau58I4KwqE69qoZIeYrNOievNND1biWcnTFX7CfcT1Ab+XrWD4ZVWScHgR3ZWcpXdasSznazCzblbF89KiS4O+sFm0bD+8rnc/+kcGssPbre84eA8LUNCPq7gLz5NrbHBAjE6o5+EJtWSfw2rzt+ybknAiRXqrycxjoaV5VW0RAWBWvoRI1w5NQOEzeGgO46YOwyAWMpTGYRAJI5fyPbrp9XfXqy0OyD5u5BLnip8l9vrXUOJ5dHKpwVRVc/hYm9y7cF8RnaZWbT8Wqp06c9GLskno75CvdYFbKA== 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=XsziEwBeQqdRiACut6k2MY6n6cUizIl3zTxvH4FcLbg=; b=NV7DoH94XDHzj5lNBVHlPhL3Fh+NInDsvT7tInHENSuP2Fwy3h9fTotNQQFoqZSGw0NoiW3OlU6J8rCv5OPh3dYJxqH9vDXp/252D9Ff11oBqInmO/50TZF+uroTbt22SdQxlz4Z1f0YVLm9bn9fOwPVKyXBd2CdMCn6urc7pThWIHe5chB6lmniz0K8OcdZba2ca0qFiA0LEIlZ8rETk5/JAiiC+q4iKt/MjcTtS32b4zkvdOjwxyVLUXPzpUrqf0iyOIv9n/mokzNOZhWaR/MF+T/LbMsWqxzsuyJTKVUKcYojhSo1BFu4D4QMtckHU8m/3TcrirYjWuXhTv1WvA== 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:21 +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:21 +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 03/10] iommu/arm-smmu-v3: Add arm_smmu_strtab_l1/2_idx() Date: Mon, 10 Jun 2024 21:31:12 -0300 Message-ID: <3-v2-318ed5f6983b+198f-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v2-318ed5f6983b+198f-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0018.namprd13.prod.outlook.com (2603:10b6:208:256::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_|MN6PR12MB8565:EE_ X-MS-Office365-Filtering-Correlation-Id: 968d5e4c-bac9-4a74-b52a-08dc89add13d 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: EnP2evE/Llb7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BJ8PZvDw+yjgKsb7BUya3dpaDguNMN566zvOdbNBXT3D5MkZBxAYqc1ID9p4SdYmJL1yd8mExtyzgkdYyQ4akyTDZlZ39013VDwggwdCtsdsPKtBLNQVYlbDxdAqp7fgs61dNShbt7WJtG4CUII1SiyKlODe9uGuA1DBf0sDLhjaZUiXkAIRWjaXQnsm7wHIwej3wVD5b3YqqYsNzBKHUszsTib3x7uV46Nk7RmtY3PMqaKQ/dJAp 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)(1800799015)(366007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: MOXOVMrsojwKmmaHmdu2UBPol1dTkhNP70a2mRfAobh5uuV+wBnamzhOXXVI9QOqjHjO1SsedVHh7hyHhdvBGbZCvTALkIsEkz6TvmhY4zLqioEN+1lLQVxy3yOkDWKSlKHO7we5Rc/RPAIMRBIzsTvUN+L3osClDE3iNomQeB3jvoQTz5BRNg1tfsvG+tIGDGl4zbJwZ/qidbDeRxjdn88Em65I/RrojafohaTg28uQbYOCBVXJm53hIMSKIt2+gP4tuF6Zedi5bQK7JfcYBuFrHQ0lPRc76tZwYqCaex0+tVX+L2GpfGAU6Cqf+Jfzo5226B2l2DKl/Unk7SuUiEskIDJo0/WYbL1GZ1zv7A2I5EPJTYkAwFsC6OL/GCts1XxHdhORO7fYuvTXEDZ2SgP0VBV38qyGbbr+dR4Am2D0lJ4z22bbgu0HT9WkUPox2s1jQ7Z10QEqaQGpXSIUYxB9VSiBMKg63uDz97dbDPfRDlAg76XY9gtCKvBLoZZ9skY2qQpb8vheWGdd0BZIOcpH//KSQBqA7bRBMbFVTz/b45Oal73kqDJc3ntIjBb8jdeIky4sKB3n44DYufwLRSR8ecd+v08yOPWx9DOCSIPWYIzTpTGdFqqyo4viXKwRj/RO5xgvtzp9M1uRjZmsp0DchmCfRtOUPKZnXDaNTYlU0gLa/H2BI4tXEiaGyMlB3Z8o09MeWnrxg+Hrfw/EmajZS9nmXPaLLFMh5/17TfFWeIrS0aymF71uf/bNsIVx+4rWAY3DJaiuT43AlQeC2wAoTFEymN+8Zs5wfMqhw68h2JZWrslqSbct3F63rf7v4M97+XLAcwvJmD4SlWzExuLfyQ5KSZHqICFBI/4XfUi7lKCYmQZYqw/dcFLnX/fznmBq0pbH2zI/xO8WXk6CUTSxs9FI032/0p9VvzpGJ78HKlq5TFsGLsy2s0ejiO3aRLmDIVJMVlNb3mbDyKKS8Y0nuCTct2LYJ0YVKhvDuwnWspxWf8q3lbGWmBc1EEXOeMsK2qFbNtVwvjpeNLVs6hOZX61CkCM9fuSazyLV7EeFUHHzrK7uFEDe6jQGwLGUcjiSEFfdDy1IGSFDik3TUzcy7YwyMEw8XN1O1rCsd5jY4m2OBrvYebiUan+i15Zr2BX2t9R/bnduVFjVWoVK15mawG/+hhAoP+LQ5RNOtdXL1MaSbGiUahJUO46R4UpxKQR/n03VJsEdpF4V/9FeAkw4SmRUdsEZsfUA5KsvcFO9026XpJgOvZ4QFfxjl11NNXSx7sonZhkgF+eWB6vPWqoRwbO3EWBxrzlUX97nPltQjDrhzSEICgOA1z71NTdD+THHfFFVkvypHsuuln+LgI7WtpgwUUFY0WYG6PCCI10U0TtDbi4mk04GN0IvHy5GAv0xhLnUIY4nhLw6TfF7KRkA5zC+486/18KEpuVJ4BNFzo6x1Z08MqNXSa2E9QE5DLodAI1mbLQNHzV9HkdMT1jr57+hkPO/riFTXmFFofru4n+quJqtr0iW6ys3VnPBETel2q1aLBF3/4afTr3uHIYPvsXuXd2emecmxYvtDH/6hQmpbxKm3mhuv8dR5kQO X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 968d5e4c-bac9-4a74-b52a-08dc89add13d 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.3867 (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: 14G5oMWRnfoP4lcYPGGonFK7sKzdn6RuIgTrZVMC4bMxj/uNqf6d2l3m6SEFW+ST X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN6PR12MB8565 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240610_173130_397731_45E6073D X-CRM114-Status: GOOD ( 15.87 ) 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 Don't open code the calculations of the indexes for each level, provide two functions to do that math and call them in all the places. Update all the places computing indexes. Calculate the L1 table size directly based on the max required index from the cap. Remove STRTAB_L1_SZ_SHIFT in favour of STRTAB_NUM_L2_STES. Use STRTAB_NUM_L2_STES to replace remaining open coded 1 << STRTAB_SPLIT. Signed-off-by: Jason Gunthorpe Reviewed-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 53 +++++++++------------ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 14 +++++- 2 files changed, 36 insertions(+), 31 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 95351c134c7c45..07b797ad832801 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1652,20 +1652,17 @@ static void arm_smmu_init_initial_stes(struct arm_smmu_ste *strtab, static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) { - size_t size; - void *strtab; dma_addr_t l2ptr_dma; struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; - struct arm_smmu_strtab_l1_desc *desc = &cfg->l1_desc[sid >> STRTAB_SPLIT]; + struct arm_smmu_strtab_l1_desc *desc = + &cfg->l1_desc[arm_smmu_strtab_l1_idx(sid)]; if (desc->l2ptr) return 0; - size = 1 << (STRTAB_SPLIT + ilog2(STRTAB_STE_DWORDS) + 3); - strtab = &cfg->strtab[(sid >> STRTAB_SPLIT) * STRTAB_L1_DESC_DWORDS]; - - desc->l2ptr = dmam_alloc_coherent(smmu->dev, size, &l2ptr_dma, - GFP_KERNEL); + desc->l2ptr = dmam_alloc_coherent( + smmu->dev, STRTAB_NUM_L2_STES * sizeof(struct arm_smmu_ste), + &l2ptr_dma, GFP_KERNEL); if (!desc->l2ptr) { dev_err(smmu->dev, "failed to allocate l2 stream table for SID %u\n", @@ -1673,8 +1670,9 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) return -ENOMEM; } - arm_smmu_init_initial_stes(desc->l2ptr, 1 << STRTAB_SPLIT); - arm_smmu_write_strtab_l1_desc(strtab, l2ptr_dma); + arm_smmu_init_initial_stes(desc->l2ptr, STRTAB_NUM_L2_STES); + arm_smmu_write_strtab_l1_desc(&cfg->strtab[arm_smmu_strtab_l1_idx(sid)], + l2ptr_dma); return 0; } @@ -2411,12 +2409,9 @@ arm_smmu_get_step_for_sid(struct arm_smmu_device *smmu, u32 sid) struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) { - unsigned int idx1, idx2; - /* Two-level walk */ - idx1 = (sid >> STRTAB_SPLIT) * STRTAB_L1_DESC_DWORDS; - idx2 = sid & ((1 << STRTAB_SPLIT) - 1); - return &cfg->l1_desc[idx1].l2ptr[idx2]; + return &cfg->l1_desc[arm_smmu_strtab_l1_idx(sid)] + .l2ptr[arm_smmu_strtab_l2_idx(sid)]; } else { /* Simple linear lookup */ return (struct arm_smmu_ste *)&cfg @@ -2792,12 +2787,10 @@ struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode) static bool arm_smmu_sid_in_range(struct arm_smmu_device *smmu, u32 sid) { - unsigned long limit = smmu->strtab_cfg.num_l1_ents; - if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) - limit *= 1UL << STRTAB_SPLIT; - - return sid < limit; + return arm_smmu_strtab_l1_idx(sid) < + smmu->strtab_cfg.num_l1_ents; + return sid < smmu->strtab_cfg.num_l1_ents; } static int arm_smmu_init_sid_strtab(struct arm_smmu_device *smmu, u32 sid) @@ -3218,19 +3211,18 @@ static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) { void *strtab; u64 reg; - u32 size, l1size; + u32 l1size; struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; + unsigned int last_sid_idx = + arm_smmu_strtab_l1_idx((1 << smmu->sid_bits) - 1); /* Calculate the L1 size, capped to the SIDSIZE. */ - size = STRTAB_L1_SZ_SHIFT - (ilog2(STRTAB_L1_DESC_DWORDS) + 3); - size = min(size, smmu->sid_bits - STRTAB_SPLIT); - cfg->num_l1_ents = 1 << size; - - size += STRTAB_SPLIT; - if (size < smmu->sid_bits) + cfg->num_l1_ents = min(last_sid_idx + 1, STRTAB_MAX_L1_ENTRIES); + if (cfg->num_l1_ents <= last_sid_idx) dev_warn(smmu->dev, - "2-level strtab only covers %u/%u bits of SID\n", - size, smmu->sid_bits); + "2-level strtab only covers %u/%u of SIDs\n", + cfg->num_l1_ents * STRTAB_NUM_L2_STES, + 1 << smmu->sid_bits); l1size = cfg->num_l1_ents * (STRTAB_L1_DESC_DWORDS << 3); strtab = dmam_alloc_coherent(smmu->dev, l1size, &cfg->strtab_dma, @@ -3245,7 +3237,8 @@ static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) /* Configure strtab_base_cfg for 2 levels */ reg = FIELD_PREP(STRTAB_BASE_CFG_FMT, STRTAB_BASE_CFG_FMT_2LVL); - reg |= FIELD_PREP(STRTAB_BASE_CFG_LOG2SIZE, size); + reg |= FIELD_PREP(STRTAB_BASE_CFG_LOG2SIZE, + ilog2(cfg->num_l1_ents) + STRTAB_SPLIT); reg |= FIELD_PREP(STRTAB_BASE_CFG_SPLIT, STRTAB_SPLIT); cfg->strtab_base_cfg = reg; diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 087733797f9087..95c3ac8613da79 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -199,7 +199,6 @@ * 2lvl: 128k L1 entries, * 256 lazy entries per table (each table covers a PCI bus) */ -#define STRTAB_L1_SZ_SHIFT 20 #define STRTAB_SPLIT 8 #define STRTAB_L1_DESC_DWORDS 1 @@ -212,6 +211,19 @@ struct arm_smmu_ste { __le64 data[STRTAB_STE_DWORDS]; }; +#define STRTAB_NUM_L2_STES (1 << STRTAB_SPLIT) +#define STRTAB_MAX_L1_ENTRIES (1 << 17) + +static inline unsigned int arm_smmu_strtab_l1_idx(unsigned int sid) +{ + return sid / STRTAB_NUM_L2_STES; +} + +static inline unsigned int arm_smmu_strtab_l2_idx(unsigned int sid) +{ + return sid % STRTAB_NUM_L2_STES; +} + #define STRTAB_STE_0_V (1UL << 0) #define STRTAB_STE_0_CFG GENMASK_ULL(3, 1) #define STRTAB_STE_0_CFG_ABORT 0 From patchwork Tue Jun 11 00:31:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13692718 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 C9AF2C27C5F for ; Tue, 11 Jun 2024 00:32:00 +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=xFXw/xAFLPMrOMf7/OZM2ZoLVwK2My0wGuqMK37/ebk=; b=ePno2J37TDG3jC u43F3s2QMYsYnLCu7QOfCqyyLf0XxmOB1uoSMOMmgaEr1JuZRAnC9KiGHm4Ise8MhfC51EEn/zYb8 7jiwLSXq4Tm1xCJ8sgQztbZID1vCe+9MAReN7UIbq04a02966s6L5eBRyQ4kRh/YVnQv9/saFy9xk Z77JPac/U4hwOHPJLKYlS6S8rtnBv9fQkDVf+TrYZhAQrRUNLdRUEMjI5JwQIa3m/94b+a+I3weOh FCUjXijcvCkqjqNfomuwwcRxtb8NYqN7TSZaC9JxlUzHe65J5kimlgKGaquLyBEGkIkS3bRmrqDCS gSsbwzFfB/TsaWJGfhbw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sGpQT-00000006yYS-0q7o; Tue, 11 Jun 2024 00:31:49 +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 1sGpQH-00000006yMq-2PWN for linux-arm-kernel@lists.infradead.org; Tue, 11 Jun 2024 00:31:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B3wa5WRz/Am+oCObsEbARwUOnS8upmmnY6O8I3lfX0U/CMmxfKynk2UV6+i/SU1MUEe1xeOWh+6IGEMvSMuEFC7m3k4RNYtBpG5TTh/IX2rpWkrMOwvGysEsVtMLuCqjxpJhKD0ojmL1uw/MLRxUxOuI3H5m+iIoNrON+jqNF+2wySEwRRRGMpJKJBo/I8HosqTHbj/JM6B6x2DkWnSoOBePrHEnJSo3Ww99qUBTqQ3ojlLmS1vdvufC3yCakHZsZQKP3CHJJGVCL/3kZCM48CU6XlMD9iyNAtqsKMLM4jed1UFrqZYnJOOybvI2skhERfXD9b86ApUMlXX2EjYSig== 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=zGBoX46GEwVxp49l1OKu7+S0xbj6faopuERfQ6HizIk=; b=idDx8jy0TevZ7kGWN5mAYsVsCNFv9wS5jThwRSfpGqvHaYBjK8QQKppPPLrfwTtjX3oc/hfQbjd+Izyu7r9W3R0VnWWpfTDAJyNTNsTAel6Z8z38/aSZZCrbIOd/2IqL0jrrfe9ChiMOKPnm8lEtO5kcshBpigubTHOAINue5oCmc/3PcxgieOTFfCuOmg+RH0MuxhcJUsVm/ampoRbxEFq7tWKg7qGYIVhIfT1Jb+FivLbKlmioN/H4kNFehBVCKNS9LKjzLWNBvUMSmWSDbSbksXgftX4tNUesOyQTjVzUdm793RlzSxG3sQ4MfcnExJslkcYWGV5xXhSMNOJGJQ== 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=zGBoX46GEwVxp49l1OKu7+S0xbj6faopuERfQ6HizIk=; b=GgvJN/AQB/XJ/ziYABbaJpX1rKhpKpcpppBAhKwarKdAhbcJPVu/oYIatGqJ59tfM1Sxw/qX1jSV7sq8RXsHgBtdCF1z6DLgQIifwsS3GEBsuDZIesnHRLkkxXE4ksqmrmvu+0u4Ez8mkwrYGIWWOJnwurB1GjQBCY+3pVkoE0lYJ9QILSzof/v560DvRKf0WLJvhHiF1HqrTU2MEUNGsoBak00s0oLhrsDi1GA8PxgmpsMUdiYWpWXTgkOGzT7pBGxosYgWtmUYNxas0g2VK/7h0Ec7DZnUiARN77Uv6SOObio05QWLXR6BJTwN916XDWzhu2Qcw503bYpiC9rnkA== 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 04/10] iommu/arm-smmu-v3: Add types for each level of the 2 level stream table Date: Mon, 10 Jun 2024 21:31:13 -0300 Message-ID: <4-v2-318ed5f6983b+198f-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v2-318ed5f6983b+198f-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR18CA0015.namprd18.prod.outlook.com (2603:10b6:208:23c::20) 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: e27f5516-5a93-4a06-a931-08dc89add18c 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: /8bVC7BgDfG7PBkdqKuxKftyEOY/D0yjpUx6ZD/o62/mP8feo1usddaiXJmrAjrYN4yAoGsVsQF3sq9Yc57QLCwntEgPPCxpmxp6aB1cRPaVCSXENmkousoZBzV/34ciTRK0+yx3jcg4J11j6yEiWLBWWxVHu8eOb5C2JzRIv9332mVHsRPk3O+ooMskGr0uRtcHEgstMaBPM8jCIRo21/SXeNMrbvFb6yxtTp4LNjFoTDGTyquUaJassjniNNUhVZLe6CvAOKSs98zF1mJdFCySOqo0lfAtC4X/xga30dLA2Q3Ybr/hFooAVDR3hFnSCRT2g63vQf+8QoQerSICgq6n7/Z1+omv0Xah6dddZ+sRyO9cgUWNeMX5w2Jn3FlQGTJRHMM4RFxhcAsNgF5hSlbPBJ7JrzVoI6FIr47dKLqAf3kJo8fysVBAOB4hfgGG4+XpDbgtzRxg+3A1Tm/GCqkBNtA1B3lIPzUbMsVNaiNqe5rRrqC5NWSEZYEh9/iMTuiwic1I0G2TDcxWGR2CfW/vfvcl5bU9BgSZcUrlWxg9vV0b76xNWeQLZw4MqpkSTuH/gpY6Z3VHlLQfn3hHB/au0Ffj/eBmhpWzN5Bte8L3bL7j9B1YGwCWUDSp9M+7IWPT+GmW0TEQBYVU4D82/kX8H/EJ6vbuQbP2qDLsDR5oMb63sJ+yruRjGmUiBjJ0jcHjBMMINw4H6K/IQQMPHMyDZ5MG/NK3m5HcjdGWlogkOe5Qy1lCgboxmnl9vwchSp2QUTDuccldp+zzXeN9n+35+n6ikOEhVXDRudsKGPc6rd5nrsJmdQo+SxuMFdRqelD6C9UsqDSkbvFbglnJ9IpcCL0DERMeAQV+ysNylvUUD3A/8h9gt32xpsSbVZvrV9AXutgHh01vH0PgoSwttx+t1P63ADiZqkEkRSWME+m0j4qdZACEnNktwkDtYwcBnxIZPCmTbaTvaJtB7sxmrHQ8YEeY9gpKu5UaBp4nxjZD77g18v0tp8O2KrUcJ4LCnOLWyKJf+rCHYdEdVmw5v/mLNdruJ5/JTZKHR0Vb5dGm/pQZmSczdupoVF1uIpmkyC7p683TN0btHrtmD/f52lRsmnwHWu2xaQ3qbEW0znbzwewziCr1aReL224XRrBnB82EHg5MoNwEzMj5yvNhS25PZg2ehvmfIPXQ2FFzqTrvX6Pwk6HznKJgd6FuulJqSwY6T7CqESvbRh6tymewHgDAcMl+NUN8j6005uh9sivs2A8FI6M7c9cRTXFwAfYa5hsiWoL8N8j2oUqzyZWrXhz/9OItq8n2IKSdCiVqfL/0xDEethYhavR1lV5xXUY4 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)(1800799015)(366007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fjnHJmLq7fZNAJZLkWYJktP5SjXXTK84t2N4Xlp/VHTfmbQZlfjn3qE0ffwxx0e3PqzbQv69Rn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omMQ7R6Wr36Qmf6+95lTJjD0h9Px05aqiUhqgwqruNANgHGvbuWIoPLHsPq6Cxq8NcFMrDcGwwYFdpL2RWv6R6lRSSIEc7Vxpyu8cc0YRtGyJXq4C58o+5Oq2rUGxilhJDlt+UBXUb7AdV1GIEfI8lBgVIoyNi+mbYlbiCW9m8eQFJmXVw5RvTpZxbOQzQqbDAAEx0AfhIs3CZvkOvNhbKDstmrh1j+GWW+P4038LCaMXSe/tjdhflXmMtTZ8Ub16IDGpMgo6o7r2auxqEjg75kiARv0GLN0s3OBcDFxE7wH6+TRpOuhwSTKPabwnnfhV8iftvJpJETqdXCGBVx7jYtYZ/Mb6bhYr1CChk39L81eitcxE6kB67wuY/Wv9FtM32LJKtv7miQZ8w4= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e27f5516-5a93-4a06-a931-08dc89add18c 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.8763 (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: IeDmoA27rwN2kfFm1xxAy9+U6rUW73ud4Ek2Sa8FmylKg8X97CzEuRKj+xP02yio X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN6PR12MB8565 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240610_173137_648927_AEBDFCA3 X-CRM114-Status: GOOD ( 13.74 ) 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 Add types struct arm_smmu_strtab_l1 and l2 to represent the HW layout of the descriptors, and use them in most places, following patches will get the remaing places. The size of the l1 and l2 HW allocations are sizeof(struct arm_smmu_strtab_l1/2). This provides some more clarity than having raw __le64 *'s and sizes computed via macros. Remove STRTAB_L1_DESC_DWORDS. Signed-off-by: Jason Gunthorpe Reviewed-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 22 +++++++++++---------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 10 ++++++++-- 2 files changed, 20 insertions(+), 12 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 07b797ad832801..6643594121a2b2 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1447,7 +1447,8 @@ bool arm_smmu_free_asid(struct arm_smmu_ctx_desc *cd) } /* Stream table manipulation functions */ -static void arm_smmu_write_strtab_l1_desc(__le64 *dst, dma_addr_t l2ptr_dma) +static void arm_smmu_write_strtab_l1_desc(struct arm_smmu_strtab_l1 *dst, + dma_addr_t l2ptr_dma) { u64 val = 0; @@ -1455,7 +1456,7 @@ static void arm_smmu_write_strtab_l1_desc(__le64 *dst, dma_addr_t l2ptr_dma) val |= l2ptr_dma & STRTAB_L1_DESC_L2PTR_MASK; /* The HW has 64 bit atomicity with stores to the L2 STE table */ - WRITE_ONCE(*dst, cpu_to_le64(val)); + WRITE_ONCE(dst->l2ptr, cpu_to_le64(val)); } struct arm_smmu_ste_writer { @@ -1660,9 +1661,8 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) if (desc->l2ptr) return 0; - desc->l2ptr = dmam_alloc_coherent( - smmu->dev, STRTAB_NUM_L2_STES * sizeof(struct arm_smmu_ste), - &l2ptr_dma, GFP_KERNEL); + desc->l2ptr = dmam_alloc_coherent(smmu->dev, sizeof(*desc->l2ptr), + &l2ptr_dma, GFP_KERNEL); if (!desc->l2ptr) { dev_err(smmu->dev, "failed to allocate l2 stream table for SID %u\n", @@ -1670,9 +1670,11 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) return -ENOMEM; } - arm_smmu_init_initial_stes(desc->l2ptr, STRTAB_NUM_L2_STES); - arm_smmu_write_strtab_l1_desc(&cfg->strtab[arm_smmu_strtab_l1_idx(sid)], - l2ptr_dma); + arm_smmu_init_initial_stes(desc->l2ptr->stes, STRTAB_NUM_L2_STES); + arm_smmu_write_strtab_l1_desc( + (struct arm_smmu_strtab_l1 *)&cfg + ->strtab[arm_smmu_strtab_l1_idx(sid)], + l2ptr_dma); return 0; } @@ -2411,7 +2413,7 @@ arm_smmu_get_step_for_sid(struct arm_smmu_device *smmu, u32 sid) if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) { /* Two-level walk */ return &cfg->l1_desc[arm_smmu_strtab_l1_idx(sid)] - .l2ptr[arm_smmu_strtab_l2_idx(sid)]; + .l2ptr->stes[arm_smmu_strtab_l2_idx(sid)]; } else { /* Simple linear lookup */ return (struct arm_smmu_ste *)&cfg @@ -3224,7 +3226,7 @@ static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) cfg->num_l1_ents * STRTAB_NUM_L2_STES, 1 << smmu->sid_bits); - l1size = cfg->num_l1_ents * (STRTAB_L1_DESC_DWORDS << 3); + l1size = cfg->num_l1_ents * sizeof(struct arm_smmu_strtab_l1); strtab = dmam_alloc_coherent(smmu->dev, l1size, &cfg->strtab_dma, GFP_KERNEL); if (!strtab) { diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 95c3ac8613da79..1418f21f5db6a0 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -201,7 +201,6 @@ */ #define STRTAB_SPLIT 8 -#define STRTAB_L1_DESC_DWORDS 1 #define STRTAB_L1_DESC_SPAN GENMASK_ULL(4, 0) #define STRTAB_L1_DESC_L2PTR_MASK GENMASK_ULL(51, 6) @@ -212,6 +211,13 @@ struct arm_smmu_ste { }; #define STRTAB_NUM_L2_STES (1 << STRTAB_SPLIT) +struct arm_smmu_strtab_l2 { + struct arm_smmu_ste stes[STRTAB_NUM_L2_STES]; +}; + +struct arm_smmu_strtab_l1 { + __le64 l2ptr; +}; #define STRTAB_MAX_L1_ENTRIES (1 << 17) static inline unsigned int arm_smmu_strtab_l1_idx(unsigned int sid) @@ -591,7 +597,7 @@ struct arm_smmu_priq { /* High-level stream table and context descriptor structures */ struct arm_smmu_strtab_l1_desc { - struct arm_smmu_ste *l2ptr; + struct arm_smmu_strtab_l2 *l2ptr; }; struct arm_smmu_ctx_desc { From patchwork Tue Jun 11 00:31: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: 13692719 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 8C379C27C4F for ; Tue, 11 Jun 2024 00:32:25 +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=tWtWad7eCq1+3rh6P1i3iNGOo8Ws0Z8Y7KcmO7ukkkU=; b=1ONiD8a5CKQ71M Htw1Zy/GHPMZbSwRmDZpTmvtUsooKghkbZlJZPCorZ/jCKi7CaElNEEFqF0KMk9wx9jmRPnm8NXF1 1ricXWePmS8TNwD4KfZPQHmAaZv6tRkbdNKEpA1YTxapT1qi1fjmrmKQVaNtVrLuFh3+tcF9Ucmnz gglj2B8mNG7BCBM38ZWafIwSrNh0PNEj+3GPdHOAEW9epIBTs9Xiv1xSGi1CeChDjtDetO4yP0KQI visBLcHuSz2gBWQ+kfYEujjmAmn+STJ2CXaagrsHQ3J4WrM5gk+5BD31ojpO9xfegwi7PD1hAwA2o 9Tbi2mhHPn8hJVmnUb1w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sGpQn-00000006yj6-3P2i; Tue, 11 Jun 2024 00:32:09 +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 1sGpQJ-00000006yMq-20TU for linux-arm-kernel@lists.infradead.org; Tue, 11 Jun 2024 00:31:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aqXqUh/POHvOl8hXU6P4WBVf/KpV8ufp15PG3iRHskfHtKbNhUg+vNeAofdwRyROLhhxrY+s9i5uSR5F9E3jduGPn7mTzw5aCGxxZcGyJj/yF3hwMn57XHEuiZ8+uSdBQFV7zCulDg7grpuDID+41AVVeDJsbJ8WtCAa96LjzUehrAigVcAJSKQhbeJ9xA2rgTiHq6gsz7nm3CoUzlYhPiRecyHEtIk1tNJIodAxEfuadDUBOH6Ctv48NMLz5ndRQSVohX7KlnT9Q0emgECKSzH/a8QqwXwbSVKlhURIsE16T+FXuLsxVvBk6sA1wDZVwP9OAPOTEmHBqtdtaBQjkg== 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=fqfhfdFL/+MaeVlul3bkxBoIl3Eo/WKDwW3y5rvA6Pk=; b=P3n6+ka7ZwvaqZBr5XfEyyiXLDRAcqTPwCTQxj13bwy/xw6b4poSKsJbxiO9y/Wb8H1XvPbjCufQauZtiVtlXSjhOeSqwv5tcg/ikgnLJD3by093OJwQzclnKaU1gPdh7OysL0fkDzz8HRMFxTXLxFHpb6na4h5ONHBI8UHmjjOXDCu0WoYzP3uX5sxVKDs7k211XKAHMGS0AeCQZbYykzqX1v76TqaDSXQUYnn5CDF4l63z9v0fn0ST/GivHQMun/W79M1Lfc4DCw3+KqLy53m673fuPXuHeBWreabCpb+7qPIM8z9L9+0wYcRopVJLYwcmt/h+UwNwfAmQXlrw7g== 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=fqfhfdFL/+MaeVlul3bkxBoIl3Eo/WKDwW3y5rvA6Pk=; b=UiMcxh0dxmVNC36VT9oedw2a6vHKeSKp/Zbn2kdPcGwx1no1+2nS7VKDJPPdtUo4zZ/ARsiaYVQpRHzDW0ZtXI3e9AqFZ0+Xb28x7BiOFy3Uqk0Ga8CUKcHAw5Aqz7RGfo/UDjnUpRvcRQZac4aRISxuwgMxlWzyabvLRl5EH+AA3XO9mGbYZqShlgD4E+9wsgJvysYVNOoz0IjKxsj2ro6jViKsC9UMQzPqRjWtuYYAuP+WcVA4DHzVsdRVV793ORBSRSQ9OFaQzC4BmuIsuGCHjPZ473lBpqGdZM6dmAorjs80Pri0eUZm95F/oPXWtQj6hJyCzZsLgqUampk5YQ== 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:26 +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:26 +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 05/10] iommu/arm-smmu-v3: Reorganize struct arm_smmu_strtab_cfg Date: Mon, 10 Jun 2024 21:31:14 -0300 Message-ID: <5-v2-318ed5f6983b+198f-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v2-318ed5f6983b+198f-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR16CA0044.namprd16.prod.outlook.com (2603:10b6:208:234::13) 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: 4552bb12-76ef-413a-6ef5-08dc89add22d 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: mpESTBqyQ3d7F6CMlmQrQzalqI6hi++dvvm6mcn5whFgO+qmQHXNnH68qwAQOVRQgSSJPqst1+GfZsn5CGc4KHJM7T/+0jdaHQXx6V4CCYHzrwhlLAXjAnnToyCxKBDds30PmymLsGYtZQPbX+W+BlcsHgEEaQW/nrlZ+0Qqh2XVj55ya4lyJdquaxZrkn+ApNKrE2gEJVUcL8ViJc6nV95/W89AD/sGR5S7jQFIVUo/amdGpjH/FluvzFW2oBLLd59GNhAsu6NKdOh0bJ7/DJbwYf1FDZYeSsdXFaQnNzfxputEdHPLW8GQ1vUE9WPXgPlEHZxlapRSXrD9avO17RV/Iyf5f2BNZJanHz9U4FM0cB8ABD34RYmurR+whfqcCPajUC5yvn4NafsctzAX0TzkYFuZBAIY72RJQJIoRgpPibA88wEOdUlNfpKaOU8mAUFva2LK2GB4Y1ffPDg36jmPIVM2sn3HHbc8xCGHCw/NwYVZODgaeio5f3AGaCtHubqlATpDEvN5JNU2nNdlVr408MfMZPPawnszjVb3O1dnXp2SNkTzTlXiyzJyxGZLZxzeLdf2IAV5Q3cA0Pk/NLJjtgli+Xg7+F1mgJo+PpZRUUc906xsLAUio5g/lxV2o+8xECT7Lc+TCwhM7VmhD0HiY7GDH/TZZvGJk5k7EPHacXVLJTFIm/TAxK3dyN5UGKVgGQeF7TEOjjbgum8PUzNklMXLFMHF06UFKZhxAffZW68nydWQkYicqtse3HGsBw++b57NSN79VGzaIQ2na+tihYLRlqjVhaFLhmGld6iFzcaUHGbDb59NpiYSS5ygF3+azide7hjMg8gHpQiMYAajUdSJHxnR5Gt91YoEjkIUolQkS/SPKMvq/gFyp29ElM2Gpu+AD4YJE8ZRszW4OZsmOu+ipE0xCvSxvc4+fi1KImdrEycQZuUy3ACgvL/GjDM1J3P/MSpNqPz3+HTOZyYFH6hLaq4Srmu+kK+eovhQDYt4NvWArHaVakJAh7pFxxK0kUI0sXfZijUR64i0S6ouvCWbEeg29Q8B5Jcbmq+UA61iFNvC+FT3Y5mRnViUzoiHk52+9d58R0cNsswqvdIL/lVhRm70C+YWAcS3u5i7CCc/OvwsXGuzpuRnmex2Q1QOdBVsIMWyG2tIVOJ2KAxrujAIzlt3YphDccEYC1oHS6cATcyanX7lTvAP5jV8MSrWlNAdmp7WtyKB3gxv9DH3ZRc98mLKN8VnFg8vF0ATeZe3CS2+/3lVq/fa1bzp3d2hDXbrvQ8vPHODs9mKSvkrZew09AKxz1RYTDVDTqwWFmh5xEjASGeOIsYmRAAd 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)(1800799015)(366007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XXfuXikb7op7w/YIxwUytKHmJ5FH2tc2P730Cs+0MNbDOnTMlMBklnNPhCMFc1wPDbTRKxkYRgToLbuXApn1FwmOUGChsAuGAfehI2i+6H29f3W7K8OKyjCct2V+xh7LcNXdxLneIIsatnC87mu+4/uKlIYWv5gMXEkYpe10KZLc6h758ffSleiePVZCWJbOqtZ9CKqVIS1iatD7h0gFq631B82bvtcZG9hdfJBnCAlhC61IYUtjT488i1oUcZmwrn50CQwc41Nh956f2XXIhiPegLQB1YeD9jZNIlBMXQ/ombpBGY+eq4IHqP5nuEm1DVMESrd7p/Xhn2shxv4ozF2HjdS70j7ybQ6w1PM7ILMvmTSKWHIlB08PTnSDF4QXdsUSvip7A3k/8q5XBvm4ZonH1ify5WxyJN32hOWGmzQFGDCJVZwcnQF2EQMlbDT2BDAgrDk1E31aOrpkji419mxufIdERM1Ocu5+AnCNy5nW7cxp9ipi24F4sm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MS-Exchange-CrossTenant-Network-Message-Id: 4552bb12-76ef-413a-6ef5-08dc89add22d 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:23.0592 (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: DvZ13pz8ego4JL+9oN4LB4b8z8QT6wstV3bqlBW2u8TMawwYQ7s+i1hbjYIIsegB X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN6PR12MB8565 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240610_173139_658363_C01D663E X-CRM114-Status: GOOD ( 15.42 ) 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 The members here are being used for both the linear and the 2 level case, with the meaning of each item slightly different in the two cases. Split it into a clean union where both cases have their own struct with their own logical names and correct types. Adjust all the users to detect linear/2lvl and use the right sub structure and types consistently. Remove STRTAB_STE_DWORDS by changing the last places to use sizeof(struct arm_smmu_ste). Signed-off-by: Jason Gunthorpe Reviewed-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 79 ++++++++++----------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 26 +++---- 2 files changed, 51 insertions(+), 54 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 6643594121a2b2..21e0438d09b26e 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1655,26 +1655,25 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid) { dma_addr_t l2ptr_dma; struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; - struct arm_smmu_strtab_l1_desc *desc = - &cfg->l1_desc[arm_smmu_strtab_l1_idx(sid)]; + struct arm_smmu_strtab_l2 **l2table = + &cfg->l2.l2ptrs[arm_smmu_strtab_l1_idx(sid)]; - if (desc->l2ptr) + if (*l2table) return 0; - desc->l2ptr = dmam_alloc_coherent(smmu->dev, sizeof(*desc->l2ptr), - &l2ptr_dma, GFP_KERNEL); - if (!desc->l2ptr) { + *l2table = dmam_alloc_coherent(smmu->dev, sizeof(**l2table), + &l2ptr_dma, GFP_KERNEL); + if (!*l2table) { dev_err(smmu->dev, "failed to allocate l2 stream table for SID %u\n", sid); return -ENOMEM; } - arm_smmu_init_initial_stes(desc->l2ptr->stes, STRTAB_NUM_L2_STES); + arm_smmu_init_initial_stes((*l2table)->stes, + ARRAY_SIZE((*l2table)->stes)); arm_smmu_write_strtab_l1_desc( - (struct arm_smmu_strtab_l1 *)&cfg - ->strtab[arm_smmu_strtab_l1_idx(sid)], - l2ptr_dma); + &cfg->l2.l1tab[arm_smmu_strtab_l1_idx(sid)], l2ptr_dma); return 0; } @@ -2412,12 +2411,11 @@ arm_smmu_get_step_for_sid(struct arm_smmu_device *smmu, u32 sid) if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) { /* Two-level walk */ - return &cfg->l1_desc[arm_smmu_strtab_l1_idx(sid)] - .l2ptr->stes[arm_smmu_strtab_l2_idx(sid)]; + return &cfg->l2.l2ptrs[arm_smmu_strtab_l1_idx(sid)] + ->stes[arm_smmu_strtab_l2_idx(sid)]; } else { /* Simple linear lookup */ - return (struct arm_smmu_ste *)&cfg - ->strtab[sid * STRTAB_STE_DWORDS]; + return &cfg->linear.table[sid]; } } @@ -2791,8 +2789,8 @@ static bool arm_smmu_sid_in_range(struct arm_smmu_device *smmu, u32 sid) { if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) return arm_smmu_strtab_l1_idx(sid) < - smmu->strtab_cfg.num_l1_ents; - return sid < smmu->strtab_cfg.num_l1_ents; + smmu->strtab_cfg.l2.num_l1_ents; + return sid < smmu->strtab_cfg.linear.num_ents; } static int arm_smmu_init_sid_strtab(struct arm_smmu_device *smmu, u32 sid) @@ -3211,7 +3209,6 @@ static int arm_smmu_init_queues(struct arm_smmu_device *smmu) static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) { - void *strtab; u64 reg; u32 l1size; struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; @@ -3219,37 +3216,36 @@ static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) arm_smmu_strtab_l1_idx((1 << smmu->sid_bits) - 1); /* Calculate the L1 size, capped to the SIDSIZE. */ - cfg->num_l1_ents = min(last_sid_idx + 1, STRTAB_MAX_L1_ENTRIES); - if (cfg->num_l1_ents <= last_sid_idx) + cfg->l2.num_l1_ents = min(last_sid_idx + 1, STRTAB_MAX_L1_ENTRIES); + if (cfg->l2.num_l1_ents <= last_sid_idx) dev_warn(smmu->dev, "2-level strtab only covers %u/%u of SIDs\n", - cfg->num_l1_ents * STRTAB_NUM_L2_STES, + cfg->l2.num_l1_ents * STRTAB_NUM_L2_STES, 1 << smmu->sid_bits); - l1size = cfg->num_l1_ents * sizeof(struct arm_smmu_strtab_l1); - strtab = dmam_alloc_coherent(smmu->dev, l1size, &cfg->strtab_dma, - GFP_KERNEL); - if (!strtab) { + l1size = cfg->l2.num_l1_ents * sizeof(struct arm_smmu_strtab_l1); + cfg->l2.l1tab = dmam_alloc_coherent(smmu->dev, l1size, &cfg->l2.l1_dma, + GFP_KERNEL); + if (!cfg->l2.l1tab) { dev_err(smmu->dev, "failed to allocate l1 stream table (%u bytes)\n", l1size); return -ENOMEM; } - cfg->strtab = strtab; /* Configure strtab_base_cfg for 2 levels */ reg = FIELD_PREP(STRTAB_BASE_CFG_FMT, STRTAB_BASE_CFG_FMT_2LVL); reg |= FIELD_PREP(STRTAB_BASE_CFG_LOG2SIZE, - ilog2(cfg->num_l1_ents) + STRTAB_SPLIT); + ilog2(cfg->l2.num_l1_ents) + STRTAB_SPLIT); reg |= FIELD_PREP(STRTAB_BASE_CFG_SPLIT, STRTAB_SPLIT); cfg->strtab_base_cfg = reg; - cfg->l1_desc = devm_kcalloc(smmu->dev, cfg->num_l1_ents, - sizeof(*cfg->l1_desc), GFP_KERNEL); - if (!cfg->l1_desc) { + cfg->l2.l2ptrs = devm_kcalloc(smmu->dev, cfg->l2.num_l1_ents, + sizeof(*cfg->l2.l2ptrs), GFP_KERNEL); + if (!cfg->l2.l2ptrs) { dev_err(smmu->dev, "failed to allocate l1 stream table (%zu bytes)\n", - cfg->num_l1_ents * sizeof(*cfg->l1_desc)); + cfg->l2.num_l1_ents * sizeof(*cfg->l2.l2ptrs)); return -ENOMEM; } return 0; @@ -3257,29 +3253,27 @@ static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) static int arm_smmu_init_strtab_linear(struct arm_smmu_device *smmu) { - void *strtab; u64 reg; u32 size; struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; - size = (1 << smmu->sid_bits) * (STRTAB_STE_DWORDS << 3); - strtab = dmam_alloc_coherent(smmu->dev, size, &cfg->strtab_dma, - GFP_KERNEL); - if (!strtab) { + size = (1 << smmu->sid_bits) * sizeof(struct arm_smmu_ste); + cfg->linear.table = dmam_alloc_coherent( + smmu->dev, size, &cfg->linear.ste_dma, GFP_KERNEL); + if (!cfg->linear.table) { dev_err(smmu->dev, "failed to allocate linear stream table (%u bytes)\n", size); return -ENOMEM; } - cfg->strtab = strtab; - cfg->num_l1_ents = 1 << smmu->sid_bits; + cfg->linear.num_ents = 1 << smmu->sid_bits; /* Configure strtab_base_cfg for a linear table covering all SIDs */ reg = FIELD_PREP(STRTAB_BASE_CFG_FMT, STRTAB_BASE_CFG_FMT_LINEAR); reg |= FIELD_PREP(STRTAB_BASE_CFG_LOG2SIZE, smmu->sid_bits); cfg->strtab_base_cfg = reg; - arm_smmu_init_initial_stes(strtab, cfg->num_l1_ents); + arm_smmu_init_initial_stes(cfg->linear.table, cfg->linear.num_ents); return 0; } @@ -3288,16 +3282,17 @@ static int arm_smmu_init_strtab(struct arm_smmu_device *smmu) u64 reg; int ret; - if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) + if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) { ret = arm_smmu_init_strtab_2lvl(smmu); - else + reg = smmu->strtab_cfg.l2.l1_dma & STRTAB_BASE_ADDR_MASK; + } else { ret = arm_smmu_init_strtab_linear(smmu); - + reg = smmu->strtab_cfg.linear.ste_dma & STRTAB_BASE_ADDR_MASK; + } if (ret) return ret; /* Set the strtab base address */ - reg = smmu->strtab_cfg.strtab_dma & STRTAB_BASE_ADDR_MASK; reg |= STRTAB_BASE_RA; smmu->strtab_cfg.strtab_base = reg; diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 1418f21f5db6a0..8b58a30ebeb06b 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -204,10 +204,8 @@ #define STRTAB_L1_DESC_SPAN GENMASK_ULL(4, 0) #define STRTAB_L1_DESC_L2PTR_MASK GENMASK_ULL(51, 6) -#define STRTAB_STE_DWORDS 8 - struct arm_smmu_ste { - __le64 data[STRTAB_STE_DWORDS]; + __le64 data[8]; }; #define STRTAB_NUM_L2_STES (1 << STRTAB_SPLIT) @@ -596,10 +594,6 @@ struct arm_smmu_priq { }; /* High-level stream table and context descriptor structures */ -struct arm_smmu_strtab_l1_desc { - struct arm_smmu_strtab_l2 *l2ptr; -}; - struct arm_smmu_ctx_desc { u16 asid; @@ -627,11 +621,19 @@ struct arm_smmu_s2_cfg { }; struct arm_smmu_strtab_cfg { - __le64 *strtab; - dma_addr_t strtab_dma; - struct arm_smmu_strtab_l1_desc *l1_desc; - unsigned int num_l1_ents; - + union { + struct { + struct arm_smmu_ste *table; + dma_addr_t ste_dma; + unsigned int num_ents; + } linear; + struct { + struct arm_smmu_strtab_l1 *l1tab; + struct arm_smmu_strtab_l2 **l2ptrs; + dma_addr_t l1_dma; + unsigned int num_l1_ents; + } l2; + }; u64 strtab_base; u32 strtab_base_cfg; }; From patchwork Tue Jun 11 00:31:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13692720 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 3DE50C27C4F for ; Tue, 11 Jun 2024 00:32:29 +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=wphL4k2KU34y3tmvOt5XMyYVKXu3VwVacVGhq329w1c=; b=uGMshEUv51+FS6 ovHq7uN6I3jZfZTXvMfGedFJGESMhkrqTeqkC/LgJxN/R+sHUTVHPTD80mHP0/zb1MXOPHuLSGE5Y 2Ru1IzLnY401eQ5kQOjSFH1wOrFV8fiad0mE0Xj9vFyDKQqif3aqMfQWCY831sCtBB8JgfbAdg9YO LiE0LlXVD6LL5wahQpiSWljmayUpNU553vdHXvmqLbVXF8QR3HHbco21YpWLoRjGoKxDlMHHGr6LA M3vgkqSGCmuUBNWonzpvOe7t6w8e9tJkB/Z+LzBrBazPSsBu6xv43OUan6793LrAQH0n6KFlJN3fg x1HUi/4hG2sNW6Wd54YQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sGpQt-00000006ylR-0bEj; Tue, 11 Jun 2024 00:32:15 +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 1sGpQO-00000006yMq-1LP7 for linux-arm-kernel@lists.infradead.org; Tue, 11 Jun 2024 00:31:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hoOt9pbqOnq3wH39swlqVpNmY5M0lQetRirVWhMjPy3FxkRrQJg0kTGmtKqlSFqUZPdCCpaiXnVmXssn/h2RUCQi62b6NYdqXksXLfLFcOeV2QCKysR/tnHcN/cqpZhCv/w7x60npoRLswRZHv517vVIarNO46Uy+WmD+sr/Mnt8N8Ah5A6vvTWxSPOtwkL+XqxdzsWZsQKgFwFZhvXpxS8TP7P1k1LN+rxxA6xtWg+4ibQUHtbZy8qzFWUqbx1C1LhfVDBOR6D/JVaPG5bwdB6mBxoC7OEjO+RlE+2B8tPpIkANhKScmoIWc5mIWdjmk9TjoqlthrMWXa2P7jrDQg== 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=W5zqR40rOkpCjeTfCaaimehSVUJMapkYGghvu+9wuKU=; b=jphkGif1/IpBv8GwFaWd5WJIrebixXStyIltsyKr74bvjbNdpHXATLRLNOKDxfRuLAjHIUqGfwoN6C+IEzsMhlqG5R89p/IUowF6/1cXBV8sMqOhzmRYfJRLNlhNqaaKk5x2FF7/bUy+PyVShmoyeczWehgFGpA8e7YFDi5ALiAmgdpQWGnV447qfUInWl/EXl5SzoDQ36K9QQIQFPQF7g4BIRiuO97mTscV27BBEQnLivH5y9ZvAmyEw5fHUIWIzwzxuJao/ZQ/JypEHZ5av+ikP/64+74eXH5hvOGsaeQvZz2R/VC2HGEvME8qHsDkoJ3AKUVeaVnkzPcP+L9UOw== 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=W5zqR40rOkpCjeTfCaaimehSVUJMapkYGghvu+9wuKU=; b=XdBLHuPivrcs06p8QiNJCiX+NqYl+kByfxnsk+lDuFjLr+xWepD6p6QfKfPMsW24Ltzu6YT/ILWIusx1tXzjhTi1faf6rYmfwcLdQb5zSjzgWc3nmmyaESqAmRUudMTFzR53AeNI0q066N/0L3TpyBBcTh7FRPfsgkZj8SmVucwyBxOn3nwoHdpgsGK94GFMGZgrAFrWymtJKEV4gEAl7gbh3rq7hZ/Z4MLZgBf5gtrXXdvsO7YL2TU2jXjTkxuL14gJEYrPjeMd3/B5kljDKeGwbPPDRY5vD+SRhSe9LOcN/jg5qKLgKfkqR2IOa5vw/0CNFJFdNV0KItkJxiy4GQ== 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:27 +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:27 +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 06/10] iommu/arm-smmu-v3: Remove strtab_base/cfg Date: Mon, 10 Jun 2024 21:31:15 -0300 Message-ID: <6-v2-318ed5f6983b+198f-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v2-318ed5f6983b+198f-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR16CA0058.namprd16.prod.outlook.com (2603:10b6:208:234::27) 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: 59295e99-40de-407d-4aa4-08dc89add263 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: +iL0QyQq5CqwBBZfxvWhzHCJ0uAjS1O1t1nprnId74tOZKvh01sr2JkVnGtmJfQzpzTXFyPi2DvrqPxw2iv+B2l3gih/Wak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Rjs0PGe20cvhEJPPEdDbMtRth6qpO6DymwnI7A3krhhpDLf6O3okdHCfzID/AfRdbbad9GIVAd9HiX6/zYHrHkndblLwo18A8xqpLjGYptGVPYpBsjntUPQP6pAkFn9u/7YVEW/EAAS1ZVJKF/gXBPI5B65oQFYXcs 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)(1800799015)(366007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: z4MrDX1323n+tqfBlZhoKsbHWJQ9R0hWFD/W7ie/FKxVNgfxhRm/FByfg3lV0xpsnB29mR7dRCrBvicYeSqdHSDXLnT4i4sLSoXhm9B5OywvtiO/9q7pdYPY4saT4gNDBrIGMOcfYWFd3Mzf2k4A6CPEmRsRnj58N4VniBQe93V2+x9xNPKCZKmoyGPxRr+XriNhuBkwJm0fJ+e80Z349+LQnpaLP/f9bEHClWgeewCCjpzJqs6XeIhesjNGNky4MgNNqcQaXuaaulqEPbBT7iOkyLvZETkrcyahAQ+B3D9cJNIszHjyETHjU6fAZqtaZ8+GCv1jr55dIglWARs6616dLJMNsm0X+tf+GphdyiKiVzgj87FASN/1+ur7A3BBrsbB7PKb6CyGnjxRAQSqn55COVoFes0OfYIC4+Gl7eAFSjwc7KV/KepmYMlrFZjr6R8fymSYZ/LKyHulls2vQxKN3SZb2RTLlIZ5zDAPtROICpJjZ81q3WuJAHBBA6eZtmn/GONQ8t+tBfk0gRvEdHCH6UAXAnS1mqXwEAC9VOlB1e9pSRMR+8LYGqex+4BxzCNBEgOqyDpfjrPvqMGMKEuGA9/aNJIVFKxtXsf2MJwmt3wg82t9OYO5RgHfobCkY4jVFlytoxCcH9f047FTIuZPUU2bw5ljDttI8Rvg5IOy2P0hjlB0lA9ceStYcm0U3bU2ARurmjCTSAmDIThtTRITMLFZDt/3BIVnXyoBO0PLsIiJ15HmARQAcI1qmtl8Ld58+7UsmzmbFT4Fz5ugGSuHiBPgGpvhzm7wujHwzeDUbm9RRWEr9NfU/qghbSUyrjo/IpudFbClTTNZUBMypI5xYH9aZhwCdZZZyoSUq90PAPtLeMgDPfx8iTSFeCa+/J2IadaO5JjY8lE+YZ2au7K869oVQruTpH3BU6W4+YzHa/uGN7vRh/ZCR/vX2ffkB1pi2gvO7BxJr6TRGVTvKr0N/p5bLwombQaZrRj+ubVFFyL757EzQ7dOFBKFOSfId4C/s+7UYZKE5ElDN/OkTz/hCuqHzEKivW0bjNc5Q7WqURcvJjVtCycfD/g812ACWMFLrjEA78WqMwquwkqBgob4t+192/UyLBYy8/ZBNU33PlDzl0J4JpdpSH9MMZDHv0pLU43keqdWacT6bvQSQCih5wLGFCVN6/RfCjSSR5NwOtOEk9WyulS36ZhUfICSGynLbepXA+GJwtvHDD5IBnxCul+zDQTeSBnFaA/6tXVvorHTaEYBkq3xB6WE6CD2Cx5q5E6ivtjCaGYsDkKclI86psOnTyu0ha9KuIhns0FcVz/Bta/0fAnD3/BmruyV9aWVHEaBtgEp7i/mUlzi/YfF7USKaUMHxMPAgp/H1Qgh6zJzUSQRt6ApP9J7n3kz3BAs2sHn2CCLL3pUhFOdoTR8l97leye/lB2joSHy0qdeXtlrhcYXKrQbhq1JCulYPgnSXmpa6aoX09vSO2XBTCS7luE7jcPvEVXKaIN0OBxK37f3yykiX2ozCttPS5Dy4LZMaXHbItxc6h6RrEG/Jm4WOczRr+Z+IZIv4W6FZvU= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 59295e99-40de-407d-4aa4-08dc89add263 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:24.5452 (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: 8hPnf8XpN7Wb2XCLPr5Jlf+/YUFH3XT8aL0qrVGiTWTIQyXY6yHUQV4dPvSlloN/ X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN6PR12MB8565 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240610_173144_475074_EF87C897 X-CRM114-Status: GOOD ( 14.47 ) 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 These values can be computed from the other values already stored in the config. Move the calculation to arm_smmu_write_strtab() and do it directly before writing the registers. This moves all the logic to calculate the two registers into one function from three and saves an unimportant 16 bytes from the arm_smmu_device. Suggested-by: Nicolin Chen Signed-off-by: Jason Gunthorpe Reviewed-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 55 ++++++++++----------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 - 2 files changed, 27 insertions(+), 30 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 21e0438d09b26e..b36bf6bed67d5f 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3209,7 +3209,6 @@ static int arm_smmu_init_queues(struct arm_smmu_device *smmu) static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) { - u64 reg; u32 l1size; struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; unsigned int last_sid_idx = @@ -3233,13 +3232,6 @@ static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) return -ENOMEM; } - /* Configure strtab_base_cfg for 2 levels */ - reg = FIELD_PREP(STRTAB_BASE_CFG_FMT, STRTAB_BASE_CFG_FMT_2LVL); - reg |= FIELD_PREP(STRTAB_BASE_CFG_LOG2SIZE, - ilog2(cfg->l2.num_l1_ents) + STRTAB_SPLIT); - reg |= FIELD_PREP(STRTAB_BASE_CFG_SPLIT, STRTAB_SPLIT); - cfg->strtab_base_cfg = reg; - cfg->l2.l2ptrs = devm_kcalloc(smmu->dev, cfg->l2.num_l1_ents, sizeof(*cfg->l2.l2ptrs), GFP_KERNEL); if (!cfg->l2.l2ptrs) { @@ -3253,7 +3245,6 @@ static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu) static int arm_smmu_init_strtab_linear(struct arm_smmu_device *smmu) { - u64 reg; u32 size; struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; @@ -3268,34 +3259,21 @@ static int arm_smmu_init_strtab_linear(struct arm_smmu_device *smmu) } cfg->linear.num_ents = 1 << smmu->sid_bits; - /* Configure strtab_base_cfg for a linear table covering all SIDs */ - reg = FIELD_PREP(STRTAB_BASE_CFG_FMT, STRTAB_BASE_CFG_FMT_LINEAR); - reg |= FIELD_PREP(STRTAB_BASE_CFG_LOG2SIZE, smmu->sid_bits); - cfg->strtab_base_cfg = reg; - arm_smmu_init_initial_stes(cfg->linear.table, cfg->linear.num_ents); return 0; } static int arm_smmu_init_strtab(struct arm_smmu_device *smmu) { - u64 reg; int ret; - if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) { + if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) ret = arm_smmu_init_strtab_2lvl(smmu); - reg = smmu->strtab_cfg.l2.l1_dma & STRTAB_BASE_ADDR_MASK; - } else { + else ret = arm_smmu_init_strtab_linear(smmu); - reg = smmu->strtab_cfg.linear.ste_dma & STRTAB_BASE_ADDR_MASK; - } if (ret) return ret; - /* Set the strtab base address */ - reg |= STRTAB_BASE_RA; - smmu->strtab_cfg.strtab_base = reg; - ida_init(&smmu->vmid_map); return 0; @@ -3504,6 +3482,30 @@ static int arm_smmu_device_disable(struct arm_smmu_device *smmu) return ret; } +static void arm_smmu_write_strtab(struct arm_smmu_device *smmu) +{ + struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; + dma_addr_t dma; + u32 reg; + + if (smmu->features & ARM_SMMU_FEAT_2_LVL_STRTAB) { + reg = FIELD_PREP(STRTAB_BASE_CFG_FMT, + STRTAB_BASE_CFG_FMT_2LVL) | + FIELD_PREP(STRTAB_BASE_CFG_LOG2SIZE, + ilog2(cfg->l2.num_l1_ents) + STRTAB_SPLIT) | + FIELD_PREP(STRTAB_BASE_CFG_SPLIT, STRTAB_SPLIT); + dma = cfg->l2.l1_dma; + } else { + reg = FIELD_PREP(STRTAB_BASE_CFG_FMT, + STRTAB_BASE_CFG_FMT_LINEAR) | + FIELD_PREP(STRTAB_BASE_CFG_LOG2SIZE, smmu->sid_bits); + dma = cfg->linear.ste_dma; + } + writeq_relaxed((dma & STRTAB_BASE_ADDR_MASK) | STRTAB_BASE_RA, + smmu->base + ARM_SMMU_STRTAB_BASE); + writel_relaxed(reg, smmu->base + ARM_SMMU_STRTAB_BASE_CFG); +} + static int arm_smmu_device_reset(struct arm_smmu_device *smmu) { int ret; @@ -3539,10 +3541,7 @@ static int arm_smmu_device_reset(struct arm_smmu_device *smmu) writel_relaxed(reg, smmu->base + ARM_SMMU_CR2); /* Stream table */ - writeq_relaxed(smmu->strtab_cfg.strtab_base, - smmu->base + ARM_SMMU_STRTAB_BASE); - writel_relaxed(smmu->strtab_cfg.strtab_base_cfg, - smmu->base + ARM_SMMU_STRTAB_BASE_CFG); + arm_smmu_write_strtab(smmu); /* Command queue */ writeq_relaxed(smmu->cmdq.q.q_base, smmu->base + ARM_SMMU_CMDQ_BASE); diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 8b58a30ebeb06b..3862f6e65c770e 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -634,8 +634,6 @@ struct arm_smmu_strtab_cfg { unsigned int num_l1_ents; } l2; }; - u64 strtab_base; - u32 strtab_base_cfg; }; /* An SMMUv3 instance */ From patchwork Tue Jun 11 00:31:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13692722 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 505EDC27C4F for ; Tue, 11 Jun 2024 00:46:26 +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=xtlYN9ToQtAUJ0o6Q44ilxbfAmbvBxOxZvuSiwaY3LI=; b=0vyiUR0yfBNBA2 Bd+NfjR9jFCiGK2upGfYVdUda2UZco9i1LJE8ac8YFfERlHrX4inU8FEho/UW1/v0WidX7C5dxbg+ LN0HRq7SUc+ROYhbq/VRWZM2fkWYPOftJFMDwsnh64VhhyDrkhyidujy50eb5VhxX271elTJWCMFe DRv19iJukG1idL7yg2k0MSaUS0taYGDSnFGcdAeqTgwB33YmwHVf/sWgSLk9OxcNSDhH2Dp6DwaSD FmcwsTW98RlORaldQi0IKlLQk0raGhpzaGuDlkL7bVxq0qA/NaV+c91x5XJcFrbRrtc6oewAovBqq yzshHKsgC2459SG997UQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sGpeM-000000070EY-0QxP; Tue, 11 Jun 2024 00:46:10 +0000 Received: from mail-dm6nam04on20600.outbound.protection.outlook.com ([2a01:111:f403:2409::600] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sGpeJ-000000070E5-011c for linux-arm-kernel@lists.infradead.org; Tue, 11 Jun 2024 00:46:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ImvHsKfHl9MmfCKu+3NW5VLHvFALP8f5xoynHQnKUqldEoIcJFLsc1J1tPIhXpm7Jq9LSrslPQ6qhhM+o+CKrYiZo0TDgL0w45wpf+96g/0lUZOvcxlzO5paxlfsRuYdqPLnSTWOZLe6nIkJTHhB1rabS17ElVEVeqxrtdX7RvxHKLNpJ5CSyc1C91lkEjYpLi4eZj6+aLIuDJBBwH0WwpeOp0C3hKl7rZ/0eeu8xa6iP6o+JRLZ+xTnSFbfB+314jaW4nztpGjgAqY/Du7+FiQJNmJzD6ZHGPu6Dya1FoOvk5aZ543yueDQo36JYpMeQ+keOlalTTm8rQ+e6svDQA== 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=VLUGPmKneAgy+CXJnRO+PByM6IvyAVil2RAIAxUOr/g=; b=dQASkO6JNUSLicMFKOcipQ/hDHXJ3d8mmCezGZRou+3BKGGtYtnjzGRwhmzGoQap/yuGyLtq0nNAgc/KqWtKpD3QiKVbXS9idsIEA0tYI1cWemosJU0E5lV/eTY0LSPf4Th4hkMwv0dbdJo/zmpkwqNHWksA5w+Ab4sxjzXTE9YAd6QJBfBHM2dsQ0HqPYxONdiW66WuSr4ifKZmdchtCjR270bUey+vo2jSpxzQGlhqrXp3TQqLgKN+1Qo4tOQgQvIv4DMdv4peQroM549UXdp0mSa/IwmNC4jv4Fu+A71c19piWYaLJvdbI+7KoUjD69v4klqSx+/BtPOHquAF9A== 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=VLUGPmKneAgy+CXJnRO+PByM6IvyAVil2RAIAxUOr/g=; b=QumwHLaevR2KZYLbXiTCPnSfSP9QusUVEedSoq3S+nSoAjcYGBwL3hR08kaUB+SEXqmojCmHr0kI8PTvp1IqxKp7I3Jf8Xv9ydoMcnnvumZswk+rOTcHc4yaoUsynb4jMBxJZ8VfiD06Wh0ZkyoTRpZ9J7wJ0o7h2rDzG5RjwqaKI7zHQrcGtz7RC2JeLJ4Tv/S2cauc6OLdN7MEdCezNqupW2OBqoyXwl+AvZfjAD2iAdt4oAeZV4O94dQkyba8tpg+gKZGH4hjDMQ8KoAF+TAR3p2xuC1dtZW0Tof8kXyD7Xw8q8qq5wJvP/GZ921c1rHzxAnRDLXIfmNGNyjsAg== 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:26 +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:26 +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 07/10] iommu/arm-smmu-v3: Do not use devm for the cd table allocations Date: Mon, 10 Jun 2024 21:31:16 -0300 Message-ID: <7-v2-318ed5f6983b+198f-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v2-318ed5f6983b+198f-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR22CA0006.namprd22.prod.outlook.com (2603:10b6:208:238::11) 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: 3a739b7b-0464-4aad-7446-08dc89add255 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: Qve5khLNYZhwKp0RmfoIGxxLjnNDROHpk3YyIAfJLXxvXjWmWX8Q0J+9CYYV5Md8AadXtDTRAUJnf7b376FUtQFTkQfDG7dGw79IpzKvRjURNbAXKTl/+71Nx4G8Mlv7LUsV6oP3s9erw2E+EXzOH7kY5Bmc11eUoYRzBE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K/b01wVyV5wo7BSYifRN/rFjGQfOqTQ8kHcXCmGN171dV8BW3S8eTs08cycaIO18hHtUZT9HnhKevMv4R5JTZN+0fmpsRWNq94SBZBD6M5 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)(1800799015)(366007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Z6gpkKjTNQgbkU+BR4e6D4XvHTm9VGD9BeD3vZPakuN6wbXtHS/yosov62VrGTL1HcFA9EjwNJdTNaubnC+zP3ujk88kTlp73m1czCwSVEJwPrRpNhnUsl/l6FzMNu7vQkkfjCmQifk+IHYIi0nNIKQkS3ELX5VTQCF4tVYVLK+p6mLBtCyOXqzHrrU2vI8ydtCl9Tv4dhtwCTK1oqC6uHDB7IIRIHTdMz0XUaCv31ZyqFCZLgqGA+lkGrjXk5DKXBnA/3/lqI0wMXF+iVlZ/ZhPM/bXgGm1KtfPiOHvgiznAQEkkOhWoALl5GTz/+r6mTZa0v8ok+AVoNcZlxNonc1wJNXL8nMe7wpEHhHxE6E8E4EoZ5flAqBy3cZMhAKTQt1zVvJr697cuJQfhrB1IHbsk+WY+ILMoQJBDsUfd1aV3oP4omvB2fpi+8Ya9RUTnVdqgHnqARUzyN2GSR9mSnQLdA+zQJuxvnSSJsWELN8oX9c4YVY/7HCYY/M/fB2rzFaFNx7Vuij/QiYJ9WEQ1HyvLwAjgnfKVaLpdVPvGvBJHrA3OvbXBbLJmn4+lB3o+Re9ulcNHR9U/sPXLPCNqs9hUY+klgyVQQy2xb58llDpUjt9HzVDPKnmkQxzOrVVO7lfaVeWTvH0t+cHHU+mePMPnYWUIJxFF73FWwRDJecb8FFyP3CXCZalQA/FnvLwbKXWAqXcgPy+Rdi0oUYGipcolh0yZQ/z5PnwUUIh/I9mRZprD1YWZyVnsvQ8+tlWj96d5eUg0wOV5V5cROAmB+iqF4QFpq20r341mt+V6l9X5QntWmXhMlsHGJeCPDwOTzXDvuu6kAoq5yXWCCvM3+/HdirmS2U9OKE8TFgHUqx4qd2qFQHnQtJzupN3FLlyAe24urFdWaf4iI10h1/gZTu7GoLS8reVOyLNq+ihz18mcADOWMEyIWzuIMs1dMP6k3HBoU/dGMCku3r5JNY2pb0rZYwmaLah+MldwRi3CZJrWi2LYtOmVY6NOtrb4hxE9qpErnxOKHFbbU0Fic/DFyoX2PnNT6IX1Kd+W6uofXz7mMUBh3OXOeWpsVYAiDAhdF1/gwnZ+g9jHOy1/RUP7Cqel2JKPOZSBvtvS5GjaKU0E6W2WdmgtTDYRHGItyF7HrWhWrNrqHy9c5uqvB3hEmzMIju6euSsnX8DDa7WSNRGMpx4/INKCpIDcHCKyK9chomq5O99QAZV+H1Jj21jvQjAm/fHxTmfLqpnIN0X0l6unyxnidDcU+0R00GTE6BqSAomRglQliLE6SdXgIPGL7/fUzzPiIQxgQHw5Ah+7k7C6PfiB0zSN6X8GpbSwX4ly57h2ysNeXhM6aCk6IPCh8SsdrM8pomOHgvhQrHcw/T+kx7FiDarDdamAzquqjXM5NEbuq+7ndGHEjbcQWkDXjK7U+AqPYuxaW80sbasHGbG1X3WE20HYPTNuA7UjYk3MwewQ6E9kEzgb0C7XLWJm/KlOhVKfC7LVLaPiiu/zRBnsa0EzlpyJmMkXFmK3QMyL3DypoGjjsULf42DvIGdGwI/nY3FlcVX+F7OlDWqxNk= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3a739b7b-0464-4aad-7446-08dc89add255 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:23.5204 (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: 4pcv8o+n7wtjJHJtDZOvcpetuGblgY1QElJ4e8eSBgGR0l4e1TvA3WMQYnmSn8C/ X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN6PR12MB8565 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240610_174607_060913_89CA784D X-CRM114-Status: UNSURE ( 9.75 ) X-CRM114-Notice: Please train this message. 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 The master->cd_table is entirely contained within the struct arm_smmu_master which is guaranteed to be freed by the core code under arm_smmu_release_device(). There is no reason to use devm here, arm_smmu_free_cd_tables() is reliably called to free the CD related memory. Remove it and save some memory. Signed-off-by: Jason Gunthorpe Reviewed-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 30 ++++++++++----------- 1 file changed, 14 insertions(+), 16 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 b36bf6bed67d5f..6245e2558e6a6a 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1172,8 +1172,8 @@ static int arm_smmu_alloc_cd_leaf_table(struct arm_smmu_device *smmu, { size_t size = CTXDESC_L2_ENTRIES * (CTXDESC_CD_DWORDS << 3); - l1_desc->l2ptr = dmam_alloc_coherent(smmu->dev, size, - &l1_desc->l2ptr_dma, GFP_KERNEL); + l1_desc->l2ptr = dma_alloc_coherent(smmu->dev, size, + &l1_desc->l2ptr_dma, GFP_KERNEL); if (!l1_desc->l2ptr) { dev_warn(smmu->dev, "failed to allocate context descriptor table\n"); @@ -1372,17 +1372,17 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master) cd_table->num_l1_ents = DIV_ROUND_UP(max_contexts, CTXDESC_L2_ENTRIES); - cd_table->l1_desc = devm_kcalloc(smmu->dev, cd_table->num_l1_ents, - sizeof(*cd_table->l1_desc), - GFP_KERNEL); + cd_table->l1_desc = kcalloc(cd_table->num_l1_ents, + sizeof(*cd_table->l1_desc), + GFP_KERNEL); if (!cd_table->l1_desc) return -ENOMEM; l1size = cd_table->num_l1_ents * (CTXDESC_L1_DESC_DWORDS << 3); } - cd_table->cdtab = dmam_alloc_coherent(smmu->dev, l1size, &cd_table->cdtab_dma, - GFP_KERNEL); + cd_table->cdtab = dma_alloc_coherent(smmu->dev, l1size, + &cd_table->cdtab_dma, GFP_KERNEL); if (!cd_table->cdtab) { dev_warn(smmu->dev, "failed to allocate context descriptor\n"); ret = -ENOMEM; @@ -1393,7 +1393,7 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master) err_free_l1: if (cd_table->l1_desc) { - devm_kfree(smmu->dev, cd_table->l1_desc); + kfree(cd_table->l1_desc); cd_table->l1_desc = NULL; } return ret; @@ -1413,21 +1413,19 @@ static void arm_smmu_free_cd_tables(struct arm_smmu_master *master) if (!cd_table->l1_desc[i].l2ptr) continue; - dmam_free_coherent(smmu->dev, size, - cd_table->l1_desc[i].l2ptr, - cd_table->l1_desc[i].l2ptr_dma); + dma_free_coherent(smmu->dev, size, + cd_table->l1_desc[i].l2ptr, + cd_table->l1_desc[i].l2ptr_dma); } - devm_kfree(smmu->dev, cd_table->l1_desc); - cd_table->l1_desc = NULL; + kfree(cd_table->l1_desc); l1size = cd_table->num_l1_ents * (CTXDESC_L1_DESC_DWORDS << 3); } else { l1size = cd_table->num_l1_ents * (CTXDESC_CD_DWORDS << 3); } - dmam_free_coherent(smmu->dev, l1size, cd_table->cdtab, cd_table->cdtab_dma); - cd_table->cdtab_dma = 0; - cd_table->cdtab = NULL; + dma_free_coherent(smmu->dev, l1size, cd_table->cdtab, + cd_table->cdtab_dma); } bool arm_smmu_free_asid(struct arm_smmu_ctx_desc *cd) From patchwork Tue Jun 11 00:31:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13692716 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 C5526C27C4F for ; Tue, 11 Jun 2024 00:31:54 +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=ZuYOHkOFfoWB5kEK6BikFdEd277bJbUfAohbV6xaZ9g=; b=bY+XWCxoytM/eo UTWwite+oM0sISAMlSsfBF35+0rY0acHLVvgKt4LOVxvDrbYsJsWZzDx6nVewjcBFAEobI+hDDkYp mentlpnGhrkOL45Q/4XiXQt2mPteTEMe3Dib+SnEivt+UIDbr8CTXPUgU8LFeCBTeioPBtvXmohRM RVu6paHXoQyapLOxCLv5RGMB9oyO6aTZcGuYdiFyaPdjAc16CVeizopY4P6ooTbBI7v423oU7z3Wd 6C1M4+cz9RY4J0F22StKHhtGx7YCvFtNJmeQli+RjqrsIteDLL4vyyLHvrXtmuDFk7i8Oqct6bqAu 8pfkiy+spg5dJejyK0AA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sGpQM-00000006yUn-0Fim; Tue, 11 Jun 2024 00:31:42 +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 1sGpQD-00000006yMq-33Ar for linux-arm-kernel@lists.infradead.org; Tue, 11 Jun 2024 00:31:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S0lwEzPgk3Tvu5Hy8wtabZB5Ps7Og+8xaYU6WfgxZSSzyLATdHLLRvTVITIH1epEyZl3+H+hqMhncBVAAxYHyguadOyMSkPPBCVj8hvsyARdnlYgGE5aiFaZ0YL1JiGNjHBx4da3PSikFiBYRfX4twy+BgoNSuN1NgzT80uPNpjq3aVbVAoqdu5CKBFTJg7BWDehZO+MqkuhM2gcI+Fo/q4jFZfhd3/o+ZMexXtP6PQmpimPIej78OnUORB5amuo/TWiHmxcKys2oMpewswi/urclmJ4o7K+0haMOtOLhID7AJXBFoUxO+h3jx/m4DhUdhn5qSEiCXC/v/YsCxJtXQ== 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=homDZW2M0t+/h1BOLIM/SoSRrMIk55R0Qwdxz9cdE50=; b=QarZnH3eE0dK/7DoxTvLoXmYhD3xqnEiAI4tPCY2ifRS5KinlnRmG97yAau3gRVTefs4b7j+NYVYvpCAt4EylWLfVx8AhOc5O0eg7uLqpFVvp9gk7S+d6ObfGFve/mkyH0/has2efD6Jl0/8q4Q5ukaX+WYpOlm1JaQ1MCMkeyHItGsEYDy40u3vRPYImtQ2arrgSlt5gGWyw9AdG8OnhgCK75k1gr5Cb7RzL+/TK7hBaNmqgfrL5bK/S58uY1+kV5FBZXjpT3i0NpnEYD8j4iJ1/kTWNopUf4+TpU6YbWidN5CEGtmifHWc9oqSszrGUuESkLkxkLW2/6UdWY0z8A== 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=homDZW2M0t+/h1BOLIM/SoSRrMIk55R0Qwdxz9cdE50=; b=q8KQrOykhFZyfS5phoJ/3KUpaymnzq6Qe4FmP9r9i/yDnrePVcBYwtPlCNS7V+/imObgLjp9MdGhvasNJM9Vd5d/AqB8azFI0vK8JTXjdttDkpNYUwwwLIWTxFNHZCOLwHLwwe9L/nSaqBZ4xQO0KQe9Jo7F776rU0uqivmEBaqV9RVKZRZq3/dXSGpdribHs3pbHotJxl2mJPCf2G12lwQ+q2zzdsBGYUgYC8fgNsKysn/C3OfZ6+YHofBUGrTyZDXDQQqGcnmuKVncP0+70gB0ThYV/lk/9a9M/ucLKYapHMu1K3Z5NGC2eAh1VVbNO0bIkq+a9kvrTfc9Bjri5Q== 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:24 +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:24 +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 08/10] iommu/arm-smmu-v3: Shrink the cdtab l1_desc array Date: Mon, 10 Jun 2024 21:31:17 -0300 Message-ID: <8-v2-318ed5f6983b+198f-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v2-318ed5f6983b+198f-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: BL1PR13CA0430.namprd13.prod.outlook.com (2603:10b6:208:2c3::15) 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: 40d4dae7-b0aa-4f69-b320-08dc89add15f 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: bijEDcsa+hteKbSqkUoxCpLkQe6vbjhUOOYnNIYaUQEes6Mf3ZMDgY4Mm028cBMsbK7nEySXnhJqnwFsFZdtGrYD09W+iCpPlBY75CN8Usklu5N3q6lSr0vuSiSeaBck1lUjYGTxlxICnt5/y0s/hzHeXX89dgqO4njBL8ZzyCqKxV0tJ+IgeVSQ4UPOMhWo4MeWX9bRSJLhlptGkxsiaz5qEmF51qA4R4RxMON2TiMR5QCbXemSJdpJIdeOk1zN4IFQpsWhcm/t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.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376005)(1800799015)(366007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: s9m/fVOsX0KaiohT9kGJaWkDt3r02LMMy/pxvCp2OwHXwZiJHgRGYndFcpgKZT9DHCU+z8vU8rQmnSP+2wFORYbsW71fd4CFnK3OxNIFiQIYXe4Zqpk7UZk5W+WXuHQpTrU7koagNtTHy/BShceTKc/gXR0TtFfAkjozmf4ED45M5LA9pZixp4+esFIeIZVT0B6n3foihTd77Pd2QuUNoQOQBz6xG109zIn8OnETgS99nW2UPmHqZfhuTUiqHpxZUYv8ImhA4x4RqLP1Z2FN0mD45h+oQ18NoQ4O//jNOilyNYtCUdfODhMcyqt0KM3koZbVxvcI6b50EiCegvZwH+RvB/CG1vFeCy9VlzA8wmZpU1vBGm6JZCRysxkm3voEASvZY8qrHNL7s7BdA4NTxkg9pN++flBBITwIgbM0KWQHOcxv/s0lV4WSFZjxC8Y7IE2STYx7o79DRXlJKulWQ+9RP+T429J1sxNrTzlldHO9kyzeWUKBIuXDH8Rhdt7g2Eis4+yLIxADJrwWaHIS4nV31sF88mlY6i4oVAmzTY1RvHQTztyeR+nueWpjFyF1NY92EWGsD9tQxVW4BaTQN1QjVuMSrx+NXy7C/h/0SjMSzFMiN5XKCudW1ARE6ZxYlmh35QqSo9vDrMkexwiaGiIBWlsxVejfAejgg4KRTP/4p0J6utoSP9gILMMt4TftBz2Q9vCdHjI4ftngpPer6qRUK7TXXsi4WmFtXN86YW5+oKu4UOiCJO00YidXm3nNBvG9eh7f8vsjuJtT7bo3R9CQGEIV6kVDIn2VfjvGTHCHnH2pbkJn07ZUYwq8VHJVL+6omYChu3HU7u7ITpIBQ9vTJjWI8aNE2DrTIEupSzhJIAN1tu6BWqLMXBRlEtnfiZ6PaxgBRaWC9TIDecZSVu7R09olQSmLkSibG1Neu+oQNLjiCa2YnJZzkwRBRn/JqtyE4IhgSHbfqwA5OTtKxr5SNZC0LVt5JTbrx44EKTdv2qWmQwHBwAvsd8zwyukoxU6k5OFRzkuBq0KmCGtlzqZL+tmqB7LLtHXKIPl4tb0I0euXjdj8LJUwK38D3kKlBIOKYRWE0b1HAy2pKWe2/bymV1TJskaOXoOLVgUPqjGDi1dTyP5QH35cFx5XBm2ozROLEmvjyfxsUUqDbZdZnVQKE1akrdRzH2tL1w6p7KMBexsuuVTk5pdvZE1QuMncVYfmbVGOlH/KLX3Igj74w+i8yr11fWTUyMbGLTweTG+2gN6jkouc5HKmXOBPYp3phpt0Hm40xqsb3llEsw8fBQBChbqk1adCobNTQgxkPijXpJhNAUYusdYfRVGral2zr3uGzY9a4MG3T4TDzpVSI9VBsLM/q48SitrAa4D0BFKU8im4Ff2E0TxvIEkjBYs0FqXuLGb97Sosp3plmnc2Jm83wVudHxFJVQVPJu0Evfcbj7DR8tViSne60ignbaWJLKPbWzMVoGNBlGo7kVS1ge8TDFJ9UybxJe7jw6+CxaQ9ZJY0QzPMVtFeab+EfW2zKfzTjXopPmdOghLUfkx3g0CG84R61A1W4gd6+tP2Wjs= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 40d4dae7-b0aa-4f69-b320-08dc89add15f 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.5952 (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: URS46DxxPQiYF7gSY/tRRZjMIa8doHCMDWnRdUIoKJRQFPJXSJTUxkOIwbJnseUA X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN6PR12MB8565 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240610_173133_881785_987E655C X-CRM114-Status: GOOD ( 13.71 ) 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 The top of the 2 level CD table is (at most) 1024 entries big, and two high order allocations are required. One of __le64 which is programmed into the HW (8k) and one of struct arm_smmu_l1_ctx_desc which holds the CPU pointer (16k). There are two copies of the l2ptr_dma, one is stored in the struct arm_smmu_l1_ctx_desc, and another is encoded in the __le64 for the HW to use. Instead of storing two copies just decode the value from the __le64. Signed-off-by: Jason Gunthorpe Reviewed-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 41 +++++++++------------ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 - 2 files changed, 17 insertions(+), 25 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 6245e2558e6a6a..dd65e27aebafd4 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1167,31 +1167,19 @@ static void arm_smmu_sync_cd(struct arm_smmu_master *master, arm_smmu_cmdq_batch_submit(smmu, &cmds); } -static int arm_smmu_alloc_cd_leaf_table(struct arm_smmu_device *smmu, - struct arm_smmu_l1_ctx_desc *l1_desc) +static void arm_smmu_write_cd_l1_desc(__le64 *dst, dma_addr_t l2ptr_dma) { - size_t size = CTXDESC_L2_ENTRIES * (CTXDESC_CD_DWORDS << 3); - - l1_desc->l2ptr = dma_alloc_coherent(smmu->dev, size, - &l1_desc->l2ptr_dma, GFP_KERNEL); - if (!l1_desc->l2ptr) { - dev_warn(smmu->dev, - "failed to allocate context descriptor table\n"); - return -ENOMEM; - } - return 0; -} - -static void arm_smmu_write_cd_l1_desc(__le64 *dst, - struct arm_smmu_l1_ctx_desc *l1_desc) -{ - u64 val = (l1_desc->l2ptr_dma & CTXDESC_L1_DESC_L2PTR_MASK) | - CTXDESC_L1_DESC_V; + u64 val = (l2ptr_dma & CTXDESC_L1_DESC_L2PTR_MASK) | CTXDESC_L1_DESC_V; /* The HW has 64 bit atomicity with stores to the L2 CD table */ WRITE_ONCE(*dst, cpu_to_le64(val)); } +static dma_addr_t arm_smmu_cd_l1_get_desc(const __le64 *src) +{ + return le64_to_cpu(src) & CTXDESC_L1_DESC_L2PTR_MASK; +} + struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, u32 ssid) { @@ -1231,13 +1219,17 @@ struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, l1_desc = &cd_table->l1_desc[idx]; if (!l1_desc->l2ptr) { - __le64 *l1ptr; + dma_addr_t l2ptr_dma; - if (arm_smmu_alloc_cd_leaf_table(smmu, l1_desc)) + l1_desc->l2ptr = dma_alloc_coherent( + smmu->dev, + CTXDESC_L2_ENTRIES * sizeof(struct arm_smmu_cd), + &l2ptr_dma, GFP_KERNEL); + if (!l1_desc->l2ptr) return NULL; - l1ptr = cd_table->cdtab + idx * CTXDESC_L1_DESC_DWORDS; - arm_smmu_write_cd_l1_desc(l1ptr, l1_desc); + arm_smmu_write_cd_l1_desc(&cd_table->cdtab[idx], + l2ptr_dma); /* An invalid L1CD can be cached */ arm_smmu_sync_cd(master, ssid, false); } @@ -1415,7 +1407,8 @@ static void arm_smmu_free_cd_tables(struct arm_smmu_master *master) dma_free_coherent(smmu->dev, size, cd_table->l1_desc[i].l2ptr, - cd_table->l1_desc[i].l2ptr_dma); + arm_smmu_cd_l1_get_desc( + &cd_table->cdtab[i])); } kfree(cd_table->l1_desc); diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 3862f6e65c770e..2f7d70d92b1f31 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -603,7 +603,6 @@ struct arm_smmu_ctx_desc { struct arm_smmu_l1_ctx_desc { struct arm_smmu_cd *l2ptr; - dma_addr_t l2ptr_dma; }; struct arm_smmu_ctx_desc_cfg { From patchwork Tue Jun 11 00:31:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13692721 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 99CB5C27C5F for ; Tue, 11 Jun 2024 00:32:29 +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=+cDWp9UTIPAZUhBZfrzGqZwmBMnZHWFe9DgKjMu0WQY=; b=D3UW/KNTrqO2B1 mFpCRvK8MsBUD0dvmU/GvZX+CL9eKgwAqy3PvO6ZcsR6de4bNItOGVvAFg5u73Al0jsH2b8L0Zt52 SczLdhDv3/qQPH++QtquS7gUrbH0ThLEhfJCtMGqpXXnQ+5jOxL1egNxYK+Eo3F7CeauZsYDrS+JO 23FJldSibf1apQoXzuUp6e0riln/LI2BjigdoHkulLhBSfUZFQwGHVFhQv9eSBE/EClYanZJC5+jh TGO0lwG78GDELTSzDe2gpZaDpJjXB4jDVUCr4GeCkteG80V77mUYXaeTOZZjhFUYXgugTpmnUM9L1 ArRYzj0TGEwUGudNx+og==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sGpQq-00000006ykS-3wN5; Tue, 11 Jun 2024 00:32:12 +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 1sGpQL-00000006yMq-1hDG for linux-arm-kernel@lists.infradead.org; Tue, 11 Jun 2024 00:31:43 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gsg++cFRZYpZp4OtmFVaUKMhfTtQ8KvLp67MTv+w1MiNChF/Ud52tojXc4KG25HslAWX6YmQVVCN+6VGYehdVdEb0p8Ytr7Ut8YTZQDMHns7iF5Aanj+cKDB3FSWjI5Vz/idPx31P0IyDNVRenyWTunReOUuj+7ofxnYlcH4Zupt9Q2EKgVzNulH76MHcosuwqogJjwO/7NSfn4HzpHqRpGJBeS6fOn4mqlv1zn4j5outJVJAv4sKyDcAGE6bPTnkmc0n4jnV6WQYKsq+/7sd5ZHD9TvOvgIz9oF8HAJuFl3gA0lUAThB40fnXYFQXk2Og5L2ue2FLLZAO3GESf4WA== 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=5lX1QUef6bYyb89bDk3ithjEsdCoPn97OMfpZsr2X4Y=; b=dzKubjcSPtdOvkxmGzz2hBIxxOA4CGf2LKAHtOHJsWV7wfSCEcdjuTN7PnR7ipKNJBgs69/PVVzVgr+OhqvqBr1W1/iR1ydM0RIa1pecNfFqVKl09ILcKrxh9HTFtCT7UOWx3FCEMFh5iRIsBrd/sFbPR/zn8Nc4NirAWlxx4GzxIAz5CzTzSqhTsAGggTBBGDyJZaibS9JJbBeCEi1LOXjctMRc7TP7MjegVTXO47p3XKc96uP8FWH7T38e16NJ9GEiBY7E60q1r5Br8/gQZg8Fsz1rN6Y95rJJJsuzsuJDsI6ICsMghUj2OYJXp0lY3z9T228XT6XYllXnifQoGw== 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=5lX1QUef6bYyb89bDk3ithjEsdCoPn97OMfpZsr2X4Y=; b=VLZlJKHLneXHG83kk30VYEs9UyaEKFSCiA3Ij9xMVaqK5xlT1Uky0LIK93z7rtfJrPPWNvjg3AiY+T5MeEIXnq8uChbHtIBIQS37m4T24mdu3xtqB4BjhLtZp+PeuRWbB+OXMh4gQjSd2JCFKvRRAWyWjfHbk6GtVHS/UV2j2YUcBGriYU4rqESv3LG7gZT1a0fjiFZRAmNAiZ3PRHuJb5m/Nx3uLq72YwIU6DP6XjrIW6NK6REdp8jTInhgwBwI4i6/RerwDP5x4hhkAQhOcfTzDyNvkLES5dVB1lbRlbjHYDE/1F6kf5rAlS7gMOLK+g32bZNtQjLSwDCIy634+g== 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 09/10] iommu/arm-smmu-v3: Add types for each level of the CD table Date: Mon, 10 Jun 2024 21:31:18 -0300 Message-ID: <9-v2-318ed5f6983b+198f-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v2-318ed5f6983b+198f-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR18CA0015.namprd18.prod.outlook.com (2603:10b6:208:23c::20) 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: 87542964-ecb9-4dfb-4fc5-08dc89add18f 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: 5wqXbaOZNn07PovzCG6SrsvAhAVREg7YZ3Gs3d948Edad+q61JcDpt1t8MfoKyYnab8WcUufc8phxzfSYfyPFumH5MxuS1tmRP64Bwvn/frFv+T5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I9TEGj8LbhvaQgUrrNAgNHj0le0at8zk1o5uzhsrIVG95AwYGmamSGoof1PpZgVld+eC76xgnV7fspGDoIvsk3Ykjasg71GOA61lfSMcgc1ctDAQx2SOuS5AUPYcKiP4/GnQPpj14Kq6WtjpzKy29ewUZFSb 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)(1800799015)(366007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wQ4n+yiEwPi9AjkaHumwd7clUQaPyD+Gb2opWMaT0zuOCvfXSDnPhjRK/cYGE0zszTzdlI54Gt7diQ3zrwNyR1TI8OfQFJ1SouI4WRvTfmTT0jbh7DECp1oQ1vRoomXqpa3/qjmUYXuoonpl11qIqs5nIKAlFyYjl9ike9vC9vP4VHmuyFIx+21S9wps8sLBkW2Yl9QxWx9uT0jW80N3jsf/TE2SA5hMQCuOBA0ttADFnrpnYtynKtPVF0coPlwIcHvQjcZ0w0AjXrGs6yS439MMu2Hsb4av3oGUN6ZLTWniyGxHy+nG3A+zRGCpUK4pTlQJov8ilIePKEeCLTtn0j28s1D5FiVSZbiyq7d0rJp6rvG3UbzbBjN0f3plJGoJzXG7iDXF+vpijVAHwyI3mO3erUCxlBxquQUt3dvaaZWiAdXw3VrP04PbcBO47C3KPC6dq8vSJDxn2HUwiNlwHVR+lK/XJXc6rHxUH3NKGsnbcNmFPsOCGdVDpxOVy2/0ArRiqixN3xsGRN+cvN888iSy+T7RVLvJrcqI8r775yDbSY4Kc1K9L7ZVf9fz2Z5qFjP9SBukIi1dvbtuv7ZAKlAlUgKWa6NfXGyqiEtzZhm9KhCo6stya6rQ7qtq/mDhZZOGA0lCZ84TUAwBC8ZXP7W+pt70kBnoX1xm6tn7VZmw+Q2/kwZXm/59I4MDORYLUjmNrvIsLi2N7NZr7njJexeclK0RklmpUZC4xlwNAGDBPV0fkkU621m5GZ/988dEaR32Jt7JiN83bf6ejaEsdagkA90uTNjBwP0Ll7IT0K7teNvmJrSrE1Jn7sEnHCehVugZnzf/cjiRXwmF11PC3zKRlbeGMmB5DxZDdmAk2rLz1XgKeV9FgxyAP8/a8UeVOqTQaftLulyvOIx5qpIFvg4mpdRcwWUTtWV7PritgEbIVAI8fq0v8Pi9DN6gpEfVHsjJ0uBJcXohiHQxxBMqnm7OO0hiGLyM4XNnPO0SOtekxcadf5S4BSRpo/hORbIomUtPTP+ezDiFuysCXoVhGN3aE6c+2n8kh0BeI4tb9xYmkj7tvvh1znB1TrkF9+H5yKIfdFYm85BgHwQDXftdTEUGp4KCDJGTDIAF09yLu2VlL+seZrNjj84fRpaUOOluYLN7JXGBWhLQL+uG/ILJdLTv1O084TLkgegpawupz+FNt7QPbtmsJdpU+ZQrBBnw947XDihSHbnU1SB5LCMaaz9bCoK1VIjzMe7MgtHF1/kgMir2cDa9+1hIpa7GgrrDEur5hmugO7Ux3mptIDdKkNLERDP5x2OLZL7j2GTtdMkxejyt4yy7WppukEPRJncEhclY9W8etFfMnmLrc+ZOsEUk8xe8XA2aUev39fkPyrMAKGkdKXE8iuu3eSMDaYamjtuj56g6lvhJXnlUC+ayzs6EhwQmFEX1UUma4ue6VD3OEx8r20YJ79wfthFOXVpfcHiA2wfkPhA0v21tGRsBVeDYCy0bK8P/QSn3sA7MjDE04BYg/w9R4+cXur/9x1XwiWZnwy+Fx/V8C34bhFGInpwYvzfoL4n5R325haQMu+I= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 87542964-ecb9-4dfb-4fc5-08dc89add18f 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.8992 (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: lLYqxjqYnZ9R48NDYUGsZIbQcTSj4ECytqGtxGEbcOTwfM9wQw/FDzfCn8xA52Ms X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN6PR12MB8565 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240610_173141_664610_F07C371C X-CRM114-Status: GOOD ( 14.49 ) 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 As well as indexing helpers arm_smmu_cdtab_l1/2_idx(). Remove CTXDESC_L1_DESC_DWORDS and CTXDESC_CD_DWORDS replacing them all with type specific calculations. Signed-off-by: Jason Gunthorpe Reviewed-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 46 +++++++++++---------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 27 +++++++++--- 2 files changed, 46 insertions(+), 27 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 dd65e27aebafd4..49e019131ef3b5 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1167,17 +1167,18 @@ static void arm_smmu_sync_cd(struct arm_smmu_master *master, arm_smmu_cmdq_batch_submit(smmu, &cmds); } -static void arm_smmu_write_cd_l1_desc(__le64 *dst, dma_addr_t l2ptr_dma) +static void arm_smmu_write_cd_l1_desc(struct arm_smmu_cdtab_l1 *dst, + dma_addr_t l2ptr_dma) { u64 val = (l2ptr_dma & CTXDESC_L1_DESC_L2PTR_MASK) | CTXDESC_L1_DESC_V; /* The HW has 64 bit atomicity with stores to the L2 CD table */ - WRITE_ONCE(*dst, cpu_to_le64(val)); + WRITE_ONCE(dst->l2ptr, cpu_to_le64(val)); } -static dma_addr_t arm_smmu_cd_l1_get_desc(const __le64 *src) +static dma_addr_t arm_smmu_cd_l1_get_desc(const struct arm_smmu_cdtab_l1 *src) { - return le64_to_cpu(src) & CTXDESC_L1_DESC_L2PTR_MASK; + return le64_to_cpu(src->l2ptr) & CTXDESC_L1_DESC_L2PTR_MASK; } struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, @@ -1190,13 +1191,12 @@ struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, return NULL; if (cd_table->s1fmt == STRTAB_STE_0_S1FMT_LINEAR) - return (struct arm_smmu_cd *)(cd_table->cdtab + - ssid * CTXDESC_CD_DWORDS); + return &((struct arm_smmu_cd *)cd_table->cdtab)[ssid]; - l1_desc = &cd_table->l1_desc[ssid / CTXDESC_L2_ENTRIES]; + l1_desc = &cd_table->l1_desc[arm_smmu_cdtab_l1_idx(ssid)]; if (!l1_desc->l2ptr) return NULL; - return &l1_desc->l2ptr[ssid % CTXDESC_L2_ENTRIES]; + return &l1_desc->l2ptr->cds[arm_smmu_cdtab_l2_idx(ssid)]; } struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, @@ -1214,7 +1214,7 @@ struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, } if (cd_table->s1fmt == STRTAB_STE_0_S1FMT_64K_L2) { - unsigned int idx = ssid / CTXDESC_L2_ENTRIES; + unsigned int idx = arm_smmu_cdtab_l1_idx(ssid); struct arm_smmu_l1_ctx_desc *l1_desc; l1_desc = &cd_table->l1_desc[idx]; @@ -1228,8 +1228,10 @@ struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, if (!l1_desc->l2ptr) return NULL; - arm_smmu_write_cd_l1_desc(&cd_table->cdtab[idx], - l2ptr_dma); + arm_smmu_write_cd_l1_desc( + &((struct arm_smmu_cdtab_l1 *) + cd_table->cdtab)[idx], + l2ptr_dma); /* An invalid L1CD can be cached */ arm_smmu_sync_cd(master, ssid, false); } @@ -1358,7 +1360,7 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master) cd_table->s1fmt = STRTAB_STE_0_S1FMT_LINEAR; cd_table->num_l1_ents = max_contexts; - l1size = max_contexts * (CTXDESC_CD_DWORDS << 3); + l1size = max_contexts * sizeof(struct arm_smmu_cd); } else { cd_table->s1fmt = STRTAB_STE_0_S1FMT_64K_L2; cd_table->num_l1_ents = DIV_ROUND_UP(max_contexts, @@ -1370,7 +1372,8 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master) if (!cd_table->l1_desc) return -ENOMEM; - l1size = cd_table->num_l1_ents * (CTXDESC_L1_DESC_DWORDS << 3); + l1size = cd_table->num_l1_ents * + sizeof(struct arm_smmu_cdtab_l1); } cd_table->cdtab = dma_alloc_coherent(smmu->dev, l1size, @@ -1394,27 +1397,28 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master) static void arm_smmu_free_cd_tables(struct arm_smmu_master *master) { int i; - size_t size, l1size; + size_t l1size; struct arm_smmu_device *smmu = master->smmu; struct arm_smmu_ctx_desc_cfg *cd_table = &master->cd_table; if (cd_table->l1_desc) { - size = CTXDESC_L2_ENTRIES * (CTXDESC_CD_DWORDS << 3); - for (i = 0; i < cd_table->num_l1_ents; i++) { if (!cd_table->l1_desc[i].l2ptr) continue; - dma_free_coherent(smmu->dev, size, + dma_free_coherent(smmu->dev, + sizeof(*cd_table->l1_desc[i].l2ptr), cd_table->l1_desc[i].l2ptr, - arm_smmu_cd_l1_get_desc( - &cd_table->cdtab[i])); + arm_smmu_cd_l1_get_desc(&( + (struct arm_smmu_cdtab_l1 *) + cd_table->cdtab)[i])); } kfree(cd_table->l1_desc); - l1size = cd_table->num_l1_ents * (CTXDESC_L1_DESC_DWORDS << 3); + l1size = cd_table->num_l1_ents * + sizeof(struct arm_smmu_cdtab_l1); } else { - l1size = cd_table->num_l1_ents * (CTXDESC_CD_DWORDS << 3); + l1size = cd_table->num_l1_ents * sizeof(struct arm_smmu_cd); } dma_free_coherent(smmu->dev, l1size, cd_table->cdtab, diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 2f7d70d92b1f31..7ed8d53423cf56 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -293,16 +293,31 @@ static inline unsigned int arm_smmu_strtab_l2_idx(unsigned int sid) */ #define CTXDESC_L2_ENTRIES 1024 -#define CTXDESC_L1_DESC_DWORDS 1 #define CTXDESC_L1_DESC_V (1UL << 0) #define CTXDESC_L1_DESC_L2PTR_MASK GENMASK_ULL(51, 12) -#define CTXDESC_CD_DWORDS 8 - struct arm_smmu_cd { - __le64 data[CTXDESC_CD_DWORDS]; + __le64 data[8]; }; +struct arm_smmu_cdtab_l2 { + struct arm_smmu_cd cds[CTXDESC_L2_ENTRIES]; +}; + +struct arm_smmu_cdtab_l1 { + __le64 l2ptr; +}; + +static inline unsigned int arm_smmu_cdtab_l1_idx(unsigned int ssid) +{ + return ssid / CTXDESC_L2_ENTRIES; +} + +static inline unsigned int arm_smmu_cdtab_l2_idx(unsigned int ssid) +{ + return ssid % CTXDESC_L2_ENTRIES; +} + #define CTXDESC_CD_0_TCR_T0SZ GENMASK_ULL(5, 0) #define CTXDESC_CD_0_TCR_TG0 GENMASK_ULL(7, 6) #define CTXDESC_CD_0_TCR_IRGN0 GENMASK_ULL(9, 8) @@ -330,7 +345,7 @@ struct arm_smmu_cd { * When the SMMU only supports linear context descriptor tables, pick a * reasonable size limit (64kB). */ -#define CTXDESC_LINEAR_CDMAX ilog2(SZ_64K / (CTXDESC_CD_DWORDS << 3)) +#define CTXDESC_LINEAR_CDMAX ilog2(SZ_64K / sizeof(struct arm_smmu_cd)) /* Command queue */ #define CMDQ_ENT_SZ_SHIFT 4 @@ -602,7 +617,7 @@ struct arm_smmu_ctx_desc { }; struct arm_smmu_l1_ctx_desc { - struct arm_smmu_cd *l2ptr; + struct arm_smmu_cdtab_l2 *l2ptr; }; struct arm_smmu_ctx_desc_cfg { From patchwork Tue Jun 11 00:31:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 13692724 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 3C45EC27C4F for ; Tue, 11 Jun 2024 00:47:34 +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=cGxLUffMqq3mIbQsu3nGUBsEsW+BvRSuVHeK/u5RYRI=; b=h+bJ1KRqOr30qq 5bMrcA5Jvvzr8rxUhIvyjiQw6ScWCffAADdN7J8jeoWdpvAFylMbTwEewWhAtjS/23cv9kyEXVgwC iFi/uwpBtBHrDeYbVtffGdiham8QRBE70U/JQCtRt8AVK0gQHQw7NfBtAuq+qYAmTJKB+LqgEIB5a MxJ0lNMBTxmXImxII99C9IHSjfP8fiLIaBXSC1iMTP9YT/7c3s5rw0TbGP2yd6dekHb5EYQTl7Ax1 +xBsEQw9ln8vXKlR0H1X137YDZq5sMeIDGdaJjdm5MYEe0RS4Vxm4P2BMf5VcrBDj7aL3wBAIn1XU GT+DJi2htGURFAE4Mw4g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sGpfT-000000070MB-2Occ; Tue, 11 Jun 2024 00:47:19 +0000 Received: from mail-bn7nam10on20626.outbound.protection.outlook.com ([2a01:111:f403:2009::626] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sGpfQ-000000070LF-49mk for linux-arm-kernel@lists.infradead.org; Tue, 11 Jun 2024 00:47:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mrBLX66Zj3xrkWf5jDbmE3MyqaOTSnmaUs2JXqyMRAjnohMS9tP0LQ8V2yNlwdfYllmA6Qh6VKxtdlMrgmi80VxtzyR6xom9lGBRqb3leBNssHUWbxoaYNOChms8X7gVLyBjVCY8o67Wj+qJeKsTcta7S4wmTTz6P3BRZBG8I5wiu8GQHYu/k30a4ubqrtxT+3+yz6kcfH+M8XC6g/HTdT6I2ziLd4qe/J7SL+jyjuuYk2Kdl2Xc39NJ8XrOZvPIgQJjNoFRjY8w0yc2wW4XQU7isZP6dS66ToiF/XvuaseA6PRhaMJcgwaW4xCeD814I4D3k3RiEZ2W8itsScHOZw== 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=egCXRcBlnMbohCVjqhJ6vFKAuzzIRmlFwYHe+rj6s8g=; b=VKPpLGadlHaFwjkJzMOFQw8MCs4q8hv47Ux6bxCtrDObX5ul7pu1NNA26K1ADKf1DkAt+Ws8SAEvNDBuJ8VI8aNvCsos/E3Mgn2qaK8r/IHaO7v6ExpWs0lgZIjqlXZmuwxvkVPxqpM9/1Y0WQtLYebRQt/mU5EpyYFZzOPT/XFHF515j3xnGUET2cr83Ps/LI/c2rQo7URwR4Rvpyk8zfTJJLYJMpaVDR/KglOIt8zIaBfKDieU47jcdHnO0vUWIKgjisQXJemetAnQPz6Yk6rVnKUaStbMk1bFSKEhLx3Xv4lVQHeAJmXZ8Er/N18eGLai+/KXncmROmavN1GDBg== 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=egCXRcBlnMbohCVjqhJ6vFKAuzzIRmlFwYHe+rj6s8g=; b=ATauL9se+g8IUf/Ss2gxmCpX7mXWY103n0JmG5vwx7AAhbHqytSPZdHaotUwUnSDTobVclDADQNZ8A5pvoVsR4zqO1D1J32ebf2g68GmyHPH11eEtry7CXNDrJDeVRDtSTEBlbM3X3mofTAVMWpQJEcEX1jUiAKeNCqV/ABQF71kkutyMIsTBSpmXQ3TR2UsGY7ZkAbzUYRg2RDiZH7Oq4Aile/I5btvrsr0Q+O+XcTX38CPJi1eOW1VDFsZKdU982YbZozuTPOjKJPLdegm6Olh3l5eOTw2bur3rFkOg1TNnWnfn2ea/N+hue3JKoAIc9lngG5pScgI+rAuGdvIjw== 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:23 +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:23 +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 10/10] iommu/arm-smmu-v3: Reorganize struct arm_smmu_ctx_desc_cfg Date: Mon, 10 Jun 2024 21:31:19 -0300 Message-ID: <10-v2-318ed5f6983b+198f-smmuv3_tidy_jgg@nvidia.com> In-Reply-To: <0-v2-318ed5f6983b+198f-smmuv3_tidy_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR22CA0014.namprd22.prod.outlook.com (2603:10b6:208:238::19) 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: 4f344b75-ffa2-43f5-09a1-08dc89add133 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: wUxp8mdqq88Grn1+Pu1niyok+mj4fvRznl+BFxwJwz5s0z0xZW3VZLTxjTosZXNaj7U83LFIWmBNDFkJ10HG5s0sH1aV0wYUSrfL+gGZWfcui2csCmQMfAdvBq3JlI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WQfTeWGWMEDo36kTQulGCzwBh1b6vIu3DXm5Ve4cY7PCL1300mp/Dushn4d/N2PRLgz7Sam5ZcUUcFQqcLe59uLmrPWOeOrRLBUNIkQHVK3V0YrdKdCxlwDn37JcVDo6dg1jpd6GxASaPJIR9UTJ6U 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)(1800799015)(366007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TUG1v1NfzJRYIvhELIyVx/lCDtxUwpa/IafhPpwSwxa1ys/7XEOQS8CLktU4tKkKIiw4Fea9GEl2R1aK/dE0tH3fo2Bsx23nZu3mImsaokv0I8MvEyBtEVnFd8hZzIpIpM3CGCe61W6yHs+AdkKtVuICTnl5EpxX7Yl6hVxJAP8X3UY0toAWnGyb8r+Ca21EtfxLPfHA/UoEBfJut6F/HQy6OM5p4jX2zTBVb//WSuyarkCJSyf7xv+ldD7k9xL82eZijE0VxK2TK+oDZsIyp8AN1kLQGSO33fjftfruTMIJTbMDxTyX+Jxm8gGLd0qgY302odKmNbWGHMfB728BWZc/yF7iMXtWfM+JP6hrcuXfzJqsseX3nk5387l3ZtILAyuNOzzZ9cdOsW3vcJlW/5zwOLgokhJM0eCxfLyJfr8n3gtu/TvLe9+bu88i6zFbmfmK3D6tpZFr33xtT582lhTlBztA91+GdTud1WBr6zoUbTY1otfNFabHc1Obgp2GnvvaIaDanbSa082BLMa4XgzcHccQkO3u3W6sAGp9Zh7uPHAkT6p3yYTUaY0fE0J6cM3SaG9K5CCvnxPwOQ8iqWPI/MEV98uVXiu2g60eqyZoMWVOFc30FMHpE14k8Td7IHqd7vdS4lj8yXEAPuzSkiic+TLWopyhxazCqMaqcLFGMIisUkhFC4kSUEsFlMSCcDbO8nEV2f6j5RYBQ4wiE1JMrqRx2F6XHqDGzSLtbDDSoONbha4U11sYldPVFoSjQzobNcrdvpukAwpgP+O+8mfgT2C6ic5WkQ7IFwxP2Ycx6LAir2pk2YmXfSyt1sgO6RbDQ7P7QM2SkJAi/vULGxuT/dRefMAYg/W+m7h5dXcoYwFGCSWwwUxCwowhcHIVvEs/CEgjkeRUNFdMVB0dhnoYUvql/Sli0n8IytDVl8MpyX6Tmt1iyBiKDdAlaoEcBvSSVst6fB1o6ojsz/wAJzOFIlzuTkSkDRAegLLRGUWr3ERuaQSmEw3ZK6qnx6BZ0x1LFtJg0HTNY5/0+kfOMSWTXKMUT4JY8hhuUI2njup7XSN8aN+yE9uP3e0wzW3IRsJHCoLEldqgty6icspL/w6WjiDyMhl8WVwtdTIQjoLduz/pD63Xb2FJ44GrwPBggzveAlvB9F+518Kt8iJ6jvvpPshOr9Fi8/7H94R5Ujdk7yhyFNs/Ky2ktlZtGyf1bAKuQoNw24PIHxiun7Xoygrbx9/Mjyldppe1xcVoS92k9uYumqg0r+rv540FfAoXt3g/JV8rDMfoZSPbV86XJ6qW1rkb21gvP8c1q/4LIURqMopa21dGV5WJ8f913/yE7anJ7yhYJEs7OdVezm73zRg6PSmyXvXtNSyyQ5qd+xkVi83o47TUOS2ZbIZmAZ8BEx1YOLz9YV3Dmw8Cc1h8ox8EDV2NN/5AllYGFolxJeQQxJ5Frnx61V/EBAO8hozuu1tD7K7FK68gTkgO+uurFWv7fPtPS6IaxAGFsUhUrpRsipsQ8P340L+n3rYhMO5fWl7maPwH+agQRlawrH6BwR2MzvBezNt8FQQ5if4QBhY= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4f344b75-ffa2-43f5-09a1-08dc89add133 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.4652 (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: GZlRxfVIz/H/h3I3ke/p0ZIhJvFmOPpFaD+WxuVbuf/5d2a8NG7LYwzpMoPKwdKe X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN6PR12MB8565 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240610_174717_116933_BA442CBE X-CRM114-Status: GOOD ( 17.20 ) 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 The members here are being used for both the linear and the 2 level case, with the meaning of each item slightly different in the two cases. Split it into a clean union where both cases have their own struct with their own logical names and correct types. Adjust all the users to detect linear/2lvl and use the right sub structure and types consistently. Remove CTXDESC_CD_DWORDS by changing the last places to use sizeof(struct arm_smmu_cd). Signed-off-by: Jason Gunthorpe Reviewed-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 119 +++++++++----------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 24 ++-- 2 files changed, 71 insertions(+), 72 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 49e019131ef3b5..b9994c46c52f25 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1184,19 +1184,19 @@ static dma_addr_t arm_smmu_cd_l1_get_desc(const struct arm_smmu_cdtab_l1 *src) struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, u32 ssid) { - struct arm_smmu_l1_ctx_desc *l1_desc; + struct arm_smmu_cdtab_l2 *l2; struct arm_smmu_ctx_desc_cfg *cd_table = &master->cd_table; - if (!cd_table->cdtab) + if (!arm_smmu_cdtab_allocated(cd_table)) return NULL; if (cd_table->s1fmt == STRTAB_STE_0_S1FMT_LINEAR) - return &((struct arm_smmu_cd *)cd_table->cdtab)[ssid]; + return &cd_table->linear.table[ssid]; - l1_desc = &cd_table->l1_desc[arm_smmu_cdtab_l1_idx(ssid)]; - if (!l1_desc->l2ptr) + l2 = cd_table->l2.l2ptrs[arm_smmu_cdtab_l1_idx(ssid)]; + if (!l2) return NULL; - return &l1_desc->l2ptr->cds[arm_smmu_cdtab_l2_idx(ssid)]; + return &l2->cds[arm_smmu_cdtab_l2_idx(ssid)]; } struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, @@ -1208,30 +1208,25 @@ struct arm_smmu_cd *arm_smmu_alloc_cd_ptr(struct arm_smmu_master *master, might_sleep(); iommu_group_mutex_assert(master->dev); - if (!cd_table->cdtab) { + if (!arm_smmu_cdtab_allocated(cd_table)) { if (arm_smmu_alloc_cd_tables(master)) return NULL; } if (cd_table->s1fmt == STRTAB_STE_0_S1FMT_64K_L2) { unsigned int idx = arm_smmu_cdtab_l1_idx(ssid); - struct arm_smmu_l1_ctx_desc *l1_desc; + struct arm_smmu_cdtab_l2 **l2ptr = &cd_table->l2.l2ptrs[idx]; - l1_desc = &cd_table->l1_desc[idx]; - if (!l1_desc->l2ptr) { + if (!*l2ptr) { dma_addr_t l2ptr_dma; - l1_desc->l2ptr = dma_alloc_coherent( - smmu->dev, - CTXDESC_L2_ENTRIES * sizeof(struct arm_smmu_cd), - &l2ptr_dma, GFP_KERNEL); - if (!l1_desc->l2ptr) + *l2ptr = dma_alloc_coherent(smmu->dev, sizeof(**l2ptr), + &l2ptr_dma, GFP_KERNEL); + if (!*l2ptr) return NULL; - arm_smmu_write_cd_l1_desc( - &((struct arm_smmu_cdtab_l1 *) - cd_table->cdtab)[idx], - l2ptr_dma); + arm_smmu_write_cd_l1_desc(&cd_table->l2.l1tab[idx], + l2ptr_dma); /* An invalid L1CD can be cached */ arm_smmu_sync_cd(master, ssid, false); } @@ -1336,7 +1331,7 @@ void arm_smmu_clear_cd(struct arm_smmu_master *master, ioasid_t ssid) struct arm_smmu_cd target = {}; struct arm_smmu_cd *cdptr; - if (!master->cd_table.cdtab) + if (!arm_smmu_cdtab_allocated(&master->cd_table)) return; cdptr = arm_smmu_get_cd_ptr(master, ssid); if (WARN_ON(!cdptr)) @@ -1346,8 +1341,6 @@ void arm_smmu_clear_cd(struct arm_smmu_master *master, ioasid_t ssid) static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master) { - int ret; - size_t l1size; size_t max_contexts; struct arm_smmu_device *smmu = master->smmu; struct arm_smmu_ctx_desc_cfg *cd_table = &master->cd_table; @@ -1358,71 +1351,67 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master) if (!(smmu->features & ARM_SMMU_FEAT_2_LVL_CDTAB) || max_contexts <= CTXDESC_L2_ENTRIES) { cd_table->s1fmt = STRTAB_STE_0_S1FMT_LINEAR; - cd_table->num_l1_ents = max_contexts; + cd_table->linear.num_ents = max_contexts; - l1size = max_contexts * sizeof(struct arm_smmu_cd); + cd_table->linear.table = dma_alloc_coherent( + smmu->dev, max_contexts * sizeof(struct arm_smmu_cd), + &cd_table->cdtab_dma, GFP_KERNEL); + if (!cd_table->linear.table) + return -ENOMEM; } else { cd_table->s1fmt = STRTAB_STE_0_S1FMT_64K_L2; - cd_table->num_l1_ents = DIV_ROUND_UP(max_contexts, - CTXDESC_L2_ENTRIES); + cd_table->l2.num_l1_ents = + DIV_ROUND_UP(max_contexts, CTXDESC_L2_ENTRIES); - cd_table->l1_desc = kcalloc(cd_table->num_l1_ents, - sizeof(*cd_table->l1_desc), - GFP_KERNEL); - if (!cd_table->l1_desc) + cd_table->l2.l2ptrs = kcalloc(cd_table->l2.num_l1_ents, + sizeof(*cd_table->l2.l2ptrs), + GFP_KERNEL); + if (!cd_table->l2.l2ptrs) return -ENOMEM; - l1size = cd_table->num_l1_ents * - sizeof(struct arm_smmu_cdtab_l1); + cd_table->l2.l1tab = dma_alloc_coherent( + smmu->dev, + cd_table->l2.num_l1_ents * + sizeof(struct arm_smmu_cdtab_l1), + &cd_table->cdtab_dma, GFP_KERNEL); + if (!cd_table->l2.l1tab) { + kfree(cd_table->l2.l2ptrs); + cd_table->l2.l2ptrs = NULL; + return -ENOMEM; + } } - - cd_table->cdtab = dma_alloc_coherent(smmu->dev, l1size, - &cd_table->cdtab_dma, GFP_KERNEL); - if (!cd_table->cdtab) { - dev_warn(smmu->dev, "failed to allocate context descriptor\n"); - ret = -ENOMEM; - goto err_free_l1; - } - return 0; - -err_free_l1: - if (cd_table->l1_desc) { - kfree(cd_table->l1_desc); - cd_table->l1_desc = NULL; - } - return ret; } static void arm_smmu_free_cd_tables(struct arm_smmu_master *master) { int i; - size_t l1size; struct arm_smmu_device *smmu = master->smmu; struct arm_smmu_ctx_desc_cfg *cd_table = &master->cd_table; - if (cd_table->l1_desc) { - for (i = 0; i < cd_table->num_l1_ents; i++) { - if (!cd_table->l1_desc[i].l2ptr) + if (cd_table->s1fmt != STRTAB_STE_0_S1FMT_LINEAR) { + for (i = 0; i < cd_table->l2.num_l1_ents; i++) { + if (!cd_table->l2.l2ptrs[i]) continue; dma_free_coherent(smmu->dev, - sizeof(*cd_table->l1_desc[i].l2ptr), - cd_table->l1_desc[i].l2ptr, - arm_smmu_cd_l1_get_desc(&( - (struct arm_smmu_cdtab_l1 *) - cd_table->cdtab)[i])); + sizeof(*cd_table->l2.l2ptrs[i]), + cd_table->l2.l2ptrs[i], + arm_smmu_cd_l1_get_desc( + &cd_table->l2.l1tab[i])); } - kfree(cd_table->l1_desc); + kfree(cd_table->l2.l2ptrs); - l1size = cd_table->num_l1_ents * - sizeof(struct arm_smmu_cdtab_l1); + dma_free_coherent(smmu->dev, + cd_table->l2.num_l1_ents * + sizeof(struct arm_smmu_cdtab_l1), + cd_table->l2.l1tab, cd_table->cdtab_dma); } else { - l1size = cd_table->num_l1_ents * sizeof(struct arm_smmu_cd); + dma_free_coherent(smmu->dev, + cd_table->linear.num_ents * + sizeof(struct arm_smmu_cd), + cd_table->linear.table, cd_table->cdtab_dma); } - - dma_free_coherent(smmu->dev, l1size, cd_table->cdtab, - cd_table->cdtab_dma); } bool arm_smmu_free_asid(struct arm_smmu_ctx_desc *cd) @@ -2937,7 +2926,7 @@ static void arm_smmu_release_device(struct device *dev) arm_smmu_disable_pasid(master); arm_smmu_remove_master(master); - if (master->cd_table.cdtab) + if (arm_smmu_cdtab_allocated(&master->cd_table)) arm_smmu_free_cd_tables(master); kfree(master); } diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 7ed8d53423cf56..35879064c0f725 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -616,20 +616,30 @@ struct arm_smmu_ctx_desc { struct mm_struct *mm; }; -struct arm_smmu_l1_ctx_desc { - struct arm_smmu_cdtab_l2 *l2ptr; -}; - struct arm_smmu_ctx_desc_cfg { - __le64 *cdtab; + union { + struct { + struct arm_smmu_cd *table; + unsigned int num_ents; + } linear; + struct { + struct arm_smmu_cdtab_l1 *l1tab; + struct arm_smmu_cdtab_l2 **l2ptrs; + unsigned int num_l1_ents; + } l2; + }; dma_addr_t cdtab_dma; - struct arm_smmu_l1_ctx_desc *l1_desc; - unsigned int num_l1_ents; u8 s1fmt; /* log2 of the maximum number of CDs supported by this table */ u8 s1cdmax; }; +static inline bool +arm_smmu_cdtab_allocated(struct arm_smmu_ctx_desc_cfg *cfg) +{ + return cfg->linear.table || cfg->l2.l1tab; +} + struct arm_smmu_s2_cfg { u16 vmid; };