From: Pasha Tatashin <pasha.tatashin@soleen.com>
To: pasha.tatashin@soleen.com, akpm@linux-foundation.org,
corbet@lwn.net, linux-mm@kvack.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org, rick.p.edgecombe@intel.com
Subject: [PATCH 2/3] mm/page_table_check: Do WARN_ON instead of BUG_ON by default
Date: Sun, 11 Sep 2022 09:59:22 +0000 [thread overview]
Message-ID: <20220911095923.3614387-3-pasha.tatashin@soleen.com> (raw)
In-Reply-To: <20220911095923.3614387-1-pasha.tatashin@soleen.com>
Currently, page_table_check when detects errors panics kernel. Instead,
print a warning, and panic only when specifically requested via kernel
parameter:
page_table_check=panic
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
mm/page_table_check.c | 53 +++++++++++++++++++++++++++++++------------
1 file changed, 39 insertions(+), 14 deletions(-)
diff --git a/mm/page_table_check.c b/mm/page_table_check.c
index 665ece0d55d4..881f19d0714c 100644
--- a/mm/page_table_check.c
+++ b/mm/page_table_check.c
@@ -17,13 +17,37 @@ struct page_table_check {
static bool __page_table_check_enabled __initdata =
IS_ENABLED(CONFIG_PAGE_TABLE_CHECK_ENFORCED);
+static bool __page_table_check_panic;
DEFINE_STATIC_KEY_TRUE(page_table_check_disabled);
EXPORT_SYMBOL(page_table_check_disabled);
+#define PAGE_TABLE_CHECK_BUG(v) \
+ do { \
+ bool __bug = !!(v); \
+ \
+ if (__page_table_check_panic) \
+ BUG_ON(__bug); \
+ else if (WARN_ON_ONCE(__bug)) \
+ static_branch_enable(&page_table_check_disabled); \
+ } while (false)
+
static int __init early_page_table_check_param(char *buf)
{
- return strtobool(buf, &__page_table_check_enabled);
+ int rc = strtobool(buf, &__page_table_check_enabled);
+
+ if (rc) {
+ if (!strcmp(buf, "panic")) {
+ __page_table_check_enabled = true;
+ __page_table_check_panic = true;
+ rc = 0;
+ }
+ }
+
+ if (rc)
+ pr_warn("Invalid option string: '%s'\n", buf);
+
+ return rc;
}
early_param("page_table_check", early_page_table_check_param);
@@ -48,7 +72,8 @@ struct page_ext_operations page_table_check_ops = {
static struct page_table_check *get_page_table_check(struct page_ext *page_ext)
{
- BUG_ON(!page_ext);
+ PAGE_TABLE_CHECK_BUG(!page_ext);
+
return (void *)(page_ext) + page_table_check_ops.offset;
}
@@ -75,11 +100,11 @@ static void page_table_check_clear(struct mm_struct *mm, unsigned long addr,
struct page_table_check *ptc = get_page_table_check(page_ext);
if (anon) {
- BUG_ON(atomic_read(&ptc->file_map_count));
- BUG_ON(atomic_dec_return(&ptc->anon_map_count) < 0);
+ PAGE_TABLE_CHECK_BUG(atomic_read(&ptc->file_map_count));
+ PAGE_TABLE_CHECK_BUG(atomic_dec_return(&ptc->anon_map_count) < 0);
} else {
- BUG_ON(atomic_read(&ptc->anon_map_count));
- BUG_ON(atomic_dec_return(&ptc->file_map_count) < 0);
+ PAGE_TABLE_CHECK_BUG(atomic_read(&ptc->anon_map_count));
+ PAGE_TABLE_CHECK_BUG(atomic_dec_return(&ptc->file_map_count) < 0);
}
page_ext = page_ext_next(page_ext);
}
@@ -102,7 +127,7 @@ static void page_table_check_set(struct mm_struct *mm, unsigned long addr,
if (!pfn_valid(pfn))
return;
- BUG_ON(is_zero_pfn(pfn) && rw);
+ PAGE_TABLE_CHECK_BUG(!is_zero_pfn(pfn) && rw);
page = pfn_to_page(pfn);
page_ext = lookup_page_ext(page);
@@ -112,11 +137,11 @@ static void page_table_check_set(struct mm_struct *mm, unsigned long addr,
struct page_table_check *ptc = get_page_table_check(page_ext);
if (anon) {
- BUG_ON(atomic_read(&ptc->file_map_count));
- BUG_ON(atomic_inc_return(&ptc->anon_map_count) > 1 && rw);
+ PAGE_TABLE_CHECK_BUG(atomic_read(&ptc->file_map_count));
+ PAGE_TABLE_CHECK_BUG(atomic_inc_return(&ptc->anon_map_count) > 1 && rw);
} else {
- BUG_ON(atomic_read(&ptc->anon_map_count));
- BUG_ON(atomic_inc_return(&ptc->file_map_count) < 0);
+ PAGE_TABLE_CHECK_BUG(atomic_read(&ptc->anon_map_count));
+ PAGE_TABLE_CHECK_BUG(atomic_inc_return(&ptc->file_map_count) < 0);
}
page_ext = page_ext_next(page_ext);
}
@@ -131,12 +156,12 @@ void __page_table_check_zero(struct page *page, unsigned int order)
struct page_ext *page_ext = lookup_page_ext(page);
unsigned long i;
- BUG_ON(!page_ext);
+ PAGE_TABLE_CHECK_BUG(!page_ext);
for (i = 0; i < (1ul << order); i++) {
struct page_table_check *ptc = get_page_table_check(page_ext);
- BUG_ON(atomic_read(&ptc->anon_map_count));
- BUG_ON(atomic_read(&ptc->file_map_count));
+ PAGE_TABLE_CHECK_BUG(atomic_read(&ptc->anon_map_count));
+ PAGE_TABLE_CHECK_BUG(atomic_read(&ptc->file_map_count));
page_ext = page_ext_next(page_ext);
}
}
--
2.37.2.789.g6183377224-goog
next prev parent reply other threads:[~2022-09-11 9:59 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-11 9:59 [PATCH 0/3] page table check default to warn instead of panic Pasha Tatashin
2022-09-11 9:59 ` [PATCH 1/3] mm/page_table_check: Check writable zero page in page table check Pasha Tatashin
2022-09-12 15:58 ` Edgecombe, Rick P
2022-09-26 8:26 ` David Hildenbrand
2022-09-11 9:59 ` Pasha Tatashin [this message]
2022-09-11 16:08 ` [PATCH 2/3] mm/page_table_check: Do WARN_ON instead of BUG_ON by default Matthew Wilcox
2022-09-11 20:42 ` Pasha Tatashin
2022-09-26 8:28 ` David Hildenbrand
2022-09-26 1:16 ` [mm/page_table_check] 6e807506f4: WARNING:at_mm/page_table_check.c:#page_table_check_set kernel test robot
2022-09-11 9:59 ` [PATCH 3/3] doc/vm: add information about page_table_check=panic Pasha Tatashin
2022-09-12 20:23 ` [PATCH 0/3] page table check default to warn instead of panic Andrew Morton
2022-09-20 18:11 ` Pasha Tatashin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220911095923.3614387-3-pasha.tatashin@soleen.com \
--to=pasha.tatashin@soleen.com \
--cc=akpm@linux-foundation.org \
--cc=corbet@lwn.net \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rick.p.edgecombe@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox