From patchwork Mon Jan 7 11:21:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miles Chen X-Patchwork-Id: 10750339 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0325B746 for ; Mon, 7 Jan 2019 11:21:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E2D172891F for ; Mon, 7 Jan 2019 11:21:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3D1B28960; Mon, 7 Jan 2019 11:21:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 774F92891F for ; Mon, 7 Jan 2019 11:21:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=baFkKYyVH4kz4ylJfggjo72id94k9ai/IWv5wuET3Lg=; b=gDHr8RX9+oErW4 I0ty+43GciSf95UU53YmjoHROkKwRhgdL8xbDbP3d9CRoK9rly5q/UsSL9c4gA/Vj06XzQpwXVGMG COTYbM0Ge27PNG8MWNzbn/J4c7xmk/6/YBG8n04roHu2diG9nDb773ow9dOad9oUFJJCSEaNkRof6 F63SEpSssqXGDSpRgR93jqtR8EIHsyV21CGQVFlD9KATk6am+zno1/KXIum/5Z47J3Mb47dK90Ht/ Jo/9s8tafO0iZvCTpJjxgXFY5/QX6vXrMf+UQIVNIr4vvcy9sQm2QkfepBA56pEz4gAmns9k5TrWk TpQZG3EGT12+4YJT5z8A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1ggSyU-0000zD-1b; Mon, 07 Jan 2019 11:21:42 +0000 Received: from mailgw01.mediatek.com ([216.200.240.184]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1ggSyQ-0000yp-Sf; Mon, 07 Jan 2019 11:21:40 +0000 X-UUID: aaff68078e72464e99ab946cf71b1e84-20190107 X-UUID: aaff68078e72464e99ab946cf71b1e84-20190107 Received: from mtkcas67.mediatek.inc [(172.29.193.45)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 808047882; Mon, 07 Jan 2019 03:21:25 -0800 Received: from mtkmbs08n2.mediatek.inc (172.21.101.56) by MTKMBS62DR.mediatek.inc (172.29.94.18) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 7 Jan 2019 03: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 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 X-TM-SNTS-SMTP: 234332DA94720DE407A4821BBD08A888B8AD06626A5B9BD0790A841A1B7E05452000:8 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190107_032138_932719_698D9D3A X-CRM114-Status: UNSURE ( 8.20 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Miles Chen , linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, wsd_upstream@mediatek.com Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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);