From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by mx.groups.io with SMTP id smtpd.web10.52176.1681943284718754226 for ; Wed, 19 Apr 2023 15:28:04 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20221208 header.b=slYRb4bW; spf=pass (domain: gmail.com, ip: 209.85.216.48, mailfrom: pedro.falcato@gmail.com) Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-24756a12ba0so197584a91.1 for ; Wed, 19 Apr 2023 15:28:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681943284; x=1684535284; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=9++18jnxfILRGMxJ4ph6uAxvVIUroh7q3euaOUZnrNQ=; b=slYRb4bWFyIZcMDmDs2vfTX5MYNwdHUJy1N2AuYOXqkKIRzCTm3hyioryXwE+kbV3D xiillTKyYjOAME8i/CfZ0JJ49trEIdCDpG11zNdRI3PSuqbUuoaDqG9k913jKoQEyNDT /aCBoJZmLZPJvEYBskZ3je1IaWMPMz9swYYOqD2Zpq4nVh5GbZWf0RifsLAfYAdM3dkx /qfL7pg+l6KtyPO/So6+6PAmGZw2phBZAAEVC6BCtj1dsY4yaVw12GplJJVbwGxX48Wq eGrdSkPpL0FUtz4rFFoj8hrBhRPhkytqdeJb0LCS7Qs+KnLcB+hcuPc2AX1xWuB6sLlq geYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681943284; x=1684535284; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9++18jnxfILRGMxJ4ph6uAxvVIUroh7q3euaOUZnrNQ=; b=fmsjy1vEyRZEEfUq/pfrQ8VJBGvBgvYJHXCwwrjfR14bOBR8ypUk0EQABRHGgAmFGZ MagerroNgG6hUgdDiF9Je9wAfBiI5fglWbjNhze99ikeWWnFDtTwg4dTHcBX85p562/i tVMKUfgJF1trPFGHv5ciwBBbz116QpAymDj06o3iAoTbIHy+qGoTez3AupB20QayUg58 Rir6LpTS/U+d1YE/kmIAmvhSgeNENSsgbk1ihkoOlLaKMTalDd6tEFKKRKOpKPstK3/K x/8+pEyNbGhg2C7L5gevaVR8/npmfWO2TFIZjuYPp4daX5M+Z0jPrIhVWsPM+r4Gveio oMJA== X-Gm-Message-State: AAQBX9cSKUtSkMPYvLd66xltSPu+ptceIhQGHPGJg8M0bqvXK48z6I8r ku+C1QeTS1XSBKpEvwLmclrt9cQ0FZJcjpiazDNTSmo+1x8Vpg== X-Google-Smtp-Source: AKy350YNFJ4meNhMBxDnPxD/UxR/5ZUTYX/0qZQeSKvU21nZhhemcZDXuVKO+MqhZIc7JC4FMH6Uhs885eO3cEXRToI= X-Received: by 2002:a17:90a:9104:b0:23d:e0e8:f453 with SMTP id k4-20020a17090a910400b0023de0e8f453mr3630412pjo.38.1681943283801; Wed, 19 Apr 2023 15:28:03 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: "Pedro Falcato" Date: Wed, 19 Apr 2023 23:27:52 +0100 Message-ID: Subject: Re: [edk2-devel] [PATCH 1/2] ArmPkg/AsmMacroIoLibV8: Introduce ASM_FUNC_ALIGN() To: devel@edk2.groups.io, ardb@kernel.org Cc: =?UTF-8?Q?Marvin_H=C3=A4user?= , Leif Lindholm , Ard Biesheuvel , Sami Mujawar , Vitaly Cheptsov Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Apr 19, 2023 at 10:55=E2=80=AFPM Ard Biesheuvel w= rote: > > On Wed, 19 Apr 2023 at 22:10, Marvin H=C3=A4user wro= te: > > > > > > > On 19. Apr 2023, at 21:48, Ard Biesheuvel wrote: > > > > > > The issue is likely caused by > > > > > > -Wl,--defsym=3DPECOFF_HEADER_SIZE=3D0 > > > > > > Why are you setting that? It breaks the ELF to PE conversion. > > > > Where? > > It would, but you only appear to be setting that for ASLD_DLINK_FLAGS, > right? So that seems unrelated. > > The only thing I am observing is that the store to memory in > ArmMmuBaseLibConstructor() > > Hob =3D GetFirstGuidHob (&gArmMmuReplaceLiveTranslationEntryFuncGuid); > if (Hob !=3D NULL) { > mReplaceLiveEntryFunc =3D *(VOID **)GET_GUID_HOB_DATA (Hob); > > is writing to the emulated NOR flash, and this switches it into NOR > programming mode, causing the firmware to crash immediately as it can > no longer fetch instructions. > > FYI I am using GDB to step through the code, i.e., > > - run gdb (or 'gdb-multiarch' if you are cross-compiling) > - start qemu with -s -S > - connect using 'target remote :1234' > - paste the 'add-symbol-file' line, e.g., > add-symbol-file > /home/ard/build/edk2-workspace/Build/ArmVirtQemu-AARCH64/DEBUG_GCC5/AARCH= 64/MdeModulePkg/Core/DxeIplPeim/DxeIpl/DEBUG/DxeIpl.dll > 0x30000 > - set breakpoint > "hb _ModuleEntryPoint" > - start executing > "c" > - use 'ni' to advance to the 'str' instruction that sets mReplaceLiveEntr= yFunc > > > 0x3553c <_ModuleEntryPoint+96> str x1, [x0, #224] > > Now, as soon as I step over that instruction (using 's'), the entire > view of memory changes into > > =E2=94=82 > 0x35540 <_ModuleEntryPoint+100> .inst 0x00800080 ; undefin= ed > =E2=94=82 0x35544 <_ModuleEntryPoint+104> .inst 0x00800080 ; undefin= ed > > etc, and the next step generates an exception, but this cannot be > handled either. This is all related to the NOR flash emulation code in > QEMU, that stops working as a ROM and switches into programming mode. > > I cannot explain why this only happens in this case, and why some > writes seem to be ignored. But it does explain why this particular > firmware build is misbehaving > > Now, if you apply the following patches: > > ArmPkg/Mmu: Remove handling of NONSECURE memory regions > ArmPkg/ArmMmuLib: Introduce region types for RO/XP WB cached memory > ArmVirtPkg/ArmVirtQemu: Use read-only memory region type for code flash > > (from the edk2-devel list), your build still crashes, but it prints > one additional line > > Synchronous Exception at 0x3553C > > which is the exception caused by the write to NOR flash, which is now > mapped read-only in the page tables, and so it is caught by the > firmware itself. > > If you subsequently apply > > ArmVirtPkg/ArmVirtQemu: Use PEI flavor of ArmMmuLib for all PEIMs > > things work as expected. > > https://github.com/ardbiesheuvel/edk2/tree/arm_corruption-latest-ardb Hi Ard, Marvin's emails keep getting caught on your spam filter, please see https://edk2.groups.io/g/devel/message/103259 --=20 Pedro