Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2547099ybl; Mon, 19 Aug 2019 03:57:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqw086cUVXvcf/pCcPnN8+7iqs7m9boy/Ut4H05CpyYz75lkahih27cs8Grt4olOeomypb0U X-Received: by 2002:a63:714a:: with SMTP id b10mr19959529pgn.25.1566212262339; Mon, 19 Aug 2019 03:57:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566212262; cv=none; d=google.com; s=arc-20160816; b=T2OoCq2PN03CfBUEJYrPFP7n7VLNKdsJgqZQeYSChIgpXKFcFbLM9+z/jnlX7s/u56 2MxNRInX8dVAUcpGLFvJsZgwLFA1AAly/0E4CBqPS2UGaby09oOUzj8ho8zzz8V1sDrN o36sZ3CE92ytQALNekyGMOodOQgF1bbko+zuLYwslAYmGGzjypaNM6PQ0oey48j8HKky ERt2//VBEnQWVXNcsmWZvVN1xwSH16creHq2H0bjJ2zIFGIEeU3zAJSP7FBifPWFAbV7 tVAmle9I2Wp0DHOtWGNEBQ6WGLJJ2UjNZW5tc40JQN5zEZmw65lnNvne55JPr0uNvwtY X73g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=0me3WvcGTEge7gXybD0rl9/00RWjNn7JrUnKm8Cq25s=; b=vHsuaajhaYG4lsb9wRmzK/q8J+wD/Oax4ODhqrqKo+y8lnV+8Ei4zWu5h28QW50BfO BwE86ZV72djxm27rvMxMEf5521wXBWE45skvn8UGFggM8vX89M8VS0N32MP3DvNKRyqs eixV+Lx4BKnKklJDgbRlXWyoRiOITecbyoeREUTkf/znXCaoR7GWGKYNhKbGVSTpBZbL n/JXu6kolFclHFcqfvmIjnYoKjD3YSlCh1iV5TDuTsw+LhbKwtUmZVhRzOgGcXSGIIcM mwp5iKvYp2DnpJxCB6i3zQVKOs3IvHv/Q9lZO0heioMyMXLZmi3nJROcWGaHjMXeVtT0 Nu6g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y22si8574828plp.59.2019.08.19.03.57.27; Mon, 19 Aug 2019 03:57:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727308AbfHSK4Y (ORCPT + 99 others); Mon, 19 Aug 2019 06:56:24 -0400 Received: from smtp2200-217.mail.aliyun.com ([121.197.200.217]:49220 "EHLO smtp2200-217.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726550AbfHSK4Y (ORCPT ); Mon, 19 Aug 2019 06:56:24 -0400 X-Alimail-AntiSpam: AC=CONTINUE;BC=0.07440019|-1;CH=green;DM=CONTINUE|CONTINUE|true|0.340673-0.0196074-0.63972;FP=0|0|0|0|0|-1|-1|-1;HT=e02c03303;MF=han_mao@c-sky.com;NM=1;PH=DS;RN=3;RT=3;SR=0;TI=SMTPD_---.FEaxY0q_1566212179; Received: from localhost(mailfrom:han_mao@c-sky.com fp:SMTPD_---.FEaxY0q_1566212179) by smtp.aliyun-inc.com(10.147.44.129); Mon, 19 Aug 2019 18:56:19 +0800 Date: Mon, 19 Aug 2019 18:56:19 +0800 From: Mao Han To: Paul Walmsley Cc: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: Re: [PATCH V3 0/3] riscv: Add perf callchain support Message-ID: <20190819105618.GA6377@vmh-VirtualBox> References: <20190819081758.GA15999@vmh-VirtualBox> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190819081758.GA15999@vmh-VirtualBox> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 19, 2019 at 04:18:01PM +0800, Mao Han wrote: > Hi Paul, > On Fri, Aug 16, 2019 at 10:14:01AM -0700, Paul Walmsley wrote: > > Hello Mao Han, > > > > On Fri, 17 May 2019, Mao Han wrote: > > > > > This patch set add perf callchain(FP/DWARF) support for RISC-V. > > > It comes from the csky version callchain support with some > > > slight modifications. The patchset base on Linux 5.1. > > > > > > CC: Palmer Dabbelt > > > CC: linux-riscv > > > CC: Christoph Hellwig > > > CC: Guo Ren > > > > I tried these patches on v5.3-rc4, both on the HiFive Unleashed board > > with a Debian-based rootfs and QEMU rv64 with a Fedora-based rootfs. For > > QEMU, I used defconfig, and for the HiFive Unleashed, I added a few more > > Kconfig directives; and on both, I enabled CONFIG_PERF_EVENTS. I built > > the perf tools from the kernel tree. > > > > Upon running "/root/bin/perf record -e cpu-clock --call-graph fp > > /bin/ls", I see the backtraces below. The first is on the HiFive > > Unleashed, the second is on QEMU. > > > > Could you take a look and tell me if you see similar issues? And if not, > > could you please walk me through your process for testing these patches on > > rv64, so I can reproduce it here? > > > > I'v tried the command line above and got similar issues with probability. > unwind_frame_kernel can not stop unwind when fp is a quite large > value(like 0x70aac93ff0eff584) which can pass the simple stack check. > if (kstack_end((void *)frame->fp)) > return -EPERM; > if (frame->fp & 0x3 || frame->fp < TASK_SIZE) > return -EPERM; > handle_exception from arch/riscv/kernel/entry.S will use s0(fp) as temp > register. The context for this frame is unpredictable. We may add more > strict check in unwind_frame_kernel or keep s0 always 0 in handle_exception > to fix this issue. > perf record -e cpu-clock --call-graph fp /bin/ls seems can work stably with this change applied. diff --git a/arch/riscv/kernel/perf_callchain.c b/arch/riscv/kernel/perf_callchain.c index 8b57903..dd27c67 100644 --- a/arch/riscv/kernel/perf_callchain.c +++ b/arch/riscv/kernel/perf_callchain.c @@ -16,6 +16,8 @@ static int unwind_frame_kernel(struct stackframe *frame) return -EPERM; if (frame->fp & 0x3 || frame->fp < TASK_SIZE) return -EPERM; + if (frame->fp < CONFIG_PAGE_OFFSET) + return -EPERM; *frame = *((struct stackframe *)frame->fp - 1); if (__kernel_text_address(frame->ra)) { PS: I got some compile error while compiling glibc 2.30 with linux v5.3-rc4 header. vfork.S include linux/sched.h(./include/uapi/linux/sched.h) which has a struct clone_args inside, added by 7f192e3cd316ba58c88dfa26796cf77789dd9872.