From: Joel Fernandes <joel@joelfernandes.org>
To: Eric Dumazet <edumazet@google.com>
Cc: "David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org, eric.dumazet@gmail.com,
Dmitry Safonov <dima@arista.com>,
"Paul E . McKenney" <paulmck@kernel.org>
Subject: Re: [PATCH net-next] tcp: use 2-arg optimal variant of kfree_rcu()
Date: Fri, 2 Dec 2022 23:49:59 +0000 [thread overview]
Message-ID: <Y4qPJ89SBWACbbTr@google.com> (raw)
In-Reply-To: <20221202052847.2623997-1-edumazet@google.com>
On Fri, Dec 02, 2022 at 05:28:47AM +0000, Eric Dumazet wrote:
> kfree_rcu(1-arg) should be avoided as much as possible,
> since this is only possible from sleepable contexts,
> and incurr extra rcu barriers.
>
> I wish the 1-arg variant of kfree_rcu() would
> get a distinct name, like kfree_rcu_slow()
> to avoid it being abused.
Hi Eric,
Nice to see your patch.
Paul, all, regarding Eric's concern, would the following work to warn of
users? Credit to Paul/others for discussing the idea on another thread. One
thing to note here is, this debugging will only be in effect on preemptible
kernels, but should still help catch issues hopefully.
The other idea Paul mentioned is to introduce a new dedicated API for 1-arg
sleepable cases. My concern with that was that, that being effective depends
on the user using the right API in the first place.
I did not test it yet, but wanted to discuss a bit first.
Cheers,
- Joel
---8<-----------------------
diff --git a/include/linux/rcutiny.h b/include/linux/rcutiny.h
index 9bc025aa79a3..112d230279ea 100644
--- a/include/linux/rcutiny.h
+++ b/include/linux/rcutiny.h
@@ -106,6 +106,11 @@ static inline void __kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func)
}
// kvfree_rcu(one_arg) call.
+ if (IS_ENABLED(CONFIG_PREEMPT_COUNT) && preemptible() && !head) {
+ WARN_ONCE(1, "%s(): Please provide an rcu_head in preemptible"
+ " contexts to avoid long waits!\n", __func__);
+ }
+
might_sleep();
synchronize_rcu();
kvfree((void *) func);
diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index 0ca21ac0f064..b29df1305a2e 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -3324,6 +3324,11 @@ void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func)
* only. For other places please embed an rcu_head to
* your data.
*/
+ if (IS_ENABLED(CONFIG_PREEMPT_COUNT) && preemptible() && !head) {
+ WARN_ONCE(1, "%s(): Please provide an rcu_head in preemptible"
+ " contexts to avoid long waits!\n", __func__);
+ }
+
might_sleep();
ptr = (unsigned long *) func;
}
next prev parent reply other threads:[~2022-12-02 23:50 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-02 5:28 [PATCH net-next] tcp: use 2-arg optimal variant of kfree_rcu() Eric Dumazet
2022-12-02 7:44 ` Pavan Chebbi
2022-12-02 16:05 ` Dmitry Safonov
2022-12-02 18:34 ` Paul E. McKenney
2022-12-02 23:49 ` Joel Fernandes [this message]
2022-12-03 0:03 ` Paul E. McKenney
2022-12-03 0:12 ` Joel Fernandes
2022-12-03 0:16 ` Joel Fernandes
2022-12-03 0:28 ` Joel Fernandes
2022-12-05 11:09 ` Uladzislau Rezki
2022-12-05 13:23 ` Eric Dumazet
2022-12-05 14:59 ` Uladzislau Rezki
2022-12-05 16:58 ` Eric Dumazet
2022-12-05 17:10 ` Uladzislau Rezki
2022-12-03 5:50 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y4qPJ89SBWACbbTr@google.com \
--to=joel@joelfernandes.org \
--cc=davem@davemloft.net \
--cc=dima@arista.com \
--cc=edumazet@google.com \
--cc=eric.dumazet@gmail.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=paulmck@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.