On Wed, Jun 14, 2023 at 01:46:34PM +0200, Hannes Reinecke wrote: > @@ -43,9 +43,11 @@ struct brd_device { > */ > struct xarray brd_folios; > u64 brd_nr_folios; > + unsigned int brd_sector_shift; > + unsigned int brd_sector_size; > }; > > -#define BRD_SECTOR_SHIFT(b) (PAGE_SHIFT - SECTOR_SHIFT) > +#define BRD_SECTOR_SHIFT(b) ((b)->brd_sector_shift - SECTOR_SHIFT) > > static pgoff_t brd_sector_index(struct brd_device *brd, sector_t sector) > { > @@ -85,7 +87,7 @@ static int brd_insert_folio(struct brd_device *brd, sector_t sector, gfp_t gfp) > { > pgoff_t idx; > struct folio *folio, *cur; > - unsigned int rd_sector_order = get_order(PAGE_SIZE); > + unsigned int rd_sector_order = get_order(brd->brd_sector_size); Surely max(0, brd->brd_sector_shift - PAGE_SHIFT) ? > @@ -346,6 +353,25 @@ static int brd_alloc(int i) > return -ENOMEM; > brd->brd_number = i; > list_add_tail(&brd->brd_list, &brd_devices); > + brd->brd_sector_shift = ilog2(rd_blksize); > + if ((1ULL << brd->brd_sector_shift) != rd_blksize) { > + pr_err("rd_blksize %d is not supported\n", rd_blksize); Are you trying to require power-of-two here? We have is_power_of_2() for that purpose.