Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4821825iob; Mon, 9 May 2022 02:24:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8bSjlaBjvdxS9YirRxMyMj8XrY3jPumJiITfiyQg2Dn94Atl3zGN4uNHkal4g0xM5TpCL X-Received: by 2002:a17:90b:3ecc:b0:1dc:9471:31a1 with SMTP id rm12-20020a17090b3ecc00b001dc947131a1mr25545589pjb.220.1652088261594; Mon, 09 May 2022 02:24:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652088261; cv=none; d=google.com; s=arc-20160816; b=sBgtA/7rjKADBCefWQX3WESvlWi1TTbjlU8p+zT4BG/3IpV0+Igw+7KihVIlsRshrh 1iKbfZuuQkb3Z+KUSkeHfVRnqVJkwuYH8O+4wYOBqJCkp1JXXTQRsr9WNPbnURIAH+vJ KB57p5zhveyjYr61PAW5oFPTI7UUqUEfeW5pawAfHbzLYyKSScJFWGHIzI1QPxux6X25 Fjsf4TgEZy+3novUeA2ueZeYPWuXCKRYMnO7kq9o6uuhLheGXf+W3KLSALxEx9ggsvo6 TdT3q5v0x9L2eMA7SLPjCqK3e091IgAxXWcmzj9VSvYt8DfjP2kGb3iHr+i/56oGBgcO 7eeg== 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=N3A1rf/Rj0PDegZIBfqZUEZZbtuVQj5afQJ+DdGLJXY=; b=VpGsPNjBYQUEeEWMGkHDiJagBrQlPOJ6CBK27hqapd7gbTfKKM0JQ80J5W2KBC8878 f6WF1LZYP9wTV1qF2jmXB1wTJN4udCKRkihYywXRttRaRaN8oVj6dOhv0uCFb3mnhfAO 1jMZ5U6AiObQa1VksekPhZDu7IaONy471P1iefiD9QJvtLKbENx8OsYzFyCev8nhAswo r7MMsF81ujJxmzB31DOjSXa44rAXyw8Ear3HcO3OzVjTRoItmXNDmA74AhteuusqSWBC R+zgSrykJ2icyQ2kGmO81iJEoFMVP2fml9CASCSgpk+0Q4fu8Nw/LgZS+oR8Wvh8WYxp iJhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=qIRoPoyI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s13-20020a65644d000000b003c640139e92si10793267pgv.720.2022.05.09.02.24.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 02:24:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=qIRoPoyI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 01A9620D56E; Mon, 9 May 2022 02:14:51 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1444571AbiEFVse (ORCPT + 99 others); Fri, 6 May 2022 17:48:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348985AbiEFVsb (ORCPT ); Fri, 6 May 2022 17:48:31 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32E856FA1C; Fri, 6 May 2022 14:44:47 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id l18so16722278ejc.7; Fri, 06 May 2022 14:44:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=N3A1rf/Rj0PDegZIBfqZUEZZbtuVQj5afQJ+DdGLJXY=; b=qIRoPoyIi9YUs2nECEBig8BQu3212ApJ192x/PT3kMGoYGdOdLgi4i/CpRitLS2c5Q tR8aBD/U8y02V1Do3uwlRPKXizYTv0uL7qWSMEvP5UO3yhPCR6vYjRHr+gi32YQE415O cTgbnS3ikd6RrO+hPDJc3+zcDE0Vtk/E+l5qf2hKFV+xpAAKmpcyHbmMplqWRjSIt3mb aldH2gdqvT0FDDBx4XJYO6M3Szu3ig6UabTifk/hdSr8FRF5PeRgnUdgpF3B3i0jjhEt jsxFTcGvFJtcYxIic4jEtB7hX3mtnva63X2s7cOyBCrMHiCOwDw4A99hJx/2KR7aemGd OlwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=N3A1rf/Rj0PDegZIBfqZUEZZbtuVQj5afQJ+DdGLJXY=; b=FDbXa2FWTQP909yFKrqk5VukJnrqiff9oGFqidS/pA2zQVEURTzway7KtuVVdAgxcu 8+L9hniKsmfpX+8HWw9fsTOppzSa6QYItgTVJg/sFi6ScFoFc2TwNHHd8QfoEmkSEzmx KzrY2ES1X6y8q3TVLJ6HDeoKPy2Nu30hLqi6F2Y7bobHx6DjEqQmZiAiOaO5vPx2k/Uf DperEChh7F8C4lZ7nyGjZRpnoUgWE1+gDom7LMRN+TEE1JrZEAxekmhuCu5vhZmskMw7 BE37qHRmD34rCfyFQ1F99e9xgdqZUB4UdvDQSgsBQpHVH/tEKvClqIVM52q8vnrKQMdJ +GDg== X-Gm-Message-State: AOAM532pk8oE5SbAaUUMqxPjnVbTA8K9Fx2+xpEhBmL/nCX039QttLsF fUfK5rTxozcKjqPgQkXxbOTZCcBPhNN9O80wC0o= X-Received: by 2002:a17:907:6d9d:b0:6da:7d4c:287f with SMTP id sb29-20020a1709076d9d00b006da7d4c287fmr4633735ejc.741.1651873485631; Fri, 06 May 2022 14:44:45 -0700 (PDT) MIME-Version: 1.0 References: <20220429014240.3434866-1-pulehui@huawei.com> <20220429014240.3434866-3-pulehui@huawei.com> In-Reply-To: <20220429014240.3434866-3-pulehui@huawei.com> From: Luke Nelson Date: Fri, 6 May 2022 14:44:34 -0700 Message-ID: Subject: Re: [PATCH bpf-next v2 2/2] riscv, bpf: Support riscv jit to provide bpf_line_info To: Pu Lehui Cc: bpf , linux-riscv , Networking , open list , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Xi Wang , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Paul Walmsley , Palmer Dabbelt , Albert Ou Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Thanks for the patch! I have a couple of notes written down below. > + ctx->prologue_offset = ctx->ninsns; > ... > + prologue_len = ctx->epilogue_offset - ctx->prologue_offset; > + for (i = 0; i < prog->len; i++) > + ctx->offset[i] = ninsns_rvoff(prologue_len + ctx->offset[i]); The logic looks correct to me; my only nit is that the name prologue_offset might be a bit confusing. The prologue is always at the beginning of the final JITed program, it just happens to be that the prologue is emitted "out of order" on the initial/internal passes that compute offsets. What prologue_offset really measures in your code is the length of the body of the JITed program. What do you think about renaming prologue_offset to something like body_len? Then the line to compute prologue_len becomes: prologue_len = ctx->epilogue_offset - ctx->body_len; This version makes more sense to me why it's correct. Curious what you think. > + bpf_prog_fill_jited_linfo(prog, ctx->offset); Here's a quote from the comment that documents bpf_prog_fill_jited_linfo in kernel/bpf/core.c: /* The jit engine is responsible to provide an array * for insn_off to the jited_off mapping (insn_to_jit_off). ... * jited_off is the byte off to the last byte of the jited insn. This comment says that ctx->offset (passed to this function as insn_to_jit_off) should map each instruction to the offset of the last byte of the JITed instructions, but as I understand it your patch sets ctx->offset[i] to be the offset _one past_ the last byte of the JITed instructions (i.e., the first byte of the next instruction). I'm not sure if this is a bug in your code, in this comment, or in my understanding :) As a concrete example, suppose the BPF instruction at index 0 compiles to 2 (non-compressed) RISC-V instructions, or 8 bytes. Then ctx->offset[0] will be 2 after the initial JIT passes, and your code would update ctx->offset[0] to be 4*prologue_len + 8. This offset corresponds to the first byte of insns[1], not the last byte of insn[0], which would be 4*prologue_len + 7. My guess would be that the comment is out of date and your code is doing the correct thing, since it seems in line with what other JITs are doing. If that's the case, maybe we can consider updating that comment at some point. I'm curious if the tests you ran would break if you changed your code to match what the comment says (i.e., subtracting 1 byte from each element in ctx->offset before passing to bpf_prog_fill_jited_linfo). > ./test_progs -a btf > #19 btf:OK > Summary: 1/215 PASSED, 0 SKIPPED, 0 FAILED Last, did you have a chance to run any of the other tests with your change (e.g., test_verifier, test_bpf.ko, other tests in test_progs)? I don't expect this change to break any tests, but may as well run them if it's easy enough just to be sure. Thanks! - Luke