Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp4574337imb; Wed, 6 Mar 2019 17:19:31 -0800 (PST) X-Google-Smtp-Source: APXvYqxLJGJsXBrJQvqOdbFMfSfFDo3C7HbGHqWLL9SyCsziImijs+BC4GD7XsKK8d018+XrYwRv X-Received: by 2002:a65:63c2:: with SMTP id n2mr8983190pgv.439.1551921571487; Wed, 06 Mar 2019 17:19:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551921571; cv=none; d=google.com; s=arc-20160816; b=uwPmNR6zs3n7DM6A6H943J7pbJMAl7PRhgbPIxxDSZy+Xnv+0XOYEMEyu3MSwNqDcB w4xGTqpAZdrC2BE0PHix8a7jufZdagRjCSMiLcnx4s+4gyFNohld8qg99fvT9xTD6/DQ NzH4Ggn6YXTW/plK1K0AfkWOnuvJKZDzfcsy1FYriCqwir+ksGqqhkEBolXenIDSC2Hx do6ORO3xo++gDDH/7ww1qbdRwpFks+EONzmen/dWW3lm3s8cEQ/3MH/NhNMQIZ8pmXfW /BYx03wDAXy3R9zCaE5j9pS0Y9gLwnT9XJARwYwbsa8HCf4OV3sELD/8jPj73Ak4F432 cdcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=W4qVrYWV/n1ivRdL2qH25FlWqe7J/irdbUsfkEjqc+4=; b=vOo1WdLE8hDXIsqaRRF+hmfAGPOWlO5f23IZq58uAFe9alQx2z11Ly3vX3gDtRUsDA GQpQqt5yk0rca3hEO/aa3BbqlxoyZQEllPm0YNepgzz9bdM4bEm5TgYKBVlVHd1CsvhO v5Je/08ap2cMqpxBs3E1eEF3oC3HJxsnJd0BmtQ+2osWDGPtbuBVAF2o1a+MFYrtvRQW /8z7imysELUJ7ejP9fE8q1UZU3PhP7QJNYETVMec9/Rvy9YVmjvk6EfDKUvXrMB3nJV8 O1ktKEXVs4l8wYmS1zSKtMR9cLKvmg0uVVDqBQjeAnJfP4ogeIrj5CJTrhnVKV3UWwN0 bCnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=iJ3dPGAf; 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 g4si2773929plt.215.2019.03.06.17.19.15; Wed, 06 Mar 2019 17:19:31 -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=pass header.i=@linux-foundation.org header.s=google header.b=iJ3dPGAf; 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 S1726216AbfCGBSf (ORCPT + 99 others); Wed, 6 Mar 2019 20:18:35 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:35690 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725793AbfCGBSf (ORCPT ); Wed, 6 Mar 2019 20:18:35 -0500 Received: by mail-lf1-f65.google.com with SMTP id h6so6151550lfc.2 for ; Wed, 06 Mar 2019 17:18:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=W4qVrYWV/n1ivRdL2qH25FlWqe7J/irdbUsfkEjqc+4=; b=iJ3dPGAfLy1mnGFufMPIpe8VYD9AVvbwLNzRcA6TEwUqiGRYLSBsZ5GPmaKj5hOoZh b654YSnZ6l38rLIIW/ChyiHqMXMWgI9MBKQ/Q9vYTMzJWOdw9CxNcUSTFTub7y/Ru5M6 mgzu658aTLg4cCp//xEYeoAYz3cEQsKx6M3Cw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=W4qVrYWV/n1ivRdL2qH25FlWqe7J/irdbUsfkEjqc+4=; b=el3t5yrU6TJdNJ5U9BRjM9vSTMXf9qpXLS4mP7ZVNvauepcXNlD3ACX/Xu9IUkcO87 MTfb63U+VEwuApTQPy49cnXngXg89kP3E7OJKu6GjHMV9UWjygwzJL1R5O/mt9B87UEI namGv9PErYbCdBvkXYivdGdwbZVqZwllG1x8H4xu5HJyYyVYlWIvrRZAcrV3PsPmDBoV BVY6SSUJzsvo8DREXBBla8AsJllWBt5nITRrym1cw2ebxpEcy93S7OX77smmMD1m1lPo 6NR8Ppa21prPFJ8tFcU5SyA3XfoGbvRaS3mAOU+/70AxvnHBny6QdwWT52PZXEr8c6L9 J0Cg== X-Gm-Message-State: APjAAAV4hYPIWQlJ+qXFKUOomdsSH9pFkdfT3+Bkh/Qqti5E90b8d1jE 7mqRIKT4JaCUjezKBxoLgqQCTMxqvGg= X-Received: by 2002:ac2:51b2:: with SMTP id f18mr5430011lfk.21.1551921512667; Wed, 06 Mar 2019 17:18:32 -0800 (PST) Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com. [209.85.208.182]) by smtp.gmail.com with ESMTPSA id f141sm580386lff.71.2019.03.06.17.18.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Mar 2019 17:18:32 -0800 (PST) Received: by mail-lj1-f182.google.com with SMTP id g80so12673479ljg.6 for ; Wed, 06 Mar 2019 17:18:32 -0800 (PST) X-Received: by 2002:a2e:9786:: with SMTP id y6mr3687996lji.79.1551921209404; Wed, 06 Mar 2019 17:13:29 -0800 (PST) MIME-Version: 1.0 References: <20190301140348.25175-1-will.deacon@arm.com> <20190301140348.25175-2-will.deacon@arm.com> <1551575210.6lwpiqtg5k.astroid@bobo.none> <87ef7n7x9v.fsf@concordia.ellerman.id.au> <87k1hbv7ba.fsf@concordia.ellerman.id.au> In-Reply-To: <87k1hbv7ba.fsf@concordia.ellerman.id.au> From: Linus Torvalds Date: Wed, 6 Mar 2019 17:13:13 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 01/20] asm-generic/mmiowb: Add generic implementation of mmiowb() tracking To: Michael Ellerman Cc: Nicholas Piggin , linux-arch , Will Deacon , Andrea Parri , Arnd Bergmann , Benjamin Herrenschmidt , Rich Felker , David Howells , Daniel Lustig , Linux List Kernel Mailing , "Maciej W. Rozycki" , Ingo Molnar , Palmer Dabbelt , Paul Burton , "Paul E. McKenney" , Peter Zijlstra , Alan Stern , Tony Luck , Yoshinori Sato Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 6, 2019 at 4:48 PM Michael Ellerman wrote: > > It's a bit hard to grep for, but I did find one case: > > static void netxen_nic_io_write_128M(struct netxen_adapter *adapter, > void __iomem *addr, u32 data) > { > read_lock(&adapter->ahw.crb_lock); > writel(data, addr); > read_unlock(&adapter->ahw.crb_lock); > } > > It looks like that driver is using the rwlock to exclude cases that can > just do a readl()/writel() (readers) vs another case that has to reconfigure a > window or something, before doing readl()/writel() and then configuring > the window back. So that seems like a valid use for a rwlock. Oh, it's actually fairly sane: the IO itself is apparently windowed on that hardware, and the *common* case is that you'd access "window 1". So if everybody accesses window 1, they can all work in parallel - the read case. But if somebody needs to access any of the other special IO windows, they need to take the write lock, then change the window pointer to the window they want to access, do the access, and then set it back to the default "window 1". So yes. That driver very much relies on exclusion of the IO through an rwlock. I'm guessing nobody uses that hardware on Power? Or maybe the "window 1 is common" is *so* common that the other cases basically never happen and don't really end up ever causing problems? [ Time passes, I look at it ] Actually, the driver probably works on Power, because *setting* the window isn't just a write to the window register, it's always serialized by a read _from_ the window register to verify that the write "took". Apparently the hardware itself really needs that "don't do accesses to the window before I've settled". And that would basically serialize the only operation that really needs serialization, so in the case of _that_ driver, it all looks safe. Even if it's partly by luck. > > Perhaps more importantly, what about sleeping locks? When they > > actually *block*, they get the barrier thanks to the scheduler, but > > you can have a nice non-contended sequence that never does that. > > Yeah. > > The mutex unlock fast path is just: Yup. Both lock/unlock have fast paths that should be just trivial atomic sequences. But the good news is that *usually* device IO is protected by a spinlock, since you almost always have interrupt serialization needs too whenever you have any sequence of MMIO that isn't just some "write single word to start the engine". So the "use mutex to serialize IO" may be fairly unusual. Linus