Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3435611imu; Mon, 7 Jan 2019 03:22:54 -0800 (PST) X-Google-Smtp-Source: ALg8bN6nVDLs8HUEnIor29tDz9VrZyroi9Loxm0MfQN6Y2zJJtZrsSsU46jKnmHX6LmaZ6be7XaG X-Received: by 2002:a17:902:9006:: with SMTP id a6mr60120933plp.334.1546860174255; Mon, 07 Jan 2019 03:22:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546860174; cv=none; d=google.com; s=arc-20160816; b=zuUucUL25YQ7KngmihrqBMNxDik1IMoRuwPZOhLrL2BixuCjKeGAvXontwpIW4q6aX L+l2OGYaLEoKV+2NIZjN7fzS6bipClDkfSIyTywzilRNb26pbpq7yroweIDedC+ZICRI C3OR2l+sXDYgCuqrT4ZX7OIO8EjYtwC3+DQ8zdvO84boTpge37o9jmJVatJUNZRAefPr NoM/7aAFGGjOAAsxDQNtiq9rhtazSv2Vq+NoSBIYv2dAhAHsLXcR1Ipcm1s9sapiVRMR xRla5IDs7rpN1wz96zTh1im8AmqTuUUcjS51gvKYNU7SmNMp1tiSuq2EJ6NOey1/dMmc +5fw== 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=3QproDH42ywj7RVxkQNaHGer0jrmbCeD75ol2pOgXK4=; b=N1Hu1O5IcKg7VLP+BY4MM6Lvk2bQWYYXv5VbSzwR66501/Ht5+/rGMmcNp1EAn6P+1 l9dVYj6NS8ok9wTZ2B5Vewugr74axvwk9VRJ/BuSr1lXfCAg6gmBZWVxKml7rno6sdyk ICK1dm4jDO+RbNZIaP0Mcul+U0ET3GfytUVFvCSVEoWtVq8IfMWWDTi7HIfu/cpR0hga gfJJI1IOwdQ1Lv/KM5+bQvGocdmpuX2A8Bo/PZLgZRJvVx+P7ZSeTk9lzlDDqtji5jon ympuGqiWtWA5N2CD1ogsE2xrrKaU9qTEJ1WKKxfCV5F4cpxHBKM1K+yywB4oZgRiffJy D7PA== 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 c37si33348016pgm.156.2019.01.07.03.22.38; Mon, 07 Jan 2019 03:22:54 -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 S1727131AbfAGLVc (ORCPT + 99 others); Mon, 7 Jan 2019 06:21:32 -0500 Received: from mailgw01.mediatek.com ([210.61.82.183]:3962 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725550AbfAGLVb (ORCPT ); Mon, 7 Jan 2019 06:21:31 -0500 X-UUID: 8b8dea8163384ecb8d76bfe5e81adc3a-20190107 X-UUID: 8b8dea8163384ecb8d76bfe5e81adc3a-20190107 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 471533334; Mon, 07 Jan 2019 19:21:24 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs08n2.mediatek.inc (172.21.101.56) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 7 Jan 2019 19:21:21 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Mon, 7 Jan 2019 19:21:22 +0800 From: Miles Chen To: Catalin Marinas , Will Deacon CC: , , , , Miles Chen Subject: [PATCH] arm64: trap illegal translations in __virt_to_phys() Date: Mon, 7 Jan 2019 19:21:20 +0800 Message-ID: <1546860080-13027-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-TM-SNTS-SMTP: 234332DA94720DE407A4821BBD08A888B8AD06626A5B9BD0790A841A1B7E05452000:8 X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Current __virt_to_phys() only print warning messages for non-linear addresses. It's hard to catch all warnings by those messages. So add a VIRTUAL_BUG_ON() to trap all non-linear and non-symbol addresses (e.g., stack addresses) Tested by pass stack addresses and symbol addresses to __pa(). Result: stack addresses: kernel BUG() symbol addresses: kernel warning message Maybe we should trap all non-linear address translations in the future. Signed-off-by: Miles Chen --- arch/arm64/mm/physaddr.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/arm64/mm/physaddr.c b/arch/arm64/mm/physaddr.c index 67a9ba9eaa96..f6b935dad19c 100644 --- a/arch/arm64/mm/physaddr.c +++ b/arch/arm64/mm/physaddr.c @@ -14,6 +14,11 @@ phys_addr_t __virt_to_phys(unsigned long x) (void *)x, (void *)x); + /* trap all non-linear and non-symbol addresses */ + VIRTUAL_BUG_ON(!__is_lm_address(x) && + (x < (unsigned long)KERNEL_START || + x > (unsigned long)KERNEL_END)); + return __virt_to_phys_nodebug(x); } EXPORT_SYMBOL(__virt_to_phys); -- 2.18.0