Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp599522pxb; Wed, 25 Aug 2021 10:20:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOwdDqgt4CyPkambwrRNGU8aDhSronsPBtvdtXZz+JU6yI0tmDAX23kwF306M0yPfHbOyN X-Received: by 2002:a17:906:4346:: with SMTP id z6mr46708147ejm.403.1629912024772; Wed, 25 Aug 2021 10:20:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629912024; cv=none; d=google.com; s=arc-20160816; b=jEeI83noOOPxxM7DnkkId54SNwmbnFliH1yUJOILQ4b6W7OZWK0pBHVkwRnZoHbixn +/Uh5TeIcLPuyvV1yTeuR3TQnrv3x3gxHE9gp0s7OnRs3rTZ7ALdpC7gRSkqJInoU6j0 oF4lXAoumqe3BS1kTUOgzhw98wR7E6q9A6tVJNyTVC6PHPvAW40Rl6RMyjDedau5DbVs KHpNGe3D16mtEH8Tpttu/bDtcCb2zV8ChV1aQcIM04b1lM79DYmYMpcNHTcyf3CAfQC9 1FvjP5SfStLt6OjUSbDbu6IFA4fXMb0Bk9RqIfNYlHscc8THQzQLkMxRuE4x55yR+v/j kMBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=jLwDMlWR89XKphtTF93tPRxtmIHINe4DT9RSu6/19ms=; b=ymbsHn2VReXjF2JHsWL2CX/n4SzDas0VIij+mT6aThMseV4DY1hm/Xai+xbKX+xD9w yIoIwICwl9mvdBc00e3KqbzUCrM7TILT3jnaJ9/111m8qaa0akuqVMOhZm9JHoyqPiV5 g8DGiLrNARobtW3Js3s9Y0Vag27kTf4EhNM9YKv9liO19Apkw3OYOQ3JLdgbf8yu5Rua FmaS9hq5F0RmKmdRqerbkaNNvbxkFcTXHByhjTFADVdKzuvg1egrcCOZ5odl2vMwgjOr xbaLW4ydWQycaB/bVGsZhGJ9CqVWru2+A9clBd19SytQhoH7eutTR1m7h967VsPRraD2 Ja+Q== 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 e24si387961ejl.517.2021.08.25.10.19.58; Wed, 25 Aug 2021 10:20:24 -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 S234224AbhHYRQn (ORCPT + 99 others); Wed, 25 Aug 2021 13:16:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:49622 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232493AbhHYRQn (ORCPT ); Wed, 25 Aug 2021 13:16:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AD50F61076; Wed, 25 Aug 2021 17:15:55 +0000 (UTC) Date: Wed, 25 Aug 2021 18:15:53 +0100 From: Catalin Marinas To: David Hildenbrand Cc: Robin Murphy , Mike Rapoport , Alex Bee , Will Deacon , Andrew Morton , Anshuman Khandual , Linux Kernel Mailing List , linux-mm@kvack.org, Linux ARM , Christoph Hellwig Subject: Re: [BUG 5.14] arm64/mm: dma memory mapping fails (in some cases) Message-ID: <20210825171552.GH3420@arm.com> References: <20210824173741.GC623@arm.com> <0908ce39-7e30-91fa-68ef-11620f9596ae@arm.com> <60a11eba-2910-3b5f-ef96-97d4556c1596@redhat.com> <20210825102044.GA3420@arm.com> <20210825105510.GB3420@arm.com> <547785ff-e02f-df28-7f9c-9ad4f5b3cc77@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <547785ff-e02f-df28-7f9c-9ad4f5b3cc77@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 25, 2021 at 01:12:37PM +0200, David Hildenbrand wrote: > On 25.08.21 12:55, Catalin Marinas wrote: > > On Wed, Aug 25, 2021 at 12:38:31PM +0200, David Hildenbrand wrote: > > > On 25.08.21 12:20, Catalin Marinas wrote: > > > > I can see the documentation for pfn_valid() does not claim anything more > > > > than the presence of an memmap entry. But I wonder whether the confusion > > > > is wider-spread than just the DMA code. At a quick grep, try_ram_remap() > > > > assumes __va() can be used on pfn_valid(), though I suspect it relies on > > > > the calling function to check that the resource was RAM. The arm64 > > > > kern_addr_valid() returns true based on pfn_valid() and kcore.c uses > > > > standard memcpy on it, which wouldn't work for I/O (should we change > > > > this check to pfn_is_map_memory() for arm64?). > > > > > > kern_addr_valid() checks that there is a direct map entry, and that the > > > mapped address has a valid mmap. (copied from x86-64) > > > > It checks that there is a va->pa mapping, not necessarily in the linear > > map as it walks the page tables. So for some I/O range that happens to > > be mapped but which was in close proximity to RAM so that pfn_valid() is > > true, kern_addr_valid() would return true. I don't thin that was the > > intention. > > > > > Would you expect to have a direct map for memory holes and similar (IOW, > > > !System RAM)? > > > > No, but we with the generic pfn_valid(), it may return true for mapped > > MMIO (with different attributes than the direct map). > > Ah, right. But can we actually run into that via kcore? > > kcore builds the RAM list via walk_system_ram_range(), IOW the resource > tree. And we end up calling kern_addr_valid() only on KCORE_RAM, > KCORE_VMEMMAP and KCORE_TEXT. It's probably fine but I'd rather do some check of the other call sites before attempting to move arm64 to the generic pfn_valid() again. -- Catalin