Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvme-auth: use IS_REACHABLE for nvme_auth_extract_key() declaration
@ 2025-11-02  3:17 Chaitanya Kulkarni
  2025-11-03 11:46 ` Christoph Hellwig
  0 siblings, 1 reply; 8+ messages in thread
From: Chaitanya Kulkarni @ 2025-11-02  3:17 UTC (permalink / raw)
  To: hare, kbusch; +Cc: hch, linux-nvme, Chaitanya Kulkarni

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 3231 bytes --]

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'")
Signed-off-by: Chaitanya Kulkarni <ckulkarnilinux@gmail.com>
---
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(-)

diff --git a/include/linux/nvme-auth.h b/include/linux/nvme-auth.h
index afc84a4cd94a..49a8afc16028 100644
--- a/include/linux/nvme-auth.h
+++ b/include/linux/nvme-auth.h
@@ -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
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] nvme-auth: use IS_REACHABLE for nvme_auth_extract_key() declaration
  2025-11-02  3:17 [PATCH] nvme-auth: use IS_REACHABLE for nvme_auth_extract_key() declaration Chaitanya Kulkarni
@ 2025-11-03 11:46 ` Christoph Hellwig
  2025-11-03 14:54   ` Keith Busch
  2025-11-03 19:43   ` Chaitanya Kulkarni
  0 siblings, 2 replies; 8+ messages in thread
From: Christoph Hellwig @ 2025-11-03 11:46 UTC (permalink / raw)
  To: Chaitanya Kulkarni; +Cc: hare, kbusch, hch, linux-nvme

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?



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] nvme-auth: use IS_REACHABLE for nvme_auth_extract_key() declaration
  2025-11-03 11:46 ` Christoph Hellwig
@ 2025-11-03 14:54   ` Keith Busch
  2025-11-03 19:46     ` Chaitanya Kulkarni
  2025-11-03 19:43   ` Chaitanya Kulkarni
  1 sibling, 1 reply; 8+ messages in thread
From: Keith Busch @ 2025-11-03 14:54 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Chaitanya Kulkarni, hare, linux-nvme

On Mon, Nov 03, 2025 at 12:46:21PM +0100, Christoph Hellwig wrote:
> 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.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] nvme-auth: use IS_REACHABLE for nvme_auth_extract_key() declaration
  2025-11-03 11:46 ` Christoph Hellwig
  2025-11-03 14:54   ` Keith Busch
@ 2025-11-03 19:43   ` Chaitanya Kulkarni
  1 sibling, 0 replies; 8+ messages in thread
From: Chaitanya Kulkarni @ 2025-11-03 19:43 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: hare@suse.de, kbusch@kernel.org, linux-nvme@lists.infradead.org,
	Chaitanya Kulkarni

On 11/3/25 3:46 AM, Christoph Hellwig wrote:
> 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



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] nvme-auth: use IS_REACHABLE for nvme_auth_extract_key() declaration
  2025-11-03 14:54   ` Keith Busch
@ 2025-11-03 19:46     ` Chaitanya Kulkarni
  2025-11-03 20:16       ` Keith Busch
  0 siblings, 1 reply; 8+ messages in thread
From: Chaitanya Kulkarni @ 2025-11-03 19:46 UTC (permalink / raw)
  To: Keith Busch, Christoph Hellwig
  Cc: Chaitanya Kulkarni, hare@suse.de, linux-nvme@lists.infradead.org

On 11/3/25 6:54 AM, Keith Busch wrote:
> On Mon, Nov 03, 2025 at 12:46:21PM +0100, Christoph Hellwig wrote:
>> 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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] nvme-auth: use IS_REACHABLE for nvme_auth_extract_key() declaration
  2025-11-03 19:46     ` Chaitanya Kulkarni
@ 2025-11-03 20:16       ` Keith Busch
  2025-11-03 20:28         ` Chaitanya Kulkarni
  0 siblings, 1 reply; 8+ messages in thread
From: Keith Busch @ 2025-11-03 20:16 UTC (permalink / raw)
  To: Chaitanya Kulkarni
  Cc: Christoph Hellwig, Chaitanya Kulkarni, hare@suse.de,
	linux-nvme@lists.infradead.org

On Mon, Nov 03, 2025 at 07:46:07PM +0000, Chaitanya Kulkarni wrote:
> 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.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] nvme-auth: use IS_REACHABLE for nvme_auth_extract_key() declaration
  2025-11-03 20:16       ` Keith Busch
@ 2025-11-03 20:28         ` Chaitanya Kulkarni
  2025-11-03 21:12           ` Keith Busch
  0 siblings, 1 reply; 8+ messages in thread
From: Chaitanya Kulkarni @ 2025-11-03 20:28 UTC (permalink / raw)
  To: Keith Busch
  Cc: Christoph Hellwig, Chaitanya Kulkarni, hare@suse.de,
	linux-nvme@lists.infradead.org

On 11/3/25 12:16, Keith Busch wrote:
> On Mon, Nov 03, 2025 at 07:46:07PM +0000, Chaitanya Kulkarni wrote:
>> 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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] nvme-auth: use IS_REACHABLE for nvme_auth_extract_key() declaration
  2025-11-03 20:28         ` Chaitanya Kulkarni
@ 2025-11-03 21:12           ` Keith Busch
  0 siblings, 0 replies; 8+ messages in thread
From: Keith Busch @ 2025-11-03 21:12 UTC (permalink / raw)
  To: Chaitanya Kulkarni
  Cc: Christoph Hellwig, Chaitanya Kulkarni, hare@suse.de,
	linux-nvme@lists.infradead.org

On Mon, Nov 03, 2025 at 08:28:35PM +0000, Chaitanya Kulkarni wrote:
> ohhh didn't know that when I sent this patch error was there ...

https://lore.kernel.org/oe-kbuild-all/202511012300.eAcEQQP5-lkp@intel.com/


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-11-03 21:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-02  3:17 [PATCH] nvme-auth: use IS_REACHABLE for nvme_auth_extract_key() declaration Chaitanya Kulkarni
2025-11-03 11:46 ` Christoph Hellwig
2025-11-03 14:54   ` Keith Busch
2025-11-03 19:46     ` Chaitanya Kulkarni
2025-11-03 20:16       ` Keith Busch
2025-11-03 20:28         ` Chaitanya Kulkarni
2025-11-03 21:12           ` Keith Busch
2025-11-03 19:43   ` Chaitanya Kulkarni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox