From patchwork Tue Feb 13 04:42:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ronnie Sahlberg X-Patchwork-Id: 10215175 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 152D8601C2 for ; Tue, 13 Feb 2018 04:43:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 08BBD28CC8 for ; Tue, 13 Feb 2018 04:43:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F167128CD9; Tue, 13 Feb 2018 04:43:16 +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=-6.9 required=2.0 tests=BAYES_00,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 74CE228CC8 for ; Tue, 13 Feb 2018 04:43:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933417AbeBMEnQ (ORCPT ); Mon, 12 Feb 2018 23:43:16 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42326 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933378AbeBMEnP (ORCPT ); Mon, 12 Feb 2018 23:43:15 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 38E1AE4486; Tue, 13 Feb 2018 04:43:15 +0000 (UTC) Received: from test1190.test.redhat.com (vpn2-54-34.bne.redhat.com [10.64.54.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 89A491006EA1; Tue, 13 Feb 2018 04:43:12 +0000 (UTC) From: Ronnie Sahlberg To: linux-cifs Cc: Steve French Subject: [PATCH 06/14] cifs: make smb_send_rqst() take an array of requests Date: Tue, 13 Feb 2018 15:42:26 +1100 Message-Id: <20180213044234.18364-7-lsahlber@redhat.com> In-Reply-To: <20180213044234.18364-1-lsahlber@redhat.com> References: <20180213044234.18364-1-lsahlber@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 13 Feb 2018 04:43:15 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 13 Feb 2018 04:43:15 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 51d0d29dceed..a5ffcaf4b144 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -440,10 +440,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 be1cb6aaa19c..23ff4cf3ac88 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -2222,9 +2222,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; @@ -2234,9 +2235,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; @@ -2264,10 +2269,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; @@ -2287,32 +2288,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 b2af2341f6b8..6f3733380e41 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c @@ -327,14 +327,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) { @@ -342,12 +348,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; } @@ -561,7 +567,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) { @@ -751,7 +757,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);