Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp21734lqp; Tue, 21 May 2024 16:56:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV29YNe5rDh+0Rh60ddnIY5gZlE3n4/QmK+a1/JvMTFghoXLKGihqkYhoh7xT73d6HnT8cUVJZzF22CSWJyn0Skwuaw+seesUGxKbHYlw== X-Google-Smtp-Source: AGHT+IEwfAhTr2midxFjMZKAdPkYRfzqtCu+3F+F9awii+JmGThszJlA9jgbtCC+dK4NMXRBIDtW X-Received: by 2002:ac8:7d45:0:b0:43e:747:491f with SMTP id d75a77b69052e-43f9e08938emr5439131cf.6.1716335775910; Tue, 21 May 2024 16:56:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716335775; cv=pass; d=google.com; s=arc-20160816; b=s/xmeofZE8fWZYshMfRba5yqkciEhNUn47h8KEFryDSu+AT1U0b1qNf3E2gfI+louC jRJjQDzBSvKnDtzXHrGRWJA75U5fiAeBiDAtKLVXie6Luw0PGIsQXOcXxuPgi5fi3Wmm UBcFnhXbtlrK88z16+M/jffBN/iktyd7X09Z7kqGX0SuY/9rI8YJOaUhPN29/l/0p4J3 0Yj7nc7DrWPsknDzG70jHVuNVbMDBUuozh4w93KIueFV7pg3mY5Nxq9Fi+kbh2ccIRQi DqxXPYAECBl6QoHk0e9Q7VGvxQKnYX8HlDLcUXmCRlwjfjexiXQvCmLoBAe6FEDbrROt /g+w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=I3L1LQIelw9oqT+0T41Q58pEC5gWfYbgn8T4h8gRVP4=; fh=U9HDw+13QAqYHhevvQoNs+C9ejuRAN20V1D1XLEiQzY=; b=Z+1UODYN8sbb2yqwFKrsMrnGdWDVyzamkHvq/pYxMAJZGfzAIhhRqVG+9XRIJlrbFf SybLJIAnSrjA9kplCWzipH1RT5yfjLtn+4RXazDMnpv8gkBeVdQwXY/mWrStAFcdGk5C 6GFWphXvkWeE+jZHqL2oct2/RmN8QYptfyYHNrNgF8eAVvj4UwIwg/Xw3VV/7VjHgNHK 3tHIG1EvMg7unmrtUpKG0Gz2Zm39lWBgoCGffyoC5IckdYWmrzX/ljnNxJy2GgnCAZ3H 9k69ep3Tb5CteGl9a+RLfEb8gAOYfz0GXuH6/gHLUhmERogaD6Awqk+Y6JOlp83dfNN3 lxmQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-11-20 header.b=cIVRSMsq; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel+bounces-185537-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185537-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=oracle.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43e047b40d5si256006991cf.754.2024.05.21.16.56.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 16:56:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-185537-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-11-20 header.b=cIVRSMsq; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel+bounces-185537-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185537-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=oracle.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 92D141C20FD6 for ; Tue, 21 May 2024 23:56:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2ABAC14A60D; Tue, 21 May 2024 23:55:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="cIVRSMsq" Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC524149DEC for ; Tue, 21 May 2024 23:55:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.177.32 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716335757; cv=none; b=CiGkIHBVdpcXZLo3wqdBRwod1yt+wThlyCalTuxTr3Q8Ni3tm+VLniG7uMHH9y3FhKkSCEBlu+Jgwf7/CrMAW568fsebE2Sq2Us9FzIAbmokBXXIDFI+gaDTcdAEIeZC8C4m3vTOolTGZmqmgFS+/IifTmqOkVpNm3MBywrImpw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716335757; c=relaxed/simple; bh=Kc38EzOfeWAlb4bBoUH+4kvKqzdFABT2qnEca+zNUkg=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bfRUslqh914urf+xmn3CMS0rxyrRiJeSgiPZono/DotUgszxoPMAA8gd3dBqYyvf9x4Lz3gIeNkH5vc5aECWR22qNVc5q2RdoaLWmOg1qt+BEtDhvFNz+4mebQg9Wn7nnHNV77m4UPc+IHN4K9jxamg1BjlaHvQkl9ZmCgwxJqk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=cIVRSMsq; arc=none smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 --- 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; } -- 2.39.3