From patchwork Mon Nov 25 17:16:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 13885155 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 62352D58D6C for ; Mon, 25 Nov 2024 17:19:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding: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:In-Reply-To:References:List-Owner; bh=VKGrHXzPjTMtOu8xNtZ4fL4TvJqYyj5I1qgj12mvHz8=; b=OEx1IcKV7/VdSBgrx79ggkI8qN cYwYsqNrB5J8HwjYkPFLaVmQmrkAtJPbkVhHdX8NZ/3mbaqLWUy9PHc8ELCMQp4Oq8BVy5pMdslkc rWoRdDn3uJosHu6qGK+3MzmFttH4/MS8Zzxt7o+IuE0IIxuUXo2T6H2REip8+FFmlLBalfvzbTono EDDcGJWGYMFiyALypaMxnfOam7YoCB0QgDGXnajda2M3a0BAgAf4bxSGI10Ebxbmu1MiyzhWibirs eNKC7Iblp4IKmSjD5iM9tq3fltXKvN7Aj7wViGIya5nyPYOeYurpMd7Bj9ePbNgQBZyV/5U26Fdft 48LGTMEA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tFcjs-00000008joS-07Zb; Mon, 25 Nov 2024 17:19:08 +0000 Received: from mail-mw2nam04on20724.outbound.protection.outlook.com ([2a01:111:f403:240a::724] helo=NAM04-MW2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tFci5-00000008jVU-0qka for linux-arm-kernel@lists.infradead.org; Mon, 25 Nov 2024 17:17:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=EwJQi2Zt7VOAW9xJFy/XEI433y0Nb6sr6LhqgtXISYpFrWthWyp0+xAdjc2xE4v5o9kKMViNHk6wG0A519dbRfsA6m/Xgwxy8YC4NFO4OavEC8m+JyS8ZgHx5Yb49wCQ9IE0zVAZTYnjC9Yr1IN5FIHdnQq2jVGujEeGW11Lh1eBvfyIBBvvaNEvu/yPnGMJqrJp4/jtivDhlaH6IiJuq5XoFZgU1rpuXJIICWVQsLM7lQPvAzRc0RK0UmCBaHXy75B+TO7qP/UWka92xSFl++lrGvHgMUlsHa/k3vNOmQwr0UCY1FvqfFoqEfImNTfZJRo/3bEEq8mAQCSta1p2gA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=VKGrHXzPjTMtOu8xNtZ4fL4TvJqYyj5I1qgj12mvHz8=; b=ihrHu29c//w6h8NaiuZNsC2DM7vO16TcOLdvpJ7O0g6EQou+us8vld2zYZdvPwmmRntqESC3Tl9bPbKZfp45zOv2l37nbk2tEG6d3tRJ2YfgbDavUsQfbbPRihMsfWPH6hFrR+s+alSP9WZal0JbsTsJcqiDbMK5x+RnrjRrml0dg+jQkgd4FmVprcf9DiPU83p/KbCtKgTZYdCyCUP3E+eAxWnQoJg5Db8YCsYyEUOC7sVK9zZ3VRP8DHeAo1U2Wf8qsWx5eTqTdEKPzWCsIR+fHzwDqreRn4x0yRuZUkvyUMp4KX/4GEFu3M/SmZg4s9ggLBplE3NHDVnpqs//NA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VKGrHXzPjTMtOu8xNtZ4fL4TvJqYyj5I1qgj12mvHz8=; b=NTHtikmECyDbTIx4FxxiKpH+k8UJcOMK2SRUAUM52da0TwRfmimj6sE5dTl3P2uTmVJA754Lwq6MwLqnzSEAuVl6yMrO5XRAXvoLFnBkuGDEYzME5YscnbgNGMJ5wTu4FK67OT2KJVG2V7JyjIysjPBCh8Qm6X/GgaYMMvzjUvY= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from CH0PR01MB6873.prod.exchangelabs.com (2603:10b6:610:112::22) by MW4PR01MB6420.prod.exchangelabs.com (2603:10b6:303:70::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.12; Mon, 25 Nov 2024 17:17:06 +0000 Received: from CH0PR01MB6873.prod.exchangelabs.com ([fe80::3850:9112:f3bf:6460]) by CH0PR01MB6873.prod.exchangelabs.com ([fe80::3850:9112:f3bf:6460%4]) with mapi id 15.20.8207.010; Mon, 25 Nov 2024 17:17:06 +0000 From: Yang Shi To: catalin.marinas@arm.com, will@kernel.org, baruch@tkos.co.il, ptesarik@suse.com, hch@lst.de Cc: yang@os.amperecomputing.com, jiangyutang@os.amperecomputing.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] arm64: mm: fix zone_dma_limit calculation Date: Mon, 25 Nov 2024 09:16:50 -0800 Message-ID: <20241125171650.77424-1-yang@os.amperecomputing.com> X-Mailer: git-send-email 2.47.0 X-ClientProxiedBy: YT4PR01CA0445.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:10d::27) To CH0PR01MB6873.prod.exchangelabs.com (2603:10b6:610:112::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH0PR01MB6873:EE_|MW4PR01MB6420:EE_ X-MS-Office365-Filtering-Correlation-Id: 84881333-ab35-4a1e-2a9d-08dd0d74fcad X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|52116014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: Y0+wf+R7hT0FQclPtKl2taMO6oyDGzhg8V5MNydypCKYqwhGKWexSX6SsbLaNN9w9AN4S4Uo0+uo4+ky93mb/LE178lHXFvume1xRgUgJdRfgGjFfnHF6BZ+Tb1peS9iRpnTQE4urWrurVAtniHhA3pCoNA2LcNFhc9ZjeeNBwDhRLUGM3sFt2/crw1kK5vY5z6NB0zxjpaq4J8f12ThFFhgmS9Uao5h5BR4rabb4L9Ild2eoy47YPddR/7BiDzog7fZ0qVLVtYFQHAlguxcjkjCt4Fdd/Xjt50w37qHHGbTSrgVqs6HlpqgzFkRp2REwqVp0z1ynNmlR02ajE5rSL17zp6y5geVm90H9WaFWfQqda88346ZeGjnwRVtiKur7AYjlHpZfjudRm+hxyTqtdDzSJ3QMLl1mrvBcH/iTsooPZIKGww2TqZOYXBhFZF29aSKGycbv1Wx+GMqRarqNiu0ZKCDnTim5jngjHksG6m3QfNWwpuQqQYUU1tT0D5oaZM6LcIOFUUJXUtwZL+DNbwNYCGsWnQCsxCtpncFGhiEq70KUPHX9UC2BJVRTPuasFXL0vfaZeNSOFm2gxYTyT72Myk0/Znt8RjQKmOFhxyhJCPwYHEiRFwQX0q4n/bIbJ7E3sHv6rdDIt/Nz3G6kspIq2vmCQJ6vmDlmQE/o7fo0/8ltWYn8VFjKiac3k8Zc09LmaVYcVTFGcJZzkeOI7PCxxjcURVBPIeWsb6DLnp6g6WXyIJJ1hVhEMK2jnDsLuhOKHmJIsYiSpbSZmr6CGQc209P5zZOADPjFXgzKamMJW5Rfpvr3GHzievxau7rLPCP0EB4C3I7LErbyl90B/ovkjRQLGDZgW7K6R9kaI7jxXYHhru7pTaWhxXSg+k67vNWYJk6HhiNDL6wTyze3v8iaPFxKPTmPTOUGffPdXtyCHn+ZeXDqqlkp2T03HkrxUYT0DkqCiCLLP3ZbPOZyl1UHDpwRoRVlNIE8V2EQOgadRCSiXET4yELww1qLAu8z/uWACAZaGUwyrWZlVQttdyx45CCHCPfc80G0JzyfbepgDvjxAA11vmBJZkmD9LJAqEPTt4Q0rCwRD7hgrPVionTpcH0z4Uqto/5oCOY1mJWeNWbEx/BEI4gOigYFJ3RPapOy3uEL3+A9GSIvHwqi/vs1ArL8gmsSAAX6Xaow1JOWcDQ4ijf7b0qr2bPggCNqwS4Pvuam2CUwCvzErirleAEfU7ybjvUZhsiZFHGDskrUFW5c5GEWWl/bnBIQ6bF6V3+qkR+iHD54yXyl3EN0gxTETGsZioYJaS6eZ7KM4dxOvfSqZMlv9tZT7AodH3JlHo19vVf98hjUlSVF6m2ntlMxcDac9yJnGJEWa9r4sWVz91juvc3Je+Y9RunpG3gtpYDrukxvJ9sXxGYuGKenA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH0PR01MB6873.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(52116014)(1800799024)(366016)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: AsAkfE5pyvwzKxA79AFec1hfcc3w9HOwmWfFfFjQZnmZGP8Pcdw1YAA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ziwF+BEV0Rs1CodJYkXw2uF5qLdHYWcp/WewTEkNioXUYLzU3q5F3H8DRrQymNHSpjrQHWHTOV+cIsdCWsC8g85LN6Vxw3T3cu1YOh0mq876hXzlLGwp4Kg4wjesl6KFsg19PvWDdaWtkxrCeh+AmVFD+E0AXqstChTEvAyLKTdqrxhJYTIjV7kES9WdlHgMA3DJgrBnhSoN6DdE2w1Kgu7LJZHKgnEWUzimzgjsZLd6l3wbCrpXtSmUeMtYTAUldWPBuXvrYgwq4Cz6QrxhuDje+ah/tVUiYxB+Kfjbw+L3XQtCdyt/jelnVgEvSe+XZNeEtkNaGcnqshtHUYM/M0V6pFDtQ/Dk6g8Z8H/Af/36UHs0yB/vs+K8CzDpu9Lz3UyuWI6Aw+e75tKp0thmpTqe9JMVxCNiMYhBl27dy+uFOwv3jJ4GCdGsm7YeubtxM9fyi2uhIVeXqRIG8CBIlzlkcNgs71oayQ9RHMandjJZHVspGe1TI0= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 84881333-ab35-4a1e-2a9d-08dd0d74fcad X-MS-Exchange-CrossTenant-AuthSource: CH0PR01MB6873.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Nov 2024 17:17:06.5029 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Cpse/Pi9+Jj4lLPOT8i8xSdXygeA93LldRax2I4aQq1yYenCSo31g3tRGET/iknfOqLqnkEu3nEF+ZhkNq76yydAu5QoW0LV1gDXO+gjJCU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR01MB6420 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241125_091717_251447_C0545522 X-CRM114-Status: GOOD ( 12.79 ) 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 commit ba0fb44aed47 ("dma-mapping: replace zone_dma_bits by zone_dma_limit") changed how zone_dma_limit was calculated. Now it returns the memsize limit in IORT or device tree instead of U32_MAX if the memsize limit is greater than U32_MAX. This resulted in DMA allocations may use GFP_DMA even though the devices don't require it. It caused regression on our two sockets systems due to excessive remote memory access. Fixes: ba0fb44aed47 ("dma-mapping: replace zone_dma_bits by zone_dma_limit") Cc: [6.12+] Reported-by: Yutang Jiang Tested-by: Yutang Jiang Signed-off-by: Yang Shi --- arch/arm64/mm/init.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index d21f67d67cf5..ccdef53872a0 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -117,15 +117,6 @@ static void __init arch_reserve_crashkernel(void) static phys_addr_t __init max_zone_phys(phys_addr_t zone_limit) { - /** - * Information we get from firmware (e.g. DT dma-ranges) describe DMA - * bus constraints. Devices using DMA might have their own limitations. - * Some of them rely on DMA zone in low 32-bit memory. Keep low RAM - * DMA zone on platforms that have RAM there. - */ - if (memblock_start_of_DRAM() < U32_MAX) - zone_limit = min(zone_limit, U32_MAX); - return min(zone_limit, memblock_end_of_DRAM() - 1) + 1; } @@ -141,6 +132,14 @@ static void __init zone_sizes_init(void) acpi_zone_dma_limit = acpi_iort_dma_get_max_cpu_address(); dt_zone_dma_limit = of_dma_get_max_cpu_address(NULL); zone_dma_limit = min(dt_zone_dma_limit, acpi_zone_dma_limit); + /* + * Information we get from firmware (e.g. DT dma-ranges) describe DMA + * bus constraints. Devices using DMA might have their own limitations. + * Some of them rely on DMA zone in low 32-bit memory. Keep low RAM + * DMA zone on platforms that have RAM there. + */ + if (memblock_start_of_DRAM() < U32_MAX) + zone_dma_limit = min(zone_dma_limit, U32_MAX); arm64_dma_phys_limit = max_zone_phys(zone_dma_limit); max_zone_pfns[ZONE_DMA] = PFN_DOWN(arm64_dma_phys_limit); #endif