Skip to contentSkip to conversation

KVM: s390: Fix a deadlock

PATCH In review Claudio Imbrenda 4 participants 4 messages Mar 3 – Mar 5

Subsystems (3)
lore
Share & tools
lore

Claudio Imbrenda

author maintainer
#0 lore raw

PATCH 1/1 KVM: s390: Fix a deadlock

In some scenarios, a deadlock can happen, involving _do_shadow_pte().

Convert all usages of pgste_get_lock() to pgste_get_trylock() in _do_shadow_pte() and return -EAGAIN. All callers can already deal with -EAGAIN being returned.

Fixes e38c884df921 ("KVM: s390: Switch to new gmap")
---
 arch/s390/kvm/gaccess.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/s390/kvm/gaccess.c +4 -2
index 4630b2a067ea..a9da9390867d 100644
@@ -1434,7 +1434,8 @@ static int _do_shadow_pte(struct gmap *sg, gpa_t raddr, union pte *ptep_h, union
 	if (rc)
 		return rc;
 
-	pgste = pgste_get_lock(ptep_h);
+	if (!pgste_get_trylock(ptep_h, &pgste))
+		return -EAGAIN;
 	newpte = _pte(f->pfn, f->writable, !p, 0);
 	newpte.s.d |= ptep->s.d;
 	newpte.s.sd |= ptep->s.sd;
@@ -1444,7 +1445,8 @@ static int _do_shadow_pte(struct gmap *sg, gpa_t raddr, union pte *ptep_h, union
 	pgste_set_unlock(ptep_h, pgste);
 
 	newpte = _pte(f->pfn, 0, !p, 0);
-	pgste = pgste_get_lock(ptep);
+	if (!pgste_get_trylock(ptep, &pgste))
+		return -EAGAIN;
 	pgste = __dat_ptep_xchg(ptep, pgste, newpte, gpa_to_gfn(raddr), sg->asce, uses_skeys(sg));
 	pgste_set_unlock(ptep, pgste);
 
Signature · 1 line
2.53.0
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Claudio Imbrenda
Quoted 8 lines · Claudio Imbrenda

In some scenarios, a deadlock can happen, involving _do_shadow_pte().

Convert all usages of pgste_get_lock() to pgste_get_trylock() in _do_shadow_pte() and return -EAGAIN. All callers can already deal with -EAGAIN being returned.

Fixes e38c884df921 ("KVM: s390: Switch to new gmap")
Tested-by on v1 1/1
#3 lore raw
In reply to Claudio Imbrenda

Am 03.03.26 um 18:52 schrieb Claudio Imbrenda:

Quoted 8 lines

In some scenarios, a deadlock can happen, involving _do_shadow_pte().

Convert all usages of pgste_get_lock() to pgste_get_trylock() in _do_shadow_pte() and return -EAGAIN. All callers can already deal with -EAGAIN being returned.

Fixes e38c884df921 ("KVM: s390: Switch to new gmap")

I no longer see the rcu stalls.

Quoted 28 lines
---
  arch/s390/kvm/gaccess.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
arch/s390/kvm/gaccess.c +4 -2
index 4630b2a067ea..a9da9390867d 100644
@@ -1434,7 +1434,8 @@ static int _do_shadow_pte(struct gmap *sg, gpa_t raddr, union pte *ptep_h, union
  	if (rc)
  		return rc;
 
-	pgste = pgste_get_lock(ptep_h);
+	if (!pgste_get_trylock(ptep_h, &pgste))
+		return -EAGAIN;
  	newpte = _pte(f->pfn, f->writable, !p, 0);
  	newpte.s.d |= ptep->s.d;
  	newpte.s.sd |= ptep->s.sd;
@@ -1444,7 +1445,8 @@ static int _do_shadow_pte(struct gmap *sg, gpa_t raddr, union pte *ptep_h, union
  	pgste_set_unlock(ptep_h, pgste);
 
  	newpte = _pte(f->pfn, 0, !p, 0);
-	pgste = pgste_get_lock(ptep);
+	if (!pgste_get_trylock(ptep, &pgste))
+		return -EAGAIN;
  	pgste = __dat_ptep_xchg(ptep, pgste, newpte, gpa_to_gfn(raddr), sg->asce, uses_skeys(sg));
  	pgste_set_unlock(ptep, pgste);