KVM: PPC: HIOR and sregs fixup
Subsystems (4)
cover KVM: PPC: HIOR and sregs fixup
While working on the HIOR setting which already made it into Avi's tree, I was too uncautious and ended up extending the sregs structure, breaking ABI compatibility with all QEMU versions.
So the approach I was taking there was obvious wrong. Instead, what I thought might be a better alternative is to get rid of the static "we have a struct full of registers and shove it left and right" and instead just poke registers directly between kernel and user space. That sounds slow for starters, but once we have the infrastructure in place, we can build a batched version of the same interface and be fast again but maintain flexibility.
This interface can also for example be used to easily fetch the next great extension of SSE registers or some MSRs that we haven't thought of or lots of PPC registers I haven't even heard of so far :). There always seem to be new ones to learn of out there.
Please take a look at the interface and comment on whether you like it this way or not. It's currently only implemented for the PPC target, but is held generically, so everyone can use it.
Oh and - it obviously implements HIOR again which we have to drop from sregs due to the ABI breakage.
Alex
Alexander Graf (3):
Revert "KVM: PPC: Add support for explicit HIOR setting"
KVM: PPC: Add generic single register ioctls
KVM: PPC: Add support for explicit HIOR setting
Documentation/virtual/kvm/api.txt | 48 ++++++++++++++++++++++++ arch/powerpc/include/asm/kvm.h | 10 +---- arch/powerpc/include/asm/kvm_book3s.h | 2 +- arch/powerpc/kvm/book3s_pr.c | 12 +----- arch/powerpc/kvm/powerpc.c | 64 +++++++++++++++++++++++++++++++++ include/linux/kvm.h | 32 ++++++++++++++++ 6 files changed, 149 insertions(+), 19 deletions(-)
PATCH 1/3 Revert "KVM: PPC: Add support for explicit HIOR setting"
This reverts commit 11d7596e18a712dc3bc29d45662ec111fd65946b. It exceeded the padding on the SREGS struct, rendering the ABI backwards-incompatible.
--- arch/powerpc/include/asm/kvm.h | 8 -------- arch/powerpc/include/asm/kvm_book3s.h | 2 -- arch/powerpc/kvm/book3s_pr.c | 14 ++------------ arch/powerpc/kvm/powerpc.c | 1 - include/linux/kvm.h | 1 - 5 files changed, 2 insertions(+), 24 deletions(-)
arch/powerpc/include/asm/kvm.h +0 -8
@@ -149,12 +149,6 @@ struct kvm_regs {#define KVM_SREGS_E_UPDATE_DBSR (1 << 3)/* -* Book3S special bits to indicate contents in the struct by maintaining -* backwards compatibility with older structs. If adding a new field, -* please make sure to add a flag for that new field */ -#define KVM_SREGS_S_HIOR (1 << 0) - -/* * In KVM_SET_SREGS, reserved/pad fields must be left untouched from a * previous KVM_GET_REGS. *
@@ -179,8 +173,6 @@ struct kvm_sregs {__u64 ibat[8 ];__u64 dbat[8 ]; } ppc32; -__u64 flags;/* KVM_SREGS_S_ */ -__u64 hior; } s; struct { union {
arch/powerpc/include/asm/kvm_book3s.h +0 -2
@@ -90,8 +90,6 @@ struct kvmppc_vcpu_book3s {#endif int context_id[SID_CONTEXTS ]; -bool hior_sregs;/* HIOR is set by SREGS, not PVR */ -struct hlist_head hpte_hash_pte[HPTEG_HASH_NUM_PTE ];struct hlist_head hpte_hash_pte_long[HPTEG_HASH_NUM_PTE_LONG ];struct hlist_head hpte_hash_vpte[HPTEG_HASH_NUM_VPTE ];
arch/powerpc/kvm/book3s_pr.c +2 -12
@@ -150,16 +150,14 @@ void kvmppc_set_pvr(struct kvm_vcpu *vcpu, u32 pvr)#ifdef CONFIG_PPC_BOOK3S_64 if ((pvr >=0x330000 ) && (pvr <0x70330000 )) {kvmppc_mmu_book3s_64_init (vcpu); -if (!to_book3s (vcpu)->hior_sregs) -to_book3s (vcpu)->hior =0xfff00000 ; +to_book3s (vcpu)->hior =0xfff00000 ;to_book3s (vcpu)->msr_mask =0xffffffffffffffffULL ; vcpu->arch.cpu_type =KVM_CPU_3S_64 ; } else#endif {kvmppc_mmu_book3s_32_init (vcpu); -if (!to_book3s (vcpu)->hior_sregs) -to_book3s (vcpu)->hior =0 ; +to_book3s (vcpu)->hior =0 ;to_book3s (vcpu)->msr_mask =0xffffffffULL ; vcpu->arch.cpu_type =KVM_CPU_3S_32 ; }
@@ -796,9 +794,6 @@ int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, } } -if (sregs->u.s.flags &KVM_SREGS_S_HIOR ) - sregs->u.s.hior =to_book3s (vcpu)->hior; -return 0 ; }
@@ -835,11 +830,6 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,/* Flush the MMU after messing with the segments */ kvmppc_mmu_pte_flush (vcpu,0 ,0 ); -if (sregs->u.s.flags &KVM_SREGS_S_HIOR ) { -to_book3s (vcpu)->hior_sregs = true; -to_book3s (vcpu)->hior = sregs->u.s.hior; - } -return 0 ; }
arch/powerpc/kvm/powerpc.c +0 -1
@@ -209,7 +209,6 @@ int kvm_dev_ioctl_check_extension(long ext)case KVM_CAP_PPC_BOOKE_SREGS :#else case KVM_CAP_PPC_SEGSTATE : -case KVM_CAP_PPC_HIOR :case KVM_CAP_PPC_PAPR :#endif case KVM_CAP_PPC_UNSET_IRQ :
include/linux/kvm.h +0 -1
@@ -554,7 +554,6 @@ struct kvm_ppc_pvinfo {#define KVM_CAP_PPC_SMT 64#define KVM_CAP_PPC_RMA 65#define KVM_CAP_MAX_VCPUS 66/* returns max vcpus per vm */ -#define KVM_CAP_PPC_HIOR 67#define KVM_CAP_PPC_PAPR 68#define KVM_CAP_SW_TLB 69
Signature · 1 line
1.6.0.2
PATCH 2/3 KVM: PPC: Add generic single register ioctls
In reply to Alexander GrafRight 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.
The only downpoint I see to this one is that it needs to pad to 1024 bits (hardware is already on 512 bit registers, so I wanted to leave some room) which is slightly too much for transmitting only 64 bits. But if that's all the tradeoff we have to do for getting an extensible interface, I'd say go for it nevertheless.
--- Documentation/virtual/kvm/api.txt | 47 ++++++++++++++++++++++++++++++++++ arch/powerpc/kvm/powerpc.c | 51 +++++++++++++++++++++++++++++++++++++ include/linux/kvm.h | 32 +++++++++++++++++++++++ 3 files changed, 130 insertions(+), 0 deletions(-)
Documentation/virtual/kvm/api.txt +47 -0
@@ -1482,6 +1482,53 @@ is supported; 2 if the processor requires all virtual machines to have an RMA, or 1 if the processor can use an RMA but doesn't require it, because it supports the Virtual RMA (VRMA) facility. +4.64 KVM_SET_ONE_REG + +Capability: KVM_CAP_ONE_REG +Architectures: all +Type: vcpu ioctl +Parameters: struct kvm_one_reg (in) +Returns: 0 on success, negative value on failure + +struct kvm_one_reg { + __u64 id; + union { + __u8 reg8; + __u16 reg16; + __u32 reg32; + __u64 reg64; + __u8 reg128[16]; + __u8 reg256[32]; + __u8 reg512[64]; + __u8 reg1024[128]; + } u; +}; + +Using this ioctl, a single vcpu register can be set to a specific value +defined by user space with the passed in struct kvm_one_reg. There can +be architecture agnostic and architecture specific registers. Each have +their own range of operation and their own constants and width. To keep +track of the implemented registers, find a list below: + + Arch | Register | Width (bits) + | | + +4.65 KVM_GET_ONE_REG + +Capability: KVM_CAP_ONE_REG +Architectures: all +Type: vcpu ioctl +Parameters: struct kvm_one_reg (in and out) +Returns: 0 on success, negative value on failure + +This ioctl allows to receive the value of a single register implemented +in a vcpu. The register to read is indicated by the "id" field of the +kvm_one_reg struct passed in. On success, the register value can be found +in the respective width field of the struct after this call. + +The list of registers accessible using this interface is identical to the +list in 4.64. + 5. The kvm_run structure Application code obtains a pointer to the kvm_run structure by
arch/powerpc/kvm/powerpc.c +51 -0
69 lines not on this page · raw message
include/linux/kvm.h +32 -0
@@ -556,6 +556,7 @@ struct kvm_ppc_pvinfo {#define KVM_CAP_MAX_VCPUS 66/* returns max vcpus per vm */ #define KVM_CAP_PPC_PAPR 68#define KVM_CAP_SW_TLB 69 +#define KVM_CAP_ONE_REG 70#ifdef KVM_CAP_IRQ_ROUTING
@@ -650,6 +651,34 @@ struct kvm_dirty_tlb {__u32 num_dirty; }; +/* Available with KVM_CAP_ONE_REG */ + +#define KVM_ONE_REG_GENERIC 0x0000000000000000ULL + +/* +* Architecture specific registers are to be defined in arch headers and +* ORed with the arch identifier. +*/ +#define KVM_ONE_REG_PPC 0x1000000000000000ULL +#define KVM_ONE_REG_X86 0x2000000000000000ULL +#define KVM_ONE_REG_IA64 0x3000000000000000ULL +#define KVM_ONE_REG_ARM 0x4000000000000000ULL +#define KVM_ONE_REG_S390 0x5000000000000000ULL + +struct kvm_one_reg { +__u64 id; +union { +__u8 reg8; +__u16 reg16; +__u32 reg32; +__u64 reg64; +__u8 reg128[16 ]; +__u8 reg256[32 ]; +__u8 reg512[64 ]; +__u8 reg1024[128 ]; + } u; +}; +/* * ioctls for VM fds */
@@ -778,6 +807,9 @@ struct kvm_dirty_tlb {#define KVM_ALLOCATE_RMA _IOR(KVMIO, 0xa9, struct kvm_allocate_rma)/* Available with KVM_CAP_SW_TLB */ #define KVM_DIRTY_TLB _IOW(KVMIO, 0xaa, struct kvm_dirty_tlb) +/* Available with KVM_CAP_ONE_REG */ +#define KVM_GET_ONE_REG _IOWR(KVMIO, 0xab, struct kvm_one_reg) +#define KVM_SET_ONE_REG _IOW(KVMIO, 0xac, struct kvm_one_reg)#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
Signature · 1 line
1.6.0.2
PATCH 3/3 KVM: PPC: Add support for explicit HIOR setting
In reply to Alexander GrafUntil now, we always set HIOR based on the PVR, but this is just wrong. Instead, we should be setting HIOR explicitly, so user space can decide what the initial HIOR value is - just like on real hardware.
We keep the old PVR based way around for backwards compatibility, but once user space uses the SET_ONE_REG based method, we drop the PVR logic.
--- Documentation/virtual/kvm/api.txt | 1 + arch/powerpc/include/asm/kvm.h | 2 ++ arch/powerpc/include/asm/kvm_book3s.h | 2 ++ arch/powerpc/kvm/book3s_pr.c | 6 ++++-- arch/powerpc/kvm/powerpc.c | 14 ++++++++++++++ include/linux/kvm.h | 1 + 6 files changed, 24 insertions(+), 2 deletions(-)
Documentation/virtual/kvm/api.txt +1 -0
@@ -1512,6 +1512,7 @@ track of the implemented registers, find a list below: Arch | Register | Width (bits) | | + PPC | KVM_ONE_REG_PPC_HIOR | 64 4.65 KVM_GET_ONE_REG
arch/powerpc/include/asm/kvm.h +2 -0
@@ -327,4 +327,6 @@ struct kvm_book3e_206_tlb_params { __u32 reserved[8]; }; +#define KVM_ONE_REG_PPC_HIOR KVM_ONE_REG_PPC | 0x100 +#endif /* __LINUX_KVM_POWERPC_H */
arch/powerpc/include/asm/kvm_book3s.h +2 -0
@@ -90,6 +90,8 @@ struct kvmppc_vcpu_book3s {#endif int context_id[SID_CONTEXTS ]; +bool hior_explicit;/* HIOR is set by ioctl, not PVR */ +struct hlist_head hpte_hash_pte[HPTEG_HASH_NUM_PTE ];struct hlist_head hpte_hash_pte_long[HPTEG_HASH_NUM_PTE_LONG ];struct hlist_head hpte_hash_vpte[HPTEG_HASH_NUM_VPTE ];
arch/powerpc/kvm/book3s_pr.c +4 -2
@@ -150,14 +150,16 @@ void kvmppc_set_pvr(struct kvm_vcpu *vcpu, u32 pvr)#ifdef CONFIG_PPC_BOOK3S_64 if ((pvr >=0x330000 ) && (pvr <0x70330000 )) {kvmppc_mmu_book3s_64_init (vcpu); -to_book3s (vcpu)->hior =0xfff00000 ; +if (!to_book3s (vcpu)->hior_explicit) +to_book3s (vcpu)->hior =0xfff00000 ;to_book3s (vcpu)->msr_mask =0xffffffffffffffffULL ; vcpu->arch.cpu_type =KVM_CPU_3S_64 ; } else#endif {kvmppc_mmu_book3s_32_init (vcpu); -to_book3s (vcpu)->hior =0 ; +if (!to_book3s (vcpu)->hior_explicit) +to_book3s (vcpu)->hior =0 ;to_book3s (vcpu)->msr_mask =0xffffffffULL ; vcpu->arch.cpu_type =KVM_CPU_3S_32 ; }
arch/powerpc/kvm/powerpc.c +14 -0
@@ -209,6 +209,7 @@ int kvm_dev_ioctl_check_extension(long ext)case KVM_CAP_PPC_BOOKE_SREGS :#else case KVM_CAP_PPC_SEGSTATE : +case KVM_CAP_PPC_HIOR :case KVM_CAP_PPC_PAPR :#endif case KVM_CAP_PPC_UNSET_IRQ :
@@ -634,6 +635,12 @@ static int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu,int r = -EINVAL ;switch (reg->id) { +#ifdef CONFIG_PPC_BOOK3S +case KVM_ONE_REG_PPC_HIOR : + reg->u.reg64 =to_book3s (vcpu)->hior; + r =0 ; +break ; +#endif default :break ; }
@@ -647,6 +654,13 @@ static int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu,int r = -EINVAL ;switch (reg->id) { +#ifdef CONFIG_PPC_BOOK3S +case KVM_ONE_REG_PPC_HIOR : +to_book3s (vcpu)->hior = reg->u.reg64; +to_book3s (vcpu)->hior_explicit = true; + r =0 ; +break ; +#endif default :break ; }
include/linux/kvm.h +1 -0
@@ -554,6 +554,7 @@ struct kvm_ppc_pvinfo {#define KVM_CAP_PPC_SMT 64#define KVM_CAP_PPC_RMA 65#define KVM_CAP_MAX_VCPUS 66/* returns max vcpus per vm */ +#define KVM_CAP_PPC_HIOR 67#define KVM_CAP_PPC_PAPR 68#define KVM_CAP_SW_TLB 69#define KVM_CAP_ONE_REG 70
Signature · 1 line
1.6.0.2