Received: by 10.223.185.116 with SMTP id b49csp4962690wrg; Wed, 7 Mar 2018 04:12:08 -0800 (PST) X-Google-Smtp-Source: AG47ELsneBZTYgJ5LQDYqK/SbjXW+eTR7gmT9zcH97I3Rt0NELGfSK0wtu4sSSYQVgTSa7uz8RdQ X-Received: by 2002:a17:902:5a5:: with SMTP id f34-v6mr20491516plf.134.1520424728335; Wed, 07 Mar 2018 04:12:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520424728; cv=none; d=google.com; s=arc-20160816; b=al2xkk4BlsDM51q/tQpKuotehr9DyVsw0CddnpOKlZ5xWeaXxFGrEdjTlr5c0a9bkI XBE4VEfhPljQaNgwhI5Svyh67aIzfaxyIxq+h/v2UI8ONJCv5YMJVgmGOypHUjcTo9+E T/R+910bS38oPjcqgR1Js7jgYfC65t3d244ZANCa36JOMSHQoeCeHmbKiSuS8/x4HT0l A9tlk3vtVtTFC2SGwhdlFPBsOubfrgGJp+Q5TYd92zpL/sscfSVdvTrKfQMdaDotjABv 7r10u+nYmIKC5fDB3UdAwDF7B1gU+WRDyoVqLNZwRanPtEByXqFOZDnle0N0DMBwAITd 3mxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject :arc-authentication-results; bh=4XgWkAoGWbHYXbvcdFug/MHILfxmSq4eVxKS3v46gfw=; b=dSLBqqgqQOGmpbWfKupkQ1jvBN6YE1gGNkxAUgE2HZ5dtVlRgJpfRUK6XScdym/G43 qQCZvOFn4CmjkGRPmrf9IL6fqyQxHyX5J2b/o/uFqKpF1FvbZ17LobuxpC4LWvwtGYQl p4hHTR2350X3tDq6uB9IBj4ltO0yF6ODfhpyC8oLjZPdxiov8x7KyTGgZ9dERg/jn3Wg P1qojNiFBzIcVTfvCuXaQRFy9iIaveggXFHiHEss6chDVCRoKYx4qstid43OITRp/IpM PlhTF5TqhY2HpHItSiIf6JyaFSqjc34yXWkxaCoh1jyKr+Lg/+2do+mOkvEN8bOKkSPa +XrQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n3si13651519pfi.302.2018.03.07.04.11.53; Wed, 07 Mar 2018 04:12:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754279AbeCGMJf (ORCPT + 99 others); Wed, 7 Mar 2018 07:09:35 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:49438 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751142AbeCGMJb (ORCPT ); Wed, 7 Mar 2018 07:09:31 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6EB3314; Wed, 7 Mar 2018 04:09:31 -0800 (PST) Received: from [10.1.207.62] (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7732F3F487; Wed, 7 Mar 2018 04:09:29 -0800 (PST) Subject: Re: [PATCH v4 10/10] ARM: sunxi: smp: Add initialization of CNTVOFF To: Chen-Yu Tsai , =?UTF-8?Q?Myl=c3=a8ne_Josserand?= Cc: Mark Rutland , devicetree , quentin.schulz@bootlin.com, Maxime Ripard , Russell King , linux-kernel , Rob Herring , LABBE Corentin , Thomas Petazzoni , linux-arm-kernel References: <20180223133742.26044-1-mylene.josserand@bootlin.com> <20180223133742.26044-11-mylene.josserand@bootlin.com> From: Marc Zyngier Organization: ARM Ltd Message-ID: Date: Wed, 7 Mar 2018 12:09:27 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23/02/18 16:17, Chen-Yu Tsai wrote: > On Fri, Feb 23, 2018 at 9:37 PM, Mylène Josserand > wrote: >> On Cortex-A7, the CNTVOFF register from arch timer is uninitialized. >> It should be done by the bootloader but it is currently not the case, >> even for boot CPU because this SoC is booting in secure mode. >> It leads to an random offset value meaning that each CPU will have a >> different time, which isn't working very well. >> >> Add assembly code used for boot CPU and secondary CPU cores to make >> sure that the CNTVOFF register is initialized. >> >> Signed-off-by: Mylène Josserand >> --- >> arch/arm/mach-sunxi/headsmp.S | 21 +++++++++++++++++++++ >> arch/arm/mach-sunxi/sunxi.c | 4 ++++ >> 2 files changed, 25 insertions(+) >> >> diff --git a/arch/arm/mach-sunxi/headsmp.S b/arch/arm/mach-sunxi/headsmp.S >> index d5c97e945e69..605896251927 100644 >> --- a/arch/arm/mach-sunxi/headsmp.S >> +++ b/arch/arm/mach-sunxi/headsmp.S >> @@ -65,9 +65,30 @@ ENTRY(sunxi_mc_smp_cluster_cache_enable) >> first: .word sunxi_mc_smp_first_comer - . >> ENDPROC(sunxi_mc_smp_cluster_cache_enable) >> >> +ENTRY(sunxi_init_cntvoff) >> + /* >> + * CNTVOFF has to be initialized either from non-secure Hypervisor >> + * mode or secure Monitor mode with SCR.NS==1. If TrustZone is enabled >> + * then it should be handled by the secure code >> + */ >> + cps #MON_MODE >> + mrc p15, 0, r1, c1, c1, 0 /* Get Secure Config */ >> + orr r0, r1, #1 >> + mcr p15, 0, r0, c1, c1, 0 /* Set Non Secure bit */ >> + instr_sync >> + mov r0, #0 >> + mcrr p15, 4, r0, r0, c14 /* CNTVOFF = 0 */ >> + instr_sync >> + mcr p15, 0, r1, c1, c1, 0 /* Set Secure bit */ >> + instr_sync >> + cps #SVC_MODE >> + ret lr >> +ENDPROC(sunxi_init_cntvoff) > > There is no need to move all the assembly into a separate file, just > to add this function. Everything can be inlined as a naked function. > The "instr_sync" macro can be replaced with "isb", which is what it > expands to anyway. > > I really want to keep everything self-contained without global symbols, > and in C files if possible. > >> + >> #ifdef CONFIG_SMP >> ENTRY(sunxi_boot) >> bl sunxi_mc_smp_cluster_cache_enable >> + bl sunxi_init_cntvoff >> b secondary_startup >> ENDPROC(sunxi_boot) >> >> diff --git a/arch/arm/mach-sunxi/sunxi.c b/arch/arm/mach-sunxi/sunxi.c >> index 5e9602ce1573..4bb041492b54 100644 >> --- a/arch/arm/mach-sunxi/sunxi.c >> +++ b/arch/arm/mach-sunxi/sunxi.c >> @@ -37,8 +37,12 @@ static const char * const sun6i_board_dt_compat[] = { >> }; >> >> extern void __init sun6i_reset_init(void); >> +extern void sunxi_init_cntvoff(void); >> + >> static void __init sun6i_timer_init(void) >> { >> + sunxi_init_cntvoff(); > > You should check the enable-method to see if PSCI is set or not, > as an indicator whether the kernel is booted secure or non-secure. > AFAIK trying to set CNTVOFF under non-secure would be very bad. Absolutely not. CNTVOFF *is* a non-secure register. The fact that it is not accessible from NS-PL1 is another problem. Please don't conflate the two things together. Thanks, M. -- Jazz is not dead. It just smells funny...