From patchwork Mon Nov 28 16:43:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 9449775 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 3CB6C60235 for ; Mon, 28 Nov 2016 17:10:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 294E827CEA for ; Mon, 28 Nov 2016 17:10:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1DECF27F80; Mon, 28 Nov 2016 17:10:24 +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=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6062827CEA for ; Mon, 28 Nov 2016 17:10:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932532AbcK1RKV (ORCPT ); Mon, 28 Nov 2016 12:10:21 -0500 Received: from outprodmail02.cc.columbia.edu ([128.59.72.51]:36550 "EHLO outprodmail02.cc.columbia.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754300AbcK1RKT (ORCPT ); Mon, 28 Nov 2016 12:10:19 -0500 X-Greylist: delayed 1520 seconds by postgrey-1.27 at vger.kernel.org; Mon, 28 Nov 2016 12:10:19 EST Received: from hazelnut (hazelnut.cc.columbia.edu [128.59.213.250]) by outprodmail02.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id uASGe4KA050106 for ; Mon, 28 Nov 2016 11:44:58 -0500 Received: from hazelnut (localhost.localdomain [127.0.0.1]) by hazelnut (Postfix) with ESMTP id C1B006D for ; Mon, 28 Nov 2016 11:44:58 -0500 (EST) Received: from sendprodmail03.cc.columbia.edu (sendprodmail03.cc.columbia.edu [128.59.72.15]) by hazelnut (Postfix) with ESMTP id 1FDCE82 for ; Mon, 28 Nov 2016 11:44:58 -0500 (EST) Received: from mail-qk0-f200.google.com (mail-qk0-f200.google.com [209.85.220.200]) by sendprodmail03.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id uASGivow019322 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 28 Nov 2016 11:44:58 -0500 Received: by mail-qk0-f200.google.com with SMTP id g193so114734412qke.2 for ; Mon, 28 Nov 2016 08:44:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=HAKnOFkY+tUUIXCv7iFlBqgvaT0CR+2L6fM15Q2+SIg=; b=W6Mmvikkz8AqLfOYnvqZ2M1XenhXZBQQkS4oSXKuZJOkRHRqR5zuSJYh7CR/q2YCYX BZG7cB5uFZKEoiK7lnu0HLGgcUSeyC9THI4uYuXlKCEVHtXB6UkV8T4J2s6SvBFPrUxW k0LkeAX54E8CJvGF5N3WUVMKFpp/68SfBv2kOHh5gzKqsWIIhObCilwCDQeBXplRau0K DZCf4re7g7wVmLL+d7TbK1P7Ed7EIzgErVOW+HCNyEB1hFvmirGTdD3l0Dvo8WUpmWps nuFieyJyleOjHbqMJFsxa1dpO7MC62RmEnsiKips5IUQ9u70Gv4VcfPNQmy2BaUbUTNB o7lg== X-Gm-Message-State: AKaTC01jzyG9f4eGBj2LGZYYwrIVujrt6gTg2pWeCOfzMVecdhzspQcYYQgeYGz+FrCA9iWiBNElNeL67LmoyE/9Jwlukk053kqpfOp/oLoNOjr1Zqjny3kQn/sT+e8hBeBWz3+Od/bvFr4= X-Received: by 10.55.15.95 with SMTP id z92mr19067085qkg.273.1480351497686; Mon, 28 Nov 2016 08:44:57 -0800 (PST) X-Received: by 10.55.15.95 with SMTP id z92mr19067065qkg.273.1480351497510; Mon, 28 Nov 2016 08:44:57 -0800 (PST) Received: from jintack.cs.columbia.edu ([2001:18d8:ffff:16:21a:4aff:feaa:f900]) by smtp.gmail.com with ESMTPSA id 21sm10369242qkh.4.2016.11.28.08.44.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 Nov 2016 08:44:56 -0800 (PST) From: Jintack Lim To: kvmarm@lists.cs.columbia.edu Cc: linux-arm-kernel@lists.infradead.org, marc.zyngier@arm.com, christoffer.dall@linaro.org, will.deacon@arm.com, catalin.marinas@arm.com, pbonzini@redhat.com, rkrcmar@redhat.com, linux@armlinux.org.uk, julien.grall@arm.com, andre.przywara@arm.com, kvm@vger.kernel.org, Jintack Subject: [PATCH] arm64: head.S: Fix CNTHCTL_EL2 access on VHE system Date: Mon, 28 Nov 2016 11:43:58 -0500 Message-Id: <1480351438-11548-1-git-send-email-jintack@cs.columbia.edu> X-Mailer: git-send-email 1.9.1 X-No-Spam-Score: Local X-Scanned-By: MIMEDefang 2.78 on 128.59.72.15 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jintack Bit positions of CNTHCTL_EL2 are changing depending on HCR_EL2.E2H bit. EL1PCEN and EL1PCTEN are 1st and 0th bits when E2H is not set, but they are 11th and 10th bits respectively when E2H is set. Current code is unintentionally setting wrong bits to CNTHCTL_EL2 with E2H set. In fact, we don't need to set those two bits, which allow EL1 and EL0 to access physical timer and counter respectively, if E2H and TGE are set for the host kernel. They will be configured later as necessary. First, we don't need to configure those bits for EL1, since the host kernel runs in EL2. It is a hypervisor's responsibility to configure them before entering a VM, which runs in EL0 and EL1. Second, EL0 accesses are configured in the later stage of boot process. Signed-off-by: Jintack Lim --- arch/arm64/kernel/head.S | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 332e331..bc3d2db 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -524,10 +524,16 @@ set_hcr: msr hcr_el2, x0 isb - /* Generic timers. */ + /* + * Allow Non-secure EL1 and EL0 to access physical timer and counter. + * This is not necessary for VHE, since the host kernel runs in EL2, + * and EL0 accesses are configured in the later stage of boot process. + */ + cbnz x2, 1f mrs x0, cnthctl_el2 orr x0, x0, #3 // Enable EL1 physical timers msr cnthctl_el2, x0 +1: msr cntvoff_el2, xzr // Clear virtual offset #ifdef CONFIG_ARM_GIC_V3