mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Vlastimil Babka <vbabka@suse.cz>,
	John Hubbard <jhubbard@nvidia.com>,
	linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
	Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	"Liam R. Howlett" <Liam.Howlett@oracle.com>,
	Mike Rapoport <rppt@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>, Jason Gunthorpe <jgg@ziepe.ca>,
	Peter Xu <peterx@redhat.com>
Subject: Re: [PATCH v1] mm/gup: remove (VM_)BUG_ONs
Date: Thu, 5 Jun 2025 08:08:24 +0200	[thread overview]
Message-ID: <f33f6f73-58bd-4877-a2cc-5436943da292@redhat.com> (raw)
In-Reply-To: <f1a3e3c1-103f-46d4-aa0e-ea057e78954d@suse.cz>

On 05.06.25 07:37, Vlastimil Babka wrote:
> On 6/5/25 03:07, John Hubbard wrote:
>> On 6/4/25 7:05 AM, David Hildenbrand wrote:
>>> Especially once we hit one of the assertions in
>>> sanity_check_pinned_pages(), observing follow-up assertions failing
>>> in other code can give good clues about what went wrong, so use
>>> VM_WARN_ON_ONCE instead.
>>>
>>> While at it, let's just convert all VM_BUG_ON to VM_WARN_ON_ONCE as
>>> well. Add one comment for the pfn_valid() check.
>>
>> It would be a nice touch to add Linus' notes here, with the BUG() history
>> and all. It answers a FAQ about BUG vs. WARN* that is really nice
>> to have in the commit log.
> 
> Perhaps then rather put it somewhere appropriate in Documentation/process/
> than a random commit log?

I mean, I documented most of that already in coding-style.rst. :)

The full BUG history is not in there, but not sure if that is really required if ...
we're not supposed to use it.

Is there anything important missing?


commit 1cfd9d7e43d5a1cf739d1420b10b1e65feb02f88
Author: David Hildenbrand <david@redhat.com>
Date:   Fri Sep 23 13:34:24 2022 +0200

     coding-style.rst: document BUG() and WARN() rules ("do not crash the kernel")
     
     Linus notes [1] that the introduction of new code that uses VM_BUG_ON()
     is just as bad as BUG_ON(), because it will crash the kernel on
     distributions that enable CONFIG_DEBUG_VM (like Fedora):
     
         VM_BUG_ON() has the exact same semantics as BUG_ON. It is literally
         no different, the only difference is "we can make the code smaller
         because these are less important". [2]
     
     This resulted in a more generic discussion about usage of BUG() and
     friends. While there might be corner cases that still deserve a BUG_ON(),
     most BUG_ON() cases should simply use WARN_ON_ONCE() and implement a
     recovery path if reasonable:
     
         The only possible case where BUG_ON can validly be used is "I have
         some fundamental data corruption and cannot possibly return an
         error". [2]
     
     As a very good approximation is the general rule:
     
         "absolutely no new BUG_ON() calls _ever_" [2]
     
     ... not even if something really shouldn't ever happen and is merely for
     documenting that an invariant always has to hold. However, there are sill
     exceptions where BUG_ON() may be used:
     
         If you have a "this is major internal corruption, there's no way we can
         continue", then BUG_ON() is appropriate. [3]
     
     There is only one good BUG_ON():
     
         Now, that said, there is one very valid sub-form of BUG_ON():
         BUILD_BUG_ON() is absolutely 100% fine. [2]
     
     While WARN will also crash the machine with panic_on_warn set, that's
     exactly to be expected:
     
         So we have two very different cases: the "virtual machine with good
         logging where a dead machine is fine" - use 'panic_on_warn'. And
         the actual real hardware with real drivers, running real loads by
         users. [4]
     
     The basic idea is that warnings will similarly get reported by users
     and be found during testing. However, in contrast to a BUG(), there is a
     way to actually influence the expected behavior (e.g., panic_on_warn)
     and to eventually keep the machine alive to extract some debug info.
     
     Ingo notes that not all WARN_ON_ONCE cases need recovery. If we don't ever
     expect this code to trigger in any case, recovery code is not really
     helpful.
     
         I'd prefer to keep all these warnings 'simple' - i.e. no attempted
         recovery & control flow, unless we ever expect these to trigger.
         [5]
     
     There have been different rules floating around that were never properly
     documented. Let's try to clarify.
     
     [1] https://lkml.kernel.org/r/CAHk-=wiEAH+ojSpAgx_Ep=NKPWHU8AdO3V56BXcCsU97oYJ1EA@mail.gmail.com
     [2] https://lore.kernel.org/r/CAHk-=wg40EAZofO16Eviaj7mfqDhZ2gVEbvfsMf6gYzspRjYvw@mail.gmail.com
     [3] https://lkml.kernel.org/r/CAHk-=wit-DmhMfQErY29JSPjFgebx_Ld+pnerc4J2Ag990WwAA@mail.gmail.com
     [4] https://lore.kernel.org/r/CAHk-=wgF7K2gSSpy=m_=K3Nov4zaceUX9puQf1TjkTJLA2XC_g@mail.gmail.com
     [5] https://lore.kernel.org/r/YwIW+mVeZoTOxn%2F4@gmail.com
     


-- 
Cheers,

David / dhildenb


  reply	other threads:[~2025-06-05  6:08 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-04 14:05 David Hildenbrand
2025-06-04 14:22 ` Vlastimil Babka
2025-06-04 14:26   ` Suren Baghdasaryan
2025-06-04 14:48 ` Lorenzo Stoakes
2025-06-04 14:58   ` David Hildenbrand
2025-06-04 15:44     ` Lorenzo Stoakes
2025-06-04 15:42   ` Linus Torvalds
2025-06-04 16:05     ` Lorenzo Stoakes
2025-06-04 15:14 ` Jason Gunthorpe
2025-06-04 16:01   ` David Hildenbrand
2025-06-04 17:25 ` SeongJae Park
2025-06-04 19:12 ` Liam R. Howlett
2025-06-04 19:16   ` David Hildenbrand
2025-06-05  1:07 ` John Hubbard
2025-06-05  5:37   ` Vlastimil Babka
2025-06-05  6:08     ` David Hildenbrand [this message]
2025-06-05  8:48       ` Vlastimil Babka
2025-06-05 12:29         ` David Hildenbrand
2025-06-05  7:10 ` Michal Hocko
2025-06-06  8:10   ` David Hildenbrand
2025-06-06  8:31     ` Michal Hocko
2025-06-06  9:01       ` David Hildenbrand
2025-06-06 10:13         ` Michal Hocko
2025-06-06 10:19           ` Lorenzo Stoakes
2025-06-06 10:28             ` David Hildenbrand
2025-06-06 11:04               ` Lorenzo Stoakes
2025-06-06 11:44                 ` David Hildenbrand
2025-06-06 11:56                   ` Michal Hocko
2025-06-06 12:12                   ` Lorenzo Stoakes
2025-06-06 12:17                     ` David Hildenbrand
2025-06-06 17:57                 ` John Hubbard
2025-06-06 18:06                   ` Lorenzo Stoakes
2025-06-06 18:15                     ` David Hildenbrand
2025-06-06 18:21                       ` John Hubbard
2025-06-06 18:23                         ` David Hildenbrand
2025-06-06 18:31                           ` John Hubbard
2025-06-06 18:36                             ` David Hildenbrand
2025-06-06 18:39                               ` John Hubbard
2025-06-06 18:34                           ` Lorenzo Stoakes
2025-06-06 18:42                           ` Jason Gunthorpe
2025-06-06 18:46                             ` Lorenzo Stoakes
2025-06-06 19:03                               ` Lorenzo Stoakes
2025-06-07 13:42                                 ` Jason Gunthorpe
2025-06-07 13:53                                   ` Lorenzo Stoakes
2025-06-07 18:00                                     ` John Hubbard
2025-06-09  9:57                                       ` Vlastimil Babka
2025-07-24 10:54                                         ` Vlastimil Babka
2025-07-24 10:56                                           ` Lorenzo Stoakes
2025-07-24 17:27                                             ` John Hubbard
2025-06-11  9:32                                       ` David Hildenbrand
2025-06-11 12:03                                         ` Jason Gunthorpe
2025-06-11 12:06                                           ` Lorenzo Stoakes
2025-06-06 10:28             ` Michal Hocko
2025-06-06 10:27           ` David Hildenbrand
2025-06-06  8:12 ` David Hildenbrand

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=f33f6f73-58bd-4877-a2cc-5436943da292@redhat.com \
    --to=david@redhat.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=jgg@ziepe.ca \
    --cc=jhubbard@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mhocko@suse.com \
    --cc=peterx@redhat.com \
    --cc=rppt@kernel.org \
    --cc=surenb@google.com \
    --cc=vbabka@suse.cz \
    /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

all inboxes | Powered by JetHome®