From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753462AbbGaOA0 (ORCPT ); Fri, 31 Jul 2015 10:00:26 -0400 Received: from terminus.zytor.com ([198.137.202.10]:57409 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751477AbbGaOAX (ORCPT ); Fri, 31 Jul 2015 10:00:23 -0400 Date: Fri, 31 Jul 2015 06:59:49 -0700 From: tip-bot for Oleg Nesterov Message-ID: Cc: oleg@redhat.com, panand@redhat.com, mingo@kernel.org, arapov@gmail.com, srikar@linux.vnet.ibm.com, hpa@zytor.com, peterz@infradead.org, tglx@linutronix.de, torvalds@linux-foundation.org, luto@amacapital.net, linux-kernel@vger.kernel.org Reply-To: hpa@zytor.com, peterz@infradead.org, luto@amacapital.net, linux-kernel@vger.kernel.org, tglx@linutronix.de, torvalds@linux-foundation.org, mingo@kernel.org, panand@redhat.com, arapov@gmail.com, oleg@redhat.com, srikar@linux.vnet.ibm.com In-Reply-To: <20150721134018.GA4766@redhat.com> References: <20150721134018.GA4766@redhat.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] uprobes/x86: Reimplement arch_uretprobe_is_alive( ) Git-Commit-ID: 7b868e4802a86d867aad1be0471b5767d9c20e10 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 7b868e4802a86d867aad1be0471b5767d9c20e10 Gitweb: http://git.kernel.org/tip/7b868e4802a86d867aad1be0471b5767d9c20e10 Author: Oleg Nesterov AuthorDate: Tue, 21 Jul 2015 15:40:18 +0200 Committer: Ingo Molnar CommitDate: Fri, 31 Jul 2015 10:38:05 +0200 uprobes/x86: Reimplement arch_uretprobe_is_alive() Add the x86 specific version of arch_uretprobe_is_alive() helper. It returns true if the stack frame mangled by prepare_uretprobe() is still on stack. So if it returns false, we know that the probed function has already returned. We add the new return_instance->stack member and change the generic code to initialize it in prepare_uretprobe, but it should be equally useful for other architectures. TODO: this assumes that the probed application can't use multiple stacks (say sigaltstack). We will try to improve this logic later. Tested-by: Pratyush Anand Signed-off-by: Oleg Nesterov Acked-by: Srikar Dronamraju Acked-by: Anton Arapov Cc: Andy Lutomirski Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/20150721134018.GA4766@redhat.com Signed-off-by: Ingo Molnar --- arch/x86/kernel/uprobes.c | 5 +++++ include/linux/uprobes.h | 1 + kernel/events/uprobes.c | 1 + 3 files changed, 7 insertions(+) diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c index 6647624..58e9b84 100644 --- a/arch/x86/kernel/uprobes.c +++ b/arch/x86/kernel/uprobes.c @@ -985,3 +985,8 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs return -1; } + +bool arch_uretprobe_is_alive(struct return_instance *ret, struct pt_regs *regs) +{ + return regs->sp <= ret->stack; +} diff --git a/include/linux/uprobes.h b/include/linux/uprobes.h index 50d2764..7ab6d2c 100644 --- a/include/linux/uprobes.h +++ b/include/linux/uprobes.h @@ -95,6 +95,7 @@ struct uprobe_task { struct return_instance { struct uprobe *uprobe; unsigned long func; + unsigned long stack; /* stack pointer */ unsigned long orig_ret_vaddr; /* original return address */ bool chained; /* true, if instance is nested */ diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index 1c71b62..c5f316e 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -1562,6 +1562,7 @@ static void prepare_uretprobe(struct uprobe *uprobe, struct pt_regs *regs) ri->uprobe = get_uprobe(uprobe); ri->func = instruction_pointer(regs); + ri->stack = user_stack_pointer(regs); ri->orig_ret_vaddr = orig_ret_vaddr; ri->chained = chained;