KVM: s390: pv: fix race when making a page secure
Claudio Imbrenda
maintainerciao Paolo,
please pull this late fix for 6.14.
It fixes a race that in some circumstances can lead to a stall.
The following changes since commit 695caca9345a160ecd9645abab8e70cfe849e9ff:
Merge tag 'leds-fixes-6.14' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/leds (2025-03-13 22:52:52 -1000)
are available in the Git repository at:
https://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git tags/kvm-s390-master-6.14-1
for you to fetch changes up to d8dfda5af0be6e48178b6f4b46c6af30b06335b2:
KVM: s390: pv: fix race when making a page secure (2025-03-14 15:24:19 +0100)
----------------------------------------------------------------
KVM: s390: pv: fix race when making a page secure
----------------------------------------------------------------
Claudio Imbrenda (1):
KVM: s390: pv: fix race when making a page secure
arch/s390/include/asm/gmap.h | 1 - arch/s390/include/asm/uv.h | 2 +- arch/s390/kernel/uv.c | 136 ++++++++++++++++++++++++++++++++++++++++--- arch/s390/kvm/gmap.c | 103 ++------------------------------ arch/s390/kvm/kvm-s390.c | 25 ++++---- arch/s390/mm/gmap.c | 28 --------- 6 files changed, 151 insertions(+), 144 deletions(-)
Claudio Imbrenda
maintainerHolding the pte lock for the page that is being converted to secure is needed to avoid races. A previous commit removed the locking, which caused issues. Fix by locking the pte again.
Message-ID: <[email protected]>
--- arch/s390/include/asm/gmap.h | 1 - arch/s390/include/asm/uv.h | 2 +- arch/s390/kernel/uv.c | 136 +++++++++++++++++++++++++++++++++-- arch/s390/kvm/gmap.c | 103 ++------------------------ arch/s390/kvm/kvm-s390.c | 25 ++++--- arch/s390/mm/gmap.c | 28 -------- 6 files changed, 151 insertions(+), 144 deletions(-)
arch/s390/include/asm/gmap.h +0 -1
@@ -139,7 +139,6 @@ int s390_replace_asce(struct gmap *gmap);void s390_uv_destroy_pfns (unsigned long count,unsigned long *pfns);int __s390_uv_destroy_range (struct mm_struct *mm,unsigned long start,unsigned long end,bool interruptible); -int kvm_s390_wiggle_split_folio (struct mm_struct *mm,struct folio *folio,bool split);unsigned long *gmap_table_walk (struct gmap *gmap,unsigned long gaddr,int level);/**
arch/s390/include/asm/uv.h +1 -1
@@ -631,7 +631,7 @@ int uv_pin_shared(unsigned long paddr);int uv_destroy_folio (struct folio *folio);int uv_destroy_pte (pte_t pte);int uv_convert_from_secure_pte (pte_t pte); -int make_folio_secure (struct folio *folio,struct uv_cb_header *uvcb); +int make_hva_secure (struct mm_struct *mm,unsigned long hva,struct uv_cb_header *uvcb);int uv_convert_from_secure (unsigned long paddr);int uv_convert_from_secure_folio (struct folio *folio);
arch/s390/kernel/uv.c +129 -7
169 lines not on this page · raw message
arch/s390/kvm/gmap.c +6 -97
122 lines not on this page · raw message
arch/s390/kvm/kvm-s390.c +15 -10
@@ -4952,6 +4952,7 @@ static int vcpu_post_run_handle_fault(struct kvm_vcpu *vcpu) {unsigned int flags =0 ;unsigned long gaddr; +int rc; gaddr = current->thread.gmap_teid.addr *PAGE_SIZE ;if (kvm_s390_cur_gmap_fault_is_write ())
@@ -4961,16 +4962,6 @@ static int vcpu_post_run_handle_fault(struct kvm_vcpu *vcpu)case 0 : vcpu->stat.exit_null++;break ; -case PGM_NON_SECURE_STORAGE_ACCESS : -kvm_s390_assert_primary_as (vcpu); -/* -* This is normal operation; a page belonging to a protected -* guest has not been imported yet. Try to import the page into -* the protected guest. -*/ -if (gmap_convert_to_secure (vcpu->arch.gmap, gaddr) == -EINVAL ) -send_sig (SIGSEGV , current,0 ); -break ;case PGM_SECURE_STORAGE_ACCESS :case PGM_SECURE_STORAGE_VIOLATION :kvm_s390_assert_primary_as (vcpu);
@@ -4995,6 +4986,20 @@ static int vcpu_post_run_handle_fault(struct kvm_vcpu *vcpu)send_sig (SIGSEGV , current,0 ); }break ; +case PGM_NON_SECURE_STORAGE_ACCESS : +kvm_s390_assert_primary_as (vcpu); +/* +* This is normal operation; a page belonging to a protected +* guest has not been imported yet. Try to import the page into +* the protected guest. +*/ + rc =gmap_convert_to_secure (vcpu->arch.gmap, gaddr); +if (rc == -EINVAL ) +send_sig (SIGSEGV , current,0 ); +if (rc != -ENXIO ) +break ; + flags =FAULT_FLAG_WRITE ; + fallthrough;case PGM_PROTECTION :case PGM_SEGMENT_TRANSLATION :case PGM_PAGE_TRANSLATION :
arch/s390/mm/gmap.c +0 -28
@@ -2626,31 +2626,3 @@ int s390_replace_asce(struct gmap *gmap)return 0 ; }EXPORT_SYMBOL_GPL (s390_replace_asce); - -/** -* kvm_s390_wiggle_split_folio() - try to drain extra references to a folio and optionally split -* @mm: the mm containing the folio to work on -* @folio: the folio -* @split: whether to split a large folio -* -* Context: Must be called while holding an extra reference to the folio; -* the mm lock should not be held. -*/ -int kvm_s390_wiggle_split_folio (struct mm_struct *mm,struct folio *folio,bool split) -{ -int rc; - -lockdep_assert_not_held (&mm->mmap_lock); -folio_wait_writeback (folio); -lru_add_drain_all (); -if (split) { -folio_lock (folio); - rc =split_folio (folio); -folio_unlock (folio); - -if (rc != -EBUSY ) -return rc; - } -return -EAGAIN ; -} -EXPORT_SYMBOL_GPL (kvm_s390_wiggle_split_folio);
Signature · 1 line
2.48.1
Paolo Bonzini
maintainerQuoted 4 lines · Claudio Imbrenda
ciao Paolo,
please pull this late fix for 6.14.
Done, thanks!
Paolo