From patchwork Mon Jan 11 15:56:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 566014 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 402531402C4 for ; Tue, 12 Jan 2016 02:59:32 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=d0qDkSKa; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933648AbcAKP5a (ORCPT ); Mon, 11 Jan 2016 10:57:30 -0500 Received: from mail-pa0-f67.google.com ([209.85.220.67]:34926 "EHLO mail-pa0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933454AbcAKP50 (ORCPT ); Mon, 11 Jan 2016 10:57:26 -0500 Received: by mail-pa0-f67.google.com with SMTP id gi1so32041188pac.2; Mon, 11 Jan 2016 07:57:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8ClEcDHk6IKNEDOZ6yA1TpBLtwpzfLWi0PkAJt6MdxI=; b=d0qDkSKa4mwu07e2NpUkHMPdyeEjYQRgFvZs5pR6OLcCi3TFEhVXxXfzURFVBCGyzH ouEe+PmXyNuwjqrU9u8rabL9ohVxOi4nRI9821QwfwZRhferHt+rF4scTM0+e1bgKaST CZWgR8w6dnW84WPRsRw7I052XQhTcJ3pK1ofE8Sm2tqDVrBJqAUsRkQ7xlK2vvLvODHV knbPJLFLS49uezJm7PJWZ//YMqEeMT/fS/4AYSiAGhII+08gZDCeEgLDeMhJBrKX1Z9A HCCnNuak65QdyDNn7244FEvHeAFGG/Y0AGLZmvm6zHdyToRuXZYq/byqTFV539pTtkgR NGQw== X-Received: by 10.66.192.42 with SMTP id hd10mr179093122pac.111.1452527845269; Mon, 11 Jan 2016 07:57:25 -0800 (PST) Received: from localhost ([103.192.227.7]) by smtp.gmail.com with ESMTPSA id w85sm24246081pfi.13.2016.01.11.07.57.22 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 11 Jan 2016 07:57:22 -0800 (PST) From: Ming Lei To: linux-kernel@vger.kernel.org, Alexei Starovoitov Cc: "David S. Miller" , netdev@vger.kernel.org, Daniel Borkmann , Martin KaFai Lau , Ming Lei Subject: [PATCH 3/9] bpf: introduce percpu verion of lookup/update in bpf_map_ops Date: Mon, 11 Jan 2016 23:56:55 +0800 Message-Id: <1452527821-12276-4-git-send-email-tom.leiming@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1452527821-12276-1-git-send-email-tom.leiming@gmail.com> References: <1452527821-12276-1-git-send-email-tom.leiming@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch is preparing for supporting percpu map, which will be done in the following patches. Signed-off-by: Ming Lei --- include/linux/bpf.h | 5 +++++ kernel/bpf/arraymap.c | 6 ++++++ kernel/bpf/bpf_map.h | 4 ++++ kernel/bpf/hashtab.c | 4 ++++ kernel/bpf/map.c | 11 +++++++++++ 5 files changed, 30 insertions(+) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 83d1926..7fa339f 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -25,6 +25,11 @@ struct bpf_map_ops { int (*map_update_elem)(struct bpf_map *map, void *key, void *value, u64 flags); int (*map_delete_elem)(struct bpf_map *map, void *key); + /* funcs callable from userspace and from eBPF programs */ + void *(*map_lookup_elem_percpu)(struct bpf_map *map, void *key, u32 cpu); + int (*map_update_elem_percpu)(struct bpf_map *map, void *key, + void *value, u64 flags, u32 cpu); + /* funcs called by prog_array and perf_event_array map */ void *(*map_fd_get_ptr) (struct bpf_map *map, int fd); void (*map_fd_put_ptr) (void *ptr); diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c index 9ad9031..20b9f2c 100644 --- a/kernel/bpf/arraymap.c +++ b/kernel/bpf/arraymap.c @@ -139,6 +139,8 @@ static const struct bpf_map_ops array_ops = { .map_lookup_elem = array_map_lookup_elem, .map_update_elem = array_map_update_elem, .map_delete_elem = map_delete_elem_nop, + .map_lookup_elem_percpu = map_lookup_elem_percpu_nop, + .map_update_elem_percpu = map_update_elem_percpu_nop, }; static struct bpf_map_type_list array_type __read_mostly = { @@ -258,6 +260,8 @@ static const struct bpf_map_ops prog_array_ops = { .map_delete_elem = fd_array_map_delete_elem, .map_fd_get_ptr = prog_fd_array_get_ptr, .map_fd_put_ptr = prog_fd_array_put_ptr, + .map_lookup_elem_percpu = map_lookup_elem_percpu_nop, + .map_update_elem_percpu = map_update_elem_percpu_nop, }; static struct bpf_map_type_list prog_array_type __read_mostly = { @@ -324,6 +328,8 @@ static const struct bpf_map_ops perf_event_array_ops = { .map_delete_elem = fd_array_map_delete_elem, .map_fd_get_ptr = perf_event_fd_array_get_ptr, .map_fd_put_ptr = perf_event_fd_array_put_ptr, + .map_lookup_elem_percpu = map_lookup_elem_percpu_nop, + .map_update_elem_percpu = map_update_elem_percpu_nop, }; static struct bpf_map_type_list perf_event_array_type __read_mostly = { diff --git a/kernel/bpf/bpf_map.h b/kernel/bpf/bpf_map.h index 7e596c1..adab4e6 100644 --- a/kernel/bpf/bpf_map.h +++ b/kernel/bpf/bpf_map.h @@ -5,5 +5,9 @@ extern void *map_lookup_elem_nop(struct bpf_map *map, void *key); extern int map_delete_elem_nop(struct bpf_map *map, void *key); +extern void *map_lookup_elem_percpu_nop(struct bpf_map *map, void *key, + u32 cpu); +extern int map_update_elem_percpu_nop(struct bpf_map *map, void *key, + void *value, u64 flags, u32 cpu); #endif diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c index c5b30fd..893e2e4 100644 --- a/kernel/bpf/hashtab.c +++ b/kernel/bpf/hashtab.c @@ -14,6 +14,8 @@ #include #include +#include "bpf_map.h" + struct bucket { struct hlist_head head; raw_spinlock_t lock; @@ -384,6 +386,8 @@ static const struct bpf_map_ops htab_ops = { .map_lookup_elem = htab_map_lookup_elem, .map_update_elem = htab_map_update_elem, .map_delete_elem = htab_map_delete_elem, + .map_lookup_elem_percpu = map_lookup_elem_percpu_nop, + .map_update_elem_percpu = map_update_elem_percpu_nop, }; static struct bpf_map_type_list htab_type __read_mostly = { diff --git a/kernel/bpf/map.c b/kernel/bpf/map.c index bf113fb..b94458a 100644 --- a/kernel/bpf/map.c +++ b/kernel/bpf/map.c @@ -24,3 +24,14 @@ int map_delete_elem_nop(struct bpf_map *map, void *key) return -EINVAL; } +void *map_lookup_elem_percpu_nop(struct bpf_map *map, void *key, u32 cpu) +{ + return NULL; +} + +int map_update_elem_percpu_nop(struct bpf_map *map, void *key, void *value, + u64 flags, u32 cpu) +{ + return -EINVAL; +} +