From patchwork Mon Nov 18 18:16:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 13878942 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 BAF07D591AC for ; Mon, 18 Nov 2024 18:19:51 +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=ZwekJ1bvjxTbcRKIIV4Je/GlYG+lORvTJsLJLWirXwc=; b=hjYpTDdxCXzgQvLKvL6LPzdAOT 2G7TFKm+eSRU06KfwvjF9rB69+yzt0kBznxU77+C7k4atuO3cZV5ZYxuSG6TmkHLLi0JQa6nplPWv LhRYNRZ6VNEtNVnJFVtSqYwnorROrIOYrA0Uyb/376wyeAzRaP3zGiAacMvs0JRIiziVw5A7akb0x R3Hk8lt1EQR7Y48k6TsDaIuUW5rDWOnnWQYKfqv/rauN7PZY/eXU/rWkYmXu7rY7qZb+KIIFiakk6 N9jYwCECi4tOuXtpucNNdwGitUtaFpsiNpOxlhsGAWXjMkKIQU98EK2pOgtDBH1MtQVTUM/hGyTXd ysec2P5g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tD6Lb-0000000AK1M-2ySP; Mon, 18 Nov 2024 18:19:39 +0000 Received: from mail-northcentralusazlp170120005.outbound.protection.outlook.com ([2a01:111:f403:c105::5] helo=CH5PR02CU005.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tD6Jm-0000000AJco-3cGK for linux-arm-kernel@lists.infradead.org; Mon, 18 Nov 2024 18:17:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=OxmqcKc6KMJcXaq7fKtJB0fE0fd+TSCW3fRO2TO+3Su4a5ZMNsgSUqpCZFcPHvUmxfYd9RzlLIGcMuk2e73fQhq3M3yki/b5tnPIvMP1dp3Pj6MN7mXZ9xFdqrHJ6HXRsKCXD8pt2BLEz2NjP46omPrMgn5gT3ht8oZh3bMNbs9pUSVS1BNWGeaTtut5GH0GvmG4OxrwsZva0TEim86pP+G7IxMVzu4+R3ohlTF02kEztnjotm2tgaJIXBE5/cRcZGj3BFE0Kw9ZDvh9rE3T7VQwZBpJKCC07zFpfP08JY06OeSVAORbv+Y8tUOqMMLlx42Y2yxNQBJmNTdY+320OQ== 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=ZwekJ1bvjxTbcRKIIV4Je/GlYG+lORvTJsLJLWirXwc=; b=Sx/yFrKuA78Mm7aP/aEQz7UieMuFjTJrdEAQbgBM5bW1w+YrRGywgooxRK0pgb5WmQcVmBilGog7ajJCsYq4OUq/T2dtcbo+3SANQ7PJT0EwE4QRXv0/S6hvVUfnXgls260HYz8bW+SFDRzxmbGk9VrVL1SErE0lVSxpLiCY+U9OfykZIkkkkzBdhk6FzMwC+9CM1M+Q5iFlK8BNGAY3itj8gWbj52Agk2XeU19URURNJZf2KaMcbFfugRxVWHM/HQnGxcUf9dUjPo8/qzzHoL4NoHwZfH3YLMytAtSmbqowbY05ey5PQe/oLDHsBZEKvfw9RWSdv9UtD/Pae6DHfg== 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=ZwekJ1bvjxTbcRKIIV4Je/GlYG+lORvTJsLJLWirXwc=; b=X4DqwS+SBEOU0YsqKS7rUVy6MfI63z5Ng3M+msWougGnTa7Sru8TMrA87FivALpohY0wviZ2tUMPJd5YhLoGSZfYKzi8KiHEzOjQjZe3Zix+NHUunuWeqWoNKXA6aM9gwoi6YEnNj1m1Ty4teTrwuR25iVgypFIpiFKVzFPIppI= 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 CYYPR01MB8601.prod.exchangelabs.com (2603:10b6:930:c5::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.20; Mon, 18 Nov 2024 18:17:39 +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.8182.013; Mon, 18 Nov 2024 18:17:39 +0000 From: Yang Shi To: catalin.marinas@arm.com, will@kernel.org Cc: cl@gentwo.org, scott@os.amperecomputing.com, yang@os.amperecomputing.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 0/3] arm64: support FEAT_BBM level 2 and large block mapping when rodata=full Date: Mon, 18 Nov 2024 10:16:07 -0800 Message-ID: <20241118181711.962576-1-yang@os.amperecomputing.com> X-Mailer: git-send-email 2.41.0 X-ClientProxiedBy: CH0PR13CA0038.namprd13.prod.outlook.com (2603:10b6:610:b2::13) To CH0PR01MB6873.prod.exchangelabs.com (2603:10b6:610:112::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH0PR01MB6873:EE_|CYYPR01MB8601:EE_ X-MS-Office365-Filtering-Correlation-Id: 83eb10a0-2d19-40af-78e4-08dd07fd492d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|52116014|376014|366016|38350700014; X-Microsoft-Antispam-Message-Info: zzrs+WYgTpFGz9Jrl1jnIGoekIMoUHlT/ap3U0RSaJyiiZJjBhmjIZVritvf4GHR757dnA59nX9Z0YQWp8i67Y5NjXOcCD2iUX3FGqHrck5ESpDOxJuMoT9j4vpEuYwUsxW/xc54jUDWk0RyDuyJKq5w0R+yhSoTKe1mjUFXeuPPS1bs0GNEuNGsxOaNiCXjqDKsEcC12+6SvGtRhqBAriTGlmvwR0ksj4qvsIBiAkDj1xr1tdOgOLrAZVJOweb8oYym8ZqXfnRfwhmh6ruTBPA/IuF9ODC/AyqXR5fFnBAWT0zb2ZtzA3vLahFcdkE0HAEmNwlCgHUDZ1Wg/oirvK0QQjKv12xKR9Qbd7tS5/z1agOJfUCIIyPFE7KgW5XkXrYpvpOXVVQzJMcqLICsExii6I74C8urUoFmtD6EUG2ATbQ/TU3VtZW6KpIAUgJ1CCb729jX8vxA7MnlAIKPwr9qVp71WbRcTVXoI3GLNU0D/aFf5s0rj65FrcB73gD7uML+FEZZ6OPSoR0eXC8ty7Z8oJ3X6ajN+AahGH1LNJ+/WBj969derl4KBkDnEJ6qniYsSZt658YudHHTE5VJjXgnvwg9F4LyR4ntDm+dV0FjVQmr4PDI2yWHB7f1BfIXsqr+apehfl6HchWGZKDTrZU1knE5xGfzKZehZjm4RaZ232CuOjkzqeT0d6+PTWT+oYWcZoYqAnX7A2IRE4KSHuGvJgZHV2Q5XFKED7SNsw+982Qdk1JwsDdIClg8Dm9ND2keHMr1ppAbHnVdQGNENoegRttWBRnfbh83xxM4bDzm0FEPw5bHJ+AiLD92zZR6bRUqSd7vnYuTPXLP/AldwlGO3GrHK0K5msLBuXDoRFwBHGHAnjsOLj7o6yGS7707XD4vqdE9TxdfhD2qBPz+75DOcMJXNQ3/ycOcJcdpjKbSH6OJzsQyiLm4h/pP+Jne1TBK6BUnGywQSZO8VNXtVSUUPuxldBLJMDt1mYBPEi/l9RGlhqXmZihSkilQp7HE0GV8ZObeucJiKt8+voefbzhu18BH+8yyngezk4vLfsw3ZIWmrd/B7mqCNgbyXZik6UJ5oI8gVRCBIEJj2Rld34Mey2hZrvzL//FEvJaOGUQcJ08b8QuX+A8a8QGCY6athVRt39S3xBoNgvbqn3F36mAoJMeb6kU7bGLOHwZ0ZOwiVSerILXrpuhIVKQrfP/t6rP5heJufDgzKdaKqlM+CPcwtJ/JHA3syH62YHJIn8a/OMUbO2KtHTCxbCeakq0sERXq9pSfINe7RIBFFM2XnIP4cNmnCAp2WnDkLGdZbtXzz/AL1Pk9BMcx1ILJsGQwJ/YlzX4yiGXkmekewns5hbHhkaeRHNV8ObiRAnt0ZIk= 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)(1800799024)(52116014)(376014)(366016)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: v4oNj2Ql9INaK/GiyLk9bs3vlNp/m72fhfNh5E2eG3JQWtxcyVARyH8AP6LNmep7Fwk1eV6Nek7Nl4K3vev5dSUKEz1fcjzM5lWzTZzDRU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TA24i54rpJ3+LVOFbyPE2eM0d3gVpLw/0uA2tT1nkI/84AezGJaw8hlxGQcwKLu2WIusdPKd8hn41250D9t2wEpffQoRca5QitL+OXysigqXMWAN3xKRJJ3wXQugyswJqnh3OKnq4YTn2S1/BjatGwPyOgTFvevJ6vJS7wm35uuAOzMNcWFSw603uZwB4peIDjg7cTjYhVgu+Jaf+E0U0RH2efTeEp6f/Dx8EMpvI9jVL4H8tUZhY3LP+gVNDxF9+T4wNPPyOFB8c/cjM7j7fWUMP1Za/7qI5CfGvvp+BbOTTyppnCsZniwDbRSP1YxG80Td77vMqWElc4577Hs5hS2Df7ZfDI/a4G5851wo6X8AH4iGTl2/gMAQPIhEpzITHm7JkRAN1PGS7cRqcN/hW5jq61G5ee1hzJgjDfPylM4xXE3BBhBlyg== X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 83eb10a0-2d19-40af-78e4-08dd07fd492d X-MS-Exchange-CrossTenant-AuthSource: CH0PR01MB6873.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2024 18:17:39.3919 (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: +NnOgTt6jwvJTJZPLmwsah553VTcKXwt4Vut7LPjw4rkzWz2t3f54g6uCfQJQ/WC25kn/nquy0k7BWMeQE4gDWGqjAO0852OeRAasb6I/ic= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR01MB8601 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241118_101746_902019_E1BA1817 X-CRM114-Status: GOOD ( 12.68 ) 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 When rodata=full kernel linear mapping is mapped by PTE due to arm's break-before-make rule. This resulted in a couple of problems: - performance degradation - more TLB pressure - memory waste for kernel page table There are some workarounds to mitigate the problems, for example, using rodata=on, but this compromises the security measurement. With FEAT_BBM level 2 support, splitting large block page table to smaller ones doesn't need to make the page table entry invalid anymore. This allows kernel split large block mapping on the fly. Add kernel page table split support and use large block mapping by default when FEAT_BBM level 2 is supported for rodata=full. When changing permissions for kernel linear mapping, the page table will be split to PTE level. The machine without FEAT_BBM level 2 will fallback to have kernel linear mapping PTE-mapped when rodata=full. With this we saw significant performance boost with some benchmarks with keeping rodata=full security protection in the mean time. The test was done on AmpereOne machine (192 cores, 1P) with 256GB memory and 4K page size + 48 bit VA. Function test (4K/16K/64K page size) - Kernel boot. Kernel needs change kernel linear mapping permission at boot stage, if the patch didn't work, kernel typically didn't boot. - Module stress from stress-ng. Kernel module load change permission for module sections. - A test kernel module which allocates 80% of total memory via vmalloc(), then change the vmalloc area permission to RO, then change it back before vfree(). Then launch a VM which consumes almost all physical memory. - VM with the patchset applied in guest kernel too. - Kernel build in VM with patched guest kernel. Memory consumption Before: MemTotal: 258988984 kB MemFree: 254821700 kB After: MemTotal: 259505132 kB MemFree: 255410264 kB Around 500MB more memory are free to use. The larger the machine, the more memory saved. Performance benchmarking * Memcached We saw performance degradation when running Memcached benchmark with rodata=full vs rodata=on. Our profiling pointed to kernel TLB pressure. With this patchset we saw ops/sec is increased by around 3.5%, P99 latency is reduced by around 9.6%. The gain mainly came from reduced kernel TLB misses. The kernel TLB MPKI is reduced by 28.5%. The benchmark data is now on par with rodata=on too. * Disk encryption (dm-crypt) benchmark Ran fio benchmark with the below command on a 128G ramdisk (ext4) with disk encryption (by dm-crypt). fio --directory=/data --random_generator=lfsr --norandommap --randrepeat 1 \ --status-interval=999 --rw=write --bs=4k --loops=1 --ioengine=sync \ --iodepth=1 --numjobs=1 --fsync_on_close=1 --group_reporting --thread \ --name=iops-test-job --eta-newline=1 --size 100G The IOPS is increased by 90% - 150% (the variance is high, but the worst number of good case is around 90% more than the best number of bad case). The bandwidth is increased and the avg clat is reduced proportionally. * Sequential file read Read 100G file sequentially on XFS (xfs_io read with page cache populated). The bandwidth is increased by 150%. Yang Shi (3): arm64: cpufeature: detect FEAT_BBM level 2 arm64: mm: support large block mapping when rodata=full arm64: cpufeature: workaround AmpereOne FEAT_BBM level 2 arch/arm64/include/asm/cpufeature.h | 24 ++++++++++++++++++ arch/arm64/include/asm/pgtable.h | 7 +++++- arch/arm64/kernel/cpufeature.c | 11 ++++++++ arch/arm64/mm/mmu.c | 31 +++++++++++++++++++++-- arch/arm64/mm/pageattr.c | 173 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- arch/arm64/tools/cpucaps | 1 + 6 files changed, 238 insertions(+), 9 deletions(-)