mirror of https://gitee.com/openkylin/linux.git
KVM: s390: vSIE (nested virtualization) feature for 4.8 (kvm/next)
With an updated QEMU this allows to create nested KVM guests (KVM under KVM) on s390. s390 memory management changes from Martin Schwidefsky or acked by Martin. One common code memory management change (pageref) acked by Andrew Morton. The feature has to be enabled with the nested medule parameter. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (GNU/Linux) iQIcBAABAgAGBQJXaS0XAAoJEBF7vIC1phx8rqMP/3EUiQbD/seIbkc2xqdApbZX xEDu6215f84N3KsLlZC/z/PhoxZ9z+GrHu+p2DqgnoMyDMj3C32s0OVecdxrE2+H pdaEY2ju8rjnY2P4hHzAfdWhdZtwsgdMIX8qDesQjcz4Z1QdOBXymEUpV7d35E/O WYqZw6EY6aOB338XKPaD03ITC+us/dW75ctPvqRzh5EKjjIMeOATonyGx0oHi14s qXRK1tfq8OegJGzioW5hOIlUkawycNu5+uIRjyoxzLuEPjn68Bomfi6W7Mak0BIc v8kEylFgMvSHKy0mWXCZsxj3hD6kNUzlJ+gRYFCiVWvdw6ywFzQiHP2nwLApg7Op 2a5S4wzQ3FIhA8u0k7JQBUncJggRZByitm4DerezHCZzKI9QimYrcKp2HWBQtI+0 12VC9/A0qyy2mKvTlgaDS4SQnPV2P6ztrLgORgK6F9TPq4w8mMYxG9Nz6neea6Po cotjEtqZivKNno1MOUzAg3jsrTMy4O4ktS0e8JSog2pDRHIrMiqCOcq1B0cRGK6P 8UmcpkK6yiEgCCbtqEU3QhcIMY6srTC6xArCjuieTY9v6EtBWAioRXuHRkVhs8xR HkEdlWlYTXeGpqcR2cCrUzEzUKdVmyTmnIVtoy/FfRfKEY02fHhiEIS3orqXoc4y +/yPsoGVxt8lMFs3/E8Y =ubb/ -----END PGP SIGNATURE----- Merge tag 'kvm-s390-next-4.8-2' of git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux into HEAD KVM: s390: vSIE (nested virtualization) feature for 4.8 (kvm/next) With an updated QEMU this allows to create nested KVM guests (KVM under KVM) on s390. s390 memory management changes from Martin Schwidefsky or acked by Martin. One common code memory management change (pageref) acked by Andrew Morton. The feature has to be enabled with the nested medule parameter.
This commit is contained in:
commit
8ff7b95647
|
@ -10,14 +10,25 @@
|
|||
|
||||
/**
|
||||
* struct gmap_struct - guest address space
|
||||
* @list: list head for the mm->context gmap list
|
||||
* @crst_list: list of all crst tables used in the guest address space
|
||||
* @mm: pointer to the parent mm_struct
|
||||
* @guest_to_host: radix tree with guest to host address translation
|
||||
* @host_to_guest: radix tree with pointer to segment table entries
|
||||
* @guest_table_lock: spinlock to protect all entries in the guest page table
|
||||
* @ref_count: reference counter for the gmap structure
|
||||
* @table: pointer to the page directory
|
||||
* @asce: address space control element for gmap page table
|
||||
* @pfault_enabled: defines if pfaults are applicable for the guest
|
||||
* @host_to_rmap: radix tree with gmap_rmap lists
|
||||
* @children: list of shadow gmap structures
|
||||
* @pt_list: list of all page tables used in the shadow guest address space
|
||||
* @shadow_lock: spinlock to protect the shadow gmap list
|
||||
* @parent: pointer to the parent gmap for shadow guest address spaces
|
||||
* @orig_asce: ASCE for which the shadow page table has been created
|
||||
* @edat_level: edat level to be used for the shadow translation
|
||||
* @removed: flag to indicate if a shadow guest address space has been removed
|
||||
* @initialized: flag to indicate if a shadow guest address space can be used
|
||||
*/
|
||||
struct gmap {
|
||||
struct list_head list;
|
||||
|
@ -26,26 +37,64 @@ struct gmap {
|
|||
struct radix_tree_root guest_to_host;
|
||||
struct radix_tree_root host_to_guest;
|
||||
spinlock_t guest_table_lock;
|
||||
atomic_t ref_count;
|
||||
unsigned long *table;
|
||||
unsigned long asce;
|
||||
unsigned long asce_end;
|
||||
void *private;
|
||||
bool pfault_enabled;
|
||||
/* Additional data for shadow guest address spaces */
|
||||
struct radix_tree_root host_to_rmap;
|
||||
struct list_head children;
|
||||
struct list_head pt_list;
|
||||
spinlock_t shadow_lock;
|
||||
struct gmap *parent;
|
||||
unsigned long orig_asce;
|
||||
int edat_level;
|
||||
bool removed;
|
||||
bool initialized;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct gmap_rmap - reverse mapping for shadow page table entries
|
||||
* @next: pointer to next rmap in the list
|
||||
* @raddr: virtual rmap address in the shadow guest address space
|
||||
*/
|
||||
struct gmap_rmap {
|
||||
struct gmap_rmap *next;
|
||||
unsigned long raddr;
|
||||
};
|
||||
|
||||
#define gmap_for_each_rmap(pos, head) \
|
||||
for (pos = (head); pos; pos = pos->next)
|
||||
|
||||
#define gmap_for_each_rmap_safe(pos, n, head) \
|
||||
for (pos = (head); n = pos ? pos->next : NULL, pos; pos = n)
|
||||
|
||||
/**
|
||||
* struct gmap_notifier - notify function block for page invalidation
|
||||
* @notifier_call: address of callback function
|
||||
*/
|
||||
struct gmap_notifier {
|
||||
struct list_head list;
|
||||
void (*notifier_call)(struct gmap *gmap, unsigned long gaddr);
|
||||
struct rcu_head rcu;
|
||||
void (*notifier_call)(struct gmap *gmap, unsigned long start,
|
||||
unsigned long end);
|
||||
};
|
||||
|
||||
struct gmap *gmap_alloc(struct mm_struct *mm, unsigned long limit);
|
||||
void gmap_free(struct gmap *gmap);
|
||||
static inline int gmap_is_shadow(struct gmap *gmap)
|
||||
{
|
||||
return !!gmap->parent;
|
||||
}
|
||||
|
||||
struct gmap *gmap_create(struct mm_struct *mm, unsigned long limit);
|
||||
void gmap_remove(struct gmap *gmap);
|
||||
struct gmap *gmap_get(struct gmap *gmap);
|
||||
void gmap_put(struct gmap *gmap);
|
||||
|
||||
void gmap_enable(struct gmap *gmap);
|
||||
void gmap_disable(struct gmap *gmap);
|
||||
struct gmap *gmap_get_enabled(void);
|
||||
int gmap_map_segment(struct gmap *gmap, unsigned long from,
|
||||
unsigned long to, unsigned long len);
|
||||
int gmap_unmap_segment(struct gmap *gmap, unsigned long to, unsigned long len);
|
||||
|
@ -57,8 +106,29 @@ void gmap_discard(struct gmap *, unsigned long from, unsigned long to);
|
|||
void __gmap_zap(struct gmap *, unsigned long gaddr);
|
||||
void gmap_unlink(struct mm_struct *, unsigned long *table, unsigned long vmaddr);
|
||||
|
||||
void gmap_register_ipte_notifier(struct gmap_notifier *);
|
||||
void gmap_unregister_ipte_notifier(struct gmap_notifier *);
|
||||
int gmap_ipte_notify(struct gmap *, unsigned long start, unsigned long len);
|
||||
int gmap_read_table(struct gmap *gmap, unsigned long gaddr, unsigned long *val);
|
||||
|
||||
struct gmap *gmap_shadow(struct gmap *parent, unsigned long asce,
|
||||
int edat_level);
|
||||
int gmap_shadow_valid(struct gmap *sg, unsigned long asce, int edat_level);
|
||||
int gmap_shadow_r2t(struct gmap *sg, unsigned long saddr, unsigned long r2t,
|
||||
int fake);
|
||||
int gmap_shadow_r3t(struct gmap *sg, unsigned long saddr, unsigned long r3t,
|
||||
int fake);
|
||||
int gmap_shadow_sgt(struct gmap *sg, unsigned long saddr, unsigned long sgt,
|
||||
int fake);
|
||||
int gmap_shadow_pgt(struct gmap *sg, unsigned long saddr, unsigned long pgt,
|
||||
int fake);
|
||||
int gmap_shadow_pgt_lookup(struct gmap *sg, unsigned long saddr,
|
||||
unsigned long *pgt, int *dat_protection, int *fake);
|
||||
int gmap_shadow_page(struct gmap *sg, unsigned long saddr, pte_t pte);
|
||||
|
||||
void gmap_register_pte_notifier(struct gmap_notifier *);
|
||||
void gmap_unregister_pte_notifier(struct gmap_notifier *);
|
||||
void gmap_pte_notify(struct mm_struct *, unsigned long addr, pte_t *,
|
||||
unsigned long bits);
|
||||
|
||||
int gmap_mprotect_notify(struct gmap *, unsigned long start,
|
||||
unsigned long len, int prot);
|
||||
|
||||
#endif /* _ASM_S390_GMAP_H */
|
||||
|
|
|
@ -145,7 +145,7 @@ struct kvm_s390_sie_block {
|
|||
__u64 cputm; /* 0x0028 */
|
||||
__u64 ckc; /* 0x0030 */
|
||||
__u64 epoch; /* 0x0038 */
|
||||
__u8 reserved40[4]; /* 0x0040 */
|
||||
__u32 svcc; /* 0x0040 */
|
||||
#define LCTL_CR0 0x8000
|
||||
#define LCTL_CR6 0x0200
|
||||
#define LCTL_CR9 0x0040
|
||||
|
@ -167,6 +167,9 @@ struct kvm_s390_sie_block {
|
|||
#define ICPT_INST 0x04
|
||||
#define ICPT_PROGI 0x08
|
||||
#define ICPT_INSTPROGI 0x0C
|
||||
#define ICPT_EXTINT 0x14
|
||||
#define ICPT_VALIDITY 0x20
|
||||
#define ICPT_STOP 0x28
|
||||
#define ICPT_OPEREXC 0x2C
|
||||
#define ICPT_PARTEXEC 0x38
|
||||
#define ICPT_IOINST 0x40
|
||||
|
@ -226,7 +229,7 @@ struct kvm_s390_sie_block {
|
|||
__u8 reserved1e6[2]; /* 0x01e6 */
|
||||
__u64 itdba; /* 0x01e8 */
|
||||
__u64 riccbd; /* 0x01f0 */
|
||||
__u8 reserved1f8[8]; /* 0x01f8 */
|
||||
__u64 gvrd; /* 0x01f8 */
|
||||
} __attribute__((packed));
|
||||
|
||||
struct kvm_s390_itdb {
|
||||
|
@ -281,6 +284,7 @@ struct kvm_vcpu_stat {
|
|||
u32 instruction_stsi;
|
||||
u32 instruction_stfl;
|
||||
u32 instruction_tprot;
|
||||
u32 instruction_sie;
|
||||
u32 instruction_essa;
|
||||
u32 instruction_sthyi;
|
||||
u32 instruction_sigp_sense;
|
||||
|
@ -545,12 +549,16 @@ struct kvm_guestdbg_info_arch {
|
|||
|
||||
struct kvm_vcpu_arch {
|
||||
struct kvm_s390_sie_block *sie_block;
|
||||
/* if vsie is active, currently executed shadow sie control block */
|
||||
struct kvm_s390_sie_block *vsie_block;
|
||||
unsigned int host_acrs[NUM_ACRS];
|
||||
struct fpu host_fpregs;
|
||||
struct kvm_s390_local_interrupt local_int;
|
||||
struct hrtimer ckc_timer;
|
||||
struct kvm_s390_pgm_info pgm;
|
||||
struct gmap *gmap;
|
||||
/* backup location for the currently enabled gmap when scheduled out */
|
||||
struct gmap *enabled_gmap;
|
||||
struct kvm_guestdbg_info_arch guestdbg;
|
||||
unsigned long pfault_token;
|
||||
unsigned long pfault_select;
|
||||
|
@ -635,6 +643,14 @@ struct sie_page2 {
|
|||
u8 reserved900[0x1000 - 0x900]; /* 0x0900 */
|
||||
} __packed;
|
||||
|
||||
struct kvm_s390_vsie {
|
||||
struct mutex mutex;
|
||||
struct radix_tree_root addr_to_page;
|
||||
int page_count;
|
||||
int next;
|
||||
struct page *pages[KVM_MAX_VCPUS];
|
||||
};
|
||||
|
||||
struct kvm_arch{
|
||||
void *sca;
|
||||
int use_esca;
|
||||
|
@ -659,6 +675,7 @@ struct kvm_arch{
|
|||
struct sie_page2 *sie_page2;
|
||||
struct kvm_s390_cpu_model model;
|
||||
struct kvm_s390_crypto crypto;
|
||||
struct kvm_s390_vsie vsie;
|
||||
u64 epoch;
|
||||
/* subset of available cpu features enabled by user space */
|
||||
DECLARE_BITMAP(cpu_feat, KVM_S390_VM_CPU_FEAT_NR_BITS);
|
||||
|
|
|
@ -8,8 +8,9 @@ typedef struct {
|
|||
cpumask_t cpu_attach_mask;
|
||||
atomic_t attach_count;
|
||||
unsigned int flush_mm;
|
||||
spinlock_t list_lock;
|
||||
spinlock_t pgtable_lock;
|
||||
struct list_head pgtable_list;
|
||||
spinlock_t gmap_lock;
|
||||
struct list_head gmap_list;
|
||||
unsigned long asce;
|
||||
unsigned long asce_limit;
|
||||
|
@ -23,8 +24,10 @@ typedef struct {
|
|||
} mm_context_t;
|
||||
|
||||
#define INIT_MM_CONTEXT(name) \
|
||||
.context.list_lock = __SPIN_LOCK_UNLOCKED(name.context.list_lock), \
|
||||
.context.pgtable_lock = \
|
||||
__SPIN_LOCK_UNLOCKED(name.context.pgtable_lock), \
|
||||
.context.pgtable_list = LIST_HEAD_INIT(name.context.pgtable_list), \
|
||||
.context.gmap_lock = __SPIN_LOCK_UNLOCKED(name.context.gmap_lock), \
|
||||
.context.gmap_list = LIST_HEAD_INIT(name.context.gmap_list),
|
||||
|
||||
static inline int tprot(unsigned long addr)
|
||||
|
|
|
@ -15,8 +15,9 @@
|
|||
static inline int init_new_context(struct task_struct *tsk,
|
||||
struct mm_struct *mm)
|
||||
{
|
||||
spin_lock_init(&mm->context.list_lock);
|
||||
spin_lock_init(&mm->context.pgtable_lock);
|
||||
INIT_LIST_HEAD(&mm->context.pgtable_list);
|
||||
spin_lock_init(&mm->context.gmap_lock);
|
||||
INIT_LIST_HEAD(&mm->context.gmap_list);
|
||||
cpumask_clear(&mm->context.cpu_attach_mask);
|
||||
atomic_set(&mm->context.attach_count, 0);
|
||||
|
|
|
@ -147,6 +147,8 @@ static inline int devmem_is_allowed(unsigned long pfn)
|
|||
#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
|
||||
#define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
|
||||
#define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
|
||||
#define pfn_to_virt(pfn) __va((pfn) << PAGE_SHIFT)
|
||||
#define page_to_virt(page) pfn_to_virt(page_to_pfn(page))
|
||||
|
||||
#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | \
|
||||
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
|
||||
|
|
|
@ -19,8 +19,10 @@ unsigned long *crst_table_alloc(struct mm_struct *);
|
|||
void crst_table_free(struct mm_struct *, unsigned long *);
|
||||
|
||||
unsigned long *page_table_alloc(struct mm_struct *);
|
||||
struct page *page_table_alloc_pgste(struct mm_struct *mm);
|
||||
void page_table_free(struct mm_struct *, unsigned long *);
|
||||
void page_table_free_rcu(struct mmu_gather *, unsigned long *, unsigned long);
|
||||
void page_table_free_pgste(struct page *page);
|
||||
extern int page_table_allocate_pgste;
|
||||
|
||||
static inline void clear_table(unsigned long *s, unsigned long val, size_t n)
|
||||
|
|
|
@ -256,6 +256,7 @@ static inline int is_module_addr(void *addr)
|
|||
/* Bits in the region table entry */
|
||||
#define _REGION_ENTRY_ORIGIN ~0xfffUL/* region/segment table origin */
|
||||
#define _REGION_ENTRY_PROTECT 0x200 /* region protection bit */
|
||||
#define _REGION_ENTRY_OFFSET 0xc0 /* region table offset */
|
||||
#define _REGION_ENTRY_INVALID 0x20 /* invalid region table entry */
|
||||
#define _REGION_ENTRY_TYPE_MASK 0x0c /* region/segment table type mask */
|
||||
#define _REGION_ENTRY_TYPE_R1 0x0c /* region first table type */
|
||||
|
@ -327,6 +328,7 @@ static inline int is_module_addr(void *addr)
|
|||
#define PGSTE_GC_BIT 0x0002000000000000UL
|
||||
#define PGSTE_UC_BIT 0x0000800000000000UL /* user dirty (migration) */
|
||||
#define PGSTE_IN_BIT 0x0000400000000000UL /* IPTE notify bit */
|
||||
#define PGSTE_VSIE_BIT 0x0000200000000000UL /* ref'd in a shadow table */
|
||||
|
||||
/* Guest Page State used for virtualization */
|
||||
#define _PGSTE_GPS_ZERO 0x0000000080000000UL
|
||||
|
@ -885,10 +887,16 @@ static inline int ptep_set_access_flags(struct vm_area_struct *vma,
|
|||
void ptep_set_pte_at(struct mm_struct *mm, unsigned long addr,
|
||||
pte_t *ptep, pte_t entry);
|
||||
void ptep_set_notify(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
|
||||
void ptep_notify(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
|
||||
void ptep_notify(struct mm_struct *mm, unsigned long addr,
|
||||
pte_t *ptep, unsigned long bits);
|
||||
int ptep_force_prot(struct mm_struct *mm, unsigned long gaddr,
|
||||
pte_t *ptep, int prot, unsigned long bit);
|
||||
void ptep_zap_unused(struct mm_struct *mm, unsigned long addr,
|
||||
pte_t *ptep , int reset);
|
||||
void ptep_zap_key(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
|
||||
int ptep_shadow_pte(struct mm_struct *mm, unsigned long saddr,
|
||||
pte_t *sptep, pte_t *tptep, pte_t pte);
|
||||
void ptep_unshadow_pte(struct mm_struct *mm, unsigned long saddr, pte_t *ptep);
|
||||
|
||||
bool test_and_clear_guest_dirty(struct mm_struct *mm, unsigned long address);
|
||||
int set_guest_storage_key(struct mm_struct *mm, unsigned long addr,
|
||||
|
|
|
@ -109,6 +109,8 @@ struct thread_struct {
|
|||
unsigned long ksp; /* kernel stack pointer */
|
||||
mm_segment_t mm_segment;
|
||||
unsigned long gmap_addr; /* address of last gmap fault. */
|
||||
unsigned int gmap_write_flag; /* gmap fault write indication */
|
||||
unsigned int gmap_int_code; /* int code of last gmap fault */
|
||||
unsigned int gmap_pfault; /* signal of a pending guest pfault */
|
||||
struct per_regs per_user; /* User specified PER registers */
|
||||
struct per_event per_event; /* Cause of the last PER trap */
|
||||
|
|
|
@ -98,6 +98,18 @@ struct kvm_s390_vm_cpu_machine {
|
|||
|
||||
#define KVM_S390_VM_CPU_FEAT_NR_BITS 1024
|
||||
#define KVM_S390_VM_CPU_FEAT_ESOP 0
|
||||
#define KVM_S390_VM_CPU_FEAT_SIEF2 1
|
||||
#define KVM_S390_VM_CPU_FEAT_64BSCAO 2
|
||||
#define KVM_S390_VM_CPU_FEAT_SIIF 3
|
||||
#define KVM_S390_VM_CPU_FEAT_GPERE 4
|
||||
#define KVM_S390_VM_CPU_FEAT_GSLS 5
|
||||
#define KVM_S390_VM_CPU_FEAT_IB 6
|
||||
#define KVM_S390_VM_CPU_FEAT_CEI 7
|
||||
#define KVM_S390_VM_CPU_FEAT_IBS 8
|
||||
#define KVM_S390_VM_CPU_FEAT_SKEY 9
|
||||
#define KVM_S390_VM_CPU_FEAT_CMMA 10
|
||||
#define KVM_S390_VM_CPU_FEAT_PFMFI 11
|
||||
#define KVM_S390_VM_CPU_FEAT_SIGPIF 12
|
||||
struct kvm_s390_vm_cpu_feat {
|
||||
__u64 feat[16];
|
||||
};
|
||||
|
|
|
@ -12,6 +12,6 @@ common-objs = $(KVM)/kvm_main.o $(KVM)/eventfd.o $(KVM)/async_pf.o $(KVM)/irqch
|
|||
ccflags-y := -Ivirt/kvm -Iarch/s390/kvm
|
||||
|
||||
kvm-objs := $(common-objs) kvm-s390.o intercept.o interrupt.o priv.o sigp.o
|
||||
kvm-objs += diag.o gaccess.o guestdbg.o sthyi.o
|
||||
kvm-objs += diag.o gaccess.o guestdbg.o sthyi.o vsie.o
|
||||
|
||||
obj-$(CONFIG_KVM) += kvm.o
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <linux/vmalloc.h>
|
||||
#include <linux/err.h>
|
||||
#include <asm/pgtable.h>
|
||||
#include <asm/gmap.h>
|
||||
#include "kvm-s390.h"
|
||||
#include "gaccess.h"
|
||||
#include <asm/switch_to.h>
|
||||
|
@ -946,3 +947,241 @@ int kvm_s390_check_low_addr_prot_real(struct kvm_vcpu *vcpu, unsigned long gra)
|
|||
return 0;
|
||||
return trans_exc(vcpu, PGM_PROTECTION, gra, 0, GACC_STORE, PROT_TYPE_LA);
|
||||
}
|
||||
|
||||
/**
|
||||
* kvm_s390_shadow_tables - walk the guest page table and create shadow tables
|
||||
* @sg: pointer to the shadow guest address space structure
|
||||
* @saddr: faulting address in the shadow gmap
|
||||
* @pgt: pointer to the page table address result
|
||||
* @fake: pgt references contiguous guest memory block, not a pgtable
|
||||
*/
|
||||
static int kvm_s390_shadow_tables(struct gmap *sg, unsigned long saddr,
|
||||
unsigned long *pgt, int *dat_protection,
|
||||
int *fake)
|
||||
{
|
||||
struct gmap *parent;
|
||||
union asce asce;
|
||||
union vaddress vaddr;
|
||||
unsigned long ptr;
|
||||
int rc;
|
||||
|
||||
*fake = 0;
|
||||
*dat_protection = 0;
|
||||
parent = sg->parent;
|
||||
vaddr.addr = saddr;
|
||||
asce.val = sg->orig_asce;
|
||||
ptr = asce.origin * 4096;
|
||||
if (asce.r) {
|
||||
*fake = 1;
|
||||
asce.dt = ASCE_TYPE_REGION1;
|
||||
}
|
||||
switch (asce.dt) {
|
||||
case ASCE_TYPE_REGION1:
|
||||
if (vaddr.rfx01 > asce.tl && !asce.r)
|
||||
return PGM_REGION_FIRST_TRANS;
|
||||
break;
|
||||
case ASCE_TYPE_REGION2:
|
||||
if (vaddr.rfx)
|
||||
return PGM_ASCE_TYPE;
|
||||
if (vaddr.rsx01 > asce.tl)
|
||||
return PGM_REGION_SECOND_TRANS;
|
||||
break;
|
||||
case ASCE_TYPE_REGION3:
|
||||
if (vaddr.rfx || vaddr.rsx)
|
||||
return PGM_ASCE_TYPE;
|
||||
if (vaddr.rtx01 > asce.tl)
|
||||
return PGM_REGION_THIRD_TRANS;
|
||||
break;
|
||||
case ASCE_TYPE_SEGMENT:
|
||||
if (vaddr.rfx || vaddr.rsx || vaddr.rtx)
|
||||
return PGM_ASCE_TYPE;
|
||||
if (vaddr.sx01 > asce.tl)
|
||||
return PGM_SEGMENT_TRANSLATION;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (asce.dt) {
|
||||
case ASCE_TYPE_REGION1: {
|
||||
union region1_table_entry rfte;
|
||||
|
||||
if (*fake) {
|
||||
/* offset in 16EB guest memory block */
|
||||
ptr = ptr + ((unsigned long) vaddr.rsx << 53UL);
|
||||
rfte.val = ptr;
|
||||
goto shadow_r2t;
|
||||
}
|
||||
rc = gmap_read_table(parent, ptr + vaddr.rfx * 8, &rfte.val);
|
||||
if (rc)
|
||||
return rc;
|
||||
if (rfte.i)
|
||||
return PGM_REGION_FIRST_TRANS;
|
||||
if (rfte.tt != TABLE_TYPE_REGION1)
|
||||
return PGM_TRANSLATION_SPEC;
|
||||
if (vaddr.rsx01 < rfte.tf || vaddr.rsx01 > rfte.tl)
|
||||
return PGM_REGION_SECOND_TRANS;
|
||||
if (sg->edat_level >= 1)
|
||||
*dat_protection |= rfte.p;
|
||||
ptr = rfte.rto << 12UL;
|
||||
shadow_r2t:
|
||||
rc = gmap_shadow_r2t(sg, saddr, rfte.val, *fake);
|
||||
if (rc)
|
||||
return rc;
|
||||
/* fallthrough */
|
||||
}
|
||||
case ASCE_TYPE_REGION2: {
|
||||
union region2_table_entry rste;
|
||||
|
||||
if (*fake) {
|
||||
/* offset in 8PB guest memory block */
|
||||
ptr = ptr + ((unsigned long) vaddr.rtx << 42UL);
|
||||
rste.val = ptr;
|
||||
goto shadow_r3t;
|
||||
}
|
||||
rc = gmap_read_table(parent, ptr + vaddr.rsx * 8, &rste.val);
|
||||
if (rc)
|
||||
return rc;
|
||||
if (rste.i)
|
||||
return PGM_REGION_SECOND_TRANS;
|
||||
if (rste.tt != TABLE_TYPE_REGION2)
|
||||
return PGM_TRANSLATION_SPEC;
|
||||
if (vaddr.rtx01 < rste.tf || vaddr.rtx01 > rste.tl)
|
||||
return PGM_REGION_THIRD_TRANS;
|
||||
if (sg->edat_level >= 1)
|
||||
*dat_protection |= rste.p;
|
||||
ptr = rste.rto << 12UL;
|
||||
shadow_r3t:
|
||||
rste.p |= *dat_protection;
|
||||
rc = gmap_shadow_r3t(sg, saddr, rste.val, *fake);
|
||||
if (rc)
|
||||
return rc;
|
||||
/* fallthrough */
|
||||
}
|
||||
case ASCE_TYPE_REGION3: {
|
||||
union region3_table_entry rtte;
|
||||
|
||||
if (*fake) {
|
||||
/* offset in 4TB guest memory block */
|
||||
ptr = ptr + ((unsigned long) vaddr.sx << 31UL);
|
||||
rtte.val = ptr;
|
||||
goto shadow_sgt;
|
||||
}
|
||||
rc = gmap_read_table(parent, ptr + vaddr.rtx * 8, &rtte.val);
|
||||
if (rc)
|
||||
return rc;
|
||||
if (rtte.i)
|
||||
return PGM_REGION_THIRD_TRANS;
|
||||
if (rtte.tt != TABLE_TYPE_REGION3)
|
||||
return PGM_TRANSLATION_SPEC;
|
||||
if (rtte.cr && asce.p && sg->edat_level >= 2)
|
||||
return PGM_TRANSLATION_SPEC;
|
||||
if (rtte.fc && sg->edat_level >= 2) {
|
||||
*dat_protection |= rtte.fc0.p;
|
||||
*fake = 1;
|
||||
ptr = rtte.fc1.rfaa << 31UL;
|
||||
rtte.val = ptr;
|
||||
goto shadow_sgt;
|
||||
}
|
||||
if (vaddr.sx01 < rtte.fc0.tf || vaddr.sx01 > rtte.fc0.tl)
|
||||
return PGM_SEGMENT_TRANSLATION;
|
||||
if (sg->edat_level >= 1)
|
||||
*dat_protection |= rtte.fc0.p;
|
||||
ptr = rtte.fc0.sto << 12UL;
|
||||
shadow_sgt:
|
||||
rtte.fc0.p |= *dat_protection;
|
||||
rc = gmap_shadow_sgt(sg, saddr, rtte.val, *fake);
|
||||
if (rc)
|
||||
return rc;
|
||||
/* fallthrough */
|
||||
}
|
||||
case ASCE_TYPE_SEGMENT: {
|
||||
union segment_table_entry ste;
|
||||
|
||||
if (*fake) {
|
||||
/* offset in 2G guest memory block */
|
||||
ptr = ptr + ((unsigned long) vaddr.sx << 20UL);
|
||||
ste.val = ptr;
|
||||
goto shadow_pgt;
|
||||
}
|
||||
rc = gmap_read_table(parent, ptr + vaddr.sx * 8, &ste.val);
|
||||
if (rc)
|
||||
return rc;
|
||||
if (ste.i)
|
||||
return PGM_SEGMENT_TRANSLATION;
|
||||
if (ste.tt != TABLE_TYPE_SEGMENT)
|
||||
return PGM_TRANSLATION_SPEC;
|
||||
if (ste.cs && asce.p)
|
||||
return PGM_TRANSLATION_SPEC;
|
||||
*dat_protection |= ste.fc0.p;
|
||||
if (ste.fc && sg->edat_level >= 1) {
|
||||
*fake = 1;
|
||||
ptr = ste.fc1.sfaa << 20UL;
|
||||
ste.val = ptr;
|
||||
goto shadow_pgt;
|
||||
}
|
||||
ptr = ste.fc0.pto << 11UL;
|
||||
shadow_pgt:
|
||||
ste.fc0.p |= *dat_protection;
|
||||
rc = gmap_shadow_pgt(sg, saddr, ste.val, *fake);
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
/* Return the parent address of the page table */
|
||||
*pgt = ptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* kvm_s390_shadow_fault - handle fault on a shadow page table
|
||||
* @vcpu: virtual cpu
|
||||
* @sg: pointer to the shadow guest address space structure
|
||||
* @saddr: faulting address in the shadow gmap
|
||||
*
|
||||
* Returns: - 0 if the shadow fault was successfully resolved
|
||||
* - > 0 (pgm exception code) on exceptions while faulting
|
||||
* - -EAGAIN if the caller can retry immediately
|
||||
* - -EFAULT when accessing invalid guest addresses
|
||||
* - -ENOMEM if out of memory
|
||||
*/
|
||||
int kvm_s390_shadow_fault(struct kvm_vcpu *vcpu, struct gmap *sg,
|
||||
unsigned long saddr)
|
||||
{
|
||||
union vaddress vaddr;
|
||||
union page_table_entry pte;
|
||||
unsigned long pgt;
|
||||
int dat_protection, fake;
|
||||
int rc;
|
||||
|
||||
down_read(&sg->mm->mmap_sem);
|
||||
/*
|
||||
* We don't want any guest-2 tables to change - so the parent
|
||||
* tables/pointers we read stay valid - unshadowing is however
|
||||
* always possible - only guest_table_lock protects us.
|
||||
*/
|
||||
ipte_lock(vcpu);
|
||||
|
||||
rc = gmap_shadow_pgt_lookup(sg, saddr, &pgt, &dat_protection, &fake);
|
||||
if (rc)
|
||||
rc = kvm_s390_shadow_tables(sg, saddr, &pgt, &dat_protection,
|
||||
&fake);
|
||||
|
||||
vaddr.addr = saddr;
|
||||
if (fake) {
|
||||
/* offset in 1MB guest memory block */
|
||||
pte.val = pgt + ((unsigned long) vaddr.px << 12UL);
|
||||
goto shadow_page;
|
||||
}
|
||||
if (!rc)
|
||||
rc = gmap_read_table(sg->parent, pgt + vaddr.px * 8, &pte.val);
|
||||
if (!rc && pte.i)
|
||||
rc = PGM_PAGE_TRANSLATION;
|
||||
if (!rc && (pte.z || (pte.co && sg->edat_level < 1)))
|
||||
rc = PGM_TRANSLATION_SPEC;
|
||||
shadow_page:
|
||||
pte.p |= dat_protection;
|
||||
if (!rc)
|
||||
rc = gmap_shadow_page(sg, saddr, __pte(pte.val));
|
||||
ipte_unlock(vcpu);
|
||||
up_read(&sg->mm->mmap_sem);
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -361,4 +361,7 @@ void ipte_unlock(struct kvm_vcpu *vcpu);
|
|||
int ipte_lock_held(struct kvm_vcpu *vcpu);
|
||||
int kvm_s390_check_low_addr_prot_real(struct kvm_vcpu *vcpu, unsigned long gra);
|
||||
|
||||
int kvm_s390_shadow_fault(struct kvm_vcpu *vcpu, struct gmap *shadow,
|
||||
unsigned long saddr);
|
||||
|
||||
#endif /* __KVM_S390_GACCESS_H */
|
||||
|
|
|
@ -995,6 +995,11 @@ void kvm_s390_vcpu_wakeup(struct kvm_vcpu *vcpu)
|
|||
swake_up(&vcpu->wq);
|
||||
vcpu->stat.halt_wakeup++;
|
||||
}
|
||||
/*
|
||||
* The VCPU might not be sleeping but is executing the VSIE. Let's
|
||||
* kick it, so it leaves the SIE to process the request.
|
||||
*/
|
||||
kvm_s390_vsie_kick(vcpu);
|
||||
}
|
||||
|
||||
enum hrtimer_restart kvm_s390_idle_wakeup(struct hrtimer *timer)
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <linux/init.h>
|
||||
#include <linux/kvm.h>
|
||||
#include <linux/kvm_host.h>
|
||||
#include <linux/mman.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/random.h>
|
||||
#include <linux/slab.h>
|
||||
|
@ -98,6 +99,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
|
|||
{ "instruction_stfl", VCPU_STAT(instruction_stfl) },
|
||||
{ "instruction_tprot", VCPU_STAT(instruction_tprot) },
|
||||
{ "instruction_sthyi", VCPU_STAT(instruction_sthyi) },
|
||||
{ "instruction_sie", VCPU_STAT(instruction_sie) },
|
||||
{ "instruction_sigp_sense", VCPU_STAT(instruction_sigp_sense) },
|
||||
{ "instruction_sigp_sense_running", VCPU_STAT(instruction_sigp_sense_running) },
|
||||
{ "instruction_sigp_external_call", VCPU_STAT(instruction_sigp_external_call) },
|
||||
|
@ -123,6 +125,11 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
|
|||
{ NULL }
|
||||
};
|
||||
|
||||
/* allow nested virtualization in KVM (if enabled by user space) */
|
||||
static int nested;
|
||||
module_param(nested, int, S_IRUGO);
|
||||
MODULE_PARM_DESC(nested, "Nested virtualization support");
|
||||
|
||||
/* upper facilities limit for kvm */
|
||||
unsigned long kvm_s390_fac_list_mask[16] = {
|
||||
0xffe6000000000000UL,
|
||||
|
@ -141,6 +148,7 @@ static DECLARE_BITMAP(kvm_s390_available_cpu_feat, KVM_S390_VM_CPU_FEAT_NR_BITS)
|
|||
static struct kvm_s390_vm_cpu_subfunc kvm_s390_available_subfunc;
|
||||
|
||||
static struct gmap_notifier gmap_notifier;
|
||||
static struct gmap_notifier vsie_gmap_notifier;
|
||||
debug_info_t *kvm_s390_dbf;
|
||||
|
||||
/* Section: not file related */
|
||||
|
@ -150,7 +158,8 @@ int kvm_arch_hardware_enable(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void kvm_gmap_notifier(struct gmap *gmap, unsigned long address);
|
||||
static void kvm_gmap_notifier(struct gmap *gmap, unsigned long start,
|
||||
unsigned long end);
|
||||
|
||||
/*
|
||||
* This callback is executed during stop_machine(). All CPUs are therefore
|
||||
|
@ -172,6 +181,8 @@ static int kvm_clock_sync(struct notifier_block *notifier, unsigned long val,
|
|||
vcpu->arch.sie_block->epoch -= *delta;
|
||||
if (vcpu->arch.cputm_enabled)
|
||||
vcpu->arch.cputm_start += *delta;
|
||||
if (vcpu->arch.vsie_block)
|
||||
vcpu->arch.vsie_block->epoch -= *delta;
|
||||
}
|
||||
}
|
||||
return NOTIFY_OK;
|
||||
|
@ -184,7 +195,9 @@ static struct notifier_block kvm_clock_notifier = {
|
|||
int kvm_arch_hardware_setup(void)
|
||||
{
|
||||
gmap_notifier.notifier_call = kvm_gmap_notifier;
|
||||
gmap_register_ipte_notifier(&gmap_notifier);
|
||||
gmap_register_pte_notifier(&gmap_notifier);
|
||||
vsie_gmap_notifier.notifier_call = kvm_s390_vsie_gmap_notifier;
|
||||
gmap_register_pte_notifier(&vsie_gmap_notifier);
|
||||
atomic_notifier_chain_register(&s390_epoch_delta_notifier,
|
||||
&kvm_clock_notifier);
|
||||
return 0;
|
||||
|
@ -192,7 +205,8 @@ int kvm_arch_hardware_setup(void)
|
|||
|
||||
void kvm_arch_hardware_unsetup(void)
|
||||
{
|
||||
gmap_unregister_ipte_notifier(&gmap_notifier);
|
||||
gmap_unregister_pte_notifier(&gmap_notifier);
|
||||
gmap_unregister_pte_notifier(&vsie_gmap_notifier);
|
||||
atomic_notifier_chain_unregister(&s390_epoch_delta_notifier,
|
||||
&kvm_clock_notifier);
|
||||
}
|
||||
|
@ -250,6 +264,46 @@ static void kvm_s390_cpu_feat_init(void)
|
|||
|
||||
if (MACHINE_HAS_ESOP)
|
||||
allow_cpu_feat(KVM_S390_VM_CPU_FEAT_ESOP);
|
||||
/*
|
||||
* We need SIE support, ESOP (PROT_READ protection for gmap_shadow),
|
||||
* 64bit SCAO (SCA passthrough) and IDTE (for gmap_shadow unshadowing).
|
||||
*/
|
||||
if (!sclp.has_sief2 || !MACHINE_HAS_ESOP || !sclp.has_64bscao ||
|
||||
!test_facility(3) || !nested)
|
||||
return;
|
||||
allow_cpu_feat(KVM_S390_VM_CPU_FEAT_SIEF2);
|
||||
if (sclp.has_64bscao)
|
||||
allow_cpu_feat(KVM_S390_VM_CPU_FEAT_64BSCAO);
|
||||
if (sclp.has_siif)
|
||||
allow_cpu_feat(KVM_S390_VM_CPU_FEAT_SIIF);
|
||||
if (sclp.has_gpere)
|
||||
allow_cpu_feat(KVM_S390_VM_CPU_FEAT_GPERE);
|
||||
if (sclp.has_gsls)
|
||||
allow_cpu_feat(KVM_S390_VM_CPU_FEAT_GSLS);
|
||||
if (sclp.has_ib)
|
||||
allow_cpu_feat(KVM_S390_VM_CPU_FEAT_IB);
|
||||
if (sclp.has_cei)
|
||||
allow_cpu_feat(KVM_S390_VM_CPU_FEAT_CEI);
|
||||
if (sclp.has_ibs)
|
||||
allow_cpu_feat(KVM_S390_VM_CPU_FEAT_IBS);
|
||||
/*
|
||||
* KVM_S390_VM_CPU_FEAT_SKEY: Wrong shadow of PTE.I bits will make
|
||||
* all skey handling functions read/set the skey from the PGSTE
|
||||
* instead of the real storage key.
|
||||
*
|
||||
* KVM_S390_VM_CPU_FEAT_CMMA: Wrong shadow of PTE.I bits will make
|
||||
* pages being detected as preserved although they are resident.
|
||||
*
|
||||
* KVM_S390_VM_CPU_FEAT_PFMFI: Wrong shadow of PTE.I bits will
|
||||
* have the same effect as for KVM_S390_VM_CPU_FEAT_SKEY.
|
||||
*
|
||||
* For KVM_S390_VM_CPU_FEAT_SKEY, KVM_S390_VM_CPU_FEAT_CMMA and
|
||||
* KVM_S390_VM_CPU_FEAT_PFMFI, all PTE.I and PGSTE bits have to be
|
||||
* correctly shadowed. We can do that for the PGSTE but not for PTE.I.
|
||||
*
|
||||
* KVM_S390_VM_CPU_FEAT_SIGPIF: Wrong SCB addresses in the SCA. We
|
||||
* cannot easily shadow the SCA because of the ipte lock.
|
||||
*/
|
||||
}
|
||||
|
||||
int kvm_arch_init(void *opaque)
|
||||
|
@ -530,20 +584,20 @@ static int kvm_s390_set_mem_control(struct kvm *kvm, struct kvm_device_attr *att
|
|||
if (!new_limit)
|
||||
return -EINVAL;
|
||||
|
||||
/* gmap_alloc takes last usable address */
|
||||
/* gmap_create takes last usable address */
|
||||
if (new_limit != KVM_S390_NO_MEM_LIMIT)
|
||||
new_limit -= 1;
|
||||
|
||||
ret = -EBUSY;
|
||||
mutex_lock(&kvm->lock);
|
||||
if (!kvm->created_vcpus) {
|
||||
/* gmap_alloc will round the limit up */
|
||||
struct gmap *new = gmap_alloc(current->mm, new_limit);
|
||||
/* gmap_create will round the limit up */
|
||||
struct gmap *new = gmap_create(current->mm, new_limit);
|
||||
|
||||
if (!new) {
|
||||
ret = -ENOMEM;
|
||||
} else {
|
||||
gmap_free(kvm->arch.gmap);
|
||||
gmap_remove(kvm->arch.gmap);
|
||||
new->private = kvm;
|
||||
kvm->arch.gmap = new;
|
||||
ret = 0;
|
||||
|
@ -1392,7 +1446,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
|
|||
else
|
||||
kvm->arch.mem_limit = min_t(unsigned long, TASK_MAX_SIZE,
|
||||
sclp.hamax + 1);
|
||||
kvm->arch.gmap = gmap_alloc(current->mm, kvm->arch.mem_limit - 1);
|
||||
kvm->arch.gmap = gmap_create(current->mm, kvm->arch.mem_limit - 1);
|
||||
if (!kvm->arch.gmap)
|
||||
goto out_err;
|
||||
kvm->arch.gmap->private = kvm;
|
||||
|
@ -1404,6 +1458,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
|
|||
kvm->arch.epoch = 0;
|
||||
|
||||
spin_lock_init(&kvm->arch.start_stop_lock);
|
||||
kvm_s390_vsie_init(kvm);
|
||||
KVM_EVENT(3, "vm 0x%pK created by pid %u", kvm, current->pid);
|
||||
|
||||
return 0;
|
||||
|
@ -1425,7 +1480,7 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
|
|||
sca_del_vcpu(vcpu);
|
||||
|
||||
if (kvm_is_ucontrol(vcpu->kvm))
|
||||
gmap_free(vcpu->arch.gmap);
|
||||
gmap_remove(vcpu->arch.gmap);
|
||||
|
||||
if (vcpu->kvm->arch.use_cmma)
|
||||
kvm_s390_vcpu_unsetup_cmma(vcpu);
|
||||
|
@ -1458,16 +1513,17 @@ void kvm_arch_destroy_vm(struct kvm *kvm)
|
|||
debug_unregister(kvm->arch.dbf);
|
||||
free_page((unsigned long)kvm->arch.sie_page2);
|
||||
if (!kvm_is_ucontrol(kvm))
|
||||
gmap_free(kvm->arch.gmap);
|
||||
gmap_remove(kvm->arch.gmap);
|
||||
kvm_s390_destroy_adapters(kvm);
|
||||
kvm_s390_clear_float_irqs(kvm);
|
||||
kvm_s390_vsie_destroy(kvm);
|
||||
KVM_EVENT(3, "vm 0x%pK destroyed", kvm);
|
||||
}
|
||||
|
||||
/* Section: vcpu related */
|
||||
static int __kvm_ucontrol_vcpu_init(struct kvm_vcpu *vcpu)
|
||||
{
|
||||
vcpu->arch.gmap = gmap_alloc(current->mm, -1UL);
|
||||
vcpu->arch.gmap = gmap_create(current->mm, -1UL);
|
||||
if (!vcpu->arch.gmap)
|
||||
return -ENOMEM;
|
||||
vcpu->arch.gmap->private = vcpu->kvm;
|
||||
|
@ -1717,7 +1773,7 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
|
|||
|
||||
save_access_regs(vcpu->arch.host_acrs);
|
||||
restore_access_regs(vcpu->run->s.regs.acrs);
|
||||
gmap_enable(vcpu->arch.gmap);
|
||||
gmap_enable(vcpu->arch.enabled_gmap);
|
||||
atomic_or(CPUSTAT_RUNNING, &vcpu->arch.sie_block->cpuflags);
|
||||
if (vcpu->arch.cputm_enabled && !is_vcpu_idle(vcpu))
|
||||
__start_cpu_timer_accounting(vcpu);
|
||||
|
@ -1730,7 +1786,8 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
|
|||
if (vcpu->arch.cputm_enabled && !is_vcpu_idle(vcpu))
|
||||
__stop_cpu_timer_accounting(vcpu);
|
||||
atomic_andnot(CPUSTAT_RUNNING, &vcpu->arch.sie_block->cpuflags);
|
||||
gmap_disable(vcpu->arch.gmap);
|
||||
vcpu->arch.enabled_gmap = gmap_get_enabled();
|
||||
gmap_disable(vcpu->arch.enabled_gmap);
|
||||
|
||||
/* Save guest register state */
|
||||
save_fpu_regs();
|
||||
|
@ -1779,7 +1836,8 @@ void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
|
|||
vcpu->arch.gmap = vcpu->kvm->arch.gmap;
|
||||
sca_add_vcpu(vcpu);
|
||||
}
|
||||
|
||||
/* make vcpu_load load the right gmap on the first trigger */
|
||||
vcpu->arch.enabled_gmap = vcpu->arch.gmap;
|
||||
}
|
||||
|
||||
static void kvm_s390_vcpu_crypto_setup(struct kvm_vcpu *vcpu)
|
||||
|
@ -1976,16 +2034,25 @@ void kvm_s390_sync_request(int req, struct kvm_vcpu *vcpu)
|
|||
kvm_s390_vcpu_request(vcpu);
|
||||
}
|
||||
|
||||
static void kvm_gmap_notifier(struct gmap *gmap, unsigned long address)
|
||||
static void kvm_gmap_notifier(struct gmap *gmap, unsigned long start,
|
||||
unsigned long end)
|
||||
{
|
||||
int i;
|
||||
struct kvm *kvm = gmap->private;
|
||||
struct kvm_vcpu *vcpu;
|
||||
unsigned long prefix;
|
||||
int i;
|
||||
|
||||
if (gmap_is_shadow(gmap))
|
||||
return;
|
||||
if (start >= 1UL << 31)
|
||||
/* We are only interested in prefix pages */
|
||||
return;
|
||||
kvm_for_each_vcpu(i, vcpu, kvm) {
|
||||
/* match against both prefix pages */
|
||||
if (kvm_s390_get_prefix(vcpu) == (address & ~0x1000UL)) {
|
||||
VCPU_EVENT(vcpu, 2, "gmap notifier for %lx", address);
|
||||
prefix = kvm_s390_get_prefix(vcpu);
|
||||
if (prefix <= end && start <= prefix + 2*PAGE_SIZE - 1) {
|
||||
VCPU_EVENT(vcpu, 2, "gmap notifier for %lx-%lx",
|
||||
start, end);
|
||||
kvm_s390_sync_request(KVM_REQ_MMU_RELOAD, vcpu);
|
||||
}
|
||||
}
|
||||
|
@ -2264,16 +2331,16 @@ static int kvm_s390_handle_requests(struct kvm_vcpu *vcpu)
|
|||
return 0;
|
||||
/*
|
||||
* We use MMU_RELOAD just to re-arm the ipte notifier for the
|
||||
* guest prefix page. gmap_ipte_notify will wait on the ptl lock.
|
||||
* guest prefix page. gmap_mprotect_notify will wait on the ptl lock.
|
||||
* This ensures that the ipte instruction for this request has
|
||||
* already finished. We might race against a second unmapper that
|
||||
* wants to set the blocking bit. Lets just retry the request loop.
|
||||
*/
|
||||
if (kvm_check_request(KVM_REQ_MMU_RELOAD, vcpu)) {
|
||||
int rc;
|
||||
rc = gmap_ipte_notify(vcpu->arch.gmap,
|
||||
rc = gmap_mprotect_notify(vcpu->arch.gmap,
|
||||
kvm_s390_get_prefix(vcpu),
|
||||
PAGE_SIZE * 2);
|
||||
PAGE_SIZE * 2, PROT_WRITE);
|
||||
if (rc)
|
||||
return rc;
|
||||
goto retry;
|
||||
|
|
|
@ -56,7 +56,7 @@ static inline int is_vcpu_stopped(struct kvm_vcpu *vcpu)
|
|||
|
||||
static inline int is_vcpu_idle(struct kvm_vcpu *vcpu)
|
||||
{
|
||||
return atomic_read(&vcpu->arch.sie_block->cpuflags) & CPUSTAT_WAIT;
|
||||
return test_bit(vcpu->vcpu_id, vcpu->arch.local_int.float_int->idle_mask);
|
||||
}
|
||||
|
||||
static inline int kvm_is_ucontrol(struct kvm *kvm)
|
||||
|
@ -252,6 +252,14 @@ int kvm_s390_handle_stctl(struct kvm_vcpu *vcpu);
|
|||
int kvm_s390_handle_lctl(struct kvm_vcpu *vcpu);
|
||||
int kvm_s390_handle_eb(struct kvm_vcpu *vcpu);
|
||||
|
||||
/* implemented in vsie.c */
|
||||
int kvm_s390_handle_vsie(struct kvm_vcpu *vcpu);
|
||||
void kvm_s390_vsie_kick(struct kvm_vcpu *vcpu);
|
||||
void kvm_s390_vsie_gmap_notifier(struct gmap *gmap, unsigned long start,
|
||||
unsigned long end);
|
||||
void kvm_s390_vsie_init(struct kvm *kvm);
|
||||
void kvm_s390_vsie_destroy(struct kvm *kvm);
|
||||
|
||||
/* implemented in sigp.c */
|
||||
int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu);
|
||||
int kvm_s390_handle_sigp_pei(struct kvm_vcpu *vcpu);
|
||||
|
|
|
@ -719,6 +719,7 @@ static const intercept_handler_t b2_handlers[256] = {
|
|||
[0x10] = handle_set_prefix,
|
||||
[0x11] = handle_store_prefix,
|
||||
[0x12] = handle_store_cpu_address,
|
||||
[0x14] = kvm_s390_handle_vsie,
|
||||
[0x21] = handle_ipte_interlock,
|
||||
[0x29] = handle_iske,
|
||||
[0x2a] = handle_rrbe,
|
||||
|
|
|
@ -77,18 +77,18 @@ static int __sigp_conditional_emergency(struct kvm_vcpu *vcpu,
|
|||
const u64 psw_int_mask = PSW_MASK_IO | PSW_MASK_EXT;
|
||||
u16 p_asn, s_asn;
|
||||
psw_t *psw;
|
||||
u32 flags;
|
||||
bool idle;
|
||||
|
||||
flags = atomic_read(&dst_vcpu->arch.sie_block->cpuflags);
|
||||
idle = is_vcpu_idle(vcpu);
|
||||
psw = &dst_vcpu->arch.sie_block->gpsw;
|
||||
p_asn = dst_vcpu->arch.sie_block->gcr[4] & 0xffff; /* Primary ASN */
|
||||
s_asn = dst_vcpu->arch.sie_block->gcr[3] & 0xffff; /* Secondary ASN */
|
||||
|
||||
/* Inject the emergency signal? */
|
||||
if (!(flags & CPUSTAT_STOPPED)
|
||||
if (!is_vcpu_stopped(vcpu)
|
||||
|| (psw->mask & psw_int_mask) != psw_int_mask
|
||||
|| ((flags & CPUSTAT_WAIT) && psw->addr != 0)
|
||||
|| (!(flags & CPUSTAT_WAIT) && (asn == p_asn || asn == s_asn))) {
|
||||
|| (idle && psw->addr != 0)
|
||||
|| (!idle && (asn == p_asn || asn == s_asn))) {
|
||||
return __inject_sigp_emergency(vcpu, dst_vcpu);
|
||||
} else {
|
||||
*reg &= 0xffffffff00000000UL;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -418,6 +418,8 @@ static inline int do_exception(struct pt_regs *regs, int access)
|
|||
(struct gmap *) S390_lowcore.gmap : NULL;
|
||||
if (gmap) {
|
||||
current->thread.gmap_addr = address;
|
||||
current->thread.gmap_write_flag = !!(flags & FAULT_FLAG_WRITE);
|
||||
current->thread.gmap_int_code = regs->int_code & 0xffff;
|
||||
address = __gmap_translate(gmap, address);
|
||||
if (address == -EFAULT) {
|
||||
fault = VM_FAULT_BADMAP;
|
||||
|
|
1578
arch/s390/mm/gmap.c
1578
arch/s390/mm/gmap.c
File diff suppressed because it is too large
Load Diff
|
@ -137,6 +137,29 @@ static inline unsigned int atomic_xor_bits(atomic_t *v, unsigned int bits)
|
|||
return new;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PGSTE
|
||||
|
||||
struct page *page_table_alloc_pgste(struct mm_struct *mm)
|
||||
{
|
||||
struct page *page;
|
||||
unsigned long *table;
|
||||
|
||||
page = alloc_page(GFP_KERNEL|__GFP_REPEAT);
|
||||
if (page) {
|
||||
table = (unsigned long *) page_to_phys(page);
|
||||
clear_table(table, _PAGE_INVALID, PAGE_SIZE/2);
|
||||
clear_table(table + PTRS_PER_PTE, 0, PAGE_SIZE/2);
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
void page_table_free_pgste(struct page *page)
|
||||
{
|
||||
__free_page(page);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_PGSTE */
|
||||
|
||||
/*
|
||||
* page table entry allocation/free routines.
|
||||
*/
|
||||
|
@ -149,7 +172,7 @@ unsigned long *page_table_alloc(struct mm_struct *mm)
|
|||
/* Try to get a fragment of a 4K page as a 2K page table */
|
||||
if (!mm_alloc_pgste(mm)) {
|
||||
table = NULL;
|
||||
spin_lock_bh(&mm->context.list_lock);
|
||||
spin_lock_bh(&mm->context.pgtable_lock);
|
||||
if (!list_empty(&mm->context.pgtable_list)) {
|
||||
page = list_first_entry(&mm->context.pgtable_list,
|
||||
struct page, lru);
|
||||
|
@ -164,7 +187,7 @@ unsigned long *page_table_alloc(struct mm_struct *mm)
|
|||
list_del(&page->lru);
|
||||
}
|
||||
}
|
||||
spin_unlock_bh(&mm->context.list_lock);
|
||||
spin_unlock_bh(&mm->context.pgtable_lock);
|
||||
if (table)
|
||||
return table;
|
||||
}
|
||||
|
@ -187,9 +210,9 @@ unsigned long *page_table_alloc(struct mm_struct *mm)
|
|||
/* Return the first 2K fragment of the page */
|
||||
atomic_set(&page->_mapcount, 1);
|
||||
clear_table(table, _PAGE_INVALID, PAGE_SIZE);
|
||||
spin_lock_bh(&mm->context.list_lock);
|
||||
spin_lock_bh(&mm->context.pgtable_lock);
|
||||
list_add(&page->lru, &mm->context.pgtable_list);
|
||||
spin_unlock_bh(&mm->context.list_lock);
|
||||
spin_unlock_bh(&mm->context.pgtable_lock);
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
@ -203,13 +226,13 @@ void page_table_free(struct mm_struct *mm, unsigned long *table)
|
|||
if (!mm_alloc_pgste(mm)) {
|
||||
/* Free 2K page table fragment of a 4K page */
|
||||
bit = (__pa(table) & ~PAGE_MASK)/(PTRS_PER_PTE*sizeof(pte_t));
|
||||
spin_lock_bh(&mm->context.list_lock);
|
||||
spin_lock_bh(&mm->context.pgtable_lock);
|
||||
mask = atomic_xor_bits(&page->_mapcount, 1U << bit);
|
||||
if (mask & 3)
|
||||
list_add(&page->lru, &mm->context.pgtable_list);
|
||||
else
|
||||
list_del(&page->lru);
|
||||
spin_unlock_bh(&mm->context.list_lock);
|
||||
spin_unlock_bh(&mm->context.pgtable_lock);
|
||||
if (mask != 0)
|
||||
return;
|
||||
}
|
||||
|
@ -235,13 +258,13 @@ void page_table_free_rcu(struct mmu_gather *tlb, unsigned long *table,
|
|||
return;
|
||||
}
|
||||
bit = (__pa(table) & ~PAGE_MASK) / (PTRS_PER_PTE*sizeof(pte_t));
|
||||
spin_lock_bh(&mm->context.list_lock);
|
||||
spin_lock_bh(&mm->context.pgtable_lock);
|
||||
mask = atomic_xor_bits(&page->_mapcount, 0x11U << bit);
|
||||
if (mask & 3)
|
||||
list_add_tail(&page->lru, &mm->context.pgtable_list);
|
||||
else
|
||||
list_del(&page->lru);
|
||||
spin_unlock_bh(&mm->context.list_lock);
|
||||
spin_unlock_bh(&mm->context.pgtable_lock);
|
||||
table = (unsigned long *) (__pa(table) | (1U << bit));
|
||||
tlb_remove_table(tlb, table);
|
||||
}
|
||||
|
|
|
@ -179,14 +179,17 @@ static inline pgste_t pgste_set_pte(pte_t *ptep, pgste_t pgste, pte_t entry)
|
|||
return pgste;
|
||||
}
|
||||
|
||||
static inline pgste_t pgste_ipte_notify(struct mm_struct *mm,
|
||||
static inline pgste_t pgste_pte_notify(struct mm_struct *mm,
|
||||
unsigned long addr,
|
||||
pte_t *ptep, pgste_t pgste)
|
||||
{
|
||||
#ifdef CONFIG_PGSTE
|
||||
if (pgste_val(pgste) & PGSTE_IN_BIT) {
|
||||
pgste_val(pgste) &= ~PGSTE_IN_BIT;
|
||||
ptep_notify(mm, addr, ptep);
|
||||
unsigned long bits;
|
||||
|
||||
bits = pgste_val(pgste) & (PGSTE_IN_BIT | PGSTE_VSIE_BIT);
|
||||
if (bits) {
|
||||
pgste_val(pgste) ^= bits;
|
||||
ptep_notify(mm, addr, ptep, bits);
|
||||
}
|
||||
#endif
|
||||
return pgste;
|
||||
|
@ -199,7 +202,7 @@ static inline pgste_t ptep_xchg_start(struct mm_struct *mm,
|
|||
|
||||
if (mm_has_pgste(mm)) {
|
||||
pgste = pgste_get_lock(ptep);
|
||||
pgste = pgste_ipte_notify(mm, addr, ptep, pgste);
|
||||
pgste = pgste_pte_notify(mm, addr, ptep, pgste);
|
||||
}
|
||||
return pgste;
|
||||
}
|
||||
|
@ -414,6 +417,90 @@ void ptep_set_notify(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
|
|||
pgste_set_unlock(ptep, pgste);
|
||||
}
|
||||
|
||||
/**
|
||||
* ptep_force_prot - change access rights of a locked pte
|
||||
* @mm: pointer to the process mm_struct
|
||||
* @addr: virtual address in the guest address space
|
||||
* @ptep: pointer to the page table entry
|
||||
* @prot: indicates guest access rights: PROT_NONE, PROT_READ or PROT_WRITE
|
||||
* @bit: pgste bit to set (e.g. for notification)
|
||||
*
|
||||
* Returns 0 if the access rights were changed and -EAGAIN if the current
|
||||
* and requested access rights are incompatible.
|
||||
*/
|
||||
int ptep_force_prot(struct mm_struct *mm, unsigned long addr,
|
||||
pte_t *ptep, int prot, unsigned long bit)
|
||||
{
|
||||
pte_t entry;
|
||||
pgste_t pgste;
|
||||
int pte_i, pte_p;
|
||||
|
||||
pgste = pgste_get_lock(ptep);
|
||||
entry = *ptep;
|
||||
/* Check pte entry after all locks have been acquired */
|
||||
pte_i = pte_val(entry) & _PAGE_INVALID;
|
||||
pte_p = pte_val(entry) & _PAGE_PROTECT;
|
||||
if ((pte_i && (prot != PROT_NONE)) ||
|
||||
(pte_p && (prot & PROT_WRITE))) {
|
||||
pgste_set_unlock(ptep, pgste);
|
||||
return -EAGAIN;
|
||||
}
|
||||
/* Change access rights and set pgste bit */
|
||||
if (prot == PROT_NONE && !pte_i) {
|
||||
ptep_flush_direct(mm, addr, ptep);
|
||||
pgste = pgste_update_all(entry, pgste, mm);
|
||||
pte_val(entry) |= _PAGE_INVALID;
|
||||
}
|
||||
if (prot == PROT_READ && !pte_p) {
|
||||
ptep_flush_direct(mm, addr, ptep);
|
||||
pte_val(entry) &= ~_PAGE_INVALID;
|
||||
pte_val(entry) |= _PAGE_PROTECT;
|
||||
}
|
||||
pgste_val(pgste) |= bit;
|
||||
pgste = pgste_set_pte(ptep, pgste, entry);
|
||||
pgste_set_unlock(ptep, pgste);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ptep_shadow_pte(struct mm_struct *mm, unsigned long saddr,
|
||||
pte_t *sptep, pte_t *tptep, pte_t pte)
|
||||
{
|
||||
pgste_t spgste, tpgste;
|
||||
pte_t spte, tpte;
|
||||
int rc = -EAGAIN;
|
||||
|
||||
if (!(pte_val(*tptep) & _PAGE_INVALID))
|
||||
return 0; /* already shadowed */
|
||||
spgste = pgste_get_lock(sptep);
|
||||
spte = *sptep;
|
||||
if (!(pte_val(spte) & _PAGE_INVALID) &&
|
||||
!((pte_val(spte) & _PAGE_PROTECT) &&
|
||||
!(pte_val(pte) & _PAGE_PROTECT))) {
|
||||
pgste_val(spgste) |= PGSTE_VSIE_BIT;
|
||||
tpgste = pgste_get_lock(tptep);
|
||||
pte_val(tpte) = (pte_val(spte) & PAGE_MASK) |
|
||||
(pte_val(pte) & _PAGE_PROTECT);
|
||||
/* don't touch the storage key - it belongs to parent pgste */
|
||||
tpgste = pgste_set_pte(tptep, tpgste, tpte);
|
||||
pgste_set_unlock(tptep, tpgste);
|
||||
rc = 1;
|
||||
}
|
||||
pgste_set_unlock(sptep, spgste);
|
||||
return rc;
|
||||
}
|
||||
|
||||
void ptep_unshadow_pte(struct mm_struct *mm, unsigned long saddr, pte_t *ptep)
|
||||
{
|
||||
pgste_t pgste;
|
||||
|
||||
pgste = pgste_get_lock(ptep);
|
||||
/* notifier is called by the caller */
|
||||
ptep_flush_direct(mm, saddr, ptep);
|
||||
/* don't touch the storage key - it belongs to parent pgste */
|
||||
pgste = pgste_set_pte(ptep, pgste, __pte(_PAGE_INVALID));
|
||||
pgste_set_unlock(ptep, pgste);
|
||||
}
|
||||
|
||||
static void ptep_zap_swap_entry(struct mm_struct *mm, swp_entry_t entry)
|
||||
{
|
||||
if (!non_swap_entry(entry))
|
||||
|
@ -483,7 +570,7 @@ bool test_and_clear_guest_dirty(struct mm_struct *mm, unsigned long addr)
|
|||
pgste_val(pgste) &= ~PGSTE_UC_BIT;
|
||||
pte = *ptep;
|
||||
if (dirty && (pte_val(pte) & _PAGE_PRESENT)) {
|
||||
pgste = pgste_ipte_notify(mm, addr, ptep, pgste);
|
||||
pgste = pgste_pte_notify(mm, addr, ptep, pgste);
|
||||
__ptep_ipte(addr, ptep);
|
||||
if (MACHINE_HAS_ESOP || !(pte_val(pte) & _PAGE_WRITE))
|
||||
pte_val(pte) |= _PAGE_PROTECT;
|
||||
|
|
|
@ -124,6 +124,15 @@ static inline int page_ref_sub_and_test(struct page *page, int nr)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static inline int page_ref_inc_return(struct page *page)
|
||||
{
|
||||
int ret = atomic_inc_return(&page->_refcount);
|
||||
|
||||
if (page_ref_tracepoint_active(__tracepoint_page_ref_mod_and_return))
|
||||
__page_ref_mod_and_return(page, 1, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline int page_ref_dec_and_test(struct page *page)
|
||||
{
|
||||
int ret = atomic_dec_and_test(&page->_refcount);
|
||||
|
|
Loading…
Reference in New Issue