From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by mx.groups.io with SMTP id smtpd.web10.21.1660556450200077892 for ; Mon, 15 Aug 2022 02:40:50 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hQzALwqF; spf=pass (domain: kernel.org, ip: 145.40.68.75, mailfrom: ardb@kernel.org) 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 ams.source.kernel.org (Postfix) with ESMTPS id A870AB80DC7; Mon, 15 Aug 2022 09:40:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD8DBC433D6; Mon, 15 Aug 2022 09:40:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660556447; bh=EqQux6WKRYokVyXedYGFWRxayF/Ag8MAafuiqyv2XBM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hQzALwqFnTlp7g97Y6QEA0phppWRyLi1bDXimrFClOI4WCJApEAx9gSdP/4QW7EVt 5f3UGQY9eTUaF1DdDViCG9Emc0IleLccvbQSvD1Kh5Kz788mWBoFixCVbir+FMOW+j 9jqP+rbvOuUIRzuQgz1tx4Jj4hKsgLvAyYwo7JS32iwQnGF34/x6aWTJZ/LgPFG0CA RP5cBQPW2evCPpkEsKjYDKACGH+rlnbLRicXY8kPbxw995FDpWg3CkecaWbKsWGOVp OnzsE48dK2wSQJk4eZWR3QatYTf1RjeSDOTvRC+zU9aVMcinTs5rbAXfzkt6SSQg7+ rRftaCrDkVy6g== From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Yuan Yu , Laszlo Ersek , Gerd Hoffmann , Pawel Polawski , Oliver Steffen , Jiewen Yao Subject: [PATCH 1/2] OvmfPkg: Introduce NULL class library to inhibit driver load Date: Mon, 15 Aug 2022 11:40:29 +0200 Message-Id: <20220815094030.465587-2-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220815094030.465587-1-ardb@kernel.org> References: <20220815094030.465587-1-ardb@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Add a new library that can be incorporated into any driver built from source, and which permits loading of the driver to be inhibited based on the value of a QEMU fw_cfg boolean variable. This will be used in a subsequent patch to allow dispatch of the IPv6 and IPv6 network protocol driver to be controlled from the QEMU command line. Signed-off-by: Ard Biesheuvel --- OvmfPkg/Library/DriverLoadInhibitorLib/DriverLoadInhibitorLib.c | 30 +++= +++++++++++++++++ OvmfPkg/Library/DriverLoadInhibitorLib/DriverLoadInhibitorLib.inf | 28 +++= +++++++++++++++ OvmfPkg/OvmfPkg.dec | 4 +++ 3 files changed, 62 insertions(+) diff --git a/OvmfPkg/Library/DriverLoadInhibitorLib/DriverLoadInhibitorLib.= c b/OvmfPkg/Library/DriverLoadInhibitorLib/DriverLoadInhibitorLib.c new file mode 100644 index 000000000000..dc8544bc38be --- /dev/null +++ b/OvmfPkg/Library/DriverLoadInhibitorLib/DriverLoadInhibitorLib.c @@ -0,0 +1,30 @@ +// @file=0D +// Copyright (c) 2022, Google LLC. All rights reserved.
=0D +// SPDX-License-Identifier: BSD-2-Clause-Patent=0D +//=0D +=0D +#include =0D +=0D +#include =0D +#include =0D +=0D +STATIC CHAR16 mExitData[] =3D L"Driver dispatch inhibited by QEMU fw_cfg v= ariable.";=0D +=0D +EFI_STATUS=0D +EFIAPI=0D +DriverLoadInhibitorLibConstructor (=0D + IN EFI_HANDLE Handle,=0D + IN EFI_SYSTEM_TABLE *SystemTable=0D + )=0D +{=0D + RETURN_STATUS Status;=0D + BOOLEAN Enabled;=0D +=0D + Status =3D QemuFwCfgParseBool (FixedPcdGetPtr (PcdDriverInhibitorFwCfgVa= rName),=0D + &Enabled);=0D + if (!RETURN_ERROR (Status) && !Enabled) {=0D + return gBS->Exit (Handle, EFI_REQUEST_UNLOAD_IMAGE, sizeof mExitData,= =0D + mExitData);=0D + }=0D + return EFI_SUCCESS;=0D +}=0D diff --git a/OvmfPkg/Library/DriverLoadInhibitorLib/DriverLoadInhibitorLib.= inf b/OvmfPkg/Library/DriverLoadInhibitorLib/DriverLoadInhibitorLib.inf new file mode 100644 index 000000000000..ed521d12d335 --- /dev/null +++ b/OvmfPkg/Library/DriverLoadInhibitorLib/DriverLoadInhibitorLib.inf @@ -0,0 +1,28 @@ +## @file=0D +# Copyright (c) 2022, Google LLC. All rights reserved.
=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 1.29=0D + BASE_NAME =3D DriverLoadInhibitorLib=0D + FILE_GUID =3D af4c2c0b-f7ed-4d61-ad97-5953982c3531= =0D + MODULE_TYPE =3D DXE_DRIVER=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D NULL=0D + CONSTRUCTOR =3D DriverLoadInhibitorLibConstructor=0D +=0D +[Sources]=0D + DriverLoadInhibitorLib.c=0D +=0D +[LibraryClasses]=0D + QemuFwCfgSimpleParserLib=0D + UefiBootServicesTableLib=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + OvmfPkg/OvmfPkg.dec=0D +=0D +[FixedPcd]=0D + gUefiOvmfPkgTokenSpaceGuid.PcdDriverInhibitorFwCfgVarName=0D diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index 5af76a540529..e9a22cab088c 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -399,6 +399,10 @@ [PcdsFixedAtBuild] ## The Tdx accept page size. 0x1000(4k),0x200000(2M)=0D gUefiOvmfPkgTokenSpaceGuid.PcdTdxAcceptPageSize|0x200000|UINT32|0x65=0D =0D + ## The QEMU fw_cfg variable that DriverLoadInhibitorLib will check to=0D + # decide whether to abort dispatch of the driver it is linked into.=0D + gUefiOvmfPkgTokenSpaceGuid.PcdDriverInhibitorFwCfgVarName|""|VOID*|0x68= =0D +=0D [PcdsDynamic, PcdsDynamicEx]=0D gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2=0D gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable|FALSE|BOOLEAN|0x1= 0=0D --=20 2.35.1