mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sourav Panda <souravpanda@google.com>
To: djbw@kernel.org, vishal.l.verma@intel.com, dave.jiang@intel.com,
	 alison.schofield@intel.com, pankaj.gupta.linux@gmail.com,
	mst@redhat.com,  jasowangio@gmail.com, eperezma@redhat.com,
	viro@zeniv.linux.org.uk,  brauner@kernel.org
Cc: iweiny@kernel.org, jack@suse.cz, xuanzhuo@linux.alibaba.com,
	 shuah@kernel.org, david@kernel.org, souravpanda@google.com,
	 nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org,
	 virtualization@lists.linux.dev, linux-fsdevel@vger.kernel.org,
	 linux-kselftest@vger.kernel.org, linux-mm@kvack.org,
	 linux-kernel@vger.kernel.org
Subject: [RFC PATCH 3/5] vfs: allow fallocate() on character devices implementing ->fallocate()
Date: Mon, 30 Nov 2026 01:23:52 +0000	[thread overview]
Message-ID: <20261130012354.1894611-4-souravpanda@google.com> (raw)
In-Reply-To: <20261130012354.1894611-1-souravpanda@google.com>

vfs_fallocate() returns -ENODEV for anything that is not a regular file
or a block device, before it looks at f_op->fallocate.  Let a character
device through when its driver implements ->fallocate().  All other
character devices keep returning -ENODEV, and since no character device
in the tree implements ->fallocate() today, nothing changes for existing
drivers.

The first user is device-dax, in a later patch, where punching a hole
releases device memory.  An ioctl could do that too, but
madvise(MADV_REMOVE) is implemented by calling vfs_fallocate() with
FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE on the mapped file.  Going
through ->fallocate() lets an allocator release part of a device-dax
mapping with the madvise() call it already uses for shmem.

The permission and sanity checks in vfs_fallocate() are unchanged and
still run before the driver is called.

Signed-off-by: Sourav Panda <souravpanda@google.com>
---
 fs/open.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/open.c b/fs/open.c
index bb484b07390ac..0f31caf9e7597 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -321,7 +321,13 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
 	if (S_ISDIR(inode->i_mode))
 		return -EISDIR;
 
-	if (!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode))
+	/*
+	 * Character devices that implement ->fallocate() (device-dax uses it
+	 * for discard, see drivers/dax/device.c) are allowed through; all other
+	 * character devices keep -ENODEV.
+	 */
+	if (!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode) &&
+	    !(S_ISCHR(inode->i_mode) && file->f_op->fallocate))
 		return -ENODEV;
 
 	/* Check for wraparound */
-- 
2.56.1.839.g22a8290db9-goog


  parent reply	other threads:[~2026-11-30  1:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  1:23 [RFC PATCH 0/5] virtio-pmem & device-dax: host-backed range discard via fallocate() / MADV_REMOVE Sourav Panda
2026-11-30  1:23 ` [RFC PATCH 1/5] dax/device: validate mmap offset alignment against dev_dax->align Sourav Panda
2026-11-30  1:23 ` [RFC PATCH 2/5] virtio_pmem: add VIRTIO_PMEM_F_DISCARD and region discard hook Sourav Panda
2026-11-30  1:23 ` Sourav Panda [this message]
2026-11-30  1:23 ` [RFC PATCH 4/5] dax/device: add fallocate() discard support Sourav Panda
2026-11-30  1:23 ` [RFC PATCH 5/5] selftests/dax: add devdax_discard tests Sourav Panda

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=20261130012354.1894611-4-souravpanda@google.com \
    --to=souravpanda@google.com \
    --cc=alison.schofield@intel.com \
    --cc=brauner@kernel.org \
    --cc=dave.jiang@intel.com \
    --cc=david@kernel.org \
    --cc=djbw@kernel.org \
    --cc=eperezma@redhat.com \
    --cc=iweiny@kernel.org \
    --cc=jack@suse.cz \
    --cc=jasowangio@gmail.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mst@redhat.com \
    --cc=nvdimm@lists.linux.dev \
    --cc=pankaj.gupta.linux@gmail.com \
    --cc=shuah@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=virtualization@lists.linux.dev \
    --cc=vishal.l.verma@intel.com \
    --cc=xuanzhuo@linux.alibaba.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®