From patchwork Tue Jun 15 14:54:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 12322069 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF261C49361 for ; Tue, 15 Jun 2021 14:55:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8E20F615FF for ; Tue, 15 Jun 2021 14:55:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231373AbhFOO5R (ORCPT ); Tue, 15 Jun 2021 10:57:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26572 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231389AbhFOO5N (ORCPT ); Tue, 15 Jun 2021 10:57:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623768908; 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=Gxp4+onf8wuO87Iii4KRL2PGeBHDLINdkwBz3RXDQ8I=; b=Ork+8lDa6MW/38/iou6InCKIfEPEYF/Qs15sPeNrKfKQeHwF07OKJZJORDe12y+5x4f6XI pXm3wf84Ls70UEjutIU4UbbvEyJn0j5hL1g5ossy0TDbKINfy3Muc4CaHvHJVBL61kIB+5 KG6hFYUo8Y5VTJ14idX8Pe5NHWSCyYg= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-446-lfc0S7EhN5y7--uqcqeNSA-1; Tue, 15 Jun 2021 10:55:06 -0400 X-MC-Unique: lfc0S7EhN5y7--uqcqeNSA-1 Received: by mail-ej1-f71.google.com with SMTP id am5-20020a1709065685b02903eef334e563so4669267ejc.2 for ; Tue, 15 Jun 2021 07:55:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Gxp4+onf8wuO87Iii4KRL2PGeBHDLINdkwBz3RXDQ8I=; b=XO2+eW6RGHCCk0Ko0YXKh1i2xJ1f67w1TljA9R3OVNA3qOWELtv1uXx074PNskqa/Z B/S2S8VECwyJRAQMl+ry36EJsUWBL431IwJqyelWmPftGZNllBiOyZAzHzdTsLgMwKu3 e/fRYHmYbrnixsJW/NsPNosN65RrJKVQbjNvNpiwmFLIA3FWTMu94NAywam6oO6x9Qxo HMOnINY5TyyTlZ5megCWUz5kkQUf+Mgt4/6Ym7CR4G71xvzLStisT+4SBHWubPx5PHyt s3LArz9rtFwtQNgmoxWB4Uj/hCpRKk94dEwBRHzdMoZVeyjb9+rkcGW18Nn+R2XsuqMh Vudw== X-Gm-Message-State: AOAM533qf79obHL3wxYm8ROfOSQVecmb9zOn+KooKVcwyHh5JL9N4YiQ gbMjZ9aoEL3Trp/gFaPrZy+KL++YqiOEp7+N5M/SanvX3rWl6GfP3qF9cEC6vT6Xc1lVyBQLRvu VI+9BDGB+lT+A X-Received: by 2002:a50:b2c5:: with SMTP id p63mr10055611edd.5.1623768905657; Tue, 15 Jun 2021 07:55:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/YwZa9hwA5T/K0ZvJNmG1D6JAT7VKQUI+n0jma5WK9p1jIeM6YWlaebazh4ioDqp7gZhVVw== X-Received: by 2002:a50:b2c5:: with SMTP id p63mr10055582edd.5.1623768905390; Tue, 15 Jun 2021 07:55:05 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id ci12sm10333745ejc.17.2021.06.15.07.55.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 07:55:04 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id A7CD31802AB; Tue, 15 Jun 2021 16:54:58 +0200 (CEST) From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: bpf@vger.kernel.org, netdev@vger.kernel.org Cc: Martin KaFai Lau , Hangbin Liu , Jesper Dangaard Brouer , Magnus Karlsson , "Paul E . McKenney" , Jakub Kicinski , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= Subject: [PATCH bpf-next v2 01/16] rcu: Create an unrcu_pointer() to remove __rcu from a pointer Date: Tue, 15 Jun 2021 16:54:40 +0200 Message-Id: <20210615145455.564037-2-toke@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615145455.564037-1-toke@redhat.com> References: <20210615145455.564037-1-toke@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: "Paul E. McKenney" The xchg() and cmpxchg() functions are sometimes used to carry out RCU updates. Unfortunately, this can result in sparse warnings for both the old-value and new-value arguments, as well as for the return value. The arguments can be dealt with using RCU_INITIALIZER(): old_p = xchg(&p, RCU_INITIALIZER(new_p)); But a sparse warning still remains due to assigning the __rcu pointer returned from xchg to the (most likely) non-__rcu pointer old_p. This commit therefore provides an unrcu_pointer() macro that strips the __rcu. This macro can be used as follows: old_p = unrcu_pointer(xchg(&p, RCU_INITIALIZER(new_p))); Reported-by: Toke Høiland-Jørgensen Signed-off-by: Paul E. McKenney Signed-off-by: Toke Høiland-Jørgensen --- include/linux/rcupdate.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h index 9455476c5ba2..d7895b81264e 100644 --- a/include/linux/rcupdate.h +++ b/include/linux/rcupdate.h @@ -363,6 +363,20 @@ static inline void rcu_preempt_sleep_check(void) { } #define rcu_check_sparse(p, space) #endif /* #else #ifdef __CHECKER__ */ +/** + * unrcu_pointer - mark a pointer as not being RCU protected + * @p: pointer needing to lose its __rcu property + * + * Converts @p from an __rcu pointer to a __kernel pointer. + * This allows an __rcu pointer to be used with xchg() and friends. + */ +#define unrcu_pointer(p) \ +({ \ + typeof(*p) *_________p1 = (typeof(*p) *__force)(p); \ + rcu_check_sparse(p, __rcu); \ + ((typeof(*p) __force __kernel *)(_________p1)); \ +}) + #define __rcu_access_pointer(p, space) \ ({ \ typeof(*p) *_________p1 = (typeof(*p) *__force)READ_ONCE(p); \ From patchwork Tue Jun 15 14:54:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 12322065 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4EE6CC48BDF for ; Tue, 15 Jun 2021 14:55:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2981561607 for ; Tue, 15 Jun 2021 14:55:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230316AbhFOO5I (ORCPT ); Tue, 15 Jun 2021 10:57:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:55848 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230463AbhFOO5I (ORCPT ); Tue, 15 Jun 2021 10:57:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623768903; 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=O7x1L+dGKzGzPnS3B1FXOo9UcWggJw8efdJQ5vHdEjA=; b=G4/qoXrBNG1WO2/A/q7EZTBHy2J0Dn+9YRRMtslpVuRdelwBUXjCngG5SMavV3CJ6zz8RK JyKEphKbfxakjOOFSSL5L5RYfdpf6FkNpz6TcMu1kSaXLuJMtmnpboqkPvCZdQM7E2Mg2M VM5qd5MBhFxewVtcSgrh8PDgUKergRw= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-428-GRkK-xwlPxWmq0IPUPoCUA-1; Tue, 15 Jun 2021 10:55:01 -0400 X-MC-Unique: GRkK-xwlPxWmq0IPUPoCUA-1 Received: by mail-ej1-f72.google.com with SMTP id o6-20020a1709063586b0290454e77502aeso2976234ejb.12 for ; Tue, 15 Jun 2021 07:55:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O7x1L+dGKzGzPnS3B1FXOo9UcWggJw8efdJQ5vHdEjA=; b=c6Lh+wfJXLDtn0X3dqXrEHZpzogcb8EhuwWRmR0WU/243WuSHQJfsjFnvJ7Z801OE4 IM5gO47i/eAdV38T8fyHnEKWcUREU96QdHSCwQBsAHOT5ahUBnBlpPnE+q/kGrH/36F9 jRt17g1tM3msa0sSxIWAmDPaxyQpbtbCQPut2zbmzd4/Xs8+uX8ZGQfWijrYd5I0uMXS wk0W15qTtB+/LlIZOOB7quTK0jA+Uq5TyXnQv9Kg3rNUbRtu0JeS3Kxwfq6/RtPxAn0i 3u4orJBfQy7/+Wxm3SNY5L+/vDdEu2fh2spVVqeRkEpRPAfAFhbtRbIeYRi9yaKOAUlh CZuA== X-Gm-Message-State: AOAM533tUpjFJD4wvk24vZHSPf/Ms6WOirDi2ZwkGrwHPCc0LK2uy/lW rPE3L94t2BIxZ6vnH95ELT9T3NbG4pG27rKCtVtB9KxdndwtJ7keOvWYBVofvz06yBDU5Mo5Y1x XNKuQeyHR14Q+ X-Received: by 2002:a17:907:1112:: with SMTP id qu18mr20732913ejb.511.1623768900623; Tue, 15 Jun 2021 07:55:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwUzxRQhszo2M42VjxXsXMwjyaZl5AHh/Jsq0Yk7slqSERlytMPN1+GuQqDhyZCaNH16JCAXw== X-Received: by 2002:a17:907:1112:: with SMTP id qu18mr20732899ejb.511.1623768900443; Tue, 15 Jun 2021 07:55:00 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id j22sm9961625eje.123.2021.06.15.07.54.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 07:54:59 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id AF6C01802C6; Tue, 15 Jun 2021 16:54:58 +0200 (CEST) From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: bpf@vger.kernel.org, netdev@vger.kernel.org Cc: Martin KaFai Lau , Hangbin Liu , Jesper Dangaard Brouer , Magnus Karlsson , "Paul E . McKenney" , Jakub Kicinski , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= Subject: [PATCH bpf-next v2 02/16] bpf: allow RCU-protected lookups to happen from bh context Date: Tue, 15 Jun 2021 16:54:41 +0200 Message-Id: <20210615145455.564037-3-toke@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615145455.564037-1-toke@redhat.com> References: <20210615145455.564037-1-toke@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net XDP programs are called from a NAPI poll context, which means the RCU reference liveness is ensured by local_bh_disable(). Add rcu_read_lock_bh_held() as a condition to the RCU checks for map lookups so lockdep understands that the dereferences are safe from inside *either* an rcu_read_lock() section *or* a local_bh_disable() section. While both bh_disabled and rcu_read_lock() provide RCU protection, they are semantically distinct, so we need both conditions to prevent lockdep complaints. This change is done in preparation for removing the redundant rcu_read_lock()s from drivers. Acked-by: Martin KaFai Lau Signed-off-by: Toke Høiland-Jørgensen --- kernel/bpf/hashtab.c | 21 ++++++++++++++------- kernel/bpf/helpers.c | 6 +++--- kernel/bpf/lpm_trie.c | 6 ++++-- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c index 6f6681b07364..72c58cc516a3 100644 --- a/kernel/bpf/hashtab.c +++ b/kernel/bpf/hashtab.c @@ -596,7 +596,8 @@ static void *__htab_map_lookup_elem(struct bpf_map *map, void *key) struct htab_elem *l; u32 hash, key_size; - WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held()); + WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held() && + !rcu_read_lock_bh_held()); key_size = map->key_size; @@ -989,7 +990,8 @@ static int htab_map_update_elem(struct bpf_map *map, void *key, void *value, /* unknown flags */ return -EINVAL; - WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held()); + WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held() && + !rcu_read_lock_bh_held()); key_size = map->key_size; @@ -1082,7 +1084,8 @@ static int htab_lru_map_update_elem(struct bpf_map *map, void *key, void *value, /* unknown flags */ return -EINVAL; - WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held()); + WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held() && + !rcu_read_lock_bh_held()); key_size = map->key_size; @@ -1148,7 +1151,8 @@ static int __htab_percpu_map_update_elem(struct bpf_map *map, void *key, /* unknown flags */ return -EINVAL; - WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held()); + WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held() && + !rcu_read_lock_bh_held()); key_size = map->key_size; @@ -1202,7 +1206,8 @@ static int __htab_lru_percpu_map_update_elem(struct bpf_map *map, void *key, /* unknown flags */ return -EINVAL; - WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held()); + WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held() && + !rcu_read_lock_bh_held()); key_size = map->key_size; @@ -1276,7 +1281,8 @@ static int htab_map_delete_elem(struct bpf_map *map, void *key) u32 hash, key_size; int ret; - WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held()); + WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held() && + !rcu_read_lock_bh_held()); key_size = map->key_size; @@ -1311,7 +1317,8 @@ static int htab_lru_map_delete_elem(struct bpf_map *map, void *key) u32 hash, key_size; int ret; - WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held()); + WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held() && + !rcu_read_lock_bh_held()); key_size = map->key_size; diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index 544773970dbc..e880f6bb6f28 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -28,7 +28,7 @@ */ BPF_CALL_2(bpf_map_lookup_elem, struct bpf_map *, map, void *, key) { - WARN_ON_ONCE(!rcu_read_lock_held()); + WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_bh_held()); return (unsigned long) map->ops->map_lookup_elem(map, key); } @@ -44,7 +44,7 @@ const struct bpf_func_proto bpf_map_lookup_elem_proto = { BPF_CALL_4(bpf_map_update_elem, struct bpf_map *, map, void *, key, void *, value, u64, flags) { - WARN_ON_ONCE(!rcu_read_lock_held()); + WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_bh_held()); return map->ops->map_update_elem(map, key, value, flags); } @@ -61,7 +61,7 @@ const struct bpf_func_proto bpf_map_update_elem_proto = { BPF_CALL_2(bpf_map_delete_elem, struct bpf_map *, map, void *, key) { - WARN_ON_ONCE(!rcu_read_lock_held()); + WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_bh_held()); return map->ops->map_delete_elem(map, key); } diff --git a/kernel/bpf/lpm_trie.c b/kernel/bpf/lpm_trie.c index 1b7b8a6f34ee..423549d2c52e 100644 --- a/kernel/bpf/lpm_trie.c +++ b/kernel/bpf/lpm_trie.c @@ -232,7 +232,8 @@ static void *trie_lookup_elem(struct bpf_map *map, void *_key) /* Start walking the trie from the root node ... */ - for (node = rcu_dereference(trie->root); node;) { + for (node = rcu_dereference_check(trie->root, rcu_read_lock_bh_held()); + node;) { unsigned int next_bit; size_t matchlen; @@ -264,7 +265,8 @@ static void *trie_lookup_elem(struct bpf_map *map, void *_key) * traverse down. */ next_bit = extract_bit(key->data, node->prefixlen); - node = rcu_dereference(node->child[next_bit]); + node = rcu_dereference_check(node->child[next_bit], + rcu_read_lock_bh_held()); } if (!found) From patchwork Tue Jun 15 14:54:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 12322079 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D30E5C49EA6 for ; Tue, 15 Jun 2021 14:55:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BAB546161C for ; Tue, 15 Jun 2021 14:55:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231510AbhFOO5T (ORCPT ); Tue, 15 Jun 2021 10:57:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:34818 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231468AbhFOO5Q (ORCPT ); Tue, 15 Jun 2021 10:57:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623768911; 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=XauQxIidgZWqKYwupDfOjsOZffqWyiEa+6VH4Dkvxc8=; b=d3OKHLuEWpev/xhdDEjjzpeKzQDTx0r7QCaqk5nTZastKBgeZWY7Vp4NDISnSzKHJFlvwl odnjhTT5RND1gsdVyVXC5Uz5npeVeaU85YOcs7ml3GjyteNVuNjD1JQ5BOsWbsMrqe3JjS QgEYCj43j2sYD6aSjgV2Io5qUxXsHFs= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-42-fbjGHs6NOuGLL4BoE-GEEg-1; Tue, 15 Jun 2021 10:55:04 -0400 X-MC-Unique: fbjGHs6NOuGLL4BoE-GEEg-1 Received: by mail-ed1-f72.google.com with SMTP id v8-20020a0564023488b0290393873961f6so15026203edc.17 for ; Tue, 15 Jun 2021 07:55:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XauQxIidgZWqKYwupDfOjsOZffqWyiEa+6VH4Dkvxc8=; b=MQBCRmUvjsdY6xwNKz/IsriMrILtdqaslDV59wRoXKqursyd+x4LZGOmlNES/gxu5D PGSJDYZ1LuHOJA3LsjkHjgc6ku0wIRxBClWOTrePIuDy46kW+boCw0b1mUf2h1R5Miqb VHpRAgSYCsg5DmTXLdOQDTM8tYU8eMz1fUrsoRxVXmUB+UKxXH2Qud9bt+tFBNmpWEK+ TtpbTpgejuSiTFqW/ZctUb39IgrlOj+uAY2M3+tJz8jopHijPz8VH+DXFhEuL3de3h2E H6NlDfbOfC3arRttd9OJg8upm4frRr0cl482Iq2EPA5T4tsFUnqyIIOod3B3hs9AWELh +HTg== X-Gm-Message-State: AOAM530T4rph25PZTvyMgTdi4/2yG+tFsGK2zx+q9cK4gTb3cMlCW/6M r6XqDBEfTyFCd8wKXr8Nweeo4UIOJeN3ac8/8kAYh6uWjRbi4nTwP5mQADDPCXUPJ7hDC0IwLKV T2rutLkJv06ae X-Received: by 2002:a05:6402:4c5:: with SMTP id n5mr23639462edw.322.1623768900951; Tue, 15 Jun 2021 07:55:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+UVP8pxC8w7iB/YuB9hqs/WlODKOZA/Y8SXwOER+whNMJCEFEtE059xFN1e1YScbbjgXvLQ== X-Received: by 2002:a05:6402:4c5:: with SMTP id n5mr23639436edw.322.1623768900673; Tue, 15 Jun 2021 07:55:00 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id t5sm10267139eje.29.2021.06.15.07.54.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 07:54:59 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id B4D5C1802FF; Tue, 15 Jun 2021 16:54:58 +0200 (CEST) From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: bpf@vger.kernel.org, netdev@vger.kernel.org Cc: Martin KaFai Lau , Hangbin Liu , Jesper Dangaard Brouer , Magnus Karlsson , "Paul E . McKenney" , Jakub Kicinski , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= Subject: [PATCH bpf-next v2 03/16] xdp: add proper __rcu annotations to redirect map entries Date: Tue, 15 Jun 2021 16:54:42 +0200 Message-Id: <20210615145455.564037-4-toke@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615145455.564037-1-toke@redhat.com> References: <20210615145455.564037-1-toke@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net XDP_REDIRECT works by a three-step process: the bpf_redirect() and bpf_redirect_map() helpers will lookup the target of the redirect and store it (along with some other metadata) in a per-CPU struct bpf_redirect_info. Next, when the program returns the XDP_REDIRECT return code, the driver will call xdp_do_redirect() which will use the information thus stored to actually enqueue the frame into a bulk queue structure (that differs slightly by map type, but shares the same principle). Finally, before exiting its NAPI poll loop, the driver will call xdp_do_flush(), which will flush all the different bulk queues, thus completing the redirect. Pointers to the map entries will be kept around for this whole sequence of steps, protected by RCU. However, there is no top-level rcu_read_lock() in the core code; instead drivers add their own rcu_read_lock() around the XDP portions of the code, but somewhat inconsistently as Martin discovered[0]. However, things still work because everything happens inside a single NAPI poll sequence, which means it's between a pair of calls to local_bh_disable()/local_bh_enable(). So Paul suggested[1] that we could document this intention by using rcu_dereference_check() with rcu_read_lock_bh_held() as a second parameter, thus allowing sparse and lockdep to verify that everything is done correctly. This patch does just that: we add an __rcu annotation to the map entry pointers and remove the various comments explaining the NAPI poll assurance strewn through devmap.c in favour of a longer explanation in filter.c. The goal is to have one coherent documentation of the entire flow, and rely on the RCU annotations as a "standard" way of communicating the flow in the map code (which can additionally be understood by sparse and lockdep). The RCU annotation replacements result in a fairly straight-forward replacement where READ_ONCE() becomes rcu_dereference_check(), WRITE_ONCE() becomes rcu_assign_pointer() and xchg() and cmpxchg() gets wrapped in the proper constructs to cast the pointer back and forth between __rcu and __kernel address space (for the benefit of sparse). The one complication is that xskmap has a few constructions where double-pointers are passed back and forth; these simply all gain __rcu annotations, and only the final reference/dereference to the inner-most pointer gets changed. With this, everything can be run through sparse without eliciting complaints, and lockdep can verify correctness even without the use of rcu_read_lock() in the drivers. Subsequent patches will clean these up from the drivers. [0] https://lore.kernel.org/bpf/20210415173551.7ma4slcbqeyiba2r@kafai-mbp.dhcp.thefacebook.com/ [1] https://lore.kernel.org/bpf/20210419165837.GA975577@paulmck-ThinkPad-P17-Gen-1/ Signed-off-by: Toke Høiland-Jørgensen --- include/net/xdp_sock.h | 2 +- kernel/bpf/cpumap.c | 13 +++++++---- kernel/bpf/devmap.c | 52 +++++++++++++++++++----------------------- net/core/filter.c | 28 +++++++++++++++++++++++ net/xdp/xsk.c | 4 ++-- net/xdp/xsk.h | 4 ++-- net/xdp/xskmap.c | 29 +++++++++++++---------- 7 files changed, 82 insertions(+), 50 deletions(-) diff --git a/include/net/xdp_sock.h b/include/net/xdp_sock.h index 9c0722c6d7ac..fff069d2ed1b 100644 --- a/include/net/xdp_sock.h +++ b/include/net/xdp_sock.h @@ -37,7 +37,7 @@ struct xdp_umem { struct xsk_map { struct bpf_map map; spinlock_t lock; /* Synchronize map updates */ - struct xdp_sock *xsk_map[]; + struct xdp_sock __rcu *xsk_map[]; }; struct xdp_sock { diff --git a/kernel/bpf/cpumap.c b/kernel/bpf/cpumap.c index a1a0c4e791c6..480e936c54d0 100644 --- a/kernel/bpf/cpumap.c +++ b/kernel/bpf/cpumap.c @@ -74,7 +74,7 @@ struct bpf_cpu_map_entry { struct bpf_cpu_map { struct bpf_map map; /* Below members specific for map type */ - struct bpf_cpu_map_entry **cpu_map; + struct bpf_cpu_map_entry __rcu **cpu_map; }; static DEFINE_PER_CPU(struct list_head, cpu_map_flush_list); @@ -469,7 +469,7 @@ static void __cpu_map_entry_replace(struct bpf_cpu_map *cmap, { struct bpf_cpu_map_entry *old_rcpu; - old_rcpu = xchg(&cmap->cpu_map[key_cpu], rcpu); + old_rcpu = unrcu_pointer(xchg(&cmap->cpu_map[key_cpu], RCU_INITIALIZER(rcpu))); if (old_rcpu) { call_rcu(&old_rcpu->rcu, __cpu_map_entry_free); INIT_WORK(&old_rcpu->kthread_stop_wq, cpu_map_kthread_stop); @@ -551,7 +551,7 @@ static void cpu_map_free(struct bpf_map *map) for (i = 0; i < cmap->map.max_entries; i++) { struct bpf_cpu_map_entry *rcpu; - rcpu = READ_ONCE(cmap->cpu_map[i]); + rcpu = rcu_dereference_raw(cmap->cpu_map[i]); if (!rcpu) continue; @@ -562,6 +562,10 @@ static void cpu_map_free(struct bpf_map *map) kfree(cmap); } +/* Elements are kept alive by RCU; either by rcu_read_lock() (from syscall) or + * by local_bh_disable() (from XDP calls inside NAPI). The + * rcu_read_lock_bh_held() below makes lockdep accept both. + */ static void *__cpu_map_lookup_elem(struct bpf_map *map, u32 key) { struct bpf_cpu_map *cmap = container_of(map, struct bpf_cpu_map, map); @@ -570,7 +574,8 @@ static void *__cpu_map_lookup_elem(struct bpf_map *map, u32 key) if (key >= map->max_entries) return NULL; - rcpu = READ_ONCE(cmap->cpu_map[key]); + rcpu = rcu_dereference_check(cmap->cpu_map[key], + rcu_read_lock_bh_held()); return rcpu; } diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c index 2a75e6c2d27d..ae6d9bfeae06 100644 --- a/kernel/bpf/devmap.c +++ b/kernel/bpf/devmap.c @@ -73,7 +73,7 @@ struct bpf_dtab_netdev { struct bpf_dtab { struct bpf_map map; - struct bpf_dtab_netdev **netdev_map; /* DEVMAP type only */ + struct bpf_dtab_netdev __rcu **netdev_map; /* DEVMAP type only */ struct list_head list; /* these are only used for DEVMAP_HASH type maps */ @@ -226,7 +226,7 @@ static void dev_map_free(struct bpf_map *map) for (i = 0; i < dtab->map.max_entries; i++) { struct bpf_dtab_netdev *dev; - dev = dtab->netdev_map[i]; + dev = rcu_dereference_raw(dtab->netdev_map[i]); if (!dev) continue; @@ -259,6 +259,10 @@ static int dev_map_get_next_key(struct bpf_map *map, void *key, void *next_key) return 0; } +/* Elements are kept alive by RCU; either by rcu_read_lock() (from syscall) or + * by local_bh_disable() (from XDP calls inside NAPI). The + * rcu_read_lock_bh_held() below makes lockdep accept both. + */ static void *__dev_map_hash_lookup_elem(struct bpf_map *map, u32 key) { struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map); @@ -266,7 +270,8 @@ static void *__dev_map_hash_lookup_elem(struct bpf_map *map, u32 key) struct bpf_dtab_netdev *dev; hlist_for_each_entry_rcu(dev, head, index_hlist, - lockdep_is_held(&dtab->index_lock)) + (lockdep_is_held(&dtab->index_lock) || + rcu_read_lock_bh_held())) if (dev->idx == key) return dev; @@ -410,15 +415,9 @@ static void bq_xmit_all(struct xdp_dev_bulk_queue *bq, u32 flags) trace_xdp_devmap_xmit(bq->dev_rx, dev, sent, cnt - sent, err); } -/* __dev_flush is called from xdp_do_flush() which _must_ be signaled - * from the driver before returning from its napi->poll() routine. The poll() - * routine is called either from busy_poll context or net_rx_action signaled - * from NET_RX_SOFTIRQ. Either way the poll routine must complete before the - * net device can be torn down. On devmap tear down we ensure the flush list - * is empty before completing to ensure all flush operations have completed. - * When drivers update the bpf program they may need to ensure any flush ops - * are also complete. Using synchronize_rcu or call_rcu will suffice for this - * because both wait for napi context to exit. +/* __dev_flush is called from xdp_do_flush() which _must_ be signalled from the + * driver before returning from its napi->poll() routine. See the comment above + * xdp_do_flush() in filter.c. */ void __dev_flush(void) { @@ -433,9 +432,9 @@ void __dev_flush(void) } } -/* rcu_read_lock (from syscall and BPF contexts) ensures that if a delete and/or - * update happens in parallel here a dev_put won't happen until after reading - * the ifindex. +/* Elements are kept alive by RCU; either by rcu_read_lock() (from syscall) or + * by local_bh_disable() (from XDP calls inside NAPI). The + * rcu_read_lock_bh_held() below makes lockdep accept both. */ static void *__dev_map_lookup_elem(struct bpf_map *map, u32 key) { @@ -445,12 +444,14 @@ static void *__dev_map_lookup_elem(struct bpf_map *map, u32 key) if (key >= map->max_entries) return NULL; - obj = READ_ONCE(dtab->netdev_map[key]); + obj = rcu_dereference_check(dtab->netdev_map[key], + rcu_read_lock_bh_held()); return obj; } -/* Runs under RCU-read-side, plus in softirq under NAPI protection. - * Thus, safe percpu variable access. +/* Runs in NAPI, i.e., softirq under local_bh_disable(). Thus, safe percpu + * variable access, and map elements stick around. See comment above + * xdp_do_flush() in filter.c. */ static void bq_enqueue(struct net_device *dev, struct xdp_frame *xdpf, struct net_device *dev_rx, struct bpf_prog *xdp_prog) @@ -735,14 +736,7 @@ static int dev_map_delete_elem(struct bpf_map *map, void *key) if (k >= map->max_entries) return -EINVAL; - /* Use call_rcu() here to ensure any rcu critical sections have - * completed as well as any flush operations because call_rcu - * will wait for preempt-disable region to complete, NAPI in this - * context. And additionally, the driver tear down ensures all - * soft irqs are complete before removing the net device in the - * case of dev_put equals zero. - */ - old_dev = xchg(&dtab->netdev_map[k], NULL); + old_dev = unrcu_pointer(xchg(&dtab->netdev_map[k], NULL)); if (old_dev) call_rcu(&old_dev->rcu, __dev_map_entry_free); return 0; @@ -851,7 +845,7 @@ static int __dev_map_update_elem(struct net *net, struct bpf_map *map, * Remembering the driver side flush operation will happen before the * net device is removed. */ - old_dev = xchg(&dtab->netdev_map[i], dev); + old_dev = unrcu_pointer(xchg(&dtab->netdev_map[i], RCU_INITIALIZER(dev))); if (old_dev) call_rcu(&old_dev->rcu, __dev_map_entry_free); @@ -1031,10 +1025,10 @@ static int dev_map_notification(struct notifier_block *notifier, for (i = 0; i < dtab->map.max_entries; i++) { struct bpf_dtab_netdev *dev, *odev; - dev = READ_ONCE(dtab->netdev_map[i]); + dev = rcu_dereference(dtab->netdev_map[i]); if (!dev || netdev != dev->dev) continue; - odev = cmpxchg(&dtab->netdev_map[i], dev, NULL); + odev = unrcu_pointer(cmpxchg(&dtab->netdev_map[i], RCU_INITIALIZER(dev), NULL)); if (dev == odev) call_rcu(&dev->rcu, __dev_map_entry_free); diff --git a/net/core/filter.c b/net/core/filter.c index caa88955562e..0b7db5c70385 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -3922,6 +3922,34 @@ static const struct bpf_func_proto bpf_xdp_adjust_meta_proto = { .arg2_type = ARG_ANYTHING, }; +/* XDP_REDIRECT works by a three-step process, implemented in the functions + * below: + * + * 1. The bpf_redirect() and bpf_redirect_map() helpers will lookup the target + * of the redirect and store it (along with some other metadata) in a per-CPU + * struct bpf_redirect_info. + * + * 2. When the program returns the XDP_REDIRECT return code, the driver will + * call xdp_do_redirect() which will use the information in struct + * bpf_redirect_info to actually enqueue the frame into a map type-specific + * bulk queue structure. + * + * 3. Before exiting its NAPI poll loop, the driver will call xdp_do_flush(), + * which will flush all the different bulk queues, thus completing the + * redirect. + * + * Pointers to the map entries will be kept around for this whole sequence of + * steps, protected by RCU. However, there is no top-level rcu_read_lock() in + * the core code; instead, the RCU protection relies on everything happening + * inside a single NAPI poll sequence, which means it's between a pair of calls + * to local_bh_disable()/local_bh_enable(). + * + * The map entries are marked as __rcu and the map code makes sure to + * dereference those pointers with rcu_dereference_check() in a way that works + * for both sections that to hold an rcu_read_lock() and sections that are + * called from NAPI without a separate rcu_read_lock(). The code below does not + * use RCU annotations, but relies on those in the map code. + */ void xdp_do_flush(void) { __dev_flush(); diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c index cd62d4ba87a9..996da915f520 100644 --- a/net/xdp/xsk.c +++ b/net/xdp/xsk.c @@ -749,7 +749,7 @@ static void xsk_unbind_dev(struct xdp_sock *xs) } static struct xsk_map *xsk_get_map_list_entry(struct xdp_sock *xs, - struct xdp_sock ***map_entry) + struct xdp_sock __rcu ***map_entry) { struct xsk_map *map = NULL; struct xsk_map_node *node; @@ -785,7 +785,7 @@ static void xsk_delete_from_maps(struct xdp_sock *xs) * might be updates to the map between * xsk_get_map_list_entry() and xsk_map_try_sock_delete(). */ - struct xdp_sock **map_entry = NULL; + struct xdp_sock __rcu **map_entry = NULL; struct xsk_map *map; while ((map = xsk_get_map_list_entry(xs, &map_entry))) { diff --git a/net/xdp/xsk.h b/net/xdp/xsk.h index edcf249ad1f1..a4bc4749faac 100644 --- a/net/xdp/xsk.h +++ b/net/xdp/xsk.h @@ -31,7 +31,7 @@ struct xdp_mmap_offsets_v1 { struct xsk_map_node { struct list_head node; struct xsk_map *map; - struct xdp_sock **map_entry; + struct xdp_sock __rcu **map_entry; }; static inline struct xdp_sock *xdp_sk(struct sock *sk) @@ -40,7 +40,7 @@ static inline struct xdp_sock *xdp_sk(struct sock *sk) } void xsk_map_try_sock_delete(struct xsk_map *map, struct xdp_sock *xs, - struct xdp_sock **map_entry); + struct xdp_sock __rcu **map_entry); void xsk_clear_pool_at_qid(struct net_device *dev, u16 queue_id); int xsk_reg_pool_at_qid(struct net_device *dev, struct xsk_buff_pool *pool, u16 queue_id); diff --git a/net/xdp/xskmap.c b/net/xdp/xskmap.c index 9df75ea4a567..2e48d0e094d9 100644 --- a/net/xdp/xskmap.c +++ b/net/xdp/xskmap.c @@ -12,7 +12,7 @@ #include "xsk.h" static struct xsk_map_node *xsk_map_node_alloc(struct xsk_map *map, - struct xdp_sock **map_entry) + struct xdp_sock __rcu **map_entry) { struct xsk_map_node *node; @@ -42,7 +42,7 @@ static void xsk_map_sock_add(struct xdp_sock *xs, struct xsk_map_node *node) } static void xsk_map_sock_delete(struct xdp_sock *xs, - struct xdp_sock **map_entry) + struct xdp_sock __rcu **map_entry) { struct xsk_map_node *n, *tmp; @@ -124,6 +124,10 @@ static int xsk_map_gen_lookup(struct bpf_map *map, struct bpf_insn *insn_buf) return insn - insn_buf; } +/* Elements are kept alive by RCU; either by rcu_read_lock() (from syscall) or + * by local_bh_disable() (from XDP calls inside NAPI). The + * rcu_read_lock_bh_held() below makes lockdep accept both. + */ static void *__xsk_map_lookup_elem(struct bpf_map *map, u32 key) { struct xsk_map *m = container_of(map, struct xsk_map, map); @@ -131,12 +135,11 @@ static void *__xsk_map_lookup_elem(struct bpf_map *map, u32 key) if (key >= map->max_entries) return NULL; - return READ_ONCE(m->xsk_map[key]); + return rcu_dereference_check(m->xsk_map[key], rcu_read_lock_bh_held()); } static void *xsk_map_lookup_elem(struct bpf_map *map, void *key) { - WARN_ON_ONCE(!rcu_read_lock_held()); return __xsk_map_lookup_elem(map, *(u32 *)key); } @@ -149,7 +152,8 @@ static int xsk_map_update_elem(struct bpf_map *map, void *key, void *value, u64 map_flags) { struct xsk_map *m = container_of(map, struct xsk_map, map); - struct xdp_sock *xs, *old_xs, **map_entry; + struct xdp_sock __rcu **map_entry; + struct xdp_sock *xs, *old_xs; u32 i = *(u32 *)key, fd = *(u32 *)value; struct xsk_map_node *node; struct socket *sock; @@ -179,7 +183,7 @@ static int xsk_map_update_elem(struct bpf_map *map, void *key, void *value, } spin_lock_bh(&m->lock); - old_xs = READ_ONCE(*map_entry); + old_xs = rcu_dereference_protected(*map_entry, lockdep_is_held(&m->lock)); if (old_xs == xs) { err = 0; goto out; @@ -191,7 +195,7 @@ static int xsk_map_update_elem(struct bpf_map *map, void *key, void *value, goto out; } xsk_map_sock_add(xs, node); - WRITE_ONCE(*map_entry, xs); + rcu_assign_pointer(*map_entry, xs); if (old_xs) xsk_map_sock_delete(old_xs, map_entry); spin_unlock_bh(&m->lock); @@ -208,7 +212,8 @@ static int xsk_map_update_elem(struct bpf_map *map, void *key, void *value, static int xsk_map_delete_elem(struct bpf_map *map, void *key) { struct xsk_map *m = container_of(map, struct xsk_map, map); - struct xdp_sock *old_xs, **map_entry; + struct xdp_sock __rcu **map_entry; + struct xdp_sock *old_xs; int k = *(u32 *)key; if (k >= map->max_entries) @@ -216,7 +221,7 @@ static int xsk_map_delete_elem(struct bpf_map *map, void *key) spin_lock_bh(&m->lock); map_entry = &m->xsk_map[k]; - old_xs = xchg(map_entry, NULL); + old_xs = unrcu_pointer(xchg(map_entry, NULL)); if (old_xs) xsk_map_sock_delete(old_xs, map_entry); spin_unlock_bh(&m->lock); @@ -231,11 +236,11 @@ static int xsk_map_redirect(struct bpf_map *map, u32 ifindex, u64 flags) } void xsk_map_try_sock_delete(struct xsk_map *map, struct xdp_sock *xs, - struct xdp_sock **map_entry) + struct xdp_sock __rcu **map_entry) { spin_lock_bh(&map->lock); - if (READ_ONCE(*map_entry) == xs) { - WRITE_ONCE(*map_entry, NULL); + if (rcu_access_pointer(*map_entry) == xs) { + rcu_assign_pointer(*map_entry, NULL); xsk_map_sock_delete(xs, map_entry); } spin_unlock_bh(&map->lock); From patchwork Tue Jun 15 14:54:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 12322063 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4EEA0C48BE8 for ; Tue, 15 Jun 2021 14:55:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1E70A61585 for ; Tue, 15 Jun 2021 14:55:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231173AbhFOO5I (ORCPT ); Tue, 15 Jun 2021 10:57:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:57861 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230316AbhFOO5H (ORCPT ); Tue, 15 Jun 2021 10:57:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623768902; 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=bmidfz0+CJmOWuJ1Ds56KwPBuWWIUyMrF1VbqTWEQjA=; b=YDOq+egnLxkhOlj0RrMALtgAK84MJMAMtS5kHLSBgKxdG/9ywVp2JHhJ82KQOHfCNZcDJD IjIa7iRvsxCgD5q51dQbKhGFn22gpJYfcKVJgN6dDSzgvMDCUEOSLUObGv046Ui1IQfI6a tolMMHOLz/+udZLC8KXAQsGv86YtVDQ= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-231-Uqb0tZa7OiynuEPT1WLkaQ-1; Tue, 15 Jun 2021 10:55:01 -0400 X-MC-Unique: Uqb0tZa7OiynuEPT1WLkaQ-1 Received: by mail-ed1-f70.google.com with SMTP id p24-20020aa7c8980000b0290393c37fdcb8so11227769eds.6 for ; Tue, 15 Jun 2021 07:55:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bmidfz0+CJmOWuJ1Ds56KwPBuWWIUyMrF1VbqTWEQjA=; b=dfeaBjqA69QrlLyNGEwaN3/mnQolrGk8biIGTwygtvONlauTLgRHN37Mosq6+WZYSA cSTpxEmbkvK59tzEhvYG0vL4VrWkffJEWmWjDW5sku9b7massEJCpIi0sLgqxz9kcVmg FBnyEEGXhmXRQn2XQA5G1S9iYOdfXiJ8adFYYlhj/ZisHWqhcmT3bUa970rF6iQNgCAj J4pAytDYPOxVhAXIJTUrfKatfag6XarbZ/Xxl8JeT/owCF3u72IPs+AjE/YrY6jlc7GL gbDhPKt5K9iPRUKZqtR0giCxMvhDOX90j9pz4iGbnL432PPQX61SIKE0gwHLwVQblrtn JKFA== X-Gm-Message-State: AOAM532/5HcMDIkEnnc37jMKRDRY9V+wBxIKtgt7EZWPd+2K8F8v8Vj4 MzhrYJvW/JjCeWILWuCMODTpqS9AqowLksqqIF/I2Oh/GE0wFJoV4RntHSO5H/2c+/tyJ162guG /a5DS2xEtNJP5 X-Received: by 2002:a05:6402:702:: with SMTP id w2mr23790302edx.189.1623768900337; Tue, 15 Jun 2021 07:55:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNRBKZlwf2ReOVkRIekxwBZ2n5A2DWRM9fshz8kMlqUDSUxWOoQYe/r7X+b9O8Xp4q8OQ9cQ== X-Received: by 2002:a05:6402:702:: with SMTP id w2mr23790285edx.189.1623768900198; Tue, 15 Jun 2021 07:55:00 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id kf3sm9320945ejc.8.2021.06.15.07.54.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 07:54:59 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id C4240180727; Tue, 15 Jun 2021 16:54:58 +0200 (CEST) From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: bpf@vger.kernel.org, netdev@vger.kernel.org Cc: Martin KaFai Lau , Hangbin Liu , Jesper Dangaard Brouer , Magnus Karlsson , "Paul E . McKenney" , Jakub Kicinski , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= , Guy Tzalik , Saeed Bishara Subject: [PATCH bpf-next v2 04/16] ena: remove rcu_read_lock() around XDP program invocation Date: Tue, 15 Jun 2021 16:54:43 +0200 Message-Id: <20210615145455.564037-5-toke@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615145455.564037-1-toke@redhat.com> References: <20210615145455.564037-1-toke@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The ena driver has rcu_read_lock()/rcu_read_unlock() pairs around XDP program invocations. However, the actual lifetime of the objects referred by the XDP program invocation is longer, all the way through to the call to xdp_do_flush(), making the scope of the rcu_read_lock() too small. This turns out to be harmless because it all happens in a single NAPI poll cycle (and thus under local_bh_disable()), but it makes the rcu_read_lock() misleading. Rather than extend the scope of the rcu_read_lock(), just get rid of it entirely. With the addition of RCU annotations to the XDP_REDIRECT map types that take bh execution into account, lockdep even understands this to be safe, so there's really no reason to keep it around. Cc: Guy Tzalik Cc: Saeed Bishara Signed-off-by: Toke Høiland-Jørgensen --- drivers/net/ethernet/amazon/ena/ena_netdev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c index 881f88754bf6..cd5f03691b4c 100644 --- a/drivers/net/ethernet/amazon/ena/ena_netdev.c +++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c @@ -385,7 +385,9 @@ static int ena_xdp_execute(struct ena_ring *rx_ring, struct xdp_buff *xdp) u64 *xdp_stat; int qid; - rcu_read_lock(); + /* This code is invoked within a single NAPI poll cycle and thus under + * local_bh_disable(), which provides the needed RCU protection. + */ xdp_prog = READ_ONCE(rx_ring->xdp_bpf_prog); if (!xdp_prog) @@ -443,8 +445,6 @@ static int ena_xdp_execute(struct ena_ring *rx_ring, struct xdp_buff *xdp) ena_increase_stat(xdp_stat, 1, &rx_ring->syncp); out: - rcu_read_unlock(); - return verdict; } From patchwork Tue Jun 15 14:54:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 12322077 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41167C49EA5 for ; Tue, 15 Jun 2021 14:55:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1F9346161E for ; Tue, 15 Jun 2021 14:55:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231439AbhFOO5S (ORCPT ); Tue, 15 Jun 2021 10:57:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:32532 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231466AbhFOO5P (ORCPT ); Tue, 15 Jun 2021 10:57:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623768911; 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=+MBUlWntOqYKNc/Hn434J6hypV0mSyDY5Wc91lYkTgY=; b=S82GwF7aYyQel24j0LCv4tRCDu4woYUk4a4OCyHeU/wltDnJbKhk5drQujxmdIe/X4RQie uk+uZDN1G8OgijWQk1UsZgacXDUiywW0lCbibEzRrbgVc/syMxg0El3vAdrd6I/VQo81Y+ eQ0yRQ4d4/LUDJ2MgpuqJC0NJVr3cpo= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-299-jzbhbBPQNkGCnIdDuUfuPw-1; Tue, 15 Jun 2021 10:55:07 -0400 X-MC-Unique: jzbhbBPQNkGCnIdDuUfuPw-1 Received: by mail-ed1-f71.google.com with SMTP id h23-20020aa7c5d70000b029038fed7b27d5so22254147eds.21 for ; Tue, 15 Jun 2021 07:55:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+MBUlWntOqYKNc/Hn434J6hypV0mSyDY5Wc91lYkTgY=; b=qvA8wV4EOagSkzVyb6avcwr2e32LIFQO4+yHGkW+Jr2cW6OJfJb79O8+GSbSkZQR7L 8ASx+Ly2n8G4R3t6gYWvjHhtjFvesqYbjD/OstXC8LbcfOoMi+IbuvSnNIxRsGu9DthF t3TLhts+AkWA37VOVX+CCm5E9sXrKI3I0796sArWccOU/pbiY4HIqw/AS/pgrcm1VIoM ldMJBqdhNCWhnSSbWvDyXe2IJkUa6KOinDNw/Mbc1Ps3Ofp4LWPSuM3bqm2skIUh3Ry6 QYKxMFTzvY2XYr3griFI+6IGn1442GvNfv2WHzYC2BsQITqqLdhcw80kgoZFRE1cP1h0 P3QQ== X-Gm-Message-State: AOAM531aJ8K/BpV+RdCv3j78nUXbTa+cgwaEe0CHRABCNM1hItkW/NMz WOL3o2MIfj0TQUw7kGL69DV6E/8J/0F48Ew2LhEbOyAyO5VLIO6AYrgyY9ExuJPIH7VUPCV15gO V3oCZFgK33FFZ X-Received: by 2002:a17:906:340d:: with SMTP id c13mr21721992ejb.457.1623768906643; Tue, 15 Jun 2021 07:55:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJya4LdcReocWctTCZ9mI36cRWbw1AvtX2B2eEU4jnR/LeLy+2+DqvNbDMZXizkn9MKh2FwH1A== X-Received: by 2002:a17:906:340d:: with SMTP id c13mr21721961ejb.457.1623768906261; Tue, 15 Jun 2021 07:55:06 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id bd3sm12013372edb.34.2021.06.15.07.55.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 07:55:04 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id CFF33180728; Tue, 15 Jun 2021 16:54:58 +0200 (CEST) From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: bpf@vger.kernel.org, netdev@vger.kernel.org Cc: Martin KaFai Lau , Hangbin Liu , Jesper Dangaard Brouer , Magnus Karlsson , "Paul E . McKenney" , Jakub Kicinski , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= , Michael Chan Subject: [PATCH bpf-next v2 05/16] bnxt: remove rcu_read_lock() around XDP program invocation Date: Tue, 15 Jun 2021 16:54:44 +0200 Message-Id: <20210615145455.564037-6-toke@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615145455.564037-1-toke@redhat.com> References: <20210615145455.564037-1-toke@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The bnxt driver has rcu_read_lock()/rcu_read_unlock() pairs around XDP program invocations. However, the actual lifetime of the objects referred by the XDP program invocation is longer, all the way through to the call to xdp_do_flush(), making the scope of the rcu_read_lock() too small. This turns out to be harmless because it all happens in a single NAPI poll cycle (and thus under local_bh_disable()), but it makes the rcu_read_lock() misleading. Rather than extend the scope of the rcu_read_lock(), just get rid of it entirely. With the addition of RCU annotations to the XDP_REDIRECT map types that take bh execution into account, lockdep even understands this to be safe, so there's really no reason to keep it around. Cc: Michael Chan Signed-off-by: Toke Høiland-Jørgensen --- drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c index ec9564e584e0..f38e6ce9b40e 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c @@ -138,9 +138,10 @@ bool bnxt_rx_xdp(struct bnxt *bp, struct bnxt_rx_ring_info *rxr, u16 cons, xdp_prepare_buff(&xdp, *data_ptr - offset, offset, *len, false); orig_data = xdp.data; - rcu_read_lock(); + /* This code is invoked within a single NAPI poll cycle and thus under + * local_bh_disable(), which provides the needed RCU protection. + */ act = bpf_prog_run_xdp(xdp_prog, &xdp); - rcu_read_unlock(); tx_avail = bnxt_tx_avail(bp, txr); /* If the tx ring is not full, we must not update the rx producer yet From patchwork Tue Jun 15 14:54:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 12322083 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6227DC49EA2 for ; Tue, 15 Jun 2021 14:55:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 47CC36161C for ; Tue, 15 Jun 2021 14:55:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231445AbhFOO5R (ORCPT ); Tue, 15 Jun 2021 10:57:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:43747 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231417AbhFOO5O (ORCPT ); Tue, 15 Jun 2021 10:57:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623768909; 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=UuVwKA1OMw5HxgYVzw3xNIdTf1mnrwsBt+MXeIcnXmI=; b=i2Vru2rc7NQrdQUfLAEzXPjuj8e5z6g0fiEkeA4zeAoWn76Z0Gl04E0eTf98OLLDTdAKkl 1IzI2WJ67qo51KtE01mj6P6J13ZfejjS/GApxstdOMLVUpIr0OyWk6+ukotTuBYMImHx2+ qM4wDltKrv3Tvs9lmIqUQqCgTHbmnmY= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-494-x_ZcpvGBNAq5IF7IEDglYA-1; Tue, 15 Jun 2021 10:55:08 -0400 X-MC-Unique: x_ZcpvGBNAq5IF7IEDglYA-1 Received: by mail-ed1-f70.google.com with SMTP id q7-20020aa7cc070000b029038f59dab1c5so22520484edt.23 for ; Tue, 15 Jun 2021 07:55:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UuVwKA1OMw5HxgYVzw3xNIdTf1mnrwsBt+MXeIcnXmI=; b=Pvlbx/mow0MTmRrYquKLadfRMgi57uTMlfwRiGFwh4+VBFn+fkukFeNrHSb+xAR/BN mvwbzlcf6WgnZn2Iolmp5Ct4JJLGF0qVhc4au4TJVUALMrqGPXSnYezlfBkFwZ5Bi8tg dBdubqABkWt97+KyKyBCguuFiDP7kYRNwtmIbBJjN7LscDW2Ej+zSl8jxnG+Y4EchyK3 D9rinGPoFsCujCOivQ3ow6G32jUdglBZRb5y/466Ob0CV7F1nGkwRl/bB2uixdhz1lm8 QlEAYYY/ByGVOMVb74l+o4XrzEqMW8bDBDJeloq/azh6S+W4pnoOq7FugVfPAh+hldu5 DZTA== X-Gm-Message-State: AOAM532NnFQUJwnznKGbKHYzXoMKPClwxccFKLQjt3SGhVHkd3iRz2mo NDTyjYSXCopwKiWRZaS4ECJck+mJ/5Ct6Idb/9zLs+JWZJTOf4XR0LAPg+TpmVJK5s0LoxlDZAC O0TqzQf4/bAR4 X-Received: by 2002:a17:906:86d2:: with SMTP id j18mr20741204ejy.180.1623768906893; Tue, 15 Jun 2021 07:55:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWpfiZnqpYkM92g7guVvXh6FJ1+oiuUPPVMTAPBLOqzvhVwFA4IyVKuSf3Gx69P5gjjEnkoA== X-Received: by 2002:a17:906:86d2:: with SMTP id j18mr20741184ejy.180.1623768906755; Tue, 15 Jun 2021 07:55:06 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id u15sm12524316edy.29.2021.06.15.07.55.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 07:55:04 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id D550418072F; Tue, 15 Jun 2021 16:54:58 +0200 (CEST) From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: bpf@vger.kernel.org, netdev@vger.kernel.org Cc: Martin KaFai Lau , Hangbin Liu , Jesper Dangaard Brouer , Magnus Karlsson , "Paul E . McKenney" , Jakub Kicinski , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= , Sunil Goutham , linux-arm-kernel@lists.infradead.org Subject: [PATCH bpf-next v2 06/16] thunderx: remove rcu_read_lock() around XDP program invocation Date: Tue, 15 Jun 2021 16:54:45 +0200 Message-Id: <20210615145455.564037-7-toke@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615145455.564037-1-toke@redhat.com> References: <20210615145455.564037-1-toke@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The thunderx driver has rcu_read_lock()/rcu_read_unlock() pairs around XDP program invocations. However, the actual lifetime of the objects referred by the XDP program invocation is longer, all the way through to the call to xdp_do_flush(), making the scope of the rcu_read_lock() too small. This turns out to be harmless because it all happens in a single NAPI poll cycle (and thus under local_bh_disable()), but it makes the rcu_read_lock() misleading. Rather than extend the scope of the rcu_read_lock(), just get rid of it entirely. With the addition of RCU annotations to the XDP_REDIRECT map types that take bh execution into account, lockdep even understands this to be safe, so there's really no reason to keep it around. Cc: Sunil Goutham Cc: linux-arm-kernel@lists.infradead.org Signed-off-by: Toke Høiland-Jørgensen --- drivers/net/ethernet/cavium/thunder/nicvf_main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/cavium/thunder/nicvf_main.c b/drivers/net/ethernet/cavium/thunder/nicvf_main.c index c33b4e837515..1d752815c69a 100644 --- a/drivers/net/ethernet/cavium/thunder/nicvf_main.c +++ b/drivers/net/ethernet/cavium/thunder/nicvf_main.c @@ -555,9 +555,10 @@ static inline bool nicvf_xdp_rx(struct nicvf *nic, struct bpf_prog *prog, xdp_prepare_buff(&xdp, hard_start, data - hard_start, len, false); orig_data = xdp.data; - rcu_read_lock(); + /* This code is invoked within a single NAPI poll cycle and thus under + * local_bh_disable(), which provides the needed RCU protection. + */ action = bpf_prog_run_xdp(prog, &xdp); - rcu_read_unlock(); len = xdp.data_end - xdp.data; /* Check if XDP program has changed headers */ From patchwork Tue Jun 15 14:54:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 12322085 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90441C48BE5 for ; Tue, 15 Jun 2021 14:55:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7B775615FF for ; Tue, 15 Jun 2021 14:55:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231576AbhFOO5W (ORCPT ); Tue, 15 Jun 2021 10:57:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:47866 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231513AbhFOO5R (ORCPT ); Tue, 15 Jun 2021 10:57:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623768912; 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=L2w+HImdAUwFSlY1hYWtFiNbCUvYk0lFrUyqVDU6cjY=; b=BbLUXcYtv+QJci6U+j8i34Uv1eFakGldxqkcKXdWdDhuLMjUMx2HLy+X3znm11LumbwsWR uv7RfzQOsIu0Y2YVlZwkJbe4k+E7cu8MuP59KgXIy5bq0ft6+MibRcG31VG9ElonJMsUo+ V1c04ZJbA1sk/JuI4I7ngitWjhIbYdM= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-195-XTgxMbJYOviYHSgPyV-Sbw-1; Tue, 15 Jun 2021 10:55:10 -0400 X-MC-Unique: XTgxMbJYOviYHSgPyV-Sbw-1 Received: by mail-ej1-f69.google.com with SMTP id f1-20020a1709064941b02903f6b5ef17bfso4631209ejt.20 for ; Tue, 15 Jun 2021 07:55:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=L2w+HImdAUwFSlY1hYWtFiNbCUvYk0lFrUyqVDU6cjY=; b=tzzRQCtXhM1COHtnu7ca0tNTgWY9d+a50pWpI6YipPLe7b1rsroWeG6kSEyD7vVWEB 8orIF7tQ4bYDfrKA2z+lLFNz3i/4tV7OLJc2UgHnNfSvubHuJJi8Rsf28Te2fEg6zTNF FpngxYeViBfKw78EnxmfEv12w+T6y6QCEXvqdKawtN/C6lUGKiUienw/iwr8WBcw5uEX t+ZZcd0Ep/eVdQ9/tn+4+8ijkvdi8ctfWNXA9J3tzQ2gT2TMlBe6xLDw0ftJly8HhuPy ofEFLPH7n2ws4icQV23CIlEyuBt4FeyVf54xX2oB84lOel/hr+CVpjS4mlHSTnHoDtSL SB/A== X-Gm-Message-State: AOAM532iKbSe+LC5nmkouVL4v7Zs8QJ/vxO3Ni8kSuoq4Xro48N76hNl IZfqeIoVzaMDKg7bU5ACDEky/WjBtsUwGZ6RyfB4WA/GGnTVqQMNMzABVG30KvpHb2CceBWY/Id xfYae/+2sZF5a X-Received: by 2002:a17:906:994d:: with SMTP id zm13mr20665193ejb.427.1623768908862; Tue, 15 Jun 2021 07:55:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrD5ykD8QuStI7yTpQynBYBmFa7phE5jHXSY1xZ0QyxDdvR2QIW94oCmW587hJOv+QJQ4J5Q== X-Received: by 2002:a17:906:994d:: with SMTP id zm13mr20665154ejb.427.1623768908470; Tue, 15 Jun 2021 07:55:08 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id t5sm10267312eje.29.2021.06.15.07.55.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 07:55:06 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id DB6F6180730; Tue, 15 Jun 2021 16:54:58 +0200 (CEST) From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: bpf@vger.kernel.org, netdev@vger.kernel.org Cc: Martin KaFai Lau , Hangbin Liu , Jesper Dangaard Brouer , Magnus Karlsson , "Paul E . McKenney" , Jakub Kicinski , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= , Madalin Bucur , Ioana Ciornei , Ioana Radulescu Subject: [PATCH bpf-next v2 07/16] freescale: remove rcu_read_lock() around XDP program invocation Date: Tue, 15 Jun 2021 16:54:46 +0200 Message-Id: <20210615145455.564037-8-toke@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615145455.564037-1-toke@redhat.com> References: <20210615145455.564037-1-toke@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The dpaa and dpaa2 drivers have rcu_read_lock()/rcu_read_unlock() pairs around XDP program invocations. However, the actual lifetime of the objects referred by the XDP program invocation is longer, all the way through to the call to xdp_do_flush(), making the scope of the rcu_read_lock() too small. This turns out to be harmless because it all happens in a single NAPI poll cycle (and thus under local_bh_disable()), but it makes the rcu_read_lock() misleading. Rather than extend the scope of the rcu_read_lock(), just get rid of it entirely. With the addition of RCU annotations to the XDP_REDIRECT map types that take bh execution into account, lockdep even understands this to be safe, so there's really no reason to keep it around. Cc: Madalin Bucur Cc: Ioana Ciornei Cc: Ioana Radulescu Signed-off-by: Toke Høiland-Jørgensen Reviewed-by: Camelia Groza --- drivers/net/ethernet/freescale/dpaa/dpaa_eth.c | 11 ++++------- drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c | 6 +++--- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c index 177c020bf34a..98fdcbde687a 100644 --- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c @@ -2558,13 +2558,9 @@ static u32 dpaa_run_xdp(struct dpaa_priv *priv, struct qm_fd *fd, void *vaddr, u32 xdp_act; int err; - rcu_read_lock(); - xdp_prog = READ_ONCE(priv->xdp_prog); - if (!xdp_prog) { - rcu_read_unlock(); + if (!xdp_prog) return XDP_PASS; - } xdp_init_buff(&xdp, DPAA_BP_RAW_SIZE - DPAA_TX_PRIV_DATA_SIZE, &dpaa_fq->xdp_rxq); @@ -2585,6 +2581,9 @@ static u32 dpaa_run_xdp(struct dpaa_priv *priv, struct qm_fd *fd, void *vaddr, } #endif + /* This code is invoked within a single NAPI poll cycle and thus under + * local_bh_disable(), which provides the needed RCU protection. + */ xdp_act = bpf_prog_run_xdp(xdp_prog, &xdp); /* Update the length and the offset of the FD */ @@ -2638,8 +2637,6 @@ static u32 dpaa_run_xdp(struct dpaa_priv *priv, struct qm_fd *fd, void *vaddr, break; } - rcu_read_unlock(); - return xdp_act; } diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c index 8433aa730c42..964d85c9e37d 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c @@ -352,8 +352,6 @@ static u32 dpaa2_eth_run_xdp(struct dpaa2_eth_priv *priv, u32 xdp_act = XDP_PASS; int err, offset; - rcu_read_lock(); - xdp_prog = READ_ONCE(ch->xdp.prog); if (!xdp_prog) goto out; @@ -363,6 +361,9 @@ static u32 dpaa2_eth_run_xdp(struct dpaa2_eth_priv *priv, xdp_prepare_buff(&xdp, vaddr + offset, XDP_PACKET_HEADROOM, dpaa2_fd_get_len(fd), false); + /* This code is invoked within a single NAPI poll cycle and thus under + * local_bh_disable(), which provides the needed RCU protection. + */ xdp_act = bpf_prog_run_xdp(xdp_prog, &xdp); /* xdp.data pointer may have changed */ @@ -414,7 +415,6 @@ static u32 dpaa2_eth_run_xdp(struct dpaa2_eth_priv *priv, ch->xdp.res |= xdp_act; out: - rcu_read_unlock(); return xdp_act; } From patchwork Tue Jun 15 14:54:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 12322087 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C2DBC48BE5 for ; Tue, 15 Jun 2021 14:55:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8603E61584 for ; Tue, 15 Jun 2021 14:55:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231476AbhFOO53 (ORCPT ); Tue, 15 Jun 2021 10:57:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:20542 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231417AbhFOO5S (ORCPT ); Tue, 15 Jun 2021 10:57:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623768913; 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=g/1dUDyNZZrs33xk0mFJ4m/UiP5685UlgffhChjEESM=; b=XUjhBSex2bj3aFF5phvGCUQbwWmtngxz5PAduXoFPO3xAdNRPckm0/8lkZwSVpsjx/etD5 c2ha4fAX5xjwoDg8oABr5+8xaAIkZUlmeO08ehKVzgvMFbAlZgeu9PT9bqmGPptFuDih7z X+oZqFgnwynP/tScy8P8MxEch2B1Gzk= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-336-7Eh65TXKM-uvXRPSISJUeg-1; Tue, 15 Jun 2021 10:55:11 -0400 X-MC-Unique: 7Eh65TXKM-uvXRPSISJUeg-1 Received: by mail-ed1-f72.google.com with SMTP id y18-20020a0564022712b029038ffac1995eso22544713edd.12 for ; Tue, 15 Jun 2021 07:55:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=g/1dUDyNZZrs33xk0mFJ4m/UiP5685UlgffhChjEESM=; b=hQg9mCcU7QBRATK3LJ+FynY18m63ny8m0az5u/MfPMlIqjGcWz2BDte+W3o1C15/ou DDa0sdm4Vxf4m3obsjY6YsM6CUV+OIULzUok01QPzDPYYHt1TFlPCdt/K2/OhlvNJWk7 JMeK/2lPyyjhxSbKW6le9b2stiAbfmobEGS5Ob9cAVa4YSb9m+Or7TNmbXOxGXanjsT4 AC16ell3d2ikCFzPV2uXWIWxE0WwwKU0/lpFwTDgher74dARES1J4jF0NT+IfAGyyC4p CzulmaGnSLpzkMn7gxXgNgiONUHkQBrP7cSpcfmaZWccMnFSD7qXofWh6TdiHEEOleTA GozQ== X-Gm-Message-State: AOAM531oiJ/gRrgFx3IUAuLb/6MV4ARZP9daOCS4FKaucW4L+7GYjyiz PzcWXBS240lOqpdGyPMcmSVgFx80MVdlW5Om+6zHuoRvIOTjYVTte9HiGKhyMPOCqr/Op+WHh/p iPM2J8IGWOPu+ X-Received: by 2002:a05:6402:128d:: with SMTP id w13mr24062070edv.38.1623768910448; Tue, 15 Jun 2021 07:55:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCDxZA5428OnKpa9GZb7yrE5vaWiO0ZAS3v/w0w55ygu8BMKcn1QLYrEOPu83LXEhSAk3gSw== X-Received: by 2002:a05:6402:128d:: with SMTP id w13mr24062041edv.38.1623768910200; Tue, 15 Jun 2021 07:55:10 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id w24sm8609477eju.73.2021.06.15.07.55.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 07:55:06 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id E1C88180731; Tue, 15 Jun 2021 16:54:58 +0200 (CEST) From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: bpf@vger.kernel.org, netdev@vger.kernel.org Cc: Martin KaFai Lau , Hangbin Liu , Jesper Dangaard Brouer , Magnus Karlsson , "Paul E . McKenney" , Jakub Kicinski , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= , Jesse Brandeburg , Tony Nguyen , intel-wired-lan@lists.osuosl.org Subject: [PATCH bpf-next v2 08/16] net: intel: remove rcu_read_lock() around XDP program invocation Date: Tue, 15 Jun 2021 16:54:47 +0200 Message-Id: <20210615145455.564037-9-toke@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615145455.564037-1-toke@redhat.com> References: <20210615145455.564037-1-toke@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The Intel drivers all have rcu_read_lock()/rcu_read_unlock() pairs around XDP program invocations. However, the actual lifetime of the objects referred by the XDP program invocation is longer, all the way through to the call to xdp_do_flush(), making the scope of the rcu_read_lock() too small. This turns out to be harmless because it all happens in a single NAPI poll cycle (and thus under local_bh_disable()), but it makes the rcu_read_lock() misleading. Rather than extend the scope of the rcu_read_lock(), just get rid of it entirely. With the addition of RCU annotations to the XDP_REDIRECT map types that take bh execution into account, lockdep even understands this to be safe, so there's really no reason to keep it around. Cc: Jesse Brandeburg Cc: Tony Nguyen Cc: intel-wired-lan@lists.osuosl.org Tested-by: Jesper Dangaard Brouer # i40e Signed-off-by: Toke Høiland-Jørgensen --- drivers/net/ethernet/intel/i40e/i40e_txrx.c | 5 +++-- drivers/net/ethernet/intel/i40e/i40e_xsk.c | 11 +++++------ drivers/net/ethernet/intel/ice/ice_txrx.c | 6 +----- drivers/net/ethernet/intel/ice/ice_xsk.c | 6 +----- drivers/net/ethernet/intel/igb/igb_main.c | 5 +++-- drivers/net/ethernet/intel/igc/igc_main.c | 10 +++++----- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 5 +++-- drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c | 9 ++++----- drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c | 5 +++-- 9 files changed, 28 insertions(+), 34 deletions(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e_txrx.c b/drivers/net/ethernet/intel/i40e/i40e_txrx.c index de70c16ef619..7fc5bdb5cd9e 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_txrx.c +++ b/drivers/net/ethernet/intel/i40e/i40e_txrx.c @@ -2298,7 +2298,6 @@ static int i40e_run_xdp(struct i40e_ring *rx_ring, struct xdp_buff *xdp) struct bpf_prog *xdp_prog; u32 act; - rcu_read_lock(); xdp_prog = READ_ONCE(rx_ring->xdp_prog); if (!xdp_prog) @@ -2306,6 +2305,9 @@ static int i40e_run_xdp(struct i40e_ring *rx_ring, struct xdp_buff *xdp) prefetchw(xdp->data_hard_start); /* xdp_frame write */ + /* This code is invoked within a single NAPI poll cycle and thus under + * local_bh_disable(), which provides the needed RCU protection. + */ act = bpf_prog_run_xdp(xdp_prog, xdp); switch (act) { case XDP_PASS: @@ -2329,7 +2331,6 @@ static int i40e_run_xdp(struct i40e_ring *rx_ring, struct xdp_buff *xdp) break; } xdp_out: - rcu_read_unlock(); return result; } diff --git a/drivers/net/ethernet/intel/i40e/i40e_xsk.c b/drivers/net/ethernet/intel/i40e/i40e_xsk.c index 46d884417c63..a5982cd112be 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_xsk.c +++ b/drivers/net/ethernet/intel/i40e/i40e_xsk.c @@ -153,8 +153,10 @@ static int i40e_run_xdp_zc(struct i40e_ring *rx_ring, struct xdp_buff *xdp) struct bpf_prog *xdp_prog; u32 act; - rcu_read_lock(); - /* NB! xdp_prog will always be !NULL, due to the fact that + /* This code is invoked within a single NAPI poll cycle and thus under + * local_bh_disable(), which provides the needed RCU protection. + * + * NB! xdp_prog will always be !NULL, due to the fact that * this path is enabled by setting an XDP program. */ xdp_prog = READ_ONCE(rx_ring->xdp_prog); @@ -162,9 +164,7 @@ static int i40e_run_xdp_zc(struct i40e_ring *rx_ring, struct xdp_buff *xdp) if (likely(act == XDP_REDIRECT)) { err = xdp_do_redirect(rx_ring->netdev, xdp, xdp_prog); - result = !err ? I40E_XDP_REDIR : I40E_XDP_CONSUMED; - rcu_read_unlock(); - return result; + return !err ? I40E_XDP_REDIR : I40E_XDP_CONSUMED; } switch (act) { @@ -184,7 +184,6 @@ static int i40e_run_xdp_zc(struct i40e_ring *rx_ring, struct xdp_buff *xdp) result = I40E_XDP_CONSUMED; break; } - rcu_read_unlock(); return result; } diff --git a/drivers/net/ethernet/intel/ice/ice_txrx.c b/drivers/net/ethernet/intel/ice/ice_txrx.c index e2b4b29ea207..1a311e91fb6d 100644 --- a/drivers/net/ethernet/intel/ice/ice_txrx.c +++ b/drivers/net/ethernet/intel/ice/ice_txrx.c @@ -1129,15 +1129,11 @@ int ice_clean_rx_irq(struct ice_ring *rx_ring, int budget) xdp.frame_sz = ice_rx_frame_truesize(rx_ring, size); #endif - rcu_read_lock(); xdp_prog = READ_ONCE(rx_ring->xdp_prog); - if (!xdp_prog) { - rcu_read_unlock(); + if (!xdp_prog) goto construct_skb; - } xdp_res = ice_run_xdp(rx_ring, &xdp, xdp_prog); - rcu_read_unlock(); if (!xdp_res) goto construct_skb; if (xdp_res & (ICE_XDP_TX | ICE_XDP_REDIR)) { diff --git a/drivers/net/ethernet/intel/ice/ice_xsk.c b/drivers/net/ethernet/intel/ice/ice_xsk.c index faa7b8d96adb..d6da377f5ac3 100644 --- a/drivers/net/ethernet/intel/ice/ice_xsk.c +++ b/drivers/net/ethernet/intel/ice/ice_xsk.c @@ -463,7 +463,6 @@ ice_run_xdp_zc(struct ice_ring *rx_ring, struct xdp_buff *xdp) struct ice_ring *xdp_ring; u32 act; - rcu_read_lock(); /* ZC patch is enabled only when XDP program is set, * so here it can not be NULL */ @@ -473,9 +472,7 @@ ice_run_xdp_zc(struct ice_ring *rx_ring, struct xdp_buff *xdp) if (likely(act == XDP_REDIRECT)) { err = xdp_do_redirect(rx_ring->netdev, xdp, xdp_prog); - result = !err ? ICE_XDP_REDIR : ICE_XDP_CONSUMED; - rcu_read_unlock(); - return result; + return !err ? ICE_XDP_REDIR : ICE_XDP_CONSUMED; } switch (act) { @@ -496,7 +493,6 @@ ice_run_xdp_zc(struct ice_ring *rx_ring, struct xdp_buff *xdp) break; } - rcu_read_unlock(); return result; } diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c index 038a9fd1af44..0b68d589218a 100644 --- a/drivers/net/ethernet/intel/igb/igb_main.c +++ b/drivers/net/ethernet/intel/igb/igb_main.c @@ -8387,7 +8387,6 @@ static struct sk_buff *igb_run_xdp(struct igb_adapter *adapter, struct bpf_prog *xdp_prog; u32 act; - rcu_read_lock(); xdp_prog = READ_ONCE(rx_ring->xdp_prog); if (!xdp_prog) @@ -8395,6 +8394,9 @@ static struct sk_buff *igb_run_xdp(struct igb_adapter *adapter, prefetchw(xdp->data_hard_start); /* xdp_frame write */ + /* This code is invoked within a single NAPI poll cycle and thus under + * local_bh_disable(), which provides the needed RCU protection. + */ act = bpf_prog_run_xdp(xdp_prog, xdp); switch (act) { case XDP_PASS: @@ -8420,7 +8422,6 @@ static struct sk_buff *igb_run_xdp(struct igb_adapter *adapter, break; } xdp_out: - rcu_read_unlock(); return ERR_PTR(-result); } diff --git a/drivers/net/ethernet/intel/igc/igc_main.c b/drivers/net/ethernet/intel/igc/igc_main.c index ea998d2defa4..333057ce60c7 100644 --- a/drivers/net/ethernet/intel/igc/igc_main.c +++ b/drivers/net/ethernet/intel/igc/igc_main.c @@ -2175,18 +2175,18 @@ static struct sk_buff *igc_xdp_run_prog(struct igc_adapter *adapter, struct bpf_prog *prog; int res; - rcu_read_lock(); - prog = READ_ONCE(adapter->xdp_prog); if (!prog) { res = IGC_XDP_PASS; - goto unlock; + goto out; } + /* This code is invoked within a single NAPI poll cycle and thus under + * local_bh_disable(), which provides the needed RCU protection. + */ res = __igc_xdp_run_prog(adapter, prog, xdp); -unlock: - rcu_read_unlock(); +out: return ERR_PTR(-res); } diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c index c5ec17d19c59..9cebe7894111 100644 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c @@ -2199,7 +2199,6 @@ static struct sk_buff *ixgbe_run_xdp(struct ixgbe_adapter *adapter, struct xdp_frame *xdpf; u32 act; - rcu_read_lock(); xdp_prog = READ_ONCE(rx_ring->xdp_prog); if (!xdp_prog) @@ -2207,6 +2206,9 @@ static struct sk_buff *ixgbe_run_xdp(struct ixgbe_adapter *adapter, prefetchw(xdp->data_hard_start); /* xdp_frame write */ + /* This code is invoked within a single NAPI poll cycle and thus under + * local_bh_disable(), which provides the needed RCU protection. + */ act = bpf_prog_run_xdp(xdp_prog, xdp); switch (act) { case XDP_PASS: @@ -2237,7 +2239,6 @@ static struct sk_buff *ixgbe_run_xdp(struct ixgbe_adapter *adapter, break; } xdp_out: - rcu_read_unlock(); return ERR_PTR(-result); } diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c index 91ad5b902673..4a075e667082 100644 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c @@ -100,15 +100,15 @@ static int ixgbe_run_xdp_zc(struct ixgbe_adapter *adapter, struct xdp_frame *xdpf; u32 act; - rcu_read_lock(); + /* This code is invoked within a single NAPI poll cycle and thus under + * local_bh_disable(), which provides the needed RCU protection. + */ xdp_prog = READ_ONCE(rx_ring->xdp_prog); act = bpf_prog_run_xdp(xdp_prog, xdp); if (likely(act == XDP_REDIRECT)) { err = xdp_do_redirect(rx_ring->netdev, xdp, xdp_prog); - result = !err ? IXGBE_XDP_REDIR : IXGBE_XDP_CONSUMED; - rcu_read_unlock(); - return result; + return !err ? IXGBE_XDP_REDIR : IXGBE_XDP_CONSUMED; } switch (act) { @@ -132,7 +132,6 @@ static int ixgbe_run_xdp_zc(struct ixgbe_adapter *adapter, result = IXGBE_XDP_CONSUMED; break; } - rcu_read_unlock(); return result; } diff --git a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c index ba2ed8a43d2d..ab05ebc3d350 100644 --- a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +++ b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c @@ -1054,12 +1054,14 @@ static struct sk_buff *ixgbevf_run_xdp(struct ixgbevf_adapter *adapter, struct bpf_prog *xdp_prog; u32 act; - rcu_read_lock(); xdp_prog = READ_ONCE(rx_ring->xdp_prog); if (!xdp_prog) goto xdp_out; + /* This code is invoked within a single NAPI poll cycle and thus under + * local_bh_disable(), which provides the needed RCU protection. + */ act = bpf_prog_run_xdp(xdp_prog, xdp); switch (act) { case XDP_PASS: @@ -1079,7 +1081,6 @@ static struct sk_buff *ixgbevf_run_xdp(struct ixgbevf_adapter *adapter, break; } xdp_out: - rcu_read_unlock(); return ERR_PTR(-result); } From patchwork Tue Jun 15 14:54:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 12322073 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E1B8C49EA7 for ; Tue, 15 Jun 2021 14:55:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 154AB6161C for ; Tue, 15 Jun 2021 14:55:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231468AbhFOO5U (ORCPT ); Tue, 15 Jun 2021 10:57:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:45233 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231477AbhFOO5Q (ORCPT ); Tue, 15 Jun 2021 10:57:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623768911; 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=rY2VfBWw6NJ0/51nfkfzpQbN8Kg/IiRrFOK+qEg2pA4=; b=fJGgf0fmYBJ/yu0/oXh4QqvwosS682jmUbvzFLAYILs+04z/ZSo+vIWOx3rQRiOnxmQiHj CVePXs21ZwsBkDr+QwU1sRz+RlvDxV8gv0kGFi65fwRtybe/n/qr34v4Mwz7yX8WadHDHb GtryHSWYT6U9TJ8tzaEaDSsBnZqB6lQ= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-316-8zKBDl0tOK6AsJpNoCqA5w-1; Tue, 15 Jun 2021 10:55:09 -0400 X-MC-Unique: 8zKBDl0tOK6AsJpNoCqA5w-1 Received: by mail-ed1-f69.google.com with SMTP id a16-20020aa7cf100000b0290391819a774aso20495642edy.8 for ; Tue, 15 Jun 2021 07:55:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rY2VfBWw6NJ0/51nfkfzpQbN8Kg/IiRrFOK+qEg2pA4=; b=hdosVOHw8548CBxk14xXhCGMzgE2kuzUlhjOJpf8Zf/zj7ZrpO3vq9g09E4kEr+x6m sgXrz6YURykc7E3PqF8KeUpuq8EDb4BruTJvQZtEIPqH7J+931+W4If4iUYjUmYoZcsf 5xa52utboTrofplPUZqTGtPMMWonOTSo+JgraePHe0ZRGZImtdHElxGxvs2+arjn+FvM zcZgfjkk1U8qVDMzrJKSly5/hBJim9BPbbyY6waVVZsThQokU1Gqvo4w+XI2UJpGjKfD NWMtJbvJXVnT4UaGY244Lk1jBVairtl5m95jVtzVt317JkLW0CYgJuGufTfmD/KC7lNi ix4g== X-Gm-Message-State: AOAM531oSkLIU5NJNyUPW+VwCJgdcY28+2ex/0m5yEiK7guQDyMz4U1/ isnyG9eRAmJ4Xl5V+XbTIsjVOhM6sOdVzNv7T33pdsplKksa5xMRUZDHq8fK2P3uwiOFt492ceT INAjt4F2mBe1f X-Received: by 2002:a17:906:dfd1:: with SMTP id jt17mr21253055ejc.486.1623768908511; Tue, 15 Jun 2021 07:55:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUc77COnG0WIdO1tAjDrhLpnKaKhnq5sFxyuzHGltCcw1hnUBlYA0poEo+mX++Ywz8VM61xg== X-Received: by 2002:a17:906:dfd1:: with SMTP id jt17mr21253020ejc.486.1623768908212; Tue, 15 Jun 2021 07:55:08 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id cf26sm10281358ejb.38.2021.06.15.07.55.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 07:55:06 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id E6CA1180732; Tue, 15 Jun 2021 16:54:58 +0200 (CEST) From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: bpf@vger.kernel.org, netdev@vger.kernel.org Cc: Martin KaFai Lau , Hangbin Liu , Jesper Dangaard Brouer , Magnus Karlsson , "Paul E . McKenney" , Jakub Kicinski , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= , Thomas Petazzoni , Marcin Wojtas , Russell King Subject: [PATCH bpf-next v2 09/16] marvell: remove rcu_read_lock() around XDP program invocation Date: Tue, 15 Jun 2021 16:54:48 +0200 Message-Id: <20210615145455.564037-10-toke@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615145455.564037-1-toke@redhat.com> References: <20210615145455.564037-1-toke@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The mvneta and mvpp2 drivers have rcu_read_lock()/rcu_read_unlock() pairs around XDP program invocations. However, the actual lifetime of the objects referred by the XDP program invocation is longer, all the way through to the call to xdp_do_flush(), making the scope of the rcu_read_lock() too small. This turns out to be harmless because it all happens in a single NAPI poll cycle (and thus under local_bh_disable()), but it makes the rcu_read_lock() misleading. Rather than extend the scope of the rcu_read_lock(), just get rid of it entirely. With the addition of RCU annotations to the XDP_REDIRECT map types that take bh execution into account, lockdep even understands this to be safe, so there's really no reason to keep it around. Cc: Thomas Petazzoni Cc: Marcin Wojtas Cc: Russell King Signed-off-by: Toke Høiland-Jørgensen --- drivers/net/ethernet/marvell/mvneta.c | 6 ++++-- drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c index 7d5cd9bc6c99..c2e9cbebc8d1 100644 --- a/drivers/net/ethernet/marvell/mvneta.c +++ b/drivers/net/ethernet/marvell/mvneta.c @@ -2370,7 +2370,6 @@ static int mvneta_rx_swbm(struct napi_struct *napi, /* Get number of received packets */ rx_todo = mvneta_rxq_busy_desc_num_get(pp, rxq); - rcu_read_lock(); xdp_prog = READ_ONCE(pp->xdp_prog); /* Fairness NAPI loop */ @@ -2421,6 +2420,10 @@ static int mvneta_rx_swbm(struct napi_struct *napi, goto next; } + /* This code is invoked within a single NAPI poll cycle and thus + * under local_bh_disable(), which provides the needed RCU + * protection. + */ if (xdp_prog && mvneta_run_xdp(pp, rxq, xdp_prog, &xdp_buf, frame_sz, &ps)) goto next; @@ -2448,7 +2451,6 @@ static int mvneta_rx_swbm(struct napi_struct *napi, xdp_buf.data_hard_start = NULL; sinfo.nr_frags = 0; } - rcu_read_unlock(); if (xdp_buf.data_hard_start) mvneta_xdp_put_buff(pp, rxq, &xdp_buf, &sinfo, -1); diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c index b2259bf1d299..658db1720826 100644 --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c @@ -3852,8 +3852,6 @@ static int mvpp2_rx(struct mvpp2_port *port, struct napi_struct *napi, int rx_done = 0; u32 xdp_ret = 0; - rcu_read_lock(); - xdp_prog = READ_ONCE(port->xdp_prog); /* Get number of received packets and clamp the to-do */ @@ -3925,6 +3923,10 @@ static int mvpp2_rx(struct mvpp2_port *port, struct napi_struct *napi, MVPP2_MH_SIZE + MVPP2_SKB_HEADROOM, rx_bytes, false); + /* This code is invoked within a single NAPI poll cycle + * and thus under local_bh_disable(), which provides the + * needed RCU protection. + */ ret = mvpp2_run_xdp(port, xdp_prog, &xdp, pp, &ps); if (ret) { @@ -3988,8 +3990,6 @@ static int mvpp2_rx(struct mvpp2_port *port, struct napi_struct *napi, mvpp2_bm_pool_put(port, pool, dma_addr, phys_addr); } - rcu_read_unlock(); - if (xdp_ret & MVPP2_XDP_REDIR) xdp_do_flush_map(); From patchwork Tue Jun 15 14:54:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 12322121 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB42FC48BE5 for ; Tue, 15 Jun 2021 15:04:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A897D61613 for ; Tue, 15 Jun 2021 15:04:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231352AbhFOPGc (ORCPT ); Tue, 15 Jun 2021 11:06:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:55842 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231274AbhFOPGb (ORCPT ); Tue, 15 Jun 2021 11:06:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623769466; 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=ZxWYziQTh5PhGh5gNlqbhBcg5NmHZI8IP9BRx6C+a+c=; b=XB4l3/O/suW1/oQS+SyKUA7b1NJkbodqYf/W19VZ5neF0zlbV3EI72c4x45yqpFslg9zvb Dl38up0+kDte/PoD5BgJOvkE+toL8anQxg8yAXyIWXuOHRLKjqWef4p/DjqlU6VqOE95N7 HPYxPCN6HxlmoRHDk0sKpkoGJxJTiR8= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-389-IiBGbGenMfap1EEU4PHaEQ-1; Tue, 15 Jun 2021 11:04:25 -0400 X-MC-Unique: IiBGbGenMfap1EEU4PHaEQ-1 Received: by mail-ed1-f69.google.com with SMTP id g13-20020a056402090db02903935a4cb74fso16641139edz.1 for ; Tue, 15 Jun 2021 08:04:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZxWYziQTh5PhGh5gNlqbhBcg5NmHZI8IP9BRx6C+a+c=; b=Zj/VPn376KaaJZkMnU4YK4pxYRjbT3YBqI2IWaM3NU9G1kEPxYZ6JWmeif2CSuS+on wh1oIKjvfe59OmJP9FXF8K8JlA8+ltlQnyZ7t6KgczyXhBJ1IhGG+2ifVRCbPp9YPMhF 6NxdE1pWT/Vjg8L6H/n+hTMmOuCmmy4oTpL5RO7yeIuo7GV+YM25W4JQxm1KgUZ5Um4r T2yzr3cfHmDNOF71x/3WqspmSk4mI4l801bnweVo66UhVW7KWfoa/Da1BGjSbLYPUDB+ /t05efJuFR9b2vYKmXH+aPqICfNaOWi1vFFuG5pMOGcgGFUxA8opAxo/PLxmahQNJmLs O5DA== X-Gm-Message-State: AOAM531uwLSr/CrHzQlCvvgNkTsDKJ+2Syxv/UYa12aAOqjIhPjqE1Ru 4eUwXYqQTkwjOP1CQ8gEnimlIrcIRvSJ1WvLO+UxBcub5rshRXG0fgC+c52ISs++1SyvHS44lnd XeiEpX89H/H5f X-Received: by 2002:a17:907:948f:: with SMTP id dm15mr21421644ejc.476.1623769463932; Tue, 15 Jun 2021 08:04:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzx2MELp8drUahchRUWbn1SY+20azHa5F2l+fLZOj+MrTocl/HB0ciEMAf412RgNG99qLgGdQ== X-Received: by 2002:a17:907:948f:: with SMTP id dm15mr21421618ejc.476.1623769463698; Tue, 15 Jun 2021 08:04:23 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id u15sm12545189edy.29.2021.06.15.08.04.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 08:04:22 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id EBE61180733; Tue, 15 Jun 2021 16:54:58 +0200 (CEST) From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: bpf@vger.kernel.org, netdev@vger.kernel.org Cc: Martin KaFai Lau , Hangbin Liu , Jesper Dangaard Brouer , Magnus Karlsson , "Paul E . McKenney" , Jakub Kicinski , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= , Tariq Toukan Subject: [PATCH bpf-next v2 10/16] mlx4: remove rcu_read_lock() around XDP program invocation Date: Tue, 15 Jun 2021 16:54:49 +0200 Message-Id: <20210615145455.564037-11-toke@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615145455.564037-1-toke@redhat.com> References: <20210615145455.564037-1-toke@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The mlx4 driver has rcu_read_lock()/rcu_read_unlock() pairs around XDP program invocations. However, the actual lifetime of the objects referred by the XDP program invocation is longer, all the way through to the call to xdp_do_flush(), making the scope of the rcu_read_lock() too small. This turns out to be harmless because it all happens in a single NAPI poll cycle (and thus under local_bh_disable()), but it makes the rcu_read_lock() misleading. Rather than extend the scope of the rcu_read_lock(), just get rid of it entirely. With the addition of RCU annotations to the XDP_REDIRECT map types that take bh execution into account, lockdep even understands this to be safe, so there's really no reason to keep it around. Also switch the RCU dereferences in the driver loop itself to the _bh variants. Cc: Tariq Toukan Reviewed-by: Tariq Toukan Signed-off-by: Toke Høiland-Jørgensen --- drivers/net/ethernet/mellanox/mlx4/en_rx.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c b/drivers/net/ethernet/mellanox/mlx4/en_rx.c index e35e4d7ef4d1..3f08c14d0441 100644 --- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c +++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c @@ -679,9 +679,7 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int bud ring = priv->rx_ring[cq_ring]; - /* Protect accesses to: ring->xdp_prog, priv->mac_hash list */ - rcu_read_lock(); - xdp_prog = rcu_dereference(ring->xdp_prog); + xdp_prog = rcu_dereference_bh(ring->xdp_prog); xdp_init_buff(&xdp, priv->frag_info[0].frag_stride, &ring->xdp_rxq); doorbell_pending = false; @@ -744,7 +742,7 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int bud /* Drop the packet, since HW loopback-ed it */ mac_hash = ethh->h_source[MLX4_EN_MAC_HASH_IDX]; bucket = &priv->mac_hash[mac_hash]; - hlist_for_each_entry_rcu(entry, bucket, hlist) { + hlist_for_each_entry_rcu_bh(entry, bucket, hlist) { if (ether_addr_equal_64bits(entry->mac, ethh->h_source)) goto next; @@ -899,8 +897,6 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int bud break; } - rcu_read_unlock(); - if (likely(polled)) { if (doorbell_pending) { priv->tx_cq[TX_XDP][cq_ring]->xdp_busy = true; From patchwork Tue Jun 15 14:54:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 12322123 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B17AC49EA2 for ; Tue, 15 Jun 2021 15:04:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8162761601 for ; Tue, 15 Jun 2021 15:04:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231311AbhFOPGd (ORCPT ); Tue, 15 Jun 2021 11:06:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21604 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230314AbhFOPGc (ORCPT ); Tue, 15 Jun 2021 11:06:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623769468; 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=0tvsP/yH9Ey7XMq3RE8CaFyAMq7vmXoKEd6exr5zYNI=; b=eCORax4uO5k2CM7Vp2+MXWizqgWJsol/U6u35NtFtxkiJcjKZ0dvjPDXHztXNKJ4YWDbFs KzprcpuOQaNk96QSNCXokRgxm85XBDhgwsvxIwtXKBI/TbmhjjqCDuja3FqBWSL43HFvcA etNheASrGPdAK/pAyehDKLrhQi3BTP8= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-443-PcR7eYlROxWriN2monNDCQ-1; Tue, 15 Jun 2021 11:04:26 -0400 X-MC-Unique: PcR7eYlROxWriN2monNDCQ-1 Received: by mail-ed1-f72.google.com with SMTP id v8-20020a0564023488b0290393873961f6so15048366edc.17 for ; Tue, 15 Jun 2021 08:04:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0tvsP/yH9Ey7XMq3RE8CaFyAMq7vmXoKEd6exr5zYNI=; b=s8STSESAvDyW3w21AjIY5D3IjBXEX52nKwpQFN/gOSstVQLfuaZptahr741H2nN1la FkVmvZMOYPZI8D0njKIn1uI12TBLHdjuBwscN6F2ldxzo/4qAVVnFVReVeyvDrc94mnT LnQJOvhYjy3IxHH37JvhXhLU7w7I+RQuEKwCtU5FQ5BBCzCzYH6RYJpiYjS4YwRvXo5f Xy9M0Ww8j2C4cHcme8RJMDX8ZqzWg6p0w3UaiuqlVkq3GN3tgzYaIxCiF94GYK+Fjyd7 IPTT1BNHE2JVS+cWJ7NnUUwWT6RTamqwWk3vERgVUYmazgBaQCKRlCWXKQFuF9NQl6DN DyrQ== X-Gm-Message-State: AOAM530S73Z42iRKDrwqB2+AYLsfmwU96X/m5jpWVA/lgzK4m2oa3lDW c6BvIwyZz59toHD6J+jFWxR2IZRvQ4AR3faS9Rxy3zR3q0OCDZudO0wvaMzvsLgW2anYnGhVIsc cjRrRWZyR499+ X-Received: by 2002:a05:6402:1592:: with SMTP id c18mr23778746edv.2.1623769464225; Tue, 15 Jun 2021 08:04:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxlhK4Hyjzlmys+ZL4H0SJamx7Lw/4wa7JVAWKdG+DZ3iR+0/DA89DGjdClsHUXjjgeYnQqlQ== X-Received: by 2002:a05:6402:1592:: with SMTP id c18mr23778723edv.2.1623769464026; Tue, 15 Jun 2021 08:04:24 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id e22sm12535481edv.57.2021.06.15.08.04.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 08:04:22 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id F0FBD180734; Tue, 15 Jun 2021 16:54:58 +0200 (CEST) From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: bpf@vger.kernel.org, netdev@vger.kernel.org Cc: Martin KaFai Lau , Hangbin Liu , Jesper Dangaard Brouer , Magnus Karlsson , "Paul E . McKenney" , Jakub Kicinski , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= , Simon Horman , oss-drivers@netronome.com Subject: [PATCH bpf-next v2 11/16] nfp: remove rcu_read_lock() around XDP program invocation Date: Tue, 15 Jun 2021 16:54:50 +0200 Message-Id: <20210615145455.564037-12-toke@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615145455.564037-1-toke@redhat.com> References: <20210615145455.564037-1-toke@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The nfp driver has rcu_read_lock()/rcu_read_unlock() pairs around XDP program invocations. However, the actual lifetime of the objects referred by the XDP program invocation is longer, all the way through to the call to xdp_do_flush(), making the scope of the rcu_read_lock() too small. While this is not actually an issue for the nfp driver because it doesn't support XDP_REDIRECT (and thus doesn't call xdp_do_flush()), the rcu_read_lock() is still unneeded. And With the addition of RCU annotations to the XDP_REDIRECT map types that take bh execution into account, lockdep even understands this to be safe, so there's really no reason to keep it around. Cc: Simon Horman Cc: oss-drivers@netronome.com Reviewed-by: Simon Horman Signed-off-by: Toke Høiland-Jørgensen --- drivers/net/ethernet/netronome/nfp/nfp_net_common.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c index eeb30680b4dc..a3d59abed6ae 100644 --- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c @@ -1819,7 +1819,6 @@ static int nfp_net_rx(struct nfp_net_rx_ring *rx_ring, int budget) struct xdp_buff xdp; int idx; - rcu_read_lock(); xdp_prog = READ_ONCE(dp->xdp_prog); true_bufsz = xdp_prog ? PAGE_SIZE : dp->fl_bufsz; xdp_init_buff(&xdp, PAGE_SIZE - NFP_NET_RX_BUF_HEADROOM, @@ -1919,6 +1918,10 @@ static int nfp_net_rx(struct nfp_net_rx_ring *rx_ring, int budget) pkt_off - NFP_NET_RX_BUF_HEADROOM, pkt_len, true); + /* This code is invoked within a single NAPI poll cycle + * and thus under local_bh_disable(), which provides the + * needed RCU protection. + */ act = bpf_prog_run_xdp(xdp_prog, &xdp); pkt_len = xdp.data_end - xdp.data; @@ -2036,7 +2039,6 @@ static int nfp_net_rx(struct nfp_net_rx_ring *rx_ring, int budget) if (!nfp_net_xdp_complete(tx_ring)) pkts_polled = budget; } - rcu_read_unlock(); return pkts_polled; } From patchwork Tue Jun 15 14:54:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 12322067 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1EAA7C48BE5 for ; Tue, 15 Jun 2021 14:55:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 08FA061584 for ; Tue, 15 Jun 2021 14:55:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231491AbhFOO5Q (ORCPT ); Tue, 15 Jun 2021 10:57:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:58911 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231379AbhFOO5M (ORCPT ); Tue, 15 Jun 2021 10:57:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623768907; 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=pWOmo2Dp6By21aiJoC+yh22NhewuBztqhmsfyiwQHMk=; b=NEMRMdHzd5MSDhuRDJJgbmjb496iVQ7TcwcnPE6RlxUxLRighUaXY7dGrcZEG1bDPoutwQ j95+SROQrr0woT6uvoVq/kNGTbIBhm4fwjfdbI4o+xUer6yLhlfcvaCz/PxYAJ1noLCRTt 3h8UEp8XQEEL2nyCEOyCqtENdQDmlfI= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-298-h-LcuI6jOMSkW-6pVcExPQ-1; Tue, 15 Jun 2021 10:55:06 -0400 X-MC-Unique: h-LcuI6jOMSkW-6pVcExPQ-1 Received: by mail-ej1-f70.google.com with SMTP id e11-20020a170906080bb02903f9c27ad9f5so4642602ejd.6 for ; Tue, 15 Jun 2021 07:55:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pWOmo2Dp6By21aiJoC+yh22NhewuBztqhmsfyiwQHMk=; b=GRVrmrohke5JCxLS0e9Vh5VakBQjw2/3VwQwHd8ALsZ8ADZNZOUB70xqraZQG985gE ocBo2SOlD6dUjBIxPZ1b36bg5ZMlrw+6xNRpBaUFhJMNHW3EW41QmPHZF+LRe8iibM8d X7fG9yg27uPRuBlAWSze4W2daa0jJMtepQWDaPCZ5b8UAsfLR2w76VkV5K3YaG7bwg70 Nq3XSJBMZNgxg6kze4vFxSTJh8RG/MPZYuPE1dCrI5bA9APB5ISrAF730eTrv9e8o0qS cv7Y5krD/qv91K4zycPOfn1ZJSIMMYPWfXkWq//Ce178lgKzRFiG9R6ThsFzqO01f8/8 MNbQ== X-Gm-Message-State: AOAM531qfHmcrQWnuL2kCLcrhvWGVU6aEnUw5h0mAs8/mwWbdyKnmfqh +pkzKAn6wQ0UGW6nznXUPamFp4infsZcYieCZr9oGRMkyBRTm05Bz0Z7NLAGovwqDk0wuvRrb1b zYpeJ/sbk/53q X-Received: by 2002:a17:906:5ac7:: with SMTP id x7mr5156293ejs.330.1623768905246; Tue, 15 Jun 2021 07:55:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzReB1fFu1rxm9m0nqkBN7wrp4chHKHdJVz9CZHmQ8NOXRhVatb2uiKb9hWHsPUxKuHc0Lkog== X-Received: by 2002:a17:906:5ac7:: with SMTP id x7mr5156279ejs.330.1623768905088; Tue, 15 Jun 2021 07:55:05 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id qh23sm10187974ejb.77.2021.06.15.07.55.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 07:55:04 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 08B1B180735; Tue, 15 Jun 2021 16:54:59 +0200 (CEST) From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: bpf@vger.kernel.org, netdev@vger.kernel.org Cc: Martin KaFai Lau , Hangbin Liu , Jesper Dangaard Brouer , Magnus Karlsson , "Paul E . McKenney" , Jakub Kicinski , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= , Ariel Elior , GR-everest-linux-l2@marvell.com Subject: [PATCH bpf-next v2 12/16] qede: remove rcu_read_lock() around XDP program invocation Date: Tue, 15 Jun 2021 16:54:51 +0200 Message-Id: <20210615145455.564037-13-toke@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615145455.564037-1-toke@redhat.com> References: <20210615145455.564037-1-toke@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The qede driver has rcu_read_lock()/rcu_read_unlock() pairs around XDP program invocations. However, the actual lifetime of the objects referred by the XDP program invocation is longer, all the way through to the call to xdp_do_flush(), making the scope of the rcu_read_lock() too small. This turns out to be harmless because it all happens in a single NAPI poll cycle (and thus under local_bh_disable()), but it makes the rcu_read_lock() misleading. Rather than extend the scope of the rcu_read_lock(), just get rid of it entirely. With the addition of RCU annotations to the XDP_REDIRECT map types that take bh execution into account, lockdep even understands this to be safe, so there's really no reason to keep it around. Cc: Ariel Elior Cc: GR-everest-linux-l2@marvell.com Signed-off-by: Toke Høiland-Jørgensen --- drivers/net/ethernet/qlogic/qede/qede_fp.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/qlogic/qede/qede_fp.c b/drivers/net/ethernet/qlogic/qede/qede_fp.c index 8e150dd4f899..d806ab925cee 100644 --- a/drivers/net/ethernet/qlogic/qede/qede_fp.c +++ b/drivers/net/ethernet/qlogic/qede/qede_fp.c @@ -1089,13 +1089,10 @@ static bool qede_rx_xdp(struct qede_dev *edev, xdp_prepare_buff(&xdp, page_address(bd->data), *data_offset, *len, false); - /* Queues always have a full reset currently, so for the time - * being until there's atomic program replace just mark read - * side for map helpers. + /* This code is invoked within a single NAPI poll cycle and thus under + * local_bh_disable(), which provides the needed RCU protection. */ - rcu_read_lock(); act = bpf_prog_run_xdp(prog, &xdp); - rcu_read_unlock(); /* Recalculate, as XDP might have changed the headers */ *data_offset = xdp.data - xdp.data_hard_start; From patchwork Tue Jun 15 14:54:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 12322125 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89351C48BE8 for ; Tue, 15 Jun 2021 15:04:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7063E615FF for ; Tue, 15 Jun 2021 15:04:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231482AbhFOPGe (ORCPT ); Tue, 15 Jun 2021 11:06:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:53957 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231433AbhFOPGe (ORCPT ); Tue, 15 Jun 2021 11:06:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623769469; 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=nZyBRJPoB1j5/g6EWUWSPPNl7ozTkFFFt8p6irUhI/M=; b=bOgrqMspaxbKC5/kD7qfWMq0ym6BlEhLWZGoDiNXz7yAd75taJGDnwgw2K0ekXV8VTP3Vg LWhECBZ79HOYk2ZH/dde8QGeBJ7b6TKlnYoVT6hqDm8JSVao4NH/qGfzj7C6qbgV6N1kMY 5VRY4Q3Iirfdzi6ueeKFqqMcvigOlB0= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-344-FXJYciJEOQWoRI6ahd944w-1; Tue, 15 Jun 2021 11:04:25 -0400 X-MC-Unique: FXJYciJEOQWoRI6ahd944w-1 Received: by mail-ej1-f69.google.com with SMTP id nd10-20020a170907628ab02903a324b229bfso4679640ejc.7 for ; Tue, 15 Jun 2021 08:04:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nZyBRJPoB1j5/g6EWUWSPPNl7ozTkFFFt8p6irUhI/M=; b=TF/B1lGBzpvgR94oJCPPW7qcyhy34RSZspjFYsET0gsr+5ZDg2m0qYf3BVc2cyNXAz e62VNEk9mPGQWAdAJp7hmF8R2NYLPh0P9YHtYne9qiE/j9hzz1JSVY8H8DfYeeMgJOyY N3oB2V9RNgLxptRE+rSpy7j8u1INx/sfBWhVn5MoCugqwfddCzuVKTaPr+vcEd72d5xn +wxPZl2ftC2V1pecjFyhBZNTOYwNS4BU1lbZGKUzd2vU97gA4xtxr9crhKMUL3J+UzMT N1RXwmOzIJ9BZmSAf1jrgEq+TVoehgBTNW3XCie451gTcMdchjbfBgeGS9qiUd8VGBn7 5nlA== X-Gm-Message-State: AOAM53386reQ5z5ReE7g6eHi2NRcCuVQCUjJTEF3PyTJqdt3sNJNJmEn 7vRSSiYKl/zIK1V7X5BJClgjE33AXMIejog/U8hGq9z1gWoQsccu4qB+q7yVa6xeY6ZKj/xGYle P6wP37RLpzaLe X-Received: by 2002:a50:fb8f:: with SMTP id e15mr23315226edq.46.1623769464510; Tue, 15 Jun 2021 08:04:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytWmHoc5NSv2Ml6IB/zXKszT4ABcEjPhTM0+V3qJGdbm2cn7dpYji1+8/ONPwzQWZqoX25Dg== X-Received: by 2002:a50:fb8f:: with SMTP id e15mr23315193edq.46.1623769464293; Tue, 15 Jun 2021 08:04:24 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id u21sm7514919eja.59.2021.06.15.08.04.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 08:04:23 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 1744F180736; Tue, 15 Jun 2021 16:54:59 +0200 (CEST) From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: bpf@vger.kernel.org, netdev@vger.kernel.org Cc: Martin KaFai Lau , Hangbin Liu , Jesper Dangaard Brouer , Magnus Karlsson , "Paul E . McKenney" , Jakub Kicinski , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= , Edward Cree , Martin Habets Subject: [PATCH bpf-next v2 13/16] sfc: remove rcu_read_lock() around XDP program invocation Date: Tue, 15 Jun 2021 16:54:52 +0200 Message-Id: <20210615145455.564037-14-toke@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615145455.564037-1-toke@redhat.com> References: <20210615145455.564037-1-toke@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The sfc driver has rcu_read_lock()/rcu_read_unlock() pairs around XDP program invocations. However, the actual lifetime of the objects referred by the XDP program invocation is longer, all the way through to the call to xdp_do_flush(), making the scope of the rcu_read_lock() too small. This turns out to be harmless because it all happens in a single NAPI poll cycle (and thus under local_bh_disable()), but it makes the rcu_read_lock() misleading. Rather than extend the scope of the rcu_read_lock(), just get rid of it entirely. With the addition of RCU annotations to the XDP_REDIRECT map types that take bh execution into account, lockdep even understands this to be safe, so there's really no reason to keep it around. Cc: Edward Cree Cc: Martin Habets Acked-by: Edward Cree Signed-off-by: Toke Høiland-Jørgensen --- drivers/net/ethernet/sfc/rx.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/sfc/rx.c b/drivers/net/ethernet/sfc/rx.c index 17b8119c48e5..3e5b88ab42db 100644 --- a/drivers/net/ethernet/sfc/rx.c +++ b/drivers/net/ethernet/sfc/rx.c @@ -260,18 +260,14 @@ static bool efx_do_xdp(struct efx_nic *efx, struct efx_channel *channel, s16 offset; int err; - rcu_read_lock(); - xdp_prog = rcu_dereference(efx->xdp_prog); - if (!xdp_prog) { - rcu_read_unlock(); + xdp_prog = rcu_dereference_bh(efx->xdp_prog); + if (!xdp_prog) return true; - } rx_queue = efx_channel_get_rx_queue(channel); if (unlikely(channel->rx_pkt_n_frags > 1)) { /* We can't do XDP on fragmented packets - drop. */ - rcu_read_unlock(); efx_free_rx_buffers(rx_queue, rx_buf, channel->rx_pkt_n_frags); if (net_ratelimit()) @@ -295,8 +291,10 @@ static bool efx_do_xdp(struct efx_nic *efx, struct efx_channel *channel, xdp_prepare_buff(&xdp, *ehp - EFX_XDP_HEADROOM, EFX_XDP_HEADROOM, rx_buf->len, false); + /* This code is invoked within a single NAPI poll cycle and thus under + * local_bh_disable(), which provides the needed RCU protection. + */ xdp_act = bpf_prog_run_xdp(xdp_prog, &xdp); - rcu_read_unlock(); offset = (u8 *)xdp.data - *ehp; From patchwork Tue Jun 15 14:54:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 12322127 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD5BAC48BE5 for ; Tue, 15 Jun 2021 15:05:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9A8D361584 for ; Tue, 15 Jun 2021 15:05:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230516AbhFOPHE (ORCPT ); Tue, 15 Jun 2021 11:07:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:23417 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230438AbhFOPHD (ORCPT ); Tue, 15 Jun 2021 11:07:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623769498; 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=YfPOjpqs+xPPviaak2ogNv+B986oj5TZMO/NC3oJo44=; b=h3+DttZKcpaUYsQQyVgmb/rg5bsBQHy8XyWMU7rc3orU8RoFf+FNng0TVh4c/o/l8ok3OC Tuux2lLiMl1wy5YWc6yR1+LTrhuiIYr6TknkiycdLd3euz0Ox908J4eeS+CnunmW6wiuXh pp8OJocAOEZO+6CwiByU4vXDhvBNWKA= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-561-Ox5nhFSGNeuDvEBIWNxQFA-1; Tue, 15 Jun 2021 11:04:26 -0400 X-MC-Unique: Ox5nhFSGNeuDvEBIWNxQFA-1 Received: by mail-ed1-f71.google.com with SMTP id f12-20020a056402150cb029038fdcfb6ea2so22376454edw.14 for ; Tue, 15 Jun 2021 08:04:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YfPOjpqs+xPPviaak2ogNv+B986oj5TZMO/NC3oJo44=; b=GXO+tPvbbNV4CYAHxnLFOqRVP3IWVUIjFinT7+dlFZDAmRgb3ZR7UeBi4jJEHyLuUD 3cfG4DC1+zCnOCNapPO0jamgmrKlzGlM6tfw2EB4AD6ZGDOcsQZ68nXMGlTgEvxnCL8S w5XncZ2bphZdchamxCPwdK3mQ/GVadpYsmwGPPJNFoaUHVnj4sQ1L5b8Msj3ruzVfm+A q1orAPAeW5dSVJlqXPHz+KKkq1NBurWfZWGYxQYLOJyANTkNgSRCwYmLS74A3aosM+iE RBO5buQF8lYwgHp8eqlFY1cN6SY4l/V75fWj2UXEJolBa4gaZRBsawAfTiVAeYebEwlp zEmw== X-Gm-Message-State: AOAM5335fu4okTFdSGyW4SDS4CsHN08MRCkYHXHf0B3tQLrVTJN6QGx4 KzWfQu7yTlhJ3cOlXwc/fg8pzoqxG8IQZbzsXFGyi2lvQfGawq2o41AO1SnV4G3a8/p7xaywGL/ FM2aJSJmRGzG6 X-Received: by 2002:a50:fc9a:: with SMTP id f26mr23484753edq.216.1623769465617; Tue, 15 Jun 2021 08:04:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyy8TVWB3Ab3G+Ed06XwW3QccJKn8HJhXMLG8fARccSuyWGMMDysWF3YtrcYvvSs+y6ZDLVcw== X-Received: by 2002:a50:fc9a:: with SMTP id f26mr23484707edq.216.1623769465281; Tue, 15 Jun 2021 08:04:25 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id k21sm12184299edo.41.2021.06.15.08.04.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 08:04:23 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 21558180737; Tue, 15 Jun 2021 16:54:59 +0200 (CEST) From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: bpf@vger.kernel.org, netdev@vger.kernel.org Cc: Martin KaFai Lau , Hangbin Liu , Jesper Dangaard Brouer , Magnus Karlsson , "Paul E . McKenney" , Jakub Kicinski , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= , Jassi Brar , Ilias Apalodimas Subject: [PATCH bpf-next v2 14/16] netsec: remove rcu_read_lock() around XDP program invocation Date: Tue, 15 Jun 2021 16:54:53 +0200 Message-Id: <20210615145455.564037-15-toke@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615145455.564037-1-toke@redhat.com> References: <20210615145455.564037-1-toke@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The netsec driver has a rcu_read_lock()/rcu_read_unlock() pair around the full RX loop, covering everything up to and including xdp_do_flush(). This is actually the correct behaviour, but because it all happens in a single NAPI poll cycle (and thus under local_bh_disable()), it is also technically redundant. With the addition of RCU annotations to the XDP_REDIRECT map types that take bh execution into account, lockdep even understands this to be safe, so there's really no reason to keep the rcu_read_lock() around anymore, so let's just remove it. Cc: Jassi Brar Cc: Ilias Apalodimas Acked-by: Ilias Apalodimas Signed-off-by: Toke Høiland-Jørgensen --- drivers/net/ethernet/socionext/netsec.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/socionext/netsec.c b/drivers/net/ethernet/socionext/netsec.c index dfc85cc68173..e07b7c870046 100644 --- a/drivers/net/ethernet/socionext/netsec.c +++ b/drivers/net/ethernet/socionext/netsec.c @@ -958,7 +958,6 @@ static int netsec_process_rx(struct netsec_priv *priv, int budget) xdp_init_buff(&xdp, PAGE_SIZE, &dring->xdp_rxq); - rcu_read_lock(); xdp_prog = READ_ONCE(priv->xdp_prog); dma_dir = page_pool_get_dma_dir(dring->page_pool); @@ -1019,6 +1018,10 @@ static int netsec_process_rx(struct netsec_priv *priv, int budget) pkt_len, false); if (xdp_prog) { + /* This code is invoked within a single NAPI poll cycle + * and thus under local_bh_disable(), which provides the + * needed RCU protection. + */ xdp_result = netsec_run_xdp(priv, xdp_prog, &xdp); if (xdp_result != NETSEC_XDP_PASS) { xdp_act |= xdp_result; @@ -1069,8 +1072,6 @@ static int netsec_process_rx(struct netsec_priv *priv, int budget) } netsec_finalize_xdp_rx(priv, xdp_act, xdp_xmit); - rcu_read_unlock(); - return done; } From patchwork Tue Jun 15 14:54:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 12322075 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 136E2C49EAF for ; Tue, 15 Jun 2021 14:55:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F23586161C for ; Tue, 15 Jun 2021 14:55:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231551AbhFOO5V (ORCPT ); Tue, 15 Jun 2021 10:57:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45010 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231482AbhFOO5Q (ORCPT ); Tue, 15 Jun 2021 10:57:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623768911; 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=ByKk7NdGTOHi1KbabnH0lRUOaQxO13c2A34mff7i6os=; b=SbAXjpPeYT+081YcqQbCEc8ZSMc37BXsmElgi/VtCLhuLZ1BA5ZoLFdcADbU4psCwKfhUg NJvwgHh8OUtY4ZU4OeHBEtLcaX2K0uc5Ykn8ir1LAcs9b7iwrx/IPSmE0KLNYWeFQli3cG t4pnlzYFJMLLFWspKn+KBlK/a8H9NCI= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-97-nXq09iPYP2a4b3YRpnoBtA-1; Tue, 15 Jun 2021 10:55:10 -0400 X-MC-Unique: nXq09iPYP2a4b3YRpnoBtA-1 Received: by mail-ej1-f72.google.com with SMTP id q7-20020a1709063607b02903f57f85ac45so4635283ejb.15 for ; Tue, 15 Jun 2021 07:55:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ByKk7NdGTOHi1KbabnH0lRUOaQxO13c2A34mff7i6os=; b=oQuWDbb4fyeqMSwu/flRWV4eTdewq7BoZoCMknDsOYP4LIWENVAbGQ9491b6bjNnfR cTjfLHy03UjLZrA0N6rUElfFeXegoU0zheGHf9y/Ql0vpiVMvLa75tIIk0hGzn/tjxAa fqnySbIdekUoSFA/jWKzdFVA1XVSeFnHc4jvfvHeprE151N5OvHo5/FsqX+PGSpfwbee pIMK5E8O9iI5Ww1Os5+QkiDuQ5plvRpp9Ac4AfdJ5DlQnzJ6fjFF8cGOc3e8dHC0/EUB 0J94jnP62PI8DEXlB6Av04Q+bavfCxOoCGl5o3kfpvHqPY6kK0XXALDgz8UDnje521AN BD0Q== X-Gm-Message-State: AOAM531pXo1UezQlomZimiO3ScmtLHU1a1sj5VBsJ/q6Zx2jvgb9XFsg q3U1wC6rh42qYPNm6Rxd82o6//ffHmstTOaaJ5lQZ2MGNNhnjjVLlPc9cIFVP0+9FAIzH81Eo2Q AEEtmxipnV8zn X-Received: by 2002:a17:906:1790:: with SMTP id t16mr21140737eje.203.1623768908968; Tue, 15 Jun 2021 07:55:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzO7NzkHVdn3I9zDxJvs+KHKQGP1gNNIkOvx0CUNjvYdIP8qMYlgja+FT1bnm1L0s5u+E2uKg== X-Received: by 2002:a17:906:1790:: with SMTP id t16mr21140717eje.203.1623768908806; Tue, 15 Jun 2021 07:55:08 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id o20sm11770169eds.20.2021.06.15.07.55.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 07:55:06 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 28118180738; Tue, 15 Jun 2021 16:54:59 +0200 (CEST) From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: bpf@vger.kernel.org, netdev@vger.kernel.org Cc: Martin KaFai Lau , Hangbin Liu , Jesper Dangaard Brouer , Magnus Karlsson , "Paul E . McKenney" , Jakub Kicinski , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= , Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu Subject: [PATCH bpf-next v2 15/16] stmmac: remove rcu_read_lock() around XDP program invocation Date: Tue, 15 Jun 2021 16:54:54 +0200 Message-Id: <20210615145455.564037-16-toke@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615145455.564037-1-toke@redhat.com> References: <20210615145455.564037-1-toke@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The stmmac driver has rcu_read_lock()/rcu_read_unlock() pairs around XDP program invocations. However, the actual lifetime of the objects referred by the XDP program invocation is longer, all the way through to the call to xdp_do_flush(), making the scope of the rcu_read_lock() too small. This turns out to be harmless because it all happens in a single NAPI poll cycle (and thus under local_bh_disable()), but it makes the rcu_read_lock() misleading. Rather than extend the scope of the rcu_read_lock(), just get rid of it entirely. With the addition of RCU annotations to the XDP_REDIRECT map types that take bh execution into account, lockdep even understands this to be safe, so there's really no reason to keep it around. Cc: Giuseppe Cavallaro Cc: Alexandre Torgue Cc: Jose Abreu Signed-off-by: Toke Høiland-Jørgensen --- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index bf9fe25fed69..5dcc8a42abf9 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -4654,7 +4654,6 @@ static int stmmac_xdp_xmit_back(struct stmmac_priv *priv, return res; } -/* This function assumes rcu_read_lock() is held by the caller. */ static int __stmmac_xdp_run_prog(struct stmmac_priv *priv, struct bpf_prog *prog, struct xdp_buff *xdp) @@ -4662,6 +4661,9 @@ static int __stmmac_xdp_run_prog(struct stmmac_priv *priv, u32 act; int res; + /* This code is invoked within a single NAPI poll cycle and thus under + * local_bh_disable(), which provides the needed RCU protection. + */ act = bpf_prog_run_xdp(prog, xdp); switch (act) { case XDP_PASS: @@ -4696,17 +4698,14 @@ static struct sk_buff *stmmac_xdp_run_prog(struct stmmac_priv *priv, struct bpf_prog *prog; int res; - rcu_read_lock(); - prog = READ_ONCE(priv->xdp_prog); if (!prog) { res = STMMAC_XDP_PASS; - goto unlock; + goto out; } res = __stmmac_xdp_run_prog(priv, prog, xdp); -unlock: - rcu_read_unlock(); +out: return ERR_PTR(-res); } @@ -4976,10 +4975,8 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue) buf->xdp->data_end = buf->xdp->data + buf1_len; xsk_buff_dma_sync_for_cpu(buf->xdp, rx_q->xsk_pool); - rcu_read_lock(); prog = READ_ONCE(priv->xdp_prog); res = __stmmac_xdp_run_prog(priv, prog, buf->xdp); - rcu_read_unlock(); switch (res) { case STMMAC_XDP_PASS: From patchwork Tue Jun 15 14:54:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= X-Patchwork-Id: 12322071 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 144FAC49EA3 for ; Tue, 15 Jun 2021 14:55:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 028486161E for ; Tue, 15 Jun 2021 14:55:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231461AbhFOO5S (ORCPT ); Tue, 15 Jun 2021 10:57:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:31926 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231439AbhFOO5P (ORCPT ); Tue, 15 Jun 2021 10:57:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623768910; 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=7zXHSL7RwyAJWnz3yfpZ7/QXhLd143qN0GShu6MwfqY=; b=GFGug33ocwRA9NG0Gg6g6zaTYvemTjQmMlyWA2Mk4JLjhLLaq0FmnRq18KZ90sErhVrj7w 4PJs96x9T7bvstC5aaIv0+TEuS3rmPvmxG38WOTlAgUXSgF3VdxTKjBE+8AnVrTIASGS+k P2g0IVMZUY0zKUVfYQjrQkU7WlkvA4o= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-3-mi7_TPJJPoOAcbNmZge7yw-1; Tue, 15 Jun 2021 10:55:09 -0400 X-MC-Unique: mi7_TPJJPoOAcbNmZge7yw-1 Received: by mail-ed1-f70.google.com with SMTP id x8-20020aa7d3880000b029038fe468f5f4so22264327edq.10 for ; Tue, 15 Jun 2021 07:55:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7zXHSL7RwyAJWnz3yfpZ7/QXhLd143qN0GShu6MwfqY=; b=uHLFbAAxGBwiEPvpSi8lY1QSRWmxSCZhoqwdYmbXd2JDBgPh7UwIz2+pYkk9sqfn3a NAjItFM5bHsR+IINqyMp1kXI0e0mj1SN+A0+7+GIy+wRfUa6Y2WuRlSu19bYwNA2wLHw R6ntldFUGroIaLNXjb7B2BhQ1VSDdNGDO4QaQqO+xLpXOqepfT673UW981ivHQYvkRe7 CEYL1HoZKQ7DpNbUvdeSkB5u7FL+cZJl/xLSxtG1qhBT3TNwmuBYoRlxK4+sbUg2iWNw HSSzACwvrnDhAuBonOAIi+zywc9pfI1NVtWmBrOoFTSKPUzGOI7GYCUciuIa3sOGQj5X 3+MA== X-Gm-Message-State: AOAM533rxeVogymCFAKVpf5bSJltD1DK3XRdqY4kUYSMjHrSG/xJv4hv xB212Gho+jetKXGxaRo4NeAPhf9H8RnyeczkPMtGKzZHzfyUvHPLLaEyVxwtt+Fv4IBU+8YJ2Xv WahoIWfhgVLY3 X-Received: by 2002:a05:6402:1652:: with SMTP id s18mr23048009edx.131.1623768908124; Tue, 15 Jun 2021 07:55:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAy/n5Es33Uj8+GjOWq3YRmuEbjhuD5rzEEzzfpqUH7cASDVtLd3bVhCfFDT4UAd0JjxkZnQ== X-Received: by 2002:a05:6402:1652:: with SMTP id s18mr23047988edx.131.1623768907804; Tue, 15 Jun 2021 07:55:07 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id f8sm9985632ejw.75.2021.06.15.07.55.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 07:55:05 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 354DC180739; Tue, 15 Jun 2021 16:54:59 +0200 (CEST) From: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= To: bpf@vger.kernel.org, netdev@vger.kernel.org Cc: Martin KaFai Lau , Hangbin Liu , Jesper Dangaard Brouer , Magnus Karlsson , "Paul E . McKenney" , Jakub Kicinski , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= , Grygorii Strashko , linux-omap@vger.kernel.org Subject: [PATCH bpf-next v2 16/16] net: ti: remove rcu_read_lock() around XDP program invocation Date: Tue, 15 Jun 2021 16:54:55 +0200 Message-Id: <20210615145455.564037-17-toke@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615145455.564037-1-toke@redhat.com> References: <20210615145455.564037-1-toke@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The cpsw driver has rcu_read_lock()/rcu_read_unlock() pairs around XDP program invocations. However, the actual lifetime of the objects referred by the XDP program invocation is longer, all the way through to the call to xdp_do_flush(), making the scope of the rcu_read_lock() too small. This turns out to be harmless because it all happens in a single NAPI poll cycle (and thus under local_bh_disable()), but it makes the rcu_read_lock() misleading. Rather than extend the scope of the rcu_read_lock(), just get rid of it entirely. With the addition of RCU annotations to the XDP_REDIRECT map types that take bh execution into account, lockdep even understands this to be safe, so there's really no reason to keep it around. Cc: Grygorii Strashko Cc: linux-omap@vger.kernel.org Tested-by: Grygorii Strashko Reviewed-by: Grygorii Strashko Signed-off-by: Toke Høiland-Jørgensen --- drivers/net/ethernet/ti/cpsw_priv.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/ti/cpsw_priv.c b/drivers/net/ethernet/ti/cpsw_priv.c index 5862f0a4a975..25fa7304a542 100644 --- a/drivers/net/ethernet/ti/cpsw_priv.c +++ b/drivers/net/ethernet/ti/cpsw_priv.c @@ -1328,14 +1328,13 @@ int cpsw_run_xdp(struct cpsw_priv *priv, int ch, struct xdp_buff *xdp, struct bpf_prog *prog; u32 act; - rcu_read_lock(); - prog = READ_ONCE(priv->xdp_prog); - if (!prog) { - ret = CPSW_XDP_PASS; - goto out; - } + if (!prog) + return CPSW_XDP_PASS; + /* This code is invoked within a single NAPI poll cycle and thus under + * local_bh_disable(), which provides the needed RCU protection. + */ act = bpf_prog_run_xdp(prog, xdp); /* XDP prog might have changed packet data and boundaries */ *len = xdp->data_end - xdp->data; @@ -1378,10 +1377,8 @@ int cpsw_run_xdp(struct cpsw_priv *priv, int ch, struct xdp_buff *xdp, ndev->stats.rx_bytes += *len; ndev->stats.rx_packets++; out: - rcu_read_unlock(); return ret; drop: - rcu_read_unlock(); page_pool_recycle_direct(cpsw->page_pool[ch], page); return ret; }