Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1694361imu; Thu, 17 Jan 2019 01:34:03 -0800 (PST) X-Google-Smtp-Source: ALg8bN4k69KZXgE5kPmnenpMvm/LKzODQPntsn4mt4vpktUpj9f0bvMU94eVy4LiVaKeKBdeorW4 X-Received: by 2002:a17:902:27a8:: with SMTP id d37mr14427382plb.182.1547717643458; Thu, 17 Jan 2019 01:34:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547717643; cv=none; d=google.com; s=arc-20160816; b=QLVLxq1xsWRpdfnWcc5TEI0sF3n9bzHHSmpKCplgev04cnXqZ6QrlqJCbjVsMWC9Ju NNqRXD9IzKrnPbUr+vXzoLri3fovl5xdv+bjNJo/XkyGRh6cKY8/OWBU/LxpBYZ3oLQS 6uoxueMBNsG8ZiMzXyA76Y1OWGdMTXo0tl1EBWAQPVIicCeruTWL0Xd0+RJBf3UklT8o 5IFzpTbUcFIARfqEnXK/1C9K2j2Vm1P0r1X0r3h6XRZTYmSy77SopsCOgCichrZAkH1H IEJrVN2nPQIhrhg8cfCljTGtYzOAPJRx1dfeJuxML/d+xJLAHWTXNG8s9E6xbKp8y2TB Ju/Q== 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=zGyAna2Dl1h07bAPr3fca2q6SGrMBnxgn0zuhAtSdwE=; b=kOQk0J405AQTB6X+HvTB26g5cs1+x66GunOOgtyjFJ1+6Lj4NlG1fwadaKkXD/6XTh 0o7fmjXxmqvb8qjT9GuoVfLsv9I/NuZ+tgrwrDmOKjvoFyabJSrl8hebFRua32o6KayV IdojsG5DYrF+By+v1SgMo5AL9se/1xfo/OQn/FUUlbrHcnrfbK8AGIIOcTZND6+DyyIN INoiSWl7viKIV2+Ojl64ndzUsx0kBGJh9bj5cvBMzBjlNyy9v1a2sPz62/o8HZjhVJMj 6w7mMyzzzlZdmUoQCPRufKzyFy43l3ISC2pbaciUpssgtAVI/qeQZmwFEyeqdQltik6s Nazg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HEsMOHrU; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v16si1166855pgg.290.2019.01.17.01.33.47; Thu, 17 Jan 2019 01:34:03 -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=@linaro.org header.s=google header.b=HEsMOHrU; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729110AbfAQICv (ORCPT + 99 others); Thu, 17 Jan 2019 03:02:51 -0500 Received: from mail-io1-f66.google.com ([209.85.166.66]:34030 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726196AbfAQICu (ORCPT ); Thu, 17 Jan 2019 03:02:50 -0500 Received: by mail-io1-f66.google.com with SMTP id b16so7125525ior.1 for ; Thu, 17 Jan 2019 00:02:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zGyAna2Dl1h07bAPr3fca2q6SGrMBnxgn0zuhAtSdwE=; b=HEsMOHrU+BUCVJkbjxCoSHvj7aRRm4WHhMBt9q1LuXgpfMqUsxqaFvwI2cmJwk5uHm vlLcaXpKscjYuHoJQmeSZs7fmzvd8XihEFxpmGxFZTWx5og1OY1NQ4hGP2gAWIIpFw21 Kyci6U6QJ7vQm5mAhrQ1piv8jQiw099hLYerc= 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=zGyAna2Dl1h07bAPr3fca2q6SGrMBnxgn0zuhAtSdwE=; b=tkW6KMqVN5cP4CDLIdUMbv02H84WRnV4bQ7wu1ydw82FNqyKlZvDjXDKM48qw2dJo2 vCjgh2PyemawINAAl8AxvnOLHZOYCHEOebmL4jMQmgTG4WYYXVjAevWdvzTDug0nMm7j ajhYoqdsXdq2TegtUrm0pTCzoisv0Z6T5niwc2b4iNAWa808diV0X8VgMJnUP2n2woqU 36VvRjmrCt7ygLnQrYd5hOynQa+OyxyucyHTySAsJpvLZMYxSnW/DjLI9pcpwSIRY2Kb vTm8p4JkhfjlNoO0qssQBnjq8grFLitXoaS9irDrRruFvo7X394e52WzmrrmMpOYXjGK Ww2Q== X-Gm-Message-State: AJcUukesaMiify9qeVNMq3BQkdpMYZXZal0jTKsjSgMRP9/jW8Hy5KV0 QryHPfaJ6GRaHcXTYqNQYKjNvjQfS0e79nHzQQf74g== X-Received: by 2002:a6b:5d01:: with SMTP id r1mr6691822iob.170.1547712169544; Thu, 17 Jan 2019 00:02:49 -0800 (PST) MIME-Version: 1.0 References: <20190110072841.3283-1-ard.biesheuvel@linaro.org> <5d8135de-80fe-9c0e-2206-ecb809f64cdb@daenzer.net> <55facfb9-92af-86b8-40e9-d63b887b5592@amd.com> <9f956898-7973-98ee-6bf1-e1d445e9d365@amd.com> <20190114191350.GA29600@fuggles.cambridge.arm.com> <20190114193548.GB29600@fuggles.cambridge.arm.com> <87a7k2yx66.fsf@concordia.ellerman.id.au> <9dc27cbf-e109-0c32-fc92-6fce1b224cda@amd.com> <9d706807c93f88bc850153ae20ea28e6502e0aac.camel@kernel.crashing.org> In-Reply-To: <9d706807c93f88bc850153ae20ea28e6502e0aac.camel@kernel.crashing.org> From: Ard Biesheuvel Date: Thu, 17 Jan 2019 09:02:38 +0100 Message-ID: Subject: Re: [RFC PATCH] drm/ttm: force cached mappings for system RAM on ARM To: Benjamin Herrenschmidt Cc: "Koenig, Christian" , Michael Ellerman , Will Deacon , =?UTF-8?Q?Michel_D=C3=A4nzer?= , Linux Kernel Mailing List , Carsten Haitzler , David Airlie , dri-devel , "Huang, Ray" , "Zhang, Jerry" , linux-arm-kernel , =?UTF-8?Q?Bernhard_Rosenkr=C3=A4nzer?= 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 Thu, 17 Jan 2019 at 07:07, Benjamin Herrenschmidt wrote: > > On Wed, 2019-01-16 at 08:47 +0100, Ard Biesheuvel wrote: > > > As far as I know on x86 it doesn't, so when you have an un-cached page > > > you can still access it with a snooping DMA read/write operation and > > > don't cause trouble. > > > > > > > I think it is the other way around. The question is, on an otherwise > > cache coherent device, whether the NoSnoop attribute set by the GPU > > propagates all the way to the bus so that it bypasses the caches. > > On powerpc it's ignored, all DMA accesses will be snooped. But that's > fine regardless of whether the memory was mapped cachable or not, the > snooper will simply not find anything if not. I *think* we only do > cache inject if the line already exists in one of the caches. > Others should correct me if I am wrong, but arm64 SoCs often have L3 system caches, and I would expect inbound transactions with writeback write-allocate (WBWA) attributes to allocate there. > > On x86, we can tolerate if this is not the case, since uncached memory > > accesses by the CPU snoop the caches as well. > > > > On other architectures, uncached accesses go straight to main memory, > > so if the device wrote anything to the caches we won't see it. > > Well, on all powerpc implementations that I am aware of at least (dunno > about ARM), they do, but we don't have a problem because I don't think > the devices can/will write to the caches directly unless a > corresponding line already exists (but I might be wrong, we need to > double check all implementations which is tricky). > > I am not aware of any powerpc chip implementing NoSnoop. > Do you have any history on why this optimization is disabled for power unless CONFIG_NOT_CACHE_COHERENT is set? That also begs the question how any of this is supposed to work with non-cache coherent DMA. The code appears to always assume cache coherent, and provide non-cache coherent as an optimization if dma_arch_can_wc_memory() returns true. So I wonder if that helper should take a struct device pointer instead, and return true for non-cache coherent devices. > > So to use this optimization, you have to either be 100% sure that > > NoSnoop is implemented correctly, or have a x86 CPU. > > > > > > The old hack of using non-cached mapping to avoid snoop cost in AGP and > > > > others is just that ... an ugly and horrible hacks that should have > > > > never eventuated, when the search for performance pushes HW people into > > > > utter insanity :) > > > > > > Well I agree that un-cached system memory makes things much more > > > complicated for a questionable gain. > > > > > > But fact is we now have to deal with the mess, so no point in > > > complaining about it to much :) > > > > > > > Indeed. I wonder if we should just disable it altogether unless CONFIG_X86=y > > The question is whether DMA from a device can instanciate cache lines > in your system. This a system specific rather than architecture > specific question I suspect... > The ARM architecture permits it, afaict, and write-allocate is a hint so the implementation is free to ignore it, whether it is set or cleared.