All of lore.kernel.org
 help / color / mirror / Atom feed
* [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

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.