From patchwork Wed Aug 5 05:50:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yonghong Song X-Patchwork-Id: 262709 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=-7.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=no 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 20E09C433DF for ; Wed, 5 Aug 2020 05:51:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F2BD422B40 for ; Wed, 5 Aug 2020 05:51:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="GFea2HL/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726459AbgHEFvC (ORCPT ); Wed, 5 Aug 2020 01:51:02 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:12732 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725920AbgHEFvB (ORCPT ); Wed, 5 Aug 2020 01:51:01 -0400 Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0755p1s4001336 for ; Tue, 4 Aug 2020 22:51:01 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=facebook; bh=CRvJorEC17eX27jrDmKqcWJ299NGOzwHbVEH856ABfA=; b=GFea2HL/MfvCUqninT5SAwt+YOfECusv3kUo/Mm+W1o0Ky0/mWlbl08lv0oSfGDF6C8H yO6fsocrnOrtMFjFO4bviL4wI+Rw6FgnsSZJbVT0umSXCaB/8TCs2hLyDPt5w9iXDq3D /FTLYopY4LGxSWijxRM+mw8c1yHfbpw4mxc= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 32qefa208s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 04 Aug 2020 22:51:01 -0700 Received: from intmgw002.03.ash8.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::e) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 4 Aug 2020 22:51:00 -0700 Received: by devbig003.ftw2.facebook.com (Postfix, from userid 128203) id 6839F3705133; Tue, 4 Aug 2020 22:50:56 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Yonghong Song Smtp-Origin-Hostname: devbig003.ftw2.facebook.com To: , CC: Alexei Starovoitov , Daniel Borkmann , Smtp-Origin-Cluster: ftw2c04 Subject: [PATCH bpf v4 0/2] bpf: change uapi for bpf iterator map elements Date: Tue, 4 Aug 2020 22:50:56 -0700 Message-ID: <20200805055056.1457388-1-yhs@fb.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-08-05_04:2020-08-03,2020-08-05 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 suspectscore=8 spamscore=0 phishscore=0 priorityscore=1501 mlxscore=0 adultscore=0 impostorscore=0 bulkscore=0 malwarescore=0 lowpriorityscore=0 mlxlogscore=999 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2008050052 X-FB-Internal: deliver Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Andrii raised a concern that current uapi for bpf iterator map element is a little restrictive and not suitable for future potential complex customization. This is a valid suggestion, considering people may indeed add more complex custimization to the iterator, e.g., cgroup_id + user_id, etc. for task or task_file. Another example might be map_id plus additional control so that the bpf iterator may bail out a bucket earlier if a bucket has too many elements which may hold lock too long and impact other parts of systems. Patch #1 modified uapi with kernel changes. Patch #2 adjusted libbpf api accordingly. Changelogs: v3 -> v4: . add a forward declaration of bpf_iter_link_info in tools/lib/bpf/bpf.h in case that libbpf is built against not-latest uapi bpf.h. . target the patch set to "bpf" instead of "bpf-next" v2 -> v3: . undo "not reject iter_info.map.map_fd == 0" from v1. In the future map_fd may become optional, so let us use map_fd == 0 indicating the map_fd is not set by user space. . add link_info_len to bpf_iter_attach_opts to ensure always correct link_info_len from user. Otherwise, libbpf may deduce incorrect link_info_len if it uses different uapi header than the user app. v1 -> v2: . ensure link_create target_fd/flags == 0 since they are not used. (Andrii) . if either of iter_info ptr == 0 or iter_info_len == 0, but not both, return error to user space. (Andrii) . do not reject iter_info.map.map_fd == 0, go ahead to use it trying to get a map reference since the map_fd is required for map_elem iterator. . use bpf_iter_link_info in bpf_iter_attach_opts instead of map_fd. this way, user space is responsible to set up bpf_iter_link_info and libbpf just passes the data to the kernel, simplifying libbpf design. (Andrii) Yonghong Song (2): bpf: change uapi for bpf iterator map elements tools/bpf: support new uapi for map element bpf iterator include/linux/bpf.h | 10 ++-- include/uapi/linux/bpf.h | 15 ++--- kernel/bpf/bpf_iter.c | 58 +++++++++---------- kernel/bpf/map_iter.c | 37 +++++++++--- kernel/bpf/syscall.c | 2 +- net/core/bpf_sk_storage.c | 37 +++++++++--- tools/bpf/bpftool/iter.c | 9 ++- tools/include/uapi/linux/bpf.h | 15 ++--- tools/lib/bpf/bpf.c | 3 + tools/lib/bpf/bpf.h | 5 +- tools/lib/bpf/libbpf.c | 6 +- tools/lib/bpf/libbpf.h | 5 +- .../selftests/bpf/prog_tests/bpf_iter.c | 40 ++++++++++--- 13 files changed, 160 insertions(+), 82 deletions(-)