Subject: Re: [RCU PATCH 06/14] net: sched: fw use RCU

From: John Fastabend <[email-masked]>
Date: Wed, 12 Mar 2014 09:41:35 -0700

On 03/10/2014 10:41 AM, Eric Dumazet wrote:
> On Mon, 2014-03-10 at 10:05 -0700, John Fastabend wrote:
>> RCU'ify fw classifier.
>>
>> Signed-off-by: John Fastabend <[email-masked]>
>> ---
>>   net/sched/cls_fw.c |  110 ++++++++++++++++++++++++++++++++++++----------------
>>   1 file changed, 76 insertions(+), 34 deletions(-)
>>
>> diff --git a/net/sched/cls_fw.c b/net/sched/cls_fw.c
>> index a366537..ff392f1 100644
>> --- a/net/sched/cls_fw.c
>> +++ b/net/sched/cls_fw.c
>> @@ -32,18 +32,21 @@
>>   #define HTSIZE (PAGE_SIZE/sizeof(struct fw_filter *))
>>
>>   struct fw_head {
>> -	struct fw_filter *ht[HTSIZE];
>> +	struct rcu_head	rcu;
>
> Try to put 'rcu' at the end of structures, we do not need it in fast
> path.
>
>> +	struct fw_filter __rcu *ht[HTSIZE];
>>   	u32 mask;
>>   };
>>
>>   struct fw_filter {
>> -	struct fw_filter	*next;
>> +	struct fw_filter __rcu	*next;
>> +	struct rcu_head		rcu;
>
> same remark
>

[...]

>>
>> @@ -150,29 +159,32 @@ static void fw_destroy(struct tcf_proto *tp)
>>   		return;
>>
>>   	for (h = 0; h < HTSIZE; h++) {
>> -		while ((f = head->ht[h]) != NULL) {
>> -			head->ht[h] = f->next;
>> -			fw_delete_filter(tp, f);
>> +		while ((f = rtnl_dereference(head->ht[h])) != NULL) {
>> +			rcu_assign_pointer(head->ht[h],
>> +					   rtnl_dereference(f->next));
>> +			call_rcu(&f->rcu, fw_delete_filter);
>>   		}
>>   	}
>> -	kfree(head);
>> +	rcu_assign_pointer(tp->root, NULL);
>
> RCU_INIT_POINTER
>
>> +	kfree_rcu(head, rcu);

Rearranging the rcu_head placement above results in this error:

net/sched/cls_fw.c: In function ‘fw_destroy’:
net/sched/cls_fw.c:169:279: error: call to ‘__compiletime_assert_169’ 
declared with attribute error: BUILD_BUG_ON failed: 
!__is_kfree_rcu_offset(__builtin_offsetof(typeof(*(head)),rcu))

However it seems best to have the rcu_head at the end of the struct
so I'll just convert the kfree_rcu() to call_rcu().

Thanks,
John

-- 
John Fastabend         Intel Corporation