Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3829643ybb; Mon, 6 Apr 2020 17:02:19 -0700 (PDT) X-Google-Smtp-Source: APiQypK0MKw3QfZh84SpcdnhOdwSHBYTRNda63w5hxEbIfILEC/raANzT6KKelTKe6xHvRRwwfd8 X-Received: by 2002:a05:6830:1e82:: with SMTP id n2mr20542885otr.338.1586217739573; Mon, 06 Apr 2020 17:02:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586217739; cv=none; d=google.com; s=arc-20160816; b=C9xASlQQxnu9PNsw5fzboG8Huv5kkOaRk+QckBa540HPfF3q2OeZWLpSVhava0Qm0M W2YFioo1IjkAhTS4jHKIdG/57uFd6WMVUmSGnFFPd8mZr07Wqm3bfoAahzCb1a/tNhwJ Kpx8dXjnsfXn1IWLzvLxy46jlQJuGDhqnk/XuCMPz6h4gGUJNxpKtkP4pIqR0qmL6LI7 hXVhqHxS1/tCM2KEk/4l5BC2ZXE/acTOuoIzx7iEWz4BmhD7RuxXfGzG+cFfzYnlMhau uIep1yUc4o6RrTsbDphjKl3YzqXkmBGOZi3TYoO5edttb7iIjKQ4orVnjz3g1uMfnGL8 KTkg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TUsCGEycQGfhC7fGSeexE4do9mNKeY3rr7wSdQTkAsk=; b=1JKj4R0SseLGDoBSc+WDxOGe6UJHVlPPnZNVwuDgLfVHjC/PPXAT1cYqBJXxNRx/nP 5qoFcuHSFO0jhQWlGnfJ7viusG0a50KKKXNrspInhkeRFjTzgwhMNLsvcINZ4kcPRBLo QrTslDApFJbL8Lq96A2ErH0UX8ZNAFlZu4uWt78FMMIu8VYNTLA2Byo9cK4UHdC93T3T w5GTLx/YIyeA3hHx86XBdKGn+m2EFKbFRZrT7tvrlUyfqbC3wP0rQLsiMtpVg275hfqD R9dlPhrN6pmSxTOiJWYsN+B/TCoZ5Zwp/wMAH+i1xcHz7FxlNHs6Xv0YyzSzLQcyC6ew /O9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yfmrQ58X; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 9si7950624oip.112.2020.04.06.17.02.07; Mon, 06 Apr 2020 17:02:19 -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=yfmrQ58X; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726780AbgDGABX (ORCPT + 99 others); Mon, 6 Apr 2020 20:01:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:34010 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726713AbgDGABP (ORCPT ); Mon, 6 Apr 2020 20:01:15 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C21EC2082D; Tue, 7 Apr 2020 00:01:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586217675; bh=P4mihfxv14d3mYrlZSFYDB506Er2e2jwCb818HK4qwI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yfmrQ58XJUnP68+7Tmy3RfxVVAQvcPNj/it8TmmhCKvla0JJX0ie8jIwLRmu722SA MfsYp0uOfGVSsueEnHJLXXI+io8HKTKOXNMtbnJ8owWSc6Olq4FOJOaF2F/vVPAI4Q SI94dEudv3oc7yvBNIPkTZF/WRefXLIq19W6rtc4= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: David Howells , Sasha Levin , linux-afs@lists.infradead.org, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.5 13/35] rxrpc: Abstract out the calculation of whether there's Tx space Date: Mon, 6 Apr 2020 20:00:35 -0400 Message-Id: <20200407000058.16423-13-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200407000058.16423-1-sashal@kernel.org> References: <20200407000058.16423-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Howells [ Upstream commit 158fe6665389964a1de212818b4a5c52b7f7aff4 ] Abstract out the calculation of there being sufficient Tx buffer space. This is reproduced several times in the rxrpc sendmsg code. Signed-off-by: David Howells Signed-off-by: Sasha Levin --- net/rxrpc/sendmsg.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/net/rxrpc/sendmsg.c b/net/rxrpc/sendmsg.c index 813fd68881429..a13051d380973 100644 --- a/net/rxrpc/sendmsg.c +++ b/net/rxrpc/sendmsg.c @@ -17,6 +17,21 @@ #include #include "ar-internal.h" +/* + * Return true if there's sufficient Tx queue space. + */ +static bool rxrpc_check_tx_space(struct rxrpc_call *call, rxrpc_seq_t *_tx_win) +{ + unsigned int win_size = + min_t(unsigned int, call->tx_winsize, + call->cong_cwnd + call->cong_extra); + rxrpc_seq_t tx_win = READ_ONCE(call->tx_hard_ack); + + if (_tx_win) + *_tx_win = tx_win; + return call->tx_top - tx_win < win_size; +} + /* * Wait for space to appear in the Tx queue or a signal to occur. */ @@ -26,9 +41,7 @@ static int rxrpc_wait_for_tx_window_intr(struct rxrpc_sock *rx, { for (;;) { set_current_state(TASK_INTERRUPTIBLE); - if (call->tx_top - call->tx_hard_ack < - min_t(unsigned int, call->tx_winsize, - call->cong_cwnd + call->cong_extra)) + if (rxrpc_check_tx_space(call, NULL)) return 0; if (call->state >= RXRPC_CALL_COMPLETE) @@ -68,9 +81,7 @@ static int rxrpc_wait_for_tx_window_nonintr(struct rxrpc_sock *rx, set_current_state(TASK_UNINTERRUPTIBLE); tx_win = READ_ONCE(call->tx_hard_ack); - if (call->tx_top - tx_win < - min_t(unsigned int, call->tx_winsize, - call->cong_cwnd + call->cong_extra)) + if (rxrpc_check_tx_space(call, &tx_win)) return 0; if (call->state >= RXRPC_CALL_COMPLETE) @@ -302,9 +313,7 @@ static int rxrpc_send_data(struct rxrpc_sock *rx, _debug("alloc"); - if (call->tx_top - call->tx_hard_ack >= - min_t(unsigned int, call->tx_winsize, - call->cong_cwnd + call->cong_extra)) { + if (!rxrpc_check_tx_space(call, NULL)) { ret = -EAGAIN; if (msg->msg_flags & MSG_DONTWAIT) goto maybe_error; -- 2.20.1