From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F0AC481A6 for ; Mon, 19 Feb 2024 18:11:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708366305; cv=none; b=K0Wb3DU86V5mf2yeM1d3dTKNrQtIdPThmeFIIjbIJleZKgvCZ+PQy9AwTn9GEIGRVwoIkygea9QxxkO3rJ4xY+4aJ2Yv0YFZgBuC3qwJ++Vx7InQHHMDYVOEfQW/GR8LAMM4vtxbn54o4KJIGqBbOFGbM3sYN1FdZ3W6ggI3OA8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708366305; c=relaxed/simple; bh=b1Fyge75aUFtR6Sg/3IhEFUXeOpecKNdoE5z4cnduLk=; h=Subject:To:Cc:From:Date:Message-ID:MIME-Version:Content-Type; b=L91WremQMiiv5WFKVLi7FJ17WlNnN/4r/ium/pfrqiAaN3JcPYhZ4QUL4keq52y+TzcNjv9zX3ciQ81vze+OwV9u9i/2bbhG8ODNyObo+afdPMlBhAzgzumBX9q33+rjgpwIalg2UM42+T5sKWbjWH1UmWi80OcOsZH/BBVMecI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=qtLHiQRn; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="qtLHiQRn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 404BEC433C7; Mon, 19 Feb 2024 18:11:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1708366304; bh=b1Fyge75aUFtR6Sg/3IhEFUXeOpecKNdoE5z4cnduLk=; h=Subject:To:Cc:From:Date:From; b=qtLHiQRnmxAe9Rtym/10C1hi4mS/qTmmOp1aonRQmlKvfEwSKEoxVA//NYP+klykq SMMoURa4kawo9qT2PCweCI+kvIScVgwViCXg1ByjYuro8q3UMe6OIWwIRaU+HkSz3x V67V827BM9VBGToWKBgSpybyJYshdh51E9mBc9s0= Subject: FAILED: patch "[PATCH] getrusage: move thread_group_cputime_adjusted() outside of" failed to apply to 4.19-stable tree To: oleg@redhat.com,akpm@linux-foundation.org,dylanbhatch@google.com,ebiederm@xmission.com,stable@vger.kernel.org Cc: From: Date: Mon, 19 Feb 2024 19:11:26 +0100 Message-ID: <2024021926-fretted-situation-ed0b@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit The patch below does not apply to the 4.19-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-4.19.y git checkout FETCH_HEAD git cherry-pick -x daa694e4137571b4ebec330f9a9b4d54aa8b8089 # git commit -s git send-email --to '' --in-reply-to '2024021926-fretted-situation-ed0b@gregkh' --subject-prefix 'PATCH 4.19.y' HEAD^.. Possible dependencies: daa694e41375 ("getrusage: move thread_group_cputime_adjusted() outside of lock_task_sighand()") c7ac8231ace9 ("getrusage: add the "signal_struct *sig" local variable") bdd565f817a7 ("y2038: rusage: use __kernel_old_timeval") thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From daa694e4137571b4ebec330f9a9b4d54aa8b8089 Mon Sep 17 00:00:00 2001 From: Oleg Nesterov Date: Mon, 22 Jan 2024 16:50:50 +0100 Subject: [PATCH] getrusage: move thread_group_cputime_adjusted() outside of lock_task_sighand() Patch series "getrusage: use sig->stats_lock", v2. This patch (of 2): thread_group_cputime() does its own locking, we can safely shift thread_group_cputime_adjusted() which does another for_each_thread loop outside of ->siglock protected section. This is also preparation for the next patch which changes getrusage() to use stats_lock instead of siglock, thread_group_cputime() takes the same lock. With the current implementation recursive read_seqbegin_or_lock() is fine, thread_group_cputime() can't enter the slow mode if the caller holds stats_lock, yet this looks more safe and better performance-wise. Link: https://lkml.kernel.org/r/20240122155023.GA26169@redhat.com Link: https://lkml.kernel.org/r/20240122155050.GA26205@redhat.com Signed-off-by: Oleg Nesterov Reported-by: Dylan Hatch Tested-by: Dylan Hatch Cc: Eric W. Biederman Cc: Signed-off-by: Andrew Morton diff --git a/kernel/sys.c b/kernel/sys.c index e219fcfa112d..70ad06ad852e 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -1785,17 +1785,19 @@ void getrusage(struct task_struct *p, int who, struct rusage *r) struct task_struct *t; unsigned long flags; u64 tgutime, tgstime, utime, stime; - unsigned long maxrss = 0; + unsigned long maxrss; + struct mm_struct *mm; struct signal_struct *sig = p->signal; - memset((char *)r, 0, sizeof (*r)); + memset(r, 0, sizeof(*r)); utime = stime = 0; + maxrss = 0; if (who == RUSAGE_THREAD) { task_cputime_adjusted(current, &utime, &stime); accumulate_thread_rusage(p, r); maxrss = sig->maxrss; - goto out; + goto out_thread; } if (!lock_task_sighand(p, &flags)) @@ -1819,9 +1821,6 @@ void getrusage(struct task_struct *p, int who, struct rusage *r) fallthrough; case RUSAGE_SELF: - thread_group_cputime_adjusted(p, &tgutime, &tgstime); - utime += tgutime; - stime += tgstime; r->ru_nvcsw += sig->nvcsw; r->ru_nivcsw += sig->nivcsw; r->ru_minflt += sig->min_flt; @@ -1839,19 +1838,24 @@ void getrusage(struct task_struct *p, int who, struct rusage *r) } unlock_task_sighand(p, &flags); -out: + if (who == RUSAGE_CHILDREN) + goto out_children; + + thread_group_cputime_adjusted(p, &tgutime, &tgstime); + utime += tgutime; + stime += tgstime; + +out_thread: + mm = get_task_mm(p); + if (mm) { + setmax_mm_hiwater_rss(&maxrss, mm); + mmput(mm); + } + +out_children: + r->ru_maxrss = maxrss * (PAGE_SIZE / 1024); /* convert pages to KBs */ r->ru_utime = ns_to_kernel_old_timeval(utime); r->ru_stime = ns_to_kernel_old_timeval(stime); - - if (who != RUSAGE_CHILDREN) { - struct mm_struct *mm = get_task_mm(p); - - if (mm) { - setmax_mm_hiwater_rss(&maxrss, mm); - mmput(mm); - } - } - r->ru_maxrss = maxrss * (PAGE_SIZE / 1024); /* convert pages to KBs */ } SYSCALL_DEFINE2(getrusage, int, who, struct rusage __user *, ru)