Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp81494imu; Mon, 10 Dec 2018 16:37:30 -0800 (PST) X-Google-Smtp-Source: AFSGD/U+ZSVrDDkJI9XgGa9SPHCnmd5bv2WW1HGvaBZGB8DabPdhF2SzwJ40vo127Nrq6gnrFOiD X-Received: by 2002:a62:8a51:: with SMTP id y78mr14182006pfd.35.1544488650221; Mon, 10 Dec 2018 16:37:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544488650; cv=none; d=google.com; s=arc-20160816; b=sTN8REQxIyi5Z/lngjcyOSrQQ4uiyZ+DaB3tn+n0hrvtk2oqKWyJiOCErfiMqADvO3 We5KgVX93QpnGAH7GzPhcTK+Q47THNdUJdVVu34wyXw3Jv3+RhGBSmuuvL9Dt+tpahx9 hLOVPi/RMlYcPb/Hh/DyAiBBX5SwaGGlfm/DW3X5b8n6ZBPYoYuR7sCJ2vK9CW+oAask cYY2XF29fo769AJWvRJtxPK50POL/UjGATn13/dfSuxqlzNXPYbQLZnIdoD6ZoIv3qRu eYWbjQM97bBrIAk6rSgUQN0SrPTd4iOrtkodfTOS10+cD2KlA3FXpUZgCJfKCEDVeTiX MQSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YG6k1tVFdVgQPRwNjfcZcQUx8EyghPoLGHnjPOBceD8=; b=wmDCr+IMu5AjzxSj1uwxAEYi9pbnWmxCqWt3mjuMV1vo+7cxV+W1K8LpBt9v5pct0d 3OTcm6Pkq4ZXWBWQ9Gh8/imy6aKhM//ZX2n3WrG5Vgpw9y5MwgLqn7sg1MDNsPphS5Ok xSyT1ljmNm2jIpXEksw1VArHbwgcHPsiIGfm27bN+0yJ8YWNm9aDVY7j+OO0LxpRWy6J VQONCtpPyug5GhCQ+5jVwMgpDBk2yF+uP5+7ZTL+cQhbLpL6UQltPgBcLsRl4PyQQ6h0 BLf6HbCZCwrlDnrZLJvkokc5rOEntpYE9shmtWFB2dzQ4NJlQMVEa5cBLdYXEu3ho2L9 Lt1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OiX74oW3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y6si10934259plr.186.2018.12.10.16.37.07; Mon, 10 Dec 2018 16:37:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OiX74oW3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730212AbeLJXnO (ORCPT + 99 others); Mon, 10 Dec 2018 18:43:14 -0500 Received: from mail-it1-f194.google.com ([209.85.166.194]:36336 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726607AbeLJXnM (ORCPT ); Mon, 10 Dec 2018 18:43:12 -0500 Received: by mail-it1-f194.google.com with SMTP id c9so848286itj.1; Mon, 10 Dec 2018 15:43:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YG6k1tVFdVgQPRwNjfcZcQUx8EyghPoLGHnjPOBceD8=; b=OiX74oW3dCrCNV8RR/35ZIStdll4IboNM2bNq75QxKOnK8KQbeeYsZm2klYVKQwt3A Deuwhik/1tQ7wzRtj4FI8eJHaiGvVxoOzKVbhd/lbDN5NoZemmCFNW6SODUe9rPqaUDC zNBs3JvXZf3v0JndEbW8aooWlXJdNhKIGrbr0AWYgBYje7tKjWZBR0RDyGcpgij0WMWi 6Fc0xxlbqBCFF8iSkfHURRBOSjaLOtLcBkkj/a9LkSQQwFjPEshh7TxWLRzlRlqJCwUo LJXzGeYzjzh3btuRRDqPWvkB8OaB0H3r88jEc0yEc3IMf4U4lSxFGWE7gRcBySy1YW2V NzRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YG6k1tVFdVgQPRwNjfcZcQUx8EyghPoLGHnjPOBceD8=; b=Ybixgc3pcMfOwCgkDzbfFW2Qb+DnvO6kEMmlCkutOWq48Wtctz4YuFzXQ573quqezV aEQeO1nDpTfTh6XE4FpzqAqFIA6XerkbtrIiyxmqNzW453psGTxjEAo6fvkwg4er73Vo tg/3khGgiaIaw931OP4sXuoUAvocvA+msKoy1SiQzEdRjKnZp3ww0tb1P5zF1SGt6EZJ wG8yabn7+3dXZBwGPoWAtKImASbaXkgNQ4U2SXdcjAFAPvLP+cxxTt5bN252awKZVT/k 237tXn+mU3Fl1jqrcj0zX2LESOF1g1l7G2nLBZjgT3ZE2p9RdFwO4m/0Ized8vbFTHLI ycSg== X-Gm-Message-State: AA+aEWZBc61Pa1PTvsy+q19feP6yoChm+Q6H7kUH4zlzkm49qo8k8yL1 F5UdOozBilrYJIZo8GXgJO+DSQdNo/0= X-Received: by 2002:a05:660c:648:: with SMTP id y8mr412244itk.48.1544485389924; Mon, 10 Dec 2018 15:43:09 -0800 (PST) Received: from tower.thefacebook.com ([2620:10d:c090:200::4:375a]) by smtp.gmail.com with ESMTPSA id e68sm625346ite.7.2018.12.10.15.43.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Dec 2018 15:43:09 -0800 (PST) From: Roman Gushchin X-Google-Original-From: Roman Gushchin To: netdev@vger.kernel.org Cc: kernel-team@fb.com, linux-kernel@vger.kernel.org, Yonghong Song , Martin Lau , Roman Gushchin , Alexei Starovoitov , Daniel Borkmann Subject: [PATCH v2 bpf-next 1/3] bpf: pass struct btf pointer to the map_check_btf() callback Date: Mon, 10 Dec 2018 15:43:00 -0800 Message-Id: <20181210234302.31327-2-guro@fb.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181210234302.31327-1-guro@fb.com> References: <20181210234302.31327-1-guro@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If key_type or value_type are of non-trivial data types (e.g. structure or typedef), it's not possible to check them without the additional information, which can't be obtained without a pointer to the btf structure. So, let's pass btf pointer to the map_check_btf() callbacks. Signed-off-by: Roman Gushchin Cc: Alexei Starovoitov Cc: Daniel Borkmann Acked-by: Martin KaFai Lau --- include/linux/bpf.h | 3 +++ kernel/bpf/arraymap.c | 1 + kernel/bpf/lpm_trie.c | 1 + kernel/bpf/syscall.c | 3 ++- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 0c992b86eb2c..e734f163bd0b 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -23,6 +23,7 @@ struct bpf_prog; struct bpf_map; struct sock; struct seq_file; +struct btf; struct btf_type; /* map is generic key/value storage optionally accesible by eBPF programs */ @@ -52,6 +53,7 @@ struct bpf_map_ops { void (*map_seq_show_elem)(struct bpf_map *map, void *key, struct seq_file *m); int (*map_check_btf)(const struct bpf_map *map, + const struct btf *btf, const struct btf_type *key_type, const struct btf_type *value_type); }; @@ -126,6 +128,7 @@ static inline bool bpf_map_support_seq_show(const struct bpf_map *map) } int map_check_no_btf(const struct bpf_map *map, + const struct btf *btf, const struct btf_type *key_type, const struct btf_type *value_type); diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c index 24583da9ffd1..25632a75d630 100644 --- a/kernel/bpf/arraymap.c +++ b/kernel/bpf/arraymap.c @@ -382,6 +382,7 @@ static void percpu_array_map_seq_show_elem(struct bpf_map *map, void *key, } static int array_map_check_btf(const struct bpf_map *map, + const struct btf *btf, const struct btf_type *key_type, const struct btf_type *value_type) { diff --git a/kernel/bpf/lpm_trie.c b/kernel/bpf/lpm_trie.c index bfd4882e1106..abf1002080df 100644 --- a/kernel/bpf/lpm_trie.c +++ b/kernel/bpf/lpm_trie.c @@ -728,6 +728,7 @@ static int trie_get_next_key(struct bpf_map *map, void *_key, void *_next_key) } static int trie_check_btf(const struct bpf_map *map, + const struct btf *btf, const struct btf_type *key_type, const struct btf_type *value_type) { diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index a99a23bf5910..4eb7750cb5c0 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -456,6 +456,7 @@ static int bpf_obj_name_cpy(char *dst, const char *src) } int map_check_no_btf(const struct bpf_map *map, + const struct btf *btf, const struct btf_type *key_type, const struct btf_type *value_type) { @@ -478,7 +479,7 @@ static int map_check_btf(const struct bpf_map *map, const struct btf *btf, return -EINVAL; if (map->ops->map_check_btf) - ret = map->ops->map_check_btf(map, key_type, value_type); + ret = map->ops->map_check_btf(map, btf, key_type, value_type); return ret; } -- 2.19.2