Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp507421yba; Wed, 24 Apr 2019 05:14:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqzZukCh19NbQSxHi11YuwyUB4vnS19TWa9+kLx7EyyptbnXtV4f5g3MxSLuzUxd13QxrAYb X-Received: by 2002:a17:902:8a4:: with SMTP id 33mr32284655pll.7.1556108049351; Wed, 24 Apr 2019 05:14:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556108049; cv=none; d=google.com; s=arc-20160816; b=HKSoz4UVQNuhK7GF5A5S0Yua0gOtttvbFJLUlJy6IEJqPAh4/zOgC4i1I0Udt7//l4 czDYJzuGW6c6xZ1o/WfeAC+F7U/dZ1pNi6kJEALrB5ymBd1Oqzq09FvoTXCITw3yQgwa TswA6srtYUSQtaBEaZ8cazkJNfqq8TTpDZcSh+sLihhgZDdKVO/Wxuf9TfJf2Cpw2LKE TfcR9R5vnDad4zZh3+8T3Wpsk5sLWRwMtexurfQrOyJ3DPFyW2o9+wcyTcahakI2vmy/ 6nFQ2g5U9/QN1JmWLCzKPz7U/8GE/mKWOptyMwvy0DxmRjH/wd5m05H2Sk6CBkSVvZdZ Pwzw== 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=P4kNFa5nAoLlIilAZZGvq0F01cTlmh++x5YtPphCZ/A=; b=e/jk33s8NV2OOBSOz+q7ewUVgRJH7eBe1+oUIixQkQDWIdOrG5vdJvM4gMTu3HhASb d3bQfKyLfmHtXSM9teKZj0AOqlMBW8MYWL85kAJrYxxEG85Q0qbEatTPJ2H6q806vn3J hbt4S5rbzK+pvf1kzAk3GbHcXgGoZzhUldg1sBQT46CSO5qlLHvF1GziX74YgId/zSPS C2dtBllqZGQiuxgacgJLTRmlTW+82vr0ZIKk8Lwv5jhqTVD7TK845cif10L0lt05iDEe WCkQqph+FzV4iIwYY7O2kVEtSLsBKPInPBzEAC7CA4wPEZoCdChQLkN9pwcT+rxy63w3 N+GA== 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 e14si18781621pfn.203.2019.04.24.05.13.53; Wed, 24 Apr 2019 05:14:09 -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 S1728399AbfDXMMl (ORCPT + 99 others); Wed, 24 Apr 2019 08:12:41 -0400 Received: from esa6.microchip.iphmx.com ([216.71.154.253]:24082 "EHLO esa6.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726211AbfDXMMl (ORCPT ); Wed, 24 Apr 2019 08:12:41 -0400 X-IronPort-AV: E=Sophos;i="5.60,389,1549954800"; d="scan'208";a="28036781" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa6.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 24 Apr 2019 05:12:39 -0700 Received: from localhost (10.10.76.4) by chn-sv-exch06.mchp-main.com (10.10.76.107) with Microsoft SMTP Server id 14.3.352.0; Wed, 24 Apr 2019 05:12:39 -0700 Date: Wed, 24 Apr 2019 14:12:38 +0200 From: Horatiu Vultur To: Paul Burton CC: "ralf@linux-mips.org" , "jhogan@kernel.org" , "linux-mips@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [Resend] arch: mips: Fix initrd_start and initrd_end when read from DT Message-ID: <20190424121236.uadnsmgg3ctvljdo@soft-dev3.microsemi.net> References: <1555409900-31278-1-git-send-email-horatiu.vultur@microchip.com> <20190419205456.uylahdin2jlkeyyy@pburton-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline In-Reply-To: <20190419205456.uylahdin2jlkeyyy@pburton-laptop> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Paul, Thank you for your detail explanation. There are few observations below. The 04/19/2019 20:55, Paul Burton wrote: > External E-Mail > > > Hi Horatiu, > > On Tue, Apr 16, 2019 at 12:18:20PM +0200, Horatiu Vultur wrote: > > When the bootloader passes arguments to linux kernel through device tree, > > it passes the address of initrd_start and initrd_stop, which are in kseg0. > > But when linux kernel reads these addresses from device tree, it converts > > them to virtual addresses inside the function > > __early_init_dt_declare_initrd. > > I'm not sure I follow - if the bootloader provides an address in kseg0 > then it's already a virtual address. So I am just a novice in this, but in my case the bootloader(Uboot) passes the address in kseg0(e.g 0x9f8a6000), but if I understand correctly this is just cached access to location 0x1f8a6000. > > It looks like __early_init_dt_declare_initrd expects the DT to provide > physical addresses, which fits in well with the fact that DTs generally > use physical addresses for everything else. > > __early_init_dt_declare_initrd calling __va on a virtual address will > give you something bogus, and it looks like you're just cancelling this > out below. In practice for a typical system where PAGE_OFFSET is the > start of kseg0 (0x80000000) the bogus address you get will happen to be > the same as the physical address, but that's not guaranteed. > > > At a later point then in the function init_initrd, it is checking for > > initrd_start to be lower than PAGE_OFFSET, which for a 32 CPU it is not, > > therefore it would disable the initrd by setting 0 to initrd_start and > > initrd_stop. > > The check you mention here is to make sure initrd_start looks like a > virtual address - if it's lower than PAGE_OFFSET (typically 0x80000000) > then it looks bad & initrd is disabled. I think your comment is > backwards - what you have is a physical address, entirely by accident, > and you're converting it back to a virtual address again by accident > which keeps the check happy. I am a little bit confused here. so the initrd_start has to have a virtual address(in kseg0) inside the function init_initrd. Meaning that when the bootloader passes the arguments to linux through a command line, then initrd_start has to be already a virtual address? Because I couldn't see a place where it converts the initrd_start. But when the bootloader pass the arguments through DT it has to be physical address? > > > The fix consists of checking if linux kernel received a device tree and not > > having enable extended virtual address and in that case convert them back > > to physical addresses that point in kseg0 as expected. > > Can you instead just have your bootloader provide physical addresses in > the DT? Yes, I have done few tests and it seems to work fine, but I need to understand it better. > > Even if we were to have this code try to sanitize the value with > something like __va(__pa(initrd_start)), it only covers systems using > the UHI boot protocol which isn't the only way we can obtain a DT. If a > system builds in its DTB for example it'll get different behaviour to if > it's passed via the UHI protocol by the bootloader. > > Thanks, > Paul > > > Signed-off-by: Horatiu Vultur > > --- > > arch/mips/kernel/setup.c | 11 +++++++++++ > > 1 file changed, 11 insertions(+) > > > > diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c > > index 8d1dc6c..774ee00 100644 > > --- a/arch/mips/kernel/setup.c > > +++ b/arch/mips/kernel/setup.c > > @@ -264,6 +264,17 @@ static unsigned long __init init_initrd(void) > > pr_err("initrd start must be page aligned\n"); > > goto disable; > > } > > + > > + /* > > + * In case the initrd_start and initrd_end are read from DT, > > + * then they are converted to virtual address, therefore convert > > + * them back to physical address. > > + */ > > + if (!IS_ENABLED(CONFIG_EVA) && fw_arg0 == -2) { > > + initrd_start = initrd_start - PAGE_OFFSET + PHYS_OFFSET; > > + initrd_end = initrd_end - PAGE_OFFSET + PHYS_OFFSET; > > + } > > + > > if (initrd_start < PAGE_OFFSET) { > > pr_err("initrd start < PAGE_OFFSET\n"); > > goto disable; > > -- > > 2.7.4 > > > -- /Horatiu