Subject: Re: [net-next PATCH v2 02/15] net: rcu-ify tcf_proto

From: John Fastabend <[email-masked]>
Date: Mon, 01 Sep 2014 18:39:13 -0700

On 08/24/2014 10:31 PM, David Miller wrote:
> From: John Fastabend <[email-masked]>
> Date: Sun, 24 Aug 2014 17:48:31 -0700
>
>> @@ -722,8 +724,9 @@ static void sfq_free(void *addr)
>>   static void sfq_destroy(struct Qdisc *sch)
>>   {
>>   	struct sfq_sched_data *q = qdisc_priv(sch);
>> +	struct tcf_proto *fl = rtnl_dereference(q->filter_list);
>>
>> -	tcf_destroy_chain(&q->filter_list);
>> +	tcf_destroy_chain(&fl);

Sorry for the delayed reply...

>
> This will cause tcf_destroy_chain() to set the local variable
> 'fl' to NULL rather than q->filter_list.
>
> I don't see how this can be correct at all.

Right now (without these patches) nothing sets q->filter_list
to NULL and we only call this when the qdisc is being destroyed.
In all cases there is a rcu_assign_pointer() to detach the qdisc
from the netdev_queue followed by a synchronize_net().

	dev_deactivate_many
	   [...]
	   dev_deactivate_queue
		rcu_assign_pointer(dev_queue->qdisc, qdisc_default)

  	   [...]
	   synchronize_net()

After the synchronize_net there should be no other references
to q->filter_list other then in the destroy path so I think it
works and the rtnl_dereference in my patch is there for annotation
to make sparse happy but doesn't change the logic.

Does that make sense?

>
> You need to make tcf_destroy_chain() take a pointer to an __rcu
> pointer, and do the proper dereferencing and RCU assignments in
> that chain destroy loop.
>
> This might be why you're getting annotation warnings.
>

The annotation warnings comes from the find_tcf blocks for example
here is the block in the sfq scheduler,

     struct sfq_sched_data *q = qdisc_priv(sch);

     if (cl)
         return NULL;
     return &q->filter_list;

This is called inside the rtnl lock but filter list is rcu protected
fixing the function types like this seems to resolve it,

     static struct tcf_proto * __rcu *sfq_find_tcf(struct Qdisc *sch, 
unsigned long cl)

and similarly the ops struct,

     struct tcf_proto * __rcu * (*tcf_chain)(struct Qdisc *, unsigned long);

This fixes the sparse warnings and looks correct to me. I'll send
an update with these fixes.

Thanks!
John

-- 
John Fastabend         Intel Corporation