Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4615675pxa; Mon, 10 Aug 2020 13:36:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmUVfIM7x14gpuVksBJ+NnjRBeipxW1dnPNh0pcNxhWdQI2yVpA7rDRrXbJjg4qZ4oR2l2 X-Received: by 2002:aa7:c45a:: with SMTP id n26mr23025681edr.45.1597091802303; Mon, 10 Aug 2020 13:36:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597091802; cv=none; d=google.com; s=arc-20160816; b=OSlQQXXwgumc13OdeGuZxbOps729RQnVP7uiDnk+jZ98vF5p1rZ2haPJbhtyPzjM2m qazaMxbN6aaUE+6Sk/8sI8412l40JzXu5jVZ9Jf/sQSZafGWMw8hzl4WrFsCss263eNR UWkZDrG85Vp6cI9opqnEX2uoS2ZtJebZqZTLGkCdn8UzfGjg82xbNb7FiO0ISpzwjtiz fHhYD5SzKSEOuEZx3wGbcA/rJ0EUuKHWCsEypTHS9bGu/Z8mN9aguH/BuMvE7QcYnwHS fgzS6aSqo62okfZZdkAjruPESnN2ez4XADmfUlfXqcu+fVVWU4DCB0iah5qKi1QOJlLd pTSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=8bIRISkDDGTFXADmzCt8aRPLFkz3fsf+ngNbn9o21Dg=; b=ntkwXgdF+4LcsjTx/Bbs6v3Om6ORiJ7yRiqtqiFipPX8GSXcdy1XiVoOyQou6fOacW 2oL5lYyT9ErIIGGipUgbMfQ1zkmwMb74cBGIN+ztdai0/VGL58BF+1JufZkCDhDNDvr8 aabVwAv9ZDBjY04oE3E7hc04T0sQfMr7Z8wyj5w1sEDYwCh7LiLsapwhAl8w6KZVHa+G iF5p8VRdbqHdzSt197LO+m6Q4vhApR7adc9MIhxQzNIHm5L8YW6MUlaN01exoHhmWcfS Sg8YQqNDhzvPPflkwfRtH40mT452W32tofqb64h1o7Ro3rbpFiaN4yRkZx/oj7cHwzAO WjiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=gxn7awJT; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o4si10176194edv.338.2020.08.10.13.36.18; Mon, 10 Aug 2020 13:36:42 -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=@google.com header.s=20161025 header.b=gxn7awJT; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726558AbgHJUfs (ORCPT + 99 others); Mon, 10 Aug 2020 16:35:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726507AbgHJUfr (ORCPT ); Mon, 10 Aug 2020 16:35:47 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99F68C061756 for ; Mon, 10 Aug 2020 13:35:47 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id j21so5589931pgi.9 for ; Mon, 10 Aug 2020 13:35:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=8bIRISkDDGTFXADmzCt8aRPLFkz3fsf+ngNbn9o21Dg=; b=gxn7awJT9+Np4VgP/fswxqwEnVeGmRiyFa3TO18lRa9adR0yPu62PZvlMG3XNvtQwq Mkwc1ciKjRqd2sj8jPtyTxcGIUrBr3zdjZMTqVA8n01OTZwofFP5uIr+ln8r8cpy+fou 2ObEl8jiC0/c29dV2mKFFAVcqNESxUSMyqdudzCSfDT/2xIKbmYMsOx9piZKf4+zICS9 MJDWAI0xzzeFTn7KKE18RY9Um0AOpWuod7fEkW6uMGLv4rgFzMiV1YDSeL88Vu4DpCsE oscChhZyhfFyd1qSD27ql80hQ8Gzl1Di002f59SRbEfHXLIdF1YPLqnjcFCmxK/6/kpF rTyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=8bIRISkDDGTFXADmzCt8aRPLFkz3fsf+ngNbn9o21Dg=; b=PdFIVcm4PLhs9bOj/sHtv0YpZKzp/B7Mz4VbxKfhF3qI5h2LWpohA9ect0BocnIEVL PyvQ+Armfv1bgDqMSerYRKNmONUccrPEKl3jkc2g0jKwAMPi34ADJ/OX46WxB+ochqPW H2XXFhto8RKDXI0yj0M98jqnphTOIfW0NeaOGpoMJhDCDzbJsjRxSHfWViRFbFsnnSl4 4OBsWXnMoKcZgoStJDsnuSRWJU90Gvoq/Al2+TMLqHUWcWzYd/aaQOncIdHUyCKeqUf8 QEGFlaq9Cq/bDQMoUdYzS3avoahlZSzPrXya2aZFISMDZYUWMS0Pl2LGmWzjdyUffv6p P/0g== X-Gm-Message-State: AOAM531Q9+czjKkWcz1YjT5XXJXD+veOwylLmV1piS2e+BCPlkxejAEq CG7kc7Ndh1OBCULRz4NUAsgRnY8Ju44EAGCUZW3lDg== X-Received: by 2002:a63:5022:: with SMTP id e34mr2477990pgb.384.1597091746854; Mon, 10 Aug 2020 13:35:46 -0700 (PDT) MIME-Version: 1.0 References: <20200806203737.3636830-1-urielguajardojr@gmail.com> In-Reply-To: From: Brendan Higgins Date: Mon, 10 Aug 2020 13:35:35 -0700 Message-ID: Subject: Re: [PATCH] kunit: added lockdep support To: Uriel Guajardo Cc: Uriel Guajardo , "open list:KERNEL SELFTEST FRAMEWORK" , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 6, 2020 at 1:43 PM Uriel Guajardo wrote: > > On Thu, Aug 6, 2020 at 3:37 PM Uriel Guajardo wrote: > > > > From: Uriel Guajardo > > > > KUnit tests will now fail if lockdep detects an error during a test > > case. > > > > The idea comes from how lib/locking-selftest [1] checks for lock errors: we > > first if lock debugging is turned on. If not, an error must have > > occurred, so we fail the test and restart lockdep for the next test case. > > > > Like the locking selftests, we also fix possible preemption count > > corruption from lock bugs. Sorry, just noticed: You probably want to send this to some of the lockdep maintainers or the maintainers of the kselftest for lockdep. > > Depends on kunit: support failure from dynamic analysis tools [2] > > > > [1] https://elixir.bootlin.com/linux/v5.7.12/source/lib/locking-selftest.c#L1137 > > > > [2] https://lore.kernel.org/linux-kselftest/20200806174326.3577537-1-urielguajardojr@gmail.com/ > > > > Signed-off-by: Uriel Guajardo > > --- > > lib/kunit/test.c | 26 +++++++++++++++++++++++++- > > 1 file changed, 25 insertions(+), 1 deletion(-) > > > > diff --git a/lib/kunit/test.c b/lib/kunit/test.c > > index d8189d827368..0838ececa005 100644 > > --- a/lib/kunit/test.c > > +++ b/lib/kunit/test.c > > @@ -11,6 +11,8 @@ > > #include > > #include > > #include > > +#include > > +#include > > > > #include "debugfs.h" > > #include "string-stream.h" > > @@ -22,6 +24,26 @@ void kunit_fail_current_test(void) > > kunit_set_failure(current->kunit_test); > > } > > > > +static inline void kunit_check_locking_bugs(struct kunit *test, > > + unsigned long saved_preempt_count) > > +{ > > + preempt_count_set(saved_preempt_count); > > +#ifdef CONFIG_TRACE_IRQFLAGS > > + if (softirq_count()) > > + current->softirqs_enabled = 0; > > + else > > + current->softirqs_enabled = 1; > > +#endif > > I am not entirely sure why lib/locking-selftests enables/disables > softirqs, but I suspect it has to do with the fact that preempt_count > became corrupted, and somehow softirqs became incorrectly > enabled/disabled as a result. The resetting of the preemption count > will undo the enabling/disabling accordingly. Any insight on this > would be appreciated! > > > +#if IS_ENABLED(CONFIG_LOCKDEP) > > + local_irq_disable(); > > + if (!debug_locks) { > > + kunit_set_failure(test); > > + lockdep_reset(); > > + } > > + local_irq_enable(); > > +#endif > > +} > > + > > static void kunit_print_tap_version(void) > > { > > static bool kunit_has_printed_tap_version; > > @@ -289,6 +311,7 @@ static void kunit_try_run_case(void *data) > > struct kunit *test = ctx->test; > > struct kunit_suite *suite = ctx->suite; > > struct kunit_case *test_case = ctx->test_case; > > + unsigned long saved_preempt_count = preempt_count(); > > > > current->kunit_test = test; > > > > @@ -298,7 +321,8 @@ static void kunit_try_run_case(void *data) > > * thread will resume control and handle any necessary clean up. > > */ > > kunit_run_case_internal(test, suite, test_case); > > - /* This line may never be reached. */ > > + /* These lines may never be reached. */ > > + kunit_check_locking_bugs(test, saved_preempt_count); > > kunit_run_case_cleanup(test, suite); > > } > > > > -- > > 2.28.0.236.gb10cc79966-goog > >