From patchwork Tue Oct 15 01:33:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ritesh Harjani (IBM)" X-Patchwork-Id: 13835646 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 361A9CFC505 for ; Tue, 15 Oct 2024 01:33:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A88766B0085; Mon, 14 Oct 2024 21:33:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A38AF6B0088; Mon, 14 Oct 2024 21:33:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8D9876B0089; Mon, 14 Oct 2024 21:33:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6F5726B0085 for ; Mon, 14 Oct 2024 21:33:50 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6E5C6140590 for ; Tue, 15 Oct 2024 01:33:41 +0000 (UTC) X-FDA: 82674114852.16.F1290C6 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by imf14.hostedemail.com (Postfix) with ESMTP id 4F028100004 for ; Tue, 15 Oct 2024 01:33:40 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=YOd80oJr; spf=pass (imf14.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.215.180 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728955885; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=/FgRTRf0le7Jh2w75CMwMOtbUSojhg+y46VXsqNVeW4=; b=4fWQE5+fOLT+XwvpEtYZYxjqhlQWoXzPlFMve7xj8Y1jv3skOiS4NFnQGCjx8pbGdj0UiE Gn7QfWJtfqD5zfO/X9Pdx5MIC3LPpJEh/tqF2DpXAgoRua3t0jsJGt/8acGEimaAd19tOK S89B5c5+g5uvLYnvej5WYxErmJ3MNP0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728955885; a=rsa-sha256; cv=none; b=Na4nMDO+kM5j66Ifbd+FC+qoKU/4XQewtXCJ1/F0VmIzRpOVeD8XBsVBTxsfaYVgUdlMl4 JmEXJ7p3LQh/scDVC5/VbGIzT7rbZwgxOPC7sgCjxSdMQeaa89FWp69NTt9lkKnPob5ePJ 8cPIb5cPmthuZmcjzpR9gbg92tbSvog= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=YOd80oJr; spf=pass (imf14.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.215.180 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-656d8b346d2so3051714a12.2 for ; Mon, 14 Oct 2024 18:33:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728956027; x=1729560827; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=/FgRTRf0le7Jh2w75CMwMOtbUSojhg+y46VXsqNVeW4=; b=YOd80oJrDqqxwUmsJZ/0poemvUzq+Qdd8Aw6QrhWbICUiQmKm5WtnAvPQqlvH4Yio0 OWOP8RSATXP/0ApwCdYxr0EWWOjJsQRd/s3U/sc3ZRrY6ThpBhCXSX+aI4AA74iEdOZ3 TytGXEWYovGDfDpgnzmwAvg1HZ2goHAZVIw1ZOkgqJUwhZx/ICIF/zDp/HsavNwUaT1v 8n4SbxsecC7VFvzEt48+VBiwqV5oX8JenFs6dj501aS8CLomXXdlIxdLRZMky3h09v9b p84TgoLh8uTH9LYGt6NNpVMJlsJ13SqSfD0lUd/vN/XHgBVDr7Pm0GVUfrodOcFNPiZg ojkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728956027; x=1729560827; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=/FgRTRf0le7Jh2w75CMwMOtbUSojhg+y46VXsqNVeW4=; b=LFIIrXGPjc/SWBcZbwjT6Tw+gn6MYqe3Z8PuIvHu3+lyyacUKkQswS49O/f/xxqXhr 3b7xDXWX/Ar2xvU/b6VoVJ4mOUuza8xb8x0Oj17NSFEMgU8VfCorbf/SJ3mJUEulL4HC zZuqapN5JHWDTbx/IuofOhic8pN2p0GiQ08N8RMX0WAlqsBPzddJAGl5ISXTa4RWpwoi 1/DqxTuYQ7iAW04N3NU3oAvhAJ8zOAItg9oRLMg9F9P3ijA1YESSVcQKB3DMsGIJ6h9n aR+lVcFWZPW+pMDB71CSAt1yYWUo/7Fw0n4m8+sayqHRUGw175TAqwG3qqRYIg5PNSej tNSQ== X-Forwarded-Encrypted: i=1; AJvYcCVMfdEIbFF08ldCBsUSOIewAUOCHqLxlOKrL2d5yWG2/WovU91x7MC/qkdWESmuVXhkL6xuQpS34Q==@kvack.org X-Gm-Message-State: AOJu0YzqzSlNGXnRsZC0WpO+n/gfuMMn09X46e4UORzKUqHrxLMIUuta wxt+VNctavXnaqfJveOXqWxbiWxo4mesZlOL0umjqzhv2qqffWjV X-Google-Smtp-Source: AGHT+IE2VbhYvinnTtnp8gdiPFs7AssOulNu8P5FQjpDVoCidl6hRwDILWFOZsBNBRYKYFDJk0Ss8Q== X-Received: by 2002:a05:6a20:9f4a:b0:1d5:1729:35ec with SMTP id adf61e73a8af0-1d8c955c8ebmr16914023637.7.1728956026633; Mon, 14 Oct 2024 18:33:46 -0700 (PDT) Received: from dw-tp.. ([171.76.80.151]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e77508562sm189349b3a.186.2024.10.14.18.33.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 18:33:45 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linuxppc-dev@lists.ozlabs.org Cc: kasan-dev@googlegroups.com, linux-mm@kvack.org, Marco Elver , Alexander Potapenko , Heiko Carstens , Michael Ellerman , Nicholas Piggin , Madhavan Srinivasan , Christophe Leroy , Hari Bathini , "Aneesh Kumar K . V" , Donet Tom , Pavithra Prakash , LKML , "Ritesh Harjani (IBM)" Subject: [RFC RESEND v2 00/13] powerpc/kfence: Improve kfence support Date: Tue, 15 Oct 2024 07:03:23 +0530 Message-ID: X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 4F028100004 X-Stat-Signature: 6gauq7c16mh1pbg66tp49c3onjcbqbod X-HE-Tag: 1728956020-122675 X-HE-Meta: U2FsdGVkX191nz5joqwuMQWo0Dv2eiF8gcoTb59NJ4U7/k8uT/bGjxZ/Bh/eKzx/j3eN6llEsB9LixN7MaY1nTVI/kdP2TAAoJBeuKnZvTulsYMmrnB/uFplWNLKC4dVVEjl+7yu92TFQY02qquGqW74gla08SisGEODLJePV440751ouRLOFetZHFPLzOz6TtPN4LXvNRgTD3QoQz5RUW5P2+wLDKqCKQd6zdj2VqxHl8BkZJS2LxT9j8VI/XTI6ZsYBGj1UGgh0zVoAvs34+5cZUGsvuWYn+v4cE8PgmCCHe9ukVu+ZMw99Dgt8coN5SgQquJ3TlCm1tbBg24OsOUsHlTKyZ9tQu4BkDukJgQlNGsUm0lftiJXOvUlbL27Xnt03BOYrBTdj9wB3PnHXFLf9trHzM4H2plgX0JEihWaMQ8xoDbYuiMzPiSOIlnL19dMJ/518wI2rogIerKKF9+ivww9cdMyM5vFsFge6L2bpbNg8Vj1+s+WhO7h4u0MVu5LwcczfNP+4rgYFIZ+N+9k64WVsRbldrGUbXFRSdJ4GGHzzsdp77xCd9XvcByOeir2NIwQcX67tv1/XJ+Hj85IHqboXEiDAV2R6JeccTd9HjizoUmiErZuE+mE/hS+NFoDH6dEOAglSTIzxxANFXEH8htCyq2/KPqDn4+90V26xGZogDs13jBuu+JdD/1pslQl0JaE7EmR0lr12vtAEFhar37EnQ2f4D7hxCOobcORnGPK1wxyH4ivQBxwOR0OZlas8WRzrH8/GLpMSefROSVrJzOljdgTlIqlxcxfVafKWUDSa2lqOuBHl5YQ76OYqmRhj7F5NSFFzLkWYUq2RKPKA0n6Uq1P5xIyzjJ4SmYokqseRuhJ0sKN7Ekxyqv+2flbqpdSSQnjc/y1fBV8OAO/varRIZR6W97Tb0oA206tZh7qnlqNzg6dY0eGzNxqJ2MVaun8BPbAbHEp0aU kaQV8Dyw c8aLLw0uA5ueEeLLlJO8Mna69slKyYhH0jnikXtfz6tfL8h9gtQdeNm6lZA0oZ9ciJBfieBKa32BXSP4G8knm3KKH2CjJWy5Si7r9J0Pv2lgojzvRH4u4wFNDN/Yj55W8jaQvi0nROtrWJI9mUGpRQgmDAgtTU97mpRamnnEFZe/8vtw9vxGlwta+xegNQC+LnkVSP7e9gjpKtjvVxHkS5GRxStKG0sI8BboycGQ8nvZE90LKpiG6SvxD0DsvBbOdJiFkqZrnWOK+SdNMyhhv4LW+qwHvChdGlT8N X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Resending v2 for review comments. This patch series addresses following to improve kfence support on Powerpc. 1. Usage of copy_from_kernel_nofault() within kernel, such as read from /proc/kcore can cause kfence to report false negatives. This is similar to what was reported on s390. [1] [1]: https://lore.kernel.org/all/20230213183858.1473681-1-hca@linux.ibm.com/ Hence this series adds patch-1 as a kfence kunit test to detect copy_from_kernel_nofault() case. I assume the same might be needed for all other archs as well (Please correct if this understanding is wrong). Patch-2, thus adds a fix to handle this case in ___do_page_fault() for powerpc. 2. (book3s64) Kfence depends upon debug_pagealloc infrastructure on Hash. debug_pagealloc allocates a linear map based on the size of the DRAM i.e. 1 byte for every 64k page. That means for a 16TB DRAM, it will need 256MB memory for linear map. Memory for linear map on pseries comes from RMA region which has size limitation. On P8 RMA is 512MB, in which we also fit crash kernel at 256MB, paca allocations and emergency stacks. That means there is not enough memory in the RMA region for the linear map based on DRAM size (required by debug_pagealloc). Now kfence only requires memory for it's kfence objects. kfence by default requires only (255 + 1) * 2 i.e. 32 MB for 64k pagesize. Summary of patches ================== This series in Patch-1 adds a kfence kunit testcase to detect copy_from_kernel_nofault() case. I assume the same should be needed for all other archs as well. Patch-2 adds a fix to handle this false negatives from copy_from_kernel_nofault(). Patch[3-9] removes the direct dependency of kfence on debug_pagealloc infrastructure. We make Hash kernel linear map functions to take linear map array as a parameter so that it can support debug_pagealloc and kfence individually. That means we don't need to keep the size of the linear map to be DRAM_SIZE >> PAGE_SHIFT anymore for kfence. Patch-10: Adds kfence support with above (abstracted out) kernel linear map infrastructure. With it, this also fixes, the boot failure problem when kfence gets enabled on Hash with >=16TB of RAM. Patch-11 & Patch-12: Ensure late initialization of kfence is disabled for both Hash and Radix due to linear mapping size limiations. Commit gives more description. Patch-13: Early detects if debug_pagealloc cannot be enabled (due to RMA size limitation) so that the linear mapping size can be set correctly during init. Testing: ======== It passes kfence kunit tests with Hash and Radix. [ 44.355173][ T1] # kfence: pass:27 fail:0 skip:0 total:27 [ 44.358631][ T1] # Totals: pass:27 fail:0 skip:0 total:27 [ 44.365570][ T1] ok 1 kfence Future TODO: ============ When kfence on Hash gets enabled, the kernel linear map uses PAGE_SIZE mapping rather than 16MB mapping. This should be improved in future. v1 -> v2: ========= 1. Added a kunit testcase patch-1. 2. Fixed a false negative with copy_from_kernel_nofault() in patch-2. 3. Addressed review comments from Christophe Leroy. 4. Added patch-13. Nirjhar Roy (1): mm/kfence: Add a new kunit test test_use_after_free_read_nofault() Ritesh Harjani (IBM) (12): powerpc: mm: Fix kfence page fault reporting book3s64/hash: Remove kfence support temporarily book3s64/hash: Refactor kernel linear map related calls book3s64/hash: Add hash_debug_pagealloc_add_slot() function book3s64/hash: Add hash_debug_pagealloc_alloc_slots() function book3s64/hash: Refactor hash__kernel_map_pages() function book3s64/hash: Make kernel_map_linear_page() generic book3s64/hash: Disable debug_pagealloc if it requires more memory book3s64/hash: Add kfence functionality book3s64/radix: Refactoring common kfence related functions book3s64/hash: Disable kfence if not early init book3s64/hash: Early detect debug_pagealloc size requirement arch/powerpc/include/asm/kfence.h | 8 +- arch/powerpc/mm/book3s64/hash_utils.c | 364 +++++++++++++++++------ arch/powerpc/mm/book3s64/pgtable.c | 13 + arch/powerpc/mm/book3s64/radix_pgtable.c | 12 - arch/powerpc/mm/fault.c | 10 +- arch/powerpc/mm/init-common.c | 1 + mm/kfence/kfence_test.c | 17 ++ 7 files changed, 318 insertions(+), 107 deletions(-) --- 2.46.0