From patchwork Fri May 24 21:53:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jane Chu X-Patchwork-Id: 13673864 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 486ABC25B74 for ; Sat, 25 May 2024 00:35:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 89B046B0088; Fri, 24 May 2024 20:35:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 824456B0089; Fri, 24 May 2024 20:35:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6C4876B008A; Fri, 24 May 2024 20:35:44 -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 478F06B0088 for ; Fri, 24 May 2024 20:35:44 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id EA3D7A1FBC for ; Sat, 25 May 2024 00:35:43 +0000 (UTC) X-FDA: 82155050166.14.13BBAE1 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf17.hostedemail.com (Postfix) with ESMTP id C3DCE40002 for ; Sat, 25 May 2024 00:35:41 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=lYxXVGvI; spf=pass (imf17.hostedemail.com: domain of jane.chu@oracle.com designates 205.220.165.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=1716597342; 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=NItRoZidtl5jZFk2E3c9bRVzuOiNACCqAvB+zCVBjYM=; b=vCGxEO4G0364ZwHdOAxOauHzXrnZVzl+3Smjglr+dgAdiaR7U54SLtUcSI9+LD6EIl2XmC HAXQiwY5IYfIab1cPtX0oDPQ7GXjXf56CUKn5QYwVwBUwLtapQ+hgMh+Iq6d5us+svOXiH mOrIr8Hh+q6sv0BmZoCO3tnHkfQLX30= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716597342; a=rsa-sha256; cv=none; b=rJfbj446MyzUR2R2fDLMtiXT170ZDlyFoByePYZ4627FD0jyYIFVskir+S4jR3twPmrDQl q7X7SCRzPWkJMkhlYFkifOd1md02JhOKO4DOMmL3+G5yh6bvW+eHardyUOaKzSZChyINc7 qPC/sq4sryMhOYJOHlsx5FmxThSlsOE= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=lYxXVGvI; spf=pass (imf17.hostedemail.com: domain of jane.chu@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=jane.chu@oracle.com; dmarc=pass (policy=quarantine) header.from=oracle.com Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 44OHcEG8021717; Fri, 24 May 2024 21:53:51 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=NItRoZidtl5jZFk2E3c9bRVzuOiNACCqAvB+zCVBjYM=; b=lYxXVGvInCRrVClVw+SA1gLS/PoZSLuThuPH2VElXUrdvyUuoUBAjy9MpgU6YzWceXem BZbTLq1JzVtnDMGh6Uh7mTdNen0dxTm8UUbCdQJAYXIaP3yd5zN6XyZ+ngfrMoAE6WOF KWRl1cKdzdZAihheh+6KJSVT5CTtnwNWg1tLBaZTXw69Fqqiozft4SWpyJH+rER00ZSb 2b9tOmhozHoN9sEHi6gCCWEfVPjFto+TkY4Ja4x2K5laurVTgs0/19bHk5bVjOmupBSQ RjuNJwWEn6CJlXSSQVTmrC4tHvyaMbK1bKokqG6Aya5gJJNurZAMxygDOTuEvYQVTePE yA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3y6k8ddd0n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 24 May 2024 21:53:50 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 44OLjG1Q035956; Fri, 24 May 2024 21:53:50 GMT Received: from brm-x62-16.us.oracle.com (brm-x62-16.us.oracle.com [10.80.150.37]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3y6jscbsu0-6; Fri, 24 May 2024 21:53:49 +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 v4 5/5] mm/memory-failure: send SIGBUS in the event of thp split fail Date: Fri, 24 May 2024 15:53:06 -0600 Message-Id: <20240524215306.2705454-6-jane.chu@oracle.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240524215306.2705454-1-jane.chu@oracle.com> References: <20240524215306.2705454-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-24_08,2024-05-24_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2405240158 X-Proofpoint-GUID: hPXbkI42xBQJuar7JkbK3Zr9qXE31038 X-Proofpoint-ORIG-GUID: hPXbkI42xBQJuar7JkbK3Zr9qXE31038 X-Rspam-User: X-Stat-Signature: m9nb9ki6a4jxdfx3mr9dt5goiytx7dur X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: C3DCE40002 X-HE-Tag: 1716597341-601201 X-HE-Meta: U2FsdGVkX19inrOnZbQ3e4zfw0oavmeLvgD+Vfcp3F3FqXVGDovAOLTo7li0D5gh+Dmsno7DXXPLWwYxVbgKPWzEG45iuLqaVoYf6xLAjHHRpoemAl3EEL1hHzx9RcBBvFT6AVSS9ihANgAbkiqAK8toPJr6dc3ow5EbxFpfBYbKin5I92iTCH8FPZyapK1uHgjk0sh3jGgf6bYME+yY3WHK63gOHdmdQ/V476ik99v9X2EpV6aJPrBDgls7J9BI19yfKzgzpHRztY+RkvAt9SppmSQX8iRfrksJ79aho51IESJotgKNwCoKVbz6L9lFNVlAzPzGe29B6JqV9ghUsGLw1Rsf5jcJSAkIc2+tmH9uKoQBJGJ+UKcQ3Vkscd3E099FnRdD8MRRZJW4+fFwdYj/3gFve2kNW+CiGUDxYYYVECC3Qx/81onVclIZbSSrYX96VliwY8Mgz/+HOnJLjRVXtzAqeLt4PXng5l26/scxcutSYecwVVdko8aDgvU9n73JSLhAOaHu6yYwDPE/1kblNy/ilfsuhrs60QVXMmd60CcqrAjQg/NXgPnQRlQge+70u06UQoO5LCvWAhJkoL/vZSA2aeQUjNIoHAwDLIs8WzHUQuvd9LaVmeql9UVgv/ccZ4rHCNd3M4lnxb3xTsGtt5dGN4hk36VpMGs+MDle5NexWKOnPBw3hsUp28kOmErLmx4xts7vSukKoXLWsHX1Y1hFe1ySMbkB9kESdNpTBumAwtDFWItxhBZF5nT1TbCSWbAFTHOhu99ElJ9mfBLr6LedeEuqOa4tqK4tkmtujATujLFUexhB3s3Os87sfY90JCcCF0u3D93fBC0Zm5qO0d838fITrEbnRY0xMv3818TM1fbfkyLDlyTZ7SLeK94bBxKpNQTV777wdwt9ENC8e9QtO2Dpsdt7MM4uXEVjK3M97bM88525aItH1gQmJXCObq6BKMIwbFl8pcG WS3NvUIK PaXHCmXUTJeCa/t124iYHQZXK74p9Npekj5NZnPuBdno2a9sM5m3JUtLQTub+rMre5GT4z7K50yLGN4hWnU7mPuSgS1XwGTtQ7zi5lu8V3pPZGpe95YxXBt8mHYKnWqrWVxWKG66CuqSfRuJ3ftxsvJ2XlKaPNQzwuSLi6JOSmx2S+idZDYnSyByZA+6Av4pFvLi1Ua/n1dUBQ02pdAKu6q0tf9Fio4Iw+h+vJItGr9AuNCQZlXEET34DXWX59R91fkXVJAYk7sc4zeYf/+cNzHqFjlg4ciZ89rydDao37YrUo0OnAobgt8rGVVTSpmfgbKju82BLrKI6c5DXZLSeoB4ULzsIUPsT73g/CdNI2dObcKXU2XsC9U4oUTkfM8EdGlBB4n/+bE50/1MQjMfyoOAeyQ== 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 | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 85659dd0ea32..dcca7297a94c 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; @@ -2186,6 +2191,22 @@ 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 void 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); +} + /** * memory_failure - Handle memory failure of a page. * @pfn: Page Number of the corrupted page @@ -2327,8 +2348,11 @@ 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 = -EHWPOISON; + 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); @@ -2702,7 +2726,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; }