Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2852491pxj; Mon, 14 Jun 2021 08:36:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzB6T9nHinFZ5DyN/5DWTr5EFm/Hnlz+OiLoZh/HCs2oA0DxvPb2e98pZWWwsOHxC8+87Qh X-Received: by 2002:a17:906:60d3:: with SMTP id f19mr4976546ejk.413.1623684960850; Mon, 14 Jun 2021 08:36:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623684960; cv=none; d=google.com; s=arc-20160816; b=Z5/gKf6OScXictNJqmAfVc0m9LCV8cavvGm/3EJKkwo0B4X3XTSr5qQe2QW3X9QmRt 4lMNZmVaBFYYEeH2I8xT81UmtdeKDGoRL7GjoBMrvbDJUE/ul79Q+j19Pc6krlXTxCAZ m9SSS4VRF1KmTBVhGwzMS4KUIz17oTpdQ7oxNsXVggqncIQJZS7NI2uqdyScL20956HF DPGxWRSua7OvZ1y1mCKL5V2mo8izE6A48bH0+U/4WZKCCZ3iQ8GSHK3SW6RqfjDjhiwz OIy2/S9uvLde84WS3AbVOnzHwVjsZOw/i8WHR4SAB7HdGoF54j+cpJY/RILUK5FGdWsA 9lbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=rOsXzevRhhVcSXslu6KyH31mCxchtys/UJSub/EE1fw=; b=RRYg6cMN0AOf3NpwLPYdXncqUZihtqLm4xUzIxcJ7fc9o+bunO19l8uLSShM2/K6MJ ecg84iMnVTN09452OQbnoRF/pjWJ8/8Oo2X96OFoAnRtyD/lECWWM0mkO8Pjk1pCT2Rb oUcAWA2uMmEYcJjYBZhKbF8wlL7gETBI77NWV4h5ajUGDFm8CEqnsJ+D9mn8UBvS7pHI lFc9Un6YzurNWY77GJ+HZIJ9j/jN41uN6JzacCCe3asWLKIck7hwNsU7ylFXM89xQAlP 5Kwz7J0D+LGvG81RiY9mzJmzXneHlh2acBytHllix/YWOU43YHZ+9xp69x6RHfHQr8a8 EEUQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c7si11326517ejz.386.2021.06.14.08.35.37; Mon, 14 Jun 2021 08:36:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233757AbhFNPgV (ORCPT + 99 others); Mon, 14 Jun 2021 11:36:21 -0400 Received: from foss.arm.com ([217.140.110.172]:39042 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233299AbhFNPgQ (ORCPT ); Mon, 14 Jun 2021 11:36:16 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 09A4811D4; Mon, 14 Jun 2021 08:34:13 -0700 (PDT) Received: from [10.57.9.136] (unknown [10.57.9.136]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7BA5A3F70D; Mon, 14 Jun 2021 08:34:11 -0700 (PDT) Subject: Re: [PATCH 1/1] dma: coherent: check no-map property for arm64 To: Catalin Marinas , Dong Aisheng Cc: Will Deacon , Dong Aisheng , iommu@lists.linux-foundation.org, open list , linux-mm@kvack.org, "moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE" , Christoph Hellwig , Marek Szyprowski References: <20210611131056.3731084-1-aisheng.dong@nxp.com> <20210614083609.GA18701@willie-the-truck> <20210614145105.GC30667@arm.com> From: Robin Murphy Message-ID: <6f897830-301f-3eb4-785f-de446476e676@arm.com> Date: Mon, 14 Jun 2021 16:34:05 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <20210614145105.GC30667@arm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-06-14 15:51, Catalin Marinas wrote: > On Mon, Jun 14, 2021 at 06:07:04PM +0800, Dong Aisheng wrote: >> On Mon, Jun 14, 2021 at 4:36 PM Will Deacon wrote: >>> On Fri, Jun 11, 2021 at 09:10:56PM +0800, Dong Aisheng wrote: >>>> Coherent dma on ARM64 also can't work with mapped system ram, >>>> that means 'no-map' property must be specified in dts. >>>> Add the missing check for ARM64 platforms as well. >>>> Besides 'no-map' checking, 'linux,dma-default' feature is also >>>> enabled for ARM64 along with this patch. Note that the "linux,dma-default" stuff is really only for NOMMU (with caches), so hardly relevant to arm64. >>> Please can you explain _why_ it can't work? We don't need to tear down >>> aliases from the linear map for the streaming DMA API, so why is this >>> case different? Also, coherent devices wouldn't need this either way, >>> would they? What problem are you solving here? >>> >> >> Not sure if i get your point correctly. Here is my understanding. (fix >> me if wrong) >> In current implementation, the coherent dma memory will be remapped as >> writecombine and uncached type which can't reuse the linear mapping. >> The prerequisite to do this is the memory must not be mapped System RAM. >> e.g. reserved memory with no-map property and invisible to the buddy system. > > The architecture allows the system RAM to be mapped in the linear map > while there's another writecombine alias, as long as there are no dirty > cache lines that could be evicted randomly. This works fine with the DMA > API (and we have some cache maintenance when the non-cacheable mapping > is first created). > > Looking at the rmem_dma_device_init() -> dma_init_coherent_memory(), it > ends up calling memremap(MEMREMAP_WC) which would warn if it intersects > with system RAM regardless of the architecture. If the memory region is > nomap, it doesn't end up as IORESOURCE_SYSTEM_RAM, so memremap() won't > warn. But why is this specific only to arm (or arm64)? Didn't some ARMv7 implementations permit unexpected cache hits for the non-cacheable address if the same PA has been speculatively fetched via the cacheable alias? > Is the "shared-dma-pool" property only meant for Normal Non-cacheable > memory (hence the MEMREMAP_WC flag)? If a system is fully cache > coherent, does this check still make sense or the DT is not supposed to > have such nodes? I don't think "shared-dma-pool" carries any particular expectation itself of how things are mapped, especially since "reusable" effectively implies a cacheable mapping for 'normal' kernel usage. Absent "reusable" to take things down the CMA path instead, "no-map" would currently be needed for coherent devices, since even when the CPU is guaranteed to bypass the cacheable alias the device can still inadvertently snoop it and see stale data. However if the device *is* coherent then it would seem more sensible to skip the remap entirely and just use the linear map address of the pool, unless of course it needs to be shared by multiple devices some of which are non-coherent... :/ >> This seems a little different from CMA which the memory is still >> underlying managed by the buddy system in order to support migration. >> >> The patch here does not resolve a real issue but just open the sanity check for >> ARM64 case as well as ARM which reports the issue a little bit earlier at >> rmem_dma_setup() time. > > I think we first need to figure out what the real issue is and then try > to solve it. Agreed. Robin.