The bio_slabs xarray and the slab_ref member of struct bio_slab are only accessed with bio_slab_lock held. The internal xarray lock is not sufficient since a lookup and the subsequent reference count update must happen atomically. Annotate both with __guarded_by(&bio_slab_lock) such that Clang's context analysis can verify that bio_slab_lock is held for all accesses. Move the bio_slab_lock definition above the struct bio_slab definition such that it can be referenced from the member annotation. Signed-off-by: Bart Van Assche --- block/bio.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/block/bio.c b/block/bio.c index 48d42acd5d90..066aeee9edb7 100644 --- a/block/bio.c +++ b/block/bio.c @@ -76,14 +76,16 @@ EXPORT_SYMBOL(fs_bio_set); /* * Our slab pool management */ +static DEFINE_MUTEX(bio_slab_lock); + struct bio_slab { struct kmem_cache *slab; - unsigned int slab_ref; + unsigned int slab_ref __guarded_by(&bio_slab_lock); unsigned int slab_size; char name[12]; }; -static DEFINE_MUTEX(bio_slab_lock); -static DEFINE_XARRAY(bio_slabs); + +static __guarded_by(&bio_slab_lock) DEFINE_XARRAY(bio_slabs); static struct bio_slab *create_bio_slab(unsigned int size) __must_hold(&bio_slab_lock)