Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp192484rwr; Wed, 19 Apr 2023 20:30:13 -0700 (PDT) X-Google-Smtp-Source: AKy350YQcPemp5MYT6QrSUdLoEanNnNfo3fTZ7C0rEwJ0f3mX26FGgD7xz1jzaY86y5hmbDDPaxc X-Received: by 2002:a17:90b:1643:b0:247:6be7:8cc0 with SMTP id il3-20020a17090b164300b002476be78cc0mr180430pjb.35.1681961413556; Wed, 19 Apr 2023 20:30:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681961413; cv=none; d=google.com; s=arc-20160816; b=aMQ/RgugbPsfgzQ/Uzdg19xW9vksPrtxtAfekAeRW46YuKLV4n2t4lNFABdFy6KMA5 x3f41/LA7LDhY1xh0P3n79hDQs6dBshBo5sKmWl/feZYnCn3rD3wzdoTZmQ8Uf3OgL3m gDZqO6wtBj2/mC6l4+KCeU0LVMclnygNlBV9AQo60YHOcFvm5e42kHu0/vl/6ZnA7jpZ gDpVQHaaaulKRKE+v8xL1/FLlzbinr3AsWQvmFde5acVLRYMWb/WPYTlgRWioR8Cf0zU +wfRBuYWvd4Rs5iHZrLv5FD/BiKkzhCDUh9iQRhZf0UaiJQxqxzfBP09GwNs1s+sAIDb ugyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hr7bhkX+Epn2YWYx/+oT337obKjgENzwcgRHzhBp9VI=; b=0TcRozb1+/mq4ZRQIpJVBdksr22cWMQ5DKLLlTZTGcSXLzCY14ZBZweTvtSok2ZWSS +q6PWItfwZiEXZKW5AfjTY+Lmz+4TXLangibJGi7aaHLDbSWejYCTWCd6ezGSqed747W bfmiVBGZdjsh+oG8UX5EIqe6bGtWY0gh+mMl1iWP7Urv3OIVNtZS3mplfifkXLoi9Dt0 UbnHYuEuo5f5kJC9m7O04Jz8xTrNpn3LX7P2BD6PAdf7hCaQLD/uXWvv2aFWJ+hRIS7L gKwQn0xhfxqoDo2HAIe/H7CKpfKSxJ5efEe3zX2Z2wOgDv3SeZbciIGWQ01jm/MFoNdz j3Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=EbJ7DiX0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b7-20020a170902d50700b001a6717fe413si646153plg.271.2023.04.19.20.30.01; Wed, 19 Apr 2023 20:30:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=EbJ7DiX0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233763AbjDTD22 (ORCPT + 99 others); Wed, 19 Apr 2023 23:28:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233502AbjDTD2X (ORCPT ); Wed, 19 Apr 2023 23:28:23 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED6084208 for ; Wed, 19 Apr 2023 20:27:56 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-63b4e5fdb1eso714940b3a.1 for ; Wed, 19 Apr 2023 20:27:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1681961276; x=1684553276; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hr7bhkX+Epn2YWYx/+oT337obKjgENzwcgRHzhBp9VI=; b=EbJ7DiX0KNLClu6JNpZIDUdsu5ZAfzUcUtofGd3c7gYYeF16zc/59GXJ+AutZPz5w3 1ifFTsK5hJK7jS8Yuwo7Jpyx5xPPQBukFkmUdFtOl7Q+AjoYuvx5dbhYnTTITWFdLbT0 0yQKRpLKV/NLt/a9TXPz/ywKmiu4fth5/3NewCfewonuQbTDHwV12xSpaKQu3zXBdLTK Wkanbypedh5FCjD5x9rM26Np8iyWJ5A6WTwsT0eUl7SY1+Mb/AXTqtug1T3xcMgQl0nK yW1wBdq39B32F1H77/uS5PhpH+H1TGtEQ217Ncm+uuavogm6WqfJlu1T+jxqmG4+Bqhw b38A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681961276; x=1684553276; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hr7bhkX+Epn2YWYx/+oT337obKjgENzwcgRHzhBp9VI=; b=L4J0UDgrKXJKtxVkRccr6EUHXRgxJ7HSYBI7KBRZ73XchgrfeXD5UspUuYRZ4VSqdl umAIDLXm7dr63IFQK7D5+xotiDVSkM4BmtvXV4xJdPpd2VNuiIguLcI4idGFhVUUpTZK BfXHs/iE2HObm8ZDaa7J3FFyYvpjMaUatBdvgw4zxV2EBHNwmKb14AwoKsJLUv046rTr c//Ujh3URBYdAiO9kT/F/yTTN9gufl3H7xVQNTfmWOwY9d1wzlWywngqPJTiWTQhG1xE TwhoQSCmNtngLfmyGqPIGwOj65LFaujO0GbOBKQRGENZk14NLlv8MgrAJxzBFTD/ywfd vmzQ== X-Gm-Message-State: AAQBX9fo3civ4lfRN6G+jxaERMGTANEsdDbdWm2IgNw5pctaIBjZDgMI to9FSDt+OosPp9DJz1nO81WPDA== X-Received: by 2002:a05:6a00:189c:b0:626:2984:8a76 with SMTP id x28-20020a056a00189c00b0062629848a76mr7091693pfh.34.1681961276413; Wed, 19 Apr 2023 20:27:56 -0700 (PDT) Received: from C02F52LSML85.bytedance.net ([139.177.225.254]) by smtp.gmail.com with ESMTPSA id z15-20020a655a4f000000b00517abaac366sm115231pgs.74.2023.04.19.20.27.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 20:27:56 -0700 (PDT) From: Feng zhou To: martin.lau@linux.dev, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mykolal@fb.com, shuah@kernel.org Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, yangzhenze@bytedance.com, wangdongdong.6@bytedance.com, zhouchengming@bytedance.com, zhoufeng.zf@bytedance.com Subject: [PATCH bpf-next v2 1/2] bpf: support access variable length array of integer type Date: Thu, 20 Apr 2023 11:27:34 +0800 Message-Id: <20230420032735.27760-2-zhoufeng.zf@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20230420032735.27760-1-zhoufeng.zf@bytedance.com> References: <20230420032735.27760-1-zhoufeng.zf@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Feng Zhou After this commit: bpf: Support variable length array in tracing programs (9c5f8a1008a1) Trace programs can access variable length array, but for structure type. This patch adds support for integer type. Example: Hook load_balance struct sched_domain { ... unsigned long span[]; } The access: sd->span[0]. Co-developed-by: Chengming Zhou Signed-off-by: Chengming Zhou Signed-off-by: Feng Zhou --- kernel/bpf/btf.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 027f9f8a3551..a0887ee44e89 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -6157,11 +6157,13 @@ static int btf_struct_walk(struct bpf_verifier_log *log, const struct btf *btf, if (off < moff) goto error; - /* Only allow structure for now, can be relaxed for - * other types later. - */ + /* allow structure and integer */ t = btf_type_skip_modifiers(btf, array_elem->type, NULL); + + if (btf_type_is_int(t)) + return WALK_SCALAR; + if (!btf_type_is_struct(t)) goto error; -- 2.20.1