Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4262262imu; Mon, 7 Jan 2019 19:27:22 -0800 (PST) X-Google-Smtp-Source: ALg8bN6o5I/5R9wrY0ftlFLbylAY0ot4ihZVJ4KpbZvrwf0W9BeQjde/iyYe5WEU+un8c0D39ZRx X-Received: by 2002:a17:902:e18d:: with SMTP id cd13mr106632plb.262.1546918042609; Mon, 07 Jan 2019 19:27:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546918042; cv=none; d=google.com; s=arc-20160816; b=l4EhGbvy79+RoNE3P4P8pEv5NY8uF76iXXZ0I+MmHGt9mKEJKw0vFQrtw7krEJIS95 y8vIgtESDkllyHqrFCie3+q3IQEC1syHn9C18gLgHJGXR4brqj68i3Om1GFLxuQarZg5 lMebwGLE2Lbq3F5EP/BpT6R+WP9UWVwzxAoHsSKXYWMsotDNcH5ZN5jZqjKA++gazdSf IUbThXvG7aTH9RuLcI858eUER/TWCYaLY3qzvw5W0h0NZ1Abdqvz4NKQ3ECNhsJ0Qrc1 vyLu6XXA8FiYwBoq/iqR3GMp3mg1BHsCqTQFc4lKwQkUHaKzSB3ac+l32oCzTTtRL+rr Nudw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :references:in-reply-to:date:cc:to:from:subject:message-id; bh=wv8bPFG2wHfR7aluUzLHcqQaHRRyu+VJl0AhJWj/lTI=; b=iPQDIyuHLqd17M9ZrASPZgrUSfnrKT5yVkhZQFdCHrUYmEf3gzbxJX9iH2TngfJ5xY ch7qvDp+eS+8GCe4LgPxaH0/W5hQ9xY0N4PSw6DernxT3zutTr5AbcMeqgTKprpIqcf2 TdcUfqvyizz1HDr/BIcC/0URNJod2fgcmFvK2GogA8/jWneCfkJTKgSYTxtX6ZO/Mx66 03ySGTFOO7846xQt1HX3P5Y81+o0K2y+hEQio4+fiO4v07+cRNTmXRNACjKXVDnc1YF/ Aqq+nIEO66GTBFV79f84/hlS39nT5Yf+GSJfdYcUmDrmdhwKuxQNfnlKtVr0XKjqSuGx xR6Q== 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 i20si63136759pgh.187.2019.01.07.19.27.06; Mon, 07 Jan 2019 19:27:22 -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 S1727554AbfAHDZA (ORCPT + 99 others); Mon, 7 Jan 2019 22:25:00 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:13278 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1727030AbfAHDZA (ORCPT ); Mon, 7 Jan 2019 22:25:00 -0500 X-UUID: 963b6ed344c64603bf61c6f016fea25b-20190108 X-UUID: 963b6ed344c64603bf61c6f016fea25b-20190108 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 186511454; Tue, 08 Jan 2019 11:24:51 +0800 Received: from MTKMBS06N2.mediatek.inc (172.21.101.130) by mtkmbs02n1.mediatek.inc (172.21.101.77) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 8 Jan 2019 11:24:43 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs06n2.mediatek.inc (172.21.101.130) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 8 Jan 2019 11:24:43 +0800 Received: from [172.21.77.33] (172.21.77.33) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Tue, 8 Jan 2019 11:24:43 +0800 Message-ID: <1546917883.6754.8.camel@mtkswgap22> Subject: Re: [PATCH] arm64: trap illegal translations in __virt_to_phys() From: Miles Chen To: Mark Rutland CC: Catalin Marinas , Will Deacon , , , , Date: Tue, 8 Jan 2019 11:24:43 +0800 In-Reply-To: <20190107150019.GC46743@lakrids.cambridge.arm.com> References: <1546860080-13027-1-git-send-email-miles.chen@mediatek.com> <20190107150019.GC46743@lakrids.cambridge.arm.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.2.3-0ubuntu6 Content-Transfer-Encoding: 7bit MIME-Version: 1.0 X-TM-SNTS-SMTP: CF316DC2706CB07A686B9BCABA81EC80B486DB3C62FD6C297DC7DBA4C053A0FD2000:8 X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2019-01-07 at 15:00 +0000, Mark Rutland wrote: > 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? Official kernel works fine. I saw some cases in our internal branch and we're fixing them. > > > 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. For the first case: for vmap'd stack, __pa() returns a junk physical address and it might be easier to debug this incorrect address translation by a BUG() call instead of monitoring the warning log. Like __phys_addr_symbol() does. __phys_addr_symbol() uses VIRTUAL_BUG_ON() for non symbol addresses. > > > 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.