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 0F670ECAAD4 for ; Mon, 29 Aug 2022 21:45:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 61DE76B0073; Mon, 29 Aug 2022 17:45:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5CD0D6B0074; Mon, 29 Aug 2022 17:45:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 46D39940007; Mon, 29 Aug 2022 17:45:28 -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 2FB4F6B0073 for ; Mon, 29 Aug 2022 17:45:28 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2AC051A0B34 for ; Mon, 29 Aug 2022 21:45:27 +0000 (UTC) X-FDA: 79853961894.06.F06EB04 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) by imf22.hostedemail.com (Postfix) with ESMTP id A4FF3C004E for ; Mon, 29 Aug 2022 21:45:26 +0000 (UTC) Received: by mail-ed1-f53.google.com with SMTP id u6so11788477eda.12 for ; Mon, 29 Aug 2022 14:45:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=sTw+/z7x03je7/hIMvP8+HPPhki5YAz4a5KqEHAejI0=; b=MCjxUJlazQF3n57DDygoL969ALwymntJYUumQoMMHF8SAJVx/AZS3qfuvFgZ39C61x VuMtxaedr886o3IrTekm8ko/cvwCu79DM16oQmkmuwu28G0LojltBclQvpaIGOeLbvB8 5arHjv5kCJYugx4E6JD4YpmHI0MxqnrrOZwGKpYCPnt3NkNN6kYx+cvbkmJbK9oq8+le RHQuR1Gc24vr4+0sA6B1oJS3WHjmzIYptW2f3fCeFo6WueUPKKSOk1yUaHMPIcv/4Ec+ LznJqg6f2Q7xc6+4BpF6QQbOIMK2d9Ko+UFW/8LPQTLMPNz/SveNyeZlQK1mptKAkR8V 2NIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=sTw+/z7x03je7/hIMvP8+HPPhki5YAz4a5KqEHAejI0=; b=eTRCUC1z06eYjktQFKDZzo1BeFP22U1kx7zPLwnbZE70URVHmxyF5I/TBaVr6fxlhM QAJuu3JWSzamCyP0e80N3IyTu0yFxNdp1AC8xHKJpq8zhXavInXDnv3R32pwxXQ4Kc7l CodVNEe4M/yuWPXkfQT9H+HvlAP48GcWFqnikBkjqqZ2w4Oth9dkK4pxKsQC44PqCk2z Jxdyh2rln0YFjNPqWHKA00/llnaZC4Cz0Hlp23xI2j6LR1cRwjGDyUa34M1ouw64VOz0 9slwjupGAMvFzLg12a/kGSSCfMIHRw8oQzvMHP05HJmMU0MswYsxXC8A1dGTkfgYWocH jWBA== X-Gm-Message-State: ACgBeo2LLf01BaApq3H0LrvTgDXUTFwEUo5Ro72IHD9njW/Vlb53wH4e ggGHaitzfMZgeTq5iMHjUP5i6vnNZaEsYaBa2k52VV9E9I0= X-Google-Smtp-Source: AA6agR4iT/8MDNTPI7OIBNJTRlyFMl9mm1PWCshoa168F9VZ2enZ8xhe4feW+V2fcw4i8eixNFHHHJivHE/qYcKkLcs= X-Received: by 2002:a05:6402:270d:b0:43a:67b9:6eea with SMTP id y13-20020a056402270d00b0043a67b96eeamr17914142edd.94.1661809525449; Mon, 29 Aug 2022 14:45:25 -0700 (PDT) MIME-Version: 1.0 References: <20220826024430.84565-1-alexei.starovoitov@gmail.com> <20220826024430.84565-2-alexei.starovoitov@gmail.com> <74acd56b-21bb-8ea8-092f-d1b4fcfc0790@iogearbox.net> In-Reply-To: <74acd56b-21bb-8ea8-092f-d1b4fcfc0790@iogearbox.net> From: Alexei Starovoitov Date: Mon, 29 Aug 2022 14:45:14 -0700 Message-ID: Subject: Re: [PATCH v4 bpf-next 01/15] bpf: Introduce any context BPF specific memory allocator. To: Daniel Borkmann Cc: "David S. Miller" , Andrii Nakryiko , Tejun Heo , Kumar Kartikeya Dwivedi , Delyan Kratunov , linux-mm , bpf , Kernel Team Content-Type: text/plain; charset="UTF-8" ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=MCjxUJla; spf=pass (imf22.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.208.53 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=1661809526; 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=sTw+/z7x03je7/hIMvP8+HPPhki5YAz4a5KqEHAejI0=; b=NKvEHNnLhq2PfJA5M6Z5aJnlToaauRhJgXmYOhulgW69RI8ez0Gy/h2i/4cF4WL2l9B2X8 P6hldKCVXFCjzBAHEaCNl2NTeMvK3SX9T6s2mVFeUSx4jLvkJahvrNYfZoxJd8gV2oSCZk 6Ht+QOw9jPwVQnyvq7Tc72jUNDLdgK4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661809526; a=rsa-sha256; cv=none; b=dES5IxY/JhdWerqwEEMjL+4m99AK5f9E9epgPsq+A3wC4+vchn6Hqmj/TRkyHJlc5CfAkt bWe8kF09TOV6iLbR8IAm1HN777c+SuAk1KUcbquLKrlMa1MkcCXaDa1RAMtzVqTBsDLlYr foS6t2oPJwMW9WQn6EcKZ/klzoNKcgM= X-Stat-Signature: 9xpdnsnm5xuz45wn9ouafrad4rit4yp9 X-Rspamd-Queue-Id: A4FF3C004E Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=MCjxUJla; spf=pass (imf22.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.208.53 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1661809526-279528 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, Aug 29, 2022 at 2:30 PM Daniel Borkmann wrote: > > 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? ahh. migration is not disabled when map is freed from worker. this_cpu_ptr above and local_irq_save shortly after need to happen on the same cpu, so I'm thinking to add migrate_disable to htab free path.