From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.7 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC8E3C432C3 for ; Mon, 18 Nov 2019 17:40:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A2CE321939 for ; Mon, 18 Nov 2019 17:40:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZSGIiOOc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727226AbfKRRkH (ORCPT ); Mon, 18 Nov 2019 12:40:07 -0500 Received: from mail-qt1-f194.google.com ([209.85.160.194]:40783 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726647AbfKRRkG (ORCPT ); Mon, 18 Nov 2019 12:40:06 -0500 Received: by mail-qt1-f194.google.com with SMTP id o49so21153616qta.7; Mon, 18 Nov 2019 09:40:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Hyf5OOMWKEL9cOljn/aGmBG4pFeH+YNqiR2OliYFFqI=; b=ZSGIiOOcMLaekKnpOYF7PJCMjqZOEthBOZb/PsBDUZEhmzBT2m6eZSyo3Gj136U4GR 3piMkz8stJlRrveQNpbA5gAIW7IeFjRDB0edF1b3zwUaBCa/95KvFabrz1LHFvoZZDFj pKoOjk/4X8Asbp9aiTqwHNtwuUQJgluhwYmjsYyJWri1dq4Hv7BBPyuc8L4bV6+VhjTI Ozm8GU8wwx610/X/9CjHGpjgn4kzrhtgGJoF/4HfQ+VgpGWVsczM28p9GNgZXHGrAG1c SN0+FZdXX6tLvwJ0bvihGPKvlGP6hqTk8oq9dAh+U2DcUf37sGj5/0FYh9QtJ6QJ9ZsF ToOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Hyf5OOMWKEL9cOljn/aGmBG4pFeH+YNqiR2OliYFFqI=; b=mJjs4NQqbX6+UMqior8DhWftqov09JrZ6JdT3XCc8ciD8TLyBVugVFaFyrCjjxDS17 PqqSrR+o9bqylHF+lMKFbm291f/V0QxqqhkwcRQl+hJ3BK8YfZKgmWyUBvWWGS+0eW45 LYEzJquRVjyhpz3I7BwG3OxNvK1Sa14Q2+TCUXUHF7t7gffxVi7SBTDCilIiP5X2p/YZ /wfWnXaNTT4k2Tk48/QrWCtOkXU6Kvfh4EXfC8bU3Fajgfk9ZHQVs8tAMzbD7tOeRo7m B9BS1kgwJs+DuKIbk7cBSwQRTHwYnlQPDqUqS3dgLjXdBtOIFXSSEeZqknKegsxuKeKg CNKw== X-Gm-Message-State: APjAAAXXWPz+Des/wtzJYmwXQLaRvJiS6v7FzglxEPaoC9re9D14nYDt u1yiqpo/D5WaufYNClpoiLThmFDG/O88AiIJ1VY= X-Google-Smtp-Source: APXvYqzxkfsJ7jA/fUNe+oKfU5tAUVijU9KiOEgz6WDLKAKs5QeRcgJIvlyyFBY7XkpEzpFKxkIe7HOKjFJUjB5+xaU= X-Received: by 2002:ac8:3fed:: with SMTP id v42mr27947748qtk.171.1574098804440; Mon, 18 Nov 2019 09:40:04 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Andrii Nakryiko Date: Mon, 18 Nov 2019 09:39:53 -0800 Message-ID: Subject: Re: [PATCH rfc bpf-next 6/8] bpf: add poke dependency tracking for prog array maps To: Daniel Borkmann Cc: Alexei Starovoitov , john fastabend , Networking , bpf Content-Type: text/plain; charset="UTF-8" Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On Thu, Nov 14, 2019 at 5:04 PM Daniel Borkmann wrote: > > This work adds program tracking to prog array maps. This is needed such > that upon prog array updates/deletions we can fix up all programs which > make use of this tail call map. We add ops->map_poke_{un,}track() helpers > to maps to maintain the list of programs and ops->map_poke_run() for > triggering the actual update. bpf_array_aux is extended to contain the > list head and poke_mutex in order to serialize program patching during > updates/deletions. bpf_free_used_maps() will untrack the program shortly > before dropping the reference to the map. > > The prog_array_map_poke_run() is triggered during updates/deletions and > walks the maintained prog list. It checks in their poke_tabs whether the > map and key is matching and runs the actual bpf_arch_text_poke() for > patching in the nop or new jmp location. Depending on the type of update, > we use one of BPF_MOD_{NOP_TO_JUMP,JUMP_TO_NOP,JUMP_TO_JUMP}. > > Signed-off-by: Daniel Borkmann > --- > include/linux/bpf.h | 36 +++++++++++++ > kernel/bpf/arraymap.c | 120 +++++++++++++++++++++++++++++++++++++++++- > kernel/bpf/core.c | 9 +++- > 3 files changed, 162 insertions(+), 3 deletions(-) > > diff --git a/include/linux/bpf.h b/include/linux/bpf.h > index 0ff06a0d0058..62a369fb8d98 100644 > --- a/include/linux/bpf.h > +++ b/include/linux/bpf.h > @@ -21,6 +21,7 @@ struct bpf_verifier_env; > struct bpf_verifier_log; > struct perf_event; > struct bpf_prog; > +struct bpf_prog_aux; > struct bpf_map; > struct sock; > struct seq_file; > @@ -63,6 +64,12 @@ struct bpf_map_ops { > const struct btf_type *key_type, > const struct btf_type *value_type); > > + /* Prog poke tracking helpers. */ > + int (*map_poke_track)(struct bpf_map *map, struct bpf_prog_aux *aux); > + void (*map_poke_untrack)(struct bpf_map *map, struct bpf_prog_aux *aux); > + void (*map_poke_run)(struct bpf_map *map, u32 key, struct bpf_prog *old, > + struct bpf_prog *new); You are passing bpf_prog_aux for track/untrack, but bpf_prog itself for run. Maybe stick to just bpf_prog everywhere? > + > /* Direct value access helpers. */ > int (*map_direct_value_addr)(const struct bpf_map *map, > u64 *imm, u32 off); > @@ -584,6 +591,9 @@ struct bpf_array_aux { > */ > enum bpf_prog_type type; > bool jited; > + /* Programs with direct jumps into programs part of this array. */ > + struct list_head poke_progs; > + struct mutex poke_mutex; > }; > [...]