KVM: s390: Updates for 6.2
Subsystems (7)
Janosch Frank
maintainerplease pull the following changes for 6.2:
- Second batch of the lazy destroy patches
- First batch of KVM changes for kernel virtual != physical address support
- Removal of a unused function
Notice:
There was a merge conflict in next with the kvm arm tree because of capability numbers.
Please only pull the tag, there's a vfio-ap patch on top that Christian needs for getting debug data only which shouldn't go upstream.
The following changes since commit 247f34f7b80357943234f93f247a1ae6b6c3a740:
Linux 6.1-rc2 (2022-10-23 15:27:33 -0700)
are available in the Git repository at:
https://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git tags/kvm-s390-next-6.2-1
for you to fetch changes up to 99b63f55dc514a357c2ecf25e9aab149879329f0:
KVM: s390: remove unused gisa_clear_ipm_gisc() function (2022-11-23 09:06:50 +0000)
----------------------------------------------------------------
Claudio Imbrenda (6):
KVM: s390: pv: asynchronous destroy for reboot
KVM: s390: pv: api documentation for asynchronous destroy
KVM: s390: pv: add KVM_CAP_S390_PROTECTED_ASYNC_DISABLE
KVM: s390: pv: avoid export before import if possible
KVM: s390: pv: support for Destroy fast UVC
KVM: s390: pv: module parameter to fence asynchronous destroy
Heiko Carstens (1):
KVM: s390: remove unused gisa_clear_ipm_gisc() function
Nico Boehr (8):
s390/mm: gmap: sort out physical vs virtual pointers usage s390/entry: sort out physical vs virtual pointers usage in sie64a
KVM: s390: sort out physical vs virtual pointers usage
KVM: s390: sida: sort out physical vs virtual pointers usage
KVM: s390: pv: sort out physical vs virtual pointers usage
KVM: s390: VSIE: sort out virtual/physical address in pin_guest_page s390/mm: fix virtual-physical address confusion for swiotlb s390/vfio-ap: GISA: sort out physical vs virtual pointers usage
Documentation/virt/kvm/api.rst | 41 +++- arch/s390/include/asm/kvm_host.h | 14 +- arch/s390/include/asm/mem_encrypt.h | 4 +- arch/s390/include/asm/stacktrace.h | 1 + arch/s390/include/asm/uv.h | 10 + arch/s390/kernel/asm-offsets.c | 1 + arch/s390/kernel/entry.S | 26 +- arch/s390/kernel/uv.c | 7 + arch/s390/kvm/intercept.c | 9 +- arch/s390/kvm/interrupt.c | 5 - arch/s390/kvm/kvm-s390.c | 111 ++++++--- arch/s390/kvm/kvm-s390.h | 8 +- arch/s390/kvm/priv.c | 3 +- arch/s390/kvm/pv.c | 359 ++++++++++++++++++++++++++-- arch/s390/kvm/vsie.c | 4 +- arch/s390/mm/gmap.c | 147 ++++++------ arch/s390/mm/init.c | 12 +- drivers/s390/crypto/vfio_ap_ops.c | 2 +- include/uapi/linux/kvm.h | 3 + 19 files changed, 604 insertions(+), 163 deletions(-)
Signature · 1 line
2.38.1
Janosch Frank
maintainer[GIT PULL 01/15] s390/mm: gmap: sort out physical vs virtual pointers usage
From: Nico Boehr <[email protected]>
Fix virtual vs physical address confusion (which currently are the same).
Message-Id: <[email protected]>
--- arch/s390/mm/gmap.c | 147 +++++++++++++++++++++++--------------------- 1 file changed, 76 insertions(+), 71 deletions(-)
arch/s390/mm/gmap.c +76 -71
@@ -72,7 +72,7 @@ static struct gmap *gmap_alloc(unsigned long limit) goto out_free; page->index =0 ;list_add (&page->lru, &gmap->crst_list); - table = (unsigned long *)page_to_phys (page); + table =page_to_virt (page);crst_table_init (table, etype); gmap->table = table; gmap->asce = atype | _ASCE_TABLE_LENGTH |
@@ -311,12 +311,12 @@ static int gmap_alloc_table(struct gmap *gmap, unsigned long *table, page =alloc_pages (GFP_KERNEL_ACCOUNT ,CRST_ALLOC_ORDER );if (!page)return -ENOMEM ; - new = (unsigned long *)page_to_phys (page); + new =page_to_virt (page);crst_table_init (new, init);spin_lock (&gmap->guest_table_lock);if (*table & _REGION_ENTRY_INVALID) {list_add (&page->lru, &gmap->crst_list); - *table = (unsigned long ) new | _REGION_ENTRY_LENGTH | + *table =__pa (new) | _REGION_ENTRY_LENGTH | (*table & _REGION_ENTRY_TYPE_MASK); page->index = gaddr; page =NULL ;
@@ -557,7 +557,7 @@ int __gmap_link(struct gmap *gmap, unsigned long gaddr, unsigned long vmaddr)gmap_alloc_table (gmap, table, _REGION2_ENTRY_EMPTY, gaddr & _REGION1_MASK)) return -ENOMEM; - table = (unsigned long *)(*table & _REGION_ENTRY_ORIGIN); + table =__va (*table & _REGION_ENTRY_ORIGIN); }if ((gmap->asce & _ASCE_TYPE_MASK) >= _ASCE_TYPE_REGION2) { table += (gaddr & _REGION2_INDEX) >> _REGION2_SHIFT;
@@ -565,7 +565,7 @@ int __gmap_link(struct gmap *gmap, unsigned long gaddr, unsigned long vmaddr)gmap_alloc_table (gmap, table, _REGION3_ENTRY_EMPTY, gaddr & _REGION2_MASK)) return -ENOMEM; - table = (unsigned long *)(*table & _REGION_ENTRY_ORIGIN); + table =__va (*table & _REGION_ENTRY_ORIGIN); }if ((gmap->asce & _ASCE_TYPE_MASK) >= _ASCE_TYPE_REGION3) { table += (gaddr & _REGION3_INDEX) >> _REGION3_SHIFT;
@@ -573,7 +573,7 @@ int __gmap_link(struct gmap *gmap, unsigned long gaddr, unsigned long vmaddr)gmap_alloc_table (gmap, table, _SEGMENT_ENTRY_EMPTY, gaddr & _REGION3_MASK)) return -ENOMEM; - table = (unsigned long *)(*table & _REGION_ENTRY_ORIGIN); + table =__va (*table & _REGION_ENTRY_ORIGIN); } table += (gaddr & _SEGMENT_INDEX) >> _SEGMENT_SHIFT;/* Walk the parent mm page table */
@@ -813,7 +813,7 @@ static inline unsigned long *gmap_table_walk(struct gmap *gmap,break ;if (*table & _REGION_ENTRY_INVALID)return NULL ; - table = (unsigned long *)(*table & _REGION_ENTRY_ORIGIN); + table =__va (*table & _REGION_ENTRY_ORIGIN); fallthrough;case _ASCE_TYPE_REGION2: table += (gaddr & _REGION2_INDEX) >> _REGION2_SHIFT;
@@ -821,7 +821,7 @@ static inline unsigned long *gmap_table_walk(struct gmap *gmap,break ;if (*table & _REGION_ENTRY_INVALID)return NULL ; - table = (unsigned long *)(*table & _REGION_ENTRY_ORIGIN); + table =__va (*table & _REGION_ENTRY_ORIGIN); fallthrough;case _ASCE_TYPE_REGION3: table += (gaddr & _REGION3_INDEX) >> _REGION3_SHIFT;
@@ -829,7 +829,7 @@ static inline unsigned long *gmap_table_walk(struct gmap *gmap,break ;if (*table & _REGION_ENTRY_INVALID)return NULL ; - table = (unsigned long *)(*table & _REGION_ENTRY_ORIGIN); + table =__va (*table & _REGION_ENTRY_ORIGIN); fallthrough;case _ASCE_TYPE_SEGMENT: table += (gaddr & _SEGMENT_INDEX) >> _SEGMENT_SHIFT;
@@ -837,7 +837,7 @@ static inline unsigned long *gmap_table_walk(struct gmap *gmap,break ;if (*table & _REGION_ENTRY_INVALID)return NULL ; - table = (unsigned long *)(*table & _SEGMENT_ENTRY_ORIGIN); + table =__va (*table & _SEGMENT_ENTRY_ORIGIN); table += (gaddr & _PAGE_INDEX) >> _PAGE_SHIFT; }return table;
@@ -1150,7 +1150,7 @@ int gmap_read_table(struct gmap *gmap, unsigned long gaddr, unsigned long *val)if (pte_present (pte) && (pte_val (pte) & _PAGE_READ)) { address =pte_val (pte) &PAGE_MASK ; address += gaddr & ~PAGE_MASK ; - *val = *(unsigned long *) address; + *val = *(unsigned long *)__va (address);set_pte (ptep,set_pte_bit (*ptep,__pgprot (_PAGE_YOUNG)));/* Do *NOT* clear the _PAGE_INVALID bit! */ rc =0 ;
@@ -1335,7 +1335,8 @@ static void __gmap_unshadow_pgt(struct gmap *sg, unsigned long raddr,*/ static void gmap_unshadow_pgt (struct gmap *sg,unsigned long raddr) { -unsigned long sto, *ste, *pgt; +unsigned long *ste; +phys_addr_t sto, pgt;struct page *page;BUG_ON (!gmap_is_shadow (sg));
@@ -1343,13 +1344,13 @@ static void gmap_unshadow_pgt(struct gmap *sg, unsigned long raddr)if (!ste || !(*ste & _SEGMENT_ENTRY_ORIGIN))return ;gmap_call_notifier (sg, raddr, raddr + _SEGMENT_SIZE -1 ); - sto = (unsigned long ) (ste - ((raddr & _SEGMENT_INDEX) >> _SEGMENT_SHIFT)); + sto =__pa (ste - ((raddr & _SEGMENT_INDEX) >> _SEGMENT_SHIFT));gmap_idte_one (sto | _ASCE_TYPE_SEGMENT, raddr); - pgt = (unsigned long *)(*ste & _SEGMENT_ENTRY_ORIGIN); + pgt = *ste & _SEGMENT_ENTRY_ORIGIN; *ste = _SEGMENT_ENTRY_EMPTY; -__gmap_unshadow_pgt (sg, raddr, pgt); +__gmap_unshadow_pgt (sg, raddr,__va (pgt));/* Free page table */ - page =pfn_to_page (__pa (pgt) >>PAGE_SHIFT ); + page =phys_to_page (pgt);list_del (&page->lru);page_table_free_pgste (page); }
@@ -1365,19 +1366,19 @@ static void gmap_unshadow_pgt(struct gmap *sg, unsigned long raddr)static void __gmap_unshadow_sgt (struct gmap *sg,unsigned long raddr,unsigned long *sgt) { -unsigned long *pgt;struct page *page; +phys_addr_t pgt;int i;BUG_ON (!gmap_is_shadow (sg));for (i =0 ; i < _CRST_ENTRIES; i++, raddr += _SEGMENT_SIZE) {if (!(sgt[i] & _SEGMENT_ENTRY_ORIGIN))continue ; - pgt = (unsigned long *)(sgt[i] & _REGION_ENTRY_ORIGIN); + pgt = sgt[i] & _REGION_ENTRY_ORIGIN; sgt[i] = _SEGMENT_ENTRY_EMPTY; -__gmap_unshadow_pgt (sg, raddr, pgt); +__gmap_unshadow_pgt (sg, raddr,__va (pgt));/* Free page table */ - page =pfn_to_page (__pa (pgt) >>PAGE_SHIFT ); + page =phys_to_page (pgt);list_del (&page->lru);page_table_free_pgste (page); }
@@ -1392,7 +1393,8 @@ static void __gmap_unshadow_sgt(struct gmap *sg, unsigned long raddr,*/ static void gmap_unshadow_sgt (struct gmap *sg,unsigned long raddr) { -unsigned long r3o, *r3e, *sgt; +unsigned long r3o, *r3e; +phys_addr_t sgt;struct page *page;BUG_ON (!gmap_is_shadow (sg));
@@ -1401,12 +1403,12 @@ static void gmap_unshadow_sgt(struct gmap *sg, unsigned long raddr)return ;gmap_call_notifier (sg, raddr, raddr + _REGION3_SIZE -1 ); r3o = (unsigned long ) (r3e - ((raddr & _REGION3_INDEX) >> _REGION3_SHIFT)); -gmap_idte_one (r3o | _ASCE_TYPE_REGION3, raddr); - sgt = (unsigned long *)(*r3e & _REGION_ENTRY_ORIGIN); +gmap_idte_one (__pa (r3o) | _ASCE_TYPE_REGION3, raddr); + sgt = *r3e & _REGION_ENTRY_ORIGIN; *r3e = _REGION3_ENTRY_EMPTY; -__gmap_unshadow_sgt (sg, raddr, sgt); +__gmap_unshadow_sgt (sg, raddr,__va (sgt));/* Free segment table */ - page =pfn_to_page (__pa (sgt) >>PAGE_SHIFT ); + page =phys_to_page (sgt);list_del (&page->lru);__free_pages (page,CRST_ALLOC_ORDER ); }
@@ -1422,19 +1424,19 @@ static void gmap_unshadow_sgt(struct gmap *sg, unsigned long raddr)static void __gmap_unshadow_r3t (struct gmap *sg,unsigned long raddr,unsigned long *r3t) { -unsigned long *sgt;struct page *page; +phys_addr_t sgt;int i;BUG_ON (!gmap_is_shadow (sg));for (i =0 ; i < _CRST_ENTRIES; i++, raddr += _REGION3_SIZE) {if (!(r3t[i] & _REGION_ENTRY_ORIGIN))continue ; - sgt = (unsigned long *)(r3t[i] & _REGION_ENTRY_ORIGIN); + sgt = r3t[i] & _REGION_ENTRY_ORIGIN; r3t[i] = _REGION3_ENTRY_EMPTY; -__gmap_unshadow_sgt (sg, raddr, sgt); +__gmap_unshadow_sgt (sg, raddr,__va (sgt));/* Free segment table */ - page =pfn_to_page (__pa (sgt) >>PAGE_SHIFT ); + page =phys_to_page (sgt);list_del (&page->lru);__free_pages (page,CRST_ALLOC_ORDER ); }
@@ -1449,7 +1451,8 @@ static void __gmap_unshadow_r3t(struct gmap *sg, unsigned long raddr,*/ static void gmap_unshadow_r3t (struct gmap *sg,unsigned long raddr) { -unsigned long r2o, *r2e, *r3t; +unsigned long r2o, *r2e; +phys_addr_t r3t;struct page *page;BUG_ON (!gmap_is_shadow (sg));
@@ -1458,12 +1461,12 @@ static void gmap_unshadow_r3t(struct gmap *sg, unsigned long raddr)return ;gmap_call_notifier (sg, raddr, raddr + _REGION2_SIZE -1 ); r2o = (unsigned long ) (r2e - ((raddr & _REGION2_INDEX) >> _REGION2_SHIFT)); -gmap_idte_one (r2o | _ASCE_TYPE_REGION2, raddr); - r3t = (unsigned long *)(*r2e & _REGION_ENTRY_ORIGIN); +gmap_idte_one (__pa (r2o) | _ASCE_TYPE_REGION2, raddr); + r3t = *r2e & _REGION_ENTRY_ORIGIN; *r2e = _REGION2_ENTRY_EMPTY; -__gmap_unshadow_r3t (sg, raddr, r3t); +__gmap_unshadow_r3t (sg, raddr,__va (r3t));/* Free region 3 table */ - page =pfn_to_page (__pa (r3t) >>PAGE_SHIFT ); + page =phys_to_page (r3t);list_del (&page->lru);__free_pages (page,CRST_ALLOC_ORDER ); }
@@ -1479,7 +1482,7 @@ static void gmap_unshadow_r3t(struct gmap *sg, unsigned long raddr)static void __gmap_unshadow_r2t (struct gmap *sg,unsigned long raddr,unsigned long *r2t) { -unsigned long *r3t; +phys_addr_t r3t;struct page *page;int i;
@@ -1487,11 +1490,11 @@ static void __gmap_unshadow_r2t(struct gmap *sg, unsigned long raddr,for (i =0 ; i < _CRST_ENTRIES; i++, raddr += _REGION2_SIZE) {if (!(r2t[i] & _REGION_ENTRY_ORIGIN))continue ; - r3t = (unsigned long *)(r2t[i] & _REGION_ENTRY_ORIGIN); + r3t = r2t[i] & _REGION_ENTRY_ORIGIN; r2t[i] = _REGION2_ENTRY_EMPTY; -__gmap_unshadow_r3t (sg, raddr, r3t); +__gmap_unshadow_r3t (sg, raddr,__va (r3t));/* Free region 3 table */ - page =pfn_to_page (__pa (r3t) >>PAGE_SHIFT ); + page =phys_to_page (r3t);list_del (&page->lru);__free_pages (page,CRST_ALLOC_ORDER ); }
@@ -1506,8 +1509,9 @@ static void __gmap_unshadow_r2t(struct gmap *sg, unsigned long raddr,*/ static void gmap_unshadow_r2t (struct gmap *sg,unsigned long raddr) { -unsigned long r1o, *r1e, *r2t; +unsigned long r1o, *r1e;struct page *page; +phys_addr_t r2t;BUG_ON (!gmap_is_shadow (sg)); r1e =gmap_table_walk (sg, raddr,4 );/* get region-1 pointer */
@@ -1515,12 +1519,12 @@ static void gmap_unshadow_r2t(struct gmap *sg, unsigned long raddr)return ;gmap_call_notifier (sg, raddr, raddr + _REGION1_SIZE -1 ); r1o = (unsigned long ) (r1e - ((raddr & _REGION1_INDEX) >> _REGION1_SHIFT)); -gmap_idte_one (r1o | _ASCE_TYPE_REGION1, raddr); - r2t = (unsigned long *)(*r1e & _REGION_ENTRY_ORIGIN); +gmap_idte_one (__pa (r1o) | _ASCE_TYPE_REGION1, raddr); + r2t = *r1e & _REGION_ENTRY_ORIGIN; *r1e = _REGION1_ENTRY_EMPTY; -__gmap_unshadow_r2t (sg, raddr, r2t); +__gmap_unshadow_r2t (sg, raddr,__va (r2t));/* Free region 2 table */ - page =pfn_to_page (__pa (r2t) >>PAGE_SHIFT ); + page =phys_to_page (r2t);list_del (&page->lru);__free_pages (page,CRST_ALLOC_ORDER ); }
@@ -1536,22 +1540,23 @@ static void gmap_unshadow_r2t(struct gmap *sg, unsigned long raddr)static void __gmap_unshadow_r1t (struct gmap *sg,unsigned long raddr,unsigned long *r1t) { -unsigned long asce, *r2t; +unsigned long asce;struct page *page; +phys_addr_t r2t;int i;BUG_ON (!gmap_is_shadow (sg)); - asce = (unsigned long ) r1t | _ASCE_TYPE_REGION1; + asce =__pa (r1t) | _ASCE_TYPE_REGION1;for (i =0 ; i < _CRST_ENTRIES; i++, raddr += _REGION1_SIZE) {if (!(r1t[i] & _REGION_ENTRY_ORIGIN))continue ; - r2t = (unsigned long *)(r1t[i] & _REGION_ENTRY_ORIGIN); -__gmap_unshadow_r2t (sg, raddr, r2t); + r2t = r1t[i] & _REGION_ENTRY_ORIGIN; +__gmap_unshadow_r2t (sg, raddr,__va (r2t));/* Clear entry and flush translation r1t -> r2t */ gmap_idte_one (asce, raddr); r1t[i] = _REGION1_ENTRY_EMPTY;/* Free region 2 table */ - page =pfn_to_page (__pa (r2t) >>PAGE_SHIFT ); + page =phys_to_page (r2t);list_del (&page->lru);__free_pages (page,CRST_ALLOC_ORDER ); }
@@ -1573,7 +1578,7 @@ static void gmap_unshadow(struct gmap *sg) sg->removed =1 ;gmap_call_notifier (sg,0 ,-1UL );gmap_flush_tlb (sg); - table = (unsigned long *)(sg->asce & _ASCE_ORIGIN); + table =__va (sg->asce & _ASCE_ORIGIN);switch (sg->asce & _ASCE_TYPE_MASK) {case _ASCE_TYPE_REGION1:__gmap_unshadow_r1t (sg,0 , table);
@@ -1748,7 +1753,8 @@ int gmap_shadow_r2t(struct gmap *sg, unsigned long saddr, unsigned long r2t, int fake) {unsigned long raddr, origin, offset, len; -unsigned long *s_r2t, *table; +unsigned long *table; +phys_addr_t s_r2t;struct page *page;int rc;
@@ -1760,7 +1766,7 @@ int gmap_shadow_r2t(struct gmap *sg, unsigned long saddr, unsigned long r2t, page->index = r2t & _REGION_ENTRY_ORIGIN;if (fake) page->index |=GMAP_SHADOW_FAKE_TABLE ; - s_r2t = (unsigned long *)page_to_phys (page); + s_r2t =page_to_phys (page);/* Install shadow region second table */ spin_lock (&sg->guest_table_lock); table =gmap_table_walk (sg, saddr,4 );/* get region-1 pointer */
@@ -1775,9 +1781,9 @@ int gmap_shadow_r2t(struct gmap *sg, unsigned long saddr, unsigned long r2t, rc = -EAGAIN ;/* Race with shadow */ goto out_free; } -crst_table_init (s_r2t, _REGION2_ENTRY_EMPTY); +crst_table_init (__va (s_r2t), _REGION2_ENTRY_EMPTY);/* mark as invalid as long as the parent table is not protected */ - *table = (unsigned long ) s_r2t | _REGION_ENTRY_LENGTH | + *table = s_r2t | _REGION_ENTRY_LENGTH | _REGION_ENTRY_TYPE_R1 | _REGION_ENTRY_INVALID;if (sg->edat_level >=1 ) *table |= (r2t & _REGION_ENTRY_PROTECT);
@@ -1798,8 +1804,7 @@ int gmap_shadow_r2t(struct gmap *sg, unsigned long saddr, unsigned long r2t,spin_lock (&sg->guest_table_lock);if (!rc) { table =gmap_table_walk (sg, saddr,4 ); -if (!table || (*table & _REGION_ENTRY_ORIGIN) != - (unsigned long ) s_r2t) +if (!table || (*table & _REGION_ENTRY_ORIGIN) != s_r2t) rc = -EAGAIN ;/* Race with unshadow */ else *table &= ~_REGION_ENTRY_INVALID;
@@ -1832,7 +1837,8 @@ int gmap_shadow_r3t(struct gmap *sg, unsigned long saddr, unsigned long r3t, int fake) {unsigned long raddr, origin, offset, len; -unsigned long *s_r3t, *table; +unsigned long *table; +phys_addr_t s_r3t;struct page *page;int rc;
@@ -1844,7 +1850,7 @@ int gmap_shadow_r3t(struct gmap *sg, unsigned long saddr, unsigned long r3t, page->index = r3t & _REGION_ENTRY_ORIGIN;if (fake) page->index |=GMAP_SHADOW_FAKE_TABLE ; - s_r3t = (unsigned long *)page_to_phys (page); + s_r3t =page_to_phys (page);/* Install shadow region second table */ spin_lock (&sg->guest_table_lock); table =gmap_table_walk (sg, saddr,3 );/* get region-2 pointer */
@@ -1859,9 +1865,9 @@ int gmap_shadow_r3t(struct gmap *sg, unsigned long saddr, unsigned long r3t, rc = -EAGAIN ;/* Race with shadow */ goto out_free; } -crst_table_init (s_r3t, _REGION3_ENTRY_EMPTY); +crst_table_init (__va (s_r3t), _REGION3_ENTRY_EMPTY);/* mark as invalid as long as the parent table is not protected */ - *table = (unsigned long ) s_r3t | _REGION_ENTRY_LENGTH | + *table = s_r3t | _REGION_ENTRY_LENGTH | _REGION_ENTRY_TYPE_R2 | _REGION_ENTRY_INVALID;if (sg->edat_level >=1 ) *table |= (r3t & _REGION_ENTRY_PROTECT);
@@ -1882,8 +1888,7 @@ int gmap_shadow_r3t(struct gmap *sg, unsigned long saddr, unsigned long r3t,spin_lock (&sg->guest_table_lock);if (!rc) { table =gmap_table_walk (sg, saddr,3 ); -if (!table || (*table & _REGION_ENTRY_ORIGIN) != - (unsigned long ) s_r3t) +if (!table || (*table & _REGION_ENTRY_ORIGIN) != s_r3t) rc = -EAGAIN ;/* Race with unshadow */ else *table &= ~_REGION_ENTRY_INVALID;
@@ -1916,7 +1921,8 @@ int gmap_shadow_sgt(struct gmap *sg, unsigned long saddr, unsigned long sgt, int fake) {unsigned long raddr, origin, offset, len; -unsigned long *s_sgt, *table; +unsigned long *table; +phys_addr_t s_sgt;struct page *page;int rc;
@@ -1928,7 +1934,7 @@ int gmap_shadow_sgt(struct gmap *sg, unsigned long saddr, unsigned long sgt, page->index = sgt & _REGION_ENTRY_ORIGIN;if (fake) page->index |=GMAP_SHADOW_FAKE_TABLE ; - s_sgt = (unsigned long *)page_to_phys (page); + s_sgt =page_to_phys (page);/* Install shadow region second table */ spin_lock (&sg->guest_table_lock); table =gmap_table_walk (sg, saddr,2 );/* get region-3 pointer */
@@ -1943,9 +1949,9 @@ int gmap_shadow_sgt(struct gmap *sg, unsigned long saddr, unsigned long sgt, rc = -EAGAIN ;/* Race with shadow */ goto out_free; } -crst_table_init (s_sgt, _SEGMENT_ENTRY_EMPTY); +crst_table_init (__va (s_sgt), _SEGMENT_ENTRY_EMPTY);/* mark as invalid as long as the parent table is not protected */ - *table = (unsigned long ) s_sgt | _REGION_ENTRY_LENGTH | + *table = s_sgt | _REGION_ENTRY_LENGTH | _REGION_ENTRY_TYPE_R3 | _REGION_ENTRY_INVALID;if (sg->edat_level >=1 ) *table |= sgt & _REGION_ENTRY_PROTECT;
@@ -1966,8 +1972,7 @@ int gmap_shadow_sgt(struct gmap *sg, unsigned long saddr, unsigned long sgt,spin_lock (&sg->guest_table_lock);if (!rc) { table =gmap_table_walk (sg, saddr,2 ); -if (!table || (*table & _REGION_ENTRY_ORIGIN) != - (unsigned long ) s_sgt) +if (!table || (*table & _REGION_ENTRY_ORIGIN) != s_sgt) rc = -EAGAIN ;/* Race with unshadow */ else *table &= ~_REGION_ENTRY_INVALID;
@@ -2040,8 +2045,9 @@ int gmap_shadow_pgt(struct gmap *sg, unsigned long saddr, unsigned long pgt, int fake) {unsigned long raddr, origin; -unsigned long *s_pgt, *table; +unsigned long *table;struct page *page; +phys_addr_t s_pgt;int rc;BUG_ON (!gmap_is_shadow (sg) || (pgt & _SEGMENT_ENTRY_LARGE));
@@ -2052,7 +2058,7 @@ int gmap_shadow_pgt(struct gmap *sg, unsigned long saddr, unsigned long pgt, page->index = pgt & _SEGMENT_ENTRY_ORIGIN;if (fake) page->index |=GMAP_SHADOW_FAKE_TABLE ; - s_pgt = (unsigned long *)page_to_phys (page); + s_pgt =page_to_phys (page);/* Install shadow page table */ spin_lock (&sg->guest_table_lock); table =gmap_table_walk (sg, saddr,1 );/* get segment pointer */
@@ -2085,8 +2091,7 @@ int gmap_shadow_pgt(struct gmap *sg, unsigned long saddr, unsigned long pgt,spin_lock (&sg->guest_table_lock);if (!rc) { table =gmap_table_walk (sg, saddr,1 ); -if (!table || (*table & _SEGMENT_ENTRY_ORIGIN) != - (unsigned long ) s_pgt) +if (!table || (*table & _SEGMENT_ENTRY_ORIGIN) != s_pgt) rc = -EAGAIN ;/* Race with unshadow */ else *table &= ~_SEGMENT_ENTRY_INVALID;
Signature · 1 line
2.38.1
Janosch Frank
maintainer[GIT PULL 03/15] KVM: s390: sort out physical vs virtual pointers usage
In reply to Janosch FrankFrom: Nico Boehr <[email protected]>
Fix virtual vs physical address confusion (which currently are the same).
Message-Id: <[email protected]>
--- arch/s390/include/asm/kvm_host.h | 1 + arch/s390/kvm/intercept.c | 2 +- arch/s390/kvm/kvm-s390.c | 44 ++++++++++++++++++-------------- arch/s390/kvm/kvm-s390.h | 5 ++-- 4 files changed, 30 insertions(+), 22 deletions(-)
arch/s390/include/asm/kvm_host.h +1 -0
@@ -276,6 +276,7 @@ struct kvm_s390_sie_block {#define ECB3_AES 0x04#define ECB3_RI 0x01__u8 ecb3;/* 0x0063 */ +#define ESCA_SCAOL_MASK ~0x3fU__u32 scaol;/* 0x0064 */ __u8 sdf;/* 0x0068 */ __u8 epdx;/* 0x0069 */
arch/s390/kvm/intercept.c +1 -1
@@ -217,7 +217,7 @@ static int handle_itdb(struct kvm_vcpu *vcpu)return 0 ;if (current->thread.per_flags &PER_FLAG_NO_TE )return 0 ; - itdb = (struct kvm_s390_itdb *)vcpu->arch.sie_block->itdba; + itdb =phys_to_virt (vcpu->arch.sie_block->itdba); rc =write_guest_lc (vcpu, __LC_PGM_TDB, itdb,sizeof (*itdb));if (rc)return rc;
arch/s390/kvm/kvm-s390.c +25 -19
105 lines not on this page · raw message
arch/s390/kvm/kvm-s390.h +3 -2
@@ -23,7 +23,8 @@/* Transactional Memory Execution related macros */ #define IS_TE_ENABLED (vcpu) ((vcpu->arch.sie_block->ecb & ECB_TE))#define TDB_FORMAT1 1 -#define IS_ITDB_VALID (vcpu) ((*(char *)vcpu->arch.sie_block->itdba == TDB_FORMAT1)) +#define IS_ITDB_VALID (vcpu) \ + ((*(char *)phys_to_virt((vcpu)->arch.sie_block->itdba) == TDB_FORMAT1))extern debug_info_t *kvm_s390_dbf;extern debug_info_t *kvm_s390_dbf_uv;
@@ -233,7 +234,7 @@ static inline unsigned long kvm_s390_get_gfn_end(struct kvm_memslots *slots)static inline u32 kvm_s390_get_gisa_desc (struct kvm *kvm) { -u32 gd = (u32 )(u64 )kvm->arch.gisa_int.origin; +u32 gd =virt_to_phys (kvm->arch.gisa_int.origin);if (gd && sclp.has_gisaf) gd |=GISA_FORMAT1 ;
Signature · 1 line
2.38.1
Janosch Frank
maintainer[GIT PULL 02/15] s390/entry: sort out physical vs virtual pointers usage in sie64a
In reply to Janosch FrankFrom: Nico Boehr <[email protected]>
Fix virtual vs physical address confusion (which currently are the same).
sie_block is accessed in entry.S and passed it to hardware, which is why both its physical and virtual address are needed. To avoid every caller having to do the virtual-physical conversion, add a new function sie64a() which converts the virtual address to physical.
Message-Id: <[email protected]>
--- arch/s390/include/asm/kvm_host.h | 8 +++++++- arch/s390/include/asm/stacktrace.h | 1 + arch/s390/kernel/asm-offsets.c | 1 + arch/s390/kernel/entry.S | 26 +++++++++++++++----------- 4 files changed, 24 insertions(+), 12 deletions(-)
arch/s390/include/asm/kvm_host.h +7 -1
@@ -1017,7 +1017,13 @@ void kvm_arch_crypto_clear_masks(struct kvm *kvm);void kvm_arch_crypto_set_masks (struct kvm *kvm,unsigned long *apm,unsigned long *aqm,unsigned long *adm); -extern int sie64a (struct kvm_s390_sie_block *,u64 *); +int __sie64a (phys_addr_t sie_block_phys,struct kvm_s390_sie_block *sie_block,u64 *rsa); + +static inline int sie64a (struct kvm_s390_sie_block *sie_block,u64 *rsa) +{ +return __sie64a (virt_to_phys (sie_block), sie_block, rsa); +} +extern char sie_exit;extern int kvm_s390_gisc_register (struct kvm *kvm,u32 gisc);
arch/s390/include/asm/stacktrace.h +1 -0
@@ -46,6 +46,7 @@ struct stack_frame {unsigned long sie_savearea;unsigned long sie_reason;unsigned long sie_flags; +unsigned long sie_control_block_phys; }; };unsigned long gprs[10 ];
arch/s390/kernel/asm-offsets.c +1 -0
@@ -62,6 +62,7 @@ int main(void)OFFSET (__SF_SIE_SAVEAREA, stack_frame, sie_savearea);OFFSET (__SF_SIE_REASON, stack_frame, sie_reason);OFFSET (__SF_SIE_FLAGS, stack_frame, sie_flags); +OFFSET (__SF_SIE_CONTROL_PHYS, stack_frame, sie_control_block_phys);DEFINE (STACK_FRAME_OVERHEAD ,sizeof (struct stack_frame ));BLANK ();/* idle data offsets */
arch/s390/kernel/entry.S +15 -11
@@ -225,18 +225,20 @@ ENDPROC(__switch_to) #if IS_ENABLED(CONFIG_KVM) /* - * sie64a calling convention: - * %r2 pointer to sie control block - * %r3 guest register save area + * __sie64a calling convention: + * %r2 pointer to sie control block phys + * %r3 pointer to sie control block virt + * %r4 guest register save area */ -ENTRY(sie64a) +ENTRY(__sie64a) stmg %r6,%r14,__SF_GPRS(%r15) # save kernel registers lg %r12,__LC_CURRENT - stg %r2,__SF_SIE_CONTROL(%r15) # save control block pointer - stg %r3,__SF_SIE_SAVEAREA(%r15) # save guest register save area + stg %r2,__SF_SIE_CONTROL_PHYS(%r15) # save sie block physical.. + stg %r3,__SF_SIE_CONTROL(%r15) # ...and virtual addresses + stg %r4,__SF_SIE_SAVEAREA(%r15) # save guest register save area xc __SF_SIE_REASON(8,%r15),__SF_SIE_REASON(%r15) # reason code = 0 mvc __SF_SIE_FLAGS(8,%r15),__TI_flags(%r12) # copy thread flags - lmg %r0,%r13,0(%r3) # load guest gprs 0-13 + lmg %r0,%r13,0(%r4) # load guest gprs 0-13 lg %r14,__LC_GMAP # get gmap pointer ltgr %r14,%r14 jz .Lsie_gmap
@@ -248,6 +250,7 @@ ENTRY(sie64a) jnz .Lsie_skip TSTMSK __LC_CPU_FLAGS,_CIF_FPU jo .Lsie_skip # exit if fp/vx regs changed + lg %r14,__SF_SIE_CONTROL_PHYS(%r15) # get sie block phys addr BPEXIT __SF_SIE_FLAGS(%r15),(_TIF_ISOLATE_BP|_TIF_ISOLATE_BP_GUEST) .Lsie_entry: sie 0(%r14)
@@ -258,13 +261,14 @@ ENTRY(sie64a) BPOFF BPENTER __SF_SIE_FLAGS(%r15),(_TIF_ISOLATE_BP|_TIF_ISOLATE_BP_GUEST) .Lsie_skip: + lg %r14,__SF_SIE_CONTROL(%r15) # get control block pointer ni __SIE_PROG0C+3(%r14),0xfe # no longer in SIE lctlg %c1,%c1,__LC_KERNEL_ASCE # load primary asce .Lsie_done: # some program checks are suppressing. C code (e.g. do_protection_exception) # will rewind the PSW by the ILC, which is often 4 bytes in case of SIE. There # are some corner cases (e.g. runtime instrumentation) where ILC is unpredictable. -# Other instructions between sie64a and .Lsie_done should not cause program +# Other instructions between __sie64a and .Lsie_done should not cause program # interrupts. So lets use 3 nops as a landing pad for all possible rewinds. .Lrewind_pad6: nopr 7
@@ -293,8 +297,8 @@ sie_exit: EX_TABLE(.Lrewind_pad4,.Lsie_fault) EX_TABLE(.Lrewind_pad2,.Lsie_fault) EX_TABLE(sie_exit,.Lsie_fault) -ENDPROC(sie64a) -EXPORT_SYMBOL(sie64a) +ENDPROC(__sie64a) +EXPORT_SYMBOL(__sie64a) EXPORT_SYMBOL(sie_exit) #endif
@@ -373,7 +377,7 @@ ENTRY(pgm_check_handler) j 3f # -> fault in user space .Lpgm_skip_asce: #if IS_ENABLED(CONFIG_KVM) - # cleanup critical section for program checks in sie64a + # cleanup critical section for program checks in __sie64a OUTSIDE %r9,.Lsie_gmap,.Lsie_done,1f SIEEXIT lghi %r10,_PIF_GUEST_FAULT
Signature · 1 line
2.38.1
Janosch Frank
maintainer[GIT PULL 04/15] KVM: s390: sida: sort out physical vs virtual pointers usage
In reply to Janosch FrankFrom: Nico Boehr <[email protected]>
All callers of the sida_origin() macro actually expected a virtual address, so rename it to sida_addr() and hand out a virtual address.
At some places, the macro wasn't used, potentially creating problems if the sida size ever becomes nonzero (not currently the case), so let's start using it everywhere now while at it.
Message-Id: <[email protected]>
--- arch/s390/include/asm/kvm_host.h | 3 +-- arch/s390/kvm/intercept.c | 7 +++---- arch/s390/kvm/kvm-s390.c | 9 +++++---- arch/s390/kvm/priv.c | 3 +-- arch/s390/kvm/pv.c | 8 +++++--- 5 files changed, 15 insertions(+), 15 deletions(-)
arch/s390/include/asm/kvm_host.h +1 -2
@@ -142,8 +142,7 @@ struct mcck_volatile_info { CR14_EXTERNAL_DAMAGE_SUBMASK)#define SIDAD_SIZE_MASK 0xff -#define sida_origin (sie_block) \ - ((sie_block)->sidad & PAGE_MASK) +#define sida_addr (sie_block) phys_to_virt((sie_block)->sidad & PAGE_MASK)#define sida_size (sie_block) \ ((((sie_block)->sidad & SIDAD_SIZE_MASK) + 1) * PAGE_SIZE)
arch/s390/kvm/intercept.c +3 -4
@@ -409,8 +409,7 @@ int handle_sthyi(struct kvm_vcpu *vcpu) out:if (!cc) {if (kvm_s390_pv_cpu_is_protected (vcpu)) { -memcpy ((void *)(sida_origin (vcpu->arch.sie_block)), - sctns,PAGE_SIZE ); +memcpy (sida_addr (vcpu->arch.sie_block), sctns,PAGE_SIZE ); }else { r =write_guest (vcpu, addr, reg2, sctns,PAGE_SIZE );if (r) {
@@ -464,7 +463,7 @@ static int handle_operexc(struct kvm_vcpu *vcpu)static int handle_pv_spx (struct kvm_vcpu *vcpu) { -u32 pref = *(u32 *)vcpu->arch.sie_block->sidad; +u32 pref = *(u32 *)sida_addr (vcpu->arch.sie_block);kvm_s390_set_prefix (vcpu, pref);trace_kvm_s390_handle_prefix (vcpu,1 , pref);
@@ -497,7 +496,7 @@ static int handle_pv_sclp(struct kvm_vcpu *vcpu)static int handle_pv_uvc (struct kvm_vcpu *vcpu) { -struct uv_cb_share *guest_uvcb = (void *)vcpu->arch.sie_block->sidad; +struct uv_cb_share *guest_uvcb =sida_addr (vcpu->arch.sie_block);struct uv_cb_cts uvcb = { .header.cmd =UVC_CMD_UNPIN_PAGE_SHARED , .header.len =sizeof (uvcb),
arch/s390/kvm/kvm-s390.c +5 -4
@@ -5167,6 +5167,7 @@ static long kvm_s390_vcpu_sida_op(struct kvm_vcpu *vcpu, struct kvm_s390_mem_op *mop) {void __user *uaddr = (void __user *)mop->buf; +void *sida_addr;int r =0 ;if (mop->flags || !mop->size)
@@ -5178,16 +5179,16 @@ static long kvm_s390_vcpu_sida_op(struct kvm_vcpu *vcpu,if (!kvm_s390_pv_cpu_is_protected (vcpu))return -EINVAL ; + sida_addr = (char *)sida_addr (vcpu->arch.sie_block) + mop->sida_offset; +switch (mop->op) {case KVM_S390_MEMOP_SIDA_READ : -if (copy_to_user (uaddr, (void *)(sida_origin (vcpu->arch.sie_block) + - mop->sida_offset), mop->size)) +if (copy_to_user (uaddr, sida_addr, mop->size)) r = -EFAULT ;break ;case KVM_S390_MEMOP_SIDA_WRITE : -if (copy_from_user ((void *)(sida_origin (vcpu->arch.sie_block) + - mop->sida_offset), uaddr, mop->size)) +if (copy_from_user (sida_addr, uaddr, mop->size)) r = -EFAULT ;break ; }
arch/s390/kvm/priv.c +1 -2
@@ -924,8 +924,7 @@ static int handle_stsi(struct kvm_vcpu *vcpu)return -EREMOTE ; }if (kvm_s390_pv_cpu_is_protected (vcpu)) { -memcpy ((void *)sida_origin (vcpu->arch.sie_block), (void *)mem, -PAGE_SIZE ); +memcpy (sida_addr (vcpu->arch.sie_block), (void *)mem,PAGE_SIZE ); rc =0 ; }else { rc =write_guest (vcpu, operand2, ar, (void *)mem,PAGE_SIZE );
arch/s390/kvm/pv.c +5 -3
@@ -44,7 +44,7 @@ int kvm_s390_pv_destroy_cpu(struct kvm_vcpu *vcpu, u16 *rc, u16 *rrc)free_pages (vcpu->arch.pv.stor_base,get_order (uv_info.guest_cpu_stor_len)); -free_page (sida_origin (vcpu->arch.sie_block)); +free_page ((unsigned long )sida_addr (vcpu->arch.sie_block)); vcpu->arch.sie_block->pv_handle_cpu =0 ; vcpu->arch.sie_block->pv_handle_config =0 ;memset (&vcpu->arch.pv,0 ,sizeof (vcpu->arch.pv));
@@ -66,6 +66,7 @@ int kvm_s390_pv_create_cpu(struct kvm_vcpu *vcpu, u16 *rc, u16 *rrc) .header.cmd = UVC_CMD_CREATE_SEC_CPU, .header.len = sizeof(uvcb), }; +void *sida_addr;int cc;if (kvm_s390_pv_cpu_get_handle (vcpu))
@@ -83,12 +84,13 @@ int kvm_s390_pv_create_cpu(struct kvm_vcpu *vcpu, u16 *rc, u16 *rrc) uvcb.stor_origin = (u64 )vcpu->arch.pv.stor_base;/* Alloc Secure Instruction Data Area Designation */ - vcpu->arch.sie_block->sidad =__get_free_page (GFP_KERNEL_ACCOUNT | __GFP_ZERO); -if (!vcpu->arch.sie_block->sidad) { + sida_addr = (void *)__get_free_page (GFP_KERNEL_ACCOUNT | __GFP_ZERO); +if (!sida_addr) {free_pages (vcpu->arch.pv.stor_base,get_order (uv_info.guest_cpu_stor_len));return -ENOMEM ; } + vcpu->arch.sie_block->sidad =virt_to_phys (sida_addr); cc =uv_call (0 , (u64)&uvcb); *rc = uvcb.header.rc;
Signature · 1 line
2.38.1
Janosch Frank
maintainer[GIT PULL 05/15] KVM: s390: pv: sort out physical vs virtual pointers usage
In reply to Janosch FrankFrom: Nico Boehr <[email protected]>
Fix virtual vs physical address confusion (which currently are the same).
Message-Id: <[email protected]>
--- arch/s390/kvm/pv.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
arch/s390/kvm/pv.c +5 -4
@@ -80,8 +80,8 @@ int kvm_s390_pv_create_cpu(struct kvm_vcpu *vcpu, u16 *rc, u16 *rrc)/* Input */ uvcb.guest_handle =kvm_s390_pv_get_handle (vcpu->kvm); uvcb.num = vcpu->arch.sie_block->icpua; - uvcb.state_origin = (u64 )vcpu->arch.sie_block; - uvcb.stor_origin = (u64 )vcpu->arch.pv.stor_base; + uvcb.state_origin =virt_to_phys (vcpu->arch.sie_block); + uvcb.stor_origin =virt_to_phys ((void *)vcpu->arch.pv.stor_base);/* Alloc Secure Instruction Data Area Designation */ sida_addr = (void *)__get_free_page (GFP_KERNEL_ACCOUNT | __GFP_ZERO);
@@ -228,8 +228,9 @@ int kvm_s390_pv_init_vm(struct kvm *kvm, u16 *rc, u16 *rrc) uvcb.guest_stor_origin =0 ;/* MSO is 0 for KVM */ uvcb.guest_stor_len = kvm->arch.pv.guest_len; uvcb.guest_asce = kvm->arch.gmap->asce; - uvcb.guest_sca = (unsigned long )kvm->arch.sca; - uvcb.conf_base_stor_origin = (u64 )kvm->arch.pv.stor_base; + uvcb.guest_sca =virt_to_phys (kvm->arch.sca); + uvcb.conf_base_stor_origin = +virt_to_phys ((void *)kvm->arch.pv.stor_base); uvcb.conf_virt_stor_origin = (u64 )kvm->arch.pv.stor_var; cc =uv_call_sched (0 , (u64)&uvcb);
Signature · 1 line
2.38.1
Janosch Frank
maintainer[GIT PULL 06/15] KVM: s390: VSIE: sort out virtual/physical address in pin_guest_page
In reply to Janosch FrankFrom: Nico Boehr <[email protected]>
pin_guest_page() used page_to_virt() to calculate the hpa of the pinned page. This currently works, because virtual and physical addresses are the same. Use page_to_phys() instead to resolve the virtual-real address confusion.
One caller of pin_guest_page() actually expected the hpa to be a hva, so add the missing phys_to_virt() conversion here.
Message-Id: <[email protected]>
--- arch/s390/kvm/vsie.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/s390/kvm/vsie.c +2 -2
@@ -654,7 +654,7 @@ static int pin_guest_page(struct kvm *kvm, gpa_t gpa, hpa_t *hpa) page =gfn_to_page (kvm,gpa_to_gfn (gpa));if (is_error_page (page))return -EINVAL ; - *hpa = (hpa_t )page_to_virt (page) + (gpa & ~PAGE_MASK ); + *hpa = (hpa_t )page_to_phys (page) + (gpa & ~PAGE_MASK );return 0 ; }
@@ -869,7 +869,7 @@ static int pin_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page,WARN_ON_ONCE (rc);return 1 ; } - vsie_page->scb_o = (struct kvm_s390_sie_block *) hpa; + vsie_page->scb_o =phys_to_virt (hpa);return 0 ; }
Signature · 1 line
2.38.1
Janosch Frank
maintainer[GIT PULL 09/15] KVM: s390: pv: api documentation for asynchronous destroy
In reply to Janosch FrankFrom: Claudio Imbrenda <[email protected]>
Add documentation for the new commands added to the KVM_S390_PV_COMMAND ioctl.
Message-Id: <[email protected]>
--- Documentation/virt/kvm/api.rst | 41 ++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-)
Documentation/virt/kvm/api.rst +37 -4
@@ -5163,10 +5163,13 @@ KVM_PV_ENABLE ===== ============================= KVM_PV_DISABLE - Deregister the VM from the Ultravisor and reclaim the memory that - had been donated to the Ultravisor, making it usable by the kernel - again. All registered VCPUs are converted back to non-protected - ones. + Deregister the VM from the Ultravisor and reclaim the memory that had + been donated to the Ultravisor, making it usable by the kernel again. + All registered VCPUs are converted back to non-protected ones. If a + previous protected VM had been prepared for asynchonous teardown with + KVM_PV_ASYNC_CLEANUP_PREPARE and not subsequently torn down with + KVM_PV_ASYNC_CLEANUP_PERFORM, it will be torn down in this call + together with the current protected VM. KVM_PV_VM_SET_SEC_PARMS Pass the image header from VM memory to the Ultravisor in
@@ -5289,6 +5292,36 @@ KVM_PV_DUMP authentication tag all of which are needed to decrypt the dump at a later time. +KVM_PV_ASYNC_CLEANUP_PREPARE + :Capability: KVM_CAP_S390_PROTECTED_ASYNC_DISABLE + + Prepare the current protected VM for asynchronous teardown. Most + resources used by the current protected VM will be set aside for a + subsequent asynchronous teardown. The current protected VM will then + resume execution immediately as non-protected. There can be at most + one protected VM prepared for asynchronous teardown at any time. If + a protected VM had already been prepared for teardown without + subsequently calling KVM_PV_ASYNC_CLEANUP_PERFORM, this call will + fail. In that case, the userspace process should issue a normal + KVM_PV_DISABLE. The resources set aside with this call will need to + be cleaned up with a subsequent call to KVM_PV_ASYNC_CLEANUP_PERFORM + or KVM_PV_DISABLE, otherwise they will be cleaned up when KVM + terminates. KVM_PV_ASYNC_CLEANUP_PREPARE can be called again as soon + as cleanup starts, i.e. before KVM_PV_ASYNC_CLEANUP_PERFORM finishes. + +KVM_PV_ASYNC_CLEANUP_PERFORM + :Capability: KVM_CAP_S390_PROTECTED_ASYNC_DISABLE + + Tear down the protected VM previously prepared for teardown with + KVM_PV_ASYNC_CLEANUP_PREPARE. The resources that had been set aside + will be freed during the execution of this command. This PV command + should ideally be issued by userspace from a separate thread. If a + fatal signal is received (or the process terminates naturally), the + command will terminate immediately without completing, and the normal + KVM shutdown procedure will take care of cleaning up all remaining + protected VMs, including the ones whose teardown was interrupted by + process termination. + 4.126 KVM_XEN_HVM_SET_ATTR --------------------------
Signature · 1 line
2.38.1
Janosch Frank
maintainer[GIT PULL 07/15] s390/mm: fix virtual-physical address confusion for swiotlb
In reply to Janosch FrankFrom: Nico Boehr <[email protected]>
swiotlb passes virtual addresses to set_memory_encrypted() and set_memory_decrypted(), but uv_remove_shared() and uv_set_shared() expect physical addresses. This currently works, because virtual and physical addresses are the same.
Add virt_to_phys() to resolve the virtual-physical confusion.
Message-Id: <[email protected]>
--- arch/s390/include/asm/mem_encrypt.h | 4 ++-- arch/s390/mm/init.c | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-)
arch/s390/include/asm/mem_encrypt.h +2 -2
@@ -4,8 +4,8 @@#ifndef __ASSEMBLY__ -int set_memory_encrypted (unsigned long addr,int numpages); -int set_memory_decrypted (unsigned long addr,int numpages); +int set_memory_encrypted (unsigned long vaddr,int numpages); +int set_memory_decrypted (unsigned long vaddr,int numpages);#endif /* __ASSEMBLY__ */
arch/s390/mm/init.c +6 -6
@@ -140,25 +140,25 @@ void mark_rodata_ro(void)debug_checkwx (); } -int set_memory_encrypted (unsigned long addr,int numpages) +int set_memory_encrypted (unsigned long vaddr,int numpages) {int i;/* make specified pages unshared, (swiotlb, dma_free) */ for (i =0 ; i < numpages; ++i) { -uv_remove_shared (addr); - addr +=PAGE_SIZE ; +uv_remove_shared (virt_to_phys ((void *)vaddr)); + vaddr +=PAGE_SIZE ; }return 0 ; } -int set_memory_decrypted (unsigned long addr,int numpages) +int set_memory_decrypted (unsigned long vaddr,int numpages) {int i;/* make specified pages shared (swiotlb, dma_alloca) */ for (i =0 ; i < numpages; ++i) { -uv_set_shared (addr); - addr +=PAGE_SIZE ; +uv_set_shared (virt_to_phys ((void *)vaddr)); + vaddr +=PAGE_SIZE ; }return 0 ; }
Signature · 1 line
2.38.1
Janosch Frank
maintainer[GIT PULL 08/15] KVM: s390: pv: asynchronous destroy for reboot
In reply to Janosch FrankFrom: Claudio Imbrenda <[email protected]>
Until now, destroying a protected guest was an entirely synchronous operation that could potentially take a very long time, depending on the size of the guest, due to the time needed to clean up the address space from protected pages.
This patch implements an asynchronous destroy mechanism, that allows a protected guest to reboot significantly faster than previously.
This is achieved by clearing the pages of the old guest in background. In case of reboot, the new guest will be able to run in the same address space almost immediately.
The old protected guest is then only destroyed when all of its memory has been destroyed or otherwise made non protected.
Two new PV commands are added for the KVM_S390_PV_COMMAND ioctl:
KVM_PV_ASYNC_CLEANUP_PREPARE: set aside the current protected VM for later asynchronous teardown. The current KVM VM will then continue immediately as non-protected. If a protected VM had already been set aside for asynchronous teardown, but without starting the teardown process, this call will fail. There can be at most one VM set aside at any time. Once it is set aside, the protected VM only exists in the context of the Ultravisor, it is not associated with the KVM VM anymore. Its protected CPUs have already been destroyed, but not its memory. This command can be issued again immediately after starting KVM_PV_ASYNC_CLEANUP_PERFORM, without having to wait for completion.
KVM_PV_ASYNC_CLEANUP_PERFORM: tears down the protected VM previously set aside using KVM_PV_ASYNC_CLEANUP_PREPARE. Ideally the KVM_PV_ASYNC_CLEANUP_PERFORM PV command should be issued by userspace from a separate thread. If a fatal signal is received (or if the process terminates naturally), the command will terminate immediately without completing. All protected VMs whose teardown was interrupted will be put in the need_cleanup list. The rest of the normal KVM teardown process will take care of properly cleaning up all remaining protected VMs, including the ones on the need_cleanup list.
Message-Id: <[email protected]>
--- arch/s390/include/asm/kvm_host.h | 2 + arch/s390/kvm/kvm-s390.c | 49 ++++- arch/s390/kvm/kvm-s390.h | 3 + arch/s390/kvm/pv.c | 295 +++++++++++++++++++++++++++++-- include/uapi/linux/kvm.h | 2 + 5 files changed, 333 insertions(+), 18 deletions(-)
arch/s390/include/asm/kvm_host.h +2 -0
@@ -942,6 +942,8 @@ struct kvm_s390_pv {unsigned long stor_base;void *stor_var;bool dumping; +void *set_aside; +struct list_head need_cleanup;struct mmu_notifier mmu_notifier; };
arch/s390/kvm/kvm-s390.c +41 -8
101 lines not on this page · raw message
arch/s390/kvm/kvm-s390.h +3 -0
@@ -244,6 +244,9 @@ static inline u32 kvm_s390_get_gisa_desc(struct kvm *kvm)/* implemented in pv.c */ int kvm_s390_pv_destroy_cpu (struct kvm_vcpu *vcpu,u16 *rc,u16 *rrc);int kvm_s390_pv_create_cpu (struct kvm_vcpu *vcpu,u16 *rc,u16 *rrc); +int kvm_s390_pv_set_aside (struct kvm *kvm,u16 *rc,u16 *rrc); +int kvm_s390_pv_deinit_aside_vm (struct kvm *kvm,u16 *rc,u16 *rrc); +int kvm_s390_pv_deinit_cleanup_all (struct kvm *kvm,u16 *rc,u16 *rrc);int kvm_s390_pv_deinit_vm (struct kvm *kvm,u16 *rc,u16 *rrc);int kvm_s390_pv_init_vm (struct kvm *kvm,u16 *rc,u16 *rrc); int kvm_s390_pv_set_sec_parms(struct kvm *kvm, void *hdr, u64 length, u16 *rc,
arch/s390/kvm/pv.c +285 -10
319 lines not on this page · raw message
include/uapi/linux/kvm.h +2 -0
@@ -1740,6 +1740,8 @@ enum pv_cmd_id {KVM_PV_UNSHARE_ALL ,KVM_PV_INFO ,KVM_PV_DUMP , +KVM_PV_ASYNC_CLEANUP_PREPARE , + KVM_PV_ASYNC_CLEANUP_PERFORM, }; struct kvm_pv_cmd {
Signature · 1 line
2.38.1
Janosch Frank
maintainer[GIT PULL 10/15] KVM: s390: pv: add KVM_CAP_S390_PROTECTED_ASYNC_DISABLE
In reply to Janosch FrankFrom: Claudio Imbrenda <[email protected]>
Add KVM_CAP_S390_PROTECTED_ASYNC_DISABLE to signal that the KVM_PV_ASYNC_DISABLE and KVM_PV_ASYNC_DISABLE_PREPARE commands for the KVM_S390_PV_COMMAND ioctl are available.
Message-Id: <[email protected]>
--- arch/s390/kvm/kvm-s390.c | 3 +++ include/uapi/linux/kvm.h | 1 + 2 files changed, 4 insertions(+)
arch/s390/kvm/kvm-s390.c +3 -0
@@ -618,6 +618,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)case KVM_CAP_S390_BPB : r =test_facility (82 );break ; +case KVM_CAP_S390_PROTECTED_ASYNC_DISABLE : + r = async_destroy &&is_prot_virt_host (); +break ;case KVM_CAP_S390_PROTECTED : r =is_prot_virt_host ();break ;
include/uapi/linux/kvm.h +1 -0
@@ -1178,6 +1178,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_S390_ZPCI_OP 221#define KVM_CAP_S390_CPU_TOPOLOGY 222#define KVM_CAP_DIRTY_LOG_RING_ACQ_REL 223 +#define KVM_CAP_S390_PROTECTED_ASYNC_DISABLE 224#ifdef KVM_CAP_IRQ_ROUTING
Signature · 1 line
2.38.1
Janosch Frank
maintainer[GIT PULL 11/15] KVM: s390: pv: avoid export before import if possible
In reply to Janosch FrankFrom: Claudio Imbrenda <[email protected]>
If the appropriate UV feature bit is set, there is no need to perform an export before import.
The misc feature indicates, among other things, that importing a shared page from a different protected VM will automatically also transfer its ownership.
Message-Id: <[email protected]>
--- arch/s390/kernel/uv.c | 7 +++++++ 1 file changed, 7 insertions(+)
arch/s390/kernel/uv.c +7 -0
@@ -255,6 +255,13 @@ static int make_secure_pte(pte_t *ptep, unsigned long addr,*/ static bool should_export_before_import (struct uv_cb_header *uvcb,struct mm_struct *mm) { +/* +* The misc feature indicates, among other things, that importing a +* shared page from a different protected VM will automatically also +* transfer its ownership. +*/ +if (test_bit_inv (BIT_UV_FEAT_MISC , &uv_info.uv_feature_indications)) +return false;if (uvcb->cmd ==UVC_CMD_UNPIN_PAGE_SHARED )return false;return atomic_read (&mm->context.protected_count) >1 ;
Signature · 1 line
2.38.1
Janosch Frank
maintainer[GIT PULL 12/15] KVM: s390: pv: support for Destroy fast UVC
In reply to Janosch FrankFrom: Claudio Imbrenda <[email protected]>
Add support for the Destroy Secure Configuration Fast Ultravisor call, and take advantage of it for asynchronous destroy.
When supported, the protected guest is destroyed immediately using the new UVC, leaving only the memory to be cleaned up asynchronously.
Message-Id: <[email protected]>
--- arch/s390/include/asm/uv.h | 10 +++++++ arch/s390/kvm/pv.c | 61 +++++++++++++++++++++++++++++++++----- 2 files changed, 63 insertions(+), 8 deletions(-)
arch/s390/include/asm/uv.h +10 -0
@@ -34,6 +34,7 @@#define UVC_CMD_INIT_UV 0x000f#define UVC_CMD_CREATE_SEC_CONF 0x0100#define UVC_CMD_DESTROY_SEC_CONF 0x0101 +#define UVC_CMD_DESTROY_SEC_CONF_FAST 0x0102#define UVC_CMD_CREATE_SEC_CPU 0x0120#define UVC_CMD_DESTROY_SEC_CPU 0x0121#define UVC_CMD_CONV_TO_SEC_STOR 0x0200
@@ -81,6 +82,7 @@ enum uv_cmds_inst {BIT_UVC_CMD_UNSHARE_ALL =20 ,BIT_UVC_CMD_PIN_PAGE_SHARED =21 ,BIT_UVC_CMD_UNPIN_PAGE_SHARED =22 , +BIT_UVC_CMD_DESTROY_SEC_CONF_FAST =23 ,BIT_UVC_CMD_DUMP_INIT =24 ,BIT_UVC_CMD_DUMP_CONFIG_STOR_STATE =25 , BIT_UVC_CMD_DUMP_CPU = 26,
@@ -230,6 +232,14 @@ struct uv_cb_nodata {u64 reserved20[4 ]; } __packed__aligned(8) ; +/* Destroy Configuration Fast */ +struct uv_cb_destroy_fast { +struct uv_cb_header header; +u64 reserved08[2 ]; +u64 handle; +u64 reserved20[5 ]; +} __packed__aligned(8) ; +/* Set Shared Access */ struct uv_cb_share {struct uv_cb_header header;
arch/s390/kvm/pv.c +53 -8
104 lines not on this page · raw message
Signature · 1 line
2.38.1
Janosch Frank
maintainer[GIT PULL 13/15] KVM: s390: pv: module parameter to fence asynchronous destroy
In reply to Janosch FrankFrom: Claudio Imbrenda <[email protected]>
Add the module parameter "async_destroy", to allow the asynchronous destroy mechanism to be switched off. This might be useful for debugging purposes.
The parameter is enabled by default since the feature is opt-in anyway.
Message-Id: <[email protected]>
--- arch/s390/kvm/kvm-s390.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
arch/s390/kvm/kvm-s390.c +7 -1
@@ -209,7 +209,13 @@ unsigned int diag9c_forwarding_hz;module_param (diag9c_forwarding_hz, uint,0644 );MODULE_PARM_DESC (diag9c_forwarding_hz,"Maximum diag9c forwarding per second, 0 to turn off" ); -static int async_destroy; +/* +* allow asynchronous deinit for protected guests; enable by default since +* the feature is opt-in anyway +*/ +static int async_destroy =1 ; +module_param (async_destroy, int,0444 ); +MODULE_PARM_DESC (async_destroy,"Asynchronous destroy for protected guests" );/* * For now we handle at most 16 double words as this is what the s390 base
Signature · 1 line
2.38.1
Janosch Frank
maintainer[GIT PULL 15/15] KVM: s390: remove unused gisa_clear_ipm_gisc() function
In reply to Janosch FrankFrom: Heiko Carstens <[email protected]>
clang warns about an unused function:arch/s390/kvm/interrupt.c:317:20:
error: unused function 'gisa_clear_ipm_gisc' [-Werror,-Wunused-function]
static inline void gisa_clear_ipm_gisc(struct kvm_s390_gisa *gisa, u32 gisc)
Remove gisa_clear_ipm_gisc(), since it is unused and get rid of this warning.
--- arch/s390/kvm/interrupt.c | 5 ----- 1 file changed, 5 deletions(-)
arch/s390/kvm/interrupt.c +0 -5
@@ -314,11 +314,6 @@ static inline u8 gisa_get_ipm(struct kvm_s390_gisa *gisa)return READ_ONCE (gisa->ipm); } -static inline void gisa_clear_ipm_gisc (struct kvm_s390_gisa *gisa,u32 gisc) -{ -clear_bit_inv (IPM_BIT_OFFSET + gisc, (unsigned long *) gisa); -} -static inline int gisa_tac_ipm_gisc (struct kvm_s390_gisa *gisa,u32 gisc) {return test_and_clear_bit_inv (IPM_BIT_OFFSET + gisc, (unsigned long *) gisa);
Signature · 1 line
2.38.1
Janosch Frank
maintainer[GIT PULL 14/15] s390/vfio-ap: GISA: sort out physical vs virtual pointers usage
In reply to Janosch FrankFrom: Nico Boehr <[email protected]>
Fix virtual vs physical address confusion (which currently are the same) for the GISA when enabling the IRQ.
Message-Id: <[email protected]>
--- drivers/s390/crypto/vfio_ap_ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/s390/crypto/vfio_ap_ops.c +1 -1
@@ -429,7 +429,7 @@ static struct ap_queue_status vfio_ap_irq_enable(struct vfio_ap_queue *q, aqic_gisa.isc = nisc; aqic_gisa.ir =1 ; - aqic_gisa.gisa = (uint64_t )gisa >>4 ; + aqic_gisa.gisa =virt_to_phys (gisa) >>4 ; status =ap_aqic (q->apqn, aqic_gisa, h_nib);switch (status.response_code) {
Signature · 1 line
2.38.1