All of lore.kernel.org
 help / color / mirror / Atom feed
* [GIT PULL 0/3] KVM: s390: Fixes for vsie (nested hypervisors)
@ 2020-04-07 11:42 Christian Borntraeger
  2020-04-07 11:42 ` [GIT PULL 1/3] KVM: s390: vsie: Fix region 1 ASCE sanity shadow address checks Christian Borntraeger
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Christian Borntraeger @ 2020-04-07 11:42 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: KVM, Janosch Frank, David Hildenbrand, Cornelia Huck, linux-s390,
	Christian Borntraeger

Paolo,

some fixes for 5.7. The commits are new due to late additions of
Reviewed-by tags, but I have been testing these for a while now.
The following changes since commit 8c1b724ddb218f221612d4c649bc9c7819d8d7a6:

  Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm (2020-04-02 15:13:15 -0700)

are available in the Git repository at:

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

for you to fetch changes up to 1493e0f944f3c319d11e067c185c904d01c17ae5:

  KVM: s390: vsie: Fix possible race when shadowing region 3 tables (2020-04-07 13:12:38 +0200)

----------------------------------------------------------------
KVM: s390: Fixes for vsie (nested hypervisors)

- Several fixes for corner cases of nesting. Still relevant as it might
  crash host or first level guest or temporarily leak memory.

----------------------------------------------------------------
David Hildenbrand (3):
      KVM: s390: vsie: Fix region 1 ASCE sanity shadow address checks
      KVM: s390: vsie: Fix delivery of addressing exceptions
      KVM: s390: vsie: Fix possible race when shadowing region 3 tables

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [GIT PULL 1/3] KVM: s390: vsie: Fix region 1 ASCE sanity shadow address checks
  2020-04-07 11:42 [GIT PULL 0/3] KVM: s390: Fixes for vsie (nested hypervisors) Christian Borntraeger
@ 2020-04-07 11:42 ` Christian Borntraeger
  2020-04-07 11:42 ` [GIT PULL 2/3] KVM: s390: vsie: Fix delivery of addressing exceptions Christian Borntraeger
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Christian Borntraeger @ 2020-04-07 11:42 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: KVM, Janosch Frank, David Hildenbrand, Cornelia Huck, linux-s390,
	Christian Borntraeger, Janosch Frank, Claudio Imbrenda

From: David Hildenbrand <david@redhat.com>

In case we have a region 1 the following calculation
(31 + ((gmap->asce & _ASCE_TYPE_MASK) >> 2)*11)
results in 64. As shifts beyond the size are undefined the compiler is
free to use instructions like sllg. sllg will only use 6 bits of the
shift value (here 64) resulting in no shift at all. That means that ALL
addresses will be rejected.

The can result in endless loops, e.g. when prefix cannot get mapped.

Fixes: 4be130a08420 ("s390/mm: add shadow gmap support")
Tested-by: Janosch Frank <frankja@linux.ibm.com>
Reported-by: Janosch Frank <frankja@linux.ibm.com>
Cc: <stable@vger.kernel.org> # v4.8+
Signed-off-by: David Hildenbrand <david@redhat.com>
Link: https://lore.kernel.org/r/20200403153050.20569-2-david@redhat.com
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>
[borntraeger@de.ibm.com: fix patch description, remove WARN_ON_ONCE]
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 arch/s390/mm/gmap.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/s390/mm/gmap.c b/arch/s390/mm/gmap.c
index 2fbece47ef6f..7e9a6761f254 100644
--- a/arch/s390/mm/gmap.c
+++ b/arch/s390/mm/gmap.c
@@ -787,14 +787,18 @@ static void gmap_call_notifier(struct gmap *gmap, unsigned long start,
 static inline unsigned long *gmap_table_walk(struct gmap *gmap,
 					     unsigned long gaddr, int level)
 {
+	const int asce_type = gmap->asce & _ASCE_TYPE_MASK;
 	unsigned long *table;
 
 	if ((gmap->asce & _ASCE_TYPE_MASK) + 4 < (level * 4))
 		return NULL;
 	if (gmap_is_shadow(gmap) && gmap->removed)
 		return NULL;
-	if (gaddr & (-1UL << (31 + ((gmap->asce & _ASCE_TYPE_MASK) >> 2)*11)))
+
+	if (asce_type != _ASCE_TYPE_REGION1 &&
+	    gaddr & (-1UL << (31 + (asce_type >> 2) * 11)))
 		return NULL;
+
 	table = gmap->table;
 	switch (gmap->asce & _ASCE_TYPE_MASK) {
 	case _ASCE_TYPE_REGION1:
-- 
2.25.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [GIT PULL 2/3] KVM: s390: vsie: Fix delivery of addressing exceptions
  2020-04-07 11:42 [GIT PULL 0/3] KVM: s390: Fixes for vsie (nested hypervisors) Christian Borntraeger
  2020-04-07 11:42 ` [GIT PULL 1/3] KVM: s390: vsie: Fix region 1 ASCE sanity shadow address checks Christian Borntraeger
@ 2020-04-07 11:42 ` Christian Borntraeger
  2020-04-07 11:42 ` [GIT PULL 3/3] KVM: s390: vsie: Fix possible race when shadowing region 3 tables Christian Borntraeger
  2020-04-07 12:31 ` [GIT PULL 0/3] KVM: s390: Fixes for vsie (nested hypervisors) Paolo Bonzini
  3 siblings, 0 replies; 5+ messages in thread
From: Christian Borntraeger @ 2020-04-07 11:42 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: KVM, Janosch Frank, David Hildenbrand, Cornelia Huck, linux-s390,
	Christian Borntraeger, Claudio Imbrenda

From: David Hildenbrand <david@redhat.com>

Whenever we get an -EFAULT, we failed to read in guest 2 physical
address space. Such addressing exceptions are reported via a program
intercept to the nested hypervisor.

We faked the intercept, we have to return to guest 2. Instead, right
now we would be returning -EFAULT from the intercept handler, eventually
crashing the VM.
the correct thing to do is to return 1 as rc == 1 is the internal
representation of "we have to go back into g2".

Addressing exceptions can only happen if the g2->g3 page tables
reference invalid g2 addresses (say, either a table or the final page is
not accessible - so something that basically never happens in sane
environments.

Identified by manual code inspection.

Fixes: a3508fbe9dc6 ("KVM: s390: vsie: initial support for nested virtualization")
Cc: <stable@vger.kernel.org> # v4.8+
Signed-off-by: David Hildenbrand <david@redhat.com>
Link: https://lore.kernel.org/r/20200403153050.20569-3-david@redhat.com
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>
[borntraeger@de.ibm.com: fix patch description]
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 arch/s390/kvm/vsie.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c
index 076090f9e666..4f6c22d72072 100644
--- a/arch/s390/kvm/vsie.c
+++ b/arch/s390/kvm/vsie.c
@@ -1202,6 +1202,7 @@ static int vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 		scb_s->iprcc = PGM_ADDRESSING;
 		scb_s->pgmilc = 4;
 		scb_s->gpsw.addr = __rewind_psw(scb_s->gpsw, 4);
+		rc = 1;
 	}
 	return rc;
 }
-- 
2.25.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [GIT PULL 3/3] KVM: s390: vsie: Fix possible race when shadowing region 3 tables
  2020-04-07 11:42 [GIT PULL 0/3] KVM: s390: Fixes for vsie (nested hypervisors) Christian Borntraeger
  2020-04-07 11:42 ` [GIT PULL 1/3] KVM: s390: vsie: Fix region 1 ASCE sanity shadow address checks Christian Borntraeger
  2020-04-07 11:42 ` [GIT PULL 2/3] KVM: s390: vsie: Fix delivery of addressing exceptions Christian Borntraeger
@ 2020-04-07 11:42 ` Christian Borntraeger
  2020-04-07 12:31 ` [GIT PULL 0/3] KVM: s390: Fixes for vsie (nested hypervisors) Paolo Bonzini
  3 siblings, 0 replies; 5+ messages in thread
From: Christian Borntraeger @ 2020-04-07 11:42 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: KVM, Janosch Frank, David Hildenbrand, Cornelia Huck, linux-s390,
	Christian Borntraeger, Claudio Imbrenda

From: David Hildenbrand <david@redhat.com>

We have to properly retry again by returning -EINVAL immediately in case
somebody else instantiated the table concurrently. We missed to add the
goto in this function only. The code now matches the other, similar
shadowing functions.

We are overwriting an existing region 2 table entry. All allocated pages
are added to the crst_list to be freed later, so they are not lost
forever. However, when unshadowing the region 2 table, we wouldn't trigger
unshadowing of the original shadowed region 3 table that we replaced. It
would get unshadowed when the original region 3 table is modified. As it's
not connected to the page table hierarchy anymore, it's not going to get
used anymore. However, for a limited time, this page table will stick
around, so it's in some sense a temporary memory leak.

Identified by manual code inspection. I don't think this classifies as
stable material.

Fixes: 998f637cc4b9 ("s390/mm: avoid races on region/segment/page table shadowing")
Signed-off-by: David Hildenbrand <david@redhat.com>
Link: https://lore.kernel.org/r/20200403153050.20569-4-david@redhat.com
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 arch/s390/mm/gmap.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/s390/mm/gmap.c b/arch/s390/mm/gmap.c
index 7e9a6761f254..1a95d8809cc3 100644
--- a/arch/s390/mm/gmap.c
+++ b/arch/s390/mm/gmap.c
@@ -1844,6 +1844,7 @@ int gmap_shadow_r3t(struct gmap *sg, unsigned long saddr, unsigned long r3t,
 		goto out_free;
 	} else if (*table & _REGION_ENTRY_ORIGIN) {
 		rc = -EAGAIN;		/* Race with shadow */
+		goto out_free;
 	}
 	crst_table_init(s_r3t, _REGION3_ENTRY_EMPTY);
 	/* mark as invalid as long as the parent table is not protected */
-- 
2.25.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [GIT PULL 0/3] KVM: s390: Fixes for vsie (nested hypervisors)
  2020-04-07 11:42 [GIT PULL 0/3] KVM: s390: Fixes for vsie (nested hypervisors) Christian Borntraeger
                   ` (2 preceding siblings ...)
  2020-04-07 11:42 ` [GIT PULL 3/3] KVM: s390: vsie: Fix possible race when shadowing region 3 tables Christian Borntraeger
@ 2020-04-07 12:31 ` Paolo Bonzini
  3 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2020-04-07 12:31 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: KVM, Janosch Frank, David Hildenbrand, Cornelia Huck, linux-s390

On 07/04/20 13:42, Christian Borntraeger wrote:
>   git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git  tags/kvm-s390-master-5.7-1

Pulled, thanks!

Paolo

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-04-07 12:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-07 11:42 [GIT PULL 0/3] KVM: s390: Fixes for vsie (nested hypervisors) Christian Borntraeger
2020-04-07 11:42 ` [GIT PULL 1/3] KVM: s390: vsie: Fix region 1 ASCE sanity shadow address checks Christian Borntraeger
2020-04-07 11:42 ` [GIT PULL 2/3] KVM: s390: vsie: Fix delivery of addressing exceptions Christian Borntraeger
2020-04-07 11:42 ` [GIT PULL 3/3] KVM: s390: vsie: Fix possible race when shadowing region 3 tables Christian Borntraeger
2020-04-07 12:31 ` [GIT PULL 0/3] KVM: s390: Fixes for vsie (nested hypervisors) Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.