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 E41B1C021A9 for ; Mon, 17 Feb 2025 16:29:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 50B8D280040; Mon, 17 Feb 2025 11:29:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4BB5C28003F; Mon, 17 Feb 2025 11:29:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 35CD5280040; Mon, 17 Feb 2025 11:29:02 -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 16F3A28003F for ; Mon, 17 Feb 2025 11:29:02 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C86AE8080E for ; Mon, 17 Feb 2025 16:29:01 +0000 (UTC) X-FDA: 83129970882.11.AD5A4A9 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by imf10.hostedemail.com (Postfix) with ESMTP id DB1BEC0002 for ; Mon, 17 Feb 2025 16:28:59 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="B4Hh2/ci"; spf=pass (imf10.hostedemail.com: domain of andreyknvl@gmail.com designates 209.85.128.42 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=1739809740; 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=yz5eSSbGmek/6y/tsCBF0vwN+yx7lRsH/SSKw++UQXI=; b=oNm89XvhNnAJAyqffINz4h0oaczV6MAl/qHMkfnJmDAFlWVdftVpCC3ivZaC5kcyQmYqSz OopYoeQCbFwGwuKy9wGhH/nHlFQf3XTjKMo7LZjfZ7hUhbdnF+MjQ5DrAMPeLQdSc6ltM9 OHNV07eyS9ulq4LQ4EsrmWTHbQfvt9Q= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="B4Hh2/ci"; spf=pass (imf10.hostedemail.com: domain of andreyknvl@gmail.com designates 209.85.128.42 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=1739809740; a=rsa-sha256; cv=none; b=Pid2lPxJVDDiw+ZSNDiQDz3gWy4or0/KRoPr1w1qyf3XsRuKGA4RSR5oSadQev+HAe0wAp M0Ft2LIdfhWrDz4jFcAywo6949zw4VRF+pkIoa5INX1EoQLzfGCzFWD3e+odTcJYK5MOXN enJ+mQlPfKaGtKLoEN+4SGNOMZVmouI= Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-4395dddb07dso47494025e9.2 for ; Mon, 17 Feb 2025 08:28:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739809738; x=1740414538; 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=yz5eSSbGmek/6y/tsCBF0vwN+yx7lRsH/SSKw++UQXI=; b=B4Hh2/ciQpDKvhZ5jJAKDG97gXUtmqjb83c5gk9Q3ekSi1L3BrpBAcnFB6ppbI/CzT WcteSXc3QLTAAzkjGPtowQ3t/KyYMbne1QEIZzvTkwfPMCkaB6szGVkdWJB4MjCVajio t6FBbJyv4/XSQOLWQcHfC7o9wsqPsAlsLIndDy9jneFt0r9rT+k+PACTbZG5ca1v8D4r +FmEfNNru1QCWkAZQpX3UCsNAQTl3fjeiugEJhTTsC1lvItN0v6LfULMIBxeygHu/kte VeBtaAwYb5iYqf9lZSGLKWuVE9b/H5fmdVqniv0t6DWRlCHtPgXs9YrG6xZlS1CCWFb5 Abgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739809738; x=1740414538; 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=yz5eSSbGmek/6y/tsCBF0vwN+yx7lRsH/SSKw++UQXI=; b=fK0b0LSxFyqFs2UxdE+iC2eol0gXNr44foYFJrlMwsCtm2Wg/YJ6iD7MrDZlVceEMn 78/JEvMa7L0w2TOACmlcbEPduxgurr1MwuID8OD8Er8cmZsn/Hn/PVmwEqfItCbKW1Fk LT5iYy5CeYHx3jlvaFWVl1W7KRaW5Gxytjdv5DFRz9701c/1SEKhKXl0uYgt0UoZHUxm c9cfx/UP4wnUAp5fQ6Sp3MPxRf1/E026MxOtILHR2UPoh3ItGVc1WM7iU4EQkCDETbGJ CGLm7W2rQj2qrAvyfLgeuRTXAFp4l/fDG3JIsrCr29ZhTkdfmZIALh7uFVVAR81N4s13 toIQ== X-Forwarded-Encrypted: i=1; AJvYcCXUzfFUjweQmU6VPlmDPyveqZN5TnYbrtZ19lymoI8wafnwfSdAmV9Z+VfEEpc3nNtvDQBgXrPsLg==@kvack.org X-Gm-Message-State: AOJu0YyshzCEx8CctscownCAaYQJJakTXACwU7mu95Dy8+Ezc52uN9T3 PaxgROcsfjDsD9Vq9h/TFBhbq93exzX4RSDwQzucM+o2dKZn04dD4L+n5SIM3EexXgrby5u3E/E avaRjIZ/Q4hNl77GsulAVsoHmdMQ= X-Gm-Gg: ASbGncs6v+L2/QYtyGHCKD/iWcFOMXbwy+6waj0WVJajXbISufh1UdAfZsV9gLCVVn0 EmcYFHdjz2/kBabDlklJwsUiosu6+PMDmzpTxsTXg0WV4Tsl5BJ+4r7R/Sks0/nXkwNgjoH3sMg 4= X-Google-Smtp-Source: AGHT+IEPuRn8oRyxtXUQAo68jc/IBOxP+D9vVZ6bGu1LAWQCU9Qytan12Krv6Qaacj6NLJ4/0DOTG24ArEI/XoTia0w= X-Received: by 2002:adf:ec03:0:b0:38a:88ac:f115 with SMTP id ffacd0b85a97d-38f340676b0mr8083238f8f.34.1739809737912; Mon, 17 Feb 2025 08:28:57 -0800 (PST) MIME-Version: 1.0 References: <20250217042108.185932-1-longman@redhat.com> In-Reply-To: <20250217042108.185932-1-longman@redhat.com> From: Andrey Konovalov Date: Mon, 17 Feb 2025 17:28:46 +0100 X-Gm-Features: AWEUYZkOCsf3Lwl5kZxqhWvK51MQBU8TFE8a7QrsCXHmnwBN1EdOJpdIiaaxzBA Message-ID: Subject: Re: [PATCH v3] kasan: Don't call find_vm_area() in RT kernel To: Waiman Long 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-Server: rspam09 X-Rspamd-Queue-Id: DB1BEC0002 X-Stat-Signature: hqc9go5berde63q161gj3m4zdr3jfnse X-HE-Tag: 1739809739-668766 X-HE-Meta: U2FsdGVkX1+7C3PCTAa+JwcWfsKGOlt1kJ/II/Gkn2C4aLJTXK7YiG3G2fe/MthUVYlXWsdmB3mIuIzWCRjakCAUz6zrhIDePxGY+8Zac3boo50jRUOmF/r7yxVLPf2gkpD4nzUZevdpzmP3VSqhkT8FLfRVGLrlwy3YaU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7jlQreMw7L0wVBCpGO8TWp5F1pj0PBfUSofp3OWxGqwhqjkaeXKKrWv/G2/toq3jznMxKVSj3eZldYGEa1Gc4wHCCMcn8zftOkbjTE63CGJAhQN1zaSOA9vdAg3d5E7WM8a1PQ3mTa6NJOV2adAeOkqsjxlLyUjqaegaCHukHSvdt3zeagXYJhJ1hjojXUXCCY+o2nQHmpDzsNwAjw= 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 Mon, Feb 17, 2025 at 5:21=E2=80=AFAM 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. > > Fixes: e30a0361b851 ("kasan: make report_lock a raw spinlock") > Signed-off-by: Waiman Long > --- > mm/kasan/report.c | 43 ++++++++++++++++++++++++++++++------------- > 1 file changed, 30 insertions(+), 13 deletions(-) > > [v3] Rename helper to print_vmalloc_info_set_page. > > diff --git a/mm/kasan/report.c b/mm/kasan/report.c > index 3fe77a360f1c..7c8c2e173aa4 100644 > --- a/mm/kasan/report.c > +++ b/mm/kasan/report.c > @@ -370,6 +370,34 @@ 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. Quoting your response from the other thread: > Lockdep currently issues warnings for taking spinlock_t inside > raw_spinlock_t because it is not allowed in RT. Test coverage of RT > kernels is likely less than !RT kernel and so less bug of this kind will > be caught. By making !RT doing the same check, we increase coverage. > However, we do allow override in the !RT case, but it has to be done on > a case-by-case basis. Got it. So let's put this exactly this explanation in the comment, otherwise it's unclear why we need something special for the !RT case. > + */ > +static inline void print_vmalloc_info_set_page(void *addr, struct page *= *ppage) > +{ > + if (!IS_ENABLED(CONFIG_PREEMPT_RT)) { > + static DEFINE_WAIT_OVERRIDE_MAP(vmalloc_map, LD_WAIT_SLEE= P); > + 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"); > + > + *ppage =3D vmalloc_to_page(addr); Looking at the code again, I actually like the Andrey Ryabinin's suggestion from the v1 thread: add a separate function that contains an annotated call of find_vm_area(). And keep vmalloc_to_page() outside of it, just as done in the upstream version now. > + } > + lock_map_release(&vmalloc_map); > + return; > + } > + pr_err("The buggy address %px belongs to a vmalloc virtual mappin= g\n", addr); > +} > + > static void print_address_description(void *addr, u8 tag, > struct kasan_report_info *info) > { > @@ -398,19 +426,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)) > + print_vmalloc_info_set_page(addr, &page); > > if (page) { > pr_err("The buggy address belongs to the physical page:\n= "); > -- > 2.48.1 >