Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2408174yba; Mon, 15 Apr 2019 10:59:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqz6Aa3GNod26fRndZKqo4TNnQD0yMTBH42UdwHdrZGJX+XfJUQso4priD3S+M1facaESpSw X-Received: by 2002:a63:7943:: with SMTP id u64mr70806183pgc.91.1555351144558; Mon, 15 Apr 2019 10:59:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555351144; cv=none; d=google.com; s=arc-20160816; b=06vZkm+Jz1N3eJMGs4ya3jjndwXhMyMIVl8mIsW6KVysHhBs8G62R/hCbV4LDR6ggj dy7SeCQ7Dr6hiBeAP1/IgafhRsM8YKFC74Twci1LUczGEqLibk7psb9h6UtRqXabANX5 xDHotIf3DM09oxaHr2ZGyKfuYG5us4504q5cvuBUl8qkmI0uj/ADXa0Kd/IvyOoaMOp4 LFd+T3rZ3PW2mkcR0RypS9AhA0aWvZH3Z0A905P6kVOLNu7T7T7WXgm0vH7LZxJDD8rw v+xlhQhz7+RUdO767GesNoqXAjelEc2mROtVuVkfuk5Iz5x0kigT53n3jhli/UP3TzAn YawA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=GD/WELDhcPqB3lwQmw5TNGIzm3wwqEYdTWnqAfYbh68=; b=m/d27IBRNPfjeKh0WB+8HA+pUq7h0IpLu4WytZpBABtJqK+FHOr5MuEJVWmcuJpYHS 7K8sKTQPP9aKvn7r9Q/rQjSyKxi5+g22R2aHh+F7ub97Q5OhjanBYFJH5aTUJaMi6+f7 TAxedBgyKfWy9Icggt5wYnqhCLs7xyswcpEfz/oB9Ref4NC7kdBnXPofMjxh8oVgAAQt x+tn2wSu/RsL1Ja1zFudMXSL4zQvAeQPVpKE0k4hUyHjDvcDwoRh6ez5AyZUDyQ4rd/w FIK55B+i5d5pg/7PX4fImVXlH2BUPzxS3drdyOKm5GHMmlPUN+XlGbeEe8PrpM9u1Zhk IglQ== 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 l18si44800459pgk.289.2019.04.15.10.58.46; Mon, 15 Apr 2019 10:59:04 -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 S1727937AbfDORgp (ORCPT + 99 others); Mon, 15 Apr 2019 13:36:45 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:23539 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1727490AbfDORgo (ORCPT ); Mon, 15 Apr 2019 13:36:44 -0400 X-UUID: f17344b417b24d7a9176044fd3f84ed4-20190416 X-UUID: f17344b417b24d7a9176044fd3f84ed4-20190416 Received: from mtkmrs01.mediatek.inc [(172.21.131.159)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1714215129; Tue, 16 Apr 2019 01:36:39 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs08n1.mediatek.inc (172.21.101.55) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 01:36:37 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Tue, 16 Apr 2019 01:36:37 +0800 From: Miles Chen To: Catalin Marinas , Will Deacon CC: , , , , Miles Chen , Ard Biesheuvel Subject: [PATCH] arm64: mm: check virtual addr in virt_to_page() if CONFIG_DEBUG_VIRTUAL=y Date: Tue, 16 Apr 2019 01:36:36 +0800 Message-ID: <1555349796-9456-1-git-send-email-miles.chen@mediatek.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 -- 2.18.0