diff options
-rw-r--r-- | Documentation/virtual/kvm/api.txt | 7 | ||||
-rw-r--r-- | Documentation/virtual/kvm/devices/arm-vgic.txt | 11 | ||||
-rw-r--r-- | arch/arm/include/uapi/asm/kvm.h | 2 | ||||
-rw-r--r-- | arch/arm/kvm/arm.c | 2 | ||||
-rw-r--r-- | include/kvm/arm_vgic.h | 2 | ||||
-rw-r--r-- | virt/kvm/arm/vgic.c | 87 |
6 files changed, 96 insertions, 15 deletions
diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt index a30035dd4c26..867112f1968d 100644 --- a/Documentation/virtual/kvm/api.txt +++ b/Documentation/virtual/kvm/api.txt | |||
@@ -2391,7 +2391,8 @@ struct kvm_reg_list { | |||
2391 | This ioctl returns the guest registers that are supported for the | 2391 | This ioctl returns the guest registers that are supported for the |
2392 | KVM_GET_ONE_REG/KVM_SET_ONE_REG calls. | 2392 | KVM_GET_ONE_REG/KVM_SET_ONE_REG calls. |
2393 | 2393 | ||
2394 | 4.85 KVM_ARM_SET_DEVICE_ADDR | 2394 | |
2395 | 4.85 KVM_ARM_SET_DEVICE_ADDR (deprecated) | ||
2395 | 2396 | ||
2396 | Capability: KVM_CAP_ARM_SET_DEVICE_ADDR | 2397 | Capability: KVM_CAP_ARM_SET_DEVICE_ADDR |
2397 | Architectures: arm, arm64 | 2398 | Architectures: arm, arm64 |
@@ -2429,6 +2430,10 @@ must be called after calling KVM_CREATE_IRQCHIP, but before calling | |||
2429 | KVM_RUN on any of the VCPUs. Calling this ioctl twice for any of the | 2430 | KVM_RUN on any of the VCPUs. Calling this ioctl twice for any of the |
2430 | base addresses will return -EEXIST. | 2431 | base addresses will return -EEXIST. |
2431 | 2432 | ||
2433 | Note, this IOCTL is deprecated and the more flexible SET/GET_DEVICE_ATTR API | ||
2434 | should be used instead. | ||
2435 | |||
2436 | |||
2432 | 4.86 KVM_PPC_RTAS_DEFINE_TOKEN | 2437 | 4.86 KVM_PPC_RTAS_DEFINE_TOKEN |
2433 | 2438 | ||
2434 | Capability: KVM_CAP_PPC_RTAS | 2439 | Capability: KVM_CAP_PPC_RTAS |
diff --git a/Documentation/virtual/kvm/devices/arm-vgic.txt b/Documentation/virtual/kvm/devices/arm-vgic.txt index 38f27f709a99..c9febb2a0c3e 100644 --- a/Documentation/virtual/kvm/devices/arm-vgic.txt +++ b/Documentation/virtual/kvm/devices/arm-vgic.txt | |||
@@ -8,3 +8,14 @@ Only one VGIC instance may be instantiated through either this API or the | |||
8 | legacy KVM_CREATE_IRQCHIP api. The created VGIC will act as the VM interrupt | 8 | legacy KVM_CREATE_IRQCHIP api. The created VGIC will act as the VM interrupt |
9 | controller, requiring emulated user-space devices to inject interrupts to the | 9 | controller, requiring emulated user-space devices to inject interrupts to the |
10 | VGIC instead of directly to CPUs. | 10 | VGIC instead of directly to CPUs. |
11 | |||
12 | Groups: | ||
13 | KVM_DEV_ARM_VGIC_GRP_ADDR | ||
14 | Attributes: | ||
15 | KVM_VGIC_V2_ADDR_TYPE_DIST (rw, 64-bit) | ||
16 | Base address in the guest physical address space of the GIC distributor | ||
17 | register mappings. | ||
18 | |||
19 | KVM_VGIC_V2_ADDR_TYPE_CPU (rw, 64-bit) | ||
20 | Base address in the guest physical address space of the GIC virtual cpu | ||
21 | interface register mappings. | ||
diff --git a/arch/arm/include/uapi/asm/kvm.h b/arch/arm/include/uapi/asm/kvm.h index 835b8678de03..76a742769e2b 100644 --- a/arch/arm/include/uapi/asm/kvm.h +++ b/arch/arm/include/uapi/asm/kvm.h | |||
@@ -163,6 +163,8 @@ struct kvm_arch_memory_slot { | |||
163 | #define KVM_REG_ARM_VFP_FPINST 0x1009 | 163 | #define KVM_REG_ARM_VFP_FPINST 0x1009 |
164 | #define KVM_REG_ARM_VFP_FPINST2 0x100A | 164 | #define KVM_REG_ARM_VFP_FPINST2 0x100A |
165 | 165 | ||
166 | /* Device Control API: ARM VGIC */ | ||
167 | #define KVM_DEV_ARM_VGIC_GRP_ADDR 0 | ||
166 | 168 | ||
167 | /* KVM_IRQ_LINE irq field index values */ | 169 | /* KVM_IRQ_LINE irq field index values */ |
168 | #define KVM_ARM_IRQ_TYPE_SHIFT 24 | 170 | #define KVM_ARM_IRQ_TYPE_SHIFT 24 |
diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index cc7c41af9c38..f290b2250ed5 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c | |||
@@ -776,7 +776,7 @@ static int kvm_vm_ioctl_set_device_addr(struct kvm *kvm, | |||
776 | case KVM_ARM_DEVICE_VGIC_V2: | 776 | case KVM_ARM_DEVICE_VGIC_V2: |
777 | if (!vgic_present) | 777 | if (!vgic_present) |
778 | return -ENXIO; | 778 | return -ENXIO; |
779 | return kvm_vgic_set_addr(kvm, type, dev_addr->addr); | 779 | return kvm_vgic_addr(kvm, type, &dev_addr->addr, true); |
780 | default: | 780 | default: |
781 | return -ENODEV; | 781 | return -ENODEV; |
782 | } | 782 | } |
diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h index 7e2d15837b02..be85127bfed3 100644 --- a/include/kvm/arm_vgic.h +++ b/include/kvm/arm_vgic.h | |||
@@ -144,7 +144,7 @@ struct kvm_run; | |||
144 | struct kvm_exit_mmio; | 144 | struct kvm_exit_mmio; |
145 | 145 | ||
146 | #ifdef CONFIG_KVM_ARM_VGIC | 146 | #ifdef CONFIG_KVM_ARM_VGIC |
147 | int kvm_vgic_set_addr(struct kvm *kvm, unsigned long type, u64 addr); | 147 | int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write); |
148 | int kvm_vgic_hyp_init(void); | 148 | int kvm_vgic_hyp_init(void); |
149 | int kvm_vgic_init(struct kvm *kvm); | 149 | int kvm_vgic_init(struct kvm *kvm); |
150 | int kvm_vgic_create(struct kvm *kvm); | 150 | int kvm_vgic_create(struct kvm *kvm); |
diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c index b15d6c17a090..45db48de4282 100644 --- a/virt/kvm/arm/vgic.c +++ b/virt/kvm/arm/vgic.c | |||
@@ -1495,6 +1495,12 @@ static int vgic_ioaddr_assign(struct kvm *kvm, phys_addr_t *ioaddr, | |||
1495 | { | 1495 | { |
1496 | int ret; | 1496 | int ret; |
1497 | 1497 | ||
1498 | if (addr & ~KVM_PHYS_MASK) | ||
1499 | return -E2BIG; | ||
1500 | |||
1501 | if (addr & (SZ_4K - 1)) | ||
1502 | return -EINVAL; | ||
1503 | |||
1498 | if (!IS_VGIC_ADDR_UNDEF(*ioaddr)) | 1504 | if (!IS_VGIC_ADDR_UNDEF(*ioaddr)) |
1499 | return -EEXIST; | 1505 | return -EEXIST; |
1500 | if (addr + size < addr) | 1506 | if (addr + size < addr) |
@@ -1507,26 +1513,41 @@ static int vgic_ioaddr_assign(struct kvm *kvm, phys_addr_t *ioaddr, | |||
1507 | return ret; | 1513 | return ret; |
1508 | } | 1514 | } |
1509 | 1515 | ||
1510 | int kvm_vgic_set_addr(struct kvm *kvm, unsigned long type, u64 addr) | 1516 | /** |
1517 | * kvm_vgic_addr - set or get vgic VM base addresses | ||
1518 | * @kvm: pointer to the vm struct | ||
1519 | * @type: the VGIC addr type, one of KVM_VGIC_V2_ADDR_TYPE_XXX | ||
1520 | * @addr: pointer to address value | ||
1521 | * @write: if true set the address in the VM address space, if false read the | ||
1522 | * address | ||
1523 | * | ||
1524 | * Set or get the vgic base addresses for the distributor and the virtual CPU | ||
1525 | * interface in the VM physical address space. These addresses are properties | ||
1526 | * of the emulated core/SoC and therefore user space initially knows this | ||
1527 | * information. | ||
1528 | */ | ||
1529 | int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write) | ||
1511 | { | 1530 | { |
1512 | int r = 0; | 1531 | int r = 0; |
1513 | struct vgic_dist *vgic = &kvm->arch.vgic; | 1532 | struct vgic_dist *vgic = &kvm->arch.vgic; |
1514 | 1533 | ||
1515 | if (addr & ~KVM_PHYS_MASK) | ||
1516 | return -E2BIG; | ||
1517 | |||
1518 | if (addr & (SZ_4K - 1)) | ||
1519 | return -EINVAL; | ||
1520 | |||
1521 | mutex_lock(&kvm->lock); | 1534 | mutex_lock(&kvm->lock); |
1522 | switch (type) { | 1535 | switch (type) { |
1523 | case KVM_VGIC_V2_ADDR_TYPE_DIST: | 1536 | case KVM_VGIC_V2_ADDR_TYPE_DIST: |
1524 | r = vgic_ioaddr_assign(kvm, &vgic->vgic_dist_base, | 1537 | if (write) { |
1525 | addr, KVM_VGIC_V2_DIST_SIZE); | 1538 | r = vgic_ioaddr_assign(kvm, &vgic->vgic_dist_base, |
1539 | *addr, KVM_VGIC_V2_DIST_SIZE); | ||
1540 | } else { | ||
1541 | *addr = vgic->vgic_dist_base; | ||
1542 | } | ||
1526 | break; | 1543 | break; |
1527 | case KVM_VGIC_V2_ADDR_TYPE_CPU: | 1544 | case KVM_VGIC_V2_ADDR_TYPE_CPU: |
1528 | r = vgic_ioaddr_assign(kvm, &vgic->vgic_cpu_base, | 1545 | if (write) { |
1529 | addr, KVM_VGIC_V2_CPU_SIZE); | 1546 | r = vgic_ioaddr_assign(kvm, &vgic->vgic_cpu_base, |
1547 | *addr, KVM_VGIC_V2_CPU_SIZE); | ||
1548 | } else { | ||
1549 | *addr = vgic->vgic_cpu_base; | ||
1550 | } | ||
1530 | break; | 1551 | break; |
1531 | default: | 1552 | default: |
1532 | r = -ENODEV; | 1553 | r = -ENODEV; |
@@ -1538,16 +1559,58 @@ int kvm_vgic_set_addr(struct kvm *kvm, unsigned long type, u64 addr) | |||
1538 | 1559 | ||
1539 | static int vgic_set_attr(struct kvm_device *dev, struct kvm_device_attr *attr) | 1560 | static int vgic_set_attr(struct kvm_device *dev, struct kvm_device_attr *attr) |
1540 | { | 1561 | { |
1562 | int r; | ||
1563 | |||
1564 | switch (attr->group) { | ||
1565 | case KVM_DEV_ARM_VGIC_GRP_ADDR: { | ||
1566 | u64 __user *uaddr = (u64 __user *)(long)attr->addr; | ||
1567 | u64 addr; | ||
1568 | unsigned long type = (unsigned long)attr->attr; | ||
1569 | |||
1570 | if (copy_from_user(&addr, uaddr, sizeof(addr))) | ||
1571 | return -EFAULT; | ||
1572 | |||
1573 | r = kvm_vgic_addr(dev->kvm, type, &addr, true); | ||
1574 | return (r == -ENODEV) ? -ENXIO : r; | ||
1575 | } | ||
1576 | } | ||
1577 | |||
1541 | return -ENXIO; | 1578 | return -ENXIO; |
1542 | } | 1579 | } |
1543 | 1580 | ||
1544 | static int vgic_get_attr(struct kvm_device *dev, struct kvm_device_attr *attr) | 1581 | static int vgic_get_attr(struct kvm_device *dev, struct kvm_device_attr *attr) |
1545 | { | 1582 | { |
1546 | return -ENXIO; | 1583 | int r = -ENXIO; |
1584 | |||
1585 | switch (attr->group) { | ||
1586 | case KVM_DEV_ARM_VGIC_GRP_ADDR: { | ||
1587 | u64 __user *uaddr = (u64 __user *)(long)attr->addr; | ||
1588 | u64 addr; | ||
1589 | unsigned long type = (unsigned long)attr->attr; | ||
1590 | |||
1591 | r = kvm_vgic_addr(dev->kvm, type, &addr, false); | ||
1592 | if (r) | ||
1593 | return (r == -ENODEV) ? -ENXIO : r; | ||
1594 | |||
1595 | if (copy_to_user(uaddr, &addr, sizeof(addr))) | ||
1596 | return -EFAULT; | ||
1597 | } | ||
1598 | } | ||
1599 | |||
1600 | return r; | ||
1547 | } | 1601 | } |
1548 | 1602 | ||
1549 | static int vgic_has_attr(struct kvm_device *dev, struct kvm_device_attr *attr) | 1603 | static int vgic_has_attr(struct kvm_device *dev, struct kvm_device_attr *attr) |
1550 | { | 1604 | { |
1605 | switch (attr->group) { | ||
1606 | case KVM_DEV_ARM_VGIC_GRP_ADDR: | ||
1607 | switch (attr->attr) { | ||
1608 | case KVM_VGIC_V2_ADDR_TYPE_DIST: | ||
1609 | case KVM_VGIC_V2_ADDR_TYPE_CPU: | ||
1610 | return 0; | ||
1611 | } | ||
1612 | break; | ||
1613 | } | ||
1551 | return -ENXIO; | 1614 | return -ENXIO; |
1552 | } | 1615 | } |
1553 | 1616 | ||