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 X-Spam-Level: X-Spam-Status: No, score=-5.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3714C4724C for ; Thu, 30 Apr 2020 14:23:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9C57D2074A for ; Thu, 30 Apr 2020 14:23:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727986AbgD3OXt (ORCPT ); Thu, 30 Apr 2020 10:23:49 -0400 Received: from www62.your-server.de ([213.133.104.62]:45380 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726520AbgD3OXs (ORCPT ); Thu, 30 Apr 2020 10:23:48 -0400 Received: from sslproxy01.your-server.de ([78.46.139.224]) by www62.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1jUA6I-00086y-K3; Thu, 30 Apr 2020 16:23:42 +0200 Received: from [178.195.186.98] (helo=pc-9.home) by sslproxy01.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jUA6I-000JJ2-3f; Thu, 30 Apr 2020 16:23:42 +0200 Subject: Re: [PATCH bpf-next] bpf, riscv: Fix stack layout of JITed code on RV32 To: Xi Wang , Luke Nelson Cc: bpf@vger.kernel.org, Luke Nelson , Alexei Starovoitov , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh , Paul Walmsley , Palmer Dabbelt , Albert Ou , netdev@vger.kernel.org, linux-riscv@lists.infradead.org, Linux Kernel Mailing List References: <20200430005127.2205-1-luke.r.nels@gmail.com> From: Daniel Borkmann Message-ID: <61bfa5f6-eb21-3767-11c6-d8be46871c0e@iogearbox.net> Date: Thu, 30 Apr 2020 16:23:41 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.102.2/25798/Thu Apr 30 14:03:33 2020) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/30/20 4:14 AM, Xi Wang wrote: > On Wed, Apr 29, 2020 at 5:51 PM Luke Nelson wrote: >> >> This patch fixes issues with stackframe unwinding and alignment in the >> current stack layout for BPF programs on RV32. >> >> In the current layout, RV32 fp points to the JIT scratch registers, rather >> than to the callee-saved registers. This breaks stackframe unwinding, >> which expects fp to point just above the saved ra and fp registers. >> >> This patch fixes the issue by moving the callee-saved registers to be >> stored on the top of the stack, pointed to by fp. This satisfies the >> assumptions of stackframe unwinding. >> >> This patch also fixes an issue with the old layout that the stack was >> not aligned to 16 bytes. >> >> Stacktrace from JITed code using the old stack layout: >> >> [ 12.196249 ] [] walk_stackframe+0x0/0x96 >> >> Stacktrace using the new stack layout: >> >> [ 13.062888 ] [] walk_stackframe+0x0/0x96 >> [ 13.063028 ] [] show_stack+0x28/0x32 >> [ 13.063253 ] [] bpf_prog_82b916b2dfa00464+0x80/0x908 >> [ 13.063417 ] [] bpf_test_run+0x124/0x39a >> [ 13.063553 ] [] bpf_prog_test_run_skb+0x234/0x448 >> [ 13.063704 ] [] __do_sys_bpf+0x766/0x13b4 >> [ 13.063840 ] [] sys_bpf+0xc/0x14 >> [ 13.063961 ] [] ret_from_syscall+0x0/0x2 >> >> The new code is also simpler to understand and includes an ASCII diagram >> of the stack layout. >> >> Tested on riscv32 QEMU virt machine. >> >> Signed-off-by: Luke Nelson > > Thanks for the fix! > > Acked-by: Xi Wang Applied, thanks everyone!