From mboxrd@z Thu Jan 1 00:00:00 1970 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 25164C04FFE for ; Wed, 8 May 2024 08:09:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A0F6F6B00B2; Wed, 8 May 2024 04:09:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9BF636B00B3; Wed, 8 May 2024 04:09:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 886B76B00B4; Wed, 8 May 2024 04:09:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 699B66B00B2 for ; Wed, 8 May 2024 04:09:04 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 0BA0D121012 for ; Wed, 8 May 2024 08:09:04 +0000 (UTC) X-FDA: 82094503008.23.6161E5E Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf23.hostedemail.com (Postfix) with ESMTP id D2C1E140003 for ; Wed, 8 May 2024 08:09:00 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; spf=pass (imf23.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715155742; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LhYQuUQMYZQxtfvvg1HJr/7wqA3wyTzsuRN16YTb1SU=; b=nQvgwM+AIBXQfopcpxUt4Gt8CErgZJjgihVrwAAZgi6Bwn4bt4zOa+x8J0UXJyKnRFufGg AfiS0vrJy46TfQNKLdMcFzgYc6G28ckNNLJjSz4Kc0bobZL7WNuPT9MWTmKXCnO+A65C/W 5jwJ8UNU5Bm+BUA9fZrdv2Hw4RL1SFI= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; spf=pass (imf23.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715155742; a=rsa-sha256; cv=none; b=t699c19Q6HnjAFgTgDOLcNxtNR9QouC4OIAXlYrooLZR7wtF+071sp+GcXVQl4BqdPYqji 5iXcanBE4EUnOgMvIwzh7B+KuFIhwvCjCAPR3sDUWZj8UTa94ONL5OTlAh0I/xQLDt72uY 8/Jz1/E44m1XeGQanBZjzTRw8/xlsjA= Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4VZ74J6jHrzvRMS; Wed, 8 May 2024 16:05:36 +0800 (CST) Received: from canpemm500002.china.huawei.com (unknown [7.192.104.244]) by mail.maildlp.com (Postfix) with ESMTPS id C0BA9180065; Wed, 8 May 2024 16:08:56 +0800 (CST) Received: from [10.173.135.154] (10.173.135.154) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Wed, 8 May 2024 16:08:56 +0800 Subject: Re: [PATCH 3/3] mm/memory-failure: send SIGBUS in the event of thp split fail To: Jane Chu , , , , References: <20240501232458.3919593-1-jane.chu@oracle.com> <20240501232458.3919593-4-jane.chu@oracle.com> <038cffc0-e027-b518-460f-40099819c588@huawei.com> From: Miaohe Lin Message-ID: Date: Wed, 8 May 2024 16:08:55 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.173.135.154] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500002.china.huawei.com (7.192.104.244) X-Rspamd-Queue-Id: D2C1E140003 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: b8gjoybumfyqgn9tomm6gd7imiiszoa4 X-HE-Tag: 1715155740-670180 X-HE-Meta: U2FsdGVkX1/bTvdKRewsh+YMIkEtWAV9G0d/4ZoWGNdance6foVfY/3ga1CsknaTm/+awJN83aXU5AvfnCaDLBepIa5gbjiZupEBnKZ/sTowggtqUYIAx/BCv4nVo3LwEU1Y/G+kBSLHp9nK3+nielJLdPRhyldbz2BcOD+EqbgoR00hsXSUumNM4ta81at6IYceaePh1FsgZs0bm0dTBkVrZsxbIrW0av7SS/38wLag0X1GtZUkD9eeNwZL4koNGIFxBGWr5JFQQgmFGK54TJmE2U/gSQf5z/ig94J16K0OObMrmnAiwp3XzpbzrV0y0JMEuJgZ2dLoQamCb5rIRI4tVEf1v8g2QiGVpGjdFBlRzAZaXtcwqCXEWTNbPz2gDn4T9dcb9UkKoF0rruHvHbuT4/1bmRclqqSHUCiBYP4nwqk8yQMVnotRmv5fefJ/TEWcVbrheUfAlbIjDJOd0L3gEmkupvc8GWOyefg0fXcmQbp7UuHcCS4oUu3Phw6cCmnViQt5Jx+XXU2dwlw/Q4xF02ZXpVT9A7+vgs+k0XaN+Pn2bhju1PmlS9VUeYG4P8ASq3mW2i2JrQTEaV+c8C94ITCByRMpFctWHS6NM0M4NdpJUaMnHKpSkqXaLF4TvzCZSteBsjGyqvaA8mPpksCuIk0+NenKvhJk3eiGElm6tCiwp9xjyZ76rs8XmxIGX+NNh5AXflDH3Dtt+4xLn63Fjp78otLIaH66lprSl+DZ5azz9PNHBTAkg6RQ42xtaoAD/rKOJRQ1quO8dO8H+NF2qnoKJ1mQ1s/0WsLIY3RoIOyCvHQymN1UpDmdfL+b0r8grn1JCJHoode/yDTYFwWuokoUVq14hVnIlUTnSoy8+WQ4G8GSWJ9qpK/Pd1E4zTyf4w8ez0owVEOXTW+guYWihn4vw9QAfSqQaSx7jal5+9gprEg06cUzFZJBXXj6ftsPylrAg0AGBH4YSdY oTQnlX0k tNc7binRT++xqPt7FRHn6EBQpp52dL8XxK+TBvkqZZBik1QC4h8HUiY3eALN3ojR1aRXZpuwK4JlyMBclTHdWJ5eztgfhxKzGWqxfyREqM2y6LDsQrMWkCubfC9hHbeVCQ0gyewQ9fp4fIuMmolRdcPw1Pu8sCJxsxBGsO/O70QLRoLOytigHavgleGKsUwOmqyEFreIaoEuVvvpUqdVpkjJLlKe+neJeoeBYa6uQ4chXX1jzeSUXvpYuSA== 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: List-Subscribe: List-Unsubscribe: On 2024/5/7 4:26, Jane Chu wrote: > On 5/5/2024 12:00 AM, Miaohe Lin wrote: > >> On 2024/5/2 7:24, Jane Chu wrote: >>> When handle hwpoison in a GUP longterm pin'ed thp page, >>> try_to_split_thp_page() will fail. And at this point, there is little else >>> the kernel could do except sending a SIGBUS to the user process, thus >>> give it a chance to recover. >>> >>> Signed-off-by: Jane Chu >> Thanks for your patch. Some comments below. >> >>> --- >>>   mm/memory-failure.c | 36 ++++++++++++++++++++++++++++++++++++ >>>   1 file changed, 36 insertions(+) >>> >>> diff --git a/mm/memory-failure.c b/mm/memory-failure.c >>> index 7fcf182abb96..67f4d24a98e7 100644 >>> --- a/mm/memory-failure.c >>> +++ b/mm/memory-failure.c >>> @@ -2168,6 +2168,37 @@ static int memory_failure_dev_pagemap(unsigned long pfn, int flags, >>>       return rc; >>>   } >>>   +/* >>> + * The calling condition is as such: thp split failed, page might have >>> + * been GUP longterm pinned, not much can be done for recovery. >>> + * But a SIGBUS should be delivered with vaddr provided so that the user >>> + * application has a chance to recover. Also, application processes' >>> + * election for MCE early killed will be honored. >>> + */ >>> +static int kill_procs_now(struct page *p, unsigned long pfn, int flags, >>> +            struct page *hpage) >>> +{ >>> +    struct folio *folio = page_folio(hpage); >>> +    LIST_HEAD(tokill); >>> +    int res = -EHWPOISON; >>> + >>> +    /* deal with user pages only */ >>> +    if (PageReserved(p) || PageSlab(p) || PageTable(p) || PageOffline(p)) >>> +        res = -EBUSY; >>> +    if (!(PageLRU(hpage) || PageHuge(p))) >>> +        res = -EBUSY; >> Above checks seems unneeded. We already know it's thp? > > Agreed. > > I  lifted these checks from hwpoison_user_mapping() with a hope to make kill_procs_now() more generic, > > such as, potentially replacing kill_accessing_processes() for re-accessing hwpoisoned page. > > But I backed out at last, due to concerns that my tests might not have covered sufficient number of scenarios. > >> >>> + >>> +    if (res == -EHWPOISON) { >>> +        collect_procs(folio, p, &tokill, flags & MF_ACTION_REQUIRED); >>> +        kill_procs(&tokill, true, pfn, flags); >>> +    } >>> + >>> +    if (flags & MF_COUNT_INCREASED) >>> +        put_page(p); >> This if block is broken. put_page() has been done when try_to_split_thp_page() fails? > > put_page() has not been done if try_to_split_thp_page() fails, and I think it should. In try_to_split_thp_page(), if split_huge_page fails, i.e. ret != 0, put_page() is called. See below: static int try_to_split_thp_page(struct page *page) { int ret; lock_page(page); ret = split_huge_page(page); unlock_page(page); if (unlikely(ret)) put_page(page); ^^^^^^^^^^^^^^^^^^^^^^^ return ret; } Or am I miss something? > > I will revise the code so that put_page() is called regardless MF_ACTION_REQUIRED is set or not. > >> >>> + >> action_result is missing? > > Indeed,  action_result() isn't always called, referring to the re-accessing hwpoison scenarios. > > In this case, I think the reason  is that, we just killed the process and there is nothing > > else to do or to report. > >> >>> +    return res; >>> +} >>> + >>>   /** >>>    * memory_failure - Handle memory failure of a page. >>>    * @pfn: Page Number of the corrupted page >>> @@ -2297,6 +2328,11 @@ int memory_failure(unsigned long pfn, int flags) >>>            */ >>>           SetPageHasHWPoisoned(hpage); >>>           if (try_to_split_thp_page(p) < 0) { >> Should hwpoison_filter() be called in this case? > Yes, it should. I will add the hwpoison_filter check. >> >>> +            if (flags & MF_ACTION_REQUIRED) { Only in MF_ACTION_REQUIRED case, SIGBUS is sent to processes when thp split failed. Any reson under it? Thanks. .