Skip to content

Commit 53ea2e4

Browse files
committed
Merge tag 'signed-kvm-ppc-next' of git://github.com/agraf/linux-2.6 into kvm-next
Patch queue for ppc - 2014-05-30 In this round we have a few nice gems. PR KVM gains initial POWER8 support as well as LE host awareness, ihe e500 targets can now properly run u-boot, LE guests now work with PR KVM including KVM hypercalls and HV KVM guests can now use huge pages. On top of this there are some bug fixes. Conflicts: include/uapi/linux/kvm.h
2 parents ee1a725 + d8d164a commit 53ea2e4

45 files changed

Lines changed: 1116 additions & 415 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Documentation/virtual/kvm/api.txt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,6 +1794,11 @@ registers, find a list below:
17941794
PPC | KVM_REG_PPC_MMCR0 | 64
17951795
PPC | KVM_REG_PPC_MMCR1 | 64
17961796
PPC | KVM_REG_PPC_MMCRA | 64
1797+
PPC | KVM_REG_PPC_MMCR2 | 64
1798+
PPC | KVM_REG_PPC_MMCRS | 64
1799+
PPC | KVM_REG_PPC_SIAR | 64
1800+
PPC | KVM_REG_PPC_SDAR | 64
1801+
PPC | KVM_REG_PPC_SIER | 64
17971802
PPC | KVM_REG_PPC_PMC1 | 32
17981803
PPC | KVM_REG_PPC_PMC2 | 32
17991804
PPC | KVM_REG_PPC_PMC3 | 32
@@ -1868,6 +1873,7 @@ registers, find a list below:
18681873
PPC | KVM_REG_PPC_PPR | 64
18691874
PPC | KVM_REG_PPC_ARCH_COMPAT 32
18701875
PPC | KVM_REG_PPC_DABRX | 32
1876+
PPC | KVM_REG_PPC_WORT | 64
18711877
PPC | KVM_REG_PPC_TM_GPR0 | 64
18721878
...
18731879
PPC | KVM_REG_PPC_TM_GPR31 | 64

‎Documentation/virtual/kvm/ppc-pv.txt‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,24 @@ a bitmap of available features inside the magic page.
9494
The following enhancements to the magic page are currently available:
9595

9696
KVM_MAGIC_FEAT_SR Maps SR registers r/w in the magic page
97+
KVM_MAGIC_FEAT_MAS0_TO_SPRG7 Maps MASn, ESR, PIR and high SPRGs
9798

9899
For enhanced features in the magic page, please check for the existence of the
99100
feature before using them!
100101

102+
Magic page flags
103+
================
104+
105+
In addition to features that indicate whether a host is capable of a particular
106+
feature we also have a channel for a guest to tell the guest whether it's capable
107+
of something. This is what we call "flags".
108+
109+
Flags are passed to the host in the low 12 bits of the Effective Address.
110+
111+
The following flags are currently available for a guest to expose:
112+
113+
MAGIC_PAGE_FLAG_NOT_MAPPED_NX Guest handles NX bits correclty wrt magic page
114+
101115
MSR bits
102116
========
103117

‎arch/powerpc/include/asm/disassemble.h‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,38 @@ static inline unsigned int get_oc(u32 inst)
8181
{
8282
return (inst >> 11) & 0x7fff;
8383
}
84+
85+
#define IS_XFORM(inst) (get_op(inst) == 31)
86+
#define IS_DSFORM(inst) (get_op(inst) >= 56)
87+
88+
/*
89+
* Create a DSISR value from the instruction
90+
*/
91+
static inline unsigned make_dsisr(unsigned instr)
92+
{
93+
unsigned dsisr;
94+
95+
96+
/* bits 6:15 --> 22:31 */
97+
dsisr = (instr & 0x03ff0000) >> 16;
98+
99+
if (IS_XFORM(instr)) {
100+
/* bits 29:30 --> 15:16 */
101+
dsisr |= (instr & 0x00000006) << 14;
102+
/* bit 25 --> 17 */
103+
dsisr |= (instr & 0x00000040) << 8;
104+
/* bits 21:24 --> 18:21 */
105+
dsisr |= (instr & 0x00000780) << 3;
106+
} else {
107+
/* bit 5 --> 17 */
108+
dsisr |= (instr & 0x04000000) >> 12;
109+
/* bits 1: 4 --> 18:21 */
110+
dsisr |= (instr & 0x78000000) >> 17;
111+
/* bits 30:31 --> 12:13 */
112+
if (IS_DSFORM(instr))
113+
dsisr |= (instr & 0x00000003) << 18;
114+
}
115+
116+
return dsisr;
117+
}
84118
#endif /* __ASM_PPC_DISASSEMBLE_H__ */

‎arch/powerpc/include/asm/kvm_asm.h‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
#define BOOK3S_INTERRUPT_PERFMON 0xf00
103103
#define BOOK3S_INTERRUPT_ALTIVEC 0xf20
104104
#define BOOK3S_INTERRUPT_VSX 0xf40
105+
#define BOOK3S_INTERRUPT_FAC_UNAVAIL 0xf60
105106
#define BOOK3S_INTERRUPT_H_FAC_UNAVAIL 0xf80
106107

107108
#define BOOK3S_IRQPRIO_SYSTEM_RESET 0
@@ -114,14 +115,15 @@
114115
#define BOOK3S_IRQPRIO_FP_UNAVAIL 7
115116
#define BOOK3S_IRQPRIO_ALTIVEC 8
116117
#define BOOK3S_IRQPRIO_VSX 9
117-
#define BOOK3S_IRQPRIO_SYSCALL 10
118-
#define BOOK3S_IRQPRIO_MACHINE_CHECK 11
119-
#define BOOK3S_IRQPRIO_DEBUG 12
120-
#define BOOK3S_IRQPRIO_EXTERNAL 13
121-
#define BOOK3S_IRQPRIO_DECREMENTER 14
122-
#define BOOK3S_IRQPRIO_PERFORMANCE_MONITOR 15
123-
#define BOOK3S_IRQPRIO_EXTERNAL_LEVEL 16
124-
#define BOOK3S_IRQPRIO_MAX 17
118+
#define BOOK3S_IRQPRIO_FAC_UNAVAIL 10
119+
#define BOOK3S_IRQPRIO_SYSCALL 11
120+
#define BOOK3S_IRQPRIO_MACHINE_CHECK 12
121+
#define BOOK3S_IRQPRIO_DEBUG 13
122+
#define BOOK3S_IRQPRIO_EXTERNAL 14
123+
#define BOOK3S_IRQPRIO_DECREMENTER 15
124+
#define BOOK3S_IRQPRIO_PERFORMANCE_MONITOR 16
125+
#define BOOK3S_IRQPRIO_EXTERNAL_LEVEL 17
126+
#define BOOK3S_IRQPRIO_MAX 18
125127

126128
#define BOOK3S_HFLAG_DCBZ32 0x1
127129
#define BOOK3S_HFLAG_SLB 0x2

‎arch/powerpc/include/asm/kvm_book3s.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,10 @@ static inline ulong kvmppc_get_pc(struct kvm_vcpu *vcpu)
268268
return vcpu->arch.pc;
269269
}
270270

271+
static inline u64 kvmppc_get_msr(struct kvm_vcpu *vcpu);
271272
static inline bool kvmppc_need_byteswap(struct kvm_vcpu *vcpu)
272273
{
273-
return (vcpu->arch.shared->msr & MSR_LE) != (MSR_KERNEL & MSR_LE);
274+
return (kvmppc_get_msr(vcpu) & MSR_LE) != (MSR_KERNEL & MSR_LE);
274275
}
275276

276277
static inline u32 kvmppc_get_last_inst_internal(struct kvm_vcpu *vcpu, ulong pc)

‎arch/powerpc/include/asm/kvm_book3s_64.h‎

Lines changed: 123 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -77,49 +77,149 @@ static inline long try_lock_hpte(unsigned long *hpte, unsigned long bits)
7777
return old == 0;
7878
}
7979

80+
static inline int __hpte_actual_psize(unsigned int lp, int psize)
81+
{
82+
int i, shift;
83+
unsigned int mask;
84+
85+
/* start from 1 ignoring MMU_PAGE_4K */
86+
for (i = 1; i < MMU_PAGE_COUNT; i++) {
87+
88+
/* invalid penc */
89+
if (mmu_psize_defs[psize].penc[i] == -1)
90+
continue;
91+
/*
92+
* encoding bits per actual page size
93+
* PTE LP actual page size
94+
* rrrr rrrz >=8KB
95+
* rrrr rrzz >=16KB
96+
* rrrr rzzz >=32KB
97+
* rrrr zzzz >=64KB
98+
* .......
99+
*/
100+
shift = mmu_psize_defs[i].shift - LP_SHIFT;
101+
if (shift > LP_BITS)
102+
shift = LP_BITS;
103+
mask = (1 << shift) - 1;
104+
if ((lp & mask) == mmu_psize_defs[psize].penc[i])
105+
return i;
106+
}
107+
return -1;
108+
}
109+
80110
static inline unsigned long compute_tlbie_rb(unsigned long v, unsigned long r,
81111
unsigned long pte_index)
82112
{
83-
unsigned long rb, va_low;
113+
int b_psize, a_psize;
114+
unsigned int penc;
115+
unsigned long rb = 0, va_low, sllp;
116+
unsigned int lp = (r >> LP_SHIFT) & ((1 << LP_BITS) - 1);
117+
118+
if (!(v & HPTE_V_LARGE)) {
119+
/* both base and actual psize is 4k */
120+
b_psize = MMU_PAGE_4K;
121+
a_psize = MMU_PAGE_4K;
122+
} else {
123+
for (b_psize = 0; b_psize < MMU_PAGE_COUNT; b_psize++) {
124+
125+
/* valid entries have a shift value */
126+
if (!mmu_psize_defs[b_psize].shift)
127+
continue;
84128

129+
a_psize = __hpte_actual_psize(lp, b_psize);
130+
if (a_psize != -1)
131+
break;
132+
}
133+
}
134+
/*
135+
* Ignore the top 14 bits of va
136+
* v have top two bits covering segment size, hence move
137+
* by 16 bits, Also clear the lower HPTE_V_AVPN_SHIFT (7) bits.
138+
* AVA field in v also have the lower 23 bits ignored.
139+
* For base page size 4K we need 14 .. 65 bits (so need to
140+
* collect extra 11 bits)
141+
* For others we need 14..14+i
142+
*/
143+
/* This covers 14..54 bits of va*/
85144
rb = (v & ~0x7fUL) << 16; /* AVA field */
145+
/*
146+
* AVA in v had cleared lower 23 bits. We need to derive
147+
* that from pteg index
148+
*/
86149
va_low = pte_index >> 3;
87150
if (v & HPTE_V_SECONDARY)
88151
va_low = ~va_low;
89-
/* xor vsid from AVA */
152+
/*
153+
* get the vpn bits from va_low using reverse of hashing.
154+
* In v we have va with 23 bits dropped and then left shifted
155+
* HPTE_V_AVPN_SHIFT (7) bits. Now to find vsid we need
156+
* right shift it with (SID_SHIFT - (23 - 7))
157+
*/
90158
if (!(v & HPTE_V_1TB_SEG))
91-
va_low ^= v >> 12;
159+
va_low ^= v >> (SID_SHIFT - 16);
92160
else
93-
va_low ^= v >> 24;
161+
va_low ^= v >> (SID_SHIFT_1T - 16);
94162
va_low &= 0x7ff;
95-
if (v & HPTE_V_LARGE) {
96-
rb |= 1; /* L field */
97-
if (cpu_has_feature(CPU_FTR_ARCH_206) &&
98-
(r & 0xff000)) {
99-
/* non-16MB large page, must be 64k */
100-
/* (masks depend on page size) */
101-
rb |= 0x1000; /* page encoding in LP field */
102-
rb |= (va_low & 0x7f) << 16; /* 7b of VA in AVA/LP field */
103-
rb |= ((va_low << 4) & 0xf0); /* AVAL field (P7 doesn't seem to care) */
104-
}
105-
} else {
106-
/* 4kB page */
107-
rb |= (va_low & 0x7ff) << 12; /* remaining 11b of VA */
163+
164+
switch (b_psize) {
165+
case MMU_PAGE_4K:
166+
sllp = ((mmu_psize_defs[a_psize].sllp & SLB_VSID_L) >> 6) |
167+
((mmu_psize_defs[a_psize].sllp & SLB_VSID_LP) >> 4);
168+
rb |= sllp << 5; /* AP field */
169+
rb |= (va_low & 0x7ff) << 12; /* remaining 11 bits of AVA */
170+
break;
171+
default:
172+
{
173+
int aval_shift;
174+
/*
175+
* remaining 7bits of AVA/LP fields
176+
* Also contain the rr bits of LP
177+
*/
178+
rb |= (va_low & 0x7f) << 16;
179+
/*
180+
* Now clear not needed LP bits based on actual psize
181+
*/
182+
rb &= ~((1ul << mmu_psize_defs[a_psize].shift) - 1);
183+
/*
184+
* AVAL field 58..77 - base_page_shift bits of va
185+
* we have space for 58..64 bits, Missing bits should
186+
* be zero filled. +1 is to take care of L bit shift
187+
*/
188+
aval_shift = 64 - (77 - mmu_psize_defs[b_psize].shift) + 1;
189+
rb |= ((va_low << aval_shift) & 0xfe);
190+
191+
rb |= 1; /* L field */
192+
penc = mmu_psize_defs[b_psize].penc[a_psize];
193+
rb |= penc << 12; /* LP field */
194+
break;
195+
}
108196
}
109197
rb |= (v >> 54) & 0x300; /* B field */
110198
return rb;
111199
}
112200

113201
static inline unsigned long hpte_page_size(unsigned long h, unsigned long l)
114202
{
203+
int size, a_psize;
204+
/* Look at the 8 bit LP value */
205+
unsigned int lp = (l >> LP_SHIFT) & ((1 << LP_BITS) - 1);
206+
115207
/* only handle 4k, 64k and 16M pages for now */
116208
if (!(h & HPTE_V_LARGE))
117-
return 1ul << 12; /* 4k page */
118-
if ((l & 0xf000) == 0x1000 && cpu_has_feature(CPU_FTR_ARCH_206))
119-
return 1ul << 16; /* 64k page */
120-
if ((l & 0xff000) == 0)
121-
return 1ul << 24; /* 16M page */
122-
return 0; /* error */
209+
return 1ul << 12;
210+
else {
211+
for (size = 0; size < MMU_PAGE_COUNT; size++) {
212+
/* valid entries have a shift value */
213+
if (!mmu_psize_defs[size].shift)
214+
continue;
215+
216+
a_psize = __hpte_actual_psize(lp, size);
217+
if (a_psize != -1)
218+
return 1ul << mmu_psize_defs[a_psize].shift;
219+
}
220+
221+
}
222+
return 0;
123223
}
124224

125225
static inline unsigned long hpte_rpn(unsigned long ptel, unsigned long psize)

‎arch/powerpc/include/asm/kvm_book3s_asm.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ struct kvmppc_host_state {
104104
#ifdef CONFIG_PPC_BOOK3S_64
105105
u64 cfar;
106106
u64 ppr;
107+
u64 host_fscr;
107108
#endif
108109
};
109110

@@ -133,6 +134,7 @@ struct kvmppc_book3s_shadow_vcpu {
133134
u64 esid;
134135
u64 vsid;
135136
} slb[64]; /* guest SLB */
137+
u64 shadow_fscr;
136138
#endif
137139
};
138140

‎arch/powerpc/include/asm/kvm_booke.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,4 @@ static inline ulong kvmppc_get_fault_dar(struct kvm_vcpu *vcpu)
108108
{
109109
return vcpu->arch.fault_dear;
110110
}
111-
112-
static inline ulong kvmppc_get_msr(struct kvm_vcpu *vcpu)
113-
{
114-
return vcpu->arch.shared->msr;
115-
}
116111
#endif /* __ASM_KVM_BOOKE_H__ */

‎arch/powerpc/include/asm/kvm_host.h‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,9 @@ struct kvm_vcpu_arch {
449449
ulong pc;
450450
ulong ctr;
451451
ulong lr;
452+
#ifdef CONFIG_PPC_BOOK3S
452453
ulong tar;
454+
#endif
453455

454456
ulong xer;
455457
u32 cr;
@@ -475,6 +477,7 @@ struct kvm_vcpu_arch {
475477
ulong ppr;
476478
ulong pspb;
477479
ulong fscr;
480+
ulong shadow_fscr;
478481
ulong ebbhr;
479482
ulong ebbrr;
480483
ulong bescr;
@@ -562,6 +565,7 @@ struct kvm_vcpu_arch {
562565
#ifdef CONFIG_PPC_BOOK3S
563566
ulong fault_dar;
564567
u32 fault_dsisr;
568+
unsigned long intr_msr;
565569
#endif
566570

567571
#ifdef CONFIG_BOOKE
@@ -622,8 +626,12 @@ struct kvm_vcpu_arch {
622626
wait_queue_head_t cpu_run;
623627

624628
struct kvm_vcpu_arch_shared *shared;
629+
#if defined(CONFIG_PPC_BOOK3S_64) && defined(CONFIG_KVM_BOOK3S_PR_POSSIBLE)
630+
bool shared_big_endian;
631+
#endif
625632
unsigned long magic_page_pa; /* phys addr to map the magic page to */
626633
unsigned long magic_page_ea; /* effect. addr to map the magic page to */
634+
bool disable_kernel_nx;
627635

628636
int irq_type; /* one of KVM_IRQ_* */
629637
int irq_cpu_id;
@@ -654,7 +662,6 @@ struct kvm_vcpu_arch {
654662
spinlock_t tbacct_lock;
655663
u64 busy_stolen;
656664
u64 busy_preempt;
657-
unsigned long intr_msr;
658665
#endif
659666
};
660667

0 commit comments

Comments
 (0)