All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH v2 00/13] block/storage: Prepare for boot-time page size selection on arm64
@ 2026-12-02  3:16 ` Eric Curtin
  0 siblings, 0 replies; 20+ messages in thread
From: Eric Curtin @ 2026-12-02  3:16 UTC (permalink / raw)
  To: linux-kernel
  Cc: Eric Curtin, Ryan Roberts, cgroups, dm-devel, linux-arm-kernel,
	linux-block, linux-fsdevel, linux-ide, linux-mm, linux-mtd,
	nvdimm, v9fs, virtualization

From: Eric Curtin <eric.curtin@docker.com>

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 block, MD, NVMe, SCSI, ATA, MTD and MMC code. 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/20261201015240.1017259-1-ericcurtin17@gmail.com/
[2] https://lore.kernel.org/all/20241014105514.3206191-1-ryan.roberts@arm.com/

Eric Curtin (8):
  scsi: core: Add dma_boundary_page for page-size DMA boundaries
  mtd: mtdswap: Initialise mtdswap_ops with a page size variable
  mmc: mmc_test: Allocate the scratch buffer with the test buffer
  md: Remove compile-time PAGE_SIZE use in md, dm and bcache
  zram: Remove PAGE_SIZE use in preprocessor conditionals
  xen/blkback: Size indirect_pages for the largest page size
  null_blk: Size the nullb_page bitmap for PAGE_SIZE_MAX
  drbd: Use PAGE_SHIFT_MIN in preprocessor checks

Ryan Roberts (5):
  nvme: Check the DSM range buffer against PAGE_SIZE_MIN
  dm: Initialise swap_bios from the runtime PAGE_SIZE
  virtio: Handle boot-time PAGE_SIZE in balloon, blk and 9p transport
  ata: sata_sil24: Use flexible arrays for the command block SGEs
  mm: Use PAGE_SIZE_MIN/MAX where a compile-time constant is required


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [RFC PATCH v2 00/13] block/storage: Prepare for boot-time page size selection on arm64
@ 2026-12-02  3:16 ` Eric Curtin
  0 siblings, 0 replies; 20+ messages in thread
From: Eric Curtin @ 2026-12-02  3:16 UTC (permalink / raw)
  To: linux-kernel
  Cc: Eric Curtin, Ryan Roberts, cgroups, dm-devel, linux-arm-kernel,
	linux-block, linux-fsdevel, linux-ide, linux-mm, linux-mtd,
	nvdimm, v9fs, virtualization

From: Eric Curtin <eric.curtin@docker.com>

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 block, MD, NVMe, SCSI, ATA, MTD and MMC code. 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/20261201015240.1017259-1-ericcurtin17@gmail.com/
[2] https://lore.kernel.org/all/20241014105514.3206191-1-ryan.roberts@arm.com/

Eric Curtin (8):
  scsi: core: Add dma_boundary_page for page-size DMA boundaries
  mtd: mtdswap: Initialise mtdswap_ops with a page size variable
  mmc: mmc_test: Allocate the scratch buffer with the test buffer
  md: Remove compile-time PAGE_SIZE use in md, dm and bcache
  zram: Remove PAGE_SIZE use in preprocessor conditionals
  xen/blkback: Size indirect_pages for the largest page size
  null_blk: Size the nullb_page bitmap for PAGE_SIZE_MAX
  drbd: Use PAGE_SHIFT_MIN in preprocessor checks

Ryan Roberts (5):
  nvme: Check the DSM range buffer against PAGE_SIZE_MIN
  dm: Initialise swap_bios from the runtime PAGE_SIZE
  virtio: Handle boot-time PAGE_SIZE in balloon, blk and 9p transport
  ata: sata_sil24: Use flexible arrays for the command block SGEs
  mm: Use PAGE_SIZE_MIN/MAX where a compile-time constant is required


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [RFC PATCH v2 01/13] scsi: core: Add dma_boundary_page for page-size DMA boundaries
  2026-12-02  3:16 ` Eric Curtin
  (?)
@ 2026-12-02  3:16 ` Eric Curtin
  -1 siblings, 0 replies; 20+ messages in thread
From: Eric Curtin @ 2026-12-02  3:16 UTC (permalink / raw)
  To: linux-kernel
  Cc: Eric Curtin, Juergen E. Fischer, James E.J. Bottomley,
	Martin K. Petersen, Varun Prakash, Oliver Neukum, Ali Akcaagac,
	Jamie Lenehan, Finn Thain, Michael Schmitz, Lee Duncan,
	Chris Leech, Mike Christie, GOTO Masanori, YOKOTA Hiroshi,
	Matthew Wilcox, Juergen Gross, Stefano Stabellini,
	Oleksandr Tyshchenko, linux-scsi, open-iscsi, xen-devel

From: Eric Curtin <eric.curtin@docker.com>

With arm64 boot-time page size selection PAGE_SIZE is not a compile-time
constant, so scsi_host_template instances, which are static const,
cannot set .dma_boundary = PAGE_SIZE - 1.

Add a dma_boundary_page flag to struct scsi_host_template. When set,
scsi_host_alloc() uses PAGE_SIZE - 1 as the DMA boundary, taking
precedence over .dma_boundary. Convert the drivers that used PAGE_SIZE -
1 (aha152x, cxgb3i, cxgb4i, dc395x, dmx3191d, fdomain, g_NCR5380,
iscsi_tcp, mvumi, nsp32, nsp_cs, qlogic_stub, qlogicfas, stex and uas)
to use the flag.

Fix the remaining compile-time uses. In ncr53c8xx and sym53c8xx_2, test
PAGE_SIZE_MIN in #if and size the m_pool h[] array from PAGE_SHIFT_MAX.
In sym_hipd.h add SYM_MEM_CLUSTER_SHIFT_MIN/MAX and
SYM_MEM_CLUSTER_SIZE_MIN, and clamp SYM_CONF_MAX_QUEUE against the
smallest cluster size. In xen-scsifront, size the shadow arrays and the
gref array from PAGE_SIZE_MAX and PAGE_SIZE_MIN, and set can_queue in
scsifront_probe() instead of the static template.

Signed-off-by: Eric Curtin <eric.curtin@docker.com>
---
 drivers/scsi/aha152x.c              |  2 +-
 drivers/scsi/cxgbi/cxgb3i/cxgb3i.c  |  2 +-
 drivers/scsi/cxgbi/cxgb4i/cxgb4i.c  |  2 +-
 drivers/scsi/dc395x.c               |  2 +-
 drivers/scsi/dmx3191d.c             |  2 +-
 drivers/scsi/fdomain.c              |  2 +-
 drivers/scsi/g_NCR5380.c            |  2 +-
 drivers/scsi/hosts.c                |  4 +++-
 drivers/scsi/iscsi_tcp.c            |  2 +-
 drivers/scsi/mvumi.c                |  2 +-
 drivers/scsi/ncr53c8xx.c            |  4 ++--
 drivers/scsi/nsp32.c                |  2 +-
 drivers/scsi/pcmcia/nsp_cs.c        |  2 +-
 drivers/scsi/pcmcia/qlogic_stub.c   |  2 +-
 drivers/scsi/qlogicfas.c            |  2 +-
 drivers/scsi/stex.c                 |  2 +-
 drivers/scsi/sym53c8xx_2/sym_hipd.h |  9 ++++++---
 drivers/scsi/xen-scsifront.c        | 12 ++++++++----
 include/scsi/scsi_host.h            |  7 +++++++
 19 files changed, 40 insertions(+), 24 deletions(-)

diff --git a/drivers/scsi/aha152x.c b/drivers/scsi/aha152x.c
index d751dc8093cc..fe5b334ec456 100644
--- a/drivers/scsi/aha152x.c
+++ b/drivers/scsi/aha152x.c
@@ -2954,7 +2954,7 @@ static const struct scsi_host_template aha152x_driver_template = {
 	.can_queue			= 1,
 	.this_id			= 7,
 	.sg_tablesize			= SG_ALL,
-	.dma_boundary			= PAGE_SIZE - 1,
+	.dma_boundary_page		= 1,
 	.cmd_size			= sizeof(struct aha152x_cmd_priv),
 };
 
diff --git a/drivers/scsi/cxgbi/cxgb3i/cxgb3i.c b/drivers/scsi/cxgbi/cxgb3i/cxgb3i.c
index 69de9657f7cb..d6eccebf4578 100644
--- a/drivers/scsi/cxgbi/cxgb3i/cxgb3i.c
+++ b/drivers/scsi/cxgbi/cxgb3i/cxgb3i.c
@@ -95,7 +95,7 @@ static const struct scsi_host_template cxgb3i_host_template = {
 	.eh_device_reset_handler = iscsi_eh_device_reset,
 	.eh_target_reset_handler = iscsi_eh_recover_target,
 	.target_alloc	= iscsi_target_alloc,
-	.dma_boundary	= PAGE_SIZE - 1,
+	.dma_boundary_page = 1,
 	.this_id	= -1,
 	.track_queue_depth = 1,
 	.cmd_size	= sizeof(struct iscsi_cmd),
diff --git a/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c b/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c
index 42676627c3af..8545cce3cb8f 100644
--- a/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c
+++ b/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c
@@ -113,7 +113,7 @@ static struct scsi_host_template cxgb4i_host_template = {
 	.eh_device_reset_handler = iscsi_eh_device_reset,
 	.eh_target_reset_handler = iscsi_eh_recover_target,
 	.target_alloc	= iscsi_target_alloc,
-	.dma_boundary	= PAGE_SIZE - 1,
+	.dma_boundary_page = 1,
 	.this_id	= -1,
 	.track_queue_depth = 1,
 	.cmd_size	= sizeof(struct iscsi_cmd),
diff --git a/drivers/scsi/dc395x.c b/drivers/scsi/dc395x.c
index 5a4f2713dcfa..8738122907cf 100644
--- a/drivers/scsi/dc395x.c
+++ b/drivers/scsi/dc395x.c
@@ -3942,7 +3942,7 @@ static const struct scsi_host_template dc395x_driver_template = {
 	.cmd_per_lun            = DC395x_MAX_CMD_PER_LUN,
 	.eh_abort_handler       = dc395x_eh_abort,
 	.eh_bus_reset_handler   = dc395x_eh_bus_reset,
-	.dma_boundary		= PAGE_SIZE - 1,
+	.dma_boundary_page	= 1,
 };
 
 
diff --git a/drivers/scsi/dmx3191d.c b/drivers/scsi/dmx3191d.c
index d6d091b2f3c7..c6ef207ec816 100644
--- a/drivers/scsi/dmx3191d.c
+++ b/drivers/scsi/dmx3191d.c
@@ -51,7 +51,7 @@ static const struct scsi_host_template dmx3191d_driver_template = {
 	.this_id		= 7,
 	.sg_tablesize		= SG_ALL,
 	.cmd_per_lun		= 2,
-	.dma_boundary		= PAGE_SIZE - 1,
+	.dma_boundary_page	= 1,
 	.cmd_size		= sizeof(struct NCR5380_cmd),
 };
 
diff --git a/drivers/scsi/fdomain.c b/drivers/scsi/fdomain.c
index b5766f752cdd..06cc2384e225 100644
--- a/drivers/scsi/fdomain.c
+++ b/drivers/scsi/fdomain.c
@@ -508,7 +508,7 @@ static const struct scsi_host_template fdomain_template = {
 	.can_queue		= 1,
 	.this_id		= 7,
 	.sg_tablesize		= 64,
-	.dma_boundary		= PAGE_SIZE - 1,
+	.dma_boundary_page	= 1,
 	.cmd_size		= sizeof(struct scsi_pointer),
 };
 
diff --git a/drivers/scsi/g_NCR5380.c b/drivers/scsi/g_NCR5380.c
index 41731a7304dd..95ad0b0fbfa7 100644
--- a/drivers/scsi/g_NCR5380.c
+++ b/drivers/scsi/g_NCR5380.c
@@ -702,7 +702,7 @@ static const struct scsi_host_template driver_template = {
 	.this_id		= 7,
 	.sg_tablesize		= SG_ALL,
 	.cmd_per_lun		= 2,
-	.dma_boundary		= PAGE_SIZE - 1,
+	.dma_boundary_page	= 1,
 	.cmd_size		= sizeof(struct NCR5380_cmd),
 	.max_sectors		= 128,
 };
diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index e8361ba65564..108940d2e230 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -511,7 +511,9 @@ struct Scsi_Host *scsi_host_alloc(const struct scsi_host_template *sht, int priv
 	/*
 	 * assume a 4GB boundary, if not set
 	 */
-	if (sht->dma_boundary)
+	if (sht->dma_boundary_page)
+		shost->dma_boundary = PAGE_SIZE - 1;
+	else if (sht->dma_boundary)
 		shost->dma_boundary = sht->dma_boundary;
 	else
 		shost->dma_boundary = 0xffffffff;
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index 9260b1c9b0e0..31dcef428df8 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -1038,7 +1038,7 @@ static const struct scsi_host_template iscsi_sw_tcp_sht = {
 	.eh_abort_handler       = iscsi_eh_abort,
 	.eh_device_reset_handler= iscsi_eh_device_reset,
 	.eh_target_reset_handler = iscsi_eh_recover_target,
-	.dma_boundary		= PAGE_SIZE - 1,
+	.dma_boundary_page	= 1,
 	.sdev_configure		= iscsi_sw_tcp_sdev_configure,
 	.proc_name		= "iscsi_tcp",
 	.this_id		= -1,
diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
index 91c2db697c69..f984ec25b5d5 100644
--- a/drivers/scsi/mvumi.c
+++ b/drivers/scsi/mvumi.c
@@ -2177,7 +2177,7 @@ static const struct scsi_host_template mvumi_template = {
 	.eh_timed_out = mvumi_timed_out,
 	.eh_host_reset_handler = mvumi_host_reset,
 	.bios_param = mvumi_bios_param,
-	.dma_boundary = PAGE_SIZE - 1,
+	.dma_boundary_page = 1,
 	.this_id = -1,
 	.cmd_size = sizeof(struct mvumi_cmd_priv),
 };
diff --git a/drivers/scsi/ncr53c8xx.c b/drivers/scsi/ncr53c8xx.c
index 5369ca3fe4fd..dc010e65fe73 100644
--- a/drivers/scsi/ncr53c8xx.c
+++ b/drivers/scsi/ncr53c8xx.c
@@ -184,7 +184,7 @@ static inline struct list_head *ncr_list_pop(struct list_head *head)
 */
 
 #define MEMO_SHIFT	4	/* 16 bytes minimum memory chunk */
-#if PAGE_SIZE >= 8192
+#if PAGE_SIZE_MIN >= 8192
 #define MEMO_PAGE_ORDER	0	/* 1 PAGE  maximum */
 #else
 #define MEMO_PAGE_ORDER	1	/* 2 PAGES maximum */
@@ -221,7 +221,7 @@ typedef struct m_pool {		/* Memory pool of a given kind */
 	int nump;
 	m_vtob_s *(vtob[VTOB_HASH_SIZE]);
 	struct m_pool *next;
-	struct m_link h[PAGE_SHIFT-MEMO_SHIFT+MEMO_PAGE_ORDER+1];
+	struct m_link h[PAGE_SHIFT_MAX-MEMO_SHIFT+MEMO_PAGE_ORDER+1];
 } m_pool_s;
 
 static void *___m_alloc(m_pool_s *mp, int size)
diff --git a/drivers/scsi/nsp32.c b/drivers/scsi/nsp32.c
index 98550c73d8a0..b73dc38a0d03 100644
--- a/drivers/scsi/nsp32.c
+++ b/drivers/scsi/nsp32.c
@@ -270,7 +270,7 @@ static const struct scsi_host_template nsp32_template = {
 	.sg_tablesize			= NSP32_SG_SIZE,
 	.max_sectors			= 128,
 	.this_id			= NSP32_HOST_SCSIID,
-	.dma_boundary			= PAGE_SIZE - 1,
+	.dma_boundary_page		= 1,
 	.eh_abort_handler		= nsp32_eh_abort,
 	.eh_host_reset_handler		= nsp32_eh_host_reset,
 /*	.highmem_io			= 1, */
diff --git a/drivers/scsi/pcmcia/nsp_cs.c b/drivers/scsi/pcmcia/nsp_cs.c
index ae70fda96ae9..ecd40c9f82f6 100644
--- a/drivers/scsi/pcmcia/nsp_cs.c
+++ b/drivers/scsi/pcmcia/nsp_cs.c
@@ -87,7 +87,7 @@ static struct scsi_host_template nsp_driver_template = {
 	.can_queue		 = 1,
 	.this_id		 = NSP_INITIATOR_ID,
 	.sg_tablesize		 = SG_ALL,
-	.dma_boundary		 = PAGE_SIZE - 1,
+	.dma_boundary_page	 = 1,
 	.cmd_size		 = sizeof(struct scsi_pointer),
 };
 
diff --git a/drivers/scsi/pcmcia/qlogic_stub.c b/drivers/scsi/pcmcia/qlogic_stub.c
index 5d8a434d3f66..d3f543703b9b 100644
--- a/drivers/scsi/pcmcia/qlogic_stub.c
+++ b/drivers/scsi/pcmcia/qlogic_stub.c
@@ -75,7 +75,7 @@ static struct scsi_host_template qlogicfas_driver_template = {
 	.can_queue		= 1,
 	.this_id		= -1,
 	.sg_tablesize		= SG_ALL,
-	.dma_boundary		= PAGE_SIZE - 1,
+	.dma_boundary_page	= 1,
 };
 
 /*====================================================================*/
diff --git a/drivers/scsi/qlogicfas.c b/drivers/scsi/qlogicfas.c
index 8f05e3707d69..929e25ea928e 100644
--- a/drivers/scsi/qlogicfas.c
+++ b/drivers/scsi/qlogicfas.c
@@ -197,7 +197,7 @@ static struct scsi_host_template qlogicfas_driver_template = {
 	.can_queue		= 1,
 	.this_id		= -1,
 	.sg_tablesize		= SG_ALL,
-	.dma_boundary		= PAGE_SIZE - 1,
+	.dma_boundary_page	= 1,
 };
 
 static __init int qlogicfas_init(void)
diff --git a/drivers/scsi/stex.c b/drivers/scsi/stex.c
index d4899816f7dc..988f2c3dee96 100644
--- a/drivers/scsi/stex.c
+++ b/drivers/scsi/stex.c
@@ -1484,7 +1484,7 @@ static const struct scsi_host_template driver_template = {
 	.eh_abort_handler		= stex_abort,
 	.eh_host_reset_handler		= stex_reset,
 	.this_id			= -1,
-	.dma_boundary			= PAGE_SIZE - 1,
+	.dma_boundary_page		= 1,
 };
 
 static const struct pci_device_id stex_pci_tbl[] = {
diff --git a/drivers/scsi/sym53c8xx_2/sym_hipd.h b/drivers/scsi/sym53c8xx_2/sym_hipd.h
index aa365e8ba66f..4f17d91215cb 100644
--- a/drivers/scsi/sym53c8xx_2/sym_hipd.h
+++ b/drivers/scsi/sym53c8xx_2/sym_hipd.h
@@ -142,6 +142,8 @@
 
 #define SYM_MEM_PAGE_ORDER 0	/* 1 PAGE  maximum */
 #define SYM_MEM_CLUSTER_SHIFT	(PAGE_SHIFT+SYM_MEM_PAGE_ORDER)
+#define SYM_MEM_CLUSTER_SHIFT_MIN	(PAGE_SHIFT_MIN+SYM_MEM_PAGE_ORDER)
+#define SYM_MEM_CLUSTER_SHIFT_MAX	(PAGE_SHIFT_MAX+SYM_MEM_PAGE_ORDER)
 #define SYM_MEM_FREE_UNUSED	/* Free unused pages immediately */
 /*
  *  Shortest memory chunk is (1<<SYM_MEM_SHIFT), currently 16.
@@ -165,9 +167,10 @@
 #define	SYM_CONF_MAX_START (SYM_CONF_MAX_QUEUE-2)
 #endif
 
-#if	SYM_CONF_MAX_QUEUE > SYM_MEM_CLUSTER_SIZE/8
+#define SYM_MEM_CLUSTER_SIZE_MIN	(1UL << SYM_MEM_CLUSTER_SHIFT_MIN)
+#if	SYM_CONF_MAX_QUEUE > SYM_MEM_CLUSTER_SIZE_MIN/8
 #undef	SYM_CONF_MAX_QUEUE
-#define	SYM_CONF_MAX_QUEUE (SYM_MEM_CLUSTER_SIZE/8)
+#define	SYM_CONF_MAX_QUEUE (SYM_MEM_CLUSTER_SIZE_MIN/8)
 #undef	SYM_CONF_MAX_START
 #define	SYM_CONF_MAX_START (SYM_CONF_MAX_QUEUE-2)
 #endif
@@ -1158,7 +1161,7 @@ typedef struct sym_m_pool {
 	int nump;
 	m_vtob_p vtob[VTOB_HASH_SIZE];
 	struct sym_m_pool *next;
-	struct sym_m_link h[SYM_MEM_CLUSTER_SHIFT - SYM_MEM_SHIFT + 1];
+	struct sym_m_link h[SYM_MEM_CLUSTER_SHIFT_MAX - SYM_MEM_SHIFT + 1];
 } *m_pool_p;
 
 /*
diff --git a/drivers/scsi/xen-scsifront.c b/drivers/scsi/xen-scsifront.c
index b37657953245..d00306670734 100644
--- a/drivers/scsi/xen-scsifront.c
+++ b/drivers/scsi/xen-scsifront.c
@@ -68,10 +68,14 @@
 #define VSCSIIF_MAX_LUN             255
 
 #define VSCSIIF_RING_SIZE	__CONST_RING_SIZE(vscsiif, PAGE_SIZE)
+#define VSCSIIF_RING_SIZE_MAX	__CONST_RING_SIZE(vscsiif, PAGE_SIZE_MAX)
 #define VSCSIIF_MAX_REQS	VSCSIIF_RING_SIZE
+#define VSCSIIF_MAX_REQS_MAX	VSCSIIF_RING_SIZE_MAX
 
 #define vscsiif_grants_sg(_sg)	(PFN_UP((_sg) *		\
 				sizeof(struct scsiif_request_segment)))
+#define vscsiif_grants_sg_max(_sg)				\
+	DIV_ROUND_UP((_sg) * sizeof(struct scsiif_request_segment), PAGE_SIZE_MIN)
 
 struct vscsifrnt_shadow {
 	/* command between backend and frontend */
@@ -96,7 +100,7 @@ struct vscsifrnt_shadow {
 
 	/* Requested struct scsi_cmnd is stored from kernel. */
 	struct scsi_cmnd *sc;
-	int gref[vscsiif_grants_sg(SG_ALL) + SG_ALL];
+	int gref[vscsiif_grants_sg_max(SG_ALL) + SG_ALL];
 };
 
 struct vscsifrnt_info {
@@ -117,8 +121,8 @@ struct vscsifrnt_info {
 	struct vscsiif_response	ring_rsp;
 
 	spinlock_t shadow_lock;
-	DECLARE_BITMAP(shadow_free_bitmap, VSCSIIF_MAX_REQS);
-	struct vscsifrnt_shadow *shadow[VSCSIIF_MAX_REQS];
+	DECLARE_BITMAP(shadow_free_bitmap, VSCSIIF_MAX_REQS_MAX);
+	struct vscsifrnt_shadow *shadow[VSCSIIF_MAX_REQS_MAX];
 
 	/* Following items are protected by the host lock. */
 	wait_queue_head_t wq_sync;
@@ -781,7 +785,6 @@ static const struct scsi_host_template scsifront_sht = {
 	.sdev_configure		= scsifront_sdev_configure,
 	.sdev_destroy		= scsifront_sdev_destroy,
 	.cmd_per_lun		= VSCSIIF_DEFAULT_CMD_PER_LUN,
-	.can_queue		= VSCSIIF_MAX_REQS,
 	.this_id		= -1,
 	.cmd_size		= sizeof(struct vscsifrnt_shadow),
 	.sg_tablesize		= VSCSIIF_SG_TABLESIZE,
@@ -924,6 +927,7 @@ static int scsifront_probe(struct xenbus_device *dev,
 
 	snprintf(name, TASK_COMM_LEN, "vscsiif.%d", host->host_no);
 
+	host->can_queue   = VSCSIIF_MAX_REQS;
 	host->max_id      = VSCSIIF_MAX_TARGET;
 	host->max_channel = 0;
 	host->max_lun     = VSCSIIF_MAX_LUN;
diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h
index daaf1247673f..d293e41a4f9c 100644
--- a/include/scsi/scsi_host.h
+++ b/include/scsi/scsi_host.h
@@ -431,6 +431,13 @@ struct scsi_host_template {
 	 */
 	unsigned long dma_boundary;
 
+	/*
+	 * Set to use PAGE_SIZE - 1 as the DMA boundary. Unlike a fixed
+	 * @dma_boundary this tracks the run-time page size. Takes
+	 * precedence over @dma_boundary.
+	 */
+	unsigned dma_boundary_page:1;
+
 	unsigned long virt_boundary_mask;
 
 	/*

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [RFC PATCH v2 02/13] mtd: mtdswap: Initialise mtdswap_ops with a page size variable
  2026-12-02  3:16 ` Eric Curtin
@ 2026-12-02  3:16   ` Eric Curtin
  -1 siblings, 0 replies; 20+ messages in thread
From: Eric Curtin @ 2026-12-02  3:16 UTC (permalink / raw)
  To: linux-kernel
  Cc: Eric Curtin, Miquel Raynal, Richard Weinberger,
	Vignesh Raghavendra, linux-mtd

From: Eric Curtin <eric.curtin@docker.com>

With arm64 boot-time page size selection PAGE_SIZE is not a
compile-time constant, so it cannot be used in the static initialiser
of mtdswap_ops, whose .blksize is PAGE_SIZE.

Define the structure with DEFINE_GLOBAL_PAGE_SIZE_VAR(), which
initialises it at boot when the page size is not fixed and is an
ordinary static initialiser otherwise.

No functional change for compile-time page sizes.

Signed-off-by: Eric Curtin <eric.curtin@docker.com>
---
 drivers/mtd/mtdswap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/mtdswap.c b/drivers/mtd/mtdswap.c
index 7b20e49d5a25..469902a4d397 100644
--- a/drivers/mtd/mtdswap.c
+++ b/drivers/mtd/mtdswap.c
@@ -1472,7 +1472,7 @@ static void mtdswap_remove_dev(struct mtd_blktrans_dev *dev)
 	kfree(d);
 }
 
-static struct mtd_blktrans_ops mtdswap_ops = {
+static DEFINE_GLOBAL_PAGE_SIZE_VAR(struct mtd_blktrans_ops, mtdswap_ops, {
 	.name		= "mtdswap",
 	.major		= 0,
 	.part_bits	= 0,
@@ -1485,7 +1485,7 @@ static struct mtd_blktrans_ops mtdswap_ops = {
 	.add_mtd	= mtdswap_add_mtd,
 	.remove_dev	= mtdswap_remove_dev,
 	.owner		= THIS_MODULE,
-};
+});
 
 module_mtd_blktrans(mtdswap_ops);
 

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [RFC PATCH v2 02/13] mtd: mtdswap: Initialise mtdswap_ops with a page size variable
@ 2026-12-02  3:16   ` Eric Curtin
  0 siblings, 0 replies; 20+ messages in thread
From: Eric Curtin @ 2026-12-02  3:16 UTC (permalink / raw)
  To: linux-kernel
  Cc: Eric Curtin, Miquel Raynal, Richard Weinberger,
	Vignesh Raghavendra, linux-mtd

From: Eric Curtin <eric.curtin@docker.com>

With arm64 boot-time page size selection PAGE_SIZE is not a
compile-time constant, so it cannot be used in the static initialiser
of mtdswap_ops, whose .blksize is PAGE_SIZE.

Define the structure with DEFINE_GLOBAL_PAGE_SIZE_VAR(), which
initialises it at boot when the page size is not fixed and is an
ordinary static initialiser otherwise.

No functional change for compile-time page sizes.

Signed-off-by: Eric Curtin <eric.curtin@docker.com>
---
 drivers/mtd/mtdswap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/mtdswap.c b/drivers/mtd/mtdswap.c
index 7b20e49d5a25..469902a4d397 100644
--- a/drivers/mtd/mtdswap.c
+++ b/drivers/mtd/mtdswap.c
@@ -1472,7 +1472,7 @@ static void mtdswap_remove_dev(struct mtd_blktrans_dev *dev)
 	kfree(d);
 }
 
-static struct mtd_blktrans_ops mtdswap_ops = {
+static DEFINE_GLOBAL_PAGE_SIZE_VAR(struct mtd_blktrans_ops, mtdswap_ops, {
 	.name		= "mtdswap",
 	.major		= 0,
 	.part_bits	= 0,
@@ -1485,7 +1485,7 @@ static struct mtd_blktrans_ops mtdswap_ops = {
 	.add_mtd	= mtdswap_add_mtd,
 	.remove_dev	= mtdswap_remove_dev,
 	.owner		= THIS_MODULE,
-};
+});
 
 module_mtd_blktrans(mtdswap_ops);
 

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [RFC PATCH v2 03/13] mmc: mmc_test: Allocate the scratch buffer with the test buffer
  2026-12-02  3:16 ` Eric Curtin
                   ` (2 preceding siblings ...)
  (?)
@ 2026-12-02  3:16 ` Eric Curtin
  -1 siblings, 0 replies; 20+ messages in thread
From: Eric Curtin @ 2026-12-02  3:16 UTC (permalink / raw)
  To: linux-kernel; +Cc: Eric Curtin, Ulf Hansson, linux-mmc

From: Eric Curtin <eric.curtin@docker.com>

With arm64 boot-time page size selection PAGE_SIZE is not a
compile-time constant. BUFFER_SIZE is derived from it, so struct
mmc_test_card can no longer embed a scratch[BUFFER_SIZE] array.

Make scratch a pointer into the same allocation as the flexible buffer
member: allocate 2 * BUFFER_SIZE in mtf_test_write() and point scratch
at the second half.

No functional change for compile-time page sizes.

Signed-off-by: Eric Curtin <eric.curtin@docker.com>
---
 drivers/mmc/core/mmc_test.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/mmc/core/mmc_test.c b/drivers/mmc/core/mmc_test.c
index 4dc16649e61d..686e91b36ab6 100644
--- a/drivers/mmc/core/mmc_test.c
+++ b/drivers/mmc/core/mmc_test.c
@@ -138,12 +138,12 @@ struct mmc_test_dbgfs_file {
  * @highmem: buffer for highmem tests
  * @area: information for performance tests
  * @gr: pointer to results of current testcase
- * @buffer: transfer buffer
+ * @buffer: transfer buffer, followed by the scratch buffer
  */
 struct mmc_test_card {
 	struct mmc_card	*card;
 
-	u8		scratch[BUFFER_SIZE];
+	u8		*scratch;
 #ifdef CONFIG_HIGHMEM
 	struct page	*highmem;
 #endif
@@ -3088,7 +3088,7 @@ static ssize_t mtf_test_write(struct file *file, const char __user *buf,
 	if (ret)
 		return ret;
 
-	test = kzalloc_flex(*test, buffer, BUFFER_SIZE);
+	test = kzalloc_flex(*test, buffer, 2 * BUFFER_SIZE);
 	if (!test)
 		return -ENOMEM;
 
@@ -3099,6 +3099,7 @@ static ssize_t mtf_test_write(struct file *file, const char __user *buf,
 	mmc_test_free_result(card);
 
 	test->card = card;
+	test->scratch = test->buffer + BUFFER_SIZE;
 
 #ifdef CONFIG_HIGHMEM
 	test->highmem = alloc_pages(GFP_KERNEL | __GFP_HIGHMEM, BUFFER_ORDER);

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [RFC PATCH v2 04/13] md: Remove compile-time PAGE_SIZE use in md, dm and bcache
  2026-12-02  3:16 ` Eric Curtin
                   ` (3 preceding siblings ...)
  (?)
@ 2026-12-02  3:16 ` Eric Curtin
  -1 siblings, 0 replies; 20+ messages in thread
From: Eric Curtin @ 2026-12-02  3:16 UTC (permalink / raw)
  To: linux-kernel
  Cc: Eric Curtin, Coly Li, Kent Overstreet, Alasdair Kergon,
	Mike Snitzer, Mikulas Patocka, Benjamin Marzinski, Matthew Sakai,
	Song Liu, Yu Kuai, Li Nan, Xiao Ni, linux-bcache, dm-devel,
	linux-raid

From: Eric Curtin <eric.curtin@docker.com>

With arm64 boot-time page size selection PAGE_SIZE and PAGE_SHIFT are
not compile-time constants, so they cannot size arrays, appear in #if
or initialise static const data.

- raid1/raid10: add RESYNC_PAGES_MAX, based on PAGE_SIZE_MIN, and use it
  for struct resync_pages and the page_len array in process_checks().
- raid5: introduce RAID5_VAR_STRIPE_SIZE, defined unless both
  PAGE_SIZE_MIN and PAGE_SIZE_MAX equal DEFAULT_STRIPE_SIZE, and use it
  in place of "PAGE_SIZE != DEFAULT_STRIPE_SIZE" in the #if checks.
- bcache: make the dump_iterator buffer a flexible array and allocate a
  full PAGE_SIZE for it.
- dm-switch: the argument limits depend on KMALLOC_MAX_SIZE, so the
  dm_arg array in switch_ctr() can no longer be static const.
- dm-writecache: compute BITMAP_GRANULARITY with max_t() instead of #if.
- dm-vdo: make MAX_BLOCKS_PER_VIO a macro rather than an enum member and
  check VDO_BLOCK_SIZE against PAGE_SIZE_MIN.

No functional change for compile-time page sizes.

Signed-off-by: Eric Curtin <eric.curtin@docker.com>
---
 drivers/md/bcache/debug.c    |  4 ++--
 drivers/md/dm-switch.c       |  2 +-
 drivers/md/dm-vdo/data-vio.c |  2 +-
 drivers/md/dm-vdo/vio.h      |  4 +---
 drivers/md/dm-writecache.c   |  6 +-----
 drivers/md/raid1-10.c        |  3 ++-
 drivers/md/raid1.c           |  2 +-
 drivers/md/raid5.c           | 18 +++++++++---------
 drivers/md/raid5.h           | 13 ++++++++-----
 9 files changed, 26 insertions(+), 28 deletions(-)

diff --git a/drivers/md/bcache/debug.c b/drivers/md/bcache/debug.c
index 2691a5da3368..4c8668a701e5 100644
--- a/drivers/md/bcache/debug.c
+++ b/drivers/md/bcache/debug.c
@@ -157,10 +157,10 @@ void bch_data_verify(struct cached_dev *dc, struct bio *bio)
 /* XXX: cache set refcounting */
 
 struct dump_iterator {
-	char			buf[PAGE_SIZE];
 	size_t			bytes;
 	struct cache_set	*c;
 	struct keybuf		keys;
+	char			buf[];
 };
 
 static bool dump_pred(struct keybuf *buf, struct bkey *k)
@@ -208,7 +208,7 @@ static int bch_dump_open(struct inode *inode, struct file *file)
 	struct cache_set *c = inode->i_private;
 	struct dump_iterator *i;
 
-	i = kzalloc_obj(struct dump_iterator);
+	i = kzalloc_flex(*i, buf, PAGE_SIZE);
 	if (!i)
 		return -ENOMEM;
 
diff --git a/drivers/md/dm-switch.c b/drivers/md/dm-switch.c
index e5b507b4fa7b..9eed3f3a4db2 100644
--- a/drivers/md/dm-switch.c
+++ b/drivers/md/dm-switch.c
@@ -252,7 +252,7 @@ static void switch_dtr(struct dm_target *ti)
  */
 static int switch_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 {
-	static const struct dm_arg _args[] = {
+	const struct dm_arg _args[] = {
 		{1, (KMALLOC_MAX_SIZE - sizeof(struct switch_ctx)) / sizeof(struct switch_path), "Invalid number of paths"},
 		{1, UINT_MAX, "Invalid region size"},
 		{0, 0, "Invalid number of optional args"},
diff --git a/drivers/md/dm-vdo/data-vio.c b/drivers/md/dm-vdo/data-vio.c
index 370d4239ba31..fe0329354cfb 100644
--- a/drivers/md/dm-vdo/data-vio.c
+++ b/drivers/md/dm-vdo/data-vio.c
@@ -785,7 +785,7 @@ static int initialize_data_vio(struct data_vio *data_vio, struct vdo *vdo)
 	struct bio *bio;
 	int result;
 
-	BUILD_BUG_ON(VDO_BLOCK_SIZE > PAGE_SIZE);
+	BUILD_BUG_ON(VDO_BLOCK_SIZE > PAGE_SIZE_MIN);
 	result = vdo_allocate_memory(VDO_BLOCK_SIZE, 0, "data_vio data",
 				     &data_vio->vio.data);
 	if (result != VDO_SUCCESS)
diff --git a/drivers/md/dm-vdo/vio.h b/drivers/md/dm-vdo/vio.h
index 7a8a6819aec4..2beedaba89e5 100644
--- a/drivers/md/dm-vdo/vio.h
+++ b/drivers/md/dm-vdo/vio.h
@@ -17,9 +17,7 @@
 #include "types.h"
 #include "vdo.h"
 
-enum {
-	MAX_BLOCKS_PER_VIO = (BIO_MAX_VECS << PAGE_SHIFT) / VDO_BLOCK_SIZE,
-};
+#define MAX_BLOCKS_PER_VIO ((BIO_MAX_VECS << PAGE_SHIFT) / VDO_BLOCK_SIZE)
 
 struct pooled_vio {
 	/* The underlying vio */
diff --git a/drivers/md/dm-writecache.c b/drivers/md/dm-writecache.c
index 6f977fb8c939..40643f982b94 100644
--- a/drivers/md/dm-writecache.c
+++ b/drivers/md/dm-writecache.c
@@ -31,11 +31,7 @@
 #define MAX_AGE_UNSPECIFIED		-1UL
 #define PAUSE_WRITEBACK			(HZ * 3)
 
-#define BITMAP_GRANULARITY	65536
-#if BITMAP_GRANULARITY < PAGE_SIZE
-#undef BITMAP_GRANULARITY
-#define BITMAP_GRANULARITY	PAGE_SIZE
-#endif
+#define BITMAP_GRANULARITY	max_t(int, 65536, PAGE_SIZE)
 
 #if IS_ENABLED(CONFIG_ARCH_HAS_PMEM_API) && IS_ENABLED(CONFIG_FS_DAX)
 #define DM_WRITECACHE_HAS_PMEM
diff --git a/drivers/md/raid1-10.c b/drivers/md/raid1-10.c
index 341a9785e3f2..919de6611ee3 100644
--- a/drivers/md/raid1-10.c
+++ b/drivers/md/raid1-10.c
@@ -2,6 +2,7 @@
 /* Maximum size of each resync request */
 #define RESYNC_BLOCK_SIZE (64*1024)
 #define RESYNC_PAGES ((RESYNC_BLOCK_SIZE + PAGE_SIZE-1) / PAGE_SIZE)
+#define RESYNC_PAGES_MAX ((RESYNC_BLOCK_SIZE + PAGE_SIZE_MIN-1) / PAGE_SIZE_MIN)
 
 /* when we get a read error on a read-only array, we redirect to another
  * device without failing the first device, or trying to over-write to
@@ -21,7 +22,7 @@
 /* for managing resync I/O pages */
 struct resync_pages {
 	void		*raid_bio;
-	struct page	*pages[RESYNC_PAGES];
+	struct page	*pages[RESYNC_PAGES_MAX];
 };
 
 struct raid1_plug_cb {
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 894efb50c6d5..9cd66dbee221 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -2252,7 +2252,7 @@ static void process_checks(struct r1bio *r1_bio)
 		struct page **ppages = get_resync_pages(pbio)->pages;
 		struct page **spages = get_resync_pages(sbio)->pages;
 		struct bio_vec *bi;
-		int page_len[RESYNC_PAGES] = { 0 };
+		int page_len[RESYNC_PAGES_MAX] = { 0 };
 		struct bvec_iter_all iter_all;
 
 		if (sbio->bi_end_io != end_sync_read)
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index d52adf81065a..0bbdd786b196 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -463,7 +463,7 @@ static struct stripe_head *get_free_stripe(struct r5conf *conf, int hash)
 	return sh;
 }
 
-#if PAGE_SIZE != DEFAULT_STRIPE_SIZE
+#ifdef RAID5_VAR_STRIPE_SIZE
 static void free_stripe_pages(struct stripe_head *sh)
 {
 	int i;
@@ -527,7 +527,7 @@ static void shrink_buffers(struct stripe_head *sh)
 	int i;
 	int num = sh->raid_conf->pool_size;
 
-#if PAGE_SIZE == DEFAULT_STRIPE_SIZE
+#ifndef RAID5_VAR_STRIPE_SIZE
 	for (i = 0; i < num ; i++) {
 		struct page *p;
 
@@ -550,7 +550,7 @@ static int grow_buffers(struct stripe_head *sh, gfp_t gfp)
 	int i;
 	int num = sh->raid_conf->pool_size;
 
-#if PAGE_SIZE == DEFAULT_STRIPE_SIZE
+#ifndef RAID5_VAR_STRIPE_SIZE
 	for (i = 0; i < num; i++) {
 		struct page *page;
 
@@ -2353,7 +2353,7 @@ static void raid_run_ops(struct stripe_head *sh, unsigned long ops_request)
 
 static void free_stripe(struct kmem_cache *sc, struct stripe_head *sh)
 {
-#if PAGE_SIZE != DEFAULT_STRIPE_SIZE
+#ifdef RAID5_VAR_STRIPE_SIZE
 	kfree(sh->pages);
 #endif
 	if (sh->ppl_page)
@@ -2385,7 +2385,7 @@ static struct stripe_head *alloc_stripe(struct kmem_cache *sc, gfp_t gfp,
 				return NULL;
 			}
 		}
-#if PAGE_SIZE != DEFAULT_STRIPE_SIZE
+#ifdef RAID5_VAR_STRIPE_SIZE
 		if (init_stripe_shared_pages(sh, conf, disks)) {
 			free_stripe(sc, sh);
 			return NULL;
@@ -2596,7 +2596,7 @@ static int resize_stripes(struct r5conf *conf, int newsize)
 		osh = get_free_stripe(conf, hash);
 		unlock_device_hash_lock(conf, hash);
 
-#if PAGE_SIZE != DEFAULT_STRIPE_SIZE
+#ifdef RAID5_VAR_STRIPE_SIZE
 	for (i = 0; i < osh->nr_pages; i++) {
 		nsh->pages[i] = osh->pages[i];
 		osh->pages[i] = NULL;
@@ -2655,7 +2655,7 @@ static int resize_stripes(struct r5conf *conf, int newsize)
 		nsh = list_entry(newstripes.next, struct stripe_head, lru);
 		list_del_init(&nsh->lru);
 
-#if PAGE_SIZE != DEFAULT_STRIPE_SIZE
+#ifdef RAID5_VAR_STRIPE_SIZE
 		for (i = 0; i < nsh->nr_pages; i++) {
 			if (nsh->pages[i])
 				continue;
@@ -7173,7 +7173,7 @@ raid5_show_stripe_size(struct mddev  *mddev, char *page)
 	return ret;
 }
 
-#if PAGE_SIZE != DEFAULT_STRIPE_SIZE
+#ifdef RAID5_VAR_STRIPE_SIZE
 static ssize_t
 raid5_store_stripe_size(struct mddev  *mddev, const char *page, size_t len)
 {
@@ -7711,7 +7711,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)
 		goto abort;
 
 	conf->mddev = mddev;
-#if PAGE_SIZE != DEFAULT_STRIPE_SIZE
+#ifdef RAID5_VAR_STRIPE_SIZE
 	conf->stripe_size = DEFAULT_STRIPE_SIZE;
 	conf->stripe_shift = ilog2(DEFAULT_STRIPE_SIZE) - 9;
 	conf->stripe_sectors = DEFAULT_STRIPE_SIZE >> 9;
diff --git a/drivers/md/raid5.h b/drivers/md/raid5.h
index 94b3e2c947ba..0f87b58a9a61 100644
--- a/drivers/md/raid5.h
+++ b/drivers/md/raid5.h
@@ -197,6 +197,9 @@ enum reconstruct_states {
 };
 
 #define DEFAULT_STRIPE_SIZE	4096
+#if PAGE_SIZE_MIN != DEFAULT_STRIPE_SIZE || PAGE_SIZE_MAX != DEFAULT_STRIPE_SIZE
+#define RAID5_VAR_STRIPE_SIZE
+#endif
 struct stripe_head {
 	struct hlist_node	hash;
 	struct list_head	lru;	      /* inactive_list or handle_list */
@@ -249,7 +252,7 @@ struct stripe_head {
 		enum sum_check_flags zero_sum_result;
 	} ops;
 
-#if PAGE_SIZE != DEFAULT_STRIPE_SIZE
+#ifdef RAID5_VAR_STRIPE_SIZE
 	/* These pages will be used by bios in dev[i] */
 	struct page	**pages;
 	int	nr_pages;	/* page array size */
@@ -480,7 +483,7 @@ struct disk_info {
 
 #define NR_STRIPES		256
 
-#if PAGE_SIZE == DEFAULT_STRIPE_SIZE
+#ifndef RAID5_VAR_STRIPE_SIZE
 #define STRIPE_SIZE		PAGE_SIZE
 #define STRIPE_SHIFT		(PAGE_SHIFT - 9)
 #define STRIPE_SECTORS		(STRIPE_SIZE>>9)
@@ -578,7 +581,7 @@ struct r5conf {
 	int			raid_disks;
 	int			max_nr_stripes;
 	int			min_nr_stripes;
-#if PAGE_SIZE != DEFAULT_STRIPE_SIZE
+#ifdef RAID5_VAR_STRIPE_SIZE
 	unsigned long	stripe_size;
 	unsigned int	stripe_shift;
 	unsigned long	stripe_sectors;
@@ -696,7 +699,7 @@ struct r5conf {
 	int			ctx_size;
 };
 
-#if PAGE_SIZE == DEFAULT_STRIPE_SIZE
+#ifndef RAID5_VAR_STRIPE_SIZE
 #define RAID5_STRIPE_SIZE(conf)	STRIPE_SIZE
 #define RAID5_STRIPE_SHIFT(conf)	STRIPE_SHIFT
 #define RAID5_STRIPE_SECTORS(conf)	STRIPE_SECTORS
@@ -784,7 +787,7 @@ static inline int algorithm_is_DDF(int layout)
 	return layout >= 8 && layout <= 10;
 }
 
-#if PAGE_SIZE != DEFAULT_STRIPE_SIZE
+#ifdef RAID5_VAR_STRIPE_SIZE
 /*
  * Return offset of the corresponding page for r5dev.
  */

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [RFC PATCH v2 05/13] zram: Remove PAGE_SIZE use in preprocessor conditionals
  2026-12-02  3:16 ` Eric Curtin
                   ` (4 preceding siblings ...)
  (?)
@ 2026-12-02  3:16 ` Eric Curtin
  -1 siblings, 0 replies; 20+ messages in thread
From: Eric Curtin @ 2026-12-02  3:16 UTC (permalink / raw)
  To: linux-kernel
  Cc: Eric Curtin, Minchan Kim, Sergey Senozhatsky, Jens Axboe,
	linux-block

From: Eric Curtin <eric.curtin@docker.com>

With arm64 boot-time page size selection PAGE_SIZE and PAGE_SHIFT are
not compile-time constants, so they cannot be used in #if or to size
arrays.

Turn the "#if PAGE_SIZE != 4096" is_partial_io() and the
ZRAM_PARTIAL_IO define into ordinary C conditions on PAGE_SIZE, and set
max_write_zeroes_sectors with a conditional expression instead of
#if. Size the pp_buckets array with a new NUM_PP_BUCKETS_MAX based on
PAGE_SIZE_MAX, and base ZRAM_FLAG_SHIFT on PAGE_SHIFT_MAX so that the
flag bits do not overlap the size bits for any page size.

The compiler still folds the conditions when the page size is fixed, so
there is no functional change for compile-time page sizes.

Signed-off-by: Eric Curtin <eric.curtin@docker.com>
---
 drivers/block/zram/zram_drv.c | 20 ++++++--------------
 drivers/block/zram/zram_drv.h |  2 +-
 2 files changed, 7 insertions(+), 15 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index ab064c84b092..11a2341a0764 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -209,18 +209,10 @@ static bool zram_can_store_page(struct zram *zram)
 	return !zram->limit_pages || alloced_pages <= zram->limit_pages;
 }
 
-#if PAGE_SIZE != 4096
 static inline bool is_partial_io(struct bio_vec *bvec)
 {
-	return bvec->bv_len != PAGE_SIZE;
+	return PAGE_SIZE != 4096 && bvec->bv_len != PAGE_SIZE;
 }
-#define ZRAM_PARTIAL_IO		1
-#else
-static inline bool is_partial_io(struct bio_vec *bvec)
-{
-	return false;
-}
-#endif
 
 #if defined CONFIG_ZRAM_WRITEBACK || defined CONFIG_ZRAM_MULTI_COMP
 struct zram_pp_slot {
@@ -234,9 +226,10 @@ struct zram_pp_slot {
  */
 #define PP_BUCKET_SIZE_RANGE	64
 #define NUM_PP_BUCKETS		((PAGE_SIZE / PP_BUCKET_SIZE_RANGE) + 1)
+#define NUM_PP_BUCKETS_MAX	((PAGE_SIZE_MAX / PP_BUCKET_SIZE_RANGE) + 1)
 
 struct zram_pp_ctl {
-	struct list_head	pp_buckets[NUM_PP_BUCKETS];
+	struct list_head	pp_buckets[NUM_PP_BUCKETS_MAX];
 };
 
 static struct zram_pp_ctl *init_pp_ctl(void)
@@ -1519,7 +1512,7 @@ static int read_from_bdev(struct zram *zram, struct page *page,
 {
 	atomic64_inc(&zram->stats.bd_reads);
 	if (!parent) {
-		if (WARN_ON_ONCE(!IS_ENABLED(ZRAM_PARTIAL_IO)))
+		if (WARN_ON_ONCE(PAGE_SIZE == 4096))
 			return -EIO;
 		return read_from_bdev_sync(zram, page, index, blk_idx);
 	}
@@ -3078,9 +3071,8 @@ static int zram_add(void)
 		 * aligned to physical block size.  So we can't ensure that all
 		 * discarded logical blocks are zeroed.
 		 */
-#if ZRAM_LOGICAL_BLOCK_SIZE == PAGE_SIZE
-		.max_write_zeroes_sectors	= UINT_MAX,
-#endif
+		.max_write_zeroes_sectors	=
+			ZRAM_LOGICAL_BLOCK_SIZE == PAGE_SIZE ? UINT_MAX : 0,
 		.features			= BLK_FEAT_STABLE_WRITES |
 						  BLK_FEAT_SYNCHRONOUS,
 	};
diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h
index 7a55d751417e..b92d81fafd3f 100644
--- a/drivers/block/zram/zram_drv.h
+++ b/drivers/block/zram/zram_drv.h
@@ -37,7 +37,7 @@
  *
  * We use BUILD_BUG_ON() to make sure that zram pageflags don't overflow.
  */
-#define ZRAM_FLAG_SHIFT (PAGE_SHIFT + 1)
+#define ZRAM_FLAG_SHIFT (PAGE_SHIFT_MAX + 1)
 
 /* Only 2 bits are allowed for comp priority index */
 #define ZRAM_COMP_PRIORITY_MASK	0x3

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [RFC PATCH v2 06/13] xen/blkback: Size indirect_pages for the largest page size
  2026-12-02  3:16 ` Eric Curtin
                   ` (5 preceding siblings ...)
  (?)
@ 2026-12-02  3:16 ` Eric Curtin
  -1 siblings, 0 replies; 20+ messages in thread
From: Eric Curtin @ 2026-12-02  3:16 UTC (permalink / raw)
  To: linux-kernel
  Cc: Eric Curtin, Roger Pau Monné, Jens Axboe, xen-devel,
	linux-block

From: Eric Curtin <eric.curtin@docker.com>

With arm64 boot-time page size selection PAGE_SIZE is not a
compile-time constant. MAX_INDIRECT_PAGES depends on the number of
segments that fit in an indirect frame, which depends on the guest page
size, so it cannot size the indirect_pages array in struct pending_req.

Add SEGS_PER_INDIRECT_FRAME_MIN, computed with the largest page size
(the fewest segments per frame), and MAX_INDIRECT_PAGES_MAX derived from
it, and use that for the array. Check the maximum against
BLKIF_MAX_INDIRECT_PAGES_PER_REQUEST in xen_blkif_alloc().

No functional change for compile-time page sizes.

Signed-off-by: Eric Curtin <eric.curtin@docker.com>
---
 drivers/block/xen-blkback/common.h | 7 ++++++-
 drivers/block/xen-blkback/xenbus.c | 2 +-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/block/xen-blkback/common.h b/drivers/block/xen-blkback/common.h
index f5890b3f1df9..14c244aa8807 100644
--- a/drivers/block/xen-blkback/common.h
+++ b/drivers/block/xen-blkback/common.h
@@ -65,6 +65,11 @@ extern unsigned int xenblk_max_queues;
 
 #define MAX_INDIRECT_PAGES \
 	((MAX_INDIRECT_SEGMENTS + SEGS_PER_INDIRECT_FRAME - 1)/SEGS_PER_INDIRECT_FRAME)
+#define SEGS_PER_INDIRECT_FRAME_MIN	\
+	(XEN_PAGES_PER_INDIRECT_FRAME / XEN_PFN_PER_PAGE_MAX)
+#define MAX_INDIRECT_PAGES_MAX \
+	((MAX_INDIRECT_SEGMENTS + SEGS_PER_INDIRECT_FRAME_MIN - 1) / \
+	 SEGS_PER_INDIRECT_FRAME_MIN)
 #define INDIRECT_PAGES(_segs) DIV_ROUND_UP(_segs, XEN_PAGES_PER_INDIRECT_FRAME)
 
 /* Not a real protocol.  Used to generate ring structs which contain
@@ -353,7 +358,7 @@ struct pending_req {
 	struct list_head	free_list;
 	struct grant_page	*segments[MAX_INDIRECT_SEGMENTS];
 	/* Indirect descriptors */
-	struct grant_page	*indirect_pages[MAX_INDIRECT_PAGES];
+	struct grant_page	*indirect_pages[MAX_INDIRECT_PAGES_MAX];
 	struct seg_buf		seg[MAX_INDIRECT_SEGMENTS];
 	struct bio		*biolist[MAX_INDIRECT_SEGMENTS];
 	struct gnttab_unmap_grant_ref unmap[MAX_INDIRECT_SEGMENTS];
diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c
index 8d0ff8fcac22..d2d51fe6081d 100644
--- a/drivers/block/xen-blkback/xenbus.c
+++ b/drivers/block/xen-blkback/xenbus.c
@@ -174,7 +174,7 @@ static struct xen_blkif *xen_blkif_alloc(domid_t domid)
 {
 	struct xen_blkif *blkif;
 
-	BUILD_BUG_ON(MAX_INDIRECT_PAGES > BLKIF_MAX_INDIRECT_PAGES_PER_REQUEST);
+	BUILD_BUG_ON(MAX_INDIRECT_PAGES_MAX > BLKIF_MAX_INDIRECT_PAGES_PER_REQUEST);
 
 	blkif = kmem_cache_zalloc(xen_blkif_cachep, GFP_KERNEL);
 	if (!blkif)

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [RFC PATCH v2 07/13] null_blk: Size the nullb_page bitmap for PAGE_SIZE_MAX
  2026-12-02  3:16 ` Eric Curtin
                   ` (6 preceding siblings ...)
  (?)
@ 2026-12-02  3:16 ` Eric Curtin
  -1 siblings, 0 replies; 20+ messages in thread
From: Eric Curtin @ 2026-12-02  3:16 UTC (permalink / raw)
  To: linux-kernel; +Cc: Eric Curtin, Jens Axboe, linux-block

From: Eric Curtin <eric.curtin@docker.com>

With arm64 boot-time page size selection PAGE_SIZE is not a
compile-time constant, but struct nullb_page embeds a bitmap with one
bit per sector of a page plus two flag bits.

Add MAP_SZ_MAX, based on PAGE_SIZE_MAX, and use it to declare the
bitmap. The runtime logic (NULLB_PAGE_LOCK and NULLB_PAGE_FREE) keeps
using MAP_SZ, derived from the actual page size, so the extra bitmap
space is simply unused on smaller pages.

No functional change for compile-time page sizes.

Signed-off-by: Eric Curtin <eric.curtin@docker.com>
---
 drivers/block/null_blk/main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index ec0d7ba4d938..f5a02a861daf 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -46,6 +46,7 @@ enum nullb_device_flags {
 };
 
 #define MAP_SZ		((PAGE_SIZE >> SECTOR_SHIFT) + 2)
+#define MAP_SZ_MAX	((PAGE_SIZE_MAX >> SECTOR_SHIFT) + 2)
 /*
  * nullb_page is a page in memory for nullb devices.
  *
@@ -60,7 +61,7 @@ enum nullb_device_flags {
  */
 struct nullb_page {
 	struct page *page;
-	DECLARE_BITMAP(bitmap, MAP_SZ);
+	DECLARE_BITMAP(bitmap, MAP_SZ_MAX);
 };
 #define NULLB_PAGE_LOCK (MAP_SZ - 1)
 #define NULLB_PAGE_FREE (MAP_SZ - 2)

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [RFC PATCH v2 08/13] drbd: Use PAGE_SHIFT_MIN in preprocessor checks
  2026-12-02  3:16 ` Eric Curtin
                   ` (7 preceding siblings ...)
  (?)
@ 2026-12-02  3:16 ` Eric Curtin
  -1 siblings, 0 replies; 20+ messages in thread
From: Eric Curtin @ 2026-12-02  3:16 UTC (permalink / raw)
  To: linux-kernel
  Cc: Eric Curtin, Philipp Reisner, Lars Ellenberg,
	Christoph Böhmwalder, Jens Axboe, drbd-dev, linux-block

From: Eric Curtin <eric.curtin@docker.com>

With arm64 boot-time page size selection PAGE_SHIFT is not a
compile-time constant and cannot be evaluated by the preprocessor.

Check the AL extent/bitmap block relationship in drbd_actlog.c and the
DRBD_MAX_BIO_SIZE limit in drbd_int.h against PAGE_SHIFT_MIN, so that
the build fails if the assumption could be violated by any supported
page size.

Drop the "ambiguous BITS_PER_PAGE" #error from drbd_bitmap.c. It
compared a macro against an expression of PAGE_SHIFT in #if, which can
no longer be evaluated, and it only guarded against a conflicting
definition of BITS_PER_PAGE in other headers.

Signed-off-by: Eric Curtin <eric.curtin@docker.com>
---
 drivers/block/drbd/drbd_actlog.c | 2 +-
 drivers/block/drbd/drbd_bitmap.c | 4 ----
 drivers/block/drbd/drbd_int.h    | 2 +-
 3 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/block/drbd/drbd_actlog.c b/drivers/block/drbd/drbd_actlog.c
index b3dbf6c76e98..086b8efce9ae 100644
--- a/drivers/block/drbd/drbd_actlog.c
+++ b/drivers/block/drbd/drbd_actlog.c
@@ -277,7 +277,7 @@ bool drbd_al_begin_io_prepare(struct drbd_device *device, struct drbd_interval *
 	return need_transaction;
 }
 
-#if (PAGE_SHIFT + 3) < (AL_EXTENT_SHIFT - BM_BLOCK_SHIFT)
+#if (PAGE_SHIFT_MIN + 3) < (AL_EXTENT_SHIFT - BM_BLOCK_SHIFT)
 /* Currently BM_BLOCK_SHIFT, BM_EXT_SHIFT and AL_EXTENT_SHIFT
  * are still coupled, or assume too much about their relation.
  * Code below will not work if this is violated.
diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
index 65ea6ec66bfd..7d715dcaf982 100644
--- a/drivers/block/drbd/drbd_bitmap.c
+++ b/drivers/block/drbd/drbd_bitmap.c
@@ -473,10 +473,6 @@ void drbd_bm_cleanup(struct drbd_device *device)
 #ifndef BITS_PER_PAGE
 #define BITS_PER_PAGE		(1UL << (PAGE_SHIFT + 3))
 #define BITS_PER_PAGE_MASK	(BITS_PER_PAGE - 1)
-#else
-# if BITS_PER_PAGE != (1UL << (PAGE_SHIFT + 3))
-#  error "ambiguous BITS_PER_PAGE"
-# endif
 #endif
 #define BITS_PER_LONG_MASK	(BITS_PER_LONG - 1)
 static int bm_clear_surplus(struct drbd_bitmap *b)
diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
index 48b45c3142f7..2db7f596a68d 100644
--- a/drivers/block/drbd/drbd_int.h
+++ b/drivers/block/drbd/drbd_int.h
@@ -1261,7 +1261,7 @@ struct bm_extent {
  * A followup commit may allow even bigger BIO sizes,
  * once we thought that through. */
 #define DRBD_MAX_BIO_SIZE (1U << 20)
-#if DRBD_MAX_BIO_SIZE > (BIO_MAX_VECS << PAGE_SHIFT)
+#if DRBD_MAX_BIO_SIZE > (BIO_MAX_VECS << PAGE_SHIFT_MIN)
 #error Architecture not supported: DRBD_MAX_BIO_SIZE > BIO_MAX_SIZE
 #endif
 #define DRBD_MAX_BIO_SIZE_SAFE (1U << 12)       /* Works always = 4k */

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [RFC PATCH v2 09/13] nvme: Check the DSM range buffer against PAGE_SIZE_MIN
  2026-12-02  3:16 ` Eric Curtin
                   ` (8 preceding siblings ...)
  (?)
@ 2026-12-02  3:16 ` Eric Curtin
  -1 siblings, 0 replies; 20+ messages in thread
From: Eric Curtin @ 2026-12-02  3:16 UTC (permalink / raw)
  To: linux-kernel
  Cc: Ryan Roberts, Keith Busch, Jens Axboe, Christoph Hellwig,
	Sagi Grimberg, linux-nvme

From: Ryan Roberts <ryan.roberts@arm.com>

The BUILD_BUG_ON() in nvme_init_ctrl() verifies that the discard page
can hold NVME_DSM_MAX_RANGES DSM ranges. PAGE_SIZE is not a compile-time
constant with arm64 boot-time page size selection, so compare against
PAGE_SIZE_MIN, the smallest page size that can be in use.

Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
---
 drivers/nvme/host/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index f43582e5f6c4..8cf78eff9cff 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -5295,7 +5295,7 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
 	ctrl->io_timeout = NVME_IO_TIMEOUT;
 
 	BUILD_BUG_ON(NVME_DSM_MAX_RANGES * sizeof(struct nvme_dsm_range) >
-			PAGE_SIZE);
+			PAGE_SIZE_MIN);
 	ctrl->discard_page = alloc_page(GFP_KERNEL | __GFP_ZERO);
 	if (!ctrl->discard_page) {
 		ret = -ENOMEM;


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [RFC PATCH v2 10/13] dm: Initialise swap_bios from the runtime PAGE_SIZE
  2026-12-02  3:16 ` Eric Curtin
                   ` (9 preceding siblings ...)
  (?)
@ 2026-12-02  3:16 ` Eric Curtin
  -1 siblings, 0 replies; 20+ messages in thread
From: Eric Curtin @ 2026-12-02  3:16 UTC (permalink / raw)
  To: linux-kernel
  Cc: Ryan Roberts, Alasdair Kergon, Mike Snitzer, Mikulas Patocka,
	Benjamin Marzinski, dm-devel

From: Ryan Roberts <ryan.roberts@arm.com>

DEFAULT_SWAP_BIOS is computed from PAGE_SIZE, so with arm64 boot-time
page size selection it is not a compile-time constant and cannot be used
as a static initialiser for swap_bios.

Define swap_bios with DEFINE_GLOBAL_PAGE_SIZE_VAR(), which keeps a
plain initialiser for a fixed page size and otherwise assigns the
default once the page size is known at boot.

Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
---
 drivers/md/dm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 38eaae8ac9b4..d47412e0b957 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -126,7 +126,7 @@ EXPORT_SYMBOL_GPL(dm_bio_get_target_bio_nr);
 static int dm_numa_node = DM_NUMA_NODE;
 
 #define DEFAULT_SWAP_BIOS	(8 * 1048576 / PAGE_SIZE)
-static int swap_bios = DEFAULT_SWAP_BIOS;
+static DEFINE_GLOBAL_PAGE_SIZE_VAR(int, swap_bios, DEFAULT_SWAP_BIOS);
 static int get_swap_bios(void)
 {
 	int latch = READ_ONCE(swap_bios);

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [RFC PATCH v2 11/13] virtio: Handle boot-time PAGE_SIZE in balloon, blk and 9p transport
  2026-12-02  3:16 ` Eric Curtin
                   ` (10 preceding siblings ...)
  (?)
@ 2026-12-02  3:16 ` Eric Curtin
  -1 siblings, 0 replies; 20+ messages in thread
From: Eric Curtin @ 2026-12-02  3:16 UTC (permalink / raw)
  To: linux-kernel
  Cc: Ryan Roberts, Michael S. Tsirkin, Jason Wang, Eugenio Pérez,
	Xuan Zhuo, Paolo Bonzini, Stefan Hajnoczi, Jens Axboe,
	David Hildenbrand, Eric Van Hensbergen, Latchesar Ionkov,
	Dominique Martinet, Christian Schoenebeck, virtualization,
	linux-block, v9fs

From: Ryan Roberts <ryan.roberts@arm.com>

With boot-time page size selection PAGE_SIZE is not a compile-time
constant.

- virtio_blk: check the serial_show() buffer size against PAGE_SIZE_MIN.
- virtio_balloon: check PAGE_SHIFT_MIN in page_to_balloon_pfn(), and
  compare the new VIRTIO_BALLOON_PAGES_PER_PAGE_MAX, based on
  PAGE_SIZE_MAX, with VIRTIO_BALLOON_ARRAY_PFNS_MAX in set_page_pfns().
  Select the free page reporting order of 5 with a run-time
  PAGE_SIZE == SZ_64K test on arm64, instead of
  CONFIG_ARM64_64K_PAGES.
- 9p: define p9_virtio_trans with DEFINE_GLOBAL_PAGE_SIZE_VAR() so that
  it is initialised at boot.

No functional change for compile-time page sizes.

Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
---
 drivers/block/virtio_blk.c      |  2 +-
 drivers/virtio/virtio_balloon.c | 10 ++++++----
 net/9p/trans_virtio.c           |  4 ++--
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 2b462005cdb6..c1b26c60ccfb 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -904,7 +904,7 @@ static ssize_t serial_show(struct device *dev,
 	int err;
 
 	/* sysfs gives us a PAGE_SIZE buffer */
-	BUILD_BUG_ON(PAGE_SIZE < VIRTIO_BLK_ID_BYTES);
+	BUILD_BUG_ON(PAGE_SIZE_MIN < VIRTIO_BLK_ID_BYTES);
 
 	buf[VIRTIO_BLK_ID_BYTES] = '\0';
 	err = virtblk_get_id(disk, buf);
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 8c1b47ec17a2..a2c9429586fb 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -26,6 +26,7 @@
  * page units.
  */
 #define VIRTIO_BALLOON_PAGES_PER_PAGE (unsigned int)(PAGE_SIZE >> VIRTIO_BALLOON_PFN_SHIFT)
+#define VIRTIO_BALLOON_PAGES_PER_PAGE_MAX (unsigned int)(PAGE_SIZE_MAX >> VIRTIO_BALLOON_PFN_SHIFT)
 #define VIRTIO_BALLOON_ARRAY_PFNS_MAX 256
 /* Maximum number of (4k) pages to deflate on OOM notifications. */
 #define VIRTIO_BALLOON_OOM_NR_PAGES 256
@@ -139,7 +140,7 @@ static u32 page_to_balloon_pfn(struct page *page)
 {
 	unsigned long pfn = page_to_pfn(page);
 
-	BUILD_BUG_ON(PAGE_SHIFT < VIRTIO_BALLOON_PFN_SHIFT);
+	BUILD_BUG_ON(PAGE_SHIFT_MIN < VIRTIO_BALLOON_PFN_SHIFT);
 	/* Convert pfn from Linux page size to balloon page size. */
 	return pfn * VIRTIO_BALLOON_PAGES_PER_PAGE;
 }
@@ -231,7 +232,7 @@ static void set_page_pfns(struct virtio_balloon *vb,
 {
 	unsigned int i;
 
-	BUILD_BUG_ON(VIRTIO_BALLOON_PAGES_PER_PAGE > VIRTIO_BALLOON_ARRAY_PFNS_MAX);
+	BUILD_BUG_ON(VIRTIO_BALLOON_PAGES_PER_PAGE_MAX > VIRTIO_BALLOON_ARRAY_PFNS_MAX);
 
 	/*
 	 * Set balloon pfns pointing at this page.
@@ -1040,8 +1041,9 @@ static int virtballoon_probe(struct virtio_device *vdev)
 		 * host's base page size. However, it needs more work to report
 		 * that value. The hard-coded order would be fine currently.
 		 */
-#if defined(CONFIG_ARM64) && defined(CONFIG_ARM64_64K_PAGES)
-		vb->pr_dev_info.order = 5;
+#if defined(CONFIG_ARM64)
+		if (PAGE_SIZE == SZ_64K)
+			vb->pr_dev_info.order = 5;
 #endif
 
 		vb->pr_dev_info.capacity = capacity;
diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c
index 9fa63e3ebf67..181ed87f703f 100644
--- a/net/9p/trans_virtio.c
+++ b/net/9p/trans_virtio.c
@@ -795,7 +795,7 @@ static struct virtio_driver p9_virtio_drv = {
 	.remove		= p9_virtio_remove,
 };
 
-static struct p9_trans_module p9_virtio_trans = {
+static DEFINE_GLOBAL_PAGE_SIZE_VAR(struct p9_trans_module, p9_virtio_trans, {
 	.name = "virtio",
 	.create = p9_virtio_create,
 	.close = p9_virtio_close,
@@ -814,7 +814,7 @@ static struct p9_trans_module p9_virtio_trans = {
 	.def = true,
 	.supports_vmalloc = false,
 	.owner = THIS_MODULE,
-};
+});
 
 /* The standard init function */
 static int __init p9_virtio_init(void)

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [RFC PATCH v2 12/13] ata: sata_sil24: Use flexible arrays for the command block SGEs
  2026-12-02  3:16 ` Eric Curtin
                   ` (11 preceding siblings ...)
  (?)
@ 2026-12-02  3:16 ` Eric Curtin
  2026-12-02  7:10   ` Damien Le Moal
  -1 siblings, 1 reply; 20+ messages in thread
From: Eric Curtin @ 2026-12-02  3:16 UTC (permalink / raw)
  To: linux-kernel; +Cc: Ryan Roberts, Damien Le Moal, Niklas Cassel, linux-ide

From: Ryan Roberts <ryan.roberts@arm.com>

SIL24_MAX_SGE is derived from PAGE_SIZE, so with boot-time page size
selection it is not a compile-time constant and cannot size the sge[]
arrays in struct sil24_ata_block and struct sil24_atapi_block.

Make sge[] a flexible array in both and move SIL24_MAX_SGT and
SIL24_MAX_SGE out of the enum into macros, since they are no longer
constant. Add SIL24_*_BLOCK_SIZE macros that compute the block sizes
with struct_size_t(), and add sil24_cmd_blk() to index the command block
array, because sizeof(union sil24_cmd_block) is no longer the stride.
Use SIL24_CMD_BLOCK_SIZE for the block stride in sil24_qc_issue() and
for the allocation size in sil24_port_start().

Define sil24_sht with DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST() so that its
sg_tablesize is initialised at boot.

The link-time check that union sil24_cmd_block is exactly PAGE_SIZE
cannot work for a run-time value, so replace it with WARN_ON_ONCE()
checks in sil24_init_one() that fail the probe with -EINVAL.

Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
---
 drivers/ata/sata_sil24.c | 70 ++++++++++++++++++++++++----------------
 1 file changed, 43 insertions(+), 27 deletions(-)

diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c
index 7acd55b17b18..ec420923d866 100644
--- a/drivers/ata/sata_sil24.c
+++ b/drivers/ata/sata_sil24.c
@@ -42,26 +42,25 @@ struct sil24_sge {
 	__le32	flags;
 };
 
+/*
+ * sil24 fetches in chunks of 64bytes.  The first block
+ * contains the PRB and two SGEs.  From the second block, it's
+ * consisted of four SGEs and called SGT.  Calculate the
+ * number of SGTs that fit into one page.
+ */
+#define SIL24_PRB_SZ	(sizeof(struct sil24_prb) + 2 * sizeof(struct sil24_sge))
+#define SIL24_MAX_SGT	((PAGE_SIZE - SIL24_PRB_SZ) / (4 * sizeof(struct sil24_sge)))
+
+/*
+ * This will give us one unused SGEs for ATA.  This extra SGE
+ * will be used to store CDB for ATAPI devices.
+ */
+#define SIL24_MAX_SGE	(4 * SIL24_MAX_SGT + 1)
 
 enum {
 	SIL24_HOST_BAR		= 0,
 	SIL24_PORT_BAR		= 2,
 
-	/* sil24 fetches in chunks of 64bytes.  The first block
-	 * contains the PRB and two SGEs.  From the second block, it's
-	 * consisted of four SGEs and called SGT.  Calculate the
-	 * number of SGTs that fit into one page.
-	 */
-	SIL24_PRB_SZ		= sizeof(struct sil24_prb)
-				  + 2 * sizeof(struct sil24_sge),
-	SIL24_MAX_SGT		= (PAGE_SIZE - SIL24_PRB_SZ)
-				  / (4 * sizeof(struct sil24_sge)),
-
-	/* This will give us one unused SGEs for ATA.  This extra SGE
-	 * will be used to store CDB for ATAPI devices.
-	 */
-	SIL24_MAX_SGE		= 4 * SIL24_MAX_SGT + 1,
-
 	/*
 	 * Global controller registers (128 bytes @ BAR0)
 	 */
@@ -244,13 +243,13 @@ enum {
 
 struct sil24_ata_block {
 	struct sil24_prb prb;
-	struct sil24_sge sge[SIL24_MAX_SGE];
+	struct sil24_sge sge[];
 };
 
 struct sil24_atapi_block {
 	struct sil24_prb prb;
 	u8 cdb[16];
-	struct sil24_sge sge[SIL24_MAX_SGE];
+	struct sil24_sge sge[];
 };
 
 union sil24_cmd_block {
@@ -258,6 +257,10 @@ union sil24_cmd_block {
 	struct sil24_atapi_block atapi;
 };
 
+#define SIL24_ATA_BLOCK_SIZE	struct_size_t(struct sil24_ata_block, sge, SIL24_MAX_SGE)
+#define SIL24_ATAPI_BLOCK_SIZE	struct_size_t(struct sil24_atapi_block, sge, SIL24_MAX_SGE)
+#define SIL24_CMD_BLOCK_SIZE	max(SIL24_ATA_BLOCK_SIZE, SIL24_ATAPI_BLOCK_SIZE)
+
 static const struct sil24_cerr_info {
 	unsigned int err_mask, action;
 	const char *desc;
@@ -322,6 +325,13 @@ struct sil24_port_priv {
 	int do_port_rst;
 };
 
+/* sizeof(union sil24_cmd_block) is not the stride between blocks */
+static inline union sil24_cmd_block *
+sil24_cmd_blk(struct sil24_port_priv *pp, unsigned int tag)
+{
+	return (void *)((u8 *)pp->cmd_block + tag * SIL24_CMD_BLOCK_SIZE);
+}
+
 static void sil24_dev_config(struct ata_device *dev);
 static int sil24_scr_read(struct ata_link *link, unsigned sc_reg, u32 *val);
 static int sil24_scr_write(struct ata_link *link, unsigned sc_reg, u32 val);
@@ -372,7 +382,7 @@ static struct pci_driver sil24_pci_driver = {
 #endif
 };
 
-static const struct scsi_host_template sil24_sht = {
+static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct scsi_host_template, sil24_sht, {
 	__ATA_BASE_SHT(DRV_NAME),
 	.can_queue		= SIL24_MAX_CMDS,
 	.sg_tablesize		= SIL24_MAX_SGE,
@@ -380,7 +390,7 @@ static const struct scsi_host_template sil24_sht = {
 	.sdev_groups		= ata_ncq_sdev_groups,
 	.change_queue_depth	= ata_scsi_change_queue_depth,
 	.sdev_configure		= ata_scsi_sdev_configure
-};
+});
 
 static struct ata_port_operations sil24_ops = {
 	.inherits		= &sata_pmp_port_ops,
@@ -599,7 +609,7 @@ static int sil24_exec_polled_cmd(struct ata_port *ap, int pmp,
 {
 	void __iomem *port = sil24_port_base(ap);
 	struct sil24_port_priv *pp = ap->private_data;
-	struct sil24_prb *prb = &pp->cmd_block[0].ata.prb;
+	struct sil24_prb *prb = &sil24_cmd_blk(pp, 0)->ata.prb;
 	dma_addr_t paddr = pp->cmd_block_dma;
 	u32 irq_enabled, irq_mask, irq_stat;
 	int rc;
@@ -841,7 +851,7 @@ static enum ata_completion_errors sil24_qc_prep(struct ata_queued_cmd *qc)
 	struct sil24_sge *sge;
 	u16 ctrl = 0;
 
-	cb = &pp->cmd_block[sil24_tag(qc->hw_tag)];
+	cb = sil24_cmd_blk(pp, sil24_tag(qc->hw_tag));
 
 	if (!ata_is_atapi(qc->tf.protocol)) {
 		prb = &cb->ata.prb;
@@ -889,7 +899,7 @@ static unsigned int sil24_qc_issue(struct ata_queued_cmd *qc)
 	dma_addr_t paddr;
 	void __iomem *activate;
 
-	paddr = pp->cmd_block_dma + tag * sizeof(*pp->cmd_block);
+	paddr = pp->cmd_block_dma + tag * SIL24_CMD_BLOCK_SIZE;
 	activate = port + PORT_CMD_ACTIVATE + tag * 8;
 
 	/*
@@ -1196,7 +1206,7 @@ static int sil24_port_start(struct ata_port *ap)
 	struct device *dev = ap->host->dev;
 	struct sil24_port_priv *pp;
 	union sil24_cmd_block *cb;
-	size_t cb_size = sizeof(*cb) * SIL24_MAX_CMDS;
+	size_t cb_size = SIL24_CMD_BLOCK_SIZE * SIL24_MAX_CMDS;
 	dma_addr_t cb_dma;
 
 	pp = devm_kzalloc_obj(dev, *pp);
@@ -1261,7 +1271,6 @@ static void sil24_init_controller(struct ata_host *host)
 
 static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
-	extern int __MARKER__sil24_cmd_block_is_sized_wrongly;
 	struct ata_port_info pi = sil24_port_info[ent->driver_data];
 	const struct ata_port_info *ppi[] = { &pi, NULL };
 	void __iomem * const *iomap;
@@ -1269,9 +1278,16 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	int rc;
 	u32 tmp;
 
-	/* cause link error if sil24_cmd_block is sized wrongly */
-	if (sizeof(union sil24_cmd_block) != PAGE_SIZE)
-		__MARKER__sil24_cmd_block_is_sized_wrongly = 1;
+	/*
+	 * union sil24_cmd_block must be PAGE_SIZE once taking into account the
+	 * 'sge' flexible array members in struct sil24_atapi_block and struct
+	 * sil24_ata_block.
+	 */
+	if (WARN_ON_ONCE(SIL24_ATAPI_BLOCK_SIZE != PAGE_SIZE))
+		return -EINVAL;
+	if (WARN_ON_ONCE(SIL24_ATA_BLOCK_SIZE !=
+			 PAGE_SIZE - sizeof_field(struct sil24_atapi_block, cdb)))
+		return -EINVAL;
 
 	ata_print_version_once(&pdev->dev, DRV_VERSION);
 

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [RFC PATCH v2 13/13] mm: Use PAGE_SIZE_MIN/MAX where a compile-time constant is required
  2026-12-02  3:16 ` Eric Curtin
@ 2026-12-02  3:16   ` Eric Curtin
  -1 siblings, 0 replies; 20+ messages in thread
From: Eric Curtin @ 2026-12-02  3:16 UTC (permalink / raw)
  To: linux-kernel
  Cc: Ryan Roberts, Miquel Raynal, Richard Weinberger,
	Vignesh Raghavendra, Dan Williams, Vishal Verma, Dave Jiang,
	Alison Schofield, Ira Weiny, David Hildenbrand, Liam R. Howlett,
	Vlastimil Babka, Mike Rapoport, Michal Hocko, Andrew Morton,
	Kairui Song, Barry Song, Qi Zheng, Shakeel Butt, Axel Rasmussen,
	Yuanchu Xie, Wei Xu, Baoquan He, Baolin Wang, Harry Yoo, Hao Li,
	Christoph Lameter, David Rientjes, Roman Gushchin, Chris Li,
	Kemeng Shi, Nhat Pham, Youngjun Park, Zi Yan, Nico Pache,
	Dev Jain, Lance Yang, Usama Arif, Kiryl Shutsemau,
	Johannes Weiner, Muchun Song, Lorenzo Stoakes, Suren Baghdasaryan,
	Pedro Falcato, Jann Horn, Matthew Wilcox (Oracle), Jan Kara,
	Uladzislau Rezki, linux-mtd, nvdimm, linux-mm, cgroups,
	linux-fsdevel

From: Ryan Roberts <ryan.roberts@arm.com>

With arm64 boot-time page size selection, PAGE_SIZE and PAGE_SHIFT are
not compile-time constants. Convert the mm code that needs a constant,
using the PAGE_{SIZE,SHIFT}_{MIN,MAX} limits.

- struct vmap_block: replace the used_map bitmap with a flexible array
  and size the allocation in new_vmap_block() with struct_size().
- union swap_header: drop the page-sized "magic" member and locate the
  signature at SWAP_HEADER_MAGIC, i.e. PAGE_SIZE - 10, using pointer
  arithmetic. Update MAX_SWAP_BADPAGES, read_swap_header() and mtdswap.
- BUILD_BUG_ON(), static_assert() and #if checks in memcontrol, mmzone,
  slub, sparse, leafops and ptep_lockptr() now compare against the
  appropriate limit. Add PFN_SECTION_SHIFT_MIN and SWP_PFN_BITS_MAX for
  this. struct page_frag uses PAGE_SIZE_MAX to choose its field widths.
- stack_guard_gap, fault_around_pages and dirty_bytes_min are defined
  with DEFINE_GLOBAL_PAGE_SIZE_VAR*() so that they can be initialised
  at boot.
- str_dup[] for thp_anon= is a fixed SZ_4K instead of PAGE_SIZE; a
  valid string fits easily for any page size.
- kmem_buckets is sized with KMALLOC_SHIFT_HIGH_MAX, and
  __assume_page_alignment uses PAGE_SIZE_MIN. Add KMALLOC_SHIFT_HIGH_MIN
  and _MAX, and KMALLOC_MAX_CACHE_SIZE_MIN and _MAX, for this.
- _kmalloc_noprof() and _kmalloc_node_noprof() keep the compile-time
  large-versus-cache choice for sizes outside the MIN/MAX cache size
  range. Constant sizes in between go to __kmalloc_noprof() and
  __kmalloc_node_noprof(), so the decision is made at run time.

The ND_MIN_NAMESPACE_SIZE format in nvdimm is changed to %#lx with a
cast, as it is no longer an int constant.

No functional change for compile-time page sizes.

Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
---
 drivers/mtd/mtdswap.c           |  4 ++--
 drivers/nvdimm/namespace_devs.c |  4 ++--
 include/linux/leafops.h         |  2 +-
 include/linux/mm.h              |  2 +-
 include/linux/mm_types_task.h   |  2 +-
 include/linux/mmzone.h          |  3 ++-
 include/linux/slab.h            | 30 ++++++++++++++++++++----------
 include/linux/swap.h            | 16 +++++++++++-----
 include/linux/swapops.h         |  4 ++++
 mm/huge_memory.c                |  4 ++--
 mm/memcontrol.c                 |  4 ++--
 mm/memory.c                     |  4 ++--
 mm/mmap.c                       |  2 +-
 mm/page-writeback.c             |  2 +-
 mm/slub.c                       |  2 +-
 mm/sparse.h                     |  2 +-
 mm/swapfile.c                   |  2 +-
 mm/vmalloc.c                    |  6 ++++--
 18 files changed, 59 insertions(+), 36 deletions(-)

diff --git a/drivers/mtd/mtdswap.c b/drivers/mtd/mtdswap.c
index 92e38ece8931..7b20e49d5a25 100644
--- a/drivers/mtd/mtdswap.c
+++ b/drivers/mtd/mtdswap.c
@@ -1063,13 +1063,13 @@ static int mtdswap_auto_header(struct mtdswap_dev *d, char *buf)
 {
 	union swap_header *hd = (union swap_header *)(buf);
 
-	memset(buf, 0, PAGE_SIZE - 10);
+	memset(buf, 0, SWAP_HEADER_MAGIC);
 
 	hd->info.version = 1;
 	hd->info.last_page = d->mbd_dev->size - 1;
 	hd->info.nr_badpages = 0;
 
-	memcpy(buf + PAGE_SIZE - 10, "SWAPSPACE2", 10);
+	memcpy(buf + SWAP_HEADER_MAGIC, "SWAPSPACE2", 10);
 
 	return 0;
 }
diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
index 3aa0a9026efa..10d5ce31eb4f 100644
--- a/drivers/nvdimm/namespace_devs.c
+++ b/drivers/nvdimm/namespace_devs.c
@@ -1478,8 +1478,8 @@ struct nd_namespace_common *nvdimm_namespace_common_probe(struct device *dev)
 
 	size = nvdimm_namespace_capacity(ndns);
 	if (size < ND_MIN_NAMESPACE_SIZE) {
-		dev_dbg(&ndns->dev, "%pa, too small must be at least %#x\n",
-				&size, ND_MIN_NAMESPACE_SIZE);
+		dev_dbg(&ndns->dev, "%pa, too small must be at least %#lx\n",
+				&size, (unsigned long)ND_MIN_NAMESPACE_SIZE);
 		return ERR_PTR(-ENODEV);
 	}
 
diff --git a/include/linux/leafops.h b/include/linux/leafops.h
index 4c1476ae3234..414da42ffc4c 100644
--- a/include/linux/leafops.h
+++ b/include/linux/leafops.h
@@ -355,7 +355,7 @@ static inline pte_marker softleaf_to_marker(softleaf_t entry)
 static inline bool softleaf_has_pfn(softleaf_t entry)
 {
 	/* Make sure the swp offset can always store the needed fields. */
-	BUILD_BUG_ON(SWP_TYPE_SHIFT < SWP_PFN_BITS);
+	BUILD_BUG_ON(SWP_TYPE_SHIFT < SWP_PFN_BITS_MAX);
 
 	if (softleaf_is_migration(entry))
 		return true;
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 14a35440c806..caca5fcff031 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -4070,7 +4070,7 @@ static inline spinlock_t *pte_lockptr(struct mm_struct *mm, pmd_t *pmd)
 static inline spinlock_t *ptep_lockptr(struct mm_struct *mm, pte_t *pte)
 {
 	BUILD_BUG_ON(IS_ENABLED(CONFIG_HIGHPTE));
-	BUILD_BUG_ON(MAX_PTRS_PER_PTE * sizeof(pte_t) > PAGE_SIZE);
+	BUILD_BUG_ON(MAX_PTRS_PER_PTE * sizeof(pte_t) > PAGE_SIZE_MAX);
 	return ptlock_ptr(virt_to_ptdesc(pte));
 }
 
diff --git a/include/linux/mm_types_task.h b/include/linux/mm_types_task.h
index 2f760f472e19..2fe24a31e24d 100644
--- a/include/linux/mm_types_task.h
+++ b/include/linux/mm_types_task.h
@@ -35,7 +35,7 @@ struct page;
 
 struct page_frag {
 	struct page *page;
-#if (BITS_PER_LONG > 32) || (PAGE_SIZE >= 65536)
+#if (BITS_PER_LONG > 32) || (PAGE_SIZE_MAX >= 65536)
 	__u32 offset;
 	__u32 size;
 #else
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 72ffb2959c4f..bf317cc1a83a 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -1990,6 +1990,7 @@ static inline bool movable_only_nodes(nodemask_t *nodes)
  */
 #define PA_SECTION_SHIFT	(SECTION_SIZE_BITS)
 #define PFN_SECTION_SHIFT	(SECTION_SIZE_BITS - PAGE_SHIFT)
+#define PFN_SECTION_SHIFT_MIN	(SECTION_SIZE_BITS - PAGE_SHIFT_MAX)
 
 #define NR_MEM_SECTIONS		(1UL << SECTIONS_SHIFT)
 
@@ -1999,7 +2000,7 @@ static inline bool movable_only_nodes(nodemask_t *nodes)
 #define SECTION_BLOCKFLAGS_BITS \
 	((1UL << (PFN_SECTION_SHIFT - pageblock_order)) * NR_PAGEBLOCK_BITS)
 
-#if (MAX_PAGE_ORDER + PAGE_SHIFT) > SECTION_SIZE_BITS
+#if (MAX_PAGE_ORDER + PAGE_SHIFT_MAX) > SECTION_SIZE_BITS
 #error Allocator MAX_PAGE_ORDER exceeds SECTION_SIZE
 #endif
 
diff --git a/include/linux/slab.h b/include/linux/slab.h
index cda126def67a..8078eb3eb0f5 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -653,7 +653,7 @@ static inline unsigned int arch_slab_minalign(void)
  */
 #define __assume_kmalloc_alignment __assume_aligned(ARCH_KMALLOC_MINALIGN)
 #define __assume_slab_alignment __assume_aligned(ARCH_SLAB_MINALIGN)
-#define __assume_page_alignment __assume_aligned(PAGE_SIZE)
+#define __assume_page_alignment __assume_aligned(PAGE_SIZE_MIN)
 
 /*
  * Kmalloc array related definitions
@@ -664,6 +664,8 @@ static inline unsigned int arch_slab_minalign(void)
  * (PAGE_SIZE*2).  Larger requests are passed to the page allocator.
  */
 #define KMALLOC_SHIFT_HIGH	(PAGE_SHIFT + 1)
+#define KMALLOC_SHIFT_HIGH_MIN	(PAGE_SHIFT_MIN + 1)
+#define KMALLOC_SHIFT_HIGH_MAX	(PAGE_SHIFT_MAX + 1)
 #define KMALLOC_SHIFT_MAX	(MAX_PAGE_ORDER + PAGE_SHIFT)
 #ifndef KMALLOC_SHIFT_LOW
 #define KMALLOC_SHIFT_LOW	3
@@ -671,8 +673,12 @@ static inline unsigned int arch_slab_minalign(void)
 
 /* Maximum allocatable size */
 #define KMALLOC_MAX_SIZE	(1UL << KMALLOC_SHIFT_MAX)
-/* Maximum size for which we actually use a slab cache */
+/* Maximum size for which we actually use slab cache (may not be const) */
 #define KMALLOC_MAX_CACHE_SIZE	(1UL << KMALLOC_SHIFT_HIGH)
+/* Smallest maximum size for which we actually use slab cache (always const) */
+#define KMALLOC_MAX_CACHE_SIZE_MIN	(1UL << KMALLOC_SHIFT_HIGH_MIN)
+/* Largest maximum size for which we actually use slab cache (always const) */
+#define KMALLOC_MAX_CACHE_SIZE_MAX	(1UL << KMALLOC_SHIFT_HIGH_MAX)
 /* Maximum order allocatable via the slab allocator */
 #define KMALLOC_MAX_ORDER	(KMALLOC_SHIFT_MAX - PAGE_SHIFT)
 
@@ -738,7 +744,7 @@ enum kmalloc_cache_type {
 	NR_KMALLOC_TYPES
 };
 
-typedef struct kmem_cache * kmem_buckets[KMALLOC_SHIFT_HIGH + 1];
+typedef struct kmem_cache * kmem_buckets[KMALLOC_SHIFT_HIGH_MAX + 1];
 
 extern kmem_buckets kmalloc_caches[NR_KMALLOC_TYPES];
 
@@ -836,7 +842,7 @@ static __always_inline unsigned int __kmalloc_index(size_t size,
 	/* Will never be reached. Needed because the compiler may complain */
 	return -1;
 }
-static_assert(PAGE_SHIFT <= 20);
+static_assert(PAGE_SHIFT_MAX <= 20);
 #define kmalloc_index(s) __kmalloc_index(s, true)
 
 #include <linux/alloc_tag.h>
@@ -984,13 +990,15 @@ static __always_inline __alloc_size(1) void *_kmalloc_noprof(size_t size, gfp_t
 	if (__builtin_constant_p(size) && size) {
 		unsigned int index;
 
-		if (size > KMALLOC_MAX_CACHE_SIZE)
+		if (size > KMALLOC_MAX_CACHE_SIZE_MAX)
 			return __kmalloc_large_noprof(size, flags);
 
-		index = kmalloc_index(size);
-		return __kmalloc_cache_noprof(
+		if (size <= KMALLOC_MAX_CACHE_SIZE_MIN) {
+			index = kmalloc_index(size);
+			return __kmalloc_cache_noprof(
 				kmalloc_caches[kmalloc_type(flags, token)][index],
 				flags, size);
+		}
 	}
 	return __kmalloc_noprof(PASS_TOKEN_PARAMS(size, token), flags);
 }
@@ -1189,13 +1197,15 @@ static __always_inline __alloc_size(1) void *_kmalloc_node_noprof(size_t size, g
 	if (__builtin_constant_p(size) && size) {
 		unsigned int index;
 
-		if (size > KMALLOC_MAX_CACHE_SIZE)
+		if (size > KMALLOC_MAX_CACHE_SIZE_MAX)
 			return __kmalloc_large_node_noprof(size, flags, node);
 
-		index = kmalloc_index(size);
-		return __kmalloc_cache_node_noprof(
+		if (size <= KMALLOC_MAX_CACHE_SIZE_MIN) {
+			index = kmalloc_index(size);
+			return __kmalloc_cache_node_noprof(
 				kmalloc_caches[kmalloc_type(flags, token)][index],
 				flags, node, size);
+		}
 	}
 	return __kmalloc_node_noprof(PASS_KMALLOC_PARAMS(size, NULL, token), flags, node);
 }
diff --git a/include/linux/swap.h b/include/linux/swap.h
index 4f686709d71f..4d6f00c2b7ac 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -117,10 +117,16 @@
  * bootbits...
  */
 union swap_header {
-	struct {
-		char reserved[PAGE_SIZE - 10];
-		char magic[10];			/* SWAP-SPACE or SWAPSPACE2 */
-	} magic;
+	/*
+	 * Exists conceptually, but since PAGE_SIZE may not be known at compile
+	 * time, we must access through pointer arithmetic at run time.
+	 *
+	 * struct {
+	 * 	char reserved[PAGE_SIZE - 10];
+	 * 	char magic[10];			   SWAP-SPACE or SWAPSPACE2
+	 * } magic;
+	 */
+#define SWAP_HEADER_MAGIC	(PAGE_SIZE - 10)
 	struct {
 		char		bootbits[1024];	/* Space for disklabel etc. */
 		__u32		version;
@@ -185,7 +191,7 @@ struct swap_extent {
  * Max bad pages in the new format..
  */
 #define MAX_SWAP_BADPAGES \
-	((offsetof(union swap_header, magic.magic) - \
+	((SWAP_HEADER_MAGIC - \
 	  offsetof(union swap_header, info.badpages)) / sizeof(int))
 
 enum {
diff --git a/include/linux/swapops.h b/include/linux/swapops.h
index 603f9e3f909c..a5cdb7baa830 100644
--- a/include/linux/swapops.h
+++ b/include/linux/swapops.h
@@ -35,10 +35,14 @@
  */
 #ifdef MAX_PHYSMEM_BITS
 #define SWP_PFN_BITS		(MAX_PHYSMEM_BITS - PAGE_SHIFT)
+#define SWP_PFN_BITS_MAX	(MAX_PHYSMEM_BITS - PAGE_SHIFT_MIN)
 #else  /* MAX_PHYSMEM_BITS */
 #define SWP_PFN_BITS		min_t(int, \
 				      sizeof(phys_addr_t) * 8 - PAGE_SHIFT, \
 				      SWP_TYPE_SHIFT)
+#define SWP_PFN_BITS_MAX	min_t(int, \
+				      sizeof(phys_addr_t) * 8 - PAGE_SHIFT_MIN, \
+				      SWP_TYPE_SHIFT)
 #endif	/* MAX_PHYSMEM_BITS */
 #define SWP_PFN_MASK		(BIT(SWP_PFN_BITS) - 1)
 
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index d065b26a94df..5d60c15af51f 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -1169,7 +1169,7 @@ static int __init setup_transparent_hugepage(char *str)
 }
 __setup("transparent_hugepage=", setup_transparent_hugepage);
 
-static char str_dup[PAGE_SIZE] __initdata;
+static char str_dup[SZ_4K] __initdata;
 static int __init setup_thp_anon(char *str)
 {
 	char *token, *range, *policy, *subtoken;
@@ -1178,7 +1178,7 @@ static int __init setup_thp_anon(char *str)
 	int start, end, nr;
 	char *p;
 
-	if (!str || strlen(str) + 1 > PAGE_SIZE)
+	if (!str || strlen(str) + 1 > SZ_4K)
 		goto err;
 	strscpy(str_dup, str);
 
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index afbb638e7e1c..7dd9405ea50e 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2115,7 +2115,7 @@ struct obj_stock_pcp {
 	int16_t node_id;
 	int16_t nr_slab_reclaimable_b;
 	int16_t nr_slab_unreclaimable_b;
-#if PAGE_SHIFT > 16
+#if PAGE_SHIFT_MAX > 16
 	/*
 	 * On rare archs with 256KiB base page size (hexagon and powerpc 44x)
 	 * keep nr_bytes to unsigned int as uint16_t cannot represent the full
@@ -5973,7 +5973,7 @@ int __init mem_cgroup_init(void)
 	 * to work fine, we should make sure that the overfill threshold can't
 	 * exceed S32_MAX / PAGE_SIZE.
 	 */
-	BUILD_BUG_ON(MEMCG_CHARGE_BATCH > S32_MAX / PAGE_SIZE);
+	BUILD_BUG_ON(MEMCG_CHARGE_BATCH > S32_MAX / PAGE_SIZE_MAX);
 
 	memcg_struct_check();
 
diff --git a/mm/memory.c b/mm/memory.c
index 05d350efc84b..9c149ba3b492 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -6015,8 +6015,8 @@ vm_fault_t finish_fault(struct vm_fault *vmf)
 	return ret;
 }
 
-static unsigned long fault_around_pages __read_mostly =
-	65536 >> PAGE_SHIFT;
+static DEFINE_GLOBAL_PAGE_SIZE_VAR_ATTR(unsigned long, fault_around_pages,
+					__read_mostly, 65536 >> PAGE_SHIFT);
 
 #ifdef CONFIG_DEBUG_FS
 static int fault_around_bytes_get(void *data, u64 *val)
diff --git a/mm/mmap.c b/mm/mmap.c
index 7618e72766a5..39663beeb2b1 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -952,7 +952,7 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
 }
 
 /* enforced gap between the expanding stack and other mappings. */
-unsigned long stack_guard_gap = 256UL<<PAGE_SHIFT;
+DEFINE_GLOBAL_PAGE_SIZE_VAR(unsigned long, stack_guard_gap, 256UL<<PAGE_SHIFT);
 
 static int __init cmdline_parse_stack_guard_gap(char *p)
 {
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 0694ec4098f6..562b26710b9c 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -2228,7 +2228,7 @@ static int laptop_mode_handler(const struct ctl_table *table, int write,
 }
 
 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
-static const unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
+static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(unsigned long, dirty_bytes_min, 2 * PAGE_SIZE);
 
 static const struct ctl_table vm_page_writeback_sysctls[] = {
 	{
diff --git a/mm/slub.c b/mm/slub.c
index 5c33d1247060..0ab0532b9255 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -7821,7 +7821,7 @@ init_kmem_cache_node(struct kmem_cache_node *n)
 static inline int alloc_kmem_cache_stats(struct kmem_cache *s)
 {
 	BUILD_BUG_ON(PERCPU_DYNAMIC_EARLY_SIZE <
-			NR_KMALLOC_TYPES * KMALLOC_SHIFT_HIGH *
+			NR_KMALLOC_TYPES * KMALLOC_SHIFT_HIGH_MAX *
 			sizeof(struct kmem_cache_stats));
 
 	s->cpu_stats = alloc_percpu(struct kmem_cache_stats);
diff --git a/mm/sparse.h b/mm/sparse.h
index fdbc4cacf91d..ff243ea4d71c 100644
--- a/mm/sparse.h
+++ b/mm/sparse.h
@@ -25,7 +25,7 @@ static inline void sparse_init_one_section(struct mem_section *ms,
 {
 	unsigned long coded_mem_map;
 
-	BUILD_BUG_ON(SECTION_MAP_LAST_BIT > PFN_SECTION_SHIFT);
+	BUILD_BUG_ON(SECTION_MAP_LAST_BIT > PFN_SECTION_SHIFT_MIN);
 	VM_WARN_ON_ONCE(section_nr > __highest_used_section_nr);
 
 	/*
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 226230dda0aa..b46867a0c294 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -3639,7 +3639,7 @@ static unsigned long read_swap_header(struct swap_info_struct *si,
 	unsigned long swapfilepages;
 	unsigned long last_page;
 
-	if (memcmp("SWAPSPACE2", swap_header->magic.magic, 10)) {
+	if (memcmp("SWAPSPACE2", (char *)swap_header + SWAP_HEADER_MAGIC, 10)) {
 		pr_err("Unable to find swap-space signature\n");
 		return 0;
 	}
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index a4c22c569b1d..79985cfdf884 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -2655,12 +2655,12 @@ struct vmap_block {
 	spinlock_t lock;
 	struct vmap_area *va;
 	unsigned long free, dirty;
-	DECLARE_BITMAP(used_map, VMAP_BBMAP_BITS);
 	unsigned long dirty_min, dirty_max; /*< dirty range */
 	struct list_head free_list;
 	struct rcu_head rcu_head;
 	struct list_head purge;
 	unsigned int cpu;
+	unsigned long used_map[];
 };
 
 /* Queue of free and dirty vmap blocks, for allocation and flushing purposes */
@@ -2758,10 +2758,12 @@ static void *new_vmap_block(unsigned int order, gfp_t gfp_mask)
 	unsigned long vb_idx;
 	int node, err;
 	void *vaddr;
+	size_t size;
 
 	node = numa_node_id();
 
-	vb = kmalloc_node(sizeof(struct vmap_block), gfp_mask, node);
+	size = struct_size(vb, used_map, BITS_TO_LONGS(VMAP_BBMAP_BITS));
+	vb = kmalloc_node(size, gfp_mask, node);
 	if (unlikely(!vb))
 		return ERR_PTR(-ENOMEM);
 


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [RFC PATCH v2 13/13] mm: Use PAGE_SIZE_MIN/MAX where a compile-time constant is required
@ 2026-12-02  3:16   ` Eric Curtin
  0 siblings, 0 replies; 20+ messages in thread
From: Eric Curtin @ 2026-12-02  3:16 UTC (permalink / raw)
  To: linux-kernel
  Cc: Ryan Roberts, Miquel Raynal, Richard Weinberger,
	Vignesh Raghavendra, Dan Williams, Vishal Verma, Dave Jiang,
	Alison Schofield, Ira Weiny, David Hildenbrand, Liam R. Howlett,
	Vlastimil Babka, Mike Rapoport, Michal Hocko, Andrew Morton,
	Kairui Song, Barry Song, Qi Zheng, Shakeel Butt, Axel Rasmussen,
	Yuanchu Xie, Wei Xu, Baoquan He, Baolin Wang, Harry Yoo, Hao Li,
	Christoph Lameter, David Rientjes, Roman Gushchin, Chris Li,
	Kemeng Shi, Nhat Pham, Youngjun Park, Zi Yan, Nico Pache,
	Dev Jain, Lance Yang, Usama Arif, Kiryl Shutsemau,
	Johannes Weiner, Muchun Song, Lorenzo Stoakes, Suren Baghdasaryan,
	Pedro Falcato, Jann Horn, Matthew Wilcox (Oracle), Jan Kara,
	Uladzislau Rezki, linux-mtd, nvdimm, linux-mm, cgroups,
	linux-fsdevel

From: Ryan Roberts <ryan.roberts@arm.com>

With arm64 boot-time page size selection, PAGE_SIZE and PAGE_SHIFT are
not compile-time constants. Convert the mm code that needs a constant,
using the PAGE_{SIZE,SHIFT}_{MIN,MAX} limits.

- struct vmap_block: replace the used_map bitmap with a flexible array
  and size the allocation in new_vmap_block() with struct_size().
- union swap_header: drop the page-sized "magic" member and locate the
  signature at SWAP_HEADER_MAGIC, i.e. PAGE_SIZE - 10, using pointer
  arithmetic. Update MAX_SWAP_BADPAGES, read_swap_header() and mtdswap.
- BUILD_BUG_ON(), static_assert() and #if checks in memcontrol, mmzone,
  slub, sparse, leafops and ptep_lockptr() now compare against the
  appropriate limit. Add PFN_SECTION_SHIFT_MIN and SWP_PFN_BITS_MAX for
  this. struct page_frag uses PAGE_SIZE_MAX to choose its field widths.
- stack_guard_gap, fault_around_pages and dirty_bytes_min are defined
  with DEFINE_GLOBAL_PAGE_SIZE_VAR*() so that they can be initialised
  at boot.
- str_dup[] for thp_anon= is a fixed SZ_4K instead of PAGE_SIZE; a
  valid string fits easily for any page size.
- kmem_buckets is sized with KMALLOC_SHIFT_HIGH_MAX, and
  __assume_page_alignment uses PAGE_SIZE_MIN. Add KMALLOC_SHIFT_HIGH_MIN
  and _MAX, and KMALLOC_MAX_CACHE_SIZE_MIN and _MAX, for this.
- _kmalloc_noprof() and _kmalloc_node_noprof() keep the compile-time
  large-versus-cache choice for sizes outside the MIN/MAX cache size
  range. Constant sizes in between go to __kmalloc_noprof() and
  __kmalloc_node_noprof(), so the decision is made at run time.

The ND_MIN_NAMESPACE_SIZE format in nvdimm is changed to %#lx with a
cast, as it is no longer an int constant.

No functional change for compile-time page sizes.

Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
---
 drivers/mtd/mtdswap.c           |  4 ++--
 drivers/nvdimm/namespace_devs.c |  4 ++--
 include/linux/leafops.h         |  2 +-
 include/linux/mm.h              |  2 +-
 include/linux/mm_types_task.h   |  2 +-
 include/linux/mmzone.h          |  3 ++-
 include/linux/slab.h            | 30 ++++++++++++++++++++----------
 include/linux/swap.h            | 16 +++++++++++-----
 include/linux/swapops.h         |  4 ++++
 mm/huge_memory.c                |  4 ++--
 mm/memcontrol.c                 |  4 ++--
 mm/memory.c                     |  4 ++--
 mm/mmap.c                       |  2 +-
 mm/page-writeback.c             |  2 +-
 mm/slub.c                       |  2 +-
 mm/sparse.h                     |  2 +-
 mm/swapfile.c                   |  2 +-
 mm/vmalloc.c                    |  6 ++++--
 18 files changed, 59 insertions(+), 36 deletions(-)

diff --git a/drivers/mtd/mtdswap.c b/drivers/mtd/mtdswap.c
index 92e38ece8931..7b20e49d5a25 100644
--- a/drivers/mtd/mtdswap.c
+++ b/drivers/mtd/mtdswap.c
@@ -1063,13 +1063,13 @@ static int mtdswap_auto_header(struct mtdswap_dev *d, char *buf)
 {
 	union swap_header *hd = (union swap_header *)(buf);
 
-	memset(buf, 0, PAGE_SIZE - 10);
+	memset(buf, 0, SWAP_HEADER_MAGIC);
 
 	hd->info.version = 1;
 	hd->info.last_page = d->mbd_dev->size - 1;
 	hd->info.nr_badpages = 0;
 
-	memcpy(buf + PAGE_SIZE - 10, "SWAPSPACE2", 10);
+	memcpy(buf + SWAP_HEADER_MAGIC, "SWAPSPACE2", 10);
 
 	return 0;
 }
diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
index 3aa0a9026efa..10d5ce31eb4f 100644
--- a/drivers/nvdimm/namespace_devs.c
+++ b/drivers/nvdimm/namespace_devs.c
@@ -1478,8 +1478,8 @@ struct nd_namespace_common *nvdimm_namespace_common_probe(struct device *dev)
 
 	size = nvdimm_namespace_capacity(ndns);
 	if (size < ND_MIN_NAMESPACE_SIZE) {
-		dev_dbg(&ndns->dev, "%pa, too small must be at least %#x\n",
-				&size, ND_MIN_NAMESPACE_SIZE);
+		dev_dbg(&ndns->dev, "%pa, too small must be at least %#lx\n",
+				&size, (unsigned long)ND_MIN_NAMESPACE_SIZE);
 		return ERR_PTR(-ENODEV);
 	}
 
diff --git a/include/linux/leafops.h b/include/linux/leafops.h
index 4c1476ae3234..414da42ffc4c 100644
--- a/include/linux/leafops.h
+++ b/include/linux/leafops.h
@@ -355,7 +355,7 @@ static inline pte_marker softleaf_to_marker(softleaf_t entry)
 static inline bool softleaf_has_pfn(softleaf_t entry)
 {
 	/* Make sure the swp offset can always store the needed fields. */
-	BUILD_BUG_ON(SWP_TYPE_SHIFT < SWP_PFN_BITS);
+	BUILD_BUG_ON(SWP_TYPE_SHIFT < SWP_PFN_BITS_MAX);
 
 	if (softleaf_is_migration(entry))
 		return true;
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 14a35440c806..caca5fcff031 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -4070,7 +4070,7 @@ static inline spinlock_t *pte_lockptr(struct mm_struct *mm, pmd_t *pmd)
 static inline spinlock_t *ptep_lockptr(struct mm_struct *mm, pte_t *pte)
 {
 	BUILD_BUG_ON(IS_ENABLED(CONFIG_HIGHPTE));
-	BUILD_BUG_ON(MAX_PTRS_PER_PTE * sizeof(pte_t) > PAGE_SIZE);
+	BUILD_BUG_ON(MAX_PTRS_PER_PTE * sizeof(pte_t) > PAGE_SIZE_MAX);
 	return ptlock_ptr(virt_to_ptdesc(pte));
 }
 
diff --git a/include/linux/mm_types_task.h b/include/linux/mm_types_task.h
index 2f760f472e19..2fe24a31e24d 100644
--- a/include/linux/mm_types_task.h
+++ b/include/linux/mm_types_task.h
@@ -35,7 +35,7 @@ struct page;
 
 struct page_frag {
 	struct page *page;
-#if (BITS_PER_LONG > 32) || (PAGE_SIZE >= 65536)
+#if (BITS_PER_LONG > 32) || (PAGE_SIZE_MAX >= 65536)
 	__u32 offset;
 	__u32 size;
 #else
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 72ffb2959c4f..bf317cc1a83a 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -1990,6 +1990,7 @@ static inline bool movable_only_nodes(nodemask_t *nodes)
  */
 #define PA_SECTION_SHIFT	(SECTION_SIZE_BITS)
 #define PFN_SECTION_SHIFT	(SECTION_SIZE_BITS - PAGE_SHIFT)
+#define PFN_SECTION_SHIFT_MIN	(SECTION_SIZE_BITS - PAGE_SHIFT_MAX)
 
 #define NR_MEM_SECTIONS		(1UL << SECTIONS_SHIFT)
 
@@ -1999,7 +2000,7 @@ static inline bool movable_only_nodes(nodemask_t *nodes)
 #define SECTION_BLOCKFLAGS_BITS \
 	((1UL << (PFN_SECTION_SHIFT - pageblock_order)) * NR_PAGEBLOCK_BITS)
 
-#if (MAX_PAGE_ORDER + PAGE_SHIFT) > SECTION_SIZE_BITS
+#if (MAX_PAGE_ORDER + PAGE_SHIFT_MAX) > SECTION_SIZE_BITS
 #error Allocator MAX_PAGE_ORDER exceeds SECTION_SIZE
 #endif
 
diff --git a/include/linux/slab.h b/include/linux/slab.h
index cda126def67a..8078eb3eb0f5 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -653,7 +653,7 @@ static inline unsigned int arch_slab_minalign(void)
  */
 #define __assume_kmalloc_alignment __assume_aligned(ARCH_KMALLOC_MINALIGN)
 #define __assume_slab_alignment __assume_aligned(ARCH_SLAB_MINALIGN)
-#define __assume_page_alignment __assume_aligned(PAGE_SIZE)
+#define __assume_page_alignment __assume_aligned(PAGE_SIZE_MIN)
 
 /*
  * Kmalloc array related definitions
@@ -664,6 +664,8 @@ static inline unsigned int arch_slab_minalign(void)
  * (PAGE_SIZE*2).  Larger requests are passed to the page allocator.
  */
 #define KMALLOC_SHIFT_HIGH	(PAGE_SHIFT + 1)
+#define KMALLOC_SHIFT_HIGH_MIN	(PAGE_SHIFT_MIN + 1)
+#define KMALLOC_SHIFT_HIGH_MAX	(PAGE_SHIFT_MAX + 1)
 #define KMALLOC_SHIFT_MAX	(MAX_PAGE_ORDER + PAGE_SHIFT)
 #ifndef KMALLOC_SHIFT_LOW
 #define KMALLOC_SHIFT_LOW	3
@@ -671,8 +673,12 @@ static inline unsigned int arch_slab_minalign(void)
 
 /* Maximum allocatable size */
 #define KMALLOC_MAX_SIZE	(1UL << KMALLOC_SHIFT_MAX)
-/* Maximum size for which we actually use a slab cache */
+/* Maximum size for which we actually use slab cache (may not be const) */
 #define KMALLOC_MAX_CACHE_SIZE	(1UL << KMALLOC_SHIFT_HIGH)
+/* Smallest maximum size for which we actually use slab cache (always const) */
+#define KMALLOC_MAX_CACHE_SIZE_MIN	(1UL << KMALLOC_SHIFT_HIGH_MIN)
+/* Largest maximum size for which we actually use slab cache (always const) */
+#define KMALLOC_MAX_CACHE_SIZE_MAX	(1UL << KMALLOC_SHIFT_HIGH_MAX)
 /* Maximum order allocatable via the slab allocator */
 #define KMALLOC_MAX_ORDER	(KMALLOC_SHIFT_MAX - PAGE_SHIFT)
 
@@ -738,7 +744,7 @@ enum kmalloc_cache_type {
 	NR_KMALLOC_TYPES
 };
 
-typedef struct kmem_cache * kmem_buckets[KMALLOC_SHIFT_HIGH + 1];
+typedef struct kmem_cache * kmem_buckets[KMALLOC_SHIFT_HIGH_MAX + 1];
 
 extern kmem_buckets kmalloc_caches[NR_KMALLOC_TYPES];
 
@@ -836,7 +842,7 @@ static __always_inline unsigned int __kmalloc_index(size_t size,
 	/* Will never be reached. Needed because the compiler may complain */
 	return -1;
 }
-static_assert(PAGE_SHIFT <= 20);
+static_assert(PAGE_SHIFT_MAX <= 20);
 #define kmalloc_index(s) __kmalloc_index(s, true)
 
 #include <linux/alloc_tag.h>
@@ -984,13 +990,15 @@ static __always_inline __alloc_size(1) void *_kmalloc_noprof(size_t size, gfp_t
 	if (__builtin_constant_p(size) && size) {
 		unsigned int index;
 
-		if (size > KMALLOC_MAX_CACHE_SIZE)
+		if (size > KMALLOC_MAX_CACHE_SIZE_MAX)
 			return __kmalloc_large_noprof(size, flags);
 
-		index = kmalloc_index(size);
-		return __kmalloc_cache_noprof(
+		if (size <= KMALLOC_MAX_CACHE_SIZE_MIN) {
+			index = kmalloc_index(size);
+			return __kmalloc_cache_noprof(
 				kmalloc_caches[kmalloc_type(flags, token)][index],
 				flags, size);
+		}
 	}
 	return __kmalloc_noprof(PASS_TOKEN_PARAMS(size, token), flags);
 }
@@ -1189,13 +1197,15 @@ static __always_inline __alloc_size(1) void *_kmalloc_node_noprof(size_t size, g
 	if (__builtin_constant_p(size) && size) {
 		unsigned int index;
 
-		if (size > KMALLOC_MAX_CACHE_SIZE)
+		if (size > KMALLOC_MAX_CACHE_SIZE_MAX)
 			return __kmalloc_large_node_noprof(size, flags, node);
 
-		index = kmalloc_index(size);
-		return __kmalloc_cache_node_noprof(
+		if (size <= KMALLOC_MAX_CACHE_SIZE_MIN) {
+			index = kmalloc_index(size);
+			return __kmalloc_cache_node_noprof(
 				kmalloc_caches[kmalloc_type(flags, token)][index],
 				flags, node, size);
+		}
 	}
 	return __kmalloc_node_noprof(PASS_KMALLOC_PARAMS(size, NULL, token), flags, node);
 }
diff --git a/include/linux/swap.h b/include/linux/swap.h
index 4f686709d71f..4d6f00c2b7ac 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -117,10 +117,16 @@
  * bootbits...
  */
 union swap_header {
-	struct {
-		char reserved[PAGE_SIZE - 10];
-		char magic[10];			/* SWAP-SPACE or SWAPSPACE2 */
-	} magic;
+	/*
+	 * Exists conceptually, but since PAGE_SIZE may not be known at compile
+	 * time, we must access through pointer arithmetic at run time.
+	 *
+	 * struct {
+	 * 	char reserved[PAGE_SIZE - 10];
+	 * 	char magic[10];			   SWAP-SPACE or SWAPSPACE2
+	 * } magic;
+	 */
+#define SWAP_HEADER_MAGIC	(PAGE_SIZE - 10)
 	struct {
 		char		bootbits[1024];	/* Space for disklabel etc. */
 		__u32		version;
@@ -185,7 +191,7 @@ struct swap_extent {
  * Max bad pages in the new format..
  */
 #define MAX_SWAP_BADPAGES \
-	((offsetof(union swap_header, magic.magic) - \
+	((SWAP_HEADER_MAGIC - \
 	  offsetof(union swap_header, info.badpages)) / sizeof(int))
 
 enum {
diff --git a/include/linux/swapops.h b/include/linux/swapops.h
index 603f9e3f909c..a5cdb7baa830 100644
--- a/include/linux/swapops.h
+++ b/include/linux/swapops.h
@@ -35,10 +35,14 @@
  */
 #ifdef MAX_PHYSMEM_BITS
 #define SWP_PFN_BITS		(MAX_PHYSMEM_BITS - PAGE_SHIFT)
+#define SWP_PFN_BITS_MAX	(MAX_PHYSMEM_BITS - PAGE_SHIFT_MIN)
 #else  /* MAX_PHYSMEM_BITS */
 #define SWP_PFN_BITS		min_t(int, \
 				      sizeof(phys_addr_t) * 8 - PAGE_SHIFT, \
 				      SWP_TYPE_SHIFT)
+#define SWP_PFN_BITS_MAX	min_t(int, \
+				      sizeof(phys_addr_t) * 8 - PAGE_SHIFT_MIN, \
+				      SWP_TYPE_SHIFT)
 #endif	/* MAX_PHYSMEM_BITS */
 #define SWP_PFN_MASK		(BIT(SWP_PFN_BITS) - 1)
 
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index d065b26a94df..5d60c15af51f 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -1169,7 +1169,7 @@ static int __init setup_transparent_hugepage(char *str)
 }
 __setup("transparent_hugepage=", setup_transparent_hugepage);
 
-static char str_dup[PAGE_SIZE] __initdata;
+static char str_dup[SZ_4K] __initdata;
 static int __init setup_thp_anon(char *str)
 {
 	char *token, *range, *policy, *subtoken;
@@ -1178,7 +1178,7 @@ static int __init setup_thp_anon(char *str)
 	int start, end, nr;
 	char *p;
 
-	if (!str || strlen(str) + 1 > PAGE_SIZE)
+	if (!str || strlen(str) + 1 > SZ_4K)
 		goto err;
 	strscpy(str_dup, str);
 
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index afbb638e7e1c..7dd9405ea50e 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2115,7 +2115,7 @@ struct obj_stock_pcp {
 	int16_t node_id;
 	int16_t nr_slab_reclaimable_b;
 	int16_t nr_slab_unreclaimable_b;
-#if PAGE_SHIFT > 16
+#if PAGE_SHIFT_MAX > 16
 	/*
 	 * On rare archs with 256KiB base page size (hexagon and powerpc 44x)
 	 * keep nr_bytes to unsigned int as uint16_t cannot represent the full
@@ -5973,7 +5973,7 @@ int __init mem_cgroup_init(void)
 	 * to work fine, we should make sure that the overfill threshold can't
 	 * exceed S32_MAX / PAGE_SIZE.
 	 */
-	BUILD_BUG_ON(MEMCG_CHARGE_BATCH > S32_MAX / PAGE_SIZE);
+	BUILD_BUG_ON(MEMCG_CHARGE_BATCH > S32_MAX / PAGE_SIZE_MAX);
 
 	memcg_struct_check();
 
diff --git a/mm/memory.c b/mm/memory.c
index 05d350efc84b..9c149ba3b492 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -6015,8 +6015,8 @@ vm_fault_t finish_fault(struct vm_fault *vmf)
 	return ret;
 }
 
-static unsigned long fault_around_pages __read_mostly =
-	65536 >> PAGE_SHIFT;
+static DEFINE_GLOBAL_PAGE_SIZE_VAR_ATTR(unsigned long, fault_around_pages,
+					__read_mostly, 65536 >> PAGE_SHIFT);
 
 #ifdef CONFIG_DEBUG_FS
 static int fault_around_bytes_get(void *data, u64 *val)
diff --git a/mm/mmap.c b/mm/mmap.c
index 7618e72766a5..39663beeb2b1 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -952,7 +952,7 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
 }
 
 /* enforced gap between the expanding stack and other mappings. */
-unsigned long stack_guard_gap = 256UL<<PAGE_SHIFT;
+DEFINE_GLOBAL_PAGE_SIZE_VAR(unsigned long, stack_guard_gap, 256UL<<PAGE_SHIFT);
 
 static int __init cmdline_parse_stack_guard_gap(char *p)
 {
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 0694ec4098f6..562b26710b9c 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -2228,7 +2228,7 @@ static int laptop_mode_handler(const struct ctl_table *table, int write,
 }
 
 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
-static const unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
+static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(unsigned long, dirty_bytes_min, 2 * PAGE_SIZE);
 
 static const struct ctl_table vm_page_writeback_sysctls[] = {
 	{
diff --git a/mm/slub.c b/mm/slub.c
index 5c33d1247060..0ab0532b9255 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -7821,7 +7821,7 @@ init_kmem_cache_node(struct kmem_cache_node *n)
 static inline int alloc_kmem_cache_stats(struct kmem_cache *s)
 {
 	BUILD_BUG_ON(PERCPU_DYNAMIC_EARLY_SIZE <
-			NR_KMALLOC_TYPES * KMALLOC_SHIFT_HIGH *
+			NR_KMALLOC_TYPES * KMALLOC_SHIFT_HIGH_MAX *
 			sizeof(struct kmem_cache_stats));
 
 	s->cpu_stats = alloc_percpu(struct kmem_cache_stats);
diff --git a/mm/sparse.h b/mm/sparse.h
index fdbc4cacf91d..ff243ea4d71c 100644
--- a/mm/sparse.h
+++ b/mm/sparse.h
@@ -25,7 +25,7 @@ static inline void sparse_init_one_section(struct mem_section *ms,
 {
 	unsigned long coded_mem_map;
 
-	BUILD_BUG_ON(SECTION_MAP_LAST_BIT > PFN_SECTION_SHIFT);
+	BUILD_BUG_ON(SECTION_MAP_LAST_BIT > PFN_SECTION_SHIFT_MIN);
 	VM_WARN_ON_ONCE(section_nr > __highest_used_section_nr);
 
 	/*
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 226230dda0aa..b46867a0c294 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -3639,7 +3639,7 @@ static unsigned long read_swap_header(struct swap_info_struct *si,
 	unsigned long swapfilepages;
 	unsigned long last_page;
 
-	if (memcmp("SWAPSPACE2", swap_header->magic.magic, 10)) {
+	if (memcmp("SWAPSPACE2", (char *)swap_header + SWAP_HEADER_MAGIC, 10)) {
 		pr_err("Unable to find swap-space signature\n");
 		return 0;
 	}
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index a4c22c569b1d..79985cfdf884 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -2655,12 +2655,12 @@ struct vmap_block {
 	spinlock_t lock;
 	struct vmap_area *va;
 	unsigned long free, dirty;
-	DECLARE_BITMAP(used_map, VMAP_BBMAP_BITS);
 	unsigned long dirty_min, dirty_max; /*< dirty range */
 	struct list_head free_list;
 	struct rcu_head rcu_head;
 	struct list_head purge;
 	unsigned int cpu;
+	unsigned long used_map[];
 };
 
 /* Queue of free and dirty vmap blocks, for allocation and flushing purposes */
@@ -2758,10 +2758,12 @@ static void *new_vmap_block(unsigned int order, gfp_t gfp_mask)
 	unsigned long vb_idx;
 	int node, err;
 	void *vaddr;
+	size_t size;
 
 	node = numa_node_id();
 
-	vb = kmalloc_node(sizeof(struct vmap_block), gfp_mask, node);
+	size = struct_size(vb, used_map, BITS_TO_LONGS(VMAP_BBMAP_BITS));
+	vb = kmalloc_node(size, gfp_mask, node);
 	if (unlikely(!vb))
 		return ERR_PTR(-ENOMEM);
 

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [RFC PATCH v2 12/13] ata: sata_sil24: Use flexible arrays for the command block SGEs
  2026-12-02  3:16 ` [RFC PATCH v2 12/13] ata: sata_sil24: Use flexible arrays for the command block SGEs Eric Curtin
@ 2026-12-02  7:10   ` Damien Le Moal
  0 siblings, 0 replies; 20+ messages in thread
From: Damien Le Moal @ 2026-12-02  7:10 UTC (permalink / raw)
  To: Eric Curtin, linux-kernel; +Cc: Ryan Roberts, Niklas Cassel, linux-ide

On 12/2/26 12:16, Eric Curtin wrote:
> From: Ryan Roberts <ryan.roberts@arm.com>
> 
> SIL24_MAX_SGE is derived from PAGE_SIZE, so with boot-time page size
> selection it is not a compile-time constant and cannot size the sge[]
> arrays in struct sil24_ata_block and struct sil24_atapi_block.
> 
> Make sge[] a flexible array in both and move SIL24_MAX_SGT and
> SIL24_MAX_SGE out of the enum into macros, since they are no longer
> constant. Add SIL24_*_BLOCK_SIZE macros that compute the block sizes
> with struct_size_t(), and add sil24_cmd_blk() to index the command block
> array, because sizeof(union sil24_cmd_block) is no longer the stride.
> Use SIL24_CMD_BLOCK_SIZE for the block stride in sil24_qc_issue() and
> for the allocation size in sil24_port_start().
> 
> Define sil24_sht with DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST() so that its
> sg_tablesize is initialised at boot.
> 
> The link-time check that union sil24_cmd_block is exactly PAGE_SIZE
> cannot work for a run-time value, so replace it with WARN_ON_ONCE()
> checks in sil24_init_one() that fail the probe with -EINVAL.
> 
> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
> Signed-off-by: Eric Curtin <eric.curtin@docker.com>
> ---
>  drivers/ata/sata_sil24.c | 70 ++++++++++++++++++++++++----------------
>  1 file changed, 43 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c
> index 7acd55b17b18..ec420923d866 100644
> --- a/drivers/ata/sata_sil24.c
> +++ b/drivers/ata/sata_sil24.c
> @@ -42,26 +42,25 @@ struct sil24_sge {
>  	__le32	flags;
>  };
>  
> +/*
> + * sil24 fetches in chunks of 64bytes.  The first block
> + * contains the PRB and two SGEs.  From the second block, it's
> + * consisted of four SGEs and called SGT.  Calculate the
> + * number of SGTs that fit into one page.
> + */
> +#define SIL24_PRB_SZ	(sizeof(struct sil24_prb) + 2 * sizeof(struct sil24_sge))
> +#define SIL24_MAX_SGT	((PAGE_SIZE - SIL24_PRB_SZ) / (4 * sizeof(struct sil24_sge)))
> +
> +/*
> + * This will give us one unused SGEs for ATA.  This extra SGE
> + * will be used to store CDB for ATAPI devices.
> + */
> +#define SIL24_MAX_SGE	(4 * SIL24_MAX_SGT + 1)
>  
>  enum {
>  	SIL24_HOST_BAR		= 0,
>  	SIL24_PORT_BAR		= 2,
>  
> -	/* sil24 fetches in chunks of 64bytes.  The first block
> -	 * contains the PRB and two SGEs.  From the second block, it's
> -	 * consisted of four SGEs and called SGT.  Calculate the
> -	 * number of SGTs that fit into one page.
> -	 */
> -	SIL24_PRB_SZ		= sizeof(struct sil24_prb)
> -				  + 2 * sizeof(struct sil24_sge),
> -	SIL24_MAX_SGT		= (PAGE_SIZE - SIL24_PRB_SZ)
> -				  / (4 * sizeof(struct sil24_sge)),
> -
> -	/* This will give us one unused SGEs for ATA.  This extra SGE
> -	 * will be used to store CDB for ATAPI devices.
> -	 */
> -	SIL24_MAX_SGE		= 4 * SIL24_MAX_SGT + 1,
> -
>  	/*
>  	 * Global controller registers (128 bytes @ BAR0)
>  	 */
> @@ -244,13 +243,13 @@ enum {
>  
>  struct sil24_ata_block {
>  	struct sil24_prb prb;
> -	struct sil24_sge sge[SIL24_MAX_SGE];
> +	struct sil24_sge sge[];

This needs a __counted_by() annotation.

>  };
>  
>  struct sil24_atapi_block {
>  	struct sil24_prb prb;
>  	u8 cdb[16];
> -	struct sil24_sge sge[SIL24_MAX_SGE];
> +	struct sil24_sge sge[];

Here too.

>  };
>  
>  union sil24_cmd_block {
> @@ -258,6 +257,10 @@ union sil24_cmd_block {
>  	struct sil24_atapi_block atapi;
>  };
>  
> +#define SIL24_ATA_BLOCK_SIZE	struct_size_t(struct sil24_ata_block, sge, SIL24_MAX_SGE)
> +#define SIL24_ATAPI_BLOCK_SIZE	struct_size_t(struct sil24_atapi_block, sge, SIL24_MAX_SGE)
> +#define SIL24_CMD_BLOCK_SIZE	max(SIL24_ATA_BLOCK_SIZE, SIL24_ATAPI_BLOCK_SIZE)
> +
>  static const struct sil24_cerr_info {
>  	unsigned int err_mask, action;
>  	const char *desc;
> @@ -322,6 +325,13 @@ struct sil24_port_priv {
>  	int do_port_rst;
>  };
>  
> +/* sizeof(union sil24_cmd_block) is not the stride between blocks */
> +static inline union sil24_cmd_block *
> +sil24_cmd_blk(struct sil24_port_priv *pp, unsigned int tag)
> +{
> +	return (void *)((u8 *)pp->cmd_block + tag * SIL24_CMD_BLOCK_SIZE);
> +}
> +
>  static void sil24_dev_config(struct ata_device *dev);
>  static int sil24_scr_read(struct ata_link *link, unsigned sc_reg, u32 *val);
>  static int sil24_scr_write(struct ata_link *link, unsigned sc_reg, u32 val);
> @@ -372,7 +382,7 @@ static struct pci_driver sil24_pci_driver = {
>  #endif
>  };
>  
> -static const struct scsi_host_template sil24_sht = {
> +static DEFINE_GLOBAL_PAGE_SIZE_VAR_CONST(struct scsi_host_template, sil24_sht, {

I am not familiar with this and a grep in 7.4-rc5 gives nothing about it. What
is this? Is it something new in next?

>  	__ATA_BASE_SHT(DRV_NAME),
>  	.can_queue		= SIL24_MAX_CMDS,
>  	.sg_tablesize		= SIL24_MAX_SGE,
> @@ -380,7 +390,7 @@ static const struct scsi_host_template sil24_sht = {
>  	.sdev_groups		= ata_ncq_sdev_groups,
>  	.change_queue_depth	= ata_scsi_change_queue_depth,
>  	.sdev_configure		= ata_scsi_sdev_configure
> -};
> +});
>  
>  static struct ata_port_operations sil24_ops = {
>  	.inherits		= &sata_pmp_port_ops,
> @@ -599,7 +609,7 @@ static int sil24_exec_polled_cmd(struct ata_port *ap, int pmp,
>  {
>  	void __iomem *port = sil24_port_base(ap);
>  	struct sil24_port_priv *pp = ap->private_data;
> -	struct sil24_prb *prb = &pp->cmd_block[0].ata.prb;
> +	struct sil24_prb *prb = &sil24_cmd_blk(pp, 0)->ata.prb;
>  	dma_addr_t paddr = pp->cmd_block_dma;
>  	u32 irq_enabled, irq_mask, irq_stat;
>  	int rc;
> @@ -841,7 +851,7 @@ static enum ata_completion_errors sil24_qc_prep(struct ata_queued_cmd *qc)
>  	struct sil24_sge *sge;
>  	u16 ctrl = 0;
>  
> -	cb = &pp->cmd_block[sil24_tag(qc->hw_tag)];
> +	cb = sil24_cmd_blk(pp, sil24_tag(qc->hw_tag));
>  
>  	if (!ata_is_atapi(qc->tf.protocol)) {
>  		prb = &cb->ata.prb;
> @@ -889,7 +899,7 @@ static unsigned int sil24_qc_issue(struct ata_queued_cmd *qc)
>  	dma_addr_t paddr;
>  	void __iomem *activate;
>  
> -	paddr = pp->cmd_block_dma + tag * sizeof(*pp->cmd_block);
> +	paddr = pp->cmd_block_dma + tag * SIL24_CMD_BLOCK_SIZE;
>  	activate = port + PORT_CMD_ACTIVATE + tag * 8;
>  
>  	/*
> @@ -1196,7 +1206,7 @@ static int sil24_port_start(struct ata_port *ap)
>  	struct device *dev = ap->host->dev;
>  	struct sil24_port_priv *pp;
>  	union sil24_cmd_block *cb;
> -	size_t cb_size = sizeof(*cb) * SIL24_MAX_CMDS;
> +	size_t cb_size = SIL24_CMD_BLOCK_SIZE * SIL24_MAX_CMDS;
>  	dma_addr_t cb_dma;
>  
>  	pp = devm_kzalloc_obj(dev, *pp);
> @@ -1261,7 +1271,6 @@ static void sil24_init_controller(struct ata_host *host)
>  
>  static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
>  {
> -	extern int __MARKER__sil24_cmd_block_is_sized_wrongly;
>  	struct ata_port_info pi = sil24_port_info[ent->driver_data];
>  	const struct ata_port_info *ppi[] = { &pi, NULL };
>  	void __iomem * const *iomap;
> @@ -1269,9 +1278,16 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
>  	int rc;
>  	u32 tmp;
>  
> -	/* cause link error if sil24_cmd_block is sized wrongly */
> -	if (sizeof(union sil24_cmd_block) != PAGE_SIZE)
> -		__MARKER__sil24_cmd_block_is_sized_wrongly = 1;
> +	/*
> +	 * union sil24_cmd_block must be PAGE_SIZE once taking into account the
> +	 * 'sge' flexible array members in struct sil24_atapi_block and struct
> +	 * sil24_ata_block.
> +	 */
> +	if (WARN_ON_ONCE(SIL24_ATAPI_BLOCK_SIZE != PAGE_SIZE))
> +		return -EINVAL;
> +	if (WARN_ON_ONCE(SIL24_ATA_BLOCK_SIZE !=
> +			 PAGE_SIZE - sizeof_field(struct sil24_atapi_block, cdb)))
> +		return -EINVAL;
>  
>  	ata_print_version_once(&pdev->dev, DRV_VERSION);
>  


-- 
Damien Le Moal
Western Digital Research

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC PATCH v2 02/13] mtd: mtdswap: Initialise mtdswap_ops with a page size variable
  2026-12-02  3:16   ` Eric Curtin
@ 2026-12-02 11:25     ` Miquel Raynal
  -1 siblings, 0 replies; 20+ messages in thread
From: Miquel Raynal @ 2026-12-02 11:25 UTC (permalink / raw)
  To: Eric Curtin
  Cc: linux-kernel, Eric Curtin, Richard Weinberger,
	Vignesh Raghavendra, linux-mtd

On 02/12/2026 at 03:16:23 GMT, Eric Curtin <ericcurtin17@gmail.com> wrote:

> From: Eric Curtin <eric.curtin@docker.com>
>
> With arm64 boot-time page size selection PAGE_SIZE is not a
> compile-time constant, so it cannot be used in the static initialiser
> of mtdswap_ops, whose .blksize is PAGE_SIZE.
>
> Define the structure with DEFINE_GLOBAL_PAGE_SIZE_VAR(), which
> initialises it at boot when the page size is not fixed and is an
> ordinary static initialiser otherwise.
>
> No functional change for compile-time page sizes.
>
> Signed-off-by: Eric Curtin <eric.curtin@docker.com>

Acked-by: Miquel Raynal <miquel.raynal@bootlin.com>

I believe this patch has very little chance to conflict with the MTD
tree, so it can be carried through the mm tree once the series will be
applied.

Thanks,
Miquèl

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC PATCH v2 02/13] mtd: mtdswap: Initialise mtdswap_ops with a page size variable
@ 2026-12-02 11:25     ` Miquel Raynal
  0 siblings, 0 replies; 20+ messages in thread
From: Miquel Raynal @ 2026-12-02 11:25 UTC (permalink / raw)
  To: Eric Curtin
  Cc: linux-kernel, Eric Curtin, Richard Weinberger,
	Vignesh Raghavendra, linux-mtd

On 02/12/2026 at 03:16:23 GMT, Eric Curtin <ericcurtin17@gmail.com> wrote:

> From: Eric Curtin <eric.curtin@docker.com>
>
> With arm64 boot-time page size selection PAGE_SIZE is not a
> compile-time constant, so it cannot be used in the static initialiser
> of mtdswap_ops, whose .blksize is PAGE_SIZE.
>
> Define the structure with DEFINE_GLOBAL_PAGE_SIZE_VAR(), which
> initialises it at boot when the page size is not fixed and is an
> ordinary static initialiser otherwise.
>
> No functional change for compile-time page sizes.
>
> Signed-off-by: Eric Curtin <eric.curtin@docker.com>

Acked-by: Miquel Raynal <miquel.raynal@bootlin.com>

I believe this patch has very little chance to conflict with the MTD
tree, so it can be carried through the mm tree once the series will be
applied.

Thanks,
Miquèl

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2026-12-02 11:25 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02  3:16 [RFC PATCH v2 00/13] block/storage: Prepare for boot-time page size selection on arm64 Eric Curtin
2026-12-02  3:16 ` Eric Curtin
2026-12-02  3:16 ` [RFC PATCH v2 01/13] scsi: core: Add dma_boundary_page for page-size DMA boundaries Eric Curtin
2026-12-02  3:16 ` [RFC PATCH v2 02/13] mtd: mtdswap: Initialise mtdswap_ops with a page size variable Eric Curtin
2026-12-02  3:16   ` Eric Curtin
2026-12-02 11:25   ` Miquel Raynal
2026-12-02 11:25     ` Miquel Raynal
2026-12-02  3:16 ` [RFC PATCH v2 03/13] mmc: mmc_test: Allocate the scratch buffer with the test buffer Eric Curtin
2026-12-02  3:16 ` [RFC PATCH v2 04/13] md: Remove compile-time PAGE_SIZE use in md, dm and bcache Eric Curtin
2026-12-02  3:16 ` [RFC PATCH v2 05/13] zram: Remove PAGE_SIZE use in preprocessor conditionals Eric Curtin
2026-12-02  3:16 ` [RFC PATCH v2 06/13] xen/blkback: Size indirect_pages for the largest page size Eric Curtin
2026-12-02  3:16 ` [RFC PATCH v2 07/13] null_blk: Size the nullb_page bitmap for PAGE_SIZE_MAX Eric Curtin
2026-12-02  3:16 ` [RFC PATCH v2 08/13] drbd: Use PAGE_SHIFT_MIN in preprocessor checks Eric Curtin
2026-12-02  3:16 ` [RFC PATCH v2 09/13] nvme: Check the DSM range buffer against PAGE_SIZE_MIN Eric Curtin
2026-12-02  3:16 ` [RFC PATCH v2 10/13] dm: Initialise swap_bios from the runtime PAGE_SIZE Eric Curtin
2026-12-02  3:16 ` [RFC PATCH v2 11/13] virtio: Handle boot-time PAGE_SIZE in balloon, blk and 9p transport Eric Curtin
2026-12-02  3:16 ` [RFC PATCH v2 12/13] ata: sata_sil24: Use flexible arrays for the command block SGEs Eric Curtin
2026-12-02  7:10   ` Damien Le Moal
2026-12-02  3:16 ` [RFC PATCH v2 13/13] mm: Use PAGE_SIZE_MIN/MAX where a compile-time constant is required Eric Curtin
2026-12-02  3:16   ` Eric Curtin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.