From patchwork Sun Apr 16 20:27:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 9683227 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 E534C602CB for ; Sun, 16 Apr 2017 20:44:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D29B927CEA for ; Sun, 16 Apr 2017 20:44:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C6CC127D0C; Sun, 16 Apr 2017 20:44:55 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID 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 472AA27CEA for ; Sun, 16 Apr 2017 20:44:55 +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=TE/rD47nCt84isgH1wC6hoHXI6IMNxUS/ctBp5iqg00=; b=Vag5+Ih5mtEehs+HZG1a2W2gUP E5Bii0i73Yw5Nn/TP7nOBWL+zSc/40jIi7P9f/kIAUwHicR+wi771tL322SkPt+r1Wh9rXp1psPTF KGCmvhODuQBC+up+os6GvaeNh0tB/ZmrqAobNshn7kU571tXFs1GhCG6UFtqX3EDCUPcJEV4dQSZC lVVKy+RQBEYFugEXMUAp8B2F2q81QJqUXGooP7G5AOcbzDbTeccliZpb/ageegCHSAp2ciDt0jJ21 WPXFQU5w3y4KHOtFKUA1btrc+mWzCUn9Y67g5gUAoEEQ6OUuTO+4Ii8/6RFqSXqbYcXeLS6oEbC+H kLZO0RUQ==; 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 1czr2U-0001LY-HO; Sun, 16 Apr 2017 20:44:54 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1czr1r-0000Wf-Ta for linux-arm-kernel@bombadil.infradead.org; Sun, 16 Apr 2017 20:44:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=GBJQuIkVh/RijFUTAb0iMBCMBKFpqtNaPtm2Z/jcI7g=; b=V2KIeJHOjwaHwPBjVaIAZHry1 F+JNOO9OKfTJ/Sb8YKC3VbQIEElIrpI1YKa3aQdCVRNfwb4gjqotj/Wn1SiN6gkPh092CoTQBBL9I pT3wq+j1s2/62X2K/VdbQFOSuMsGYfTzjGGZWKnPm98q4N1/BnpPpfEbnS3n79nEPOaa+HGPxd1SQ g7bS2c2iwK5NXBeZY0CvSqDgs6NkpZjfwnWyHijj+L0W05j6X1vPGziDIophMC6FyVcSnlh0f16fd a7e1k2ggZmYyfVwqVfXakf5bDk+tZAkeUxJlUUzyMzr9UqTquchy8AuztGt6vizdYWzSYc6TZPaEt AeBL/x69A==; Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]) by merlin.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1czqmp-0007RA-6t for linux-arm-kernel@lists.infradead.org; Sun, 16 Apr 2017 20:28:44 +0000 Received: by mail-wm0-x22b.google.com with SMTP id u2so22406265wmu.0 for ; Sun, 16 Apr 2017 13:28:22 -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=GBJQuIkVh/RijFUTAb0iMBCMBKFpqtNaPtm2Z/jcI7g=; b=Fz5CKZrUW8yclfKLvLlbeZ0XIXg3z7/+oEKrjmF4uzxBHPunDnajdY+CNDCblqdRIr zRe9M3lFUKtolX1Mqm/oGM4ISs/BG3mxAAZy2X7959wYRPlwz8iGRu2SOQJhBu3sEav5 UB/Hb5dDQw8FuhciCEUCQpsDbFE/Xc8l689i4= 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=GBJQuIkVh/RijFUTAb0iMBCMBKFpqtNaPtm2Z/jcI7g=; b=PmjEj65NEY3JB01qzQ7yHhjZlGLny8iJD2qkorC3IUuVzZeBVXbrOXFQ/0DA/pV8UD t7glWmioLB6kGoJldYRZJT+NGivtvaGNi+NseHvKDEjiA+AqMyXAF7LK17KnqRkzkPvw ZTzqWV98Dh++zPP/xSY1Lun9l56cg/2u7NCnugORHh2dUOihpWRD7/NePkwNC1a10MZO kpn9V7swQAkanqzZ32T9YsbGNjLnQswwPnVQFjk9iajlYy8VkHq7XFU25Nne9vBGzpj7 mo1B1uXtoem5PVV8bDM1c7KzrMl19I63Vw0TUY7reibEHALRXgOf6tRUN9ERko+Rbrpv sN1w== X-Gm-Message-State: AN3rC/6xGoLIcv9OfgTQhUbomjl7GSTloTLxcKY4pR3rgAXmiVp5ZIo/ i7bfsKGhxmE1CwxR X-Received: by 10.28.207.136 with SMTP id f130mr6495417wmg.51.1492374500133; Sun, 16 Apr 2017 13:28:20 -0700 (PDT) Received: from mai.lan ([2001:41d0:fe90:b800:20c0:6248:a385:db35]) by smtp.gmail.com with ESMTPSA id 81sm7732196wmj.9.2017.04.16.13.28.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 16 Apr 2017 13:28:19 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de Subject: [PATCH 15/29] arm64: arch_timer: Enable CNTVCT_EL0 trap if workaround is enabled Date: Sun, 16 Apr 2017 22:27:05 +0200 Message-Id: <1492374441-23336-15-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1492374441-23336-1-git-send-email-daniel.lezcano@linaro.org> References: <20170416202542.GV2078@mai> <1492374441-23336-1-git-send-email-daniel.lezcano@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170416_162843_474781_8EBF553C X-CRM114-Status: GOOD ( 15.73 ) 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: Marc Zyngier , Mark Rutland , linux-kernel@vger.kernel.org, "moderated list:ARM ARCHITECTED TIMER DRIVER" 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: Marc Zyngier Userspace being allowed to use read CNTVCT_EL0 anytime (and not only in the VDSO), we need to enable trapping whenever a cntvct workaround is enabled on a given CPU. Acked-by: Thomas Gleixner Signed-off-by: Marc Zyngier --- drivers/clocksource/arm_arch_timer.c | 45 +++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c index 5c114da..f8adea2 100644 --- a/drivers/clocksource/arm_arch_timer.c +++ b/drivers/clocksource/arm_arch_timer.c @@ -83,6 +83,7 @@ static enum ppi_nr arch_timer_uses_ppi = VIRT_PPI; static bool arch_timer_c3stop; static bool arch_timer_mem_use_virtual; static bool arch_counter_suspend_stop; +static bool vdso_default = true; static bool evtstrm_enable = IS_ENABLED(CONFIG_ARM_ARCH_TIMER_EVTSTREAM); @@ -383,6 +384,17 @@ void arch_timer_enable_workaround(const struct arch_timer_erratum_workaround *wa } static_branch_enable(&arch_timer_read_ool_enabled); + + /* + * Don't use the vdso fastpath if errata require using the + * out-of-line counter accessor. We may change our mind pretty + * late in the game (with a per-CPU erratum, for example), so + * change both the default value and the vdso itself. + */ + if (wa->read_cntvct_el0) { + clocksource_counter.archdata.vdso_direct = false; + vdso_default = false; + } } static void arch_timer_check_ool_workaround(enum arch_timer_erratum_match_type type, @@ -443,11 +455,19 @@ static void arch_timer_check_ool_workaround(enum arch_timer_erratum_match_type t __val; \ }) +static bool arch_timer_this_cpu_has_cntvct_wa(void) +{ + const struct arch_timer_erratum_workaround *wa; + + wa = __this_cpu_read(timer_unstable_counter_workaround); + return wa && wa->read_cntvct_el0; +} #else #define arch_timer_check_ool_workaround(t,a) do { } while(0) #define erratum_set_next_event_tval_virt(...) ({BUG(); 0;}) #define erratum_set_next_event_tval_phys(...) ({BUG(); 0;}) #define erratum_handler(fn, r, ...) ({false;}) +#define arch_timer_this_cpu_has_cntvct_wa() ({false;}) #endif /* CONFIG_ARM_ARCH_TIMER_OOL_WORKAROUND */ static __always_inline irqreturn_t timer_handler(const int access, @@ -660,15 +680,23 @@ static void arch_counter_set_user_access(void) { u32 cntkctl = arch_timer_get_cntkctl(); - /* Disable user access to the timers and the physical counter */ + /* Disable user access to the timers and both counters */ /* Also disable virtual event stream */ cntkctl &= ~(ARCH_TIMER_USR_PT_ACCESS_EN | ARCH_TIMER_USR_VT_ACCESS_EN + | ARCH_TIMER_USR_VCT_ACCESS_EN | ARCH_TIMER_VIRT_EVT_EN | ARCH_TIMER_USR_PCT_ACCESS_EN); - /* Enable user access to the virtual counter */ - cntkctl |= ARCH_TIMER_USR_VCT_ACCESS_EN; + /* + * Enable user access to the virtual counter if it doesn't + * need to be workaround. The vdso may have been already + * disabled though. + */ + if (arch_timer_this_cpu_has_cntvct_wa()) + pr_info("CPU%d: Trapping CNTVCT access\n", smp_processor_id()); + else + cntkctl |= ARCH_TIMER_USR_VCT_ACCESS_EN; arch_timer_set_cntkctl(cntkctl); } @@ -791,16 +819,7 @@ static void __init arch_counter_register(unsigned type) else arch_timer_read_counter = arch_counter_get_cntpct; - clocksource_counter.archdata.vdso_direct = true; - -#ifdef CONFIG_ARM_ARCH_TIMER_OOL_WORKAROUND - /* - * Don't use the vdso fastpath if errata require using - * the out-of-line counter accessor. - */ - if (static_branch_unlikely(&arch_timer_read_ool_enabled)) - clocksource_counter.archdata.vdso_direct = false; -#endif + clocksource_counter.archdata.vdso_direct = vdso_default; } else { arch_timer_read_counter = arch_counter_get_cntvct_mem; }