* [cocci] Question about Coccinelle (with __uint macro)
@ 2025-03-05 21:14 Danikka Jelski
2025-03-06 12:13 ` [cocci] Modifying BPF map definitions? Markus Elfring
2025-03-06 12:19 ` [cocci] Question about Coccinelle (with __uint macro) Julia Lawall
0 siblings, 2 replies; 5+ messages in thread
From: Danikka Jelski @ 2025-03-05 21:14 UTC (permalink / raw)
To: cocci
[-- Attachment #1: Type: text/plain, Size: 2739 bytes --]
I hope this email finds you well. I’m reaching out to seek guidance about
how Coccinelle parses complex macros. In my current research project, I am
working with Coccinelle on Ubuntu 22.04 (kernel version 6.0 generic), and
I’m experiencing issues regarding parsing complex macros. Specifically, I
was trying to modify BPF map definitions, and I encountered an issue when
applying a patch:
@@
@@
struct {
- __uint(type, BPF_MAP_TYPE_ARRAY);
+ __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
__type(key, u32);
__type(value, struct array_elem);
__uint(max_entries, 1);
} port_state SEC(".maps");
In this patch, I wanted to change the BPF map from BPF_MAP_TYPE_ARRAY to
BPF_MAP_TYPE_PERCPU_ARRAY from the __uint
<https://docs.ebpf.io/ebpf-library/libbpf/ebpf/__uint/#:~:text=The%20__uint%20macros%20is,integer%20properties%20of%20BTF%20maps.>.
I have a similar problem where it cannot parse the __type
<https://docs.ebpf.io/ebpf-library/libbpf/ebpf/__type/> macro either when I
had tested for that macro independently.
The error I get is:
Some troubleshooting I have done included:
1.
I made simplified .c files with simplified headers to check if the issue
was due to missing kernel dependencies and to isolate the issue. It seems
that it wouldn’t parse it this way, either.
One of the simpler examples I did was:
I received the same error message as before.
2.
Checking out the preprocessed code to see if the macro is expanding
correctly. I understand that Coccinelle has the option to preprocess the
code before applying a spatch, but I had also preprocessed with the C
preprocessor (gcc -E) of the file. I understand that applying a patch on
preprocessed code, where the macros are expanded, requires that the spatch
match those expansions.
With simplified examples, such as the one above, I tried to apply the patch
on preprocessed code, where it expands to:
With adjusted .cocci:
Using the spatch on such preprocessed code leads to other errors, like:
Another more simplified case with testing the expansion alone without the
struct:
The transformation unfortunately was unable to be applied in these cases.
Some specific questions I have:
1.
Can Coccinelle recognize the __uint macro inside the struct and apply a
patch that uses such a macro?
2.
Can you provide any guidance on how to properly match and modify this
struct in Coccinelle?
I would greatly appreciate any insights you can offer. Please let me know
if you need more information.
Thank you so much for your time and consideration.
Best,
Danikka Jelski | cmj136@scarletmail.rutgers.edu
[-- Attachment #2: Type: text/html, Size: 20873 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [cocci] Modifying BPF map definitions?
2025-03-05 21:14 [cocci] Question about Coccinelle (with __uint macro) Danikka Jelski
@ 2025-03-06 12:13 ` Markus Elfring
2025-03-06 12:19 ` Victor Gambier
2025-03-06 12:19 ` [cocci] Question about Coccinelle (with __uint macro) Julia Lawall
1 sibling, 1 reply; 5+ messages in thread
From: Markus Elfring @ 2025-03-06 12:13 UTC (permalink / raw)
To: Danikka Jelski; +Cc: cocci
…
> Specifically, I was trying to modify BPF map definitions, and I encountered an issue when applying a patch:
…
> The error I get is:
How do you think about to share any additional information as text
instead of linked pictures?
> Can you provide any guidance on how to properly match and modify this struct in Coccinelle?
I observed that another transformation approach gets accepted
(also together with the software version “1.3-00043-gcca22217d”).
@replacement@
@@
__uint(type,
- BPF_MAP_TYPE_ARRAY
+ BPF_MAP_TYPE_PERCPU_ARRAY
);
I am unsure under which circumstances a subsequent software version will become able
to generate patches accordingly.
Regards,
Markus
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [cocci] Modifying BPF map definitions?
2025-03-06 12:13 ` [cocci] Modifying BPF map definitions? Markus Elfring
@ 2025-03-06 12:19 ` Victor Gambier
0 siblings, 0 replies; 5+ messages in thread
From: Victor Gambier @ 2025-03-06 12:19 UTC (permalink / raw)
To: Markus Elfring, Danikka Jelski; +Cc: cocci
Hi Danikka,
Thanks for your interest!
I don't have an answer for you right now, but I just wanted you to know:
Markus is known to send unhelpful emails to newcomers, so feel free to
ignore him if his emails don't make a lot of sense. He is not a
maintainer. I do agree that text is usually preferred over pictures, but
don't sweat it too much.
Victor
On 06/03/2025 13:13, Markus Elfring wrote:
> …
>> Specifically, I was trying to modify BPF map definitions, and I encountered an issue when applying a patch:
> …
>> The error I get is:
> How do you think about to share any additional information as text
> instead of linked pictures?
>
>
>> Can you provide any guidance on how to properly match and modify this struct in Coccinelle?
> I observed that another transformation approach gets accepted
> (also together with the software version “1.3-00043-gcca22217d”).
>
>
> @replacement@
> @@
> __uint(type,
> - BPF_MAP_TYPE_ARRAY
> + BPF_MAP_TYPE_PERCPU_ARRAY
> );
>
>
> I am unsure under which circumstances a subsequent software version will become able
> to generate patches accordingly.
>
> Regards,
> Markus
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [cocci] Question about Coccinelle (with __uint macro)
2025-03-05 21:14 [cocci] Question about Coccinelle (with __uint macro) Danikka Jelski
2025-03-06 12:13 ` [cocci] Modifying BPF map definitions? Markus Elfring
@ 2025-03-06 12:19 ` Julia Lawall
2025-03-06 14:43 ` [cocci] Modifying BPF map definitions? Markus Elfring
1 sibling, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2025-03-06 12:19 UTC (permalink / raw)
To: Danikka Jelski; +Cc: cocci
[-- Attachment #1: Type: text/plain, Size: 4825 bytes --]
On Wed, 5 Mar 2025, Danikka Jelski wrote:
>
> I hope this email finds you well. I’m reaching out to seek guidance about
> how Coccinelle parses complex macros. In my current research project, I am
> working with Coccinelle on Ubuntu 22.04 (kernel version 6.0 generic), and
> I’m experiencing issues regarding parsing complex macros. Specifically, I
> was trying to modify BPF map definitions, and I encountered an issue when
> applying a patch:
>
>
> @@
>
> @@
>
> struct {
>
> - __uint(type, BPF_MAP_TYPE_ARRAY);
>
> + __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
>
> __type(key, u32);
>
> __type(value, struct array_elem);
>
> __uint(max_entries, 1);
>
> } port_state SEC(".maps");
Please try adding a metavariable:
declarer name __uint;
On the other hand, I don't know how the SEC thing will work. Is that
something that you care about whether it is there or not? Do you care
about the declaration of port_state? If you actually just want to change
the type declaration wheerer it occurs, you can get rid of "port_state
SEC(".maps");". Then it will just work on the type.
As Markus mentioned, please make messages that contain only text.
thanks,
julia
>
>
> In this patch, I wanted to change the BPF map from BPF_MAP_TYPE_ARRAY to
> BPF_MAP_TYPE_PERCPU_ARRAY from the __uint. I have a similar problem where it
> cannot parse the __type macro either when I had tested for that macro
> independently.
>
>
> The error I get is:
>
> [AD_4nXdSOIb1mx6UOgK95vL1l3BTTwStJgl3BWKcm0S7gx13MpOcwIBj5hyWIY9R6lFCBn_7al
> jh2uohN2suEGtxDPjP5Q9Qh0S6wDo496iVST5EbGj7v7uU17ul68j8K09zMG436N5NrQ?key=H
> Dx3ebciDTqk2MuXMXjB9X1r]
>
> Some troubleshooting I have done included:
>
> 1.
>
> I made simplified .c files with simplified headers to check if the issue
> was due to missing kernel dependencies and to isolate the issue. It
> seems that it wouldn’t parse it this way, either.
>
> One of the simpler examples I did was:
>
>
> [AD_4nXcze023-F5OV4Rax-hTjRdtcBoJVlO03zGi1HwEJW6YULoqcVl41_liGdiiQU40tigM4q
> bzBGkLpzifzmy-NCew7kr7BNi3nfc_pdNZAp7QcWj4mkab6thRYrgNamaAzz0zY6II-w?key=H
> Dx3ebciDTqk2MuXMXjB9X1r]
>
> [AD_4nXe44xFLkphNYL16klw0BOw1N-sgjYydSe4K8ebUEf0P7LzHzXHh64dyXSkBSl7fQrVVhc
> NF7SJWZDB-gELO0_FJIgdPL2ZwzuA0wVQbTPwx7-4vn5dg16FE2HCsAn2UUgMJI29GHA?key=H
> Dx3ebciDTqk2MuXMXjB9X1r]
>
> I received the same error message as before.
>
>
> 2.
>
> Checking out the preprocessed code to see if the macro is expanding
> correctly. I understand that Coccinelle has the option to preprocess the
> code before applying a spatch, but I had also preprocessed with the C
> preprocessor (gcc -E) of the file. I understand that applying a patch on
> preprocessed code, where the macros are expanded, requires that the
> spatch match those expansions.
>
> With simplified examples, such as the one above, I tried to apply the patch
> on preprocessed code, where it expands to:
>
> [AD_4nXfZSAGZD1liPgdEWRbWd2soFXXvuN7Ln66V6LBlHF3xnBEHrcEdWIyfMM2N10_dtXzWiw
> s2SDvPnU1MWlS5O5ANOMJZ_XOMEHKVUkPXHJ2V0kPXmrNvQUPIQ6Xy0Ih4MraUS8Zk?key=HDx
> 3ebciDTqk2MuXMXjB9X1r]
>
> With adjusted .cocci:
>
> [AD_4nXcLELlpbC3w5XjioTqe60X0rcj1hqVyzFOm-DhDteLCJLtxuGYn1x41j0r-p8-yvEw7X
> _L5gcyK65E6SNSDpIXrW4fW0SnzYHju7Y1kgJw9StoBsRiTidIn9ELWZvy0WKWY08Cq?key=HD
> x3ebciDTqk2MuXMXjB9X1r]
>
> Using the spatch on such preprocessed code leads to other errors, like:
>
> [AD_4nXfGz64oFjBTtPyjoJsSMTRXrW-ELoXUc0wug9NyW1Gy83piBuORsvO4UjBfByAC73dE5h
> 56s2TzcQ4mZEi4RfsFtluLJwGTzyNpe_5ZJnlIBeNIL-r0UsBwjxI5lyVKHUjOp6iKhw?key=H
> Dx3ebciDTqk2MuXMXjB9X1r]
>
>
> Another more simplified case with testing the expansion alone without the
> struct:
>
> [AD_4nXcV_sFkshVZkb7elsFL97QAbZYWETLMdaILEyiP00TUIssUQGpUBk2QJT-cpLZHdKqtLJ
> 8OncW7EU96sMad_umZBgpBDrNKvjNBvfrw2kQPTxVLa11baGtLr4xGF45zNrSulTwAZQ?key=H
> Dx3ebciDTqk2MuXMXjB9X1r]
>
> [AD_4nXfj46ZjPdGs_w31DavWeAge8ODdFevKPZIL-jStK8u081pXcLdqCjwpQI0cDUCwvMcZyz
> TngQ_S8qGSRB1Vcimrm6Z1_0vJtmdLrgX2leAkK2MQMrKqB6RNhSqqtWBVHB6d2Vdv?key=HDx
> 3ebciDTqk2MuXMXjB9X1r]
>
> [AD_4nXfO8A2d5ngtG01ULaQvxMU1tWI9PybYeJ0QokLN_XkG_u1B3hcAB0N6hyLYtont7w84IZ
> hpqTbxq_k_Ae-0HKcSmwpIzP2lKRKo8q9h9NQ_qxN9G80wERvaAUJxNF93UyGy56ltKw?key=H
> Dx3ebciDTqk2MuXMXjB9X1r]
>
> The transformation unfortunately was unable to be applied in these cases.
>
>
> Some specific questions I have:
>
> 1.
>
> Can Coccinelle recognize the __uint macro inside the struct and apply a
> patch that uses such a macro?
>
> 2.
>
> Can you provide any guidance on how to properly match and modify this
> struct in Coccinelle?
>
>
> I would greatly appreciate any insights you can offer. Please let me know if
> you need more information.
>
>
> Thank you so much for your time and consideration.
>
>
> Best,
>
> Danikka Jelski | cmj136@scarletmail.rutgers.edu
>
>
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [cocci] Modifying BPF map definitions?
2025-03-06 12:19 ` [cocci] Question about Coccinelle (with __uint macro) Julia Lawall
@ 2025-03-06 14:43 ` Markus Elfring
0 siblings, 0 replies; 5+ messages in thread
From: Markus Elfring @ 2025-03-06 14:43 UTC (permalink / raw)
To: Julia Lawall, cocci; +Cc: Danikka Jelski
…
>> __uint(max_entries, 1);
>>
>> } port_state SEC(".maps");
…
> you can get rid of "port_state
> SEC(".maps");". …
How do you think about the applicability of another transformation approach?
@replacement2@
attribute name SEC;
declarer name __uint;
constant char[] text;
@@
struct
{
...
__uint(type,
- BPF_MAP_TYPE_ARRAY
+ BPF_MAP_TYPE_PERCPU_ARRAY
);
...
} port_state SEC(text);
Regards,
Markus
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-03-06 14:43 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-05 21:14 [cocci] Question about Coccinelle (with __uint macro) Danikka Jelski
2025-03-06 12:13 ` [cocci] Modifying BPF map definitions? Markus Elfring
2025-03-06 12:19 ` Victor Gambier
2025-03-06 12:19 ` [cocci] Question about Coccinelle (with __uint macro) Julia Lawall
2025-03-06 14:43 ` [cocci] Modifying BPF map definitions? Markus Elfring
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.