* [RFC PATCH v2 00/13] block/storage: Prepare for boot-time page size selection on arm64 @ 2026-12-02 3:16 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 0 siblings, 1 reply; 3+ 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] 3+ messages in thread
* [RFC PATCH v2 12/13] ata: sata_sil24: Use flexible arrays for the command block SGEs 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 7:10 ` Damien Le Moal 0 siblings, 1 reply; 3+ 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] 3+ 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; 3+ 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] 3+ messages in thread
end of thread, other threads:[~2026-12-02 7:10 UTC | newest] Thread overview: 3+ 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 ` [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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox