From patchwork Thu Jan 19 16:42:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 45862 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp436413wrn; Thu, 19 Jan 2023 08:57:58 -0800 (PST) X-Google-Smtp-Source: AMrXdXvuof1bCz6q5Akj0zBWe/WBAXveONGmsLFYcMhdXr6pl1AjMWHTrOrJnhnvbyz6lEUCCPij X-Received: by 2002:a17:906:90c3:b0:870:b5bb:625d with SMTP id v3-20020a17090690c300b00870b5bb625dmr11914061ejw.16.1674147478241; Thu, 19 Jan 2023 08:57:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674147478; cv=none; d=google.com; s=arc-20160816; b=Vi/azrljUYz6wt+39knHbEpaMJMWCOYO1ZDDk4FHZ6PYQ/tTTyd1NCmYEHpVQpjwsw 3vg9HDeMebykigHnAqp3Qzk+xGnpdU287aerAaw2C0n6D9d3ZwpCXpv6QnSdTpB6zrOM kYxUIYSywNLsLxUctCPh1+Lx1JN0g5GeGrHvZd9amTM6pY00LN19eQd/zp2cv2f4/7RZ JtJgJ6dPjoyk+aXLMTNsagBz4XJ3gtBThgu1Hjxi6sGqmHP9Tqlh73o79BngU4H0i3kA l+2fM5i2xuinz7UcNbBo9DHWRE1DwwlhJ69iefcSUFhLrKmugiOLtMsZ+jpzfSahVRR8 TPsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qybvzKiStNiUNGATO663RjHw6VximamN/ZpXa1IOz+M=; b=0mhVCELE7zxKyJ3MJWPjGuNOeys9iAi5GJ5Hk1fCudHnj5lrDYlSV1MQH4WZMLJ3tc utfslB2MAlcxvaRVbI9/ILFT1DlvvuEK5i9/whwLZdqWG6G1d+8PDArfez/WUdge5M/+ 8stt7bAGQ+m8VuwjFMhkfAqsZ/MDfvTdPMkPSDER6rEQQ9x92GLwQsgPrdsr5K9AYW6b PS2ufJ89d11AQ6+71sZlRzZ198xZE8OhJibuj2hlrSqEYOIiyYdUGzH73xCU6tcsBo3o 65rKvN12wJBFx7s21ON0afSTQ3wAvc5W8j/hkdOZczvIqVtBlcR0QZctqeCW/ynHYUoZ AL0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FcC3eOC0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j4-20020a1709062a0400b007adc8d6b77esi33886524eje.308.2023.01.19.08.57.34; Thu, 19 Jan 2023 08:57:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FcC3eOC0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230451AbjASQqO (ORCPT + 99 others); Thu, 19 Jan 2023 11:46:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230403AbjASQqE (ORCPT ); Thu, 19 Jan 2023 11:46:04 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 756998BAA2; Thu, 19 Jan 2023 08:45:51 -0800 (PST) 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 sin.source.kernel.org (Postfix) with ESMTPS id C7B7ACE24F8; Thu, 19 Jan 2023 16:45:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E105C43392; Thu, 19 Jan 2023 16:45:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674146748; bh=QeWwkHCkmPI6InIWABry3ht60PE2twa3Wx83EnocKUc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FcC3eOC0tK1JDm2vU5t6lG8N6tu2TTkZsEkQFINKv3WNnID1xUrnhqQa7j+fE2+eO LcdFhQp59mnpkqoWEGnz6PhnIH/Pg6NwhEDX7x3kj4AHY50PIe4zwX0LpS+WD+V/5J cwDq20s978Dr0himuRr1MO4WFz+zoObpD4Kinu4ZdJ1rDUhcwohVF99J00aZlaUHWT lAdsUpO2pS7hFAQTko8jDkFb2joMJ07UK8+jEeVo1m1033azICpEOXvSQaiwXi2shX DLK+9UsVAtYuOCeg4TWtEhoZF0yyCbbeDcOgI8Sya7pkc4vj0Daq03uym8g9IvcfYK UhqdEVTUPEutw== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1pIY3M-0007Mv-7w; Thu, 19 Jan 2023 17:46:16 +0100 From: Johan Hovold To: Ard Biesheuvel Cc: Matthew Garrett , Jeremy Kerr , Maximilian Luz , linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 3/4] efi: verify that variable services are supported Date: Thu, 19 Jan 2023 17:42:54 +0100 Message-Id: <20230119164255.28091-4-johan+linaro@kernel.org> X-Mailer: git-send-email 2.38.2 In-Reply-To: <20230119164255.28091-1-johan+linaro@kernel.org> References: <20230119164255.28091-1-johan+linaro@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755470799327381840?= X-GMAIL-MSGID: =?utf-8?q?1755470866047343809?= Current Qualcomm UEFI firmware does not implement the variable services but not all revisions clear the corresponding bits in the RT_PROP table services mask and instead the corresponding calls return EFI_UNSUPPORTED. This leads to efi core registering the generic efivar ops even when the variable services are not supported or when they are accessed through some other interface (e.g. Google SMI or the upcoming Qualcomm SCM implementation). Instead of playing games with init call levels to make sure that the custom implementations are registered after the generic one, make sure that get_next_variable() is actually supported before registering the generic ops. Signed-off-by: Johan Hovold --- drivers/firmware/efi/efi.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index a7f1a32537f1..03ccc4e8d1fc 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -187,8 +187,27 @@ static const struct attribute_group efi_subsys_attr_group = { static struct efivars generic_efivars; static struct efivar_operations generic_ops; +static bool generic_ops_supported(void) +{ + unsigned long name_size; + efi_status_t status; + efi_char16_t name; + efi_guid_t guid; + + name_size = sizeof(name); + + status = efi.get_next_variable(&name_size, &name, &guid); + if (status == EFI_UNSUPPORTED) + return false; + + return true; +} + static int generic_ops_register(void) { + if (!generic_ops_supported()) + return 0; + generic_ops.get_variable = efi.get_variable; generic_ops.get_next_variable = efi.get_next_variable; generic_ops.query_variable_store = efi_query_variable_store; @@ -202,6 +221,9 @@ static int generic_ops_register(void) static void generic_ops_unregister(void) { + if (!generic_ops.get_variable) + return; + efivars_unregister(&generic_efivars); }