Received: by 10.192.165.148 with SMTP id m20csp4156836imm; Mon, 30 Apr 2018 12:51:40 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp15qDC7a0U/xkh7DFMuBV/7DmhEiJvyP8h+ONqXY0pAGpnzeIDKQxOsnlFe5I8oVSCEDzn X-Received: by 2002:a17:902:2804:: with SMTP id e4-v6mr13588888plb.153.1525117900539; Mon, 30 Apr 2018 12:51:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525117900; cv=none; d=google.com; s=arc-20160816; b=cK3tsLc1Fzqn10P0E4IoYN/nefvio69Hij4qEOk3OiulWt4VKZ2ttILkNfYbrslYxe WI5L+OHDa8mbx9EfaIhNCe5+hLLs79gZVVXMlUK1BSgMwqjSo0bsE3ivJYwvB6a3ix+c sU1xigVIKV/dkHfwYWYi8FNnxqm91bx6QLjobITTf4b4j03zyIYTbfoZHyOXRqEC2zCM N9gmNg5mnguhBh3VdASF0yNz9niAADFveaCmaNKME992dq85wuvemb36SkMmObj3A6qA qhIeBc1arcN/E2u9BdVzdHg3Odt8UJ3IVz379rOpjNQ7NsQ8H2rqtDULMak3C+7/7K7S mNiw== 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:dmarc-filter :arc-authentication-results; bh=UYyAtUFuV6EMIiPrRzOMOuuAttxv/XfowVIykF3Sgeo=; b=zostHxnAGEbI5YDTXhKKkkGZbdE/utPU5NobiWLfQgZ/Lpwman0lIkrBgSOkza2pla Av73WtHGXdSbHLbVtx0HGPT7bjg+qrfWIV9+v2e8xGIwEsoQCULrQO+puW3FgkAaxztU uVF3FMr2t4EmWQvnLxRxB2+fPR1g8perP59szoGoYS8/ALBp7yLAAqWtueZpUEtRl0ES rCEeeTplQKIBD3dypgdq5yl4pxVC9giZHQLNE8t5DlImjGxQD/uDEogUtmluW/2jkFs8 +CMiVqqOmWH0wo+bIbtVzoY6HZGicpY5PIVwZIN/U20TmIVFB+lpQcEZGxFnmgwuU+Gc nm8w== 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 t64-v6si6510432pgc.160.2018.04.30.12.50.56; Mon, 30 Apr 2018 12:51:40 -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; 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 S1756570AbeD3Tqi (ORCPT + 99 others); Mon, 30 Apr 2018 15:46:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:35932 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755211AbeD3T2V (ORCPT ); Mon, 30 Apr 2018 15:28:21 -0400 Received: from localhost (unknown [104.132.1.102]) (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 3E31222E03; Mon, 30 Apr 2018 19:28:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3E31222E03 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Matt Redfearn , Long Li , Ronnie Sahlberg , Steve French Subject: [PATCH 4.16 036/113] cifs: smbd: Avoid allocating iov on the stack Date: Mon, 30 Apr 2018 12:24:07 -0700 Message-Id: <20180430184016.580365072@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430184015.043892819@linuxfoundation.org> References: <20180430184015.043892819@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.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Long Li commit 8bcda1d2a79da4ab84162574eee2c9f6e1a12a03 upstream. It's not necessary to allocate another iov when going through the buffers in smbd_send() through RDMA send. Remove it to reduce stack size. Thanks to Matt for spotting a printk typo in the earlier version of this. CC: Matt Redfearn Signed-off-by: Long Li Acked-by: Ronnie Sahlberg Cc: stable@vger.kernel.org Signed-off-by: Steve French Signed-off-by: Greg Kroah-Hartman --- fs/cifs/smbdirect.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) --- a/fs/cifs/smbdirect.c +++ b/fs/cifs/smbdirect.c @@ -2086,7 +2086,7 @@ int smbd_send(struct smbd_connection *in int start, i, j; int max_iov_size = info->max_send_size - sizeof(struct smbd_data_transfer); - struct kvec iov[SMBDIRECT_MAX_SGE]; + struct kvec *iov; int rc; info->smbd_send_pending++; @@ -2096,32 +2096,20 @@ int smbd_send(struct smbd_connection *in } /* - * This usually means a configuration error - * We use RDMA read/write for packet size > rdma_readwrite_threshold - * as long as it's properly configured we should never get into this - * situation - */ - if (rqst->rq_nvec + rqst->rq_npages > SMBDIRECT_MAX_SGE) { - log_write(ERR, "maximum send segment %x exceeding %x\n", - rqst->rq_nvec + rqst->rq_npages, SMBDIRECT_MAX_SGE); - rc = -EINVAL; - goto done; - } - - /* - * Remove the RFC1002 length defined in MS-SMB2 section 2.1 - * It is used only for TCP transport + * Skip the RFC1002 length defined in MS-SMB2 section 2.1 + * It is used only for TCP transport in the iov[0] * In future we may want to add a transport layer under protocol * layer so this will only be issued to TCP transport */ - iov[0].iov_base = (char *)rqst->rq_iov[0].iov_base + 4; - iov[0].iov_len = rqst->rq_iov[0].iov_len - 4; - buflen += iov[0].iov_len; + + if (rqst->rq_iov[0].iov_len != 4) { + log_write(ERR, "expected the pdu length in 1st iov, but got %zu\n", rqst->rq_iov[0].iov_len); + return -EINVAL; + } + iov = &rqst->rq_iov[1]; /* total up iov array first */ - for (i = 1; i < rqst->rq_nvec; i++) { - iov[i].iov_base = rqst->rq_iov[i].iov_base; - iov[i].iov_len = rqst->rq_iov[i].iov_len; + for (i = 0; i < rqst->rq_nvec-1; i++) { buflen += iov[i].iov_len; } @@ -2194,14 +2182,14 @@ int smbd_send(struct smbd_connection *in goto done; } i++; - if (i == rqst->rq_nvec) + if (i == rqst->rq_nvec-1) break; } start = i; buflen = 0; } else { i++; - if (i == rqst->rq_nvec) { + if (i == rqst->rq_nvec-1) { /* send out all remaining vecs */ remaining_data_length -= buflen; log_write(INFO,