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 957C1C4829A for ; Sat, 10 Feb 2024 04:35:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF3106B0075; Fri, 9 Feb 2024 23:35:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C7AC16B0078; Fri, 9 Feb 2024 23:35:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B1B276B007D; Fri, 9 Feb 2024 23:35:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 9B2E16B0075 for ; Fri, 9 Feb 2024 23:35:17 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C4234120444 for ; Sat, 10 Feb 2024 04:35:16 +0000 (UTC) X-FDA: 81774629832.09.7DB1373 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) by imf28.hostedemail.com (Postfix) with ESMTP id 06BD8C0010 for ; Sat, 10 Feb 2024 04:35:14 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=aT4Db2Zz; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf28.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.167.47 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707539715; 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=/EelMK3MNqQ7kc2Ty0nKSU3ZVwcIo6iAgFWKPjvAcvk=; b=2X5BM7/ZNZjglYCCFrjKFi44RVQaxO+3VxzMfUhzSReKyWgk+bFP8lw13yAS5txI/lYaVM XNbv7pbEI9HoeJn0Wg8bXBlvEeRQV1H+yEvlHV0/edF03we5Y2bfZerHWi40fgEn94uU0O iejCf1NVzBJzMGWbGYi0DEti8eLuvio= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=aT4Db2Zz; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf28.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.167.47 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707539715; a=rsa-sha256; cv=none; b=wgxBmDtJoWKsHMnAsoO9FWX0doXBhV4FGA1K/woMo7YXgWcNVDKeJMQe0L56T3+Pht0jNd K+kzALHexQ5bgpWvKujfK3QPpIbTfv/C4rYgmiDis3CIT3DZpKPZ9bnfP0Ma+KQEPzvjtY ZGgg/4/C7HJTVOC1hlndtCz7gPBg4Hs= Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-51165efb684so2793661e87.3 for ; Fri, 09 Feb 2024 20:35:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707539713; x=1708144513; 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=/EelMK3MNqQ7kc2Ty0nKSU3ZVwcIo6iAgFWKPjvAcvk=; b=aT4Db2ZzHBBwlQYhsvmiJ46KfYi4wt/UpZR7hDIYk8xBVu9f1AY1iey0LpuZQtR/x9 xJOxKM5y+lLL2yhJFJxlBHbEn9m+1/m8nYSYI3kCk26UMMrC0H1A+1U/NdrZ5Wn6R1cA 1Vf6JHfr/1x58gAPUwoNxzojRqsQDohn0ZzfLdO5zpkkToh8BDAc8IgEsgWAD1g8ojB+ ChXWeGTtt+ciekWGQlT3rZDypNluTaYU9eHuQaLIVzSfZhDGfhtxc/11uUtO01GUmHdm 2vOjzdWt9ocVwcqEm7SdKZJbUsTm49H+9AiGe6OMQg7i96BAMo+tU8Qpq4kXYm3cLz3Y owXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707539713; x=1708144513; 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=/EelMK3MNqQ7kc2Ty0nKSU3ZVwcIo6iAgFWKPjvAcvk=; b=L7wR5IzeT74Wgv0YxSjzHib2yI7FrNc/SMNDgfIMMe3IF1SIAFaUAIZZYj9zQwU9i3 zM8dGQm+aQzaiX6h6wHnB/Al+5SjZ63KhENNhUfYmq13WLQ1DB7ZcIBYeHJAFvJxw20P l3D3VgQeugC5U8U61+wB15ppbSN1VJi/l+l/JkpDOnXkOtYLOGJhX/KQVPayrZyY7RML mKe6QAv3Z6jrsX19dkFjwc3JZCXdQUchE43V/X63tceW1F+eL16mcsa9tbLXYbUkvq2H Ns0mZ8fqRC1CN1SLYTanIn/C/7bUCuygfvtGbq3anQu5j9wQ+qBLgaDOXY8Bt38hTxf4 aN2A== X-Gm-Message-State: AOJu0YxT1G3wMQoBOrbqgIzweRYxNj7FHDBfskW1zcHs0y6GvdVgzUkG FuEIxd/MclijtnF+7TgO4fSFfC1oPbgbye8QE2PdXdfkqGplGfhe78HpunzbpDKJCWRX0BW+eIf Lbgjky9vGXyo94LmW9vDv61Ya6Ws= X-Google-Smtp-Source: AGHT+IF+y/dAhddg2G9++QGcoCfVBM8iGq8fEgZ8U1iiAhwmWIH5JO54RAihATpQnmZtdbCjG/ShsWTjGvD3Lpsgwew= X-Received: by 2002:ac2:593a:0:b0:511:71fe:dc10 with SMTP id v26-20020ac2593a000000b0051171fedc10mr582654lfi.10.1707539712964; Fri, 09 Feb 2024 20:35:12 -0800 (PST) MIME-Version: 1.0 References: <20240209040608.98927-1-alexei.starovoitov@gmail.com> <20240209040608.98927-18-alexei.starovoitov@gmail.com> <20240209231433.GE975217@maniforge.lan> In-Reply-To: <20240209231433.GE975217@maniforge.lan> From: Alexei Starovoitov Date: Fri, 9 Feb 2024 20:35:01 -0800 Message-ID: Subject: Re: [PATCH v2 bpf-next 17/20] selftests/bpf: Add unit tests for bpf_arena_alloc/free_pages To: David Vernet Cc: bpf , Daniel Borkmann , Andrii Nakryiko , Kumar Kartikeya Dwivedi , Eddy Z , Tejun Heo , Barret Rhoden , Johannes Weiner , Lorenzo Stoakes , Andrew Morton , Uladzislau Rezki , Christoph Hellwig , linux-mm , Kernel Team Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Stat-Signature: xcyqttn8cifgmxn8e4bzwdeuzzqw3hjw X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 06BD8C0010 X-HE-Tag: 1707539714-289580 X-HE-Meta: U2FsdGVkX19GiX0dQPDnYuU0pDPBILkgBPZU0VnPJDekFBqM5vMLPvo6NQYt2X/Np4FAaInyao+YJXwEq7iNl0Y2yDx/mnEYFVqhQrl3Rq1qucG73p38u0hYs/FSaVaxLBs2xIHKQO2QrQNMMI0Kgl+pn2kdQHpxQwpyttmgA5ez9WcoLp48iUX2z6qRdh8pvp2HmLcacRR+XBLabPQu0I4PkTPr7eX4oKlzLerxs661LYJ4UXjkCpJxVcNIuYE3MyHeIVB2asu9xsZuRBQptXvGQnrzR9qjxBHa5rS0MTtz/EqJXtqUBDM0hoLn9hIT5dwvCXuhOF0F6rslIDZRPaQOc9nRJLPFqmVoQIejsxHuOMbMe591JjnbzdfohXWM3XUH65+QQCwl7UFpVBVoL1j0rIJVjtnICez8nA5/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ter, spamicity=0.000001, 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 Fri, Feb 9, 2024 at 3:14=E2=80=AFPM David Vernet wr= ote: > > > + > > +#ifndef arena_container_of > > Why is this ifndef required if we have a pragma once above? Just a habit to check for a macro before defining it. > Obviously it's way better for us to actually have arenas in the interim > so this is fine for now, but UAF bugs could potentially be pretty > painful until we get proper exception unwinding support. Detection that arena access faulted doesn't have to come after exception unwinding. Exceptions vs cancellable progs are also different. A record of the line in bpf prog that caused the first fault is probably good enough for prog debugging. > Otherwise, in terms of usability, this looks really good. The only thing > to bear in mind is that I don't think we can fully get away from kptrs > that will have some duplicated logic compared to what we can enable in > an arena. For example, we will have to retain at least some of the > struct cpumask * kptrs for e.g. copying a struct task_struct's struct > cpumask *cpus_ptr field. I think that's a bit orthogonal. task->cpus_ptr is a trusted_ptr_to_btf_id access that can be mixed within a program with arena access. > For now, we could iterate over the cpumask and manually set the bits, so > maybe even just supporting bpf_cpumask_test_cpu() would be enough > (though donig a bitmap_copy() would be better of course)? This is > probably fine for most use cases as we'd likely only be doing struct > cpumask * -> arena copies on slowpaths. But is there any kind of more > generalized integration we want to have between arenas and kptrs? Not > sure, can't think of any off the top of my head. Hopefully we'll be able to invent a way to store kptr-s inside the arena, but from a cpumask perspective bpf_cpumask_test_cpu() can be made polymorphic to work with arena ptrs and kptrs. Same with bpf_cpumask_and(). Mixed arguments can be allowed. Args can be either kptr or ptr_to_arena. I still believe that we can deprecate 'struct bpf_cpumask'. The cpumask_t will stay, of course, but we won't need to bpf_obj_new(bpf_cpumask) and carefully track refcnt. The arena can do the same much faster. > > > + return 7; > > + page3 =3D bpf_arena_alloc_pages(&arena, NULL, 1, NUMA_NO_NODE, 0)= ; > > + if (!page3) > > + return 8; > > + *page3 =3D 3; > > + if (page2 !=3D page3) > > + return 9; > > + if (*page1 !=3D 1) > > + return 10; > > Should we also test doing a store after an arena has been freed? You mean the whole bpf arena map was freed ? I don't see how the verifier would allow that. If you meant a few pages were freed from the arena then such a test is already in the patches.