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: 12729773 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 63971C433F5 for ; Sun, 30 Jan 2022 09:31:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=WGb96aHqenGfP9C62GQGPfunMm7YAosRN14AhoRa4qc=; b=hXInxJAdMj6WK/ QBvABBq6WBuOi0jQMLAYiL/OczR6z9Q/lmQa5Pd3G5zXOoRmQrFdRBW378F3DeKMdAqFbdl/FvE8F LUj69xirdBHiUUWc8j6GEqKzF8hZi02NRqV5LdIsJSmORsOPFqVvM61k58Bo0tcNKtLL497lnyYpr QBdo+UQ9randxc8sSZhuJ5vPFCiGgcIOIlNy8FultCbg4LnJebm+RT+lMpAnz/7YoYxPTQDkc9YMH u0wOpVN01K7SbTrK9w0dcNv5j8ASZW53LAAr/8nQRP5zs7AoGWpBrkUeOKl0O9FhgQTpQ1TFBQdQ5 j3fHuDz2WxocbTuNwuSg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nE6XF-006F0k-6G; Sun, 30 Jan 2022 09:30:13 +0000 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nE6X4-006EyQ-B1 for linux-arm-kernel@lists.infradead.org; Sun, 30 Jan 2022 09:30:03 +0000 Received: by mail-pj1-x102d.google.com with SMTP id h20-20020a17090adb9400b001b518bf99ffso15216693pjv.1 for ; 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=taoqssLL6qEVrzCH4Cu4cqFs1AH8U8XE5IYKIFulJ92LFEsp+UV4VPHZQgAbI8N4hK atuewayCol9qRdvU81AlIBLu0P6WzeahbKCIKwE6gQUvAPXYbpFBg0zlW7CPskacYnLw Y/k/XkGi9X6VurKxD9D3XwJQ0wWFSl8m8phbbFUcMzzGMeToUswOKIht5ITDEC5I7VcQ 3n7PpNI1PIuTbyVac/Q0dWi5oDlmSTIgyHC6J2YgI0HtpU+LZYPnuh1BACGi1+SCh5ep TMsO8A8ebBZoPCvDCUkat8EZY22I3mMZEWiitKV8HrhKOiXq4uQ/X7HZy9WQHE0lEGV2 NecA== X-Gm-Message-State: AOAM531sLXZMJUOqUn70KlSchjmHgfieymZpE7KsK/2QYPvfQ2CSS9kU SkdlT9J9TTxgdwmefqfLT1I= 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220130_013002_456056_C136D56B X-CRM114-Status: UNSURE ( 9.91 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 12729772 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 858CCC433FE for ; Sun, 30 Jan 2022 09:31:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=A56wMp+l4XRNQTDoP0Eunaw61NLvcEyRL/l1TEyDCFk=; b=pm7hTB4F83DPDR c8hh8U7ZAL7yJi0PUEkCgL9TNlZEUf+XOK1avXhwJbTDmUrqHGlC2sUpSvVKNafdSgagF/7RqNfHk dTYzG6Hrqa1D2rlfrud2V69gxdbKkNIabnewWV96nggc5FJzI0wQE4EtOrJk/RD0X+4MFkX/aap6+ fON3WzA3DzWmO7Dq1Jy0kIKZ1aC9/vfXlfeOGBMsRiUMax6m/ofGlR1fxXeaP511AD3D0vuvgNDni MFI9zMIri726KXLYUBjd0kK3Ph0o3lsspPh1HPazW8Dpnp6DqE1VpeGlWo+rIXDr7Zgcv291s2ikd NZQCRFQ2Dcssmp9yYcrQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nE6XW-006F3v-A3; Sun, 30 Jan 2022 09:30:30 +0000 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nE6XS-006F35-RR for linux-arm-kernel@lists.infradead.org; Sun, 30 Jan 2022 09:30:28 +0000 Received: by mail-pf1-x42d.google.com with SMTP id 192so10207410pfz.3 for ; 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=LtJVDrzQshSla1HMvdAELfPYeG+dPLX233UbPmqLai1Mpf9KJq3A/41XggYzYyni3b /tQyQDF+pO8fYeNANRTY26NntnCCsuifloBxdC5M18s5IoXepocTK7oTpu066uosohjv RrM+WvnAPB9r+S6Z/dWOuWGKiEZp6nKixnMbeamOX3zPclhTKdc9I3zzF+f3/yg27WOl c0sK1gOyZD3tZ59bCzLnN9/mQMqAIU4kIXBo5zxYQmWKfApe7R1e0B9Mb/0R1FjIb9En HveGtAIZ72WNgEVN8TYbUHyKhv2uTIQVwNKc11MrpFdhh+CuS8T6fW30raUL411yMRnq AeJw== X-Gm-Message-State: AOAM533dbUtkDb5wcKISmmyKAUUILQfODAfh5uhicrT4BBi0MnfNhrpO JzqUaFyINbSTMmCjbAVpSac= 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220130_013026_918510_5E49FBA3 X-CRM114-Status: GOOD ( 14.89 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 12729774 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9D2A5C433F5 for ; Sun, 30 Jan 2022 09:32:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2fMf4kEsvL6ueRQFGkBodFT9kc/FVA/AgBmp+GJIOpc=; b=yH6Mf/qUjD3psk XmsoOPpoRwDc12fNLaCI6I6pPmnFIwl9/q8IPT6pzKu3Sr7DIBmgER4XUlGEqPF884MkBwtY+KFZt KXoyQPJRTilCO88Ha76YdD0+boBfwp4oakhvkd6thQ5ubAEXUka01ITmBxmjON0mLhynuUaftIkQH F1INfamN+M3gyVvxKizBOpcEdj8sdhNfOQtcOiJiJ9x9BLmPcenabmmmHWQus2LgXBUt7gah7K+UT ycznZgYmXqgnWnlcr9WG0Q2QpFSS3lhgMwjIpAawRF1XcSZxg3FKeNSQUd8yf6krQ893vQ9mVyhrg jGwLezMGBKUAnfl5l8Dg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nE6Xk-006F73-Bk; Sun, 30 Jan 2022 09:30:44 +0000 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nE6Xa-006F4c-9q for linux-arm-kernel@lists.infradead.org; Sun, 30 Jan 2022 09:30:35 +0000 Received: by mail-pl1-x629.google.com with SMTP id x11so9964830plg.6 for ; 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=vbu938kkHfRdFNdMCPkmZ+6C7a0cxykWFcK02kzzoZ3T2SQuiJxQLZmi7KoUxQqRl3 gY1KSiKEUoSWTaZ/ghCbLNv9C+lPWdD2wCMxW0+SzKqO/rutj0ppzuB0H2L6G+XNtN7a ylKod2bW3fL2+X9jI+25KhvYhBDOUL/5YJ2RwpaA14C43MQrn+n6rt55naTTmWkL67cF caxcryb68nIfmFfsUY5rJKDK9mDyBclZkmNyyPtFYbh8IQvCY3LSxRuIrXRbp/H7c8qA oWMzrjHAiTSzz+xy8d9bYM5cm0iRnZkon6tQnM5twDLIApnPIZmaiv3xjf0IIX6qlrgq epWw== X-Gm-Message-State: AOAM53097G3tWHsUNbqfrI19qZe5L+lIg12UXZagSfGv+cq9GX6cUyq/ wV99roOP6e5GjIRVJ9NN564= 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220130_013034_388334_E7BC05C5 X-CRM114-Status: GOOD ( 15.03 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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"))