From: Martin KaFai Lau <martin.lau@linux.dev>
To: tong@infragraf.org, Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>, Song Liu <song@kernel.org>,
Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>, Hou Tao <houtao1@huawei.com>,
bpf@vger.kernel.org
Subject: Re: [bpf-next v5 3/3] bpf: hash map, suppress false lockdep warning
Date: Thu, 12 Jan 2023 17:53:18 -0800 [thread overview]
Message-ID: <7e6d02ea-f9f7-2d09-bf10-ccd41b16a671@linux.dev> (raw)
In-Reply-To: <20230111092903.92389-3-tong@infragraf.org>
On 1/11/23 1:29 AM, tong@infragraf.org wrote:
> + /*
> + * The lock may be taken in both NMI and non-NMI contexts.
> + * There is a false lockdep warning (inconsistent lock state),
> + * if lockdep enabled. The potential deadlock happens when the
> + * lock is contended from the same cpu. map_locked rejects
> + * concurrent access to the same bucket from the same CPU.
> + * When the lock is contended from a remote cpu, we would
> + * like the remote cpu to spin and wait, instead of giving
> + * up immediately. As this gives better throughput. So replacing
> + * the current raw_spin_lock_irqsave() with trylock sacrifices
> + * this performance gain. atomic map_locked is necessary.
> + * lockdep_off is invoked temporarily to fix the false warning.
> + */
> + lockdep_off();
> raw_spin_lock_irqsave(&b->raw_lock, flags);
> - *pflags = flags;
> + lockdep_on();
I am not very sure about the lockdep_off/on. Other than the false warning when
using the very same htab map by both NMI and non-NMI context, I think the
lockdep will still be useful to catch other potential issues. The commit
c50eb518e262 ("bpf: Use separate lockdep class for each hashtab") has already
solved this false alarm when NMI happens on one map and non-NMI happens on
another map.
Alexei, what do you think? May be only land the patch 1 fix for now.
>
> + *pflags = flags;
> return 0;
> }
>
> @@ -172,7 +187,11 @@ static inline void htab_unlock_bucket(const struct bpf_htab *htab,
> unsigned long flags)
> {
> hash = hash & min_t(u32, HASHTAB_MAP_LOCK_MASK, htab->n_buckets - 1);
> +
> + lockdep_off();
> raw_spin_unlock_irqrestore(&b->raw_lock, flags);
> + lockdep_on();
> +
> __this_cpu_dec(*(htab->map_locked[hash]));
> preempt_enable();
> }
next prev parent reply other threads:[~2023-01-13 1:53 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-11 9:29 [bpf-next v5 1/3] bpf: hash map, avoid deadlock with suitable hash mask tong
2023-01-11 9:29 ` [bpf-next v5 2/3] selftests/bpf: add test case for htab map tong
2023-01-11 9:29 ` [bpf-next v5 3/3] bpf: hash map, suppress false lockdep warning tong
2023-01-13 1:53 ` Martin KaFai Lau [this message]
2023-01-13 2:03 ` Alexei Starovoitov
2023-01-13 2:17 ` Tonghao Zhang
2023-01-13 5:14 ` Martin KaFai Lau
2023-01-13 9:15 ` Tonghao Zhang
2023-01-15 22:51 ` Martin KaFai Lau
2023-02-01 7:12 ` Hou Tao
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=7e6d02ea-f9f7-2d09-bf10-ccd41b16a671@linux.dev \
--to=martin.lau@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=houtao1@huawei.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=tong@infragraf.org \
--cc=yhs@fb.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox