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 6D878E77180 for ; Thu, 12 Dec 2024 15:07:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B795F6B0082; Thu, 12 Dec 2024 10:07:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B291A6B0088; Thu, 12 Dec 2024 10:07:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9F1226B0089; Thu, 12 Dec 2024 10:07:51 -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 81D3D6B0082 for ; Thu, 12 Dec 2024 10:07:51 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D5B59121959 for ; Thu, 12 Dec 2024 15:07:50 +0000 (UTC) X-FDA: 82886635776.13.7B915BC Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf19.hostedemail.com (Postfix) with ESMTP id 0FFAA1A0026 for ; Thu, 12 Dec 2024 15:07:22 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b="lGaZYc/e"; dkim=pass header.d=linutronix.de header.s=2020e header.b="7d6kHi/3"; spf=pass (imf19.hostedemail.com: domain of bigeasy@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=bigeasy@linutronix.de; dmarc=pass (policy=none) header.from=linutronix.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734016050; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=eY305dc3rE3qvXpFds78ml1gx5qsrQHsdU//zOdN308=; b=5F18OvUvhT2VYwmV094v64B+fFgWgdPjmct9Gmvk3X2xRz25l2FecLr2EKMHdIIeLpDIzX MrbnTi7XuYSwcZ2HlVsxXeeGRxxczAVevhtyK3KyZiS4avREetDKeDULuret3iVXf57RuH f4M6hpOXcaIx+DVcuHx25bLyEdZ6d6o= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b="lGaZYc/e"; dkim=pass header.d=linutronix.de header.s=2020e header.b="7d6kHi/3"; spf=pass (imf19.hostedemail.com: domain of bigeasy@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=bigeasy@linutronix.de; dmarc=pass (policy=none) header.from=linutronix.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734016050; a=rsa-sha256; cv=none; b=8RT/Yav+UgYNKhI+tSpHI3PR5lr7ltSTdFpwUjMtucYNT8zPUjPHMJExl1FptP/Pt8bOvz DaWcqKdTL1Ok3pGoxxN8IR3wjvUc7pey3DrChnAG3c60K1eBjOA34Xsy/RPpLUwkUo5F0A nEOJtQnoH3MJXXFrdDodEoV2Sao47KQ= Date: Thu, 12 Dec 2024 16:07:44 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734016065; 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: in-reply-to:in-reply-to:references:references; bh=eY305dc3rE3qvXpFds78ml1gx5qsrQHsdU//zOdN308=; b=lGaZYc/ev1Oxhb+h7Qhy6vhaJHJpEpMIurB9thL6gwpbSvgiHJ+WPjpdWZdHi/u9HYI/ut 26I+2rseH5/wHn3VnCYnYWXeaEWX+BbcX33CC8d3uiyaHEF+D6VJfps12VJj32IkvS6MHd UZfiRCuu6x4SbrG38+eBLtXTxMfRT9F6QWbEkSpSTc49gjnfMLfbWhRO/TWUQKA2reqZnF IDJhmjh4K+bM96gdQNgcmugT1mQUbZuu+iNkJyHpMhTCSEXQTLPWQA/+sYrWis//MR5Hrt pSRrSpi/+C7TEI4VhO6qfC9n7X7vj4Kjy2bqFzSIjxt2esHYZCRSvRf8dxU4Vw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734016065; 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: in-reply-to:in-reply-to:references:references; bh=eY305dc3rE3qvXpFds78ml1gx5qsrQHsdU//zOdN308=; b=7d6kHi/3PRl0sVZ1/mDjhi0ZH5pVm9hDbqJAoxWDp0wJOp6Fh8kXlNzsaAhsJ9X0GlnsOu GPJJdsE3kiU1ooAw== From: Sebastian Sewior To: Alexei Starovoitov Cc: Michal Hocko , Matthew Wilcox , bpf , Andrii Nakryiko , Kumar Kartikeya Dwivedi , Andrew Morton , Peter Zijlstra , Vlastimil Babka , Steven Rostedt , Hou Tao , Johannes Weiner , shakeel.butt@linux.dev, Thomas Gleixner , Tejun Heo , linux-mm , Kernel Team Subject: Re: [PATCH bpf-next v2 1/6] mm, bpf: Introduce __GFP_TRYLOCK for opportunistic page allocation Message-ID: <20241212150744.dVyycFUJ@linutronix.de> References: <20241210023936.46871-1-alexei.starovoitov@gmail.com> <20241210023936.46871-2-alexei.starovoitov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 0FFAA1A0026 X-Rspamd-Server: rspam12 X-Stat-Signature: d7uy7n3iw5pxweptexe8j1of74ru6zot X-Rspam-User: X-HE-Tag: 1734016042-621395 X-HE-Meta: U2FsdGVkX19ZMs3uZmS+b7GlNdvQvOLJAB8ofrR8/GCPWXeadgo/XQeZptIymahzo2rqhO33Clf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2ATf6lmrxzITKwwuZmbWCw247B1eTWaCwhBzbWjeZa0QCpFXH6VTSsTnEqi88juA1z5AtHjMH7iWOWi33Ld6MViRpj9duXExhQLRRdeysg/zmyLoFqtfWQHhEg== 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 2024-12-10 14:06:32 [-0800], Alexei Starovoitov wrote: > > Is there any reason why GFP_ATOMIC cannot be extended to support new > > contexts? This allocation mode is already documented to be usable from > > atomic contexts except from NMI and raw_spinlocks. But is it feasible to > > extend the current implementation to use only trylock on zone->lock if > > called from in_nmi() to reduce unexpected failures on contention for > > existing users? > > No. in_nmi() doesn't help. It's the lack of reentrance of slab and page > allocator that is an issue. > The page alloctor might grab zone lock. In !RT it will disable irqs. > In RT will stay sleepable. Both paths will be calling other > kernel code including tracepoints, potential kprobes, etc > and bpf prog may be attached somewhere. > If it calls alloc_page() it may deadlock on zone->lock. > pcpu lock is thankfully trylock already. > So !irqs_disabled() part of preemptible() guarantees that > zone->lock won't deadlock in !RT. > And rcu_preempt_depth() case just steers bpf into try lock only path in RT. > Since there is no way to tell whether it's safe to call > sleepable spin_lock(&zone->lock). Oh. You don't need to check rcu_preempt_depth() for that. On PREEMPT_RT rcu_preempt_depth() is incremented with every spin_lock() because we need an explicit start of a RCU section (same thing happens with preempt_disable() spin_lock()). If there is already a RCU section (rcu_preempt_depth() > 0) you can still try to acquire a spinlock_t and maybe schedule out/ sleep. That is okay. But since I see in_nmi(). You can't trylock from NMI on RT. The trylock part is easy but unlock might need to acquire rt_mutex_base::wait_lock and worst case is to wake a waiter via wake_up_process(). Sebastian