aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason J. Herne <jjherne@linux.vnet.ibm.com>2014-09-23 09:18:57 -0400
committerChristian Borntraeger <borntraeger@de.ibm.com>2014-11-28 07:58:48 -0500
commit9fcf93b5de063e5cadb95a7bd0130bf73edcd3b5 (patch)
tree5c3f3f03d464210dbd82c64b0b04a67eadadda21
parentda00fcbdac1b00bf33b71093047e975cc1f68779 (diff)
KVM: S390: Create helper function get_guest_storage_key
Define get_guest_storage_key which can be used to get the value of a guest storage key. This compliments the functionality provided by the helper function set_guest_storage_key. Both functions are needed for live migration of s390 guests that use storage keys. Signed-off-by: Jason J. Herne <jjherne@linux.vnet.ibm.com> Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
-rw-r--r--arch/s390/include/asm/pgalloc.h1
-rw-r--r--arch/s390/mm/pgtable.c39
2 files changed, 40 insertions, 0 deletions
diff --git a/arch/s390/include/asm/pgalloc.h b/arch/s390/include/asm/pgalloc.h
index d39a31c3cdf2..ede2eab42c17 100644
--- a/arch/s390/include/asm/pgalloc.h
+++ b/arch/s390/include/asm/pgalloc.h
@@ -26,6 +26,7 @@ void page_table_reset_pgste(struct mm_struct *, unsigned long, unsigned long,
26 bool init_skey); 26 bool init_skey);
27int set_guest_storage_key(struct mm_struct *mm, unsigned long addr, 27int set_guest_storage_key(struct mm_struct *mm, unsigned long addr,
28 unsigned long key, bool nq); 28 unsigned long key, bool nq);
29unsigned long get_guest_storage_key(struct mm_struct *mm, unsigned long addr);
29 30
30static inline void clear_table(unsigned long *s, unsigned long val, size_t n) 31static inline void clear_table(unsigned long *s, unsigned long val, size_t n)
31{ 32{
diff --git a/arch/s390/mm/pgtable.c b/arch/s390/mm/pgtable.c
index cfecc241f9a4..0b185857164a 100644
--- a/arch/s390/mm/pgtable.c
+++ b/arch/s390/mm/pgtable.c
@@ -980,6 +980,45 @@ retry:
980} 980}
981EXPORT_SYMBOL(set_guest_storage_key); 981EXPORT_SYMBOL(set_guest_storage_key);
982 982
983unsigned long get_guest_storage_key(struct mm_struct *mm, unsigned long addr)
984{
985 spinlock_t *ptl;
986 pgste_t pgste;
987 pte_t *ptep;
988 uint64_t physaddr;
989 unsigned long key = 0;
990
991 down_read(&mm->mmap_sem);
992 ptep = get_locked_pte(mm, addr, &ptl);
993 if (unlikely(!ptep)) {
994 up_read(&mm->mmap_sem);
995 return -EFAULT;
996 }
997 pgste = pgste_get_lock(ptep);
998
999 if (pte_val(*ptep) & _PAGE_INVALID) {
1000 key |= (pgste_val(pgste) & PGSTE_ACC_BITS) >> 56;
1001 key |= (pgste_val(pgste) & PGSTE_FP_BIT) >> 56;
1002 key |= (pgste_val(pgste) & PGSTE_GR_BIT) >> 48;
1003 key |= (pgste_val(pgste) & PGSTE_GC_BIT) >> 48;
1004 } else {
1005 physaddr = pte_val(*ptep) & PAGE_MASK;
1006 key = page_get_storage_key(physaddr);
1007
1008 /* Reflect guest's logical view, not physical */
1009 if (pgste_val(pgste) & PGSTE_GR_BIT)
1010 key |= _PAGE_REFERENCED;
1011 if (pgste_val(pgste) & PGSTE_GC_BIT)
1012 key |= _PAGE_CHANGED;
1013 }
1014
1015 pgste_set_unlock(ptep, pgste);
1016 pte_unmap_unlock(ptep, ptl);
1017 up_read(&mm->mmap_sem);
1018 return key;
1019}
1020EXPORT_SYMBOL(get_guest_storage_key);
1021
983#else /* CONFIG_PGSTE */ 1022#else /* CONFIG_PGSTE */
984 1023
985static inline int page_table_with_pgste(struct page *page) 1024static inline int page_table_with_pgste(struct page *page)