Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1899170ybz; Thu, 30 Apr 2020 07:25:49 -0700 (PDT) X-Google-Smtp-Source: APiQypJuxlQ01eZ3UceOwVT4+IkmKCVKaeUVQj07yHTASvtNk/aSWfJ0FltxNAvgIIbQxAHV4yw4 X-Received: by 2002:a17:906:f1c4:: with SMTP id gx4mr2818798ejb.171.1588256749577; Thu, 30 Apr 2020 07:25:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588256749; cv=none; d=google.com; s=arc-20160816; b=BfDxZYv/rzNIq7rKhWFGEA1LBcsmu0g6Vvn7VTfG/6zCGTNlNKyn/iirQS494qtJeC 1WYCNg3A3eEkqbi2FDmkqf14xVxrFomO6qPdgGNOSJzOa6Ars52iDoqU+Mea2A4CGZBB +1i6utmGx/LzbjGektGY895fPusjjSSQGX+M24A3U0Na+SeKqYNQMiq5pUhV1LwbfXe0 jRtbPYkvx5x1F/kcvjskIN/LtWUGexH/nttMeMRIK+e+Ab7LGP+JaQ1Oe//K1y4A+ufs oxIzrvEvIg/mF+lKljjY2LGrTOgdLVNZaffGljzT9h9vo1oQOFAEb0LfKB+hNrtYiEm1 FgTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=l8GCWY92duqdcsv06uiJ2/8DfkZLpd16ozEeQxW5Bpg=; b=VB6YKDDHT3qbVFqSiIHPsgcnc9WI312V3BPDym7Sh9poMssrJXLepUOlT48zpYJ32z cYLQJlvoPk/nnWLB7jc7YIAYkCOyTS8ILeYjjgaJmcrZkeEKng2pZZwkedOeb3FquXZp ZMphp7Excy5r4pGH7x+dxkmC/NIWuqAHC1ma0zSoqmwLc+l46vrOCX90m5m27gv5RJys MUYM/9OFr3QpeEmxYF5pSQNgdrJEZRIiEhs2jmcxTh7jO8IfCpn9BpDs8Sscc5w2D9Vv 2gov+6vZC2qEPiCT/NSMLCLojDbKR/FC61T5fM4S4ZoC3dQU6tHIqUj2/QUIG7XikO9V UN2g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b26si5497436edx.291.2020.04.30.07.25.26; Thu, 30 Apr 2020 07:25:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727963AbgD3OXs (ORCPT + 99 others); Thu, 30 Apr 2020 10:23:48 -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!