From patchwork Sun May 21 23:07:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Rientjes X-Patchwork-Id: 13249667 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 3D81BC77B7C for ; Sun, 21 May 2023 23:07:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2E2896B0072; Sun, 21 May 2023 19:07:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 293076B0074; Sun, 21 May 2023 19:07:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 15AE0900003; Sun, 21 May 2023 19:07:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 07E166B0072 for ; Sun, 21 May 2023 19:07:45 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id AD773C02D8 for ; Sun, 21 May 2023 23:07:44 +0000 (UTC) X-FDA: 80815801248.09.5246956 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf22.hostedemail.com (Postfix) with ESMTP id EA2F2C0009 for ; Sun, 21 May 2023 23:07:42 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=Kq87XCym; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf22.hostedemail.com: domain of rientjes@google.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=rientjes@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684710463; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=WIwsDcXIgqGabOrw2zINVCQbldk9zdIAC6OoUEGx+AQ=; b=AFwkzTGgS3hLbu9GwgvTU9Gl6R2LQJfMeG9O8lR3AA6IQKH96CAuWgzxN23grbCJu2p21r EYq8jw4U7JbPofPI1ZTbBRiXyqSInby2CToj+iPdIyVeO+NqM7ImxFiB4AfjEwUBYaTFFJ 1ZOxQfcnnx4V4HgRXKzDZRqflztc/Z8= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=Kq87XCym; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf22.hostedemail.com: domain of rientjes@google.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=rientjes@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684710463; a=rsa-sha256; cv=none; b=pHuZw1wC3LKZJAvsReeGWCLcqMlZHVFao3ynV+D+ogymKb4NAPsa7va8YF76eif0uDgJlb JpZsyUR6wJUroPvcLDKxNyxoUz4WTh/9+09YZ/uGrNBLSv6tX64x06yTse3UBcefvZOqpY djXqVWjwZcJ65d4l53z9dg1RRp1iHR4= Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1ae3f74c98bso163395ad.1 for ; Sun, 21 May 2023 16:07:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684710461; x=1687302461; h=mime-version:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=WIwsDcXIgqGabOrw2zINVCQbldk9zdIAC6OoUEGx+AQ=; b=Kq87XCymTREUT+OVcogWZjum+1CbBEkWMM1pjljQewkjdZWBEJt9ATHO6gRjNhv2h/ eWKdio8rIBqOha0dRTe64GQq9M89S6B9QFu0SQBLWC7v95ubzIYjbBRdPIDG3Vt9Zb5f cp/FslnnDIFM3xVhqnYkdmAqXYvYYC2GTcJpZFZgxyVRw7HQD28jqXcCauvgH6Utp4xj aTbuKXgHPkb7TFL4nzn7U32K3P7NmoxEFdzmOKQ04yhR12Q5EDbrTxYOwIwpcvoSlt/I j/H0BYLfIWwFmaru2YzO7HOlMs4R6s+ACQcMasO9iXdf7RyjqQdzWxBZA5DVHYDP2I1z JKZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684710461; x=1687302461; h=mime-version:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=WIwsDcXIgqGabOrw2zINVCQbldk9zdIAC6OoUEGx+AQ=; b=CXW1umkt63ku2EpO6ShrfG1wcURfWio2Q8MPMOsuwwcyMiLSojTLHzfmI6ZwBXP+JV QnYMPvt59Hp0lB//ydkasGyV1E9sAa9Enq4wCXexVadp7gnogIqrRnv27qwI+0Jxx+Yw eXhfiyGoLs5KvjEpCptvz8dcKoOaLDyiFJm8pTpINtgvqgQyuSVYd27bKJxvY+r5Ipml Ie8s3DqgWmADzBXnKNnCbjSoEBAN/DwhzdT/nIZdaASK0BR88p+4geX/ziFZQtLiRdLB 2a+oC/xJa3iWXe/mgF7AV4C9Nw8up65uTWXQv622p/z0YKI8vFLFOrb+AU2L1OVPIfXf B0eQ== X-Gm-Message-State: AC+VfDyt1dhwVjNww/FlEYIt0Wcs2p3IvpfG1QUMpvyVJJv3xUILCHnE Q0eMelOEXPXieB9zH/zenDc0VQ== X-Google-Smtp-Source: ACHHUZ436D+0OgmobeGSeiZ+v/J8u3Cyb6uS0YRQ12TwEbqHtMzGvOzBVTCw8IZIdkwZgwL/Bp9mxg== X-Received: by 2002:a17:902:cec4:b0:1ac:36e6:2801 with SMTP id d4-20020a170902cec400b001ac36e62801mr713442plg.12.1684710461498; Sun, 21 May 2023 16:07:41 -0700 (PDT) Received: from [2620:0:1008:11:c77c:12d8:c868:4106] ([2620:0:1008:11:c77c:12d8:c868:4106]) by smtp.gmail.com with ESMTPSA id 5-20020a170902e9c500b001a1a8e98e93sm3164121plk.287.2023.05.21.16.07.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 May 2023 16:07:40 -0700 (PDT) Date: Sun, 21 May 2023 16:07:40 -0700 (PDT) From: David Rientjes To: Andrew Morton , Michal Hocko , Alex Shi , Johannes Weiner , Matthew Wilcox , Alexander Duyck cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [patch] mm, debug: allow suppressing panic on CONFIG_DEBUG_VM checks Message-ID: MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: EA2F2C0009 X-Stat-Signature: i7p1fboxq3nnwwxmdyxjer63sic4trhu X-Rspam-User: X-HE-Tag: 1684710462-18218 X-HE-Meta: U2FsdGVkX1/0RjGqR0bkacQjFqjmMScKSYRC624ufU2Kj/PgJ6bUaFZmXQ3DG6GbOa78uJiYpDxnH7FKmYp8pIb3gjX+E+VG2ca8mR7USPbdVe3s0QtA3UIqh8eWRFmy9Cl0gdKgHqXRR5u9IpnFsWHGLMffLmTv3NUIAFsdU3XgDQzVlgApgiRo+hTfFyYMGNNfT4sVFE63uPzgBtgZg22MdSyRcE/cxChPJ557GhZPeEGSJcd3koElXxenvIECn2imOxq8byZyDa3TH1lL3UoahrW75B48S0UPtDutafkV7y0oEC5Em3PsIXN2b01aekV3ngffXknJqm3LvQACA7f4SFU8MDkszjzYspnJaz32xoz9Z5Pqedi3uxFzUwKAjV4unnaH0a0KDUfcIWJMW9jxnK1IX2c/LhoEnx2E1Hgb5x7LXu64uJ/3vbeNk7dvW08Drhck5bgU8K0HH7cIj8667JaeqD8qRwge4/nZ1bfF8cpAiEPDf/6aUPUFrnFhEr58Jrpx7kp8Cgz4Nu0M/LoU6jNcvci/i2WRLu8HdVOLLlZ+kZ4VC/29i5sFe2kOLVhkxirOyR3dfCPgoHLTCRcSuzlDpQHJKV6DrBZxIuNnl9SFt63HqTRDHkErHR7Ahd8mhD9SBqIAYMyOhJGrM6/1EllxA5ti3iTPk76HaXvtO35+j0+JFAI3ZVa507ZC4o1R0w8Ky33ggUTPZ9Kn/7wHnVLTUTf7jGJYUinmldL/8eJM456bUii43ew372QWkNZ5matm9nun5OzYJjrzgs6M/HgmuchKQL3SkdR+IPQ6/9EKH426Oah8/6RVLCbNLUJ++DUNXe7NTKoHwn69tPx4B7bxyJHQAyviG4+Qu0imm5ULHFYVPnLp4+mGU9txrmMBbLZW/wkzGu14NS+tAxi76Ngv9+gZNt6tSWXcBc60INF4lvjg9MgKF2BKxoOInPVc30B5ky1A1+oEN8e oArNzTmr 0C8lPRLrka8RKSp2sJtuuUx9M1CnelM+Sg7z0YrKZ1owj3Ts8Mpvr0TzrLyflE8/0QZKB7mUfdLtlkS99MsqSMMtyimhd1nuTG0cGkaNo/fM1Xc51FKO3rPsfu8gpD1WuBYwywo4ltcusu4pKS5KxJBSllbxdSu1vaq3KwbMcWNV9l9vnXqXw4LTVoSQLqTByma83JABZATkvF2oMccA2KyX7Rc2xZS9ajB3cpbaHzsQJA2BgE/mq3iqcQ46o2hghKp3ZRUTD7yyt1lcZK7z8rxb2MxpkjUW8KikM+TRz8yF1UdcAClG7WORO5452bYKuZPakVvO7imBJVQX8zYdF3HfhIbJKEkfF7XtU9l1Vq9/FEUi6PMAF13aXdBcKMgPCvTkz8o8crkureyXY9EG4u2V7nbbkeufkpTw2oxGgILYvt997jEaZKmNGYuLO3lCtYZCs 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: CONFIG_DEBUG_VM is used to enable additional MM debug checks at runtime. This can be used to catch latent kernel bugs. Because this is mainly used for debugging, it is seldom enabled in production environments, including due to the added performance overhead. Thus, the choice between VM_BUG_ON() and VM_WARN_ON() is somewhat loosely defined. VM_BUG_ON() is often used because debuggers would like to collect crash dumps when unexpected conditions occur. When CONFIG_DEBUG_VM is enabled on a very small set of production deployments to catch any unexpected condition, however, VM_WARN_ON() could be used as a substitute. In these configurations, it would be useful to surface the unexpected condition in the kernel log but not panic the system. In other words, it would be useful if checks done by CONFIG_DEBUG_ON could both generate crash dumps for kernel developers *and* surface issues but not crash depending on how it's configured. [ If it is really unsafe to continue operation, then BUG_ON() would be used instead so that the kernel panics regardless of whether CONFIG_DEBUG_VM is enabled or not. ] Introduce the ability to suppress kernel panics when VM_BUG_ON*() variants are used. This leverages the existing vm_debug= kernel command line option. Additionally, this can reduce the risk of systems boot looping if VM_BUG_ON() conditions are encountered during bootstrap. Signed-off-by: David Rientjes --- Note: the vm_debug= kernel parameter is only extensible for new debug options, not for disabling existing debug options. When adding the ability to selectively disable existing debug options, such as in this patch, admins would need to know this future set of debug options in advance. In other words, if admins would like to preserve the existing behavior of BUG() when VM_BUG_ON() is used after this patch, they would have had to have the foresight to use vm_debug=B. It would be useful to rewrite the vm_debug= interface to select the specific options to disable rather than "disable all, and enable those that are specified." This could be done by making vm_debug only disable the listed debug options rather than enabling them. This change could be done before this patch is merged if that's the agreed path forward. --- .../admin-guide/kernel-parameters.txt | 1 + include/linux/mmdebug.h | 20 ++++++++++++++----- mm/debug.c | 14 ++++++++++++- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6818,6 +6818,7 @@ debugging features. Available options are: + B Enable panic on MM debug checks P Enable page structure init time poisoning - Disable all of the above options diff --git a/include/linux/mmdebug.h b/include/linux/mmdebug.h --- a/include/linux/mmdebug.h +++ b/include/linux/mmdebug.h @@ -13,34 +13,44 @@ void dump_page(struct page *page, const char *reason); void dump_vma(const struct vm_area_struct *vma); void dump_mm(const struct mm_struct *mm); +extern bool debug_vm_bug_enabled; + #ifdef CONFIG_DEBUG_VM -#define VM_BUG_ON(cond) BUG_ON(cond) +#define VM_BUG_ON(cond) \ + do { \ + if (unlikely(cond)) { \ + if (likely(debug_vm_bug_enabled)) \ + BUG(); \ + else \ + WARN_ON(1); \ + } \ + } while (0) #define VM_BUG_ON_PAGE(cond, page) \ do { \ if (unlikely(cond)) { \ dump_page(page, "VM_BUG_ON_PAGE(" __stringify(cond)")");\ - BUG(); \ + VM_BUG_ON(1); \ } \ } while (0) #define VM_BUG_ON_FOLIO(cond, folio) \ do { \ if (unlikely(cond)) { \ dump_page(&folio->page, "VM_BUG_ON_FOLIO(" __stringify(cond)")");\ - BUG(); \ + VM_BUG_ON(1); \ } \ } while (0) #define VM_BUG_ON_VMA(cond, vma) \ do { \ if (unlikely(cond)) { \ dump_vma(vma); \ - BUG(); \ + VM_BUG_ON(1); \ } \ } while (0) #define VM_BUG_ON_MM(cond, mm) \ do { \ if (unlikely(cond)) { \ dump_mm(mm); \ - BUG(); \ + VM_BUG_ON(1); \ } \ } while (0) #define VM_WARN_ON_ONCE_PAGE(cond, page) ({ \ diff --git a/mm/debug.c b/mm/debug.c --- a/mm/debug.c +++ b/mm/debug.c @@ -224,10 +224,15 @@ void dump_mm(const struct mm_struct *mm) } EXPORT_SYMBOL(dump_mm); +/* If disabled, warns but does not panic on added CONFIG_DEBUG_VM checks */ +bool debug_vm_bug_enabled = true; +EXPORT_SYMBOL(debug_vm_bug_enabled); + static bool page_init_poisoning __read_mostly = true; static int __init setup_vm_debug(char *str) { + bool __debug_vm_bug_enabled = true; bool __page_init_poisoning = true; /* @@ -237,13 +242,17 @@ static int __init setup_vm_debug(char *str) if (*str++ != '=' || !*str) goto out; + __debug_vm_bug_enabled = false; __page_init_poisoning = false; if (*str == '-') goto out; while (*str) { switch (tolower(*str)) { - case'p': + case 'b': + __debug_vm_bug_enabled = true; + break; + case 'p': __page_init_poisoning = true; break; default: @@ -254,9 +263,12 @@ static int __init setup_vm_debug(char *str) str++; } out: + if (debug_vm_bug_enabled && !__debug_vm_bug_enabled) + pr_warn("Panic on MM debug checks disabled by kernel command line option 'vm_debug'\n"); if (page_init_poisoning && !__page_init_poisoning) pr_warn("Page struct poisoning disabled by kernel command line option 'vm_debug'\n"); + debug_vm_bug_enabled = __debug_vm_bug_enabled; page_init_poisoning = __page_init_poisoning; return 1;