Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp1170963ybg; Wed, 29 Jul 2020 07:34:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbBHbQA++tiR8aM5bRt5NvhE+yL458v6oefQHST9wqh9Z0aUfZ7haY6GU1WCsBPNlVZc/B X-Received: by 2002:aa7:cf19:: with SMTP id a25mr12457057edy.67.1596033278241; Wed, 29 Jul 2020 07:34:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596033278; cv=none; d=google.com; s=arc-20160816; b=pZ7xvEt0Z/8a613cYYPVxhAkszMuIcGH3pE0FEJ4Injb8MMVjeN6EWAHWi0NFqoGF3 QKUOfkOvZFJWVYZbHYS9RmaVchB6xtt1vn8+zyEnu7O2OGHQ6nEJAnXw5shYb6NRbW5c t3MdhEDUCIFi13czgqEGqWBOtdnEwe7Uiv+FFRKxqIPfKo+dIG6C+AZ3rM/E7zSJ2JXG tbcmE8QFWaiK5KhDOfmZOLOsxY29gae8FCkR6VD3/aDE8dlNyVSj0iE99Zuf9Iu6P/18 6QMHBJo3w6sHQlAy67CQQLJrydSLreIuQea6E8k5ipwYBHb50+04pQ0fOL0g/zPJ4Mkq ppaQ== 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 :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:dkim-signature :dkim-signature:date; bh=sk02ac1kUEoOR/0yIxmnkbHaSkRJBENdZDrwuKFyrzg=; b=QtF0Id+PQel8S6WSwYO2SSbhk44pSg6RneUnbBijpSgr4FGrNthpM7uEiXdWzNtV9c IR2jCR/uO4u1tMRL35UVH7MEISiQn0OD4dKDm7nZDEI3ifKZxP5rjsoUorfWDrPf5b8c ZOZoT95diWGJKC1LeiJkBBOZljjzOmkHzOPhAT1MzHk2Hgpy3gY/PsmINBMVI+NvCH3J VmRe9ahdPhzQhicnXdrSoeKSW2571XEjyTY9wnECN9SzbRUxfI0mn3NKhqGAS/5FAuPN ExdVs6sN8Ba5DuPeiukqcerkcwJl0+dHCQNMP4U6aJFrrQSIy9KduHW/JBeTMq3wW3kc BDwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linutronix.de header.s=2020 header.b=oMjPiiAK; dkim=neutral (no key) header.i=@linutronix.de header.b=yW6Czo4J; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dr16si1622242ejc.502.2020.07.29.07.34.14; Wed, 29 Jul 2020 07:34:38 -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=fail header.i=@linutronix.de header.s=2020 header.b=oMjPiiAK; dkim=neutral (no key) header.i=@linutronix.de header.b=yW6Czo4J; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727807AbgG2Ods (ORCPT + 99 others); Wed, 29 Jul 2020 10:33:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727071AbgG2Odl (ORCPT ); Wed, 29 Jul 2020 10:33:41 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 074AFC0619D2; Wed, 29 Jul 2020 07:33:41 -0700 (PDT) Date: Wed, 29 Jul 2020 14:33:38 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1596033219; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sk02ac1kUEoOR/0yIxmnkbHaSkRJBENdZDrwuKFyrzg=; b=oMjPiiAKp1/Hiju/Pg7t+AdeMq4HBBjgrThMSM1iRpXmppG8rd/T/Fg7XCgRsc1KNs89wY WnJ7nYsrYSjFTwmKgHqB+sYkpHiyMU/wU0aVfPQAJficnnmlK4M2gPadrEUpl+aa4lxh3/ ikTPI+B5JIyvc9btxqtKOuHLnNR++Bxqm0CyixJYyEQaEUwHRshQkqa/LCjGuQaLwNbNKN gIqpxf9lhF2XbdZtbiio0BHKR9aRJfzQtX8nNKdKloQLiDCIqjawQqApZEAqNvhOUy14q7 Mf2MdlUVDMT8lZwEmBnW2tcM/xLzPxMaAt3zWHcGfoxfZ7Id09zVgB+TF0Y6ag== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1596033219; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sk02ac1kUEoOR/0yIxmnkbHaSkRJBENdZDrwuKFyrzg=; b=yW6Czo4J/dxyow0aztIY30e4gCm8Yvh9v+jrB9s1y06gCqb0o/cDWaFpK6HK8AQpVua7AC zft4UYBRy/H4jVCg== From: "tip-bot2 for Ahmed S. Darwish" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/core] lockdep: Add preemption enabled/disabled assertion APIs Cc: "Ahmed S. Darwish" , "Peter Zijlstra (Intel)" , x86 , LKML In-Reply-To: <20200720155530.1173732-8-a.darwish@linutronix.de> References: <20200720155530.1173732-8-a.darwish@linutronix.de> MIME-Version: 1.0 Message-ID: <159603321858.4006.1242799063290395518.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the locking/core branch of tip: Commit-ID: 8fd8ad5c5dfcb09cf62abadd4043eaf1afbbd0ce Gitweb: https://git.kernel.org/tip/8fd8ad5c5dfcb09cf62abadd4043eaf1afbbd0ce Author: Ahmed S. Darwish AuthorDate: Mon, 20 Jul 2020 17:55:13 +02:00 Committer: Peter Zijlstra CommitterDate: Wed, 29 Jul 2020 16:14:24 +02:00 lockdep: Add preemption enabled/disabled assertion APIs Asserting that preemption is enabled or disabled is a critical sanity check. Developers are usually reluctant to add such a check in a fastpath as reading the preemption count can be costly. Extend the lockdep API with macros asserting that preemption is disabled or enabled. If lockdep is disabled, or if the underlying architecture does not support kernel preemption, this assert has no runtime overhead. References: f54bb2ec02c8 ("locking/lockdep: Add IRQs disabled/enabled assertion APIs: ...") Signed-off-by: Ahmed S. Darwish Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20200720155530.1173732-8-a.darwish@linutronix.de --- include/linux/lockdep.h | 19 +++++++++++++++++++ lib/Kconfig.debug | 1 + 2 files changed, 20 insertions(+) diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h index 7aafba0..39a3569 100644 --- a/include/linux/lockdep.h +++ b/include/linux/lockdep.h @@ -549,6 +549,22 @@ do { \ WARN_ON_ONCE(debug_locks && !this_cpu_read(hardirq_context)); \ } while (0) +#define lockdep_assert_preemption_enabled() \ +do { \ + WARN_ON_ONCE(IS_ENABLED(CONFIG_PREEMPT_COUNT) && \ + debug_locks && \ + (preempt_count() != 0 || \ + !this_cpu_read(hardirqs_enabled))); \ +} while (0) + +#define lockdep_assert_preemption_disabled() \ +do { \ + WARN_ON_ONCE(IS_ENABLED(CONFIG_PREEMPT_COUNT) && \ + debug_locks && \ + (preempt_count() == 0 && \ + this_cpu_read(hardirqs_enabled))); \ +} while (0) + #else # define might_lock(lock) do { } while (0) # define might_lock_read(lock) do { } while (0) @@ -557,6 +573,9 @@ do { \ # define lockdep_assert_irqs_enabled() do { } while (0) # define lockdep_assert_irqs_disabled() do { } while (0) # define lockdep_assert_in_irq() do { } while (0) + +# define lockdep_assert_preemption_enabled() do { } while (0) +# define lockdep_assert_preemption_disabled() do { } while (0) #endif #ifdef CONFIG_PROVE_RAW_LOCK_NESTING diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 9ad9210..5379931 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -1117,6 +1117,7 @@ config PROVE_LOCKING select DEBUG_RWSEMS select DEBUG_WW_MUTEX_SLOWPATH select DEBUG_LOCK_ALLOC + select PREEMPT_COUNT if !ARCH_NO_PREEMPT select TRACE_IRQFLAGS default n help