From patchwork Fri Aug 11 14:17:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 9896051 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D4DA160325 for ; Fri, 11 Aug 2017 14:19:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C63FA28C3C for ; Fri, 11 Aug 2017 14:19:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BAE4328C45; Fri, 11 Aug 2017 14:19:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 896D628C3C for ; Fri, 11 Aug 2017 14:19:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=KekBq1E8Nt0deWwa5VdkG3ErPrj06Ct2eIHd8mq69nY=; b=S4Jfb8xOm658ZaztsphK+sSEcN 349MM8jWyrRPzXuhaBn3U1w3DjS921+Q+jmvRgCdZRy7srY7iTaqqp1eLww9Z9DReyyOjPi4nZW7+ gZNPdCZ817Plht7+pG+FBUTZXCR+KSmPzgRU3fCeB643jFvJ3h/Bj7ac00rcOWlrxDFgSSzTEjzvc wbHZbjzG4S2nTDFkUREivLSCeS/3/5I6wkV+GqJ0iE2Np9KJzkxJPbO4v3z8/qmcod5rf0Uwbmtrb sc2PWfOogPPli95MQy1erqOhB7Y5nnw4llndDhhjlK72tT55PWOXecX/JncRcVmiOeBpiaJPacQ8U 5M0iketQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dgAmi-0005hp-Cv; Fri, 11 Aug 2017 14:19:32 +0000 Received: from mail-wr0-x22a.google.com ([2a00:1450:400c:c0c::22a]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dgAmI-0005M1-ET for linux-arm-kernel@lists.infradead.org; Fri, 11 Aug 2017 14:19:12 +0000 Received: by mail-wr0-x22a.google.com with SMTP id y43so13958630wrd.3 for ; Fri, 11 Aug 2017 07:18:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nDqlsJhUAk3IfHV4KCdccVXblqleBeW/0mVFD/7+on0=; b=VYD2oQdh9fa4LRzLJr1At+IQufQZVtUxvvauMcnFU6LWLQ5Skp8CqKYjUUdtoLPrAi E10b2AJcHepMEUMWtFGZHUUZWH45t9xE4QTwREikrC2iyqtNafwU4oRz2lCOZMbHju03 5YE/UoaasO9LbxrxLgySlLXVO7DXlryFr4N10= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nDqlsJhUAk3IfHV4KCdccVXblqleBeW/0mVFD/7+on0=; b=cpMfrve2TB61w1exbDdOE2QdKlBuNsgdU6SG5FYT81mE3C67w39hOKh3tW+7G22x2X TxkAx9GlCq4j2bhaiwE02roOtFC7X2NxbrBz5qnZI5/ZEz2Bfh+mj6ADXcobbSqjTuAZ o4njfLDTjyz9q296iOqdrMlnDWOxc0jnJRXGoUHmuN0IcHNix4gFcZAKxq9sXl+OReeq YnM4r39mLcBg1qti8TeKDTh4nRMiO0+krfxqF25tm5EUVURAxAxrgGtIjiVnVVthzOxV GaxDQQMCigMZgxETl/v2B9V7gsxAl1IGYF3knO1QLbgU1WjYXYWEgIRu5vYcBvRNlGe+ 0ytw== X-Gm-Message-State: AHYfb5hRMITpeTlJUDpHhUNBYVRIOrexpYYWHwhVfTAo5PITVqrpn3uq NSt7+i0Qz2v7q2ot X-Received: by 10.223.171.17 with SMTP id q17mr12110724wrc.12.1502461125940; Fri, 11 Aug 2017 07:18:45 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:e0e8:7a5e:bd6d:f842]) by smtp.gmail.com with ESMTPSA id v22sm868383wra.70.2017.08.11.07.18.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 11 Aug 2017 07:18:45 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de, mingo@kernel.org Subject: [PATCH 5/5] clocksource/drivers/arm_arch_timer: Avoid infinite recursion when ftrace is enabled Date: Fri, 11 Aug 2017 16:17:41 +0200 Message-Id: <1502461061-28065-5-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502461061-28065-1-git-send-email-daniel.lezcano@linaro.org> References: <20170811141520.GA795@mai> <1502461061-28065-1-git-send-email-daniel.lezcano@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170811_071906_896747_5AB8C93E X-CRM114-Status: GOOD ( 13.11 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Marc Zyngier , Catalin Marinas , Will Deacon , linux-kernel@vger.kernel.org, mka@chromium.org, garsilva@embeddedor.com, "moderated list:ARM ARCHITECTED TIMER DRIVER" , dingtianhong@huawei.com, matt.redfearn@imgtec.com, dan.carpenter@oracle.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ding Tianhong On platforms with an arch timer erratum workaround, it's possible for arch_timer_reg_read_stable() to recurse into itself when certain tracing options are enabled, leading to stack overflows and related problems. For example, when PREEMPT_TRACER and FUNCTION_GRAPH_TRACER are selected, it's possible to trigger this with: $ mount -t debugfs nodev /sys/kernel/debug/ $ echo function_graph > /sys/kernel/debug/tracing/current_tracer The problem is that in such cases, preempt_disable() instrumentation attempts to acquire a timestamp via trace_clock(), resulting in a call back to arch_timer_reg_read_stable(), and hence recursion. This patch changes arch_timer_reg_read_stable() to use preempt_{disable,enable}_notrace(), which avoids this. This problem is similar to the fixed by upstream commit 96b3d28bf4 ("sched/clock: Prevent tracing recursion in sched_clock_cpu()"). Fixes: 6acc71ccac71 ("arm64: arch_timer: Allows a CPU-specific erratum to only affect a subset of CPUs") Signed-off-by: Ding Tianhong Acked-by: Mark Rutland Acked-by: Marc Zyngier Signed-off-by: Daniel Lezcano --- arch/arm64/include/asm/arch_timer.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/arch_timer.h b/arch/arm64/include/asm/arch_timer.h index 74d08e4..a652ce0 100644 --- a/arch/arm64/include/asm/arch_timer.h +++ b/arch/arm64/include/asm/arch_timer.h @@ -65,13 +65,13 @@ DECLARE_PER_CPU(const struct arch_timer_erratum_workaround *, u64 _val; \ if (needs_unstable_timer_counter_workaround()) { \ const struct arch_timer_erratum_workaround *wa; \ - preempt_disable(); \ + preempt_disable_notrace(); \ wa = __this_cpu_read(timer_unstable_counter_workaround); \ if (wa && wa->read_##reg) \ _val = wa->read_##reg(); \ else \ _val = read_sysreg(reg); \ - preempt_enable(); \ + preempt_enable_notrace(); \ } else { \ _val = read_sysreg(reg); \ } \