Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp325258pxf; Wed, 31 Mar 2021 04:27:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3GYi7s6ATnDKkzMriK8G1+u+KTwC0Xh7na8Q5+pnXzYw02n4s4nv2f1XtOTOhSFBKlEiR X-Received: by 2002:a17:906:cc89:: with SMTP id oq9mr2953908ejb.258.1617190034542; Wed, 31 Mar 2021 04:27:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617190034; cv=none; d=google.com; s=arc-20160816; b=qLhvPog+tzHN32iFykRaUrAEAwaTnX34W9DqDwVm+WS/xge5OWFWLOkZDHh0dfl/Q0 ZUxYNFaAXxf6N5SH1HXubFYqp5j0VOE9TUDxM0vMttB/BJaRmZbxklt62jk/25EhcmVN 36szmLnq537Sgext4MRV4wle9kfehe6fnMB9I+A01a3OhcBHR2U+i3QzUn29Ptj2uMkV 6ejFej4OSvDAcqx2sYolu8nhWFhU8MdEv/jPVnoenBVyMj6D6giCay0OeuIUcmRMs6cS UR3vhvoOo7fvEG2DEMtnSSx4kIFF+W9vVBI2z18AjynpODP17xPWnaTCgVQ+UCB3itTj Ic+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=1W23Bb/rfKoEGPfWLFU+3PzhTsKk8POKpZ7oxw3dYKI=; b=Empzau179lnSPDWjgW8+kMWHgOfWgOKFArNFE+g4nRia55G26K6RFACvI8syM0gfVS zYLFYCAup2jdfh18HmBCeH6SaMefjwCtLdBFhSGX5+hnfsMb1vk9AzqBoWMQ1ilkDjn0 8+L9wy10yRgrQKl9VQy5v+kESAfbdEWAH2BFySlALG2PU3QfJkkgq0FJeu/jLwU5T2Rz pkldPIHY8eYsTIVZTyxgxorWQuyE6h0wYYYoEzSgwy86LyuFv7+7EkBwl9azOjRynWxZ 39fASPAeV+Ft02pcTVWHAv/c3E20FPxD0L3TMPZzXQiuGkwb/v00m5VJC3MNuMD70VkF gRdA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hc31si1386502ejc.524.2021.03.31.04.26.51; Wed, 31 Mar 2021 04:27:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235222AbhCaLZx (ORCPT + 99 others); Wed, 31 Mar 2021 07:25:53 -0400 Received: from mail.kingsoft.com ([114.255.44.145]:18494 "EHLO mail.kingsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235140AbhCaLZn (ORCPT ); Wed, 31 Mar 2021 07:25:43 -0400 X-AuditID: 0a580155-f55ff70000015057-03-60645c357ab1 Received: from mail.kingsoft.com (localhost [10.88.1.79]) (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 82.14.20567.53C54606; Wed, 31 Mar 2021 19:25:41 +0800 (HKT) Received: from alex-virtual-machine (172.16.253.254) by KSBJMAIL4.kingsoft.cn (10.88.1.79) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 31 Mar 2021 19:25:41 +0800 Date: Wed, 31 Mar 2021 19:25:40 +0800 From: Aili Yao To: "HORIGUCHI =?UTF-8?B?TkFPWUE=?=(=?UTF-8?B?5aCA5Y+j44CA55u05Lmf?=)" , "Luck, Tony" , "Oscar Salvador" , "david@redhat.com" CC: "akpm@linux-foundation.org" , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , "yangfeng1@kingsoft.com" , , Subject: [PATCH v3] mm,hwpoison: return -EHWPOISON when page already poisoned Message-ID: <20210331192540.2141052f@alex-virtual-machine> In-Reply-To: <20210309143534.6c1a8ec5@alex-virtual-machine> References: <20210304144524.795872d7@alex-virtual-machine> <20210304235720.GA215567@agluck-desk2.amr.corp.intel.com> <20210305093016.40c87375@alex-virtual-machine> <20210305093656.6c262b19@alex-virtual-machine> <20210305221143.GA220893@agluck-desk2.amr.corp.intel.com> <20210308064558.GA3617@hori.linux.bs1.fc.nec.co.jp> <3690ece2101d428fb9067fcd2a423ff8@intel.com> <20210308223839.GA21886@hori.linux.bs1.fc.nec.co.jp> <20210308225504.GA233893@agluck-desk2.amr.corp.intel.com> <20210309100421.3d09b6b1@alex-virtual-machine> <20210309060440.GA29668@hori.linux.bs1.fc.nec.co.jp> <20210309143534.6c1a8ec5@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 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [172.16.253.254] X-ClientProxiedBy: KSBJMAIL1.kingsoft.cn (10.88.1.31) To KSBJMAIL4.kingsoft.cn (10.88.1.79) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrNLMWRmVeSWpSXmKPExsXCFcHor2sak5JgsO2xvMWc9WvYLL6u/8Vs cXnXHDaLe2v+s1pcbDzAaHFmWpHFmwv3WBzYPRbvecnksenTJHaPEzN+s3i8uLqRxeP9vqts HptPV3t83iQXwB7FZZOSmpNZllqkb5fAlXHvfgNzwRuhivWrJjA1MD7l62Lk5JAQMJHYcKmL GcQWEpjOJHH5qlQXIxeQ/YpRYurK70wgCRYBVYm9v1pZQGw2IHvXvVmsIEUiAlcZJRbem8oO 4jAL9DFJ7Nq+nLGLkYNDWMBfYuLPUJAGXgEriaPXF4EN4hSwljhyfAozxIZWVok9r6+AreYX EJPovfKfCeIke4m2LYsYIZoFJU7OfAK2mVlAR+LEqmPMELa8xPa3c6DOVpQ4vOQXO0SvksSR 7hlsEHasRNOBW2wTGIVnIRk1C8moWUhGLWBkXsXIUpybbrSJERIfoTsYZzR91DvEyMTBeIhR goNZSYRX+EBighBvSmJlVWpRfnxRaU5q8SFGaQ4WJXHe7w+SEoQE0hNLUrNTUwtSi2CyTByc Ug1M0w+uiuasi45LFPxc96KmyCTs4erFCTxVb5pLrLM/3f+z6fXuQ4UvnJlm3Jz1N9T3RO57 HZ9JfBfucH6bvP7SEeuvb3eUhLnf4eXxUzgQvJubncU24innSqtPPmcsWjifsN6/3Xz/2o74 gr8bZ8gemaNfxM7/bQVD4x73LZuK7ev3B1dNMWFTLopcp7yrUUi3Il4hpL6jaMpXg9KtsZPV vovWvNy37l4M5/Wjr+6ufeTzrczjrvPVnfPSLvRM33D/47rVx6Jmpx8RPlNjXH7QWtT5be2m 51VTLFtFXrVuqnyzROj5/UzjMnXrvLUMZw/d3sz4u1wnKiXq1cQcN+/1CzMmdraaPH4c5/ZZ Y+nzCCWW4oxEQy3mouJEAHFYImD+AgAA Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When the page is already poisoned, another memory_failure() call in the same page now return 0, meaning OK. For nested memory mce handling, this behavior may lead to one mce looping, Example: 1.When LCME is enabled, and there are two processes A && B running on different core X && Y separately, which will access one same page, then the page corrupted when process A access it, a MCE will be rasied to core X and the error process is just underway. 2.Then B access the page and trigger another MCE to core Y, it will also do error process, it will see TestSetPageHWPoison be true, and 0 is returned. 3.The kill_me_maybe will check the return: 1244 static void kill_me_maybe(struct callback_head *cb) 1245 { 1254 if (!memory_failure(p->mce_addr >> PAGE_SHIFT, flags) && 1255 !(p->mce_kflags & MCE_IN_KERNEL_COPYIN)) { 1256 set_mce_nospec(p->mce_addr >> PAGE_SHIFT, p->mce_whole_page); 1257 sync_core(); 1258 return; 1259 } 1267 } 4. The error process for B will end, and may nothing happened if kill-early is not set, The process B will re-excute instruction and get into mce again and then loop happens. And also the set_mce_nospec() here is not proper, may refer to commit fd0e786d9d09 ("x86/mm, mm/hwpoison: Don't unconditionally unmap kernel 1:1 pages"). For other cases which care the return value of memory_failure() should check why they want to process a memory error which have already been processed. This behavior seems reasonable. Signed-off-by: Aili Yao --- mm/memory-failure.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 24210c9bd843..5cd42144b67c 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1228,7 +1228,7 @@ static int memory_failure_hugetlb(unsigned long pfn, int flags) if (TestSetPageHWPoison(head)) { pr_err("Memory failure: %#lx: already hardware poisoned\n", pfn); - return 0; + return -EHWPOISON; } num_poisoned_pages_inc(); @@ -1430,7 +1430,7 @@ int memory_failure(unsigned long pfn, int flags) if (TestSetPageHWPoison(p)) { pr_err("Memory failure: %#lx: already hardware poisoned\n", pfn); - return 0; + return -EHWPOISON; } orig_head = hpage = compound_head(p); -- 2.25.1