From nobody Mon Jun 8 16:28:21 2026 Received: from mail-pj1-f67.google.com (mail-pj1-f67.google.com [209.85.216.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC22734389E for ; Thu, 28 May 2026 05:35:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.67 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779946561; cv=none; b=l9XasQA6vsxPR4Ep4V7x2GFrSFL5kmupaim47bQ/vTt5hJPEwjAT4AqpvKV14vV5eCnaDQd7M1ZyE+k1YCItxZtWnk5hZigaimWYnNAeaiP5n0Odk9r5PD1JLrJ4IFVbmkr1+nCLUnnDy2NkOCxo59xP0L4am4S66xGrihrDejY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779946561; c=relaxed/simple; bh=PmMBSSQOwrY3wTAPMf/51qrLvIqEO7uPriuBMkyldYY=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=CAz5IoC5BI8ml9GCaWwzPq0mo+c1tP/C9MUXVNUqXQwF5jeeHnEIe6aAWpBLPdtNM+i+PB8N5AtIYxFDpz6ckiiayLoUyoszQmobmmpvnPTwr/kJhCnIzqYPtFNDZlOM8pRpPuGUjSjPHBKvedbQ9pP98bW7V6OwfkrzIZx6EZA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BFlXWRDc; arc=none smtp.client-ip=209.85.216.67 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BFlXWRDc" Received: by mail-pj1-f67.google.com with SMTP id 98e67ed59e1d1-366139223e4so7622517a91.0 for ; Wed, 27 May 2026 22:35:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779946559; x=1780551359; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=jEcLv72SgXWCsu9Ow9ZF5fDTMQLKci6Ciiyqk71jcRE=; b=BFlXWRDcwDIKAcVVCwra6Vmt32P2MClVIDvC5zJfmnq7kCGWBvrRCgA4b1tOBzasCG TuujjjAP203qHQYvrmCK04/JbGhWUeAJCtUvFtVjZna5ODdgpvzuzAQKqkZguXJ2oylH 782c2xZobdxseFm12n6IoXghAavE09Dn6zPZniyez6I9wonCJ1R2Lb8BXsJ4xxye1OVj kCH4G2e92vDpTnhPxDv+pOL0MLBtIF0X84TAK/rVweXevZ/j+LpVX68//YAMBIdyosSw jj54Wb7SFA8k3b0G5Aran+Vya5Qwh5hRNoJevvT4kZ2ReTiUrS1bch8dM4yBe4/HhwyH hUYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779946559; x=1780551359; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=jEcLv72SgXWCsu9Ow9ZF5fDTMQLKci6Ciiyqk71jcRE=; b=ivIuhOft/TiuPmFS6N+IOfkA69quP8TPVpeQKEE4MgGyrSqDmLz1sTD2mItPyleEbj brZxBtKjmq++78sqOT+qRxUMgUpKjnG8Odfvla0s25Hj6xz2yWyCR0W9bR+jlYAMx0QC u3Bnc6Nzdm55WN1Ok5YNdI7ceHwJPVLYusHbTFOahNAWHZEGbLD4Ku9n8ocotTNRafl9 rlJzsIMEyCA/XyP1dU5/cRlrvKMdvrYcb7zO9ojtdSy4tK0cwgeJ/6S7mWqo2Qsjtlui bAhj5WP31TfuXdqPIXIfDiVve1iaT0ajQoOnbVtYh+uF0wi3b8l4jexEM7yncxshiiJw qJig== X-Forwarded-Encrypted: i=1; AFNElJ+g7YOgFRtlWOqN68Cc9QWDGlABcDlwguC8MXDAzR0I9gBONQHqJfOhV4wzsyiwSAepl7GM+xOFP2LhjtM=@vger.kernel.org X-Gm-Message-State: AOJu0YwBZ5z/6EDpSycGQ/4xD0xjBocjJkMCMnr6CFzf8J3Nagy+BkMp OHT0XI7B4QB2Q1e3WNzMgmcYVIbpRFfrFMuEA6P+BCbYVGJoaah8NtP221/uB/XefQY2/w== X-Gm-Gg: Acq92OGirdwTQwbau13rHp0uH9hPSCaJgzJnqEukgf5HRmzPYiOvtNqbnkf4o+5DtFW ZWKt0sRUlgXC5x+26julBtug0RU06uhB3SoLpfOoS3WWCk8+k5uA6is3tYqyoeM9XuoKxI+nhm/ R9OREs2lkzQQZ/wPTxOnexFnsTVqrBTiqJwx6keFGqSFrYeOnpWuPuCn2epCO1psoY2wjR+dZxh W+SyNFwgwjiyPTgJkVfIGDXp7TsNTTAPlCBkWFuRMSi73DDknCXgqLqkFMYXMUbj5tXJHI8zrFb tgMIl/Vfawuaub98AHIpsZs0YhMGP0sCsjgoAxOFwpbdEDp+B7CbO+Nd4+BufavPKYjoZTB9rzO ZHN+3eoNiUHG1iHLyfQT/ZUUAQnlY6+6giB1vk/18X+H/qW2B0uXv3sx8YWEQNT1P/WmA8Lajwe A5LkVGwQ3WCIW2WrpOkJCqcUCwx2tTJGZhWbr4YP96Xw== X-Received: by 2002:a17:90b:4c50:b0:369:d704:d944 with SMTP id 98e67ed59e1d1-36a6741f011mr24463407a91.4.1779946559118; Wed, 27 May 2026 22:35:59 -0700 (PDT) Received: from localhost ([111.228.63.84]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-36b7e7f99basm355720a91.3.2026.05.27.22.35.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2026 22:35:58 -0700 (PDT) From: Zhang Cen To: Carlos Maiolino Cc: linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, Christoph Hellwig , zerocling0077@gmail.com, 2045gemini@gmail.com, Zhang Cen Subject: [PATCH v2] xfs: drain inodegc before quota teardown on mount failure Date: Thu, 28 May 2026 13:35:54 +0800 Message-Id: <20260528053554.3047829-1-rollkingzzc@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" xfs_mountfs() starts background inodegc before mount completion. If a later setup step fails after quota setup, the failure unwind can destroy quota state while an inodegc worker is still able to resume xfs_inactive(). There are two related windows. First, out_agresv can still call xfs_qm_unmount_quotas() while m_qflags allow dqattach, so dqget can still need quota inodes that are being released. Second, failures after xfs_qm_newmount() can destroy mp->m_quotainfo before inodegc has been drained, while xfs_qm_dqattach() can still follow m_qflags into the quota cache. Normal unmount and the quotacheck abort path already drain inodegc before quota teardown. Do the same for mount failure. Drain inodegc at out_agresv before dropping AG reservations and quota inodes. Add an out_qm_unmount label above out_rtunmount so failures after xfs_qm_newmount() drain inodegc before xfs_qm_unmount() destroys quotainfo. This was reproduced in a KASAN QEMU setup that forced a late xfs_mountfs() failure after quota setup and widened the inodegc/dqattach window. The failure reported a general protection fault in xfs_qm_dqget_cache_lookup() from the inodegc worker path: xfs_qm_dqget_cache_lookup() xfs_qm_dqget_inode() xfs_qm_dqattach_locked() xfs_qm_dqattach() xfs_free_eofblocks() xfs_inactive() xfs_inodegc_worker() Fixes: ab23a7768739 ("xfs: per-cpu deferred inode inactivation queues") Signed-off-by: Zhang Cen --- v2: - Add an out_qm_unmount label above out_rtunmount, as Christoph suggested. - Keep the out_agresv inodegc drain before xfs_qm_unmount_quotas(). - Describe the KASAN/QEMU validation setup and fix trailer spacing. fs/xfs/xfs_mount.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index b24195f570cd8..39ce56e866060 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c @@ -1156,7 +1156,7 @@ xfs_mountfs( xfs_fs_unreserve_ag_blocks(mp); if (error) { xfs_warn(mp, "log mount finish failed"); - goto out_rtunmount; + goto out_qm_unmount; } =20 /* @@ -1174,7 +1174,7 @@ xfs_mountfs( if (xfs_has_zoned(mp)) { error =3D xfs_mount_zones(mp); if (error) - goto out_rtunmount; + goto out_qm_unmount; } =20 /* @@ -1228,16 +1228,29 @@ xfs_mountfs( return 0; =20 out_agresv: + /* + * Drain ordinary inodegc before we drop per-AG reservations or tear + * down quota state. Background inactivation can still attach dquots + * here, and dqget can still need the quota inodes. + */ + xfs_inodegc_flush(mp); xfs_fs_unreserve_ag_blocks(mp); xfs_qm_unmount_quotas(mp); if (xfs_has_zoned(mp)) xfs_unmount_zones(mp); + out_qm_unmount: + /* + * xfs_qm_newmount() can bring quota inodes into the mount. Drain + * inodegc before destroying quotainfo because background inactivation + * can still attach dquots. + */ + xfs_inodegc_flush(mp); + /* Clean out dquots that might be in memory after quotacheck. */ + xfs_qm_unmount(mp); out_rtunmount: xfs_rtunmount_inodes(mp); out_rele_rip: xfs_irele(rip); - /* Clean out dquots that might be in memory after quotacheck. */ - xfs_qm_unmount(mp); out_free_metadir: if (mp->m_metadirip) xfs_irele(mp->m_metadirip); base-commit: eb3f4b7426cfd2b79d65b7d37155480b32259a11 --=20 2.43.0