From: mawupeng <mawupeng1@huawei.com>
To: <ryncsn@gmail.com>
Cc: <mawupeng1@huawei.com>, <akpm@linux-foundation.org>,
<david@redhat.com>, <ryan.roberts@arm.com>, <chrisl@kernel.org>,
<huang.ying.caritas@gmail.com>, <schatzberg.dan@gmail.com>,
<baohua@kernel.org>, <hanchuanhua@oppo.com>,
<willy@infradead.org>, <gaoxu2@honor.com>, <linux-mm@kvack.org>,
<linux-kernel@vger.kernel.org>, <nphamcs@gmail.com>,
<yosryahmed@google.com>
Subject: Re: [PATCH] mm: swap: Avoid infinite loop if no valid swap entry found during do_swap_page
Date: Sat, 22 Feb 2025 15:41:18 +0800 [thread overview]
Message-ID: <a868e635-a86e-4dd7-8bae-c6ca94a2dc09@huawei.com> (raw)
In-Reply-To: <CAMgjq7AfZnwGAHoyCEhO5p2km-gPLk65WLL+2vO1i8hQDaTy+A@mail.gmail.com>
On 2025/2/22 15:33, Kairui Song wrote:
> On Sat, Feb 22, 2025 at 10:56 AM Wupeng Ma <mawupeng1@huawei.com> wrote:
>>
>> From: Ma Wupeng <mawupeng1@huawei.com>
>>
>> During our test, infinite loop is produced during #PF will lead to infinite
>> error log as follow:
>>
>> get_swap_device: Bad swap file entry 114000000
>>
>> Digging into the source, we found that the swap entry is invalid due to
>> unknown reason, and this lead to invalid swap_info_struct. Excessive log
>
> Hi Wupeng,
>
> What is the kernel version you are using? If it's another bug causing
> this invalid swap entry, we should fix that bug instead, not
> workaround it.
>
> This looks kind of similar to another PATCH & Bug report, corrupted
> page table or swap entry:
> https://lore.kernel.org/linux-mm/e223b0e6ba2f4924984b1917cc717bd5@honor.com/
>
> Might be the same kernel bug? Gaoxu mentioned the bug was observed on
> Kernel 6.6.30 (android version), and neither of these two workarounds
> will fix it completely, the invalid value could cause many other
> issues too. We definitely need to find out the root cause.
We are having this problem in linux-v5.10, since the log is lost and swap
is not enabled in this machines, maybe memory corrupted in the pt.
>
>> printing can fill up the prioritized log space, leading to the purging of
>> originally valid logs and hindering problem troubleshooting. To make this
>> more robust, kill this task.
>>
>> Signed-off-by: Ma Wupeng <mawupeng1@huawei.com>
>> ---
>> include/linux/swap.h | 1 +
>> mm/memory.c | 9 ++++++++-
>> mm/swapfile.c | 2 +-
>> 3 files changed, 10 insertions(+), 2 deletions(-)
>>
>> diff --git a/include/linux/swap.h b/include/linux/swap.h
>> index b13b72645db3..0fa39cf66bc4 100644
>> --- a/include/linux/swap.h
>> +++ b/include/linux/swap.h
>> @@ -508,6 +508,7 @@ struct backing_dev_info;
>> extern int init_swap_address_space(unsigned int type, unsigned long nr_pages);
>> extern void exit_swap_address_space(unsigned int type);
>> extern struct swap_info_struct *get_swap_device(swp_entry_t entry);
>> +struct swap_info_struct *_swap_info_get(swp_entry_t entry);
>> sector_t swap_folio_sector(struct folio *folio);
>>
>> static inline void put_swap_device(struct swap_info_struct *si)
>> diff --git a/mm/memory.c b/mm/memory.c
>> index b4d3d4893267..2d36e5a644d1 100644
>> --- a/mm/memory.c
>> +++ b/mm/memory.c
>> @@ -4365,8 +4365,15 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
>>
>> /* Prevent swapoff from happening to us. */
>> si = get_swap_device(entry);
>> - if (unlikely(!si))
>> + if (unlikely(!si)) {
>> + if (unlikely(!_swap_info_get(entry)))
>> + /*
>> + * return VM_FAULT_SIGBUS for invalid swap entry to
>> + * avoid infinite #PF.
>> + */
>> + ret = VM_FAULT_SIGBUS;
>
> This could lead to VM_FAULT_SIGBUS on swapoff. After swapoff
> get_swap_device will return NULL.
If swap is off, All swap pages should be swap in as expected, so
such entry can not trigger do_swap_page?
next prev parent reply other threads:[~2025-02-22 7:41 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-22 2:46 Wupeng Ma
2025-02-22 3:45 ` Matthew Wilcox
2025-02-22 3:59 ` mawupeng
2025-02-23 2:42 ` Matthew Wilcox
2025-02-23 6:18 ` Barry Song
2025-02-24 1:27 ` mawupeng
2025-02-24 4:22 ` Matthew Wilcox
2025-02-24 7:11 ` Barry Song
2025-02-24 15:37 ` Matthew Wilcox
2025-02-22 7:33 ` Kairui Song
2025-02-22 7:41 ` mawupeng [this message]
2025-02-22 8:02 ` Kairui Song
2025-02-22 9:58 ` Barry Song
2025-02-23 2:38 ` kernel test robot
2025-02-23 2:50 ` kernel test robot
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=a868e635-a86e-4dd7-8bae-c6ca94a2dc09@huawei.com \
--to=mawupeng1@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=chrisl@kernel.org \
--cc=david@redhat.com \
--cc=gaoxu2@honor.com \
--cc=hanchuanhua@oppo.com \
--cc=huang.ying.caritas@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nphamcs@gmail.com \
--cc=ryan.roberts@arm.com \
--cc=ryncsn@gmail.com \
--cc=schatzberg.dan@gmail.com \
--cc=willy@infradead.org \
--cc=yosryahmed@google.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
all inboxes | Powered by JetHome®