DM_PCACHE reaches persistent memory through dm_dev->dax_dev and
dax_direct_access(). That dax_device is registered by the block driver with
dax_add_host(), which stores it in the global dax_hosts xarray keyed by the
gendisk pointer; fs_dax_get_by_bdev() later looks it up by
bdev->bd_disk and drivers/md/dm.c:769 assigns the result to
dm_dev->dax_dev. The whole registry, both dax_add_host() and
fs_dax_get_by_bdev(), is compiled under CONFIG_BLOCK && CONFIG_FS_DAX
(drivers/dax/super.c), so with FS_DAX=n neither side exists: pmem and
virtio-pmem still register a dax_device for their char node, but the lookup
can never find one and dm_dev->dax_dev stays NULL. cache_dev_dax_init()
then fails:

  dm-pcache: cache_dev_dax_init:91 252:0 dax_direct_access failed: -95
  dm-pcache: cache_dev_start:254 252:0 failed to init cache_dev 259:0 via
  dax way: -95.

-EOPNOTSUPP here comes from dax_direct_access() taking a NULL dax_device;
the message gives no hint that the kernel is simply missing FS_DAX.
Since the target cannot work at all without it, make the dependency
explicit so Kconfig does not offer a target that can never start.

Verified by Kconfig alone (defconfig, DAX=y DEV_DAX=y):
  FS_DAX=n: DM_PCACHE is not selectable
  FS_DAX=y: DM_PCACHE=m is selectable
and at runtime in QEMU (virtio-pmem + virtio-blk, KASAN kernel): the same
dmsetup table that returned -EOPNOTSUPP without FS_DAX is created
successfully once FS_DAX=y.

Note: DEV_DAX is not what the target uses, so it could arguably be dropped
instead of kept; this change only adds the dependency that is missing.

Fixes: 1d57628ff95b ("dm-pcache: add persistent cache target in device-mapper")
Cc: [email protected]
Signed-off-by: Ruiqiang Hao <[email protected]>
---
 drivers/md/dm-pcache/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/md/dm-pcache/Kconfig b/drivers/md/dm-pcache/Kconfig
index 0e251eca892e..bf223eb8accd 100644
--- a/drivers/md/dm-pcache/Kconfig
+++ b/drivers/md/dm-pcache/Kconfig
@@ -2,6 +2,7 @@ config DM_PCACHE
        tristate "Persistent cache for Block Device (Experimental)"
        depends on BLK_DEV_DM
        depends on DEV_DAX
+       depends on FS_DAX
        help
          PCACHE provides a mechanism to use persistent memory (e.g., CXL 
persistent memory,
          DAX-enabled devices) as a high-performance cache layer in front of
-- 
2.43.0

Reply via email to