From patchwork Fri Nov 14 19:19:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 40867 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f69.google.com (mail-ee0-f69.google.com [74.125.83.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DE2B9240ED for ; Fri, 14 Nov 2014 19:19:45 +0000 (UTC) Received: by mail-ee0-f69.google.com with SMTP id c41sf11104556eek.0 for ; Fri, 14 Nov 2014 11:19:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=a2KDO++8MjHWcCFi97sPAJlnVzWj88hBc/72aHDiDrc=; b=kbVPpEdqRyPqQpf6YVJHiW5uz8p64TpZ4gbNMHuiKKmR4uhpOnMmotaYVCeTI0ctqD Ks0vkotNdQYGeIcylXAeJm/Y073jLjtXsQnyUPv4jetoufLUDcjidU01Cyrtcyu2Bz/l zHerMQHEA/fDnCwgsBaMq9779iSjC4PV4fybBgGSdBvJ6/VBA/QSDtp6ZPCb9ArIvhl3 COfykyFvK2umoZy/V91wL0hjfcjutTMMeeUySHoZ4gUrMM3WKtk/EjQhPctWHsQe2GtY ryZJiO6IM2bpbFNMIXZsKOh0GEo1P1U+wsdy/a7RmCtE2xTbjN/Z4TybQdWqqhC0Sm0T BR/Q== X-Gm-Message-State: ALoCoQl+9KEbArhO5oGZefd2MNs/uF0oQ9Z+3sIuAnzpYcWw80mGmNKAx7TKh7XPyQfD3SiFcvw0 X-Received: by 10.180.19.226 with SMTP id i2mr1416307wie.5.1415992785086; Fri, 14 Nov 2014 11:19:45 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.197.100 with SMTP id it4ls997963lac.7.gmail; Fri, 14 Nov 2014 11:19:44 -0800 (PST) X-Received: by 10.112.73.103 with SMTP id k7mr9933991lbv.41.1415992784366; Fri, 14 Nov 2014 11:19:44 -0800 (PST) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id kt1si14138079lac.41.2014.11.14.11.19.44 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 14 Nov 2014 11:19:44 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by mail-lb0-f171.google.com with SMTP id b6so13360331lbj.16 for ; Fri, 14 Nov 2014 11:19:44 -0800 (PST) X-Received: by 10.112.202.104 with SMTP id kh8mr9989498lbc.46.1415992784210; Fri, 14 Nov 2014 11:19:44 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp821923lbc; Fri, 14 Nov 2014 11:19:43 -0800 (PST) X-Received: by 10.70.88.233 with SMTP id bj9mr12339528pdb.23.1415992782017; Fri, 14 Nov 2014 11:19:42 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id dp4si28961491pbb.251.2014.11.14.11.19.41 for ; Fri, 14 Nov 2014 11:19:42 -0800 (PST) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161792AbaKNTTj (ORCPT + 26 others); Fri, 14 Nov 2014 14:19:39 -0500 Received: from mail-ie0-f172.google.com ([209.85.223.172]:38039 "EHLO mail-ie0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161586AbaKNTTi (ORCPT ); Fri, 14 Nov 2014 14:19:38 -0500 Received: by mail-ie0-f172.google.com with SMTP id ar1so3809779iec.31 for ; Fri, 14 Nov 2014 11:19:37 -0800 (PST) X-Received: by 10.50.119.3 with SMTP id kq3mr8299574igb.46.1415992777550; Fri, 14 Nov 2014 11:19:37 -0800 (PST) Received: from localhost.localdomain (c-24-245-18-91.hsd1.mn.comcast.net. [24.245.18.91]) by mx.google.com with ESMTPSA id qk10sm1764879igc.12.2014.11.14.11.19.36 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 14 Nov 2014 11:19:36 -0800 (PST) From: Alex Elder To: akpm@linux-foundation.org Cc: bobby.prani@gmail.com, pmladek@suse.cz, jack@suse.cz, mcgrof@suse.com, rostedt@goodmis.org, joe@perches.com, linux-kernel@vger.kernel.org Subject: [PATCH] printk: drop logbuf_cpu volatile qualifier Date: Fri, 14 Nov 2014 13:19:31 -0600 Message-Id: <1415992771-9071-1-git-send-email-elder@linaro.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: elder@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Pranith Kumar posted a patch in which removed the "volatile" qualifier for the "logbuf_cpu" variable in vprintk_emit(). https://lkml.org/lkml/2014/11/13/894 In his patch, he used ACCESS_ONCE() for all references to that symbol to provide whatever protection was intended. There was some discussion that followed, and in the end Stephen Rostedt concluded that not only was "volatile" not needed, neither was it required to use ACCESS_ONCE(). I offered an elaborate description that concluded Stephen was right, and Pranith asked me to submit an alternative patch. And this is it. The basic reason "volatile" is not needed is that "logbuf_cpu" has static storage duration, and vprintk_emit() is an exported interface. This means that the value of logbuf_cpu must be read from memory the first time it is used in a particular call of vprintk_emit(). The variable's value is read only once in that function, when it's read it'll be the copy from memory (or cache). In addition, the value of "logbuf_cpu" is only ever written under protection of a spinlock. So the value that is read is the "real" value (and not an out-of-date cached one). If its value is not UINT_MAX, it is the current CPU's processor id, and it will have been last written by the running CPU. Reported-by: Pranith Kumar Fix-suggested-by: Steven Rostedt Signed-off-by: Alex Elder Reviewed-by: Jan Kara --- Note!!! I am not able to stress test this patch. kernel/printk/printk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index ced2b84..fefc8d0 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1627,7 +1627,7 @@ asmlinkage int vprintk_emit(int facility, int level, int printed_len = 0; bool in_sched = false; /* cpu currently holding logbuf_lock in this function */ - static volatile unsigned int logbuf_cpu = UINT_MAX; + static unsigned int logbuf_cpu = UINT_MAX; if (level == SCHED_MESSAGE_LOGLEVEL) { level = -1;