fs: Prepare for boot-time page size selection on arm64
Subsystems (26)
v2 cover fs: Prepare for boot-time page size selection on arm64
From: Eric Curtin <[email protected]>
This series is part of the boot-time page size selection work for arm64, posted as RFC [1]. With CONFIG_ARM64_BOOT_TIME_PAGE_SIZE=y, PAGE_SIZE, PAGE_SHIFT and PAGE_MASK are variables chosen at boot with arm64.pagesize=, so code that needs a compile-time constant (array sizes, struct layouts, static initialisers, BUILD_BUG_ON(), case labels, #if) has to use the new PAGE_SIZE_MIN/PAGE_SIZE_MAX limits or a run-time value instead. For fixed page sizes both limits equal PAGE_SIZE, so behaviour should not change.
The patches here convert filesystems. They apply on top of the core series [1], whose patch 1 adds PAGE_SIZE_MIN/MAX, and are otherwise independent of each other. Patches authored by Ryan Roberts come from his v1 [2], updated for v7.4-rc5. The full tree is at:
https://github.com/ericcurtin/linux/tree/boot-time-page-size-v2
Testing: allmodconfig with the option enabled builds cleanly on arm64 with all of these applied, and the defconfig kernel boots to userspace with 4K, 16K and 64K pages under QEMU/KVM (details in [1]). The code in this series is not otherwise exercised on hardware.
Tool use: these conversions were prepared with an LLM coding assistant (opencode with Claude Sonnet), driven by build errors and followed by an automated review pass. I have not hand-audited every patch, so please review with that in mind and tell me where you would prefer a different approach for your subsystem.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
Eric Curtin (17):
smb: client: Use PAGE_SIZE_MIN in the lock element build checks fs/resctrl: Define the kernfs_ops as page-size variables
ocfs2: Use PAGE_SIZE_MIN/MAX for the page-count limits
ntfs3: Use MAX_BUF_PER_PAGE_SIZE_MAX for struct ntfs_buffers
ntfs: Use PAGE_SIZE_MIN in NTFS_WOF_MAX_PAGES
nilfs2: Test PAGE_SIZE at run time in the rec_len conversions
jfs: Use PAGE_SIZE_MAX to size the metapage anchor arrays
isofs: Use PAGE_SIZE_MAX for zisofs_sink_page
ext4: Use PAGE_SIZE_MAX for the inline KUnit test data buffer
ext2: Test PAGE_SIZE at run time in the rec_len conversions
erofs: Make the decompressor bounce buffers flexible arrays
ecryptfs: Resolve the PAGE_SIZE cache sizes at cache creation time
dlm: Use PAGE_SIZE_MIN in the lowcomms buffer size build check
cramfs: Allocate the read buffers at init time
ceph: Use PAGE_SHIFT_MIN in the ceph_fscrypt_blocks() build check
btrfs: Use PAGE_SIZE_MAX in a static_assert and min_t() for PAGE_SHIFT
afs: Use PAGE_SIZE_MAX to size struct afs_xdr_dir_page
Ryan Roberts (5):
fuse: Check CUSE and ioctl buffer sizes against PAGE_SIZE_MIN
btrfs: Use PAGE_SIZE_MAX and PAGE_SIZE_MIN for compile-time checks
NFSv4: Use PAGE_SIZE_MIN to size ACL and xattr page arrays
coredump: Use PAGE_SIZE_MIN for the zero-fill buffer
fat: Use MAX_BUF_PER_PAGE_SIZE_MAX to size buffer_head arrays
RFC PATCH v2 1/22 smb: client: Use PAGE_SIZE_MIN in the lock element build checks
From: Eric Curtin <[email protected]>
With arm64 boot-time page size selection PAGE_SIZE is not a compile-time constant, so it cannot be used in BUILD_BUG_ON().
Compare the size of the LOCKING_ANDX_RANGE and smb2_lock_element lock buffers against PAGE_SIZE_MIN in cifs_push_mandatory_locks(), cifs_unlock_range(), smb2_unlock_range() and smb2_push_mandatory_locks(), so that the checks hold for every supported page size. The run-time clamps that use PAGE_SIZE are unchanged.
No functional change for compile-time page sizes.
--- fs/smb/client/file.c | 4 ++-- fs/smb/client/smb2file.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
fs/smb/client/file.c +2 -2
@@ -2417,7 +2417,7 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile) }BUILD_BUG_ON (sizeof (struct smb_hdr ) +sizeof (LOCKING_ANDX_RANGE ) > -PAGE_SIZE ); +PAGE_SIZE_MIN ); max_buf = min_t(unsigned int, max_buf - sizeof(struct smb_hdr),PAGE_SIZE ); max_num = (max_buf - sizeof(struct smb_hdr)) /
@@ -2793,7 +2793,7 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock,return -EINVAL ;BUILD_BUG_ON (sizeof (struct smb_hdr ) +sizeof (LOCKING_ANDX_RANGE ) > -PAGE_SIZE ); +PAGE_SIZE_MIN ); max_buf = min_t(unsigned int, max_buf - sizeof(struct smb_hdr),PAGE_SIZE ); max_num = (max_buf - sizeof(struct smb_hdr)) /
fs/smb/client/smb2file.c +2 -2
@@ -314,7 +314,7 @@ smb2_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock,if (max_buf <sizeof (struct smb2_lock_element ))return -EINVAL ; -BUILD_BUG_ON (sizeof (struct smb2_lock_element ) >PAGE_SIZE ); +BUILD_BUG_ON (sizeof (struct smb2_lock_element ) >PAGE_SIZE_MIN ); max_buf = min_t(unsigned int, max_buf, PAGE_SIZE); max_num = max_buf /sizeof (struct smb2_lock_element ); buf = kzalloc_objs(struct smb2_lock_element, max_num);
@@ -457,7 +457,7 @@ smb2_push_mandatory_locks(struct cifsFileInfo *cfile)return -EINVAL ; } -BUILD_BUG_ON (sizeof (struct smb2_lock_element ) >PAGE_SIZE ); +BUILD_BUG_ON (sizeof (struct smb2_lock_element ) >PAGE_SIZE_MIN ); max_buf = min_t(unsigned int, max_buf, PAGE_SIZE); max_num = max_buf /sizeof (struct smb2_lock_element ); buf = kzalloc_objs(struct smb2_lock_element, max_num);
RFC PATCH v2 2/22 fs/resctrl: Define the kernfs_ops as page-size variables
In reply to Eric CurtinFrom: Eric Curtin <[email protected]>
With arm64 boot-time page size selection PAGE_SIZE is not a compile-time constant, so it cannot initialise .atomic_write_len in a static const struct kernfs_ops.
Define rdtgroup_kf_single_ops and kf_mondata_ops with DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(), which keeps them const for fixed page sizes and initialises them from the run-time PAGE_SIZE before any initcall otherwise.
No functional change for compile-time page sizes.
--- fs/resctrl/rdtgroup.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
fs/resctrl/rdtgroup.c +5 -4
@@ -329,16 +329,17 @@ static ssize_t rdtgroup_file_write(struct kernfs_open_file *of, char *buf,return -EINVAL ; } -static const struct kernfs_ops rdtgroup_kf_single_ops = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct kernfs_ops, + rdtgroup_kf_single_ops, { .atomic_write_len = PAGE_SIZE, .write = rdtgroup_file_write, .seq_show = rdtgroup_seqfile_show, -}; +}); -static const struct kernfs_ops kf_mondata_ops = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct kernfs_ops, kf_mondata_ops, { .atomic_write_len = PAGE_SIZE, .seq_show = rdtgroup_mondata_show, -}; +});static bool is_cpu_list (struct kernfs_open_file *of) {
RFC PATCH v2 3/22 ocfs2: Use PAGE_SIZE_MIN/MAX for the page-count limits
In reply to Eric CurtinFrom: Eric Curtin <[email protected]>
With arm64 boot-time page size selection PAGE_SIZE is not a compile-time constant, so it cannot be used in #if or in the macros that size arrays in struct ocfs2_write_ctxt.
In aops.c, use PAGE_SIZE_MIN for OCFS2_MAX_CTXT_PAGES, since the smallest page needs the most pages per cluster, and PAGE_SIZE_MAX for OCFS2_MAX_CLUSTERS_PER_PAGE, since the largest page holds the most clusters. In dlmcommon.h, replace the #if that selected DLM_HASH_PAGES with a conditional expression, since the value is only used at run time.
No functional change for compile-time page sizes.
--- fs/ocfs2/aops.c | 6 +++--- fs/ocfs2/dlm/dlmcommon.h | 8 +++----- 2 files changed, 6 insertions(+), 8 deletions(-)
fs/ocfs2/aops.c +3 -3
@@ -663,13 +663,13 @@ int ocfs2_map_folio_blocks(struct folio *folio, u64 *p_blkno,return ret; } -#if (PAGE_SIZE >=OCFS2_MAX_CLUSTERSIZE ) +#if (PAGE_SIZE_MIN >=OCFS2_MAX_CLUSTERSIZE )#define OCFS2_MAX_CTXT_PAGES 1#else -#define OCFS2_MAX_CTXT_PAGES (OCFS2_MAX_CLUSTERSIZE / PAGE_SIZE) +#define OCFS2_MAX_CTXT_PAGES (OCFS2_MAX_CLUSTERSIZE / PAGE_SIZE_MIN)#endif -#define OCFS2_MAX_CLUSTERS_PER_PAGE (PAGE_SIZE / OCFS2_MIN_CLUSTERSIZE) +#define OCFS2_MAX_CLUSTERS_PER_PAGE (PAGE_SIZE_MAX / OCFS2_MIN_CLUSTERSIZE)struct ocfs2_unwritten_extent {struct list_head ue_node;
fs/ocfs2/dlm/dlmcommon.h +3 -5
@@ -18,11 +18,9 @@#define DLM_LOCK_RES_OWNER_UNKNOWN O2NM_MAX_NODES#define DLM_HASH_SIZE_DEFAULT (1 << 17) -#if DLM_HASH_SIZE_DEFAULT <PAGE_SIZE -# define DLM_HASH_PAGES 1 -#else -# define DLM_HASH_PAGES (DLM_HASH_SIZE_DEFAULT / PAGE_SIZE) -#endif +#define DLM_HASH_PAGES \ + (DLM_HASH_SIZE_DEFAULT < PAGE_SIZE ? 1 : \ + DLM_HASH_SIZE_DEFAULT / PAGE_SIZE)#define DLM_BUCKETS_PER_PAGE (PAGE_SIZE / sizeof(struct hlist_head))#define DLM_HASH_BUCKETS (DLM_HASH_PAGES * DLM_BUCKETS_PER_PAGE)
RFC PATCH v2 4/22 ntfs3: Use MAX_BUF_PER_PAGE_SIZE_MAX for struct ntfs_buffers
In reply to Eric CurtinFrom: Eric Curtin <[email protected]>
With arm64 boot-time page size selection PAGE_SIZE is not a compile-time constant, so PAGE_SIZE >> SECTOR_SHIFT cannot size the bh[] array in struct ntfs_buffers.
Use MAX_BUF_PER_PAGE_SIZE_MAX, the number of 512-byte buffers in the largest supported page, which is what the old expression evaluated to for a fixed page size.
No functional change for compile-time page sizes.
--- fs/ntfs3/ntfs_fs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs3/ntfs_fs.h +1 -1
@@ -130,7 +130,7 @@ struct runs_tree {struct ntfs_buffers {/* Biggest MFT / smallest cluster = 4096 / 512 = 8 */ /* Biggest index / smallest cluster = 4096 / 512 = 8 */ -struct buffer_head *bh[PAGE_SIZE >>SECTOR_SHIFT ]; +struct buffer_head *bh[MAX_BUF_PER_PAGE_SIZE_MAX ];u32 bytes;u32 nbufs;u32 off;
RFC PATCH v2 5/22 ntfs: Use PAGE_SIZE_MIN in NTFS_WOF_MAX_PAGES
In reply to Eric CurtinFrom: Eric Curtin <[email protected]>
With arm64 boot-time page size selection PAGE_SIZE is not a compile-time constant, but NTFS_WOF_MAX_PAGES sizes the folios[] and pages[] arrays.
Compute NTFS_WOF_MAX_PAGES with PAGE_SIZE_MIN, since the smallest page size needs the most pages to hold a compression unit.
No functional change for compile-time page sizes.
--- fs/ntfs/wof.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs/wof.c +1 -1
@@ -33,7 +33,7 @@ static const __le16 WOF_NAME[] = {#define NTFS_WOF_MAX_COMP_UNIT (1U << 15)#define NTFS_WOF_MAX_PAGES \ - DIV_ROUND_UP(NTFS_WOF_MAX_COMP_UNIT + PAGE_SIZE - 1, PAGE_SIZE) + DIV_ROUND_UP(NTFS_WOF_MAX_COMP_UNIT + PAGE_SIZE_MIN - 1, PAGE_SIZE_MIN)struct ntfs_wof_workspace {struct mutex *lock;
RFC PATCH v2 6/22 nilfs2: Test PAGE_SIZE at run time in the rec_len conversions
In reply to Eric CurtinFrom: Eric Curtin <[email protected]>
With arm64 boot-time page size selection PAGE_SIZE is not a compile-time constant, so it cannot be used in #if.
Replace the #if (PAGE_SIZE >= 65536) blocks in nilfs_rec_len_from_disk() and nilfs_rec_len_to_disk() with ordinary C conditions. The compiler still removes the dead code when PAGE_SIZE is constant.
No functional change for compile-time page sizes.
--- fs/nilfs2/dir.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
fs/nilfs2/dir.c +6 -8
@@ -38,21 +38,19 @@ static inline unsigned int nilfs_rec_len_from_disk(__le16 dlen) {unsigned int len =le16_to_cpu (dlen); -#if (PAGE_SIZE >=65536 ) -if (len ==NILFS_MAX_REC_LEN ) +if (PAGE_SIZE >=65536 && len ==NILFS_MAX_REC_LEN )return 1 <<16 ; -#endif return len; }static inline __le16 nilfs_rec_len_to_disk (unsigned int len) { -#if (PAGE_SIZE >=65536 ) -if (len == (1 <<16 )) -return cpu_to_le16 (NILFS_MAX_REC_LEN ); +if (PAGE_SIZE >=65536 ) { +if (len == (1 <<16 )) +return cpu_to_le16 (NILFS_MAX_REC_LEN ); -BUG_ON (len > (1 <<16 )); -#endif +BUG_ON (len > (1 <<16 )); + }return cpu_to_le16 (len); }
RFC PATCH v2 7/22 jfs: Use PAGE_SIZE_MAX to size the metapage anchor arrays
In reply to Eric CurtinFrom: Eric Curtin <[email protected]>
With arm64 boot-time page size selection PAGE_SIZE is not a compile-time constant, so MPS_PER_PAGE cannot be used in #if or as an array size.
Add MPS_PER_PAGE_MAX, based on PAGE_SIZE_MAX, and use it for the #if that selects the multi-metapage-per-page code, for struct meta_anchor's mp[] array and for the mps[] array in __metapage_migrate_folio(). MPS_PER_PAGE continues to be used for run-time indexing and loops.
No functional change for compile-time page sizes.
--- fs/jfs/jfs_metapage.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/jfs/jfs_metapage.c +4 -3
@@ -71,14 +71,15 @@ static struct kmem_cache *metapage_cache;static mempool_t *metapage_mempool;#define MPS_PER_PAGE (PAGE_SIZE >> L2PSIZE) +#define MPS_PER_PAGE_MAX (PAGE_SIZE_MAX >> L2PSIZE) -#if MPS_PER_PAGE >1 +#if MPS_PER_PAGE_MAX >1 struct meta_anchor {int mp_count;atomic_t io_count;blk_status_t status; -struct metapage *mp[MPS_PER_PAGE ]; +struct metapage *mp[MPS_PER_PAGE_MAX ]; };static inline struct metapage *folio_to_mp (struct folio *folio,int offset)
@@ -158,7 +159,7 @@ static int __metapage_migrate_folio(struct address_space *mapping, enum migrate_mode mode) {struct meta_anchor *src_anchor = src->private; -struct metapage *mps[MPS_PER_PAGE ] = {0 }; +struct metapage *mps[MPS_PER_PAGE_MAX ] = {0 };struct metapage *mp;int i, rc;
RFC PATCH v2 8/22 isofs: Use PAGE_SIZE_MAX for zisofs_sink_page
In reply to Eric CurtinFrom: Eric Curtin <[email protected]>
With arm64 boot-time page size selection PAGE_SIZE is not a compile-time constant, so it cannot size the static zisofs_sink_page[] array.
Size the array with PAGE_SIZE_MAX so that it can absorb a full page for any supported page size.
No functional change for compile-time page sizes.
--- fs/isofs/compress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/isofs/compress.c +1 -1
@@ -23,7 +23,7 @@#include "zisofs.h" /* This should probably be global. */ -static char zisofs_sink_page[PAGE_SIZE ]; +static char zisofs_sink_page[PAGE_SIZE_MAX ];/* * This contains the zlib memory allocation and the mutex for the
RFC PATCH v2 9/22 ext4: Use PAGE_SIZE_MAX for the inline KUnit test data buffer
In reply to Eric CurtinFrom: Eric Curtin <[email protected]>
With arm64 boot-time page size selection PAGE_SIZE is not a compile-time constant, so it cannot size the data_block_buf[] member of struct inline_test_ctx.
Size data_block_buf[] with PAGE_SIZE_MAX so that the buffer is large enough for every supported page size.
No functional change for compile-time page sizes.
--- fs/ext4/inline-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/inline-test.c +1 -1
@@ -52,7 +52,7 @@ struct inline_test_ctx {struct buffer_head iloc_bh;u8 raw_inode_buf[TEST_BLOCK_SIZE ];struct buffer_head data_bh; -u8 data_block_buf[PAGE_SIZE ]; +u8 data_block_buf[PAGE_SIZE_MAX ];int get_inode_loc_err;int map_blocks_ret;ext4_fsblk_t map_pblk;
RFC PATCH v2 10/22 ext2: Test PAGE_SIZE at run time in the rec_len conversions
In reply to Eric CurtinFrom: Eric Curtin <[email protected]>
With arm64 boot-time page size selection PAGE_SIZE is not a compile-time constant, so it cannot be used in #if.
Replace the #if (PAGE_SIZE >= 65536) blocks in ext2_rec_len_from_disk() and ext2_rec_len_to_disk() with ordinary C conditions. The compiler still removes the dead code when PAGE_SIZE is constant.
No functional change for compile-time page sizes.
--- fs/ext2/dir.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
fs/ext2/dir.c +7 -9
@@ -40,21 +40,19 @@ static inline unsigned ext2_rec_len_from_disk(__le16 dlen) {unsigned len =le16_to_cpu (dlen); -#if (PAGE_SIZE >=65536 ) -if (len ==EXT2_MAX_REC_LEN ) +if (PAGE_SIZE >=65536 && len ==EXT2_MAX_REC_LEN )return 1 <<16 ; -#endif return len; }static inline __le16 ext2_rec_len_to_disk (unsigned len) { -#if (PAGE_SIZE >=65536 ) -if (len == (1 <<16 )) -return cpu_to_le16 (EXT2_MAX_REC_LEN ); -else -BUG_ON (len > (1 <<16 )); -#endif +if (PAGE_SIZE >=65536 ) { +if (len == (1 <<16 )) +return cpu_to_le16 (EXT2_MAX_REC_LEN ); +else +BUG_ON (len > (1 <<16 )); + }return cpu_to_le16 (len); }
RFC PATCH v2 11/22 erofs: Make the decompressor bounce buffers flexible arrays
In reply to Eric CurtinFrom: Eric Curtin <[email protected]>
With arm64 boot-time page size selection PAGE_SIZE is not a compile-time constant, so it cannot be used as the size of the bounce[] member in the deflate, lzma and zstd stream structures.
Turn bounce[] into a flexible array member in struct z_erofs_deflate, z_erofs_lzma and z_erofs_zstd, move it to the end of struct z_erofs_zstd, and allocate the structures with kzalloc_flex(*strm, bounce, PAGE_SIZE) so that the run-time page size sets the buffer size.
In zdata.c, compute Z_EROFS_PCLUSTER_MAX_PAGES with PAGE_SIZE_MIN. It is used as an upper bound and must be constant.
No functional change for compile-time page sizes.
--- fs/erofs/decompressor_deflate.c | 4 ++-- fs/erofs/decompressor_lzma.c | 4 ++-- fs/erofs/decompressor_zstd.c | 4 ++-- fs/erofs/zdata.c | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-)
fs/erofs/decompressor_deflate.c +2 -2
@@ -5,7 +5,7 @@struct z_erofs_deflate {struct z_erofs_deflate *next;struct z_stream_s z; -u8 bounce[PAGE_SIZE ]; +u8 bounce[]; };static DEFINE_SPINLOCK (z_erofs_deflate_lock);
@@ -71,7 +71,7 @@ static int z_erofs_load_deflate_config(struct super_block *sb, ++z_erofs_deflate_avail_strms) {struct z_erofs_deflate *strm; - strm =kzalloc_obj (*strm); + strm =kzalloc_flex (*strm, bounce,PAGE_SIZE );if (!strm) goto failed;/* XXX: in-kernel zlib cannot customize windowbits */
fs/erofs/decompressor_lzma.c +2 -2
@@ -6,7 +6,7 @@ struct z_erofs_lzma {struct z_erofs_lzma *next;struct xz_dec_microlzma *state;unsigned int dict_size; -u8 bounce[PAGE_SIZE ]; +u8 bounce[]; };/* considering the LZMA performance, no need to use a lockless list for now */
@@ -56,7 +56,7 @@ static int __init z_erofs_lzma_init(void) CONFIG_EROFS_FS_ZIP_LZMA_DEFAULT_MAX_STREAMS);for (i =0 ; i < z_erofs_lzma_nstrms; ++i) { -struct z_erofs_lzma *strm =kzalloc_obj (*strm); +struct z_erofs_lzma *strm =kzalloc_flex (*strm, bounce,PAGE_SIZE );if (!strm) {z_erofs_lzma_exit ();
fs/erofs/decompressor_zstd.c +2 -2
@@ -4,9 +4,9 @@struct z_erofs_zstd {struct z_erofs_zstd *next; -u8 bounce[PAGE_SIZE ];void *wksp;unsigned int wkspsz; +u8 bounce[]; };static DEFINE_SPINLOCK (z_erofs_zstd_lock);
@@ -59,7 +59,7 @@ static int __init z_erofs_zstd_init(void) ++z_erofs_zstd_avail_strms) {struct z_erofs_zstd *strm; - strm =kzalloc_obj (*strm); + strm =kzalloc_flex (*strm, bounce,PAGE_SIZE );if (!strm) {z_erofs_zstd_exit ();return -ENOMEM ;
fs/erofs/zdata.c +1 -1
@@ -10,7 +10,7 @@#include <trace/events/erofs.h> #define Z_EROFS_MAX_SYNC_DECOMPRESS_BYTES 12288 -#define Z_EROFS_PCLUSTER_MAX_PAGES (Z_EROFS_PCLUSTER_MAX_SIZE / PAGE_SIZE) +#define Z_EROFS_PCLUSTER_MAX_PAGES (Z_EROFS_PCLUSTER_MAX_SIZE / PAGE_SIZE_MIN)#define Z_EROFS_INLINE_BVECS 2struct z_erofs_bvec {
RFC PATCH v2 12/22 ecryptfs: Resolve the PAGE_SIZE cache sizes at cache creation time
In reply to Eric CurtinFrom: Eric Curtin <[email protected]>
With arm64 boot-time page size selection PAGE_SIZE is not a compile-time constant, so it cannot initialise the static ecryptfs_cache_infos[] table.
Drop the PAGE_SIZE sizes of the ecryptfs_headers and ecryptfs_xattr_cache entries, and treat a size of 0 as PAGE_SIZE in ecryptfs_init_kmem_caches(), where the value is known at run time.
No functional change for compile-time page sizes.
--- fs/ecryptfs/main.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
fs/ecryptfs/main.c +2 -4
@@ -655,7 +655,7 @@ inode_info_init_once(void *vptr)static struct ecryptfs_cache_info {struct kmem_cache **cache;const char *name; -size_t size; +size_t size;/* 0 means PAGE_SIZE */ slab_flags_t flags;void (*ctor)(void *obj); } ecryptfs_cache_infos[] = {
@@ -684,12 +684,10 @@ static struct ecryptfs_cache_info { { .cache = &ecryptfs_header_cache, .name = "ecryptfs_headers", - .size = PAGE_SIZE, }, { .cache = &ecryptfs_xattr_cache, .name = "ecryptfs_xattr_cache", - .size = PAGE_SIZE, }, { .cache = &ecryptfs_key_record_cache,
@@ -744,7 +742,7 @@ static int ecryptfs_init_kmem_caches(void)struct ecryptfs_cache_info *info; info = &ecryptfs_cache_infos[i]; - *(info->cache) =kmem_cache_create (info->name, info->size,0 , + *(info->cache) =kmem_cache_create (info->name, info->size ?:PAGE_SIZE ,0 ,SLAB_HWCACHE_ALIGN | info->flags, info->ctor);if (!*(info->cache)) {ecryptfs_free_kmem_caches ();
RFC PATCH v2 13/22 dlm: Use PAGE_SIZE_MIN in the lowcomms buffer size build check
In reply to Eric CurtinFrom: Eric Curtin <[email protected]>
With arm64 boot-time page size selection PAGE_SIZE is not a compile-time constant, so it cannot be used in BUILD_BUG_ON().
Check DLM_MAX_SOCKET_BUFSIZE against PAGE_SIZE_MIN in dlm_lowcomms_new_msg() so that the message buffer fits in a page for every supported page size.
No functional change for compile-time page sizes.
--- fs/dlm/lowcomms.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/dlm/lowcomms.c +1 -1
@@ -1266,7 +1266,7 @@ struct dlm_msg *dlm_lowcomms_new_msg(int nodeid, int len, char **ppc,if (len >DLM_MAX_SOCKET_BUFSIZE || len <sizeof (struct dlm_header )) { -BUILD_BUG_ON (PAGE_SIZE <DLM_MAX_SOCKET_BUFSIZE ); +BUILD_BUG_ON (PAGE_SIZE_MIN <DLM_MAX_SOCKET_BUFSIZE );log_print ("failed to allocate a buffer of size %d" , len);WARN_ON_ONCE (1 );return NULL ;
RFC PATCH v2 14/22 cramfs: Allocate the read buffers at init time
In reply to Eric CurtinFrom: Eric Curtin <[email protected]>
With arm64 boot-time page size selection PAGE_SIZE is not a compile-time constant, so the statically sized read_buffers[] array, whose size is BLKS_PER_BUF * PAGE_SIZE, cannot be declared as before.
Make read_buffers[] an array of pointers and allocate each buffer with kmalloc() in cramfs_alloc_read_buffers(), called from init_cramfs_fs(). The buffers are only needed when CONFIG_CRAMFS_BLOCKDEV is enabled, so nothing is allocated otherwise. Free them on the init error paths and on module exit.
The buffers are now allocated from the slab instead of living in .bss.
--- fs/cramfs/inode.c | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-)
fs/cramfs/inode.c +38 -3
@@ -181,7 +181,7 @@ static struct inode *get_cramfs_inode(struct super_block *sb,#define BLKS_PER_BUF (1 << BLKS_PER_BUF_SHIFT)#define BUFFER_SIZE (BLKS_PER_BUF*PAGE_SIZE) -static unsigned char read_buffers[READ_BUFFERS ][BUFFER_SIZE ]; +static unsigned char *read_buffers[READ_BUFFERS ];static unsigned buffer_blocknr[READ_BUFFERS ];static struct super_block *buffer_dev[READ_BUFFERS ];static int next_buffer;
@@ -987,16 +987,50 @@ static struct file_system_type cramfs_fs_type = { };MODULE_ALIAS_FS ("cramfs" ); +static void cramfs_free_read_buffers (void ) +{ +int i; + +for (i =0 ; i <READ_BUFFERS ; i++) +kfree (read_buffers[i]); +} + +static int __init cramfs_alloc_read_buffers (void ) +{ +int i; + +if (!IS_ENABLED (CONFIG_CRAMFS_BLOCKDEV )) +return 0 ; + +for (i =0 ; i <READ_BUFFERS ; i++) { + read_buffers[i] =kmalloc (BUFFER_SIZE ,GFP_KERNEL ); +if (!read_buffers[i]) { +cramfs_free_read_buffers (); +return -ENOMEM ; + } + } +return 0 ; +} +static int __init init_cramfs_fs (void ) {int rv; - rv =cramfs_uncompress_init (); + rv =cramfs_alloc_read_buffers ();if (rv <0 )return rv; + rv =cramfs_uncompress_init (); +if (rv <0 ) + goto err_buffers; rv =register_filesystem (&cramfs_fs_type);if (rv <0 ) -cramfs_uncompress_exit (); + goto err_uncompress; +return 0 ; + +err_uncompress: +cramfs_uncompress_exit (); +err_buffers: +cramfs_free_read_buffers ();return rv; }
@@ -1004,6 +1038,7 @@ static void __exit exit_cramfs_fs(void) {cramfs_uncompress_exit ();unregister_filesystem (&cramfs_fs_type); +cramfs_free_read_buffers (); }module_init (init_cramfs_fs)
RFC PATCH v2 15/22 ceph: Use PAGE_SHIFT_MIN in the ceph_fscrypt_blocks() build check
In reply to Eric CurtinFrom: Eric Curtin <[email protected]>
With arm64 boot-time page size selection PAGE_SHIFT is not a compile- time constant, so it cannot be used in BUILD_BUG_ON().
ceph_fscrypt_blocks() asserts that a crypto block does not span more than one page. Compare CEPH_FSCRYPT_BLOCK_SHIFT against PAGE_SHIFT_MIN so that the assertion holds for every supported page size.
No functional change for compile-time page sizes.
--- fs/ceph/crypto.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ceph/crypto.h +1 -1
@@ -122,7 +122,7 @@ int ceph_fscrypt_prepare_readdir(struct inode *dir);static inline unsigned int ceph_fscrypt_blocks (u64 off,u64 len) {/* crypto blocks cannot span more than one page */ -BUILD_BUG_ON (CEPH_FSCRYPT_BLOCK_SHIFT >PAGE_SHIFT ); +BUILD_BUG_ON (CEPH_FSCRYPT_BLOCK_SHIFT >PAGE_SHIFT_MIN );return ((off+len+CEPH_FSCRYPT_BLOCK_SIZE -1 ) >>CEPH_FSCRYPT_BLOCK_SHIFT ) - (off >>CEPH_FSCRYPT_BLOCK_SHIFT );
RFC PATCH v2 16/22 btrfs: Use PAGE_SIZE_MAX in a static_assert and min_t() for PAGE_SHIFT
In reply to Eric CurtinFrom: Eric Curtin <[email protected]>
With arm64 boot-time page size selection PAGE_SIZE and PAGE_SHIFT are not compile-time constants.
Check BTRFS_MAX_FOLIO_SIZE against PAGE_SIZE_MAX in the static_assert so that it holds for every supported page size. In index_one_bio(), use min_t(u32, ...) to compare sectorsize_bits with PAGE_SHIFT, because PAGE_SHIFT is a variable of a different type and min() would not accept the mix.
No functional change for compile-time page sizes.
--- fs/btrfs/fs.h | 2 +- fs/btrfs/raid56.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/fs.h +1 -1
@@ -56,7 +56,7 @@ struct btrfs_space_info;/* The maximum folio size btrfs supports. */ #define BTRFS_MAX_FOLIO_SIZE (SZ_2M) -static_assert (BTRFS_MAX_FOLIO_SIZE >PAGE_SIZE ); +static_assert (BTRFS_MAX_FOLIO_SIZE >PAGE_SIZE_MAX );/* * The maximum number of blocks a huge folio can support.
fs/btrfs/raid56.c +1 -1
@@ -1289,7 +1289,7 @@ static void index_one_bio(struct btrfs_raid_bio *rbio, struct bio *bio) {struct btrfs_fs_info *fs_info = rbio->bioc->fs_info;const u32 step =min (fs_info->sectorsize,PAGE_SIZE ); -const u32 step_bits =min (fs_info->sectorsize_bits,PAGE_SHIFT ); +const u32 step_bits =min_t (u32, fs_info->sectorsize_bits,PAGE_SHIFT );struct bvec_iter iter = bio->bi_iter;phys_addr_t paddr; u32 offset = (bio->bi_iter.bi_sector << SECTOR_SHIFT) -
RFC PATCH v2 17/22 afs: Use PAGE_SIZE_MAX to size struct afs_xdr_dir_page
In reply to Eric CurtinFrom: Eric Curtin <[email protected]>
With arm64 boot-time page size selection PAGE_SIZE is not a compile-time constant, so AFS_DIR_BLOCKS_PER_PAGE cannot be used as an array size.
Add AFS_DIR_BLOCKS_PER_PAGE_MAX, based on PAGE_SIZE_MAX, and use it for the blocks[] array of struct afs_xdr_dir_page. The structure is then large enough for the largest page size. AFS_DIR_BLOCKS_PER_PAGE keeps using PAGE_SIZE for run-time use.
No functional change for compile-time page sizes.
--- fs/afs/xdr_fs.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/afs/xdr_fs.h +2 -1
@@ -38,6 +38,7 @@ struct afs_xdr_AFSFetchStatus {#define AFS_DIR_SLOTS_PER_BLOCK 64#define AFS_DIR_BLOCK_SIZE 2048#define AFS_DIR_BLOCKS_PER_PAGE (PAGE_SIZE / AFS_DIR_BLOCK_SIZE) +#define AFS_DIR_BLOCKS_PER_PAGE_MAX (PAGE_SIZE_MAX / AFS_DIR_BLOCK_SIZE)#define AFS_DIR_MAX_SLOTS 65536#define AFS_DIR_BLOCKS_WITH_CTR 128#define AFS_DIR_MAX_BLOCKS 1023
@@ -99,7 +100,7 @@ union afs_xdr_dir_block {* Directory layout on a linux VM page. */ struct afs_xdr_dir_page { -union afs_xdr_dir_block blocks[AFS_DIR_BLOCKS_PER_PAGE ]; +union afs_xdr_dir_block blocks[AFS_DIR_BLOCKS_PER_PAGE_MAX ]; };/*
RFC PATCH v2 18/22 fuse: Check CUSE and ioctl buffer sizes against PAGE_SIZE_MIN
In reply to Eric CurtinFrom: Ryan Roberts <[email protected]>
The BUILD_BUG_ON() checks that CUSE_INIT_INFO_MAX in cuse_send_init() and the ioctl iovec array in fuse_do_ioctl() fit in a page cannot use PAGE_SIZE, which is not a compile-time constant with arm64 boot-time page size selection. Compare against PAGE_SIZE_MIN, the smallest page size that can be in use, so the assumptions hold for every page size.
--- fs/fuse/cuse.c | 2 +- fs/fuse/ioctl.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
fs/fuse/cuse.c +1 -1
@@ -438,7 +438,7 @@ static int cuse_send_init(struct cuse_conn *cc)struct cuse_init_args *ia;struct fuse_args_pages *ap; -BUILD_BUG_ON (CUSE_INIT_INFO_MAX >PAGE_SIZE ); +BUILD_BUG_ON (CUSE_INIT_INFO_MAX >PAGE_SIZE_MIN ); rc = -ENOMEM ;
fs/fuse/ioctl.c +2 -1
@@ -246,7 +246,8 @@ long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,#endif /* assume all the iovs returned by client always fits in a page */ -BUILD_BUG_ON (sizeof (struct fuse_ioctl_iovec ) *FUSE_IOCTL_MAX_IOV >PAGE_SIZE ); +BUILD_BUG_ON (sizeof (struct fuse_ioctl_iovec ) *FUSE_IOCTL_MAX_IOV > +PAGE_SIZE_MIN ); err = -ENOMEM ; ap.folios =fuse_folios_alloc (fm->fc->max_pages,GFP_KERNEL , &ap.descs);
RFC PATCH v2 19/22 btrfs: Use PAGE_SIZE_MAX and PAGE_SIZE_MIN for compile-time checks
In reply to Eric CurtinFrom: Ryan Roberts <[email protected]>
With boot-time page size selection PAGE_SIZE is not a compile-time constant, so it cannot be used in static assertions or to size arrays.
Check alignment against PAGE_SIZE_MAX in the static_assert()s for BTRFS_MAX_COMPRESSED, the defrag CLUSTER_SIZE, and BTRFS_STRIPE_LEN in scrub. A size aligned to PAGE_SIZE_MAX is also aligned to any smaller page size.
Compute INLINE_EXTENT_BUFFER_PAGES with PAGE_SIZE_MIN, which gives the largest number of pages per extent buffer and so is the worst case for the inline pages[] array.
No functional change for compile-time page sizes.
--- fs/btrfs/compression.h | 2 +- fs/btrfs/defrag.c | 2 +- fs/btrfs/extent_io.h | 2 +- fs/btrfs/scrub.c | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-)
fs/btrfs/compression.h +1 -1
@@ -34,7 +34,7 @@ struct btrfs_ordered_extent;/* Maximum length of compressed data stored on disk */ #define BTRFS_MAX_COMPRESSED (SZ_128K)#define BTRFS_MAX_COMPRESSED_PAGES (BTRFS_MAX_COMPRESSED / PAGE_SIZE) -static_assert ((BTRFS_MAX_COMPRESSED %PAGE_SIZE ) ==0 ); +static_assert ((BTRFS_MAX_COMPRESSED %PAGE_SIZE_MAX ) ==0 );/* The max size for a single worker to compress. */ #define BTRFS_COMPRESSION_CHUNK_SIZE (SZ_512K)
fs/btrfs/defrag.c +1 -1
@@ -1117,7 +1117,7 @@ static int defrag_collect_targets(struct btrfs_inode *inode, }#define CLUSTER_SIZE (SZ_256K) -static_assert (PAGE_ALIGNED (CLUSTER_SIZE )); +static_assert (IS_ALIGNED (CLUSTER_SIZE ,PAGE_SIZE_MAX ));/* * Defrag one contiguous target range.
fs/btrfs/extent_io.h +1 -1
@@ -81,7 +81,7 @@ enum {int __init extent_buffer_init_cachep (void );void __cold extent_buffer_free_cachep (void ); -#define INLINE_EXTENT_BUFFER_PAGES (BTRFS_MAX_METADATA_BLOCKSIZE / PAGE_SIZE) +#define INLINE_EXTENT_BUFFER_PAGES (BTRFS_MAX_METADATA_BLOCKSIZE / PAGE_SIZE_MIN)struct extent_buffer {u64 start;u32 len;
fs/btrfs/scrub.c +2 -2
@@ -219,8 +219,8 @@ struct scrub_ctx {refcount_t refs; }; -static_assert (BTRFS_STRIPE_LEN >=PAGE_SIZE ); -static_assert (IS_ALIGNED (BTRFS_STRIPE_LEN ,PAGE_SIZE )); +static_assert (BTRFS_STRIPE_LEN >=PAGE_SIZE_MAX ); +static_assert (IS_ALIGNED (BTRFS_STRIPE_LEN ,PAGE_SIZE_MAX ));#define scrub_calc_start_bit (stripe, name, block_nr) \ ({ \
Re: [RFC PATCH v2 19/22] btrfs: Use PAGE_SIZE_MAX and PAGE_SIZE_MIN for compile-time checks
Quoted 14 lines · Eric Curtin
From: Ryan Roberts <[email protected]>
With boot-time page size selection
PAGE_SIZEis not a compile-time constant, so it cannot be used in static assertions or to size arrays.Check alignment against
PAGE_SIZE_MAXin the static_assert()s forBTRFS_MAX_COMPRESSED, the defragCLUSTER_SIZE, andBTRFS_STRIPE_LENin scrub. A size aligned toPAGE_SIZE_MAXis also aligned to any smaller page size.Compute
INLINE_EXTENT_BUFFER_PAGESwithPAGE_SIZE_MIN, which gives the largest number of pages per extent buffer and so is the worst case for the inline pages[] array.
Quoted 6 lines
No functional change for compile-time page sizes.
Co-developed-by Petr Tesarik <[email protected]>Signed-off-by Petr Tesarik <[email protected]>Signed-off-by Ryan Roberts <[email protected]>Signed-off-by Eric Curtin <[email protected]>
I guess as long as the PAGE_SIZE_MAX on arm64 is still no larger than 64K, it would be fine for btrfs.
But if one day it's going to support 128K page size, then btrfs will have a lot of extra work to adapt for that...
Thanks,
Qu
Quoted 61 lines
--- fs/btrfs/compression.h | 2 +- fs/btrfs/defrag.c | 2 +- fs/btrfs/extent_io.h | 2 +- fs/btrfs/scrub.c | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-)fs/btrfs/compression.h +1
-1@@ -34,7 +34,7 @@ struct btrfs_ordered_extent;/* Maximum length of compressed data stored on disk */ #define BTRFS_MAX_COMPRESSED (SZ_128K)#define BTRFS_MAX_COMPRESSED_PAGES (BTRFS_MAX_COMPRESSED / PAGE_SIZE) -static_assert ((BTRFS_MAX_COMPRESSED %PAGE_SIZE ) ==0 ); +static_assert ((BTRFS_MAX_COMPRESSED %PAGE_SIZE_MAX ) ==0 );/* The max size for a single worker to compress. */ #define BTRFS_COMPRESSION_CHUNK_SIZE (SZ_512K)fs/btrfs/defrag.c +1
-1@@ -1117,7 +1117,7 @@ static int defrag_collect_targets(struct btrfs_inode *inode, }#define CLUSTER_SIZE (SZ_256K) -static_assert (PAGE_ALIGNED (CLUSTER_SIZE )); +static_assert (IS_ALIGNED (CLUSTER_SIZE ,PAGE_SIZE_MAX ));/* * Defrag one contiguous target range. fs/btrfs/extent_io.h +1
-1@@ -81,7 +81,7 @@ enum {int __init extent_buffer_init_cachep (void );void __cold extent_buffer_free_cachep (void ); -#define INLINE_EXTENT_BUFFER_PAGES (BTRFS_MAX_METADATA_BLOCKSIZE / PAGE_SIZE) +#define INLINE_EXTENT_BUFFER_PAGES (BTRFS_MAX_METADATA_BLOCKSIZE / PAGE_SIZE_MIN)struct extent_buffer {u64 start;u32 len;fs/btrfs/scrub.c +2
-2@@ -219,8 +219,8 @@ struct scrub_ctx {refcount_t refs; }; -static_assert (BTRFS_STRIPE_LEN >=PAGE_SIZE ); -static_assert (IS_ALIGNED (BTRFS_STRIPE_LEN ,PAGE_SIZE )); +static_assert (BTRFS_STRIPE_LEN >=PAGE_SIZE_MAX ); +static_assert (IS_ALIGNED (BTRFS_STRIPE_LEN ,PAGE_SIZE_MAX ));#define scrub_calc_start_bit (stripe, name, block_nr) \ ({ \
RFC PATCH v2 20/22 NFSv4: Use PAGE_SIZE_MIN to size ACL and xattr page arrays
In reply to Eric CurtinFrom: Ryan Roberts <[email protected]>
With boot-time page size selection PAGE_SIZE is not a compile-time constant, but NFS4ACL_MAXPAGES and NFS4XATTR_MAXPAGES are used to size on-stack page pointer arrays.
Compute both from PAGE_SIZE_MIN, which gives the largest possible page count. Likewise, make the BUILD_BUG_ON() in nfs4_xattr_alloc_entry() compare against PAGE_SIZE_MIN; if it holds for the smallest page size it holds for all of them.
No functional change for compile-time page sizes.
--- fs/nfs/nfs42proc.c | 2 +- fs/nfs/nfs42xattr.c | 2 +- fs/nfs/nfs4proc.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
fs/nfs/nfs42proc.c +1 -1
@@ -1388,7 +1388,7 @@ int nfs42_proc_clone(struct file *src_f, struct file *dst_f,return err; } -#define NFS4XATTR_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) +#define NFS4XATTR_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE_MIN)static int _nfs42_proc_removexattr (struct inode *inode,const char *name) {
fs/nfs/nfs42xattr.c +1 -1
@@ -183,7 +183,7 @@ nfs4_xattr_alloc_entry(const char *name, const void *value,uint32_t flags;BUILD_BUG_ON (sizeof (struct nfs4_xattr_entry ) + -XATTR_NAME_MAX +1 >PAGE_SIZE ); +XATTR_NAME_MAX +1 >PAGE_SIZE_MIN ); alloclen =sizeof (struct nfs4_xattr_entry );if (name !=NULL ) {
fs/nfs/nfs4proc.c +1 -1
@@ -6003,7 +6003,7 @@ static bool nfs4_server_supports_acls(const struct nfs_server *server,* it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_SIZE) bytes on * the stack. */ -#define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) +#define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE_MIN)int nfs4_buf_to_pages_noslab (const void *buf,size_t buflen,struct page **pages)
RFC PATCH v2 21/22 coredump: Use PAGE_SIZE_MIN for the zero-fill buffer
In reply to Eric CurtinFrom: Ryan Roberts <[email protected]>
With boot-time page size selection PAGE_SIZE is not a compile-time constant, so it cannot size the static zeroes[] buffer in __dump_skip(), and some fs code must be reworked as well.
In __dump_skip(), size zeroes[] and the chunk length with PAGE_SIZE_MIN. This is the old PAGE_SIZE when the page size is fixed; PAGE_SIZE_MIN is preferred over PAGE_SIZE_MAX to save memory.
In binfmt_elf, turn the #if choosing ELF_MIN_ALIGN into a ternary expression that evaluates at run time, and define elf_format with DEFINE_GLOBAL_PAGE_SIZE_VAR() so that its ELF_EXEC_PAGESIZE based initialiser can be deferred to boot.
No functional change for compile-time page sizes.
--- fs/binfmt_elf.c | 11 ++++------- fs/coredump.c | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-)
fs/binfmt_elf.c +4 -7
@@ -79,11 +79,8 @@ static bool elf_core_dump(struct coredump_params *cprm);#define elf_core_dump NULL#endif -#if ELF_EXEC_PAGESIZE >PAGE_SIZE -#define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE -#else -#define ELF_MIN_ALIGN PAGE_SIZE -#endif +#define ELF_MIN_ALIGN \ + (ELF_EXEC_PAGESIZE > PAGE_SIZE ? ELF_EXEC_PAGESIZE : PAGE_SIZE)#ifndef ELF_CORE_EFLAGS #define ELF_CORE_EFLAGS 0
@@ -93,14 +90,14 @@ static bool elf_core_dump(struct coredump_params *cprm);#define ELF_PAGEOFFSET (_v) ((_v) & (ELF_MIN_ALIGN-1))#define ELF_PAGEALIGN (_v) (((_v) + ELF_MIN_ALIGN - 1) & ~(ELF_MIN_ALIGN - 1)) -static struct linux_binfmt elf_format = { +static DEFINE_GLOBAL_PAGE_SIZE_VAR(struct linux_binfmt, elf_format, { .module = THIS_MODULE, .load_binary = load_elf_binary, #ifdef CONFIG_COREDUMP .core_dump = elf_core_dump, .min_coredump = ELF_EXEC_PAGESIZE, #endif -}; +});#define BAD_ADDR (x) (unlikely((unsigned long)(x) >= TASK_SIZE))
fs/coredump.c +2 -2
@@ -1442,7 +1442,7 @@ static void dump_end_record(struct coredump_params *cprm)static bool __dump_skip (struct coredump_params *cprm,size_t nr) { -static char zeroes[PAGE_SIZE ]; +static char zeroes[PAGE_SIZE_MIN ];struct file *file = cprm->file;if (dump_sparse (cprm)) {
@@ -1460,7 +1460,7 @@ static bool __dump_skip(struct coredump_params *cprm, size_t nr) }while (nr) { -size_t chunk =min_t (size_t, nr,PAGE_SIZE ); +size_t chunk =min_t (size_t, nr,PAGE_SIZE_MIN );if (!__dump_emit (cprm, zeroes, chunk))return false;
RFC PATCH v2 22/22 fat: Use MAX_BUF_PER_PAGE_SIZE_MAX to size buffer_head arrays
In reply to Eric CurtinFrom: Ryan Roberts <[email protected]>
MAX_BUF_PER_PAGE is derived from PAGE_SIZE, so with boot-time page size selection it cannot be used to size an on-stack array.
Add MAX_BUF_PER_PAGE_SIZE_MAX, the value of MAX_BUF_PER_PAGE at PAGE_SIZE_MAX, and use it for the bhs[] arrays in fat_alloc_new_dir(), fat_add_new_entries(), __fat_alloc_clusters() and fat_free_clusters().
No functional change for compile-time page sizes.
--- fs/fat/dir.c | 4 ++-- fs/fat/fatent.c | 4 ++-- include/linux/buffer_head.h | 1 + 3 files changed, 5 insertions(+), 4 deletions(-)
fs/fat/dir.c +2 -2
@@ -1184,7 +1184,7 @@ int fat_alloc_new_dir(struct inode *dir, struct timespec64 *ts) {struct super_block *sb = dir->i_sb;struct msdos_sb_info *sbi =MSDOS_SB (sb); -struct buffer_head *bhs[MAX_BUF_PER_PAGE ]; +struct buffer_head *bhs[MAX_BUF_PER_PAGE_SIZE_MAX ];struct msdos_dir_entry *de;sector_t blknr;__le16 date, time;
@@ -1251,7 +1251,7 @@ static int fat_add_new_entries(struct inode *dir, void *slots, int nr_slots, {struct super_block *sb = dir->i_sb;struct msdos_sb_info *sbi =MSDOS_SB (sb); -struct buffer_head *bhs[MAX_BUF_PER_PAGE ]; +struct buffer_head *bhs[MAX_BUF_PER_PAGE_SIZE_MAX ];sector_t blknr, start_blknr, last_blknr;unsigned long size, copy;int err, i, n, offset, cluster[2 ];
fs/fat/fatent.c +2 -2
@@ -510,7 +510,7 @@ static int __fat_alloc_clusters(struct inode *inode, int *cluster, int nr_clustestruct msdos_sb_info *sbi =MSDOS_SB (sb);const struct fatent_operations *ops = sbi->fatent_ops;struct fat_entry fatent, prev_ent; -struct buffer_head *bhs[MAX_BUF_PER_PAGE ]; +struct buffer_head *bhs[MAX_BUF_PER_PAGE_SIZE_MAX ];int i, count, err, nr_bhs, idx_clus;lock_fat (sbi);
@@ -616,7 +616,7 @@ int fat_free_clusters(struct inode *inode, int cluster)struct msdos_sb_info *sbi =MSDOS_SB (sb);const struct fatent_operations *ops = sbi->fatent_ops;struct fat_entry fatent; -struct buffer_head *bhs[MAX_BUF_PER_PAGE ]; +struct buffer_head *bhs[MAX_BUF_PER_PAGE_SIZE_MAX ];int i, err, nr_bhs;int first_cl = cluster, dirty_fsinfo =0 ;
include/linux/buffer_head.h +1 -0
@@ -42,6 +42,7 @@ enum bh_state_bits { };#define MAX_BUF_PER_PAGE (PAGE_SIZE / 512) +#define MAX_BUF_PER_PAGE_SIZE_MAX (PAGE_SIZE_MAX / 512)struct page ;struct buffer_head ;