Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1597442rdb; Mon, 2 Oct 2023 14:58:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF1+aULAlhHFLiXuwRAm2nzpmqH8a1iU32HaHfRMDKh6c5uong4GTN1cDOERTlDQoHW+9E2 X-Received: by 2002:a17:90b:4a42:b0:277:3afc:f27 with SMTP id lb2-20020a17090b4a4200b002773afc0f27mr1314356pjb.1.1696283905653; Mon, 02 Oct 2023 14:58:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696283905; cv=none; d=google.com; s=arc-20160816; b=nPtYd9h2nJDTPBGwkT9qQWsJYrnLdsLDEzK/TElqVsVbWJRMzU7f0p9SfUJ0n+W32W gcbzyz+kSKdONE5W7qgyiQzm4z2emzd0CTumySt53qeTC9kkNsEBsh4b6oJgH8iVkdBr 07BG5VqJApKoAmptvmPkcLWEUjlVEbHnqcweKJE4ESLOCXLg9GontcIPXCG6POvog40N 3rDbChjMrTgBXoOzQ7JAzM0O55Brk3i4tVa9CPjTxoSP3LeR/o3Wp7ubSdUwfCRagSzp LFZGV31jd3iHEC+gWyCyRwanNH4lHnZY9aem4+eKD36stMdnpoesrVhZEojewrp9NOoT OWqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:sender:dkim-signature; bh=DDwLuB+JnJ/fkY5rfqgAXIgE3qv2mbDu3+kGxrUmSpU=; fh=D6rZXy0fz8xYFeYHB14UUtyoPPgnD3GEUkwQ4OfPt/A=; b=y0WmyzGWtzfppqsbfs02CX6hdmJ4IFxPyIi/FOf7tQZrWSNZErSAvwITeoGGK2LnqS R+C0c3/zaM4sZC1O1pxYYnhHgxh7TPPyDYhjY5HEAfkodtJy6hPNujKiR5w4Ug3Rl9Mb 8L1Cyn4y25nmqoRlbO11hKWVL1/f4sx88RDSx3CklDgnS1rnySlX7Lgmsj3iGBSCDvWi SBMAkTKQspFRh95kguijKcefLzv4tpBFkW6mcGHHhMKmDKIcckd/xDSbGeLFaB3uQf30 IBI+Q+qtvYDOjayxKRljHj+2EFPhDAiEma9VdhqlbZlgR4e27LKhZAKEChWodPaeSci8 Pr5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Wy5w3GDK; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id ob17-20020a17090b391100b00279140ac5b3si9245249pjb.143.2023.10.02.14.58.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 14:58:25 -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=@gmail.com header.s=20230601 header.b=Wy5w3GDK; 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=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 7F68B8159632; Mon, 2 Oct 2023 12:06:22 -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 S238486AbjJBTGV (ORCPT + 99 others); Mon, 2 Oct 2023 15:06:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbjJBTGU (ORCPT ); Mon, 2 Oct 2023 15:06:20 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32E12AC; Mon, 2 Oct 2023 12:06:17 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-9b1ebc80d0aso11591666b.0; Mon, 02 Oct 2023 12:06:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696273575; x=1696878375; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=DDwLuB+JnJ/fkY5rfqgAXIgE3qv2mbDu3+kGxrUmSpU=; b=Wy5w3GDKGCCUYPQDQDRakluGy25n1ifSpE45YYFnbUmbHUtCDF5ipHmeKWuiaqWdPo U53McQCrsAmNqtewcY17qcod2Qnz4jjU/MLV1RulXkSZ/t5C+UXvxnPsjKoK93zxl0bo mRYlhrMabFfVFR+fuz/N5DDKAB3aB1jbEmNPOa5zinduftGT+m7t2jYK8Pat+hMtk/An vVxYqOfri/XJjHxT8UbIoh9dsHvf4qF3OLhbsDztdS7704a6+XhXgkKeh/lEOOuxKNvb BrnCdcA0C2jfHMPFKcWVafX1K4RWyf6Vv+aMTRHSNGuRm8Ntu7hyxkRg5B6kHs+ziqNj GdEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696273575; x=1696878375; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DDwLuB+JnJ/fkY5rfqgAXIgE3qv2mbDu3+kGxrUmSpU=; b=lSkvE8WymTAJRCfPnJgIM7YeVfij/EzNDmEA8ugOsMDpJoBai60B/JAXMN8vaul6Id p4eDpYbHsHMjXXhjNGp9Y2xDn9BdqdOSny8GuXMml4bgfvPsq9RKbhFHK1hu2fwn+GZt 7rgU7dnrJp9azMpo9rjsbJAgY2KT/SIJm+znsLXuCMPApzZ/sy2UN3B0y2xA/qCGLIMd tjjzpnK1id0CSeyb4x/vChCfoNqKSPzVBidg1CHQVsUKckKMTtTRnEZNyEZcXWGr6Ykt ocjJYRYqTFSzk7K7vsq5uXQFF3C3RKIJPOH8lVhQansq1pWiFIN7YkNSIHqxVWtx2iA4 OHTw== X-Gm-Message-State: AOJu0YxjNyOPj5vlNOhpa0EeC4Cy1y3JrPAARHXCD+4q4RzLEk43KMiZ jDpU7yWCKcbz0dWg15VHaFc= X-Received: by 2002:a17:906:256:b0:9ae:74d1:4b45 with SMTP id 22-20020a170906025600b009ae74d14b45mr12065034ejl.65.1696273575354; Mon, 02 Oct 2023 12:06:15 -0700 (PDT) Received: from gmail.com (1F2EF530.nat.pool.telekom.hu. [31.46.245.48]) by smtp.gmail.com with ESMTPSA id rp5-20020a170906d96500b0098e78ff1a87sm17405863ejb.120.2023.10.02.12.06.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 12:06:14 -0700 (PDT) Sender: Ingo Molnar Date: Mon, 2 Oct 2023 21:06:12 +0200 From: Ingo Molnar To: Zhiquan Li Cc: x86@kernel.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, bp@alien8.de, tony.luck@intel.com, naoya.horiguchi@nec.com, Youquan Song Subject: Re: [PATCH RESEND v2] x86/mce: Set PG_hwpoison page flag to avoid the capture kernel panic Message-ID: References: <20230914030539.1622477-1-zhiquan1.li@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230914030539.1622477-1-zhiquan1.li@intel.com> X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE, SPF_PASS autolearn=no 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:06:22 -0700 (PDT) * Zhiquan Li wrote: > Kdump can exclude the HWPosion page to avoid touch 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(), as a result, > the capture kernel touches the error page again and panics. > > Add function mce_set_page_hwpoison_now() 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()] > > Co-developed-by: Youquan Song > Signed-off-by: Youquan Song > Signed-off-by: Zhiquan Li > Signed-off-by: Tony Luck > Reviewed-by: Naoya Horiguchi > > --- > V2 RESEND notes: > - No changes on this, just rebasing as v6.6-rc1 is out. > - Added the tag from Naoya. > Link: https://lore.kernel.org/all/20230719211625.298785-1-tony.luck@intel.com/#t > > Changes since V1: > - Revised the commit message as per Naoya's suggestion. > - Replaced "TODO" comment in code with comments based on mailing list > discussion on the lack of value in covering other page types. > Link: https://lore.kernel.org/all/20230127015030.30074-1-tony.luck@intel.com/ > --- > 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 6f35f724cc14..2725698268f3 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 HWPosion page to avoid touch the error page again, > + * the prerequisite is the PG_hwpoison page flag is set. However, for some > + * MCE fatal error cases, there are no opportunity to queue a task > + * for calling memory_failure(), as a result, the capture kernel panics. > + * This function marks the page as HWPoison before kernel panic() for MCE. > + */ The English in this commit is *atrocious*, both in the changelog and in the comments - how on Earth did 'Posion' typo and half a dozen other typos and bad grammar survive ~3 iterations and a Reviewed-by tag?? The version below fixes up the worst, but I suspect that's not the only problem with this patch... Thanks, Ingo ================> From: Zhiquan Li Date: Thu, 14 Sep 2023 11:05:39 +0800 Subject: [PATCH] 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 6f35f724cc14..1a14e8233c5a 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);