Skip to contentSkip to conversation

mm/hugetlb.c: teach follow_hugetlb_page() to handle FOLL_NOWAIT

PATCH Applied Andrea Arcangeli 3 participants 4 messages Jan 9, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover mm/hugetlb.c: teach follow_hugetlb_page() to handle FOLL_NOWAIT

Hello,

this fixes a regression that resurfaced in hugetlbfs code after we fixed it for the core VM a few months ago. This is only reproducible doing postcopy live migration of KVM (the only user of FOLL_NOWAIT) if backed by hugetlbfs memory. It's unrelated to userfaultfd, but userfaultfd reproduces it easily because it's an heavy user of VM_FAULT_RETRY retvals.

Thanks,
Andrea

Andrea Arcangeli (1):
mm/hugetlb.c: teach follow_hugetlb_page() to handle FOLL_NOWAIT

 mm/hugetlb.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
#1 lore raw

PATCH 1/1 mm/hugetlb.c: teach follow_hugetlb_page() to handle FOLL_NOWAIT

hugetlb needs the same fix as faultin_nopage (which was applied in 96312e61282ae3f6537a562625706498cbc75594) or KVM hangs because it thinks the mmap_sem was already released by hugetlb_fault() if it returned VM_FAULT_RETRY, but it wasn't in the FOLL_NOWAIT case.

Fixes ce53053ce378 ("kvm: switch get_user_page_nowait() to get_user_pages_unlocked()")
---
 mm/hugetlb.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/hugetlb.c +2 -1
index e37efd5d8318..b3622d7888c8 100644
@@ -4301,7 +4301,8 @@ long follow_hugetlb_page(struct mm_struct *mm, struct vm_area_struct *vma,
 				break;
 			}
 			if (ret & VM_FAULT_RETRY) {
-				if (nonblocking)
+				if (nonblocking &&
+				    !(fault_flags & FAULT_FLAG_RETRY_NOWAIT))
 					*nonblocking = 0;
 				*nr_pages = 0;
 				/*
Reviewed-by on v1 1/1
#2 lore raw
Quoted 9 lines · Andrea Arcangeli

hugetlb needs the same fix as faultin_nopage (which was applied in 96312e61282ae3f6537a562625706498cbc75594) or KVM hangs because it thinks the mmap_sem was already released by hugetlb_fault() if it returned VM_FAULT_RETRY, but it wasn't in the FOLL_NOWAIT case.

Fixes ce53053ce378 ("kvm: switch get_user_page_nowait() to get_user_pages_unlocked()")

Thanks for fixing this.

Signature · 1 line
Mike Kravetz
Quoted 19 lines
---
 mm/hugetlb.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/hugetlb.c +2 -1
index e37efd5d8318..b3622d7888c8 100644
@@ -4301,7 +4301,8 @@ long follow_hugetlb_page(struct mm_struct *mm, struct vm_area_struct *vma,
 				break;
 			}
 			if (ret & VM_FAULT_RETRY) {
-				if (nonblocking)
+				if (nonblocking &&
+				    !(fault_flags & FAULT_FLAG_RETRY_NOWAIT))
 					*nonblocking = 0;
 				*nr_pages = 0;
 				/*
Reviewed-by on v1 1/1
#3 lore raw
In reply to Andrea Arcangeli
Quoted 9 lines · Andrea Arcangeli

hugetlb needs the same fix as faultin_nopage (which was applied in 96312e61282ae3f6537a562625706498cbc75594) or KVM hangs because it thinks the mmap_sem was already released by hugetlb_fault() if it returned VM_FAULT_RETRY, but it wasn't in the FOLL_NOWAIT case.

Fixes ce53053ce378 ("kvm: switch get_user_page_nowait() to get_user_pages_unlocked()")

FWIW:

Quoted 9 lines
---
 mm/hugetlb.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/hugetlb.c +0 -0
index e37efd5d8318..b3622d7888c8 100644

mm/hugetlb.c long follow_hugetlb_page(struct mm_struct *mm, struct vm_area_struct *vma, · line 4308

Quoted 9 lines
mm/hugetlb.c +2 -1
@@ -4301,7 +4301,8 @@ long follow_hugetlb_page(struct mm_struct *mm, struct vm_area_struct *vma,
 				break;
 			}
 			if (ret & VM_FAULT_RETRY) {
-				if (nonblocking)
+				if (nonblocking &&
+				    !(fault_flags & FAULT_FLAG_RETRY_NOWAIT))
 					*nonblocking = 0;
 				*nr_pages = 0;
 				/*

Regards,

Signature · 1 line
Peter Xu