Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp824835ybt; Wed, 1 Jul 2020 10:56:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwaQ0L1EgF8U6v4FrUml6OPpGWKcAppkUCyUCnzTxq/lMIhShEDF6iZRz0153V+Fp+6zLO2 X-Received: by 2002:a50:e8c8:: with SMTP id l8mr31154672edn.386.1593626170477; Wed, 01 Jul 2020 10:56:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593626170; cv=none; d=google.com; s=arc-20160816; b=ff74R3TyNK+f5GpSxGye070G0SgW+93FJbjh+n1wXPeP+2IbD3MPNAbLXAVk8+pTWK pi+FUHQ94JouGiv+pk+lC5brws/+lnw82rNyHnK1GgUcAyGN4pAvVx89eVsYZkpruHpn KC8IQztkyGWYsW2z7UfNGHftL+l+klYhifzxU2e8vtn9yGsVzm1ckj0y2vSzL93vAfYA RnGXl1zBZ8zQGfVVSj0zLVJSuh9SGdEsNGzGbAgjYNZuKass/Ag5KbeyRCasNvU7boOm 9HfpIT3e9OuhaOEM//l5ljtt5aI7s+AGGeqsB2jJhOjXjLbXcjlU36e2uQPgy+JAhoEq OOsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=VB/KSdoSleNPyuddI4RHZwpZo8dMr4vfXtKSdI4JDW8=; b=qkaBx2QObCWTLLOlF+knlW3LM3O6pXiD3iCV8vyJyhGGQU7xAAYjIikhdfSKvg2jOI /ZNsen2EtDCNK57stk1gYEZ9q0fqOWPBpIO1RL7DtRnOzRFJoMMCwtKNhd5ViWqR8bid dfC+wsY+t0RyAbOHJJH6AIjvEcS5vzCH0Uo2gNYo2eSHoSAOQ6MEZPmxI8sqLLHsHlV9 EdIvKEKggbLGMfBSEPHvJni3NyD2aQ8dx7fJH1Jx5CZqKqnFSMwmDT+HYgsqmUSgRnSf 3rAe1vUz9xKTlyOjHTKYNOkQU3fQYqndvq3gU/elLgQkhN9MaBj9875C71IyWEswLq5s 77vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Ufhtwlfr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id yd21si4093299ejb.727.2020.07.01.10.55.46; Wed, 01 Jul 2020 10:56:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Ufhtwlfr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731171AbgGARxU (ORCPT + 99 others); Wed, 1 Jul 2020 13:53:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726449AbgGARxT (ORCPT ); Wed, 1 Jul 2020 13:53:19 -0400 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59C28C08C5DC for ; Wed, 1 Jul 2020 10:53:19 -0700 (PDT) Received: by mail-qt1-x84a.google.com with SMTP id h10so3834145qtc.4 for ; Wed, 01 Jul 2020 10:53:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=VB/KSdoSleNPyuddI4RHZwpZo8dMr4vfXtKSdI4JDW8=; b=UfhtwlfrE3cJUVoe4WVJG0157tIrGS4kww4M+vCDEfR+MCtIiF4OHtsu8K6QHxFgSL H0UHxeRL8rCoT0xjdG6BeSd9Vzya6G5s6MvHiwqdFlGdqTCJaXXJeUrqNTHrlVNwFpaR A/ANM+yVtI8e/dEMoZKYYul4ntUXW8V2/F3LhRlIYDNn0RqTajLdXN0eMWaTagt9HVCl hPG3cFJQIU2bTRi3IzGl4NTUH9f4NgKrXrfdnIIG/RuFR9rCo/VuMGRcXIqsQ6GT+ndI hQVRM0DybGmWejTnFp3mJO8RGffIZPtnhuFSu3QvgYT4djdjGnsgFSyEwHF1fOuWUomu wvqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=VB/KSdoSleNPyuddI4RHZwpZo8dMr4vfXtKSdI4JDW8=; b=R0pOV2K1MhwHaWwk27lrH9TwprG42AkoeVBNflZvLdyC96cnN18Jqx20vWdA6yuEjh HAXodqeM7Rd3erRT9dGnwo28KjzxFilJmhepIkhdL47tjSX4VwHj5HrPhyp3fff8a7S1 dPHQXMmIp5nlFa4r8YffwDyvRKSywmrE9nnX/GdP7LbbkQdWjOmNfWGyNHlptVyZUHxW s3D8c4JP/o1fTcgMLUDBkPZJ8/0QovEqgICyL/quXM9hCuBNX0RbY+v4nTWGPCfqdDv6 UErkD8zx8dtgKwau7EgJJLEoaUBxggupYr3u9ckaqjb3Q1BOvgvR7YY/4x24ktcU1rH/ GGjA== X-Gm-Message-State: AOAM531Jxk3v9FFhj/uZckr5z25SLq1W3Qb0I3/mgRrITty6dt5YKVdI IQNDmhskq8F6ioQg8cmsN0GxIuRjllE= X-Received: by 2002:a0c:8b4a:: with SMTP id d10mr26091444qvc.31.1593625998237; Wed, 01 Jul 2020 10:53:18 -0700 (PDT) Date: Wed, 1 Jul 2020 10:53:15 -0700 Message-Id: <20200701175315.1161242-1-haoluo@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.27.0.212.ge8ba1cc988-goog Subject: [PATCH bpf-next v2] selftests/bpf: Switch test_vmlinux to use hrtimer_range_start_ns. From: Hao Luo To: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com Cc: sdf@google.com, Shuah Khan , Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Hao Luo , linux-kselftest@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The test_vmlinux test uses hrtimer_nanosleep as hook to test tracing programs. But in a kernel built by clang, which performs more aggresive inlining, that function gets inlined into its caller SyS_nanosleep. Therefore, even though fentry and kprobe do hook on the function, they aren't triggered by the call to nanosleep in the test. A possible fix is switching to use a function that is less likely to be inlined, such as hrtimer_range_start_ns. The EXPORT_SYMBOL functions shouldn't be inlined based on the description of [1], therefore safe to use for this test. Also the arguments of this function include the duration of sleep, therefore suitable for test verification. [1] af3b56289be1 time: don't inline EXPORT_SYMBOL functions Tested: In a clang build kernel, before this change, the test fails: test_vmlinux:PASS:skel_open 0 nsec test_vmlinux:PASS:skel_attach 0 nsec test_vmlinux:PASS:tp 0 nsec test_vmlinux:PASS:raw_tp 0 nsec test_vmlinux:PASS:tp_btf 0 nsec test_vmlinux:FAIL:kprobe not called test_vmlinux:FAIL:fentry not called After switching to hrtimer_range_start_ns, the test passes: test_vmlinux:PASS:skel_open 0 nsec test_vmlinux:PASS:skel_attach 0 nsec test_vmlinux:PASS:tp 0 nsec test_vmlinux:PASS:raw_tp 0 nsec test_vmlinux:PASS:tp_btf 0 nsec test_vmlinux:PASS:kprobe 0 nsec test_vmlinux:PASS:fentry 0 nsec Signed-off-by: Hao Luo Acked-by: Andrii Nakryiko --- Changelog since v1: - More accurate commit messages tools/testing/selftests/bpf/progs/test_vmlinux.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/bpf/progs/test_vmlinux.c b/tools/testing/selftests/bpf/progs/test_vmlinux.c index 5611b564d3b1..29fa09d6a6c6 100644 --- a/tools/testing/selftests/bpf/progs/test_vmlinux.c +++ b/tools/testing/selftests/bpf/progs/test_vmlinux.c @@ -63,20 +63,20 @@ int BPF_PROG(handle__tp_btf, struct pt_regs *regs, long id) return 0; } -SEC("kprobe/hrtimer_nanosleep") -int BPF_KPROBE(handle__kprobe, - ktime_t rqtp, enum hrtimer_mode mode, clockid_t clockid) +SEC("kprobe/hrtimer_start_range_ns") +int BPF_KPROBE(handle__kprobe, struct hrtimer *timer, ktime_t tim, u64 delta_ns, + const enum hrtimer_mode mode) { - if (rqtp == MY_TV_NSEC) + if (tim == MY_TV_NSEC) kprobe_called = true; return 0; } -SEC("fentry/hrtimer_nanosleep") -int BPF_PROG(handle__fentry, - ktime_t rqtp, enum hrtimer_mode mode, clockid_t clockid) +SEC("fentry/hrtimer_start_range_ns") +int BPF_PROG(handle__fentry, struct hrtimer *timer, ktime_t tim, u64 delta_ns, + const enum hrtimer_mode mode) { - if (rqtp == MY_TV_NSEC) + if (tim == MY_TV_NSEC) fentry_called = true; return 0; } -- 2.27.0.212.ge8ba1cc988-goog