All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: "Ananyev, Konstantin" <konstantin.ananyev@intel.com>
Cc: bpf <bpf@vger.kernel.org>
Subject: Re: FW: BPF_PSEUDO_CALL question
Date: Fri, 19 Apr 2019 17:30:02 -0700	[thread overview]
Message-ID: <20190420003000.rxahvtjoih7gcnah@ast-mbp.dhcp.thefacebook.com> (raw)
In-Reply-To: <2601191342CEEE43887BDE71AB9772580148A99F8B@irsmsx105.ger.corp.intel.com>

On Fri, Apr 19, 2019 at 11:16:31AM +0000, Ananyev, Konstantin wrote:
> 
> 
> > > > >
> > > > > Hi Alexei,
> > > > > I posted the question below on llvm-dev mailing list, but there is no answer so far.
> > > > > As you seems the author of BPF_PSEUDO_CALL in LLVM (and linux kernel) thought might
> > > > > be you know the answer?
> > > > > I looked through the patches, but didn't spot anything myself.
> > > > > Thanks
> > > > > Konstantin
> > > > >
> > > > > -----Original Message-----
> > > > > From: llvm-dev [mailto:llvm-dev-bounces@lists.llvm.org] On Behalf Of Ananyev, Konstantin via llvm-dev
> > > > > Sent: Wednesday, April 10, 2019 7:37 PM
> > > > > To: llvm-dev@lists.llvm.org
> > > > > Subject: [llvm-dev] BPF_PSEUDO_CALL question
> > > > >
> > > > >
> > > > > Hi everyone,
> > > > > with clang 6.0 and onwards, for the following code:
> > > > > $ cat t6.c
> > > > >
> > > > > #include <stdint.h>
> > > > >
> > > > > extern int ffx1(const void *p);
> > > > >
> > > > > uint64_t entry(const void *p)
> > > > > {
> > > > >         return ffx1(p);
> > > > > }
> > > > >
> > > > > clang -O2  -target bpfel -c t6.c
> > > > > generates for the call BPF_PSEUDO_CALL instruction:
> > > > > entry:
> > > > >        0:       85 10 00 00 ff ff ff ff         call -1
> > > > >        1:       67 00 00 00 20 00 00 00         r0 <<= 32
> > > > >        2:       c7 00 00 00 20 00 00 00         r0 s>>= 32
> > > > >        3:       95 00 00 00 00 00 00 00         exit
> > > > >
> > > > > Is there any way to force clang to generate proper BPF_CALL instruction,
> > > > > i.e: 85 00 00 00 ff ff ff ff (as it did in older versions)?
> > > >
> > > > older version of llvm generated broken code.
> > > > there are only two call flavors:
> > > > - call imm -> calling particular kernel helper where imm==helper_id
> > >
> > > Ok but in the example above, is it possible tell to the llvm that
> > > ffx1() is actually a kernel helper with id==X?
> > 
> > here is how it works for helpers:
> > static void *(*bpf_map_lookup_elem)(void *map, const void *key) =
> >         (void *) BPF_FUNC_map_lookup_elem;
> > 
> > User space can hack similar thing for any integer and any name.
> 
> Thanks a lot.
> Yes, such approach would work.
> Though it means that user will need to define exact id for the each  helper function
> and keep it always in sync between bpf programs and bpf execution environment. 
> Probably not a big deal for kernel when all helpers are well defined and restricted,
> but might become messy for user-space where each app might want to have it's
> own set of helpers.
> My thought was - might be it is possible to say to llvm that it is a helper function
> but with unknown id that will be resolved dynamically at bpf load time.

I'm not sure what exactly you're proposing.
For local functions llvm will generate relative offset with pseudo_call mark.
That is api and cannot be changed.
Support for calling external functions is currently half way done,
since relocations are there, but could be buggy, since
there is no kernel/libbpf support for it yet.


      reply	other threads:[~2019-04-20  0:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <2601191342CEEE43887BDE71AB9772580148A95A96@irsmsx105.ger.corp.intel.com>
     [not found] ` <2601191342CEEE43887BDE71AB9772580148A97E27@irsmsx105.ger.corp.intel.com>
2019-04-16  1:01   ` FW: BPF_PSEUDO_CALL question Alexei Starovoitov
2019-04-16 14:34     ` Ananyev, Konstantin
2019-04-16 16:12       ` Alexei Starovoitov
2019-04-19 11:16         ` Ananyev, Konstantin
2019-04-20  0:30           ` Alexei Starovoitov [this message]

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=20190420003000.rxahvtjoih7gcnah@ast-mbp.dhcp.thefacebook.com \
    --to=alexei.starovoitov@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=konstantin.ananyev@intel.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.