Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp4358972ybz; Mon, 20 Apr 2020 22:08:21 -0700 (PDT) X-Google-Smtp-Source: APiQypJTBtsZJ1xzvh/GiMImtIjdLsPXGcuII9TqlgP3iE2hLUjsUtxuynmL1RXf+Ka/MeIdBxDm X-Received: by 2002:a05:6402:1cac:: with SMTP id cz12mr15847873edb.373.1587445700880; Mon, 20 Apr 2020 22:08:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587445700; cv=none; d=google.com; s=arc-20160816; b=uS3bl63BdtVti8K03WkeaUVZalFFl59VU4k6BndHzCK7iIIO/mLOk1PtHaNi7j6Jxm kUdjdq/Y6qtCw+fqSx9qMefmmJSpL0zxafLTxzRzkwBYv/MaqIoGGeir+2EAleIIB3vz VO3VAwx4vfDJ8TaNho5Ip1e0twR7hWPTXTWVSfcQ4GxAYHmGQZE+7jhXaQ/gT3uCKkNo PzouB0AB+0JXaH6Na9e3K3yGb8O7NbBjf6qH1GfTCq3hH0Q4mZIrhWHw+xhRcJ6hNffU DSV+xg1hCkwzjh/2Frlkzfxiw9qkY4hID3em/dMpXZ/228NyJdIN1QGyyM8VinOMLqpx ufow== 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=T22n9ZgIUDB3iwAvu4Bq1V9WbDX7+F8NlJ84vbdyBpU=; b=H6+JZuPI1tKAad3kQ8v85tgJtOth56qlq9eRdVmJN9G/svwHdS4OBzReYYIaWa+uSf WytQxun2u/zPFqrXLwSpt81HEvFSMCPH0HeZU65N74H0TgvdtcJpwNg0aOWPkXfIx0YP ziGYvsBLkgTAsaEtvIgmREaGOGOnHdEZr7w0lJYZ9m8gfKIa978NlP0zZjg7HyhtrSD9 e6Y9ZbHg6yQy5lRjxCoLUes5esnyKSOPtZAcnNFAaHo+ReaLWYWV56X3cyH+vuPQk8eS pBrz1MJJe2jjypCnFIbGgtdY/nFoGflzo6Y8Ty/koZUCHWKs9/PxCCHp7moaa6aoS5d2 lgFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=TbbEcTtb; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v22si957616eds.78.2020.04.20.22.07.51; Mon, 20 Apr 2020 22:08:20 -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=@atishpatra.org header.s=google header.b=TbbEcTtb; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726052AbgDUFGV (ORCPT + 99 others); Tue, 21 Apr 2020 01:06:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725881AbgDUFGU (ORCPT ); Tue, 21 Apr 2020 01:06:20 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F00CC061A10 for ; Mon, 20 Apr 2020 22:06:20 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id k1so14932991wrx.4 for ; Mon, 20 Apr 2020 22:06:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atishpatra.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=T22n9ZgIUDB3iwAvu4Bq1V9WbDX7+F8NlJ84vbdyBpU=; b=TbbEcTtbkUhu5j2yaYH+f+uFPiIpZ3yBjYVhCleGgNsF1aO4CgYh+UrghN6KBPBQcT IgpjQfPvPR6qPJN8AcPFeMzbjZxCPnbtdVHHHGMaGyO69yqPxQxRY7/l5L8NfejCVxIb wVPpsjcTehCzi4zdDmGXRhGX3uNGF+JmfmzQkUQExl0RbRk/bxjggB830/4xJrQlUMoE Ck3FVQ8pguhwrBJHadOAhR4PSQ2Hr/E3VFGt0+imcpMzUH7vhJePvH5s/42uFtQF1Kd6 Hl4dXHcvKSlIPs1a7HK3qH4h1h8NVBPk+1AuCoHJbvG1pyNDHSsouqLo7zPDvtZu8NaL iGuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=T22n9ZgIUDB3iwAvu4Bq1V9WbDX7+F8NlJ84vbdyBpU=; b=NyIAYuaik8aSkyFLomwNc56WbnyDDCzR+qa5JOthdXII+olb6xXo9e5ecPvGdeNF3D Ws017CEemso43IwmCO4eicwh/zwqD5X1OM7m4Ue8w6cgl+nuvJtUyfd/s2KBY5TqBzwl thOcBul8Kjxi/6uvxAHwPCYXbeRu7C3xRoE6E+ME8qqvFSv6xV4lt0YciIU8sAi79dAr cQJIfsP+3rvy7n0oZm2a9HefiPgFPTulSFIWAiR3JnqUbHab7xKnYygbWp/jHibCMYty Pjo3F1TfQZqHuQMR0t2Ykf7nidyslIBzN0e8AZrKTm66B4rybT3bHQ+QhZdKirRzHvbi +YSw== X-Gm-Message-State: AGi0PuZY0kcIaQWQe1fGs+/r6zVe3rtXfkQqjPGuX6xKpWJaq5U2BRyL MXhLeuz4DRUBpBGVQvx2m1qM0LvUWwLc2X1y1qV0 X-Received: by 2002:a5d:4443:: with SMTP id x3mr21644255wrr.162.1587445578746; Mon, 20 Apr 2020 22:06:18 -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: Atish Patra Date: Mon, 20 Apr 2020 22:06:07 -0700 Message-ID: Subject: Re: [v3 PATCH 5/5] RISC-V: Add EFI stub support. To: Ard Biesheuvel Cc: Atish Patra , "linux-riscv@lists.infradead.org" , "linux-efi@vger.kernel.org" , "palmer@dabbelt.com" , "linux-kernel@vger.kernel.org" , "arnd@arndb.de" , Anup Patel 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, Apr 20, 2020 at 1:02 AM Ard Biesheuvel wrote: > > 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. > Sorry. I misunderstood the question. I think it is kept at the start of dram to accommodate embedded systems with smaller memory. It was also easier to manage at the beginning of the memory because all other next stages in the boot process just ignores first few KBs of the memory. We also did not have a memory reservation scheme back then. Having said that, this parameter is configurable for each platform in OpenSBI. In future, this restriction can be relaxed if a platform vendor wants. IIRC, linux kernel can't use the memory below the kernel start address (where PAGE_OFFSET is mapped) because of generic mm code limitations. Added Anup (In case he wants to add something to this) > > > 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. -- Regards, Atish