block: setup bounce bio_sets properly
Jens Axboe
maintainerPATCH 1/1 block: setup bounce bio_sets properly
We're only setting up the bounce bio sets if we happen to need bouncing for regular HIGHMEM, not if we only need it for ISA devices.
block/bounce.c +20 -8
@@ -31,6 +31,24 @@static struct bio_set bounce_bio_set, bounce_bio_split;static mempool_t page_pool, isa_page_pool; +static void init_bounce_bioset (void ) +{ +static bool bounce_bs_setup; +int ret; + +if (bounce_bs_setup) +return ; + + ret =bioset_init (&bounce_bio_set,BIO_POOL_SIZE ,0 ,BIOSET_NEED_BVECS ); +BUG_ON (ret); +if (bioset_integrity_create (&bounce_bio_set,BIO_POOL_SIZE )) +BUG_ON (1 ); + + ret =bioset_init (&bounce_bio_split,BIO_POOL_SIZE ,0 ,0 ); +BUG_ON (ret); + bounce_bs_setup = true; +} +#if defined(CONFIG_HIGHMEM )static __init int init_emergency_pool (void ) {
@@ -44,14 +62,7 @@ static __init int init_emergency_pool(void)BUG_ON (ret);pr_info ("pool size: %d pages\n" ,POOL_SIZE ); - ret =bioset_init (&bounce_bio_set,BIO_POOL_SIZE ,0 ,BIOSET_NEED_BVECS ); -BUG_ON (ret); -if (bioset_integrity_create (&bounce_bio_set,BIO_POOL_SIZE )) -BUG_ON (1 ); - - ret =bioset_init (&bounce_bio_split,BIO_POOL_SIZE ,0 ,0 ); -BUG_ON (ret); - +init_bounce_bioset ();return 0 ; }
@@ -102,6 +113,7 @@ int init_emergency_isa_pool(void)BUG_ON (ret);pr_info ("isa pool size: %d pages\n" ,ISA_POOL_SIZE ); +init_bounce_bioset ();return 0 ; }
Signature · 1 line
Jens Axboe
Quoted 22 lines · Jens Axboe
We're only setting up the bounce bio sets if we happen to need bouncing for regular HIGHMEM, not if we only need it for ISA devices.
Reported-by Ondrej Zary <[email protected]>Tested-by Ondrej Zary <[email protected]>Signed-off-by Jens Axboe <[email protected]>block/bounce.c +6
-0@@ -31,6 +31,24 @@static struct bio_set bounce_bio_set, bounce_bio_split;static mempool_t page_pool, isa_page_pool; +static void init_bounce_bioset (void ) +{ +static bool bounce_bs_setup; +int ret; + +if (bounce_bs_setup)
block/bounce.c line 49
Quoted 10 lines
block/bounce.c +10
-0+return ; + + ret =bioset_init (&bounce_bio_set,BIO_POOL_SIZE ,0 ,BIOSET_NEED_BVECS ); +BUG_ON (ret); +if (bioset_integrity_create (&bounce_bio_set,BIO_POOL_SIZE )) +BUG_ON (1 ); + + ret =bioset_init (&bounce_bio_split,BIO_POOL_SIZE ,0 ,0 ); +BUG_ON (ret); + bounce_bs_setup = true;
When initcall is run from do_basic_setup(), all CPUs and scheduler have been up, it is likely that init_emergency_pool() is run when one driver is calling blk_queue_bounce_limit() to start init_emergency_isa_pool().
So the above code might be run twice.
Thanks,
Ming
Jens Axboe
maintainerQuoted 38 lines · Ming Lei
Quoted 22 lines · Jens Axboe
We're only setting up the bounce bio sets if we happen to need bouncing for regular HIGHMEM, not if we only need it for ISA devices.
Reported-by Ondrej Zary <[email protected]>Tested-by Ondrej Zary <[email protected]>Signed-off-by Jens Axboe <[email protected]>block/bounce.c +6
-0@@ -31,6 +31,24 @@static struct bio_set bounce_bio_set, bounce_bio_split;static mempool_t page_pool, isa_page_pool; +static void init_bounce_bioset (void ) +{ +static bool bounce_bs_setup; +int ret; + +if (bounce_bs_setup)block/bounce.c line 49
Quoted 10 lines
block/bounce.c +10
-0+return ; + + ret =bioset_init (&bounce_bio_set,BIO_POOL_SIZE ,0 ,BIOSET_NEED_BVECS ); +BUG_ON (ret); +if (bioset_integrity_create (&bounce_bio_set,BIO_POOL_SIZE )) +BUG_ON (1 ); + + ret =bioset_init (&bounce_bio_split,BIO_POOL_SIZE ,0 ,0 ); +BUG_ON (ret); + bounce_bs_setup = true;When initcall is run from
do_basic_setup(), all CPUs and scheduler have been up, it is likely thatinit_emergency_pool()is run when one driver is callingblk_queue_bounce_limit()to startinit_emergency_isa_pool().
Quoted 1 line
So the above code might be run twice.
Good point, it's actually not even safe right now with the mempool setup. How about the below?
block/bounce.c +28 -9
@@ -31,6 +31,24 @@static struct bio_set bounce_bio_set, bounce_bio_split;static mempool_t page_pool, isa_page_pool; +static void init_bounce_bioset (void ) +{ +static bool bounce_bs_setup; +int ret; + +if (bounce_bs_setup) +return ; + + ret =bioset_init (&bounce_bio_set,BIO_POOL_SIZE ,0 ,BIOSET_NEED_BVECS ); +BUG_ON (ret); +if (bioset_integrity_create (&bounce_bio_set,BIO_POOL_SIZE )) +BUG_ON (1 ); + + ret =bioset_init (&bounce_bio_split,BIO_POOL_SIZE ,0 ,0 ); +BUG_ON (ret); + bounce_bs_setup = true; +} +#if defined(CONFIG_HIGHMEM )static __init int init_emergency_pool (void ) {
@@ -44,14 +62,7 @@ static __init int init_emergency_pool(void)BUG_ON (ret);pr_info ("pool size: %d pages\n" ,POOL_SIZE ); - ret =bioset_init (&bounce_bio_set,BIO_POOL_SIZE ,0 ,BIOSET_NEED_BVECS ); -BUG_ON (ret); -if (bioset_integrity_create (&bounce_bio_set,BIO_POOL_SIZE )) -BUG_ON (1 ); - - ret =bioset_init (&bounce_bio_split,BIO_POOL_SIZE ,0 ,0 ); -BUG_ON (ret); - +init_bounce_bioset ();return 0 ; }
@@ -86,6 +97,8 @@ static void *mempool_alloc_pages_isa(gfp_t gfp_mask, void *data)return mempool_alloc_pages (gfp_mask |GFP_DMA , data); } +static DEFINE_MUTEX (isa_mutex); +/* * gets called "every" time someone init's a queue with BLK_BOUNCE_ISA * as the max address, so check if the pool has already been created.
@@ -94,14 +107,20 @@ int init_emergency_isa_pool(void) {int ret; -if (mempool_initialized (&isa_page_pool)) +mutex_lock (&isa_mutex); + +if (mempool_initialized (&isa_page_pool)) { +mutex_unlock (&isa_mutex);return 0 ; + } ret =mempool_init (&isa_page_pool,ISA_POOL_SIZE , mempool_alloc_pages_isa, mempool_free_pages, (void *)0 );BUG_ON (ret);pr_info ("isa pool size: %d pages\n" ,ISA_POOL_SIZE ); +init_bounce_bioset (); +mutex_unlock (&isa_mutex);return 0 ; }
Signature · 1 line
Jens Axboe
Quoted 111 lines · On Friday 19 October 2018 18:35:00 Jens Axboe wrote:
Quoted 38 lines · Ming Lei
Quoted 22 lines · Jens Axboe
We're only setting up the bounce bio sets if we happen to need bouncing for regular HIGHMEM, not if we only need it for ISA devices.
Reported-by Ondrej Zary <[email protected]>Tested-by Ondrej Zary <[email protected]>Signed-off-by Jens Axboe <[email protected]>block/bounce.c +6
-0@@ -31,6 +31,24 @@static struct bio_set bounce_bio_set, bounce_bio_split;static mempool_t page_pool, isa_page_pool; +static void init_bounce_bioset (void ) +{ +static bool bounce_bs_setup; +int ret; + +if (bounce_bs_setup)block/bounce.c line 49
Quoted 10 lines
block/bounce.c +10
-0+return ; + + ret =bioset_init (&bounce_bio_set,BIO_POOL_SIZE ,0 ,BIOSET_NEED_BVECS ); +BUG_ON (ret); +if (bioset_integrity_create (&bounce_bio_set,BIO_POOL_SIZE )) +BUG_ON (1 ); + + ret =bioset_init (&bounce_bio_split,BIO_POOL_SIZE ,0 ,0 ); +BUG_ON (ret); + bounce_bs_setup = true;When initcall is run from
do_basic_setup(), all CPUs and scheduler have been up, it is likely thatinit_emergency_pool()is run when one driver is callingblk_queue_bounce_limit()to startinit_emergency_isa_pool().Quoted 1 line
So the above code might be run twice.
Good point, it's actually not even safe right now with the mempool setup. How about the below?
block/bounce.c +26
-9@@ -31,6 +31,24 @@static struct bio_set bounce_bio_set, bounce_bio_split;static mempool_t page_pool, isa_page_pool; +static void init_bounce_bioset (void ) +{ +static bool bounce_bs_setup; +int ret; + +if (bounce_bs_setup) +return ; + + ret =bioset_init (&bounce_bio_set,BIO_POOL_SIZE ,0 ,BIOSET_NEED_BVECS ); +BUG_ON (ret); +if (bioset_integrity_create (&bounce_bio_set,BIO_POOL_SIZE )) +BUG_ON (1 ); + + ret =bioset_init (&bounce_bio_split,BIO_POOL_SIZE ,0 ,0 ); +BUG_ON (ret); + bounce_bs_setup = true; +} +#if defined(CONFIG_HIGHMEM )static __init int init_emergency_pool (void ) {@@ -44,14 +62,7 @@ static __init int init_emergency_pool(void)BUG_ON (ret);pr_info ("pool size: %d pages\n" ,POOL_SIZE ); - ret =bioset_init (&bounce_bio_set,BIO_POOL_SIZE ,0 ,BIOSET_NEED_BVECS ); -BUG_ON (ret); -if (bioset_integrity_create (&bounce_bio_set,BIO_POOL_SIZE )) -BUG_ON (1 ); - - ret =bioset_init (&bounce_bio_split,BIO_POOL_SIZE ,0 ,0 ); -BUG_ON (ret); - +init_bounce_bioset ();return 0 ; }@@ -86,6 +97,8 @@ static void *mempool_alloc_pages_isa(gfp_t gfp_mask, void *data)return mempool_alloc_pages (gfp_mask |GFP_DMA , data); } +static DEFINE_MUTEX (isa_mutex); +/* * gets called "every" time someone init's a queue with BLK_BOUNCE_ISA * as the max address, so check if the pool has already been created. @@ -94,14 +107,20 @@ int init_emergency_isa_pool(void) {int ret; -if (mempool_initialized (&isa_page_pool)) +mutex_lock (&isa_mutex); + +if (mempool_initialized (&isa_page_pool)) { +mutex_unlock (&isa_mutex);return 0 ; + }
block/bounce.c int init_emergency_isa_pool(void) · line 126
Quoted 10 lines
block/bounce.c +2
-0ret =mempool_init (&isa_page_pool,ISA_POOL_SIZE , mempool_alloc_pages_isa, mempool_free_pages, (void *)0 );BUG_ON (ret);pr_info ("isa pool size: %d pages\n" ,ISA_POOL_SIZE ); +init_bounce_bioset (); +mutex_unlock (&isa_mutex);return 0 ; }
Works for me.
Signature · 1 line
Ondrej Zary
Jens Axboe
maintainerQuoted 116 lines · Ondrej Zary
Quoted 115 lines · On Friday 19 October 2018 18:35:00 Jens Axboe wrote:
Quoted 38 lines · Ming Lei
Quoted 22 lines · Jens Axboe
We're only setting up the bounce bio sets if we happen to need bouncing for regular HIGHMEM, not if we only need it for ISA devices.
Reported-by Ondrej Zary <[email protected]>Tested-by Ondrej Zary <[email protected]>Signed-off-by Jens Axboe <[email protected]>block/bounce.c +6
-0@@ -31,6 +31,24 @@static struct bio_set bounce_bio_set, bounce_bio_split;static mempool_t page_pool, isa_page_pool; +static void init_bounce_bioset (void ) +{ +static bool bounce_bs_setup; +int ret; + +if (bounce_bs_setup)block/bounce.c line 49
Quoted 10 lines
block/bounce.c +10
-0+return ; + + ret =bioset_init (&bounce_bio_set,BIO_POOL_SIZE ,0 ,BIOSET_NEED_BVECS ); +BUG_ON (ret); +if (bioset_integrity_create (&bounce_bio_set,BIO_POOL_SIZE )) +BUG_ON (1 ); + + ret =bioset_init (&bounce_bio_split,BIO_POOL_SIZE ,0 ,0 ); +BUG_ON (ret); + bounce_bs_setup = true;When initcall is run from
do_basic_setup(), all CPUs and scheduler have been up, it is likely thatinit_emergency_pool()is run when one driver is callingblk_queue_bounce_limit()to startinit_emergency_isa_pool().Quoted 1 line
So the above code might be run twice.
Good point, it's actually not even safe right now with the mempool setup. How about the below?
block/bounce.c +26
-9@@ -31,6 +31,24 @@static struct bio_set bounce_bio_set, bounce_bio_split;static mempool_t page_pool, isa_page_pool; +static void init_bounce_bioset (void ) +{ +static bool bounce_bs_setup; +int ret; + +if (bounce_bs_setup) +return ; + + ret =bioset_init (&bounce_bio_set,BIO_POOL_SIZE ,0 ,BIOSET_NEED_BVECS ); +BUG_ON (ret); +if (bioset_integrity_create (&bounce_bio_set,BIO_POOL_SIZE )) +BUG_ON (1 ); + + ret =bioset_init (&bounce_bio_split,BIO_POOL_SIZE ,0 ,0 ); +BUG_ON (ret); + bounce_bs_setup = true; +} +#if defined(CONFIG_HIGHMEM )static __init int init_emergency_pool (void ) {@@ -44,14 +62,7 @@ static __init int init_emergency_pool(void)BUG_ON (ret);pr_info ("pool size: %d pages\n" ,POOL_SIZE ); - ret =bioset_init (&bounce_bio_set,BIO_POOL_SIZE ,0 ,BIOSET_NEED_BVECS ); -BUG_ON (ret); -if (bioset_integrity_create (&bounce_bio_set,BIO_POOL_SIZE )) -BUG_ON (1 ); - - ret =bioset_init (&bounce_bio_split,BIO_POOL_SIZE ,0 ,0 ); -BUG_ON (ret); - +init_bounce_bioset ();return 0 ; }@@ -86,6 +97,8 @@ static void *mempool_alloc_pages_isa(gfp_t gfp_mask, void *data)return mempool_alloc_pages (gfp_mask |GFP_DMA , data); } +static DEFINE_MUTEX (isa_mutex); +/* * gets called "every" time someone init's a queue with BLK_BOUNCE_ISA * as the max address, so check if the pool has already been created. @@ -94,14 +107,20 @@ int init_emergency_isa_pool(void) {int ret; -if (mempool_initialized (&isa_page_pool)) +mutex_lock (&isa_mutex); + +if (mempool_initialized (&isa_page_pool)) { +mutex_unlock (&isa_mutex);return 0 ; + } ret =mempool_init (&isa_page_pool,ISA_POOL_SIZE , mempool_alloc_pages_isa, mempool_free_pages, (void *)0 );BUG_ON (ret);
Quoted 8 lines
block/bounce.c int init_emergency_isa_pool(void) · line 126
Quoted 6 lines
block/bounce.c +2
-0pr_info ("isa pool size: %d pages\n" ,ISA_POOL_SIZE ); +init_bounce_bioset (); +mutex_unlock (&isa_mutex);return 0 ; }Works for me.
Thanks Ondrej, I'm going to queue it up for 4.20 and mark it for stable.
Signature · 1 line
Jens Axboe