2019-09-24 17:01:21

by Valentin Schneider

[permalink] [raw]
Subject: Re: sched: make struct task_struct::state 32-bit

On 23/09/2019 11:34, Julia Lawall wrote:
>> // FIXME: current not recognized as task_struct*, fixhack with regexp
>> identifier current =~ "^current$";
>
> Please don't do this. Just use the word current. It doesn't have to be a
> metavariable. You will though get a warning about it. To eliminate the
> warning, you can say symbol current;
>

Didn't know about that way to get rid of the warning, thanks!

>> identifier task_state =~ "^TASK_";
>
> Are there a lot of options? You can also enumerate them in {}, ie
>
> identifier task_state = {TASK_BLAH, TASK_BLAHBLAH};
>

Around a dozen, can be enumerated easily and is indeed probably better than
a regexp.

>> identifier state_var;
>> position pos;
>> @@
>>
>> (
>> p->state & state_var@pos
>> |
>> current->state & state_var@pos
>> |
>> p->state | state_var@pos
>> |
>> current->state | state_var@pos
>> |
>> p->state < state_var@pos
>> |
>> current->state < state_var@pos
>> |
>> p->state > state_var@pos
>> |
>> current->state > state_var@pos
>> |
>> state_var@pos = p->state
>> |
>> state_var@pos = current->state
>> |
>> p->state == state_var@pos
>> |
>> current->state == state_var@pos
>> |
>> p->state != state_var@pos
>> |
>> current->state != state_var@pos
>> |
>> // FIXME: match functions that do something with state_var underneath?
>> // How to do recursive rules?
>
> You want to look at the definitions of called functions? Coccinelle
> doesn't really support that, but there are hackish ways to add that. How
> many function calls would you expect have to be unrolled?
>

I wouldn't expect more than a handful (~5). I suppose this has to do with
injecting some Python/Ocaml code? I have some examples bookmarked but
haven't gotten to stare at them long enough.

>> set_current_state(state_var@pos)
>> |
>> set_special_state(state_var@pos)
>> |
>> signal_pending_state(state_var@pos, p)
>> |
>> signal_pending_state(state_var@pos, current)
>> |
>> state_var@pos & task_state
>> |
>> state_var@pos | task_state
>> )
>>
>> // Fixup local variables
>> @depends on patch && state_access@
>> identifier state_var = state_access.state_var;
>> @@
>> (
>> - long
>> + int
>> |
>> - unsigned long
>> + unsigned int
>> )
>> state_var;
>>
>> // Fixup function parameters
>> @depends on patch && state_access@
>> identifier fn;
>> identifier state_var = state_access.state_var;
>> @@
>>
>> fn(...,
>> - long state_var
>> + int state_var
>> ,...)
>> {
>> ...
>> }
>>
>> // FIXME: find a way to squash that with the above?
>
> I think that you can make a disjunction on a function parameter
>
> fn(...,
> (
> - T1 x1
> + T2 x2
> |
> - T3 x3
> + T4 x4
> )
> , ...) { ... }
>

My attempt at this gives me "minus: parse error", which is why I went
with the split.

Something simple like this works:
---
virtual patch
virtual report

@@
identifier fn;
identifier p;
@@

fn(...,
- long
+ int
p
,...)
{
...
}
---

but this doesn't:
---
virtual patch
virtual report

@@
identifier fn;
identifier p;
@@

fn(...,
(
- long p
+ int p
|
- unsigned long p
+ unsigned int p
)
,...)
{
...
}
---

> julia
>


2019-09-25 12:15:41

by Julia Lawall

[permalink] [raw]
Subject: Re: sched: make struct task_struct::state 32-bit

> >> // FIXME: match functions that do something with state_var underneath?
> >> // How to do recursive rules?
> >
> > You want to look at the definitions of called functions? Coccinelle
> > doesn't really support that, but there are hackish ways to add that. How
> > many function calls would you expect have to be unrolled?
> >
>
> I wouldn't expect more than a handful (~5). I suppose this has to do with
> injecting some Python/Ocaml code? I have some examples bookmarked but
> haven't gotten to stare at them long enough.

You can look at iteration.cocci, but it's a bit complex.

You could match definitions of functions that do what you are interested
in, then store the names of these functions in a list (python/ocaml), and
then look for calls to those functions. Something like

identifier fn : script:ocaml() { in_my_list fn };

> >> // Fixup local variables
> >> @depends on patch && state_access@
> >> identifier state_var = state_access.state_var;
> >> @@
> >> (
> >> - long
> >> + int
> >> |
> >> - unsigned long
> >> + unsigned int
> >> )
> >> state_var;
> >>
> >> // Fixup function parameters
> >> @depends on patch && state_access@
> >> identifier fn;
> >> identifier state_var = state_access.state_var;
> >> @@
> >>
> >> fn(...,
> >> - long state_var
> >> + int state_var
> >> ,...)
> >> {
> >> ...
> >> }
> >>
> >> // FIXME: find a way to squash that with the above?
> >
> > I think that you can make a disjunction on a function parameter
> >
> > fn(...,
> > (
> > - T1 x1
> > + T2 x2
> > |
> > - T3 x3
> > + T4 x4
> > )
> > , ...) { ... }
> >
>
> My attempt at this gives me "minus: parse error", which is why I went
> with the split.

OK, the split is probably not a major catastrophe...

julia

>
> Something simple like this works:
> ---
> virtual patch
> virtual report
>
> @@
> identifier fn;
> identifier p;
> @@
>
> fn(...,
> - long
> + int
> p
> ,...)
> {
> ...
> }
> ---
>
> but this doesn't:
> ---
> virtual patch
> virtual report
>
> @@
> identifier fn;
> identifier p;
> @@
>
> fn(...,
> (
> - long p
> + int p
> |
> - unsigned long p
> + unsigned int p
> )
> ,...)
> {
> ...
> }
> ---
>
> > julia
> >
>

2019-09-26 07:59:07

by Markus Elfring

[permalink] [raw]
Subject: Re: sched: make struct task_struct::state 32-bit

>>> identifier task_state =~ "^TASK_";
>>
>> Are there a lot of options? You can also enumerate them in {}, ie
>>
>> identifier task_state = {TASK_BLAH, TASK_BLAHBLAH};
>
> Around a dozen, can be enumerated easily and is indeed probably better than
> a regexp.

Can the application of a regular expression be more convenient
for such an use case?


>> You want to look at the definitions of called functions?
>> Coccinelle doesn't really support that,

I got an other impression.


>> but there are hackish ways to add that.

How do you think about to discuss corresponding software development challenges?

Regards,
Markus