Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.198 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796001840; b=dEoLM4ljfNTgTgNa3Jm9ZXSp8ZgyZ9UVNCmzdD7XvE+qIcGibwPhY6Ow61+8xFwry3/j n49mq9vJPLZTcNwq1qH3gOcQHZkOXwR0tmVolp9+5u5AtlLWScou5GAmKNITdAaC6AIXO yXwxIfRSv+m56M0VotENkrr6SVKE2sw1oNUYt5VXHGbVODRha0eXGB/rrt4aHeFOXEJCg 4riXFZWSCUvhFabidCP2jJUit+LK9w7j8iOLyZiidu/tQbVGIoS3RUXgWpW8tjBU/OIOY E+FbjJagntaFaby4ape8X5sttfDcEq72DLOXuyPNdzAWR/neRpmOnKNhVDdBHeHlZWw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796001840; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=hbglymmccX8FLzPcK+y2BXFnYZmtUB5/w1+tn4vJJSc=; b=HLVlBD08QWr+jjVQFRipf2MpmlnGzVS9MaK6MUJ1KAGnOkjYBPRc4ySij1yxiCjRcNEf 565yun7PNnX8z48r0O/GyQ80Rr9vXLPUK47worjKlN6es3KFtkQUupPPus+rTZasFlkzO 6k4sXyEFjbnxO+ctNHFZ0aQJalSni7R4ADMY1HdeAx6XKkLYFPEGWuqQpcXDFHc3Llouk zNn4KkjyG9rHFtHr7TjRVHt3QGQelrVeIHZdm9/rL88LloDYpPJFpSO2GhvsAj6Vt61Ip C6/cJJKKCbH9TCjhlH04wNWuLlYIyez6NGZCFJI72y36rcKQ/CTqr3kdQBQy3yhZXhw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--souravpanda.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=lof3ljuO; arc=none smtp.remote-ip=209.85.215.198 Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E071606A6B9 for ; Mon, 30 Nov 2026 01:23:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9E071606A6B9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--souravpanda.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=lof3ljuO Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-cd66551e02cso9052199a12.2 for ; Sun, 29 Nov 2026 17:23:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796001839; x=1796606639; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=hbglymmccX8FLzPcK+y2BXFnYZmtUB5/w1+tn4vJJSc=; b=lof3ljuONI5sOCeDe8BLSUVuG5Vc/a2cJuXMrYL6lAa/lonExYx34YlQ+hKA/UCdSH Pgfz3DO9Gyisei2Db/ivqmXBAdoRVZ9Smq5nNm0C4rNFP/WdBU+t1ZVZNWYAAdi1G3qn zpowbANQHTWNa0S8/X2NHEgPTQdhX/DAK5J/cSU6zNf4XDOciwpyc+r/InVLs5j5LIPu 99ht+TFH7xRJvLk+GsynwquWXBWWlzf8UfkW6BajwtEuRME8lytXu69BQU4G5EcDAWUj 5ddnp1qfTkPKeMD8B8EQ3dqMUBTX7r62X762dZt5F9OewlUsbgO0seVPD07VG1fJSM9E g/pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796001839; x=1796606639; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=hbglymmccX8FLzPcK+y2BXFnYZmtUB5/w1+tn4vJJSc=; b=sGE88QjCBZI/nLJOjDf/M/Kc/e1IXckRKR6QCzxX/DGUf9uVjARLHCN9ZvwxOQExZa tAI8srjUx4lJ0/xuUktu2BHFlwiuqHRC5Z2bEiM6o5HBLd+MEhGT7j5fZjjYFeOXi2pL c/R2DmOZjQhUFf/RAQFu0DjIiW61+5CeN36p2yaFpiGfEDycbFphazWrK6XyQQBBt3Ng u2YCQ4gKwbWnH+M1u2RuyGQMpdZcsbRNxUpISQE7PEbXG7CRiXSFV7oWcY4AF8x4DPPV B+RrIfBSVc6ouzSZiCfte2DLCbq5MoMGQz5B17OQmTzP9iNsBSIvbwGxCkN6n3zsGvDI Q+zg== X-Forwarded-Encrypted: i=1; AL+hErGIj5TSK+Ez2UbiB+P6dVwB4LI7hm7vrm9I/bRNbjUCtqCkyhAK+pRxBTRkaUp0Os9/gvPR1cCLqvg=@vger.kernel.org X-Gm-Message-State: APuU4Z/aN7LwxckVgcJ5tN7J8oMjLmRxIGrTU6Sx+G7j33Wltaa9aAGk fw15N7MefmIgFqNR609D+tNkV0QHbKxY57Gvj4bBcPv7FN5viPhcvwBH7HxkahfLkFsCnxAV/un C9nqLJN+TK5d9rKDJrQciVzhF/A== X-Received: from pgbm24-n1.prod.google.com ([2002:a05:6a02:6198:10b0:cd8:bbd8:6e89]) (user=souravpanda job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6300:8095:b0:3dd:a196:69e4 with SMTP id adf61e73a8af0-4014d14d2d3mr30286540637.63.1796001838843; Sun, 29 Nov 2026 17:23:58 -0800 (PST) Date: Mon, 30 Nov 2026 01:23:52 +0000 In-Reply-To: <20261130012354.1894611-1-souravpanda@google.com> X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261130012354.1894611-1-souravpanda@google.com> X-Mailer: git-send-email 2.56.1.839.g22a8290db9-goog Message-ID: <20261130012354.1894611-4-souravpanda@google.com> Subject: [RFC PATCH 3/5] vfs: allow fallocate() on character devices implementing ->fallocate() From: Sourav Panda 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 Content-Type: text/plain; charset="UTF-8" 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 --- 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