Skip to contentSkip to conversation

x86/sgx: handle VA page allocation failure for EAUG on PF.

PATCH In review Haitao Huang 3 participants 7 messages Aug 12, 2022 – Aug 16, 2022

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

PATCH 1/1 x86/sgx: handle VA page allocation failure for EAUG on PF.

Return VM_FAULT_NOPAGE to allow the swapping thread to catch up.

---
 arch/x86/kernel/cpu/sgx/encl.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/sgx/encl.c +5 -2
index 24c1bb8eb196..1f88f80c4477 100644
@@ -344,8 +344,11 @@ static vm_fault_t sgx_encl_eaug_page(struct vm_area_struct *vma,
 	}
 
 	va_page = sgx_encl_grow(encl, false);
-	if (IS_ERR(va_page))
-		goto err_out_epc;
+	if (IS_ERR(va_page)) {
+        if (PTR_ERR(va_page) == -EBUSY)
+            vmret =  VM_FAULT_NOPAGE;
+        goto err_out_epc;
+    }
 
 	if (va_page)
 		list_add(&va_page->list, &encl->va_pages);
Signature · 1 line
2.25.1
Tested-by on v1 1/1
#1 lore raw

Hi Haitao,

Quoted 36 lines

-----Original Message-----
From: Haitao Huang <[email protected]>
Sent: Friday, August 12, 2022 12:12 PM
To: [email protected]; [email protected]; Chatre, Reinette <[email protected]>; [email protected]; Dhanraj, Vijay <[email protected]>
Subject: [PATCH] x86/sgx: handle VA page allocation failure for EAUG on PF.

Return VM_FAULT_NOPAGE to allow the swapping thread to catch up.

[email protected]/

---
 arch/x86/kernel/cpu/sgx/encl.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/sgx/encl.c +5 -2
index 24c1bb8eb196..1f88f80c4477 100644
@@ -344,8 +344,11 @@ static vm_fault_t sgx_encl_eaug_page(struct
 vm_area_struct *vma,
 	}
 
 	va_page = sgx_encl_grow(encl, false);
-	if (IS_ERR(va_page))
-		goto err_out_epc;
+	if (IS_ERR(va_page)) {
+        if (PTR_ERR(va_page) == -EBUSY)
+            vmret =  VM_FAULT_NOPAGE;
+        goto err_out_epc;
+    }
 
 	if (va_page)
Quoted 3 lines

list_add(&va_page->list, &encl->va_pages);
--
2.25.1

After applying this patch, I don't see the allocation failure issue with augment_via_eaccept_long test case. Ran the test for about ~60 times and all the time it passes.

#2 lore raw
Quoted 37 lines · Vijay

Hi Haitao,

Quoted 35 lines

-----Original Message-----
From: Haitao Huang <[email protected]>
Sent: Friday, August 12, 2022 12:12 PM
To: [email protected]; [email protected]; Chatre, Reinette <[email protected]>; [email protected]; Dhanraj, Vijay <[email protected]>
Subject: [PATCH] x86/sgx: handle VA page allocation failure for EAUG on PF.

Return VM_FAULT_NOPAGE to allow the swapping thread to catch up.

[email protected]/

 arch/x86/kernel/cpu/sgx/encl.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/sgx/encl.c +5 -2
index 24c1bb8eb196..1f88f80c4477 100644
@@ -344,8 +344,11 @@ static vm_fault_t sgx_encl_eaug_page(struct
 vm_area_struct *vma,
 	}
 
 	va_page = sgx_encl_grow(encl, false);
-	if (IS_ERR(va_page))
-		goto err_out_epc;
+	if (IS_ERR(va_page)) {
+        if (PTR_ERR(va_page) == -EBUSY)
+            vmret =  VM_FAULT_NOPAGE;
+        goto err_out_epc;
+    }
 
Quoted 7 lines
Quoted 4 lines
arch/x86/kernel/cpu/sgx/encl.c +0 -0
 	if (va_page)

list_add(&va_page->list, &encl->va_pages);
--
2.25.1

After applying this patch, I don't see the allocation failure issue with augment_via_eaccept_long test case. Ran the test for about ~60 times and all the time it passes.

Good to hear. Thank you.

BR, Jarkko

maintainer
#3 lore raw
In reply to Haitao Huang
Quoted 30 lines · Haitao Huang

Return VM_FAULT_NOPAGE to allow the swapping thread to catch up.

---
 arch/x86/kernel/cpu/sgx/encl.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/sgx/encl.c +5 -2
index 24c1bb8eb196..1f88f80c4477 100644
@@ -344,8 +344,11 @@ static vm_fault_t sgx_encl_eaug_page(struct vm_area_struct *vma,
 	}
 
 	va_page = sgx_encl_grow(encl, false);
-	if (IS_ERR(va_page))
-		goto err_out_epc;
+	if (IS_ERR(va_page)) {
+        if (PTR_ERR(va_page) == -EBUSY)
+            vmret =  VM_FAULT_NOPAGE;
+        goto err_out_epc;
+    }
 
 	if (va_page)
 		list_add(&va_page->list, &encl->va_pages);
Signature · 1 line
2.25.1

Indentation is probably not right, but the fix look legit.

You need to use real tab-characters to fix that. Run the patch with scripts/checkpatch.pl and it will report you these issues.

Vijay, can you check if this fixes the issue for you?

BR, Jarkko

#4 lore raw

PATCH 1/1 x86/sgx: handle VA page allocation failure for EAUG on PF.

Return VM_FAULT_NOPAGE to allow the swapping thread to catch up.

---
 arch/x86/kernel/cpu/sgx/encl.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/sgx/encl.c +4 -1
index 24c1bb8eb196..de92c1c8b79d 100644
@@ -344,8 +344,11 @@ static vm_fault_t sgx_encl_eaug_page(struct vm_area_struct *vma,
 	}
 
 	va_page = sgx_encl_grow(encl, false);
-	if (IS_ERR(va_page))
+	if (IS_ERR(va_page)) {
+		if (PTR_ERR(va_page) == -EBUSY)
+			vmret =  VM_FAULT_NOPAGE;
 		goto err_out_epc;
+	}
 
 	if (va_page)
 		list_add(&va_page->list, &encl->va_pages);
Signature · 1 line
2.25.1
maintainer Reviewed-by on v1 1/1
#5 lore raw
Quoted 29 lines · Haitao Huang

Return VM_FAULT_NOPAGE to allow the swapping thread to catch up.

---
 arch/x86/kernel/cpu/sgx/encl.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/sgx/encl.c +4 -1
index 24c1bb8eb196..de92c1c8b79d 100644
@@ -344,8 +344,11 @@ static vm_fault_t sgx_encl_eaug_page(struct vm_area_struct *vma,
 	}
 
 	va_page = sgx_encl_grow(encl, false);
-	if (IS_ERR(va_page))
+	if (IS_ERR(va_page)) {
+		if (PTR_ERR(va_page) == -EBUSY)
+			vmret =  VM_FAULT_NOPAGE;
 		goto err_out_epc;
+	}
 
 	if (va_page)
 		list_add(&va_page->list, &encl->va_pages);
Signature · 1 line
2.25.1

BR, Jarkko

#6 lore raw
In reply to Jarkko Sakkinen
Quoted 27 lines · Jarkko Sakkinen
Quoted 26 lines · Haitao Huang

Return VM_FAULT_NOPAGE to allow the swapping thread to catch up.

---
 arch/x86/kernel/cpu/sgx/encl.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/sgx/encl.c +5 -2
index 24c1bb8eb196..1f88f80c4477 100644
@@ -344,8 +344,11 @@ static vm_fault_t sgx_encl_eaug_page(struct  
 vm_area_struct *vma,
 	}
 
 	va_page = sgx_encl_grow(encl, false);
-	if (IS_ERR(va_page))
-		goto err_out_epc;
+	if (IS_ERR(va_page)) {
+        if (PTR_ERR(va_page) == -EBUSY)
+            vmret =  VM_FAULT_NOPAGE;
+        goto err_out_epc;
+    }
 
Quoted 7 lines
Quoted 5 lines
arch/x86/kernel/cpu/sgx/encl.c +0 -0
 	if (va_page)

list_add(&va_page->list, &encl->va_pages);
--
2.25.1

Indentation is probably not right, but the fix look legit.

Fixed in updated patch. Can I add your "Reviewed-by" tag? Thanks
Haitao