Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6416515imu; Mon, 21 Jan 2019 08:32:15 -0800 (PST) X-Google-Smtp-Source: ALg8bN5YUao44nke0S4MYvun6XCkjZ0BNWs0Y932EgOAgmlJ639J2az2Z9Mfa/OGgvxQALU8pMrZ X-Received: by 2002:a62:fb07:: with SMTP id x7mr30106041pfm.71.1548088335626; Mon, 21 Jan 2019 08:32:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548088335; cv=none; d=google.com; s=arc-20160816; b=CRYgETFO3I1T1y15F7nMBiZsefo3ShaLN6f3WSsAI69KKWxqLMw4GWleSPhntjymZw zBW6urpMuHBUFPi44SPAZNP5YI5iHnwkCVSVjOAi2EO1c8L83PXpD3/FDmrmdfaWmtXA SabVuYgemAio4EhHRo8nZH0GGKPqlKAX+wJncKOaOJV8VrlgFMQh/g4GPZ2GlfspWes+ aNusSKKhdBAxq6O6p3JKj9sW5GYTFYyaxcbaHtKR8rFLzcVZ7uoZNxrvl+XOagIskMnI +RLqnMkcHOcc8CxekkZ2nuLmSa3Lt4MpQmMgwKMoeGbBn91Mwaf/vVux3vVsEMx+cWE0 oLtw== 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=eADEIz0iwznb0TSre1LvJOXMgvWd8rOdZ80eJVALlOs=; b=EbC2koyKX4tJcJvX0G3Dfg2/8m/+NsFR7ChOJMg3lS7wIvQfVGhUX4VJUKAL1NRVQ5 LWZ15f33J38CqdM2Iv89gZJjEZBojVoCyx0alxqGgLJgL590GlIqTlGFWXHlOOHntqgT LxdxUkkSUlG6XZe1H1i3XemQyil80Gzqb0rXTAfVoaNo6l/VmCqlg7zji93AaK4MNDV8 FuSqcz7xWc+sO8WsAyxgxLF3HVjEwrtDGDDgR1a52OCWSM4yJsJ1dQ9QbdaIf66GWrIQ pSQS28FrF5zPO+yYO+7tAUOWXQxqvehAvO5WzAeiZhY5eQ/bfgYw3ZPz7QE8umAR0bJ6 5j1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="IgcA+zu/"; 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 d4si12466038pfa.150.2019.01.21.08.31.58; Mon, 21 Jan 2019 08:32:15 -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="IgcA+zu/"; 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 S1730546AbfAUQaN (ORCPT + 99 others); Mon, 21 Jan 2019 11:30:13 -0500 Received: from mail-io1-f65.google.com ([209.85.166.65]:39956 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729580AbfAUQaM (ORCPT ); Mon, 21 Jan 2019 11:30:12 -0500 Received: by mail-io1-f65.google.com with SMTP id k2so16828089iog.7 for ; Mon, 21 Jan 2019 08:30:11 -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=eADEIz0iwznb0TSre1LvJOXMgvWd8rOdZ80eJVALlOs=; b=IgcA+zu/3zhC1gBAyy/mGl+AwjUvef+boE7Zb66yOFc2qibmGG0Jh5Z74HkztTdSgB jZasnWUu68LFhIBBQvxmkQgpvppzuKDU+u7crf4NfP1kjSK+PUB1MInPaxsqCRBF7MYP SCLHk/2buYs5nhGNikNiUQcrczAJtZqnnKZCg= 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=eADEIz0iwznb0TSre1LvJOXMgvWd8rOdZ80eJVALlOs=; b=N2JKhJgAWPUIs4pZkRrG9l2E7nYQXuzJwtfaimRziIdqqqc5Bbkb37KZIMRktAVZ3X wPU7DIf6gnqNRRhOqFOKmWGNG9zsetnJNz7nfRigxWH9XN8CrUWye7uiC1xDmyVX3IOt KIUrmoh6MkndAYCJyCzmjNWxd/bHYe372QegMUWru79TQHZHydM4A+YG2sU8jEdUmKn7 sGuWnLgyFNwg+Ss/1kkP6/pzkhK6faDOrVOHVxWoBnKXrpp2VgCefPjdrHCcLUow468H 2qcC0IHTsPOAAnHl65fl1tOE3NWYjDMTJtpo5GkNqpHXdLjTSyscCQh0SO9a6k+SYOH9 BX0Q== X-Gm-Message-State: AJcUukeHAZ6H4VqJRJ6NoGaWyIsVUOPk7Og/bUC/p2YCsZVdp0PYcbkb 7jkzsG3VGOf/8DzEyg9qp5NGBlA3TtkPIi3eXNP9pQ== X-Received: by 2002:a6b:5d01:: with SMTP id r1mr16148051iob.170.1548088211443; Mon, 21 Jan 2019 08:30:11 -0800 (PST) MIME-Version: 1.0 References: <20190121100617.2311-1-ard.biesheuvel@linaro.org> <20190121150734.GA30582@infradead.org> <20190121155908.GA8084@infradead.org> <20190121162238.GA17651@infradead.org> In-Reply-To: <20190121162238.GA17651@infradead.org> From: Ard Biesheuvel Date: Mon, 21 Jan 2019 17:30:00 +0100 Message-ID: Subject: Re: [RFC PATCH] drm: disable WC optimization for cache coherent devices on non-x86 To: Christoph Hellwig Cc: linux-arm-kernel , dri-devel , Linux Kernel Mailing List , amd-gfx@lists.freedesktop.org, Christian Koenig , Alex Deucher , David Zhou , Huang Rui , Junwei Zhang , Michel Daenzer , David Airlie , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Sean Paul , Michael Ellerman , Benjamin Herrenschmidt , Will Deacon 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 Mon, 21 Jan 2019 at 17:22, Christoph Hellwig wrote: > > On Mon, Jan 21, 2019 at 05:14:37PM +0100, Ard Biesheuvel wrote: > > > I'll add big fat comments. But the fact that nothing is exported > > > there should be a fairly big hint. > > > > > > > I don't follow. How do other header files 'export' things in a way > > that this header doesn't? > > Well, I'll add comments to make it more obvious.. > > > As far as I can tell, these drivers allocate DMA'able memory [in > > ttm_tt_populate()] and subsequently create their own CPU mappings for > > it, assuming that > > a) the default is cache coherent, so vmap()ing those pages with > > cacheable attributes works, and > > Yikes. vmaping with different attributes is generally prone to > create problems on a lot of architectures. > Indeed. But if your starting point is the assumption that DMA is always cache coherent, those vmap() attributes are never different. > > b) telling the GPU to use NoSnoop attributes makes the accesses it > > performs coherent with non-cacheable CPU mappings of those physical > > pages > > > > Since the latter is not true for many arm64 systems, I need this patch > > to get a working system. > > Do we know that this actually works anywhere but x86? > In theory, it could work on arm64 systems with stage2-only SMMUs and correctly configured PCIe RCs that set the right AMBA attributes for inbound transactions with the NoSnoop attributes set. Unfortunately, it seems that the current SMMU ARM code will clobber those AMBA attributes when it uses stage1 mappings, since it forces the memory attributes to WBWA for cache coherent devices. So, as I pointed out in the commit log, the main difference between x86 and other arches it that it can easily tolerate when NoSnoop is non-functional. > In general I would call these above sequence rather bogus and would > prefer we could get rid of such antipatterns in the kernel and just use > dma_alloc_attrs with DMA_ATTR_WRITECOMBINE if we want writecombine > semantics. > Agreed. > Until that happens we should just change the driver ifdefs to default > the hacks to off and only enable them on setups where we 100% > positively know that they actually work. And document that fact > in big fat comments. Well, as I mentioned in my commit log as well, if we default to off unless CONFIG_X86, we may break working setups on MIPS and Power where the device is in fact non-cache coherent, and relies on this 'optimization' to get things working. The same could be true for non-coherent ARM systems, hence my approach to disable this hack for cache coherent devices on non-X86 only.