Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3086567yba; Tue, 16 Apr 2019 04:33:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqwCTd0+jTZ11xMPcijvXlLhYEwd8W1L8utM2I5fy41Ef7/LTVmM6jYnmJDTWpubYOsVgXPN X-Received: by 2002:a17:902:8bc3:: with SMTP id r3mr24070620plo.53.1555414399233; Tue, 16 Apr 2019 04:33:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555414399; cv=none; d=google.com; s=arc-20160816; b=J32XaH8rQrWaN3om1duEL5ft6goI4WuPM8WJ4FHfZm4+5fx0NzsS/O+qFiCwbaaYgc j4HryGKSSjVI92MydRAjVH0DqzO/f4CNC5HRdFCKTYkgnuq4qsrP7IGL0kIpd915G3yR MDPCawwew/XpbNfgL7xJt8FPhO3MDAnWssZ4Zzu53bJyl4SDHkrwOOZbDjlUWNEaxS+W fPI28mAA8rJQmG93zJFeDEnaaRzaHaYxPI9PoXFCtHK+4d6DsN8OSxlr13932Y0I2KUa NoFPsKYPkwcEH6iQQm694FjCH6pV034gWwjnQOTbBgJnX/mmGri3u1+21P0l0bfEekcF HzBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=2R8gWNnqmk6+BOCO7WKYHUYfqtL5K6VZIDBFGNRZ8j0=; b=LQ+/fd0mVx24VfQeMBRVcywWYMSAKrmvdSh51HnKAmrYUzXbpeB1JH0wE3DJ/SGVYv mlswN7zXIHxDkzEzuh+Ft8l/FZIJq6IBMOhAH0wC+feYPt0x3uUSgptTxtFWinCc5KaL IYJtbqHquu0GiCf+0VeVeQ3f6fdIV443PxashKFssuPjShkOyW9XMOk+JiXM/07Nu+yR SXwkBtOJbv7zL24eyMk3+eLAr4ntaxZAfI5zhqbJsgbEmjX/r3dQOXXK0W8NDLinp11K HxzvRF3ettRL9hpLIz2pLTXID7pRJ/7L2emUVeJ+Iecfl2j44ljNoF/T5KWWQqapQ0bW iSVQ== 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 31si24812175plz.116.2019.04.16.04.33.02; Tue, 16 Apr 2019 04:33:19 -0700 (PDT) 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 S1728569AbfDPLbD (ORCPT + 99 others); Tue, 16 Apr 2019 07:31:03 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:52774 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726672AbfDPLbC (ORCPT ); Tue, 16 Apr 2019 07:31:02 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 46DF980D; Tue, 16 Apr 2019 04:31:02 -0700 (PDT) Received: from arrakis.emea.arm.com (arrakis.cambridge.arm.com [10.1.196.78]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E40093F68F; Tue, 16 Apr 2019 04:31:00 -0700 (PDT) Date: Tue, 16 Apr 2019 12:30:58 +0100 From: Catalin Marinas To: Miles Chen Cc: Will Deacon , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, wsd_upstream@mediatek.com, Ard Biesheuvel Subject: Re: [PATCH] arm64: mm: check virtual addr in virt_to_page() if CONFIG_DEBUG_VIRTUAL=y Message-ID: <20190416113057.GA28994@arrakis.emea.arm.com> References: <1555349796-9456-1-git-send-email-miles.chen@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1555349796-9456-1-git-send-email-miles.chen@mediatek.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 16, 2019 at 01:36:36AM +0800, Miles Chen wrote: > This change uses the original virt_to_page() (the one with __pa()) to > check the given virtual address if CONFIG_DEBUG_VIRTUAL=y. > > Recently, I worked on a bug: a driver passes a symbol address to > dma_map_single() and the virt_to_page() (called by dma_map_single()) > does not work for non-linear addresses after commit 9f2875912dac > ("arm64: mm: restrict virt_to_page() to the linear mapping"). > > I tried to trap the bug by enabling CONFIG_DEBUG_VIRTUAL but it > did not work - bacause the commit removes the __pa() from > virt_to_page() but CONFIG_DEBUG_VIRTUAL checks the virtual address > in __pa()/__virt_to_phys(). > > A simple solution is to use the original virt_to_page() > (the one with__pa()) if CONFIG_DEBUG_VIRTUAL=y. > > Signed-off-by: Miles Chen > Cc: Ard Biesheuvel > --- > arch/arm64/include/asm/memory.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h > index 290195168bb3..2cb8248fa2c8 100644 > --- a/arch/arm64/include/asm/memory.h > +++ b/arch/arm64/include/asm/memory.h > @@ -302,7 +302,7 @@ static inline void *phys_to_virt(phys_addr_t x) > */ > #define ARCH_PFN_OFFSET ((unsigned long)PHYS_PFN_OFFSET) > > -#ifndef CONFIG_SPARSEMEM_VMEMMAP > +#if !defined(CONFIG_SPARSEMEM_VMEMMAP) || defined(CONFIG_DEBUG_VIRTUAL) > #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) > #define _virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT) > #else IIUC, this shouldn't change the behaviour of virt_addr_valid(). The patch looks fine to me. Acked-by: Catalin Marinas