Received: by 10.223.164.202 with SMTP id h10csp409929wrb; Fri, 17 Nov 2017 02:40:46 -0800 (PST) X-Google-Smtp-Source: AGs4zMZsT3tqKUTXnyPrM8r7DJKGg6NU1+7huM6nW6OyxvdCrinYGygAQ30wqdVij3zs7DNXIs0G X-Received: by 10.98.181.1 with SMTP id y1mr1588612pfe.240.1510915246379; Fri, 17 Nov 2017 02:40:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510915246; cv=none; d=google.com; s=arc-20160816; b=Xdv8dIT8io3Kq89RKnAcns0ebcb7N62GOXUzvTL2qhzQS6OwyhQPPOThukUavAQ9ng SLuhThP/71gJCU8NIVzvjGyMm5HKr/fveh96U6zUMq40FLnwGU9TThy0kTLKvIgV15M/ fSIZiT3SBvaS1wLjTTnsOLAeKbUXK8iw0eTZpDYBj5XGaUCWKc4rP+r8nAAyrLfmxTFZ LnP5N+uBInxECM3y8hyUOT5piCdQoZcQhdc+bV5+Nd0Mw81zlMfE0YW+Oia+Ew0ds7/O KWEMFopDTTPpnYNRxSdW/sbe68Mrh1OM6ZMuSLGqW+OrdA064y05vw9X7733fNc+GMYH aNoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=OLjSQCweZOe9Z16fGKXdiUDXWb4jhnnH0a3CyX6EXvw=; b=Wh4pIw90VnfBX64t/pTRvVCsCLnXhRGVxYTelGyHn/DyP+q4VyEXp48lxDBgKc4T0p arZSX1qBIwaGW3UFGDsfTBChIfnpOWpTKCIIDYd2Yan7UW5AYrxpxdgtrU09T2tsPiON h0bUTSNJ6jBsLnJWbjIT6VYiURHltoj5Y1bWIBUBY+TYYPRZqlFG5lRCPNsjiIr5kTkt OL7/ujE/dFK5gbdD2vzptvbTDl8Aw6O66PT6M4jh2ZIg9o7pmSXwbvVAEMg5c4p+v8cf dy/Ekl/AFwgvUXMVV7XFJE9ffBTFVycRYpmw4KP1dpsfiThEmBlmHuvvf3dl5CAO4357 zt1Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 7si2553817ple.62.2017.11.17.02.40.33; Fri, 17 Nov 2017 02:40:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753613AbdKQAN5 (ORCPT + 92 others); Thu, 16 Nov 2017 19:13:57 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:34384 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753570AbdKQANv (ORCPT ); Thu, 16 Nov 2017 19:13:51 -0500 Received: from akpm3.svl.corp.google.com (unknown [104.133.9.92]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 13767A67; Fri, 17 Nov 2017 00:13:51 +0000 (UTC) Date: Thu, 16 Nov 2017 16:13:50 -0800 From: Andrew Morton To: Cc: Christoph Hellwig , Robin Murphy , , , , , , Christoph Hellwig Subject: Re: [PATCH v4] dma-debug: fix incorrect pfn calculation Message-Id: <20171116161350.3b8bd1fbcaae8e032441d3e7@linux-foundation.org> In-Reply-To: <1510872972-23919-1-git-send-email-miles.chen@mediatek.com> References: <1510872972-23919-1-git-send-email-miles.chen@mediatek.com> X-Mailer: Sylpheed 3.4.1 (GTK+ 2.24.23; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 17 Nov 2017 06:56:12 +0800 wrote: > From: Miles Chen > > dma-debug reports the following warning: > > [name:panic&]WARNING: CPU: 3 PID: 298 at kernel-4.4/lib/dma-debug.c:604 > debug _dma_assert_idle+0x1a8/0x230() > DMA-API: cpu touching an active dma mapped cacheline [cln=0x00000882300] > CPU: 3 PID: 298 Comm: vold Tainted: G W O 4.4.22+ #1 > Hardware name: MT6739 (DT) > Call trace: > [] dump_backtrace+0x0/0x1d4 > [] show_stack+0x14/0x1c > [] dump_stack+0xa8/0xe0 > [] warn_slowpath_common+0xf4/0x11c > [] warn_slowpath_fmt+0x60/0x80 > [] debug_dma_assert_idle+0x1a8/0x230 > [] wp_page_copy.isra.96+0x118/0x520 > [] do_wp_page+0x4fc/0x534 > [] handle_mm_fault+0xd4c/0x1310 > [] do_page_fault+0x1c8/0x394 > [] do_mem_abort+0x50/0xec > > I found that debug_dma_alloc_coherent() and debug_dma_free_coherent() > assume that dma_alloc_coherent() always returns a linear address. However > it's possible that dma_alloc_coherent() returns a non-linear address. In > this case, page_to_pfn(virt_to_page(virt)) will return an incorrect pfn. > If the pfn is valid and mapped as a COW page, we will hit the warning when > doing wp_page_copy(). > > Fix this by calculating pfn for linear and non-linear addresses. > It's a shame you didn't Cc Christoph, who was the sole reviewer of the earlier version. And it's a shame you didn't capture the result of that review discussion in the v3 changelog. And it's a shame that you didn't describe how this patch differs from earlier versions. Oh well, here's the incremental patch: --- a/lib/dma-debug.c~dma-debug-fix-incorrect-pfn-calculation-v4 +++ a/lib/dma-debug.c @@ -1495,15 +1495,22 @@ void debug_dma_alloc_coherent(struct dev if (!entry) return; + /* handle vmalloc and linear addresses */ + if (!is_vmalloc_addr(virt) && !virt_to_page(virt)) + return; + entry->type = dma_debug_coherent; entry->dev = dev; - entry->pfn = is_vmalloc_addr(virt) ? vmalloc_to_pfn(virt) : - page_to_pfn(virt_to_page(virt)); entry->offset = offset_in_page(virt); entry->size = size; entry->dev_addr = dma_addr; entry->direction = DMA_BIDIRECTIONAL; + if (is_vmalloc_addr(virt)) + entry->pfn = vmalloc_to_pfn(virt); + else + entry->pfn = page_to_pfn(virt_to_page(virt)); + add_dma_entry(entry); } EXPORT_SYMBOL(debug_dma_alloc_coherent); @@ -1514,14 +1521,21 @@ void debug_dma_free_coherent(struct devi struct dma_debug_entry ref = { .type = dma_debug_coherent, .dev = dev, - .pfn = is_vmalloc_addr(virt) ? vmalloc_to_pfn(virt) : - page_to_pfn(virt_to_page(virt)), .offset = offset_in_page(virt), .dev_addr = addr, .size = size, .direction = DMA_BIDIRECTIONAL, }; + /* handle vmalloc and linear addresses */ + if (!is_vmalloc_addr(virt) && !virt_to_page(virt)) + return; + + if (is_vmalloc_addr(virt)) + ref.pfn = vmalloc_to_pfn(virt); + else + ref.pfn = page_to_pfn(virt_to_page(virt)); + if (unlikely(dma_debug_disabled())) return; _ From 1584306461485814633@xxx Fri Nov 17 09:53:01 +0000 2017 X-GM-THRID: 1584299430012978510 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread