Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp277370pxb; Wed, 25 Aug 2021 03:04:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyD/CBeXaiaOL7EYmglheR7oN5p/lMmQ5VqpjeHPrZwH2c+jrw2wudTL6GNxNEo/4s9JpNg X-Received: by 2002:a50:fd82:: with SMTP id o2mr47825049edt.294.1629885843596; Wed, 25 Aug 2021 03:04:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629885843; cv=none; d=google.com; s=arc-20160816; b=XbIlNvUcDkuWaQ96M0+V/UgpNsNK5MQJkOu3kQx0u79vtsZE00GSp7WJC1A88U08Mm Tdd1DvC0t6GA0ZCLEN/WSHyImDMUHXO4vz4KQuF4Q/GL3ArhatSmnamYO5ZvXxZY5KUi VBY7D1sllDWKDhSEctSKcgpBOlB5vGOgEMQtvzGIUZGN4jIWx3xMyr5B/j6PdJclytuq vdV+Bkju/PcDWX4Qllb/hpSIgqReonOJyvhr7Y3ULcxBE/yhzs4LLZzXNkeaoTm8Xn0z 9e+s19BFieU1xH0Nal9Uwe9qW1gxUyTaQytVPqnnSnXT02XAxkL2PuLzu1+07cED0dDT 0Nqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=t1Fxyis5VyGmJ28Q6mHHWuWqL/LfgK4tUw1UlmoXIy4=; b=R3knsez9XQQJz0N+FRVop+VZwgyxY5ZLAUNNGFELzzbFDc68C44BqBWH3xh/8YUv3H 9YoaO4OlWc2WFRZlkLzs7RxMJ7P89KRHC5W0ucaq/Um/Lzi14h1xtHvDSaqowL4cUp6i IiD4J51Qws8yKK3O5lG1TcYmifx/2MoaQCnaFIJEEykSu1GAcZHZAChG8CCg/SUo06ym 56/sQaiOFNymZu4GuhVCdWK2MvTii5EOghYSylhgXQYe0nlJpTsLicaN81tMkT5WIDik CMVB51FQCan7Qc8knkSlB6Ln0zn9VAgzEiMv3r34EUjIGiR7m41XB6r5e/T1CncvyQLN vQlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=N5KuOH68; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 10si19415098ejt.595.2021.08.25.03.03.36; Wed, 25 Aug 2021 03:04:03 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=N5KuOH68; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239628AbhHYKBn (ORCPT + 99 others); Wed, 25 Aug 2021 06:01:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239550AbhHYKBl (ORCPT ); Wed, 25 Aug 2021 06:01:41 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20FF0C061757 for ; Wed, 25 Aug 2021 03:00:55 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id q11-20020a7bce8b0000b02902e6880d0accso3881098wmj.0 for ; Wed, 25 Aug 2021 03:00:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=t1Fxyis5VyGmJ28Q6mHHWuWqL/LfgK4tUw1UlmoXIy4=; b=N5KuOH68gGgamALSiXAw9kpRRby+Lo7oec2oseaOCeZD17MuGC7V/2taZQqmhnRrrw llWa01fwlfzXt2LvD2u6iM88oLcXN7KdEXYiWqFVBSdPwCXGg+npZDPL7LGN8uu0/BsL IKteQNg2ZoACgemT2X7DYthtTxs6ZM0RI3k8/M4JzNaeMklGbKqkRdio3CepznulmMU/ tKIaIAjwBaRY9E4toUvZzBWb6F4G7AcacllOwFah8pWqa9AKGVmGtG4Yi8Wm502v3CAo muY11dljK0DZ6LtlV+egTQJa623Vgv4GbK68v0lQEQQCJ7C4uhOlLvUViK95ECS0euI0 H4VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=t1Fxyis5VyGmJ28Q6mHHWuWqL/LfgK4tUw1UlmoXIy4=; b=fgH9IhyRRXZ9t8IY3e44y6sIlrWawH087soL8YXBjMX0vBPfFNU3wxnrqvVmXSTpKN /KYhm3ml+vZDFqBM1NPAlMRGlZRuD7nGwsF40amVJysPyzch5uTv2lt4GcJ/UoPGeC3F PjL9tbJ+juEYKmf66osVJ8ILMOEEurbKgCQcWkYTgXYmIdSaUg7V8ql4lMU8ATeFm7Xj suQ6L0a9u1f+zdoAoP4/BV3sbd4OUaH/HIWUHhGVPm/liZkusjzyWy79eDHGWCTfpiZZ cxWuK0BXJmXAdKJ+xPs0KZ3C1CCbnFJ9clLUNWSoH+AEhLrF9sj14Y1CygWGRtX2zv26 Oemg== X-Gm-Message-State: AOAM5337da03JrqK/XTGRDRHqtwUtjEgzD0ADNhI4TH+UIIRnOrYBtWX sI+0vVNlozUhrQs9UmAxWQ== X-Received: by 2002:a1c:1bce:: with SMTP id b197mr8108729wmb.43.1629885653723; Wed, 25 Aug 2021 03:00:53 -0700 (PDT) Received: from [192.168.200.23] (ip5b434083.dynamic.kabel-deutschland.de. [91.67.64.131]) by smtp.gmail.com with ESMTPSA id f20sm657674wmb.32.2021.08.25.03.00.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 Aug 2021 03:00:53 -0700 (PDT) Subject: Re: [BUG 5.14] arm64/mm: dma memory mapping fails (in some cases) To: Mike Rapoport , Robin Murphy , Andrew Morton , Catalin Marinas Cc: Will Deacon , Anshuman Khandual , Linux Kernel Mailing List , linux-mm@kvack.org, Linux ARM References: <20210824173741.GC623@arm.com> From: Alex Bee Message-ID: <3bc0c465-475d-78e8-b742-ef093ebaf47c@gmail.com> Date: Wed, 25 Aug 2021 12:00:51 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am 25.08.21 um 06:39 schrieb Mike Rapoport: > On Tue, Aug 24, 2021 at 10:14:01PM +0200, Alex Bee wrote: >> Hi Mike, >> >> thanks for your reply >> >> Am 24.08.21 um 20:28 schrieb Mike Rapoport: >>> On Tue, Aug 24, 2021 at 06:37:41PM +0100, Catalin Marinas wrote: >>>> Hi Alex, >>>> >>>> Thanks for the report. >>>> >>>> On Tue, Aug 24, 2021 at 03:40:47PM +0200, Alex Bee wrote: >>>>> it seems there is a regression in arm64 memory mapping in 5.14, since it >>>>> fails on Rockchip RK3328 when the pl330 dmac tries to map with: >>>>> >>>>> [    8.921909] ------------[ cut here ]------------ >>>>> [    8.921940] WARNING: CPU: 2 PID: 373 at kernel/dma/mapping.c:235 dma_map_resource+0x68/0xc0 >>>>> [    8.921973] Modules linked in: spi_rockchip(+) fuse >>>>> [    8.921996] CPU: 2 PID: 373 Comm: systemd-udevd Not tainted 5.14.0-rc7 #1 >>>>> [    8.922004] Hardware name: Pine64 Rock64 (DT) >>>>> [    8.922011] pstate: 80000005 (Nzcv daif -PAN -UAO -TCO BTYPE=--) >>>>> [    8.922018] pc : dma_map_resource+0x68/0xc0 >>>>> [    8.922026] lr : pl330_prep_slave_fifo+0x78/0xd0 >>>>> [    8.922040] sp : ffff800012102ae0 >>>>> [    8.922043] x29: ffff800012102ae0 x28: ffff000005c94800 x27: 0000000000000000 >>>>> [    8.922056] x26: ffff000000566bd0 x25: 0000000000000001 x24: 0000000000000001 >>>>> [    8.922067] x23: 0000000000000002 x22: ffff000000628c00 x21: 0000000000000001 >>>>> [    8.922078] x20: ffff000000566bd0 x19: 0000000000000001 x18: 0000000000000000 >>>>> [    8.922089] x17: 0000000000000000 x16: 0000000000000000 x15: 0000000000000000 >>>>> [    8.922100] x14: 0000000000000277 x13: 0000000000000001 x12: 0000000000000000 >>>>> [    8.922111] x11: 0000000000000001 x10: 00000000000008e0 x9 : ffff800012102a80 >>>>> [    8.922123] x8 : ffff000000d14b80 x7 : ffff0000fe7b12f0 x6 : ffff0000fe7b1100 >>>>> [    8.922134] x5 : fffffc000000000f x4 : 0000000000000000 x3 : 0000000000000001 >>>>> [    8.922145] x2 : 0000000000000001 x1 : 00000000ff190800 x0 : ffff000000628c00 >>>>> [    8.922158] Call trace: >>>>> [    8.922163]  dma_map_resource+0x68/0xc0 >>>>> [    8.922173]  pl330_prep_slave_sg+0x58/0x220 >>>>> [    8.922181]  rockchip_spi_prepare_dma+0xd8/0x2c0 [spi_rockchip] >>>>> [    8.922208]  rockchip_spi_transfer_one+0x294/0x3d8 [spi_rockchip] >>>> [...] >>>>> Note: This does not relate to the spi driver - when disabling this device in >>>>> the device tree it fails for any other (i2s, for instance) which uses dma. >>>>> Commenting out the failing check at [1], however, helps and the mapping >>>>> works again. >>>> Do you know which address dma_map_resource() is trying to map (maybe >>>> add some printk())? It's not supposed to map RAM, hence the warning. >>>> Random guess, the address is 0xff190800 (based on the x1 above but the >>>> regs might as well be mangled). >>> 0xff190800 will cause this warning for sure. It has a memory map, but it is >>> not RAM so old version of pfn_valid() would return 0 and the new one >>> returns 1. >>>>> I tried to follow the recent changes for arm64 mm which could relate to the >>>>> check failing at [1] and reverting >>>>>   commit 16c9afc77660 ("arm64/mm: drop HAVE_ARCH_PFN_VALID") >>>>> helps and makes it work again, but I'm 100% uncertain if that commit is >>>>> really the culprit. >>>>> >>>>> Note, that the firmware (legacy u-boot) injects memory configuration in the >>>>> device tree as follows: >>>>> >>>>> /memreserve/    0x00000000fcefc000 0x000000000000d000; >>>>> / { >>>>> .. >>>>>     compatible = "pine64,rock64\0rockchip,rk3328"; >>>>> .. >>>>>     memory { >>>>>         reg = <0x00 0x200000 0x00 0xfee00000 0x00 0x00 0x00 0x00>; >>>>>         device_type = "memory"; >>>>>     }; >>>>> >>>>> .. >>>>> } >>>> Either pfn_valid() gets confused in 5.14 or something is wrong with the >>>> DT. I have a suspicion it's the former since reverting the above commit >>>> makes it disappear. >>> I think pfn_valid() actually behaves as expected but the caller is wrong >>> because pfn_valid != RAM (this applies btw to !arm64 as well). >>> >>> /* Don't allow RAM to be mapped */ >>> if (WARN_ON_ONCE(pfn_valid(PHYS_PFN(phys_addr)))) >>> return DMA_MAPPING_ERROR; >>> >>> Alex, can you please try this patch: >>> >>> diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c >>> index 2b06a809d0b9..4715e9641a29 100644 >>> --- a/kernel/dma/mapping.c >>> +++ b/kernel/dma/mapping.c >>> @@ -232,7 +232,7 @@ dma_addr_t dma_map_resource(struct device *dev, phys_addr_t phys_addr, >>> return DMA_MAPPING_ERROR; >>> /* Don't allow RAM to be mapped */ >>> - if (WARN_ON_ONCE(pfn_valid(PHYS_PFN(phys_addr)))) >>> + if (WARN_ON_ONCE(!memblock_is_memory(phys_addr))) >>> return DMA_MAPPING_ERROR; >>> if (dma_map_direct(dev, ops)) >> Nope, doesn't help: >> >> [    8.353879] dma_map_resource Failed to map address 0xff190800 >> [    8.353886] dma_map_resource pfn_valid(PHYS_PFN(0xff190800)): 1 >> [    8.353892] dma_map_resource memblock_is_memory(0xff190800): 0 >> >> If understand the comment for that check correct, that we _don't_ want RAM >> to be mapped - shoudn't that be: >> >> + if (WARN_ON_ONCE(memblock_is_memory(phys_addr))) >> >> ? > Right, we don't want RAM to be mapped, the negation was wrong and it should > be > > if (WARN_ON_ONCE(memblock_is_memory(phys_addr))) > OK, great: that helps with no other complaints - at least on this (arm64) SoC. Since this affects all other archs, I doubt this will be in 5.14 - but it would be great if there could be fix for that in 5.14 since at system breaking bug. I'm not sure why it wasn't reported yet - is there any chance that at least   commit 16c9afc77660 ("arm64/mm: drop HAVE_ARCH_PFN_VALID") can be reverted in 5.14? Alex