From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9BE4C4338F for ; Wed, 25 Aug 2021 17:18:26 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 85D916109E for ; Wed, 25 Aug 2021 17:18:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 85D916109E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=RqPU8we1d3ebPartm6WetM7yx9ORjVBpVc2WFgZxKI4=; b=JjESLgQfXwn0qk 9ErVkDw96NOSlXSMdIm7LjeptMqEKGU+kLsxKuwmvXD1+GAq/cxGhsbQToc38iGfdwdhqHvQKhT5t jSKeQ9nnz7y4kIPsPyeteEE8/iemRWr7YfS9GlnOCG92BP+HgBA3CGY6NRt9py6/C/T7N6WVTjjBO JK1lwRrJ4fKQdCIBTwQZJX37/rWdbRIFYW/DCDS1U3ZsWDt8uhl+3X5ReinpftNY+vqxuUcRsZ4J8 XymhL2qbLqI9vb5n3/1s1Eg+qK3Bf4BMNYbvo45aVszNuz0DkxDNcNEgUJXTdu4rW/wvgi/B6YMOQ xSQZJGk7oIOfFUzeJDJQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mIwVN-0084Iy-JK; Wed, 25 Aug 2021 17:16:01 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mIwVJ-0084IG-Un for linux-arm-kernel@lists.infradead.org; Wed, 25 Aug 2021 17:15:59 +0000 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-Disposition: inline In-Reply-To: <547785ff-e02f-df28-7f9c-9ad4f5b3cc77@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210825_101558_053881_E20106BA X-CRM114-Status: GOOD ( 27.92 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31D3EC432BE for ; Wed, 25 Aug 2021 17:16:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A896E60F25 for ; Wed, 25 Aug 2021 17:15:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A896E60F25 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 371C6900003; Wed, 25 Aug 2021 13:15:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 321BB900002; Wed, 25 Aug 2021 13:15:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E9D9900003; Wed, 25 Aug 2021 13:15:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0144.hostedemail.com [216.40.44.144]) by kanga.kvack.org (Postfix) with ESMTP id 05525900002 for ; Wed, 25 Aug 2021 13:15:59 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 8CBA322C18 for ; Wed, 25 Aug 2021 17:15:58 +0000 (UTC) X-FDA: 78514255596.09.C6B357E Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf27.hostedemail.com (Postfix) with ESMTP id 48D3C70000AD for ; Wed, 25 Aug 2021 17:15:58 +0000 (UTC) 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) Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf27.hostedemail.com: domain of cmarinas@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=cmarinas@kernel.org X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 48D3C70000AD X-Stat-Signature: hf88cb457p4kd1r9fixuq9pxxm38dcg9 X-HE-Tag: 1629911758-298928 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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