From patchwork Sun Jan 30 09:29:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Tao X-Patchwork-Id: 12729768 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5785C433FE for ; Sun, 30 Jan 2022 09:30:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354457AbiA3JaD (ORCPT ); Sun, 30 Jan 2022 04:30:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354455AbiA3JaC (ORCPT ); Sun, 30 Jan 2022 04:30:02 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DAB8C061714; Sun, 30 Jan 2022 01:30:01 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id z14-20020a17090ab10e00b001b6175d4040so9472132pjq.0; Sun, 30 Jan 2022 01:30:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hwhiK/i0m2gMPbUVcACp59cbViDIBKcuhYUz1Evs1T8=; b=SuD27Uwt0VDKSTE/hpK3UZuAUqFXHAvhFsvcLUhQRKTsYPHnRI0c6V0HyqeD2GB4Lt 3131mhQojJSEJ1QRUJCStJrmlGncfYqKyz6x8w5sG/+oPwXivgY5zT1bqATqP2FSaNqN EWXwhewG8LIWvVScBum9ffoC8MxRNFsC2RFTo+QmK9teDyZH1dJ7jHnFGoSOSQj6zqpQ sqwmvXtZu9JYtOpnAPk2H3T9IA0AZv/QW10jukl1ISXqEaZsHLsGzWLKhs9M4lDF3s8m 1y6rk0ngTzfYApmqjGiTgdZRSdwVSQEuZJ5i2IMaK5yx+OL9Pg/l4Y979H4ci84g2379 kinA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hwhiK/i0m2gMPbUVcACp59cbViDIBKcuhYUz1Evs1T8=; b=vVdub2RmV4Iu8ndvt76cPdwZ1IK16ajCxaDtEx/P9KRt1lCs3EewYD9ZNK0pG30m9z 638DVMkHVx+nECyrYM4mfFbLj723ccVEQ66+YifnInPAi4kLid/3+XAqaNZO0skSkFOJ bobMJSfwzDiHcMOlt8l0JNOit1FXQlPijzM4nyP19BH65RgMraxCD/ah2Weg8JduGBIu jD3HjwaJIuL3veTEhS938VIDHUXprcCJO4RYKvCfcMW6bBvxa/tK7tTsQaARkoSNdAY/ huFZCaBph8poJ346bKb1GYhiN7wP+uiDRmhdPp4KcPekZzbRhDkIGDCa6MyKD7Vu9X5+ 10IQ== X-Gm-Message-State: AOAM530KwaVvYTyqAZG9wSoMTd+TySLQUCUQszs0g1D4vkeB8BjInNO9 JIUAIwS4Cs6RFNZv4vl93nc= X-Google-Smtp-Source: ABdhPJxiXht9rQ0HJ5RMTZeHOXNaz82mVp0MXPm3OIsOJ7xyLtnXTTg6KUALVdRw3mTcR2Z9AEXxrQ== X-Received: by 2002:a17:903:2290:: with SMTP id b16mr16037097plh.103.1643535001397; Sun, 30 Jan 2022 01:30:01 -0800 (PST) Received: from localhost (61-223-193-169.dynamic-ip.hinet.net. [61.223.193.169]) by smtp.gmail.com with ESMTPSA id e28sm1159654pgm.23.2022.01.30.01.30.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jan 2022 01:30:00 -0800 (PST) From: Hou Tao To: Daniel Borkmann Cc: Alexei Starovoitov , Martin KaFai Lau , Yonghong Song , Andrii Nakryiko , "David S . Miller" , Jakub Kicinski , John Fastabend , netdev@vger.kernel.org, bpf@vger.kernel.org, houtao1@huawei.com, Zi Shen Lim , Catalin Marinas , Will Deacon , Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Subject: [PATCH bpf-next v3 1/3] bpf, arm64: enable kfunc call Date: Sun, 30 Jan 2022 17:29:15 +0800 Message-Id: <20220130092917.14544-2-hotforest@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220130092917.14544-1-hotforest@gmail.com> References: <20220130092917.14544-1-hotforest@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Hou Tao Since commit b2eed9b58811 ("arm64/kernel: kaslr: reduce module randomization range to 2 GB"), for arm64 whether KASLR is enabled or not, the module is placed within 2GB of the kernel region, so s32 in bpf_kfunc_desc is sufficient to represente the offset of module function relative to __bpf_call_base. The only thing needed is to override bpf_jit_supports_kfunc_call(). Signed-off-by: Hou Tao --- arch/arm64/net/bpf_jit_comp.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c index e96d4d87291f..74f9a9b6a053 100644 --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -1143,6 +1143,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog) return prog; } +bool bpf_jit_supports_kfunc_call(void) +{ + return true; +} + u64 bpf_jit_alloc_exec_limit(void) { return VMALLOC_END - VMALLOC_START; From patchwork Sun Jan 30 09:29:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Tao X-Patchwork-Id: 12729769 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86E51C433F5 for ; Sun, 30 Jan 2022 09:30:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354459AbiA3Ja1 (ORCPT ); Sun, 30 Jan 2022 04:30:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234034AbiA3Ja0 (ORCPT ); Sun, 30 Jan 2022 04:30:26 -0500 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 869F0C061714; Sun, 30 Jan 2022 01:30:26 -0800 (PST) Received: by mail-pf1-x432.google.com with SMTP id d187so10192189pfa.10; Sun, 30 Jan 2022 01:30:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YlVRxz39fY5cRLJn+loRiR0FbZ2jN676CvPNPpw0e+M=; b=Z8bDKdXGnZSNdZMBJsP78ZxDzyQ8c6cgyUV1W4+4PUW8JjCkqPkRP3iwOLKjT5Edpa tmNhUBe3z5KexUux9yAuKJzguTvrNtKFs1rM+24eULlsCqqoh+MG049e9KHTB/zaePx1 EOCscBUkMpVO+5W6yPAaWvmMg0qSD2UbX28DufA6/KBhZdpw3jcW8CPw2UfqzHPBHnjh +8Zo+RjBZ1j8vgRRttsw7bGFxQxXHtdLlUDkc0CdjRCf/xLtfxTiaVn48Qptn0O+PGbm AiALGN8p7Vj8vJvdlMmQAGgtLeRrePYtUfLsytJJTAJqNqpDfy+h6moIh+TKn/jd3kC/ S18A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YlVRxz39fY5cRLJn+loRiR0FbZ2jN676CvPNPpw0e+M=; b=Z6EDlmnm86YC3y2DRJm98yLSdE6qBEMzButkzjxsg4ul55WyxGLXVmiQEWmhv1JKGn jegEqBiX+vRXrrlhWJECuqFK0uAGj274Pamf66H8r0VBRgj/ZcVPQXY3Uv9bFI6PgbLv xJIylO4haU/4MfqC/t4gvfaiR/BvyU7xPlUizqdaHeQisa10bMxsRGRfZPWILYqNaSiZ T3tWMbPYKkIhnF5joJ3zY3ppoJoxW/jXhTpTKmFPPcZxZflKVN5Kcikxeu2MUmcimKtz lldJuV4ugNN44gVyqH2QHfC0l2NbCO5lDnHUhALCr2U3Eh38OLS4/VpBEKtSEzNxMPXG uLWg== X-Gm-Message-State: AOAM53351soomB8Vc/wAp3ZnLcJYl/53ftg37XXlonJMKekGiLuMBjYi /GXoneDPJ7KqcEt5dUINFdc= X-Google-Smtp-Source: ABdhPJz5sN9mXEcVRNmRul1bu2ljG6NHpaiOD+Mnw+OkBHrJQc6TnmXVJcIgEBiUd2tskW/Xudeftw== X-Received: by 2002:a63:2326:: with SMTP id j38mr12839349pgj.346.1643535026074; Sun, 30 Jan 2022 01:30:26 -0800 (PST) Received: from localhost (61-223-193-169.dynamic-ip.hinet.net. [61.223.193.169]) by smtp.gmail.com with ESMTPSA id t11sm497032pgi.90.2022.01.30.01.30.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jan 2022 01:30:25 -0800 (PST) From: Hou Tao To: Daniel Borkmann Cc: Alexei Starovoitov , Martin KaFai Lau , Yonghong Song , Andrii Nakryiko , "David S . Miller" , Jakub Kicinski , John Fastabend , netdev@vger.kernel.org, bpf@vger.kernel.org, houtao1@huawei.com, Zi Shen Lim , Catalin Marinas , Will Deacon , Ard Biesheuvel , linux-arm-kernel@lists.infradead.org, Hou Tao Subject: [PATCH bpf-next v3 2/3] selftests/bpf: do not export subtest as standalone test Date: Sun, 30 Jan 2022 17:29:16 +0800 Message-Id: <20220130092917.14544-3-hotforest@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220130092917.14544-1-hotforest@gmail.com> References: <20220130092917.14544-1-hotforest@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Two subtests in ksyms_module.c are not qualified as static, so these subtests are exported as standalone tests in tests.h and lead to confusion for the output of "./test_progs -t ksyms_module". By using the following command: grep "^void \(serial_\)\?test_[a-zA-Z0-9_]\+(\(void\)\?)" \ tools/testing/selftests/bpf/prog_tests/*.c | \ awk -F : '{print $1}' | sort | uniq -c | awk '$1 != 1' Find out that other tests also have the similar problem, so fix these tests by marking subtests in these tests as static. For xdp_adjust_frags.c, there is just one subtest, so just export the subtest directly. Signed-off-by: Hou Tao --- tools/testing/selftests/bpf/prog_tests/ksyms_module.c | 4 ++-- tools/testing/selftests/bpf/prog_tests/xdp_adjust_frags.c | 6 ------ tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c | 4 ++-- tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c | 4 ++-- tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c | 2 +- 5 files changed, 7 insertions(+), 13 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/ksyms_module.c b/tools/testing/selftests/bpf/prog_tests/ksyms_module.c index d490ad80eccb..997aa90dea64 100644 --- a/tools/testing/selftests/bpf/prog_tests/ksyms_module.c +++ b/tools/testing/selftests/bpf/prog_tests/ksyms_module.c @@ -6,7 +6,7 @@ #include "test_ksyms_module.lskel.h" #include "test_ksyms_module.skel.h" -void test_ksyms_module_lskel(void) +static void test_ksyms_module_lskel(void) { struct test_ksyms_module_lskel *skel; int retval; @@ -30,7 +30,7 @@ void test_ksyms_module_lskel(void) test_ksyms_module_lskel__destroy(skel); } -void test_ksyms_module_libbpf(void) +static void test_ksyms_module_libbpf(void) { struct test_ksyms_module *skel; int retval, err; diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_frags.c b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_frags.c index 31c188666e81..6ca3582bb056 100644 --- a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_frags.c +++ b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_frags.c @@ -96,9 +96,3 @@ void test_xdp_update_frags(void) out: bpf_object__close(obj); } - -void test_xdp_adjust_frags(void) -{ - if (test__start_subtest("xdp_adjust_frags")) - test_xdp_update_frags(); -} diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c index ccc9e63254a8..a254c54c3ada 100644 --- a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c +++ b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c @@ -118,7 +118,7 @@ static void test_xdp_adjust_tail_grow2(void) bpf_object__close(obj); } -void test_xdp_adjust_frags_tail_shrink(void) +static void test_xdp_adjust_frags_tail_shrink(void) { const char *file = "./test_xdp_adjust_tail_shrink.o"; __u32 duration, retval, size, exp_size; @@ -180,7 +180,7 @@ void test_xdp_adjust_frags_tail_shrink(void) bpf_object__close(obj); } -void test_xdp_adjust_frags_tail_grow(void) +static void test_xdp_adjust_frags_tail_grow(void) { const char *file = "./test_xdp_adjust_tail_grow.o"; __u32 duration, retval, size, exp_size; diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c b/tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c index 13aabb3b6cf2..15e48098c8b8 100644 --- a/tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c +++ b/tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c @@ -8,7 +8,7 @@ #define IFINDEX_LO 1 -void test_xdp_with_cpumap_helpers(void) +static void test_xdp_with_cpumap_helpers(void) { struct test_xdp_with_cpumap_helpers *skel; struct bpf_prog_info info = {}; @@ -68,7 +68,7 @@ void test_xdp_with_cpumap_helpers(void) test_xdp_with_cpumap_helpers__destroy(skel); } -void test_xdp_with_cpumap_frags_helpers(void) +static void test_xdp_with_cpumap_frags_helpers(void) { struct test_xdp_with_cpumap_frags_helpers *skel; struct bpf_prog_info info = {}; diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c b/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c index 2a784ccd3136..08d074ec471d 100644 --- a/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c +++ b/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c @@ -81,7 +81,7 @@ static void test_neg_xdp_devmap_helpers(void) } } -void test_xdp_with_devmap_frags_helpers(void) +static void test_xdp_with_devmap_frags_helpers(void) { struct test_xdp_with_devmap_frags_helpers *skel; struct bpf_prog_info info = {}; From patchwork Sun Jan 30 09:29:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Tao X-Patchwork-Id: 12729770 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3CE43C4332F for ; Sun, 30 Jan 2022 09:30:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354471AbiA3Jaf (ORCPT ); Sun, 30 Jan 2022 04:30:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354465AbiA3Jae (ORCPT ); Sun, 30 Jan 2022 04:30:34 -0500 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E697DC061714; Sun, 30 Jan 2022 01:30:33 -0800 (PST) Received: by mail-pj1-x1034.google.com with SMTP id g15-20020a17090a67cf00b001b7d5b6bedaso1551871pjm.4; Sun, 30 Jan 2022 01:30:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ueDBeTvh6E3uYQIJcGjSDWIJHO5uP2AyA8BgDmH0/x8=; b=XAnu+rkl3csF10DXVpN8bDe05Ux7nKR5lL63gaV21DqAS2Lj1ls2o1Cu5pH7ZpmZ4U J3MadUSTy0rG2LDOx2zHogcXGtRxrP4RAOUhpMZMglJYfBmWTgZMm9hjVmYEjAX0LTTw basatcDS5iq9Lndx1t49VWoKx0L3ycTw5nbvhbDZF71QrsdSi5FGNjbkruEvqRh27c8P G0ieH8ivE5JajurByZgm312WBAj03sJkaksquBSCzJdG3ISWNFEdwseT/lV4As3Qc8ON amVc8PJJmYaiHCunuSq+NT3MKcnlw+nMwW4gkkYiAMLqIEHXg5CYDofSnmqk7cn2+hbU +psA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ueDBeTvh6E3uYQIJcGjSDWIJHO5uP2AyA8BgDmH0/x8=; b=w5KG2jvfa4CyOXjFM9sDPUaG83v6bO9420T3/HMGmuE446qMFEqisQjnICWvA7cFV7 yM0Fp8f0jlQc9ER+nk98mNNAFqIMxAb8RCG9nxhjDpmI19qktn0sJLW/fC0Cj43lNvfi cWfMweuKjXA6mVrR6FD8dum2V+eZSYVnlEYbQMnVp40WWHj3zgrLKHD6KyZ0KUEwn9ES YOgHSj69AG7Sbh5fe0OISkKhNn6GuS2Z3333Sc34Vrr75t5jrh3jsnrFOCIz0BQcAyg/ Dnz/GtJP16Lky6Tvx4pmKvPefMFBWiJMdc0qGOR5zK9r4ZyAqOI1G5JdHZ8GyPyKOsL8 TXQw== X-Gm-Message-State: AOAM530bJnkN5ph04PQl2zkwpmfcStPf1vFM7WY8YOOpkfNr7+7V/zyM jU8UjGqsRypNFWkGbKriRLQ= X-Google-Smtp-Source: ABdhPJxvClpGoupxFezGR1EJD5z2XSnsdE9wibhe+RrEz2KSCaDlkw1IP1xkBk9tmMVZw2wDkjXl5w== X-Received: by 2002:a17:902:bcc6:: with SMTP id o6mr16526122pls.116.1643535033488; Sun, 30 Jan 2022 01:30:33 -0800 (PST) Received: from localhost (61-223-193-169.dynamic-ip.hinet.net. [61.223.193.169]) by smtp.gmail.com with ESMTPSA id o7sm13641025pfk.184.2022.01.30.01.30.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jan 2022 01:30:32 -0800 (PST) From: Hou Tao To: Daniel Borkmann Cc: Alexei Starovoitov , Martin KaFai Lau , Yonghong Song , Andrii Nakryiko , "David S . Miller" , Jakub Kicinski , John Fastabend , netdev@vger.kernel.org, bpf@vger.kernel.org, houtao1@huawei.com, Zi Shen Lim , Catalin Marinas , Will Deacon , Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Subject: [PATCH bpf-next v3 3/3] selftests/bpf: check whether s32 is sufficient for kfunc offset Date: Sun, 30 Jan 2022 17:29:17 +0800 Message-Id: <20220130092917.14544-4-hotforest@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220130092917.14544-1-hotforest@gmail.com> References: <20220130092917.14544-1-hotforest@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Hou Tao In add_kfunc_call(), bpf_kfunc_desc->imm with type s32 is used to represent the offset of called kfunc from __bpf_call_base, so add a test to ensure that the offset will not be overflowed. Signed-off-by: Hou Tao --- .../selftests/bpf/prog_tests/ksyms_module.c | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/ksyms_module.c b/tools/testing/selftests/bpf/prog_tests/ksyms_module.c index 997aa90dea64..955a9ede4756 100644 --- a/tools/testing/selftests/bpf/prog_tests/ksyms_module.c +++ b/tools/testing/selftests/bpf/prog_tests/ksyms_module.c @@ -3,9 +3,49 @@ #include #include +#include #include "test_ksyms_module.lskel.h" #include "test_ksyms_module.skel.h" +/* + * Check whether or not s32 in bpf_kfunc_desc is sufficient + * to represent the offset between bpf_testmod_test_mod_kfunc + * and __bpf_call_base. + */ +static void test_ksyms_module_valid_offset(void) +{ + struct test_ksyms_module *skel; + unsigned long long kfunc_addr; + unsigned long long base_addr; + long long actual_offset; + int used_offset; + int err; + + if (!env.has_testmod) { + test__skip(); + return; + } + + /* Ensure kfunc call is supported */ + skel = test_ksyms_module__open_and_load(); + if (!ASSERT_OK_PTR(skel, "test_ksyms_module__open")) + return; + + err = kallsyms_find("bpf_testmod_test_mod_kfunc", &kfunc_addr); + if (!ASSERT_OK(err, "find kfunc addr")) + goto cleanup; + + err = kallsyms_find("__bpf_call_base", &base_addr); + if (!ASSERT_OK(err, "find base addr")) + goto cleanup; + + used_offset = kfunc_addr - base_addr; + actual_offset = kfunc_addr - base_addr; + ASSERT_EQ((long long)used_offset, actual_offset, "kfunc offset overflowed"); +cleanup: + test_ksyms_module__destroy(skel); +} + static void test_ksyms_module_lskel(void) { struct test_ksyms_module_lskel *skel; @@ -55,6 +95,8 @@ static void test_ksyms_module_libbpf(void) void test_ksyms_module(void) { + if (test__start_subtest("valid_offset")) + test_ksyms_module_valid_offset(); if (test__start_subtest("lskel")) test_ksyms_module_lskel(); if (test__start_subtest("libbpf"))