Skip to content

Commit d2ff4fc

Browse files
committed
Merge branch 'for-upstream' of https://github.com/agraf/linux-2.6 into queue
* 'for-upstream' of https://github.com/agraf/linux-2.6: (28 commits) KVM: PPC: booke: Get/set guest EPCR register using ONE_REG interface KVM: PPC: bookehv: Add EPCR support in mtspr/mfspr emulation KVM: PPC: bookehv: Add guest computation mode for irq delivery KVM: PPC: Make EPCR a valid field for booke64 and bookehv KVM: PPC: booke: Extend MAS2 EPN mask for 64-bit KVM: PPC: e500: Mask MAS2 EPN high 32-bits in 32/64 tlbwe emulation KVM: PPC: Mask ea's high 32-bits in 32/64 instr emulation KVM: PPC: e500: Add emulation helper for getting instruction ea KVM: PPC: bookehv64: Add support for interrupt handling KVM: PPC: bookehv: Remove GET_VCPU macro from exception handler KVM: PPC: booke: Fix get_tb() compile error on 64-bit KVM: PPC: e500: Silence bogus GCC warning in tlb code KVM: PPC: Book3S HV: Handle guest-caused machine checks on POWER7 without panicking KVM: PPC: Book3S HV: Improve handling of local vs. global TLB invalidations MAINTAINERS: Add git tree link for PPC KVM KVM: PPC: Book3S PR: MSR_DE doesn't exist on Book 3S KVM: PPC: Book3S PR: Fix VSX handling KVM: PPC: Book3S PR: Emulate PURR, SPURR and DSCR registers KVM: PPC: Book3S HV: Don't give the guest RW access to RO pages KVM: PPC: Book3S HV: Report correct HPT entry index when reading HPT ...
2 parents 8f536b7 + 352df1d commit d2ff4fc

34 files changed

Lines changed: 1279 additions & 229 deletions

‎Documentation/virtual/kvm/api.txt‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,6 +1773,7 @@ registers, find a list below:
17731773
PPC | KVM_REG_PPC_VPA_ADDR | 64
17741774
PPC | KVM_REG_PPC_VPA_SLB | 128
17751775
PPC | KVM_REG_PPC_VPA_DTL | 128
1776+
PPC | KVM_REG_PPC_EPCR | 32
17761777

17771778
4.69 KVM_GET_ONE_REG
17781779

@@ -2071,6 +2072,60 @@ KVM_S390_INT_EXTERNAL_CALL (vcpu) - sigp external call; source cpu in parm
20712072

20722073
Note that the vcpu ioctl is asynchronous to vcpu execution.
20732074

2075+
4.78 KVM_PPC_GET_HTAB_FD
2076+
2077+
Capability: KVM_CAP_PPC_HTAB_FD
2078+
Architectures: powerpc
2079+
Type: vm ioctl
2080+
Parameters: Pointer to struct kvm_get_htab_fd (in)
2081+
Returns: file descriptor number (>= 0) on success, -1 on error
2082+
2083+
This returns a file descriptor that can be used either to read out the
2084+
entries in the guest's hashed page table (HPT), or to write entries to
2085+
initialize the HPT. The returned fd can only be written to if the
2086+
KVM_GET_HTAB_WRITE bit is set in the flags field of the argument, and
2087+
can only be read if that bit is clear. The argument struct looks like
2088+
this:
2089+
2090+
/* For KVM_PPC_GET_HTAB_FD */
2091+
struct kvm_get_htab_fd {
2092+
__u64 flags;
2093+
__u64 start_index;
2094+
__u64 reserved[2];
2095+
};
2096+
2097+
/* Values for kvm_get_htab_fd.flags */
2098+
#define KVM_GET_HTAB_BOLTED_ONLY ((__u64)0x1)
2099+
#define KVM_GET_HTAB_WRITE ((__u64)0x2)
2100+
2101+
The `start_index' field gives the index in the HPT of the entry at
2102+
which to start reading. It is ignored when writing.
2103+
2104+
Reads on the fd will initially supply information about all
2105+
"interesting" HPT entries. Interesting entries are those with the
2106+
bolted bit set, if the KVM_GET_HTAB_BOLTED_ONLY bit is set, otherwise
2107+
all entries. When the end of the HPT is reached, the read() will
2108+
return. If read() is called again on the fd, it will start again from
2109+
the beginning of the HPT, but will only return HPT entries that have
2110+
changed since they were last read.
2111+
2112+
Data read or written is structured as a header (8 bytes) followed by a
2113+
series of valid HPT entries (16 bytes) each. The header indicates how
2114+
many valid HPT entries there are and how many invalid entries follow
2115+
the valid entries. The invalid entries are not represented explicitly
2116+
in the stream. The header format is:
2117+
2118+
struct kvm_get_htab_header {
2119+
__u32 index;
2120+
__u16 n_valid;
2121+
__u16 n_invalid;
2122+
};
2123+
2124+
Writes to the fd create HPT entries starting at the index given in the
2125+
header; first `n_valid' valid entries with contents from the data
2126+
written, then `n_invalid' invalid entries, invalidating any previously
2127+
valid entries found.
2128+
20742129

20752130
5. The kvm_run structure
20762131
------------------------

‎MAINTAINERS‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4253,6 +4253,7 @@ KERNEL VIRTUAL MACHINE (KVM) FOR POWERPC
42534253
M: Alexander Graf <agraf@suse.de>
42544254
L: kvm-ppc@vger.kernel.org
42554255
W: http://kvm.qumranet.com
4256+
T: git git://github.com/agraf/linux-2.6.git
42564257
S: Supported
42574258
F: arch/powerpc/include/asm/kvm*
42584259
F: arch/powerpc/kvm/

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ struct kvmppc_vcpu_book3s {
8181
u64 sdr1;
8282
u64 hior;
8383
u64 msr_mask;
84+
u64 purr_offset;
85+
u64 spurr_offset;
8486
#ifdef CONFIG_PPC_BOOK3S_32
8587
u32 vsid_pool[VSID_POOL_SIZE];
8688
u32 vsid_next;
@@ -157,8 +159,12 @@ extern void *kvmppc_pin_guest_page(struct kvm *kvm, unsigned long addr,
157159
extern void kvmppc_unpin_guest_page(struct kvm *kvm, void *addr);
158160
extern long kvmppc_virtmode_h_enter(struct kvm_vcpu *vcpu, unsigned long flags,
159161
long pte_index, unsigned long pteh, unsigned long ptel);
160-
extern long kvmppc_h_enter(struct kvm_vcpu *vcpu, unsigned long flags,
161-
long pte_index, unsigned long pteh, unsigned long ptel);
162+
extern long kvmppc_do_h_enter(struct kvm *kvm, unsigned long flags,
163+
long pte_index, unsigned long pteh, unsigned long ptel,
164+
pgd_t *pgdir, bool realmode, unsigned long *idx_ret);
165+
extern long kvmppc_do_h_remove(struct kvm *kvm, unsigned long flags,
166+
unsigned long pte_index, unsigned long avpn,
167+
unsigned long *hpret);
162168
extern long kvmppc_hv_get_dirty_log(struct kvm *kvm,
163169
struct kvm_memory_slot *memslot, unsigned long *map);
164170

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ extern int kvm_hpt_order; /* order of preallocated HPTs */
5050
#define HPTE_V_HVLOCK 0x40UL
5151
#define HPTE_V_ABSENT 0x20UL
5252

53+
/*
54+
* We use this bit in the guest_rpte field of the revmap entry
55+
* to indicate a modified HPTE.
56+
*/
57+
#define HPTE_GR_MODIFIED (1ul << 62)
58+
59+
/* These bits are reserved in the guest view of the HPTE */
60+
#define HPTE_GR_RESERVED HPTE_GR_MODIFIED
61+
5362
static inline long try_lock_hpte(unsigned long *hpte, unsigned long bits)
5463
{
5564
unsigned long tmp, old;
@@ -237,4 +246,26 @@ static inline bool slot_is_aligned(struct kvm_memory_slot *memslot,
237246
return !(memslot->base_gfn & mask) && !(memslot->npages & mask);
238247
}
239248

249+
/*
250+
* This works for 4k, 64k and 16M pages on POWER7,
251+
* and 4k and 16M pages on PPC970.
252+
*/
253+
static inline unsigned long slb_pgsize_encoding(unsigned long psize)
254+
{
255+
unsigned long senc = 0;
256+
257+
if (psize > 0x1000) {
258+
senc = SLB_VSID_L;
259+
if (psize == 0x10000)
260+
senc |= SLB_VSID_LP_01;
261+
}
262+
return senc;
263+
}
264+
265+
static inline int is_vrma_hpte(unsigned long hpte_v)
266+
{
267+
return (hpte_v & ~0xffffffUL) ==
268+
(HPTE_V_1TB_SEG | (VRMA_VSID << (40 - 16)));
269+
}
270+
240271
#endif /* __ASM_KVM_BOOK3S_64_H__ */

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* there are no exceptions for which we fall through directly to
1818
* the normal host handler.
1919
*
20+
* 32-bit host
2021
* Expected inputs (normal exceptions):
2122
* SCRATCH0 = saved r10
2223
* r10 = thread struct
@@ -33,6 +34,30 @@
3334
* *(r8 + GPR9) = saved r9
3435
* *(r8 + GPR10) = saved r10 (r10 not yet clobbered)
3536
* *(r8 + GPR11) = saved r11
37+
*
38+
* 64-bit host
39+
* Expected inputs (GEN/GDBELL/DBG/MC exception types):
40+
* r10 = saved CR
41+
* r13 = PACA_POINTER
42+
* *(r13 + PACA_EX##type + EX_R10) = saved r10
43+
* *(r13 + PACA_EX##type + EX_R11) = saved r11
44+
* SPRN_SPRG_##type##_SCRATCH = saved r13
45+
*
46+
* Expected inputs (CRIT exception type):
47+
* r10 = saved CR
48+
* r13 = PACA_POINTER
49+
* *(r13 + PACA_EX##type + EX_R10) = saved r10
50+
* *(r13 + PACA_EX##type + EX_R11) = saved r11
51+
* *(r13 + PACA_EX##type + EX_R13) = saved r13
52+
*
53+
* Expected inputs (TLB exception type):
54+
* r10 = saved CR
55+
* r13 = PACA_POINTER
56+
* *(r13 + PACA_EX##type + EX_TLB_R10) = saved r10
57+
* *(r13 + PACA_EX##type + EX_TLB_R11) = saved r11
58+
* SPRN_SPRG_GEN_SCRATCH = saved r13
59+
*
60+
* Only the bolted version of TLB miss exception handlers is supported now.
3661
*/
3762
.macro DO_KVM intno srr1
3863
#ifdef CONFIG_KVM_BOOKE_HV

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,12 @@ struct kvm_arch {
246246
int using_mmu_notifiers;
247247
u32 hpt_order;
248248
atomic_t vcpus_running;
249+
u32 online_vcores;
249250
unsigned long hpt_npte;
250251
unsigned long hpt_mask;
252+
atomic_t hpte_mod_interest;
251253
spinlock_t slot_phys_lock;
252-
unsigned short last_vcpu[NR_CPUS];
254+
cpumask_t need_tlb_flush;
253255
struct kvmppc_vcore *vcores[KVM_MAX_VCORES];
254256
struct kvmppc_linear_info *hpt_li;
255257
#endif /* CONFIG_KVM_BOOK3S_64_HV */
@@ -274,6 +276,7 @@ struct kvmppc_vcore {
274276
int nap_count;
275277
int napping_threads;
276278
u16 pcpu;
279+
u16 last_cpu;
277280
u8 vcore_state;
278281
u8 in_guest;
279282
struct list_head runnable_threads;
@@ -403,13 +406,18 @@ struct kvm_vcpu_arch {
403406
u32 host_mas4;
404407
u32 host_mas6;
405408
u32 shadow_epcr;
406-
u32 epcr;
407409
u32 shadow_msrp;
408410
u32 eplc;
409411
u32 epsc;
410412
u32 oldpir;
411413
#endif
412414

415+
#if defined(CONFIG_BOOKE)
416+
#if defined(CONFIG_KVM_BOOKE_HV) || defined(CONFIG_64BIT)
417+
u32 epcr;
418+
#endif
419+
#endif
420+
413421
#ifdef CONFIG_PPC_BOOK3S
414422
/* For Gekko paired singles */
415423
u32 qpr[32];
@@ -522,7 +530,6 @@ struct kvm_vcpu_arch {
522530
u64 dec_jiffies;
523531
u64 dec_expires;
524532
unsigned long pending_exceptions;
525-
u16 last_cpu;
526533
u8 ceded;
527534
u8 prodded;
528535
u32 last_inst;

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ extern void kvmppc_bookehv_exit(void);
164164

165165
extern int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu);
166166

167+
extern int kvm_vm_ioctl_get_htab_fd(struct kvm *kvm, struct kvm_get_htab_fd *);
168+
167169
/*
168170
* Cuts out inst bits with ordering according to spec.
169171
* That means the leftmost bit is zero. All given bits are included.
@@ -293,4 +295,25 @@ static inline void kvmppc_lazy_ee_enable(void)
293295
#endif
294296
}
295297

298+
static inline ulong kvmppc_get_ea_indexed(struct kvm_vcpu *vcpu, int ra, int rb)
299+
{
300+
ulong ea;
301+
ulong msr_64bit = 0;
302+
303+
ea = kvmppc_get_gpr(vcpu, rb);
304+
if (ra)
305+
ea += kvmppc_get_gpr(vcpu, ra);
306+
307+
#if defined(CONFIG_PPC_BOOK3E_64)
308+
msr_64bit = MSR_CM;
309+
#elif defined(CONFIG_PPC_BOOK3S_64)
310+
msr_64bit = MSR_SF;
311+
#endif
312+
313+
if (!(vcpu->arch.shared->msr & msr_64bit))
314+
ea = (uint32_t)ea;
315+
316+
return ea;
317+
}
318+
296319
#endif /* __POWERPC_KVM_PPC_H__ */

‎arch/powerpc/include/asm/mmu-book3e.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
#define MAS1_TSIZE_SHIFT 7
6060
#define MAS1_TSIZE(x) (((x) << MAS1_TSIZE_SHIFT) & MAS1_TSIZE_MASK)
6161

62-
#define MAS2_EPN 0xFFFFF000
62+
#define MAS2_EPN (~0xFFFUL)
6363
#define MAS2_X0 0x00000040
6464
#define MAS2_X1 0x00000020
6565
#define MAS2_W 0x00000010

‎arch/powerpc/include/asm/mmu-hash64.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@ extern char initial_stab[];
121121
#define PP_RXRX 3 /* Supervisor read, User read */
122122
#define PP_RXXX (HPTE_R_PP0 | 2) /* Supervisor read, user none */
123123

124+
/* Fields for tlbiel instruction in architecture 2.06 */
125+
#define TLBIEL_INVAL_SEL_MASK 0xc00 /* invalidation selector */
126+
#define TLBIEL_INVAL_PAGE 0x000 /* invalidate a single page */
127+
#define TLBIEL_INVAL_SET_LPID 0x800 /* invalidate a set for current LPID */
128+
#define TLBIEL_INVAL_SET 0xc00 /* invalidate a set for all LPIDs */
129+
#define TLBIEL_INVAL_SET_MASK 0xfff000 /* set number to inval. */
130+
#define TLBIEL_INVAL_SET_SHIFT 12
131+
132+
#define POWER7_TLB_SETS 128 /* # sets in POWER7 TLB */
133+
124134
#ifndef __ASSEMBLY__
125135

126136
struct hash_pte {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@
518518
#define SRR1_WS_DEEPER 0x00020000 /* Some resources not maintained */
519519
#define SRR1_WS_DEEP 0x00010000 /* All resources maintained */
520520
#define SRR1_PROGFPE 0x00100000 /* Floating Point Enabled */
521+
#define SRR1_PROGILL 0x00080000 /* Illegal instruction */
521522
#define SRR1_PROGPRIV 0x00040000 /* Privileged instruction */
522523
#define SRR1_PROGTRAP 0x00020000 /* Trap */
523524
#define SRR1_PROGADDR 0x00010000 /* SRR0 contains subsequent addr */

0 commit comments

Comments
 (0)