KVM: No need to retry for hva_to_pfn_remapped()
PATCH 1/1 KVM: No need to retry for hva_to_pfn_remapped()
hva_to_pfn_remapped() calls fixup_user_fault(), which has already handled the retry gracefully. Even if "unlocked" is set to true, it means that we've got a VM_FAULT_RETRY inside fixup_user_fault(), however the page fault has already retried and we should have the pfn set correctly. No need to do that again.
--- virt/kvm/kvm_main.c | 5 ----- 1 file changed, 5 deletions(-)
virt/kvm/kvm_main.c +0 -5
@@ -1824,8 +1824,6 @@ static int hva_to_pfn_remapped(struct vm_area_struct *vma, r =fixup_user_fault (current, current->mm, addr, (write_fault ?FAULT_FLAG_WRITE :0 ), &unlocked); -if (unlocked) -return -EAGAIN ;if (r)return r;
@@ -1896,15 +1894,12 @@ static kvm_pfn_t hva_to_pfn(unsigned long addr, bool atomic, bool *async, goto exit; } -retry: vma =find_vma_intersection (current->mm, addr, addr +1 );if (vma ==NULL ) pfn =KVM_PFN_ERR_FAULT ;else if (vma->vm_flags & (VM_IO |VM_PFNMAP )) { r =hva_to_pfn_remapped (vma, addr, write_fault, writable, &pfn); -if (r == -EAGAIN ) - goto retry;if (r <0 ) pfn =KVM_PFN_ERR_FAULT ; }else {
Signature · 1 line
2.24.1
Quoted 31 lines · Peter Xu
hva_to_pfn_remapped()callsfixup_user_fault(), which has already handled the retry gracefully. Even if "unlocked" is set to true, it means that we've got aVM_FAULT_RETRYinsidefixup_user_fault(), however the page fault has already retried and we should have the pfn set correctly. No need to do that again.Signed-off-by Peter Xu <[email protected]>--- virt/kvm/kvm_main.c | 5 ----- 1 file changed, 5 deletions(-)virt/kvm/kvm_main.c +0
-3@@ -1824,8 +1824,6 @@ static int hva_to_pfn_remapped(struct vm_area_struct *vma, r =fixup_user_fault (current, current->mm, addr, (write_fault ?FAULT_FLAG_WRITE :0 ), &unlocked); -if (unlocked) -return -EAGAIN ;if (r)return r;@@ -1896,15 +1894,12 @@ static kvm_pfn_t hva_to_pfn(unsigned long addr, bool atomic, bool *async, goto exit; } -retry: vma =find_vma_intersection (current->mm, addr, addr +1 );
virt/kvm/kvm_main.c static kvm_pfn_t hva_to_pfn(unsigned long addr, bool atomic, bool *async, · line 1905
Quoted 10 lines
virt/kvm/kvm_main.c +0
-2if (vma ==NULL ) pfn =KVM_PFN_ERR_FAULT ;else if (vma->vm_flags & (VM_IO |VM_PFNMAP )) { r =hva_to_pfn_remapped (vma, addr, write_fault, writable, &pfn); -if (r == -EAGAIN ) - goto retry;if (r <0 ) pfn =KVM_PFN_ERR_FAULT ; }else {
Queued, thanks.
Paolo
Quoted 32 lines · Paolo Bonzini
Quoted 31 lines · Peter Xu
hva_to_pfn_remapped()callsfixup_user_fault(), which has already handled the retry gracefully. Even if "unlocked" is set to true, it means that we've got aVM_FAULT_RETRYinsidefixup_user_fault(), however the page fault has already retried and we should have the pfn set correctly. No need to do that again.Signed-off-by Peter Xu <[email protected]>--- virt/kvm/kvm_main.c | 5 ----- 1 file changed, 5 deletions(-)virt/kvm/kvm_main.c +0
-3@@ -1824,8 +1824,6 @@ static int hva_to_pfn_remapped(struct vm_area_struct *vma, r =fixup_user_fault (current, current->mm, addr, (write_fault ?FAULT_FLAG_WRITE :0 ), &unlocked); -if (unlocked) -return -EAGAIN ;if (r)return r;@@ -1896,15 +1894,12 @@ static kvm_pfn_t hva_to_pfn(unsigned long addr, bool atomic, bool *async, goto exit; } -retry: vma =find_vma_intersection (current->mm, addr, addr +1 );
Quoted 12 lines
virt/kvm/kvm_main.c static kvm_pfn_t hva_to_pfn(unsigned long addr, bool atomic, bool *async, · line 1905
Quoted 10 lines
virt/kvm/kvm_main.c +0
-2if (vma ==NULL ) pfn =KVM_PFN_ERR_FAULT ;else if (vma->vm_flags & (VM_IO |VM_PFNMAP )) { r =hva_to_pfn_remapped (vma, addr, write_fault, writable, &pfn); -if (r == -EAGAIN ) - goto retry;if (r <0 ) pfn =KVM_PFN_ERR_FAULT ; }else {Queued, thanks.
Paolo, Is it still possible to unqueue this patch? I overlooked the fact that if unlocked==true then the vma pointer could be invalidated, so the 2nd follow_pfn() is potentially racy. Sorry for the trouble!
Signature · 1 line
Peter Xu
Paolo Bonzini
maintainerQuoted 6 lines · Peter Xu
Quoted 1 line
Queued, thanks.
Paolo, Is it still possible to unqueue this patch? I overlooked the fact that if unlocked==true then the vma pointer could be invalidated, so the 2nd
follow_pfn()is potentially racy. Sorry for the trouble!
Sure, thanks.
Paolo
Paolo Bonzini
maintainerQuoted 2 lines · Peter Xu
Even if "unlocked" is set to true, it
means that we've got aVM_FAULT_RETRYinsidefixup_user_fault(),
I have just reverted it. Thanks!
Paolo