From nobody Wed Nov 27 00:31:34 2024 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9454915B115 for ; Tue, 15 Oct 2024 01:33:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728956034; cv=none; b=q7C83HznSiXx1yKcE5gZCLzH0Os3VZ2hrZaj2KAlku4dv7vs4kfHqhnr5KQmYPI4KTfmt/Ya7CH9v7p7ZDJw/kdSj8RK2eIIVLrMkphqFYVP/6aORBXnqHymzrvUoO9eW+jCa+VBSz3wndBilMCmavxo+oqVDy1teo8aZS3xXgk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728956034; c=relaxed/simple; bh=QII9r4fc3119Wy1Fk5d28jwhD4LaT6craTteAVb6YM4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sSkF+8XKKJlfF6rPBP4IFk46x9MyjPi2bpWVECV36V8XmaI3saK5xDw8YSdNeTuobtiFrckV9v7nquxhARFeGvkOr//FB3i21RkspNeHBaXJ8s057egDZdUJ2KgdX46WmSsQNiAc4enhbYGN5YJ+j2utsRM2BpBEv3kt9A2Dv7M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=a1HQ6A54; arc=none smtp.client-ip=209.85.210.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="a1HQ6A54" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-71e483c83dbso2992392b3a.3 for ; Mon, 14 Oct 2024 18:33:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728956032; x=1729560832; darn=vger.kernel.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=L3z8aqN2PapGEchw6ngaiDWNeD417V3WkhQBwYXWFqM=; b=a1HQ6A54I/M1WHas+YuY5eWYYjMclIi//q4labA5I5vyV+qYSfpIWxNKwwn2xRd0Ev VzSQGVEBDMVynsqTK9+FUDS6SLVt3L96ALLQtDIGVi6viGs69wWXwHYUiI02LKq+gp/c DIKzf1ej3v2DdV1U49g1/P9nRRDzvJVRsPfHA4R/qfjrTr4LkkzJENNxjHswchEfrw31 b5USs5LhCd6EjDXrBbPVYoVVCRsg+X2GS+fPoT6wWMirc/HZkkAYrAT87W/8b+nm6XQ0 wl77/1R4RlBPi9t5VE6sEeXGV4s6D9hYh7O6nTpQzhxt9C4jNKjuPnCkPFXCFooUG1BN spVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728956032; x=1729560832; 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=L3z8aqN2PapGEchw6ngaiDWNeD417V3WkhQBwYXWFqM=; b=oaJ2oQFdONNZWkOXCQjtLJgPACwGdApnzxcY+qs135pTSUZm8FI+5CzXBlgCDnNMyY lHMLgx9NuIJ+G0YrSPdHqGudiUZTPGkTziYv+xxx+uXzwGjkfj9boVv0Uasi82has3VR 65S0GL4C3vmTIBVaM1nAnX4zIuJauv23p5d5IhRkg4WY6bqq5Jlhf6wIaiZBdN6NtIIG mLCNl8O+Dwh3b626BY9frLA8YC8HGckYi6zjRT6gthGhlXh65mYbYHfWqrsMikwjC7VL AOVLMpIbs+K0hiQ/Eru0AlXz/seXKoGfLMo8je0xp6wbiXP4yzudkuSf/zn7FhR5sR/9 EI7A== X-Forwarded-Encrypted: i=1; AJvYcCVsv14HYCqySzDUvoED8yb+kIrGa3zeq4Ub4R35DZO9pqIDIUZ7UIKVLt1qEpW2DgiloTbS1/HRtWgzI8s=@vger.kernel.org X-Gm-Message-State: AOJu0YzVpnn5xeS8O3T5urToG0q9HidTtMobFfYn6SYlwbgnjkmJE/HP BGqiqUKNUPttYj9ZpxtcxH9ga9liiUucWEXiiQyZQJ47JNMu6xrm X-Google-Smtp-Source: AGHT+IGqbk3XkcP38tM4YL865mfr8G0wKwLOrKwm5cB+ZAuXCK3oFNnJ20ByJ9R3zI+2HFTRH1ioYA== X-Received: by 2002:a05:6a00:9a1:b0:71d:f215:1d96 with SMTP id d2e1a72fcca58-71e37e287e7mr22675408b3a.6.1728956031701; Mon, 14 Oct 2024 18:33:51 -0700 (PDT) Received: from dw-tp.. ([171.76.80.151]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e77508562sm189349b3a.186.2024.10.14.18.33.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 18:33:51 -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 , Nirjhar Roy , "Ritesh Harjani (IBM)" Subject: [RFC RESEND v2 01/13] mm/kfence: Add a new kunit test test_use_after_free_read_nofault() Date: Tue, 15 Oct 2024 07:03:24 +0530 Message-ID: X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Nirjhar Roy Faults from copy_from_kernel_nofault() needs to be handled by fixup table and should not be handled by kfence. Otherwise while reading /proc/kcore which uses copy_from_kernel_nofault(), kfence can generate false negatives. This can happen when /proc/kcore ends up reading an unmapped address from kfence pool. Let's add a testcase to cover this case. Co-developed-by: Ritesh Harjani (IBM) Signed-off-by: Ritesh Harjani (IBM) Signed-off-by: Nirjhar Roy Cc: kasan-dev@googlegroups.com Cc: Alexander Potapenko Cc: linux-mm@kvack.org --- mm/kfence/kfence_test.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/mm/kfence/kfence_test.c b/mm/kfence/kfence_test.c index 00fd17285285..f65fb182466d 100644 --- a/mm/kfence/kfence_test.c +++ b/mm/kfence/kfence_test.c @@ -383,6 +383,22 @@ static void test_use_after_free_read(struct kunit *tes= t) KUNIT_EXPECT_TRUE(test, report_matches(&expect)); } =20 +static void test_use_after_free_read_nofault(struct kunit *test) +{ + const size_t size =3D 32; + char *addr; + char dst; + int ret; + + setup_test_cache(test, size, 0, NULL); + addr =3D test_alloc(test, size, GFP_KERNEL, ALLOCATE_ANY); + test_free(addr); + /* Use after free with *_nofault() */ + ret =3D copy_from_kernel_nofault(&dst, addr, 1); + KUNIT_EXPECT_EQ(test, ret, -EFAULT); + KUNIT_EXPECT_FALSE(test, report_available()); +} + static void test_double_free(struct kunit *test) { const size_t size =3D 32; @@ -780,6 +796,7 @@ static struct kunit_case kfence_test_cases[] =3D { KFENCE_KUNIT_CASE(test_out_of_bounds_read), KFENCE_KUNIT_CASE(test_out_of_bounds_write), KFENCE_KUNIT_CASE(test_use_after_free_read), + KFENCE_KUNIT_CASE(test_use_after_free_read_nofault), KFENCE_KUNIT_CASE(test_double_free), KFENCE_KUNIT_CASE(test_invalid_addr_free), KFENCE_KUNIT_CASE(test_corruption), --=20 2.46.0 From nobody Wed Nov 27 00:31:34 2024 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E57417BD3 for ; Tue, 15 Oct 2024 01:33:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728956039; cv=none; b=DXv+P917NLT6zGdViZgqa/vS3uWS9Dw3QZslZ8tp5j30vEE79jYDrIM9C380SlZGGARt0459l1UtHNfIOY4FmRDr7DeOOtnYXLT9RfH75ask9iriTJeP2vPFsrnRQzO2id9DNsoImDx46xsxM0bmQudVWE5sVRA7wJ3l1RILsdw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728956039; c=relaxed/simple; bh=m+dUswfxUsZy9prkRABXDXGfNap5/jDlWlqOFp9ZXy0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bqQFd6FquHClOiwO0tidMgVIJv4qSNY9kQ5HuehNuvpYllBx90HuFKDW5NPrtml+4pfx/bryZUyG17ttbKah7kd49KpQC6OJ01DtPY2GfBNJpLleYMGflWkVUwRXjLVyCSvilGrhPS3blzbOV7wZLT/w1GHkpx/L9nE+x499TV8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IUQ3kosK; arc=none smtp.client-ip=209.85.210.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IUQ3kosK" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-71e5a62031aso1363623b3a.1 for ; Mon, 14 Oct 2024 18:33:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728956037; x=1729560837; darn=vger.kernel.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=2IOurK7ENej5lHHiP4d73lr8yQG82cdevQPBO00m0fo=; b=IUQ3kosKkRAn6d183mRmnWCkm4kdP6CEvBXVLJsmwjka5Wo0Cmxl3qyktnUuiUDTpJ 2kXsag9TD2B6DFJ58IyOQHcQsI3Pn28qnjK6a1qwugIWoWbdkZU3GGpGHzNHspUG0tf6 sBXiKqG56H53HopMARmR7mPjZQOpvNXm8yu0w8IvU8HKofvXeGwyvoysoFq465pbUglM pe5zPrWSVAfgbwYQeg6EKNd16kJODSyWVfFiKhzfOntZ2gjDA7qh3q6kAuE8rnQMYJxW jXvI/R3gcEESCLwgoPjJMs6HDhzzIwXKejvpKodYg1/Dpi2CsaFV3+yJdO5q8F+IWUc3 eLIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728956037; x=1729560837; 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=2IOurK7ENej5lHHiP4d73lr8yQG82cdevQPBO00m0fo=; b=twtQygVFJNzIFcCtXIRrzghQSbmERX1jMqxxDPImnXyyFiyODRFyUrbxrklI6LNcng EcqudT/BcpJIhwitYItqdtR6GNtXpn74xRQy/8WMIXuN4Z7E5U9avwBnMQb1k4QUqlR9 i4dqoqQWt7myihE+NUBF4UiY04lgF+6ZRS1dSNqcfrkBT8NhJ+aoZxFnlZmkKo84bIYF roaj5JYeB3B0WI6jw1npkP8DRMVL5IviCgCupjwt+ddFstTrxg/AuLkuyZyRYRAmXCCW KiYhvOrZExgr5yfwgD8F6EbjlCF17HhkcXR/Ds0aYAbQLDNFvz99vxIOKGdkMfK0wuUj 9rGg== X-Forwarded-Encrypted: i=1; AJvYcCUnhryX+yVn1JpesQqqQK8d7zog07/9TsYh70Q0fRgubLne1vZ2Wt7DkvcmwJncwOH1CWfYlPHahdPr1nA=@vger.kernel.org X-Gm-Message-State: AOJu0YxsJKhgR1tKDaOEmZXwGeg7fb/eYOsojeLLzrkbAEDihVzlVsIJ xz7JCRC1TnUkYrOPZu9E1JX5n28jxItdc4g1VkyrHh7i6IlESeW9 X-Google-Smtp-Source: AGHT+IE+s7PAXjF3lV5jJ2AuCaaz/0o7aAW2i8sfMGGFqoeg6aQJcAwijtM1PaQhSx1fjTwLZ36lFg== X-Received: by 2002:a05:6a00:174b:b0:71e:148c:4611 with SMTP id d2e1a72fcca58-71e4c13a1d0mr15707237b3a.6.1728956036726; Mon, 14 Oct 2024 18:33:56 -0700 (PDT) Received: from dw-tp.. ([171.76.80.151]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e77508562sm189349b3a.186.2024.10.14.18.33.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 18:33:56 -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: [RFC RESEND v2 02/13] powerpc: mm: Fix kfence page fault reporting Date: Tue, 15 Oct 2024 07:03:25 +0530 Message-ID: <6bf523aa03e72d701d24aca49b51864331eed2d5.1728954719.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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=3D/proc/kcore of=3D/dev/null bs=3D1M =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D 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 Guessing the fix should go back to when we first got kfence on PPC32. Fixes: 90cbac0e995d ("powerpc: Enable KFENCE for PPC32") Reported-by: Disha Goel Signed-off-by: Ritesh Harjani (IBM) --- arch/powerpc/mm/fault.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c index 81c77ddce2e3..fa825198f29f 100644 --- a/arch/powerpc/mm/fault.c +++ b/arch/powerpc/mm/fault.c @@ -439,9 +439,17 @@ static int ___do_page_fault(struct pt_regs *regs, unsi= gned 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 reporting false negatives, let the fixup table + * handler handle the page fault by returning SIGSEGV, if the fault + * has come from functions like copy_from_kernel_nofault(). */ if (unlikely(!is_user && bad_kernel_fault(regs, error_code, address, is_w= rite))) { + + if (search_exception_tables(instruction_pointer(regs))) + return SIGSEGV; + if (kfence_handle_page_fault(address, is_write, regs)) return 0; =20 --=20 2.46.0 From nobody Wed Nov 27 00:31:34 2024 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69BAA16DC36 for ; Tue, 15 Oct 2024 01:34:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728956043; cv=none; b=UqKX/s+NnijTKXVY4moFitEFZhsWd/P1CJPlP21XLwon3BDiVderrTWq9B/WlIeTDb1jFMCdizn02OVQ3SqYbdY7nu4CBJNPPTK3GPmFegXEfPxaheW50vdbCvyByhW/mYTeHjAeTjtLA+DdOoKYlhKS/CK0SbChYUqH532gf9o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728956043; c=relaxed/simple; bh=L3Ba7Q5bU38/cxIB9cSQHYQb0MRnuxWke3X0IYEi7MQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Dif1uGsk/TVJYDVWbLh0t9eLs8dS+9D9qJEPeLQc7FCRxw/Rl29/Oe0m72FTUzCpToNqdNNJf4bN6vtIUvL6RWSUCCDGLdCLZGruDIao53lIf8wiGxtS+5wUIyCEk7dCrKzcI1PK1ZNtphpKY19WFU76Yc8RAcYHBktty8c272E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=K5k2DIow; arc=none smtp.client-ip=209.85.210.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="K5k2DIow" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-71e681bc315so921843b3a.0 for ; Mon, 14 Oct 2024 18:34:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728956042; x=1729560842; darn=vger.kernel.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=9gdBU6NTSnQ45ASWgUOhpCdQmMAIjthCFPvKHCG5k1I=; b=K5k2DIowlLCmzXEY03Ak8wOeUb/pQhIf0ur7dYq3hpkpNsqQ2Rtukh9HcL3mZXAKK/ +uPck8u2XS9GJoBjVDWkPAdj7QehBwhg218JgYnETvWfcGlLiUYe6LpsbYyR3bHiwTGv G5y/LTYc5ZYHCulz6kSObuij+NsrjPWkAJoA15hrJa1HAmdoIdbcxGB9ni7iUytf2Vvr 0dBntlEWYi3fw7s9AGgqmxkMph7NGghj++O1JHoOdandIyVr511SNKxPrOunNClettFM EbbP0h/SDt/deETGH+8V7UHoisCZoCZq/4XXZMmqgDunoiR2uKbH1xB3p/TNoOpmeujE PIlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728956042; x=1729560842; 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=9gdBU6NTSnQ45ASWgUOhpCdQmMAIjthCFPvKHCG5k1I=; b=iBBoQWS7JAbuVHQ9l7XW0WrR8JD4Ou6z+AxgfG81FglstNIC8Prk+LACdYd6NOMqry BXfmFJA6Tfo78vEHltfvxxluHMmeNNUb1+jRggi+ooG2JZ+EMfZL5sFQbtCmcu7CrkUE CWqeak96PV3wy+KeTUZo7NFgAIEKIJOldD0SBNq7dbrPAzIr+Q3xsj0yjw+hLnreR7Id yIZ1NcEdLaSN5Sc+OBk63l5OXnBryry5nghG1e/zyvYRgdr2Rz4wcgmnEafHElTo3kf4 jylqpUFZ4D9hFAM/3X1PoffJ3y1rMS/MuVjCVeijb8S7Wqng2U35JkVsjwFqfx/DTUpo 4+dQ== X-Forwarded-Encrypted: i=1; AJvYcCUGqDEbL4IB++L1iW8DEuChni/rT9iZJVvD05Qp47dx/vRSZAJr7YGZFWFbSNVnIgAzsMoquT7dFUuRKsY=@vger.kernel.org X-Gm-Message-State: AOJu0YwTS/Ni45/82gdULJkDzYgSs++uwIPDxf6d3Ddk3NhxIVcFLB5d nZvrGyK/7y46Jclur+6+wy1ZjP7sUD5vWWd55j5BPTJwOgVlamzS X-Google-Smtp-Source: AGHT+IEiFeaAHOWvlSRTf6MSOaFyHyrBNKW3yk4oAKnnkBoJktpp0QXSxa/Okqxxx4ycP0dnhBWBFw== X-Received: by 2002:a62:f252:0:b0:71e:5709:2330 with SMTP id d2e1a72fcca58-71e570923afmr12036633b3a.7.1728956041587; Mon, 14 Oct 2024 18:34:01 -0700 (PDT) Received: from dw-tp.. ([171.76.80.151]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e77508562sm189349b3a.186.2024.10.14.18.33.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 18:34:01 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linuxppc-dev@lists.ozlabs.org Cc: kasan-dev@googlegroups.com, linux-mm@kvack.org, Marco Elver , Alexander Potapenko , Heiko Carstens , Michael Ellerman , Nicholas Piggin , Madhavan Srinivasan , Christophe Leroy , Hari Bathini , "Aneesh Kumar K . V" , Donet Tom , Pavithra Prakash , LKML , "Ritesh Harjani (IBM)" Subject: [RFC RESEND v2 03/13] book3s64/hash: Remove kfence support temporarily Date: Tue, 15 Oct 2024 07:03:26 +0530 Message-ID: <00ba1fdbf7e135fab9d3d1c8872674079452446a.1728954719.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 (>=3D16TB) (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/k= fence.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/book3s= 64/hash_utils.c index e1eadd03f133..296bb74dbf40 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 lo= ng 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] =3D ret | 0x80; } @@ -814,7 +814,7 @@ static void __init htab_init_page_sizes(void) bool aligned =3D 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 =3D pgprot_val(PAGE_KERNEL); - if (debug_pagealloc_enabled_or_kfence()) { + if (debug_pagealloc_enabled()) { linear_map_hash_count =3D memblock_end_of_DRAM() >> PAGE_SHIFT; linear_map_hash_slots =3D 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 hp= te_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 nu= mpages, 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) -- 2.46.0 From nobody Wed Nov 27 00:31:34 2024 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 490E017335C for ; Tue, 15 Oct 2024 01:34:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728956048; cv=none; b=oQP5BbgsoEFnd9ReucCovC+qpyy8FUlH3xlQWu8YrFTwA9nEgOYv/DH2S3Lcnj6FV5zItPn6yhqWcVMhE55IU1/era8B6ETM+rowtwlIKBpcgAQsV+lgsyNpWafgiQC92BAHp2LZ+GCdkB1EHuNlQr/FfWrrZ2GpfcQEXio1klg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728956048; c=relaxed/simple; bh=FsG1hRAQUYRA/vEnlI+7JEFrFUI5bmUaSjg6v6DcwoU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OEMdYLosoddJEIVGFW499NJbMiYrv6J/XqQfruislSdx1qeRzAu3ADEMMrC4KH1l4l7V3xyB57Rf8sCHV0b7sJaDb+5YBWQtM28L0LM1iHAN5QZT6u65T1tWf/uteFXW8/SFluHaESpsHlfdVz5MVktilhaeLOUE9/nlkZ/MNQ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ek00m7W4; arc=none smtp.client-ip=209.85.215.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ek00m7W4" Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-7ea76a12c32so1815214a12.1 for ; Mon, 14 Oct 2024 18:34:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728956046; x=1729560846; darn=vger.kernel.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=axWsqNzIpvlhLR7DqrnxUdvbHKQsISEkZ4mTeZAqu9w=; b=ek00m7W40mLApXCFYCdZiCe+U/CvuqRpi1N+T3rlsTLud1VSHUk6qeaJVCnV4uWH12 CvDlavMfDrtRgV80JC7K0PgJCfdAMXKtsP4XoC14BPIq2s5zUwayi6C714RpYrOTBT24 5FJNcvlMuL4hfQDMjHXHOVZHxxBd8CbFVlMyKPEjlKXZmWWgOLAb5+b1UghcSecdKbLI 6llwnAevU/XOanGmS0w3tgdlkniSvgmJeSYlFR9xvMxUHoJ6pgMI82j+zoG0jTr1uRfF T/A1qYBjs9yan/gdRRRVZj0Lf2mA4Id3C2GpKsnImwC2msq75qdskgLSHpauTqsHSvq0 CKdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728956046; x=1729560846; 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=axWsqNzIpvlhLR7DqrnxUdvbHKQsISEkZ4mTeZAqu9w=; b=Mds5w0DnBK4fJUPFZ5zOkiYgzgiZyInEH4oNfDETGcizwkQtGpS7NkjptikyTnVxP3 0qwkKIEGSVph9toTl6UifSiN3V9VXJ5IFkgiNgtHqx9QoGjQ+1e++LQQAyrkfNBqkzeg RSDVBnU+30sr4UDwJHIjCCcJFGzy7b4rXwmIwg9NhrbhFeOKAMZ++1I8Bj4O2Oufzbg6 LyR+IIYwD04MTawN1th0yvtrHd5FIBgTNv1eV5PSv/5DKg36STPxSvtkRlZLtZmil8xq WN4+zAm8sQTgrFgkOIbMSC8TL4gGfb+zSwA/J5+zoMsoMYslAhR5xN4UY6DkQ1bgeR7P ucbw== X-Forwarded-Encrypted: i=1; AJvYcCUF0O9ITZLttZ9fKyHoSbq4LGG0HGSLgBk//XxmMNRln3jhr/tYFWoVq/Kws7D60IKIuegu4SLjyEjogkY=@vger.kernel.org X-Gm-Message-State: AOJu0YyxqNYRxaGZ0EcdZuQYXx946JddBAZFTIQK1VoD60drRYAnDUhV CW58Uc7pDAXPOvKD6GGPkgcZP0VxnnS73WtQw/o+u4bVh3qAnh3P X-Google-Smtp-Source: AGHT+IG4I/3JRaWO1s0Oc1G3nloW3mFZD9rynaJ4QyFbWI1r3K+RwAKvmgR5I5AwDy8LCEp8stlWhw== X-Received: by 2002:a05:6a20:2d1f:b0:1d8:a899:8899 with SMTP id adf61e73a8af0-1d8bcf561dfmr20114300637.29.1728956046508; Mon, 14 Oct 2024 18:34:06 -0700 (PDT) Received: from dw-tp.. ([171.76.80.151]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e77508562sm189349b3a.186.2024.10.14.18.34.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 18:34: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: [RFC RESEND v2 04/13] book3s64/hash: Refactor kernel linear map related calls Date: Tue, 15 Oct 2024 07:03:27 +0530 Message-ID: <5a4522af03014d41d98809dd58fab57b187e8b51.1728954719.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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/book3s= 64/hash_utils.c index 296bb74dbf40..82151fff9648 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__); } =20 +#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 =3D get_kernel_vsid(vaddr, mmu_kernel_ssize); + unsigned long vpn =3D hpt_vpn(vaddr, vsid, mmu_kernel_ssize); + unsigned long mode =3D htab_convert_pte_flags(pgprot_val(PAGE_KERNEL), HP= TE_USE_KERNEL_KEY); + long ret; + + hash =3D 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 =3D 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] =3D ret | 0x80; + raw_spin_unlock(&linear_map_hash_lock); +} + +static void kernel_unmap_linear_page(unsigned long vaddr, unsigned long lm= i) +{ + unsigned long hash, hidx, slot; + unsigned long vsid =3D get_kernel_vsid(vaddr, mmu_kernel_ssize); + unsigned long vpn =3D hpt_vpn(vaddr, vsid, mmu_kernel_ssize); + + hash =3D 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 =3D linear_map_hash_slots[lmi] & 0x7f; + linear_map_hash_slots[lmi] =3D 0; + raw_spin_unlock(&linear_map_hash_lock); + if (hidx & _PTEIDX_SECONDARY) + hash =3D ~hash; + slot =3D (hash & htab_hash_mask) * HPTES_PER_GROUP; + slot +=3D 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 =3D 0; i < numpages; i++, page++) { + vaddr =3D (unsigned long)page_address(page); + lmi =3D __pa(vaddr) >> PAGE_SHIFT; + if (lmi >=3D 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 h= pte_group) } } =20 -#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 =3D get_kernel_vsid(vaddr, mmu_kernel_ssize); - unsigned long vpn =3D hpt_vpn(vaddr, vsid, mmu_kernel_ssize); - unsigned long mode =3D htab_convert_pte_flags(pgprot_val(PAGE_KERNEL), HP= TE_USE_KERNEL_KEY); - long ret; - - hash =3D 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 =3D 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] =3D ret | 0x80; - raw_spin_unlock(&linear_map_hash_lock); -} - -static void kernel_unmap_linear_page(unsigned long vaddr, unsigned long lm= i) -{ - unsigned long hash, hidx, slot; - unsigned long vsid =3D get_kernel_vsid(vaddr, mmu_kernel_ssize); - unsigned long vpn =3D hpt_vpn(vaddr, vsid, mmu_kernel_ssize); - - hash =3D 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 =3D linear_map_hash_slots[lmi] & 0x7f; - linear_map_hash_slots[lmi] =3D 0; - raw_spin_unlock(&linear_map_hash_lock); - if (hidx & _PTEIDX_SECONDARY) - hash =3D ~hash; - slot =3D (hash & htab_hash_mask) * HPTES_PER_GROUP; - slot +=3D 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 =3D 0; i < numpages; i++, page++) { - vaddr =3D (unsigned long)page_address(page); - lmi =3D __pa(vaddr) >> PAGE_SHIFT; - if (lmi >=3D 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) { --=20 2.46.0 From nobody Wed Nov 27 00:31:34 2024 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D25717278D for ; Tue, 15 Oct 2024 01:34:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728956053; cv=none; b=Tcz/d0HySuwLjY/der0oiYKQ0eLIlJkduxwdV1bsd8R5KjP5aoSqFqoRXw/iiCahDrK+2qQCF2XxTrLIpWBWaarp652e4OkEmBiuHPRQasvwlMIK7BnnrzsNYt+tlO6398wL265My8KWtzIQxtF3tQdo0yvMm0Wd3gErwfkp41s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728956053; c=relaxed/simple; bh=lGDU6+XsEZA63vePePBnGkCzitISc6raOI8xarwqjFo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A0+QtYlZ5bPPo5NPK/3XbxT/OYqAeGb+GFMkZWyNrNZusMk4LKz0GzPVpi34Gy+0U5u5wXBFFaA+k93vT7BbaGNnKWTyMITyZGQ4PBd20QZN2Yb9W4j5fuyXb42FFuy3Om415Ka/umYv5R/QTJLOPHtmK01CbEA4N3fMotESs4g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BFYwILq0; arc=none smtp.client-ip=209.85.215.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BFYwILq0" Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-7d4fa972cbeso3595510a12.2 for ; Mon, 14 Oct 2024 18:34:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728956051; x=1729560851; darn=vger.kernel.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=U+q0qzhvgy5Htf+jNoj0jpwh62QEw37SjQucvD3DcJc=; b=BFYwILq0VylmbJ3mf4GVmrtMBlY6Q+Laqd4qCqNVJYrVtlZ3H42JRMxxMhXT8+3t/+ Ci0HmDnMBA4hxuweGkXUIzyExaKiV7bMRv/VNTRWBcle6yP5n+62k3bu4lAfFMJRT8Dp UGUb0pScI0VOzPQ+9ZyQgQe5sJJNDdgicvUi0VYE1jg896pcKgV5xlqv3QOJ+trdhhc+ C0/eADjurf4OCE10t5g3bCdx3Vld6I79ttvFPIaXKpm2khu9pZ6UYvIWCPsqZO890+rZ 54vTDXE+HmPSHjXLXDqA8KBszbUxjcsGWORgYx/xlr59+kRxx7EVqBT3yMqRuaJSNovV dYoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728956051; x=1729560851; 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=U+q0qzhvgy5Htf+jNoj0jpwh62QEw37SjQucvD3DcJc=; b=RbcwiaBtdeVobC3Gw+4VO86BQlvcF0w5DHreFBmUu9bskiKgsKDQzJOifXH4u70kxc YardUm/8B+F0tRXn/iJiwuFSeFJFNhpL49ILw+x8KqCSH14u7tdmy9E3NhAKkNWgpnb2 IvQHJ0+xY+axCnDyJYuKIAW7qZqA4fZVAeHvVG7Lqmughq+ipHCy/RayTsBU5Cespe+V Z/nIj1ZHI30BUzYo2JJZQONh08PqVEKLgd5k8BN+mJ+A+GuS5fwZdaNTBv4YfGv2FVwo mxAnTtNTuflEcBoGv7XGAgsxo1h2zF6Omb6QWhpXjuculgPsU7hDXzfpFr55SE/Xhn3P 53cw== X-Forwarded-Encrypted: i=1; AJvYcCWNnlLGHz/Nao6XYQ73osd2VdXjD8Gydxdrilw9Td7nc3V9pwWix3aNR+N2DQbF/LTgypI4n7IDUojJ9l4=@vger.kernel.org X-Gm-Message-State: AOJu0YxmgMdvryR+nQwgEGk2mret787rCdTo1MCIcG28p7n4824RB6vO 71Zf5ntKGrdud7st/FOVS3AkrlUJ2p8Q1HdkPoa1YJtydiuJwnAE X-Google-Smtp-Source: AGHT+IEG9dZAng0ihOIRx501nnz2kIcPdMnvgADTGVh5vNpZ9v3ZsQlVB5geCgNicOYeTFxr8a+CGw== X-Received: by 2002:a05:6a21:710a:b0:1cf:9a86:6cb7 with SMTP id adf61e73a8af0-1d8bcf2c37bmr19861897637.20.1728956051333; Mon, 14 Oct 2024 18:34:11 -0700 (PDT) Received: from dw-tp.. ([171.76.80.151]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e77508562sm189349b3a.186.2024.10.14.18.34.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 18:34:10 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linuxppc-dev@lists.ozlabs.org Cc: kasan-dev@googlegroups.com, linux-mm@kvack.org, Marco Elver , Alexander Potapenko , Heiko Carstens , Michael Ellerman , Nicholas Piggin , Madhavan Srinivasan , Christophe Leroy , Hari Bathini , "Aneesh Kumar K . V" , Donet Tom , Pavithra Prakash , LKML , "Ritesh Harjani (IBM)" Subject: [RFC RESEND v2 05/13] book3s64/hash: Add hash_debug_pagealloc_add_slot() function Date: Tue, 15 Oct 2024 07:03:28 +0530 Message-ID: <7fc9a78423fceda0bfd07f80583a7c9c0938e339.1728954719.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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/book3s= 64/hash_utils.c index 82151fff9648..6e3860224351 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 vad= dr, unsigned long lmi) mmu_kernel_ssize, 0); } =20 +static inline void hash_debug_pagealloc_add_slot(phys_addr_t paddr, int sl= ot) +{ + if (!debug_pagealloc_enabled()) + return; + if ((paddr >> PAGE_SHIFT) < linear_map_hash_count) + linear_map_hash_slots[paddr >> PAGE_SHIFT] =3D 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 numpa= ges, { return 0; } +static inline void hash_debug_pagealloc_add_slot(phys_addr_t paddr, int sl= ot) {} #endif /* CONFIG_DEBUG_PAGEALLOC */ =20 /* @@ -513,9 +522,7 @@ int htab_bolt_mapping(unsigned long vstart, unsigned lo= ng vend, break; =20 cond_resched(); - if (debug_pagealloc_enabled() && - (paddr >> PAGE_SHIFT) < linear_map_hash_count) - linear_map_hash_slots[paddr >> PAGE_SHIFT] =3D ret | 0x80; + hash_debug_pagealloc_add_slot(paddr, ret); } return ret < 0 ? ret : 0; } --=20 2.46.0 From nobody Wed Nov 27 00:31:34 2024 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E16CA15B96E for ; Tue, 15 Oct 2024 01:34:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728956058; cv=none; b=U8veeoXy6BCOu/7P3/K2OEpgcA96FAJuxWYpalrZjtRUW74OHmIN5SUAlNOUbTVB/9E7IrCymp1MQ0IIHGCJaN2D0X2uK24uYSeLZqR3S+RDXsP2RjQGo+R+Aq8VHsvIUap7GBlusQ3QzOKLrGFiLHjzTu0TIG905mosYJ4uSP8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728956058; c=relaxed/simple; bh=ll46Y5ohND+TUmqRmSlDtnD60Fmr6r5zMc07Tyy0M5k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EIbk9rTpQHqkdF8wqKHAENuiv4pw/shY9JJhvTyuhLqJ0HnZaaK+96oUav3dTBDfdQPt//QfAhc2Jf1zdk6KtAcl8fI+tpgau84mrn3NBeZ2xdFlrqt1P1uex8CTyfXjn46VEuEZZn0zbSizZjPhnPqVlaVMFNnEJS4+wzW6AF4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TcSwee0A; arc=none smtp.client-ip=209.85.210.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TcSwee0A" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-71e5a62031aso1363786b3a.1 for ; Mon, 14 Oct 2024 18:34:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728956056; x=1729560856; darn=vger.kernel.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=/MHsxmP9bN1bxx4msR28qZ2la9zK0wSY8EDrce3K+zQ=; b=TcSwee0AaZMkdxLVwzxlbaCFTTjtbU7AhSy9yINvy4IfMGOE4c82oU0zhHOqVB834O 41qbtFENQW9lrTe4wFZ7h4u6Wq4LqCdwhqmewjF/3Wqq/wElJ9Y2/ngznkmbyg4V9dUg kssewrzOOsoZxeYeuoXi+QHY1eiYEEw0UMViCkil4C4OM36JYhhRXfQCQmggPYe53kkJ lAVVTeOFMvbYmyu/Ay0Op4FYgTPM7eSaEkIJxGeC6TEVHckyZACnnCiNgVOCwPO2gXHR pkEtt6pcGVbqwiXXBDOrizVoTsl8LzgwVEoH99yRdgBve29sDXB0Ah+pyQ7ttgYSTRnt nTIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728956056; x=1729560856; 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=/MHsxmP9bN1bxx4msR28qZ2la9zK0wSY8EDrce3K+zQ=; b=PksjHIEQ5fpoNN45qGVpFZYgivfS0remIBm0UPlftaSFRAnYyf52+0BnSbJkjtJQVb 9iXaoT1l51bOwphv1PIBRvDDtuHswhIklmeHolM24wPM0xG0wG+LSabX5xJtI27dKU4X r58gEP7tU4F6+buObXE+6tFijUeyRRJrW2u3VOf+DZetndaVmsXSE6yIjGSXbV75ydOp yQvacHzImxkGngxQU9MvpkTJhoq3wALCVNvEBXkwhEVhUZO+vyGPkwmZJxN8eQTZp4KV 1aYOjQaeVRBwCYRgcfZodrWWipq8WOR8Yg9yrTKTVodkN9j+cBJaTUPYIzaxg85NFerj 2ATA== X-Forwarded-Encrypted: i=1; AJvYcCVRl1lBk3tVjy0UVz9cFA0FZX5mTTtBsJKJupRz/m8bMRqegR2UMUVbbFL7c3z0zr4Od91DNu7Kz+qXgbs=@vger.kernel.org X-Gm-Message-State: AOJu0Yxysv6NMaFO1nmT8toVKZtp+TIYTg2C2ljnOCePb9Vct2KszNP7 XpeogH29r+k+2TdZOf08Vke6IcHs5/DquMrAnrLIg6t9iLWWGHb/ X-Google-Smtp-Source: AGHT+IEaRbtvLZbSifnrZqi1CARugZbYpE5zHqXON9KkesVGZbR8E08Sd3QxolQeAT6rqf3d5xyTkQ== X-Received: by 2002:a05:6a20:9f47:b0:1d0:7df2:cf39 with SMTP id adf61e73a8af0-1d8c9577ca1mr13971673637.7.1728956056191; Mon, 14 Oct 2024 18:34:16 -0700 (PDT) Received: from dw-tp.. ([171.76.80.151]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e77508562sm189349b3a.186.2024.10.14.18.34.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 18:34:15 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linuxppc-dev@lists.ozlabs.org Cc: kasan-dev@googlegroups.com, linux-mm@kvack.org, Marco Elver , Alexander Potapenko , Heiko Carstens , Michael Ellerman , Nicholas Piggin , Madhavan Srinivasan , Christophe Leroy , Hari Bathini , "Aneesh Kumar K . V" , Donet Tom , Pavithra Prakash , LKML , "Ritesh Harjani (IBM)" Subject: [RFC RESEND v2 06/13] book3s64/hash: Add hash_debug_pagealloc_alloc_slots() function Date: Tue, 15 Oct 2024 07:03:29 +0530 Message-ID: <4245e8392bdcb0ea168b9700d356f75575511536.1728954719.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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/book3s= 64/hash_utils.c index 6e3860224351..030c120d1399 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); =20 @@ -274,6 +272,8 @@ void hash__tlbiel_all(unsigned int action) } =20 #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); =20 static void kernel_map_linear_page(unsigned long vaddr, unsigned long lmi) @@ -328,6 +328,19 @@ static void kernel_unmap_linear_page(unsigned long vad= dr, unsigned long lmi) mmu_kernel_ssize, 0); } =20 +static inline void hash_debug_pagealloc_alloc_slots(void) +{ + if (!debug_pagealloc_enabled()) + return; + linear_map_hash_count =3D memblock_end_of_DRAM() >> PAGE_SHIFT; + linear_map_hash_slots =3D 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=3D%pa\n", + __func__, linear_map_hash_count, &ppc64_rma_size); +} + static inline void hash_debug_pagealloc_add_slot(phys_addr_t paddr, int sl= ot) { if (!debug_pagealloc_enabled()) @@ -361,6 +374,7 @@ int hash__kernel_map_pages(struct page *page, int numpa= ges, { return 0; } +static inline void hash_debug_pagealloc_alloc_slots(void) {} static inline void hash_debug_pagealloc_add_slot(phys_addr_t paddr, int sl= ot) {} #endif /* CONFIG_DEBUG_PAGEALLOC */ =20 @@ -1223,16 +1237,7 @@ static void __init htab_initialize(void) =20 prot =3D pgprot_val(PAGE_KERNEL); =20 - if (debug_pagealloc_enabled()) { - linear_map_hash_count =3D memblock_end_of_DRAM() >> PAGE_SHIFT; - linear_map_hash_slots =3D 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=3D%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 =3D end - base; --=20 2.46.0 From nobody Wed Nov 27 00:31:34 2024 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5C1518872D for ; Tue, 15 Oct 2024 01:34:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728956063; cv=none; b=JnrX2dPlyzRsF3wn/+63Rb7Y+GRIYrMkfVcGUH9KhGvm9ay9KbVm1aN92gNiU3uZ0v2ccndPbQ3G2nyn9kg1vVdscpU/jPGN74mt3upQrZCWl6XWX4Z8Kg9XKhRDSQAJ67NAPtyUkpGt6TXl5hZ6f5aR28f/q7jJLiSOuM2t0Ig= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728956063; c=relaxed/simple; bh=v1P4WAxWuvUCZPOP2tMFqMbCJcwChW39Ab67XAl34ag=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l6zobrcF9KFqo6R6wOIB22TamOaMrr/QPti/RP+ZZgQMIRhfrI9X2p/EFma7BWCFohoZMZv0Dlc7HI0I3m2UBHGWsMZM++3XBogipqXeqmg+0p3/iDlSpEva69kl1HUHal6nw3snzOW9W2Sr6EfG95J17fFY48m7u231wNXjIf4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=AzEpBIyp; arc=none smtp.client-ip=209.85.215.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AzEpBIyp" Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-7ea76a12c32so1815370a12.1 for ; Mon, 14 Oct 2024 18:34:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728956061; x=1729560861; darn=vger.kernel.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=oTnklaF1aF0bTWeWldi91Sj9bwNgHQZw6gVAVQdUYd0=; b=AzEpBIyp0OVVMqWO3areVMHpQstvB1+w9BTHtCmXv2Tk2kdan3F2dtaF/3u2uDEgog mSI3e4jw0PatwvRN7q2mz/z9bfo4fvIMyFQKktlzsL7jPdB1Yj0Z46IJlEBDlgkJKEf8 iLs3N0KAUfuK8pcJNxp4LGZNk4YY2qJSFnNrw/GKV/z5tbYOjuNsTrxutHjIB6Fq/0GE 3VAF9MKF6jKWHc6wONTafZJfa68XmbDyi/gVqfGThaC0nq/7oUfVdlrtxrAKi8QL4Ssu yvmIzKtvgfkiFpwy3Bft3ZiIqffr7MOUK1p1ftliOh/vJCeP7dVEJw8GGKAbegr53uJI CpNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728956061; x=1729560861; 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=oTnklaF1aF0bTWeWldi91Sj9bwNgHQZw6gVAVQdUYd0=; b=ZGEqFMy7Vd4MWoLaSFVgrtqdcCq+Y4nheRb4XeJeHq8pgKPR8+Da7BC4Xs86comfDw +/KzmNeCsSrlVUOzBx8MSY4GD6n9sDO3EqzWCQFozlV8vYMtfqOtRx6YopdGxei0QZo+ FMuwoaAC5d1x+fNZyCGSPW7ITHy9q1aDqWGNmu5+b/qFF5IHSRtxwkzj11YDDTHsanuj rI0C2lGFNdnrCyO9D/k1cY8j6QclJDbgusr1Gmw38xgZSKOGLmUe3Iy0/KA4z53V7gHf eeaA4SdZMUStqozQVYfz/EtsN4BCD/mfWsOVJ9sKIzVCJPZ4Nq4ZywjBYiv0OAPkNkym pGdw== X-Forwarded-Encrypted: i=1; AJvYcCXgyWW275fWKjAm97RV4ufVl0S9zp2M64KRD17faEmmzMUxlfAyiEqYvC/0oEIBgQAR4PXAkf9Y5qhf9wQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yx7zyGrDe/+YWTqMIJd1VU0+DdzSfvJjbNeM4vkeocXO3YqWo9z /X0AYmEVvqFQ+VE4Dvxh1vGZogee+5tw9A6RVgXM7sTat4fbOLfB X-Google-Smtp-Source: AGHT+IFT6UGlq+wYgtgPhE6bzO8Rllrurc9EHvyW/SZWzz7xpV6AjzAWDpsP/H6dyEXrivEMXbEKOw== X-Received: by 2002:a05:6a20:cfa4:b0:1d2:e92f:2f48 with SMTP id adf61e73a8af0-1d8bcfa7ef1mr19096796637.40.1728956061028; Mon, 14 Oct 2024 18:34:21 -0700 (PDT) Received: from dw-tp.. ([171.76.80.151]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e77508562sm189349b3a.186.2024.10.14.18.34.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 18:34:20 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linuxppc-dev@lists.ozlabs.org Cc: kasan-dev@googlegroups.com, linux-mm@kvack.org, Marco Elver , Alexander Potapenko , Heiko Carstens , Michael Ellerman , Nicholas Piggin , Madhavan Srinivasan , Christophe Leroy , Hari Bathini , "Aneesh Kumar K . V" , Donet Tom , Pavithra Prakash , LKML , "Ritesh Harjani (IBM)" Subject: [RFC RESEND v2 07/13] book3s64/hash: Refactor hash__kernel_map_pages() function Date: Tue, 15 Oct 2024 07:03:30 +0530 Message-ID: X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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/book3s= 64/hash_utils.c index 030c120d1399..da9b089c8e8b 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_a= ddr_t paddr, int slot) linear_map_hash_slots[paddr >> PAGE_SHIFT] =3D slot | 0x80; } =20 -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 nump= ages, 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) --=20 2.46.0 From nobody Wed Nov 27 00:31:34 2024 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E797170A30 for ; Tue, 15 Oct 2024 01:34:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728956068; cv=none; b=nHXtNZwErQiEjsHSoAuIwn/9I3KBuRJcKGAGG7MoGp0gn/fxq6vXtaKFDTnwDAetKS+KIa0QA2nLy50VmQlS0jzpkXira8Tv1i9MIqJZnmYHO4aO7xQKZJAIniuVcPTp2CvxqXYr2Q82BIoGGdV2JR52qtwNljXzRaPIBn6RX74= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728956068; c=relaxed/simple; bh=R968dba8OE7cCpOttgpeILQbdzMZ+6PWqhvC1JS2Eaw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pie0OUOZSYCPPGdXhWxxZ31xOi7/9ohVwNrMvfGKh+ZrxjWzBQIKRdm9Zbp8/0Eo3BqYcfHUcIxV57JBslhKY2NXeknWVi/0Pup6dZ8t0Lhw2vRmyf5buj1D3YMsO6RGv6TpWnjgW4eNFJF/3B8zA0NNQoQYPpFV6ddL31c5mJQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=YEESqLlX; arc=none smtp.client-ip=209.85.215.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YEESqLlX" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-7ea7d509e61so690165a12.1 for ; Mon, 14 Oct 2024 18:34:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728956066; x=1729560866; darn=vger.kernel.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=ww6ZbzhcNbPuRWG0GzwKnAEreEL780mKVa0cmRg0+f0=; b=YEESqLlXYbtbq/nueHrwq8DF9vCW4juriEETVQBrOxArQWrUAagIUaUzuAi4S/ly/Z Rlt2OvLGBmWhKBcnbESGKF+jyrTmHkj5ErZ/nQ8VbioEYTQl65tqEFXgOEeGUsaR93Ht LxrW+KlQbpIIu2CO+BQKfvtL793mKeNzAN7me9rQoalUx3oqlwHGIWjhGyPlmx4qxLYv 2GOZBzSjnQf8lyu/EeLFdUWPKWeL43XzFnU7lKO0X0qA18lJj4DVGd50KsBR1HiVleZg FUlc8iy3EJ1v2LohoATACP7YaBpt0Azx4euV6Jj3IhWsjlHCw0vghaI+4r+l1NUhinH0 Y2Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728956066; x=1729560866; 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=ww6ZbzhcNbPuRWG0GzwKnAEreEL780mKVa0cmRg0+f0=; b=eRUZIonc0IntkWL9bvGyX1/fHKaLCEVz/8V7b7DegTVurFOdwvSU26AZHYebn2zgkL I/SlIA0ogwbpgHCYRpDoTz7I2/aarDnoRakA0zUTDPGi3Omud5AQYEuxrrlrhb5Xg+xB degfg/aIWyzRpxCw+5wG+a0kJysKtOkrW+8vSJIOAwl3TlI644FFCO4ml3kIMLgQt92d m4946wWGEzw7CexAb6tH59t+B2pkdMTPnJ9l/5lqQNOehcmTLl2J5lP4a3ExkrWv2Xgj p5TWU6QhWzW2bUOTUI8RPvNgR0xVEVhCHrAEXquDfYZOTWXTFPu3TW7vxy6R4gBtGiYK DzWw== X-Forwarded-Encrypted: i=1; AJvYcCUwqAMgm1/Lw49w/46gNVg4WS8++4+OhbpZOASIyoVbHPtNEdbtlTkh510bvxFXjj0gih6+GHzy9nmNzcY=@vger.kernel.org X-Gm-Message-State: AOJu0YxPUsQmWTY1eH+NCQEKXdEctGiBYXb/Tya9FJwPv5dZwW3kfD1i 1cmUe/mbyM6peh4rrJT5x0vhnUjw/AYduyi7chmN+fofuzXJ9LVR X-Google-Smtp-Source: AGHT+IHGZTaTUSSUJMjQoBpL1FZpf4KVi65Lqy7OyMEzvzFSJ0mjrxB0rW6XRaLy1i6Ch9oXLcIlMw== X-Received: by 2002:a05:6a20:2d0b:b0:1d8:b060:37c6 with SMTP id adf61e73a8af0-1d8bce4272amr19010970637.0.1728956065840; Mon, 14 Oct 2024 18:34:25 -0700 (PDT) Received: from dw-tp.. ([171.76.80.151]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e77508562sm189349b3a.186.2024.10.14.18.34.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 18:34:25 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linuxppc-dev@lists.ozlabs.org Cc: kasan-dev@googlegroups.com, linux-mm@kvack.org, Marco Elver , Alexander Potapenko , Heiko Carstens , Michael Ellerman , Nicholas Piggin , Madhavan Srinivasan , Christophe Leroy , Hari Bathini , "Aneesh Kumar K . V" , Donet Tom , Pavithra Prakash , LKML , "Ritesh Harjani (IBM)" Subject: [RFC RESEND v2 08/13] book3s64/hash: Make kernel_map_linear_page() generic Date: Tue, 15 Oct 2024 07:03:31 +0530 Message-ID: <0ecad6f4f0d71fd8eb92b437315e981d23a14bca.1728954719.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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/book3s= 64/hash_utils.c index da9b089c8e8b..cc2eaa97982c 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) } =20 #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 =3D 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; =20 - if (linear_map_hash_slots[lmi] & 0x80) + if (slots[idx] & 0x80) return; =20 ret =3D hpte_insert_repeating(hash, vpn, __pa(vaddr), mode, @@ -298,36 +295,40 @@ static void kernel_map_linear_page(unsigned long vadd= r, unsigned long lmi) mmu_linear_psize, mmu_kernel_ssize); =20 BUG_ON (ret < 0); - raw_spin_lock(&linear_map_hash_lock); - BUG_ON(linear_map_hash_slots[lmi] & 0x80); - linear_map_hash_slots[lmi] =3D ret | 0x80; - raw_spin_unlock(&linear_map_hash_lock); + raw_spin_lock(lock); + BUG_ON(slots[idx] & 0x80); + slots[idx] =3D ret | 0x80; + raw_spin_unlock(lock); } =20 -static void kernel_unmap_linear_page(unsigned long vaddr, unsigned long lm= i) +static void kernel_unmap_linear_page(unsigned long vaddr, unsigned long id= x, + u8 *slots, raw_spinlock_t *lock) { - unsigned long hash, hidx, slot; + unsigned long hash, hslot, slot; unsigned long vsid =3D get_kernel_vsid(vaddr, mmu_kernel_ssize); unsigned long vpn =3D hpt_vpn(vaddr, vsid, mmu_kernel_ssize); =20 hash =3D 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 =3D linear_map_hash_slots[lmi] & 0x7f; - linear_map_hash_slots[lmi] =3D 0; - raw_spin_unlock(&linear_map_hash_lock); - if (hidx & _PTEIDX_SECONDARY) + hslot =3D slots[idx] & 0x7f; + slots[idx] =3D 0; + raw_spin_unlock(lock); + if (hslot & _PTEIDX_SECONDARY) hash =3D ~hash; slot =3D (hash & htab_hash_mask) * HPTES_PER_GROUP; - slot +=3D hidx & _PTEIDX_GROUP_IX; + slot +=3D hslot & _PTEIDX_GROUP_IX; mmu_hash_ops.hpte_invalidate(slot, vpn, mmu_linear_psize, mmu_linear_psize, mmu_kernel_ssize, 0); } =20 +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 >=3D 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; --=20 2.46.0 From nobody Wed Nov 27 00:31:34 2024 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4642E189BB5 for ; Tue, 15 Oct 2024 01:34:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728956072; cv=none; b=Bj77Cr9IOWjzQD1qoehL/oECSL1BLiCtqn505SmekWRj+eagVUKyjebuqo6cnSimBDdtjWIPbSicGAlVDCEuirRkU2b3bGLXb5aVhCzcpCX0NyX5M//JeZ5cMvpN2NBX79A4FllUsSdc53HKn+XxZaywuXBbcAFqpoV64gch9b8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728956072; c=relaxed/simple; bh=iNTLscZVjBDcYCPDjAxQPKLBjQZrCDHjaFhmiiWrPrk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HHFM2iWt04SE95R6KSo70hIF0+H1OwXSoCJKEXzER3Q4s2VxjoYe/hwunp1znnrQu8enwRoWXoKYAkiBpJhsd4P5EcXc4yRH0k6OCgdVhr30uX44lMlUgsk+Jun51a8DvwtB/roBT++jCKU8LjatjaSO4xJ0JsBb792bfTIzZ1I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=J+kLlr1n; arc=none smtp.client-ip=209.85.215.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="J+kLlr1n" Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-7e6cbf6cd1dso3348008a12.3 for ; Mon, 14 Oct 2024 18:34:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728956071; x=1729560871; darn=vger.kernel.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=jpwPGGqxMjTTALmPRltkI2obnVC0TIxSM0BTVcrrVEU=; b=J+kLlr1nuBJOcBM7Pi+BWPSi8tVDNozUZ1MSUAYizRN3mub93Wjr8ffk9xlY8yKiAr 8liNmphT7g2J4vziBfpdnUDrimye7j1xdGEt6t8HNEO/5BcTxNavMR79ClpSPhzs3prs AbagJdFNwNU77MUFMooZvJJosNjbtkP7eDTMTB+54/xshXyOcfuSLNNwhlrHRN1Ykx8V aVDEWnsR+sYHPbZx4FB6GJQ1mbHUfEVuCWstTYoj/anq74zOQg+vpwkmnGV8wzAskDzF Mq7MfABmUqAXHmamtD+W8qmLyT42ZKb6kWbKICjRiYlKMgrKRxVae0S7aE+z2jvw+828 yJEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728956071; x=1729560871; 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=jpwPGGqxMjTTALmPRltkI2obnVC0TIxSM0BTVcrrVEU=; b=lp1B/2vcLca3RFGcibrRW8JyNFdLm1EI0x1re+VMM/iLgmoX10sCy8tmMf28SFYHCd cS8v+9b3nTmHCj9dVICytcXqWx98Shki3S5D+Lz/I+EYeqRjNQEscsYKo6MEfvUaUtSL oGd/b51sovzJXKtRwEReS+jDWZ5XbzUHRMWUJDb7X6jrveLB5izDt2p9PCO6a+63lzwM KYK4LNJsN5k7BH1eDIV66VoZzoG78O0ifTFrazv7E6yPCPvfbovSIPe77TRtpkN44obt n1ef39or3Jol7JKDKFZ6Zn6gtIoeXmuJxVUJrxO0cVwK0gPTXStocINSPQp72Kvj3Hjf F9fg== X-Forwarded-Encrypted: i=1; AJvYcCUZYSoTTckKJwjoj1glf+4Nv+l0zJqaJqyC9gEiNYM0LEilFKNafg7QqdsTlpzMlCdpezhVjtopOUd9pWg=@vger.kernel.org X-Gm-Message-State: AOJu0YwPtKRiEB1hARAwlAkmhWq0cm3pf1CEPzmm1n2Q9QFKjDJnfrFI qC0mb8+iy9ofZh/Ly8mpNr3U1TKhVFHAg+stJozd8F695TlGK+Ru X-Google-Smtp-Source: AGHT+IHYwbiuRk5aKKEVmS1LD0xBTPgGenAkQ5XvzCOzwV/g1bm0dITYhUx7OfVFtgaRIRCqBx30PA== X-Received: by 2002:a05:6a20:c997:b0:1d8:adea:3f7c with SMTP id adf61e73a8af0-1d8bcf18038mr20979021637.14.1728956070636; Mon, 14 Oct 2024 18:34:30 -0700 (PDT) Received: from dw-tp.. ([171.76.80.151]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e77508562sm189349b3a.186.2024.10.14.18.34.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 18:34:30 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linuxppc-dev@lists.ozlabs.org Cc: kasan-dev@googlegroups.com, linux-mm@kvack.org, Marco Elver , Alexander Potapenko , Heiko Carstens , Michael Ellerman , Nicholas Piggin , Madhavan Srinivasan , Christophe Leroy , Hari Bathini , "Aneesh Kumar K . V" , Donet Tom , Pavithra Prakash , LKML , "Ritesh Harjani (IBM)" Subject: [RFC RESEND v2 09/13] book3s64/hash: Disable debug_pagealloc if it requires more memory Date: Tue, 15 Oct 2024 07:03:32 +0530 Message-ID: <79552bdb6dac0d0a39d9c639bdf92f4e66dcaa55.1728954719.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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/book3s= 64/hash_utils.c index cc2eaa97982c..cffbb6499ac4 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 =3D ppc64_rma_size / 4; + if (!debug_pagealloc_enabled()) return; linear_map_hash_count =3D 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 =3D 0; + return; + } + linear_map_hash_slots =3D 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(voi= d) =20 static inline void hash_debug_pagealloc_add_slot(phys_addr_t paddr, int sl= ot) { - 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] =3D 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; =20 + if (!debug_pagealloc_enabled() || !linear_map_hash_count) + return 0; + local_irq_save(flags); for (i =3D 0; i < numpages; i++, page++) { vaddr =3D (unsigned long)page_address(page); --=20 2.46.0 From nobody Wed Nov 27 00:31:34 2024 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E00A1714B5 for ; Tue, 15 Oct 2024 01:34:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728956077; cv=none; b=KWKwZKHYNpp2mofzfIwdhx8l/7Z+cg0LsIk+V4VgHuyGdpbd4FAUJ8NftJix/M9doghvaDnumgOmZl8+WC5+6fQoMYKjRXubfQuqW5xKss3zXPexCkPBzE9DbifPduQk3VOAndyvvk/cX5fCRK3u0eWb4I1SUySl96Hw0wLBBH0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728956077; c=relaxed/simple; bh=2xzcSmJ90OeB9AEpfOWapA2ZrBMBcKUdC05kW071KNs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O5QkCB6ZBLFSUPIqUKEe5f05gSeqPL3m6WuESUPCh5e8lM6132Hl6lwuBQdJPCOrUhDefCaubMj7xui24xSSGyqY5cQVJgz0f7pUIg7o7xJSdpeDp0eHr4+mCOfzBt02Gk0lx/b2HnIB2hNk9NKhi65jbNTjhu479UW/41Gu3PQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fN7/qsc1; arc=none smtp.client-ip=209.85.215.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fN7/qsc1" Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-7ea7e250c54so1064958a12.0 for ; Mon, 14 Oct 2024 18:34:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728956075; x=1729560875; darn=vger.kernel.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=OpMDq1IEGMMPwRojJ8i4AsUukx9XqidcnS2hx9BDF5Q=; b=fN7/qsc1pHAiYSTN8RNhHeD/Vnt7Na8+2BfQZfne7XiawzmOb8fEYE3GlVQnd3Ydha pF4xRTcVpQY8c36eQC8bnKN9qv8y/K4yl0qZYyKgemiNmFZtr8QXlPaTrTRXMTBYSO+4 vEcvjCCY+1po+n9rTgRYogmIAWNEMzD5NDidfwxzyOxfZAQr3+MeQ+QFP70UKJKqtfh7 3FHgSBu5pnyxtdaJ2W7lpsTUfetVRqY+ErnYqXZAxatEEYfevUoaUau0LGv0FD+5ZPl6 Fkhk21rvVdDmvSEmWnasc2yg/5J3rSLYFux7arfXBOq2al5c/LX+6nz9eWIMELEzY37q rnwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728956075; x=1729560875; 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=OpMDq1IEGMMPwRojJ8i4AsUukx9XqidcnS2hx9BDF5Q=; b=d+c2yzFzihmUX3dHpYKSwa+rqwDGQyW1cVCT8N3VclgH//HXr6GpNwSin3hfmtv5Zl P2CkBl073gWsegRsxsFwSFL/i9HxNARntKvfLthtnWZ1B59koA4lv5MjQlc+LcwFXNqE SLS0I0gPZL0KMNorDRDiWtpGZcuaE0ZCIjaxiGRVylZJmx7LN/JqnTo9+mHwkZwhQ5dh sX1un8sfBZMQuHPpw7HqLrSwnqQCPMw0dEwXHqNQP2NgrPfalwEqGLnySdgrsm424HLx sx69vlfIrjfbyo+LZVO1TnfvDTXTKu0m6wx6DOllPad6WCAN0EUbTFS2ReS862Zd4i7I zttQ== X-Forwarded-Encrypted: i=1; AJvYcCUnRW+4LSHIK33d6G4xqCIyhmiTbgTgDP0SyyePxn9Ua6X1LqpqRqIuB/SRKe6JU9zGra3nAqEx4TiQycI=@vger.kernel.org X-Gm-Message-State: AOJu0YyeIK559nauMFuR85LnA9bcp+8LxcaqSy7SJi8385hZtdMdeWvf iFEGCdDsCcaaDNx6k6ll48zM55f2lIfgaOAMJbAsIOR01BmktN4M X-Google-Smtp-Source: AGHT+IElYihUi5SaCUs0c7LmxcpRmW8kQkNDCDqxwFSQ+3TwWSxwbS4zt9B7T8hR9EdwB2YanBkkig== X-Received: by 2002:a05:6a21:168e:b0:1cf:3677:1c63 with SMTP id adf61e73a8af0-1d8c95d56c3mr14328100637.25.1728956075539; Mon, 14 Oct 2024 18:34:35 -0700 (PDT) Received: from dw-tp.. ([171.76.80.151]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e77508562sm189349b3a.186.2024.10.14.18.34.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 18:34:34 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linuxppc-dev@lists.ozlabs.org Cc: kasan-dev@googlegroups.com, linux-mm@kvack.org, Marco Elver , Alexander Potapenko , Heiko Carstens , Michael Ellerman , Nicholas Piggin , Madhavan Srinivasan , Christophe Leroy , Hari Bathini , "Aneesh Kumar K . V" , Donet Tom , Pavithra Prakash , LKML , "Ritesh Harjani (IBM)" Subject: [RFC RESEND v2 10/13] book3s64/hash: Add kfence functionality Date: Tue, 15 Oct 2024 07:03:33 +0530 Message-ID: <52f01906734ece9d4f9292c252cf02e7cd267f99.1728954719.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =3D> ((1+255) * 2) << PAGE_SHIFT =3D 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/k= fence.h index f3a9476a71b3..fab124ada1c7 100644 --- a/arch/powerpc/include/asm/kfence.h +++ b/arch/powerpc/include/asm/kfence.h @@ -10,7 +10,6 @@ =20 #include #include -#include =20 #ifdef CONFIG_PPC64_ELF_ABI_V1 #define ARCH_FUNC_PREFIX "." @@ -26,10 +25,6 @@ static inline void disable_kfence(void) =20 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/book3s= 64/hash_utils.c index cffbb6499ac4..53e6f3a524eb 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 =20 #include #include @@ -66,6 +67,7 @@ #include #include #include +#include =20 #include =20 @@ -271,7 +273,7 @@ void hash__tlbiel_all(unsigned int action) WARN(1, "%s called on pre-POWER7 CPU\n", __func__); } =20 -#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 va= ddr, unsigned long idx, mmu_linear_psize, mmu_kernel_ssize, 0); } +#endif =20 +#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 =3D ppc64_rma_size / 4; =20 @@ -352,7 +356,8 @@ static inline void hash_debug_pagealloc_alloc_slots(voi= d) __func__, linear_map_hash_count, &ppc64_rma_size); } =20 -static inline void hash_debug_pagealloc_add_slot(phys_addr_t paddr, int sl= ot) +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 pag= e *page, int numpages, return 0; } =20 -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 sl= ot) {} +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 */ =20 -#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 =3D KFENCE_POOL_SIZE >> PAGE_SHIFT; + linear_map_kf_hash_slots =3D 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 =3D 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 =3D 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 =3D pgprot_val(PAGE_KERNEL); + + if (!kfence_pool) + return; + + kfence_pool_start =3D (unsigned long) __va(kfence_pool); + kfence_pool_end =3D kfence_pool_start + KFENCE_POOL_SIZE; + __kfence_pool =3D (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 =3D (unsigned long) __va(paddr); + unsigned long lmi =3D (vaddr - (unsigned long)__kfence_pool) + >> PAGE_SHIFT; + + if (!kfence_pool) + return; + BUG_ON(!is_kfence_address((void *)vaddr)); + BUG_ON(lmi >=3D linear_map_kf_hash_count); + linear_map_kf_hash_slots[lmi] =3D slot | 0x80; +} + +static int hash_kfence_map_pages(struct page *page, int numpages, int enab= le) +{ + unsigned long flags, vaddr, lmi; + int i; + + WARN_ON_ONCE(!linear_map_kf_hash_count); + local_irq_save(flags); + for (i =3D 0; i < numpages; i++, page++) { + vaddr =3D (unsigned long)page_address(page); + lmi =3D (vaddr - (unsigned long)__kfence_pool) >> PAGE_SHIFT; + + /* Ideally this should never happen */ + if (lmi >=3D 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 sl= ot) {} -#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 =3D 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 =20 /* * 'R' and 'C' update notes: @@ -559,7 +692,8 @@ int htab_bolt_mapping(unsigned long vstart, unsigned lo= ng vend, break; =20 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 =3D true; init_hpte_page_sizes(); =20 - 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 =3D pgprot_val(PAGE_KERNEL); =20 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 =3D 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); =20 /* --=20 2.46.0 From nobody Wed Nov 27 00:31:34 2024 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F7FF18BB88 for ; Tue, 15 Oct 2024 01:34:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728956082; cv=none; b=pz/mk8OE0BdvOX5NJaL8+NeIpCPL+WOTqcrt/Nc0OYOqlL7Y9RbPxNmo7yVAaPnHHjaAOJ/E6iosuLA071Jkck0pDlOQOpzMa9V6w2sQ8tpp5Kgx6QUVBrbx4AJuuuA9YbVC6tDNQ1grSAzi5g4HiyiF1B/NeDQnB4SGlE0a9LQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728956082; c=relaxed/simple; bh=fMHk4IyW0Ffe4ScDjse+ggRYbCEftOSHs3jid3aXfU4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IEW8oisHyewmLjzTOB7irwCWmu3HatGurwkezbtE4x0twNqsfMjna9etZw7n5qR2tntvCkAtvfPc/4usbj8POWs/QWIc2C98K4DzPbpWckLj4a0iZ7CTRcoYwL0DlsOa9+CKe7LwGEgcp6eNENgWeF9Iu8EnJwwmW60TG+RfrSk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JvPbvqy0; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JvPbvqy0" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-71e70c32cd7so717787b3a.1 for ; Mon, 14 Oct 2024 18:34:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728956080; x=1729560880; darn=vger.kernel.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=vbK+DyWhNFTOskVhv1fyi/tJ2PP4Ej6g6TRuPbyIjZc=; b=JvPbvqy0zbDDCf6wIolTcQdaqbSX0iGz5s5XHreqyE+VN0t6NASXf+KjndiVaLH9Oz nIThrUg/vd22n8f/85wAwOnE4FJT1AEkxfMLZwwsO7C1hnEsMTG+NFd4daIOUgfBwC9X VG2CFcKKpfwOgKK1AvKJ79oQ1OzCDat+UiAlCWeAf7fMC1S0bx+hBbyd16CbHBnG/3O1 GDvFRQa2g8k2jJi3vNj3tzsrZDLA0JRnwFoFoFCOVf1ePjaYwZEWdL1XiBFWoWF8pwaw gghRMtavYYT5f5yPRA38Y7MGIzP7OQ/MklH1MzwYe8Wahdrv5jOImmXxvclZk3xw7+ul 5kNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728956080; x=1729560880; 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=vbK+DyWhNFTOskVhv1fyi/tJ2PP4Ej6g6TRuPbyIjZc=; b=lsQ0nJKjrmrW2o9JkBwh/fFF5VrX7PpaFjN48DGkbT/OYvZlPf3Ul2SXMvU9ilm0wU kHZJ3n9Ps+yD8sPGwS6nTzKhn7EBye7Y6VLiu50312O/rKnwjx6B74BBUR7Z4ImdOXUO zYzP4ikaO+D07AbchURKtJ0bYxfcpWYd980JcVeYFPsmjk8+rtcj68Gult3I06J5ykgd TFPjBTsTVJJQZ+AhgLFYh1a1fVrIA3fTFJub1STwGivdyUmNCNcIAqK03eLwZXxU2eeZ p/hC7JDWBhv9gwDD+XkRe7wJO4/tiY4Ad+VT9kGXaTGFxhUJmab+wSYKNfHZPRs1XA7n MUog== X-Forwarded-Encrypted: i=1; AJvYcCVQTwi/fHaCZOOLvlUk4EF1V+apSuk2uJ7zwrkI8H08UpqahTK3Ymexs7FRx9lhvCvUb75dl1mhJUyPemI=@vger.kernel.org X-Gm-Message-State: AOJu0YxpIEqCA8r+dQjLkwtRmKA4gnRAIJX7jnfp6LOBAgxAg3ngvzp7 LE/CvMElkUrrswWjIhpYBKkgUp0xb0CkMpcM+gYhnQfXF5/UCA5c X-Google-Smtp-Source: AGHT+IHF1r2QtlGKVN6HtXXxcFg+k0gYJd/nSgLWyKs83ZTBLQXCdo//6FQThWun5q5jEjrAv0//bA== X-Received: by 2002:a05:6a00:189d:b0:71e:768b:700a with SMTP id d2e1a72fcca58-71e768b7107mr1328450b3a.23.1728956080395; Mon, 14 Oct 2024 18:34:40 -0700 (PDT) Received: from dw-tp.. ([171.76.80.151]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e77508562sm189349b3a.186.2024.10.14.18.34.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 18:34:39 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linuxppc-dev@lists.ozlabs.org Cc: kasan-dev@googlegroups.com, linux-mm@kvack.org, Marco Elver , Alexander Potapenko , Heiko Carstens , Michael Ellerman , Nicholas Piggin , Madhavan Srinivasan , Christophe Leroy , Hari Bathini , "Aneesh Kumar K . V" , Donet Tom , Pavithra Prakash , LKML , "Ritesh Harjani (IBM)" Subject: [RFC RESEND v2 11/13] book3s64/radix: Refactoring common kfence related functions Date: Tue, 15 Oct 2024 07:03:34 +0530 Message-ID: X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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/k= fence.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 =20 -#ifdef CONFIG_KFENCE +extern bool kfence_early_init; extern bool kfence_disabled; =20 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; +} =20 #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 5a4a75369043..374542528080 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); =20 +#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 =3D !!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/boo= k3s64/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, } =20 #ifdef CONFIG_KFENCE -static bool __ro_after_init kfence_early_init =3D !!CONFIG_KFENCE_SAMPLE_I= NTERVAL; - -static int __init parse_kfence_early_init(char *arg) -{ - int val; - - if (get_option(&arg, &val)) - kfence_early_init =3D !!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 =3D !IS_ENABLED(CONFIG_PPC_KUEP); bool disable_kuap =3D !IS_ENABLED(CONFIG_PPC_KUAP); #ifdef CONFIG_KFENCE bool __ro_after_init kfence_disabled; +bool __ro_after_init kfence_early_init =3D !!CONFIG_KFENCE_SAMPLE_INTERVAL; #endif =20 static int __init parse_nosmep(char *p) --=20 2.46.0 From nobody Wed Nov 27 00:31:34 2024 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDA9A1537DA for ; Tue, 15 Oct 2024 01:34:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728956088; cv=none; b=q1PwUQXzCVFUEB97f04Sqo1Vfgtwiq4oaTlqtaYxHtw2IYg5xHgXsx8cc2S+Xua+1bqsortqudIj2zgzDNt6gq+jQJcWLezGUNu4zjNqlCGSLR2fr2/PFldG1KpJA2NM0XBoOJSp7tXtgsyVtIPLbLbAXqGzZx3BzDteP24DUXk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728956088; c=relaxed/simple; bh=rKAkwnrKqFe/pXWHE++1cg7Hf02Exo4/eTPzv1Uabug=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g+g8HHH3tu22ETseyjrRKoJFwpRCwUc62MIRJjPBYofuV8dtyQWS8LXmcb4LGZ7Q5ziiTDo7A0wTY8EmuwV+PT2dJSekTbGerO+uVeHxavns2bELaOnNNbFhukyfUtJZq6is86ydphNXF2ISeXF+2T2GFKaD7RYjX9feP1cjQss= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TESLRL/0; arc=none smtp.client-ip=209.85.210.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TESLRL/0" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-71e6f085715so926890b3a.2 for ; Mon, 14 Oct 2024 18:34:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728956085; x=1729560885; darn=vger.kernel.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=t5daj1tikBz1GmvjDxbc2gCsvgSNJoz/zYutj+6dtSk=; b=TESLRL/0/Cqie+7c69JbbhqzWUYy2Jftn8sBSvAcG1bxAFM9lxGEMACVOREzG6OyLG Nc8CGSa0DUqM/smGNeo/61tBaWxXEY4jHiFs4JhNWI9k1fD/KUANi8QwazHpcyjAgow9 JXRE3HBLaatOfG5oCF4+qEZA7e960JuCT+PsJbBXMPUwXpsf4cpC6xreeBqICtwJ9+tn l6S2f+lQjDaRr8P57y3YvUrMIy81JQ3GLnJeKxHiVvEbtOPMFHLKpZdOnBsBRo7yd49k qrGadZ0ei8oJX3GD25s/k7UFhhTBKRLtH+2+hqioIC+csz0iHRNHFbPn656byA1SHeuq lBfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728956085; x=1729560885; 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=t5daj1tikBz1GmvjDxbc2gCsvgSNJoz/zYutj+6dtSk=; b=YIX3j4JPz0JZ4v5SyIlXch3jsX7QUr5a21ZmkrKFYXHIY6/VTZBnoRU8c8+xqr+5JX H3ScV8bQWymR1i8gpdYmWb9IYWuQeFczjzMHzQIISK3AjV2nkeKCneXXqhVnNGOTD8tz 9CmZFohPZzyPG5xQvCjdUXDBWlD6nBqa9XWjHU0GgimK9wyZ5yFdIdm1a0CPQBhXhYpZ TxakcOC6s/sFTyb8s6gdEWfo4cq871uw2Dh2vVDgXiBYw5BnKPkvDyd2er64QL22qsVt QylswszYN6gUCoxociz1rSKkrV6EmnHmVi94tnwW7bDMn9EsdIgH7KEuxh5S5Cep4Xoe A6uQ== X-Forwarded-Encrypted: i=1; AJvYcCWCag0jiFj0hnM6SwNPF5Zpu2/Dfqqap9AC2xmcGTLs37M1yDeugMRM8n618n/e9LexWC9wW8v0s0oTEHM=@vger.kernel.org X-Gm-Message-State: AOJu0YzwoyWGUuqcg3xtUxJMvTV3CrcLbUpbL+KRkg7vF0lOrC7FmqK5 inwr47K2k5+8xt3VL2ZYMnJ+Hfy7LVRv1bT/V6lAs6KXTlNAe0Cy X-Google-Smtp-Source: AGHT+IEs2IxrBsPT6YXEgz2epQyHoorcOdT0d4hm7NYr74rGWRI5/0uchu7H7p2tlDXCJav5W/E8eg== X-Received: by 2002:a05:6a00:3e03:b0:71e:3eed:95c9 with SMTP id d2e1a72fcca58-71e4c1bfba9mr15531178b3a.22.1728956085196; Mon, 14 Oct 2024 18:34:45 -0700 (PDT) Received: from dw-tp.. ([171.76.80.151]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e77508562sm189349b3a.186.2024.10.14.18.34.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 18:34:44 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linuxppc-dev@lists.ozlabs.org Cc: kasan-dev@googlegroups.com, linux-mm@kvack.org, Marco Elver , Alexander Potapenko , Heiko Carstens , Michael Ellerman , Nicholas Piggin , Madhavan Srinivasan , Christophe Leroy , Hari Bathini , "Aneesh Kumar K . V" , Donet Tom , Pavithra Prakash , LKML , "Ritesh Harjani (IBM)" Subject: [RFC RESEND v2 12/13] book3s64/hash: Disable kfence if not early init Date: Tue, 15 Oct 2024 07:03:35 +0530 Message-ID: <29cca55915a923d1823644b37fa571234f9ea549.1728954719.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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/book3s= 64/hash_utils.c index 53e6f3a524eb..b6da25719e37 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; =20 static inline void hash_kfence_alloc_pool(void) { + if (!kfence_early_init_enabled()) + goto err; =20 // allocate linear map for kfence within RMA region linear_map_kf_hash_count =3D KFENCE_POOL_SIZE >> PAGE_SHIFT; @@ -1074,7 +1076,7 @@ static void __init htab_init_page_sizes(void) bool aligned =3D true; init_hpte_page_sizes(); =20 - 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 --=20 2.46.0 From nobody Wed Nov 27 00:31:34 2024 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1B641A76D0 for ; Tue, 15 Oct 2024 01:34:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728956092; cv=none; b=AKS4kyolwYzbYgvExhfMbF3GrMa4UmsF09ifu+5jFgQwD8xg1pb7vpX1VsaQe5AloHpALt62QGoRm1KxUhXKsp7R7LJLjK0aswtsv8d/fICL8TWp4dcSVPtVwTsnba16BI14QFNuhJDGDHa5DHXICILIDtmmGo5plBZtrW2kqTk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728956092; c=relaxed/simple; bh=7LTcZT2HWVkqoSPK4x+UBfyzXYZc0lzBW4tVD7tCB10=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JcK8RvwyCOJEsmt7/hX0szCIKfaNn020Z765raooesQ0ZdQmwrkozEucOAO3e2wlATmbUCR4I4H02GpYmnzGctp3jJi1jVZ1ctWEMoRQ1Rti3VqJ0Amp+ULh/wafah2/dMz7YY/GnsDPP64gNgWn+Eb+14HJA/QvbvcM42T0ZDY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kzd7Oni3; arc=none smtp.client-ip=209.85.210.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kzd7Oni3" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-71e70c32cd7so717913b3a.1 for ; Mon, 14 Oct 2024 18:34:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728956090; x=1729560890; darn=vger.kernel.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=rG0rlJ7RpNnGy840avhtCY+OIP6FbV4qxEoUkbOoVC0=; b=kzd7Oni3JqDs0G0pjwqbI+r8IysOZyhMVkyyRIE28F/6BK6AKT8JZS+leVYZG7PyC6 RErhU54XohIEY2IzlR2rGGsXDwuYS9L5m6I7e1052QzqKqi0r4r0ukNrTBhDvAPM9ut8 Q/apGn3qKOPUZnm+DPuzwHDIvJpuwxryqCi1Sypz0G7JwPuXXMCMmMrRenj2N/yIahKd Ln+gTuSCm+/StEWF75j1UiQcGXi20KiTnTBpM8hYEDbc+L3T3RIWpwSgSu461ycERaeK BXGgad+mUyCVOvjixe70NdXTmOvTv794DLoiPVUi+wycxlcK++hEafQ78dsTy6R1af/A l0cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728956090; x=1729560890; 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=rG0rlJ7RpNnGy840avhtCY+OIP6FbV4qxEoUkbOoVC0=; b=R1ADbPchIwqjCcsa372IMcov8tms1fL62GRj+2lWf/ZM93YahQCeOCkxDzTPnwy+pX BzcCkpBCKmSus14yXhV8nWEKHNbQJMO4X8wT0TIDB0EN0xw7d1jBuR4SX0wclcrwX5Y0 mL7UMi5ZyVXGgbqXZXrBx+vjRsPx9/x2iCY0gejJY7zlQ755SNzF+YJZ0ozCDlQy0S5T prbAQuDcwyFUuVmokKiKCCMYXJhf6LOfATf1Hp2Xf8/S8MbnH1LgXg9xGjiKVRlb2Qmx nQ3KGx4bsITcLcLSpz/awIxnT/bvb5XkLKgQMw2U4D4vBpmpwlHpGjDlCv0wKdhgXiMI Xubw== X-Forwarded-Encrypted: i=1; AJvYcCVRFIgTqjYgg36kltw799cym747vGiwPN+sBxWsoOixZtZATA7UlNhRQJ9NncFVfyveD3BzI+K02+0KZ4A=@vger.kernel.org X-Gm-Message-State: AOJu0YxzKesgXAdbnfGt2vOPHGmmGpeETxc+aVMLkQm/dlMsYxB+9tL6 qMTFrqFBP8oneUwotGS8+j8XU8NWdLptx8GbyKOTyJu0aoSaiZlf X-Google-Smtp-Source: AGHT+IFvESYA3zS1GBFZJxbiWhM237fiGLHeDy47xUMjk/AhsGWJAlSSfmCDieCeQukhtrPpShvuWQ== X-Received: by 2002:a05:6a00:1404:b0:71e:5033:c5 with SMTP id d2e1a72fcca58-71e50330377mr13492824b3a.14.1728956090001; Mon, 14 Oct 2024 18:34:50 -0700 (PDT) Received: from dw-tp.. ([171.76.80.151]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e77508562sm189349b3a.186.2024.10.14.18.34.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 18:34:49 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linuxppc-dev@lists.ozlabs.org Cc: kasan-dev@googlegroups.com, linux-mm@kvack.org, Marco Elver , Alexander Potapenko , Heiko Carstens , Michael Ellerman , Nicholas Piggin , Madhavan Srinivasan , Christophe Leroy , Hari Bathini , "Aneesh Kumar K . V" , Donet Tom , Pavithra Prakash , LKML , "Ritesh Harjani (IBM)" Subject: [RFC RESEND v2 13/13] book3s64/hash: Early detect debug_pagealloc size requirement Date: Tue, 15 Oct 2024 07:03:36 +0530 Message-ID: <6b5deb16494e80703577e20fbb150789c83076a9.1728954719.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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/book3s= 64/hash_utils.c index b6da25719e37..3ffc98b3deb1 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 va= ddr, unsigned long idx, } #endif =20 +static inline bool hash_supports_debug_pagealloc(void) +{ + unsigned long max_hash_count =3D ppc64_rma_size / 4; + unsigned long linear_map_count =3D 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 =3D ppc64_rma_size / 4; - - if (!debug_pagealloc_enabled()) - return; - linear_map_hash_count =3D 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 =3D 0; + if (!hash_supports_debug_pagealloc()) return; - } =20 + linear_map_hash_count =3D memblock_end_of_DRAM() >> PAGE_SHIFT; linear_map_hash_slots =3D 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 =3D true; init_hpte_page_sizes(); =20 - 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 --=20 2.46.0