From patchwork Sat Dec 20 23:23:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 997 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=1766273061; bh=uFo6nOMIqVeQcANhma56DDtJ1Ltfw8MhYAKvpDlEENk=; 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=Hgucs8pUHQWurkJAfMtnsQK++WWsAruC6PeN0/X15J2tnqsFbNmfSlyP/NKnGhHXK iMr98BVssSxMi7SCYp0U51Bf3TYUTgpU5poGvbe8Ry2F0CXWeuKQXVfiwf6TUqR8Xh /sU+qbzyqLo1kZaRIzgcNmBaoZIZaM3H9CNCOHJu8OUpSURe55xOZQOEpd/UooFQ8E b9zfkg48Zeni7ezNBwb2Myv+IfelZ775y7CYTWvD934w8pyNSixj0mlpY5eSm+MAkZ NFpRpbqfQVfiGh7qm1I8p1n8mEAG4qa7kAXGDi4xcGIau1v/1cR9XGEcSdbBAm9v++ hZ/PbNGeJeoKQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 20C7064C60 for ; Sat, 20 Dec 2025 16:24:21 -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 7tBA2bQQqUxQ for ; Sat, 20 Dec 2025 16:24:21 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1766273061; bh=uFo6nOMIqVeQcANhma56DDtJ1Ltfw8MhYAKvpDlEENk=; 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=Hgucs8pUHQWurkJAfMtnsQK++WWsAruC6PeN0/X15J2tnqsFbNmfSlyP/NKnGhHXK iMr98BVssSxMi7SCYp0U51Bf3TYUTgpU5poGvbe8Ry2F0CXWeuKQXVfiwf6TUqR8Xh /sU+qbzyqLo1kZaRIzgcNmBaoZIZaM3H9CNCOHJu8OUpSURe55xOZQOEpd/UooFQ8E b9zfkg48Zeni7ezNBwb2Myv+IfelZ775y7CYTWvD934w8pyNSixj0mlpY5eSm+MAkZ NFpRpbqfQVfiGh7qm1I8p1n8mEAG4qa7kAXGDi4xcGIau1v/1cR9XGEcSdbBAm9v++ hZ/PbNGeJeoKQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1042464C57 for ; Sat, 20 Dec 2025 16:24:21 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1766273059; bh=m6eNhyDsICkoQtMpZp57kxsJRKNnvNuG83OkyaAWQtA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d89IeEveXSlfFDISEn2XJorhvd/af4et6wOqadD8381CHIQVi+NURWo6z81eojuTi GsI6UOEJcqNXgIK/IWFogHxkUY72625PVQ8KtbsepqDj5Pk91II+IUnDfZ8VvKmjpt 4kFB5MiPkS3G99egVgYrz4iFHZLKx+a/AFxO3UFACNfV7inVP42N75AN6IeJx+0hvu vfDXQPlT/l+cLuTebZFkagRi738yhawHbKZJHGotJUaM5LVnqRdow0/MDaUeSTTe0Z 80xYJQpcecmZ16Prft+RF/t7AczGiKKvf3HnWQ5LYGGlxxTVQVg86ndEAIuvXqBAIQ QO6FYPn5THcjQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2CC3664C29; Sat, 20 Dec 2025 16:24:19 -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 LBwVSEVdGRsl; Sat, 20 Dec 2025 16:24:19 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1766273055; bh=XwansqDXMH7F5z/cYZqk1iRj7GDNyqChv+J8bd2phVM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jC1YA+oueJZK2XuWcCUA8JVmL6f3hTYX8la+vZFV/ukJRa8OL/QJ+qmY2J8CFJYDl I1I2zpoS5WodOqS1B39JUX5s3ejibD49C13iSK7btIs9yTUOSOE6PwCeClA7G1M8+e 0NJosLLQ3eB1oh/nemL9uXDhpHp7lqZqNiH2QC0F8wf6wnT2Sh6eln5HJwakjmpwXA 1nHbRQPSb2ZB5+llQVmfOJcvPbBYHKNEhKH1Lf+ubWrCwColwssoyuQb0dniFhlFeM thoW31RRKtrfF8rxHPgr6owcZOi8k2/C55Kru/hC5/v+KAOR/yAtGR2StpZmaozbhD 1z5zdJx2vsPVg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id BEF7F64C25; Sat, 20 Dec 2025 16:24:14 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 20 Dec 2025 16:23:43 -0700 Message-ID: <20251220232355.845414-4-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251220232355.845414-1-sjg@u-boot.org> References: <20251220232355.845414-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: O22D5POJ23OE2OTU2RXFGIMSVDQR3W64 X-Message-ID-Hash: O22D5POJ23OE2OTU2RXFGIMSVDQR3W64 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 03/10] ext4l: Add orphan.c and required 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 orphan.c to the ext4l build and fix various build issues: - Add atomic_inc/atomic_dec macros to ext4_uboot.h - Add s_flags member to struct super_block and SB_RDONLY constant - Add bdev_read_only() stub function - Add kvfree() and kvmalloc_array() to linux/slab.h - Add stub functions for orphan.c: ext4_reserve_inode_write, ext4_superblock_csum_set, ext4_mark_iloc_dirty, ext4_truncate, ext4_feature_set_ok, ext4_bread - Fix orphan.c to use U-Boot include pattern - Remove linux/atomic.h include from buffer_head.h (types provided by ext4_uboot.h) - Add kunit/static_stub.h and linux/nospec.h stub headers - Simplify seq_file.h macros Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- fs/ext4l/Makefile | 3 ++- fs/ext4l/ext4_uboot.h | 48 ++++++++++++++++++++++++++++++++----- fs/ext4l/extents_status.c | 1 - fs/ext4l/ialloc.c | 1 - fs/ext4l/orphan.c | 5 ++-- fs/ext4l/stub.c | 37 ++++++++++++++++++++++++++++ include/kunit/static_stub.h | 13 ++++++++++ include/linux/buffer_head.h | 12 ++++------ include/linux/nospec.h | 14 +++++++++++ include/linux/seq_file.h | 7 +++--- include/linux/slab.h | 10 ++++++++ 11 files changed, 127 insertions(+), 24 deletions(-) create mode 100644 include/kunit/static_stub.h create mode 100644 include/linux/nospec.h diff --git a/fs/ext4l/Makefile b/fs/ext4l/Makefile index 4878523eae3..c5adb121f77 100644 --- a/fs/ext4l/Makefile +++ b/fs/ext4l/Makefile @@ -6,4 +6,5 @@ obj-y := interface.o stub.o obj-y += balloc.o bitmap.o block_validity.o ext4_jbd2.o extents.o \ - extents_status.o hash.o ialloc.o indirect.o + extents_status.o hash.o ialloc.o indirect.o \ + orphan.o diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 943b474cdc8..6c328a5abf1 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -48,8 +48,24 @@ typedef struct { long counter; } atomic64_t; #define atomic_read(v) ((v)->counter) #define atomic_set(v, i) ((v)->counter = (i)) +#define atomic_inc(v) ((v)->counter++) +#define atomic_dec(v) ((v)->counter--) #define atomic64_read(v) ((v)->counter) #define atomic64_set(v, i) ((v)->counter = (i)) +#define atomic_dec_if_positive(v) (--(v)->counter) + +/* SMP stubs - U-Boot is single-threaded */ +#define raw_smp_processor_id() 0 + +/* 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; \ +}) /* Reference count type */ typedef struct { atomic_t refs; } refcount_t; @@ -58,10 +74,10 @@ typedef struct { atomic_t refs; } refcount_t; typedef int rwlock_t; /* spinlock_t is defined in linux/compat.h */ -#define read_lock(l) do { (void)(l); } while (0) -#define read_unlock(l) do { (void)(l); } while (0) -#define write_lock(l) do { (void)(l); } while (0) -#define write_unlock(l) do { (void)(l); } while (0) +#define read_lock(l) do { } while (0) +#define read_unlock(l) do { } while (0) +#define write_lock(l) do { } while (0) +#define write_unlock(l) do { } while (0) /* RB tree types - stubs */ struct rb_node { @@ -374,7 +390,12 @@ struct qstr; int __ext4_xattr_set_credits(struct super_block *sb, struct inode *inode, struct buffer_head *block_bh, size_t value_len, bool is_create); -/* ext4_init_security is declared in xattr.h */ +/* ext4_init_security - stub for files that don't include xattr.h */ +static inline int ext4_init_security(void *handle, struct inode *inode, + struct inode *dir, const struct qstr *qstr) +{ + return 0; +} /* inode state stubs */ #define is_bad_inode(inode) (0) @@ -431,7 +452,7 @@ int __ext4_xattr_set_credits(struct super_block *sb, struct inode *inode, #define rb_next(node) ((node)->rb_right) #define rb_prev(node) ((node)->rb_left) #define rb_insert_color(node, root) do { } while (0) -#define rb_erase(node, root) do { (void)(node); (void)(root); } while (0) +#define rb_erase(node, root) do { } while (0) #define rb_link_node(node, parent, rb_link) do { *(rb_link) = (node); } while (0) #define RB_EMPTY_ROOT(root) ((root)->rb_node == NULL) #define rbtree_postorder_for_each_entry_safe(pos, n, root, field) \ @@ -563,6 +584,9 @@ struct fstrim_range { /* block_device is defined in linux/fs.h */ +/* Superblock flags */ +#define SB_RDONLY (1 << 0) + /* super_block - minimal stub */ struct super_block { void *s_fs_info; @@ -570,6 +594,7 @@ struct super_block { unsigned char s_blocksize_bits; unsigned long s_magic; loff_t s_maxbytes; + unsigned long s_flags; struct rw_semaphore s_umount; struct sb_writers s_writers; struct block_device *s_bdev; @@ -577,9 +602,19 @@ struct super_block { struct dentry *s_root; }; +/* Block device read-only check - stub */ +static inline int bdev_read_only(struct block_device *bdev) +{ + return 0; +} + /* kuid_t and kgid_t - from linux/cred.h */ #include +/* Inode state bits */ +#define I_NEW (1 << 0) +#define I_FREEING (1 << 1) + /* inode - minimal stub */ struct inode { struct super_block *i_sb; @@ -594,6 +629,7 @@ struct inode { unsigned int i_generation; unsigned int i_flags; unsigned int i_blkbits; + unsigned long i_state; struct timespec64 i_atime; struct timespec64 i_mtime; struct timespec64 i_ctime; diff --git a/fs/ext4l/extents_status.c b/fs/ext4l/extents_status.c index 72377fadd70..485f3a2f5cc 100644 --- a/fs/ext4l/extents_status.c +++ b/fs/ext4l/extents_status.c @@ -1741,7 +1741,6 @@ int ext4_seq_es_shrinker_info_show(struct seq_file *seq, void *v) max->vfs_inode.i_ino, max->i_es_all_nr, max->i_es_shk_nr, div_u64(es_stats->es_stats_max_scan_time, 1000)); - (void)es_stats; /* Used only by seq_printf which is stubbed */ return 0; } diff --git a/fs/ext4l/ialloc.c b/fs/ext4l/ialloc.c index d72204a5d02..3d9edbcc1c3 100644 --- a/fs/ext4l/ialloc.c +++ b/fs/ext4l/ialloc.c @@ -16,7 +16,6 @@ #include "ext4_uboot.h" #include "ext4.h" #include "ext4_jbd2.h" -#include "xattr.h" /* * ialloc.c contains the inodes allocation and deallocation routines diff --git a/fs/ext4l/orphan.c b/fs/ext4l/orphan.c index 82d5e750145..32ec59b2978 100644 --- a/fs/ext4l/orphan.c +++ b/fs/ext4l/orphan.c @@ -1,10 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Ext4 orphan inode handling */ -#include -#include -#include +#include "ext4_uboot.h" #include "ext4.h" #include "ext4_jbd2.h" diff --git a/fs/ext4l/stub.c b/fs/ext4l/stub.c index 44cc4b7f52e..5a3eda0ad2e 100644 --- a/fs/ext4l/stub.c +++ b/fs/ext4l/stub.c @@ -395,3 +395,40 @@ int ext4_init_security(void *handle, struct inode *inode, struct inode *dir, { return 0; } + +/* + * Stubs for orphan.c + */ +struct ext4_iloc; + +int ext4_reserve_inode_write(void *handle, struct inode *inode, + struct ext4_iloc *iloc) +{ + return 0; +} + +void ext4_superblock_csum_set(struct super_block *sb) +{ +} + +int ext4_mark_iloc_dirty(void *handle, struct inode *inode, + struct ext4_iloc *iloc) +{ + return 0; +} + +int ext4_truncate(struct inode *inode) +{ + return 0; +} + +int ext4_feature_set_ok(struct super_block *sb, int readonly) +{ + return 1; +} + +struct buffer_head *ext4_bread(void *handle, struct inode *inode, + unsigned long long block, int create) +{ + return NULL; +} diff --git a/include/kunit/static_stub.h b/include/kunit/static_stub.h new file mode 100644 index 00000000000..995a919f641 --- /dev/null +++ b/include/kunit/static_stub.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _KUNIT_STATIC_STUB_H +#define _KUNIT_STATIC_STUB_H + +/* + * Stub header for U-Boot ext4l. + * + * KUnit static stubs are for kernel unit testing - not needed in U-Boot. + */ + +#define KUNIT_STATIC_STUB_REDIRECT(func, args...) do { } while (0) + +#endif /* _KUNIT_STATIC_STUB_H */ diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h index 9c663741bef..b7596a74108 100644 --- a/include/linux/buffer_head.h +++ b/include/linux/buffer_head.h @@ -12,14 +12,10 @@ #include #include #include - -/* Simple atomic_inc/dec for U-Boot (single-threaded) */ -#ifndef atomic_inc -#define atomic_inc(v) ((v)->counter++) -#endif -#ifndef atomic_dec -#define atomic_dec(v) ((v)->counter--) -#endif +/* + * Note: atomic_t and sector_t are expected to be defined by the including + * file (ext4_uboot.h) before including this header. + */ enum bh_state_bits { BH_Uptodate, /* Contains valid data */ diff --git a/include/linux/nospec.h b/include/linux/nospec.h new file mode 100644 index 00000000000..97d8271a00b --- /dev/null +++ b/include/linux/nospec.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_NOSPEC_H +#define _LINUX_NOSPEC_H + +/* + * Stub header for U-Boot ext4l. + * + * array_index_nospec bounds-checks array access, but in U-Boot's + * single-user environment this is not necessary. + */ + +#define array_index_nospec(index, size) (index) + +#endif /* _LINUX_NOSPEC_H */ diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h index 1d43f23348a..fb5dbf97708 100644 --- a/include/linux/seq_file.h +++ b/include/linux/seq_file.h @@ -11,9 +11,8 @@ struct seq_file { void *private; }; -#define seq_printf(m, fmt, ...) \ - do { (void)(m); (void)(fmt); } while (0) -#define seq_puts(m, s) do { (void)(m); (void)(s); } while (0) -#define seq_putc(m, c) do { (void)(m); (void)(c); } while (0) +#define seq_printf(m, fmt, ...) do { } while (0) +#define seq_puts(m, s) do { } while (0) +#define seq_putc(m, c) do { } while (0) #endif /* _LINUX_SEQ_FILE_H */ diff --git a/include/linux/slab.h b/include/linux/slab.h index 8da8f36e413..ac588dec6e2 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -67,6 +67,16 @@ static inline void kfree(const void *block) free((void *)block); } +static inline void kvfree(const void *addr) +{ + kfree(addr); +} + +static inline void *kvmalloc_array(size_t n, size_t size, gfp_t flags) +{ + return kmalloc_array(n, size, flags); +} + static inline void *krealloc(const void *p, size_t new_size, gfp_t flags) { return realloc((void *)p, new_size);