aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/include
diff options
context:
space:
mode:
authorPaul Mackerras <paulus@samba.org>2011-12-12 07:32:27 -0500
committerAvi Kivity <avi@redhat.com>2012-03-05 07:52:37 -0500
commit9d0ef5ea043d1242897d15c71bd1a15da79b4a5d (patch)
tree2847b3bd444b999f3c2a32d4cbb220d0e788e93a /arch/powerpc/include
parentda9d1d7f2875cc8c1ffbce8f3501d0b33f4e7a4d (diff)
KVM: PPC: Allow I/O mappings in memory slots
This provides for the case where userspace maps an I/O device into the address range of a memory slot using a VM_PFNMAP mapping. In that case, we work out the pfn from vma->vm_pgoff, and record the cache enable bits from vma->vm_page_prot in two low-order bits in the slot_phys array entries. Then, in kvmppc_h_enter() we check that the cache bits in the HPTE that the guest wants to insert match the cache bits in the slot_phys array entry. However, we do allow the guest to create what it thinks is a non-cacheable or write-through mapping to memory that is actually cacheable, so that we can use normal system memory as part of an emulated device later on. In that case the actual HPTE we insert is a cacheable HPTE. Signed-off-by: Paul Mackerras <paulus@samba.org> Signed-off-by: Alexander Graf <agraf@suse.de> Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/powerpc/include')
-rw-r--r--arch/powerpc/include/asm/kvm_book3s_64.h26
-rw-r--r--arch/powerpc/include/asm/kvm_host.h2
2 files changed, 28 insertions, 0 deletions
diff --git a/arch/powerpc/include/asm/kvm_book3s_64.h b/arch/powerpc/include/asm/kvm_book3s_64.h
index 10920f7a2b8d..18b590d261ff 100644
--- a/arch/powerpc/include/asm/kvm_book3s_64.h
+++ b/arch/powerpc/include/asm/kvm_book3s_64.h
@@ -113,6 +113,32 @@ static inline unsigned long hpte_page_size(unsigned long h, unsigned long l)
113 return 0; /* error */ 113 return 0; /* error */
114} 114}
115 115
116static inline int hpte_cache_flags_ok(unsigned long ptel, unsigned long io_type)
117{
118 unsigned int wimg = ptel & HPTE_R_WIMG;
119
120 /* Handle SAO */
121 if (wimg == (HPTE_R_W | HPTE_R_I | HPTE_R_M) &&
122 cpu_has_feature(CPU_FTR_ARCH_206))
123 wimg = HPTE_R_M;
124
125 if (!io_type)
126 return wimg == HPTE_R_M;
127
128 return (wimg & (HPTE_R_W | HPTE_R_I)) == io_type;
129}
130
131/* Return HPTE cache control bits corresponding to Linux pte bits */
132static inline unsigned long hpte_cache_bits(unsigned long pte_val)
133{
134#if _PAGE_NO_CACHE == HPTE_R_I && _PAGE_WRITETHRU == HPTE_R_W
135 return pte_val & (HPTE_R_W | HPTE_R_I);
136#else
137 return ((pte_val & _PAGE_NO_CACHE) ? HPTE_R_I : 0) +
138 ((pte_val & _PAGE_WRITETHRU) ? HPTE_R_W : 0);
139#endif
140}
141
116static inline bool slot_is_aligned(struct kvm_memory_slot *memslot, 142static inline bool slot_is_aligned(struct kvm_memory_slot *memslot,
117 unsigned long pagesize) 143 unsigned long pagesize)
118{ 144{
diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h
index 9252d5e3758d..243bc8038572 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -178,6 +178,8 @@ struct revmap_entry {
178 178
179/* Low-order bits in kvm->arch.slot_phys[][] */ 179/* Low-order bits in kvm->arch.slot_phys[][] */
180#define KVMPPC_PAGE_ORDER_MASK 0x1f 180#define KVMPPC_PAGE_ORDER_MASK 0x1f
181#define KVMPPC_PAGE_NO_CACHE HPTE_R_I /* 0x20 */
182#define KVMPPC_PAGE_WRITETHRU HPTE_R_W /* 0x40 */
181#define KVMPPC_GOT_PAGE 0x80 183#define KVMPPC_GOT_PAGE 0x80
182 184
183struct kvm_arch { 185struct kvm_arch {