Skip to contentSkip to conversation

KVM: No need to retry for hva_to_pfn_remapped()

PATCH Applied Peter Xu 2 participants 5 messages Apr 16, 2020 – May 29, 2020 KVM

lore
Share & tools
lore

Peter Xu

author
#0 lore raw

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
index 2f1f2f56e93d..6aaed69641a5 100644
@@ -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
maintainer Applied
#1 lore raw
Quoted 31 lines · Peter Xu

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 -3
index 2f1f2f56e93d..6aaed69641a5 100644
@@ -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 -2
 
 	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 {

Queued, thanks.

Paolo

author
#2 lore raw
Quoted 32 lines · Paolo Bonzini
Quoted 31 lines · Peter Xu

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 -3
index 2f1f2f56e93d..6aaed69641a5 100644
@@ -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 -2
 	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 {

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
maintainer
#3 lore raw
Quoted 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

maintainer
#4 lore raw
In reply to Peter Xu
Quoted 2 lines · Peter Xu

Even if "unlocked" is set to true, it
means that we've got a VM_FAULT_RETRY inside fixup_user_fault(),

I have just reverted it. Thanks!

Paolo