From patchwork Wed Aug 15 23:08:05 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikulas Patocka X-Patchwork-Id: 1328921 Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by patchwork1.kernel.org (Postfix) with ESMTP id E2D423FC66 for ; Wed, 15 Aug 2012 23:10:37 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q7FN8B7H025215; Wed, 15 Aug 2012 19:08:11 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q7FN8AEU022095 for ; Wed, 15 Aug 2012 19:08:10 -0400 Received: from file.rdu.redhat.com (file.rdu.redhat.com [10.11.255.147]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q7FN85Fe022020 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 15 Aug 2012 19:08:05 -0400 Received: from file.rdu.redhat.com (localhost [127.0.0.1]) by file.rdu.redhat.com (8.14.4/8.14.4) with ESMTP id q7FN85Ox013412; Wed, 15 Aug 2012 19:08:05 -0400 Received: from localhost (mpatocka@localhost) by file.rdu.redhat.com (8.14.4/8.14.4/Submit) with ESMTP id q7FN85eW013409; Wed, 15 Aug 2012 19:08:05 -0400 X-Authentication-Warning: file.rdu.redhat.com: mpatocka owned process doing -bs Date: Wed, 15 Aug 2012 19:08:05 -0400 (EDT) From: Mikulas Patocka X-X-Sender: mpatocka@file.rdu.redhat.com To: "Alasdair G. Kergon" Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com Subject: [dm-devel] [PATCH] dm-bufio & dm-verity: use ACCESS_ONCE instead of volatile X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com Hi This is a simple cleanup patch. Mikulas --- dm-bufio & dm-verity: use ACCESS_ONCE instead of volatile If the variable can be asynchronously modified and we want to prevent compiler optimizations that could assume that the variable is the same, use ACCESS_ONCE macro, as documented in Documentation/atomic_ops.txt. Signed-off-by: Mikulas Patocka --- drivers/md/dm-bufio.c | 6 +++--- drivers/md/dm-verity.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) -- dm-devel mailing list dm-devel@redhat.com https://www.redhat.com/mailman/listinfo/dm-devel Index: linux-3.5.1-fast/drivers/md/dm-bufio.c =================================================================== --- linux-3.5.1-fast.orig/drivers/md/dm-bufio.c 2012-08-16 00:46:43.000000000 +0200 +++ linux-3.5.1-fast/drivers/md/dm-bufio.c 2012-08-16 00:49:08.000000000 +0200 @@ -280,7 +280,7 @@ static void __cache_size_refresh(void) BUG_ON(!mutex_is_locked(&dm_bufio_clients_lock)); BUG_ON(dm_bufio_client_count < 0); - dm_bufio_cache_size_latch = *(volatile unsigned long *)&dm_bufio_cache_size; + dm_bufio_cache_size_latch = ACCESS_ONCE(dm_bufio_cache_size); /* * Use default if set to 0 and report the actual cache size used. @@ -811,7 +811,7 @@ static void __get_memory_limit(struct dm { unsigned long buffers; - if (*(volatile unsigned long *)&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); __cache_size_refresh(); mutex_unlock(&dm_bufio_clients_lock); @@ -1589,7 +1589,7 @@ EXPORT_SYMBOL_GPL(dm_bufio_client_destro static void cleanup_old_buffers(void) { - unsigned long max_age = *(volatile unsigned *)&dm_bufio_max_age; + unsigned long max_age = ACCESS_ONCE(dm_bufio_max_age); struct dm_bufio_client *c; if (max_age > ULONG_MAX / HZ) Index: linux-3.5.1-fast/drivers/md/dm-verity.c =================================================================== --- linux-3.5.1-fast.orig/drivers/md/dm-verity.c 2012-08-16 00:46:14.000000000 +0200 +++ linux-3.5.1-fast/drivers/md/dm-verity.c 2012-08-16 00:47:11.000000000 +0200 @@ -438,7 +438,7 @@ static void verity_prefetch_io(struct dm 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); if (!i) { - unsigned cluster = *(volatile unsigned *)&dm_verity_prefetch_cluster; + unsigned cluster = ACCESS_ONCE(dm_verity_prefetch_cluster); cluster >>= v->data_dev_block_bits; if (unlikely(!cluster))