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 CBEC6ECAAD2 for ; Mon, 29 Aug 2022 21:31:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 665FC940007; Mon, 29 Aug 2022 17:31:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 615BA6B0074; Mon, 29 Aug 2022 17:31:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4DE7C940007; Mon, 29 Aug 2022 17:31:02 -0400 (EDT) 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 407DA6B0073 for ; Mon, 29 Aug 2022 17:31:02 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 17A411A0340 for ; Mon, 29 Aug 2022 21:31:02 +0000 (UTC) X-FDA: 79853925564.07.CDB6B5F Received: from www62.your-server.de (www62.your-server.de [213.133.104.62]) by imf11.hostedemail.com (Postfix) with ESMTP id 7816540027 for ; Mon, 29 Aug 2022 21:31:01 +0000 (UTC) Received: from sslproxy01.your-server.de ([78.46.139.224]) by www62.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1oSmLN-0006af-I1; Mon, 29 Aug 2022 23:30:53 +0200 Received: from [85.1.206.226] (helo=linux-4.home) by sslproxy01.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oSmLN-000N2o-8H; Mon, 29 Aug 2022 23:30:53 +0200 Subject: Re: [PATCH v4 bpf-next 01/15] bpf: Introduce any context BPF specific memory allocator. To: Alexei Starovoitov , davem@davemloft.net Cc: andrii@kernel.org, tj@kernel.org, memxor@gmail.com, delyank@fb.com, linux-mm@kvack.org, bpf@vger.kernel.org, kernel-team@fb.com References: <20220826024430.84565-1-alexei.starovoitov@gmail.com> <20220826024430.84565-2-alexei.starovoitov@gmail.com> From: Daniel Borkmann Message-ID: <74acd56b-21bb-8ea8-092f-d1b4fcfc0790@iogearbox.net> Date: Mon, 29 Aug 2022 23:30:52 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20220826024430.84565-2-alexei.starovoitov@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.103.6/26642/Mon Aug 29 09:54:26 2022) ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of daniel@iogearbox.net designates 213.133.104.62 as permitted sender) smtp.mailfrom=daniel@iogearbox.net; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661808661; a=rsa-sha256; cv=none; b=kvdI97N7JtILegG39bCg98ykX0x+N9RHHEsbLUTAASPAtDUR1NgCSMH2h7Max8OKm6Ip60 RJmeRcz1UfQkC/1KWI6w9biBU0sBy4dTKAKIOw8Wsh385pdKwBv404W2UqVnJmHekXuNTg yLPxE+qxP8O+5GmSi9gE+hEyrZQMEMc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661808661; 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=sMPPOwiPQfXD6GjNt/0SXsIJfYzTGF3TtzB8Lc7rY2w=; b=IqOAn1Z8hVYXbxEmmSfiuYy5wsfXS1g77+htNLJZ+0mp+CQCwjKbyhC2/JVA0Nh625WYJv havvSFTkbrnVbgL9u8tsyAap6Qqo5hUeRBCZKQ3V3HKAPh+/GTRvIDRCNAN4c/ogcYtR8c vITaN9Vq4QZ4sTK7VUs+dZSkgrSvmBM= X-Rspam-User: X-Stat-Signature: 11o9ofjt8yasickqabjoj5xzcodggnpb X-Rspamd-Queue-Id: 7816540027 Authentication-Results: imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of daniel@iogearbox.net designates 213.133.104.62 as permitted sender) smtp.mailfrom=daniel@iogearbox.net; dmarc=none X-Rspamd-Server: rspam07 X-HE-Tag: 1661808661-618213 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 8/26/22 4:44 AM, Alexei Starovoitov wrote: [...] > + > +/* Called from BPF program or from sys_bpf syscall. > + * In both cases migration is disabled. > + */ > +void notrace *bpf_mem_alloc(struct bpf_mem_alloc *ma, size_t size) > +{ > + int idx; > + void *ret; > + > + if (!size) > + return ZERO_SIZE_PTR; > + > + idx = bpf_mem_cache_idx(size + LLIST_NODE_SZ); > + if (idx < 0) > + return NULL; > + > + ret = unit_alloc(this_cpu_ptr(ma->caches)->cache + idx); > + return !ret ? NULL : ret + LLIST_NODE_SZ; > +} > + > +void notrace bpf_mem_free(struct bpf_mem_alloc *ma, void *ptr) > +{ > + int idx; > + > + if (!ptr) > + return; > + > + idx = bpf_mem_cache_idx(__ksize(ptr - LLIST_NODE_SZ)); > + if (idx < 0) > + return; > + > + unit_free(this_cpu_ptr(ma->caches)->cache + idx, ptr); > +} > + > +void notrace *bpf_mem_cache_alloc(struct bpf_mem_alloc *ma) > +{ > + void *ret; > + > + ret = unit_alloc(this_cpu_ptr(ma->cache)); > + return !ret ? NULL : ret + LLIST_NODE_SZ; > +} > + > +void notrace bpf_mem_cache_free(struct bpf_mem_alloc *ma, void *ptr) > +{ > + if (!ptr) > + return; > + > + unit_free(this_cpu_ptr(ma->cache), ptr); > +} Looks like smp_processor_id() needs to be made aware that preemption might be ok just not migration to a different CPU? [...] [ 593.639025] BUG: using smp_processor_id() in preemptible [00000000] code: kworker/u16:246/1946 [ 593.639026] BUG: using smp_processor_id() in preemptible [00000000] code: kworker/u16:83/1642 [ 593.639138] caller is bpf_mem_cache_free+0x14/0x40 [ 593.640971] caller is bpf_mem_cache_free+0x14/0x40 [ 593.641060] CPU: 6 PID: 1642 Comm: kworker/u16:83 Not tainted 5.19.0-gf0d7b67fb6f8 #1 [ 593.641874] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014 [ 593.641874] Workqueue: events_unbound bpf_map_free_deferred [ 593.641874] Call Trace: [ 593.641874] [ 593.641874] dump_stack_lvl+0x69/0x9b [ 593.641874] check_preemption_disabled+0x10b/0x120 [ 593.641874] bpf_mem_cache_free+0x14/0x40 [ 593.641874] htab_map_free+0x13f/0x2a0 [ 593.641874] process_one_work+0x28e/0x580 [ 593.641874] worker_thread+0x1fb/0x420 [ 593.641874] ? rcu_lock_release+0x20/0x20 [ 593.641874] kthread+0xf1/0x110 [ 593.641874] ? kthread_blkcg+0x40/0x40 [ 593.641874] ret_from_fork+0x22/0x30 [ 593.641874] [ 593.654117] CPU: 5 PID: 1946 Comm: kworker/u16:246 Not tainted 5.19.0-gf0d7b67fb6f8 #1 [ 593.654317] BUG: using smp_processor_id() in preemptible [00000000] code: kworker/u16:83/1642 [ 593.654560] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014 [ 593.654560] Workqueue: events_unbound bpf_map_free_deferred [ 593.654560] Call Trace: [ 593.654560] [ 593.654560] dump_stack_lvl+0x69/0x9b [ 593.658872] caller is bpf_mem_cache_free+0x14/0x40 [ 593.654560] check_preemption_disabled+0x10b/0x120 [ 593.654560] bpf_mem_cache_free+0x14/0x40 [ 593.654560] htab_map_free+0x13f/0x2a0 [ 593.654560] process_one_work+0x28e/0x580 [ 593.654560] worker_thread+0x1fb/0x420 [ 593.654560] ? rcu_lock_release+0x20/0x20 [ 593.654560] kthread+0xf1/0x110 [ 593.654560] ? kthread_blkcg+0x40/0x40 [ 593.654560] ret_from_fork+0x22/0x30 [ 593.654560] [...] [ 1158.399989] test_maps invoked oom-killer: gfp_mask=0x140cca(GFP_HIGHUSER_MOVABLE|__GFP_COMP), order=0, oom_score_adj=0 [ 1158.401948] CPU: 1 PID: 4147 Comm: test_maps Not tainted 5.19.0-gf0d7b67fb6f8 #1 [ 1158.402612] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014 [ 1158.402666] Call Trace: [ 1158.402666] [ 1158.402666] dump_stack_lvl+0x69/0x9b [ 1158.402666] dump_header+0x4d/0x370 [ 1158.402666] out_of_memory+0x5a2/0x5e0 [ 1158.402666] __alloc_pages_slowpath+0xbf4/0x1140 [ 1158.402666] __alloc_pages+0x222/0x2c0 [ 1158.402666] folio_alloc+0x14/0x40 [ 1158.402666] filemap_alloc_folio+0x43/0x150 [ 1158.402666] __filemap_get_folio+0x263/0x3a0 [ 1158.402666] filemap_fault+0x20f/0x540 [ 1158.410527] __do_fault+0x4a/0x100 [ 1158.410527] do_fault+0x13a/0x630 [ 1158.410527] handle_mm_fault+0x83d/0x13d0 [ 1158.410527] do_user_addr_fault+0x33c/0x4e0 [ 1158.410527] exc_page_fault+0x72/0x280 [ 1158.410527] asm_exc_page_fault+0x22/0x30 [ 1158.410527] RIP: 0033:0x7fa4d11a6ffc [ 1158.410527] Code: Unable to access opcode bytes at RIP 0x7fa4d11a6fd2. [ 1158.410527] RSP: 002b:00007ffd4fa8ac00 EFLAGS: 00000206 [ 1158.410527] RAX: 0000000000000240 RBX: 0000000000000075 RCX: 00007fa4d11d4610 [ 1158.410527] RDX: 0000000000000065 RSI: 00007fa4d11d42a0 RDI: 000055d328f91ac8 [ 1158.410527] RBP: 00007ffd4fa8ace0 R08: 00007fa4d1198aa0 R09: 0000000000000001 [ 1158.419624] R10: 00007ffd4fa8ace0 R11: 0000000000000246 R12: 000055d328f91ac8 [ 1158.420234] R13: 000055d328f9e4e0 R14: 0000000000000000 R15: 00007fa4d11d3000 [ 1158.420234] [...]