Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5452997pxj; Wed, 23 Jun 2021 01:20:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCHV+ey3Gtrh9fxwmypLZPcng9t63bQR8Y2vMjr/f/A/LZ+fNfowDvygOgKz2v7tFIm5rB X-Received: by 2002:a17:907:c0f:: with SMTP id ga15mr8394776ejc.228.1624436451011; Wed, 23 Jun 2021 01:20:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624436450; cv=none; d=google.com; s=arc-20160816; b=LQp6RpUah0lHjtfu8GTcm3nQFYfiyNTOAciBL8oMbYBoPtpE940l8pMx9nVqL5/z0S JgjpTM/J8URHY0FbssCF2d+HYn1xypySkSuEsub7+SQngvW7Ly4BvZafaPTMoeZHWTzH A2RDbq39pw67Vg0bEp6i5zo46f7AvGVUvr5bau9sxPKO+/WEte3W33L33xVeyIKmx1LC /JW3hVllyb8jZYlmgYxpSmgSBx5tryX2pePPbLq4rpVejnwyzha60W0iHPDWxU/vXeQP fQHTYwuemu4TJOteLuholX3o3Q3PPoqi2GKFedXLZJ3L0tU3Eg/IC4X84mwaZrYkbu8d Dk1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=CsPziWcszOZ6Y66MkCFy+zHnVgjyE3ciD1TrCmGld3A=; b=HCHt3D1KS9FK3TCBTchIky1Th+Nq3dVajPX9yIdA0j9UjDK+V5JPnYElwZZs6/x02O QXVqddEUgNNaqlZwYmPQBP3vXATMUnVyJAcWnlxC0i6uf9ZquOXkVnFNRxHFYqINvenF Jj9fBuyhmu7ar+XB80Vye0CDW2KLKo7ObgnA43QcfZZoKbpoLggMT15cpGQaG+CHEAL8 5tepZObtFW2SilMuRFXwQK8QKSEkvfFAzR7kIHvEypruNgzV0u0HSGMbDfTwtNYtDBI/ 08ej0G2EoYo4Zdoi3baR2moXdLHhYFjyMnv0DcaX9HpUyOsL9rvIzyk1/ElI/VgbZ5uV UKOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=oeLLgJ2t; dkim=neutral (no key) header.i=@linutronix.de header.b="ivW/sYHO"; 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=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d2si16835215ejd.638.2021.06.23.01.20.28; Wed, 23 Jun 2021 01:20:50 -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=@linutronix.de header.s=2020 header.b=oeLLgJ2t; dkim=neutral (no key) header.i=@linutronix.de header.b="ivW/sYHO"; 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=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230334AbhFWIVi (ORCPT + 99 others); Wed, 23 Jun 2021 04:21:38 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:35120 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229987AbhFWIV3 (ORCPT ); Wed, 23 Jun 2021 04:21:29 -0400 Date: Wed, 23 Jun 2021 08:19:09 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1624436349; 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=CsPziWcszOZ6Y66MkCFy+zHnVgjyE3ciD1TrCmGld3A=; b=oeLLgJ2tBSjJJliQBPbKYV1y2WkAQaSWWR01ab8v4N9yRyBCk5ECNxwBDvcpXKbh7oX2om dArePDW8A073B9ojZwLOXUcaqbAhqe6UL7nRHyFIVAqZkyiF0ifQASNGUykJxPUXyGdr3D Wiq/Y6j4sjovc12qmb2tapW6qU2TWEoHKn/4HozD8Jq1+0pe50HCsEkPf2VvP7rihoG4Du 7yYCAX5+Ba471cV6BhAJe6l2D68nXBPpXrTFeJvWgjwvNOAgnPQzPizzf2Oaq22XK23JYr TEIba3tt2Bkz1sEzG3aPKDqo1j+HHofyMJaW6wLaQcneCbfoaIVRxWoaVUnf1Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1624436349; 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=CsPziWcszOZ6Y66MkCFy+zHnVgjyE3ciD1TrCmGld3A=; b=ivW/sYHORLulC9KbEEHLupGshHeY53g77YmstbJ8kyKRFZ5g3pys5MtRgRmRglITnmWUEA 1vVQqr7cZWQYMABw== From: "tip-bot2 for Boqun Feng" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/core] locking/selftests: Add a selftest for check_irq_usage() Cc: Boqun Feng , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20210618170110.3699115-5-boqun.feng@gmail.com> References: <20210618170110.3699115-5-boqun.feng@gmail.com> MIME-Version: 1.0 Message-ID: <162443634910.395.2271085913562698380.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 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: 8946ccc25ed22d957ca7f0b6fac1dcf6d25eaf1f Gitweb: https://git.kernel.org/tip/8946ccc25ed22d957ca7f0b6fac1dcf6d25eaf1f Author: Boqun Feng AuthorDate: Sat, 19 Jun 2021 01:01:10 +08:00 Committer: Peter Zijlstra CommitterDate: Tue, 22 Jun 2021 16:42:07 +02:00 locking/selftests: Add a selftest for check_irq_usage() Johannes Berg reported a lockdep problem which could be reproduced by the special test case introduced in this patch, so add it. Signed-off-by: Boqun Feng Signed-off-by: Peter Zijlstra (Intel) Link: https://lore.kernel.org/r/20210618170110.3699115-5-boqun.feng@gmail.com --- lib/locking-selftest.c | 65 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+) diff --git a/lib/locking-selftest.c b/lib/locking-selftest.c index 2d85aba..5c50b09 100644 --- a/lib/locking-selftest.c +++ b/lib/locking-selftest.c @@ -53,6 +53,7 @@ __setup("debug_locks_verbose=", setup_debug_locks_verbose); #define LOCKTYPE_WW 0x10 #define LOCKTYPE_RTMUTEX 0x20 #define LOCKTYPE_LL 0x40 +#define LOCKTYPE_SPECIAL 0x80 static struct ww_acquire_ctx t, t2; static struct ww_mutex o, o2, o3; @@ -2744,6 +2745,66 @@ static void local_lock_tests(void) pr_cont("\n"); } +static void hardirq_deadlock_softirq_not_deadlock(void) +{ + /* mutex_A is hardirq-unsafe and softirq-unsafe */ + /* mutex_A -> lock_C */ + mutex_lock(&mutex_A); + HARDIRQ_DISABLE(); + spin_lock(&lock_C); + spin_unlock(&lock_C); + HARDIRQ_ENABLE(); + mutex_unlock(&mutex_A); + + /* lock_A is hardirq-safe */ + HARDIRQ_ENTER(); + spin_lock(&lock_A); + spin_unlock(&lock_A); + HARDIRQ_EXIT(); + + /* lock_A -> lock_B */ + HARDIRQ_DISABLE(); + spin_lock(&lock_A); + spin_lock(&lock_B); + spin_unlock(&lock_B); + spin_unlock(&lock_A); + HARDIRQ_ENABLE(); + + /* lock_B -> lock_C */ + HARDIRQ_DISABLE(); + spin_lock(&lock_B); + spin_lock(&lock_C); + spin_unlock(&lock_C); + spin_unlock(&lock_B); + HARDIRQ_ENABLE(); + + /* lock_D is softirq-safe */ + SOFTIRQ_ENTER(); + spin_lock(&lock_D); + spin_unlock(&lock_D); + SOFTIRQ_EXIT(); + + /* And lock_D is hardirq-unsafe */ + SOFTIRQ_DISABLE(); + spin_lock(&lock_D); + spin_unlock(&lock_D); + SOFTIRQ_ENABLE(); + + /* + * mutex_A -> lock_C -> lock_D is softirq-unsafe -> softirq-safe, not + * deadlock. + * + * lock_A -> lock_B -> lock_C -> lock_D is hardirq-safe -> + * hardirq-unsafe, deadlock. + */ + HARDIRQ_DISABLE(); + spin_lock(&lock_C); + spin_lock(&lock_D); + spin_unlock(&lock_D); + spin_unlock(&lock_C); + HARDIRQ_ENABLE(); +} + void locking_selftest(void) { /* @@ -2872,6 +2933,10 @@ void locking_selftest(void) local_lock_tests(); + print_testname("hardirq_unsafe_softirq_safe"); + dotest(hardirq_deadlock_softirq_not_deadlock, FAILURE, LOCKTYPE_SPECIAL); + pr_cont("\n"); + if (unexpected_testcase_failures) { printk("-----------------------------------------------------------------\n"); debug_locks = 0;