From patchwork Wed Apr 23 08:52:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 2076053 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=mail.ozlabs.org; envelope-from=srs0=fpxl=xj=vger.kernel.org=linux-ext4+bounces-7427-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4ZjCqn2kk7z1yMm for ; Wed, 23 Apr 2025 19:05:25 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4ZjCr7019Vz4xN6 for ; Wed, 23 Apr 2025 19:05:43 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4ZjCr674Yfz4xNs; Wed, 23 Apr 2025 19:05:42 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip="2604:1380:45e3:2400::1" arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1745399142; cv=pass; b=Hu8916aSvddkd9WO2oEYn/wvppVNrmVgYgI8IGMVHCoj79/kSbVldqJ8hsoRj1pM0Bp6Gm8BGGhBKjNIztGf6tHMYm58bMIBHn3YufTxETmtRCvAfKPldLUorZCGU6tnr7YhwADcK4xsyo1vDL+aswz2PPcVVH/C8uYs/tJKQZ6UvW7Q/EzcgUvs8SbGW+CJbdxC34BpXFj7DWHAE0swByW/FJUItOmSuG4wL5aNgFPoMZoBNXGcr0qPBlxtjAVSuXTyic7sYYVPRkGHzgEAewz/Rwmh0/OsylV9qped4yC0AsmV+yWkhtgExZO/p4Pz7c/8IUN2CtdwagSiKALEcQ== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1745399142; c=relaxed/relaxed; bh=gghKq7UAszh1Q4Owt3tzqHoZLpUdXBVfa2P93uTQots=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jB7bf/LLAYvTS+xLYUc4MPB+umym8sWHYKopjBFo2Xv77zrVvBUTgxjkJLm5b6GBuL2wWxQAWwM4gfoQ7eykerAabHHFAbp/OD/F640b5DJDL/GFLqTQvDuTXrW4T8zZSQiX28Ie2gE9VZYeDk7LeaSevLnZtWmCDMZ5WSWTNYezb6kOp/vsWlqjLYd9sfSSqjBknOQkhStwIEuhzd2CWLSTqb+XTKRpeAhcvZ5dyGSC4NWA5Vr8Iyf7D4VvkPxdgHCUfUi8O6P2vOmAoKWY0p9qGFmudkWFiEUWy/f+P4YRrxFsHPlxK2xKYeomLdy60VgV1yO+EQgjzq4m0D8MaA== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: gandalf.ozlabs.org; spf=pass smtp.mailfrom=vger.kernel.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4ZjCr35Jqrz4xN6 for ; Wed, 23 Apr 2025 19:05:39 +1000 (AEST) Received: from smtp.subspace.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 6A3AA3BC8D4 for ; Wed, 23 Apr 2025 09:05:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7387026739B; Wed, 23 Apr 2025 09:03:35 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25EF6242D80; Wed, 23 Apr 2025 09:03:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745399015; cv=none; b=coDnePtzWyuQ9E6zDdZuUUZsmbV3K3v5n0dwdZsGD+fu8t0VaKnNMEVsd89PuztN3MXDBlCIWwOk0I3/Ks8ir9JocVk2HLLpgusrBWsihx37yoog+ZInqBL94uN6rakE3BSZotpxPzFOYgBRHn6F3w7REmLUqbXH3IVeQ4wAFYM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745399015; c=relaxed/simple; bh=WKTlVWm2pLhYKYsfki9QxTLxFfgKRro3jYHwiIaL/e0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YWbDEid2F+YukSP0Z1YZkguaszwnY29gkyMTUYiCSxDpfdTnm1rRnsV6IiFEJ/us6corTwdCL1M+L0yfZBPVVdWP+Lq/sYlXDwv5UE4flQ7M4Ll7Cjh4PokoONbp7DiarV0TUTWsrdDerKba9JwQVznMKW2CkdM+s7UWlHXrS0Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=none smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4ZjCmy1syNz4f3lDq; Wed, 23 Apr 2025 17:02:58 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.252]) by mail.maildlp.com (Postfix) with ESMTP id B76DB1A1D33; Wed, 23 Apr 2025 17:03:23 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.112.188]) by APP3 (Coremail) with SMTP id _Ch0CgAXacPQrAhoJkGrKA--.8976S11; Wed, 23 Apr 2025 17:03:23 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, libaokun1@huawei.com, yukuai3@huawei.com, yangerkun@huawei.com Subject: [PATCH 7/9] ext4: introduce ext4_check_map_extents_env() debug helper Date: Wed, 23 Apr 2025 16:52:55 +0800 Message-ID: <20250423085257.122685-8-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20250423085257.122685-1-yi.zhang@huaweicloud.com> References: <20250423085257.122685-1-yi.zhang@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: _Ch0CgAXacPQrAhoJkGrKA--.8976S11 X-Coremail-Antispam: 1UD129KBjvJXoW7Aw1kGw1UKrykXF1DWF4DArb_yoW5JFW8pr 98KFy5Gw1DX3s29w4xtw4UXr15ta48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Spam-Status: No, score=-0.1 required=5.0 tests=ARC_SIGNED,ARC_VALID, DMARC_MISSING,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=disabled version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on gandalf.ozlabs.org From: Zhang Yi Loading and modifying the extents tree and extent status tree without holding the inode's i_rwsem or the mapping's invalidate_lock is not permitted, except during the I/O writeback. Add a new debug helper ext4_check_map_extents_env(), it will verify whether the extent loading/modifying context is safe. Signed-off-by: Zhang Yi --- fs/ext4/ext4.h | 1 + fs/ext4/inode.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index ccc1de1e23a9..3b1bf52737e3 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2977,6 +2977,7 @@ static inline bool ext4_mb_cr_expensive(enum criteria cr) void ext4_inode_csum_set(struct inode *inode, struct ext4_inode *raw, struct ext4_inode_info *ei); int ext4_inode_is_fast_symlink(struct inode *inode); +void ext4_check_map_extents_env(struct inode *inode); struct buffer_head *ext4_getblk(handle_t *, struct inode *, ext4_lblk_t, int); struct buffer_head *ext4_bread(handle_t *, struct inode *, ext4_lblk_t, int); int ext4_bread_batch(struct inode *inode, ext4_lblk_t block, int bh_count, diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 51801f6d23ef..74c7a902a41d 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -416,6 +416,32 @@ int ext4_issue_zeroout(struct inode *inode, ext4_lblk_t lblk, ext4_fsblk_t pblk, return ret; } +/* + * For generic regular files, when updating the extent tree, Ext4 should + * hold the i_rwsem and invalidate_lock exclusively. This ensures + * exclusion against concurrent page faults, as well as reads and writes. + */ +#ifdef CONFIG_EXT4_DEBUG +void ext4_check_map_extents_env(struct inode *inode) +{ + if (EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY) + return; + + if (!S_ISREG(inode->i_mode) || + IS_NOQUOTA(inode) || IS_VERITY(inode) || + is_special_ino(inode->i_sb, inode->i_ino) || + (inode->i_state & (I_FREEING | I_WILL_FREE | I_NEW)) || + ext4_test_inode_flag(inode, EXT4_INODE_EA_INODE) || + ext4_verity_in_progress(inode)) + return; + + WARN_ON_ONCE(!inode_is_locked(inode) && + !rwsem_is_locked(&inode->i_mapping->invalidate_lock)); +} +#else +void ext4_check_map_extents_env(struct inode *inode) {} +#endif + #define check_block_validity(inode, map) \ __check_block_validity((inode), __func__, __LINE__, (map))