Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1233866ybh; Thu, 23 Jul 2020 03:59:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsS3g2XavapDxHCIgmaCbEWBgwip0KeSaQVXSdNCOekeyNkS9hyOzJ6laDTfB8l1vFsww4 X-Received: by 2002:a17:906:a24a:: with SMTP id bi10mr3665829ejb.227.1595501966231; Thu, 23 Jul 2020 03:59:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595501966; cv=none; d=google.com; s=arc-20160816; b=WceGrxZ7fhBIJB998pw+7ftExJDhfx2YHbnB9rk5EhhYCKNU1Bok+XjAr2929UBFsL wfS2pXns7Z8N+13L5bgJ0B7fLzLCFOBvbO8CAcDtxiE8KkVzP2nkdIjEPk488bEMRIbY bwbwGKjURk4lDG9fts00/VP/GK/BaFcRfe61RuyxNLrOnkBTfdIM54ex9R3UgUhX+6St 4XyIbtAQgwCzfcdGzovwj+abzIvDc1yySZsvSB8UVAa3r1eStVKHNNMHQU1HE9c5EtTd smKEIX/qUUcIgKH6P/GrmKTOni+2svpDI8379c6srYFkYpVg5nQjtXmycdJ6usTyLbKK JrKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=B+mLXieEAfXnO/747XGSjyHkJWweuJW45UcNIGomDRA=; b=ONTC05ol6/8lEvJrJEVBcCR7VdqkIVgwJRbSUs2Mn9jRNyn9IOAY73TphU9VbjOL1S 64IfEd5+0N1Rn5/tbZmR32v1jaegGzByrVB2Sif8X+i1MryBwuXIhFFDngniDSIfAG3A 74l0BpktYlawGd7mVdFLpopYrOvbD6BusMwZ3tl4yMWW7srUQTQbayxfRYeBKTInQ2AR +qFU+VGacIgTZAQZx5CCcH5RQCtD3LelGWI5BCTQw0kfCQfgM4eA2Gxsbyow1r0G4f3f VV6yfyaUnx/pQTaihZi8YdsPPD3W68Vd94TZ6NX1oa6xcd8lP7XJvUNDK8BuFhj8/lmm Vrjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=c6FyYWFe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n7si1654502edo.512.2020.07.23.03.59.03; Thu, 23 Jul 2020 03:59:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=c6FyYWFe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728496AbgGWK41 (ORCPT + 99 others); Thu, 23 Jul 2020 06:56:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726675AbgGWK40 (ORCPT ); Thu, 23 Jul 2020 06:56:26 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 894A6C0619DC; Thu, 23 Jul 2020 03:56:26 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id a9so2996109pjd.3; Thu, 23 Jul 2020 03:56:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=B+mLXieEAfXnO/747XGSjyHkJWweuJW45UcNIGomDRA=; b=c6FyYWFei/GJd4W55hsLdi161Ij5iiz7XoxIgjk8uWEyUHjj+HzhiwHI9g/9lzjL9J 8JwVe3kqr/y5qBDb0HaNVOemR+LFDw7OHJVDnej1EW+fUA91rBUAvZcdivH2wG9HyrMA 3AAZN+m7GRTB8I7TT5YxXOwSvQiUwHnuEDwFGdU/KE5iIQR5Q1gdo2OvaDbfm65T0lE+ rsA+aUfoJ3VeW58rSNvW1MOQYbzFEC1qnVTjqZi473T5DG0Scw0qWT1x7keIapAeDtLG b5GZT7JXPChb3Rx5F+XvVny5702h5KhkLCOO/1hUo32rBmHGDcI3qxfKzfi3AoP0TfnW MB7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=B+mLXieEAfXnO/747XGSjyHkJWweuJW45UcNIGomDRA=; b=LKqH+aJAj3wvXwXlW+aPLeJljY6iIq7aysBSF6/RB4RZJZG4CViVGkZb94HY0GVmP0 5A2+0MI9fkE+9NPtH2ZNFCYxlrEdcCqslYPLCpa9bFTHMbykSFyeCxAeTJPuK8nqGmUz OVu2uSNoRGnRJiebMphvdFrfa1n8oNeRns+DwFmRyLDQCZG5JUnJiHoknYdp6fn/EBUH S7IAk0l/n7yIxi7rKtgwveFeMjVBScmb1XU4xiBVjz246ksgIdlDCbIvy96Hn8YC7w5N LxdJ/TDhIjtuHzeOnjYheBY3m/jaZL5uj/mNgd7AFpw8d1vcxVVrtww+3fIhX/GyYVA2 trxg== X-Gm-Message-State: AOAM5306xXprrellYtjJkX1Cfo4QRxweArVxW8DBZ8CcshjtAugSBErZ azgNym8JkY9hVsJjfJbt5xtLt5dI X-Received: by 2002:a17:902:b20a:: with SMTP id t10mr3176863plr.185.1595501785905; Thu, 23 Jul 2020 03:56:25 -0700 (PDT) Received: from bobo.ozlabs.ibm.com (110-174-173-27.tpgi.com.au. [110.174.173.27]) by smtp.gmail.com with ESMTPSA id 204sm2598009pfx.3.2020.07.23.03.56.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jul 2020 03:56:25 -0700 (PDT) From: Nicholas Piggin To: linux-kernel@vger.kernel.org Cc: Nicholas Piggin , linux-arch@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Peter Zijlstra , Ingo Molnar , Will Deacon , Alexey Kardashevskiy Subject: [PATCH 1/2] lockdep: improve current->(hard|soft)irqs_enabled synchronisation with actual irq state Date: Thu, 23 Jul 2020 20:56:14 +1000 Message-Id: <20200723105615.1268126-1-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If an interrupt is not masked by local_irq_disable (e.g., a powerpc perf interrupt), then it can hit in local_irq_enable() after trace_hardirqs_on() and before raw_local_irq_enable(). If that interrupt handler calls local_irq_save(), it will call trace_hardirqs_off() but the local_irq_restore() will not call trace_hardirqs_on() again because raw_irqs_disabled_flags(flags) is true. This can lead lockdep_assert_irqs_enabled() to trigger false positive warnings. Fix this by being careful to only enable and disable trace_hardirqs with the outer-most irq enable/disable. Reported-by: Alexey Kardashevskiy Signed-off-by: Nicholas Piggin --- I haven't tested on other architectures but I imagine NMIs in general might cause a similar problem. Other architectures might have to be updated for patch 2, but there's a lot of asm around interrupt/return, so I didn't have a very good lock. The warnings should be harmless enough and uncover most places that need updating. arch/powerpc/include/asm/hw_irq.h | 11 ++++------- include/linux/irqflags.h | 29 ++++++++++++++++++----------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/arch/powerpc/include/asm/hw_irq.h b/arch/powerpc/include/asm/hw_irq.h index 3a0db7b0b46e..35060be09073 100644 --- a/arch/powerpc/include/asm/hw_irq.h +++ b/arch/powerpc/include/asm/hw_irq.h @@ -200,17 +200,14 @@ static inline bool arch_irqs_disabled(void) #define powerpc_local_irq_pmu_save(flags) \ do { \ raw_local_irq_pmu_save(flags); \ - trace_hardirqs_off(); \ + if (!raw_irqs_disabled_flags(flags)) \ + trace_hardirqs_off(); \ } while(0) #define powerpc_local_irq_pmu_restore(flags) \ do { \ - if (raw_irqs_disabled_flags(flags)) { \ - raw_local_irq_pmu_restore(flags); \ - trace_hardirqs_off(); \ - } else { \ + if (!raw_irqs_disabled_flags(flags)) \ trace_hardirqs_on(); \ - raw_local_irq_pmu_restore(flags); \ - } \ + raw_local_irq_pmu_restore(flags); \ } while(0) #else #define powerpc_local_irq_pmu_save(flags) \ diff --git a/include/linux/irqflags.h b/include/linux/irqflags.h index 6384d2813ded..571ee29ecefc 100644 --- a/include/linux/irqflags.h +++ b/include/linux/irqflags.h @@ -163,26 +163,33 @@ do { \ * if !TRACE_IRQFLAGS. */ #ifdef CONFIG_TRACE_IRQFLAGS -#define local_irq_enable() \ - do { trace_hardirqs_on(); raw_local_irq_enable(); } while (0) -#define local_irq_disable() \ - do { raw_local_irq_disable(); trace_hardirqs_off(); } while (0) +#define local_irq_enable() \ + do { \ + trace_hardirqs_on(); \ + raw_local_irq_enable(); \ + } while (0) + +#define local_irq_disable() \ + do { \ + bool was_disabled = raw_irqs_disabled(); \ + raw_local_irq_disable(); \ + if (!was_disabled) \ + trace_hardirqs_off(); \ + } while (0) + #define local_irq_save(flags) \ do { \ raw_local_irq_save(flags); \ - trace_hardirqs_off(); \ + if (!raw_irqs_disabled_flags(flags)) \ + trace_hardirqs_off(); \ } while (0) #define local_irq_restore(flags) \ do { \ - if (raw_irqs_disabled_flags(flags)) { \ - raw_local_irq_restore(flags); \ - trace_hardirqs_off(); \ - } else { \ + if (!raw_irqs_disabled_flags(flags)) \ trace_hardirqs_on(); \ - raw_local_irq_restore(flags); \ - } \ + raw_local_irq_restore(flags); \ } while (0) #define safe_halt() \ -- 2.23.0