Commit 7d9b3ad4 authored by Andrii Nakryiko's avatar Andrii Nakryiko
Browse files

Merge branch 'Fixes for kfunc-mod regressions and warnings'

Kumar Kartikeya says:

====================

This set includes fixes for two regressions and one build warning introduced by
the kfunc for modules series.

Changelog:
----------

v1 -> v2:
v1: https://lore.kernel.org/bpf/20211115191840.496263-1-memxor@gmail.com



 * Instead of demoting resolve_btfids warning to debug, only skip in case of
   set->cnt == 0.
====================

Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
parents 099f83aa 3345193f
Loading
Loading
Loading
Loading
+10 −4
Original line number Original line Diff line number Diff line
@@ -245,7 +245,10 @@ struct kfunc_btf_id_set {
	struct module *owner;
	struct module *owner;
};
};


struct kfunc_btf_id_list;
struct kfunc_btf_id_list {
	struct list_head list;
	struct mutex mutex;
};


#ifdef CONFIG_DEBUG_INFO_BTF_MODULES
#ifdef CONFIG_DEBUG_INFO_BTF_MODULES
void register_kfunc_btf_id_set(struct kfunc_btf_id_list *l,
void register_kfunc_btf_id_set(struct kfunc_btf_id_list *l,
@@ -254,6 +257,9 @@ void unregister_kfunc_btf_id_set(struct kfunc_btf_id_list *l,
				 struct kfunc_btf_id_set *s);
				 struct kfunc_btf_id_set *s);
bool bpf_check_mod_kfunc_call(struct kfunc_btf_id_list *klist, u32 kfunc_id,
bool bpf_check_mod_kfunc_call(struct kfunc_btf_id_list *klist, u32 kfunc_id,
			      struct module *owner);
			      struct module *owner);

extern struct kfunc_btf_id_list bpf_tcp_ca_kfunc_list;
extern struct kfunc_btf_id_list prog_test_kfunc_list;
#else
#else
static inline void register_kfunc_btf_id_set(struct kfunc_btf_id_list *l,
static inline void register_kfunc_btf_id_set(struct kfunc_btf_id_list *l,
					     struct kfunc_btf_id_set *s)
					     struct kfunc_btf_id_set *s)
@@ -268,13 +274,13 @@ static inline bool bpf_check_mod_kfunc_call(struct kfunc_btf_id_list *klist,
{
{
	return false;
	return false;
}
}

static struct kfunc_btf_id_list bpf_tcp_ca_kfunc_list __maybe_unused;
static struct kfunc_btf_id_list prog_test_kfunc_list __maybe_unused;
#endif
#endif


#define DEFINE_KFUNC_BTF_ID_SET(set, name)                                     \
#define DEFINE_KFUNC_BTF_ID_SET(set, name)                                     \
	struct kfunc_btf_id_set name = { LIST_HEAD_INIT(name.list), (set),     \
	struct kfunc_btf_id_set name = { LIST_HEAD_INIT(name.list), (set),     \
					 THIS_MODULE }
					 THIS_MODULE }


extern struct kfunc_btf_id_list bpf_tcp_ca_kfunc_list;
extern struct kfunc_btf_id_list prog_test_kfunc_list;

#endif
#endif
+2 −9
Original line number Original line Diff line number Diff line
@@ -6346,11 +6346,6 @@ BTF_ID_LIST_GLOBAL_SINGLE(btf_task_struct_ids, struct, task_struct)


/* BTF ID set registration API for modules */
/* BTF ID set registration API for modules */


struct kfunc_btf_id_list {
	struct list_head list;
	struct mutex mutex;
};

#ifdef CONFIG_DEBUG_INFO_BTF_MODULES
#ifdef CONFIG_DEBUG_INFO_BTF_MODULES


void register_kfunc_btf_id_set(struct kfunc_btf_id_list *l,
void register_kfunc_btf_id_set(struct kfunc_btf_id_list *l,
@@ -6376,8 +6371,6 @@ bool bpf_check_mod_kfunc_call(struct kfunc_btf_id_list *klist, u32 kfunc_id,
{
{
	struct kfunc_btf_id_set *s;
	struct kfunc_btf_id_set *s;


	if (!owner)
		return false;
	mutex_lock(&klist->mutex);
	mutex_lock(&klist->mutex);
	list_for_each_entry(s, &klist->list, list) {
	list_for_each_entry(s, &klist->list, list) {
		if (s->owner == owner && btf_id_set_contains(s->set, kfunc_id)) {
		if (s->owner == owner && btf_id_set_contains(s->set, kfunc_id)) {
@@ -6389,8 +6382,6 @@ bool bpf_check_mod_kfunc_call(struct kfunc_btf_id_list *klist, u32 kfunc_id,
	return false;
	return false;
}
}


#endif

#define DEFINE_KFUNC_BTF_ID_LIST(name)                                         \
#define DEFINE_KFUNC_BTF_ID_LIST(name)                                         \
	struct kfunc_btf_id_list name = { LIST_HEAD_INIT(name.list),           \
	struct kfunc_btf_id_list name = { LIST_HEAD_INIT(name.list),           \
					  __MUTEX_INITIALIZER(name.mutex) };   \
					  __MUTEX_INITIALIZER(name.mutex) };   \
@@ -6398,3 +6389,5 @@ bool bpf_check_mod_kfunc_call(struct kfunc_btf_id_list *klist, u32 kfunc_id,


DEFINE_KFUNC_BTF_ID_LIST(bpf_tcp_ca_kfunc_list);
DEFINE_KFUNC_BTF_ID_LIST(bpf_tcp_ca_kfunc_list);
DEFINE_KFUNC_BTF_ID_LIST(prog_test_kfunc_list);
DEFINE_KFUNC_BTF_ID_LIST(prog_test_kfunc_list);

#endif
+1 −0
Original line number Original line Diff line number Diff line
@@ -316,6 +316,7 @@ config DEBUG_INFO_BTF
	bool "Generate BTF typeinfo"
	bool "Generate BTF typeinfo"
	depends on !DEBUG_INFO_SPLIT && !DEBUG_INFO_REDUCED
	depends on !DEBUG_INFO_SPLIT && !DEBUG_INFO_REDUCED
	depends on !GCC_PLUGIN_RANDSTRUCT || COMPILE_TEST
	depends on !GCC_PLUGIN_RANDSTRUCT || COMPILE_TEST
	depends on BPF_SYSCALL
	help
	help
	  Generate deduplicated BTF type information from DWARF debug info.
	  Generate deduplicated BTF type information from DWARF debug info.
	  Turning this on expects presence of pahole tool, which will convert
	  Turning this on expects presence of pahole tool, which will convert
+5 −3
Original line number Original line Diff line number Diff line
@@ -83,6 +83,7 @@ struct btf_id {
		int	 cnt;
		int	 cnt;
	};
	};
	int		 addr_cnt;
	int		 addr_cnt;
	bool		 is_set;
	Elf64_Addr	 addr[ADDR_CNT];
	Elf64_Addr	 addr[ADDR_CNT];
};
};


@@ -451,8 +452,10 @@ static int symbols_collect(struct object *obj)
			 * in symbol's size, together with 'cnt' field hence
			 * in symbol's size, together with 'cnt' field hence
			 * that - 1.
			 * that - 1.
			 */
			 */
			if (id)
			if (id) {
				id->cnt = sym.st_size / sizeof(int) - 1;
				id->cnt = sym.st_size / sizeof(int) - 1;
				id->is_set = true;
			}
		} else {
		} else {
			pr_err("FAILED unsupported prefix %s\n", prefix);
			pr_err("FAILED unsupported prefix %s\n", prefix);
			return -1;
			return -1;
@@ -568,9 +571,8 @@ static int id_patch(struct object *obj, struct btf_id *id)
	int *ptr = data->d_buf;
	int *ptr = data->d_buf;
	int i;
	int i;


	if (!id->id) {
	if (!id->id && !id->is_set)
		pr_err("WARN: resolve_btfids: unresolved symbol %s\n", id->name);
		pr_err("WARN: resolve_btfids: unresolved symbol %s\n", id->name);
	}


	for (i = 0; i < id->addr_cnt; i++) {
	for (i = 0; i < id->addr_cnt; i++) {
		unsigned long addr = id->addr[i];
		unsigned long addr = id->addr[i];