From patchwork Mon Sep 25 13:24:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 114173 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp2607600qgf; Mon, 25 Sep 2017 06:26:13 -0700 (PDT) X-Google-Smtp-Source: AOwi7QA5P0q5vMelVKEvGEXLZ9yM5PN5gsApR0VuqlXdrigUsjyjDI7RoZtkZ2O73anfmA/dUIZJ X-Received: by 10.159.197.76 with SMTP id d12mr7617665plo.132.1506345973709; Mon, 25 Sep 2017 06:26:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506345973; cv=none; d=google.com; s=arc-20160816; b=wFwfUaaDvsjyu8Qu472A3TsOU2k5ogbPRX5HPF8neOmwLM/nDuDg5lcyVmPkpXpLFR iCrdC2Z7uL6hfgY4K5PH+kR8RvsjvG8RNrnBgYRd6KjlhhmHUemKOziFhOpf4mjgM/id qQrrSOHEo1bs9gVQpqD8rBO/sp885Kn1gquqji9ohs9DKoc+dqW1DNJnlOXlBrr4I2Ct 4StKxrSwsi1jguHag48SCcJg1gzGj5oVnK44Av7U/RJG4yYRzI3EpxcoNtqAZFH4yXs8 JTZaOQmfpMffiVbTWJpHUsCZagPxdA4YwRxm5VbPUNC0Kww2BmTkrabKIpCBBKfqui4K /XEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=/I9nfENowPS8vs6zw7UyQsw4MLONFdoVzgqFqa/ZPhs=; b=Ww9i4aJo9Cf+tdg0ER341EbAfU4VZkVhLQTtXSMI1jruGUGJQhfwLhb984b58YYfbK /Ng9PJhF0VroiM9gMI4QjoB+Ra5Rvlk5IXrtpife6vJrmRbpcyZyvQkUn7tmwAqfexT3 2WNQW9hWvPEuVl1ePmztIKkRWcukpa7PMEQj7Ty/HtDlzFOzI3fmLViTNXq2iAH+g39z 8dEptcL5Xno0mL1Ou6aUH8kz5aXunHN3XP6Hc+Uf3Hs3vBe7ZgOj7LLtZU+rF7euiAqA vHYZdfgW/iW0aXonGCuEkihm0iWTZaoROjQ6X4JhtGfv8NM1K2tq78eLykNBa8PEJ29t gEfg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g2si4126050pgf.680.2017.09.25.06.26.13; Mon, 25 Sep 2017 06:26:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934921AbdIYN0L (ORCPT + 26 others); 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 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id ABCBC1529; Mon, 25 Sep 2017 06:26:09 -0700 (PDT) Received: from leverpostej.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 318C53F483; Mon, 25 Sep 2017 06:26:08 -0700 (PDT) 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 1.9.1 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) \