From: Julius Bairaktaris <julius@bairaktaris.de>
To: Andrew Lunn <andrew+netdev@lunn.ch>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Willem de Bruijn <willemb@google.com>,
Simon Horman <horms@kernel.org>, Shuah Khan <shuah@kernel.org>,
Qingfang Deng <qingfang.deng@linux.dev>,
Guillaume Nault <gnault@redhat.com>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Haoli Zhang <26031212468@stu.xidian.edu.cn>,
linux-ppp@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: [PATCH net-next 1/3] ppp: transmit data frames without the unit and channel locks
Date: Sun, 29 Nov 2026 15:43:17 +0100 [thread overview]
Message-ID: <20261129144319.1489366-2-julius@bairaktaris.de> (raw)
In-Reply-To: <20261129144319.1489366-1-julius@bairaktaris.de>
ppp_xmit_process() takes ppp->wlock and ppp_push() takes the channel's
downl for every frame, so CPUs that transmit on one PPP unit at the same
time run the channel's xmit and the lower device's transmit path one
frame at a time. The device is already LLTX and, on a direct_xmit
channel, IFF_NO_QUEUE, so these two locks are the only serialisation
left.
Send a data frame straight to the channel when none of the work done
under those locks applies: no multilink, no transmit compressor, no VJ
compression of the frame, no demand loopback, no filter and no backlog
on ppp->file.xq. A channel opts in with the new lockless_xmit flag,
which promises that its start_xmit can run concurrently and accepts
every frame. The channel is looked up under RCU, and
ppp_disconnect_channel() already waits for a grace period after it
removes the channel from ppp->channels. ppp_set_compress() now also
waits for one after it installs the first transmit compressor, so no
frame bypasses compression once CCP has started it. Control protocol
frames (protocol 0x8000 and above) keep the locked path, and last_xmit
is only written when jiffies has changed.
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
drivers/net/ppp/ppp_generic.c | 85 ++++++++++++++++++++++++++++++++---
include/linux/ppp_channel.h | 1 +
2 files changed, 79 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
index bd5a7630f297..89a756ae3f4a 100644
--- a/drivers/net/ppp/ppp_generic.c
+++ b/drivers/net/ppp/ppp_generic.c
@@ -823,7 +823,7 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
if (!(ppp->flags & SC_MULTILINK) && (val & SC_MULTILINK))
ppp->nextseq = 0;
#endif
- ppp->flags = val & SC_FLAG_BITS;
+ WRITE_ONCE(ppp->flags, val & SC_FLAG_BITS);
ppp_unlock(ppp);
if (cflags & SC_CCP_OPEN)
ppp_ccp_closed(ppp);
@@ -943,7 +943,7 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
ppp_lock(ppp);
if (*which)
bpf_prog_destroy(*which);
- *which = filter;
+ WRITE_ONCE(*which, filter);
ppp_unlock(ppp);
err = 0;
break;
@@ -1009,7 +1009,7 @@ static long ppp_compat_ioctl(struct file *file, unsigned int cmd, unsigned long
ppp_lock(ppp);
if (*which)
bpf_prog_destroy(*which);
- *which = filter;
+ WRITE_ONCE(*which, filter);
ppp_unlock(ppp);
err = 0;
break;
@@ -1564,7 +1564,7 @@ static void ppp_dev_uninit(struct net_device *dev)
struct ppp_net *pn = ppp_pernet(ppp->ppp_net);
ppp_lock(ppp);
- ppp->closing = 1;
+ WRITE_ONCE(ppp->closing, 1);
ppp_unlock(ppp);
mutex_lock(&pn->all_ppp_mutex);
@@ -1660,8 +1660,73 @@ static void ppp_xmit_flush(struct ppp *ppp)
netif_wake_queue(netdev_from_priv(ppp));
}
+/*
+ * Send a data frame straight to the channel, without ppp->wlock and
+ * pch->downl, when none of the work done under those locks applies:
+ * no multilink, transmit compressor, VJ compression of this frame,
+ * demand loopback, filters or transmit backlog, and a channel whose
+ * start_xmit may run concurrently.
+ *
+ * A frame that saw the old flags of a concurrent PPPIOCSFLAGS is sent
+ * as if it had been sent just before the update; none of these frames
+ * touches VJ or multilink state. Compression cannot start before
+ * ppp_set_compress() has installed a compressor and waited for a grace
+ * period, so no frame bypasses a running compressor. The
+ * channel stays registered until ppp_disconnect_channel() has removed
+ * it from ppp->channels and waited for a grace period.
+ *
+ * Returns true if the frame was consumed.
+ */
+static bool ppp_xmit_lockless(struct ppp *ppp, struct sk_buff *skb)
+{
+ struct net_device *dev = netdev_from_priv(ppp);
+ unsigned int flags = READ_ONCE(ppp->flags);
+ unsigned long now = jiffies;
+ int proto = PPP_PROTO(skb);
+ struct ppp_channel *chan;
+ struct channel *pch;
+ bool ret = false;
+
+ if (proto >= 0x8000 ||
+ (flags & (SC_MULTILINK | SC_LOOP_TRAFFIC)) ||
+ (proto == PPP_IP && (flags & SC_COMP_TCP)) ||
+ READ_ONCE(ppp->xc_state) || READ_ONCE(ppp->closing) ||
+ !skb_queue_empty_lockless(&ppp->file.xq))
+ return false;
+#ifdef CONFIG_PPP_FILTER
+ if (READ_ONCE(ppp->pass_filter) || READ_ONCE(ppp->active_filter))
+ return false;
+#endif /* CONFIG_PPP_FILTER */
+
+ rcu_read_lock();
+ pch = list_first_or_null_rcu(&ppp->channels, struct channel, clist);
+ if (!pch)
+ goto out;
+ chan = pch->chan;
+ if (!chan->lockless_xmit)
+ goto out;
+
+ skb->dev = dev;
+ /* Do not dirty a cache line shared by all CPUs for every frame. */
+ if (READ_ONCE(ppp->last_xmit) != now)
+ WRITE_ONCE(ppp->last_xmit, now);
+ dev_sw_netstats_tx_add(dev, 1, skb->len - PPP_PROTO_LEN);
+
+ if (unlikely(!chan->direct_xmit && skb_linearize(skb)))
+ kfree_skb(skb);
+ else if (WARN_ON_ONCE(!chan->ops->start_xmit(chan, skb)))
+ kfree_skb(skb);
+ ret = true;
+out:
+ rcu_read_unlock();
+ return ret;
+}
+
static void __ppp_xmit_process(struct ppp *ppp, struct sk_buff *skb)
{
+ if (ppp_xmit_lockless(ppp, skb))
+ return;
+
ppp_xmit_lock(ppp);
if (unlikely(ppp->closing)) {
kfree_skb(skb);
@@ -3153,11 +3218,17 @@ ppp_set_compress(struct ppp *ppp, struct ppp_option_data *data)
ocomp = ppp->xcomp;
ostate = ppp->xc_state;
ppp->xcomp = cp;
- ppp->xc_state = state;
+ WRITE_ONCE(ppp->xc_state, state);
ppp_xmit_unlock(ppp);
if (ostate) {
ocomp->comp_free(ostate);
module_put(ocomp->owner);
+ } else {
+ /* Compression can start with the next CCP
+ * frame from pppd; let lockless senders that
+ * saw no compressor finish first.
+ */
+ synchronize_net();
}
err = 0;
} else
@@ -3285,11 +3356,11 @@ ppp_ccp_closed(struct ppp *ppp)
struct compressor *xcomp, *rcomp;
ppp_lock(ppp);
- ppp->flags &= ~(SC_CCP_OPEN | SC_CCP_UP);
+ WRITE_ONCE(ppp->flags, ppp->flags & ~(SC_CCP_OPEN | SC_CCP_UP));
ppp->xstate = 0;
xcomp = ppp->xcomp;
xstate = ppp->xc_state;
- ppp->xc_state = NULL;
+ WRITE_ONCE(ppp->xc_state, NULL);
ppp->rstate = 0;
rcomp = ppp->rcomp;
rstate = ppp->rc_state;
diff --git a/include/linux/ppp_channel.h b/include/linux/ppp_channel.h
index 15bc3aa4f171..a0de060623a1 100644
--- a/include/linux/ppp_channel.h
+++ b/include/linux/ppp_channel.h
@@ -44,6 +44,7 @@ struct ppp_channel {
int speed; /* transfer rate (bytes/second) */
bool direct_xmit; /* no qdisc, xmit directly */
bool xmit_offload; /* accepts GSO and CHECKSUM_PARTIAL skbs */
+ bool lockless_xmit; /* concurrent start_xmit, never 0 */
};
#ifdef __KERNEL__
--
2.53.0
next prev parent reply other threads:[~2026-11-29 14:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 14:43 [PATCH net-next 0/3] " Julius Bairaktaris
2026-11-29 14:43 ` Julius Bairaktaris [this message]
2026-11-29 14:43 ` [PATCH net-next 2/3] pppoe: transmit without the PPP channel lock Julius Bairaktaris
2026-11-29 14:43 ` [PATCH net-next 3/3] selftests: net: ppp: send on PPPoE from every CPU at once Julius Bairaktaris
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=20261129144319.1489366-2-julius@bairaktaris.de \
--to=julius@bairaktaris.de \
--cc=26031212468@stu.xidian.edu.cn \
--cc=andrew+netdev@lunn.ch \
--cc=bigeasy@linutronix.de \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=gnault@redhat.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-ppp@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=qingfang.deng@linux.dev \
--cc=shuah@kernel.org \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®