From patchwork Sun Dec 24 00:56:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10131767 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 5397E60318 for ; Sun, 24 Dec 2017 01:05:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 442DD28B11 for ; Sun, 24 Dec 2017 01:05:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3925C28F78; Sun, 24 Dec 2017 01:05:17 +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,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 BC97E28B11 for ; Sun, 24 Dec 2017 01:05:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756541AbdLXBFO (ORCPT ); Sat, 23 Dec 2017 20:05:14 -0500 Received: from mga11.intel.com ([192.55.52.93]:19648 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756838AbdLXBFO (ORCPT ); Sat, 23 Dec 2017 20:05:14 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Dec 2017 17:05:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,448,1508828400"; d="scan'208";a="14768106" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga003.jf.intel.com with ESMTP; 23 Dec 2017 17:05:13 -0800 Subject: [PATCH v4 11/18] fs, dax: introduce DEFINE_FSDAX_AOPS From: Dan Williams To: akpm@linux-foundation.org Cc: jack@suse.cz, Matthew Wilcox , linux-nvdimm@lists.01.org, linux-xfs@vger.kernel.org, Jeff Moyer , linux-fsdevel@vger.kernel.org, ross.zwisler@linux.intel.com, hch@lst.de Date: Sat, 23 Dec 2017 16:56:59 -0800 Message-ID: <151407701943.38751.8997225433943672290.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <151407695916.38751.2866053440557472361.stgit@dwillia2-desk3.amr.corp.intel.com> References: <151407695916.38751.2866053440557472361.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 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 In preparation for the dax implementation to start associating dax pages to inodes via page->mapping, we need to provide a 'struct address_space_operations' instance for dax. Otherwise, direct-I/O triggers incorrect page cache assumptions and warnings like the following: WARNING: CPU: 27 PID: 1783 at fs/xfs/xfs_aops.c:1468 xfs_vm_set_page_dirty+0xf3/0x1b0 [xfs] [..] CPU: 27 PID: 1783 Comm: dma-collision Tainted: G O 4.15.0-rc2+ #984 [..] Call Trace: set_page_dirty_lock+0x40/0x60 bio_set_pages_dirty+0x37/0x50 iomap_dio_actor+0x2b7/0x3b0 ? iomap_dio_zero+0x110/0x110 iomap_apply+0xa4/0x110 iomap_dio_rw+0x29e/0x3b0 ? iomap_dio_zero+0x110/0x110 ? xfs_file_dio_aio_read+0x7c/0x1a0 [xfs] xfs_file_dio_aio_read+0x7c/0x1a0 [xfs] xfs_file_read_iter+0xa0/0xc0 [xfs] __vfs_read+0xf9/0x170 vfs_read+0xa6/0x150 SyS_pread64+0x93/0xb0 entry_SYSCALL_64_fastpath+0x1f/0x96 ...where the default set_page_dirty() handler assumes that dirty state is being tracked in 'struct page' flags. A DEFINE_FSDAX_AOPS macro helper is provided instead of a global 'struct address_space_operations fs_dax_aops' instance, because ->writepages needs to be an fs-specific implementation. Cc: Jeff Moyer Cc: Christoph Hellwig Cc: Matthew Wilcox Cc: Ross Zwisler Suggested-by: Jan Kara Signed-off-by: Dan Williams --- fs/dax.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/dax.h | 32 ++++++++++++++++++++++++ 2 files changed, 101 insertions(+) diff --git a/fs/dax.c b/fs/dax.c index 54071cd27e8c..fadc1b13838b 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -45,6 +45,75 @@ /* The 'colour' (ie low bits) within a PMD of a page offset. */ #define PG_PMD_COLOUR ((PMD_SIZE >> PAGE_SHIFT) - 1) +int dax_set_page_dirty(struct page *page) +{ + /* + * Unlike __set_page_dirty_no_writeback, dax does all dirty + * tracking in the radix in response to mkwrite faults. + */ + return 0; +} +EXPORT_SYMBOL(dax_set_page_dirty); + +ssize_t dax_direct_IO(struct kiocb *kiocb, struct iov_iter *iter) +{ + /* + * The expectation is that filesystems that implement DAX + * support also arrange for ->read_iter and ->write_iter to + * bypass ->direct_IO. + */ + WARN_ONCE(1, "dax: incomplete fs implementation\n"); + return -EINVAL; +} +EXPORT_SYMBOL(dax_direct_IO); + +int dax_writepage(struct page *page, struct writeback_control *wbc) +{ + WARN_ONCE(1, "dax: incomplete fs implementation\n"); + return -EINVAL; +} +EXPORT_SYMBOL(dax_writepage); + +int dax_readpage(struct file *filp, struct page *page) +{ + WARN_ONCE(1, "dax: incomplete fs implementation\n"); + return -EINVAL; +} +EXPORT_SYMBOL(dax_readpage); + +int dax_readpages(struct file *filp, struct address_space *mapping, + struct list_head *pages, unsigned nr_pages) +{ + WARN_ONCE(1, "dax: incomplete fs implementation\n"); + return -EINVAL; +} +EXPORT_SYMBOL(dax_readpages); + +int dax_write_begin(struct file *filp, struct address_space *mapping, + loff_t pos, unsigned len, unsigned flags, + struct page **pagep, void **fsdata) +{ + WARN_ONCE(1, "dax: incomplete fs implementation\n"); + return -EINVAL; +} +EXPORT_SYMBOL(dax_write_begin); + +int dax_write_end(struct file *filp, struct address_space *mapping, + loff_t pos, unsigned len, unsigned copied, + struct page *page, void *fsdata) +{ + WARN_ONCE(1, "dax: incomplete fs implementation\n"); + return -EINVAL; +} +EXPORT_SYMBOL(dax_write_end); + +void dax_invalidatepage(struct page *page, unsigned int offset, + unsigned int length) +{ + /* nothing to do for dax */ +} +EXPORT_SYMBOL(dax_invalidatepage); + static wait_queue_head_t wait_table[DAX_WAIT_TABLE_ENTRIES]; static int __init init_dax_wait_table(void) diff --git a/include/linux/dax.h b/include/linux/dax.h index 1c6ed44fe9fc..3502abcbea31 100644 --- a/include/linux/dax.h +++ b/include/linux/dax.h @@ -53,6 +53,34 @@ static inline struct dax_device *fs_dax_get_by_host(const char *host) struct dax_device *fs_dax_claim_bdev(struct block_device *bdev, void *owner); void fs_dax_release(struct dax_device *dax_dev, void *owner); +int dax_set_page_dirty(struct page *page); +ssize_t dax_direct_IO(struct kiocb *kiocb, struct iov_iter *iter); +int dax_writepage(struct page *page, struct writeback_control *wbc); +int dax_readpage(struct file *filp, struct page *page); +int dax_readpages(struct file *filp, struct address_space *mapping, + struct list_head *pages, unsigned nr_pages); +int dax_write_begin(struct file *filp, struct address_space *mapping, + loff_t pos, unsigned len, unsigned flags, + struct page **pagep, void **fsdata); +int dax_write_end(struct file *filp, struct address_space *mapping, + loff_t pos, unsigned len, unsigned copied, + struct page *page, void *fsdata); +void dax_invalidatepage(struct page *page, unsigned int offset, + unsigned int length); + +#define DEFINE_FSDAX_AOPS(name, writepages_fn) \ +const struct address_space_operations name = { \ + .set_page_dirty = dax_set_page_dirty, \ + .direct_IO = dax_direct_IO, \ + .writepage = dax_writepage, \ + .readpage = dax_readpage, \ + .writepages = writepages_fn, \ + .readpages = dax_readpages, \ + .write_begin = dax_write_begin, \ + .write_end = dax_write_end, \ + .invalidatepage = dax_invalidatepage, \ +} + #else static inline int bdev_dax_supported(struct super_block *sb, int blocksize) { @@ -73,6 +101,10 @@ static inline struct dax_device *fs_dax_claim_bdev(struct block_device *bdev, static inline void fs_dax_release(struct dax_device *dax_dev, void *owner) { } + +#define DEFINE_FSDAX_AOPS(name, writepages_fn) \ +const struct address_space_operations name = { 0 } + #endif int dax_read_lock(void);