From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f176.google.com (mail-yw1-f176.google.com [209.85.128.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 81349274FF5 for ; Mon, 24 Nov 2025 22:54:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764024853; cv=none; b=PAsWowJOBpMADEE0odj265MC+JmUwnCXcab9KbLeFq9O6YbaGeR/DHI/YukIPDtrlmdQPQYNvXX69y4/gx1TjG6kBAptEKZ5+hE9Jw9MUMT3GK/FJ4vJKdqQ4BO8lIRovHomU/WCSGjG/3pEIxTznnTMjRAIKPWNMqgGCBpbqV0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764024853; c=relaxed/simple; bh=pIWqXRM7mw32jjJFWrRxVUh61jU+ZO2Ij4k6YDDb7vc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ivZ7AK/FU8fhbzIHv6TsOJCkwTXsh/UUn8Oov7uhQXdS+J1W8jZCeeGgMaD0dQggWFqdAl37Eghp0PjLLxqBhQF5Pjt3JBXn4DyH6ZjPUE/mau916+8D1cZOjDcJCQy4UM5vhL7HF5b8nnsnEBX9IghHgfhiGhhzIbieLTPJ/Rc= 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=SlWkpZHs; arc=none smtp.client-ip=209.85.128.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="SlWkpZHs" Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-78a7af9fe4fso50532187b3.2 for ; Mon, 24 Nov 2025 14:54:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764024850; x=1764629650; 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=OkPGFrQcQy83MwqnxJzEu9f7EPjZBBQnl/KZG5BmF+o=; b=SlWkpZHspGZkraMUzsW1sCLPWEr/brxUWFis2rExPJ54o/Re8eQBXLk6OB3evaAlI+ /Bc39gtpGVaP4dqZ0bl/mvoSTSlobYUPPRBC2yswDXDEELWOOPoWyZK2ODZc2rSqIPE2 X5fSalZUiPaIff2rycEJFslfSUYXW9DiDdulO3C5LNg/mC+40vaKlZsekHrl1pqvl3jw ptuWq67C1uCw7zLKxpkWSW0sGUCKVCLW17iSrafpJyFGSrmyfx6OB8bXc1s9OIF9snpB xnQ8YkR1/JNvmzvzF2R1GERppzhKWH3XifVDS/y7KekWkqyHvQYsVUB6utDr0xVrmmvI I1JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764024850; x=1764629650; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=OkPGFrQcQy83MwqnxJzEu9f7EPjZBBQnl/KZG5BmF+o=; b=NN7PCiWbwsjm7s52rje71pmmJANyqmynk6COorLlVhn6lagAMEQWAsygzv8rLFNllN 9OW3CEl3l7cn9jKGz33XMoc01T+IVK8kJ/RN8WNdzL8hn80h6HepdVivogR63ybhoKV0 ZB/gWxv1anWDowcATHZLXgH+b6NoKNtsHStjdmlwbPYrZFj448rL6rEkPOoGGoAjAqFT YSv+1uHTBxqtU85fEfYkXqDsJtt0+XkhcM5NGZNz0Ww6Po4uSUKu0oheYLQLqiDzw4fK +Soj/3jDH5amO9Iark4CO4QilvXwaAByUiAEmxpVLVdW4m1gZhaptO9xBl4Ycj643+ja uHAg== X-Forwarded-Encrypted: i=1; AJvYcCWW1SK5V1GLYhFW2WTuomaHubfDKCjjcAYXqeMBeDe4+ubloZEdYojEghEtMDbDD9jbrAnK0n60g4VaIC4=@vger.kernel.org X-Gm-Message-State: AOJu0YxX/qeK1FonReoe56rNw6bMndorZk0RBORYXg0/TgCpkZG2C46p QT/mub0NpiJznc61/TtbFBypuLJL0OMCxrKCYhd9MK8cI/US+qIcwj0u/9u2Zg== X-Gm-Gg: ASbGnctlzWqoDsQQx+Rr39GbfDY2LdzRQL9J7zy4mTFIskkmlslWEw4T635TdGj0lqN QemEaxb8bg194TBh/vvHQObpV2BNiCec5EjvM5XoJ3t/KGQastFD8leZVjP2XvAvfvxfCetcKls il9rzSf+Ak5fRb+GzLqYASXXHhOF6rACtsiiZMJRgWl9TRo7OJmQHVvHGklWfiqGpSlsoOC3V62 Ibqp9yLg9OBXBcQMRrh8fnWEX0B68Adlzv7tD5twvwQzh+onUoZJQ8d0iJ9VcCbuYexSV7g7zBe 6cGyEe8OsuqxE2wpsxAlEB6pwzVv+YWm422SbC5xPnX36FO7ZMcULlI9N0/1CuhNu6Nsqt/AXTH zsJT/qokH5ym/FvjbE9gGYE32Q9tysYIun64lDByHHWojpAKj1y/kw+L6+T/z3rEtponrPqgijg lEVXPXMM3EYyTVn4pKz+L9TA== X-Google-Smtp-Source: AGHT+IHQu+hk6/+e2su2tG4hNtS2lfQylKwKpETUyCBrjxURSXX4V7f1ntb4sZE/boplQjM8SDZYOw== X-Received: by 2002:a05:690e:168d:b0:63f:b5d8:9da9 with SMTP id 956f58d0204a3-64302a2f963mr9451894d50.12.1764024850286; Mon, 24 Nov 2025 14:54:10 -0800 (PST) Received: from localhost ([2a03:2880:25ff:53::]) by smtp.gmail.com with ESMTPSA id 00721157ae682-78a799278a3sm49039097b3.27.2025.11.24.14.54.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Nov 2025 14:54:09 -0800 (PST) From: Joshua Hahn To: Andrew Morton Cc: Vlastimil Babka , Mike Rapoport , linux-kernel@vger.kernel.org, linux-mm@kvack.org, kernel-team@meta.com Subject: [PATCH v2 2/2] mm/mm_init: decouple page checking and init_on_{alloc, free} Date: Mon, 24 Nov 2025 14:54:07 -0800 Message-ID: <20251124225408.2243564-2-joshua.hahnjy@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251124225408.2243564-1-joshua.hahnjy@gmail.com> References: <20251124225408.2243564-1-joshua.hahnjy@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit init_on_alloc and init_on_free protect the kernel by initializing allocated and freed pages to 0 on allocation time / deletion. Commit 700d2e9a36b93601270c1e15550acde2521386c5 ("mm, page_alloc: reduce page alloc/free sanity checks") removed page checking from hot pcp drain and refill paths, and instead coupled it with CONFIG_DEBUG_VM, debug_pagealloc, page poisoning, and init_on_{alloc, free}. As the commit suggests, the first three turn the kernel into a debug kernel, while the last hardens the kernel against leaking sensitive memory. While enabling page checking is relatively low-cost and tying it together with page initialization is not unreasonable, it does feel like a bit of a side-effect, rather than an obvious consequence. With page checking now pulled out as a boot time parameter that can be set independently, let's decouple page checking and init_on_alloc and init_on_free. As a direct side effect, systems that have init_on_alloc or init_on_free will no longer have page checking enabled by default; they will either have to pass the check_pages boot parameter, build the kernel with CONFIG_DEBUG_VM, or enable debug_pagealloc / page poisoning. Suggested-by: Vlastimil Babka Signed-off-by: Joshua Hahn --- mm/mm_init.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/mm/mm_init.c b/mm/mm_init.c index 01d46efc42b4..59636d2c0178 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -2566,19 +2566,15 @@ static void __init mem_debugging_and_hardening_init(void) _init_on_free_enabled_early = false; } - if (_init_on_alloc_enabled_early) { - want_check_pages = true; + if (_init_on_alloc_enabled_early) static_branch_enable(&init_on_alloc); - } else { + else static_branch_disable(&init_on_alloc); - } - if (_init_on_free_enabled_early) { - want_check_pages = true; + if (_init_on_free_enabled_early) static_branch_enable(&init_on_free); - } else { + else static_branch_disable(&init_on_free); - } if (IS_ENABLED(CONFIG_KMSAN) && (_init_on_alloc_enabled_early || _init_on_free_enabled_early)) -- 2.47.3