Received: by 10.223.164.202 with SMTP id h10csp366997wrb; Fri, 17 Nov 2017 01:53:01 -0800 (PST) X-Google-Smtp-Source: AGs4zMZ8hcNPgVx4yz87e9ZNCdxGBJKh2l/5BIfIm7aTWZ2ZNRBp49J7xosngzPzkVmuyeS+jHUb X-Received: by 10.159.229.136 with SMTP id az8mr4696469plb.59.1510912381694; Fri, 17 Nov 2017 01:53:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510912381; cv=none; d=google.com; s=arc-20160816; b=gCQastF/uGe/LU2wsCApwkO+1xq8TPvmRsIrx07ek06amgAPg62934EyEjqelsu2p1 btI/V2EVoS9hHnZLzEL8Z0ymygK8ld0HSaPTBDJ1FdphXthP8EBcjTsHQrdgyuEpwOUD lcvRMhz9wjtNj1rmG1ZVb6kx3jsCrOoSboLDU1/Hrhr9kGzW3DE3fmDndKMCZQnRqnH2 qhAzmD2nGQQJoFF0CBwHQGsO+JDSEOjTPvzzgynDjCX+alCDV3E+v5oUv8G5jOAtlAM/ 5BK7qyLb023r5jw+zRsnGqnC6WnteIl6H8mYi3GLuR5BTgVV2mgI6xzRRjoSJbYPq+rQ wPaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :references:in-reply-to:date:cc:to:from:subject:message-id :arc-authentication-results; bh=zNdFJPl81NmmctRN0QxXK0NKGf8YDGGKggIvJwM5Ofk=; b=0nCEZP4lcFf1Fyym6u5wVFlq8xIgTDHwnRfhVL5BLYwfHEOSfpU8MGy99JG5YRmLbR ds4NMRhLLmjvcialrCGrunOEwJCUh74Q4uJyh2iWIUxpcqfH0Nx+qwAeHLZDLxiKI+D4 X3SZXfAC6kcZ7ZrSLLtqB+epT+lhuZO19Vcqk37LQgj85wvqcPq70DQ1hwMdRaGnDK0a BJstNe96YsewYup5M+TqCd7NsraMKy0Ard9CSLuLLkJEWvt72hN12RHgF+ke/i4vDqkE B6ZCojs8m958V0S8rM1+4PQJ8bqVMCPpPUshXVFca5gz56c2f5cFNQdR0qVeKrWxkoRF 7Nrw== 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 61si2503361plr.279.2017.11.17.01.52.48; Fri, 17 Nov 2017 01:53:01 -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 S1754627AbdKQBXc (ORCPT + 91 others); Thu, 16 Nov 2017 20:23:32 -0500 Received: from mailgw01.mediatek.com ([210.61.82.183]:39546 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1753684AbdKQBXY (ORCPT ); Thu, 16 Nov 2017 20:23:24 -0500 X-UUID: dbf8a0c2749244b1b9b4dd3e3027a990-20171117 Received: from mtkcas08.mediatek.inc [(172.21.101.126)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 326804425; Fri, 17 Nov 2017 09:23:21 +0800 Received: from mtkcas08.mediatek.inc (172.21.101.126) by mtkmbs03n2.mediatek.inc (172.21.101.182) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Fri, 17 Nov 2017 09:23:18 +0800 Received: from [172.21.77.33] (172.21.77.33) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1210.3 via Frontend Transport; Fri, 17 Nov 2017 09:23:18 +0800 Message-ID: <1510881798.3024.43.camel@mtkswgap22> Subject: Re: [PATCH v4] dma-debug: fix incorrect pfn calculation From: Miles Chen To: Andrew Morton CC: Christoph Hellwig , Robin Murphy , , , , , , Christoph Hellwig Date: Fri, 17 Nov 2017 09:23:18 +0800 In-Reply-To: <20171116161350.3b8bd1fbcaae8e032441d3e7@linux-foundation.org> References: <1510872972-23919-1-git-send-email-miles.chen@mediatek.com> <20171116161350.3b8bd1fbcaae8e032441d3e7@linux-foundation.org> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.2.3-0ubuntu6 Content-Transfer-Encoding: 7bit MIME-Version: 1.0 X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2017-11-16 at 16:13 -0800, Andrew Morton wrote: > 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. I am truly sorry about this. I was not sure if I can submit a patch based on a linux-next patch, so I submit a new patch based on the latest mainline kernel again. I know how to do this now. I will do it correctly next time. Is there anyway to fix this? (send another patch with v3 discussion and the difference from earlier versions to the commit message). > 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 1584299430012978510@xxx Fri Nov 17 08:01:15 +0000 2017 X-GM-THRID: 1584299430012978510 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread