From patchwork Mon Nov 12 08:27:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 150797 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2877994ljp; Mon, 12 Nov 2018 00:27:21 -0800 (PST) X-Google-Smtp-Source: AJdET5ciQH0BpzJ/82mHWNHiRU1zuZ/ykYuoltkujaQ6xsYpE7KnbA88jd/wMj1PZa161oftOvNB X-Received: by 2002:a17:902:704c:: with SMTP id h12mr42917plt.78.1542011241305; Mon, 12 Nov 2018 00:27:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542011241; cv=none; d=google.com; s=arc-20160816; b=Aw6rfxxY2b3zYW4pS3mLbG2cTRRqiUnulIPPO2dGxC3hOoWE5jsmrJjCp8+kB5cJJP bJSp5y6i2Mlii5B5mc/51MLeR/GrnSWfr2sufmQgoxYBo81/XMiUq98QIew9Uy2TYeg0 DqkzNyDkcDDiXg9DODuSH87GKs+PGKKiI2ipedSfOBSciGtuYqU7RqBzYyDjaFq7yuxW wyGo4DI1rxiuzHRt8Tl2dtIWdVoPLH8uo2gCW644qHK8DuElyJ6oHUhk1RCpiz0c5itN tAVcQiAs8yRX9EPzvHw7U4gLH0iwxvXrxTU7S8sDa0n+pvKwqUh7hO5vladAUKm8xxOE 3a0A== 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 :message-id:date:subject:cc:to:from; bh=y9/5zam4sLZNdSHRiX5ZS0cEF8weWMxoaIWrE/nxbWU=; b=I+y18Sj8Kd8i3j0UMoSpyAeRs/D/56a6R3qA5CN3sEVG59wOU//aoN79o6+NtuNy5u l8PZ57NWI7SPL/KaJy7Xwu6k40xGOWEdNktBVe11E5IvlBLXTIHVhG1/JcxPgNP4yK8s ac3B/wDVir2kIhtIGG+lmjJ+EUHec76+YjKnKAR2W8zxlVMcOzuduPCpFFfrUKgDWVsE 0oQxAJJ8UojSwfW2+Icv5zE7b1cp0JrToRIF1DPreRSYguD7V2M7syJ/gC8/g035ghd5 +y4SImHjqSk9aaflXXQFzfYAw/AopMvz9Rkmdn2Cl2+v2sBkyceugVFc2L0MtzfjQurL Cglg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 b137si16869816pga.394.2018.11.12.00.27.19; Mon, 12 Nov 2018 00:27:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-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 stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726615AbeKLSTZ (ORCPT + 15 others); Mon, 12 Nov 2018 13:19:25 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:59862 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726443AbeKLSTZ (ORCPT ); Mon, 12 Nov 2018 13:19:25 -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 1B338A78; Mon, 12 Nov 2018 00:27:18 -0800 (PST) Received: from big-swifty.lan (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 677633F5A0; Mon, 12 Nov 2018 00:27:16 -0800 (PST) From: Marc Zyngier To: stable@vger.kernel.org Cc: Mark Rutland , christoffer.dall@arm.com, james.morse@arm.com, robin.murphy@arm.com, will.deacon@arm.com Subject: [PATCH stable-4.9] KVM: arm64: Fix caching of host MDCR_EL2 value Date: Mon, 12 Nov 2018 08:27:07 +0000 Message-Id: <20181112082707.26785-1-marc.zyngier@arm.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 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 --- arch/arm/kvm/arm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.19.1 diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index 20436972537f..a670c70f4def 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -1092,8 +1092,6 @@ static void cpu_init_hyp_mode(void *dummy) __cpu_init_hyp_mode(pgd_ptr, hyp_stack_ptr, vector_ptr); __cpu_init_stage2(); - - kvm_arm_init_debug(); } static void cpu_hyp_reinit(void) @@ -1108,6 +1106,8 @@ static void cpu_hyp_reinit(void) if (__hyp_get_vectors() == hyp_default_vectors) cpu_init_hyp_mode(NULL); } + + kvm_arm_init_debug(); } static void cpu_hyp_reset(void)