All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: Andrew Melnychenko <andrew@daynix.com>, mst@redhat.com
Cc: yan@daynix.com, yuri.benditovich@daynix.com, qemu-devel@nongnu.org
Subject: Re: [RFC PATCH v2 2/5] ebpf: Added eBPF RSS program.
Date: Tue, 24 Nov 2020 16:14:51 +0800	[thread overview]
Message-ID: <3b1129d9-4e78-bdce-de9d-b2106827d75f@redhat.com> (raw)
In-Reply-To: <20201119111305.485202-3-andrew@daynix.com>


On 2020/11/19 下午7:13, Andrew Melnychenko wrote:
> From: Andrew<andrew@daynix.com>
>
> RSS program and Makefile to build it.
> Also, added a python script that would generate '.h' file.
> The data in that file may be loaded by libbpf.
> EBPF compilation is not required for building qemu.
> You can use Makefile if you need to regenerate tun_rss_steering.h.
>
> NOTE: BPF program can't be loaded without debug/btf info.
> Which brings to huge tun_rss_steering.h file.
> In future, need to find proper way to shrink the file
> and leave only the program data and btf info.
>
> Signed-off-by: Yuri Benditovich<yuri.benditovich@daynix.com>
> Signed-off-by: Andrew Melnychenko<andrew@daynix.com>
> ---
>   ebpf/EbpfElf_to_C.py    |   36 +
>   ebpf/Makefile.ebpf      |   33 +
>   ebpf/rss.bpf.c          |  505 ++++


I think it's better to place them under tools/


>   ebpf/tun_rss_steering.h | 5439 +++++++++++++++++++++++++++++++++++++++


And move this to net/


>   4 files changed, 6013 insertions(+)
>   create mode 100644 ebpf/EbpfElf_to_C.py
>   create mode 100755 ebpf/Makefile.ebpf
>   create mode 100644 ebpf/rss.bpf.c
>   create mode 100644 ebpf/tun_rss_steering.h
>
> diff --git a/ebpf/EbpfElf_to_C.py b/ebpf/EbpfElf_to_C.py
> new file mode 100644
> index 0000000000..3a1b01aedc
> --- /dev/null
> +++ b/ebpf/EbpfElf_to_C.py
> @@ -0,0 +1,36 @@
> +#!/usr/bin/python3


Missing license.


> +
> +import sys
> +import argparse
> +
> +def process_file(filename, prog_name):
> +    print('Processing file:', filename)
> +    with open(filename, 'rb') as f:
> +        with open("%s.h" % prog_name, 'w') as w:
> +
> +            w.write('#ifndef %s\n' % prog_name.upper())
> +            w.write('#define %s\n\n' % prog_name.upper())
> +
> +            w.write("uint8_t data_%s[] = {\n" % prog_name)
> +
> +            data = f.read(8)
> +            while data:
> +                w.write("    " + ", ".join("0x%02x" % x for x in data) + ",\n")
> +                data = f.read(8)
> +
> +            w.write('};\n\n')
> +
> +            w.write('#endif /* %s */\n' % prog_name.upper())
> +
> +    return 0
> +
> +if __name__ == '__main__':
> +    parser = argparse.ArgumentParser(
> +        description='Convert eBPF ELF to C header. '
> +                    'Section name will be used in C namings.')
> +    parser.add_argument('--file', '-f', nargs=1, required=True,
> +                        help='eBPF ELF file')
> +    parser.add_argument('--section', '-s', nargs=1, required=True,
> +                        help='section in ELF with eBPF program.')
> +    args = parser.parse_args()
> +    sys.exit(process_file(args.file[0], args.section[0]))
> diff --git a/ebpf/Makefile.ebpf b/ebpf/Makefile.ebpf
> new file mode 100755
> index 0000000000..c09a8ac543
> --- /dev/null
> +++ b/ebpf/Makefile.ebpf
> @@ -0,0 +1,33 @@
> +OBJS = rss.bpf.o
> +
> +LLC ?= llc
> +CLANG ?= clang
> +INC_FLAGS = -nostdinc -isystem `$(CLANG) -print-file-name=include`
> +EXTRA_CFLAGS ?= -O2 -g -emit-llvm


Do we need a check of clang version to make sure BTF can be generated 
with "-g"?


> +
> +linuxhdrs = ~/src/kernel/master
> +
> +LINUXINCLUDE =  -I $(linuxhdrs)/arch/x86/include/uapi \
> +                -I $(linuxhdrs)/arch/x86/include/generated/uapi \
> +                -I $(linuxhdrs)/arch/x86/include/generated \
> +                -I $(linuxhdrs)/include/generated/uapi \
> +                -I $(linuxhdrs)/include/uapi \
> +                -I $(linuxhdrs)/include \
> +                -I $(linuxhdrs)/tools/lib
> +
> +all: $(OBJS)
> +
> +.PHONY: clean
> +
> +clean:
> +	rm -f $(OBJS)
> +
> +INC_FLAGS = -nostdinc -isystem `$(CLANG) -print-file-name=include`
> +
> +$(OBJS):  %.o:%.c
> +	$(CLANG) $(INC_FLAGS) \
> +                -D__KERNEL__ -D__ASM_SYSREG_H \
> +                -I../include $(LINUXINCLUDE) \
> +                $(EXTRA_CFLAGS) -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@
> +	python3 EbpfElf_to_C.py -f rss.bpf.o -s tun_rss_steering
> +
> diff --git a/ebpf/rss.bpf.c b/ebpf/rss.bpf.c
> new file mode 100644
> index 0000000000..3416bc72d0
> --- /dev/null
> +++ b/ebpf/rss.bpf.c
> @@ -0,0 +1,505 @@
> +/*
> + * eBPF RSS program
> + *
> + * Developed by Daynix Computing LTD (http://www.daynix.com)
> + *
> + * Authors:
> + *  Andrew Melnychenko<andrew@daynix.com>
> + *  Yuri Benditovich<yuri.benditovich@daynix.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2.  See
> + * the COPYING file in the top-level directory.
> + */
> +
> +#include <stddef.h>
> +#include <stdbool.h>
> +#include <linux/bpf.h>
> +
> +#include <linux/in.h>
> +#include <linux/if_ether.h>
> +#include <linux/ip.h>
> +#include <linux/ipv6.h>
> +
> +#include <linux/udp.h>
> +#include <linux/tcp.h>
> +
> +#include <bpf/bpf_helpers.h>
> +#include <linux/virtio_net.h>
> +
> +/*
> + * Prepare:
> + * Requires llvm, clang, python3, linux kernel tree
> + *
> + * Build tun_rss_steering.h:
> + * make -f Mefile.ebpf clean all
> + */


It's better to merge those instructions with the comments at the beginning.


> +
> +#define INDIRECTION_TABLE_SIZE 128
> +#define HASH_CALCULATION_BUFFER_SIZE 36
> +
> +struct rss_config_t {
> +    __u8 redirect;
> +    __u8 populate_hash;
> +    __u32 hash_types;
> +    __u16 indirections_len;
> +    __u16 default_queue;
> +};
> +
> +struct toeplitz_key_data_t {
> +    __u32 leftmost_32_bits;
> +    __u8 next_byte[HASH_CALCULATION_BUFFER_SIZE];
> +};
> +


[...]


> +
> +SEC("tun_rss_steering")
> +int tun_rss_steering_prog(struct __sk_buff *skb)
> +{
> +
> +    struct rss_config_t *config = 0;
> +    struct toeplitz_key_data_t *toe = 0;


There's no need to initialize the above two.

Thanks



  reply	other threads:[~2020-11-24  8:17 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-19 11:13 [RFC PATCH v2 0/5] eBPF RSS support for virtio-net Andrew Melnychenko
2020-11-19 11:13 ` [RFC PATCH v2 1/5] net: Added SetSteeringEBPF method for NetClientState Andrew Melnychenko
2020-11-23  6:10   ` Jason Wang
2020-11-19 11:13 ` [RFC PATCH v2 2/5] ebpf: Added eBPF RSS program Andrew Melnychenko
2020-11-24  8:14   ` Jason Wang [this message]
2020-11-19 11:13 ` [RFC PATCH v2 3/5] ebpf: Added eBPF RSS loader Andrew Melnychenko
2020-11-24  8:33   ` Jason Wang
2020-11-19 11:13 ` [RFC PATCH v2 4/5] virtio-net: Added eBPF RSS to virtio-net Andrew Melnychenko
2020-11-24  8:48   ` Jason Wang
2020-12-01  7:40     ` Yuri Benditovich
2020-12-02  4:05       ` Jason Wang
2020-12-02  7:16         ` Yuri Benditovich
2020-12-02  8:06           ` Jason Wang
2020-11-19 11:13 ` [RFC PATCH v2 5/5] docs: Added eBPF documentation Andrew Melnychenko
2020-11-24  8:54   ` Jason Wang
2020-11-26 13:00     ` Yuri Benditovich
2020-11-27  4:36       ` Jason Wang
2020-11-23  6:08 ` [RFC PATCH v2 0/5] eBPF RSS support for virtio-net Jason Wang
2020-11-26 12:52   ` Yuri Benditovich
2020-11-27  4:35     ` Jason Wang
2020-11-27  6:06       ` Yuri Benditovich
2020-11-30  2:54         ` Jason Wang
2020-12-02 13:55 ` Jason Wang
2020-12-02 14:18   ` Toke Høiland-Jørgensen
2020-12-04  7:42     ` Yuri Benditovich
2020-12-04 10:09       ` Toke Høiland-Jørgensen
2020-12-04 12:31         ` Yuri Benditovich
2020-12-04 13:57           ` Toke Høiland-Jørgensen
2020-12-06 18:44             ` Yuri Benditovich

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=3b1129d9-4e78-bdce-de9d-b2106827d75f@redhat.com \
    --to=jasowang@redhat.com \
    --cc=andrew@daynix.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=yan@daynix.com \
    --cc=yuri.benditovich@daynix.com \
    /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 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.