From nobody Mon Feb 9 21:37:36 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A2E1C001DF for ; Mon, 31 Jul 2023 06:53:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230308AbjGaGw4 (ORCPT ); Mon, 31 Jul 2023 02:52:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230322AbjGaGwT (ORCPT ); Mon, 31 Jul 2023 02:52:19 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78EAAE7B for ; Sun, 30 Jul 2023 23:52:14 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1bb81809ca8so32995375ad.3 for ; Sun, 30 Jul 2023 23:52:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690786333; x=1691391133; 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=JYaCDiKdVWO9cZraS7V+ofxTmX3f1MZ4zggvyBMHvuW73dw6uhpgm3lFPQRZ/Quhjw R8nT04er5RhQ7SB2FrIPzQVVbAOItFDOna1B5z+PyOrWPDhyhn8c8VhgW63JM+eisPJD GFjVsiPJ4VTdVcKP3Cywd14LCClnG2DKTZ0BZmiK9Tlan0dK1barPg/bDV/E3QNwRVGx /QbKc+11uYpbdE6Z77K+tp1KCQZYPu9Y9sH5Slzdj2JTNi8BBee+vj76ruHOL7YCpTeM rnuAwfYCT87BWLs+9ygRvsW5VxXG8uNEqQlZ7r2I4heol0KLMMSEdNbta+Crmjy4qVnW I2bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690786333; x=1691391133; 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=iOmXXwc5dRj7O7TsqHZO+h/0qqzgzhU0sN/CyZUcFrqgT4ppnhpkirV7yExYEE8cvn KuH5SF0bIVjJQpLYc4Pz7EpLYzXr37PH8CZdFqCqpAEIo2qnBb68Kg24lpInQwLs3uH8 qibvlo3OZDBFw6evfbW/KMujEdlRCzVI2hXu8S3hVsDasbFl3uDTAh7vcFaZFXWVFUo4 wLthlU0UICAI0lZ0TN/LaC3iBiVyxDvbCaTJIHRaRDRUGowuQRruDFcOAla+Yp/lrSQ/ 7ynzHSY7xAjem4jXQf2ucMSi+ui/FOPbR0iorlp2kms8JQQEyd992nSMUg+7S8+bbNOY 4TaQ== X-Gm-Message-State: ABy/qLZdKY78yo4bUKvSlOfvEzy4u+Sy4ChnHDlQbh4gywsiFF9SO9g3 x2tL31h7tQDqSlvSzl1m1Kd/oQ== X-Google-Smtp-Source: APBJJlEAXdzU63g7A2VaDZiUb8jlBN3WNEQQrCc8J7xZjQJ/siookE5BblCKqYJbwhDzZf7UVQlz2g== X-Received: by 2002:a17:903:495:b0:1b7:ffb9:ea85 with SMTP id jj21-20020a170903049500b001b7ffb9ea85mr8558885plb.29.1690786333643; Sun, 30 Jul 2023 23:52:13 -0700 (PDT) Received: from localhost.localdomain (fp9875a45d.knge128.ap.nuro.jp. [152.117.164.93]) by smtp.gmail.com with ESMTPSA id kb14-20020a170903338e00b001b8ad8382a4sm7706245plb.216.2023.07.30.23.52.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jul 2023 23:52:13 -0700 (PDT) From: Masahisa Kojima To: Ard Biesheuvel , Jens Wiklander , Jan Kiszka , Sumit Garg , linux-kernel@vger.kernel.org, op-tee@lists.trustedfirmware.org Cc: Ilias Apalodimas , Johan Hovold , Masahisa Kojima , Jeremy Kerr , linux-efi@vger.kernel.org Subject: [PATCH v7 4/5] efivarfs: automatically update super block flag Date: Mon, 31 Jul 2023 15:50:39 +0900 Message-Id: <20230731065041.1447-5-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230731065041.1447-1-masahisa.kojima@linaro.org> References: <20230731065041.1447-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 =20 #include =20 @@ -184,6 +185,9 @@ static const struct attribute_group efi_subsys_attr_gro= up =3D { .is_visible =3D efi_attr_is_visible, }; =20 +struct blocking_notifier_head efivar_ops_nh; +EXPORT_SYMBOL_GPL(efivar_ops_nh); + static struct efivars generic_efivars; static struct efivar_operations generic_ops; =20 @@ -442,6 +446,8 @@ static int __init efisubsys_init(void) platform_device_register_simple("efivars", 0, NULL, 0); } =20 + BLOCKING_INIT_NOTIFIER_HEAD(&efivar_ops_nh); + error =3D 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; =20 if (down_interruptible(&efivars_lock)) return -EINTR; @@ -77,6 +78,13 @@ int efivars_register(struct efivars *efivars, =20 __efivars =3D efivars; =20 + if (efivar_supports_writes()) + event =3D EFIVAR_OPS_RDWR; + else + event =3D EFIVAR_OPS_RDONLY; + + blocking_notifier_call_chain(&efivar_ops_nh, event, NULL); + pr_info("Registered efivars operations\n"); rv =3D 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 =20 #include "internal.h" =20 LIST_HEAD(efivarfs_list); =20 +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 |=3D SB_RDONLY; + break; + case EFIVAR_OPS_RDWR: + info.sb->s_flags &=3D ~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; =20 + info.sb =3D sb; + info.nb.notifier_call =3D efivarfs_ops_notifier; + err =3D blocking_notifier_chain_register(&efivar_ops_nh, &info.nb); + if (err) + return err; + INIT_LIST_HEAD(&efivarfs_list); =20 err =3D efivar_init(efivarfs_callback, (void *)sb, true, &efivarfs_list); @@ -281,6 +312,8 @@ static int efivarfs_init_fs_context(struct fs_context *= fc) =20 static void efivarfs_kill_sb(struct super_block *sb) { + blocking_notifier_chain_unregister(&efivar_ops_nh, &info.nb); + info.sb =3D NULL; kill_litter_super(sb); =20 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 *gu= id, unsigned long table) return xen_efi_config_table_is_usable(guid, table); } =20 +/* + * 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); =20 --=20 2.30.2