From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E924DC433EF for ; Wed, 8 Sep 2021 10:53:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CF9DD6103E for ; Wed, 8 Sep 2021 10:53:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347888AbhIHKyp (ORCPT ); Wed, 8 Sep 2021 06:54:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348968AbhIHKym (ORCPT ); Wed, 8 Sep 2021 06:54:42 -0400 Received: from mail-yb1-xb2d.google.com (mail-yb1-xb2d.google.com [IPv6:2607:f8b0:4864:20::b2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBE3AC061757 for ; Wed, 8 Sep 2021 03:53:34 -0700 (PDT) Received: by mail-yb1-xb2d.google.com with SMTP id c206so3292872ybb.12 for ; Wed, 08 Sep 2021 03:53:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anyfinetworks-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=8+FiuvJj8Y4nT8SCPEuVHuMdoydnO/ZdFnbO3tV8nt4=; b=0U5bbvfC1NC3O0SPdmzv2/on6Pl1YX6DSCMLy3Qw3OKvDoinV7iBgFtX0n30uRg7R0 jJVYRcDDITXGbnrhyIODlROcaZUErYbt9EdaP7bGcvNMgOZjOhHBBiD7cRYBF0mqAtET sd6fGgV621Rr7tic5qbuHNtgSQPLzZqoQ1pBaKncCeSh0zW2dYlmyr/YKXgtehwJC2EW bu9119sTeN74SjJx2SR7umQtv6dOKtmS9VUBMIz0wiLU7iAvxx5g54BNMgV+DBlgpzh0 nEkE6xNZXFl8n88ej8bsCjI1itaf5NouT6Qh6Lujy+eYqKHgEjwjQ3iRhLYm1U0OW+iQ 7HUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=8+FiuvJj8Y4nT8SCPEuVHuMdoydnO/ZdFnbO3tV8nt4=; b=k4GJs7njLsx7f0Mh3eP5U55kt9F8A0SgwblOfFFdGFVIepl1s1yTXGQ14vJnhd021g +F1wA8l3q66Fp88KZOy8gwnPLFnOjld77IWE9y4Q9O5kaGkMFDHiW+X61L0XddOHb4aT 9EiPsuvnj6UMuJqEyUlYcynCE1s6PGkSadIKdE/LyJRfaT7FRUZRovS1NGq711xscsOL jUSc+/v1IwlDFCNJHag+I0hfHY/X58E1tJXsH/poXIGB777kXBzozJmKLeJGkF1yJMy6 c+9vV0PTJQRruF9rmrOSEJZ+LQ96LNgeOmanvPrlMDZtV7st6vKQm+a/NYssoiyfccM1 PDuA== X-Gm-Message-State: AOAM530nKsfJNez8fBaPLzQ5yc2F0uegaBhJGOI9i/VkrOok5FOrQ4AR FHM4hGBhzs8vyD7kwyyCkyjOeEzDR/+6a2iy3a5yKA== X-Google-Smtp-Source: ABdhPJywWobX7mjX+JOraUaQSgQ1OOfd2U+jhJ8Bll1RPXi3aL1mUC2LfRIpsld6Hd++Enxx8y8uwZTOmTRNAW73jYE= X-Received: by 2002:a05:6902:124f:: with SMTP id t15mr4369311ybu.161.1631098414000; Wed, 08 Sep 2021 03:53:34 -0700 (PDT) MIME-Version: 1.0 References: <20210907222339.4130924-1-johan.almbladh@anyfinetworks.com> <20210907222339.4130924-14-johan.almbladh@anyfinetworks.com> In-Reply-To: From: Johan Almbladh Date: Wed, 8 Sep 2021 12:53:23 +0200 Message-ID: Subject: Re: [PATCH bpf-next v2 13/13] bpf/tests: Add tail call limit test with external function call To: Ilya Leoshkevich Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Networking , bpf Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Wed, Sep 8, 2021 at 12:10 PM Ilya Leoshkevich wrote: > > On Wed, 2021-09-08 at 00:23 +0200, Johan Almbladh wrote: > > This patch adds a tail call limit test where the program also emits > > a BPF_CALL to an external function prior to the tail call. Mainly > > testing that JITed programs preserve its internal register state, for > > example tail call count, across such external calls. > > > > Signed-off-by: Johan Almbladh > > --- > > lib/test_bpf.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++--- > > 1 file changed, 48 insertions(+), 3 deletions(-) > > > > diff --git a/lib/test_bpf.c b/lib/test_bpf.c > > index 7475abfd2186..6e45b4da9841 100644 > > --- a/lib/test_bpf.c > > +++ b/lib/test_bpf.c > > @@ -12259,6 +12259,20 @@ static struct tail_call_test tail_call_tests[] > > = { > > }, > > .result = MAX_TAIL_CALL_CNT + 1, > > }, > > + { > > + "Tail call count preserved across function calls", > > + .insns = { > > + BPF_ALU64_IMM(BPF_ADD, R1, 1), > > + BPF_STX_MEM(BPF_DW, R10, R1, -8), > > + BPF_CALL_REL(0), > > + BPF_LDX_MEM(BPF_DW, R1, R10, -8), > > + BPF_ALU32_REG(BPF_MOV, R0, R1), > > + TAIL_CALL(0), > > + BPF_EXIT_INSN(), > > + }, > > + .stack_depth = 8, > > + .result = MAX_TAIL_CALL_CNT + 1, > > + }, > > { > > "Tail call error path, NULL target", > > .insns = { > > There seems to be a problem with BPF_CALL_REL(0) on s390, since it > assumes that test_bpf_func and __bpf_call_base are within +-2G of > each other, which is not (yet) the case. The idea with this test is to mess up a JITed program's internal state if it does not properly save/restore those regs. I would like to keep the test in some form, but I do see the problem here. Another option could perhaps be to skip this test at runtime if the computed offset is outside +-2G. If the offset is greater than that it does not fit into the 32-bit BPF immediate field, and must therefore be skipped. This would work for other archs too. Yet another solution would be call one or several bpf helpers instead. As I understand it, they should always be located within this range, otherwise they would not be callable from a BPF program. The reason I did not do this was because I found helpers that don't require any context to be too simple. Ideally one would want to call something that uses pretty much all available caller-saved CPU registers. I figured snprintf would be complex/nasty enough for this purpose. > > I can't think of a good fix, so how about something like this? > > --- a/lib/test_bpf.c > +++ b/lib/test_bpf.c > @@ -12257,6 +12257,7 @@ static struct tail_call_test tail_call_tests[] > = { > }, > .result = MAX_TAIL_CALL_CNT + 1, > }, > +#ifndef __s390__ > { > "Tail call count preserved across function calls", > .insns = { > @@ -12271,6 +12272,7 @@ static struct tail_call_test tail_call_tests[] > = { > .stack_depth = 8, > .result = MAX_TAIL_CALL_CNT + 1, > }, > +#endif > { > "Tail call error path, NULL target", > .insns = { > > [...] >