From nobody Sat May 4 12:28:46 2024 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 10A83C74A5B for ; Sun, 26 Mar 2023 04:40:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231833AbjCZEkg (ORCPT ); Sun, 26 Mar 2023 00:40:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231410AbjCZEkd (ORCPT ); Sun, 26 Mar 2023 00:40:33 -0400 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD8B1618D; Sat, 25 Mar 2023 21:40:30 -0700 (PDT) X-UUID: b6cde0c7e2b64c718c7dc18a8eab4dc3-20230326 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.20,REQID:8e8edc52-f736-4f72-9b68-3722b697739c,IP:10, URL:0,TC:0,Content:0,EDM:25,RT:0,SF:1,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:36 X-CID-INFO: VERSION:1.1.20,REQID:8e8edc52-f736-4f72-9b68-3722b697739c,IP:10,UR L:0,TC:0,Content:0,EDM:25,RT:0,SF:1,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:36 X-CID-META: VersionHash:25b5999,CLOUDID:0cdd7f29-564d-42d9-9875-7c868ee415ec,B ulkID:230326123044RXI7AJ6O,BulkQuantity:3,Recheck:0,SF:38|24|17|19|43|102, TC:nil,Content:0,EDM:5,IP:-2,URL:0,File:nil,Bulk:40,QS:nil,BEC:nil,COL:0,O SI:0,OSA:0,AV:0 X-CID-BVR: 0 X-UUID: b6cde0c7e2b64c718c7dc18a8eab4dc3-20230326 X-User: guodongtai@kylinos.cn Received: from localhost.localdomain [(210.12.40.82)] by mailgw (envelope-from ) (Generic MTA) with ESMTP id 124657828; Sun, 26 Mar 2023 12:40:21 +0800 From: George Guo To: chenhuacai@kernel.org, masahiroy@kernel.org, michal.lkml@markovi.net Cc: kernel@xen0n.name, ndesaulniers@google.com, daniel@iogearbox.net, ast@kernel.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH] loongarch/bpf: Fix bpf load failed with CONFIG_BPF_JIT_ALWAYS_ON, caused by jit (BPF_ST | BPF_NOSPEC) code Date: Sun, 26 Mar 2023 12:40:19 +0800 Message-Id: <20230326044019.2139628-1-guodongtai@kylinos.cn> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Here just skip the code(BPF_ST | BPF_NOSPEC) that has no couterpart to the = loongarch. To verify, use ltp testcase: Without this patch: $ ./bpf_prog02 ... ... bpf_common.c:123: TBROK: Failed verification: ??? (524) Summary: passed 0 failed 0 broken 1 skipped 0 warnings 0 With this patch: $ ./bpf_prog02 ... ... Summary: passed 0 failed 0 broken 0 skipped 0 warnings 0 Signed-off-by: George Guo --- arch/loongarch/net/bpf_jit.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c index 288003a9f0ca..745d344385ed 100644 --- a/arch/loongarch/net/bpf_jit.c +++ b/arch/loongarch/net/bpf_jit.c @@ -1046,6 +1046,11 @@ static int build_body(struct jit_ctx *ctx, bool extr= a_pass) if (ctx->image =3D=3D NULL) ctx->offset[i] =3D ctx->idx; =20 + /* skip the code that has no couterpart to the host arch */ + if(insn->code =3D=3D (BPF_ST | BPF_NOSPEC)) { + continue; + } + ret =3D build_insn(insn, ctx, extra_pass); if (ret > 0) { i++; --=20 2.34.1