mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: linux-m68k@vger.kernel.org,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] m68k: Wire up bpf
Date: Wed, 22 Oct 2014 09:48:30 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.02.1410220945360.31528@ayla.of.borg> (raw)
In-Reply-To: <CAADnVQ+5J+BM3onCUxzX+eL-gDqiJ04vDG4iD+3zbqngcmoqzQ@mail.gmail.com>

	Hi Alexei,

On Tue, 21 Oct 2014, Alexei Starovoitov wrote:
> On Tue, Oct 21, 2014 at 10:30 AM, Geert Uytterhoeven
> <geert@linux-m68k.org> wrote:
> > Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
> > ---
> >  arch/m68k/include/asm/unistd.h      | 2 +-
> >  arch/m68k/include/uapi/asm/unistd.h | 1 +
> >  arch/m68k/kernel/syscalltable.S     | 1 +
> >  3 files changed, 3 insertions(+), 1 deletion(-)
> 
> did the tests pass in samples/bpf/test_verifier ?

Thanks for reminding me about the existence of the tests ;-)

Yes, they passed.

Note that gcc 4.1.2 doesn't like C99-initialization of anonymous
struct and union members, so I had to use the patch below:

diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index d18316f9e9c488b0..6ec5060a6ece8f23 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -123,7 +123,7 @@ union bpf_attr {
 		__u32	key_size;	/* size of key in bytes */
 		__u32	value_size;	/* size of value in bytes */
 		__u32	max_entries;	/* max number of entries in a map */
-	};
+	} create;
 
 	struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
 		__u32		map_fd;
@@ -132,7 +132,7 @@ union bpf_attr {
 			__aligned_u64 value;
 			__aligned_u64 next_key;
 		};
-	};
+	} elem;
 
 	struct { /* anonymous struct used by BPF_PROG_LOAD command */
 		__u32		prog_type;	/* one of enum bpf_prog_type */
@@ -142,7 +142,7 @@ union bpf_attr {
 		__u32		log_level;	/* verbosity level of verifier */
 		__u32		log_size;	/* size of user buffer */
 		__aligned_u64	log_buf;	/* user supplied buffer */
-	};
+	} load;
 } __attribute__((aligned(8)));
 
 /* integer value in 'imm' field of BPF_CALL instruction selects which helper
diff --git a/samples/bpf/libbpf.c b/samples/bpf/libbpf.c
index ff65044207384b90..bf1d0bae42c7c6aa 100644
--- a/samples/bpf/libbpf.c
+++ b/samples/bpf/libbpf.c
@@ -18,10 +18,10 @@ int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size,
 		   int max_entries)
 {
 	union bpf_attr attr = {
-		.map_type = map_type,
-		.key_size = key_size,
-		.value_size = value_size,
-		.max_entries = max_entries
+		.create.map_type = map_type,
+		.create.key_size = key_size,
+		.create.value_size = value_size,
+		.create.max_entries = max_entries
 	};
 
 	return syscall(__NR_bpf, BPF_MAP_CREATE, &attr, sizeof(attr));
@@ -30,10 +30,10 @@ int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size,
 int bpf_update_elem(int fd, void *key, void *value)
 {
 	union bpf_attr attr = {
-		.map_fd = fd,
-		.key = ptr_to_u64(key),
-		.value = ptr_to_u64(value),
+		.elem.map_fd = fd,
+		.elem.key = ptr_to_u64(key),
 	};
+	attr.elem.value = ptr_to_u64(value);
 
 	return syscall(__NR_bpf, BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr));
 }
@@ -41,10 +41,10 @@ int bpf_update_elem(int fd, void *key, void *value)
 int bpf_lookup_elem(int fd, void *key, void *value)
 {
 	union bpf_attr attr = {
-		.map_fd = fd,
-		.key = ptr_to_u64(key),
-		.value = ptr_to_u64(value),
+		.elem.map_fd = fd,
+		.elem.key = ptr_to_u64(key),
 	};
+	attr.elem.value = ptr_to_u64(value);
 
 	return syscall(__NR_bpf, BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr));
 }
@@ -52,8 +52,8 @@ int bpf_lookup_elem(int fd, void *key, void *value)
 int bpf_delete_elem(int fd, void *key)
 {
 	union bpf_attr attr = {
-		.map_fd = fd,
-		.key = ptr_to_u64(key),
+		.elem.map_fd = fd,
+		.elem.key = ptr_to_u64(key),
 	};
 
 	return syscall(__NR_bpf, BPF_MAP_DELETE_ELEM, &attr, sizeof(attr));
@@ -62,10 +62,10 @@ int bpf_delete_elem(int fd, void *key)
 int bpf_get_next_key(int fd, void *key, void *next_key)
 {
 	union bpf_attr attr = {
-		.map_fd = fd,
-		.key = ptr_to_u64(key),
-		.next_key = ptr_to_u64(next_key),
+		.elem.map_fd = fd,
+		.elem.key = ptr_to_u64(key),
 	};
+	attr.elem.next_key = ptr_to_u64(next_key);
 
 	return syscall(__NR_bpf, BPF_MAP_GET_NEXT_KEY, &attr, sizeof(attr));
 }
@@ -79,13 +79,13 @@ int bpf_prog_load(enum bpf_prog_type prog_type,
 		  const char *license)
 {
 	union bpf_attr attr = {
-		.prog_type = prog_type,
-		.insns = ptr_to_u64((void *) insns),
-		.insn_cnt = prog_len / sizeof(struct bpf_insn),
-		.license = ptr_to_u64((void *) license),
-		.log_buf = ptr_to_u64(bpf_log_buf),
-		.log_size = LOG_BUF_SIZE,
-		.log_level = 1,
+		.load.prog_type = prog_type,
+		.load.insns = ptr_to_u64((void *) insns),
+		.load.insn_cnt = prog_len / sizeof(struct bpf_insn),
+		.load.license = ptr_to_u64((void *) license),
+		.load.log_buf = ptr_to_u64(bpf_log_buf),
+		.load.log_size = LOG_BUF_SIZE,
+		.load.log_level = 1,
 	};
 
 	bpf_log_buf[0] = 0;

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds

  reply	other threads:[~2014-10-22  7:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-21 17:30 Geert Uytterhoeven
2014-10-21 21:12 ` Alexei Starovoitov
2014-10-22  7:48   ` Geert Uytterhoeven [this message]
2014-10-22 16:34     ` Alexei Starovoitov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.02.1410220945360.31528@ayla.of.borg \
    --to=geert@linux-m68k.org \
    --cc=alexei.starovoitov@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-m68k@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®