From mboxrd@z Thu Jan 1 00:00:00 1970 From: Atish Patra Date: Thu, 30 Jul 2020 14:10:26 -0700 Subject: efi_loader/RISC-V: misaligned load when running grubriscv64.efi In-Reply-To: <9939A597-4AB4-48E1-9F55-090FBB474FA5@gmx.de> References: <7f999242-4c12-620d-1198-20a197d4c801@gmx.de> <941aa434-47fe-0456-54d0-4a2d70c02d08@gmx.de> <2BABE4D2-D37E-497B-8EE1-618D260716BE@gmx.de> <9939A597-4AB4-48E1-9F55-090FBB474FA5@gmx.de> Message-ID: List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Thu, Jul 30, 2020 at 1:19 PM Heinrich Schuchardt wrote: > > Am 30. Juli 2020 22:11:39 MESZ schrieb Heinrich Schuchardt : > >Am 30. Juli 2020 20:31:47 MESZ schrieb Atish Patra > >: > >>On Thu, Jul 30, 2020 at 4:04 AM Heinrich Schuchardt > >> wrote: > >>> > >>> On 30.07.20 12:16, Sean Anderson wrote: > >>> > On 7/30/20 6:03 AM, Heinrich Schuchardt wrote: > >>> >> Dear Sean, > >>> >> > >>> >> when trying to run grubriscv64.efi from the > >>> >> trini/u-boot-gitlab-ci-runner:bionic-20200526-18Jun2020 Docker > >>image on > >>> >> a MAIXDUINO the relocations are not naturally aligned: > >>> >> > >>> >> lib/efi_loader/efi_image_loader.c(133) efi_loader_relocate(): > >>> >> > >>> >> efi_reloc 000000008030a000, offset 0x101e, type 10 > >>> >> > >>> >> Here we are trying to change an u64 at 0x8030B01E: > >>> >> > >>> >> uint64_t *x64 = efi_reloc + offset; > >>> >> *x64 += (uint64_t)delta; > >>> >> > >>> >> This leads to an exception in function efi_loader_relocate(): > >>> >> > >>> >> Unhandled exception: Load address misaligned > >>> >> EPC: 00000000805a95ac RA: 00000000805a953a TVAL: > >>000000008030b01e > >>> >> EPC: 000000008001c5ac RA: 000000008001c53a reloc > >>> >> > >>> >> The GRUB image is available here: > >>> >> > >>> >> > >>https://gist.github.com/xypron/522a91962248e9c3888d8554cb61ad2c/raw/b959661626b38a738673a9efb2f398b2fabd5c77/grubriscv64.efi > >>> >> > >>> >> On QEMU the GRUB image is executed without problems: > >>> >> > >>> >> https://gitlab.denx.de/u-boot/custodians/u-boot-efi/-/jobs/132919 > >>> >> > >>> >> The UEFI specification requires for the ARM platform that > >>unaligned > >>> >> support is enabled. This is why we have implemented function > >>> >> allow_unaligned(). > >>> >> > >>> >> On RISC-V we have not yet implemented allow_unaligned() yet. Is > >>there a > >>> >> way to switch RISCV64 CPUs especially the Kendryte K210 into a > >>mode > >>> >> supporting unaligned access? > >>> > > >>> > AFAIK RISC-V has no requirement that un-aligned loads/stores > >>complete. I > >>> > believe the recommended solution is to install a trap handler > >which > >>> > completes the un-aligned load through a series of aligned loads > >and > >>then > >>> > returns back to the application. For an example of such an > >>> > implementation, check out arch/riscv/kernel/traps_misaligned.c in > >>Linux. > >>> > This may be too complex for U-Boot, so perhaps you can simply > >>disallow > >>> > unaligned accesses? > >>> > > >>> > --Sean > >>> > > >>> > >>> Working around the problem inside U-Boot is easy (just some memcpy() > >>> calls) but the GRUB image itself also makes unaligned accesses: > >>> > >>> Unhandled exception: Load address misaligned > >>> EPC: 000000008030b004 RA: 00000000805a4eca TVAL: 000000008030b02e > >>> EPC: 000000007fd7e004 RA: 0000000080017eca reloc > >>> > >>> UEFI image [0x000000008030a000:0x0000000080433fff] pc=0x1004 > >>> > >>> This is what I found in "RISC-V Unprivileged ISA V20191213" > >>> > >>> "Loads and stores where the effective address is not > >>naturally > >>> aligned to the referenced datatype (i.e., on a four-byte boundary > >for > >>> 32-bit accesses, and a two-byte boundary for 16-bit accesses) have > >>> behavior dependent on the EEI. An EEI may guarantee that misaligned > >>> loads and stores are fully supported, and so the software running > >>inside > >>> the execution environment will never experience a contained or fatal > >>> address-misaligned trap." > >>> > >>> @Leif > >>> Should GRUB be built with -mstrict-align for RISC-V? > >>> > >> > >>That shouldn't be necessary. Any real board with an MMU that can boot > >>Linux needs > >>a SBI provider such as OpenSBI. OpenSBI already implements a > >misaligned > >>handler. > >> > >>Are we planning to support EFI booting for NoMMU platforms ? As per my > >>understanding > >>runtime services need to be mapped through kernel page tables. > >> > > > >My interest is to have an affordable hardware platform where I can test > >U-Boot's UEFI sub-system on RISC-V. > > Yeah. For U-Boot UEFI subsystem verification kendryte is a good choice. But we shouldn't try to boot Linux via grub on that platform :) > >With 6 MiB usable RAM. (2 MiB reserved for AI) we probably won't get > >further than running GRUB. > > > >Can OpenSBI be built for the Kendryte K210 SoC? What is the size of > >OpenSBI? > Usually, OpenSBI firmware size is around ~100 KB. > Yes: > https://github.com/riscv/opensbi/tree/master/platform/kendryte/k210 > > So we should try if we can run U-Boot with OpenSBI on the platform. > > > > >Best regards > > > >Heinrich > > > >>> @Ard > >>> How about the EFI part of the Linux kernel? > >>> > >>> Best regards > >>> > >>> Heinrich > -- Regards, Atish From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1k1Fp5-00062v-GJ for mharc-grub-devel@gnu.org; Thu, 30 Jul 2020 17:10:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53912) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1Fp3-00062j-Nm for grub-devel@gnu.org; Thu, 30 Jul 2020 17:10:41 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:39019) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k1Fp1-0001xg-JT for grub-devel@gnu.org; Thu, 30 Jul 2020 17:10:41 -0400 Received: by mail-wm1-x342.google.com with SMTP id q76so6234710wme.4 for ; Thu, 30 Jul 2020 14:10:38 -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=mhIcnWZNiOWosiId44LVIboHiznl+Hzq8Q2lz4IRvcQ=; b=r8tlOWWStaHi5ggTCEZk0XzcKcqpnlKEEV7F1djFbFNulXdJnPtUEKeGmoB4fSAF9q jsv2HBHREuSM3i+PJlfBxKBRBa7VPgez/fe57XXXaVLvw7XHv29uPEwA1M2hAq8QXDRA chg2em4F4H8JTrJSMOTJYy5Gou8tSqO15xgdc= 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=mhIcnWZNiOWosiId44LVIboHiznl+Hzq8Q2lz4IRvcQ=; b=FU4XXZy7GX20fgtLBUSB6GOAcgJLH7UbWX/h70E54XxgwDy6Ro1Tz3fJxw3jt0nAuG kThS3EFLOYvcCV1uJatDCf7DX+ykafPzNFpotvzD3AFwVbDO+IayUW5pqPvIresd+y3b DLYDkAyI49ToitqoTpilj2dqr7QaCpTckYLCo3KCI5LkisWsmOMWD/bdwZRXobxV8CX0 qA/r9ntSTly2Vg4bElWxwonyzJ1JRz/21cus4Wfm/VIrHqR/JY9gLKWXhjwbZYNAURYz yDkX8wdBTaiVV8BGkhmGAxJIvbr9O6gW6n+vd+sFzDoF8M3lum4EEFdEKIbHNNQ3WIR/ bcng== X-Gm-Message-State: AOAM532tcxx8QUQV/hPvqnx8kT2KkgY8lO4RJOpncfexGE/u4sBu821K aydbz/J29ZgvZVTm+0NBoS62JRB+8i+Uv0+Y12YE X-Google-Smtp-Source: ABdhPJz54wl8YPFDly92uu6QKG+D+z1VZqPt/4Aei58CD2VMEPBJZg41BGpBeCp1ajBPhPgTQgekVkU7Aexu2924VDM= X-Received: by 2002:a1c:3c87:: with SMTP id j129mr909116wma.176.1596143437866; Thu, 30 Jul 2020 14:10:37 -0700 (PDT) MIME-Version: 1.0 References: <7f999242-4c12-620d-1198-20a197d4c801@gmx.de> <941aa434-47fe-0456-54d0-4a2d70c02d08@gmx.de> <2BABE4D2-D37E-497B-8EE1-618D260716BE@gmx.de> <9939A597-4AB4-48E1-9F55-090FBB474FA5@gmx.de> In-Reply-To: <9939A597-4AB4-48E1-9F55-090FBB474FA5@gmx.de> From: Atish Patra Date: Thu, 30 Jul 2020 14:10:26 -0700 Message-ID: Subject: Re: efi_loader/RISC-V: misaligned load when running grubriscv64.efi To: Heinrich Schuchardt Cc: Sean Anderson , Leif Lindholm , Alexander Graf , U-Boot Mailing List , Rick Chen , Daniel Kiper , GRUB mailing list , Ard Biesheuvel Content-Type: text/plain; charset="UTF-8" Received-SPF: pass client-ip=2a00:1450:4864:20::342; envelope-from=atishp@atishpatra.org; helo=mail-wm1-x342.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Jul 2020 21:10:41 -0000 On Thu, Jul 30, 2020 at 1:19 PM Heinrich Schuchardt wrote: > > Am 30. Juli 2020 22:11:39 MESZ schrieb Heinrich Schuchardt : > >Am 30. Juli 2020 20:31:47 MESZ schrieb Atish Patra > >: > >>On Thu, Jul 30, 2020 at 4:04 AM Heinrich Schuchardt > >> wrote: > >>> > >>> On 30.07.20 12:16, Sean Anderson wrote: > >>> > On 7/30/20 6:03 AM, Heinrich Schuchardt wrote: > >>> >> Dear Sean, > >>> >> > >>> >> when trying to run grubriscv64.efi from the > >>> >> trini/u-boot-gitlab-ci-runner:bionic-20200526-18Jun2020 Docker > >>image on > >>> >> a MAIXDUINO the relocations are not naturally aligned: > >>> >> > >>> >> lib/efi_loader/efi_image_loader.c(133) efi_loader_relocate(): > >>> >> > >>> >> efi_reloc 000000008030a000, offset 0x101e, type 10 > >>> >> > >>> >> Here we are trying to change an u64 at 0x8030B01E: > >>> >> > >>> >> uint64_t *x64 = efi_reloc + offset; > >>> >> *x64 += (uint64_t)delta; > >>> >> > >>> >> This leads to an exception in function efi_loader_relocate(): > >>> >> > >>> >> Unhandled exception: Load address misaligned > >>> >> EPC: 00000000805a95ac RA: 00000000805a953a TVAL: > >>000000008030b01e > >>> >> EPC: 000000008001c5ac RA: 000000008001c53a reloc > >>> >> > >>> >> The GRUB image is available here: > >>> >> > >>> >> > >>https://gist.github.com/xypron/522a91962248e9c3888d8554cb61ad2c/raw/b959661626b38a738673a9efb2f398b2fabd5c77/grubriscv64.efi > >>> >> > >>> >> On QEMU the GRUB image is executed without problems: > >>> >> > >>> >> https://gitlab.denx.de/u-boot/custodians/u-boot-efi/-/jobs/132919 > >>> >> > >>> >> The UEFI specification requires for the ARM platform that > >>unaligned > >>> >> support is enabled. This is why we have implemented function > >>> >> allow_unaligned(). > >>> >> > >>> >> On RISC-V we have not yet implemented allow_unaligned() yet. Is > >>there a > >>> >> way to switch RISCV64 CPUs especially the Kendryte K210 into a > >>mode > >>> >> supporting unaligned access? > >>> > > >>> > AFAIK RISC-V has no requirement that un-aligned loads/stores > >>complete. I > >>> > believe the recommended solution is to install a trap handler > >which > >>> > completes the un-aligned load through a series of aligned loads > >and > >>then > >>> > returns back to the application. For an example of such an > >>> > implementation, check out arch/riscv/kernel/traps_misaligned.c in > >>Linux. > >>> > This may be too complex for U-Boot, so perhaps you can simply > >>disallow > >>> > unaligned accesses? > >>> > > >>> > --Sean > >>> > > >>> > >>> Working around the problem inside U-Boot is easy (just some memcpy() > >>> calls) but the GRUB image itself also makes unaligned accesses: > >>> > >>> Unhandled exception: Load address misaligned > >>> EPC: 000000008030b004 RA: 00000000805a4eca TVAL: 000000008030b02e > >>> EPC: 000000007fd7e004 RA: 0000000080017eca reloc > >>> > >>> UEFI image [0x000000008030a000:0x0000000080433fff] pc=0x1004 > >>> > >>> This is what I found in "RISC-V Unprivileged ISA V20191213" > >>> > >>> "Loads and stores where the effective address is not > >>naturally > >>> aligned to the referenced datatype (i.e., on a four-byte boundary > >for > >>> 32-bit accesses, and a two-byte boundary for 16-bit accesses) have > >>> behavior dependent on the EEI. An EEI may guarantee that misaligned > >>> loads and stores are fully supported, and so the software running > >>inside > >>> the execution environment will never experience a contained or fatal > >>> address-misaligned trap." > >>> > >>> @Leif > >>> Should GRUB be built with -mstrict-align for RISC-V? > >>> > >> > >>That shouldn't be necessary. Any real board with an MMU that can boot > >>Linux needs > >>a SBI provider such as OpenSBI. OpenSBI already implements a > >misaligned > >>handler. > >> > >>Are we planning to support EFI booting for NoMMU platforms ? As per my > >>understanding > >>runtime services need to be mapped through kernel page tables. > >> > > > >My interest is to have an affordable hardware platform where I can test > >U-Boot's UEFI sub-system on RISC-V. > > Yeah. For U-Boot UEFI subsystem verification kendryte is a good choice. But we shouldn't try to boot Linux via grub on that platform :) > >With 6 MiB usable RAM. (2 MiB reserved for AI) we probably won't get > >further than running GRUB. > > > >Can OpenSBI be built for the Kendryte K210 SoC? What is the size of > >OpenSBI? > Usually, OpenSBI firmware size is around ~100 KB. > Yes: > https://github.com/riscv/opensbi/tree/master/platform/kendryte/k210 > > So we should try if we can run U-Boot with OpenSBI on the platform. > > > > >Best regards > > > >Heinrich > > > >>> @Ard > >>> How about the EFI part of the Linux kernel? > >>> > >>> Best regards > >>> > >>> Heinrich > -- Regards, Atish