Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2068542imu; Sun, 16 Dec 2018 16:08:40 -0800 (PST) X-Google-Smtp-Source: AFSGD/WH0VZJdvGuqD8Jcye8fBEITBVMlQGXm+qmb4UZ1jIEXw+Bo7oBnobSLor5F8IqyLqWCT4U X-Received: by 2002:a17:902:b112:: with SMTP id q18mr10800131plr.255.1545005320397; Sun, 16 Dec 2018 16:08:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545005320; cv=none; d=google.com; s=arc-20160816; b=BGhB/fue8xr1u+AvXliM6l3kWbEEDtjdSuHYKEyFIldau6320Sd1erF7OPbaB7bX4/ MTzpl5GNb6DVOlZLodRuwjcdh/KRrr5K5uz/mh1AZglw8Bg+G+vX6T/jzajwHjQmQniT mlurqPTvlFNbew+8nQZP/6mGW4rCzKWBtt3z8R9MiwnmGrfwILnFOvdK8qDz3kHUfarv 61VkR2ZkKiwHoP2+4ap7q6C5GgROehcV3Ob/K7YsAjKKgEEClaa0+4kM3GkBiF1RiB9S 8SJoKmgTIOyhhKx+uBZZCS7OgSBkT6fXYnV3OTY4hdJpOF02T6XiWWU5ePk/4yA9fNgZ KhfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:reply-to :mime-version:message-id:date:subject:cc:to:from; bh=nsWIaaBcGvQNQsx3uSPLzX1j6dWir2nWk4kpSUFS/6k=; b=wsIFKoMETOlKzNF0UwvWr6tFYBrj5pZUHPid9e96ORns6s1BZ38uq40eYfpJdqRyNC M1mTiFW0yHsagJ20aRPwzJ8g4K2IGRjETE3IPTBkBHpi3YRBGVza6b0GDVVAOUuHxnb1 6tKUCOXOWByzCrCoYPfz44SRRlQc4PDBXxFAEQoAwoKQwZu4wji3mJFefB8aaAzS6OSE h5l+sb5es8OwPVXopBdjIb5W3iFRja0PFw4P1hV1J+lEZZnl6yb/FlAWi1ISxPbOtB7n figWSvUjiDDFmRNTvNTk2GVmLEG/cdGBtMi0qzD2cwB3vJRu+iNNTfdKZu97nTR4NIuR Pr4A== 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 j39si9660082plb.272.2018.12.16.16.08.22; Sun, 16 Dec 2018 16:08:40 -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 S1731104AbeLPXSQ (ORCPT + 99 others); Sun, 16 Dec 2018 18:18:16 -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 Content-Transfer-Encoding: 8bit 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 " -- 2.7.4