From patchwork Fri Sep 23 06:06:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Marchevsky X-Patchwork-Id: 12986150 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23B6BC6FA82 for ; Fri, 23 Sep 2022 06:06:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229744AbiIWGGY (ORCPT ); Fri, 23 Sep 2022 02:06:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229900AbiIWGGW (ORCPT ); Fri, 23 Sep 2022 02:06:22 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DECA4115F4F for ; Thu, 22 Sep 2022 23:06:21 -0700 (PDT) Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28MKiQlg001103 for ; Thu, 22 Sep 2022 23:06:21 -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=FIa3Yq6n+zpZVVx7wdnOb8Y0bW8rXKBDQLxFsBYeCqg=; b=EO9ZkImL2kJ4DTybOli8pC8OLWn6UnpFVBNticCXKjWf2HVrVVgstrTEdQnhg8GbNVqz fYSgziTO0c64MdtigkKQui3oGIh0Z4dC5+XweVBDVALBYc9ji8OCwL8hslLhv7lrrFMB BxU3m+7r+ke7I7LQHZCpEhSxaqoIvNhY8Y4= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3jrhjgrj85-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 22 Sep 2022 23:06:21 -0700 Received: from twshared3888.09.ash9.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::d) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 22 Sep 2022 23:06:18 -0700 Received: by devbig077.ldc1.facebook.com (Postfix, from userid 158236) id B495DDE1C3D6; Thu, 22 Sep 2022 23:06:16 -0700 (PDT) From: Dave Marchevsky To: CC: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Kernel Team , Kumar Kartikeya Dwivedi , Yonghong Song , Dave Marchevsky Subject: [PATCH v4 bpf-next 1/2] bpf: Allow ringbuf memory to be used as map key Date: Thu, 22 Sep 2022 23:06:13 -0700 Message-ID: <20220923060614.4025371-1-davemarchevsky@fb.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: OlcdaPvLOjBCDFEfZBlBqNtnrt9Z0qg9 X-Proofpoint-ORIG-GUID: OlcdaPvLOjBCDFEfZBlBqNtnrt9Z0qg9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-23_02,2022-09-22_02,2022-06-22_01 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net This patch adds support for the following pattern: struct some_data *data = bpf_ringbuf_reserve(&ringbuf, sizeof(struct some_data, 0)); if (!data) return; bpf_map_lookup_elem(&another_map, &data->some_field); bpf_ringbuf_submit(data); Currently the verifier does not consider bpf_ringbuf_reserve's PTR_TO_MEM | MEM_ALLOC ret type a valid key input to bpf_map_lookup_elem. Since PTR_TO_MEM is by definition a valid region of memory, it is safe to use it as a key for lookups. Signed-off-by: Dave Marchevsky Acked-by: Yonghong Song --- v2->v3: lore.kernel.org/bpf/20220914123600.927632-1-davemarchevsky@fb.com * Add Yonghong ack, rebase v1->v2: lore.kernel.org/bpf/20220912101106.2765921-1-davemarchevsky@fb.com * Move test changes into separate patch - patch 2 in this series. (Kumar, Yonghong). That patch's changelog enumerates specific changes from v1 * Remove PTR_TO_MEM addition from this patch - patch 1 (Yonghong) * I don't have a usecase for PTR_TO_MEM w/o MEM_ALLOC * Add "if (!data)" error check to example pattern in this patch (Yonghong) * Remove patch 2 from v1's series, which removed map_key_value_types as it was more-or-less duplicate of mem_types * Now that PTR_TO_MEM isn't added here, more differences between map_key_value_types and mem_types, and no usecase for PTR_TO_BUF, so drop for now. kernel/bpf/verifier.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 6f6d2d511c06..97351ae3e7a7 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -5641,6 +5641,7 @@ static const struct bpf_reg_types map_key_value_types = { PTR_TO_PACKET_META, PTR_TO_MAP_KEY, PTR_TO_MAP_VALUE, + PTR_TO_MEM | MEM_ALLOC, }, };