Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3474919imu; Sun, 11 Nov 2018 15:57:47 -0800 (PST) X-Google-Smtp-Source: AJdET5dokcY0UDAP80N0yq+9VSPY3iofEtklr1TUbM8MdltcTpv7uzOijNtKt5GX2hIT2HBG1m0z X-Received: by 2002:a62:c299:: with SMTP id w25-v6mr18535282pfk.205.1541980667835; Sun, 11 Nov 2018 15:57:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541980667; cv=none; d=google.com; s=arc-20160816; b=vdomgAcADj/hUJFcOriGiNaw8XH8ovhaM0aAjBCVyTJ6jj5YTa+xynloXt7zYFTTL0 zw7X4jhQ2vu/TMJ3pHNIaEIk0FXefKeK9C/k3KoAiPV3oKarNS0So2JWJ6r1UfBxTLBo IptgYlyrnQEW65lXAUVxPuxgOsoQhs+hoI/ZbRWjezM6sYpUQWSI0Asi8Hedn/cDhtHG pG3QhK688vcGMev5li5EkdX5hJBOGl//xbroy2foT6MSmuYadGWNSir50OfR/IVCAfPQ 8/GWy3to58OkvwEfG58rHHuDl9ck4LJ6dBQN9FQvvRQlfGscq1Z+teY6rCzMdIEx+Qx4 I+sg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6HaIz6K38HV1DsoWRwBLHGHXS7NMh1WsBDwiokRdcC8=; b=z4BHGYt7I1MLMWBPiuEe1OpTPWCVQ59g1PLF317DQeNYakao3iTEOgOQEfzCqClx3Z X/gxlQkl//HLKU38gA6pC2yyhKC1P4RLDXRIKdisIyuAjHM0gXLlVLAm7hGxy8keehRT OjTZoWS9FuhUfmKsXXrxwKEMD50x+jRFh1zjSOqMZ8WALzaZfFoWHRh9FSQ5WxMMeUjU EIuePfQsRXXr6L/8URItmEbGRCnT0u8aPIZHgdDJ8d//K8yJ/ZvN0Dgq1UrQQVqnO/ud qSIJH3HDgRMflwjbxvAFZQxacclD6xB8G8004ajUoTH319LAkiMvZ1D1SnmJ0mVPSrCJ z9uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=04JlDluz; 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 h3-v6si15683718plb.291.2018.11.11.15.57.32; Sun, 11 Nov 2018 15:57:47 -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; dkim=pass header.i=@kernel.org header.s=default header.b=04JlDluz; 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 S1732613AbeKLISP (ORCPT + 99 others); Mon, 12 Nov 2018 03:18:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:35400 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732574AbeKLISO (ORCPT ); Mon, 12 Nov 2018 03:18:14 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F13AD216FD; Sun, 11 Nov 2018 22:28:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975299; bh=7MaIqrFauHoI0ru1/fdyd2YAe9K8qB2TUb0i8H7c3Pw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=04JlDluzSKcDcqZXaMt3HSzDTFlxyGkVBTyXQpfwL7xLiD6BSDTUnawcUcHjzlUZz p/Bk6cwHTpHStGfNh29A0LBq8427q/4Vs7ElsUTsdpnpxhwjZBF/ThTdBdasVmOp+u C69WJhsJ6m1cX6EnH9f1BWUci5EZrI9EY7qgKDhc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christopher Dall , James Morse , Will Deacon , Robin Murphy , Mark Rutland , Marc Zyngier Subject: [PATCH 4.19 256/361] KVM: arm64: Fix caching of host MDCR_EL2 value Date: Sun, 11 Nov 2018 14:20:03 -0800 Message-Id: <20181111221653.591319262@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mark Rutland commit da5a3ce66b8bb51b0ea8a89f42aac153903f90fb upstream. At boot time, KVM stashes the host MDCR_EL2 value, but only does this when the kernel is not running in hyp mode (i.e. is non-VHE). In these cases, the stashed value of MDCR_EL2.HPMN happens to be zero, which can lead to CONSTRAINED UNPREDICTABLE behaviour. Since we use this value to derive the MDCR_EL2 value when switching to/from a guest, after a guest have been run, the performance counters do not behave as expected. This has been observed to result in accesses via PMXEVTYPER_EL0 and PMXEVCNTR_EL0 not affecting the relevant counters, resulting in events not being counted. In these cases, only the fixed-purpose cycle counter appears to work as expected. Fix this by always stashing the host MDCR_EL2 value, regardless of VHE. Cc: Christopher Dall Cc: James Morse Cc: Will Deacon Cc: stable@vger.kernel.org Fixes: 1e947bad0b63b351 ("arm64: KVM: Skip HYP setup when already running in HYP") Tested-by: Robin Murphy Signed-off-by: Mark Rutland Signed-off-by: Marc Zyngier Signed-off-by: Greg Kroah-Hartman --- virt/kvm/arm/arm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/virt/kvm/arm/arm.c +++ b/virt/kvm/arm/arm.c @@ -1295,8 +1295,6 @@ static void cpu_init_hyp_mode(void *dumm __cpu_init_hyp_mode(pgd_ptr, hyp_stack_ptr, vector_ptr); __cpu_init_stage2(); - - kvm_arm_init_debug(); } static void cpu_hyp_reset(void) @@ -1320,6 +1318,8 @@ static void cpu_hyp_reinit(void) cpu_init_hyp_mode(NULL); } + kvm_arm_init_debug(); + if (vgic_present) kvm_vgic_init_cpu_hardware(); }