From: "Ritesh Harjani (IBM)" <ritesh.list@gmail.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: kasan-dev@googlegroups.com, linux-mm@kvack.org,
Marco Elver <elver@google.com>,
Alexander Potapenko <glider@google.com>,
Heiko Carstens <hca@linux.ibm.com>,
Michael Ellerman <mpe@ellerman.id.au>,
Nicholas Piggin <npiggin@gmail.com>,
Madhavan Srinivasan <maddy@linux.ibm.com>,
Christophe Leroy <christophe.leroy@csgroup.eu>,
Hari Bathini <hbathini@linux.ibm.com>,
"Aneesh Kumar K . V" <aneesh.kumar@kernel.org>,
Donet Tom <donettom@linux.vnet.ibm.com>,
Pavithra Prakash <pavrampu@linux.vnet.ibm.com>,
LKML <linux-kernel@vger.kernel.org>,
"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>
Subject: [RFC RESEND v2 00/13] powerpc/kfence: Improve kfence support
Date: Tue, 15 Oct 2024 07:03:23 +0530 [thread overview]
Message-ID: <cover.1728954719.git.ritesh.list@gmail.com> (raw)
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
next reply other threads:[~2024-10-15 1:33 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-15 1:33 Ritesh Harjani (IBM) [this message]
2024-10-15 1:33 ` [RFC RESEND v2 01/13] mm/kfence: Add a new kunit test test_use_after_free_read_nofault() Ritesh Harjani (IBM)
2024-10-15 1:33 ` [RFC RESEND v2 02/13] powerpc: mm: Fix kfence page fault reporting Ritesh Harjani (IBM)
2024-10-15 6:42 ` Christophe Leroy
2024-10-15 8:19 ` Ritesh Harjani
2024-10-15 1:33 ` [RFC RESEND v2 03/13] book3s64/hash: Remove kfence support temporarily Ritesh Harjani (IBM)
2024-10-15 1:33 ` [RFC RESEND v2 04/13] book3s64/hash: Refactor kernel linear map related calls Ritesh Harjani (IBM)
2024-10-15 1:33 ` [RFC RESEND v2 05/13] book3s64/hash: Add hash_debug_pagealloc_add_slot() function Ritesh Harjani (IBM)
2024-10-15 1:33 ` [RFC RESEND v2 06/13] book3s64/hash: Add hash_debug_pagealloc_alloc_slots() function Ritesh Harjani (IBM)
2024-10-15 1:33 ` [RFC RESEND v2 07/13] book3s64/hash: Refactor hash__kernel_map_pages() function Ritesh Harjani (IBM)
2024-10-15 1:33 ` [RFC RESEND v2 08/13] book3s64/hash: Make kernel_map_linear_page() generic Ritesh Harjani (IBM)
2024-10-15 1:33 ` [RFC RESEND v2 09/13] book3s64/hash: Disable debug_pagealloc if it requires more memory Ritesh Harjani (IBM)
2024-10-15 1:33 ` [RFC RESEND v2 10/13] book3s64/hash: Add kfence functionality Ritesh Harjani (IBM)
2024-10-15 1:33 ` [RFC RESEND v2 11/13] book3s64/radix: Refactoring common kfence related functions Ritesh Harjani (IBM)
2024-10-15 1:33 ` [RFC RESEND v2 12/13] book3s64/hash: Disable kfence if not early init Ritesh Harjani (IBM)
2024-10-15 1:33 ` [RFC RESEND v2 13/13] book3s64/hash: Early detect debug_pagealloc size requirement Ritesh Harjani (IBM)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cover.1728954719.git.ritesh.list@gmail.com \
--to=ritesh.list@gmail.com \
--cc=aneesh.kumar@kernel.org \
--cc=christophe.leroy@csgroup.eu \
--cc=donettom@linux.vnet.ibm.com \
--cc=elver@google.com \
--cc=glider@google.com \
--cc=hbathini@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=mpe@ellerman.id.au \
--cc=npiggin@gmail.com \
--cc=pavrampu@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).