From: Miaohe Lin <linmiaohe@huawei.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: <akpm@linux-foundation.org>, <naoya.horiguchi@nec.com>,
<shy828301@gmail.com>, <linux-mm@kvack.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/4] mm/swapfile: fix wrong swap entry type for hwpoisoned swapcache page
Date: Sun, 23 Jul 2023 10:23:18 +0800 [thread overview]
Message-ID: <c81fb547-df79-6966-790d-219b8511f3c2@huawei.com> (raw)
In-Reply-To: <ZLStQ5QACPOHJcd2@casper.infradead.org>
On 2023/7/17 10:53, Matthew Wilcox wrote:
> On Mon, Jul 17, 2023 at 10:33:14AM +0800, Miaohe Lin wrote:
>> On 2023/7/15 11:50, Matthew Wilcox wrote:
>>> On Sat, Jul 15, 2023 at 11:17:26AM +0800, Miaohe Lin wrote:
>>>> Hwpoisoned dirty swap cache page is kept in the swap cache and there's
>>>> simple interception code in do_swap_page() to catch it. But when trying
>>>> to swapoff, unuse_pte() will wrongly install a general sense of "future
>>>> accesses are invalid" swap entry for hwpoisoned swap cache page due to
>>>> unaware of such type of page. The user will receive SIGBUS signal without
>>>> expected BUS_MCEERR_AR payload.
>>>
>>> Have you observed this, or do you just think it's true?
>>>
>>>> +++ b/mm/swapfile.c
>>>> @@ -1767,7 +1767,8 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd,
>>>> swp_entry_t swp_entry;
>>>>
>>>> dec_mm_counter(vma->vm_mm, MM_SWAPENTS);
>>>> - if (hwposioned) {
>>>> + /* Hwpoisoned swapcache page is also !PageUptodate. */
>>>> + if (hwposioned || PageHWPoison(page)) {
>>>
>>> This line makes no sense to me. How do we get here with PageHWPoison()
>>> being true and hwposioned being false?
>>
>> hwposioned will be true iff ksm_might_need_to_copy returns -EHWPOISON.
>> And there's PageUptodate check in ksm_might_need_to_copy before we can return -EHWPOISON:
>>
>> ksm_might_need_to_copy
>> if (!PageUptodate(page))
>> return page; /* let do_swap_page report the error */
>> ^^^
>> Will return here because hwpoisoned swapcache page is !PageUptodate(cleared via me_swapcache_dirty()).
>>
>> Or am I miss something?
>
> Ah! So we don't even get to calling copy_mc_to_kernel(). That seems
> like a bug in ksm_might_need_to_copy(), don't you think? Maybe this
> would be a better fix:
>
> + if (PageHWPoison(page))
> + return ERR_PTR(-EHWPOISON);
I'm preparing posting the v2. But I found this won't fix the issue if CONFIG_KSM is disabled. So the correct fix
should be something like below?
diff --git a/mm/ksm.c b/mm/ksm.c
index 97a9627116fa..74804158ee02 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -2794,6 +2794,8 @@ struct page *ksm_might_need_to_copy(struct page *page,
anon_vma->root == vma->anon_vma->root) {
return page; /* still no need to copy it */
}
+ if (PageHWPoison(page))
+ return ERR_PTR(-EHWPOISON);
if (!PageUptodate(page))
return page; /* let do_swap_page report the error */
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 346e22b8ae97..3dcc9d92689c 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1744,7 +1744,7 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd,
struct page *swapcache;
spinlock_t *ptl;
pte_t *pte, new_pte, old_pte;
- bool hwposioned = false;
+ bool hwposioned = PageHWPoison(page);
int ret = 1;
swapcache = page;
Thanks.
next prev parent reply other threads:[~2023-07-23 2:23 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-15 3:17 [PATCH 0/4] A few fixup and cleanup patches for memory-failure Miaohe Lin
2023-07-15 3:17 ` [PATCH 1/4] mm/swapfile: fix wrong swap entry type for hwpoisoned swapcache page Miaohe Lin
2023-07-15 3:50 ` Matthew Wilcox
2023-07-17 2:33 ` Miaohe Lin
2023-07-17 2:53 ` Matthew Wilcox
2023-07-17 5:55 ` Miaohe Lin
2023-07-23 2:23 ` Miaohe Lin [this message]
2023-07-15 3:17 ` [PATCH 2/4] mm: memory-failure: fix potential unexpected return value from unpoison_memory() Miaohe Lin
2023-07-19 23:48 ` Naoya Horiguchi
2023-07-20 8:44 ` Miaohe Lin
2023-07-15 3:17 ` [PATCH 3/4] mm: memory-failure: avoid false hwpoison page mapped error info Miaohe Lin
2023-07-15 3:59 ` Matthew Wilcox
2023-07-19 23:50 ` Naoya Horiguchi
2023-07-15 3:17 ` [PATCH 4/4] mm: memory-failure: add PageOffline() check Miaohe Lin
2023-07-20 1:09 ` Naoya Horiguchi
2023-07-20 8:42 ` Miaohe Lin
2023-07-20 23:55 ` Naoya Horiguchi
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=c81fb547-df79-6966-790d-219b8511f3c2@huawei.com \
--to=linmiaohe@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=naoya.horiguchi@nec.com \
--cc=shy828301@gmail.com \
--cc=willy@infradead.org \
/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