From patchwork Fri Feb 9 04:06:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 13550854 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 50349C4828F for ; Fri, 9 Feb 2024 04:07:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D5DEE8D000A; Thu, 8 Feb 2024 23:07:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CC0608D0001; Thu, 8 Feb 2024 23:07:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B393C8D000A; Thu, 8 Feb 2024 23:07:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9FF598D0001 for ; Thu, 8 Feb 2024 23:07:10 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7A09940010 for ; Fri, 9 Feb 2024 04:07:10 +0000 (UTC) X-FDA: 81770930220.16.07A9433 Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42]) by imf10.hostedemail.com (Postfix) with ESMTP id A1A4FC001D for ; Fri, 9 Feb 2024 04:07:08 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=RAiKDjXP; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.161.42 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=1707451628; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=F0RFXFHjgEipVAjjo7rYUK8PW9TKsuaRbrDEibnvW4k=; b=JuftfkVmtC8rObwjv2DrJ0ie/AZdXJQCYnbUo2teKKfdF6vjUcYnU/vJPxyKBPCT4wGYhZ 1htK67gea0qIsk8tguqpzAfsVyivM15rBJ9rWgJnfBzFRMdX2QoiBqCNY1WOKpbl77jQp1 gPmTZ0VtseIzsyFdhn8pYksD8FA5YCI= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=RAiKDjXP; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.161.42 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707451628; a=rsa-sha256; cv=none; b=czt1YiNvgzsuCfEEaZ1JUE2+bJd1N2RttA2UKFHnY30RgOXYqomjEg0J6OUE/rB2M5cEft EjtUapVyjJDiPJQOAWnTaG9A9iy2Fm59hrvm+cgRIcRv87OjNnRKQ7b5izUqWerPLzGV0v JVZkQAkgQAQulxZaLKkmzZmWyJXcTtQ= Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-598699c0f1eso317140eaf.2 for ; Thu, 08 Feb 2024 20:07:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707451628; x=1708056428; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=F0RFXFHjgEipVAjjo7rYUK8PW9TKsuaRbrDEibnvW4k=; b=RAiKDjXPHP36aCP4iXv2MQBTQb8zymn3F4bisRDwQBRSEkHmMxMotzPXleeVLRpLyX a1iB6dLjbubwnP4AjnJBAczK/fEbGnm7dhzm6flezYhzxr41LBnpTZnEMYNs2dneeVkz xxpe9wm5XIMxo8RRErAwYYzvNmQjC4UPwUtWlJx4qjc0nwGmqrilXH+JCkEvJe+R6B/C uqtd0sIn9aCeofFV6oEaaRz9hHepW1BFckvB+6NfaAcJia8uVjp/xTmIKCGKxcKPHmpW hrWYkDvOvYzH4cmFFOHqzudpC7GhXVuW08Eja+3KwJ5wafB0S16xL3627KsIlc7bzYrn 6u0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707451628; x=1708056428; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=F0RFXFHjgEipVAjjo7rYUK8PW9TKsuaRbrDEibnvW4k=; b=K/gcptUGZrICNr9m3+fdV9ip1eVxtbWWZrK8c+8Q4hQimZx4wQUAapX05tGx6Dw+Q3 rjmv9fwbEEuO2e64Vy34hg/j/cCmLYuqZP+MVje5qnvEHKIsJg+2INH/3GhxBP/g8HFx RxG19SB2MZguKBtdq3wxYBOCaE8Z18vASZw6P9Nm7w8OstW05q8Ytayfn9HJhAiA/Qpx taT3KNv8b7GOvXlTxdLyqY7rf6OoKHrOwJPaTbV5G6IayrelIKYCkt7ggwsHaXxw0r1a ICIu3UUsj0vzpqOeCFHTYbZQoFQQZgVczw+wSbnZTS90fXPLTA76Ep5Ruxgw8cNbK8M/ k3ZQ== X-Gm-Message-State: AOJu0YxMQYQUs9WzF7YzdJpLo5wM4TBTeylS6xssg6ckvJrnWNKQ+VUL 5bwimuZ0JLkrUbeExGHQsUR95pzsXqtPZ6CTGOsphyE/dR+fumRS X-Google-Smtp-Source: AGHT+IH3ELoemyowyx9wDHV3307l0ycjd0Y77bmRJBAVEdimNMeIuNSIlIwPFXHELajuyUjjlQuC3w== X-Received: by 2002:a05:6358:5923:b0:178:fcd3:c316 with SMTP id g35-20020a056358592300b00178fcd3c316mr369964rwf.19.1707451627656; Thu, 08 Feb 2024 20:07:07 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWoqc11kvj74nhgP0ItrhTalUSnkiKOdLRkeNXEUDkXxEiRPRf5d4bYuosF+6cOhfxzAMXVsl+t9+QOFHt5NPTVLFeWfXCYrBD7zGBhDwyKkAg83xUqbq16d4W438iTv/u4iqXlrxEfu5sU2ANBjPMqsLutqvxFcyLN7iF8AmK5czq/wJC1HhSd5mJgCo/vuHecDmQai1BM7uVYVxdm2xvH48dSiZe88KkqjcoFFxkEbZdmbNwrubW/g03c508mJ+Ep58KUOUKGi+0TXrw5efj3tEt/fIfNkCt6kmNdiEVmolW+mb3CmnCkJvU+Vf3d6lOpC4xDzA8R75HxOgkWVg0SLXn4HSflWlWByPP9oqC5Q5ltk7QVRA== Received: from macbook-pro-49.dhcp.thefacebook.com ([2620:10d:c090:400::4:a894]) by smtp.gmail.com with ESMTPSA id r15-20020aa7988f000000b006e02da3a158sm610623pfl.17.2024.02.08.20.07.05 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 08 Feb 2024 20:07:07 -0800 (PST) From: Alexei Starovoitov To: bpf@vger.kernel.org Cc: daniel@iogearbox.net, andrii@kernel.org, memxor@gmail.com, eddyz87@gmail.com, tj@kernel.org, brho@google.com, hannes@cmpxchg.org, lstoakes@gmail.com, akpm@linux-foundation.org, urezki@gmail.com, hch@infradead.org, linux-mm@kvack.org, kernel-team@fb.com Subject: [PATCH v2 bpf-next 13/20] libbpf: Allow specifying 64-bit integers in map BTF. Date: Thu, 8 Feb 2024 20:06:01 -0800 Message-Id: <20240209040608.98927-14-alexei.starovoitov@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20240209040608.98927-1-alexei.starovoitov@gmail.com> References: <20240209040608.98927-1-alexei.starovoitov@gmail.com> MIME-Version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ytZYoHt9vaehBXzAp+l3h pbkc5C7X bHRQbxSToKPmO7ORnBDtUFF+6t8fkzplOIYYm1hmyTHr4yigGkEOYdtaQAHXRy9x3xGFxyCKZ+kJFxpcAycegGbyQB2Tb1EdU1UjNJtOoqFwADgVrJjWxFM7KjIB1X5MstVLrcUApiYWMpupeP/daoYQLG1F+GPoC6I2NuHcr4TrjaAMHkPwWnLA7pMuvRS5d1IUnF34xbFQZL/zmKYwawI8/lz0rGLOuAV5j2XPOQODnvlmSNyj2IOlWhPZ5e3V8ewEk1J/UMdY278xhMfKn+hbdMqMF59Gdl4tWgDMZy2vrDZaVA/qdn2lRGlFBhLO3j6fNAovoYvBWxThDFtfPabrvc6rHu8nvaUXsO2BckKyAtZQA3PXlVZSSsFh1Gnr0Slziz4ha7xJfjDC74aOW/lo8Fr3INarCYcG4sxIFf+U9eDSF9neSUVuw+3y6mevpCKAmRi4awfAqBTZ6o0VKfpjUHZ0hQqNgTCBsWkCyKyOYJIVYuJ7IHxo3Dgma828WVlnGB9ENFZWEHcud+mspRbAwYJQgm6gIaoa3yMq7UG9R8eyHRDz4Uj/L9w== 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: From: Alexei Starovoitov __uint() macro that is used to specify map attributes like: __uint(type, BPF_MAP_TYPE_ARRAY); __uint(map_flags, BPF_F_MMAPABLE); is limited to 32-bit, since BTF_KIND_ARRAY has u32 "number of elements" field. Introduce __ulong() macro that allows specifying values bigger than 32-bit. In map definition "map_extra" is the only u64 field. Signed-off-by: Alexei Starovoitov Acked-by: Eduard Zingerman --- tools/lib/bpf/bpf_helpers.h | 5 +++++ tools/lib/bpf/libbpf.c | 44 ++++++++++++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/tools/lib/bpf/bpf_helpers.h b/tools/lib/bpf/bpf_helpers.h index 9c777c21da28..0aeac8ea7af2 100644 --- a/tools/lib/bpf/bpf_helpers.h +++ b/tools/lib/bpf/bpf_helpers.h @@ -13,6 +13,11 @@ #define __uint(name, val) int (*name)[val] #define __type(name, val) typeof(val) *name #define __array(name, val) typeof(val) *name[] +#ifndef __PASTE +#define ___PASTE(a,b) a##b +#define __PASTE(a,b) ___PASTE(a,b) +#endif +#define __ulong(name, val) enum { __PASTE(__unique_value, __COUNTER__) = val } name /* * Helper macro to place programs, maps, license in diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 4880d623098d..f8158e250327 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -2243,6 +2243,39 @@ static bool get_map_field_int(const char *map_name, const struct btf *btf, return true; } +static bool get_map_field_long(const char *map_name, const struct btf *btf, + const struct btf_member *m, __u64 *res) +{ + const struct btf_type *t = skip_mods_and_typedefs(btf, m->type, NULL); + const char *name = btf__name_by_offset(btf, m->name_off); + + if (btf_is_ptr(t)) + return false; + + if (!btf_is_enum(t) && !btf_is_enum64(t)) { + pr_warn("map '%s': attr '%s': expected enum or enum64, got %s.\n", + map_name, name, btf_kind_str(t)); + return false; + } + + if (btf_vlen(t) != 1) { + pr_warn("map '%s': attr '%s': invalid __ulong\n", + map_name, name); + return false; + } + + if (btf_is_enum(t)) { + const struct btf_enum *e = btf_enum(t); + + *res = e->val; + } else { + const struct btf_enum64 *e = btf_enum64(t); + + *res = btf_enum64_value(e); + } + return true; +} + static int pathname_concat(char *buf, size_t buf_sz, const char *path, const char *name) { int len; @@ -2476,10 +2509,15 @@ int parse_btf_map_def(const char *map_name, struct btf *btf, map_def->pinning = val; map_def->parts |= MAP_DEF_PINNING; } else if (strcmp(name, "map_extra") == 0) { - __u32 map_extra; + __u64 map_extra; - if (!get_map_field_int(map_name, btf, m, &map_extra)) - return -EINVAL; + if (!get_map_field_long(map_name, btf, m, &map_extra)) { + __u32 map_extra_u32; + + if (!get_map_field_int(map_name, btf, m, &map_extra_u32)) + return -EINVAL; + map_extra = map_extra_u32; + } map_def->map_extra = map_extra; map_def->parts |= MAP_DEF_MAP_EXTRA; } else {