Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp320745rwi; Fri, 14 Oct 2022 02:27:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6OyhbAPjzOOTNfUzQvvGw6VDDN+3ieWG8MW2A6M9y53TxPM05xmnhp2wV9N0PGYD5oz5lC X-Received: by 2002:a17:907:6e28:b0:78d:20d7:1431 with SMTP id sd40-20020a1709076e2800b0078d20d71431mr2834814ejc.333.1665739674840; Fri, 14 Oct 2022 02:27:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665739674; cv=none; d=google.com; s=arc-20160816; b=G5b+dQ4uhoLAG8m6cQxVvossuYXOAkx7KJuee/J9CAfufglJPjzDBrFkN/slLY3rmn oAwAxvwjIeixy4PcT6B3FLC6Or71c2AkXXbRV8O0K87RqBuO/G8Q0LjYx1RpkiuQVhCX G5WzqV5wytWXOFdPkKLFgCvMSvStgwsdNrDq71dRWh4w6srx3puqyzt7u7rWs559nuoP SM1EgfXxQ+5/T0IZCPGyPs6pQwGxBFqjeei1ngw8sjnFwdKCh5juQdIJ6KSbu4dGpdpn Iagm1pd+SxkMFyMZuyXl0wxN2kWoSqBdLMgQcqWwUPZI0C6aVDF0up4WR4lGDqxWjp4a WxdA== 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=gZ2cMm+FtFaDhRGLv8zpzr1osiclC+0rQ1yQcsTxBkE=; b=syTddaF6TLVOIHa6LtxqF0ZUciA4sjW4wIkkZ/h7xHuzoLGc65mWtiO54CaYldJY06 7GTbEB0gDX8dmbK00b2I1sV3JkXW48WaNheb0Fpds1pHKQU37yoS3aC4yoAlzjUWPAeH w041JKzjGxZVY5Cy7uhFjP/BA9p54EboIqMDYPAKJPwPAg/5bRHdWtjP+Z7LNkRd33DT F0El38l9pP8SizR0GIInPWcoRcmpv1Du8ZAkZ3YIz8yeljnAt68z+a0kfXgAHUOSWxic B1QtQHFIkNeQfXnddtLhQEZQCnuw4sCwL3yHZrgajS/YZ+WwJha3osnKaRJET6ZEKW0J KFAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="ef/3XGuF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u21-20020aa7d895000000b004569899e0bcsi1765707edq.138.2022.10.14.02.27.29; Fri, 14 Oct 2022 02:27:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="ef/3XGuF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229980AbiJNI6X (ORCPT + 99 others); Fri, 14 Oct 2022 04:58:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229916AbiJNI6W (ORCPT ); Fri, 14 Oct 2022 04:58:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8745B14EC4B for ; Fri, 14 Oct 2022 01:58:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2CE6961A3E for ; Fri, 14 Oct 2022 08:58:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8999DC433B5 for ; Fri, 14 Oct 2022 08:58:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665737900; bh=jjLpNiBtYUiuOX7cnEKMRg+pshJMGQgSYBE4bgVEUIU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ef/3XGuFVgUUNlF1CkC9qw6I+JqB7jQOVfGbhBOLpsl16VCmb+d514fxn2DpzYxYw Hhu1A//L1dLqw7XGRdb56GabTHhDqRenlZuu1NDOJGFF2hYXqGeJ1UGfGUJfUi8Sgm TUq4penAHlqQd3dzB2WFLy106LhHP4CyzkufCQlfNZ1WZKkUs0JxdeiNYRG6LPYUsb F29ddHnA8qvS8HAxWpp/8aP29DE3qSjhRp11k3ckiLm4KB2cbNcomxWJO6KyFfENK+ gNjueg6UgkvaCLQ+8lHAY3BBffrIMGrCK6ToL4MxNMl0GCtgd0/jxr1CoehvVcM8TJ 5TBrLZ+79Fvlg== Received: by mail-ed1-f41.google.com with SMTP id e18so5946240edj.3 for ; Fri, 14 Oct 2022 01:58:20 -0700 (PDT) X-Gm-Message-State: ACrzQf1Wcyo/ebMvbPlXRse3T6NhQJMeIXiuwsm9pdpMi0qqxAIMtcSy zuD8OWOa/wQ2qtMtBarS0y6tdYrRbRexFYT2JlE= X-Received: by 2002:aa7:d4d9:0:b0:45c:7eae:d8d8 with SMTP id t25-20020aa7d4d9000000b0045c7eaed8d8mr3411632edr.254.1665737898655; Fri, 14 Oct 2022 01:58:18 -0700 (PDT) MIME-Version: 1.0 References: <20221013154000.3462836-1-chenhuacai@loongson.cn> <8a8fa581-94a9-649d-8c01-f1afd4bc9514@xen0n.name> In-Reply-To: From: Huacai Chen Date: Fri, 14 Oct 2022 16:58:07 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] LoongArch: BPF: Avoid declare variables in switch-case To: Tiezhu Yang Cc: WANG Xuerui , Huacai Chen , loongarch@lists.linux.dev, Xuefeng Li , Guo Ren , Jiaxun Yang , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 14, 2022 at 10:18 AM Tiezhu Yang wrote: > > > > On 10/14/2022 09:13 AM, Huacai Chen wrote: > > Hi, Xuerui, > > > > On Fri, Oct 14, 2022 at 12:43 AM WANG Xuerui wrote: > >> > >> On 10/13/22 23:40, Huacai Chen wrote: > >>> Not all compilers support declare variables in switch-case, so move > >>> declarations to the beginning of a function. Otherwise we may get such > >>> build errors: > > ... > > >>> > >>> static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool extra_pass) > >>> { > >>> - const bool is32 = BPF_CLASS(insn->code) == BPF_ALU || > >>> - BPF_CLASS(insn->code) == BPF_JMP32; > >>> + u8 t0 = -1; > >> Here "t0" seems to be a versatile temp value, while the "t1" below is > >> the actual GPR $t1. What about renaming "t0" to something like "tmp" to > >> reduce confusion? I believe due to things like "t0 = LOONGARCH_GPR_ZERO" > >> the "t0" is 100% not an actual mapping to $t0. > > I rename t7 to t0 because there is no t3-t6, t7 looks very strange. > > But from emit_cond_jmp() the 3rd and 4th parameters have no difference > > so I suppose t0 is just OK, then whether rename it to tmp depends on > > Tiezhu's opinion. > > > > Use "tmp" seems better due to it is a temp value. OK, then I will use tmp or just tm for alignment. > > >>> + u64 func_addr; > >>> + bool func_addr_fixed; > >>> + int i = insn - ctx->prog->insnsi; > >>> + int ret, jmp_offset; > >>> const u8 code = insn->code; > >>> const u8 cond = BPF_OP(code); > >>> const u8 t1 = LOONGARCH_GPR_T1; > >>> @@ -400,8 +402,8 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext > >>> const u8 dst = regmap[insn->dst_reg]; > >>> const s16 off = insn->off; > >>> const s32 imm = insn->imm; > >>> - int jmp_offset; > >>> - int i = insn - ctx->prog->insnsi; > >>> + const u64 imm64 = (u64)(insn + 1)->imm << 32 | (u32)insn->imm; > >>> + const bool is32 = BPF_CLASS(insn->code) == BPF_ALU || BPF_CLASS(insn->code) == BPF_JMP32; > >> Please consider reducing diff damage and not touching parts not directly > >> affected by this change. For example this "is32" declaration and > >> initialization was moved although not related to this change. > > It looks reasonable, one change per patch is better. > > > I think defining variables from simple to complex and grouping them > > can make life easier. :) > > > > No strong opinion on this, I am OK either way. > > Thanks, > Tiezhu > >