rxrpc: Pass the input handler's data skb reference to the Rx ring
authorDavid Howells <dhowells@redhat.com>
Mon, 19 Aug 2019 08:25:36 +0000 (09:25 +0100)
committerDavid Howells <dhowells@redhat.com>
Tue, 27 Aug 2019 08:59:19 +0000 (09:59 +0100)
Pass the reference held on a DATA skb in the rxrpc input handler into the
Rx ring rather than getting an additional ref for this and then dropping
the original ref at the end.

Signed-off-by: David Howells <dhowells@redhat.com>
net/rxrpc/input.c

index 35b1a9368d80e4018f97fed56e58c18b1610a5aa..140cede776552035157f66a58d8f541cb84c035b 100644 (file)
@@ -422,7 +422,8 @@ static void rxrpc_input_dup_data(struct rxrpc_call *call, rxrpc_seq_t seq,
 }
 
 /*
- * Process a DATA packet, adding the packet to the Rx ring.
+ * Process a DATA packet, adding the packet to the Rx ring.  The caller's
+ * packet ref must be passed on or discarded.
  */
 static void rxrpc_input_data(struct rxrpc_call *call, struct sk_buff *skb)
 {
@@ -441,8 +442,10 @@ static void rxrpc_input_data(struct rxrpc_call *call, struct sk_buff *skb)
               sp->hdr.serial, seq0, sp->hdr.flags, sp->nr_subpackets);
 
        state = READ_ONCE(call->state);
-       if (state >= RXRPC_CALL_COMPLETE)
+       if (state >= RXRPC_CALL_COMPLETE) {
+               rxrpc_free_skb(skb, rxrpc_skb_rx_freed);
                return;
+       }
 
        if (call->state == RXRPC_CALL_SERVER_RECV_REQUEST) {
                unsigned long timo = READ_ONCE(call->next_req_timo);
@@ -555,7 +558,8 @@ static void rxrpc_input_data(struct rxrpc_call *call, struct sk_buff *skb)
                 * Barriers against rxrpc_recvmsg_data() and rxrpc_rotate_rx_window()
                 * and also rxrpc_fill_out_ack().
                 */
-               rxrpc_get_skb(skb, rxrpc_skb_rx_got);
+               if (!terminal)
+                       rxrpc_get_skb(skb, rxrpc_skb_rx_got);
                call->rxtx_annotations[ix] = annotation;
                smp_wmb();
                call->rxtx_buffer[ix] = skb;
@@ -616,6 +620,7 @@ ack:
 
 unlock:
        spin_unlock(&call->input_lock);
+       rxrpc_free_skb(skb, rxrpc_skb_rx_freed);
        _leave(" [queued]");
 }
 
@@ -1024,7 +1029,7 @@ static void rxrpc_input_call_packet(struct rxrpc_call *call,
        switch (sp->hdr.type) {
        case RXRPC_PACKET_TYPE_DATA:
                rxrpc_input_data(call, skb);
-               break;
+               goto no_free;
 
        case RXRPC_PACKET_TYPE_ACK:
                rxrpc_input_ack(call, skb);
@@ -1051,6 +1056,8 @@ static void rxrpc_input_call_packet(struct rxrpc_call *call,
                break;
        }
 
+       rxrpc_free_skb(skb, rxrpc_skb_rx_freed);
+no_free:
        _leave("");
 }
 
@@ -1375,8 +1382,11 @@ int rxrpc_input_packet(struct sock *udp_sk, struct sk_buff *skb)
                mutex_unlock(&call->user_mutex);
        }
 
+       /* Process a call packet; this either discards or passes on the ref
+        * elsewhere.
+        */
        rxrpc_input_call_packet(call, skb);
-       goto discard;
+       goto out;
 
 discard:
        rxrpc_free_skb(skb, rxrpc_skb_rx_freed);