linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexei Starovoitov <ast@plumgrid.com>
To: Daniel Borkmann <dborkman@redhat.com>
Cc: "David S. Miller" <davem@davemloft.net>,
	Ingo Molnar <mingo@kernel.org>,
	Andy Lutomirski <luto@amacapital.net>,
	Hannes Frederic Sowa <hannes@stressinduktion.org>,
	Eric Dumazet <edumazet@google.com>,
	Linux API <linux-api@vger.kernel.org>,
	Network Development <netdev@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH net-next 6/7] bpf: allow eBPF programs to use maps
Date: Tue, 4 Nov 2014 15:08:03 -0800	[thread overview]
Message-ID: <CAMEtUuwgSDdMPeRSWGiVAXb4DfwxoBVvd2TgHdruczq2mVbM=A@mail.gmail.com> (raw)
In-Reply-To: <5458A17B.7030904@redhat.com>

On Tue, Nov 4, 2014 at 1:50 AM, Daniel Borkmann <dborkman@redhat.com> wrote:
> These WARN_ON_ONCE(!rcu_read_lock_held()) seem odd. While I see the point
> that
> you're holding RCU read lock on the lookup, can you elaborate on your RCU
> usage
> here and why it's necessary for delete/update?
>
> I suspect due to the synchronize_rcu() you're using and not using any RCU
> accessors but plain memcpy() e.g. in case of the array ...?

Correct in case of array.
Also hash delete/update() call into lookup() internally
that is using _rcu() helpers...
Future map types might have much more
complex implementations (like LPM), so it helps
to state the rules early.

Another reason is more complex to explain:
A program that intends to access maps has to be one
rcu critical section. So all lookup/update/delete calls
are under rcu_lock_held.
Since programs by themselves cannot have WARN_ON
inside them, I've added WARN_ON in these three
functions that will be called from the programs to make
sure that kernel subsystems don't do (*prog->bpf_func)(...)
without taking rcu_lock if they intend to let programs
access maps.

Having said that in the future we might have a case
for programs that don't call into these functions at all
and execute instructions only. Those won't need
rcu_lock() wrap. I experimented with that for the
patch where I replaced pred-tree walker with eBPF
program. There is no rcu there. And no calls
to map accessors.

Has to be noted, that socket filters use rcu to
protect sk_filter pointer and program itself. So for that
use case we'll keep using rcu for foreseeable future.
For tracing filters I had to add rcu_lock() around
BPF_PROG_RUN() invocation and these WARN_ON
checks saved me a lot of headache, so I prefer to
keep them since they cost nothing when lockdep is off.

  reply	other threads:[~2014-11-04 23:08 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-04  2:54 [PATCH net-next 0/7] implementation of eBPF maps Alexei Starovoitov
2014-11-04  2:54 ` [PATCH net-next 1/7] bpf: add 'flags' attribute to BPF_MAP_UPDATE_ELEM command Alexei Starovoitov
2014-11-04  9:25   ` Daniel Borkmann
2014-11-04 23:04     ` Alexei Starovoitov
2014-11-05 14:57       ` Daniel Borkmann
2014-11-06 17:39         ` Alexei Starovoitov
2014-11-04  2:54 ` [PATCH net-next 2/7] bpf: add hashtable type of eBPF maps Alexei Starovoitov
2014-11-04  2:54 ` [PATCH net-next 3/7] bpf: add array " Alexei Starovoitov
2014-11-04  9:58   ` Daniel Borkmann
2014-11-04 23:14     ` Alexei Starovoitov
2014-11-04  2:54 ` [PATCH net-next 4/7] bpf: fix BPF_MAP_LOOKUP_ELEM command return code Alexei Starovoitov
2014-11-04  2:54 ` [PATCH net-next 5/7] bpf: add a testsuite for eBPF maps Alexei Starovoitov
2014-11-04  2:54 ` [PATCH net-next 6/7] bpf: allow eBPF programs to use maps Alexei Starovoitov
2014-11-04  9:50   ` Daniel Borkmann
2014-11-04 23:08     ` Alexei Starovoitov [this message]
2014-11-04  2:54 ` [PATCH net-next 7/7] bpf: remove test map scaffolding and use proper types 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='CAMEtUuwgSDdMPeRSWGiVAXb4DfwxoBVvd2TgHdruczq2mVbM=A@mail.gmail.com' \
    --to=ast@plumgrid.com \
    --cc=davem@davemloft.net \
    --cc=dborkman@redhat.com \
    --cc=edumazet@google.com \
    --cc=hannes@stressinduktion.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mingo@kernel.org \
    --cc=netdev@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;
as well as URLs for NNTP newsgroup(s).