From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mout01.posteo.de (mout01.posteo.de [185.67.36.65]) by mx.groups.io with SMTP id smtpd.web11.51702.1681150094260360017 for ; Mon, 10 Apr 2023 11:08:14 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@posteo.de header.s=2017 header.b=ryS1i7B7; spf=pass (domain: posteo.de, ip: 185.67.36.65, mailfrom: mhaeuser@posteo.de) Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 59C2C240194 for ; Mon, 10 Apr 2023 20:08:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1681150092; bh=Sx1YPWiikbxvLqB3Vo1wfNaSDX3V4qlVrejYULB4Irs=; h=From:Subject:Date:To:From; b=ryS1i7B7vtRvFcjfxFE5YidfGdb4Wq4ANTbJpeMfEh/QB8syxNBkVE1qGgQopmgEk ZD3ULhxYfxv1Mz4ap2Hf+6HVgvFFvauZ9Vg13hcXWEpWfz/xCmgpX434fyG/A/rbB+ y8VJMD9/AnfeOG9/Jj0tewgLAjFl2hknBh0Qcw7B5HnRE/y6NDrZmIqjHpOjvY1miw aGXgEPkWwBTNSqoa8V6XaeCKLmpk/I+IrjpiKYSEMTtlX/hX+KNALiburlE32jikZ0 sqs240CpFJyViEZgOIqIDWfLacaBQwxRGI1f/6W9HRpHB2OiI0V/PotNdxoknKcA5+ ZvConW8D68w+w== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4PwH5R2M10z9rxM; Mon, 10 Apr 2023 20:08:10 +0200 (CEST) From: =?UTF-8?B?TWFydmluIEjDpHVzZXI=?= Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.500.231\)) Subject: [RFC PATCH] Fix ArmReplaceLiveTranslationEntry alignment Message-Id: Date: Mon, 10 Apr 2023 18:08:00 +0000 To: edk2-devel-groups-io , Leif Lindholm , Ard Biesheuvel , Sami Mujawar Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Good day everyone, Sorry, but due to time constraints, I cannot immediately provide a = proper patch. Would you mind checking this commit and commenting on = whether it looks about right, so I can submit a proper patch for review = some time this or next week? = https://github.com/acidanthera/audk/commit/53f2af3ad5909e177818445cafed7bd= b6aae9d97 With the proper patch, I will probably also include an ASSERT to make = sure the alignment is actually checked. The symptom is that late PEI may crash due to corrupted memory. This is = due to the fact that ArmReplaceLiveTranslationEntry() is misaligned = despite the requirement it may not cross page boundaries. The related = .balign directive technically belongs to the previous section, as = ArmReplaceLiveTranslationEntry() is moved to its own section via = ASM_FUNC() macro *after' the directive appears. The directive also = cannot nicely be placed after ASM_FUNC(), as that would mean the label = may refer to the padding inserted to achieve said alignment. Hence, my = solution is to introduce a separate macro. Reproducers are here, I tested the last two stable tags: https://github.com/mhaeuser/edk2/tree/arm_corruption-202211 https://github.com/mhaeuser/edk2/tree/arm_corruption-202302 ... and identified the last commit it is reproducible with (my hack does = not work on master): https://github.com/mhaeuser/edk2/tree/arm_corruption-latest The fact that the commits after that last branch work is mere luck, I = just didn't want to bruteforce a new hack to trigger the issue. :) To trigger the issue, build ArmVirtQemu/AARCH64 of any of those branches = with GCC 12 (GCC5) and as DEBUG - GCC 11 and RELEASE/NOOPT do *not* = trigger the issue as-is for me. If this doesn't work for you, you = probably need to find a different hack to move the function across a = page boundary. When starting the generated FD, I get a hang right when = jumping to DxeIplPeim (its entry point is badly corrupted). Opening = PeiCore in IDA, it's obvious said function is misaligned. Best regards, Marvin=