From patchwork Tue Nov 28 20:21:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Brandenburg X-Patchwork-Id: 10081033 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 D253C602DC for ; Tue, 28 Nov 2017 20:24:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C97B829672 for ; Tue, 28 Nov 2017 20:24:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BEACB29675; Tue, 28 Nov 2017 20:24:02 +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,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=unavailable 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 4774129672 for ; Tue, 28 Nov 2017 20:24:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932167AbdK1UXp (ORCPT ); Tue, 28 Nov 2017 15:23:45 -0500 Received: from mail-yw0-f195.google.com ([209.85.161.195]:44339 "EHLO mail-yw0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932172AbdK1UWn (ORCPT ); Tue, 28 Nov 2017 15:22:43 -0500 Received: by mail-yw0-f195.google.com with SMTP id m129so468034ywb.11 for ; Tue, 28 Nov 2017 12:22:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=omnibond-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dteo+t2RW5l1zCSBxpEJxscgZpxrDTlY5wx081flA/o=; b=XHpH3Mo7aXRCMxVlYnKQOiP0XYlVXllQjRi9vfwTD4dfyqtY95LSe4MIdxNgBirWLP 4WqLFFE+d3ja3Aox2miyLRtvdbzkE/FF+Lql1nvZTxg8evwYJIHM1trskN/aDMb/hQ3L nRU6blcNRGevUxi/ENjDQgkS64VHj0F2gbnn3gKFtaX3ioIBElIIFcwUlqNIFI67Cz1y lKvpreEJCeJvKuJiv2UBtJKRB/I06MyCtqjc74drfqjlMtUl5Sh7M3oK4PD+JLrKkkyQ jBpE85crAnE9ELqNSwdiZH5Sng/ZtOy6YLdzISSDPwSWk0SrhztT7O097o4/D4s2PjLI SyTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dteo+t2RW5l1zCSBxpEJxscgZpxrDTlY5wx081flA/o=; b=JGd3jKR2OUyupoYacvaZ7bKpVd7gf3yuk77ZrOz2BZSnn5eKCRRqH/CFuelTgYXmUU J5IX9mE82B3jS0rX9q8w5pZkBGr5HQRNcSuaFSYOiQBJgfpYpiv3erBBME7BoDNM8Hrt UHazZzIRwbAf5QrPzHt97BYrArqsccDtmpzZzni4ONe4cYIrh5nTD97CyBb30DY1xXCo GdPKDqDum1PmmRQTZxYIrOSeajGO2FemrHQ8xi+jsn71hIYQ7m+k0NHijHUtjzmkI13r lEXQPWCfs7idGiVXO7mnDVvhSPZgunAqvz3cLuDAHF3VSKnTunxHFuTEbuScCAdKLkqr W5gQ== X-Gm-Message-State: AJaThX5lE2eW79eQcmBr32NRXn9oafriQidhaQ9AXTwQkcFloQRGrdvG 6hFRNVUHsayIfiVF9U17MhWuXg== X-Google-Smtp-Source: AGs4zMauqyPryD1CqYwAKhbuSC62C4tMxgr/yjveE5f7FhbJgJ016tdOY2XktIlK6rvdIXwljXSvIQ== X-Received: by 10.129.72.136 with SMTP id v130mr246809ywa.487.1511900562531; Tue, 28 Nov 2017 12:22:42 -0800 (PST) Received: from omnifs1.omnibond.com ([24.31.12.185]) by smtp.gmail.com with ESMTPSA id u194sm2190ywe.71.2017.11.28.12.22.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Nov 2017 12:22:41 -0800 (PST) From: Martin Brandenburg To: hubcap@omnibond.com, devel@lists.orangefs.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Martin Brandenburg Subject: [PATCH 2/5] orangefs: implement vm_ops->fault Date: Tue, 28 Nov 2017 15:21:58 -0500 Message-Id: <20171128202201.8717-3-martin@omnibond.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171128202201.8717-1-martin@omnibond.com> References: <20171128202201.8717-1-martin@omnibond.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Must retrieve size before running filemap_fault so the kernel has an up-to-date size. This should have been caught by xfstests generic/246, but it was masked by orangefs_new_inode, which set i_size to PAGE_SIZE. When nothing caused a getattr prior to a pagefault, i_size was still PAGE_SIZE. Since xfstests only read 10 bytes, it did not catch this bug. When orangefs_new_inode was modified to perform a getattr instead, i_size was set to zero, as it was a newly created file. Then orangefs_file_write_iter did NOT set i_size, instead prefering to invalidate the attribute cache and letting the next caller retrieve i_size. But the fault handler did not know it was supposed to retrieve i_size. So during xfstests, i_size was still zero, and filemap_fault returned VM_FAULT_SIGBUS. Fixes xfstests generic/080, generic/141, generic/215, generic/247, generic/248, generic/437, and generic/452. Signed-off-by: Martin Brandenburg --- fs/orangefs/file.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/fs/orangefs/file.c b/fs/orangefs/file.c index 44879b1ff33e..c88846dc432a 100644 --- a/fs/orangefs/file.c +++ b/fs/orangefs/file.c @@ -531,6 +531,28 @@ static long orangefs_ioctl(struct file *file, unsigned int cmd, unsigned long ar return ret; } +static int orangefs_fault(struct vm_fault *vmf) +{ + struct file *file = vmf->vma->vm_file; + int rc; + rc = orangefs_inode_getattr(file->f_mapping->host, 0, 1, + STATX_SIZE); + if (rc == -ESTALE) + rc = -EIO; + if (rc) { + gossip_err("%s: orangefs_inode_getattr failed, " + "rc:%d:.\n", __func__, rc); + return rc; + } + return filemap_fault(vmf); +} + +const struct vm_operations_struct orangefs_file_vm_ops = { + .fault = orangefs_fault, + .map_pages = filemap_map_pages, + .page_mkwrite = filemap_page_mkwrite, +}; + /* * Memory map a region of a file. */ @@ -546,8 +568,9 @@ static int orangefs_file_mmap(struct file *file, struct vm_area_struct *vma) vma->vm_flags |= VM_SEQ_READ; vma->vm_flags &= ~VM_RAND_READ; - /* Use readonly mmap since we cannot support writable maps. */ - return generic_file_readonly_mmap(file, vma); + file_accessed(file); + vma->vm_ops = &orangefs_file_vm_ops; + return 0; } #define mapping_nrpages(idata) ((idata)->nrpages)