From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 944F345038;
	Mon, 28 Jul 2025 04:13:00 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.196
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1753675982; cv=none; b=A2ICGmJt1HoLikwUfcDqZ25ijyfAkpUzKhmGtKgYX6LQr+Doj6g+vvYo4rgP4hl7UN2n2vMf8yNUeHmjJm/kOco3nZ6belQiCidCuIJJe43q1maCglukaYG8zVErU4crAxUX/LJ4pUf+tiHRKHermidcCw71cvKt8zkxlKpqu98=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1753675982; c=relaxed/simple;
	bh=P/PichhOLi2hHPK2QFhXjEtN6Z2+SvejzH2jq8CIUao=;
	h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=E1ZoTvTZTcMfMw+XSAP6nGq8OBMvmKYSV3nRgpglFepeLSh3lgEoBPhdVJgAuIvzwfbBus2WLgn+Tp/XRMQlPIdFduCuh8NIgkktUTUnUvonz5MXKU3kXsTCntCjPvS/aGCs3gbsghsdzd1IaLLBkTdEEArm+eFzKzl/UdI5uzI=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BhTtnYjm; arc=none smtp.client-ip=209.85.215.196
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BhTtnYjm"
Received: by mail-pg1-f196.google.com with SMTP id 41be03b00d2f7-b34ab678931so3047504a12.0;
        Sun, 27 Jul 2025 21:13:00 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20230601; t=1753675980; x=1754280780; darn=vger.kernel.org;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:from:to:cc:subject:date:message-id:reply-to;
        bh=49wuBF4kwjRWDzJQK9NYqp+wEnf5GToY6o8GT5CE1sk=;
        b=BhTtnYjmgdciSrzKj3t9dEbTXrv3Koahe5DryPexTWmnvbqmdPsJ8bYs94AnS51qRl
         1r1JrW6KsYs9c0YQpMdVHF3w0wdMpGbPRXHZC3bFHmme3HZLonnP/PlzeI/KMWiktPfQ
         hPxmHGLydd0EH5W0Lwpvw7Wn+I2TNf7hspTrofwK7OwD4AK4dKsa50Yz4Hu6E4dNVd6M
         lVPusKX5pYoD8rGu8c+MeyfuXsMU/QXoHC2XXPgS5TV0iVD1FDZUoK++/Zb+CketcWYA
         Ro8Uq7o6GphtI+ZLUKx1zClaM/eYZz3sYaLwnCWpLWQTroQzX5JVxNRvPivlpOJDQOvc
         448w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1753675980; x=1754280780;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:x-gm-message-state:from:to:cc:subject:date:message-id
         :reply-to;
        bh=49wuBF4kwjRWDzJQK9NYqp+wEnf5GToY6o8GT5CE1sk=;
        b=iG2gITRaA3WuxT265HJadf7eM0hLs7Fix0fI3wzuvcB7lq9fsdF2aoYeIB5tHuf6IK
         dF1NyZ23GWQMwiw/EQcTybFdF0rpmQkEN7677DkxMJx0RvSxeYRsaDCDBGbPAqb4ipZw
         6XlphpcSRK5tDyX4R13EhVFb9JRVJCGBdjrmRO7Ong0LhfUtmBZwciBFEJLhaJ1UBc0s
         JA5/p4aw6wXfScyhnMTueKXSpMR8Y1qVWKYd4edw8q509rzskF/CexywmTWoxV0sCeN/
         C6rsSuBrZyF33DarHzSnSzR/y9qqa8HXcPI/12nkFhEZnO+NYWfCGopwYr/fWBZexLpm
         NV3g==
X-Forwarded-Encrypted: i=1; AJvYcCUvWJDVoZALko8xiwa7ZT4j5IsoTRly4QVgFmNiiILmYhTooO4b0UNLm31Jv6COdXEcbtNsVq3q1Ob2uQzc@vger.kernel.org, AJvYcCWyAIzITjmOOwux0c9i98sQcro5YM88dmxqHXAO3ZfltfkculJieIkDqTlBnvgKIiSZCruhrGLxQlPEWgw9Y7FkcSPX@vger.kernel.org, AJvYcCXvKxP7jlR1LAb3tXohwJKpDEcum1zhpHVNsZYcXO/R9uopu71kfgj0aNaAvlT0rboIaZo=@vger.kernel.org
X-Gm-Message-State: AOJu0YxyIopCNlKbrHqFT6FIq1U1gGrT/3rHUlnXNe5NBqqSiu8yOVWn
	JS7VENU11JWh0svZTu+xDlHLViX8uZYYCqErkOiF/lt/kwP6JGO5snkA
X-Gm-Gg: ASbGncu+DyBtHMA+CTkfzcj3hQ8F0duMmPqa0woB7JKNwLuafMtRQYrURX8uhwRqTTU
	nSL1EJh2/+KKdc0ou3IyUqzy7q1u37XgSonSOUZ6G71oXwH5g7tBQ4nWjJdfv65FF72dQWAt8T4
	DJS1PFZEQXOETEciakzS8dPh1q5coDm4nEW8xxsy00s1NmwPJh6gImd2ETI/QmwZewLtVYv4CYw
	LruEwXmvsDytWz2y5Perl7siqFej3cv64vJYnWWW51dZ9xImzseYVD9tlLpHbUxY4eXvW5hCW9i
	uFlDNsJnvMpQmx/W3OS70vykDeRI/3Zk5NcZlQtFdm23/I/aoWIk5WIh0MLqkarqgQ0aye6NHd4
	32KHKL6ZxNTa/368DIBwNFNhlffQisA==
X-Google-Smtp-Source: AGHT+IFmntsjJe2mTLVOva2YkqW63Lp/8vbsMQhSFzuszLmldvG94Z2uQnwUps32cHU7XEOlgUAW0g==
X-Received: by 2002:a17:902:c94f:b0:23f:f6e0:b3c7 with SMTP id d9443c01a7336-23ff6e0b6a4mr83657805ad.45.1753675979548;
        Sun, 27 Jul 2025 21:12:59 -0700 (PDT)
Received: from 7950hx ([43.129.244.20])
        by smtp.gmail.com with ESMTPSA id d9443c01a7336-24008efc073sm20599175ad.58.2025.07.27.21.12.56
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Sun, 27 Jul 2025 21:12:59 -0700 (PDT)
From: Menglong Dong <menglong8.dong@gmail.com>
X-Google-Original-From: Menglong Dong <dongml2@chinatelecom.cn>
To: alexei.starovoitov@gmail.com,
	mhiramat@kernel.org
Cc: rostedt@goodmis.org,
	mathieu.desnoyers@efficios.com,
	hca@linux.ibm.com,
	revest@chromium.org,
	linux-kernel@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org,
	bpf@vger.kernel.org
Subject: [PATCH bpf-next 0/4] fprobe: use rhashtable for fprobe_ip_table
Date: Mon, 28 Jul 2025 12:12:47 +0800
Message-ID: <20250728041252.441040-1-dongml2@chinatelecom.cn>
X-Mailer: git-send-email 2.50.1
Precedence: bulk
X-Mailing-List: linux-trace-kernel@vger.kernel.org
List-Id: <linux-trace-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-trace-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-trace-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

For now, the budget of the hash table that is used for fprobe_ip_table is
fixed, which is 256, and can cause huge overhead when the hooked functions
is a huge quantity.

In this series, we use rhashtable for fprobe_ip_table to reduce the
overhead.

Meanwhile, we also add the benchmark testcase "kprobe-multi-all", which
will hook all the kernel functions during the testing. Before this series,
the performance is:
  usermode-count :  875.380 Â± 0.366M/s 
  kernel-count   :  435.924 Â± 0.461M/s 
  syscall-count  :   31.004 Â± 0.017M/s 
  fentry         :  134.076 Â± 1.752M/s 
  fexit          :   68.319 Â± 0.055M/s 
  fmodret        :   71.530 Â± 0.032M/s 
  rawtp          :  202.751 Â± 0.138M/s 
  tp             :   79.562 Â± 0.084M/s 
  kprobe         :   55.587 Â± 0.028M/s 
  kprobe-multi   :   56.481 Â± 0.043M/s 
  kprobe-multi-all:    6.283 Â± 0.005M/s << look this
  kretprobe      :   22.378 Â± 0.028M/s 
  kretprobe-multi:   28.205 Â± 0.025M/s

With this series, the performance is:
  usermode-count :  897.083 Â± 5.347M/s 
  kernel-count   :  431.638 Â± 1.781M/s 
  syscall-count  :   30.807 Â± 0.057M/s 
  fentry         :  134.803 Â± 1.045M/s 
  fexit          :   68.763 Â± 0.018M/s 
  fmodret        :   71.444 Â± 0.052M/s 
  rawtp          :  202.344 Â± 0.149M/s 
  tp             :   79.644 Â± 0.376M/s 
  kprobe         :   55.480 Â± 0.108M/s 
  kprobe-multi   :   57.302 Â± 0.119M/s 
  kprobe-multi-all:   57.855 Â± 0.144M/s << look this
  kretprobe      :   22.265 Â± 0.023M/s 
  kretprobe-multi:   27.740 Â± 0.023M/s

The benchmark of "kprobe-multi-all" increase from 6.283M/s to 57.855M/s.

Menglong Dong (4):
  fprobe: use rhashtable
  selftests/bpf: move get_ksyms and get_addrs to trace_helpers.c
  selftests/bpf: add benchmark testing for kprobe-multi-all
  selftests/bpf: skip recursive functions for kprobe_multi

 include/linux/fprobe.h                        |   2 +-
 kernel/trace/fprobe.c                         | 144 ++++++-----
 tools/testing/selftests/bpf/bench.c           |   2 +
 .../selftests/bpf/benchs/bench_trigger.c      |  30 +++
 .../selftests/bpf/benchs/run_bench_trigger.sh |   2 +-
 .../bpf/prog_tests/kprobe_multi_test.c        | 220 +----------------
 tools/testing/selftests/bpf/trace_helpers.c   | 230 ++++++++++++++++++
 tools/testing/selftests/bpf/trace_helpers.h   |   3 +
 8 files changed, 351 insertions(+), 282 deletions(-)

-- 
2.50.1


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE5EE217716;
	Mon, 28 Jul 2025 04:13:03 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.194
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1753675985; cv=none; b=QmfVANw9pxJEZYt/qXmaY7AclQHPhAY63bM64SeE3HFPb4tp0f78MgE61dlm7fsfLE0ZiivYQi4asGdx10sCAuy1jFuu7musVtbnwY8/mhupPvCfiyUOnUa/68+kOacp0CzBGxs2JIzoGJDhXmQcyc7osQ+Kor3KUVGJf35cIXU=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1753675985; c=relaxed/simple;
	bh=/Xj3sOaOCNeqUFX5P0Wp28TH0ulruXkgsD0ebXMyvfk=;
	h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
	 MIME-Version; b=Frgj+n46SiRnzjNjZ5LlP9Ff2oef8r6sqedvRpDGvNwyRt6FXxeJ6JCA7GpTrezG/9jsVM2Qdpqnd1l7KFYIguKs/9H2KFbGrQKtprlhSaICFPHmSh0p047Nb5esCJJFtkgHdH47K0WuPyk9S9PlnOGX/0EqzeyFLWoeQlWnG/Y=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NwAic8/I; arc=none smtp.client-ip=209.85.214.194
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NwAic8/I"
Received: by mail-pl1-f194.google.com with SMTP id d9443c01a7336-23636167afeso33922125ad.3;
        Sun, 27 Jul 2025 21:13:03 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20230601; t=1753675983; x=1754280783; darn=vger.kernel.org;
        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=4dDuLpi2XdML7z9q3X9SSRyeitTIxFEVOUJtDB7FRXM=;
        b=NwAic8/I645j9PJw6OAAvOHA19DCwloI38xMt5YyiqBcJfJbSxoyiCZfr1XMnt+S6Z
         L/qT8ZTrC032UaoAk+f6u8K7M7sW41fnkL2rkS2wuuUSuKqfqFz3HMIvmv+ZEeHi+eoD
         izaAddtrYVPjApKY9CNb0BpyQo7CAuQq/uOnni39Mw7tFk5IVfuXpYZxS09SQ+RcRe/p
         JCSApWH3Hy+9ALbUzyes/yXpVVjJAVNXwi0e13rIFhCTR8Fal2SabRroIhyR3DwfgY4y
         W9xxunPKbfHVFZHhIqKwu/HOT/+tSfNK5rZakxcaGaooVFDexRxHTpvZFWXWQcEsUcne
         J2uA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1753675983; x=1754280783;
        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=4dDuLpi2XdML7z9q3X9SSRyeitTIxFEVOUJtDB7FRXM=;
        b=EfDl2lP9Q+/89V8IXlwMZU9eWeYDkAyIn4EYMubGFFGov8uJrtyCv8qUyz2x/XYPse
         iU7QjMRcRA+Wa4kJVUc2luHBKw3TN+SOcNihk9+BIIK0egxAmwMkaS3m8Wxrg0VDyEpA
         54Mr06w6g5Lf5BLQ/6oEQwYYR8S1gGwfLlBZWgaRIpY5hr0KD9sqSnI0iL22uGXE3XeC
         acezXm16q+zL2aUogkTZKnMsuxBcpkOpQgH2X2Iqw8jQjk7fSD1iy9nbY2YMg0H9viZn
         zNgkZSqybnbkJR7F2vLxAE7C+N9eOXTMmohv7/RlQA/orhryeD7SZjlVL3XwsBKFo3g2
         qHrA==
X-Forwarded-Encrypted: i=1; AJvYcCVM2D1Ff7xfv8qegH12RBqE7nw39TkfwElgmLNx+yI90zGw0oU0vC5i5t2FGiG4il3NaQA=@vger.kernel.org, AJvYcCVQFRus1Osfnn82fuKorUR3nqo7V8bRRZkgBfOXeyEYd0402d+Sp1TiQSs088UAfJ2KxNlnAvGLc3xKQsWo@vger.kernel.org, AJvYcCXpJt79mkKKMbCEPQ/Z5HZ7YAoNkM/7yOqQhTyqBZBE5JET3tfp4qgc1HVeQV9+dv9xslW7K7CU4+Q8x1nefOqrk7NU@vger.kernel.org
X-Gm-Message-State: AOJu0YxT7YZg/yIswTyAVCK4m3Ry/fnSUutTwLk31m6uA5E9BUKe24rg
	xysTK8qwZuHoK+M/4ZMfS0nLbnfyZdhhXqOTFx7/ukJeyN73kmLJpud6
X-Gm-Gg: ASbGncuUMlhA3haKPxy8zHDMptXGbEa/ky/xCs2C9MMm4XHAugpi13rYCNjRJzQbZme
	ybGeS+SitbEOiyU3WH19WfoijKgRkg8nco6wCP9CQHUIC+g82EbKZTKVSzhRy+ulXdiJ3LzVtYO
	vfFqsEQ7qbNkgDmqYlOkYgkNKf+YHF7Gf/0ANyU6d/IaE2/41hjmmqX/B1IPI59Lw/X0TXILsI6
	TeC8EisPphRb5BPTWIaoHRmuFo/EI9inu2DQCBqNEs7+1vSsWnJ1+oAHrcvMTtcJv9/jNMGYNi/
	10yUXAKneh79Bocw/uDoemecauAcdOl7KhLnTzjkReGyKNlfmaQir6dEHgr4FMxNhLg+aqizBx2
	aU2NO398xd1MLWP9eMdI=
X-Google-Smtp-Source: AGHT+IGX01LFBZYPPzjW+WAT4Mc3ZMKmNo/fMqJ2YCdk7j9r8w1TpTyxdQeiS3f8wUgLHP7lKowHXw==
X-Received: by 2002:a17:903:1c2:b0:234:ef42:5d69 with SMTP id d9443c01a7336-23fb30995c3mr161420655ad.13.1753675983055;
        Sun, 27 Jul 2025 21:13:03 -0700 (PDT)
Received: from 7950hx ([43.129.244.20])
        by smtp.gmail.com with ESMTPSA id d9443c01a7336-24008efc073sm20599175ad.58.2025.07.27.21.12.59
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Sun, 27 Jul 2025 21:13:02 -0700 (PDT)
From: Menglong Dong <menglong8.dong@gmail.com>
X-Google-Original-From: Menglong Dong <dongml2@chinatelecom.cn>
To: alexei.starovoitov@gmail.com,
	mhiramat@kernel.org
Cc: rostedt@goodmis.org,
	mathieu.desnoyers@efficios.com,
	hca@linux.ibm.com,
	revest@chromium.org,
	linux-kernel@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org,
	bpf@vger.kernel.org
Subject: [PATCH bpf-next 1/4] fprobe: use rhashtable
Date: Mon, 28 Jul 2025 12:12:48 +0800
Message-ID: <20250728041252.441040-2-dongml2@chinatelecom.cn>
X-Mailer: git-send-email 2.50.1
In-Reply-To: <20250728041252.441040-1-dongml2@chinatelecom.cn>
References: <20250728041252.441040-1-dongml2@chinatelecom.cn>
Precedence: bulk
X-Mailing-List: linux-trace-kernel@vger.kernel.org
List-Id: <linux-trace-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-trace-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-trace-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

For now, all the kernel functions who are hooked by the fprobe will be
added to the hash table "fprobe_ip_table". The key of it is the function
address, and the value of it is "struct fprobe_hlist_node".

The budget of the hash table is FPROBE_IP_TABLE_SIZE, which is 256. And
this means the overhead of the hash table lookup will grow linearly if
the count of the functions in the fprobe more than 256. When we try to
hook all the kernel functions, the overhead will be huge.

Therefore, replace the hash table with rhashtable to reduce the overhead.

Signed-off-by: Menglong Dong <dongml2@chinatelecom.cn>
---
 include/linux/fprobe.h |   2 +-
 kernel/trace/fprobe.c  | 144 +++++++++++++++++++++++------------------
 2 files changed, 82 insertions(+), 64 deletions(-)

diff --git a/include/linux/fprobe.h b/include/linux/fprobe.h
index 702099f08929..0c9b239f5485 100644
--- a/include/linux/fprobe.h
+++ b/include/linux/fprobe.h
@@ -26,7 +26,7 @@ typedef void (*fprobe_exit_cb)(struct fprobe *fp, unsigned long entry_ip,
  * @fp: The fprobe which owns this.
  */
 struct fprobe_hlist_node {
-	struct hlist_node	hlist;
+	struct rhash_head	hlist;
 	unsigned long		addr;
 	struct fprobe		*fp;
 };
diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
index ba7ff14f5339..b3e16303fc6a 100644
--- a/kernel/trace/fprobe.c
+++ b/kernel/trace/fprobe.c
@@ -12,6 +12,7 @@
 #include <linux/mutex.h>
 #include <linux/slab.h>
 #include <linux/sort.h>
+#include <linux/rhashtable.h>
 
 #include <asm/fprobe.h>
 
@@ -41,47 +42,47 @@
  *  - RCU hlist traversal under disabling preempt
  */
 static struct hlist_head fprobe_table[FPROBE_TABLE_SIZE];
-static struct hlist_head fprobe_ip_table[FPROBE_IP_TABLE_SIZE];
+static struct rhashtable fprobe_ip_table;
 static DEFINE_MUTEX(fprobe_mutex);
 
-/*
- * Find first fprobe in the hlist. It will be iterated twice in the entry
- * probe, once for correcting the total required size, the second time is
- * calling back the user handlers.
- * Thus the hlist in the fprobe_table must be sorted and new probe needs to
- * be added *before* the first fprobe.
- */
-static struct fprobe_hlist_node *find_first_fprobe_node(unsigned long ip)
+static u32 fprobe_node_hashfn(const void *data, u32 len, u32 seed)
 {
-	struct fprobe_hlist_node *node;
-	struct hlist_head *head;
+	return hash_ptr(*(unsigned long **)data, 32);
+}
 
-	head = &fprobe_ip_table[hash_ptr((void *)ip, FPROBE_IP_HASH_BITS)];
-	hlist_for_each_entry_rcu(node, head, hlist,
-				 lockdep_is_held(&fprobe_mutex)) {
-		if (node->addr == ip)
-			return node;
-	}
-	return NULL;
+static int fprobe_node_cmp(struct rhashtable_compare_arg *arg,
+			   const void *ptr)
+{
+	unsigned long key = *(unsigned long *)arg->key;
+	const struct fprobe_hlist_node *n = ptr;
+
+	return n->addr != key;
+}
+
+static u32 fprobe_node_obj_hashfn(const void *data, u32 len, u32 seed)
+{
+	const struct fprobe_hlist_node *n = data;
+
+	return hash_ptr((void *)n->addr, 32);
 }
-NOKPROBE_SYMBOL(find_first_fprobe_node);
+
+static const struct rhashtable_params fprobe_rht_params = {
+	.head_offset		= offsetof(struct fprobe_hlist_node, hlist),
+	.key_offset		= offsetof(struct fprobe_hlist_node, addr),
+	.key_len		= sizeof_field(struct fprobe_hlist_node, addr),
+	.hashfn			= fprobe_node_hashfn,
+	.obj_hashfn		= fprobe_node_obj_hashfn,
+	.obj_cmpfn		= fprobe_node_cmp,
+	.automatic_shrinking	= true,
+};
 
 /* Node insertion and deletion requires the fprobe_mutex */
 static void insert_fprobe_node(struct fprobe_hlist_node *node)
 {
-	unsigned long ip = node->addr;
-	struct fprobe_hlist_node *next;
-	struct hlist_head *head;
-
 	lockdep_assert_held(&fprobe_mutex);
 
-	next = find_first_fprobe_node(ip);
-	if (next) {
-		hlist_add_before_rcu(&node->hlist, &next->hlist);
-		return;
-	}
-	head = &fprobe_ip_table[hash_ptr((void *)ip, FPROBE_IP_HASH_BITS)];
-	hlist_add_head_rcu(&node->hlist, head);
+	rhashtable_insert_fast(&fprobe_ip_table, &node->hlist,
+			       fprobe_rht_params);
 }
 
 /* Return true if there are synonims */
@@ -92,9 +93,11 @@ static bool delete_fprobe_node(struct fprobe_hlist_node *node)
 	/* Avoid double deleting */
 	if (READ_ONCE(node->fp) != NULL) {
 		WRITE_ONCE(node->fp, NULL);
-		hlist_del_rcu(&node->hlist);
+		rhashtable_remove_fast(&fprobe_ip_table, &node->hlist,
+				       fprobe_rht_params);
 	}
-	return !!find_first_fprobe_node(node->addr);
+	return !!rhashtable_lookup_fast(&fprobe_ip_table, &node->addr,
+					fprobe_rht_params);
 }
 
 /* Check existence of the fprobe */
@@ -249,25 +252,28 @@ static inline int __fprobe_kprobe_handler(unsigned long ip, unsigned long parent
 static int fprobe_entry(struct ftrace_graph_ent *trace, struct fgraph_ops *gops,
 			struct ftrace_regs *fregs)
 {
-	struct fprobe_hlist_node *node, *first;
+	struct rhash_lock_head __rcu *const *bkt;
+	struct fprobe_hlist_node *node;
 	unsigned long *fgraph_data = NULL;
 	unsigned long func = trace->func;
+	struct bucket_table *tbl;
+	struct rhash_head *head;
 	unsigned long ret_ip;
 	int reserved_words;
 	struct fprobe *fp;
+	unsigned int key;
 	int used, ret;
 
 	if (WARN_ON_ONCE(!fregs))
 		return 0;
 
-	first = node = find_first_fprobe_node(func);
-	if (unlikely(!first))
-		return 0;
-
+	tbl = rht_dereference_rcu(fprobe_ip_table.tbl, &fprobe_ip_table);
+	key = rht_key_hashfn(&fprobe_ip_table, tbl, &func, fprobe_rht_params);
+	bkt = rht_bucket(tbl, key);
 	reserved_words = 0;
-	hlist_for_each_entry_from_rcu(node, hlist) {
+	rht_for_each_entry_rcu_from(node, head, rht_ptr_rcu(bkt), tbl, key, hlist) {
 		if (node->addr != func)
-			break;
+			continue;
 		fp = READ_ONCE(node->fp);
 		if (!fp || !fp->exit_handler)
 			continue;
@@ -278,13 +284,13 @@ static int fprobe_entry(struct ftrace_graph_ent *trace, struct fgraph_ops *gops,
 		reserved_words +=
 			FPROBE_HEADER_SIZE_IN_LONG + SIZE_IN_LONG(fp->entry_data_size);
 	}
-	node = first;
 	if (reserved_words) {
 		fgraph_data = fgraph_reserve_data(gops->idx, reserved_words * sizeof(long));
 		if (unlikely(!fgraph_data)) {
-			hlist_for_each_entry_from_rcu(node, hlist) {
+			rht_for_each_entry_rcu_from(node, head, rht_ptr_rcu(bkt),
+						    tbl, key, hlist) {
 				if (node->addr != func)
-					break;
+					continue;
 				fp = READ_ONCE(node->fp);
 				if (fp && !fprobe_disabled(fp))
 					fp->nmissed++;
@@ -299,12 +305,12 @@ static int fprobe_entry(struct ftrace_graph_ent *trace, struct fgraph_ops *gops,
 	 */
 	ret_ip = ftrace_regs_get_return_address(fregs);
 	used = 0;
-	hlist_for_each_entry_from_rcu(node, hlist) {
+	rht_for_each_entry_rcu_from(node, head, rht_ptr_rcu(bkt), tbl, key, hlist) {
 		int data_size;
 		void *data;
 
 		if (node->addr != func)
-			break;
+			continue;
 		fp = READ_ONCE(node->fp);
 		if (!fp || fprobe_disabled(fp))
 			continue;
@@ -448,25 +454,21 @@ static int fprobe_addr_list_add(struct fprobe_addr_list *alist, unsigned long ad
 	return 0;
 }
 
-static void fprobe_remove_node_in_module(struct module *mod, struct hlist_head *head,
-					struct fprobe_addr_list *alist)
+static void fprobe_remove_node_in_module(struct module *mod, struct fprobe_hlist_node *node,
+					 struct fprobe_addr_list *alist)
 {
-	struct fprobe_hlist_node *node;
 	int ret = 0;
 
-	hlist_for_each_entry_rcu(node, head, hlist,
-				 lockdep_is_held(&fprobe_mutex)) {
-		if (!within_module(node->addr, mod))
-			continue;
-		if (delete_fprobe_node(node))
-			continue;
-		/*
-		 * If failed to update alist, just continue to update hlist.
-		 * Therefore, at list user handler will not hit anymore.
-		 */
-		if (!ret)
-			ret = fprobe_addr_list_add(alist, node->addr);
-	}
+	if (!within_module(node->addr, mod))
+		return;
+	if (delete_fprobe_node(node))
+		return;
+	/*
+	 * If failed to update alist, just continue to update hlist.
+	 * Therefore, at list user handler will not hit anymore.
+	 */
+	if (!ret)
+		ret = fprobe_addr_list_add(alist, node->addr);
 }
 
 /* Handle module unloading to manage fprobe_ip_table. */
@@ -474,8 +476,9 @@ static int fprobe_module_callback(struct notifier_block *nb,
 				  unsigned long val, void *data)
 {
 	struct fprobe_addr_list alist = {.size = FPROBE_IPS_BATCH_INIT};
+	struct fprobe_hlist_node *node;
+	struct rhashtable_iter iter;
 	struct module *mod = data;
-	int i;
 
 	if (val != MODULE_STATE_GOING)
 		return NOTIFY_DONE;
@@ -486,8 +489,16 @@ static int fprobe_module_callback(struct notifier_block *nb,
 		return NOTIFY_DONE;
 
 	mutex_lock(&fprobe_mutex);
-	for (i = 0; i < FPROBE_IP_TABLE_SIZE; i++)
-		fprobe_remove_node_in_module(mod, &fprobe_ip_table[i], &alist);
+	rhashtable_walk_enter(&fprobe_ip_table, &iter);
+	do {
+		rhashtable_walk_start(&iter);
+
+		while ((node = rhashtable_walk_next(&iter)) && !IS_ERR(node))
+			fprobe_remove_node_in_module(mod, node, &alist);
+
+		rhashtable_walk_stop(&iter);
+	} while (node == ERR_PTR(-EAGAIN));
+	rhashtable_walk_exit(&iter);
 
 	if (alist.index < alist.size && alist.index > 0)
 		ftrace_set_filter_ips(&fprobe_graph_ops.ops,
@@ -819,3 +830,10 @@ int unregister_fprobe(struct fprobe *fp)
 	return ret;
 }
 EXPORT_SYMBOL_GPL(unregister_fprobe);
+
+static int __init fprobe_initcall(void)
+{
+	rhashtable_init(&fprobe_ip_table, &fprobe_rht_params);
+	return 0;
+}
+late_initcall(fprobe_initcall);
-- 
2.50.1


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9438B21ABB0;
	Mon, 28 Jul 2025 04:13:07 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.194
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1753675989; cv=none; b=QPq1J8Y5+KNntpJGJVqjPwO6nuneNXMGNQAczAaAUUvz5BAkXAUoHL9Hf2AqQbFEiYyeqs4hBRMNjE9KGqftoZZy43WLesTp6uJbCs2ul9+BXQGYVWV7d2VGTlCigMY1LOyNERiV5ZhehmV0KkplPTjQDDr4hSb8Uy3SFs0PO0k=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1753675989; c=relaxed/simple;
	bh=zudiWkkAlg6yySZkWMGW/IXw6hzgirR0YopZ0oI3JAs=;
	h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
	 MIME-Version; b=HLK+EzJrDTHin/nL7ltwB7rqHGBuSx8NBe4RhlS+iS5LgALFsIKnlcg1aDbxOG9Z4Yyzz9QFz2qLJpNveIUtZLDrdLmCJcEwmbhESrYjYU+T1Rzd8yS/IEUq68TKZWFUaXyhO3WisPaUYDvLLJdEuZ//KCSU3iOhSQpYJw1iVK0=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mNmhiDDA; arc=none smtp.client-ip=209.85.214.194
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mNmhiDDA"
Received: by mail-pl1-f194.google.com with SMTP id d9443c01a7336-234c5b57557so32828955ad.3;
        Sun, 27 Jul 2025 21:13:07 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20230601; t=1753675987; x=1754280787; darn=vger.kernel.org;
        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=y8iwRQl4S0Ri7auKWOImDztrR8W3w7sQvsgC0R12G/0=;
        b=mNmhiDDA+dvuMlAEcr3CChg4hiqGPbwdw4p9vCoZiw977QD2E24lq1d9GkuJ1dekou
         pF6GOGhv2XsKN7wIYbTk1dK9Uf8P8OHWLLWM7nZc4Z1rZeyp2KoA156CT7Uhj1OTLFyD
         zynhVXtGx6/gPQyFHqZ9QLlzssx0nnNxFy17kcTwkwYKvCkGse7xmkolybowzLd67y17
         k20aNrfpKBI8TWt7CAaIVaB1Z+G9ZHBMZtDWR+1jOi2jJdpjLbqNQsYfSFGydtV8pb+C
         rOzWkrzi+hUfhmAIzMT5ot/p0JHQJ6JyBzBtyoVBo6boEcWXkKwufmm2yGOdMxDTKPzI
         yWTA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1753675987; x=1754280787;
        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=y8iwRQl4S0Ri7auKWOImDztrR8W3w7sQvsgC0R12G/0=;
        b=AZo94ALMNfldTNfGDZMYhvwJ+4oH7bskb0UlgjvXJWDsOXQzspF2xKFjAm8FX3uuDp
         qW7oFkXMqh+1/fMpaSVIr4exR8/xmolzaza3+wXZ0gPx9UnqfaMiaNW7y4Kpjf4hAQz3
         uoQObxDAAnGd9SE2IMaP/7hOF9RubyH3l2101wXorBWpfbpYSKqNCyGRaAfKgiYdv63U
         2Pkk4RDrUCfTG0gLu4ZGd/zcWDZIT9v7L+B7cURVbfSgvrjJgCHk4mqw9ftc0KhPbGhe
         DtxAFwgtR9ucGu37/qmq2ShGo6OMceE8gfpadPa5XjWVL8atW1b+57f9u4NaKuTTouwf
         wEYA==
X-Forwarded-Encrypted: i=1; AJvYcCUk5F6sO+FqPfZ9vCoEQ36IQv2KgyjeRKwijPMn/QqSmopR6jQoItPx4UHeA88PzCmRwPU=@vger.kernel.org, AJvYcCV6rBdFKltKleCc3GPHZMfOR/RCzWaB0Pz2UO3h+7s2xbwIHa/W6IVLKy3MwytP0iTkqptPrPwwVEQs/Q5y@vger.kernel.org, AJvYcCVRyKK7nOiT/rSQUfAKtGmBzTc83LPBrjj4N16+6zaXlbBTuaWui5loG8Cq8CyxZoK2+U6friHmeroqD957eGfNjxml@vger.kernel.org
X-Gm-Message-State: AOJu0YwCwm6YZTm3OaNbdHyCps7c8CmBMxVvs1kwMfBRaxcd2KIU0Bvs
	NzN5VUBhxwDy/Bu7qAWDALZKd5tLj4JxPLBeztTy8XKzn+MjEg6dVdEU
X-Gm-Gg: ASbGncvGEnnezg9EUt8Y7njb5bLnKy+g/72C4Zw/UWiYhiOMhogeIRoDrFJoXVsIdJ8
	khJhdAxlu+5uunLSmT/TK4xkTYc2BpkUc5tCMYMInfI05ghM97nw3lIwiSxentZKyiP2giq9Ceb
	/P6uhTp5FxrLfesdCuaYnrFEhnAlr/G2/pR3iu/7cjzNDSaivRyQumRAnsN6f4ZiaO7OSVryFwx
	Hv8IYZnIPKfukEM2TI5PRmg/21f+HIu5H/Yy4WxfjCmK5P5cVnkYw1UA/kdH4hJiiovemQBPZFC
	zzPO0P2FYtVxvt7XNQrXEOilvCWLiWymagfEhOgoTEz4QXc+r6sIKfVZ8M0dOs1X+tfZXziK1zc
	RCRjD4kmhgKIqxfdzvCU=
X-Google-Smtp-Source: AGHT+IGwtqmpSHudD7CUmmpKMgJ9sWb4H32pd44LkaxBtJGu1kz6YvGAo4FC9U1zduDH6tDvyyamoA==
X-Received: by 2002:a17:902:f610:b0:240:14c:c648 with SMTP id d9443c01a7336-240014cc9c4mr53755115ad.25.1753675986561;
        Sun, 27 Jul 2025 21:13:06 -0700 (PDT)
Received: from 7950hx ([43.129.244.20])
        by smtp.gmail.com with ESMTPSA id d9443c01a7336-24008efc073sm20599175ad.58.2025.07.27.21.13.03
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Sun, 27 Jul 2025 21:13:06 -0700 (PDT)
From: Menglong Dong <menglong8.dong@gmail.com>
X-Google-Original-From: Menglong Dong <dongml2@chinatelecom.cn>
To: alexei.starovoitov@gmail.com,
	mhiramat@kernel.org
Cc: rostedt@goodmis.org,
	mathieu.desnoyers@efficios.com,
	hca@linux.ibm.com,
	revest@chromium.org,
	linux-kernel@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org,
	bpf@vger.kernel.org
Subject: [PATCH bpf-next 2/4] selftests/bpf: move get_ksyms and get_addrs to trace_helpers.c
Date: Mon, 28 Jul 2025 12:12:49 +0800
Message-ID: <20250728041252.441040-3-dongml2@chinatelecom.cn>
X-Mailer: git-send-email 2.50.1
In-Reply-To: <20250728041252.441040-1-dongml2@chinatelecom.cn>
References: <20250728041252.441040-1-dongml2@chinatelecom.cn>
Precedence: bulk
X-Mailing-List: linux-trace-kernel@vger.kernel.org
List-Id: <linux-trace-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-trace-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-trace-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

We need to get all the kernel function that can be traced sometimes, so we
move the get_syms() and get_addrs() in kprobe_multi_test.c to
trace_helpers.c and rename it to bpf_get_ksyms() and bpf_get_addrs().

Signed-off-by: Menglong Dong <dongml2@chinatelecom.cn>
---
 .../bpf/prog_tests/kprobe_multi_test.c        | 220 +-----------------
 tools/testing/selftests/bpf/trace_helpers.c   | 214 +++++++++++++++++
 tools/testing/selftests/bpf/trace_helpers.h   |   3 +
 3 files changed, 220 insertions(+), 217 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
index e19ef509ebf8..171706e78da8 100644
--- a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
+++ b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
@@ -422,220 +422,6 @@ static void test_unique_match(void)
 	kprobe_multi__destroy(skel);
 }
 
-static size_t symbol_hash(long key, void *ctx __maybe_unused)
-{
-	return str_hash((const char *) key);
-}
-
-static bool symbol_equal(long key1, long key2, void *ctx __maybe_unused)
-{
-	return strcmp((const char *) key1, (const char *) key2) == 0;
-}
-
-static bool is_invalid_entry(char *buf, bool kernel)
-{
-	if (kernel && strchr(buf, '['))
-		return true;
-	if (!kernel && !strchr(buf, '['))
-		return true;
-	return false;
-}
-
-static bool skip_entry(char *name)
-{
-	/*
-	 * We attach to almost all kernel functions and some of them
-	 * will cause 'suspicious RCU usage' when fprobe is attached
-	 * to them. Filter out the current culprits - arch_cpu_idle
-	 * default_idle and rcu_* functions.
-	 */
-	if (!strcmp(name, "arch_cpu_idle"))
-		return true;
-	if (!strcmp(name, "default_idle"))
-		return true;
-	if (!strncmp(name, "rcu_", 4))
-		return true;
-	if (!strcmp(name, "bpf_dispatcher_xdp_func"))
-		return true;
-	if (!strncmp(name, "__ftrace_invalid_address__",
-		     sizeof("__ftrace_invalid_address__") - 1))
-		return true;
-	return false;
-}
-
-/* Do comparision by ignoring '.llvm.<hash>' suffixes. */
-static int compare_name(const char *name1, const char *name2)
-{
-	const char *res1, *res2;
-	int len1, len2;
-
-	res1 = strstr(name1, ".llvm.");
-	res2 = strstr(name2, ".llvm.");
-	len1 = res1 ? res1 - name1 : strlen(name1);
-	len2 = res2 ? res2 - name2 : strlen(name2);
-
-	if (len1 == len2)
-		return strncmp(name1, name2, len1);
-	if (len1 < len2)
-		return strncmp(name1, name2, len1) <= 0 ? -1 : 1;
-	return strncmp(name1, name2, len2) >= 0 ? 1 : -1;
-}
-
-static int load_kallsyms_compare(const void *p1, const void *p2)
-{
-	return compare_name(((const struct ksym *)p1)->name, ((const struct ksym *)p2)->name);
-}
-
-static int search_kallsyms_compare(const void *p1, const struct ksym *p2)
-{
-	return compare_name(p1, p2->name);
-}
-
-static int get_syms(char ***symsp, size_t *cntp, bool kernel)
-{
-	size_t cap = 0, cnt = 0;
-	char *name = NULL, *ksym_name, **syms = NULL;
-	struct hashmap *map;
-	struct ksyms *ksyms;
-	struct ksym *ks;
-	char buf[256];
-	FILE *f;
-	int err = 0;
-
-	ksyms = load_kallsyms_custom_local(load_kallsyms_compare);
-	if (!ASSERT_OK_PTR(ksyms, "load_kallsyms_custom_local"))
-		return -EINVAL;
-
-	/*
-	 * The available_filter_functions contains many duplicates,
-	 * but other than that all symbols are usable in kprobe multi
-	 * interface.
-	 * Filtering out duplicates by using hashmap__add, which won't
-	 * add existing entry.
-	 */
-
-	if (access("/sys/kernel/tracing/trace", F_OK) == 0)
-		f = fopen("/sys/kernel/tracing/available_filter_functions", "r");
-	else
-		f = fopen("/sys/kernel/debug/tracing/available_filter_functions", "r");
-
-	if (!f)
-		return -EINVAL;
-
-	map = hashmap__new(symbol_hash, symbol_equal, NULL);
-	if (IS_ERR(map)) {
-		err = libbpf_get_error(map);
-		goto error;
-	}
-
-	while (fgets(buf, sizeof(buf), f)) {
-		if (is_invalid_entry(buf, kernel))
-			continue;
-
-		free(name);
-		if (sscanf(buf, "%ms$*[^\n]\n", &name) != 1)
-			continue;
-		if (skip_entry(name))
-			continue;
-
-		ks = search_kallsyms_custom_local(ksyms, name, search_kallsyms_compare);
-		if (!ks) {
-			err = -EINVAL;
-			goto error;
-		}
-
-		ksym_name = ks->name;
-		err = hashmap__add(map, ksym_name, 0);
-		if (err == -EEXIST) {
-			err = 0;
-			continue;
-		}
-		if (err)
-			goto error;
-
-		err = libbpf_ensure_mem((void **) &syms, &cap,
-					sizeof(*syms), cnt + 1);
-		if (err)
-			goto error;
-
-		syms[cnt++] = ksym_name;
-	}
-
-	*symsp = syms;
-	*cntp = cnt;
-
-error:
-	free(name);
-	fclose(f);
-	hashmap__free(map);
-	if (err)
-		free(syms);
-	return err;
-}
-
-static int get_addrs(unsigned long **addrsp, size_t *cntp, bool kernel)
-{
-	unsigned long *addr, *addrs, *tmp_addrs;
-	int err = 0, max_cnt, inc_cnt;
-	char *name = NULL;
-	size_t cnt = 0;
-	char buf[256];
-	FILE *f;
-
-	if (access("/sys/kernel/tracing/trace", F_OK) == 0)
-		f = fopen("/sys/kernel/tracing/available_filter_functions_addrs", "r");
-	else
-		f = fopen("/sys/kernel/debug/tracing/available_filter_functions_addrs", "r");
-
-	if (!f)
-		return -ENOENT;
-
-	/* In my local setup, the number of entries is 50k+ so Let us initially
-	 * allocate space to hold 64k entries. If 64k is not enough, incrementally
-	 * increase 1k each time.
-	 */
-	max_cnt = 65536;
-	inc_cnt = 1024;
-	addrs = malloc(max_cnt * sizeof(long));
-	if (addrs == NULL) {
-		err = -ENOMEM;
-		goto error;
-	}
-
-	while (fgets(buf, sizeof(buf), f)) {
-		if (is_invalid_entry(buf, kernel))
-			continue;
-
-		free(name);
-		if (sscanf(buf, "%p %ms$*[^\n]\n", &addr, &name) != 2)
-			continue;
-		if (skip_entry(name))
-			continue;
-
-		if (cnt == max_cnt) {
-			max_cnt += inc_cnt;
-			tmp_addrs = realloc(addrs, max_cnt);
-			if (!tmp_addrs) {
-				err = -ENOMEM;
-				goto error;
-			}
-			addrs = tmp_addrs;
-		}
-
-		addrs[cnt++] = (unsigned long)addr;
-	}
-
-	*addrsp = addrs;
-	*cntp = cnt;
-
-error:
-	free(name);
-	fclose(f);
-	if (err)
-		free(addrs);
-	return err;
-}
-
 static void do_bench_test(struct kprobe_multi_empty *skel, struct bpf_kprobe_multi_opts *opts)
 {
 	long attach_start_ns, attach_end_ns;
@@ -670,7 +456,7 @@ static void test_kprobe_multi_bench_attach(bool kernel)
 	char **syms = NULL;
 	size_t cnt = 0;
 
-	if (!ASSERT_OK(get_syms(&syms, &cnt, kernel), "get_syms"))
+	if (!ASSERT_OK(bpf_get_ksyms(&syms, &cnt, kernel), "bpf_get_ksyms"))
 		return;
 
 	skel = kprobe_multi_empty__open_and_load();
@@ -696,13 +482,13 @@ static void test_kprobe_multi_bench_attach_addr(bool kernel)
 	size_t cnt = 0;
 	int err;
 
-	err = get_addrs(&addrs, &cnt, kernel);
+	err = bpf_get_addrs(&addrs, &cnt, kernel);
 	if (err == -ENOENT) {
 		test__skip();
 		return;
 	}
 
-	if (!ASSERT_OK(err, "get_addrs"))
+	if (!ASSERT_OK(err, "bpf_get_addrs"))
 		return;
 
 	skel = kprobe_multi_empty__open_and_load();
diff --git a/tools/testing/selftests/bpf/trace_helpers.c b/tools/testing/selftests/bpf/trace_helpers.c
index 81943c6254e6..d24baf244d1f 100644
--- a/tools/testing/selftests/bpf/trace_helpers.c
+++ b/tools/testing/selftests/bpf/trace_helpers.c
@@ -17,6 +17,7 @@
 #include <linux/limits.h>
 #include <libelf.h>
 #include <gelf.h>
+#include "bpf/hashmap.h"
 #include "bpf/libbpf_internal.h"
 
 #define TRACEFS_PIPE	"/sys/kernel/tracing/trace_pipe"
@@ -519,3 +520,216 @@ void read_trace_pipe(void)
 {
 	read_trace_pipe_iter(trace_pipe_cb, NULL, 0);
 }
+
+static size_t symbol_hash(long key, void *ctx __maybe_unused)
+{
+	return str_hash((const char *) key);
+}
+
+static bool symbol_equal(long key1, long key2, void *ctx __maybe_unused)
+{
+	return strcmp((const char *) key1, (const char *) key2) == 0;
+}
+
+static bool is_invalid_entry(char *buf, bool kernel)
+{
+	if (kernel && strchr(buf, '['))
+		return true;
+	if (!kernel && !strchr(buf, '['))
+		return true;
+	return false;
+}
+
+static bool skip_entry(char *name)
+{
+	/*
+	 * We attach to almost all kernel functions and some of them
+	 * will cause 'suspicious RCU usage' when fprobe is attached
+	 * to them. Filter out the current culprits - arch_cpu_idle
+	 * default_idle and rcu_* functions.
+	 */
+	if (!strcmp(name, "arch_cpu_idle"))
+		return true;
+	if (!strcmp(name, "default_idle"))
+		return true;
+	if (!strncmp(name, "rcu_", 4))
+		return true;
+	if (!strcmp(name, "bpf_dispatcher_xdp_func"))
+		return true;
+	if (!strncmp(name, "__ftrace_invalid_address__",
+		     sizeof("__ftrace_invalid_address__") - 1))
+		return true;
+	return false;
+}
+
+/* Do comparison by ignoring '.llvm.<hash>' suffixes. */
+static int compare_name(const char *name1, const char *name2)
+{
+	const char *res1, *res2;
+	int len1, len2;
+
+	res1 = strstr(name1, ".llvm.");
+	res2 = strstr(name2, ".llvm.");
+	len1 = res1 ? res1 - name1 : strlen(name1);
+	len2 = res2 ? res2 - name2 : strlen(name2);
+
+	if (len1 == len2)
+		return strncmp(name1, name2, len1);
+	if (len1 < len2)
+		return strncmp(name1, name2, len1) <= 0 ? -1 : 1;
+	return strncmp(name1, name2, len2) >= 0 ? 1 : -1;
+}
+
+static int load_kallsyms_compare(const void *p1, const void *p2)
+{
+	return compare_name(((const struct ksym *)p1)->name, ((const struct ksym *)p2)->name);
+}
+
+static int search_kallsyms_compare(const void *p1, const struct ksym *p2)
+{
+	return compare_name(p1, p2->name);
+}
+
+int bpf_get_ksyms(char ***symsp, size_t *cntp, bool kernel)
+{
+	size_t cap = 0, cnt = 0;
+	char *name = NULL, *ksym_name, **syms = NULL;
+	struct hashmap *map;
+	struct ksyms *ksyms;
+	struct ksym *ks;
+	char buf[256];
+	FILE *f;
+	int err = 0;
+
+	ksyms = load_kallsyms_custom_local(load_kallsyms_compare);
+	if (!ksyms)
+		return -EINVAL;
+
+	/*
+	 * The available_filter_functions contains many duplicates,
+	 * but other than that all symbols are usable to trace.
+	 * Filtering out duplicates by using hashmap__add, which won't
+	 * add existing entry.
+	 */
+
+	if (access("/sys/kernel/tracing/trace", F_OK) == 0)
+		f = fopen("/sys/kernel/tracing/available_filter_functions", "r");
+	else
+		f = fopen("/sys/kernel/debug/tracing/available_filter_functions", "r");
+
+	if (!f)
+		return -EINVAL;
+
+	map = hashmap__new(symbol_hash, symbol_equal, NULL);
+	if (IS_ERR(map)) {
+		err = libbpf_get_error(map);
+		goto error;
+	}
+
+	while (fgets(buf, sizeof(buf), f)) {
+		if (is_invalid_entry(buf, kernel))
+			continue;
+
+		free(name);
+		if (sscanf(buf, "%ms$*[^\n]\n", &name) != 1)
+			continue;
+		if (skip_entry(name))
+			continue;
+
+		ks = search_kallsyms_custom_local(ksyms, name, search_kallsyms_compare);
+		if (!ks) {
+			err = -EINVAL;
+			goto error;
+		}
+
+		ksym_name = ks->name;
+		err = hashmap__add(map, ksym_name, 0);
+		if (err == -EEXIST) {
+			err = 0;
+			continue;
+		}
+		if (err)
+			goto error;
+
+		err = libbpf_ensure_mem((void **) &syms, &cap,
+					sizeof(*syms), cnt + 1);
+		if (err)
+			goto error;
+
+		syms[cnt++] = ksym_name;
+	}
+
+	*symsp = syms;
+	*cntp = cnt;
+
+error:
+	free(name);
+	fclose(f);
+	hashmap__free(map);
+	if (err)
+		free(syms);
+	return err;
+}
+
+int bpf_get_addrs(unsigned long **addrsp, size_t *cntp, bool kernel)
+{
+	unsigned long *addr, *addrs, *tmp_addrs;
+	int err = 0, max_cnt, inc_cnt;
+	char *name = NULL;
+	size_t cnt = 0;
+	char buf[256];
+	FILE *f;
+
+	if (access("/sys/kernel/tracing/trace", F_OK) == 0)
+		f = fopen("/sys/kernel/tracing/available_filter_functions_addrs", "r");
+	else
+		f = fopen("/sys/kernel/debug/tracing/available_filter_functions_addrs", "r");
+
+	if (!f)
+		return -ENOENT;
+
+	/* In my local setup, the number of entries is 50k+ so Let us initially
+	 * allocate space to hold 64k entries. If 64k is not enough, incrementally
+	 * increase 1k each time.
+	 */
+	max_cnt = 65536;
+	inc_cnt = 1024;
+	addrs = malloc(max_cnt * sizeof(long));
+	if (addrs == NULL) {
+		err = -ENOMEM;
+		goto error;
+	}
+
+	while (fgets(buf, sizeof(buf), f)) {
+		if (is_invalid_entry(buf, kernel))
+			continue;
+
+		free(name);
+		if (sscanf(buf, "%p %ms$*[^\n]\n", &addr, &name) != 2)
+			continue;
+		if (skip_entry(name))
+			continue;
+
+		if (cnt == max_cnt) {
+			max_cnt += inc_cnt;
+			tmp_addrs = realloc(addrs, max_cnt);
+			if (!tmp_addrs) {
+				err = -ENOMEM;
+				goto error;
+			}
+			addrs = tmp_addrs;
+		}
+
+		addrs[cnt++] = (unsigned long)addr;
+	}
+
+	*addrsp = addrs;
+	*cntp = cnt;
+
+error:
+	free(name);
+	fclose(f);
+	if (err)
+		free(addrs);
+	return err;
+}
diff --git a/tools/testing/selftests/bpf/trace_helpers.h b/tools/testing/selftests/bpf/trace_helpers.h
index 2ce873c9f9aa..9437bdd4afa5 100644
--- a/tools/testing/selftests/bpf/trace_helpers.h
+++ b/tools/testing/selftests/bpf/trace_helpers.h
@@ -41,4 +41,7 @@ ssize_t get_rel_offset(uintptr_t addr);
 
 int read_build_id(const char *path, char *build_id, size_t size);
 
+int bpf_get_ksyms(char ***symsp, size_t *cntp, bool kernel);
+int bpf_get_addrs(unsigned long **addrsp, size_t *cntp, bool kernel);
+
 #endif
-- 
2.50.1


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCBE421CC74;
	Mon, 28 Jul 2025 04:13:10 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.194
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1753675992; cv=none; b=spZGfoflpBT9h3DtQC83psxLEdBJl0RnurdtdSUvr4NIknl78tPYz+siwKQPa2VMpLsyhKm6ePFmYcLv1MIfDBCFT+eo/J0U0QZnZCOIPxqxzncCneD/2CgnPpaw7YsFyyrd1zUfaN2bIOpgo6JPFzdcUA8qJLPx6qLUq+lAUTw=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1753675992; c=relaxed/simple;
	bh=TGw2ul2ZAldEcVHaU0fnT+T9Zm5AaMY7QcEq1fLdVSA=;
	h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
	 MIME-Version; b=TrKsWbJPN8E/BEaHK6LhdyANcjgxOaIGZucM5LKlqI2s/ys5eIWYLZlCy+YnrXU3Cz++/0/fmvWCQeAV6I5UBTXh1afOmZ+xFrV5ZbwwpT+6f2mQCfh1D90/bSnKunI0c3xFyd1IaWz/7JZg3S8pq0fQViUKkrjm8uXDdFpd1kA=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HByaA437; arc=none smtp.client-ip=209.85.214.194
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HByaA437"
Received: by mail-pl1-f194.google.com with SMTP id d9443c01a7336-234f17910d8so33814795ad.3;
        Sun, 27 Jul 2025 21:13:10 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20230601; t=1753675990; x=1754280790; darn=vger.kernel.org;
        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=DGBbLIiLGqrmFvSwaYDbAojdCre78exL+6ZjHnBuXvE=;
        b=HByaA437BoA9M86BoqGIPDAMLeB975vjxV6EXiGTXszhkMGWlPtN3HGXOAB5BkhfZX
         KD5mepIRUK43RYo4U+11BexLkK2+jZcM01LUqcxI8ETG8EwIzKLSBHoalDTL5ru0lsTF
         SZczRc/rUmeC25twD4yziI1n7WViZtIfoL2+92fnlfCaKGZr6VMXQ7TrObtg9Bo2PxeB
         HLsYD8yMuYLHvDBiC+iz7lnd7cHZHJabSQmHCvalCGN7tMG910fwTOhzNiTln31hBcq3
         DAb7ZUXeuIOOyVkVEqwSncX9AyaMkKasH5rKKcdvH+zO8qZZxJCamzRrihZHqoogbc3u
         kwIA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1753675990; x=1754280790;
        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=DGBbLIiLGqrmFvSwaYDbAojdCre78exL+6ZjHnBuXvE=;
        b=b/0bLSZuqVZMKLbyi7R+714vnV46fHYSKXTig36QK1+GANpCqmb8uq0hm6pKBp6Wzv
         AVzZCgNgitSBEBR2pzqmCzYCHZ7f6vkTIi0c45KirpZsBq5zme7j24S3L7hGqBmznyrd
         3VrYJRovDZBmGsla1qQENdTYzCV9L77u+PE+Yj3DbGpOiTHAXsZgckZ/9sOPaW3SCPYL
         iBl3w/VOggU3/tNxilvy62fUXWQWpUXcvUM57StWjirxAfzNaDPoNQdCn0GZ7aVhGmSG
         ORxiYkpxTQQbgtBH4Vj0+hmPTdByMTTzgJdnL4oa54OjPBg05o3G1ECFa9XaGJC50KRT
         vT7g==
X-Forwarded-Encrypted: i=1; AJvYcCUM+JGpsIw4OZ6NlZH+/+QBS8KCptLt5JobmaSgU/f8LfvrqT8f4tNuiCHP8GDZqaO2EmSyQNPfkEryVANUAVmWVDPP@vger.kernel.org, AJvYcCXhXgeg8lXq+gn3Dp04owI6woUpBKMKypzk+uMxHNEMKYsxNcS+S6VeiEd2V+4S36O0c+s=@vger.kernel.org, AJvYcCXxWgU+mq0KlGatDsMefnD0aBZTYRDKGaWbTZvh3B80/ljOYelgh1n2bn74H3C3KrbbPMNx4WklRFn0n/da@vger.kernel.org
X-Gm-Message-State: AOJu0YxppwLGvNmB4/FHxZLL5Zr1V+TbuYwmeVVsELCeTUMGpIxejuF1
	xmgYTUMBLU1ueAeubExSK05CTFCP19lkDI9TaYIdbsmP26180HpZpsKGuDzVGfnNcd0=
X-Gm-Gg: ASbGncs2VapEI4tR3DuYFho8wvvtLp9jZMFi8AA/3FXnwMCxGXvqacZ2LqU7zVPUE0f
	qZyynVnOAQWF2qyPCTUHsNLQo9ccXW3SCnPw9bMWxiD2Yq2BX6D/g8Vrg4Ni7q7RKRQLwjTUcd7
	hBRqZDherF5DKY5bjG4AqpNJAhPpVCOc1klr04aWfbWZq+cl92Jjz3aCfTtTURy8LZB8wVT1xa7
	0vSGuRFKCn3y6oDwgF7Vd0trOLmc7JVbErsGQEWUWLL6C+Cez1Y9pUNVa8dYV8ludpZxORhy0vT
	XCuJWQrJVf6GgvDRK9B8ER8ED840xRJRCvfsmeXPG8AJL7qFW1XSCP9oa8UK2PeyspGSZgg8UrO
	OyDgYrZeApBgNRkduYjQ=
X-Google-Smtp-Source: AGHT+IGB2pjt0vkcDq6lWjAxS++yOy8gk7moI81oq6LOT4h67+7I5MBC0hse5/AG1yjymEbtYkgE5A==
X-Received: by 2002:a17:902:d506:b0:235:f45f:ed2b with SMTP id d9443c01a7336-23fb2fe1271mr144452705ad.1.1753675989958;
        Sun, 27 Jul 2025 21:13:09 -0700 (PDT)
Received: from 7950hx ([43.129.244.20])
        by smtp.gmail.com with ESMTPSA id d9443c01a7336-24008efc073sm20599175ad.58.2025.07.27.21.13.06
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Sun, 27 Jul 2025 21:13:09 -0700 (PDT)
From: Menglong Dong <menglong8.dong@gmail.com>
X-Google-Original-From: Menglong Dong <dongml2@chinatelecom.cn>
To: alexei.starovoitov@gmail.com,
	mhiramat@kernel.org
Cc: rostedt@goodmis.org,
	mathieu.desnoyers@efficios.com,
	hca@linux.ibm.com,
	revest@chromium.org,
	linux-kernel@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org,
	bpf@vger.kernel.org
Subject: [PATCH bpf-next 3/4] selftests/bpf: skip recursive functions for kprobe_multi
Date: Mon, 28 Jul 2025 12:12:50 +0800
Message-ID: <20250728041252.441040-4-dongml2@chinatelecom.cn>
X-Mailer: git-send-email 2.50.1
In-Reply-To: <20250728041252.441040-1-dongml2@chinatelecom.cn>
References: <20250728041252.441040-1-dongml2@chinatelecom.cn>
Precedence: bulk
X-Mailing-List: linux-trace-kernel@vger.kernel.org
List-Id: <linux-trace-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-trace-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-trace-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

Some functions is recursive for the kprobe_multi and impact the benchmark
results. So just skip them.

Signed-off-by: Menglong Dong <dongml2@chinatelecom.cn>
---
 tools/testing/selftests/bpf/trace_helpers.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/tools/testing/selftests/bpf/trace_helpers.c b/tools/testing/selftests/bpf/trace_helpers.c
index d24baf244d1f..9da9da51b132 100644
--- a/tools/testing/selftests/bpf/trace_helpers.c
+++ b/tools/testing/selftests/bpf/trace_helpers.c
@@ -559,6 +559,22 @@ static bool skip_entry(char *name)
 	if (!strncmp(name, "__ftrace_invalid_address__",
 		     sizeof("__ftrace_invalid_address__") - 1))
 		return true;
+
+	if (!strcmp(name, "migrate_disable"))
+		return true;
+	if (!strcmp(name, "migrate_enable"))
+		return true;
+	if (!strcmp(name, "rcu_read_unlock_strict"))
+		return true;
+	if (!strcmp(name, "preempt_count_add"))
+		return true;
+	if (!strcmp(name, "preempt_count_sub"))
+		return true;
+	if (!strcmp(name, "__rcu_read_lock"))
+		return true;
+	if (!strcmp(name, "__rcu_read_unlock"))
+		return true;
+
 	return false;
 }
 
-- 
2.50.1


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2ACAB220F34;
	Mon, 28 Jul 2025 04:13:13 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.196
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1753675995; cv=none; b=HAd7NNUhFNVz6Pp2u83LSseVNXSkFDX/UHFlhznP5A8U4jrNDC1DINbNhhrMNiTdk7jUX2xCa1Y1yxyUWSRYlws39M0b2+USvCmuHvDUzUl5g3pIsr2b1P+byRQbFCmlvKYuPjkXUoc5fd7aCcpgR2EnSdv8jn/n03fpe2H6WnA=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1753675995; c=relaxed/simple;
	bh=bRExeoONmR0WhrsbqFNroJ9+Vz1rBjIUMt3FwoFHMyQ=;
	h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
	 MIME-Version; b=XGyPmxDWkaqHwdw0+nvm7ptYnnKBHSTU/IF+FDPzNFWQaA5FW+Kx5dAS+G5kS/GPqgaqRhOGnzD+V7AFUCyEU84nLDUPtg52p3sFqk0onzYQkLvORODR9mVMgTZVe7s2/b4Iz2RGgfzNEOxGIihN4onY680G4Te/X5/YAIkf5GY=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fK+gBeSX; arc=none smtp.client-ip=209.85.214.196
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fK+gBeSX"
Received: by mail-pl1-f196.google.com with SMTP id d9443c01a7336-23602481460so39620015ad.0;
        Sun, 27 Jul 2025 21:13:13 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20230601; t=1753675993; x=1754280793; darn=vger.kernel.org;
        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=AjeNP1ojEwSXm7x5F0g4swwiLUfc7kqWz38lpPc+Rx8=;
        b=fK+gBeSX/zLgzQIWjLg5MsFYTWm+ernGTfh48OcfErjnfZT+paMLVH5PAxb4tw5CaM
         U84qSUotMtrYmmsIe5uKaMSxD5CLY37o8kTvVVxyyaroiApv92PTwAwPyPq7JmCVZ0d3
         Op2bZSeBRFRW/UiQ6E7vV9afNzaZnE6afh0GFo50W2c2LM4ig3iHhGStKQbAvn4HgtU1
         7Bzs4d+qJ/OU5imjb7mpUD5/YAUxXY7uo1pcpV3CeWaHwuoffUB7n3auWtZDSU5py9jb
         btZ1M1ZkINpni2arWmYoXV/Ly9SjYdj15ctqB+125bde17awZoXmZNwO7ztXycnP19qd
         uzBw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1753675993; x=1754280793;
        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=AjeNP1ojEwSXm7x5F0g4swwiLUfc7kqWz38lpPc+Rx8=;
        b=M3aA8Yc26ZA9mXS1iLMgQ8VIgugQysmX91hAYxjV7beJBPXlpiNl0HnkKPvjk6QLkc
         /bSobfX0u4I9M1AusMG5ieQhh7jVrkH7LoyV5vtLPbNvW4Zr+AM9zzLCTkaVvNS4q0sr
         fBrix7M1oaQbZTyqJC09hwq7KbKHGjOK8Ll2bN65aWoYtZ2vJGWqlyabDSY+JitHDPTw
         StLGoVP/R7WqTVcn8abz9Y0IJSGYkeUBm6JBiYV7M+v5zPjuq3phN7IBhnNSk1+2INPp
         41OtayBqVhqP5qdkuaZEMHlvLy6BO2yz+b+WGCEt77RiGxGERQZ7neDk68T3MLFAS/VG
         dvbw==
X-Forwarded-Encrypted: i=1; AJvYcCUWoFKvckbHYbdnRybrr1uWdf+7cTD9TF70t+y9RRIQk1YoLFbpN4KBP1QFRnYQ+weJlnNr9Q7n5r+WrqLPfolkFxS4@vger.kernel.org, AJvYcCXCWj97iTtKxhgwhR9xEkygSUAH3CL72fJfgR0EVCqC3KyGTUvUUR/rQOIn2FSiWKhv72mzzsh97YBVCnOt@vger.kernel.org, AJvYcCXXsjNMRbyx1pTj1uVRdqZTmYU6hmV5LZGpzNVaEurYad7IIzQygj6cXMOBVS0GmFXb+VA=@vger.kernel.org
X-Gm-Message-State: AOJu0YytkzG/C1Uxvmj/xkfPzskngoIdZj365ZPnpysVFDtTmUZM4vjR
	tdf9Y3KBGNqIv5cVkdqqZOt/dRppzXntBB4x6JsEJPO9K3p5NRKBNJ1O
X-Gm-Gg: ASbGncv0ZetoHcaykpEpNnrbGb75ix1ebpwUJqxpW9y7dPSqIjCN5AQb3SQUC4MNO4N
	YTIWCJl0HHTxZf2+9K2jubq7Apic+QE/rox+4npjLiJzr7XGysl6Mh7u+zh9ABVq92cZ0h8Yso7
	wgd720ZV3BD7kTT7zVSz7W31zxGyPivHwwWF20xcvuhozILzcIq+9QEkOZWxDoWNrLDUbuf2/y5
	fvJ1d+YKAVgNo5fQ/knSm8cwzP/sXmzRds0oXgXYElznKcw8ahFuXq8M3fcr17z80ILNTHgJ6w/
	zA99LBMgun5TZd9dF5+z1nQdNeNpLVp98roQo6EU1jztk4e5NMb29hJYPeFJuWMRXC4keVxr2cO
	NkubBBK6r/Dksfk40Zco=
X-Google-Smtp-Source: AGHT+IF9kh81K3dC0j67xBO5/cmUYFztZWzS9P4O92aNSAOnGEzvIs2s4ZaQScwsDq0lt6VC2wP0aw==
X-Received: by 2002:a17:903:4b50:b0:236:9726:7264 with SMTP id d9443c01a7336-23fb305083dmr171963755ad.5.1753675993352;
        Sun, 27 Jul 2025 21:13:13 -0700 (PDT)
Received: from 7950hx ([43.129.244.20])
        by smtp.gmail.com with ESMTPSA id d9443c01a7336-24008efc073sm20599175ad.58.2025.07.27.21.13.10
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Sun, 27 Jul 2025 21:13:13 -0700 (PDT)
From: Menglong Dong <menglong8.dong@gmail.com>
X-Google-Original-From: Menglong Dong <dongml2@chinatelecom.cn>
To: alexei.starovoitov@gmail.com,
	mhiramat@kernel.org
Cc: rostedt@goodmis.org,
	mathieu.desnoyers@efficios.com,
	hca@linux.ibm.com,
	revest@chromium.org,
	linux-kernel@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org,
	bpf@vger.kernel.org
Subject: [PATCH bpf-next 4/4] selftests/bpf: add benchmark testing for kprobe-multi-all
Date: Mon, 28 Jul 2025 12:12:51 +0800
Message-ID: <20250728041252.441040-5-dongml2@chinatelecom.cn>
X-Mailer: git-send-email 2.50.1
In-Reply-To: <20250728041252.441040-1-dongml2@chinatelecom.cn>
References: <20250728041252.441040-1-dongml2@chinatelecom.cn>
Precedence: bulk
X-Mailing-List: linux-trace-kernel@vger.kernel.org
List-Id: <linux-trace-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-trace-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-trace-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

For now, the benchmark for kprobe-multi is single, which means there is
only 1 function is hooked during testing. Add the testing
"kprobe-multi-all", which will hook all the kernel functions during
the benchmark.

Signed-off-by: Menglong Dong <dongml2@chinatelecom.cn>
---
 tools/testing/selftests/bpf/bench.c           |  2 ++
 .../selftests/bpf/benchs/bench_trigger.c      | 30 +++++++++++++++++++
 .../selftests/bpf/benchs/run_bench_trigger.sh |  2 +-
 3 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/bench.c b/tools/testing/selftests/bpf/bench.c
index ddd73d06a1eb..da971d8c5ae5 100644
--- a/tools/testing/selftests/bpf/bench.c
+++ b/tools/testing/selftests/bpf/bench.c
@@ -510,6 +510,7 @@ extern const struct bench bench_trig_kretprobe;
 extern const struct bench bench_trig_kprobe_multi;
 extern const struct bench bench_trig_kretprobe_multi;
 extern const struct bench bench_trig_fentry;
+extern const struct bench bench_trig_kprobe_multi_all;
 extern const struct bench bench_trig_fexit;
 extern const struct bench bench_trig_fmodret;
 extern const struct bench bench_trig_tp;
@@ -578,6 +579,7 @@ static const struct bench *benchs[] = {
 	&bench_trig_kprobe_multi,
 	&bench_trig_kretprobe_multi,
 	&bench_trig_fentry,
+	&bench_trig_kprobe_multi_all,
 	&bench_trig_fexit,
 	&bench_trig_fmodret,
 	&bench_trig_tp,
diff --git a/tools/testing/selftests/bpf/benchs/bench_trigger.c b/tools/testing/selftests/bpf/benchs/bench_trigger.c
index 82327657846e..be5fe88862a4 100644
--- a/tools/testing/selftests/bpf/benchs/bench_trigger.c
+++ b/tools/testing/selftests/bpf/benchs/bench_trigger.c
@@ -226,6 +226,35 @@ static void trigger_fentry_setup(void)
 	attach_bpf(ctx.skel->progs.bench_trigger_fentry);
 }
 
+static void trigger_kprobe_multi_all_setup(void)
+{
+	LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
+	struct bpf_program *prog;
+	struct bpf_link *link;
+	char **syms = NULL;
+	size_t cnt = 0;
+
+	setup_ctx();
+	prog = ctx.skel->progs.bench_trigger_kprobe_multi;
+	bpf_program__set_autoload(prog, true);
+	load_ctx();
+
+	if (bpf_get_ksyms(&syms, &cnt, true)) {
+		printf("failed to get ksyms\n");
+		exit(1);
+	}
+
+	printf("found %zu ksyms\n", cnt);
+	opts.syms = (const char **) syms;
+	opts.cnt = cnt;
+	link = bpf_program__attach_kprobe_multi_opts(prog, NULL, &opts);
+	if (!link) {
+		printf("failed to attach bpf_program__attach_kprobe_multi_opts to all\n");
+		exit(1);
+	}
+	ctx.skel->links.bench_trigger_kprobe_multi = link;
+}
+
 static void trigger_fexit_setup(void)
 {
 	setup_ctx();
@@ -512,6 +541,7 @@ BENCH_TRIG_KERNEL(kretprobe, "kretprobe");
 BENCH_TRIG_KERNEL(kprobe_multi, "kprobe-multi");
 BENCH_TRIG_KERNEL(kretprobe_multi, "kretprobe-multi");
 BENCH_TRIG_KERNEL(fentry, "fentry");
+BENCH_TRIG_KERNEL(kprobe_multi_all, "kprobe-multi-all");
 BENCH_TRIG_KERNEL(fexit, "fexit");
 BENCH_TRIG_KERNEL(fmodret, "fmodret");
 BENCH_TRIG_KERNEL(tp, "tp");
diff --git a/tools/testing/selftests/bpf/benchs/run_bench_trigger.sh b/tools/testing/selftests/bpf/benchs/run_bench_trigger.sh
index a690f5a68b6b..886b6ffc9742 100755
--- a/tools/testing/selftests/bpf/benchs/run_bench_trigger.sh
+++ b/tools/testing/selftests/bpf/benchs/run_bench_trigger.sh
@@ -6,7 +6,7 @@ def_tests=( \
 	usermode-count kernel-count syscall-count \
 	fentry fexit fmodret \
 	rawtp tp \
-	kprobe kprobe-multi \
+	kprobe kprobe-multi kprobe-multi-all \
 	kretprobe kretprobe-multi \
 )
 
-- 
2.50.1


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A8161F5842;
	Mon, 28 Jul 2025 07:28:30 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1753687710; cv=none; b=QO1bzoBCCqThe8DfDC9IvtafNfHaBZtM+kI1qPvIUmRTrXJb67OVj/YbCUGg//dJCpc8vV9jR3AV6mBvA2rv3FyCGOaqmYWNm6z3fakXesT9UkWOy4Z1wJwIFqdipf7XicSWuHzl5iubKPLSHskB5uVNsYnIfDC8XVwSYO4b/H4=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1753687710; c=relaxed/simple;
	bh=NuySEPRxGoYqa915NES8ScXAe1vL+2p1aF5SCXze/HU=;
	h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References:
	 Mime-Version:Content-Type; b=htkGLRAjmXwCGijmBJZPRr5WjQItmDI58DSNr75pXF+yldGce6oovVHQ1dOwrwLW9qZTIMW3TYvO+a0twdxJiitLT4S3NTRBQykN9uduXXKCv+L21YaM89AuthGbuBsN9x92Md3YDLAorcJstPof5dHYn/Tyovv/A4fgIySDzw8=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iGYoCt5H; arc=none smtp.client-ip=10.30.226.201
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iGYoCt5H"
Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE978C4CEE7;
	Mon, 28 Jul 2025 07:28:28 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
	s=k20201202; t=1753687710;
	bh=NuySEPRxGoYqa915NES8ScXAe1vL+2p1aF5SCXze/HU=;
	h=Date:From:To:Cc:Subject:In-Reply-To:References:From;
	b=iGYoCt5HULdz7sWlbKMUNuBGcWmPEJIppW2EmWfKu7kido2FsrCuT79fhGkLazZgh
	 X/DIFoB171oWo1o2KCeIPGn7ermAIHPMTDRmI+72/JKJ6SYQFuCsBfgiiuilGkg3aJ
	 oBZabsdHriznEi5vTBMRWkKcTHz63hcww2cRoAbEZ4eNO903NVUoDEZjfUFi1FyLY4
	 hsZ8D/+t3hyKOqtIPiDQ9kl5owYlQYHsO+yYXjoN4qRHksGMpNPq73pazdzjA32SkR
	 i+TPh2qDcV+oMfBtL8PM+BDteImIEp1ST001Q//txP0sBUOv3tYFKtTBpf2ffMxV73
	 hP1Ydmbm8j/TA==
Date: Mon, 28 Jul 2025 16:28:27 +0900
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Menglong Dong <menglong8.dong@gmail.com>
Cc: alexei.starovoitov@gmail.com, rostedt@goodmis.org,
 mathieu.desnoyers@efficios.com, hca@linux.ibm.com, revest@chromium.org,
 linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
 bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 0/4] fprobe: use rhashtable for fprobe_ip_table
Message-Id: <20250728162827.09b6c89697bc1ce6a3f33d55@kernel.org>
In-Reply-To: <20250728041252.441040-1-dongml2@chinatelecom.cn>
References: <20250728041252.441040-1-dongml2@chinatelecom.cn>
X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu)
Precedence: bulk
X-Mailing-List: linux-trace-kernel@vger.kernel.org
List-Id: <linux-trace-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-trace-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-trace-kernel+unsubscribe@vger.kernel.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

On Mon, 28 Jul 2025 12:12:47 +0800
Menglong Dong <menglong8.dong@gmail.com> wrote:

> For now, the budget of the hash table that is used for fprobe_ip_table is
> fixed, which is 256, and can cause huge overhead when the hooked functions
> is a huge quantity.
> 
> In this series, we use rhashtable for fprobe_ip_table to reduce the
> overhead.
> 
> Meanwhile, we also add the benchmark testcase "kprobe-multi-all", which
> will hook all the kernel functions during the testing. Before this series,
> the performance is:
>   usermode-count :  875.380 Â± 0.366M/s 
>   kernel-count   :  435.924 Â± 0.461M/s 
>   syscall-count  :   31.004 Â± 0.017M/s 
>   fentry         :  134.076 Â± 1.752M/s 
>   fexit          :   68.319 Â± 0.055M/s 
>   fmodret        :   71.530 Â± 0.032M/s 
>   rawtp          :  202.751 Â± 0.138M/s 
>   tp             :   79.562 Â± 0.084M/s 
>   kprobe         :   55.587 Â± 0.028M/s 
>   kprobe-multi   :   56.481 Â± 0.043M/s 
>   kprobe-multi-all:    6.283 Â± 0.005M/s << look this
>   kretprobe      :   22.378 Â± 0.028M/s 
>   kretprobe-multi:   28.205 Â± 0.025M/s
> 
> With this series, the performance is:
>   usermode-count :  897.083 Â± 5.347M/s 
>   kernel-count   :  431.638 Â± 1.781M/s 
>   syscall-count  :   30.807 Â± 0.057M/s 
>   fentry         :  134.803 Â± 1.045M/s 
>   fexit          :   68.763 Â± 0.018M/s 
>   fmodret        :   71.444 Â± 0.052M/s 
>   rawtp          :  202.344 Â± 0.149M/s 
>   tp             :   79.644 Â± 0.376M/s 
>   kprobe         :   55.480 Â± 0.108M/s 
>   kprobe-multi   :   57.302 Â± 0.119M/s 
>   kprobe-multi-all:   57.855 Â± 0.144M/s << look this
>   kretprobe      :   22.265 Â± 0.023M/s 
>   kretprobe-multi:   27.740 Â± 0.023M/s
> 
> The benchmark of "kprobe-multi-all" increase from 6.283M/s to 57.855M/s.

Wow, great improvement. Interesting. Let me review it.

Thanks!!

> 
> Menglong Dong (4):
>   fprobe: use rhashtable
>   selftests/bpf: move get_ksyms and get_addrs to trace_helpers.c
>   selftests/bpf: add benchmark testing for kprobe-multi-all
>   selftests/bpf: skip recursive functions for kprobe_multi
> 
>  include/linux/fprobe.h                        |   2 +-
>  kernel/trace/fprobe.c                         | 144 ++++++-----
>  tools/testing/selftests/bpf/bench.c           |   2 +
>  .../selftests/bpf/benchs/bench_trigger.c      |  30 +++
>  .../selftests/bpf/benchs/run_bench_trigger.sh |   2 +-
>  .../bpf/prog_tests/kprobe_multi_test.c        | 220 +----------------
>  tools/testing/selftests/bpf/trace_helpers.c   | 230 ++++++++++++++++++
>  tools/testing/selftests/bpf/trace_helpers.h   |   3 +
>  8 files changed, 351 insertions(+), 282 deletions(-)
> 
> -- 
> 2.50.1
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 241832566F7;
	Mon, 28 Jul 2025 13:13:13 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1753708395; cv=none; b=fis/xlwbjZgVJyGLAELWxZLltCriWZ2eqjPuc89wrdcJUJSxXDkDD2IgsGjfAyPaazIv/Bz+ccaQmTLRGf2BeG4J5KQsPmw083BfRurC1FwecX79hOddKtdAaBb/xmg2rt6bHlxFPXpHYRimdOBdyn91yTsIb6mhl9LtFTfDXVo=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1753708395; c=relaxed/simple;
	bh=QnpLGbplVU8WZ8kkrDvGOUPeOR65rzZYVf9MhTKGYWI=;
	h=From:Date:To:Cc:Subject:Message-ID:References:MIME-Version:
	 Content-Type:Content-Disposition:In-Reply-To; b=h9Z/13zJVANDXaLQDzGGWA0Wp9v5jdZu12r6pdyf54CAK/yI8wWLPtgBtjkR+iMHntgVm5Pqt7R+KhE586G1FJqxtwcnuSnJKfb+6I6mg3UAUpbRcpBWYLde5pNhhCYBfD6J20TLIMUMygGPDBX52EuQswzTZs1lRAKSckQWfz0=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=l8fb3UBN; arc=none smtp.client-ip=209.85.218.46
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="l8fb3UBN"
Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-ae708b0e83eso832127766b.2;
        Mon, 28 Jul 2025 06:13:13 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20230601; t=1753708392; x=1754313192; darn=vger.kernel.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=APcAiwvhLI1BWyHpWwSAgoil9Lsrd8sTBWTZU/FOIgc=;
        b=l8fb3UBNcn6SIOniEv0rKwzW+PNeZj9mGhMD1vh1ktQeJfJErFxw3CBfYqMQrCPWOA
         S9B2u3sDu0uXWd6XVFS3TXl4otaUORZ2idLNlj7rREV2zkLHlhh/Cw7tYiDElfu19IJV
         m9L8oseePryHOdnMQ3KpsJFBpUIoTmZ9M6/wO0wvlZCjzgGmEMVCDs1HdJa3J2wi4TJG
         eXU3Y14IPimij0BYerfAXVP+Li5fIQbth+FDi5sVjcbpORZnrGB7QiygAi1M7L0gYW4c
         0Gq/HVy9TMog1K8U6oCbIFfJ5ZEraOA/27ZNcoQqZpgpQ8liUTiotQ0Fq/tqR7Gz3vwD
         3ZGQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1753708392; x=1754313192;
        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=APcAiwvhLI1BWyHpWwSAgoil9Lsrd8sTBWTZU/FOIgc=;
        b=CKTW6Ez9umuNwTmZvzQQMT37WrczK7KsKzOQz2wtUZ5dUv4MPAcROc/n8LpbZaU+pq
         5/aKJTbJVAcyglrLz2nWZzug7do1NjxUOdbhbb0zz9bukEDGH1R8sCv0OgmihCQ/iaAk
         jXzqXZdT4S53TPNngiMLLKHJmF+SegL7ayLlYtGG+P/vc37qH9nW1E6n85OXeyhWSXIk
         bI1hQGozzXQOJv5wyqv6Svf9suaUyOf6gWTtQ3KmHri3Xh+P30SDfj7eb7BgWHt4kKg7
         HT3lI8eacF4dGzePRdJxXXy5l95uAu/gw7H7zMfujj1/kvPdRJX+Lo19JT5uUaed9sAv
         gn1g==
X-Forwarded-Encrypted: i=1; AJvYcCU0imyJvDGZhbhopbHl44UrAj4Jq/sk9BW/84EDWA2snn22+PhvJDVIovnPyut7YOFZPx82CsNNiI/qoUi8@vger.kernel.org, AJvYcCV6L7Y53ebArxKUwzdmbsaWQhss6N3FQO6AjyQXZ6qwKna46an5btuVBX3sJpJ6W4Lgq1XwZTgeWNBo6TFUc1DT7zyu@vger.kernel.org, AJvYcCVfPtt2YzHsJgYFLwzfctjED4gdYse+eRIaHo41dRQgGMKQSg/aet/MCmP9m/dAe7o1cPc=@vger.kernel.org
X-Gm-Message-State: AOJu0YzrgWXNEP4YZDUl4MezFFQzqmciEVzeKgJ3X6Xpu3FFZT+vVXat
	xFLTtGd2W5DH35otz2jY9Uzbzw/Z1KlPRSUpjhX6H/UMFqA/vB4lR51Y
X-Gm-Gg: ASbGncsH+UaOPI1q4XTun/Vdcca6F/0Vz+2D2g9DBLq4u3C2cpIh6ps99odFC6prsKq
	cUYiwUUxsqHljNxEogeDpCjRUXjePZDrxDyAS1VdSDoAYPpSF1rQeCQangi1rU4WQ/TGCHM7gcv
	3ba8NJt+Wz1jV8m/xtHNHhi8/uld6Q+/nAowUUQunkYkxgqhLhtz903s+hokiOWz/Pqu1/sroMh
	bAJUO+6ZalDeOLEEF5ac/U4kLu8uULSsE1AKnO75h3/7CVZE+u5itWp0aTys4HGZkJvqiHds9Es
	4zQY3S/fRken/XY4/ikNmEGt00GPIKIMUlutBcxF0i9ObH3S+ENneG7KU0oPhMRuP7G4BTMDB3v
	G1NoWttpc6kD2T8d8EeFc2krD9SPcow==
X-Google-Smtp-Source: AGHT+IFxFvoo1uaWCi0japBTc2d8G11avlTyqRxvI8u1fyVQDTxX/+1QkLSM9XPdVIP7XoR7AMfalg==
X-Received: by 2002:a17:907:3fa9:b0:ad8:9a86:cf52 with SMTP id a640c23a62f3a-af616d05720mr1276325166b.11.1753708392057;
        Mon, 28 Jul 2025 06:13:12 -0700 (PDT)
Received: from krava ([173.38.220.53])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-af635af9967sm410482566b.131.2025.07.28.06.13.11
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Mon, 28 Jul 2025 06:13:11 -0700 (PDT)
From: Jiri Olsa <olsajiri@gmail.com>
X-Google-Original-From: Jiri Olsa <jolsa@kernel.org>
Date: Mon, 28 Jul 2025 15:13:09 +0200
To: Menglong Dong <menglong8.dong@gmail.com>
Cc: alexei.starovoitov@gmail.com, mhiramat@kernel.org, rostedt@goodmis.org,
	mathieu.desnoyers@efficios.com, hca@linux.ibm.com,
	revest@chromium.org, linux-kernel@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 1/4] fprobe: use rhashtable
Message-ID: <aId3ZSnlZRzoDUHC@krava>
References: <20250728041252.441040-1-dongml2@chinatelecom.cn>
 <20250728041252.441040-2-dongml2@chinatelecom.cn>
Precedence: bulk
X-Mailing-List: linux-trace-kernel@vger.kernel.org
List-Id: <linux-trace-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-trace-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-trace-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20250728041252.441040-2-dongml2@chinatelecom.cn>

On Mon, Jul 28, 2025 at 12:12:48PM +0800, Menglong Dong wrote:

SNIP

> +static const struct rhashtable_params fprobe_rht_params = {
> +	.head_offset		= offsetof(struct fprobe_hlist_node, hlist),
> +	.key_offset		= offsetof(struct fprobe_hlist_node, addr),
> +	.key_len		= sizeof_field(struct fprobe_hlist_node, addr),
> +	.hashfn			= fprobe_node_hashfn,
> +	.obj_hashfn		= fprobe_node_obj_hashfn,
> +	.obj_cmpfn		= fprobe_node_cmp,
> +	.automatic_shrinking	= true,
> +};
>  
>  /* Node insertion and deletion requires the fprobe_mutex */
>  static void insert_fprobe_node(struct fprobe_hlist_node *node)
>  {
> -	unsigned long ip = node->addr;
> -	struct fprobe_hlist_node *next;
> -	struct hlist_head *head;
> -
>  	lockdep_assert_held(&fprobe_mutex);
>  
> -	next = find_first_fprobe_node(ip);
> -	if (next) {
> -		hlist_add_before_rcu(&node->hlist, &next->hlist);
> -		return;
> -	}
> -	head = &fprobe_ip_table[hash_ptr((void *)ip, FPROBE_IP_HASH_BITS)];
> -	hlist_add_head_rcu(&node->hlist, head);
> +	rhashtable_insert_fast(&fprobe_ip_table, &node->hlist,
> +			       fprobe_rht_params);

onw that rhashtable_insert_fast can fail, I think insert_fprobe_node
needs to be able to fail as well

>  }
>  
>  /* Return true if there are synonims */
> @@ -92,9 +93,11 @@ static bool delete_fprobe_node(struct fprobe_hlist_node *node)
>  	/* Avoid double deleting */
>  	if (READ_ONCE(node->fp) != NULL) {
>  		WRITE_ONCE(node->fp, NULL);
> -		hlist_del_rcu(&node->hlist);
> +		rhashtable_remove_fast(&fprobe_ip_table, &node->hlist,
> +				       fprobe_rht_params);

I guess this one can't fail in here.. ?

jirka

>  	}
> -	return !!find_first_fprobe_node(node->addr);
> +	return !!rhashtable_lookup_fast(&fprobe_ip_table, &node->addr,
> +					fprobe_rht_params);
>  }
>  

SNIP

From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 771E125DD1E;
	Mon, 28 Jul 2025 13:14:34 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1753708477; cv=none; b=j4fVPM1TPzIbQhShTDJPhiZkrTzsYDiQ/c/yB2eCg8RQcb4FdVypIVnHJiD0/5YRDzzo4pVXEk+u97Ciu8X29Hd7HhSMNxpDTAF5BIhGDptuSGu7S00T4Ykv7kP9X1/rgQ6iZLUm3IhTdDcqcsqWfDxZYBphqVnkM5Vu7MHfQBI=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1753708477; c=relaxed/simple;
	bh=/JmWk7zs3nfyhClMXqzipmUy0qSDDHncW6sykqFZENY=;
	h=From:Date:To:Cc:Subject:Message-ID:References:MIME-Version:
	 Content-Type:Content-Disposition:In-Reply-To; b=U5KrR61gVm7oms/fVTxfMF0SHZL3KTnhQi1eLkkiVoB6icrUhWxZ/pwNCUvDyn0JRoGefkmRkwLd6XTN2vJrjhvV7WOsYsex5vBBtHfqmFwMsB4jxa5NV3NzTfvnMVz/iYxygS6+4DbjQvP9ADP92esU6fDsUwWwHPYI4oV/k28=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=F0Fl8+d5; arc=none smtp.client-ip=209.85.218.48
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="F0Fl8+d5"
Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-ae3703c2a8bso921369166b.0;
        Mon, 28 Jul 2025 06:14:34 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20230601; t=1753708473; x=1754313273; darn=vger.kernel.org;
        h=in-reply-to:content-transfer-encoding:content-disposition
         :mime-version:references:message-id:subject:cc:to:date:from:from:to
         :cc:subject:date:message-id:reply-to;
        bh=GDFjPQjNHLQQewbHjrCkwV119Zp5gq44Dp1xWV5F2p8=;
        b=F0Fl8+d5wGYjBvzH01ECmzScCU3VO85/9LX4uLV+5vXj62SBdX0CjCtJWDjPODMehA
         M9am3eC81CR1rB1A1gEeyn+Q/6xGD8fHXdJvhOox9Eb3TW9+Kpi7DTIAUxtkqjrLRMVw
         KA3XXHjebb3entiNYTlExUTHAOa2p1DA7sbRv8uqP396t1QcktZQFZWgFqsQHx1RB9wi
         my1aw6FbxPCjXiwxJMJ6RmH4j3TPN0iX3X1DFmQvjLekkKSQukIKeH5vuYvmYsVsEHpf
         LdhDx+mcyTvHWfAYMnMnVPUhbxpW/9vh70CofdcSJe8Ak8GMbVq0nT9mu74OFWZBNqKH
         Bbrg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1753708473; x=1754313273;
        h=in-reply-to:content-transfer-encoding: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=GDFjPQjNHLQQewbHjrCkwV119Zp5gq44Dp1xWV5F2p8=;
        b=OEW4dqrqDOJf/6i91NXOFeObfaZ+diKJ5s590pI60smRQFS+tqD0I6dgsjxhkJ14bq
         maKM7KUVqshHIpAxG8CPDx04TdkpEdrtHvRnsb+xNvIvW/t/T1XGECJum+9+z/owjMKH
         C7K/ZKZ+osRQU0Fh4vQqXD2UxWpcEpEuRtZji2gDSPa0Owl1b9dnc3ipmgwQoYA4UNZJ
         g/GyH3eZth8SUFFoNEqEh99vNbvRkntTjYNbkkx85OxQLDI9vl2Ve0uN6q7Meie2IPXn
         Z3kLy+bIqyk5SPbIaBP/Rssu07zgJqmcavKCGr8PQTf0VieC1SAloTjjbICIOzovnOPn
         Yd+A==
X-Forwarded-Encrypted: i=1; AJvYcCUBEnimLauPmkNpGj09h9aj4RS9pOEy0T7craBYBKIC4BE+zDjfd2Um8VzP6uR1YcFZ5sU=@vger.kernel.org, AJvYcCWue7APP3W09XrX3DHNJx+7JZRIn4CN5Ds6y5ZtS9s5EFdoxSL0hcbC84Mpc9lxkxTkfuI2ZGS96Y28isKS2i017LgG@vger.kernel.org, AJvYcCXGBNfB7wDsg0ujbVg7S+3asMVlCJrlcdAqN+LoD9p1i3eO9O8zbySCwiQ0LQu0JFIipyh0uMXtI4T7Pw5Z@vger.kernel.org
X-Gm-Message-State: AOJu0Yx7Ef26iyRPDGu8G8OcaV8mQ8BChDFFY2jmbt1rz1m3TUWMSTnZ
	Dhb2k+iyEX5NC4ISV0GuZhgGp44Tf3/i55jwnQ0EcK6dRuRt7aP/Z4TwRrWqUwEA
X-Gm-Gg: ASbGncuowiO9JSKCQ4Ch7VzT9pw4zHbhhm1q1R5jGLoKmgkst5u6YQU2mUxj4aH96hM
	g2lDRP8fzQom4IiXY8RMfTqZ7tpXe+qZ3eubKdsXo6DUSB5AvTsNSD1+K2duLqKnksSwxf4MpLT
	XxH/dK4QeT98rvlKpj1+o2nm5Hzi2dAILVY1NI7FZcUIImi5G1l/K/xVbu5o07Sw0F6tTRLljbu
	SKMUJng5/L4bDP7mNvv58oTMXUKYWW/psdddJg0oln2o6THPj/VW5edTw95YwUuBNdrTMPgY9Q+
	hr4ySX9LjoTF2vUDX+kZ5dIy0VRTdcJmrm1q03n5tPloiQc0DsPiXLzSe2FBIiTbMoACsYmjRlB
	PNupBAlvP
X-Google-Smtp-Source: AGHT+IF83yApWustjCzSkrFTYttoyXch6R12wpIEtH4ogxlT87k++Cqgfg8D/XP99YLhQssIGlD2EQ==
X-Received: by 2002:a17:906:c105:b0:ae3:69a8:8da4 with SMTP id a640c23a62f3a-af617203561mr1080690866b.9.1753708472267;
        Mon, 28 Jul 2025 06:14:32 -0700 (PDT)
Received: from krava ([173.38.220.53])
        by smtp.gmail.com with ESMTPSA id a640c23a62f3a-af635ad656fsm420271466b.121.2025.07.28.06.14.31
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Mon, 28 Jul 2025 06:14:31 -0700 (PDT)
From: Jiri Olsa <olsajiri@gmail.com>
X-Google-Original-From: Jiri Olsa <jolsa@kernel.org>
Date: Mon, 28 Jul 2025 15:14:30 +0200
To: Menglong Dong <menglong8.dong@gmail.com>
Cc: alexei.starovoitov@gmail.com, mhiramat@kernel.org, rostedt@goodmis.org,
	mathieu.desnoyers@efficios.com, hca@linux.ibm.com,
	revest@chromium.org, linux-kernel@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 0/4] fprobe: use rhashtable for fprobe_ip_table
Message-ID: <aId3tjPnh_NyRLSv@krava>
References: <20250728041252.441040-1-dongml2@chinatelecom.cn>
Precedence: bulk
X-Mailing-List: linux-trace-kernel@vger.kernel.org
List-Id: <linux-trace-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-trace-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-trace-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
In-Reply-To: <20250728041252.441040-1-dongml2@chinatelecom.cn>

On Mon, Jul 28, 2025 at 12:12:47PM +0800, Menglong Dong wrote:
> For now, the budget of the hash table that is used for fprobe_ip_table is
> fixed, which is 256, and can cause huge overhead when the hooked functions
> is a huge quantity.
> 
> In this series, we use rhashtable for fprobe_ip_table to reduce the
> overhead.
> 
> Meanwhile, we also add the benchmark testcase "kprobe-multi-all", which
> will hook all the kernel functions during the testing. Before this series,
> the performance is:
>   usermode-count :  875.380 ± 0.366M/s 
>   kernel-count   :  435.924 ± 0.461M/s 
>   syscall-count  :   31.004 ± 0.017M/s 
>   fentry         :  134.076 ± 1.752M/s 
>   fexit          :   68.319 ± 0.055M/s 
>   fmodret        :   71.530 ± 0.032M/s 
>   rawtp          :  202.751 ± 0.138M/s 
>   tp             :   79.562 ± 0.084M/s 
>   kprobe         :   55.587 ± 0.028M/s 
>   kprobe-multi   :   56.481 ± 0.043M/s 
>   kprobe-multi-all:    6.283 ± 0.005M/s << look this
>   kretprobe      :   22.378 ± 0.028M/s 
>   kretprobe-multi:   28.205 ± 0.025M/s
> 
> With this series, the performance is:
>   usermode-count :  897.083 ± 5.347M/s 
>   kernel-count   :  431.638 ± 1.781M/s 
>   syscall-count  :   30.807 ± 0.057M/s 
>   fentry         :  134.803 ± 1.045M/s 
>   fexit          :   68.763 ± 0.018M/s 
>   fmodret        :   71.444 ± 0.052M/s 
>   rawtp          :  202.344 ± 0.149M/s 
>   tp             :   79.644 ± 0.376M/s 
>   kprobe         :   55.480 ± 0.108M/s 
>   kprobe-multi   :   57.302 ± 0.119M/s 
>   kprobe-multi-all:   57.855 ± 0.144M/s << look this

nice, so the we still trigger one function, but having all possible
functions attached, right?

thanks,
jirka


>   kretprobe      :   22.265 ± 0.023M/s 
>   kretprobe-multi:   27.740 ± 0.023M/s
> 
> The benchmark of "kprobe-multi-all" increase from 6.283M/s to 57.855M/s.
> 
> Menglong Dong (4):
>   fprobe: use rhashtable
>   selftests/bpf: move get_ksyms and get_addrs to trace_helpers.c
>   selftests/bpf: add benchmark testing for kprobe-multi-all
>   selftests/bpf: skip recursive functions for kprobe_multi
> 
>  include/linux/fprobe.h                        |   2 +-
>  kernel/trace/fprobe.c                         | 144 ++++++-----
>  tools/testing/selftests/bpf/bench.c           |   2 +
>  .../selftests/bpf/benchs/bench_trigger.c      |  30 +++
>  .../selftests/bpf/benchs/run_bench_trigger.sh |   2 +-
>  .../bpf/prog_tests/kprobe_multi_test.c        | 220 +----------------
>  tools/testing/selftests/bpf/trace_helpers.c   | 230 ++++++++++++++++++
>  tools/testing/selftests/bpf/trace_helpers.h   |   3 +
>  8 files changed, 351 insertions(+), 282 deletions(-)
> 
> -- 
> 2.50.1
> 
> 

From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-yb1-f194.google.com (mail-yb1-f194.google.com [209.85.219.194])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25D401DDC23;
	Mon, 28 Jul 2025 14:36:53 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.194
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1753713415; cv=none; b=ufC+4yMWXP2cPRtH3iscXOxBQGu4j5oV15Dl+hOgLGEh++xiYcJo8b4Fy2T6FmOYjy6mM8TnH+gZkfoJCJ2//m1o/4LNB0FA5CTzliLgJa/2aQ0ND0RmIswozD8R06BMxyAbLlLR5SRi5Oj1NeUO15stG2nyIN7Ep5MhjHIN3QA=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1753713415; c=relaxed/simple;
	bh=QnrsrJuP1GBoHq8sg/d50wmv19fU3Un35JYEo0d8vCA=;
	h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:
	 To:Cc:Content-Type; b=D8FyhQGeIgvfQPX27mGVZ+3uA7jtZO+1gVn78b+5xixDRTJqd4GODmycx2qAkKrIx+vRzB9H4yRhg/9g3tUtoDQrFKN0ShSf7BdDuYZsCu5sSaUd2JhiUSNGB7gKpCTaOUi7xyXOD0oeFeEGEM51ZKUKnABpcuuYTPQRcdbK36s=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DxiGvI90; arc=none smtp.client-ip=209.85.219.194
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DxiGvI90"
Received: by mail-yb1-f194.google.com with SMTP id 3f1490d57ef6-e8e0fb4a2d2so923682276.1;
        Mon, 28 Jul 2025 07:36:53 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20230601; t=1753713413; x=1754318213; darn=vger.kernel.org;
        h=content-transfer-encoding:cc:to:subject:message-id:date:from
         :in-reply-to:references:mime-version:from:to:cc:subject:date
         :message-id:reply-to;
        bh=YQF8OLdFRkuLmNOLZ0xTeHW70hzSwwUMXvMZUwqZwwE=;
        b=DxiGvI90xBiLsC3Asxp/uLORTMISoWHCPwRW/rWzPUD1Kb4aBIbOOdODSu3WVS54Hw
         3HvvwtyO2JIQRJgytYsI6AKbtYS7ufOCRgV/LE98wV5Wpfbxch9uIlCsaYpVw+fyg1hU
         nFPLvqMzPxWcUAXQ+JL7+uZa7lvuNqE/mmESwRWVxAXqdtXb6P1CEfGozBuPQN2i2WY/
         gAUZ2IN6wUUS+6XvLTYQdG4khhGcoAdbR76VCQz9FJf8por8SaJzLjt9ZbimzJKNfPQw
         6//y52OYrfxuxIKu/q12F/eKmG2xnlFzEBxNU7U5ZMZVXIu2ZHB9y4LPcAR329ajto0m
         jBGQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1753713413; x=1754318213;
        h=content-transfer-encoding:cc:to:subject:message-id:date:from
         :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to;
        bh=YQF8OLdFRkuLmNOLZ0xTeHW70hzSwwUMXvMZUwqZwwE=;
        b=HPDwix3zdcaYlbE1+jCvJ9NaZRCnz3AIuEMiKv9xhFDKBJ+elfxNWoOXjMtWWNhQJw
         eC+UAL32Ybv6g4uatZZ55hN4LzTUsyD6/7Uc1O67bCMgzseTOlzGCmfRSY+fOoWJOQL9
         SVqkyy6rsjQtG09l5JTX2dNF9knATz2IZkBWx2y+QNDVy7rqSsdjHm4Yr7Nt6ggc6Ixh
         aE0g8Dohh3ORdbtdM5xk7xzcEeKUpYDH/qVmMOXMQ7QRPBWRYF1Ba8rOR2tlQo2cLO9/
         AVvv1kN04oXsqI3ovEWCjcfU8CPj79UZiF84hwchR0XOlM6tSu6JyixjrvrcyAhhvFtm
         b3qA==
X-Forwarded-Encrypted: i=1; AJvYcCUojwFTP7jq+BbO0YQUQazUFgGP3htOSfXyEAG8Ut0zT1K9x2e4K2O0piCswuDf32rZXK8=@vger.kernel.org, AJvYcCUxAr7oqXK1J7QdFa+tXwTDga7izf3a6vwFZTdo1eotYXWGkpotGmpW1tMFE++S30SzEaWzCCQSuaN+GsUk@vger.kernel.org, AJvYcCXlx2KNFq+TjjvuwMRo2ugq5TkW4SmLz2F7r61eDdTkSSSzUQ5y8E7pm26WvaOd5gWMeI/OXTBYsMJyVM3bKjzkmYWj@vger.kernel.org
X-Gm-Message-State: AOJu0YyT/qQqQmAUjQoHI0fWjaD4bxYusADXOCdasf9reBnajaAa90/b
	jd6O27NjqyxfDBxvwG+hgxA2H4FF0ovgwTFpbzeYaKAtvlnBzs4Adw4rn7qzySBp6r3F+Q12ZQ9
	yYBBWh3x+RiGebS5ogssL2XbCb44ESwE=
X-Gm-Gg: ASbGncsmNB3zKrhingH9ypsmrfmKnH6HcdgdYH0wKTcxs7WqlWNAHz/4wcQeH1PaEps
	axA23YEB4WTWx3NyZi/LDvX1/fYRFH386dqvpZyN3ghOZEqMKPzy/8Op93vjkF3Ca9PRlnS0UY8
	PSeLne6Xw3wKBi+nfARvNUGI58j/RGIP8S2nNVReka5mnrIFqGlkLKNy9Qj2sN9gXrmoDIXoMO0
	ZXKdkU=
X-Google-Smtp-Source: AGHT+IHTfterZh5K4FP62ikSM7yGnUdWojT8JqO/9s3TbF8LqdAE99foIreTsqNrhp3xLTH4bUnKCYSh3cETfn2htCs=
X-Received: by 2002:a05:6902:2587:b0:e8e:c03:75ac with SMTP id
 3f1490d57ef6-e8e0c037aa5mr6564522276.7.1753713412859; Mon, 28 Jul 2025
 07:36:52 -0700 (PDT)
Precedence: bulk
X-Mailing-List: linux-trace-kernel@vger.kernel.org
List-Id: <linux-trace-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-trace-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-trace-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
References: <20250728041252.441040-1-dongml2@chinatelecom.cn> <aId3tjPnh_NyRLSv@krava>
In-Reply-To: <aId3tjPnh_NyRLSv@krava>
From: Menglong Dong <menglong8.dong@gmail.com>
Date: Mon, 28 Jul 2025 22:36:42 +0800
X-Gm-Features: Ac12FXxyq9CpApNUdOi_nWDdjQ0ZtYIEVhqRonl51lRO2MPXFG0Olnk9FumpTvM
Message-ID: <CADxym3brzU=npXwSNUA7x1bCwyyyqgR49LwUzgxeka6ss6Jzrw@mail.gmail.com>
Subject: Re: [PATCH bpf-next 0/4] fprobe: use rhashtable for fprobe_ip_table
To: Jiri Olsa <olsajiri@gmail.com>
Cc: alexei.starovoitov@gmail.com, mhiramat@kernel.org, rostedt@goodmis.org, 
	mathieu.desnoyers@efficios.com, hca@linux.ibm.com, revest@chromium.org, 
	linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, 
	bpf@vger.kernel.org
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Mon, Jul 28, 2025 at 9:14=E2=80=AFPM Jiri Olsa <olsajiri@gmail.com> wrot=
e:
>
> On Mon, Jul 28, 2025 at 12:12:47PM +0800, Menglong Dong wrote:
> > For now, the budget of the hash table that is used for fprobe_ip_table =
is
> > fixed, which is 256, and can cause huge overhead when the hooked functi=
ons
> > is a huge quantity.
> >
> > In this series, we use rhashtable for fprobe_ip_table to reduce the
> > overhead.
> >
> > Meanwhile, we also add the benchmark testcase "kprobe-multi-all", which
> > will hook all the kernel functions during the testing. Before this seri=
es,
> > the performance is:
> >   usermode-count :  875.380 =C2=B1 0.366M/s
> >   kernel-count   :  435.924 =C2=B1 0.461M/s
> >   syscall-count  :   31.004 =C2=B1 0.017M/s
> >   fentry         :  134.076 =C2=B1 1.752M/s
> >   fexit          :   68.319 =C2=B1 0.055M/s
> >   fmodret        :   71.530 =C2=B1 0.032M/s
> >   rawtp          :  202.751 =C2=B1 0.138M/s
> >   tp             :   79.562 =C2=B1 0.084M/s
> >   kprobe         :   55.587 =C2=B1 0.028M/s
> >   kprobe-multi   :   56.481 =C2=B1 0.043M/s
> >   kprobe-multi-all:    6.283 =C2=B1 0.005M/s << look this
> >   kretprobe      :   22.378 =C2=B1 0.028M/s
> >   kretprobe-multi:   28.205 =C2=B1 0.025M/s
> >
> > With this series, the performance is:
> >   usermode-count :  897.083 =C2=B1 5.347M/s
> >   kernel-count   :  431.638 =C2=B1 1.781M/s
> >   syscall-count  :   30.807 =C2=B1 0.057M/s
> >   fentry         :  134.803 =C2=B1 1.045M/s
> >   fexit          :   68.763 =C2=B1 0.018M/s
> >   fmodret        :   71.444 =C2=B1 0.052M/s
> >   rawtp          :  202.344 =C2=B1 0.149M/s
> >   tp             :   79.644 =C2=B1 0.376M/s
> >   kprobe         :   55.480 =C2=B1 0.108M/s
> >   kprobe-multi   :   57.302 =C2=B1 0.119M/s
> >   kprobe-multi-all:   57.855 =C2=B1 0.144M/s << look this
>
> nice, so the we still trigger one function, but having all possible
> functions attached, right?

Yes. The test case can be improved further. For now,
I attach the prog bench_trigger_kprobe_multi to all the kernel
functions and triggers the benchmark. There can be some noise,
as all the kernel function calling can increase the benchmark
results. However, it will not make much difference.

A better choice will be: attach an empty kprobe_multi prog to
all the kernel functions except bpf_get_numa_node_id, and
attach bench_trigger_kprobe_multi to bpf_get_numa_node_id,
which can make the results more accurate.

>
> thanks,
> jirka
>
>
> >   kretprobe      :   22.265 =C2=B1 0.023M/s
> >   kretprobe-multi:   27.740 =C2=B1 0.023M/s
> >
> > The benchmark of "kprobe-multi-all" increase from 6.283M/s to 57.855M/s=
.
> >
> > Menglong Dong (4):
> >   fprobe: use rhashtable
> >   selftests/bpf: move get_ksyms and get_addrs to trace_helpers.c
> >   selftests/bpf: add benchmark testing for kprobe-multi-all
> >   selftests/bpf: skip recursive functions for kprobe_multi
> >
> >  include/linux/fprobe.h                        |   2 +-
> >  kernel/trace/fprobe.c                         | 144 ++++++-----
> >  tools/testing/selftests/bpf/bench.c           |   2 +
> >  .../selftests/bpf/benchs/bench_trigger.c      |  30 +++
> >  .../selftests/bpf/benchs/run_bench_trigger.sh |   2 +-
> >  .../bpf/prog_tests/kprobe_multi_test.c        | 220 +----------------
> >  tools/testing/selftests/bpf/trace_helpers.c   | 230 ++++++++++++++++++
> >  tools/testing/selftests/bpf/trace_helpers.h   |   3 +
> >  8 files changed, 351 insertions(+), 282 deletions(-)
> >
> > --
> > 2.50.1
> >
> >

From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-yb1-f195.google.com (mail-yb1-f195.google.com [209.85.219.195])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id D74F125C809;
	Mon, 28 Jul 2025 14:44:18 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.195
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1753713860; cv=none; b=KfArT2KJo9zYL4T7v0mjZ7YyX+kUaLVsQIURWQZDqS7TueOTX0T8hEltLgdcJFHgPV0QcQgwtXzEYr6NhgRMKp4R2HCHk/0ZZ+dHqKF49/MMbLtUpGTFf4VA80B2EwYnDJXLXNUMjAgq09BmzPaoCF1tG9AIYW4NSEqnqylrrQw=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1753713860; c=relaxed/simple;
	bh=wsr1LSR7+n0Itpa/QPxmLvKnRmNsZ0SzdvviS0DEzA8=;
	h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:
	 To:Cc:Content-Type; b=hAYxHJxC4TcJgJ/JFNfdmlnGRP2EWkAuJ5qPOdyeTiZZHBYwdLEyoh81YsXEtVNAziNBBhKaeYdrG3aY9erC65MHsC6pAEebfmxyHUJ4BGizXobeer3bzpRdvmXzCz4HFeVN1p/m7wTQhhqGHqd3Hb5yThrMfvbSwC/6REgG9SA=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IUo020F/; arc=none smtp.client-ip=209.85.219.195
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IUo020F/"
Received: by mail-yb1-f195.google.com with SMTP id 3f1490d57ef6-e8986a25cbfso2966072276.0;
        Mon, 28 Jul 2025 07:44:18 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20230601; t=1753713858; x=1754318658; darn=vger.kernel.org;
        h=content-transfer-encoding:cc:to:subject:message-id:date:from
         :in-reply-to:references:mime-version:from:to:cc:subject:date
         :message-id:reply-to;
        bh=hkhIo9S2NuUPn8Ju9aHWFElGQrfosb66aaSoTyONGdM=;
        b=IUo020F/qNkTExkXPuZcrT/9u1gBl9tFCmi/43wxYWMSZu84U68m71GIU41HicOuHa
         B3btFkW/Hxt791uhKF8udjO0zKKgck4RgHkhgI0POLuUT0/qSaRFhQfs053dhR1J+Xtj
         nl4xD+TWE0co3uvIA/LDZe0/1BJbYgKtKs5XLeGWdRlUw7kQs7GgDHWjW2AbLFWAMfTU
         uQPjut7CeetkRZ60i5wumUCdfrpDOuG/brKix56LrQUSVu22LFugJ+IqjPtzAhG/cJvI
         c/W8JozHdj9gGpYm98pynZXuqqgT5nnB/dMlgqV22bAGSmGK3OW0OMB5G1MGbewbM5M8
         mjCA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1753713858; x=1754318658;
        h=content-transfer-encoding:cc:to:subject:message-id:date:from
         :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to;
        bh=hkhIo9S2NuUPn8Ju9aHWFElGQrfosb66aaSoTyONGdM=;
        b=U3cTYzwjBgOVd0cz/+qev2GNMbj96D49Lhev3zDWPeBbTkYH4UVnymGZFMQAsvZGEu
         UbVStN/T7RohUOP8FsAiXQSV1+hOSt+7lcHqjO2VlqFdueslQ9fvexrEVfhQuVobUkp2
         VqxvPxLL2e314tjhzWhD5JygT1k6ysybI6NIZdraO81q8Mj3QYIqWlc5IoHOFLnPH0bh
         EB6aH+92TSDPlh0P4/CjDA0XjsxFLVtElc9mHdQYhCkPeLDUcJ+itHw+BKyhd91IUwiU
         9l5xDiLeAAi1juY9SLkjqtF8PmbvszQEccfy3Nxbe8q8reEzWIonw3JycKDfkce0Nzwh
         +i4w==
X-Forwarded-Encrypted: i=1; AJvYcCU8x6s/x5YSktFPYCeBMNCUViffA1gz554zkxHjCTChvNI5ze29xmrJ9den9Qcvxm+/RqdWeFjkx/aU3ClHAjqm/2qM@vger.kernel.org, AJvYcCUZywvVKqBK6VxJeowAWCY39QG8HwGv+lFKG3EiTa34OcwyaKkTgpHW+oOB2NrWSOOQhEk=@vger.kernel.org, AJvYcCV89/uMVOqIg49JQeCwOGrVRTQI924obGX48gUf15dKKuxp0Zw8CtmE5+fpg4eMcKLIMf8qrWOMB/5LJ/dO@vger.kernel.org
X-Gm-Message-State: AOJu0YzU2nblYTczp9f10WVuyHoUgedAu2ce4eRUzew/01bOTy+j/gUn
	kikhSknTLrFC1kpRT+0tdrSek8bnEtjCdbTHsGEsQU7eLeClJt1BTn5VWWGsXrIvwOtwocySu38
	cqybmiit8oe3B6flvPnq++Buvo3CYuis=
X-Gm-Gg: ASbGncsGFBzIBneECNZNTtqRyFn/qsmxLknrVpA+y99m6hMvj5adiFkpYmgxji9wmM+
	wVWL1CpF60IXMVrdblPqX5vtQE0I8222k3CHXb/wB6U3V6TLmqqItqsak4eXhxb6Dk/EszijGj2
	kX2hj+/sqDbfdAWL6t7SvhAxxUZ7JFQ+Qkccl6Tvkk7kITOJvrONn53bmmEU8r2TDG5TmX+aaA9
	Q7hbeo=
X-Google-Smtp-Source: AGHT+IGw+BV5iIkJd0xeq+J18BCm8tecXqc78tbEg2RaKDEo5C3nuDCIfgSCSjMoVOvoKdgqUIpwPyRO/aa0OjrYd+I=
X-Received: by 2002:a05:6902:701:b0:e8b:cf19:6675 with SMTP id
 3f1490d57ef6-e8df12529f5mr13184248276.33.1753713857691; Mon, 28 Jul 2025
 07:44:17 -0700 (PDT)
Precedence: bulk
X-Mailing-List: linux-trace-kernel@vger.kernel.org
List-Id: <linux-trace-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-trace-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-trace-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
References: <20250728041252.441040-1-dongml2@chinatelecom.cn>
 <20250728041252.441040-2-dongml2@chinatelecom.cn> <aId3ZSnlZRzoDUHC@krava>
In-Reply-To: <aId3ZSnlZRzoDUHC@krava>
From: Menglong Dong <menglong8.dong@gmail.com>
Date: Mon, 28 Jul 2025 22:44:07 +0800
X-Gm-Features: Ac12FXz9yDuGxyUUvq1yq2Xivxcq9LfAFipWjSp370RUODg_l7KddnP3JNIeLfk
Message-ID: <CADxym3YdOkcr-Jr-NkDUu4HqU7x_5Rwgiz6PS32BktGuLcBJRw@mail.gmail.com>
Subject: Re: [PATCH bpf-next 1/4] fprobe: use rhashtable
To: Jiri Olsa <olsajiri@gmail.com>
Cc: alexei.starovoitov@gmail.com, mhiramat@kernel.org, rostedt@goodmis.org, 
	mathieu.desnoyers@efficios.com, hca@linux.ibm.com, revest@chromium.org, 
	linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, 
	bpf@vger.kernel.org
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Mon, Jul 28, 2025 at 9:13=E2=80=AFPM Jiri Olsa <olsajiri@gmail.com> wrot=
e:
>
> On Mon, Jul 28, 2025 at 12:12:48PM +0800, Menglong Dong wrote:
>
> SNIP
>
> > +static const struct rhashtable_params fprobe_rht_params =3D {
> > +     .head_offset            =3D offsetof(struct fprobe_hlist_node, hl=
ist),
> > +     .key_offset             =3D offsetof(struct fprobe_hlist_node, ad=
dr),
> > +     .key_len                =3D sizeof_field(struct fprobe_hlist_node=
, addr),
> > +     .hashfn                 =3D fprobe_node_hashfn,
> > +     .obj_hashfn             =3D fprobe_node_obj_hashfn,
> > +     .obj_cmpfn              =3D fprobe_node_cmp,
> > +     .automatic_shrinking    =3D true,
> > +};
> >
> >  /* Node insertion and deletion requires the fprobe_mutex */
> >  static void insert_fprobe_node(struct fprobe_hlist_node *node)
> >  {
> > -     unsigned long ip =3D node->addr;
> > -     struct fprobe_hlist_node *next;
> > -     struct hlist_head *head;
> > -
> >       lockdep_assert_held(&fprobe_mutex);
> >
> > -     next =3D find_first_fprobe_node(ip);
> > -     if (next) {
> > -             hlist_add_before_rcu(&node->hlist, &next->hlist);
> > -             return;
> > -     }
> > -     head =3D &fprobe_ip_table[hash_ptr((void *)ip, FPROBE_IP_HASH_BIT=
S)];
> > -     hlist_add_head_rcu(&node->hlist, head);
> > +     rhashtable_insert_fast(&fprobe_ip_table, &node->hlist,
> > +                            fprobe_rht_params);
>
> onw that rhashtable_insert_fast can fail, I think insert_fprobe_node
> needs to be able to fail as well

You are right, the insert_fprobe_node should return a error and
be handled properly.

>
> >  }
> >
> >  /* Return true if there are synonims */
> > @@ -92,9 +93,11 @@ static bool delete_fprobe_node(struct fprobe_hlist_n=
ode *node)
> >       /* Avoid double deleting */
> >       if (READ_ONCE(node->fp) !=3D NULL) {
> >               WRITE_ONCE(node->fp, NULL);
> > -             hlist_del_rcu(&node->hlist);
> > +             rhashtable_remove_fast(&fprobe_ip_table, &node->hlist,
> > +                                    fprobe_rht_params);
>
> I guess this one can't fail in here.. ?

Yeah, the only failure is the entry doesn't exist in the hash
table.

BTW, the usage of rhltable is similar to rhashtable, and the
comment here is valid in the V2 too.

Thanks!
Menglong Dong

>
> jirka
>
> >       }
> > -     return !!find_first_fprobe_node(node->addr);
> > +     return !!rhashtable_lookup_fast(&fprobe_ip_table, &node->addr,
> > +                                     fprobe_rht_params);
> >  }
> >
>
> SNIP

From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C427221D92;
	Tue, 29 Jul 2025 03:43:25 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1753760607; cv=none; b=p3Y03ei1JavsPTi7r+1epd8/nvEpaBdRjqmoePQWGlN5vWXNp52NxjUIePpphipUjntt8xM4WHH8MTWXs15wZYVgfeTp/7roPNusQSOXmqae5lQCi0qTgdvDsmdBzs/zXYoX/Bqbsv5/31MG4aEYplc49+pGAEPPCcaAdPcvfmY=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1753760607; c=relaxed/simple;
	bh=MSHUoTMwY9oyY7Q1By+Pt8D/32X7z1oJYuHmG752vAk=;
	h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:
	 Content-Type:Content-Disposition:In-Reply-To; b=YMvImE7Rdv0kUSlXmJ4FjRSFwbBHeH5GO+jDU9m+VbNBA85y3I6a6/67OUJ28gyqu28/h8oTXSWkhZm7TTvBW/QaTNyV0G+O3yfNT8p316g0qWZ/af2oZA/BzJfdU54yUsaorCbC1azQqEud19FtjTYbH1XJr13S7DaIvtCSGJ4=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=KXnVZKJd; arc=none smtp.client-ip=198.175.65.16
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="KXnVZKJd"
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
  d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
  t=1753760605; x=1785296605;
  h=date:from:to:cc:subject:message-id:references:
   mime-version:in-reply-to;
  bh=MSHUoTMwY9oyY7Q1By+Pt8D/32X7z1oJYuHmG752vAk=;
  b=KXnVZKJduo1izaWZ6KJGoChfgyx7AL7YF+5a7lRCvS7q5Tl8Fi8Y0ZRF
   XkA8swUlpSZR3L4BQ9mWo6JQUpYl4xQiuJKrfGxxxet9WGIA3kuyuVaZ1
   Ax3AAdi5YnwfygZn0hRAHaNC3v1lPdcXJjAcTyqTKTL4dpIadjU9jLyMm
   aJtoMc4DNL0losDTW6b8IGqqHpd8OjHgP1EC8C7rNv0DdwDxKuQIHWxjB
   omkT/snzPxpo3rX88eiJgFcH8ukGhHAp7T4yEfGKTgD7qwawKxizNaKSQ
   tfNItF4CWrmEBX3iAlB4gp6QKuGVucAZ0QhjJttiOqGONFKc5EJyT9/Dv
   g==;
X-CSE-ConnectionGUID: 95OAQGZmTN6YA6TVmYAbJQ==
X-CSE-MsgGUID: e31MsPbTSVWiXnTEsWq4yA==
X-IronPort-AV: E=McAfee;i="6800,10657,11505"; a="56169093"
X-IronPort-AV: E=Sophos;i="6.16,348,1744095600"; 
   d="scan'208";a="56169093"
Received: from fmviesa002.fm.intel.com ([10.60.135.142])
  by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jul 2025 20:43:24 -0700
X-CSE-ConnectionGUID: SXW922UHQ2KYmkp/06qCFA==
X-CSE-MsgGUID: ObdttVA4S2SxFdfQh85pxQ==
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="6.16,348,1744095600"; 
   d="scan'208";a="186235766"
Received: from lkp-server01.sh.intel.com (HELO 160750d4a34c) ([10.239.97.150])
  by fmviesa002.fm.intel.com with ESMTP; 28 Jul 2025 20:43:21 -0700
Received: from kbuild by 160750d4a34c with local (Exim 4.96)
	(envelope-from <lkp@intel.com>)
	id 1ugbFH-0000xL-2p;
	Tue, 29 Jul 2025 03:43:19 +0000
Date: Tue, 29 Jul 2025 11:43:12 +0800
From: kernel test robot <lkp@intel.com>
To: Menglong Dong <menglong8.dong@gmail.com>, alexei.starovoitov@gmail.com,
	mhiramat@kernel.org
Cc: llvm@lists.linux.dev, oe-kbuild-all@lists.linux.dev,
	rostedt@goodmis.org, mathieu.desnoyers@efficios.com,
	hca@linux.ibm.com, revest@chromium.org,
	linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
	bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 1/4] fprobe: use rhashtable
Message-ID: <202507291147.Fov8pl4N-lkp@intel.com>
References: <20250728041252.441040-2-dongml2@chinatelecom.cn>
Precedence: bulk
X-Mailing-List: linux-trace-kernel@vger.kernel.org
List-Id: <linux-trace-kernel.vger.kernel.org>
List-Subscribe: <mailto:linux-trace-kernel+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-trace-kernel+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20250728041252.441040-2-dongml2@chinatelecom.cn>

Hi Menglong,

kernel test robot noticed the following build errors:

[auto build test ERROR on bpf-next/master]

url:    https://github.com/intel-lab-lkp/linux/commits/Menglong-Dong/fprobe-use-rhashtable/20250728-121631
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
patch link:    https://lore.kernel.org/r/20250728041252.441040-2-dongml2%40chinatelecom.cn
patch subject: [PATCH bpf-next 1/4] fprobe: use rhashtable
config: loongarch-allmodconfig (https://download.01.org/0day-ci/archive/20250729/202507291147.Fov8pl4N-lkp@intel.com/config)
compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250729/202507291147.Fov8pl4N-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202507291147.Fov8pl4N-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from kernel/trace/fprobe.c:8:
>> include/linux/fprobe.h:29:20: error: field has incomplete type 'struct rhash_head'
      29 |         struct rhash_head       hlist;
         |                                 ^
   include/linux/fprobe.h:29:9: note: forward declaration of 'struct rhash_head'
      29 |         struct rhash_head       hlist;
         |                ^
>> kernel/trace/fprobe.c:71:17: error: initializer element is not a compile-time constant
      71 |         .key_offset             = offsetof(struct fprobe_hlist_node, addr),
         |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/stddef.h:16:32: note: expanded from macro 'offsetof'
      16 | #define offsetof(TYPE, MEMBER)  __builtin_offsetof(TYPE, MEMBER)
         |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   2 errors generated.
--
   In file included from kernel/trace/trace_fprobe.c:9:
>> include/linux/fprobe.h:29:20: error: field has incomplete type 'struct rhash_head'
      29 |         struct rhash_head       hlist;
         |                                 ^
   include/linux/fprobe.h:29:9: note: forward declaration of 'struct rhash_head'
      29 |         struct rhash_head       hlist;
         |                ^
   1 error generated.


vim +29 include/linux/fprobe.h

    11	
    12	struct fprobe;
    13	typedef int (*fprobe_entry_cb)(struct fprobe *fp, unsigned long entry_ip,
    14				       unsigned long ret_ip, struct ftrace_regs *regs,
    15				       void *entry_data);
    16	
    17	typedef void (*fprobe_exit_cb)(struct fprobe *fp, unsigned long entry_ip,
    18				       unsigned long ret_ip, struct ftrace_regs *regs,
    19				       void *entry_data);
    20	
    21	/**
    22	 * struct fprobe_hlist_node - address based hash list node for fprobe.
    23	 *
    24	 * @hlist: The hlist node for address search hash table.
    25	 * @addr: One of the probing address of @fp.
    26	 * @fp: The fprobe which owns this.
    27	 */
    28	struct fprobe_hlist_node {
  > 29		struct rhash_head	hlist;
    30		unsigned long		addr;
    31		struct fprobe		*fp;
    32	};
    33	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

