From patchwork Tue Dec 30 23:41:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1124 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=1767138271; bh=eJkwQowsObw3x9CBH8amL41EHcUgKNF6P6hKnmPL6Bw=; 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=maKyripvPRnpWSrzevFB0B/A8Saf7/OdVNGNsrnmzRoRklqckxvBwlNE+ne0KC1Og bEGhnFcVqFcH8BKMvbWxNh+7kvM75RtCwdOgznslEESN1yXdFxQD4oMH+TK5RmGbfB 2Ox6a/HStJ4JJTOVpLkRWlJJcCobM6xPKySycTTX7HmgdZq3UdPcmYUacd4BJ1UHKi uKwMY6ruqH3Y0pX0QE/VyynV81Hw1M5W2Z5bhuxQGNSLEy9AasoQHTXX1VK9qFuNAg MlAXINfpkWbdTr1QJGSGCOKcZ0DkrAezkdg3d9xU0FDPrkfsW93Zfm0miqB+F+XeFu KvyIIaJ9wXQ9Q== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id CB92368F8E for ; Tue, 30 Dec 2025 16:44:31 -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 iRG9TwrkaQHf for ; Tue, 30 Dec 2025 16:44:31 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138271; bh=eJkwQowsObw3x9CBH8amL41EHcUgKNF6P6hKnmPL6Bw=; 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=maKyripvPRnpWSrzevFB0B/A8Saf7/OdVNGNsrnmzRoRklqckxvBwlNE+ne0KC1Og bEGhnFcVqFcH8BKMvbWxNh+7kvM75RtCwdOgznslEESN1yXdFxQD4oMH+TK5RmGbfB 2Ox6a/HStJ4JJTOVpLkRWlJJcCobM6xPKySycTTX7HmgdZq3UdPcmYUacd4BJ1UHKi uKwMY6ruqH3Y0pX0QE/VyynV81Hw1M5W2Z5bhuxQGNSLEy9AasoQHTXX1VK9qFuNAg MlAXINfpkWbdTr1QJGSGCOKcZ0DkrAezkdg3d9xU0FDPrkfsW93Zfm0miqB+F+XeFu KvyIIaJ9wXQ9Q== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BA7DA68C58 for ; Tue, 30 Dec 2025 16:44:31 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138270; bh=mVfBM5jkVBotui2cJaLELhg07K6pG8OBlse5M2Gh8co=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mXBYQuCbVCMb10ZNmEAKY8/NXvQz/256RHwbiLGgJjGzeonV9/lWUmaj5HV88fwFh VRNszOBeJQszE8onzmqnIZCtMyM4ZBkGQcPV9A0Pb1SmkosTZ2VPUyGocmSV63livU nQDYMcoqb2ioo3AEWFB/HO9K+DPg1EJpyWK1x1AvU9DAkccnT5nlSxE9RpDNfc4OH2 wFrB8U8JFRXo7DFamML7QXBzaN1yndowZskl78HlSU7LTwfeEXk0jIfEZVZNxyU3lM gFbE6lZWiS0+6T20cN3Y1w0h2HbsYi0W+pdnCEfx596q3BvcfV0Hd5z+HtL4GcwXuo is857fZCrWiOw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8A7D664E2A; Tue, 30 Dec 2025 16:44:30 -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 gay8AhsW1XNA; Tue, 30 Dec 2025 16:44:30 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138266; bh=9NjmARiCpteJAP7hcLoznYU0bXyC8s6MgweSeGYf0NE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MIXcEjOvEgA6mdbzCLfC8XHBm1KDQR6alXXkkGDG1OKSsiTP85n0i2wNabV0UwSvY hTYzZIIq9d9c4M2wZfqjFK4XpqJOuOOFkwl39IpXbMIYBSj3zLh9MR97PJOejJ9IJN V6P/XquVTqMaNH7Gkb/xuJL9+RixhtRy6Ni64GQny+ZegH3784P2UuRU4R5Foe3SwM Ik+jupaFmqO7jooQNqcTiZYcJKdriPggGPCZQ4jlYd5yv+6+Bh3ayOwJ3EfA/8nrxJ dYe/zNJl1OBo2AndXtBPttt7L7kWjfmPchc5YXUs0bV3C+dDOMt/v823FRyqX7waq6 WkG4YVBQBnyHQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 3D22A68C0F; Tue, 30 Dec 2025 16:44:26 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 30 Dec 2025 16:41:13 -0700 Message-ID: <20251230234134.906477-2-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251230234134.906477-1-sjg@u-boot.org> References: <20251230234134.906477-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: F2L7IRWDX3OE4XRRI6HZY7JB5D3DXEKD X-Message-ID-Hash: F2L7IRWDX3OE4XRRI6HZY7JB5D3DXEKD 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 X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 01/15] lib: Add CONFIG_LIB_KMEM_CACHE for full kmem_cache support 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 Add a Kconfig option to control whether full kmem_cache_free() and kmem_cache_destroy() implementations are provided in lib/linux_compat.c Most boards do not need these functions, so they can use simple inline stubs in slab.h. Subsystems like ext4 that require proper cache management can select CONFIG_LIB_KMEM_CACHE. Co-developed-by: Claude Signed-off-by: Simon Glass --- include/linux/slab.h | 27 ++++++++++++++++----------- lib/Kconfig | 8 ++++++++ lib/Makefile | 1 + lib/kmem_cache.c | 20 ++++++++++++++++++++ 4 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 lib/kmem_cache.c diff --git a/include/linux/slab.h b/include/linux/slab.h index 2b374641534..caaaa3d9e16 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -84,24 +84,19 @@ static inline void *krealloc(const void *p, size_t new_size, gfp_t flags) void *kmemdup(const void *src, size_t len, gfp_t gfp); -/* kmem_cache stubs */ +/* kmem_cache implementation / stubs */ struct kmem_cache { int sz; }; struct kmem_cache *get_mem(int element_sz); -#define kmem_cache_create(a, sz, c, d, e) ({ (void)(a); (void)(e); get_mem(sz); }) +#define kmem_cache_create(a, sz, c, d, e) get_mem(sz) void *kmem_cache_alloc(struct kmem_cache *obj, gfp_t flag); -static inline void *kmem_cache_zalloc(struct kmem_cache *obj, gfp_t flags) -{ - void *ret = kmem_cache_alloc(obj, flags); - - if (ret) - memset(ret, 0, obj->sz); - return ret; -} - +#if CONFIG_IS_ENABLED(LIB_KMEM_CACHE) +void kmem_cache_free(struct kmem_cache *cachep, void *obj); +void kmem_cache_destroy(struct kmem_cache *cachep); +#else static inline void kmem_cache_free(struct kmem_cache *cachep, void *obj) { free(obj); @@ -111,5 +106,15 @@ static inline void kmem_cache_destroy(struct kmem_cache *cachep) { free(cachep); } +#endif + +static inline void *kmem_cache_zalloc(struct kmem_cache *obj, gfp_t flags) +{ + void *ret = kmem_cache_alloc(obj, flags); + + if (ret) + memset(ret, 0, obj->sz); + return ret; +} #endif /* _LINUX_SLAB_H */ diff --git a/lib/Kconfig b/lib/Kconfig index 9c7eb27c392..5ddf8125766 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -396,6 +396,14 @@ config TPL_TINY_MEMSET config RBTREE bool +config LIB_KMEM_CACHE + bool "Enable full kmem_cache implementation" + help + Provide a proper kmem_cache implementation in lib/linux_compat.c + that tracks allocated objects. This is needed by subsystems like + ext4 that require cache management. When disabled, simple inline + stubs are used instead. + config BITREVERSE bool "Bit reverse library from Linux" diff --git a/lib/Makefile b/lib/Makefile index 15a43b2cc5e..01b967d46b7 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -135,6 +135,7 @@ obj-$(CONFIG_$(PHASE_)OF_LIBFDT) += fdtdec.o fdtdec_common.o fdt_print.o obj-y += hang.o obj-y += linux_compat.o obj-y += linux_string.o +obj-$(CONFIG_$(PHASE_)LIB_KMEM_CACHE) += kmem_cache.o obj-$(CONFIG_$(PHASE_)LMB) += lmb.o obj-y += membuf.o obj-$(CONFIG_REGEX) += slre.o diff --git a/lib/kmem_cache.c b/lib/kmem_cache.c new file mode 100644 index 00000000000..bff9329aa53 --- /dev/null +++ b/lib/kmem_cache.c @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * kmem_cache implementation for U-Boot + * + * Copyright 2025 Canonical Ltd + * Written by Simon Glass + */ + +#include +#include + +void kmem_cache_free(struct kmem_cache *cachep, void *obj) +{ + free(obj); +} + +void kmem_cache_destroy(struct kmem_cache *cachep) +{ + free(cachep); +} From patchwork Tue Dec 30 23:41:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1125 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=1767138276; bh=PF66alhrTgviiShEOSruerpcHIBzo17wyUZJV0IyPyI=; 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=hs2k/4pApUdC6o9g2lSVLWLncVq6BTexryU0AFKRmo+FLIjJKvqKMd0QZ7geYNwfC pBgrGY/v0bAYQb8LAb6oqFBHTq5gM7e/QD7cs3AY2/cWPaevy9CXLhgs6xqFIZ114x E+1+gVCWU5s4h5jyw21PAdBAM8rw/y28DK5J/Iur2MrWjU9d30TOxG+FwrohrBtIi7 +oVYFWhcTCJkPouW1viQSXH7ASRFItMcMXfoJhrAc3tQ+2DfbAu/l4EzPaIivxvcug D9Ya5TqQpRgSw87t2JyWis77N4pwgFuC2OcaYcx09sRiSgUKaJVJ2Q40BkCks/mWsS bmOBZ+iz/nDgA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A691968C0F for ; Tue, 30 Dec 2025 16:44:36 -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 wl6LQHcSA3lK for ; Tue, 30 Dec 2025 16:44:36 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138276; bh=PF66alhrTgviiShEOSruerpcHIBzo17wyUZJV0IyPyI=; 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=hs2k/4pApUdC6o9g2lSVLWLncVq6BTexryU0AFKRmo+FLIjJKvqKMd0QZ7geYNwfC pBgrGY/v0bAYQb8LAb6oqFBHTq5gM7e/QD7cs3AY2/cWPaevy9CXLhgs6xqFIZ114x E+1+gVCWU5s4h5jyw21PAdBAM8rw/y28DK5J/Iur2MrWjU9d30TOxG+FwrohrBtIi7 +oVYFWhcTCJkPouW1viQSXH7ASRFItMcMXfoJhrAc3tQ+2DfbAu/l4EzPaIivxvcug D9Ya5TqQpRgSw87t2JyWis77N4pwgFuC2OcaYcx09sRiSgUKaJVJ2Q40BkCks/mWsS bmOBZ+iz/nDgA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 93A1D68F6F for ; Tue, 30 Dec 2025 16:44:36 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138275; bh=A0AVBTomcXJmyx9sBpbjtSFSiwj3C835OYMLgeY+OmU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EOzsokFV8p2dCw+sTOKoKBapVoO5Hc/nz5DmmHmUYn9GXJuxKR9di0CMh8pEONRqD FwkOSq09EYyhkaAsSBlwaL82y2+ZCtaIVDLspxQc+GmLYQHJFll5FQsOqpcchnMPd3 1kojLX/nIrB4FrmyPNhPCAn+LYBKovVmG0VPhwP1+qrPLqkhlXTv5McAHmRhlXbYyk LkmDdotRZsY9OtPIPd1XK8m43w9Kai5LEFP6kDOIk1FWxE9GU5R84WWJGdWA4AGQD9 GpwrlO5m5ashFWV1CbuVoCofcrGk4U30X5sdEPwJTGhafak3f9dMlNIUM7q8seB5Tc 5pEbUmw6D6Ytw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 28CD464E2A; Tue, 30 Dec 2025 16:44:35 -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 ZIrYLbiS19kx; Tue, 30 Dec 2025 16:44:35 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138271; bh=Ahe+UVMIPCr+t3cn6WfnfxusFqC5106T3M3mqOuy1XI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gpSFTZdjGIThbbbA2/K5KASs24WsqHTwPtoVQANqloizlPNdlK5v7ia9yr4EYo1J0 yUMI1steD8cxi3n+VHQ2VbYd/Y50oEznYY77Zps3Q8E8tkNi3NIIvZBmPqHvrtaOlW TbexF0YTY/lhj1mXEmNm+VEXXHdPWfOmK1L3cv+LCF1SHgILvbATsY8CKrqOYD/Ev/ tKmdYn6x9AeMl49c7pxKII9wbAST+5MXVwbJ+WqxW8HAkuPCjeuQixbD8wXu4uMsL2 +1ih7Z9/4e4cQFcPHU1j4MQVsZ9kMYQ5y6JFTlGpcbKG813YF1LDGDV2rwNFq24O3U aCnn/h0L28Cfw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id CD53D68C0F; Tue, 30 Dec 2025 16:44:30 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 30 Dec 2025 16:41:14 -0700 Message-ID: <20251230234134.906477-3-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251230234134.906477-1-sjg@u-boot.org> References: <20251230234134.906477-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: WILBTTFNUICIIALOLUC3FAQWC4DA65L4 X-Message-ID-Hash: WILBTTFNUICIIALOLUC3FAQWC4DA65L4 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 02/15] ext4l: Add journal_head detection in bh_cache_clear 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 When debugging journal-cleanup issues, stale journal_head attachments on buffer_heads can cause crashes on subsequent mounts. Add detection logic in bh_cache_clear() to warn when a buffer_head still has a journal_head attached. This indicates the journal was not properly destroyed before unmount. Clear the JBD flag and pointer to prevent issues with subsequent mounts. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- fs/ext4l/support.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/fs/ext4l/support.c b/fs/ext4l/support.c index a046654ca54..127a3920c96 100644 --- a/fs/ext4l/support.c +++ b/fs/ext4l/support.c @@ -222,6 +222,29 @@ static void bh_cache_insert(struct buffer_head *bh) * * Called on unmount to free all cached buffers. */ +/** + * bh_clear_stale_jbd() - Clear stale journal_head from buffer_head + * @bh: buffer_head to check + * + * Check if the buffer still has journal_head attached. This should not happen + * if the journal was properly destroyed, but warn if it does to help debugging. + * Clear the JBD flag and b_private to prevent issues with subsequent mounts. + */ +static void bh_clear_stale_jbd(struct buffer_head *bh) +{ + if (buffer_jbd(bh)) { + log_err("bh %p block %llu still has JBD (b_private %p)\n", + bh, (unsigned long long)bh->b_blocknr, bh->b_private); + /* + * Clear the JBD flag and b_private to prevent issues. + * The journal_head itself will be freed when the + * journal_head cache is destroyed. + */ + clear_buffer_jbd(bh); + bh->b_private = NULL; + } +} + void bh_cache_clear(void) { int i; @@ -231,9 +254,12 @@ void bh_cache_clear(void) for (entry = bh_cache[i]; entry; entry = next) { next = entry->next; if (entry->bh) { + struct buffer_head *bh = entry->bh; + + bh_clear_stale_jbd(bh); /* Release the cache's reference */ - if (atomic_dec_and_test(&entry->bh->b_count)) - free_buffer_head(entry->bh); + if (atomic_dec_and_test(&bh->b_count)) + free_buffer_head(bh); } free(entry); } From patchwork Tue Dec 30 23:41:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1126 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=1767138279; bh=pq0gJyAnmaBvJbABY9B7XyOYVHPFtnaZXNJyupso39s=; 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=M1adhZteJ5D4Gl6bjwPyfWTCDGvggVtrtHkoF/F1iU8+i+TuLlUI6o1SJydqmNqDf lr7RosgqLI8YbqxUdzLlq3uf8k/xMQkRolvagoEYcBnFwhoT/Oab3tV+JhFd9dKQp7 Xl8nAnRE/LEvOCaKVtuCmxhhpZzZgdY/95r44Mg00AjkMLfM9ZBL+5VpnwGJVdAT1j 41gb2o1dlDYgl74RAvZbxhtfNkZV0S2HLucQKLqFsiStaREXR5i6y/iRXHDm3jg1BI DqRLRmVJXpa7pAViazcHCQFTrlsMpoU9BSi0kjekf5wPSmNgTli80BXGNJfj3/GcSb 5L7xpIR2j4eEg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3A47D64E2A for ; Tue, 30 Dec 2025 16:44:39 -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 mGY7wUKJ6IPR for ; Tue, 30 Dec 2025 16:44:39 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138277; bh=pq0gJyAnmaBvJbABY9B7XyOYVHPFtnaZXNJyupso39s=; 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=lSzvXD8TEaORxZjf7nyXis4Lx9pDFqsYUxk7WL3OSGMFXjbmQb2ZkFuQ/Lr2Gno9g p2vkzghliJqUYaE+89YjJiwb8cP9QmGO11dIfAm6B+kvhRBAWBGcNUTIprJCyYMiMx Yh2sRKurkFKSq+VXmoR3fNWCF7L/RmWKAimFcCpw0PZpUO1w9hC70QctTBe6U3/K65 hQVLzFK0a35ECa1EGJkjb5th2DUPVFTHOhDMt4r1l1sCWoyyklNeHBCXgtZR5To6sZ BubndY5IVtDPr5HgEXt8Y08VYiwY+9HwRaN/Q5f+KR2uhRkDqqnt1OJticVUMwu0Ez Yb26jq7+ho1aw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 21A8868F9A for ; Tue, 30 Dec 2025 16:44:37 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138275; bh=0BsDARb6etYCgGV1EOs4mrQNSxzeNJX8ds3JtjaVEpw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iThM5yBesUFHcbWTUfq/CRJlgiaCeQAbVAXSqDZRVfhq2U8XjHlOF4R5dMgxsU2lX lDQB6OJOhvWjsfn7X8G8Vx3alwEArqzuRsu5vrwpkmd8yMGiD1r16R1zSorAIccyX4 0/T9VtHyEZfOpbzCQYyby6k76fjJIv1Do5mWuT4VU3bLRCp9b2eCcki+wHtsxkqBWD RV/kUkkNa/Z6hpQN99EnHii14nbVz65eDHbJl5/PDJgSITW83UwbkLpCVwOyBArrWa 1t7B/spS1xDY50edetns8ehjOOyXlQNrU/r/oZpbn6F4ZhsA07I4A78fyV48CZUvm4 qvhxdex4kYBIA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id ED5A168C58; Tue, 30 Dec 2025 16:44:35 -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 bbxkggol46xo; Tue, 30 Dec 2025 16:44:35 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138275; bh=2RtOffHWcQUUOZfJ1n0Urfn8ZcxMpJUxEVazkaouakg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KB4Ubsbb6Sq6biIkR1lqrC65u9Z0nN8D40irbpefIw5ZlB8p6s0MBJVzIGH9sVqFt wzU68I5gu4GUk1aZmVL3mPqt6AVDpJE7A3ySqpoKFHfjFasNxQUL2pdN7mcn9Yay8W jhjZyNAhoTw19nbkQJBf8LFehvkJile2N+8ej5P9VtRhmSRedgIqk8Vdz6PlqAge+h 36rUxLRiOmmw4ED56MmtbU8VJHIqSsYmA3MawfasLrbdgBD4TJ/GArcTx4WBXOuicO gRFPDaX459IUXF4OHXU/2ZU/A5Nm8/hu+/ixhHpvqL4QQpLUPeRkfG+fYCOXMoMP+w A1B6y5IVsqtGQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 6B39B68C0F; Tue, 30 Dec 2025 16:44:35 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 30 Dec 2025 16:41:15 -0700 Message-ID: <20251230234134.906477-4-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251230234134.906477-1-sjg@u-boot.org> References: <20251230234134.906477-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: KZZHDAQLBR5LJD3N2MQOYMCLDKV4UNWB X-Message-ID-Hash: KZZHDAQLBR5LJD3N2MQOYMCLDKV4UNWB 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 X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 03/15] bitops: linux: Add fns() to find N'th set bit 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 Add the fns() function from Linux to find the N'th set bit in a word. This is needed by lib/find_bit.c which uses it in the FIND_NTH_BIT macro. Taken from Linux v6.19 Co-developed-by: Claude Signed-off-by: Simon Glass --- include/linux/bitops.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/linux/bitops.h b/include/linux/bitops.h index f826d7f3b34..86f7ee492b4 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -194,6 +194,19 @@ static inline unsigned long __ffs64(u64 word) return __ffs((unsigned long)word); } +/** + * fns - find N'th set bit in a word + * @word: The word to search + * @n: Bit to find + */ +static inline unsigned int fns(unsigned long word, unsigned int n) +{ + while (word && n--) + word &= word - 1; + + return word ? __ffs(word) : BITS_PER_LONG; +} + /** * __set_bit - Set a bit in memory * @nr: the bit to set From patchwork Tue Dec 30 23:41:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1127 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=1767138281; bh=8mDs2jyTtWzGrvzFWAhmGKxBW9KhsDOtZrrdgxvaN4U=; 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=KSKwSeLa7ZFapHTpsi0NSkYN73uj+ZjSB1cYs9l5AxN3r7hvscZdw4Okns+etLJjh XBjtw93be+7O7qax1ZIUr8UFXiNbSMzX/cB73s5tgnB7RthIFa4C00XJfKhJIbdFG7 tZhkLtVnC7On0jHeMEcku4mCEbIUCPCnoaNR+JUjqL3DN+r8uzwrdkhm+zehfzlPyI n3U2Ik1h6gJ+f07+S5jy5g8r8bspR8ROY0e1sN4wiH/orTEQkCPMOsR3wHFDEg9YbG aCeP/RullWkycvbbPp9P1fp8c6PIDdHYJQ37yz9SDmVMHvJaRSbjvi2h15lJV6gEcu xTrjHWnYv+LgA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8899B64E2A for ; Tue, 30 Dec 2025 16:44:41 -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 NPJQgBKewW21 for ; Tue, 30 Dec 2025 16:44:41 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138280; bh=8mDs2jyTtWzGrvzFWAhmGKxBW9KhsDOtZrrdgxvaN4U=; 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=kpWTFDsCyFGJuINCg79JhrAUmuN6TM4NinmneC6yulINYOG7u5c+ECOeGFK2AKG3n S+N4jcZ6xFNs3dJ6ycocJ4sDZd+EV+5D9lqaAjFNVVqj6BVIUvkH32B8phJknypi/y YFVHfEocq+sMU+wXdrjGZR0xUqpyqiG6aK24owZtyT4j2RojzCQx+bHKyhm1SL2BOl 3f95dYIthkXtnqcjzomsz0orxA/7CdlQLawgQ11qIjpKJzslYqPDCWm8mjtKI3EhJJ F0QaCvhUkc+d5drs31pWQ7HY4+GZUU+gPlpIyX3zgnFiu+J9Me1sJmFkSeFc6dWiVq pvyiTjhJAt7BQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8F5B268C57 for ; Tue, 30 Dec 2025 16:44:40 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138279; bh=nVkUVPV8+5eqWqeO4IW/c2UkmacjwYwDR+BqPnB49fM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iuWZXY2puPYr/tlGk7g2OLQ6CayIxzUSYGqeqvVB2vQQx1i2XN5U6te092RZvYlc6 vmoBLwfQSE4QZlCBAgiuWF62H8ZjtqOzwOlV1T8a0g7J6cAU9vWthcSdgB5Hav1dI0 rYzresdhGu4Wqz/pmNeH9fyFJLsXAJKZBwSQmZIzcOff6yhlZ4tlIoMmjbLrQ6B6ZA BsredPUvJJ+49uiv4OaKXE8fwKHur/i4XRNrQ4NeTRKJIQu6g9yrcexMsfTR3VmTba JPXwwYp+i8ZRFqqrOyA8cAVn3UUf6sOpE4Aq6zzg7yWEY7DQBgIaP+l9idqiGWE0Oo 5D5aLK6NkGD6Q== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2649668C58; Tue, 30 Dec 2025 16:44:39 -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 0aM4eeoVoB1k; Tue, 30 Dec 2025 16:44:39 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138276; bh=Iw0HHFgQaBMHVsjYLbovzm274otvH/tK6rjiUBOrnVI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ypb+ZkX8Mnk20toC+whfQIHPnivugzro+Mu5URO/JPYi3SQJmjtIX7o8F8lx4nJou PSX0Ew+Mi12r/LnejmYpYXPW49rRvc8oHwrsxfk3EqKnxpsSCcnjfOpy0iAeYzspY0 ijaTZv2EQ2k/bx35DeKFXSb5lm93MjnAmNt/M6o6EQSgR0osecqsCJDI+TUt3eCZ1e ZpASlWh1BDXCKHjhD5Rr18VMYugVLX1VERE5JfyJ9NrYFjsQ6wrE9kgXFOg5OtP7UQ 7SVDtQiUs4EmbDuGhpdihPt/mu3n2VLCiRlBckIh4lyLxIse/TldGQwWvBuvr6lB1H 8i+bTO5CL/9ew== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 3CB2764E2A; Tue, 30 Dec 2025 16:44:36 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 30 Dec 2025 16:41:16 -0700 Message-ID: <20251230234134.906477-5-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251230234134.906477-1-sjg@u-boot.org> References: <20251230234134.906477-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: PTKG7DG6ENH5FG56U4P5ZLCTL3DBN26R X-Message-ID-Hash: PTKG7DG6ENH5FG56U4P5ZLCTL3DBN26R 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 04/15] lib: linux: Add find_bit from Linux 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 Add lib/find_bit.c and include/linux/find.h from Linux v6.19, trimmed to include only the functions needed for ext4l: find_first_bit(), find_first_zero_bit(), find_next_bit(), find_next_zero_bit() and find_last_bit() The following items are removed from the Linux originals: - find.h: _and_bit, _andnot_bit, _or_bit, _nth_bit variants, wrap functions, clump8 functions, big-endian support, most for_each_... macros - find_bit.c: Corresponding implementations, random.h include Add wrapper functions matching sandbox's asm/bitops.h declarations (int return type, void* addr) that call the _find_* implementations. Build find_bit.o only for sandbox for now. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- include/linux/find.h | 176 +++++++++++++++++++++++++++++++++++++++++++ lib/Makefile | 1 + lib/find_bit.c | 142 ++++++++++++++++++++++++++++++++++ 3 files changed, 319 insertions(+) create mode 100644 include/linux/find.h create mode 100644 lib/find_bit.c diff --git a/include/linux/find.h b/include/linux/find.h new file mode 100644 index 00000000000..117d9015c57 --- /dev/null +++ b/include/linux/find.h @@ -0,0 +1,176 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LINUX_FIND_H_ +#define __LINUX_FIND_H_ + +#include + +unsigned long _find_next_bit(const unsigned long *addr1, unsigned long nbits, + unsigned long start); +unsigned long _find_next_zero_bit(const unsigned long *addr, unsigned long nbits, + unsigned long start); +extern unsigned long _find_first_bit(const unsigned long *addr, unsigned long size); +extern unsigned long _find_first_zero_bit(const unsigned long *addr, unsigned long size); +extern unsigned long _find_last_bit(const unsigned long *addr, unsigned long size); + +#ifndef find_next_bit +/** + * find_next_bit - find the next set bit in a memory region + * @addr: The address to base the search on + * @size: The bitmap size in bits + * @offset: The bitnumber to start searching at + * + * Returns the bit number for the next set bit + * If no bits are set, returns @size. + */ +static __always_inline +unsigned long find_next_bit(const unsigned long *addr, unsigned long size, + unsigned long offset) +{ + if (small_const_nbits(size)) { + unsigned long val; + + if (unlikely(offset >= size)) + return size; + + val = *addr & GENMASK(size - 1, offset); + return val ? __ffs(val) : size; + } + + return _find_next_bit(addr, size, offset); +} +#endif + +#ifndef find_next_zero_bit +/** + * find_next_zero_bit - find the next cleared bit in a memory region + * @addr: The address to base the search on + * @size: The bitmap size in bits + * @offset: The bitnumber to start searching at + * + * Returns the bit number of the next zero bit + * If no bits are zero, returns @size. + */ +static __always_inline +unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size, + unsigned long offset) +{ + if (small_const_nbits(size)) { + unsigned long val; + + if (unlikely(offset >= size)) + return size; + + val = *addr | ~GENMASK(size - 1, offset); + return val == ~0UL ? size : ffz(val); + } + + return _find_next_zero_bit(addr, size, offset); +} +#endif + +#ifndef find_first_bit +/** + * find_first_bit - find the first set bit in a memory region + * @addr: The address to start the search at + * @size: The maximum number of bits to search + * + * Returns the bit number of the first set bit. + * If no bits are set, returns @size. + */ +static __always_inline +unsigned long find_first_bit(const unsigned long *addr, unsigned long size) +{ + if (small_const_nbits(size)) { + unsigned long val = *addr & GENMASK(size - 1, 0); + + return val ? __ffs(val) : size; + } + + return _find_first_bit(addr, size); +} +#endif + +#ifndef find_first_zero_bit +/** + * find_first_zero_bit - find the first cleared bit in a memory region + * @addr: The address to start the search at + * @size: The maximum number of bits to search + * + * Returns the bit number of the first cleared bit. + * If no bits are zero, returns @size. + */ +static __always_inline +unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size) +{ + if (small_const_nbits(size)) { + unsigned long val = *addr | ~GENMASK(size - 1, 0); + + return val == ~0UL ? size : ffz(val); + } + + return _find_first_zero_bit(addr, size); +} +#endif + +#ifndef find_last_bit +/** + * find_last_bit - find the last set bit in a memory region + * @addr: The address to start the search at + * @size: The number of bits to search + * + * Returns the bit number of the last set bit, or size. + */ +static __always_inline +unsigned long find_last_bit(const unsigned long *addr, unsigned long size) +{ + if (small_const_nbits(size)) { + unsigned long val = *addr & GENMASK(size - 1, 0); + + return val ? __fls(val) : size; + } + + return _find_last_bit(addr, size); +} +#endif + +#if defined(__LITTLE_ENDIAN) + +static __always_inline +unsigned long find_next_zero_bit_le(const void *addr, unsigned long size, unsigned long offset) +{ + return find_next_zero_bit(addr, size, offset); +} + +static __always_inline +unsigned long find_next_bit_le(const void *addr, unsigned long size, unsigned long offset) +{ + return find_next_bit(addr, size, offset); +} + +static __always_inline +unsigned long find_first_zero_bit_le(const void *addr, unsigned long size) +{ + return find_first_zero_bit(addr, size); +} + +#else +#error "Please fix " +#endif + +#define for_each_set_bit(bit, addr, size) \ + for ((bit) = 0; (bit) = find_next_bit((addr), (size), (bit)), (bit) < (size); (bit)++) + +/* same as for_each_set_bit() but use bit as value to start with */ +#define for_each_set_bit_from(bit, addr, size) \ + for (; (bit) = find_next_bit((addr), (size), (bit)), (bit) < (size); (bit)++) + +#define for_each_clear_bit(bit, addr, size) \ + for ((bit) = 0; \ + (bit) = find_next_zero_bit((addr), (size), (bit)), (bit) < (size); \ + (bit)++) + +/* same as for_each_clear_bit() but use bit as value to start with */ +#define for_each_clear_bit_from(bit, addr, size) \ + for (; (bit) = find_next_zero_bit((addr), (size), (bit)), (bit) < (size); (bit)++) + +#endif /*__LINUX_FIND_H_ */ diff --git a/lib/Makefile b/lib/Makefile index 01b967d46b7..3890a827d1c 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -58,6 +58,7 @@ obj-$(CONFIG_PHYSMEM) += physmem.o obj-y += rc4.o obj-$(CONFIG_RBTREE) += rbtree.o obj-$(CONFIG_BITREVERSE) += bitrev.o +obj-$(CONFIG_SANDBOX) += find_bit.o obj-y += list_sort.o endif diff --git a/lib/find_bit.c b/lib/find_bit.c new file mode 100644 index 00000000000..762c5448d84 --- /dev/null +++ b/lib/find_bit.c @@ -0,0 +1,142 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* bit search implementation + * + * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved. + * Written by David Howells (dhowells@redhat.com) + * + * Copyright (C) 2008 IBM Corporation + * 'find_last_bit' is written by Rusty Russell + * (Inspired by David Howell's find_next_bit implementation) + * + * Rewritten by Yury Norov to decrease + * size and improve performance, 2015. + */ + +#include +#include +#include +#include + +/* + * Common helper for find_bit() function family + * @FETCH: The expression that fetches and pre-processes each word of bitmap(s) + * @MUNGE: The expression that post-processes a word containing found bit (may be empty) + * @size: The bitmap size in bits + */ +#define FIND_FIRST_BIT(FETCH, MUNGE, size) \ +({ \ + unsigned long idx, val, sz = (size); \ + \ + for (idx = 0; idx * BITS_PER_LONG < sz; idx++) { \ + val = (FETCH); \ + if (val) { \ + sz = min(idx * BITS_PER_LONG + __ffs(MUNGE(val)), sz); \ + break; \ + } \ + } \ + \ + sz; \ +}) + +/* + * Common helper for find_next_bit() function family + * @FETCH: The expression that fetches and pre-processes each word of bitmap(s) + * @MUNGE: The expression that post-processes a word containing found bit (may be empty) + * @size: The bitmap size in bits + * @start: The bitnumber to start searching at + */ +#define FIND_NEXT_BIT(FETCH, MUNGE, size, start) \ +({ \ + unsigned long mask, idx, tmp, sz = (size), __start = (start); \ + \ + if (unlikely(__start >= sz)) \ + goto out; \ + \ + mask = MUNGE(BITMAP_FIRST_WORD_MASK(__start)); \ + idx = __start / BITS_PER_LONG; \ + \ + for (tmp = (FETCH) & mask; !tmp; tmp = (FETCH)) { \ + if ((idx + 1) * BITS_PER_LONG >= sz) \ + goto out; \ + idx++; \ + } \ + \ + sz = min(idx * BITS_PER_LONG + __ffs(MUNGE(tmp)), sz); \ +out: \ + sz; \ +}) + +#ifndef find_first_bit +/* + * Find the first set bit in a memory region. + */ +unsigned long _find_first_bit(const unsigned long *addr, unsigned long size) +{ + return FIND_FIRST_BIT(addr[idx], /* nop */, size); +} +EXPORT_SYMBOL(_find_first_bit); +#endif + +#ifndef find_first_zero_bit +/* + * Find the first cleared bit in a memory region. + */ +unsigned long _find_first_zero_bit(const unsigned long *addr, unsigned long size) +{ + return FIND_FIRST_BIT(~addr[idx], /* nop */, size); +} +EXPORT_SYMBOL(_find_first_zero_bit); +#endif + +#ifndef find_next_bit +unsigned long _find_next_bit(const unsigned long *addr, unsigned long nbits, unsigned long start) +{ + return FIND_NEXT_BIT(addr[idx], /* nop */, nbits, start); +} +EXPORT_SYMBOL(_find_next_bit); +#endif + +#ifndef find_next_zero_bit +unsigned long _find_next_zero_bit(const unsigned long *addr, unsigned long nbits, + unsigned long start) +{ + return FIND_NEXT_BIT(~addr[idx], /* nop */, nbits, start); +} +EXPORT_SYMBOL(_find_next_zero_bit); +#endif + +#ifndef find_last_bit +unsigned long _find_last_bit(const unsigned long *addr, unsigned long size) +{ + if (size) { + unsigned long val = BITMAP_LAST_WORD_MASK(size); + unsigned long idx = (size-1) / BITS_PER_LONG; + + do { + val &= addr[idx]; + if (val) + return idx * BITS_PER_LONG + __fls(val); + + val = ~0ul; + } while (idx--); + } + return size; +} +EXPORT_SYMBOL(_find_last_bit); +#endif + +/* + * Wrapper functions matching sandbox's asm/bitops.h declarations. + * These provide the expected function signatures for sandbox platform. + */ +int find_first_zero_bit(void *addr, unsigned int size) +{ + return _find_first_zero_bit(addr, size); +} +EXPORT_SYMBOL(find_first_zero_bit); + +int find_next_zero_bit(void *addr, int size, int offset) +{ + return _find_next_zero_bit(addr, size, offset); +} +EXPORT_SYMBOL(find_next_zero_bit); From patchwork Tue Dec 30 23:41:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1128 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=1767138284; bh=sL9QrN41XlD0a/QSUL9jyp7XOq9KbnO388fxn1pj1ss=; 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=g/+1maKBp/yjOXyR06n+vhrGxrkIiDNI1bPITjnAB3I70sfDWQ24X13z6dj3+2qoB CX6OJROJflQ0R/563kdpL2WguadpCcHTEaxN+ySFIYBaO6eJMPuCQlZR9hCe6s9dXm P/u0w+Q53DnGQfgo8qGYrIfqm2YrTxN7qkkQuVCk9YMAwfcKUCRODC/X8tpmNS0wxT ofOxmgIIB0qHO4ZPKFmGJ29DopTrSy8rPxeroNXv89Q9Nj+aeR4QlHEUUoY0/pToR1 aGMTRkbxPcZlDPb8TuASCq3vcINusKt6OWqPKUGWo5vmbK7FrzcNtH3oDXLzD+Sa/t TlbScFTRXt0Hw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 156F068F6F for ; Tue, 30 Dec 2025 16:44:44 -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 mm2JmbxT6MgK for ; Tue, 30 Dec 2025 16:44:44 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138283; bh=sL9QrN41XlD0a/QSUL9jyp7XOq9KbnO388fxn1pj1ss=; 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=fuFi2216ZVr4TfOqJlbDEYaTR0QctA5jUVeqVgWBMpcCoTzIoIm5AUkI19I7dPGxp 6K2iyNMFyTPZQZxzpmPhlc1FN49OxQFTBQHi5TDTFtnI4qOq2qT8YgYo1zihAdWDNo WC/Zx85Ccf14LFqDhu20OznThKWTNMQcKKR9SDQzrwJ17smDEME7uVJ9RGoJTU+KhX GgssBZsJXzafwlgem5N+WAtKlHaUSagEujbnDAVSO0VO463tz/TaMDlPNzVS9pSBOD h6n4xtJO5VNH2bcu/7IrkyPhJDK8MgsUCkGWhgnntvExmNnL8O6hRuK9uo8oozN016 zWPP1bQyQJaNA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 36C4768F8E for ; Tue, 30 Dec 2025 16:44:43 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138281; bh=KptjRZhQUgbbo+LoGT+dvqeW3pZ1FTVYPQAg7iaSj2k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sGkYeSUt2Ni11TMujISuJG8VdYIq2KVzsF+EaTi0qwFchO6zv6v9ZXQ5rhMpjfrHF QA9knbvomuScEmy0BTDuIhyclDDTxvTc7qlxCFsVR6jx45IlTBSk3hosCzK/UDfRO0 8qiBvaZC/QIE178j6SoNnoF0fArVBtda9ntreLbwVAq8sjnyoEsgqZyGRA0bz/lwsi YfC7Mym9Q1PYYxis+ViPrMkNi84m96+By/SBMMC7TRqe3AxQkWmBD1JSWZYKw2um18 tehIotKEJQPdQlxe12CBTfFwO0pHzGqQIoS/oi6/LyH0fPDmbVPEir6xWr7IgtIlWQ uTYmZwN7PPRNg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 740AB68F9A; Tue, 30 Dec 2025 16:44:41 -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 EDEcoSfhAQlp; Tue, 30 Dec 2025 16:44:41 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138277; bh=m3MNrP7X+Bf3dBpiaNXpRl+SAEnXlyyUEffHaSLY6RA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dd1scIUF5iqMdMDd8J8rdXcnnUNLbMPT3ft3tZimOtxrcZGk5jl15A7u3vvH15V5D zJmXO/qH3QbBoTphCPs/nKNeobKWyhKJSW1HxxrjwxwHdZPdP397tdyQ/E6DvDkfsT 5eJOhnY3961mASsvBjtfwa/3e1eX0B1DLIvtRPIZzyHDeAuwvMb8PYt1bFeuJPThv2 fTfXJPgXU35N037VKOE7HO31p4qc0qVGtHCL7fAMsL+4M/FCk6UZwPZ8CJgD+riEKo ZGkIX/VDVMFNb8gVWiFizMKu2mtRbstK4eSfc8GTsoYQTLyHROveibJ/rw/8q/xncz 64K5XGgBZ2vwQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 6FF0B68F9C; Tue, 30 Dec 2025 16:44:37 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 30 Dec 2025 16:41:17 -0700 Message-ID: <20251230234134.906477-6-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251230234134.906477-1-sjg@u-boot.org> References: <20251230234134.906477-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 6OFDYMX4S76AZJYWB5D7CBVN56MSRHM2 X-Message-ID-Hash: 6OFDYMX4S76AZJYWB5D7CBVN56MSRHM2 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 05/15] ext4l: Implement little-endian bit operations 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 The ext4 block allocator uses little-endian bit operations on block bitmaps. Implement these operations by wrapping the existing set/test/clear_bit() functions. Add find_next_zero_bit() to search for free blocks in bitmaps. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- fs/ext4l/ext4_uboot.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 39bade68654..4ce98eeb7ed 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -349,13 +349,15 @@ struct buffer_head *sb_getblk(struct super_block *sb, sector_t block); * We implement them in interface.c for sandbox. */ -/* Little-endian bit operations */ -#define __set_bit_le(nr, addr) ((void)(nr), (void)(addr)) -#define test_bit_le(nr, addr) ({ (void)(nr); (void)(addr); 0; }) +/* Little-endian bit operations - use arch-provided find_next_zero_bit */ #define find_next_zero_bit_le(addr, size, offset) \ - ({ (void)(addr); (void)(size); (offset); }) -#define __test_and_clear_bit_le(nr, addr) ({ (void)(nr); (void)(addr); 0; }) -#define __test_and_set_bit_le(nr, addr) ({ (void)(nr); (void)(addr); 0; }) + find_next_zero_bit((void *)addr, size, offset) +#define __set_bit_le(nr, addr) set_bit(nr, addr) +#define test_bit_le(nr, addr) test_bit(nr, addr) +#define __test_and_clear_bit_le(nr, addr) \ + ({ int __old = test_bit(nr, addr); clear_bit(nr, addr); __old; }) +#define __test_and_set_bit_le(nr, addr) \ + ({ int __old = test_bit(nr, addr); set_bit(nr, addr); __old; }) /* KUNIT stub */ #define KUNIT_STATIC_STUB_REDIRECT(...) do { } while (0) From patchwork Tue Dec 30 23:41:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1129 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=1767138286; bh=4PCTJYYJbOYAz88+piofBVu0nJyiSLZWSWhkSuaxNf8=; 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=fwYePmJ5FZcXl5BkpX/N5QMZ8/f1nph6wcgDZp7IoG8mKVm8ol3RE2Qu64sMCoHc3 71r1KT0mDeRb4yfR2D0IeHL5oB2AKR/Abp9EDExekhjayg1KnShWERliZnPO5yLxIp A5UYMjjiuHGA9RjggxfZEjC+sMY5q3n+Cp6kFrQSgScCgneHovSyy20raPoHgaH9cZ gHwtRmVOujz48KgQpFYfOUtzIzjxO/8y2CDriKljVGTMD/YGk4Spt7iB5EPW4QIrlI 5PtWLME7aSOVqttUTapF6XOQ5zwaMTavpR5MB3mzfsyD7XLZSOotD11tbxVVHA00E8 TvhO5G+TMO87w== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 573A768F98 for ; Tue, 30 Dec 2025 16:44:46 -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 JuBz8Hg_8RRW for ; Tue, 30 Dec 2025 16:44:46 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138285; bh=4PCTJYYJbOYAz88+piofBVu0nJyiSLZWSWhkSuaxNf8=; 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=DgcAd+egyd105ISTxuHlqAXaVRZFyvLIkyhY5As9uCloWbdv2djQDXOIowHx02y7j yU2Wrsu+iPcWiBcJ0uvdnLEpnhDWLJi3SF32PlX7A7UZCoLVY7wtZlRhQt1VST41k1 Jmwexv12I4z6HoNxd/rPFh3xKmXXxZbnPw7cPYLAgFjBzFgjmYoICG+IwJSqxlp354 WbQ1hvoh08rgtj5UGUVm6O6q35mkBKm9ZuYaouJ0G+9bUROG+aaUKifeVFw8k7O47u SEc1oY9e7wfOhy2/I7A9DORBsLCyOx9NUYi0Rig8ZSMBF6qqj2svQZ9AKpLdt+DImd IEDtIfIZnox1Q== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id ABDFF68C58 for ; Tue, 30 Dec 2025 16:44:45 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138283; bh=4MqquyXNp4fSzjftIRy8RD/6j+OtXbubsPYhmytUWOo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Em68mztVpqlMsvZT3LiTwSe3zTtfFgghenI6DMi1c2m043KqhBnFVVD7OkT8ECM4+ bm6S/NkMgR0HDxNO1a1D9cN37cPs4LjJxFWrik5/GYRGielOu8qboDc3X0PpCmFOKG 8SRalRcUpRk6a8mlbPdZJ5MtzOevmtZasjVxdVHkTmXikrOwaMqRp3U5e1X81ZBLHr I4E87Plum1HDB1mqniXBxoLXCIWDP9wubs1/olI2oNBXjjWfpv0JF60EGL1+R8uvK4 kaYAO4+3qJfXsr4WEM85qeoW4UOEvw3hbi/nlT9vNm9X68YT8O3dK+Xt0bp+/V89pP NG7azPCpH7row== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id F005B68FA5; Tue, 30 Dec 2025 16:44:43 -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 Fp4t2ewPY9t4; Tue, 30 Dec 2025 16:44:43 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138278; bh=x+7Le9/q/2Owrj9Vaba6SDuGA34tcEWenxGCOy0ZWpE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dokoujL7DpR/m3PHX+x4ay69CgWVNFHZEa0nBKEEf5Jqt8IeDyatyNLHdQr3+neRf AwmhY/g3ZqosUZkBKltKhybKM0dwdj6ssbgY/ItJnn0Vig+0lfcSIKAV/bpmS4HAvj zun64Fum7EWatKoi3HVxyfxw463bewud4+xWpwpVg2rE686ZTTv3qPAf1uhbS4gmXM XtJAfnJZc6enFgDTba6TSQBdy64IcXF+sYRD4v75ciUsmS6ZvRve/uMbZd8wZBYUUE Z7tSHxuiOTIeNMv3jrFsd6gTr7JZF0wBsZV2kRYAh2ip9EWtcfqCbsibqAca3lYecg KtOTjVxJDptYw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 4667B68C06; Tue, 30 Dec 2025 16:44:38 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 30 Dec 2025 16:41:18 -0700 Message-ID: <20251230234134.906477-7-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251230234134.906477-1-sjg@u-boot.org> References: <20251230234134.906477-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: TLPAVDJK6XWTUBDHFCNAXS222ERD65H3 X-Message-ID-Hash: TLPAVDJK6XWTUBDHFCNAXS222ERD65H3 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 X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 06/15] ext4l: Adjust folio offset and mapping operations 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 The existing folios macros assume page-aligned memory, but U-Boot uses malloc'd buffers for simplicity. Update the macros accordinging: - offset_in_folio(): Calculate the offset from the folio's data pointer - bh_offset(): Calculate the actual offset within the folio - folio_set_bh(): Actually set b_folio and b_data - kmap_local_folio(): Return a pointer to folio data + offset Implement __filemap_get_folio(), folio_put() and folio_get() for folio-lifecycle management. Co-developed-by: Claude Signed-off-by: Simon Glass --- fs/ext4l/ext4_uboot.h | 33 ++++++++++-------- fs/ext4l/support.c | 80 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 14 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 4ce98eeb7ed..d7053c11d31 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -1247,16 +1247,21 @@ struct folio_batch { /* folio operations - stubs */ #define folio_mark_dirty(f) do { (void)(f); } while (0) -#define offset_in_folio(f, p) ({ (void)(f); (unsigned int)((unsigned long)(p) & (PAGE_SIZE - 1)); }) +/* + * offset_in_folio - calculate offset of pointer within folio's data + * In Linux this uses page alignment, but in U-Boot we use the folio's + * actual data pointer since our buffers are malloc'd. + */ +#define offset_in_folio(f, p) ((f) ? (unsigned int)((uintptr_t)(p) - (uintptr_t)(f)->data) : 0U) #define folio_buffers(f) ({ (void)(f); (struct buffer_head *)NULL; }) #define virt_to_folio(p) ({ (void)(p); (struct folio *)NULL; }) -#define folio_set_bh(bh, f, off) do { (void)(bh); (void)(f); (void)(off); } while (0) +#define folio_set_bh(bh, f, off) do { if ((bh) && (f)) { (bh)->b_folio = (f); (bh)->b_data = (char *)(f)->data + (off); } } while (0) #define memcpy_from_folio(dst, f, off, len) do { (void)(dst); (void)(f); (void)(off); (void)(len); } while (0) #define folio_test_uptodate(f) ({ (void)(f); 1; }) #define folio_pos(f) ({ (void)(f); 0LL; }) #define folio_size(f) ({ (void)(f); PAGE_SIZE; }) #define folio_unlock(f) do { (void)(f); } while (0) -#define folio_put(f) do { (void)(f); } while (0) +/* folio_put and folio_get are implemented in support.c */ #define folio_lock(f) do { (void)(f); } while (0) #define folio_batch_init(fb) do { (fb)->nr = 0; } while (0) #define filemap_get_folios(m, i, e, fb) ({ (void)(m); (void)(i); (void)(e); (void)(fb); 0U; }) @@ -1357,7 +1362,7 @@ static inline int generic_error_remove_folio(struct address_space *mapping, #define FGP_WRITEBEGIN (FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE) /* kmap/kunmap stubs for inline.c */ -#define kmap_local_folio(folio, off) ({ (void)(folio); (void)(off); (void *)NULL; }) +#define kmap_local_folio(folio, off) ((folio) ? (char *)(folio)->data + (off) : NULL) #define kunmap_local(addr) do { (void)(addr); } while (0) /* Folio zeroing stubs for inline.c */ @@ -1367,13 +1372,12 @@ static inline int generic_error_remove_folio(struct address_space *mapping, /* mapping_gfp_mask stub */ #define mapping_gfp_mask(m) ({ (void)(m); GFP_KERNEL; }) -/* __filemap_get_folio stub */ -static inline struct folio *__filemap_get_folio(struct address_space *mapping, - pgoff_t index, unsigned int fgp_flags, - gfp_t gfp) -{ - return NULL; -} +/* Folio operations - implemented in support.c */ +struct folio *__filemap_get_folio(struct address_space *mapping, + pgoff_t index, unsigned int fgp_flags, + gfp_t gfp); +void folio_put(struct folio *folio); +void folio_get(struct folio *folio); /* projid_t - project ID type */ typedef unsigned int projid_t; @@ -1545,7 +1549,9 @@ static inline char *d_path(const struct path *path, char *buf, int buflen) /* Buffer operations - additional */ #define getblk_unmovable(bdev, block, size) sb_getblk(bdev->bd_super, block) #define create_empty_buffers(f, s, flags) ({ (void)(f); (void)(s); (void)(flags); (struct buffer_head *)NULL; }) -#define bh_offset(bh) (0UL) +/* bh_offset returns offset of b_data within the folio */ +#define bh_offset(bh) ((bh)->b_folio ? \ + (unsigned long)((char *)(bh)->b_data - (char *)(bh)->b_folio->data) : 0UL) #define block_invalidate_folio(f, o, l) do { } while (0) #define block_write_end(pos, len, copied, folio) ({ (void)(pos); (void)(len); (void)(folio); (copied); }) #define block_dirty_folio(m, f) ({ (void)(m); (void)(f); false; }) @@ -2542,8 +2548,7 @@ static inline unsigned long ext4_find_next_bit_le(const void *addr, /* WARN_RATELIMIT - just evaluate condition, no warning in U-Boot */ #define WARN_RATELIMIT(condition, ...) (condition) -/* folio_get - increment folio refcount (no-op in U-Boot) */ -#define folio_get(f) do { (void)(f); } while (0) +/* folio_get - now implemented in support.c */ /* array_index_nospec - bounds checking without speculation (no-op in U-Boot) */ #define array_index_nospec(index, size) (index) diff --git a/fs/ext4l/support.c b/fs/ext4l/support.c index 127a3920c96..e5343aab198 100644 --- a/fs/ext4l/support.c +++ b/fs/ext4l/support.c @@ -626,3 +626,83 @@ int bh_read(struct buffer_head *bh, int flags) submit_bh(REQ_OP_READ | flags, bh); return buffer_uptodate(bh) ? 0 : -EIO; } + +/** + * __filemap_get_folio() - Get or create a folio for a mapping + * @mapping: The address_space to search + * @index: The page index + * @fgp_flags: Flags (FGP_CREAT to create if not found) + * @gfp: Memory allocation flags + * Return: Folio pointer or ERR_PTR on error + */ +struct folio *__filemap_get_folio(struct address_space *mapping, + pgoff_t index, unsigned int fgp_flags, + gfp_t gfp) +{ + struct folio *folio; + int i; + + /* Search for existing folio in cache */ + if (mapping) { + for (i = 0; i < mapping->folio_cache_count; i++) { + folio = mapping->folio_cache[i]; + if (folio && folio->index == index) { + /* Found existing folio, bump refcount */ + folio->_refcount++; + return folio; + } + } + } + + /* If not creating, return error */ + if (!(fgp_flags & FGP_CREAT)) + return ERR_PTR(-ENOENT); + + /* Create new folio */ + folio = kzalloc(sizeof(struct folio), gfp); + if (!folio) + return ERR_PTR(-ENOMEM); + + folio->data = kzalloc(PAGE_SIZE, gfp); + if (!folio->data) { + kfree(folio); + return ERR_PTR(-ENOMEM); + } + + folio->index = index; + folio->mapping = mapping; + folio->_refcount = 1; + + /* Add to cache if there's room */ + if (mapping && mapping->folio_cache_count < FOLIO_CACHE_MAX) { + mapping->folio_cache[mapping->folio_cache_count++] = folio; + /* Extra ref for cache */ + folio->_refcount++; + } + + return folio; +} + +/** + * folio_put() - Release a reference to a folio + * @folio: The folio to release + */ +void folio_put(struct folio *folio) +{ + if (!folio) + return; + if (--folio->_refcount > 0) + return; + kfree(folio->data); + kfree(folio); +} + +/** + * folio_get() - Acquire a reference to a folio + * @folio: The folio to reference + */ +void folio_get(struct folio *folio) +{ + if (folio) + folio->_refcount++; +} From patchwork Tue Dec 30 23:41:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1130 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=1767138290; bh=HIYEQ2cLBP1vhUzgYl/G/qfZiEUJGvPUyLyjMkpCFiA=; 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=UaFuN1Bp2x9hAH9i/xCnzVRov3Jsqnqq0EZQTXPakHA36HXq6VBvd1dap8rrY1JBm 0bsBBV+gcfGvu4Vw0qhpMNSLckzOdqbfv61TYcNv2M1dWtf18gnZ9+y4dSj7kd57K8 6ZkZs+4Wtn9SHUS2QtZGHsFL2aPR0nv6+89/SIjHPTd0C3LgoAy/vGpYndlzX5o08n 2fJU44x8mqJuIiB6/PjaosuhuedwUxFAEW1AIMxZkNdi6rlGm28k0WxILxhQOdUprR Zuc2NRzFGmLCk08b8xSplGpVG1kEVKhFQxltq74ZlzxmcJCWb3OxIajcrXCm5/HOYd qw72ln2hZLtfQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2956A68F71 for ; Tue, 30 Dec 2025 16:44:50 -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 ngkTej1oghF0 for ; Tue, 30 Dec 2025 16:44:50 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138290; bh=HIYEQ2cLBP1vhUzgYl/G/qfZiEUJGvPUyLyjMkpCFiA=; 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=UaFuN1Bp2x9hAH9i/xCnzVRov3Jsqnqq0EZQTXPakHA36HXq6VBvd1dap8rrY1JBm 0bsBBV+gcfGvu4Vw0qhpMNSLckzOdqbfv61TYcNv2M1dWtf18gnZ9+y4dSj7kd57K8 6ZkZs+4Wtn9SHUS2QtZGHsFL2aPR0nv6+89/SIjHPTd0C3LgoAy/vGpYndlzX5o08n 2fJU44x8mqJuIiB6/PjaosuhuedwUxFAEW1AIMxZkNdi6rlGm28k0WxILxhQOdUprR Zuc2NRzFGmLCk08b8xSplGpVG1kEVKhFQxltq74ZlzxmcJCWb3OxIajcrXCm5/HOYd qw72ln2hZLtfQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1940968C58 for ; Tue, 30 Dec 2025 16:44:50 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138289; bh=tICiIE0df2adDR2h+CQF5k1HB6CEJLHSEPA38YiIcFk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FLPrWNahaVzCzJ70MMSmwWfaoQ4ARVMN5PrzcCoQhAhDAZTJAxV0ADPRXXvXuF8ky KLkGlmHN2QcjTiuR/FD2jzeq+bsywodsE35nssLX/juXSE3YC8NWGtgEOUKiUErI/F v4G1xIHteXZcBmIzQXxOaDyRr2Uq+8dMEFod72hAlglRL9hVrhTiq2/LSSgU+EHzB1 w8l1zQR1nJJWwsYw961Qske5xHFE8MQXZINB2+6DXangOXR0DU2KPNlyoEtvXYjda0 +zjU9rliQgxbA/QIqLA6UIDMvC3r396GPRqcj02j8sM0feEcj/Es7H7/tXpwapLbCl ab9GNBkLN8fkA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2D02968C06; Tue, 30 Dec 2025 16:44:49 -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 bzZe81jUTjtR; Tue, 30 Dec 2025 16:44:49 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138283; bh=VJMdKqE9M9lt//FnnDlOasmFwFKKdBoj4MKQZp7MaYo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bDkp1q7mWrtOkM50W6tZ4sk/k2HtvBUSKTVudajMkKb6WbrnhIMgn1i7GyNTSAVXW pzA1gAeM07QG+ODgnku0I5OilGvTiY5nague0nuyeZWLvCgjziCZGMXXp1+f/dVdrr cL5ifiashTuTrFk4OX0A7SANsyFsmz8VE4xWT5Z9HaMQaSerws6ygCNmz5isjl73V9 e8tpzKMsOTxX6dTHy+BRVO+ARg1RNzjvpkxQqBpwhHx3m7dhl/qj0AQDDvYKbaWLHh C1tElaUanT8qaZG3YjOuVtNi/GaBqTEImEddww385hv7KIsI51FdHa0EBg6XyQa6Nc 2vk7Sldz4AloA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id E001F68C0F; Tue, 30 Dec 2025 16:44:42 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 30 Dec 2025 16:41:19 -0700 Message-ID: <20251230234134.906477-8-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251230234134.906477-1-sjg@u-boot.org> References: <20251230234134.906477-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: FVU7NL3U7ZWKUXOJR3RCC5HTSEVBJWCN X-Message-ID-Hash: FVU7NL3U7ZWKUXOJR3RCC5HTSEVBJWCN 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 X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 07/15] ext4l: Implement buffer write I/O and allocation 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 Add more complete buffer I/O infrastructure so that we can support writing to an ext4 filesystem. - end_buffer_write_sync(): I/O completion callback for sync writes - submit_bh(): Add the write path with b_end_io callback invocation - __getblk(): Allocate journal-descriptor buffers - free_buffer_head(): Don't free shared folios from shadow buffers - __brelse(): Only decrement refcount, don't free - bh_cache_sync(): Sync all dirty buffers to disk - sync_dirty_buffer()/mark_buffer_dirty(): Write buffer immediately The shadow-buffer fix is needed for jbd2 journaling: shadow buffers created by jbd2_journal_write_metadata_buffer() share their folio with the original buffer (as indicated by b_private). With this, the buffer I/O layer is ready for ext4 write support. Co-developed-by: Claude Signed-off-by: Simon Glass --- fs/ext4l/ext4_uboot.h | 15 +++-- fs/ext4l/support.c | 136 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 133 insertions(+), 18 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index d7053c11d31..f4831a9b5c2 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -328,8 +328,8 @@ extern struct user_namespace init_user_ns; /* Buffer operations - stubs */ #define wait_on_buffer(bh) do { } while (0) #define __bforget(bh) do { } while (0) -#define mark_buffer_dirty_inode(bh, i) do { } while (0) -#define mark_buffer_dirty(bh) do { } while (0) +#define mark_buffer_dirty_inode(bh, i) sync_dirty_buffer(bh) +#define mark_buffer_dirty(bh) sync_dirty_buffer(bh) #define lock_buffer(bh) set_buffer_locked(bh) #define unlock_buffer(bh) clear_buffer_locked(bh) struct buffer_head *sb_getblk(struct super_block *sb, sector_t block); @@ -399,7 +399,7 @@ struct buffer_head *sb_getblk(struct super_block *sb, sector_t block); /* Buffer cache operations */ #define sb_find_get_block(sb, block) ((struct buffer_head *)NULL) -#define sync_dirty_buffer(bh) ({ (void)(bh); 0; }) +#define sync_dirty_buffer(bh) submit_bh(REQ_OP_WRITE, bh) /* Time functions */ #define ktime_get_real_seconds() (0) @@ -2181,8 +2181,8 @@ struct blk_holder_ops { }; static const struct blk_holder_ops fs_holder_ops; -/* end_buffer_write_sync */ -#define end_buffer_write_sync NULL +/* end_buffer_write_sync - implemented in support.c */ +void end_buffer_write_sync(struct buffer_head *bh, int uptodate); /* File system management time flag */ #define FS_MGTIME 0 @@ -2886,7 +2886,9 @@ void free_buffer_head(struct buffer_head *bh); /* ext4l support functions (support.c) */ void ext4l_crc32c_init(void); void bh_cache_clear(void); +int bh_cache_sync(void); int ext4l_read_block(sector_t block, size_t size, void *buffer); +int ext4l_write_block(sector_t block, size_t size, void *buffer); /* ext4l interface functions (interface.c) */ struct blk_desc *ext4l_get_blk_dev(void); @@ -2921,7 +2923,8 @@ struct membuf *ext4l_get_msg_buf(void); /* JBD2 journal.c stubs */ struct buffer_head *alloc_buffer_head(gfp_t gfp_mask); -#define __getblk(bdev, block, size) ({ (void)(bdev); (void)(block); (void)(size); (struct buffer_head *)NULL; }) +struct buffer_head *__getblk(struct block_device *bdev, sector_t block, + unsigned int size); int bmap(struct inode *inode, sector_t *block); #define trace_jbd2_update_log_tail(j, t, b, f) \ do { (void)(j); (void)(t); (void)(b); (void)(f); } while (0) diff --git a/fs/ext4l/support.c b/fs/ext4l/support.c index e5343aab198..72bf819c3d6 100644 --- a/fs/ext4l/support.c +++ b/fs/ext4l/support.c @@ -267,6 +267,34 @@ void bh_cache_clear(void) } } +/** + * bh_cache_sync() - Sync all dirty buffers to disk + * + * U-Boot doesn't have a journal thread, so we need to manually sync + * all dirty buffers after write operations. + * + * Return: 0 on success, negative on first error + */ +int bh_cache_sync(void) +{ + int i, ret = 0; + struct bh_cache_entry *entry; + + for (i = 0; i < BH_CACHE_SIZE; i++) { + for (entry = bh_cache[i]; entry; entry = entry->next) { + if (entry->bh && buffer_dirty(entry->bh)) { + int err = ext4l_write_block(entry->bh->b_blocknr, + entry->bh->b_size, + entry->bh->b_data); + if (err && !ret) + ret = err; + clear_buffer_dirty(entry->bh); + } + } + } + return ret; +} + /** * alloc_buffer_head() - Allocate a buffer_head structure * @gfp_mask: Allocation flags (ignored in U-Boot) @@ -328,19 +356,25 @@ static struct buffer_head *alloc_buffer_head_with_data(size_t size) * @bh: Buffer head to free * * Only free b_data if BH_OwnsData is set. Shadow buffers created by - * jbd2_journal_write_metadata_buffer() share b_data with the original - * buffer and should not free it. + * jbd2_journal_write_metadata_buffer() share b_data/b_folio with the original + * buffer and should not free them. Shadow buffers are identified by having + * b_private set to point to the original buffer. */ void free_buffer_head(struct buffer_head *bh) { if (!bh) return; + /* + * Shadow buffers (b_private != NULL) share their folio with the + * original buffer. Don't free the shared folio. + */ + if (!bh->b_private && bh->b_folio) + free(bh->b_folio); + /* Only free b_data if this buffer owns it */ if (bh->b_data && test_bit(BH_OwnsData, &bh->b_state)) free(bh->b_data); - if (bh->b_folio) - free(bh->b_folio); free(bh); } @@ -451,6 +485,50 @@ struct buffer_head *sb_getblk(struct super_block *sb, sector_t block) return bh; } +/** + * __getblk() - Get a buffer for a given block device + * @bdev: Block device + * @block: Block number + * @size: Block size + * Return: Buffer head or NULL on error + * + * Similar to sb_getblk but takes a block device instead of superblock. + * Used by the journal to allocate descriptor buffers. + */ +struct buffer_head *__getblk(struct block_device *bdev, sector_t block, + unsigned int size) +{ + struct buffer_head *bh; + + if (!bdev || !size) + return NULL; + + /* Check cache first - must match block number AND size */ + bh = bh_cache_lookup(block, size); + if (bh) + return bh; + + /* Allocate new buffer */ + bh = alloc_buffer_head_with_data(size); + if (!bh) + return NULL; + + bh->b_blocknr = block; + bh->b_bdev = bdev; + bh->b_size = size; + + /* Mark buffer as having a valid disk mapping */ + set_buffer_mapped(bh); + + /* Don't read - just allocate with zeroed data */ + memset(bh->b_data, '\0', bh->b_size); + + /* Add to cache */ + bh_cache_insert(bh); + + return bh; +} + /** * sb_bread() - Read a block via super_block * @sb: Super block @@ -503,12 +581,17 @@ void brelse(struct buffer_head *bh) } /** - * __brelse() - Release a buffer_head (alternate API) + * __brelse() - Release a buffer_head reference without freeing * @bh: Buffer head to release + * + * Unlike brelse(), this only decrements the reference count without + * freeing the buffer when count reaches zero. Used when caller will + * explicitly free with free_buffer_head() afterward. */ void __brelse(struct buffer_head *bh) { - brelse(bh); + if (bh) + atomic_dec(&bh->b_count); } /** @@ -582,6 +665,23 @@ struct buffer_head *__bread(struct block_device *bdev, sector_t block, return bh; } +/** + * end_buffer_write_sync() - Completion handler for synchronous buffer writes + * @bh: Buffer head that completed I/O + * @uptodate: 1 if I/O succeeded, 0 if failed + * + * This callback is invoked after a buffer write completes. It sets the + * buffer's uptodate state based on the result and unlocks the buffer. + */ +void end_buffer_write_sync(struct buffer_head *bh, int uptodate) +{ + if (uptodate) + set_buffer_uptodate(bh); + else + clear_buffer_uptodate(bh); + unlock_buffer(bh); +} + /** * submit_bh() - Submit a buffer_head for I/O * @op: Operation (REQ_OP_READ, REQ_OP_WRITE, etc.) @@ -590,26 +690,38 @@ struct buffer_head *__bread(struct block_device *bdev, sector_t block, */ int submit_bh(int op, struct buffer_head *bh) { - int ret; + int ret = 0; int op_type = op & REQ_OP_MASK; /* Mask out flags, keep operation type */ + int uptodate; if (op_type == REQ_OP_READ) { ret = ext4l_read_block(bh->b_blocknr, bh->b_size, bh->b_data); if (ret) { clear_buffer_uptodate(bh); - return ret; + uptodate = 0; + } else { + set_buffer_uptodate(bh); + uptodate = 1; } - set_buffer_uptodate(bh); } else if (op_type == REQ_OP_WRITE) { ret = ext4l_write_block(bh->b_blocknr, bh->b_size, bh->b_data); if (ret) { clear_buffer_uptodate(bh); - return ret; + set_buffer_write_io_error(bh); + uptodate = 0; + } else { + clear_buffer_write_io_error(bh); + uptodate = 1; } - /* Mark buffer as clean (not dirty) after write */ + } else { + uptodate = 0; } - return 0; + /* Call b_end_io callback if set - U-Boot does sync I/O */ + if (bh->b_end_io) + bh->b_end_io(bh, uptodate); + + return ret; } /** From patchwork Tue Dec 30 23:41:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1131 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=1767138295; bh=EDzM3baFzRb0MwvMcg4t2YAsbiku8t7QO1WcIDzRFVI=; 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=HLlE5SC9KI5Q/9lDJSGtz5iWzLBOCyztRlQB61FRG4Ng+NYNpz36hmDFwrUrwCLRi c+Vn7Z12drBqpKUTwcxecpq/2l4JzAIBRcZicr+jaZU9UKNm1m+/AeZ1YZpeESNlln JG5pGIsyq3V7zuc0ouHX77bUmUVQfkaRfSxkfWtjKhem23d7Fk+eFkY7PWyBUQlSvA NLyEpttrOfYR5Drlv2lWKrwNUKdQSQcgwp47SSTLCC6QMhuK+nhtoQ6khKlpSacMMj nUvF7tNemnPA1gmqXoT0AxPhsvjyASkF6I0sT8sserJv8pt/L1VFCcPCwoyC8HjF2N ntThZDSWLaTIg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9DAA768F71 for ; Tue, 30 Dec 2025 16:44:55 -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 INw3TbDb8ZhN for ; Tue, 30 Dec 2025 16:44:55 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138295; bh=EDzM3baFzRb0MwvMcg4t2YAsbiku8t7QO1WcIDzRFVI=; 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=HLlE5SC9KI5Q/9lDJSGtz5iWzLBOCyztRlQB61FRG4Ng+NYNpz36hmDFwrUrwCLRi c+Vn7Z12drBqpKUTwcxecpq/2l4JzAIBRcZicr+jaZU9UKNm1m+/AeZ1YZpeESNlln JG5pGIsyq3V7zuc0ouHX77bUmUVQfkaRfSxkfWtjKhem23d7Fk+eFkY7PWyBUQlSvA NLyEpttrOfYR5Drlv2lWKrwNUKdQSQcgwp47SSTLCC6QMhuK+nhtoQ6khKlpSacMMj nUvF7tNemnPA1gmqXoT0AxPhsvjyASkF6I0sT8sserJv8pt/L1VFCcPCwoyC8HjF2N ntThZDSWLaTIg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8D15768C06 for ; Tue, 30 Dec 2025 16:44:55 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138293; bh=KQ37FfCDyxUfZK/MiKW3GVUde3L0z2JUb0Z0aefvrEQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PnTAbTliTQVSiVlAs3MSs9zHJpVbqN268dwQ5HZdpkSMMTpDunWxhsYhbRKFvmGTc HWQ35h1GDuoHef3VWNg90CgMacPROnJGiSleALXW/N6qUAsbkKYrVjIun9581Sb+0r jhBJebGoI0d6gkFAXbprhkzLXuDj6E6rEPbEhZTteKywaVuBC7UE76hThlhpEAkY4P s6O325RoZ+mCanylCsQaJpHoB65xZoVo2feQaiUcHkHPoVL8S/VK65RvaBDusZ19ZX uybOEavFSj6vKr/m6ieSLh3fGu40O6petausXw7pW+eLUTi28q6KdSBa1pr4RNCwYt EiGkPv0qAC8hA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BBE1864E2A; Tue, 30 Dec 2025 16:44:53 -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 EzuCxObEKtdX; Tue, 30 Dec 2025 16:44:53 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138289; bh=ERMMvBFfvkFb9Pb4UlhVgrDE5rYCD9bo/GVUzJ7kOEk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jZ/EzHlzzyS2wRmXEKFp/L9BbDv3uvR3HQ2CCTh2ULraNXGLjEBjl6aKHSw8Ic3Yx ghaUUrNk/Mi851jsN/Dmta0APlUzD6UVLycrNlE3oxqdLBNVW1p3CQL9JoX3rsMEKK SXk4THseP7RvcG6b4CqTJ5vLUjeTymSDg/igzcYVjZ5rYlBVJWtRJ+6hma4cQhRFek g/8Ay4Cble0fW18Eaif9Y0x5G9Od6BYWkrTYSQQXv/iSsjLs2XfFlMw9qxMyzaU6uN VlxuQr/EAmTDwBDCZtp81YRXBsgx94ivAOwzySYFbzymXdytnG5rANKiH2ZuA6V+aR SLYEwku5kZWrA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 7112F68C0F; Tue, 30 Dec 2025 16:44:49 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 30 Dec 2025 16:41:20 -0700 Message-ID: <20251230234134.906477-9-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251230234134.906477-1-sjg@u-boot.org> References: <20251230234134.906477-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: TIDYRKVXTPSEXZW4ULMYVBMDRVCS34BJ X-Message-ID-Hash: TIDYRKVXTPSEXZW4ULMYVBMDRVCS34BJ 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 08/15] ext4l: Fix inode_init_owner to set i_mode 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 Fix inode_init_owner() to properly set i_mode, which is needed for ext4_create() to work correctly. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- fs/ext4l/ext4_uboot.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index f4831a9b5c2..35db84588d6 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -410,7 +410,7 @@ extern struct inode *new_inode(struct super_block *sb); #define i_uid_write(inode, uid) do { } while (0) #define i_gid_write(inode, gid) do { } while (0) #define inode_fsuid_set(inode, idmap) do { } while (0) -#define inode_init_owner(idmap, i, dir, mode) do { } while (0) +#define inode_init_owner(idmap, i, dir, mode) do { (i)->i_mode = (mode); } while (0) #define insert_inode_locked(inode) (0) #define unlock_new_inode(inode) do { } while (0) #define clear_nlink(inode) do { } while (0) From patchwork Tue Dec 30 23:41:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1132 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=1767138300; bh=x7mIpd6gfxcghRMdGbNIJxTZ5vNGpoy/4FZgLliG7EE=; 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=iZ3wU4QQOjtUj5rg9Aoe0/NimJ9TT/VLfESkzbXjD1uvtlKrjEvnIHMjbPG+3u3Ya gvtsmeUXxDAuP3vr43fEiI+gBq0O14K51+G/lKylLkZTU3PPlWYn21WhpXc1w8ojb+ 0bhN5AKtvzlZKddq7w7pstYNjzkjqNojMCULlGFzFzOe6CaEB8naBxDr9VStpJEY2y 8jUWMInHp+QQ4Zt4VfH5rfaLZleE0zcRIl805cj/i8lnf2+rO9cwhrZabypNbYIxn8 wCZ5DJJdVRET/dGwHJH0sUBktabkkTHDDQBijbOK7rlOjIWC01rnCwcA7kPsKLbSpu +s0aAgbGuYFRA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 5805A68F8E for ; Tue, 30 Dec 2025 16:45:00 -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 h4z6o2AVSvaX for ; Tue, 30 Dec 2025 16:45:00 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138300; bh=x7mIpd6gfxcghRMdGbNIJxTZ5vNGpoy/4FZgLliG7EE=; 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=iZ3wU4QQOjtUj5rg9Aoe0/NimJ9TT/VLfESkzbXjD1uvtlKrjEvnIHMjbPG+3u3Ya gvtsmeUXxDAuP3vr43fEiI+gBq0O14K51+G/lKylLkZTU3PPlWYn21WhpXc1w8ojb+ 0bhN5AKtvzlZKddq7w7pstYNjzkjqNojMCULlGFzFzOe6CaEB8naBxDr9VStpJEY2y 8jUWMInHp+QQ4Zt4VfH5rfaLZleE0zcRIl805cj/i8lnf2+rO9cwhrZabypNbYIxn8 wCZ5DJJdVRET/dGwHJH0sUBktabkkTHDDQBijbOK7rlOjIWC01rnCwcA7kPsKLbSpu +s0aAgbGuYFRA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 46A1268C57 for ; Tue, 30 Dec 2025 16:45:00 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138298; bh=M0DYZTIlyDOgGvg4IL+r8bbhA85kaUgtIP7HvcbTvPk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Da6UBruJUpSl81blpy2nORMrYRV2rolH12g74ZrIXgdqu6PC19dRC+ZPL6gFZiHU8 ni+tVkN5tPco0bUXeXg+CGyuNWRTMgmA3teF7tvV7sNczxUQ1DaZmrATaRlAb4V1UY gFuXQ7wMoJqjCYxkegKbea29JIxxmpoh88Ogm1FUxGhmwELqtvQkAwGfIgfE29AIev E5wxKDsxQH9l58BYytfbwtUhPd9chRyFPllWSxz+68lA3PI7rItgIwZBt/U2ITF8CX tpgzogaONHCxU/u3jceoc795xk26AHSHbVGlP2UmV2QBZ8IU3vmjp5uV+FITfUjqo0 iPYP2cExdX1Eg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4392D68C06; Tue, 30 Dec 2025 16:44: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 10026) with ESMTP id kKcFsj5gcnr0; Tue, 30 Dec 2025 16:44:58 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138294; bh=WdBNvZih0phMjnuaQmcHx1r+PHU/tlAm5EDlfAw8M/s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s3/J+Y2fYOE+QMIzOAzMxvv66zbRZaPAuifFTnnXaj6RRHShGCl/n2UwYxOCpGAO9 9w6bMBF8+qInTthAT/Vvrue/nY20xEAFSvbA/ArKoc2djNIzYas/Bg0d7Rr6iej0nX dzKw4VlcefzGxey1s8Gf/4Chxwca4RnpgG/5MCQBfo6FtowQIuP76uMpTsyT1fkb8p dXFu63G9iZrHoQpr8VFaRlQxEqVkkNkyk9tPqH/2A0Ojaq5/sDHVWgVOMwG7+xkCbg 3RS6DpFqJ39naxNDs3P4jAPfwh8zI5U2tJT5OkmXi9CULJuVwDiaFLcn/YXIki2CXo rYbdlRJe4xnPA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 0A1B968C0F; Tue, 30 Dec 2025 16:44:53 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 30 Dec 2025 16:41:21 -0700 Message-ID: <20251230234134.906477-10-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251230234134.906477-1-sjg@u-boot.org> References: <20251230234134.906477-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 5HA6LNHXYNC6O3OFTPM4KETNKQE7XRI7 X-Message-ID-Hash: 5HA6LNHXYNC6O3OFTPM4KETNKQE7XRI7 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 X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 09/15] ext4l: Add ext4_commit_super() declaration 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 Add declaration for ext4_commit_super() to the ext4_uboot.h header and update the comment to reflect both superblock initialisation and commit functions. Signed-off-by: Simon Glass --- fs/ext4l/ext4_uboot.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 35db84588d6..610fe34b556 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -2075,8 +2075,9 @@ struct fs_context { bool silent; }; -/* ext4 superblock initialisation */ +/* ext4 superblock initialisation and commit */ int ext4_fill_super(struct super_block *sb, struct fs_context *fc); +int ext4_commit_super(struct super_block *sb); /* fs_parameter stubs */ struct fs_parameter { From patchwork Tue Dec 30 23:41:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1133 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=1767138304; bh=aLe3RM6+uT9W1qyKrcMdHuW3lkGXWAR6YuMJq53EQXo=; 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=cho2pUkP3VU6Xu1vu6B6k6NFFeqw9Ltl5qPBZDe7JRTjwHSaTQrZFoSXecrr+1DDd MsYsucg0fHHLugngKzSYqqrpB3IAFieDTkCc96QIwnrUvhNzY+EHmgBXtyfMkeGuYJ 4uiv7MyRU+gktMZuv7k0IIdt8026d4RnjAxlvtugmYDDP5bxPN0xZW4d2UrBd+2+aH /JaZ0cL5ndt4h0JaUI1EARmlF5x76HQEFwmSGIyXVnZAM1n6v9kgAbUWsAUaj4RZt1 7lx5sbCBq6RpxCBDXYe5chLYqe4tq6UMhbDMwDhLrXMYfDuvzkshs5uS1/O72PjuTN gzIm3saqa65Bw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D2C1368F8E for ; Tue, 30 Dec 2025 16:45:04 -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 CC8cf_Npr1De for ; Tue, 30 Dec 2025 16:45:04 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138304; bh=aLe3RM6+uT9W1qyKrcMdHuW3lkGXWAR6YuMJq53EQXo=; 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=cho2pUkP3VU6Xu1vu6B6k6NFFeqw9Ltl5qPBZDe7JRTjwHSaTQrZFoSXecrr+1DDd MsYsucg0fHHLugngKzSYqqrpB3IAFieDTkCc96QIwnrUvhNzY+EHmgBXtyfMkeGuYJ 4uiv7MyRU+gktMZuv7k0IIdt8026d4RnjAxlvtugmYDDP5bxPN0xZW4d2UrBd+2+aH /JaZ0cL5ndt4h0JaUI1EARmlF5x76HQEFwmSGIyXVnZAM1n6v9kgAbUWsAUaj4RZt1 7lx5sbCBq6RpxCBDXYe5chLYqe4tq6UMhbDMwDhLrXMYfDuvzkshs5uS1/O72PjuTN gzIm3saqa65Bw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B917B68C57 for ; Tue, 30 Dec 2025 16:45:04 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138302; bh=/yoq94/3OIeTYhhfbBOAFf8NquxxsEBMtUCbANBMafk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OUgb+yJnwr60ZmbDAwBawKy9NN//PMzhGwSSrp0Mf0zbLaAhw1+d1QUQxeJhAdcNm pNKnrlnhXGnBq6K9DC41hAZErNs9wlsKgAikFgVqxXyr/dCqDncOQxgvklKlnVcRqq 7PzUim5JNz7K4pOCTw47P7Pj+H23Wwz8r5p6QyjdXMK3bsB6YaUx1r6xmW805kJA4T gpeYwFY1uuwbFuYjdQpu80HNi1LIHjiJ3jZW/IRad6CN3krvHmpYbC6BgKUEN+SIaT kkPoR0pnQ6rUcXkkMF3k+mnz5yy8yYViGEo9BGnt7NDLxp5x48iAtSl4PipBSwSJed PlI8sFNZ/Q+BA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DD98B68C57; Tue, 30 Dec 2025 16:45:02 -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 n1qoE0qvwxlA; Tue, 30 Dec 2025 16:45:02 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138298; bh=jjQBUVGS/6HnMsnLH69hkJAHc3Ip4hdrfh3aQGoE8ao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vEqMz9A0wdoIaQo/WtP6gHuckAuxj/V4EbGwSlQ1sIfBccYFUZm8AOhazrCmY3dYI vtUsn4Z7jN50Cy8GBh7wyFeooNpBO9bSPctAU2HrFderqB+o56He3m+RVhHJZQ8nyu oP5aoeAHsm1zvJzsR5hT4p8gEmNgGTAZ5j0//AKRQS5qgAH6F/W0ckpDGvgJN92aeN 77f4twEbEig1WIp0eACTDz8MEpYGCotVj+SrsJvIQNbOES1DwmBM/Uk7uUjCTBO0I8 F8mQi/SQ2tyq8UNSt+OLXS5Jf/xX3fGJOgQElELO/7oUYj0x5J/UyjTdnVc7QGEpZw rcvoJ7d4jAqCA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 8644468C0F; Tue, 30 Dec 2025 16:44:58 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 30 Dec 2025 16:41:22 -0700 Message-ID: <20251230234134.906477-11-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251230234134.906477-1-sjg@u-boot.org> References: <20251230234134.906477-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 6T3H2WZT55XY2FKXSBK3T2G6BEOOTMZP X-Message-ID-Hash: 6T3H2WZT55XY2FKXSBK3T2G6BEOOTMZP 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 X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 10/15] ext4l: Fix dquot functions to update i_blocks 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 The dquot_alloc_block(), dquot_free_block() and dquot_alloc_block_nofail() functions are stubs that do nothing. These functions are called by ext4 when allocating and freeing blocks, and they should update the inode's i_blocks field. Fix these functions to properly track block allocation in i_blocks, which is stored in 512-byte units. Co-developed-by: Claude Signed-off-by: Simon Glass --- fs/ext4l/ext4_uboot.h | 3 ++- fs/ext4l/stub.c | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 610fe34b556..c5eddca3aef 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -375,7 +375,8 @@ struct buffer_head *sb_getblk(struct super_block *sb, sector_t block); /* Quota operations - stubs (only define if quotaops.h not included) */ #ifndef _LINUX_QUOTAOPS_H -#define dquot_alloc_block_nofail(inode, nr) ({ (void)(inode); (void)(nr); 0; }) +#define dquot_alloc_block_nofail(inode, nr) \ + ({ (inode)->i_blocks += (nr) << ((inode)->i_blkbits - 9); 0; }) #define dquot_initialize(inode) ({ (void)(inode); 0; }) #define dquot_free_inode(inode) do { (void)(inode); } while (0) #define dquot_alloc_inode(inode) ({ (void)(inode); 0; }) diff --git a/fs/ext4l/stub.c b/fs/ext4l/stub.c index 2d066be4af3..ce68ec28b20 100644 --- a/fs/ext4l/stub.c +++ b/fs/ext4l/stub.c @@ -669,11 +669,22 @@ void dquot_free_space_nodirty(struct inode *inode, loff_t size) int dquot_alloc_block(struct inode *inode, loff_t nr) { + /* + * Update i_blocks to reflect the allocated blocks. + * i_blocks is in 512-byte units, so convert from fs blocks. + */ + inode->i_blocks += nr << (inode->i_blkbits - 9); + return 0; } void dquot_free_block(struct inode *inode, loff_t nr) { + /* + * Update i_blocks to reflect the freed blocks. + * i_blocks is in 512-byte units, so convert from fs blocks. + */ + inode->i_blocks -= nr << (inode->i_blkbits - 9); } /* From patchwork Tue Dec 30 23:41:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1134 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=1767138309; bh=SX4CHj/V6CeUaYLSaV6ZmhWnxrLCB9oJWotJyVtQ23o=; 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=OLUZwORRSbNCvf5DP7/Wp9NE7OTWC/jdHK6WD8+CnsFMJrks0gkOrLPb5JA7dJdcY fGC7XStf4APYY3cf0+Cescv9uBeBGIP12czpEXFyUnkUf2RylqdBmM6bCKcN0/5Qw2 7M/WzguM6dzyChz/uNOMEa2mLUQmdmZSJP3SnSUzWoBuMaAZSr9wM0FAgFH9qGi1b9 ooLwYMagNOFDFRVywOJ1ZQyU6Pb0L7Lij4m99CRM5AZX/EebZ54yCxMcietY07ED3g 1fPC5fLRSiuaHSNaJP9+XnLqelZOdMO+aMcTrP7hV8RhjE4SaLf2A0IKsvjcggnuo8 yYdJ0BKXTro5Q== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4B94968F8E for ; Tue, 30 Dec 2025 16:45:09 -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 U-lLiKNZDxGk for ; Tue, 30 Dec 2025 16:45:09 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138309; bh=SX4CHj/V6CeUaYLSaV6ZmhWnxrLCB9oJWotJyVtQ23o=; 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=OLUZwORRSbNCvf5DP7/Wp9NE7OTWC/jdHK6WD8+CnsFMJrks0gkOrLPb5JA7dJdcY fGC7XStf4APYY3cf0+Cescv9uBeBGIP12czpEXFyUnkUf2RylqdBmM6bCKcN0/5Qw2 7M/WzguM6dzyChz/uNOMEa2mLUQmdmZSJP3SnSUzWoBuMaAZSr9wM0FAgFH9qGi1b9 ooLwYMagNOFDFRVywOJ1ZQyU6Pb0L7Lij4m99CRM5AZX/EebZ54yCxMcietY07ED3g 1fPC5fLRSiuaHSNaJP9+XnLqelZOdMO+aMcTrP7hV8RhjE4SaLf2A0IKsvjcggnuo8 yYdJ0BKXTro5Q== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3AF2368C0F for ; Tue, 30 Dec 2025 16:45:09 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138307; bh=TiqTvFTJ1QCsqmtnSDF0sU+N0HSczr0AkAdhXMgX/g4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NXYsg8OxyxI7cX9k/etmI813Ezk+A/8poeBbPtkelJFF3RxXV+jJEFDaY62IKCCGj Qu4LC8Orl8xU60f5OmOC0t35S83bLMIxoQEOYff2u5ejra0KquGLLsRqVEzattAj/R sWSIFUPgQxI1EQzhEY5gIK3bsd5B9ZVfsgaEgjmSfi+WyVvVbgi7dntaWr6vj8+DIO SoKfU4T707Z25tnkBh30VbWgteAueJ6sWE0s6kmhpZ5kUAAiPaIoJH83Ad53f9q+uH L9ENHVe2cas66CW1zfc8oxD3PqeiaNkVLZDzUV5ZkmPeKvLEEgGEzqo9ZGQobuyq+G i2B5gnzR4GSQg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6D3AB68C06; Tue, 30 Dec 2025 16:45:07 -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 Ok24VNHkeA3L; Tue, 30 Dec 2025 16:45:07 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138303; bh=aB7dCY/TJECHoDyqAlOIEfgF0Em2N6UE2NBO+Ac0Aa8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vcyiiA7W7qW3bBNeoHNl5dMHsVpaERjoaALgeysjeJvMmsWQF878KGKlJ+ajmmZ+C Hhvn0h54Gkpviqvln32lRvHMSqLbc0tmpnLsNXqwgtf4gsQVZECtPI2YW1G4fvwptV imC7Q/IUGZx0fAZ5zY0y1QNc50W9/ErUjfeEGH/zA+UXtjUVyO34sne+E6DpA2sWzp 7B795VqYeyCTrBmeq+ohQDoIPdYkFerVbIMSMwOFSZHVv42NV9o7v9YpStbLO6ROaR F2dIGxWH35PvWKAEQX3On4GFZNgS7SYrONsR7jN7rZpJs5mcJqqGBrGq2fy20wZdjz X/iWWIXbl1x6Q== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 2362768C0F; Tue, 30 Dec 2025 16:45:03 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 30 Dec 2025 16:41:23 -0700 Message-ID: <20251230234134.906477-12-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251230234134.906477-1-sjg@u-boot.org> References: <20251230234134.906477-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: NHX3A7JPF4GVKCGEIJMGCU33AX5E2KMN X-Message-ID-Hash: NHX3A7JPF4GVKCGEIJMGCU33AX5E2KMN 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 X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 11/15] ext4l: Return boot-relative time from ktime_get_real_seconds() 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 The ktime_get_real_seconds() stub returns 0, causing deleted inodes to have zero i_dtime. This causes fsck to complain about deleted inodes with zero deletion time. Instead, use the boot-relative time in seconds. While not a real wall-clock timestamp, it provides a non-zero value that satisfies filesystem-consistency checks. Future work can improve on this, perhaps using an on-board RTC. Co-developed-by: Claude Signed-off-by: Simon Glass --- fs/ext4l/ext4_uboot.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index c5eddca3aef..5c66e35662d 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -402,8 +402,8 @@ struct buffer_head *sb_getblk(struct super_block *sb, sector_t block); #define sb_find_get_block(sb, block) ((struct buffer_head *)NULL) #define sync_dirty_buffer(bh) submit_bh(REQ_OP_WRITE, bh) -/* Time functions */ -#define ktime_get_real_seconds() (0) +/* Time functions - use boot-relative time for timestamps */ +#define ktime_get_real_seconds() (get_timer(0) / 1000) #define time_before32(a, b) (0) /* Inode operations - iget_locked and new_inode are in interface.c */ From patchwork Tue Dec 30 23:41:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1135 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=1767138309; bh=dW45BHo+d637kwbE817je7aG3/bUJmog4vVenLVb11Q=; 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=TIfzNTkCWhylzbQ6jYU00Wi+AjJoz5fXCPAYkJZNYo0Rrr27ZZPC5Aki4w2XNzzgr aupvX8lCd7sc5HeTaVEc2M4NsdslMwAAGOLiONQHtTLY1CaJnk/Qd+XyROb1rRwN2r dioBojVro1jwPtENHmrDmqCn4FRO9SkD6NDzF5kiKg67wBV/r/WmqHR/EakC5ujcN5 AlDd3CP/7FzeVbDuCp+PzXFP0qdNHjTMUghU9c0o10LuxsrWLkBo5O7dAw3go55TUq M6hhqY3pDgyRppOwzu2CduwporTLpjmQu6Kik00u6OL1ayI1fTduMcAtT4toFHOeUq YCuumTmZR7lsA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BB22C68FA8 for ; Tue, 30 Dec 2025 16:45:09 -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 9KGkWEJM1NlY for ; Tue, 30 Dec 2025 16:45:09 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138309; bh=dW45BHo+d637kwbE817je7aG3/bUJmog4vVenLVb11Q=; 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=TIfzNTkCWhylzbQ6jYU00Wi+AjJoz5fXCPAYkJZNYo0Rrr27ZZPC5Aki4w2XNzzgr aupvX8lCd7sc5HeTaVEc2M4NsdslMwAAGOLiONQHtTLY1CaJnk/Qd+XyROb1rRwN2r dioBojVro1jwPtENHmrDmqCn4FRO9SkD6NDzF5kiKg67wBV/r/WmqHR/EakC5ujcN5 AlDd3CP/7FzeVbDuCp+PzXFP0qdNHjTMUghU9c0o10LuxsrWLkBo5O7dAw3go55TUq M6hhqY3pDgyRppOwzu2CduwporTLpjmQu6Kik00u6OL1ayI1fTduMcAtT4toFHOeUq YCuumTmZR7lsA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A9DF068C06 for ; Tue, 30 Dec 2025 16:45:09 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138308; bh=0JFwz3oCrwQvig6iMCrxhhJzJrohD4WkhoRegGJbff0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YdJR2KhXpIhkyBug4ag4iLs6nS/tbvwABI5xNmbdNu59kksqK1I8xbVYfOLHQyw1B uZGqYpGCIHcJz+MigOZkspviadd6ONZWUXwHi0w/l3P2mwSr9cQUnUXrZBRhGlCKRv MGm5X/LY+RSD9kHUt3NqvwJ5wYSjdQlc+K12fqY4owY3i6qF6sabWBMlMVZmA5EDxl mSI/8tq2EJFkHHYiu0DnI4IQtIgHzoRoTWetOqNvQk3oZ2sE97qp3smVsfmxFaWP8l suD5/m3Qkbi1DXSk0gF/uiY3Zn/WPPGFnJnvZaZEUlByUYlWlu347Xl7XetE/fwtiE xBb0EOLgo0QVA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 48D8D64E2A; Tue, 30 Dec 2025 16:45:08 -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 rWxlEzkh468W; Tue, 30 Dec 2025 16:45:08 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138308; bh=ZNX4zRSTw+nLyuNQxYT5E+D0R4MA7YRoc9R8+SaR6Dc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VK/SD1eliAvRCXN01v8L7dOyG5LMlynXiV/3oE2+coM0QJRmuaG+wxtSWrD9pOaav jeXrGrVB28La8UEkZpVfVFoNPD2GuftVGc5QkGF01tPlKxCqG7dniwcCqqM7EeBGsj rNLXSLvspRJBhXW//cNiA8yGoQ+hnhcTGJ2Z3FEEO/PPJUMbiXFFtRzF+SHi1F10U9 pELl+FAfyJZG6egjuDiDlo/wDNS7n0hETPfVLkd0RxouNJ1m6CfjEY72pvFD0TWweG B52w0zbP7Jxcj6wGEvb+WkN3wIx/Ym/unXCGhs6KrdkScCAAL4UhKSFTNL7vWIT3OV BAC7GGoCLuahQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id B137F68C0F; Tue, 30 Dec 2025 16:45:07 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 30 Dec 2025 16:41:24 -0700 Message-ID: <20251230234134.906477-13-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251230234134.906477-1-sjg@u-boot.org> References: <20251230234134.906477-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: YZCINMDOC5XNTPY5IV3RQOZ2YXIYMSLL X-Message-ID-Hash: YZCINMDOC5XNTPY5IV3RQOZ2YXIYMSLL 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 12/15] ext4l: Implement iput() to evict deleted inodes 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 Implement iput() to properly handle inode reference counting and eviction. When the reference count drops to zero and the inode has no links (i_nlink == 0), call ext4_evict_inode() to free the inode's data blocks and the inode itself. This is required for unlink operations to properly free filesystem resources. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- fs/ext4l/ext4_uboot.h | 4 ++-- fs/ext4l/stub.c | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 5c66e35662d..18ea2b1bcd4 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -491,8 +491,8 @@ int __ext4_xattr_set_credits(struct super_block *sb, struct inode *inode, /* RCU barrier - stub */ #define rcu_barrier() do { } while (0) -/* inode/dentry operations - stubs */ -#define iput(inode) do { } while (0) +/* inode/dentry operations */ +void iput(struct inode *inode); /* current task - from linux/sched.h */ #include diff --git a/fs/ext4l/stub.c b/fs/ext4l/stub.c index ce68ec28b20..2b7618df64c 100644 --- a/fs/ext4l/stub.c +++ b/fs/ext4l/stub.c @@ -587,6 +587,29 @@ struct dentry *d_make_root(struct inode *inode) return de; } +/** + * iput() - Release a reference to an inode + * @inode: Inode to release + * + * Decrements the inode reference count. When the reference count reaches + * zero and the inode has no links, the inode is evicted (freed). + */ +void iput(struct inode *inode) +{ + if (!inode) + return; + + if (atomic_dec_and_test(&inode->i_count)) { + /* Last reference - check if inode should be evicted */ + if (inode->i_nlink == 0 && inode->i_sb && + inode->i_sb->s_op && inode->i_sb->s_op->evict_inode) { + inode->i_sb->s_op->evict_inode(inode); + /* Sync dirty buffers after eviction */ + bh_cache_sync(); + } + } +} + /* percpu init rwsem */ int percpu_init_rwsem(struct percpu_rw_semaphore *sem) { From patchwork Tue Dec 30 23:41:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1136 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=1767138312; bh=XU5tKATEncLvtHNStRpq8JYv/uOGg+7VsyQxiceDw8M=; 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=UdrKzY5MvVL+yeE0pSEWoVykpOYpropajR/h4pp0SuxSNmGL5Fiptk64nhmAoNlww zJt6f1WwoZ47WqEpCsTrTnkLViwPNHPWaqRENkj84c/BbEQ5xZ1lwdbPi3LE0bbHuR diT99mwUjm2lCfu/i8eYwlozOKQMOmQXNfwogzSzrm/RKsTIszDeNZZJxqwoJFhGMM geIZwE2QAX9e2eZ9aNQZdn4C1hp0UEJLlo+CyliTIjLPjhm2ilQLN2Rm9gSF41e0J6 /AkzeaDk/PoeNuVznSUgCygD3t58F+UuXfi05ojUbLx+GUcZAmoJTo3BtowOdHiMVg ez4QroqWFk4xQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 141A764E2A for ; Tue, 30 Dec 2025 16:45:12 -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 b_ddDfoCt-OC for ; Tue, 30 Dec 2025 16:45:12 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138311; bh=XU5tKATEncLvtHNStRpq8JYv/uOGg+7VsyQxiceDw8M=; 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=vRoGhZqavRCAE/gQVFJ1YTApUtz+Kp6SlsWz6G/qxVC31ppno6XjW3IaT6BpnOKUT 3KWWqUbox29qqWBZyRQoK7uRG8qvjr+TdDDXqazEOy6zCqAzV8xymTUlSEsFmrH20T XekIrQdAMUy/dWoYs4ezru4rxrbdSj5vN2r355WoiRATHYgb0m/3VTF7qlj5wId5lj OO8tDKetVOXz/ZHPpFbWet5N/LSY/Vp0dNS+iN5f/SV6r7IVBxkFsqvMqCGHMwrfWV 5w4rxlHEUD1xidVq+WPb4ey4dAN6sB3Yd2wImE+8QlOfr7V1XD4EOjwf9rqNoV5a1E rp4aDTluuDcrg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 63A7A68C0F for ; Tue, 30 Dec 2025 16:45:11 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138309; bh=74OSJfspoA5Kb+gkhf/Nho/Ad7zS7XznZg1PDNkIeeg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sN09a6Oytr0lIdSVo2Vl59jtaJ+txiaEwIhVeccYNE23onl1PuwoEzLNhOTRU6Gaf jNfPcbtwSGc5/mlYaVVqmzcmjxQiWaqsq6HRYyYgcHLrWqZ5Zbqt6TSwbZBpSbwwPh CpqPPow8BgjvEXxPD8t7r/QAc1RFnmmBhYjUsemkcrR04+iwJANoHam6iMy0+5CQyl cU++/MTF4SJM6DoCfGOn5tDC0mIwQH50gPyj6h2soiJT+PthLXbXH0mX27R59EH0Br oKe02i4PGcraNQKRqgTTwDQbYCIQ3ZNbymZpBNCXbrhcZfaEBeJ0mT6zMwFZPyakKa xMUsd83EfbOdg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1841264E2A; Tue, 30 Dec 2025 16:45:09 -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 8NOL_uhRNY2k; Tue, 30 Dec 2025 16:45:09 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138308; bh=9X2tbqwOeAcfuasyVz4NZtlVZnHjCN6t7quop+PYQys=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KTjPVVXym3WfxxEtSsIIMoHEuA2ePWTEJxsJZJG6rsD7bJQZlu5K3kbMJXtjvVmrx oA3d+13bvhoFTcdGRW55sX09/jgXXH9fCRlHw3qKDSVs9kU0wGe9PNc52FnxfY0XPX pZQzaKJWdNRDqOdMW+4Pt1AxNPe8uh017AgCr/p7NwvaE6fef4DiHobnmzSydtZo8K Io949Hz1tEBOfw9jamQfXLUwBFQZGsmL9wkteRogpsPKS3tg8DyAjNzdGztmUw+VVJ 1zM1kWrmeYlBpeHiIt+eHiTIJVvkzdoEtttSIdEM41LV0E1bEYjE4d630+ZXUljC5k 5fe9E5FEPyj9w== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 87F8F68C06; Tue, 30 Dec 2025 16:45:08 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 30 Dec 2025 16:41:25 -0700 Message-ID: <20251230234134.906477-14-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251230234134.906477-1-sjg@u-boot.org> References: <20251230234134.906477-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: LBQTIDBJYFF552SX2L4FPTOEWUIM57VE X-Message-ID-Hash: LBQTIDBJYFF552SX2L4FPTOEWUIM57VE 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/15] ext4l: Use percpu_counter initialized field 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 Update the percpu_counter_initialized() and percpu_counter_init() macros in ext4_uboot.h to use the new initialized field. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- fs/ext4l/ext4_uboot.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 18ea2b1bcd4..2d0e817be40 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -368,7 +368,7 @@ struct buffer_head *sb_getblk(struct super_block *sb, sector_t block); #define percpu_counter_add(fbc, amount) ((fbc)->count += (amount)) #define percpu_counter_inc(fbc) ((fbc)->count++) #define percpu_counter_dec(fbc) ((fbc)->count--) -#define percpu_counter_initialized(fbc) (1) +#define percpu_counter_initialized(fbc) ((fbc)->initialized) /* Group permission - stub */ #define in_group_p(gid) (0) @@ -1216,7 +1216,8 @@ static inline ktime_t ktime_add_ns(ktime_t kt, s64 ns) #define write_trylock(lock) ({ (void)(lock); 1; }) /* percpu counter init/destroy */ -#define percpu_counter_init(fbc, val, gfp) ({ (fbc)->count = (val); 0; }) +#define percpu_counter_init(fbc, val, gfp) \ + ({ (fbc)->count = (val); (fbc)->initialized = true; 0; }) #define percpu_counter_destroy(fbc) do { } while (0) /* ratelimit macros */ From patchwork Tue Dec 30 23:41:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1137 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=1767138317; bh=ZLXHjPyifleY4qMP5hiuTrHqocik3ZJSrj1hRoYRILI=; 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=FFC6QOumU859HygykOoJENQqIOOdNopirdr5QfieHy1vDbTZph/ba17UezfROxMyV s/KltN1BqVMtCLRTMWbCqtmrzK4r0Bf/wExBR0g91qeIsYizsoqLd0L7rKKZVlW9K+ uHAlbo66MPNbaPrWJD9VNANzLo1xuBCBOmwJX3DSMGwfWLV4ycjZRE77GSZ2CizzDD qdDBrrDbmCqL0HWhLHWz245lHPKITOmN4/zsnKyOenxV5/j3RBoOf2fwdW8hhRnueM q1E0MoxJWLY0iMfV1TRJbsw7H90EnodPifNCIyH4sjkCn7O2HXcfdUdIZvKY8nkKV4 d3bF9IqYClKMg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E7C1768C0F for ; Tue, 30 Dec 2025 16:45:17 -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 R5jWi0jBY9pO for ; Tue, 30 Dec 2025 16:45:17 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138317; bh=ZLXHjPyifleY4qMP5hiuTrHqocik3ZJSrj1hRoYRILI=; 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=FFC6QOumU859HygykOoJENQqIOOdNopirdr5QfieHy1vDbTZph/ba17UezfROxMyV s/KltN1BqVMtCLRTMWbCqtmrzK4r0Bf/wExBR0g91qeIsYizsoqLd0L7rKKZVlW9K+ uHAlbo66MPNbaPrWJD9VNANzLo1xuBCBOmwJX3DSMGwfWLV4ycjZRE77GSZ2CizzDD qdDBrrDbmCqL0HWhLHWz245lHPKITOmN4/zsnKyOenxV5/j3RBoOf2fwdW8hhRnueM q1E0MoxJWLY0iMfV1TRJbsw7H90EnodPifNCIyH4sjkCn7O2HXcfdUdIZvKY8nkKV4 d3bF9IqYClKMg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BD34264E2A for ; Tue, 30 Dec 2025 16:45:17 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138314; bh=D760mnHYbOoXxlGrrPV/mmCYM7ML56jEyaZhqmxcuuY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pXT0YWnemnI9T9R/9fktJ5Yi5Csrltd4fStgOZYOc99zghzI4GoBSs1dauAmg3jNE uWK8vMMnJPFk6c1UJF62WUc4qL0b0Z196S9VT9JbuEzTAqXHzwoiUWV1xEFTvu3IxU VnAeqBEVKZ2a03y54sb4QnEB4sFfwa3mjkRUkENZmiLV63y0sxePftTXAuHGis33Jr BWe8an2SRn9pzKrQTzhAWjvkfbhatI4t8Gb4pSiil60ydNuNjg1KjUq4a+841/OCzt oDrR1jaZTKZYmo8HSdM1lo2blBc1AoI7hJam16SFn6Mg/eoIe5jpmL2+bxa+xgry7u 2NgEAMDnHwLzQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 5C9F868C06; Tue, 30 Dec 2025 16:45:14 -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 nMiWw5Y-RUJo; Tue, 30 Dec 2025 16:45:14 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138309; bh=q9fbyfRbgRm40Udq1WcJeYLrvFnOnFu088GYksy2VWI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S9hszDTG6iNJAWUVQoaN6+7i6ZaMvYhwSfkGREEiGYKtbz2iSggOpiVy9QC3ECqCQ utxUy98AUrUuBOO3CIdJsYeZ+VHu19tN8eLc067m5Qr2VQWMQMiCn+HbYFU/M4zhU7 PwjrLUs2AlkFteaq7S9R5AoT3hA0OJ5viaArDbeKms4f3oihEF0pwY8p5bWDlcTETr feP7tEMCcBCkqNyiwIXz2Ixl9gKyA7ZKKC+3+Gj5Xy7pHGod0byeHnJOY9U2/CWV7X xLmNmXrLlgA7jXYcHKLDNw8E5k+GAc+4zAMHJHhubq8VyTVcqtHehOzDW9F4LvZjHl m70+NFuEkYDuQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 57A0168F98; Tue, 30 Dec 2025 16:45:09 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 30 Dec 2025 16:41:26 -0700 Message-ID: <20251230234134.906477-15-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251230234134.906477-1-sjg@u-boot.org> References: <20251230234134.906477-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: UINWQBXRZKJJCPCLV4PRVIYNURARUVBH X-Message-ID-Hash: UINWQBXRZKJJCPCLV4PRVIYNURARUVBH 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 14/15] ext4l: Fix bit operations for bits beyond first word 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 The set_bit(), clear_bit(), and change_bit() functions only modify the first word of a bitmap, regardless of the bit number. For bit numbers >= 64 on 64-bit systems, the shift wraps around and modifies the wrong bit position. Fix these functions to properly calculate the word offset before modifying the bit. This is needed for block bitmap operations where bit numbers can be in the thousands. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- fs/ext4l/stub.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/fs/ext4l/stub.c b/fs/ext4l/stub.c index 2b7618df64c..f072cb5713f 100644 --- a/fs/ext4l/stub.c +++ b/fs/ext4l/stub.c @@ -77,26 +77,27 @@ typedef struct journal_s journal_t; /* * Bit operations - sandbox declares these extern but doesn't implement them. + * These work on bitmaps where nr is the absolute bit number. */ void set_bit(int nr, void *addr) { - unsigned long *p = (unsigned long *)addr; + unsigned long *p = (unsigned long *)addr + (nr / BITS_PER_LONG); - *p |= (1UL << nr); + *p |= (1UL << (nr % BITS_PER_LONG)); } void clear_bit(int nr, void *addr) { - unsigned long *p = (unsigned long *)addr; + unsigned long *p = (unsigned long *)addr + (nr / BITS_PER_LONG); - *p &= ~(1UL << nr); + *p &= ~(1UL << (nr % BITS_PER_LONG)); } void change_bit(int nr, void *addr) { - unsigned long *p = (unsigned long *)addr; + unsigned long *p = (unsigned long *)addr + (nr / BITS_PER_LONG); - *p ^= (1UL << nr); + *p ^= (1UL << (nr % BITS_PER_LONG)); } /* From patchwork Tue Dec 30 23:41:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1138 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=1767138318; bh=s83aFXmrjg2ogJV7kCD58L8XeHsBaXli5tnd3EAQW6g=; 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=NQi9IVPLRxxeN3QPdTFeLnfx5TeSI2pDZ1gkEawTmfRKNLgfj4zEuwU9ys3DPAfyC qxmGTHlrSY6HV+C+Bz/uCsdoSEB3qzZYP3yUQLS5LZ9P1QV+iN/dXo97W0qxgskPUe fixiV5fV82qbeiZAc41WPWWVDSd0D9Gx0GbxBZVuQMAW0t4mLHtiHvL2UEW9MRcfue s4SzjYGT/Z8uqbButpot3FJ1EGHBpyC/b/i2SiOuefiALKWTUYyLQTKk5rLM4BZvSt eShOs4KuFYCzwweQAOTgPf+nTylvO+7ue3aYUoaExfPb32anMxRSI0A/hvtjMlIkbg bum918qy2goYA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id F15C264E2A for ; Tue, 30 Dec 2025 16:45:18 -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 aYCrV0ocULpr for ; Tue, 30 Dec 2025 16:45:18 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138318; bh=s83aFXmrjg2ogJV7kCD58L8XeHsBaXli5tnd3EAQW6g=; 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=NQi9IVPLRxxeN3QPdTFeLnfx5TeSI2pDZ1gkEawTmfRKNLgfj4zEuwU9ys3DPAfyC qxmGTHlrSY6HV+C+Bz/uCsdoSEB3qzZYP3yUQLS5LZ9P1QV+iN/dXo97W0qxgskPUe fixiV5fV82qbeiZAc41WPWWVDSd0D9Gx0GbxBZVuQMAW0t4mLHtiHvL2UEW9MRcfue s4SzjYGT/Z8uqbButpot3FJ1EGHBpyC/b/i2SiOuefiALKWTUYyLQTKk5rLM4BZvSt eShOs4KuFYCzwweQAOTgPf+nTylvO+7ue3aYUoaExfPb32anMxRSI0A/hvtjMlIkbg bum918qy2goYA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id CF6FF68F99 for ; Tue, 30 Dec 2025 16:45:18 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138314; bh=wRD8Rv1mOZQ7633pk8bcH9L1+6McRElqoEADT34jcQk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h4+Br9LfXF0UGwkhd5jwgKX+zqjkMAjXqwqvW0whjm7g1aXMsOOPzQqHz8qmv9yWG k9Rm1ZKxwvu4Ur0HW8CxousFPSSfjiagPd8bnxwOs7Bs6qQ5AuCcIqPgudRWonN7kZ 208mnKf3jg1h2CtaAFRrkKoftkQM/8GjU5jYRU3REvXA6Lcgu0lNcxqIwmqkB/EOJc kzVdfiIBwsqr1Af+wyVmUMYifxJ1DISpzh33QuJ7rSs9zH9Syl8YW3WqbzCTjj2QJ1 0Pp76/o7HmSmRXTdnGyd4Q8i5b+lyUozpxU48Yv43LdGkaA9D84bX3nGWySt0rKYpl Uxv1BUoa6vHJQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A8F4468C0F; Tue, 30 Dec 2025 16:45:14 -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 62jsYF0EK-NW; Tue, 30 Dec 2025 16:45:14 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767138314; bh=ZEsWo2niiG/dVcsBedniMslpjgzJawtaHo9TJwhTINw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MvKHW0HmNOHF/dVOeeiNrFmr72Lnfc34ZmlfCEbVBpJ7Nh8VC989wXiVcmjfxCgvQ edVafj6813Gc9LhOsqFyY2gD4lxmV+rhzG5FJ3BSEzdINWH34/A7ylHlqIdXbqthWH UM9LGmUYUIoV/uRX8FJrM7+FrQ7SBF8PZoGiqyzg8b+EeLzEbEVawgztLc+fUAFVUF rnwF55nH1kLz1CsVMpzad5mmpcAZ8zpCMH2BAN2+hhYu5doBEGBjg5S2UTcIPDqh18 tWSJF6gKQeYyJypLSnwyQWprMTolhgOhZddoj4XMO1l+hQ93aU2rAyTLNZyi/SR/eK eLzYDMZefY7Jw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 0050964E2A; Tue, 30 Dec 2025 16:45:13 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 30 Dec 2025 16:41:27 -0700 Message-ID: <20251230234134.906477-16-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251230234134.906477-1-sjg@u-boot.org> References: <20251230234134.906477-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: TSYPDBOND4D63OG3PXG666FLJBTZML4P X-Message-ID-Hash: TSYPDBOND4D63OG3PXG666FLJBTZML4P 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 X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 15/15] ext4l: Fix cmpxchg macro warning with clang 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 Rename local variables in cmpxchg macro to avoid shadowing when used inside try_cmpxchg, which also declares __old. Clang complains about "variable '__old' is uninitialised when used within its own initialisation" due to the nested macro expansion. Co-developed-by: Claude Signed-off-by: Simon Glass --- fs/ext4l/ext4_uboot.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 2d0e817be40..087d8394ab6 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -101,12 +101,12 @@ struct timespec64 { /* cmpxchg - compare and exchange, single-threaded version */ #define cmpxchg(ptr, old, new) ({ \ - typeof(*(ptr)) __old = (old); \ - typeof(*(ptr)) __new = (new); \ - typeof(*(ptr)) __ret = *(ptr); \ - if (__ret == __old) \ - *(ptr) = __new; \ - __ret; \ + typeof(*(ptr)) __cmpxchg_old = (old); \ + typeof(*(ptr)) __cmpxchg_new = (new); \ + typeof(*(ptr)) __cmpxchg_ret = *(ptr); \ + if (__cmpxchg_ret == __cmpxchg_old) \ + *(ptr) = __cmpxchg_new; \ + __cmpxchg_ret; \ }) /* Reference count type */