lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Thu, 21 Sep 2017 09:13:21 -0400
From:   Craig Gallek <kraigatgoog@...il.com>
To:     Daniel Mack <daniel@...que.org>
Cc:     Alexei Starovoitov <ast@...com>,
        Daniel Borkmann <daniel@...earbox.net>,
        "David S . Miller" <davem@...emloft.net>,
        netdev <netdev@...r.kernel.org>
Subject: Re: [PATCH net-next] bpf: Optimize lpm trie delete

On Wed, Sep 20, 2017 at 6:56 PM, Daniel Mack <daniel@...que.org> wrote:
> On 09/20/2017 08:51 PM, Craig Gallek wrote:
>> On Wed, Sep 20, 2017 at 12:51 PM, Daniel Mack <daniel@...que.org> wrote:
>>> Hi Craig,
>>>
>>> Thanks, this looks much cleaner already :)
>>>
>>> On 09/20/2017 06:22 PM, Craig Gallek wrote:
>>>> diff --git a/kernel/bpf/lpm_trie.c b/kernel/bpf/lpm_trie.c
>>>> index 9d58a576b2ae..b5a7d70ec8b5 100644
>>>> --- a/kernel/bpf/lpm_trie.c
>>>> +++ b/kernel/bpf/lpm_trie.c
>>>> @@ -397,7 +397,7 @@ static int trie_delete_elem(struct bpf_map *map, void *_key)
>>>>       struct lpm_trie_node __rcu **trim;
>>>>       struct lpm_trie_node *node;
>>>>       unsigned long irq_flags;
>>>> -     unsigned int next_bit;
>>>> +     unsigned int next_bit = 0;
>>>
>>> This default assignment seems wrong, and I guess you only added it to
>>> squelch a compiler warning?
>> Yes, this variable is only initialized after the lookup iterations
>> below (meaning it will never be initialized the the root-removal
>> case).
>
> Right, and once set, it's only updated in case we don't have an exact
> match and try to drill down further.
>
>>> [...]
>>>
>>>> +     /* If the node has one child, we may be able to collapse the tree
>>>> +      * while removing this node if the node's child is in the same
>>>> +      * 'next bit' slot as this node was in its parent or if the node
>>>> +      * itself is the root.
>>>> +      */
>>>> +     if (trim == &trie->root) {
>>>> +             next_bit = node->child[0] ? 0 : 1;
>>>> +             rcu_assign_pointer(trie->root, node->child[next_bit]);
>>>> +             kfree_rcu(node, rcu);
>>>
>>> I don't think you should treat this 'root' case special.
>>>
>>> Instead, move the 'next_bit' assignment outside of the condition ...
>> I'm not quite sure I follow.  Are you saying do something like this:
>>
>> if (trim == &trie->root) {
>>   next_bit = node->child[0] ? 0 : 1;
>> }
>> if (rcu_access_pointer(node->child[next_bit])) {
>> ...
>>
>> This would save a couple lines of code, but I think the as-is
>> implementation is slightly easier to understand.  I don't have a
>> strong opinion either way, though.
>
> Me neither :)
>
> My idea was to set
>
>   next_bit = node->child[0] ? 0 : 1;
>
> unconditionally, because it should result in the same in both cases.
>
> It might be a bit of bike shedding, but I dislike this default
> assignment, and I believe that not relying on next_bit to be set as a
> side effect of the lookup loop makes the code a bit more readable.
>
> WDYT?
That sounds reasonable.  I'll spin a v2 today if no one else has any comments.

Thanks again,
Craig

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ