From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED003C67871 for ; Fri, 13 Jan 2023 01:53:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238392AbjAMBx3 (ORCPT ); Thu, 12 Jan 2023 20:53:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240644AbjAMBx1 (ORCPT ); Thu, 12 Jan 2023 20:53:27 -0500 Received: from out-193.mta0.migadu.com (out-193.mta0.migadu.com [91.218.175.193]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7583A61445 for ; Thu, 12 Jan 2023 17:53:25 -0800 (PST) Message-ID: <7e6d02ea-f9f7-2d09-bf10-ccd41b16a671@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1673574803; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=33Ku8g/h4myxf2UTWuqY4sRCItNB1UVhMBs8WSvSEuE=; b=mCwR0Vm4mZ1nqSGgqju1K3rW340ihXvH6LXcqGEMqxa2ZXTrepriGReeuYvzoyZICi6plY 5yclT87TQ9Gp4XoUk8lUfzLS8Su9YLPqsNKDCkv42PmzoDvZzy1U6JdngVUiKy0pJhI0hH e9ltXYPXk1wv8XXKSGGT4BC2k9Ew0uQ= Date: Thu, 12 Jan 2023 17:53:18 -0800 MIME-Version: 1.0 Subject: Re: [bpf-next v5 3/3] bpf: hash map, suppress false lockdep warning To: tong@infragraf.org, Alexei Starovoitov Cc: Daniel Borkmann , Andrii Nakryiko , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Hou Tao , bpf@vger.kernel.org References: <20230111092903.92389-1-tong@infragraf.org> <20230111092903.92389-3-tong@infragraf.org> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Martin KaFai Lau In-Reply-To: <20230111092903.92389-3-tong@infragraf.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.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(); > }