Commit fe5fe906 authored by Mikulas Patocka's avatar Mikulas Patocka Committed by Alasdair G Kergon

dm: use ACCESS_ONCE for sysfs values

Use the ACCESS_ONCE macro in dm-bufio and dm-verity where a variable
can be modified asynchronously (through sysfs) and we want to prevent
compiler optimizations that assume that the variable hasn't changed.
(See Documentation/atomic_ops.txt.)
Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
Signed-off-by: default avatarAlasdair G Kergon <agk@redhat.com>
parent 54499afb
...@@ -280,9 +280,7 @@ static void __cache_size_refresh(void) ...@@ -280,9 +280,7 @@ static void __cache_size_refresh(void)
BUG_ON(!mutex_is_locked(&dm_bufio_clients_lock)); BUG_ON(!mutex_is_locked(&dm_bufio_clients_lock));
BUG_ON(dm_bufio_client_count < 0); BUG_ON(dm_bufio_client_count < 0);
dm_bufio_cache_size_latch = dm_bufio_cache_size; dm_bufio_cache_size_latch = ACCESS_ONCE(dm_bufio_cache_size);
barrier();
/* /*
* Use default if set to 0 and report the actual cache size used. * Use default if set to 0 and report the actual cache size used.
...@@ -812,7 +810,7 @@ static void __get_memory_limit(struct dm_bufio_client *c, ...@@ -812,7 +810,7 @@ static void __get_memory_limit(struct dm_bufio_client *c,
{ {
unsigned long buffers; unsigned long buffers;
if (dm_bufio_cache_size != dm_bufio_cache_size_latch) { if (ACCESS_ONCE(dm_bufio_cache_size) != dm_bufio_cache_size_latch) {
mutex_lock(&dm_bufio_clients_lock); mutex_lock(&dm_bufio_clients_lock);
__cache_size_refresh(); __cache_size_refresh();
mutex_unlock(&dm_bufio_clients_lock); mutex_unlock(&dm_bufio_clients_lock);
...@@ -1590,11 +1588,9 @@ EXPORT_SYMBOL_GPL(dm_bufio_client_destroy); ...@@ -1590,11 +1588,9 @@ EXPORT_SYMBOL_GPL(dm_bufio_client_destroy);
static void cleanup_old_buffers(void) static void cleanup_old_buffers(void)
{ {
unsigned long max_age = dm_bufio_max_age; unsigned long max_age = ACCESS_ONCE(dm_bufio_max_age);
struct dm_bufio_client *c; struct dm_bufio_client *c;
barrier();
if (max_age > ULONG_MAX / HZ) if (max_age > ULONG_MAX / HZ)
max_age = ULONG_MAX / HZ; max_age = ULONG_MAX / HZ;
......
...@@ -438,7 +438,7 @@ static void verity_prefetch_io(struct dm_verity *v, struct dm_verity_io *io) ...@@ -438,7 +438,7 @@ static void verity_prefetch_io(struct dm_verity *v, struct dm_verity_io *io)
verity_hash_at_level(v, io->block, i, &hash_block_start, NULL); verity_hash_at_level(v, io->block, i, &hash_block_start, NULL);
verity_hash_at_level(v, io->block + io->n_blocks - 1, i, &hash_block_end, NULL); verity_hash_at_level(v, io->block + io->n_blocks - 1, i, &hash_block_end, NULL);
if (!i) { if (!i) {
unsigned cluster = *(volatile unsigned *)&dm_verity_prefetch_cluster; unsigned cluster = ACCESS_ONCE(dm_verity_prefetch_cluster);
cluster >>= v->data_dev_block_bits; cluster >>= v->data_dev_block_bits;
if (unlikely(!cluster)) if (unlikely(!cluster))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment