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"))