From patchwork Fri Mar 19 02:44:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?eWFvYWlsaSBb5LmI54ix5YipXQ==?= X-Patchwork-Id: 12149841 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_2 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27807C433DB for ; Fri, 19 Mar 2021 02:44:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D9A5264E38 for ; Fri, 19 Mar 2021 02:44:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D9A5264E38 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kingsoft.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3BEB26B006C; Thu, 18 Mar 2021 22:44:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 36E986B0071; Thu, 18 Mar 2021 22:44:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 199506B0072; Thu, 18 Mar 2021 22:44:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0201.hostedemail.com [216.40.44.201]) by kanga.kvack.org (Postfix) with ESMTP id E76D16B006C for ; Thu, 18 Mar 2021 22:44:45 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 98C1A8249980 for ; Fri, 19 Mar 2021 02:44:45 +0000 (UTC) X-FDA: 77935080930.19.821763F Received: from mail.kingsoft.com (unknown [114.255.44.146]) by imf24.hostedemail.com (Postfix) with ESMTP id 19177A000245 for ; Fri, 19 Mar 2021 02:44:42 +0000 (UTC) X-AuditID: 0a580155-20dff7000005482e-2c-6054085166bb Received: from mail.kingsoft.com (localhost [10.88.1.32]) (using TLS with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.kingsoft.com (SMG-2-NODE-85) with SMTP id 17.4A.18478.15804506; Fri, 19 Mar 2021 10:11:29 +0800 (HKT) Received: from alex-virtual-machine (172.16.253.254) by KSBJMAIL2.kingsoft.cn (10.88.1.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Fri, 19 Mar 2021 10:44:38 +0800 Date: Fri, 19 Mar 2021 10:44:37 +0800 From: Aili Yao To: David Hildenbrand , Matthew Wilcox CC: , , , , , , Oscar Salvador , Mike Kravetz , Subject: [PATCH v3] mm/gup: check page posion status for coredump. Message-ID: <20210319104437.6f30e80d@alex-virtual-machine> In-Reply-To: <20210318133412.12078eb7@alex-virtual-machine> References: <20210317163714.328a038d@alex-virtual-machine> <20a0d078-f49d-54d6-9f04-f6b41dd51e5f@redhat.com> <20210318044600.GJ3420@casper.infradead.org> <20210318133412.12078eb7@alex-virtual-machine> Organization: kingsoft X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Originating-IP: [172.16.253.254] X-ClientProxiedBy: KSBJMAIL1.kingsoft.cn (10.88.1.31) To KSBJMAIL2.kingsoft.cn (10.88.1.32) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrELMWRmVeSWpSXmKPExsXCFcGooBvIEZJg0NSnZTFn/Ro2i6/rfzFb XN41h83i3pr/rBYf9wdbXGw8wGhxZlqRxe8fc9gcODw2r9Dy2PRpErvHiRm/WTxeXN3I4vHx 6S0Wj/f7rrJ5bD5d7fF5k1wARxSXTUpqTmZZapG+XQJXxrT+sywFe4UrLt+7ztrAeIC/i5GD Q0LARGLTZJcuRi4OIYHpTBLz5n9nhXBeMUq8X3wAyOHkYBFQlXhzfSobiM0GZO+6NwssLiLg J3Fr6UcWkAZmgT4miY6VR1hAEsICThI/310BK+IVsJK4sX42M4jNKWAtcXD1F7BBQgLnGCX6 55uC2PwCYhK9V/4zgdgSAvYSbVsWMUL0CkqcnPkEbCazgI7EiVXHmCFseYntb+cwQ8xRlDi8 5Bc7RK+SxJHuGWwQdqzEsnmvWCcwCs9CMmoWklGzkIxawMi8ipGlODfdaBMjJFpCdzDOaPqo d4iRiYPxEKMEB7OSCK9pXkCCEG9KYmVValF+fFFpTmrxIUZpDhYlcV7HSKCUQHpiSWp2ampB ahFMlomDU6qBqaeq9ZDvSplibjWzTbJdx/QXf/ravG9/rWbIUR+HHcvOaCdV8x+WMM9fv5hL seKY94RdnN/sn7wOu/zTwXmu4QNZsa0160Ri7q+6wbMzycP5POv7Xc01U2r2rTqw89QEqwk8 /0wPWmcsOvcp383rQjVXneTjhHPTuIKX7m+Zyyoq+Crs/v07mtxhr7b+TIjif/FzRozFYnuP FUx7/yd316UUeznOvxn7aF/o5rTr/fKS2c/+Xd/j8yDFVFGK4ZLa0b1+G87yLPO4wPYu+9rN xL6sp8Yrzk70F5idofe4TuDE5U//rbdNX1qU6SzJbrQnWHCe5Jezb68HtKknfPvUnfIgMGW9 mE/chKr2jquOZUosxRmJhlrMRcWJAJ9dPw4FAwAA X-Stat-Signature: oy1dcj5pr5c3oqnbua3ym44ytebdrttt X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 19177A000245 Received-SPF: none (kingsoft.com>: No applicable sender policy available) receiver=imf24; identity=mailfrom; envelope-from=""; helo=mail.kingsoft.com; client-ip=114.255.44.146 X-HE-DKIM-Result: none/none X-HE-Tag: 1616121882-325511 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: When we do coredump for user process signal, this may be an SIGBUS signal with BUS_MCEERR_AR or BUS_MCEERR_AO code, which means this signal is resulted from ECC memory fail like SRAR or SRAO, we expect the memory recovery work is finished correctly, then the get_dump_page() will not return the error page as its process pte is set invalid by memory_failure(). But memory_failure() may fail, and the process's related pte may not be correctly set invalid, for current code, we will return the poison page, get it dumped, and then lead to system panic as its in kernel code. So check the poison status in get_dump_page(), and if TRUE, return NULL. There maybe other scenario that is also better to check the posion status and not to panic, so make a wrapper for this check, Thanks to David's suggestion(). Signed-off-by: Aili Yao --- mm/gup.c | 4 ++++ mm/internal.h | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/mm/gup.c b/mm/gup.c index e4c224c..dcabe96 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1536,6 +1536,10 @@ struct page *get_dump_page(unsigned long addr) FOLL_FORCE | FOLL_DUMP | FOLL_GET); if (locked) mmap_read_unlock(mm); + + if (ret == 1 && is_page_poisoned(page)) + return NULL; + return (ret == 1) ? page : NULL; } #endif /* CONFIG_ELF_CORE */ diff --git a/mm/internal.h b/mm/internal.h index 25d2b2439..902d993 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -97,6 +97,27 @@ static inline void set_page_refcounted(struct page *page) set_page_count(page, 1); } +/* + * When kernel touch the user page, the user page may be have been marked + * poison but still mapped in user space, if without this page, the kernel + * can guarantee the data integrity and operation success, the kernel is + * better to check the posion status and avoid touching it, be good not to + * panic, coredump for process fatal signal is a sample case matching this + * scenario. Or if kernel can't guarantee the data integrity, it's better + * not to call this function, let kernel touch the poison page and get to + * panic. + */ +static inline bool is_page_poisoned(struct page *page) +{ + if (page != NULL) { + if (PageHWPoison(page)) + return true; + else if (PageHuge(page) && PageHWPoison(compound_head(page))) + return true; + } + return 0; +} + extern unsigned long highest_memmap_pfn; /*