Skip to content

Commit cf8d097

Browse files
axboegregkh
authored andcommitted
block: setup bounce bio_sets properly
commit 52990a5 upstream. 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. Protect the ISA bounce setup with a mutex, since it's being invoked from driver init functions and can thus be called in parallel. Cc: [email protected] Reported-by: Ondrej Zary <[email protected]> Tested-by: Ondrej Zary <[email protected]> Signed-off-by: Jens Axboe <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f5f578e commit cf8d097

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

block/bounce.c

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,24 @@
3131
static struct bio_set bounce_bio_set, bounce_bio_split;
3232
static mempool_t page_pool, isa_page_pool;
3333

34+
static void init_bounce_bioset(void)
35+
{
36+
static bool bounce_bs_setup;
37+
int ret;
38+
39+
if (bounce_bs_setup)
40+
return;
41+
42+
ret = bioset_init(&bounce_bio_set, BIO_POOL_SIZE, 0, BIOSET_NEED_BVECS);
43+
BUG_ON(ret);
44+
if (bioset_integrity_create(&bounce_bio_set, BIO_POOL_SIZE))
45+
BUG_ON(1);
46+
47+
ret = bioset_init(&bounce_bio_split, BIO_POOL_SIZE, 0, 0);
48+
BUG_ON(ret);
49+
bounce_bs_setup = true;
50+
}
51+
3452
#if defined(CONFIG_HIGHMEM)
3553
static __init int init_emergency_pool(void)
3654
{
@@ -44,14 +62,7 @@ static __init int init_emergency_pool(void)
4462
BUG_ON(ret);
4563
pr_info("pool size: %d pages\n", POOL_SIZE);
4664

47-
ret = bioset_init(&bounce_bio_set, BIO_POOL_SIZE, 0, BIOSET_NEED_BVECS);
48-
BUG_ON(ret);
49-
if (bioset_integrity_create(&bounce_bio_set, BIO_POOL_SIZE))
50-
BUG_ON(1);
51-
52-
ret = bioset_init(&bounce_bio_split, BIO_POOL_SIZE, 0, 0);
53-
BUG_ON(ret);
54-
65+
init_bounce_bioset();
5566
return 0;
5667
}
5768

@@ -86,6 +97,8 @@ static void *mempool_alloc_pages_isa(gfp_t gfp_mask, void *data)
8697
return mempool_alloc_pages(gfp_mask | GFP_DMA, data);
8798
}
8899

100+
static DEFINE_MUTEX(isa_mutex);
101+
89102
/*
90103
* gets called "every" time someone init's a queue with BLK_BOUNCE_ISA
91104
* as the max address, so check if the pool has already been created.
@@ -94,14 +107,20 @@ int init_emergency_isa_pool(void)
94107
{
95108
int ret;
96109

97-
if (mempool_initialized(&isa_page_pool))
110+
mutex_lock(&isa_mutex);
111+
112+
if (mempool_initialized(&isa_page_pool)) {
113+
mutex_unlock(&isa_mutex);
98114
return 0;
115+
}
99116

100117
ret = mempool_init(&isa_page_pool, ISA_POOL_SIZE, mempool_alloc_pages_isa,
101118
mempool_free_pages, (void *) 0);
102119
BUG_ON(ret);
103120

104121
pr_info("isa pool size: %d pages\n", ISA_POOL_SIZE);
122+
init_bounce_bioset();
123+
mutex_unlock(&isa_mutex);
105124
return 0;
106125
}
107126

0 commit comments

Comments
 (0)