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

powerpc/secvar: Allow backend to populate static list of variable names

Currently, the list of variables is populated by calling
secvar_ops->get_next() repeatedly, which is explicitly modelled on the
OPAL API (including the keylen parameter).

For the upcoming PLPKS backend, we have a static list of variable names.
It is messy to fit that into get_next(), so instead, let the backend put
a NULL-terminated array of variable names into secvar_ops->var_names,
which will be used if get_next() is undefined.

Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
Signed-off-by: Russell Currey <ruscur@russell.cc>
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-12-ajd@linux.ibm.com

authored by

Andrew Donnellan and committed by
Michael Ellerman
50a466bf 86b6c0ae

+52 -21
+4
arch/powerpc/include/asm/secvar.h
··· 21 21 ssize_t (*format)(char *buf, size_t bufsize); 22 22 int (*max_size)(u64 *max_size); 23 23 const struct attribute **config_attrs; 24 + 25 + // NULL-terminated array of fixed variable names 26 + // Only used if get_next() isn't provided 27 + const char * const *var_names; 24 28 }; 25 29 26 30 #ifdef CONFIG_PPC_SECURE_BOOT
+48 -21
arch/powerpc/kernel/secvar-sysfs.c
··· 157 157 return 0; 158 158 } 159 159 160 - static int secvar_sysfs_load(void) 160 + static int add_var(const char *name) 161 161 { 162 162 struct kobject *kobj; 163 + int rc; 164 + 165 + kobj = kzalloc(sizeof(*kobj), GFP_KERNEL); 166 + if (!kobj) 167 + return -ENOMEM; 168 + 169 + kobject_init(kobj, &secvar_ktype); 170 + 171 + rc = kobject_add(kobj, &secvar_kset->kobj, "%s", name); 172 + if (rc) { 173 + pr_warn("kobject_add error %d for attribute: %s\n", rc, 174 + name); 175 + kobject_put(kobj); 176 + return rc; 177 + } 178 + 179 + kobject_uevent(kobj, KOBJ_ADD); 180 + return 0; 181 + } 182 + 183 + static int secvar_sysfs_load(void) 184 + { 163 185 u64 namesize = 0; 164 186 char *name; 165 187 int rc; ··· 201 179 break; 202 180 } 203 181 204 - kobj = kzalloc(sizeof(*kobj), GFP_KERNEL); 205 - if (!kobj) { 206 - rc = -ENOMEM; 207 - break; 208 - } 209 - 210 - kobject_init(kobj, &secvar_ktype); 211 - 212 - rc = kobject_add(kobj, &secvar_kset->kobj, "%s", name); 213 - if (rc) { 214 - pr_warn("kobject_add error %d for attribute: %s\n", rc, 215 - name); 216 - kobject_put(kobj); 217 - kobj = NULL; 218 - } 219 - 220 - if (kobj) 221 - kobject_uevent(kobj, KOBJ_ADD); 222 - 182 + rc = add_var(name); 223 183 } while (!rc); 224 184 225 185 kfree(name); 226 186 return rc; 187 + } 188 + 189 + static int secvar_sysfs_load_static(void) 190 + { 191 + const char * const *name_ptr = secvar_ops->var_names; 192 + int rc; 193 + 194 + while (*name_ptr) { 195 + rc = add_var(*name_ptr); 196 + if (rc) 197 + return rc; 198 + name_ptr++; 199 + } 200 + 201 + return 0; 227 202 } 228 203 229 204 static int secvar_sysfs_init(void) ··· 264 245 goto err; 265 246 } 266 247 267 - secvar_sysfs_load(); 248 + if (secvar_ops->get_next) 249 + rc = secvar_sysfs_load(); 250 + else 251 + rc = secvar_sysfs_load_static(); 252 + 253 + if (rc) { 254 + pr_err("Failed to create variable attributes\n"); 255 + goto err; 256 + } 268 257 269 258 return 0; 270 259 err: