From patchwork Sat Jul 22 23:15:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13323058 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 8563FC41513 for ; Sat, 22 Jul 2023 23:15:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 837BD6B0072; Sat, 22 Jul 2023 19:15:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7BF0C6B0074; Sat, 22 Jul 2023 19:15:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 649C06B0075; Sat, 22 Jul 2023 19:15:18 -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 441636B0072 for ; Sat, 22 Jul 2023 19:15:18 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 0CD8180672 for ; Sat, 22 Jul 2023 23:15:18 +0000 (UTC) X-FDA: 81040805916.10.996937D Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) by imf17.hostedemail.com (Postfix) with ESMTP id 2D6314000E for ; Sat, 22 Jul 2023 23:15:15 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b="bY/thvLc"; dmarc=none; spf=pass (imf17.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.182 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690067716; 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=Dz1WtFDUN503GFfPrb86//foDSemE6Fx12xrK89H/vw=; b=hjvIf0bYqKU/6Q4WovbYkq2umHIZgD81NfkeIFrfLQX2cHS/3N1NT+1qhQDt7Bq4PUFJYG Ei+N7Ok9K8g7G+ErRtoOC00zLtMJ7i2tKrPrZ70FPMrk0rBqEn5gvruTsdQxyzJAjlyNTH gZDU8psEW2qbZSP2k4AxbuFMIFdq75I= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b="bY/thvLc"; dmarc=none; spf=pass (imf17.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.182 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690067716; a=rsa-sha256; cv=none; b=PLIXlnBBikru6k0amYnrBZrhSzgCidYAG4VfY48LLZ2KDM4GJXPfeBzHkfBQxBHHaSi6Fx nRAKkemTwp3mmRbHzo7B+LdVXX4+xCDP/7gx7qwZ8W6/BRX5iVk1Ivsgdqy5AucOyXUAhP mIkPOs2pcUCM5WXxWs/4Hp6RyOU6W9w= Received: by mail-qk1-f182.google.com with SMTP id af79cd13be357-7679ea01e16so289751585a.2 for ; Sat, 22 Jul 2023 16:15:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1690067715; x=1690672515; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Dz1WtFDUN503GFfPrb86//foDSemE6Fx12xrK89H/vw=; b=bY/thvLcgkc1kW1AiaCtDdgCl0GfMZRm3ZXHre3bwwItwa2QFP+rNHHQro/QmoOQff SI+ax91vPJVjZuEexwJ+NcNiJvh4ZD341RywPTp5zViX/QpyMlKvE3BatWDge2b9aXYf XRzErIo70NKB3/0lov6evFqbdQDftwlrF7WGfTt7v1ErLh86yDMTI1f/NmNREfl6eeu9 JT2qhvs7omUMVpT19OxD5mhUoM7yVse9sNIt+segHAFkLEZSDmqFDZIBfzvQJAbRxmEO dHiDwjGBelZXtngdm3adx169KFbtYBzX1XRUx1NX2rbo7fGIjG9wank6BOnumMU7frS0 bjlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690067715; x=1690672515; 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:message-id:reply-to; bh=Dz1WtFDUN503GFfPrb86//foDSemE6Fx12xrK89H/vw=; b=iZAP5j6Qz4SYrkJlufM4l8MhEWRyGTUFzmDJo9e+l64LiIn5bvpmTaIZTwCvd2lORH qhBd/SYhuRlEVwWEqog/izhtvZYtTdBLhiNb02mCgPRcXfWN7SRoQQEA9Uzt4KDtjV+F 1k1RgwZbu3M3F41FzpGBzXYFLVjqfnmDRHaRyZiNGEXyl8/eUA6qxYVnl+zlIcITrrE+ k9q/oW13Dnl2/KeTjT7YKXDa6A4LPYBEVz+wN0AHFDy1kWv+cXnItu0J1dUW9k80Vd3a YN4UD6prWpfZimxwYoovYzBUNGBmIhjygg1R0xK9i2FcVo+CtkXoIVjaEdztG2qqUp8h Kj1Q== X-Gm-Message-State: ABy/qLYsoYRUodwdZZhlt+cHp58arhkwEDfBjGWH1MIoF89saCfIN6cn JI346g2H7Q01xhpt7aWWszW5YA== X-Google-Smtp-Source: APBJJlHl+ww4l/5L3aVaKf+nyHJSNfnHmrmG6yrGFh/lnSNpYxDd9Cn/A23HI9OTbXjjHyktI1V6bQ== X-Received: by 2002:a05:620a:158f:b0:767:e27d:99fe with SMTP id d15-20020a05620a158f00b00767e27d99femr3915518qkk.29.1690067715304; Sat, 22 Jul 2023 16:15:15 -0700 (PDT) Received: from soleen.c.googlers.com.com (193.132.150.34.bc.googleusercontent.com. [34.150.132.193]) by smtp.gmail.com with ESMTPSA id u21-20020ae9c015000000b007675c4b530fsm2075957qkk.28.2023.07.22.16.15.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Jul 2023 16:15:14 -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 v2 1/3] mm/page_table_check: Do WARN_ON instead of BUG_ON Date: Sat, 22 Jul 2023 23:15:06 +0000 Message-ID: <20230722231508.1030269-2-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog In-Reply-To: <20230722231508.1030269-1-pasha.tatashin@soleen.com> References: <20230722231508.1030269-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 2D6314000E X-Stat-Signature: pcgmo38fsg8kp441hksybe6jmhfy4sco X-HE-Tag: 1690067715-34716 X-HE-Meta: U2FsdGVkX1/u9f07LMQWTkfOKG71o1vAYW7As0BIa3FUuB4r/vyIg+qgyFODJTQHoMZ9HnGR7MMIzUpfjaayvJrkn+q18JzYNA9fd7lih6VgAihiAGBGq6Zy4Zuzq/dkP7saQhE33Fa+QbnoKWwlKUAmrI8U7JhA65Kbx0G/YwM9nppR3gfNsmon9jxfPXOXhJlXDh7LYFz9d8/BSL9OvR0LAvtuF5SGA7b6jNMudzojqiJG2lhfeAL9gqgbts98S41oTYRVF6FQgAhu69tsjyGT90NXrtO0B4lTiK1jxUCUXgMMFd2HkU6sdmFd+0tA3qHVYUHmf+ZJtfOV7bawHra5Lp/NZa083gqbHYWAi66PpyQKLDpGoti235hgohb9+SHDhUbE3y6JjR1oyK3KRdSHJYUdhpZKgWdWX9FCcPIIonpD1oRZFcKoiG35zD+x7xTnh6uwmdTfNERE+J0nsNStEHMFIcqWcVDQEjEsFkxNoO+mm8xQWpYR894H/Kl4G79R128atxYJ5GKisTkOCAnHCvlh4caVu0Vzt9+hAu1dNe/mV67IhEAGkGKjxK8/mLuaeVbMmjZq5rz5I16X9VnjH63d/mRKWw5t2U5fxIAi8mCzcSV7fJ9f5C990BbDhSrw96K+mDgHkblpxkwJ/nBVvD5oJluBluLzYl10zB4Z1WwJX55rgZCquifm0UN3cK+EQ3VVIF/PTaxLqSul/n1B01g79e+z3gPEX6i74S9hgP5lXfYmrEURB1ccnVtCyQPOn/zjWhji0BKSQ0kNZI3mcM+loY5w1pIZvzyCmMZ0Ymv0G3lxz88X8h0WXqzWHL9GOfuLiEPeKBw52DBVa3Pg5MNEA7skog59FCSREP4Xb0bXv9Wp+iLbS3BiYx1jc7FLgV96khL5fjPAjIgaBWtw99w4DUwVUhH1Gzj2H11qgoYgPevyWXcL5dgiH2Kx1VK1de0d0w9vA4Sz42t Swkg1fIq I3z6HD6Oe8/BEh95N4yXXMP1p6kkTxzVzg5RYfBaJx2TqJx1X3KqvowDIEFQbDfWtz4wJeaWq5IY2BgIAq5zm1caBx5jiA+ZfKwfhOiW5TjRb8cCX+dITn1NUilv22Phwo+Rj3J1dKJ1hPqFNREP0ZvIm1CX0FrR6xFYV9kNFfqjvsnMHEWDi1+egf5VMkPd7S4wZqeyy+tSpdbkRreNrCmfNT54OjDn0DzB33GYZAS6xTdgt6qUpD/9/NF9Tn/XLa1dsrB0msc6AQcZj/wVpVVLm22KAUZQm+2O8vQZpxm9ZQlPpLdFyoFuiy4XM2hEs49+S0Y0q3VWcMLilD7nV67M80U8oYPZX6rmaq7+rN9PMx9y4TPgVz0q+Eylq74u1PM36mcwpvlYncfm1Y2QBs4/WRc8YN+QKjbKWrtrtdJDPBug= 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 the kernel. Instead, print a warning as it is more useful compared to unconditionally crashing the machine. However, once a warning is detected, the counting of page_table_check becomes unbalanced, therefore, disable its activity until the next boot. In case of where machine hardening requires a more secure environment, it is still possible to crash machine on page_table_check errors via panic_on_warn sysctl option. Signed-off-by: Pasha Tatashin --- mm/page_table_check.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/mm/page_table_check.c b/mm/page_table_check.c index 93ec7690a0d8..ad4447e999f8 100644 --- a/mm/page_table_check.c +++ b/mm/page_table_check.c @@ -22,6 +22,12 @@ static bool __page_table_check_enabled __initdata = DEFINE_STATIC_KEY_TRUE(page_table_check_disabled); EXPORT_SYMBOL(page_table_check_disabled); +#define PAGE_TABLE_CHECK_WARN(v) \ + do { \ + if (WARN_ON_ONCE(v)) \ + static_branch_enable(&page_table_check_disabled); \ + } while (false) + static int __init early_page_table_check_param(char *buf) { return kstrtobool(buf, &__page_table_check_enabled); @@ -50,7 +56,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_WARN(!page_ext); + return (void *)(page_ext) + page_table_check_ops.offset; } @@ -72,18 +79,18 @@ static void page_table_check_clear(struct mm_struct *mm, unsigned long addr, page = pfn_to_page(pfn); page_ext = page_ext_get(page); - BUG_ON(PageSlab(page)); + PAGE_TABLE_CHECK_WARN(PageSlab(page)); anon = PageAnon(page); for (i = 0; i < pgcnt; i++) { 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_WARN(atomic_read(&ptc->file_map_count)); + PAGE_TABLE_CHECK_WARN(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_WARN(atomic_read(&ptc->anon_map_count)); + PAGE_TABLE_CHECK_WARN(atomic_dec_return(&ptc->file_map_count) < 0); } page_ext = page_ext_next(page_ext); } @@ -110,18 +117,18 @@ static void page_table_check_set(struct mm_struct *mm, unsigned long addr, page = pfn_to_page(pfn); page_ext = page_ext_get(page); - BUG_ON(PageSlab(page)); + PAGE_TABLE_CHECK_WARN(PageSlab(page)); anon = PageAnon(page); for (i = 0; i < pgcnt; i++) { 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_WARN(atomic_read(&ptc->file_map_count)); + PAGE_TABLE_CHECK_WARN(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_WARN(atomic_read(&ptc->anon_map_count)); + PAGE_TABLE_CHECK_WARN(atomic_inc_return(&ptc->file_map_count) < 0); } page_ext = page_ext_next(page_ext); } @@ -137,15 +144,15 @@ void __page_table_check_zero(struct page *page, unsigned int order) struct page_ext *page_ext; unsigned long i; - BUG_ON(PageSlab(page)); + PAGE_TABLE_CHECK_WARN(PageSlab(page)); page_ext = page_ext_get(page); - BUG_ON(!page_ext); + PAGE_TABLE_CHECK_WARN(!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_WARN(atomic_read(&ptc->anon_map_count)); + PAGE_TABLE_CHECK_WARN(atomic_read(&ptc->file_map_count)); page_ext = page_ext_next(page_ext); } page_ext_put(page_ext);