All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/2] add btf_dedup() support for VAR and DATASEC
@ 2019-04-15 23:48 andrii.nakryiko
  2019-04-15 23:48 ` [PATCH bpf-next 1/2] btf: add support for VAR and DATASEC in btf_dedup() andrii.nakryiko
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: andrii.nakryiko @ 2019-04-15 23:48 UTC (permalink / raw)
  To: andrii.nakryiko, netdev, bpf, kernel-team; +Cc: Andrii Nakryiko

From: Andrii Nakryiko <andriin@fb.com>

This patchset adds support for new BTF_KIND_VAR and BTF_KIND_DATASEC BTF types
in btf_dedup() algorithm. VAR and DATASEC are not deduplicated and are always
considered to be unique, but they require referenced type IDs adjustment.

Patch #1 adds VAR/DATASEC pass-through support to btf_dedup().
Patch #2 adds a test validating all the type ID adjustments are correct.

Andrii Nakryiko (2):
  btf: add support for VAR and DATASEC in btf_dedup()
  selftests/btf: add VAR and DATASEC case for dedup tests

 tools/lib/bpf/btf.c                    | 29 +++++++++++++--
 tools/testing/selftests/bpf/test_btf.c | 49 ++++++++++++++++++++++++++
 2 files changed, 76 insertions(+), 2 deletions(-)

-- 
2.17.1


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

* [PATCH bpf-next 1/2] btf: add support for VAR and DATASEC in btf_dedup()
  2019-04-15 23:48 [PATCH bpf-next 0/2] add btf_dedup() support for VAR and DATASEC andrii.nakryiko
@ 2019-04-15 23:48 ` andrii.nakryiko
  2019-04-15 23:48 ` [PATCH bpf-next 2/2] selftests/btf: add VAR and DATASEC case for dedup tests andrii.nakryiko
  2019-04-16  8:26 ` [PATCH bpf-next 0/2] add btf_dedup() support for VAR and DATASEC Daniel Borkmann
  2 siblings, 0 replies; 4+ messages in thread
From: andrii.nakryiko @ 2019-04-15 23:48 UTC (permalink / raw)
  To: andrii.nakryiko, netdev, bpf, kernel-team
  Cc: Andrii Nakryiko, Daniel Borkmann, Yonghong Song, Alexei Starovoitov

From: Andrii Nakryiko <andriin@fb.com>

This patch adds support for VAR and DATASEC in btf_dedup(). VAR/DATASEC
are never deduplicated, but they need to be processed anyway as types
they refer to might need to be remapped due to deduplication and
compaction.

Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Yonghong Song <yhs@fb.com>
Cc: Alexei Starovoitov <ast@fb.com>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
 tools/lib/bpf/btf.c | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 701e7e28ada3..75eaf10b9e1a 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -1354,8 +1354,16 @@ static struct btf_dedup *btf_dedup_new(struct btf *btf, struct btf_ext *btf_ext,
 	}
 	/* special BTF "void" type is made canonical immediately */
 	d->map[0] = 0;
-	for (i = 1; i <= btf->nr_types; i++)
-		d->map[i] = BTF_UNPROCESSED_ID;
+	for (i = 1; i <= btf->nr_types; i++) {
+		struct btf_type *t = d->btf->types[i];
+		__u16 kind = BTF_INFO_KIND(t->info);
+
+		/* VAR and DATASEC are never deduped and are self-canonical */
+		if (kind == BTF_KIND_VAR || kind == BTF_KIND_DATASEC)
+			d->map[i] = i;
+		else
+			d->map[i] = BTF_UNPROCESSED_ID;
+	}
 
 	d->hypot_map = malloc(sizeof(__u32) * (1 + btf->nr_types));
 	if (!d->hypot_map) {
@@ -1946,6 +1954,8 @@ static int btf_dedup_prim_type(struct btf_dedup *d, __u32 type_id)
 	case BTF_KIND_UNION:
 	case BTF_KIND_FUNC:
 	case BTF_KIND_FUNC_PROTO:
+	case BTF_KIND_VAR:
+	case BTF_KIND_DATASEC:
 		return 0;
 
 	case BTF_KIND_INT:
@@ -2699,6 +2709,7 @@ static int btf_dedup_remap_type(struct btf_dedup *d, __u32 type_id)
 	case BTF_KIND_PTR:
 	case BTF_KIND_TYPEDEF:
 	case BTF_KIND_FUNC:
+	case BTF_KIND_VAR:
 		r = btf_dedup_remap_type_id(d, t->type);
 		if (r < 0)
 			return r;
@@ -2753,6 +2764,20 @@ static int btf_dedup_remap_type(struct btf_dedup *d, __u32 type_id)
 		break;
 	}
 
+	case BTF_KIND_DATASEC: {
+		struct btf_var_secinfo *var = (struct btf_var_secinfo *)(t + 1);
+		__u16 vlen = BTF_INFO_VLEN(t->info);
+
+		for (i = 0; i < vlen; i++) {
+			r = btf_dedup_remap_type_id(d, var->type);
+			if (r < 0)
+				return r;
+			var->type = r;
+			var++;
+		}
+		break;
+	}
+
 	default:
 		return -EINVAL;
 	}
-- 
2.17.1


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

* [PATCH bpf-next 2/2] selftests/btf: add VAR and DATASEC case for dedup tests
  2019-04-15 23:48 [PATCH bpf-next 0/2] add btf_dedup() support for VAR and DATASEC andrii.nakryiko
  2019-04-15 23:48 ` [PATCH bpf-next 1/2] btf: add support for VAR and DATASEC in btf_dedup() andrii.nakryiko
@ 2019-04-15 23:48 ` andrii.nakryiko
  2019-04-16  8:26 ` [PATCH bpf-next 0/2] add btf_dedup() support for VAR and DATASEC Daniel Borkmann
  2 siblings, 0 replies; 4+ messages in thread
From: andrii.nakryiko @ 2019-04-15 23:48 UTC (permalink / raw)
  To: andrii.nakryiko, netdev, bpf, kernel-team
  Cc: Andrii Nakryiko, Daniel Borkmann, Yonghong Song, Alexei Starovoitov

From: Andrii Nakryiko <andriin@fb.com>

Add test case verifying that dedup happens (INTs are deduped in this
case) and VAR/DATASEC types are not deduped, but have their referenced
type IDs adjusted correctly.

Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Yonghong Song <yhs@fb.com>
Cc: Alexei Starovoitov <ast@fb.com>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
 tools/testing/selftests/bpf/test_btf.c | 49 ++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/tools/testing/selftests/bpf/test_btf.c b/tools/testing/selftests/bpf/test_btf.c
index 44cd3378d216..f8eb7987b794 100644
--- a/tools/testing/selftests/bpf/test_btf.c
+++ b/tools/testing/selftests/bpf/test_btf.c
@@ -6642,6 +6642,51 @@ const struct btf_dedup_test dedup_tests[] = {
 		.dont_resolve_fwds = false,
 	},
 },
+{
+	.descr = "dedup: datasec and vars pass-through",
+	.input = {
+		.raw_types = {
+			/* int */
+			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
+			/* static int t */
+			BTF_VAR_ENC(NAME_NTH(2), 1, 0),			/* [2] */
+			/* .bss section */				/* [3] */
+			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
+			BTF_VAR_SECINFO_ENC(2, 0, 4),
+			/* int, referenced from [5] */
+			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [4] */
+			/* another static int t */
+			BTF_VAR_ENC(NAME_NTH(2), 4, 0),			/* [5] */
+			/* another .bss section */			/* [6] */
+			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
+			BTF_VAR_SECINFO_ENC(5, 0, 4),
+			BTF_END_RAW,
+		},
+		BTF_STR_SEC("\0.bss\0t"),
+	},
+	.expect = {
+		.raw_types = {
+			/* int */
+			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
+			/* static int t */
+			BTF_VAR_ENC(NAME_NTH(2), 1, 0),			/* [2] */
+			/* .bss section */				/* [3] */
+			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
+			BTF_VAR_SECINFO_ENC(2, 0, 4),
+			/* another static int t */
+			BTF_VAR_ENC(NAME_NTH(2), 1, 0),			/* [4] */
+			/* another .bss section */			/* [5] */
+			BTF_TYPE_ENC(NAME_NTH(1), BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
+			BTF_VAR_SECINFO_ENC(4, 0, 4),
+			BTF_END_RAW,
+		},
+		BTF_STR_SEC("\0.bss\0t"),
+	},
+	.opts = {
+		.dont_resolve_fwds = false,
+		.dedup_table_size = 1
+	},
+},
 
 };
 
@@ -6671,6 +6716,10 @@ static int btf_type_size(const struct btf_type *t)
 		return base_size + vlen * sizeof(struct btf_member);
 	case BTF_KIND_FUNC_PROTO:
 		return base_size + vlen * sizeof(struct btf_param);
+	case BTF_KIND_VAR:
+		return base_size + sizeof(struct btf_var);
+	case BTF_KIND_DATASEC:
+		return base_size + vlen * sizeof(struct btf_var_secinfo);
 	default:
 		fprintf(stderr, "Unsupported BTF_KIND:%u\n", kind);
 		return -EINVAL;
-- 
2.17.1


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

* Re: [PATCH bpf-next 0/2] add btf_dedup() support for VAR and DATASEC
  2019-04-15 23:48 [PATCH bpf-next 0/2] add btf_dedup() support for VAR and DATASEC andrii.nakryiko
  2019-04-15 23:48 ` [PATCH bpf-next 1/2] btf: add support for VAR and DATASEC in btf_dedup() andrii.nakryiko
  2019-04-15 23:48 ` [PATCH bpf-next 2/2] selftests/btf: add VAR and DATASEC case for dedup tests andrii.nakryiko
@ 2019-04-16  8:26 ` Daniel Borkmann
  2 siblings, 0 replies; 4+ messages in thread
From: Daniel Borkmann @ 2019-04-16  8:26 UTC (permalink / raw)
  To: andrii.nakryiko, netdev, bpf, kernel-team; +Cc: Andrii Nakryiko

On 04/16/2019 01:48 AM, andrii.nakryiko@gmail.com wrote:
> From: Andrii Nakryiko <andriin@fb.com>
> 
> This patchset adds support for new BTF_KIND_VAR and BTF_KIND_DATASEC BTF types
> in btf_dedup() algorithm. VAR and DATASEC are not deduplicated and are always
> considered to be unique, but they require referenced type IDs adjustment.
> 
> Patch #1 adds VAR/DATASEC pass-through support to btf_dedup().
> Patch #2 adds a test validating all the type ID adjustments are correct.
> 
> Andrii Nakryiko (2):
>   btf: add support for VAR and DATASEC in btf_dedup()
>   selftests/btf: add VAR and DATASEC case for dedup tests
> 
>  tools/lib/bpf/btf.c                    | 29 +++++++++++++--
>  tools/testing/selftests/bpf/test_btf.c | 49 ++++++++++++++++++++++++++
>  2 files changed, 76 insertions(+), 2 deletions(-)
> 

Looks good, applied, thanks!

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

end of thread, other threads:[~2019-04-16  8:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-15 23:48 [PATCH bpf-next 0/2] add btf_dedup() support for VAR and DATASEC andrii.nakryiko
2019-04-15 23:48 ` [PATCH bpf-next 1/2] btf: add support for VAR and DATASEC in btf_dedup() andrii.nakryiko
2019-04-15 23:48 ` [PATCH bpf-next 2/2] selftests/btf: add VAR and DATASEC case for dedup tests andrii.nakryiko
2019-04-16  8:26 ` [PATCH bpf-next 0/2] add btf_dedup() support for VAR and DATASEC Daniel Borkmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.