From nobody Tue Nov 24 11:52:11 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=79.135.106.31 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795361183; b=a9cOKHleM6WR3ZyeaFEWz03ceMig3UeF721i8H4t32dDrxyjaiWB4zsEHNBBjOvRZdLF RqES04SWLLyiedohKyLpT0AftNo53Cr8ZM9kt81bVuaB5oB4P1Ysyjo/gOpxA3JiyxSNC I3rYJuf/sT3Iv+ufPOZum4UmI+av8ttjxaE3QtlFmdnKcrOZw2ZwDDAcoVO9w4DC9doD2 yvfNze5URRTj/fJMFjrzC71umU6qXm/YFjvKNagmfN45DWERIn/PXlhq6zyE+L2Fm7Xsn mgpj6tHaWIs96Oxv7fZJYnMj1RQqH9nDpeH+LeLiSpJp9iTxW1nrbD4I+1dh2xHIZ3A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795361183; h=DMARC-Filter:DKIM-Signature:Date:To:From:Cc:Subject:Message-ID: In-Reply-To:References:Feedback-ID:X-Pm-Message-ID:MIME-Version: Content-Type:Content-Transfer-Encoding; bh=8Sc/0QjrZjg1TPndTW2kHmTziSBLoi+G23tfiraHCRE=; b=RwaiXP6ld0sxsIYixBppnNFDmtTR/nHcv1z0nySZu/bdXOQDdm9FGIZo0UkBrAnbEJc2 /qPNwtUkIfbT9Y5mfDx2TWnhMKItmQ95GcLWYLR8gqZxLW81uJ3JjIstQJpBqzoxVNbgM knq5TJklcDNqjb/Wj2qf+XILUBNk7VVWtI6kji13DK/6w4UKItUXYNMOo41W1UIZERezE VI3bi6LzT0QWrdDQ9NW47PCILFMNRTU0RJ6YA0iSGadT0sX7Klk3ezFdJGyggipInQtDE bsgnp0ZX+jMFRJBnTVc0uuvwgyuV+/iHuCUyd7YSd1JUqUn2O9OxnpmjBYmD3XffAkA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass header.d=proton.me header.i=@proton.me header.a=rsa-sha256 header.s=protonmail2 header.b=aUCYkEny; arc=none smtp.remote-ip=79.135.106.31 Received: from mail-10631.protonmail.ch (mail-10631.protonmail.ch [79.135.106.31]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5AFB606A330; Sun, 22 Nov 2026 15:26:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B5AFB606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=proton.me header.i=@proton.me header.a=rsa-sha256 header.s=protonmail2 header.b=aUCYkEny DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail2; t=1795361180; x=1795620380; bh=8Sc/0QjrZjg1TPndTW2kHmTziSBLoi+G23tfiraHCRE=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=aUCYkEnyuiU22Jh7bh//oeOtvhU35Hg3yAA/E1M3rsIe4niC7+BR9cf3Xyc514DdU cAXCTcBuBqB7YzY6EChe/4KW16OGuO9XhCnUvNTCPxuVxhAeKQnXvkrAZ3W9i5dCVh v0GWecsoJVLSM7ayBMDAeGmMazeIpi6OdKDvhOx61w2VRKXatkuv3Rp1PnGCRCHIC4 0GRS/EqhaeoDI/SQeYooP/jNp2jf7CrxSXQyot71yAD6221N5NW3dtAdHog+7VOiGM 9iDY+WHL7f4b9DFa4Wf6rZufsgSghq6HRg1mX97CNuX5QlOeYOMMHXVfmpmOwiB2Ny g6dN2d31WWsCQ== Date: Sun, 22 Nov 2026 15:26:14 +0000 To: Miklos Szeredi From: Yun Wang <7z0423arsenova@proton.me> Cc: Bernd Schubert , Joanne Koong , Shuah Khan , fuse-devel@lists.linux.dev, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/5] fuse: don't wait for a sync-init mount when turning off fasync Message-ID: <20261122152514.467423-2-7z0423arsenova@proton.me> In-Reply-To: <20261122152514.467423-1-7z0423arsenova@proton.me> References: <20261122152514.467423-1-7z0423arsenova@proton.me> Feedback-ID: 227066774:user:proton X-Pm-Message-ID: 255a16f6281118b0e3e2bc920c60b135dae23307 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Yun Wang Since commit dfb84c330794 ("fuse: allow synchronous FUSE_INIT"), fuse_dev_fasync() looks the device up with fuse_get_dev(), which waits until the mount has installed the channel if FUSE_DEV_IOC_SYNC_INIT was used. open(2) keeps O_ASYNC in f_flags, and __fput() calls ->fasync(-1, file, 0) for every file with FASYNC set. So the last fput of a sync-init device that was opened with O_ASYNC and never mounted waits for a mount that can no longer come: until a signal in a task, and forever in a kworker, which no signal wakes. The last fput runs in a kworker for example when the unix socket garbage collector frees a file that was in flight, and then the stuck delayed_fput work also holds up every later delayed fput: an unrelated tmpfs umount(2) then fails with EBUSY. /dev/fuse is 0666, so any user can do this. In v7.1, before commit 9f6f44aa5a58 ("fuse: don't block in fuse_get_dev() for non-sync_init case"), fuse_get_dev() waited for any device that wasn't mounted yet, so this didn't even need FUSE_DEV_IOC_SYNC_INIT. Only an installed device can be on fiq->fasync, so before the mount there is nothing to remove. Don't wait when fasync is turned off; turning it on still waits for the mount as before. Turning it off on a device that isn't mounted now succeeds instead of failing with -EPERM. Fixes: dfb84c330794 ("fuse: allow synchronous FUSE_INIT") Cc: stable@vger.kernel.org Signed-off-by: Yun Wang --- fs/fuse/dev.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index 3641abb90d6b..2f6991d0e959 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -2280,10 +2280,23 @@ EXPORT_SYMBOL_GPL(fuse_dev_release); =20 static int fuse_dev_fasync(int fd, struct file *file, int on) { - struct fuse_dev *fud =3D fuse_get_dev(file); + struct fuse_dev *fud; =20 - if (IS_ERR(fud)) - return PTR_ERR(fud); + /* + * Only an installed device can be on fiq->fasync, so there is nothing + * to remove before the mount. Don't wait for it then: __fput() calls + * this for every O_ASYNC file, also one that is never mounted, and + * also from a kworker, which no signal ends the wait for. + */ + if (!on) { + fud =3D __fuse_get_dev(file); + if (!fud) + return 0; + } else { + fud =3D fuse_get_dev(file); + if (IS_ERR(fud)) + return PTR_ERR(fud); + } =20 /* No locking - fasync_helper does its own locking */ return fasync_helper(fd, file, on, &fud->chan->iq.fasync); --=20 2.56.1 From nobody Tue Nov 24 11:52:11 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=109.224.244.16 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795361199; b=bqyqrc2fHA0UJNJOn/Dko5ELiALB4Jgh//6exIIiGMciwAMwFdzxqPRm6yHmv4EZoc4E V1JcWfvrTLuztO6FT/UxmmIuCFg42u3W8ZdNb7MYuaSZhXdJSXksO/xry+FFkMBgGnUBm NFA29NTGrVMQkCLl1o4GPkBC5EzjpepuTznLRZcj9W/sFyO7Q2wpSYGPMz87pGz+UWiYm GKEIscWWyNxPEvo9Jw+6KN62qGXWYrjfEPWhcVhxcB15T/ep0R+mi3MbsjpqvGFwYlO7a cjGuSZGPal8PptgT5e8hp3yj/4O1IA2tVdoy7DuHdzUDvwLc34/xphPrJKHx/wTOEIA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795361199; h=DMARC-Filter:DKIM-Signature:Date:To:From:Cc:Subject:Message-ID: In-Reply-To:References:Feedback-ID:X-Pm-Message-ID:MIME-Version: Content-Type:Content-Transfer-Encoding; bh=AhNJa4RluqAwM/OuiFX7GgLlrJSQIox3sRpeUWbwb7Q=; b=bS+UGC5qhlMmJsUyHp2XglkWEH61NWgkvhNZ1H22Nj+DjA4MiOANWSkvw8YiAA+U76bq KQ1mNOPaO+uF+hz+eOkQdOHLGWUHg7qhQKfesTiV3obCDYcmPsGL5uns30YGRr0lHoIKw rRz3RnOAl1E7K5f9s6DHpqjCpSI1RRS30j5poHGd+oqjY0pO3Kl1NJewLIaYkG+ZN7AAP r3YKubUvSbQCVrJdR4koq4qg8QB5n0J1ZeI5oVEMuJYaQQGWuaHRJyhIp/cozqtaz045W hR1B7hovVqmYczM0fSTZ2wDrRUhvxa7Jtgie5h+R4rdqqsn/Pw3j2ch+sOQvMVj9g0Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass header.d=proton.me header.i=@proton.me header.a=rsa-sha256 header.s=protonmail2 header.b=HUA6GlXR; arc=none smtp.remote-ip=109.224.244.16 Received: from mail-24416.protonmail.ch (mail-24416.protonmail.ch [109.224.244.16]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B67F5606A32A; Sun, 22 Nov 2026 15:26:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B67F5606A32A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=proton.me header.i=@proton.me header.a=rsa-sha256 header.s=protonmail2 header.b=HUA6GlXR DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail2; t=1795361194; x=1795620394; bh=AhNJa4RluqAwM/OuiFX7GgLlrJSQIox3sRpeUWbwb7Q=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=HUA6GlXRu5tMQtRaVX0K9UKfjEUUaRH+RTbz7+VS7EG7vnkAys0yc0HswAVXMH4J9 0tPcv87ToNoigThTVa0PdSPAdB0v4ASZqSPzMfq64KBzywiu3sGMKaxHZRNHyJOBbR SuL32uW/vxT8Mq3LbMQEJ2wSjWL00QOkyEh2K99D3/Q7aeVMFC9RvNQMncqA9I63kH RZbrKV/iNRi4KQzGrdiOaPhtlMqgsLDVF7G8JmsIuFBkZgMMjN+Uz68QhSo2yDInFa gV70DoVFJs8799OfyhwgRXq0x1lcdFM0rAm8iFjwOWd1yjugWO8GuOzFQVeZSrQ7Xy 4tGWmBBItq1bQ== Date: Sun, 22 Nov 2026 15:26:28 +0000 To: Miklos Szeredi From: Yun Wang <7z0423arsenova@proton.me> Cc: Bernd Schubert , Joanne Koong , Shuah Khan , fuse-devel@lists.linux.dev, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/5] fuse: don't wait for a sync-init mount in non-blocking reads Message-ID: <20261122152514.467423-3-7z0423arsenova@proton.me> In-Reply-To: <20261122152514.467423-1-7z0423arsenova@proton.me> References: <20261122152514.467423-1-7z0423arsenova@proton.me> Feedback-ID: 227066774:user:proton X-Pm-Message-ID: cf13ff2cbfec08cf1850c81af825a8fef619ae86 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Yun Wang Since commit dfb84c330794 ("fuse: allow synchronous FUSE_INIT"), fuse_get_dev() waits until the mount has installed the channel when FUSE_DEV_IOC_SYNC_INIT was used on the device. fuse_dev_read() and fuse_dev_splice_read() call it before fuse_dev_do_read() looks at O_NONBLOCK, so read(2) or splice(2) on an O_NONBLOCK sync-init device that is not mounted yet sleeps until the mount or a signal, instead of returning -EAGAIN. Commit 9f6f44aa5a58 ("fuse: don't block in fuse_get_dev() for non-sync_init case") fixed the same hang for devices without sync init, which LTP's read_all hit with O_NONBLOCK reads of /dev/fuse. Rename fuse_get_dev() to _fuse_get_dev() and add fuse_get_dev_nowait(), which returns -EAGAIN instead of waiting for the mount. The new fuse_get_dev() uses the latter for O_NONBLOCK files and is called from fuse_dev_read() and fuse_dev_splice_read(). The other callers still wait whether or not the file is O_NONBLOCK and call _fuse_get_dev(); fuse_uring_cmd() and ->poll are fixed in the next patches. A non-blocking read before the mount now gets -EAGAIN, the same as after the mount while no request is queued. Blocking reads still wait for the mount. Fixes: dfb84c330794 ("fuse: allow synchronous FUSE_INIT") Reviewed-by: Bernd Schubert Signed-off-by: Yun Wang --- fs/fuse/dev.c | 10 +++++----- fs/fuse/dev_uring.c | 2 +- fs/fuse/fuse_dev_i.h | 30 ++++++++++++++++++++++++++++-- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index 2f6991d0e959..7cb93885cd0a 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -1687,7 +1687,7 @@ static int fuse_dev_open(struct inode *inode, struct = file *file) return 0; } =20 -struct fuse_dev *fuse_get_dev(struct file *file) +struct fuse_dev *_fuse_get_dev(struct file *file) { struct fuse_dev *fud =3D fuse_file_to_fud(file); int err; @@ -2106,7 +2106,7 @@ static __poll_t fuse_dev_poll(struct file *file, poll= _table *wait) { __poll_t mask =3D EPOLLOUT | EPOLLWRNORM; struct fuse_iqueue *fiq; - struct fuse_dev *fud =3D fuse_get_dev(file); + struct fuse_dev *fud =3D _fuse_get_dev(file); =20 if (IS_ERR(fud)) return EPOLLERR; @@ -2293,7 +2293,7 @@ static int fuse_dev_fasync(int fd, struct file *file,= int on) if (!fud) return 0; } else { - fud =3D fuse_get_dev(file); + fud =3D _fuse_get_dev(file); if (IS_ERR(fud)) return PTR_ERR(fud); } @@ -2322,7 +2322,7 @@ static long fuse_dev_ioctl_clone(struct file *file, _= _u32 __user *argp) if (fd_file(f)->f_op !=3D file->f_op) return -EINVAL; =20 - fud =3D fuse_get_dev(fd_file(f)); + fud =3D _fuse_get_dev(fd_file(f)); if (IS_ERR(fud)) return PTR_ERR(fud); =20 @@ -2339,7 +2339,7 @@ static long fuse_dev_ioctl_clone(struct file *file, _= _u32 __user *argp) =20 static struct fuse_conn *fuse_get_conn_for_passthrough(struct file *file) { - struct fuse_dev *fud =3D fuse_get_dev(file); + struct fuse_dev *fud =3D _fuse_get_dev(file); =20 if (IS_ERR(fud)) return ERR_CAST(fud); diff --git a/fs/fuse/dev_uring.c b/fs/fuse/dev_uring.c index 460776cd69cd..92240ab76e45 100644 --- a/fs/fuse/dev_uring.c +++ b/fs/fuse/dev_uring.c @@ -1664,7 +1664,7 @@ int fuse_uring_cmd(struct io_uring_cmd *cmd, unsigned= int issue_flags) if (!(issue_flags & IO_URING_F_SQE128)) return -EINVAL; =20 - fud =3D fuse_get_dev(cmd->file); + fud =3D _fuse_get_dev(cmd->file); if (IS_ERR(fud)) { pr_info_ratelimited("No fuse device found\n"); return PTR_ERR(fud); diff --git a/fs/fuse/fuse_dev_i.h b/fs/fuse/fuse_dev_i.h index 4b412a76225f..808152b75792 100644 --- a/fs/fuse/fuse_dev_i.h +++ b/fs/fuse/fuse_dev_i.h @@ -367,9 +367,35 @@ static inline struct fuse_dev *__fuse_get_dev(struct f= ile *file) return fud; } =20 -void fuse_iqueue_init(struct fuse_iqueue *fiq, const struct fuse_iqueue_op= s *ops, void *priv); +/* Get the device, waiting for the mount of a sync-init device */ +struct fuse_dev *_fuse_get_dev(struct file *file); + +/* + * Like _fuse_get_dev(), but don't wait for the mount of a sync-init devic= e: + * return -EAGAIN instead. + */ +static inline struct fuse_dev *fuse_get_dev_nowait(struct file *file) +{ + struct fuse_dev *fud =3D fuse_file_to_fud(file); + + if (unlikely(!fuse_dev_chan_get(fud))) + return ERR_PTR(fud->sync_init ? -EAGAIN : -EPERM); + + return fud; +} + +/* + * For read(2) and splice(2): an O_NONBLOCK device doesn't wait for the + * mount of a sync-init device. + */ +static inline struct fuse_dev *fuse_get_dev(struct file *file) +{ + if (file->f_flags & O_NONBLOCK) + return fuse_get_dev_nowait(file); + return _fuse_get_dev(file); +} =20 -struct fuse_dev *fuse_get_dev(struct file *file); +void fuse_iqueue_init(struct fuse_iqueue *fiq, const struct fuse_iqueue_op= s *ops, void *priv); =20 unsigned int fuse_req_hash(u64 unique); struct fuse_req *fuse_request_find(struct fuse_pqueue *fpq, u64 unique); --=20 2.56.1 From nobody Tue Nov 24 11:52:11 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=109.224.244.17 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795361213; b=EnGk7Z16erhfS7Lw16v3c3bBvrp/FhXrz0Mtbrzjj6ugWrsl8wuWOEL7jbYs1H+NQPMw Ts28U3QVxK0WBLIJLtHymML7SudjyLkcOSPt3DfBw4Yl177dWJ1FePQp8qTKXgN059aNJ nuKHz49G5SJ8RK+3Mvw2HYqg2c9OIfzsIMOW1wi89ZK2AoRgJ0HSdSpCEl0B/ab1PbIRw WaiZFsKSPlVUpmyF9rtBVS6CWN3sTQa9HsTzE7ZFStO1O5uBnwzx4IJMK1clgnH/Kdq2Y jSwtQpijzijJ/q8lHuROwz1XI5NGI8P5TUyANoDfFgfaJe3NHds3meBH6pLjHpLUUoQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795361213; h=DMARC-Filter:DKIM-Signature:Date:To:From:Cc:Subject:Message-ID: In-Reply-To:References:Feedback-ID:X-Pm-Message-ID:MIME-Version: Content-Type:Content-Transfer-Encoding; bh=wy6XS5seyhU6K2UszLq+oDiIaG1TExlMlf05DK9sBJ4=; b=0scypRIqhuzmuAx/5HEv+QeXeBtikiL6vw0qaDWPxT6Z0YPhMGBsufhJ32h2aX4HX8P3 yOtd3ywh1rn/bVbsoNvS89D69pg1PJuy93+ocXaKAJQq6QUgAUCBfS5CVxN/9Ty0/+NnN 4LXTHUxSCRxrrgf/P+UdMM2Q6W8xdnCJ/NEitvZDkhAq8pyfIRjg3CpuLuN99H/112y4h 518Ym6AnQhnuj04fRJ1EFq2Vphs5CYLl1BNnJwZ5EhIFZwJ+oPBdK7ImpZ/+Glf2khHph S8P/dTvjeXTqk0NvsFgE+CyaRfgJTiCevZ6M/WMJlNKj0hHfJwSeNLTTh8boiRqLtPQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass header.d=proton.me header.i=@proton.me header.a=rsa-sha256 header.s=protonmail2 header.b=wid8b3OF; arc=none smtp.remote-ip=109.224.244.17 Received: from mail-24417.protonmail.ch (mail-24417.protonmail.ch [109.224.244.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA243606A320; Sun, 22 Nov 2026 15:26:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BA243606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=proton.me header.i=@proton.me header.a=rsa-sha256 header.s=protonmail2 header.b=wid8b3OF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail2; t=1795361210; x=1795620410; bh=wy6XS5seyhU6K2UszLq+oDiIaG1TExlMlf05DK9sBJ4=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=wid8b3OFQ5jb1m7UQzO6w0UiqY8Mr/tj0TrVujKq06SWLPJeD1KRZC6tawFE7q5UB LRIUw0snQ297eW3Ys8QiFEJMZq4qXfrTi6EdV8GzoLbSL2YpUz8qOo1mlvA8276qvu CbnyXTwPpuA+JjuaNDtff/IbAwgCp3/e1Fg5jS8NvxxOQhTTPNoNrs/hA4xq9W3Jdi STRQkwQOmmhq4Ts1jQ26Z8GuFnvzAKBCt+4zMLeD+vt8lr3xghme1F5PD7UTCQK6XK 2Gx6MxjMi0E844IpebPiIbYsIih3Yw7lJRVGMQaQbHXDsZ6GuWOogpQhRs5opEkViE GQUCybGgrWDUg== Date: Sun, 22 Nov 2026 15:26:45 +0000 To: Miklos Szeredi From: Yun Wang <7z0423arsenova@proton.me> Cc: Bernd Schubert , Joanne Koong , Shuah Khan , fuse-devel@lists.linux.dev, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/5] fuse: don't wait for a sync-init mount in fuse_uring_cmd() Message-ID: <20261122152514.467423-4-7z0423arsenova@proton.me> In-Reply-To: <20261122152514.467423-1-7z0423arsenova@proton.me> References: <20261122152514.467423-1-7z0423arsenova@proton.me> Feedback-ID: 227066774:user:proton X-Pm-Message-ID: 2ec993559162f69e6c53bdd792e08644d489bf26 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Yun Wang fuse_uring_cmd() gets the device with _fuse_get_dev(), which waits for the mount of a device in sync-init mode. io_uring normally issues the command from the task that called io_uring_enter(2), so an IORING_OP_URING_CMD on such a device before the mount puts that task to sleep until the mount or a signal, with the ring's uring_lock held: any other thread that submits to the same ring waits for it in D state meanwhile. This happens before the enable_uring check, so also when fuse-over-io-uring is disabled. Once the mount has woken it up, the command can still get past the initialized check: FUSE_INIT may have been answered by then, or else io_uring retries it from io-wq after the -EAGAIN, which may be late enough. So a REGISTER sent before the mount sometimes went through, but only by timing. A server has to handle -EAGAIN here anyway, as it does for a REGISTER sent before FUSE_INIT has been answered on an async-init connection, and libfuse only sends REGISTER once the connection is initialized. Return -EAGAIN at once when the device is not mounted yet either, using fuse_get_dev_nowait() from the previous patch, as fuse_uring_cmd() already does until FUSE_INIT has completed, and don't log "No fuse device found" for it. Fixes: dfb84c330794 ("fuse: allow synchronous FUSE_INIT") Signed-off-by: Yun Wang --- fs/fuse/dev_uring.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/fuse/dev_uring.c b/fs/fuse/dev_uring.c index 92240ab76e45..0f725172ae6e 100644 --- a/fs/fuse/dev_uring.c +++ b/fs/fuse/dev_uring.c @@ -1664,9 +1664,15 @@ int fuse_uring_cmd(struct io_uring_cmd *cmd, unsigne= d int issue_flags) if (!(issue_flags & IO_URING_F_SQE128)) return -EINVAL; =20 - fud =3D _fuse_get_dev(cmd->file); + /* + * Don't wait for the mount of a sync-init device: this may run in + * the task that called io_uring_enter(), and the ring can't be + * registered before FUSE_INIT anyway, see the -EAGAIN below. + */ + fud =3D fuse_get_dev_nowait(cmd->file); if (IS_ERR(fud)) { - pr_info_ratelimited("No fuse device found\n"); + if (PTR_ERR(fud) !=3D -EAGAIN) + pr_info_ratelimited("No fuse device found\n"); return PTR_ERR(fud); } fch =3D fud->chan; --=20 2.56.1 From nobody Tue Nov 24 11:52:11 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.70.43.16 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795361228; b=mwXfZ0wlXEJSnVCj4Cf3cJISGbknhbMFh3THoeUUfntUhzXz7NO1mcsPHgv4+XuJc2Xh HtiAK9BxkYxSjPKO2kX1Sw2zeTxIc8MTTkWgh3GpQsWf0OHFRG82+u/729YMDnG04iWSt PE2FI9XMVzCyBrk5BJi6ijEXY5CeUJ9XeIvS9GE3ibTvP8K+EfKhTMLXlSrepHLbABrUm YyKKaVR/VvDi5Lk7rN5VAym27mrTzFF/EYU8kSsAgQKxuOLPaGzs/GPh8szF16w+th1eH Dg7x6JWJbl9X11DpYsMmeNIZFtaHYYBsBRlxi8LokTYcPgYwPHX/iUij0sN4tj6yWhw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795361228; h=DMARC-Filter:DKIM-Signature:Date:To:From:Cc:Subject:Message-ID: In-Reply-To:References:Feedback-ID:X-Pm-Message-ID:MIME-Version: Content-Type:Content-Transfer-Encoding; bh=GvGsD0red2CdKw9UkrmRFfAWiCbnnyXIqmSsv7DDcpU=; b=mfbIUY4num4VIGdvBwc8a9JthCSmkEvOKSoacY2wwYpacK9D/renQSmvKIZIo4UNrvEe PCgjL0biIZuK7liHEr5Pid4XN8FLnffKiYv5iBzJOUxRKn6vbi+L/WiUoANZPPhnvd63Q AzUZXsc51iaOuEPnI1JPxNO6Y1rbnd92CBwfhamz7J0DZqAm4IRUOPVLmF+7IAve/IBiB pMovsA+SvrZ1f4jK/nDKsoA6kjJKIyldLP4Nu89Q1VQ0L4X33f+90CSVqFrVMhPJnMuvW 6DarEtmIl08f5+0pjrntz8sqt+Kjlp9BBr4T6RcbN7SM7464pWWsm7JujKr7r/urR6Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass header.d=proton.me header.i=@proton.me header.a=rsa-sha256 header.s=protonmail2 header.b=Z8HUp7qg; arc=none smtp.remote-ip=185.70.43.16 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 20C09606A32C for ; Sun, 22 Nov 2026 15:27:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 20C09606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=proton.me header.i=@proton.me header.a=rsa-sha256 header.s=protonmail2 header.b=Z8HUp7qg DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail2; t=1795361224; x=1795620424; bh=GvGsD0red2CdKw9UkrmRFfAWiCbnnyXIqmSsv7DDcpU=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=Z8HUp7qgMzJ2h9PYwaCGcaQ+5a8tdpRDmkomDyearmV+hxEYIj8gfxN/4ClDBOsvu mkrwzFbiDIvIjyAkHJ4hvNf8IzRTx6edqLOlqoofwnJ8r8RW8Z1KsVKqTx5gae3cNU Sa1faTJ/YkRqDdNUsTqKMF6QDDiiqmZYqwrph5fFec3ekR4uRR573MmdfRybMDtaEk 2IkLcZ/PXkIhRoXXpPw/8LygJOavvf2C/LUr7V/vkmtIc+AYSLsEXrkK0t+ZI4gPvY KG/RJpd5iUojyBr3M4u02zS6kRWEkSI57+xsg0sQXC+CowSJ0LNYt8/Mm2nY2XNxAM dnUXZrN7enmlQ== Date: Sun, 22 Nov 2026 15:26:58 +0000 To: Miklos Szeredi From: Yun Wang <7z0423arsenova@proton.me> Cc: Bernd Schubert , Joanne Koong , Shuah Khan , fuse-devel@lists.linux.dev, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/5] fuse: don't sleep in ->poll before a sync-init mount Message-ID: <20261122152514.467423-5-7z0423arsenova@proton.me> In-Reply-To: <20261122152514.467423-1-7z0423arsenova@proton.me> References: <20261122152514.467423-1-7z0423arsenova@proton.me> Feedback-ID: 227066774:user:proton X-Pm-Message-ID: 4fa0da788131fab095a1cf655217660b1313cf65 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Yun Wang fuse_dev_poll() gets the device with _fuse_get_dev(), which waits for the mount of a device in sync-init mode. So before the mount, ->poll sleeps until the mount or a signal, and so do its callers: - poll(2), even with a zero timeout. An eventfd in the same poll set can't end the wait, and after a signal poll(2) reports POLLERR. libfuse's sync-init worker polls the device together with an eventfd that is meant to stop it, and libfuse had to work around mounts that hung there, see the Link. - epoll_ctl(EPOLL_CTL_ADD), while holding ep->mtx, so other epoll_ctl() calls and an epoll_wait(2) with events to report on the same epoll instance wait too. - io_uring_enter(2) for a read or a poll, since io_uring polls the device before it tries the read or when it arms a poll for it. That happens with the ring's uring_lock held, so any other thread that submits to the same ring waits for it in D state meanwhile. The sleep can't simply be dropped. Before the mount there is no fiq->waitq to wait on, and poll(2), epoll and io_uring register their wait queue entries only once, so a poller that registered somewhere else before the mount would miss the requests that come after it. Give struct fuse_dev a wait queue for that window. Before the mount, ->poll waits on fud->mount_waitq and reports no events. When a sync-init device is installed, add an entry to fiq->waitq that passes every wakeup on to fud->mount_waitq, and wake fud->mount_waitq once, since the device is writable now. ->poll checks for the channel again after queueing itself, and the channel is set before that wakeup, so a poller racing with the mount either gets woken or sees the channel and then waits on fiq->waitq as well. fuse_dev_release() removes the entry before it drops the connection reference. Pollers that come after the mount wait on fiq->waitq as before. This adds 64 bytes to struct fuse_dev on x86-64 without lock debugging. The wake_up_sync() of a synchronous request is passed on as it is. Any other wakeup may come from wake_up_all(), so it wakes every waiter on fud->mount_waitq, EPOLLEXCLUSIVE ones too; that only affects pollers that came before the mount. The entry stays on fiq->waitq while the device is open, so every wakeup of fiq->waitq calls it. If nobody waits on fud->mount_waitq, it returns without taking that lock, and a request costs one more indirect call. That is the case once the pollers from before the mount are gone, such as libfuse's worker once its poll(2) returns. The check needs no barrier: every waker of fiq->waitq holds fiq->lock, and the pollers woken by the mount look at the queue under fiq->lock again, see the comment in fuse_dev_mount_wake(). Fixes: dfb84c330794 ("fuse: allow synchronous FUSE_INIT") Link: https://github.com/libfuse/libfuse/pull/1633 Signed-off-by: Yun Wang --- fs/fuse/dev.c | 70 +++++++++++++++++++++++++++++++++++++++++--- fs/fuse/fuse_dev_i.h | 9 ++++++ 2 files changed, 75 insertions(+), 4 deletions(-) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index 7cb93885cd0a..187fd13fefe0 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -439,6 +439,7 @@ static struct fuse_dev *fuse_dev_alloc_no_pq(void) =20 refcount_set(&fud->ref, 1); fuse_pqueue_init(&fud->pq); + init_waitqueue_head(&fud->mount_waitq); =20 return fud; } @@ -457,6 +458,35 @@ struct fuse_dev *fuse_dev_alloc(void) } EXPORT_SYMBOL_GPL(fuse_dev_alloc); =20 +/* + * Pollers of a sync-init device that came before the mount are queued on + * fud->mount_waitq, and poll(2), epoll and io_uring don't register again + * later. Pass every wakeup of fiq->waitq on to them: a sync one as it is, + * any other to all of them, since it may come from wake_up_all(). + */ +static int fuse_dev_mount_wake(struct wait_queue_entry *wait, unsigned int= mode, + int wake_flags, void *key) +{ + struct fuse_dev *fud =3D container_of(wait, struct fuse_dev, mount_fwd); + + /* + * Nobody to pass the wakeup on to. Every waker of fiq->waitq holds + * fiq->lock, and the pollers on mount_waitq were woken by the mount + * and look at the queue under fiq->lock again. If that look came + * first, this waker sees them here; if it came later, it sees the + * new request. + */ + if (!waitqueue_active(&fud->mount_waitq)) + return 0; + + /* fiq->waitq is woken only by wake_up{,_all,_sync}(): 0 or WF_SYNC */ + if (wake_flags) + __wake_up_sync_key(&fud->mount_waitq, mode, key); + else + __wake_up(&fud->mount_waitq, mode, 0, key); + return 0; +} + /* * Installs @fch into @fud, return true on success. "Consumes" @pq in eit= her case. */ @@ -490,6 +520,19 @@ static bool fuse_dev_install_with_pq(struct fuse_dev *= fud, struct fuse_chan *fch } list_add_tail(&fud->entry, &fch->devices); fuse_conn_get(fch->conn); + + if (fud->sync_init) { + /* Removed in fuse_dev_release(), before the conn ref is put */ + init_waitqueue_func_entry(&fud->mount_fwd, fuse_dev_mount_wake); + add_wait_queue(&fch->iq.waitq, &fud->mount_fwd); + fud->mount_fwd_queued =3D true; + /* + * The device is writable now. Wake without a key: a poller + * that waits only for EPOLLIN has to look again as well, see + * fuse_dev_mount_wake(). + */ + wake_up_all(&fud->mount_waitq); + } wake_up_all(&fuse_dev_waitq); return true; } @@ -2102,16 +2145,33 @@ static ssize_t fuse_dev_splice_write(struct pipe_in= ode_info *pipe, return ret; } =20 +/* + * Before the mount, a sync-init device has no fiq->waitq to wait on. Its + * pollers wait on fud->mount_waitq instead, and the mount passes the + * wakeups of fiq->waitq on to it, see fuse_dev_mount_wake(). + */ static __poll_t fuse_dev_poll(struct file *file, poll_table *wait) { __poll_t mask =3D EPOLLOUT | EPOLLWRNORM; struct fuse_iqueue *fiq; - struct fuse_dev *fud =3D _fuse_get_dev(file); + struct fuse_dev *fud =3D fuse_file_to_fud(file); + struct fuse_chan *fch =3D fuse_dev_chan_get(fud); =20 - if (IS_ERR(fud)) - return EPOLLERR; + if (unlikely(!fch)) { + if (!fud->sync_init) + return EPOLLERR; + + poll_wait(file, &fud->mount_waitq, wait); + /* + * Check again after queueing: fuse_dev_install_with_pq() sets + * the channel before it wakes fud->mount_waitq. + */ + fch =3D fuse_dev_chan_get(fud); + if (!fch) + return 0; + } =20 - fiq =3D &fud->chan->iq; + fiq =3D &fch->iq; poll_wait(file, &fiq->waitq, wait); =20 spin_lock(&fiq->lock); @@ -2264,6 +2324,8 @@ int fuse_dev_release(struct inode *inode, struct file= *file) /* Are we the last open device? */ last =3D list_empty(&fch->devices); spin_unlock(&fch->lock); + if (fud->mount_fwd_queued) + remove_wait_queue(&fch->iq.waitq, &fud->mount_fwd); =20 fuse_dev_end_requests(&to_end); =20 diff --git a/fs/fuse/fuse_dev_i.h b/fs/fuse/fuse_dev_i.h index 808152b75792..40caa4d820a1 100644 --- a/fs/fuse/fuse_dev_i.h +++ b/fs/fuse/fuse_dev_i.h @@ -305,6 +305,9 @@ struct fuse_dev { /** @sync_init: Issue FUSE_INIT synchronously */ bool sync_init; =20 + /** @mount_fwd_queued: @mount_fwd is on chan->iq.waitq */ + bool mount_fwd_queued; + /** @chan: Fuse channel for this device */ struct fuse_chan *chan; =20 @@ -313,6 +316,12 @@ struct fuse_dev { =20 /** @entry: list entry on fch->devices */ struct list_head entry; + + /** @mount_waitq: pollers that came before the mount wait here */ + wait_queue_head_t mount_waitq; + + /** @mount_fwd: passes wakeups of chan->iq.waitq on to @mount_waitq */ + wait_queue_entry_t mount_fwd; }; =20 struct fuse_copy_state { --=20 2.56.1 From nobody Tue Nov 24 11:52:11 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=109.224.244.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795361240; b=MfIVpDiiTzPq4wuM5ILn0d9yacPE9uBJyt38/HTIKPW0Io7yNHYZBl/Z5jQ2Fbyef099 og36G5n+kl7BeRLQ2TwzbNs4x7dbPXErXzIXzLVmC+0h16csWmXzvQ1hTDACIrww9MZlz aXGI/UuWgflcJ1CCmFRnU+QQRxjMFZkBWY2E2khLet3XymP0SwOjt3L2vm25tUkyNbWgu g+gSg/K5F99fE+3UxmJA2y6cw4TinqkfdmYF/+Odvu62tybdiDsQFxBZiBnmhqXDz0kIk XZWFOaA3AzRGaSCYONUlO09OtkfCfbIM+QNe0fLhnVgy5+GApzMSOHFJXfC0yDRTdpg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795361240; h=DMARC-Filter:DKIM-Signature:Date:To:From:Cc:Subject:Message-ID: In-Reply-To:References:Feedback-ID:X-Pm-Message-ID:MIME-Version: Content-Type:Content-Transfer-Encoding; bh=QG9b2UaelpX3Wm1347brCg45zPhFGvUkcmcf2KQfdH0=; b=Fg9qPiegiElOw8vzhe6ZlwFrsee+Ltg2lb/eBrvRXytm6M9URq4erLUVc3HrhlyzA0Op jfF3J8ljNE2i3MaJJyzOE5ezYq1a6a75FZyM/VA2cmPVWV9/h614/XrZf3NFHlXnSep6e mfpXRgI9SjvRmeiVZvvpaxv86211MIHDWFTR/Ff6jkXuOXu6H5v8pNCFJKGV6/HivhGO9 UzZ81n3WfPRKxcsKr9NLWrv6/7hn/r4ruFKEtRT7Adz093QYLDqvhJlGR8zVv4kJWq5bj 26BQyVfTgnq8URVpMxYi8ndaGY9nhOAam4KH9hJopH/vf90nmdnl9PbuUUJBspEdh+g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass header.d=proton.me header.i=@proton.me header.a=rsa-sha256 header.s=protonmail2 header.b=cVyCRQqd; arc=none smtp.remote-ip=109.224.244.18 Received: from mail-24418.protonmail.ch (mail-24418.protonmail.ch [109.224.244.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61C95606A330 for ; Sun, 22 Nov 2026 15:27:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 61C95606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=proton.me header.i=@proton.me header.a=rsa-sha256 header.s=protonmail2 header.b=cVyCRQqd DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail2; t=1795361236; x=1795620436; bh=QG9b2UaelpX3Wm1347brCg45zPhFGvUkcmcf2KQfdH0=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=cVyCRQqdkgao3bz1OX6ZlxYZPxR9+4n8JLHVM8Gw5EReevUpkpWuSy9Oji1ZEkp6V dJQ3k0aVXyR9mCcxwh2sIm2KxpEh3GD4hKLbT1BomnxfUv2Nr/zkEpPMHkUIsXUAPB mBM4h89hVrLm4dlfZatV5A+ZyUqZEBzD9i9lRa3x8wIRGt91GW1+jAICyHDfqm8Qnw npRvPIZvJgXTyxwDIzcmx+/m7ySuujhFj6IQwdNXDswvqEvu1W4yiK4Y79tl1xnnVC XiMaeIGjTRB2qqe7hUYt9+jQIKdbXwz4ceKXRNtM9fLbekioJzIxRwNjRO0PRpCiWB oU9F8nuwQ8pUQ== Date: Sun, 22 Nov 2026 15:27:14 +0000 To: Miklos Szeredi From: Yun Wang <7z0423arsenova@proton.me> Cc: Bernd Schubert , Joanne Koong , Shuah Khan , fuse-devel@lists.linux.dev, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/5] selftests/fuse: test a sync-init device before the mount Message-ID: <20261122152514.467423-6-7z0423arsenova@proton.me> In-Reply-To: <20261122152514.467423-1-7z0423arsenova@proton.me> References: <20261122152514.467423-1-7z0423arsenova@proton.me> Feedback-ID: 227066774:user:proton X-Pm-Message-ID: ecc7b75af6301248a35516565cc5009ce75ca7b1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Yun Wang A server that uses FUSE_DEV_IOC_SYNC_INIT has the device before the mount does. Test that calls which must not block don't wait for the mount, and that waiters armed before it see its requests. The fuse_dev tests never mount. poll(2) with a zero timeout or together with an eventfd, epoll_ctl(2), read(2) and splice(2) on an O_NONBLOCK device, FUSE_IO_URING_CMD_REGISTER through io_uring, and the close of a device opened with O_ASYNC must return at once; where they wait for the mount, the harness kills them after two seconds. A blocking read(2) must still wait, until an alarm ends it. Two tests send a REGISTER or a POLL_ADD from one thread and a NOP to the same ring from another: the NOP must not have to wait for the mount, as it does when the first thread sleeps with the ring's uring_lock held. Each test also runs on a device without sync init, which must keep failing at once. The mount tests arm epoll (level triggered, edge triggered and with EPOLLEXCLUSIVE) or a multishot io_uring poll before the mount, then mount as root of a new user namespace. The waiter has to report FUSE_INIT, and then a request queued after the mount, without being armed again. io_uring is set up with its system calls, with the 128-byte SQEs that FUSE_IO_URING_CMD_* needs, so the test doesn't depend on liburing. No privileges are needed; the tests skip without /dev/fuse, FUSE_DEV_IOC_SYNC_INIT, io_uring or user namespaces, and the uring_cmd test also without CONFIG_FUSE_IO_URING. Signed-off-by: Yun Wang --- .../selftests/filesystems/fuse/.gitignore | 1 + .../selftests/filesystems/fuse/Makefile | 2 + .../filesystems/fuse/fuse_sync_init_test.c | 532 ++++++++++++++++++ 3 files changed, 535 insertions(+) create mode 100644 tools/testing/selftests/filesystems/fuse/fuse_sync_init= _test.c diff --git a/tools/testing/selftests/filesystems/fuse/.gitignore b/tools/te= sting/selftests/filesystems/fuse/.gitignore index 7c787313e69b..9066f735cfe2 100644 --- a/tools/testing/selftests/filesystems/fuse/.gitignore +++ b/tools/testing/selftests/filesystems/fuse/.gitignore @@ -6,3 +6,4 @@ write_extend_eof_test fuse_acl_cache_test fuse_symlink_cache_test fuse_readdir_cache_test +fuse_sync_init_test diff --git a/tools/testing/selftests/filesystems/fuse/Makefile b/tools/test= ing/selftests/filesystems/fuse/Makefile index e3ae3acff113..15630db378ca 100644 --- a/tools/testing/selftests/filesystems/fuse/Makefile +++ b/tools/testing/selftests/filesystems/fuse/Makefile @@ -7,11 +7,13 @@ TEST_GEN_PROGS +=3D write_extend_eof_test TEST_GEN_PROGS +=3D fuse_acl_cache_test TEST_GEN_PROGS +=3D fuse_symlink_cache_test TEST_GEN_PROGS +=3D fuse_readdir_cache_test +TEST_GEN_PROGS +=3D fuse_sync_init_test TEST_GEN_FILES :=3D fuse_mnt =20 include ../../lib.mk =20 $(OUTPUT)/write_extend_eof_test: LDLIBS +=3D -lpthread +$(OUTPUT)/fuse_sync_init_test: LDLIBS +=3D -lpthread =20 VAR_CFLAGS :=3D $(shell pkg-config fuse3 --cflags 2>/dev/null) ifeq ($(VAR_CFLAGS),) diff --git a/tools/testing/selftests/filesystems/fuse/fuse_sync_init_test.c= b/tools/testing/selftests/filesystems/fuse/fuse_sync_init_test.c new file mode 100644 index 000000000000..98eab737ea8a --- /dev/null +++ b/tools/testing/selftests/filesystems/fuse/fuse_sync_init_test.c @@ -0,0 +1,532 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * A /dev/fuse fd in sync-init mode (FUSE_DEV_IOC_SYNC_INIT) is opened bef= ore + * the mount. Until the mount, calls that must not block have to return at + * once, and waiters armed before it have to see the requests that come af= ter + * it. A call that sleeps instead makes its test hit the harness timeout. + * + * The fuse_dev tests never mount. Each runs on a sync-init fd, where + * non-blocking calls must not wait (while a blocking read still does), and + * on an fd without sync init, which keeps failing at once. The mount tes= ts + * mount as root of a new user namespace. + */ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kselftest_harness.h" + +#define MNT "/tmp/fuse" + +/* A minimal io_uring with 128-byte SQEs, which FUSE_IO_URING_CMD_* needs = */ +struct ring { + int fd; + void *sq, *cq; + size_t sq_sz, cq_sz, sqes_sz; + unsigned int *sq_tail, *sq_mask, *sq_array; + unsigned int *cq_head, *cq_tail, *cq_mask; + struct io_uring_sqe *sqes; + struct io_uring_cqe *cqes; +}; + +static void ring_exit(struct ring *r) +{ + if (r->sq && r->sq !=3D MAP_FAILED) + munmap(r->sq, r->sq_sz); + if (r->cq && r->cq !=3D MAP_FAILED) + munmap(r->cq, r->cq_sz); + if (r->sqes && r->sqes !=3D MAP_FAILED) + munmap(r->sqes, r->sqes_sz); + if (r->fd >=3D 0) + close(r->fd); + memset(r, 0, sizeof(*r)); + r->fd =3D -1; +} + +static int ring_init(struct ring *r, unsigned int entries) +{ + struct io_uring_params p =3D { .flags =3D IORING_SETUP_SQE128 }; + char *sq, *cq; + + memset(r, 0, sizeof(*r)); + r->fd =3D syscall(__NR_io_uring_setup, entries, &p); + if (r->fd < 0) + return -1; + r->sq_sz =3D p.sq_off.array + p.sq_entries * sizeof(unsigned int); + r->cq_sz =3D p.cq_off.cqes + p.cq_entries * sizeof(*r->cqes); + r->sqes_sz =3D p.sq_entries * 2 * sizeof(*r->sqes); + sq =3D r->sq =3D mmap(NULL, r->sq_sz, PROT_READ | PROT_WRITE, MAP_SHARED, + r->fd, IORING_OFF_SQ_RING); + cq =3D r->cq =3D mmap(NULL, r->cq_sz, PROT_READ | PROT_WRITE, MAP_SHARED, + r->fd, IORING_OFF_CQ_RING); + r->sqes =3D mmap(NULL, r->sqes_sz, PROT_READ | PROT_WRITE, MAP_SHARED, + r->fd, IORING_OFF_SQES); + if (sq =3D=3D MAP_FAILED || cq =3D=3D MAP_FAILED || r->sqes =3D=3D MAP_FA= ILED) { + int err =3D errno; + + ring_exit(r); + errno =3D err; + return -1; + } + r->sq_tail =3D (void *)(sq + p.sq_off.tail); + r->sq_mask =3D (void *)(sq + p.sq_off.ring_mask); + r->sq_array =3D (void *)(sq + p.sq_off.array); + r->cq_head =3D (void *)(cq + p.cq_off.head); + r->cq_tail =3D (void *)(cq + p.cq_off.tail); + r->cq_mask =3D (void *)(cq + p.cq_off.ring_mask); + r->cqes =3D (void *)(cq + p.cq_off.cqes); + return 0; +} + +/* Return a zeroed SQE at the tail; publish via ring_commit()/ring_submit(= ). */ +static struct io_uring_sqe *ring_sqe(struct ring *r) +{ + unsigned int idx =3D *r->sq_tail & *r->sq_mask; + struct io_uring_sqe *sqe =3D &r->sqes[idx * 2]; + + memset(sqe, 0, 2 * sizeof(*sqe)); + return sqe; +} + +static void ring_commit(struct ring *r) +{ + unsigned int tail =3D *r->sq_tail; + unsigned int idx =3D tail & *r->sq_mask; + + r->sq_array[idx] =3D idx; + __atomic_store_n(r->sq_tail, tail + 1, __ATOMIC_RELEASE); +} + +static int ring_enter(struct ring *r) +{ + return syscall(__NR_io_uring_enter, r->fd, 1, 0, 0, NULL, 0); +} + +static int ring_submit(struct ring *r) +{ + ring_commit(r); + return ring_enter(r); +} + +/* Wait up to @ms for a CQE; return 1 and its result in @res, or 0. */ +static int ring_cqe(struct ring *r, int ms, int *res) +{ + struct pollfd pfd =3D { .fd =3D r->fd, .events =3D POLLIN }; + unsigned int head =3D *r->cq_head; + + if (head =3D=3D __atomic_load_n(r->cq_tail, __ATOMIC_ACQUIRE)) { + int ret; + + do { + ret =3D poll(&pfd, 1, ms); + } while (ret < 0 && errno =3D=3D EINTR); + if (ret !=3D 1 || + head =3D=3D __atomic_load_n(r->cq_tail, __ATOMIC_ACQUIRE)) + return 0; + } + *res =3D r->cqes[head & *r->cq_mask].res; + __atomic_store_n(r->cq_head, head + 1, __ATOMIC_RELEASE); + return 1; +} + +static int open_dev(struct __test_metadata *const _metadata, bool sync_ini= t) +{ + int fd =3D open("/dev/fuse", O_RDWR | O_NONBLOCK); + + if (fd < 0) + SKIP(return -1, "/dev/fuse: %s", strerror(errno)); + if (sync_init && ioctl(fd, FUSE_DEV_IOC_SYNC_INIT)) { + if (errno =3D=3D ENOTTY) { + close(fd); + SKIP(return -1, "no FUSE_DEV_IOC_SYNC_INIT (v6.18)"); + } + ASSERT_EQ(0, errno); + } + return fd; +} + +FIXTURE(fuse_dev) { + int fd; +}; + +FIXTURE_VARIANT(fuse_dev) { + bool sync_init; + int err; /* what a non-blocking call gets before the mount */ +}; + +FIXTURE_VARIANT_ADD(fuse_dev, sync_init) { + .sync_init =3D true, + .err =3D EAGAIN, +}; + +FIXTURE_VARIANT_ADD(fuse_dev, plain) { + .err =3D EPERM, +}; + +FIXTURE_SETUP(fuse_dev) +{ + self->fd =3D open_dev(_metadata, variant->sync_init); +} + +FIXTURE_TEARDOWN(fuse_dev) +{ + if (self->fd >=3D 0) + close(self->fd); +} + +TEST_F_TIMEOUT(fuse_dev, poll, 2) +{ + struct pollfd pfd =3D { .fd =3D self->fd, .events =3D POLLIN }; + + ASSERT_EQ(!variant->sync_init, poll(&pfd, 1, 0)); + if (!variant->sync_init) + ASSERT_EQ(POLLERR, pfd.revents); +} + +static void *kick(void *efd) +{ + usleep(100 * 1000); + eventfd_write(*(int *)efd, 1); + return NULL; +} + +/* libfuse's sync-init worker polls the fd together with an eventfd. */ +TEST_F_TIMEOUT(fuse_dev, poll_eventfd, 2) +{ + struct pollfd pfd[2] =3D { + { .fd =3D self->fd, .events =3D POLLIN }, + { .fd =3D eventfd(0, 0), .events =3D POLLIN }, + }; + pthread_t thread; + + ASSERT_LE(0, pfd[1].fd); + ASSERT_EQ(0, pthread_create(&thread, NULL, kick, &pfd[1].fd)); + ASSERT_LE(1, poll(pfd, 2, -1)); + if (variant->sync_init) { + ASSERT_EQ(0, pfd[0].revents); + ASSERT_EQ(POLLIN, pfd[1].revents); + } else { + ASSERT_EQ(POLLERR, pfd[0].revents); + } + ASSERT_EQ(0, pthread_join(thread, NULL)); + close(pfd[1].fd); +} + +TEST_F_TIMEOUT(fuse_dev, epoll, 2) +{ + struct epoll_event ev =3D { .events =3D EPOLLIN }; + int epfd =3D epoll_create1(0); + + ASSERT_LE(0, epfd); + ASSERT_EQ(0, epoll_ctl(epfd, EPOLL_CTL_ADD, self->fd, &ev)); + ASSERT_EQ(!variant->sync_init, epoll_wait(epfd, &ev, 1, 0)); + if (!variant->sync_init) + ASSERT_EQ(EPOLLERR, ev.events); + close(epfd); +} + +TEST_F_TIMEOUT(fuse_dev, read, 2) +{ + char buf[FUSE_MIN_READ_BUFFER]; + + ASSERT_EQ(-1, read(self->fd, buf, sizeof(buf))); + ASSERT_EQ(variant->err, errno); +} + +TEST_F_TIMEOUT(fuse_dev, splice, 2) +{ + int p[2]; + + ASSERT_EQ(0, pipe(p)); + ASSERT_EQ(-1, splice(self->fd, NULL, p[1], NULL, + FUSE_MIN_READ_BUFFER, 0)); + ASSERT_EQ(variant->err, errno); + close(p[0]); + close(p[1]); +} + +/* + * open(2) doesn't call ->fasync for O_ASYNC, but the last close turns it + * off through ->fasync, and that must not wait for a mount either. + */ +TEST_F_TIMEOUT(fuse_dev, fasync_close, 2) +{ + int fd =3D open("/dev/fuse", O_RDWR | O_ASYNC); + + ASSERT_LE(0, fd); + if (variant->sync_init) + ASSERT_EQ(0, ioctl(fd, FUSE_DEV_IOC_SYNC_INIT)); + ASSERT_EQ(0, close(fd)); +} + +static void nop(int sig) +{ +} + +/* A blocking read still waits for the mount, until a signal ends it. */ +TEST_F_TIMEOUT(fuse_dev, read_blocking, 3) +{ + struct sigaction sa =3D { .sa_handler =3D nop }; /* no SA_RESTART */ + char buf[FUSE_MIN_READ_BUFFER]; + + ASSERT_EQ(0, sigaction(SIGALRM, &sa, NULL)); + ASSERT_EQ(0, fcntl(self->fd, F_SETFL, 0)); + alarm(1); + ASSERT_EQ(-1, read(self->fd, buf, sizeof(buf))); + alarm(0); + ASSERT_EQ(variant->sync_init ? EINTR : EPERM, errno); +} + +static void prep(struct io_uring_sqe *sqe, __u8 opcode, int fd) +{ + sqe->opcode =3D opcode; + sqe->fd =3D fd; + if (opcode =3D=3D IORING_OP_URING_CMD) + sqe->cmd_op =3D FUSE_IO_URING_CMD_REGISTER; + else + sqe->poll32_events =3D POLLIN; +} + +TEST_F_TIMEOUT(fuse_dev, uring_cmd, 2) +{ + struct ring r; + int res; + + if (ring_init(&r, 1)) + SKIP(return, "io_uring_setup: %s", strerror(errno)); + prep(ring_sqe(&r), IORING_OP_URING_CMD, self->fd); + ASSERT_EQ(1, ring_submit(&r)); + ASSERT_EQ(1, ring_cqe(&r, 1000, &res)); + ring_exit(&r); + if (res =3D=3D -EOPNOTSUPP) + SKIP(return, "no CONFIG_FUSE_IO_URING"); + ASSERT_EQ(-variant->err, res); +} + +static void *submit(void *r) +{ + ring_enter(r); + return NULL; +} + +/* + * io_uring issues the command and polls the fd with the ring's uring_lock + * held: another thread submitting to the same ring must not have to wait + * for the mount. + */ +static void ring_lock(struct __test_metadata *const _metadata, int fd, + __u8 opcode) +{ + struct timespec t0, t1; + pthread_t thread; + struct ring r; + + if (ring_init(&r, 4)) + SKIP(return, "io_uring_setup: %s", strerror(errno)); + prep(ring_sqe(&r), opcode, fd); + ring_commit(&r); + ASSERT_EQ(0, pthread_create(&thread, NULL, submit, &r)); + usleep(100 * 1000); + ring_sqe(&r)->opcode =3D IORING_OP_NOP; + ring_commit(&r); + clock_gettime(CLOCK_MONOTONIC, &t0); + ASSERT_EQ(1, ring_enter(&r)); + clock_gettime(CLOCK_MONOTONIC, &t1); + ASSERT_GT(500, (t1.tv_sec - t0.tv_sec) * 1000 + + (t1.tv_nsec - t0.tv_nsec) / 1000000); + ASSERT_EQ(0, pthread_join(thread, NULL)); + ring_exit(&r); +} + +TEST_F_TIMEOUT(fuse_dev, ring_lock_cmd, 2) +{ + ring_lock(_metadata, self->fd, IORING_OP_URING_CMD); +} + +TEST_F_TIMEOUT(fuse_dev, ring_lock_poll, 2) +{ + ring_lock(_metadata, self->fd, IORING_OP_POLL_ADD); +} + +FIXTURE(mount) { + int fd; + int epfd; + struct ring r; + int err; /* errno of the thread that mounts or calls getxattr */ +}; + +FIXTURE_VARIANT(mount) { + __u32 events; /* epoll events, or 0 for a multishot io_uring poll */ +}; + +FIXTURE_VARIANT_ADD(mount, epoll) { + .events =3D EPOLLIN, +}; + +/* Edge triggered: only a wakeup reports the request after the mount */ +FIXTURE_VARIANT_ADD(mount, epoll_et) { + .events =3D EPOLLIN | EPOLLET, +}; + +/* The forwarded wakeup has to reach an exclusive waiter too */ +FIXTURE_VARIANT_ADD(mount, epoll_excl) { + .events =3D EPOLLIN | EPOLLEXCLUSIVE, +}; + +FIXTURE_VARIANT_ADD(mount, io_uring) { +}; + +static int write_file(const char *path, const char *val) +{ + int fd =3D open(path, O_WRONLY); + int ret =3D fd < 0 ? -1 : write(fd, val, strlen(val)); + + if (fd >=3D 0) + close(fd); + return ret =3D=3D (int)strlen(val) ? 0 : -1; +} + +FIXTURE_SETUP(mount) +{ + uid_t uid =3D getuid(); + gid_t gid =3D getgid(); + char map[32]; + + snprintf(map, sizeof(map), "0 %u 1", uid); + if (unshare(CLONE_NEWUSER | CLONE_NEWNS) || + write_file("/proc/self/setgroups", "deny") || + write_file("/proc/self/uid_map", map)) + SKIP(return, "no user namespace: %s", strerror(errno)); + snprintf(map, sizeof(map), "0 %u 1", gid); + ASSERT_EQ(0, write_file("/proc/self/gid_map", map)); + ASSERT_EQ(0, mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL)); + ASSERT_EQ(0, mount("tmpfs", "/tmp", "tmpfs", 0, NULL)); + ASSERT_EQ(0, mkdir(MNT, 0755)); + self->epfd =3D -1; + self->r.fd =3D -1; + self->fd =3D open_dev(_metadata, true); +} + +FIXTURE_TEARDOWN(mount) +{ + umount2(MNT, MNT_DETACH); + if (self->epfd >=3D 0) + close(self->epfd); + ring_exit(&self->r); + if (self->fd >=3D 0) + close(self->fd); +} + +static void *do_mount(void *arg) +{ + FIXTURE_DATA(mount) * self =3D arg; + char opts[64]; + + snprintf(opts, sizeof(opts), + "fd=3D%d,rootmode=3D40000,user_id=3D0,group_id=3D0", self->fd); + self->err =3D mount("fuse", MNT, "fuse", 0, opts) ? errno : 0; + return NULL; +} + +static void *do_getxattr(void *arg) +{ + FIXTURE_DATA(mount) * self =3D arg; + char buf[16]; + + self->err =3D getxattr(MNT, "user.x", buf, sizeof(buf)) < 0 ? errno : 0; + return NULL; +} + +/* Answer the queued requests: FUSE_INIT, and -ENODATA for the rest. */ +static void serve(struct __test_metadata *const _metadata, int fd) +{ + struct fuse_init_out init =3D { + .major =3D FUSE_KERNEL_VERSION, + .minor =3D FUSE_KERNEL_MINOR_VERSION, + .max_write =3D 4096, + }; + __u64 buf[FUSE_MIN_READ_BUFFER / sizeof(__u64)]; + struct fuse_in_header *in =3D (void *)buf; + struct fuse_out_header out; + struct iovec iov[2] =3D { { &out, sizeof(out) }, { &init, sizeof(init) } = }; + int n; + + while (read(fd, buf, sizeof(buf)) >=3D (ssize_t)sizeof(*in)) { + n =3D in->opcode =3D=3D FUSE_INIT ? 2 : 1; + out.unique =3D in->unique; + out.error =3D n =3D=3D 2 ? 0 : -ENODATA; + out.len =3D sizeof(out) + (n =3D=3D 2 ? sizeof(init) : 0); + ASSERT_EQ((ssize_t)out.len, writev(fd, iov, n)); + } +} + +/* Wait up to @ms for the waiter armed before the mount; return its events= . */ +static int wait_event(FIXTURE_DATA(mount) * self, int ms) +{ + struct epoll_event ev; + int res; + + if (self->epfd >=3D 0) + return epoll_wait(self->epfd, &ev, 1, ms) =3D=3D 1 ? ev.events : 0; + return ring_cqe(&self->r, ms, &res) ? res : 0; +} + +TEST_F_TIMEOUT(mount, wake, 5) +{ + struct epoll_event ev =3D { .events =3D variant->events }; + pthread_t thread; + + /* Arm the waiter before the mount */ + if (variant->events) { + self->epfd =3D epoll_create1(0); + ASSERT_LE(0, self->epfd); + ASSERT_EQ(0, epoll_ctl(self->epfd, EPOLL_CTL_ADD, self->fd, &ev)); + } else { + struct io_uring_sqe *sqe; + + if (ring_init(&self->r, 4)) + SKIP(return, "io_uring_setup: %s", strerror(errno)); + sqe =3D ring_sqe(&self->r); + prep(sqe, IORING_OP_POLL_ADD, self->fd); + sqe->len =3D IORING_POLL_ADD_MULTI; + ASSERT_EQ(1, ring_submit(&self->r)); + } + + /* mount(2) waits for the reply to FUSE_INIT */ + ASSERT_EQ(0, pthread_create(&thread, NULL, do_mount, self)); + ASSERT_EQ(POLLIN, wait_event(self, 1000)); + serve(_metadata, self->fd); + ASSERT_EQ(0, pthread_join(thread, NULL)); + ASSERT_EQ(0, self->err); + + /* Drain any leftover mount events before testing a new request */ + while (wait_event(self, 100)) + serve(_metadata, self->fd); + + /* A request after the mount, without arming the waiter again */ + ASSERT_EQ(0, pthread_create(&thread, NULL, do_getxattr, self)); + ASSERT_EQ(POLLIN, wait_event(self, 1000)); + serve(_metadata, self->fd); + ASSERT_EQ(0, pthread_join(thread, NULL)); + ASSERT_EQ(ENODATA, self->err); +} + +TEST_HARNESS_MAIN --=20 2.56.1