From patchwork Fri Oct 19 12:58:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 10649461 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2025F15E2 for ; Fri, 19 Oct 2018 13:18:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A15E28B0F for ; Fri, 19 Oct 2018 13:18:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED69528B14; Fri, 19 Oct 2018 13:17:59 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8DC0928B0F for ; Fri, 19 Oct 2018 13:17:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CCaCos6e8AjwFnOCAN2hOli8xs2Ytj/KsRJDy09FJHw=; b=PGRKaIhTsY2GgP K/AvzSnmGQkd/X8jAig6UPXUJomCPIoX3tqfKkz/1JKrM7XLPa3mMOMc7J6RqXdeLzj5CHB+F94CE SbIKnuYsEqzq0p/w0IZk5oF78dZzJl42cFJUPCaqCf+oIvY/D9bYjbigaCc4sZwtogG5KxmJiD9Lb IEuFFJhrfCHec13GniYevByrAjxm1OCY4js648vigRH14QY+43GIENTwr2pUoc3Vl6hjWsu9JGhGh eF8g4L1rATZa8YPXiLrP4ehG7dWIm2kLJh8orZXBU3jxjMCvUzlKTluhryh0PZirwc+XRLrE83o3R bg0eV2lvOydmgns5gCQw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gDUf5-0002mv-Sp; Fri, 19 Oct 2018 13:17:55 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gDUbs-0008Vq-G0 for linux-arm-kernel@bombadil.infradead.org; Fri, 19 Oct 2018 13:14:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=4D5yTHS/ZNT6itqdV0dBqvCOzdJg8Ob0HjqpH0U4BqI=; b=ZR1v9nlYkLz/88s6q/qK+sonHy oHXjMVGMCRlaSoBP0AWaAKhsLuNjhX5rgP4Ujx7Y2DVFlTdE2musC6Qoc1uYSa96EgBIIdGCMhVim Y2aWrUI7MROEicQ1VUvHL8dbJIOSOSzdjxWxEAQY4HTAhyLWm/qcFZ7CEDxjzDWC75hjUmIuQH9gv gflpSRsBwA7x1u4UWwxL9QNANrBvEFDG9EcW1Q6kl+rD1a/TnUiT8TIrSkim7js054U2l9d/aktKb oy1MDoJMh9ck7LuBPRy/w0t8FOHjx6udlPZDWk0+Su7p9ssAnG5YPgwCd8KwvqLCJITfg4cq0NyH2 Me2fs8+Q==; Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by casper.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gDUOA-0000NO-0B for linux-arm-kernel@lists.infradead.org; Fri, 19 Oct 2018 13:00:27 +0000 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 BA0ACEBD; Fri, 19 Oct 2018 06:00:25 -0700 (PDT) Received: from filthy-habits.cambridge.arm.com (filthy-habits.cambridge.arm.com [10.1.196.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1A8463F71D; Fri, 19 Oct 2018 06:00:22 -0700 (PDT) From: Marc Zyngier To: Paolo Bonzini , =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= Subject: [PATCH 23/26] KVM: arm64: Fix caching of host MDCR_EL2 value Date: Fri, 19 Oct 2018 13:58:58 +0100 Message-Id: <20181019125901.185478-24-marc.zyngier@arm.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181019125901.185478-1-marc.zyngier@arm.com> References: <20181019125901.185478-1-marc.zyngier@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181019_140026_224308_D8D3F3C5 X-CRM114-Status: GOOD ( 14.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , zhong jiang , kvm@vger.kernel.org, Suzuki K Poulose , Catalin Marinas , Punit Agrawal , Christoffer Dall , Kristina Martsenko , Dongjiu Geng , Eric Auger , James Morse , Robin Murphy , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Mark Rutland 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 --- virt/kvm/arm/arm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c index 4ce99bb223bc..4c5ff06b18f9 100644 --- a/virt/kvm/arm/arm.c +++ b/virt/kvm/arm/arm.c @@ -1296,8 +1296,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_reset(void) @@ -1315,6 +1313,8 @@ static void cpu_hyp_reinit(void) else cpu_init_hyp_mode(NULL); + kvm_arm_init_debug(); + if (vgic_present) kvm_vgic_init_cpu_hardware(); }