From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A594466B57; Tue, 16 Jun 2026 16:24:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781627047; cv=none; b=E3FoZ3ACh2x5mjN/d0WRp+Nxm3tiMkrjNnOoHWg4BM73FK7cbdW2qRVWxJFB4rIJcnLQ3iCPs58/84+Qc3+dgQ2+hUvSVa3Q5+RbaXitkElFHzkY8F3euJs9+KtTl4mLG9xmqIiXotMDZNaQinHdfTVoRGFut4VszVEKVq8qeK4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781627047; c=relaxed/simple; bh=nJ2eTa2ZIQLt7JArccbU8swtCFHh6g6Y16+WcJ+/M8k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h+SgftHjUk4cnayTFjh3oQDxT0OWQx8L1nopwPHSkgQ9nlRx4GOIfPEXF7N/oK7KuX4jJRNl5kUdFaASHAiDfbc+Xj+t3URbxtoLYmSITeccA9KLSKntjEe3aEyOMifWzjsXhcMVYNq7R4n6zfWl2A47yVtWqHA14T6jWfT2ahg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=IdmDMDtw; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="IdmDMDtw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C81661F000E9; Tue, 16 Jun 2026 16:24:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1781627045; bh=No0xFgTGmE7SrdwmSjwAd8bebCcKSj8siVK6/aUUVbg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=IdmDMDtw5BOsUw6et4/jDFB8X1V+Z9xkSRD5v1bA/nhK07iqTN/Z5G8O0TSJLE3p6 GNfoJu9YXYaatrQ3zS1f7ARYTW01xoRL4OecZyBp+dgM9tLvYs9Z4h7Mv+6ygx0AtO zIa31n23G4t2bX/JDaOv+86L3ABKC24GJG2PtoRU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jianbo Liu , Cosmin Ratiu , Steffen Klassert , Simon Liebold , Sasha Levin Subject: [PATCH 6.12 111/261] xfrm: hold device only for the asynchronous decryption Date: Tue, 16 Jun 2026 20:29:09 +0530 Message-ID: <20260616145050.209026904@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260616145044.869532709@linuxfoundation.org> References: <20260616145044.869532709@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jianbo Liu [ Upstream commit b05d42eefac737ce3cd80114d3579111023941b8 ] The dev_hold() on skb->dev during packet reception was originally added to prevent the device from being released prematurely during asynchronous decryption operations. As current hardware can offload decryption, this asynchronous path is not always utilized. This often results in a pattern of dev_hold() immediately followed by dev_put() for each packet, creating unnecessary reference counting overhead detrimental to performance. This patch optimizes this by skipping the dev_hold() and subsequent dev_put() when asynchronous decryption is not being performed. Signed-off-by: Jianbo Liu Reviewed-by: Cosmin Ratiu Signed-off-by: Steffen Klassert Stable-dep-of: 1c428b038400 ("xfrm: hold dev ref until after transport_finish NF_HOOK") Signed-off-by: Simon Liebold Signed-off-by: Sasha Levin --- net/xfrm/xfrm_input.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/net/xfrm/xfrm_input.c b/net/xfrm/xfrm_input.c index 8edcb32735e595..90a79558dca259 100644 --- a/net/xfrm/xfrm_input.c +++ b/net/xfrm/xfrm_input.c @@ -492,6 +492,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) /* An encap_type of -1 indicates async resumption. */ if (encap_type == -1) { async = 1; + dev_put(skb->dev); seq = XFRM_SKB_CB(skb)->seq.input.low; goto resume; } @@ -638,18 +639,18 @@ 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; - dev_hold(skb->dev); - - if (crypto_done) + if (crypto_done) { nexthdr = x->type_offload->input_tail(x, skb); - else + } else { + dev_hold(skb->dev); + nexthdr = x->type->input(x, skb); + if (nexthdr == -EINPROGRESS) + return 0; - if (nexthdr == -EINPROGRESS) - return 0; + dev_put(skb->dev); + } resume: - dev_put(skb->dev); - spin_lock(&x->lock); if (nexthdr < 0) { if (nexthdr == -EBADMSG) { -- 2.53.0