Received: by 10.223.185.116 with SMTP id b49csp3570563wrg; Mon, 26 Feb 2018 02:14:27 -0800 (PST) X-Google-Smtp-Source: AH8x226LnPosXptfHZ0NKTJ0oYgZ1/EZa5z9KUXjJboD0X9Kv+Kayf1yG4dYNetxFaGXmo5PgIs9 X-Received: by 10.98.211.198 with SMTP id z67mr10282951pfk.0.1519640067366; Mon, 26 Feb 2018 02:14:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519640067; cv=none; d=google.com; s=arc-20160816; b=XMvCZm/GEn24IS/kpYtYlyjVt7b9upL6Zjbf4u4mo2xe/QXckhxBgCbcgfkWjvjhTl /lA+PNairq5SnDuF73i74gYwgifFAhekv5wCFVOSAKkE+Khycz5Y833ZG0RUvDnaKldx 1/6K8fILecAo3qxydwx2mB9kk9JF/mtQx0eExlmFCifLgGrm1ALtfL5EuKFmn0sLkvNH Ix5PaSfM42QrNAebpTU5cmImcG6HjCanBVC8oF1mQudzoksZb7hfibwK1Zjr+Z5/M94S wD9e6AlVVDriMFLnJCa1R4HTgiydhl5N1Xeruvm/UEmOpc75dqtic6s+BbK7Hi5oNln9 qA4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=njZMAK/58hSUoZSGlRRVR32tcgmlGtzBdRLbaiKJzf4=; b=evrN7DKm911dyx+TjquMK7FnQQmNN1ou1kylCpZWgLlhY9Gs3EWBKfqyn+F/B4d/0K yIsfnVmjKi6HjAw+sTHkPTgzo+CCxKhgbLUoiydEvGR6OH6kR9q6xBKBLghC/TfDenfB vAwI0bsjyFAs0QQow0VAeGZlfDxCWAQt9O1h7ZMJLZszP2cHytIoUosVhmaDmh9Tw7hq f5TkmljPiWNPXFBp78xmvcuEEMoGhP8QWV6gwsvuoZ/URE/tavqRC3HWGO5M+zqV6VQU eqP5p7+dkBNY444csvLX6T9l86tEcuclhiVZAfk2xnK6yJSgy/IXyQ5qj4QYdYdxMK3Z Ru/A== 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 i11-v6si6542282plt.688.2018.02.26.02.14.13; Mon, 26 Feb 2018 02:14:27 -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 S1752389AbeBZKM4 (ORCPT + 99 others); Mon, 26 Feb 2018 05:12:56 -0500 Received: from mail.bootlin.com ([62.4.15.54]:44278 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752336AbeBZKMy (ORCPT ); Mon, 26 Feb 2018 05:12:54 -0500 Received: by mail.bootlin.com (Postfix, from userid 110) id BD00D2071F; Mon, 26 Feb 2018 11:12:51 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.bootlin.com (Postfix) with ESMTPSA id 6149E200FB; Mon, 26 Feb 2018 11:12:51 +0100 (CET) Date: Mon, 26 Feb 2018 11:12:52 +0100 From: Maxime Ripard To: Chen-Yu Tsai Cc: =?utf-8?Q?Myl=C3=A8ne?= Josserand , Russell King , Rob Herring , Mark Rutland , devicetree , linux-arm-kernel , linux-kernel , LABBE Corentin , Thomas Petazzoni , quentin.schulz@bootlin.com Subject: Re: [PATCH v4 10/10] ARM: sunxi: smp: Add initialization of CNTVOFF Message-ID: <20180226101252.ozdsxjvawgkemz2c@flea.lan> References: <20180223133742.26044-1-mylene.josserand@bootlin.com> <20180223133742.26044-11-mylene.josserand@bootlin.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="mbneedr2uplq73p2" Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180223 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --mbneedr2uplq73p2 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Feb 24, 2018 at 12:17:13AM +0800, Chen-Yu Tsai wrote: > On Fri, Feb 23, 2018 at 9:37 PM, Myl=E8ne 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=E8ne 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/headsm= p.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 Hypervi= sor > > + * mode or secure Monitor mode with SCR.NS=3D=3D1. 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 =3D 0 */ > > + instr_sync > > + mcr p15, 0, r1, c1, c1, 0 /* Set Secure bit */ > > + instr_sync > > + cps #SVC_MODE > > + ret lr > > +ENDPROC(sunxi_init_cntvoff) >=20 > 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. >=20 > I really want to keep everything self-contained without global symbols, > and in C files if possible. What is the rationale for keeping it in C files (beside the global symbols)? Because the syntax is quite ugly, and it's much easier to read, review and amend using a separate file. > > #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[] = =3D { > > }; > > > > extern void __init sun6i_reset_init(void); > > +extern void sunxi_init_cntvoff(void); > > + > > static void __init sun6i_timer_init(void) > > { > > + sunxi_init_cntvoff(); >=20 > 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. It's an indicator, but it's not really a perfect one. You could very well have your kernel booted in non-secure, without PSCI. Or even with PSCI, but without the SMP ops. We have a quite big number of these cases already, where, depending on the configuration, we might not have access to the device we write to, the number of hacks to just enable that device for non-secure is a good example of that. > AFAIK trying to set CNTVOFF under non-secure would be very bad. Just like any other access we do :/ Maxime --=20 Maxime Ripard, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com --mbneedr2uplq73p2 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEE0VqZU19dR2zEVaqr0rTAlCFNr3QFAlqT3aMACgkQ0rTAlCFN r3Qmqw//WGnAKBTv6UvydDeyCIB9E8IQO19puDonvS5tDNbJCXX2sPNqlvZi5eYH gudBP8QUQsSpCdRR8YHOKrh2XLyTdjkRFuMa1bochbSAIk+jsA1IA3hW+V8i9N6B STw8FG/0araXLAMapBOc5/0JSzSEdc7o+X4XEUMG6WGlmlHxk2i0zxfSe3EhhF/Q hSHUUbkcwAlJhE4xW98ZmsgqgSH5zt3z03/MiQhNpo+DLZpR25xkRytz72Z1dhyZ VcRPtunBLlmXM0h/Q98G8LPVXsKmgdJITTYyt5SNfbuFRHOlkfkRD/D8u5GX2nGp xiefs8IqW9PywLjrsVd0tSX6V+zcEvbM02LN/8KSVKY6StkRaEH1ZthOR1QJmRty mHBRZhMgQWcpkjGzeIKp3dsrcH4fYISLvavqNNjgO3GDwtXeF8yMqsT1hbmd3daT d6R5AeDk8msU7CUFBSlKzgWyJ/BOaHIn0XR4YCu8sHyJVEUXEEtU2KnWtf5gc4QW 3g9ROxL1NT9bALnnibi/sWELqTA1iiUeIbh0lGU4d+jAtIy8ZOJZa8hSWZUo7AOu s8FzovMl/3+1ZqGRTZbu18y2IPfhG9kDVUe8UaYyu1RpWAfhc4z+YemcKsa+5nm5 O7ew3QimPym+PvAH/KNy4TfstyhrKXloi8pbVBCY035LudK1bC4= =86xh -----END PGP SIGNATURE----- --mbneedr2uplq73p2--