From patchwork Sun Mar 26 15:29:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zqiang X-Patchwork-Id: 13188308 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C536AC6FD1C for ; Sun, 26 Mar 2023 15:17:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2C6D46B0072; Sun, 26 Mar 2023 11:17:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2762C6B0074; Sun, 26 Mar 2023 11:17:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1654F6B0075; Sun, 26 Mar 2023 11:17:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 07D0B6B0072 for ; Sun, 26 Mar 2023 11:17:37 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id CF92A1C5CDA for ; Sun, 26 Mar 2023 15:17:36 +0000 (UTC) X-FDA: 80611403712.25.B9272E5 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by imf09.hostedemail.com (Postfix) with ESMTP id CE43E140004 for ; Sun, 26 Mar 2023 15:17:33 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=l+z1T4+1; spf=pass (imf09.hostedemail.com: domain of qiang1.zhang@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=qiang1.zhang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679843854; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=tLhxb7IYtvrE0VJpOEV96TXX3ZZqWXP/wgw/UEPcVHM=; b=I7oBHXR1mMBgVYT48ILD4wZK5vju5QlmfmultWf0KRrToiOnPiiUKG3oaCn0tQuOnGVXtk K16xjnVwOQCXX79kHRCbvvAh2DIKBzc4G9eF3qVNN7zPOGHRuXLZ1nMq4yJUMaF3lFnJXp GJD7CsPETbkTVHunpoTqQewY83AmYNs= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=l+z1T4+1; spf=pass (imf09.hostedemail.com: domain of qiang1.zhang@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=qiang1.zhang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679843854; a=rsa-sha256; cv=none; b=7mdT9MYvq1gZXkNtLuYNV14QOIbXJhJA2gPUBSG6oc/04HzbIukqG8K9PeA0G4v3czOQ1H ghGsQTukQ1dOd7FAHe1msnTS2FHa37gB6rdfE2edWkxlSidQUXYYKlM/jaqXe6N2bFzSu9 ggQkjKxYvWcRo2RVaVC9l9ofnzF/PpU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679843853; x=1711379853; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=WJRm5pgcwyOIzkAndrIzPJP+upuXTmVFQTvWxN/CGw8=; b=l+z1T4+1ESBF+lZkHRZMdjX8Yk+7UGIkUiaXIZX+Oc+dUcvn/qEqNrmd 5nclbRG6svcp1yffG9zsCFbv7vjCzUT1a9wDlTrd4nxxaLc/m1TMAsQOk 8CQ9XXxR63yUq6TEbBAfewzmINeumwal1dplWpJ7FwbBpUpAbhRou0isd SmUwajDT17OADgALNI8RH5Bc1VxRZwzgUOJuBwF6UEm8+eX6EYy6Gx0sj iOzXtsjqJ4srrASxnVCtv00QCuqQgn/j0So7RXWF5OXQQZRJg1Jdh7ro9 EYlFcbl89Oyqtrl2HHLSHfIGF+cAh/XGEsfk4bobhu8Ef13C2T1oFDvqU A==; X-IronPort-AV: E=McAfee;i="6600,9927,10661"; a="337602084" X-IronPort-AV: E=Sophos;i="5.98,292,1673942400"; d="scan'208";a="337602084" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Mar 2023 08:17:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10661"; a="713598738" X-IronPort-AV: E=Sophos;i="5.98,292,1673942400"; d="scan'208";a="713598738" Received: from zq-optiplex-7090.bj.intel.com ([10.238.156.129]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Mar 2023 08:17:29 -0700 From: Zqiang To: ryabinin.a.a@gmail.com, andreyknvl@gmail.com, dvyukov@google.com, akpm@linux-foundation.org, qiang.zhang1211@gmail.com Cc: kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] kasan: Fix lockdep report invalid wait context Date: Sun, 26 Mar 2023 23:29:11 +0800 Message-Id: <20230326152911.830609-1-qiang1.zhang@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: itpyntc7uedfjyhdazbtbdrkcjn1389w X-Rspamd-Queue-Id: CE43E140004 X-HE-Tag: 1679843853-856326 X-HE-Meta: U2FsdGVkX1+sU7WNux5a7nJHojy5PcMzXESH4CRWylYUUgtLMpsdbpuyp/sczBl0iSVC+9aBFHKax4Qg3UotQ48T5XELpc0cczBNb/SK6EgXc5jGCGxNFNONQpUFVoAaMAgurCYbAQ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ef0ok= 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: For kernels built with the following options and booting CONFIG_SLUB=y CONFIG_DEBUG_LOCKDEP=y CONFIG_PROVE_LOCKING=y CONFIG_PROVE_RAW_LOCK_NESTING=y [ 0.523115] [ BUG: Invalid wait context ] [ 0.523315] 6.3.0-rc1-yocto-standard+ #739 Not tainted [ 0.523649] ----------------------------- [ 0.523663] swapper/0/0 is trying to lock: [ 0.523663] ffff888035611360 (&c->lock){....}-{3:3}, at: put_cpu_partial+0x2e/0x1e0 [ 0.523663] other info that might help us debug this: [ 0.523663] context-{2:2} [ 0.523663] no locks held by swapper/0/0. [ 0.523663] stack backtrace: [ 0.523663] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 6.3.0-rc1-yocto-standard+ #739 [ 0.523663] Call Trace: [ 0.523663] [ 0.523663] dump_stack_lvl+0x64/0xb0 [ 0.523663] dump_stack+0x10/0x20 [ 0.523663] __lock_acquire+0x6c4/0x3c10 [ 0.523663] lock_acquire+0x188/0x460 [ 0.523663] put_cpu_partial+0x5a/0x1e0 [ 0.523663] __slab_free+0x39a/0x520 [ 0.523663] ___cache_free+0xa9/0xc0 [ 0.523663] qlist_free_all+0x7a/0x160 [ 0.523663] per_cpu_remove_cache+0x5c/0x70 [ 0.523663] __flush_smp_call_function_queue+0xfc/0x330 [ 0.523663] generic_smp_call_function_single_interrupt+0x13/0x20 [ 0.523663] __sysvec_call_function+0x86/0x2e0 [ 0.523663] sysvec_call_function+0x73/0x90 [ 0.523663] [ 0.523663] [ 0.523663] asm_sysvec_call_function+0x1b/0x20 [ 0.523663] RIP: 0010:default_idle+0x13/0x20 [ 0.523663] RSP: 0000:ffffffff83e07dc0 EFLAGS: 00000246 [ 0.523663] RAX: 0000000000000000 RBX: ffffffff83e1e200 RCX: ffffffff82a83293 [ 0.523663] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffffff8119a6b1 [ 0.523663] RBP: ffffffff83e07dc8 R08: 0000000000000001 R09: ffffed1006ac0d66 [ 0.523663] R10: ffff888035606b2b R11: ffffed1006ac0d65 R12: 0000000000000000 [ 0.523663] R13: ffffffff83e1e200 R14: ffffffff84a7d980 R15: 0000000000000000 [ 0.523663] default_idle_call+0x6c/0xa0 [ 0.523663] do_idle+0x2e1/0x330 [ 0.523663] cpu_startup_entry+0x20/0x30 [ 0.523663] rest_init+0x152/0x240 [ 0.523663] arch_call_rest_init+0x13/0x40 [ 0.523663] start_kernel+0x331/0x470 [ 0.523663] x86_64_start_reservations+0x18/0x40 [ 0.523663] x86_64_start_kernel+0xbb/0x120 [ 0.523663] secondary_startup_64_no_verify+0xe0/0xeb [ 0.523663] The local_lock_irqsave() is invoked in put_cpu_partial() and happens in IPI context, due to the CONFIG_PROVE_RAW_LOCK_NESTING=y, the local_lock wait_type_inner is LD_WAIT_CONFIG, so acquire local_lock in IPI context (wait_type_inner is LD_WAIT_SPIN) will trigger above calltrace. This commit therefore move qlist_free_all() from hard-irq context to task context. Signed-off-by: Zqiang --- mm/kasan/quarantine.c | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/mm/kasan/quarantine.c b/mm/kasan/quarantine.c index 75585077eb6d..152dca73f398 100644 --- a/mm/kasan/quarantine.c +++ b/mm/kasan/quarantine.c @@ -99,7 +99,6 @@ static unsigned long quarantine_size; static DEFINE_RAW_SPINLOCK(quarantine_lock); DEFINE_STATIC_SRCU(remove_cache_srcu); -#ifdef CONFIG_PREEMPT_RT struct cpu_shrink_qlist { raw_spinlock_t lock; struct qlist_head qlist; @@ -108,7 +107,6 @@ struct cpu_shrink_qlist { static DEFINE_PER_CPU(struct cpu_shrink_qlist, shrink_qlist) = { .lock = __RAW_SPIN_LOCK_UNLOCKED(shrink_qlist.lock), }; -#endif /* Maximum size of the global queue. */ static unsigned long quarantine_max_size; @@ -319,16 +317,6 @@ static void qlist_move_cache(struct qlist_head *from, } } -#ifndef CONFIG_PREEMPT_RT -static void __per_cpu_remove_cache(struct qlist_head *q, void *arg) -{ - struct kmem_cache *cache = arg; - struct qlist_head to_free = QLIST_INIT; - - qlist_move_cache(q, &to_free, cache); - qlist_free_all(&to_free, cache); -} -#else static void __per_cpu_remove_cache(struct qlist_head *q, void *arg) { struct kmem_cache *cache = arg; @@ -340,7 +328,6 @@ static void __per_cpu_remove_cache(struct qlist_head *q, void *arg) qlist_move_cache(q, &sq->qlist, cache); raw_spin_unlock_irqrestore(&sq->lock, flags); } -#endif static void per_cpu_remove_cache(void *arg) { @@ -362,6 +349,8 @@ void kasan_quarantine_remove_cache(struct kmem_cache *cache) { unsigned long flags, i; struct qlist_head to_free = QLIST_INIT; + int cpu; + struct cpu_shrink_qlist *sq; /* * Must be careful to not miss any objects that are being moved from @@ -372,20 +361,13 @@ void kasan_quarantine_remove_cache(struct kmem_cache *cache) */ on_each_cpu(per_cpu_remove_cache, cache, 1); -#ifdef CONFIG_PREEMPT_RT - { - int cpu; - struct cpu_shrink_qlist *sq; - - for_each_online_cpu(cpu) { - sq = per_cpu_ptr(&shrink_qlist, cpu); - raw_spin_lock_irqsave(&sq->lock, flags); - qlist_move_cache(&sq->qlist, &to_free, cache); - raw_spin_unlock_irqrestore(&sq->lock, flags); - } - qlist_free_all(&to_free, cache); + for_each_online_cpu(cpu) { + sq = per_cpu_ptr(&shrink_qlist, cpu); + raw_spin_lock_irqsave(&sq->lock, flags); + qlist_move_cache(&sq->qlist, &to_free, cache); + raw_spin_unlock_irqrestore(&sq->lock, flags); } -#endif + qlist_free_all(&to_free, cache); raw_spin_lock_irqsave(&quarantine_lock, flags); for (i = 0; i < QUARANTINE_BATCHES; i++) {