Received: by 10.223.185.111 with SMTP id b44csp907387wrg; Fri, 9 Mar 2018 16:33:22 -0800 (PST) X-Google-Smtp-Source: AG47ELvphYzWLfzRYr/Uzl9CFGAnx9Dq8gez9yR7OsdyQAD3Ek9aAzzE5pnTS6oyaFSNWLGEiLjt X-Received: by 2002:a17:902:968c:: with SMTP id n12-v6mr327011plp.371.1520642002845; Fri, 09 Mar 2018 16:33:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520642002; cv=none; d=google.com; s=arc-20160816; b=oyWqJvX03Tdb1TNUpfrojOttKJY5FFg0eItE0fiUjLjJpQyOvCWYMnR+uYNy1Dj9TH Y7GKgCe63zWHDukLKK3nW4ZaXPm5kS79TjxXiKAZ6i8AobgxoTxpE1Ceb6hyJkVdHj2w vExmFkDzbXAc7xYGA6Jd+1LTrIn4vPGcVFygCQDCy/y4EHj90fVSl/ECRTMoySL0cs7q /x7fU2JTdaL/ozoLEMVvXt1wcv4I66vHwy/QrCr/AHRSh+sv54LmsuIyJrxccDLZjKSR aRRKnGB7LesDu1H6/P84bAkgEKPOBI1NYGLGGa3W7WmwWWMcN94L0k2zrDdSJesWOsET JPdg== 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=absro0RkSog9yMA89twv/0iBSSkDf2iWhLfyB2NEAZw=; b=BFwMGCPUS1qR/vs/BSsm+i92hwurhLmGNibfdgUthf5x53v29dOYn4vSDqLBMXEvwh SpUEKgV5F0/2IAia2xy9Ns4KZj8JuGEQ8ttZ0vTA/Zx37LGV7fQMb5Lx0sHeZOuJ+dOM dm0PUPp5wBvdmpC43aDorqCI9NJNv97wFAS/tSmK62pYL5hFOWmBhRBPDLgalY3Arfvt xp9QCIrJGSXbYfg/DW7spt3gtUYnH44krabjqCFCmo4//EA8uEZGvZ+mxWU/8S7E17mj E59jPewIrihFdjfpqcNoV92xj3zLb+oHu+BMACYA4Qym2AYMVEQybOZavTWUI2XvrfKr aqeQ== 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 m189si1691146pfc.410.2018.03.09.16.33.08; Fri, 09 Mar 2018 16:33:22 -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 S933880AbeCJAWa (ORCPT + 99 others); Fri, 9 Mar 2018 19:22:30 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:40026 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933578AbeCJAW2 (ORCPT ); Fri, 9 Mar 2018 19:22:28 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 935561176; Sat, 10 Mar 2018 00:22:27 +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.9 51/65] s390/qeth: fix overestimated count of buffer elements Date: Fri, 9 Mar 2018 16:18:51 -0800 Message-Id: <20180310001829.079631694@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180310001824.927996722@linuxfoundation.org> References: <20180310001824.927996722@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.9-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 @@ -3854,10 +3854,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 @@ -2784,11 +2784,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,