From patchwork Mon Aug 16 00:12:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12437521 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00084C4338F for ; Mon, 16 Aug 2021 00:19:20 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B6E3C61151 for ; Mon, 16 Aug 2021 00:19:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B6E3C61151 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=1CPu0kqVkGPHKFhaHmTO1E3trBDWjySPqjPUG6coE58=; b=OpRBYBSA6ePgoJrTqBRxVPdD0u IdvAxW2dbaZI6zLih0mgztCSp9yYMmtNpzU1wc6aDPgtkOrlxerWjnBkMj3qF+UW1NkQZmMqCXINb 1zGxSd/bk7T2VioXAR5q/5NNG7n9QPN30YFtp7a2HkOSBI8m3oTQu9W7ibYAWAZgwRjFGA3Twkult ZlJT4lZq2Bbeg4CpmE0cRxofwZtGFndLK2CG2zfQn4qARZ0dF5KeRm/7DKyQ5/c/K7Zuzh2Jrbvm1 EJ9VZsiODXpgyJ+GnmQnvDv2BUfkyGsjamqak3XwRpoAMHVPFGFj5Ov7wit0/E9/yV9/DOdcEySg9 UN8sKwWQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mFQJs-00FnMG-Cw; Mon, 16 Aug 2021 00:17:37 +0000 Received: from mail-qv1-xf4a.google.com ([2607:f8b0:4864:20::f4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mFQEv-00FlD5-23 for linux-arm-kernel@lists.infradead.org; Mon, 16 Aug 2021 00:12:30 +0000 Received: by mail-qv1-xf4a.google.com with SMTP id n14-20020a0c9d4e0000b0290354a5f8c800so11767695qvf.17 for ; Sun, 15 Aug 2021 17:12:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=IzZpuEsgwV0AULnFn0VDAkOlC3SkP0x8cjQf8LHfPG8=; b=Z6KJIWUoRZm4gv1SxUSGM1H6/YnrARuwOEm5BdLr/NIw2XcC76fYJA/umAxe1eKVRy roA/HxRxx9DEMfnoH0VYW9Dq7WKsVqbZsfl1UXp5C/+7nEOY8tPdtSNnp4an2z/fhNP/ /hSJ1Yvy7h7zW7dQBoz3hSL9+ruqcYlSuE/QwBGN4ED8WT9ee1x0wY5zXsU7K4Wilody ju6OQD7sBLOx6tKwDvk16FD6QRCIOyUPis0cP8sn5jutVX57b7PmSIos9ixZ9RnXzIZA G4LmfbIOdX/Jzm+JanelRb5nJzx8rt9LZLR+Ox5DuoF1uojBAVpWBWsEZP0xlBp886dY UhXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=IzZpuEsgwV0AULnFn0VDAkOlC3SkP0x8cjQf8LHfPG8=; b=j7ClDX3YclTcWqcfn4N7AL2vkkOtsZvGfl0ZZo1p/Au3QbJ3SEPbDvSsjfJMXjo32D Y7Jbi8dEFNPmy+xSJSnXsk8PyhtY1TddWrxgU3UwNJFtXXTj0WDm2WyRHiIFXFF10m3F uGHx3spqiZ6TJIPnfggMMA3hp8EDoO8T28duDx/DvMOAl2bZkqaPOdb8D/yFFCsO97Ty puSCKiWD5f8/l71JwfPcui9mNRp6tUXhPICYa/tvMJMbgeKQhf9Q8sKaKf2PeNx26LDR pF5Orz7gCxbh0Rc55gq3Dc0ryTTXvh6fTb2Nr63Pe8ezBO9LgzfW9z+o53eoXd7gbOug 2ADQ== X-Gm-Message-State: AOAM532LYQdGrtwuHA1Ls++DEwszK7PQgpcQsxYgZ2x1HR7xQgGpWhYs iVyuJip/HikRvkzuK4hJXuXyHdyet68= X-Google-Smtp-Source: ABdhPJyq1E1IRX+IFCz2UT4Lu7i7B0G3RsUFCvBiLDi44WCVFhrddU+e2oHM6bxVIVMm1WK477KidWJeex0= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a05:6214:10c4:: with SMTP id r4mr13783414qvs.58.1629072747465; Sun, 15 Aug 2021 17:12:27 -0700 (PDT) Date: Mon, 16 Aug 2021 00:12:16 +0000 In-Reply-To: <20210816001217.3063400-1-oupton@google.com> Message-Id: <20210816001217.3063400-7-oupton@google.com> Mime-Version: 1.0 References: <20210816001217.3063400-1-oupton@google.com> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog Subject: [PATCH v7 6/7] KVM: arm64: Configure timer traps in vcpu_load() for VHE From: Oliver Upton To: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu Cc: Paolo Bonzini , Sean Christopherson , Marc Zyngier , Peter Shier , Jim Mattson , David Matlack , Ricardo Koller , Jing Zhang , Raghavendra Rao Anata , James Morse , Alexandru Elisei , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, Andrew Jones , Will Deacon , Catalin Marinas , Oliver Upton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210815_171229_176647_1D34C174 X-CRM114-Status: GOOD ( 14.91 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In preparation for emulated physical counter-timer offsetting, configure traps on every vcpu_load() for VHE systems. As before, these trap settings do not affect host userspace, and are only active for the guest. Suggested-by: Marc Zyngier Signed-off-by: Oliver Upton Reviewed-by: Andrew Jones --- arch/arm64/kvm/arch_timer.c | 10 +++++++--- arch/arm64/kvm/arm.c | 4 +--- include/kvm/arm_arch_timer.h | 2 -- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c index 46380c389683..1689c2e20cd3 100644 --- a/arch/arm64/kvm/arch_timer.c +++ b/arch/arm64/kvm/arch_timer.c @@ -51,6 +51,7 @@ static void kvm_arm_timer_write(struct kvm_vcpu *vcpu, static u64 kvm_arm_timer_read(struct kvm_vcpu *vcpu, struct arch_timer_context *timer, enum kvm_arch_timer_regs treg); +static void kvm_timer_enable_traps_vhe(void); u32 timer_get_ctl(struct arch_timer_context *ctxt) { @@ -663,6 +664,9 @@ void kvm_timer_vcpu_load(struct kvm_vcpu *vcpu) if (map.emul_ptimer) timer_emulate(map.emul_ptimer); + + if (has_vhe()) + kvm_timer_enable_traps_vhe(); } bool kvm_timer_should_notify_user(struct kvm_vcpu *vcpu) @@ -1355,12 +1359,12 @@ int kvm_timer_enable(struct kvm_vcpu *vcpu) } /* - * On VHE system, we only need to configure the EL2 timer trap register once, - * not for every world switch. + * On VHE system, we only need to configure the EL2 timer trap register on + * vcpu_load(), but not every world switch into the guest. * The host kernel runs at EL2 with HCR_EL2.TGE == 1, * and this makes those bits have no effect for the host kernel execution. */ -void kvm_timer_init_vhe(void) +static void kvm_timer_enable_traps_vhe(void) { /* When HCR_EL2.E2H ==1, EL1PCEN and EL1PCTEN are shifted by 10 */ u32 cnthctl_shift = 10; diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 0de4b41c3706..f882a7fb3a1b 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1559,9 +1559,7 @@ static void cpu_hyp_reinit(void) cpu_hyp_reset(); - if (is_kernel_in_hyp_mode()) - kvm_timer_init_vhe(); - else + if (!is_kernel_in_hyp_mode()) cpu_init_hyp_mode(); cpu_set_hyp_vector(); diff --git a/include/kvm/arm_arch_timer.h b/include/kvm/arm_arch_timer.h index 615f9314f6a5..254653b42da0 100644 --- a/include/kvm/arm_arch_timer.h +++ b/include/kvm/arm_arch_timer.h @@ -87,8 +87,6 @@ u64 kvm_phys_timer_read(void); void kvm_timer_vcpu_load(struct kvm_vcpu *vcpu); void kvm_timer_vcpu_put(struct kvm_vcpu *vcpu); -void kvm_timer_init_vhe(void); - bool kvm_arch_timer_get_input_level(int vintid); #define vcpu_timer(v) (&(v)->arch.timer_cpu)