cregit-Linux how code gets into the kernel

Release 4.8 net/rxrpc/call_event.c

Directory: net/rxrpc
/* Management of Tx window, Tx resend, ACKs and out-of-sequence reception
 *
 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
 * Written by David Howells (dhowells@redhat.com)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or (at your option) any later version.
 */


#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/module.h>
#include <linux/circ_buf.h>
#include <linux/net.h>
#include <linux/skbuff.h>
#include <linux/slab.h>
#include <linux/udp.h>
#include <net/sock.h>
#include <net/af_rxrpc.h>
#include "ar-internal.h"

/*
 * propose an ACK be sent
 */

void __rxrpc_propose_ACK(struct rxrpc_call *call, u8 ack_reason, u32 serial, bool immediate) { unsigned long expiry; s8 prior = rxrpc_ack_priority[ack_reason]; ASSERTCMP(prior, >, 0); _enter("{%d},%s,%%%x,%u", call->debug_id, rxrpc_acks(ack_reason), serial, immediate); if (prior < rxrpc_ack_priority[call->ackr_reason]) { if (immediate) goto cancel_timer; return; } /* update DELAY, IDLE, REQUESTED and PING_RESPONSE ACK serial * numbers */ if (prior == rxrpc_ack_priority[call->ackr_reason]) { if (prior <= 4) call->ackr_serial = serial; if (immediate) goto cancel_timer; return; } call->ackr_reason = ack_reason; call->ackr_serial = serial; switch (ack_reason) { case RXRPC_ACK_DELAY: _debug("run delay timer"); expiry = rxrpc_soft_ack_delay; goto run_timer; case RXRPC_ACK_IDLE: if (!immediate) { _debug("run defer timer"); expiry = rxrpc_idle_ack_delay; goto run_timer; } goto cancel_timer; case RXRPC_ACK_REQUESTED: expiry = rxrpc_requested_ack_delay; if (!expiry) goto cancel_timer; if (!immediate || serial == 1) { _debug("run defer timer"); goto run_timer; } default: _debug("immediate ACK"); goto cancel_timer; } run_timer: expiry += jiffies; if (!timer_pending(&call->ack_timer) || time_after(call->ack_timer.expires, expiry)) mod_timer(&call->ack_timer, expiry); return; cancel_timer: _debug("cancel timer %%%u", serial); try_to_del_timer_sync(&call->ack_timer); read_lock_bh(&call->state_lock); if (call->state <= RXRPC_CALL_COMPLETE && !test_and_set_bit(RXRPC_CALL_EV_ACK, &call->events)) rxrpc_queue_call(call); read_unlock_bh(&call->state_lock); }

Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells30899.35%685.71%
dan carpenterdan carpenter20.65%114.29%
Total310100.00%7100.00%

/* * propose an ACK be sent, locking the call structure */
void rxrpc_propose_ACK(struct rxrpc_call *call, u8 ack_reason, u32 serial, bool immediate) { s8 prior = rxrpc_ack_priority[ack_reason]; if (prior > rxrpc_ack_priority[call->ackr_reason]) { spin_lock_bh(&call->lock); __rxrpc_propose_ACK(call, ack_reason, serial, immediate); spin_unlock_bh(&call->lock); } }

Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells67100.00%3100.00%
Total67100.00%3100.00%

/* * set the resend timer */
static void rxrpc_set_resend(struct rxrpc_call *call, u8 resend, unsigned long resend_at) { read_lock_bh(&call->state_lock); if (call->state >= RXRPC_CALL_COMPLETE) resend = 0; if (resend & 1) { _debug("SET RESEND"); set_bit(RXRPC_CALL_EV_RESEND, &call->events); } if (resend & 2) { _debug("MODIFY RESEND TIMER"); set_bit(RXRPC_CALL_RUN_RTIMER, &call->flags); mod_timer(&call->resend_timer, resend_at); } else { _debug("KILL RESEND TIMER"); del_timer_sync(&call->resend_timer); clear_bit(RXRPC_CALL_EV_RESEND_TIMER, &call->events); clear_bit(RXRPC_CALL_RUN_RTIMER, &call->flags); } read_unlock_bh(&call->state_lock); }

Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells138100.00%2100.00%
Total138100.00%2100.00%

/* * resend packets */
static void rxrpc_resend(struct rxrpc_call *call) { struct rxrpc_wire_header *whdr; struct rxrpc_skb_priv *sp; struct sk_buff *txb; unsigned long *p_txb, resend_at; bool stop; int loop; u8 resend; _enter("{%d,%d,%d,%d},", call->acks_hard, call->acks_unacked, atomic_read(&call->sequence), CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz)); stop = false; resend = 0; resend_at = 0; for (loop = call->acks_tail; loop != call->acks_head || stop; loop = (loop + 1) & (call->acks_winsz - 1) ) { p_txb = call->acks_window + loop; smp_read_barrier_depends(); if (*p_txb & 1) continue; txb = (struct sk_buff *) *p_txb; sp = rxrpc_skb(txb); if (sp->need_resend) { sp->need_resend = false; /* each Tx packet has a new serial number */ sp->hdr.serial = atomic_inc_return(&call->conn->serial); whdr = (struct rxrpc_wire_header *)txb->head; whdr->serial = htonl(sp->hdr.serial); _proto("Tx DATA %%%u { #%d }", sp->hdr.serial, sp->hdr.seq); if (rxrpc_send_data_packet(call->conn, txb) < 0) { stop = true; sp->resend_at = jiffies + 3; } else { sp->resend_at = jiffies + rxrpc_resend_timeout; } } if (time_after_eq(jiffies + 1, sp->resend_at)) { sp->need_resend = true; resend |= 1; } else if (resend & 2) { if (time_before(sp->resend_at, resend_at)) resend_at = sp->resend_at; } else { resend_at = sp->resend_at; resend |= 2; } } rxrpc_set_resend(call, resend, resend_at); _leave(""); }

Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells34197.99%360.00%
florian westphalflorian westphal51.44%120.00%
rusty russellrusty russell20.57%120.00%
Total348100.00%5100.00%

/* * handle resend timer expiry */
static void rxrpc_resend_timer(struct rxrpc_call *call) { struct rxrpc_skb_priv *sp; struct sk_buff *txb; unsigned long *p_txb, resend_at; int loop; u8 resend; _enter("%d,%d,%d", call->acks_tail, call->acks_unacked, call->acks_head); if (call->state >= RXRPC_CALL_COMPLETE) return; resend = 0; resend_at = 0; for (loop = call->acks_unacked; loop != call->acks_head; loop = (loop + 1) & (call->acks_winsz - 1) ) { p_txb = call->acks_window + loop; smp_read_barrier_depends(); txb = (struct sk_buff *) (*p_txb & ~1); sp = rxrpc_skb(txb); ASSERT(!(*p_txb & 1)); if (sp->need_resend) { ; } else if (time_after_eq(jiffies + 1, sp->resend_at)) { sp->need_resend = true; resend |= 1; } else if (resend & 2) { if (time_before(sp->resend_at, resend_at)) resend_at = sp->resend_at; } else { resend_at = sp->resend_at; resend |= 2; } } rxrpc_set_resend(call, resend, resend_at); _leave(""); }

Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells23199.57%266.67%
rusty russellrusty russell10.43%133.33%
Total232100.00%3100.00%

/* * process soft ACKs of our transmitted packets * - these indicate packets the peer has or has not received, but hasn't yet * given to the consumer, and so can still be discarded and re-requested */
static int rxrpc_process_soft_ACKs(struct rxrpc_call *call, struct rxrpc_ackpacket *ack, struct sk_buff *skb) { struct rxrpc_skb_priv *sp; struct sk_buff *txb; unsigned long *p_txb, resend_at; int loop; u8 sacks[RXRPC_MAXACKS], resend; _enter("{%d,%d},{%d},", call->acks_hard, CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz), ack->nAcks); if (skb_copy_bits(skb, 0, sacks, ack->nAcks) < 0) goto protocol_error; resend = 0; resend_at = 0; for (loop = 0; loop < ack->nAcks; loop++) { p_txb = call->acks_window; p_txb += (call->acks_tail + loop) & (call->acks_winsz - 1); smp_read_barrier_depends(); txb = (struct sk_buff *) (*p_txb & ~1); sp = rxrpc_skb(txb); switch (sacks[loop]) { case RXRPC_ACK_TYPE_ACK: sp->need_resend = false; *p_txb |= 1; break; case RXRPC_ACK_TYPE_NACK: sp->need_resend = true; *p_txb &= ~1; resend = 1; break; default: _debug("Unsupported ACK type %d", sacks[loop]); goto protocol_error; } } smp_mb(); call->acks_unacked = (call->acks_tail + loop) & (call->acks_winsz - 1); /* anything not explicitly ACK'd is implicitly NACK'd, but may just not * have been received or processed yet by the far end */ for (loop = call->acks_unacked; loop != call->acks_head; loop = (loop + 1) & (call->acks_winsz - 1) ) { p_txb = call->acks_window + loop; smp_read_barrier_depends(); txb = (struct sk_buff *) (*p_txb & ~1); sp = rxrpc_skb(txb); if (*p_txb & 1) { /* packet must have been discarded */ sp->need_resend = true; *p_txb &= ~1; resend |= 1; } else if (sp->need_resend) { ; } else if (time_after_eq(jiffies + 1, sp->resend_at)) { sp->need_resend = true; resend |= 1; } else if (resend & 2) { if (time_before(sp->resend_at, resend_at)) resend_at = sp->resend_at; } else { resend_at = sp->resend_at; resend |= 2; } } rxrpc_set_resend(call, resend, resend_at); _leave(" = 0"); return 0; protocol_error: _leave(" = -EPROTO"); return -EPROTO; }

Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells44399.11%150.00%
rusty russellrusty russell40.89%150.00%
Total447100.00%2100.00%

/* * discard hard-ACK'd packets from the Tx window */
static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard) { unsigned long _skb; int tail = call->acks_tail, old_tail; int win = CIRC_CNT(call->acks_head, tail, call->acks_winsz); _enter("{%u,%u},%u", call->acks_hard, win, hard); ASSERTCMP(hard - call->acks_hard, <=, win); while (call->acks_hard < hard) { smp_read_barrier_depends(); _skb = call->acks_window[tail] & ~1; rxrpc_free_skb((struct sk_buff *) _skb); old_tail = tail; tail = (tail + 1) & (call->acks_winsz - 1); call->acks_tail = tail; if (call->acks_unacked == old_tail) call->acks_unacked = tail; call->acks_hard++; } wake_up(&call->tx_waitq); }

Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells157100.00%2100.00%
Total157100.00%2100.00%

/* * clear the Tx window in the event of a failure */
static void rxrpc_clear_tx_window(struct rxrpc_call *call) { rxrpc_rotate_tx_window(call, atomic_read(&call->sequence)); }

Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells24100.00%1100.00%
Total24100.00%1100.00%

/* * drain the out of sequence received packet queue into the packet Rx queue */
static int rxrpc_drain_rx_oos_queue(struct rxrpc_call *call) { struct rxrpc_skb_priv *sp; struct sk_buff *skb; bool terminal; int ret; _enter("{%d,%d}", call->rx_data_post, call->rx_first_oos); spin_lock_bh(&call->lock); ret = -ECONNRESET; if (test_bit(RXRPC_CALL_RELEASED, &call->flags)) goto socket_unavailable; skb = skb_dequeue(&call->rx_oos_queue); if (skb) { sp = rxrpc_skb(skb); _debug("drain OOS packet %d [%d]", sp->hdr.seq, call->rx_first_oos); if (sp->hdr.seq != call->rx_first_oos) { skb_queue_head(&call->rx_oos_queue, skb); call->rx_first_oos = rxrpc_skb(skb)->hdr.seq; _debug("requeue %p {%u}", skb, call->rx_first_oos); } else { skb->mark = RXRPC_SKB_MARK_DATA; terminal = ((sp->hdr.flags & RXRPC_LAST_PACKET) && !(sp->hdr.flags & RXRPC_CLIENT_INITIATED)); ret = rxrpc_queue_rcv_skb(call, skb, true, terminal); BUG_ON(ret < 0); _debug("drain #%u", call->rx_data_post); call->rx_data_post++; /* find out what the next packet is */ skb = skb_peek(&call->rx_oos_queue); if (skb) call->rx_first_oos = rxrpc_skb(skb)->hdr.seq; else call->rx_first_oos = 0; _debug("peek %p {%u}", skb, call->rx_first_oos); } } ret = 0; socket_unavailable: spin_unlock_bh(&call->lock); _leave(" = %d", ret); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells292100.00%1100.00%
Total292100.00%1100.00%

/* * insert an out of sequence packet into the buffer */
static void rxrpc_insert_oos_packet(struct rxrpc_call *call, struct sk_buff *skb) { struct rxrpc_skb_priv *sp, *psp; struct sk_buff *p; u32 seq; sp = rxrpc_skb(skb); seq = sp->hdr.seq; _enter(",,{%u}", seq); skb->destructor = rxrpc_packet_destructor; ASSERTCMP(sp->call, ==, NULL); sp->call = call; rxrpc_get_call(call); atomic_inc(&call->skb_count); /* insert into the buffer in sequence order */ spin_lock_bh(&call->lock); skb_queue_walk(&call->rx_oos_queue, p) { psp = rxrpc_skb(p); if (psp->hdr.seq > seq) { _debug("insert oos #%u before #%u", seq, psp->hdr.seq); skb_insert(p, skb, &call->rx_oos_queue); goto inserted; } } _debug("append oos #%u", seq); skb_queue_tail(&call->rx_oos_queue, skb); inserted: /* we might now have a new front to the queue */ if (call->rx_first_oos == 0 || seq < call->rx_first_oos) call->rx_first_oos = seq; read_lock(&call->state_lock); if (call->state < RXRPC_CALL_COMPLETE && call->rx_data_post == call->rx_first_oos) { _debug("drain rx oos now"); set_bit(RXRPC_CALL_EV_DRAIN_RX_OOS, &call->events); } read_unlock(&call->state_lock); spin_unlock_bh(&call->lock); _leave(" [stored #%u]", call->rx_first_oos); }

Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells260100.00%3100.00%
Total260100.00%3100.00%

/* * clear the Tx window on final ACK reception */
static void rxrpc_zap_tx_window(struct rxrpc_call *call) { struct rxrpc_skb_priv *sp; struct sk_buff *skb; unsigned long _skb, *acks_window; u8 winsz = call->acks_winsz; int tail; acks_window = call->acks_window; call->acks_window = NULL; while (CIRC_CNT(call->acks_head, call->acks_tail, winsz) > 0) { tail = call->acks_tail; smp_read_barrier_depends(); _skb = acks_window[tail] & ~1; smp_mb(); call->acks_tail = (call->acks_tail + 1) & (winsz - 1); skb = (struct sk_buff *) _skb; sp = rxrpc_skb(skb); _debug("+++ clear Tx %u", sp->hdr.seq); rxrpc_free_skb(skb); } kfree(acks_window); }

Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells146100.00%2100.00%
Total146100.00%2100.00%

/* * process the extra information that may be appended to an ACK packet */
static void rxrpc_extract_ackinfo(struct rxrpc_call *call, struct sk_buff *skb, unsigned int latest, int nAcks) { struct rxrpc_ackinfo ackinfo; struct rxrpc_peer *peer; unsigned int mtu; if (skb_copy_bits(skb, nAcks + 3, &ackinfo, sizeof(ackinfo)) < 0) { _leave(" [no ackinfo]"); return; } _proto("Rx ACK %%%u Info { rx=%u max=%u rwin=%u jm=%u }", latest, ntohl(ackinfo.rxMTU), ntohl(ackinfo.maxMTU), ntohl(ackinfo.rwind), ntohl(ackinfo.jumbo_max)); mtu = min(ntohl(ackinfo.rxMTU), ntohl(ackinfo.maxMTU)); peer = call->conn->params.peer; if (mtu < peer->maxdata) { spin_lock_bh(&peer->lock); peer->maxdata = mtu; peer->mtu = mtu + peer->hdrsize; spin_unlock_bh(&peer->lock); _net("Net MTU %u (maxdata %u)", peer->mtu, peer->maxdata); } }

Contributors

PersonTokensPropCommitsCommitProp
david howellsdavid howells18298.91%266.67%
eric dumazeteric dumazet21.09%133.33%
Total184100.00%3100.00%

/* * process packets in the reception queue */
static int rxrpc_process_rx_queue(struct rxrpc_call *call, u32 *_abort_code) { struct rxrpc_ackpacket ack; struct rxrpc_skb_priv *sp; struct sk_buff *skb; bool post_ACK; int latest; u32 hard, tx; _enter(""); process_further: skb = skb_dequeue(&call->rx_queue); if (!skb) return -EAGAIN; _net("deferred skb %p", skb); sp = rxrpc_skb(skb); _debug("process %s [st %d]", rxrpc_pkts[sp->hdr.type], call