Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3366372ybz; Mon, 20 Apr 2020 01:04:01 -0700 (PDT) X-Google-Smtp-Source: APiQypJxalmmFpudNxA7y3m6qmZV7WCauvgbli1mDTU65XgWFPyQl7gkkIggoDWD7t0wBleT++g4 X-Received: by 2002:a17:906:da1b:: with SMTP id fi27mr14662335ejb.194.1587369840666; Mon, 20 Apr 2020 01:04:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587369840; cv=none; d=google.com; s=arc-20160816; b=UXrb7KU2PyZD1iS/0CwhVjNiTBqXOOy4DJPB8dQCVJZSkNOuR7juWVV2tMHtp6eVkv 6MrGgUWXNWP1c/pAhrXIA53UUK1EGkjnemN+EWGwRvgyLvtCHDS2VabfLpYRQ1TmdaqX EXMwizyjQItTSOdF03nxitLHlv/6hMgR+bN8ni/8Z31Q5CIxKaWR2+8QvCE2bteaem6y TYL9DsqXuRsOho2QTHUqOGzqdp8kQlCBdf5mhtnWbLLvwZzgcjrHPGFBQLUfUOUW7pjp WXgKyA4YOoWIqfg+EhxQ6vywhJNkOWgTGNWhPKr8sVSGuou3evCrzaFAK8fr5LMYxlxb 1TEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=3xcya7M/sEvPLWNBKP6Q1scBZdGSUS616tgCh9F9c7Q=; b=vnc2PAxHX/G/q3W8LLG15pt/fa1ubE+aS562Jvi+X0xZRICAy0YWNGCUfafMpUlsB/ pymRO1QYgXBNFusxNNb0O9BR/HuU9ZjkvTLrwprge0C1KLbkXEbOE2YGYW/pPTdoz86S HNehC9mO78SDizt2T/qlOslx/191duV2hgiS0DAhpIoMYfRS0aqJimGktFfHS/opnpp4 93HdYagFlcQI72z6nJlMwFzjm04OdMJuhsXhf7phzlSvIogQZVPbeGoFD6vu1eF9Rbgi ObAErtQ2cvd/3OcB51BopVAqUFX2jaPFeZL8pkuQF1FIUqrWbtNasyRVCMJZVlRYafRG N/Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MTffXFCO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k15si125345edk.194.2020.04.20.01.03.37; Mon, 20 Apr 2020 01:04:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MTffXFCO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726495AbgDTICT (ORCPT + 99 others); Mon, 20 Apr 2020 04:02:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:44642 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726048AbgDTICR (ORCPT ); Mon, 20 Apr 2020 04:02:17 -0400 Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8682C22202; Mon, 20 Apr 2020 08:02:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587369736; bh=3xcya7M/sEvPLWNBKP6Q1scBZdGSUS616tgCh9F9c7Q=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=MTffXFCO//iyqq/dquWfsII+EQEvkEl1aut2+SzUn9L92VGIKyAl+Zm4GLZNl0hc4 TJCmR3MNkNjeRWVy80plCLzKyL2JfHIMnLkHphHzYUcoigLfmXVjVoyxaTEIz5DSVz L4kzv2fjHZ7yumEV6roTQ5RKVKgOPBYyBW1eJCiY= Received: by mail-ed1-f50.google.com with SMTP id d16so6342413edv.8; Mon, 20 Apr 2020 01:02:16 -0700 (PDT) X-Gm-Message-State: AGi0PuZXmOBedT5pfLif8VBhvZdqJSQyeo2HaMN8f6kowQUePh6JAkPl 3tKXf4mTycR9QEnyVBW6fQ7Np0NNM5r/sB1MAL4= X-Received: by 2002:aa7:c0d1:: with SMTP id j17mr12138364edp.308.1587369734880; Mon, 20 Apr 2020 01:02:14 -0700 (PDT) MIME-Version: 1.0 References: <20200415195422.19866-1-atish.patra@wdc.com> <20200415195422.19866-6-atish.patra@wdc.com> In-Reply-To: From: Ard Biesheuvel Date: Mon, 20 Apr 2020 10:02:03 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [v3 PATCH 5/5] RISC-V: Add EFI stub support. To: Atish Patra Cc: Atish Patra , "masahiroy@kernel.org" , "linux-riscv@lists.infradead.org" , "linux-efi@vger.kernel.org" , "palmer@dabbelt.com" , "catalin.marinas@arm.com" , "linux-kernel@vger.kernel.org" , "arnd@arndb.de" , "will@kernel.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 20 Apr 2020 at 09:59, Atish Patra wrote: > > On Mon, Apr 20, 2020 at 12:04 AM Ard Biesheuvel wrote: > > > > On Mon, 20 Apr 2020 at 06:20, Atish Patra wrote: > > > ... > > > > > > "If the preferred address is set as the base of DRAM, efi_bs_call is > > > bound to fail as well because the base of DRAM is reserved by the > > > firmware. So the efi memory allocator can't allocate at that address. > > > Technically, it will work but it is no different than passing > > > ULONG_MAX. So I thought ULONG_MAX will avoid the confusion. > > > > > > We try to allocate as low as possible so I am passing dram_base as the > > > minimum address anyways. As the firmware reserved the first few KBs, > > > > > > > > > OK, so the preferred address *is* the base of DRAM (assuming it is 2 > > MB aligned). However, in the general case, you keep some firmware > > state there (couple of KB) and so you typically end up at DRAM base > > plus 2 MB? > > > > Yes. > > > So first question: why does the firmware put this stuff at the base of > > DRAM in the first place? Does it *have* to live there? > > > > The firmware includes the RISC-V specific supervisor binary interface (SBI)[[1] > implementation. As it is a RISC-V specific run time service provider, > it has to be resident in memory. > The arm equivalent of SBI would be PSCI. > > [1] https://github.com/riscv/riscv-sbi-doc/blob/master/riscv-sbi.adoc > I am not asking why it has to be resident in memory. I am asking why it has to be at the *base* of memory. > > Then, if the base of DRAM is guaranteed to be occupied, why not make > > the preferred address base of DRAM + 2 MB ? (or 4 MB for the 32-bit > > case) > > I guess that will work too. I was inclined to use low_alloc_above so > that we ensure that the kernel > boots from the lowest possible address given the alignment > restriction. If the alignment restrictions are relaxed, > in future, we just have to change the macro. > > However, I think calling relocate_kernel with a preferred offset > (dram_base + KIMG_ALIGN) is > better because it will always fall back to low_alloc_above anyways. I > will send the patch. Indeed. In the common case, it will just do the allocate_pages() directly, which is preferred. It will fall back to efi_low_alloc_aboce() [and do the memory map parsing and traversal etc] only if needed.