Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp111262rdg; Wed, 11 Oct 2023 23:37:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGpS00UWBOemLCFgxy6rmlI4ZQgNFNweBiWHlNuTL/c7MEQKX9y9GSBj2E25Dy33wL8Se97 X-Received: by 2002:a05:6808:13d1:b0:3af:68f9:86de with SMTP id d17-20020a05680813d100b003af68f986demr31972730oiw.25.1697092668064; Wed, 11 Oct 2023 23:37:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697092668; cv=none; d=google.com; s=arc-20160816; b=kRwY+6/8QgFza/GFxCBA32moX4t1Xa8PueEekDKyu+bfLWKLxZv5AdojU5imn4B1qQ qrVMa7orDn1j32tS+MpZ7A27EcoTNAx9mCGRoyWRdTE54/xWDHIzA77ogVPV18o+1Q7y I32lSd32lGvVx4rAn5tAyfA0xhGhwOuw9E6sH+NQAmRMxxCD37tqTUH3ZML+35stoWR3 6QcnimZScFUAlMOWPZ0xvf42wQtQuLcdbP0LjlIB1PM5u8blfEM5Wb3K2M4Cg0VCngT2 mn7zneZIZOmFoTPLlSNUAbOSFt6ZsxCNaeEJuC7Tpb+lSzBsMIfEy8uAJA5Jq/woRtFV D4Bg== 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=WfN4c+uJkrhU2kFJj8dGcLWVfidGbqblVgC8sawHtT8=; fh=RourYA9o6AkK9YWimaHEkg3Jx4lpZGr60AcPqtHDODw=; b=NbUREOVZqlfLSZeE9aJr+8T3i73+aeUzPBJN1O1UcbWu0f46iELYgl0WPW6w8wuP9U EHL7R2EqkFZZsTShXKgvX09g5IoXSIegBanQRID8lHG2Q80Qq0V8d9ZV+ZEpDj5W3l1Z 1Ech4EAzbqWxhnfdnxZRJrA0/TpiqPrXWSsP0/PylFI/SVJ3Ov0ThvvRbU348Fii+5l8 MMZv9EnQjjNUZ5yOwxY2lf7pzjt/moPufFon84hjGjEH+zQyA1c5P8DIRj8czA9WnBUb jj+pY0OJDGLFEwkEE/+xmqOnIIZy7xI5vR062ZFea+RQnpgVvpG6eYH7xj4/N4CmKFiO cWnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Reo+qnmz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id v202-20020a6361d3000000b0059c88df7ad6si1577132pgb.57.2023.10.11.23.37.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 23:37:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Reo+qnmz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 4C7C080B81F6; Wed, 11 Oct 2023 23:37:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347077AbjJLGhe (ORCPT + 99 others); Thu, 12 Oct 2023 02:37:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347082AbjJLGhb (ORCPT ); Thu, 12 Oct 2023 02:37:31 -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 8B8FADA for ; Wed, 11 Oct 2023 23:37:29 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-9b98a699f45so90458166b.3 for ; Wed, 11 Oct 2023 23:37:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697092648; x=1697697448; 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=WfN4c+uJkrhU2kFJj8dGcLWVfidGbqblVgC8sawHtT8=; b=Reo+qnmzOb0VgBoRaxLvJSEI6UHaoX/iF4rX1Mu9JZnMjv83bzM+smxhIMPrbcq1b9 xa23NUDKqgy6ai8G+PkZ+JAr1wN681qyiuxMrnXS55UGTLM5sGHwFUU0dSsnMb0UpSld jtXGHEcKF5Leh+6LMZTavq1s1O6G5Iam53COutBEH2eJno6G7fDQRsBt7bb+pRSg2ako Ot+RoH80nVtAgekv8Y7bg+OkDzKVVFhUKeANjjsqYPrQZrok+Rk9hjwGfzpMMMReB+oY IVHuWSbQQrMKcwmnMoMzZFKV2qmJ/NMQXCv0Ocv0ksDL8Ej2KEUoPKLpepYAI9PW/5RO 6O8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697092648; x=1697697448; 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=WfN4c+uJkrhU2kFJj8dGcLWVfidGbqblVgC8sawHtT8=; b=cFdm761RY6tojYPwu3/5jRy7rurIjSMo4PSt1pITGPNFmShterrZWHgm8thKp+1z/0 //detfGfsLGfX3+DBypkGTb/dibo0JliM7EekF3ps4kDycA5gjHP8gWdKscOucX4JhU4 QIbcIUS3s02yaa3ystI2uF4WOkWp4XKwq3fZDcX7Y79/mBS0jP6fkgGM03Go9ayZmo82 heq7KJTP3wTOeM0Nu/C38bK4X9uLNmrx8JS+yJM3v/FuhsVfjxVZNXJ/I/5MlxoFUsDs 5H5Yt3PrfRXocrFaFtsuvDvXezKA/+OCuhdi7MnAh4xvOHGt4A42RHyxMfAUwq4ECTOF qu9g== X-Gm-Message-State: AOJu0YzSYomS6MP/P4U8XZ2tHf89Ks1bmqwFsEU1tpmqRyYIljI80O6R 8kAmM1jBtqXkVs7zr+loXw8= X-Received: by 2002:a17:906:144:b0:9b6:5811:d990 with SMTP id 4-20020a170906014400b009b65811d990mr18772808ejh.47.1697092647891; Wed, 11 Oct 2023 23:37:27 -0700 (PDT) Received: from gmail.com (1F2EF405.nat.pool.telekom.hu. [31.46.244.5]) by smtp.gmail.com with ESMTPSA id i25-20020a1709064ed900b009b947aacb4bsm10753461ejv.191.2023.10.11.23.37.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 23:37:27 -0700 (PDT) Sender: Ingo Molnar Date: Thu, 12 Oct 2023 08:37:25 +0200 From: Ingo Molnar To: "Paul E. McKenney" Cc: linux-kernel@vger.kernel.org, x86@kernel.org, clm@fb.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com Subject: Re: [PATCH RFC x86/nmi] Fix out-of-order nesting checks Message-ID: References: <0cbff831-6e3d-431c-9830-ee65ee7787ff@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0cbff831-6e3d-431c-9830-ee65ee7787ff@paulmck-laptop> X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email 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 (fry.vger.email [0.0.0.0]); Wed, 11 Oct 2023 23:37:45 -0700 (PDT) * Paul E. McKenney wrote: > The ->idt_seq and ->recv_jiffies variables added by commit 1a3ea611fc10 > ("x86/nmi: Accumulate NMI-progress evidence in exc_nmi()") place > the exit-time check of the bottom bit of ->idt_seq after the > this_cpu_dec_return() that re-enables NMI nesting. This can result in > the following sequence of events on a given CPU in kernels built with > CONFIG_NMI_CHECK_CPU=y: > > o An NMI arrives, and ->idt_seq is incremented to an odd number. > In addition, nmi_state is set to NMI_EXECUTING==1. > > o The NMI is processed. > > o The this_cpu_dec_return(nmi_state) zeroes nmi_state and returns > NMI_EXECUTING==1, thus opting out of the "goto nmi_restart". > > o Another NMI arrives and ->idt_seq is incremented to an even > number, triggering the warning. But all is just fine, at least > assuming we don't get so many closely spaced NMIs that the stack > overflows or some such. > > Experience on the fleet indicates that the MTBF of this false positive > is about 70 years. Or, for those who are not quite that patient, the > MTBF appears to be about one per week per 4,000 systems. > > Fix this false-positive warning by moving the "nmi_restart" label before > the initial ->idt_seq increment/check and moving the this_cpu_dec_return() > to follow the final ->idt_seq increment/check. This way, all nested NMIs > that get past the NMI_NOT_RUNNING check get a clean ->idt_seq slate. > And if they don't get past that check, they will set nmi_state to > NMI_LATCHED, which will cause the this_cpu_dec_return(nmi_state) > to restart. This looks like a sensible fix: the warning should obviously be atomic wrt. the no-nesting region. I've applied your fix to tip:x86/irq, as it doesn't seem urgent enough with a MTBF of 70 years to warrant tip:x86/urgent handling. ;-) Thanks, Ingo