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 A2C13C48260 for ; Wed, 14 Feb 2024 01:24:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1CA6F6B0085; Tue, 13 Feb 2024 20:24:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 153B36B00A4; Tue, 13 Feb 2024 20:24:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F0E5F6B00A5; Tue, 13 Feb 2024 20:24:48 -0500 (EST) 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 DE9126B0085 for ; Tue, 13 Feb 2024 20:24:48 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B2D9414089C for ; Wed, 14 Feb 2024 01:24:48 +0000 (UTC) X-FDA: 81788665056.30.44F96FC Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) by imf17.hostedemail.com (Postfix) with ESMTP id D19684000F for ; Wed, 14 Feb 2024 01:24:46 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=A2UGkknA; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.221.54 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707873886; a=rsa-sha256; cv=none; b=L8gMxTKvdefINdteK8oAf5UaWH5/8DjRZOlwlLJ/YxzyBKtWvzlmiiqs6YfYJsc6VpJFB+ 2htrwqEZvS21v8yEqGygMWJCaBzkpUsK1uSSZOWWPVuSl5Ub6bjvUd1zSgDc7JyinW2fqI 0+kcXP5xwvUuUTKiPWH6XD3ty968RFI= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=A2UGkknA; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.221.54 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=1707873886; 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=MAN6wJN8t3Wj9pNbdOPZpab49RIQxLUbM2po1RJfgNg=; b=vZCtSh1odrMxNXJ7kd7kPOzUqgtL4lbVQPVmM2SLA2mqVE6MnH/+GkSgkIoKYShBVO423e D+Hitissln0N1aAxdemg/hMl0pimv1rcwTgK1sm9+SB01lc5ygXkG5PYeNWr97K/wNm66V FLvjLaYeatcJZbVwhO4yooqmujH5FBE= Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-33cd57b7eabso754610f8f.2 for ; Tue, 13 Feb 2024 17:24:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707873885; x=1708478685; 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=MAN6wJN8t3Wj9pNbdOPZpab49RIQxLUbM2po1RJfgNg=; b=A2UGkknA82zT4BhvPd+nxnszk/l2MUNsXca4vCIFXs+3ipCPc83lZgOIC5naM9UeJp EzI3VV6NNQD6jDwobOpr2S60MB9HQkhm41HusnLUAab/az3Pql5TZCRRHLsQMbtckx30 11w0UxsJjGe5Lw/k2y0/X09CQsbPyoRbGmxHO9Eecx24uMr4Eo0MHL6pT11cXoToe1Ro tefp8Qlwqkd7pehv5qgB2tW/KXECvExrp1l9lgEdQsSgx2F7nARI3t/nGLf7AOl80xcm u3Rr+IoXw9Zpk57cakmxaz72AfNJhoIFfkIKLtb9SLwiRez3GHwRBiyGKTaNPaW9aWOD WEUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707873885; x=1708478685; 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=MAN6wJN8t3Wj9pNbdOPZpab49RIQxLUbM2po1RJfgNg=; b=KJYucqp6KmbOR644c5/H0siIiIVS/DNdOyqmwvWoMwFGRlMn1LtbK53dcYvb9HW5wS y26jvrbEmwYL/moYcIkbYRhUUMmy4Kl4ZAGVee+5GkMgmOMFQr3XlWsqwuy4Lbbtx9yk 3gQbCnS6FByUuZEUCeWDbcBX3wAilNbK7PdgwthcwSF0Ko9QrIAdDk356kVBE/Ul8XrB xZeTkk6oIaiEhGqctyi/fG9TOA52fwO+9NxU7C+rUPy3CJ0/tDhiCqIMzEmyF6mFLpD+ x0g4nQZNrOjDkxIQpFk2vPTQMbvt2HPaogQhuQ0l0O4Wx3jjnDMZ1HObjo3areiWT4zw mYYw== X-Forwarded-Encrypted: i=1; AJvYcCUp8Xnp264tmcXEL+hiRwoiMlV+W5AA9+ThazAr75J6m8sPLQgEoRtyG50As+wndeL6lwhl/mHpyryeWKPj/ujaq+I= X-Gm-Message-State: AOJu0YwoFXBAsSJDCRT8Vi6gJvSZa8xCt5dbmQr0KAdlKAMPL4nfK2uh VibH9aCrkCEGQkms7nqd9slZ/mj/N19CqPz/w8dOZ0ZUQqFq2lnYhsdiNu/wRUzQ92zFKWWZSb8 TQeaVT/DDOHiN21eQegT3jbCIEEI= X-Google-Smtp-Source: AGHT+IFP7jE013omUuIgoWyBfFFWhzTkKFhQzL7TUr3fOux83eVKQoDaYji9CCkwZ74pHixiVhVfjLLxON6raCpg6go= X-Received: by 2002:a5d:5912:0:b0:33b:15fc:22bc with SMTP id v18-20020a5d5912000000b0033b15fc22bcmr645921wrd.52.1707873885278; Tue, 13 Feb 2024 17:24:45 -0800 (PST) MIME-Version: 1.0 References: <20240209040608.98927-1-alexei.starovoitov@gmail.com> <20240209040608.98927-15-alexei.starovoitov@gmail.com> <7af0d2e0cc168eb8f57be0fe185d7fa9caf87824.camel@gmail.com> In-Reply-To: From: Alexei Starovoitov Date: Tue, 13 Feb 2024 17:24:33 -0800 Message-ID: Subject: Re: [PATCH v2 bpf-next 14/20] libbpf: Recognize __arena global varaibles. To: Andrii Nakryiko Cc: Eduard Zingerman , bpf , Daniel Borkmann , Andrii Nakryiko , Kumar Kartikeya Dwivedi , 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-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: D19684000F X-Stat-Signature: 1b95ybksmr81sfzredn6985jnjq14phy X-HE-Tag: 1707873886-256571 X-HE-Meta: U2FsdGVkX18xHFipg+SVhqoXO0pAU0xtTfvJ/NYGUFXwhQqrt7VOQ620ome+vHMSB6O/ExJPlwbLDE+KspImt792P4Ns/jOIk74cjS6qR70/Ea5G5QdPEvweA4s8dXI+0aqRtj0qm56rnFu2tNDeNcmtoR3LDSZIwOsO7SqEfJcQZvUUSTWEkqKdS3amzDmbDpDfbVJ94KsY2N/+5eewFGhPruQ9cKz4rJKXu0brFY/h0pRzUyFOdMiI/5QyiTYPJMJ45io6EOky4IxpDi95rV252+8IEGHVlPrTEDiY4fjXLcMORvIMxX3RBXULKiHX/v+UDOIo4sUjkF+tlnh/yX5pB7fztpEec54n8mQNDz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J2Koq5lH/oecooTGhKmLH0fFT7s4wMrRqK7N/orcNLCtS/cfDrldAA/+F8vF2OhBM7OqNuWyDBTrxqAEeXUPEjLh1ekv9lA/pGkn7xaoMrs9J0eH5ATk8Eta7xiZRcIDuZNNg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000197, 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 Tue, Feb 13, 2024 at 4:09=E2=80=AFPM Andrii Nakryiko wrote: > > On Tue, Feb 13, 2024 at 3:37=E2=80=AFPM Eduard Zingerman wrote: > > > > On Tue, 2024-02-13 at 15:17 -0800, Andrii Nakryiko wrote: > > > > [...] > > > > > > So, at first I thought that having two maps is a bit of a hack. > > > > > > yep, that was my instinct as well > > > > > > > However, after trying to make it work with only one map I don't rea= lly > > > > like that either :) > > > > > > Can you elaborate? see my reply to Alexei, I wonder how did you think > > > about doing this? > > > > Relocations in the ELF file are against a new section: ".arena.1". > > This works nicely with logic in bpf_program__record_reloc(). > > If single map is used, we effectively need to track two indexes for > > the map section: > > - one used for relocations against map variables themselves > > (named "generic map reference relocation" in the function code); > > - one used for relocations against ".arena.1" > > (named "global data map relocation" in the function code). > > > > This spooked me off: > > - either bpf_object__init_internal_map() would have a specialized > > branch for arenas, as with current approach; > > - or bpf_program__record_reloc() would have a specialized branch for ar= enas, > > as with one map approach. > > Yes, relocations would know about .arena.1, but it's a pretty simple > check in a few places. We basically have arena *definition* sec_idx > (corresponding to SEC(".maps")) and arena *data* sec_idx. The latter > is what is recorded for global variables in .arena.1. We can remember > this arena data sec_idx in struct bpf_object once during ELF > processing, and then just special case it internally in a few places. That was my first attempt and bpf_program__record_reloc() became a mess. Currently it does relo search either in internal maps or in obj->efile.btf_maps_shndx. Doing double search wasn't nice. And further, such dual meaning of 'struct bpf_map' object messes assumptions of bpf_object__shndx_is_maps, bpf_object__shndx_is_data and the way libbpf treats map->libbpf_type everywhere. bpf_map__is_internal() cannot really say true or false for such dual use map. Then skeleton gen gets ugly. Needs more public libbpf APIs to use in bpftool gen. Just a mess. > The "fake" bpf_map for __arena_internal is user-visible and requires > autocreate=3Dfalse tricks, etc. I feel like it's a worse tradeoff from a > user API perspective than a few extra ARENA-specific internal checks > (which we already have a few anyways, ARENA is not completely > transparent internally anyways). what do you mean 'user visible'? I can add a filter to avoid generating a pointer for it in a skeleton. Then it won't be any more visible than other bss/data fake maps. The 2nd fake arena returns true out of bpf_map__is_internal. The key comment in the patch: /* bpf_object will contain two arena maps: * LIBBPF_MAP_ARENA & BPF_MAP_TYPE_ARENA * and * LIBBPF_MAP_UNSPEC & BPF_MAP_TYPE_ARENA. * The former map->arena will point to latter. */