From: "Toke Høiland-Jørgensen" <toke@redhat.com>
To: Alexei Starovoitov <ast@fb.com>,
Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Cc: "daniel\@iogearbox.net" <daniel@iogearbox.net>,
"bpf\@vger.kernel.org" <bpf@vger.kernel.org>,
"netdev\@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [PATCH bpf] xdp: Handle device unregister for devmap_hash map type
Date: Thu, 17 Oct 2019 17:40:22 +0200 [thread overview]
Message-ID: <871rvbfkih.fsf@toke.dk> (raw)
In-Reply-To: <d77bd569-eee2-b436-c575-9ff78bab4f1a@fb.com>
Alexei Starovoitov <ast@fb.com> writes:
> On 10/17/19 3:28 AM, Toke Høiland-Jørgensen wrote:
>> Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp> writes:
>>
>>> On 2019/10/16 22:28, Toke Høiland-Jørgensen wrote:
>>>> It seems I forgot to add handling of devmap_hash type maps to the device
>>>> unregister hook for devmaps. This omission causes devices to not be
>>>> properly released, which causes hangs.
>>>>
>>>> Fix this by adding the missing handler.
>>>>
>>>> Fixes: 6f9d451ab1a3 ("xdp: Add devmap_hash map type for looking up devices by hashed index")
>>>> Reported-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
>>>> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
>>>
>>> Well, regarding 6f9d451ab1a3, I think that we want explicit "(u64)" cast
>>>
>>> @@ -97,6 +123,14 @@ static int dev_map_init_map(struct bpf_dtab *dtab, union bpf_attr *attr)
>>> cost = (u64) dtab->map.max_entries * sizeof(struct bpf_dtab_netdev *);
>>> cost += sizeof(struct list_head) * num_possible_cpus();
>>>
>>> + if (attr->map_type == BPF_MAP_TYPE_DEVMAP_HASH) {
>>> + dtab->n_buckets = roundup_pow_of_two(dtab->map.max_entries);
>>> +
>>> + if (!dtab->n_buckets) /* Overflow check */
>>> + return -EINVAL;
>>> + cost += sizeof(struct hlist_head) * dtab->n_buckets;
>>>
>>> ^here
>>>
>>> + }
>>> +
>>> /* if map size is larger than memlock limit, reject it */
>>> err = bpf_map_charge_init(&dtab->map.memory, cost);
>>> if (err)
>>>
>>> like "(u64) dtab->map.max_entries * sizeof(struct bpf_dtab_netdev *)" does.
>>> Otherwise, on 32bits build, "sizeof(struct hlist_head) * dtab->n_buckets" can become 0.
>>
>> Oh, right. I kinda assumed the compiler would be smart enough to figure
>> that out based on the type of the LHS; will send a separate fix for this.
>
> compiler smart enough?! you must be kidding.
> It's a C standard. Compiler has to do 32 bit multiply because n_buckets
> is u32 and sizeof is 32 bit in 32bit arches as Tetsuo explained.
Sure, I can see that now that Tetsuo pointed it out (thanks for that,
BTW!).
I'm just saying that since it's being assigned to a u64, the fact that
the calculation is not automatically promoted to 64-bit is somewhat
unintuitive (to me), regardless of whether it's in the standard or not.
-Toke
next prev parent reply other threads:[~2019-10-17 15:40 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-16 13:28 [PATCH bpf] xdp: Handle device unregister for devmap_hash map type Toke Høiland-Jørgensen
2019-10-16 16:24 ` Martin Lau
2019-10-17 10:27 ` Toke Høiland-Jørgensen
2019-10-16 20:09 ` Tetsuo Handa
2019-10-17 10:28 ` Toke Høiland-Jørgensen
2019-10-17 15:23 ` Alexei Starovoitov
2019-10-17 15:40 ` Toke Høiland-Jørgensen [this message]
2019-10-17 19:17 ` Andrii Nakryiko
2019-10-18 10:31 ` Toke Høiland-Jørgensen
2019-10-18 16:28 ` Andrii Nakryiko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871rvbfkih.fsf@toke.dk \
--to=toke@redhat.com \
--cc=ast@fb.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=netdev@vger.kernel.org \
--cc=penguin-kernel@i-love.sakura.ne.jp \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.