From patchwork Mon Jan 29 21:06:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Desnoyers X-Patchwork-Id: 13536399 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DA58C47DB3 for ; Mon, 29 Jan 2024 21:07:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 14F386B009D; Mon, 29 Jan 2024 16:06:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 076656B00A0; Mon, 29 Jan 2024 16:06:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE6636B009D; Mon, 29 Jan 2024 16:06:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 8DCA06B009D for ; Mon, 29 Jan 2024 16:06:54 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 683FB120695 for ; Mon, 29 Jan 2024 21:06:54 +0000 (UTC) X-FDA: 81733583148.27.662624E Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by imf05.hostedemail.com (Postfix) with ESMTP id C4E0F100021 for ; Mon, 29 Jan 2024 21:06:52 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=efficios.com header.s=smtpout1 header.b=Or9KKQbE; dmarc=pass (policy=none) header.from=efficios.com; spf=pass (imf05.hostedemail.com: domain of mathieu.desnoyers@efficios.com designates 167.114.26.122 as permitted sender) smtp.mailfrom=mathieu.desnoyers@efficios.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706562412; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ky+lCyzDge5OH74kS9vjXopzUiz2nH47LN5bR/8Pwh0=; b=Bqbfuk+05dqM9pyGkoo7CHEliE0Jzsdf1/mlkskeg0W3TFZEnOC5Wtj24kSamiWGaKeG+P hzCdhyKcEsUEdNqzT1kXsU8JNVZjhojS99BcwwQkzXuZ9yLUvr6fi2tMTGti1q+nB7ZSgr MSJ0i/ua7ei9slB6A3fLNt9bccRLaxQ= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=efficios.com header.s=smtpout1 header.b=Or9KKQbE; dmarc=pass (policy=none) header.from=efficios.com; spf=pass (imf05.hostedemail.com: domain of mathieu.desnoyers@efficios.com designates 167.114.26.122 as permitted sender) smtp.mailfrom=mathieu.desnoyers@efficios.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706562412; a=rsa-sha256; cv=none; b=B/xgV7nlqzl04H+imzQaGMoSM3CSwageU0RISSOEH36vov6isXALn3CLVs5fnjwNuV0DML 9ea4ko3HeZmGnIFrlPCpbUJwsjOkmlJwemlC8KEl37MsJyQNrfFDYRPVfSxEt+XS3HQ3/s MnNgfsIPs4spVaMTlF3H+VjhDkV3HvI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1706562411; bh=qE6d84dw/RHBezptIMoCUSoZjf7hEPQsPy+jBZ/P/F4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Or9KKQbE01DFHpcvYQEjceuM4WZSaWEOvWctam+nWYmhRaiKWaY7y4HtQ+LAL/ra6 WnhCkdYwWZj1fXClvt1jc4U9MGLixIqC+hCRIm0pnM+eeQFIiNsW9gPQLzahPKQZip vRvFUs1OQNbZHK4eqX9cfuOZsbhSkZk4y/WO9vHGSkKQ21R8iTopGgKUiPYn3cVKKy NY2XTs9e84eCiZRaD6C5ObMVDsbSWAz48qTfj2g5hx+kNTA/IE6wmKHn6763C2ptlI DRA6nvmFJIFA0Neet56IfoOGTJ7CVKcNye2U8woci47wLQIqX7JopQB0ezWkW1cJQy Ap1Rsna8wszfQ== Received: from thinkos.internal.efficios.com (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4TP17v02t7zVfq; Mon, 29 Jan 2024 16:06:50 -0500 (EST) From: Mathieu Desnoyers To: Dan Williams , Vishal Verma , Dave Jiang Cc: linux-kernel@vger.kernel.org, Mathieu Desnoyers , Miklos Szeredi , linux-fsdevel@vger.kernel.org, Andrew Morton , Linus Torvalds , linux-mm@kvack.org, linux-arch@vger.kernel.org, Matthew Wilcox , nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Subject: [RFC PATCH 6/7] fuse: Introduce fuse_dax_is_supported() Date: Mon, 29 Jan 2024 16:06:30 -0500 Message-Id: <20240129210631.193493-7-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240129210631.193493-1-mathieu.desnoyers@efficios.com> References: <20240129210631.193493-1-mathieu.desnoyers@efficios.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: C4E0F100021 X-Stat-Signature: ijcoin8p6461eto5ujnrfytr4ad4yzbx X-HE-Tag: 1706562412-695272 X-HE-Meta: U2FsdGVkX1+hNJ9NtADtVWBZglga++rXwqkcSdPRBBqWAQC0A7xUOsE9cMxUCsXhZKDFAmGgCKOw9wfQA1iX9YfiZYsYif7cVSPM3+pc52PWDJ2uTxuQ72OXsQSi2Ca18ot2b18x1WddIiKds6Fq+f13A/3C0iKoFz/unmzBWjK/Bpfcr3SRsJm9Kdzv1D8sPrdXXd7Ox7f6/aX/BRJhfnUifnr7RlLIvW7Vmg64L+WoMvq9oWZqYA1/jq3XVW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ub7HBSrH50kgBb1aqs4hmKXT/j86uDMRAeSnBhJ0x86y1Uy1VGIl6Q+fRN9ygqtiTdaIzineLDKFTdZCQk8MNZrBCFLW4zq+zbWigtYOktaWxuPSv1YMcdrsTFQAgb8iJDaIhuaBsjoq4yfCE+ClFXE9XaC4WaEwQa2png62+10DZVO6zUjSKZEtezgrExC7shAOzINGdJkSWQURU9ZNB8fPYYc9LhjoqRHQFwkdBGj0pesCA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Use dax_is_supported() in addition to IS_ENABLED(CONFIG_FUSE_DAX) to validate whether CONFIG_FUSE_DAX is enabled and the architecture does not have virtually aliased caches. This is relevant for architectures which require a dynamic check to validate whether they have virtually aliased data caches (ARCH_HAS_CACHE_ALIASING_DYNAMIC=y). Fixes: d92576f1167c ("dax: does not work correctly with virtual aliasing caches") Signed-off-by: Mathieu Desnoyers Cc: Miklos Szeredi Cc: linux-fsdevel@vger.kernel.org Cc: Andrew Morton Cc: Linus Torvalds Cc: linux-mm@kvack.org Cc: linux-arch@vger.kernel.org Cc: Dan Williams Cc: Vishal Verma Cc: Dave Jiang Cc: Matthew Wilcox Cc: nvdimm@lists.linux.dev Cc: linux-cxl@vger.kernel.org --- fs/fuse/file.c | 2 +- fs/fuse/fuse_i.h | 36 +++++++++++++++++++++++++++++++++- fs/fuse/inode.c | 47 +++++++++++++++++++++++---------------------- fs/fuse/virtio_fs.c | 4 ++-- 4 files changed, 62 insertions(+), 27 deletions(-) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index a660f1f21540..133ac8524064 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -3247,6 +3247,6 @@ void fuse_init_file_inode(struct inode *inode, unsigned int flags) init_waitqueue_head(&fi->page_waitq); fi->writepages = RB_ROOT; - if (IS_ENABLED(CONFIG_FUSE_DAX)) + if (fuse_dax_is_supported()) fuse_dax_inode_init(inode, flags); } diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 1df83eebda92..1cbe37106669 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -31,6 +31,7 @@ #include #include #include +#include /** Default max number of pages that can be used in a single read request */ #define FUSE_DEFAULT_MAX_PAGES_PER_REQ 32 @@ -979,6 +980,38 @@ static inline void fuse_sync_bucket_dec(struct fuse_sync_bucket *bucket) rcu_read_unlock(); } +#ifdef CONFIG_FUSE_DAX +static inline struct fuse_inode_dax *fuse_inode_get_dax(struct fuse_inode *inode) +{ + return inode->dax; +} + +static inline enum fuse_dax_mode fuse_conn_get_dax_mode(struct fuse_conn *fc) +{ + return fc->dax_mode; +} + +static inline struct fuse_conn_dax *fuse_conn_get_dax(struct fuse_conn *fc) +{ + return fc->dax; +} +#else +static inline struct fuse_inode_dax *fuse_inode_get_dax(struct fuse_inode *inode) +{ + return NULL; +} + +static inline enum fuse_dax_mode fuse_conn_get_dax_mode(struct fuse_conn *fc) +{ + return FUSE_DAX_INODE_DEFAULT; +} + +static inline struct fuse_conn_dax *fuse_conn_get_dax(struct fuse_conn *fc) +{ + return NULL; +} +#endif + /** Device operations */ extern const struct file_operations fuse_dev_operations; @@ -1324,7 +1357,8 @@ void fuse_free_conn(struct fuse_conn *fc); /* dax.c */ -#define FUSE_IS_DAX(inode) (IS_ENABLED(CONFIG_FUSE_DAX) && IS_DAX(inode)) +#define fuse_dax_is_supported() (IS_ENABLED(CONFIG_FUSE_DAX) && dax_is_supported()) +#define FUSE_IS_DAX(inode) (fuse_dax_is_supported() && IS_DAX(inode)) ssize_t fuse_dax_read_iter(struct kiocb *iocb, struct iov_iter *to); ssize_t fuse_dax_write_iter(struct kiocb *iocb, struct iov_iter *from); diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index 2a6d44f91729..030e6ce5486d 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c @@ -108,7 +108,7 @@ static struct inode *fuse_alloc_inode(struct super_block *sb) if (!fi->forget) goto out_free; - if (IS_ENABLED(CONFIG_FUSE_DAX) && !fuse_dax_inode_alloc(sb, fi)) + if (fuse_dax_is_supported() && !fuse_dax_inode_alloc(sb, fi)) goto out_free_forget; return &fi->inode; @@ -126,9 +126,8 @@ static void fuse_free_inode(struct inode *inode) mutex_destroy(&fi->mutex); kfree(fi->forget); -#ifdef CONFIG_FUSE_DAX - kfree(fi->dax); -#endif + if (fuse_dax_is_supported()) + kfree(fuse_inode_get_dax(fi)); kmem_cache_free(fuse_inode_cachep, fi); } @@ -361,7 +360,7 @@ void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, invalidate_inode_pages2(inode->i_mapping); } - if (IS_ENABLED(CONFIG_FUSE_DAX)) + if (fuse_dax_is_supported()) fuse_dax_dontcache(inode, attr->flags); } @@ -856,14 +855,16 @@ static int fuse_show_options(struct seq_file *m, struct dentry *root) if (sb->s_bdev && sb->s_blocksize != FUSE_DEFAULT_BLKSIZE) seq_printf(m, ",blksize=%lu", sb->s_blocksize); } -#ifdef CONFIG_FUSE_DAX - if (fc->dax_mode == FUSE_DAX_ALWAYS) - seq_puts(m, ",dax=always"); - else if (fc->dax_mode == FUSE_DAX_NEVER) - seq_puts(m, ",dax=never"); - else if (fc->dax_mode == FUSE_DAX_INODE_USER) - seq_puts(m, ",dax=inode"); -#endif + if (fuse_dax_is_supported()) { + enum fuse_dax_mode dax_mode = fuse_conn_get_dax_mode(fc); + + if (dax_mode == FUSE_DAX_ALWAYS) + seq_puts(m, ",dax=always"); + else if (dax_mode == FUSE_DAX_NEVER) + seq_puts(m, ",dax=never"); + else if (dax_mode == FUSE_DAX_INODE_USER) + seq_puts(m, ",dax=inode"); + } return 0; } @@ -936,7 +937,7 @@ void fuse_conn_put(struct fuse_conn *fc) struct fuse_iqueue *fiq = &fc->iq; struct fuse_sync_bucket *bucket; - if (IS_ENABLED(CONFIG_FUSE_DAX)) + if (fuse_dax_is_supported()) fuse_dax_conn_free(fc); if (fiq->ops->release) fiq->ops->release(fiq); @@ -1264,7 +1265,7 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args, min_t(unsigned int, fc->max_pages_limit, max_t(unsigned int, arg->max_pages, 1)); } - if (IS_ENABLED(CONFIG_FUSE_DAX)) { + if (fuse_dax_is_supported()) { if (flags & FUSE_MAP_ALIGNMENT && !fuse_dax_check_alignment(fc, arg->map_alignment)) { ok = false; @@ -1331,12 +1332,12 @@ void fuse_send_init(struct fuse_mount *fm) FUSE_HANDLE_KILLPRIV_V2 | FUSE_SETXATTR_EXT | FUSE_INIT_EXT | FUSE_SECURITY_CTX | FUSE_CREATE_SUPP_GROUP | FUSE_HAS_EXPIRE_ONLY | FUSE_DIRECT_IO_ALLOW_MMAP; -#ifdef CONFIG_FUSE_DAX - if (fm->fc->dax) - flags |= FUSE_MAP_ALIGNMENT; - if (fuse_is_inode_dax_mode(fm->fc->dax_mode)) - flags |= FUSE_HAS_INODE_DAX; -#endif + if (fuse_dax_is_supported()) { + if (fuse_conn_get_dax(fm->fc)) + flags |= FUSE_MAP_ALIGNMENT; + if (fuse_is_inode_dax_mode(fuse_conn_get_dax_mode(fm->fc))) + flags |= FUSE_HAS_INODE_DAX; + } if (fm->fc->auto_submounts) flags |= FUSE_SUBMOUNTS; @@ -1643,7 +1644,7 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx) sb->s_subtype = ctx->subtype; ctx->subtype = NULL; - if (IS_ENABLED(CONFIG_FUSE_DAX)) { + if (fuse_dax_is_supported()) { err = fuse_dax_conn_alloc(fc, ctx->dax_mode, ctx->dax_dev); if (err) goto err; @@ -1709,7 +1710,7 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx) if (fud) fuse_dev_free(fud); err_free_dax: - if (IS_ENABLED(CONFIG_FUSE_DAX)) + if (fuse_dax_is_supported()) fuse_dax_conn_free(fc); err: return err; diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c index 5f1be1da92ce..99f8f2a18ee4 100644 --- a/fs/fuse/virtio_fs.c +++ b/fs/fuse/virtio_fs.c @@ -801,7 +801,7 @@ static int virtio_fs_setup_dax(struct virtio_device *vdev, struct virtio_fs *fs) struct dev_pagemap *pgmap; bool have_cache; - if (!IS_ENABLED(CONFIG_FUSE_DAX)) + if (fuse_dax_is_supported()) return 0; /* Get cache region */ @@ -1366,7 +1366,7 @@ static void virtio_fs_conn_destroy(struct fuse_mount *fm) /* Stop dax worker. Soon evict_inodes() will be called which * will free all memory ranges belonging to all inodes. */ - if (IS_ENABLED(CONFIG_FUSE_DAX)) + if (fuse_dax_is_supported()) fuse_dax_cancel_work(fc); /* Stop forget queue. Soon destroy will be sent */