From nobody Tue Sep 16 20:06:06 2025 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 AAEE4C46467 for ; Fri, 30 Dec 2022 04:22:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234542AbiL3EWN (ORCPT ); Thu, 29 Dec 2022 23:22:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234450AbiL3EVi (ORCPT ); Thu, 29 Dec 2022 23:21:38 -0500 Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E27FDBC2F for ; Thu, 29 Dec 2022 20:21:26 -0800 (PST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 4F4DD5C0152; Thu, 29 Dec 2022 23:21:26 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 29 Dec 2022 23:21:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=russell.cc; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1672374086; x=1672460486; bh=iT OttKbNR7xkPMRwFqFwNhSHOJKloxjRTq8OiJSL07I=; b=Vjau4z2Cjv9WSC/QJQ KFLCgZfn04hK/3uFBesviigBnvowu3buCYgv0sgx7NjjwJsECaqqPKb/86Gfa44X lENo1cQVVcnuB/a8KstSqkarlQMerhe+7tJINmbZaF21ZROZIgI3Ui2/wL25jAzn 20mAt/VTIKxtwNWlZs2dzN6T2Tg9u7FboAcfOA81352JW4fgya4scByMB75Jdtr4 lhX4CCxsfPblDM/kZwSvUzt+yQAPZ7EgJAzkGzjFXG/gbFCepGXpCVOzg4Dqixjx jYgfDLgJ+tBXj3l16zZgVfA+gGbhr1Gv+3n74aah2gQ+o28fKCHdtItsoR7lYDcj KHmg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1672374086; x=1672460486; bh=iTOttKbNR7xkP MRwFqFwNhSHOJKloxjRTq8OiJSL07I=; b=fYSOlDwXmFv07ShosbMAKkMWi4MJv gs+5tBotLlHPBvn1jnpKJKPnYq3DYfSYfvgz4aekBTvu38y2oKwaFfKZznKJhgeY Rs5/zuJDgL0Kudsu9/IcZCMp4fVftbSWHbRX+zX6j68Qm2OQQBm38Iiqxz/iJnHd JO/eKgULNoZC/805YfT/c23Ac8s9/Gy/L3oZP+qQVx04n6tZ18Fk1FdlCKs2sTA3 xzL9L3scAHbA9v7l+pnRka+74RyRrnF7c1bhakE4Er55n5rnqa6+TnJol1z1PWf9 BUHUvpng31kHa4eTai9cDN92poeQNBBxXVxs/cFtLQyJOdZUQsk8Y4LVw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrieehgdejtdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdeftddmnecujfgurhephffvve fufffkofgjfhgggfestdekredtredttdenucfhrhhomheptfhushhsvghllhcuvehurhhr vgihuceorhhushgtuhhrsehruhhsshgvlhhlrdgttgeqnecuggftrfgrthhtvghrnhephf dvuefgtddvieeigefffeffkeeigedvgfeitdejteffveefhfdtheejffeiiedvnecuvehl uhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomheprhhushgtuhhrse hruhhsshgvlhhlrdgttg X-ME-Proxy: Feedback-ID: i4421424f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Dec 2022 23:21:23 -0500 (EST) From: Russell Currey To: linuxppc-dev@lists.ozlabs.org Cc: gregkh@linuxfoundation.org, gcwilson@linux.ibm.com, linux-kernel@vger.kernel.org, nayna@linux.ibm.com, ajd@linux.ibm.com, zohar@linux.ibm.com, mpe@ellerman.id.au, Russell Currey Subject: [PATCH v2 6/7] powerpc/secvar: Extend sysfs to include config vars Date: Fri, 30 Dec 2022 15:20:13 +1100 Message-Id: <20221230042014.154483-7-ruscur@russell.cc> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221230042014.154483-1-ruscur@russell.cc> References: <20221230042014.154483-1-ruscur@russell.cc> 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" The forthcoming pseries consumer of the secvar API wants to expose a number of config variables. Allowing secvar implementations to provide their own sysfs attributes makes it easy for consumers to expose what they need to. This is not being used by the OPAL secvar implementation at present, and the config directory will not be created if no attributes are set. Signed-off-by: Russell Currey Reviewed-by: Andrew Donnellan --- I played around with adding an API call to facilitate a more generic key/value interface for config variables and it seemed like unnecessary complexity. I think this is cleaner. If there was ever a secvar interface other than sysfs we'd have to rework it, though. arch/powerpc/include/asm/secvar.h | 3 +++ arch/powerpc/kernel/secvar-sysfs.c | 40 ++++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/include/asm/secvar.h b/arch/powerpc/include/asm/s= ecvar.h index 92d2c051918b..250e7066b6da 100644 --- a/arch/powerpc/include/asm/secvar.h +++ b/arch/powerpc/include/asm/secvar.h @@ -10,6 +10,7 @@ =20 #include #include +#include =20 extern const struct secvar_operations *secvar_ops; =20 @@ -27,10 +28,12 @@ struct secvar_operations { #ifdef CONFIG_PPC_SECURE_BOOT =20 extern void set_secvar_ops(const struct secvar_operations *ops); +extern void set_secvar_config_attrs(const struct attribute **attrs); =20 #else =20 static inline void set_secvar_ops(const struct secvar_operations *ops) { } +static inline void set_secvar_config_attrs(const struct attribute **attrs)= { } =20 #endif =20 diff --git a/arch/powerpc/kernel/secvar-sysfs.c b/arch/powerpc/kernel/secva= r-sysfs.c index aa1daec480e1..ad1e1d72d2ae 100644 --- a/arch/powerpc/kernel/secvar-sysfs.c +++ b/arch/powerpc/kernel/secvar-sysfs.c @@ -15,9 +15,17 @@ =20 #define NAME_MAX_SIZE 1024 =20 +const struct attribute **secvar_config_attrs __ro_after_init =3D NULL; + static struct kobject *secvar_kobj; static struct kset *secvar_kset; =20 +void set_secvar_config_attrs(const struct attribute **attrs) +{ + WARN_ON_ONCE(secvar_config_attrs); + secvar_config_attrs =3D attrs; +} + static ssize_t format_show(struct kobject *kobj, struct kobj_attribute *at= tr, char *buf) { @@ -134,6 +142,16 @@ static int update_kobj_size(void) return 0; } =20 +static int secvar_sysfs_config(struct kobject *kobj) +{ + struct attribute_group config_group =3D { + .name =3D "config", + .attrs =3D (struct attribute **)secvar_config_attrs, + }; + + return sysfs_create_group(kobj, &config_group); +} + static int secvar_sysfs_load(void) { char *name; @@ -196,26 +214,38 @@ static int secvar_sysfs_init(void) =20 rc =3D sysfs_create_file(secvar_kobj, &format_attr.attr); if (rc) { - kobject_put(secvar_kobj); - return -ENOMEM; + pr_err("secvar: Failed to create format object\n"); + rc =3D -ENOMEM; + goto err; } =20 secvar_kset =3D kset_create_and_add("vars", NULL, secvar_kobj); if (!secvar_kset) { pr_err("secvar: sysfs kobject registration failed.\n"); - kobject_put(secvar_kobj); - return -ENOMEM; + rc =3D -ENOMEM; + goto err; } =20 rc =3D update_kobj_size(); if (rc) { pr_err("Cannot read the size of the attribute\n"); - return rc; + goto err; + } + + if (secvar_config_attrs) { + rc =3D secvar_sysfs_config(secvar_kobj); + if (rc) { + pr_err("secvar: Failed to create config directory\n"); + goto err; + } } =20 secvar_sysfs_load(); =20 return 0; +err: + kobject_put(secvar_kobj); + return rc; } =20 late_initcall(secvar_sysfs_init); --=20 2.38.1