Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1210913imu; Fri, 7 Dec 2018 16:54:22 -0800 (PST) X-Google-Smtp-Source: AFSGD/XrvNy3KLplAOgTK3zAR3TcPXbRI8qJroRCOVK8CGPE/YfYsskFPb3EcB91uFKUmO7xgoic X-Received: by 2002:a17:902:6b0c:: with SMTP id o12mr4167456plk.291.1544230462490; Fri, 07 Dec 2018 16:54:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544230462; cv=none; d=google.com; s=arc-20160816; b=no94cajq84raxPdN9vEm3BHI3E661PKL7HEiyWyDvdO4s4BceHvSY1ci4aJYa90COh sQ2kelyUyNFYDAcndfv1F10tMaPzDTmqNLiGHTQE1SSHFqAfLoCnpBxkU6FiAMzl4GOc R15nZPDfZN9v4V2H9B/XvOP4coG1La+I6YygPI8f0Q3h5hok6Qjf2kLedjci3np4Vm7R VIb5FyuoGZdLuNGBMck8TxKn5Yz4XOkJqPtymd5V1l5GiquzI2X7I2c04aFFbIdeNUwB GoxuK7Xkraav/yG6kvsnbSf2bIP+zO4Nm4yCtXj7hFkj96lrOE3JXCEMmZRM4HpGhfiT Xl+A== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=xEbODVp2HpGjxgjKeclkzSSi6q3c0+//7NxFbJhw2io=; b=eNZie2sDRLYcmkJkHjvjL0KPcb2OtdQDzcib0NFs9P5dozBO3RzJUtl+ouK6+GFi5S q9FRpG98BD9Qn+tamb/LRQqGCeboNj3gIM4IbFBcRmoA1wSW1oQ8sIKpRsZWaYN15unO pu4It7zucf9QZj0n1SW2sHqAQFcrAIdDjTk8sWc5O9NVYHDwSzOsfkKOtwdKdhXngrJk xKozqfJ2RbMfMbu02JX0jUHOL7AsHhHkj6yg1/9FVXVGbW0R7vHFR6wyfyrtzSd97D9I qdHxCvBEe0CnsgENEl/uWUVMx5Uh8yjZw4DEMA3Gc+IgNZnx1VS5rGzLTWe+WTLTnteO RUIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nLAbJhuh; 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 g26si4260096pfi.184.2018.12.07.16.54.07; Fri, 07 Dec 2018 16:54:22 -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=nLAbJhuh; 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 S1726153AbeLHAxa (ORCPT + 99 others); Fri, 7 Dec 2018 19:53:30 -0500 Received: from mail-it1-f196.google.com ([209.85.166.196]:35301 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726070AbeLHAxa (ORCPT ); Fri, 7 Dec 2018 19:53:30 -0500 Received: by mail-it1-f196.google.com with SMTP id p197so9877000itp.0; Fri, 07 Dec 2018 16:53:29 -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:mime-version :content-transfer-encoding; bh=xEbODVp2HpGjxgjKeclkzSSi6q3c0+//7NxFbJhw2io=; b=nLAbJhuhGRi7YZuM8dIgd1fubmTb5jwEymEd94oAYmsh+hUQNce1hBhrUr82VxjXho xWWbKxNgF/f/QjsBR4voASQlygcxg/lnxQkURe3DlpEYzDWEW2TuleHi+cR1xRCuI1jA ZmWaGkVmJorKuzsw7WuRbw/W27Eq/rbX+vFXIqXYcbu42qxU325rN8apVkE3B1v1hvos 1+uoVaaUGwBgL1zjeS/2pQNoCBgoLU8oXCNSpvD/j32er6v7GMcC6Bq/XmyvgzF24U/o nEO2BSO/HNMorGdgcuk5HoTIVIYd9+sXCkYj2GkHG8i2hGFrOE7b4/BQiWcURoL05dyW wKYA== 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:mime-version :content-transfer-encoding; bh=xEbODVp2HpGjxgjKeclkzSSi6q3c0+//7NxFbJhw2io=; b=HP7raWIDhH3xiP9USMkEwvG7JaTv+6NtorXVnd5r9bIWWN/p3sJ+A4F8fhnOit18MC cK1H5+GLFL3g+9dDuKgVB/q4AS+akqP3g6NIsKvO1qj5CDOffQeE7FNbJE/r/S5aXFqh Uny3q64aXgkHR4aNDh+NmYz1pDJPGocPIuAtcBMFHT32Dl6Ke4rqOXFsMGTzUUpeLDs7 awA62f87dFdChmFDpeFDDUNTD0BGjOb9hehdicJAY0j2OGJtXCbtyAFrOy2fQY1iHfCR 7kdtg0l5wcHnwNpQM89NVbYSgEOeAaf126/MenlDQ7iagPD9CezXmPqGoJVPACd3Arp1 +G0A== X-Gm-Message-State: AA+aEWbMikt80hvUwj70pCs6KhwDmSpenfJ8WCo/Wp2eZGGULfXvgg94 QGAOPEuYi++6xVh/IEaX8sqdevZNHZE= X-Received: by 2002:a05:660c:88b:: with SMTP id o11mr3824996itk.9.1544230408762; Fri, 07 Dec 2018 16:53:28 -0800 (PST) Received: from tower.thefacebook.com ([2620:10d:c090:200::6:9a2e]) by smtp.gmail.com with ESMTPSA id 21sm2069769iou.79.2018.12.07.16.53.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Dec 2018 16:53:28 -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, Roman Gushchin , Alexei Starovoitov , Daniel Borkmann Subject: [PATCH bpf-next 1/3] bpf: pass struct btf pointer to the map_check_btf() callback Date: Fri, 7 Dec 2018 16:53:13 -0800 Message-Id: <20181208005315.3500-1-guro@fb.com> X-Mailer: git-send-email 2.19.2 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 --- 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 e82b7039fc66..128d93540b23 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 aa05aa38f4a8..7c2e8ab03a34 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