Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1418193rdb; Wed, 6 Dec 2023 20:12:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IE/UGOE+ZjH4YxD3/EO4/zlikaid5hnrGdj18kZBMRM7HiAE5NSo3BPpI57o4mP27acEmDd X-Received: by 2002:a05:6a00:1ca5:b0:6cd:ed99:550b with SMTP id y37-20020a056a001ca500b006cded99550bmr1933521pfw.4.1701922371350; Wed, 06 Dec 2023 20:12:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701922371; cv=none; d=google.com; s=arc-20160816; b=FTEuvDypbQ+DR+NNy2Rc6lizY4L3YwI89E5YXAPi4ed110StIoONE6e1DVlXY2wSEH UpuRzu3c5v/E66+U9pJ50NgPQ6ehMCoHVQ2Ugf+1LoqompBQXjEJshvrPX93Dn40bK3i V/LLeLqbsRv2JMeVLsZNWHSF7N5BraG/aYLCV1eGt/4lXSchFzd3AtsjQ7KnQPjDtBEt 67XGNEIembFWZ1j7XsAxV4gMj0Ag35q6pGR+BQblj/1FzoF5M+U0C/0vdq1tLLO8hiib Z36HBi44g3c5q2Zqf1LGTPhDkSi8toQ5+E5rKR4RBH0QstL2hWKJcDS7nc3CL57LQS5q KX7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=r0MzEI/a6pK6Uf9ZRNdM+wxtjQoSCQTijZDEgYeS7VQ=; fh=f4MftPGsNGtpCap33U4Xe5vUihu/fNczhNa8iDGX330=; b=tH/Qe1xiezmKIm7ML4uHI0l11h0HP2+FiLSqeLnK+YjIrcne2lvWBDt9+t5CXB/OpV oCYyWXBCzgNxxX65lKEU2kY3LV95lAdN9CHQZkmlh/E9zxIUJA3w/BUdaupoxcJ1Y4wh 0EklTTyS8qcrike8gepXgMb9MS4PVUdARiwi+hG+C2C48+hp14MX80IZ7M/iHZ++qCa/ si0CzAca/kSs1+EIFfkXzI/oiT4UDeIl6jFKQ/9KdLGDZ1M4/A2sax6AeIILEqlROtT3 Ws8cSlNT2GlZRXdFkSYnXZGEIlC92OcBBxj59a1sLsg0hykFkblM3UrPv4JcCfZ8d4Z/ vmxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nlS5viHc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id t11-20020a056a0021cb00b006ce51863712si487796pfj.330.2023.12.06.20.12.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 20:12:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nlS5viHc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 221EC831D2EA; Wed, 6 Dec 2023 20:12:49 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229459AbjLGEMV (ORCPT + 99 others); Wed, 6 Dec 2023 23:12:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229449AbjLGEMS (ORCPT ); Wed, 6 Dec 2023 23:12:18 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D93D10C0 for ; Wed, 6 Dec 2023 20:12:25 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1E55C433C9 for ; Thu, 7 Dec 2023 04:12:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701922344; bh=0RjgV47unZBqHuDbjr4/VkAWoqZn4Tl76xtyIEWOyh0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=nlS5viHch/RcAiCqRdfO+367ziRpUvnEvaoVtrJObtLC1jnMJI7FLhQLyHzrcIG/j 4fjUN5D4eTHuQOxE4OYY95R+GBA955UkmHTrIXEmLtUl6iXa8rUSP9LnBN3Hd7uIsP Tw/RruHlM9j98uMOxtPgmfflwiBAyRyF2bUX7pPYLqjYyll6bZkMaGcmC3RUp45aXQ qVe5PbpQhWf1MBB73vppPkNXf6ZUP1cYriT6D3Wwot8LEUIhJy9PwbayYi18VdAHB/ /FSIDDQuSDo9poqx/CvIYEPdq4QidgNQl62XfbtdtUZOtcOSQtQ4s2j3wWS4nMpSJh yt5fCTtZZAX9A== Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-2c9f85eff28so3422811fa.3 for ; Wed, 06 Dec 2023 20:12:24 -0800 (PST) X-Gm-Message-State: AOJu0Yzj6YnTugRjjEOiHKYvQfMqj/hhLZ2a/o3qgmKDM8cruRpsBjNw Q+aAcSqED4nDSAgGIlgn01qJV/jYlFdY1uqVjPc= X-Received: by 2002:a05:651c:1030:b0:2c9:d872:e7b3 with SMTP id w16-20020a05651c103000b002c9d872e7b3mr1141856ljm.106.1701922343104; Wed, 06 Dec 2023 20:12:23 -0800 (PST) MIME-Version: 1.0 References: <20231207032951.16334-1-yangtiezhu@loongson.cn> <20231207032951.16334-2-yangtiezhu@loongson.cn> In-Reply-To: <20231207032951.16334-2-yangtiezhu@loongson.cn> From: Huacai Chen Date: Thu, 7 Dec 2023 12:12:10 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v1 1/2] LoongArch: BPF: Fix sign-extension mov instructions To: Tiezhu Yang Cc: Hengqi Chen , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 06 Dec 2023 20:12:49 -0800 (PST) On Thu, Dec 7, 2023 at 11:30=E2=80=AFAM Tiezhu Yang wrote: > > We can see that "Short form of movsx, dst_reg =3D (s8,s16,s32)src_reg" > in include/linux/filter.h, additionally, for BPF_ALU64 the value of > the destination register is unchanged whereas for BPF_ALU the upper > 32 bits of the destination register are zeroed, so it should clear > the upper 32 bits for BPF_ALU. > > [root@linux fedora]# echo 1 > /proc/sys/net/core/bpf_jit_enable > [root@linux fedora]# modprobe test_bpf > > Before: > test_bpf: #81 ALU_MOVSX | BPF_B jited:1 ret 2 !=3D 1 (0x2 !=3D 0x1)FAIL (= 1 times) > test_bpf: #82 ALU_MOVSX | BPF_H jited:1 ret 2 !=3D 1 (0x2 !=3D 0x1)FAIL (= 1 times) > > After: > test_bpf: #81 ALU_MOVSX | BPF_B jited:1 6 PASS > test_bpf: #82 ALU_MOVSX | BPF_H jited:1 6 PASS > > By the way, the bpf selftest case "./test_progs -t verifier_movsx" can > also be fixed with this patch. Hmmm, it is a little strange that privileged verifier_movsx has no problem. Huacai > > Fixes: f48012f16150 ("LoongArch: BPF: Support sign-extension mov instruct= ions") > Signed-off-by: Tiezhu Yang > --- > arch/loongarch/net/bpf_jit.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c > index 169ff8b3915e..8c907c2c42f7 100644 > --- a/arch/loongarch/net/bpf_jit.c > +++ b/arch/loongarch/net/bpf_jit.c > @@ -480,10 +480,12 @@ static int build_insn(const struct bpf_insn *insn, = struct jit_ctx *ctx, bool ext > case 8: > move_reg(ctx, t1, src); > emit_insn(ctx, extwb, dst, t1); > + emit_zext_32(ctx, dst, is32); > break; > case 16: > move_reg(ctx, t1, src); > emit_insn(ctx, extwh, dst, t1); > + emit_zext_32(ctx, dst, is32); > break; > case 32: > emit_insn(ctx, addw, dst, src, LOONGARCH_GPR_ZERO= ); > -- > 2.42.0 > >