ppc patch queue 2013-10-31
Subsystems (12)
Hi Paolo / Gleb,
This is my current patch queue for ppc. Please pull.
Highlights of this request are:
- Book3s HV and PR can be built into the same kernel
- e500 target debug support
- Book3s POWER8 preparation
- Lots of book3s PR fixes
I left out the FPU rework from Paul in this round, as kvm/next is still on rc2. I think it'll just have to wait for 3.14.
Alex
The following changes since commit d570142674890fe10b3d7d86aa105e3dfce1ddfa:
Merge tag 'kvm-arm-for-3.13-1' of git://git.linaro.org/people/cdall/linux-kvm-arm into next (2013-10-16 15:30:32 +0300)
are available in the git repository at:
git://github.com/agraf/linux-2.6.git kvm-ppc-queue
for you to fetch changes up to a78b55d1c0218b6d91d504941d20e36435c276f5:
kvm: powerpc: book3s: drop is_hv_enabled (2013-10-17 18:43:34 +0200)
----------------------------------------------------------------
Aneesh Kumar K.V (11):
kvm: powerpc: book3s: pr: Rename KVM_BOOK3S_PR to KVM_BOOK3S_PR_POSSIBLE
kvm: powerpc: book3s: Add a new config variable CONFIG_KVM_BOOK3S_HV_POSSIBLE
kvm: powerpc: Add kvmppc_ops callback
kvm: powerpc: book3s: Cleanup interrupt handling code
kvm: powerpc: book3s: Add is_hv_enabled to kvmppc_ops
kvm: powerpc: book3s: pr: move PR related tracepoints to a separate header
kvm: powerpc: booke: Move booke related tracepoints to separate header
kvm: powerpc: book3s: Support building HV and PR KVM as module
kvm: Add struct kvm arg to memslot APIs
kvm: powerpc: book3s: Allow the HV and PR selection per virtual machine
kvm: powerpc: book3s: drop is_hv_enabled
Bharat Bhushan (10):
powerpc: book3e: _PAGE_LENDIAN must be _PAGE_ENDIAN
kvm: powerpc: allow guest control "E" attribute in mas2
kvm: powerpc: allow guest control "G" attribute in mas2
kvm: powerpc: e500: mark page accessed when mapping a guest page
powerpc: remove unnecessary line continuations
powerpc: move debug registers in a structure
powerpc: export debug registers save function for KVM
KVM: PPC: E500: exit to user space on "ehpriv 1" instruction
KVM: PPC: E500: Using "struct debug_reg"
KVM: PPC: E500: Add userspace debug stub support
Michael Neuling (1):
KVM: PPC: Book3S HV: Reserve POWER8 space in get/set_one_reg
Paul Mackerras (29):
KVM: PPC: Book3S HV: Save/restore SIAR and SDAR along with other PMU registers
KVM: PPC: Book3S HV: Implement timebase offset for guests
KVM: PPC: Book3S: Add GET/SET_ONE_REG interface for VRSAVE
KVM: PPC: Book3S HV: Implement H_CONFER
KVM: PPC: Book3S HV: Restructure kvmppc_hv_entry to be a subroutine
KVM: PPC: Book3S HV: Pull out interrupt-reading code into a subroutine
KVM: PPC: Book3S HV: Avoid unbalanced increments of VPA yield count
KVM: PPC: BookE: Add GET/SET_ONE_REG interface for VRSAVE
KVM: PPC: Book3S HV: Store LPCR value for each virtual core
KVM: PPC: Book3S HV: Add support for guest Program Priority Register
KVM: PPC: Book3S HV: Support POWER6 compatibility mode on POWER7
KVM: PPC: Book3S HV: Don't crash host on unknown guest interrupt
KVM: PPC: Book3S PR: Fix compilation without CONFIG_ALTIVEC
KVM: PPC: Book3S PR: Keep volatile reg values in vcpu rather than shadow_vcpu
KVM: PPC: Book3S PR: Allow guest to use 64k pages
KVM: PPC: Book3S PR: Use 64k host pages where possible
KVM: PPC: Book3S PR: Handle PP0 page-protection bit in guest HPTEs
KVM: PPC: Book3S PR: Correct errors in H_ENTER implementation
KVM: PPC: Book3S PR: Make HPT accesses and updates SMP-safe
KVM: PPC: Book3S PR: Allocate kvm_vcpu structs from kvm_vcpu_cache
KVM: PPC: Book3S: Move skip-interrupt handlers to common code
KVM: PPC: Book3S PR: Better handling of host-side read-only pages
KVM: PPC: Book3S PR: Use mmu_notifier_retry() in kvmppc_mmu_map_page()
KVM: PPC: Book3S PR: Mark pages accessed, and dirty if being written
KVM: PPC: Book3S PR: Reduce number of shadow PTEs invalidated by MMU notifiers
kvm: powerpc: book3s hv: Fix vcore leak
KVM: PPC: Book3S HV: Better handling of exceptions that happen in real mode
kvm: powerpc: book3s: remove kvmppc_handler_highmem label
kvm: powerpc: book3s: move book3s_64_vio_hv.c into the main kernel binary
Documentation/virtual/kvm/api.txt | 44 +++ arch/arm/kvm/arm.c | 5 +- arch/ia64/kvm/kvm-ia64.c | 5 +- arch/mips/kvm/kvm_mips.c | 5 +- arch/powerpc/include/asm/disassemble.h | 4 + arch/powerpc/include/asm/exception-64s.h | 21 +- arch/powerpc/include/asm/kvm_asm.h | 4 + arch/powerpc/include/asm/kvm_book3s.h | 232 +---------- arch/powerpc/include/asm/kvm_book3s_32.h | 2 +- arch/powerpc/include/asm/kvm_book3s_64.h | 8 +- arch/powerpc/include/asm/kvm_book3s_asm.h | 9 +- arch/powerpc/include/asm/kvm_booke.h | 7 +- arch/powerpc/include/asm/kvm_host.h | 52 ++- arch/powerpc/include/asm/kvm_ppc.h | 107 ++++-- arch/powerpc/include/asm/paca.h | 2 +- arch/powerpc/include/asm/processor.h | 38 +- arch/powerpc/include/asm/pte-book3e.h | 2 +- arch/powerpc/include/asm/reg.h | 15 + arch/powerpc/include/asm/reg_booke.h | 8 +- arch/powerpc/include/asm/switch_to.h | 1 + arch/powerpc/include/uapi/asm/kvm.h | 86 ++++- arch/powerpc/kernel/asm-offsets.c | 23 +- arch/powerpc/kernel/exceptions-64s.S | 30 +- arch/powerpc/kernel/idle_power7.S | 2 +- arch/powerpc/kernel/process.c | 45 +-- arch/powerpc/kernel/ptrace.c | 154 ++++---- arch/powerpc/kernel/ptrace32.c | 2 +- arch/powerpc/kernel/signal_32.c | 6 +- arch/powerpc/kernel/traps.c | 35 +- arch/powerpc/kvm/44x.c | 58 ++- arch/powerpc/kvm/44x_emulate.c | 8 +- arch/powerpc/kvm/44x_tlb.c | 2 +- arch/powerpc/kvm/Kconfig | 28 +- arch/powerpc/kvm/Makefile | 29 +- arch/powerpc/kvm/book3s.c | 257 ++++++++++++- arch/powerpc/kvm/book3s.h | 34 ++ arch/powerpc/kvm/book3s_32_mmu.c | 73 ++-- arch/powerpc/kvm/book3s_32_mmu_host.c | 16 +- arch/powerpc/kvm/book3s_64_mmu.c | 181 +++++++-- arch/powerpc/kvm/book3s_64_mmu_host.c | 106 +++-- arch/powerpc/kvm/book3s_64_mmu_hv.c | 24 +- arch/powerpc/kvm/book3s_64_vio_hv.c | 1 + arch/powerpc/kvm/book3s_emulate.c | 18 +- arch/powerpc/kvm/book3s_exports.c | 5 +- arch/powerpc/kvm/book3s_hv.c | 389 +++++++++++++++---- arch/powerpc/kvm/book3s_hv_interrupts.S | 3 - arch/powerpc/kvm/book3s_hv_rmhandlers.S | 618 +++++++++++++++++------------- arch/powerpc/kvm/book3s_interrupts.S | 32 +- arch/powerpc/kvm/book3s_mmu_hpte.c | 66 +++- arch/powerpc/kvm/book3s_pr.c | 498 +++++++++++++++++------- arch/powerpc/kvm/book3s_pr_papr.c | 52 ++- arch/powerpc/kvm/book3s_rmhandlers.S | 32 +- arch/powerpc/kvm/book3s_rtas.c | 1 + arch/powerpc/kvm/book3s_segment.S | 4 +- arch/powerpc/kvm/book3s_xics.c | 7 +- arch/powerpc/kvm/booke.c | 337 ++++++++++++++-- arch/powerpc/kvm/booke.h | 29 ++ arch/powerpc/kvm/e500.c | 59 ++- arch/powerpc/kvm/e500.h | 2 +- arch/powerpc/kvm/e500_emulate.c | 34 +- arch/powerpc/kvm/e500_mmu.c | 4 +- arch/powerpc/kvm/e500_mmu_host.c | 6 +- arch/powerpc/kvm/e500mc.c | 58 ++- arch/powerpc/kvm/emulate.c | 12 +- arch/powerpc/kvm/powerpc.c | 171 +++++---- arch/powerpc/kvm/trace.h | 429 --------------------- arch/powerpc/kvm/trace_booke.h | 177 +++++++++ arch/powerpc/kvm/trace_pr.h | 297 ++++++++++++++ arch/s390/kvm/kvm-s390.c | 5 +- arch/x86/kvm/x86.c | 5 +- include/linux/kvm_host.h | 5 +- include/uapi/linux/kvm.h | 4 + virt/kvm/kvm_main.c | 16 +- 73 files changed, 3408 insertions(+), 1738 deletions(-) create mode 100644 arch/powerpc/kvm/book3s.h create mode 100644 arch/powerpc/kvm/trace_booke.h create mode 100644 arch/powerpc/kvm/trace_pr.h
[PULL 01/51] KVM: PPC: Book3S HV: Reserve POWER8 space in get/set_one_reg
From: Michael Neuling <[email protected]>
This reserves space in get/set_one_reg ioctl for the extra guest state needed for POWER8. It doesn't implement these at all, it just reserves them so that the ABI is defined now.
A few things to note here:
- This add *a lot* state for transactional memory. TM suspend mode, this is unavoidable, you can't simply roll back all transactions and store only the checkpointed state. I've added this all to get/set_one_reg (including GPRs) rather than creating a new ioctl which returns a struct kvm_regs like KVM_GET_REGS does. This means we if we need to extract the TM state, we are going to need a bucket load of IOCTLs. Hopefully most of the time this will not be needed as we can look at the MSR to see if TM is active and only grab them when needed. If this becomes a bottle neck in future we can add another ioctl to grab all this state in one go.
- The TM state is offset by 0x80000000.
- For TM, I've done away with VMX and FP and created a single 64x128 bit VSX register space.
- I've left a space of 1 (at 0x9c) since Paulus needs to add a value which applies to POWER7 as well.
--- Documentation/virtual/kvm/api.txt | 39 +++++++++++++++++++++++++++ arch/powerpc/include/uapi/asm/kvm.h | 54 +++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+)
Documentation/virtual/kvm/api.txt +39 -0
@@ -1810,6 +1810,45 @@ registers, find a list below: PPC | KVM_REG_PPC_TLB3PS | 32 PPC | KVM_REG_PPC_EPTCFG | 32 PPC | KVM_REG_PPC_ICP_STATE | 64 + PPC | KVM_REG_PPC_SPMC1 | 32 + PPC | KVM_REG_PPC_SPMC2 | 32 + PPC | KVM_REG_PPC_IAMR | 64 + PPC | KVM_REG_PPC_TFHAR | 64 + PPC | KVM_REG_PPC_TFIAR | 64 + PPC | KVM_REG_PPC_TEXASR | 64 + PPC | KVM_REG_PPC_FSCR | 64 + PPC | KVM_REG_PPC_PSPB | 32 + PPC | KVM_REG_PPC_EBBHR | 64 + PPC | KVM_REG_PPC_EBBRR | 64 + PPC | KVM_REG_PPC_BESCR | 64 + PPC | KVM_REG_PPC_TAR | 64 + PPC | KVM_REG_PPC_DPDES | 64 + PPC | KVM_REG_PPC_DAWR | 64 + PPC | KVM_REG_PPC_DAWRX | 64 + PPC | KVM_REG_PPC_CIABR | 64 + PPC | KVM_REG_PPC_IC | 64 + PPC | KVM_REG_PPC_VTB | 64 + PPC | KVM_REG_PPC_CSIGR | 64 + PPC | KVM_REG_PPC_TACR | 64 + PPC | KVM_REG_PPC_TCSCR | 64 + PPC | KVM_REG_PPC_PID | 64 + PPC | KVM_REG_PPC_ACOP | 64 + PPC | KVM_REG_PPC_TM_GPR0 | 64 + ... + PPC | KVM_REG_PPC_TM_GPR31 | 64 + PPC | KVM_REG_PPC_TM_VSR0 | 128 + ... + PPC | KVM_REG_PPC_TM_VSR63 | 128 + PPC | KVM_REG_PPC_TM_CR | 64 + PPC | KVM_REG_PPC_TM_LR | 64 + PPC | KVM_REG_PPC_TM_CTR | 64 + PPC | KVM_REG_PPC_TM_FPSCR | 64 + PPC | KVM_REG_PPC_TM_AMR | 64 + PPC | KVM_REG_PPC_TM_PPR | 64 + PPC | KVM_REG_PPC_TM_VRSAVE | 64 + PPC | KVM_REG_PPC_TM_VSCR | 32 + PPC | KVM_REG_PPC_TM_DSCR | 64 + PPC | KVM_REG_PPC_TM_TAR | 64 ARM registers are mapped using the lower 32 bits. The upper 16 of that is the register group type, or coprocessor number:
arch/powerpc/include/uapi/asm/kvm.h +54 -0
66 lines not on this page · raw message
Signature · 1 line
1.8.1.4
[PULL 02/51] KVM: PPC: Book3S HV: Save/restore SIAR and SDAR along with other PMU registers
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
Currently we are not saving and restoring the SIAR and SDAR registers in the PMU (performance monitor unit) on guest entry and exit. The result is that performance monitoring tools in the guest could get false information about where a program was executing and what data it was accessing at the time of a performance monitor interrupt. This fixes it by saving and restoring these registers along with the other PMU registers on guest entry/exit.
This also provides a way for userspace to access these values for a vcpu via the one_reg interface.
--- arch/powerpc/include/asm/kvm_host.h | 2 ++ arch/powerpc/kernel/asm-offsets.c | 2 ++ arch/powerpc/kvm/book3s_hv.c | 12 ++++++++++++ arch/powerpc/kvm/book3s_hv_rmhandlers.S | 8 ++++++++ 4 files changed, 24 insertions(+)
arch/powerpc/include/asm/kvm_host.h +2 -0
@@ -493,6 +493,8 @@ struct kvm_vcpu_arch {u64 mmcr[3 ];u32 pmc[8 ]; +u64 siar; +u64 sdar;#ifdef CONFIG_KVM_EXIT_TIMING struct mutex exit_timing_lock;
arch/powerpc/kernel/asm-offsets.c +2 -0
@@ -508,6 +508,8 @@ int main(void) DEFINE(VCPU_PRODDED, offsetof(struct kvm_vcpu, arch.prodded)); DEFINE(VCPU_MMCR, offsetof(struct kvm_vcpu, arch.mmcr)); DEFINE(VCPU_PMC, offsetof(struct kvm_vcpu, arch.pmc)); + DEFINE(VCPU_SIAR, offsetof(struct kvm_vcpu, arch.siar)); + DEFINE(VCPU_SDAR, offsetof(struct kvm_vcpu, arch.sdar)); DEFINE(VCPU_SLB, offsetof(struct kvm_vcpu, arch.slb)); DEFINE(VCPU_SLB_MAX, offsetof(struct kvm_vcpu, arch.slb_max)); DEFINE(VCPU_SLB_NR, offsetof(struct kvm_vcpu, arch.slb_nr));
arch/powerpc/kvm/book3s_hv.c +12 -0
@@ -749,6 +749,12 @@ int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *val) i = id -KVM_REG_PPC_PMC1 ; *val =get_reg_val (id, vcpu->arch.pmc[i]);break ; +case KVM_REG_PPC_SIAR : + *val =get_reg_val (id, vcpu->arch.siar); +break ; +case KVM_REG_PPC_SDAR : + *val =get_reg_val (id, vcpu->arch.sdar); +break ;#ifdef CONFIG_VSX case KVM_REG_PPC_FPR0 ... KVM_REG_PPC_FPR31:if (cpu_has_feature (CPU_FTR_VSX )) {
@@ -833,6 +839,12 @@ int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *val) i = id -KVM_REG_PPC_PMC1 ; vcpu->arch.pmc[i] =set_reg_val (id, *val);break ; +case KVM_REG_PPC_SIAR : + vcpu->arch.siar =set_reg_val (id, *val); +break ; +case KVM_REG_PPC_SDAR : + vcpu->arch.sdar =set_reg_val (id, *val); +break ;#ifdef CONFIG_VSX case KVM_REG_PPC_FPR0 ... KVM_REG_PPC_FPR31:if (cpu_has_feature (CPU_FTR_VSX )) {
arch/powerpc/kvm/book3s_hv_rmhandlers.S +8 -0
@@ -200,8 +200,12 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201) ld r3, VCPU_MMCR(r4) ld r5, VCPU_MMCR + 8(r4) ld r6, VCPU_MMCR + 16(r4) + ld r7, VCPU_SIAR(r4) + ld r8, VCPU_SDAR(r4) mtspr SPRN_MMCR1, r5 mtspr SPRN_MMCRA, r6 + mtspr SPRN_SIAR, r7 + mtspr SPRN_SDAR, r8 mtspr SPRN_MMCR0, r3 isync
@@ -1134,9 +1138,13 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) std r3, VCPU_MMCR(r9) /* if not, set saved MMCR0 to FC */ b 22f 21: mfspr r5, SPRN_MMCR1 + mfspr r7, SPRN_SIAR + mfspr r8, SPRN_SDAR std r4, VCPU_MMCR(r9) std r5, VCPU_MMCR + 8(r9) std r6, VCPU_MMCR + 16(r9) + std r7, VCPU_SIAR(r9) + std r8, VCPU_SDAR(r9) mfspr r3, SPRN_PMC1 mfspr r4, SPRN_PMC2 mfspr r5, SPRN_PMC3
Signature · 1 line
1.8.1.4
[PULL 03/51] KVM: PPC: Book3S HV: Implement timebase offset for guests
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
This allows guests to have a different timebase origin from the host. This is needed for migration, where a guest can migrate from one host to another and the two hosts might have a different timebase origin. However, the timebase seen by the guest must not go backwards, and should go forwards only by a small amount corresponding to the time taken for the migration.
Therefore this provides a new per-vcpu value accessed via the one_reg interface using the new KVM_REG_PPC_TB_OFFSET identifier. This value defaults to 0 and is not modified by KVM. On entering the guest, this value is added onto the timebase, and on exiting the guest, it is subtracted from the timebase.
This is only supported for recent POWER hardware which has the TBU40 (timebase upper 40 bits) register. Writing to the TBU40 register only alters the upper 40 bits of the timebase, leaving the lower 24 bits unchanged. This provides a way to modify the timebase for guest migration without disturbing the synchronization of the timebase registers across CPU cores. The kernel rounds up the value given to a multiple of 2^24.
Timebase values stored in KVM structures (struct kvm_vcpu, struct kvmppc_vcore, etc.) are stored as host timebase values. The timebase values in the dispatch trace log need to be guest timebase values, however, since that is read directly by the guest. This moves the setting of vcpu->arch.dec_expires on guest exit to a point after we have restored the host timebase so that vcpu->arch.dec_expires is a host timebase value.
--- Documentation/virtual/kvm/api.txt | 1 + arch/powerpc/include/asm/kvm_host.h | 1 + arch/powerpc/include/asm/reg.h | 1 + arch/powerpc/include/uapi/asm/kvm.h | 3 ++ arch/powerpc/kernel/asm-offsets.c | 1 + arch/powerpc/kvm/book3s_hv.c | 10 ++++++- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 50 +++++++++++++++++++++++++++------ 7 files changed, 57 insertions(+), 10 deletions(-)
Documentation/virtual/kvm/api.txt +1 -0
@@ -1810,6 +1810,7 @@ registers, find a list below: PPC | KVM_REG_PPC_TLB3PS | 32 PPC | KVM_REG_PPC_EPTCFG | 32 PPC | KVM_REG_PPC_ICP_STATE | 64 + PPC | KVM_REG_PPC_TB_OFFSET | 64 PPC | KVM_REG_PPC_SPMC1 | 32 PPC | KVM_REG_PPC_SPMC2 | 32 PPC | KVM_REG_PPC_IAMR | 64
arch/powerpc/include/asm/kvm_host.h +1 -0
@@ -289,6 +289,7 @@ struct kvmppc_vcore {u64 stolen_tb;u64 preempt_tb;struct kvm_vcpu *runner; +u64 tb_offset;/* guest timebase - host timebase */ };#define VCORE_ENTRY_COUNT (vc) ((vc)->entry_exit_count & 0xff)
arch/powerpc/include/asm/reg.h +1 -0
@@ -243,6 +243,7 @@#define SPRN_TBRU 0x10D/* Time Base Read Upper Register (user, R/O) */ #define SPRN_TBWL 0x11C/* Time Base Lower Register (super, R/W) */ #define SPRN_TBWU 0x11D/* Time Base Upper Register (super, R/W) */ +#define SPRN_TBU40 0x11E/* Timebase upper 40 bits (hyper, R/W) */ #define SPRN_SPURR 0x134/* Scaled PURR */ #define SPRN_HSPRG0 0x130/* Hypervisor Scratch 0 */ #define SPRN_HSPRG1 0x131/* Hypervisor Scratch 1 */
arch/powerpc/include/uapi/asm/kvm.h +3 -0
@@ -504,6 +504,9 @@ struct kvm_get_htab_header {#define KVM_REG_PPC_TLB3PS (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x9a)#define KVM_REG_PPC_EPTCFG (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x9b) +/* Timebase offset */ +#define KVM_REG_PPC_TB_OFFSET (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x9c) +/* POWER8 registers */ #define KVM_REG_PPC_SPMC1 (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x9d)#define KVM_REG_PPC_SPMC2 (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x9e)
arch/powerpc/kernel/asm-offsets.c +1 -0
@@ -523,6 +523,7 @@ int main(void)DEFINE (VCORE_NAP_COUNT , offsetof(struct kvmppc_vcore , nap_count));DEFINE (VCORE_IN_GUEST , offsetof(struct kvmppc_vcore , in_guest));DEFINE (VCORE_NAPPING_THREADS , offsetof(struct kvmppc_vcore , napping_threads)); +DEFINE (VCORE_TB_OFFSET , offsetof(struct kvmppc_vcore , tb_offset));DEFINE (VCPU_SVCPU , offsetof(struct kvmppc_vcpu_book3s , shadow_vcpu) - offsetof(struct kvmppc_vcpu_book3s , vcpu));DEFINE (VCPU_SLB_E , offsetof(struct kvmppc_slb , orige));
arch/powerpc/kvm/book3s_hv.c +8 -1
@@ -489,7 +489,7 @@ static void kvmppc_create_dtl_entry(struct kvm_vcpu *vcpu,memset (dt,0 ,sizeof (struct dtl_entry )); dt->dispatch_reason =7 ; dt->processor_id = vc->pcpu + vcpu->arch.ptid; - dt->timebase = now; + dt->timebase = now + vc->tb_offset; dt->enqueue_to_dispatch_time = stolen; dt->srr0 =kvmppc_get_pc (vcpu); dt->srr1 = vcpu->arch.shregs.msr;
@@ -793,6 +793,9 @@ int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *val) val->vpaval.length = vcpu->arch.dtl.len;spin_unlock (&vcpu->arch.vpa_update_lock);break ; +case KVM_REG_PPC_TB_OFFSET : + *val =get_reg_val (id, vcpu->arch.vcore->tb_offset); +break ;default : r = -EINVAL ;break ;
@@ -892,6 +895,11 @@ int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *val) len -= len %sizeof (struct dtl_entry ); r =set_vpa (vcpu, &vcpu->arch.dtl, addr, len);break ; +case KVM_REG_PPC_TB_OFFSET : +/* round up to multiple of 2^24 */ + vcpu->arch.vcore->tb_offset +ALIGN (set_reg_val (id, *val),1UL <<24 ); +break ;default : r = -EINVAL ;break ;
arch/powerpc/kvm/book3s_hv_rmhandlers.S +41 -9
74 lines not on this page · raw message
Signature · 1 line
1.8.1.4
[PULL 04/51] KVM: PPC: Book3S: Add GET/SET_ONE_REG interface for VRSAVE
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
The VRSAVE register value for a vcpu is accessible through the GET/SET_SREGS interface for Book E processors, but not for Book 3S processors. In order to make this accessible for Book 3S processors, this adds a new register identifier for GET/SET_ONE_REG, and adds the code to implement it.
--- Documentation/virtual/kvm/api.txt | 1 + arch/powerpc/include/uapi/asm/kvm.h | 2 ++ arch/powerpc/kvm/book3s.c | 10 ++++++++++ 3 files changed, 13 insertions(+)
Documentation/virtual/kvm/api.txt +1 -0
@@ -1834,6 +1834,7 @@ registers, find a list below: PPC | KVM_REG_PPC_TCSCR | 64 PPC | KVM_REG_PPC_PID | 64 PPC | KVM_REG_PPC_ACOP | 64 + PPC | KVM_REG_PPC_VRSAVE | 32 PPC | KVM_REG_PPC_TM_GPR0 | 64 ... PPC | KVM_REG_PPC_TM_GPR31 | 64
arch/powerpc/include/uapi/asm/kvm.h +2 -0
@@ -532,6 +532,8 @@ struct kvm_get_htab_header {#define KVM_REG_PPC_PID (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb2)#define KVM_REG_PPC_ACOP (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb3) +#define KVM_REG_PPC_VRSAVE (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xb4) +/* Transactional Memory checkpointed state: * This is all GPRs, all VSX regs and a subset of SPRs */
arch/powerpc/kvm/book3s.c +10 -0
@@ -528,6 +528,9 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) } val =get_reg_val (reg->id, vcpu->arch.vscr.u[3 ]);break ; +case KVM_REG_PPC_VRSAVE : + val =get_reg_val (reg->id, vcpu->arch.vrsave); +break ;#endif /* CONFIG_ALTIVEC */ case KVM_REG_PPC_DEBUG_INST : {u32 opcode =INS_TW ;
@@ -605,6 +608,13 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) } vcpu->arch.vscr.u[3 ] =set_reg_val (reg->id, val);break ; +case KVM_REG_PPC_VRSAVE : +if (!cpu_has_feature (CPU_FTR_ALTIVEC )) { + r = -ENXIO ; +break ; + } + vcpu->arch.vrsave =set_reg_val (reg->id, val); +break ;#endif /* CONFIG_ALTIVEC */ #ifdef CONFIG_KVM_XICS case KVM_REG_PPC_ICP_STATE :
Signature · 1 line
1.8.1.4
[PULL 05/51] KVM: PPC: Book3S HV: Implement H_CONFER
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
The H_CONFER hypercall is used when a guest vcpu is spinning on a lock held by another vcpu which has been preempted, and the spinning vcpu wishes to give its timeslice to the lock holder. We implement this in the straightforward way using kvm_vcpu_yield_to().
--- arch/powerpc/kvm/book3s_hv.c | 9 +++++++++ 1 file changed, 9 insertions(+)
arch/powerpc/kvm/book3s_hv.c +9 -0
@@ -538,6 +538,15 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu) }break ;case H_CONFER : + target =kvmppc_get_gpr (vcpu,4 ); +if (target ==-1 ) +break ; + tvcpu =kvmppc_find_vcpu (vcpu->kvm, target); +if (!tvcpu) { + ret =H_PARAMETER ; +break ; + } +kvm_vcpu_yield_to (tvcpu);break ;case H_REGISTER_VPA : ret = do_h_register_vpa(vcpu, kvmppc_get_gpr(vcpu, 4),
Signature · 1 line
1.8.1.4
[PULL 06/51] KVM: PPC: Book3S HV: Restructure kvmppc_hv_entry to be a subroutine
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
We have two paths into and out of the low-level guest entry and exit
code: from a vcpu task via kvmppc_hv_entry_trampoline, and from the system reset vector for an offline secondary thread on POWER7 via kvm_start_guest. Currently both just branch to kvmppc_hv_entry to enter the guest, and on guest exit, we test the vcpu physical thread ID to detect which way we came in and thus whether we should return to the vcpu task or go back to nap mode.
In order to make the code flow clearer, and to keep the code relating to each flow together, this turns kvmppc_hv_entry into a subroutine that follows the normal conventions for call and return. This means that kvmppc_hv_entry_trampoline() and kvmppc_hv_entry() now establish normal stack frames, and we use the normal stack slots for saving return addresses rather than local_paca->kvm_hstate.vmhandler. Apart from that this is mostly moving code around unchanged.
--- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 344 +++++++++++++++++--------------- 1 file changed, 178 insertions(+), 166 deletions(-)
arch/powerpc/kvm/book3s_hv_rmhandlers.S +178 -166
@@ -66,8 +66,11 @@ kvmppc_skip_Hinterrupt: * LR = return address to continue at after eventually re-enabling MMU */ _GLOBAL(kvmppc_hv_entry_trampoline) + mflr r0 + std r0, PPC_LR_STKOFF(r1) + stdu r1, -112(r1) mfmsr r10 - LOAD_REG_ADDR(r5, kvmppc_hv_entry) + LOAD_REG_ADDR(r5, kvmppc_call_hv_entry) li r0,MSR_RI andc r0,r10,r0 li r6,MSR_IR | MSR_DR
@@ -77,11 +80,103 @@ _GLOBAL(kvmppc_hv_entry_trampoline) mtsrr1 r6 RFI -/****************************************************************************** - * * - * Entry code * - * * - *****************************************************************************/ +kvmppc_call_hv_entry: + bl kvmppc_hv_entry + + /* Back from guest - restore host state and return to caller */ + + /* Restore host DABR and DABRX */ + ld r5,HSTATE_DABR(r13) + li r6,7 + mtspr SPRN_DABR,r5 + mtspr SPRN_DABRX,r6 + + /* Restore SPRG3 */ + ld r3,PACA_SPRG3(r13) + mtspr SPRN_SPRG3,r3 + + /* + * Reload DEC. HDEC interrupts were disabled when + * we reloaded the host's LPCR value. + */ + ld r3, HSTATE_DECEXP(r13) + mftb r4 + subf r4, r4, r3 + mtspr SPRN_DEC, r4 + + /* Reload the host's PMU registers */ + ld r3, PACALPPACAPTR(r13) /* is the host using the PMU? */ + lbz r4, LPPACA_PMCINUSE(r3) + cmpwi r4, 0 + beq 23f /* skip if not */ + lwz r3, HSTATE_PMC(r13) + lwz r4, HSTATE_PMC + 4(r13) + lwz r5, HSTATE_PMC + 8(r13) + lwz r6, HSTATE_PMC + 12(r13) + lwz r8, HSTATE_PMC + 16(r13) + lwz r9, HSTATE_PMC + 20(r13) +BEGIN_FTR_SECTION + lwz r10, HSTATE_PMC + 24(r13) + lwz r11, HSTATE_PMC + 28(r13) +END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201) + mtspr SPRN_PMC1, r3 + mtspr SPRN_PMC2, r4 + mtspr SPRN_PMC3, r5 + mtspr SPRN_PMC4, r6 + mtspr SPRN_PMC5, r8 + mtspr SPRN_PMC6, r9 +BEGIN_FTR_SECTION + mtspr SPRN_PMC7, r10 + mtspr SPRN_PMC8, r11 +END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201) + ld r3, HSTATE_MMCR(r13) + ld r4, HSTATE_MMCR + 8(r13) + ld r5, HSTATE_MMCR + 16(r13) + mtspr SPRN_MMCR1, r4 + mtspr SPRN_MMCRA, r5 + mtspr SPRN_MMCR0, r3 + isync +23: + + /* + * For external and machine check interrupts, we need + * to call the Linux handler to process the interrupt. + * We do that by jumping to absolute address 0x500 for + * external interrupts, or the machine_check_fwnmi label + * for machine checks (since firmware might have patched + * the vector area at 0x200). The [h]rfid at the end of the + * handler will return to the book3s_hv_interrupts.S code. + * For other interrupts we do the rfid to get back + * to the book3s_hv_interrupts.S code here. + */ + ld r8, 112+PPC_LR_STKOFF(r1) + addi r1, r1, 112 + ld r7, HSTATE_HOST_MSR(r13) + + cmpwi cr1, r12, BOOK3S_INTERRUPT_MACHINE_CHECK + cmpwi r12, BOOK3S_INTERRUPT_EXTERNAL +BEGIN_FTR_SECTION + beq 11f +END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) + + /* RFI into the highmem handler, or branch to interrupt handler */ + mfmsr r6 + li r0, MSR_RI + andc r6, r6, r0 + mtmsrd r6, 1 /* Clear RI in MSR */ + mtsrr0 r8 + mtsrr1 r7 + beqa 0x500 /* external interrupt (PPC970) */ + beq cr1, 13f /* machine check */ + RFI + + /* On POWER7, we have external interrupts set to use HSRR0/1 */ +11: mtspr SPRN_HSRR0, r8 + mtspr SPRN_HSRR1, r7 + ba 0x500 + +13: b machine_check_fwnmi + /* * We come in here when wakened from nap mode on a secondary hw thread.
@@ -137,7 +232,7 @@ kvm_start_guest: cmpdi r4,0 /* if we have no vcpu to run, go back to sleep */ beq kvm_no_guest - b kvmppc_hv_entry + b 30f 27: /* XXX should handle hypervisor maintenance interrupts etc. here */ b kvm_no_guest
@@ -147,6 +242,57 @@ kvm_start_guest: stw r8,HSTATE_SAVED_XIRR(r13) b kvm_no_guest +30: bl kvmppc_hv_entry + + /* Back from the guest, go back to nap */ + /* Clear our vcpu pointer so we don't come back in early */ + li r0, 0 + std r0, HSTATE_KVM_VCPU(r13) + lwsync + /* Clear any pending IPI - we're an offline thread */ + ld r5, HSTATE_XICS_PHYS(r13) + li r7, XICS_XIRR + lwzcix r3, r5, r7 /* ack any pending interrupt */ + rlwinm. r0, r3, 0, 0xffffff /* any pending? */ + beq 37f + sync + li r0, 0xff + li r6, XICS_MFRR + stbcix r0, r5, r6 /* clear the IPI */ + stwcix r3, r5, r7 /* EOI it */ +37: sync + + /* increment the nap count and then go to nap mode */ + ld r4, HSTATE_KVM_VCORE(r13) + addi r4, r4, VCORE_NAP_COUNT + lwsync /* make previous updates visible */ +51: lwarx r3, 0, r4 + addi r3, r3, 1 + stwcx. r3, 0, r4 + bne 51b + +kvm_no_guest: + li r0, KVM_HWTHREAD_IN_NAP + stb r0, HSTATE_HWTHREAD_STATE(r13) + li r3, LPCR_PECE0 + mfspr r4, SPRN_LPCR + rlwimi r4, r3, 0, LPCR_PECE0 | LPCR_PECE1 + mtspr SPRN_LPCR, r4 + isync + std r0, HSTATE_SCRATCH0(r13) + ptesync + ld r0, HSTATE_SCRATCH0(r13) +1: cmpd r0, r0 + bne 1b + nap + b . + +/****************************************************************************** + * * + * Entry code * + * * + *****************************************************************************/ + .global kvmppc_hv_entry kvmppc_hv_entry:
@@ -159,7 +305,8 @@ kvmppc_hv_entry: * all other volatile GPRS = free */ mflr r0 - std r0, HSTATE_VMHANDLER(r13) + std r0, PPC_LR_STKOFF(r1) + stdu r1, -112(r1) /* Set partition DABR */ /* Do this before re-enabling PMU to avoid P7 DABR corruption bug */
@@ -1198,103 +1345,30 @@ BEGIN_FTR_SECTION stw r11, VCPU_PMC + 28(r9) END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201) 22: + ld r0, 112+PPC_LR_STKOFF(r1) + addi r1, r1, 112 + mtlr r0 + blr +secondary_too_late: + ld r5,HSTATE_KVM_VCORE(r13) + HMT_LOW +13: lbz r3,VCORE_IN_GUEST(r5) + cmpwi r3,0 + bne 13b + HMT_MEDIUM + li r0, KVM_GUEST_MODE_NONE + stb r0, HSTATE_IN_GUEST(r13) + ld r11,PACA_SLBSHADOWPTR(r13) - /* Secondary threads go off to take a nap on POWER7 */ -BEGIN_FTR_SECTION - lwz r0,VCPU_PTID(r9) - cmpwi r0,0 - bne secondary_nap -END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) - - /* Restore host DABR and DABRX */ - ld r5,HSTATE_DABR(r13) - li r6,7 - mtspr SPRN_DABR,r5 - mtspr SPRN_DABRX,r6 - - /* Restore SPRG3 */ - ld r3,PACA_SPRG3(r13) - mtspr SPRN_SPRG3,r3 - - /* - * Reload DEC. HDEC interrupts were disabled when - * we reloaded the host's LPCR value. - */ - ld r3, HSTATE_DECEXP(r13) - mftb r4 - subf r4, r4, r3 - mtspr SPRN_DEC, r4 - - /* Reload the host's PMU registers */ - ld r3, PACALPPACAPTR(r13) /* is the host using the PMU? */ - lbz r4, LPPACA_PMCINUSE(r3) - cmpwi r4, 0 - beq 23f /* skip if not */ - lwz r3, HSTATE_PMC(r13) - lwz r4, HSTATE_PMC + 4(r13) - lwz r5, HSTATE_PMC + 8(r13) - lwz r6, HSTATE_PMC + 12(r13) - lwz r8, HSTATE_PMC + 16(r13) - lwz r9, HSTATE_PMC + 20(r13) -BEGIN_FTR_SECTION - lwz r10, HSTATE_PMC + 24(r13) - lwz r11, HSTATE_PMC + 28(r13) -END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201) - mtspr SPRN_PMC1, r3 - mtspr SPRN_PMC2, r4 - mtspr SPRN_PMC3, r5 - mtspr SPRN_PMC4, r6 - mtspr SPRN_PMC5, r8 - mtspr SPRN_PMC6, r9 -BEGIN_FTR_SECTION - mtspr SPRN_PMC7, r10 - mtspr SPRN_PMC8, r11 -END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201) - ld r3, HSTATE_MMCR(r13) - ld r4, HSTATE_MMCR + 8(r13) - ld r5, HSTATE_MMCR + 16(r13) - mtspr SPRN_MMCR1, r4 - mtspr SPRN_MMCRA, r5 - mtspr SPRN_MMCR0, r3 - isync -23: - /* - * For external and machine check interrupts, we need - * to call the Linux handler to process the interrupt. - * We do that by jumping to absolute address 0x500 for - * external interrupts, or the machine_check_fwnmi label - * for machine checks (since firmware might have patched - * the vector area at 0x200). The [h]rfid at the end of the - * handler will return to the book3s_hv_interrupts.S code. - * For other interrupts we do the rfid to get back - * to the book3s_hv_interrupts.S code here. - */ - ld r8, HSTATE_VMHANDLER(r13) - ld r7, HSTATE_HOST_MSR(r13) - - cmpwi cr1, r12, BOOK3S_INTERRUPT_MACHINE_CHECK - cmpwi r12, BOOK3S_INTERRUPT_EXTERNAL -BEGIN_FTR_SECTION - beq 11f -END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) - - /* RFI into the highmem handler, or branch to interrupt handler */ - mfmsr r6 - li r0, MSR_RI - andc r6, r6, r0 - mtmsrd r6, 1 /* Clear RI in MSR */ - mtsrr0 r8 - mtsrr1 r7 - beqa 0x500 /* external interrupt (PPC970) */ - beq cr1, 13f /* machine check */ - RFI - - /* On POWER7, we have external interrupts set to use HSRR0/1 */ -11: mtspr SPRN_HSRR0, r8 - mtspr SPRN_HSRR1, r7 - ba 0x500 - -13: b machine_check_fwnmi + .rept SLB_NUM_BOLTED + ld r5,SLBSHADOW_SAVEAREA(r11) + ld r6,SLBSHADOW_SAVEAREA+8(r11) + andis. r7,r5,SLB_ESID_V@h + beq 1f + slbmte r6,r5 +1: addi r11,r11,16 + .endr + b 22b /* * Check whether an HDSI is an HPTE not found fault or something else.
@@ -1741,68 +1815,6 @@ machine_check_realmode: rotldi r11, r11, 63 b fast_interrupt_c_return -secondary_too_late: - ld r5,HSTATE_KVM_VCORE(r13) - HMT_LOW -13: lbz r3,VCORE_IN_GUEST(r5) - cmpwi r3,0 - bne 13b - HMT_MEDIUM - ld r11,PACA_SLBSHADOWPTR(r13) - - .rept SLB_NUM_BOLTED - ld r5,SLBSHADOW_SAVEAREA(r11) - ld r6,SLBSHADOW_SAVEAREA+8(r11) - andis. r7,r5,SLB_ESID_V@h - beq 1f - slbmte r6,r5 -1: addi r11,r11,16 - .endr - -secondary_nap: - /* Clear our vcpu pointer so we don't come back in early */ - li r0, 0 - std r0, HSTATE_KVM_VCPU(r13) - lwsync - /* Clear any pending IPI - assume we're a secondary thread */ - ld r5, HSTATE_XICS_PHYS(r13) - li r7, XICS_XIRR - lwzcix r3, r5, r7 /* ack any pending interrupt */ - rlwinm. r0, r3, 0, 0xffffff /* any pending? */ - beq 37f - sync - li r0, 0xff - li r6, XICS_MFRR - stbcix r0, r5, r6 /* clear the IPI */ - stwcix r3, r5, r7 /* EOI it */ -37: sync - - /* increment the nap count and then go to nap mode */ - ld r4, HSTATE_KVM_VCORE(r13) - addi r4, r4, VCORE_NAP_COUNT - lwsync /* make previous updates visible */ -51: lwarx r3, 0, r4 - addi r3, r3, 1 - stwcx. r3, 0, r4 - bne 51b - -kvm_no_guest: - li r0, KVM_HWTHREAD_IN_NAP - stb r0, HSTATE_HWTHREAD_STATE(r13) - - li r3, LPCR_PECE0 - mfspr r4, SPRN_LPCR - rlwimi r4, r3, 0, LPCR_PECE0 | LPCR_PECE1 - mtspr SPRN_LPCR, r4 - isync - std r0, HSTATE_SCRATCH0(r13) - ptesync - ld r0, HSTATE_SCRATCH0(r13) -1: cmpd r0, r0 - bne 1b - nap - b . - /* * Save away FP, VMX and VSX registers. * r3 = vcpu pointer
Signature · 1 line
1.8.1.4
[PULL 07/51] KVM: PPC: Book3S HV: Pull out interrupt-reading code into a subroutine
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
This moves the code in book3s_hv_rmhandlers.S that reads any pending interrupt from the XICS interrupt controller, and works out whether it is an IPI for the guest, an IPI for the host, or a device interrupt, into a new function called kvmppc_read_intr. Later patches will need this.
--- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 117 +++++++++++++++++++------------- 1 file changed, 68 insertions(+), 49 deletions(-)
arch/powerpc/kvm/book3s_hv_rmhandlers.S +68 -49
@@ -862,46 +862,11 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_206) * set, we know the host wants us out so let's do it now */ do_ext_interrupt: - lbz r0, HSTATE_HOST_IPI(r13) - cmpwi r0, 0 - bne ext_interrupt_to_host - - /* Now read the interrupt from the ICP */ - ld r5, HSTATE_XICS_PHYS(r13) - li r7, XICS_XIRR - cmpdi r5, 0 - beq- ext_interrupt_to_host - lwzcix r3, r5, r7 - rlwinm. r0, r3, 0, 0xffffff - sync - beq 3f /* if nothing pending in the ICP */ - - /* We found something in the ICP... - * - * If it's not an IPI, stash it in the PACA and return to - * the host, we don't (yet) handle directing real external - * interrupts directly to the guest - */ - cmpwi r0, XICS_IPI - bne ext_stash_for_host - - /* It's an IPI, clear the MFRR and EOI it */ - li r0, 0xff - li r6, XICS_MFRR - stbcix r0, r5, r6 /* clear the IPI */ - stwcix r3, r5, r7 /* EOI it */ - sync - - /* We need to re-check host IPI now in case it got set in the - * meantime. If it's clear, we bounce the interrupt to the - * guest - */ - lbz r0, HSTATE_HOST_IPI(r13) - cmpwi r0, 0 - bne- 1f + bl kvmppc_read_intr + cmpdi r3, 0 + bgt ext_interrupt_to_host /* Allright, looks like an IPI for the guest, we need to set MER */ -3: /* Check if any CPU is heading out to the host, if so head out too */ ld r5, HSTATE_KVM_VCORE(r13) lwz r0, VCORE_ENTRY_EXIT(r5)
@@ -930,17 +895,6 @@ do_ext_interrupt: mtspr SPRN_LPCR, r8 b fast_guest_return - /* We raced with the host, we need to resend that IPI, bummer */ -1: li r0, IPI_PRIORITY - stbcix r0, r5, r6 /* set the IPI */ - sync - b ext_interrupt_to_host - -ext_stash_for_host: - /* It's not an IPI and it's for the host, stash it in the PACA - * before exit, it will be picked up by the host ICP driver - */ - stw r3, HSTATE_SAVED_XIRR(r13) ext_interrupt_to_host: guest_exit_cont: /* r9 = vcpu, r12 = trap, r13 = paca */
@@ -1816,6 +1770,71 @@ machine_check_realmode: b fast_interrupt_c_return /* + * Determine what sort of external interrupt is pending (if any). + * Returns: + * 0 if no interrupt is pending + * 1 if an interrupt is pending that needs to be handled by the host + * -1 if there was a guest wakeup IPI (which has now been cleared) + */ +kvmppc_read_intr: + /* see if a host IPI is pending */ + li r3, 1 + lbz r0, HSTATE_HOST_IPI(r13) + cmpwi r0, 0 + bne 1f + + /* Now read the interrupt from the ICP */ + ld r6, HSTATE_XICS_PHYS(r13) + li r7, XICS_XIRR + cmpdi r6, 0 + beq- 1f + lwzcix r0, r6, r7 + rlwinm. r3, r0, 0, 0xffffff + sync + beq 1f /* if nothing pending in the ICP */ + + /* We found something in the ICP... + * + * If it's not an IPI, stash it in the PACA and return to + * the host, we don't (yet) handle directing real external + * interrupts directly to the guest + */ + cmpwi r3, XICS_IPI /* if there is, is it an IPI? */ + li r3, 1 + bne 42f + + /* It's an IPI, clear the MFRR and EOI it */ + li r3, 0xff + li r8, XICS_MFRR + stbcix r3, r6, r8 /* clear the IPI */ + stwcix r0, r6, r7 /* EOI it */ + sync + + /* We need to re-check host IPI now in case it got set in the + * meantime. If it's clear, we bounce the interrupt to the + * guest + */ + lbz r0, HSTATE_HOST_IPI(r13) + cmpwi r0, 0 + bne- 43f + + /* OK, it's an IPI for us */ + li r3, -1 +1: blr + +42: /* It's not an IPI and it's for the host, stash it in the PACA + * before exit, it will be picked up by the host ICP driver + */ + stw r0, HSTATE_SAVED_XIRR(r13) + b 1b + +43: /* We raced with the host, we need to resend that IPI, bummer */ + li r0, IPI_PRIORITY + stbcix r0, r6, r8 /* set the IPI */ + sync + b 1b + +/* * Save away FP, VMX and VSX registers. * r3 = vcpu pointer */
Signature · 1 line
1.8.1.4
[PULL 08/51] KVM: PPC: Book3S HV: Avoid unbalanced increments of VPA yield count
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
The yield count in the VPA is supposed to be incremented every time we enter the guest, and every time we exit the guest, so that its value is even when the vcpu is running in the guest and odd when it isn't. However, it's currently possible that we increment the yield count on the way into the guest but then find that other CPU threads are already exiting the guest, so we go back to nap mode via the secondary_too_late label. In this situation we don't increment the yield count again, breaking the relationship between the LSB of the count and whether the vcpu is in the guest.
To fix this, we move the increment of the yield count to a point after we have checked whether other CPU threads are exiting.
--- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
arch/powerpc/kvm/book3s_hv_rmhandlers.S +10 -10
@@ -405,16 +405,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) /* Save R1 in the PACA */ std r1, HSTATE_HOST_R1(r13) - /* Increment yield count if they have a VPA */ - ld r3, VCPU_VPA(r4) - cmpdi r3, 0 - beq 25f - lwz r5, LPPACA_YIELDCOUNT(r3) - addi r5, r5, 1 - stw r5, LPPACA_YIELDCOUNT(r3) - li r6, 1 - stb r6, VCPU_VPA_DIRTY(r4) -25: /* Load up DAR and DSISR */ ld r5, VCPU_DAR(r4) lwz r6, VCPU_DSISR(r4)
@@ -525,6 +515,16 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201) mtspr SPRN_RMOR,r8 isync + /* Increment yield count if they have a VPA */ + ld r3, VCPU_VPA(r4) + cmpdi r3, 0 + beq 25f + lwz r5, LPPACA_YIELDCOUNT(r3) + addi r5, r5, 1 + stw r5, LPPACA_YIELDCOUNT(r3) + li r6, 1 + stb r6, VCPU_VPA_DIRTY(r4) +25: /* Check if HDEC expires soon */ mfspr r3,SPRN_HDEC cmpwi r3,10
Signature · 1 line
1.8.1.4
[PULL 09/51] KVM: PPC: BookE: Add GET/SET_ONE_REG interface for VRSAVE
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
This makes the VRSAVE register value for a vcpu accessible through the GET/SET_ONE_REG interface on Book E systems (in addition to the existing GET/SET_SREGS interface), for consistency with Book 3S.
--- arch/powerpc/kvm/booke.c | 6 ++++++ 1 file changed, 6 insertions(+)
arch/powerpc/kvm/booke.c +6 -0
@@ -1479,6 +1479,9 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)case KVM_REG_PPC_DEBUG_INST : val =get_reg_val (reg->id,KVMPPC_INST_EHPRIV );break ; +case KVM_REG_PPC_VRSAVE : + val =get_reg_val (reg->id, vcpu->arch.vrsave); +break ;default : r =kvmppc_get_one_reg (vcpu, reg->id, &val);break ;
@@ -1552,6 +1555,9 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)kvmppc_set_tcr (vcpu, tcr);break ; } +case KVM_REG_PPC_VRSAVE : + vcpu->arch.vrsave =set_reg_val (reg->id, val); +break ;default : r =kvmppc_set_one_reg (vcpu, reg->id, &val);break ;
Signature · 1 line
1.8.1.4
[PULL 10/51] KVM: PPC: Book3S HV: Store LPCR value for each virtual core
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
This adds the ability to have a separate LPCR (Logical Partitioning Control Register) value relating to a guest for each virtual core, rather than only having a single value for the whole VM. This corresponds to what real POWER hardware does, where there is a LPCR per CPU thread but most of the fields are required to have the same value on all active threads in a core.
The per-virtual-core LPCR can be read and written using the GET/SET_ONE_REG interface. Userspace can can only modify the following fields of the LPCR value:
DPFD Default prefetch depth
ILE Interrupt little-endian
TC Translation control (secondary HPT hash group search disable)
We still maintain a per-VM default LPCR value in kvm->arch.lpcr, which contains bits relating to memory management, i.e. the Virtualized Partition Memory (VPM) bits and the bits relating to guest real mode. When this default value is updated, the update needs to be propagated to the per-vcore values, so we add a kvmppc_update_lpcr() helper to do that.
--- Documentation/virtual/kvm/api.txt | 1 + arch/powerpc/include/asm/kvm_book3s.h | 2 + arch/powerpc/include/asm/kvm_host.h | 1 + arch/powerpc/include/asm/reg.h | 3 ++ arch/powerpc/include/uapi/asm/kvm.h | 1 + arch/powerpc/kernel/asm-offsets.c | 1 + arch/powerpc/kvm/book3s_64_mmu_hv.c | 5 +-- arch/powerpc/kvm/book3s_hv.c | 73 +++++++++++++++++++++++++++------ arch/powerpc/kvm/book3s_hv_rmhandlers.S | 5 ++- 9 files changed, 75 insertions(+), 17 deletions(-)
Documentation/virtual/kvm/api.txt +1 -0
@@ -1835,6 +1835,7 @@ registers, find a list below: PPC | KVM_REG_PPC_PID | 64 PPC | KVM_REG_PPC_ACOP | 64 PPC | KVM_REG_PPC_VRSAVE | 32 + PPC | KVM_REG_PPC_LPCR | 64 PPC | KVM_REG_PPC_TM_GPR0 | 64 ... PPC | KVM_REG_PPC_TM_GPR31 | 64
arch/powerpc/include/asm/kvm_book3s.h +2 -0
@@ -172,6 +172,8 @@ extern long kvmppc_do_h_remove(struct kvm *kvm, unsigned long flags, unsigned long *hpret);extern long kvmppc_hv_get_dirty_log (struct kvm *kvm,struct kvm_memory_slot *memslot,unsigned long *map); +extern void kvmppc_update_lpcr (struct kvm *kvm,unsigned long lpcr, +unsigned long mask);extern void kvmppc_entry_trampoline (void );extern void kvmppc_hv_entry_trampoline (void );
arch/powerpc/include/asm/kvm_host.h +1 -0
@@ -290,6 +290,7 @@ struct kvmppc_vcore {u64 preempt_tb;struct kvm_vcpu *runner;u64 tb_offset;/* guest timebase - host timebase */ +ulong lpcr; };#define VCORE_ENTRY_COUNT (vc) ((vc)->entry_exit_count & 0xff)
arch/powerpc/include/asm/reg.h +3 -0
@@ -284,6 +284,7 @@#define LPCR_ISL (1ul << (63-2))#define LPCR_VC_SH (63-2)#define LPCR_DPFD_SH (63-11) +#define LPCR_DPFD (7ul << LPCR_DPFD_SH)#define LPCR_VRMASD (0x1ful << (63-16))#define LPCR_VRMA_L (1ul << (63-12))#define LPCR_VRMA_LP0 (1ul << (63-15))
@@ -300,6 +301,7 @@#define LPCR_PECE2 0x00001000/* machine check etc can cause exit */ #define LPCR_MER 0x00000800/* Mediated External Exception */ #define LPCR_MER_SH 11 +#define LPCR_TC 0x00000200/* Translation control */ #define LPCR_LPES 0x0000000c#define LPCR_LPES0 0x00000008/* LPAR Env selector 0 */ #define LPCR_LPES1 0x00000004/* LPAR Env selector 1 */
@@ -421,6 +423,7 @@#define HID4_RMLS2_SH (63 - 2)/* Real mode limit bottom 2 bits */ #define HID4_LPID5_SH (63 - 6)/* partition ID bottom 4 bits */ #define HID4_RMOR_SH (63 - 22)/* real mode offset (16 bits) */ +#define HID4_RMOR (0xFFFFul << HID4_RMOR_SH)#define HID4_LPES1 (1 << (63-57))/* LPAR env. sel. bit 1 */ #define HID4_RMLS0_SH (63 - 58)/* Real mode limit top bit */ #define HID4_LPID1_SH 0/* partition ID top 2 bits */
arch/powerpc/include/uapi/asm/kvm.h +1 -0
@@ -533,6 +533,7 @@ struct kvm_get_htab_header {#define KVM_REG_PPC_ACOP (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb3)#define KVM_REG_PPC_VRSAVE (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xb4) +#define KVM_REG_PPC_LPCR (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xb5)/* Transactional Memory checkpointed state: * This is all GPRs, all VSX regs and a subset of SPRs
arch/powerpc/kernel/asm-offsets.c +1 -0
@@ -524,6 +524,7 @@ int main(void)DEFINE (VCORE_IN_GUEST , offsetof(struct kvmppc_vcore , in_guest));DEFINE (VCORE_NAPPING_THREADS , offsetof(struct kvmppc_vcore , napping_threads));DEFINE (VCORE_TB_OFFSET , offsetof(struct kvmppc_vcore , tb_offset)); +DEFINE (VCORE_LPCR , offsetof(struct kvmppc_vcore , lpcr));DEFINE (VCPU_SVCPU , offsetof(struct kvmppc_vcpu_book3s , shadow_vcpu) - offsetof(struct kvmppc_vcpu_book3s , vcpu));DEFINE (VCPU_SLB_E , offsetof(struct kvmppc_slb , orige));
arch/powerpc/kvm/book3s_64_mmu_hv.c +2 -3
@@ -1512,9 +1512,8 @@ static ssize_t kvm_htab_write(struct file *file, const char __user *buf, kvm->arch.vrma_slb_v = senc |SLB_VSID_B_1T | (VRMA_VSID <<SLB_VSID_SHIFT_1T ); - lpcr = kvm->arch.lpcr & ~LPCR_VRMASD ; - lpcr |= senc << (LPCR_VRMASD_SH -4 ); - kvm->arch.lpcr = lpcr; + lpcr = senc << (LPCR_VRMASD_SH -4 ); +kvmppc_update_lpcr (kvm, lpcr,LPCR_VRMASD ); rma_setup =1 ; } ++i;
arch/powerpc/kvm/book3s_hv.c +61 -12
142 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv_rmhandlers.S +3 -2
@@ -509,7 +509,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201) beq 20b /* Set LPCR and RMOR. */ -10: ld r8,KVM_LPCR(r9) +10: ld r8,VCORE_LPCR(r5) mtspr SPRN_LPCR,r8 ld r8,KVM_RMOR(r9) mtspr SPRN_RMOR,r8
@@ -571,7 +571,8 @@ toc_tlbie_lock: bne 24b isync - ld r7,KVM_LPCR(r9) /* use kvm->arch.lpcr to store HID4 */ + ld r5,HSTATE_KVM_VCORE(r13) + ld r7,VCORE_LPCR(r5) /* use vcore->lpcr to store HID4 */ li r0,0x18f rotldi r0,r0,HID4_LPID5_SH /* all lpid bits in HID4 = 1 */ or r0,r7,r0
Signature · 1 line
1.8.1.4
[PULL 11/51] KVM: PPC: Book3S HV: Add support for guest Program Priority Register
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
POWER7 and later IBM server processors have a register called the Program Priority Register (PPR), which controls the priority of each hardware CPU SMT thread, and affects how fast it runs compared to other SMT threads. This priority can be controlled by writing to the PPR or by use of a set of instructions of the form or rN,rN,rN which are otherwise no-ops but have been defined to set the priority to particular levels.
This adds code to context switch the PPR when entering and exiting guests and to make the PPR value accessible through the SET/GET_ONE_REG interface. When entering the guest, we set the PPR as late as possible, because if we are setting a low thread priority it will make the code run slowly from that point on. Similarly, the first-level interrupt handlers save the PPR value in the PACA very early on, and set the thread priority to the medium level, so that the interrupt handling code runs at a reasonable speed.
--- Documentation/virtual/kvm/api.txt | 1 + arch/powerpc/include/asm/exception-64s.h | 8 ++++++++ arch/powerpc/include/asm/kvm_book3s_asm.h | 1 + arch/powerpc/include/asm/kvm_host.h | 1 + arch/powerpc/include/uapi/asm/kvm.h | 1 + arch/powerpc/kernel/asm-offsets.c | 2 ++ arch/powerpc/kvm/book3s_hv.c | 6 ++++++ arch/powerpc/kvm/book3s_hv_rmhandlers.S | 12 +++++++++++- 8 files changed, 31 insertions(+), 1 deletion(-)
Documentation/virtual/kvm/api.txt +1 -0
@@ -1836,6 +1836,7 @@ registers, find a list below: PPC | KVM_REG_PPC_ACOP | 64 PPC | KVM_REG_PPC_VRSAVE | 32 PPC | KVM_REG_PPC_LPCR | 64 + PPC | KVM_REG_PPC_PPR | 64 PPC | KVM_REG_PPC_TM_GPR0 | 64 ... PPC | KVM_REG_PPC_TM_GPR31 | 64
arch/powerpc/include/asm/exception-64s.h +8 -0
@@ -204,6 +204,10 @@ do_kvm_##n: \ ld r10,area+EX_CFAR(r13); \std r10,HSTATE_CFAR (r13 ); \END_FTR_SECTION_NESTED (CPU_FTR_CFAR ,CPU_FTR_CFAR ,947 ); \ + BEGIN_FTR_SECTION_NESTED(948) \ + ld r10,area+EX_PPR(r13); \ +std r10,HSTATE_PPR (r13 ); \ +END_FTR_SECTION_NESTED (CPU_FTR_HAS_PPR ,CPU_FTR_HAS_PPR ,948 ); \ ld r10,area+EX_R10(r13); \stw r9,HSTATE_SCRATCH1 (r13 ); \ ld r9,area+EX_R9(r13); \
@@ -217,6 +221,10 @@ do_kvm_##n: \ ld r10,area+EX_R10(r13); \ beq 89f; \stw r9,HSTATE_SCRATCH1 (r13 ); \ + BEGIN_FTR_SECTION_NESTED(948) \ + ld r9,area+EX_PPR(r13); \ +std r9,HSTATE_PPR (r13 ); \ +END_FTR_SECTION_NESTED (CPU_FTR_HAS_PPR ,CPU_FTR_HAS_PPR ,948 ); \ ld r9,area+EX_R9(r13); \std r12,HSTATE_SCRATCH0 (r13 ); \li r12,n; \
arch/powerpc/include/asm/kvm_book3s_asm.h +1 -0
@@ -101,6 +101,7 @@ struct kvmppc_host_state {#endif #ifdef CONFIG_PPC_BOOK3S_64 u64 cfar; +u64 ppr;#endif };
arch/powerpc/include/asm/kvm_host.h +1 -0
@@ -460,6 +460,7 @@ struct kvm_vcpu_arch {u32 ctrl;ulong dabr;ulong cfar; +ulong ppr;#endif u32 vrsave;/* also USPRG0 */ u32 mmucr;
arch/powerpc/include/uapi/asm/kvm.h +1 -0
@@ -534,6 +534,7 @@ struct kvm_get_htab_header {#define KVM_REG_PPC_VRSAVE (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xb4)#define KVM_REG_PPC_LPCR (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xb5) +#define KVM_REG_PPC_PPR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb6)/* Transactional Memory checkpointed state: * This is all GPRs, all VSX regs and a subset of SPRs
arch/powerpc/kernel/asm-offsets.c +2 -0
@@ -519,6 +519,7 @@ int main(void) DEFINE(VCPU_TRAP, offsetof(struct kvm_vcpu, arch.trap)); DEFINE(VCPU_PTID, offsetof(struct kvm_vcpu, arch.ptid)); DEFINE(VCPU_CFAR, offsetof(struct kvm_vcpu, arch.cfar)); + DEFINE(VCPU_PPR, offsetof(struct kvm_vcpu, arch.ppr));DEFINE (VCORE_ENTRY_EXIT , offsetof(struct kvmppc_vcore , entry_exit_count));DEFINE (VCORE_NAP_COUNT , offsetof(struct kvmppc_vcore , nap_count));DEFINE (VCORE_IN_GUEST , offsetof(struct kvmppc_vcore , in_guest));
@@ -604,6 +605,7 @@ int main(void)#ifdef CONFIG_PPC_BOOK3S_64 HSTATE_FIELD (HSTATE_CFAR , cfar); +HSTATE_FIELD (HSTATE_PPR , ppr);#endif /* CONFIG_PPC_BOOK3S_64 */ #else /* CONFIG_PPC_BOOK3S */
arch/powerpc/kvm/book3s_hv.c +6 -0
@@ -823,6 +823,9 @@ int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *val)case KVM_REG_PPC_LPCR : *val =get_reg_val (id, vcpu->arch.vcore->lpcr);break ; +case KVM_REG_PPC_PPR : + *val =get_reg_val (id, vcpu->arch.ppr); +break ;default : r = -EINVAL ;break ;
@@ -930,6 +933,9 @@ int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *val)case KVM_REG_PPC_LPCR :kvmppc_set_lpcr (vcpu,set_reg_val (id, *val));break ; +case KVM_REG_PPC_PPR : + vcpu->arch.ppr =set_reg_val (id, *val); +break ;default : r = -EINVAL ;break ;
arch/powerpc/kvm/book3s_hv_rmhandlers.S +11 -1
@@ -717,13 +717,15 @@ BEGIN_FTR_SECTION ld r5, VCPU_CFAR(r4) mtspr SPRN_CFAR, r5 END_FTR_SECTION_IFSET(CPU_FTR_CFAR) +BEGIN_FTR_SECTION + ld r0, VCPU_PPR(r4) +END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) ld r5, VCPU_LR(r4) lwz r6, VCPU_CR(r4) mtlr r5 mtcr r6 - ld r0, VCPU_GPR(R0)(r4) ld r1, VCPU_GPR(R1)(r4) ld r2, VCPU_GPR(R2)(r4) ld r3, VCPU_GPR(R3)(r4)
@@ -737,6 +739,10 @@ END_FTR_SECTION_IFSET(CPU_FTR_CFAR) ld r12, VCPU_GPR(R12)(r4) ld r13, VCPU_GPR(R13)(r4) +BEGIN_FTR_SECTION + mtspr SPRN_PPR, r0 +END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) + ld r0, VCPU_GPR(R0)(r4) ld r4, VCPU_GPR(R4)(r4) hrfid
@@ -787,6 +793,10 @@ BEGIN_FTR_SECTION ld r3, HSTATE_CFAR(r13) std r3, VCPU_CFAR(r9) END_FTR_SECTION_IFSET(CPU_FTR_CFAR) +BEGIN_FTR_SECTION + ld r4, HSTATE_PPR(r13) + std r4, VCPU_PPR(r9) +END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) /* Restore R1/R2 so we can handle faults */ ld r1, HSTATE_HOST_R1(r13)
Signature · 1 line
1.8.1.4
[PULL 12/51] KVM: PPC: Book3S HV: Support POWER6 compatibility mode on POWER7
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
This enables us to use the Processor Compatibility Register (PCR) on POWER7 to put the processor into architecture 2.05 compatibility mode when running a guest. In this mode the new instructions and registers that were introduced on POWER7 are disabled in user mode. This includes all the VSX facilities plus several other instructions such as ldbrx, stdbrx, popcntw, popcntd, etc.
To select this mode, we have a new register accessible through the set/get_one_reg interface, called KVM_REG_PPC_ARCH_COMPAT. Setting this to zero gives the full set of capabilities of the processor. Setting it to one of the "logical" PVR values defined in PAPR puts the vcpu into the compatibility mode for the corresponding architecture level. The supported values are:
0x0f000002 Architecture 2.05 (POWER6)0x0f000003 Architecture 2.06 (POWER7)0x0f100003 Architecture 2.06+ (POWER7+)
Since the PCR is per-core, the architecture compatibility level and the corresponding PCR value are stored in the struct kvmppc_vcore, and are therefore shared between all vcpus in a virtual core.
--- Documentation/virtual/kvm/api.txt | 1 + arch/powerpc/include/asm/kvm_host.h | 2 ++ arch/powerpc/include/asm/reg.h | 11 +++++++++++ arch/powerpc/include/uapi/asm/kvm.h | 3 +++ arch/powerpc/kernel/asm-offsets.c | 1 + arch/powerpc/kvm/book3s_hv.c | 35 +++++++++++++++++++++++++++++++++ arch/powerpc/kvm/book3s_hv_rmhandlers.S | 16 +++++++++++++-- 7 files changed, 67 insertions(+), 2 deletions(-)
Documentation/virtual/kvm/api.txt +1 -0
@@ -1837,6 +1837,7 @@ registers, find a list below: PPC | KVM_REG_PPC_VRSAVE | 32 PPC | KVM_REG_PPC_LPCR | 64 PPC | KVM_REG_PPC_PPR | 64 + PPC | KVM_REG_PPC_ARCH_COMPAT 32 PPC | KVM_REG_PPC_TM_GPR0 | 64 ... PPC | KVM_REG_PPC_TM_GPR31 | 64
arch/powerpc/include/asm/kvm_host.h +2 -0
@@ -291,6 +291,8 @@ struct kvmppc_vcore {struct kvm_vcpu *runner;u64 tb_offset;/* guest timebase - host timebase */ ulong lpcr; +u32 arch_compat; +ulong pcr; };#define VCORE_ENTRY_COUNT (vc) ((vc)->entry_exit_count & 0xff)
arch/powerpc/include/asm/reg.h +11 -0
@@ -314,6 +314,10 @@#define LPID_RSVD 0x3ff/* Reserved LPID for partn switching */ #define SPRN_HMER 0x150/* Hardware m? error recovery */ #define SPRN_HMEER 0x151/* Hardware m? enable error recovery */ +#define SPRN_PCR 0x152/* Processor compatibility register */ +#define PCR_VEC_DIS (1ul << (63-0))/* Vec. disable (bit NA since POWER8) */ +#define PCR_VSX_DIS (1ul << (63-1))/* VSX disable (bit NA since POWER8) */ +#define PCR_ARCH_205 0x2/* Architecture 2.05 */ #define SPRN_HEIR 0x153/* Hypervisor Emulated Instruction Register */ #define SPRN_TLBINDEXR 0x154/* P7 TLB control register */ #define SPRN_TLBVPNR 0x155/* P7 TLB control register */
@@ -1106,6 +1110,13 @@#define PVR_BE 0x0070#define PVR_PA6T 0x0090 +/* "Logical" PVR values defined in PAPR, representing architecture levels */ +#define PVR_ARCH_204 0x0f000001 +#define PVR_ARCH_205 0x0f000002 +#define PVR_ARCH_206 0x0f000003 +#define PVR_ARCH_206p 0x0f100003 +#define PVR_ARCH_207 0x0f000004 +/* Macros for setting and retrieving special purpose registers */ #ifndef __ASSEMBLY__#define mfmsr () ({unsigned long rval; \
arch/powerpc/include/uapi/asm/kvm.h +3 -0
@@ -536,6 +536,9 @@ struct kvm_get_htab_header {#define KVM_REG_PPC_LPCR (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xb5)#define KVM_REG_PPC_PPR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb6) +/* Architecture compatibility level */ +#define KVM_REG_PPC_ARCH_COMPAT (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xb7) +/* Transactional Memory checkpointed state: * This is all GPRs, all VSX regs and a subset of SPRs */
arch/powerpc/kernel/asm-offsets.c +1 -0
@@ -526,6 +526,7 @@ int main(void)DEFINE (VCORE_NAPPING_THREADS , offsetof(struct kvmppc_vcore , napping_threads));DEFINE (VCORE_TB_OFFSET , offsetof(struct kvmppc_vcore , tb_offset));DEFINE (VCORE_LPCR , offsetof(struct kvmppc_vcore , lpcr)); +DEFINE (VCORE_PCR , offsetof(struct kvmppc_vcore , pcr));DEFINE (VCPU_SVCPU , offsetof(struct kvmppc_vcpu_book3s , shadow_vcpu) - offsetof(struct kvmppc_vcpu_book3s , vcpu));DEFINE (VCPU_SLB_E , offsetof(struct kvmppc_slb , orige));
arch/powerpc/kvm/book3s_hv.c +35 -0
@@ -166,6 +166,35 @@ void kvmppc_set_pvr(struct kvm_vcpu *vcpu, u32 pvr) vcpu->arch.pvr = pvr; } +int kvmppc_set_arch_compat (struct kvm_vcpu *vcpu,u32 arch_compat) +{ +unsigned long pcr =0 ; +struct kvmppc_vcore *vc = vcpu->arch.vcore; + +if (arch_compat) { +if (!cpu_has_feature (CPU_FTR_ARCH_206 )) +return -EINVAL ;/* 970 has no compat mode support */ + +switch (arch_compat) { +case PVR_ARCH_205 : + pcr =PCR_ARCH_205 ; +break ; +case PVR_ARCH_206 : +case PVR_ARCH_206p: +break ; +default : +return -EINVAL ; + } + } + +spin_lock (&vc->lock); + vc->arch_compat = arch_compat; + vc->pcr = pcr; +spin_unlock (&vc->lock); + +return 0 ; +} +void kvmppc_dump_regs (struct kvm_vcpu *vcpu) {int r;
@@ -826,6 +855,9 @@ int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *val)case KVM_REG_PPC_PPR : *val =get_reg_val (id, vcpu->arch.ppr);break ; +case KVM_REG_PPC_ARCH_COMPAT : + *val =get_reg_val (id, vcpu->arch.vcore->arch_compat); +break ;default : r = -EINVAL ;break ;
@@ -936,6 +968,9 @@ int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *val)case KVM_REG_PPC_PPR : vcpu->arch.ppr =set_reg_val (id, *val);break ; +case KVM_REG_PPC_ARCH_COMPAT : + r =kvmppc_set_arch_compat (vcpu,set_reg_val (id, *val)); +break ;default : r = -EINVAL ;break ;
arch/powerpc/kvm/book3s_hv_rmhandlers.S +14 -2
@@ -499,7 +499,13 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201) addis r8,r8,0x100 /* if so, increment upper 40 bits */ mtspr SPRN_TBU40,r8 -37: li r0,1 + /* Load guest PCR value to select appropriate compat mode */ +37: ld r7, VCORE_PCR(r5) + cmpdi r7, 0 + beq 38f + mtspr SPRN_PCR, r7 +38: + li r0,1 stb r0,VCORE_IN_GUEST(r5) /* signal secondaries to continue */ b 10f
@@ -1094,8 +1100,14 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201) addis r8,r8,0x100 /* if so, increment upper 40 bits */ mtspr SPRN_TBU40,r8 + /* Reset PCR */ +17: ld r0, VCORE_PCR(r5) + cmpdi r0, 0 + beq 18f + li r0, 0 + mtspr SPRN_PCR, r0 +18: /* Signal secondary CPUs to continue */ -17: li r0,0 stb r0,VCORE_IN_GUEST(r5) lis r8,0x7fff /* MAX_INT@h */ mtspr SPRN_HDEC,r8
Signature · 1 line
1.8.1.4
[PULL 13/51] KVM: PPC: Book3S HV: Don't crash host on unknown guest interrupt
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
If we come out of a guest with an interrupt that we don't know about, instead of crashing the host with a BUG(), we now return to userspace with the exit reason set to KVM_EXIT_UNKNOWN and the trap vector in the hw.hardware_exit_reason field of the kvm_run structure, as is done on x86. Note that run->exit_reason is already set to KVM_EXIT_UNKNOWN at the beginning of kvmppc_handle_exit().
--- arch/powerpc/kvm/book3s_hv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kvm/book3s_hv.c +1 -1
@@ -709,8 +709,8 @@ static int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,printk (KERN_EMERG "trap=0x%x | pc=0x%lx | msr=0x%llx\n" , vcpu->arch.trap,kvmppc_get_pc (vcpu), vcpu->arch.shregs.msr); + run->hw.hardware_exit_reason = vcpu->arch.trap; r =RESUME_HOST ; -BUG ();break ; }
Signature · 1 line
1.8.1.4
[PULL 14/51] KVM: PPC: Book3S PR: Fix compilation without CONFIG_ALTIVEC
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
Commit 9d1ffdd8f3 ("KVM: PPC: Book3S PR: Don't corrupt guest state when kernel uses VMX") added a call to kvmppc_load_up_altivec() that isn't guarded by CONFIG_ALTIVEC, causing a link failure when building a kernel without CONFIG_ALTIVEC set. This adds an #ifdef to fix this.
--- arch/powerpc/kvm/book3s_pr.c | 2 ++ 1 file changed, 2 insertions(+)
arch/powerpc/kvm/book3s_pr.c +2 -0
@@ -619,8 +619,10 @@ static void kvmppc_handle_lost_ext(struct kvm_vcpu *vcpu)if (lost_ext &MSR_FP )kvmppc_load_up_fpu (); +#ifdef CONFIG_ALTIVEC if (lost_ext &MSR_VEC )kvmppc_load_up_altivec (); +#endif current->thread.regs->msr |= lost_ext; }
Signature · 1 line
1.8.1.4
[PULL 15/51] KVM: PPC: Book3S PR: Keep volatile reg values in vcpu rather than shadow_vcpu
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
Currently PR-style KVM keeps the volatile guest register values (R0 - R13, CR, LR, CTR, XER, PC) in a shadow_vcpu struct rather than the main kvm_vcpu struct. For 64-bit, the shadow_vcpu exists in two places, a kmalloc'd struct and in the PACA, and it gets copied back and forth in kvmppc_core_vcpu_load/put(), because the real-mode code can't rely on being able to access the kmalloc'd struct.
This changes the code to copy the volatile values into the shadow_vcpu as one of the last things done before entering the guest. Similarly the values are copied back out of the shadow_vcpu to the kvm_vcpu immediately after exiting the guest. We arrange for interrupts to be still disabled at this point so that we can't get preempted on 64-bit and end up copying values from the wrong PACA.
This means that the accessor functions in kvm_book3s.h for these registers are greatly simplified, and are same between PR and HV KVM. In places where accesses to shadow_vcpu fields are now replaced by accesses to the kvm_vcpu, we can also remove the svcpu_get/put pairs. Finally, on 64-bit, we don't need the kmalloc'd struct at all any more.
With this, the time to read the PVR one million times in a loop went from 567.7ms to 575.5ms (averages of 6 values), an increase of about 1.4% for this worse-case test for guest entries and exits. The standard deviation of the measurements is about 11ms, so the difference is only marginally significant statistically.
--- arch/powerpc/include/asm/kvm_book3s.h | 220 +++++------------------------- arch/powerpc/include/asm/kvm_book3s_asm.h | 6 +- arch/powerpc/include/asm/kvm_host.h | 1 + arch/powerpc/kernel/asm-offsets.c | 4 +- arch/powerpc/kvm/book3s_emulate.c | 8 +- arch/powerpc/kvm/book3s_interrupts.S | 27 +++- arch/powerpc/kvm/book3s_pr.c | 122 ++++++++++++----- arch/powerpc/kvm/book3s_rmhandlers.S | 6 +- arch/powerpc/kvm/trace.h | 7 +- 9 files changed, 162 insertions(+), 239 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +35 -185
@@ -200,140 +200,76 @@ extern void kvm_return_point(void);#include <asm/kvm_book3s_64.h> #endif -#ifdef CONFIG_KVM_BOOK3S_PR - -static inline unsigned long kvmppc_interrupt_offset (struct kvm_vcpu *vcpu) -{ -return to_book3s (vcpu)->hior; -} - -static inline void kvmppc_update_int_pending (struct kvm_vcpu *vcpu, -unsigned long pending_now,unsigned long old_pending) -{ -if (pending_now) - vcpu->arch.shared->int_pending =1 ; -else if (old_pending) - vcpu->arch.shared->int_pending =0 ; -} -static inline void kvmppc_set_gpr (struct kvm_vcpu *vcpu,int num,ulong val) { -if ( num <14 ) { -struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); - svcpu->gpr[num] = val; -svcpu_put (svcpu); -to_book3s (vcpu)->shadow_vcpu->gpr[num] = val; - }else - vcpu->arch.gpr[num] = val; + vcpu->arch.gpr[num] = val; }static inline ulong kvmppc_get_gpr (struct kvm_vcpu *vcpu,int num) { -if ( num <14 ) { -struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); -ulong r = svcpu->gpr[num]; -svcpu_put (svcpu); -return r; - }else -return vcpu->arch.gpr[num]; +return vcpu->arch.gpr[num]; }static inline void kvmppc_set_cr (struct kvm_vcpu *vcpu,u32 val) { -struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); - svcpu->cr = val; -svcpu_put (svcpu); -to_book3s (vcpu)->shadow_vcpu->cr = val; + vcpu->arch.cr = val; }static inline u32 kvmppc_get_cr (struct kvm_vcpu *vcpu) { -struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); -u32 r; - r = svcpu->cr; -svcpu_put (svcpu); -return r; +return vcpu->arch.cr; }static inline void kvmppc_set_xer (struct kvm_vcpu *vcpu,u32 val) { -struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); - svcpu->xer = val; -to_book3s (vcpu)->shadow_vcpu->xer = val; -svcpu_put (svcpu); + vcpu->arch.xer = val; }static inline u32 kvmppc_get_xer (struct kvm_vcpu *vcpu) { -struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); -u32 r; - r = svcpu->xer; -svcpu_put (svcpu); -return r; +return vcpu->arch.xer; }static inline void kvmppc_set_ctr (struct kvm_vcpu *vcpu,ulong val) { -struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); - svcpu->ctr = val; -svcpu_put (svcpu); + vcpu->arch.ctr = val; }static inline ulong kvmppc_get_ctr (struct kvm_vcpu *vcpu) { -struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); -ulong r; - r = svcpu->ctr; -svcpu_put (svcpu); -return r; +return vcpu->arch.ctr; }static inline void kvmppc_set_lr (struct kvm_vcpu *vcpu,ulong val) { -struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); - svcpu->lr = val; -svcpu_put (svcpu); + vcpu->arch.lr = val; }static inline ulong kvmppc_get_lr (struct kvm_vcpu *vcpu) { -struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); -ulong r; - r = svcpu->lr; -svcpu_put (svcpu); -return r; +return vcpu->arch.lr; }static inline void kvmppc_set_pc (struct kvm_vcpu *vcpu,ulong val) { -struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); - svcpu->pc = val; -svcpu_put (svcpu); + vcpu->arch.pc = val; }static inline ulong kvmppc_get_pc (struct kvm_vcpu *vcpu) { -struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); -ulong r; - r = svcpu->pc; -svcpu_put (svcpu); -return r; +return vcpu->arch.pc; }static inline u32 kvmppc_get_last_inst (struct kvm_vcpu *vcpu) {ulong pc =kvmppc_get_pc (vcpu); -struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); -u32 r;/* Load the instruction manually if it failed to do so in the * exit path */ -if (svcpu->last_inst ==KVM_INST_FETCH_FAILED ) -kvmppc_ld (vcpu, &pc,sizeof (u32), &svcpu->last_inst, false); +if (vcpu->arch.last_inst ==KVM_INST_FETCH_FAILED ) +kvmppc_ld (vcpu, &pc,sizeof (u32), &vcpu->arch.last_inst, false); - r = svcpu->last_inst; -svcpu_put (svcpu); -return r; +return vcpu->arch.last_inst; }/*
@@ -344,26 +280,34 @@ static inline u32 kvmppc_get_last_inst(struct kvm_vcpu *vcpu)static inline u32 kvmppc_get_last_sc (struct kvm_vcpu *vcpu) {ulong pc =kvmppc_get_pc (vcpu) -4 ; -struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); -u32 r;/* Load the instruction manually if it failed to do so in the * exit path */ -if (svcpu->last_inst ==KVM_INST_FETCH_FAILED ) -kvmppc_ld (vcpu, &pc,sizeof (u32), &svcpu->last_inst, false); +if (vcpu->arch.last_inst ==KVM_INST_FETCH_FAILED ) +kvmppc_ld (vcpu, &pc,sizeof (u32), &vcpu->arch.last_inst, false); - r = svcpu->last_inst; -svcpu_put (svcpu); -return r; +return vcpu->arch.last_inst; }static inline ulong kvmppc_get_fault_dar (struct kvm_vcpu *vcpu) { -struct kvmppc_book3s_shadow_vcpu *svcpu =svcpu_get (vcpu); -ulong r; - r = svcpu->fault_dar; -svcpu_put (svcpu); -return r; +return vcpu->arch.fault_dar; +} + +#ifdef CONFIG_KVM_BOOK3S_PR + +static inline unsigned long kvmppc_interrupt_offset (struct kvm_vcpu *vcpu) +{ +return to_book3s (vcpu)->hior; +} + +static inline void kvmppc_update_int_pending (struct kvm_vcpu *vcpu, +unsigned long pending_now,unsigned long old_pending) +{ +if (pending_now) + vcpu->arch.shared->int_pending =1 ; +else if (old_pending) + vcpu->arch.shared->int_pending =0 ; }static inline bool kvmppc_critical_section (struct kvm_vcpu *vcpu)
@@ -397,100 +341,6 @@ static inline void kvmppc_update_int_pending(struct kvm_vcpu *vcpu, { } -static inline void kvmppc_set_gpr (struct kvm_vcpu *vcpu,int num,ulong val) -{ - vcpu->arch.gpr[num] = val; -} - -static inline ulong kvmppc_get_gpr (struct kvm_vcpu *vcpu,int num) -{ -return vcpu->arch.gpr[num]; -} - -static inline void kvmppc_set_cr (struct kvm_vcpu *vcpu,u32 val) -{ - vcpu->arch.cr = val; -} - -static inline u32 kvmppc_get_cr (struct kvm_vcpu *vcpu) -{ -return vcpu->arch.cr; -} - -static inline void kvmppc_set_xer (struct kvm_vcpu *vcpu,u32 val) -{ - vcpu->arch.xer = val; -} - -static inline u32 kvmppc_get_xer (struct kvm_vcpu *vcpu) -{ -return vcpu->arch.xer; -} - -static inline void kvmppc_set_ctr (struct kvm_vcpu *vcpu,ulong val) -{ - vcpu->arch.ctr = val; -} - -static inline ulong kvmppc_get_ctr (struct kvm_vcpu *vcpu) -{ -return vcpu->arch.ctr; -} - -static inline void kvmppc_set_lr (struct kvm_vcpu *vcpu,ulong val) -{ - vcpu->arch.lr = val; -} - -static inline ulong kvmppc_get_lr (struct kvm_vcpu *vcpu) -{ -return vcpu->arch.lr; -} - -static inline void kvmppc_set_pc (struct kvm_vcpu *vcpu,ulong val) -{ - vcpu->arch.pc = val; -} - -static inline ulong kvmppc_get_pc (struct kvm_vcpu *vcpu) -{ -return vcpu->arch.pc; -} - -static inline u32 kvmppc_get_last_inst (struct kvm_vcpu *vcpu) -{ -ulong pc =kvmppc_get_pc (vcpu); - -/* Load the instruction manually if it failed to do so in the -* exit path */ -if (vcpu->arch.last_inst ==KVM_INST_FETCH_FAILED ) -kvmppc_ld (vcpu, &pc,sizeof (u32), &vcpu->arch.last_inst, false); - -return vcpu->arch.last_inst; -} - -/* -* Like kvmppc_get_last_inst(), but for fetching a sc instruction. -* Because the sc instruction sets SRR0 to point to the following -* instruction, we have to fetch from pc - 4. -*/ -static inline u32 kvmppc_get_last_sc (struct kvm_vcpu *vcpu) -{ -ulong pc =kvmppc_get_pc (vcpu) -4 ; - -/* Load the instruction manually if it failed to do so in the -* exit path */ -if (vcpu->arch.last_inst ==KVM_INST_FETCH_FAILED ) -kvmppc_ld (vcpu, &pc,sizeof (u32), &vcpu->arch.last_inst, false); - -return vcpu->arch.last_inst; -} - -static inline ulong kvmppc_get_fault_dar (struct kvm_vcpu *vcpu) -{ -return vcpu->arch.fault_dar; -} -static inline bool kvmppc_critical_section (struct kvm_vcpu *vcpu) {return false;
arch/powerpc/include/asm/kvm_book3s_asm.h +3 -3
@@ -109,14 +109,14 @@ struct kvmppc_book3s_shadow_vcpu {ulong gpr[14 ];u32 cr;u32 xer; - -u32 fault_dsisr; -u32 last_inst;ulong ctr;ulong lr;ulong pc; +ulong shadow_srr1;ulong fault_dar; +u32 fault_dsisr; +u32 last_inst;#ifdef CONFIG_PPC_BOOK3S_32 u32 sr[16 ];/* Guest SRs */
arch/powerpc/include/asm/kvm_host.h +1 -0
@@ -463,6 +463,7 @@ struct kvm_vcpu_arch {ulong dabr;ulong cfar;ulong ppr; +ulong shadow_srr1;#endif u32 vrsave;/* also USPRG0 */ u32 mmucr;
arch/powerpc/kernel/asm-offsets.c +2 -2
@@ -520,6 +520,7 @@ int main(void) DEFINE(VCPU_PTID, offsetof(struct kvm_vcpu, arch.ptid)); DEFINE(VCPU_CFAR, offsetof(struct kvm_vcpu, arch.cfar)); DEFINE(VCPU_PPR, offsetof(struct kvm_vcpu, arch.ppr)); + DEFINE(VCPU_SHADOW_SRR1, offsetof(struct kvm_vcpu, arch.shadow_srr1));DEFINE (VCORE_ENTRY_EXIT , offsetof(struct kvmppc_vcore , entry_exit_count));DEFINE (VCORE_NAP_COUNT , offsetof(struct kvmppc_vcore , nap_count));DEFINE (VCORE_IN_GUEST , offsetof(struct kvmppc_vcore , in_guest));
@@ -527,14 +528,13 @@ int main(void)DEFINE (VCORE_TB_OFFSET , offsetof(struct kvmppc_vcore , tb_offset));DEFINE (VCORE_LPCR , offsetof(struct kvmppc_vcore , lpcr));DEFINE (VCORE_PCR , offsetof(struct kvmppc_vcore , pcr)); -DEFINE (VCPU_SVCPU , offsetof(struct kvmppc_vcpu_book3s , shadow_vcpu) - - offsetof(struct kvmppc_vcpu_book3s , vcpu));DEFINE (VCPU_SLB_E , offsetof(struct kvmppc_slb , orige));DEFINE (VCPU_SLB_V , offsetof(struct kvmppc_slb , origv));DEFINE (VCPU_SLB_SIZE ,sizeof (struct kvmppc_slb ));#ifdef CONFIG_PPC_BOOK3S_64 #ifdef CONFIG_KVM_BOOK3S_PR +DEFINE (PACA_SVCPU , offsetof(struct paca_struct , shadow_vcpu));# define SVCPU_FIELD (x, f) DEFINE(x, offsetof(struct paca_struct, shadow_vcpu.f))#else # define SVCPU_FIELD (x, f)
arch/powerpc/kvm/book3s_emulate.c +2 -6
@@ -267,12 +267,9 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, r =kvmppc_st (vcpu, &addr,32 , zeros, true);if ((r == -ENOENT ) || (r == -EPERM )) { -struct kvmppc_book3s_shadow_vcpu *svcpu; - - svcpu =svcpu_get (vcpu); *advance =0 ; vcpu->arch.shared->dar = vaddr; - svcpu->fault_dar = vaddr; + vcpu->arch.fault_dar = vaddr; dsisr =DSISR_ISSTORE ;if (r == -ENOENT )
@@ -281,8 +278,7 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, dsisr |=DSISR_PROTFAULT ; vcpu->arch.shared->dsisr = dsisr; - svcpu->fault_dsisr = dsisr; -svcpu_put (svcpu); + vcpu->arch.fault_dsisr = dsisr;kvmppc_book3s_queue_irqprio (vcpu,BOOK3S_INTERRUPT_DATA_STORAGE );
arch/powerpc/kvm/book3s_interrupts.S +25 -2
@@ -26,8 +26,12 @@ #if defined(CONFIG_PPC_BOOK3S_64) #define FUNC(name) GLUE(.,name) +#define GET_SHADOW_VCPU(reg) addi reg, r13, PACA_SVCPU + #elif defined(CONFIG_PPC_BOOK3S_32) #define FUNC(name) name +#define GET_SHADOW_VCPU(reg) lwz reg, (THREAD + THREAD_KVM_SVCPU)(r2) + #endif /* CONFIG_PPC_BOOK3S_XX */ #define VCPU_LOAD_NVGPRS(vcpu) \
@@ -87,8 +91,14 @@ kvm_start_entry: VCPU_LOAD_NVGPRS(r4) kvm_start_lightweight: + /* Copy registers into shadow vcpu so we can access them in real mode */ + GET_SHADOW_VCPU(r3) + bl FUNC(kvmppc_copy_to_svcpu) + nop + REST_GPR(4, r1) #ifdef CONFIG_PPC_BOOK3S_64 + /* Get the dcbz32 flag */ PPC_LL r3, VCPU_HFLAGS(r4) rldicl r3, r3, 0, 63 /* r3 &= 1 */ stb r3, HSTATE_RESTORE_HID5(r13)
@@ -125,18 +135,31 @@ kvmppc_handler_highmem: * */ - /* R7 = vcpu */ - PPC_LL r7, GPR4(r1) + /* Transfer reg values from shadow vcpu back to vcpu struct */ + /* On 64-bit, interrupts are still off at this point */ + PPC_LL r3, GPR4(r1) /* vcpu pointer */ + GET_SHADOW_VCPU(r4) + bl FUNC(kvmppc_copy_from_svcpu) + nop #ifdef CONFIG_PPC_BOOK3S_64 + /* Re-enable interrupts */ + ld r3, HSTATE_HOST_MSR(r13) + ori r3, r3, MSR_EE + MTMSR_EERI(r3) + /* * Reload kernel SPRG3 value. * No need to save guest value as usermode can't modify SPRG3. */ ld r3, PACA_SPRG3(r13) mtspr SPRN_SPRG3, r3 + #endif /* CONFIG_PPC_BOOK3S_64 */ + /* R7 = vcpu */ + PPC_LL r7, GPR4(r1) + PPC_STL r14, VCPU_GPR(R14)(r7) PPC_STL r15, VCPU_GPR(R15)(r7) PPC_STL r16, VCPU_GPR(R16)(r7)
arch/powerpc/kvm/book3s_pr.c +88 -34
215 lines not on this page · raw message
arch/powerpc/kvm/book3s_rmhandlers.S +5 -1
@@ -179,11 +179,15 @@ _GLOBAL(kvmppc_entry_trampoline) li r6, MSR_IR | MSR_DR andc r6, r5, r6 /* Clear DR and IR in MSR value */ +#ifdef CONFIG_PPC_BOOK3S_32 /* * Set EE in HOST_MSR so that it's enabled when we get into our - * C exit handler function + * C exit handler function. On 64-bit we delay enabling + * interrupts until we have finished transferring stuff + * to or from the PACA. */ ori r5, r5, MSR_EE +#endif mtsrr0 r7 mtsrr1 r6 RFI
arch/powerpc/kvm/trace.h +1 -6
@@ -101,17 +101,12 @@ TRACE_EVENT(kvm_exit, ), TP_fast_assign( -#ifdef CONFIG_KVM_BOOK3S_PR -struct kvmppc_book3s_shadow_vcpu *svcpu; -#endif __entry->exit_nr = exit_nr; __entry->pc =kvmppc_get_pc (vcpu); __entry->dar =kvmppc_get_fault_dar (vcpu); __entry->msr = vcpu->arch.shared->msr;#ifdef CONFIG_KVM_BOOK3S_PR - svcpu =svcpu_get (vcpu); - __entry->srr1 = svcpu->shadow_srr1; -svcpu_put (svcpu); + __entry->srr1 = vcpu->arch.shadow_srr1;#endif __entry->last_inst = vcpu->arch.last_inst; ),
Signature · 1 line
1.8.1.4
[PULL 16/51] KVM: PPC: Book3S PR: Allow guest to use 64k pages
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
This adds the code to interpret 64k HPTEs in the guest hashed page table (HPT), 64k SLB entries, and to tell the guest about 64k pages in kvm_vm_ioctl_get_smmu_info(). Guest 64k pages are still shadowed by 4k pages.
This also adds another hash table to the four we have already in book3s_mmu_hpte.c to allow us to find all the PTEs that we have instantiated that match a given 64k guest page.
The tlbie instruction changed starting with POWER6 to use a bit in the RB operand to indicate large page invalidations, and to use other RB bits to indicate the base and actual page sizes and the segment size. 64k pages came in slightly earlier, with POWER5++. We use one bit in vcpu->arch.hflags to indicate that the emulated cpu supports 64k pages, and another to indicate that it has the new tlbie definition.
The KVM_PPC_GET_SMMU_INFO ioctl presents a bit of a problem, because the MMU capabilities depend on which CPU model we're emulating, but it is a VM ioctl not a VCPU ioctl and therefore doesn't get passed a VCPU fd. In addition, commonly-used userspace (QEMU) calls it before setting the PVR for any VCPU. Therefore, as a best effort we look at the first vcpu in the VM and return 64k pages or not depending on its capabilities. We also make the PVR default to the host PVR on recent CPUs that support 1TB segments (and therefore multiple page sizes as well) so that KVM_PPC_GET_SMMU_INFO will include 64k page and 1TB segment support on those CPUs.
--- arch/powerpc/include/asm/kvm_asm.h | 2 + arch/powerpc/include/asm/kvm_book3s.h | 6 +++ arch/powerpc/include/asm/kvm_host.h | 4 ++ arch/powerpc/kvm/book3s_64_mmu.c | 92 +++++++++++++++++++++++++++++++---- arch/powerpc/kvm/book3s_mmu_hpte.c | 50 +++++++++++++++++++ arch/powerpc/kvm/book3s_pr.c | 58 +++++++++++++++++++--- 6 files changed, 197 insertions(+), 15 deletions(-)
arch/powerpc/include/asm/kvm_asm.h +2 -0
@@ -123,6 +123,8 @@#define BOOK3S_HFLAG_SLB 0x2#define BOOK3S_HFLAG_PAIRED_SINGLE 0x4#define BOOK3S_HFLAG_NATIVE_PS 0x8 +#define BOOK3S_HFLAG_MULTI_PGSIZE 0x10 +#define BOOK3S_HFLAG_NEW_TLBIE 0x20#define RESUME_FLAG_NV (1<<0)/* Reload guest nonvolatile state? */ #define RESUME_FLAG_HOST (1<<1)/* Resume host? */
arch/powerpc/include/asm/kvm_book3s.h +6 -0
@@ -58,6 +58,9 @@ struct hpte_cache {struct hlist_node list_pte_long;struct hlist_node list_vpte;struct hlist_node list_vpte_long; +#ifdef CONFIG_PPC_BOOK3S_64 +struct hlist_node list_vpte_64k; +#endif struct rcu_head rcu_head;u64 host_vpn;u64 pfn;
@@ -99,6 +102,9 @@ struct kvmppc_vcpu_book3s {struct hlist_head hpte_hash_pte_long[HPTEG_HASH_NUM_PTE_LONG ];struct hlist_head hpte_hash_vpte[HPTEG_HASH_NUM_VPTE ];struct hlist_head hpte_hash_vpte_long[HPTEG_HASH_NUM_VPTE_LONG ]; +#ifdef CONFIG_PPC_BOOK3S_64 +struct hlist_head hpte_hash_vpte_64k[HPTEG_HASH_NUM_VPTE_64K ]; +#endif int hpte_cache_count;spinlock_t mmu_lock; };
arch/powerpc/include/asm/kvm_host.h +4 -0
@@ -68,10 +68,12 @@ extern void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte);#define HPTEG_HASH_BITS_PTE_LONG 12#define HPTEG_HASH_BITS_VPTE 13#define HPTEG_HASH_BITS_VPTE_LONG 5 +#define HPTEG_HASH_BITS_VPTE_64K 11#define HPTEG_HASH_NUM_PTE (1 << HPTEG_HASH_BITS_PTE)#define HPTEG_HASH_NUM_PTE_LONG (1 << HPTEG_HASH_BITS_PTE_LONG)#define HPTEG_HASH_NUM_VPTE (1 << HPTEG_HASH_BITS_VPTE)#define HPTEG_HASH_NUM_VPTE_LONG (1 << HPTEG_HASH_BITS_VPTE_LONG) +#define HPTEG_HASH_NUM_VPTE_64K (1 << HPTEG_HASH_BITS_VPTE_64K)/* Physical Address Mask - allowed range of real mode RAM access */ #define KVM_PAM 0x0fffffffffffffffULL
@@ -327,6 +329,7 @@ struct kvmppc_pte { bool may_read : 1; bool may_write : 1; bool may_execute : 1; +u8 page_size;/* MMU_PAGE_xxx */ };struct kvmppc_mmu {
@@ -359,6 +362,7 @@ struct kvmppc_slb { bool large : 1; /* PTEs are 16MB */ bool tb : 1; /* 1TB segment */ bool class : 1; +u8 base_page_size;/* MMU_PAGE_xxx */ };# ifdef CONFIG_PPC_FSL_BOOK3E
arch/powerpc/kvm/book3s_64_mmu.c +83 -9
157 lines not on this page · raw message
arch/powerpc/kvm/book3s_mmu_hpte.c +50 -0
86 lines not on this page · raw message
arch/powerpc/kvm/book3s_pr.c +52 -6
84 lines not on this page · raw message
Signature · 1 line
1.8.1.4
[PULL 17/51] KVM: PPC: Book3S PR: Use 64k host pages where possible
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
Currently, PR KVM uses 4k pages for the host-side mappings of guest memory, regardless of the host page size. When the host page size is 64kB, we might as well use 64k host page mappings for guest mappings of 64kB and larger pages and for guest real-mode mappings. However, the magic page has to remain a 4k page.
To implement this, we first add another flag bit to the guest VSID values we use, to indicate that this segment is one where host pages should be mapped using 64k pages. For segments with this bit set we set the bits in the shadow SLB entry to indicate a 64k base page size. When faulting in host HPTEs for this segment, we make them 64k HPTEs instead of 4k. We record the pagesize in struct hpte_cache for use when invalidating the HPTE.
For now we restrict the segment containing the magic page (if any) to 4k pages. It should be possible to lift this restriction in future by ensuring that the magic 4k page is appropriately positioned within a host 64k page.
--- arch/powerpc/include/asm/kvm_book3s.h | 6 ++++-- arch/powerpc/kvm/book3s_32_mmu.c | 1 + arch/powerpc/kvm/book3s_64_mmu.c | 35 ++++++++++++++++++++++++++++++----- arch/powerpc/kvm/book3s_64_mmu_host.c | 27 +++++++++++++++++++++------ arch/powerpc/kvm/book3s_pr.c | 1 + 5 files changed, 57 insertions(+), 13 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +4 -2
@@ -66,6 +66,7 @@ struct hpte_cache {u64 pfn;ulong slot;struct kvmppc_pte pte; +int pagesize; };struct kvmppc_vcpu_book3s {
@@ -113,8 +114,9 @@ struct kvmppc_vcpu_book3s {#define CONTEXT_GUEST 1#define CONTEXT_GUEST_END 2 -#define VSID_REAL 0x0fffffffffc00000ULL -#define VSID_BAT 0x0fffffffffb00000ULL +#define VSID_REAL 0x07ffffffffc00000ULL +#define VSID_BAT 0x07ffffffffb00000ULL +#define VSID_64K 0x0800000000000000ULL#define VSID_1T 0x1000000000000000ULL#define VSID_REAL_DR 0x2000000000000000ULL#define VSID_REAL_IR 0x4000000000000000ULL
arch/powerpc/kvm/book3s_32_mmu.c +1 -0
@@ -308,6 +308,7 @@ static int kvmppc_mmu_book3s_32_xlate(struct kvm_vcpu *vcpu, gva_t eaddr,ulong mp_ea = vcpu->arch.magic_page_ea; pte->eaddr = eaddr; + pte->page_size =MMU_PAGE_4K ;/* Magic page override */ if (unlikely(mp_ea) &&
arch/powerpc/kvm/book3s_64_mmu.c +30 -5
@@ -542,6 +542,16 @@ static void kvmppc_mmu_book3s_64_tlbie(struct kvm_vcpu *vcpu, ulong va,kvmppc_mmu_pte_vflush (vcpu, va >>12 , mask); } +#ifdef CONFIG_PPC_64K_PAGES +static int segment_contains_magic_page (struct kvm_vcpu *vcpu,ulong esid) +{ +ulong mp_ea = vcpu->arch.magic_page_ea; + +return mp_ea && !(vcpu->arch.shared->msr &MSR_PR ) && + (mp_ea >>SID_SHIFT ) == esid; +} +#endif +static int kvmppc_mmu_book3s_64_esid_to_vsid (struct kvm_vcpu *vcpu,ulong esid,u64 *vsid) {
@@ -549,11 +559,13 @@ static int kvmppc_mmu_book3s_64_esid_to_vsid(struct kvm_vcpu *vcpu, ulong esid,struct kvmppc_slb *slb;u64 gvsid = esid;ulong mp_ea = vcpu->arch.magic_page_ea; +int pagesize =MMU_PAGE_64K ;if (vcpu->arch.shared->msr & (MSR_DR |MSR_IR )) { slb =kvmppc_mmu_book3s_64_find_slbe (vcpu, ea);if (slb) { gvsid = slb->vsid; + pagesize = slb->base_page_size;if (slb->tb) { gvsid <<=SID_SHIFT_1T -SID_SHIFT ; gvsid |= esid & ((1ul << (SID_SHIFT_1T -SID_SHIFT )) -1 );
@@ -564,28 +576,41 @@ static int kvmppc_mmu_book3s_64_esid_to_vsid(struct kvm_vcpu *vcpu, ulong esid,switch (vcpu->arch.shared->msr & (MSR_DR |MSR_IR )) {case 0 : - *vsid =VSID_REAL | esid; + gvsid =VSID_REAL | esid;break ;case MSR_IR : - *vsid =VSID_REAL_IR | gvsid; + gvsid |=VSID_REAL_IR ;break ;case MSR_DR : - *vsid =VSID_REAL_DR | gvsid; + gvsid |=VSID_REAL_DR ;break ;case MSR_DR |MSR_IR :if (!slb) goto no_slb; - *vsid = gvsid;break ;default :BUG ();break ; } +#ifdef CONFIG_PPC_64K_PAGES +/* +* Mark this as a 64k segment if the host is using +* 64k pages, the host MMU supports 64k pages and +* the guest segment page size is >= 64k, +* but not if this segment contains the magic page. +*/ +if (pagesize >=MMU_PAGE_64K && + mmu_psize_defs[MMU_PAGE_64K ].shift && + !segment_contains_magic_page (vcpu, esid)) + gvsid |=VSID_64K ; +#endif +if (vcpu->arch.shared->msr &MSR_PR ) - *vsid |=VSID_PR ; + gvsid |=VSID_PR ; + *vsid = gvsid;return 0 ; no_slb:
arch/powerpc/kvm/book3s_64_mmu_host.c +21 -6
@@ -34,7 +34,7 @@void kvmppc_mmu_invalidate_pte (struct kvm_vcpu *vcpu,struct hpte_cache *pte) { ppc_md.hpte_invalidate (pte->slot, pte->host_vpn, -MMU_PAGE_4K ,MMU_PAGE_4K ,MMU_SEGSIZE_256M , + pte->pagesize, pte->pagesize,MMU_SEGSIZE_256M , false); }
@@ -90,6 +90,7 @@ int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *orig_pte)int attempt =0 ;struct kvmppc_sid_map *map;int r =0 ; +int hpsize =MMU_PAGE_4K ;/* Get host physical address for gpa */ hpaddr =kvmppc_gfn_to_pfn (vcpu, orig_pte->raddr >>PAGE_SHIFT );
@@ -99,7 +100,6 @@ int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *orig_pte) goto out; } hpaddr <<=PAGE_SHIFT ; - hpaddr |= orig_pte->raddr & (~0xfffULL & ~PAGE_MASK );/* and write the mapping ea -> hpa into the pt */ vcpu->arch.mmu.esid_to_vsid (vcpu, orig_pte->eaddr >>SID_SHIFT , &vsid);
@@ -117,8 +117,7 @@ int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *orig_pte) goto out; } - vsid = map->host_vsid; - vpn =hpt_vpn (orig_pte->eaddr, vsid,MMU_SEGSIZE_256M ); + vpn =hpt_vpn (orig_pte->eaddr, map->host_vsid,MMU_SEGSIZE_256M );if (!orig_pte->may_write) rflags |=HPTE_R_PP ;
@@ -130,7 +129,16 @@ int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *orig_pte)else kvmppc_mmu_flush_icache (hpaddr >>PAGE_SHIFT ); - hash =hpt_hash (vpn,PTE_SIZE ,MMU_SEGSIZE_256M ); +/* +* Use 64K pages if possible; otherwise, on 64K page kernels, +* we need to transfer 4 more bits from guest real to host real addr. +*/ +if (vsid &VSID_64K ) + hpsize =MMU_PAGE_64K ; +else + hpaddr |= orig_pte->raddr & (~0xfffULL & ~PAGE_MASK ); + + hash =hpt_hash (vpn, mmu_psize_defs[hpsize].shift,MMU_SEGSIZE_256M ); map_again: hpteg = ((hash & htab_hash_mask) *HPTES_PER_GROUP );
@@ -143,7 +151,7 @@ map_again: } ret = ppc_md.hpte_insert (hpteg, vpn, hpaddr, rflags, vflags, -MMU_PAGE_4K ,MMU_PAGE_4K ,MMU_SEGSIZE_256M ); + hpsize, hpsize,MMU_SEGSIZE_256M );if (ret <0 ) {/* If we couldn't map a primary PTE, try a secondary */
@@ -168,6 +176,7 @@ map_again: pte->host_vpn = vpn; pte->pte = *orig_pte; pte->pfn = hpaddr >>PAGE_SHIFT ; + pte->pagesize = hpsize;kvmppc_mmu_hpte_cache_map (vcpu, pte); }
@@ -291,6 +300,12 @@ int kvmppc_mmu_map_segment(struct kvm_vcpu *vcpu, ulong eaddr) slb_vsid &= ~SLB_VSID_KP ; slb_esid |= slb_index; +#ifdef CONFIG_PPC_64K_PAGES +/* Set host segment base page size to 64K if possible */ +if (gvsid &VSID_64K ) + slb_vsid |= mmu_psize_defs[MMU_PAGE_64K ].sllp; +#endif + svcpu->slb[slb_index].esid = slb_esid; svcpu->slb[slb_index].vsid = slb_vsid;
arch/powerpc/kvm/book3s_pr.c +1 -0
@@ -422,6 +422,7 @@ int kvmppc_handle_pagefault(struct kvm_run *run, struct kvm_vcpu *vcpu, pte.raddr = eaddr &KVM_PAM ; pte.eaddr = eaddr; pte.vpage = eaddr >>12 ; + pte.page_size =MMU_PAGE_64K ; }switch (vcpu->arch.shared->msr & (MSR_DR |MSR_IR )) {
Signature · 1 line
1.8.1.4
[PULL 18/51] KVM: PPC: Book3S PR: Handle PP0 page-protection bit in guest HPTEs
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
64-bit POWER processors have a three-bit field for page protection in the hashed page table entry (HPTE). Currently we only interpret the two bits that were present in older versions of the architecture. The only defined combination that has the new bit set is 110, meaning read-only for supervisor and no access for user mode.
This adds code to kvmppc_mmu_book3s_64_xlate() to interpret the extra bit appropriately.
--- arch/powerpc/kvm/book3s_64_mmu.c | 3 +++ 1 file changed, 3 insertions(+)
arch/powerpc/kvm/book3s_64_mmu.c +3 -0
@@ -298,6 +298,8 @@ do_second: v = pteg[i]; r = pteg[i+1 ]; pp = (r &HPTE_R_PP ) | key; +if (r &HPTE_R_PP0 ) + pp |=8 ; gpte->eaddr = eaddr; gpte->vpage =kvmppc_mmu_book3s_64_ea_to_vp (vcpu, eaddr, data);
@@ -319,6 +321,7 @@ do_second:case 3 :case 5 :case 7 : +case 10 : gpte->may_read = true;break ; }
Signature · 1 line
1.8.1.4
[PULL 19/51] KVM: PPC: Book3S PR: Correct errors in H_ENTER implementation
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
The implementation of H_ENTER in PR KVM has some errors:
* With H_EXACT not set, if the HPTEG is full, we return H_PTEG_FULL as the return value of kvmppc_h_pr_enter, but the caller is expecting one of the EMULATE_* values. The H_PTEG_FULL needs to go in the guest's R3 instead.
* With H_EXACT set, if the selected HPTE is already valid, the H_ENTER call should return a H_PTEG_FULL error.
This fixes these errors and also makes it write only the selected HPTE, not the whole group, since only the selected HPTE has been modified. This also micro-optimizes the calculations involving pte_index and i.
--- arch/powerpc/kvm/book3s_pr_papr.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
arch/powerpc/kvm/book3s_pr_papr.c +14 -5
@@ -21,6 +21,8 @@#include <asm/kvm_ppc.h> #include <asm/kvm_book3s.h> +#define HPTE_SIZE 16/* bytes per HPT entry */ +static unsigned long get_pteg_addr (struct kvm_vcpu *vcpu,long pte_index) {struct kvmppc_vcpu_book3s *vcpu_book3s =to_book3s (vcpu);
@@ -40,32 +42,39 @@ static int kvmppc_h_pr_enter(struct kvm_vcpu *vcpu)long pte_index =kvmppc_get_gpr (vcpu,5 );unsigned long pteg[2 *8 ];unsigned long pteg_addr, i, *hpte; +long int ret; + i = pte_index &7 ; pte_index &= ~7UL ; pteg_addr =get_pteg_addr (vcpu, pte_index);copy_from_user (pteg, (void __user *)pteg_addr,sizeof (pteg)); hpte = pteg; + ret =H_PTEG_FULL ;if (likely ((flags &H_EXACT ) =0 )) { - pte_index &= ~7UL ;for (i =0 ; ; ++i) {if (i =8 ) -return H_PTEG_FULL ; + goto done;if ((*hpte &HPTE_V_VALID ) =0 )break ; hpte +=2 ; } }else { - i =kvmppc_get_gpr (vcpu,5 ) &7UL ; hpte += i *2 ; +if (*hpte &HPTE_V_VALID ) + goto done; } hpte[0 ] =kvmppc_get_gpr (vcpu,6 ); hpte[1 ] =kvmppc_get_gpr (vcpu,7 ); -copy_to_user ((void __user *)pteg_addr, pteg,sizeof (pteg)); -kvmppc_set_gpr (vcpu,3 ,H_SUCCESS ); + pteg_addr += i *HPTE_SIZE ; +copy_to_user ((void __user *)pteg_addr, hpte,HPTE_SIZE );kvmppc_set_gpr (vcpu,4 , pte_index | i); + ret =H_SUCCESS ; + + done: +kvmppc_set_gpr (vcpu,3 , ret);return EMULATE_DONE ; }
Signature · 1 line
1.8.1.4
[PULL 20/51] KVM: PPC: Book3S PR: Make HPT accesses and updates SMP-safe
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
This adds a per-VM mutex to provide mutual exclusion between vcpus for accesses to and updates of the guest hashed page table (HPT). This also makes the code use single-byte writes to the HPT entry when updating of the reference (R) and change (C) bits. The reason for doing this, rather than writing back the whole HPTE, is that on non-PAPR virtual machines, the guest OS might be writing to the HPTE concurrently, and writing back the whole HPTE might conflict with that. Also, real hardware does single-byte writes to update R and C.
The new mutex is taken in kvmppc_mmu_book3s_64_xlate() when reading the HPT and updating R and/or C, and in the PAPR HPT update hcalls (H_ENTER, H_REMOVE, etc.). Having the mutex means that we don't need to use a hypervisor lock bit in the HPT update hcalls, and we don't need to be careful about the order in which the bytes of the HPTE are updated by those hcalls.
The other change here is to make emulated TLB invalidations (tlbie) effective across all vcpus. To do this we call kvmppc_mmu_pte_vflush for all vcpus in kvmppc_ppc_book3s_64_tlbie().
For 32-bit, this makes the setting of the accessed and dirty bits use single-byte writes, and makes tlbie invalidate shadow HPTEs for all vcpus.
With this, PR KVM can successfully run SMP guests.
--- arch/powerpc/include/asm/kvm_host.h | 3 +++ arch/powerpc/kvm/book3s_32_mmu.c | 36 ++++++++++++++++++++++-------------- arch/powerpc/kvm/book3s_64_mmu.c | 33 +++++++++++++++++++++++---------- arch/powerpc/kvm/book3s_pr.c | 1 + arch/powerpc/kvm/book3s_pr_papr.c | 33 +++++++++++++++++++++++---------- 5 files changed, 72 insertions(+), 34 deletions(-)
arch/powerpc/include/asm/kvm_host.h +3 -0
@@ -254,6 +254,9 @@ struct kvm_arch {struct kvmppc_vcore *vcores[KVM_MAX_VCORES ];int hpt_cma_alloc;#endif /* CONFIG_KVM_BOOK3S_64_HV */ +#ifdef CONFIG_KVM_BOOK3S_PR +struct mutex hpt_mutex; +#endif #ifdef CONFIG_PPC_BOOK3S_64 struct list_head spapr_tce_tables;struct list_head rtas_tokens;
arch/powerpc/kvm/book3s_32_mmu.c +22 -14
@@ -271,19 +271,22 @@ static int kvmppc_mmu_book3s_32_xlate_pte(struct kvm_vcpu *vcpu, gva_t eaddr,/* Update PTE C and A bits, so the guest's swapper knows we used the page */ if (found) { -u32 oldpte = pteg[i+1 ]; - -if (pte->may_read) - pteg[i+1 ] |=PTEG_FLAG_ACCESSED ; -if (pte->may_write) - pteg[i+1 ] |=PTEG_FLAG_DIRTY ; -else -dprintk_pte ("KVM: Mapping read-only page!\n" ); - -/* Write back into the PTEG */ -if (pteg[i+1 ] != oldpte) -copy_to_user ((void __user *)ptegp, pteg,sizeof (pteg)); - +u32 pte_r = pteg[i+1 ]; +char __user *addr = (char __user *) &pteg[i+1 ]; + +/* +* Use single-byte writes to update the HPTE, to +* conform to what real hardware does. +*/ +if (pte->may_read && !(pte_r &PTEG_FLAG_ACCESSED )) { + pte_r |=PTEG_FLAG_ACCESSED ; +put_user (pte_r >>8 , addr +2 ); + } +if (pte->may_write && !(pte_r &PTEG_FLAG_DIRTY )) { +/* XXX should only set this for stores */ + pte_r |=PTEG_FLAG_DIRTY ; +put_user (pte_r, addr +3 ); + }return 0 ; }
@@ -348,7 +351,12 @@ static void kvmppc_mmu_book3s_32_mtsrin(struct kvm_vcpu *vcpu, u32 srnum,static void kvmppc_mmu_book3s_32_tlbie (struct kvm_vcpu *vcpu,ulong ea,bool large) { -kvmppc_mmu_pte_flush (vcpu, ea,0x0FFFF000 ); +int i; +struct kvm_vcpu *v; + +/* flush this VA on all cpus */ +kvm_for_each_vcpu (i, v, vcpu->kvm) +kvmppc_mmu_pte_flush (v, ea,0x0FFFF000 ); } static int kvmppc_mmu_book3s_32_esid_to_vsid(struct kvm_vcpu *vcpu, ulong esid,
arch/powerpc/kvm/book3s_64_mmu.c +23 -10
@@ -257,6 +257,8 @@ static int kvmppc_mmu_book3s_64_xlate(struct kvm_vcpu *vcpu, gva_t eaddr, pgsize = slbe->large ?MMU_PAGE_16M :MMU_PAGE_4K ; +mutex_lock (&vcpu->kvm->arch.hpt_mutex); + do_second: ptegp =kvmppc_mmu_book3s_64_get_pteg (vcpu_book3s, slbe, eaddr, second);if (kvm_is_error_hva (ptegp))
@@ -332,30 +334,37 @@ do_second:/* Update PTE R and C bits, so the guest's swapper knows we used the * page */ -if (gpte->may_read) { -/* Set the accessed flag */ +if (gpte->may_read && !(r &HPTE_R_R )) { +/* +* Set the accessed flag. +* We have to write this back with a single byte write +* because another vcpu may be accessing this on +* non-PAPR platforms such as mac99, and this is +* what real hardware does. +*/ +char __user *addr = (char __user *) &pteg[i+1 ]; r |=HPTE_R_R ; +put_user (r >>8 , addr +6 ); } -if (data && gpte->may_write) { +if (data && gpte->may_write && !(r &HPTE_R_C )) {/* Set the dirty flag -- XXX even if not writing */ +/* Use a single byte write */ +char __user *addr = (char __user *) &pteg[i+1 ]; r |=HPTE_R_C ; +put_user (r, addr +7 ); } -/* Write back into the PTEG */ -if (pteg[i+1 ] != r) { - pteg[i+1 ] = r; -copy_to_user ((void __user *)ptegp, pteg,sizeof (pteg)); - } +mutex_unlock (&vcpu->kvm->arch.hpt_mutex);if (!gpte->may_read)return -EPERM ;return 0 ; no_page_found: +mutex_unlock (&vcpu->kvm->arch.hpt_mutex);return -ENOENT ; no_seg_found: -dprintk ("KVM MMU: Trigger segment fault\n" );return -EINVAL ; }
@@ -520,6 +529,8 @@ static void kvmppc_mmu_book3s_64_tlbie(struct kvm_vcpu *vcpu, ulong va, bool large) {u64 mask =0xFFFFFFFFFULL ; +long i; +struct kvm_vcpu *v;dprintk ("KVM MMU: tlbie(0x%lx)\n" , va);
@@ -542,7 +553,9 @@ static void kvmppc_mmu_book3s_64_tlbie(struct kvm_vcpu *vcpu, ulong va,if (large) mask =0xFFFFFF000ULL ; } -kvmppc_mmu_pte_vflush (vcpu, va >>12 , mask); +/* flush this VA on all vcpus */ +kvm_for_each_vcpu (i, v, vcpu->kvm) +kvmppc_mmu_pte_vflush (v, va >>12 , mask); }#ifdef CONFIG_PPC_64K_PAGES
arch/powerpc/kvm/book3s_pr.c +1 -0
@@ -1422,6 +1422,7 @@ int kvmppc_core_init_vm(struct kvm *kvm)INIT_LIST_HEAD (&kvm->arch.spapr_tce_tables);INIT_LIST_HEAD (&kvm->arch.rtas_tokens);#endif +mutex_init (&kvm->arch.hpt_mutex);if (firmware_has_feature (FW_FEATURE_SET_MODE )) {spin_lock (&kvm_global_user_count_lock);
arch/powerpc/kvm/book3s_pr_papr.c +23 -10
@@ -48,6 +48,7 @@ static int kvmppc_h_pr_enter(struct kvm_vcpu *vcpu) pte_index &= ~7UL ; pteg_addr =get_pteg_addr (vcpu, pte_index); +mutex_lock (&vcpu->kvm->arch.hpt_mutex);copy_from_user (pteg, (void __user *)pteg_addr,sizeof (pteg)); hpte = pteg;
@@ -74,6 +75,7 @@ static int kvmppc_h_pr_enter(struct kvm_vcpu *vcpu) ret =H_SUCCESS ; done: +mutex_unlock (&vcpu->kvm->arch.hpt_mutex);kvmppc_set_gpr (vcpu,3 , ret);return EMULATE_DONE ;
@@ -86,26 +88,31 @@ static int kvmppc_h_pr_remove(struct kvm_vcpu *vcpu)unsigned long avpn =kvmppc_get_gpr (vcpu,6 );unsigned long v =0 , pteg, rb;unsigned long pte[2 ]; +long int ret; pteg =get_pteg_addr (vcpu, pte_index); +mutex_lock (&vcpu->kvm->arch.hpt_mutex);copy_from_user (pte, (void __user *)pteg,sizeof (pte)); + ret =H_NOT_FOUND ;if ((pte[0 ] &HPTE_V_VALID ) ==0 || ((flags &H_AVPN ) && (pte[0 ] & ~0x7fUL ) != avpn) || - ((flags &H_ANDCOND ) && (pte[0 ] & avpn) !=0 )) { -kvmppc_set_gpr (vcpu,3 ,H_NOT_FOUND ); -return EMULATE_DONE ; - } + ((flags &H_ANDCOND ) && (pte[0 ] & avpn) !=0 )) + goto done;copy_to_user ((void __user *)pteg, &v,sizeof (v)); rb =compute_tlbie_rb (pte[0 ], pte[1 ], pte_index); vcpu->arch.mmu.tlbie (vcpu, rb, rb &1 ? true : false); -kvmppc_set_gpr (vcpu,3 ,H_SUCCESS ); + ret =H_SUCCESS ;kvmppc_set_gpr (vcpu,4 , pte[0 ]);kvmppc_set_gpr (vcpu,5 , pte[1 ]); + done: +mutex_unlock (&vcpu->kvm->arch.hpt_mutex); +kvmppc_set_gpr (vcpu,3 , ret); +return EMULATE_DONE ; }
@@ -133,6 +140,7 @@ static int kvmppc_h_pr_bulk_remove(struct kvm_vcpu *vcpu)int paramnr =4 ;int ret =H_SUCCESS ; +mutex_lock (&vcpu->kvm->arch.hpt_mutex);for (i =0 ; i <H_BULK_REMOVE_MAX_BATCH ; i++) {unsigned long tsh =kvmppc_get_gpr (vcpu, paramnr+(2 *i));unsigned long tsl =kvmppc_get_gpr (vcpu, paramnr+(2 *i)+1 );
@@ -181,6 +189,7 @@ static int kvmppc_h_pr_bulk_remove(struct kvm_vcpu *vcpu) }kvmppc_set_gpr (vcpu, paramnr+(2 *i), tsh); } +mutex_unlock (&vcpu->kvm->arch.hpt_mutex);kvmppc_set_gpr (vcpu,3 , ret);return EMULATE_DONE ;
@@ -193,15 +202,16 @@ static int kvmppc_h_pr_protect(struct kvm_vcpu *vcpu)unsigned long avpn =kvmppc_get_gpr (vcpu,6 );unsigned long rb, pteg, r, v;unsigned long pte[2 ]; +long int ret; pteg =get_pteg_addr (vcpu, pte_index); +mutex_lock (&vcpu->kvm->arch.hpt_mutex);copy_from_user (pte, (void __user *)pteg,sizeof (pte)); + ret =H_NOT_FOUND ;if ((pte[0 ] &HPTE_V_VALID ) ==0 || - ((flags &H_AVPN ) && (pte[0 ] & ~0x7fUL ) != avpn)) { -kvmppc_set_gpr (vcpu,3 ,H_NOT_FOUND ); -return EMULATE_DONE ; - } + ((flags &H_AVPN ) && (pte[0 ] & ~0x7fUL ) != avpn)) + goto done; v = pte[0 ]; r = pte[1 ];
@@ -216,8 +226,11 @@ static int kvmppc_h_pr_protect(struct kvm_vcpu *vcpu) rb =compute_tlbie_rb (v, r, pte_index); vcpu->arch.mmu.tlbie (vcpu, rb, rb &1 ? true : false);copy_to_user ((void __user *)pteg, pte,sizeof (pte)); + ret =H_SUCCESS ; -kvmppc_set_gpr (vcpu,3 ,H_SUCCESS ); + done: +mutex_unlock (&vcpu->kvm->arch.hpt_mutex); +kvmppc_set_gpr (vcpu,3 , ret);return EMULATE_DONE ; }
Signature · 1 line
1.8.1.4
[PULL 21/51] KVM: PPC: Book3S PR: Allocate kvm_vcpu structs from kvm_vcpu_cache
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
This makes PR KVM allocate its kvm_vcpu structs from the kvm_vcpu_cache rather than having them embedded in the kvmppc_vcpu_book3s struct, which is allocated with vzalloc. The reason is to reduce the differences between PR and HV KVM in order to make is easier to have them coexist in one kernel binary.
With this, the kvm_vcpu struct has a pointer to the kvmppc_vcpu_book3s struct. The pointer to the kvmppc_book3s_shadow_vcpu struct has moved from the kvmppc_vcpu_book3s struct to the kvm_vcpu struct, and is only present for 32-bit, since it is only used for 32-bit.
--- arch/powerpc/include/asm/kvm_book3s.h | 4 +--- arch/powerpc/include/asm/kvm_book3s_32.h | 2 +- arch/powerpc/include/asm/kvm_host.h | 7 +++++++ arch/powerpc/kvm/book3s_32_mmu.c | 8 ++++---- arch/powerpc/kvm/book3s_64_mmu.c | 11 +++++------ arch/powerpc/kvm/book3s_pr.c | 33 ++++++++++++++++++++------------ 6 files changed, 39 insertions(+), 26 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +1 -3
@@ -70,8 +70,6 @@ struct hpte_cache { };struct kvmppc_vcpu_book3s { -struct kvm_vcpu vcpu; -struct kvmppc_book3s_shadow_vcpu *shadow_vcpu;struct kvmppc_sid_map sid_map[SID_MAP_NUM ];struct {u64 esid;
@@ -194,7 +192,7 @@ extern int kvmppc_h_pr(struct kvm_vcpu *vcpu, unsigned long cmd);static inline struct kvmppc_vcpu_book3s *to_book3s (struct kvm_vcpu *vcpu) { - return container_of(vcpu, struct kvmppc_vcpu_book3s, vcpu); +return vcpu->arch.book3s; }extern void kvm_return_point (void );
arch/powerpc/include/asm/kvm_book3s_32.h +1 -1
@@ -22,7 +22,7 @@static inline struct kvmppc_book3s_shadow_vcpu *svcpu_get (struct kvm_vcpu *vcpu) { -return to_book3s (vcpu)->shadow_vcpu; +return vcpu->arch.shadow_vcpu; }static inline void svcpu_put (struct kvmppc_book3s_shadow_vcpu *svcpu)
arch/powerpc/include/asm/kvm_host.h +7 -0
@@ -86,6 +86,9 @@ struct lppaca;struct slb_shadow ;struct dtl_entry ; +struct kvmppc_vcpu_book3s ; +struct kvmppc_book3s_shadow_vcpu ; +struct kvm_vm_stat {u32 remote_tlb_flush; };
@@ -408,6 +411,10 @@ struct kvm_vcpu_arch {int slb_max;/* 1 + index of last valid entry in slb[] */ int slb_nr;/* total number of entries in SLB */ struct kvmppc_mmu mmu; +struct kvmppc_vcpu_book3s *book3s; +#endif +#ifdef CONFIG_PPC_BOOK3S_32 +struct kvmppc_book3s_shadow_vcpu *shadow_vcpu;#endif ulong gpr[32 ];
arch/powerpc/kvm/book3s_32_mmu.c +4 -4
@@ -111,10 +111,11 @@ static void kvmppc_mmu_book3s_32_reset_msr(struct kvm_vcpu *vcpu)kvmppc_set_msr (vcpu,0 ); } -static hva_t kvmppc_mmu_book3s_32_get_pteg (struct kvmppc_vcpu_book3s *vcpu_book3s, +static hva_t kvmppc_mmu_book3s_32_get_pteg (struct kvm_vcpu *vcpu,u32 sre,gva_t eaddr,bool primary) { +struct kvmppc_vcpu_book3s *vcpu_book3s =to_book3s (vcpu);u32 page, hash, pteg, htabmask;hva_t r;
@@ -132,7 +133,7 @@ static hva_t kvmppc_mmu_book3s_32_get_pteg(struct kvmppc_vcpu_book3s *vcpu_book3kvmppc_get_pc (&vcpu_book3s->vcpu), eaddr, vcpu_book3s->sdr1, pteg, sr_vsid(sre)); - r =gfn_to_hva (vcpu_book3s->vcpu.kvm, pteg >>PAGE_SHIFT ); + r =gfn_to_hva (vcpu->kvm, pteg >>PAGE_SHIFT );if (kvm_is_error_hva (r))return r;return r | (pteg & ~PAGE_MASK );
@@ -203,7 +204,6 @@ static int kvmppc_mmu_book3s_32_xlate_pte(struct kvm_vcpu *vcpu, gva_t eaddr, struct kvmppc_pte *pte, bool data, bool primary) { - struct kvmppc_vcpu_book3s *vcpu_book3s = to_book3s(vcpu); u32 sre;hva_t ptegp;u32 pteg[16 ];
@@ -218,7 +218,7 @@ static int kvmppc_mmu_book3s_32_xlate_pte(struct kvm_vcpu *vcpu, gva_t eaddr, pte->vpage =kvmppc_mmu_book3s_32_ea_to_vp (vcpu, eaddr, data); - ptegp =kvmppc_mmu_book3s_32_get_pteg (vcpu_book3s, sre, eaddr, primary); + ptegp =kvmppc_mmu_book3s_32_get_pteg (vcpu, sre, eaddr, primary);if (kvm_is_error_hva (ptegp)) {printk (KERN_INFO "KVM: Invalid PTEG!\n" ); goto no_page_found;
arch/powerpc/kvm/book3s_64_mmu.c +5 -6
@@ -130,11 +130,11 @@ static u32 kvmppc_mmu_book3s_64_get_page(struct kvmppc_slb *slbe, gva_t eaddr)return ((eaddr &kvmppc_slb_offset_mask (slbe)) >> p); } -static hva_t kvmppc_mmu_book3s_64_get_pteg ( -struct kvmppc_vcpu_book3s *vcpu_book3s, +static hva_t kvmppc_mmu_book3s_64_get_pteg (struct kvm_vcpu *vcpu,struct kvmppc_slb *slbe,gva_t eaddr,bool second) { +struct kvmppc_vcpu_book3s *vcpu_book3s =to_book3s (vcpu);u64 hash, pteg, htabsize;u32 ssize;hva_t r;
@@ -159,10 +159,10 @@ static hva_t kvmppc_mmu_book3s_64_get_pteg(/* When running a PAPR guest, SDR1 contains a HVA address instead of a GPA */ -if (vcpu_book3s->vcpu.arch.papr_enabled) +if (vcpu->arch.papr_enabled) r = pteg;else - r =gfn_to_hva (vcpu_book3s->vcpu.kvm, pteg >>PAGE_SHIFT ); + r =gfn_to_hva (vcpu->kvm, pteg >>PAGE_SHIFT );if (kvm_is_error_hva (r))return r;
@@ -208,7 +208,6 @@ static int decode_pagesize(struct kvmppc_slb *slbe, u64 r)static int kvmppc_mmu_book3s_64_xlate (struct kvm_vcpu *vcpu,gva_t eaddr,struct kvmppc_pte *gpte,bool data) { -struct kvmppc_vcpu_book3s *vcpu_book3s =to_book3s (vcpu);struct kvmppc_slb *slbe;hva_t ptegp;u64 pteg[16 ];
@@ -260,7 +259,7 @@ static int kvmppc_mmu_book3s_64_xlate(struct kvm_vcpu *vcpu, gva_t eaddr,mutex_lock (&vcpu->kvm->arch.hpt_mutex); do_second: - ptegp =kvmppc_mmu_book3s_64_get_pteg (vcpu_book3s, slbe, eaddr, second); + ptegp =kvmppc_mmu_book3s_64_get_pteg (vcpu, slbe, eaddr, second);if (kvm_is_error_hva (ptegp)) goto no_page_found;
arch/powerpc/kvm/book3s_pr.c +20 -11
@@ -66,7 +66,7 @@ void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu)#endif vcpu->cpu =smp_processor_id ();#ifdef CONFIG_PPC_BOOK3S_32 - current->thread.kvm_shadow_vcpu =to_book3s (vcpu)->shadow_vcpu; + current->thread.kvm_shadow_vcpu = vcpu->arch.shadow_vcpu;#endif }
@@ -1125,17 +1125,22 @@ struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id)int err = -ENOMEM ;unsigned long p; + vcpu =kmem_cache_zalloc (kvm_vcpu_cache,GFP_KERNEL ); +if (!vcpu) + goto out; + vcpu_book3s =vzalloc (sizeof (struct kvmppc_vcpu_book3s ));if (!vcpu_book3s) - goto out; + goto free_vcpu; + vcpu->arch.book3s = vcpu_book3s;#ifdef CONFIG_KVM_BOOK3S_32 - vcpu_book3s->shadow_vcpu -kzalloc (sizeof (*vcpu_book3s->shadow_vcpu),GFP_KERNEL ); -if (!vcpu_book3s->shadow_vcpu) - goto free_vcpu; + vcpu->arch.shadow_vcpu +kzalloc (sizeof (*vcpu->arch.shadow_vcpu),GFP_KERNEL ); +if (!vcpu->arch.shadow_vcpu) + goto free_vcpu3s;#endif - vcpu = &vcpu_book3s->vcpu; + err =kvm_vcpu_init (vcpu, kvm, id);if (err) goto free_shadow_vcpu;
@@ -1175,10 +1180,12 @@ uninit_vcpu:kvm_vcpu_uninit (vcpu); free_shadow_vcpu:#ifdef CONFIG_KVM_BOOK3S_32 -kfree (vcpu_book3s->shadow_vcpu); -free_vcpu: +kfree (vcpu->arch.shadow_vcpu); +free_vcpu3s:#endif vfree (vcpu_book3s); +free_vcpu: +kmem_cache_free (kvm_vcpu_cache, vcpu); out:return ERR_PTR (err); }
@@ -1189,8 +1196,11 @@ void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)free_page ((unsigned long )vcpu->arch.shared &PAGE_MASK );kvm_vcpu_uninit (vcpu); -kfree (vcpu_book3s->shadow_vcpu); +#ifdef CONFIG_KVM_BOOK3S_32 +kfree (vcpu->arch.shadow_vcpu); +#endif vfree (vcpu_book3s); +kmem_cache_free (kvm_vcpu_cache, vcpu); }int kvmppc_vcpu_run (struct kvm_run *kvm_run,struct kvm_vcpu *vcpu)
@@ -1452,8 +1462,7 @@ static int kvmppc_book3s_init(void) {int r; - r =kvm_init (NULL ,sizeof (struct kvmppc_vcpu_book3s ),0 , -THIS_MODULE ); + r =kvm_init (NULL ,sizeof (struct kvm_vcpu ),0 ,THIS_MODULE );if (r)return r;
Signature · 1 line
1.8.1.4
[PULL 22/51] KVM: PPC: Book3S: Move skip-interrupt handlers to common code
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
Both PR and HV KVM have separate, identical copies of the kvmppc_skip_interrupt and kvmppc_skip_Hinterrupt handlers that are used for the situation where an interrupt happens when loading the instruction that caused an exit from the guest. To eliminate this duplication and make it easier to compile in both PR and HV KVM, this moves this code to arch/powerpc/kernel/exceptions-64s.S along with other kernel interrupt handler code.
--- arch/powerpc/kernel/exceptions-64s.S | 26 ++++++++++++++++++++++++++ arch/powerpc/kvm/book3s_hv_rmhandlers.S | 24 ------------------------ arch/powerpc/kvm/book3s_rmhandlers.S | 26 -------------------------- 3 files changed, 26 insertions(+), 50 deletions(-)
arch/powerpc/kernel/exceptions-64s.S +26 -0
@@ -650,6 +650,32 @@ slb_miss_user_pseries: b . /* prevent spec. execution */ #endif /* __DISABLED__ */ +#ifdef CONFIG_KVM_BOOK3S_64_HANDLER +kvmppc_skip_interrupt: + /* + * Here all GPRs are unchanged from when the interrupt happened + * except for r13, which is saved in SPRG_SCRATCH0. + */ + mfspr r13, SPRN_SRR0 + addi r13, r13, 4 + mtspr SPRN_SRR0, r13 + GET_SCRATCH0(r13) + rfid + b . + +kvmppc_skip_Hinterrupt: + /* + * Here all GPRs are unchanged from when the interrupt happened + * except for r13, which is saved in SPRG_SCRATCH0. + */ + mfspr r13, SPRN_HSRR0 + addi r13, r13, 4 + mtspr SPRN_HSRR0, r13 + GET_SCRATCH0(r13) + hrfid + b . +#endif + /* * Code from here down to __end_handlers is invoked from the * exception prologs above. Because the prologs assemble the
arch/powerpc/kvm/book3s_hv_rmhandlers.S +0 -24
@@ -33,30 +33,6 @@ #error Need to fix lppaca and SLB shadow accesses in little endian mode #endif -/***************************************************************************** - * * - * Real Mode handlers that need to be in the linear mapping * - * * - ****************************************************************************/ - - .globl kvmppc_skip_interrupt -kvmppc_skip_interrupt: - mfspr r13,SPRN_SRR0 - addi r13,r13,4 - mtspr SPRN_SRR0,r13 - GET_SCRATCH0(r13) - rfid - b . - - .globl kvmppc_skip_Hinterrupt -kvmppc_skip_Hinterrupt: - mfspr r13,SPRN_HSRR0 - addi r13,r13,4 - mtspr SPRN_HSRR0,r13 - GET_SCRATCH0(r13) - hrfid - b . - /* * Call kvmppc_hv_entry in real mode. * Must be called with interrupts hard-disabled.
arch/powerpc/kvm/book3s_rmhandlers.S +0 -26
@@ -38,32 +38,6 @@ #define FUNC(name) GLUE(.,name) - .globl kvmppc_skip_interrupt -kvmppc_skip_interrupt: - /* - * Here all GPRs are unchanged from when the interrupt happened - * except for r13, which is saved in SPRG_SCRATCH0. - */ - mfspr r13, SPRN_SRR0 - addi r13, r13, 4 - mtspr SPRN_SRR0, r13 - GET_SCRATCH0(r13) - rfid - b . - - .globl kvmppc_skip_Hinterrupt -kvmppc_skip_Hinterrupt: - /* - * Here all GPRs are unchanged from when the interrupt happened - * except for r13, which is saved in SPRG_SCRATCH0. - */ - mfspr r13, SPRN_HSRR0 - addi r13, r13, 4 - mtspr SPRN_HSRR0, r13 - GET_SCRATCH0(r13) - hrfid - b . - #elif defined(CONFIG_PPC_BOOK3S_32) #define FUNC(name) name
Signature · 1 line
1.8.1.4
[PULL 23/51] KVM: PPC: Book3S PR: Better handling of host-side read-only pages
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
Currently we request write access to all pages that get mapped into the guest, even if the guest is only loading from the page. This reduces the effectiveness of KSM because it means that we unshare every page we access. Also, we always set the changed (C) bit in the guest HPTE if it allows writing, even for a guest load.
This fixes both these problems. We pass an 'iswrite' flag to the mmu.xlate() functions and to kvmppc_mmu_map_page() to indicate whether the access is a load or a store. The mmu.xlate() functions now only set C for stores. kvmppc_gfn_to_pfn() now calls gfn_to_pfn_prot() instead of gfn_to_pfn() so that it can indicate whether we need write access to the page, and get back a 'writable' flag to indicate whether the page is writable or not. If that 'writable' flag is clear, we then make the host HPTE read-only even if the guest HPTE allowed writing.
This means that we can get a protection fault when the guest writes to a page that it has mapped read-write but which is read-only on the host side (perhaps due to KSM having merged the page). Thus we now call kvmppc_handle_pagefault() for protection faults as well as HPTE not found faults. In kvmppc_handle_pagefault(), if the access was allowed by the guest HPTE and we thus need to install a new host HPTE, we then need to remove the old host HPTE if there is one. This is done with a new function, kvmppc_mmu_unmap_page(), which uses kvmppc_mmu_pte_vflush() to find and remove the old host HPTE.
Since the memslot-related functions require the KVM SRCU read lock to be held, this adds srcu_read_lock/unlock pairs around the calls to kvmppc_handle_pagefault().
Finally, this changes kvmppc_mmu_book3s_32_xlate_pte() to not ignore guest HPTEs that don't permit access, and to return -EPERM for accesses that are not permitted by the page protections.
--- arch/powerpc/include/asm/kvm_book3s.h | 7 +++++-- arch/powerpc/include/asm/kvm_host.h | 3 ++- arch/powerpc/kvm/book3s.c | 15 +++++++++------ arch/powerpc/kvm/book3s_32_mmu.c | 32 +++++++++++++++++--------------- arch/powerpc/kvm/book3s_32_mmu_host.c | 14 +++++++++++--- arch/powerpc/kvm/book3s_64_mmu.c | 9 +++++---- arch/powerpc/kvm/book3s_64_mmu_host.c | 20 +++++++++++++++++--- arch/powerpc/kvm/book3s_64_mmu_hv.c | 2 +- arch/powerpc/kvm/book3s_pr.c | 29 ++++++++++++++++++++++++----- 9 files changed, 91 insertions(+), 40 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +5 -2
@@ -128,7 +128,9 @@ extern void kvmppc_set_pvr(struct kvm_vcpu *vcpu, u32 pvr);extern void kvmppc_mmu_book3s_64_init (struct kvm_vcpu *vcpu);extern void kvmppc_mmu_book3s_32_init (struct kvm_vcpu *vcpu);extern void kvmppc_mmu_book3s_hv_init (struct kvm_vcpu *vcpu); -extern int kvmppc_mmu_map_page (struct kvm_vcpu *vcpu,struct kvmppc_pte *pte); +extern int kvmppc_mmu_map_page (struct kvm_vcpu *vcpu,struct kvmppc_pte *pte, +bool iswrite); +extern void kvmppc_mmu_unmap_page (struct kvm_vcpu *vcpu,struct kvmppc_pte *pte);extern int kvmppc_mmu_map_segment (struct kvm_vcpu *vcpu,ulong eaddr);extern void kvmppc_mmu_flush_segment (struct kvm_vcpu *vcpu,ulong eaddr,ulong seg_size);extern void kvmppc_mmu_flush_segments (struct kvm_vcpu *vcpu);
@@ -157,7 +159,8 @@ extern void kvmppc_set_bat(struct kvm_vcpu *vcpu, struct kvmppc_bat *bat, bool upper, u32 val);extern void kvmppc_giveup_ext (struct kvm_vcpu *vcpu,ulong msr);extern int kvmppc_emulate_paired_single (struct kvm_run *run,struct kvm_vcpu *vcpu); -extern pfn_t kvmppc_gfn_to_pfn (struct kvm_vcpu *vcpu,gfn_t gfn); +extern pfn_t kvmppc_gfn_to_pfn (struct kvm_vcpu *vcpu,gfn_t gfn,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_invalidate_hpte(struct kvm *kvm, unsigned long *hptep,
arch/powerpc/include/asm/kvm_host.h +2 -1
@@ -348,7 +348,8 @@ struct kvmppc_mmu {/* book3s */ void (*mtsrin)(struct kvm_vcpu *vcpu,u32 srnum,ulong value);u32 (*mfsrin)(struct kvm_vcpu *vcpu,u32 srnum); -int (*xlate)(struct kvm_vcpu *vcpu,gva_t eaddr,struct kvmppc_pte *pte,bool data); +int (*xlate)(struct kvm_vcpu *vcpu,gva_t eaddr, +struct kvmppc_pte *pte,bool data,bool iswrite);void (*reset_msr)(struct kvm_vcpu *vcpu);void (*tlbie)(struct kvm_vcpu *vcpu,ulong addr,bool large);int (*esid_to_vsid)(struct kvm_vcpu *vcpu,ulong esid,u64 *vsid);
arch/powerpc/kvm/book3s.c +9 -6
@@ -286,7 +286,8 @@ int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)return 0 ; } -pfn_t kvmppc_gfn_to_pfn (struct kvm_vcpu *vcpu,gfn_t gfn) +pfn_t kvmppc_gfn_to_pfn (struct kvm_vcpu *vcpu,gfn_t gfn,bool writing, +bool *writable) {ulong mp_pa = vcpu->arch.magic_page_pa;
@@ -302,20 +303,22 @@ pfn_t kvmppc_gfn_to_pfn(struct kvm_vcpu *vcpu, gfn_t gfn) pfn = (pfn_t )virt_to_phys ((void *)shared_page) >>PAGE_SHIFT ;get_page (pfn_to_page (pfn)); +if (writable) + *writable = true;return pfn; } -return gfn_to_pfn (vcpu->kvm, gfn); +return gfn_to_pfn_prot (vcpu->kvm, gfn, writing, writable); }static int kvmppc_xlate (struct kvm_vcpu *vcpu,ulong eaddr,bool data, -struct kvmppc_pte *pte) +bool iswrite,struct kvmppc_pte *pte) {int relocated = (vcpu->arch.shared->msr & (data ?MSR_DR :MSR_IR ));int r;if (relocated) { - r = vcpu->arch.mmu.xlate (vcpu, eaddr, pte, data); + r = vcpu->arch.mmu.xlate (vcpu, eaddr, pte, data, iswrite); }else { pte->eaddr = eaddr; pte->raddr = eaddr &KVM_PAM ;
@@ -361,7 +364,7 @@ int kvmppc_st(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, vcpu->stat.st++; -if (kvmppc_xlate (vcpu, *eaddr, data, &pte)) +if (kvmppc_xlate (vcpu, *eaddr, data, true, &pte))return -ENOENT ; *eaddr = pte.raddr;
@@ -383,7 +386,7 @@ int kvmppc_ld(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, vcpu->stat.ld++; -if (kvmppc_xlate (vcpu, *eaddr, data, &pte)) +if (kvmppc_xlate (vcpu, *eaddr, data, false, &pte)) goto nopte; *eaddr = pte.raddr;
arch/powerpc/kvm/book3s_32_mmu.c +17 -15
@@ -84,7 +84,8 @@ static inline bool sr_nx(u32 sr_raw) }static int kvmppc_mmu_book3s_32_xlate_bat (struct kvm_vcpu *vcpu,gva_t eaddr, -struct kvmppc_pte *pte,bool data); +struct kvmppc_pte *pte,bool data, +bool iswrite);static int kvmppc_mmu_book3s_32_esid_to_vsid (struct kvm_vcpu *vcpu,ulong esid,u64 *vsid);
@@ -99,7 +100,7 @@ static u64 kvmppc_mmu_book3s_32_ea_to_vp(struct kvm_vcpu *vcpu, gva_t eaddr,u64 vsid;struct kvmppc_pte pte; -if (!kvmppc_mmu_book3s_32_xlate_bat (vcpu, eaddr, &pte, data)) +if (!kvmppc_mmu_book3s_32_xlate_bat (vcpu, eaddr, &pte, data, false))return pte.vpage;kvmppc_mmu_book3s_32_esid_to_vsid (vcpu, eaddr >>SID_SHIFT , &vsid);
@@ -146,7 +147,8 @@ static u32 kvmppc_mmu_book3s_32_get_ptem(u32 sre, gva_t eaddr, bool primary) }static int kvmppc_mmu_book3s_32_xlate_bat (struct kvm_vcpu *vcpu,gva_t eaddr, -struct kvmppc_pte *pte,bool data) +struct kvmppc_pte *pte,bool data, +bool iswrite) {struct kvmppc_vcpu_book3s *vcpu_book3s =to_book3s (vcpu);struct kvmppc_bat *bat;
@@ -187,8 +189,7 @@ static int kvmppc_mmu_book3s_32_xlate_bat(struct kvm_vcpu *vcpu, gva_t eaddr,printk (KERN_INFO "BAT is not readable!\n" );continue ; } -if (!pte->may_write) { -/* let's treat r/o BATs as not-readable for now */ +if (iswrite && !pte->may_write) {dprintk_pte ("BAT is read-only!\n" );continue ; }
@@ -202,7 +203,7 @@ static int kvmppc_mmu_book3s_32_xlate_bat(struct kvm_vcpu *vcpu, gva_t eaddr,static int kvmppc_mmu_book3s_32_xlate_pte (struct kvm_vcpu *vcpu,gva_t eaddr,struct kvmppc_pte *pte,bool data, -bool primary) +bool iswrite,bool primary) {u32 sre;hva_t ptegp;
@@ -258,9 +259,6 @@ static int kvmppc_mmu_book3s_32_xlate_pte(struct kvm_vcpu *vcpu, gva_t eaddr,break ; } -if ( !pte->may_read ) -continue ; -dprintk_pte ("MMU: Found PTE -> %x %x - %x\n" , pteg[i], pteg[i+1 ], pp); found =1 ;
@@ -282,11 +280,12 @@ static int kvmppc_mmu_book3s_32_xlate_pte(struct kvm_vcpu *vcpu, gva_t eaddr, pte_r |=PTEG_FLAG_ACCESSED ;put_user (pte_r >>8 , addr +2 ); } -if (pte->may_write && !(pte_r &PTEG_FLAG_DIRTY )) { -/* XXX should only set this for stores */ +if (iswrite && pte->may_write && !(pte_r &PTEG_FLAG_DIRTY )) { pte_r |=PTEG_FLAG_DIRTY ;put_user (pte_r, addr +3 ); } +if (!pte->may_read || (iswrite && !pte->may_write)) +return -EPERM ;return 0 ; }
@@ -305,7 +304,8 @@ no_page_found: }static int kvmppc_mmu_book3s_32_xlate (struct kvm_vcpu *vcpu,gva_t eaddr, -struct kvmppc_pte *pte,bool data) +struct kvmppc_pte *pte,bool data, +bool iswrite) {int r;ulong mp_ea = vcpu->arch.magic_page_ea;
@@ -327,11 +327,13 @@ static int kvmppc_mmu_book3s_32_xlate(struct kvm_vcpu *vcpu, gva_t eaddr,return 0 ; } - r =kvmppc_mmu_book3s_32_xlate_bat (vcpu, eaddr, pte, data); + r =kvmppc_mmu_book3s_32_xlate_bat (vcpu, eaddr, pte, data, iswrite);if (r <0 ) - r =kvmppc_mmu_book3s_32_xlate_pte (vcpu, eaddr, pte, data, true); + r =kvmppc_mmu_book3s_32_xlate_pte (vcpu, eaddr, pte, + data, iswrite, true);if (r <0 ) - r =kvmppc_mmu_book3s_32_xlate_pte (vcpu, eaddr, pte, data, false); + r =kvmppc_mmu_book3s_32_xlate_pte (vcpu, eaddr, pte, + data, iswrite, false);return r; }
arch/powerpc/kvm/book3s_32_mmu_host.c +11 -3
@@ -138,7 +138,8 @@ static u32 *kvmppc_mmu_get_pteg(struct kvm_vcpu *vcpu, u32 vsid, u32 eaddr,extern char etext[]; -int kvmppc_mmu_map_page (struct kvm_vcpu *vcpu,struct kvmppc_pte *orig_pte) +int kvmppc_mmu_map_page (struct kvm_vcpu *vcpu,struct kvmppc_pte *orig_pte, +bool iswrite) {pfn_t hpaddr;u64 vpn;
@@ -152,9 +153,11 @@ int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *orig_pte)bool evict = false;struct hpte_cache *pte;int r =0 ; +bool writable;/* Get host physical address for gpa */ - hpaddr =kvmppc_gfn_to_pfn (vcpu, orig_pte->raddr >>PAGE_SHIFT ); + hpaddr =kvmppc_gfn_to_pfn (vcpu, orig_pte->raddr >>PAGE_SHIFT , + iswrite, &writable);if (is_error_noslot_pfn (hpaddr)) {printk (KERN_INFO "Couldn't get guest page for gfn %lx!\n" , orig_pte->eaddr);
@@ -204,7 +207,7 @@ next_pteg: (primary ?0 :PTE_SEC ); pteg1 = hpaddr |PTE_M |PTE_R |PTE_C ; -if (orig_pte->may_write) { +if (orig_pte->may_write && writable) { pteg1 |=PP_RWRW ;mark_page_dirty (vcpu->kvm, orig_pte->raddr >>PAGE_SHIFT ); }else {
@@ -259,6 +262,11 @@ out:return r; } +void kvmppc_mmu_unmap_page (struct kvm_vcpu *vcpu,struct kvmppc_pte *pte) +{ +kvmppc_mmu_pte_vflush (vcpu, pte->vpage,0xfffffffffULL ); +} +static struct kvmppc_sid_map *create_sid_map (struct kvm_vcpu *vcpu,u64 gvsid) {struct kvmppc_sid_map *map;
arch/powerpc/kvm/book3s_64_mmu.c +5 -4
@@ -206,7 +206,8 @@ static int decode_pagesize(struct kvmppc_slb *slbe, u64 r) }static int kvmppc_mmu_book3s_64_xlate (struct kvm_vcpu *vcpu,gva_t eaddr, -struct kvmppc_pte *gpte,bool data) +struct kvmppc_pte *gpte,bool data, +bool iswrite) {struct kvmppc_slb *slbe;hva_t ptegp;
@@ -345,8 +346,8 @@ do_second: r |=HPTE_R_R ;put_user (r >>8 , addr +6 ); } -if (data && gpte->may_write && !(r &HPTE_R_C )) { -/* Set the dirty flag -- XXX even if not writing */ +if (iswrite && gpte->may_write && !(r &HPTE_R_C )) { +/* Set the dirty flag */ /* Use a single byte write */ char __user *addr = (char __user *) &pteg[i+1 ]; r |=HPTE_R_C ;
@@ -355,7 +356,7 @@ do_second:mutex_unlock (&vcpu->kvm->arch.hpt_mutex); -if (!gpte->may_read) +if (!gpte->may_read || (iswrite && !gpte->may_write))return -EPERM ;return 0 ;
arch/powerpc/kvm/book3s_64_mmu_host.c +17 -3
@@ -78,7 +78,8 @@ static struct kvmppc_sid_map *find_sid_vsid(struct kvm_vcpu *vcpu, u64 gvsid)return NULL ; } -int kvmppc_mmu_map_page (struct kvm_vcpu *vcpu,struct kvmppc_pte *orig_pte) +int kvmppc_mmu_map_page (struct kvm_vcpu *vcpu,struct kvmppc_pte *orig_pte, +bool iswrite) {unsigned long vpn;pfn_t hpaddr;
@@ -91,9 +92,11 @@ int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *orig_pte)struct kvmppc_sid_map *map;int r =0 ;int hpsize =MMU_PAGE_4K ; +bool writable;/* Get host physical address for gpa */ - hpaddr =kvmppc_gfn_to_pfn (vcpu, orig_pte->raddr >>PAGE_SHIFT ); + hpaddr =kvmppc_gfn_to_pfn (vcpu, orig_pte->raddr >>PAGE_SHIFT , + iswrite, &writable);if (is_error_noslot_pfn (hpaddr)) {printk (KERN_INFO "Couldn't get guest page for gfn %lx!\n" , orig_pte->eaddr); r = -EINVAL ;
@@ -119,7 +122,7 @@ int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *orig_pte) vpn =hpt_vpn (orig_pte->eaddr, map->host_vsid,MMU_SEGSIZE_256M ); -if (!orig_pte->may_write) +if (!orig_pte->may_write || !writable) rflags |=HPTE_R_PP ;else mark_page_dirty (vcpu->kvm, orig_pte->raddr >>PAGE_SHIFT );
@@ -186,6 +189,17 @@ out:return r; } +void kvmppc_mmu_unmap_page (struct kvm_vcpu *vcpu,struct kvmppc_pte *pte) +{ +u64 mask =0xfffffffffULL ; +u64 vsid; + + vcpu->arch.mmu.esid_to_vsid (vcpu, pte->eaddr >>SID_SHIFT , &vsid); +if (vsid &VSID_64K ) + mask =0xffffffff0ULL ; +kvmppc_mmu_pte_vflush (vcpu, pte->vpage, mask); +} +static struct kvmppc_sid_map *create_sid_map (struct kvm_vcpu *vcpu,u64 gvsid) {struct kvmppc_sid_map *map;
arch/powerpc/kvm/book3s_64_mmu_hv.c +1 -1
@@ -451,7 +451,7 @@ static unsigned long kvmppc_mmu_get_real_addr(unsigned long v, unsigned long r, }static int kvmppc_mmu_book3s_64_hv_xlate (struct kvm_vcpu *vcpu,gva_t eaddr, -struct kvmppc_pte *gpte,bool data) +struct kvmppc_pte *gpte,bool data,bool iswrite) {struct kvm *kvm = vcpu->kvm;struct kvmppc_slb *slbe;
arch/powerpc/kvm/book3s_pr.c +24 -5
@@ -401,6 +401,7 @@ int kvmppc_handle_pagefault(struct kvm_run *run, struct kvm_vcpu *vcpu, ulong eaddr, int vec) { bool data = (vec == BOOK3S_INTERRUPT_DATA_STORAGE); +bool iswrite = false;int r =RESUME_GUEST ;int relocated;int page_found =0 ;
@@ -411,10 +412,12 @@ int kvmppc_handle_pagefault(struct kvm_run *run, struct kvm_vcpu *vcpu,u64 vsid; relocated = data ? dr : ir; +if (data && (vcpu->arch.fault_dsisr &DSISR_ISSTORE )) + iswrite = true;/* Resolve real address if translation turned on */ if (relocated) { - page_found = vcpu->arch.mmu.xlate (vcpu, eaddr, &pte, data); + page_found = vcpu->arch.mmu.xlate (vcpu, eaddr, &pte, data, iswrite); }else { pte.may_execute = true; pte.may_read = true;
@@ -475,12 +478,20 @@ int kvmppc_handle_pagefault(struct kvm_run *run, struct kvm_vcpu *vcpu,kvmppc_book3s_queue_irqprio (vcpu, vec +0x80 ); }else if (!is_mmio &&kvmppc_visible_gfn (vcpu, pte.raddr >>PAGE_SHIFT )) { +if (data && !(vcpu->arch.fault_dsisr &DSISR_NOHPTE )) { +/* +* There is already a host HPTE there, presumably +* a read-only one for a page the guest thinks +* is writable, so get rid of it first. +*/ +kvmppc_mmu_unmap_page (vcpu, &pte); + }/* The guest's PTE is not mapped yet. Map on the host */ -kvmppc_mmu_map_page (vcpu, &pte); +kvmppc_mmu_map_page (vcpu, &pte, iswrite);if (data) vcpu->stat.sp_storage++;else if (vcpu->arch.mmu.is_dcbz32 (vcpu) && - (!(vcpu->arch.hflags &BOOK3S_HFLAG_DCBZ32 ))) + (!(vcpu->arch.hflags &BOOK3S_HFLAG_DCBZ32 )))kvmppc_patch_dcbz (vcpu, &pte); }else {/* MMIO */
@@ -732,7 +743,9 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,/* only care about PTEG not found errors, but leave NX alone */ if (shadow_srr1 &0x40000000 ) { +int idx =srcu_read_lock (&vcpu->kvm->srcu); r =kvmppc_handle_pagefault (run, vcpu,kvmppc_get_pc (vcpu), exit_nr); +srcu_read_unlock (&vcpu->kvm->srcu, idx); vcpu->stat.sp_instruc++; }else if (vcpu->arch.mmu.is_dcbz32 (vcpu) && (!(vcpu->arch.hflags &BOOK3S_HFLAG_DCBZ32 ))) {
@@ -774,9 +787,15 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu, }#endif -/* The only case we need to handle is missing shadow PTEs */ -if (fault_dsisr &DSISR_NOHPTE ) { +/* +* We need to handle missing shadow PTEs, and +* protection faults due to us mapping a page read-only +* when the guest thinks it is writable. +*/ +if (fault_dsisr & (DSISR_NOHPTE |DSISR_PROTFAULT )) { +int idx =srcu_read_lock (&vcpu->kvm->srcu); r =kvmppc_handle_pagefault (run, vcpu, dar, exit_nr); +srcu_read_unlock (&vcpu->kvm->srcu, idx); }else { vcpu->arch.shared->dar = dar; vcpu->arch.shared->dsisr = fault_dsisr;
Signature · 1 line
1.8.1.4
[PULL 24/51] KVM: PPC: Book3S PR: Use mmu_notifier_retry() in kvmppc_mmu_map_page()
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
When the MM code is invalidating a range of pages, it calls the KVM kvm_mmu_notifier_invalidate_range_start() notifier function, which calls kvm_unmap_hva_range(), which arranges to flush all the existing host HPTEs for guest pages. However, the Linux PTEs for the range being flushed are still valid at that point. We are not supposed to establish any new references to pages in the range until the ...range_end() notifier gets called. The PPC-specific KVM code doesn't get any explicit notification of that; instead, we are supposed to use mmu_notifier_retry() to test whether we are or have been inside a range flush notifier pair while we have been getting a page and instantiating a host HPTE for the page.
This therefore adds a call to mmu_notifier_retry inside kvmppc_mmu_map_page(). This call is inside a region locked with kvm->mmu_lock, which is the same lock that is called by the KVM MMU notifier functions, thus ensuring that no new notification can proceed while we are in the locked region. Inside this region we also create the host HPTE and link the corresponding hpte_cache structure into the lists used to find it later. We cannot allocate the hpte_cache structure inside this locked region because that can lead to deadlock, so we allocate it outside the region and free it if we end up not using it.
This also moves the updates of vcpu3s->hpte_cache_count inside the regions locked with vcpu3s->mmu_lock, and does the increment in kvmppc_mmu_hpte_cache_map() when the pte is added to the cache rather than when it is allocated, in order that the hpte_cache_count is accurate.
--- arch/powerpc/include/asm/kvm_book3s.h | 1 + arch/powerpc/kvm/book3s_64_mmu_host.c | 37 ++++++++++++++++++++++++++--------- arch/powerpc/kvm/book3s_mmu_hpte.c | 14 +++++++++---- 3 files changed, 39 insertions(+), 13 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +1 -0
@@ -142,6 +142,7 @@ extern long kvmppc_hv_find_lock_hpte(struct kvm *kvm, gva_t eaddr,extern void kvmppc_mmu_hpte_cache_map (struct kvm_vcpu *vcpu,struct hpte_cache *pte);extern struct hpte_cache *kvmppc_mmu_hpte_cache_next (struct kvm_vcpu *vcpu); +extern void kvmppc_mmu_hpte_cache_free (struct hpte_cache *pte);extern void kvmppc_mmu_hpte_destroy (struct kvm_vcpu *vcpu);extern int kvmppc_mmu_hpte_init (struct kvm_vcpu *vcpu);extern void kvmppc_mmu_invalidate_pte (struct kvm_vcpu *vcpu,struct hpte_cache *pte);
arch/powerpc/kvm/book3s_64_mmu_host.c +28 -9
@@ -93,6 +93,13 @@ int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *orig_pte,int r =0 ;int hpsize =MMU_PAGE_4K ;bool writable; +unsigned long mmu_seq; +struct kvm *kvm = vcpu->kvm; +struct hpte_cache *cpte; + +/* used to check for invalidations in progress */ + mmu_seq = kvm->mmu_notifier_seq; +smp_rmb ();/* Get host physical address for gpa */ hpaddr = kvmppc_gfn_to_pfn(vcpu, orig_pte->raddr >> PAGE_SHIFT,
@@ -143,6 +150,14 @@ int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *orig_pte, hash =hpt_hash (vpn, mmu_psize_defs[hpsize].shift,MMU_SEGSIZE_256M ); + cpte =kvmppc_mmu_hpte_cache_next (vcpu); + +spin_lock (&kvm->mmu_lock); +if (!cpte ||mmu_notifier_retry (kvm, mmu_seq)) { + r = -EAGAIN ; + goto out_unlock; + } + map_again: hpteg = ((hash & htab_hash_mask) *HPTES_PER_GROUP );
@@ -150,7 +165,7 @@ map_again:if (attempt >1 )if (ppc_md.hpte_remove (hpteg) <0 ) { r =-1 ; - goto out; + goto out_unlock; } ret = ppc_md.hpte_insert(hpteg, vpn, hpaddr, rflags, vflags,
@@ -163,8 +178,6 @@ map_again: attempt++; goto map_again; }else { -struct hpte_cache *pte =kvmppc_mmu_hpte_cache_next (vcpu); -trace_kvm_book3s_64_mmu_map (rflags, hpteg, vpn, hpaddr, orig_pte);
@@ -175,15 +188,21 @@ map_again: hpteg = ((hash & htab_hash_mask) *HPTES_PER_GROUP ); } - pte->slot = hpteg + (ret &7 ); - pte->host_vpn = vpn; - pte->pte = *orig_pte; - pte->pfn = hpaddr >>PAGE_SHIFT ; - pte->pagesize = hpsize; + cpte->slot = hpteg + (ret &7 ); + cpte->host_vpn = vpn; + cpte->pte = *orig_pte; + cpte->pfn = hpaddr >>PAGE_SHIFT ; + cpte->pagesize = hpsize; -kvmppc_mmu_hpte_cache_map (vcpu, pte); +kvmppc_mmu_hpte_cache_map (vcpu, cpte); + cpte =NULL ; } + +out_unlock: +spin_unlock (&kvm->mmu_lock);kvm_release_pfn_clean (hpaddr >>PAGE_SHIFT ); +if (cpte) +kvmppc_mmu_hpte_cache_free (cpte); out:return r;
arch/powerpc/kvm/book3s_mmu_hpte.c +10 -4
@@ -98,6 +98,8 @@ void kvmppc_mmu_hpte_cache_map(struct kvm_vcpu *vcpu, struct hpte_cache *pte) &vcpu3s->hpte_hash_vpte_64k[index]);#endif + vcpu3s->hpte_cache_count++; +spin_unlock (&vcpu3s->mmu_lock); }
@@ -131,10 +133,10 @@ static void invalidate_pte(struct kvm_vcpu *vcpu, struct hpte_cache *pte)#ifdef CONFIG_PPC_BOOK3S_64 hlist_del_init_rcu (&pte->list_vpte_64k);#endif + vcpu3s->hpte_cache_count--;spin_unlock (&vcpu3s->mmu_lock); - vcpu3s->hpte_cache_count--;call_rcu (&pte->rcu_head, free_pte_rcu); }
@@ -331,15 +333,19 @@ struct hpte_cache *kvmppc_mmu_hpte_cache_next(struct kvm_vcpu *vcpu)struct kvmppc_vcpu_book3s *vcpu3s =to_book3s (vcpu);struct hpte_cache *pte; - pte =kmem_cache_zalloc (hpte_cache,GFP_KERNEL ); - vcpu3s->hpte_cache_count++; -if (vcpu3s->hpte_cache_count ==HPTEG_CACHE_NUM )kvmppc_mmu_pte_flush_all (vcpu); + pte =kmem_cache_zalloc (hpte_cache,GFP_KERNEL ); +return pte; } +void kvmppc_mmu_hpte_cache_free (struct hpte_cache *pte) +{ +kmem_cache_free (hpte_cache, pte); +} +void kvmppc_mmu_hpte_destroy (struct kvm_vcpu *vcpu) {kvmppc_mmu_pte_flush (vcpu,0 ,0 );
Signature · 1 line
1.8.1.4
[PULL 25/51] KVM: PPC: Book3S PR: Mark pages accessed, and dirty if being written
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
The mark_page_dirty() function, despite what its name might suggest, doesn't actually mark the page as dirty as far as the MM subsystem is concerned. It merely sets a bit in KVM's map of dirty pages, if userspace has requested dirty tracking for the relevant memslot. To tell the MM subsystem that the page is dirty, we have to call kvm_set_pfn_dirty() (or an equivalent such as SetPageDirty()).
This adds a call to kvm_set_pfn_dirty(), and while we are here, also adds a call to kvm_set_pfn_accessed() to tell the MM subsystem that the page has been accessed. Since we are now using the pfn in several places, this adds a 'pfn' variable to store it and changes the places that used hpaddr >> PAGE_SHIFT to use pfn instead, which is the same thing.
This also changes a use of HPTE_R_PP to PP_RXRX. Both are 3, but PP_RXRX is more informative as being the read-only page permission bit setting.
--- arch/powerpc/kvm/book3s_64_mmu_host.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-)
arch/powerpc/kvm/book3s_64_mmu_host.c +15 -11
@@ -96,20 +96,21 @@ int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *orig_pte,unsigned long mmu_seq;struct kvm *kvm = vcpu->kvm;struct hpte_cache *cpte; +unsigned long gfn = orig_pte->raddr >>PAGE_SHIFT ; +unsigned long pfn;/* used to check for invalidations in progress */ mmu_seq = kvm->mmu_notifier_seq;smp_rmb ();/* Get host physical address for gpa */ - hpaddr =kvmppc_gfn_to_pfn (vcpu, orig_pte->raddr >>PAGE_SHIFT , - iswrite, &writable); -if (is_error_noslot_pfn (hpaddr)) { -printk (KERN_INFO "Couldn't get guest page for gfn %lx!\n" , orig_pte->eaddr); + pfn =kvmppc_gfn_to_pfn (vcpu, gfn, iswrite, &writable); +if (is_error_noslot_pfn (pfn)) { +printk (KERN_INFO "Couldn't get guest page for gfn %lx!\n" , gfn); r = -EINVAL ; goto out; } - hpaddr <<=PAGE_SHIFT ; + hpaddr = pfn <<PAGE_SHIFT ;/* and write the mapping ea -> hpa into the pt */ vcpu->arch.mmu.esid_to_vsid (vcpu, orig_pte->eaddr >>SID_SHIFT , &vsid);
@@ -129,15 +130,18 @@ int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *orig_pte, vpn =hpt_vpn (orig_pte->eaddr, map->host_vsid,MMU_SEGSIZE_256M ); +kvm_set_pfn_accessed (pfn);if (!orig_pte->may_write || !writable) - rflags |=HPTE_R_PP ; -else -mark_page_dirty (vcpu->kvm, orig_pte->raddr >>PAGE_SHIFT ); + rflags |=PP_RXRX ; +else { +mark_page_dirty (vcpu->kvm, gfn); +kvm_set_pfn_dirty (pfn); + }if (!orig_pte->may_execute) rflags |=HPTE_R_N ;else -kvmppc_mmu_flush_icache (hpaddr >>PAGE_SHIFT ); +kvmppc_mmu_flush_icache (pfn);/* * Use 64K pages if possible; otherwise, on 64K page kernels,
@@ -191,7 +195,7 @@ map_again: cpte->slot = hpteg + (ret &7 ); cpte->host_vpn = vpn; cpte->pte = *orig_pte; - cpte->pfn = hpaddr >>PAGE_SHIFT ; + cpte->pfn = pfn; cpte->pagesize = hpsize;kvmppc_mmu_hpte_cache_map (vcpu, cpte);
@@ -200,7 +204,7 @@ map_again: out_unlock:spin_unlock (&kvm->mmu_lock); -kvm_release_pfn_clean (hpaddr >>PAGE_SHIFT ); +kvm_release_pfn_clean (pfn);if (cpte)kvmppc_mmu_hpte_cache_free (cpte);
Signature · 1 line
1.8.1.4
[PULL 26/51] KVM: PPC: Book3S PR: Reduce number of shadow PTEs invalidated by MMU notifiers
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
Currently, whenever any of the MMU notifier callbacks get called, we invalidate all the shadow PTEs. This is inefficient because it means that we typically then get a lot of DSIs and ISIs in the guest to fault the shadow PTEs back in. We do this even if the address range being notified doesn't correspond to guest memory.
This commit adds code to scan the memslot array to find out what range(s) of guest physical addresses corresponds to the host virtual address range being affected. For each such range we flush only the shadow PTEs for the range, on all cpus.
--- arch/powerpc/kvm/book3s_pr.c | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-)
arch/powerpc/kvm/book3s_pr.c +31 -8
@@ -150,24 +150,48 @@ int kvmppc_core_check_requests(struct kvm_vcpu *vcpu) }/************* MMU Notifiers *************/ +static void do_kvm_unmap_hva (struct kvm *kvm,unsigned long start, +unsigned long end) +{ +long i; +struct kvm_vcpu *vcpu; +struct kvm_memslots *slots; +struct kvm_memory_slot *memslot; + + slots =kvm_memslots (kvm); +kvm_for_each_memslot (memslot, slots) { +unsigned long hva_start, hva_end; +gfn_t gfn, gfn_end; + + hva_start =max (start, memslot->userspace_addr); + hva_end =min (end, memslot->userspace_addr + + (memslot->npages <<PAGE_SHIFT )); +if (hva_start >= hva_end) +continue ; +/* +* {gfn(page) | page intersects with [hva_start, hva_end)} + * {gfn, gfn+1, ..., gfn_end-1}. +*/ + gfn =hva_to_gfn_memslot (hva_start, memslot); + gfn_end =hva_to_gfn_memslot (hva_end +PAGE_SIZE -1 , memslot); +kvm_for_each_vcpu (i, vcpu, kvm) +kvmppc_mmu_pte_pflush (vcpu, gfn <<PAGE_SHIFT , + gfn_end <<PAGE_SHIFT ); + } +}int kvm_unmap_hva (struct kvm *kvm,unsigned long hva) {trace_kvm_unmap_hva (hva); -/* -* Flush all shadow tlb entries everywhere. This is slow, but -* we are 100% sure that we catch the to be unmapped page -*/ -kvm_flush_remote_tlbs (kvm); +do_kvm_unmap_hva (kvm, hva, hva +PAGE_SIZE );return 0 ; }int kvm_unmap_hva_range (struct kvm *kvm,unsigned long start,unsigned long end) { -/* kvm_unmap_hva flushes everything anyways */ -kvm_unmap_hva (kvm, start); +do_kvm_unmap_hva (kvm, start, end);return 0 ; }
@@ -187,7 +211,7 @@ int kvm_test_age_hva(struct kvm *kvm, unsigned long hva)void kvm_set_spte_hva (struct kvm *kvm,unsigned long hva,pte_t pte) {/* The page will get remapped properly on its next fault */ -kvm_unmap_hva (kvm, hva); +do_kvm_unmap_hva (kvm, hva, hva +PAGE_SIZE ); }/*****************************************/
Signature · 1 line
1.8.1.4
[PULL 27/51] kvm: powerpc: book3s hv: Fix vcore leak
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
add kvmppc_free_vcores() to free the kvmppc_vcore structures that we allocate for a guest, which are currently being leaked.
--- arch/powerpc/kvm/book3s_hv.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/powerpc/kvm/book3s_hv.c +10 -0
@@ -2050,10 +2050,20 @@ int kvmppc_core_init_vm(struct kvm *kvm)return 0 ; } +static void kvmppc_free_vcores (struct kvm *kvm) +{ +long int i; + +for (i =0 ; i <KVM_MAX_VCORES ; ++i) +kfree (kvm->arch.vcores[i]); + kvm->arch.online_vcores =0 ; +} +void kvmppc_core_destroy_vm (struct kvm *kvm) {uninhibit_secondary_onlining (); +kvmppc_free_vcores (kvm);if (kvm->arch.rma) {kvm_release_rma (kvm->arch.rma); kvm->arch.rma =NULL ;
Signature · 1 line
1.8.1.4
[PULL 28/51] KVM: PPC: Book3S HV: Better handling of exceptions that happen in real mode
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
When an interrupt or exception happens in the guest that comes to the host, the CPU goes to hypervisor real mode (MMU off) to handle the exception but doesn't change the MMU context. After saving a few registers, we then clear the "in guest" flag. If, for any reason, we get an exception in the real-mode code, that then gets handled by the normal kernel exception handlers, which turn the MMU on. This is disastrous if the MMU is still set to the guest context, since we end up executing instructions from random places in the guest kernel with hypervisor privilege.
In order to catch this situation, we define a new value for the "in guest" flag, KVM_GUEST_MODE_HOST_HV, to indicate that we are in hypervisor real mode with guest MMU context. If the "in guest" flag is set to this value, we branch off to an emergency handler. For the moment, this just does a branch to self to stop the CPU from doing anything further.
While we're here, we define another new flag value to indicate that we are in a HV guest, as distinct from a PR guest. This will be useful when we have a kernel that can support both PR and HV guests concurrently.
--- arch/powerpc/include/asm/kvm_asm.h | 2 ++ arch/powerpc/kvm/book3s_hv_rmhandlers.S | 31 +++++++++++++++++++++++++------ 2 files changed, 27 insertions(+), 6 deletions(-)
arch/powerpc/include/asm/kvm_asm.h +2 -0
@@ -138,6 +138,8 @@#define KVM_GUEST_MODE_NONE 0#define KVM_GUEST_MODE_GUEST 1#define KVM_GUEST_MODE_SKIP 2 +#define KVM_GUEST_MODE_GUEST_HV 3 +#define KVM_GUEST_MODE_HOST_HV 4#define KVM_INST_FETCH_FAILED -1
arch/powerpc/kvm/book3s_hv_rmhandlers.S +25 -6
@@ -387,6 +387,9 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) mtspr SPRN_DAR, r5 mtspr SPRN_DSISR, r6 + li r6, KVM_GUEST_MODE_HOST_HV + stb r6, HSTATE_IN_GUEST(r13) + BEGIN_FTR_SECTION /* Restore AMR and UAMOR, set AMOR to all 1s */ ld r5,VCPU_AMR(r4)
@@ -690,7 +693,7 @@ fast_guest_return: mtspr SPRN_HSRR1,r11 /* Activate guest mode, so faults get handled by KVM */ - li r9, KVM_GUEST_MODE_GUEST + li r9, KVM_GUEST_MODE_GUEST_HV stb r9, HSTATE_IN_GUEST(r13) /* Enter guest */
@@ -750,6 +753,14 @@ kvmppc_interrupt: */ /* abuse host_r2 as third scratch area; we get r2 from PACATOC(r13) */ std r9, HSTATE_HOST_R2(r13) + + lbz r9, HSTATE_IN_GUEST(r13) + cmpwi r9, KVM_GUEST_MODE_HOST_HV + beq kvmppc_bad_host_intr + /* We're now back in the host but in guest MMU context */ + li r9, KVM_GUEST_MODE_HOST_HV + stb r9, HSTATE_IN_GUEST(r13) + ld r9, HSTATE_KVM_VCPU(r13) /* Save registers */
@@ -801,10 +812,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) std r3, VCPU_GPR(R13)(r9) std r4, VCPU_LR(r9) - /* Unset guest mode */ - li r0, KVM_GUEST_MODE_NONE - stb r0, HSTATE_IN_GUEST(r13) - stw r12,VCPU_TRAP(r9) /* Save HEIR (HV emulation assist reg) in last_inst
@@ -1198,6 +1205,10 @@ BEGIN_FTR_SECTION mtspr SPRN_AMR,r6 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) + /* Unset guest mode */ + li r0, KVM_GUEST_MODE_NONE + stb r0, HSTATE_IN_GUEST(r13) + /* Switch DSCR back to host value */ BEGIN_FTR_SECTION mfspr r8, SPRN_DSCR
@@ -1400,7 +1411,7 @@ fast_interrupt_c_return: stw r8, VCPU_LAST_INST(r9) /* Unset guest mode. */ - li r0, KVM_GUEST_MODE_NONE + li r0, KVM_GUEST_MODE_HOST_HV stb r0, HSTATE_IN_GUEST(r13) b guest_exit_cont
@@ -1949,3 +1960,11 @@ END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) lwz r7,VCPU_VRSAVE(r4) mtspr SPRN_VRSAVE,r7 blr + +/* + * We come here if we get any exception or interrupt while we are + * executing host real mode code while in guest MMU context. + * For now just spin, but we should do something better. + */ +kvmppc_bad_host_intr: + b .
Signature · 1 line
1.8.1.4
[PULL 29/51] powerpc: book3e: _PAGE_LENDIAN must be _PAGE_ENDIAN
In reply to Alexander GrafFrom: Bharat Bhushan <[email protected]>
For booke3e _PAGE_ENDIAN is not defined. Infact what is defined is "_PAGE_LENDIAN" which is wrong and that should be _PAGE_ENDIAN. There are no compilation errors as arch/powerpc/include/asm/pte-common.h defines _PAGE_ENDIAN to 0 as it is not defined anywhere.
--- arch/powerpc/include/asm/pte-book3e.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/include/asm/pte-book3e.h +1 -1
@@ -40,7 +40,7 @@#define _PAGE_U1 0x010000#define _PAGE_U0 0x020000#define _PAGE_ACCESSED 0x040000 -#define _PAGE_LENDIAN 0x080000 +#define _PAGE_ENDIAN 0x080000#define _PAGE_GUARDED 0x100000#define _PAGE_COHERENT 0x200000/* M: enforce memory coherence */ #define _PAGE_NO_CACHE 0x400000/* I: cache inhibit */
Signature · 1 line
1.8.1.4
[PULL 30/51] kvm: powerpc: allow guest control "E" attribute in mas2
In reply to Alexander GrafFrom: Bharat Bhushan <[email protected]>
"E" bit in MAS2 bit indicates whether the page is accessed in Little-Endian or Big-Endian byte order.
There is no reason to stop guest setting "E", so allow him."
--- arch/powerpc/kvm/e500.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kvm/e500.h +1 -1
@@ -117,7 +117,7 @@ static inline struct kvmppc_vcpu_e500 *to_e500(struct kvm_vcpu *vcpu)#define E500_TLB_USER_PERM_MASK (MAS3_UX|MAS3_UR|MAS3_UW)#define E500_TLB_SUPER_PERM_MASK (MAS3_SX|MAS3_SR|MAS3_SW)#define MAS2_ATTRIB_MASK \ - (MAS2_X0 | MAS2_X1) + (MAS2_X0 | MAS2_X1 | MAS2_E)#define MAS3_ATTRIB_MASK \ (MAS3_U0 | MAS3_U1 | MAS3_U2 | MAS3_U3 \ | E500_TLB_USER_PERM_MASK | E500_TLB_SUPER_PERM_MASK)
Signature · 1 line
1.8.1.4
[PULL 31/51] kvm: powerpc: allow guest control "G" attribute in mas2
In reply to Alexander GrafFrom: Bharat Bhushan <[email protected]>
"G" bit in MAS2 indicates whether the page is Guarded. There is no reason to stop guest setting "G", so allow him.
--- arch/powerpc/kvm/e500.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kvm/e500.h +1 -1
@@ -117,7 +117,7 @@ static inline struct kvmppc_vcpu_e500 *to_e500(struct kvm_vcpu *vcpu)#define E500_TLB_USER_PERM_MASK (MAS3_UX|MAS3_UR|MAS3_UW)#define E500_TLB_SUPER_PERM_MASK (MAS3_SX|MAS3_SR|MAS3_SW)#define MAS2_ATTRIB_MASK \ - (MAS2_X0 | MAS2_X1 | MAS2_E) + (MAS2_X0 | MAS2_X1 | MAS2_E | MAS2_G)#define MAS3_ATTRIB_MASK \ (MAS3_U0 | MAS3_U1 | MAS3_U2 | MAS3_U3 \ | E500_TLB_USER_PERM_MASK | E500_TLB_SUPER_PERM_MASK)
Signature · 1 line
1.8.1.4
[PULL 32/51] kvm: powerpc: e500: mark page accessed when mapping a guest page
In reply to Alexander GrafFrom: Bharat Bhushan <[email protected]>
Mark the guest page as accessed so that there is likely less chances of this page getting swap-out.
--- arch/powerpc/kvm/e500_mmu_host.c | 3 +++ 1 file changed, 3 insertions(+)
arch/powerpc/kvm/e500_mmu_host.c +3 -0
@@ -253,6 +253,9 @@ static inline void kvmppc_e500_ref_setup(struct tlbe_ref *ref, ref->pfn = pfn; ref->flags |=E500_TLB_VALID ; +/* Mark the page accessed */ +kvm_set_pfn_accessed (pfn); +if (tlbe_is_writable (gtlbe))kvm_set_pfn_dirty (pfn); }
Signature · 1 line
1.8.1.4
[PULL 33/51] powerpc: remove unnecessary line continuations
In reply to Alexander GrafFrom: Bharat Bhushan <[email protected]>
--- arch/powerpc/kernel/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kernel/process.c +1 -1
@@ -327,7 +327,7 @@ static void set_debug_reg_defaults(struct thread_struct *thread)/* * Force User/Supervisor bits to b11 (user-only MSR[PR]=1) */ - thread->dbcr1 =DBCR1_IAC1US |DBCR1_IAC2US | \ + thread->dbcr1 =DBCR1_IAC1US |DBCR1_IAC2US |DBCR1_IAC3US |DBCR1_IAC4US ;/* * Force Data Address Compare User/Supervisor bits to be User-only
Signature · 1 line
1.8.1.4
[PULL 34/51] powerpc: move debug registers in a structure
In reply to Alexander GrafFrom: Bharat Bhushan <[email protected]>
This way we can use same data type struct with KVM and also help in using other debug related function.
--- arch/powerpc/include/asm/processor.h | 38 +++++---- arch/powerpc/include/asm/reg_booke.h | 8 +- arch/powerpc/kernel/asm-offsets.c | 2 +- arch/powerpc/kernel/process.c | 42 +++++----- arch/powerpc/kernel/ptrace.c | 154 +++++++++++++++++------------------ arch/powerpc/kernel/ptrace32.c | 2 +- arch/powerpc/kernel/signal_32.c | 6 +- arch/powerpc/kernel/traps.c | 35 ++++---- 8 files changed, 147 insertions(+), 140 deletions(-)
arch/powerpc/include/asm/processor.h +22 -16
@@ -147,22 +147,7 @@ typedef struct {#define TS_FPR (i) fpr[i][TS_FPROFFSET]#define TS_TRANS_FPR (i) transact_fpr[i][TS_FPROFFSET] -struct thread_struct { -unsigned long ksp;/* Kernel stack pointer */ -unsigned long ksp_limit;/* if ksp <= ksp_limit stack overflow */ - -#ifdef CONFIG_PPC64 -unsigned long ksp_vsid; -#endif -struct pt_regs *regs;/* Pointer to saved register state */ -mm_segment_t fs;/* for get_fs() validation */ -#ifdef CONFIG_BOOKE -/* BookE base exception scratch space; align on cacheline */ -unsigned long normsave[8 ]____cacheline_aligned ; -#endif -#ifdef CONFIG_PPC32 -void *pgdir;/* root of page-table tree */ -#endif +struct debug_reg {#ifdef CONFIG_PPC_ADV_DEBUG_REGS /* * The following help to manage the use of Debug Control Registers
@@ -199,6 +184,27 @@ struct thread_struct {unsigned long dvc2;#endif #endif +}; + +struct thread_struct { +unsigned long ksp;/* Kernel stack pointer */ +unsigned long ksp_limit;/* if ksp <= ksp_limit stack overflow */ + +#ifdef CONFIG_PPC64 +unsigned long ksp_vsid; +#endif +struct pt_regs *regs;/* Pointer to saved register state */ +mm_segment_t fs;/* for get_fs() validation */ +#ifdef CONFIG_BOOKE +/* BookE base exception scratch space; align on cacheline */ +unsigned long normsave[8 ]____cacheline_aligned ; +#endif +#ifdef CONFIG_PPC32 +void *pgdir;/* root of page-table tree */ +#endif +/* Debug Registers */ +struct debug_reg debug; +/* FP and VSX 0-31 register set */ double fpr[32 ][TS_FPRWIDTH ] __attribute__((aligned (16 )));struct {
arch/powerpc/include/asm/reg_booke.h +4 -4
@@ -381,7 +381,7 @@#define DBCR0_IA34T 0x00004000/* Instr Addr 3-4 range Toggle */ #define DBCR0_FT 0x00000001/* Freeze Timers on debug event */ -#define dbcr_iac_range (task) ((task)->thread.dbcr0) +#define dbcr_iac_range (task) ((task)->thread.debug.dbcr0)#define DBCR_IAC12I DBCR0_IA12/* Range Inclusive */ #define DBCR_IAC12X (DBCR0_IA12 | DBCR0_IA12X)/* Range Exclusive */ #define DBCR_IAC12MODE (DBCR0_IA12 | DBCR0_IA12X)/* IAC 1-2 Mode Bits */
@@ -395,7 +395,7 @@#define DBCR1_DAC1W 0x20000000/* DAC1 Write Debug Event */ #define DBCR1_DAC2W 0x10000000/* DAC2 Write Debug Event */ -#define dbcr_dac (task) ((task)->thread.dbcr1) +#define dbcr_dac (task) ((task)->thread.debug.dbcr1)#define DBCR_DAC1R DBCR1_DAC1R#define DBCR_DAC1W DBCR1_DAC1W#define DBCR_DAC2R DBCR1_DAC2R
@@ -441,7 +441,7 @@#define DBCR0_CRET 0x00000020/* Critical Return Debug Event */ #define DBCR0_FT 0x00000001/* Freeze Timers on debug event */ -#define dbcr_dac (task) ((task)->thread.dbcr0) +#define dbcr_dac (task) ((task)->thread.debug.dbcr0)#define DBCR_DAC1R DBCR0_DAC1R#define DBCR_DAC1W DBCR0_DAC1W#define DBCR_DAC2R DBCR0_DAC2R
@@ -475,7 +475,7 @@#define DBCR1_IAC34MX 0x000000C0/* Instr Addr 3-4 range eXclusive */ #define DBCR1_IAC34AT 0x00000001/* Instr Addr 3-4 range Toggle */ -#define dbcr_iac_range (task) ((task)->thread.dbcr1) +#define dbcr_iac_range (task) ((task)->thread.debug.dbcr1)#define DBCR_IAC12I DBCR1_IAC12M/* Range Inclusive */ #define DBCR_IAC12X DBCR1_IAC12MX/* Range Exclusive */ #define DBCR_IAC12MODE DBCR1_IAC12MX/* IAC 1-2 Mode Bits */
arch/powerpc/kernel/asm-offsets.c +1 -1
@@ -113,7 +113,7 @@ int main(void)#endif /* CONFIG_SPE */ #endif /* CONFIG_PPC64 */ #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE ) -DEFINE (THREAD_DBCR0 , offsetof(struct thread_struct , dbcr0)); + DEFINE(THREAD_DBCR0, offsetof(struct thread_struct, debug.dbcr0));#endif #ifdef CONFIG_KVM_BOOK3S_32_HANDLER DEFINE (THREAD_KVM_SVCPU , offsetof(struct thread_struct , kvm_shadow_vcpu));
arch/powerpc/kernel/process.c +21 -21
79 lines not on this page · raw message
arch/powerpc/kernel/ptrace.c +73 -77
336 lines not on this page · raw message
arch/powerpc/kernel/ptrace32.c +1 -1
@@ -269,7 +269,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,if (addr >0 )break ;#ifdef CONFIG_PPC_ADV_DEBUG_REGS - ret =put_user (child->thread.dac1, (u32 __user *)data); + ret =put_user (child->thread.debug.dac1, (u32 __user *)data);#else dabr_fake = ( (child->thread.hw_brk.address & (~HW_BRK_TYPE_DABR)) |
arch/powerpc/kernel/signal_32.c +3 -3
@@ -1309,7 +1309,7 @@ int sys_debug_setcontext(struct ucontext __user *ctx,unsigned char tmp;unsigned long new_msr = regs->msr;#ifdef CONFIG_PPC_ADV_DEBUG_REGS -unsigned long new_dbcr0 = current->thread.dbcr0; +unsigned long new_dbcr0 = current->thread.debug.dbcr0;#endif for (i=0 ; i<ndbg; i++) {
@@ -1324,7 +1324,7 @@ int sys_debug_setcontext(struct ucontext __user *ctx, }else { new_dbcr0 &= ~DBCR0_IC ;if (!DBCR_ACTIVE_EVENTS (new_dbcr0, - current->thread.dbcr1)) { + current->thread.debug.dbcr1)) { new_msr &= ~MSR_DE ; new_dbcr0 &= ~DBCR0_IDM ; }
@@ -1359,7 +1359,7 @@ int sys_debug_setcontext(struct ucontext __user *ctx,the user is really doing something wrong. */ regs->msr = new_msr;#ifdef CONFIG_PPC_ADV_DEBUG_REGS - current->thread.dbcr0 = new_dbcr0; + current->thread.debug.dbcr0 = new_dbcr0;#endif if (!access_ok(VERIFY_READ, ctx, sizeof(*ctx))
arch/powerpc/kernel/traps.c +18 -17
@@ -351,8 +351,8 @@ static inline int check_io_access(struct pt_regs *regs)#define REASON_TRAP ESR_PTR/* single-step stuff */ -#define single_stepping (regs) (current->thread.dbcr0 & DBCR0_IC) -#define clear_single_step (regs) (current->thread.dbcr0 &= ~DBCR0_IC) +#define single_stepping (regs) (current->thread.debug.dbcr0 & DBCR0_IC) +#define clear_single_step (regs) (current->thread.debug.dbcr0 &= ~DBCR0_IC)#else /* On non-4xx, the reason for the machine check or program
@@ -1486,7 +1486,7 @@ static void handle_debug(struct pt_regs *regs, unsigned long debug_status)if (debug_status & (DBSR_DAC1R |DBSR_DAC1W )) {dbcr_dac (current) &= ~(DBCR_DAC1R |DBCR_DAC1W );#ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE - current->thread.dbcr2 &= ~DBCR2_DAC12MODE ; + current->thread.debug.dbcr2 &= ~DBCR2_DAC12MODE ;#endif do_send_trap (regs,mfspr (SPRN_DAC1 ), debug_status,TRAP_HWBKPT ,5 );
@@ -1497,24 +1497,24 @@ static void handle_debug(struct pt_regs *regs, unsigned long debug_status) 6); changed |=0x01 ; }else if (debug_status &DBSR_IAC1 ) { - current->thread.dbcr0 &= ~DBCR0_IAC1 ; + current->thread.debug.dbcr0 &= ~DBCR0_IAC1 ;dbcr_iac_range (current) &= ~DBCR_IAC12MODE ;do_send_trap (regs,mfspr (SPRN_IAC1 ), debug_status,TRAP_HWBKPT ,1 ); changed |=0x01 ; }else if (debug_status &DBSR_IAC2 ) { - current->thread.dbcr0 &= ~DBCR0_IAC2 ; + current->thread.debug.dbcr0 &= ~DBCR0_IAC2 ;do_send_trap (regs,mfspr (SPRN_IAC2 ), debug_status,TRAP_HWBKPT ,2 ); changed |=0x01 ; }else if (debug_status &DBSR_IAC3 ) { - current->thread.dbcr0 &= ~DBCR0_IAC3 ; + current->thread.debug.dbcr0 &= ~DBCR0_IAC3 ;dbcr_iac_range (current) &= ~DBCR_IAC34MODE ;do_send_trap (regs,mfspr (SPRN_IAC3 ), debug_status,TRAP_HWBKPT ,3 ); changed |=0x01 ; }else if (debug_status &DBSR_IAC4 ) { - current->thread.dbcr0 &= ~DBCR0_IAC4 ; + current->thread.debug.dbcr0 &= ~DBCR0_IAC4 ;do_send_trap (regs,mfspr (SPRN_IAC4 ), debug_status,TRAP_HWBKPT ,4 ); changed |=0x01 ;
@@ -1524,19 +1524,20 @@ static void handle_debug(struct pt_regs *regs, unsigned long debug_status)* Check all other debug flags and see if that bit needs to be turned * back on or not. */ -if (DBCR_ACTIVE_EVENTS (current->thread.dbcr0, current->thread.dbcr1)) +if (DBCR_ACTIVE_EVENTS (current->thread.debug.dbcr0, + current->thread.debug.dbcr1)) regs->msr |=MSR_DE ;else /* Make sure the IDM flag is off */ - current->thread.dbcr0 &= ~DBCR0_IDM ; + current->thread.debug.dbcr0 &= ~DBCR0_IDM ;if (changed &0x01 ) -mtspr (SPRN_DBCR0 , current->thread.dbcr0); +mtspr (SPRN_DBCR0 , current->thread.debug.dbcr0); }void __kprobes DebugException (struct pt_regs *regs,unsigned long debug_status) { - current->thread.dbsr = debug_status; + current->thread.debug.dbsr = debug_status;/* Hack alert: On BookE, Branch Taken stops on the branch itself, while * on server, it stops on the target of the branch. In order to simulate
@@ -1553,8 +1554,8 @@ void __kprobes DebugException(struct pt_regs *regs, unsigned long debug_status)/* Do the single step trick only when coming from userspace */ if (user_mode (regs)) { - current->thread.dbcr0 &= ~DBCR0_BT ; - current->thread.dbcr0 |=DBCR0_IDM |DBCR0_IC ; + current->thread.debug.dbcr0 &= ~DBCR0_BT ; + current->thread.debug.dbcr0 |=DBCR0_IDM |DBCR0_IC ; regs->msr |=MSR_DE ;return ; }
@@ -1582,13 +1583,13 @@ void __kprobes DebugException(struct pt_regs *regs, unsigned long debug_status)return ;if (user_mode (regs)) { - current->thread.dbcr0 &= ~DBCR0_IC ; -if (DBCR_ACTIVE_EVENTS (current->thread.dbcr0, - current->thread.dbcr1)) + current->thread.debug.dbcr0 &= ~DBCR0_IC ; +if (DBCR_ACTIVE_EVENTS (current->thread.debug.dbcr0, + current->thread.debug.dbcr1)) regs->msr |=MSR_DE ;else /* Make sure the IDM bit is off */ - current->thread.dbcr0 &= ~DBCR0_IDM ; + current->thread.debug.dbcr0 &= ~DBCR0_IDM ; }_exception (SIGTRAP , regs,TRAP_TRACE , regs->nip);
Signature · 1 line
1.8.1.4
Re: [PULL 34/51] powerpc: move debug registers in a structure
Quoted 7 lines · Alexander Graf
From: Bharat Bhushan <[email protected]>
This way we can use same data type struct with KVM and also help in using other debug related function.
Signed-off-by Bharat Bhushan <[email protected]>Signed-off-by Alexander Graf <[email protected]>
It would be nice to have PPC maintainers (CCed) ACKs here. This patch also has merging conflicts with cbc9565e (should be easy to resolve)
Quoted 723 lines
--- arch/powerpc/include/asm/processor.h | 38 +++++---- arch/powerpc/include/asm/reg_booke.h | 8 +- arch/powerpc/kernel/asm-offsets.c | 2 +- arch/powerpc/kernel/process.c | 42 +++++----- arch/powerpc/kernel/ptrace.c | 154 +++++++++++++++++------------------ arch/powerpc/kernel/ptrace32.c | 2 +- arch/powerpc/kernel/signal_32.c | 6 +- arch/powerpc/kernel/traps.c | 35 ++++---- 8 files changed, 147 insertions(+), 140 deletions(-)arch/powerpc/include/asm/processor.h +22
-16@@ -147,22 +147,7 @@ typedef struct {#define TS_FPR (i) fpr[i][TS_FPROFFSET]#define TS_TRANS_FPR (i) transact_fpr[i][TS_FPROFFSET] -struct thread_struct { -unsigned long ksp;/* Kernel stack pointer */ -unsigned long ksp_limit;/* if ksp <= ksp_limit stack overflow */ - -#ifdef CONFIG_PPC64 -unsigned long ksp_vsid; -#endif -struct pt_regs *regs;/* Pointer to saved register state */ -mm_segment_t fs;/* for get_fs() validation */ -#ifdef CONFIG_BOOKE -/* BookE base exception scratch space; align on cacheline */ -unsigned long normsave[8 ]____cacheline_aligned ; -#endif -#ifdef CONFIG_PPC32 -void *pgdir;/* root of page-table tree */ -#endif +struct debug_reg {#ifdef CONFIG_PPC_ADV_DEBUG_REGS /* * The following help to manage the use of Debug Control Registers @@ -199,6 +184,27 @@ struct thread_struct {unsigned long dvc2;#endif #endif +}; + +struct thread_struct { +unsigned long ksp;/* Kernel stack pointer */ +unsigned long ksp_limit;/* if ksp <= ksp_limit stack overflow */ + +#ifdef CONFIG_PPC64 +unsigned long ksp_vsid; +#endif +struct pt_regs *regs;/* Pointer to saved register state */ +mm_segment_t fs;/* for get_fs() validation */ +#ifdef CONFIG_BOOKE +/* BookE base exception scratch space; align on cacheline */ +unsigned long normsave[8 ]____cacheline_aligned ; +#endif +#ifdef CONFIG_PPC32 +void *pgdir;/* root of page-table tree */ +#endif +/* Debug Registers */ +struct debug_reg debug; +/* FP and VSX 0-31 register set */ double fpr[32 ][TS_FPRWIDTH ] __attribute__((aligned (16 )));struct {arch/powerpc/include/asm/reg_booke.h +4
-4@@ -381,7 +381,7 @@#define DBCR0_IA34T 0x00004000/* Instr Addr 3-4 range Toggle */ #define DBCR0_FT 0x00000001/* Freeze Timers on debug event */ -#define dbcr_iac_range (task) ((task)->thread.dbcr0) +#define dbcr_iac_range (task) ((task)->thread.debug.dbcr0)#define DBCR_IAC12I DBCR0_IA12/* Range Inclusive */ #define DBCR_IAC12X (DBCR0_IA12 | DBCR0_IA12X)/* Range Exclusive */ #define DBCR_IAC12MODE (DBCR0_IA12 | DBCR0_IA12X)/* IAC 1-2 Mode Bits */ @@ -395,7 +395,7 @@#define DBCR1_DAC1W 0x20000000/* DAC1 Write Debug Event */ #define DBCR1_DAC2W 0x10000000/* DAC2 Write Debug Event */ -#define dbcr_dac (task) ((task)->thread.dbcr1) +#define dbcr_dac (task) ((task)->thread.debug.dbcr1)#define DBCR_DAC1R DBCR1_DAC1R#define DBCR_DAC1W DBCR1_DAC1W#define DBCR_DAC2R DBCR1_DAC2R@@ -441,7 +441,7 @@#define DBCR0_CRET 0x00000020/* Critical Return Debug Event */ #define DBCR0_FT 0x00000001/* Freeze Timers on debug event */ -#define dbcr_dac (task) ((task)->thread.dbcr0) +#define dbcr_dac (task) ((task)->thread.debug.dbcr0)#define DBCR_DAC1R DBCR0_DAC1R#define DBCR_DAC1W DBCR0_DAC1W#define DBCR_DAC2R DBCR0_DAC2R@@ -475,7 +475,7 @@#define DBCR1_IAC34MX 0x000000C0/* Instr Addr 3-4 range eXclusive */ #define DBCR1_IAC34AT 0x00000001/* Instr Addr 3-4 range Toggle */ -#define dbcr_iac_range (task) ((task)->thread.dbcr1) +#define dbcr_iac_range (task) ((task)->thread.debug.dbcr1)#define DBCR_IAC12I DBCR1_IAC12M/* Range Inclusive */ #define DBCR_IAC12X DBCR1_IAC12MX/* Range Exclusive */ #define DBCR_IAC12MODE DBCR1_IAC12MX/* IAC 1-2 Mode Bits */ arch/powerpc/kernel/asm-offsets.c +1
-1@@ -113,7 +113,7 @@ int main(void)#endif /* CONFIG_SPE */ #endif /* CONFIG_PPC64 */ #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE ) -DEFINE (THREAD_DBCR0 , offsetof(struct thread_struct , dbcr0)); + DEFINE(THREAD_DBCR0, offsetof(struct thread_struct, debug.dbcr0));#endif #ifdef CONFIG_KVM_BOOK3S_32_HANDLER DEFINE (THREAD_KVM_SVCPU , offsetof(struct thread_struct , kvm_shadow_vcpu));arch/powerpc/kernel/process.c +21
-21@@ -314,28 +314,28 @@ static DEFINE_PER_CPU(struct arch_hw_breakpoint, current_brk);*/ static void set_debug_reg_defaults (struct thread_struct *thread) { - thread->iac1 = thread->iac2 =0 ; + thread->debug.iac1 = thread->debug.iac2 =0 ;#if CONFIG_PPC_ADV_DEBUG_IACS >2 - thread->iac3 = thread->iac4 =0 ; + thread->debug.iac3 = thread->debug.iac4 =0 ;#endif - thread->dac1 = thread->dac2 =0 ; + thread->debug.dac1 = thread->debug.dac2 =0 ;#if CONFIG_PPC_ADV_DEBUG_DVCS >0 - thread->dvc1 = thread->dvc2 =0 ; + thread->debug.dvc1 = thread->debug.dvc2 =0 ;#endif - thread->dbcr0 =0 ; + thread->debug.dbcr0 =0 ;#ifdef CONFIG_BOOKE /* * Force User/Supervisor bits to b11 (user-only MSR[PR]=1) */ - thread->dbcr1 =DBCR1_IAC1US |DBCR1_IAC2US | + thread->debug.dbcr1 =DBCR1_IAC1US |DBCR1_IAC2US |DBCR1_IAC3US |DBCR1_IAC4US ;/* * Force Data Address Compare User/Supervisor bits to be User-only * (0b11 MSR[PR]=1) and set all other bits in DBCR2 register to be 0. */ - thread->dbcr2 =DBCR2_DAC1US |DBCR2_DAC2US ; + thread->debug.dbcr2 =DBCR2_DAC1US |DBCR2_DAC2US ;#else - thread->dbcr1 =0 ; + thread->debug.dbcr1 =0 ;#endif }@@ -348,22 +348,22 @@ static void prime_debug_regs(struct thread_struct *thread)*/ mtmsr (mfmsr () & ~MSR_DE ); -mtspr (SPRN_IAC1 , thread->iac1); -mtspr (SPRN_IAC2 , thread->iac2); +mtspr (SPRN_IAC1 , thread->debug.iac1); +mtspr (SPRN_IAC2 , thread->debug.iac2);#if CONFIG_PPC_ADV_DEBUG_IACS >2 -mtspr (SPRN_IAC3 , thread->iac3); -mtspr (SPRN_IAC4 , thread->iac4); +mtspr (SPRN_IAC3 , thread->debug.iac3); +mtspr (SPRN_IAC4 , thread->debug.iac4);#endif -mtspr (SPRN_DAC1 , thread->dac1); -mtspr (SPRN_DAC2 , thread->dac2); +mtspr (SPRN_DAC1 , thread->debug.dac1); +mtspr (SPRN_DAC2 , thread->debug.dac2);#if CONFIG_PPC_ADV_DEBUG_DVCS >0 -mtspr (SPRN_DVC1 , thread->dvc1); -mtspr (SPRN_DVC2 , thread->dvc2); +mtspr (SPRN_DVC1 , thread->debug.dvc1); +mtspr (SPRN_DVC2 , thread->debug.dvc2);#endif -mtspr (SPRN_DBCR0 , thread->dbcr0); -mtspr (SPRN_DBCR1 , thread->dbcr1); +mtspr (SPRN_DBCR0 , thread->debug.dbcr0); +mtspr (SPRN_DBCR1 , thread->debug.dbcr1);#ifdef CONFIG_BOOKE -mtspr (SPRN_DBCR2 , thread->dbcr2); +mtspr (SPRN_DBCR2 , thread->debug.dbcr2);#endif }/* @@ -373,8 +373,8 @@ static void prime_debug_regs(struct thread_struct *thread)*/ static void switch_booke_debug_regs (struct thread_struct *new_thread) { -if ((current->thread.dbcr0 &DBCR0_IDM ) - || (new_thread->dbcr0 &DBCR0_IDM )) +if ((current->thread.debug.dbcr0 &DBCR0_IDM ) + || (new_thread->debug.dbcr0 &DBCR0_IDM ))prime_debug_regs (new_thread); }#else /* !CONFIG_PPC_ADV_DEBUG_REGS */ arch/powerpc/kernel/ptrace.c +77
-77@@ -854,8 +854,8 @@ void user_enable_single_step(struct task_struct *task)if (regs !=NULL ) {#ifdef CONFIG_PPC_ADV_DEBUG_REGS - task->thread.dbcr0 &= ~DBCR0_BT ; - task->thread.dbcr0 |=DBCR0_IDM |DBCR0_IC ; + task->thread.debug.dbcr0 &= ~DBCR0_BT ; + task->thread.debug.dbcr0 |=DBCR0_IDM |DBCR0_IC ; regs->msr |=MSR_DE ;#else regs->msr &= ~MSR_BE ;@@ -871,8 +871,8 @@ void user_enable_block_step(struct task_struct *task)if (regs !=NULL ) {#ifdef CONFIG_PPC_ADV_DEBUG_REGS - task->thread.dbcr0 &= ~DBCR0_IC ; - task->thread.dbcr0 =DBCR0_IDM |DBCR0_BT ; + task->thread.debug.dbcr0 &= ~DBCR0_IC ; + task->thread.debug.dbcr0 =DBCR0_IDM |DBCR0_BT ; regs->msr |=MSR_DE ;#else regs->msr &= ~MSR_SE ;@@ -894,16 +894,16 @@ void user_disable_single_step(struct task_struct *task)* And, after doing so, if all debug flags are off, turn * off DBCR0(IDM) and MSR(DE) .... Torez */ - task->thread.dbcr0 &= ~DBCR0_IC ; + task->thread.debug.dbcr0 &= ~DBCR0_IC ;/* * Test to see if any of the DBCR_ACTIVE_EVENTS bits are set. */ -if (!DBCR_ACTIVE_EVENTS (task->thread.dbcr0, - task->thread.dbcr1)) { +if (!DBCR_ACTIVE_EVENTS (task->thread.debug.dbcr0, + task->thread.debug.dbcr1)) {/* * All debug events were off..... */ - task->thread.dbcr0 &= ~DBCR0_IDM ; + task->thread.debug.dbcr0 &= ~DBCR0_IDM ; regs->msr &= ~MSR_DE ; }#else @@ -1022,14 +1022,14 @@ int ptrace_set_debugreg(struct task_struct *task, unsigned long addr,*/ /* DAC's hold the whole address without any mode flags */ - task->thread.dac1 = data & ~0x3UL ; + task->thread.debug.dac1 = data & ~0x3UL ; -if (task->thread.dac1 ==0 ) { +if (task->thread.debug.dac1 ==0 ) {dbcr_dac (task) &= ~(DBCR_DAC1R |DBCR_DAC1W ); -if (!DBCR_ACTIVE_EVENTS (task->thread.dbcr0, - task->thread.dbcr1)) { +if (!DBCR_ACTIVE_EVENTS (task->thread.debug.dbcr0, + task->thread.debug.dbcr1)) { task->thread.regs->msr &= ~MSR_DE ; - task->thread.dbcr0 &= ~DBCR0_IDM ; + task->thread.debug.dbcr0 &= ~DBCR0_IDM ; }return 0 ; }@@ -1041,7 +1041,7 @@ int ptrace_set_debugreg(struct task_struct *task, unsigned long addr,/* Set the Internal Debugging flag (IDM bit 1) for the DBCR0 register */ - task->thread.dbcr0 |=DBCR0_IDM ; + task->thread.debug.dbcr0 |=DBCR0_IDM ;/* Check for write and read flags and set DBCR0 accordingly */ @@ -1071,10 +1071,10 @@ static long set_instruction_bp(struct task_struct *child, struct ppc_hw_breakpoint *bp_info) {int slot; -int slot1_in_use = ((child->thread.dbcr0 &DBCR0_IAC1 ) !=0 ); -int slot2_in_use = ((child->thread.dbcr0 &DBCR0_IAC2 ) !=0 ); -int slot3_in_use = ((child->thread.dbcr0 &DBCR0_IAC3 ) !=0 ); -int slot4_in_use = ((child->thread.dbcr0 &DBCR0_IAC4 ) !=0 ); +int slot1_in_use = ((child->thread.debug.dbcr0 &DBCR0_IAC1 ) !=0 ); +int slot2_in_use = ((child->thread.debug.dbcr0 &DBCR0_IAC2 ) !=0 ); +int slot3_in_use = ((child->thread.debug.dbcr0 &DBCR0_IAC3 ) !=0 ); +int slot4_in_use = ((child->thread.debug.dbcr0 &DBCR0_IAC4 ) !=0 );if (dbcr_iac_range (child) &DBCR_IAC12MODE ) slot2_in_use =1 ;@@ -1093,9 +1093,9 @@ static long set_instruction_bp(struct task_struct *child,/* We need a pair of IAC regsisters */ if ((!slot1_in_use) && (!slot2_in_use)) { slot =1 ; - child->thread.iac1 = bp_info->addr; - child->thread.iac2 = bp_info->addr2; - child->thread.dbcr0 |=DBCR0_IAC1 ; + child->thread.debug.iac1 = bp_info->addr; + child->thread.debug.iac2 = bp_info->addr2; + child->thread.debug.dbcr0 |=DBCR0_IAC1 ;if (bp_info->addr_mode ==PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE )dbcr_iac_range (child) |=DBCR_IAC12X ;@@ -1104,9 +1104,9 @@ static long set_instruction_bp(struct task_struct *child,#if CONFIG_PPC_ADV_DEBUG_IACS >2 } else if ((!slot3_in_use) && (!slot4_in_use)) { slot =3 ; - child->thread.iac3 = bp_info->addr; - child->thread.iac4 = bp_info->addr2; - child->thread.dbcr0 |=DBCR0_IAC3 ; + child->thread.debug.iac3 = bp_info->addr; + child->thread.debug.iac4 = bp_info->addr2; + child->thread.debug.dbcr0 |=DBCR0_IAC3 ;if (bp_info->addr_mode ==PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE )dbcr_iac_range (child) |=DBCR_IAC34X ;@@ -1126,30 +1126,30 @@ static long set_instruction_bp(struct task_struct *child,*/ if (slot2_in_use || (slot3_in_use == slot4_in_use)) { slot =1 ; - child->thread.iac1 = bp_info->addr; - child->thread.dbcr0 |=DBCR0_IAC1 ; + child->thread.debug.iac1 = bp_info->addr; + child->thread.debug.dbcr0 |=DBCR0_IAC1 ; goto out; } }if (!slot2_in_use) { slot =2 ; - child->thread.iac2 = bp_info->addr; - child->thread.dbcr0 |=DBCR0_IAC2 ; + child->thread.debug.iac2 = bp_info->addr; + child->thread.debug.dbcr0 |=DBCR0_IAC2 ;#if CONFIG_PPC_ADV_DEBUG_IACS >2 } else if (!slot3_in_use) { slot =3 ; - child->thread.iac3 = bp_info->addr; - child->thread.dbcr0 |=DBCR0_IAC3 ; + child->thread.debug.iac3 = bp_info->addr; + child->thread.debug.dbcr0 |=DBCR0_IAC3 ; }else if (!slot4_in_use) { slot =4 ; - child->thread.iac4 = bp_info->addr; - child->thread.dbcr0 |=DBCR0_IAC4 ; + child->thread.debug.iac4 = bp_info->addr; + child->thread.debug.dbcr0 |=DBCR0_IAC4 ;#endif }else return -ENOSPC ; } out: - child->thread.dbcr0 |=DBCR0_IDM ; + child->thread.debug.dbcr0 |=DBCR0_IDM ; child->thread.regs->msr |=MSR_DE ;return slot;@@ -1159,49 +1159,49 @@ static int del_instruction_bp(struct task_struct *child, int slot) {switch (slot) {case 1 : -if ((child->thread.dbcr0 &DBCR0_IAC1 ) ==0 ) +if ((child->thread.debug.dbcr0 &DBCR0_IAC1 ) ==0 )return -ENOENT ;if (dbcr_iac_range (child) &DBCR_IAC12MODE ) {/* address range - clear slots 1 & 2 */ - child->thread.iac2 =0 ; + child->thread.debug.iac2 =0 ;dbcr_iac_range (child) &= ~DBCR_IAC12MODE ; } - child->thread.iac1 =0 ; - child->thread.dbcr0 &= ~DBCR0_IAC1 ; + child->thread.debug.iac1 =0 ; + child->thread.debug.dbcr0 &= ~DBCR0_IAC1 ;break ;case 2 : -if ((child->thread.dbcr0 &DBCR0_IAC2 ) ==0 ) +if ((child->thread.debug.dbcr0 &DBCR0_IAC2 ) ==0 )return -ENOENT ;if (dbcr_iac_range (child) &DBCR_IAC12MODE )/* used in a range */ return -EINVAL ; - child->thread.iac2 =0 ; - child->thread.dbcr0 &= ~DBCR0_IAC2 ; + child->thread.debug.iac2 =0 ; + child->thread.debug.dbcr0 &= ~DBCR0_IAC2 ;break ;#if CONFIG_PPC_ADV_DEBUG_IACS >2 case 3 : -if ((child->thread.dbcr0 &DBCR0_IAC3 ) ==0 ) +if ((child->thread.debug.dbcr0 &DBCR0_IAC3 ) ==0 )return -ENOENT ;if (dbcr_iac_range (child) &DBCR_IAC34MODE ) {/* address range - clear slots 3 & 4 */ - child->thread.iac4 =0 ; + child->thread.debug.iac4 =0 ;dbcr_iac_range (child) &= ~DBCR_IAC34MODE ; } - child->thread.iac3 =0 ; - child->thread.dbcr0 &= ~DBCR0_IAC3 ; + child->thread.debug.iac3 =0 ; + child->thread.debug.dbcr0 &= ~DBCR0_IAC3 ;break ;case 4 : -if ((child->thread.dbcr0 &DBCR0_IAC4 ) ==0 ) +if ((child->thread.debug.dbcr0 &DBCR0_IAC4 ) ==0 )return -ENOENT ;if (dbcr_iac_range (child) &DBCR_IAC34MODE )/* Used in a range */ return -EINVAL ; - child->thread.iac4 =0 ; - child->thread.dbcr0 &= ~DBCR0_IAC4 ; + child->thread.debug.iac4 =0 ; + child->thread.debug.dbcr0 &= ~DBCR0_IAC4 ;break ;#endif default :@@ -1231,18 +1231,18 @@ static int set_dac(struct task_struct *child, struct ppc_hw_breakpoint *bp_info)dbcr_dac (child) |=DBCR_DAC1R ;if (bp_info->trigger_type &PPC_BREAKPOINT_TRIGGER_WRITE )dbcr_dac (child) |=DBCR_DAC1W ; - child->thread.dac1 = (unsigned long )bp_info->addr; + child->thread.debug.dac1 = (unsigned long )bp_info->addr;#if CONFIG_PPC_ADV_DEBUG_DVCS >0 if (byte_enable) { - child->thread.dvc1 = + child->thread.debug.dvc1 = (unsigned long )bp_info->condition_value; - child->thread.dbcr2 |= + child->thread.debug.dbcr2 |= ((byte_enable <<DBCR2_DVC1BE_SHIFT ) | (condition_mode <<DBCR2_DVC1M_SHIFT )); }#endif #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE - }else if (child->thread.dbcr2 &DBCR2_DAC12MODE ) { + }else if (child->thread.debug.dbcr2 &DBCR2_DAC12MODE ) {/* Both dac1 and dac2 are part of a range */ return -ENOSPC ;#endif @@ -1252,19 +1252,19 @@ static int set_dac(struct task_struct *child, struct ppc_hw_breakpoint *bp_info)dbcr_dac (child) |=DBCR_DAC2R ;if (bp_info->trigger_type &PPC_BREAKPOINT_TRIGGER_WRITE )dbcr_dac (child) |=DBCR_DAC2W ; - child->thread.dac2 = (unsigned long )bp_info->addr; + child->thread.debug.dac2 = (unsigned long )bp_info->addr;#if CONFIG_PPC_ADV_DEBUG_DVCS >0 if (byte_enable) { - child->thread.dvc2 = + child->thread.debug.dvc2 = (unsigned long )bp_info->condition_value; - child->thread.dbcr2 |= + child->thread.debug.dbcr2 |= ((byte_enable <<DBCR2_DVC2BE_SHIFT ) | (condition_mode <<DBCR2_DVC2M_SHIFT )); }#endif }else return -ENOSPC ; - child->thread.dbcr0 |=DBCR0_IDM ; + child->thread.debug.dbcr0 |=DBCR0_IDM ; child->thread.regs->msr |=MSR_DE ;return slot +4 ;@@ -1276,32 +1276,32 @@ static int del_dac(struct task_struct *child, int slot)if ((dbcr_dac (child) & (DBCR_DAC1R |DBCR_DAC1W )) ==0 )return -ENOENT ; - child->thread.dac1 =0 ; + child->thread.debug.dac1 =0 ;dbcr_dac (child) &= ~(DBCR_DAC1R |DBCR_DAC1W );#ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE -if (child->thread.dbcr2 &DBCR2_DAC12MODE ) { - child->thread.dac2 =0 ; - child->thread.dbcr2 &= ~DBCR2_DAC12MODE ; +if (child->thread.debug.dbcr2 &DBCR2_DAC12MODE ) { + child->thread.debug.dac2 =0 ; + child->thread.debug.dbcr2 &= ~DBCR2_DAC12MODE ; } - child->thread.dbcr2 &= ~(DBCR2_DVC1M |DBCR2_DVC1BE ); + child->thread.debug.dbcr2 &= ~(DBCR2_DVC1M |DBCR2_DVC1BE );#endif #if CONFIG_PPC_ADV_DEBUG_DVCS >0 - child->thread.dvc1 =0 ; + child->thread.debug.dvc1 =0 ;#endif }else if (slot ==2 ) {if ((dbcr_dac (child) & (DBCR_DAC2R |DBCR_DAC2W )) ==0 )return -ENOENT ;#ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE -if (child->thread.dbcr2 &DBCR2_DAC12MODE ) +if (child->thread.debug.dbcr2 &DBCR2_DAC12MODE )/* Part of a range */ return -EINVAL ; - child->thread.dbcr2 &= ~(DBCR2_DVC2M |DBCR2_DVC2BE ); + child->thread.debug.dbcr2 &= ~(DBCR2_DVC2M |DBCR2_DVC2BE );#endif #if CONFIG_PPC_ADV_DEBUG_DVCS >0 - child->thread.dvc2 =0 ; + child->thread.debug.dvc2 =0 ;#endif - child->thread.dac2 =0 ; + child->thread.debug.dac2 =0 ;dbcr_dac (child) &= ~(DBCR_DAC2R |DBCR_DAC2W ); }else return -EINVAL ;@@ -1343,22 +1343,22 @@ static int set_dac_range(struct task_struct *child,return -EIO ; } -if (child->thread.dbcr0 & +if (child->thread.debug.dbcr0 & (DBCR0_DAC1R |DBCR0_DAC1W |DBCR0_DAC2R |DBCR0_DAC2W ))return -ENOSPC ;if (bp_info->trigger_type &PPC_BREAKPOINT_TRIGGER_READ ) - child->thread.dbcr0 |= (DBCR0_DAC1R |DBCR0_IDM ); + child->thread.debug.dbcr0 |= (DBCR0_DAC1R |DBCR0_IDM );if (bp_info->trigger_type &PPC_BREAKPOINT_TRIGGER_WRITE ) - child->thread.dbcr0 |= (DBCR0_DAC1W |DBCR0_IDM ); - child->thread.dac1 = bp_info->addr; - child->thread.dac2 = bp_info->addr2; + child->thread.debug.dbcr0 |= (DBCR0_DAC1W |DBCR0_IDM ); + child->thread.debug.dac1 = bp_info->addr; + child->thread.debug.dac2 = bp_info->addr2;if (mode ==PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE ) - child->thread.dbcr2 |=DBCR2_DAC12M ; + child->thread.debug.dbcr2 |=DBCR2_DAC12M ;else if (mode ==PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE ) - child->thread.dbcr2 |=DBCR2_DAC12MX ; + child->thread.debug.dbcr2 |=DBCR2_DAC12MX ;else /* PPC_BREAKPOINT_MODE_MASK */ - child->thread.dbcr2 |=DBCR2_DAC12MM ; + child->thread.debug.dbcr2 |=DBCR2_DAC12MM ; child->thread.regs->msr |=MSR_DE ;return 5 ;@@ -1489,9 +1489,9 @@ static long ppc_del_hwdebug(struct task_struct *child, long data) rc =del_dac (child, (int )data -4 );if (!rc) { -if (!DBCR_ACTIVE_EVENTS (child->thread.dbcr0, - child->thread.dbcr1)) { - child->thread.dbcr0 &= ~DBCR0_IDM ; +if (!DBCR_ACTIVE_EVENTS (child->thread.debug.dbcr0, + child->thread.debug.dbcr1)) { + child->thread.debug.dbcr0 &= ~DBCR0_IDM ; child->thread.regs->msr &= ~MSR_DE ; } }@@ -1669,7 +1669,7 @@ long arch_ptrace(struct task_struct *child, long request,if (addr >0 )break ;#ifdef CONFIG_PPC_ADV_DEBUG_REGS - ret =put_user (child->thread.dac1, datalp); + ret =put_user (child->thread.debug.dac1, datalp);#else dabr_fake = ((child->thread.hw_brk.address & (~HW_BRK_TYPE_DABR )) | (child->thread.hw_brk.type &HW_BRK_TYPE_DABR ));arch/powerpc/kernel/ptrace32.c +1
-1@@ -269,7 +269,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,if (addr >0 )break ;#ifdef CONFIG_PPC_ADV_DEBUG_REGS - ret =put_user (child->thread.dac1, (u32 __user *)data); + ret =put_user (child->thread.debug.dac1, (u32 __user *)data);#else dabr_fake = ( (child->thread.hw_brk.address & (~HW_BRK_TYPE_DABR)) |arch/powerpc/kernel/signal_32.c +3
-3@@ -1309,7 +1309,7 @@ int sys_debug_setcontext(struct ucontext __user *ctx,unsigned char tmp;unsigned long new_msr = regs->msr;#ifdef CONFIG_PPC_ADV_DEBUG_REGS -unsigned long new_dbcr0 = current->thread.dbcr0; +unsigned long new_dbcr0 = current->thread.debug.dbcr0;#endif for (i=0 ; i<ndbg; i++) {@@ -1324,7 +1324,7 @@ int sys_debug_setcontext(struct ucontext __user *ctx, }else { new_dbcr0 &= ~DBCR0_IC ;if (!DBCR_ACTIVE_EVENTS (new_dbcr0, - current->thread.dbcr1)) { + current->thread.debug.dbcr1)) { new_msr &= ~MSR_DE ; new_dbcr0 &= ~DBCR0_IDM ; }@@ -1359,7 +1359,7 @@ int sys_debug_setcontext(struct ucontext __user *ctx,the user is really doing something wrong. */ regs->msr = new_msr;#ifdef CONFIG_PPC_ADV_DEBUG_REGS - current->thread.dbcr0 = new_dbcr0; + current->thread.debug.dbcr0 = new_dbcr0;#endif if (!access_ok(VERIFY_READ, ctx, sizeof(*ctx))arch/powerpc/kernel/traps.c +18
-17@@ -351,8 +351,8 @@ static inline int check_io_access(struct pt_regs *regs)#define REASON_TRAP ESR_PTR/* single-step stuff */ -#define single_stepping (regs) (current->thread.dbcr0 & DBCR0_IC) -#define clear_single_step (regs) (current->thread.dbcr0 &= ~DBCR0_IC) +#define single_stepping (regs) (current->thread.debug.dbcr0 & DBCR0_IC) +#define clear_single_step (regs) (current->thread.debug.dbcr0 &= ~DBCR0_IC)#else /* On non-4xx, the reason for the machine check or program @@ -1486,7 +1486,7 @@ static void handle_debug(struct pt_regs *regs, unsigned long debug_status)if (debug_status & (DBSR_DAC1R |DBSR_DAC1W )) {dbcr_dac (current) &= ~(DBCR_DAC1R |DBCR_DAC1W );#ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE - current->thread.dbcr2 &= ~DBCR2_DAC12MODE ; + current->thread.debug.dbcr2 &= ~DBCR2_DAC12MODE ;#endif do_send_trap (regs,mfspr (SPRN_DAC1 ), debug_status,TRAP_HWBKPT ,5 );@@ -1497,24 +1497,24 @@ static void handle_debug(struct pt_regs *regs, unsigned long debug_status) 6); changed |=0x01 ; }else if (debug_status &DBSR_IAC1 ) { - current->thread.dbcr0 &= ~DBCR0_IAC1 ; + current->thread.debug.dbcr0 &= ~DBCR0_IAC1 ;dbcr_iac_range (current) &= ~DBCR_IAC12MODE ;do_send_trap (regs,mfspr (SPRN_IAC1 ), debug_status,TRAP_HWBKPT ,1 ); changed |=0x01 ; }else if (debug_status &DBSR_IAC2 ) { - current->thread.dbcr0 &= ~DBCR0_IAC2 ; + current->thread.debug.dbcr0 &= ~DBCR0_IAC2 ;do_send_trap (regs,mfspr (SPRN_IAC2 ), debug_status,TRAP_HWBKPT ,2 ); changed |=0x01 ; }else if (debug_status &DBSR_IAC3 ) { - current->thread.dbcr0 &= ~DBCR0_IAC3 ; + current->thread.debug.dbcr0 &= ~DBCR0_IAC3 ;dbcr_iac_range (current) &= ~DBCR_IAC34MODE ;do_send_trap (regs,mfspr (SPRN_IAC3 ), debug_status,TRAP_HWBKPT ,3 ); changed |=0x01 ; }else if (debug_status &DBSR_IAC4 ) { - current->thread.dbcr0 &= ~DBCR0_IAC4 ; + current->thread.debug.dbcr0 &= ~DBCR0_IAC4 ;do_send_trap (regs,mfspr (SPRN_IAC4 ), debug_status,TRAP_HWBKPT ,4 ); changed |=0x01 ;@@ -1524,19 +1524,20 @@ static void handle_debug(struct pt_regs *regs, unsigned long debug_status)* Check all other debug flags and see if that bit needs to be turned * back on or not. */ -if (DBCR_ACTIVE_EVENTS (current->thread.dbcr0, current->thread.dbcr1)) +if (DBCR_ACTIVE_EVENTS (current->thread.debug.dbcr0, + current->thread.debug.dbcr1)) regs->msr |=MSR_DE ;else /* Make sure the IDM flag is off */ - current->thread.dbcr0 &= ~DBCR0_IDM ; + current->thread.debug.dbcr0 &= ~DBCR0_IDM ;if (changed &0x01 ) -mtspr (SPRN_DBCR0 , current->thread.dbcr0); +mtspr (SPRN_DBCR0 , current->thread.debug.dbcr0); }void __kprobes DebugException (struct pt_regs *regs,unsigned long debug_status) { - current->thread.dbsr = debug_status; + current->thread.debug.dbsr = debug_status;/* Hack alert: On BookE, Branch Taken stops on the branch itself, while * on server, it stops on the target of the branch. In order to simulate @@ -1553,8 +1554,8 @@ void __kprobes DebugException(struct pt_regs *regs, unsigned long debug_status)/* Do the single step trick only when coming from userspace */ if (user_mode (regs)) { - current->thread.dbcr0 &= ~DBCR0_BT ; - current->thread.dbcr0 |=DBCR0_IDM |DBCR0_IC ; + current->thread.debug.dbcr0 &= ~DBCR0_BT ; + current->thread.debug.dbcr0 |=DBCR0_IDM |DBCR0_IC ; regs->msr |=MSR_DE ;return ; }@@ -1582,13 +1583,13 @@ void __kprobes DebugException(struct pt_regs *regs, unsigned long debug_status)return ;if (user_mode (regs)) { - current->thread.dbcr0 &= ~DBCR0_IC ; -if (DBCR_ACTIVE_EVENTS (current->thread.dbcr0, - current->thread.dbcr1)) + current->thread.debug.dbcr0 &= ~DBCR0_IC ; +if (DBCR_ACTIVE_EVENTS (current->thread.debug.dbcr0, + current->thread.debug.dbcr1)) regs->msr |=MSR_DE ;else /* Make sure the IDM bit is off */ - current->thread.dbcr0 &= ~DBCR0_IDM ; + current->thread.debug.dbcr0 &= ~DBCR0_IDM ; }_exception (SIGTRAP , regs,TRAP_TRACE , regs->nip);Signature · 1 line
1.8.1.4
--
Gleb.
Re: [PULL 34/51] powerpc: move debug registers in a structure
Quoted 10 lines · Gleb Natapov
Quoted 7 lines · Alexander Graf
From: Bharat Bhushan <[email protected]>
This way we can use same data type struct with KVM and also help in using other debug related function.
Signed-off-by Bharat Bhushan <[email protected]>Signed-off-by Alexander Graf <[email protected]>It would be nice to have PPC maintainers (CCed) ACKs here. This patch also has merging conflicts with
cbc9565e(should be easy to resolve)
Is it easier if I put it in powerpc -next and resolve the conflicts ?
I was ok with the patch but yes, I should probably have put it in a topic branch in the first place and merge it both in my tree and Alex.
Cheers,
Ben.
Quoted 726 lines
Quoted 723 lines
--- arch/powerpc/include/asm/processor.h | 38 +++++---- arch/powerpc/include/asm/reg_booke.h | 8 +- arch/powerpc/kernel/asm-offsets.c | 2 +- arch/powerpc/kernel/process.c | 42 +++++----- arch/powerpc/kernel/ptrace.c | 154 +++++++++++++++++------------------ arch/powerpc/kernel/ptrace32.c | 2 +- arch/powerpc/kernel/signal_32.c | 6 +- arch/powerpc/kernel/traps.c | 35 ++++---- 8 files changed, 147 insertions(+), 140 deletions(-)arch/powerpc/include/asm/processor.h +22
-16@@ -147,22 +147,7 @@ typedef struct {#define TS_FPR (i) fpr[i][TS_FPROFFSET]#define TS_TRANS_FPR (i) transact_fpr[i][TS_FPROFFSET] -struct thread_struct { -unsigned long ksp;/* Kernel stack pointer */ -unsigned long ksp_limit;/* if ksp <= ksp_limit stack overflow */ - -#ifdef CONFIG_PPC64 -unsigned long ksp_vsid; -#endif -struct pt_regs *regs;/* Pointer to saved register state */ -mm_segment_t fs;/* for get_fs() validation */ -#ifdef CONFIG_BOOKE -/* BookE base exception scratch space; align on cacheline */ -unsigned long normsave[8 ]____cacheline_aligned ; -#endif -#ifdef CONFIG_PPC32 -void *pgdir;/* root of page-table tree */ -#endif +struct debug_reg {#ifdef CONFIG_PPC_ADV_DEBUG_REGS /* * The following help to manage the use of Debug Control Registers @@ -199,6 +184,27 @@ struct thread_struct {unsigned long dvc2;#endif #endif +}; + +struct thread_struct { +unsigned long ksp;/* Kernel stack pointer */ +unsigned long ksp_limit;/* if ksp <= ksp_limit stack overflow */ + +#ifdef CONFIG_PPC64 +unsigned long ksp_vsid; +#endif +struct pt_regs *regs;/* Pointer to saved register state */ +mm_segment_t fs;/* for get_fs() validation */ +#ifdef CONFIG_BOOKE +/* BookE base exception scratch space; align on cacheline */ +unsigned long normsave[8 ]____cacheline_aligned ; +#endif +#ifdef CONFIG_PPC32 +void *pgdir;/* root of page-table tree */ +#endif +/* Debug Registers */ +struct debug_reg debug; +/* FP and VSX 0-31 register set */ double fpr[32 ][TS_FPRWIDTH ] __attribute__((aligned (16 )));struct {arch/powerpc/include/asm/reg_booke.h +4
-4@@ -381,7 +381,7 @@#define DBCR0_IA34T 0x00004000/* Instr Addr 3-4 range Toggle */ #define DBCR0_FT 0x00000001/* Freeze Timers on debug event */ -#define dbcr_iac_range (task) ((task)->thread.dbcr0) +#define dbcr_iac_range (task) ((task)->thread.debug.dbcr0)#define DBCR_IAC12I DBCR0_IA12/* Range Inclusive */ #define DBCR_IAC12X (DBCR0_IA12 | DBCR0_IA12X)/* Range Exclusive */ #define DBCR_IAC12MODE (DBCR0_IA12 | DBCR0_IA12X)/* IAC 1-2 Mode Bits */ @@ -395,7 +395,7 @@#define DBCR1_DAC1W 0x20000000/* DAC1 Write Debug Event */ #define DBCR1_DAC2W 0x10000000/* DAC2 Write Debug Event */ -#define dbcr_dac (task) ((task)->thread.dbcr1) +#define dbcr_dac (task) ((task)->thread.debug.dbcr1)#define DBCR_DAC1R DBCR1_DAC1R#define DBCR_DAC1W DBCR1_DAC1W#define DBCR_DAC2R DBCR1_DAC2R@@ -441,7 +441,7 @@#define DBCR0_CRET 0x00000020/* Critical Return Debug Event */ #define DBCR0_FT 0x00000001/* Freeze Timers on debug event */ -#define dbcr_dac (task) ((task)->thread.dbcr0) +#define dbcr_dac (task) ((task)->thread.debug.dbcr0)#define DBCR_DAC1R DBCR0_DAC1R#define DBCR_DAC1W DBCR0_DAC1W#define DBCR_DAC2R DBCR0_DAC2R@@ -475,7 +475,7 @@#define DBCR1_IAC34MX 0x000000C0/* Instr Addr 3-4 range eXclusive */ #define DBCR1_IAC34AT 0x00000001/* Instr Addr 3-4 range Toggle */ -#define dbcr_iac_range (task) ((task)->thread.dbcr1) +#define dbcr_iac_range (task) ((task)->thread.debug.dbcr1)#define DBCR_IAC12I DBCR1_IAC12M/* Range Inclusive */ #define DBCR_IAC12X DBCR1_IAC12MX/* Range Exclusive */ #define DBCR_IAC12MODE DBCR1_IAC12MX/* IAC 1-2 Mode Bits */ arch/powerpc/kernel/asm-offsets.c +1
-1@@ -113,7 +113,7 @@ int main(void)#endif /* CONFIG_SPE */ #endif /* CONFIG_PPC64 */ #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE ) -DEFINE (THREAD_DBCR0 , offsetof(struct thread_struct , dbcr0)); + DEFINE(THREAD_DBCR0, offsetof(struct thread_struct, debug.dbcr0));#endif #ifdef CONFIG_KVM_BOOK3S_32_HANDLER DEFINE (THREAD_KVM_SVCPU , offsetof(struct thread_struct , kvm_shadow_vcpu));arch/powerpc/kernel/process.c +21
-21@@ -314,28 +314,28 @@ static DEFINE_PER_CPU(struct arch_hw_breakpoint, current_brk);*/ static void set_debug_reg_defaults (struct thread_struct *thread) { - thread->iac1 = thread->iac2 =0 ; + thread->debug.iac1 = thread->debug.iac2 =0 ;#if CONFIG_PPC_ADV_DEBUG_IACS >2 - thread->iac3 = thread->iac4 =0 ; + thread->debug.iac3 = thread->debug.iac4 =0 ;#endif - thread->dac1 = thread->dac2 =0 ; + thread->debug.dac1 = thread->debug.dac2 =0 ;#if CONFIG_PPC_ADV_DEBUG_DVCS >0 - thread->dvc1 = thread->dvc2 =0 ; + thread->debug.dvc1 = thread->debug.dvc2 =0 ;#endif - thread->dbcr0 =0 ; + thread->debug.dbcr0 =0 ;#ifdef CONFIG_BOOKE /* * Force User/Supervisor bits to b11 (user-only MSR[PR]=1) */ - thread->dbcr1 =DBCR1_IAC1US |DBCR1_IAC2US | + thread->debug.dbcr1 =DBCR1_IAC1US |DBCR1_IAC2US |DBCR1_IAC3US |DBCR1_IAC4US ;/* * Force Data Address Compare User/Supervisor bits to be User-only * (0b11 MSR[PR]=1) and set all other bits in DBCR2 register to be 0. */ - thread->dbcr2 =DBCR2_DAC1US |DBCR2_DAC2US ; + thread->debug.dbcr2 =DBCR2_DAC1US |DBCR2_DAC2US ;#else - thread->dbcr1 =0 ; + thread->debug.dbcr1 =0 ;#endif }@@ -348,22 +348,22 @@ static void prime_debug_regs(struct thread_struct *thread)*/ mtmsr (mfmsr () & ~MSR_DE ); -mtspr (SPRN_IAC1 , thread->iac1); -mtspr (SPRN_IAC2 , thread->iac2); +mtspr (SPRN_IAC1 , thread->debug.iac1); +mtspr (SPRN_IAC2 , thread->debug.iac2);#if CONFIG_PPC_ADV_DEBUG_IACS >2 -mtspr (SPRN_IAC3 , thread->iac3); -mtspr (SPRN_IAC4 , thread->iac4); +mtspr (SPRN_IAC3 , thread->debug.iac3); +mtspr (SPRN_IAC4 , thread->debug.iac4);#endif -mtspr (SPRN_DAC1 , thread->dac1); -mtspr (SPRN_DAC2 , thread->dac2); +mtspr (SPRN_DAC1 , thread->debug.dac1); +mtspr (SPRN_DAC2 , thread->debug.dac2);#if CONFIG_PPC_ADV_DEBUG_DVCS >0 -mtspr (SPRN_DVC1 , thread->dvc1); -mtspr (SPRN_DVC2 , thread->dvc2); +mtspr (SPRN_DVC1 , thread->debug.dvc1); +mtspr (SPRN_DVC2 , thread->debug.dvc2);#endif -mtspr (SPRN_DBCR0 , thread->dbcr0); -mtspr (SPRN_DBCR1 , thread->dbcr1); +mtspr (SPRN_DBCR0 , thread->debug.dbcr0); +mtspr (SPRN_DBCR1 , thread->debug.dbcr1);#ifdef CONFIG_BOOKE -mtspr (SPRN_DBCR2 , thread->dbcr2); +mtspr (SPRN_DBCR2 , thread->debug.dbcr2);#endif }/* @@ -373,8 +373,8 @@ static void prime_debug_regs(struct thread_struct *thread)*/ static void switch_booke_debug_regs (struct thread_struct *new_thread) { -if ((current->thread.dbcr0 &DBCR0_IDM ) - || (new_thread->dbcr0 &DBCR0_IDM )) +if ((current->thread.debug.dbcr0 &DBCR0_IDM ) + || (new_thread->debug.dbcr0 &DBCR0_IDM ))prime_debug_regs (new_thread); }#else /* !CONFIG_PPC_ADV_DEBUG_REGS */ arch/powerpc/kernel/ptrace.c +77
-77@@ -854,8 +854,8 @@ void user_enable_single_step(struct task_struct *task)if (regs !=NULL ) {#ifdef CONFIG_PPC_ADV_DEBUG_REGS - task->thread.dbcr0 &= ~DBCR0_BT ; - task->thread.dbcr0 |=DBCR0_IDM |DBCR0_IC ; + task->thread.debug.dbcr0 &= ~DBCR0_BT ; + task->thread.debug.dbcr0 |=DBCR0_IDM |DBCR0_IC ; regs->msr |=MSR_DE ;#else regs->msr &= ~MSR_BE ;@@ -871,8 +871,8 @@ void user_enable_block_step(struct task_struct *task)if (regs !=NULL ) {#ifdef CONFIG_PPC_ADV_DEBUG_REGS - task->thread.dbcr0 &= ~DBCR0_IC ; - task->thread.dbcr0 =DBCR0_IDM |DBCR0_BT ; + task->thread.debug.dbcr0 &= ~DBCR0_IC ; + task->thread.debug.dbcr0 =DBCR0_IDM |DBCR0_BT ; regs->msr |=MSR_DE ;#else regs->msr &= ~MSR_SE ;@@ -894,16 +894,16 @@ void user_disable_single_step(struct task_struct *task)* And, after doing so, if all debug flags are off, turn * off DBCR0(IDM) and MSR(DE) .... Torez */ - task->thread.dbcr0 &= ~DBCR0_IC ; + task->thread.debug.dbcr0 &= ~DBCR0_IC ;/* * Test to see if any of the DBCR_ACTIVE_EVENTS bits are set. */ -if (!DBCR_ACTIVE_EVENTS (task->thread.dbcr0, - task->thread.dbcr1)) { +if (!DBCR_ACTIVE_EVENTS (task->thread.debug.dbcr0, + task->thread.debug.dbcr1)) {/* * All debug events were off..... */ - task->thread.dbcr0 &= ~DBCR0_IDM ; + task->thread.debug.dbcr0 &= ~DBCR0_IDM ; regs->msr &= ~MSR_DE ; }#else @@ -1022,14 +1022,14 @@ int ptrace_set_debugreg(struct task_struct *task, unsigned long addr,*/ /* DAC's hold the whole address without any mode flags */ - task->thread.dac1 = data & ~0x3UL ; + task->thread.debug.dac1 = data & ~0x3UL ; -if (task->thread.dac1 ==0 ) { +if (task->thread.debug.dac1 ==0 ) {dbcr_dac (task) &= ~(DBCR_DAC1R |DBCR_DAC1W ); -if (!DBCR_ACTIVE_EVENTS (task->thread.dbcr0, - task->thread.dbcr1)) { +if (!DBCR_ACTIVE_EVENTS (task->thread.debug.dbcr0, + task->thread.debug.dbcr1)) { task->thread.regs->msr &= ~MSR_DE ; - task->thread.dbcr0 &= ~DBCR0_IDM ; + task->thread.debug.dbcr0 &= ~DBCR0_IDM ; }return 0 ; }@@ -1041,7 +1041,7 @@ int ptrace_set_debugreg(struct task_struct *task, unsigned long addr,/* Set the Internal Debugging flag (IDM bit 1) for the DBCR0 register */ - task->thread.dbcr0 |=DBCR0_IDM ; + task->thread.debug.dbcr0 |=DBCR0_IDM ;/* Check for write and read flags and set DBCR0 accordingly */ @@ -1071,10 +1071,10 @@ static long set_instruction_bp(struct task_struct *child, struct ppc_hw_breakpoint *bp_info) {int slot; -int slot1_in_use = ((child->thread.dbcr0 &DBCR0_IAC1 ) !=0 ); -int slot2_in_use = ((child->thread.dbcr0 &DBCR0_IAC2 ) !=0 ); -int slot3_in_use = ((child->thread.dbcr0 &DBCR0_IAC3 ) !=0 ); -int slot4_in_use = ((child->thread.dbcr0 &DBCR0_IAC4 ) !=0 ); +int slot1_in_use = ((child->thread.debug.dbcr0 &DBCR0_IAC1 ) !=0 ); +int slot2_in_use = ((child->thread.debug.dbcr0 &DBCR0_IAC2 ) !=0 ); +int slot3_in_use = ((child->thread.debug.dbcr0 &DBCR0_IAC3 ) !=0 ); +int slot4_in_use = ((child->thread.debug.dbcr0 &DBCR0_IAC4 ) !=0 );if (dbcr_iac_range (child) &DBCR_IAC12MODE ) slot2_in_use =1 ;@@ -1093,9 +1093,9 @@ static long set_instruction_bp(struct task_struct *child,/* We need a pair of IAC regsisters */ if ((!slot1_in_use) && (!slot2_in_use)) { slot =1 ; - child->thread.iac1 = bp_info->addr; - child->thread.iac2 = bp_info->addr2; - child->thread.dbcr0 |=DBCR0_IAC1 ; + child->thread.debug.iac1 = bp_info->addr; + child->thread.debug.iac2 = bp_info->addr2; + child->thread.debug.dbcr0 |=DBCR0_IAC1 ;if (bp_info->addr_mode ==PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE )dbcr_iac_range (child) |=DBCR_IAC12X ;@@ -1104,9 +1104,9 @@ static long set_instruction_bp(struct task_struct *child,#if CONFIG_PPC_ADV_DEBUG_IACS >2 } else if ((!slot3_in_use) && (!slot4_in_use)) { slot =3 ; - child->thread.iac3 = bp_info->addr; - child->thread.iac4 = bp_info->addr2; - child->thread.dbcr0 |=DBCR0_IAC3 ; + child->thread.debug.iac3 = bp_info->addr; + child->thread.debug.iac4 = bp_info->addr2; + child->thread.debug.dbcr0 |=DBCR0_IAC3 ;if (bp_info->addr_mode ==PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE )dbcr_iac_range (child) |=DBCR_IAC34X ;@@ -1126,30 +1126,30 @@ static long set_instruction_bp(struct task_struct *child,*/ if (slot2_in_use || (slot3_in_use == slot4_in_use)) { slot =1 ; - child->thread.iac1 = bp_info->addr; - child->thread.dbcr0 |=DBCR0_IAC1 ; + child->thread.debug.iac1 = bp_info->addr; + child->thread.debug.dbcr0 |=DBCR0_IAC1 ; goto out; } }if (!slot2_in_use) { slot =2 ; - child->thread.iac2 = bp_info->addr; - child->thread.dbcr0 |=DBCR0_IAC2 ; + child->thread.debug.iac2 = bp_info->addr; + child->thread.debug.dbcr0 |=DBCR0_IAC2 ;#if CONFIG_PPC_ADV_DEBUG_IACS >2 } else if (!slot3_in_use) { slot =3 ; - child->thread.iac3 = bp_info->addr; - child->thread.dbcr0 |=DBCR0_IAC3 ; + child->thread.debug.iac3 = bp_info->addr; + child->thread.debug.dbcr0 |=DBCR0_IAC3 ; }else if (!slot4_in_use) { slot =4 ; - child->thread.iac4 = bp_info->addr; - child->thread.dbcr0 |=DBCR0_IAC4 ; + child->thread.debug.iac4 = bp_info->addr; + child->thread.debug.dbcr0 |=DBCR0_IAC4 ;#endif }else return -ENOSPC ; } out: - child->thread.dbcr0 |=DBCR0_IDM ; + child->thread.debug.dbcr0 |=DBCR0_IDM ; child->thread.regs->msr |=MSR_DE ;return slot;@@ -1159,49 +1159,49 @@ static int del_instruction_bp(struct task_struct *child, int slot) {switch (slot) {case 1 : -if ((child->thread.dbcr0 &DBCR0_IAC1 ) ==0 ) +if ((child->thread.debug.dbcr0 &DBCR0_IAC1 ) ==0 )return -ENOENT ;if (dbcr_iac_range (child) &DBCR_IAC12MODE ) {/* address range - clear slots 1 & 2 */ - child->thread.iac2 =0 ; + child->thread.debug.iac2 =0 ;dbcr_iac_range (child) &= ~DBCR_IAC12MODE ; } - child->thread.iac1 =0 ; - child->thread.dbcr0 &= ~DBCR0_IAC1 ; + child->thread.debug.iac1 =0 ; + child->thread.debug.dbcr0 &= ~DBCR0_IAC1 ;break ;case 2 : -if ((child->thread.dbcr0 &DBCR0_IAC2 ) ==0 ) +if ((child->thread.debug.dbcr0 &DBCR0_IAC2 ) ==0 )return -ENOENT ;if (dbcr_iac_range (child) &DBCR_IAC12MODE )/* used in a range */ return -EINVAL ; - child->thread.iac2 =0 ; - child->thread.dbcr0 &= ~DBCR0_IAC2 ; + child->thread.debug.iac2 =0 ; + child->thread.debug.dbcr0 &= ~DBCR0_IAC2 ;break ;#if CONFIG_PPC_ADV_DEBUG_IACS >2 case 3 : -if ((child->thread.dbcr0 &DBCR0_IAC3 ) ==0 ) +if ((child->thread.debug.dbcr0 &DBCR0_IAC3 ) ==0 )return -ENOENT ;if (dbcr_iac_range (child) &DBCR_IAC34MODE ) {/* address range - clear slots 3 & 4 */ - child->thread.iac4 =0 ; + child->thread.debug.iac4 =0 ;dbcr_iac_range (child) &= ~DBCR_IAC34MODE ; } - child->thread.iac3 =0 ; - child->thread.dbcr0 &= ~DBCR0_IAC3 ; + child->thread.debug.iac3 =0 ; + child->thread.debug.dbcr0 &= ~DBCR0_IAC3 ;break ;case 4 : -if ((child->thread.dbcr0 &DBCR0_IAC4 ) ==0 ) +if ((child->thread.debug.dbcr0 &DBCR0_IAC4 ) ==0 )return -ENOENT ;if (dbcr_iac_range (child) &DBCR_IAC34MODE )/* Used in a range */ return -EINVAL ; - child->thread.iac4 =0 ; - child->thread.dbcr0 &= ~DBCR0_IAC4 ; + child->thread.debug.iac4 =0 ; + child->thread.debug.dbcr0 &= ~DBCR0_IAC4 ;break ;#endif default :@@ -1231,18 +1231,18 @@ static int set_dac(struct task_struct *child, struct ppc_hw_breakpoint *bp_info)dbcr_dac (child) |=DBCR_DAC1R ;if (bp_info->trigger_type &PPC_BREAKPOINT_TRIGGER_WRITE )dbcr_dac (child) |=DBCR_DAC1W ; - child->thread.dac1 = (unsigned long )bp_info->addr; + child->thread.debug.dac1 = (unsigned long )bp_info->addr;#if CONFIG_PPC_ADV_DEBUG_DVCS >0 if (byte_enable) { - child->thread.dvc1 = + child->thread.debug.dvc1 = (unsigned long )bp_info->condition_value; - child->thread.dbcr2 |= + child->thread.debug.dbcr2 |= ((byte_enable <<DBCR2_DVC1BE_SHIFT ) | (condition_mode <<DBCR2_DVC1M_SHIFT )); }#endif #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE - }else if (child->thread.dbcr2 &DBCR2_DAC12MODE ) { + }else if (child->thread.debug.dbcr2 &DBCR2_DAC12MODE ) {/* Both dac1 and dac2 are part of a range */ return -ENOSPC ;#endif @@ -1252,19 +1252,19 @@ static int set_dac(struct task_struct *child, struct ppc_hw_breakpoint *bp_info)dbcr_dac (child) |=DBCR_DAC2R ;if (bp_info->trigger_type &PPC_BREAKPOINT_TRIGGER_WRITE )dbcr_dac (child) |=DBCR_DAC2W ; - child->thread.dac2 = (unsigned long )bp_info->addr; + child->thread.debug.dac2 = (unsigned long )bp_info->addr;#if CONFIG_PPC_ADV_DEBUG_DVCS >0 if (byte_enable) { - child->thread.dvc2 = + child->thread.debug.dvc2 = (unsigned long )bp_info->condition_value; - child->thread.dbcr2 |= + child->thread.debug.dbcr2 |= ((byte_enable <<DBCR2_DVC2BE_SHIFT ) | (condition_mode <<DBCR2_DVC2M_SHIFT )); }#endif }else return -ENOSPC ; - child->thread.dbcr0 |=DBCR0_IDM ; + child->thread.debug.dbcr0 |=DBCR0_IDM ; child->thread.regs->msr |=MSR_DE ;return slot +4 ;@@ -1276,32 +1276,32 @@ static int del_dac(struct task_struct *child, int slot)if ((dbcr_dac (child) & (DBCR_DAC1R |DBCR_DAC1W )) ==0 )return -ENOENT ; - child->thread.dac1 =0 ; + child->thread.debug.dac1 =0 ;dbcr_dac (child) &= ~(DBCR_DAC1R |DBCR_DAC1W );#ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE -if (child->thread.dbcr2 &DBCR2_DAC12MODE ) { - child->thread.dac2 =0 ; - child->thread.dbcr2 &= ~DBCR2_DAC12MODE ; +if (child->thread.debug.dbcr2 &DBCR2_DAC12MODE ) { + child->thread.debug.dac2 =0 ; + child->thread.debug.dbcr2 &= ~DBCR2_DAC12MODE ; } - child->thread.dbcr2 &= ~(DBCR2_DVC1M |DBCR2_DVC1BE ); + child->thread.debug.dbcr2 &= ~(DBCR2_DVC1M |DBCR2_DVC1BE );#endif #if CONFIG_PPC_ADV_DEBUG_DVCS >0 - child->thread.dvc1 =0 ; + child->thread.debug.dvc1 =0 ;#endif }else if (slot ==2 ) {if ((dbcr_dac (child) & (DBCR_DAC2R |DBCR_DAC2W )) ==0 )return -ENOENT ;#ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE -if (child->thread.dbcr2 &DBCR2_DAC12MODE ) +if (child->thread.debug.dbcr2 &DBCR2_DAC12MODE )/* Part of a range */ return -EINVAL ; - child->thread.dbcr2 &= ~(DBCR2_DVC2M |DBCR2_DVC2BE ); + child->thread.debug.dbcr2 &= ~(DBCR2_DVC2M |DBCR2_DVC2BE );#endif #if CONFIG_PPC_ADV_DEBUG_DVCS >0 - child->thread.dvc2 =0 ; + child->thread.debug.dvc2 =0 ;#endif - child->thread.dac2 =0 ; + child->thread.debug.dac2 =0 ;dbcr_dac (child) &= ~(DBCR_DAC2R |DBCR_DAC2W ); }else return -EINVAL ;@@ -1343,22 +1343,22 @@ static int set_dac_range(struct task_struct *child,return -EIO ; } -if (child->thread.dbcr0 & +if (child->thread.debug.dbcr0 & (DBCR0_DAC1R |DBCR0_DAC1W |DBCR0_DAC2R |DBCR0_DAC2W ))return -ENOSPC ;if (bp_info->trigger_type &PPC_BREAKPOINT_TRIGGER_READ ) - child->thread.dbcr0 |= (DBCR0_DAC1R |DBCR0_IDM ); + child->thread.debug.dbcr0 |= (DBCR0_DAC1R |DBCR0_IDM );if (bp_info->trigger_type &PPC_BREAKPOINT_TRIGGER_WRITE ) - child->thread.dbcr0 |= (DBCR0_DAC1W |DBCR0_IDM ); - child->thread.dac1 = bp_info->addr; - child->thread.dac2 = bp_info->addr2; + child->thread.debug.dbcr0 |= (DBCR0_DAC1W |DBCR0_IDM ); + child->thread.debug.dac1 = bp_info->addr; + child->thread.debug.dac2 = bp_info->addr2;if (mode ==PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE ) - child->thread.dbcr2 |=DBCR2_DAC12M ; + child->thread.debug.dbcr2 |=DBCR2_DAC12M ;else if (mode ==PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE ) - child->thread.dbcr2 |=DBCR2_DAC12MX ; + child->thread.debug.dbcr2 |=DBCR2_DAC12MX ;else /* PPC_BREAKPOINT_MODE_MASK */ - child->thread.dbcr2 |=DBCR2_DAC12MM ; + child->thread.debug.dbcr2 |=DBCR2_DAC12MM ; child->thread.regs->msr |=MSR_DE ;return 5 ;@@ -1489,9 +1489,9 @@ static long ppc_del_hwdebug(struct task_struct *child, long data) rc =del_dac (child, (int )data -4 );if (!rc) { -if (!DBCR_ACTIVE_EVENTS (child->thread.dbcr0, - child->thread.dbcr1)) { - child->thread.dbcr0 &= ~DBCR0_IDM ; +if (!DBCR_ACTIVE_EVENTS (child->thread.debug.dbcr0, + child->thread.debug.dbcr1)) { + child->thread.debug.dbcr0 &= ~DBCR0_IDM ; child->thread.regs->msr &= ~MSR_DE ; } }@@ -1669,7 +1669,7 @@ long arch_ptrace(struct task_struct *child, long request,if (addr >0 )break ;#ifdef CONFIG_PPC_ADV_DEBUG_REGS - ret =put_user (child->thread.dac1, datalp); + ret =put_user (child->thread.debug.dac1, datalp);#else dabr_fake = ((child->thread.hw_brk.address & (~HW_BRK_TYPE_DABR )) | (child->thread.hw_brk.type &HW_BRK_TYPE_DABR ));arch/powerpc/kernel/ptrace32.c +1
-1@@ -269,7 +269,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,if (addr >0 )break ;#ifdef CONFIG_PPC_ADV_DEBUG_REGS - ret =put_user (child->thread.dac1, (u32 __user *)data); + ret =put_user (child->thread.debug.dac1, (u32 __user *)data);#else dabr_fake = ( (child->thread.hw_brk.address & (~HW_BRK_TYPE_DABR)) |arch/powerpc/kernel/signal_32.c +3
-3@@ -1309,7 +1309,7 @@ int sys_debug_setcontext(struct ucontext __user *ctx,unsigned char tmp;unsigned long new_msr = regs->msr;#ifdef CONFIG_PPC_ADV_DEBUG_REGS -unsigned long new_dbcr0 = current->thread.dbcr0; +unsigned long new_dbcr0 = current->thread.debug.dbcr0;#endif for (i=0 ; i<ndbg; i++) {@@ -1324,7 +1324,7 @@ int sys_debug_setcontext(struct ucontext __user *ctx, }else { new_dbcr0 &= ~DBCR0_IC ;if (!DBCR_ACTIVE_EVENTS (new_dbcr0, - current->thread.dbcr1)) { + current->thread.debug.dbcr1)) { new_msr &= ~MSR_DE ; new_dbcr0 &= ~DBCR0_IDM ; }@@ -1359,7 +1359,7 @@ int sys_debug_setcontext(struct ucontext __user *ctx,the user is really doing something wrong. */ regs->msr = new_msr;#ifdef CONFIG_PPC_ADV_DEBUG_REGS - current->thread.dbcr0 = new_dbcr0; + current->thread.debug.dbcr0 = new_dbcr0;#endif if (!access_ok(VERIFY_READ, ctx, sizeof(*ctx))arch/powerpc/kernel/traps.c +18
-17@@ -351,8 +351,8 @@ static inline int check_io_access(struct pt_regs *regs)#define REASON_TRAP ESR_PTR/* single-step stuff */ -#define single_stepping (regs) (current->thread.dbcr0 & DBCR0_IC) -#define clear_single_step (regs) (current->thread.dbcr0 &= ~DBCR0_IC) +#define single_stepping (regs) (current->thread.debug.dbcr0 & DBCR0_IC) +#define clear_single_step (regs) (current->thread.debug.dbcr0 &= ~DBCR0_IC)#else /* On non-4xx, the reason for the machine check or program @@ -1486,7 +1486,7 @@ static void handle_debug(struct pt_regs *regs, unsigned long debug_status)if (debug_status & (DBSR_DAC1R |DBSR_DAC1W )) {dbcr_dac (current) &= ~(DBCR_DAC1R |DBCR_DAC1W );#ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE - current->thread.dbcr2 &= ~DBCR2_DAC12MODE ; + current->thread.debug.dbcr2 &= ~DBCR2_DAC12MODE ;#endif do_send_trap (regs,mfspr (SPRN_DAC1 ), debug_status,TRAP_HWBKPT ,5 );@@ -1497,24 +1497,24 @@ static void handle_debug(struct pt_regs *regs, unsigned long debug_status) 6); changed |=0x01 ; }else if (debug_status &DBSR_IAC1 ) { - current->thread.dbcr0 &= ~DBCR0_IAC1 ; + current->thread.debug.dbcr0 &= ~DBCR0_IAC1 ;dbcr_iac_range (current) &= ~DBCR_IAC12MODE ;do_send_trap (regs,mfspr (SPRN_IAC1 ), debug_status,TRAP_HWBKPT ,1 ); changed |=0x01 ; }else if (debug_status &DBSR_IAC2 ) { - current->thread.dbcr0 &= ~DBCR0_IAC2 ; + current->thread.debug.dbcr0 &= ~DBCR0_IAC2 ;do_send_trap (regs,mfspr (SPRN_IAC2 ), debug_status,TRAP_HWBKPT ,2 ); changed |=0x01 ; }else if (debug_status &DBSR_IAC3 ) { - current->thread.dbcr0 &= ~DBCR0_IAC3 ; + current->thread.debug.dbcr0 &= ~DBCR0_IAC3 ;dbcr_iac_range (current) &= ~DBCR_IAC34MODE ;do_send_trap (regs,mfspr (SPRN_IAC3 ), debug_status,TRAP_HWBKPT ,3 ); changed |=0x01 ; }else if (debug_status &DBSR_IAC4 ) { - current->thread.dbcr0 &= ~DBCR0_IAC4 ; + current->thread.debug.dbcr0 &= ~DBCR0_IAC4 ;do_send_trap (regs,mfspr (SPRN_IAC4 ), debug_status,TRAP_HWBKPT ,4 ); changed |=0x01 ;@@ -1524,19 +1524,20 @@ static void handle_debug(struct pt_regs *regs, unsigned long debug_status)* Check all other debug flags and see if that bit needs to be turned * back on or not. */ -if (DBCR_ACTIVE_EVENTS (current->thread.dbcr0, current->thread.dbcr1)) +if (DBCR_ACTIVE_EVENTS (current->thread.debug.dbcr0, + current->thread.debug.dbcr1)) regs->msr |=MSR_DE ;else /* Make sure the IDM flag is off */ - current->thread.dbcr0 &= ~DBCR0_IDM ; + current->thread.debug.dbcr0 &= ~DBCR0_IDM ;if (changed &0x01 ) -mtspr (SPRN_DBCR0 , current->thread.dbcr0); +mtspr (SPRN_DBCR0 , current->thread.debug.dbcr0); }void __kprobes DebugException (struct pt_regs *regs,unsigned long debug_status) { - current->thread.dbsr = debug_status; + current->thread.debug.dbsr = debug_status;/* Hack alert: On BookE, Branch Taken stops on the branch itself, while * on server, it stops on the target of the branch. In order to simulate @@ -1553,8 +1554,8 @@ void __kprobes DebugException(struct pt_regs *regs, unsigned long debug_status)/* Do the single step trick only when coming from userspace */ if (user_mode (regs)) { - current->thread.dbcr0 &= ~DBCR0_BT ; - current->thread.dbcr0 |=DBCR0_IDM |DBCR0_IC ; + current->thread.debug.dbcr0 &= ~DBCR0_BT ; + current->thread.debug.dbcr0 |=DBCR0_IDM |DBCR0_IC ; regs->msr |=MSR_DE ;return ; }@@ -1582,13 +1583,13 @@ void __kprobes DebugException(struct pt_regs *regs, unsigned long debug_status)return ;if (user_mode (regs)) { - current->thread.dbcr0 &= ~DBCR0_IC ; -if (DBCR_ACTIVE_EVENTS (current->thread.dbcr0, - current->thread.dbcr1)) + current->thread.debug.dbcr0 &= ~DBCR0_IC ; +if (DBCR_ACTIVE_EVENTS (current->thread.debug.dbcr0, + current->thread.debug.dbcr1)) regs->msr |=MSR_DE ;else /* Make sure the IDM bit is off */ - current->thread.dbcr0 &= ~DBCR0_IDM ; + current->thread.debug.dbcr0 &= ~DBCR0_IDM ; }_exception (SIGTRAP , regs,TRAP_TRACE , regs->nip);Signature · 1 line
1.8.1.4--
Gleb.
Re: [PULL 34/51] powerpc: move debug registers in a structure
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 8 lines · Gleb Natapov
Quoted 7 lines · Alexander Graf
From: Bharat Bhushan <[email protected]>
This way we can use same data type struct with KVM and also help in using other debug related function.
Signed-off-by Bharat Bhushan <[email protected]>Signed-off-by Alexander Graf <[email protected]>
Quoted 7 lines
Quoted 2 lines
It would be nice to have PPC maintainers (CCed) ACKs here. This patch also has merging conflicts with
cbc9565e(should be easy to resolve)Is it easier if I put it in powerpc -next and resolve the conflicts ?
I was ok with the patch but yes, I should probably have put it in a topic branch in the first place and merge it both in my tree and Alex.
It's already in your -next via my tree (sha1 51ae8d4a2b9e4aa9a502061b9c39168e08829b94). I didn't realize Alex was planning on applying it.
-Scott
Re: [PULL 34/51] powerpc: move debug registers in a structure
Quoted 13 lines · Scott Wood
Quoted 12 lines · Benjamin Herrenschmidt
Quoted 10 lines · Gleb Natapov
Quoted 7 lines · Alexander Graf
From: Bharat Bhushan <[email protected]>
This way we can use same data type struct with KVM and also help in using other debug related function.
Signed-off-by Bharat Bhushan <[email protected]>Signed-off-by Alexander Graf <[email protected]>It would be nice to have PPC maintainers (CCed) ACKs here. This patch also has merging conflicts with
cbc9565e(should be easy to resolve)
Quoted 8 lines
Quoted 4 lines
Is it easier if I put it in powerpc -next and resolve the conflicts ?
I was ok with the patch but yes, I should probably have put it in a topic branch in the first place and merge it both in my tree and Alex.
It's already in your -next via my tree (sha1
51ae8d4a2b9e4aa9a502061b9c39168e08829b94). I didn't realize Alex was planning on applying it.
Yeah, it's what Ben and me agreed on after I waited forever to get a topic branch created. Oh well, I guess this time we just have to manually resolve the conflicts and do a better job at communicating next time.
Alex
Re: [PULL 34/51] powerpc: move debug registers in a structure
Quoted 4 lines · Alexander Graf
Yeah, it's what Ben and me agreed on after I waited forever to get a topic branch created. Oh well, I guess this time we just have to manually resolve the conflicts and do a better job at communicating next time.
That specific one was my fault. Too much stuff on my plate and I completely forgot about the topic branch, anyway, it's ok now.
Cheers,
Ben.
[PULL 35/51] powerpc: export debug registers save function for KVM
In reply to Alexander GrafFrom: Bharat Bhushan <[email protected]>
KVM need this function when switching from vcpu to user-space thread. My subsequent patch will use this function.
--- arch/powerpc/include/asm/switch_to.h | 1 + arch/powerpc/kernel/process.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/switch_to.h +1 -0
@@ -35,6 +35,7 @@ extern void giveup_vsx(struct task_struct *);extern void enable_kernel_spe (void );extern void giveup_spe (struct task_struct *);extern void load_up_spe (struct task_struct *); +extern void switch_booke_debug_regs (struct thread_struct *new_thread);#ifndef CONFIG_SMP extern void discard_lazy_cpu_state (void );
arch/powerpc/kernel/process.c +2 -1
@@ -371,12 +371,13 @@ static void prime_debug_regs(struct thread_struct *thread)* debug registers, set the debug registers from the values * stored in the new thread. */ -static void switch_booke_debug_regs (struct thread_struct *new_thread) +void switch_booke_debug_regs (struct thread_struct *new_thread) {if ((current->thread.debug.dbcr0 &DBCR0_IDM ) || (new_thread->debug.dbcr0 &DBCR0_IDM ))prime_debug_regs (new_thread); } +EXPORT_SYMBOL_GPL (switch_booke_debug_regs);#else /* !CONFIG_PPC_ADV_DEBUG_REGS */ #ifndef CONFIG_HAVE_HW_BREAKPOINT static void set_debug_reg_defaults (struct thread_struct *thread)
Signature · 1 line
1.8.1.4
[PULL 36/51] KVM: PPC: E500: exit to user space on "ehpriv 1" instruction
In reply to Alexander GrafFrom: Bharat Bhushan <[email protected]>
"ehpriv 1" instruction is used for setting software breakpoints by user space. This patch adds support to exit to user space with "run->debug" have relevant information.
As this is the first point we are using run->debug, also defined the run->debug structure.
--- arch/powerpc/include/asm/disassemble.h | 4 ++++ arch/powerpc/include/asm/kvm_booke.h | 7 ++++++- arch/powerpc/include/uapi/asm/kvm.h | 21 +++++++++++++++++---- arch/powerpc/kvm/booke.c | 2 +- arch/powerpc/kvm/e500_emulate.c | 26 ++++++++++++++++++++++++++ 5 files changed, 54 insertions(+), 6 deletions(-)
arch/powerpc/include/asm/disassemble.h +4 -0
@@ -77,4 +77,8 @@ static inline unsigned int get_d(u32 inst) return inst & 0xffff; } +static inline unsigned int get_oc (u32 inst) +{ +return (inst >>11 ) &0x7fff ; +}#endif /* __ASM_PPC_DISASSEMBLE_H__ */
arch/powerpc/include/asm/kvm_booke.h +6 -1
@@ -26,7 +26,12 @@/* LPIDs we support with this build -- runtime limit may be lower */ #define KVMPPC_NR_LPIDS 64 -#define KVMPPC_INST_EHPRIV 0x7c00021c +#define KVMPPC_INST_EHPRIV 0x7c00021c +#define EHPRIV_OC_SHIFT 11 +/* "ehpriv 1" : ehpriv with OC = 1 is used for debug emulation */ +#define EHPRIV_OC_DEBUG 1 +#define KVMPPC_INST_EHPRIV_DEBUG (KVMPPC_INST_EHPRIV | \ + (EHPRIV_OC_DEBUG << EHPRIV_OC_SHIFT))static inline void kvmppc_set_gpr (struct kvm_vcpu *vcpu,int num,ulong val) {
arch/powerpc/include/uapi/asm/kvm.h +17 -4
@@ -269,7 +269,24 @@ struct kvm_fpu {__u64 fpr[32 ]; }; +/* +* Defines for h/w breakpoint, watchpoint (read, write or both) and +* software breakpoint. +* These are used as "type" in KVM_SET_GUEST_DEBUG ioctl and "status" +* for KVM_DEBUG_EXIT. +*/ +#define KVMPPC_DEBUG_NONE 0x0 +#define KVMPPC_DEBUG_BREAKPOINT (1UL << 1) +#define KVMPPC_DEBUG_WATCH_WRITE (1UL << 2) +#define KVMPPC_DEBUG_WATCH_READ (1UL << 3)struct kvm_debug_exit_arch { +__u64 address; +/* +* exiting to userspace because of h/w breakpoint, watchpoint +* (read, write or both) and software breakpoint. +*/ +__u32 status; +__u32 reserved; };/* for KVM_SET_GUEST_DEBUG */
@@ -281,10 +298,6 @@ struct kvm_guest_debug_arch {* Type denotes h/w breakpoint, read watchpoint, write * watchpoint or watchpoint (both read and write). */ -#define KVMPPC_DEBUG_NONE 0x0 -#define KVMPPC_DEBUG_BREAKPOINT (1UL << 1) -#define KVMPPC_DEBUG_WATCH_WRITE (1UL << 2) -#define KVMPPC_DEBUG_WATCH_READ (1UL << 3)__u32 type;__u32 reserved; } bp[16 ];
arch/powerpc/kvm/booke.c +1 -1
@@ -1477,7 +1477,7 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) val =get_reg_val (reg->id, vcpu->arch.tsr);break ;case KVM_REG_PPC_DEBUG_INST : - val =get_reg_val (reg->id,KVMPPC_INST_EHPRIV ); + val =get_reg_val (reg->id,KVMPPC_INST_EHPRIV_DEBUG );break ;case KVM_REG_PPC_VRSAVE : val =get_reg_val (reg->id, vcpu->arch.vrsave);
arch/powerpc/kvm/e500_emulate.c +26 -0
@@ -26,6 +26,7 @@#define XOP_TLBRE 946#define XOP_TLBWE 978#define XOP_TLBILX 18 +#define XOP_EHPRIV 270#ifdef CONFIG_KVM_E500MC static int dbell2prio (ulong param)
@@ -82,6 +83,26 @@ static int kvmppc_e500_emul_msgsnd(struct kvm_vcpu *vcpu, int rb) }#endif +static int kvmppc_e500_emul_ehpriv (struct kvm_run *run,struct kvm_vcpu *vcpu, +unsigned int inst,int *advance) +{ +int emulated =EMULATE_DONE ; + +switch (get_oc (inst)) { +case EHPRIV_OC_DEBUG : + run->exit_reason =KVM_EXIT_DEBUG ; + run->debug.arch.address = vcpu->arch.pc; + run->debug.arch.status =0 ; +kvmppc_account_exit (vcpu,DEBUG_EXITS ); + emulated =EMULATE_EXIT_USER ; + *advance =0 ; +break ; +default : + emulated =EMULATE_FAIL ; + } +return emulated; +} +int kvmppc_core_emulate_op (struct kvm_run *run,struct kvm_vcpu *vcpu,unsigned int inst,int *advance) {
@@ -130,6 +151,11 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, emulated =kvmppc_e500_emul_tlbivax (vcpu, ea);break ; +case XOP_EHPRIV : + emulated =kvmppc_e500_emul_ehpriv (run, vcpu, inst, + advance); +break ; +default : emulated =EMULATE_FAIL ; }
Signature · 1 line
1.8.1.4
[PULL 37/51] KVM: PPC: E500: Using "struct debug_reg"
In reply to Alexander GrafFrom: Bharat Bhushan <[email protected]>
For KVM also use the "struct debug_reg" defined in asm/processor.h
--- arch/powerpc/include/asm/kvm_host.h | 13 +------------ arch/powerpc/kvm/booke.c | 34 ++++++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 22 deletions(-)
arch/powerpc/include/asm/kvm_host.h +1 -12
@@ -387,17 +387,6 @@ struct kvmppc_slb {#define KVMPPC_EPR_USER 1/* exit to userspace to fill EPR */ #define KVMPPC_EPR_KERNEL 2/* in-kernel irqchip */ -struct kvmppc_booke_debug_reg { -u32 dbcr0; -u32 dbcr1; -u32 dbcr2; -#ifdef CONFIG_KVM_E500MC -u32 dbcr4; -#endif -u64 iac[KVMPPC_BOOKE_MAX_IAC ]; -u64 dac[KVMPPC_BOOKE_MAX_DAC ]; -}; -#define KVMPPC_IRQ_DEFAULT 0#define KVMPPC_IRQ_MPIC 1#define KVMPPC_IRQ_XICS 2
@@ -549,7 +538,7 @@ struct kvm_vcpu_arch {u32 eptcfg;u32 epr;u32 crit_save; -struct kvmppc_booke_debug_reg dbg_reg; +struct debug_reg dbg_reg;#endif gpa_t paddr_accessed;gva_t vaddr_accessed;
arch/powerpc/kvm/booke.c +24 -10
@@ -1441,7 +1441,6 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)int r =0 ;union kvmppc_one_reg val;int size; -long int i; size =one_reg_size (reg->id);if (size >sizeof (val))
@@ -1449,16 +1448,24 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)switch (reg->id) {case KVM_REG_PPC_IAC1 : + val =get_reg_val (reg->id, vcpu->arch.dbg_reg.iac1); +break ;case KVM_REG_PPC_IAC2 : + val =get_reg_val (reg->id, vcpu->arch.dbg_reg.iac2); +break ; +#if CONFIG_PPC_ADV_DEBUG_IACS >2 case KVM_REG_PPC_IAC3 : + val =get_reg_val (reg->id, vcpu->arch.dbg_reg.iac3); +break ;case KVM_REG_PPC_IAC4 : - i = reg->id -KVM_REG_PPC_IAC1 ; - val =get_reg_val (reg->id, vcpu->arch.dbg_reg.iac[i]); + val =get_reg_val (reg->id, vcpu->arch.dbg_reg.iac4);break ; +#endif case KVM_REG_PPC_DAC1 : + val =get_reg_val (reg->id, vcpu->arch.dbg_reg.dac1); +break ;case KVM_REG_PPC_DAC2 : - i = reg->id -KVM_REG_PPC_DAC1 ; - val =get_reg_val (reg->id, vcpu->arch.dbg_reg.dac[i]); + val =get_reg_val (reg->id, vcpu->arch.dbg_reg.dac2);break ;case KVM_REG_PPC_EPR : {u32 epr =get_guest_epr (vcpu);
@@ -1501,7 +1508,6 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)int r =0 ;union kvmppc_one_reg val;int size; -long int i; size =one_reg_size (reg->id);if (size >sizeof (val))
@@ -1512,16 +1518,24 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)switch (reg->id) {case KVM_REG_PPC_IAC1 : + vcpu->arch.dbg_reg.iac1 =set_reg_val (reg->id, val); +break ;case KVM_REG_PPC_IAC2 : + vcpu->arch.dbg_reg.iac2 =set_reg_val (reg->id, val); +break ; +#if CONFIG_PPC_ADV_DEBUG_IACS >2 case KVM_REG_PPC_IAC3 : + vcpu->arch.dbg_reg.iac3 =set_reg_val (reg->id, val); +break ;case KVM_REG_PPC_IAC4 : - i = reg->id -KVM_REG_PPC_IAC1 ; - vcpu->arch.dbg_reg.iac[i] =set_reg_val (reg->id, val); + vcpu->arch.dbg_reg.iac4 =set_reg_val (reg->id, val);break ; +#endif case KVM_REG_PPC_DAC1 : + vcpu->arch.dbg_reg.dac1 =set_reg_val (reg->id, val); +break ;case KVM_REG_PPC_DAC2 : - i = reg->id -KVM_REG_PPC_DAC1 ; - vcpu->arch.dbg_reg.dac[i] =set_reg_val (reg->id, val); + vcpu->arch.dbg_reg.dac2 =set_reg_val (reg->id, val);break ;case KVM_REG_PPC_EPR : {u32 new_epr =set_reg_val (reg->id, val);
Signature · 1 line
1.8.1.4
[PULL 38/51] KVM: PPC: E500: Add userspace debug stub support
In reply to Alexander GrafFrom: Bharat Bhushan <[email protected]>
This patch adds the debug stub support on booke/bookehv. Now QEMU debug stub can use hw breakpoint, watchpoint and software breakpoint to debug guest.
This is how we save/restore debug register context when switching between guest, userspace and kernel user-process:
When QEMU is running
-> thread->debug_reg = QEMU debug register context.
-> Kernel will handle switching the debug register on context switch. -> no vcpu_load() called
QEMU makes ioctls (except RUN)
-> This will call vcpu_load()
-> should not change context.
-> Some ioctls can change vcpu debug register, context saved in vcpu->debug_regs
QEMU Makes RUN ioctl
-> Save thread->debug_reg on STACK
-> Store thread->debug_reg = vcpu->debug_reg
-> load thread->debug_reg
-> RUN VCPU ( So thread points to vcpu context )
Context switch happens When VCPU running
-> makes vcpu_load() should not load any context
-> kernel loads the vcpu context as thread->debug_regs points to vcpu context.
On heavyweight_exit
-> Load the context saved on stack in thread->debug_reg
Currently we do not support debug resource emulation to guest, On debug exception, always exit to user space irrespective of user space is expecting the debug exception or not. If this is unexpected exception (breakpoint/watchpoint event not set by userspace) then let us leave the action on user space. This is similar to what it was before, only thing is that now we have proper exit state available to user space.
--- arch/powerpc/include/asm/kvm_host.h | 3 + arch/powerpc/include/uapi/asm/kvm.h | 1 + arch/powerpc/kvm/booke.c | 240 +++++++++++++++++++++++++++++++++--- arch/powerpc/kvm/booke.h | 5 + 4 files changed, 231 insertions(+), 18 deletions(-)
arch/powerpc/include/asm/kvm_host.h +3 -0
@@ -538,7 +538,10 @@ struct kvm_vcpu_arch {u32 eptcfg;u32 epr;u32 crit_save; +/* guest debug registers*/ struct debug_reg dbg_reg; +/* hardware visible debug registers when in guest state */ +struct debug_reg shadow_dbg_reg;#endif gpa_t paddr_accessed;gva_t vaddr_accessed;
arch/powerpc/include/uapi/asm/kvm.h +1 -0
@@ -27,6 +27,7 @@#define __KVM_HAVE_PPC_SMT#define __KVM_HAVE_IRQCHIP#define __KVM_HAVE_IRQ_LINE +#define __KVM_HAVE_GUEST_DEBUGstruct kvm_regs {__u64 pc;
arch/powerpc/kvm/booke.c +222 -18
313 lines not on this page · raw message
arch/powerpc/kvm/booke.h +5 -0
@@ -129,4 +129,9 @@ static inline void kvmppc_save_guest_fp(struct kvm_vcpu *vcpu)giveup_fpu (current); #endif } + +static inline void kvmppc_clear_dbsr (void ) +{ +mtspr (SPRN_DBSR ,mfspr (SPRN_DBSR )); +}#endif /* __KVM_BOOKE_H__ */
Signature · 1 line
1.8.1.4
[PULL 39/51] kvm: powerpc: book3s: remove kvmppc_handler_highmem label
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
This label is not used now.
--- arch/powerpc/kvm/book3s_hv_interrupts.S | 3 --- arch/powerpc/kvm/book3s_interrupts.S | 3 --- 2 files changed, 6 deletions(-)
arch/powerpc/kvm/book3s_hv_interrupts.S +0 -3
@@ -158,9 +158,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201) * Interrupts are enabled again at this point. */ -.global kvmppc_handler_highmem -kvmppc_handler_highmem: - /* * Register usage at this point: *
arch/powerpc/kvm/book3s_interrupts.S +0 -3
@@ -121,9 +121,6 @@ kvm_start_lightweight: * */ -.global kvmppc_handler_highmem -kvmppc_handler_highmem: - /* * Register usage at this point: *
Signature · 1 line
1.8.1.4
[PULL 40/51] kvm: powerpc: book3s: move book3s_64_vio_hv.c into the main kernel binary
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
Since the code in book3s_64_vio_hv.c is called from real mode with HV KVM, and therefore has to be built into the main kernel binary, this makes it always built-in rather than part of the KVM module. It gets called from the KVM module by PR KVM, so this adds an EXPORT_SYMBOL_GPL().
--- arch/powerpc/kvm/Makefile | 12 ++++++++---- arch/powerpc/kvm/book3s_64_vio_hv.c | 1 + 2 files changed, 9 insertions(+), 4 deletions(-)
arch/powerpc/kvm/Makefile +8 -4
@@ -53,32 +53,36 @@ kvm-e500mc-objs := \ e500_emulate.o kvm-objs-$(CONFIG_KVM_E500MC) := $(kvm-e500mc-objs) +kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HANDLER) := \ + book3s_64_vio_hv.o + kvm-book3s_64-objs-$(CONFIG_KVM_BOOK3S_64_PR) := \ $(KVM)/coalesced_mmio.o \ fpu.o \ book3s_paired_singles.o \ book3s_pr.o \ book3s_pr_papr.o \ - book3s_64_vio_hv.o \ book3s_emulate.o \ book3s_interrupts.o \ book3s_mmu_hpte.o \ book3s_64_mmu_host.o \ book3s_64_mmu.o \ book3s_32_mmu.o -kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_PR) := \ + +kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_PR) += \ book3s_rmhandlers.o kvm-book3s_64-objs-$(CONFIG_KVM_BOOK3S_64_HV) := \ book3s_hv.o \ book3s_hv_interrupts.o \ book3s_64_mmu_hv.o + kvm-book3s_64-builtin-xics-objs-$(CONFIG_KVM_XICS) := \ book3s_hv_rm_xics.o -kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HV) := \ + +kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HV) += \ book3s_hv_rmhandlers.o \ book3s_hv_rm_mmu.o \ - book3s_64_vio_hv.o \ book3s_hv_ras.o \ book3s_hv_builtin.o \ book3s_hv_cma.o \
arch/powerpc/kvm/book3s_64_vio_hv.c +1 -0
@@ -74,3 +74,4 @@ long kvmppc_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn,/* Didn't find the liobn, punt it to userspace */ return H_TOO_HARD ; } +EXPORT_SYMBOL_GPL (kvmppc_h_put_tce);
Signature · 1 line
1.8.1.4
[PULL 41/51] kvm: powerpc: book3s: pr: Rename KVM_BOOK3S_PR to KVM_BOOK3S_PR_POSSIBLE
In reply to Alexander GrafFrom: "Aneesh Kumar K.V" <[email protected]>
With later patches supporting PR kvm as a kernel module, the changes that has to be built into the main kernel binary to enable PR KVM module is now selected via KVM_BOOK3S_PR_POSSIBLE
--- arch/powerpc/include/asm/exception-64s.h | 2 +- arch/powerpc/include/asm/kvm_book3s.h | 4 ++-- arch/powerpc/include/asm/kvm_book3s_64.h | 2 +- arch/powerpc/include/asm/kvm_host.h | 2 +- arch/powerpc/include/asm/paca.h | 2 +- arch/powerpc/kernel/asm-offsets.c | 2 +- arch/powerpc/kernel/exceptions-64s.S | 2 +- arch/powerpc/kvm/Kconfig | 6 +++--- arch/powerpc/kvm/trace.h | 10 +++++----- 9 files changed, 16 insertions(+), 16 deletions(-)
arch/powerpc/include/asm/exception-64s.h +1 -1
@@ -244,7 +244,7 @@ do_kvm_##n: \#define KVM_HANDLER_SKIP (area, h, n)#endif -#ifdef CONFIG_KVM_BOOK3S_PR +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE #define KVMTEST_PR (n) __KVMTEST(n)#define KVM_HANDLER_PR (area, h, n) __KVM_HANDLER(area, h, n)#define KVM_HANDLER_PR_SKIP (area, h, n) __KVM_HANDLER_SKIP(area, h, n)
arch/powerpc/include/asm/kvm_book3s.h +2 -2
@@ -304,7 +304,7 @@ static inline ulong kvmppc_get_fault_dar(struct kvm_vcpu *vcpu)return vcpu->arch.fault_dar; } -#ifdef CONFIG_KVM_BOOK3S_PR +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE static inline unsigned long kvmppc_interrupt_offset (struct kvm_vcpu *vcpu) {
@@ -339,7 +339,7 @@ static inline bool kvmppc_critical_section(struct kvm_vcpu *vcpu) return crit; } -#else /* CONFIG_KVM_BOOK3S_PR */ +#else /* CONFIG_KVM_BOOK3S_PR_POSSIBLE */ static inline unsigned long kvmppc_interrupt_offset (struct kvm_vcpu *vcpu) {
arch/powerpc/include/asm/kvm_book3s_64.h +1 -1
@@ -20,7 +20,7 @@ #ifndef __ASM_KVM_BOOK3S_64_H__ #define __ASM_KVM_BOOK3S_64_H__ -#ifdef CONFIG_KVM_BOOK3S_PR +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE static inline struct kvmppc_book3s_shadow_vcpu *svcpu_get(struct kvm_vcpu *vcpu) { preempt_disable();
arch/powerpc/include/asm/kvm_host.h +1 -1
@@ -257,7 +257,7 @@ struct kvm_arch {struct kvmppc_vcore *vcores[KVM_MAX_VCORES ];int hpt_cma_alloc;#endif /* CONFIG_KVM_BOOK3S_64_HV */ -#ifdef CONFIG_KVM_BOOK3S_PR +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE struct mutex hpt_mutex;#endif #ifdef CONFIG_PPC_BOOK3S_64
arch/powerpc/include/asm/paca.h +1 -1
@@ -166,7 +166,7 @@ struct paca_struct {struct dtl_entry *dtl_curr;/* pointer corresponding to dtl_ridx */ #ifdef CONFIG_KVM_BOOK3S_HANDLER -#ifdef CONFIG_KVM_BOOK3S_PR +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE /* We use this to store guest state in */ struct kvmppc_book3s_shadow_vcpu shadow_vcpu;#endif
arch/powerpc/kernel/asm-offsets.c +1 -1
@@ -533,7 +533,7 @@ int main(void)DEFINE (VCPU_SLB_SIZE ,sizeof (struct kvmppc_slb ));#ifdef CONFIG_PPC_BOOK3S_64 -#ifdef CONFIG_KVM_BOOK3S_PR +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE DEFINE (PACA_SVCPU , offsetof(struct paca_struct , shadow_vcpu));# define SVCPU_FIELD (x, f) DEFINE(x, offsetof(struct paca_struct, shadow_vcpu.f))#else
arch/powerpc/kernel/exceptions-64s.S +1 -1
@@ -425,7 +425,7 @@ data_access_check_stab: mfspr r9,SPRN_DSISR srdi r10,r10,60 rlwimi r10,r9,16,0x20 -#ifdef CONFIG_KVM_BOOK3S_PR +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE lbz r9,HSTATE_IN_GUEST(r13) rlwimi r10,r9,8,0x300 #endif
arch/powerpc/kvm/Kconfig +3 -3
@@ -34,7 +34,7 @@ config KVM_BOOK3S_64_HANDLER bool select KVM_BOOK3S_HANDLER -config KVM_BOOK3S_PR +config KVM_BOOK3S_PR_POSSIBLE bool select KVM_MMIO select MMU_NOTIFIER
@@ -44,7 +44,7 @@ config KVM_BOOK3S_32 depends on PPC_BOOK3S_32 && !SMP && !PTE_64BIT select KVM select KVM_BOOK3S_32_HANDLER - select KVM_BOOK3S_PR + select KVM_BOOK3S_PR_POSSIBLE ---help--- Support running unmodified book3s_32 guest kernels in virtual machines on book3s_32 host processors.
@@ -91,7 +91,7 @@ config KVM_BOOK3S_64_HV config KVM_BOOK3S_64_PR def_bool y depends on KVM_BOOK3S_64 && !KVM_BOOK3S_64_HV - select KVM_BOOK3S_PR + select KVM_BOOK3S_PR_POSSIBLE config KVM_BOOKE_HV bool
arch/powerpc/kvm/trace.h +5 -5
@@ -94,7 +94,7 @@ TRACE_EVENT(kvm_exit, __field( unsigned long, pc ) __field( unsigned long, msr ) __field( unsigned long, dar ) -#ifdef CONFIG_KVM_BOOK3S_PR +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE __field( unsigned long, srr1 ) #endif__field (unsigned long , last_inst )
@@ -105,7 +105,7 @@ TRACE_EVENT(kvm_exit, __entry->pc =kvmppc_get_pc (vcpu); __entry->dar =kvmppc_get_fault_dar (vcpu); __entry->msr = vcpu->arch.shared->msr; -#ifdef CONFIG_KVM_BOOK3S_PR +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE __entry->srr1 = vcpu->arch.shadow_srr1;#endif __entry->last_inst = vcpu->arch.last_inst;
@@ -115,7 +115,7 @@ TRACE_EVENT(kvm_exit, " | pc=0x%lx" " | msr=0x%lx" " | dar=0x%lx" -#ifdef CONFIG_KVM_BOOK3S_PR +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE " | srr1=0x%lx" #endif" | last_inst=0x%lx"
@@ -124,7 +124,7 @@ TRACE_EVENT(kvm_exit, __entry->pc, __entry->msr, __entry->dar, -#ifdef CONFIG_KVM_BOOK3S_PR +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE __entry->srr1, #endif __entry->last_inst
@@ -236,7 +236,7 @@ TRACE_EVENT(kvm_check_requests,* Book3S trace points * *************************************************************************/ -#ifdef CONFIG_KVM_BOOK3S_PR +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE TRACE_EVENT(kvm_book3s_reenter, TP_PROTO(int r, struct kvm_vcpu *vcpu),
Signature · 1 line
1.8.1.4
[PULL 42/51] kvm: powerpc: book3s: Add a new config variable CONFIG_KVM_BOOK3S_HV_POSSIBLE
In reply to Alexander GrafFrom: "Aneesh Kumar K.V" <[email protected]>
This help ups to select the relevant code in the kernel code when we later move HV and PR bits as seperate modules. The patch also makes the config options for PR KVM selectable
--- arch/powerpc/include/asm/kvm_book3s.h | 2 -- arch/powerpc/include/asm/kvm_book3s_64.h | 6 +++--- arch/powerpc/include/asm/kvm_book3s_asm.h | 2 +- arch/powerpc/include/asm/kvm_host.h | 10 +++++----- arch/powerpc/include/asm/kvm_ppc.h | 2 +- arch/powerpc/kernel/asm-offsets.c | 8 ++++---- arch/powerpc/kernel/idle_power7.S | 2 +- arch/powerpc/kvm/Kconfig | 18 +++++++++++++++++- arch/powerpc/kvm/Makefile | 12 ++++++++---- arch/powerpc/kvm/book3s_exports.c | 5 +++-- 10 files changed, 43 insertions(+), 24 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +0 -2
@@ -199,8 +199,6 @@ static inline struct kvmppc_vcpu_book3s *to_book3s(struct kvm_vcpu *vcpu)return vcpu->arch.book3s; } -extern void kvm_return_point (void ); -/* Also add subarch specific defines */ #ifdef CONFIG_KVM_BOOK3S_32_HANDLER
arch/powerpc/include/asm/kvm_book3s_64.h +3 -3
@@ -35,7 +35,7 @@ static inline void svcpu_put(struct kvmppc_book3s_shadow_vcpu *svcpu)#define SPAPR_TCE_SHIFT 12 -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE #define KVM_DEFAULT_HPT_ORDER 24/* 16MB HPT by default */ extern unsigned long kvm_rma_pages;#endif
@@ -278,7 +278,7 @@ static inline int is_vrma_hpte(unsigned long hpte_v) (HPTE_V_1TB_SEG | (VRMA_VSID << (40 -16 ))); } -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE /* * Note modification of an HPTE; set the HPTE modified bit * if anyone is interested.
@@ -289,6 +289,6 @@ static inline void note_hpte_modification(struct kvm *kvm,if (atomic_read (&kvm->arch.hpte_mod_interest)) rev->guest_rpte |=HPTE_GR_MODIFIED ; } -#endif /* CONFIG_KVM_BOOK3S_64_HV */ +#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ #endif /* __ASM_KVM_BOOK3S_64_H__ */
arch/powerpc/include/asm/kvm_book3s_asm.h +1 -1
@@ -83,7 +83,7 @@ struct kvmppc_host_state {u8 restore_hid5;u8 napping; -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE u8 hwthread_req;u8 hwthread_state;u8 host_ipi;
arch/powerpc/include/asm/kvm_host.h +5 -5
@@ -224,15 +224,15 @@ struct revmap_entry {#define KVMPPC_GOT_PAGE 0x80struct kvm_arch_memory_slot { -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE unsigned long *rmap;unsigned long *slot_phys; -#endif /* CONFIG_KVM_BOOK3S_64_HV */ +#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ };struct kvm_arch {unsigned int lpid; -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE unsigned long hpt_virt;struct revmap_entry *revmap;unsigned int host_lpid;
@@ -256,7 +256,7 @@ struct kvm_arch {cpumask_t need_tlb_flush;struct kvmppc_vcore *vcores[KVM_MAX_VCORES ];int hpt_cma_alloc; -#endif /* CONFIG_KVM_BOOK3S_64_HV */ +#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE struct mutex hpt_mutex;#endif
@@ -592,7 +592,7 @@ struct kvm_vcpu_arch {struct kvmppc_icp *icp;/* XICS presentation controller */ #endif -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE struct kvm_vcpu_arch_shared shregs;unsigned long pgfault_addr;
arch/powerpc/include/asm/kvm_ppc.h +1 -1
@@ -260,7 +260,7 @@ void kvmppc_set_pid(struct kvm_vcpu *vcpu, u32 pid);struct openpic ; -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE extern void kvm_cma_reserve (void )__init ;static inline void kvmppc_set_xics_phys (int cpu,unsigned long addr) {
arch/powerpc/kernel/asm-offsets.c +4 -4
@@ -445,7 +445,7 @@ int main(void) DEFINE(VCPU_LR, offsetof(struct kvm_vcpu, arch.lr)); DEFINE(VCPU_CR, offsetof(struct kvm_vcpu, arch.cr)); DEFINE(VCPU_PC, offsetof(struct kvm_vcpu, arch.pc)); -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE DEFINE(VCPU_MSR, offsetof(struct kvm_vcpu, arch.shregs.msr)); DEFINE(VCPU_SRR0, offsetof(struct kvm_vcpu, arch.shregs.srr0)); DEFINE(VCPU_SRR1, offsetof(struct kvm_vcpu, arch.shregs.srr1));
@@ -476,7 +476,7 @@ int main(void) DEFINE(KVM_LPID, offsetof(struct kvm, arch.lpid));/* book3s */ -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE DEFINE(KVM_SDR1, offsetof(struct kvm, arch.sdr1)); DEFINE(KVM_HOST_LPID, offsetof(struct kvm, arch.host_lpid)); DEFINE(KVM_HOST_LPCR, offsetof(struct kvm, arch.host_lpcr));
@@ -586,7 +586,7 @@ int main(void)HSTATE_FIELD (HSTATE_RESTORE_HID5 , restore_hid5);HSTATE_FIELD (HSTATE_NAPPING , napping); -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE HSTATE_FIELD (HSTATE_HWTHREAD_REQ , hwthread_req);HSTATE_FIELD (HSTATE_HWTHREAD_STATE , hwthread_state);HSTATE_FIELD (HSTATE_KVM_VCPU , kvm_vcpu);
@@ -602,7 +602,7 @@ int main(void)HSTATE_FIELD (HSTATE_DABR , dabr);HSTATE_FIELD (HSTATE_DECEXP , dec_expires);DEFINE (IPI_PRIORITY ,IPI_PRIORITY ); -#endif /* CONFIG_KVM_BOOK3S_64_HV */ +#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ #ifdef CONFIG_PPC_BOOK3S_64 HSTATE_FIELD (HSTATE_CFAR , cfar);
arch/powerpc/kernel/idle_power7.S +1 -1
@@ -84,7 +84,7 @@ _GLOBAL(power7_nap) std r9,_MSR(r1) std r1,PACAR1(r13) -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE /* Tell KVM we're napping */ li r4,KVM_HWTHREAD_IN_NAP stb r4,HSTATE_HWTHREAD_STATE(r13)
arch/powerpc/kvm/Kconfig +17 -1
@@ -39,6 +39,9 @@ config KVM_BOOK3S_PR_POSSIBLE select KVM_MMIO select MMU_NOTIFIER +config KVM_BOOK3S_HV_POSSIBLE + bool + config KVM_BOOK3S_32 tristate "KVM support for PowerPC book3s_32 processors" depends on PPC_BOOK3S_32 && !SMP && !PTE_64BIT
@@ -59,6 +62,7 @@ config KVM_BOOK3S_64 depends on PPC_BOOK3S_64 select KVM_BOOK3S_64_HANDLER select KVM + select KVM_BOOK3S_PR_POSSIBLE if !KVM_BOOK3S_HV_POSSIBLE ---help--- Support running unmodified book3s_64 and book3s_32 guest kernels in virtual machines on book3s_64 host processors.
@@ -71,6 +75,7 @@ config KVM_BOOK3S_64 config KVM_BOOK3S_64_HV bool "KVM support for POWER7 and PPC970 using hypervisor mode in host" depends on KVM_BOOK3S_64 + select KVM_BOOK3S_HV_POSSIBLE select MMU_NOTIFIER select CMA ---help---
@@ -89,9 +94,20 @@ config KVM_BOOK3S_64_HV If unsure, say N. config KVM_BOOK3S_64_PR - def_bool y + bool "KVM support without using hypervisor mode in host" depends on KVM_BOOK3S_64 && !KVM_BOOK3S_64_HV select KVM_BOOK3S_PR_POSSIBLE + ---help--- + Support running guest kernels in virtual machines on processors + without using hypervisor mode in the host, by running the + guest in user mode (problem state) and emulating all + privileged instructions and registers. + + This is not as fast as using hypervisor mode, but works on + machines where hypervisor mode is not available or not usable, + and can emulate processors that are different from the host + processor, including emulating 32-bit processors on a 64-bit + host. config KVM_BOOKE_HV bool
arch/powerpc/kvm/Makefile +8 -4
@@ -57,7 +57,6 @@ kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HANDLER) := \ book3s_64_vio_hv.o kvm-book3s_64-objs-$(CONFIG_KVM_BOOK3S_64_PR) := \ - $(KVM)/coalesced_mmio.o \ fpu.o \ book3s_paired_singles.o \ book3s_pr.o \
@@ -69,10 +68,15 @@ kvm-book3s_64-objs-$(CONFIG_KVM_BOOK3S_64_PR) := \ book3s_64_mmu.o \ book3s_32_mmu.o -kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_PR) += \ +ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE +kvm-book3s_64-module-objs := \ + $(KVM)/coalesced_mmio.o + +kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HANDLER) += \ book3s_rmhandlers.o +endif -kvm-book3s_64-objs-$(CONFIG_KVM_BOOK3S_64_HV) := \ +kvm-book3s_64-objs-$(CONFIG_KVM_BOOK3S_64_HV) += \ book3s_hv.o \ book3s_hv_interrupts.o \ book3s_64_mmu_hv.o
@@ -91,7 +95,7 @@ kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HV) += \ kvm-book3s_64-objs-$(CONFIG_KVM_XICS) += \ book3s_xics.o -kvm-book3s_64-module-objs := \ +kvm-book3s_64-module-objs += \ $(KVM)/kvm_main.o \ $(KVM)/eventfd.o \ powerpc.o \
arch/powerpc/kvm/book3s_exports.c +3 -2
@@ -20,9 +20,10 @@#include <linux/export.h> #include <asm/kvm_book3s.h> -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE EXPORT_SYMBOL_GPL (kvmppc_hv_entry_trampoline); -#else +#endif +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE EXPORT_SYMBOL_GPL (kvmppc_entry_trampoline);EXPORT_SYMBOL_GPL (kvmppc_load_up_fpu);#ifdef CONFIG_ALTIVEC
Signature · 1 line
1.8.1.4
[PULL 43/51] kvm: powerpc: Add kvmppc_ops callback
In reply to Alexander GrafFrom: "Aneesh Kumar K.V" <[email protected]>
This patch add a new callback kvmppc_ops. This will help us in enabling both HV and PR KVM together in the same kernel. The actual change to enable them together is done in the later patch in the series.
--- arch/powerpc/include/asm/kvm_book3s.h | 1 - arch/powerpc/include/asm/kvm_ppc.h | 89 ++++++++++---- arch/powerpc/kernel/exceptions-64s.S | 2 +- arch/powerpc/kvm/44x.c | 55 ++++++--- arch/powerpc/kvm/44x_emulate.c | 8 +- arch/powerpc/kvm/44x_tlb.c | 2 +- arch/powerpc/kvm/book3s.c | 145 +++++++++++++++++++++- arch/powerpc/kvm/book3s.h | 32 +++++ arch/powerpc/kvm/book3s_32_mmu_host.c | 2 +- arch/powerpc/kvm/book3s_64_mmu_host.c | 2 +- arch/powerpc/kvm/book3s_64_mmu_hv.c | 17 ++- arch/powerpc/kvm/book3s_emulate.c | 8 +- arch/powerpc/kvm/book3s_hv.c | 220 ++++++++++++++++++++++++---------- arch/powerpc/kvm/book3s_interrupts.S | 2 +- arch/powerpc/kvm/book3s_pr.c | 194 +++++++++++++++++++----------- arch/powerpc/kvm/book3s_xics.c | 4 +- arch/powerpc/kvm/booke.c | 47 +++++++- arch/powerpc/kvm/booke.h | 24 ++++ arch/powerpc/kvm/e500.c | 53 +++++--- arch/powerpc/kvm/e500_emulate.c | 8 +- arch/powerpc/kvm/e500_mmu.c | 2 +- arch/powerpc/kvm/e500mc.c | 54 ++++++--- arch/powerpc/kvm/emulate.c | 6 +- arch/powerpc/kvm/powerpc.c | 58 +++------ 24 files changed, 748 insertions(+), 287 deletions(-) create mode 100644 arch/powerpc/kvm/book3s.h
arch/powerpc/include/asm/kvm_book3s.h +0 -1
@@ -124,7 +124,6 @@ extern void kvmppc_mmu_pte_flush(struct kvm_vcpu *vcpu, ulong ea, ulong ea_mask)extern void kvmppc_mmu_pte_vflush (struct kvm_vcpu *vcpu,u64 vp,u64 vp_mask);extern void kvmppc_mmu_pte_pflush (struct kvm_vcpu *vcpu,ulong pa_start,ulong pa_end);extern void kvmppc_set_msr (struct kvm_vcpu *vcpu,u64 new_msr); -extern void kvmppc_set_pvr (struct kvm_vcpu *vcpu,u32 pvr);extern void kvmppc_mmu_book3s_64_init (struct kvm_vcpu *vcpu);extern void kvmppc_mmu_book3s_32_init (struct kvm_vcpu *vcpu);extern void kvmppc_mmu_book3s_hv_init (struct kvm_vcpu *vcpu);
arch/powerpc/include/asm/kvm_ppc.h +66 -23
127 lines not on this page · raw message
arch/powerpc/kernel/exceptions-64s.S +1 -1
@@ -126,7 +126,7 @@ BEGIN_FTR_SECTION bgt cr1,. GET_PACA(r13) -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE li r0,KVM_HWTHREAD_IN_KERNEL stb r0,HSTATE_HWTHREAD_STATE(r13) /* Order setting hwthread_state vs. testing hwthread_req */
arch/powerpc/kvm/44x.c +40 -15
113 lines not on this page · raw message
arch/powerpc/kvm/44x_emulate.c +4 -4
@@ -91,8 +91,8 @@ static int emulate_mfdcr(struct kvm_vcpu *vcpu, int rt, int dcrn)return EMULATE_DONE ; } -int kvmppc_core_emulate_op (struct kvm_run *run,struct kvm_vcpu *vcpu, -unsigned int inst,int *advance) +int kvmppc_core_emulate_op_44x (struct kvm_run *run,struct kvm_vcpu *vcpu, +unsigned int inst,int *advance) {int emulated =EMULATE_DONE ;int dcrn =get_dcrn (inst);
@@ -152,7 +152,7 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,return emulated; } -int kvmppc_core_emulate_mtspr (struct kvm_vcpu *vcpu,int sprn,ulong spr_val) +int kvmppc_core_emulate_mtspr_44x (struct kvm_vcpu *vcpu,int sprn,ulong spr_val) {int emulated =EMULATE_DONE ;
@@ -172,7 +172,7 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)return emulated; } -int kvmppc_core_emulate_mfspr (struct kvm_vcpu *vcpu,int sprn,ulong *spr_val) +int kvmppc_core_emulate_mfspr_44x (struct kvm_vcpu *vcpu,int sprn,ulong *spr_val) {int emulated =EMULATE_DONE ;
arch/powerpc/kvm/44x_tlb.c +1 -1
@@ -268,7 +268,7 @@ static void kvmppc_44x_shadow_release(struct kvmppc_vcpu_44x *vcpu_44x,trace_kvm_stlb_inval (stlb_index); } -void kvmppc_mmu_destroy (struct kvm_vcpu *vcpu) +void kvmppc_mmu_destroy_44x (struct kvm_vcpu *vcpu) {struct kvmppc_vcpu_44x *vcpu_44x =to_44x (vcpu);int i;
arch/powerpc/kvm/book3s.c +141 -4
172 lines not on this page · raw message
arch/powerpc/kvm/book3s.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* Copyright IBM Corporation, 2013 +* Author Aneesh Kumar K.V <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of the +* License or (at your optional) any later version of the license. +* +*/ + +#ifndef __POWERPC_KVM_BOOK3S_H__ +#define __POWERPC_KVM_BOOK3S_H__ + +extern void kvmppc_core_flush_memslot_hv (struct kvm *kvm, +struct kvm_memory_slot *memslot); +extern int kvm_unmap_hva_hv (struct kvm *kvm,unsigned long hva); +extern int kvm_unmap_hva_range_hv (struct kvm *kvm,unsigned long start, +unsigned long end); +extern int kvm_age_hva_hv (struct kvm *kvm,unsigned long hva); +extern int kvm_test_age_hva_hv (struct kvm *kvm,unsigned long hva); +extern void kvm_set_spte_hva_hv (struct kvm *kvm,unsigned long hva,pte_t pte); + +extern void kvmppc_mmu_destroy_pr (struct kvm_vcpu *vcpu); +extern int kvmppc_core_emulate_op_pr (struct kvm_run *run,struct kvm_vcpu *vcpu, +unsigned int inst,int *advance); +extern int kvmppc_core_emulate_mtspr_pr (struct kvm_vcpu *vcpu, +int sprn,ulong spr_val); +extern int kvmppc_core_emulate_mfspr_pr (struct kvm_vcpu *vcpu, +int sprn,ulong *spr_val); + +#endif
arch/powerpc/kvm/book3s_32_mmu_host.c +1 -1
@@ -349,7 +349,7 @@ void kvmppc_mmu_flush_segments(struct kvm_vcpu *vcpu)svcpu_put (svcpu); } -void kvmppc_mmu_destroy (struct kvm_vcpu *vcpu) +void kvmppc_mmu_destroy_pr (struct kvm_vcpu *vcpu) {int i;
arch/powerpc/kvm/book3s_64_mmu_host.c +1 -1
@@ -378,7 +378,7 @@ void kvmppc_mmu_flush_segments(struct kvm_vcpu *vcpu)svcpu_put (svcpu); } -void kvmppc_mmu_destroy (struct kvm_vcpu *vcpu) +void kvmppc_mmu_destroy_pr (struct kvm_vcpu *vcpu) {kvmppc_mmu_hpte_destroy (vcpu);__destroy_context (to_book3s (vcpu)->context_id[0 ]);
arch/powerpc/kvm/book3s_64_mmu_hv.c +7 -10
@@ -260,10 +260,6 @@ int kvmppc_mmu_hv_init(void)return 0 ; } -void kvmppc_mmu_destroy (struct kvm_vcpu *vcpu) -{ -} -static void kvmppc_mmu_book3s_64_hv_reset_msr (struct kvm_vcpu *vcpu) {kvmppc_set_msr (vcpu,MSR_SF |MSR_ME );
@@ -906,21 +902,22 @@ static int kvm_unmap_rmapp(struct kvm *kvm, unsigned long *rmapp,return 0 ; } -int kvm_unmap_hva (struct kvm *kvm,unsigned long hva) +int kvm_unmap_hva_hv (struct kvm *kvm,unsigned long hva) {if (kvm->arch.using_mmu_notifiers)kvm_handle_hva (kvm, hva, kvm_unmap_rmapp);return 0 ; } -int kvm_unmap_hva_range (struct kvm *kvm,unsigned long start,unsigned long end) +int kvm_unmap_hva_range_hv (struct kvm *kvm,unsigned long start,unsigned long end) {if (kvm->arch.using_mmu_notifiers)kvm_handle_hva_range (kvm, start, end, kvm_unmap_rmapp);return 0 ; } -void kvmppc_core_flush_memslot (struct kvm *kvm,struct kvm_memory_slot *memslot) +void kvmppc_core_flush_memslot_hv (struct kvm *kvm, +struct kvm_memory_slot *memslot) {unsigned long *rmapp;unsigned long gfn;
@@ -994,7 +991,7 @@ static int kvm_age_rmapp(struct kvm *kvm, unsigned long *rmapp,return ret; } -int kvm_age_hva (struct kvm *kvm,unsigned long hva) +int kvm_age_hva_hv (struct kvm *kvm,unsigned long hva) {if (!kvm->arch.using_mmu_notifiers)return 0 ;
@@ -1032,14 +1029,14 @@ static int kvm_test_age_rmapp(struct kvm *kvm, unsigned long *rmapp,return ret; } -int kvm_test_age_hva (struct kvm *kvm,unsigned long hva) +int kvm_test_age_hva_hv (struct kvm *kvm,unsigned long hva) {if (!kvm->arch.using_mmu_notifiers)return 0 ;return kvm_handle_hva (kvm, hva, kvm_test_age_rmapp); } -void kvm_set_spte_hva (struct kvm *kvm,unsigned long hva,pte_t pte) +void kvm_set_spte_hva_hv (struct kvm *kvm,unsigned long hva,pte_t pte) {if (!kvm->arch.using_mmu_notifiers)return ;
arch/powerpc/kvm/book3s_emulate.c +4 -4
@@ -86,8 +86,8 @@ static bool spr_allowed(struct kvm_vcpu *vcpu, enum priv_level level)return true; } -int kvmppc_core_emulate_op (struct kvm_run *run,struct kvm_vcpu *vcpu, -unsigned int inst,int *advance) +int kvmppc_core_emulate_op_pr (struct kvm_run *run,struct kvm_vcpu *vcpu, +unsigned int inst,int *advance) {int emulated =EMULATE_DONE ;int rt =get_rt (inst);
@@ -345,7 +345,7 @@ static struct kvmppc_bat *kvmppc_find_bat(struct kvm_vcpu *vcpu, int sprn)return bat; } -int kvmppc_core_emulate_mtspr (struct kvm_vcpu *vcpu,int sprn,ulong spr_val) +int kvmppc_core_emulate_mtspr_pr (struct kvm_vcpu *vcpu,int sprn,ulong spr_val) {int emulated =EMULATE_DONE ;
@@ -468,7 +468,7 @@ unprivileged:return emulated; } -int kvmppc_core_emulate_mfspr (struct kvm_vcpu *vcpu,int sprn,ulong *spr_val) +int kvmppc_core_emulate_mfspr_pr (struct kvm_vcpu *vcpu,int sprn,ulong *spr_val) {int emulated =EMULATE_DONE ;
arch/powerpc/kvm/book3s_hv.c +158 -62
423 lines not on this page · raw message
arch/powerpc/kvm/book3s_interrupts.S +1 -1
@@ -181,7 +181,7 @@ kvm_start_lightweight: /* Restore r3 (kvm_run) and r4 (vcpu) */ REST_2GPRS(3, r1) - bl FUNC(kvmppc_handle_exit) + bl FUNC(kvmppc_handle_exit_pr) /* If RESUME_GUEST, get back in the loop */ cmpwi r3, RESUME_GUEST
arch/powerpc/kvm/book3s_pr.c +125 -69
365 lines not on this page · raw message
arch/powerpc/kvm/book3s_xics.c +2 -2
@@ -1250,13 +1250,13 @@ static int kvmppc_xics_create(struct kvm_device *dev, u32 type)xics_debugfs_init (xics); -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE if (cpu_has_feature (CPU_FTR_ARCH_206 )) {/* Enable real mode support */ xics->real_mode =ENABLE_REALMODE ; xics->real_mode_dbg =DEBUG_REALMODE ; } -#endif /* CONFIG_KVM_BOOK3S_64_HV */ +#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ return 0 ; }
arch/powerpc/kvm/booke.c +41 -6
89 lines not on this page · raw message
arch/powerpc/kvm/booke.h +24 -0
@@ -99,6 +99,30 @@ enum int_class {void kvmppc_set_pending_interrupt (struct kvm_vcpu *vcpu,enum int_class type); +extern void kvmppc_mmu_destroy_44x (struct kvm_vcpu *vcpu); +extern int kvmppc_core_emulate_op_44x (struct kvm_run *run,struct kvm_vcpu *vcpu, +unsigned int inst,int *advance); +extern int kvmppc_core_emulate_mtspr_44x (struct kvm_vcpu *vcpu,int sprn, +ulong spr_val); +extern int kvmppc_core_emulate_mfspr_44x (struct kvm_vcpu *vcpu,int sprn, +ulong *spr_val); +extern void kvmppc_mmu_destroy_e500 (struct kvm_vcpu *vcpu); +extern int kvmppc_core_emulate_op_e500 (struct kvm_run *run, +struct kvm_vcpu *vcpu, +unsigned int inst,int *advance); +extern int kvmppc_core_emulate_mtspr_e500 (struct kvm_vcpu *vcpu,int sprn, +ulong spr_val); +extern int kvmppc_core_emulate_mfspr_e500 (struct kvm_vcpu *vcpu,int sprn, +ulong *spr_val); +extern void kvmppc_mmu_destroy_e500 (struct kvm_vcpu *vcpu); +extern int kvmppc_core_emulate_op_e500 (struct kvm_run *run, +struct kvm_vcpu *vcpu, +unsigned int inst,int *advance); +extern int kvmppc_core_emulate_mtspr_e500 (struct kvm_vcpu *vcpu,int sprn, +ulong spr_val); +extern int kvmppc_core_emulate_mfspr_e500 (struct kvm_vcpu *vcpu,int sprn, +ulong *spr_val); +/* * Load up guest vcpu FP state if it's needed. * It also set the MSR_FP in thread so that host know
arch/powerpc/kvm/e500.c +38 -15
129 lines not on this page · raw message
arch/powerpc/kvm/e500_emulate.c +4 -4
@@ -103,8 +103,8 @@ static int kvmppc_e500_emul_ehpriv(struct kvm_run *run, struct kvm_vcpu *vcpu,return emulated; } -int kvmppc_core_emulate_op (struct kvm_run *run,struct kvm_vcpu *vcpu, -unsigned int inst,int *advance) +int kvmppc_core_emulate_op_e500 (struct kvm_run *run,struct kvm_vcpu *vcpu, +unsigned int inst,int *advance) {int emulated =EMULATE_DONE ;int ra =get_ra (inst);
@@ -172,7 +172,7 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,return emulated; } -int kvmppc_core_emulate_mtspr (struct kvm_vcpu *vcpu,int sprn,ulong spr_val) +int kvmppc_core_emulate_mtspr_e500 (struct kvm_vcpu *vcpu,int sprn,ulong spr_val) {struct kvmppc_vcpu_e500 *vcpu_e500 =to_e500 (vcpu);int emulated =EMULATE_DONE ;
@@ -263,7 +263,7 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)return emulated; } -int kvmppc_core_emulate_mfspr (struct kvm_vcpu *vcpu,int sprn,ulong *spr_val) +int kvmppc_core_emulate_mfspr_e500 (struct kvm_vcpu *vcpu,int sprn,ulong *spr_val) {struct kvmppc_vcpu_e500 *vcpu_e500 =to_e500 (vcpu);int emulated =EMULATE_DONE ;
arch/powerpc/kvm/e500_mmu.c +1 -1
@@ -536,7 +536,7 @@ gpa_t kvmppc_mmu_xlate(struct kvm_vcpu *vcpu, unsigned int index,return get_tlb_raddr (gtlbe) | (eaddr & pgmask); } -void kvmppc_mmu_destroy (struct kvm_vcpu *vcpu) +void kvmppc_mmu_destroy_e500 (struct kvm_vcpu *vcpu) { }
arch/powerpc/kvm/e500mc.c +39 -15
128 lines not on this page · raw message
arch/powerpc/kvm/emulate.c +3 -3
@@ -130,7 +130,7 @@ static int kvmppc_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)case SPRN_PIR :break ;default : - emulated =kvmppc_core_emulate_mtspr (vcpu, sprn, + emulated = kvmppc_ops->emulate_mtspr (vcpu, sprn, spr_val);if (emulated ==EMULATE_FAIL ) printk(KERN_INFO "mtspr: unknown spr "
@@ -191,7 +191,7 @@ static int kvmppc_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt) spr_val =kvmppc_get_dec (vcpu,get_tb ());break ;default : - emulated =kvmppc_core_emulate_mfspr (vcpu, sprn, + emulated = kvmppc_ops->emulate_mfspr (vcpu, sprn, &spr_val);if (unlikely (emulated ==EMULATE_FAIL )) { printk(KERN_INFO "mfspr: unknown spr "
@@ -464,7 +464,7 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) }if (emulated ==EMULATE_FAIL ) { - emulated =kvmppc_core_emulate_op (run, vcpu, inst, &advance); + emulated = kvmppc_ops->emulate_op (run, vcpu, inst, &advance);if (emulated ==EMULATE_AGAIN ) { advance =0 ; }else if (emulated ==EMULATE_FAIL ) {
arch/powerpc/kvm/powerpc.c +14 -44
92 lines not on this page · raw message
Signature · 1 line
1.8.1.4
[PULL 44/51] kvm: powerpc: book3s: Cleanup interrupt handling code
In reply to Alexander GrafFrom: "Aneesh Kumar K.V" <[email protected]>
With this patch if HV is included, interrupts come in to the HV version of the kvmppc_interrupt code, which then jumps to the PR handler, renamed to kvmppc_interrupt_pr, if the guest is a PR guest. This helps in enabling both HV and PR, which we do in later patch
--- arch/powerpc/include/asm/exception-64s.h | 11 +++++++++++ arch/powerpc/kvm/book3s_hv_rmhandlers.S | 9 +++++++-- arch/powerpc/kvm/book3s_segment.S | 4 ++-- 3 files changed, 20 insertions(+), 4 deletions(-)
arch/powerpc/include/asm/exception-64s.h +11 -0
@@ -198,6 +198,17 @@ END_FTR_SECTION_NESTED(ftr,ftr,943) cmpwi r10,0; \ bne do_kvm_##n +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE +/* +* If hv is possible, interrupts come into to the hv version +* of the kvmppc_interrupt code, which then jumps to the PR handler, +* kvmppc_interrupt_pr, if the guest is a PR guest. +*/ +#define kvmppc_interrupt kvmppc_interrupt_hv +#else +#define kvmppc_interrupt kvmppc_interrupt_pr +#endif +#define __KVM_HANDLER (area, h, n) \ do_kvm_##n: \ BEGIN_FTR_SECTION_NESTED(947) \
arch/powerpc/kvm/book3s_hv_rmhandlers.S +7 -2
@@ -742,8 +742,8 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) /* * We come here from the first-level interrupt handlers. */ - .globl kvmppc_interrupt -kvmppc_interrupt: + .globl kvmppc_interrupt_hv +kvmppc_interrupt_hv: /* * Register contents: * R12 = interrupt vector
@@ -757,6 +757,11 @@ kvmppc_interrupt: lbz r9, HSTATE_IN_GUEST(r13) cmpwi r9, KVM_GUEST_MODE_HOST_HV beq kvmppc_bad_host_intr +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE + cmpwi r9, KVM_GUEST_MODE_GUEST + ld r9, HSTATE_HOST_R2(r13) + beq kvmppc_interrupt_pr +#endif /* We're now back in the host but in guest MMU context */ li r9, KVM_GUEST_MODE_HOST_HV stb r9, HSTATE_IN_GUEST(r13)
arch/powerpc/kvm/book3s_segment.S +2 -2
@@ -161,8 +161,8 @@ kvmppc_handler_trampoline_enter_end: .global kvmppc_handler_trampoline_exit kvmppc_handler_trampoline_exit: -.global kvmppc_interrupt -kvmppc_interrupt: +.global kvmppc_interrupt_pr +kvmppc_interrupt_pr: /* Register usage at this point: *
Signature · 1 line
1.8.1.4
[PULL 45/51] kvm: powerpc: book3s: Add is_hv_enabled to kvmppc_ops
In reply to Alexander GrafFrom: "Aneesh Kumar K.V" <[email protected]>
This help us to identify whether we are running with hypervisor mode KVM enabled. The change is needed so that we can have both HV and PR kvm enabled in the same kernel.
If both HV and PR KVM are included, interrupts come in to the HV version of the kvmppc_interrupt code, which then jumps to the PR handler, renamed to kvmppc_interrupt_pr, if the guest is a PR guest.
Allowing both PR and HV in the same kernel required some changes to kvm_dev_ioctl_check_extension(), since the values returned now can't be selected with #ifdefs as much as previously. We look at is_hv_enabled to return the right value when checking for capabilities.For capabilities that are only provided by HV KVM, we return the HV value only if is_hv_enabled is true. For capabilities provided by PR KVM but not HV, we return the PR value only if is_hv_enabled is false.
NOTE: in later patch we replace is_hv_enabled with a static inline function comparing kvm_ppc_ops
--- arch/powerpc/include/asm/kvm_book3s.h | 53 ---------------------------------- arch/powerpc/include/asm/kvm_ppc.h | 5 ++-- arch/powerpc/kvm/book3s.c | 44 ++++++++++++++++++++++++++++ arch/powerpc/kvm/book3s_hv.c | 1 + arch/powerpc/kvm/book3s_pr.c | 1 + arch/powerpc/kvm/book3s_xics.c | 2 +- arch/powerpc/kvm/powerpc.c | 54 +++++++++++++++++++---------------- 7 files changed, 79 insertions(+), 81 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +0 -53
@@ -301,59 +301,6 @@ static inline ulong kvmppc_get_fault_dar(struct kvm_vcpu *vcpu)return vcpu->arch.fault_dar; } -#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE - -static inline unsigned long kvmppc_interrupt_offset (struct kvm_vcpu *vcpu) -{ -return to_book3s (vcpu)->hior; -} - -static inline void kvmppc_update_int_pending (struct kvm_vcpu *vcpu, -unsigned long pending_now,unsigned long old_pending) -{ -if (pending_now) - vcpu->arch.shared->int_pending =1 ; -else if (old_pending) - vcpu->arch.shared->int_pending =0 ; -} - -static inline bool kvmppc_critical_section (struct kvm_vcpu *vcpu) -{ -ulong crit_raw = vcpu->arch.shared->critical; -ulong crit_r1 =kvmppc_get_gpr (vcpu,1 ); -bool crit; - -/* Truncate crit indicators in 32 bit mode */ -if (!(vcpu->arch.shared->msr &MSR_SF )) { - crit_raw &=0xffffffff ; - crit_r1 &=0xffffffff ; - } - -/* Critical section when crit == r1 */ - crit = (crit_raw == crit_r1); -/* ... and we're in supervisor mode */ - crit = crit && !(vcpu->arch.shared->msr &MSR_PR ); - -return crit; -} -#else /* CONFIG_KVM_BOOK3S_PR_POSSIBLE */ - -static inline unsigned long kvmppc_interrupt_offset (struct kvm_vcpu *vcpu) -{ -return 0 ; -} - -static inline void kvmppc_update_int_pending (struct kvm_vcpu *vcpu, -unsigned long pending_now,unsigned long old_pending) -{ -} - -static inline bool kvmppc_critical_section (struct kvm_vcpu *vcpu) -{ -return false; -} -#endif -/* Magic register values loaded into r3 and r4 before the 'sc' assembly * instruction for the OSI hypercalls */ #define OSI_SC_MAGIC_R3 0x113724FA
arch/powerpc/include/asm/kvm_ppc.h +3 -2
@@ -180,6 +180,7 @@ union kvmppc_one_reg { };struct kvmppc_ops { +bool is_hv_enabled;int (*get_sregs)(struct kvm_vcpu *vcpu,struct kvm_sregs *sregs);int (*set_sregs)(struct kvm_vcpu *vcpu,struct kvm_sregs *sregs); int (*get_one_reg)(struct kvm_vcpu *vcpu, u64 id,
@@ -309,10 +310,10 @@ static inline void kvmppc_set_xics_phys(int cpu, unsigned long addr)static inline u32 kvmppc_get_xics_latch (void ) { -u32 xirr =get_paca ()->kvm_hstate.saved_xirr; +u32 xirr; + xirr =get_paca ()->kvm_hstate.saved_xirr;get_paca ()->kvm_hstate.saved_xirr =0 ; -return xirr; }
arch/powerpc/kvm/book3s.c +44 -0
50 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv.c +1 -0
@@ -2159,6 +2159,7 @@ static long kvm_arch_vm_ioctl_hv(struct file *filp, }static struct kvmppc_ops kvmppc_hv_ops = { + .is_hv_enabled = true, .get_sregs = kvm_arch_vcpu_ioctl_get_sregs_hv, .set_sregs = kvm_arch_vcpu_ioctl_set_sregs_hv, .get_one_reg = kvmppc_get_one_reg_hv,
arch/powerpc/kvm/book3s_pr.c +1 -0
@@ -1523,6 +1523,7 @@ static long kvm_arch_vm_ioctl_pr(struct file *filp, }static struct kvmppc_ops kvmppc_pr_ops = { + .is_hv_enabled = false, .get_sregs = kvm_arch_vcpu_ioctl_get_sregs_pr, .set_sregs = kvm_arch_vcpu_ioctl_set_sregs_pr, .get_one_reg = kvmppc_get_one_reg_pr,
arch/powerpc/kvm/book3s_xics.c +1 -1
@@ -818,7 +818,7 @@ int kvmppc_xics_hcall(struct kvm_vcpu *vcpu, u32 req) }/* Check for real mode returning too hard */ -if (xics->real_mode) +if (xics->real_mode && kvmppc_ops->is_hv_enabled)return kvmppc_xics_rm_complete (vcpu, req);switch (req) {
arch/powerpc/kvm/powerpc.c +29 -25
119 lines not on this page · raw message
Signature · 1 line
1.8.1.4
[PULL 46/51] kvm: powerpc: book3s: pr: move PR related tracepoints to a separate header
In reply to Alexander GrafFrom: "Aneesh Kumar K.V" <[email protected]>
This patch moves PR related tracepoints to a separate header. This enables in converting PR to a kernel module which will be done in later patches
--- arch/powerpc/kvm/book3s_64_mmu_host.c | 2 +- arch/powerpc/kvm/book3s_mmu_hpte.c | 2 +- arch/powerpc/kvm/book3s_pr.c | 4 +- arch/powerpc/kvm/trace.h | 234 +-------------------------- arch/powerpc/kvm/trace_pr.h | 297 ++++++++++++++++++++++++++++++++++ 5 files changed, 309 insertions(+), 230 deletions(-) create mode 100644 arch/powerpc/kvm/trace_pr.h
arch/powerpc/kvm/book3s_64_mmu_host.c +1 -1
@@ -27,7 +27,7 @@#include <asm/machdep.h> #include <asm/mmu_context.h> #include <asm/hw_irq.h> -#include "trace.h" +#include "trace_pr.h" #define PTE_SIZE 12
arch/powerpc/kvm/book3s_mmu_hpte.c +1 -1
@@ -28,7 +28,7 @@#include <asm/mmu_context.h> #include <asm/hw_irq.h> -#include "trace.h" +#include "trace_pr.h" #define PTE_SIZE 12
arch/powerpc/kvm/book3s_pr.c +3 -1
@@ -42,7 +42,9 @@#include <linux/highmem.h> #include "book3s.h" -#include "trace.h" + +#define CREATE_TRACE_POINTS +#include "trace_pr.h" /* #define EXIT_DEBUG */ /* #define DEBUG_EXT */
arch/powerpc/kvm/trace.h +7 -227
276 lines not on this page · raw message
arch/powerpc/kvm/trace_pr.h new file +297 -0
297 lines not on this page · raw message
Signature · 1 line
1.8.1.4
[PULL 47/51] kvm: powerpc: booke: Move booke related tracepoints to separate header
In reply to Alexander GrafFrom: "Aneesh Kumar K.V" <[email protected]>
--- arch/powerpc/kvm/booke.c | 4 +- arch/powerpc/kvm/e500_mmu.c | 2 +- arch/powerpc/kvm/e500_mmu_host.c | 3 +- arch/powerpc/kvm/trace.h | 204 --------------------------------------- arch/powerpc/kvm/trace_booke.h | 177 +++++++++++++++++++++++++++++++++ 5 files changed, 183 insertions(+), 207 deletions(-) create mode 100644 arch/powerpc/kvm/trace_booke.h
arch/powerpc/kvm/booke.c +3 -1
@@ -40,7 +40,9 @@#include "timing.h" #include "booke.h" -#include "trace.h" + +#define CREATE_TRACE_POINTS +#include "trace_booke.h" unsigned long kvmppc_booke_handlers;
arch/powerpc/kvm/e500_mmu.c +1 -1
@@ -32,7 +32,7 @@#include <asm/kvm_ppc.h> #include "e500.h" -#include "trace.h" +#include "trace_booke.h" #include "timing.h" #include "e500_mmu_host.h"
arch/powerpc/kvm/e500_mmu_host.c +2 -1
@@ -32,10 +32,11 @@#include <asm/kvm_ppc.h> #include "e500.h" -#include "trace.h" #include "timing.h" #include "e500_mmu_host.h" +#include "trace_booke.h" +#define to_htlb1_esel (esel) (host_tlb_params[1].entries - (esel) - 1)static struct kvmppc_e500_tlb_params host_tlb_params[E500_TLB_NUM ];
arch/powerpc/kvm/trace.h +0 -204
216 lines not on this page · raw message
arch/powerpc/kvm/trace_booke.h new file +177 -0
177 lines not on this page · raw message
Signature · 1 line
1.8.1.4
[PULL 48/51] kvm: powerpc: book3s: Support building HV and PR KVM as module
In reply to Alexander GrafFrom: "Aneesh Kumar K.V" <[email protected]>
--- arch/powerpc/kvm/Kconfig | 6 +++--- arch/powerpc/kvm/Makefile | 11 ++++++++--- arch/powerpc/kvm/book3s.c | 12 +++++++++++- arch/powerpc/kvm/book3s_emulate.c | 2 +- arch/powerpc/kvm/book3s_hv.c | 2 ++ arch/powerpc/kvm/book3s_pr.c | 5 ++++- arch/powerpc/kvm/book3s_rtas.c | 1 + arch/powerpc/kvm/book3s_xics.c | 1 + arch/powerpc/kvm/emulate.c | 1 + arch/powerpc/kvm/powerpc.c | 10 ++++++++++ virt/kvm/kvm_main.c | 4 ++++ 11 files changed, 46 insertions(+), 9 deletions(-)
arch/powerpc/kvm/Kconfig +3 -3
@@ -73,7 +73,7 @@ config KVM_BOOK3S_64 If unsure, say N. config KVM_BOOK3S_64_HV - bool "KVM support for POWER7 and PPC970 using hypervisor mode in host" + tristate "KVM support for POWER7 and PPC970 using hypervisor mode in host" depends on KVM_BOOK3S_64 select KVM_BOOK3S_HV_POSSIBLE select MMU_NOTIFIER
@@ -94,8 +94,8 @@ config KVM_BOOK3S_64_HV If unsure, say N. config KVM_BOOK3S_64_PR - bool "KVM support without using hypervisor mode in host" - depends on KVM_BOOK3S_64 && !KVM_BOOK3S_64_HV + tristate "KVM support without using hypervisor mode in host" + depends on KVM_BOOK3S_64 select KVM_BOOK3S_PR_POSSIBLE ---help--- Support running guest kernels in virtual machines on processors
arch/powerpc/kvm/Makefile +8 -3
@@ -56,7 +56,7 @@ kvm-objs-$(CONFIG_KVM_E500MC) := $(kvm-e500mc-objs) kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HANDLER) := \ book3s_64_vio_hv.o -kvm-book3s_64-objs-$(CONFIG_KVM_BOOK3S_64_PR) := \ +kvm-pr-y := \ fpu.o \ book3s_paired_singles.o \ book3s_pr.o \
@@ -76,7 +76,7 @@ kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HANDLER) += \ book3s_rmhandlers.o endif -kvm-book3s_64-objs-$(CONFIG_KVM_BOOK3S_64_HV) += \ +kvm-hv-y += \ book3s_hv.o \ book3s_hv_interrupts.o \ book3s_64_mmu_hv.o
@@ -84,13 +84,15 @@ kvm-book3s_64-objs-$(CONFIG_KVM_BOOK3S_64_HV) += \ kvm-book3s_64-builtin-xics-objs-$(CONFIG_KVM_XICS) := \ book3s_hv_rm_xics.o -kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HV) += \ +ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE +kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HANDLER) += \ book3s_hv_rmhandlers.o \ book3s_hv_rm_mmu.o \ book3s_hv_ras.o \ book3s_hv_builtin.o \ book3s_hv_cma.o \ $(kvm-book3s_64-builtin-xics-objs-y) +endif kvm-book3s_64-objs-$(CONFIG_KVM_XICS) += \ book3s_xics.o
@@ -131,4 +133,7 @@ obj-$(CONFIG_KVM_E500MC) += kvm.o obj-$(CONFIG_KVM_BOOK3S_64) += kvm.o obj-$(CONFIG_KVM_BOOK3S_32) += kvm.o +obj-$(CONFIG_KVM_BOOK3S_64_PR) += kvm-pr.o +obj-$(CONFIG_KVM_BOOK3S_64_HV) += kvm-hv.o + obj-y += $(kvm-book3s_64-builtin-objs-y)
arch/powerpc/kvm/book3s.c +11 -1
@@ -170,28 +170,32 @@ void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec)printk (KERN_INFO "Queueing interrupt %x\n" , vec);#endif } - +EXPORT_SYMBOL_GPL (kvmppc_book3s_queue_irqprio);void kvmppc_core_queue_program (struct kvm_vcpu *vcpu,ulong flags) {/* might as well deliver this straight away */ kvmppc_inject_interrupt (vcpu,BOOK3S_INTERRUPT_PROGRAM , flags); } +EXPORT_SYMBOL_GPL (kvmppc_core_queue_program);void kvmppc_core_queue_dec (struct kvm_vcpu *vcpu) {kvmppc_book3s_queue_irqprio (vcpu,BOOK3S_INTERRUPT_DECREMENTER ); } +EXPORT_SYMBOL_GPL (kvmppc_core_queue_dec);int kvmppc_core_pending_dec (struct kvm_vcpu *vcpu) {return test_bit (BOOK3S_IRQPRIO_DECREMENTER , &vcpu->arch.pending_exceptions); } +EXPORT_SYMBOL_GPL (kvmppc_core_pending_dec);void kvmppc_core_dequeue_dec (struct kvm_vcpu *vcpu) {kvmppc_book3s_dequeue_irqprio (vcpu,BOOK3S_INTERRUPT_DECREMENTER ); } +EXPORT_SYMBOL_GPL (kvmppc_core_dequeue_dec);void kvmppc_core_queue_external (struct kvm_vcpu *vcpu,struct kvm_interrupt *irq)
@@ -329,6 +333,7 @@ int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)return 0 ; } +EXPORT_SYMBOL_GPL (kvmppc_core_prepare_to_enter);pfn_t kvmppc_gfn_to_pfn (struct kvm_vcpu *vcpu,gfn_t gfn,bool writing,bool *writable)
@@ -354,6 +359,7 @@ pfn_t kvmppc_gfn_to_pfn(struct kvm_vcpu *vcpu, gfn_t gfn, bool writing,return gfn_to_pfn_prot (vcpu->kvm, gfn, writing, writable); } +EXPORT_SYMBOL_GPL (kvmppc_gfn_to_pfn);static int kvmppc_xlate (struct kvm_vcpu *vcpu,ulong eaddr,bool data,bool iswrite,struct kvmppc_pte *pte)
@@ -421,6 +427,7 @@ int kvmppc_st(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr,return EMULATE_DONE ; } +EXPORT_SYMBOL_GPL (kvmppc_st);int kvmppc_ld (struct kvm_vcpu *vcpu,ulong *eaddr,int size,void *ptr,bool data)
@@ -451,6 +458,7 @@ nopte: mmio:return EMULATE_DO_MMIO ; } +EXPORT_SYMBOL_GPL (kvmppc_ld);int kvm_arch_vcpu_setup (struct kvm_vcpu *vcpu) {
@@ -706,6 +714,7 @@ void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 msr) { kvmppc_ops->set_msr (vcpu, msr); } +EXPORT_SYMBOL_GPL (kvmppc_set_msr);int kvmppc_vcpu_run (struct kvm_run *kvm_run,struct kvm_vcpu *vcpu) {
@@ -787,6 +796,7 @@ int kvm_unmap_hva(struct kvm *kvm, unsigned long hva) {return kvmppc_ops->unmap_hva (kvm, hva); } +EXPORT_SYMBOL_GPL (kvm_unmap_hva);int kvm_unmap_hva_range (struct kvm *kvm,unsigned long start,unsigned long end) {
arch/powerpc/kvm/book3s_emulate.c +1 -1
@@ -172,7 +172,7 @@ int kvmppc_core_emulate_op_pr(struct kvm_run *run, struct kvm_vcpu *vcpu, vcpu->arch.mmu.tlbie (vcpu, addr, large);break ; } -#ifdef CONFIG_KVM_BOOK3S_64_PR +#ifdef CONFIG_PPC_BOOK3S_64 case OP_31_XOP_FAKE_SC1 : {/* SC 1 papr hypercalls */
arch/powerpc/kvm/book3s_hv.c +2 -0
@@ -52,6 +52,7 @@#include <linux/vmalloc.h> #include <linux/highmem.h> #include <linux/hugetlb.h> +#include <linux/module.h> #include "book3s.h"
@@ -2215,3 +2216,4 @@ static void kvmppc_book3s_exit_hv(void)module_init (kvmppc_book3s_init_hv);module_exit (kvmppc_book3s_exit_hv); +MODULE_LICENSE ("GPL" );
arch/powerpc/kvm/book3s_pr.c +4 -1
@@ -40,6 +40,7 @@#include <linux/sched.h> #include <linux/vmalloc.h> #include <linux/highmem.h> +#include <linux/module.h> #include "book3s.h"
@@ -918,7 +919,7 @@ program_interrupt:ulong cmd =kvmppc_get_gpr (vcpu,3 );int i; -#ifdef CONFIG_KVM_BOOK3S_64_PR +#ifdef CONFIG_PPC_BOOK3S_64 if (kvmppc_h_pr (vcpu, cmd) ==EMULATE_DONE ) { r =RESUME_GUEST ;break ;
@@ -1582,3 +1583,5 @@ static void kvmppc_book3s_exit_pr(void)module_init (kvmppc_book3s_init_pr);module_exit (kvmppc_book3s_exit_pr); + +MODULE_LICENSE ("GPL" );
arch/powerpc/kvm/book3s_rtas.c +1 -0
@@ -260,6 +260,7 @@ fail:*/ return rc; } +EXPORT_SYMBOL_GPL (kvmppc_rtas_hcall);void kvmppc_rtas_tokens_free (struct kvm *kvm) {
arch/powerpc/kvm/book3s_xics.c +1 -0
@@ -840,6 +840,7 @@ int kvmppc_xics_hcall(struct kvm_vcpu *vcpu, u32 req)return rc; } +EXPORT_SYMBOL_GPL (kvmppc_xics_hcall);/* -- Initialisation code etc. -- */
arch/powerpc/kvm/emulate.c +1 -0
@@ -483,3 +483,4 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)return emulated; } +EXPORT_SYMBOL_GPL (kvmppc_emulate_instruction);
arch/powerpc/kvm/powerpc.c +10 -0
@@ -126,6 +126,7 @@ int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)return r; } +EXPORT_SYMBOL_GPL (kvmppc_prepare_to_enter);int kvmppc_kvm_pv (struct kvm_vcpu *vcpu) {
@@ -179,6 +180,7 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)return r; } +EXPORT_SYMBOL_GPL (kvmppc_kvm_pv);int kvmppc_sanity_check (struct kvm_vcpu *vcpu) {
@@ -207,6 +209,7 @@ out: vcpu->arch.sane = r;return r ?0 : -EINVAL ; } +EXPORT_SYMBOL_GPL (kvmppc_sanity_check);int kvmppc_emulate_mmio (struct kvm_run *run,struct kvm_vcpu *vcpu) {
@@ -241,6 +244,7 @@ int kvmppc_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu)return r; } +EXPORT_SYMBOL_GPL (kvmppc_emulate_mmio);int kvm_arch_hardware_enable (void *garbage) {
@@ -665,6 +669,7 @@ int kvmppc_handle_load(struct kvm_run *run, struct kvm_vcpu *vcpu,return EMULATE_DO_MMIO ; } +EXPORT_SYMBOL_GPL (kvmppc_handle_load);/* Same as above, but sign extends */ int kvmppc_handle_loads(struct kvm_run *run, struct kvm_vcpu *vcpu,
@@ -726,6 +731,7 @@ int kvmppc_handle_store(struct kvm_run *run, struct kvm_vcpu *vcpu,return EMULATE_DO_MMIO ; } +EXPORT_SYMBOL_GPL (kvmppc_handle_store);int kvm_arch_vcpu_ioctl_run (struct kvm_vcpu *vcpu,struct kvm_run *run) {
@@ -1074,22 +1080,26 @@ long kvmppc_alloc_lpid(void)return lpid; } +EXPORT_SYMBOL_GPL (kvmppc_alloc_lpid);void kvmppc_claim_lpid (long lpid) {set_bit (lpid, lpid_inuse); } +EXPORT_SYMBOL_GPL (kvmppc_claim_lpid);void kvmppc_free_lpid (long lpid) {clear_bit (lpid, lpid_inuse); } +EXPORT_SYMBOL_GPL (kvmppc_free_lpid);void kvmppc_init_lpid (unsigned long nr_lpids_param) { nr_lpids = min_t(unsigned long, KVMPPC_NR_LPIDS, nr_lpids_param);memset (lpid_inuse,0 ,sizeof (lpid_inuse)); } +EXPORT_SYMBOL_GPL (kvmppc_init_lpid);int kvm_arch_init (void *opaque) {
virt/kvm/kvm_main.c +4 -0
@@ -187,6 +187,7 @@ void kvm_flush_remote_tlbs(struct kvm *kvm) ++kvm->stat.remote_tlb_flush;cmpxchg (&kvm->tlbs_dirty, dirty_count,0 ); } +EXPORT_SYMBOL_GPL (kvm_flush_remote_tlbs);void kvm_reload_remote_mmus (struct kvm *kvm) {
@@ -965,6 +966,7 @@ int kvm_get_dirty_log(struct kvm *kvm, out:return r; } +EXPORT_SYMBOL_GPL (kvm_get_dirty_log);bool kvm_largepages_enabled (void ) {
@@ -1653,6 +1655,7 @@ void mark_page_dirty(struct kvm *kvm, gfn_t gfn) memslot =gfn_to_memslot (kvm, gfn);mark_page_dirty_in_slot (kvm, memslot, gfn); } +EXPORT_SYMBOL_GPL (mark_page_dirty);/* * The vCPU has executed a HLT instruction with in-kernel mode enabled.
@@ -1678,6 +1681,7 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)finish_wait (&vcpu->wq, &wait); } +EXPORT_SYMBOL_GPL (kvm_vcpu_block);#ifndef CONFIG_S390 /*
Signature · 1 line
1.8.1.4
[PULL 49/51] kvm: Add struct kvm arg to memslot APIs
In reply to Alexander GrafFrom: "Aneesh Kumar K.V" <[email protected]>
We will use that in the later patch to find the kvm ops handler
--- arch/arm/kvm/arm.c | 5 +++-- arch/ia64/kvm/kvm-ia64.c | 5 +++-- arch/mips/kvm/kvm_mips.c | 5 +++-- arch/powerpc/include/asm/kvm_ppc.h | 6 ++++-- arch/powerpc/kvm/book3s.c | 4 ++-- arch/powerpc/kvm/booke.c | 4 ++-- arch/powerpc/kvm/powerpc.c | 9 +++++---- arch/s390/kvm/kvm-s390.c | 5 +++-- arch/x86/kvm/x86.c | 5 +++-- include/linux/kvm_host.h | 5 +++-- virt/kvm/kvm_main.c | 12 ++++++------ 11 files changed, 37 insertions(+), 28 deletions(-)
arch/arm/kvm/arm.c +3 -2
@@ -152,12 +152,13 @@ int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf)return VM_FAULT_SIGBUS ; } -void kvm_arch_free_memslot (struct kvm_memory_slot *free, +void kvm_arch_free_memslot (struct kvm *kvm,struct kvm_memory_slot *free,struct kvm_memory_slot *dont) { } -int kvm_arch_create_memslot (struct kvm_memory_slot *slot,unsigned long npages) +int kvm_arch_create_memslot (struct kvm *kvm,struct kvm_memory_slot *slot, +unsigned long npages) {return 0 ; }
arch/ia64/kvm/kvm-ia64.c +3 -2
@@ -1550,12 +1550,13 @@ int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf)return VM_FAULT_SIGBUS ; } -void kvm_arch_free_memslot (struct kvm_memory_slot *free, +void kvm_arch_free_memslot (struct kvm *kvm,struct kvm_memory_slot *free,struct kvm_memory_slot *dont) { } -int kvm_arch_create_memslot (struct kvm_memory_slot *slot,unsigned long npages) +int kvm_arch_create_memslot (struct kvm *kvm,struct kvm_memory_slot *slot, +unsigned long npages) {return 0 ; }
arch/mips/kvm/kvm_mips.c +3 -2
@@ -198,12 +198,13 @@ kvm_arch_dev_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)return -ENOIOCTLCMD ; } -void kvm_arch_free_memslot (struct kvm_memory_slot *free, +void kvm_arch_free_memslot (struct kvm *kvm,struct kvm_memory_slot *free,struct kvm_memory_slot *dont) { } -int kvm_arch_create_memslot (struct kvm_memory_slot *slot,unsigned long npages) +int kvm_arch_create_memslot (struct kvm *kvm,struct kvm_memory_slot *slot, +unsigned long npages) {return 0 ; }
arch/powerpc/include/asm/kvm_ppc.h +4 -2
@@ -134,9 +134,11 @@ extern struct page *kvm_alloc_hpt(unsigned long nr_pages);extern void kvm_release_hpt (struct page *page,unsigned long nr_pages);extern int kvmppc_core_init_vm (struct kvm *kvm);extern void kvmppc_core_destroy_vm (struct kvm *kvm); -extern void kvmppc_core_free_memslot (struct kvm_memory_slot *free, +extern void kvmppc_core_free_memslot (struct kvm *kvm, +struct kvm_memory_slot *free,struct kvm_memory_slot *dont); -extern int kvmppc_core_create_memslot (struct kvm_memory_slot *slot, +extern int kvmppc_core_create_memslot (struct kvm *kvm, +struct kvm_memory_slot *slot,unsigned long npages); extern int kvmppc_core_prepare_memory_region(struct kvm *kvm, struct kvm_memory_slot *memslot,
arch/powerpc/kvm/book3s.c +2 -2
@@ -761,13 +761,13 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log)return kvmppc_ops->get_dirty_log (kvm, log); } -void kvmppc_core_free_memslot (struct kvm_memory_slot *free, +void kvmppc_core_free_memslot (struct kvm *kvm,struct kvm_memory_slot *free,struct kvm_memory_slot *dont) { kvmppc_ops->free_memslot (free, dont); } -int kvmppc_core_create_memslot (struct kvm_memory_slot *slot, +int kvmppc_core_create_memslot (struct kvm *kvm,struct kvm_memory_slot *slot,unsigned long npages) {return kvmppc_ops->create_memslot (slot, npages);
arch/powerpc/kvm/booke.c +2 -2
@@ -1662,12 +1662,12 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log)return -ENOTSUPP ; } -void kvmppc_core_free_memslot (struct kvm_memory_slot *free, +void kvmppc_core_free_memslot (struct kvm *kvm,struct kvm_memory_slot *free,struct kvm_memory_slot *dont) { } -int kvmppc_core_create_memslot (struct kvm_memory_slot *slot, +int kvmppc_core_create_memslot (struct kvm *kvm,struct kvm_memory_slot *slot,unsigned long npages) {return 0 ;
arch/powerpc/kvm/powerpc.c +5 -4
@@ -417,15 +417,16 @@ long kvm_arch_dev_ioctl(struct file *filp,return -EINVAL ; } -void kvm_arch_free_memslot (struct kvm_memory_slot *free, +void kvm_arch_free_memslot (struct kvm *kvm,struct kvm_memory_slot *free,struct kvm_memory_slot *dont) { -kvmppc_core_free_memslot (free, dont); +kvmppc_core_free_memslot (kvm, free, dont); } -int kvm_arch_create_memslot (struct kvm_memory_slot *slot,unsigned long npages) +int kvm_arch_create_memslot (struct kvm *kvm,struct kvm_memory_slot *slot, +unsigned long npages) { -return kvmppc_core_create_memslot (slot, npages); +return kvmppc_core_create_memslot (kvm, slot, npages); }void kvm_arch_memslots_updated (struct kvm *kvm)
arch/s390/kvm/kvm-s390.c +3 -2
@@ -1089,12 +1089,13 @@ int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf)return VM_FAULT_SIGBUS ; } -void kvm_arch_free_memslot (struct kvm_memory_slot *free, +void kvm_arch_free_memslot (struct kvm *kvm,struct kvm_memory_slot *free,struct kvm_memory_slot *dont) { } -int kvm_arch_create_memslot (struct kvm_memory_slot *slot,unsigned long npages) +int kvm_arch_create_memslot (struct kvm *kvm,struct kvm_memory_slot *slot, +unsigned long npages) {return 0 ; }
arch/x86/kvm/x86.c +3 -2
@@ -7080,7 +7080,7 @@ void kvm_arch_destroy_vm(struct kvm *kvm)kfree (rcu_dereference_check (kvm->arch.apic_map,1 )); } -void kvm_arch_free_memslot (struct kvm_memory_slot *free, +void kvm_arch_free_memslot (struct kvm *kvm,struct kvm_memory_slot *free,struct kvm_memory_slot *dont) {int i;
@@ -7101,7 +7101,8 @@ void kvm_arch_free_memslot(struct kvm_memory_slot *free, } } -int kvm_arch_create_memslot (struct kvm_memory_slot *slot,unsigned long npages) +int kvm_arch_create_memslot (struct kvm *kvm,struct kvm_memory_slot *slot, +unsigned long npages) {int i;
include/linux/kvm_host.h +3 -2
@@ -507,9 +507,10 @@ int kvm_set_memory_region(struct kvm *kvm, struct kvm_userspace_memory_region *mem);int __kvm_set_memory_region (struct kvm *kvm,struct kvm_userspace_memory_region *mem); -void kvm_arch_free_memslot (struct kvm_memory_slot *free, +void kvm_arch_free_memslot (struct kvm *kvm,struct kvm_memory_slot *free,struct kvm_memory_slot *dont); -int kvm_arch_create_memslot (struct kvm_memory_slot *slot,unsigned long npages); +int kvm_arch_create_memslot (struct kvm *kvm,struct kvm_memory_slot *slot, +unsigned long npages);void kvm_arch_memslots_updated (struct kvm *kvm); int kvm_arch_prepare_memory_region(struct kvm *kvm, struct kvm_memory_slot *memslot,
virt/kvm/kvm_main.c +6 -6
@@ -542,13 +542,13 @@ static void kvm_destroy_dirty_bitmap(struct kvm_memory_slot *memslot)/* * Free any memory in @free but not in @dont. */ -static void kvm_free_physmem_slot (struct kvm_memory_slot *free, +static void kvm_free_physmem_slot (struct kvm *kvm,struct kvm_memory_slot *free,struct kvm_memory_slot *dont) {if (!dont || free->dirty_bitmap != dont->dirty_bitmap)kvm_destroy_dirty_bitmap (free); -kvm_arch_free_memslot (free, dont); +kvm_arch_free_memslot (kvm, free, dont); free->npages =0 ; }
@@ -559,7 +559,7 @@ void kvm_free_physmem(struct kvm *kvm)struct kvm_memory_slot *memslot;kvm_for_each_memslot (memslot, slots) -kvm_free_physmem_slot (memslot,NULL ); +kvm_free_physmem_slot (kvm, memslot,NULL );kfree (kvm->memslots); }
@@ -823,7 +823,7 @@ int __kvm_set_memory_region(struct kvm *kvm,if (change ==KVM_MR_CREATE ) { new.userspace_addr = mem->userspace_addr; -if (kvm_arch_create_memslot (&new, npages)) +if (kvm_arch_create_memslot (kvm, &new, npages)) goto out_free; }
@@ -899,7 +899,7 @@ int __kvm_set_memory_region(struct kvm *kvm,kvm_arch_commit_memory_region (kvm, mem, &old, change); -kvm_free_physmem_slot (&old, &new); +kvm_free_physmem_slot (kvm, &old, &new);kfree (old_memslots);return 0 ;
@@ -907,7 +907,7 @@ int __kvm_set_memory_region(struct kvm *kvm, out_slots:kfree (slots); out_free: -kvm_free_physmem_slot (&new, &old); +kvm_free_physmem_slot (kvm, &new, &old); out:return r; }
Signature · 1 line
1.8.1.4
[PULL 50/51] kvm: powerpc: book3s: Allow the HV and PR selection per virtual machine
In reply to Alexander GrafFrom: "Aneesh Kumar K.V" <[email protected]>
This moves the kvmppc_ops callbacks to be a per VM entity. This enables us to select HV and PR mode when creating a VM. We also allow both kvm-hv and kvm-pr kernel module to be loaded. To achieve this we move /dev/kvm ownership to kvm.ko module. Depending on which KVM mode we select during VM creation we take a reference count on respective module
--- arch/powerpc/include/asm/kvm_host.h | 1 + arch/powerpc/include/asm/kvm_ppc.h | 7 +-- arch/powerpc/kvm/44x.c | 7 ++- arch/powerpc/kvm/book3s.c | 89 +++++++++++++++++++++++++------------ arch/powerpc/kvm/book3s.h | 2 + arch/powerpc/kvm/book3s_hv.c | 18 ++++---- arch/powerpc/kvm/book3s_pr.c | 25 +++++++---- arch/powerpc/kvm/book3s_xics.c | 2 +- arch/powerpc/kvm/booke.c | 22 ++++----- arch/powerpc/kvm/e500.c | 8 +++- arch/powerpc/kvm/e500mc.c | 6 ++- arch/powerpc/kvm/emulate.c | 11 ++--- arch/powerpc/kvm/powerpc.c | 76 ++++++++++++++++++++++--------- include/uapi/linux/kvm.h | 4 ++ 14 files changed, 187 insertions(+), 91 deletions(-)
arch/powerpc/include/asm/kvm_host.h +1 -0
@@ -270,6 +270,7 @@ struct kvm_arch {#ifdef CONFIG_KVM_XICS struct kvmppc_xics *xics;#endif +struct kvmppc_ops *kvm_ops; };/*
arch/powerpc/include/asm/kvm_ppc.h +4 -3
@@ -182,6 +182,7 @@ union kvmppc_one_reg { };struct kvmppc_ops { +struct module *owner;bool is_hv_enabled;int (*get_sregs)(struct kvm_vcpu *vcpu,struct kvm_sregs *sregs);int (*set_sregs)(struct kvm_vcpu *vcpu,struct kvm_sregs *sregs);
@@ -217,7 +218,6 @@ struct kvmppc_ops { unsigned long npages);int (*init_vm)(struct kvm *kvm);void (*destroy_vm)(struct kvm *kvm); -int (*check_processor_compat)(void );int (*get_smmu_info)(struct kvm *kvm,struct kvm_ppc_smmu_info *info);int (*emulate_op)(struct kvm_run *run,struct kvm_vcpu *vcpu,unsigned int inst,int *advance);
@@ -229,7 +229,8 @@ struct kvmppc_ops { }; -extern struct kvmppc_ops *kvmppc_ops; +extern struct kvmppc_ops *kvmppc_hv_ops; +extern struct kvmppc_ops *kvmppc_pr_ops;/* * Cuts out inst bits with ordering according to spec.
@@ -326,7 +327,7 @@ static inline void kvmppc_set_host_ipi(int cpu, u8 host_ipi)static inline void kvmppc_fast_vcpu_kick (struct kvm_vcpu *vcpu) { - kvmppc_ops->fast_vcpu_kick (vcpu); + vcpu->kvm->arch.kvm_ops->fast_vcpu_kick (vcpu); }#else
arch/powerpc/kvm/44x.c +5 -2
@@ -213,16 +213,19 @@ static int __init kvmppc_44x_init(void)if (r) goto err_out; - r =kvm_init (&kvm_ops_44x,sizeof (struct kvmppc_vcpu_44x ), -0 ,THIS_MODULE ); + r =kvm_init (NULL ,sizeof (struct kvmppc_vcpu_44x ),0 ,THIS_MODULE );if (r) goto err_out; + kvm_ops_44x.owner =THIS_MODULE ; + kvmppc_pr_ops = &kvm_ops_44x; + err_out:return r; } static void __exit kvmppc_44x_exit(void) { + kvmppc_pr_ops =NULL ;kvmppc_booke_exit (); }
arch/powerpc/kvm/book3s.c +60 -29
238 lines not on this page · raw message
arch/powerpc/kvm/book3s.h +2 -0
@@ -28,5 +28,7 @@ extern int kvmppc_core_emulate_mtspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val);extern int kvmppc_core_emulate_mfspr_pr (struct kvm_vcpu *vcpu,int sprn,ulong *spr_val); +extern int kvmppc_book3s_init_pr (void ); +extern void kvmppc_book3s_exit_pr (void );#endif
arch/powerpc/kvm/book3s_hv.c +10 -8
@@ -2159,7 +2159,7 @@ static long kvm_arch_vm_ioctl_hv(struct file *filp,return r; } -static struct kvmppc_ops kvmppc_hv_ops = { +static struct kvmppc_ops kvm_ops_hv = { .is_hv_enabled = true, .get_sregs = kvm_arch_vcpu_ioctl_get_sregs_hv, .set_sregs = kvm_arch_vcpu_ioctl_set_sregs_hv,
@@ -2186,7 +2186,6 @@ static struct kvmppc_ops kvmppc_hv_ops = { .create_memslot = kvmppc_core_create_memslot_hv, .init_vm = kvmppc_core_init_vm_hv, .destroy_vm = kvmppc_core_destroy_vm_hv, - .check_processor_compat = kvmppc_core_check_processor_compat_hv, .get_smmu_info = kvm_vm_ioctl_get_smmu_info_hv, .emulate_op = kvmppc_core_emulate_op_hv, .emulate_mtspr = kvmppc_core_emulate_mtspr_hv,
@@ -2198,20 +2197,23 @@ static struct kvmppc_ops kvmppc_hv_ops = {static int kvmppc_book3s_init_hv (void ) {int r; - - r =kvm_init (&kvmppc_hv_ops,sizeof (struct kvm_vcpu ),0 ,THIS_MODULE ); - -if (r) +/* +* FIXME!! Do we need to check on all cpus ? +*/ + r =kvmppc_core_check_processor_compat_hv (); +if (r <0 )return r; - r =kvmppc_mmu_hv_init (); + kvm_ops_hv.owner =THIS_MODULE ; + kvmppc_hv_ops = &kvm_ops_hv; + r =kvmppc_mmu_hv_init ();return r; }static void kvmppc_book3s_exit_hv (void ) { -kvm_exit (); + kvmppc_hv_ops =NULL ; }module_init (kvmppc_book3s_init_hv);
arch/powerpc/kvm/book3s_pr.c +16 -9
@@ -1525,7 +1525,7 @@ static long kvm_arch_vm_ioctl_pr(struct file *filp,return -ENOTTY ; } -static struct kvmppc_ops kvmppc_pr_ops = { +static struct kvmppc_ops kvm_ops_pr = { .is_hv_enabled = false, .get_sregs = kvm_arch_vcpu_ioctl_get_sregs_pr, .set_sregs = kvm_arch_vcpu_ioctl_set_sregs_pr,
@@ -1552,7 +1552,6 @@ static struct kvmppc_ops kvmppc_pr_ops = { .create_memslot = kvmppc_core_create_memslot_pr, .init_vm = kvmppc_core_init_vm_pr, .destroy_vm = kvmppc_core_destroy_vm_pr, - .check_processor_compat = kvmppc_core_check_processor_compat_pr, .get_smmu_info = kvm_vm_ioctl_get_smmu_info_pr, .emulate_op = kvmppc_core_emulate_op_pr, .emulate_mtspr = kvmppc_core_emulate_mtspr_pr,
@@ -1561,27 +1560,35 @@ static struct kvmppc_ops kvmppc_pr_ops = { .arch_vm_ioctl = kvm_arch_vm_ioctl_pr, }; -static int kvmppc_book3s_init_pr (void ) + +int kvmppc_book3s_init_pr (void ) {int r; - r =kvm_init (&kvmppc_pr_ops,sizeof (struct kvm_vcpu ),0 ,THIS_MODULE ); - -if (r) + r =kvmppc_core_check_processor_compat_pr (); +if (r <0 )return r; - r =kvmppc_mmu_hpte_sysinit (); + kvm_ops_pr.owner =THIS_MODULE ; + kvmppc_pr_ops = &kvm_ops_pr; + r =kvmppc_mmu_hpte_sysinit ();return r; } -static void kvmppc_book3s_exit_pr (void ) +void kvmppc_book3s_exit_pr (void ) { + kvmppc_pr_ops =NULL ;kvmppc_mmu_hpte_sysexit (); -kvm_exit (); } +/* +* We only support separate modules for book3s 64 +*/ +#ifdef CONFIG_PPC_BOOK3S_64 +module_init (kvmppc_book3s_init_pr);module_exit (kvmppc_book3s_exit_pr);MODULE_LICENSE ("GPL" ); +#endif
arch/powerpc/kvm/book3s_xics.c +1 -1
@@ -818,7 +818,7 @@ int kvmppc_xics_hcall(struct kvm_vcpu *vcpu, u32 req) }/* Check for real mode returning too hard */ -if (xics->real_mode && kvmppc_ops->is_hv_enabled) +if (xics->real_mode && vcpu->kvm->arch.kvm_ops->is_hv_enabled)return kvmppc_xics_rm_complete (vcpu, req);switch (req) {
arch/powerpc/kvm/booke.c +11 -11
@@ -1472,7 +1472,7 @@ int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,get_sregs_base (vcpu, sregs);get_sregs_arch206 (vcpu, sregs); -return kvmppc_ops->get_sregs (vcpu, sregs); +return vcpu->kvm->arch.kvm_ops->get_sregs (vcpu, sregs); } int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
@@ -1491,7 +1491,7 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,if (ret <0 )return ret; -return kvmppc_ops->set_sregs (vcpu, sregs); +return vcpu->kvm->arch.kvm_ops->set_sregs (vcpu, sregs); }int kvm_vcpu_ioctl_get_one_reg (struct kvm_vcpu *vcpu,struct kvm_one_reg *reg)
@@ -1548,7 +1548,7 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) val =get_reg_val (reg->id, vcpu->arch.vrsave);break ;default : - r = kvmppc_ops->get_one_reg (vcpu, reg->id, &val); + r = vcpu->kvm->arch.kvm_ops->get_one_reg (vcpu, reg->id, &val);break ; }
@@ -1631,7 +1631,7 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) vcpu->arch.vrsave =set_reg_val (reg->id, val);break ;default : - r = kvmppc_ops->set_one_reg (vcpu, reg->id, &val); + r = vcpu->kvm->arch.kvm_ops->set_one_reg (vcpu, reg->id, &val);break ; }
@@ -1911,37 +1911,37 @@ void kvmppc_booke_vcpu_put(struct kvm_vcpu *vcpu)void kvmppc_mmu_destroy (struct kvm_vcpu *vcpu) { - kvmppc_ops->mmu_destroy (vcpu); + vcpu->kvm->arch.kvm_ops->mmu_destroy (vcpu); }int kvmppc_core_init_vm (struct kvm *kvm) { -return kvmppc_ops->init_vm (kvm); +return kvm->arch.kvm_ops->init_vm (kvm); }struct kvm_vcpu *kvmppc_core_vcpu_create (struct kvm *kvm,unsigned int id) { -return kvmppc_ops->vcpu_create (kvm, id); +return kvm->arch.kvm_ops->vcpu_create (kvm, id); }void kvmppc_core_vcpu_free (struct kvm_vcpu *vcpu) { - kvmppc_ops->vcpu_free (vcpu); + vcpu->kvm->arch.kvm_ops->vcpu_free (vcpu); }void kvmppc_core_destroy_vm (struct kvm *kvm) { - kvmppc_ops->destroy_vm (kvm); + kvm->arch.kvm_ops->destroy_vm (kvm); }void kvmppc_core_vcpu_load (struct kvm_vcpu *vcpu,int cpu) { - kvmppc_ops->vcpu_load (vcpu, cpu); + vcpu->kvm->arch.kvm_ops->vcpu_load (vcpu, cpu); }void kvmppc_core_vcpu_put (struct kvm_vcpu *vcpu) { - kvmppc_ops->vcpu_put (vcpu); + vcpu->kvm->arch.kvm_ops->vcpu_put (vcpu); }int __init kvmppc_booke_init (void )
arch/powerpc/kvm/e500.c +7 -1
@@ -555,13 +555,19 @@ static int __init kvmppc_e500_init(void)flush_icache_range (kvmppc_booke_handlers, kvmppc_booke_handlers + ivor[max_ivor] + handler_len); - r =kvm_init (&kvm_ops_e500,sizeof (struct kvmppc_vcpu_e500 ),0 ,THIS_MODULE ); + r =kvm_init (NULL ,sizeof (struct kvmppc_vcpu_e500 ),0 ,THIS_MODULE ); +if (r) + goto err_out; + kvm_ops_e500.owner =THIS_MODULE ; + kvmppc_pr_ops = &kvm_ops_e500; + err_out:return r; } static void __exit kvmppc_e500_exit(void) { + kvmppc_pr_ops =NULL ;kvmppc_booke_exit (); }
arch/powerpc/kvm/e500mc.c +5 -1
@@ -373,15 +373,19 @@ static int __init kvmppc_e500mc_init(void)kvmppc_init_lpid (64 );kvmppc_claim_lpid (0 );/* host */ - r =kvm_init (&kvm_ops_e500mc,sizeof (struct kvmppc_vcpu_e500 ),0 ,THIS_MODULE ); + r =kvm_init (NULL ,sizeof (struct kvmppc_vcpu_e500 ),0 ,THIS_MODULE );if (r) goto err_out; + kvm_ops_e500mc.owner =THIS_MODULE ; + kvmppc_pr_ops = &kvm_ops_e500mc; + err_out:return r; } static void __exit kvmppc_e500mc_exit(void) { + kvmppc_pr_ops =NULL ;kvmppc_booke_exit (); }
arch/powerpc/kvm/emulate.c +6 -5
@@ -130,8 +130,8 @@ static int kvmppc_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)case SPRN_PIR :break ;default : - emulated = kvmppc_ops->emulate_mtspr (vcpu, sprn, - spr_val); + emulated = vcpu->kvm->arch.kvm_ops->emulate_mtspr (vcpu, sprn, + spr_val);if (emulated ==EMULATE_FAIL )printk (KERN_INFO "mtspr: unknown spr " "0x%x\n" , sprn);
@@ -191,8 +191,8 @@ static int kvmppc_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt) spr_val =kvmppc_get_dec (vcpu,get_tb ());break ;default : - emulated = kvmppc_ops->emulate_mfspr (vcpu, sprn, - &spr_val); + emulated = vcpu->kvm->arch.kvm_ops->emulate_mfspr (vcpu, sprn, + &spr_val);if (unlikely (emulated ==EMULATE_FAIL )) {printk (KERN_INFO "mfspr: unknown spr " "0x%x\n" , sprn);
@@ -464,7 +464,8 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) }if (emulated ==EMULATE_FAIL ) { - emulated = kvmppc_ops->emulate_op (run, vcpu, inst, &advance); + emulated = vcpu->kvm->arch.kvm_ops->emulate_op (run, vcpu, inst, + &advance);if (emulated ==EMULATE_AGAIN ) { advance =0 ; }else if (emulated ==EMULATE_FAIL ) {
arch/powerpc/kvm/powerpc.c +55 -21
171 lines not on this page · raw message
include/uapi/linux/kvm.h +4 -0
@@ -518,6 +518,10 @@ struct kvm_ppc_smmu_info {/* machine type bits, to be used as argument to KVM_CREATE_VM */ #define KVM_VM_S390_UCONTROL 1 +/* on ppc, 0 indicate default, 1 should force HV and 2 PR */ +#define KVM_VM_PPC_HV 1 +#define KVM_VM_PPC_PR 2 +#define KVM_S390_SIE_PAGE_OFFSET 1/*
Signature · 1 line
1.8.1.4
[PULL 51/51] kvm: powerpc: book3s: drop is_hv_enabled
In reply to Alexander GrafFrom: "Aneesh Kumar K.V" <[email protected]>
drop is_hv_enabled, because that should not be a callback property
--- arch/powerpc/include/asm/kvm_ppc.h | 6 +++++- arch/powerpc/kvm/book3s.c | 6 +++--- arch/powerpc/kvm/book3s_hv.c | 1 - arch/powerpc/kvm/book3s_pr.c | 1 - arch/powerpc/kvm/book3s_xics.c | 2 +- arch/powerpc/kvm/powerpc.c | 2 +- 6 files changed, 10 insertions(+), 8 deletions(-)
arch/powerpc/include/asm/kvm_ppc.h +5 -1
@@ -183,7 +183,6 @@ union kvmppc_one_reg {struct kvmppc_ops {struct module *owner; -bool is_hv_enabled;int (*get_sregs)(struct kvm_vcpu *vcpu,struct kvm_sregs *sregs);int (*set_sregs)(struct kvm_vcpu *vcpu,struct kvm_sregs *sregs); int (*get_one_reg)(struct kvm_vcpu *vcpu, u64 id,
@@ -232,6 +231,11 @@ struct kvmppc_ops {extern struct kvmppc_ops *kvmppc_hv_ops;extern struct kvmppc_ops *kvmppc_pr_ops; +static inline bool is_kvmppc_hv_enabled (struct kvm *kvm) +{ +return kvm->arch.kvm_ops == kvmppc_hv_ops; +} +/* * Cuts out inst bits with ordering according to spec. * That means the leftmost bit is zero. All given bits are included.
arch/powerpc/kvm/book3s.c +3 -3
@@ -72,7 +72,7 @@ void kvmppc_core_load_guest_debugstate(struct kvm_vcpu *vcpu)static inline unsigned long kvmppc_interrupt_offset (struct kvm_vcpu *vcpu) { -if (!vcpu->kvm->arch.kvm_ops->is_hv_enabled) +if (!is_kvmppc_hv_enabled (vcpu->kvm))return to_book3s (vcpu)->hior;return 0 ; }
@@ -80,7 +80,7 @@ static inline unsigned long kvmppc_interrupt_offset(struct kvm_vcpu *vcpu)static inline void kvmppc_update_int_pending (struct kvm_vcpu *vcpu,unsigned long pending_now,unsigned long old_pending) { -if (vcpu->kvm->arch.kvm_ops->is_hv_enabled) +if (is_kvmppc_hv_enabled (vcpu->kvm))return ;if (pending_now) vcpu->arch.shared->int_pending =1 ;
@@ -94,7 +94,7 @@ static inline bool kvmppc_critical_section(struct kvm_vcpu *vcpu)ulong crit_r1;bool crit; -if (vcpu->kvm->arch.kvm_ops->is_hv_enabled) +if (is_kvmppc_hv_enabled (vcpu->kvm))return false; crit_raw = vcpu->arch.shared->critical;
arch/powerpc/kvm/book3s_hv.c +0 -1
@@ -2160,7 +2160,6 @@ static long kvm_arch_vm_ioctl_hv(struct file *filp, }static struct kvmppc_ops kvm_ops_hv = { - .is_hv_enabled = true, .get_sregs = kvm_arch_vcpu_ioctl_get_sregs_hv, .set_sregs = kvm_arch_vcpu_ioctl_set_sregs_hv, .get_one_reg = kvmppc_get_one_reg_hv,
arch/powerpc/kvm/book3s_pr.c +0 -1
@@ -1526,7 +1526,6 @@ static long kvm_arch_vm_ioctl_pr(struct file *filp, }static struct kvmppc_ops kvm_ops_pr = { - .is_hv_enabled = false, .get_sregs = kvm_arch_vcpu_ioctl_get_sregs_pr, .set_sregs = kvm_arch_vcpu_ioctl_set_sregs_pr, .get_one_reg = kvmppc_get_one_reg_pr,
arch/powerpc/kvm/book3s_xics.c +1 -1
@@ -818,7 +818,7 @@ int kvmppc_xics_hcall(struct kvm_vcpu *vcpu, u32 req) }/* Check for real mode returning too hard */ -if (xics->real_mode && vcpu->kvm->arch.kvm_ops->is_hv_enabled) +if (xics->real_mode &&is_kvmppc_hv_enabled (vcpu->kvm))return kvmppc_xics_rm_complete (vcpu, req);switch (req) {
arch/powerpc/kvm/powerpc.c +1 -1
@@ -200,7 +200,7 @@ int kvmppc_sanity_check(struct kvm_vcpu *vcpu) goto out;/* HV KVM can only do PAPR mode for now */ -if (!vcpu->arch.papr_enabled && vcpu->kvm->arch.kvm_ops->is_hv_enabled) +if (!vcpu->arch.papr_enabled &&is_kvmppc_hv_enabled (vcpu->kvm)) goto out;#ifdef CONFIG_KVM_BOOKE_HV
Signature · 1 line
1.8.1.4