nvme-auth: use IS_REACHABLE for nvme_auth_extract_key() declaration
Subsystems (2)
PATCH 1/1 nvme-auth: use IS_REACHABLE for nvme_auth_extract_key() declaration
Fix build error when CONFIG_NVME_AUTH=m (module):
drivers/nvme/common/auth.c:158:13: error: redefinition of 'nvme_auth_extract_key' include/linux/nvme-auth.h:25:27: note: previous definition is here
The issue occurs because when NVME_AUTH is built as a module (=m), the preprocessor symbol CONFIG_NVME_AUTH is not defined during compilation, but the object file auth.o is still compiled as part of nvme-auth.ko.
With #ifdef CONFIG_NVME_AUTH, the header provides a static inline stub when the config is =m, while auth.c provides the real implementation, causing a redefinition conflict.
Use IS_REACHABLE(CONFIG_NVME_AUTH) instead of #ifdef CONFIG_NVME_AUTH to properly handle both built-in (=y) and modular (=m) builds. IS_REACHABLE evaluates to true when the code is reachable, either because it's built-in or because we're building the same module.
---
Hi,
Please review this very carefully :-
Broken scenario with #ifdef CONFIG_NVME_AUTH:
make menuconfig --> NVMe over Fabrics In-Band Authentication --> *
nvme (nvme-6.19) # grep NVME_AUTH .configCONFIG_NVME_AUTH_STATE=yCONFIG_NVME_AUTH=m
nvme (nvme-6.19) #
1: Makefile compiles auth.c
obj-$(CONFIG_NVME_AUTH) += nvme-auth.o nvme-auth-y += auth.o
auth.c gets compiled as part of nvme-auth.ko module make[1]: Entering directory '/mnt/data/nvme/drivers/nvme'
CC [M] common/auth.o
CC [M] host/core.o
CC [M] host/sysfs.o
CC [M] target/configfs.o
CC [M] host/auth.o
CC [M] host/fabrics.o
CC [M] target/fabrics-cmd-auth.o
CC [M] target/auth.o
common/auth.c:158:13: error: redefinition of ‘nvme_auth_extract_key’
158 | struct key *nvme_auth_extract_key(struct key *keyring, const u8 *secret,
| ^~~~~~~~~~~~~~~~~~~~~2: Preprocessor evaluates header guards in nvme-auth.h
#ifdef CONFIG_NVME_AUTH <---- CONFIG_NVME_AUTH is NOT defined when =m
Only CONFIG_NVME_AUTH_MODULE is defined!
struct key *nvme_auth_extract_key(...); <--- Declaration (NOT reached)
#else
static inline struct key *nvme_auth_extract_key(...) { <---- This is used Static inline stub
return ERR_PTR(-ENOKEY);
}
#endif
3: Compiler sees BOTH definitions when NVME_AUTH is enabled
using make menuconfig NVMe over Fabrics In-Band Authentication = *
- auth.c:158 has the real implementation: struct key *nvme_auth_extract_key(...)
- Header provides static inline stub: static inline struct key *nvme_auth_extract_key(...)
--- include/linux/nvme-auth.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/nvme-auth.h +1 -1
@@ -18,7 +18,7 @@ const char *nvme_auth_digest_name(u8 hmac_id);size_t nvme_auth_hmac_hash_len (u8 hmac_id);u8 nvme_auth_hmac_id (const char *hmac_name); -#ifdef CONFIG_NVME_AUTH +#if IS_REACHABLE (CONFIG_NVME_AUTH )struct key *nvme_auth_extract_key (struct key *keyring,const u8 *secret,size_t secret_len,bool *generated);#else
Signature · 1 line
2.40.0
Christoph Hellwig
maintainerSo with Keith' latest fixes the auth code should always be built in if either the host or target code is built in. Did this not work, or is this for an older branch?
Keith Busch
maintainerQuoted 3 lines · Christoph Hellwig
So with Keith' latest fixes the auth code should always be built in if either the host or target code is built in. Did this not work, or is this for an older branch?
It should be fine if either or both are built in. The problem is if both are modules. For that config, this should have used:
#ifdef CONFIG_NVME_AUTH_STATE
Or IS_REACHABLE also works.
Quoted 11 lines · Keith Busch
Quoted 3 lines · Christoph Hellwig
So with Keith' latest fixes the auth code should always be built in if either the host or target code is built in. Did this not work, or is this for an older branch?
It should be fine if either or both are built in. The problem is if both are modules. For that config, this should have used:
#ifdef
CONFIG_NVME_AUTH_STATEOr
IS_REACHABLEalso works.
unless there is a specific need to replace IS_REACHABLE() by CONFIG_NVME_AUTH_STATE, can I please get Reviewed-by on this patch ?
-ck
Keith Busch
maintainerQuoted 2 lines · Chaitanya Kulkarni
unless there is a specific need to replace
IS_REACHABLE()byCONFIG_NVME_AUTH_STATE, can I please get Reviewed-by on this patch ?
I just folded it in when the build bot reported the error. This one was pretty trivial and top of the stack already.
Quoted 5 lines · Keith Busch
Quoted 2 lines · Chaitanya Kulkarni
unless there is a specific need to replace
IS_REACHABLE()byCONFIG_NVME_AUTH_STATE, can I please get Reviewed-by on this patch ?I just folded it in when the build bot reported the error. This one was pretty trivial and top of the stack already.
ohhh didn't know that when I sent this patch error was there ...
-ck
Keith Busch
maintainerQuoted 1 line · Chaitanya Kulkarni
ohhh didn't know that when I sent this patch error was there ...
Quoted 5 lines · Christoph Hellwig
So with Keith' latest fixes the auth code should always be built in if either the host or target code is built in. Did this not work, or is this for an older branch?
it errors out with following since NVMe over Fabrics In-Band Authentication is built-in only on my machine :-
make menuconfig --> NVMe over Fabrics In-Band Authentication --> * (* only option no <M>)
nvme (nvme-6.19) # grep NVME_AUTH .configCONFIG_NVME_AUTH_STATE=yCONFIG_NVME_AUTH=m
nvme (nvme-6.19) #
Makefile compiles auth.c
obj-$(CONFIG_NVME_AUTH) += nvme-auth.o nvme-auth-y += auth.o
auth.c gets compiled as part of nvme-auth.ko module make[1]: Entering directory '/mnt/data/nvme/drivers/nvme'
CC [M] common/auth.o
CC [M] host/core.o
CC [M] host/sysfs.o
CC [M] target/configfs.o
CC [M] host/auth.o
CC [M] host/fabrics.o
CC [M] target/fabrics-cmd-auth.o
CC [M] target/auth.o
common/auth.c:158:13: error: redefinition of ‘nvme_auth_extract_key’
158 | struct key *nvme_auth_extract_key(struct key *keyring, const u8 *secret,
| ^~~~~~~~~~~~~~~~~~~~~-ck