From nobody Fri Apr 26 22:31:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+61648+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61648+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1592997333; cv=none; d=zohomail.com; s=zohoarc; b=eeom8vXW1RmjzVaHZrPhFrTxAa2+YVl95Q5AId0NgDMpz2BI4o++KZIAVWbSwPNMzMaGJj46KBObcyyJn7b/6Gj1cj4YHXA02FEaHCEdpiAk/eXVdUMrXruhUn/Vm2HfVrlD71slZ0RUU39I0L45A8roY3ymjRpufFjHTuZK2LE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592997333; h=Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=ueXkObbu+xFjNdVfKdT5+dmAGXbdcU2pfrROnMRdZnQ=; b=FOYrDYmkiU991ckcNXaxRwAhsNAoxkbqAp9or/JShbkU7Fyw/2I+bTDOuDL8tdci+Iy+s7l4lqKjrE7U8Ht45rRKHwU5yeaJbKrNginy4nIA2fA096N627wWquOmaUSBuBh9E2LDwPkY5SNhHQDV3iqjcVXsdw8XulTyz0gTa58= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61648+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1592997332973307.32052381289793; Wed, 24 Jun 2020 04:15:32 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id aHpqYY1788612xulAOwhUH5j; Wed, 24 Jun 2020 04:15:32 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.11196.1592997331518140605 for ; Wed, 24 Jun 2020 04:15:31 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1ACC71F1; Wed, 24 Jun 2020 04:15:30 -0700 (PDT) X-Received: from localhost.localdomain (unknown [10.37.8.29]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 05A0B3F6CF; Wed, 24 Jun 2020 04:15:28 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: lersek@redhat.com, philmd@redhat.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH v2] ArmVirtPkg/NorFlashQemuLib: disable NOR flash DT nodes upon discovery Date: Wed, 24 Jun 2020 13:15:24 +0200 Message-Id: <20200624111524.1588197-1-ard.biesheuvel@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ard.biesheuvel@arm.com X-Gm-Message-State: cKC6FjhX7jY7uz8VWiMJe0OQx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1592997332; bh=eqMdu46ig+RfzhGCypQOZMLE+VgVtiKMaZlhFdCYCas=; h=Cc:Date:From:Reply-To:Subject:To; b=pLWt1zeMpNUUQlBD3E9lxS59Wb+0abHnQizXnrMNZIDlNKmXXqKPBp6A68uENClYuTM oV0Nq9KBo9RMlGmpo7/umeRM8r2qcRxvdIYl0Wm7679wU6WmpIIVPWjLS7DZFCvAkcW5L vFH4L1JviWBr0Tv9suE/8pPuQ485p+L2vew= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Our UEFI guest firmware takes ownership of the emulated NOR flash in order to support the variable runtime services, and it does not expect the OS to interfere with the underlying storage directly. So disable the NOR flash DT nodes as we discover them, in a way similar to how we disable the PL031 RTC in the device tree when we attach our RTC runtime driver to it. Note that this also hides the NOR flash bank that carries the UEFI executable code, but this is not intended to be updatable from inside the guest anyway, and if it was, we should use capsule update to do so. Also, the first -pflash argument that defines the backing for this flash bank is often issued with the 'readonly' modifier, in order to prevent any changes whatsoever to be made to the executable firmware image by the guest. This issue has become relevant due to the following Linux changes, which enable the flash driver stack for default build configurations targetting arm64 and 32-bit ARM. ce693fc2a877 ("arm64: defconfig: Enable flash device drivers for QorIQ boards", 2020-03-= 16). 5f068190cc10 ("ARM: multi_v7_defconfig: Enable support for CFI NOR FLASH", 2019-04-03) Reviewed-by: Laszlo Ersek Reviewed-by: Philippe Mathieu-Daude Signed-off-by: Ard Biesheuvel --- ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c b/ArmVirt= Pkg/Library/NorFlashQemuLib/NorFlashQemuLib.c index 9b1d1184bdd3..425e36f2d127 100644 --- a/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c +++ b/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c @@ -86,6 +86,22 @@ NorFlashPlatformGetDevices ( mNorFlashDevices[Num].BlockSize =3D QEMU_NOR_BLOCK_SIZE; Num++; } + + // + // UEFI takes ownership of the NOR flash, and exposes its functionality + // through the UEFI Runtime Services GetVariable, SetVariable, etc. Th= is + // means we need to disable it in the device tree to prevent the OS fr= om + // attaching its device driver as well. + // Note that this also hides other flash banks, but the only other fla= sh + // bank we expect to encounter is the one that carries the UEFI execut= able + // code, which is not intended to be guest updatable, and is usually b= acked + // in a readonly manner by QEMU anyway. + // + Status =3D FdtClient->SetNodeProperty (FdtClient, Node, "status", + "disabled", sizeof ("disabled")); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_WARN, "Failed to set NOR flash status to 'disabled'\= n")); + } } =20 *NorFlashDescriptions =3D mNorFlashDevices; --=20 2.27.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 (#61648): https://edk2.groups.io/g/devel/message/61648 Mute This Topic: https://groups.io/mt/75079347/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-