public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
* Improvements of BTF sanitizing for old kernels
@ 2025-04-07 19:01 Timur Chernykh
  2025-04-07 19:01 ` [PATCH v2 1/2] libbpf: add proto_func param name generation Timur Chernykh
  2025-04-07 19:01 ` [PATCH v2 2/2] libbpf: add kind flag sanitizing Timur Chernykh
  0 siblings, 2 replies; 7+ messages in thread
From: Timur Chernykh @ 2025-04-07 19:01 UTC (permalink / raw)
  To: bpf; +Cc: mykyta.yatsenko5

I've done fixing comments for first version of patch set (thanks for
Mykyta).

Here's a second version. 

From: Timur Chernykh <tim.cherry.co@gmail.com>
To: bpf@vger.kernel.org
Cc: mykyta.yatsenko5@gmail.com
Bcc: 
Reply-To: 20250331201016.345704-1-tim.cherry.co@gmail.com
Subject: Improvements of BTF sanitizing for old kernels
In-Reply-To: 


^ permalink raw reply	[flat|nested] 7+ messages in thread
* Improvements of BTF sanitizing for old kernels
@ 2025-03-31 20:45 Timur Chernykh
  0 siblings, 0 replies; 7+ messages in thread
From: Timur Chernykh @ 2025-03-31 20:45 UTC (permalink / raw)
  To: bpf

I'm very sorry, but I found a small typo in 2nd patch, here's a
quick fix for one.

From: Timur Chernykh <tim.cherry.co@gmail.com>
To: bpf@vger.kernel.org
Subject: Improvements of BTF sanitizing for old kernels


^ permalink raw reply	[flat|nested] 7+ messages in thread
* Improvements of BTF sanitizing for old kernels
@ 2025-03-31 20:09 Timur Chernykh
  0 siblings, 0 replies; 7+ messages in thread
From: Timur Chernykh @ 2025-03-31 20:09 UTC (permalink / raw)
  To: bpf

Hello everyone. Recently I've encountered some issues with loading on debian 10 with kernel version `4.19.0-[17-22]`.

This first one consists of when the kernel loads BTF with specified min-CORE and libbpf does some sanitizing on those, then it "translates" func_proto to enum. But if `func_proto` has no names for it's parameters then kernel verifier fails with "Invalid name" error. This error caused by enum members must has a valid C identifier, but there's might be no names generated.

The second issue this PR supposed to fix is missed check whether kernel supports the `kind flag` or not. Let's say we're compiling the BPF object on new kernel with a new compiler. There's 99% percent chance that compiler will use this `kind flag`. But of we're loading on old kernels that have no support of this, so the loading will fail in multiple places.

- The type metadata check. Old BTF_INFO_MASK prohibits 31d bit
- Integer bitfield verification. Because old kernel waits for an offset-only encoding for the btf_member->offset field, but it's encoded in different way in case when the `kind flag` is set.

This PR contains:
- Enum names generation during sanitizing process for `func_proto` kind, when it being translate to `enum` kind.
- The feature check whether kernel supports the kind flag or not
- Kind flag sanitizing if kernel doesn't support one
- Struct/enum bitfield members sanitizing by generation a proper replacement the type of bitfield with corresponding integer type with same bit size

From: Timur Chernykh <tim.cherry.co@gmail.com>
To: bpf@vger.kernel.org
Cc: 
Bcc: 
Reply-To: 
Subject: Improvements of BTF sanitizing for old kernels
In-Reply-To: 


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-04-10  0:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-07 19:01 Improvements of BTF sanitizing for old kernels Timur Chernykh
2025-04-07 19:01 ` [PATCH v2 1/2] libbpf: add proto_func param name generation Timur Chernykh
2025-04-09 23:51   ` Andrii Nakryiko
2025-04-07 19:01 ` [PATCH v2 2/2] libbpf: add kind flag sanitizing Timur Chernykh
2025-04-10  0:02   ` Andrii Nakryiko
  -- strict thread matches above, loose matches on Subject: below --
2025-03-31 20:45 Improvements of BTF sanitizing for old kernels Timur Chernykh
2025-03-31 20:09 Timur Chernykh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox