Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7321755rdb; Wed, 3 Jan 2024 11:42:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IHVg9lgAs+gvLuYlCa+WbelrpA4zDk9fJXlC8ZRn3s6rS+cnyp/9sKi4SHB2LkUN3ZmvGy6 X-Received: by 2002:a17:902:6546:b0:1d4:3af6:6d1b with SMTP id d6-20020a170902654600b001d43af66d1bmr7419186pln.33.1704310947742; Wed, 03 Jan 2024 11:42:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704310947; cv=none; d=google.com; s=arc-20160816; b=UHFy/bfWuMmbwfAoTbkCAT8VXInxCbzAAAVGsiR2TbuIUiwlTSK9N8N9rjG0ur9Jtp jO5a0ZLUF/tc7pMDiGeklTWbLxB/rR6prS1FUIEUgukpGpQhV2O6gsaTeGb7S7Mo0d+Q 4aRYeobyZNArQnIm8f0Hm/2URlIQmYrSdWrszWO9xeMGq2GxMi8hctcQtAA4JhnZytYn MN4zwrjpgxXWiYG1hiCnPmlAMlWo+e7eQxiYqMN87ykQZ/8xfcAGSECku2rpkekaDnGd D9vatZAFPCnBmF7BcvI6KGX6xg0/xeVz1BZBj1wIEb6FrJeKzoa/8WcP6RqITYSeDwp3 szMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=hQMMyp/+VqJgJzvufNwTc8r2Xq2Zt9hxS7khxJRxxoU=; fh=kWZtVRr3OqUr9cTIRnamcvwoPDzGPV8zB4X9oxIpA3M=; b=gC6JWoyZwGLLdL847mhSAmTyReqQn+aFSZui7sOFu/ma6/5bAr+01mR9xDGZz3K3GW 1Q3RMjw4h9jY976zMm3eezOdxzJV0BONNC6tuf3PkqYLH88zR4ouqAT5ahAhdyrnEAj6 fCcMlfd/fymUt14ezKOIvKNMTyMY306RUueNk8QKhPdjiwYRjICqYxH1W89LUyHR/CbE u22hgdponlZVCYWybgW9lUg1A/V9ljiWl+wldT/T7ziKTipjz1GqeySPFsRWDrByc+9j i94bS8CquCR9vydRCsJ80bfPCrq9oZ29dqmEyegp84QUwK2bX8yyL1txHxnwIE3EIe5b t/bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=M8xUQWdo; spf=pass (google.com: domain of linux-kernel+bounces-15921-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15921-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id iw4-20020a170903044400b001d3fbe6900dsi4748640plb.622.2024.01.03.11.42.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 11:42:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15921-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=M8xUQWdo; spf=pass (google.com: domain of linux-kernel+bounces-15921-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15921-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 588612874B5 for ; Wed, 3 Jan 2024 19:42:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0BB0F1CF91; Wed, 3 Jan 2024 19:42:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="M8xUQWdo" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCED61CAB1; Wed, 3 Jan 2024 19:42:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-50e7e55c0f6so7700827e87.0; Wed, 03 Jan 2024 11:42:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704310935; x=1704915735; darn=vger.kernel.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=hQMMyp/+VqJgJzvufNwTc8r2Xq2Zt9hxS7khxJRxxoU=; b=M8xUQWdoQPjQPDElcyAIOJRKgPKKPynBjvqc697mF/94PyoTLnyM5pQ4k12MzT4n8a jqiauXRzVvKkcctkEUEHi3aG72jKUX2ArM0eBe8rEwGlzqynWpPObw35z+H45rjKQ9kd ODdJZB8oNA2fHkO34FdrH1nxbTvyjlOtJKRJ9V455wlKwxBAYkxM9DYbqnzAPKaGAMPu cfarLSal09EtYxwtHErMywHxAOddipp/p4024CyLdCjouz5xQ2ar/QrfATWkfeOteQFw +sfGztrQpAbAJVWKktMfufhZV8gB/u8RofBDETCO98p8hHNlfyKfEwrhHGO4yvrmWC6b 61yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704310935; x=1704915735; 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=hQMMyp/+VqJgJzvufNwTc8r2Xq2Zt9hxS7khxJRxxoU=; b=WeOpf10Ao0mc4JxpAVClK0aVF75PAK0ydOhoVSyUq8ksuLP64ZMaCujhDHg1GvJFUa PaP8IhavibUUQ6wTNdhFNPkbRf02FWGoaON2bqw1sDRUcLjjkfbWdXSV5zw4nYYIsT0y y5xzAo9Qm3uv08BGN5JFz/2MaxLNe/ao6kQiYT9pORrHAxRTcDWVrn42OWnqQ7MIi3vx Opr2gOMOaJK/ePsSS2aGDpgx2Z64gUv1H6cmW6F9FSswGHOyxTqEumIN+cst9zqbj4eJ 8mwoJtklTMXK+RlUvpHU33Yqr6vBbAjpWojG6ocgXiTLkbYjlPubblszAUsMXNqNlHTw ckxQ== X-Gm-Message-State: AOJu0Yy3BVyaR8ff09BxXJEVXynjjM4hFs6bATnxP2tYknTzUeGsoNdv F8xYW5GNs7HUu0ERNrUmphC8YyC6tlZBKl+s294= X-Received: by 2002:a05:6512:3912:b0:50d:6249:17cc with SMTP id a18-20020a056512391200b0050d624917ccmr3923088lfu.245.1704310934397; Wed, 03 Jan 2024 11:42:14 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240103185403.610641-1-brho@google.com> <20240103185403.610641-2-brho@google.com> In-Reply-To: <20240103185403.610641-2-brho@google.com> From: Andrii Nakryiko Date: Wed, 3 Jan 2024 11:42:01 -0800 Message-ID: Subject: Re: [PATCH v2 bpf-next 1/2] libbpf: add helpers for mmapping maps To: Barret Rhoden Cc: Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Song Liu , Yonghong Song , mattbobrowski@google.com, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jan 3, 2024 at 10:54=E2=80=AFAM Barret Rhoden wro= te: > > bpf_map__mmap_size() was internal to bpftool. Use that to make wrappers > for mmap and munmap. > > Signed-off-by: Barret Rhoden > --- > tools/bpf/bpftool/gen.c | 16 +++------------- > tools/lib/bpf/libbpf.c | 18 ++++++++++++++++++ > tools/lib/bpf/libbpf.h | 6 ++++++ > tools/lib/bpf/libbpf.map | 4 ++++ > 4 files changed, 31 insertions(+), 13 deletions(-) > There is very little added value provided by these APIs, while adding API obligations. bpf_map__mmap() assumes READ/WRITE access, why? What if the user needs only read-only? And so on. Please drop this patch, we don't need to expose these functions as stable APIs. Definitely not bpf_map__mmap/munmap. bpf_map__mmap_size() might be useful to hide various per-map type details, but we'll need to discuss all this separately. > diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c > index ee3ce2b8000d..a328e960c141 100644 > --- a/tools/bpf/bpftool/gen.c > +++ b/tools/bpf/bpftool/gen.c > @@ -453,16 +453,6 @@ static void print_hex(const char *data, int data_sz) > } > } > > -static size_t bpf_map_mmap_sz(const struct bpf_map *map) > -{ > - long page_sz =3D sysconf(_SC_PAGE_SIZE); > - size_t map_sz; > - > - map_sz =3D (size_t)roundup(bpf_map__value_size(map), 8) * bpf_map= __max_entries(map); this is specifically ARRAY map's rules, it might differ for other map types (e.g., RINGBUF has different logic) > - map_sz =3D roundup(map_sz, page_sz); > - return map_sz; > -} > - [...]