From patchwork Fri Jan 20 07:42:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Donnellan X-Patchwork-Id: 46184 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp65426wrn; Thu, 19 Jan 2023 23:44:24 -0800 (PST) X-Google-Smtp-Source: AMrXdXunAmcw+1tRhjjYkXP26yJOAJjOp36oHWISCtYkM7282mlVZA2NYkCFBV17SZCjw7r8cSJS X-Received: by 2002:a17:90a:738d:b0:229:3d1c:3612 with SMTP id j13-20020a17090a738d00b002293d1c3612mr14754786pjg.2.1674200664631; Thu, 19 Jan 2023 23:44:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674200664; cv=none; d=google.com; s=arc-20160816; b=kE7HEuyPBlW24XQGVAwV3iBdG7V1Dc4US1MUfidCcv/rTQIs0YzSkap6QQjwc3OYb4 7H9VlHk19WuuSFTycnQXRmh/bb/+VkKGxhDlEZjLzF4Nf32BR/EQENGMdyD6yMcAb6l6 oote1iiz4xTvGZX07FF5famljJgLjhspJZDNOCU4oAJjMqf850GTQPO4UvGRfLtG8kf7 gK9K53Pl9G+9SRXjCWHPr2A01rFmufueRzsp08ZILMcLUzMP2wmcm3Gbr2RllETIp5O5 FOSaAjyCnvf8gKL6zaE7IHyYm1ckTvkkXEM+tRLXGQtoqJYYFHxYKr1HgDaaZNlm/0K3 Rf1w== 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=X9RWK7u+lqZXzvGKT1EUO/s3FORrcaMWOKcvj7V2ig0=; b=iO8PSFAanbZ6Fwm5Uv34i9jgqVBCqXgd9PPK1TMR3OdgmQR+OuDmOFVSa0vsVLf6++ IUlAyJ+Cgn8U2AMxOT29/6u5Difk5UWUacrBboLw5wtnNa8F1k5tmimDdb+YaVvrQj0p wLHahTKND9fB0bXG4BA7fSz3KoNiowZTqdHq8aW7p3ju6pAwbG10m22YOjkJ4xxnPSZr 3mswbs9+iGqlqmRVE6k/IdD2izeFsNqJI0m9wPU2XZ+daGrTg/13JPnhZ3nfaK7oj7oX ksL3N6AR5Wqkw53/0w9BLXe66AeJDjXB2qqcXG14IiJT9PdBeM5OrPjZOfEhA1jOobZE E4FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=HY43z9Q0; 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=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l7-20020a17090a72c700b0022939a02263si1758933pjk.45.2023.01.19.23.44.11; Thu, 19 Jan 2023 23:44:24 -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=@ibm.com header.s=pp1 header.b=HY43z9Q0; 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=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230325AbjATHoD (ORCPT + 99 others); Fri, 20 Jan 2023 02:44:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230163AbjATHnt (ORCPT ); Fri, 20 Jan 2023 02:43:49 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5975A7DF95; Thu, 19 Jan 2023 23:43:48 -0800 (PST) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30K6nkao012526; Fri, 20 Jan 2023 07:43:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=X9RWK7u+lqZXzvGKT1EUO/s3FORrcaMWOKcvj7V2ig0=; b=HY43z9Q0MAKVMH4kMvWtja8PBBnBjCWN9WJG5hexyzBf+4Gif1by1q1qKTVOUGiQNoxU mzP6G7UkfiItSxS/rtXKRmKevnjUa99ZMsP2hxgJA10MqrP0kIljKHk7RDj2mMZgEK68 kW6rV5xso7ZHFuPxbkxHwcyl/ilHyqO9/DpyWrHEmmX/ik5mE2FhwfeogNlzEFfw4ei3 QZL0IEG8WKXiQQf/HmnMGrzuHkeizjbe1ZdUmKaB1axJscDVpyb2kQsmKxXBljyFWgvD QSDitqo6Xcgj1RuRV9Q0CCFVwFgzu2ZVaDvXF6I0TJBGGUDuWLi1Dr7HFm+9dkIrVXzq eQ== Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3n7p1e92gf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Jan 2023 07:43:40 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 30JK7XrM006209; Fri, 20 Jan 2023 07:43:37 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3n3knfqpah-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 Jan 2023 07:43:37 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 30K7hZaq37355810 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Jan 2023 07:43:35 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 347A420040; Fri, 20 Jan 2023 07:43:35 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3E59F20043; Fri, 20 Jan 2023 07:43:34 +0000 (GMT) Received: from ozlabs.au.ibm.com (unknown [9.192.253.14]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 20 Jan 2023 07:43:34 +0000 (GMT) Received: from jarvis-ozlabs-ibm-com.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id E92B06060A; Fri, 20 Jan 2023 18:43:29 +1100 (AEDT) From: Andrew Donnellan To: linuxppc-dev@lists.ozlabs.org, linux-integrity@vger.kernel.org Cc: gregkh@linuxfoundation.org, gcwilson@linux.ibm.com, linux-kernel@vger.kernel.org, nayna@linux.ibm.com, ruscur@russell.cc, zohar@linux.ibm.com, mpe@ellerman.id.au, gjoyce@linux.ibm.com, sudhakar@linux.ibm.com, bgray@linux.ibm.com, erichte@linux.ibm.com, joel@jms.id.au Subject: [PATCH v4 09/24] powerpc/secvar: Extend sysfs to include config vars Date: Fri, 20 Jan 2023 18:42:51 +1100 Message-Id: <20230120074306.1326298-10-ajd@linux.ibm.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230120074306.1326298-1-ajd@linux.ibm.com> References: <20230120074306.1326298-1-ajd@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: LErvDv8MSMcIYhMWMHLUPFAtvp02iDt4 X-Proofpoint-GUID: LErvDv8MSMcIYhMWMHLUPFAtvp02iDt4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-20_04,2023-01-19_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 mlxscore=0 malwarescore=0 adultscore=0 bulkscore=0 phishscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301200070 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,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?1755526636082039280?= X-GMAIL-MSGID: =?utf-8?q?1755526636082039280?= From: Russell Currey 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 Co-developed-by: Andrew Donnellan Signed-off-by: Andrew Donnellan --- v3: Remove unnecessary "secvar:" prefix from error messages (ajd) Merge config attributes into secvar_operations (mpe) --- arch/powerpc/include/asm/secvar.h | 2 ++ arch/powerpc/kernel/secvar-sysfs.c | 33 +++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/include/asm/secvar.h b/arch/powerpc/include/asm/secvar.h index b97ab793cc8a..5ed141c711b0 100644 --- a/arch/powerpc/include/asm/secvar.h +++ b/arch/powerpc/include/asm/secvar.h @@ -10,6 +10,7 @@ #include #include +#include extern const struct secvar_operations *secvar_ops; @@ -19,6 +20,7 @@ struct secvar_operations { int (*set)(const char *key, u64 key_len, u8 *data, u64 data_size); ssize_t (*format)(char *buf, size_t bufsize); int (*max_size)(u64 *max_size); + const struct attribute **config_attrs; }; #ifdef CONFIG_PPC_SECURE_BOOT diff --git a/arch/powerpc/kernel/secvar-sysfs.c b/arch/powerpc/kernel/secvar-sysfs.c index 53ac01e0eb0b..d7936d8c7478 100644 --- a/arch/powerpc/kernel/secvar-sysfs.c +++ b/arch/powerpc/kernel/secvar-sysfs.c @@ -144,6 +144,19 @@ static int update_kobj_size(void) return 0; } +static int secvar_sysfs_config(struct kobject *kobj) +{ + struct attribute_group config_group = { + .name = "config", + .attrs = (struct attribute **)secvar_ops->config_attrs, + }; + + if (secvar_ops->config_attrs) + return sysfs_create_group(kobj, &config_group); + + return 0; +} + static int secvar_sysfs_load(void) { struct kobject *kobj; @@ -206,26 +219,36 @@ static int secvar_sysfs_init(void) rc = sysfs_create_file(secvar_kobj, &format_attr.attr); if (rc) { - kobject_put(secvar_kobj); - return -ENOMEM; + pr_err("Failed to create format object\n"); + rc = -ENOMEM; + goto err; } secvar_kset = kset_create_and_add("vars", NULL, secvar_kobj); if (!secvar_kset) { pr_err("sysfs kobject registration failed\n"); - kobject_put(secvar_kobj); - return -ENOMEM; + rc = -ENOMEM; + goto err; } rc = update_kobj_size(); if (rc) { pr_err("Cannot read the size of the attribute\n"); - return rc; + goto err; + } + + rc = secvar_sysfs_config(secvar_kobj); + if (rc) { + pr_err("Failed to create config directory\n"); + goto err; } secvar_sysfs_load(); return 0; +err: + kobject_put(secvar_kobj); + return rc; } late_initcall(secvar_sysfs_init);