Skip to contentSkip to conversation

nvme-auth: use IS_REACHABLE for nvme_auth_extract_key() declaration

PATCH In review Chaitanya Kulkarni 4 participants 8 messages Nov 2, 2025 – Nov 3, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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.

Fixes e30cd923b3ed ("nvme-auth: switch to use 'struct key'")

---
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 .config
CONFIG_NVME_AUTH_STATE=y
CONFIG_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
index afc84a4cd94a..49a8afc16028 100644
@@ -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
#1 lore raw

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?

maintainer
#2 lore raw
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_STATE

Or IS_REACHABLE also works.

#3 lore raw
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_STATE

Or IS_REACHABLE also 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

maintainer
#4 lore raw
Quoted 2 lines · Chaitanya Kulkarni

unless there is a specific need to replace IS_REACHABLE() by CONFIG_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.

#5 lore raw
Quoted 5 lines · Keith Busch
Quoted 2 lines · Chaitanya Kulkarni

unless there is a specific need to replace IS_REACHABLE() by CONFIG_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

#7 lore raw
In reply to Christoph Hellwig
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 .config
CONFIG_NVME_AUTH_STATE=y
CONFIG_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