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

s390/zcrypt: Fix initialisation when zcrypt is built-in

ap_bus and zcrypt_api assumed module information to always be present
and initialisation to be done in module loading order (symbol
dependencies). These assumptions don't hold if zcrypt is built-in;
THIS_MODULE will be NULL in this case and init call order is linker
order, i.e. Makefile order.

Fix initialisation order by ordering the object files in the Makefile
according to their dependencies, like the module loader would do.

Fix message type registration by using a dedicated "name" field rather
than piggy-backing on the module ("owner") information. There's no
change to the requirement that module name and msgtype name are
identical. The existing name macros are used.

We don't need any special code for dealing with the drivers being
built-in; the generic module support code already does the right
thing.

Test results:
1. CONFIG_MODULES=y, CONFIG_ZCRYPT=y

KVM: boots, no /sys/bus/ap (expected)
LPAR with CEX5: boots, /sys/bus/ap/devices/card*/type present

2. CONFIG_MODULES=y, CONFIG_ZCRYPT=m=:

KVM: boots, loading zcrypt_cex4 (and ap) fails (expected)
LPAR with CEX5: boots, loading =zcrypt_cex4= succeeds,
/sys/bus/ap/devices/card*/type present after explicit module
loading

3. CONFIG_MODULES unset, CONFIG_ZCRYPT=y:
KVM: boots, no /sys/bus/ap (expected)
LPAR with CEX5: boots, /sys/bus/ap/devices/card*/type present

No further testing (user-space functionality) was done.

Fixes: 3b6245fd303f ("s390/zcrypt: Separate msgtype implementation from card modules.")
Signed-off-by: Sascha Silbe <silbe@linux.vnet.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>

authored by

Sascha Silbe and committed by
Martin Schwidefsky
121a868d e387753c

+14 -8
+5 -2
drivers/s390/crypto/Makefile
··· 3 3 # 4 4 5 5 ap-objs := ap_bus.o 6 - obj-$(CONFIG_ZCRYPT) += ap.o zcrypt_api.o zcrypt_pcixcc.o 7 - obj-$(CONFIG_ZCRYPT) += zcrypt_cex2a.o zcrypt_cex4.o 6 + # zcrypt_api depends on ap 7 + obj-$(CONFIG_ZCRYPT) += ap.o zcrypt_api.o 8 + # msgtype* depend on zcrypt_api 8 9 obj-$(CONFIG_ZCRYPT) += zcrypt_msgtype6.o zcrypt_msgtype50.o 10 + # adapter drivers depend on ap, zcrypt_api and msgtype* 11 + obj-$(CONFIG_ZCRYPT) += zcrypt_pcixcc.o zcrypt_cex2a.o zcrypt_cex4.o
+4 -6
drivers/s390/crypto/zcrypt_api.c
··· 317 317 318 318 void zcrypt_msgtype_register(struct zcrypt_ops *zops) 319 319 { 320 - if (zops->owner) { 321 - spin_lock_bh(&zcrypt_ops_list_lock); 322 - list_add_tail(&zops->list, &zcrypt_ops_list); 323 - spin_unlock_bh(&zcrypt_ops_list_lock); 324 - } 320 + spin_lock_bh(&zcrypt_ops_list_lock); 321 + list_add_tail(&zops->list, &zcrypt_ops_list); 322 + spin_unlock_bh(&zcrypt_ops_list_lock); 325 323 } 326 324 EXPORT_SYMBOL(zcrypt_msgtype_register); 327 325 ··· 340 342 spin_lock_bh(&zcrypt_ops_list_lock); 341 343 list_for_each_entry(zops, &zcrypt_ops_list, list) { 342 344 if ((zops->variant == variant) && 343 - (!strncmp(zops->owner->name, name, MODULE_NAME_LEN))) { 345 + (!strncmp(zops->name, name, sizeof(zops->name)))) { 344 346 found = 1; 345 347 break; 346 348 }
+1
drivers/s390/crypto/zcrypt_api.h
··· 96 96 struct list_head list; /* zcrypt ops list. */ 97 97 struct module *owner; 98 98 int variant; 99 + char name[128]; 99 100 }; 100 101 101 102 struct zcrypt_device {
+1
drivers/s390/crypto/zcrypt_msgtype50.c
··· 513 513 .rsa_modexpo = zcrypt_cex2a_modexpo, 514 514 .rsa_modexpo_crt = zcrypt_cex2a_modexpo_crt, 515 515 .owner = THIS_MODULE, 516 + .name = MSGTYPE50_NAME, 516 517 .variant = MSGTYPE50_VARIANT_DEFAULT, 517 518 }; 518 519
+3
drivers/s390/crypto/zcrypt_msgtype6.c
··· 1119 1119 */ 1120 1120 static struct zcrypt_ops zcrypt_msgtype6_norng_ops = { 1121 1121 .owner = THIS_MODULE, 1122 + .name = MSGTYPE06_NAME, 1122 1123 .variant = MSGTYPE06_VARIANT_NORNG, 1123 1124 .rsa_modexpo = zcrypt_msgtype6_modexpo, 1124 1125 .rsa_modexpo_crt = zcrypt_msgtype6_modexpo_crt, ··· 1128 1127 1129 1128 static struct zcrypt_ops zcrypt_msgtype6_ops = { 1130 1129 .owner = THIS_MODULE, 1130 + .name = MSGTYPE06_NAME, 1131 1131 .variant = MSGTYPE06_VARIANT_DEFAULT, 1132 1132 .rsa_modexpo = zcrypt_msgtype6_modexpo, 1133 1133 .rsa_modexpo_crt = zcrypt_msgtype6_modexpo_crt, ··· 1138 1136 1139 1137 static struct zcrypt_ops zcrypt_msgtype6_ep11_ops = { 1140 1138 .owner = THIS_MODULE, 1139 + .name = MSGTYPE06_NAME, 1141 1140 .variant = MSGTYPE06_VARIANT_EP11, 1142 1141 .rsa_modexpo = NULL, 1143 1142 .rsa_modexpo_crt = NULL,