From patchwork Mon Mar 11 16:46:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13589081 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34486C54E58 for ; Mon, 11 Mar 2024 16:47:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BB30C6B00D0; Mon, 11 Mar 2024 12:46:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B36C16B00D1; Mon, 11 Mar 2024 12:46:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 961136B00D2; Mon, 11 Mar 2024 12:46:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 7FBA06B00D0 for ; Mon, 11 Mar 2024 12:46:52 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4F5A81404F9 for ; Mon, 11 Mar 2024 16:46:52 +0000 (UTC) X-FDA: 81885337464.01.6D6006A Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.169]) by imf09.hostedemail.com (Postfix) with ESMTP id 9613914002C for ; Mon, 11 Mar 2024 16:46:50 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=CjU1balY; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf09.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.167.169 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710175610; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=85s92hjYUuufTOzCHiSH6hattUyZa1ZbNxNbo2SWk2c=; b=tmcsTVSfcuXBJHFq1RlcHklbeTkY+8qu+66scyYcZUCG0wpENImKkyfOjvf1pcAe887mIb HC0gjYwd9uVHE75sQG7U874wilQHpa/dEIwnpudpi6DsM9/gcFWsnws9798u3P4TsQqnwv Xz2KZLS5e8HmG6TGLeyAPvFWw3KU340= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=CjU1balY; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf09.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.167.169 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710175610; a=rsa-sha256; cv=none; b=1sChIMJKbxXL3vgn4xUDdM5/89n/ok5kH/sLnuikT/tmmPUzb2Mh+NBehj0yTlo17G3oWm Q9JiryvlOosVWpOZUM6I9xJD5nNEiwFjMtRrvRhz5/Rmu6NSUQjcNxU0/RkS0ZyMrTxO+i wSSkIHpRWHHbTfwloOc/N41CLYb2ssI= Received: by mail-oi1-f169.google.com with SMTP id 5614622812f47-3c19b7d9de7so3130545b6e.2 for ; Mon, 11 Mar 2024 09:46:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1710175610; x=1710780410; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=85s92hjYUuufTOzCHiSH6hattUyZa1ZbNxNbo2SWk2c=; b=CjU1balY7rK3bDNcI4qQ852zLFfRHcecPorCeOMGrNZoPwNJLje1m71aeeQUp3dmX6 KwaIasjil6w4fJ8trGxJKUwuQoX89xEt+lOMm4iSLCoDasJSAA3k02Dvl93dsWK3Ho0J CvUg3ntTYK0extWx/yohCcxPETh5A1gWTApr7LqAkP4I0GBD2t/nF1eZUhbcOytp8LmR L9Oco8jHm7tpAoMPqgg5tuQHIbHcqdfifPQCZL3nZVws88zq8SP7QmmG6j+qYRnAnRUK +VP4y3BUdNGuiTiL/j1mLY4G92rBxJojQIbl5FB6NXRJ8QcLAzMgc7EsyNZWFq6Fqed1 jMHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710175610; x=1710780410; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=85s92hjYUuufTOzCHiSH6hattUyZa1ZbNxNbo2SWk2c=; b=LORF4Rqqj3VXE/ZzOOWLZUscE8GdHpcs2j7J1KZa9osJOofg9wFeuYm5L+B9D3QcBW jifBXB1OyJkp+jQtiUfc1p6pF+4Ro1/58TdWHD5kzLWhCwI16vbZzKbrHsCKR8S7NGfh zxqC8yvIPYG94u2cpuxamiIpEDCbXEuH/+lRN0zQPDZcfIvAE20pJ83PGKzf1EwOsO3v 1hKcneTj8ilY3Wjw7QUEJkMXuOvCeuC259ghyXg7vOJKnCfeNNtKr11CG0P5XAZIuTbi DdqM8bwhcRHqvzSseyfeDIAMv2ULyLnFLwUpmPC58FxDp+z6uNgnZO3/HVTUaoQosTy7 lBKg== X-Forwarded-Encrypted: i=1; AJvYcCXYWAnfodebxf4n1Z2fHOwi0mA6oBJvZH8EsXfzSFV/knjiqSSAx1eq638zCVpmaEfsEVIk3E2Vjw8USY0BqldyGNM= X-Gm-Message-State: AOJu0YzYNRwsPRl+XItALK8XEz5llsISgHGNnGC4neh/Au5mMRyg/MiS eT2e0oWMYYNyitTbOsAgV0MDTp8ioCWAeDvlswtHQ5RZY6tdEVafQ9cGVO4MLsQ= X-Google-Smtp-Source: AGHT+IF0sA8TBoTxey5vp022o4Baok5dPg7vNZ4pcZt1EEyuyh5oG+THj2Y1Wu2BsuZNYuYtVQC9/Q== X-Received: by 2002:a05:6808:15aa:b0:3c2:1262:e04a with SMTP id t42-20020a05680815aa00b003c21262e04amr8114898oiw.1.1710175608379; Mon, 11 Mar 2024 09:46:48 -0700 (PDT) Received: from soleen.c.googlers.com.com (150.254.86.34.bc.googleusercontent.com. [34.86.254.150]) by smtp.gmail.com with ESMTPSA id d27-20020a05620a137b00b00788228fbe05sm2851589qkl.17.2024.03.11.09.46.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 09:46:47 -0700 (PDT) From: Pasha Tatashin To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, x86@kernel.org, bp@alien8.de, brauner@kernel.org, bristot@redhat.com, bsegall@google.com, dave.hansen@linux.intel.com, dianders@chromium.org, dietmar.eggemann@arm.com, eric.devolder@oracle.com, hca@linux.ibm.com, hch@infradead.org, hpa@zytor.com, jacob.jun.pan@linux.intel.com, jgg@ziepe.ca, jpoimboe@kernel.org, jroedel@suse.de, juri.lelli@redhat.com, kent.overstreet@linux.dev, kinseyho@google.com, kirill.shutemov@linux.intel.com, lstoakes@gmail.com, luto@kernel.org, mgorman@suse.de, mic@digikod.net, michael.christie@oracle.com, mingo@redhat.com, mjguzik@gmail.com, mst@redhat.com, npiggin@gmail.com, peterz@infradead.org, pmladek@suse.com, rick.p.edgecombe@intel.com, rostedt@goodmis.org, surenb@google.com, tglx@linutronix.de, urezki@gmail.com, vincent.guittot@linaro.org, vschneid@redhat.com, pasha.tatashin@soleen.com Subject: [RFC 05/14] fork: check charging success before zeroing stack Date: Mon, 11 Mar 2024 16:46:29 +0000 Message-ID: <20240311164638.2015063-6-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog In-Reply-To: <20240311164638.2015063-1-pasha.tatashin@soleen.com> References: <20240311164638.2015063-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 9613914002C X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: rp5853m41ucse8tzjs1484nntbbdi3e3 X-HE-Tag: 1710175610-938550 X-HE-Meta: U2FsdGVkX184FeXaxgoeQgcVQXXxtIFUtBlOJQEHkr9kJCPWF4MDwjdt17LVBI0j0+F3LvFe7avnlprrHgSarQHZ2XzJBsbGUH3tNW0mWn4bywu8T+cs1D9fjbaSTRUHYFLiCkfrG+pFC7W3fmJ+22Ii2sQ4XGrNs/9h7dcwUszkMFGI0eh4LsdUj7SREClL+/j47mQZSNMKMGMpYQ3RHo6IQj/GLMPXyl1zGw7sgGmP6IN4HYT6/pk5XSWTHRL1o8nCiYrhTwAyqNCJl8Px3Cf2j9xn6M43xVPnZhPQjpw0w+ogfhNvydzkJ/c6S3YnuxLpZ0C91ppyUZCqj5ErSVaORB2/1eLi60fMsBkQxObQd/Rop5ij/AZ8yrDceKrzDgxdDfHUGQA32sP/uo1kGI+vdzR67L/5Lo3QClP6oSnKqlcGDOdLIEB+voqrbirAG7yIBhgvzwY2ajh2kBzZ6981cMjtQlsWLsBglIm1LnbacAOFXuwtPPe6ZxfOLDiJtRClzvfzu8VtKDlITY9voMM1ul7MHshAFsqoBegINTxeqMk5huzToe4dOAYR1VCN/1yoCOOIauN0AoFNvmX8byr6dA5miKZH15qWFgO1Uz5m+UTWkuw5AwVBXBSsZ1uXyaFwNB6zQBaMnTsz4yqozA58rD9zCTyPt3KCc7J3i9SSWtCAq+bkDPfeB/SEE+WYX0WlJjJB/QgHafGQBv5/NYe5BfznxxURRHHtA9bRnlkTvrLaHLgDnB+1bMBVxuwzgwjjCyBFPBHEtDGGNl0UZ2Y9R/nGJPGQYwu99TFNtqQd8e5UeW4w4yH3ozQznYyqGZAWYtLahmnAHfpPr/EDVbgf1P7giUZNawJyN7bCvuutccG+WQFRd6yPYpKXIPAqGMrxwFXYHfI2hWsYThLjXmeeq47DMejCxxZ+KVHAYtDGWrlZkdtZx7/z7eyVt4Xja5InFVSiT6CiV4do/Fj efyKM9bF dhIl5rECrPbg63SWpblJFKGu7RzuMoQexNKejwrROLvFMwhLkPHgXZiyonp7K1+DqsjDIcYBdHeYCZdP88RtODa25vT70ncIOL0eHLw0CFfjukV3Ej04XY0UiLVB5H4nM5mY75XiU6ZcdDacEvV4G8Htd4Gh9rnR+U8mZa73foawnOaY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000272, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 --- kernel/fork.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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;