Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3418057imu; Mon, 10 Dec 2018 01:41:07 -0800 (PST) X-Google-Smtp-Source: AFSGD/Xh5U12s7CzCsNcQf/jFhjN7ixxuTK3mmQbkTPBBpwOtHY2XcB5TOmN11lV+rPZoPvlCr7J X-Received: by 2002:a17:902:7481:: with SMTP id h1mr11658055pll.341.1544434867427; Mon, 10 Dec 2018 01:41:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544434867; cv=none; d=google.com; s=arc-20160816; b=RyWBn5OhyZE1DDZFHy5BABta46IYMzLkGU2WCInuDA4dhj4XUS0BnnRcboPydpOsrs NlWLbd0D4Z/9N0iwytcT3UMq+F4YVf0w722fVLl4HZQVK5RNiSPBmOdA9eQu0DlDAHCb WJM+ldWtvX/bU8HE4cL7jIrtQHvZRoUxqvfgmikuMJbhGXKy6XKBUP8QdFn1Okuavflt lGei1bVew6rI07HjW/N3jML4PA+hHM8cxQI5V75lfxutpabPX7uvKA6Gk1bgv55cQBC/ tFEVqWo8NFC64cLwiJyrZnIaImzCW4m1L2fwluKGULZ+bOLrTm47SEWWoL9t3MDTOqxI 2R9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=7NJVooFTIsQ1sLkf0iscEhELwDGD/ToFRglzg8miKq0=; b=vdUeLGNYlSeLACS86cL+X7ZU/NvFdMe7o4ODAWOLsQFasKTwd/E/noNxcCO6cRoM3d xHC1GpVFWmWYO5EpwBQzazmmxELNJPTEFsoW2tdwc/19ATlQZ+5dnvTKHVHdfq45hJ0K TAqE5mMaF+GCbElDfft8XwHTDEo26/yKo8lFfi9zmnLnIf0uOG51ryoYH6hwT05cmpu+ V0zJxf0/mm8TwT4J8x4deeDQh/omlsUzqtF9xDNSHsBX0Mb3JCVxN7VCn2U621VkAR3a nw09C2RyHuzjcNMY2PlKTHfXM9Yd9i+bgIlYQHXOse12Fi1FAEDmaXkdEKgE++92CcCn ODqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=Iiyj8+Qn; 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 x141si9664569pgx.266.2018.12.10.01.40.51; Mon, 10 Dec 2018 01:41:07 -0800 (PST) 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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=Iiyj8+Qn; 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 S1726697AbeLJIzl (ORCPT + 99 others); Mon, 10 Dec 2018 03:55:41 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:49372 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726572AbeLJIzl (ORCPT ); Mon, 10 Dec 2018 03:55:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=7NJVooFTIsQ1sLkf0iscEhELwDGD/ToFRglzg8miKq0=; b=Iiyj8+QnmYLqIGGVuq//ASid1 FgobeVzTq1ckKSaJ7bRoyUhcT3ZNDVmh6qHg5+xRraqRVuMWRX1MPc9bJV5fjtANCXXXudqtnr3wa Stj0H1iaezgqN8EfWOorQt8MZiMOrFmKsDvK6IlMHD+wKHVAvxCpf1gkkTUNibCMqZG2nHZ+WFm3w TwuGhVKRnZrtIborVj7qx5PQP4L+2XXMkrwlZV3+4v7SIAOXKOGrfUK6Q88nMCjIGL2cemBOodsJ0 mLVJpOHOR+k9ecv4W5Ao+iPqeqmuJxzPqHbc5jIXxANkztnJqlsDaBqRSvd8/bPYktG9IiAMeLkcr 1uZGkqZ3A==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gWHLj-0002MZ-1S; Mon, 10 Dec 2018 08:55:35 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 56C20207261A3; Mon, 10 Dec 2018 09:55:32 +0100 (CET) Date: Mon, 10 Dec 2018 09:55:32 +0100 From: Peter Zijlstra To: Nadav Amit Cc: Matthew Wilcox , Vlastimil Babka , Linux-MM , LKML , X86 ML , Ingo Molnar , Thomas Gleixner , Andy Lutomirski Subject: Re: Should this_cpu_read() be volatile? Message-ID: <20181210085532.GG5289@hirez.programming.kicks-ass.net> References: <20181203224920.GQ10377@bombadil.infradead.org> <20181206102559.GG13538@hirez.programming.kicks-ass.net> <55B665E1-3F64-4D87-B779-D1B4AFE719A9@gmail.com> <20181207084550.GA2237@hirez.programming.kicks-ass.net> <20181208105220.GF5289@hirez.programming.kicks-ass.net> <5DE00B41-835C-4E68-B192-2A3C7ACB4392@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5DE00B41-835C-4E68-B192-2A3C7ACB4392@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Dec 09, 2018 at 04:57:43PM -0800, Nadav Amit wrote: > > On Dec 8, 2018, at 2:52 AM, Peter Zijlstra wrote: > > My patch proposed here: > > > > https://marc.info/?l=linux-mm&m=154409548410209 > > > > would actually fix that one I think, preempt_count() uses > > raw_cpu_read_4() which will loose the volatile with that patch. > I tested the patch you referenced, and it certainly improves the situation > for reads, but there are still small and big issues lying around. I'm sure :-(, this has been 'festering' for a long while it seems. And esp. on x86 specific code, where for a long time we all assumed the various per-cpu APIs were in fact the same (which turns out to very much not be true). > The biggest one is that (I think) smp_processor_id() should apparently use > __this_cpu_read(). Agreed, and note that this will also improve code generation on !x86. However, I'm not sure the current !debug definition: #define smp_processor_id() raw_smp_processor_id() is actually correct. Where raw_smp_processor_id() must be this_cpu_read() to avoid CSE, we actually want to allow CSE on smp_processor_id() etc.. > There are all kind of other smaller issues, such as set_irq_regs() and > get_irq_regs(), which should run with disabled interrupts. They affect the > generated code in do_IRQ() and others. > > But beyond that, there are so many places in the code that use > this_cpu_read() while IRQs are guaranteed to be disabled. For example > arch/x86/mm/tlb.c is full with this_cpu_read/write() and almost(?) all > should be running with interrupts disabled. Having said that, in my build > only flush_tlb_func_common() was affected. This all feels like something static analysis could help with; such tools would also make sense for !x86 where the difference between the various per-cpu accessors is even bigger.