Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1392779ybf; Thu, 27 Feb 2020 10:05:39 -0800 (PST) X-Google-Smtp-Source: APXvYqxOwjJZPbL3UxfKoBzevwtOvjPKzbyeTDczJyIAxmhVpMC+8H1lP8INQfyPsAyZTvlZTm67 X-Received: by 2002:a9d:75da:: with SMTP id c26mr150325otl.40.1582826739723; Thu, 27 Feb 2020 10:05:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582826739; cv=none; d=google.com; s=arc-20160816; b=iwllLkNjFYMn6SDk4aCi9xFtktnLdSjyQzgS/gB2jsfOl1qUT1Bj559JfF22vjnRql r0x2Pq/ksFeIvDVZMHpJXFj3me+CEO3pCyQ80XQ0eKgo90fVd5LwXHvWkJbmSf22adnl KDs1EV8RHM+ZMGMhrT03vhPUGrd5P4h0Gt26czYpVbbvDsvaPsrDAEnlSlo0KD7WQL9O jIO3RA56yOLhiRo/sdzEIjom+dnKgRJh85fPFmorMRz12LZzJ/3xzWrr22c9ocggURFw xJ7uyJ4qvQ2m0Ltj4ARsJqCJzLY+8GfU4/g+ph2xE/Eb6S9kwDDSEhsVCKSM0Mm2/88p 4hjg== 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=YVEntATD8Di4X+bfE0q+dQjUPZodyWiwMumJsgAjImQ=; b=weHI1nYovH3AFP0WKb5qfYsyAuKIYQsKXrzvDg3aPCpJ6eG05F8ThKoYwSb8osDT4v 3h7aioSkObE8Zk46Jdr/Sisuo+NHr4bck7ECcrRMFp2renhCCnHxgQCzv/xQDisR9MzH HlOPBH9kf+xNQB1MRHHT71KTrIz37lmhAI+MSWiyQSlrMPwd0gZIxJQsZ5tAog5ngqh3 jOFyTXaiJC3lcxr2zJQ3yeAO0YkkIA1Sy/6joMNlinWz3oxj2q9bgPyu/EJiJ6qYZC4W tAhtWP9ajY4IM570FGchc3/bKCqom3/bIeV6/AnlrTferIZxbGTNB5+S3x9K2nqPBVng 2JWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=RAltTZst; 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 k3si2166248otn.288.2020.02.27.10.05.26; Thu, 27 Feb 2020 10:05:39 -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=@ziepe.ca header.s=google header.b=RAltTZst; 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 S1730567AbgB0SDt (ORCPT + 99 others); Thu, 27 Feb 2020 13:03:49 -0500 Received: from mail-qk1-f194.google.com ([209.85.222.194]:40423 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730545AbgB0SDs (ORCPT ); Thu, 27 Feb 2020 13:03:48 -0500 Received: by mail-qk1-f194.google.com with SMTP id m2so230550qka.7 for ; Thu, 27 Feb 2020 10:03:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=YVEntATD8Di4X+bfE0q+dQjUPZodyWiwMumJsgAjImQ=; b=RAltTZstLeabLiJ0d66x7j4b8d0dFG+sPOHfpbO/cFKDi0l5MP5SaBmzQZcj23Dj9O F/bYYNBZZSSfyS9/dujI6RC7S6GQGiGhjfoRC4Je5Ph5T17ppPj/nNg6eK7g8v4ebWzu Qxmk3XbPh4QJMBWSZz4NrK//VIcI+eMAy0MaVJAPx5AhdQtsNg6OJfWlFI3uTppHsXSP NLDKJ/17oMjJmVhx6/pQNGEX+CmviRc1utdWSmUNrTHklbQUwh86mk+awHvAFbaKoddd 0oAlTI+2vm+ko8Vd1wYitYFGuU7IYpDc+5ksP1iJZ4Sf+eRw2yMQhLqeo1YoqRFOoTVh Z2sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=YVEntATD8Di4X+bfE0q+dQjUPZodyWiwMumJsgAjImQ=; b=m0rJUqApZgV5x/ml6gdTXfIrb3I5hBJghccxsTfs5n2t/dVQ4KA38xWQdN1DAtsF7n uy67J/A+NMP931RQcfXarlD/CjJyIgp07qh7eux1t/tiqAk07LLGxMq65J3bez46zGlZ 8x6nBAlIykc9IPhIhNqiCnidYSRcg39l7O2hhX6xq/LJxVbVTDvYgQvI0eEnt7sDkTEd ot2AvhBdsY/OIjjVkaVG4FFom0aJVq2Ltk3Ki5sPYHDzqA3u/aGN/xsqpfHy9xzisxQc XQo/ZgtBv9uUjK5GeWH/kElaTC6vsqHIWhbWq6nXB09XUtJlyugChpQsBBffeafKexAU LyHA== X-Gm-Message-State: APjAAAX/4VvLlfLiAM/aM5oUjuTp4xmzYxohFI/ISS8CsYn6unZ2dTnT /C2AGu2zO0WUKJK/EG+d3a5dHg== X-Received: by 2002:a37:4e53:: with SMTP id c80mr533140qkb.58.1582826627303; Thu, 27 Feb 2020 10:03:47 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-142-68-57-212.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.68.57.212]) by smtp.gmail.com with ESMTPSA id e64sm3551886qtd.45.2020.02.27.10.03.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 27 Feb 2020 10:03:46 -0800 (PST) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1j7NVi-0008Pb-Fb; Thu, 27 Feb 2020 14:03:46 -0400 Date: Thu, 27 Feb 2020 14:03:46 -0400 From: Jason Gunthorpe To: Dan Williams Cc: Logan Gunthorpe , Linux Kernel Mailing List , Linux ARM , linux-ia64@vger.kernel.org, linuxppc-dev , linux-s390 , Linux-sh , platform-driver-x86@vger.kernel.org, Linux MM , Michal Hocko , David Hildenbrand , Andrew Morton , Christoph Hellwig , Catalin Marinas , Will Deacon , Benjamin Herrenschmidt , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Eric Badger Subject: Re: [PATCH v3 0/7] Allow setting caching mode in arch_add_memory() for P2PDMA Message-ID: <20200227180346.GM31668@ziepe.ca> References: <20200221182503.28317-1-logang@deltatee.com> <20200227171704.GK31668@ziepe.ca> <20200227174311.GL31668@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 27, 2020 at 09:55:04AM -0800, Dan Williams wrote: > On Thu, Feb 27, 2020 at 9:43 AM Jason Gunthorpe wrote: > > > > On Thu, Feb 27, 2020 at 10:21:50AM -0700, Logan Gunthorpe wrote: > > > > > > > > > On 2020-02-27 10:17 a.m., Jason Gunthorpe wrote: > > > >> Instead of this, this series proposes a change to arch_add_memory() > > > >> to take the pgprot required by the mapping which allows us to > > > >> explicitly set pagetable entries for P2PDMA memory to WC. > > > > > > > > Is there a particular reason why WC was selected here? I thought for > > > > the p2pdma cases there was no kernel user that touched the memory? > > > > > > Yes, that's correct. I choose WC here because the existing users are > > > registering memory blocks without side effects which fit the WC > > > semantics well. > > > > Hm, AFAIK WC memory is not compatible with the spinlocks/mutexs/etc in > > Linux, so while it is true the memory has no side effects, there would > > be surprising concurrency risks if anything in the kernel tried to > > write to it. > > > > Not compatible means the locks don't contain stores to WC memory the > > way you would expect. AFAIK on many CPUs extra barriers are required > > to keep WC stores ordered, the same way ARM already has extra barriers > > to keep UC stores ordered with locking.. > > > > The spinlocks are defined to contain UC stores though. > > How are spinlocks and mutexes getting into p2pdma ranges in the first > instance? Even with UC, the system has bigger problems if it's trying > to send bus locks targeting PCI, see the flurry of activity of trying > to trigger faults on split locks [1]. This is not what I was trying to explain. Consider static spinlock lock; // CPU DRAM static idx = 0; u64 *wc_memory = [..]; spin_lock(&lock); wc_memory[0] = idx++; spin_unlock(&lock); You'd expect that the PCI device will observe stores where idx is strictly increasing, but this is not guarenteed. idx may decrease, idx may skip. It just won't duplicate. Or perhaps wc_memory[0] = foo; writel(doorbell) foo is not guarenteed observable by the device before doorbell reaches the device. All of these are things that do not happen with UC or NC memory, and are surprising violations of our programming model. Generic kernel code should never touch WC memory unless the code is specifically designed to handle it. Jason