diff mbox series

[RFC,05/14] fork: check charging success before zeroing stack

Message ID 20240311164638.2015063-6-pasha.tatashin@soleen.com (mailing list archive)
State New
Headers show
Series Dynamic Kernel Stacks | expand

Commit Message

Pasha Tatashin March 11, 2024, 4:46 p.m. UTC
No need to do zero cahced stack if memcg charge fails, so move the
charging attempt before the memset operation.

Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
 kernel/fork.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Kirill A . Shutemov March 12, 2024, 3:57 p.m. UTC | #1
On Mon, Mar 11, 2024 at 04:46:29PM +0000, Pasha Tatashin wrote:
> No need to do zero cahced stack if memcg charge fails, so move the

Typo.
Pasha Tatashin March 12, 2024, 4:52 p.m. UTC | #2
On Tue, Mar 12, 2024 at 11:57 AM Kirill A. Shutemov
<kirill.shutemov@linux.intel.com> wrote:
>
> On Mon, Mar 11, 2024 at 04:46:29PM +0000, Pasha Tatashin wrote:
> > No need to do zero cahced stack if memcg charge fails, so move the
>
> Typo.

Thanks, I will fix this.

>
> --
>   Kiryl Shutsemau / Kirill A. Shutemov
diff mbox series

Patch

diff --git a/kernel/fork.c b/kernel/fork.c
index a35f4008afa0..6a2f2c85e09f 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -271,6 +271,11 @@  static int alloc_thread_stack_node(struct task_struct *tsk, int node)
 		if (!vm_area)
 			continue;
 
+		if (memcg_charge_kernel_stack(vm_area)) {
+			vfree(vm_area->addr);
+			return -ENOMEM;
+		}
+
 		/* Reset stack metadata. */
 		kasan_unpoison_range(vm_area->addr, THREAD_SIZE);
 
@@ -279,11 +284,6 @@  static int alloc_thread_stack_node(struct task_struct *tsk, int node)
 		/* Clear stale pointers from reused stack. */
 		memset(stack, 0, THREAD_SIZE);
 
-		if (memcg_charge_kernel_stack(vm_area)) {
-			vfree(vm_area->addr);
-			return -ENOMEM;
-		}
-
 		tsk->stack_vm_area = vm_area;
 		tsk->stack = stack;
 		return 0;