KVM: s390: fix a newly introduced bug
Claudio Imbrenda
maintainerv5 cover KVM: s390: fix a newly introduced bug
Fix race when making a page secure (hold pte lock again)
This should fix the issues I have seen, which I think/hope are also the same issues that David found.
v4->v5:
* fixed kerneldoc for s390_wiggle_split_folio()
* remove get_locked_valid_pte() and replace it with folio_walk_start() [thanks David]
v3->v4:
* move and rename s390_wiggle_split_folio() to fix a compile issue when KVM is not selected
* removed obsolete reference to __() from comments
v2->v3:
* added check for pte_write() in make_hva_secure() [thanks David]
v1->v2:
* major refactoring
* walk the page tables only once
* when importing, manually fault in pages if needed
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(-)
Signature · 1 line
2.48.1
Claudio Imbrenda
maintainerPATCH v5 1/1 KVM: s390: pv: fix race when making a page secure
Holding 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.
--- 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