Skip to contentSkip to conversation

bpf: Small nf_conn cleanups

PATCH Superseded Daniel Xu 2 participants 6 messages Sep 19, 2022 – Sep 20, 2022

Subsystems (6)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Daniel Xu

author
#0 lore raw

v2 cover bpf: Small nf_conn cleanups

This patchset cleans up a few small things:

* Delete unused stub
* Rename variable to be more descriptive
* Fix some extern declaration warnings

Daniel Xu (3):
bpf: Remove unused btf_struct_access stub
bpf: Rename nfct_bsa to nfct_btf_struct_access
bpf: Move nf_conn extern declarations to filter.h

 include/linux/filter.h                   |  6 ++++++
 include/net/netfilter/nf_conntrack_bpf.h | 17 +----------------
 net/core/filter.c                        | 18 +++++++++---------
 net/netfilter/nf_conntrack_bpf.c         |  4 ++--
 4 files changed, 18 insertions(+), 27 deletions(-)
Signature · 1 line
2.37.1
author
#1 lore raw

PATCH v2 1/3 bpf: Remove unused btf_struct_access stub

This stub was not being used anywhere.

---
 include/net/netfilter/nf_conntrack_bpf.h | 10 ----------
 1 file changed, 10 deletions(-)
include/net/netfilter/nf_conntrack_bpf.h +0 -10
index a61a93d1c6dc..73f2b78232e5 100644
@@ -31,16 +31,6 @@ static inline void cleanup_nf_conntrack_bpf(void)
 {
 }
 
-static inline int nf_conntrack_btf_struct_access(struct bpf_verifier_log *log,
-						 const struct btf *btf,
-						 const struct btf_type *t, int off,
-						 int size, enum bpf_access_type atype,
-						 u32 *next_btf_id,
-						 enum bpf_type_flag *flag)
-{
-	return -EACCES;
-}
-
 #endif
 
 #endif /* _NF_CONNTRACK_BPF_H */
Signature · 1 line
2.37.1
author
#2 lore raw

PATCH v2 2/3 bpf: Rename nfct_bsa to nfct_btf_struct_access

In reply to Daniel Xu

The former name was a little hard to guess.

---
 include/net/netfilter/nf_conntrack_bpf.h |  8 ++++----
 net/core/filter.c                        | 18 +++++++++---------
 net/netfilter/nf_conntrack_bpf.c         |  4 ++--
 3 files changed, 15 insertions(+), 15 deletions(-)
include/net/netfilter/nf_conntrack_bpf.h +4 -4
index 73f2b78232e5..d1087e4da440 100644
@@ -15,10 +15,10 @@ extern int register_nf_conntrack_bpf(void);
 extern void cleanup_nf_conntrack_bpf(void);
 
 extern struct mutex nf_conn_btf_access_lock;
-extern int (*nfct_bsa)(struct bpf_verifier_log *log, const struct btf *btf,
-		       const struct btf_type *t, int off, int size,
-		       enum bpf_access_type atype, u32 *next_btf_id,
-		       enum bpf_type_flag *flag);
+extern int (*nfct_btf_struct_access)(struct bpf_verifier_log *log, const struct btf *btf,
+				     const struct btf_type *t, int off, int size,
+				     enum bpf_access_type atype, u32 *next_btf_id,
+				     enum bpf_type_flag *flag);
 
 #else
 
net/core/filter.c +9 -9
index 4b2be211bcbe..2fd9449026aa 100644
@@ -8608,11 +8608,11 @@ static bool tc_cls_act_is_valid_access(int off, int size,
 DEFINE_MUTEX(nf_conn_btf_access_lock);
 EXPORT_SYMBOL_GPL(nf_conn_btf_access_lock);
 
-int (*nfct_bsa)(struct bpf_verifier_log *log, const struct btf *btf,
-		const struct btf_type *t, int off, int size,
-		enum bpf_access_type atype, u32 *next_btf_id,
-		enum bpf_type_flag *flag);
-EXPORT_SYMBOL_GPL(nfct_bsa);
+int (*nfct_btf_struct_access)(struct bpf_verifier_log *log, const struct btf *btf,
+			      const struct btf_type *t, int off, int size,
+			      enum bpf_access_type atype, u32 *next_btf_id,
+			      enum bpf_type_flag *flag);
+EXPORT_SYMBOL_GPL(nfct_btf_struct_access);
 
 static int tc_cls_act_btf_struct_access(struct bpf_verifier_log *log,
 					const struct btf *btf,
@@ -8628,8 +8628,8 @@ static int tc_cls_act_btf_struct_access(struct bpf_verifier_log *log,
 					 flag);
 
 	mutex_lock(&nf_conn_btf_access_lock);
-	if (nfct_bsa)
-		ret = nfct_bsa(log, btf, t, off, size, atype, next_btf_id, flag);
+	if (nfct_btf_struct_access)
+		ret = nfct_btf_struct_access(log, btf, t, off, size, atype, next_btf_id, flag);
 	mutex_unlock(&nf_conn_btf_access_lock);
 
 	return ret;
@@ -8708,8 +8708,8 @@ static int xdp_btf_struct_access(struct bpf_verifier_log *log,
 					 flag);
 
 	mutex_lock(&nf_conn_btf_access_lock);
-	if (nfct_bsa)
-		ret = nfct_bsa(log, btf, t, off, size, atype, next_btf_id, flag);
+	if (nfct_btf_struct_access)
+		ret = nfct_btf_struct_access(log, btf, t, off, size, atype, next_btf_id, flag);
 	mutex_unlock(&nf_conn_btf_access_lock);
 
 	return ret;
net/netfilter/nf_conntrack_bpf.c +2 -2
index 77eb8e959f61..29c4efb3da5e 100644
@@ -502,7 +502,7 @@ int register_nf_conntrack_bpf(void)
 	ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_SCHED_CLS, &nf_conntrack_kfunc_set);
 	if (!ret) {
 		mutex_lock(&nf_conn_btf_access_lock);
-		nfct_bsa = _nf_conntrack_btf_struct_access;
+		nfct_btf_struct_access = _nf_conntrack_btf_struct_access;
 		mutex_unlock(&nf_conn_btf_access_lock);
 	}
 
@@ -512,6 +512,6 @@ int register_nf_conntrack_bpf(void)
 void cleanup_nf_conntrack_bpf(void)
 {
 	mutex_lock(&nf_conn_btf_access_lock);
-	nfct_bsa = NULL;
+	nfct_btf_struct_access = NULL;
 	mutex_unlock(&nf_conn_btf_access_lock);
 }
Signature · 1 line
2.37.1
author
#3 lore raw

PATCH v2 3/3 bpf: Move nf_conn extern declarations to filter.h

In reply to Daniel Xu

We're seeing the following new warnings on netdev/build_32bit and netdev/build_allmodconfig_warn CI jobs:

../net/core/filter.c:8608:1: warning: symbol 'nf_conn_btf_access_lock' was not declared. Should it be static? ../net/core/filter.c:8611:5: warning: symbol 'nfct_bsa' was not declared. Should it be static?

Fix by ensuring extern declaration is present while compiling filter.o.

Fixes 864b656f82cc ("bpf: Add support for writing to nf_conn:mark")
---
 include/linux/filter.h                   | 6 ++++++
 include/net/netfilter/nf_conntrack_bpf.h | 7 +------
 2 files changed, 7 insertions(+), 6 deletions(-)
include/linux/filter.h +6 -0
index 75335432fcbc..98e28126c24b 100644
@@ -567,6 +567,12 @@ struct sk_filter {
 
 DECLARE_STATIC_KEY_FALSE(bpf_stats_enabled_key);
 
+extern struct mutex nf_conn_btf_access_lock;
+extern int (*nfct_btf_struct_access)(struct bpf_verifier_log *log, const struct btf *btf,
+				     const struct btf_type *t, int off, int size,
+				     enum bpf_access_type atype, u32 *next_btf_id,
+				     enum bpf_type_flag *flag);
+
 typedef unsigned int (*bpf_dispatcher_fn)(const void *ctx,
 					  const struct bpf_insn *insnsi,
 					  unsigned int (*bpf_func)(const void *,
include/net/netfilter/nf_conntrack_bpf.h +1 -6
index d1087e4da440..24d1ccc1f8df 100644
@@ -5,6 +5,7 @@
 
 #include <linux/bpf.h>
 #include <linux/btf.h>
+#include <linux/filter.h>
 #include <linux/kconfig.h>
 #include <linux/mutex.h>
 
@@ -14,12 +15,6 @@
 extern int register_nf_conntrack_bpf(void);
 extern void cleanup_nf_conntrack_bpf(void);
 
-extern struct mutex nf_conn_btf_access_lock;
-extern int (*nfct_btf_struct_access)(struct bpf_verifier_log *log, const struct btf *btf,
-				     const struct btf_type *t, int off, int size,
-				     enum bpf_access_type atype, u32 *next_btf_id,
-				     enum bpf_type_flag *flag);
-
 #else
 
 static inline int register_nf_conntrack_bpf(void)
Signature · 1 line
2.37.1
#4 lore raw

Re: [PATCH bpf-next v2 3/3] bpf: Move nf_conn extern declarations to filter.h

Quoted 39 lines · Daniel Xu

We're seeing the following new warnings on netdev/build_32bit and netdev/build_allmodconfig_warn CI jobs:

../net/core/filter.c:8608:1: warning: symbol 'nf_conn_btf_access_lock' was not declared. Should it be static? ../net/core/filter.c:8611:5: warning: symbol 'nfct_bsa' was not declared. Should it be static?

Fix by ensuring extern declaration is present while compiling filter.o.

Fixes 864b656f82cc ("bpf: Add support for writing to nf_conn:mark")
---
  include/linux/filter.h                   | 6 ++++++
  include/net/netfilter/nf_conntrack_bpf.h | 7 +------
  2 files changed, 7 insertions(+), 6 deletions(-)
include/linux/filter.h +6 -0
index 75335432fcbc..98e28126c24b 100644
@@ -567,6 +567,12 @@ struct sk_filter {
 
  DECLARE_STATIC_KEY_FALSE(bpf_stats_enabled_key);
 
+extern struct mutex nf_conn_btf_access_lock;
+extern int (*nfct_btf_struct_access)(struct bpf_verifier_log *log, const struct btf *btf,
+				     const struct btf_type *t, int off, int size,
+				     enum bpf_access_type atype, u32 *next_btf_id,
+				     enum bpf_type_flag *flag);
+
  typedef unsigned int (*bpf_dispatcher_fn)(const void *ctx,
  					  const struct bpf_insn *insnsi,
  					  unsigned int (*bpf_func)(const void *,
include/net/netfilter/nf_conntrack_bpf.h +0 -0
index d1087e4da440..24d1ccc1f8df 100644

include/net/netfilter/nf_conntrack_bpf.h line 8

Quoted 4 lines
include/net/netfilter/nf_conntrack_bpf.h +1 -0
@@ -5,6 +5,7 @@
 
  #include <linux/bpf.h>
  #include <linux/btf.h>
+#include <linux/filter.h>

The filter.h is only needed by nf_conntrack_bpf.c? How about moving this include to nf_conntrack_bpf.c. nf_conntrack_bpf.h is included by other conntrack core codes. I would prefer not to spill over unnecessary bpf headers to them. The same goes for the above bpf.h and btf.h which are only needed in nf_conntrack_bpf.c also?

include/net/netfilter/nf_conntrack_bpf.h line 10

Quoted 2 lines
include/net/netfilter/nf_conntrack_bpf.h +0 -0
  #include <linux/kconfig.h>
  #include <linux/mutex.h>

Also, is mutex.h still needed?

Quoted 14 lines
include/net/netfilter/nf_conntrack_bpf.h +0 -6
@@ -14,12 +15,6 @@
  extern int register_nf_conntrack_bpf(void);
  extern void cleanup_nf_conntrack_bpf(void);
 
-extern struct mutex nf_conn_btf_access_lock;
-extern int (*nfct_btf_struct_access)(struct bpf_verifier_log *log, const struct btf *btf,
-				     const struct btf_type *t, int off, int size,
-				     enum bpf_access_type atype, u32 *next_btf_id,
-				     enum bpf_type_flag *flag);
-
  #else
 
  static inline int register_nf_conntrack_bpf(void)
author
#5 lore raw

Re: [PATCH bpf-next v2 3/3] bpf: Move nf_conn extern declarations to filter.h

Quoted 39 lines · Martin KaFai Lau
Quoted 38 lines · Daniel Xu

We're seeing the following new warnings on netdev/build_32bit and netdev/build_allmodconfig_warn CI jobs:

../net/core/filter.c:8608:1: warning: symbol 'nf_conn_btf_access_lock' was not declared. Should it be static? ../net/core/filter.c:8611:5: warning: symbol 'nfct_bsa' was not declared. Should it be static?

Fix by ensuring extern declaration is present while compiling filter.o.

Fixes 864b656f82cc ("bpf: Add support for writing to nf_conn:mark")
---
  include/linux/filter.h                   | 6 ++++++
  include/net/netfilter/nf_conntrack_bpf.h | 7 +------
  2 files changed, 7 insertions(+), 6 deletions(-)
include/linux/filter.h +6 -0
index 75335432fcbc..98e28126c24b 100644
@@ -567,6 +567,12 @@ struct sk_filter {
  DECLARE_STATIC_KEY_FALSE(bpf_stats_enabled_key);
+extern struct mutex nf_conn_btf_access_lock;
+extern int (*nfct_btf_struct_access)(struct bpf_verifier_log *log, const struct btf *btf,
+				     const struct btf_type *t, int off, int size,
+				     enum bpf_access_type atype, u32 *next_btf_id,
+				     enum bpf_type_flag *flag);
+
  typedef unsigned int (*bpf_dispatcher_fn)(const void *ctx,
  					  const struct bpf_insn *insnsi,
  					  unsigned int (*bpf_func)(const void *,
include/net/netfilter/nf_conntrack_bpf.h +0 -0
index d1087e4da440..24d1ccc1f8df 100644
@@ -5,6 +5,7 @@
  #include <linux/bpf.h>
Quoted 8 lines

include/net/netfilter/nf_conntrack_bpf.h line 8

Quoted 2 lines
include/net/netfilter/nf_conntrack_bpf.h +1 -0
  #include <linux/btf.h>
+#include <linux/filter.h>

The filter.h is only needed by nf_conntrack_bpf.c? How about moving this include to nf_conntrack_bpf.c. nf_conntrack_bpf.h is included by other conntrack core codes. I would prefer not to spill over unnecessary bpf headers to them. The same goes for the above bpf.h and btf.h which are only needed in nf_conntrack_bpf.c also?

Ah yeah. Thanks for catching. Will send out a v3.

Now I'm wondering if https://include-what-you-use.org/ would work with kernel source. Might give it a try later.

Quoted 5 lines

include/net/netfilter/nf_conntrack_bpf.h line 10

Quoted 3 lines
include/net/netfilter/nf_conntrack_bpf.h +0 -0
  #include <linux/kconfig.h>
  #include <linux/mutex.h>

Also, is mutex.h still needed?

Nope. But forgot to send that out in v3. I'll roll it into v4 if we need another respin or otherwise I'll send out a separate patch after.

Quoted 13 lines
Quoted 12 lines
include/net/netfilter/nf_conntrack_bpf.h +0 -6
@@ -14,12 +15,6 @@
  extern int register_nf_conntrack_bpf(void);
  extern void cleanup_nf_conntrack_bpf(void);
-extern struct mutex nf_conn_btf_access_lock;
-extern int (*nfct_btf_struct_access)(struct bpf_verifier_log *log, const struct btf *btf,
-				     const struct btf_type *t, int off, int size,
-				     enum bpf_access_type atype, u32 *next_btf_id,
-				     enum bpf_type_flag *flag);
-
  #else
  static inline int register_nf_conntrack_bpf(void)