From: Patrick Farrell Date: Tue, 12 Mar 2019 18:32:21 +0000 (-0400) Subject: LU-11403 llite: ll_fault fixes X-Git-Tag: 2.12.53~51 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=a8f4d1e5fd79e77f1347e983ec52f2ddc3e75ab9 LU-11403 llite: ll_fault fixes 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 Change-Id: I53fc16d91462ac5d4555855dfa067d7fd6716c90 Reviewed-on: https://review.whamcloud.com/34247 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Alex Zhuravlev Reviewed-by: Alexander Zarochentsev Reviewed-by: Oleg Drokin --- diff --git a/lustre/llite/llite_mmap.c b/lustre/llite/llite_mmap.c index fe8710a..989a53b 100644 --- a/lustre/llite/llite_mmap.c +++ b/lustre/llite/llite_mmap.c @@ -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 */ diff --git a/lustre/tests/Makefile.am b/lustre/tests/Makefile.am index c77958c..1b36587 100644 --- a/lustre/tests/Makefile.am +++ b/lustre/tests/Makefile.am @@ -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 index 0000000..6a70987 --- /dev/null +++ b/lustre/tests/mmap_mknod_test.c @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include + +int save_errno; + +char usage[] = +"Usage: %s \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; +} + diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index bdc08f2..b6fec4f 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -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() {