Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934919AbdIYN0L (ORCPT ); Mon, 25 Sep 2017 09:26:11 -0400 Received: from foss.arm.com ([217.140.101.70]:51764 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932395AbdIYN0K (ORCPT ); Mon, 25 Sep 2017 09:26:10 -0400 From: Mark Rutland To: linux-kernel@vger.kernel.org Cc: Mark Rutland , Arnd Bergmann , Christoph Lameter , Peter Zijlstra , Pranith Kumar , Tejun Heo , linux-arch@vger.kernel.org Subject: [PATCH] percpu: make this_cpu_generic_read() atomic w.r.t. interrupts Date: Mon, 25 Sep 2017 14:24:32 +0100 Message-Id: <1506345872-30559-1-git-send-email-mark.rutland@arm.com> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1305 Lines: 38 As raw_cpu_generic_read() is a plain read from a raw_cpu_ptr() address, it's possible (albeit unlikely) that the compiler will split the access across multiple instructions. In this_cpu_generic_read() we disable preemption but not interrupts before calling raw_cpu_generic_read(). Thus, an interrupt could be taken in the middle of the split load instructions. If a this_cpu_write() or RMW this_cpu_*() op is made to the same variable in the interrupt handling path, this_cpu_read() will return a torn value. Avoid this by using READ_ONCE() to inhibit tearing. Signed-off-by: Mark Rutland Cc: Arnd Bergmann Cc: Christoph Lameter Cc: Peter Zijlstra Cc: Pranith Kumar Cc: Tejun Heo Cc: linux-arch@vger.kernel.org --- include/asm-generic/percpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/asm-generic/percpu.h b/include/asm-generic/percpu.h index 0504ef8..79a8a58 100644 --- a/include/asm-generic/percpu.h +++ b/include/asm-generic/percpu.h @@ -67,7 +67,7 @@ #define raw_cpu_generic_read(pcp) \ ({ \ - *raw_cpu_ptr(&(pcp)); \ + READ_ONCE(*raw_cpu_ptr(&(pcp))); \ }) #define raw_cpu_generic_to_op(pcp, val, op) \ -- 1.9.1