From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796388142; b=bYT9A2VcK08ez/W/4aCKERZgfCDF0I/sCNZvLOEGf9jqtyP+aoi9FpkIw2+w8nNeeKHX lEEJ/AHku9Tk6bGW5v/ThBzRXS1iXqiu4vkiUhUnQs7fXE1YdOiBK/9Wg/3T6WrI6H7DM ycL5iYXRUhy6Bctiu2B7xX4XzIpYfkqZCc3Ajkra4u5Qxyd5qSpzdi+Spk6s0mYflwTV2 nyp5xY0xF/QvCPZiCJ67xL2lnahYr6dgDw8fNdxobgW2YZrePTzv3VrSNaX+8WkxNbp8j oNMoUwaSJfRVM3+JsoEkLoZ0LccY209Vvm8yetHjXpr6hnoBt0poQ45BI/ZN5ieFfkg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388142; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=RUBTZBfOY9VDHLRCCfrSHdlXgMxmyZ0rdPpc1lOWzLY=; b=3oaA3n1JEA41VXgMS/uUAV43xzjbaL3g0TDt4OZlz3NiupR1K+7DhWdiGDSM44+QfT3e QnNgyWXzn8Bly0S1DiLrcHb7KaQlBxcS07vzIdnfFb3X2M/avXjfPxqna/kN6lP1Ylhzu L3n/9RJxlqHQejg0axXgXSqMqDsnaKKrT9jbnogDW9pmHmAn98SzIrYAR+g9Eu7C9OAOM xsrfcZf83BrXl/L9Vaz7BB8rZVPHrbbLtgeVtfybrCe6O7OQU16KVblhFoT4tLS7VYZYK R+e4j4dc9wxThpNPQR5t2Bm8kxmHUNhigdz2kuaLgughvJsRDN2ovRJzDaNQj5smBQg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=twHLrp4t; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0084606A32D; Fri, 4 Dec 2026 12:42:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=twHLrp4t Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C86C1F000C2; Fri, 4 Dec 2026 12:42:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796388142; bh=RUBTZBfOY9VDHLRCCfrSHdlXgMxmyZ0rdPpc1lOWzLY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=twHLrp4tLY4TeptJvo2WfA1v980SBFM3KHO7zEjLtTn/TcO2JccC+6U9gAUXX4Mks 6w+DAnX2QW4cHWeNfplscS+WRaF7TISqfJYB3JUw56YdYwCR3PouTJKV+v8mcst9XK aj6M4wLVN8Cb2gxqn7FdbPTI4ZhXvRlAHnbb8vYw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Oleg Nesterov , Thomas Gleixner , Hungyu Lin Subject: [PATCH 6.1 0493/1059] tsacct: Keep task begin times stable across suspend Date: Fri, 4 Dec 2026 19:00:24 +0900 Message-ID: <20261204100657.005007564@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Hungyu Lin commit c49b3c20a2d0b22700e2100a527e68e829ece7f0 upstream. bacct_add_tsk() derives ac_btime and ac_btime64 by subtracting a CLOCK_MONOTONIC elapsed duration from CLOCK_REALTIME. MONOTONIC stops during suspend while REALTIME continues, so querying an existing task after resume moves its reported begin time forward by the time spent suspended. Calculate the begin time from the wall-clock boot timestamp and the task's CLOCK_BOOTTIME start timestamp instead. This accounts for suspend and adds the nanoseconds before truncating to seconds. Keep ac_etime and ac_tgetime on CLOCK_MONOTONIC and retain the existing rebasing when the wall clock is adjusted. The new begin time can be negative: setting CLOCK_REALTIME is bounded by CLOCK_MONOTONIC, which excludes suspend, rather than CLOCK_BOOTTIME. A permitted backward clock adjustment after suspend can therefore put the task's begin time before the epoch. Clamp ac_btime64 at zero too, instead of wrapping in the unsigned field, and retain its positive range. Fixes: f3cef7a99469 ("[PATCH] csa: basic accounting over taskstats") Reported-by: Oleg Nesterov Suggested-by: Thomas Gleixner Signed-off-by: Hungyu Lin Signed-off-by: Thomas Gleixner Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20130611200600.GA15168@redhat.com Link: https://lore.kernel.org/r/alpine.DEB.2.21.1911071335320.4256@nanos.tec.linutronix.de Link: https://patch.msgid.link/20261030054227.35453-3-dennylin0707@gmail.com Signed-off-by: Greg Kroah-Hartman --- kernel/tsacct.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) --- a/kernel/tsacct.c +++ b/kernel/tsacct.c @@ -24,7 +24,7 @@ void bacct_add_tsk(struct user_namespace const struct cred *tcred; u64 utime, stime, utimescaled, stimescaled; u64 now_ns, delta; - time64_t btime; + struct timespec64 btime; BUILD_BUG_ON(TS_COMM_LEN < TASK_COMM_LEN); @@ -39,9 +39,11 @@ void bacct_add_tsk(struct user_namespace do_div(delta, NSEC_PER_USEC); stats->ac_etime = delta; /* Convert to seconds for btime (note y2106 limit) */ - btime = ktime_get_real_seconds() - div_u64(delta, USEC_PER_SEC); - stats->ac_btime = clamp_t(time64_t, btime, 0, U32_MAX); - stats->ac_btime64 = btime; + getboottime64(&btime); + btime = timespec64_add(btime, ns_to_timespec64(tsk->start_boottime)); + stats->ac_btime = clamp_t(time64_t, btime.tv_sec, 0, U32_MAX); + /* Setting the clock back after suspend can make btime negative. */ + stats->ac_btime64 = max_t(time64_t, btime.tv_sec, 0); if (tsk->flags & PF_EXITING) stats->ac_exitcode = tsk->exit_code;