From patchwork Tue May 11 15:07:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Glitta X-Patchwork-Id: 12251327 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB6B2C433ED for ; Tue, 11 May 2021 15:07:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 22CF6613C1 for ; Tue, 11 May 2021 15:07:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 22CF6613C1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 842386B006E; Tue, 11 May 2021 11:07:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7CBE46B0072; Tue, 11 May 2021 11:07:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 62A186B006E; Tue, 11 May 2021 11:07:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0121.hostedemail.com [216.40.44.121]) by kanga.kvack.org (Postfix) with ESMTP id 433376B006E for ; Tue, 11 May 2021 11:07:39 -0400 (EDT) Received: from smtpin37.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id D0AFC181AF5FD for ; Tue, 11 May 2021 15:07:38 +0000 (UTC) X-FDA: 78129279396.37.062E48C Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) by imf20.hostedemail.com (Postfix) with ESMTP id D40BC3DC for ; Tue, 11 May 2021 15:07:37 +0000 (UTC) Received: by mail-ed1-f48.google.com with SMTP id g14so23308884edy.6 for ; Tue, 11 May 2021 08:07:37 -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=+fRsR5t8wvCfu4sVp9hQ5wsUoHnYKOQm/lSOy9/33Bw=; b=qU+9gcOwydfg4s6P6n/Jb+5uionmETIkViN7y+BGerFtxjo3bl57OISiAWjpk8S9t2 AhC97YSGC5R811hgJhp4Wk1drQAyUwZ2ih0doU8PbXjOeD0TevC3uXVC4n+x51XGcsts PKGHs1Hngz5Cw5oyclUpQZbmRdUCUR6CvWfiHncCH6/1XT4zmG2QSAEEHzdPdCG2amyX aMf23Mqnki3G62xwUiuL8dJhRw5kMCiTlmyyaSZwkYzpypWjWkhZl9N2SbcNGcloKbWl dH9pmLYQbP42p+hpaQ0eKQQ7G3Tu4Er2jAejDC2g8nsN8Va0HB+/Wbu2AX5vy60fCymQ WEKQ== 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=+fRsR5t8wvCfu4sVp9hQ5wsUoHnYKOQm/lSOy9/33Bw=; b=UJ6UEfyIvBYssacJTlSUGUlCvWcmuWqXIyBltPVuwLCpXfKzHiRdBO4823qTlIcTT9 gvIjdkw1Ao1lZY8c13RYJpI8R6lnd9usZNVDoGJKG5BxEwiHWADcLmWrXRub1bSFRKww D7517oDMzqzjobdl3mIc8Toa+MRQ7FuAEaKZwDEEteuLh4W32KwyvhlTdJdyyHcQp0Ym kOFCtjqwefKVflrq8LO1FQT5daUVtHiPGpiZpzYp6uqMrsF+k315H38ySH/URmtxHkMA Y4YdPmrurQkk21qRtkqhq01BCMAzCh65rR1gYegFuzVMNS4AGCOW70NGJwX8KVdVeThn 2Uag== X-Gm-Message-State: AOAM533hueaZebBI+YKVouijA5HD76CkgmMo4sEIaUv56sy9BRAgcWcY YGct3Ik01X9x8tCUd3z01P4= X-Google-Smtp-Source: ABdhPJzVrN4P/dKwWMkwHkth9UYmwQuaRE8e4YYq8slMmp8f8icnhSQHfcZPPLBj0WhS5HmnOJCnNg== X-Received: by 2002:a50:c446:: with SMTP id w6mr33437597edf.62.1620745656797; Tue, 11 May 2021 08:07:36 -0700 (PDT) Received: from localhost.localdomain (ispc-static-34.84-47-111.telekom.sk. [84.47.111.34]) by smtp.gmail.com with ESMTPSA id lr15sm11872709ejb.107.2021.05.11.08.07.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 08:07:36 -0700 (PDT) From: glittao@gmail.com To: brendanhiggins@google.com, cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, vbabka@suse.cz Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-mm@kvack.org, elver@google.com, dlatypov@google.com, Oliver Glitta Subject: [PATCH v5 1/3] kunit: make test->lock irq safe Date: Tue, 11 May 2021 17:07:32 +0200 Message-Id: <20210511150734.3492-1-glittao@gmail.com> X-Mailer: git-send-email 2.31.1.272.g89b43f80a5 MIME-Version: 1.0 Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=qU+9gcOw; spf=pass (imf20.hostedemail.com: domain of glittao@gmail.com designates 209.85.208.48 as permitted sender) smtp.mailfrom=glittao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: D40BC3DC X-Stat-Signature: 5nnudkhy79qido9h7osfxiirm33aj5fs Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf20; identity=mailfrom; envelope-from=""; helo=mail-ed1-f48.google.com; client-ip=209.85.208.48 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620745657-279425 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Vlastimil Babka The upcoming SLUB kunit test will be calling kunit_find_named_resource() from a context with disabled interrupts. That means kunit's test->lock needs to be IRQ safe to avoid potential deadlocks and lockdep splats. This patch therefore changes the test->lock usage to spin_lock_irqsave() and spin_unlock_irqrestore(). Signed-off-by: Vlastimil Babka Signed-off-by: Oliver Glitta Reviewed-by: Brendan Higgins --- Changes since v4 Rebased whole series on 5.13-rc1 include/kunit/test.h | 5 +++-- lib/kunit/test.c | 18 +++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) -- 2.31.1.272.g89b43f80a5 diff --git a/include/kunit/test.h b/include/kunit/test.h index 49601c4b98b8..524d4789af22 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -515,8 +515,9 @@ kunit_find_resource(struct kunit *test, void *match_data) { struct kunit_resource *res, *found = NULL; + unsigned long flags; - spin_lock(&test->lock); + spin_lock_irqsave(&test->lock, flags); list_for_each_entry_reverse(res, &test->resources, node) { if (match(test, res, (void *)match_data)) { @@ -526,7 +527,7 @@ kunit_find_resource(struct kunit *test, } } - spin_unlock(&test->lock); + spin_unlock_irqrestore(&test->lock, flags); return found; } diff --git a/lib/kunit/test.c b/lib/kunit/test.c index 2f6cc0123232..45f068864d76 100644 --- a/lib/kunit/test.c +++ b/lib/kunit/test.c @@ -475,6 +475,7 @@ int kunit_add_resource(struct kunit *test, void *data) { int ret = 0; + unsigned long flags; res->free = free; kref_init(&res->refcount); @@ -487,10 +488,10 @@ int kunit_add_resource(struct kunit *test, res->data = data; } - spin_lock(&test->lock); + spin_lock_irqsave(&test->lock, flags); list_add_tail(&res->node, &test->resources); /* refcount for list is established by kref_init() */ - spin_unlock(&test->lock); + spin_unlock_irqrestore(&test->lock, flags); return ret; } @@ -548,9 +549,11 @@ EXPORT_SYMBOL_GPL(kunit_alloc_and_get_resource); void kunit_remove_resource(struct kunit *test, struct kunit_resource *res) { - spin_lock(&test->lock); + unsigned long flags; + + spin_lock_irqsave(&test->lock, flags); list_del(&res->node); - spin_unlock(&test->lock); + spin_unlock_irqrestore(&test->lock, flags); kunit_put_resource(res); } EXPORT_SYMBOL_GPL(kunit_remove_resource); @@ -630,6 +633,7 @@ EXPORT_SYMBOL_GPL(kunit_kfree); void kunit_cleanup(struct kunit *test) { struct kunit_resource *res; + unsigned long flags; /* * test->resources is a stack - each allocation must be freed in the @@ -641,9 +645,9 @@ void kunit_cleanup(struct kunit *test) * protect against the current node being deleted, not the next. */ while (true) { - spin_lock(&test->lock); + spin_lock_irqsave(&test->lock, flags); if (list_empty(&test->resources)) { - spin_unlock(&test->lock); + spin_unlock_irqrestore(&test->lock, flags); break; } res = list_last_entry(&test->resources, @@ -654,7 +658,7 @@ void kunit_cleanup(struct kunit *test) * resource, and this can't happen if the test->lock * is held. */ - spin_unlock(&test->lock); + spin_unlock_irqrestore(&test->lock, flags); kunit_remove_resource(test, res); } current->kunit_test = NULL;