Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9890333ybi; Wed, 24 Jul 2019 11:47:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqxl4dKu0NY3ilJfSPRuRR1aVxSX+qNvOab4zvJYkDKXZu/AzjLNKogOXX04BSA7DAmH+8Cl X-Received: by 2002:a65:5144:: with SMTP id g4mr30314621pgq.202.1563994068277; Wed, 24 Jul 2019 11:47:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563994068; cv=none; d=google.com; s=arc-20160816; b=BoDaZxpEfd6NDqAPnduBmIGvxGhqBjAH82h3p05pcHSx0GOIwO9fm98dpI9QMiQ0jf R5REv7xSWhWJUId9qel2BkEZvQTblIF7Tur82AjGM7c6E9gtxpchTlJQA6nnRGZ7UGvN 5aFbshnPQ1UDjHps7+8T8uh8bGSHRzhinhOhbq3wKBz8RBwD+MBKJ95z6ZtqdWnhImWT nmSUo6rkE7Lavr+QlUp/uCMRACgr6UuueOcuvjYqeEHl1mbTD3ZMppjy1PyKqmPfYmi9 b5xlY4PxsollRHGFBmHoodY62XP7/LhERTRq8kB8n7REu3Kta/TChpbGKypMu4rSjjbo K+8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=6m5pZYRwQ/VLImDzwYssdUybUrVH4MZ+xdF6UGNAnzQ=; b=wVL29YApgIhPkxJP46+OFnR04B6RVfGQlGJgDwfEQEEPoATDmEh3qJlJe9FZWka5BX rWdvTY/E14JGIBDPm3/WoaE/AF85hUEfeAubqclHaJiaIpCc1WTPYjJ/K9S9rZm+cJb0 emm2NGQaF9btOdaj9dVpDXExUzx1Me/v8m0TtB6IcS1Nd/YQl+jRAlhUjprPriJPcfpR 6W88aa0NY59gKbetFeHDSj4wlBqhLD/jRsNV1EyCtGgbRBNu3NCyswjQva6JvvRH7X2o t5nXx5hgJGvWhyCj+a5JYYfmmDEj15BEItYzSBFTnZKLDcVH/cwFfGHfQiEyVV7tT109 afsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=FQTT+XyX; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w12si15895056pgs.364.2019.07.24.11.47.32; Wed, 24 Jul 2019 11:47:48 -0700 (PDT) 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=@google.com header.s=20161025 header.b=FQTT+XyX; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387394AbfGXQ6T (ORCPT + 99 others); Wed, 24 Jul 2019 12:58:19 -0400 Received: from mail-pl1-f202.google.com ([209.85.214.202]:32984 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726282AbfGXQ6T (ORCPT ); Wed, 24 Jul 2019 12:58:19 -0400 Received: by mail-pl1-f202.google.com with SMTP id f2so24451349plr.0 for ; Wed, 24 Jul 2019 09:58:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=6m5pZYRwQ/VLImDzwYssdUybUrVH4MZ+xdF6UGNAnzQ=; b=FQTT+XyX/59gFXT1uGFwGXtgUyjKf4iPsM32Sk9G7dinmYGnLj5i3YxJQtU8tzbl3K fwhzXeFXWn0VIXqHMCinq/2BuSH08UCWzLV1RhNs2sLV3K6hH4jBQs/6fNwFi/g+EKXR edlGI5m6uMpv4ChVdLz3GNY/yAFrgF63w7bCSpQpduHIbJ8i4GKo67HwDYWtHVc30uH2 cHuLWQEAtdudgD5RySbzOO2htsNdMFjzNb5sD0lRZwmVsGSKHhc+cjH/B0sFOU6XO4MB 0uVmd0DQzCI7Nlg93wUgjZRchVV0sPjtemJxHS6WjwuQVp1T4K0c/o2K1wYsWPyE4XZD OPxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=6m5pZYRwQ/VLImDzwYssdUybUrVH4MZ+xdF6UGNAnzQ=; b=e09GJ5sY13BN8XgbP04rJmyp+kjqLdeINYwlqyFSzeVfGBKNe1iDRDcVnxjKJV0NOw rzQXgBtR4911LNd+aohWgKpUDmj4lSbaH9KoZ367zkn1oLVyQgbs/tmTLIRH1a3HdgNC IjtcGpAojOqUToWsNrUjy35xVqo6rqMfWHqsId91eEOwQTvNPwECGfg5eINt3QOcY5hq HIDHhHNyLI+Q0Cp2Ygns4IQUH2C7dizfsqnoj3QLO2NovYsV/NwHXgxR5AGmzAPn17kd 1QVFrLBRPftP6ATuc7AsgC4FYo/P0Cn//5snlrRCVuBlmu45lDPfxZuJnIVABsHsUNCM sOmQ== X-Gm-Message-State: APjAAAUalBm4AZmmQjLVG46yvOE3hd/k5w+FQ00f6otGtEzBw4+anIn+ BQSRM75cwIpYVsPxA66oWSQOKfXf3+ZO X-Received: by 2002:a63:a35e:: with SMTP id v30mr23431447pgn.129.1563987497938; Wed, 24 Jul 2019 09:58:17 -0700 (PDT) Date: Wed, 24 Jul 2019 09:57:57 -0700 Message-Id: <20190724165803.87470-1-brianvv@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.22.0.657.g960e92d24f-goog Subject: [PATCH bpf-next 0/6] bpf: add BPF_MAP_DUMP command to dump more than one entry per call From: Brian Vazquez To: Brian Vazquez , Alexei Starovoitov , Daniel Borkmann , "David S . Miller" Cc: Stanislav Fomichev , Willem de Bruijn , Petar Penkov , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Brian Vazquez Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This introduces a new command to retrieve multiple number of entries from a bpf map. This new command can be executed from the existing BPF syscall as follows: err = bpf(BPF_MAP_DUMP, union bpf_attr *attr, u32 size) using attr->dump.map_fd, attr->dump.prev_key, attr->dump.buf, attr->dump.buf_len returns zero or negative error, and populates buf and buf_len on succees This implementation is wrapping the existing bpf methods: map_get_next_key and map_lookup_elem Note that this implementation can be extended later to do dump and delete by extending map_lookup_and_delete_elem (currently it only works for bpf queue/stack maps) and either use a new flag in map_dump or a new command map_dump_and_delete. Results show that even with a 1-elem_size buffer, it runs ~40 faster than the current implementation, improvements of ~85% are reported when the buffer size is increased, although, after the buffer size is around 5% of the total number of entries there's no huge difference in increasing it. Tested: Tried different size buffers to handle case where the bulk is bigger, or the elements to retrieve are less than the existing ones, all runs read a map of 100K entries. Below are the results(in ns) from the different runs: buf_len_1: 69038725 entry-by-entry: 112384424 improvement 38.569134 buf_len_2: 40897447 entry-by-entry: 111030546 improvement 63.165590 buf_len_230: 13652714 entry-by-entry: 111694058 improvement 87.776687 buf_len_5000: 13576271 entry-by-entry: 111101169 improvement 87.780263 buf_len_73000: 14694343 entry-by-entry: 111740162 improvement 86.849542 buf_len_100000: 13745969 entry-by-entry: 114151991 improvement 87.958187 buf_len_234567: 14329834 entry-by-entry: 114427589 improvement 87.476941 The series of patches are split as follows: - First patch move some map_lookup_elem logic into 2 fucntions to deduplicate code: bpf_map_value_size and bpf_map_copy_value - Second patch introduce map_dump function - Third patch syncs tools linux headers - Fourth patch adds libbpf support - Last two patches adds tests RFC Changelog: - remove wrong usage of attr.flags - move map_fd to remove hole after it v3: - add explanation of the API in the commit message - fix masked errors and return them to user - copy last_key from return buf into prev_key if it was provided - run perf test with kpti and retpoline mitigations v2: - use proper bpf-next tag Brian Vazquez (6): bpf: add bpf_map_value_size and bp_map_copy_value helper functions bpf: add BPF_MAP_DUMP command to dump more than one entry per call bpf: keep bpf.h in sync with tools/ libbpf: support BPF_MAP_DUMP command selftests/bpf: test BPF_MAP_DUMP command on a bpf hashmap selftests/bpf: add test to measure performance of BPF_MAP_DUMP include/uapi/linux/bpf.h | 9 + kernel/bpf/syscall.c | 251 ++++++++++++++++++------ tools/include/uapi/linux/bpf.h | 9 + tools/lib/bpf/bpf.c | 28 +++ tools/lib/bpf/bpf.h | 4 + tools/lib/bpf/libbpf.map | 2 + tools/testing/selftests/bpf/test_maps.c | 148 +++++++++++++- 7 files changed, 388 insertions(+), 63 deletions(-) -- 2.22.0.657.g960e92d24f-goog