From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751499AbdHaScc (ORCPT ); Thu, 31 Aug 2017 14:32:32 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:54273 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750996AbdHaScb (ORCPT ); Thu, 31 Aug 2017 14:32:31 -0400 From: "Naveen N. Rao" To: Ingo Molnar Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Srikar Dronamraju , Oleg Nesterov , Anton Blanchard Subject: [PATCH] uprobe: Warn if unable to install breakpoint Date: Fri, 1 Sep 2017 00:02:15 +0530 X-Mailer: git-send-email 2.14.1 X-TM-AS-MML: disable x-cbid: 17083118-1617-0000-0000-000001FD4078 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17083118-1618-0000-0000-00004849B8F6 Message-Id: <20170831183215.4306-1-naveen.n.rao@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-08-31_07:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1708310274 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When we try to install a uprobe breakpoint in uprobe_mmap(), we ignore all errors encountered in the process per this comment at the top of the function: /* * Called from mmap_region/vma_adjust with mm->mmap_sem acquired. * * Currently we ignore all errors and always return 0, the callers * can't handle the failure anyway. */ However, this is very confusing for users since no probe hits are recorded nor is an error logged in dmesg. Fix this by logging an error in dmesg so that users can discover that there was an issue with the uprobe. To facilitate use of uprobe_warn(), we move that function to the top of the file. With this patch, we see a message similar to this in dmesg: [ 201.449213] uprobe: uprobe_t:9740 failed to setup probe at 0x95c (-524) Reported-by: Anton Blanchard Signed-off-by: Naveen N. Rao --- kernel/events/uprobes.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index 0e137f98a50c..587c591a535c 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -112,6 +112,12 @@ struct xol_area { unsigned long vaddr; /* Page(s) of instruction slots */ }; +static void uprobe_warn(struct task_struct *t, const char *msg) +{ + pr_warn("uprobe: %s:%d failed to %s\n", + current->comm, current->pid, msg); +} + /* * valid_vma: Verify if the specified vma is an executable vma * Relax restrictions while unregistering: vm_flags might have @@ -1087,7 +1093,14 @@ int uprobe_mmap(struct vm_area_struct *vma) if (!fatal_signal_pending(current) && filter_chain(uprobe, UPROBE_FILTER_MMAP, vma->vm_mm)) { unsigned long vaddr = offset_to_vaddr(vma, uprobe->offset); - install_breakpoint(uprobe, vma->vm_mm, vma, vaddr); + int ret = install_breakpoint(uprobe, vma->vm_mm, vma, vaddr); + if (ret) { + char msg[64]; + snprintf(msg, sizeof(msg), + "setup probe at 0x%llx (%d)", + uprobe->offset, ret); + uprobe_warn(current, (const char *)msg); + } } put_uprobe(uprobe); } @@ -1470,12 +1483,6 @@ static int dup_utask(struct task_struct *t, struct uprobe_task *o_utask) return 0; } -static void uprobe_warn(struct task_struct *t, const char *msg) -{ - pr_warn("uprobe: %s:%d failed to %s\n", - current->comm, current->pid, msg); -} - static void dup_xol_work(struct callback_head *work) { if (current->flags & PF_EXITING) -- 2.14.1