Skip to contentSkip to conversation

x86/sgx: Add missing xa_destroy() when virtual EPC is destroyed

PATCH In review Kai Huang 3 participants 7 messages Jun 16, 2021 – Jun 25, 2021

Subsystems (2)
lore
Share & tools
lore

Kai Huang

author
#0 lore raw

PATCH v2 1/1 x86/sgx: Add missing xa_destroy() when virtual EPC is destroyed

xa_destroy() needs to be called to destroy virtual EPC's page array before calling kfree() to free the virtual EPC. Currently it is not called. Add the missing xa_destroy() to fix.

Fixes 540745ddbc70 ("x86/sgx: Introduce virtual EPC for use by KVM guests")

---
v1->v2:

- Fixed typo in commit msg
- Added Dave's Acked-by

---
 arch/x86/kernel/cpu/sgx/virt.c | 1 +
 1 file changed, 1 insertion(+)
arch/x86/kernel/cpu/sgx/virt.c +1 -0
index 6ad165a5c0cc..64511c4a5200 100644
@@ -212,6 +212,7 @@ static int sgx_vepc_release(struct inode *inode, struct file *file)
 		list_splice_tail(&secs_pages, &zombie_secs_pages);
 	mutex_unlock(&zombie_secs_pages_lock);
 
+	xa_destroy(&vepc->page_array);
 	kfree(vepc);
 
 	return 0;
Signature · 1 line
2.31.1
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 lines · Kai Huang

xa_destroy() needs to be called to destroy virtual EPC's page array before calling kfree() to free the virtual EPC. Currently it is not called. Add the missing xa_destroy() to fix.

Fixes 540745ddbc70 ("x86/sgx: Introduce virtual EPC for use by KVM guests")
Quoted 25 lines

---
v1->v2:

- Fixed typo in commit msg
- Added Dave's Acked-by

---
 arch/x86/kernel/cpu/sgx/virt.c | 1 +
 1 file changed, 1 insertion(+)
arch/x86/kernel/cpu/sgx/virt.c +1 -0
index 6ad165a5c0cc..64511c4a5200 100644
@@ -212,6 +212,7 @@ static int sgx_vepc_release(struct inode *inode, struct file *file)
 		list_splice_tail(&secs_pages, &zombie_secs_pages);
 	mutex_unlock(&zombie_secs_pages_lock);
 
+	xa_destroy(&vepc->page_array);
 	kfree(vepc);
 
 	return 0;
Signature · 1 line
2.31.1

/Jarkko

author
#2 lore raw
Quoted 5 lines · Jarkko Sakkinen
Quoted 4 lines · Kai Huang

xa_destroy() needs to be called to destroy virtual EPC's page array before calling kfree() to free the virtual EPC. Currently it is not called. Add the missing xa_destroy() to fix.

Quoted 7 lines
Quoted 4 lines
Fixes 540745ddbc70 ("x86/sgx: Introduce virtual EPC for use by KVM guests")

Thanks Jarkko.

Hi Boris,

Should we consider to get this into 5.13, since it is a fix?

Quoted 28 lines
Quoted 26 lines

---
v1->v2:

- Fixed typo in commit msg
- Added Dave's Acked-by

---
 arch/x86/kernel/cpu/sgx/virt.c | 1 +
 1 file changed, 1 insertion(+)
arch/x86/kernel/cpu/sgx/virt.c +1 -0
index 6ad165a5c0cc..64511c4a5200 100644
@@ -212,6 +212,7 @@ static int sgx_vepc_release(struct inode *inode, struct file *file)
 		list_splice_tail(&secs_pages, &zombie_secs_pages);
 	mutex_unlock(&zombie_secs_pages_lock);
 
+	xa_destroy(&vepc->page_array);
 	kfree(vepc);
 
 	return 0;
Signature · 1 line
2.31.1

/Jarkko

maintainer
#3 lore raw
Quoted 1 line · Kai Huang

Should we consider to get this into 5.13, since it is a fix?

We have considered it, have queued it, you're on Cc on the tip-bot notification:

https://lkml.kernel.org/r/162377378414.19906.6678244614782222506.tip-bot2@tip-bot2

In the meantime, that fix landed upstream and will be in 5.13:

4692bc775d21 ("x86/sgx: Add missing xa_destroy() when virtual EPC is destroyed")

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author
#4 lore raw
Quoted 12 lines · Borislav Petkov
Quoted 1 line · Kai Huang

Should we consider to get this into 5.13, since it is a fix?

We have considered it, have queued it, you're on Cc on the tip-bot notification:

https://lkml.kernel.org/r/162377378414.19906.6678244614782222506.tip-bot2@tip-bot2

In the meantime, that fix landed upstream and will be in 5.13:

4692bc775d21 ("x86/sgx: Add missing xa_destroy() when virtual EPC is destroyed")

Oh sorry I thought the patch would go via x86/sgx branch, and I didn't monitor the tip-bot2 mail which was moved to my local x86 folder. Thanks!

maintainer
#5 lore raw
Quoted 1 line · Kai Huang

Oh sorry I thought the patch would go via x86/sgx branch

We usually send fixes through tip's urgent branches because they go straight to Linus and not wait for the merge window.

Quoted 2 lines

and I didn't monitor the tip-bot2 mail which was moved to my local x86 folder.

That's not optimal because those tip-bot notifications are *exactly* for that - to let the involved parties know that the patch has been queued.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author
#6 lore raw
Quoted 12 lines · Borislav Petkov
Quoted 1 line · Kai Huang

Oh sorry I thought the patch would go via x86/sgx branch

We usually send fixes through tip's urgent branches because they go straight to Linus and not wait for the merge window.

Quoted 2 lines

and I didn't monitor the tip-bot2 mail which was moved to my local x86 folder.

That's not optimal because those tip-bot notifications are *exactly* for that - to let the involved parties know that the patch has been queued.

Got it. Thanks for remaindering.