Received: by 2002:a05:7412:2a8a:b0:fc:a2b0:25d7 with SMTP id u10csp504523rdh; Wed, 7 Feb 2024 10:53:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IG5lAxbQKy2vs40kv6mXhTJMnxqwjMiF+sf2KyGkK3x2eq3I5Mqa99/mJA4UcOJuUZ6D2eb X-Received: by 2002:a17:90a:3484:b0:296:5e07:7a87 with SMTP id p4-20020a17090a348400b002965e077a87mr3698422pjb.26.1707332010312; Wed, 07 Feb 2024 10:53:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707332010; cv=pass; d=google.com; s=arc-20160816; b=1EQgh0+m+LFqzE6+XF9+aIKMG4eoZuiDL72nsziHmrmaluWM5nS3GgyEERmvv5h593 No47U33K2+Fjqjr/j2IWvmFoVLA8kwSsmnVs5afs2+RyimmyuMgjdjUZimpXBofY/eLN 0qVm43W2ZKQooaL0mkOEUBKOts+F8NuMBcHA9WOXNCKWOyhUXA0nBUUVCN/kKOW5m/3j nY3Mi13Y9SRVbKDs4uxC7wrjj19FgWsOdzSYQQHtZV6WYbSXvWKt21xNLxmswuiaSCvu PfjLjRbCusEfbumDQNr4Pc9l9xtMUOm4aUnmAf3E+W3Ks1Nlkbu8FLtjz0dB4aDdYE3Z IQ+w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature:dkim-filter; bh=+euICXmQceRDTVsASTkgUeNDpBza5bVSfxOZzTFcd4I=; fh=xziXSO+2Op7rQf6DbCjZXw/hjpBgPmn0RMzTWevzOgA=; b=xxFaWqX/hnCQtBTC5cl65V5mn7evebe+xJL2gjxuHAD/hVua++YALl3qgmyCg/8dF0 o/TCOwGJz5NT578Mw0/EAvMEe6hbQ+brZZGWk28+YQYv611do4Qre5CT9KkLeblVt6OT IcZ8WvWPhMvTZPQ/Oq78oDuufrjQzSEe2vGYacBb+RuEjYMdotStYNOQMJW5QRMKbwh1 7KfwGjjMpasILKnJ4nngck8xTjSknYS+8pZLFLl0fLi97WGiNX5gAcuNxrgXPBgcjXYF YJtok7N/74gKwd0z3WUhlhuU4n6PE6LcWIgqtYHhNIPflbS+GcnHCiCoVz+fjIMh47lz owuA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@zytor.com header.s=2024011201 header.b=nWXkN37R; arc=pass (i=1 spf=pass spfdomain=zytor.com dkim=pass dkdomain=zytor.com dmarc=pass fromdomain=zytor.com); spf=pass (google.com: domain of linux-kernel+bounces-56956-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56956-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com X-Forwarded-Encrypted: i=2; AJvYcCX5ebLcgACCYwoReQyJQasMOV39BAr84NMmEF87cjTGSLlEgqPX0gu8eBP1DYyDLbLiqNK6dXS1NAJ7aqGsEzH8hNsFNdzh694Nnjy29w== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id o5-20020a17090ac70500b00296548b467bsi3987742pjt.1.2024.02.07.10.53.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 10:53:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56956-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@zytor.com header.s=2024011201 header.b=nWXkN37R; arc=pass (i=1 spf=pass spfdomain=zytor.com dkim=pass dkdomain=zytor.com dmarc=pass fromdomain=zytor.com); spf=pass (google.com: domain of linux-kernel+bounces-56956-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56956-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 4A5ED282CBF for ; Wed, 7 Feb 2024 18:53:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8F2D786ADD; Wed, 7 Feb 2024 18:46:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=zytor.com header.i=@zytor.com header.b="nWXkN37R" Received: from mail.zytor.com (terminus.zytor.com [198.137.202.136]) (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 634A185C63 for ; Wed, 7 Feb 2024 18:46:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.136 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707331564; cv=none; b=kzTlkC+k0HWLqKnQ2GX4yz3Jq8NJ6/V08jbfyntZrJbjAH9cTuOFwnuuGteLIXaD49m4Z/DhnJgtH6gp4rWJJeOrs81Tp6/WyWkmGSJG1e0iSFAjwBgc5f0/yCAWhaUPdzM4KqATpqYEp0pXL84BE/nlpkRaUW6NfCn7LqLMXmc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707331564; c=relaxed/simple; bh=mlfUdvF3nuFmNk1lDQ0dgsIzWOBiMVa8ptQk84jgnhE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=NeeujbsdHjs9wHQpArlOjSpRSIgckIh5AeZSw+Mfcr1OELZGysaaHRtV9RH0hvkwQDcH4LkY/LHV5LSY45f9fhR/pf9ssygqFdnz6GaK+Z5+L92NTZniSlMCVNezwOirpRLGh2aTKx1GSrcNI3JdoG/YHqx4YP5wox/kKcDjf/o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zytor.com; spf=pass smtp.mailfrom=zytor.com; dkim=pass (2048-bit key) header.d=zytor.com header.i=@zytor.com header.b=nWXkN37R; arc=none smtp.client-ip=198.137.202.136 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zytor.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zytor.com Received: from [192.168.7.187] ([71.202.196.111]) (authenticated bits=0) by mail.zytor.com (8.17.2/8.17.1) with ESMTPSA id 417Iix0H2706018 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NO); Wed, 7 Feb 2024 10:44:59 -0800 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 417Iix0H2706018 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2024011201; t=1707331500; bh=+euICXmQceRDTVsASTkgUeNDpBza5bVSfxOZzTFcd4I=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=nWXkN37RV9vpIGiituFfLtXtutGmqWdL84/jxvEpeis7Yc0WOHpY856xKPmi/Id9k LVBSP05VRbGtIJJL9qJf+Ob8wkg1hGJbSxZNpbfYoaekLbkA4MWrBD9l28hSC7tyO4 re9oNgitRU0tzMDjMIRiLUoqE1OfBCiyMzKGyYwq66JDa0n+Ypam6kyW6vYGk32i19 lSGKDWGGkWsICil0WA6oFSeiUeenDbhpuBGN5N1dArxD+ZP5iuXgN6b2UNa5bMF9pG svtlCYpqxQpDJf+D5ZANrcM5M4//ycqEyOCZJaf9JfqAfQdV0L0/ng0Z52/FN6+Esv eCoKiUhOKVQuA== Message-ID: <0fabf792-3a9e-48c9-9f83-286905b5b2d3@zytor.com> Date: Wed, 7 Feb 2024 10:44:57 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] x86/nmi: Fix "in NMI handler" check To: paulmck@kernel.org, Breno Leitao Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , leit@meta.com, Mark Rutland , Ingo Molnar , "open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)" References: <20240207165237.1048837-1-leitao@debian.org> Content-Language: en-US From: Xin Li Autocrypt: addr=xin@zytor.com; keydata= xsDNBGUPz1cBDACS/9yOJGojBFPxFt0OfTWuMl0uSgpwk37uRrFPTTLw4BaxhlFL0bjs6q+0 2OfG34R+a0ZCuj5c9vggUMoOLdDyA7yPVAJU0OX6lqpg6z/kyQg3t4jvajG6aCgwSDx5Kzg5 Rj3AXl8k2wb0jdqRB4RvaOPFiHNGgXCs5Pkux/qr0laeFIpzMKMootGa4kfURgPhRzUaM1vy bsMsL8vpJtGUmitrSqe5dVNBH00whLtPFM7IbzKURPUOkRRiusFAsw0a1ztCgoFczq6VfAVu raTye0L/VXwZd+aGi401V2tLsAHxxckRi9p3mc0jExPc60joK+aZPy6amwSCy5kAJ/AboYtY VmKIGKx1yx8POy6m+1lZ8C0q9b8eJ8kWPAR78PgT37FQWKYS1uAroG2wLdK7FiIEpPhCD+zH wlslo2ETbdKjrLIPNehQCOWrT32k8vFNEMLP5G/mmjfNj5sEf3IOKgMTMVl9AFjsINLHcxEQ 6T8nGbX/n3msP6A36FDfdSEAEQEAAc0WWGluIExpIDx4aW5Aenl0b3IuY29tPsLBDQQTAQgA NxYhBIUq/WFSDTiOvUIqv2u9DlcdrjdRBQJlD89XBQkFo5qAAhsDBAsJCAcFF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AQYAQgA JhYhBIUq/WFSDTiOvUIqv2u9DlcdrjdRBQJlD89ZBQkFo5qAAhsMAAoJEGu9DlcdrjdR4C0L /RcjolEjoZW8VsyxWtXazQPnaRvzZ4vhmGOsCPr2BPtMlSwDzTlri8BBG1/3t/DNK4JLuwEj OAIE3fkkm+UG4Kjud6aNeraDI52DRVCSx6xff3bjmJsJJMb12mWglN6LjdF6K+PE+OTJUh2F dOhslN5C2kgl0dvUuevwMgQF3IljLmi/6APKYJHjkJpu1E6luZec/lRbetHuNFtbh3xgFIJx 2RpgVDP4xB3f8r0I+y6ua+p7fgOjDLyoFjubRGed0Be45JJQEn7A3CSb6Xu7NYobnxfkwAGZ Q81a2XtvNS7Aj6NWVoOQB5KbM4yosO5+Me1V1SkX2jlnn26JPEvbV3KRFcwV5RnDxm4OQTSk PYbAkjBbm+tuJ/Sm+5Yp5T/BnKz21FoCS8uvTiziHj2H7Cuekn6F8EYhegONm+RVg3vikOpn gao85i4HwQTK9/D1wgJIQkdwWXVMZ6q/OALaBp82vQ2U9sjTyFXgDjglgh00VRAHP7u1Rcu4 l75w1xInsg== In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2/7/2024 10:30 AM, Paul E. McKenney wrote: > On Wed, Feb 07, 2024 at 08:52:35AM -0800, Breno Leitao wrote: >> Commit 344da544f177 ("x86/nmi: Print reasons why backtrace NMIs are >> ignored") creates a super nice framework to diagnose NMIs. >> >> Every time nmi_exc() is called, it increments a per_cpu counter >> (nsp->idt_nmi_seq). At its exit, it also increments the same counter. >> Looking at this counter, you can see how many times that function was >> called (dividing by 2), and, if the function is still being executed, by >> checking the idt_nmi_seq's last bit. >> >> On the check side (nmi_backtrace_stall_check()), that variable is >> queried to check if the NMI is still being executed, but, there is a >> mistake in the bitwise operation. That code wants to check if the last >> bit of the idt_nmi_seq is set or not, but, does the opposite, and check >> for all the other bits, which will always be true after the first >> exc_nmi() executed successfully. >> >> This appends the misleading string to the dump "(CPU currently in NMI >> handler function)" >> >> Fix it by checking the last bit, and if it is set, append the string. >> >> Fixes: 344da544f177 ("x86/nmi: Print reasons why backtrace NMIs are ignored") >> Signed-off-by: Breno Leitao > > If someone else is taking this: > > Reviewed-by: Paul E. McKenney > > (I am queueing it for testing in any case.) Does this fix need to be backported? Commit 344da544f177 has a date on Dec 16 2022. > >> --- >> arch/x86/kernel/nmi.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c >> index 17e955ab69fe..6e738ad474dc 100644 >> --- a/arch/x86/kernel/nmi.c >> +++ b/arch/x86/kernel/nmi.c >> @@ -639,7 +639,7 @@ void nmi_backtrace_stall_check(const struct cpumask *btp) >> msgp = nmi_check_stall_msg[idx]; >> if (nsp->idt_ignored_snap != READ_ONCE(nsp->idt_ignored) && (idx & 0x1)) >> modp = ", but OK because ignore_nmis was set"; >> - if (nmi_seq & ~0x1) >> + if (nmi_seq & 0x1) >> msghp = " (CPU currently in NMI handler function)"; >> else if (nsp->idt_nmi_seq_snap + 1 == nmi_seq) >> msghp = " (CPU exited one NMI handler function)"; >> -- >> 2.39.3 >> > -- Thanks! Xin