Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp985584ybt; Fri, 10 Jul 2020 18:35:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1GKkLbbyriK9vKuEiZV9e3BLEtn7sQbEGLWjmEnsf8QVVrHNDp60k0c1DayYdIRNI6yuU X-Received: by 2002:a17:906:35cd:: with SMTP id p13mr63050417ejb.172.1594431313842; Fri, 10 Jul 2020 18:35:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594431313; cv=none; d=google.com; s=arc-20160816; b=xZpOtICmUL2+Mi8ZHJKcDkfHXQP7yhsMXV9+SO+fFMyfftUvLKfIcjSlW7rNjeBkCX X/VFNskFkPo4D3RI0I0SgA6/XspSgVk+iLmHpr3GvcWhNEDke/cHe9H6zQ+9QYyLglPT iKYiGMrCwXrCeKlPTvLn5KqYFpD6df6FgDAlgkUgs62prtMAcQ4Geyx0zLoch1YOtrst uysnqTPFe5XVlrhtHkWCS75bOh/LgzXveC2SUVFH5xHdRdSl73SMGf/lQenH1FCpq+v6 2EgqipXrYf5+P8ppl9YiaggBmahewjyr5xkCn30ZX4j/OlZEdMbRik1Vr4xVXvPdGxm7 RtVw== 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=E4VtfbiS82NckWlN8SVkogNZaZyAXPAmZmnMlXg6T/E=; b=Ka+FWFP3LrKpQ/XObUHfl5Bx8hr1Q8KFinKKq2v5hhnQAT/NfRcaIaEilDK+AT5BBR Cy5mbhpPI3lbWNlf70k/7x0/Ve5iZdYtdQplpUsr9rHo+cD7MMJv4ygZKXG2Zt/gII9M 1UqflmwtIJSGwwDZIleorMKPLd/EDAArLESgwUq4GNSWiZye7qzal2/7jTDgQn8nZjwM Uwmgt4SfncToMcUIul4Wm7TQhYeAAL+Cs03egU2imntmfpEyHlmj2PET+tuV3JXYQUv4 Qq9AaYmZQiqaWzLzZ+SckzATzADdDKVuHb91Gtnp9YxeDSl1jNdAFAghAj9rD+/htqUH Y4lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bMfSdxB7; 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 i22si4697738edy.547.2020.07.10.18.34.49; Fri, 10 Jul 2020 18:35:13 -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=bMfSdxB7; 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 S1726693AbgGKBcQ (ORCPT + 99 others); Fri, 10 Jul 2020 21:32:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:42708 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726605AbgGKBcQ (ORCPT ); Fri, 10 Jul 2020 21:32:16 -0400 Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (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 E30AC2077D; Sat, 11 Jul 2020 01:32:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594431135; bh=JHAq849TrDR2TO0YVgHnBwsgpBJXggDvOdSCDOO9Mhg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=bMfSdxB7MrcYqYQa7ldPOwQ86Zvf7PpQlWpXfKwWn1cLEuXE64jZUFUYBu6rYOzyI iW9WNDqwkrk0sgSJttDTT1OJ/ku53mvBNojP8dEQQR8KaZXPa7y6EUoPqUh/FVz9eG YFLH08D+jTSwcQCN2Sb1ues3kIAJ8EMD9qUmzR5A= Received: by mail-lj1-f182.google.com with SMTP id q4so8455722lji.2; Fri, 10 Jul 2020 18:32:14 -0700 (PDT) X-Gm-Message-State: AOAM533i9RSOURlAFGvve92goWza/FThJwSuHSocrh6mjc95rlGTOZ+4 3TqNKT67wiC+0SZv7TtaKeQ1BnH3eYxsadrDbL4= X-Received: by 2002:a2e:b0ed:: with SMTP id h13mr31505047ljl.250.1594431133218; Fri, 10 Jul 2020 18:32:13 -0700 (PDT) MIME-Version: 1.0 References: <1594261154-69745-1-git-send-email-guoren@kernel.org> <1594261154-69745-7-git-send-email-guoren@kernel.org> <20200710225017.5ce329485e911f99e17cd483@kernel.org> In-Reply-To: <20200710225017.5ce329485e911f99e17cd483@kernel.org> From: Guo Ren Date: Sat, 11 Jul 2020 09:32:01 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 6/6] riscv: Add KPROBES_ON_FTRACE supported To: Masami Hiramatsu Cc: Palmer Dabbelt , Paul Walmsley , Anup Patel , Greentime Hu , Zong Li , =?UTF-8?Q?Patrick_St=C3=A4hlin?= , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Atish Patra , penberg@kernel.org, linux-riscv , Linux Kernel Mailing List , linux-csky@vger.kernel.org, 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 Thx Masami, On Fri, Jul 10, 2020 at 9:50 PM Masami Hiramatsu wrote: > > Hi Guo, > > On Thu, 9 Jul 2020 02:19:14 +0000 > guoren@kernel.org wrote: > > > +/* Ftrace callback handler for kprobes -- called under preepmt disabed */ > > +void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip, > > + struct ftrace_ops *ops, struct pt_regs *regs) > > +{ > > + struct kprobe *p; > > + struct kprobe_ctlblk *kcb; > > + > > + p = get_kprobe((kprobe_opcode_t *)ip); > > + if (unlikely(!p) || kprobe_disabled(p)) > > + return; > > + > > + kcb = get_kprobe_ctlblk(); > > + if (kprobe_running()) { > > + kprobes_inc_nmissed_count(p); > > + } else { > > + /* > > + * The regs->epc hasn't been saved by SAVE_ALL in mcount-dyn.S > > + * So no need to resume it, just for kprobe handler. > > + */ > > + instruction_pointer_set(regs, ip); > > + __this_cpu_write(current_kprobe, p); > > + kcb->kprobe_status = KPROBE_HIT_ACTIVE; > > + if (!p->pre_handler || !p->pre_handler(p, regs)) { > > + /* > > + * Emulate singlestep (and also recover regs->pc) > > + * as if there is a nop > > + */ > > + instruction_pointer_set(regs, > > + (unsigned long)p->addr + MCOUNT_INSN_SIZE); > > + if (unlikely(p->post_handler)) { > > + kcb->kprobe_status = KPROBE_HIT_SSDONE; > > + p->post_handler(p, regs, 0); > > + } > > Hmm, don't you need restoring the previous instruction pointer here? look at riscv mcount-dyn.S SAVE_ALL function, sp frame lay out like this: ----------------------- | return address | ----------------------- | frame pointer | ----------------------- | pt_regs x1-x31| ----------------------- It's not a complete pt_regs for the handler, so modifing regs->ip is no use. > If you don't support modifying the instruction pointer in the handler, We can modify ip like this if necessary: *(unsigned long *)((unsigned long)regs + sizeof(struct pt_regs) + 8) = xxx; > it must not be compatible with kprobes. Why, can you show related codes? thank you very much. > > Now BPF function override and function error injection depends on > this behevior, so could you consider to support it in the "ftrace" > implementation at first? (And if it is enabled, you can enable the > livepatch on RISCV too) Great message! But can you show me codes that bpf and err-jnject using the behavior? Thx I'll try to fix up it :) -- Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/