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 BE414C43334 for ; Tue, 28 Jun 2022 13:57:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 27AE66B0071; Tue, 28 Jun 2022 09:57:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 22CEA8E0002; Tue, 28 Jun 2022 09:57:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0F49A8E0001; Tue, 28 Jun 2022 09:57:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 000AB6B0071 for ; Tue, 28 Jun 2022 09:57:57 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id BC12D607EC for ; Tue, 28 Jun 2022 13:57:57 +0000 (UTC) X-FDA: 79627798194.14.9D9A6C8 Received: from gentwo.de (gentwo.de [161.97.139.209]) by imf23.hostedemail.com (Postfix) with ESMTP id 9427D140020 for ; Tue, 28 Jun 2022 13:57:56 +0000 (UTC) Received: by gentwo.de (Postfix, from userid 1001) id 85421B00288; Tue, 28 Jun 2022 15:57:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gentwo.de; s=default; t=1656424674; bh=VT8t4+mQig9OHwaOUo8PSDyy3DkhSeEak6r67HuPmB8=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=ihddj4pHEl8O1YbhCY63nb3i7cS1+j1fP6ZlwqcOkp2nypfaq8UBPWY7gE1sktLWD wt8KhDYmklnczDFwKbGaRfxbDgkKcMVz3zq0hh5JEhYEPRqIgNLS8Tw+R+2jgCT3QX FpNwHYmmFNxwh67WbnZsD3vynoQUlhxajKyDzI70oDTYxXcntP1VUvtuydTlFAVjnC cQsNPMyY9aS+vxLkJECNXgpR/TxSxPzRIfCNHJcrIbe21DKBn2SMfPNRvQI9ODIC28 BhNauNbGMs92yX+I7JAa+OYnDspvlBk320AqxKqApexIw4TOul6gdu9yGD4oUxXhgp Eo645rgeTyQZw== Received: from localhost (localhost [127.0.0.1]) by gentwo.de (Postfix) with ESMTP id 82930B00132; Tue, 28 Jun 2022 15:57:54 +0200 (CEST) Date: Tue, 28 Jun 2022 15:57:54 +0200 (CEST) From: Christoph Lameter To: Alexei Starovoitov cc: Christoph Hellwig , David Miller , Daniel Borkmann , Andrii Nakryiko , Tejun Heo , Martin KaFai Lau , bpf , Kernel Team , linux-mm , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka Subject: Re: [PATCH bpf-next 0/5] bpf: BPF specific memory allocator. In-Reply-To: Message-ID: References: User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656424676; a=rsa-sha256; cv=none; b=Y+5zQgFfYB5k8NzqdYXu28EXNBVKcUbskXLx5AtY3R1OjNgLn6j3mUHaTtH++zRAWOclx6 FD77nOiZYdvMQ4cyXhukGkUZsRx0XMlzu9kNKl6/dA03TiSgbxB+Glt+DK4e7CMAUEujyT AL4GkhVuuX0AC0bbtJ1GykhUkaOh2Ds= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gentwo.de header.s=default header.b=ihddj4pH; dmarc=pass (policy=none) header.from=gentwo.de; spf=pass (imf23.hostedemail.com: domain of cl@gentwo.de designates 161.97.139.209 as permitted sender) smtp.mailfrom=cl@gentwo.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656424676; 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=hwhwUjxvSNqpBsPmTqN1vXjQfGf+5lUkjQW0aXkinY8=; b=liYfW7P23h4Z9LdmU3q94lPsZGUeBUT4TdO8+SXDQe7a8EAicPMc7RnPo/ZfSle2og5rnS sNnl8DSNpjT6fr3vT0qH+w0B20jijDkK9Tpa4TJSyRcLIjeeJ/vGMUbkTJxQXEk+qsJi8i DGD9U/Ru+eV7iDJNCrj41daOX98+6ho= X-Stat-Signature: 11moa8wpw3kheuwzoz8u7ysegzi4r53k X-Rspam-User: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9427D140020 Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gentwo.de header.s=default header.b=ihddj4pH; dmarc=pass (policy=none) header.from=gentwo.de; spf=pass (imf23.hostedemail.com: domain of cl@gentwo.de designates 161.97.139.209 as permitted sender) smtp.mailfrom=cl@gentwo.de X-HE-Tag: 1656424676-690821 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: On Mon, 27 Jun 2022, Alexei Starovoitov wrote: > On Mon, Jun 27, 2022 at 5:17 PM Christoph Lameter wrote: > > > > > From: Alexei Starovoitov > > > > > > Introduce any context BPF specific memory allocator. > > > > > > Tracing BPF programs can attach to kprobe and fentry. Hence they > > > run in unknown context where calling plain kmalloc() might not be safe. > > > Front-end kmalloc() with per-cpu per-bucket cache of free elements. > > > Refill this cache asynchronously from irq_work. > > > > GFP_ATOMIC etc is not going to work for you? > > slab_alloc_node->slab_alloc->local_lock_irqsave > kprobe -> bpf prog -> slab_alloc_node -> deadlock. > In other words, the slow path of slab allocator takes locks. That is a relatively new feature due to RT logic support. without RT this would be a simple irq disable. Generally doing slab allocation while debugging slab allocation is not something that can work. Can we exempt RT locks/irqsave or slab alloc from BPF tracing? I would assume that other key items of kernel logic will have similar issues. > Which makes it unsafe to use from tracing bpf progs. > That's why we preallocated all elements in bpf maps, > so there are no calls to mm or rcu logic. > bpf specific allocator cannot use locks at all. > try_lock approach could have been used in alloc path, > but free path cannot fail with try_lock. > Hence the algorithm in this patch is purely lockless. > bpf prog can attach to spin_unlock_irqrestore and > safely do bpf_mem_alloc. That is generally safe unless you get into reetrance issues with memory allocation. Which begs the question: What happens if I try to use BPF to trace *your* shiny new memory allocation functions in the BPF logic like bpf_mem_alloc? How do you stop that from happening?