From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 16E78C2BBCA for ; Tue, 25 Jun 2024 13:37:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=WqBYiI3lzZChU584wznf77K9JYJR0aXUwfkczwQNYbg=; b=OGWpoqkqlov6uHj3bpMu74j9Tm rKKW9US7eKHTpZJu8mj3IF63+h4u24NOgl9UC7I6PSEBTM7ePZFo2C0QR6qMAL16EAsFGId8ci5so i4YeHrCJU7Q8ap6OyEOEVKGUDQ0eS06YkakrBhxTmNhnss43XFEz8EfngJGrnAtVXi0h2JyxzsPQO BEu4feN/LzYa/UAJMsJzuTxP0bcuI2P8eGBYsk/WFdwq/fMle7p/hozWNGAXlFfpzB2T3wImA5zJl ukTzt9LGnVwd+VdcAKxX9ueuC8h8XHtkQftPOAfa5wT5P+5YIFCH+m2LoLwfQxxUQCxIutYOaXhzV 0Irm+NGQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM6M5-000000030ep-38C1; Tue, 25 Jun 2024 13:37:05 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sM6Ka-0000000301j-033o for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 13:35:34 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 79F06CE1AFA; Tue, 25 Jun 2024 13:35:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD8A6C4AF0D; Tue, 25 Jun 2024 13:35:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719322524; bh=GYYU7oaazXbNaqz2ULj2k5bsMFiur2S8hJufSai2nx4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xpzyr36qQjQUJMMnP7fnMA9Ks5+IJtwuMhwkX9wE+iek3+SvXAVtZyFJLNZeA5EUf sqpMNtyUWDGsLGo+fEb+dLWJXU6eRXR2OBs3PkVUb6WHKb9LURkRJQ5OtyS7fF/xUH p+8W/FcrWU/zy/iZ0L0s/q2Hek63XEMqoTW011y80UyBOpxTO8KrkbNLlJW04hsAQd g+dKyWXKgjVAPZ9cRO8/6b/VSKlOCuEfInyqyNQcuadX1lPwaxCpO+63VSN9HF9oAH 4MT8fvBwm5+hSFAHVK5zhhdw22N4saA3LXtFsIEcjajAhKMPOOklOhWe0CLodqKLDA zE1VFYnj4Yg7Q== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sM6KR-007A6l-2e; Tue, 25 Jun 2024 14:35:23 +0100 From: Marc Zyngier To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org Cc: James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Joey Gouly Subject: [PATCH 07/12] KVM: arm64: nv: Add basic emulation of AT S1E2{R,W} Date: Tue, 25 Jun 2024 14:35:06 +0100 Message-Id: <20240625133508.259829-8-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240625133508.259829-1-maz@kernel.org> References: <20240625133508.259829-1-maz@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, joey.gouly@arm.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240625_063532_558622_1392B455 X-CRM114-Status: GOOD ( 13.01 ) 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 Similar to our AT S1E{0,1} emulation, we implement the AT S1E2 handling. This emulation of course suffers from the same problems, but is somehow simpler due to the lack of PAN2 and the fact that we are guaranteed to execute it from the correct context. Co-developed-by: Jintack Lim Signed-off-by: Jintack Lim Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/kvm_asm.h | 1 + arch/arm64/kvm/at.c | 57 ++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h index 9b6c9f4f4d885..6ec0622969766 100644 --- a/arch/arm64/include/asm/kvm_asm.h +++ b/arch/arm64/include/asm/kvm_asm.h @@ -237,6 +237,7 @@ extern int __kvm_tlbi_s1e2(struct kvm_s2_mmu *mmu, u64 va, u64 sys_encoding); extern void __kvm_timer_set_cntvoff(u64 cntvoff); extern void __kvm_at_s1e01(struct kvm_vcpu *vcpu, u32 op, u64 vaddr); +extern void __kvm_at_s1e2(struct kvm_vcpu *vcpu, u32 op, u64 vaddr); extern int __kvm_vcpu_run(struct kvm_vcpu *vcpu); diff --git a/arch/arm64/kvm/at.c b/arch/arm64/kvm/at.c index eb0aa49e61f68..147df5a9cc4e0 100644 --- a/arch/arm64/kvm/at.c +++ b/arch/arm64/kvm/at.c @@ -195,3 +195,60 @@ void __kvm_at_s1e01(struct kvm_vcpu *vcpu, u32 op, u64 vaddr) write_unlock(&vcpu->kvm->mmu_lock); } + +void __kvm_at_s1e2(struct kvm_vcpu *vcpu, u32 op, u64 vaddr) +{ + struct kvm_s2_mmu *mmu; + unsigned long flags; + u64 val, hcr, par; + bool fail; + + write_lock(&vcpu->kvm->mmu_lock); + + mmu = &vcpu->kvm->arch.mmu; + + /* + * We've trapped, so everything is live on the CPU. As we will + * be switching context behind everybody's back, disable + * interrupts... + */ + local_irq_save(flags); + + val = hcr = read_sysreg(hcr_el2); + val &= ~HCR_TGE; + val |= HCR_VM; + + if (!vcpu_el2_e2h_is_set(vcpu)) + val |= HCR_NV | HCR_NV1; + + write_sysreg(val, hcr_el2); + isb(); + + switch (op) { + case OP_AT_S1E2R: + fail = __kvm_at(OP_AT_S1E1R, vaddr); + break; + case OP_AT_S1E2W: + fail = __kvm_at(OP_AT_S1E1W, vaddr); + break; + default: + WARN_ON_ONCE(1); + fail = true; + } + + isb(); + + if (!fail) + par = read_sysreg_par(); + else + par = SYS_PAR_EL1_F; + + write_sysreg(hcr, hcr_el2); + isb(); + + local_irq_restore(flags); + + write_unlock(&vcpu->kvm->mmu_lock); + + vcpu_write_sys_reg(vcpu, par, PAR_EL1); +} -- 2.39.2