From patchwork Mon Oct 2 19:02:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 147528 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1723702vqb; Mon, 2 Oct 2023 15:21:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEsZVhxxgSbtv4XV/8Z09kWhKOCf+3jgjv1vJ3YKbZSj1/h3ShZAfoCH45u6ytmEFOvB5E3 X-Received: by 2002:a67:fdd0:0:b0:452:8999:fb76 with SMTP id l16-20020a67fdd0000000b004528999fb76mr11017814vsq.21.1696285270215; Mon, 02 Oct 2023 15:21:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696285270; cv=none; d=google.com; s=arc-20160816; b=HWBQXc3CcbqCTsJMi4vgsYp6Gc3lwbuwSAOr5f64L92QVxlijn7RgOkhQ3lRP5MeIH TGC7Ijj6BRoy3LzDJzbYtI8zf6UEyuo9U6OfjBp8oobYaDWXgg8TSgacZ1hY7spm6VOS W28FRXTcpa0uBNokI+d5ccf3/FyKUd7He1UPuRF/rmo03+vm26+/rp3/TjJ14NtSQRMI /3O6p8XDcGAgE+tGZx7TjOk6oQw6JelLGqJQNoUs0/ShMt6Y+WubF+JY76rc0aGcYnfL kAJLFylYec1N0KsZ6mCvQrRYSoyXYRFav96gaEfrjMq2q7WO2sESbdPXNgH510EwDVeu 3h9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=9kykBRle4YMK7mud01a1hYzMlSj6W5nGXFWJBDbOBmY=; fh=SBSfwOQvgyu1A8eYcG159pTj9uI8b+3VoL9IDmcV7FA=; b=ZBI5zMg9ph6o8M6XWMTUnnlZEezrD18VCTSeZ3t1TFqUBBWgBDAkUrkZelYT7jgCLM Vie5Zd7LQ0CI/JRdVMx5u2Q47DVy/ATtGNdg3L/4h+YvlxIr95iuoW0NmNhIQvEgapC6 znOy7mht/y7bPdM9VcGdn3pmYvu9iImVH5/OucxG7AtmwMoXXDawHcjxhqOM3tyyWovV NzcXssdvDgnLk+waxEVBmiTYqoDU6b0lYSXZ8l58AFZgDFxR+9mM9jsuyxhO2yMkMup4 jCklCbjqbuzhMtbCrrLlzYggY/WQ7UoEXCdysThVF1qnM2SwQA5fmZ6wkOY6Dq54RzBL XTAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=p+vQGxcS; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=Yl8KGZUj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id j191-20020a6380c8000000b0056513361b4fsi27569837pgd.741.2023.10.02.15.21.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 15:21:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=p+vQGxcS; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=Yl8KGZUj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id DB2A580FDDF5; Mon, 2 Oct 2023 12:02:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238554AbjJBTCd (ORCPT + 18 others); Mon, 2 Oct 2023 15:02:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229696AbjJBTCc (ORCPT ); Mon, 2 Oct 2023 15:02:32 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FD4AAC; Mon, 2 Oct 2023 12:02:29 -0700 (PDT) Date: Mon, 02 Oct 2023 19:02:27 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1696273347; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=9kykBRle4YMK7mud01a1hYzMlSj6W5nGXFWJBDbOBmY=; b=p+vQGxcSM58OSSCcFE3oDZ5+j4OyScgJjZPScYZN+b437pQbfkb3VqwTQ1OqOG4Rr0f5jy llUUJoJpgg0AAKwOdB3fTghwhi6e7NmQlUwe4V4PbJ1ueA1fOjew9au3RJXpSx+MfzILur triwqY/SxNbN4D41Rz4l3LbXlC2tKveJkeT6tC4WFF51qPRv/dfMB7XH2RBeGU3Soyq2d8 HsrTdmmhKs4FXPMgUbiDPaEzzl0QEZXio364/tX+4UsztbxSH6FYjihmrqAixLRxIjeefj 9srBknaf2nJrR8HE6CLUeoiqlhC7eewyvHfJCPKOSEY1I0wCLZtFq+tkVy+SNg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1696273347; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=9kykBRle4YMK7mud01a1hYzMlSj6W5nGXFWJBDbOBmY=; b=Yl8KGZUjz4bE/sSLu8cjn7TsmZ91ClBmJmPA+QmapRRQlsqU83VAPW9knoSYmZ1aKqbc/n 9cvNlPbu7zQbwzAw== From: "tip-bot2 for Zhiquan Li" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/mm] x86/mce: Set PG_hwpoison page flag to avoid the capture kernel panic Cc: Youquan Song , Zhiquan Li , Tony Luck , Ingo Molnar , Naoya Horiguchi , Borislav Petkov , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <169627334714.3135.12336854585078188172.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 02 Oct 2023 12:02:54 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778684023405241519 X-GMAIL-MSGID: 1778684023405241519 The following commit has been merged into the x86/mm branch of tip: Commit-ID: cb17fd1dcdaea8f6508844c690b3ffd5da484800 Gitweb: https://git.kernel.org/tip/cb17fd1dcdaea8f6508844c690b3ffd5da484800 Author: Zhiquan Li AuthorDate: Thu, 14 Sep 2023 11:05:39 +08:00 Committer: Ingo Molnar CommitterDate: Mon, 02 Oct 2023 20:26:13 +02:00 x86/mce: Set PG_hwpoison page flag to avoid the capture kernel panic Kdump can exclude the HWPoison page to avoid touching the error page again, the prerequisite is the PG_hwpoison page flag is set. However, for some MCE fatal error cases, there is no opportunity to queue a task for calling memory_failure(), and as a result, the capture kernel touches the error page again and panics. Add the mce_set_page_hwpoison_now() function, which marks a page as HWPoison before kernel panic() for MCE error, so that the dump program can check and skip the error page and prevent the capture kernel panic. [ Tony: Changed TestSetPageHWPoison() to SetPageHWPoison() ] [ mingo: Fixed the comments & changelog ] Co-developed-by: Youquan Song Signed-off-by: Youquan Song Signed-off-by: Zhiquan Li Signed-off-by: Tony Luck Signed-off-by: Ingo Molnar Reviewed-by: Naoya Horiguchi Cc: Borislav Petkov Link: https://lore.kernel.org/all/20230719211625.298785-1-tony.luck@intel.com/#t --- arch/x86/kernel/cpu/mce/core.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c index 6f35f72..1a14e82 100644 --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -156,6 +156,22 @@ void mce_unregister_decode_chain(struct notifier_block *nb) } EXPORT_SYMBOL_GPL(mce_unregister_decode_chain); +/* + * Kdump can exclude the HWPoison page to avoid touching the error page again, + * the prerequisite is that the PG_hwpoison page flag is set. However, for some + * MCE fatal error cases, there is no opportunity to queue a task + * for calling memory_failure(), and as a result, the capture kernel panics. + * This function marks the page as HWPoison before kernel panic() for MCE. + */ +static void mce_set_page_hwpoison_now(unsigned long pfn) +{ + struct page *p; + + p = pfn_to_online_page(pfn); + if (p) + SetPageHWPoison(p); +} + static void __print_mce(struct mce *m) { pr_emerg(HW_ERR "CPU %d: Machine Check%s: %Lx Bank %d: %016Lx\n", @@ -286,6 +302,8 @@ static noinstr void mce_panic(const char *msg, struct mce *final, char *exp) if (!fake_panic) { if (panic_timeout == 0) panic_timeout = mca_cfg.panic_timeout; + if (final && (final->status & MCI_STATUS_ADDRV)) + mce_set_page_hwpoison_now(final->addr >> PAGE_SHIFT); panic(msg); } else pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);