From patchwork Wed Jun 23 11:07:10 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: 466255 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=-19.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, 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 543C9C4743C for ; Wed, 23 Jun 2021 11:07:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3C2D76108E for ; Wed, 23 Jun 2021 11:07:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230272AbhFWLKC (ORCPT ); Wed, 23 Jun 2021 07:10:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:22473 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230031AbhFWLJt (ORCPT ); Wed, 23 Jun 2021 07:09:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624446451; 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=gCA//v5U2zdeKF30MPJkPlDU8nWyKsxnTIF8PhfpTLo=; b=UkPKnQhOXhZkkthRmDLak/HJw93A8A9BCGnbgAQiW05V02r/H8m/IQCBRNbwUp5XPAixyG 9zbe72cIeatVKK0lw6GztBjwxxV/onXwvrjtDNOlJ9QCNWrsuFeGn6mZYBcYu/MHTLbcoh uIQj0E3DEp5An9O8axoZ9CT33byPQeg= 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-112-rKcmHtWRPOSF41u9txZZDg-1; Wed, 23 Jun 2021 07:07:30 -0400 X-MC-Unique: rKcmHtWRPOSF41u9txZZDg-1 Received: by mail-ed1-f71.google.com with SMTP id j19-20020aa7c4130000b029039497d5cdbeso1088607edq.15 for ; Wed, 23 Jun 2021 04:07:30 -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=gCA//v5U2zdeKF30MPJkPlDU8nWyKsxnTIF8PhfpTLo=; b=i3QgdDWiDw/vXSNdHlfWWw3PcKDdY2r2jvHc9MCHJtWnxjMrj4enFiPcDLPBYcqCUL p5b42V0pJ3bVyMiDkJJ0Dxkn9m8xxVBeGzluNR8jcZ4I6aisizCHhi2QQnJrG00r4bOq tKbA4gCL92w6mW755s2wBr6WI/hUt3nbgfbAUOVDcIje4+ar9ZSDtIQuv9eJ3cszr8Ko CjJEOzQPX2k8hk4rqkkTBfVEaDQFbRE+F71Fd8JjQWa3jlJiEUDnTAIq6Vi1qEB/BnBr fUwV5c8zPQ7atGeJptwcWfpm7iEG7VFm/pg6lXcjmlFB+CesxrwsG2AgsKbMwtV71/JI f0mg== X-Gm-Message-State: AOAM5334ERX5hmK8H5eNlnSIyKgPMZ2zVGdC8Qc9tutIQ6TEPzSWoEqa rxaNvBIRLbJDtYkBscVt1NZsjaLHfafaHem8YvDMZErJ97VDwtTZsd0gic3U4biYs1H0MlwL8nF t7y3j6DVLPbvLr+sB X-Received: by 2002:a05:6402:100e:: with SMTP id c14mr11312160edu.51.1624446449337; Wed, 23 Jun 2021 04:07:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxK5QVgpNKfKSNK2v/czWwASjaveoabV2SEAVqeVJeP9mCNaG4Ztjz6zIgdwue4LxXhpgF06A== X-Received: by 2002:a05:6402:100e:: with SMTP id c14mr11312118edu.51.1624446449004; Wed, 23 Jun 2021 04:07:29 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id cn10sm10177304edb.38.2021.06.23.04.07.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jun 2021 04:07:28 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 07804180732; Wed, 23 Jun 2021 13:07:28 +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-?= =?utf-8?q?J=C3=B8rgensen?= Subject: [PATCH bpf-next v4 02/19] doc: Clarify and expand RCU updaters and corresponding readers Date: Wed, 23 Jun 2021 13:07:10 +0200 Message-Id: <20210623110727.221922-3-toke@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210623110727.221922-1-toke@redhat.com> References: <20210623110727.221922-1-toke@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: "Paul E. McKenney" This commit clarifies which primitives readers can use given that the corresponding updaters have made a specific choice. This commit also adds this information for the various RCU Tasks flavors. While in the area, it removes a paragraph that no longer applies in any straightforward manner. Signed-off-by: Paul E. McKenney Signed-off-by: Toke Høiland-Jørgensen --- Documentation/RCU/checklist.rst | 48 ++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/Documentation/RCU/checklist.rst b/Documentation/RCU/checklist.rst index 1030119294d0..07f6cb8f674d 100644 --- a/Documentation/RCU/checklist.rst +++ b/Documentation/RCU/checklist.rst @@ -211,27 +211,33 @@ over a rather long period of time, but improvements are always welcome! of the system, especially to real-time workloads running on the rest of the system. -7. As of v4.20, a given kernel implements only one RCU flavor, - which is RCU-sched for PREEMPTION=n and RCU-preempt for PREEMPTION=y. - If the updater uses call_rcu() or synchronize_rcu(), - then the corresponding readers may use rcu_read_lock() and - rcu_read_unlock(), rcu_read_lock_bh() and rcu_read_unlock_bh(), - or any pair of primitives that disables and re-enables preemption, - for example, rcu_read_lock_sched() and rcu_read_unlock_sched(). - If the updater uses synchronize_srcu() or call_srcu(), - then the corresponding readers must use srcu_read_lock() and - srcu_read_unlock(), and with the same srcu_struct. The rules for - the expedited primitives are the same as for their non-expedited - counterparts. Mixing things up will result in confusion and - broken kernels, and has even resulted in an exploitable security - issue. - - One exception to this rule: rcu_read_lock() and rcu_read_unlock() - may be substituted for rcu_read_lock_bh() and rcu_read_unlock_bh() - in cases where local bottom halves are already known to be - disabled, for example, in irq or softirq context. Commenting - such cases is a must, of course! And the jury is still out on - whether the increased speed is worth it. +7. As of v4.20, a given kernel implements only one RCU flavor, which + is RCU-sched for PREEMPTION=n and RCU-preempt for PREEMPTION=y. + If the updater uses call_rcu() or synchronize_rcu(), then + the corresponding readers may use: (1) rcu_read_lock() and + rcu_read_unlock(), (2) any pair of primitives that disables + and re-enables softirq, for example, rcu_read_lock_bh() and + rcu_read_unlock_bh(), or (3) any pair of primitives that disables + and re-enables preemption, for example, rcu_read_lock_sched() and + rcu_read_unlock_sched(). If the updater uses synchronize_srcu() + or call_srcu(), then the corresponding readers must use + srcu_read_lock() and srcu_read_unlock(), and with the same + srcu_struct. The rules for the expedited RCU grace-period-wait + primitives are the same as for their non-expedited counterparts. + + If the updater uses call_rcu_tasks() or synchronize_rcu_tasks(), + then the readers must refrain from executing voluntary + context switches, that is, from blocking. If the updater uses + call_rcu_tasks_trace() or synchronize_rcu_tasks_trace(), then + the corresponding readers must use rcu_read_lock_trace() and + rcu_read_unlock_trace(). If an updater uses call_rcu_tasks_rude() + or synchronize_rcu_tasks_rude(), then the corresponding readers + must use anything that disables interrupts. + + Mixing things up will result in confusion and broken kernels, and + has even resulted in an exploitable security issue. Therefore, + when using non-obvious pairs of primitives, commenting is of + course a must. 8. Although synchronize_rcu() is slower than is call_rcu(), it usually results in simpler code. So, unless update performance is From patchwork Wed Jun 23 11:07:14 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: 466253 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=-19.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, 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 AD710C48BC2 for ; Wed, 23 Jun 2021 11:08:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 97B2461003 for ; Wed, 23 Jun 2021 11:08:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230436AbhFWLKZ (ORCPT ); Wed, 23 Jun 2021 07:10:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:37771 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230174AbhFWLJy (ORCPT ); Wed, 23 Jun 2021 07:09:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624446456; 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=w/RD8INVqrZhxhRYQu3p0iItEELqlKBFxEmUhyTn65o=; b=DFYu4DMGN3RwHXbmP+9cbPQYkVulaUttcBP5F6xoMiL3WYv7xAUugigQMpBQKAy8KX2hEC llUb8OpUfp507cq1L+O4LMaYhS8VHNHtDc/Fva2hAZUrdRx8rdJj9s5Kxtap1PR6ozFZzV aDDmugyzuvxZfLWpYcWCjO7Vbj2b89A= 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-189-9UrXy0KJNhqXC8xtWcrbqA-1; Wed, 23 Jun 2021 07:07:35 -0400 X-MC-Unique: 9UrXy0KJNhqXC8xtWcrbqA-1 Received: by mail-ej1-f70.google.com with SMTP id w13-20020a170906384db02903d9ad6b26d8so868174ejc.0 for ; Wed, 23 Jun 2021 04:07:35 -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=w/RD8INVqrZhxhRYQu3p0iItEELqlKBFxEmUhyTn65o=; b=Vra41TDCxIqTH3c6dWfIiA/WKuFb/IWA/dkgpxjH2s6gghDsBrkOAimN/Ms5YTmpr/ Hue35qO1gvlH8PxayHJoAlcvctSg3+mDZ6vSMcusUwWkk2gjlWOZie9oQe91nybuywhv zj5kvD49ZhbFRsNQ9iX6dfHQStQl/RhzPd0gq40f06DppXrvuJUp6C1Jaj5Qeakd82Zv mGA9YG4evSDVezdlhLVJ97SB1TWRuKY9jOHMtT6Q4lSkSGX30AMMmEUjSytVuGnzT+mL +oaAM6IHisX5tRl2QSmJF9uBA/8rvwKf8FputJkrKG3oE4MQoMWdrXMDO+KtM1Q/MvKy ZA4w== X-Gm-Message-State: AOAM5323muKABF2MD7zgdy282hnTQ28KnK2R+XC8/CGKl0ze5SQg5PA1 lEVBUHZ8Xb17K7DAW8CB8lNp6mblT3rewFXwDh7gD0y6Rj8AJdiLW6fLLa6C4ku8WN13pmAqNr0 0dNCF9WsMfcN7xc80 X-Received: by 2002:a05:6402:18f6:: with SMTP id x54mr11865253edy.53.1624446454209; Wed, 23 Jun 2021 04:07:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkLnLptVgUW3clOL3nBx1FYnj3knCIVTef6R4LuM+oJs85AS2SKwdWmRQkxek9cThzk7dCeg== X-Received: by 2002:a05:6402:18f6:: with SMTP id x54mr11865234edy.53.1624446454079; Wed, 23 Jun 2021 04:07:34 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id z20sm7246260ejd.18.2021.06.23.04.07.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jun 2021 04:07:29 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 1DB33180736; Wed, 23 Jun 2021 13:07:28 +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-?= =?utf-8?q?J=C3=B8rgensen?= Subject: [PATCH bpf-next v4 06/19] sched: remove unneeded rcu_read_lock() around BPF program invocation Date: Wed, 23 Jun 2021 13:07:14 +0200 Message-Id: <20210623110727.221922-7-toke@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210623110727.221922-1-toke@redhat.com> References: <20210623110727.221922-1-toke@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The rcu_read_lock() call in cls_bpf and act_bpf are redundant: on the TX side, there's already a call to rcu_read_lock_bh() in __dev_queue_xmit(), and on RX there's a covering rcu_read_lock() in netif_receive_skb{,_list}_internal(). With the previous patches we also amended the lockdep checks in the map code to not require any particular RCU flavour, so we can just get rid of the rcu_read_lock()s. Signed-off-by: Toke Høiland-Jørgensen --- net/sched/act_bpf.c | 2 -- net/sched/cls_bpf.c | 3 --- 2 files changed, 5 deletions(-) diff --git a/net/sched/act_bpf.c b/net/sched/act_bpf.c index e48e980c3b93..e409a0005717 100644 --- a/net/sched/act_bpf.c +++ b/net/sched/act_bpf.c @@ -43,7 +43,6 @@ static int tcf_bpf_act(struct sk_buff *skb, const struct tc_action *act, tcf_lastuse_update(&prog->tcf_tm); bstats_cpu_update(this_cpu_ptr(prog->common.cpu_bstats), skb); - rcu_read_lock(); filter = rcu_dereference(prog->filter); if (at_ingress) { __skb_push(skb, skb->mac_len); @@ -56,7 +55,6 @@ static int tcf_bpf_act(struct sk_buff *skb, const struct tc_action *act, } if (skb_sk_is_prefetched(skb) && filter_res != TC_ACT_OK) skb_orphan(skb); - rcu_read_unlock(); /* A BPF program may overwrite the default action opcode. * Similarly as in cls_bpf, if filter_res == -1 we use the diff --git a/net/sched/cls_bpf.c b/net/sched/cls_bpf.c index 6e3e63db0e01..fa739efa59f4 100644 --- a/net/sched/cls_bpf.c +++ b/net/sched/cls_bpf.c @@ -85,8 +85,6 @@ static int cls_bpf_classify(struct sk_buff *skb, const struct tcf_proto *tp, struct cls_bpf_prog *prog; int ret = -1; - /* Needed here for accessing maps. */ - rcu_read_lock(); list_for_each_entry_rcu(prog, &head->plist, link) { int filter_res; @@ -131,7 +129,6 @@ static int cls_bpf_classify(struct sk_buff *skb, const struct tcf_proto *tp, break; } - rcu_read_unlock(); return ret; } From patchwork Wed Jun 23 11:07:15 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: 466252 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=-19.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, 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 26526C4743C for ; Wed, 23 Jun 2021 11:08:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 11A6561003 for ; Wed, 23 Jun 2021 11:08:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230444AbhFWLK3 (ORCPT ); Wed, 23 Jun 2021 07:10:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:46929 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230204AbhFWLJz (ORCPT ); Wed, 23 Jun 2021 07:09:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624446457; 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=r8Kxje9mo0eA1OfdUdQS/iz/Q4P9zCSTZ9JCaTqfbwY=; b=LJ/LrixdY0DomJ1qdS+pxgzhaqOT9CEW3QPgifRTaeoZVKaIBnhZFij+ah/r7f/jxTFVA+ kLUCK/5s/5QAAbBDh0y4J63alDqtBb9vHu880OIZNaygFRrv9yTnccS5c2vT3V2nz1pbAi cVfcT6P/Sikq/Q6I599bWqwd9W4zVIU= 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-465-oHdCA3wqOJyQlgJUzHuk0A-1; Wed, 23 Jun 2021 07:07:36 -0400 X-MC-Unique: oHdCA3wqOJyQlgJUzHuk0A-1 Received: by mail-ed1-f70.google.com with SMTP id dy23-20020a05640231f7b0290394996f1452so1093107edb.18 for ; Wed, 23 Jun 2021 04:07:36 -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=r8Kxje9mo0eA1OfdUdQS/iz/Q4P9zCSTZ9JCaTqfbwY=; b=orOKDSy6rBjms9r77f4fF6HpbYh3TlHQctjVTk5bnU4TaDJDGnAM4U2R5VFSRC2TG3 YXOZQPW+d333t6kJzvOCrLSvCZ+VPwe/meXG+AyRnyc0CREmzkfdfgJ2dn0AO/Mml/qt i5Gk4jVISHAmHSG7u7+D2uRcdnW/uFXseMr2rJG0xbKaag8R+ByTyx599IbVt3qOwkh2 I0uCzL5XnIdhX9efAVU8QHBS/0DOb2HMWiYd64p9kFDOrI+ZjW6JZ4/J7jN66RZBkfP2 IIKhP0UXz2cgRuxhkkGwMnHU03kw+RrT/1LSDCDy/QuxhGEQmYx1+bwZKHWGxk2frQ0x W8hg== X-Gm-Message-State: AOAM531r7souSrKqJf3VO+BgE4K0D1Sd1PHdgw9j8quGpntblDwF0yqT m3RNh6UVmoaomUnrsz5CAx8IUWKlGcL9Y5l2Ex9zVms6A9iBebDv+3c/iEf4nUOaF14dPcXVxaO jMm+Joffbvas8usSK X-Received: by 2002:a17:907:2622:: with SMTP id aq2mr9352248ejc.48.1624446455075; Wed, 23 Jun 2021 04:07:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9y32Eh+jTvhrwfrV+XjryvNhw+II0gK5l99fd1c7Gry3y4vk/TmSfoejTBO7gW/Bf7bP9qw== X-Received: by 2002:a17:907:2622:: with SMTP id aq2mr9352206ejc.48.1624446454670; Wed, 23 Jun 2021 04:07:34 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id c15sm10860553edu.19.2021.06.23.04.07.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jun 2021 04:07:29 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 266CE180737; Wed, 23 Jun 2021 13:07:28 +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-?= =?utf-8?q?J=C3=B8rgensen?= , Guy Tzalik , Saeed Bishara Subject: [PATCH bpf-next v4 07/19] ena: remove rcu_read_lock() around XDP program invocation Date: Wed, 23 Jun 2021 13:07:15 +0200 Message-Id: <20210623110727.221922-8-toke@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210623110727.221922-1-toke@redhat.com> References: <20210623110727.221922-1-toke@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c index 881f88754bf6..a4378b14af4c 100644 --- a/drivers/net/ethernet/amazon/ena/ena_netdev.c +++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c @@ -385,7 +385,6 @@ static int ena_xdp_execute(struct ena_ring *rx_ring, struct xdp_buff *xdp) u64 *xdp_stat; int qid; - rcu_read_lock(); xdp_prog = READ_ONCE(rx_ring->xdp_bpf_prog); if (!xdp_prog) @@ -443,8 +442,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 Wed Jun 23 11:07:17 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: 466251 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=-19.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, 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 C78E3C4743C for ; Wed, 23 Jun 2021 11:08:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B18DB61003 for ; Wed, 23 Jun 2021 11:08:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230526AbhFWLKe (ORCPT ); Wed, 23 Jun 2021 07:10:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:59946 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230234AbhFWLJ5 (ORCPT ); Wed, 23 Jun 2021 07:09:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624446460; 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=2arA4F9H8piXSu2BaYZfrwo91oZXpALZLKMt5odcOCY=; b=RM0QewaZCDtUVr6mp4IlKWBtXVEtWd4JRiw+i2sKlCa8zcyAL0tSbtZxz8Cuxk+ZU4jJBC IyxY8+Gsx3FxzsJO92AHCoFuhSjaJgwgSy3lLxYaif7JYVdwqcOyKqy6Vkd4g++KfXq0pH vvUNnCWe4x1eC9XzOIL0lbIBJg0SeFg= 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-86-Wcu1KxwTNxiQiMROZyGsHw-1; Wed, 23 Jun 2021 07:07:38 -0400 X-MC-Unique: Wcu1KxwTNxiQiMROZyGsHw-1 Received: by mail-ej1-f71.google.com with SMTP id jw19-20020a17090776b3b0290481592f1fc4so853512ejc.2 for ; Wed, 23 Jun 2021 04:07:38 -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=2arA4F9H8piXSu2BaYZfrwo91oZXpALZLKMt5odcOCY=; b=jsapL2uD7qXYtvkndT29l4w9IkDogO95NRT2O2v5yVKnf8vRDOI8DQ+rbD/jADt5lO 5U5v3xbdN1ozDBmOWUTCyNaUSS1jcG3S1hV3/0PaZSoypr2j1x4ewKqGS//q1jA74s/7 IBXIdgqeVebSyyCj4dIVX7NdX0phbTTZDd9sjnaj4xmIAMs9fncIpBarfnCuEdA6ZI6o l18KaQzXpuoc5oUkS8+4mAo0nkFeB/eYCG01O8q+HfiurHgUEBwiGI4IMfdxYLC44ePv kIlGfv63ugWFKeuWQlbDjhLYaiC7/bYw9z95JX/kpvJdW8MeFXQpcv/bCVZjzrjwGzle YAuQ== X-Gm-Message-State: AOAM533c3uCLTXDoFjYU10PZDUU6jkzpSwdQD+XOHbpspvMFqT+9mf4w 4VRdL//W20HoxAd7ueFF70zYX4uDm+uPUpXG6liXbzOXMM1iGRFKxobhCcWo0v1X9cMBDWQqIP4 asxq90hZloyTyQfkP X-Received: by 2002:a17:906:190c:: with SMTP id a12mr9070038eje.491.1624446457192; Wed, 23 Jun 2021 04:07:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfYOxCXGNl6WwCkAT61NO9Jw5DYitkekz8LmF8VlrNsuA0TOsWQBt9kYvTmODjjA976dI+eg== X-Received: by 2002:a17:906:190c:: with SMTP id a12mr9070029eje.491.1624446457054; Wed, 23 Jun 2021 04:07:37 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id jl21sm5514474ejc.42.2021.06.23.04.07.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jun 2021 04:07:35 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 32D22180739; Wed, 23 Jun 2021 13:07:28 +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-?= =?utf-8?q?J=C3=B8rgensen?= , Sunil Goutham , linux-arm-kernel@lists.infradead.org Subject: [PATCH bpf-next v4 09/19] thunderx: remove rcu_read_lock() around XDP program invocation Date: Wed, 23 Jun 2021 13:07:17 +0200 Message-Id: <20210623110727.221922-10-toke@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210623110727.221922-1-toke@redhat.com> References: <20210623110727.221922-1-toke@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/net/ethernet/cavium/thunder/nicvf_main.c b/drivers/net/ethernet/cavium/thunder/nicvf_main.c index c33b4e837515..e2b290135fd9 100644 --- a/drivers/net/ethernet/cavium/thunder/nicvf_main.c +++ b/drivers/net/ethernet/cavium/thunder/nicvf_main.c @@ -555,9 +555,7 @@ 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(); 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 Wed Jun 23 11:07:22 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: 466246 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=-19.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, 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 0F698C4743C for ; Wed, 23 Jun 2021 11:14:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E73AC6108E for ; Wed, 23 Jun 2021 11:14:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230397AbhFWLQV (ORCPT ); Wed, 23 Jun 2021 07:16:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:39371 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230300AbhFWLQE (ORCPT ); Wed, 23 Jun 2021 07:16:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624446826; 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=3OGKlT+K3Cpr2CAOizG3FJ/dNahuGZz8NpheYYFR6ws=; b=O2zr/BJnwqEjDCfiWkYbzi2E+ox7eU/rIyC1eKXJqIcJGNrZuzvgwJD6VbtLWMESYx0Kti gQMCGnCe0BOsIjMo2SUC57fzro1Yx6D58TcoM52zx48PbDp3If0hvi4cFHQ+hZfBPAGGDm zM6YdKQc2IAvduKSyRrP3cQajp5BOrA= 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-373-CYGfScniODWxXF_D6exVkA-1; Wed, 23 Jun 2021 07:13:45 -0400 X-MC-Unique: CYGfScniODWxXF_D6exVkA-1 Received: by mail-ed1-f69.google.com with SMTP id r6-20020a05640216c6b0290394ed90b605so1002961edx.20 for ; Wed, 23 Jun 2021 04:13:45 -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=3OGKlT+K3Cpr2CAOizG3FJ/dNahuGZz8NpheYYFR6ws=; b=QZwthlfNWUmyb0q5rhFuG0pNa4Z5fejynW1Yb6IDz2d5R0dLjgsUYJs3YXVXAmgkgL Jo057rSYW5KDbqQ4HvZKzmCxUakFqkwK8+wXRYZURcR3kPtyr9+4TeID0Msy1yL9fZIE 17JGs96Fp74BkIj9/wLErTLt7NHrESWOmxJYq9cWL5OXJW4uXcQS7wFAnn50f0l0F3Xj NLGxlLWqTLBIQnHHX96CdqCdOkjRgRPPOOvpf+9+QR2FDWjFn5ekCs5YL/0O+TryNNoj 4Z8sXHBS0hh4J1tKzTLHdH+tUSx6YhcJt8v+nSVChccpZMVPMSawAP70gchYpPpz2RQ3 Z7IA== X-Gm-Message-State: AOAM5319ddBxKAHT65bUZ3Fw5RM6a+3S8PEtLTCZ4ZGx203oRKMWO0BN Rvpuy/dCutIvnz+I8M7u7EGR5PjDFQeh3/dh5UaRPXu/N/BcM/Ove0PK8jI6Wdcs2Ji+JRqYngw fLSMjV5VEmuT5tBch X-Received: by 2002:a17:906:244d:: with SMTP id a13mr9481827ejb.551.1624446824262; Wed, 23 Jun 2021 04:13:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw71VQKEC/9KOOq6gTZpsMVmotp3bYZ3eOEuR03USdj7N4YBneTwSsmElAQRP2hdOY2F02acA== X-Received: by 2002:a17:906:244d:: with SMTP id a13mr9481811ejb.551.1624446824081; Wed, 23 Jun 2021 04:13:44 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id n2sm13477595edi.32.2021.06.23.04.13.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jun 2021 04:13:43 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 61ACB18073E; Wed, 23 Jun 2021 13:07:28 +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-?= =?utf-8?q?J=C3=B8rgensen?= , Simon Horman , oss-drivers@netronome.com Subject: [PATCH bpf-next v4 14/19] nfp: remove rcu_read_lock() around XDP program invocation Date: Wed, 23 Jun 2021 13:07:22 +0200 Message-Id: <20210623110727.221922-15-toke@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210623110727.221922-1-toke@redhat.com> References: <20210623110727.221922-1-toke@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 | 2 -- 1 file changed, 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..5dfa4799c34f 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, @@ -2036,7 +2035,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 Wed Jun 23 11:07:23 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: 466247 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=-19.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, 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 251E7C48BE5 for ; Wed, 23 Jun 2021 11:13:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 103E66108E for ; Wed, 23 Jun 2021 11:13:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230455AbhFWLQO (ORCPT ); Wed, 23 Jun 2021 07:16:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:36859 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230286AbhFWLQE (ORCPT ); Wed, 23 Jun 2021 07:16:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624446826; 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=ZRUA/Y9lIwzUgTw5uRoa39eJ4yIyIch6xpJH66I9Qdc=; b=GwDinBErv5wJKP4y4NTW/bHXFy0yBYewemOyr1eva2xHMFEBfPIb8DKEOHLo0gz5yeYrEI LxNlw7x6XB2td7GryvfhYOjvt7KdBg0qk0LkLxw0E6vbFtZYC60ZoJHpPTTWPgRUuLN7e6 3DTzSJEF1sW9RpcV4JfiOycKPOoLa/w= 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-475-pM7iJNsZOxGjBg3sNlPFNQ-1; Wed, 23 Jun 2021 07:13:43 -0400 X-MC-Unique: pM7iJNsZOxGjBg3sNlPFNQ-1 Received: by mail-ed1-f69.google.com with SMTP id m4-20020a0564024304b0290394d27742e4so1105700edc.10 for ; Wed, 23 Jun 2021 04:13:42 -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=ZRUA/Y9lIwzUgTw5uRoa39eJ4yIyIch6xpJH66I9Qdc=; b=Zg3cLQuDe4LJ9hzHmm5Od8I3n7jtruhlWH2HggZjJIWeC5D0Eavi83lq1wLpTLQsBY qpJhGPdpAz4Yd3Hga7+NaGRwRQuS2/yPjyTK8wXH7HgaRQJZ0IPsMj72jB2wy3qMwbUP 12yCxAIdV9L1wZC7jT7DPmzd3Em/xoz9dLnxEPChEfOA9zNzKjsT0ZE6iNwVdCogpCrP A7a7tJ1IcsBtM6ovguY114pO8pcj4IN6YV1FUV+oYrqwIKboWhIit8CkXu8sg8Y+vaXb cuz0Rwc6igqPbUtZfr/jrmr6tL+Rt3s9ilXRe8cSyygFFabQ3dH0oRGc5W9SRX13bbNC Z1JQ== X-Gm-Message-State: AOAM531EIE3mU495WkBibrHUv/YBFq8q0WTCfQrqatJzNl5TEuuP2llq Uvjgri+pZ2rVx5MsmzEMAKEai+FlhXnbIlnrrwZqUfFzOEtRF+Lcsy+qIx5HZqCPaWhfMaalpZm Pdg5dTKi75ZUM2TX3 X-Received: by 2002:a17:906:34cf:: with SMTP id h15mr9261311ejb.526.1624446821842; Wed, 23 Jun 2021 04:13:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNBQa0CtVLyqSCtU7E+yLdrrdnxdFKoAi4uPGzq58jwGDY1F5UViDRBybswKmPs7D4pY6M7Q== X-Received: by 2002:a17:906:34cf:: with SMTP id h15mr9261282ejb.526.1624446821485; Wed, 23 Jun 2021 04:13:41 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id ml14sm3124574ejb.27.2021.06.23.04.13.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jun 2021 04:13:40 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 6C06218073F; Wed, 23 Jun 2021 13:07:28 +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-?= =?utf-8?q?J=C3=B8rgensen?= , Ariel Elior , GR-everest-linux-l2@marvell.com Subject: [PATCH bpf-next v4 15/19] qede: remove rcu_read_lock() around XDP program invocation Date: Wed, 23 Jun 2021 13:07:23 +0200 Message-Id: <20210623110727.221922-16-toke@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210623110727.221922-1-toke@redhat.com> References: <20210623110727.221922-1-toke@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 | 6 ------ 1 file changed, 6 deletions(-) diff --git a/drivers/net/ethernet/qlogic/qede/qede_fp.c b/drivers/net/ethernet/qlogic/qede/qede_fp.c index 8e150dd4f899..065e9004598e 100644 --- a/drivers/net/ethernet/qlogic/qede/qede_fp.c +++ b/drivers/net/ethernet/qlogic/qede/qede_fp.c @@ -1089,13 +1089,7 @@ 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. - */ - 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 Wed Jun 23 11:07:24 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: 466249 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=-19.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, 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 8CB2AC49EA7 for ; Wed, 23 Jun 2021 11:13:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 74848611AD for ; Wed, 23 Jun 2021 11:13:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230304AbhFWLQE (ORCPT ); Wed, 23 Jun 2021 07:16:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:46478 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230232AbhFWLQB (ORCPT ); Wed, 23 Jun 2021 07:16:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624446824; 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=cOyh19f+n3Klc9n0Uf50USUZ/OAvnTAcZiRzl4mD+JA=; b=W9SyoSi8B1sOzdyy3LCQRfLDEX/RUOxpDwaPziCFQFg5J9jh0XnbA84m8kGMdedx7E3yMI CvTX8PRZGceRt6Pe7LxiaVmPPBz1FXSByJboZJuGm9H7xihcUSGnwloHlucWzaPcMEKkv9 DK+mpScFTtx9PlA6Tqx2SLoKBD8jnCE= 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-185-jtZu29QnN8WS3wthJd8bJw-1; Wed, 23 Jun 2021 07:13:43 -0400 X-MC-Unique: jtZu29QnN8WS3wthJd8bJw-1 Received: by mail-ej1-f72.google.com with SMTP id p20-20020a1709064994b02903cd421d7803so832946eju.22 for ; Wed, 23 Jun 2021 04:13:42 -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=cOyh19f+n3Klc9n0Uf50USUZ/OAvnTAcZiRzl4mD+JA=; b=d+JKYArkg9RlPNEeiQz6PUOPLGRYagD3mwLRKa1NWSRJKJBx1yUNA43oNdiW/1AXBf avB7h3dRfVz42YCW2ttQIMcida0s3diAn7kY409oPzhCAFXf9G0Du42R7IuYt388O2FC jYqFW4qhBy46EgGv8qlKzRzUiOuL9JWzQl/inoA3Ze51NVl6CzmyMAFbw+DhTsYcazhO 5VYN2HV0SfwJYHTM1WMbCAX+/hhm3E/m595PlqGWFJZp5faQ0p/Mrd5To5Csi3p/wQge S+jmqFXXEkZJ7Q+RR/7K1k3v3h4Q7pk+6LHpToi9qb/u36VLydMpbv7/ZWZHduIIzXEd q7wA== X-Gm-Message-State: AOAM530j/0mK1UyMBagA/p4RSYczuPPd0hlkdPLxZ4plm50rOXEkAbEW NRzjJZobCFaGPfcWQbxGWYwclkzQJI3OunvcG8Wu4jYo1DIpvl+qu0rN1F/T/T3mBXKkWzcM/sP 011Rzhce5sn2dwwG1 X-Received: by 2002:a17:906:c108:: with SMTP id do8mr9602774ejc.74.1624446821906; Wed, 23 Jun 2021 04:13:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFC4J4yF4C76IBXxeFdHx2yW30lP8pvvXj7t+qqzCoChKhiwz3GKGGMBaMUXSqFPorcLDoxw== X-Received: by 2002:a17:906:c108:: with SMTP id do8mr9602748ejc.74.1624446821693; Wed, 23 Jun 2021 04:13:41 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id bq1sm7200517ejb.66.2021.06.23.04.13.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jun 2021 04:13:40 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 74594180740; Wed, 23 Jun 2021 13:07:28 +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-?= =?utf-8?q?J=C3=B8rgensen?= , Edward Cree , Martin Habets Subject: [PATCH bpf-next v4 16/19] sfc: remove rcu_read_lock() around XDP program invocation Date: Wed, 23 Jun 2021 13:07:24 +0200 Message-Id: <20210623110727.221922-17-toke@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210623110727.221922-1-toke@redhat.com> References: <20210623110727.221922-1-toke@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/sfc/rx.c b/drivers/net/ethernet/sfc/rx.c index 17b8119c48e5..606750938b89 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()) @@ -296,7 +292,6 @@ static bool efx_do_xdp(struct efx_nic *efx, struct efx_channel *channel, rx_buf->len, false); xdp_act = bpf_prog_run_xdp(xdp_prog, &xdp); - rcu_read_unlock(); offset = (u8 *)xdp.data - *ehp; From patchwork Wed Jun 23 11:07:25 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: 466250 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=-19.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, 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 CC3D4C48BE5 for ; Wed, 23 Jun 2021 11:08:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB55161026 for ; Wed, 23 Jun 2021 11:08:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230161AbhFWLKk (ORCPT ); Wed, 23 Jun 2021 07:10:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:21888 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230239AbhFWLJ6 (ORCPT ); Wed, 23 Jun 2021 07:09:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624446461; 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=yDyNUpCpBTNbFxDC2WQuaaPWytT5QLCtZC1t66JXAlk=; b=HghLPu/6cLfRJgCvUyZzMOADyhneoMvrhonyjKx80rLTAMV6oU+GkJXwUsfia9QAri9Z0C elBNp6vGPEVoBoHgMMTHGVC0lcOAgCfkUqn6yE5YnkG4nTcsfDWn3PPBLnyMlPNJghQysu WhkjVVhuTq/GLcdXO5n3tktchYQfeDA= 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-184-zZI-8p0ONi6z11oObLh7Ag-1; Wed, 23 Jun 2021 07:07:40 -0400 X-MC-Unique: zZI-8p0ONi6z11oObLh7Ag-1 Received: by mail-ed1-f69.google.com with SMTP id w1-20020a0564022681b0290394cedd8a6aso1089883edd.14 for ; Wed, 23 Jun 2021 04:07:39 -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=yDyNUpCpBTNbFxDC2WQuaaPWytT5QLCtZC1t66JXAlk=; b=eWs/sdp02CUYmC9JLmGhmAna/8F08jD0Hm2D8p6B1ZEwbN6TK6MH5hfmJDYToYyfY7 aNYh7kT0H3v7swvJ3Lsl0YK2kaJZB5o9qLkmHMEIKJk08VFOOdH8lx/S7zx6CPEs+ymP jEeARxWuTQvGF9Ho32YXF/QeE9qovB/7lOiw0aHld6nsU4cIYA0HU1MJZvUg38pIX4iu CZitUuXfTRUy+RQw6Z25xv0eqUedbVl/2w3AYlm3BMkSmc6y1cbogAUYPqhbV0ivD7uG t/qz78wz25P2in0Cm8dFsUbQsWHmaVETgFrh18liSYwd4mJv0ecEYdIODSK5T+NyX5oJ XOyQ== X-Gm-Message-State: AOAM533KwBx7r2hmNlrhwiStV507pqcKiIJ57277/2h0CZvS+cQz/qR3 8cYg0iDDZlEsCUtjhfKN17zPdpB4aY3sPGXG2f9931MJyhnE3f39SodK/8yIe1iZmL0iqQfQw5H 4MuhqC8pu4O2ju03w X-Received: by 2002:a17:906:841a:: with SMTP id n26mr9052469ejx.430.1624446458601; Wed, 23 Jun 2021 04:07:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyiCn+E0GqnflDNDr2cZUSBElhE9Z+SzSMhk9zf2y/FqN45sosWDLQuM6WRitS6qMnDZWcnwQ== X-Received: by 2002:a17:906:841a:: with SMTP id n26mr9052436ejx.430.1624446458285; Wed, 23 Jun 2021 04:07:38 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id j19sm3767903ejo.3.2021.06.23.04.07.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jun 2021 04:07:37 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 804F0180741; Wed, 23 Jun 2021 13:07:28 +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-?= =?utf-8?q?J=C3=B8rgensen?= , Jassi Brar , Ilias Apalodimas Subject: [PATCH bpf-next v4 17/19] netsec: remove rcu_read_lock() around XDP program invocation Date: Wed, 23 Jun 2021 13:07:25 +0200 Message-Id: <20210623110727.221922-18-toke@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210623110727.221922-1-toke@redhat.com> References: <20210623110727.221922-1-toke@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/net/ethernet/socionext/netsec.c b/drivers/net/ethernet/socionext/netsec.c index dfc85cc68173..20d148c019d8 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); @@ -1069,8 +1068,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 Wed Jun 23 11:07:26 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: 466248 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=-19.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, 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 979B0C4743C for ; Wed, 23 Jun 2021 11:13:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 75153611AC for ; Wed, 23 Jun 2021 11:13:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230402AbhFWLQJ (ORCPT ); Wed, 23 Jun 2021 07:16:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45045 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230098AbhFWLQD (ORCPT ); Wed, 23 Jun 2021 07:16:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624446825; 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=llJCIySvFOtrYZhTAdojGqVA7hNSjDHEmwwvlUzwRuo=; b=BN5m6m9d/5aK6ze/ACjEHaAt9YX4ZAcQUjh0nHmtWO2lmxxc5PmaBbKfup/gic0HPhgcwu sl/qflNG0JBmaImJwwVzGyAnEccb9xeRwoMsvjjCgqiezM63jNHcTrOrh/XaWXvNckKn78 8laCrxKHy5SRKCmp0eVAi7c8P/uMMt4= 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-503-jkdPTtRBOeG52CBWEbaYtg-1; Wed, 23 Jun 2021 07:13:44 -0400 X-MC-Unique: jkdPTtRBOeG52CBWEbaYtg-1 Received: by mail-ed1-f69.google.com with SMTP id z5-20020a05640235c5b0290393974bcf7eso1125225edc.2 for ; Wed, 23 Jun 2021 04:13:44 -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=llJCIySvFOtrYZhTAdojGqVA7hNSjDHEmwwvlUzwRuo=; b=ULkRLlkiggZpVrlu6B5XkHekGLhvRb9us9yLDD5YRGbkKAWNUW8aX8gmKarsNY4E08 uKfchIafGzh830WyyEk70pOeFVXFsL8fWJ9ZlHTkZCrvDz/EBxGtbSxjPic8d0JMHWOP htJlw5r4esANR+dnJdumhCOmqoKWWj9faTYMzBe3WmbAUoCm3GzoRLCE1REfNscLFKJK PLmRNOUOXhKoB9Un/yahxU0sKUtVdPZL8wlH3Lbxu0q2onrDd4S36OW1YlVUohNLkTv2 EPhg3N64hq8T5JdMia8yoymaPu0cWs3KV67EzyqqAy2M680ZDgTIiLypUdrs2e+6ABOZ C5yw== X-Gm-Message-State: AOAM533N4igsmA24M6eqRbk+Oagx6qZNLVy8sjO00PGXTezPERySkV2z JXSkefTyWzKzR88mYfoNFr7cAdfcYfz4IiRk8UglezaiSbL/DpxE+50ocLJN8k3FJFG004LezoU FetTXBDHy0YXKDtpg X-Received: by 2002:a05:6402:42d2:: with SMTP id i18mr11522753edc.168.1624446823373; Wed, 23 Jun 2021 04:13:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8yFgTmKihKxpCubnh8O8F/QHFr0n5nAr6MMyZq4hXtQykYRJ1mSniQXOqaN4HV1YIOxxxAQ== X-Received: by 2002:a05:6402:42d2:: with SMTP id i18mr11522725edc.168.1624446823254; Wed, 23 Jun 2021 04:13:43 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id gx4sm3605409ejc.34.2021.06.23.04.13.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jun 2021 04:13:40 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 872E3180742; Wed, 23 Jun 2021 13:07:28 +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-?= =?utf-8?q?J=C3=B8rgensen?= , Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu Subject: [PATCH bpf-next v4 18/19] stmmac: remove rcu_read_lock() around XDP program invocation Date: Wed, 23 Jun 2021 13:07:26 +0200 Message-Id: <20210623110727.221922-19-toke@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210623110727.221922-1-toke@redhat.com> References: <20210623110727.221922-1-toke@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 | 10 ++-------- 1 file changed, 2 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..08c4b999e1ba 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) @@ -4696,17 +4695,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 +4972,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: