From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (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 AB7E53ABD82 for ; Fri, 17 Jul 2026 21:52:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784325176; cv=none; b=edutXrK/brFyieD0HxI+5NlgLWu5JE+0OVKquP8tpzyJ3tRhOvtFxycpO+h2ue3C/5v9E1AW2eV44LnXKPQ+ue05vRIokmzBA2uimHzXSiq9MybfJMiU/oMMmpJRIAAgtYIqOrU5bcFesdjh4XHVB9sgzS9BN7AZwZrt8ysrwwM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784325176; c=relaxed/simple; bh=zc7D/9EwQRgTjJcnICDGen34BP8M4e+uP9KTBbq2Gmg=; h=Mime-Version:Content-Type:Date:Message-Id:From:To:Cc:Subject: References:In-Reply-To; b=dOxb6FU9ns6YQB1sak8cfKpi22dr+/Kg7ISdwkjc6JQoVWmWtqDVBe4cuLnTSInu4vocF4+dQpk9TFH12dWMxEwopxPg/Spgk0187nciFsD+dmBdViCom7xqmK9AP9FifvQM7+MUahbIANQc6XB74HcMhr99ryOIyHzT08Ss5mU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=etsalapatis.com; spf=pass smtp.mailfrom=etsalapatis.com; dkim=pass (2048-bit key) header.d=etsalapatis-com.20251104.gappssmtp.com header.i=@etsalapatis-com.20251104.gappssmtp.com header.b=WFJfe5tv; arc=none smtp.client-ip=209.85.216.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=etsalapatis.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=etsalapatis.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=etsalapatis-com.20251104.gappssmtp.com header.i=@etsalapatis-com.20251104.gappssmtp.com header.b="WFJfe5tv" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-38e07ebd263so3431605a91.1 for ; Fri, 17 Jul 2026 14:52:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=etsalapatis-com.20251104.gappssmtp.com; s=20251104; t=1784325158; x=1784929958; darn=vger.kernel.org; h=in-reply-to:references:subject:cc:to:from:message-id:date :content-type:content-transfer-encoding:mime-version:from:to:cc :subject:date:message-id:reply-to:content-type; bh=ZRpkQ2cyJn8DEz8vKvVjafNoUUwgLSz9vl4mrpr70F0=; b=WFJfe5tv5GXpTFQB+Nl+/juMQ9Rm6EB/gSsoE0uimt30/V+dV5cWOcr0Rl4EjvnNgl 8KS1Y1DvFb9Jh6GV0Tu2wQdI/U/TI4EdAqRmX7HorCoout3o70Vfl1uT08Mw7fnCn+rb aF5FGJF/TpYSSuoON8bpvH475u/ozdQrCByJ3WHy8kCwCcuHv767jbaPxwN1rZU+/syH JdUoMOUKXR7G+e38oMZ+nSNom22ayZMbOUm4rEYvXWP0oWQT7R1dwHnw6B2AHhX4/JSd i4cgIuCfeMp+RsX3XpegPdEIJfEGfXIk6GCwEn4csBPOZUCdjMgK3Brz+0x02SwITUw4 M33g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784325158; x=1784929958; h=in-reply-to:references:subject:cc:to:from:message-id:date :content-type:content-transfer-encoding:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ZRpkQ2cyJn8DEz8vKvVjafNoUUwgLSz9vl4mrpr70F0=; b=FFyrb9uDFvW6VyGV9JjgjU2MS5GHVquCfQOPT8way2mHDcuNDTpFyf4+tUdOR9YMhw Gtnr53/8z+ijxjU7AWP6G/aRMcXcDEStauuu72m89JQSGD5OIA45ipLKKMYXB6thGF8M b4gjCDLePnNwxQCHbfZjNnin0DDyofW9iEEq9EwxvCpM4vdy26ePqAyXAvpcAepZyc9j wmfJuBbKetX2Wu+f2GAeX5gmQYpZeBI1RyD7cqqyIslzjHwXKEhX5jX1QbYLvvll2Bt8 +ZKjaoCxr2a5exSzztITzufTfF9wWhULwpwwAotQGs7B6mYVKoVtV96H2RGaVW+PIinS Y9bg== X-Forwarded-Encrypted: i=1; AHgh+RrsuKnTKWS5pkwwGdfH/ZTMAzNFyfsnZLmLnQ+flw3qaM2SqNxvFTnw0q5jYlj6Xwd+w3HZ29/WqDu6sbw=@vger.kernel.org X-Gm-Message-State: AOJu0YxZLi9gpqhwUCT+xisD9mT3qaMiW1GKLwyPBKg18QLPAkMvNlAa 3affL0itnEFv3XXO+V1b564wgctEzzz4IeI61Id4I+0o9zTj6ub7gMfqz5o0P3j6lOc= X-Gm-Gg: AfdE7clSFXTmKBErf/4vlHp8nunSuuyQh8bqNgwGw60muTBNgUFUKMMlRaM8BOm2JKB AMGHySoFdVpbKgDorWn3ktfKPT7ZT9XmzkYEfRVM+5jW6ZdbLqyLKQAF5dp7RVFmPGL47gn7RMK EY5hPbmckA+09YHoQImAHPuid3TjElfnGdni7m1l0NunwdWUIaQRrl7EE22tF3YiyhL22DSl+qM jAC/JN6AWo2w0p7B5v/fzio2u0IanoAN0+8XDbU0kyFkXCtWpet8RBYRmhax0WRmldOu2A9rtx4 tDXJvSv21enJcdX/yRI708TibvrC3btM8sxJhJejhyg8A+JT1QwlW398nvGQwauCL4NIfYSo8Wi mPbCeACLPm4yZhxyV5gqGxGnbNR9zmtfWwIz/hl+hMkPIjtiDttskQR4l3176bmBpCiy5lCKvro w7Zw== X-Received: by 2002:a17:90a:e7c1:b0:37f:9ce1:735f with SMTP id 98e67ed59e1d1-38e4b537cf4mr3919621a91.32.1784325157799; Fri, 17 Jul 2026 14:52:37 -0700 (PDT) Received: from localhost ([163.114.132.129]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3142a1bb8a4sm11278963eec.14.2026.07.17.14.52.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Jul 2026 14:52:37 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Fri, 17 Jul 2026 17:52:34 -0400 Message-Id: From: "Emil Tsalapatis" To: "Leon Hwang" , Cc: "Alexei Starovoitov" , "Daniel Borkmann" , "Andrii Nakryiko" , "Martin KaFai Lau" , "Eduard Zingerman" , "Kumar Kartikeya Dwivedi" , "Song Liu" , "Yonghong Song" , "Jiri Olsa" , "John Fastabend" , "Quentin Monnet" , "Shuah Khan" , , , Subject: Re: [PATCH bpf-next v10 3/9] libbpf: Probe percpu data feature X-Mailer: aerc 0.21.0-0-g5549850facc2 References: <20260715153254.92010-1-leon.hwang@linux.dev> <20260715153254.92010-4-leon.hwang@linux.dev> In-Reply-To: <20260715153254.92010-4-leon.hwang@linux.dev> On Wed Jul 15, 2026 at 11:32 AM EDT, Leon Hwang wrote: > libbpf needs a reliable way to distinguish kernels that can support > global percpu data from those that cannot. > > Add a dedicated feature probe, so libbpf can make capability decisions > early and fail predictably when global percpu data is unavailable. > > Acked-by: Andrii Nakryiko > Signed-off-by: Leon Hwang Reviewed-by: Emil Tsalapatis > --- > tools/lib/bpf/features.c | 35 +++++++++++++++++++++++++++++++++ > tools/lib/bpf/libbpf_internal.h | 2 ++ > 2 files changed, 37 insertions(+) > > diff --git a/tools/lib/bpf/features.c b/tools/lib/bpf/features.c > index b7e388f99d0b..ef9581c11303 100644 > --- a/tools/lib/bpf/features.c > +++ b/tools/lib/bpf/features.c > @@ -620,6 +620,38 @@ static int probe_bpf_syscall_common_attrs(int token_= fd) > return probe_sys_bpf_ext(); > } > =20 > +static int probe_kern_percpu_data(int token_fd) > +{ > + struct bpf_insn insns[] =3D { > + BPF_LD_MAP_VALUE(BPF_REG_1, 0, 0), > + BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, 0), > + BPF_EXIT_INSN(), > + }; > + LIBBPF_OPTS(bpf_map_create_opts, map_opts, > + .token_fd =3D token_fd, > + .map_flags =3D token_fd ? BPF_F_TOKEN_FD : 0, > + ); > + LIBBPF_OPTS(bpf_prog_load_opts, prog_opts, > + .token_fd =3D token_fd, > + .prog_flags =3D token_fd ? BPF_F_TOKEN_FD : 0, > + ); > + int ret, map, insn_cnt =3D ARRAY_SIZE(insns); > + > + map =3D bpf_map_create(BPF_MAP_TYPE_PERCPU_ARRAY, "libbpf_percpu", size= of(int), 8, 1, > + &map_opts); > + if (map < 0) { > + pr_warn("Error in %s(): %s. Couldn't create simple percpu_array map.\n= ", > + __func__, errstr(map)); > + return map; > + } > + > + insns[0].imm =3D map; > + > + ret =3D bpf_prog_load(BPF_PROG_TYPE_SOCKET_FILTER, NULL, "GPL", insns, = insn_cnt, &prog_opts); > + close(map); > + return probe_fd(ret); > +} > + > typedef int (*feature_probe_fn)(int /* token_fd */); > =20 > static struct kern_feature_cache feature_cache; > @@ -707,6 +739,9 @@ static struct kern_feature_desc { > [FEAT_BPF_SYSCALL_COMMON_ATTRS] =3D { > "BPF syscall common attributes support", probe_bpf_syscall_common_attr= s, > }, > + [FEAT_PERCPU_DATA] =3D { > + "kernel supports percpu data", probe_kern_percpu_data, > + }, > }; > =20 > bool feat_supported(struct kern_feature_cache *cache, enum kern_feature_= id feat_id) > diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_inter= nal.h > index d5b7db703b3f..b786f1a35567 100644 > --- a/tools/lib/bpf/libbpf_internal.h > +++ b/tools/lib/bpf/libbpf_internal.h > @@ -401,6 +401,8 @@ enum kern_feature_id { > FEAT_BTF_LAYOUT, > /* Kernel supports BPF syscall common attributes */ > FEAT_BPF_SYSCALL_COMMON_ATTRS, > + /* Kernel supports percpu data */ > + FEAT_PERCPU_DATA, > __FEAT_CNT, > }; > =20