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 996C2C5475B for ; Mon, 11 Mar 2024 23:03:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F0AD86B010D; Mon, 11 Mar 2024 19:03:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EB9FD6B010F; Mon, 11 Mar 2024 19:03:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D82636B0111; Mon, 11 Mar 2024 19:03:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C695B6B010D for ; Mon, 11 Mar 2024 19:03:04 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9E399C086E for ; Mon, 11 Mar 2024 23:03:04 +0000 (UTC) X-FDA: 81886285488.21.6A59CC9 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) by imf06.hostedemail.com (Postfix) with ESMTP id DB10D180007 for ; Mon, 11 Mar 2024 23:03:02 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=OFzZYmMw; spf=pass (imf06.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.221.42 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710198183; 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=d4dmxu+SWq+3xSszaIAWWzfY8zg4uor+kSDuvUvAOFc=; b=erjvAfznFiqcbQU7mNOcmg4XVgYZopogkkDX04PNUNtbwzlouALMLjgjEOLV3V3Wu952Pt RYAXfEhJ04vXygNfQ6oNQL+68abbvFEz3UwZhrNOFIY4y9BPOc23Y+LvJxX1+XOU+yv9zw SApX/49ak5sfQFVChN6FW+MVOYylfYg= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=OFzZYmMw; spf=pass (imf06.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.221.42 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710198183; a=rsa-sha256; cv=none; b=fTtUWiJesyTvswruRRhGqAnToLQivbKhG4XNgOlDf78oN0qjsxjCERVSAzF94d2kXiAzjv BBI8Sc3DuueOXBHni+3UrGyve4f3A8HqgqFPFiHgCtfqzulg95ZIEZqn65huoZOo+pPXHs NSvCvTjc9ZjEzEybRcMsxEsOiihtCrk= Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-33e796cc90dso3223539f8f.1 for ; Mon, 11 Mar 2024 16:03:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710198181; x=1710802981; 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=d4dmxu+SWq+3xSszaIAWWzfY8zg4uor+kSDuvUvAOFc=; b=OFzZYmMwNeNsTmuSAQ2bmmlGFtNy9hfwRgRxigwSSp0X5FmCNEYQ/jAPtg7CU0vgpO iOXO5xk9q4tLy8hgO2rq/IRvYBTTZMAGQW4HmmaR5UYtKBQhuLDkAgRtNTzFbgdzkM3K ajSds39DrfOtthk9A9J2ef87aRvuDjzwo9mzNiGzugMWfyLBC3HJ/gcbEdtcOLVDdIGw FZFuUUkO9WpwBVXCj8MgJLiud22NtLLvvIGL4ad2/bJYqScQmWUAwHe3ltSOKXZpKHR2 nL4Ee+6KzPEUXzDMBP7LikILY9AvqnKi+XnKtLXeNjYY2VXHwjaakFeW3yF4Is5bsiix awUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710198181; x=1710802981; 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=d4dmxu+SWq+3xSszaIAWWzfY8zg4uor+kSDuvUvAOFc=; b=acx6aRqxEmXB7j2GOBoZpzgIM7MS3EqW2jSu+PyGEHLATSzbOLolEg9XG/IUo22Wh/ ndhsmBJnnbVk4xynKi8QgIKJH7pnw6rs8JzWFzGbNVtm40vZXFIJeSuP8pb1VEkg5hot M7TzeG4CG8F9d8c2k9uUseU4+HO1j27i+Q2PFirW+ZCbXfKf+lZalBDpkmRER+mcRC1a 5avnNIV6M26kR/74JvqtCC06es0BAt0yyMhrp6eNXV4KG2uahaMpBeInspXFMo1Rm9Tb D/6R6ANSzPIUicG3KNXQOFJCUd8VpLAbpG1r15/fMfYLboDAxiR/3CnPl0/TR1Wu1W+1 KDLw== X-Forwarded-Encrypted: i=1; AJvYcCXu119ncrdplmtkn2k/IMmIwpGxBaFl3hKAO6hnLYPXhXImNfrVpTqUgV3vBsqQ+TQysGgZY50pXwOn0OrL1YLP4qU= X-Gm-Message-State: AOJu0YysvsZ+Bdwqc5T/jXFaejqT5Jnf5XoOEJ0Cpw8QSgZSfgZqRa0C qLg7evWsbzQG3EGIiGQ8sZYwFB9iYESIcBVUMamgIXlZUw07RfsmTUu5jTqm0lvNcSmUqJpeQCt Z/b6HhDxiHbfCp6XPlYN2EUAbBK8= X-Google-Smtp-Source: AGHT+IGYAFrDAcr+GNhsy0h8ReBdmoFFgz4WJhzXeFB0Q4eVwczINZLvJ3xcKP1UeBaaO0mmYzIuMTqi02qiXF+w2u8= X-Received: by 2002:adf:ecc8:0:b0:33e:629d:38c2 with SMTP id s8-20020adfecc8000000b0033e629d38c2mr5929637wro.8.1710198181209; Mon, 11 Mar 2024 16:03:01 -0700 (PDT) MIME-Version: 1.0 References: <20240308010812.89848-1-alexei.starovoitov@gmail.com> In-Reply-To: From: Alexei Starovoitov Date: Mon, 11 Mar 2024 16:02:50 -0700 Message-ID: Subject: Re: [PATCH v3 bpf-next 00/14] bpf: Introduce BPF arena. To: Andrii Nakryiko Cc: bpf , Daniel Borkmann , Andrii Nakryiko , Linus Torvalds , Barret Rhoden , Johannes Weiner , Andrew Morton , Uladzislau Rezki , Christoph Hellwig , linux-mm , Kernel Team Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: DB10D180007 X-Rspam-User: X-Stat-Signature: 789mej5wtfqwxjghxehs5979jrhwdrrc X-Rspamd-Server: rspam01 X-HE-Tag: 1710198182-272083 X-HE-Meta: U2FsdGVkX1/7Tk7N3TLaKiKxprtRWnIVKP5vAWLMFwu0A6pnHDQSN2JqSp7LyzFQ2j88kmAZS9wMaGwVb+IRpTLGw2C2T2KbPh0t3f2SHWF+OEFfNFX8P3PmDtTZW0jbMbSxEY9HkVHwePmPtuMFlc3hgmTcxvSf7gsAxF74DJm2inrMAxwN4NmWL625I9mITPbVHM9ZAxhxN8Y81NFbkurg7Tf8c88xZv+s5637ew3LWWg+Ah2U35e2d31JKdUqEzdGiiE1cKemMqf0qN0J3oMvBIlH3A3pdSyzdXrnW+CX9+Z/7RD8jpR+iAT8hfZaaLgbbxwX7+jm1uaBDGZLesc5P7LdKaSfY0V6mIxkOG6CsdEUL3nsORq/Hxl4Dbr4gCYGZXy+7a1rug4cA0Vl6M7L+/aRXpvc0vNEbyStkT9n6WvuT9UE3soRRTFd8e+9GvUCVGFnHf3uy2t0BCXaliJRtpQxo1iff/grq8BGUdM6PBaRWuhtzwx8yQiIABPHl1/ZtHyfWZVsflxYQu2T44EZ3EGQPHaKlXGYOe0FwKF5IFg+uxW7OreKLpPlWNLzg8+H4cslKdQIKFyTE8dTYSErRCHuYaiMrDiVnYL+tzAro8S+DAqVs3FZFVcWmDgUQRyweVeGAwB1M71TFv6xFPH38lgksR22viKcjMFjKkP3ZcCxSZHjgqoZwLpzRf/oH9aWiEv5h/8Z7Zqr7rXSd+B3I1W6orcfZDM+7iilcZABg7WVv0EBsIl7pgcg/zishBIlUoB27T6nr07lpkR0pcP36r0wJVk4k+ip8JzRFHGS5OXP5Jen7q03Th2p7knRcoVGvD7ApEiJtie8eZ6WXsxA2VWT2p+uC5F4XHrdgEXYaUrvaS0icPXE27D8Bf58u8Kre7YTefD7jh3QsFc6GGNlEjbP22zFmGyFPz7irduc4cAx//hgTq7kaXva8dSmQAlO867RHQocpV4GJkx wQSOupQl Pg+A/rC1xDmPmYNI/kMPU9yc8m1GikpGhsKicxtSlckinclFjeQFUz7cln+/nsCEiMaBq7Lhdr+PXagIqrsCPjYA9XnNON2BtUbTs0mpn9JmKgFRKYdMGeyOzRS9JzYSUWorPdrUwqa31sIw= 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 Mon, Mar 11, 2024 at 3:45=E2=80=AFPM Andrii Nakryiko wrote: > > 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 on= e. > > - 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 aren= a. > > 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 faste= st > > 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. Thanks! That subj typo survived two months of reviews in v1,v2,v3 and I swear I use ./scripts/checkpatch.pl --codespell all the time. I guess it got drowned in all of the messages like: WARNING: 'mmaped' may be misspelled - perhaps 'mapped'? #356: FILE: tools/lib/bpf/libbpf.c:13666: + *mmaped =3D map->mmaped; ^^^^^^ WARNING: 'mmaped' may be misspelled - perhaps 'mapped'? #356: FILE: tools/lib/bpf/libbpf.c:13666: + *mmaped =3D map->mmaped; ^^^^^^ > 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). yes. It's on todo list already. I've added #define PAGE_SIZE 4096 to user space side of bpf selftest, because it's used in bpf_arena_*.h code which is dual compiled as bpf prog (and then it's using PAGE_SIZE from vmlinux.h) and compiled as native code. So bpf side gets correct PAGE_SIZE automatically as a nice constant at compile time, but for user space there is no good PAGE_SIZE constant to use. Just doing #define PAGE_SIZE sysconf(_SC_PAGE_SIZE) produces inefficient code. Hence I left it as a todo to figure out later.