Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2272396pxa; Mon, 17 Aug 2020 05:49:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0f9BMBrmNbg1GEb7XGCruYDMv/wcVJyt7hiIxUl7UFzKum/yXtJVp/WZ/eai/vswlWZK+ X-Received: by 2002:a50:ccd1:: with SMTP id b17mr14551572edj.165.1597668555493; Mon, 17 Aug 2020 05:49:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597668555; cv=none; d=google.com; s=arc-20160816; b=YOGer41SferB+G/kYOJK6/nXfLAkqQUKtGj8l3WZzXJXimTEi5tMACSVrPE3DaKmIR Nl3HnJTSnYTYTLlrTs2ht4+nDaa6UkuRJeE2qTp9FRCZVAgUIOyQgqZ0iNlO26jGKajG tBMEcte1MFJqFPrE9U3lV/uDRQ8SJcoPw6RXBUCP5NwWBL/wIqnJsBU/xvs+NDJ7fV0V geSAZjuP48Jxjy6uBsYFCy3X7TEirsxUSZB70MifdtCYCCV0AK+II4qSHMQgcnoegMGf VsGXktiteyTVTzePY6+EWJsREYKfrdF1B39pxbqgOLtRF/58ZhPlDYkglg0i0LvDEZSm ns7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=KJFQigoF4rz29/0gRqXehC3WCsD+R4OAjKuIveeU7BQ=; b=ixhYL+OTcFS+05OcjwyEM7PzxAHRwJxi97V/axJ/NTy1QOguZsHtYA0EW5pPoZoPji GhMmVch8t1d+8gMmf/qXFgOKTFc7D9R3Xlc1UHPmlSzRj1WJyqn1O49P1D6hGBFyrVjd nM2iCFrPJEsqopdWhgN37wH06poMsnhNw4y4G4xBLGpMNIHfJpYmsYpCxooPdse40yHP QRMv1uEF21SyOe7vB4PY3Ti+pgxoYhcmzvfX8/jE9QN3AldwvHtAxgHIp2r+zNNzb3sK tB+HSApbwiYZh4g2mSeOYkfIfy6uyIFKdEo0L9IZFd5oD7CnqE7Zr2ARYO6gkGzBQWyJ fYdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WLGovId1; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dm1si12515370edb.315.2020.08.17.05.48.51; Mon, 17 Aug 2020 05:49:15 -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; dkim=pass header.i=@kernel.org header.s=default header.b=WLGovId1; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728370AbgHQMri (ORCPT + 99 others); Mon, 17 Aug 2020 08:47:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:35594 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726265AbgHQMrh (ORCPT ); Mon, 17 Aug 2020 08:47:37 -0400 Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 09A2A2078D; Mon, 17 Aug 2020 12:47:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597668456; bh=F6AeSzf4yODe5VfS/mOvvXXrmYEDiPf8ncHRYGsJH9o=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=WLGovId1pF0RtoS/pxVhAbmTDQxL+wlb/YPyjGm4gwU7EG0HpRde71z58372pAGUI Mk7gmvMtdYHyCuhuPVYr4Pyx7oBmnbh5hBitrBnQEaY0aHR0Q7DRVQHu/ZXD3RYk4h ZjAMCDf1SsweOIV20FDlQU218t5SISXQewIF1Xjo= Received: by mail-lj1-f179.google.com with SMTP id h19so17298517ljg.13; Mon, 17 Aug 2020 05:47:35 -0700 (PDT) X-Gm-Message-State: AOAM532oqzzG5LP9YEUrK2IZP8tpsDMZcUPpohezb42zbSVCSt0TzE4J Yr6UXzWlaMlVjN6FRh5PIq4hUnJAjDtwgDZCwss= X-Received: by 2002:a2e:9bc1:: with SMTP id w1mr6581503ljj.79.1597668454259; Mon, 17 Aug 2020 05:47:34 -0700 (PDT) MIME-Version: 1.0 References: <1594683562-68149-4-git-send-email-guoren@kernel.org> In-Reply-To: From: Guo Ren Date: Mon, 17 Aug 2020 20:47:21 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 3/7] riscv: Fixup kprobes handler couldn't change pc To: Palmer Dabbelt Cc: Paul Walmsley , Masami Hiramatsu , Oleg Nesterov , linux-riscv , Linux Kernel Mailing List , Anup Patel , linux-csky@vger.kernel.org, Greentime Hu , Zong Li , =?UTF-8?Q?Patrick_St=C3=A4hlin?= , Bjorn Topel , Guo Ren Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Aug 15, 2020 at 6:36 AM Palmer Dabbelt wrote: > > On Mon, 13 Jul 2020 16:39:18 PDT (-0700), guoren@kernel.org wrote: > > From: Guo Ren > > > > The "Changing Execution Path" section in the Documentation/kprobes.txt > > said: > > > > Since kprobes can probe into a running kernel code, it can change the > > register set, including instruction pointer. > > > > Signed-off-by: Guo Ren > > Cc: Masami Hiramatsu > > Cc: Palmer Dabbelt > > --- > > arch/riscv/kernel/mcount-dyn.S | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > diff --git a/arch/riscv/kernel/mcount-dyn.S b/arch/riscv/kernel/mcount-dyn.S > > index 35a6ed7..4b58b54 100644 > > --- a/arch/riscv/kernel/mcount-dyn.S > > +++ b/arch/riscv/kernel/mcount-dyn.S > > @@ -123,6 +123,7 @@ ENDPROC(ftrace_caller) > > sd ra, (PT_SIZE_ON_STACK+8)(sp) > > addi s0, sp, (PT_SIZE_ON_STACK+16) > > > > + sd ra, PT_EPC(sp) > > sd x1, PT_RA(sp) > > sd x2, PT_SP(sp) > > sd x3, PT_GP(sp) > > So that's definately not going to be EPC any more. I'm not sure that field is > sanely named, though, as it's really just the PC when it comes to other ptrace > stuff. > > > @@ -157,6 +158,7 @@ ENDPROC(ftrace_caller) > > .endm > > > > .macro RESTORE_ALL > > + ld ra, PT_EPC(sp) > > ld x1, PT_RA(sp) > > x1 is ra, so loading it twice doesn't seem reasonable. > > > ld x2, PT_SP(sp) > > ld x3, PT_GP(sp) > > @@ -190,7 +192,6 @@ ENDPROC(ftrace_caller) > > ld x31, PT_T6(sp) > > > > ld s0, (PT_SIZE_ON_STACK)(sp) > > - ld ra, (PT_SIZE_ON_STACK+8)(sp) > > addi sp, sp, (PT_SIZE_ON_STACK+16) > > .endm > > If you're dropping the load you should drop the store above as well. In > general this seems kind of mixed up, both before and after this patch. This is a wrong patch, it should be: diff --git a/arch/riscv/kernel/mcount-dyn.S b/arch/riscv/kernel/mcount-dyn.S index 35a6ed7..d82b8f0 100644 --- a/arch/riscv/kernel/mcount-dyn.S +++ b/arch/riscv/kernel/mcount-dyn.S @@ -120,10 +120,10 @@ ENDPROC(ftrace_caller) .macro SAVE_ALL addi sp, sp, -(PT_SIZE_ON_STACK+16) sd s0, (PT_SIZE_ON_STACK)(sp) - sd ra, (PT_SIZE_ON_STACK+8)(sp) addi s0, sp, (PT_SIZE_ON_STACK+16) - sd x1, PT_RA(sp) + sd ra, PT_EPC(sp) + sd ra, PT_RA(sp) sd x2, PT_SP(sp) sd x3, PT_GP(sp) sd x4, PT_TP(sp) @@ -157,7 +157,7 @@ ENDPROC(ftrace_caller) .endm .macro RESTORE_ALL - ld x1, PT_RA(sp) + ld ra, PT_EPC(sp) ld x2, PT_SP(sp) ld x3, PT_GP(sp) ld x4, PT_TP(sp) @@ -190,7 +190,6 @@ ENDPROC(ftrace_caller) ld x31, PT_T6(sp) ld s0, (PT_SIZE_ON_STACK)(sp) - ld ra, (PT_SIZE_ON_STACK+8)(sp) addi sp, sp, (PT_SIZE_ON_STACK+16) .endm Now, I'm developing livepatch and they are so mixed features (kprobe, livepatch, ftrace, optprobes, STACK_WALK, -fpatchable-function-entry 'no -pg'). I'll test this patch in the next version of the patchset. Thx for the review. -- Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/