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=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,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 AFDA6C2D0C0 for ; Mon, 23 Dec 2019 18:29:48 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 8829C206CB for ; Mon, 23 Dec 2019 18:29:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="iG+sDNro"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="NQ/x9Xan" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8829C206CB Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+infradead-linux-riscv=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:Content-Type:Mime-Version:Message-ID:References: In-Reply-To:To:Subject:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ETCAz2nAecl12u4VuGxwDzQ9bwqkvTCnDzDrKnZSkaE=; b=iG+sDNro5Bz6M8 7fidt8S7ek4q3wSNlIl0RuusLcNNxlHXaRCmlPv4Ib02EozZthd7HNnZKcB07q3V68jLnXFgdcxIU DYIA4k6U2euFS2HQno92qqQ2OwvBFfye4EGwNAyCombJ7tP7XwXxM06BnMdp54XOIbDYLhoeqpJFp grr3t9/uj8P496D+0HigUJ7nk8Ixshxk6KINXvHcZaqcPjT8i7guefBsj3dcrR45WDR+wtRQi37/s ggPpmtAXgnHzrcRHr2Y03C6lx3oawAr1hxcY2YSSBXoMijQRCkd1wzis7nKszWlPtROUBuYOiV7Bd I+to8LIEQ6tUWHbIXumw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ijSSh-0001R2-Hx; Mon, 23 Dec 2019 18:29:47 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ijSSe-0001QY-6g for linux-riscv@lists.infradead.org; Mon, 23 Dec 2019 18:29:45 +0000 Received: by mail-pf1-x441.google.com with SMTP id z16so9581040pfk.0 for ; Mon, 23 Dec 2019 10:29:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:subject:cc:to:in-reply-to:references:message-id :mime-version:content-transfer-encoding; bh=ETCAz2nAecl12u4VuGxwDzQ9bwqkvTCnDzDrKnZSkaE=; b=NQ/x9Xan0pE4XVpqheHlJ4CgdWe9LDhiMKidcqqT/im1ZAJ8dXpX0qu/PHgUy31UXc G6lwCJOBwiAh/ft2PEvg80+4POa6qy7ZUAtsi0I51DRIPt1txRBs1ubVABHHkMq84bx6 Kfcs79SAgBwfBBF2bxH2cNdP4dfjRRRLwYt8VfjTO6bR8exPyX8qx8azKgm/U2X7npz0 /6McjwgckB8P17bxehoGhsQtMyxnja/2UTTroiKjpoLuAVsfKCH6Xa0FOzHNYjE/TGoQ UN8DeWzbvbMYNHdgcA1zhyqEpumsqCinN9aKr8Qtsu+5X8j40ZMJqXM6DCkuCNoHPGbf FWOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:subject:cc:to:in-reply-to:references :message-id:mime-version:content-transfer-encoding; bh=ETCAz2nAecl12u4VuGxwDzQ9bwqkvTCnDzDrKnZSkaE=; b=g0YVRI66Y1QbN9goq29EhMfq3gEl9zrtvQn6tJi8yCiux8dwSV/po6b7rWzn0SAV4P ykp8eigE7+0ty4BntAeRH5vA2v15cRcbwFB0dL+Lgyvui6ZQUOUWDje/0m1Uy3ZhJBeN 7qnYJbuu+rS2Op4bRGMf7WTk2kHICIhaH7ge/PO5whmpjqEjLtnybmYXZ737e6VN2tGH PXTrf18AIo7QbfqpSxGO0s5s+hHB1Clhiev3t9rVbaeb5ZOF0MegeOk3uDDKTbzjq33w J/lnI6MDavVpaTXscQP8xmb9Y+XukHCpIVCV+gDOEB8sm4mKsWbx1HTda2TbnHbYejBM H6bg== X-Gm-Message-State: APjAAAWSYXyNBuvScfBGhjaA7tAMLx8DBoyf/tjPAuUuD5XwLBlq4KY/ GV0oye3qdVWX+ve1f85nq+k1xA== X-Google-Smtp-Source: APXvYqzyXbXysDM2meGOAdnFewhF96oWfXTEbytcsUZtAPxGdzhU1sBVIYdYLoMQmjWY+UsfFcIGRQ== X-Received: by 2002:a62:a515:: with SMTP id v21mr34004010pfm.128.1577125779770; Mon, 23 Dec 2019 10:29:39 -0800 (PST) Received: from localhost ([2620:0:1000:2514:7f69:cd98:a2a2:a03d]) by smtp.gmail.com with ESMTPSA id w20sm15751188pfi.86.2019.12.23.10.29.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Dec 2019 10:29:39 -0800 (PST) Date: Mon, 23 Dec 2019 10:29:39 -0800 (PST) X-Google-Original-Date: Mon, 23 Dec 2019 10:29:24 PST (-0800) From: Palmer Dabbelt X-Google-Original-From: Palmer Dabbelt Subject: Re: [PATCH bpf-next v2 5/9] riscv, bpf: optimize BPF tail calls To: Bjorn Topel In-Reply-To: <20191216091343.23260-6-bjorn.topel@gmail.com> References: <20191216091343.23260-6-bjorn.topel@gmail.com> <20191216091343.23260-1-bjorn.topel@gmail.com> Message-ID: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191223_102944_269879_B3ACB2B0 X-CRM114-Status: GOOD ( 14.26 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: daniel@iogearbox.net, netdev@vger.kernel.org, ast@kernel.org, Bjorn Topel , linux-riscv@lists.infradead.org, bpf@vger.kernel.org Sender: "linux-riscv" Errors-To: linux-riscv-bounces+infradead-linux-riscv=archiver.kernel.org@lists.infradead.org On Mon, 16 Dec 2019 01:13:39 PST (-0800), Bjorn Topel wrote: > Remove one addi, and instead use the offset part of jalr. > > Signed-off-by: Björn Töpel > --- > arch/riscv/net/bpf_jit_comp.c | 13 +++++++------ > 1 file changed, 7 insertions(+), 6 deletions(-) > > diff --git a/arch/riscv/net/bpf_jit_comp.c b/arch/riscv/net/bpf_jit_comp.c > index 2fc0f24ad30f..8aa19c846881 100644 > --- a/arch/riscv/net/bpf_jit_comp.c > +++ b/arch/riscv/net/bpf_jit_comp.c > @@ -552,7 +552,7 @@ static int epilogue_offset(struct rv_jit_context *ctx) > return (to - from) << 2; > } > > -static void __build_epilogue(u8 reg, struct rv_jit_context *ctx) > +static void __build_epilogue(bool is_tail_call, struct rv_jit_context *ctx) > { > int stack_adjust = ctx->stack_size, store_offset = stack_adjust - 8; > > @@ -589,9 +589,11 @@ static void __build_epilogue(u8 reg, struct rv_jit_context *ctx) > > emit(rv_addi(RV_REG_SP, RV_REG_SP, stack_adjust), ctx); > /* Set return value. */ > - if (reg == RV_REG_RA) > + if (!is_tail_call) > emit(rv_addi(RV_REG_A0, RV_REG_A5, 0), ctx); > - emit(rv_jalr(RV_REG_ZERO, reg, 0), ctx); > + emit(rv_jalr(RV_REG_ZERO, is_tail_call ? RV_REG_T3 : RV_REG_RA, > + is_tail_call ? 4 : 0), /* skip TCC init */ > + ctx); > } > > /* return -1 or inverted cond */ > @@ -751,9 +753,8 @@ static int emit_bpf_tail_call(int insn, struct rv_jit_context *ctx) > if (is_12b_check(off, insn)) > return -1; > emit(rv_ld(RV_REG_T3, off, RV_REG_T2), ctx); > - emit(rv_addi(RV_REG_T3, RV_REG_T3, 4), ctx); > emit(rv_addi(RV_REG_TCC, RV_REG_T1, 0), ctx); > - __build_epilogue(RV_REG_T3, ctx); > + __build_epilogue(true, ctx); > return 0; > } > > @@ -1504,7 +1505,7 @@ static void build_prologue(struct rv_jit_context *ctx) > > static void build_epilogue(struct rv_jit_context *ctx) > { > - __build_epilogue(RV_REG_RA, ctx); > + __build_epilogue(false, ctx); > } > > static int build_body(struct rv_jit_context *ctx, bool extra_pass) Reviewed-by: Palmer Dabbelt Acked-by: Palmer Dabbelt