Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp779502pxb; Sun, 10 Oct 2021 10:53:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXhvGdI7U2xB16MBHCtYUZZPno7wOuNAvFFjrLVvjY7IFNJP9nu2fsomq7abwxmwmAi8Te X-Received: by 2002:a50:e142:: with SMTP id i2mr33583313edl.107.1633888380316; Sun, 10 Oct 2021 10:53:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633888380; cv=none; d=google.com; s=arc-20160816; b=xIRYMtBfhDciqkR0UJtnvRXG4N6lIhhc6nqPTQOLNdAHmN5+U+trdCfXs6nrZrFhET A3Q9VQTLDJMG4X5LM9q/HhEyEZZ44YZDWn8ary+ORQZOi/MfSsayXQUV5yu64lbbA3Kf I0kPtx2U75UtXUbp76h7yv1MHy+6c6/+usKgmGGFJLvgoGQYgumkl+4oXMBwtoFIXlE1 dgjgbKnXXjqmVcfwPjE3pNrLb8POgmk0Db8c/4Lnl9PU5UitiLacCnPPuG1Xg+Ey7Qip 8Ddo3dwz3bsj+ovxQ3tXFT0F2DR7sugv+OqNFaVH6GWIUt/zsg4EGBOyYhRDyjj4TinV Qmvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=x5ZjKsTtEg68L0kiGkt4LxgOXkimH+/pqF53AqKiKZQ=; b=Hd/pm117W5E8JGBH6Pvst2RVYacLf/l8jGM/+iyaXDNSGIOd6IrpUmFU1geYtJhbwj Qz+aY1u12P/i4GW8RJAyYMNunFfWUe5MdeUewvCFvODAbrogpiYcAb8wsNeEA6308Exd CygS6gCUrFP5paZQbjnEyJGfi8dZrsURQ8FIeCSEfYu3nwyHnKu94xahmmj6s+N427Hc QEP1i5M3IbASnRlFcX4kcXQBbtSiObUVK01VgXZgELa1aIj0yRARzraOm1HhU5PFCKTJ tMGScG/yHROT0CXtu8GpmucgpydFOSdckuTbXG9Z03W6gZKQOfKSod6BJcgMk75VQWMY b5NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@anyfinetworks-com.20210112.gappssmtp.com header.s=20210112 header.b=ipoQjOKZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w2si434676edc.261.2021.10.10.10.52.36; Sun, 10 Oct 2021 10:53:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@anyfinetworks-com.20210112.gappssmtp.com header.s=20210112 header.b=ipoQjOKZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231862AbhJJRck (ORCPT + 99 others); Sun, 10 Oct 2021 13:32:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231699AbhJJRck (ORCPT ); Sun, 10 Oct 2021 13:32:40 -0400 Received: from mail-yb1-xb30.google.com (mail-yb1-xb30.google.com [IPv6:2607:f8b0:4864:20::b30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51CDCC061745 for ; Sun, 10 Oct 2021 10:30:41 -0700 (PDT) Received: by mail-yb1-xb30.google.com with SMTP id n65so33372304ybb.7 for ; Sun, 10 Oct 2021 10:30:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anyfinetworks-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=x5ZjKsTtEg68L0kiGkt4LxgOXkimH+/pqF53AqKiKZQ=; b=ipoQjOKZwOE7PQSN4YXQwnoGYQ+z2crmfDLF5WIwFdsg3/6MkCvp/W7Wp6ZqZE7wuo nGSKuaAKG9OW2VEgKfWnY0DSuF4iI52mCBt1gBRWdFthEOl1PdRxO3H2Huo5aCLhzmxu fVkrm35sRErkUmXrOi+JSiFTshKPLob3y1O7ZMiUsQO8p6ahUdSuSEeoM8xipzZjAFKi hommd4/b7ihiMx6RnGbDIPnKmweJZlVlcZw49A6iPSYG+aDkJFvpv12ZKnnIt1YFg7XQ F0HFqjMkZNnBAryZ1Rh8K3ZzI6v6fSyZHnkBwK5v0TbxSBnra/n5CcPMbZ55+JslYFWL ZEmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=x5ZjKsTtEg68L0kiGkt4LxgOXkimH+/pqF53AqKiKZQ=; b=gOF9SEZVIT6gfdxPNMQ4YIdnmlxbtPFcdii6qQZjk2IeXXQexLFjT+ma0VSN8cx3Kw rFRX8yDjOhnGdH5PQm4iodynoHWms+ZkVX4Vj2V7BKqnCHEydABRIYJNUI8lR8VHAYkb 52ta07OEqA+664NnIAJpeg3kdR618qZ8nLIY+Wkwo5WnnCwhNlu+g1osNwyBOZRhsavl DIbupXWbTv3bR8NlBzztKxasg+mmuWpSFMS1jilsBsBnUzRd/WFywb6UErIjb0Q0/aTg Wc2hRtM0C9jlvu4BPqYEcM21CS93qc3Ad3XkGR8JgdrOjRcyfrfa+taj33F6fhcJMGuS nZjA== X-Gm-Message-State: AOAM5304r+qaNiAA4yjgDcG75AQjeGhJaVIMWOUxCvNWf4w6+IIOd0xE avdBhVA7SHoB8NPWg/8/eea+Hj6UpJW0zKWfLFJbkA== X-Received: by 2002:a25:520b:: with SMTP id g11mr17619445ybb.268.1633887040541; Sun, 10 Oct 2021 10:30:40 -0700 (PDT) MIME-Version: 1.0 References: <1633777076-17256-1-git-send-email-yangtiezhu@loongson.cn> <1633777076-17256-3-git-send-email-yangtiezhu@loongson.cn> In-Reply-To: <1633777076-17256-3-git-send-email-yangtiezhu@loongson.cn> From: Johan Almbladh Date: Sun, 10 Oct 2021 19:30:29 +0200 Message-ID: Subject: Re: [PATCH bpf-next 2/2] bpf, mips: Modify check condition about tail call count To: Tiezhu Yang Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Thomas Bogendoerfer , Paul Burton , Networking , bpf , linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Xuefeng Li , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Oct 9, 2021 at 12:58 PM Tiezhu Yang wrote: > > In emit_tail_call() of bpf_jit_comp32.c, "blez t2" (t2 <= 0) is not > consistent with the comment "t2 < 0", modify the check condition to > keep consistency. > > Signed-off-by: Tiezhu Yang > --- > arch/mips/net/bpf_jit_comp32.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/arch/mips/net/bpf_jit_comp32.c b/arch/mips/net/bpf_jit_comp32.c > index 9d7041a..b887c01 100644 > --- a/arch/mips/net/bpf_jit_comp32.c > +++ b/arch/mips/net/bpf_jit_comp32.c > @@ -1312,12 +1312,12 @@ static int emit_tail_call(struct jit_context *ctx) > emit(ctx, sltu, t1, ind, t1); /* t1 = ind < t1 */ > emit(ctx, beqz, t1, get_offset(ctx, 1)); /* PC += off(1) if t1 == 0 */ > /* (next insn delay slot) */ > - /* if (TCC-- <= 0) goto out */ > + /* if (--TCC < 0) goto out */ > emit(ctx, lw, t2, ctx->stack_size, MIPS_R_SP); /* t2 = *(SP + size) */ > emit_load_delay(ctx); /* Load delay slot */ > - emit(ctx, blez, t2, get_offset(ctx, 1)); /* PC += off(1) if t2 < 0 */ > emit(ctx, addiu, t2, t2, -1); /* t2-- (delay slot) */ > emit(ctx, sw, t2, ctx->stack_size, MIPS_R_SP); /* *(SP + size) = t2 */ > + emit(ctx, bltz, t2, get_offset(ctx, 1)); /* PC += off(1) if t2 < 0 */ If the comment is not consistent with the code, and the code is correct, why did you change the code? Have you seen the JIT fail on any of the tail call test cases? The current code works as intended. The t2 register is decremented in the branch delay slot of the blez. After your change, the the comment still says "delay slot", but it is no longer in the delay slot of a branch. Instead the next instruction emitted, not visible in the patch context, fills the delay slot of the bltz. In this case it probably is ok, but if that instruction is also a branch, the result would be unpredictable. I prefer to emit the delay slot instruction immediately after the branch is emitted when possible. If a branch and its delay slot is separated in the JIT logic, it makes the JIT more brittle IMO. Please keep the original logic, but update the blez comment so it is consistent with the code. > > /* prog = ary->ptrs[ind] */ > off = offsetof(struct bpf_array, ptrs); > -- > 2.1.0 >