Skip to contentSkip to conversation

Fix undefined symbol references for module build post cnum changes

PATCH In review Alan Maguire 4 participants 6 messages Apr 27 – Apr 29 BPF

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix undefined symbol references for module build post cnum changes

Seeing the following on bpf-next:

DESCEND objtool
DESCEND bpf/resolve_btfids
INSTALL libsubcmd_headers
INSTALL libsubcmd_headers
MODPOST Module.symvers
ERROR: modpost: "cnum64_umin" [drivers/net/ethernet/netronome/nfp/nfp.ko] undefined!
ERROR: modpost: "cnum64_umax" [drivers/net/ethernet/netronome/nfp/nfp.ko] undefined! make[2]: *** [scripts/Makefile.modpost:147: Module.symvers] Error 1 make[1]: *** [bpf-next/Makefile:2089: modpost] Error 2
make: *** [Makefile:248: __sub-make] Error 2

Further investigation suggests nfp indeed does pull in those symbols, likely due to references in include/linux/bpf_verifier.h:

static inline s64 reg_smax(const struct bpf_reg_state *reg)

{
        return cnum64_smax(reg->r64);
}

static inline u64 reg_umin(const struct bpf_reg_state *reg)

{
        return cnum64_umin(reg->r64);
}

...

Export symbols for these references.

Fixes bbc631085503 ("bpf: replace min/max fields with struct cnum{32,64}")
---
 kernel/bpf/cnum_defs.h | 7 +++++++
 1 file changed, 7 insertions(+)
kernel/bpf/cnum_defs.h +7 -0
index 3ebd8f723dbb..7d992ee6a8a4 100644
@@ -6,6 +6,7 @@
 #endif
 
 #include <linux/cnum.h>
+#include <linux/kernel.h>
 #include <linux/limits.h>
 #include <linux/minmax.h>
 #include <linux/compiler_types.h>
@@ -23,6 +24,7 @@ struct cnum_t FN(from_urange)(ut min, ut max)
 {
 	return (struct cnum_t){ .base = min, .size = (ut)max - min };
 }
+EXPORT_SYMBOL_GPL(FN(from_urange));
 
 struct cnum_t FN(from_srange)(st min, st max)
 {
@@ -31,6 +33,7 @@ struct cnum_t FN(from_srange)(st min, st max)
 
 	return (struct cnum_t){ .base = base, .size = size };
 }
+EXPORT_SYMBOL_GPL(FN(from_srange));
 
 /* True if this cnum represents two unsigned ranges. */
 static inline bool FN(urange_overflow)(struct cnum_t cnum)
@@ -48,11 +51,13 @@ ut FN(umin)(struct cnum_t cnum)
 {
 	return FN(urange_overflow)(cnum) ? 0 : cnum.base;
 }
+EXPORT_SYMBOL_GPL(FN(umin));
 
 ut FN(umax)(struct cnum_t cnum)
 {
 	return FN(urange_overflow)(cnum) ? UT_MAX : cnum.base + cnum.size;
 }
+EXPORT_SYMBOL_GPL(FN(umax));
 
 /* True if this cnum represents two signed ranges. */
 static inline bool FN(srange_overflow)(struct cnum_t cnum)
@@ -71,6 +76,7 @@ st FN(smin)(struct cnum_t cnum)
 	       ? ST_MIN
 	       : min((st)cnum.base, (st)(cnum.base + cnum.size));
 }
+EXPORT_SYMBOL_GPL(FN(smin));
 
 st FN(smax)(struct cnum_t cnum)
 {
@@ -78,6 +84,7 @@ st FN(smax)(struct cnum_t cnum)
 	       ? ST_MAX
 	       : max((st)cnum.base, (st)(cnum.base + cnum.size));
 }
+EXPORT_SYMBOL_GPL(FN(smax));
 
 /*
  * Returns a possibly empty intersection of cnums 'a' and 'b'.
Signature · 1 line
2.39.3
#1 lore raw
Quoted 97 lines · Alan Maguire

Seeing the following on bpf-next:

DESCEND objtool
DESCEND bpf/resolve_btfids
INSTALL libsubcmd_headers
INSTALL libsubcmd_headers
MODPOST Module.symvers
ERROR: modpost: "cnum64_umin" [drivers/net/ethernet/netronome/nfp/nfp.ko] undefined!
ERROR: modpost: "cnum64_umax" [drivers/net/ethernet/netronome/nfp/nfp.ko] undefined! make[2]: *** [scripts/Makefile.modpost:147: Module.symvers] Error 1 make[1]: *** [bpf-next/Makefile:2089: modpost] Error 2
make: *** [Makefile:248: __sub-make] Error 2

Further investigation suggests nfp indeed does pull in those symbols, likely due to references in include/linux/bpf_verifier.h:

static inline s64 reg_smax(const struct bpf_reg_state *reg)

{
        return cnum64_smax(reg->r64);
}

static inline u64 reg_umin(const struct bpf_reg_state *reg)

{
        return cnum64_umin(reg->r64);
}

...

Export symbols for these references.

Fixes bbc631085503 ("bpf: replace min/max fields with struct cnum{32,64}")
---
 kernel/bpf/cnum_defs.h | 7 +++++++
 1 file changed, 7 insertions(+)
kernel/bpf/cnum_defs.h +7 -1
index 3ebd8f723dbb..7d992ee6a8a4 100644
@@ -6,6 +6,7 @@
 #endif
 
 #include <linux/cnum.h>
+#include <linux/kernel.h>
 #include <linux/limits.h>
 #include <linux/minmax.h>
 #include <linux/compiler_types.h>
@@ -23,6 +24,7 @@ struct cnum_t FN(from_urange)(ut min, ut max)
 {
        return (struct cnum_t){ .base = min, .size = (ut)max - min };
 }
+EXPORT_SYMBOL_GPL(FN(from_urange));
 
 struct cnum_t FN(from_srange)(st min, st max)
 {
@@ -31,6 +33,7 @@ struct cnum_t FN(from_srange)(st min, st max)
 
        return (struct cnum_t){ .base = base, .size = size };
 }
+EXPORT_SYMBOL_GPL(FN(from_srange));
 
 /* True if this cnum represents two unsigned ranges. */
 static inline bool FN(urange_overflow)(struct cnum_t cnum)
@@ -48,11 +51,13 @@ ut FN(umin)(struct cnum_t cnum)
 {
        return FN(urange_overflow)(cnum) ? 0 : cnum.base;
 }
+EXPORT_SYMBOL_GPL(FN(umin));
 
 ut FN(umax)(struct cnum_t cnum)
 {
        return FN(urange_overflow)(cnum) ? UT_MAX : cnum.base + cnum.size;
 }
+EXPORT_SYMBOL_GPL(FN(umax));
 
 /* True if this cnum represents two signed ranges. */
 static inline bool FN(srange_overflow)(struct cnum_t cnum)
@@ -71,6 +76,7 @@ st FN(smin)(struct cnum_t cnum)
               ? ST_MIN
               : min((st)cnum.base, (st)(cnum.base + cnum.size));
 }
+EXPORT_SYMBOL_GPL(FN(smin));
 
 st FN(smax)(struct cnum_t cnum)
 {
@@ -78,6 +84,7 @@ st FN(smax)(struct cnum_t cnum)
               ? ST_MAX
               : max((st)cnum.base, (st)(cnum.base + cnum.size));
 }
+EXPORT_SYMBOL_GPL(FN(smax));
 
 /*
  * Returns a possibly empty intersection of cnums 'a' and 'b'.
--
Quoted 2 lines

2.39.3

LGFM.

Signature · 2 lines
Yours,
Chengkaitao
maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Alan Maguire
Quoted 26 lines · Alan Maguire

Seeing the following on bpf-next:

DESCEND objtool
DESCEND bpf/resolve_btfids
INSTALL libsubcmd_headers
INSTALL libsubcmd_headers
MODPOST Module.symvers
ERROR: modpost: "cnum64_umin" [drivers/net/ethernet/netronome/nfp/nfp.ko] undefined!
ERROR: modpost: "cnum64_umax" [drivers/net/ethernet/netronome/nfp/nfp.ko] undefined! make[2]: *** [scripts/Makefile.modpost:147: Module.symvers] Error 1 make[1]: *** [bpf-next/Makefile:2089: modpost] Error 2
make: *** [Makefile:248: __sub-make] Error 2

Further investigation suggests nfp indeed does pull in those symbols, likely due to references in include/linux/bpf_verifier.h:

static inline s64 reg_smax(const struct bpf_reg_state *reg)

{
        return cnum64_smax(reg->r64);
}

static inline u64 reg_umin(const struct bpf_reg_state *reg)

{
        return cnum64_umin(reg->r64);
}
Quoted 8 lines

...

Export symbols for these references.

Fixes bbc631085503 ("bpf: replace min/max fields with struct cnum{32,64}")

---

Hi Alan,

thank you for the fix, apologies for breaking this.

[...]

maintainer
#3 lore raw
Quoted 36 lines · Eduard Zingerman
Quoted 26 lines · Alan Maguire

Seeing the following on bpf-next:

DESCEND objtool
DESCEND bpf/resolve_btfids
INSTALL libsubcmd_headers
INSTALL libsubcmd_headers
MODPOST Module.symvers
ERROR: modpost: "cnum64_umin" [drivers/net/ethernet/netronome/nfp/nfp.ko] undefined!
ERROR: modpost: "cnum64_umax" [drivers/net/ethernet/netronome/nfp/nfp.ko] undefined! make[2]: *** [scripts/Makefile.modpost:147: Module.symvers] Error 1 make[1]: *** [bpf-next/Makefile:2089: modpost] Error 2
make: *** [Makefile:248: __sub-make] Error 2

Further investigation suggests nfp indeed does pull in those symbols, likely due to references in include/linux/bpf_verifier.h:

static inline s64 reg_smax(const struct bpf_reg_state *reg)

{
        return cnum64_smax(reg->r64);
}

static inline u64 reg_umin(const struct bpf_reg_state *reg)

{
        return cnum64_umin(reg->r64);
}
Quoted 8 lines

...

Export symbols for these references.

Fixes bbc631085503 ("bpf: replace min/max fields with struct cnum{32,64}")

---

Quoted 5 lines

Hi Alan,

thank you for the fix, apologies for breaking this.

However, Alexei raises a valid question.
Netronome code uses the following accessors:
- cnum{32,64}_reg_umin
- cnum{32,64}_reg_umax

However, this patch also exports the following on top:
- cnum{32,64}_from_{urange,srange}
- cnum{32,64}_reg_smin
- cnum{32,64}_reg_smax

Why export extra accessors?

#4 lore raw
Quoted 49 lines · Eduard Zingerman
Quoted 36 lines · Eduard Zingerman
Quoted 26 lines · Alan Maguire

Seeing the following on bpf-next:

DESCEND objtool
DESCEND bpf/resolve_btfids
INSTALL libsubcmd_headers
INSTALL libsubcmd_headers
MODPOST Module.symvers
ERROR: modpost: "cnum64_umin" [drivers/net/ethernet/netronome/nfp/nfp.ko] undefined!
ERROR: modpost: "cnum64_umax" [drivers/net/ethernet/netronome/nfp/nfp.ko] undefined! make[2]: *** [scripts/Makefile.modpost:147: Module.symvers] Error 1 make[1]: *** [bpf-next/Makefile:2089: modpost] Error 2
make: *** [Makefile:248: __sub-make] Error 2

Further investigation suggests nfp indeed does pull in those symbols, likely due to references in include/linux/bpf_verifier.h:

static inline s64 reg_smax(const struct bpf_reg_state *reg)

{
        return cnum64_smax(reg->r64);
}

static inline u64 reg_umin(const struct bpf_reg_state *reg)

{
        return cnum64_umin(reg->r64);
}
Quoted 8 lines

...

Export symbols for these references.

Fixes bbc631085503 ("bpf: replace min/max fields with struct cnum{32,64}")

---

Quoted 5 lines

Hi Alan,

thank you for the fix, apologies for breaking this.

However, Alexei raises a valid question.
Netronome code uses the following accessors:
- cnum{32,64}_reg_umin
- cnum{32,64}_reg_umax

Quoted 6 lines

However, this patch also exports the following on top:
- cnum{32,64}_from_{urange,srange}
- cnum{32,64}_reg_smin
- cnum{32,64}_reg_smax

Why export extra accessors?

I left only 2 while applying and rewrote commit log.

#5 lore raw
Quoted 50 lines · Alexei Starovoitov
Quoted 49 lines · Eduard Zingerman
Quoted 36 lines · Eduard Zingerman
Quoted 26 lines · Alan Maguire

Seeing the following on bpf-next:

DESCEND objtool
DESCEND bpf/resolve_btfids
INSTALL libsubcmd_headers
INSTALL libsubcmd_headers
MODPOST Module.symvers
ERROR: modpost: "cnum64_umin" [drivers/net/ethernet/netronome/nfp/nfp.ko] undefined!
ERROR: modpost: "cnum64_umax" [drivers/net/ethernet/netronome/nfp/nfp.ko] undefined! make[2]: *** [scripts/Makefile.modpost:147: Module.symvers] Error 1 make[1]: *** [bpf-next/Makefile:2089: modpost] Error 2
make: *** [Makefile:248: __sub-make] Error 2

Further investigation suggests nfp indeed does pull in those symbols, likely due to references in include/linux/bpf_verifier.h:

static inline s64 reg_smax(const struct bpf_reg_state *reg)

{
        return cnum64_smax(reg->r64);
}

static inline u64 reg_umin(const struct bpf_reg_state *reg)

{
        return cnum64_umin(reg->r64);
}
Quoted 8 lines

...

Export symbols for these references.

Fixes bbc631085503 ("bpf: replace min/max fields with struct cnum{32,64}")

---

Quoted 5 lines

Hi Alan,

thank you for the fix, apologies for breaking this.

However, Alexei raises a valid question.
Netronome code uses the following accessors:
- cnum{32,64}_reg_umin
- cnum{32,64}_reg_umax

Quoted 8 lines
Quoted 6 lines

However, this patch also exports the following on top:
- cnum{32,64}_from_{urange,srange}
- cnum{32,64}_reg_smin
- cnum{32,64}_reg_smax

Why export extra accessors?

I left only 2 while applying and rewrote commit log.

Yep, I just added the accessors as they are potentially available to consumers via bpf_verifier.h. No actual users today though as far as I could see. Thanks!