Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3641683imu; Mon, 7 Jan 2019 07:02:06 -0800 (PST) X-Google-Smtp-Source: ALg8bN6P3TmWpRExrfB/AWwnD+ziIZtyUwc3onRVPnoN/Cbcc8KfDYDpEC0xV0XXv5WS/m1EUb4X X-Received: by 2002:a65:4ccb:: with SMTP id n11mr30885947pgt.257.1546873326267; Mon, 07 Jan 2019 07:02:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546873326; cv=none; d=google.com; s=arc-20160816; b=yB2wxTw/XYzL7kwM8+oEol26WHyuTVF+dVPGKuQHXq3wAjrnKa10/O3lt11bXjxnQz nvw5G8TfovxqUeUrv/0E9ceVHtifnwCIXLSJX2Ki1Bh7KFGpoBGJ3YDMMWarv/1eqgSY IJwOB/RG49NvL942b4p0d4JlvbN73nwLQBn+CLdylzhGd0yMkim4jA3R+TIn2o8yOzs1 7hPg35El9uiAzhJA0/gW+ukqYoTA+/Up9PsVLqXhPkXiSx+ns9v2RSVnaTqIJP1NpraC 1cM6eYX7fZXkWPnJilDz0rNd7hREWpmuHjNI/O7sMUbciyuCCV1PGUucZFv5HrZm7UoS LLiw== 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=ZUJul9UzEAhfuFIFt3ED7Thce7Ss+d0uDRbHRiGBX3Q=; b=wxKDjsES5OrJfsUyjvYDRcK2N7kLJb5Q7D2WC9t4mOuLoUSHn3xY4OT5QBcc/DWLbp 4cObwd1Q+bRl1bhFS2YWdfS+gUavhIteBnt7hArnEmMcgdcNi5si2CYjeU8e4wsHmPDY tSxmHl6qFZYntFdzPGVTfJxfPKsoHNK/9e6FdGj+6TW2kIPip2nOpWBhHeoaESb207qB YTqXmRsIXJ5NbU2x/Xfp3LecBXctToL/Ey+k7Qsysxl2GaU7b5WM0P4n/IQsGXTEL4Aq 1tNNA4wCDn/mH0Pb8+szm6+/dsV/Ci0oJnq5BOxq/m94isf/3XvSOSHh8I7lGIsowoMd SydA== 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 i190si35059343pfc.116.2019.01.07.07.01.50; Mon, 07 Jan 2019 07:02:06 -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 S1729117AbfAGPAY (ORCPT + 99 others); Mon, 7 Jan 2019 10:00:24 -0500 Received: from foss.arm.com ([217.140.101.70]:32806 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727343AbfAGPAY (ORCPT ); Mon, 7 Jan 2019 10:00:24 -0500 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 6372480D; Mon, 7 Jan 2019 07:00:23 -0800 (PST) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0979E3F5B7; Mon, 7 Jan 2019 07:00:21 -0800 (PST) Date: Mon, 7 Jan 2019 15:00:19 +0000 From: Mark Rutland To: Miles Chen Cc: Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, wsd_upstream@mediatek.com Subject: Re: [PATCH] arm64: trap illegal translations in __virt_to_phys() Message-ID: <20190107150019.GC46743@lakrids.cambridge.arm.com> References: <1546860080-13027-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: <1546860080-13027-1-git-send-email-miles.chen@mediatek.com> User-Agent: Mutt/1.11.1+11 (2f07cb52) (2018-12-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 07, 2019 at 07:21:20PM +0800, Miles Chen wrote: > Current __virt_to_phys() only print warning messages for non-linear > addresses. It's hard to catch all warnings by those messages. Why? Are you seeing a large number of warnings somewhere? > 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() Either: * Stacks are vmap'd, and __is_lm_address(stack_addr) is false. We'll produce a WARNING() today (and return a junk physical address). * Stacks are linear mapped, and cannot be distinguished from other linear mapped addresses. The physical address will be valid. ... so I don't understand why you need to change this. > symbol addresses: kernel warning message That should already be the case today, since the kernel image is mapped separately from the linear map, so __is_lm_address(symbol_addr) should be false. > > 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)); The KERNEL_START and KERNEL_END definitions refer to the kernel image, not the linear map, so it doesn't make any sense to permit those here. It is *not* valid to call __virt_to_phys() with a symbol address. We only support those in __virt_to_phys_nodebug() so that broken code has a chance of stumbling on. If you want the kernel to die immediately when it hits a warning here, please set panic_on_warn. Thanks, Mark.