From patchwork Mon Oct 5 21:32:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 54509 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by patches.linaro.org (Postfix) with ESMTPS id E431222B0F for ; Mon, 5 Oct 2015 21:49:59 +0000 (UTC) Received: by wicmn1 with SMTP id mn1sf34148270wic.1 for ; Mon, 05 Oct 2015 14:49:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=ndn6eLTiCLBEVrDZAI9cG7yVRjFRpiB/M4bM3KRIlSM=; b=GFPuZHwrJAiwvLb7XO9//z+4mUnHZ0+jpfQjeC/SIfC2yNeRPZlOWDMI/P29oxpwqV IU/mJb4cEFS6729iz6APkp+5rOkeoZaYtwGHfbJ7GF86edXP/4uxhzmFh4kZN9nSxH7T LdIPyLMGsY7Va/NqfoDA8r/KQxCYKGtTu0WFF0rjLW0wv6DF7MF/RAMxc7LjPppI+Vql DzDsBlFB97Xyh27lJq6vpkrTMks0J4aE0l+5l1IQHpQdkq14pbJA51214Uw1mVXRo62x 0U07UikQuHLQOUAgTHhkmljh53FPGOxxgTmPvnVHNjVT0Kze9O0gXn+9wxap3vpiJ/pr rN9w== X-Gm-Message-State: ALoCoQl+wK7JGCYhIFFSSuGH02ndL0iNhDS41gJyLjn7+lfgmoX8MZ9GHEGBsCAiMrDQI6zVQZQ/ X-Received: by 10.180.106.197 with SMTP id gw5mr2607761wib.7.1444081799240; Mon, 05 Oct 2015 14:49:59 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.166.82 with SMTP id p79ls530118lfe.99.gmail; Mon, 05 Oct 2015 14:49:59 -0700 (PDT) X-Received: by 10.25.81.3 with SMTP id f3mr8472831lfb.44.1444081799087; Mon, 05 Oct 2015 14:49:59 -0700 (PDT) Received: from mail-la0-f41.google.com (mail-la0-f41.google.com. [209.85.215.41]) by mx.google.com with ESMTPS id oj2si18394895lbb.154.2015.10.05.14.49.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Oct 2015 14:49:59 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.41 as permitted sender) client-ip=209.85.215.41; Received: by laddr2 with SMTP id dr2so16043432lad.3 for ; Mon, 05 Oct 2015 14:49:59 -0700 (PDT) X-Received: by 10.25.19.73 with SMTP id j70mr8339911lfi.29.1444081798901; Mon, 05 Oct 2015 14:49:58 -0700 (PDT) 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.59.35 with SMTP id w3csp1491397lbq; Mon, 5 Oct 2015 14:49:56 -0700 (PDT) X-Received: by 10.66.229.67 with SMTP id so3mr43476745pac.66.1444081796487; Mon, 05 Oct 2015 14:49:56 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id nn10si43276210pbc.131.2015.10.05.14.49.55; Mon, 05 Oct 2015 14:49:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-rt-users-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751238AbbJEVtz (ORCPT + 4 others); Mon, 5 Oct 2015 17:49:55 -0400 Received: from mail-pa0-f48.google.com ([209.85.220.48]:34471 "EHLO mail-pa0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750937AbbJEVty (ORCPT ); Mon, 5 Oct 2015 17:49:54 -0400 Received: by padhy16 with SMTP id hy16so47801802pad.1 for ; Mon, 05 Oct 2015 14:49:53 -0700 (PDT) X-Received: by 10.68.190.105 with SMTP id gp9mr42352877pbc.152.1444081793648; Mon, 05 Oct 2015 14:49:53 -0700 (PDT) Received: from yshi-Precision-T5600.corp.ad.wrs.com (unknown-216-82.windriver.com. [147.11.216.82]) by smtp.gmail.com with ESMTPSA id y5sm29385904pbt.77.2015.10.05.14.49.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Oct 2015 14:49:52 -0700 (PDT) From: Yang Shi To: rostedt@goodmis.org, catalin.marinas@arm.com, will.deacon@arm.com, paulmck@linux.vnet.ibm.com, dave.long@linaro.org, panand@redhat.com Cc: linux-kernel@vger.kernel.org, linux-rt-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linaro-kernel@lists.linaro.org, yang.shi@linaro.org Subject: [v3 PATCH] arm64: replace read_lock to rcu lock in call_break_hook Date: Mon, 5 Oct 2015 14:32:51 -0700 Message-Id: <1444080771-22468-1-git-send-email-yang.shi@linaro.org> X-Mailer: git-send-email 2.0.2 Sender: linux-rt-users-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-rt-users@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: yang.shi@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.215.41 as permitted sender) smtp.mailfrom=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: , BUG: sleeping function called from invalid context at kernel/locking/rtmutex.c:917 in_atomic(): 0, irqs_disabled(): 128, pid: 342, name: perf 1 lock held by perf/342: #0: (break_hook_lock){+.+...}, at: [] call_break_hook+0x34/0xd0 irq event stamp: 62224 hardirqs last enabled at (62223): [] __call_rcu.constprop.59+0x104/0x270 hardirqs last disabled at (62224): [] vprintk_emit+0x68/0x640 softirqs last enabled at (0): [] copy_process.part.8+0x428/0x17f8 softirqs last disabled at (0): [< (null)>] (null) CPU: 0 PID: 342 Comm: perf Not tainted 4.1.6-rt5 #4 Hardware name: linux,dummy-virt (DT) Call trace: [] dump_backtrace+0x0/0x128 [] show_stack+0x20/0x30 [] dump_stack+0x7c/0xa0 [] ___might_sleep+0x174/0x260 [] __rt_spin_lock+0x28/0x40 [] rt_read_lock+0x60/0x80 [] call_break_hook+0x30/0xd0 [] brk_handler+0x30/0x98 [] do_debug_exception+0x50/0xb8 Exception stack(0xffffffc00514fe30 to 0xffffffc00514ff50) fe20: 00000000 00000000 c1594680 0000007f fe40: ffffffff ffffffff 92063940 0000007f 0550dcd8 ffffffc0 00000000 00000000 fe60: 0514fe70 ffffffc0 000be1f8 ffffffc0 0514feb0 ffffffc0 0008948c ffffffc0 fe80: 00000004 00000000 0514fed0 ffffffc0 ffffffff ffffffff 9282a948 0000007f fea0: 00000000 00000000 9282b708 0000007f c1592820 0000007f 00083914 ffffffc0 fec0: 00000000 00000000 00000010 00000000 00000064 00000000 00000001 00000000 fee0: 005101e0 00000000 c1594680 0000007f c1594740 0000007f ffffffd8 ffffff80 ff00: 00000000 00000000 00000000 00000000 c1594770 0000007f c1594770 0000007f ff20: 00665e10 00000000 7f7f7f7f 7f7f7f7f 01010101 01010101 00000000 00000000 ff40: 928e4cc0 0000007f 91ff11e8 0000007f call_break_hook is called in atomic context (hard irq disabled), so replace the sleepable lock to rcu lock, replace relevant list operations to rcu version and call synchronize_rcu() in unregister_break_hook(). And, replace write lock to spinlock in {un}register_break_hook. Signed-off-by: Yang Shi --- v2 -> v3 Add synchronize_rcu() in ungister_break_hook() Replace write lock to spinlock v1 -> v2 Replace list operations to rcu version. arch/arm64/kernel/debug-monitors.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c index cebf786..13ca9cd 100644 --- a/arch/arm64/kernel/debug-monitors.c +++ b/arch/arm64/kernel/debug-monitors.c @@ -271,20 +271,21 @@ static int single_step_handler(unsigned long addr, unsigned int esr, * Use reader/writer locks instead of plain spinlock. */ static LIST_HEAD(break_hook); -static DEFINE_RWLOCK(break_hook_lock); +static DEFINE_SPINLOCK(break_hook_lock); void register_break_hook(struct break_hook *hook) { - write_lock(&break_hook_lock); - list_add(&hook->node, &break_hook); - write_unlock(&break_hook_lock); + spin_lock(&break_hook_lock); + list_add_rcu(&hook->node, &break_hook); + spin_unlock(&break_hook_lock); } void unregister_break_hook(struct break_hook *hook) { - write_lock(&break_hook_lock); - list_del(&hook->node); - write_unlock(&break_hook_lock); + spin_lock(&break_hook_lock); + list_del_rcu(&hook->node); + spin_unlock(&break_hook_lock); + synchronize_rcu(); } static int call_break_hook(struct pt_regs *regs, unsigned int esr) @@ -292,11 +293,11 @@ static int call_break_hook(struct pt_regs *regs, unsigned int esr) struct break_hook *hook; int (*fn)(struct pt_regs *regs, unsigned int esr) = NULL; - read_lock(&break_hook_lock); - list_for_each_entry(hook, &break_hook, node) + rcu_read_lock(); + list_for_each_entry_rcu(hook, &break_hook, node) if ((esr & hook->esr_mask) == hook->esr_val) fn = hook->fn; - read_unlock(&break_hook_lock); + rcu_read_unlock(); return fn ? fn(regs, esr) : DBG_HOOK_ERROR; }