[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAADnVQJsnVmTNxj1QbEbHCsvyvL348R08cZ6ChZK8EGnpc2BfQ@mail.gmail.com>
Date: Thu, 7 Nov 2019 09:50:39 -0800
From: Alexei Starovoitov <alexei.starovoitov@...il.com>
To: Song Liu <songliubraving@...com>
Cc: Alexei Starovoitov <ast@...nel.org>,
David Miller <davem@...emloft.net>,
"daniel@...earbox.net" <daniel@...earbox.net>,
"x86@...nel.org" <x86@...nel.org>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>,
"bpf@...r.kernel.org" <bpf@...r.kernel.org>,
Kernel Team <Kernel-team@...com>
Subject: Re: [PATCH v2 bpf-next 02/17] bpf: Add bpf_arch_text_poke() helper
On Thu, Nov 7, 2019 at 9:20 AM Song Liu <songliubraving@...com> wrote:
>
>
>
> > On Nov 6, 2019, at 9:46 PM, Alexei Starovoitov <ast@...nel.org> wrote:
> >
> > Add bpf_arch_text_poke() helper that is used by BPF trampoline logic to patch
> > nops/calls in kernel text into calls into BPF trampoline and to patch
> > calls/nops inside BPF programs too.
> >
> > Signed-off-by: Alexei Starovoitov <ast@...nel.org>
> > ---
> > arch/x86/net/bpf_jit_comp.c | 51 +++++++++++++++++++++++++++++++++++++
> > include/linux/bpf.h | 8 ++++++
> > kernel/bpf/core.c | 6 +++++
> > 3 files changed, 65 insertions(+)
> >
> > diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
> > index 0399b1f83c23..8631d3bd637f 100644
> > --- a/arch/x86/net/bpf_jit_comp.c
> > +++ b/arch/x86/net/bpf_jit_comp.c
> > @@ -9,9 +9,11 @@
> > #include <linux/filter.h>
> > #include <linux/if_vlan.h>
> > #include <linux/bpf.h>
> > +#include <linux/memory.h>
> > #include <asm/extable.h>
> > #include <asm/set_memory.h>
> > #include <asm/nospec-branch.h>
> > +#include <asm/text-patching.h>
> >
> > static u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
> > {
> > @@ -487,6 +489,55 @@ static int emit_call(u8 **pprog, void *func, void *ip)
> > return 0;
> > }
> >
> > +int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,
> > + void *old_addr, void *new_addr)
> > +{
> > + u8 old_insn[NOP_ATOMIC5] = {};
> > + u8 new_insn[NOP_ATOMIC5] = {};
> > + u8 *prog;
> > + int ret;
> > +
> > + if (!is_kernel_text((long)ip))
> > + /* BPF trampoline in modules is not supported */
> > + return -EINVAL;
> > +
> > + if (old_addr) {
> > + prog = old_insn;
> > + ret = emit_call(&prog, old_addr, (void *)ip);
> > + if (ret)
> > + return ret;
> > + }
> > + if (old_addr) {
> ^ should be new_addr?
> > + prog = new_insn;
> > + ret = emit_call(&prog, old_addr, (void *)ip);
> ^^^ and here?
> > + if (ret)
> > + return ret;
> > + }
> > + ret = -EBUSY;
> > + mutex_lock(&text_mutex);
> > + switch (t) {
> > + case BPF_MOD_NOP_TO_CALL:
> > + if (memcmp(ip, ideal_nops, 5))
>
> Maybe use X86_CALL_SIZE instead of 5? And the five more "5" below?
ohh. yes. of course. I had it fixed.
NOP_ATOMIC5 above is incorrect as well. I had it fixed too.
Looks like I've lost another squash commit last night.
Sorry about that.
Powered by blists - more mailing lists