From patchwork Wed Feb 7 16:52:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 197987 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2367654dyb; Wed, 7 Feb 2024 09:01:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXFE7Uvt4W0U0OG28I8IbsetUcOsSNvewq8IhgrfqUmNVQvFGlgPzcEiEqqfoPpmoxhkmNgqWLz5/zUrOONcDWapME+tw== X-Google-Smtp-Source: AGHT+IHOzCzFq9sFWY0th3qr5GshYbaUWhy7bXx7QPVktdsp0JW5JB3qqr+Xih/LujuwWcDjFma+ X-Received: by 2002:ac2:5059:0:b0:511:59a9:7b59 with SMTP id a25-20020ac25059000000b0051159a97b59mr4537244lfm.1.1707325284334; Wed, 07 Feb 2024 09:01:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707325284; cv=pass; d=google.com; s=arc-20160816; b=e0O+5bdyvmjRdPtO2wAsrDj9DFgS/N4tacKZEyWSvF3j2Hfk7pBl1D2Gl9eZfz6NmR jycTB27I7pyy/R/QuhxC2hXPcNko5EdqM0zxdMRSjnjHwKIFfRZNCGvqaBtXh44JDk7K qhvYOzT75Us1VUzbJ7dVWCLxv/CEIXh45Stw1LiLroAMCp7DgQqaoyVjlNbpQGC1sV/I eFs2KPR22nlm/zmOcYRLA8e542jqI6DtKiJ2WEjtKbYCFmJe40dDqHOe4iRJzip0gNuG BLkELSoCfkUr/sXb6H/V+GcZqN2N3hQ8cWMJYclS2fu92CRanqTDS/39JfAoRqfej5x4 w7+Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=5i5FrcnSrEoPjLtJnNgRwolqrsX+z2Vjc1zQhPcrCKo=; fh=PypXAMqUaFVT6Tf1E+e3vzY0eoQQfC4/wHCQRE5qEEg=; b=AKyfZzS1Nl8RxTKbif3blc5U2aYxqOnvV0UDri4HbaouCIErL7mbnTKtsLR91LVfjT CNEi37LMrPTl5EjoQWNCp0f5xd6DeLb2e3dcPlnwp0smARoVlcgmUGQxB65GWgGpHtD1 qXPTK7NgISAzr1T6b54s2d/bfCUm0dx0F7H+S0TSNsvaxzbgqQapyXV4mQ7PwpUooR49 UHz641CO6dT6fqR2R1OpnCxpF4VXcPhILkVBavHB1gQun3s4u+EaajyHvuuhLJ++QqFW hbgrqnDOyc34oA3IhS9gMm4fksB9IZDDwRF2PAmJts/gw9WtObdeXrjtCtJ4y9ckZ0y5 +3fA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-56797-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56797-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCVgpwI8jvV3SAU/2H4on8sKZjL/PS6MNVCTdzSfSf4AQk1vkyk4I+uKUfCJNZpYW7jnIiB/1ZxKZyISvE5+vosbuUu7yw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id p16-20020a1709060e9000b00a388802b836si691619ejf.174.2024.02.07.09.01.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 09:01:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56797-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-56797-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56797-ouuuleilei=gmail.com@vger.kernel.org" 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 932611F2388B for ; Wed, 7 Feb 2024 16:56:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 37070823D2; Wed, 7 Feb 2024 16:56:00 +0000 (UTC) Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2FBE446C8 for ; Wed, 7 Feb 2024 16:55:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707324958; cv=none; b=bq9s6uyZ6G7iKdjlAI3EeCSQjAfB0ctvD8FdOQsqVE5y1CcJLexYir972V521v5Ylc6aTMTkHL83on7SDjPIOeYbkTTRXZ8ceSZQqMxEI9ijG/TzPOGyoL/hw7omZ2e6zJUnDnuyWkNPmXO6QZrLx2iHCsmUbizhTFASvQvN+RQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707324958; c=relaxed/simple; bh=G1nyEGKFSLJqeuc/L/imI5qGuNgH+kWkWa6rxnpIlb8=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=iE721rvj2m0/id7yYXcqzUVDSRx0n17D/NVCZ65bWYnNcIc9hQENcH49dB4DVxdW91RdBiv8x1MsEPszh9ShwPF0JM8Iu5adOegc49zjuoIhXJjXLTua0doYxUznkegmt+6NYkO48VQP8sNlQSZT+hQZH9dUx6tIXi8NVV4H42E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-2d0ce2222a6so5327381fa.3 for ; Wed, 07 Feb 2024 08:55:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707324955; x=1707929755; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5i5FrcnSrEoPjLtJnNgRwolqrsX+z2Vjc1zQhPcrCKo=; b=jN1LDxBD/I8rLWnJOE+t83VP8NmzewhW71Xpm+eXLllz5z19L3HCr8P7hzgmSgLe1y ghqlSB2ow4SDiy5/m0RFHZO9xe58/qIrOLCDjR6QaY5Ec3Uc4iQlvjqJ9AU28u9Z+cNN Wjw4PxldKBl14OrzYNxzuVIPMNJJoyQ7dQEK8oajUnHrh9+BPhKS96FuVTLByIHWsMb9 8wejHwHfkMWpoIa2M04dR28yi3J5JONsFJPqfAvLWacilyolSDOrfleH/zZjK2Jx+3dE ReWIg6FK2pCZQRx3Q6nLBVuj6/8wSNQA2LbWCJIeS55i4tB2o/pwpXoGqi6jgTGg9P0s hEew== X-Forwarded-Encrypted: i=1; AJvYcCUlp+dksgj5c9wV6Ng1fWIG6ecmOXpfluAWJjEegI/ZcLZ6dpn3mTCjhugqZEEyyznjT8/XKyuLjijOJBoxZt99Ji1948GmeEZn2BDL X-Gm-Message-State: AOJu0YzvGQcwdaYIU810F19nSPoSOYVP8iBnCUEjulkpPrWaK3DfQ3Pv 07hBJuh41sLK+A1mxXJQr89MkQhx8BkauqBIF1L9xxu0PYHl5eHG94WgzrYvfUR58Q== X-Received: by 2002:a2e:8610:0:b0:2d0:a47c:d544 with SMTP id a16-20020a2e8610000000b002d0a47cd544mr4466321lji.53.1707324954662; Wed, 07 Feb 2024 08:55:54 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUDJMRoi7sXdJilXSn2awq0qUfUfEA5pUO3W7NuldfmTbahExz1E57QDT6SZQLGVc08ieUo+YLiEhupK4KFRcp1mhEAA6QBlvK366pQevt0ptK+5JpemaxoFnCcT4Y1oMnfdSr1geZa5+dDbMpqODM9sV00nQ0av3iFW2ZQ2G7fbRZTqeavJ/zehk/fEhxn6vxt6nLSkKaDLATcabFyuQkwxv86AVttzBHfn1blBUtTQbtkI/MX6VY3tLUIcgpyufRCnT32NdsUBX57p/Rmq2qbkdiVVbE7WWwbr5ERymjJUfipHmk= Received: from localhost (fwdproxy-lla-008.fbsv.net. [2a03:2880:30ff:8::face:b00c]) by smtp.gmail.com with ESMTPSA id f3-20020a05640214c300b00560556fe9b7sm829107edx.78.2024.02.07.08.55.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 08:55:54 -0800 (PST) From: Breno Leitao To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , "Paul E. McKenney" Cc: leit@meta.com, Mark Rutland , Ingo Molnar , linux-kernel@vger.kernel.org (open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)) Subject: [PATCH] x86/nmi: Fix "in NMI handler" check Date: Wed, 7 Feb 2024 08:52:35 -0800 Message-Id: <20240207165237.1048837-1-leitao@debian.org> X-Mailer: git-send-email 2.39.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790260317108480714 X-GMAIL-MSGID: 1790260317108480714 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 Reviewed-by: Paul E. McKenney --- 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)";