Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2330630pxk; Mon, 14 Sep 2020 10:23:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNPtNt3OKdSx/dnUgkbW0d8Cit65vE5OQUaW/3YV5gosjtk5kkZwZJHagu+6zi7AVmIE/C X-Received: by 2002:aa7:c648:: with SMTP id z8mr18507516edr.239.1600104181164; Mon, 14 Sep 2020 10:23:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600104181; cv=none; d=google.com; s=arc-20160816; b=N7v7uE4qbbvB46XClFxXU+1f5SKBomjMULhcTyhsazAggWuBNJIi0Lo/7Q7b28COgJ UFwC4TCqDZ8DstBve45BBeoarxQslTskVxYc2WC+iJy3DdIjqUSSNQjLohuQj3CJKMQt WCxh2jjNCG7aesj2ZHjUTnEKz2x1YSe9e9VQwNP3BUHKQbAo+jloXqKesrmoY4RLcoFB PbXQPKBl9vXcn9MXK35amtmHwQJ5ekM3TZloLaXiXcdyVwt0dfHswPsn8gjmW1VtQyvA E84zkP51DDNBw4hIVnBmrPe8iz2ZnxHktKJ9US+qY+pO35QlQ4FVi48jKGEWCWqPjCfu CQ1A== 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 :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:dkim-signature :dkim-signature:date; bh=mSE1RFWu5Z3osNzlxKs1p7faEX7TKfD5sRev9f5x2as=; b=HP0aLY1B4Us7LVZxnFKw7090JPb0fLZzMEzr6JOcTf7d7taf9uf6DHUFTBMhkUjtQ3 hbrpK1pjiDh2tdgsVFXgNddiduSLA+1AllEEiwivahzqyrSt1qf4ujAtF/wy8nS8MGyv 0+tNZs/i6yCsXB9iAiumIwUMpR8kDO2swMo9jeGpw2ZyDKL/Aqgwj0Ocy8PCC+e3ALYD hlqW54ILp3kQXL1tFzRo7RosD1V1leFXs0fwfnYu2VRw+vW0ANEn2sWJeOvRLkXhc3yb n8zg50lYtEFnMJy0ecJMAQ/8uvCLs3i7SBkyhGNjLCU6zoVtSDpcsfJDHUAVFdw0QV3K zpuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linutronix.de header.s=2020 header.b=MQqtjJrW; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=vQxCyhzQ; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d13si8511368edj.132.2020.09.14.10.22.38; Mon, 14 Sep 2020 10:23:01 -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=fail header.i=@linutronix.de header.s=2020 header.b=MQqtjJrW; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=vQxCyhzQ; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726372AbgINRUM (ORCPT + 99 others); Mon, 14 Sep 2020 13:20:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726306AbgINRQ0 (ORCPT ); Mon, 14 Sep 2020 13:16:26 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1759C061351; Mon, 14 Sep 2020 10:16:23 -0700 (PDT) Date: Mon, 14 Sep 2020 17:16:21 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1600103782; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mSE1RFWu5Z3osNzlxKs1p7faEX7TKfD5sRev9f5x2as=; b=MQqtjJrWnv2tOsOJv46ieGn3EweFdTfNkkxfYrbjsE/p/H5jLSl7jw/+DvE/DS4b6yO1WR oIbadshgXthyZ0RI5BbCXBD3zTZcFI6sY9BUJ8DsPqdyOIjNj74FVi2bkf+imBCYq5SR2q hJvuf5oUtbx1OXDmslyrSAndM74raMlKZE7MKtEmhVov4OKrhAloBYiL1Y0nma+2XiXI7h 1G2RlFwBGj7Nnkef6wWUYtBkz79ihYW+4kAcgzOqnVerKHv/+TdWO55AXdaPDg0+v6XCji 21P0adPyHOhMn1uR6eR+Mk6MVR66UtvRgGJ4D2pKcmE0VYce1NABkAgMWvi9Wg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1600103782; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mSE1RFWu5Z3osNzlxKs1p7faEX7TKfD5sRev9f5x2as=; b=vQxCyhzQxeji0yrxNtLRSkVTmgrnfBymvWCLz34XFlx9qzp/jp2cuutNS2y4A/D7LZ96DU M4xjI2nuj+GflsDw== From: "tip-bot2 for Masami Hiramatsu" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/kprobes] arm64: kprobes: Use generic kretprobe trampoline handler Cc: Masami Hiramatsu , Ingo Molnar , x86 , LKML In-Reply-To: <159870603544.1229682.10309733593594205725.stgit@devnote2> References: <159870603544.1229682.10309733593594205725.stgit@devnote2> MIME-Version: 1.0 Message-ID: <160010378174.15536.11352617130932309049.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the perf/kprobes branch of tip: Commit-ID: 95a4b7a24f55efd4fbc77c020fe0aab3e1f37f8a Gitweb: https://git.kernel.org/tip/95a4b7a24f55efd4fbc77c020fe0aab3e1f37f8a Author: Masami Hiramatsu AuthorDate: Sat, 29 Aug 2020 22:00:35 +09:00 Committer: Ingo Molnar CommitterDate: Tue, 08 Sep 2020 11:52:32 +02:00 arm64: kprobes: Use generic kretprobe trampoline handler Use the generic kretprobe trampoline handler, and use kernel_stack_pointer(regs) for framepointer verification. Signed-off-by: Masami Hiramatsu Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/159870603544.1229682.10309733593594205725.stgit@devnote2 --- arch/arm64/kernel/probes/kprobes.c | 78 +---------------------------- 1 file changed, 3 insertions(+), 75 deletions(-) diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c index 5290f17..deba738 100644 --- a/arch/arm64/kernel/probes/kprobes.c +++ b/arch/arm64/kernel/probes/kprobes.c @@ -464,87 +464,15 @@ int __init arch_populate_kprobe_blacklist(void) void __kprobes __used *trampoline_probe_handler(struct pt_regs *regs) { - struct kretprobe_instance *ri = NULL; - struct hlist_head *head, empty_rp; - struct hlist_node *tmp; - unsigned long flags, orig_ret_address = 0; - unsigned long trampoline_address = - (unsigned long)&kretprobe_trampoline; - kprobe_opcode_t *correct_ret_addr = NULL; - - INIT_HLIST_HEAD(&empty_rp); - kretprobe_hash_lock(current, &head, &flags); - - /* - * It is possible to have multiple instances associated with a given - * task either because multiple functions in the call path have - * return probes installed on them, and/or more than one - * return probe was registered for a target function. - * - * We can handle this because: - * - instances are always pushed into the head of the list - * - when multiple return probes are registered for the same - * function, the (chronologically) first instance's ret_addr - * will be the real return address, and all the rest will - * point to kretprobe_trampoline. - */ - hlist_for_each_entry_safe(ri, tmp, head, hlist) { - if (ri->task != current) - /* another task is sharing our hash bucket */ - continue; - - orig_ret_address = (unsigned long)ri->ret_addr; - - if (orig_ret_address != trampoline_address) - /* - * This is the real return address. Any other - * instances associated with this task are for - * other calls deeper on the call stack - */ - break; - } - - kretprobe_assert(ri, orig_ret_address, trampoline_address); - - correct_ret_addr = ri->ret_addr; - hlist_for_each_entry_safe(ri, tmp, head, hlist) { - if (ri->task != current) - /* another task is sharing our hash bucket */ - continue; - - orig_ret_address = (unsigned long)ri->ret_addr; - if (ri->rp && ri->rp->handler) { - __this_cpu_write(current_kprobe, &ri->rp->kp); - get_kprobe_ctlblk()->kprobe_status = KPROBE_HIT_ACTIVE; - ri->ret_addr = correct_ret_addr; - ri->rp->handler(ri, regs); - __this_cpu_write(current_kprobe, NULL); - } - - recycle_rp_inst(ri, &empty_rp); - - if (orig_ret_address != trampoline_address) - /* - * This is the real return address. Any other - * instances associated with this task are for - * other calls deeper on the call stack - */ - break; - } - - kretprobe_hash_unlock(current, &flags); - - hlist_for_each_entry_safe(ri, tmp, &empty_rp, hlist) { - hlist_del(&ri->hlist); - kfree(ri); - } - return (void *)orig_ret_address; + return (void *)kretprobe_trampoline_handler(regs, &kretprobe_trampoline, + (void *)kernel_stack_pointer(regs)); } void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri, struct pt_regs *regs) { ri->ret_addr = (kprobe_opcode_t *)regs->regs[30]; + ri->fp = (void *)kernel_stack_pointer(regs); /* replace return addr (x30) with trampoline */ regs->regs[30] = (long)&kretprobe_trampoline;