From patchwork Sun Sep 11 09:59:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12972822 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16C0CC6FA8A for ; Sun, 11 Sep 2022 09:59:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C896F8000C; Sun, 11 Sep 2022 05:59:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C0FB480008; Sun, 11 Sep 2022 05:59:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A894B8000C; Sun, 11 Sep 2022 05:59:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 943E580008 for ; Sun, 11 Sep 2022 05:59:31 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 67919A04E5 for ; Sun, 11 Sep 2022 09:59:31 +0000 (UTC) X-FDA: 79899357342.21.B0F3216 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) by imf18.hostedemail.com (Postfix) with ESMTP id 1B1B11C0084 for ; Sun, 11 Sep 2022 09:59:30 +0000 (UTC) Received: by mail-qk1-f178.google.com with SMTP id c19so2318931qkm.7 for ; Sun, 11 Sep 2022 02:59:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=IQgFAlcZ+zBw786vdsFczK8VrNHApPya6ZC6RPMkUdg=; b=B7B7pHbZ63+sPWwS2bD6YT1SStvX81UMer7JZxmb2Y5zl//fOZKSJe6QQrlxj4unjc WDxlNFc81O6KKYWX+3kHXoCbwgrnTNTHrGPYF/Gy9N2yadEqTjxSGmHf6kXGCKYQSWsf i4szN97Ry6b/Sp93I9coUyReS67tuLpesPv72OwqzThS4Z7UjkNZaqZ+lGko554zcfcr jMbMa0KbUB9TSqD9EkFodoHDAkeUypmhY4mRkP+TAvo28yxDtecBCwbKDDLMp/eo7EFz g36jyaTCaEVtCX8w4/C+5f1Y+v4pabrpWeWxLiP4KAvAF6WYqDwwQIXjtUOrqRHZQlRZ r4RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=IQgFAlcZ+zBw786vdsFczK8VrNHApPya6ZC6RPMkUdg=; b=hxEOkW/LEfK81mhlY/MOj+DGjul8zmtTHzk1dFwCaqXq/AwfAWMMhvLOX3LHkIcyY7 91VXS/k/3s6ozoWmzjROuR+9ZLgONQXyZIXueqVsrvXt9iqZHssqMehhbB/zz0meq35k 3yG7Kaq1foRYPlwbUgdcBileIoFPBVRBdra6M99Ygh5v1U5uIb5zFa+pvFPDHfIbf9kn pnPKhhlvbJ4yzjoHl+Mwpn/zNvZtVupKk5RnaCx8EiX6u6DkgyBsrm2tqyKJCE0EbpC1 uwfSmD4q2DXZChGB3awYNEZCguHgfo7FszED1607kFhnzERF1e1b4F1xDFPAEGLltsc7 /xcQ== X-Gm-Message-State: ACgBeo12b4IWyrJJNYmDCTOS/1ME+eacdS9pyCzbNPk0cX4CIvcLhMSt Ky6jU5NtuIUqmcW2jn9gbocC4g== X-Google-Smtp-Source: AA6agR5DcmR8o9JAtmJ/2eIiSKRUYqewIiL/dNKxjys5qnEA0ST4IsGWy6xsrwjMK/lKCFbJNdD3zg== X-Received: by 2002:a05:620a:278d:b0:6bb:1435:c0bd with SMTP id g13-20020a05620a278d00b006bb1435c0bdmr15648933qkp.291.1662890370397; Sun, 11 Sep 2022 02:59:30 -0700 (PDT) Received: from soleen.c.googlers.com.com (240.157.150.34.bc.googleusercontent.com. [34.150.157.240]) by smtp.gmail.com with ESMTPSA id y29-20020a37f61d000000b006cbd60c14c9sm4625233qkj.35.2022.09.11.02.59.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Sep 2022 02:59:29 -0700 (PDT) From: Pasha Tatashin 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 Message-Id: <20220911095923.3614387-3-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog In-Reply-To: <20220911095923.3614387-1-pasha.tatashin@soleen.com> References: <20220911095923.3614387-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=B7B7pHbZ; spf=pass (imf18.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.178 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662890371; a=rsa-sha256; cv=none; b=QMDe0q99iG6isN0OixYeDAryOVT/Cd9TWIQFP0usn7Ta2TjELvu+3IB/J9zd9bdj8hUfYS Nic9ek8CFAmHqw75KMzHwqLmym2POboyrKAbHMeGmEkXfsuleU/yiyDKW+1QElcuQkbaFG CcygvMyRswo0n7K9xtBAMnqtrmch9I0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662890371; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=IQgFAlcZ+zBw786vdsFczK8VrNHApPya6ZC6RPMkUdg=; b=lifoE6UyFa8hLOFNRfb/Sk+Rwh2gv+xlh9Wn9ROUq0fhSfNzDW8wXOSq2Mlr2loZIRaqlW MWw1Y3pksS5zi9q8jT7RCwPXCp9alWMFFrAq3MHIDExBYHxchpnLi1FuKa7CCNN7IkV/+c Dz8LPWX/tJjpI7n2UdAfPl8ZUdICy8k= X-Stat-Signature: qb64r3gipjr6ddj1fm5346nhmreimb3o X-Rspam-User: Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=B7B7pHbZ; spf=pass (imf18.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.178 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 1B1B11C0084 X-HE-Tag: 1662890370-22124 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 --- 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); } }