From nobody Thu Apr 30 08:26:49 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22236C433EF for ; Wed, 1 Jun 2022 01:11:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229849AbiFABL3 (ORCPT ); Tue, 31 May 2022 21:11:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348905AbiFABLW (ORCPT ); Tue, 31 May 2022 21:11:22 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7220B941B4 for ; Tue, 31 May 2022 18:11:21 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id e11so515095pfj.5 for ; Tue, 31 May 2022 18:11:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6zB4k8HCgWXfZMWhhHx3oaP+QO4uDjlOYW5CoGqwerk=; b=Lbq7WXgQ/WC3otO2Va6VnCJPaH/mjOaNwN17SFcjO6TTUjkrrWkXKU4/I7E8aSOylz rygmw+G6kHV1S7NEhQtCElRekSTDNEoEdDkORdvEPnh5Iri8rR/f2iuW1o+F2zc6bU/o C0/HWydp8AK1kopJfiZ4dy+RMO8dwKo1J5t3k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6zB4k8HCgWXfZMWhhHx3oaP+QO4uDjlOYW5CoGqwerk=; b=KP24JWiElAzdb8WBot+SH6Li3sbtWRLwDXZiLqXzjdvsGASY1B6MvP233Ky2qRjEgk +VgmCYSF8ysnT1HZbMy9aa9H+u6yjEFbqtughTRmit7Cl61H+ZQ84fRjncWGJbGrA/Kh CK6JQ6wZTrdina9bpxDUyyNyCrzpVMI6jToba0VB9frZkVBecWI3rtRC1QP73Ly56kEQ 3K/M3o9SgFkn5j1nrT4CNvP9R1NNpnCCh5S5szvPkt2kihm6DEuzMs64akfNCYRiFkEl UN1znb2oLQ5KSKtQ3yZ2F/WzoVqDKpqeSPq/tJDtrdnKQgZDpdgeMRKPBCFqE+mwjRV+ 8cLQ== X-Gm-Message-State: AOAM531jHplUC1A7q39Gm5wamSJeck3Eb5skZBGJ1rEdnKMariT1y8qg cdtFEidYeAmKxujZTFNFwgG8Qg== X-Google-Smtp-Source: ABdhPJww89xHjaZSrTlsmpVQ0UyZtfG7Ef/34KraF0X8f2jl92sSxYe4IW8cr5SOURKUegrj11fg8A== X-Received: by 2002:a63:401:0:b0:3fc:8810:f0ae with SMTP id 1-20020a630401000000b003fc8810f0aemr2585858pge.335.1654045880991; Tue, 31 May 2022 18:11:20 -0700 (PDT) Received: from dlunevwfh.roam.corp.google.com (n122-107-196-14.sbr2.nsw.optusnet.com.au. [122.107.196.14]) by smtp.gmail.com with ESMTPSA id mi16-20020a17090b4b5000b001df6173700dsm2621916pjb.49.2022.05.31.18.11.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 May 2022 18:11:20 -0700 (PDT) From: Daniil Lunev X-Google-Original-From: Daniil Lunev To: linux-fsdevel@vger.kernel.org, miklos@szeredi.hu, viro@zeniv.linux.org.uk, hch@infradead.org, tytso@mit.edu Cc: linux-kernel@vger.kernel.org, fuse-devel@lists.sourceforge.net, Daniil Lunev , Daniil Lunev Subject: [PATCH v4 1/2] fs/super: function to prevent super re-use Date: Wed, 1 Jun 2022 11:11:02 +1000 Message-Id: <20220601111059.v4.1.I0e579520b03aa244906b8fe2ef1ec63f2ab7eecf@changeid> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20220601011103.12681-1-dlunev@google.com> References: <20220601011103.12681-1-dlunev@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Daniil Lunev The function is to be called from filesystem-specific code to mark a superblock to be ignored by superblock test and thus never re-used. The function also unregisters bdi if the bdi is per-superblock to avoid collision if a new superblock is created to represent the filesystem. generic_shutdown_super() skips unregistering bdi for a retired superlock as it assumes retire function has already done it. Signed-off-by: Daniil Lunev Signed-off-by: Daniil Lunev Reviewed-by: Christoph Hellwig --- Changes in v4: - Simplify condition according to Christoph Hellwig's comments. Changes in v3: - Back to state tracking from v1 - Use s_iflag to mark superblocked ignored - Only unregister private bdi in retire, without freeing Changes in v2: - Remove super from list of superblocks instead of using a flag fs/super.c | 28 ++++++++++++++++++++++++++-- include/linux/fs.h | 2 ++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/fs/super.c b/fs/super.c index f1d4a193602d6..3fb9fc8d61160 100644 --- a/fs/super.c +++ b/fs/super.c @@ -422,6 +422,30 @@ bool trylock_super(struct super_block *sb) return false; } =20 +/** + * retire_super - prevernts superblock from being reused + * @sb: superblock to retire + * + * The function marks superblock to be ignored in superblock test, which + * prevents it from being reused for any new mounts. If the superblock has + * a private bdi, it also unregisters it, but doesn't reduce the refcount + * of the superblock to prevent potential races. The refcount is reduced + * by generic_shutdown_super(). The function can not be called concurrently + * with generic_shutdown_super(). It is safe to call the function multiple + * times, subsequent calls have no effect. + */ +void retire_super(struct super_block *sb) +{ + down_write(&sb->s_umount); + if (sb->s_iflags & SB_I_PERSB_BDI) { + bdi_unregister(sb->s_bdi); + sb->s_iflags &=3D ~SB_I_PERSB_BDI; + } + sb->s_iflags |=3D SB_I_RETIRED; + up_write(&sb->s_umount); +} +EXPORT_SYMBOL(retire_super); + /** * generic_shutdown_super - common helper for ->kill_sb() * @sb: superblock to kill @@ -1216,7 +1240,7 @@ static int set_bdev_super_fc(struct super_block *s, s= truct fs_context *fc) =20 static int test_bdev_super_fc(struct super_block *s, struct fs_context *fc) { - return s->s_bdev =3D=3D fc->sget_key; + return !(s->s_iflags & SB_I_RETIRED) && s->s_bdev =3D=3D fc->sget_key; } =20 /** @@ -1307,7 +1331,7 @@ EXPORT_SYMBOL(get_tree_bdev); =20 static int test_bdev_super(struct super_block *s, void *data) { - return (void *)s->s_bdev =3D=3D data; + return !(s->s_iflags & SB_I_RETIRED) && (void *)s->s_bdev =3D=3D data; } =20 struct dentry *mount_bdev(struct file_system_type *fs_type, diff --git a/include/linux/fs.h b/include/linux/fs.h index bbde95387a23a..ef392fd2361bd 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1411,6 +1411,7 @@ extern int send_sigurg(struct fown_struct *fown); #define SB_I_SKIP_SYNC 0x00000100 /* Skip superblock at global sync */ #define SB_I_PERSB_BDI 0x00000200 /* has a per-sb bdi */ #define SB_I_TS_EXPIRY_WARNED 0x00000400 /* warned about timestamp range e= xpiry */ +#define SB_I_RETIRED 0x00000800 /* superblock shouldn't be reused */ =20 /* Possible states of 'frozen' field */ enum { @@ -2424,6 +2425,7 @@ extern struct dentry *mount_nodev(struct file_system_= type *fs_type, int flags, void *data, int (*fill_super)(struct super_block *, void *, int)); extern struct dentry *mount_subtree(struct vfsmount *mnt, const char *path= ); +void retire_super(struct super_block *sb); void generic_shutdown_super(struct super_block *sb); void kill_block_super(struct super_block *sb); void kill_anon_super(struct super_block *sb); --=20 2.31.0 From nobody Thu Apr 30 08:26:49 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47F98C433FE for ; Wed, 1 Jun 2022 01:11:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348931AbiFABLf (ORCPT ); Tue, 31 May 2022 21:11:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348914AbiFABL2 (ORCPT ); Tue, 31 May 2022 21:11:28 -0400 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB3869548F for ; Tue, 31 May 2022 18:11:26 -0700 (PDT) Received: by mail-pg1-x52b.google.com with SMTP id v15so402365pgk.11 for ; Tue, 31 May 2022 18:11:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nKEUJeXWAGT71M4N/DTrrCo2nCewg6Tf9KzJevsB9XY=; b=m4J4YCPDnXF//qtjts865ZEuKBRqf0VgVqj8gZK53Befqo6FPRUTVnDwec4dQ580d9 aqJFMSXZjyHyKdqTbS6lLV0hIrBiojyaSD+b57dVyQTsRs5qzwshLrXr6e7DI22TdbpQ ygOKjK8SeE4jIxf2tqNA2rfo4UpBFDX2rRNg0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nKEUJeXWAGT71M4N/DTrrCo2nCewg6Tf9KzJevsB9XY=; b=KS7Zve2RQj0Z7RzNQIRzoZw+xWcGiAqza9GMm2HDS1gQfMIVtqFw5m8l0dxnwzR1O2 r8jwycfZYcgP5/idaC0lXneksIebiee1/pAzHVMsd09aaVwkJ2dGjiO/tIWAo/xTiEjc mx5BuNl7H9t51Jgro5p9Ms7ShQKPqXB+wgIIj9OQ858LZD3WiDBF8Bu8eAENgDaYKPD1 sby8m2vzvoyRZ/UXki4Tdy+EBOwkiBjBSzYFuV+1JRVRy6ycfQxbLeFLz3dIHkd1qY40 GZrJNhhu54E6G1Qz0RvyGqiYcToHrNl46YzYwsVkbN7xDH/BgWe3lY0fxDgjTkJ/Kr0E arIA== X-Gm-Message-State: AOAM533nKJoExHcBhfpFXYCFTCZx2KWA2NS8AaMbZiom0Nt/ZhS/6lMJ AQnl3CmC1ajA4QXomqLellxWyA== X-Google-Smtp-Source: ABdhPJynnTGiG4LmI3+NfkdP8fOwQQyaZS2a5FcA44p1Pbzas8YuxiUlcinQhaCxvItUIGBAXtUoYg== X-Received: by 2002:a05:6a00:15c5:b0:518:9848:4915 with SMTP id o5-20020a056a0015c500b0051898484915mr47269716pfu.62.1654045886479; Tue, 31 May 2022 18:11:26 -0700 (PDT) Received: from dlunevwfh.roam.corp.google.com (n122-107-196-14.sbr2.nsw.optusnet.com.au. [122.107.196.14]) by smtp.gmail.com with ESMTPSA id mi16-20020a17090b4b5000b001df6173700dsm2621916pjb.49.2022.05.31.18.11.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 May 2022 18:11:26 -0700 (PDT) From: Daniil Lunev X-Google-Original-From: Daniil Lunev To: linux-fsdevel@vger.kernel.org, miklos@szeredi.hu, viro@zeniv.linux.org.uk, hch@infradead.org, tytso@mit.edu Cc: linux-kernel@vger.kernel.org, fuse-devel@lists.sourceforge.net, Daniil Lunev , Daniil Lunev Subject: [PATCH v4 2/2] FUSE: Retire superblock on force unmount Date: Wed, 1 Jun 2022 11:11:03 +1000 Message-Id: <20220601111059.v4.2.I692165059274c30b59bed56940b54a573ccb46e4@changeid> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20220601011103.12681-1-dlunev@google.com> References: <20220601011103.12681-1-dlunev@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Daniil Lunev Force unmount of FUSE severes the connection with the user space, even if there are still open files. Subsequent remount tries to re-use the superblock held by the open files, which is meaningless in the FUSE case after disconnect - reused super block doesn't have userspace counterpart attached to it and is incapable of doing any IO. Signed-off-by: Daniil Lunev Signed-off-by: Daniil Lunev --- (no changes since v3) Changes in v3: - No changes Changes in v2: - Use an exported function instead of directly modifying superblock fs/fuse/inode.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index 8c0665c5dff88..8875361544b2a 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c @@ -476,8 +476,11 @@ static void fuse_umount_begin(struct super_block *sb) { struct fuse_conn *fc =3D get_fuse_conn_super(sb); =20 - if (!fc->no_force_umount) - fuse_abort_conn(fc); + if (fc->no_force_umount) + return; + + fuse_abort_conn(fc); + retire_super(sb); } =20 static void fuse_send_destroy(struct fuse_mount *fm) --=20 2.31.0