From patchwork Wed Aug 23 03:37:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: rdodgen@gmail.com X-Patchwork-Id: 9916505 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 49530602CB for ; Wed, 23 Aug 2017 03:38:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 12A962895F for ; Wed, 23 Aug 2017 03:38:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 022AB28958; Wed, 23 Aug 2017 03:38:18 +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=-1.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6852728958 for ; Wed, 23 Aug 2017 03:38:18 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9E5232095DC9B; Tue, 22 Aug 2017 20:35:18 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mail-pg0-x243.google.com (mail-pg0-x243.google.com [IPv6:2607:f8b0:400e:c05::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 25FF22095DC99 for ; Tue, 22 Aug 2017 20:35:17 -0700 (PDT) Received: by mail-pg0-x243.google.com with SMTP id y129so524426pgy.3 for ; Tue, 22 Aug 2017 20:37:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qXfgpUSwSBV+lMlU4IAUESJKcFXwe/IcGLUQun7uZgI=; b=fUxlyyq3zPm+fyA300hTIgYcobZJFCZwDoFn/QxhpRziZbrwfeWxNSfYkLRvmurbbU skaUnbkPeOdACpNLStn7LQ/teAsD57JuGyOeBL8t3nc4Hl43HvobTuqp9wP/vacexE37 +5W++hsvol4Vs/5XtQ78mGmq5jHoIPT9cSHkoCRNodur2XqFS+LB1my4HmCwj5fjeY4p /jkmk5pEDwVMfYUuOec1Em+8vz/WuORz6claybAFv8hhqNOn2gTdlLQypfOSn9MB6BL1 8byoX0HPbT3m+WCaMQL2e/j5sbvvLP+f/mVTOYCJGWMEZO3Wr5LvNtzeUx6NgP6gj1Px RC/w== 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=qXfgpUSwSBV+lMlU4IAUESJKcFXwe/IcGLUQun7uZgI=; b=P4N3A2lr5ikKr1dMNuWXUAMGf0jfPbZvbOfOBCd2aKxo+3PaTAsFvZhltb1A7KyAp8 hC+bpKvPYdEJT7XmkKXqUiVc/SHOOrn03WPt9j/0w4kczkBhCFfbGmRhvNT0e1d07zfF 1FLys2UsJ9UFHDE/gpuHlg9As7HFrYOxUz77/kWBBrIFLIIAZLIyoYS+Z2+i96SWwqYS K6VQ1eLYneImMO7T8AHdzEdo5rgEp1A/x7todnyXF+EengE8wfH4voxSUwrOlrGQhKJN 3sNcxp09aYQOefKF7jr9qp9E6bTp+Jp8a6xNe9iU5N9F0ucPjFwWP5LI2s6K5LF1LVHA fg3A== X-Gm-Message-State: AHYfb5jOcPUy168fcB7my5ov31LbrYSeZXuDvI+hRS3F6l80i+Xl9dcL Aq37p605aR1MNQ== X-Received: by 10.99.185.69 with SMTP id v5mr1298256pgo.304.1503459470057; Tue, 22 Aug 2017 20:37:50 -0700 (PDT) Received: from localhost ([2620:0:1009:11:843f:59ee:acb7:5c0]) by smtp.gmail.com with ESMTPSA id r16sm533205pgu.68.2017.08.22.20.37.49 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 22 Aug 2017 20:37:49 -0700 (PDT) From: rdodgen@gmail.com To: tytso@mit.edu, linux-ext4@vger.kernel.org, ross.zwisler@linux.intel.com Subject: [PATCH v2] Fix ext4 fault handling when mounted with -o dax,ro Date: Tue, 22 Aug 2017 20:37:04 -0700 Message-Id: X-Mailer: git-send-email 2.14.1.480.gb18f417b89-goog In-Reply-To: <20170822222434.146233-1-dodgen@google.com> References: <20170822222434.146233-1-dodgen@google.com> X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Randy Dodgen , linux-nvdimm@lists.01.org MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP From: Randy Dodgen If an ext4 filesystem is mounted with both the DAX and read-only options, executables on that filesystem will fail to start (claiming 'Segmentation fault') due to the fault handler returning VM_FAULT_SIGBUS. This is due to the DAX fault handler (see ext4_dax_huge_fault) attempting to write to the journal when FAULT_FLAG_WRITE is set. This is the wrong behavior for write faults which will lead to a COW page; in particular, this fails for readonly mounts. This changes replicates some check from dax_iomap_fault to more precisely reason about when a journal-write is needed. It might be the case that this could be better handled in ext4_iomap_begin / ext4_iomap_end (called via iomap_ops inside dax_iomap_fault). These is some overlap already (e.g. grabbing journal handles). Signed-off-by: Randy Dodgen --- I'm resending for some DMARC-proofing (thanks Ted for the explanation), a missing Signed-off-by, and some extra cc's. Oops! fs/ext4/file.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 0d7cf0cc9b87..d512fb85a3e3 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -279,7 +279,31 @@ static int ext4_dax_huge_fault(struct vm_fault *vmf, handle_t *handle = NULL; struct inode *inode = file_inode(vmf->vma->vm_file); struct super_block *sb = inode->i_sb; - bool write = vmf->flags & FAULT_FLAG_WRITE; + bool write; + + /* + * We have to distinguish real writes from writes which will result in a + * COW page + * - COW writes need to fall-back to installing PTEs. See + * dax_iomap_pmd_fault. + * - COW writes should *not* poke the journal (the file will not be + * changed). Doing so would cause unintended failures when mounted + * read-only. + */ + if (pe_size == PE_SIZE_PTE) { + /* See dax_iomap_pte_fault. */ + write = (vmf->flags & FAULT_FLAG_WRITE) && !vmf->cow_page; + } else if (pe_size == PE_SIZE_PMD) { + /* See dax_iomap_pmd_fault. */ + write = vmf->flags & FAULT_FLAG_WRITE; + if (write && !(vmf->vma->vm_flags & VM_SHARED)) { + split_huge_pmd(vmf->vma, vmf->pmd, vmf->address); + count_vm_event(THP_FAULT_FALLBACK); + return VM_FAULT_FALLBACK; + } + } else { + return VM_FAULT_FALLBACK; + } if (write) { sb_start_pagefault(sb);