aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Graf <agraf@suse.de>2011-09-14 04:02:41 -0400
committerAvi Kivity <avi@redhat.com>2012-03-05 07:52:40 -0500
commite24ed81fedd551e80378be62fa0b0532480ea7d4 (patch)
tree254bcf7fbe858bc75087432667c7409e58b35575
parent6b75e6bfef7ba108ac3df0d430d80dea68fde4bf (diff)
KVM: PPC: Add generic single register ioctls
Right now we transfer a static struct every time we want to get or set registers. Unfortunately, over time we realize that there are more of these than we thought of before and the extensibility and flexibility of transferring a full struct every time is limited. So this is a new approach to the problem. With these new ioctls, we can get and set a single register that is identified by an ID. This allows for very precise and limited transmittal of data. When we later realize that it's a better idea to shove over multiple registers at once, we can reuse most of the infrastructure and simply implement a GET_MANY_REGS / SET_MANY_REGS interface. Signed-off-by: Alexander Graf <agraf@suse.de> Signed-off-by: Avi Kivity <avi@redhat.com>
-rw-r--r--Documentation/virtual/kvm/api.txt46
-rw-r--r--arch/powerpc/kvm/powerpc.c41
-rw-r--r--include/linux/kvm.h35
3 files changed, 119 insertions, 3 deletions
diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt
index bcd45d5afcab..e0c75dcb2ca3 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -1533,7 +1533,7 @@ following algorithm:
1533Some guests configure the LINT1 NMI input to cause a panic, aiding in 1533Some guests configure the LINT1 NMI input to cause a panic, aiding in
1534debugging. 1534debugging.
1535 1535
15364.64 KVM_S390_UCAS_MAP 15364.65 KVM_S390_UCAS_MAP
1537 1537
1538Capability: KVM_CAP_S390_UCONTROL 1538Capability: KVM_CAP_S390_UCONTROL
1539Architectures: s390 1539Architectures: s390
@@ -1552,7 +1552,7 @@ This ioctl maps the memory at "user_addr" with the length "length" to
1552the vcpu's address space starting at "vcpu_addr". All parameters need to 1552the vcpu's address space starting at "vcpu_addr". All parameters need to
1553be alligned by 1 megabyte. 1553be alligned by 1 megabyte.
1554 1554
15554.65 KVM_S390_UCAS_UNMAP 15554.66 KVM_S390_UCAS_UNMAP
1556 1556
1557Capability: KVM_CAP_S390_UCONTROL 1557Capability: KVM_CAP_S390_UCONTROL
1558Architectures: s390 1558Architectures: s390
@@ -1571,7 +1571,7 @@ This ioctl unmaps the memory in the vcpu's address space starting at
1571"vcpu_addr" with the length "length". The field "user_addr" is ignored. 1571"vcpu_addr" with the length "length". The field "user_addr" is ignored.
1572All parameters need to be alligned by 1 megabyte. 1572All parameters need to be alligned by 1 megabyte.
1573 1573
15744.66 KVM_S390_VCPU_FAULT 15744.67 KVM_S390_VCPU_FAULT
1575 1575
1576Capability: KVM_CAP_S390_UCONTROL 1576Capability: KVM_CAP_S390_UCONTROL
1577Architectures: s390 1577Architectures: s390
@@ -1587,6 +1587,46 @@ table upfront. This is useful to handle validity intercepts for user
1587controlled virtual machines to fault in the virtual cpu's lowcore pages 1587controlled virtual machines to fault in the virtual cpu's lowcore pages
1588prior to calling the KVM_RUN ioctl. 1588prior to calling the KVM_RUN ioctl.
1589 1589
15904.68 KVM_SET_ONE_REG
1591
1592Capability: KVM_CAP_ONE_REG
1593Architectures: all
1594Type: vcpu ioctl
1595Parameters: struct kvm_one_reg (in)
1596Returns: 0 on success, negative value on failure
1597
1598struct kvm_one_reg {
1599 __u64 id;
1600 __u64 addr;
1601};
1602
1603Using this ioctl, a single vcpu register can be set to a specific value
1604defined by user space with the passed in struct kvm_one_reg, where id
1605refers to the register identifier as described below and addr is a pointer
1606to a variable with the respective size. There can be architecture agnostic
1607and architecture specific registers. Each have their own range of operation
1608and their own constants and width. To keep track of the implemented
1609registers, find a list below:
1610
1611 Arch | Register | Width (bits)
1612 | |
1613
16144.69 KVM_GET_ONE_REG
1615
1616Capability: KVM_CAP_ONE_REG
1617Architectures: all
1618Type: vcpu ioctl
1619Parameters: struct kvm_one_reg (in and out)
1620Returns: 0 on success, negative value on failure
1621
1622This ioctl allows to receive the value of a single register implemented
1623in a vcpu. The register to read is indicated by the "id" field of the
1624kvm_one_reg struct passed in. On success, the register value can be found
1625at the memory location pointed to by "addr".
1626
1627The list of registers accessible using this interface is identical to the
1628list in 4.64.
1629
15905. The kvm_run structure 16305. The kvm_run structure
1591 1631
1592Application code obtains a pointer to the kvm_run structure by 1632Application code obtains a pointer to the kvm_run structure by
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index f4380cb264e0..089c61bf0e16 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -217,6 +217,7 @@ int kvm_dev_ioctl_check_extension(long ext)
217 case KVM_CAP_PPC_UNSET_IRQ: 217 case KVM_CAP_PPC_UNSET_IRQ:
218 case KVM_CAP_PPC_IRQ_LEVEL: 218 case KVM_CAP_PPC_IRQ_LEVEL:
219 case KVM_CAP_ENABLE_CAP: 219 case KVM_CAP_ENABLE_CAP:
220 case KVM_CAP_ONE_REG:
220 r = 1; 221 r = 1;
221 break; 222 break;
222#ifndef CONFIG_KVM_BOOK3S_64_HV 223#ifndef CONFIG_KVM_BOOK3S_64_HV
@@ -645,6 +646,32 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
645 return r; 646 return r;
646} 647}
647 648
649static int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu,
650 struct kvm_one_reg *reg)
651{
652 int r = -EINVAL;
653
654 switch (reg->id) {
655 default:
656 break;
657 }
658
659 return r;
660}
661
662static int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu,
663 struct kvm_one_reg *reg)
664{
665 int r = -EINVAL;
666
667 switch (reg->id) {
668 default:
669 break;
670 }
671
672 return r;
673}
674
648int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu, 675int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu,
649 struct kvm_mp_state *mp_state) 676 struct kvm_mp_state *mp_state)
650{ 677{
@@ -684,6 +711,20 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
684 break; 711 break;
685 } 712 }
686 713
714 case KVM_SET_ONE_REG:
715 case KVM_GET_ONE_REG:
716 {
717 struct kvm_one_reg reg;
718 r = -EFAULT;
719 if (copy_from_user(&reg, argp, sizeof(reg)))
720 goto out;
721 if (ioctl == KVM_SET_ONE_REG)
722 r = kvm_vcpu_ioctl_set_one_reg(vcpu, &reg);
723 else
724 r = kvm_vcpu_ioctl_get_one_reg(vcpu, &reg);
725 break;
726 }
727
687#ifdef CONFIG_KVM_E500 728#ifdef CONFIG_KVM_E500
688 case KVM_DIRTY_TLB: { 729 case KVM_DIRTY_TLB: {
689 struct kvm_dirty_tlb dirty; 730 struct kvm_dirty_tlb dirty;
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index fa029ced4bd5..4f7a9fb8ab06 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -582,6 +582,7 @@ struct kvm_ppc_pvinfo {
582#define KVM_CAP_MAX_VCPUS 66 /* returns max vcpus per vm */ 582#define KVM_CAP_MAX_VCPUS 66 /* returns max vcpus per vm */
583#define KVM_CAP_PPC_PAPR 68 583#define KVM_CAP_PPC_PAPR 68
584#define KVM_CAP_SW_TLB 69 584#define KVM_CAP_SW_TLB 69
585#define KVM_CAP_ONE_REG 70
585#define KVM_CAP_S390_GMAP 71 586#define KVM_CAP_S390_GMAP 71
586#define KVM_CAP_TSC_DEADLINE_TIMER 72 587#define KVM_CAP_TSC_DEADLINE_TIMER 72
587#define KVM_CAP_S390_UCONTROL 73 588#define KVM_CAP_S390_UCONTROL 73
@@ -680,6 +681,37 @@ struct kvm_dirty_tlb {
680 __u32 num_dirty; 681 __u32 num_dirty;
681}; 682};
682 683
684/* Available with KVM_CAP_ONE_REG */
685
686#define KVM_REG_ARCH_MASK 0xff00000000000000ULL
687#define KVM_REG_GENERIC 0x0000000000000000ULL
688
689/*
690 * Architecture specific registers are to be defined in arch headers and
691 * ORed with the arch identifier.
692 */
693#define KVM_REG_PPC 0x1000000000000000ULL
694#define KVM_REG_X86 0x2000000000000000ULL
695#define KVM_REG_IA64 0x3000000000000000ULL
696#define KVM_REG_ARM 0x4000000000000000ULL
697#define KVM_REG_S390 0x5000000000000000ULL
698
699#define KVM_REG_SIZE_SHIFT 52
700#define KVM_REG_SIZE_MASK 0x00f0000000000000ULL
701#define KVM_REG_SIZE_U8 0x0000000000000000ULL
702#define KVM_REG_SIZE_U16 0x0010000000000000ULL
703#define KVM_REG_SIZE_U32 0x0020000000000000ULL
704#define KVM_REG_SIZE_U64 0x0030000000000000ULL
705#define KVM_REG_SIZE_U128 0x0040000000000000ULL
706#define KVM_REG_SIZE_U256 0x0050000000000000ULL
707#define KVM_REG_SIZE_U512 0x0060000000000000ULL
708#define KVM_REG_SIZE_U1024 0x0070000000000000ULL
709
710struct kvm_one_reg {
711 __u64 id;
712 __u64 addr;
713};
714
683/* 715/*
684 * ioctls for VM fds 716 * ioctls for VM fds
685 */ 717 */
@@ -819,6 +851,9 @@ struct kvm_s390_ucas_mapping {
819#define KVM_ALLOCATE_RMA _IOR(KVMIO, 0xa9, struct kvm_allocate_rma) 851#define KVM_ALLOCATE_RMA _IOR(KVMIO, 0xa9, struct kvm_allocate_rma)
820/* Available with KVM_CAP_SW_TLB */ 852/* Available with KVM_CAP_SW_TLB */
821#define KVM_DIRTY_TLB _IOW(KVMIO, 0xaa, struct kvm_dirty_tlb) 853#define KVM_DIRTY_TLB _IOW(KVMIO, 0xaa, struct kvm_dirty_tlb)
854/* Available with KVM_CAP_ONE_REG */
855#define KVM_GET_ONE_REG _IOW(KVMIO, 0xab, struct kvm_one_reg)
856#define KVM_SET_ONE_REG _IOW(KVMIO, 0xac, struct kvm_one_reg)
822 857
823#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0) 858#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
824 859