Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6146226iog; Thu, 23 Jun 2022 12:17:55 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uw6ipSNXJapNW3M4bZkecpGIKJpHTwZ+HriAUH7dXzQFUyNukOZfquazK2BYeDyc+7DxaE X-Received: by 2002:a17:902:d389:b0:16a:17c6:35f2 with SMTP id e9-20020a170902d38900b0016a17c635f2mr27168625pld.56.1656011874852; Thu, 23 Jun 2022 12:17:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656011874; cv=none; d=google.com; s=arc-20160816; b=bW7DvH4vtIA0BKx4pnOVu83ONVxSpjHd8mJzcuvHYz75j3d8xkC5GSQXyq3euSwRb0 xTEt1WSr5dAKMOgX1uCtqkDtSszIaHG9n1kp587Ig1AKanbkEK9pgZxiegUWrc7SWnk2 7El4TOEQcZ/8HUE8nkTuIZBM+55Acppr3+VCW86vxDBNyFf0vd6EfksTnPwgfId/TXlb /oulnhEjFVGJUMzY881LnR+o8ycqHV5kYYLG8NqyFpdVxHBNsKFGI4bO/qFoBBKei4Be gGsMkW52YTXd7lZiQvvaBAfXK68bqE1xluvDjZCkPNitp6nmcH8SesRPpJCm/wXVhOsv zgHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Z17OnnAzSGvmXGVAHW6nj1iLfgxsqGEDImh8m2MPS/Y=; b=WC8Q4ehYf0+/XtEMTIvuubak08goCHyNqr3RwWSg7bm3GgVcN6PuLh7l2zZZBwkO3R Gyn/M5EarS+vDIHvViuEWGKXmACE3FF+nCXYi2zFcdFe69wSNjnPesqQTxSVWe6lfI+p 7XbPJGf7MycyPo/z+n9rX9x0EtNGLbDcQEVq7V8qHe2eNRrqSPRpvBMqhA07kew0M46J JOx39FiDAtBvvzazgxgzyvjjpiV9qyDRoOnIqOco1sM2bKodSINY9Woo5vhBiaJg76BS V1GxKBTD9NyW6gHX4GVpPH4ixw64ciYGc4SOSXkEXntCdFUSs2J0Hx2+UdRHzLazeBNY Whlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QQHZsMGI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g8-20020a636b08000000b0040cf420e717si11796831pgc.232.2022.06.23.12.17.43; Thu, 23 Jun 2022 12:17:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QQHZsMGI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233575AbiFWSYx (ORCPT + 99 others); Thu, 23 Jun 2022 14:24:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237386AbiFWSWj (ORCPT ); Thu, 23 Jun 2022 14:22:39 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 426589413A; Thu, 23 Jun 2022 10:25:23 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B29B0B824BE; Thu, 23 Jun 2022 17:25:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A68C5C3411B; Thu, 23 Jun 2022 17:25:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656005120; bh=Dgo+qeo1tTgFj4A8Mf0R41+TzFQaiRkWV6tvtPg3G+k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QQHZsMGIk+Ag6TCol8TjqaS/nYkAkLH25od+8GzA4uhhkF2vCq1rkMynk2p353dju g1Kv3c/pHc2sGU5TkaeNGHbZTMMtvXUnqAgXoKcVip/fQQoJ80kJ47qiFWYs1AWtlJ 0QTNSpt2p6kq3PwvxF4JDRkee1/Sugox4HGhBlY4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , Alexei Starovoitov Subject: [PATCH 5.18 10/11] selftests/bpf: Add selftest for calling global functions from freplace Date: Thu, 23 Jun 2022 18:45:22 +0200 Message-Id: <20220623164322.614224121@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164322.315085512@linuxfoundation.org> References: <20220623164322.315085512@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Toke Høiland-Jørgensen commit 2cf7b7ffdae519b284f1406012b52e2282fa36bf upstream. Add a selftest that calls a global function with a context object parameter from an freplace function to check that the program context type is correctly converted to the freplace target when fetching the context type from the kernel BTF. v2: - Trim includes - Get rid of global function - Use __noinline Signed-off-by: Toke Høiland-Jørgensen Link: https://lore.kernel.org/r/20220606075253.28422-2-toke@redhat.com Signed-off-by: Alexei Starovoitov Signed-off-by: Greg Kroah-Hartman --- tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c | 14 +++++++++++ tools/testing/selftests/bpf/progs/freplace_global_func.c | 18 +++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/freplace_global_func.c --- a/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c +++ b/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c @@ -395,6 +395,18 @@ static void test_func_map_prog_compatibi "./test_attach_probe.o"); } +static void test_func_replace_global_func(void) +{ + const char *prog_name[] = { + "freplace/test_pkt_access", + }; + + test_fexit_bpf2bpf_common("./freplace_global_func.o", + "./test_pkt_access.o", + ARRAY_SIZE(prog_name), + prog_name, false, NULL); +} + /* NOTE: affect other tests, must run in serial mode */ void serial_test_fexit_bpf2bpf(void) { @@ -416,4 +428,6 @@ void serial_test_fexit_bpf2bpf(void) test_func_replace_multi(); if (test__start_subtest("fmod_ret_freplace")) test_fmod_ret_freplace(); + if (test__start_subtest("func_replace_global_func")) + test_func_replace_global_func(); } --- /dev/null +++ b/tools/testing/selftests/bpf/progs/freplace_global_func.c @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include + +__noinline +int test_ctx_global_func(struct __sk_buff *skb) +{ + volatile int retval = 1; + return retval; +} + +SEC("freplace/test_pkt_access") +int new_test_pkt_access(struct __sk_buff *skb) +{ + return test_ctx_global_func(skb); +} + +char _license[] SEC("license") = "GPL";