Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp3487087pxy; Tue, 4 May 2021 03:31:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqb5R4DUo/xvxO09AN3w5OQ4QSU1ju2UeXZoga8+UeDS+8a00ZTCKTYKB9LSazZh3T15KT X-Received: by 2002:a63:1d19:: with SMTP id d25mr22440742pgd.169.1620124276920; Tue, 04 May 2021 03:31:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620124276; cv=none; d=google.com; s=arc-20160816; b=ymjqy7XsbxFrPu7w9cTrIBdnEje+SyGSByG2No25sYx1SMYmGQg6ehcVvUAb2dJogK PtohI0M9w6LHLUjdAVh0q+5xZ0W7csbRUpufAqL91H22J+EGy/HyZ+jkOW2HAKfb+ARE 8LKNDRb6mcytip8EDYFihqeYRNUYwDsKJaYqsgxXBL9pUHOD8GTFM/ukbrH1w+8IDZkW wJWYlKGUMQH5/1uRCJHOJ4QD9/CgmwIZPT1ReprDjVyDTWIr0l6sCIAL56bc12j3S/mk 5g9LncYgTtIrqOzCF6gD8mB4JYiDUUnRquWCgnA5IwUadGRsbammsAD6RrmWZVjipJ42 1WjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=dgb9VLbXx2tiQjiliX2CVp3l/xl303Qwf2JBJdlh0SQ=; b=pqGVHD7f9xm9n/C8+g/CP9RYXa6lKJsv/n1ZS9yspaCjPyqzp8Wu+VJHM/0yrX7OM/ YX3c7FhZjd+zq6kuhDy8aOwoUwBscbcZHhBVi+TRXQJhxy25mnJAnnd+ta3ZW6mcSLRB 8pIkPO2iHaOuDD1w5aE1c9KDxYaopPs5Jnr7hcMTROm4y3GGqTdtNY8w8yopLf4/EDJI 3iU3/aZpAvPL+8WSMXJ3afbOXicf7UAOdx4bP0Eoc2+icgomzJvUFMUz7m1EfFgKGNK0 x8/dUQSMr3k30GDThFWZERXHve40FFrlotk1QaSP5O+5t2ANITRnM46KCLaNtS37Gbc/ gDeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OMlThanM; 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 s1si3320066plg.12.2021.05.04.03.30.55; Tue, 04 May 2021 03:31:16 -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=k20201202 header.b=OMlThanM; 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 S230248AbhEDK3p (ORCPT + 99 others); Tue, 4 May 2021 06:29:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:43428 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230283AbhEDK3n (ORCPT ); Tue, 4 May 2021 06:29:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4F4E2613BE; Tue, 4 May 2021 10:28:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1620124127; bh=dgb9VLbXx2tiQjiliX2CVp3l/xl303Qwf2JBJdlh0SQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=OMlThanMroC7t/Y160W99ZocuyAr4w8fXQ07/HQtVO2nbS6VEXkS8GLyn2j+t/xER 0sTYqMSJKR416yXOMtSo3SIbgiNtEIN2eFgl20plWso0fzHiNdGPNSWA10YzfJ9K4D y2Ii+tJihSFeKWZeX5iEj763No0vjdlAqEQfJartr2q95ms0uG8Y5vi4pHD7iqD3Yq cb6kDvleh4bzBIteD0qIFaVN6y+Jjrnx24+R7aTyawcb/rhepCULzhtyS/o42RlUfi PtnjEPyceVpuvS3Qvpc3Q8ecI5izMGBHs8HxUXaLD1Bud7985ojfcPBUBkaMLPJ5OK x2X9H2ehcnQUQ== Received: by mail-oi1-f182.google.com with SMTP id i26so8289475oii.3; Tue, 04 May 2021 03:28:47 -0700 (PDT) X-Gm-Message-State: AOAM530NnGAwBOmX6qoab4UrNKz+Yt+v4tHbb86EXS6SZdg1iwAh88d+ eHEV244GshWD3G2e+JlLY3m/8vS/d1OxN5hNRk8= X-Received: by 2002:aca:4056:: with SMTP id n83mr2521838oia.47.1620124126620; Tue, 04 May 2021 03:28:46 -0700 (PDT) MIME-Version: 1.0 References: <20210427120607.2646166-1-arei@altlinux.org> In-Reply-To: From: Ard Biesheuvel Date: Tue, 4 May 2021 12:28:35 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] RISC-V: Relocate the kernel relative to a DRAM base. To: Nikita Ermakov Cc: linux-efi , Paul Walmsley , Palmer Dabbelt , Albert Ou , Atish Patra , linux-riscv , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 28 Apr 2021 at 18:00, Nikita Ermakov wrote: > > On Tue, 27 Apr 2021 at 15:43, Ard Biesheuvel wrote: > > > > On Tue, 27 Apr 2021 at 14:07, Nikita Ermakov wrote: > > > > > > Try to get the base of the DRAM from a DTB to use it as a lowest address > > > in physical memory to relocate the kernel. If it is not possible to > > > obtain the base from a /memory node of the DTB let's make an assumption > > > that the DRAM base at the beginning of the memory. > > > > > > > Why? > > > > You right, this patch is useless. I made it because I overlooked > efi_low_alloc_above() in libstub/relocate.c > Sorry for bothering. > > I had an issue with booting a Linux kernel with EFI stub on a HiFive > Unleashed board. > My boot chain was as follows: ZSBL -> FSBL -> OpenSBI -> U-Boot > (bootefi) -> Linux > When I tried to boot the kernel, U-Boot throws an Store/AMO access > fault exception. > I checked the riscv-stub.c and libstub/relocate.c and I thought that > it tries to relocate the kernel at the 2 MiB. > With this patch the kernel started to boot and I thought that the > theory was right. > But, after further investigation I found out that U-Boot EFI does not > mark the first 4 KiB page of DRAM as EFI_BOOT_SERVICE_DATA on the > board and efi_low_alloc_above() allocates this region as conventional > memory. The lowest region of DRAM is protected and that is why I got > the exception when the kernel tries to relocate to the 0x80000000. The > reason why U-Boot EFI does not mark the first 4 KiB of DRAM as > EFI_BOOT_SERVICE_DATA was that there wasn't /reserved-memory node in a > DTB. I had the FSBL with a patch which enables an entire L2 cache and > it does not preserve a0, a1 registers before a jump to the OpenSBI. > So, OpenSBI didn't fixup the DTB where it adds the /reserved-memory > node. > OK, thanks for the explanation. I will disregard this patch then.