From patchwork Fri Jun 1 00:53:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ronnie Sahlberg X-Patchwork-Id: 10442307 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 37BCF602BC for ; Fri, 1 Jun 2018 00:53:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2FF6023B32 for ; Fri, 1 Jun 2018 00:53:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 24C8D26E47; Fri, 1 Jun 2018 00:53:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B21023B32 for ; Fri, 1 Jun 2018 00:53:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750844AbeFAAxk (ORCPT ); Thu, 31 May 2018 20:53:40 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60608 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750756AbeFAAxj (ORCPT ); Thu, 31 May 2018 20:53:39 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7CBE888843; Fri, 1 Jun 2018 00:53:39 +0000 (UTC) Received: from test1135.test.redhat.com (vpn2-54-65.bne.redhat.com [10.64.54.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id A74DD2144B20; Fri, 1 Jun 2018 00:53:38 +0000 (UTC) From: Ronnie Sahlberg To: linux-cifs Cc: Steve French Subject: [PATCH 12/15] cifs: make smb_send_rqst() take an array of requests Date: Fri, 1 Jun 2018 10:53:12 +1000 Message-Id: <20180601005315.6159-13-lsahlber@redhat.com> In-Reply-To: <20180601005315.6159-1-lsahlber@redhat.com> References: <20180601005315.6159-1-lsahlber@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 01 Jun 2018 00:53:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 01 Jun 2018 00:53:39 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lsahlber@redhat.com' RCPT:'' Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Update free_transform_rq to take an array of requests. Only the first request has a transform header which needs to be freed. Signed-off-by: Ronnie Sahlberg --- fs/cifs/cifsglob.h | 6 +++--- fs/cifs/smb2ops.c | 37 +++++++++++++++++++++---------------- fs/cifs/transport.c | 22 ++++++++++++++-------- 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index c65e9ce922f6..0583f53e584b 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -449,10 +449,10 @@ struct smb_version_operations { long (*fallocate)(struct file *, struct cifs_tcon *, int, loff_t, loff_t); /* init transform request - used for encryption for now */ - int (*init_transform_rq)(struct TCP_Server_Info *, struct smb_rqst *, - struct smb_rqst *); + int (*init_transform_rq)(struct TCP_Server_Info *, int num_rqst, + struct smb_rqst *, struct smb_rqst *); /* free transform request */ - void (*free_transform_rq)(struct smb_rqst *); + void (*free_transform_rq)(int num_rqst, struct smb_rqst *); int (*is_transform_hdr)(void *buf); int (*receive_transform)(struct TCP_Server_Info *, struct mid_q_entry **); diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index b3019b36747c..4e22a4a1a2d3 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -2314,9 +2314,10 @@ crypt_message(struct TCP_Server_Info *server, struct smb_rqst *rqst, int enc) return rc; } +/* Encrypt all the requests but only add a transform header to the first */ static int -smb3_init_transform_rq(struct TCP_Server_Info *server, struct smb_rqst *new_rq, - struct smb_rqst *old_rq) +smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst, + struct smb_rqst *new_rq, struct smb_rqst *old_rq) { struct kvec *iov; struct page **pages; @@ -2326,9 +2327,13 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, struct smb_rqst *new_rq, int i; int rc = -ENOMEM; + tr_hdr = kmalloc(sizeof(struct smb2_transform_hdr), GFP_KERNEL); + if (!tr_hdr) + return rc; + pages = kmalloc_array(npages, sizeof(struct page *), GFP_KERNEL); if (!pages) - return rc; + goto err_free_tr_hdr; new_rq->rq_pages = pages; new_rq->rq_npages = old_rq->rq_npages; @@ -2356,10 +2361,6 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, struct smb_rqst *new_rq, new_rq->rq_iov = iov; new_rq->rq_nvec = old_rq->rq_nvec + 1; - tr_hdr = kmalloc(sizeof(struct smb2_transform_hdr), GFP_KERNEL); - if (!tr_hdr) - goto err_free_iov; - /* fill the 2nd iov with a transform header */ fill_transform_hdr(tr_hdr, orig_len, old_rq); new_rq->rq_iov[0].iov_base = tr_hdr; @@ -2379,32 +2380,36 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, struct smb_rqst *new_rq, rc = crypt_message(server, new_rq, 1); cifs_dbg(FYI, "encrypt message returned %d", rc); if (rc) - goto err_free_tr_hdr; + goto err_free_iov; return rc; -err_free_tr_hdr: - kfree(tr_hdr); err_free_iov: kfree(iov); err_free_pages: for (i = i - 1; i >= 0; i--) put_page(pages[i]); kfree(pages); +err_free_tr_hdr: + kfree(tr_hdr); return rc; } +/* Only the first request has a transform header */ static void -smb3_free_transform_rq(struct smb_rqst *rqst) +smb3_free_transform_rq(int num_rqst, struct smb_rqst *rqst) { - int i = rqst->rq_npages - 1; + int i, j; - for (; i >= 0; i--) - put_page(rqst->rq_pages[i]); - kfree(rqst->rq_pages); /* free transform header */ kfree(rqst->rq_iov[0].iov_base); - kfree(rqst->rq_iov); + + for (i = 0; i < num_rqst; i++) { + for (j = rqst[i].rq_npages - 1; j >= 0; j--) + put_page(rqst[i].rq_pages[j]); + kfree(rqst[i].rq_pages); + kfree(rqst[i].rq_iov); + } } static int diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index 9136e3d35204..01f34eab64cc 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c @@ -333,14 +333,20 @@ __smb_send_rqst(struct TCP_Server_Info *server, int num_rqst, return rc; } +#define MAX_COMPOUND 5 + static int -smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst, int flags) +smb_send_rqst(struct TCP_Server_Info *server, int num_rqst, + struct smb_rqst *rqst, int flags) { - struct smb_rqst cur_rqst; + struct smb_rqst cur_rqst[MAX_COMPOUND]; int rc; + if (num_rqst > MAX_COMPOUND) + return -ENOMEM; + if (!(flags & CIFS_TRANSFORM_REQ)) - return __smb_send_rqst(server, 1, rqst); + return __smb_send_rqst(server, num_rqst, rqst); if (!server->ops->init_transform_rq || !server->ops->free_transform_rq) { @@ -348,12 +354,12 @@ smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst, int flags) return -EIO; } - rc = server->ops->init_transform_rq(server, &cur_rqst, rqst); + rc = server->ops->init_transform_rq(server, num_rqst, cur_rqst, rqst); if (rc) return rc; - rc = __smb_send_rqst(server, 1, &cur_rqst); - server->ops->free_transform_rq(&cur_rqst); + rc = __smb_send_rqst(server, num_rqst, cur_rqst); + server->ops->free_transform_rq(num_rqst, cur_rqst); return rc; } @@ -567,7 +573,7 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst, */ cifs_save_when_sent(mid); cifs_in_send_inc(server); - rc = smb_send_rqst(server, rqst, flags); + rc = smb_send_rqst(server, 1, rqst, flags); cifs_in_send_dec(server); if (rc < 0) { @@ -757,7 +763,7 @@ cifs_send_recv(const unsigned int xid, struct cifs_ses *ses, midQ->mid_state = MID_REQUEST_SUBMITTED; cifs_in_send_inc(ses->server); - rc = smb_send_rqst(ses->server, rqst, flags); + rc = smb_send_rqst(ses->server, 1, rqst, flags); cifs_in_send_dec(ses->server); cifs_save_when_sent(midQ);