From patchwork Sun Dec 16 23:17:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Long Li X-Patchwork-Id: 10732635 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 615E6924 for ; Sun, 16 Dec 2018 23:18:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37A6029A7C for ; Sun, 16 Dec 2018 23:18:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 11EC529AF7; Sun, 16 Dec 2018 23:18:17 +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 B426529A7C for ; Sun, 16 Dec 2018 23:18:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731079AbeLPXSP (ORCPT ); Sun, 16 Dec 2018 18:18:15 -0500 Received: from a2nlsmtp01-05.prod.iad2.secureserver.net ([198.71.225.49]:56128 "EHLO a2nlsmtp01-05.prod.iad2.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730911AbeLPXSP (ORCPT ); Sun, 16 Dec 2018 18:18:15 -0500 Received: from linuxonhyperv2.linuxonhyperv.com ([107.180.71.197]) by : HOSTING RELAY : with ESMTP id YfesghRTUse9VYfesgsUNi; Sun, 16 Dec 2018 16:17:14 -0700 x-originating-ip: 107.180.71.197 Received: from longli by linuxonhyperv2.linuxonhyperv.com with local (Exim 4.91) (envelope-from ) id 1gYfes-0004N1-BI; Sun, 16 Dec 2018 16:17:14 -0700 From: Long Li To: Steve French , linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org Cc: Long Li , stable@vger.kernel.org Subject: [PATCH] CIFS: use the correct length when pinning memory for direct I/O for write Date: Sun, 16 Dec 2018 23:17:04 +0000 Message-Id: <20181216231704.16761-1-longli@linuxonhyperv.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Reply-To: longli@microsoft.com X-CMAE-Envelope: MS4wfGn50yF0YsEmJGgTR0bJMjMMe42gCNFOtx6XwYFW+BOmbfQX/TjRVZLrWCIy/pJhbs/GHkGWp1V7zXNECmtXsNlmTrG/lruIgaMaD/auMaVhfqOwRw1r 6YL98WADIw3wtC9QKGhS2jpIwVDK1BBy6Qnljd/DVPmUQCcLOMFdpibu1umOyniVYPqKaHnNVBjsBwA5HEgXzAW/0QCJtDfyufiiwtNMDsUkcdjdFbBJ+Unf +Pyy6CEWcW9x1I6BRi1B34Gj/GwOFh9RGtErz4JbxihuK5Py+ryUJols/W1P4Ykdwb/kBuqLJ3tjppBFcBUVEcsrbEVVw7GepHRu2hkKPWY1xpINznT/wUbT kKTCZshls9cssJHO+2SixDpu3vrJ3zz785oF/8D5LRCffyvmkn6pGLrDs51RwfiiNmvvOvd7n7n8IvHgvrpOIZoJ6IqwrPbdHPN0MEigRH6yeBoxQws= 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 From: Long Li The current code attempts to pin memory using the largest possible wsize based on the currect SMB credits. This doesn't cause kernel oops but this is not optimal as we may pin more pages then actually needed. Fix this by only pinning what are needed for doing this write I/O. Signed-off-by: Long Li Cc: stable@vger.kernel.org Reviewed-by: Joey Pabalinas --- fs/cifs/file.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 3467351..c23bf9d 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -2617,11 +2617,13 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from, if (rc) break; + cur_len = min_t(const size_t, len, wsize); + if (ctx->direct_io) { ssize_t result; result = iov_iter_get_pages_alloc( - from, &pagevec, wsize, &start); + from, &pagevec, cur_len, &start); if (result < 0) { cifs_dbg(VFS, "direct_writev couldn't get user pages "