From mboxrd@z Thu Jan 1 00:00:00 1970 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 F1068C021A0 for ; Thu, 13 Feb 2025 01:49:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8A7576B0088; Wed, 12 Feb 2025 20:49:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 857976B0089; Wed, 12 Feb 2025 20:49:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 71E986B00A3; Wed, 12 Feb 2025 20:49:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 537A26B0088 for ; Wed, 12 Feb 2025 20:49:14 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 13C52B201B for ; Thu, 13 Feb 2025 01:49:14 +0000 (UTC) X-FDA: 83113238628.19.2E1305D Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) by imf10.hostedemail.com (Postfix) with ESMTP id 1C0B7C0002 for ; Thu, 13 Feb 2025 01:49:11 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=WrCy8uAZ; spf=pass (imf10.hostedemail.com: domain of andreyknvl@gmail.com designates 209.85.128.50 as permitted sender) smtp.mailfrom=andreyknvl@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1739411352; 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:in-reply-to:references:references:dkim-signature; bh=/wY4wXs5+HLRneqjqUBolpxhGqLVUYvpAwoIF6j/MLQ=; b=m9IX0mhw2Pw/1j0JnB58S8R7aISVVZMDAJOXUQhguw6LQ5nLP3+pImAAKSFGxAD22xz3xR rAT8lb7ndfsz/1Wa9KeUk7mI4uyDWiBHUkcInFuzkh9YkJuBN90qd6TuYkUoU2LPmpFMCk BW9N68h33UNSafewAoW43hNwZ7TAw/A= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=WrCy8uAZ; spf=pass (imf10.hostedemail.com: domain of andreyknvl@gmail.com designates 209.85.128.50 as permitted sender) smtp.mailfrom=andreyknvl@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1739411352; a=rsa-sha256; cv=none; b=oti5cqd7ZQsLzlbvDYC5SzDKDvwf9y5YHEUESCDS8y52Niy/vEEik/uvKkZX6XyLJmPKXo pWuSmJmaaDoYS18Adc06AfrEi7UJRCj/lNDrXgWET1+IeyEolKaZ5037usYdGOpnBwsGlc OLD8kDJcqrp8IF7uCAf2r28NwCvgvvE= Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-439585a067eso3386655e9.3 for ; Wed, 12 Feb 2025 17:49:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739411350; x=1740016150; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=/wY4wXs5+HLRneqjqUBolpxhGqLVUYvpAwoIF6j/MLQ=; b=WrCy8uAZczJnQjodnEf/vkJ4HXJJWLTh1fvZ3xn24s8hl24w5/Ote5RHFDI/KshZ1e 8afBu0Y6LL1iezkjUYrQsNBFsaiAMkfj1feH0JktO/l1TyEgegxYHECg6HMsZ2Jce1FG GUI61nWowVOSuK5Sd/3JKe3RBehrZS529koAe0anCxEZaQOZ6x+6DGxAKBydLqZ3JH2/ vTRyxH2O5EThL3cV4mqEgrMRcarRsbqwz61qmslPME7mYw25mIwub09nde0rpnOgZzSI +PXqCrGSQ0pcTIxMO02kCwA795k+TzP5TbW75IvTXSpxq4UCAYvjuYDj9UR6qt6fHuzP jfKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739411350; x=1740016150; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/wY4wXs5+HLRneqjqUBolpxhGqLVUYvpAwoIF6j/MLQ=; b=dDk9bjJHGYGeWtBMGxNLB4tUW+djjyzYGzfoz/b8oXSAtZE5k6M7kq3R8Kid6at+gj f7b3HuHCHTA1dDg7n2caHj2yNL+etQK7yZFlniEW4Oyhh8lTqywAF/Y8ihQiyRI1//2F 9Mc+ULw8usCfJ/Lo9HrFHvpEKPiTlokS8HrxmyMSOBhXQ13fO1h0Hbbf2hKwNmq3yQjE thzBbgCc5y/DjLtkBVB/L6TzWfyl72JL+SkpbgOq33rUTfSIhuUWay1AtDfHcx2x8tHT CIzINuexGF7GZg6u4VmqfTdT80qbga4r+8JAqVakmnVNG7nSHT0IDMU904WJGCNzXmnu 16dQ== X-Forwarded-Encrypted: i=1; AJvYcCWCdizUSQ2UfB8vN7tsIGDzdwXTW05OsPDz6J1bHrO9uwKh5BtK5ldjZMeYCymAUBxQaA+aXUImww==@kvack.org X-Gm-Message-State: AOJu0YwZNYD9x7qNSNqCtCA7aFMtmeMNnXxg0thQUGRT2W2Jh/hSxFy0 RDSTTanxfVGPoHOZu0LZ7abdWJ4GrGe3UoWkfr1LuDqZHhzJRmbh3P5ujLd2DfnVTkcEii/V4lQ OxGSfRo1w+Aeou1X1LtrxWd5Qbok= X-Gm-Gg: ASbGnctzoxGNR/A/InfLNoSN2jEjc/w4AvoSC9cybnjvhnhT127oowGULupvAavhqb5 P7B/36Qh/Q1misL/PlghAz7kmY6w/vht+hwgxfL7azZyLJdW/3itzC0iP2PTce1Z062eGEVvMs2 o= X-Google-Smtp-Source: AGHT+IGsexwhGjEvQnmXxS/PprXAz9+JEzr7OrPin2TezEcpsjL4WY4sUa5E3qCz5q59GrohfZFhC8yZjHvgGdZoZ1o= X-Received: by 2002:a05:600c:1d9b:b0:439:60ef:ce94 with SMTP id 5b1f17b1804b1-43960efd0ffmr6349015e9.21.1739411350285; Wed, 12 Feb 2025 17:49:10 -0800 (PST) MIME-Version: 1.0 References: <20250212162151.1599059-1-longman@redhat.com> In-Reply-To: <20250212162151.1599059-1-longman@redhat.com> From: Andrey Konovalov Date: Thu, 13 Feb 2025 02:48:59 +0100 X-Gm-Features: AWEUYZlva8wcqIGZAMNqHBqIKxnv5SeuKq11Lnse6U1bm1Vg8g3HRUGtElXJDM4 Message-ID: Subject: Re: [PATCH v2] kasan: Don't call find_vm_area() in RT kernel To: Waiman Long , Peter Zijlstra Cc: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Vincenzo Frascino , Andrew Morton , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, Nico Pache Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Queue-Id: 1C0B7C0002 X-Stat-Signature: p9q5nj4zomh6ugsbzaeqo665ruemypob X-Rspamd-Server: rspam03 X-HE-Tag: 1739411351-784099 X-HE-Meta: U2FsdGVkX19fZGuFhaL+Y47XCWw2Dor/fPPNprTJsM3oO46yAoDg0248+hNbRz3ZgOdjCTdeVUmH+Ln9DHL9Sl6JIi5URjv6DS6AyaYWxUT+w9LaFZzS8Da5QESA6qe1TrrbM3cop3KPHPmsvomWK0QxYyNtpYnhpTsiatXHRxsLaW5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ufvqmJPSbRJb3t8Ug0lndzQaU73zpieB0odd3FaOmDLeU05tdZi5jNQF/+JpMxggZTXiGCTs0JOmUNaEnte+mgec8i17vzF4Aiy1wKNyhXqURHRdeUidDR38l6WmZIHrqtxLfkVw3y/c7BIApAMPZgGMHnoMDqLxFeQ0KVRqV0ftstoo1L43M8vQfIfaAftH0Fz+E= 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: On Wed, Feb 12, 2025 at 5:22=E2=80=AFPM Waiman Long wr= ote: > > The following bug report appeared with a test run in a RT debug kernel. > > [ 3359.353842] BUG: sleeping function called from invalid context at kern= el/locking/spinlock_rt.c:48 > [ 3359.353848] in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 140= 605, name: kunit_try_catch > [ 3359.353853] preempt_count: 1, expected: 0 > : > [ 3359.353933] Call trace: > : > [ 3359.353955] rt_spin_lock+0x70/0x140 > [ 3359.353959] find_vmap_area+0x84/0x168 > [ 3359.353963] find_vm_area+0x1c/0x50 > [ 3359.353966] print_address_description.constprop.0+0x2a0/0x320 > [ 3359.353972] print_report+0x108/0x1f8 > [ 3359.353976] kasan_report+0x90/0xc8 > [ 3359.353980] __asan_load1+0x60/0x70 > > Commit e30a0361b851 ("kasan: make report_lock a raw spinlock") > changes report_lock to a raw_spinlock_t to avoid a similar RT problem. > The print_address_description() function is called with report_lock > acquired and interrupt disabled. However, the find_vm_area() function > still needs to acquire a spinlock_t which becomes a sleeping lock in > the RT kernel. IOW, we can't call find_vm_area() in a RT kernel and > changing report_lock to a raw_spinlock_t is not enough to completely > solve this RT kernel problem. > > Fix this bug report by skipping the find_vm_area() call in this case > and just print out the address as is. > > For !RT kernel, follow the example set in commit 0cce06ba859a > ("debugobjects,locking: Annotate debug_object_fill_pool() wait type > violation") and use DEFINE_WAIT_OVERRIDE_MAP() to avoid a spinlock_t > inside raw_spinlock_t warning. Would it be possible to get lockdep to allow taking spinlock_t inside raw_spinlock_t instead of annotating the callers for the !RT case? Or is this a rare thing for this to be allowed on !RT? > > Fixes: e30a0361b851 ("kasan: make report_lock a raw spinlock") > Signed-off-by: Waiman Long > --- > mm/kasan/report.c | 47 ++++++++++++++++++++++++++++++++++------------- > 1 file changed, 34 insertions(+), 13 deletions(-) > > [v2] Encapsulate the change into a new > kasan_print_vmalloc_info_ret_page() helper > > diff --git a/mm/kasan/report.c b/mm/kasan/report.c > index 3fe77a360f1c..9580ac3f3203 100644 > --- a/mm/kasan/report.c > +++ b/mm/kasan/report.c > @@ -370,6 +370,38 @@ static inline bool init_task_stack_addr(const void *= addr) > sizeof(init_thread_union.stack)); > } > > +/* > + * RT kernel cannot call find_vm_area() in atomic context. For !RT kerne= l, > + * prevent spinlock_t inside raw_spinlock_t warning by raising wait-type > + * to WAIT_SLEEP. > + * > + * Return: page pointer or NULL > + */ > +static inline struct page *kasan_print_vmalloc_info_ret_page(void *addr) No need for the kasan_ prefix: this is a static function. (Also the _ret_* suffix is something I've never seen before in the kernel context, but I don't mind it.) > +{ > + if (!IS_ENABLED(CONFIG_PREEMPT_RT)) { > + static DEFINE_WAIT_OVERRIDE_MAP(vmalloc_map, LD_WAIT_SLEE= P); > + struct page *page =3D NULL; > + struct vm_struct *va; > + > + lock_map_acquire_try(&vmalloc_map); > + va =3D find_vm_area(addr); > + if (va) { > + pr_err("The buggy address belongs to the virtual = mapping at\n" > + " [%px, %px) created by:\n" > + " %pS\n", > + va->addr, va->addr + va->size, va->caller)= ; > + pr_err("\n"); > + > + page =3D vmalloc_to_page(addr); > + } > + lock_map_release(&vmalloc_map); > + return page; > + } > + pr_err("The buggy address %px belongs to a vmalloc virtual mappin= g\n", addr); > + return NULL; > +} > + > static void print_address_description(void *addr, u8 tag, > struct kasan_report_info *info) > { > @@ -398,19 +430,8 @@ static void print_address_description(void *addr, u8= tag, > pr_err("\n"); > } > > - if (is_vmalloc_addr(addr)) { > - struct vm_struct *va =3D find_vm_area(addr); > - > - if (va) { > - pr_err("The buggy address belongs to the virtual = mapping at\n" > - " [%px, %px) created by:\n" > - " %pS\n", > - va->addr, va->addr + va->size, va->caller)= ; > - pr_err("\n"); > - > - page =3D vmalloc_to_page(addr); > - } > - } > + if (is_vmalloc_addr(addr)) > + page =3D kasan_print_vmalloc_info_ret_page(addr); > > if (page) { > pr_err("The buggy address belongs to the physical page:\n= "); > -- > 2.48.1 >