{"id":812695,"url":"http://patchwork.ozlabs.org/api/patches/812695/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-ext4/patch/20170912050526.7627-3-ross.zwisler@linux.intel.com/","project":{"id":8,"url":"http://patchwork.ozlabs.org/api/projects/8/?format=json","name":"Linux ext4 filesystem development","link_name":"linux-ext4","list_id":"linux-ext4.vger.kernel.org","list_email":"linux-ext4@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170912050526.7627-3-ross.zwisler@linux.intel.com>","list_archive_url":null,"date":"2017-09-12T05:05:23","name":"[v2,2/5] ext4: prevent data corruption with journaling + DAX","commit_ref":null,"pull_url":null,"state":"accepted","archived":true,"hash":"a1302733a036d1c9c312fa44f42164943501b04b","submitter":{"id":46514,"url":"http://patchwork.ozlabs.org/api/people/46514/?format=json","name":"Ross Zwisler","email":"ross.zwisler@linux.intel.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-ext4/patch/20170912050526.7627-3-ross.zwisler@linux.intel.com/mbox/","series":[{"id":2615,"url":"http://patchwork.ozlabs.org/api/series/2615/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-ext4/list/?series=2615","date":"2017-09-12T05:05:23","name":"ext4: DAX data corruption fixes","version":2,"mbox":"http://patchwork.ozlabs.org/series/2615/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/812695/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/812695/checks/","tags":{},"related":[],"headers":{"Return-Path":"<linux-ext4-owner@vger.kernel.org>","X-Original-To":"patchwork-incoming@ozlabs.org","Delivered-To":"patchwork-incoming@ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=linux-ext4-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xrt6R1B5Cz9s8J\n\tfor <patchwork-incoming@ozlabs.org>;\n\tTue, 12 Sep 2017 15:05:51 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1751399AbdILFFi (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tTue, 12 Sep 2017 01:05:38 -0400","from mga09.intel.com ([134.134.136.24]:5341 \"EHLO mga09.intel.com\"\n\trhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP\n\tid S1751292AbdILFFe (ORCPT <rfc822;linux-ext4@vger.kernel.org>);\n\tTue, 12 Sep 2017 01:05:34 -0400","from fmsmga003.fm.intel.com ([10.253.24.29])\n\tby orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t11 Sep 2017 22:05:34 -0700","from theros.lm.intel.com ([10.232.112.77])\n\tby FMSMGA003.fm.intel.com with ESMTP; 11 Sep 2017 22:05:30 -0700"],"X-ExtLoop1":"1","X-IronPort-AV":"E=Sophos;i=\"5.42,381,1500966000\"; d=\"scan'208\";a=\"899352296\"","From":"Ross Zwisler <ross.zwisler@linux.intel.com>","To":"\"Theodore Ts'o\" <tytso@mit.edu>, Jan Kara <jack@suse.cz>,\n\tlinux-kernel@vger.kernel.org","Cc":"Ross Zwisler <ross.zwisler@linux.intel.com>,\n\tAndreas Dilger <adilger.kernel@dilger.ca>,\n\tChristoph Hellwig <hch@lst.de>, Dan Williams <dan.j.williams@intel.com>,\n\tDave Chinner <david@fromorbit.com>, linux-ext4@vger.kernel.org,\n\tlinux-nvdimm@lists.01.org","Subject":"[PATCH v2 2/5] ext4: prevent data corruption with journaling + DAX","Date":"Mon, 11 Sep 2017 23:05:23 -0600","Message-Id":"<20170912050526.7627-3-ross.zwisler@linux.intel.com>","X-Mailer":"git-send-email 2.9.5","In-Reply-To":"<20170912050526.7627-1-ross.zwisler@linux.intel.com>","References":"<20170912050526.7627-1-ross.zwisler@linux.intel.com>","Sender":"linux-ext4-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<linux-ext4.vger.kernel.org>","X-Mailing-List":"linux-ext4@vger.kernel.org"},"content":"The current code has the potential for data corruption when changing an\ninode's journaling mode, as that can result in a subsequent unsafe change\nin S_DAX.\n\nI've captured an instance of this data corruption in the following fstest:\n\nhttps://patchwork.kernel.org/patch/9948377/\n\nPrevent this data corruption from happening by disallowing changes to the\njournaling mode if the '-o dax' mount option was used.  This means that for\na given filesystem we could have a mix of inodes using either DAX or\ndata journaling, but whatever state the inodes are in will be held for the\nduration of the mount.\n\nSigned-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>\nSuggested-by: Jan Kara <jack@suse.cz>\n---\n fs/ext4/inode.c |  5 -----\n fs/ext4/ioctl.c | 16 +++++++++++++---\n 2 files changed, 13 insertions(+), 8 deletions(-)","diff":"diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c\nindex e963508..3207333 100644\n--- a/fs/ext4/inode.c\n+++ b/fs/ext4/inode.c\n@@ -5971,11 +5971,6 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val)\n \t\text4_clear_inode_flag(inode, EXT4_INODE_JOURNAL_DATA);\n \t}\n \text4_set_aops(inode);\n-\t/*\n-\t * Update inode->i_flags after EXT4_INODE_JOURNAL_DATA was updated.\n-\t * E.g. S_DAX may get cleared / set.\n-\t */\n-\text4_set_inode_flags(inode);\n \n \tjbd2_journal_unlock_updates(journal);\n \tpercpu_up_write(&sbi->s_journal_flag_rwsem);\ndiff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c\nindex afb66d4..b0b754b 100644\n--- a/fs/ext4/ioctl.c\n+++ b/fs/ext4/ioctl.c\n@@ -290,10 +290,20 @@ static int ext4_ioctl_setflags(struct inode *inode,\n \tif (err)\n \t\tgoto flags_out;\n \n-\tif ((jflag ^ oldflags) & (EXT4_JOURNAL_DATA_FL))\n+\tif ((jflag ^ oldflags) & (EXT4_JOURNAL_DATA_FL)) {\n+\t\t/*\n+\t\t * Changes to the journaling mode can cause unsafe changes to\n+\t\t * S_DAX if we are using the DAX mount option.\n+\t\t */\n+\t\tif (test_opt(inode->i_sb, DAX)) {\n+\t\t\terr = -EBUSY;\n+\t\t\tgoto flags_out;\n+\t\t}\n+\n \t\terr = ext4_change_inode_journal_flag(inode, jflag);\n-\tif (err)\n-\t\tgoto flags_out;\n+\t\tif (err)\n+\t\t\tgoto flags_out;\n+\t}\n \tif (migrate) {\n \t\tif (flags & EXT4_EXTENTS_FL)\n \t\t\terr = ext4_ext_migrate(inode);\n","prefixes":["v2","2/5"]}