From patchwork Fri Oct 18 17:29:41 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: 13842082 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 7BFA0D3DEA0 for ; Fri, 18 Oct 2024 17:30:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 093E76B0089; Fri, 18 Oct 2024 13:30:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0420F6B008A; Fri, 18 Oct 2024 13:30:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E4C4B6B008C; Fri, 18 Oct 2024 13:30:22 -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 C6EB96B0089 for ; Fri, 18 Oct 2024 13:30:22 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id BE57A141BA3 for ; Fri, 18 Oct 2024 17:30:09 +0000 (UTC) X-FDA: 82687411380.08.DEE92E9 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) by imf20.hostedemail.com (Postfix) with ESMTP id E2CE81C0028 for ; Fri, 18 Oct 2024 17:30:06 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Nq+gAA2v; spf=pass (imf20.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.215.172 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=1729272425; 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=/kexGPHg7BP7JEy0b70rSKtUMi9zN66ceCEdb7Ha4D0=; b=xt4M01FuFCgZOi7iJKpZ5EsT8FJSnttNgs9LKIvknBDQ1g5Qn3Mq8s5BcxWvqx03CPiZKi MFtJ1QNLtZ4O2mIJ8tRf1JfSGjj/AXKb6soSgn73CIr82lzRao+sGOzgLDttfgUyJtxzRX D6UGrsPzZRf4zS+mKDzTNmy5HVIB1x4= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Nq+gAA2v; spf=pass (imf20.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.215.172 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729272425; a=rsa-sha256; cv=none; b=RcTKInPs+Vaxrui5dOa5XFVmdM5idHMCRKO57OVrNSogIEe0Opf4u05SO1ci8M203ksQea yT502wT/3P3ZNII0vItoMr3nsn5ZpdreQf0k0b+bDeJPB3ACu+uct9hQPk5GpW0A0UfeXM 1DrZc6HY4k4IOMXOKcUHx6Hq3Pn2ie4= Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-7db637d1e4eso2452978a12.2 for ; Fri, 18 Oct 2024 10:30:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729272619; x=1729877419; 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=/kexGPHg7BP7JEy0b70rSKtUMi9zN66ceCEdb7Ha4D0=; b=Nq+gAA2vT+KKoqQZOaFaodHo4KBrzNuGTYCtuqsW/c8yplBb2SWzL0wVTgATQ6bv0H Z6mydT42odBYGBcZNaiQBGjRxnZFLwu+kpr5leUIKi1Qyxjxek0cq+bHp28WUcDMhf+t R1N86qSWWMRl+QG471KIDbg+vMd3w8ty0BDJ7Cc0l7LW+HWhPXA37v5p8nlOojGpzLyJ 8Hd+lsX2Ey91sCfdvodV9EIE/0xGkX7KDLHwghwlX7T83C/Pz7Xs7iWJ4DS1K/DtwfQn 333+k9D0lyqAtQ1mcOJ9uc2ceTZ3MlQPMNRT9qKtj0KYpgTB21Rz7yDMimMwHteaI+1a tNZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729272619; x=1729877419; 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=/kexGPHg7BP7JEy0b70rSKtUMi9zN66ceCEdb7Ha4D0=; b=m4k2JxNu51KaLvORpfijaMNB5SeDl4fPej2JblmeZ+ewwholMFjMmnkO/pHTYSXPQ5 TozjpStN9zEOcjeUeX2y9I06JScBHEjSxypO38fQI5l0KpnfNHa/8z6wL9+PRvr1q7b/ ey/kTv6mEeMTH6u6AmipF96vugifsSbZ4adkjbexJW/ZyIhP6b64mCzX40euvsy1uY+d qzxuNDJ9U/Xl3ANQsziYAtaeKXoY3XPGR/FqyEInVSBe03gaJdweteWs6hHO5LDeLzIY 4dd1y7ZI6gTWU5H9d2WLqnuvGBAHPJ1dUooyKl9Fk3zuVzcu7RGFM0AeB635HZgtpdaZ D0sw== X-Forwarded-Encrypted: i=1; AJvYcCXNYmKFJDXXn8foKgCp37d6EUbaqckLm8HQZ4tUd2NBtICpE/ejV8kCT4VvMJANDXcO3vmjwYssdA==@kvack.org X-Gm-Message-State: AOJu0YzM8ulaaULsmD2RVGbq2aHFBf1HDABERt9sdxeL/01hsKhSU3RV xkO9n3TNBWnHbmz6Gnwpv/bYk0W9uk1pfx4kgGkl/OKxbS4VpaYs X-Google-Smtp-Source: AGHT+IEbOGLNKLJrJFImzQpsiOOXU0drvvKYT531il5KzE7IqW3k2drNkmi6NFk+P7Ia/vyxbbkhgQ== X-Received: by 2002:a05:6a21:164a:b0:1d6:e6b1:120f with SMTP id adf61e73a8af0-1d92c4dffb5mr4996670637.11.1729272619178; Fri, 18 Oct 2024 10:30:19 -0700 (PDT) Received: from dw-tp.ibmuc.com ([171.76.80.151]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ea3311f51sm1725242b3a.36.2024.10.18.10.30.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 10:30:16 -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: [PATCH v3 00/12] powerpc/kfence: Improve kfence support (mainly Hash) Date: Fri, 18 Oct 2024 22:59:41 +0530 Message-ID: X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: E2CE81C0028 X-Stat-Signature: n343torc4bk15ixrx5sucx1r41cty3wy X-Rspam-User: X-HE-Tag: 1729272606-276856 X-HE-Meta: U2FsdGVkX1+AfMLeiOCInsWkrWX2nlUouFbL064o8VNhXpNXymFf/PK8NpPB0vyMGz+m6cxausjz37vtxK8fzkOy+hPBtxNWPD2JRkfXGOx4CUJ0XxiJFBGilEsqkEybnYIl2aC6kKN5K78DRyUuEpMaNcAq2pjw3tYXUTl4vbepsYYePGJA03RCcpbx4RK7QPON+L+EQcP3iElGVLFJGCWZQ/4AqIsap9FLJyn8ePxr60rQ2pIEXRMq1ECUikkQC5y2f1wt4mof+F8qsIW0SnT1SaIPc6l5/Y6nE49Pu/eI+7u7xFD/R37gGK3XXptquccnvTIdt9WQeP4v9c8yMwqa+AQg+6jMTIqd6zLtG/BvmgyVOX1N/w4ZU2WA2vzHiyZooiLjeEAVsCQoRnBuvYf3/1uO0xeDW1sheTB1UkEUSDBFu4QWjGhm1r8aT3hDZCcRrHHPmC0QDAQIw8UZUlFm2AozlHx+PjyAYDTj0u5Lt05rOqr0MzPW4N0I9tCIuV5gqRekk+zkHuwSDy6Ra3a2u4baQp5IeCmaSyIlFQbgeXPHccZMAnLnh098WzEktut0XpZfAB+IWjfN7A6d0rSNqhj0ZIWTUyczt7QGV3Vb252qtFhJHMkaoKTlIdC6nhMA8IiMe1aC0X+aB9vuz+orBz/N3T9wFeBdpR0ObReIzQ4QFxVB7MZFyy/YMV97tBYfTubD8XK9QG24/DkiQrC8zgaNZ/gS6BXuB5t1Bs4/abYAMpldml+zzv4geExV77BB5wUb6he00aFnYgxd/VB9n3Na83GRZQow/x9lTywqIAyzH+DGQzF2u5gpvHkoUfYDnvLSdvjemO6MnBYjoMdHBfhDlIHp0WGYrC2cr/jAbhzvbNPJTzgTNlNWm83pmf+1jVBkse/mpp9z2oOvgc8hpzC/oFVwOGMnSS26xXONJRCh90pQlHdftAMqyvG0y3XjM7fy4UEhmjoqDRR 22fhrpmI vp4cdNVCIL4KQ8K67SR6EF/R9hPpUp6M0y871O+zCAITPs7sJuEzNw6EF/d+SpKKerG65UjFCWH3v6p7cNiXHQno72zI/FNJZQUTbTSWylhtowWt+WdSNs+Ks0T/N4+BgrmY+HsBrHxr1bk0YGu3bQluheaATnab/od+Lic/VP+dMLlbO1bFyD0mrcv76EK37aZtyRlotC+zL9C+x//6pK1S9pe8ZzryA9h6kqUdGGUb+lfEm8Ms6zYUKLn4vw1u065xNOJ+AaJ9e+ZM3C5uMctPUfT0y/BuZjg46 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: v2 -> v3: ============ 1. Addressed review comments from Christophe in patch-1: To check for is_kfence_address before doing search in exception tables. (Thanks for the review!) 2. Separate out patch-1, which will need a separate tree for inclusion and review from kfence/kasan folks since it's a kfence kunit test. [v2]: https://lore.kernel.org/linuxppc-dev/cover.1728954719.git.ritesh.list@gmail.com/ Not much of the change from last revision. I wanted to split this series up and drop the RFC tag so that this starts to look ready for inclusion before the merge window opens for powerpc-next testing. Kindly let me know if anything is needed for this. -ritesh Summary: ========== 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/ Patch-1, 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 ================== Patch-1 adds a fix to handle this false negatives from copy_from_kernel_nofault(). Patch[2-8] 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-9: 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-10 & Patch-11: Ensure late initialization of kfence is disabled for both Hash and Radix due to linear mapping size limiations. Commit gives more description. Patch-12: 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. Ritesh Harjani (IBM) (12): powerpc: mm/fault: 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 | 11 +- arch/powerpc/mm/init-common.c | 1 + 6 files changed, 301 insertions(+), 108 deletions(-) --- 2.46.0