Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp10589071rwd; Thu, 22 Jun 2023 01:56:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4FNSMHFqoaOdaEtvLYsMLPxgDgvCRbhbcmvQgyqMAKHsqncpUpnQkUsTk09ati+uWjVgDi X-Received: by 2002:a17:903:1ce:b0:1b6:8de4:a2c9 with SMTP id e14-20020a17090301ce00b001b68de4a2c9mr6762966plh.66.1687424184148; Thu, 22 Jun 2023 01:56:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687424184; cv=none; d=google.com; s=arc-20160816; b=IV/TvwWg1FDcUWE1VtOVLUhGWNdbGadlLGQQPw5enVq0lFyWruqWjVWd3FtoC0CDH8 GZTl92HsDoglsUN8q+47VbtTXZ3856+VqbxJi23punHvge+Arlpm2Eh7N5BxbXxestrX dThIagM0/iVgCcPJ022h8CzuGESM4alEp3FbYe9EIWQmwnP4dFrkcwNiHvlS7Yw8tQkW NxgrfyC9bYxxfLO09eweSWMlxMTGNTQTnkpeGUL4fn26DJRoerqaHJkyxXkz+p6vmZSD AV0DL3eKYR1/NtQ/9pZON7fdBr3Vy1BmE2ZyBTnXyxFLfepGCoubZGvRO6Y2ATEitP3S /HCQ== 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=liuthB6FVlJk3VZZwK7QDBE7dTzWXLlSNT3A/53JsYo=; b=huGigiZPzzFOKaXU7gVDkr7NEAhnqloyb4youJqZIQHWlYG8WY6N3anPy1Z4Q62jBd IV//ZQQN/VIQVJQZ3lr65O454OiMiq+Gn0b/8hdoMfiHdv1knHet84t9lupxwwRv1RUY 3cB7Q577WEyDPSzcpjANx2ceQg80T51029dJKJLlIfLF5Ogm5rYL8D+rtYYJDDrCsgYx qUybyJVmg1HKbYG9/lpgaMHOllPLotx7SlJWd3M248dhBB2TVtDwTmHqOJ4Hv2ruJV4o zE/VtfU6elkYTNx+4le6cdWy12lAR/p21gmwa53wXxaCL8hYCR/Hxl4/4zYp3vrYjTXl Hpdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hdLTNgmf; 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=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f5-20020a170902ab8500b001b3bd85f54bsi5725325plr.35.2023.06.22.01.56.10; Thu, 22 Jun 2023 01:56:24 -0700 (PDT) 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=@linaro.org header.s=google header.b=hdLTNgmf; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229813AbjFVIyA (ORCPT + 99 others); Thu, 22 Jun 2023 04:54:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231315AbjFVIxF (ORCPT ); Thu, 22 Jun 2023 04:53:05 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D087B2107 for ; Thu, 22 Jun 2023 01:53:03 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1b5422163f4so45407575ad.2 for ; Thu, 22 Jun 2023 01:53:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687423983; x=1690015983; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=liuthB6FVlJk3VZZwK7QDBE7dTzWXLlSNT3A/53JsYo=; b=hdLTNgmfUDlss+P4w085KQ7k0O7v872Qg7Cn0d6e6Ki1cMORUSj2TVgAFl7zVj4aQS GDdIrAfDtraZX9vWlp+SMagNbJ7psVGsdp4kHBIw8Ie1cMdU6Obts67bKslvcN2dbHI7 VjQz6r8I+CI3413S5nS3oq/aWhQb2eBaihaKJXRs1Q//4wSq8yfBc2MvHVsUhHm/yb2A iWveiOmB6hXJR7xdPkBVDsDqnDz42fuLzs8o5OsTCnGUwMlACHIfwK1K0GUQIL7FOHiS oXxzt+p2/WpMcB4jSfaGpHxVklaLBGw2QSnJQBGHYtdWT8M0izbiqzPyrNykQqBeoVKa Cy6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687423983; x=1690015983; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=liuthB6FVlJk3VZZwK7QDBE7dTzWXLlSNT3A/53JsYo=; b=fjc6yTmWOv/FAyCswmgihRE2Kog4MI4kwpJlZ6PhsgkfmvnT9x0TbQIIDt43d0Trg9 nUfuYbtn4y5O8BAL0yIr6863oRt+KYrbu7erT88FPT+J5tFKnoY0WFcVx766X1FQQl8v VN28KBoqfd9Q7d2SiXq56lt3Z68EThqVGDx13CDr9Sq37zqPBjQ+DDDSpage7RuwtusK tAC3SW+UtAapP5tSXA6j8tnYEknY7q2Tqppp2Feuudlt+59+4sixRvcM5FAn+1FaNb0M AbDNVidnfOwS48Si2uTXrrx8L08nFZhf9TbuwdKoXkGQ/BzBLgqr5lPweUCSRipnhGtV KN2g== X-Gm-Message-State: AC+VfDwwWmcMhaLO40s0lPIS2ELukQcc6bjJ8PPESH+QAc9ExicZpwrn W4Ny4IwTrCKnMvL1B+lxr1F8Hgpx/HvVUfcyAJ0= X-Received: by 2002:a17:902:e843:b0:1ac:7405:d3ba with SMTP id t3-20020a170902e84300b001ac7405d3bamr22554283plg.40.1687423983333; Thu, 22 Jun 2023 01:53:03 -0700 (PDT) Received: from localhost.localdomain (fp9875a45d.knge128.ap.nuro.jp. [152.117.164.93]) by smtp.gmail.com with ESMTPSA id z6-20020a170903018600b001b02bd00c61sm4820154plg.237.2023.06.22.01.53.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jun 2023 01:53:02 -0700 (PDT) From: Masahisa Kojima To: Ard Biesheuvel , Jens Wiklander , Sumit Garg , linux-kernel@vger.kernel.org, op-tee@lists.trustedfirmware.org Cc: Ilias Apalodimas , Johan Hovold , Masahisa Kojima , Jan Kiszka , Jeremy Kerr , linux-efi@vger.kernel.org Subject: [PATCH v6 4/4] efivarfs: automatically update super block flag Date: Thu, 22 Jun 2023 17:51:11 +0900 Message-Id: <20230622085112.1521-5-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230622085112.1521-1-masahisa.kojima@linaro.org> References: <20230622085112.1521-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 efivar operation is updated when the tee_stmm_efi module is probed. tee_stmm_efi module supports SetVariable runtime service, but user needs to manually remount the efivarfs as RW to enable the write access if the previous efivar operation does not support SerVariable and efivarfs is mounted as read-only. This commit notifies the update of efivar operation to efivarfs subsystem, then drops SB_RDONLY flag if the efivar operation supports SetVariable. Signed-off-by: Masahisa Kojima --- drivers/firmware/efi/efi.c | 6 ++++++ drivers/firmware/efi/vars.c | 8 ++++++++ fs/efivarfs/super.c | 33 +++++++++++++++++++++++++++++++++ include/linux/efi.h | 8 ++++++++ 4 files changed, 55 insertions(+) diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index d108cf03e19d..00494fcf16ba 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -32,6 +32,7 @@ #include #include #include +#include #include @@ -184,6 +185,9 @@ static const struct attribute_group efi_subsys_attr_group = { .is_visible = efi_attr_is_visible, }; +struct blocking_notifier_head efivar_ops_nh; +EXPORT_SYMBOL_GPL(efivar_ops_nh); + static struct efivars generic_efivars; static struct efivar_operations generic_ops; @@ -442,6 +446,8 @@ static int __init efisubsys_init(void) platform_device_register_simple("efivars", 0, NULL, 0); } + BLOCKING_INIT_NOTIFIER_HEAD(&efivar_ops_nh); + error = sysfs_create_group(efi_kobj, &efi_subsys_attr_group); if (error) { pr_err("efi: Sysfs attribute export failed with error %d.\n", diff --git a/drivers/firmware/efi/vars.c b/drivers/firmware/efi/vars.c index e9dc7116daf1..f654e6f6af87 100644 --- a/drivers/firmware/efi/vars.c +++ b/drivers/firmware/efi/vars.c @@ -63,6 +63,7 @@ int efivars_register(struct efivars *efivars, const struct efivar_operations *ops) { int rv; + int event; if (down_interruptible(&efivars_lock)) return -EINTR; @@ -77,6 +78,13 @@ int efivars_register(struct efivars *efivars, __efivars = efivars; + if (efivar_supports_writes()) + event = EFIVAR_OPS_RDWR; + else + event = EFIVAR_OPS_RDONLY; + + blocking_notifier_call_chain(&efivar_ops_nh, event, NULL); + pr_info("Registered efivars operations\n"); rv = 0; out: diff --git a/fs/efivarfs/super.c b/fs/efivarfs/super.c index e028fafa04f3..0f6e4d223aea 100644 --- a/fs/efivarfs/super.c +++ b/fs/efivarfs/super.c @@ -14,11 +14,36 @@ #include #include #include +#include #include "internal.h" LIST_HEAD(efivarfs_list); +struct efivarfs_info { + struct super_block *sb; + struct notifier_block nb; +}; + +static struct efivarfs_info info; + +static int efivarfs_ops_notifier(struct notifier_block *nb, unsigned long event, + void *data) +{ + switch (event) { + case EFIVAR_OPS_RDONLY: + info.sb->s_flags |= SB_RDONLY; + break; + case EFIVAR_OPS_RDWR: + info.sb->s_flags &= ~SB_RDONLY; + break; + default: + return NOTIFY_DONE; + } + + return NOTIFY_OK; +} + static void efivarfs_evict_inode(struct inode *inode) { clear_inode(inode); @@ -255,6 +280,12 @@ static int efivarfs_fill_super(struct super_block *sb, struct fs_context *fc) if (!root) return -ENOMEM; + info.sb = sb; + info.nb.notifier_call = efivarfs_ops_notifier; + err = blocking_notifier_chain_register(&efivar_ops_nh, &info.nb); + if (err) + return err; + INIT_LIST_HEAD(&efivarfs_list); err = efivar_init(efivarfs_callback, (void *)sb, true, &efivarfs_list); @@ -281,6 +312,8 @@ static int efivarfs_init_fs_context(struct fs_context *fc) static void efivarfs_kill_sb(struct super_block *sb) { + blocking_notifier_chain_unregister(&efivar_ops_nh, &info.nb); + info.sb = NULL; kill_litter_super(sb); if (!efivar_is_available()) diff --git a/include/linux/efi.h b/include/linux/efi.h index 657f7e203374..2533e4f2547f 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1350,6 +1350,14 @@ bool efi_config_table_is_usable(const efi_guid_t *guid, unsigned long table) return xen_efi_config_table_is_usable(guid, table); } +/* + * efivar ops event type + */ +#define EFIVAR_OPS_RDONLY 0 +#define EFIVAR_OPS_RDWR 1 + +extern struct blocking_notifier_head efivar_ops_nh; + void efivars_generic_ops_register(void); void efivars_generic_ops_unregister(void); -- 2.30.2