Path: blob/master/arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c
26490 views
// SPDX-License-Identifier: GPL-2.0-only1/*2* Copyright (C) 2012-2015 - ARM Ltd3* Author: Marc Zyngier <[email protected]>4*/56#include <hyp/adjust_pc.h>78#include <linux/compiler.h>9#include <linux/irqchip/arm-gic.h>10#include <linux/kvm_host.h>11#include <linux/swab.h>1213#include <asm/kvm_emulate.h>14#include <asm/kvm_hyp.h>15#include <asm/kvm_mmu.h>1617static bool __is_be(struct kvm_vcpu *vcpu)18{19if (vcpu_mode_is_32bit(vcpu))20return !!(read_sysreg_el2(SYS_SPSR) & PSR_AA32_E_BIT);2122return !!(read_sysreg_el1(SYS_SCTLR) & SCTLR_ELx_EE);23}2425/*26* __vgic_v2_perform_cpuif_access -- perform a GICV access on behalf of the27* guest.28*29* @vcpu: the offending vcpu30*31* Returns:32* 1: GICV access successfully performed33* 0: Not a GICV access34* -1: Illegal GICV access successfully performed35*/36int __vgic_v2_perform_cpuif_access(struct kvm_vcpu *vcpu)37{38struct kvm *kvm = kern_hyp_va(vcpu->kvm);39struct vgic_dist *vgic = &kvm->arch.vgic;40phys_addr_t fault_ipa;41void __iomem *addr;42int rd;4344/* Build the full address */45fault_ipa = kvm_vcpu_get_fault_ipa(vcpu);46fault_ipa |= kvm_vcpu_get_hfar(vcpu) & GENMASK(11, 0);4748/* If not for GICV, move on */49if (fault_ipa < vgic->vgic_cpu_base ||50fault_ipa >= (vgic->vgic_cpu_base + KVM_VGIC_V2_CPU_SIZE))51return 0;5253/* Reject anything but a 32bit access */54if (kvm_vcpu_dabt_get_as(vcpu) != sizeof(u32)) {55__kvm_skip_instr(vcpu);56return -1;57}5859/* Not aligned? Don't bother */60if (fault_ipa & 3) {61__kvm_skip_instr(vcpu);62return -1;63}6465rd = kvm_vcpu_dabt_get_rd(vcpu);66addr = kvm_vgic_global_state.vcpu_hyp_va;67addr += fault_ipa - vgic->vgic_cpu_base;6869if (kvm_vcpu_dabt_iswrite(vcpu)) {70u32 data = vcpu_get_reg(vcpu, rd);71if (__is_be(vcpu)) {72/* guest pre-swabbed data, undo this for writel() */73data = __kvm_swab32(data);74}75writel_relaxed(data, addr);76} else {77u32 data = readl_relaxed(addr);78if (__is_be(vcpu)) {79/* guest expects swabbed data */80data = __kvm_swab32(data);81}82vcpu_set_reg(vcpu, rd, data);83}8485__kvm_skip_instr(vcpu);8687return 1;88}899091