From nobody Wed Feb 11 03:42:04 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 CEA87C8E6 for ; Tue, 7 Oct 2025 14:22:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759846965; cv=none; b=ii3fTzP1nIAOKUez1yu0nHLkjNmoLiTK8rJY+5yFW60c5xyKj7GmiB7unKO24ZyTOJHhYuMuFVYePilbEFjl6FCDKRKqaDxnZ9bQW2gmWAMj1E7itJJAZsBFg1lTbyBGQeRDzjk+2qDpQCE0YfO7XEGQTHx7XQFhv3ulaOaYN6E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759846965; c=relaxed/simple; bh=MagsYnyO/PngDp5RikRyfZ3ShJ0QzpuVsDa7007xqBo=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=ROWGkJRv8a6jMz1S8H3NjhskKqCfz5KP5V57/Ylodlyvl92ufGvxSPUYNBKdLxgP0MYqTiZEioOHRjHB0YXzLJvAYW+uudwuU9eao/lK8aLSjSJ2F7vO8guaJGAyPoJ4/GIFyxuImtPLq422x7cG4PLu/L7Gm2BBX9o3fz6w2Lg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=JTuwphzx; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JTuwphzx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1759846962; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=9pMYuQ2QGrbIhRcGVh9ovw0uGVViHx8S0lvJ3ldsv7I=; b=JTuwphzxn32FE80Fmid2RY0eWLMbyU0Stbhs2U5W1PzZnX293V4kSy2GoOi1jo2m2/DvWH dF5qjo/7uTm1VvM1rVEy3BGd2Wv9CPv644tlCBDSlEyaub1FZ9ayXA51bnWx5tl5wGYJaF Hc+pJtmSkW+i89QBKxoWv4R3vTzP2SU= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-255-ETD93PPiNDC-W_Mu3v8LMA-1; Tue, 07 Oct 2025 10:22:41 -0400 X-MC-Unique: ETD93PPiNDC-W_Mu3v8LMA-1 X-Mimecast-MFC-AGG-ID: ETD93PPiNDC-W_Mu3v8LMA_1759846960 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 68F4A1955F3C; Tue, 7 Oct 2025 14:22:39 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.227.6]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 472D4180141D; Tue, 7 Oct 2025 14:22:34 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 7 Oct 2025 16:21:18 +0200 (CEST) Date: Tue, 7 Oct 2025 16:21:13 +0200 From: Oleg Nesterov To: Alexander Viro , Boqun Feng , David Howells , Ingo Molnar , Li RongQing , Linus Torvalds , Peter Zijlstra , Waiman Long , Will Deacon Cc: linux-kernel@vger.kernel.org Subject: [PATCH 1/4] seqlock: introduce scoped_seqlock_read() and scoped_seqlock_read_irqsave() Message-ID: <20251007142113.GA17118@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20251007142043.GA17089@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The read_seqbegin/need_seqretry/done_seqretry API is cumbersome and error prone. With the new helper the "typical" code like int seq, nextseq; unsigned long flags; nextseq =3D 0; do { seq =3D nextseq; flags =3D read_seqbegin_or_lock_irqsave(&seqlock, &seq); // read-side critical section nextseq =3D 1; } while (need_seqretry(&seqlock, seq)); done_seqretry_irqrestore(&seqlock, seq, flags); can be rewritten as scoped_seqlock_read_irqsave (&seqlock) { // read-side critical section } Signed-off-by: Oleg Nesterov --- include/linux/seqlock.h | 61 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h index 5ce48eab7a2a..9012702fd0a8 100644 --- a/include/linux/seqlock.h +++ b/include/linux/seqlock.h @@ -1209,4 +1209,65 @@ done_seqretry_irqrestore(seqlock_t *lock, int seq, u= nsigned long flags) if (seq & 1) read_sequnlock_excl_irqrestore(lock, flags); } + +/* internal helper for scoped_seqlock_read/scoped_seqlock_read_irqsave */ +static inline int +scoped_seqlock_read_retry(seqlock_t *lock, int *seq, unsigned long *flags) +{ + int retry =3D 0; + + if (*seq & 1) { + if (flags) + read_sequnlock_excl_irqrestore(lock, *flags); + else + read_sequnlock_excl(lock); + } else if (read_seqretry(lock, *seq)) { + retry =3D *seq =3D 1; + if (flags) + read_seqlock_excl_irqsave(lock, *flags); + else + read_seqlock_excl(lock); + } + + return retry; +} + +#define __scoped_seqlock_read(lock, lockless, seq) \ + for (int lockless =3D 1, seq =3D read_seqbegin(lock); \ + lockless || scoped_seqlock_read_retry(lock, &seq, NULL); \ + lockless =3D 0) + +/** + * scoped_seqlock_read(lock) - execute the read side critical section + * without manual sequence counter handling + * or calls to other helpers + * @lock: pointer to the seqlock_t protecting the data + * + * Example: + * + * scoped_seqlock_read(&lock) { + * // read-side critical section + * } + * + * Starts with a lockless pass first. If it fails, restarts the critical + * section with the lock held. + * + * The critical section must not contain control flow that escapes the loo= p. + */ +#define scoped_seqlock_read(lock) \ + __scoped_seqlock_read(lock, __UNIQUE_ID(lockless), __UNIQUE_ID(seq)) + +#define __scoped_seqlock_read_irqsave(lock, s) \ + for (struct { int lockless, seq; ulong flags; } s =3D { 1, read_seqbegin(= lock) }; \ + s.lockless || scoped_seqlock_read_retry(lock, &s.seq, &s.flags); \ + s.lockless =3D 0) + +/** + * scoped_seqlock_read_irqsave(lock) - same as scoped_seqlock_read() but + * disables irqs on a locking pass + * @lock: pointer to the seqlock_t protecting the data + */ +#define scoped_seqlock_read_irqsave(lock) \ + __scoped_seqlock_read_irqsave(lock, __UNIQUE_ID(s)) + #endif /* __LINUX_SEQLOCK_H */ --=20 2.25.1.362.g51ebf55 From nobody Wed Feb 11 03:42:04 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 2A18AC8E6 for ; Tue, 7 Oct 2025 14:22:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759846974; cv=none; b=tZU+99raP11pn22RxIG5ZuBDcoAhGuAgQWHJ+z5LU/LkMtnmNsD1K6HZ9dHH5hnnSHsizRl2QWQ/bBAZXuDX8xnAv6BJ24IJAOwFrkdts5IOwTTpz/IJFKNKbcothxy9dvPSRrI+R0I72htylfUpMtnANHxBefBYqZI1Tz5yHSo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759846974; c=relaxed/simple; bh=rau0Of92Imxa/DTtgDTx+Cu0VrDp6j2EHky4cVJztmQ=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=Qfo9K7Iseg8gF+Nc/DT7cnRizceIatqtA9gp/ejE249D90TMzmC1A0RDOs5TRsmbSpXU+df4iTGZWop68XOP0DT19N+RDn3W7Ke7dUe1eWTrMevOqsmIu9mDuCXHdNU0r+fvfA7HdnQA3LsXNlsEX3uwauj5ebWVqEBjltkdC+Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=dq5BwML7; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dq5BwML7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1759846972; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=zbuIk8AUUnhPP+HZuAhozUptVNutr+rLH6yGzIfS3zI=; b=dq5BwML7mcqzMmE4n0GUO6/vILKnUsKhXrkAhzdAWgADnbpVr0GSggmxLBu1eMfpc1aQVd ttloIMeQH0GXdcHxGXmT7fNJmRhQSUIrHyjwXdaWIkHNUBA88DXC4reQJIaEmg1yQh0tiL +7WeOpOyCx/8OcUjvF7TZVL8fP2Yb/c= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-524-DkFC6j_UNP6dfZcdoE2xtQ-1; Tue, 07 Oct 2025 10:22:48 -0400 X-MC-Unique: DkFC6j_UNP6dfZcdoE2xtQ-1 X-Mimecast-MFC-AGG-ID: DkFC6j_UNP6dfZcdoE2xtQ_1759846966 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 45B6F1800579; Tue, 7 Oct 2025 14:22:46 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.227.6]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 821CB30002CC; Tue, 7 Oct 2025 14:22:41 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 7 Oct 2025 16:21:25 +0200 (CEST) Date: Tue, 7 Oct 2025 16:21:19 +0200 From: Oleg Nesterov To: Alexander Viro , Boqun Feng , David Howells , Ingo Molnar , Li RongQing , Linus Torvalds , Peter Zijlstra , Waiman Long , Will Deacon Cc: linux-kernel@vger.kernel.org Subject: [PATCH 2/4] seqlock: change thread_group_cputime() to use scoped_seqlock_read_irqsave() Message-ID: <20251007142119.GA17122@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20251007142043.GA17089@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To simplify the code and make it more readable. While at it, change thread_group_cputime() to use __for_each_thread(sig). Signed-off-by: Oleg Nesterov --- kernel/sched/cputime.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c index 7097de2c8cda..94b445e947d2 100644 --- a/kernel/sched/cputime.c +++ b/kernel/sched/cputime.c @@ -315,8 +315,6 @@ void thread_group_cputime(struct task_struct *tsk, stru= ct task_cputime *times) struct signal_struct *sig =3D tsk->signal; u64 utime, stime; struct task_struct *t; - unsigned int seq, nextseq; - unsigned long flags; =20 /* * Update current task runtime to account pending time since last @@ -330,25 +328,18 @@ void thread_group_cputime(struct task_struct *tsk, st= ruct task_cputime *times) (void) task_sched_runtime(current); =20 rcu_read_lock(); - /* Attempt a lockless read on the first round. */ - nextseq =3D 0; - do { - seq =3D nextseq; - flags =3D read_seqbegin_or_lock_irqsave(&sig->stats_lock, &seq); + scoped_seqlock_read_irqsave(&sig->stats_lock) { times->utime =3D sig->utime; times->stime =3D sig->stime; times->sum_exec_runtime =3D sig->sum_sched_runtime; =20 - for_each_thread(tsk, t) { + __for_each_thread(sig, t) { task_cputime(t, &utime, &stime); times->utime +=3D utime; times->stime +=3D stime; times->sum_exec_runtime +=3D read_sum_exec_runtime(t); } - /* If lockless access failed, take the lock. */ - nextseq =3D 1; - } while (need_seqretry(&sig->stats_lock, seq)); - done_seqretry_irqrestore(&sig->stats_lock, seq, flags); + } rcu_read_unlock(); } =20 --=20 2.25.1.362.g51ebf55 From nobody Wed Feb 11 03:42:04 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 A7BE3C8E6 for ; Tue, 7 Oct 2025 14:22:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759846981; cv=none; b=Ix6fo8rsI1LamVdSwBasKgxhgAsxKTwtEOYpzQi8+30g26AWq0IZKFst5qaaf+xXKaY7dLwwT3IEwD2QeqqQ1qMxOkEeMo40gFjHvX8nazSIZ/pY9phpVD650pENFDgzKk8CIQV6sJowfEXroxUbtwcwBq7Y5nvxSxIKFuTK2AY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759846981; c=relaxed/simple; bh=PKq/HM8C2Xv7OWMoIILS6DZ84AfGURYMW+igTgy7FvA=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=fs64YF5cllmKY4PD96tHy5lUm+yObGbn0XlmGMM7lo4JTWLMUlMQ6jFA0WUAoaFNPRRewnLcXF4IscoIfND172Ep0f1NA7MWGv0zgbLQuzjsBD0WAhHZl36/qLkouOsyGBJuBPdWGsRSgKVmuFX6ZvytW2TDqQgwPH0J1NNtRPU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=gi2X2MIb; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gi2X2MIb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1759846978; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=t6EsGNKU+HFfruQUpBJy7+ykll9vexiISVYh4SJGvp4=; b=gi2X2MIbPX3l4gi0UapQosbqtsrmxHIcPZ3/W2wqBsEU//S8xX2RQQm+a3nViqaXqdCteR E/n1GGrJ7MYoYJ+VVzXynfxM1DLq56o+FTRokEOZT4loNh5fU4FjtEsr+wvd6JUVKQ1W6/ DaPBnnMJrMrd+eDfP5lQ8BsqbUH17bE= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-622-te5Xb7CqOKKYEzwFdruDIQ-1; Tue, 07 Oct 2025 10:22:54 -0400 X-MC-Unique: te5Xb7CqOKKYEzwFdruDIQ-1 X-Mimecast-MFC-AGG-ID: te5Xb7CqOKKYEzwFdruDIQ_1759846972 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CBDBE1800285; Tue, 7 Oct 2025 14:22:52 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.227.6]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 8CF641955F21; Tue, 7 Oct 2025 14:22:48 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 7 Oct 2025 16:21:31 +0200 (CEST) Date: Tue, 7 Oct 2025 16:21:26 +0200 From: Oleg Nesterov To: Alexander Viro , Boqun Feng , David Howells , Ingo Molnar , Li RongQing , Linus Torvalds , Peter Zijlstra , Waiman Long , Will Deacon Cc: linux-kernel@vger.kernel.org Subject: [PATCH 3/4] seqlock: change do_task_stat() to use scoped_seqlock_read_irqsave() Message-ID: <20251007142126.GA17127@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20251007142043.GA17089@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To simplify the code and make it more readable. Signed-off-by: Oleg Nesterov --- fs/proc/array.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/fs/proc/array.c b/fs/proc/array.c index d6a0369caa93..e9c61448f3ee 100644 --- a/fs/proc/array.c +++ b/fs/proc/array.c @@ -483,7 +483,6 @@ static int do_task_stat(struct seq_file *m, struct pid_= namespace *ns, unsigned long flags; int exit_code =3D task->exit_code; struct signal_struct *sig =3D task->signal; - unsigned int seq =3D 1; =20 state =3D *get_task_state(task); vsize =3D eip =3D esp =3D 0; @@ -540,10 +539,7 @@ static int do_task_stat(struct seq_file *m, struct pid= _namespace *ns, if (permitted && (!whole || num_threads < 2)) wchan =3D !task_is_running(task); =20 - do { - seq++; /* 2 on the 1st/lockless path, otherwise odd */ - flags =3D read_seqbegin_or_lock_irqsave(&sig->stats_lock, &seq); - + scoped_seqlock_read_irqsave(&sig->stats_lock) { cmin_flt =3D sig->cmin_flt; cmaj_flt =3D sig->cmaj_flt; cutime =3D sig->cutime; @@ -565,8 +561,7 @@ static int do_task_stat(struct seq_file *m, struct pid_= namespace *ns, } rcu_read_unlock(); } - } while (need_seqretry(&sig->stats_lock, seq)); - done_seqretry_irqrestore(&sig->stats_lock, seq, flags); + } =20 if (whole) { thread_group_cputime_adjusted(task, &utime, &stime); --=20 2.25.1.362.g51ebf55 From nobody Wed Feb 11 03:42:04 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 E713B2DC77E for ; Tue, 7 Oct 2025 14:23:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759846986; cv=none; b=GDaTWz6lQ85SRAwFxPyFD8SMFIYIvMtYvGfimtrQLuEetDsouKFFaBxP8nGlbKwgc5gBB0daKLat1h6B5mGUStgdHr218agwLRaiG29EuaZdAN5EYXGcgS75kLy/bUQr/IK8+AzL3abON+PmscMKy9JxgLZjutNL0i6tjaI7guk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759846986; c=relaxed/simple; bh=BbNmQemkRXT0PPX4T4yxdzIGVzZNni1zIWvxlTMEN54=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=XykcPUp0filQrKvZ+PcUQtiEsDBBIb3W/0iJ+gObPq5aYZOdv3lPUvi3POkLlm5RKnz4I/YpPDNn3+hZEcH5rrElBLCKLUwBR/GG20J36nDhHL4HmwOKcLxyp8KYFc5e+TNwpe2xFHVnOCqovw1g+P70THNYeymj0Gs23FyPZP4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=TWlz6IEZ; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TWlz6IEZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1759846984; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=fKLnyQUCu2ZpDNTuQSd/OvsIqqCGMU2IGAT+l5MmJp8=; b=TWlz6IEZAcWCwjdEb81YtQZLTfr2IxBNudTwNthzJwu8L9fxjyJ/A3qf0vGogZsRKqBV7C pkyinLEdJvL6s3DYThRh11PWZt+h+TJlhqOX5zXHJxLjUTKPQQyWGByi5d27Hs/l8J8uYi RCBiP0dE5SCTHoLgNwlFsSoh8Ae3+rM= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-564-m3dv1AaBMiSKFYaGGsGHRA-1; Tue, 07 Oct 2025 10:23:00 -0400 X-MC-Unique: m3dv1AaBMiSKFYaGGsGHRA-1 X-Mimecast-MFC-AGG-ID: m3dv1AaBMiSKFYaGGsGHRA_1759846979 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4440E195609F; Tue, 7 Oct 2025 14:22:59 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.227.6]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 1EC52180047F; Tue, 7 Oct 2025 14:22:54 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 7 Oct 2025 16:21:38 +0200 (CEST) Date: Tue, 7 Oct 2025 16:21:32 +0200 From: Oleg Nesterov To: Alexander Viro , Boqun Feng , David Howells , Ingo Molnar , Li RongQing , Linus Torvalds , Peter Zijlstra , Waiman Long , Will Deacon Cc: linux-kernel@vger.kernel.org Subject: [PATCH 4/4] seqlock: change do_io_accounting() to use scoped_seqlock_read_irqsave() Message-ID: <20251007142132.GA17130@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20251007142043.GA17089@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To simplify the code and make it more readable. Signed-off-by: Oleg Nesterov --- fs/proc/base.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index 62d35631ba8c..08113bb6af1d 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -3041,20 +3041,14 @@ static int do_io_accounting(struct task_struct *tas= k, struct seq_file *m, int wh if (whole) { struct signal_struct *sig =3D task->signal; struct task_struct *t; - unsigned int seq =3D 1; - unsigned long flags; =20 rcu_read_lock(); - do { - seq++; /* 2 on the 1st/lockless path, otherwise odd */ - flags =3D read_seqbegin_or_lock_irqsave(&sig->stats_lock, &seq); - + scoped_seqlock_read_irqsave(&sig->stats_lock) { acct =3D sig->ioac; __for_each_thread(sig, t) task_io_accounting_add(&acct, &t->ioac); =20 - } while (need_seqretry(&sig->stats_lock, seq)); - done_seqretry_irqrestore(&sig->stats_lock, seq, flags); + } rcu_read_unlock(); } else { acct =3D task->ioac; --=20 2.25.1.362.g51ebf55