~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*
  3  * Copyright (C) 2012-2015 - ARM Ltd
  4  * Author: Marc Zyngier <marc.zyngier@arm.com>
  5  */
  6 
  7 #include <hyp/adjust_pc.h>
  8 
  9 #include <linux/compiler.h>
 10 #include <linux/irqchip/arm-gic.h>
 11 #include <linux/kvm_host.h>
 12 #include <linux/swab.h>
 13 
 14 #include <asm/kvm_emulate.h>
 15 #include <asm/kvm_hyp.h>
 16 #include <asm/kvm_mmu.h>
 17 
 18 static bool __is_be(struct kvm_vcpu *vcpu)
 19 {
 20         if (vcpu_mode_is_32bit(vcpu))
 21                 return !!(read_sysreg_el2(SYS_SPSR) & PSR_AA32_E_BIT);
 22 
 23         return !!(read_sysreg(SCTLR_EL1) & SCTLR_ELx_EE);
 24 }
 25 
 26 /*
 27  * __vgic_v2_perform_cpuif_access -- perform a GICV access on behalf of the
 28  *                                   guest.
 29  *
 30  * @vcpu: the offending vcpu
 31  *
 32  * Returns:
 33  *  1: GICV access successfully performed
 34  *  0: Not a GICV access
 35  * -1: Illegal GICV access successfully performed
 36  */
 37 int __vgic_v2_perform_cpuif_access(struct kvm_vcpu *vcpu)
 38 {
 39         struct kvm *kvm = kern_hyp_va(vcpu->kvm);
 40         struct vgic_dist *vgic = &kvm->arch.vgic;
 41         phys_addr_t fault_ipa;
 42         void __iomem *addr;
 43         int rd;
 44 
 45         /* Build the full address */
 46         fault_ipa  = kvm_vcpu_get_fault_ipa(vcpu);
 47         fault_ipa |= kvm_vcpu_get_hfar(vcpu) & GENMASK(11, 0);
 48 
 49         /* If not for GICV, move on */
 50         if (fault_ipa <  vgic->vgic_cpu_base ||
 51             fault_ipa >= (vgic->vgic_cpu_base + KVM_VGIC_V2_CPU_SIZE))
 52                 return 0;
 53 
 54         /* Reject anything but a 32bit access */
 55         if (kvm_vcpu_dabt_get_as(vcpu) != sizeof(u32)) {
 56                 __kvm_skip_instr(vcpu);
 57                 return -1;
 58         }
 59 
 60         /* Not aligned? Don't bother */
 61         if (fault_ipa & 3) {
 62                 __kvm_skip_instr(vcpu);
 63                 return -1;
 64         }
 65 
 66         rd = kvm_vcpu_dabt_get_rd(vcpu);
 67         addr  = kvm_vgic_global_state.vcpu_hyp_va;
 68         addr += fault_ipa - vgic->vgic_cpu_base;
 69 
 70         if (kvm_vcpu_dabt_iswrite(vcpu)) {
 71                 u32 data = vcpu_get_reg(vcpu, rd);
 72                 if (__is_be(vcpu)) {
 73                         /* guest pre-swabbed data, undo this for writel() */
 74                         data = __kvm_swab32(data);
 75                 }
 76                 writel_relaxed(data, addr);
 77         } else {
 78                 u32 data = readl_relaxed(addr);
 79                 if (__is_be(vcpu)) {
 80                         /* guest expects swabbed data */
 81                         data = __kvm_swab32(data);
 82                 }
 83                 vcpu_set_reg(vcpu, rd, data);
 84         }
 85 
 86         __kvm_skip_instr(vcpu);
 87 
 88         return 1;
 89 }
 90 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php