From patchwork Wed Dec 10 16:38:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Capper X-Patchwork-Id: 42091 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7196926C75 for ; Wed, 10 Dec 2014 16:38:44 +0000 (UTC) Received: by mail-wi0-f199.google.com with SMTP id bs8sf2515355wib.10 for ; Wed, 10 Dec 2014 08:38:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:date:from:to:cc:subject:message-id :references:mime-version:content-type:content-disposition :in-reply-to:user-agent:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=D5XODbvRz0Aclkvedcfs+G8lbIgT9cmw2U8J4FKenV8=; b=X5W2MoVs4Iicdd+UvM19thhbiq/qXP5nC7BCAgq8shnlHf6ZoHwooaJ7nfJeZ74mcE 5FAhTeop/c1IMdOzr0FkFZsOqYklNH7I0zag2n1KQYUaCioAd8dpP2ZDI3rtqAmuOyXE vR/w4h62HIFIsKO6dYlGNzlUQicUGb6WJJJhNFga76Ys0sdXtj8pk0wP4Z12N0z1fJIg KdW55wMx3XMVrlTECuXMObfz6Tz9NxRSihexY80DeCoBuprLc51r04zKTiof7xXClmvj moZyIkKe//Nft1qUwigAfxjmh60dfgAbww4fbEF9ke1XuwRCnC0Wtj2lsjHCMRg8j+pK 4yOA== X-Gm-Message-State: ALoCoQkScIC0Wx7zHvkpb8NrSwU9tlpiXsnLMDkq2C81rGzwgecSJ0Yhci6fNOdpL5VaLkQY8x4q X-Received: by 10.112.159.199 with SMTP id xe7mr5228lbb.21.1418229523722; Wed, 10 Dec 2014 08:38:43 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.203.162 with SMTP id kr2ls179023lac.36.gmail; Wed, 10 Dec 2014 08:38:43 -0800 (PST) X-Received: by 10.152.1.193 with SMTP id 1mr4988329lao.45.1418229523418; Wed, 10 Dec 2014 08:38:43 -0800 (PST) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id f4si3058307lam.117.2014.12.10.08.38.43 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 10 Dec 2014 08:38:43 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by mail-lb0-f170.google.com with SMTP id 10so2653967lbg.29 for ; Wed, 10 Dec 2014 08:38:43 -0800 (PST) X-Received: by 10.152.43.103 with SMTP id v7mr5004003lal.29.1418229523265; Wed, 10 Dec 2014 08:38:43 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.142.69 with SMTP id ru5csp258076lbb; Wed, 10 Dec 2014 08:38:42 -0800 (PST) X-Received: by 10.68.246.229 with SMTP id xz5mr8457401pbc.131.1418229521075; Wed, 10 Dec 2014 08:38:41 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ps9si7417524pdb.180.2014.12.10.08.38.36 for ; Wed, 10 Dec 2014 08:38:41 -0800 (PST) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757950AbaLJQif (ORCPT + 27 others); Wed, 10 Dec 2014 11:38:35 -0500 Received: from mail-wg0-f51.google.com ([74.125.82.51]:64336 "EHLO mail-wg0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756142AbaLJQid (ORCPT ); Wed, 10 Dec 2014 11:38:33 -0500 Received: by mail-wg0-f51.google.com with SMTP id x12so4061968wgg.24 for ; Wed, 10 Dec 2014 08:38:32 -0800 (PST) X-Received: by 10.194.87.100 with SMTP id w4mr8296624wjz.65.1418229512447; Wed, 10 Dec 2014 08:38:32 -0800 (PST) Received: from linaro.org (marmot.wormnet.eu. [2a03:9800:10:2d:3203:b3a5:8bdc:5b68]) by mx.google.com with ESMTPSA id ck7sm6516598wjb.13.2014.12.10.08.38.30 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 10 Dec 2014 08:38:31 -0800 (PST) Date: Wed, 10 Dec 2014 16:38:18 +0000 From: Steve Capper To: David Long Cc: Masami Hiramatsu , "Jon Medhurst (Tixy)" , Russell King , Ananth N Mavinakayanahalli , Sandeepa Prabhu , Catalin Marinas , Will Deacon , "linux-kernel@vger.kernel.org" , Anil S Keshavamurthy , William Cohen , David Miller , "linux-arm-kernel@lists.infradead.org" Subject: Re: [PATCH v3 0/5] ARM64: Add kernel probes(Kprobes) support Message-ID: <20141210163817.GA27500@linaro.org> References: <547F242D.1060705@redhat.com> <547F94B0.1000902@linaro.org> <547FB5DD.901@redhat.com> <547FCB73.1010707@linaro.org> <54803ADD.2090201@hitachi.com> <54804B1F.3020703@hitachi.com> <20141209133340.GA20265@linaro.org> <548706C6.2050105@linaro.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <548706C6.2050105@linaro.org> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: steve.capper@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , On Tue, Dec 09, 2014 at 09:27:18AM -0500, David Long wrote: > On 12/09/14 08:33, Steve Capper wrote: > >On Thu, Dec 04, 2014 at 08:53:03PM +0900, Masami Hiramatsu wrote: [...] > > > >Not sure if this is helpful, but the following also caused a crash for > >me: > > > >echo "p:trace_event_buffer_lock_reserve trace_event_buffer_lock_reserve" > /sys/kernel/debug/tracing/kprobe_events > >echo "p:memcpy memcpy" >> /sys/kernel/debug/tracing/kprobe_events > >echo 1 > /sys/kernel/debug/tracing/events/kprobes/enable > > > >[immediate crash] > > > >The crash point for me is in the arm64 ASID allocator, it again looks > >like the interrupts are in an unexpected state. > >(check_and_switch_context goes down the irqs disabled code path, I > >think incorrectly). > > > >This occurred for me both with and without the proposed irq saving fix. > > > >I will do some more digging. > > > > Thanks, more information is good. > Hi, Some good news, I think I've fixed the problem I've been experiencing. Basically, I've torn out all the interrupt save/restore and have narrowed the scope to just sandwich the instruction single-step. This simplifies a lot of logic, and I've now been able to perf record a kprobe on memcpy (and the trace_event_buffer_lock_reserve + memcpy test) without any issues on a Juno platform. I may have been somewhat over-zealous with the chainsaw, so please do put this fix through its paces. Cheers, --- Steve >From d3f4d80ce19bec71bd03209beb2fbfd8084d6543 Mon Sep 17 00:00:00 2001 From: Steve Capper Date: Mon, 1 Dec 2014 11:30:10 +0000 Subject: [PATCH] Fix the interrupt handling for kprobes --- arch/arm64/kernel/kprobes.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/arch/arm64/kernel/kprobes.c b/arch/arm64/kernel/kprobes.c index be7c330..d39d826 100644 --- a/arch/arm64/kernel/kprobes.c +++ b/arch/arm64/kernel/kprobes.c @@ -229,10 +229,6 @@ skip_singlestep_missed(struct kprobe_ctlblk *kcb, struct pt_regs *regs) { /* set return addr to next pc to continue */ instruction_pointer(regs) += sizeof(kprobe_opcode_t); - - if (kcb->kprobe_status != KPROBE_REENTER) - kprobes_restore_local_irqflag(regs); - } static void __kprobes setup_singlestep(struct kprobe *p, @@ -259,7 +255,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, spsr_set_debug_flag(regs, 0); /* IRQs and single stepping do not mix well. */ - local_irq_disable(); + kprobes_save_local_irqflag(regs); kernel_enable_single_step(regs); instruction_pointer(regs) = slot; } else { @@ -326,7 +322,6 @@ post_kprobe_handler(struct kprobe_ctlblk *kcb, struct pt_regs *regs) } reset_current_kprobe(); - kprobes_restore_local_irqflag(regs); } int __kprobes kprobe_fault_handler(struct pt_regs *regs, unsigned int fsr) @@ -380,8 +375,6 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, unsigned int fsr) return 1; break; - default: - break; } return 0; } @@ -446,7 +439,6 @@ void __kprobes kprobe_handler(struct pt_regs *regs) * handling of this interrupt is appropriate. * Return back to original instruction, and continue. */ - kprobes_restore_local_irqflag(regs); return; } else if (cur) { /* We probably hit a jprobe. Call its break handler. */ @@ -459,7 +451,6 @@ void __kprobes kprobe_handler(struct pt_regs *regs) /* breakpoint is removed, now in a race * Return back to original instruction & continue. */ - kprobes_restore_local_irqflag(regs); } } @@ -485,6 +476,7 @@ kprobe_single_step_handler(struct pt_regs *regs, unsigned int esr) retval = kprobe_ss_hit(kcb, instruction_pointer(regs)); if (retval == DBG_HOOK_HANDLED) { + kprobes_restore_local_irqflag(regs); kernel_disable_single_step(); if (kcb->kprobe_status == KPROBE_REENTER) @@ -499,7 +491,6 @@ kprobe_single_step_handler(struct pt_regs *regs, unsigned int esr) static int __kprobes kprobe_breakpoint_handler(struct pt_regs *regs, unsigned int esr) { - kprobes_save_local_irqflag(regs); kprobe_handler(regs); return DBG_HOOK_HANDLED; } @@ -563,7 +554,6 @@ int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs) memcpy((void *)stack_addr, kcb->jprobes_stack, MIN_STACK_SIZE(stack_addr)); preempt_enable_no_resched(); - kprobes_restore_local_irqflag(regs); return 1; } return 0; @@ -655,8 +645,6 @@ trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs) kfree(ri); } - kprobes_restore_local_irqflag(regs); - /* return 1 so that post handlers not called */ return 1; }