block/storage: Prepare for boot-time page size selection on arm64
Subsystems (41)
v2 cover block/storage: Prepare for boot-time page size selection on arm64
From: Eric Curtin <[email protected]>
This series is part of the boot-time page size selection work for arm64, posted as RFC [1]. With CONFIG_ARM64_BOOT_TIME_PAGE_SIZE=y, PAGE_SIZE, PAGE_SHIFT and PAGE_MASK are variables chosen at boot with arm64.pagesize=, so code that needs a compile-time constant (array sizes, struct layouts, static initialisers, BUILD_BUG_ON(), case labels, #if) has to use the new PAGE_SIZE_MIN/PAGE_SIZE_MAX limits or a run-time value instead. For fixed page sizes both limits equal PAGE_SIZE, so behaviour should not change.
The patches here convert 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/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
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
RFC PATCH v2 1/13 scsi: core: Add dma_boundary_page for page-size DMA boundaries
From: Eric Curtin <[email protected]>
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.
--- 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(-)
drivers/scsi/aha152x.c +1 -1
@@ -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), };
drivers/scsi/cxgbi/cxgb3i/cxgb3i.c +1 -1
@@ -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),
drivers/scsi/cxgbi/cxgb4i/cxgb4i.c +1 -1
@@ -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),
drivers/scsi/dc395x.c +1 -1
@@ -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, };
drivers/scsi/dmx3191d.c +1 -1
@@ -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), };
drivers/scsi/fdomain.c +1 -1
@@ -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), };
drivers/scsi/g_NCR5380.c +1 -1
@@ -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, };
drivers/scsi/hosts.c +3 -1
@@ -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 ;
drivers/scsi/iscsi_tcp.c +1 -1
@@ -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,
drivers/scsi/mvumi.c +1 -1
@@ -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), };
drivers/scsi/ncr53c8xx.c +2 -2
@@ -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)
drivers/scsi/nsp32.c +1 -1
@@ -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, */
drivers/scsi/pcmcia/nsp_cs.c +1 -1
@@ -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), };
drivers/scsi/pcmcia/qlogic_stub.c +1 -1
@@ -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, };/*====================================================================*/
drivers/scsi/qlogicfas.c +1 -1
@@ -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 )
drivers/scsi/stex.c +1 -1
@@ -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[] = {
drivers/scsi/sym53c8xx_2/sym_hipd.h +6 -3
@@ -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;/*
drivers/scsi/xen-scsifront.c +8 -4
@@ -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 ;
include/scsi/scsi_host.h +7 -0
@@ -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;/*
RFC PATCH v2 2/13 mtd: mtdswap: Initialise mtdswap_ops with a page size variable
In reply to Eric CurtinFrom: Eric Curtin <[email protected]>
With arm64 boot-time page size selection PAGE_SIZE is not a compile-time constant, so it cannot be used in 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.
--- drivers/mtd/mtdswap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/mtdswap.c +2 -2
@@ -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);
RFC PATCH v2 3/13 mmc: mmc_test: Allocate the scratch buffer with the test buffer
In reply to Eric CurtinFrom: Eric Curtin <[email protected]>
With arm64 boot-time page size selection PAGE_SIZE is not a compile-time constant. 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.
--- drivers/mmc/core/mmc_test.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/mmc/core/mmc_test.c +4 -3
@@ -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 );
RFC PATCH v2 4/13 md: Remove compile-time PAGE_SIZE use in md, dm and bcache
In reply to Eric CurtinFrom: Eric Curtin <[email protected]>
With arm64 boot-time page size selection PAGE_SIZE and PAGE_SHIFT are not compile-time constants, 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.
--- 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(-)
drivers/md/bcache/debug.c +2 -2
@@ -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 ;
drivers/md/dm-switch.c +1 -1
@@ -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" },
drivers/md/dm-vdo/data-vio.c +1 -1
@@ -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 )
drivers/md/dm-vdo/vio.h +1 -3
@@ -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 */
drivers/md/dm-writecache.c +1 -5
@@ -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
drivers/md/raid1-10.c +2 -1
@@ -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 {
drivers/md/raid1.c +1 -1
@@ -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)
drivers/md/raid5.c +9 -9
@@ -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 ;
drivers/md/raid5.h +8 -5
@@ -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. */
RFC PATCH v2 5/13 zram: Remove PAGE_SIZE use in preprocessor conditionals
In reply to Eric CurtinFrom: Eric Curtin <[email protected]>
With arm64 boot-time page size selection PAGE_SIZE and PAGE_SHIFT are not compile-time constants, 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.
--- drivers/block/zram/zram_drv.c | 20 ++++++-------------- drivers/block/zram/zram_drv.h | 2 +- 2 files changed, 7 insertions(+), 15 deletions(-)
drivers/block/zram/zram_drv.c +6 -14
@@ -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 definedCONFIG_ZRAM_WRITEBACK || definedCONFIG_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, };
drivers/block/zram/zram_drv.h +1 -1
@@ -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
RFC PATCH v2 6/13 xen/blkback: Size indirect_pages for the largest page size
In reply to Eric CurtinFrom: Eric Curtin <[email protected]>
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.
--- drivers/block/xen-blkback/common.h | 7 ++++++- drivers/block/xen-blkback/xenbus.c | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-)
drivers/block/xen-blkback/common.h +6 -1
@@ -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 ];
drivers/block/xen-blkback/xenbus.c +1 -1
@@ -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)
RFC PATCH v2 7/13 null_blk: Size the nullb_page bitmap for PAGE_SIZE_MAX
In reply to Eric CurtinFrom: Eric Curtin <[email protected]>
With arm64 boot-time page size selection PAGE_SIZE is not a compile-time constant, but 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.
--- drivers/block/null_blk/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/block/null_blk/main.c +2 -1
@@ -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)
RFC PATCH v2 8/13 drbd: Use PAGE_SHIFT_MIN in preprocessor checks
In reply to Eric CurtinFrom: Eric Curtin <[email protected]>
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.
--- 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(-)
drivers/block/drbd/drbd_actlog.c +1 -1
@@ -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.
drivers/block/drbd/drbd_bitmap.c +0 -4
@@ -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)
drivers/block/drbd/drbd_int.h +1 -1
@@ -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 */
RFC PATCH v2 9/13 nvme: Check the DSM range buffer against PAGE_SIZE_MIN
In reply to Eric CurtinFrom: Ryan Roberts <[email protected]>
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.
--- drivers/nvme/host/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/host/core.c +1 -1
@@ -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 ;
RFC PATCH v2 10/13 dm: Initialise swap_bios from the runtime PAGE_SIZE
In reply to Eric CurtinFrom: Ryan Roberts <[email protected]>
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.
--- drivers/md/dm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm.c +1 -1
@@ -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);
RFC PATCH v2 11/13 virtio: Handle boot-time PAGE_SIZE in balloon, blk and 9p transport
In reply to Eric CurtinFrom: Ryan Roberts <[email protected]>
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.
--- 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(-)
drivers/block/virtio_blk.c +1 -1
@@ -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);
drivers/virtio/virtio_balloon.c +6 -4
@@ -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;
net/9p/trans_virtio.c +2 -2
@@ -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 )
RFC PATCH v2 12/13 ata: sata_sil24: Use flexible arrays for the command block SGEs
In reply to Eric CurtinFrom: Ryan Roberts <[email protected]>
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.
--- drivers/ata/sata_sil24.c | 70 ++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 27 deletions(-)
drivers/ata/sata_sil24.c +43 -27
@@ -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 );
RFC PATCH v2 13/13 mm: Use PAGE_SIZE_MIN/MAX where a compile-time constant is required
In reply to Eric CurtinFrom: Ryan Roberts <[email protected]>
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.
--- 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(-)
drivers/mtd/mtdswap.c +2 -2
@@ -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 ; }
drivers/nvdimm/namespace_devs.c +2 -2
@@ -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 ); }
include/linux/leafops.h +1 -1
@@ -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;
include/linux/mm.h +1 -1
@@ -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)); }
include/linux/mm_types_task.h +1 -1
@@ -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
include/linux/mmzone.h +2 -1
@@ -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
include/linux/slab.h +20 -10
@@ -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_tif (__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, gif (__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); }
include/linux/swap.h +11 -5
@@ -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 {
include/linux/swapops.h +4 -0
@@ -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)
mm/huge_memory.c +2 -2
@@ -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);
mm/memcontrol.c +2 -2
@@ -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 ();
mm/memory.c +2 -2
@@ -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)
mm/mmap.c +1 -1
@@ -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) {
mm/page-writeback.c +1 -1
@@ -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[] = { {
mm/slub.c +1 -1
@@ -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);
mm/sparse.h +1 -1
@@ -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);/*
mm/swapfile.c +1 -1
@@ -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 ; }
mm/vmalloc.c +4 -2
@@ -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 );
Damien Le Moal
maintainerRe: [RFC PATCH v2 12/13] ata: sata_sil24: Use flexible arrays for the command block SGEs
In reply to Eric CurtinQuoted 73 lines · Eric Curtin
From: Ryan Roberts <[email protected]>
SIL24_MAX_SGEis derived fromPAGE_SIZE, so with boot-time page size selection it is not a compile-time constant and cannot size the sge[] arrays in structsil24_ata_blockand structsil24_atapi_block.Make sge[] a flexible array in both and move
SIL24_MAX_SGTandSIL24_MAX_SGEout of the enum into macros, since they are no longer constant. Add SIL24_*_BLOCK_SIZE macros that compute the block sizes withstruct_size_t(), and addsil24_cmd_blk()to index the command block array, becausesizeof(union sil24_cmd_block)is no longer the stride. UseSIL24_CMD_BLOCK_SIZEfor the block stride insil24_qc_issue()and for the allocation size insil24_port_start().Define
sil24_shtwithDEFINE_GLOBAL_PAGE_SIZE_VAR_CONST()so that itssg_tablesizeis initialised at boot.The link-time check that union
sil24_cmd_blockis exactlyPAGE_SIZEcannot work for a run-time value, so replace it withWARN_ON_ONCE()checks insil24_init_one()that fail the probe with-EINVAL.Signed-off-by Ryan Roberts <[email protected]>Signed-off-by Eric Curtin <[email protected]>--- drivers/ata/sata_sil24.c | 70 ++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 27 deletions(-)drivers/ata/sata_sil24.c +14
-15@@ -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) */
drivers/ata/sata_sil24.c enum { · line 246
Quoted 5 lines
drivers/ata/sata_sil24.c +1
-1@@ -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.
drivers/ata/sata_sil24.c enum { · line 252
Quoted 7 lines
drivers/ata/sata_sil24.c +1
-1};struct sil24_atapi_block {struct sil24_prb prb;u8 cdb[16 ]; -struct sil24_sge sge[SIL24_MAX_SGE ]; +struct sil24_sge sge[];
Here too.
Quoted 29 lines
drivers/ata/sata_sil24.c +11
-0};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);
drivers/ata/sata_sil24.c static struct pci_driver sil24_pci_driver = { · line 385
Quoted 5 lines
drivers/ata/sata_sil24.c +1
-1@@ -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?
Quoted 76 lines
drivers/ata/sata_sil24.c +15
-9__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 );
Signature · 2 lines
Damien Le Moal Western Digital Research
Re: [RFC PATCH v2 02/13] mtd: mtdswap: Initialise mtdswap_ops with a page size variable
In reply to Eric CurtinQuoted 6 lines · Eric Curtin
From: Eric Curtin <[email protected]>
With arm64 boot-time page size selection
PAGE_SIZEis not a compile-time constant, so it cannot be used in the static initialiser ofmtdswap_ops, whose .blksize isPAGE_SIZE.
Quoted 7 lines
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 <[email protected]>
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