From: "Michael D Kinney" <michael.d.kinney@intel.com>
To: "devel@edk2.groups.io" <devel@edk2.groups.io>,
"Jin, Zhi" <zhi.jin@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>,
"Ni, Ray" <ray.ni@intel.com>,
"Kinney, Michael D" <michael.d.kinney@intel.com>
Subject: Re: [edk2-devel] [PATCH 1/2] MdeModulePkg: Remove the handle validation check in CoreGetProtocolInterface
Date: Sat, 20 Jan 2024 02:02:12 +0000 [thread overview]
Message-ID: <CO1PR11MB4929376FD623FDDC87505CFCD2772@CO1PR11MB4929.namprd11.prod.outlook.com> (raw)
In-Reply-To: <20240117064510.390499-1-zhi.jin@intel.com>
Hi Zhi,
Some comments below.
Mike
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Zhi Jin
> Sent: Tuesday, January 16, 2024 10:45 PM
> To: devel@edk2.groups.io
> Cc: Jin, Zhi <zhi.jin@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>;
> Ni, Ray <ray.ni@intel.com>
> Subject: [edk2-devel] [PATCH 1/2] MdeModulePkg: Remove the handle
> validation check in CoreGetProtocolInterface
>
> CoreGetProtocolInterface() is called by CoreOpenProtocol(),
> CoreCloseProtocol() and CoreOpenProtocolInformation().
> Before CoreOpenProtocol() calls CoreGetProtocolInterface(), the input
> parameter UserHandle has been already checked for validation. So does
> CoreCloseProtocol().
> Removing the handle validation check in CoreGetProtocolInterface()
> could improve the performance, as CoreOpenProtocol() is called very
> frequently.
> Meanwhile, need to make it the caller's responsibility to check the
> parameters, and add the check in CoreOpenProtocolInformation().
>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Ray Ni <ray.ni@intel.com>
> Signed-off-by: Zhi Jin <zhi.jin@intel.com>
> ---
> MdeModulePkg/Core/Dxe/Hand/Handle.c | 17 +++++++++++------
> 1 file changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/MdeModulePkg/Core/Dxe/Hand/Handle.c
> b/MdeModulePkg/Core/Dxe/Hand/Handle.c
> index 51e5b5d3b3..a0d2d03267 100644
> --- a/MdeModulePkg/Core/Dxe/Hand/Handle.c
> +++ b/MdeModulePkg/Core/Dxe/Hand/Handle.c
> @@ -916,6 +916,8 @@ CoreUninstallMultipleProtocolInterfaces (
>
> /**
> Locate a certain GUID protocol interface in a Handle's protocols.
> + Note: This function doesn't do parameters checking, it's caller's
> responsibility
> + to pass in valid parameters.
>
> @param UserHandle The handle to obtain the protocol
> interface on
Instead of a Note:, I recommend the description of this parameter
be updated to state that the caller must pass in a valid UserHandle
that is checked with CoreValidateHandle().
Also, this API CoreGetProtocolInterface() is an internal helper
function. I also recommend that this function be declared 'static'
so the scope of the assumption that UserHandle is valid is only
by calls from other functions in this same file.
> @param Protocol The GUID of the protocol
> @@ -929,17 +931,11 @@ CoreGetProtocolInterface (
> IN EFI_GUID *Protocol
> )
> {
> - EFI_STATUS Status;
> PROTOCOL_ENTRY *ProtEntry;
> PROTOCOL_INTERFACE *Prot;
> IHANDLE *Handle;
> LIST_ENTRY *Link;
>
> - Status = CoreValidateHandle (UserHandle);
> - if (EFI_ERROR (Status)) {
> - return NULL;
> - }
> -
> Handle = (IHANDLE *)UserHandle;
>
> //
> @@ -1392,6 +1388,15 @@ CoreOpenProtocolInformation (
> //
> CoreAcquireProtocolLock ();
>
> + //
> + // Check for invalid UserHandle
> + //
> + Status = CoreValidateHandle (UserHandle);
> + if (EFI_ERROR (Status)) {
> + Status = EFI_NOT_FOUND;
> + goto Done;
> + }
> +
> //
> // Look at each protocol interface for a match
> //
> --
> 2.39.2
>
>
>
>
>
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#114107): https://edk2.groups.io/g/devel/message/114107
Mute This Topic: https://groups.io/mt/103781273/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/1913456212/xyzzy [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
prev parent reply other threads:[~2024-01-20 2:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-17 6:45 [edk2-devel] [PATCH 1/2] MdeModulePkg: Remove the handle validation check in CoreGetProtocolInterface Zhi Jin
2024-01-17 6:45 ` [edk2-devel] [PATCH 2/2] MdeModulePkg: Optimize CoreConnectSingleController Zhi Jin
2024-01-20 1:53 ` Michael D Kinney
2024-01-20 2:02 ` Michael D Kinney [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CO1PR11MB4929376FD623FDDC87505CFCD2772@CO1PR11MB4929.namprd11.prod.outlook.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox