On Fri, 27 Nov 2020, Ira Weiny wrote:
> I have been looking for a way to help automate my kmap/mem*/kunmap
> transformation.[1] I'm very new to coccinelle and I'm having some trouble.
>
> I have tried to build up a script[2][3] to do this while also learning
> coccinelle
> but I'm not getting a couple of points.
>
> 1) How do I get matches to iterate?
What do you mean by iterate?
> 1a) What is the difference between '<+... ...+>' and '<... ...>'?
<+... P ...+> requires P to appear one or more times
<... P ...> allows P to occur 0 or more times
> 2) Why can't I get the type declaration (type VP;) matched correctly. It
> works
> some times but not always. It also matches a lot of random declarations?
> 2a) and for some reason in the more advanced script[3] it completely
> breaks. Which is very confusing because fundamentally it does not
> seem to be any different from [2]?
I haven't tried running the scripts to see why the declaration breaks.
but I think that the declaration is not what you want. ptr could be used
in some other case. It would be better to have one rule that makes the
rest of the changes in the code, and the another rule that removes the ptr
declaration when there is no remaining use of the variable:
@r1@
identifier ptr;
...
@@
remove kmaps etc
@@
identifier r1.ptr;
type T;
@@
- T ptr;
... when != ptr
This will allow you to get rid of lines 8 and 28 in [2].
julia
> Any advice is appreciated.
>
> Thanks,
> Ira
>
> [1] https://lore.kernel.org/lkml/20201124141244.ge17...@twin.jikos.cz/
>
> [2]
> <script>
> 1 @ rule0 @
> 2 type VP;
> 3 identifier ptr;
> 4 identifier page;
> 5 @@
> 6
> 7 -VP ptr;
> 8 <...
> 9 (
> 10 -ptr = kmap(page);
> 11 |
> 12 -ptr = kmap_atomic(page);
> 13 )
> 14 <+...
> 15 (
> 16 -memset(...);
> 17 +memIra();
> 18 |
> 19 -memcpy(...);
> 20 +memIra();
> 21 )
> 22 ...+>
> 23 (
> 24 -kunmap(page);
> 25 |
> 26 -kunmap_atomic(ptr);
> 27 )
> 28 ...>
> </script>
>
> [3]
> <script>
> 1 @ rule0 @
> 2 type VP;
> 3 identifier page;
> 4 identifier ptr;
> 5 expression V;
> 6 expression L;
> 7 expression T;
> 8 expression F;
> 9 expression B;
> 10 expression Off;
> 11 @@
> 12
> 13 -VP ptr;
> 14 <...
> 15 (
> 16 -ptr = kmap(page);
> 17 |
> 18 -ptr = kmap_atomic(page);
> 19 )
> 20 <...
> 21 (
> 22 -memset(ptr, 0, L);
> 23 +zero_user(page, 0, L);
> 24 |
> 25 -memset(ptr + Off, 0, L);
> 26 +zero_user(page, Off, L);
> 27 |
> 28 -memset(ptr, V, L);
> 29 +memset_page(page, V, 0, L);
> 30 |
> 31 -memset(ptr + Off, V, L);
> 32 +memset_page(page, V, Off, L);
> 33 |
> 34 -memcpy(ptr + Off, F, B);
> 35 +memcpy_to_page(page, Off, F, B);
> 36 |
> 37 -memcpy(ptr, F, B);
> 38 +memcpy_to_page(page, 0, F, B);
> 39 |
> 40 -memcpy(T, ptr + Off, B);
> 41 +memcpy_from_page(T, page, Off, B);
> 42 |
> 43 -memcpy(T, ptr, B);
> 44 +memcpy_from_page(T, page, 0, B);
> 45 )
> 46 ...>
> 47 (
> 48 -kunmap(page);
> 49 |
> 50 -kunmap_atomic(ptr);
> 51 )
> 52 ...>
> </script>
> _______________________________________________
> Cocci mailing list
> Cocci@systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci