From patchwork Fri Sep 24 12:53:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 12515347 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=-18.2 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, 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 9BF58C433F5 for ; Fri, 24 Sep 2021 13:11:55 +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 6363360EE0 for ; Fri, 24 Sep 2021 13:11:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6363360EE0 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=Be8MxYoTqY4dIDJuINzd4iFwyqGxeB7HeIzfOhWmtZM=; b=R3J3NiuN2ThE3ecqjrN9BPuNAD +kiPu0A5ye9JJ2XDwD1KDjOojlKaoo5fsVQK1mASs1Y9W0cOlkCz2iGplcIn5dPyP+FfKqYmS9/D6 yuVRk8qgOM3gUpoYuLpSK5KRyX3iEep65auzpWIPO9RKPZmWGnZNou5/DMIitiI9D4rFJok5xdCVs Dpe+hBH+9555H6dis8ZmepMS48aXeYBCnNh5Bnx2nGu3j7q23XKw83qkeSTXBpusP5ifA5xgjxY5m +n69DufKquQcNVuJe/et4vCj7tMsYHoNXuz1SfCt1RW72XKcaG5ShV8ofiZJFMWb2nPP6YlVi22/4 QsancyMg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mTkvy-00ESAi-HY; Fri, 24 Sep 2021 13:08:10 +0000 Received: from mail-wr1-x449.google.com ([2a00:1450:4864:20::449]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mTkiz-00EMF8-Ul for linux-arm-kernel@lists.infradead.org; Fri, 24 Sep 2021 12:54:47 +0000 Received: by mail-wr1-x449.google.com with SMTP id a17-20020adfed11000000b00160525e875aso465980wro.23 for ; Fri, 24 Sep 2021 05:54:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=xhHjvocneo3OmYPl2aUhxqJ3BMqVUjdViv8A/KXRtOc=; b=J/C7Ta1yUem3gYRbil/zKRF0IxStHUFvTVNEvuRRLK6gctPS7/SC8wGX+7hdV8c7WF sjSMDuG0NjrV+/3ZNT0KciOwQfFrUiKwdKHNGGAYU85PPOeEbgyIDakYmiziwKsXibQN ZPrs0iDshzZjAJZ1kGyfQ1P565o2m8tAaHk2VwfnaXwwQCX46G347RPHq4hD4gmQ2LzT SLor++gvWIZW6zyDo3nnux9Tf+Km2hcZI0xela+/ti30GaLVylKlApErL4/QNfcgmrZL +j6MVi7XB5CJE/FaDfjRSKxRzHxJNULy6UVDbKmpOpKkV6+Jjj8ul6m6gZRAuZ+d1A50 4JLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=xhHjvocneo3OmYPl2aUhxqJ3BMqVUjdViv8A/KXRtOc=; b=PBZgfKe1d7d6Y7DTZk44bRchm0LHlPz8lz8bh1HDD4MWModFKf6/wf0zp8pK6RvNw1 2JwWZBTr/1/GUfqDKqoN7brHEfvvFFVXT0gnqK7pYVXKz5ASWtnw8OSVO6UuEHay+Yv8 HzrgWpeJ1Kv0G/EoOcCY0ngh3YKJQi1SNdm5Wbi8tyuWlCio67kDnE58eCV0Up3svBT4 mgVSqm/t/zbKMWwYFastQWEAp2EKGDmSnUgIw44b+QuICmtyw50HUsYEbUXCidCvaUzd RQtVeqQBfKrb88thtTFk708VyJ200/1C+3YhRXGfEz37G0kwRSnKmBN2W23VdT84PZEo SbxQ== X-Gm-Message-State: AOAM530rmP5j3kpVkh2FsNGP2t4p+WEsz3B2a2J859wMA0qUuXfZccVj 7eOwyGCsJwlYNS8DG+DBKy0AKSelUA== X-Google-Smtp-Source: ABdhPJxU6dLnsCPB/2TUUhu7b+8Tafoe11ACEILnegBEKHhcSyod6McampCuDXPyU43B2yIY76HX2EhGMA== X-Received: from tabba.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:482]) (user=tabba job=sendgmr) by 2002:a05:6000:1a89:: with SMTP id f9mr11219965wry.19.1632488083973; Fri, 24 Sep 2021 05:54:43 -0700 (PDT) Date: Fri, 24 Sep 2021 13:53:49 +0100 In-Reply-To: <20210924125359.2587041-1-tabba@google.com> Message-Id: <20210924125359.2587041-21-tabba@google.com> Mime-Version: 1.0 References: <20210924125359.2587041-1-tabba@google.com> X-Mailer: git-send-email 2.33.0.685.g46640cef36-goog Subject: [RFC PATCH v1 20/30] KVM: arm64: add __hyp_running_ctxt and __hyp_running_hyps From: Fuad Tabba To: kvmarm@lists.cs.columbia.edu Cc: maz@kernel.org, will@kernel.org, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, mark.rutland@arm.com, christoffer.dall@arm.com, drjones@redhat.com, qperret@google.com, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel-team@android.com, tabba@google.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210924_055446_087836_44E6F8E1 X-CRM114-Status: GOOD ( 13.42 ) 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 order to prepare to remove __hyp_running_vcpu, add __hyp_running_ctxt and __hyp_running_hyps to access the running kvm_cpu_ctxt and the hyp_state, as well as their associated assembly offsets. These new fields are updated but not accessed yet. Their state is consistent with __hyp_running_vcpu. Signed-off-by: Fuad Tabba --- arch/arm64/include/asm/kvm_asm.h | 13 +++++++++++++ arch/arm64/include/asm/kvm_host.h | 19 ++++++++++++++++--- arch/arm64/kernel/asm-offsets.c | 2 ++ arch/arm64/kvm/hyp/entry.S | 2 +- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h index 766b6a852407..52079e937fcd 100644 --- a/arch/arm64/include/asm/kvm_asm.h +++ b/arch/arm64/include/asm/kvm_asm.h @@ -271,6 +271,19 @@ extern u32 __kvm_get_mdcr_el2(void); .macro set_loaded_vcpu vcpu, ctxt, tmp adr_this_cpu \ctxt, kvm_hyp_ctxt, \tmp str \vcpu, [\ctxt, #HOST_CONTEXT_VCPU] + + add \tmp, \vcpu, #VCPU_CONTEXT + str \tmp, [\ctxt, #HOST_CONTEXT_CTXT] + + add \tmp, \vcpu, #VCPU_HYPS + str \tmp, [\ctxt, #HOST_CONTEXT_HYPS] +.endm + +.macro clear_loaded_vcpu ctxt, tmp + adr_this_cpu \ctxt, kvm_hyp_ctxt, \tmp + str xzr, [\ctxt, #HOST_CONTEXT_VCPU] + str xzr, [\ctxt, #HOST_CONTEXT_CTXT] + str xzr, [\ctxt, #HOST_CONTEXT_HYPS] .endm .macro get_loaded_vcpu_ctxt vcpu, ctxt diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 4b01c74705ad..b42d0c6c8004 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -228,14 +228,27 @@ struct kvm_cpu_context { u64 sys_regs[NR_SYS_REGS]; struct kvm_vcpu *__hyp_running_vcpu; + struct kvm_cpu_context *__hyp_running_ctxt; + struct vcpu_hyp_state *__hyp_running_hyps; }; #define get_hyp_running_vcpu(ctxt) (ctxt)->__hyp_running_vcpu -#define set_hyp_running_vcpu(ctxt, vcpu) (ctxt)->__hyp_running_vcpu = (vcpu) +#define set_hyp_running_vcpu(host_ctxt, vcpu) do { \ + struct kvm_vcpu *v = (vcpu); \ + (host_ctxt)->__hyp_running_vcpu = v; \ + if (vcpu) { \ + (host_ctxt)->__hyp_running_ctxt = &v->arch.ctxt; \ + (host_ctxt)->__hyp_running_hyps = &v->arch.hyp_state; \ + } else { \ + (host_ctxt)->__hyp_running_ctxt = NULL; \ + (host_ctxt)->__hyp_running_hyps = NULL; \ + }\ +} while(0) + #define is_hyp_running_vcpu(ctxt) (ctxt)->__hyp_running_vcpu -#define get_hyp_running_ctxt(host_ctxt) (host_ctxt)->__hyp_running_vcpu ? &(host_ctxt)->__hyp_running_vcpu->arch.ctxt : NULL -#define get_hyp_running_hyps(host_ctxt) (host_ctxt)->__hyp_running_vcpu ? &(host_ctxt)->__hyp_running_vcpu->arch.hyp_state : NULL +#define get_hyp_running_ctxt(host_ctxt) (host_ctxt)->__hyp_running_ctxt +#define get_hyp_running_hyps(host_ctxt) (host_ctxt)->__hyp_running_hyps struct kvm_pmu_events { u32 events_host; diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c index 1ecc55570acc..9c25078da294 100644 --- a/arch/arm64/kernel/asm-offsets.c +++ b/arch/arm64/kernel/asm-offsets.c @@ -117,6 +117,8 @@ int main(void) DEFINE(CPU_APDBKEYLO_EL1, offsetof(struct kvm_cpu_context, sys_regs[APDBKEYLO_EL1])); DEFINE(CPU_APGAKEYLO_EL1, offsetof(struct kvm_cpu_context, sys_regs[APGAKEYLO_EL1])); DEFINE(HOST_CONTEXT_VCPU, offsetof(struct kvm_cpu_context, __hyp_running_vcpu)); + DEFINE(HOST_CONTEXT_CTXT, offsetof(struct kvm_cpu_context, __hyp_running_ctxt)); + DEFINE(HOST_CONTEXT_HYPS, offsetof(struct kvm_cpu_context, __hyp_running_hyps)); DEFINE(HOST_DATA_CONTEXT, offsetof(struct kvm_host_data, host_ctxt)); DEFINE(NVHE_INIT_MAIR_EL2, offsetof(struct kvm_nvhe_init_params, mair_el2)); DEFINE(NVHE_INIT_TCR_EL2, offsetof(struct kvm_nvhe_init_params, tcr_el2)); diff --git a/arch/arm64/kvm/hyp/entry.S b/arch/arm64/kvm/hyp/entry.S index 1804be5b7ead..8e7033aa5770 100644 --- a/arch/arm64/kvm/hyp/entry.S +++ b/arch/arm64/kvm/hyp/entry.S @@ -145,7 +145,7 @@ SYM_INNER_LABEL(__guest_exit, SYM_L_GLOBAL) // Now restore the hyp regs restore_callee_saved_regs x2 - set_loaded_vcpu xzr, x2, x3 + clear_loaded_vcpu x2, x3 alternative_if ARM64_HAS_RAS_EXTN // If we have the RAS extensions we can consume a pending error