Received: by 10.223.185.116 with SMTP id b49csp2301539wrg; Sun, 4 Mar 2018 23:53:08 -0800 (PST) X-Google-Smtp-Source: AG47ELuaX+w79Kp0JAf99O5V+A6Qf3OeCKbGQ7YfSZLlPNss5VOVhEwEAp7w3Yjho17XkEz22vY4 X-Received: by 2002:a17:902:c5:: with SMTP id a63-v6mr12568579pla.391.1520236388741; Sun, 04 Mar 2018 23:53:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520236388; cv=none; d=google.com; s=arc-20160816; b=RWhp7kw/RZno9yLryMpFl8uiVTW1595MFMRsk20QfT2Xwon8WTISt8iz8vtbWtvvb7 xREXhguLHTlV4JIGcwPtu5mO0VNIGrq2Yrp7G/JruVd0O4UgyNLQk6uy4jQ+3obZ2wz9 zg85geoKcA0EfD0CbilvhX1R0Fo/+/EBvnKwR5fVXlncXcglil7gt1fpDDqT0Qh2l59H frvO9G0h4tADFDTsEDkqO+62GMMhfFh5U2DkrlQTEbSfcgjnp5SxKR6HWcPn5SzVA4dw 0BsLmoFF+VKozHuandpt1oRfJKVU8f5yKWanisFHvNjUfunzF4cyGnoF3z5diQAT/SO9 p7lA== 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:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:arc-authentication-results; bh=lrXr2eC/XWV/VrHbmmJFtpZDpO/zgsR5D1pCy/JoasQ=; b=Mla5O2vcYh0/e9w412TqjvY1zgHsOK6x39puAiGcS01zXLB3BdpQ3y8CMBNWV4Nbru +acqblHQcqJM3TITJWzScIoHBCyJ1GckMzjaKga5757vGpWJ5YBV0GFriVMogxfiQS9b aQtbZfMGWT4JXtdZbL1kFj0hPAijCUdHTI17IBNJp7IMW3lAiAwsp+2ZHc3SMiwTJ+LB uImnApFHXcEXacuCcfmLiyDR6JK6jsaG1VupHtvl74J7zII7TQlYTBVTX+9H1sqbMU1S VOpYm8drHdyyQs046FdzgnbyksU8HV4GJzmesJ02hQciqI8SyLwJjd7hJetLbbnFvjrX QJHw== 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 r16si9768856pfl.163.2018.03.04.23.52.54; Sun, 04 Mar 2018 23:53: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 S1752578AbeCEHvy convert rfc822-to-8bit (ORCPT + 99 others); Mon, 5 Mar 2018 02:51:54 -0500 Received: from mail.bootlin.com ([62.4.15.54]:47518 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752527AbeCEHvv (ORCPT ); Mon, 5 Mar 2018 02:51:51 -0500 Received: by mail.bootlin.com (Postfix, from userid 110) id 12D2520784; Mon, 5 Mar 2018 08:51:48 +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 dell-desktop.home (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.bootlin.com (Postfix) with ESMTPSA id 7F64B2046F; Mon, 5 Mar 2018 08:51:47 +0100 (CET) Date: Mon, 5 Mar 2018 08:51:48 +0100 From: =?UTF-8?B?TXlsw6huZQ==?= Josserand To: Chen-Yu Tsai Cc: Maxime Ripard , 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: <20180305085148.1de2a99c@dell-desktop.home> In-Reply-To: References: <20180223133742.26044-1-mylene.josserand@bootlin.com> <20180223133742.26044-11-mylene.josserand@bootlin.com> <20180226101252.ozdsxjvawgkemz2c@flea.lan> Organization: Bootlin X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Mon, 26 Feb 2018 18:25:10 +0800 Chen-Yu Tsai wrote: > On Mon, Feb 26, 2018 at 6:12 PM, Maxime Ripard > wrote: > > On Sat, Feb 24, 2018 at 12:17:13AM +0800, 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. > > > > 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. > > Global symbols and keeping everything in one place I guess. > This symbol would be used in a few places, so I suppose having it > in a separate assembly file would be OK. Okay so I will keep it in 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[] = { > >> > }; > >> > > >> > 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. > > > > 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. > > I wouldn't consider them hacks though. The hardware gives the option > to have control of many devices delegated solely to secure-only, or > secure/non-secure. Our present model is to support everything we can > in Linux directly, instead of through some firmware interface to a > non-existent firmware. I am not sure to understand what is the conclusion about it. Should I use "psci"/enable-method or should I use another mechanism to detect we are in secure/non-secure (if it exists)? Otherwise, for the moment, I can use machine-compatible on sun8i-a83t and we will see later how we can handle it in a better way. Thank you in advance, Best regards, Mylène -- Mylène Josserand, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering http://bootlin.com > > ChenYu > > >> AFAIK trying to set CNTVOFF under non-secure would be very bad. > > > > Just like any other access we do :/ > > > > Maxime > > > > -- > > Maxime Ripard, Bootlin (formerly Free Electrons) > > Embedded Linux and Kernel engineering > > https://bootlin.com