From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D4DD2C433FE for ; Wed, 12 Oct 2022 00:09:57 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1415A84C4D; Wed, 12 Oct 2022 02:09:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="berQ/9gz"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 42AB084C8D; Wed, 12 Oct 2022 02:09:53 +0200 (CEST) Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8675884BE0 for ; Wed, 12 Oct 2022 02:09:49 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pj1-x1031.google.com with SMTP id p3-20020a17090a284300b0020a85fa3ffcso475937pjf.2 for ; Tue, 11 Oct 2022 17:09:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date:from:to:cc :subject:date:message-id:reply-to; bh=KZkuJ56A0WwT5nkDbrmUnk6m1NapJ8mtzUCRvbqhzj4=; b=berQ/9gzKgUjDAs+QmstYl15QivYXUeXf9U5/vE2CUIX+HsrSrE6CII6jx9kE6NNXK Ue58votzFU/ZjHWyZeAf14jXvwJ8CHRA2c9fkGe6TEBuODxKPF7hEF020X7d0+JXIXhf YhXuAULjJesyAMd9A5gReb0BLJV9/Uw/KvZEi10g+mG5i+d4ovJxXA8Uomjev30U0y3c O+jlrvmh9wXVFMNBYjCs8SzppwLsa58s+mj0jLNPQaKfhy3oP2XD8Cy3D+RzzNxjLf34 9k788S+2S1RfEn2IM/+bh9fm3KTDevvm5zQegbzB1fWaFr26VdgR1Z8/Ym9WzVVjo/8A 7GDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KZkuJ56A0WwT5nkDbrmUnk6m1NapJ8mtzUCRvbqhzj4=; b=CkUSvXKoqUNoynlzCR5eREeOZmbm6xDuBNq0arnLg1qtYIWFlB76sBFwG7sRPv4Yaz aJ5M1k3aQLVeY941oSoQZUG9l7INTDhvcbk/EUAssmVp5GYoUQ3QT6jEwtZnnRhc/qj5 KuM4Xd1CyYR/zKueoOBpgHoSbzpNYJMgAtNjw6v0tgjrKN+fqoBMpRTtaYe4ne1eyL3k yYAdJqM7wf6TOCUYxGQ+S535Blnv/oQ/Ompx/p0Ko5qRSvJUe42q9yIDhVycIr0YT5Sq kWqACUjYbbrth0R5Ti7v3yRfURyv3YQAewK9ZokDlZcPGdbKgPDlB0uORPgLDXJX9+P1 zLOQ== X-Gm-Message-State: ACrzQf0LPE3xQY8b7GMYXauZ/8K3+iAm8VEqPyssrD96tFLBJ2BOaKXC G45QyJbH5ftMpGjsJ/KPQqfUUA== X-Google-Smtp-Source: AMsMyM7q+nnWrv2Nk7evqDRAhL/P6Q+hnoPofBy+naNfqaUZdTVX7xHivV0nS9SwEbL+Kyov3TAdEQ== X-Received: by 2002:a17:902:a606:b0:178:57e4:a0c1 with SMTP id u6-20020a170902a60600b0017857e4a0c1mr26684672plq.83.1665533387450; Tue, 11 Oct 2022 17:09:47 -0700 (PDT) Received: from laputa ([2400:4050:c3e1:100:886e:2a2f:de1a:53f4]) by smtp.gmail.com with ESMTPSA id mt11-20020a17090b230b00b001fdbb2e38acsm165033pjb.5.2022.10.11.17.09.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Oct 2022 17:09:46 -0700 (PDT) Date: Wed, 12 Oct 2022 09:09:43 +0900 From: AKASHI Takahiro To: Heinrich Schuchardt Cc: Ilias Apalodimas , u-boot@lists.denx.de Subject: Re: [PATCH 1/1] efi_loader: CloseProtocol in efi_fmp_find Message-ID: <20221012000943.GA49651@laputa> Mail-Followup-To: AKASHI Takahiro , Heinrich Schuchardt , Ilias Apalodimas , u-boot@lists.denx.de References: <20221007140623.167909-1-heinrich.schuchardt@canonical.com> <20221011004939.GA39168@laputa> <7d7b2d2d-ef72-7e42-c503-78cabc967f49@canonical.com> <20221011073541.GB39168@laputa> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean On Tue, Oct 11, 2022 at 01:08:26PM +0200, Heinrich Schuchardt wrote: > > > On 10/11/22 09:35, AKASHI Takahiro wrote: > > On Tue, Oct 11, 2022 at 07:58:11AM +0200, Heinrich Schuchardt wrote: > > > > > > > > > On 10/11/22 02:49, AKASHI Takahiro wrote: > > > > The commit message is not accurate. > > > > > > > > On Fri, Oct 07, 2022 at 04:06:23PM +0200, Heinrich Schuchardt wrote: > > > > > The CloseProtocol() boot service requires a handle as first argument. > > > > > Passing the protocol interface is incorrect. > > > > > > > > Correct, but > > > > > > > > > CloseProtocol() only has an effect if called with a non-zero value for > > > > > agent_handle. HandleProtocol() uses an opaque agent_handle when invoking > > > > > OpenProtocol() (currently NULL). > > > > > > > > No. OpenProtocol() is called with efi_root as an agent handle. > > > > So, calling CloseProtocol() is a right thing at the end. > > > > > > Typically an agent handle is used to relate to a driver exposing the driver > > > binding protocol. > > > > Why can't we, other than a driver, call HandleProtocol() > > as a convenient way of accessing an interface? > > The description of HandleProtocol() clearly says that it is deprecated. > > The assumption that the UEFI specification makes in it is example code that > you never be able to close a protocol opened with HandleProtocol. I don't understand this statement. I never find any description of "you never be able to close a protocol opened with HandleProtocol" in the spec. > After the first usage of handle protocol the open protocol information with > the opaque agent handle will block the protocol interface from ever being > removed by the driver exposing it. > > > > > > The root node does not expose the driver binding protocol. > > > > So do you mean the current implementation of HandleProtocol() is wrong? > > Yes. If you ever install a boot time driver, it might remove a protocol > interface which is actually still in use. Again, what about efi_load_image_from_path() that I gave in another example? I think that you have something to do *before* you submit this patch. Anyhow, your commit message is not accurate. -Takahiro Akashi > > > > > Why would you want to create an open protocol information entry here? > > > > To access get_image_info() quickly. > > This is not related to an open protocol information (see the UEFI spec > description of OpenProtocolInformation()). > > Best regards > > Heinrich > > > > > > Do you think anything with the code after the patch is wrong? > > > > No reason to replace handle_protocol(). > > > > Another example is here: > > efi_load_image_from_path() > > efi_handle_protocol(device, guid, (void **)&load_file_protocol)); > > ... > > efi_close_protocol(device, guid, efi_root, NULL); > > > > I believe that this function is anything but a driver. > > I think using HandleProtocol() (or preferably OpenProtocol()) and CloseProtocol() > > in pair seems totally sane. > > > > -Takahiro Akashi > > > > > > > > > Best regards > > > > > > Heinrich > > > > > > > > > > > > Therefore HandleProtocol() should be > > > > > avoided. > > > > > > > > > > * Replace the LocateHandle() call by efi_search_protocol(). > > > > > > > > LocateHandle() -> efi_handle_protocol() > > > > > > > > So you could have fixed this way: > > > > EFI_CALL(efi_close_protocol(handle, ..., &efi_root, NULL); > > > > > > > > I preferred to use EFI_CALL() over this file as you can see. > > > > > > > > -Takahiro Akashi > > > > > > > > > * Remove the CloseProtocol() call. > > > > > > > > > > Fixes: 8d99026f0697 ("efi_loader: capsule: support firmware update") > > > > > Signed-off-by: Heinrich Schuchardt > > > > > --- > > > > > lib/efi_loader/efi_capsule.c | 14 ++++++-------- > > > > > 1 file changed, 6 insertions(+), 8 deletions(-) > > > > > > > > > > diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c > > > > > index b6bd2d6af8..397e393a18 100644 > > > > > --- a/lib/efi_loader/efi_capsule.c > > > > > +++ b/lib/efi_loader/efi_capsule.c > > > > > @@ -159,12 +159,14 @@ efi_fmp_find(efi_guid_t *image_type, u8 image_index, u64 instance, > > > > > efi_status_t ret; > > > > > for (i = 0, handle = handles; i < no_handles; i++, handle++) { > > > > > - ret = EFI_CALL(efi_handle_protocol( > > > > > - *handle, > > > > > - &efi_guid_firmware_management_protocol, > > > > > - (void **)&fmp)); > > > > > + struct efi_handler *fmp_handler; > > > > > + > > > > > + ret = efi_search_protocol( > > > > > + *handle, &efi_guid_firmware_management_protocol, > > > > > + &fmp_handler); > > > > > if (ret != EFI_SUCCESS) > > > > > continue; > > > > > + fmp = fmp_handler->protocol_interface; > > > > > /* get device's image info */ > > > > > info_size = 0; > > > > > @@ -215,10 +217,6 @@ efi_fmp_find(efi_guid_t *image_type, u8 image_index, u64 instance, > > > > > skip: > > > > > efi_free_pool(package_version_name); > > > > > free(image_info); > > > > > - EFI_CALL(efi_close_protocol( > > > > > - (efi_handle_t)fmp, > > > > > - &efi_guid_firmware_management_protocol, > > > > > - NULL, NULL)); > > > > > if (found) > > > > > return fmp; > > > > > } > > > > > -- > > > > > 2.37.2 > > > > >