From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751035AbdJAIEz (ORCPT ); Sun, 1 Oct 2017 04:04:55 -0400 Received: from verein.lst.de ([213.95.11.211]:59482 "EHLO newverein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750980AbdJAIEv (ORCPT ); Sun, 1 Oct 2017 04:04:51 -0400 Date: Sun, 1 Oct 2017 10:04:49 +0200 From: Christoph Hellwig To: Robin Murphy Cc: miles.chen@mediatek.com, Christoph Hellwig , Marek Szyprowski , Andrew Morton , wsd_upstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, iommu@lists.linux-foundation.org, linux-mediatek@lists.infradead.org Subject: Re: [PATCH v3] dma-debug: fix incorrect pfn calculation Message-ID: <20171001080449.GB11843@lst.de> References: <1506484087-1177-1-git-send-email-miles.chen@mediatek.com> <273077fd-c5ad-82c8-60aa-cde89355e5e8@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <273077fd-c5ad-82c8-60aa-cde89355e5e8@arm.com> User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 27, 2017 at 11:23:52AM +0100, Robin Murphy wrote: > > 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(). Hmm, can the debug code assume anything? Right now you're just patching it from supporting linear and vmalloc. But what about other potential mapping types? > > + entry->pfn = is_vmalloc_addr(virt) ? vmalloc_to_pfn(virt) : > > + page_to_pfn(virt_to_page(virt)); Please use normal if/else conditionsals: if (is_vmalloc_addr(virt)) entry->pfn = vmalloc_to_pfn(virt); else entry->pfn = page_to_pfn(virt_to_page(virt)); > > + .pfn = is_vmalloc_addr(virt) ? vmalloc_to_pfn(virt) : > > + page_to_pfn(virt_to_page(virt)), Same here.