Subject: Re: [PATCH 1/7] xfrm: remove policy lock when accessing policy->walk.dead

From: Timo Teräs <[email-masked]>
Date: Tue, 30 Mar 2010 15:04:01 +0300

Herbert Xu wrote:
> On Tue, Mar 30, 2010 at 07:55:07AM +0300, Timo Teräs wrote:
>> Herbert Xu wrote:
>>> On Mon, Mar 29, 2010 at 05:12:38PM +0300, Timo Teras wrote:
>>>> @@ -1132,7 +1119,7 @@ int xfrm_sk_policy_insert(struct sock *sk, int dir, struct xfrm_policy *pol)
>>>>  		__xfrm_policy_link(pol, XFRM_POLICY_MAX+dir);
>>>>  	}
>>>>  	if (old_pol)
>>>> -		__xfrm_policy_unlink(old_pol, XFRM_POLICY_MAX+dir);
>>>> +		old_pol = __xfrm_policy_unlink(old_pol, XFRM_POLICY_MAX+dir);
>>>>  	write_unlock_bh(&xfrm_policy_lock);
>>>>   	if (old_pol) {
>>> So when can this actually fail?
>> Considering that the socket reference is received from the sk->sk_policy,
>> and the hash bucket we use is "XFRM_POLICY_MAX+dir", it's non-obvious if
>> it can fail or not.
>>
>> It would look like the timer can kill a policy and unlink it, but it
>> would still be found from sk_policy.
> 
> Socket policies cannot expire.

Was not aware of that. The above is not needed then.

> In fact, they probably shouldn't even be on the bydst or any other
> hash table.  I think the only reason they're there at all is because
> the hash table was added to __xfrm_policy_link which happens to be
> used by socket policies.

I think it's hashed so socket policies are included in the policy
db dumps and counts.