PPC: Current patch queue for HV KVM
Subsystems (3)
cover PPC: Current patch queue for HV KVM
This is my current queue of patches for HV KVM. This series is based on the kvm next branch. They have all been posted 6 weeks ago or more, though I have just added a 3-line fix to patch 2/5 to fix a bug that we found in testing migration, and I expanded a comment (no code change) in patch 3/5 following a suggestion by Aneesh.
I'd like to see these go into 4.2 if possible.
Paul.
---
arch/powerpc/include/asm/kvm_book3s.h | 1 + arch/powerpc/include/asm/kvm_book3s_asm.h | 20 + arch/powerpc/include/asm/kvm_host.h | 24 +- arch/powerpc/kernel/asm-offsets.c | 9 + arch/powerpc/kvm/book3s_64_mmu_hv.c | 8 +- arch/powerpc/kvm/book3s_hv.c | 648 ++++++++++++++++++++++++++---- arch/powerpc/kvm/book3s_hv_builtin.c | 32 +- arch/powerpc/kvm/book3s_hv_rm_mmu.c | 161 +++++++- arch/powerpc/kvm/book3s_hv_rm_xics.c | 4 +- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 122 +++++- 10 files changed, 906 insertions(+), 123 deletions(-)
PATCH 1/5 KVM: PPC: Book3S HV: Make use of unused threads when running guests
When running a virtual core of a guest that is configured with fewer threads per core than the physical cores have, the extra physical threads are currently unused. This makes it possible to use them to run one or more other virtual cores from the same guest when certain conditions are met. This applies on POWER7, and on POWER8 to guests with one thread per virtual core. (It doesn't apply to POWER8 guests with multiple threads per vcore because they require a 1-1 virtual to physical thread mapping in order to be able to use msgsndp and the TIR.)
The idea is that we maintain a list of preempted vcores for each physical cpu (i.e. each core, since the host runs single-threaded). Then, when a vcore is about to run, it checks to see if there are any vcores on the list for its physical cpu that could be piggybacked onto this vcore's execution. If so, those additional vcores are put into state VCORE_PIGGYBACK and their runnable VCPU threads are started as well as the original vcore, which is called the master vcore.
After the vcores have exited the guest, the extra ones are put back onto the preempted list if any of their VCPUs are still runnable and not idle.
This means that vcpu->arch.ptid is no longer necessarily the same as the physical thread that the vcpu runs on. In order to make it easier for code that wants to send an IPI to know which CPU to target, we now store that in a new field in struct vcpu_arch, called thread_cpu.
--- arch/powerpc/include/asm/kvm_host.h | 19 +- arch/powerpc/kernel/asm-offsets.c | 2 + arch/powerpc/kvm/book3s_hv.c | 333 ++++++++++++++++++++++++++------ arch/powerpc/kvm/book3s_hv_builtin.c | 7 +- arch/powerpc/kvm/book3s_hv_rm_xics.c | 4 +- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 5 + 6 files changed, 298 insertions(+), 72 deletions(-)
arch/powerpc/include/asm/kvm_host.h +14 -5
@@ -278,7 +278,9 @@ struct kvmppc_vcore {u16 last_cpu;u8 vcore_state;u8 in_guest; +struct kvmppc_vcore *master_vcore;struct list_head runnable_threads; +struct list_head preempt_list;spinlock_t lock;wait_queue_head_t wq;spinlock_t stoltb_lock;/* protects stolen_tb and preempt_tb */
@@ -300,12 +302,18 @@ struct kvmppc_vcore {#define VCORE_EXIT_MAP (vc) ((vc)->entry_exit_map >> 8)#define VCORE_IS_EXITING (vc) (VCORE_EXIT_MAP(vc) != 0) -/* Values for vcore_state */ +/* +* Values for vcore_state. +* Note that these are arranged such that lower values +* (< VCORE_SLEEPING) don't require stolen time accounting +* on load/unload, and higher values do. +*/ #define VCORE_INACTIVE 0 -#define VCORE_SLEEPING 1 -#define VCORE_PREEMPT 2 -#define VCORE_RUNNING 3 -#define VCORE_EXITING 4 +#define VCORE_PREEMPT 1 +#define VCORE_PIGGYBACK 2 +#define VCORE_SLEEPING 3 +#define VCORE_RUNNING 4 +#define VCORE_EXITING 5/* * Struct used to manage memory for a virtual processor area
@@ -619,6 +627,7 @@ struct kvm_vcpu_arch {int trap;int state;int ptid; +int thread_cpu;bool timer_running;wait_queue_head_t cpu_run;
arch/powerpc/kernel/asm-offsets.c +2 -0
@@ -512,6 +512,8 @@ int main(void) DEFINE(VCPU_VPA, offsetof(struct kvm_vcpu, arch.vpa.pinned_addr)); DEFINE(VCPU_VPA_DIRTY, offsetof(struct kvm_vcpu, arch.vpa.dirty)); DEFINE(VCPU_HEIR, offsetof(struct kvm_vcpu, arch.emul_inst)); +DEFINE (VCPU_CPU , offsetof(struct kvm_vcpu , cpu)); + DEFINE(VCPU_THREAD_CPU, offsetof(struct kvm_vcpu, arch.thread_cpu));#endif #ifdef CONFIG_PPC_BOOK3S DEFINE (VCPU_VCPUID , offsetof(struct kvm_vcpu , vcpu_id));
arch/powerpc/kvm/book3s_hv.c +272 -61
521 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv_builtin.c +4 -3
@@ -110,14 +110,15 @@ void __init kvm_cma_reserve(void)long int kvmppc_rm_h_confer (struct kvm_vcpu *vcpu,int target,unsigned int yield_count) { -struct kvmppc_vcore *vc = vcpu->arch.vcore; +struct kvmppc_vcore *vc = local_paca->kvm_hstate.kvm_vcore; +int ptid = local_paca->kvm_hstate.ptid;int threads_running;int threads_ceded;int threads_conferring;u64 stop =get_tb () +10 * tb_ticks_per_usec;int rv =H_SUCCESS ;/* => don't yield */ -set_bit (vcpu->arch.ptid, &vc->conferring_threads); +set_bit (ptid, &vc->conferring_threads);while ((get_tb () < stop) && !VCORE_IS_EXITING (vc)) { threads_running =VCORE_ENTRY_MAP (vc); threads_ceded = vc->napping_threads;
@@ -127,7 +128,7 @@ long int kvmppc_rm_h_confer(struct kvm_vcpu *vcpu, int target,break ; } } -clear_bit (vcpu->arch.ptid, &vc->conferring_threads); +clear_bit (ptid, &vc->conferring_threads);return rv; }
arch/powerpc/kvm/book3s_hv_rm_xics.c +1 -3
@@ -67,14 +67,12 @@ static void icp_rm_set_vcpu_irq(struct kvm_vcpu *vcpu, }/* Check if the core is loaded, if not, too hard */ - cpu = vcpu->cpu; + cpu = vcpu->arch.thread_cpu;if (cpu <0 || cpu >= nr_cpu_ids) { this_icp->rm_action |=XICS_RM_KICK_VCPU ; this_icp->rm_kick_target = vcpu;return ; } -/* In SMT cpu will always point to thread 0, we adjust it */ - cpu += vcpu->arch.ptid;smp_mb ();kvmhv_rm_send_ipi (cpu);
arch/powerpc/kvm/book3s_hv_rmhandlers.S +5 -0
@@ -1176,6 +1176,11 @@ mc_cont: ld r9, HSTATE_KVM_VCPU(r13) lwz r12, VCPU_TRAP(r9) + /* Stop others sending VCPU interrupts to this physical CPU */ + li r0, -1 + stw r0, VCPU_CPU(r9) + stw r0, VCPU_THREAD_CPU(r9) + /* Save guest CTRL register, set runlatch to 1 */ mfspr r6,SPRN_CTRLF stw r6,VCPU_CTRL(r9)
Signature · 1 line
2.1.4
PATCH 2/5 KVM: PPC: Book3S HV: Implement dynamic micro-threading on POWER8
In reply to Paul MackerrasThis builds on the ability to run more than one vcore on a physical core by using the micro-threading (split-core) modes of the POWER8 chip. Previously, only vcores from the same VM could be run together, and (on POWER8) only if they had just one thread per core. With the ability to split the core on guest entry and unsplit it on guest exit, we can run up to 8 vcpu threads from up to 4 different VMs, and we can run multiple vcores with 2 or 4 vcpus per vcore.
Dynamic micro-threading is only available if the static configuration of the cores is whole-core mode (unsplit), and only on POWER8.
To manage this, we introduce a new kvm_split_mode struct which is shared across all of the subcores in the core, with a pointer in the paca on each thread. In addition we extend the core_info struct to have information on each subcore. When deciding whether to add a vcore to the set already on the core, we now have two possibilities:
(a) piggyback the vcore onto an existing subcore, or (b) start a new subcore.
Currently, when any vcpu needs to exit the guest and switch to host virtual mode, we interrupt all the threads in all subcores and switch the core back to whole-core mode. It may be possible in future to allow some of the subcores to keep executing in the guest while subcore 0 switches to the host, but that is not implemented in this patch.
This adds a module parameter called dynamic_mt_modes which controls which micro-threading (split-core) modes the code will consider, as a bitmap. In other words, if it is 0, no micro-threading mode is considered; if it is 2, only 2-way micro-threading is considered; if it is 4, only 4-way, and if it is 6, both 2-way and 4-way micro-threading mode will be considered. The default is 6.
With this, we now have secondary threads which are the primary thread for their subcore and therefore need to do the MMU switch. These threads will need to be started even if they have no vcpu to run, so we use the vcore pointer in the PACA rather than the vcpu pointer to trigger them.
It is now possible for thread 0 to find that an exit has been requested before it gets to switch the subcore state to the guest. In that case we haven't added the guest's timebase offset to the timebase, so we need to be careful not to subtract the offset in the guest exit path. In fact we just skip the whole path that switches back to host context, since we haven't switched to the guest context.
--- arch/powerpc/include/asm/kvm_book3s_asm.h | 20 ++ arch/powerpc/include/asm/kvm_host.h | 3 + arch/powerpc/kernel/asm-offsets.c | 7 + arch/powerpc/kvm/book3s_hv.c | 369 ++++++++++++++++++++++++++---- arch/powerpc/kvm/book3s_hv_builtin.c | 25 +- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 113 +++++++-- 6 files changed, 475 insertions(+), 62 deletions(-)
arch/powerpc/include/asm/kvm_book3s_asm.h +20 -0
@@ -25,6 +25,12 @@#define XICS_MFRR 0xc#define XICS_IPI 2/* interrupt source # for IPIs */ +/* Maximum number of threads per physical core */ +#define MAX_THREADS 8 + +/* Maximum number of subcores per physical core */ +#define MAX_SUBCORES 4 +#ifdef __ASSEMBLY__#ifdef CONFIG_KVM_BOOK3S_HANDLER
@@ -65,6 +71,19 @@ kvmppc_resume_\intno:#else /*__ASSEMBLY__ */ +struct kvmppc_vcore ; + +/* Struct used for coordinating micro-threading (split-core) mode changes */ +struct kvm_split_mode { +unsigned long rpr; +unsigned long pmmar; +unsigned long ldbar; +u8 subcore_size; +u8 do_nap; +u8 napped[MAX_THREADS ]; +struct kvmppc_vcore *master_vcs[MAX_SUBCORES ]; +}; +/* * This struct goes in the PACA on 64-bit processors. It is used * to store host state that needs to be saved when we enter a guest
@@ -100,6 +119,7 @@ struct kvmppc_host_state {u64 host_spurr;u64 host_dscr;u64 dec_expires; +struct kvm_split_mode *kvm_split_mode;#endif #ifdef CONFIG_PPC_BOOK3S_64 u64 cfar;
arch/powerpc/include/asm/kvm_host.h +3 -0
@@ -302,6 +302,9 @@ struct kvmppc_vcore {#define VCORE_EXIT_MAP (vc) ((vc)->entry_exit_map >> 8)#define VCORE_IS_EXITING (vc) (VCORE_EXIT_MAP(vc) != 0) +/* This bit is used when a vcore exit is triggered from outside the vcore */ +#define VCORE_EXIT_REQ 0x10000 +/* * Values for vcore_state. * Note that these are arranged such that lower values
arch/powerpc/kernel/asm-offsets.c +7 -0
@@ -676,7 +676,14 @@ int main(void)HSTATE_FIELD (HSTATE_DSCR , host_dscr);HSTATE_FIELD (HSTATE_DABR , dabr);HSTATE_FIELD (HSTATE_DECEXP , dec_expires); +HSTATE_FIELD (HSTATE_SPLIT_MODE , kvm_split_mode);DEFINE (IPI_PRIORITY ,IPI_PRIORITY ); +DEFINE (KVM_SPLIT_RPR , offsetof(struct kvm_split_mode , rpr)); +DEFINE (KVM_SPLIT_PMMAR , offsetof(struct kvm_split_mode , pmmar)); +DEFINE (KVM_SPLIT_LDBAR , offsetof(struct kvm_split_mode , ldbar)); +DEFINE (KVM_SPLIT_SIZE , offsetof(struct kvm_split_mode , subcore_size)); +DEFINE (KVM_SPLIT_DO_NAP , offsetof(struct kvm_split_mode , do_nap)); +DEFINE (KVM_SPLIT_NAPPED , offsetof(struct kvm_split_mode , napped));#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ #ifdef CONFIG_PPC_BOOK3S_64
arch/powerpc/kvm/book3s_hv.c +322 -46
495 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv_builtin.c +24 -1
@@ -239,7 +239,8 @@ void kvmhv_commence_exit(int trap) {struct kvmppc_vcore *vc = local_paca->kvm_hstate.kvm_vcore;int ptid = local_paca->kvm_hstate.ptid; -int me, ee; +struct kvm_split_mode *sip = local_paca->kvm_hstate.kvm_split_mode; +int me, ee, i;/* Set our bit in the threads-exiting-guest map in the 0xff00 bits of vcore->entry_exit_map */
@@ -259,4 +260,26 @@ void kvmhv_commence_exit(int trap)*/ if (trap !=BOOK3S_INTERRUPT_HV_DECREMENTER )kvmhv_interrupt_vcore (vc, ee & ~(1 << ptid)); + +/* +* If we are doing dynamic micro-threading, interrupt the other +* subcores to pull them out of their guests too. +*/ +if (!sip) +return ; + +for (i =0 ; i <MAX_SUBCORES ; ++i) { + vc = sip->master_vcs[i]; +if (!vc) +break ; +do { + ee = vc->entry_exit_map; +/* Already asked to exit? */ +if ((ee >>8 ) !=0 ) +break ; + }while (cmpxchg (&vc->entry_exit_map, ee, + ee |VCORE_EXIT_REQ ) != ee); +if ((ee >>8 ) =0 ) +kvmhv_interrupt_vcore (vc, ee); + } }
arch/powerpc/kvm/book3s_hv_rmhandlers.S +98 -15
193 lines not on this page · raw message
Signature · 1 line
2.1.4
Re: [PATCH 2/5] KVM: PPC: Book3S HV: Implement dynamic micro-threading on POWER8
Quoted 139 lines · Paul Mackerras
This builds on the ability to run more than one vcore on a physical core by using the micro-threading (split-core) modes of the POWER8 chip. Previously, only vcores from the same VM could be run together, and (on POWER8) only if they had just one thread per core. With the ability to split the core on guest entry and unsplit it on guest exit, we can run up to 8 vcpu threads from up to 4 different VMs, and we can run multiple vcores with 2 or 4 vcpus per vcore.
Dynamic micro-threading is only available if the static configuration of the cores is whole-core mode (unsplit), and only on POWER8.
To manage this, we introduce a new
kvm_split_modestruct which is shared across all of the subcores in the core, with a pointer in the paca on each thread. In addition we extend thecore_infostruct to have information on each subcore. When deciding whether to add a vcore to the set already on the core, we now have two possibilities:
(a) piggyback the vcore onto an existing subcore, or (b) start a new subcore.Currently, when any vcpu needs to exit the guest and switch to host virtual mode, we interrupt all the threads in all subcores and switch the core back to whole-core mode. It may be possible in future to allow some of the subcores to keep executing in the guest while subcore 0 switches to the host, but that is not implemented in this patch.
This adds a module parameter called
dynamic_mt_modeswhich controls which micro-threading (split-core) modes the code will consider, as a bitmap. In other words, if it is 0, no micro-threading mode is considered; if it is 2, only 2-way micro-threading is considered; if it is 4, only 4-way, and if it is 6, both 2-way and 4-way micro-threading mode will be considered. The default is 6.With this, we now have secondary threads which are the primary thread for their subcore and therefore need to do the MMU switch. These threads will need to be started even if they have no vcpu to run, so we use the vcore pointer in the PACA rather than the vcpu pointer to trigger them.
It is now possible for thread 0 to find that an exit has been requested before it gets to switch the subcore state to the guest. In that case we haven't added the guest's timebase offset to the timebase, so we need to be careful not to subtract the offset in the guest exit path. In fact we just skip the whole path that switches back to host context, since we haven't switched to the guest context.
Signed-off-by Paul Mackerras <[email protected]>--- arch/powerpc/include/asm/kvm_book3s_asm.h | 20 ++ arch/powerpc/include/asm/kvm_host.h | 3 + arch/powerpc/kernel/asm-offsets.c | 7 + arch/powerpc/kvm/book3s_hv.c | 369 ++++++++++++++++++++++++++---- arch/powerpc/kvm/book3s_hv_builtin.c | 25 +- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 113 +++++++-- 6 files changed, 475 insertions(+), 62 deletions(-)arch/powerpc/include/asm/kvm_book3s_asm.h +20
-0@@ -25,6 +25,12 @@#define XICS_MFRR 0xc#define XICS_IPI 2/* interrupt source # for IPIs */ +/* Maximum number of threads per physical core */ +#define MAX_THREADS 8 + +/* Maximum number of subcores per physical core */ +#define MAX_SUBCORES 4 +#ifdef __ASSEMBLY__#ifdef CONFIG_KVM_BOOK3S_HANDLER @@ -65,6 +71,19 @@ kvmppc_resume_\intno:#else /*__ASSEMBLY__ */ +struct kvmppc_vcore ; + +/* Struct used for coordinating micro-threading (split-core) mode changes */ +struct kvm_split_mode { +unsigned long rpr; +unsigned long pmmar; +unsigned long ldbar; +u8 subcore_size; +u8 do_nap; +u8 napped[MAX_THREADS ]; +struct kvmppc_vcore *master_vcs[MAX_SUBCORES ]; +}; +/* * This struct goes in the PACA on 64-bit processors. It is used * to store host state that needs to be saved when we enter a guest @@ -100,6 +119,7 @@ struct kvmppc_host_state {u64 host_spurr;u64 host_dscr;u64 dec_expires; +struct kvm_split_mode *kvm_split_mode;#endif #ifdef CONFIG_PPC_BOOK3S_64 u64 cfar;arch/powerpc/include/asm/kvm_host.h +3
-0@@ -302,6 +302,9 @@ struct kvmppc_vcore {#define VCORE_EXIT_MAP (vc) ((vc)->entry_exit_map >> 8)#define VCORE_IS_EXITING (vc) (VCORE_EXIT_MAP(vc) != 0) +/* This bit is used when a vcore exit is triggered from outside the vcore */ +#define VCORE_EXIT_REQ 0x10000 +/* * Values for vcore_state. * Note that these are arranged such that lower values arch/powerpc/kernel/asm-offsets.c +7
-0@@ -676,7 +676,14 @@ int main(void)HSTATE_FIELD (HSTATE_DSCR , host_dscr);HSTATE_FIELD (HSTATE_DABR , dabr);HSTATE_FIELD (HSTATE_DECEXP , dec_expires); +HSTATE_FIELD (HSTATE_SPLIT_MODE , kvm_split_mode);DEFINE (IPI_PRIORITY ,IPI_PRIORITY ); +DEFINE (KVM_SPLIT_RPR , offsetof(struct kvm_split_mode , rpr)); +DEFINE (KVM_SPLIT_PMMAR , offsetof(struct kvm_split_mode , pmmar)); +DEFINE (KVM_SPLIT_LDBAR , offsetof(struct kvm_split_mode , ldbar)); +DEFINE (KVM_SPLIT_SIZE , offsetof(struct kvm_split_mode , subcore_size)); +DEFINE (KVM_SPLIT_DO_NAP , offsetof(struct kvm_split_mode , do_nap)); +DEFINE (KVM_SPLIT_NAPPED , offsetof(struct kvm_split_mode , napped));#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ #ifdef CONFIG_PPC_BOOK3S_64 arch/powerpc/kvm/book3s_hv.c +0
-0
arch/powerpc/kvm/book3s_hv.c static DECLARE_BITMAP(default_enabled_hcalls, MAX_HCALL_OPCODE/4 + 1); · line 86
Quoted 6 lines
arch/powerpc/kvm/book3s_hv.c +3
-0@@ -81,6 +81,9 @@ static DECLARE_BITMAP(default_enabled_hcalls, MAX_HCALL_OPCODE/4 + 1);#define MPP_BUFFER_ORDER 3#endif +static int dynamic_mt_modes =6 ; +module_param (dynamic_mt_modes, int,S_IRUGO |S_IWUSR ); +MODULE_PARM_DESC (dynamic_mt_modes,"Set of allowed dynamic micro-threading modes" );
Please be more verbose here. Just list the possible choices like you do in the patch description.
Alex
PATCH v2 2/5 KVM: PPC: Book3S HV: Implement dynamic micro-threading on POWER8
In reply to Paul MackerrasThis builds on the ability to run more than one vcore on a physical core by using the micro-threading (split-core) modes of the POWER8 chip. Previously, only vcores from the same VM could be run together, and (on POWER8) only if they had just one thread per core. With the ability to split the core on guest entry and unsplit it on guest exit, we can run up to 8 vcpu threads from up to 4 different VMs, and we can run multiple vcores with 2 or 4 vcpus per vcore.
Dynamic micro-threading is only available if the static configuration of the cores is whole-core mode (unsplit), and only on POWER8.
To manage this, we introduce a new kvm_split_mode struct which is shared across all of the subcores in the core, with a pointer in the paca on each thread. In addition we extend the core_info struct to have information on each subcore. When deciding whether to add a vcore to the set already on the core, we now have two possibilities:
(a) piggyback the vcore onto an existing subcore, or (b) start a new subcore.
Currently, when any vcpu needs to exit the guest and switch to host virtual mode, we interrupt all the threads in all subcores and switch the core back to whole-core mode. It may be possible in future to allow some of the subcores to keep executing in the guest while subcore 0 switches to the host, but that is not implemented in this patch.
This adds a module parameter called dynamic_mt_modes which controls which micro-threading (split-core) modes the code will consider, as a bitmap. In other words, if it is 0, no micro-threading mode is considered; if it is 2, only 2-way micro-threading is considered; if it is 4, only 4-way, and if it is 6, both 2-way and 4-way micro-threading mode will be considered. The default is 6.
With this, we now have secondary threads which are the primary thread for their subcore and therefore need to do the MMU switch. These threads will need to be started even if they have no vcpu to run, so we use the vcore pointer in the PACA rather than the vcpu pointer to trigger them.
It is now possible for thread 0 to find that an exit has been requested before it gets to switch the subcore state to the guest. In that case we haven't added the guest's timebase offset to the timebase, so we need to be careful not to subtract the offset in the guest exit path. In fact we just skip the whole path that switches back to host context, since we haven't switched to the guest context.
---
v2: List allowed values for dynamic_mt_modes module parameter in the module parameter description.
arch/powerpc/include/asm/kvm_book3s_asm.h | 20 ++ arch/powerpc/include/asm/kvm_host.h | 3 + arch/powerpc/kernel/asm-offsets.c | 7 + arch/powerpc/kvm/book3s_hv.c | 369 ++++++++++++++++++++++++++---- arch/powerpc/kvm/book3s_hv_builtin.c | 25 +- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 113 +++++++-- 6 files changed, 475 insertions(+), 62 deletions(-)
arch/powerpc/include/asm/kvm_book3s_asm.h +20 -0
@@ -25,6 +25,12 @@#define XICS_MFRR 0xc#define XICS_IPI 2/* interrupt source # for IPIs */ +/* Maximum number of threads per physical core */ +#define MAX_THREADS 8 + +/* Maximum number of subcores per physical core */ +#define MAX_SUBCORES 4 +#ifdef __ASSEMBLY__#ifdef CONFIG_KVM_BOOK3S_HANDLER
@@ -65,6 +71,19 @@ kvmppc_resume_\intno:#else /*__ASSEMBLY__ */ +struct kvmppc_vcore ; + +/* Struct used for coordinating micro-threading (split-core) mode changes */ +struct kvm_split_mode { +unsigned long rpr; +unsigned long pmmar; +unsigned long ldbar; +u8 subcore_size; +u8 do_nap; +u8 napped[MAX_THREADS ]; +struct kvmppc_vcore *master_vcs[MAX_SUBCORES ]; +}; +/* * This struct goes in the PACA on 64-bit processors. It is used * to store host state that needs to be saved when we enter a guest
@@ -100,6 +119,7 @@ struct kvmppc_host_state {u64 host_spurr;u64 host_dscr;u64 dec_expires; +struct kvm_split_mode *kvm_split_mode;#endif #ifdef CONFIG_PPC_BOOK3S_64 u64 cfar;
arch/powerpc/include/asm/kvm_host.h +3 -0
@@ -302,6 +302,9 @@ struct kvmppc_vcore {#define VCORE_EXIT_MAP (vc) ((vc)->entry_exit_map >> 8)#define VCORE_IS_EXITING (vc) (VCORE_EXIT_MAP(vc) != 0) +/* This bit is used when a vcore exit is triggered from outside the vcore */ +#define VCORE_EXIT_REQ 0x10000 +/* * Values for vcore_state. * Note that these are arranged such that lower values
arch/powerpc/kernel/asm-offsets.c +7 -0
@@ -676,7 +676,14 @@ int main(void)HSTATE_FIELD (HSTATE_DSCR , host_dscr);HSTATE_FIELD (HSTATE_DABR , dabr);HSTATE_FIELD (HSTATE_DECEXP , dec_expires); +HSTATE_FIELD (HSTATE_SPLIT_MODE , kvm_split_mode);DEFINE (IPI_PRIORITY ,IPI_PRIORITY ); +DEFINE (KVM_SPLIT_RPR , offsetof(struct kvm_split_mode , rpr)); +DEFINE (KVM_SPLIT_PMMAR , offsetof(struct kvm_split_mode , pmmar)); +DEFINE (KVM_SPLIT_LDBAR , offsetof(struct kvm_split_mode , ldbar)); +DEFINE (KVM_SPLIT_SIZE , offsetof(struct kvm_split_mode , subcore_size)); +DEFINE (KVM_SPLIT_DO_NAP , offsetof(struct kvm_split_mode , do_nap)); +DEFINE (KVM_SPLIT_NAPPED , offsetof(struct kvm_split_mode , napped));#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ #ifdef CONFIG_PPC_BOOK3S_64
arch/powerpc/kvm/book3s_hv.c +322 -46
495 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv_builtin.c +24 -1
@@ -239,7 +239,8 @@ void kvmhv_commence_exit(int trap) {struct kvmppc_vcore *vc = local_paca->kvm_hstate.kvm_vcore;int ptid = local_paca->kvm_hstate.ptid; -int me, ee; +struct kvm_split_mode *sip = local_paca->kvm_hstate.kvm_split_mode; +int me, ee, i;/* Set our bit in the threads-exiting-guest map in the 0xff00 bits of vcore->entry_exit_map */
@@ -259,4 +260,26 @@ void kvmhv_commence_exit(int trap)*/ if (trap !=BOOK3S_INTERRUPT_HV_DECREMENTER )kvmhv_interrupt_vcore (vc, ee & ~(1 << ptid)); + +/* +* If we are doing dynamic micro-threading, interrupt the other +* subcores to pull them out of their guests too. +*/ +if (!sip) +return ; + +for (i =0 ; i <MAX_SUBCORES ; ++i) { + vc = sip->master_vcs[i]; +if (!vc) +break ; +do { + ee = vc->entry_exit_map; +/* Already asked to exit? */ +if ((ee >>8 ) !=0 ) +break ; + }while (cmpxchg (&vc->entry_exit_map, ee, + ee |VCORE_EXIT_REQ ) != ee); +if ((ee >>8 ) =0 ) +kvmhv_interrupt_vcore (vc, ee); + } }
arch/powerpc/kvm/book3s_hv_rmhandlers.S +98 -15
193 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH v3 1/1 KVM: PPC: Book3S HV: Implement dynamic micro-threading on POWER8
This builds on the ability to run more than one vcore on a physical core by using the micro-threading (split-core) modes of the POWER8 chip. Previously, only vcores from the same VM could be run together, and (on POWER8) only if they had just one thread per core. With the ability to split the core on guest entry and unsplit it on guest exit, we can run up to 8 vcpu threads from up to 4 different VMs, and we can run multiple vcores with 2 or 4 vcpus per vcore.
Dynamic micro-threading is only available if the static configuration of the cores is whole-core mode (unsplit), and only on POWER8.
To manage this, we introduce a new kvm_split_mode struct which is shared across all of the subcores in the core, with a pointer in the paca on each thread. In addition we extend the core_info struct to have information on each subcore. When deciding whether to add a vcore to the set already on the core, we now have two possibilities:
(a) piggyback the vcore onto an existing subcore, or (b) start a new subcore.
Currently, when any vcpu needs to exit the guest and switch to host virtual mode, we interrupt all the threads in all subcores and switch the core back to whole-core mode. It may be possible in future to allow some of the subcores to keep executing in the guest while subcore 0 switches to the host, but that is not implemented in this patch.
This adds a module parameter called dynamic_mt_modes which controls which micro-threading (split-core) modes the code will consider, as a bitmap. In other words, if it is 0, no micro-threading mode is considered; if it is 2, only 2-way micro-threading is considered; if it is 4, only 4-way, and if it is 6, both 2-way and 4-way micro-threading mode will be considered. The default is 6.
With this, we now have secondary threads which are the primary thread for their subcore and therefore need to do the MMU switch. These threads will need to be started even if they have no vcpu to run, so we use the vcore pointer in the PACA rather than the vcpu pointer to trigger them.
It is now possible for thread 0 to find that an exit has been requested before it gets to switch the subcore state to the guest. In that case we haven't added the guest's timebase offset to the timebase, so we need to be careful not to subtract the offset in the guest exit path. In fact we just skip the whole path that switches back to host context, since we haven't switched to the guest context.
---
v3: Rename MAX_THREADS to MAX_SMT_THREADS to avoid a compile warning
arch/powerpc/include/asm/kvm_book3s_asm.h | 20 ++ arch/powerpc/include/asm/kvm_host.h | 3 + arch/powerpc/kernel/asm-offsets.c | 7 + arch/powerpc/kvm/book3s_hv.c | 367 ++++++++++++++++++++++++++---- arch/powerpc/kvm/book3s_hv_builtin.c | 25 +- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 113 +++++++-- 6 files changed, 473 insertions(+), 62 deletions(-)
arch/powerpc/include/asm/kvm_book3s_asm.h +20 -0
@@ -25,6 +25,12 @@#define XICS_MFRR 0xc#define XICS_IPI 2/* interrupt source # for IPIs */ +/* Maximum number of threads per physical core */ +#define MAX_SMT_THREADS 8 + +/* Maximum number of subcores per physical core */ +#define MAX_SUBCORES 4 +#ifdef __ASSEMBLY__#ifdef CONFIG_KVM_BOOK3S_HANDLER
@@ -65,6 +71,19 @@ kvmppc_resume_\intno:#else /*__ASSEMBLY__ */ +struct kvmppc_vcore ; + +/* Struct used for coordinating micro-threading (split-core) mode changes */ +struct kvm_split_mode { +unsigned long rpr; +unsigned long pmmar; +unsigned long ldbar; +u8 subcore_size; +u8 do_nap; +u8 napped[MAX_SMT_THREADS ]; +struct kvmppc_vcore *master_vcs[MAX_SUBCORES ]; +}; +/* * This struct goes in the PACA on 64-bit processors. It is used * to store host state that needs to be saved when we enter a guest
@@ -100,6 +119,7 @@ struct kvmppc_host_state {u64 host_spurr;u64 host_dscr;u64 dec_expires; +struct kvm_split_mode *kvm_split_mode;#endif #ifdef CONFIG_PPC_BOOK3S_64 u64 cfar;
arch/powerpc/include/asm/kvm_host.h +3 -0
@@ -302,6 +302,9 @@ struct kvmppc_vcore {#define VCORE_EXIT_MAP (vc) ((vc)->entry_exit_map >> 8)#define VCORE_IS_EXITING (vc) (VCORE_EXIT_MAP(vc) != 0) +/* This bit is used when a vcore exit is triggered from outside the vcore */ +#define VCORE_EXIT_REQ 0x10000 +/* * Values for vcore_state. * Note that these are arranged such that lower values
arch/powerpc/kernel/asm-offsets.c +7 -0
@@ -676,7 +676,14 @@ int main(void)HSTATE_FIELD (HSTATE_DSCR , host_dscr);HSTATE_FIELD (HSTATE_DABR , dabr);HSTATE_FIELD (HSTATE_DECEXP , dec_expires); +HSTATE_FIELD (HSTATE_SPLIT_MODE , kvm_split_mode);DEFINE (IPI_PRIORITY ,IPI_PRIORITY ); +DEFINE (KVM_SPLIT_RPR , offsetof(struct kvm_split_mode , rpr)); +DEFINE (KVM_SPLIT_PMMAR , offsetof(struct kvm_split_mode , pmmar)); +DEFINE (KVM_SPLIT_LDBAR , offsetof(struct kvm_split_mode , ldbar)); +DEFINE (KVM_SPLIT_SIZE , offsetof(struct kvm_split_mode , subcore_size)); +DEFINE (KVM_SPLIT_DO_NAP , offsetof(struct kvm_split_mode , do_nap)); +DEFINE (KVM_SPLIT_NAPPED , offsetof(struct kvm_split_mode , napped));#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ #ifdef CONFIG_PPC_BOOK3S_64
arch/powerpc/kvm/book3s_hv.c +320 -46
493 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv_builtin.c +24 -1
@@ -239,7 +239,8 @@ void kvmhv_commence_exit(int trap) {struct kvmppc_vcore *vc = local_paca->kvm_hstate.kvm_vcore;int ptid = local_paca->kvm_hstate.ptid; -int me, ee; +struct kvm_split_mode *sip = local_paca->kvm_hstate.kvm_split_mode; +int me, ee, i;/* Set our bit in the threads-exiting-guest map in the 0xff00 bits of vcore->entry_exit_map */
@@ -259,4 +260,26 @@ void kvmhv_commence_exit(int trap)*/ if (trap !=BOOK3S_INTERRUPT_HV_DECREMENTER )kvmhv_interrupt_vcore (vc, ee & ~(1 << ptid)); + +/* +* If we are doing dynamic micro-threading, interrupt the other +* subcores to pull them out of their guests too. +*/ +if (!sip) +return ; + +for (i =0 ; i <MAX_SUBCORES ; ++i) { + vc = sip->master_vcs[i]; +if (!vc) +break ; +do { + ee = vc->entry_exit_map; +/* Already asked to exit? */ +if ((ee >>8 ) !=0 ) +break ; + }while (cmpxchg (&vc->entry_exit_map, ee, + ee |VCORE_EXIT_REQ ) != ee); +if ((ee >>8 ) =0 ) +kvmhv_interrupt_vcore (vc, ee); + } }
arch/powerpc/kvm/book3s_hv_rmhandlers.S +98 -15
193 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH 3/5 KVM: PPC: Book3S HV: Fix race in reading change bit when removing HPTE
In reply to Paul MackerrasThe reference (R) and change (C) bits in a HPT entry can be set by hardware at any time up until the HPTE is invalidated and the TLB invalidation sequence has completed. This means that when removing a HPTE, we need to read the HPTE after the invalidation sequence has completed in order to obtain reliable values of R and C. The code in kvmppc_do_h_remove() used to do this. However, commit 6f22bd3265fb ("KVM: PPC: Book3S HV: Make HTAB code LE host aware") removed the read after invalidation as a side effect of other changes. This restores the read of the HPTE after invalidation.
The user-visible effect of this bug would be that when migrating a guest, there is a small probability that a page modified by the guest and then unmapped by the guest might not get re-transmitted and thus the destination might end up with a stale copy of the page.
--- arch/powerpc/kvm/book3s_hv_rm_mmu.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
arch/powerpc/kvm/book3s_hv_rm_mmu.c +12 -6
@@ -421,14 +421,20 @@ long kvmppc_do_h_remove(struct kvm *kvm, unsigned long flags, rev =real_vmalloc_addr (&kvm->arch.revmap[pte_index]); v = pte & ~HPTE_V_HVLOCK ;if (v &HPTE_V_VALID ) { -u64 pte1; - - pte1 =be64_to_cpu (hpte[1 ]); hpte[0 ] &= ~cpu_to_be64 (HPTE_V_VALID ); - rb =compute_tlbie_rb (v, pte1, pte_index); + rb =compute_tlbie_rb (v,be64_to_cpu (hpte[1 ]), pte_index);do_tlbies (kvm, &rb,1 ,global_invalidates (kvm, flags), true); -/* Read PTE low word after tlbie to get final R/C values */ -remove_revmap_chain (kvm, pte_index, rev, v, pte1); +/* +* The reference (R) and change (C) bits in a HPT +* entry can be set by hardware at any time up until +* the HPTE is invalidated and the TLB invalidation +* sequence has completed. This means that when +* removing a HPTE, we need to re-read the HPTE after +* the invalidation sequence has completed in order to +* obtain reliable values of R and C. +*/ +remove_revmap_chain (kvm, pte_index, rev, v, +be64_to_cpu (hpte[1 ])); } r = rev->guest_rpte & ~HPTE_GR_RESERVED ;note_hpte_modification (kvm, rev);
Signature · 1 line
2.1.4
PATCH 4/5 KVM: PPC: Book3S HV: Fix bug in dirty page tracking
In reply to Paul MackerrasThis fixes a bug in the tracking of pages that get modified by the guest. If the guest creates a large-page HPTE, writes to memory somewhere within the large page, and then removes the HPTE, we only record the modified state for the first normal page within the large page, when in fact the guest might have modified some other normal page within the large page.
To fix this we use some unused bits in the rmap entry to record the order (log base 2) of the size of the page that was modified, when removing an HPTE. Then in kvm_test_clear_dirty_npages() we use that order to return the correct number of modified pages.
The same thing could in principle happen when removing a HPTE at the host's request, i.e. when paging out a page, except that we never page out large pages, and the guest can only create large-page HPTEs if the guest RAM is backed by large pages. However, we also fix this case for the sake of future-proofing.
The reference bit is also subject to the same loss of information. We don't make the same fix here for the reference bit because there isn't an interface for userspace to find out which pages the guest has referenced, whereas there is one for userspace to find out which pages the guest has modified. Because of this loss of information, the kvm_age_hva_hv() and kvm_test_age_hva_hv() functions might incorrectly say that a page has not been referenced when it has, but that doesn't matter greatly because we never page or swap out large pages.
--- arch/powerpc/include/asm/kvm_book3s.h | 1 + arch/powerpc/include/asm/kvm_host.h | 2 ++ arch/powerpc/kvm/book3s_64_mmu_hv.c | 8 +++++++- arch/powerpc/kvm/book3s_hv_rm_mmu.c | 17 +++++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/kvm_book3s.h +1 -0
@@ -158,6 +158,7 @@ extern pfn_t kvmppc_gpa_to_pfn(struct kvm_vcpu *vcpu, gpa_t gpa, bool writing, bool *writable);extern void kvmppc_add_revmap_chain (struct kvm *kvm,struct revmap_entry *rev,unsigned long *rmap,long pte_index,int realmode); +extern void kvmppc_update_rmap_change (unsigned long *rmap,unsigned long psize);extern void kvmppc_invalidate_hpte (struct kvm *kvm,__be64 *hptep,unsigned long pte_index); void kvmppc_clear_ref_hpte(struct kvm *kvm, __be64 *hptep,
arch/powerpc/include/asm/kvm_host.h +2 -0
@@ -205,8 +205,10 @@ struct revmap_entry {*/ #define KVMPPC_RMAP_LOCK_BIT 63#define KVMPPC_RMAP_RC_SHIFT 32 +#define KVMPPC_RMAP_CHG_SHIFT 48#define KVMPPC_RMAP_REFERENCED (HPTE_R_R << KVMPPC_RMAP_RC_SHIFT)#define KVMPPC_RMAP_CHANGED (HPTE_R_C << KVMPPC_RMAP_RC_SHIFT) +#define KVMPPC_RMAP_CHG_ORDER (0x3ful << KVMPPC_RMAP_CHG_SHIFT)#define KVMPPC_RMAP_PRESENT 0x100000000ul#define KVMPPC_RMAP_INDEX 0xfffffffful
arch/powerpc/kvm/book3s_64_mmu_hv.c +7 -1
@@ -761,6 +761,8 @@ static int kvm_unmap_rmapp(struct kvm *kvm, unsigned long *rmapp,/* Harvest R and C */ rcbits =be64_to_cpu (hptep[1 ]) & (HPTE_R_R |HPTE_R_C ); *rmapp |= rcbits <<KVMPPC_RMAP_RC_SHIFT ; +if (rcbits &HPTE_R_C ) +kvmppc_update_rmap_change (rmapp, psize);if (rcbits & ~rev[i].guest_rpte) { rev[i].guest_rpte = ptel | rcbits;note_hpte_modification (kvm, &rev[i]);
@@ -927,8 +929,12 @@ static int kvm_test_clear_dirty_npages(struct kvm *kvm, unsigned long *rmapp) retry:lock_rmap (rmapp);if (*rmapp &KVMPPC_RMAP_CHANGED ) { - *rmapp &= ~KVMPPC_RMAP_CHANGED ; +long change_order = (*rmapp &KVMPPC_RMAP_CHG_ORDER ) + >>KVMPPC_RMAP_CHG_SHIFT ; + *rmapp &= ~(KVMPPC_RMAP_CHANGED |KVMPPC_RMAP_CHG_ORDER ); npages_dirty =1 ; +if (change_order >PAGE_SHIFT ) + npages_dirty =1ul << (change_order -PAGE_SHIFT ); }if (!(*rmapp &KVMPPC_RMAP_PRESENT )) {unlock_rmap (rmapp);
arch/powerpc/kvm/book3s_hv_rm_mmu.c +17 -0
@@ -12,6 +12,7 @@#include <linux/kvm_host.h> #include <linux/hugetlb.h> #include <linux/module.h> +#include <linux/log2.h> #include <asm/tlbflush.h> #include <asm/kvm_ppc.h>
@@ -97,6 +98,20 @@ void kvmppc_add_revmap_chain(struct kvm *kvm, struct revmap_entry *rev, }EXPORT_SYMBOL_GPL (kvmppc_add_revmap_chain); +/* Update the changed page order field of an rmap entry */ +void kvmppc_update_rmap_change (unsigned long *rmap,unsigned long psize) +{ +unsigned long order; + +if (!psize) +return ; + order =ilog2 (psize); + order <<=KVMPPC_RMAP_CHG_SHIFT ; +if (order > (*rmap &KVMPPC_RMAP_CHG_ORDER )) + *rmap = (*rmap & ~KVMPPC_RMAP_CHG_ORDER ) | order; +} +EXPORT_SYMBOL_GPL (kvmppc_update_rmap_change); +/* Remove this HPTE from the chain for a real page */ static void remove_revmap_chain(struct kvm *kvm, long pte_index, struct revmap_entry *rev,
@@ -131,6 +146,8 @@ static void remove_revmap_chain(struct kvm *kvm, long pte_index, *rmap = (*rmap & ~KVMPPC_RMAP_INDEX ) | head; } *rmap |= rcbits <<KVMPPC_RMAP_RC_SHIFT ; +if (rcbits &HPTE_R_C ) +kvmppc_update_rmap_change (rmap,hpte_page_size (hpte_v, hpte_r));unlock_rmap (rmap); }
Signature · 1 line
2.1.4
PATCH 5/5 KVM: PPC: Book3S HV: Implement H_CLEAR_REF and H_CLEAR_MOD
In reply to Paul MackerrasThis adds implementations for the H_CLEAR_REF (test and clear reference bit) and H_CLEAR_MOD (test and clear changed bit) hypercalls.
When clearing the reference or change bit in the guest view of the HPTE, we also have to clear it in the real HPTE so that we can detect future references or changes. When we do so, we transfer the R or C bit value to the rmap entry for the underlying host page so that kvm_age_hva_hv(), kvm_test_age_hva_hv() and kvmppc_hv_get_dirty_log() know that the page has been referenced and/or changed.
These hypercalls are not used by Linux guests. These implementations have been tested using a FreeBSD guest.
--- arch/powerpc/kvm/book3s_hv_rm_mmu.c | 126 ++++++++++++++++++++++++++++++-- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 4 +- 2 files changed, 121 insertions(+), 9 deletions(-)
arch/powerpc/kvm/book3s_hv_rm_mmu.c +119 -7
@@ -112,25 +112,38 @@ void kvmppc_update_rmap_change(unsigned long *rmap, unsigned long psize) }EXPORT_SYMBOL_GPL (kvmppc_update_rmap_change); +/* Returns a pointer to the revmap entry for the page mapped by a HPTE */ +static unsigned long *revmap_for_hpte (struct kvm *kvm,unsigned long hpte_v, +unsigned long hpte_gr) +{ +struct kvm_memory_slot *memslot; +unsigned long *rmap; +unsigned long gfn; + + gfn =hpte_rpn (hpte_gr,hpte_page_size (hpte_v, hpte_gr)); + memslot =__gfn_to_memslot (kvm_memslots_raw (kvm), gfn); +if (!memslot) +return NULL ; + + rmap =real_vmalloc_addr (&memslot->arch.rmap[gfn - memslot->base_gfn]); +return rmap; +} +/* Remove this HPTE from the chain for a real page */ static void remove_revmap_chain (struct kvm *kvm,long pte_index,struct revmap_entry *rev,unsigned long hpte_v,unsigned long hpte_r) {struct revmap_entry *next, *prev; -unsigned long gfn, ptel, head; -struct kvm_memory_slot *memslot; +unsigned long ptel, head;unsigned long *rmap;unsigned long rcbits; rcbits = hpte_r & (HPTE_R_R |HPTE_R_C ); ptel = rev->guest_rpte |= rcbits; - gfn =hpte_rpn (ptel,hpte_page_size (hpte_v, ptel)); - memslot =__gfn_to_memslot (kvm_memslots_raw (kvm), gfn); -if (!memslot) + rmap =revmap_for_hpte (kvm, hpte_v, ptel); +if (!rmap)return ; - - rmap =real_vmalloc_addr (&memslot->arch.rmap[gfn - memslot->base_gfn]);lock_rmap (rmap); head = *rmap &KVMPPC_RMAP_INDEX ;
@@ -678,6 +691,105 @@ long kvmppc_h_read(struct kvm_vcpu *vcpu, unsigned long flags,return H_SUCCESS ; } +long kvmppc_h_clear_ref (struct kvm_vcpu *vcpu,unsigned long flags, +unsigned long pte_index) +{ +struct kvm *kvm = vcpu->kvm; +__be64 *hpte; +unsigned long v, r, gr; +struct revmap_entry *rev; +unsigned long *rmap; +long ret =H_NOT_FOUND ; + +if (pte_index >= kvm->arch.hpt_npte) +return H_PARAMETER ; + + rev =real_vmalloc_addr (&kvm->arch.revmap[pte_index]); + hpte = (__be64 *)(kvm->arch.hpt_virt + (pte_index <<4 )); +while (!try_lock_hpte (hpte,HPTE_V_HVLOCK )) +cpu_relax (); + v =be64_to_cpu (hpte[0 ]); + r =be64_to_cpu (hpte[1 ]); +if (!(v & (HPTE_V_VALID |HPTE_V_ABSENT ))) + goto out; + + gr = rev->guest_rpte; +if (rev->guest_rpte &HPTE_R_R ) { + rev->guest_rpte &= ~HPTE_R_R ; +note_hpte_modification (kvm, rev); + } +if (v &HPTE_V_VALID ) { + gr |= r & (HPTE_R_R |HPTE_R_C ); +if (r &HPTE_R_R ) { +kvmppc_clear_ref_hpte (kvm, hpte, pte_index); + rmap =revmap_for_hpte (kvm, v, gr); +if (rmap) { +lock_rmap (rmap); + *rmap |=KVMPPC_RMAP_REFERENCED ; +unlock_rmap (rmap); + } + } + } + vcpu->arch.gpr[4 ] = gr; + ret =H_SUCCESS ; + out: +unlock_hpte (hpte, v & ~HPTE_V_HVLOCK ); +return ret; +} + +long kvmppc_h_clear_mod (struct kvm_vcpu *vcpu,unsigned long flags, +unsigned long pte_index) +{ +struct kvm *kvm = vcpu->kvm; +__be64 *hpte; +unsigned long v, r, gr; +struct revmap_entry *rev; +unsigned long *rmap; +long ret =H_NOT_FOUND ; + +if (pte_index >= kvm->arch.hpt_npte) +return H_PARAMETER ; + + rev =real_vmalloc_addr (&kvm->arch.revmap[pte_index]); + hpte = (__be64 *)(kvm->arch.hpt_virt + (pte_index <<4 )); +while (!try_lock_hpte (hpte,HPTE_V_HVLOCK )) +cpu_relax (); + v =be64_to_cpu (hpte[0 ]); + r =be64_to_cpu (hpte[1 ]); +if (!(v & (HPTE_V_VALID |HPTE_V_ABSENT ))) + goto out; + + gr = rev->guest_rpte; +if (gr &HPTE_R_C ) { + rev->guest_rpte &= ~HPTE_R_C ; +note_hpte_modification (kvm, rev); + } +if (v &HPTE_V_VALID ) { +/* need to make it temporarily absent so C is stable */ + hpte[0 ] |=cpu_to_be64 (HPTE_V_ABSENT ); +kvmppc_invalidate_hpte (kvm, hpte, pte_index); + r =be64_to_cpu (hpte[1 ]); + gr |= r & (HPTE_R_R |HPTE_R_C ); +if (r &HPTE_R_C ) { +unsigned long psize =hpte_page_size (v, r); + hpte[1 ] =cpu_to_be64 (r & ~HPTE_R_C ); +eieio (); + rmap =revmap_for_hpte (kvm, v, gr); +if (rmap) { +lock_rmap (rmap); + *rmap |=KVMPPC_RMAP_CHANGED ; +kvmppc_update_rmap_change (rmap, psize); +unlock_rmap (rmap); + } + } + } + vcpu->arch.gpr[4 ] = gr; + ret =H_SUCCESS ; + out: +unlock_hpte (hpte, v & ~HPTE_V_HVLOCK ); +return ret; +} +void kvmppc_invalidate_hpte (struct kvm *kvm,__be64 *hptep,unsigned long pte_index) {
arch/powerpc/kvm/book3s_hv_rmhandlers.S +2 -2
@@ -1904,8 +1904,8 @@ hcall_real_table: .long DOTSYM(kvmppc_h_remove) - hcall_real_table .long DOTSYM(kvmppc_h_enter) - hcall_real_table .long DOTSYM(kvmppc_h_read) - hcall_real_table - .long 0 /* 0x10 - H_CLEAR_MOD */ - .long 0 /* 0x14 - H_CLEAR_REF */ + .long DOTSYM(kvmppc_h_clear_mod) - hcall_real_table + .long DOTSYM(kvmppc_h_clear_ref) - hcall_real_table .long DOTSYM(kvmppc_h_protect) - hcall_real_table .long DOTSYM(kvmppc_h_get_tce) - hcall_real_table .long DOTSYM(kvmppc_h_put_tce) - hcall_real_table
Signature · 1 line
2.1.4
Alexander Graf
AppliedQuoted 7 lines · Paul Mackerras
This is my current queue of patches for HV KVM. This series is based on the kvm next branch. They have all been posted 6 weeks ago or more, though I have just added a 3-line fix to patch 2/5 to fix a bug that we found in testing migration, and I expanded a comment (no code change) in patch 3/5 following a suggestion by Aneesh.
I'd like to see these go into 4.2 if possible.
Thanks, applied all to kvm-ppc-queue.
Alex