Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp296707pxb; Wed, 25 Aug 2021 03:36:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmWhC56dmsPIXoqnN4FavxNX/Od/eBZo8yt0dO/TJlmJKgY7il0EiudBz1w7heRpm6rnwj X-Received: by 2002:a17:907:1b1b:: with SMTP id mp27mr44590319ejc.538.1629887780194; Wed, 25 Aug 2021 03:36:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629887780; cv=none; d=google.com; s=arc-20160816; b=UPBVF5exnnlSUX+qKXtdc3KW0P/ASUABgS58zzzptFxBHYhG3TrgKJe5hDalkT5dV8 uc1qCiXyiZH0kaeB6tNcPOXrCXW6+zcibc+K2Qc5gf8WnGNxpODAygPYS4vXWaw8fB4r ovZAGZct7muYnIZVccr0NGizm9FSfAbCFFdNWJdntMy+QK5fNw76xB3O2MlZfvskJ9Xg gIR0hB637JdAKL0nu6+5xVATIjMLNIv9zrdqOM4hxII/c3xcXa9C9JDnK+L9nSmPT/Aw s6634Y8OqJHGGl7IboV6V1A49bDr7PVDlul5h+1ryC1egX3/cUdPkyuYm3o5ogCeRYPp KCJg== 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=4YyLWrRsKy0ZEVcoUStrD+IwEXRlSFdJ1METrI8YbG0=; b=E7miOqozLJTv/IGz8u2QYgq8lgukK5Y2DZyerGSV4hR/TkS6WQgj97n5zNZmsMdLjk af/0TkVIn8r0ba8Wp4eVgqGYIGDdbsXhcx6n2U+lHv947sFo1MEwXumM3xPfPVVqqxtN GUNB8LJPLALKovX93vNBDIUcBT7E4PdX5QGjgQOE1XfxlJXhLk46Euvre4hBzqNF1Osb I5KHrl6iLgF5PHKbV/KZUAeTDgtp1e1jhJHuc/5OSaTIPIAAp6xPRXzxvyoiDQqI0LmZ QQ9rXT+utiwo9s94CJSJ3vP2YX+8EPxF3VoPGo1p2zCC8qSR7ajcC4kAgnbD2m69ukzN 4lfA== 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 k8si8663932edr.262.2021.08.25.03.35.56; Wed, 25 Aug 2021 03:36:20 -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 S239992AbhHYKef (ORCPT + 99 others); Wed, 25 Aug 2021 06:34:35 -0400 Received: from foss.arm.com ([217.140.110.172]:48226 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238646AbhHYKed (ORCPT ); Wed, 25 Aug 2021 06:34:33 -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 D1E6831B; Wed, 25 Aug 2021 03:33:47 -0700 (PDT) Received: from [10.57.15.112] (unknown [10.57.15.112]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2D1363F66F; Wed, 25 Aug 2021 03:33:46 -0700 (PDT) Subject: Re: [BUG 5.14] arm64/mm: dma memory mapping fails (in some cases) To: Will Deacon , Catalin Marinas Cc: David Hildenbrand , Mike Rapoport , Alex Bee , Andrew Morton , Anshuman Khandual , Linux Kernel Mailing List , linux-mm@kvack.org, Linux ARM , Christoph Hellwig References: <20210824173741.GC623@arm.com> <0908ce39-7e30-91fa-68ef-11620f9596ae@arm.com> <60a11eba-2910-3b5f-ef96-97d4556c1596@redhat.com> <20210825102044.GA3420@arm.com> <20210825102856.GD24546@willie-the-truck> From: Robin Murphy Message-ID: <244f4b37-2db6-6f9e-b5e2-3ccd6c3136ba@arm.com> Date: Wed, 25 Aug 2021 11:33:41 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20210825102856.GD24546@willie-the-truck> 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-08-25 11:28, Will Deacon wrote: > On Wed, Aug 25, 2021 at 11:20:46AM +0100, Catalin Marinas wrote: >> Given how later we are in the -rc cycle, I suggest we revert Anshuman's >> commit 16c9afc77660 ("arm64/mm: drop HAVE_ARCH_PFN_VALID") and try to >> assess the implications in 5.15 (the patch doesn't seem to have the >> arm64 maintainers' ack anyway ;)). > > I'll stick the revert (below) into kernelci now so we can get some coverage > in case it breaks something else. > > Will > > --->8 > > From e97ba0e39e486c20d8f76f3e632e4b7d933602cd Mon Sep 17 00:00:00 2001 > From: Will Deacon > Date: Wed, 25 Aug 2021 11:10:07 +0100 > Subject: [PATCH] Revert "arm64/mm: drop HAVE_ARCH_PFN_VALID" > > This reverts commit 16c9afc776608324ca71c0bc354987bab532f51d. > > Alex Bee reports a regression in 5.14 on their RK3328 SoC when > configuring the PL330 DMA controller: > > | ------------[ cut here ]------------ > | WARNING: CPU: 2 PID: 373 at kernel/dma/mapping.c:235 dma_map_resource+0x68/0xc0 > | Modules linked in: spi_rockchip(+) fuse > | CPU: 2 PID: 373 Comm: systemd-udevd Not tainted 5.14.0-rc7 #1 > | Hardware name: Pine64 Rock64 (DT) > | pstate: 80000005 (Nzcv daif -PAN -UAO -TCO BTYPE=--) > | pc : dma_map_resource+0x68/0xc0 > | lr : pl330_prep_slave_fifo+0x78/0xd0 > > This appears to be because dma_map_resource() is being called for a > physical address which does not correspond to a memory address yet does > have a valid 'struct page' due to the way in which the vmemmap is > constructed. > > Prior to 16c9afc77660 ("arm64/mm: drop HAVE_ARCH_PFN_VALID"), the arm64 > implementation of pfn_valid() called memblock_is_memory() to return > 'false' for such regions and the DMA mapping request would proceed. > However, now that we are using the generic implementation where only the > presence of the memory map entry is considered, we return 'true' and > erroneously fail with DMA_MAPPING_ERROR because we identify the region > as DRAM. > > Although fixing this in the DMA mapping code is arguably the right fix, > it is a risky, cross-architecture change at this stage in the cycle. So > just revert arm64 back to its old pfn_valid() implementation for v5.14. TBH the offending warning is only meant to be a quick sanity check, so I don't think there should be much impact to changing the DMA code; it's just a question of figuring out what change to make. I'm digging in now... Thanks, Robin. > Cc: Catalin Marinas > Cc: Robin Murphy > Cc: Mike Rapoport > Cc: Anshuman Khandual > Cc: Christoph Hellwig > Reported-by: Alex Bee > Link: https://lore.kernel.org/r/d3a3c828-b777-faf8-e901-904995688437@gmail.com > Signed-off-by: Will Deacon > --- > arch/arm64/Kconfig | 1 + > arch/arm64/include/asm/page.h | 1 + > arch/arm64/mm/init.c | 37 +++++++++++++++++++++++++++++++++++ > include/linux/mmzone.h | 9 --------- > 4 files changed, 39 insertions(+), 9 deletions(-) > > diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig > index fdcd54d39c1e..62c3c1d2190f 100644 > --- a/arch/arm64/Kconfig > +++ b/arch/arm64/Kconfig > @@ -156,6 +156,7 @@ config ARM64 > select HAVE_ARCH_KGDB > select HAVE_ARCH_MMAP_RND_BITS > select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT > + select HAVE_ARCH_PFN_VALID > select HAVE_ARCH_PREL32_RELOCATIONS > select HAVE_ARCH_RANDOMIZE_KSTACK_OFFSET > select HAVE_ARCH_SECCOMP_FILTER > diff --git a/arch/arm64/include/asm/page.h b/arch/arm64/include/asm/page.h > index 993a27ea6f54..f98c91bbd7c1 100644 > --- a/arch/arm64/include/asm/page.h > +++ b/arch/arm64/include/asm/page.h > @@ -41,6 +41,7 @@ void tag_clear_highpage(struct page *to); > > typedef struct page *pgtable_t; > > +int pfn_valid(unsigned long pfn); > int pfn_is_map_memory(unsigned long pfn); > > #include > diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c > index 8490ed2917ff..1fdb7bb7c198 100644 > --- a/arch/arm64/mm/init.c > +++ b/arch/arm64/mm/init.c > @@ -219,6 +219,43 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max) > free_area_init(max_zone_pfns); > } > > +int pfn_valid(unsigned long pfn) > +{ > + phys_addr_t addr = PFN_PHYS(pfn); > + struct mem_section *ms; > + > + /* > + * Ensure the upper PAGE_SHIFT bits are clear in the > + * pfn. Else it might lead to false positives when > + * some of the upper bits are set, but the lower bits > + * match a valid pfn. > + */ > + if (PHYS_PFN(addr) != pfn) > + return 0; > + > + if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS) > + return 0; > + > + ms = __pfn_to_section(pfn); > + if (!valid_section(ms)) > + return 0; > + > + /* > + * ZONE_DEVICE memory does not have the memblock entries. > + * memblock_is_map_memory() check for ZONE_DEVICE based > + * addresses will always fail. Even the normal hotplugged > + * memory will never have MEMBLOCK_NOMAP flag set in their > + * memblock entries. Skip memblock search for all non early > + * memory sections covering all of hotplug memory including > + * both normal and ZONE_DEVICE based. > + */ > + if (!early_section(ms)) > + return pfn_section_valid(ms, pfn); > + > + return memblock_is_memory(addr); > +} > +EXPORT_SYMBOL(pfn_valid); > + > int pfn_is_map_memory(unsigned long pfn) > { > phys_addr_t addr = PFN_PHYS(pfn); > diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h > index fcb535560028..ee70f21a79d5 100644 > --- a/include/linux/mmzone.h > +++ b/include/linux/mmzone.h > @@ -1463,15 +1463,6 @@ static inline int pfn_valid(unsigned long pfn) > { > struct mem_section *ms; > > - /* > - * Ensure the upper PAGE_SHIFT bits are clear in the > - * pfn. Else it might lead to false positives when > - * some of the upper bits are set, but the lower bits > - * match a valid pfn. > - */ > - if (PHYS_PFN(PFN_PHYS(pfn)) != pfn) > - return 0; > - > if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS) > return 0; > ms = __nr_to_section(pfn_to_section_nr(pfn)); >