Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4640451pxa; Mon, 10 Aug 2020 14:19:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUstw5dd+gz3hGqnTZeblM62DzD9QWTXmMqqx1VYShDj7HwjVuH2gK5vqgJURMWwq9vuG6 X-Received: by 2002:a17:906:6b87:: with SMTP id l7mr22507135ejr.198.1597094355383; Mon, 10 Aug 2020 14:19:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597094355; cv=none; d=google.com; s=arc-20160816; b=o+aeok1PR0MU7R5bcJbDOQrNEANPOU5f3JQJY7y/ZYkjxF8XEmvR41MxHU95L+m7th NVtWnlIS81Rdrq3if7xpXiD4BcSLQkbh2voOOfcQhF3RoHezi36zY3SPNbvjxMBSTDm9 T17s5NxZJRF3WNRWTzxI8CjzF6IR/upiRWZfIDpXivjQ8MwcCArLF2KItrK4QEJkr0mw MwpNonuw5wkAt0kfNp4XhGiy+aW3+QU2oy9+6ryweEnkmrxUbFLY9AlmnZ6uY3RbAhD3 oxaMiXB+uG5uGi1G4qXzl9TdKEBKyoGWnuro0k6z3mHUf2Bh24sVyh3eMb5BA/XhLU8d VoHg== 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=8GBCeeTPIAs1vqUkzRTPXsfrx2cgCSPgccIBR3gAYiM=; b=E56T79oUU33WluGQi5sKNFSQVr4Fj6u1B8z7jOtIDTkR+EfZLLZOUXYS1GUAQ3kGCK ZYELLT7/cxwiQzXNL7hoZ8faV/sbsyWQqiPiHeDHqNULwruYX2M9ZsSOMjg8AeimY+SO HEhacZAwuBsfWQgAZFeWOPL0TuJW+ABkxdAU3B0sscJYJTIyH8Xkb/Ev3nIqM41Br6ZE c/7ckxFksclyOjFX+Oh3zqAh3yY4NFUtJC4zQUv12Qit2EvA2+PEaHeeAmCI/D4N8ey1 uTd3UQLhtz3TqM1oACJCynaoDcF1UJT7KdlQgCr9iRNNWo9yAyHX+Tp+8hhkAYBgUXkL A0Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=YwVxAf9E; 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 pg13si11613972ejb.681.2020.08.10.14.18.52; Mon, 10 Aug 2020 14:19:15 -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=YwVxAf9E; 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 S1726799AbgHJVR4 (ORCPT + 99 others); Mon, 10 Aug 2020 17:17:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726654AbgHJVRz (ORCPT ); Mon, 10 Aug 2020 17:17:55 -0400 Received: from mail-oo1-xc42.google.com (mail-oo1-xc42.google.com [IPv6:2607:f8b0:4864:20::c42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91323C061756 for ; Mon, 10 Aug 2020 14:17:55 -0700 (PDT) Received: by mail-oo1-xc42.google.com with SMTP id j16so2192636ooc.7 for ; Mon, 10 Aug 2020 14:17:55 -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=8GBCeeTPIAs1vqUkzRTPXsfrx2cgCSPgccIBR3gAYiM=; b=YwVxAf9ERd4NAgz/iv74mmhNe+RAXg6chRDIyAeaYYRlCmWNGbR8BirN0ldW84u1U6 cSpF2BdqRyuFhjeWnuigySpcmnXkJianTvoEnYFvC92ziAo86ZXbrzlpUvdIiEXFo8wp N6bOwOepauIwC6qjZs0bjOeCNDZV+0wCbn+R+OifZSNds/eh0KSUgNYpKXcYqhd/82Mn iNoethuJvVwm86k/hPDhnY2blkQcN5HL+q3qfjpK/AWaYuKQfo8ZTCrP/QqLpmYYZISQ e93nJEL83o8hEd6G4P24Rz4sRWb5R1u2yEdmL5R/qLnFl1ewOuabrlFqD0T2rzWMOagi habg== 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=8GBCeeTPIAs1vqUkzRTPXsfrx2cgCSPgccIBR3gAYiM=; b=FEjCvWPc4XEu8mWoVklYEfo99HHvXEFA7kh+4sLD1p8it6mqQMCQSSouS3Y34ypUF1 k1btNpocY8qdob/y1IKwQ1gWkK4az890zxbs6dTyyPVpYmYcl0+EUas+xb9w+yRwLwn7 PCVFdOWHB+UeTmCaCcYLwFtUnGdRD0otWqS9CYGnv+x+qIEqPp1amDdQ86+lX09dEnlT g21jWZxOKeo8MHFhkuW0cfA8ssfFlZIT8Gdt8e+iWlEsd0CaHM9xi3HzHEwdhTIz4yoL LrHALC6ixRHw18FUmM0kV96vE9tfkBHDNe7HLyLNSfBuYAkX/YMRtdTM0uKOFlx/gZhq GgYQ== X-Gm-Message-State: AOAM5338M3QrGAxcr2h2G5nKhyS9mpW+9c4LUy5O1bkvrnb4w7P/SLsU EHVNmrYDxbPx8Td/kghJ72Uzh0BR6DveEGe2oH5XYQ== X-Received: by 2002:a4a:2f4b:: with SMTP id p72mr2448256oop.39.1597094273806; Mon, 10 Aug 2020 14:17:53 -0700 (PDT) MIME-Version: 1.0 References: <20200806203737.3636830-1-urielguajardojr@gmail.com> In-Reply-To: From: Uriel Guajardo Date: Mon, 10 Aug 2020 16:17:42 -0500 Message-ID: Subject: Re: [PATCH] kunit: added lockdep support To: Brendan Higgins , peterz@infradead.org, mingo@redhat.com, will@kernel.org 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 Mon, Aug 10, 2020 at 3:35 PM Brendan Higgins wrote: > > 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. > Thanks for the reminder. CC'ed lockdep maintainers. > > > 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 > > >