From patchwork Tue Dec 30 20:51:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1122 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767127978; bh=P/e0MwWim/zfhD1uFAWMBp9pZuwLUmAo4yvkuWXjVNs=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=R7PXe+uQGB9mPwra7RgJ9z1cbRTMOfXdpEujfTRJ9C9MHMWnyT7e0dwZTRICxzk7A ilvTmOiXI+tXCBYfxJPCJpo6+zeTMxkKjtR95hp0ggnvZiGgXG66Wwl6fu+jjQ08Ws 58U4xgTGD+rFBZOsLLgGau0HxtzMJAkMY2gB0RRcCQrYLD7rlhbrK8jPnQTanW2mvf ejwBPeEO7aHlbMmndnLVraSmD3ddKGb6XvAcivXU/pTFI6oHZLmD/fhPUXG23d2+Pq iTf5SVL7wIREHnSwiJBAdt7aMecOj3BMh/E/U3sWLzpfX9Z7r9AQHYAfhg9+hupzST DqB0pNZ4z9zvw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A237068F7D for ; Tue, 30 Dec 2025 13:52:58 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id byVFKz-XPoiy for ; Tue, 30 Dec 2025 13:52:58 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767127978; bh=P/e0MwWim/zfhD1uFAWMBp9pZuwLUmAo4yvkuWXjVNs=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=R7PXe+uQGB9mPwra7RgJ9z1cbRTMOfXdpEujfTRJ9C9MHMWnyT7e0dwZTRICxzk7A ilvTmOiXI+tXCBYfxJPCJpo6+zeTMxkKjtR95hp0ggnvZiGgXG66Wwl6fu+jjQ08Ws 58U4xgTGD+rFBZOsLLgGau0HxtzMJAkMY2gB0RRcCQrYLD7rlhbrK8jPnQTanW2mvf ejwBPeEO7aHlbMmndnLVraSmD3ddKGb6XvAcivXU/pTFI6oHZLmD/fhPUXG23d2+Pq iTf5SVL7wIREHnSwiJBAdt7aMecOj3BMh/E/U3sWLzpfX9Z7r9AQHYAfhg9+hupzST DqB0pNZ4z9zvw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8D3AE68C0D for ; Tue, 30 Dec 2025 13:52:58 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767127976; bh=Q47JGQ+7r5vj99HTZTUzkDrb04NWWczuHAeLsbNkEU8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BhfrSMfgendgmEt8Hxp6hk89WqqBAqdK7m3RQGncoZ9TgNA+lLKuOMmm7zGOaMCyu BjJYVQgkJwKu7e4UquzDs2D0xp8NItjmHS58fUMjkruVFhFgtGHTlQYQ94oekgY+g1 cO3Gi2rwFHmHJi71BBpRJAvUZuvFrP9hL7q33BuzjcsltEeXl/J/5ummrLhXisO0y9 I3hUSmS6rW7X4roM8M+8qHG4hyVH/IdFT99krAHBuoUhAHPRAkZCdLUcHLPnGQRsuF aQa93ehiMb0UdAt+rhZD5fpY6hRFfiv2wyVAf5A9c7Q5ysDQKIYCYejZrXGOATJNKV CV/TFFPbHczHg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 129FB68BF0; Tue, 30 Dec 2025 13:52:56 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id qEmRK4i7b51a; Tue, 30 Dec 2025 13:52:56 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767127970; bh=1nTqTqigSPyj2C772ocXdAvIPBGPENt9z1EgCPOjht4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kG6aOX961nWJFyK/UmhQtXCxvy7OxjXqbfR4cYGdvf7ihaLYWvA70sXWcTE/yoDuS Wmb3UCfUsPQc5MAj5HIquoJJn3AHsdavDbNzT3ABzPtsbGc+ScNCk7N9YInFcI02uF 2qYTgYZgrLoFkizCPdvus2T8oEhZNq7BWK/GiY+XalvZvJsQCq8iqZLjkRiqOxXzG6 smi9Vhz6ZsCAokn+xa4bwFoPHWu2omN2rBH5hM9hzw1dnsBLK9R7po6bcKBN7U3Glc 9SvcaRSjmhVQGLJrDjjwAQbwwsKLwU3QHiGNK6pme3wkYvghTMileo5pHDCV+RR00M EaidaKfHSKvXQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 2D4F864C8A; Tue, 30 Dec 2025 13:52:50 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 30 Dec 2025 13:51:50 -0700 Message-ID: <20251230205157.3383926-14-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251230205157.3383926-1-sjg@u-boot.org> References: <20251230205157.3383926-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: ZNX6P7FCCZJNBBNABKH2EAX64MV7FNKA X-Message-ID-Hash: ZNX6P7FCCZJNBBNABKH2EAX64MV7FNKA X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 13/14] linux: ext4l: Make cache init/exit functions reentrant for U-Boot List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass In U-Boot, filesystems may be mounted and unmounted multiple times in a single session. The ext4 cache initialization functions would fail on subsequent mounts because the caches were already initialized but pointers were not reset on exit. Add early return checks in init functions when already initialized, and reset cache pointers to NULL in exit functions to allow clean reinitialization. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- fs/ext4l/block_validity.c | 10 ++++++++++ fs/ext4l/extents_status.c | 6 ++++++ fs/ext4l/mballoc.c | 13 +++++++++++++ 3 files changed, 29 insertions(+) diff --git a/fs/ext4l/block_validity.c b/fs/ext4l/block_validity.c index bff72dcd27c..f110d7ef4c7 100644 --- a/fs/ext4l/block_validity.c +++ b/fs/ext4l/block_validity.c @@ -23,6 +23,12 @@ static struct kmem_cache *ext4_system_zone_cachep; int __init ext4_init_system_zone(void) { +#ifdef __UBOOT__ + /* Already initialized - skip in multiple mount scenarios */ + if (ext4_system_zone_cachep) + return 0; +#endif + ext4_system_zone_cachep = KMEM_CACHE(ext4_system_zone, 0); if (ext4_system_zone_cachep == NULL) return -ENOMEM; @@ -33,6 +39,10 @@ void ext4_exit_system_zone(void) { rcu_barrier(); kmem_cache_destroy(ext4_system_zone_cachep); +#ifdef __UBOOT__ + /* Reset pointer for clean reinitialization */ + ext4_system_zone_cachep = NULL; +#endif } static inline int can_merge(struct ext4_system_zone *entry1, diff --git a/fs/ext4l/extents_status.c b/fs/ext4l/extents_status.c index a3ab26624e7..f557c7c23c2 100644 --- a/fs/ext4l/extents_status.c +++ b/fs/ext4l/extents_status.c @@ -189,6 +189,12 @@ static int __revise_pending(struct inode *inode, ext4_lblk_t lblk, int __init ext4_init_es(void) { +#ifdef __UBOOT__ + /* Already initialized - skip in multiple mount scenarios */ + if (ext4_es_cachep) + return 0; +#endif + ext4_es_cachep = KMEM_CACHE(extent_status, SLAB_RECLAIM_ACCOUNT); if (ext4_es_cachep == NULL) return -ENOMEM; diff --git a/fs/ext4l/mballoc.c b/fs/ext4l/mballoc.c index 1d44d9b5cb6..47863efd1cb 100644 --- a/fs/ext4l/mballoc.c +++ b/fs/ext4l/mballoc.c @@ -4008,6 +4008,12 @@ void ext4_process_freed_data(struct super_block *sb, tid_t commit_tid) int __init ext4_init_mballoc(void) { +#ifdef __UBOOT__ + /* Already initialized - skip in multiple mount scenarios */ + if (ext4_pspace_cachep) + return 0; +#endif + ext4_pspace_cachep = KMEM_CACHE(ext4_prealloc_space, SLAB_RECLAIM_ACCOUNT); if (ext4_pspace_cachep == NULL) @@ -4044,6 +4050,13 @@ void ext4_exit_mballoc(void) kmem_cache_destroy(ext4_ac_cachep); kmem_cache_destroy(ext4_free_data_cachep); ext4_groupinfo_destroy_slabs(); + +#ifdef __UBOOT__ + /* Reset pointers for clean reinitialization */ + ext4_pspace_cachep = NULL; + ext4_ac_cachep = NULL; + ext4_free_data_cachep = NULL; +#endif } #define EXT4_MB_BITMAP_MARKED_CHECK 0x0001