* [PATCH net-next 0/2] xfrm: IPsec hardware offload performance improvements
@ 2025-10-21 1:35 Jianbo Liu
2025-10-21 1:35 ` [PATCH net-next 1/2] xfrm: Refactor xfrm_input lock to reduce contention with RSS Jianbo Liu
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Jianbo Liu @ 2025-10-21 1:35 UTC (permalink / raw)
To: netdev, davem, kuba, steffen.klassert; +Cc: Jianbo Liu
This patch series optimizes IPsec crypto offload performance by
addressing a lock contention bottleneck using RSS.
The first patch refactors the xfrm_input to avoid a costly
unlock/relock cycle.
The second patch builds on this by removing a redundant replay check,
which is unnecessary for the synchronous hardware path.
Jianbo Liu (2):
xfrm: Refactor xfrm_input lock to reduce contention with RSS
xfrm: Skip redundant replay recheck for the hardware offload path
net/xfrm/xfrm_input.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
--
2.49.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH net-next 1/2] xfrm: Refactor xfrm_input lock to reduce contention with RSS
2025-10-21 1:35 [PATCH net-next 0/2] xfrm: IPsec hardware offload performance improvements Jianbo Liu
@ 2025-10-21 1:35 ` Jianbo Liu
2025-10-21 1:35 ` [PATCH net-next 2/2] xfrm: Skip redundant replay recheck for the hardware offload path Jianbo Liu
2025-10-28 6:49 ` [PATCH net-next 0/2] xfrm: IPsec hardware offload performance improvements Steffen Klassert
2 siblings, 0 replies; 4+ messages in thread
From: Jianbo Liu @ 2025-10-21 1:35 UTC (permalink / raw)
To: netdev, davem, kuba, steffen.klassert
Cc: Jianbo Liu, Cosmin Ratiu, Herbert Xu, Eric Dumazet, Paolo Abeni,
Simon Horman
With newer NICs like mlx5 supporting RSS for IPsec crypto offload,
packets for a single Security Association (SA) are scattered across
multiple CPU cores for parallel processing. The xfrm_state spinlock
(x->lock) is held for each packet during xfrm processing.
When multiple connections or flows share the same SA, this parallelism
causes high lock contention on x->lock, creating a performance
bottleneck and limiting scalability.
The original xfrm_input() function exacerbated this issue by releasing
and immediately re-acquiring x->lock. For hardware crypto offload
paths, this unlock/relock sequence is unnecessary and introduces
significant overhead. This patch refactors the function to relocate
the type_offload->input_tail call for the offload path, performing all
necessary work while continuously holding the lock. This reordering is
safe, since packets which don't pass the checks below will still fail
them with the new code.
Performance testing with iperf using multiple parallel streams over a
single IPsec SA shows significant improvement in throughput as the
number of queues (and thus CPU cores) increases:
+-----------+---------------+--------------+-----------------+
| RX queues | Before (Gbps) | After (Gbps) | Improvement (%) |
+-----------+---------------+--------------+-----------------+
| 2 | 32.3 | 34.4 | 6.5 |
| 4 | 34.4 | 40.0 | 16.3 |
| 6 | 24.5 | 38.3 | 56.3 |
| 8 | 23.1 | 38.3 | 65.8 |
| 12 | 18.1 | 29.9 | 65.2 |
| 16 | 16.0 | 25.2 | 57.5 |
+-----------+---------------+--------------+-----------------+
Signed-off-by: Jianbo Liu <jianbol@nvidia.com>
Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com>
---
net/xfrm/xfrm_input.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/net/xfrm/xfrm_input.c b/net/xfrm/xfrm_input.c
index c9ddef869aa5..257935cbd221 100644
--- a/net/xfrm/xfrm_input.c
+++ b/net/xfrm/xfrm_input.c
@@ -505,6 +505,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
async = 1;
dev_put(skb->dev);
seq = XFRM_SKB_CB(skb)->seq.input.low;
+ spin_lock(&x->lock);
goto resume;
}
/* GRO call */
@@ -541,6 +542,8 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
XFRM_INC_STATS(net, LINUX_MIB_XFRMINHDRERROR);
goto drop;
}
+
+ nexthdr = x->type_offload->input_tail(x, skb);
}
goto lock;
@@ -638,11 +641,9 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
goto drop_unlock;
}
- spin_unlock(&x->lock);
-
if (xfrm_tunnel_check(skb, x, family)) {
XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATEMODEERROR);
- goto drop;
+ goto drop_unlock;
}
seq_hi = htonl(xfrm_replay_seqhi(x, seq));
@@ -650,9 +651,8 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
XFRM_SKB_CB(skb)->seq.input.low = seq;
XFRM_SKB_CB(skb)->seq.input.hi = seq_hi;
- if (crypto_done) {
- nexthdr = x->type_offload->input_tail(x, skb);
- } else {
+ if (!crypto_done) {
+ spin_unlock(&x->lock);
dev_hold(skb->dev);
nexthdr = x->type->input(x, skb);
@@ -660,9 +660,9 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
return 0;
dev_put(skb->dev);
+ spin_lock(&x->lock);
}
resume:
- spin_lock(&x->lock);
if (nexthdr < 0) {
if (nexthdr == -EBADMSG) {
xfrm_audit_state_icvfail(x, skb,
--
2.49.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH net-next 2/2] xfrm: Skip redundant replay recheck for the hardware offload path
2025-10-21 1:35 [PATCH net-next 0/2] xfrm: IPsec hardware offload performance improvements Jianbo Liu
2025-10-21 1:35 ` [PATCH net-next 1/2] xfrm: Refactor xfrm_input lock to reduce contention with RSS Jianbo Liu
@ 2025-10-21 1:35 ` Jianbo Liu
2025-10-28 6:49 ` [PATCH net-next 0/2] xfrm: IPsec hardware offload performance improvements Steffen Klassert
2 siblings, 0 replies; 4+ messages in thread
From: Jianbo Liu @ 2025-10-21 1:35 UTC (permalink / raw)
To: netdev, davem, kuba, steffen.klassert
Cc: Jianbo Liu, Cosmin Ratiu, Herbert Xu, Eric Dumazet, Paolo Abeni,
Simon Horman
The xfrm_replay_recheck() function was introduced to handle the issues
arising from asynchronous crypto algorithms.
The crypto offload path is now effectively synchronous, as it holds
the state lock throughout its operation. This eliminates the race
condition, making the recheck an unnecessary overhead. This patch
improves performance by skipping the redundant call when
crypto_done is true.
Additionally, the sequence number assignment is moved to an earlier
point in the function. This improves performance by reducing lock
contention and places the logic at a more appropriate point, as the
full sequence number (including the higher-order bits) can be
determined as soon as the packet is received.
Signed-off-by: Jianbo Liu <jianbol@nvidia.com>
Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com>
---
net/xfrm/xfrm_input.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/net/xfrm/xfrm_input.c b/net/xfrm/xfrm_input.c
index 257935cbd221..4ed346e682c7 100644
--- a/net/xfrm/xfrm_input.c
+++ b/net/xfrm/xfrm_input.c
@@ -546,7 +546,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
nexthdr = x->type_offload->input_tail(x, skb);
}
- goto lock;
+ goto process;
}
family = XFRM_SPI_SKB_CB(skb)->family;
@@ -614,7 +614,12 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
goto drop;
}
-lock:
+process:
+ seq_hi = htonl(xfrm_replay_seqhi(x, seq));
+
+ XFRM_SKB_CB(skb)->seq.input.low = seq;
+ XFRM_SKB_CB(skb)->seq.input.hi = seq_hi;
+
spin_lock(&x->lock);
if (unlikely(x->km.state != XFRM_STATE_VALID)) {
@@ -646,11 +651,6 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
goto drop_unlock;
}
- seq_hi = htonl(xfrm_replay_seqhi(x, seq));
-
- XFRM_SKB_CB(skb)->seq.input.low = seq;
- XFRM_SKB_CB(skb)->seq.input.hi = seq_hi;
-
if (!crypto_done) {
spin_unlock(&x->lock);
dev_hold(skb->dev);
@@ -676,7 +676,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
/* only the first xfrm gets the encap type */
encap_type = 0;
- if (xfrm_replay_recheck(x, skb, seq)) {
+ if (!crypto_done && xfrm_replay_recheck(x, skb, seq)) {
XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATESEQERROR);
goto drop_unlock;
}
--
2.49.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net-next 0/2] xfrm: IPsec hardware offload performance improvements
2025-10-21 1:35 [PATCH net-next 0/2] xfrm: IPsec hardware offload performance improvements Jianbo Liu
2025-10-21 1:35 ` [PATCH net-next 1/2] xfrm: Refactor xfrm_input lock to reduce contention with RSS Jianbo Liu
2025-10-21 1:35 ` [PATCH net-next 2/2] xfrm: Skip redundant replay recheck for the hardware offload path Jianbo Liu
@ 2025-10-28 6:49 ` Steffen Klassert
2 siblings, 0 replies; 4+ messages in thread
From: Steffen Klassert @ 2025-10-28 6:49 UTC (permalink / raw)
To: Jianbo Liu; +Cc: netdev, davem, kuba
On Tue, Oct 21, 2025 at 04:35:41AM +0300, Jianbo Liu wrote:
> This patch series optimizes IPsec crypto offload performance by
> addressing a lock contention bottleneck using RSS.
>
> The first patch refactors the xfrm_input to avoid a costly
> unlock/relock cycle.
>
> The second patch builds on this by removing a redundant replay check,
> which is unnecessary for the synchronous hardware path.
>
> Jianbo Liu (2):
> xfrm: Refactor xfrm_input lock to reduce contention with RSS
> xfrm: Skip redundant replay recheck for the hardware offload path
Series applied to ipsec-next, thanks Jianbo!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-10-28 6:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-21 1:35 [PATCH net-next 0/2] xfrm: IPsec hardware offload performance improvements Jianbo Liu
2025-10-21 1:35 ` [PATCH net-next 1/2] xfrm: Refactor xfrm_input lock to reduce contention with RSS Jianbo Liu
2025-10-21 1:35 ` [PATCH net-next 2/2] xfrm: Skip redundant replay recheck for the hardware offload path Jianbo Liu
2025-10-28 6:49 ` [PATCH net-next 0/2] xfrm: IPsec hardware offload performance improvements Steffen Klassert
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).