From patchwork Tue Nov 19 21:02:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jared Kangas X-Patchwork-Id: 13880543 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 EE116D6C29A for ; Tue, 19 Nov 2024 21:02:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4BB0E6B008C; Tue, 19 Nov 2024 16:02:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 46A9C6B0092; Tue, 19 Nov 2024 16:02:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 332E76B0093; Tue, 19 Nov 2024 16:02:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 0D89C6B008C for ; Tue, 19 Nov 2024 16:02:59 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 7136EA084C for ; Tue, 19 Nov 2024 21:02:58 +0000 (UTC) X-FDA: 82804067808.12.69FF800 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 8270E80003 for ; Tue, 19 Nov 2024 21:01:19 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fllQS6h7; spf=pass (imf30.hostedemail.com: domain of jkangas@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=jkangas@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732049932; 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-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=t3TBOVGPHnMk/PpScx+zP3qwXBcwdGmVH4QE3u2wmIw=; b=gnhaNytiElyu9dq74wgbuccrigNR0SkAP7JBma0A5f30/7wM21UKEZb9p2egv4k9kLpuBw cluN73Ih6Q6Mh3/Dysjkt34fy7zeFrM8nw3hvPE2Mk9xwUglMfLGenZqHNCXlCxI1Nu8tz Fp7GAGlpNpavWGjjG6ltBnFRETy978A= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fllQS6h7; spf=pass (imf30.hostedemail.com: domain of jkangas@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=jkangas@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732049932; a=rsa-sha256; cv=none; b=Sr6Cz24iUpR/DTAWvln1NT/Jo3vw3A2zNX0pZcd/K/8pcVwtMvKBwFz66D+WenrwlAl2TG EWd615CT5B5ZTengf+6oq5CCbo79ENzi3B8AVXmP5G6he381JStF9XVaF6TpRPF/7Fq1dS 7nVzOGyH82SXPjGk9wlCyL6YFtyygZI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732050174; h=from:from: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; bh=t3TBOVGPHnMk/PpScx+zP3qwXBcwdGmVH4QE3u2wmIw=; b=fllQS6h7nW1Ev2UlCHetX/z9Pv9jOJD1+/Q4QkriE+c+uz3Xlf0Z5bzu1E4xrQBuBJ0c/G HZ9X0MMVm1hbfQZ2hDNbcr5c67+ejAgWHKRbhcE83a86FyAD5jiH+Lxzk5QwptIuXnu6mI Tz7INv3Qz9uRGdj2bVmkq9H0mcWX4AM= Received: from mail-il1-f198.google.com (mail-il1-f198.google.com [209.85.166.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-668-M1Ywk35uNdy7sKLMBflkDA-1; Tue, 19 Nov 2024 16:02:53 -0500 X-MC-Unique: M1Ywk35uNdy7sKLMBflkDA-1 X-Mimecast-MFC-AGG-ID: M1Ywk35uNdy7sKLMBflkDA Received: by mail-il1-f198.google.com with SMTP id e9e14a558f8ab-3a78272b784so7391575ab.3 for ; Tue, 19 Nov 2024 13:02:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732050173; x=1732654973; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=t3TBOVGPHnMk/PpScx+zP3qwXBcwdGmVH4QE3u2wmIw=; b=H2xlwDa5aCzS0dDtxPiuNUq2eoXbKO/DnCxHXlFx3g4sm9cWbOMGiWZTRWFlXxd1Qp l0Nl9+mKv9ltFLOeTvM6TytgqiNKqtfXC5aX/yXM4BOQWrTmBq7zFhNi0mbW7sq+b8C4 wOJZ0XnYneCDS8prtlvCXkPpgxY/YKXniqc0AK6PJ0YBkF8pDk2hrU42Q8iUyXAkrP+G 2xa44XJkLNWHpjsWM9Ox3qisDO+3UTSW2yq9gSVuBN+Y2+kttWvdD3LnKXFSw/u7Joj/ SjDxP14IrDRAVcxG9L1/k838+MEoSmMuv82Wd/trdTvkz26OnO3VK6hTlyhM77mxdVEm jnCQ== X-Forwarded-Encrypted: i=1; AJvYcCVEfVyKpM1GZnZmBTzvbEySHRtoF+HFi79zM592dyahK3v3hiA21gWTlTLcFEE04nAJ//qGVDD0Lg==@kvack.org X-Gm-Message-State: AOJu0Yx0C7/XS/DjgNo+VGSfu3ZVNaIzuLETtAv98oVbou3IJ3SqqS1i viVuAZCyQuULAwqZNlE9w9xsamMfV/jbT6nErARavXFNQTw/tnOlL69tfLfG2Bqr6epT8Wi/71+ tqkCEYk2qPIFAkD7iUq37XZBDfkYNfRqRb7UUKpFB+18Ke0fH X-Received: by 2002:a05:6e02:2163:b0:3a7:7dc9:a4b0 with SMTP id e9e14a558f8ab-3a786457e63mr2505525ab.9.1732050172832; Tue, 19 Nov 2024 13:02:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IHNZhFi4Xzwng9eavnh81Qgmhou8NXC0G0kcJ/atGWwSCqLsA1Fb8DTEeCVsTBJAqR40j3BvA== X-Received: by 2002:a05:6e02:2163:b0:3a7:7dc9:a4b0 with SMTP id e9e14a558f8ab-3a786457e63mr2505235ab.9.1732050172398; Tue, 19 Nov 2024 13:02:52 -0800 (PST) Received: from jkangas-thinkpadp1gen3.rmtuswa.csb ([2601:1c2:4301:5e20:98fe:4ecb:4f14:576b]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4e0756b0e35sm2987964173.108.2024.11.19.13.02.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 13:02:51 -0800 (PST) From: Jared Kangas To: ryabinin.a.a@gmail.com Cc: glider@google.com, andreyknvl@gmail.com, dvyukov@google.com, vincenzo.frascino@arm.com, akpm@linux-foundation.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Jared Kangas Subject: [PATCH] kasan: make report_lock a raw spinlock Date: Tue, 19 Nov 2024 13:02:34 -0800 Message-ID: <20241119210234.1602529-1-jkangas@redhat.com> X-Mailer: git-send-email 2.47.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: xK0VQFWNA6zAKi8m1lD0OgeIj4wBM796Z6FA5hZwvhE_1732050173 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 8270E80003 X-Stat-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tNn0UQDAwi0MIpt2nNm8U6ZDaSlbExfKD/8B0x8z+vnGHF0AB7fCYXzdEZo4mwypJfBWpiMZm9/v9AOXFj8VjGLv5Lo3pSX3mJw6P6GeIPFKaTEYTcoGckHInlbyCfnD470wnmT5sGvnSdhgF1m0dX9pRmHcsjFpGT7ri02Gmcv1I5ohX4TbhQY01OduhuZpCkmCC8L3H4qBSzKVlkw+ef3LD0BWUzFfkHp0qq58rOdJfjpJYBlSzIn53IZ3vDUzwc964DaFsm4Yj73AHHzTk4vk/5W4iI1jhqecKPLLqWvY7NU9YX3BaK3CB82XqHIsyrA0V0NHhVyVIvpOIhIYqMzQdKI1pNzPLv67780FOt2T/zPRl4MDFwa+hUeWUqMPiSH8vOskKwQUkWjiST9lS7UNA3rBOq2O2nFhd+AofK9ZEzjJJF8RIZV0svYjJbFkYFbnrZ83nm5kTShKKVs= 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: List-Subscribe: List-Unsubscribe: If PREEMPT_RT is enabled, report_lock is a sleeping spinlock and must not be locked when IRQs are disabled. However, KASAN reports may be triggered in such contexts. For example: char *s = kzalloc(1, GFP_KERNEL); kfree(s); local_irq_disable(); char c = *s; /* KASAN report here leads to spin_lock() */ local_irq_enable(); Make report_spinlock a raw spinlock to prevent rescheduling when PREEMPT_RT is enabled. Signed-off-by: Jared Kangas --- mm/kasan/report.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/kasan/report.c b/mm/kasan/report.c index b48c768acc84..c7c0083203cb 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -200,7 +200,7 @@ static inline void fail_non_kasan_kunit_test(void) { } #endif /* CONFIG_KUNIT */ -static DEFINE_SPINLOCK(report_lock); +static DEFINE_RAW_SPINLOCK(report_lock); static void start_report(unsigned long *flags, bool sync) { @@ -211,7 +211,7 @@ static void start_report(unsigned long *flags, bool sync) lockdep_off(); /* Make sure we don't end up in loop. */ report_suppress_start(); - spin_lock_irqsave(&report_lock, *flags); + raw_spin_lock_irqsave(&report_lock, *flags); pr_err("==================================================================\n"); } @@ -221,7 +221,7 @@ static void end_report(unsigned long *flags, const void *addr, bool is_write) trace_error_report_end(ERROR_DETECTOR_KASAN, (unsigned long)addr); pr_err("==================================================================\n"); - spin_unlock_irqrestore(&report_lock, *flags); + raw_spin_unlock_irqrestore(&report_lock, *flags); if (!test_bit(KASAN_BIT_MULTI_SHOT, &kasan_flags)) check_panic_on_warn("KASAN"); switch (kasan_arg_fault) {