From patchwork Tue May 21 23:54:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jane Chu X-Patchwork-Id: 13669818 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 B74ADC25B74 for ; Tue, 21 May 2024 23:55:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4363D6B0099; Tue, 21 May 2024 19:55:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3E5466B009C; Tue, 21 May 2024 19:55:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 286836B009D; Tue, 21 May 2024 19:55:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 0905A6B0099 for ; Tue, 21 May 2024 19:55:53 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B5F8B1C16AB for ; Tue, 21 May 2024 23:55:52 +0000 (UTC) X-FDA: 82144063344.15.10242FC Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf10.hostedemail.com (Postfix) with ESMTP id E4039C0021 for ; Tue, 21 May 2024 23:55:50 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=cIVRSMsq; spf=pass (imf10.hostedemail.com: domain of jane.chu@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=jane.chu@oracle.com; dmarc=pass (policy=quarantine) header.from=oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716335751; a=rsa-sha256; cv=none; b=w9TlqS0cqOqWUOL3wGwkl0IMThzuKtdfbgZJ+0nG401LtEbwmS31h5JjIVuLknBGqzj2hO gdCoW16owRIEheBABQSH7n6yy1rLjDWm2lMOO44667GNGdcQvWux4i7sZ0QKSb/U5ML58e UhH9kGaTQmJdk+Uf7aIz3InMdFv1Xoc= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=cIVRSMsq; spf=pass (imf10.hostedemail.com: domain of jane.chu@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=jane.chu@oracle.com; dmarc=pass (policy=quarantine) header.from=oracle.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716335751; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=I3L1LQIelw9oqT+0T41Q58pEC5gWfYbgn8T4h8gRVP4=; b=DADSQSxPFl1Gk0K+rP19gH1gRYKM+DQfliGItzLbypeEe+VI54Ndls64BdU1bjG57RHiJs dWHHMWV6eC3TRTa9o/f3WNW7rcPJepDageNovIPdR1tOYoylFbvMYlFxMT3VMPjZAg+zxO AB9HieG8f1hMJWGsAwTzwS/lkwXCL5U= Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 44LJi9Ws025744; Tue, 21 May 2024 23:55:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-11-20; bh=I3L1LQIelw9oqT+0T41Q58pEC5gWfYbgn8T4h8gRVP4=; b=cIVRSMsqlLYYsVPR2FJWLHywyYr1y2WfWRRswKtAInrkSKhipcwyIHgLKtg5aCPx3weg 4/MikqcfOxA1ATOm9swY1+lkMIpxUz75w0nP6P5ImYo/RrVGREO6UMDCS8R7TPSbFnRf 8fVjE8ZNv6d73S00tKQeZZ3qnP4VREXyaznOoNR2OrLzSBNissq+dH2UqJYWEub8Q+Qn 1otMtmDfbAtipTA5aSl1oyPWfz1LaQdp2Ga/DMc7sIVCoX/2dyv+MMR3VBeeTAQvbgc7 79vOJtMhSKQjW6JFNFhr2k2tAYTmoozCsYCkl6OxIwUlQ3OqWFn8oMWe6KVVYV/DDPm8 0A== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3y6k466m2c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 May 2024 23:55:44 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 44LMZkKk002667; Tue, 21 May 2024 23:55:43 GMT Received: from brm-x62-16.us.oracle.com (brm-x62-16.us.oracle.com [10.80.150.37]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 3y6js8erce-6; Tue, 21 May 2024 23:55:43 +0000 From: Jane Chu To: linmiaohe@huawei.com, nao.horiguchi@gmail.com, akpm@linux-foundation.org, osalvador@suse.de, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 5/5] mm/memory-failure: send SIGBUS in the event of thp split fail Date: Tue, 21 May 2024 17:54:29 -0600 Message-Id: <20240521235429.2368017-6-jane.chu@oracle.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240521235429.2368017-1-jane.chu@oracle.com> References: <20240521235429.2368017-1-jane.chu@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.12.28.16 definitions=2024-05-21_14,2024-05-21_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 adultscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2405210182 X-Proofpoint-ORIG-GUID: 79GQpZ_jzEgc6Qmkdeqa_86YlEdLM5cy X-Proofpoint-GUID: 79GQpZ_jzEgc6Qmkdeqa_86YlEdLM5cy X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: E4039C0021 X-Stat-Signature: do9nyhyey9sdsu9nnjzihcjeecmjbgbd X-HE-Tag: 1716335750-385644 X-HE-Meta: U2FsdGVkX18xY6ISvjiWBRW0AgUxf2AVm1j4h/fcKLQ6z8sxdDtNMXCNO1y6f17F1un/GS6LO09/AK6dgcTxRXQvhaE6RMjg/T7IyGbUrq/qubW0PJHMKk6l0U28MA5ZxHMGuc307Up3XUxdnyO/ZTQUtdzkMmJw1SDN1tItoEwUZWIha2+3kq9MlJU8CzSsT5O2M8NFlR98j1Cx+h165NcXI3NKT9oZLaeTPSFSxVQlgZzgPzz4h1ncCGbLEnpsuWgc2XO4K9ZWfma4S2vJGjmy/SOjeigA40HKx8yu5XQx7nUMQNgcB5AkRFS2miMMKoP84TmL96Mi3RK7LMlQ+dC/ME5Zo2wSGm7h10F5BSJO3NG1/UCrNVK1dJ+Stz4uSVX4BCH+J6k1etfa73ZK73qh32PEhaAJk5CP7+YDAye6Tz7IW9yRui8/crco1Elf404Atqsoich21kb61VwbmwUzg9NdwaVDBNj3GLz7FKwU5lqIkkJItYMsZ1iue/31rEKPcuEWDE94XAJYZiLiMiLuydCoHl6fZxz4Q6XwJP/GpiEDVj+6XNcgdnPL80VbJ8KJAu/20upd4qftkcAFnCEqSyK4H1HXQ/jFYNeG/LdTqZG4DnO6Zy6Q4URMsjzV4uzn+AVFY96yk6mIrF9hlCN1zIR2ZEmhGLDvyqPgq1N6wHHEqJsbqlV8M+8oxJmsR4c5OUs9nK5PFVmCnfW1pu/G4IaKtH/xJpFWfguSKdNCM8eZ9AFhabZmWceCkDhc8ixWRjDQir7oDWdtF5Jxvpw3OSEjxrxR7qxZyPAHgYEPIfxg1POPbUE3gTs5w0BZr/HghdwjqgeD+v76EJwCK9wrXfImWWtnaN4OzbF5kXwtx0VymZOWmRIvbwwJDEk7jKzfQedaAYkH5F8XZIZaeTBvqmXO3SXdH7aBFYOlxkxmlZkUtFIUZD1GgfRJds+Q2GdaTK0A7ygFJV1KZ7F A/qs62is IvTilrEJDJpHlDxub+1saPwXcC8k0/iuYEB2pmzLjR1tA+MCa+KGe/KlgwEMw4Y/UY7auBxqrBgDMjfCRMBEtFVhXihSQZJqDYcP5mGaB3HXxRdms8DNkNafmiDdpk16RaZbQngStLtVckKQSIRyp1fDe/gWOgM9mzQIGfnqQOTLHy+Ce2pNizI7l0QDes+xjAMKCTwwj3XGqeqFp9EnzL+GR6MTyDev9DdDQRK4S5biwI2d2n+REtVgfF1MEt31Z6ue3baw8NGnjZWGwqVIeuUn/VrU2LIXUozpc 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: While handling hwpoison in a THP page, it is possible that try_to_split_thp_page() fails. For example, when the THP page has been RDMA pinned. At this point, the kernel cannot isolate the poisoned THP page, all it could do is to send a SIGBUS to the user process with meaningful payload to give user-level recovery a chance. Signed-off-by: Jane Chu Reviewed-by: Oscar Salvador Acked-by: Miaohe Lin --- mm/memory-failure.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 794196951a04..a14d56e66902 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1706,7 +1706,12 @@ static int identify_page_state(unsigned long pfn, struct page *p, return page_action(ps, p, pfn); } -static int try_to_split_thp_page(struct page *page) +/* + * When 'release' is 'false', it means that if thp split has failed, + * there is still more to do, hence the page refcount we took earlier + * is still needed. + */ +static int try_to_split_thp_page(struct page *page, bool release) { int ret; @@ -1714,7 +1719,7 @@ static int try_to_split_thp_page(struct page *page) ret = split_huge_page(page); unlock_page(page); - if (unlikely(ret)) + if (ret && release) put_page(page); return ret; @@ -2187,6 +2192,24 @@ 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 RDMA 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 folio *folio) +{ + LIST_HEAD(tokill); + + collect_procs(folio, p, &tokill, flags & MF_ACTION_REQUIRED); + kill_procs(&tokill, true, pfn, flags); + + return -EHWPOISON; +} + /** * memory_failure - Handle memory failure of a page. * @pfn: Page Number of the corrupted page @@ -2328,8 +2351,10 @@ int memory_failure(unsigned long pfn, int flags) * page is a valid handlable page. */ folio_set_has_hwpoisoned(folio); - if (try_to_split_thp_page(p) < 0) { - res = action_result(pfn, MF_MSG_UNSPLIT_THP, MF_IGNORED); + if (try_to_split_thp_page(p, false) < 0) { + res = kill_procs_now(p, pfn, flags, folio); + put_page(p); + action_result(pfn, MF_MSG_UNSPLIT_THP, MF_FAILED); goto unlock_mutex; } VM_BUG_ON_PAGE(!page_count(p), p); @@ -2703,7 +2728,7 @@ static int soft_offline_in_use_page(struct page *page) }; if (!huge && folio_test_large(folio)) { - if (try_to_split_thp_page(page)) { + if (try_to_split_thp_page(page, true)) { pr_info("soft offline: %#lx: thp split failed\n", pfn); return -EBUSY; }