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: 196030 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp699646dyc; Fri, 2 Feb 2024 13:07:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IFZRwowyiUHeupNq7mzOb2+hDHVIqrR5MvskboaIkgCvgU2pqEokEvKK40du/S1/15IIxEU X-Received: by 2002:a05:6808:6509:b0:3be:cdbd:5d77 with SMTP id fm9-20020a056808650900b003becdbd5d77mr7383689oib.39.1706908076807; Fri, 02 Feb 2024 13:07:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706908076; cv=pass; d=google.com; s=arc-20160816; b=ipVZbvuAYuKOvlzvYZtJAB/7heKQfSx1A4cvw5mfy54KQ6M1fBmUeHYM8qVrkQXkLY rXxVCmvLypQcGFeXNHxk7O2nkS1zZMUI0Yal8kTxE45p2gI3K4S3bvznc5TrbTq868fs UWTL/FtbAzJP1mfKRYyxUle+GUsyksuMHBetjxct36J+SjV0dhtrlc7PcVrgWPkjemKM Ln5j29FRLhSbPFZM4iC6TwLmkgGZymfYKC/Y9xdcFPR7HyQ6MU5lLrtC1Y/YRF2JwmPq o7VvkczOq1x2sa44nwk/ZPYWNXMXIdqMoYEqped+ahceMNlEF996qRWF3cCxa5h240/Z jCZA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Kwly0G1hIyigNj4R8I+M8crQH2nJcdxecRBcCdsJ/MQ=; fh=fHMT/Bsuev4px2BoVCTDBXjbLJSxf1wIoLxwak+fk5w=; b=LKa8DPTK8aJWvgRYtUsgnZLUCIrMXUlPcYsEXfkqLuy4Yxwj62oLIk/Z6mLBFq3qFx JgvZVHH/+nIcqogQMOB2L/JYrWeXZtQALtH/NCk5AWLC1e6XGE/QWwmCvGIPfRZILQI+ 9cwo1JVMrnYbSpBRi1g7ZiM3Jk9KjI2N1CCjjJjI0WOgarSQ09DKBjY6faPgulZPjkH1 GU3GkKfU0sUBelWi2HiOWRLZ5+t55bhESzc7JRMo/6YHOxy0tRrrFyQGdhhtzCMZn6Lu riMq3Fd8ucW2za4BrXw2fnQHcMusL6eELtAqWHTRqKBDWHphtx44A5Jfk4P1+rfahqSD JP3A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=MHwLCxMM; arc=pass (i=1 spf=pass spfdomain=efficios.com dkim=pass dkdomain=efficios.com dmarc=pass fromdomain=efficios.com); spf=pass (google.com: domain of linux-kernel+bounces-50580-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50580-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com X-Forwarded-Encrypted: i=1; AJvYcCUzHG+zUcqYb/eQzGq8Rm1EZ/63N8KbbMixIkQAcwVoqjEvYNoqJYx/tdnHt0f1Bu+jtpehm+MZEPtCo5UtE1MtrLB6Yw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id u14-20020a05622a14ce00b0042c0b9e0fc6si701784qtx.456.2024.02.02.13.07.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 13:07:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50580-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=MHwLCxMM; arc=pass (i=1 spf=pass spfdomain=efficios.com dkim=pass dkdomain=efficios.com dmarc=pass fromdomain=efficios.com); spf=pass (google.com: domain of linux-kernel+bounces-50580-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50580-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 9285D1C218A4 for ; Fri, 2 Feb 2024 21:07:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 25ED813A89F; Fri, 2 Feb 2024 21:00:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b="MHwLCxMM" Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CFB2812F366; Fri, 2 Feb 2024 21:00:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=167.114.26.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706907634; cv=none; b=sr56j8D5+5vtGyqJ+4vRF7dKsHqRR4I0OjicZk/OIaLjvzoGEPFBCCQAxBQgAp0JcaqFHkcCtRFTXjXDyUKbgBEYGYLoUtprae1zcaPJ/sSv9409fDJYy987cbsYjP87qTt3c2T8p740+C54r1yzdDRDdpZchcmeMZ2nRUg6fR0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706907634; c=relaxed/simple; bh=hDhYMA3F+4l5mMIlcEOrH62nfylV2E9jEwkIfVNtigI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LWicAoMIsgJpELU4FZGn6xkDr/iAYUMmSHHqfDcVlUvgwD2H4hBT3Klz2OvfW6Ks23fXev9M2ZHqG3onn2PQapKAJpxRs1O3Rs2JpLezQI/MaNX3uzyTWe+ERA/BlPqe8AH2R/YOR3FaA58XxRdH9lcEJBz5rGrsz4sXuwMxg0I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com; spf=pass smtp.mailfrom=efficios.com; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b=MHwLCxMM; arc=none smtp.client-ip=167.114.26.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=efficios.com 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789822843332318392 X-GMAIL-MSGID: 1789822843332318392 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) {