Skip to contentSkip to conversation

KVM: s390: pv: Two small fixes for 6.5

GIT PULL Claudio Imbrenda 2 participants 4 messages Jul 18, 2023 – Jul 23, 2023

Subsystems (4)
lore
Share & tools
lore

Claudio Imbrenda

author maintainer
#0 lore raw

Hi Paolo,

just two small bugfixes for asynchronous destroy.

please pull, thanks!

Claudio

The following changes since commit fdf0eaf11452d72945af31804e2a1048ee1b574c:

Linux 6.5-rc2 (2023-07-16 15:10:37 -0700)

are available in the Git repository at:

https://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git tags/kvm-s390-master-6.5-1

for you to fetch changes up to c2fceb59bbda16468bda82b002383bff59de89ab:

KVM: s390: pv: fix index value of replaced ASCE (2023-07-18 11:21:51 +0200)

----------------------------------------------------------------
Two fixes for asynchronous destroy

----------------------------------------------------------------
Claudio Imbrenda (2):
KVM: s390: pv: simplify shutdown and fix race
KVM: s390: pv: fix index value of replaced ASCE

 arch/s390/kvm/pv.c  | 8 ++++++--
 arch/s390/mm/gmap.c | 1 +
 2 files changed, 7 insertions(+), 2 deletions(-)
Signature · 1 line
2.41.0
author maintainer
#1 lore raw

[GIT PULL 1/2] KVM: s390: pv: simplify shutdown and fix race

Simplify the shutdown of non-protected VMs. There is no need to do complex manipulations of the counter if it was zero.

This also fixes a very rare race which caused pages to be torn down from the address space with a non-zero counter even on older machines that don't support the UVC instruction, causing a crash.

Fixes fb491d5500a7 ("KVM: s390: pv: asynchronous destroy for reboot")

Message-ID: <[email protected]>

---
 arch/s390/kvm/pv.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
arch/s390/kvm/pv.c +6 -2
index 2f34c7c3c5ab..bf1fdc7bf89e 100644
@@ -411,8 +411,12 @@ int kvm_s390_pv_deinit_cleanup_all(struct kvm *kvm, u16 *rc, u16 *rrc)
 	u16 _rc, _rrc;
 	int cc = 0;
 
-	/* Make sure the counter does not reach 0 before calling s390_uv_destroy_range */
-	atomic_inc(&kvm->mm->context.protected_count);
+	/*
+	 * Nothing to do if the counter was already 0. Otherwise make sure
+	 * the counter does not reach 0 before calling s390_uv_destroy_range.
+	 */
+	if (!atomic_inc_not_zero(&kvm->mm->context.protected_count))
+		return 0;
 
 	*rc = 1;
 	/* If the current VM is protected, destroy it */
Signature · 1 line
2.41.0
author maintainer
#2 lore raw

[GIT PULL 2/2] KVM: s390: pv: fix index value of replaced ASCE

In reply to Claudio Imbrenda

The index field of the struct page corresponding to a guest ASCE should be 0. When replacing the ASCE in s390_replace_asce(), the index of the new ASCE should also be set to 0.

Having the wrong index might lead to the wrong addresses being passed around when notifying pte invalidations, and eventually to validity intercepts (VM crash) if the prefix gets unmapped and the notifier gets called with the wrong address.

Fixes faa2f72cb356 ("KVM: s390: pv: leak the topmost page table when destroy fails")

Message-ID: <[email protected]>

---
 arch/s390/mm/gmap.c | 1 +
 1 file changed, 1 insertion(+)
arch/s390/mm/gmap.c +1 -0
index 989ebd0912b4..9c8af31be970 100644
@@ -2853,6 +2853,7 @@ int s390_replace_asce(struct gmap *gmap)
 	page = alloc_pages(GFP_KERNEL_ACCOUNT, CRST_ALLOC_ORDER);
 	if (!page)
 		return -ENOMEM;
+	page->index = 0;
 	table = page_to_virt(page);
 	memcpy(table, gmap->table, 1UL << (CRST_ALLOC_ORDER + PAGE_SHIFT));
 
Signature · 1 line
2.41.0
maintainer
#3 lore raw
In reply to Claudio Imbrenda
Quoted 7 lines · Claudio Imbrenda

Hi Paolo,

just two small bugfixes for asynchronous destroy.

please pull, thanks!

Done, thanks.

Paolo

Quoted 31 lines

Claudio

The following changes since commit fdf0eaf11452d72945af31804e2a1048ee1b574c:

Linux 6.5-rc2 (2023-07-16 15:10:37 -0700)

are available in the Git repository at:

https://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git tags/kvm-s390-master-6.5-1

for you to fetch changes up to c2fceb59bbda16468bda82b002383bff59de89ab:

KVM: s390: pv: fix index value of replaced ASCE (2023-07-18 11:21:51 +0200)

----------------------------------------------------------------
Two fixes for asynchronous destroy

----------------------------------------------------------------
Claudio Imbrenda (2):
KVM: s390: pv: simplify shutdown and fix race
KVM: s390: pv: fix index value of replaced ASCE

 arch/s390/kvm/pv.c  | 8 ++++++--
 arch/s390/mm/gmap.c | 1 +
 2 files changed, 7 insertions(+), 2 deletions(-)

--
2.41.0