From patchwork Fri Feb 2 21:00:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Desnoyers X-Patchwork-Id: 13543405 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 52406C4828E for ; Fri, 2 Feb 2024 21:00:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C9DB36B0098; Fri, 2 Feb 2024 16:00:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BE05D6B0095; Fri, 2 Feb 2024 16:00:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8584B6B0096; Fri, 2 Feb 2024 16:00:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 603C96B0089 for ; Fri, 2 Feb 2024 16:00:32 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 3D8A18032F for ; Fri, 2 Feb 2024 21:00:32 +0000 (UTC) X-FDA: 81748082304.19.C9776D8 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by imf20.hostedemail.com (Postfix) with ESMTP id 7C3D31C002F for ; Fri, 2 Feb 2024 21:00:30 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=efficios.com header.s=smtpout1 header.b=MHwLCxMM; dmarc=pass (policy=none) header.from=efficios.com; spf=pass (imf20.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=1706907630; 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=Kwly0G1hIyigNj4R8I+M8crQH2nJcdxecRBcCdsJ/MQ=; b=IdQwAgQnppzTRtFptc0yNrc4RPMR6T1EaluvNBcFSQZjPNjM/8Ludz/r+7L2m6jUif95MH 04eazafhF6s2bdA8ZuELgPU0NDGjSFhhfZJXf+cnwymsrS/fW5e07ZDE7Wv7D1qFdxoJdH Mo9amGVsG/DSHw4EQAsq5sPFs0QHUrs= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=efficios.com header.s=smtpout1 header.b=MHwLCxMM; dmarc=pass (policy=none) header.from=efficios.com; spf=pass (imf20.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=1706907630; a=rsa-sha256; cv=none; b=KU98a6Y7Rw8KILDqimkcpSWXbc5a8pT9y/a1BjBip9rosxEXP/Qvd7eTdxMNEVmhAD99Dj EfmcWyBU5S424+foKYjb86Fty6qI/Q7gTs6p0awTYQRUDMo3R67x/dT0H/vIEeX/PS9B5T dvE9xobgLiV9CR9kdb5++EFMyC0W3g4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1706907629; bh=hDhYMA3F+4l5mMIlcEOrH62nfylV2E9jEwkIfVNtigI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MHwLCxMMJ8oX6+bHEOyVn0lkZWWp3rdA/3Ni7ikq4m3u/+zRvC1YBE6wqxLL7ME+n bgtUOSoSwrkc53a8AMpqI8r1roW5ed7yLgGbUksKRENhkgdc0fwks9v/6nR8TTMRY6 +0nAINngg+wnnGf/N2eZwv+LGmczJE5nl1OEURUOSjYrBV3Ql9BFVUT9r7x6rBUKiR OS4hhk0KIM4MvPNbRVvDfCHuI/kNx4MaTpchFxgSzS7luhDBCjsF2qKuj4PU9PWXMv olV2aSH37fJ9i07BukbKYDwL9bHUbH1JJggkbDvLLLQ04RCIH7ZHMou+lQfNNPnT6u 8aHu31qfGDDKg== 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 4TRSpj1nT8zXBx; Fri, 2 Feb 2024 16:00:29 -0500 (EST) From: Mathieu Desnoyers To: Dan Williams , Arnd Bergmann , Dave Chinner Cc: linux-kernel@vger.kernel.org, Mathieu Desnoyers , Andrew Morton , Linus Torvalds , Vishal Verma , Dave Jiang , Matthew Wilcox , Russell King , linux-arch@vger.kernel.org, linux-cxl@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-xfs@vger.kernel.org, dm-devel@lists.linux.dev, nvdimm@lists.linux.dev, linux-s390@vger.kernel.org Subject: [RFC PATCH v4 06/12] dax: Check for data cache aliasing at runtime Date: Fri, 2 Feb 2024 16:00:13 -0500 Message-Id: <20240202210019.88022-7-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240202210019.88022-1-mathieu.desnoyers@efficios.com> References: <20240202210019.88022-1-mathieu.desnoyers@efficios.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 5yfapo4ne733837n8z9frj8e6u3c5cd1 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 7C3D31C002F X-HE-Tag: 1706907630-470320 X-HE-Meta: U2FsdGVkX1/FR+ikz7OuqrTNxyJPQhC1NRaO2SSwMG96i8vCaDWoFisfbCOwBq5eK+gD5IWL/fp49v3xgH0NvHASagDIsf5TKvQ6VD2YroreAzcgnvSZTRYvzbzBQ4PRDoNaVmitEDH7TtDC8vqNHmKyNZVZgGn62Q/GOarIQXtfSg4YunNNDzY26pfs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6HcrOj6iawlcCcwgSw8YxUbPNd/1Oa02QC5WxrNo4VzATsrBzUNq20fjhBwm6DP9J1nDsOH50Vf+FrS1/5IhZ9QJjXpOFQygBtEVQPk1KfeUovUhlRYy/IidMHcy5a7Gl/b+JrpRRQdBijTmhp1aGFAQ7CCeybG900kl2re+NBsFzTge1AUzZWmEx56XyaAL0xnjailUMEeEIueFh4wvuc+9IoKbqgQKZq0S3WkX+91uHGerSn/s2U4LJOOVkpQ29bcM8+iCxZaxJOP/CyeFV9T6mVuLLkOB8Rx6 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: Replace the following fs/Kconfig:FS_DAX dependency: depends on !(ARM || MIPS || SPARC) By a runtime check within alloc_dax(). This runtime check returns ERR_PTR(-EOPNOTSUPP) if the @ops parameter is non-NULL (which means the kernel is using an aliased mapping) on an architecture which has data cache aliasing. Change the return value from NULL to PTR_ERR(-EOPNOTSUPP) for CONFIG_DAX=n for consistency. This is done in preparation for using cpu_dcache_is_aliasing() in a following change which will properly support architectures which detect data cache aliasing at runtime. Fixes: d92576f1167c ("dax: does not work correctly with virtual aliasing caches") Signed-off-by: Mathieu Desnoyers Cc: Andrew Morton Cc: Linus Torvalds Cc: Dan Williams Cc: Vishal Verma Cc: Dave Jiang Cc: Matthew Wilcox Cc: Arnd Bergmann Cc: Russell King Cc: linux-arch@vger.kernel.org Cc: linux-cxl@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org Cc: linux-mm@kvack.org Cc: linux-xfs@vger.kernel.org Cc: dm-devel@lists.linux.dev Cc: nvdimm@lists.linux.dev --- drivers/dax/super.c | 15 +++++++++++++++ fs/Kconfig | 1 - include/linux/dax.h | 6 +----- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/drivers/dax/super.c b/drivers/dax/super.c index 0da9232ea175..ce5bffa86bba 100644 --- a/drivers/dax/super.c +++ b/drivers/dax/super.c @@ -319,6 +319,11 @@ EXPORT_SYMBOL_GPL(dax_alive); * that any fault handlers or operations that might have seen * dax_alive(), have completed. Any operations that start after * synchronize_srcu() has run will abort upon seeing !dax_alive(). + * + * Note, because alloc_dax() returns an ERR_PTR() on error, callers + * typically store its result into a local variable in order to check + * the result. Therefore, care must be taken to populate the struct + * device dax_dev field make sure the dax_dev is not leaked. */ void kill_dax(struct dax_device *dax_dev) { @@ -445,6 +450,16 @@ struct dax_device *alloc_dax(void *private, const struct dax_operations *ops) dev_t devt; int minor; + /* + * Unavailable on architectures with virtually aliased data caches, + * except for device-dax (NULL operations pointer), which does + * not use aliased mappings from the kernel. + */ + if (ops && (IS_ENABLED(CONFIG_ARM) || + IS_ENABLED(CONFIG_MIPS) || + IS_ENABLED(CONFIG_SPARC))) + return ERR_PTR(-EOPNOTSUPP); + if (WARN_ON_ONCE(ops && !ops->zero_page_range)) return ERR_PTR(-EINVAL); diff --git a/fs/Kconfig b/fs/Kconfig index 42837617a55b..e5efdb3b276b 100644 --- a/fs/Kconfig +++ b/fs/Kconfig @@ -56,7 +56,6 @@ endif # BLOCK config FS_DAX bool "File system based Direct Access (DAX) support" depends on MMU - depends on !(ARM || MIPS || SPARC) depends on ZONE_DEVICE || FS_DAX_LIMITED select FS_IOMAP select DAX diff --git a/include/linux/dax.h b/include/linux/dax.h index b463502b16e1..df2d52b8a245 100644 --- a/include/linux/dax.h +++ b/include/linux/dax.h @@ -86,11 +86,7 @@ static inline void *dax_holder(struct dax_device *dax_dev) static inline struct dax_device *alloc_dax(void *private, const struct dax_operations *ops) { - /* - * Callers should check IS_ENABLED(CONFIG_DAX) to know if this - * NULL is an error or expected. - */ - return NULL; + return ERR_PTR(-EOPNOTSUPP); } static inline void put_dax(struct dax_device *dax_dev) {