Received: by 10.223.185.116 with SMTP id b49csp5450192wrg; Wed, 7 Mar 2018 11:59:48 -0800 (PST) X-Google-Smtp-Source: AG47ELv+kpE8xTxAlnTsSF0S1Q0uufsU2qrJ+mZIax0oZYh2kD9mjomyHwx0SV1bMLPtv54C3/KY X-Received: by 10.98.217.76 with SMTP id s73mr23627287pfg.209.1520452788720; Wed, 07 Mar 2018 11:59:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520452788; cv=none; d=google.com; s=arc-20160816; b=qp8TrfNTXnbkDjACoqtiQWxLGR6lzmkvtA3aGyDjAQvaDewsw04zdWXuNZj9kMPpGc yGbD50mgD/6klIcd9Q9u0gXbj2UUq7HJX1mlVC+Rvz8w1LSuauSTvQmyosDcpzzzp0B4 4jtBukGhIGhByDkL68OT64Zx9Kr5gocvvQ6mJYdRnQbtJvEZMHpWklvtB8n6LfaBG5U2 PLGCOHoAOFuTOnfrEBKfvcVpieEeuzfNA/U7XrSq67LBYOND3Gcb9rsXFBObsxIArD6t NvNOLycnuQy1D2+3lnNHQeQY37JLh8CYVRQszSVhIeHSreHZimt9u/Ry+AYJqhovKWk3 UZ7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=VJcszIFopjX1IjQW49o2atiEt7LLHV4FINcodO5REO0=; b=f7a+TJSyAzqNlsf/mB6/a07z8kfbEw1QHmaNA8qETTb3Rwwf7dUCkmVhvfrMa5pfl6 XeISgtpFVkfLRekgLmDHlyWvCVhxDD1BgYFz8a9twMhtadpfme3PMOLgtoLVNCMvyOC1 AkurP7f4cNROSw2LFC+dJXT0KXPXf4aaocKt25QGh0UTAawo2wp/OAx5JibRLvSQiXRP WP1uePI9qMaDZLYl/xMLFKd1kkF25dHAXzrZo7aNoKtWoIq6JCZEaBIrBxs9NXbyd13x ziToRAM+9fdxo0gZFp9c6dRSJ9JIUanuYEYoU6nfuINWwMO9EBDyX+Hsmq+lw/xcXzuQ d54A== ARC-Authentication-Results: i=1; mx.google.com; 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 g9si11766599pgs.752.2018.03.07.11.59.33; Wed, 07 Mar 2018 11:59:48 -0800 (PST) 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; 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 S965679AbeCGTrH (ORCPT + 99 others); Wed, 7 Mar 2018 14:47:07 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:44868 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754916AbeCGTrE (ORCPT ); Wed, 7 Mar 2018 14:47:04 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 68D7210DA; Wed, 7 Mar 2018 19:47:03 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Julian Wiedmann , "David S. Miller" Subject: [PATCH 4.14 077/110] s390/qeth: fix overestimated count of buffer elements Date: Wed, 7 Mar 2018 11:39:00 -0800 Message-Id: <20180307191049.591681083@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180307191039.748351103@linuxfoundation.org> References: <20180307191039.748351103@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Julian Wiedmann [ Upstream commit 12472af89632beb1ed8dea29d4efe208ca05b06a ] qeth_get_elements_for_range() doesn't know how to handle a 0-length range (ie. start == end), and returns 1 when it should return 0. Such ranges occur on TSO skbs, where the L2/L3/L4 headers (and thus all of the skb's linear data) are skipped when mapping the skb into regular buffer elements. This overestimation may cause several performance-related issues: 1. sub-optimal IO buffer selection, where the next buffer gets selected even though the skb would actually still fit into the current buffer. 2. forced linearization, if the element count for a non-linear skb exceeds QETH_MAX_BUFFER_ELEMENTS. Rather than modifying qeth_get_elements_for_range() and adding overhead to every caller, fix up those callers that are in risk of passing a 0-length range. Fixes: 2863c61334aa ("qeth: refactor calculation of SBALE count") Signed-off-by: Julian Wiedmann Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/s390/net/qeth_core_main.c | 10 ++++++---- drivers/s390/net/qeth_l3_main.c | 11 ++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) --- a/drivers/s390/net/qeth_core_main.c +++ b/drivers/s390/net/qeth_core_main.c @@ -3861,10 +3861,12 @@ EXPORT_SYMBOL_GPL(qeth_get_elements_for_ int qeth_get_elements_no(struct qeth_card *card, struct sk_buff *skb, int extra_elems, int data_offset) { - int elements = qeth_get_elements_for_range( - (addr_t)skb->data + data_offset, - (addr_t)skb->data + skb_headlen(skb)) + - qeth_get_elements_for_frags(skb); + addr_t end = (addr_t)skb->data + skb_headlen(skb); + int elements = qeth_get_elements_for_frags(skb); + addr_t start = (addr_t)skb->data + data_offset; + + if (start != end) + elements += qeth_get_elements_for_range(start, end); if ((elements + extra_elems) > QETH_MAX_BUFFER_ELEMENTS(card)) { QETH_DBF_MESSAGE(2, "Invalid size of IP packet " --- a/drivers/s390/net/qeth_l3_main.c +++ b/drivers/s390/net/qeth_l3_main.c @@ -2633,11 +2633,12 @@ static void qeth_tso_fill_header(struct static int qeth_l3_get_elements_no_tso(struct qeth_card *card, struct sk_buff *skb, int extra_elems) { - addr_t tcpdptr = (addr_t)tcp_hdr(skb) + tcp_hdrlen(skb); - int elements = qeth_get_elements_for_range( - tcpdptr, - (addr_t)skb->data + skb_headlen(skb)) + - qeth_get_elements_for_frags(skb); + addr_t start = (addr_t)tcp_hdr(skb) + tcp_hdrlen(skb); + addr_t end = (addr_t)skb->data + skb_headlen(skb); + int elements = qeth_get_elements_for_frags(skb); + + if (start != end) + elements += qeth_get_elements_for_range(start, end); if ((elements + extra_elems) > QETH_MAX_BUFFER_ELEMENTS(card)) { QETH_DBF_MESSAGE(2,