From mboxrd@z Thu Jan 1 00:00:00 1970 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 98000C433EF for ; Mon, 11 Jul 2022 11:58:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230096AbiGKL6W (ORCPT ); Mon, 11 Jul 2022 07:58:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230050AbiGKL6V (ORCPT ); Mon, 11 Jul 2022 07:58:21 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D008D32BBB for ; Mon, 11 Jul 2022 04:58:19 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id i128-20020a1c3b86000000b003a2ce31b4f8so4867812wma.1 for ; Mon, 11 Jul 2022 04:58:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=BQEPX2oLS4VAKW2DD0EGpgirZ7z4jyQAcpaLby2W2Ts=; b=bhB6lDedVM5GCtm3RN67vsyj7pGah/TwUoSfOWdn7V8TyJdb5ImGupDVq4LfeiheP/ KOAscNuTWRp2WFA0yWg6PBhk4UflvQSCKtdrR/o8DmDJnusIQpGZ6X3sv8hq/HcnTaDl UtPSJxS5OjS6SFYzs67C1X9WJm5wy4Vg1T7GbPv+2+l8mJdvsv/0KEw799t1lHz+KPcl 2tUeYFJNL2DMko4SuvFPGuwDrxN3x+WMThq2y+xZ6IuXke/gdPqPJpkNJ5rXUe1N+twN zblYstSj4Q0P9QIlaE91xbdF6b9AYALeUc/uVmOc8QXcW+gRehj/bEfrOrWSY+4fibSw OCcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=BQEPX2oLS4VAKW2DD0EGpgirZ7z4jyQAcpaLby2W2Ts=; b=6X82mAtFTArwUSLpl3q7V/XB1INq/HGAs6eZpJpZJGWGtINlUNTyeBOOj28ar/qztT 8pbja873FdNqnCu9vrygEjgBqyhjInQRmrWNH653uYqjN4clEOvnuNFGKuODcu7HMvD2 V/Zw4uYgdnGNkDJTdaPbDxl/P9f15rBpTgW1Dims257qPyWVSl7aj8JeYh3G27J+dOOW mFF5NR4h2fUI8v0lgZ3wqFQR1/wShdRMArhGW/lfPypJ3bWBxPBzG0IFFk4WtJTqovF+ 0HX7COofUGXUF3jEccqCh1t+crotNiMsmilyG/fZC9cKWXXLAxCUPz6msFlOeEGhkAea 6Utg== X-Gm-Message-State: AJIora9Ur4vUu0+30dg2yRULyDgxWk5mYqKqdMI1Nc5JWywouEfdciyF 8i2mJXUCUu19C/AfI/q2qH6W3w== X-Google-Smtp-Source: AGRyM1uEchsOaegipf3GjUUvcb3Np4cRU36PBEf3G1M1h2oadk+gzl6uHqzdYQujNkpiR2MHW0tajg== X-Received: by 2002:a05:600c:1e10:b0:3a2:e35c:f5fb with SMTP id ay16-20020a05600c1e1000b003a2e35cf5fbmr10434045wmb.27.1657540698361; Mon, 11 Jul 2022 04:58:18 -0700 (PDT) Received: from myrica (cpc92880-cmbg19-2-0-cust679.5-4.cable.virginm.net. [82.27.106.168]) by smtp.gmail.com with ESMTPSA id ch9-20020a5d5d09000000b0021da4b6c6f7sm2898365wrb.40.2022.07.11.04.58.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jul 2022 04:58:17 -0700 (PDT) Date: Mon, 11 Jul 2022 12:57:52 +0100 From: Jean-Philippe Brucker To: Xu Kuohai Cc: bpf@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Will Deacon , KP Singh , Mark Rutland , Catalin Marinas , Daniel Borkmann , Alexei Starovoitov , Andrii Nakryiko , Zi Shen Lim , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , "David S . Miller" , Hideaki YOSHIFUJI , David Ahern , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , Jakub Kicinski , Jesper Dangaard Brouer , Russell King , James Morse , Hou Tao , Jason Wang Subject: Re: [PATCH bpf-next v7 4/4] bpf, arm64: bpf trampoline for arm64 Message-ID: References: <20220708093032.1832755-1-xukuohai@huawei.com> <20220708093032.1832755-5-xukuohai@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220708093032.1832755-5-xukuohai@huawei.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 08, 2022 at 05:30:32AM -0400, Xu Kuohai wrote: > +static void invoke_bpf_prog(struct jit_ctx *ctx, struct bpf_tramp_link *l, > + int args_off, int retval_off, int run_ctx_off, > + bool save_ret) > +{ > + u32 *branch; > + u64 enter_prog; > + u64 exit_prog; > + u8 r0 = bpf2a64[BPF_REG_0]; > + struct bpf_prog *p = l->link.prog; > + int cookie_off = offsetof(struct bpf_tramp_run_ctx, bpf_cookie); > + > + if (p->aux->sleepable) { > + enter_prog = (u64)__bpf_prog_enter_sleepable; > + exit_prog = (u64)__bpf_prog_exit_sleepable; > + } else { > + enter_prog = (u64)__bpf_prog_enter; > + exit_prog = (u64)__bpf_prog_exit; > + } > + > + if (l->cookie == 0) { > + /* if cookie is zero, one instruction is enough to store it */ > + emit(A64_STR64I(A64_ZR, A64_SP, run_ctx_off + cookie_off), ctx); > + } else { > + emit_a64_mov_i64(A64_R(10), l->cookie, ctx); > + emit(A64_STR64I(A64_R(10), A64_SP, run_ctx_off + cookie_off), > + ctx); > + } > + > + /* save p to callee saved register x19 to avoid loading p with mov_i64 > + * each time. > + */ > + emit_addr_mov_i64(A64_R(19), (const u64)p, ctx); > + > + /* arg1: prog */ > + emit(A64_MOV(1, A64_R(0), A64_R(19)), ctx); > + /* arg2: &run_ctx */ > + emit(A64_ADD_I(1, A64_R(1), A64_SP, run_ctx_off), ctx); > + > + emit_call(enter_prog, ctx); > + > + /* if (__bpf_prog_enter(prog) == 0) > + * goto skip_exec_of_prog; > + */ > + branch = ctx->image + ctx->idx; > + emit(A64_NOP, ctx); > + > + /* save return value to callee saved register x20 */ > + emit(A64_MOV(1, A64_R(20), A64_R(0)), ctx); > + > + emit(A64_ADD_I(1, A64_R(0), A64_SP, args_off), ctx); > + if (!p->jited) > + emit_addr_mov_i64(A64_R(1), (const u64)p->insnsi, ctx); > + > + emit_call((const u64)p->bpf_func, ctx); > + > + /* store return value, which is held in r0 for JIT and in x0 > + * for interpreter. > + */ > + if (save_ret) > + emit(A64_STR64I(p->jited ? r0 : A64_R(0), A64_SP, retval_off), > + ctx); This should be only A64_R(0), not r0. r0 happens to equal A64_R(0) when jitted due to the way build_epilogue() builds the function at the moment, but we shouldn't rely on that. Apart from that, for the series Reviewed-by: Jean-Philippe Brucker From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BF680C433EF for ; Mon, 11 Jul 2022 11:59:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=yKvperiys0JdLSNxVoStuALOp6+sg7wxDxIjDTpD6sQ=; b=H3bCGGCbAFAFhp eOvP5TgQjI7JikyFtKsrymGt8VSxkb8ntKxKDLXGqwn6aNn2IkHeiUx4M+7Qu7/G6m8XkKxY2h68P nD0Mk4ZyN1xN8ConkVkU5kgxRb6+khoAdAuTwM5t2/9H1upp8r+WUKPeK9Bj60ps3bURGjrxi5wGa X4DLYg17zkV5wQUOm0zMDMA8HQSXcKieeeBaIXn7sTGAt2Rqr5yUHoEEXf/hR+z4c+3nNbIWAXXXj LUIf839LXIG/84hxajMACVah+wW1s5Fj1qVLcSJv9sOVf29yulcpH9HOu1x1pQ1tP9C2FrpqLWSB6 tHJq49QHTA//A6mDQYZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oAs3V-001E71-36; Mon, 11 Jul 2022 11:58:25 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oAs3S-001E3y-4v for linux-arm-kernel@lists.infradead.org; Mon, 11 Jul 2022 11:58:23 +0000 Received: by mail-wm1-x330.google.com with SMTP id v67-20020a1cac46000000b003a1888b9d36so4887619wme.0 for ; Mon, 11 Jul 2022 04:58:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=BQEPX2oLS4VAKW2DD0EGpgirZ7z4jyQAcpaLby2W2Ts=; b=bhB6lDedVM5GCtm3RN67vsyj7pGah/TwUoSfOWdn7V8TyJdb5ImGupDVq4LfeiheP/ KOAscNuTWRp2WFA0yWg6PBhk4UflvQSCKtdrR/o8DmDJnusIQpGZ6X3sv8hq/HcnTaDl UtPSJxS5OjS6SFYzs67C1X9WJm5wy4Vg1T7GbPv+2+l8mJdvsv/0KEw799t1lHz+KPcl 2tUeYFJNL2DMko4SuvFPGuwDrxN3x+WMThq2y+xZ6IuXke/gdPqPJpkNJ5rXUe1N+twN zblYstSj4Q0P9QIlaE91xbdF6b9AYALeUc/uVmOc8QXcW+gRehj/bEfrOrWSY+4fibSw OCcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=BQEPX2oLS4VAKW2DD0EGpgirZ7z4jyQAcpaLby2W2Ts=; b=bBtDOdR+BHQ1Ojlp6AIks8DJKWFnhFGKzxFZQuB0jGza7hjdhNZzWrWJtj247Pk2It g82W/vOHHx466G4Mjzn1dBHN9fzmxLoXf3ih1t3ml9+E1k6CaRfKAjcqUTpBaquWeU4s LsjClJC4GjPvtxwArvVp7Znq/xugGVb3Tz5UgBpKQk275Y2XTGYdK8It6gfcn9VDy0ux 3eA2dpfCshBGbLYICVDT54TF643BfU2W9Q2ojl/ycxSj6pTGxLDfhTW3rRB2kmIaj2Te U4ZXTvs/MHsGfqDo0s9iE9qcl7eE63knUWFuAZr6T755luVjMYGLKgS+2UcLU05/mXyF G63w== X-Gm-Message-State: AJIora/WomF0I2cl2fdkK2aULtOWYnfT5SfX2NKz+F09cpH3HCBUCwQ5 nh/UuCaBIy7ScsxoQr4cGRcFJQ== X-Google-Smtp-Source: AGRyM1uEchsOaegipf3GjUUvcb3Np4cRU36PBEf3G1M1h2oadk+gzl6uHqzdYQujNkpiR2MHW0tajg== X-Received: by 2002:a05:600c:1e10:b0:3a2:e35c:f5fb with SMTP id ay16-20020a05600c1e1000b003a2e35cf5fbmr10434045wmb.27.1657540698361; Mon, 11 Jul 2022 04:58:18 -0700 (PDT) Received: from myrica (cpc92880-cmbg19-2-0-cust679.5-4.cable.virginm.net. [82.27.106.168]) by smtp.gmail.com with ESMTPSA id ch9-20020a5d5d09000000b0021da4b6c6f7sm2898365wrb.40.2022.07.11.04.58.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jul 2022 04:58:17 -0700 (PDT) Date: Mon, 11 Jul 2022 12:57:52 +0100 From: Jean-Philippe Brucker To: Xu Kuohai Cc: bpf@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Will Deacon , KP Singh , Mark Rutland , Catalin Marinas , Daniel Borkmann , Alexei Starovoitov , Andrii Nakryiko , Zi Shen Lim , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , "David S . Miller" , Hideaki YOSHIFUJI , David Ahern , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , Jakub Kicinski , Jesper Dangaard Brouer , Russell King , James Morse , Hou Tao , Jason Wang Subject: Re: [PATCH bpf-next v7 4/4] bpf, arm64: bpf trampoline for arm64 Message-ID: References: <20220708093032.1832755-1-xukuohai@huawei.com> <20220708093032.1832755-5-xukuohai@huawei.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220708093032.1832755-5-xukuohai@huawei.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220711_045822_212729_50821B75 X-CRM114-Status: GOOD ( 17.14 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Jul 08, 2022 at 05:30:32AM -0400, Xu Kuohai wrote: > +static void invoke_bpf_prog(struct jit_ctx *ctx, struct bpf_tramp_link *l, > + int args_off, int retval_off, int run_ctx_off, > + bool save_ret) > +{ > + u32 *branch; > + u64 enter_prog; > + u64 exit_prog; > + u8 r0 = bpf2a64[BPF_REG_0]; > + struct bpf_prog *p = l->link.prog; > + int cookie_off = offsetof(struct bpf_tramp_run_ctx, bpf_cookie); > + > + if (p->aux->sleepable) { > + enter_prog = (u64)__bpf_prog_enter_sleepable; > + exit_prog = (u64)__bpf_prog_exit_sleepable; > + } else { > + enter_prog = (u64)__bpf_prog_enter; > + exit_prog = (u64)__bpf_prog_exit; > + } > + > + if (l->cookie == 0) { > + /* if cookie is zero, one instruction is enough to store it */ > + emit(A64_STR64I(A64_ZR, A64_SP, run_ctx_off + cookie_off), ctx); > + } else { > + emit_a64_mov_i64(A64_R(10), l->cookie, ctx); > + emit(A64_STR64I(A64_R(10), A64_SP, run_ctx_off + cookie_off), > + ctx); > + } > + > + /* save p to callee saved register x19 to avoid loading p with mov_i64 > + * each time. > + */ > + emit_addr_mov_i64(A64_R(19), (const u64)p, ctx); > + > + /* arg1: prog */ > + emit(A64_MOV(1, A64_R(0), A64_R(19)), ctx); > + /* arg2: &run_ctx */ > + emit(A64_ADD_I(1, A64_R(1), A64_SP, run_ctx_off), ctx); > + > + emit_call(enter_prog, ctx); > + > + /* if (__bpf_prog_enter(prog) == 0) > + * goto skip_exec_of_prog; > + */ > + branch = ctx->image + ctx->idx; > + emit(A64_NOP, ctx); > + > + /* save return value to callee saved register x20 */ > + emit(A64_MOV(1, A64_R(20), A64_R(0)), ctx); > + > + emit(A64_ADD_I(1, A64_R(0), A64_SP, args_off), ctx); > + if (!p->jited) > + emit_addr_mov_i64(A64_R(1), (const u64)p->insnsi, ctx); > + > + emit_call((const u64)p->bpf_func, ctx); > + > + /* store return value, which is held in r0 for JIT and in x0 > + * for interpreter. > + */ > + if (save_ret) > + emit(A64_STR64I(p->jited ? r0 : A64_R(0), A64_SP, retval_off), > + ctx); This should be only A64_R(0), not r0. r0 happens to equal A64_R(0) when jitted due to the way build_epilogue() builds the function at the moment, but we shouldn't rely on that. Apart from that, for the series Reviewed-by: Jean-Philippe Brucker _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel