Whamcloud - gitweb
LU-11403 llite: ll_fault fixes 47/34247/7
authorPatrick Farrell <pfarrell@whamcloud.com>
Tue, 12 Mar 2019 18:32:21 +0000 (14:32 -0400)
committerOleg Drokin <green@whamcloud.com>
Sat, 13 Apr 2019 04:49:57 +0000 (04:49 +0000)
Various error conditions in the fault path can cause us to
not return a page in vm_fault.  Check if it's present
before accessing it.

Additionally, it's not valid to return VM_FAULT_NOPAGE for
page faults.  The correct return when accessing a page that
does not exist is VM_FAULT_SIGBUS.  Correcting this avoids
looping infinitely in the testcase.

Signed-off-by: Patrick Farrell <pfarrell@whamcloud.com>
Change-Id: I53fc16d91462ac5d4555855dfa067d7fd6716c90
Reviewed-on: https://review.whamcloud.com/34247
Tested-by: Jenkins
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Alex Zhuravlev <bzzz@whamcloud.com>
Reviewed-by: Alexander Zarochentsev <c17826@cray.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/llite/llite_mmap.c
lustre/tests/Makefile.am
lustre/tests/mmap_mknod_test.c [new file with mode: 0644]
lustre/tests/sanity.sh

index fe8710a..989a53b 100644 (file)
@@ -240,9 +240,6 @@ static inline int to_fault_error(int result)
        case 0:
                result = VM_FAULT_LOCKED;
                break;
-       case -EFAULT:
-               result = VM_FAULT_NOPAGE;
-               break;
        case -ENOMEM:
                result = VM_FAULT_OOM;
                break;
@@ -368,7 +365,8 @@ static int ll_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
                return VM_FAULT_SIGBUS;
 restart:
        result = ll_fault0(vma, vmf);
-       if (!(result & (VM_FAULT_RETRY | VM_FAULT_ERROR | VM_FAULT_LOCKED))) {
+       if (vmf->page &&
+           !(result & (VM_FAULT_RETRY | VM_FAULT_ERROR | VM_FAULT_LOCKED))) {
                 struct page *vmpage = vmf->page;
 
                 /* check if this page has been truncated */
index c77958c..1b36587 100644 (file)
@@ -74,7 +74,7 @@ THETESTS += write_time_limit rwv lgetxattr_size_check checkfiemap
 THETESTS += listxattr_size_check check_fhandle_syscalls badarea_io
 THETESTS += llapi_layout_test orphan_linkea_check llapi_hsm_test
 THETESTS += group_lock_test llapi_fid_test sendfile_grouplock mmap_cat
-THETESTS += swap_lock_test lockahead_test mirror_io
+THETESTS += swap_lock_test lockahead_test mirror_io mmap_mknod_test
 
 if TESTS
 if MPITESTS
diff --git a/lustre/tests/mmap_mknod_test.c b/lustre/tests/mmap_mknod_test.c
new file mode 100644 (file)
index 0000000..6a70987
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * GPL HEADER START
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.gnu.org/licenses/gpl-2.0.html
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Use is subject to license terms.
+ *
+ * Copyright (c) 2015, Intel Corporation.
+ *
+ * Copyright (c) 2019, Whamcloud.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <assert.h>
+
+int save_errno;
+
+char usage[] =
+"Usage: %s <file>\n"
+"       mknod, truncate to larger size, open, and mmap file";
+
+int main(int argc, char **argv)
+{
+       void *mmappedData;
+       int rc;
+
+       if (argc != 2) {
+               fprintf(stderr, usage, argv[0]);
+               exit(1);
+       }
+
+       /* Create file without striping */
+       rc = mknod(argv[1], S_IFREG | 0666, 0);
+       if (rc) {
+               save_errno = errno;
+               perror("mknod");
+               exit(save_errno);
+       }
+
+       /* use truncate to extend file size */
+       rc = truncate(argv[1], 4096);
+       if (rc) {
+               save_errno = errno;
+               perror("mknod");
+               exit(save_errno);
+       }
+
+       rc = open(argv[1], O_RDONLY);
+       if (rc < 0) {
+               save_errno = errno;
+               perror("mknod");
+               exit(save_errno);
+       }
+
+       /* mmap of file without striping should work */
+       mmappedData = mmap(NULL, 4096, PROT_READ,
+                          MAP_SHARED, rc, 0);
+       if (mmappedData == MAP_FAILED) {
+               save_errno = errno;
+               perror("mknod");
+               exit(save_errno);
+       }
+
+       return 0;
+}
+
index bdc08f2..b6fec4f 100755 (executable)
@@ -6434,7 +6434,7 @@ test_60g() {
 }
 run_test 60g "transaction abort won't cause MDT hung"
 
-test_61() {
+test_61a() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run"
 
        f="$DIR/f61"
@@ -6443,7 +6443,12 @@ test_61() {
        $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
        sync
 }
-run_test 61 "mmap() writes don't make sync hang ================"
+run_test 61a "mmap() writes don't make sync hang ================"
+
+test_61b() {
+       mmap_mknod_test $tfile || error "mmap_mknod_test failed"
+}
+run_test 61b "mmap() of unstriped file is successful"
 
 # bug 2330 - insufficient obd_match error checking causes LBUG
 test_62() {