netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tushar Dave <tushar.n.dave@oracle.com>
To: ast@kernel.org, daniel@iogearbox.net, davem@davemloft.net,
	santosh.shilimkar@oracle.com, jakub.kicinski@netronome.com,
	quentin.monnet@netronome.com, jiong.wang@netronome.com,
	sandipan@linux.vnet.ibm.com, john.fastabend@gmail.com,
	kafai@fb.com, rdna@fb.com, yhs@fb.com, netdev@vger.kernel.org,
	rds-devel@oss.oracle.com, sowmini.varadhan@oracle.com
Subject: [PATCH net-next 0/5] eBPF and struct scatterlist
Date: Tue, 11 Sep 2018 21:37:59 +0200	[thread overview]
Message-ID: <1536694684-3200-1-git-send-email-tushar.n.dave@oracle.com> (raw)

This non-RFC patch-set is follow-up on the RFC v3 that was sent earlier.
(https://www.spinics.net/lists/netdev/msg519380.html)

In this patch-set following changes are made,
RFC v3 -> this patch-set:

- "RFC v3 patch 3" is removed as it is no longer needed because
bpf_msg_pull_data() has all required bug fixed. Thanks Daniel.

- Use __GFP_COMP while allocating pages in bpf_msg_pull_data to avoid
page_copy_sane while using sg page in copy_page_to_iter() (patch 1)

- In sg_filter_run(), after BPF prog returns, mb.sg_data may have
changed while linearize multiple scatterlist entries into one.
Therefore, make sure to update original sg and mark the sg end correctly
before return. (patch 3)

- BPF program can write/modify RDS packet, if that is the case then the
modified packet data is represented in scatterlist. Therefore use
scatterlist (not skb) while copying payload back to userspace. Also
carefully release scatterlist and associated pages e.g.
get_page()/put_page() (patch 4)



Details:
--------
eBPF: Patch 1 use __GFP_COMP while allocating pages in bpf_msg_pull_data
to avoid page_copy_sane warning.

eBPF: Patch 2 adds new eBPF prog type BPF_PROG_TYPE_SOCKET_SG_FILTER
which uses the existing socket filter infrastructure for bpf program
attach and load. eBPF program of type BPF_PROG_TYPE_SOCKET_SG_FILTER
deals with struct scatterlist as bpf context contrast to
BPF_PROG_TYPE_SOCKET_FILTER which deals with struct skb. This new eBPF
program type allow socket filter to run on packet data that is in form
of struct scatterlist.

eBPF: Patch 3 adds sg_filter_run() that runs BPF_PROG_TYPE_SOCKET_SG_FILTER.

RDS: patch 4 allows rds_recv_incoming to invoke socket filter program
which deals with struct scatterlist

bpf/samples: Patch 5 adds socket filter eBPF sample program that uses
patches 1 to 5. The sample program opens an rds socket, attach ebpf
program (socksg i.e. BPF_PROG_TYPE_SOCKET_SG_FILTER) to rds socket and
uses bpf_msg_pull_data() helper to inspect RDS packet data. For a test,
current sample program only prints first few bytes of packet data.


Background:
-----------
The motivation for this work is to allow eBPF based firewalling for
kernel modules that do not always get their packet as an sk_buff from
their downlink drivers. One such instance of this use-case is RDS, which
can be run both over IB (driver RDMA's a scatterlist to the RDS module)
or over TCP (TCP passes an sk_buff to the RDS module).

This patchset uses exiting socket filter infrastructure and extend it
with new eBPF program type that deals with struct scatterlist.
Existing bpf helper bpf_msg_pull_data() is used to inspect packet data
that are in form struct scatterlist. For RDS, the integrated approach
treats the scatterlist as the common denominator, and allows the
application to write a filter for processing a scatterlist.


Testing:
---------
To confirm data accuracy and results, RDS packets of various sizes has
been tested with socksg program along with various start and end values
for bpf_msg_pull_data(). All such tests shows accurate results.

Thanks.

-Tushar


Tushar Dave (5):
  bpf: use __GFP_COMP while allocating page
  eBPF: Add new eBPF prog type BPF_PROG_TYPE_SOCKET_SG_FILTER
  ebpf: Add sg_filter_run()
  rds: invoke socket sg filter attached to rds socket
  ebpf: Add sample ebpf program for SOCKET_SG_FILTER

 include/linux/bpf_types.h      |   1 +
 include/linux/filter.h         |   8 +
 include/uapi/linux/bpf.h       |   7 +
 kernel/bpf/syscall.c           |   1 +
 kernel/bpf/verifier.c          |   1 +
 net/core/filter.c              |  93 ++++++++++-
 net/rds/ib.c                   |   1 +
 net/rds/ib.h                   |   1 +
 net/rds/ib_recv.c              |  12 ++
 net/rds/rds.h                  |   1 +
 net/rds/recv.c                 |  12 ++
 net/rds/tcp.c                  |   1 +
 net/rds/tcp.h                  |   2 +
 net/rds/tcp_recv.c             | 108 ++++++++++++-
 samples/bpf/Makefile           |   3 +
 samples/bpf/bpf_load.c         |  11 +-
 samples/bpf/rds_filter_kern.c  |  42 +++++
 samples/bpf/rds_filter_user.c  | 339 +++++++++++++++++++++++++++++++++++++++++
 tools/bpf/bpftool/prog.c       |   1 +
 tools/include/uapi/linux/bpf.h |   7 +
 tools/lib/bpf/libbpf.c         |   3 +
 tools/lib/bpf/libbpf.h         |   2 +
 22 files changed, 650 insertions(+), 7 deletions(-)
 create mode 100644 samples/bpf/rds_filter_kern.c
 create mode 100644 samples/bpf/rds_filter_user.c

-- 
1.8.3.1

             reply	other threads:[~2018-09-12  0:40 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-11 19:37 Tushar Dave [this message]
2018-09-11 19:38 ` [PATCH net-next 1/5] bpf: use __GFP_COMP while allocating page Tushar Dave
2018-09-12 16:21   ` Tushar Dave
2018-09-12 16:51     ` John Fastabend
2018-09-12 20:15       ` Tushar Dave
2018-09-11 19:38 ` [PATCH net-next 2/5] eBPF: Add new eBPF prog type BPF_PROG_TYPE_SOCKET_SG_FILTER Tushar Dave
2018-09-12  3:57   ` Alexei Starovoitov
2018-09-12 19:25     ` Tushar Dave
2018-09-11 19:38 ` [PATCH net-next 3/5] ebpf: Add sg_filter_run() Tushar Dave
2018-09-12  3:58   ` Alexei Starovoitov
2018-09-12 19:27     ` Tushar Dave
2018-09-11 19:38 ` [PATCH net-next 4/5] rds: invoke socket sg filter attached to rds socket Tushar Dave
2018-09-11 21:06   ` santosh.shilimkar
2018-09-11 19:38 ` [PATCH net-next 5/5] ebpf: Add sample ebpf program for SOCKET_SG_FILTER Tushar Dave
2018-09-12  4:00   ` Alexei Starovoitov
2018-09-12 19:32     ` Tushar Dave
2018-09-13  0:59       ` Sowmini Varadhan
2018-09-13  2:07         ` Alexei Starovoitov
2018-09-13 10:10           ` Sowmini Varadhan
2018-09-17 23:15             ` Alexei Starovoitov
2018-09-17 23:23               ` Sowmini Varadhan
2018-09-17 23:26                 ` 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=1536694684-3200-1-git-send-email-tushar.n.dave@oracle.com \
    --to=tushar.n.dave@oracle.com \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=jakub.kicinski@netronome.com \
    --cc=jiong.wang@netronome.com \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=quentin.monnet@netronome.com \
    --cc=rdna@fb.com \
    --cc=rds-devel@oss.oracle.com \
    --cc=sandipan@linux.vnet.ibm.com \
    --cc=santosh.shilimkar@oracle.com \
    --cc=sowmini.varadhan@oracle.com \
    --cc=yhs@fb.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).