Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/secvar: Extend sysfs to include config vars

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 <ruscur@russell.cc>
Co-developed-by: Andrew Donnellan <ajd@linux.ibm.com>
Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20230210080401.345462-11-ajd@linux.ibm.com

authored by

Russell Currey and committed by
Michael Ellerman
86b6c0ae caefd3b7

+30 -5
+2
arch/powerpc/include/asm/secvar.h
··· 10 10 11 11 #include <linux/types.h> 12 12 #include <linux/errno.h> 13 + #include <linux/sysfs.h> 13 14 14 15 extern const struct secvar_operations *secvar_ops; 15 16 ··· 20 19 int (*set)(const char *key, u64 key_len, u8 *data, u64 data_size); 21 20 ssize_t (*format)(char *buf, size_t bufsize); 22 21 int (*max_size)(u64 *max_size); 22 + const struct attribute **config_attrs; 23 23 }; 24 24 25 25 #ifdef CONFIG_PPC_SECURE_BOOT
+28 -5
arch/powerpc/kernel/secvar-sysfs.c
··· 144 144 return 0; 145 145 } 146 146 147 + static int secvar_sysfs_config(struct kobject *kobj) 148 + { 149 + struct attribute_group config_group = { 150 + .name = "config", 151 + .attrs = (struct attribute **)secvar_ops->config_attrs, 152 + }; 153 + 154 + if (secvar_ops->config_attrs) 155 + return sysfs_create_group(kobj, &config_group); 156 + 157 + return 0; 158 + } 159 + 147 160 static int secvar_sysfs_load(void) 148 161 { 149 162 struct kobject *kobj; ··· 221 208 222 209 rc = sysfs_create_file(secvar_kobj, &format_attr.attr); 223 210 if (rc) { 224 - kobject_put(secvar_kobj); 225 - return -ENOMEM; 211 + pr_err("Failed to create format object\n"); 212 + rc = -ENOMEM; 213 + goto err; 226 214 } 227 215 228 216 secvar_kset = kset_create_and_add("vars", NULL, secvar_kobj); 229 217 if (!secvar_kset) { 230 218 pr_err("sysfs kobject registration failed\n"); 231 - kobject_put(secvar_kobj); 232 - return -ENOMEM; 219 + rc = -ENOMEM; 220 + goto err; 233 221 } 234 222 235 223 rc = update_kobj_size(); 236 224 if (rc) { 237 225 pr_err("Cannot read the size of the attribute\n"); 238 - return rc; 226 + goto err; 227 + } 228 + 229 + rc = secvar_sysfs_config(secvar_kobj); 230 + if (rc) { 231 + pr_err("Failed to create config directory\n"); 232 + goto err; 239 233 } 240 234 241 235 secvar_sysfs_load(); 242 236 243 237 return 0; 238 + err: 239 + kobject_put(secvar_kobj); 240 + return rc; 244 241 } 245 242 246 243 late_initcall(secvar_sysfs_init);