From patchwork Sun Feb 12 03:52:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hengqi Chen X-Patchwork-Id: 13137334 X-Patchwork-Delegate: bpf@iogearbox.net 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34497C05027 for ; Sun, 12 Feb 2023 03:53:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229618AbjBLDxB (ORCPT ); Sat, 11 Feb 2023 22:53:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229473AbjBLDxB (ORCPT ); Sat, 11 Feb 2023 22:53:01 -0500 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF42E14228 for ; Sat, 11 Feb 2023 19:52:59 -0800 (PST) Received: by mail-pl1-x632.google.com with SMTP id m2so10468928plg.4 for ; Sat, 11 Feb 2023 19:52:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/hA3IP0EbHRoML81/juFYStllsBM72tyAWPCxGp78Zw=; b=b3OB5PiJ1CXthmneNF/B9Wj2k4dwIrxhOSGQvSfxodeWP3/0sAn3wTh957DzP2T7V1 0ivg7lf7yfWNKpjpc50dDcXJ/xuqsXxTxb2rLOYSUig+LtZWBc8WWs6n5yDoMD1HMGjC ohindg499u5UWix7AGserjKVxDcOcjWgPshN5OEEBkb2iBQXmdXYN6HMHtE6NrCefYu5 VHd/XVW5Nn7bgEyOXuJYCX4cv8mGumwGyWtwdOi91VceUB8qd43M1U2xFDqZ8jwCuxyy MClSDaaW1STM2uR01dnftvXaAIU/xoRGx//LsGEm36RVKGBJjePPC4Sp8RNtZCydaBwI h5NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/hA3IP0EbHRoML81/juFYStllsBM72tyAWPCxGp78Zw=; b=FZptk58vF3+28n+DY4zQNGMw1QTJNC5WdeeNv0nJGrM3NyA0cAxX7n+AO3KTZoDPAJ 238SFNzR7xps2tnA1pNFyjixWiPAM1Ngbdrwp4tovTdTBFJjsqfzg4cVUKAEwwy6mwUk SS1KvviXsflYG7BpE0gyXcbd16qJcCZQXeehThiLIYDn+uQTfiPb+X9bhVWJCI3QIsrG btCZWy/zU3ql2NiixfPHSSJKQZD2hUqVOSl84j/hHlLdKX5hLEwSjUtkWfcDiawZJEyN 33OaLLUAyWtDw+F7DXqYzjmcRUDhR/+v0d8Qpe+UvSFhMxJFp8MLwOF1iljNDcqQjaNu XZIA== X-Gm-Message-State: AO0yUKX2mrhrmVlCTgMnrRd2E2I2iuNe6TxWaRy67YqEOilImdeDB2TJ XY5LpOxYFX3vHIhU/bAxhv4RYNiJICs= X-Google-Smtp-Source: AK7set/A1OcyJ2w19fBpsJRXWqZ4xbxNpu62Z9iwsaKHIgOI3LaasCYkYwOKGsY2P7362uHMki0AuA== X-Received: by 2002:a05:6a20:6990:b0:b8:a17c:75e4 with SMTP id t16-20020a056a20699000b000b8a17c75e4mr22766775pzk.48.1676173979232; Sat, 11 Feb 2023 19:52:59 -0800 (PST) Received: from localhost.localdomain ([43.132.141.9]) by smtp.gmail.com with ESMTPSA id s1-20020a63dc01000000b004fab4455748sm5055399pgg.75.2023.02.11.19.52.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Feb 2023 19:52:58 -0800 (PST) From: Hengqi Chen To: bpf@vger.kernel.org, loongarch@lists.linux.dev Cc: hengqi.chen@gmail.com Subject: [PATCH 1/2] LoongArch: BPF: Treat function address as 64-bit value Date: Sun, 12 Feb 2023 11:52:35 +0800 Message-Id: <20230212035236.1436532-2-hengqi.chen@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230212035236.1436532-1-hengqi.chen@gmail.com> References: <20230212035236.1436532-1-hengqi.chen@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Let's always use 4 instructions for function address in JIT. So that the instruction sequences don't change between the first pass and the extra pass for function calls. Fixes: 5dc615520c4d ("LoongArch: Add BPF JIT support") Signed-off-by: Hengqi Chen --- arch/loongarch/net/bpf_jit.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c index c4b1947ebf76..2d952110be72 100644 --- a/arch/loongarch/net/bpf_jit.c +++ b/arch/loongarch/net/bpf_jit.c @@ -446,6 +446,27 @@ static int add_exception_handler(const struct bpf_insn *insn, return 0; } +static inline void emit_addr_move(struct jit_ctx *ctx, enum loongarch_gpr rd, u64 addr) +{ + u64 imm_11_0, imm_31_12, imm_51_32, imm_63_52; + + /* lu12iw rd, imm_31_12 */ + imm_31_12 = (addr >> 12) & 0xfffff; + emit_insn(ctx, lu12iw, rd, imm_31_12); + + /* ori rd, rd, imm_11_0 */ + imm_11_0 = addr & 0xfff; + emit_insn(ctx, ori, rd, rd, imm_11_0); + + /* lu32id rd, imm_51_32 */ + imm_51_32 = (addr >> 32) & 0xfffff; + emit_insn(ctx, lu32id, rd, imm_51_32); + + /* lu52id rd, rd, imm_63_52 */ + imm_63_52 = (addr >> 52) & 0xfff; + emit_insn(ctx, lu52id, rd, rd, imm_63_52); +} + static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool extra_pass) { u8 tm = -1; @@ -841,7 +862,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext if (ret < 0) return ret; - move_imm(ctx, t1, func_addr, is32); + emit_addr_move(ctx, t1, func_addr); emit_insn(ctx, jirl, t1, LOONGARCH_GPR_RA, 0); move_reg(ctx, regmap[BPF_REG_0], LOONGARCH_GPR_A0); break; From patchwork Sun Feb 12 03:52:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hengqi Chen X-Patchwork-Id: 13137335 X-Patchwork-Delegate: bpf@iogearbox.net 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D460BC05027 for ; Sun, 12 Feb 2023 03:53:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229625AbjBLDxO (ORCPT ); Sat, 11 Feb 2023 22:53:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229473AbjBLDxN (ORCPT ); Sat, 11 Feb 2023 22:53:13 -0500 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E22111E99 for ; Sat, 11 Feb 2023 19:53:12 -0800 (PST) Received: by mail-pj1-x102f.google.com with SMTP id rm7-20020a17090b3ec700b0022c05558d22so9273614pjb.5 for ; Sat, 11 Feb 2023 19:53:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Y4h9WsUjmRZxu6NcTdxjKOjuLJtm5ecgWlCdBojSgEo=; b=Duai0FFr0vViGfcGbGoyoFjMUy1Pdd7aLYF36PlQAfHBxjxvw4j8LuPtUv6NJJHAuC Be7rKxydxqF67thEl11uCeZ9W3gAkmKS1CTyne5i5MwoFmMRRyZ5ib5ahE2n+NmzOTZ+ G3bVpK/TRlgnlK4lcuXMWu1unCUb2LB2nDXSh815TOg7lDeOmS5LS5nEONlJ7raoMHzC 4UpuX4ktY2bbMw9tlVS5t5cpn2lGjsDo51Sk9yNW9u8byuvn93AnxmaFJ6iA7YuoVF9e rQbd7fJ5V5aCnovG1YMwwfCZpugLOsQa4pM4TNwQUMqIJyqjsd/3iAd5PIGMZOJk8EMG zc+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y4h9WsUjmRZxu6NcTdxjKOjuLJtm5ecgWlCdBojSgEo=; b=Z/qz6rvePKvWgPnFHbxI//j2jHt1yzdnETWTGvNKhOvM2cXZDo/ovEoESMO/6MnXHl SR/8SWUhnnlOvQ+39d9Bi1cnjstqwKFTaG2sYjV+7UooVGD4XeNUP8/ANiDugDauv0fW jjWNT11gmvdxtNatyNnv4GLE4a8/icXJDogTOzqpTxic/MuOZM/9Y765w9a3vtGuyC/e rxQQ62S4lQfY/lfu0W6jiv++OZFMZ5+fVp6PPlhAMLyCwtPdCYKK/QRf4NZJLGzU8wQh PXL2qyO/HPi4SCkNUxZepVDdF9kVoomxIOEM4KBvrvxkDNJNdIRfvltCrwfq1k0AjW7p 4z2Q== X-Gm-Message-State: AO0yUKU/AhyVAMlMIQ5DeLx3evEJ91ywFwd9CROveSvdchzPpsKC5p7v iUWb/Iq0u/5mVbpwn6OvYh660nhTM4A= X-Google-Smtp-Source: AK7set8135vryfARAaRnU8fQfooqphztWQGg4x2hS0DF9JblOf2Xw5wkGvUzM7T0tz/eY9wX1lxITg== X-Received: by 2002:a17:90b:30c1:b0:233:c3e3:182f with SMTP id hi1-20020a17090b30c100b00233c3e3182fmr4611280pjb.8.1676173991946; Sat, 11 Feb 2023 19:53:11 -0800 (PST) Received: from localhost.localdomain ([43.132.141.9]) by smtp.gmail.com with ESMTPSA id s1-20020a63dc01000000b004fab4455748sm5055399pgg.75.2023.02.11.19.53.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Feb 2023 19:53:11 -0800 (PST) From: Hengqi Chen To: bpf@vger.kernel.org, loongarch@lists.linux.dev Cc: hengqi.chen@gmail.com Subject: [PATCH 2/2] LoongArch: BPF: Support mixing bpf2bpf and tailcalls Date: Sun, 12 Feb 2023 11:52:36 +0800 Message-Id: <20230212035236.1436532-3-hengqi.chen@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230212035236.1436532-1-hengqi.chen@gmail.com> References: <20230212035236.1436532-1-hengqi.chen@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The current implementation already allow such mixing. Let's enable it in JIT. Signed-off-by: Hengqi Chen --- arch/loongarch/net/bpf_jit.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c index 2d952110be72..01892dfa637e 100644 --- a/arch/loongarch/net/bpf_jit.c +++ b/arch/loongarch/net/bpf_jit.c @@ -1269,3 +1269,9 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog) return prog; } + +/* Indicate the JIT backend supports mixing bpf2bpf and tailcalls. */ +bool bpf_jit_supports_subprog_tailcalls(void) +{ + return true; +}