Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp2454157imd; Fri, 2 Nov 2018 11:40:42 -0700 (PDT) X-Google-Smtp-Source: AJdET5cRKdyveM6g/ljtWsuGug6NapGyI6i0LRQaqOO4iZrL/p+wx57w8ZosDWC91q38UbE34ZtH X-Received: by 2002:a63:7b06:: with SMTP id w6mr11885005pgc.288.1541184042514; Fri, 02 Nov 2018 11:40:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541184042; cv=none; d=google.com; s=arc-20160816; b=vbiKxApUpJhf16YnlTPpsblgwZIOJra+Q8VU5b06tUVro3SraJ0J/GH7LD44mzkabL gz2/X/fYJhbmNU4nAAW4dL2ekZzIfIVdA413CoygEHfjbFLQ6OJy9h5gl+6kihuIwWsj PB0zvqXIN6EM+GWTfmeWCvPU8aFDbsAkgwYLUvvTvLH1/wDCZTvV8n9hgdoB0f16gC/M 8Sgu7vt9qRbFE+vncJW59u4pEy/mq5Wcm6cug2JRJfI7LCpFGIFsrC9rXPFAKJMi2dTg DSEspclllsfbHPHChEoFcW/r5SmJXPLM6LOqvGAKMJjEwOycaEZ5f+6q/N/9WAUkldf7 3DtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=HEp72q+oeQsFwHA7C+CSVpzPEcV40Hh9PSPZJVJW9Yw=; b=nVva61jnBWR+y9jTCat5PmcXdlSZ5I5iV/S+L0BQlZQJqGeJ+74w8caXXGOuiYP8kt jAcRSxgu50vnbpwrx7rxkZQkrNeVReYQt2l2x8gINBqb9Tgx5NsSGI/QAcfphRhv65Cq dfDjqDC0BfH+P1R5eT57hNOBQe1P8DV6uozHaIoHsx5Z0xR5Hgj9GCfwDSBmBpNTHGyn LHHJqoFx3plSRPBcKAZDmAYcRFonPmB2E921X/XYbbd4nGMFgS4Uax2b3c3mZVfTFYSw OavQqLXCpp+owhjifd7DNSxaFflnczFYG+rIVCI0UeNkoHuOEs25FbsMuBTPNv/1JDh8 OeOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yUOhECQr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l9-v6si34149721pgj.210.2018.11.02.11.40.27; Fri, 02 Nov 2018 11:40:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yUOhECQr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729134AbeKCDrj (ORCPT + 99 others); Fri, 2 Nov 2018 23:47:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:41734 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728102AbeKCDri (ORCPT ); Fri, 2 Nov 2018 23:47:38 -0400 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B80532082E; Fri, 2 Nov 2018 18:39:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541183966; bh=C7yI2r5455g1t1fGj3qeJBwXqtqCru/k7q52luDH1ss=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yUOhECQr2MDgP8/lIg76wbV5aYNBC8RJOzFT9e1epGr46s8DpdTsn9JFM+mEyBy2j L7NbTKMycpYllRIya/JTX29noE68fVorVj/I5xRI/sFRwvD7qdR0ICPhnH/Mfridv2 yflq84HWuzvsxJlgGswYQNNbm/G8MzTm929KMbgQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Howells , Sasha Levin Subject: [PATCH 4.18 037/150] rxrpc: Fix RTT gathering Date: Fri, 2 Nov 2018 19:33:19 +0100 Message-Id: <20181102182905.903056585@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181102182902.250560510@linuxfoundation.org> References: <20181102182902.250560510@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit b604dd9883f783a94020d772e4fe03160f455372 ] Fix RTT information gathering in AF_RXRPC by the following means: (1) Enable Rx timestamping on the transport socket with SO_TIMESTAMPNS. (2) If the sk_buff doesn't have a timestamp set when rxrpc_data_ready() collects it, set it at that point. (3) Allow ACKs to be requested on the last packet of a client call, but not a service call. We need to be careful lest we undo: bf7d620abf22c321208a4da4f435e7af52551a21 Author: David Howells Date: Thu Oct 6 08:11:51 2016 +0100 rxrpc: Don't request an ACK on the last DATA packet of a call's Tx phase but that only really applies to service calls that we're handling, since the client side gets to send the final ACK (or not). (4) When about to transmit an ACK or DATA packet, record the Tx timestamp before only; don't update the timestamp afterwards. (5) Switch the ordering between recording the serial and recording the timestamp to always set the serial number first. The serial number shouldn't be seen referenced by an ACK packet until we've transmitted the packet bearing it - so in the Rx path, we don't need the timestamp until we've checked the serial number. Fixes: cf1a6474f807 ("rxrpc: Add per-peer RTT tracker") Signed-off-by: David Howells Signed-off-by: Sasha Levin --- net/rxrpc/input.c | 8 ++++++-- net/rxrpc/local_object.c | 9 +++++++++ net/rxrpc/output.c | 31 ++++++++++++++++++------------- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/net/rxrpc/input.c b/net/rxrpc/input.c index 338fbbf216a9..f6027c875876 100644 --- a/net/rxrpc/input.c +++ b/net/rxrpc/input.c @@ -616,13 +616,14 @@ static void rxrpc_input_requested_ack(struct rxrpc_call *call, if (!skb) continue; + sent_at = skb->tstamp; + smp_rmb(); /* Read timestamp before serial. */ sp = rxrpc_skb(skb); if (sp->hdr.serial != orig_serial) continue; - smp_rmb(); - sent_at = skb->tstamp; goto found; } + return; found: @@ -1137,6 +1138,9 @@ void rxrpc_data_ready(struct sock *udp_sk) return; } + if (skb->tstamp == 0) + skb->tstamp = ktime_get_real(); + rxrpc_new_skb(skb, rxrpc_skb_rx_received); _net("recv skb %p", skb); diff --git a/net/rxrpc/local_object.c b/net/rxrpc/local_object.c index b493e6b62740..5d89ea5c1976 100644 --- a/net/rxrpc/local_object.c +++ b/net/rxrpc/local_object.c @@ -173,6 +173,15 @@ static int rxrpc_open_socket(struct rxrpc_local *local, struct net *net) _debug("setsockopt failed"); goto error; } + + /* We want receive timestamps. */ + opt = 1; + ret = kernel_setsockopt(local->socket, SOL_SOCKET, SO_TIMESTAMPNS, + (char *)&opt, sizeof(opt)); + if (ret < 0) { + _debug("setsockopt failed"); + goto error; + } break; default: diff --git a/net/rxrpc/output.c b/net/rxrpc/output.c index 4774c8f5634d..6ac21bb2071d 100644 --- a/net/rxrpc/output.c +++ b/net/rxrpc/output.c @@ -124,7 +124,6 @@ int rxrpc_send_ack_packet(struct rxrpc_call *call, bool ping, struct kvec iov[2]; rxrpc_serial_t serial; rxrpc_seq_t hard_ack, top; - ktime_t now; size_t len, n; int ret; u8 reason; @@ -196,9 +195,7 @@ int rxrpc_send_ack_packet(struct rxrpc_call *call, bool ping, /* We need to stick a time in before we send the packet in case * the reply gets back before kernel_sendmsg() completes - but * asking UDP to send the packet can take a relatively long - * time, so we update the time after, on the assumption that - * the packet transmission is more likely to happen towards the - * end of the kernel_sendmsg() call. + * time. */ call->ping_time = ktime_get_real(); set_bit(RXRPC_CALL_PINGING, &call->flags); @@ -206,9 +203,6 @@ int rxrpc_send_ack_packet(struct rxrpc_call *call, bool ping, } ret = kernel_sendmsg(conn->params.local->socket, &msg, iov, 2, len); - now = ktime_get_real(); - if (ping) - call->ping_time = now; conn->params.peer->last_tx_at = ktime_get_seconds(); if (ret < 0) trace_rxrpc_tx_fail(call->debug_id, serial, ret, @@ -357,8 +351,14 @@ int rxrpc_send_data_packet(struct rxrpc_call *call, struct sk_buff *skb, /* If our RTT cache needs working on, request an ACK. Also request * ACKs if a DATA packet appears to have been lost. + * + * However, we mustn't request an ACK on the last reply packet of a + * service call, lest OpenAFS incorrectly send us an ACK with some + * soft-ACKs in it and then never follow up with a proper hard ACK. */ - if (!(sp->hdr.flags & RXRPC_LAST_PACKET) && + if ((!(sp->hdr.flags & RXRPC_LAST_PACKET) || + rxrpc_to_server(sp) + ) && (test_and_clear_bit(RXRPC_CALL_EV_ACK_LOST, &call->events) || retrans || call->cong_mode == RXRPC_CALL_SLOW_START || @@ -384,6 +384,11 @@ int rxrpc_send_data_packet(struct rxrpc_call *call, struct sk_buff *skb, goto send_fragmentable; down_read(&conn->params.local->defrag_sem); + + sp->hdr.serial = serial; + smp_wmb(); /* Set serial before timestamp */ + skb->tstamp = ktime_get_real(); + /* send the packet by UDP * - returns -EMSGSIZE if UDP would have to fragment the packet * to go out of the interface @@ -404,12 +409,8 @@ done: trace_rxrpc_tx_data(call, sp->hdr.seq, serial, whdr.flags, retrans, lost); if (ret >= 0) { - ktime_t now = ktime_get_real(); - skb->tstamp = now; - smp_wmb(); - sp->hdr.serial = serial; if (whdr.flags & RXRPC_REQUEST_ACK) { - call->peer->rtt_last_req = now; + call->peer->rtt_last_req = skb->tstamp; trace_rxrpc_rtt_tx(call, rxrpc_rtt_tx_data, serial); if (call->peer->rtt_usage > 1) { unsigned long nowj = jiffies, ack_lost_at; @@ -448,6 +449,10 @@ send_fragmentable: down_write(&conn->params.local->defrag_sem); + sp->hdr.serial = serial; + smp_wmb(); /* Set serial before timestamp */ + skb->tstamp = ktime_get_real(); + switch (conn->params.local->srx.transport.family) { case AF_INET: opt = IP_PMTUDISC_DONT; -- 2.17.1