From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <bounce+27952+118032+7686176+12367111@groups.io>
Received: from mail05.groups.io (mail05.groups.io [45.79.224.7])
	by spool.mail.gandi.net (Postfix) with ESMTPS id 5512D740034
	for <rebecca@openfw.io>; Fri, 19 Apr 2024 16:09:46 +0000 (UTC)
DKIM-Signature: a=rsa-sha256; bh=KxTN4i49ihaYT2nDYDTFQmoirD/DMqld2pPFEt2Dtqw=;
 c=relaxed/simple; d=groups.io;
 h=Date:From:To:CC:Subject:Message-ID:In-Reply-To:References:Organization:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type:Content-Transfer-Encoding;
 s=20240206; t=1713542984; v=1;
 b=rZmSZRO+EUcKVqvuXf4AkhtwK8RgRLOSfka8/LfVWMHn4YAQgJIfHM9Z+je+Q8HPFTkkTLeg
 PqBcAB9rO65521mtizxCOi9M5DNXucX4/LgJdqpRGhiT+D+feKYiwwlIuRLGs8Epd2UAs+2RI5Q
 B3pKJpuHM7nLr6ReIcCF9qyjtELUDvvGo3VMRmBJxFwYsWeGSZDtjZryPb/ZneHz7aQDVwGXxP3
 rsWc9tMDgEhDpFODUkq/YIlEX1s9NdRbhEf+MiM9OH+/p/biAG/tfErCHiCqqcEHg+KVoYYFn3k
 AtjbV0jJ91qupk7IhXhjSVxjvV7xwi5Wwj71yTvP2LvYw==
X-Received: by 127.0.0.2 with SMTP id 02NWYY7687511x6AKwSdoXs5; Fri, 19 Apr 2024 09:09:44 -0700
X-Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56])
 by mx.groups.io with SMTP id smtpd.web10.25394.1713542983284104204
 for <devel@edk2.groups.io>;
 Fri, 19 Apr 2024 09:09:43 -0700
X-Received: from mail.maildlp.com (unknown [172.18.186.31])
	by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4VLfgB67pKz6JBJF;
	Sat, 20 Apr 2024 00:07:34 +0800 (CST)
X-Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240])
	by mail.maildlp.com (Postfix) with ESMTPS id BFEF4140A35;
	Sat, 20 Apr 2024 00:09:40 +0800 (CST)
X-Received: from localhost (10.122.247.231) by lhrpeml500005.china.huawei.com
 (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Fri, 19 Apr
 2024 17:09:40 +0100
Date: Fri, 19 Apr 2024 17:09:38 +0100
From: "Jonathan Cameron via groups.io" <jonathan.cameron=huawei.com@groups.io>
To: Gerd Hoffmann <kraxel@redhat.com>
CC: <devel@edk2.groups.io>, Jonathan Cameron via <qemu-devel@nongnu.org>,
	<linuxarm@huawei.com>, Richard Henderson <richard.henderson@linaro.org>,
	<qemu-arm@nongnu.org>, Philippe =?ISO-8859-1?Q?Mathieu-Daud=E9?=
	<philmd@linaro.org>, Idan Horowitz <idan.horowitz@gmail.com>, "Ard
 Biesheuvel" <ardb@kernel.org>
Subject: Re: [edk2-devel] [PATCH v3 5/6] target/arm: Do memory type alignment check when translation disabled
Message-ID: <20240419170938.00000551@huawei.com>
In-Reply-To: <kjpkyoux2xcegrqshde5ddhicf33jnlelobuzuo4uj4svvlzdn@rilun7dz6776>
References: <20240301204110.656742-1-richard.henderson@linaro.org>
	<20240301204110.656742-6-richard.henderson@linaro.org>
	<20240416161111.0000607c@huawei.com>
	<0c878d25-3fbb-4f0b-bc9e-ca638f8c4f1e@linaro.org>
	<20240418091555.00006666@Huawei.com>
	<20240418183600.00000345@huawei.com>
	<kjpkyoux2xcegrqshde5ddhicf33jnlelobuzuo4uj4svvlzdn@rilun7dz6776>
Organization: Huawei Technologies R&D (UK) Ltd.
MIME-Version: 1.0
X-Originating-IP: [10.122.247.231]
X-ClientProxiedBy: lhrpeml100003.china.huawei.com (7.191.160.210) To
 lhrpeml500005.china.huawei.com (7.191.163.240)
Precedence: Bulk
List-Subscribe: <mailto:devel+subscribe@edk2.groups.io>
List-Help: <mailto:devel+help@edk2.groups.io>
Sender: devel@edk2.groups.io
List-Id: <devel.edk2.groups.io>
Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io
Resent-Date: Fri, 19 Apr 2024 09:09:43 -0700
Resent-From: jonathan.cameron@huawei.com
Reply-To: devel@edk2.groups.io,jonathan.cameron@huawei.com
List-Unsubscribe-Post: List-Unsubscribe=One-Click
List-Unsubscribe: <https://edk2.groups.io/g/devel/leave/12367111/7686176/1913456212/plugh>
X-Gm-Message-State: DSmvUoQ1XwFmi56cChaldWUex7686176AA=
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: quoted-printable
X-GND-Status: LEGIT
Authentication-Results: spool.mail.gandi.net;
	dkim=pass header.d=groups.io header.s=20240206 header.b=rZmSZRO+;
	dmarc=pass (policy=none) header.from=groups.io;
	spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io

On Fri, 19 Apr 2024 13:52:07 +0200
Gerd Hoffmann <kraxel@redhat.com> wrote:

>   Hi,
>=20
> > Gerd, any ideas?  Maybe I needs something subtly different in my
> > edk2 build?  I've not looked at this bit of the qemu infrastructure
> > before - is there a document on how that image is built? =20
>=20
> There is roms/Makefile for that.
>=20
> make -C roms help
> make -C roms efi
>=20
> So easiest would be to just update the edk2 submodule to what you
> need, then rebuild.
>=20
> The build is handled by the roms/edk2-build.py script,
> with the build configuration being in roms/edk2-build.config.
> That is usable outside the qemu source tree too, i.e. like this:
>=20
>   python3 /path/to/qemu.git/roms/edk2-build.py \
>     --config /path/to/qemu.git/roms/edk2-build.config \
>     --core /path/to/edk2.git \
>     --match armvirt \
>     --silent --no-logs
>=20
> That'll try to place the images build in "../pc-bios", so maybe better
> work with a copy of the config file where you adjust this.
>=20
> HTH,
>   Gerd
>=20

Thanks Gerd!

So the builds are very similar via the two method...
However - the QEMU build sets -D CAVIUM_ERRATUM_27456=3DTRUE

And that's the difference - with that set for my other builds the alignment
problems go away...

Any idea why we have that set in roms/edk2-build.config?
Superficially it seems rather unlikely anyone cares about thunderx1
(if they do we need to get them some new hardware with fresh bugs)
bugs now and this config file was only added last year.


However, the last comment in Ard's commit message below seems
highly likely to be relevant!

Chasing through Ard's patch it has the side effect of dropping
an override of a requirement for strict alignment.=20
So with out the errata=20
DEFINE GCC_AARCH64_CC_XIPFLAGS     =3D -mstrict-align -mgeneral-regs-only
is replaced with
 [BuildOptions]
+!if $(CAVIUM_ERRATUM_27456) =3D=3D TRUE^M
+  GCC:*_*_AARCH64_PP_FLAGS =3D -DCAVIUM_ERRATUM_27456^M
+!else^M
   GCC:*_*_AARCH64_CC_XIPFLAGS =3D=3D
+!endif^M

The edk2 commit that added this was the following +CC Ard.

Given I wasn't sure of the syntax of that file I set it
manually to the original value and indeed it works.


commit ec54ce1f1ab41b92782b37ae59e752fff0ef9c41
Author: Ard Biesheuvel <ardb@kernel.org>
Date:   Wed Jan 4 16:51:35 2023 +0100

    ArmVirtPkg/ArmVirtQemu: Avoid early ID map on ThunderX

    The early ID map used by ArmVirtQemu uses ASID scoped non-global
    mappings, as this allows us to switch to the permanent ID map seamlessl=
y
    without the need for explicit TLB maintenance.

    However, this triggers a known erratum on ThunderX, which does not
    tolerate non-global mappings that are executable at EL1, as this appear=
s
    to result in I-cache corruption. (Linux disables the KPTI based Meltdow=
n
    mitigation on ThunderX for the same reason)

    So work around this, by detecting the CPU implementor and part number,
    and proceeding without the early ID map if a ThunderX CPU is detected.

    Note that this requires the C code to be built with strict alignment
    again, as we may end up executing it with the MMU and caches off.

    Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
    Acked-by: Laszlo Ersek <lersek@redhat.com>
    Tested-by: dann frazier <dann.frazier@canonical.com>

Test case is
qemu-system-aarch64 -M virt,virtualization=3Dtrue, -m 4g -cpu cortex-a76 \
-bios QEMU_EFI.fd -d int

Which gets alignment faults since:
https://lore.kernel.org/all/20240301204110.656742-6-richard.henderson@linar=
o.org/

So my feeling here is EDK2 should either have yet another config for QEMU a=
s a host
or should always set the alignment without needing to pick the CAVIUM 27456=
 errata
which I suspect will get dropped soonish anyway if anyone ever cleans up
old errata.

Jonathan





-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#118032): https://edk2.groups.io/g/devel/message/118032
Mute This Topic: https://groups.io/mt/105602816/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-