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 1EE78D711B0 for ; Wed, 20 Nov 2024 15:25:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9108D6B0089; Wed, 20 Nov 2024 10:25:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8BFB16B008A; Wed, 20 Nov 2024 10:25:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B4DF6B008C; Wed, 20 Nov 2024 10:25:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 5D88F6B0089 for ; Wed, 20 Nov 2024 10:25:32 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id EE96B1208AA for ; Wed, 20 Nov 2024 15:25:31 +0000 (UTC) X-FDA: 82806847200.14.B8A66A3 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf08.hostedemail.com (Postfix) with ESMTP id B24F3160023 for ; Wed, 20 Nov 2024 15:24:55 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf08.hostedemail.com: domain of "SRS0=2jgT=SP=goodmis.org=rostedt@kernel.org" designates 139.178.84.217 as permitted sender) smtp.mailfrom="SRS0=2jgT=SP=goodmis.org=rostedt@kernel.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732116145; 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; bh=kPlGcgNc2zQfvlPwJa9He7pCKG0aHEMtxS6xtC+v1Ns=; b=T2AqVhJhpBE2QWUD7ez4B9awq/iCymamplJH4iSaGzLYgSxVvKvHa18AOpUxgJpPUOWaog 3qGYkSHY4DToH0Si0ZvkVSMmxmwzD4KJQsLHELJsQlKhYS/DtitEI9fVMWH9a0owy/lYEB 6j3ainJomTFvaHm8wCweZeCWWspuQMI= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf08.hostedemail.com: domain of "SRS0=2jgT=SP=goodmis.org=rostedt@kernel.org" designates 139.178.84.217 as permitted sender) smtp.mailfrom="SRS0=2jgT=SP=goodmis.org=rostedt@kernel.org" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732116145; a=rsa-sha256; cv=none; b=M+jbowfbXXA3xLuNAF07m88u7x8JNye8M/w7DbO/q5rxFzBqxPR9bPAljBDbfFHmGBROop HzAj0r/l0LeXfjDjUYlA4oeMRTi7XWfU0FviCVwWdKo29gnLAxBYlO2iyTQkfstef0DLMI Bf/QUn3bfwt2z90gCtS6ofGkJU028Lk= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 00ED75C58D5; Wed, 20 Nov 2024 15:24:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 183F7C4CECD; Wed, 20 Nov 2024 15:25:26 +0000 (UTC) Date: Wed, 20 Nov 2024 10:26:02 -0500 From: Steven Rostedt To: Catalin Marinas Cc: Alessandro Carminati , Andrew Morton , Sebastian Andrzej Siewior , Clark Williams , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, Thomas Weissschuh , Alessandro Carminati , Juri Lelli , Gabriele Paoloni , Eric Chanudet Subject: Re: [PATCH] mm/kmemleak: Fix sleeping function called from invalid context in kmemleak_seq_show Message-ID: <20241120102602.3e17f2d5@gandalf.local.home> In-Reply-To: References: <20241120102325.3538-1-acarmina@redhat.com> X-Mailer: Claws Mail 3.20.0git84 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: B24F3160023 X-Stat-Signature: mmzdx5gkf4mz671odizifz9az7hgzbuu X-Rspam-User: X-HE-Tag: 1732116295-290318 X-HE-Meta: U2FsdGVkX1/AwFV1r0G5RnzjqVVm23lcKZKWZVF7CHTORZtawOecCKy57+pnSEj4ftIni2Kc98QAcqGBMJMwBnU2fToipRu1TbcHCdXBJvwwBnfE+5YG9WaxiaFCBScbSk79VMy24IOTOQIMrXKqa2ZWoJp+7/aVoCJvX3lGImei1jZNEvLZYAWmrAsElfwUSkR+GwRdu09U/ugLua63z565+DCJwEh9ESBmrzpKSHSvz5arZz4FB2ZKgFd8INTZ9WXsXWp5VYwr6OIPNLP5Wu7u3rt53P0sz0Qd8J6yEoFWv2hPXP0s//AULzJbZypQYrKMQJUKd98qsRsSsuhxPV9ghdhyXYPkfeN8/GTnSPkM9/4iDputu0t2GuyRfiWFjeEjE9acNGq+ViRko49L3FD/Y6usVJVGRvs3BobZgLLABZV+tF8k11EYfV/bwCDPZPCkV24Igc3xvGL3o4sT9/qhEz8bHiFa2se7nZ9K8ey2AoBEk3e0MJYD+hFX4eIAkanpZQPBLtp6tcgeTOOp0HOK2gamDhh5fzczavTw2Xarx1YA5MjyHJ7RKfPudGPI7YeG5OqtnE7u1F2IgrzAJrXgcHExFRBkjaWo47fnQ4T8m2nboCBZQ8sTppRiEeqYpXzOFbx73CmQHXGARWZmT50e6MmHIlPdzYztl4VaBIwuZ0jgWP5OgNeyRnPcgnBi7jNWReIbfQYoKrsFttlToOlvrsGSbp2ZjvVlIp8KPtiu1r1Rc59pnAtGrp1z9XDVyUa3lS1rq2UsMmbF9QZ0PBFKQsNpZ3fHElDwpd6C457vlybwT2b7vV1HNqCmUwiuBcvp0mmYcF4rbHD8jmAg7nQgzVJNCFH9TXRE8t6yvZDd/x+XLbQEoDVLeW/USrQ+BW/rV6n6CQg0QThHgO0Erap3wZSaq6rMajEp3/1RShlrNoMfiGb/S9FnE7bW9N05PIm6YNI0d2W7Sz7lvaL N154PNNC OjHNGqlxmmWiZTrHIfPaCIzEW4xlF7hb2Rp4DJ89Sga7anjYSxfQbF3826H81RsnapIIoLw+E7e1iMr4DigHwSrHc3AkopIO0CDvvc8nZtfj1cdWgn3usQ2EAO2Ecqeu3Ylt6x/jqNasLMIDj94xURK9ibmqQKor9hvNUYuB9he9zIMPQKxDRqrb3PBYThYBe+YjiN1iiJOi0VAWzmN+2bHJy3g+qqVU7PEx9os02vXcClr9+0IaPijHNmboG/5NliILZDnGZFcsqt8BHHKUmV8g1oqmHQ+sE/t1otlFVcYujaH0wTwkwcTYnsb6ycgesp7t9qXWfIfML5Rv6EusKmEEAOnJH7ZHGGGuL2+wHU8gqZ1kL5PocVdOFPM682qzaZN9Ku5KzBYeMtoPBo4tToSQnRDQaRLMhHrsesAH3e3N7Xqo= 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, 20 Nov 2024 14:53:13 +0000 Catalin Marinas wrote: > > -static void print_unreferenced(struct seq_file *seq, > > +static depot_stack_handle_t print_unreferenced(struct seq_file *seq, > > struct kmemleak_object *object) > > { > > - int i; > > - unsigned long *entries; > > - unsigned int nr_entries; > > - > > - nr_entries = stack_depot_fetch(object->trace_handle, &entries); > > warn_or_seq_printf(seq, "unreferenced object 0x%08lx (size %zu):\n", > > object->pointer, object->size); > > warn_or_seq_printf(seq, " comm \"%s\", pid %d, jiffies %lu\n", > > @@ -371,6 +366,23 @@ static void print_unreferenced(struct seq_file *seq, > > hex_dump_object(seq, object); > > warn_or_seq_printf(seq, " backtrace (crc %x):\n", object->checksum); > > > > + return object->trace_handle; > > +} > > What I don't fully understand - is this a problem with any seq_printf() > or just the backtrace pointers from the stack depot that trigger this > issue? I guess it's something to do with restricted pointers but I'm not > familiar with the PREEMPT_RT concepts. It would be good to explain, > ideally both in the commit log and a comment in the code, why we only > need to do this for the stack dump. In PREEMPT_RT, to achieve the ability to preempt in more context, spin_lock() is converted to a special sleeping mutex. But there's some places where it can not be converted, and in those cases we use raw_spin_lock(). kmemleak has been converted to use raw_spin_lock() which means anything that gets called under that lock can not take a normal spin_lock(). What happened here is that the kmemleak raw spinlock is held and seq_printf() is called. Normally, this is not an issue, but the behavior of seq_printf() is dependent on what values is being printed. The "%pK" dereferences a pointer and there's some SELinux hooks attached to that code. The problem is that the SELinux hooks take spinlocks. This would not have been an issue if it wasn't for that "%pK" in the format. Maybe SELinux locks should be converted to raw? I don't know how long that lock is held. There are some loops though :-/ avc_insert(): spin_lock_irqsave(lock, flag); hlist_for_each_entry(pos, head, list) { if (pos->ae.ssid == ssid && pos->ae.tsid == tsid && pos->ae.tclass == tclass) { avc_node_replace(node, pos); goto found; } } hlist_add_head_rcu(&node->list, head); found: spin_unlock_irqrestore(lock, flag); Perhaps that could be converted to simple RCU? As I'm sure there's other places that call vsprintf() under a raw_spin_lock or non-preemptable context, perhaps this should be the fix we do. -- Steve