From: sashiko-bot@kernel.org
To: "John Groves" <john@jagalactic.com>
Cc: nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org
Subject: Re: [PATCH V14 11/12] famfs: Report device capacity via statfs so df works
Date: Sat, 29 Aug 2026 17:30:37 +0000 [thread overview]
Message-ID: <20260829173037.9FABD1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <010001a04e82df10-e266ce13-d8e7-42f0-ae64-0b2df6e94be5-000000@email.amazonses.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Use-after-free race condition in `dax_fsdev_size()` due to missing SRCU read lock (`dax_read_lock()`).
- [Medium] The statfs `used_capacity` counter grows monotonically but is never decremented when files are evicted, causing `df` to permanently show 0 available space.
- [Low] Mixing goto-based error handling with scope-based cleanup helpers (`scoped_guard`) in the same function violates kernel cleanup guidelines.
--
commit dd30d0d60f5f3c8708d001e5e982ce4519316fdc
Author: John Groves <John@Groves.net>
famfs: Report device capacity via statfs so df works
Replace simple_statfs(), which reports zero blocks (so df omits the mount),
with famfs_statfs() reporting real capacity and usage.
> diff --git a/drivers/dax/fsdev.c b/drivers/dax/fsdev.c
> index 188b2526bee45..a5b4b2d794286 100644
> --- a/drivers/dax/fsdev.c
> +++ b/drivers/dax/fsdev.c
[ ... ]
> @@ -104,6 +104,25 @@ static size_t fsdev_dax_recovery_write(struct dax_device *dax_dev, pgoff_t pgoff
> return _copy_from_iter_flushcache(addr, bytes, i);
> }
>
> +/**
> + * dax_fsdev_size() - total size in bytes of an fsdev dax device
> + * @dax_dev: the dax device (must be bound to this driver)
> + *
> + * Returns the size cached at probe time (sum of all ranges); it cannot change
> + * while the driver is bound. Only valid for fsdev dax devices - callers
> + * ensure that (e.g. fs_dax_get() enforces DAXDRV_FSDEV_TYPE). Returns 0 if the
> + * device is not alive.
> + */
> +u64 dax_fsdev_size(struct dax_device *dax_dev)
> +{
> + struct dev_dax *dev_dax = dax_get_private(dax_dev);
> +
> + if (!dev_dax)
> + return 0;
> + return dev_dax->cached_size;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[Severity: High]
Does this code introduce a use-after-free race condition?
dax_fsdev_size() retrieves the dev_dax pointer via dax_get_private(dax_dev)
and accesses dev_dax->cached_size without acquiring the SRCU read lock
(dax_read_lock()).
If an asynchronous device unplug or sysfs unbind occurs concurrently,
kill_dax() could clear the DAXDEV_ALIVE flag and call synchronize_srcu().
Since the SRCU read lock is not held here, synchronize_srcu() would return
immediately, and the unplug path could free the dev_dax structure before
cached_size is read.
> +}
> +EXPORT_SYMBOL_GPL(dax_fsdev_size);
> +
> static const struct dax_operations dev_dax_ops = {
> .direct_access = fsdev_dax_direct_access,
> .zero_page_range = fsdev_dax_zero_page_range,
[ ... ]
> diff --git a/fs/famfs/famfs_file.c b/fs/famfs/famfs_file.c
> index 0a6d0392794c5..965b6732f52c4 100644
> --- a/fs/famfs/famfs_file.c
> +++ b/fs/famfs/famfs_file.c
[ ... ]
> @@ -344,6 +344,11 @@ famfs_file_init_dax(struct file *file, void __user *arg)
> }
> inode_unlock(inode);
>
> + /* Account the mapped device bytes for statfs (only on success) */
> + if (!rc) {
> + scoped_guard(rwsem_write, &fsi->stats_sem)
> + fsi->used_capacity += extent_total;
> + }
^^^^^
[Severity: Low]
This isn't a bug, but does mixing scope-based cleanup helpers (scoped_guard)
with goto-based error handling in this function violate kernel cleanup
guidelines?
famfs_file_init_dax() heavily relies on goto labels (out:) for error
handling. The kernel guidelines suggest either converting all resources
that need cleanup to scope-based cleanup, or converting none of them, to
avoid confusing ownership semantics.
> out:
> kvfree(fmap_buf);
> if (meta)
[ ... ]
> diff --git a/fs/famfs/famfs_inode.c b/fs/famfs/famfs_inode.c
> index 2f1938adbfbc3..61b668b299ef5 100644
> --- a/fs/famfs/famfs_inode.c
> +++ b/fs/famfs/famfs_inode.c
[ ... ]
> @@ -348,8 +349,38 @@ famfs_evict_inode(struct inode *inode)
> clear_inode(inode);
> }
^^^^^^^^^^^^^^^^^^
[Severity: Medium]
Will this cause the fsi->used_capacity counter to grow monotonically and
eventually report zero available space?
When a user creates and maps a famfs file, fsi->used_capacity is permanently
incremented in famfs_file_init_dax(). However, famfs_evict_inode() frees the
metadata but does not appear to decrement fsi->used_capacity to reflect the
freed space.
If users repeatedly create and unlink files, won't fsi->used_capacity
double-count the space until df permanently shows 0 available blocks?
>
> +/*
> + * famfs_statfs() - report device capacity and consumption so 'df' works.
> + * @total_capacity is the sum of installed daxdev sizes; @used_capacity is the
> + * sum of device bytes mapped by fmaps (superblock + log + data files). Free is
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/010001a04e801a4e-8eb212cd-b263-4043-ab65-33e480d2d7d4-000000@email.amazonses.com?part=11
next prev parent reply other threads:[~2026-08-29 17:30 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260829171004.7336-1-john@jagalactic.com>
2026-08-29 17:10 ` [PATCH V14 00/12] Subject: [PATCH v14 00/12] famfs: the Fabric-Attached Memory File System (standalone) John Groves
2026-08-29 17:10 ` [PATCH V14 01/12] dax: replace exported dax_dev_get() with non-allocating dax_dev_find() John Groves
2026-08-29 17:11 ` [PATCH V14 02/12] famfs: Module operations, fs_context, and mount John Groves
2026-08-29 17:28 ` sashiko-bot
2026-08-29 17:11 ` [PATCH V14 03/12] famfs: Add daxdev table and dax notify_failure support John Groves
2026-08-29 17:32 ` sashiko-bot
2026-08-29 17:11 ` [PATCH V14 04/12] famfs: Introduce inode_operations and super_operations John Groves
2026-08-29 17:11 ` [PATCH V14 05/12] famfs: Introduce file_operations read/write John Groves
2026-08-29 17:25 ` sashiko-bot
2026-08-29 17:11 ` [PATCH V14 06/12] famfs: Introduce mmap and VM fault handling John Groves
2026-08-29 17:26 ` sashiko-bot
2026-08-29 17:11 ` [PATCH V14 07/12] famfs: MAP_CREATE ioctl and fmap ingest (ABI 44) John Groves
2026-08-29 17:30 ` sashiko-bot
2026-08-29 17:12 ` [PATCH V14 08/12] famfs: iomap_begin and file-to-dax offset resolution John Groves
2026-08-29 17:25 ` sashiko-bot
2026-08-29 17:12 ` [PATCH V14 09/12] famfs: Register secondary daxdevs by path (FAMFSIOC_DAXDEV_OPEN) John Groves
2026-08-29 17:25 ` sashiko-bot
2026-08-29 17:13 ` [PATCH V14 10/12] famfs: Add runtime operation-permission (opts) framework John Groves
2026-08-29 17:13 ` [PATCH V14 11/12] famfs: Report device capacity via statfs so df works John Groves
2026-08-29 17:30 ` sashiko-bot [this message]
2026-08-29 17:13 ` [PATCH V14 12/12] famfs: Add documentation John Groves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260829173037.9FABD1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=john@jagalactic.com \
--cc=linux-cxl@vger.kernel.org \
--cc=nvdimm@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.