From patchwork Fri Oct 18 17:29:42 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: 13842083 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 6427AD3DEA4 for ; Fri, 18 Oct 2024 17:30:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A0B1A6B0092; Fri, 18 Oct 2024 13:30:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8F5D56B0093; Fri, 18 Oct 2024 13:30:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5E8D96B0095; Fri, 18 Oct 2024 13:30:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 3561A6B0092 for ; Fri, 18 Oct 2024 13:30:28 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2AC39805F4 for ; Fri, 18 Oct 2024 17:30:17 +0000 (UTC) X-FDA: 82687411842.15.47535C1 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by imf07.hostedemail.com (Postfix) with ESMTP id E3CE640017 for ; Fri, 18 Oct 2024 17:30:09 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=dxQxbxYL; spf=pass (imf07.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.171 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=1729272430; 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:in-reply-to:references:references:dkim-signature; bh=ZFpXrhpElIx5U0caqw8WXCQdQvrJMpAq6qiRpCPXwmQ=; b=ppAeqdK3KVia2PNafrgp9t+fQrm2a/tLgRQI+5SvHoVjuK00b69CmzfqM1HsFqIw3T0v6m xzAvwFPyB6uRgULiZsMbDsl1E+k5rZ3/AM3GfDpgNrb9w6XOhy4VFWjB+epZIznjIA9Dcg xa0ovgNu3dE0bFTM6AizwRZDDeZ7AIA= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=dxQxbxYL; spf=pass (imf07.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.171 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=1729272430; a=rsa-sha256; cv=none; b=sceIZ/H0IpAPGlRhsvC/oZX3dOmaTq9aAqo6GJa29RPKnuTzTz7jT6GitSCUMhrDaI25nY /0T7OrZzgsqd8v34ODoHt9K6ngs0VLy+wGxfuSV2hUKOEEKoMgexG0oh+YfGS99ySQU7Ae juuI93XSEoZJwJgsAD2ydzVQTjXERsw= Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-71e52582cf8so1686516b3a.2 for ; Fri, 18 Oct 2024 10:30:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729272624; x=1729877424; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZFpXrhpElIx5U0caqw8WXCQdQvrJMpAq6qiRpCPXwmQ=; b=dxQxbxYL8IsA+pcO+1pM/uHk6MwdvnKbgGqRjPPD7e9G0qblMsqMn/5hn9o+V4HdFT UFAI1uliiV5PM/8xbebtqmcPNBTfFOUd5xJjkh7GOOeHh9w2WuP5HTOwsT54d0Blrx9j oTPvxqzpxmrygE9XiCxJ1rrUpdOQLr9rnvRK9MmITPXEKia5Ty/S7gBvt9pb3FT5aDUe 7ZbkaWJAFPr04kRlEorp7b5cGE8tmCvJMhFGeqoS8fDelpN2Ztv/sZA4d8ZjlSWq0sN0 YvLGGycF78nwOFI+hMogDsMG6m7qoYMysYeL1K8L3KGaA1jNRt+LwSs0PFUR2gyvVNHG DYzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729272624; x=1729877424; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZFpXrhpElIx5U0caqw8WXCQdQvrJMpAq6qiRpCPXwmQ=; b=J1Xnzd3R/q+XBGOtGm4bgONUdO2HpXKEMgPxHsz5FEzdjCvZdJK/CeJcsiNa+5iVbf aAn/hIY0fCmfj8noKgIvBjDCIfkdL5OJbuklw6qSBsWN9O6YY3VaN2T+Wme8tUIZBQPT LSyh8Pxk1SDEErT6RT/GQFpL2jZPTX53yP8pFFLUSCQqUvaP/ACt8aDqsWLht52Eii/3 gxIuEb8YIqf0Cq6q/13tszQ2ap50Tl4vq9U0WvLDeJMRsy75bMXUeGOoO2uNzKGBusdZ cU7V7VxYRN803YzXlxbyElrzpoEhHz1iQMlpOIT6GjO/o5VTeLV5lopFot1Ei9T0D1Kh Xx4Q== X-Forwarded-Encrypted: i=1; AJvYcCVO/dyflJVx7KyHq1b2pbKl8mO2ZEe19D1zeeP+o86vBkjfDt1x16j3k3H9jJ8Wx/qiMMZaFxieEg==@kvack.org X-Gm-Message-State: AOJu0Yxsj69KuR4QD7OoKcL5yH0enZCQ70dSy+Jvi0mCe3BIiZ9JnwqU UwXsyTvDG8r4I4AAiB88r/dAifCWT6XN98/NSjxhmpYq4jaWX74t X-Google-Smtp-Source: AGHT+IFcGGMjhgZmKijPwzMX2TIIKyjbIB1NxgoXGiQqvtxq79BYQZAFUknM7+tFqktbTIEQT/2tPA== X-Received: by 2002:a05:6a00:1390:b0:71e:148c:4611 with SMTP id d2e1a72fcca58-71ea3124252mr4810440b3a.6.1729272624262; Fri, 18 Oct 2024 10:30:24 -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.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 10:30:23 -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)" , Disha Goel Subject: [PATCH v3 01/12] powerpc: mm/fault: Fix kfence page fault reporting Date: Fri, 18 Oct 2024 22:59:42 +0530 Message-ID: X-Mailer: git-send-email 2.46.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: E3CE640017 X-Stat-Signature: mrg4ybmjya1xfx3iirnjka97qr1qqfzq X-Rspam-User: X-HE-Tag: 1729272609-900952 X-HE-Meta: U2FsdGVkX1/nA5ZWIcC3LX0yUgSs8mmLVhuZubzEJaI8UdugquPw9yb7x8pfwNJAlYyAYhwO7LQi82Iv0FOE4v6uRQ9KdCHN6aauZ6MqB6cg3/PHDizYkg2mW93GHC1PCYax3eH3ay7i2U65j6Vupi9jdrxGZviS22IGpzNrrqMyJSu1Znm2KPI/Yh3/1Isuj130HfwMyf2UL+ap6fJVCS54UPMcjOYQ9/fXV+EdPyy1/2cFC/vOSf+OsyCwyh3XaicrVohYAMJKiVtC2wClNMt8HM0AvmT688EWH9R3R4DbPXSQqrMAye5xF9u5h8UI8kNeZnBzfjJneWcR4s9P+rOr+4stLInGdSuIfVfY5KmtIGAQSVEkuqMKcmwE6BsZfSlrlbBx9Zt2vMCbY6OKWI8hIb5+2LKn0WjDPR8AfpPvTBfmTX5MwQhPx6/2iR5dUZg5L9BrKxYKP7afwdtbBZwazoeddhXf14XphevZCP7nXqXRShO1Yi4rQ8GEtttyFimujQch7UYRRkCG3v6U7/FjFAz8nQspILemPEYv9Ri9obkO+IsjjXw/Jtpt9bQJpyTLDXclcuKJfzCDENnXGJ5uK86lzxmMzzjf0yPRhjkyv8/L+khKUoBC07ZJmEjls2jKIGrf9T/9j2UlYJxvAKwYzJvJ+hGWgtD33nUMJUFzh1Y+wHkpvkq1BccEVews2CWXGhAynQ0kHG1D7hFn4dBRuPlaE78Q8N6ASbvHcAl7kCUava7RIb6J3gWdkqsr4Mnl+k7FNg24mCfTlun+Crbb47e6C5biQUslkyCVRI+hDy5XwXfJoZLrEUKQluEZkgbm3P1XFZ3WfPCQM0Jrr/+Ad/oVv68v56B7HkXR6eNrh1ED3DdSEbQ3d6FMQdwxe4u5Gs0L4w77WG6xuLCZLajVm9/7zdyI6EJZNUKwXU2VucssRrXOLyo+pWEsn9rtWeaGLUEIhPGIs4oSOH+ PSnL/WCg 14u2pZvZJsRPVpwpQAcXubR+UP2V/jBRJa1H0FCsrGjjPFLqCjkMedmFZZfYpIHrWiQCIfys8v5cVbTfoUXEq1sfvlduiLlQhWFO6VmGbVR/qLFzoPmwGGByRncx/NkY6AAwqnMLVOFXU7vvXHzQNM4fQ9fvg9c3PUfXu96rk9NJxLl0Tmf7FxiZyuCoOwDgOy3/YPsCZMd+TnmLMD0NCqinJA+77GNirAOuCbE3Z9Js4Q7mxeFLPC9e3BXJFe/c6nvyp2+3zM+EulDarjGoiLWT1JIeveOu6ezpn X-Bogosity: Ham, tests=bogofilter, spamicity=0.000005, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: copy_from_kernel_nofault() can be called when doing read of /proc/kcore. /proc/kcore can have some unmapped kfence objects which when read via copy_from_kernel_nofault() can cause page faults. Since *_nofault() functions define their own fixup table for handling fault, use that instead of asking kfence to handle such faults. Hence we search the exception tables for the nip which generated the fault. If there is an entry then we let the fixup table handler handle the page fault by returning an error from within ___do_page_fault(). This can be easily triggered if someone tries to do dd from /proc/kcore. dd if=/proc/kcore of=/dev/null bs=1M =============================== BUG: KFENCE: invalid read in copy_from_kernel_nofault+0xb0/0x1c8 Invalid read at 0x000000004f749d2e: copy_from_kernel_nofault+0xb0/0x1c8 0xc0000000057f7950 read_kcore_iter+0x41c/0x9ac proc_reg_read_iter+0xe4/0x16c vfs_read+0x2e4/0x3b0 ksys_read+0x88/0x154 system_call_exception+0x124/0x340 system_call_common+0x160/0x2c4 BUG: KFENCE: use-after-free read in copy_from_kernel_nofault+0xb0/0x1c8 Use-after-free read at 0x000000008fbb08ad (in kfence-#0): copy_from_kernel_nofault+0xb0/0x1c8 0xc0000000057f7950 read_kcore_iter+0x41c/0x9ac proc_reg_read_iter+0xe4/0x16c vfs_read+0x2e4/0x3b0 ksys_read+0x88/0x154 system_call_exception+0x124/0x340 system_call_common+0x160/0x2c4 Fixes: 90cbac0e995d ("powerpc: Enable KFENCE for PPC32") Suggested-by: Christophe Leroy Reported-by: Disha Goel Signed-off-by: Ritesh Harjani (IBM) Reviewed-by: Christophe Leroy --- arch/powerpc/mm/fault.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) -- 2.46.0 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c index 81c77ddce2e3..316f5162ffc4 100644 --- a/arch/powerpc/mm/fault.c +++ b/arch/powerpc/mm/fault.c @@ -439,10 +439,17 @@ static int ___do_page_fault(struct pt_regs *regs, unsigned long address, /* * The kernel should never take an execute fault nor should it * take a page fault to a kernel address or a page fault to a user - * address outside of dedicated places + * address outside of dedicated places. + * + * Rather than kfence directly reporting false negatives, search whether + * the NIP belongs to the fixup table for cases where fault could come + * from functions like copy_from_kernel_nofault(). */ if (unlikely(!is_user && bad_kernel_fault(regs, error_code, address, is_write))) { - if (kfence_handle_page_fault(address, is_write, regs)) + + if (is_kfence_address((void *)address) && + !search_exception_tables(instruction_pointer(regs)) && + kfence_handle_page_fault(address, is_write, regs)) return 0; return SIGSEGV; From patchwork Fri Oct 18 17:29:43 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: 13842084 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 AB35ED3DEA0 for ; Fri, 18 Oct 2024 17:30:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 32CEF6B0095; Fri, 18 Oct 2024 13:30:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2DE156B0096; Fri, 18 Oct 2024 13:30:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12DAA6B0098; Fri, 18 Oct 2024 13:30:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E4B026B0095 for ; Fri, 18 Oct 2024 13:30:32 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A90EB1A085B for ; Fri, 18 Oct 2024 17:30:10 +0000 (UTC) X-FDA: 82687411842.19.B8FCDC4 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf10.hostedemail.com (Postfix) with ESMTP id A799DC0023 for ; Fri, 18 Oct 2024 17:30:25 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=FOgoPr1H; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729272596; a=rsa-sha256; cv=none; b=LQVItjyPTHh4QEQBeTlvlzG0MMCt7e0P5RGqSr3t5LWjqV3qLxuU3dxvVzuUUkJRenlHCr BoK08W5pmjBn3YHPMdPdO1vmun+nIXphKhNPwdas5oaRhAx+TCO1tbhxQIv29OJA0P1Qsq 50dDXxxqu6e83N9huFjY5hxW6pDgKIs= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=FOgoPr1H; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729272596; 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:in-reply-to:references:references:dkim-signature; bh=Y7m6nw0SlLNWzWwVTYubL573BHmMjcLP6yP7O1snSbI=; b=uEgANZ3fBjGJQ/tq0qSlBSUJBDjUjx1skvI2r+Z+9O4c5594a0PeR6ZefpdL2ds8WZxRxx jd0OzeSI8wButW5HRfOjM3Ms+B5fuDD5T5zMDQEyZUrl4chBpyMwMsmrImQX6geTENJd5H pzymMaGCEtqS/RCD/OSvovVzc5Et74M= Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-71e4e481692so2056446b3a.1 for ; Fri, 18 Oct 2024 10:30:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729272629; x=1729877429; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Y7m6nw0SlLNWzWwVTYubL573BHmMjcLP6yP7O1snSbI=; b=FOgoPr1H+lIYDWZdUHp6L1rWEv+ND+A+0nfzOYHRbFY+w6i0UFZFhf3ZeW5xo2Upn1 ku3xkctpdRwKATSmwlZ/P5whflsPLIIYGMb9Lx/rglhcTLwVXI7+x2i09YFdApFrwKHE odHR3n5D1BjoxNopgVfN0JMT24tN/vcrlzQx1KC5zqqE20VavxLwUyEur3b8I81vjY48 FIoO93B2JEW+jsGnz4eS8RrKPY9mtELVfSaLZK9mbCfxk5nrb+DokZ3/m3+e0dvQkiOh O6OrpdrSOAEc4rCBvv4thGxbjEuj0BYsOtKBpWFNw8bPde704itfybx2j6fNU8Okwt7V GWpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729272629; x=1729877429; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y7m6nw0SlLNWzWwVTYubL573BHmMjcLP6yP7O1snSbI=; b=cyU3os1jveOegFKV5cbLBOdFChzcyLMqkWqmK5yOsbXmXWh+BFWUWHZR1vaLF4hJHM kK+RGUlddJHnbHyEb7Eqbp/h8oEWFRqBom68WKocbUBJdbgyZgnpIAWxbp+6C0uX88lS cuDcsWkEZwiOWRZ+ie4Z99UruYczEZAEKlXhrhc0zNcioD6qVlNJCSw/Jy0o5m/zT+48 /YJH5HUzkU2XG0XiIOHhIFQ8sLrsapzK4cNKW9NtN22wTqxdbzjzYwKmzN4HeQw3rcB9 J+oayoRZd2F64Ehrs/sSnwQUbqRdYgb14ewT9BENRiC2c3Ddo8rtpCl8bWwG6HqUb8rB KooA== X-Forwarded-Encrypted: i=1; AJvYcCWRTl9vm7gH8YXRjZi9GoZwGDZ7Bx30Ej5eZtTECdXXvBNPWhVBgWMmJ2o0/IZxJ1U8GWDp1xv5xQ==@kvack.org X-Gm-Message-State: AOJu0YygXtbyAOm6GEQBAJ//90ipZ67AX5mzhMwDsFlb3CHrEO/uVWUV LNY30IXWrks9eGQ4inb5uLAxJNAvHtlH/32JpA7aNj6vM71pAhag X-Google-Smtp-Source: AGHT+IH29uhXoWddJW63rmOfdUmm3F60bMAd8Lb1nxktQLiJXibpBjYFtPZvdFulLgU3PQV9sp2ESA== X-Received: by 2002:a05:6a00:3e0f:b0:71e:4a1b:2204 with SMTP id d2e1a72fcca58-71ea331b398mr4152501b3a.25.1729272629392; Fri, 18 Oct 2024 10:30:29 -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.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 10:30:28 -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 02/12] book3s64/hash: Remove kfence support temporarily Date: Fri, 18 Oct 2024 22:59:43 +0530 Message-ID: <1761bc39674473c8878dedca15e0d9a0d3a1b528.1729271995.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: dt1io4fhju4zckskwt3hdubzibechf76 X-Rspamd-Queue-Id: A799DC0023 X-Rspamd-Server: rspam02 X-HE-Tag: 1729272625-887611 X-HE-Meta: U2FsdGVkX18KSJTFsBaFaDbueczk/HiylecAfdm6CHE5wBV1Z53xXFh91bcG/fLWqHuXLNW7OaAcaNwoYjRG5slnwdET6jnUVyH7KztZ1MOilKa/MeQLwlEnbynkRVoeVfZktvLTgKz0uGFsEXI1KeN/YWclImFxZwjkr3MGwn4ew4fvm00wMC3OG1/D78QmuMRPShZezXeWqFzaTc87s0axubmC816kYQSoX12nnSHOLT9g5HMynPsa3U+hIjcqQC42N1JPMQI7fA+VrrBgnFpDkQYBearNFutAMxCB2QHfoNJWVZQuZJB/MA2CE9xn/gJKE/gIXPfPAxWds3NAjD4Ws+77/9+zK4WP83CAKs63ouyd5J01MQjJXUxRQfxlkZzoQ2/CAV575+/eAMf2RVFEhLgHpfuDtMtgS6VMsXnH+1wdLS57jwXBg+3/oKE206hhcitquBrYG1nxQnow0or7gb5Fd0m4EtUKE0sbzTU+SgvtTJy1cTOlGqOZLX/hK8bBnHtopbgmcLuYwRj/jhyvx5qxbP73t7pvXH4jUdCysruGEj5KGctZXVLRaFdUOc8hhGfzBsMpLeY38f3Wiw16tf7Jwb+J9C9LsKXqoUJQJoiwWek+cQlRbGYPU+kESPmXzXUqw6RWtIR+xeoYFI6itywO2u0RRUX6leMV/fRaWnAhYlJQAh0qaK5vOMc5F/CHljBe0vzwt1T/JtAfY4yGmpEL/8CeSNY12WOXvmN4O1fR7v82bhm4q75Vz0IqqBPsKI6sCy2GfutT1uDysYE4PrgA6Jf22JHlSg5yBkZvHWd4l1ZxvBwxeyZNQsjHafp6yN8Epq+/1NopeiyqMCSk6FGKSnFGOmtZPlWNX6qSR9UJHNQaT+YGiu78S6NsIr7hKoe4rdNGJIOkPL59OGsMf2kWQNt/SLz4/aUCbeqLH4W6Yha2h7cCuPl0H2ReWJljxG4EVzA08Qhbgx3 Hi74jyYG 1oIvv3T9yn/0hJ2G1BTYupATAmgCRv+RD5hcHMpdWo8Pp1nxX70aiBxBGfKpEm5/w/GdxmgB5xLWSBnXRxwmc+U3hXmIBeDCQvI67BIYnhFsr39uRZzQFK068Raurrv5dnffbAh1Cqg6TLj7e9HpHEdc4+XGvQ4V7hl1A6X5Bp6LuYPEJWMZyN6Iy4FWBthWplxeV5ppqE2cmc7h0dJxR4zoTVFm7AdjN0C1yIHFsgh4DX0ymINwXPUGvSPkFNT7CjO9abEjRQqQfzp6Y9Ire49gbAY1fEgrK3sKy 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: Kfence on book3s Hash on pseries is anyways broken. It fails to boot due to RMA size limitation. That is because, kfence with Hash uses debug_pagealloc infrastructure. debug_pagealloc allocates linear map for entire dram size instead of just kfence relevant objects. This means for 16TB of DRAM it will require (16TB >> PAGE_SHIFT) which is 256MB which is half of RMA region on P8. crash kernel reserves 256MB and we also need 2048 * 16KB * 3 for emergency stack and some more for paca allocations. That means there is not enough memory for reserving the full linear map in the RMA region, if the DRAM size is too big (>=16TB) (The issue is seen above 8TB with crash kernel 256 MB reservation). Now Kfence does not require linear memory map for entire DRAM. It only needs for kfence objects. So this patch temporarily removes the kfence functionality since debug_pagealloc code needs some refactoring. We will bring in kfence on Hash support in later patches. Signed-off-by: Ritesh Harjani (IBM) --- arch/powerpc/include/asm/kfence.h | 5 +++++ arch/powerpc/mm/book3s64/hash_utils.c | 16 +++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/include/asm/kfence.h b/arch/powerpc/include/asm/kfence.h index fab124ada1c7..f3a9476a71b3 100644 --- a/arch/powerpc/include/asm/kfence.h +++ b/arch/powerpc/include/asm/kfence.h @@ -10,6 +10,7 @@ #include #include +#include #ifdef CONFIG_PPC64_ELF_ABI_V1 #define ARCH_FUNC_PREFIX "." @@ -25,6 +26,10 @@ static inline void disable_kfence(void) static inline bool arch_kfence_init_pool(void) { +#ifdef CONFIG_PPC64 + if (!radix_enabled()) + return false; +#endif return !kfence_disabled; } #endif diff --git a/arch/powerpc/mm/book3s64/hash_utils.c b/arch/powerpc/mm/book3s64/hash_utils.c index a408ef7d850e..e22a8f540193 100644 --- a/arch/powerpc/mm/book3s64/hash_utils.c +++ b/arch/powerpc/mm/book3s64/hash_utils.c @@ -431,7 +431,7 @@ int htab_bolt_mapping(unsigned long vstart, unsigned long vend, break; cond_resched(); - if (debug_pagealloc_enabled_or_kfence() && + if (debug_pagealloc_enabled() && (paddr >> PAGE_SHIFT) < linear_map_hash_count) linear_map_hash_slots[paddr >> PAGE_SHIFT] = ret | 0x80; } @@ -814,7 +814,7 @@ static void __init htab_init_page_sizes(void) bool aligned = true; init_hpte_page_sizes(); - if (!debug_pagealloc_enabled_or_kfence()) { + if (!debug_pagealloc_enabled()) { /* * Pick a size for the linear mapping. Currently, we only * support 16M, 1M and 4K which is the default @@ -1134,7 +1134,7 @@ static void __init htab_initialize(void) prot = pgprot_val(PAGE_KERNEL); - if (debug_pagealloc_enabled_or_kfence()) { + if (debug_pagealloc_enabled()) { linear_map_hash_count = memblock_end_of_DRAM() >> PAGE_SHIFT; linear_map_hash_slots = memblock_alloc_try_nid( linear_map_hash_count, 1, MEMBLOCK_LOW_LIMIT, @@ -2120,7 +2120,7 @@ void hpt_do_stress(unsigned long ea, unsigned long hpte_group) } } -#if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KFENCE) +#ifdef CONFIG_DEBUG_PAGEALLOC static DEFINE_RAW_SPINLOCK(linear_map_hash_lock); static void kernel_map_linear_page(unsigned long vaddr, unsigned long lmi) @@ -2194,7 +2194,13 @@ int hash__kernel_map_pages(struct page *page, int numpages, int enable) local_irq_restore(flags); return 0; } -#endif /* CONFIG_DEBUG_PAGEALLOC || CONFIG_KFENCE */ +#else /* CONFIG_DEBUG_PAGEALLOC */ +int hash__kernel_map_pages(struct page *page, int numpages, + int enable) +{ + return 0; +} +#endif /* CONFIG_DEBUG_PAGEALLOC */ void hash__setup_initial_memory_limit(phys_addr_t first_memblock_base, phys_addr_t first_memblock_size) From patchwork Fri Oct 18 17:29:44 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: 13842085 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 E3988D3DEA3 for ; Fri, 18 Oct 2024 17:30:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 725E66B0099; Fri, 18 Oct 2024 13:30:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D2D16B009A; Fri, 18 Oct 2024 13:30:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5740E6B009B; Fri, 18 Oct 2024 13:30:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 276486B0099 for ; Fri, 18 Oct 2024 13:30:38 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D62E61C7572 for ; Fri, 18 Oct 2024 17:30:23 +0000 (UTC) X-FDA: 82687412304.18.A5F4200 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by imf08.hostedemail.com (Postfix) with ESMTP id 181C616000A for ; Fri, 18 Oct 2024 17:30:27 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=KjtuVad8; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf08.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.215.176 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729272516; a=rsa-sha256; cv=none; b=2zJ7y7ASp5y9OpA2F8U0tTwHZBjIvOKIV5j2Um13Rhv8jyQis1alc3ZDbCBoBNTD6JgryW GFRHL6PuXcNiBDeJX41MFHP6tvWMfMKUF1eKICJbY+IKA1YssIt5MHjavOH+qKNwcLXXNZ 9YHH1ZD3yLx6CdiYiBwxOOvv+gLR00c= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=KjtuVad8; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf08.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.215.176 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729272516; 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:in-reply-to:references:references:dkim-signature; bh=PKeOGzBwhkORap+bFaXRZ5k5ETEZTGkTXkc6r1BfTnM=; b=HYSw5gQqTzidznUnAH9NP1TONCBUKK0YKLr+Jtv20bscle4V0GqlxMGDq5n3NnwQA5xKNq PJjs5YpHiS4JyU7F4C4h5xmawQ1FRf5If0gnfRXIMjq1Eo61JA0GBfiwGZT7bhwSq81HW3 BsFkSx610VqSyhZjWP6xpkh6YT5SqXM= Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-7ea784aea63so1301243a12.3 for ; Fri, 18 Oct 2024 10:30:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729272634; x=1729877434; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PKeOGzBwhkORap+bFaXRZ5k5ETEZTGkTXkc6r1BfTnM=; b=KjtuVad8WjTzrTlYH6XxyPrMm0bYnxRqxkfK7T+nezVN6SFlH+n4Q1rdSFWdcmz/Om Z8ubk7LM0Dze1MGoccaBbdWV5h7HiKLM82PjEnbMvHfrKUivpr06/lEJ1tVLh/2m4MsJ v6WVvs0PAEsGY0pwB2zyzCyHzzHOrYs9kQATfgGvyywuuY7vLNXajT5ixJP0ppmrcL57 nrrkmbZq2Fugi+yYC7uPucN3+b6ERlyfq4ffF9Nkm4JumolVTLjhK0vlXK8aVjMDKkIZ 9NUSqdU6cEBUa165Xey3Kuo+S39Um9J69olmj6kV87iLmTmBmCUGXk7r/c1EetEjVWlD O+/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729272634; x=1729877434; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PKeOGzBwhkORap+bFaXRZ5k5ETEZTGkTXkc6r1BfTnM=; b=Ccgl+Rz3qaSU66ckhe46Y/2YbW+YEjnxAHUqSNf1In52uehKFW5juphgB02E0jspEN l4JkC84pTeFuIbEzJ8pGqfx7dWOdelhv8pCEujtbMKlDo4yzosxP7ZiG6DmlfkbiQIqj Ta0RgL1fGz+0nfQfHDQi//C8uJ9NkkJ1vYAuLKGFcUu8+Q++nTahvhSYf9fcE2ThX1ie z03XmQXiHu8+R1USAnk68tnY2faEc5tbO+7ja5MyhoVJ6+EBFYNhgQwZ2qZwiK6Lv5ox TaTbI9m2oy7ItZnYnEJbXYD4680Lvi9cPeeWzOUVC3GdPbyYC/DnmQxBKTsQmr6bI4AY YW4g== X-Forwarded-Encrypted: i=1; AJvYcCVrscXvdxVldwfIU73mAI4le+j5UPA5EIby2MhD9z1g8b9rdp67809cGUxP9QpaY0sOP6/SLrutUQ==@kvack.org X-Gm-Message-State: AOJu0YxeZM0+4WT9uLQdB0VkcYzkaznjSi3xCpQ1xrzBEKOmJmlkpAdH 7QF9kcUa+Upusm8ztHRLvgfUqaA+9u/b2nLGVjaS+keLoUKvW9yT X-Google-Smtp-Source: AGHT+IEHDVJvXPkTfxkfLhiJ891PgPvrAItwAzBFVy3rywsUuhpfmzOVbkrBnF6delxgn8dQGKkFxQ== X-Received: by 2002:a05:6a20:d98:b0:1cf:38b0:57ff with SMTP id adf61e73a8af0-1d92c5ac311mr4139493637.48.1729272634341; Fri, 18 Oct 2024 10:30:34 -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.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 10:30:33 -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 03/12] book3s64/hash: Refactor kernel linear map related calls Date: Fri, 18 Oct 2024 22:59:44 +0530 Message-ID: <56c610310aa50b5417976a39c5f15b78bc76c764.1729271995.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 181C616000A X-Stat-Signature: ubiwri3qqokf537dwcoo9y5w18pnp4kk X-Rspam-User: X-HE-Tag: 1729272627-944324 X-HE-Meta: U2FsdGVkX18ahu+RNjz8gisgrYBBA8GnqnyONaaO2ztmQ7+Oclj9KW4EIA8bMfXwOU0fgoUUbFyUUjX3MCSrA29j91fdcO2qGfQWdU8a7Quwy2xQf+xg/sYumzlBTMo6pdjiNIkctGfQg3BEmayE5P1r64hBiL41VM7SgBRwq6maAbVsMdtXoecEfWDdjuN8Pc2tDRa3NwfDAcog3uoX7RktDbcDT35UZ8JNwLPeviydoMlGgFBDAZ7w222Lv7iVoCg2Ao8H/ybagN523G2GGHvSWIjT5JOtp1lRDeLMtGLjJ2V7BFOfBs8CFlTLB1o+djEHTsptLG5lOBnKXvvgmFMk82sge7WyJO7Fbhyp0I4LpQw8ZiV2Na4vN57AnXxoWRc6nzbLkTgMQ0UzbvvPsES4RGnCdfd/IibCjOtH9e2DzxUJ92BoBtmNwzsuoAxmw7sk5YzdajoSlUmTHXW8gYGxvolJE2qTZsA7Sv4Sbxp56kxn1uCKGmGVnoFvraQJuNRo2kU4qCEXqareLJfxVGaYT+VF1Vw74OsBxlNUSbJbjPla34BnVd2u6womUTG2HPNuDBpgd5ysH5ItIoNq9cvSU/m8I/0WTy1itAebxjNCMCw2OzPGI+Or2+oypUVoFeoPErCHJR0EOfFaJ7K7d//K6jqj3c7O3nicYQvprVKog1dfBDAiDdCIdTWZTg3rbB96t3COLQ8gihbp/7Nsi3Vi2u92BIGKc7Yo4/kGFjIQxBXFTiVjnz8FeKMtHHJOzL5V0wQBTrSl7VT5nzQAQdfs0jKNl+A+jFfCYTb3JKka8SNKPL+wvHJxVXLxeD9uSSzguTojC0f44b+utR7BxffTYJ27NpxZZHpCCDDM0KFWiR8js8hS6vrSz+NMw+Yoec5kPhH0K/3OTjL2iRVsabxYzhOGdrlYIygIVwayw3xk5P1ShWveEJMCmXYO0FvxbDGUUNtmR0QKUUgBbfB /4/H912+ QIQSK2joEmTfQlncmU19Bt8vbbyCeJojb+NoqEL/sHzwzCVrIrmMH+kmgBcDi4l6eirNQxYSMy5za/K6NaH0k92DPY9/jLRZTChLqpbCDOhxJ5B8xN03mmqQ2vVWFvr3Kh73K081T6/s8hxvDjZtaq8VWDPyWL19lOzbh/QfWNi6vBSCEt420zJXtaHmpVmcJjLteX9/n+3Va4GBg9dUuTFApkfzhd8XAEHmidpqBJaEJJc0JvnyMaJMs8gf1aJF6ccAdlUSVAjdFbZLw+xsCWvalK0v0jdIV5UN9 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: This just brings all linear map related handling at one place instead of having those functions scattered in hash_utils file. Makes it easy for review. No functionality changes in this patch. Signed-off-by: Ritesh Harjani (IBM) --- arch/powerpc/mm/book3s64/hash_utils.c | 164 +++++++++++++------------- 1 file changed, 82 insertions(+), 82 deletions(-) diff --git a/arch/powerpc/mm/book3s64/hash_utils.c b/arch/powerpc/mm/book3s64/hash_utils.c index e22a8f540193..fb2f717e9e74 100644 --- a/arch/powerpc/mm/book3s64/hash_utils.c +++ b/arch/powerpc/mm/book3s64/hash_utils.c @@ -273,6 +273,88 @@ void hash__tlbiel_all(unsigned int action) WARN(1, "%s called on pre-POWER7 CPU\n", __func__); } +#ifdef CONFIG_DEBUG_PAGEALLOC +static DEFINE_RAW_SPINLOCK(linear_map_hash_lock); + +static void kernel_map_linear_page(unsigned long vaddr, unsigned long lmi) +{ + unsigned long hash; + unsigned long vsid = get_kernel_vsid(vaddr, mmu_kernel_ssize); + unsigned long vpn = hpt_vpn(vaddr, vsid, mmu_kernel_ssize); + unsigned long mode = htab_convert_pte_flags(pgprot_val(PAGE_KERNEL), HPTE_USE_KERNEL_KEY); + long ret; + + hash = hpt_hash(vpn, PAGE_SHIFT, mmu_kernel_ssize); + + /* Don't create HPTE entries for bad address */ + if (!vsid) + return; + + if (linear_map_hash_slots[lmi] & 0x80) + return; + + ret = hpte_insert_repeating(hash, vpn, __pa(vaddr), mode, + HPTE_V_BOLTED, + mmu_linear_psize, mmu_kernel_ssize); + + BUG_ON (ret < 0); + raw_spin_lock(&linear_map_hash_lock); + BUG_ON(linear_map_hash_slots[lmi] & 0x80); + linear_map_hash_slots[lmi] = ret | 0x80; + raw_spin_unlock(&linear_map_hash_lock); +} + +static void kernel_unmap_linear_page(unsigned long vaddr, unsigned long lmi) +{ + unsigned long hash, hidx, slot; + unsigned long vsid = get_kernel_vsid(vaddr, mmu_kernel_ssize); + unsigned long vpn = hpt_vpn(vaddr, vsid, mmu_kernel_ssize); + + hash = hpt_hash(vpn, PAGE_SHIFT, mmu_kernel_ssize); + raw_spin_lock(&linear_map_hash_lock); + if (!(linear_map_hash_slots[lmi] & 0x80)) { + raw_spin_unlock(&linear_map_hash_lock); + return; + } + hidx = linear_map_hash_slots[lmi] & 0x7f; + linear_map_hash_slots[lmi] = 0; + raw_spin_unlock(&linear_map_hash_lock); + if (hidx & _PTEIDX_SECONDARY) + hash = ~hash; + slot = (hash & htab_hash_mask) * HPTES_PER_GROUP; + slot += hidx & _PTEIDX_GROUP_IX; + mmu_hash_ops.hpte_invalidate(slot, vpn, mmu_linear_psize, + mmu_linear_psize, + mmu_kernel_ssize, 0); +} + +int hash__kernel_map_pages(struct page *page, int numpages, int enable) +{ + unsigned long flags, vaddr, lmi; + int i; + + local_irq_save(flags); + for (i = 0; i < numpages; i++, page++) { + vaddr = (unsigned long)page_address(page); + lmi = __pa(vaddr) >> PAGE_SHIFT; + if (lmi >= linear_map_hash_count) + continue; + if (enable) + kernel_map_linear_page(vaddr, lmi); + else + kernel_unmap_linear_page(vaddr, lmi); + } + local_irq_restore(flags); + return 0; +} +#else /* CONFIG_DEBUG_PAGEALLOC */ +int hash__kernel_map_pages(struct page *page, int numpages, + int enable) +{ + return 0; +} +#endif /* CONFIG_DEBUG_PAGEALLOC */ + /* * 'R' and 'C' update notes: * - Under pHyp or KVM, the updatepp path will not set C, thus it *will* @@ -2120,88 +2202,6 @@ void hpt_do_stress(unsigned long ea, unsigned long hpte_group) } } -#ifdef CONFIG_DEBUG_PAGEALLOC -static DEFINE_RAW_SPINLOCK(linear_map_hash_lock); - -static void kernel_map_linear_page(unsigned long vaddr, unsigned long lmi) -{ - unsigned long hash; - unsigned long vsid = get_kernel_vsid(vaddr, mmu_kernel_ssize); - unsigned long vpn = hpt_vpn(vaddr, vsid, mmu_kernel_ssize); - unsigned long mode = htab_convert_pte_flags(pgprot_val(PAGE_KERNEL), HPTE_USE_KERNEL_KEY); - long ret; - - hash = hpt_hash(vpn, PAGE_SHIFT, mmu_kernel_ssize); - - /* Don't create HPTE entries for bad address */ - if (!vsid) - return; - - if (linear_map_hash_slots[lmi] & 0x80) - return; - - ret = hpte_insert_repeating(hash, vpn, __pa(vaddr), mode, - HPTE_V_BOLTED, - mmu_linear_psize, mmu_kernel_ssize); - - BUG_ON (ret < 0); - raw_spin_lock(&linear_map_hash_lock); - BUG_ON(linear_map_hash_slots[lmi] & 0x80); - linear_map_hash_slots[lmi] = ret | 0x80; - raw_spin_unlock(&linear_map_hash_lock); -} - -static void kernel_unmap_linear_page(unsigned long vaddr, unsigned long lmi) -{ - unsigned long hash, hidx, slot; - unsigned long vsid = get_kernel_vsid(vaddr, mmu_kernel_ssize); - unsigned long vpn = hpt_vpn(vaddr, vsid, mmu_kernel_ssize); - - hash = hpt_hash(vpn, PAGE_SHIFT, mmu_kernel_ssize); - raw_spin_lock(&linear_map_hash_lock); - if (!(linear_map_hash_slots[lmi] & 0x80)) { - raw_spin_unlock(&linear_map_hash_lock); - return; - } - hidx = linear_map_hash_slots[lmi] & 0x7f; - linear_map_hash_slots[lmi] = 0; - raw_spin_unlock(&linear_map_hash_lock); - if (hidx & _PTEIDX_SECONDARY) - hash = ~hash; - slot = (hash & htab_hash_mask) * HPTES_PER_GROUP; - slot += hidx & _PTEIDX_GROUP_IX; - mmu_hash_ops.hpte_invalidate(slot, vpn, mmu_linear_psize, - mmu_linear_psize, - mmu_kernel_ssize, 0); -} - -int hash__kernel_map_pages(struct page *page, int numpages, int enable) -{ - unsigned long flags, vaddr, lmi; - int i; - - local_irq_save(flags); - for (i = 0; i < numpages; i++, page++) { - vaddr = (unsigned long)page_address(page); - lmi = __pa(vaddr) >> PAGE_SHIFT; - if (lmi >= linear_map_hash_count) - continue; - if (enable) - kernel_map_linear_page(vaddr, lmi); - else - kernel_unmap_linear_page(vaddr, lmi); - } - local_irq_restore(flags); - return 0; -} -#else /* CONFIG_DEBUG_PAGEALLOC */ -int hash__kernel_map_pages(struct page *page, int numpages, - int enable) -{ - return 0; -} -#endif /* CONFIG_DEBUG_PAGEALLOC */ - void hash__setup_initial_memory_limit(phys_addr_t first_memblock_base, phys_addr_t first_memblock_size) { From patchwork Fri Oct 18 17:29:45 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: 13842086 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 EF6DFD3DEA2 for ; Fri, 18 Oct 2024 17:30:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 770076B009B; Fri, 18 Oct 2024 13:30:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 720896B009C; Fri, 18 Oct 2024 13:30:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5C1B06B009D; Fri, 18 Oct 2024 13:30:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 300E06B009B for ; Fri, 18 Oct 2024 13:30:45 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 59375A174C for ; Fri, 18 Oct 2024 17:30:22 +0000 (UTC) X-FDA: 82687412514.12.638B564 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by imf06.hostedemail.com (Postfix) with ESMTP id A682A180020 for ; Fri, 18 Oct 2024 17:30:34 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=NGpOZLXX; spf=pass (imf06.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.176 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=1729272448; 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:in-reply-to:references:references:dkim-signature; bh=Jw41Uo4vlK/av70SyuzQ/EcBacKxJaXG8uVQm7tNSaA=; b=BOqWB9F1boG9v14HznEDB68p99tbbFafAcLTdIKjRAMh1pIga6tcsYgvwGdX0O6ydjnkQo Nxw6KgQqbAi8QPSc9cJ7dehN2JjQWifdXwGz3j1kPhqCRRrjTjR4MnGv2KVRky5ZUulLPy j8fXK2k1JJXgeKonFt1iFUsjTOlEfkA= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=NGpOZLXX; spf=pass (imf06.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.176 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=1729272448; a=rsa-sha256; cv=none; b=6OFlynr/KbbQGNfTQ2COMSj0t/AepMzLOlEtqmuA0CZP2K0twrWPAc/84HZEfRtLl4n9Th z9JprC2N4dNXqsrFFFutuTjVsYj91xD37c5DGSASA1BtHduEJplsjbk+K3tTXu8PhUUm0E cLy23LglI6P4uirfQbF/Ume9eU3Gl08= Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-71eb1d0e3c2so29085b3a.2 for ; Fri, 18 Oct 2024 10:30:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729272641; x=1729877441; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Jw41Uo4vlK/av70SyuzQ/EcBacKxJaXG8uVQm7tNSaA=; b=NGpOZLXXSdLEDJstsPOhnpEAhyQMUOozzcKHcOHYjEchpkU44O653qLqYwUk3SJFWW vBojdPZmUPKnA67BGnUj6vNbedyIKRREYtcySV9LrMoDDHBup6svixh82xa8OLiqb8xY fq+NclVREmwoYUdS+JS0PQZT0xb31BOgPuwMN1HL21vuFbAQiXwteWad8NwHks10lClm 7zcEPRc/glHbqVYxYxwhMKMFUKiJz0WLG4fyZJCtNKneIXMFYUf9Q7JbTWAA0yBrgyrr l/utUqyBB6vYeAkecDCAAfpSyGdQRxu+/1Sgfj3zfwvQ1sYH27mAR/WTp7rYRXZdGuA6 nACg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729272641; x=1729877441; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Jw41Uo4vlK/av70SyuzQ/EcBacKxJaXG8uVQm7tNSaA=; b=svZNlfzVPYojZVANMxXDCOjywrs1QvDLHV938B5HLhL8lPEyLVOsjpYv989nhKTZed /snHWdr/8248jzTFwJhOAYxf37AusFL9kV3iLwNfpC0Cbb2wFiBbv6DKQSwGe9uKYD6S /hl94XY7zGRiK7s672212ZNfmwd0gCVSqF/uECiiNc+oE4/5+riA5U3od41A9MHdz6Ze M24bDA0VysdB0UDw3qC7g9KR6RwfoqYmq7FSD7YxYhd3c8mgPLZnCvcMKRZUDhk9VJj3 4CdWZBdz4obrOOpIBIg1DmtR4fyANQWQrMKVbKt1umkur6aLSy0kYBPEY69vC3Mc+03k DEfg== X-Forwarded-Encrypted: i=1; AJvYcCVZCtK1UkDqjt7Rqq76b7OSKmzZBFT4camkaMWQp13sjeFd0Gsa/L3p3O8btoSdNHlMaexi+Ocn5w==@kvack.org X-Gm-Message-State: AOJu0Yz46c4UDiOZ+peLvzt7EHBZHW2VFEz28987toskHxKFkBQ+s5Wb baEN+r2Mbt8jbtsXWmydvbwOunVnggRLJUIXBVcKBGM20iCUhks8 X-Google-Smtp-Source: AGHT+IHA05XWUstb450eeCq2YkOYG3UKP/gDh/dgZ6794ND1I3UZATF+JDsVTkAs4xXtweTSIyj5Uw== X-Received: by 2002:aa7:86da:0:b0:71e:b1dc:f255 with SMTP id d2e1a72fcca58-71eb1dcf5e7mr118528b3a.9.1729272641491; Fri, 18 Oct 2024 10:30:41 -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.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 10:30:40 -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 04/12] book3s64/hash: Add hash_debug_pagealloc_add_slot() function Date: Fri, 18 Oct 2024 22:59:45 +0530 Message-ID: <026f0aaa1dddd89154dc8d20ceccfca4f63ccf79.1729271995.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: A682A180020 X-Stat-Signature: r9e59f7bjmn5qjsga86xhgfp67o7f7iw X-Rspam-User: X-HE-Tag: 1729272634-374611 X-HE-Meta: U2FsdGVkX198PifKHcH7y/d5Ug+Ytt2iEuDktI105zfmlDPYBccwD7+HuqFsK+rtbOvGpm4H7TC0+Z7tCu9yN08Z0z64x3doVWsAEwOt62eVa8NffFw+zgAz8DiYJjDx10rUrpOAr2JfQ0FIi7VH9oTVY94qOkMIi5Rj5+WSF1tKB4PFEEUbbuLnFr7rcTxsSIctx9ny70R7ldHcodGUGbBSyPIfAX4O674vSBcXYnRmOLE1W9jdAAhb15yXyG3muFVd5QN+oxhpwBT4suCI+fY+OELN/rypmgkBPygDQtIMaTA1n74yd0Pa/XHIEuX3Vnq00I/hCTHFZ9FZx+QMjRsduf+MXTsE7z9h8PUraxYGMDdx9Crn1vPbIVdc0pLT0ADKe/LD4WKqO4G+kmuHWN950Sfs8j8mq8cBcxC0ouGOLjC9latwXasi13eGc8VIzu9aFtpGYW0rPd6RKL2kuNSaJ7S0dvQ6kMdX4GdJoC7DhEUwpO43PfZizhf9PHn48JScL6u8/9NozayalWF5Kr98tTRozXR9CJPUxp284WoQr7GTHZOIU8DMTDi4FhZ1qrPy7lWkAhb5bWHPYucaCvapBGz3ZRFnHdrGnEycWtt8V5wPKDXKwXv94z5iwwj5nMCpmYuEd/3Fjj1thprmOpqMX/SwWQBg/UYeyN2QqxgUtH44DIZA2vvgdv4Kbg1ttDOY6t9ujXHR8OXemlEKXjXp19zssbCVVsCllwh97b4wSEGz7Z2iezpRPuEB70uTPERqRKkAXoe0Enkle8GNsH5uDTDS+JOkB0WGQFwqtez3VoNI/xB08a7OoRFiguvEFw5CFrFGmY8wQwAfNgCTQ6TNfkG3NYp7JDX1M3Arft7eH2VI9dmRRoYS2ngjS6CnMiGoCgXTd5d25dV+9putLtg3/SMpHnxy0Q1nrwRywGVjpafzenMJ8bsEsKbwnaaEe6Q1YOLRHa+gMJqoNw9 /0tvhflq KUgsviPOxK43XnBfd9mFgb+pg0sKOTehhhAC6uAwcqYtx/Hs7EulQDMBKneDPuu28b6/TV2MOhVjQoc3JueoJJo+TxXCa3I++t+BQozlrHDOo392idI2piBCuvA7fIP5D8IjP/gzmybCQqKIrE6uNo24KLLnqN3q2Ion3DE1VuEinhQYFhhBwZXiCJvzS5TLvQeqt6Yf++Zoznd27Ez4ZBCwwzP263jdlUJrwgBCCjyMDhgkjQcWlHObvdrmY4qH9YYNOM0LaBsD/H4a7jtZokTZ1yylnzijCsnShJ0JeZ76zGYF85FlMEsKF/wmkyuNmxMQebvLIb0qErxN2mPeK7yWoHA== 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: This adds hash_debug_pagealloc_add_slot() function instead of open coding that in htab_bolt_mapping(). This is required since we will be separating kfence functionality to not depend upon debug_pagealloc. No functionality change in this patch. Signed-off-by: Ritesh Harjani (IBM) --- arch/powerpc/mm/book3s64/hash_utils.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/mm/book3s64/hash_utils.c b/arch/powerpc/mm/book3s64/hash_utils.c index fb2f717e9e74..de3cabd66812 100644 --- a/arch/powerpc/mm/book3s64/hash_utils.c +++ b/arch/powerpc/mm/book3s64/hash_utils.c @@ -328,6 +328,14 @@ static void kernel_unmap_linear_page(unsigned long vaddr, unsigned long lmi) mmu_kernel_ssize, 0); } +static inline void hash_debug_pagealloc_add_slot(phys_addr_t paddr, int slot) +{ + if (!debug_pagealloc_enabled()) + return; + if ((paddr >> PAGE_SHIFT) < linear_map_hash_count) + linear_map_hash_slots[paddr >> PAGE_SHIFT] = slot | 0x80; +} + int hash__kernel_map_pages(struct page *page, int numpages, int enable) { unsigned long flags, vaddr, lmi; @@ -353,6 +361,7 @@ int hash__kernel_map_pages(struct page *page, int numpages, { return 0; } +static inline void hash_debug_pagealloc_add_slot(phys_addr_t paddr, int slot) {} #endif /* CONFIG_DEBUG_PAGEALLOC */ /* @@ -513,9 +522,7 @@ int htab_bolt_mapping(unsigned long vstart, unsigned long vend, break; cond_resched(); - if (debug_pagealloc_enabled() && - (paddr >> PAGE_SHIFT) < linear_map_hash_count) - linear_map_hash_slots[paddr >> PAGE_SHIFT] = ret | 0x80; + hash_debug_pagealloc_add_slot(paddr, ret); } return ret < 0 ? ret : 0; } From patchwork Fri Oct 18 17:29:46 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: 13842087 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 AA611D3DEA0 for ; Fri, 18 Oct 2024 17:30:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 356116B009D; Fri, 18 Oct 2024 13:30:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B5DB6B009E; Fri, 18 Oct 2024 13:30:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12DC26B009F; Fri, 18 Oct 2024 13:30:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E333A6B009D for ; Fri, 18 Oct 2024 13:30:49 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 74614ACE5F for ; Fri, 18 Oct 2024 17:30:25 +0000 (UTC) X-FDA: 82687412934.14.3C97C2D Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf01.hostedemail.com (Postfix) with ESMTP id 8AE7040024 for ; Fri, 18 Oct 2024 17:30:38 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Ma12FNHk; spf=pass (imf01.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.175 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=1729272453; 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:in-reply-to:references:references:dkim-signature; bh=DfUSdtWOnTBS3aUaneALBJjz6yO/1MpkxmVLk8hKBQI=; b=aO6h9s9M9N40+5CtEJFsw1l128qDxmKbdyiRnda+15x2pNqkvDuorbHnfl6Aws83nRvWeA LSJchlTPANncA4qmValHkJBrvlFDx6g8t2W7hCKj18He6nSd8xf6O2LWA20GTFwKT3065j bw+mturdSk9FAQYMNsVWRGU6oS37+qE= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Ma12FNHk; spf=pass (imf01.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.175 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=1729272453; a=rsa-sha256; cv=none; b=x93P7gcBjYVxgGml7ouZC+aMpkoCsj4MvHiWu8XFQbkoieapkMONrTkTYh5hbz1SE2GyhB 7q7jREcNvyk5YJ+2YTEFUxMMhhF+PlNwc02qoJEPZBdywOW3heg9NUvxZciuOImXJk4zog BQP6mpdQHCx6DLZE/7DFb6R6IAIhB88= Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-71e7086c231so1828284b3a.0 for ; Fri, 18 Oct 2024 10:30:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729272646; x=1729877446; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DfUSdtWOnTBS3aUaneALBJjz6yO/1MpkxmVLk8hKBQI=; b=Ma12FNHkHIrZBsWeV6VnYn9JBiEOwgDeAJ61Jrj30Pr0Rbejj8eYUfrxkKxeKKNaOF y7PbTNSh8QEauIWRs3+CYOXI15eT6nao2giTUXQLXXURD+Avxg8uf696VSUMIThAznUm 4+0J/ZVsdrE/q7R2vDNHBwmz0esj4wfzExCkLaHO7RFgjLT8fFJq+95KehfesrXwKqNW KM5oAF5Gbw42e4miQ1McD+I8OXRfboZSIG9hOuNMBN+c6x+Ag6T31AKwBUN04REpMhm2 GewGSho1u0BNS+vtvcsUyQdKidP+kOGwUcoo+qy4aBpcbd5VCD5Dm/47MTl36q7qPy+d aUHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729272646; x=1729877446; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DfUSdtWOnTBS3aUaneALBJjz6yO/1MpkxmVLk8hKBQI=; b=DOvcjmY2bHeYAuBxnkpmix9CCOXQQhYR6jf2h8R1UNbHQzXCJS90HyN1oJURoRUg32 eSUTR83b3YZSSl1SOPQW4BidoO5cPP4p+sPvfOzpDcWH/cqQ8ts7JC4X+q0aIU9vHrw+ 5o4splHWq137GqDdPFLf3s7xATMgeZA/0KO96tTdXDozpUzpCEUWoz/9ZqppLCRPCF3J vVz/D8i8ruNuPYGKZiWF6yEsWGnMmpFIq0H72RmUde2bgRHuMI1Pvbk1Hv2DE9C9d5L1 D3k6y0mt8kWB3tMDavmNQIHA5SC0q+TJE4BJOZfPJ1Olf+ugIGQtT57vAMyQZVsfI0AS KtNA== X-Forwarded-Encrypted: i=1; AJvYcCWoCo2ef9UbS3ZrZyuHRg24PpyPCUg51wxaqVoqwk+1UNVEsZ69jWCJL6VyPmWQsg6B7JRzlB1qyA==@kvack.org X-Gm-Message-State: AOJu0YxDhRQuWbsDL3AazGKPu4pk73ydZf8O+jNw+NrM/szegdM6QUrz sJLUGgLgIlYKrpABhOa28pGeoR4tzXmWWJyT33Pbn+gtOQcXyz+K X-Google-Smtp-Source: AGHT+IEH/PHoy0SvfRofUPBZ0xaaeQuP6mqbjcomFuXt7qmLHoVJL01TXC7JEI5XORTcA+JdNts71g== X-Received: by 2002:a05:6a00:6618:b0:71e:4e2a:38c4 with SMTP id d2e1a72fcca58-71ea31e53d5mr3448284b3a.14.1729272646416; Fri, 18 Oct 2024 10:30:46 -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.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 10:30: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: [PATCH v3 05/12] book3s64/hash: Add hash_debug_pagealloc_alloc_slots() function Date: Fri, 18 Oct 2024 22:59:46 +0530 Message-ID: X-Mailer: git-send-email 2.46.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 8AE7040024 X-Stat-Signature: 5xocwub5hctrxuoo8aeq1r9hb9njutxy X-Rspam-User: X-HE-Tag: 1729272638-923560 X-HE-Meta: U2FsdGVkX18OyPlFPjm0oVFM1p0sjdtKoin4gyQwnQZO0Yn/8uf3izygpZw4xggQ4eom74c0EiPyq0x10PMqCu8jMEjqO8kYCNvzOmS8XABzMKpviknXcYKwcY6NQSa/JPfxEHttqL7+UuYDHhZvXl8SgZjMoIAQVjuoFqzf8ppuhWU47jh+JZESfGrwvI2JaA4OsuisK9lfNDjdxO9UbEu8KlphUXanMamP3GrYxD9yRmHtWQ36RCevnu+9r3AzOM4CseL+r3xNgCnCkmVWEROQAWxYgzb2oHF0pAbGYaZS0pbrmBHCPigHs0UMg6SdMk/D53jrzmDrvzAyydvDT7NAAlTDpJGz/ufL2PNFI7u4Gkmr9TUOk3TWejY7shFkX39aLw4KirYiAhVDhvVClTlEP1iTL4vAwzWd3Cegh3tRcwqumx/9ebLcTvXM3jhPADaIVILcp90dGTniLvw97yhBFM1JJt3A4DKjw37u0PjcY2P+dFkvZqj1Q0/yTFtlVXtcQKIBNMH2xIzXW04xr8eQjG5/P3UK4KgZTh6LaoJF18hPNN4XIlqsL2cqhz7RzHZ2C0I4LN3OGKFtQlAkUMpRE3oNQ/CHtV3MuTbkP/LJ9FVYGKtEfkok7WiZU/TBXqnCjd/20SvR71uSCY3hcgf0zV+hxUM0cP5s6aEUm82l0gi+QErdVzOgqeBDxi+k50r4lmsfe5YlgIWIA/51RgoW9y0MNVzwZ/TyefBT6u3BQok941ENr3jvceAvspQFqFls537fPxBhYfgY4NU4/fwViEkYH7tFAe1Df9V2XELBAwa91oM4re/U8W0lvIEg4VyQY+72NIeO7ZPQmcysPM4oBq1f+jVnGe01uxXACeKBSEqZUvTDp5uC1CfQMP/4eN97/SgFbqnYUklBpf/xravFZmOH13NSsK/ewlWcUxGqDQoAMEJ+40lWR5OWTsBA0Z3PAE1h/2JMiAVZarF EGEM9CmO rux0M2zipaHSXc3KN4SIx1Ij8QT10685673IpJAActZjn7NFmA7l9mVKALFzdco3OFaCJnUcyvx4ih02e0jmR802Op/8SfNJ3As91X3cC9VtL4Nxzf8MC+MNhgqrnT4dw6tNo3z7Dc+GSH+++l38dnmtuBViiL7EN/Sn6NTU3cOpvJsa5kg61JVxUi+WdFvbMy30UNu41npEnBv9rJ4YjOH0hQVjP6MG0jpEb4cm+bTxPYgQeijEMsPaBYDkAYGy9NST55ukSwE8pBUZ9zMgGFMvGV/6DX/4DrdWflFn4Ki6sqLpFscbKh6TWHMYHYG9ozmWLWwkdhCW2IVGSnCgZheqimg== 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: This adds hash_debug_pagealloc_alloc_slots() function instead of open coding that in htab_initialize(). This is required since we will be separating the kfence functionality to not depend upon debug_pagealloc. Now that everything required for debug_pagealloc is under a #ifdef config. Bring in linear_map_hash_slots and linear_map_hash_count variables under the same config too. Signed-off-by: Ritesh Harjani (IBM) --- arch/powerpc/mm/book3s64/hash_utils.c | 29 ++++++++++++++++----------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/arch/powerpc/mm/book3s64/hash_utils.c b/arch/powerpc/mm/book3s64/hash_utils.c index de3cabd66812..0b63acf62d1d 100644 --- a/arch/powerpc/mm/book3s64/hash_utils.c +++ b/arch/powerpc/mm/book3s64/hash_utils.c @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(mmu_slb_size); #ifdef CONFIG_PPC_64K_PAGES int mmu_ci_restrictions; #endif -static u8 *linear_map_hash_slots; -static unsigned long linear_map_hash_count; struct mmu_hash_ops mmu_hash_ops __ro_after_init; EXPORT_SYMBOL(mmu_hash_ops); @@ -274,6 +272,8 @@ void hash__tlbiel_all(unsigned int action) } #ifdef CONFIG_DEBUG_PAGEALLOC +static u8 *linear_map_hash_slots; +static unsigned long linear_map_hash_count; static DEFINE_RAW_SPINLOCK(linear_map_hash_lock); static void kernel_map_linear_page(unsigned long vaddr, unsigned long lmi) @@ -328,6 +328,19 @@ static void kernel_unmap_linear_page(unsigned long vaddr, unsigned long lmi) mmu_kernel_ssize, 0); } +static inline void hash_debug_pagealloc_alloc_slots(void) +{ + if (!debug_pagealloc_enabled()) + return; + linear_map_hash_count = memblock_end_of_DRAM() >> PAGE_SHIFT; + linear_map_hash_slots = memblock_alloc_try_nid( + linear_map_hash_count, 1, MEMBLOCK_LOW_LIMIT, + ppc64_rma_size, NUMA_NO_NODE); + if (!linear_map_hash_slots) + panic("%s: Failed to allocate %lu bytes max_addr=%pa\n", + __func__, linear_map_hash_count, &ppc64_rma_size); +} + static inline void hash_debug_pagealloc_add_slot(phys_addr_t paddr, int slot) { if (!debug_pagealloc_enabled()) @@ -361,6 +374,7 @@ int hash__kernel_map_pages(struct page *page, int numpages, { return 0; } +static inline void hash_debug_pagealloc_alloc_slots(void) {} static inline void hash_debug_pagealloc_add_slot(phys_addr_t paddr, int slot) {} #endif /* CONFIG_DEBUG_PAGEALLOC */ @@ -1223,16 +1237,7 @@ static void __init htab_initialize(void) prot = pgprot_val(PAGE_KERNEL); - if (debug_pagealloc_enabled()) { - linear_map_hash_count = memblock_end_of_DRAM() >> PAGE_SHIFT; - linear_map_hash_slots = memblock_alloc_try_nid( - linear_map_hash_count, 1, MEMBLOCK_LOW_LIMIT, - ppc64_rma_size, NUMA_NO_NODE); - if (!linear_map_hash_slots) - panic("%s: Failed to allocate %lu bytes max_addr=%pa\n", - __func__, linear_map_hash_count, &ppc64_rma_size); - } - + hash_debug_pagealloc_alloc_slots(); /* create bolted the linear mapping in the hash table */ for_each_mem_range(i, &base, &end) { size = end - base; From patchwork Fri Oct 18 17:29:47 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: 13842088 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 61CE5D3DEA0 for ; Fri, 18 Oct 2024 17:30:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E76886B009F; Fri, 18 Oct 2024 13:30:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E260F6B00A0; Fri, 18 Oct 2024 13:30:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C9F886B00A1; Fri, 18 Oct 2024 13:30:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id A9A4D6B009F for ; Fri, 18 Oct 2024 13:30:54 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 4540FC17A1 for ; Fri, 18 Oct 2024 17:30:41 +0000 (UTC) X-FDA: 82687412808.06.FFD08C5 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf14.hostedemail.com (Postfix) with ESMTP id A73EC100015 for ; Fri, 18 Oct 2024 17:30:39 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=kmgd64rx; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf14.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729272533; a=rsa-sha256; cv=none; b=dzScKGgQZl5Vshy4hBt4EFjnoY0Wz6Nr4wT+EmEZ8K9cbWdbSa0dtGV5M2CK9B/cQRBV27 rAcpsp3IIEpSef+y/0OruZ3MhpVd00SsDVZ78jBlzRD+7DmQC/CEKRcjPahBNBE7KuPmI4 WjgmHetsSz9J6t8e0R+/OxuUYhvTR8o= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=kmgd64rx; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf14.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729272533; 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:in-reply-to:references:references:dkim-signature; bh=/yT2xkfY2cuEcnEiccNoddLAZz1lOngFGOhNqKs9rtU=; b=79pFUHrmKogvi5krKa+8FvhL8nLXKygxhr6wHnlN1AMXtdYjPNHf8vXBDlq3yIWbrLteex osEQ/11F9T6CIby4VWWWIVvQ5iUFdE/xP67hNFRP6CxZ+tegtvQSF9RSAlsP5qhrPfc9xv 8nWyvYVV2DG8uH4G3WBVzG3uFN0tE1Y= Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-71e4244fdc6so1725752b3a.0 for ; Fri, 18 Oct 2024 10:30:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729272651; x=1729877451; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/yT2xkfY2cuEcnEiccNoddLAZz1lOngFGOhNqKs9rtU=; b=kmgd64rxMy1OnXdOG00WRjmnWn9edYjP7Q6kEx2E2Am0xxFK1s7kuxvQR1lvu4G/rS zBTt0quCOA0W+1XpXmFLb577a1xq/tijMCcsGb9sGafLwuGYhBkZXMMrW2fb2r1fKRGY fFuJlrOOqidYMIuuF+05uElNUyISqopANwx8ztgdF0golsRTuNdt01Vztc2eimXl26zc 9ciCGkYq2OYFqdVzRg8MBSokeEScJGDQ8Kpp9VRr/donSHlv8nRTgdEuaZghNsrPXHzP tVZi8jUpBs127bUJP/wiq4nULgq4vAwL1wBQweWI3H0VwWggix03SkIqHHWKlnk1kPsB xXjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729272651; x=1729877451; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/yT2xkfY2cuEcnEiccNoddLAZz1lOngFGOhNqKs9rtU=; b=gZD6S5ikW0QPuEjFKHs006hz4db5DimjnNPsuRpi/SOWAvLAJsEZpZ8GgYqs2+RijC 2vOfg1s/ZVCCqBUj64Aosi7bOu3O0egXFDo4WIbOPWwWDceAvIZSXNNjTmnrU02k+GDr dhos4HaIybKsFU3D6kYItcYwYSzDbayXceeWXyGzqBXy/psjOBaXqiM/JGRj46IK6g8n S7XFOtBsLwoe9wcpDTEoOaEEzCYDWTTxzZp5DlUf0eWnRkfUJzI428Ugv/zfiCrpSZ+y NcRfyClxRT7mtrPTZ7/aFcqyUiPsw12TUfJ6n5ePNrOFht0xbm8jwzLZIYsOj6JeVNej FscQ== X-Forwarded-Encrypted: i=1; AJvYcCWnqxV1E2cLajnvBw5Qv6WhLdMHOHFpz64dp/brl4eqHj8+QQoZ33B3OZawbygMQlFahTezgmM6Qg==@kvack.org X-Gm-Message-State: AOJu0YzeFv8Xq+WNWqgySdf4na3Nn0vY2d2/Oyofj/eTJdOawe+50COC 2HTxGEKuJPmHP1zTTfksTfvIqTN8P4fCB1ZHSS8U4zTAZ2CIBZaz X-Google-Smtp-Source: AGHT+IHW0pQgponGx/gVpoZ4bowEpREiydwVrhTTv3Smj0fSfHzFmSnPLW4FIXTVD3Eg6sTX/fZl5A== X-Received: by 2002:a05:6a21:3a96:b0:1d8:fcf2:9ce2 with SMTP id adf61e73a8af0-1d92c57db72mr3781064637.44.1729272651290; Fri, 18 Oct 2024 10:30:51 -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.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 10:30:50 -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 06/12] book3s64/hash: Refactor hash__kernel_map_pages() function Date: Fri, 18 Oct 2024 22:59:47 +0530 Message-ID: <0cb8ddcccdcf61ea06ab4d92aacd770c16cc0f2c.1729271995.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: A73EC100015 X-Stat-Signature: 7bpum1r7dbz9kaedk4quzztwwd8edn7e X-Rspam-User: X-HE-Tag: 1729272639-450430 X-HE-Meta: U2FsdGVkX1/4kMey5b1F/mwuBGirYp82d/uNsbXm1IA/6gp+W8pg/Z9ny9/f99lTL8aqkAfJXnK1i9C0D0xWbp8rFSHCRFrTIfrKRwLZSF0+LqvYKg4+QoSKGvHstxA4xUKoHs1nBp9+1DOFphjyDkwdQ8XJ7a6bs0cKyvWSL35FAlgdIBGRXI6xJNp+ASeXdgY8oTTNz5uMKV8a5GFwx6fjxrhUNp2i4cKjdpSJYNL8AoBffB/l1doOAfzit/1JUTaJS6JuwKphLSpOvpIU6rekz9HKNuriwJbDZlwTENaPsU7XjaDjUF1ZitCyHwEpF+xik6bLxsCEudiYOwfQzN5MmeE8lZiVIYD789cJxlUiT8n4whWZ36+bg+X6ASt753GyMgOAyES1IMnKQZFfa5CL6R9Kz9MOgDDamzWH++BykMYqTognVsOrJgkOjH3l6TiSyKqhZCgkWzeZyi6H1/7j1VKf4tESxcOPjkaBcy2ONedDl4MjBdHW6CCaJJMJIzxt1Hz+86SAvEsO2vdbBKH4tiK6hjN6qSAq7skeHhDIbB2176GYFdfvIWXNpALI3c/nacI8vMunQ6nXXJVIssXxV3Tbb/k2DPdbzGD1k0eM8AotHMjseoMpoNy91lBncsX+66sXA5msV9Os2vi/ngPlQpNd2jGVg/Ac9u4Rqbny05HsTHLGHw7Hv5UTyA7eQ0guMXFjYxBGYhz9SmjPOKKgd6HAdn8DBJtPqUU6PTNageVXLvwbiz+9/52hjTubLmNmIKbFGi1wXIGy5AfLTA9MLgKsCWb3WhCLoJxPl6Zdjl3Ah747Zfc0vQfo+b/nFmhxXKwsFJrWvgBF09z6IAddbTRAoeHIH2HRrxQNQVlg8Wy5T6mCnMPNnbwbsEX8ym8AKLTBTtejTAQMumZWG7FlRwXzCf1dzdWtOFqG7EsWbCAlE+NJpINa/pUe841ewMC+paveqGDnZtp4VVf i5Wod59J orX1tiQ/s0RKAE90afXqbK8FeLb+XMpPwNBwj+nF3H6BeZWwH/bELkSxYiuW+dICFZjo71kz3kWk2F17n3tb9BEUQ3SY6IngDjA7Z6GCc5ZahRPb3NZg2DlB0Efpr2s4zNR/et7far+W/Pnw5qhcMIpP0x7m98yDGrxHA2Xkq8i/K/S8hWOk8wIQSgJQ/oO2n9T7xkIRm5X12OtTCa1+PITU49k/2BO56Sp9ekrhSCyNTsuB/6UPVKEqCDr5agaLjdshx6ADqXwOdi/ob0ZEanw5cV3+/KOed0irMGWaxnR0o99o6f6MBkKKYjRaNTBquptn0A6T25+X+zCikfKamf20kcw== 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: This refactors hash__kernel_map_pages() function to call hash_debug_pagealloc_map_pages(). This will come useful when we will add kfence support. No functionality changes in this patch. Signed-off-by: Ritesh Harjani (IBM) --- arch/powerpc/mm/book3s64/hash_utils.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/mm/book3s64/hash_utils.c b/arch/powerpc/mm/book3s64/hash_utils.c index 0b63acf62d1d..ab50bb33a390 100644 --- a/arch/powerpc/mm/book3s64/hash_utils.c +++ b/arch/powerpc/mm/book3s64/hash_utils.c @@ -349,7 +349,8 @@ static inline void hash_debug_pagealloc_add_slot(phys_addr_t paddr, int slot) linear_map_hash_slots[paddr >> PAGE_SHIFT] = slot | 0x80; } -int hash__kernel_map_pages(struct page *page, int numpages, int enable) +static int hash_debug_pagealloc_map_pages(struct page *page, int numpages, + int enable) { unsigned long flags, vaddr, lmi; int i; @@ -368,6 +369,12 @@ int hash__kernel_map_pages(struct page *page, int numpages, int enable) local_irq_restore(flags); return 0; } + +int hash__kernel_map_pages(struct page *page, int numpages, int enable) +{ + return hash_debug_pagealloc_map_pages(page, numpages, enable); +} + #else /* CONFIG_DEBUG_PAGEALLOC */ int hash__kernel_map_pages(struct page *page, int numpages, int enable) From patchwork Fri Oct 18 17:29:48 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: 13842089 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 C0891D3DEA0 for ; Fri, 18 Oct 2024 17:31:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4FFC46B0082; Fri, 18 Oct 2024 13:31:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4887E6B0083; Fri, 18 Oct 2024 13:31:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3291E6B00A1; Fri, 18 Oct 2024 13:31:00 -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 11DFE6B0082 for ; Fri, 18 Oct 2024 13:31:00 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 0413F1C6191 for ; Fri, 18 Oct 2024 17:30:45 +0000 (UTC) X-FDA: 82687413186.15.FF46108 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by imf25.hostedemail.com (Postfix) with ESMTP id 0EFD9A0029 for ; Fri, 18 Oct 2024 17:30:49 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nCBbwVPo; spf=pass (imf25.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.215.177 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=1729272583; a=rsa-sha256; cv=none; b=oe/85ygahj2+WP7YvURLj7khtLGhbCUea6BXgazyyalpuakNzumQHOZl3VU7/G38N2qYiN sBB2NCvVoVACLzEzi/FSHLyyO1aT++DsyNKLnFl3R1D+anuEKiSKY/+fEf+n00HemiQkwy IY7/xuOQP532ZcUGi2E7brWiHihOxlU= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nCBbwVPo; spf=pass (imf25.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.215.177 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=1729272583; 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:in-reply-to:references:references:dkim-signature; bh=SYv3qxbJ8XzSYVM3O5y7o2xiEmCUj8b+8LHRXlL50QE=; b=l9z3fys1nwWmD+Eb1G38xdzGuJnc3uZAViWgnDxEKqXJyHKB0tTGB9RWX2195RgAhLcjox rB/+DzU2xBVV+flRqN5SWbJybysXWnyxpP2ytlAcdnogJdrkoFjVMVaWzzOp/cjQD8g7z7 A/7KnnUvkyUPbJwbuRpTvz0xqS1mg0k= Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-7ea784aea63so1301514a12.3 for ; Fri, 18 Oct 2024 10:30:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729272657; x=1729877457; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SYv3qxbJ8XzSYVM3O5y7o2xiEmCUj8b+8LHRXlL50QE=; b=nCBbwVPoOK7LHMPFekvf9pmHPfomgnHbR+A8PIzml6tYPvhAstOh+llKWTW3FpWbKm MNJDHkZJHjroLShK4n6zyWTDdZvyXCI9IeJUS231AsHaoawyPvkhDi0Kj8xcOtdII+wh 3gpXZ9KBcsLDxQkup+UYTi+zld1wL8EIo8NwqtvWxKkj5RmnuDEgdqI15qsORZncQGB3 shCdc6h67HCjf/1FExR8Z9WMyAJ94u2MeGzvFHj+XSlQYPhwt98xJAAZ84yHRtBS9bgz JF5qVRpre3HnRZ2tYloxpHygX5cjPRs2FqpW3z3jKErfszA+7+zfADACUdej0oDQTier VhgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729272657; x=1729877457; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SYv3qxbJ8XzSYVM3O5y7o2xiEmCUj8b+8LHRXlL50QE=; b=XZEodEELJeo7nlawbLFxH6xO93Ke9nyEYCH7UmTD97OOd4LQOunku9ti6m6ZXEaCqD LVqbu11PnOZqsOO7dWAZbFixiuXdeLktbbgYG8M+pFgGUa/EGyWi+KHQ3PbP7BjK0fwA WASzzakZWeRtBQ64bTvnHZiFojIo8bm4OD3S4krG7Ec8qfdWWJuT56lTCgKpifzD4BJa pGNPgEyqCoiGozgj6KM+JoGhPBtAIfugAZjY1gkuuEuJV7P2p+p/PPCcPeZrkN8d/d+T r4qTc2Qbf/3OJlCuevwvMTA+au/IqUR4CN2OQuVr58uwHKUFTfJ+0FlxG/A/cJZUIUfm EBow== X-Forwarded-Encrypted: i=1; AJvYcCXHoHxDCKXeM+KqgIu2kk8IWs9B+7tC1fDnrFzysq8h3er+Dv4pbG7KqWz61ZDDexQMHzxvgHQDxw==@kvack.org X-Gm-Message-State: AOJu0Yy5LAtObKiT3e+ye6xbiIso1IdEffbJO8W6i8Z2wHwIxVp56P/d SxfeBU8Kwrh0D3LIVgP8FbXXU2iIKtoxfHK/u7GqRQ+REDXf3pgC X-Google-Smtp-Source: AGHT+IGzdUgXGWS3Rnfne00N0lzoqmJmv13oE/GEcsOOigglv7dM20Xc4zaopt4Axws81Q8JXv67zw== X-Received: by 2002:a05:6a21:a4c1:b0:1d8:f1f4:f4ee with SMTP id adf61e73a8af0-1d92c4baaaemr4986521637.8.1729272656623; Fri, 18 Oct 2024 10:30:56 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 10:30:55 -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 07/12] book3s64/hash: Make kernel_map_linear_page() generic Date: Fri, 18 Oct 2024 22:59:48 +0530 Message-ID: <5b67df7b29e68d7c78d6fc1f42d41137299bac6b.1729271995.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: k6dzbxays561neio1u1kf9hocp8ckrod X-Rspamd-Queue-Id: 0EFD9A0029 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1729272649-900658 X-HE-Meta: U2FsdGVkX193uBHu8HRBhBNJMfQtBOaV9xNy+SioOV2obam1U550j5P8sLZO8sdZPieJ5AvzNtKBf5gXNDPPDO75oz0FCuCg/e7+mqev9Y+qhTbPnnDXBFcth09JIkgJ/udTRilS+zO2oeRwico5V0aUbWa3Wfy21a8xKoUi/z/zGl/bWJwKiVNkIWDtJVtuCF7czP/UWIKgvvAOvPkrUmZijVZO2XMStSv7HYTx9u2T6/hzTBAMSQEg28uAfFFpuFIAvNPD2HHy8jQpN7/NGwlesSiI4CbIakrT+eXBXj4Xxn+inMAxvR0WZP6HO4EFEEUl7Dj7EcfluUVK4Ap/qwa4h7tyguwdnG3loUTx4z4z0Hx5CUPGRSVEv7+zuQSQTHZy870elAbnnZ2CQ/DodddTWeyBm1460eVg8V9Dzhb4GcuGB1+STXp0lAss1zULSTSZWwUIuccHIo+T8/zgppCMVgpWuBHpiHLEgIYZi75iV3qOmJr0A85Ijiv7gEPTVAKu1UIT4V0BAEw1mYc3XqoEojNvqQw7HT4cmFwLPcjM0F6Lv2FuH0SJxqx1u0HdP7UUx4v3Z9+p1gZ9aDxzbJFROIKCE0/A+BWo3+jApDFGX4xCidEOKUgQX9m6rWecMK33/AF5NU+8u4daj+OPMxBxrT7o4QHPkLFG9XZ8MVmPfjBN8jxFJZwqLDkgjQNH8L4guJkU+wkuNvDod1N1j+jeI+zCxmp4g+DsuKuhrtsow38T8Ke6n6ANtAplGZ6IQ7ZPww6oESa8pLTNRqowUT8qS0hz2yvlHrTF3GWUZjPFAH+QiiHTgukadGrNUD/oZiHnRPf/HUIPZGWIXIMbDoemEwA/z2L8rkPi9FMNpxBlo0LUtHOd+Pc1HlfFEMkd5trUwy5/Di+5Hp6ALBUcY0tj3Q25HnZm5xGwSbJS3HwE75Z8PUcEiOZ+p5GanglV+8G8mP6TSe4AIiLzL4Y bg3yX1bj 1B/AkIIfrn6CaRb4XsPVT52P69ZtE4nTPNrWPgLcU98TzJaq3P0TjE3pOLmSfdtqNvMuvyqw/kQZa1Hf7QXUSkfMu37lOaam4hf5Mv4AK8Cst2VIZis1pjVAyxP18skhKb5nSaqTF5LckX08EdNYn4vRlegxQYM/EN4KcZ9FXu1DbjHahl8LRP4yh7q4VYS8d82t1Vx1f1vql2i+4og0B+Av7Z+cH8uV4cGFIWrcrHaXSLAoeEjIItpqnyUSIzivjU2HQZaxgR/g9UWoXyj9HQ5O1YgkE/a2xRlcOBikpQQrwXLOg3MQHdb6kRmxtFWC3MvD3CukFuFc0XajCm0iql8DOzQ== 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: Currently kernel_map_linear_page() function assumes to be working on linear_map_hash_slots array. But since in later patches we need a separate linear map array for kfence, hence make kernel_map_linear_page() take a linear map array and lock in it's function argument. This is needed to separate out kfence from debug_pagealloc infrastructure. Signed-off-by: Ritesh Harjani (IBM) --- arch/powerpc/mm/book3s64/hash_utils.c | 47 ++++++++++++++------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/arch/powerpc/mm/book3s64/hash_utils.c b/arch/powerpc/mm/book3s64/hash_utils.c index ab50bb33a390..11975a2f7403 100644 --- a/arch/powerpc/mm/book3s64/hash_utils.c +++ b/arch/powerpc/mm/book3s64/hash_utils.c @@ -272,11 +272,8 @@ void hash__tlbiel_all(unsigned int action) } #ifdef CONFIG_DEBUG_PAGEALLOC -static u8 *linear_map_hash_slots; -static unsigned long linear_map_hash_count; -static DEFINE_RAW_SPINLOCK(linear_map_hash_lock); - -static void kernel_map_linear_page(unsigned long vaddr, unsigned long lmi) +static void kernel_map_linear_page(unsigned long vaddr, unsigned long idx, + u8 *slots, raw_spinlock_t *lock) { unsigned long hash; unsigned long vsid = get_kernel_vsid(vaddr, mmu_kernel_ssize); @@ -290,7 +287,7 @@ static void kernel_map_linear_page(unsigned long vaddr, unsigned long lmi) if (!vsid) return; - if (linear_map_hash_slots[lmi] & 0x80) + if (slots[idx] & 0x80) return; ret = hpte_insert_repeating(hash, vpn, __pa(vaddr), mode, @@ -298,36 +295,40 @@ static void kernel_map_linear_page(unsigned long vaddr, unsigned long lmi) mmu_linear_psize, mmu_kernel_ssize); BUG_ON (ret < 0); - raw_spin_lock(&linear_map_hash_lock); - BUG_ON(linear_map_hash_slots[lmi] & 0x80); - linear_map_hash_slots[lmi] = ret | 0x80; - raw_spin_unlock(&linear_map_hash_lock); + raw_spin_lock(lock); + BUG_ON(slots[idx] & 0x80); + slots[idx] = ret | 0x80; + raw_spin_unlock(lock); } -static void kernel_unmap_linear_page(unsigned long vaddr, unsigned long lmi) +static void kernel_unmap_linear_page(unsigned long vaddr, unsigned long idx, + u8 *slots, raw_spinlock_t *lock) { - unsigned long hash, hidx, slot; + unsigned long hash, hslot, slot; unsigned long vsid = get_kernel_vsid(vaddr, mmu_kernel_ssize); unsigned long vpn = hpt_vpn(vaddr, vsid, mmu_kernel_ssize); hash = hpt_hash(vpn, PAGE_SHIFT, mmu_kernel_ssize); - raw_spin_lock(&linear_map_hash_lock); - if (!(linear_map_hash_slots[lmi] & 0x80)) { - raw_spin_unlock(&linear_map_hash_lock); + raw_spin_lock(lock); + if (!(slots[idx] & 0x80)) { + raw_spin_unlock(lock); return; } - hidx = linear_map_hash_slots[lmi] & 0x7f; - linear_map_hash_slots[lmi] = 0; - raw_spin_unlock(&linear_map_hash_lock); - if (hidx & _PTEIDX_SECONDARY) + hslot = slots[idx] & 0x7f; + slots[idx] = 0; + raw_spin_unlock(lock); + if (hslot & _PTEIDX_SECONDARY) hash = ~hash; slot = (hash & htab_hash_mask) * HPTES_PER_GROUP; - slot += hidx & _PTEIDX_GROUP_IX; + slot += hslot & _PTEIDX_GROUP_IX; mmu_hash_ops.hpte_invalidate(slot, vpn, mmu_linear_psize, mmu_linear_psize, mmu_kernel_ssize, 0); } +static u8 *linear_map_hash_slots; +static unsigned long linear_map_hash_count; +static DEFINE_RAW_SPINLOCK(linear_map_hash_lock); static inline void hash_debug_pagealloc_alloc_slots(void) { if (!debug_pagealloc_enabled()) @@ -362,9 +363,11 @@ static int hash_debug_pagealloc_map_pages(struct page *page, int numpages, if (lmi >= linear_map_hash_count) continue; if (enable) - kernel_map_linear_page(vaddr, lmi); + kernel_map_linear_page(vaddr, lmi, + linear_map_hash_slots, &linear_map_hash_lock); else - kernel_unmap_linear_page(vaddr, lmi); + kernel_unmap_linear_page(vaddr, lmi, + linear_map_hash_slots, &linear_map_hash_lock); } local_irq_restore(flags); return 0; From patchwork Fri Oct 18 17:29:49 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: 13842090 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 AB584D3DEA2 for ; Fri, 18 Oct 2024 17:31:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 303496B00A3; Fri, 18 Oct 2024 13:31:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B3AE6B00A4; Fri, 18 Oct 2024 13:31:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 155316B00A5; Fri, 18 Oct 2024 13:31:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E9E166B00A3 for ; Fri, 18 Oct 2024 13:31:04 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 6FA32ACF74 for ; Fri, 18 Oct 2024 17:30:40 +0000 (UTC) X-FDA: 82687413354.24.66B65FA Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) by imf28.hostedemail.com (Postfix) with ESMTP id A408BC0024 for ; Fri, 18 Oct 2024 17:30:51 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=BZlOn9SZ; spf=pass (imf28.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=1729272614; 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:in-reply-to:references:references:dkim-signature; bh=c7nu+U6UkRZF2cuN8FLbB8nvBf84Wg4YjQThyWhRKHk=; b=IIlN6jtwgvHypr7pSK1l46xvZyIRYseXSJR23Dglx54BMAR7F0Ir3Hw6DZ5a+b/V3T8PNk WSAHWJtf5JA47zSmYq6ii//+Sby8WcIzcTWGftPFCRyJcvKdnjQVuIzTh+1uqyNPnb1BwA PobyjVBb886OTO3/1AXVhkHJEPjp9mA= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=BZlOn9SZ; spf=pass (imf28.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=1729272614; a=rsa-sha256; cv=none; b=IvuNcUKIVDEAHe/Ve6Sv35hpoAH2sngEp0pDKeWu4GhpbdBF2Fw/h8vl/5JtZFevEt4wwd PORTfn3RO29dJX6JnXDxjIED5noD48QMEp/MGAovauyaRjG7rU/7+n2cW537syINp0jZVh 9jZJ+miLFcQD/sKmwSt5MKlJXY7TTqs= Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-7ea8d7341e6so1813820a12.3 for ; Fri, 18 Oct 2024 10:31:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729272661; x=1729877461; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=c7nu+U6UkRZF2cuN8FLbB8nvBf84Wg4YjQThyWhRKHk=; b=BZlOn9SZBGi4w/e9VDhesjlLF6942fhyCI0+w+DUDkJNZRMDksaY6t3ax9VO0AkD4o BC/Dk7QYgDzYWciyXwuW2WEpACdw6+viTXG5gzKikcrA5mG2LIHODjxbyl0eItZMLmYn 9cBa5mRWWbJOZVT2a+hZo1+Jjl8kFDPDNmPno1iMM3IgR9ZZA5+Z6FpflKpQq5/4lpee x0gnUD9ffnVic+iJ5t3VwQ/2fEioBMXOkkXnnlASe1Xs1sgN46CpumPj1W4WkY6C00O3 03kTWM3kbYuv1nKvsTc89iK0IpWYwENHrsBCISaXZ/nwQ5f+90yxJgBGDEK0Bcf0lVuX glOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729272661; x=1729877461; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c7nu+U6UkRZF2cuN8FLbB8nvBf84Wg4YjQThyWhRKHk=; b=UxP11LuAztI7CJyfktZ4fea81OZdv7R0VUaFAN8Abbhpy60BzfnKOBnHb2mtmHziDO NUWJSKJHM/6kUrEFU8Xetq2zRWZyb0rM2Bz/p9VK99qh/V1vjPrtZsKsv4lTUgbiYULp SIcpoMPb25JM9h/QEHeDctC3hRjtALyGM9E1eMy6GWN2pE06FTbFY6FC5Ny9wKgZApG/ YqKYTzulD4RvKzcIYlIMeWH2SiJmyOTu4YCXSKSBM8caoAGrpdS5MfqRvfYFZx9/Kpl6 V9YD+zXqWqSoIa/Bf+dI5Gsd+a7aYqlXap/omi1fRXNzinmEd+Ug0GW482KrnVIJZe6w /6Ng== X-Forwarded-Encrypted: i=1; AJvYcCVF4Avq0jQ8pHnsjae078BX3UvRnzr8EdWK9pvPaGLdHcLORmv6qkV9bFaVmM+Yr5oVL6+LLPFBPA==@kvack.org X-Gm-Message-State: AOJu0YwxWGtD1o/htmZ25pb6uDyxZ6J4LIHfn0x9XqXwVBn2WWFBOiUA Jat12Sq6Sf1gbh0YB7GHXC9yHlLTcpLUzqq3IPBC04qsM0kYrCETdPqhz6S9 X-Google-Smtp-Source: AGHT+IHJYrrrqJRfAumO9Q20FqjOKsTO5quh/OtUWisgh37hgw56Q3PPkpt1yyNYXV1te9hYA/UiKQ== X-Received: by 2002:a05:6a21:1519:b0:1d8:a3ab:7228 with SMTP id adf61e73a8af0-1d92c3323d2mr4881461637.0.1729272661553; Fri, 18 Oct 2024 10:31:01 -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.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 10:31:00 -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 08/12] book3s64/hash: Disable debug_pagealloc if it requires more memory Date: Fri, 18 Oct 2024 22:59:49 +0530 Message-ID: X-Mailer: git-send-email 2.46.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: hz8onkiyt7f4zdb9gsiipxp4exmgjz5s X-Rspamd-Queue-Id: A408BC0024 X-Rspamd-Server: rspam11 X-HE-Tag: 1729272651-193370 X-HE-Meta: U2FsdGVkX1/wphpc3f3axMFfGn+S+ELKgnt6OJSnPQNQJRPkRlOKAd/XZ08ldXitNKg+2r01F2Gx/t7PEtUFtZEwod4vSKP9y0TDDspyqWT7xHrumifRCsbgm1VkrpqBxXgGytcp2TLCOS9JDWLNBwh9/63cNar/RhY2b0YMybzMN82UYNkrj5vc36K5PTjzG24p3h/lT99uHLvpI8Tm3pFZXaZkMdRcqX4Te/ke4KpxF40wHCZthKdMrnFtx6f0VaAKb7EaSWPnQ1dBWWUz1jZ82/BzFX7OVH7kj0Nx84NeKqh5egR/r46qEu7wLPzfuKErmTS9k9w7/pW7Pap0wxyiC3qCTsQkECWbRgNsqhpMcEmYoHqKjrQgMMdlhLMPGO8pnocUa+YXQBqyKfbmnC0YVyMvADjtwnQWYFzEiqHqrx2iVLi3m486rm6v5hWJr3Ql0cj8kizJQCPCJOVVulAHLLMr2HflFjaQQI1gwrFu+ZsujmgY3zQitpE5yFE5H8meKJkCO5EOwk5+Lbb88+ASAUHYjCXxUb9USiOAfWTXqbsyasjRUjMJScAbW5y7cByxlL37YUDhQQnv187XMmo7ENC4+DIwXRbs0q2XDKWbuo239v/pIZsOTT7LoNXaxSGePQzI8GpTkC5aBf40nQ23xXIRtywCCDERfCgwyFBz8xMcdTb011E/1P8GgBhNSepIzkzsKdRJGzWtBm03uc9xIEknPSiK8guIBRR/ICXkZqQ6tBM4qco1GdIkD4fKnWx7GU/iqReBCQ/w4ZvfOxMIbbVbeNGkGPr0qa69AZpbF44PdgzC/jFOeVsdD8cRRWRp61mMnSpSKZtuRFP6TcYtYIuYRHWtR9a/QHnnqUBTyTv9bKUVatl7vhCz4kgUCv9KkPj8R6ZjZCCy9ZsfGkW4o9ruaCbsZhWOyEXTi2z8oy3OpyGXLkIGWMHJ/gdzvoatXclw1z1+mOgktf3 9MMiA7jR cg1FO5QoGoL03WNwDwaU2dsperbxq0lhmpOiWpOLjoio9A+Q+jH4iwQNK1q4awaXwYK5Y5YQqrJBLONABpd4RaC6HnEIzc0wecT+7RezPVCWOYeJRdAI4Jjunf0geOQd00jYR0K6L0HaxWVKDq9tD4A/Sy+MdLrD1moKy8xKwS3Nj+gplg2FwQ7FrH3/P0IwFaIr1fgkf+7K6Mt4VPInJaby0hYiVzswOvg3ZrVvj36/Qzn50//J/O7tDI6MsIWAbeoTF/2nytFpqFcWmtbHfq7GJpOOFFOUs6NzkDXo2A7kvJ3Zf91ZBKon1JbHo7Zh5SGFJQGaiyLkK349PUL2/fPlCBQ== 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: Make size of the linear map to be allocated in RMA region to be of ppc64_rma_size / 4. If debug_pagealloc requires more memory than that then do not allocate any memory and disable debug_pagealloc. Signed-off-by: Ritesh Harjani (IBM) --- arch/powerpc/mm/book3s64/hash_utils.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/mm/book3s64/hash_utils.c b/arch/powerpc/mm/book3s64/hash_utils.c index 11975a2f7403..f51f2cd9bf22 100644 --- a/arch/powerpc/mm/book3s64/hash_utils.c +++ b/arch/powerpc/mm/book3s64/hash_utils.c @@ -331,9 +331,19 @@ static unsigned long linear_map_hash_count; static DEFINE_RAW_SPINLOCK(linear_map_hash_lock); static inline void hash_debug_pagealloc_alloc_slots(void) { + unsigned long max_hash_count = ppc64_rma_size / 4; + if (!debug_pagealloc_enabled()) return; linear_map_hash_count = memblock_end_of_DRAM() >> PAGE_SHIFT; + if (unlikely(linear_map_hash_count > max_hash_count)) { + pr_info("linear map size (%llu) greater than 4 times RMA region (%llu). Disabling debug_pagealloc\n", + ((u64)linear_map_hash_count << PAGE_SHIFT), + ppc64_rma_size); + linear_map_hash_count = 0; + return; + } + linear_map_hash_slots = memblock_alloc_try_nid( linear_map_hash_count, 1, MEMBLOCK_LOW_LIMIT, ppc64_rma_size, NUMA_NO_NODE); @@ -344,7 +354,7 @@ static inline void hash_debug_pagealloc_alloc_slots(void) static inline void hash_debug_pagealloc_add_slot(phys_addr_t paddr, int slot) { - if (!debug_pagealloc_enabled()) + if (!debug_pagealloc_enabled() || !linear_map_hash_count) return; if ((paddr >> PAGE_SHIFT) < linear_map_hash_count) linear_map_hash_slots[paddr >> PAGE_SHIFT] = slot | 0x80; @@ -356,6 +366,9 @@ static int hash_debug_pagealloc_map_pages(struct page *page, int numpages, unsigned long flags, vaddr, lmi; int i; + if (!debug_pagealloc_enabled() || !linear_map_hash_count) + return 0; + local_irq_save(flags); for (i = 0; i < numpages; i++, page++) { vaddr = (unsigned long)page_address(page); From patchwork Fri Oct 18 17:29:50 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: 13842091 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 0D5ECD3DEA2 for ; Fri, 18 Oct 2024 17:31:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8AA986B00A5; Fri, 18 Oct 2024 13:31:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 85A3D6B00A6; Fri, 18 Oct 2024 13:31:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 686236B00A7; Fri, 18 Oct 2024 13:31:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 427CC6B00A5 for ; Fri, 18 Oct 2024 13:31:10 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 0D08A1A012A for ; Fri, 18 Oct 2024 17:30:48 +0000 (UTC) X-FDA: 82687413354.03.A668862 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by imf30.hostedemail.com (Postfix) with ESMTP id B055C80013 for ; Fri, 18 Oct 2024 17:30:46 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bfuIQyym; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.180 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729272633; a=rsa-sha256; cv=none; b=Ne1QJW72FpRc8xGCPWtYnfYfH81MzVEE/SaVEGredpc59xedqBclamoBtaKeXbpCuSuGtp Zw8c/Iu1ooCy5u7QBC+KITDLrI7Q4+JdHJTFkIoIdU4S1uvagaHsE9cBDydAwudW6uEbkZ d1zd+3pyEgbkUZafG75NfzJyV8xOtWM= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bfuIQyym; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.180 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729272633; 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:in-reply-to:references:references:dkim-signature; bh=EPaaeu37JE/wM6SvauUhRnxy0xWFM+VjQPTyakMCkTU=; b=J6VcMu/XaPymLI0xcine32r+qkAA4d0/MMzdfadfz6AtN3kL8fA3sSa+ZqrP3o0Ai87EA+ t/1DloPqLwgZ/ouSx6VGkKVhecocbTcsdDBwxMxoi1U9w1wlG4ZVoqhTHDgUpqPT8giHUY L+65e6vJg3M9l4WqOcuNlDnRUck8X0c= Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-71e79f73aaeso1759735b3a.3 for ; Fri, 18 Oct 2024 10:31:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729272667; x=1729877467; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EPaaeu37JE/wM6SvauUhRnxy0xWFM+VjQPTyakMCkTU=; b=bfuIQyymDkqMg9aJPHHYiCcCFCvZHI+0kzIwkHMPGf9m+ZH1UqqmFINkzPfzheRVOw CGfRL3ZAOyXC+4scFrwQqFbDUm4tbsMS5Oryc7cyf96LF5bQfExUo4y6o/tv6muYg0d9 NZAWc8OhkC3VREJ8fzBnp88vzCZLucIY2DQDGtpVd3qJZ/0r1UpqftHxjbme0PDKS0e8 5cd5aRAYrItmej7E6HEfE+FLuNBrLkPKS4K1+avHAp7F9YSuMlrqux/o/mcUpyGpq5yS BsJUjDuovW+SUoo0qqRBnfbmx6VD5a55gs7s8cIx4g1YLv/V5N4Y4m7LrlyPz48AWon0 zxdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729272667; x=1729877467; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EPaaeu37JE/wM6SvauUhRnxy0xWFM+VjQPTyakMCkTU=; b=wBtNJdC2K5qdeY5e+npovgIxyU5pPe2s5K1UovH0Z6pRZun9TXSrhucEC0Ibzt39zq 66ULGxaZQDGndCMFx6HmgALpSJR5siEN3y21vAcE3Sv5fcNIfDmIGhz30xYkYhQsvAMs mpBkBmv4ZeXqLD86CStSNcM/TTifmMJPEjbI6SMtEQffcZOpjPQSNyyf+mvxQHATpIJd D7oB+im9tmCTRkrhRIdTgnnz52OoxmjkIPrIiq6MFCwZ+CmXMam5MUX5y51VcvjBUmwF ceQaaszAynwr4GE2FQq+9JX4yg7DQCvR73oaYi4U1tgyehlgG/Y6bOwurxxdBC2fCknq JLbA== X-Forwarded-Encrypted: i=1; AJvYcCW0uHEqY32fT8DMNQuE+oA/PsLqDOqIL7Tlw/g+YadFrjE48Vrhyj2wK4JiUVxBpZTktGC9wUnIog==@kvack.org X-Gm-Message-State: AOJu0Yz3axZsA5iKRYwxPwZVI7JHB9tXpfO+KclgZzvJiT/deTUuR4dH NukdxzNQmw6askMhNL5Pyb2LGsgrqt6YxiffGEXssbrePFKy+yAp X-Google-Smtp-Source: AGHT+IEEe+ByOf1Adz9XWU2Tes8g7tZEwmexWC38hJ63m0WcdhEx6XCci2ar7YRCIZhlcwi/ce3HQw== X-Received: by 2002:a05:6a00:2d25:b0:71e:5950:97d2 with SMTP id d2e1a72fcca58-71ea3328e08mr4294187b3a.17.1729272666771; Fri, 18 Oct 2024 10:31:06 -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.31.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 10:31:05 -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 09/12] book3s64/hash: Add kfence functionality Date: Fri, 18 Oct 2024 22:59:50 +0530 Message-ID: <5c2b61941b344077a2b8654dab46efa0322af3af.1729271995.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: tgpqi3eati941iosbcgeh4wjx79tweiy X-Rspamd-Queue-Id: B055C80013 X-Rspamd-Server: rspam02 X-HE-Tag: 1729272646-2940 X-HE-Meta: U2FsdGVkX1/Kxt7JIrZUsWk9SofasOrY32aHWCsVsD/S38qc0vQvJd4TX77lUV0HfXexTorCVoSwHYw1P1aiXEFsesFACoZ+I90qT3Qu2kotGMJZAFR6FkBBVsD7LVt9nC3KzuGGylJ7iKNVih7Gz60fK61ix0uZ+hBLKZdDu/80tJETep7eCnx60SeRFi795qV19S9JzTi5xPvohkt6w5TamP9SWNzSamlIgOBcRTu8dFUXOFttWOTpuXCBjjChT8FV4YjqMJuEOpVrT+Z7W3noOnSDUJLPOcktI9e/ERxAkHaZTeh0IHnT4MmsUSFlQ2mvVU4Rlv08XNaRS2xjIxnJadMhuc7OZA5eNq14N44aqVahNNRctSBEoTqkdBekFEFeZifJ9vc7Rnr5yQi1z6/Lum5TEE/e7TBM4L2h/TfpCbr2++0B/BB15gQ0lTMxH28alDRAGWZtyPrB+NEXY8THvV50Tqcx2zn9oaAHOEkfb4ut8QQrBj9FQtOuaECS+jF2NGUeOlDcIrSZ5PkuzZAiIo7fzQJmJ/NvITFDbgt1yjUOCzcVPNYfBDQJQyVKa/54cwU3wqBiV7CSrnGPk+4FifvJLSduwCnbuXRiW4ZnA8gH0bL/8i/Kn7fQT0Sn/Bj5CpKYQw2Y29zASo2CQ/izSBkEGV3AoZEaVa3AK16XvmBMgaOpVa68mce9pr24/iWwoOdzmvpARUHIcuoDUn5NvJHPcaAb4r9QcYzfGl9HeKZbespsddkmy7UxdbKFZzCu7DX3BNajnrbmi/bDJTIV76puCjuSDVZVQiSgw1CW6BXWoIxj0OSddwzBEICJi5Sgr9mhOYqVyYRFiwMpeZ9aIZUw70dgzzdkyk5TRtJtaMOKh/HgOQRWzKOmk5TwoLrL6axxoOs5YixhbPsDCq0QsMWkwzkZnBKxEmJ3pC0H/GvwXG9hGEfqcRijYjTcFHWLGDu1UN4+2bmY3zi mCHFqg5b nKNHFilidgizjX+jtUf7SxYKBC2TB931Rj7ZW6nDaBHrfpAsU/8Zp4810eAM4e5cQ+qtdhkbNyymhsqyNV7M5PJsyezvODaXPyUIQsTkmljhNBPeOAZQBjiM1qdQ6pzorxOVtZfPcXeEcCls2WtBf6S8gceM+t/MpKy46g6cG5mRTawZlG/ue3o1rHQ8e6mdgqkkWiOLnISP66g07WC4ejeeGD+aH5OlSL+tDj83oazO0bIyOKHAxBxLoXzHyY44lkpjOiENuzbO7pKP5+2k9j4bSLKd4KOWrbVKS 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: Now that linear map functionality of debug_pagealloc is made generic, enable kfence to use this generic infrastructure. 1. Define kfence related linear map variables. - u8 *linear_map_kf_hash_slots; - unsigned long linear_map_kf_hash_count; - DEFINE_RAW_SPINLOCK(linear_map_kf_hash_lock); 2. The linear map size allocated in RMA region is quite small (KFENCE_POOL_SIZE >> PAGE_SHIFT) which is 512 bytes by default. 3. kfence pool memory is reserved using memblock_phys_alloc() which has can come from anywhere. (default 255 objects => ((1+255) * 2) << PAGE_SHIFT = 32MB) 4. The hash slot information for kfence memory gets added in linear map in hash_linear_map_add_slot() (which also adds for debug_pagealloc). Reported-by: Pavithra Prakash Signed-off-by: Ritesh Harjani (IBM) --- arch/powerpc/include/asm/kfence.h | 5 - arch/powerpc/mm/book3s64/hash_utils.c | 162 +++++++++++++++++++++++--- 2 files changed, 149 insertions(+), 18 deletions(-) diff --git a/arch/powerpc/include/asm/kfence.h b/arch/powerpc/include/asm/kfence.h index f3a9476a71b3..fab124ada1c7 100644 --- a/arch/powerpc/include/asm/kfence.h +++ b/arch/powerpc/include/asm/kfence.h @@ -10,7 +10,6 @@ #include #include -#include #ifdef CONFIG_PPC64_ELF_ABI_V1 #define ARCH_FUNC_PREFIX "." @@ -26,10 +25,6 @@ static inline void disable_kfence(void) static inline bool arch_kfence_init_pool(void) { -#ifdef CONFIG_PPC64 - if (!radix_enabled()) - return false; -#endif return !kfence_disabled; } #endif diff --git a/arch/powerpc/mm/book3s64/hash_utils.c b/arch/powerpc/mm/book3s64/hash_utils.c index f51f2cd9bf22..558d6f5202b9 100644 --- a/arch/powerpc/mm/book3s64/hash_utils.c +++ b/arch/powerpc/mm/book3s64/hash_utils.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -66,6 +67,7 @@ #include #include #include +#include #include @@ -271,7 +273,7 @@ void hash__tlbiel_all(unsigned int action) WARN(1, "%s called on pre-POWER7 CPU\n", __func__); } -#ifdef CONFIG_DEBUG_PAGEALLOC +#if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KFENCE) static void kernel_map_linear_page(unsigned long vaddr, unsigned long idx, u8 *slots, raw_spinlock_t *lock) { @@ -325,11 +327,13 @@ static void kernel_unmap_linear_page(unsigned long vaddr, unsigned long idx, mmu_linear_psize, mmu_kernel_ssize, 0); } +#endif +#ifdef CONFIG_DEBUG_PAGEALLOC static u8 *linear_map_hash_slots; static unsigned long linear_map_hash_count; static DEFINE_RAW_SPINLOCK(linear_map_hash_lock); -static inline void hash_debug_pagealloc_alloc_slots(void) +static void hash_debug_pagealloc_alloc_slots(void) { unsigned long max_hash_count = ppc64_rma_size / 4; @@ -352,7 +356,8 @@ static inline void hash_debug_pagealloc_alloc_slots(void) __func__, linear_map_hash_count, &ppc64_rma_size); } -static inline void hash_debug_pagealloc_add_slot(phys_addr_t paddr, int slot) +static inline void hash_debug_pagealloc_add_slot(phys_addr_t paddr, + int slot) { if (!debug_pagealloc_enabled() || !linear_map_hash_count) return; @@ -386,20 +391,148 @@ static int hash_debug_pagealloc_map_pages(struct page *page, int numpages, return 0; } -int hash__kernel_map_pages(struct page *page, int numpages, int enable) +#else /* CONFIG_DEBUG_PAGEALLOC */ +static inline void hash_debug_pagealloc_alloc_slots(void) {} +static inline void hash_debug_pagealloc_add_slot(phys_addr_t paddr, int slot) {} +static int __maybe_unused +hash_debug_pagealloc_map_pages(struct page *page, int numpages, int enable) { - return hash_debug_pagealloc_map_pages(page, numpages, enable); + return 0; } +#endif /* CONFIG_DEBUG_PAGEALLOC */ -#else /* CONFIG_DEBUG_PAGEALLOC */ -int hash__kernel_map_pages(struct page *page, int numpages, - int enable) +#ifdef CONFIG_KFENCE +static u8 *linear_map_kf_hash_slots; +static unsigned long linear_map_kf_hash_count; +static DEFINE_RAW_SPINLOCK(linear_map_kf_hash_lock); + +static phys_addr_t kfence_pool; + +static inline void hash_kfence_alloc_pool(void) +{ + + /* allocate linear map for kfence within RMA region */ + linear_map_kf_hash_count = KFENCE_POOL_SIZE >> PAGE_SHIFT; + linear_map_kf_hash_slots = memblock_alloc_try_nid( + linear_map_kf_hash_count, 1, + MEMBLOCK_LOW_LIMIT, ppc64_rma_size, + NUMA_NO_NODE); + if (!linear_map_kf_hash_slots) { + pr_err("%s: memblock for linear map (%lu) failed\n", __func__, + linear_map_kf_hash_count); + goto err; + } + + /* allocate kfence pool early */ + kfence_pool = memblock_phys_alloc_range(KFENCE_POOL_SIZE, PAGE_SIZE, + MEMBLOCK_LOW_LIMIT, MEMBLOCK_ALLOC_ANYWHERE); + if (!kfence_pool) { + pr_err("%s: memblock for kfence pool (%lu) failed\n", __func__, + KFENCE_POOL_SIZE); + memblock_free(linear_map_kf_hash_slots, + linear_map_kf_hash_count); + linear_map_kf_hash_count = 0; + goto err; + } + memblock_mark_nomap(kfence_pool, KFENCE_POOL_SIZE); + + return; +err: + pr_info("Disabling kfence\n"); + disable_kfence(); +} + +static inline void hash_kfence_map_pool(void) +{ + unsigned long kfence_pool_start, kfence_pool_end; + unsigned long prot = pgprot_val(PAGE_KERNEL); + + if (!kfence_pool) + return; + + kfence_pool_start = (unsigned long) __va(kfence_pool); + kfence_pool_end = kfence_pool_start + KFENCE_POOL_SIZE; + __kfence_pool = (char *) kfence_pool_start; + BUG_ON(htab_bolt_mapping(kfence_pool_start, kfence_pool_end, + kfence_pool, prot, mmu_linear_psize, + mmu_kernel_ssize)); + memblock_clear_nomap(kfence_pool, KFENCE_POOL_SIZE); +} + +static inline void hash_kfence_add_slot(phys_addr_t paddr, int slot) { + unsigned long vaddr = (unsigned long) __va(paddr); + unsigned long lmi = (vaddr - (unsigned long)__kfence_pool) + >> PAGE_SHIFT; + + if (!kfence_pool) + return; + BUG_ON(!is_kfence_address((void *)vaddr)); + BUG_ON(lmi >= linear_map_kf_hash_count); + linear_map_kf_hash_slots[lmi] = slot | 0x80; +} + +static int hash_kfence_map_pages(struct page *page, int numpages, int enable) +{ + unsigned long flags, vaddr, lmi; + int i; + + WARN_ON_ONCE(!linear_map_kf_hash_count); + local_irq_save(flags); + for (i = 0; i < numpages; i++, page++) { + vaddr = (unsigned long)page_address(page); + lmi = (vaddr - (unsigned long)__kfence_pool) >> PAGE_SHIFT; + + /* Ideally this should never happen */ + if (lmi >= linear_map_kf_hash_count) { + WARN_ON_ONCE(1); + continue; + } + + if (enable) + kernel_map_linear_page(vaddr, lmi, + linear_map_kf_hash_slots, + &linear_map_kf_hash_lock); + else + kernel_unmap_linear_page(vaddr, lmi, + linear_map_kf_hash_slots, + &linear_map_kf_hash_lock); + } + local_irq_restore(flags); return 0; } -static inline void hash_debug_pagealloc_alloc_slots(void) {} -static inline void hash_debug_pagealloc_add_slot(phys_addr_t paddr, int slot) {} -#endif /* CONFIG_DEBUG_PAGEALLOC */ +#else +static inline void hash_kfence_alloc_pool(void) {} +static inline void hash_kfence_map_pool(void) {} +static inline void hash_kfence_add_slot(phys_addr_t paddr, int slot) {} +static int __maybe_unused +hash_kfence_map_pages(struct page *page, int numpages, int enable) +{ + return 0; +} +#endif + +#if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_KFENCE) +int hash__kernel_map_pages(struct page *page, int numpages, int enable) +{ + void *vaddr = page_address(page); + + if (is_kfence_address(vaddr)) + return hash_kfence_map_pages(page, numpages, enable); + else + return hash_debug_pagealloc_map_pages(page, numpages, enable); +} + +static void hash_linear_map_add_slot(phys_addr_t paddr, int slot) +{ + if (is_kfence_address(__va(paddr))) + hash_kfence_add_slot(paddr, slot); + else + hash_debug_pagealloc_add_slot(paddr, slot); +} +#else +static void hash_linear_map_add_slot(phys_addr_t paddr, int slot) {} +#endif /* * 'R' and 'C' update notes: @@ -559,7 +692,8 @@ int htab_bolt_mapping(unsigned long vstart, unsigned long vend, break; cond_resched(); - hash_debug_pagealloc_add_slot(paddr, ret); + /* add slot info in debug_pagealloc / kfence linear map */ + hash_linear_map_add_slot(paddr, ret); } return ret < 0 ? ret : 0; } @@ -940,7 +1074,7 @@ static void __init htab_init_page_sizes(void) bool aligned = true; init_hpte_page_sizes(); - if (!debug_pagealloc_enabled()) { + if (!debug_pagealloc_enabled_or_kfence()) { /* * Pick a size for the linear mapping. Currently, we only * support 16M, 1M and 4K which is the default @@ -1261,6 +1395,7 @@ static void __init htab_initialize(void) prot = pgprot_val(PAGE_KERNEL); hash_debug_pagealloc_alloc_slots(); + hash_kfence_alloc_pool(); /* create bolted the linear mapping in the hash table */ for_each_mem_range(i, &base, &end) { size = end - base; @@ -1277,6 +1412,7 @@ static void __init htab_initialize(void) BUG_ON(htab_bolt_mapping(base, base + size, __pa(base), prot, mmu_linear_psize, mmu_kernel_ssize)); } + hash_kfence_map_pool(); memblock_set_current_limit(MEMBLOCK_ALLOC_ANYWHERE); /* From patchwork Fri Oct 18 17:29:51 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: 13842092 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 8C08CD3DEA0 for ; Fri, 18 Oct 2024 17:31:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 17F806B00A7; Fri, 18 Oct 2024 13:31:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 131466B00A8; Fri, 18 Oct 2024 13:31:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F110D6B00A9; Fri, 18 Oct 2024 13:31:15 -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 CB5FD6B00A7 for ; Fri, 18 Oct 2024 13:31:15 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 1E925A08D8 for ; Fri, 18 Oct 2024 17:30:53 +0000 (UTC) X-FDA: 82687413648.08.6FAB082 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by imf03.hostedemail.com (Postfix) with ESMTP id 3565F20014 for ; Fri, 18 Oct 2024 17:31:08 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ZeQMro5J; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.176 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729272512; 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:in-reply-to:references:references:dkim-signature; bh=maqsHecWoRrqy0atrv0EioRwOZB99TyG0W2HP4lfnAU=; b=NjhgmZaCRMIYEe7lWAG2WPTF3CU3H+SU9+Wvpji3vXsMV2F6ShoYTBmaaJBo0xWa284hBb b0RSmNiXRE5yPNfqxxTVybPz+yrXLIHgsQwwXJDGOZRzwS+znGkLqayuko+0RkclvqwiK/ 7DlNmXAbzJUrM6WJY827/21kwO5MHVg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729272512; a=rsa-sha256; cv=none; b=tk6GJKUMD83ZMF6Urs//KIMZLDXTcJwIonwN7LyB5jtcSb71T1vfMr19vDyTLDFyCkuDnw bVjnfH7JHPb2t73qRxPCU2yW7ET+vrjLlq0YhlydCVsVufJIUCwvz8ZfgoWOeXTjh2DFTN jRK6aRfNN0CO0tGd6ZBjIlWf2opD8Nk= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ZeQMro5J; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.176 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-71e7086c231so1828704b3a.0 for ; Fri, 18 Oct 2024 10:31:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729272672; x=1729877472; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=maqsHecWoRrqy0atrv0EioRwOZB99TyG0W2HP4lfnAU=; b=ZeQMro5J8hstSYDafwns0kvxSg7pFaxUoh7pZYd5e/OcYZ8kDjhs64pmdOFqr7LHNI lj09R0Xe+2oGe/9LCeYAfXhOrSglnqMfWlMnpbQ07ht4gHWhdf//X6IHpb8hPdd/J7yj 5KQDp0BjLhmYvwSlwUA6PxsB2G47AcPgGoT1uy0+CU/VvjzbPipcYrsh2Ge6rLLBcfbB IveuvF3n/OuvhjZz6Tw3rtmjfmvCuHzttbKIFXUk6ueHcDkLMR7Q801sJHSA9/cVqRKV tV7tbjLXJkR748I4zOgUue5HL3Z4fyoLgc17yjK2Va9ty/mQqLC5GF43vNNsVn9prw8U STGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729272672; x=1729877472; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=maqsHecWoRrqy0atrv0EioRwOZB99TyG0W2HP4lfnAU=; b=NvLG8h3QnsoPPXuzJgh6PkS9GIFSPQ1n/nVUIFB13iX9XUp7mA0i9Gt0F4SOIOlYKq V/fYW0GL4aOQA99lvtC9oNkN21e1qNF5d+X3t+sSaAXhyAl89wY61V058tc/RSk3bwRm MovPx3OLlGlCVUTdjDCk08HBVR4iDPFa9u3yCuEHAyPmek8SzBxvBZnN6KLMJrgZ9nva kulzDhVjK1L50EHUWODh2HVXdXpMyT2Y160ehGsYtZvn8ZAX7545tewvzV8vnk2yUtIV oRAc7R+LCvLIXJqNOpD5zVbrAm7GgyYj1byE3mMduZ6YVomm90bU/ttVXeog2rJvbu2P 6nXw== X-Forwarded-Encrypted: i=1; AJvYcCUqo8z6W3pdmXst1VXYAFsu7LLB9Ro2xPHoGxbk54y7GLi+GHDDDeuTx3HeDuqb1xoHx4LN5cll3g==@kvack.org X-Gm-Message-State: AOJu0Yy21S4apUNWlTLz7KUWN6e1za2pEZ+foK68dW7UMf4pWysBMKRD QcCqRvBqmmd+R7S7HE2+qz8Kvmi8wMB4DRoZKp85BepAafPmnwqI X-Google-Smtp-Source: AGHT+IGCcfcvV3hhkWCRVZ4L4+07qgofxPBOFcgBhHnT233XbATfjI7cFHkLMcuk8gJsatcgaCUiZQ== X-Received: by 2002:a05:6a20:43a0:b0:1d9:a90:8879 with SMTP id adf61e73a8af0-1d92c502994mr4770966637.21.1729272672394; Fri, 18 Oct 2024 10:31:12 -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.31.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 10:31:11 -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 10/12] book3s64/radix: Refactoring common kfence related functions Date: Fri, 18 Oct 2024 22:59:51 +0530 Message-ID: X-Mailer: git-send-email 2.46.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 3565F20014 X-Stat-Signature: q8di3tusfbotcbusytfb4x9szs8eotmf X-Rspam-User: X-HE-Tag: 1729272668-292308 X-HE-Meta: U2FsdGVkX18Rq/Y8ihXfEbfjSQeOdAu14ioHDyxct5EeyvgU0GSpSzx2XgQ8npJQwKZ9T+dxDdB5c30nDUDbG5WWGuSjj8/lXJGNS7n7DRkaQXtGtu5xsHX6QuFZIYFXDqklSfnD8ZvYgGpg/Mc9XNMvkp289u067elxr+7MEgKXaSDF1lcNNlrfvmYKhJ1pN/A4s8DZ7MKDaw6EhWuJkfPTtFoPxKF3tJjwgBqrGQ1nlk/LjO83vZwqvTw0R2fvyKOH0pgj5GcZDKG8K+p5z5naxPJNtqhSocadqrUjZqKA9/tgiTCpA16oMGuA0aCuPGlgQJBGcVbRcHf1VX5evFmeQAlLZwB8onmzPiCEahUVU9UFGvOzYygPPbKz2Gg+KImDdnWswQ/UfOuZJ52OCH0PM5DTBsgraL/+teo7+jo95gjhI0U+TReX9xNxezBTw1kDvFsHDxTtixcbS/wRbqLxo/w06mXSrnuey+Jx+1fBqUK+HOOV9TeHG2gF5Tndx86FWMP/fKT/Wu1MHN8QwkwMaPCWll41Xz3GRFs28sRe/l6hqJDEacKxuQllhZfLxU4Mw3naMLD+y+IjjGFsmLFlCisw4qFP5PmOaqFwISaJqZWCZlXT0eicLDXSuYffSwBS0gtMmchrauxw4aCdjAlj/VfADQOjAFgn6KzzkLtZDZiTYXu5NhPJJQhVSCoQwflShRPAfnhO/P0xK9yw3bysh8+JXFT6nilXSKB46o4M9qHEx+xCaDkrrFdceIGhbvU5MrZIUXZpmFZ5uWpwQqA9RT7mKdTHxiiTnxn4nakh08Fb3EYhP5I0bOeJwCYJj3yDpPCIsJgiJey2n+k7g3E7aioH8rk4vy6rKfZ2Zi9euAnXeuBd7PWHlxtqoHvn0SgkOFR+2nVwN1dlW13Ro54kULKNHLkFGUVWeMIyEdvdqPr8CVeSrHLtdJ0vWW6Feq2DppjQQsPlBspaapq P2Dx0ew5 kIQuDgYbANKBMx88rAIuZ9AZs7dy9sq9IZq7vJbvpXjV2L5TFheBqe+aKjBntIGiTCrZ+JjyOLXcoJ7nCH8fR6dar09YBY99mYfkH4ZCDUhd/93D+Y3ek+dxLWNdKQPsNMYQw8ZJQZzEvpCOiYZcfipb2n9ykUuSgXu2s10nDj647y5cjhwcCyuNnyNmScZSJWM+a0IJKBsoVH1Z4/tLatJHDEhUehqSBWYn334YOmOrOlDnqpMcRZncBSjdz7aI07bjMo+WhpTMHDJnKLJ/qSpYMK/gImePISh8l 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: Both radix and hash on book3s requires to detect if kfence early init is enabled or not. Hash needs to disable kfence if early init is not enabled because with kfence the linear map is mapped using PAGE_SIZE rather than 16M mapping. We don't support multiple page sizes for slb entry used for kernel linear map in book3s64. This patch refactors out the common functions required to detect kfence early init is enabled or not. Signed-off-by: Ritesh Harjani (IBM) --- arch/powerpc/include/asm/kfence.h | 8 ++++++-- arch/powerpc/mm/book3s64/pgtable.c | 13 +++++++++++++ arch/powerpc/mm/book3s64/radix_pgtable.c | 12 ------------ arch/powerpc/mm/init-common.c | 1 + 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/arch/powerpc/include/asm/kfence.h b/arch/powerpc/include/asm/kfence.h index fab124ada1c7..1f7cab58ab2c 100644 --- a/arch/powerpc/include/asm/kfence.h +++ b/arch/powerpc/include/asm/kfence.h @@ -15,7 +15,7 @@ #define ARCH_FUNC_PREFIX "." #endif -#ifdef CONFIG_KFENCE +extern bool kfence_early_init; extern bool kfence_disabled; static inline void disable_kfence(void) @@ -27,7 +27,11 @@ static inline bool arch_kfence_init_pool(void) { return !kfence_disabled; } -#endif + +static inline bool kfence_early_init_enabled(void) +{ + return IS_ENABLED(CONFIG_KFENCE) && kfence_early_init; +} #ifdef CONFIG_PPC64 static inline bool kfence_protect_page(unsigned long addr, bool protect) diff --git a/arch/powerpc/mm/book3s64/pgtable.c b/arch/powerpc/mm/book3s64/pgtable.c index f4d8d3c40e5c..1563a8c28feb 100644 --- a/arch/powerpc/mm/book3s64/pgtable.c +++ b/arch/powerpc/mm/book3s64/pgtable.c @@ -37,6 +37,19 @@ EXPORT_SYMBOL(__pmd_frag_nr); unsigned long __pmd_frag_size_shift; EXPORT_SYMBOL(__pmd_frag_size_shift); +#ifdef CONFIG_KFENCE +extern bool kfence_early_init; +static int __init parse_kfence_early_init(char *arg) +{ + int val; + + if (get_option(&arg, &val)) + kfence_early_init = !!val; + return 0; +} +early_param("kfence.sample_interval", parse_kfence_early_init); +#endif + #ifdef CONFIG_TRANSPARENT_HUGEPAGE /* * This is called when relaxing access to a hugepage. It's also called in the page diff --git a/arch/powerpc/mm/book3s64/radix_pgtable.c b/arch/powerpc/mm/book3s64/radix_pgtable.c index b0d927009af8..311e2112d782 100644 --- a/arch/powerpc/mm/book3s64/radix_pgtable.c +++ b/arch/powerpc/mm/book3s64/radix_pgtable.c @@ -363,18 +363,6 @@ static int __meminit create_physical_mapping(unsigned long start, } #ifdef CONFIG_KFENCE -static bool __ro_after_init kfence_early_init = !!CONFIG_KFENCE_SAMPLE_INTERVAL; - -static int __init parse_kfence_early_init(char *arg) -{ - int val; - - if (get_option(&arg, &val)) - kfence_early_init = !!val; - return 0; -} -early_param("kfence.sample_interval", parse_kfence_early_init); - static inline phys_addr_t alloc_kfence_pool(void) { phys_addr_t kfence_pool; diff --git a/arch/powerpc/mm/init-common.c b/arch/powerpc/mm/init-common.c index 2978fcbe307e..745097554bea 100644 --- a/arch/powerpc/mm/init-common.c +++ b/arch/powerpc/mm/init-common.c @@ -33,6 +33,7 @@ bool disable_kuep = !IS_ENABLED(CONFIG_PPC_KUEP); bool disable_kuap = !IS_ENABLED(CONFIG_PPC_KUAP); #ifdef CONFIG_KFENCE bool __ro_after_init kfence_disabled; +bool __ro_after_init kfence_early_init = !!CONFIG_KFENCE_SAMPLE_INTERVAL; #endif static int __init parse_nosmep(char *p) From patchwork Fri Oct 18 17:29:52 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: 13842093 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 ECFD0D3DEA2 for ; Fri, 18 Oct 2024 17:31:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7BECB6B00A9; Fri, 18 Oct 2024 13:31:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 76F0D6B00AA; Fri, 18 Oct 2024 13:31:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 611BA6B00AB; Fri, 18 Oct 2024 13:31:20 -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 40BD26B00A9 for ; Fri, 18 Oct 2024 13:31:20 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 15FFD1A1A35 for ; Fri, 18 Oct 2024 17:30:58 +0000 (UTC) X-FDA: 82687414194.28.B5F3B88 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf23.hostedemail.com (Postfix) with ESMTP id 01567140023 for ; Fri, 18 Oct 2024 17:31:10 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=NaLB6kRR; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729272558; a=rsa-sha256; cv=none; b=nPkFZ0FNl21GCAutIFeaMi6tAdw5DdNiffCuHpp0Mb7nd5vh5sKL7LVsLjfziwmCYRLQ+4 cVZuHMegbFLnJujDhAaFJawM5sdzVIUE1XTp2qdtBgUxvU11pn0svcqFM4CYV6sXmMGGBP ot0JPjLhWH7x/QxqzK9/YngbNkYtPDk= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=NaLB6kRR; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=ritesh.list@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729272558; 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:in-reply-to:references:references:dkim-signature; bh=M+pQKseSbUwQ7nDgMGbwYxJsHyJez2ZBxycyN9iER7I=; b=NtIEncPbO/fUo6+fnUEFCgMY8O9oPP/KglnsnPg8dkgpSdgTMhb6KJCEJVyJRJ/6Uq5b7Z bg4rIDNWjx3UDlSysmBDrfv417WwzURiCdGveBp7VdYonW/j/A+vzzHmC8FSkaQeYlLkq7 Uc4Kl/ElN7sp21gb6YPY74ttCA4vNGM= Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-71e4244fdc6so1726152b3a.0 for ; Fri, 18 Oct 2024 10:31:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729272677; x=1729877477; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=M+pQKseSbUwQ7nDgMGbwYxJsHyJez2ZBxycyN9iER7I=; b=NaLB6kRRBWfyAxaqZo0lCJnVZ/aDsb3aoPoglE795lyhEfLlCuKEi/w5Jy9ldm9UJc mUPOnr+nmQLCTuOAzp+wLbuMF9K9SLO5AQKoOVC3E+hlVHXCDcIkbEaqbkBgy6sD/eeC 7aEn7hIBx3bfGBgfltRnlAONrvTVVxINLLV6gcr9ilryxK3oEcEKYAWKjZ0As8nRLluy Zz1LeslSP/H0V7A49DKwRI1UzcnHQkRV+IxkB48MYHbMQZvRvyoXEnNHMTRqRhfUnLOP WKL7sgjSr98KBiPfWvQHfRb9bQlsZjXGJ8S036RiboEBgR5f3GFZePc/bmuBN5a22gWB 7ttw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729272677; x=1729877477; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=M+pQKseSbUwQ7nDgMGbwYxJsHyJez2ZBxycyN9iER7I=; b=mCEaukB5K3G7gwIhJJ9egOp0r4dzlHbzcx2hxO1NvU53A5X4a82aLkJlCdU8mzvGku sJukZXNNGKIWKHN4gn9QJmBUFk+FuqzLuzNIfuTdqY2Ad714LJ88TtwjRYuOvQ4naCdi r0swS1dPCfGkr93Uawf629wxDyGTBbK7dfX35T8EXp1hOZBzyQGyEvGU8BSUK1BMCBB4 98pfYIAO4KM2Sax8H0nTwrkzukwl/KtdOXQICkkJ66vx8A4K1ymMZ3RRa+P3FN1GGp03 K6Eeb+w2JE861z9qXlnrEhYxjrUaarXYGXPqdoS9GNQuhkBK17eifqBlRVSq7amm3mtI CCog== X-Forwarded-Encrypted: i=1; AJvYcCVUYvDSZPCBZLJUfzf0K5W+AG8NsGughSDpTwV0x53TWOW1QN0pa50ItA2xcKJyYLXxQMvb7ty3Lg==@kvack.org X-Gm-Message-State: AOJu0Yya/lFGuwwrsFmolFNUxF9CgIhIZwRfSOlyqFMUDJ417kxOTVIy 5iynv9JcnhnWAhC2R2ymd8uPhRkTr0QnHQKANyVecauEmRVsxKwX X-Google-Smtp-Source: AGHT+IFVWe1xUi/sLyBKrxUXKe/50HIPEi+N9laTmy/mjDBIPEDqbRrd1jNCsq8LdLHdy/KQ/lg9Ig== X-Received: by 2002:a05:6a21:168d:b0:1d9:61b:9607 with SMTP id adf61e73a8af0-1d92c4a0231mr4271987637.6.1729272677039; Fri, 18 Oct 2024 10:31:17 -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.31.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 10:31: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 11/12] book3s64/hash: Disable kfence if not early init Date: Fri, 18 Oct 2024 22:59:52 +0530 Message-ID: <4a6eea8cfd1cd28fccfae067026bff30cbec1d4b.1729271995.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 01567140023 X-Stat-Signature: 44fkiihebcyttes3zmpm5nrqumqu6bt5 X-Rspam-User: X-HE-Tag: 1729272670-157809 X-HE-Meta: U2FsdGVkX19Bgdxt0yWCtU2w9f9S76prDaH+SLzqHmuRqIWuBNGMcbAr2QouEES/R5c/qEP3eyyMvYegcVMMSlYE50fg+GPjprZFcpQpNapvXxfKJ1AYqTrzCK/Hq24e8JskRd2aoRYqEkmoB7mezeenr6iQsgfh7SRxKS59A1LBGysjCbxI0t39tBGnpVPe39V0TMm+IPRZHdXkBrvMZXrQlcSonKYl8jTAQZzwv7SoPsP03hAVESqmm24WU4eRpM38qE66AeQCF95/8JZPu60QS3zLRAIlIyG2bLmiBEkObThLMSQ6D0R/HBxxzoqR77I0Tn5s82DowKgimCJAgZzlvM4JOspJz7mRevG1qQANea3n8/XOFznt1SFk/35Yn5aOnpUW42Aw+fD13z932zQwKWO5vxnTfPycTp/lvXIypxtAxvLwz7nZoGG3zxrlhny2m5Bg2PTla3Zo2ZkSLWnEi9JnlkJICYT5dJxVH5O/nQVapTeHC9P80gimZlcLJW+f9aucQ9vj0NY++jjnoFgUNonJBrLng5QMlaA9jpVgMzuw9HjsnxGeUljGWUl1iu0gsszY4CVVu7hymQSuo1uT9xIQt8vpDUMXSbgpR/N2fBH6aNM19+JkzszjAXwsZQ69gYxM8GkH/1+s9HRjq0v+g1trW15+1z/uh5XmRqtpYHv3yskYIgmgO6Hkn1wn/ai15CsVuvMHox0uZfT5/bAARBcWF5tuYvFEU0M+Gp2PXJYPwvhFNiT+htA4KmAsbOepDgyl+lMEQkVFK3eE7adGxDIIESMwChId1tfbra8kl2+7DYwRVRZWZqzswVkSxbtR+3Gvod1yuQaxpnAzsyJv5M44XLP341y/S0pE24+XwJgD1Ep8nwbwjY/c9PPylaGwLPSEBQ4JHJv2V6dqb9Gn638rGyZ1dqzw78041csUqasZIEhD3rzvMZSqA2S3QHNKAutswIJYvDoTiTT 7xZ8NGlp ii3lMiWZLapRa10WDvA6XXIQq31D87CPmXDyJJ89BJxf7b0Hx/zkpmssLOlhxLiHo4my5bFeS0CpT9UPnommFisQFJ7kgkvoaELz3esTenn2eR59eSUofPClVG7IBmVlTTlSFMnJW5/JmWoxY2nMsgUiq2sGSKPf7iwY8LU20aF29fa2smnPOsrBGha1rNOlMRT1hSPy2fVJNIqC5sQPupRe2XKxsg3YuJ8ifBDzb9IUu/x0PsbaYes3+vgCTyoSou/YjWROF/rhlpQGFyMBrkP9V59c98GIozNBy 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: Enable kfence on book3s64 hash only when early init is enabled. This is because, kfence could cause the kernel linear map to be mapped at PAGE_SIZE level instead of 16M (which I guess we don't want). Also currently there is no way to - 1. Make multiple page size entries for the SLB used for kernel linear map. 2. No easy way of getting the hash slot details after the page table mapping for kernel linear setup. So even if kfence allocate the pool in late init, we won't be able to get the hash slot details in kfence linear map. Thus this patch disables kfence on hash if kfence early init is not enabled. Signed-off-by: Ritesh Harjani (IBM) --- arch/powerpc/mm/book3s64/hash_utils.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/mm/book3s64/hash_utils.c b/arch/powerpc/mm/book3s64/hash_utils.c index 558d6f5202b9..2f5dd6310a8f 100644 --- a/arch/powerpc/mm/book3s64/hash_utils.c +++ b/arch/powerpc/mm/book3s64/hash_utils.c @@ -410,6 +410,8 @@ static phys_addr_t kfence_pool; static inline void hash_kfence_alloc_pool(void) { + if (!kfence_early_init_enabled()) + goto err; /* allocate linear map for kfence within RMA region */ linear_map_kf_hash_count = KFENCE_POOL_SIZE >> PAGE_SHIFT; @@ -1074,7 +1076,7 @@ static void __init htab_init_page_sizes(void) bool aligned = true; init_hpte_page_sizes(); - if (!debug_pagealloc_enabled_or_kfence()) { + if (!debug_pagealloc_enabled() && !kfence_early_init_enabled()) { /* * Pick a size for the linear mapping. Currently, we only * support 16M, 1M and 4K which is the default From patchwork Fri Oct 18 17:29:53 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: 13842094 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 6C8BAD3DEA3 for ; Fri, 18 Oct 2024 17:31:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C53F06B00AB; Fri, 18 Oct 2024 13:31:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C03556B00AC; Fri, 18 Oct 2024 13:31:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A7D296B00AD; Fri, 18 Oct 2024 13:31:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 83ED06B00AB for ; Fri, 18 Oct 2024 13:31:25 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 27A80121B22 for ; Fri, 18 Oct 2024 17:31:14 +0000 (UTC) X-FDA: 82687414194.24.AC1D61A Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf27.hostedemail.com (Postfix) with ESMTP id 064784001B for ; Fri, 18 Oct 2024 17:31:11 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Ng6bUMdJ; spf=pass (imf27.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.179 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=1729272634; 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:in-reply-to:references:references:dkim-signature; bh=1QLaMyzhWv0h56bpJNLe2thoYBckgfAdM8HvqGdr41M=; b=2euNsQLtbm48+3IgNT/WHTF4y87F0S0ePscdlAzcybfLQ6K7tApm9vi6Ki9j4JMI3C1XzR DH46k6olN91NVz123JIFor+SakG/YkkPwx/QwHTd+tPXMCay+O9ihRVMLroIqb+8EC9B/8 RgTLq1xe4kT/6eEUyajlDNYveh7U+WI= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Ng6bUMdJ; spf=pass (imf27.hostedemail.com: domain of ritesh.list@gmail.com designates 209.85.210.179 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=1729272634; a=rsa-sha256; cv=none; b=KIyqJxbQbCq1pb+w9n9zRZlq0ntBMDFCm87pBmMKYSdLW/ebJ6SMbCFw6cM3qxvoWVySvD nZ1cgk+Ko/vj/gLuI1ZSqDIZIobL0SWvh/dDCojJErWK4oDRj0kWeR2AF4Ch/buSHuB02g UDdxLD8A7e2t7ANT5aYVFCCVQfHxm7c= Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-71eb1d0e3c2so29613b3a.2 for ; Fri, 18 Oct 2024 10:31:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729272682; x=1729877482; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1QLaMyzhWv0h56bpJNLe2thoYBckgfAdM8HvqGdr41M=; b=Ng6bUMdJ7scoPtOI2WxXMmDkNAxzyyJDDpnGj1GZTxsZ+mGwecfJgBQ+xs2m33EBay 6iBSx/jh96kfaT3caeXL6AQX6b17S7M/mpL1FsFCim+G9YhKHymQkktElkknaFWaYr16 N4F8z9PgtAOLHA5x7yv+edPn1jX39zCJ8VlFF/+1cSVIxgXGWfgKZK2nh1OorLET4PFE MQajy8wQPeMxvnYsPDEYvd4rhrYP5g6QOR/dUl5YYl7V24k9zEC24ESJQBnMrGq2SaxW 9kC9Xa5LPafT+Umdhg8tZaMJviOcy1YbHLzFFG8lHNcxmnkChtYMLBW5+XnTKWHCHBwM 7CBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729272682; x=1729877482; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1QLaMyzhWv0h56bpJNLe2thoYBckgfAdM8HvqGdr41M=; b=awvi8rvpjvsALxBcoB9v4HqZpALXFd1aP9jfbxc9yU7KAdGXPUZLmhB8mI1mFy4DGL eNjYjKw9pw/NlqrgvskZi6SdZOjSARfLGGJEan6HLWQglhjUNmUGH7hs3hn1I3ngG/cw JT+yVOGyTeeTq/VhErPKLnvfWH6Bj8jU11WZfcN34lcbIQlCYXTXfP0G8sBPC8o50m5f 2j+HB0tfCnzRa7E9xtIScyfuJnmTbn5fCCMEVp7k/9wjWcv0ll0E/P8t13r6HWINaduZ WUp+c2pyQmP5+wppJA+2s+ypUVD6xrFNlHCex+3C7kg5JI2VxBRZD917ZuzFgcAuZuQt ubRA== X-Forwarded-Encrypted: i=1; AJvYcCVNiyF9qfSOWi8bK+bdstfyDlD61hsOftc1cAkYQZ2Jb8uM5ThmpJfgkk9FLFI9SxmYnlwr0hKjSA==@kvack.org X-Gm-Message-State: AOJu0YyHh4mVeQ8NdSptt8HPF3zmBCJu6CDENyZLSvCI1GHNKH9nQibq Xdr5gwdDyv0o9d8m616JnE0Zg0WkZdW3S8r1gA+gxV24dcmlq1hskaNi5r3z X-Google-Smtp-Source: AGHT+IFTSMl8QW5ycN4XEBU+MJ3K9NfWvdEojOEp7QlJ+1fDl8flZ96NMrdY+IbWH9uWHYWgBiWu4A== X-Received: by 2002:a05:6a00:cd4:b0:71e:cf8:d6f1 with SMTP id d2e1a72fcca58-71ea316bf4emr3925702b3a.14.1729272682003; Fri, 18 Oct 2024 10:31:22 -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.31.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 10:31:21 -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 12/12] book3s64/hash: Early detect debug_pagealloc size requirement Date: Fri, 18 Oct 2024 22:59:53 +0530 Message-ID: X-Mailer: git-send-email 2.46.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: o43sb3hedidf384nhktq3q479tn378ey X-Rspamd-Queue-Id: 064784001B X-Rspamd-Server: rspam11 X-HE-Tag: 1729272671-251274 X-HE-Meta: U2FsdGVkX197JJFgEJZwYShuoDyjMqz5huWvHJeuR1S7dQSRKmqlO1W5GvQc6gunZrK5HJw2EPWVekvpQeXA3ahpCXDvP0rOLNtQsZ1vYgKlQ8ghj20Tp9UqK6/IThnAc9YhxvY5hKFWzBDKbM/nvZWgG9WiBTW4/M+VdZW0y0ZPMUIfQLjcu+T2fDc1iGI9dbY00hE2YcW4DQtCcEtWSXkiiMOe9lUGim2VtRyNgh4Ur9qvxzfsDJFzroi92j2hTh0VuLoJWjnfT+Ge6aB9DZ1HlIiqwUOXvsGDGoF/zcmmzQFyQMUJIVxAz4d0ZVLISR+EhY72IJbkcsOVDYjmjshdjsv8KxmUNwamypqh+OWJnN/IPczmrciR50+u4Yl7K1OfW5hRZ1Atk5xSbGRe7UKkjAkcAXvEPKxo9l2eoF4purjM4YJE3ZkIjU9el0+SY0Lu0fSwgol+4YhHdccHC2RdZPaoHZbc+osSvm43eg1FgDhIinR8u2VwxZyaX/+a3vNkYgbZ3SFyWKwtLWzowTymz287uCSv3BLIKmO/cJ/+npWlxLA7EnVqPFFUyrm4N8NMJUVaPPi6x391q7yqt9UZcn040ZY++1EGuYAV/3KWlnz7CwBKHJrw7SgOuiTAbcCJm8aM1GLHuF2J2xrrkm8XUwTKMYc2Mv/0r5Sj28jmrVCOurfTvNacJCQAMpButrd2ezSs3ilcYttj4xSPdDISaZiWxrjvn5TKBOCusM/Q7UwiNQNIUOGF9HDmBYayXFzW0hUU8nJYrhx5QGl6oCUTnWw6qkLIEOxU+TVVU8AyMqPhPn6esXBGWKLbOMCRXIKD6D3lnRl7EDyxfHTVQuVqCvlx6WjT+JYBDu2MsqZ5zYq+L3WF85QznnvwWBIa/GcqZ8Nv0EvUd5tKQrqfRPGixJ0VS45MfUfvvxgPBF6+/tuJZPk2m0fx6Z5rC13pKPK7AabzFZ1C75uy/mU 3lCsrxSt H64tIKF6/dRMCAjyAXnO1xUOeQjrzqF3rHbexCw4n5UjkPUBQ9Cdkrp6RA2ryRftVDnIlODlPKfBYQKen09X0uY+PIyzZ3q8T9D0RU8YtzSBEIZuCVQKdTQpTwS91VcousVSXduUTnnjId4EdoXfgx12G9LaGly6GW/zvzj/R4+ax23jkICYVhC2n9H3oea7ZPkCBY96P+dkWGRyxGbL4O96KO4PCCZLHPuGxDQgeolmgF/3ofbGEnCdaTOWwZOUlJHGA4Vllll3d+Q3ZCpUde37cgXa5JCxVhLccs9lCL+rnmdrPXVZgIoaiQfzN4NVEqmwsylts7TWjWhOln9FbQFZuxA== 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: Add hash_supports_debug_pagealloc() helper to detect whether debug_pagealloc can be supported on hash or not. This checks for both, whether debug_pagealloc config is enabled and the linear map should fit within rma_size/4 region size. This can then be used early during htab_init_page_sizes() to decide linear map pagesize if hash supports either debug_pagealloc or kfence. Signed-off-by: Ritesh Harjani (IBM) --- arch/powerpc/mm/book3s64/hash_utils.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/arch/powerpc/mm/book3s64/hash_utils.c b/arch/powerpc/mm/book3s64/hash_utils.c index 2f5dd6310a8f..2674f763f5db 100644 --- a/arch/powerpc/mm/book3s64/hash_utils.c +++ b/arch/powerpc/mm/book3s64/hash_utils.c @@ -329,25 +329,26 @@ static void kernel_unmap_linear_page(unsigned long vaddr, unsigned long idx, } #endif +static inline bool hash_supports_debug_pagealloc(void) +{ + unsigned long max_hash_count = ppc64_rma_size / 4; + unsigned long linear_map_count = memblock_end_of_DRAM() >> PAGE_SHIFT; + + if (!debug_pagealloc_enabled() || linear_map_count > max_hash_count) + return false; + return true; +} + #ifdef CONFIG_DEBUG_PAGEALLOC static u8 *linear_map_hash_slots; static unsigned long linear_map_hash_count; static DEFINE_RAW_SPINLOCK(linear_map_hash_lock); static void hash_debug_pagealloc_alloc_slots(void) { - unsigned long max_hash_count = ppc64_rma_size / 4; - - if (!debug_pagealloc_enabled()) - return; - linear_map_hash_count = memblock_end_of_DRAM() >> PAGE_SHIFT; - if (unlikely(linear_map_hash_count > max_hash_count)) { - pr_info("linear map size (%llu) greater than 4 times RMA region (%llu). Disabling debug_pagealloc\n", - ((u64)linear_map_hash_count << PAGE_SHIFT), - ppc64_rma_size); - linear_map_hash_count = 0; + if (!hash_supports_debug_pagealloc()) return; - } + linear_map_hash_count = memblock_end_of_DRAM() >> PAGE_SHIFT; linear_map_hash_slots = memblock_alloc_try_nid( linear_map_hash_count, 1, MEMBLOCK_LOW_LIMIT, ppc64_rma_size, NUMA_NO_NODE); @@ -1076,7 +1077,7 @@ static void __init htab_init_page_sizes(void) bool aligned = true; init_hpte_page_sizes(); - if (!debug_pagealloc_enabled() && !kfence_early_init_enabled()) { + if (!hash_supports_debug_pagealloc() && !kfence_early_init_enabled()) { /* * Pick a size for the linear mapping. Currently, we only * support 16M, 1M and 4K which is the default