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 3FD3AC54E58 for ; Mon, 11 Mar 2024 22:45:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D07F16B0148; Mon, 11 Mar 2024 18:45:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CB7866B0149; Mon, 11 Mar 2024 18:45:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B7F356B014A; Mon, 11 Mar 2024 18:45:25 -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 A98796B0148 for ; Mon, 11 Mar 2024 18:45:25 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 87A921C0F2E for ; Mon, 11 Mar 2024 22:45:25 +0000 (UTC) X-FDA: 81886241010.13.A1E7482 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by imf16.hostedemail.com (Postfix) with ESMTP id D3F69180002 for ; Mon, 11 Mar 2024 22:45:23 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=S+WPBPM0; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf16.hostedemail.com: domain of andrii.nakryiko@gmail.com designates 209.85.216.46 as permitted sender) smtp.mailfrom=andrii.nakryiko@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710197123; 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=8NaRF1UcYNKuVhmQKcLCX1HToQxH2gsLpAwn60nGP6Y=; b=31HEz9LyJZMzBsHGXQsE7bnnEqwoyv0xfKp1A0NPrlY4E2OZbSqH8hoDBUaPxUIGwYmiOv XYveakZSTRaRNT3smY/yi6QolwGIKp8AHELHiP12Oei6BuKNT4KKAUTzRCRsWm4q4sGMI/ JH/lmw4QPqDJP/lX4y79Q+83CMojok8= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=S+WPBPM0; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf16.hostedemail.com: domain of andrii.nakryiko@gmail.com designates 209.85.216.46 as permitted sender) smtp.mailfrom=andrii.nakryiko@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710197123; a=rsa-sha256; cv=none; b=UvJVtliTdVkQZJMlPgpX5nv3FYYsPQbcgPpa7f+Ck1bXRx0DUKcHLs9UPIi8fLht/Ll1aS Gr69olOtEaPQ3Uo1JPn8IEhexpO0TXctCk/DmM2J5Q4iUgxhVHCgDhb+xrkAPbrKCUzwJA cYORnM/UzZ/j9rC04eG4dgJgK0ex6RI= Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-29b7164eef6so2798714a91.2 for ; Mon, 11 Mar 2024 15:45:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710197123; x=1710801923; 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=8NaRF1UcYNKuVhmQKcLCX1HToQxH2gsLpAwn60nGP6Y=; b=S+WPBPM0+wNn/4ep72dIOyFS6SdLtmRoPwVWPoKLzDEQckrzqtmFM5s3bimrSMVFr6 DleWWEkiB8cT9wP3EVqyaaPQrLyrEtNn54bxXb5zTP5HDe0biB+FBDBgydfEPh/TBZ8N g0WsnhnPwl7Vvv0Y2GUy0V/DZzPllHrhaiyAVs5aX8dK5a+aXJcXR9fJ5ikHEImdAnQB bHtTihugMr2Wr7bSCc6FUAbZiXVLeaLhhuViSd1n578FX9PVJtbKNdYyfwmwrw2bSk0F IFRc88aHOpHOvxOOKMhvctKWF4lahVfm8oqapBcxU5Z71xDlbnVvAWXYu2OMvqkhb1o0 UMVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710197123; x=1710801923; 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=8NaRF1UcYNKuVhmQKcLCX1HToQxH2gsLpAwn60nGP6Y=; b=tW2BqIZ6YhZHgp/4MOrvnaSP93qhjpbax3jeDmpcYwNdqQi+jxXBJWVWSFuzTRgP2a NM1sXb4L7I2J9JkORbXcg2jSwJQAf1cmdrEsdyVn0hAIEKMYqSFNqk0KFe+5rVFLGZHd Tb4KaagfFXsP+hg1D4g152S1tYhznNrN1t9jSuxaxUXQsYKaPhHyWDS+2+v28MkPBvvV Fu0pagWFmJaW8xeI60+o+WwtVUSb+VSwNznzIMnQAxuxm6wb+1XejFAJEXL9HjfhgJUU SBUulaoyk/FUTH5tL3rEYRaXH7vcB203VQXpHykAuayENHIqOZVp54UzBgeByImlik0n kg0Q== X-Forwarded-Encrypted: i=1; AJvYcCXcm99QAfSWLqJJwjeRWOnqDB9aQEOkEBaZg/srvM7iKcTjm3BFy1y0g5N1f9VT+K1n/XsuuH1fW7FE6RRn8+fEHfQ= X-Gm-Message-State: AOJu0YyX1S3um8s0Yafr4Hghy9PJcuoDNntzBHk45Q2eBZuCam8kQbB8 fkvBKLr25h3WY2Va4h5BnNGDkY01fjNn11ik0CKdKNQ3dkdHcMAoHS3gsR9+eXAPAqxyar2jshP 6Mwdd/xOz8mm0nO7gBSqIWVnwwAk= X-Google-Smtp-Source: AGHT+IE0pigo0eTF3sH/ZoUUgemSf4u92krF+Owg5ehe/czZnB7utxH+KS4cwh228NwrYjDluyxxN+6cVqpDgfZpNkM= X-Received: by 2002:a17:90a:d249:b0:29b:c3a5:1909 with SMTP id o9-20020a17090ad24900b0029bc3a51909mr6174769pjw.7.1710197122625; Mon, 11 Mar 2024 15:45:22 -0700 (PDT) MIME-Version: 1.0 References: <20240308010812.89848-1-alexei.starovoitov@gmail.com> In-Reply-To: <20240308010812.89848-1-alexei.starovoitov@gmail.com> From: Andrii Nakryiko Date: Mon, 11 Mar 2024 15:45:10 -0700 Message-ID: Subject: Re: [PATCH v3 bpf-next 00/14] bpf: Introduce BPF arena. To: Alexei Starovoitov Cc: bpf@vger.kernel.org, daniel@iogearbox.net, andrii@kernel.org, torvalds@linux-foundation.org, brho@google.com, hannes@cmpxchg.org, akpm@linux-foundation.org, urezki@gmail.com, hch@infradead.org, linux-mm@kvack.org, kernel-team@fb.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: D3F69180002 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: unm9irw9c789cqco8ro6u9khri8oegfn X-HE-Tag: 1710197123-1865 X-HE-Meta: U2FsdGVkX1/YI6AyzgCbsIcHUPxKwRQdkTtMIlcfdec1oU0LIQIUTtdaCOcVAEelLgnkK/QpCeyi3ow60mPtzS8ULvcQZA7t/3OA4XqxSUoDz0qGnJy8HybwbP+PS1trgrWsLi3Y4UkAigo6PP1D1uIaDC9NC/dhkZ/nSshCrlXM+GEqdB/VmckqybF4yZT4ovAnm9Gjqwk4skfH3JF+s8pVIAV63slWoQUtmkE2PIt2TpLs7hhCGLFglTWCXga9RrrI6RjRCBTlJDw9WhCLZJYZ5+kEECExC0kgX9+fEterD64ADRT5r9zZQ30vKTRS+EQ3Lv+QY6FbyYClSrtIV2GOVBx5PNkhB4vH5Gon3Lum7A0PmJQyIVUkBVJcfvBmAKeAkfbDpr4dqE5Y+DQEHzOwhESPM2myyQVb1buHQfn2GcWuGMtaBg+9I/e45zAbjldSHFjuyobQF/veILApjVn+8ygxmW+fG0+nrU3sGXTxcdnhOazx2W3CxsL2AkgbijLVxLxHa+4MQJ5lCr6HM0GU56lp1u954tYmSDh4vdkzDIOZWJI1Bypfg1nXafpeFu9OFEDJOok1Rd90MeVXNVK+/CB4yAbtY/WWHOotDL8Ot/vd+RaGx2XF0/e/14VqtQCfiiowcdLgKBF4hazQA+N638uK6lXuK1cDCgP4+OU4du8KdQC50IZrz9aYHth8NFfbuQDcVRxt2Or1ozT2dkE69bNnaSv+D9adOqUq1C1cnB5FlS4Rtj+8ub7b0dBSZH1U4KhwwHaG7+jwr6VbHUr7Ws6tWGimwfQAocCMaLqvw45T8c66cChTvN1WN8cGMypwcWjPd11pjVuAbyIvG8Zl5052gSySqG1b7P59q9uUEDiqAtMNPuJhqtOXQSsMijVDYF6HxxvHTZm22lX2yzaIUtFurgSeasaVmoYYiUH0MrgS8zvI0xH/P1ZsBdITdCyLOg2xIxsJz4EGTZa 9jAV7jwS NbZ/BQ7Jv4WR9feFARolvW6dHvpxGI6en4IqALP4Km+YdTtX9MmhR51ZvpX6+uXCQ5PopNTmF2NOJa2POVgo0Kt3Q5WJUaAjrc4JGuFISMuMyoMaZrlFg0FMy4cok37mCM0ZYajw8uvPgIUE= 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 Thu, Mar 7, 2024 at 5:08=E2=80=AFPM Alexei Starovoitov wrote: > > From: Alexei Starovoitov > > v2->v3: > - contains bpf bits only, but cc-ing past audience for continuity > - since prerequisite patches landed, this series focus on the main > functionality of bpf_arena. > - adopted Andrii's approach to support arena in libbpf. > - simplified LLVM support. Instead of two instructions it's now only one. > - switched to cond_break (instead of open coded iters) in selftests > - implemented several follow-ups that will be sent after this set > . remember first IP and bpf insn that faulted in arena. > report to user space via bpftool > . copy paste and tweak glob_match() aka mini-regex as a selftests/bpf > - see patch 1 for detailed description of bpf_arena > > v1->v2: > - Improved commit log with reasons for using vmap_pages_range() in arena. > Thanks to Johannes > - Added support for __arena global variables in bpf programs > - Fixed race conditions spotted by Barret > - Fixed wrap32 issue spotted by Barret > - Fixed bpf_map_mmap_sz() the way Andrii suggested > > The work on bpf_arena was inspired by Barret's work: > https://github.com/google/ghost-userspace/blob/main/lib/queue.bpf.h > that implements queues, lists and AVL trees completely as bpf programs > using giant bpf array map and integer indices instead of pointers. > bpf_arena is a sparse array that allows to use normal C pointers to > build such data structures. Last few patches implement page_frag > allocator, link list and hash table as bpf programs. > > v1: > bpf programs have multiple options to communicate with user space: > - Various ring buffers (perf, ftrace, bpf): The data is streamed > unidirectionally from bpf to user space. > - Hash map: The bpf program populates elements, and user space consumes > them via bpf syscall. > - mmap()-ed array map: Libbpf creates an array map that is directly > accessed by the bpf program and mmap-ed to user space. It's the fastest > way. Its disadvantage is that memory for the whole array is reserved at > the start. > > Alexei Starovoitov (13): > bpf: Introduce bpf_arena. > bpf: Disasm support for addr_space_cast instruction. > bpf: Add x86-64 JIT support for PROBE_MEM32 pseudo instructions. > bpf: Add x86-64 JIT support for bpf_addr_space_cast instruction. > bpf: Recognize addr_space_cast instruction in the verifier. > bpf: Recognize btf_decl_tag("arg:arena") as PTR_TO_ARENA. > libbpf: Add __arg_arena to bpf_helpers.h > libbpf: Add support for bpf_arena. > bpftool: Recognize arena map type > bpf: Add helper macro bpf_addr_space_cast() > selftests/bpf: Add unit tests for bpf_arena_alloc/free_pages > selftests/bpf: Add bpf_arena_list test. > selftests/bpf: Add bpf_arena_htab test. > > Andrii Nakryiko (1): > libbpf: Recognize __arena global varaibles. > > arch/x86/net/bpf_jit_comp.c | 231 +++++++- > include/linux/bpf.h | 10 +- > include/linux/bpf_types.h | 1 + > include/linux/bpf_verifier.h | 1 + > include/linux/filter.h | 4 + > include/uapi/linux/bpf.h | 14 + > kernel/bpf/Makefile | 3 + > kernel/bpf/arena.c | 558 ++++++++++++++++++ > kernel/bpf/btf.c | 19 +- > kernel/bpf/core.c | 16 + > kernel/bpf/disasm.c | 10 + > kernel/bpf/log.c | 3 + > kernel/bpf/syscall.c | 42 ++ > kernel/bpf/verifier.c | 123 +++- > .../bpf/bpftool/Documentation/bpftool-map.rst | 2 +- > tools/bpf/bpftool/gen.c | 13 + > tools/bpf/bpftool/map.c | 2 +- > tools/include/uapi/linux/bpf.h | 14 + > tools/lib/bpf/bpf_helpers.h | 1 + > tools/lib/bpf/libbpf.c | 163 ++++- > tools/lib/bpf/libbpf.h | 2 +- > tools/lib/bpf/libbpf_probes.c | 7 + > tools/testing/selftests/bpf/DENYLIST.aarch64 | 2 + > tools/testing/selftests/bpf/DENYLIST.s390x | 2 + > tools/testing/selftests/bpf/bpf_arena_alloc.h | 67 +++ > .../testing/selftests/bpf/bpf_arena_common.h | 70 +++ > tools/testing/selftests/bpf/bpf_arena_htab.h | 100 ++++ > tools/testing/selftests/bpf/bpf_arena_list.h | 92 +++ > .../testing/selftests/bpf/bpf_experimental.h | 43 ++ > .../selftests/bpf/prog_tests/arena_htab.c | 88 +++ > .../selftests/bpf/prog_tests/arena_list.c | 68 +++ > .../selftests/bpf/prog_tests/verifier.c | 2 + > .../testing/selftests/bpf/progs/arena_htab.c | 48 ++ > .../selftests/bpf/progs/arena_htab_asm.c | 5 + > .../testing/selftests/bpf/progs/arena_list.c | 87 +++ > .../selftests/bpf/progs/verifier_arena.c | 146 +++++ > tools/testing/selftests/bpf/test_loader.c | 9 +- > 37 files changed, 2028 insertions(+), 40 deletions(-) > create mode 100644 kernel/bpf/arena.c > create mode 100644 tools/testing/selftests/bpf/bpf_arena_alloc.h > create mode 100644 tools/testing/selftests/bpf/bpf_arena_common.h > create mode 100644 tools/testing/selftests/bpf/bpf_arena_htab.h > create mode 100644 tools/testing/selftests/bpf/bpf_arena_list.h > create mode 100644 tools/testing/selftests/bpf/prog_tests/arena_htab.c > create mode 100644 tools/testing/selftests/bpf/prog_tests/arena_list.c > create mode 100644 tools/testing/selftests/bpf/progs/arena_htab.c > create mode 100644 tools/testing/selftests/bpf/progs/arena_htab_asm.c > create mode 100644 tools/testing/selftests/bpf/progs/arena_list.c > create mode 100644 tools/testing/selftests/bpf/progs/verifier_arena.c > > -- > 2.43.0 > Besides a few comments on patch #1 (and maybe one or two potential corner case issues I mentioned, which can be easily fixed), the series looked good. So I've applied patches as is. I fixed typo ("varaibles") in one of the commit subjects while applying. Also, in one of the selftests you hard-coded PAGE_SIZE to 4096, which isn't correct on some architectures, so please see how you can make it not hard-coded (but still work for both bpf and user code). It seemed minor enough to not delay patches (either way those architectures don't support ARENA just yet).