Skip to contentSkip to conversation

xfrm: Skip redundant statistics update for crypto offload

PATCH Applied Jianbo Liu 2 participants 2 messages Jul 3, 2025 – Jul 7, 2025

Subsystems (3)
lore
Share & tools
lore

Jianbo Liu

author
#0 lore raw

PATCH 1/1 xfrm: Skip redundant statistics update for crypto offload

In the crypto offload path, every packet is still processed by the software stack. The state's statistics required for the expiration check are being updated in software.

However, the code also calls xfrm_dev_state_update_stats(), which triggers a query to the hardware device to fetch statistics. This hardware query is redundant and introduces unnecessary performance overhead.

Skip this call when it's crypto offload (not packet offload) to avoid the unnecessary hardware access, thereby improving performance.

---
 net/xfrm/xfrm_state.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
net/xfrm/xfrm_state.c +6 -1
index 203b585c2ae2..b8b97798c504 100644
@@ -2262,7 +2262,12 @@ EXPORT_SYMBOL(xfrm_state_update);
 
 int xfrm_state_check_expire(struct xfrm_state *x)
 {
-	xfrm_dev_state_update_stats(x);
+	/* All counters which are needed to decide if state is expired
+	 * are handled by SW for non-packet offload modes. Simply skip
+	 * the following update and save extra boilerplate in drivers.
+	 */
+	if (x->xso.type == XFRM_DEV_OFFLOAD_PACKET)
+		xfrm_dev_state_update_stats(x);
 
 	if (!READ_ONCE(x->curlft.use_time))
 		WRITE_ONCE(x->curlft.use_time, ktime_get_real_seconds());
Signature · 1 line
2.38.1
maintainer Applied
#1 lore raw
Quoted 9 lines · Jianbo Liu

In the crypto offload path, every packet is still processed by the software stack. The state's statistics required for the expiration check are being updated in software.

However, the code also calls xfrm_dev_state_update_stats(), which triggers a query to the hardware device to fetch statistics. This hardware query is redundant and introduces unnecessary performance overhead.

Quoted 5 lines

Skip this call when it's crypto offload (not packet offload) to avoid the unnecessary hardware access, thereby improving performance.

Applied, thanks a lot Jianbo!