From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 940BCC48BC3 for ; Tue, 20 Feb 2024 17:18:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Nt6L1vIx0n0S0Xfyb8hO6M2oSp4gJq0/Hm7tDfX36NY=; b=BJ6xZbBdNYWoAq B5Fku3ZqEi+aV7XAIzppT5/PW/cuN7IlnpNuZEJuhNvCFPtLHDl593a9EmJM7jfvKhxILEpDlQ4/N dWqomQEvZWdoZeOp/DKZ1NtDYZ0k20wFTbdQaqzaB8m5ThRK5z7XUzvkVvD0t56bcd/8ta4HYosnT 1OzDeQ0qPtbR6GsiseYjIwkkcQtjR1Ec86QCaa3DyrL+LuKy+tpvZ8UScT7ZPPMhrn7ppEDqCv1+S rcUoKVkalWnEmNxQfIByYqU54G8y1NnkEQERkjXb4rW/+/fBF/rWv6PAeNT/J/xJTXC4B+e5r1NbH AeLcjEzKUslMSWbF/o4w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rcTlX-0000000Fbir-2wqV; Tue, 20 Feb 2024 17:18:47 +0000 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rcTlV-0000000Fbh6-0a2P for linux-arm-kernel@lists.infradead.org; Tue, 20 Feb 2024 17:18:46 +0000 Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-563f675be29so5187233a12.0 for ; Tue, 20 Feb 2024 09:18:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708449523; x=1709054323; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:from:to:cc:subject:date:message-id:reply-to; bh=2jsimXL4CWxMWFytJ0GOuQvmJcBH3su7G6flKHH6vaI=; b=JMboYHkWrIHJmDXb6JVGnzyDNpPBX/LnY282QxzkfkU898RPpiz/nLKk1YrYz2rmbU HhkOniBK+/LRgSwB+DRyI8kDCGSZfGofPIa0rBjq+91qWK+IkN7L+6/RJrOLRKrnwWN2 xeLc/vX6k2+yKCFcMiecsItiCfAGYADbGD/GZJHYVyn1UR1OjBiNJ4lpqZil2GTzzZty BXuLiyGZKB1qt33wVRPE/N0dWYiqrfcG4Pogc7A4HvBPgAs4eWfS9+GxxPnywFLRBTeu XycG04/l1y/a77e016kB1OzdE6/XZ96VHkjDEMpsWSpAaft6S93CocJDd+mfXIfj+5Cy UO3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708449523; x=1709054323; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=2jsimXL4CWxMWFytJ0GOuQvmJcBH3su7G6flKHH6vaI=; b=r7PQtEr2MisPcWbdVg+E/2caSUbudkAMcqMtNcTJ7geRInIg17CARzOXVUUXKXChii 7Qa/ea7mRJxSZJpmGiTZbwRiEDc2VgnstH9NZ7UMWV+q2vwAKA+lX80jRksE6HR+Uh7W AVeWUltoX6g207wxRfVlkhtV6L0t8tKNXU8v8O0LOPlqRrbyYLT5Sku2vfp3v9nq7pwN AiEUfMLW9nq7vvoTnLinjWTX/+7JZsMf9LmzQWvb4X8MNwkh9X7BQ4shtkwS4puNiDdd RVKt9Gq2hXDQ0wCM8Keyi8XeTFS9d+ILIJZARdeBaSym2aH3lc93PkeFYojhqIH46rUR ak5w== X-Forwarded-Encrypted: i=1; AJvYcCWBc3w0wrc7Rwn4yGfkDlU2m75Q21G72l5wiDOy2iZjE9q7OHPk9Fc0P5kQSNnIUJ6MNn2kaZPFM/Ef39FkJs7QFjDMWM0usP4eu81qt/l+Fw8NGy8= X-Gm-Message-State: AOJu0Yz9Xk9Lob4DFrGV8LDUb5xPz0CvdwG6nGHpcdZ7jFR6AvYkMXdk M+bFnqMdoQQXJik1jZkjLM6JxZopYWr45Y6rlM++6l8U71ycrpEa X-Google-Smtp-Source: AGHT+IHc0pN9KHkKeb7luanourVgNNVzQPzVIAPQ4poYAK/bHeBaBBTbjvPtzX2mIiyI/iKaLuo4xQ== X-Received: by 2002:aa7:db49:0:b0:564:a76b:aa55 with SMTP id n9-20020aa7db49000000b00564a76baa55mr2426459edt.12.1708449523138; Tue, 20 Feb 2024 09:18:43 -0800 (PST) Received: from krava ([83.240.60.70]) by smtp.gmail.com with ESMTPSA id ew14-20020a056402538e00b005602346c3f5sm3823732edb.79.2024.02.20.09.18.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 09:18:42 -0800 (PST) From: Jiri Olsa X-Google-Original-From: Jiri Olsa Date: Tue, 20 Feb 2024 18:18:40 +0100 To: Menglong Dong Cc: andrii@kernel.org, ast@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, mykolal@fb.com, shuah@kernel.org, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, thinker.li@gmail.com, zhoufeng.zf@bytedance.com, davemarchevsky@fb.com, dxu@dxuuu.xyz, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH bpf-next 1/5] bpf: tracing: add support to record and check the accessed args Message-ID: References: <20240220035105.34626-1-dongmenglong.8@bytedance.com> <20240220035105.34626-2-dongmenglong.8@bytedance.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240220035105.34626-2-dongmenglong.8@bytedance.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240220_091845_215224_B8817326 X-CRM114-Status: GOOD ( 23.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Feb 20, 2024 at 11:51:01AM +0800, Menglong Dong wrote: SNIP > +static int get_ctx_arg_idx_aligned(struct btf *btf, const struct btf_type *t, > + int off) > +{ > + const struct btf_param *args; > + u32 offset = 0, nr_args; > + int i; > + > + nr_args = btf_type_vlen(t); > + args = (const struct btf_param *)(t + 1); > + for (i = 0; i < nr_args; i++) { > + if (offset == off) > + return i; > + > + t = btf_type_skip_modifiers(btf, args[i].type, NULL); > + offset += btf_type_is_ptr(t) ? 8 : roundup(t->size, 8); > + if (offset > off) > + return -1; > + } > + return -1; > +} > + > +/* This function is similar to btf_check_func_type_match(), except that it > + * only compare some function args of the function prototype t1 and t2. > + */ could we reuse btf_check_func_type_match instead? perhaps just adding extra argument with arguments bitmap to it? jirka > +int btf_check_func_part_match(struct btf *btf1, const struct btf_type *func1, > + struct btf *btf2, const struct btf_type *func2, > + u64 func_args) > +{ > + const struct btf_param *args1, *args2; > + u32 nargs1, i, offset = 0; > + const char *s1, *s2; > + > + if (!btf_type_is_func_proto(func1) || !btf_type_is_func_proto(func2)) > + return -EINVAL; > + > + args1 = (const struct btf_param *)(func1 + 1); > + args2 = (const struct btf_param *)(func2 + 1); > + nargs1 = btf_type_vlen(func1); > + > + for (i = 0; i <= nargs1; i++) { > + const struct btf_type *t1, *t2; > + > + if (!(func_args & (1 << i))) > + goto next; > + > + if (i < nargs1) { > + int t2_index; > + > + /* get the index of the arg corresponding to args1[i] > + * by the offset. > + */ > + t2_index = get_ctx_arg_idx_aligned(btf2, func2, > + offset); > + if (t2_index < 0) > + return -EINVAL; > + > + t1 = btf_type_skip_modifiers(btf1, args1[i].type, NULL); > + t2 = btf_type_skip_modifiers(btf2, args2[t2_index].type, > + NULL); > + } else { > + /* i == nargs1, this is the index of return value of t1 */ > + if (get_ctx_arg_total_size(btf1, func1) != > + get_ctx_arg_total_size(btf2, func2)) > + return -EINVAL; > + > + /* check the return type of t1 and t2 */ > + t1 = btf_type_skip_modifiers(btf1, func1->type, NULL); > + t2 = btf_type_skip_modifiers(btf2, func2->type, NULL); > + } > + > + if (t1->info != t2->info || > + (btf_type_has_size(t1) && t1->size != t2->size)) > + return -EINVAL; > + if (btf_type_is_int(t1) || btf_is_any_enum(t1)) > + goto next; > + > + if (btf_type_is_struct(t1)) > + goto on_struct; > + > + if (!btf_type_is_ptr(t1)) > + return -EINVAL; > + > + t1 = btf_type_skip_modifiers(btf1, t1->type, NULL); > + t2 = btf_type_skip_modifiers(btf2, t2->type, NULL); > + if (!btf_type_is_struct(t1) || !btf_type_is_struct(t2)) > + return -EINVAL; > + > +on_struct: > + s1 = btf_name_by_offset(btf1, t1->name_off); > + s2 = btf_name_by_offset(btf2, t2->name_off); > + if (strcmp(s1, s2)) > + return -EINVAL; > +next: > + if (i < nargs1) { > + t1 = btf_type_skip_modifiers(btf1, args1[i].type, NULL); > + offset += btf_type_is_ptr(t1) ? 8 : roundup(t1->size, 8); > + } > + } > + > + return 0; > +} > + > static bool btf_is_dynptr_ptr(const struct btf *btf, const struct btf_type *t) > { > const char *name; > -- > 2.39.2 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel