Skip to content

Commit b05d42e

Browse files
Jianbo Liuklassert
authored andcommitted
xfrm: hold device only for the asynchronous decryption
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 <[email protected]> Reviewed-by: Cosmin Ratiu <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent 4f4040e commit b05d42e

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

net/xfrm/xfrm_input.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
503503
/* An encap_type of -1 indicates async resumption. */
504504
if (encap_type == -1) {
505505
async = 1;
506+
dev_put(skb->dev);
506507
seq = XFRM_SKB_CB(skb)->seq.input.low;
507508
goto resume;
508509
}
@@ -649,18 +650,18 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
649650
XFRM_SKB_CB(skb)->seq.input.low = seq;
650651
XFRM_SKB_CB(skb)->seq.input.hi = seq_hi;
651652

652-
dev_hold(skb->dev);
653-
654-
if (crypto_done)
653+
if (crypto_done) {
655654
nexthdr = x->type_offload->input_tail(x, skb);
656-
else
655+
} else {
656+
dev_hold(skb->dev);
657+
657658
nexthdr = x->type->input(x, skb);
659+
if (nexthdr == -EINPROGRESS)
660+
return 0;
658661

659-
if (nexthdr == -EINPROGRESS)
660-
return 0;
662+
dev_put(skb->dev);
663+
}
661664
resume:
662-
dev_put(skb->dev);
663-
664665
spin_lock(&x->lock);
665666
if (nexthdr < 0) {
666667
if (nexthdr == -EBADMSG) {

0 commit comments

Comments
 (0)