From nobody Wed May 15 09:43:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+97947+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+97947+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1672852988; cv=none; d=zohomail.com; s=zohoarc; b=nJxB7YgSoVCPZdE98vZO7hCtXrE2PtJdh0inbGO36rlR6L5qgRdGhLKT1Tj2kQKdjALRGwx6KGNF8gC44zRLzdcOsLCWMBBxbWOIzgnKtwcjxZ1TSBY+Wen9ZTwGulRq11NnpHFNuGea+uopeYBH96ewgRLKqNb8AVjx3uiFgLY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1672852988; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=3q1Iw3Crk6UR4ZXZ+5lxltutCAYi8gc+Xiu7U5tFvXc=; b=VWiRAn9OQShx9ydvWGxztegWuIhvm8Yzcl/Mx574f/9GIp5ycgf1sfm3B7QT5jCcWvkm/XGJ0+UsJGqCdsS7SHzv2qN7fIseNQGpyR6VAdy9eRO/wjiR9FNtwTgdBdXPmRLoJxI3sLlJa1sO9uMkwqLtbd7A/xwpQ4jE8B6WOdg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+97947+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1672852988126672.0387329527891; Wed, 4 Jan 2023 09:23:08 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id sYxbYY1788612xfpNNBf8s3S; Wed, 04 Jan 2023 09:23:07 -0800 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web11.18836.1672852987105836003 for ; Wed, 04 Jan 2023 09:23:07 -0800 X-Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 56046616C3; Wed, 4 Jan 2023 17:23:06 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB898C433D2; Wed, 4 Jan 2023 17:23:04 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: dann.frazier@canonical.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH] ArmVirtPkg/ArmVirtQemu: Avoid early ID map on ThunderX Date: Wed, 4 Jan 2023 18:22:55 +0100 Message-Id: <20230104172255.1211768-1-ardb@kernel.org> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ardb@kernel.org X-Gm-Message-State: XPEBA6WGr2gSBDZofAemlIhCx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1672852987; bh=fzRqa4SBvKSZ9KwkUgCEtVif/jTKd1dHtfnzCHIAexk=; h=Cc:Date:From:Reply-To:Subject:To; b=ZQBBtE7uRuIqCVjvOfoQ40URDnoIjtToyusuav2eaVEFbEX3XAmV4Cq1JjFo9PgMwzR 8TV2/dckg8iRxGnZ7/d3VbVf6eGc0Qg8WG9FWXOEquhlOWVSSYjaZPAy1ey1KgR1houWD T/qgPHhk5DcifCqi7oVM0dGMSE1FMHlvkIA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1672852989362100001 Content-Type: text/plain; charset="utf-8" The early ID map used by ArmVirtQemu uses ASID scoped non-global mappings, as this allows us to switch to the permanent ID map seamlessly 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 appears to result in I-cache corruption. (Linux disables the KPTI based Meltdown 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 Acked-by: Laszlo Ersek --- ArmVirtPkg/ArmVirtQemu.dsc | 6 +++= +++ ArmVirtPkg/Library/ArmPlatformLibQemu/AArch64/ArmPlatformHelper.S | 18 +++= +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc index f77443229e8e..340b36f69c2c 100644 --- a/ArmVirtPkg/ArmVirtQemu.dsc +++ b/ArmVirtPkg/ArmVirtQemu.dsc @@ -31,6 +31,7 @@ [Defines] DEFINE SECURE_BOOT_ENABLE =3D FALSE DEFINE TPM2_ENABLE =3D FALSE DEFINE TPM2_CONFIG_ENABLE =3D FALSE + DEFINE CAVIUM_ERRATUM_27456 =3D FALSE =20 # # Network definition @@ -117,7 +118,12 @@ [LibraryClasses.common.UEFI_DRIVER] UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf =20 [BuildOptions] +!if $(CAVIUM_ERRATUM_27456) =3D=3D TRUE + GCC:*_*_AARCH64_CC_XIPFLAGS =3D -mno-strict-align + GCC:*_*_AARCH64_PP_FLAGS =3D -DCAVIUM_ERRATUM_27456 +!else GCC:*_*_AARCH64_CC_XIPFLAGS =3D=3D +!endif =20 !include NetworkPkg/NetworkBuildOptions.dsc.inc =20 diff --git a/ArmVirtPkg/Library/ArmPlatformLibQemu/AArch64/ArmPlatformHelpe= r.S b/ArmVirtPkg/Library/ArmPlatformLibQemu/AArch64/ArmPlatformHelper.S index 05ccc7f9f043..962f1ba3a4d7 100644 --- a/ArmVirtPkg/Library/ArmPlatformLibQemu/AArch64/ArmPlatformHelper.S +++ b/ArmVirtPkg/Library/ArmPlatformLibQemu/AArch64/ArmPlatformHelper.S @@ -44,8 +44,26 @@ =20 =20 ASM_FUNC(ArmPlatformPeiBootAction) +#ifdef CAVIUM_ERRATUM_27456 + /* + * On Cavium ThunderX, using non-global mappings that are executable at = EL1 + * results in I-cache corruption. So just avoid the early ID mapping the= re. + * + * MIDR implementor 0x43 + * MIDR part numbers 0xA1 0xA2 + */ + mrs x0, midr_el1 // read the MIDR into X0 + ubfx x1, x0, #6, #10 // grab part number bits [11:2] + ubfx x0, x0, #24, #8 // grab implementor id + mov x2, #0xA0 >> 2 + cmp x0, #0x43 // compare implementor id + ccmp x1, x2, #0, eq // compare part# bits [11:2] + b.eq .Lreturn +#endif + mrs x0, CurrentEL // check current exception level tbz x0, #3, 0f // bail if above EL1 +.Lreturn: ret =20 0:mov_i x0, mairval --=20 2.39.0 -=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 (#97947): https://edk2.groups.io/g/devel/message/97947 Mute This Topic: https://groups.io/mt/96054879/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-