From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.197 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796001840; b=VcxkOXHmBumQ2fkL6Z5leaVhdOiWgbfHJgcOS7Rs+Hpky47/dI55uyUn31f1YlWBOW4T VM0zx7rbBLb7AcOJGXN/GNzH0dt+L08d4FmdUTPLmjzV6sPVtgYsm7kVD6YO2zRJIGBET bnrsAAP1GtHYBmVq4KUSjQ9fy3ff4pP3WVLToPAVgrsal+YM6RHfRPf4QQyF8NlI4sq5q FISonrMp6MsCWwZ+behuFg9BBI4XlAxlUDGYCWqE2PabF5r9JboDzO54863jWuKRenOCH 1UX5g1dycjXSFEOZIqsPWDN7AmJkEsDLWt3Yp8qbNjThysFhPK4J505BxMtSXmMYemg== 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=e6TmrvJCRooi98rskCsHh8w3387dFZpQAzo858yvK2kzG0IWLb68h7VoOfOaJARAcPf+ 8FC672a3dD9Wv5orjJiYT7yciW7B7bm8uGUoYQFr4uHol8V6++5L9GBpI/g0J3228O7ht P9PkqBfmZg7nW6dDR5CJ/1jfWhkLXziNtGbLaOfg1useqQ794ln1MXXUqQvbvEPkb4BNp +/RvcT+1edRrZ2/ScTsB+QvZASjJSv5Rj8tNsLqEwuWbNNH5Tidgcbfghnmq3GYt0rhXs 1KBfYeSRpCTpprDjYkhNElrjtmaYupxPyt0INgDS5YNMhNRsz/bnTd+IM6LvyuyYbCA== 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="Qv+1/g//"; arc=none smtp.remote-ip=209.85.215.197 Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) (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 9C525606A334 for ; Mon, 30 Nov 2026 01:23:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9C525606A334 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=Qv+1/g// Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-cd66551e02cso9052202a12.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=lists.linux.dev; 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=Qv+1/g//1OCnAKfWnpsf9+vfMpQimXTMEeBnI/M+XQJFP0QnhRcJ9yuDZh4fuWuh54 O1iG8RG8S4V7AZVfdsm3gFE/8v8SLRYHNKMNT5EcMP4+lRposyNH9dmDSw8M7a39uXP9 qjBsch3c9I+uiVAVWKwMmO9tGuCWYKTNbtZYohYwSqhIsTWhsSrCJjbtPqoaI/PE+KSJ zH6ALkekHGQ01bt05WM+OQG35AiK7gjdKQ/UKtbUEC1g5uuj8gSRJrAADprqPi1vQyOF bVRedX8Rq59YPlyIv9J0ESYTCkm9VqPbuGq0MYeuYw3fDveCltQOMK12le3/ci2cb16P 7MFQ== 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=cei6yOWheOjH5Hks/Zv6S3R4A+/WL/+8GU706tc4yI6eON3Th9KSdeo+xx0vMsjnDi aaeMvgf13IlnBucVFtnixExCiZEEafF3BdB3r0RnnyuYPLP+ARor8MehJy/l6bsfS6Nw X/1u//X8qdKDBV48SWFmWOI/tVawlH370YdWoyzRIo/OSfGETsGs85MEKvBhEEmMMvVQ ljPaS51S+yAQA5UawO+UfemiMitFm+w7HfkaHZnrfvNkJaIKV+cCEdinrBMxQ7lzDUnK fBeTe73GLfJ9p21Nvk2lXJ3xDQoImJPZHjeWZL07seJN6Eg/ydwXmx/pb/CdJobedJj1 xW1w== X-Forwarded-Encrypted: i=1; AL+hErFFqfbP2OmogZaFb9zd1B00bbBswJuJ2y7Tdo5Lft9uli7H2khinaEkvmL/XJZeSpYjgItg2FVCtBvnh3saeA==@lists.linux.dev X-Gm-Message-State: APuU4Z+QPoeXNtGwCRf1oRy2HCm47C8Zoo5rQ3raonPkUidJhLG06V9Y 5r4PwW2tyRzGA0draFl8vYTuRyWqGavdGWpHNIT9dqGSF455PZSnt8Ho/gyb64Jg/CfjNAfiUMK n4emyynTXR7LjfoPq+9Lx1W/QsQ== 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: virtualization@lists.linux.dev 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