From nobody Wed Feb 11 03:41:58 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 532111E47A5 for ; Wed, 8 Oct 2025 12:32:17 +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=1759926740; cv=none; b=UQiY1ZSANEJGgO5osP1jY6Gx7MF/1eRCo4J2Zzz+r7rQqFvOje0MPRTiCu1AQwUJn6Y43znezSHQpr096YCDm3cigmznbBT1SanC6NAcV+iAUYLoJMsf7WZT1PLHmUC126EsmcZ/Ms3qiSahTo5yQf61vts1r7c1p2rvGie0z9A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759926740; c=relaxed/simple; bh=uHqksmuJLKSt+GdkWV/u3ycsK4AeSgh5FUnv2EVyyqY=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=VdyiUPjo+L2aLvnxbZGItAd6gnOR8STbG0/N89mEF4OABun1DHlVTKLyanH4683gQBogqrk55/cZ2CCnCQLheW/GDDbnV8LC4+db16w6h+iIhXx4plr6Ga6cPBwztBYEkIixLzx5+OyOPHyfm0xssVSHYHcKxQqEm9SvKDcKexY= 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=gm4yheLG; 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="gm4yheLG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1759926737; 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=0Ag5D+pguf9nHfO9uoXExb7dGwEZzjEQQ2eIuAoJM0g=; b=gm4yheLGF0lntM7cqwssxNQxwwDhTK7yfxKwyIhtIctBRgIJA1+BT2PMWf6pGjUAZKYvCg sU/dZjZKuKu9Tgk86zjrsVLpB1klmrjbT5xhpyVsuwstEsMOjqtosavn5I28uvJfbd86xA PnjUwihmrn2K+anyTebo66EgpSYaEps= 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-322-RblnqmgiPrym8XO7raAsXQ-1; Wed, 08 Oct 2025 08:32:14 -0400 X-MC-Unique: RblnqmgiPrym8XO7raAsXQ-1 X-Mimecast-MFC-AGG-ID: RblnqmgiPrym8XO7raAsXQ_1759926732 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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4C0111800451; Wed, 8 Oct 2025 12:32:12 +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 110961956056; Wed, 8 Oct 2025 12:32:07 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Wed, 8 Oct 2025 14:30:51 +0200 (CEST) Date: Wed, 8 Oct 2025 14:30:45 +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 v2 1/4] seqlock: introduce scoped_seqlock_read() and scoped_seqlock_read_irqsave() Message-ID: <20251008123045.GA20440@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: <20251008123014.GA20413@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" 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 Reviewed-by: Oleg Nesterov --- include/linux/seqlock.h | 64 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h index 5ce48eab7a2a..fa8d73668f4b 100644 --- a/include/linux/seqlock.h +++ b/include/linux/seqlock.h @@ -1209,4 +1209,68 @@ 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 bool +__scoped_seqlock_read_retry(seqlock_t *lock, int *seq, unsigned long *flag= s) +{ + bool retry =3D false; + + if (*seq & 1) { + if (flags) + read_sequnlock_excl_irqrestore(lock, *flags); + else + read_sequnlock_excl(lock); + } else if (read_seqretry(lock, *seq)) { + *seq =3D 1; + retry =3D true; + if (flags) + read_seqlock_excl_irqsave(lock, *flags); + else + read_seqlock_excl(lock); + } + + return retry; +} + +#define __scoped_seqlock_read(lock, s) \ + for (struct { bool lockless; int seq; } \ + s =3D { .lockless =3D true, .seq =3D read_seqbegin(lock) }; \ + s.lockless || __scoped_seqlock_read_retry(lock, &s.seq, NULL); \ + s.lockless =3D false) + +#define __scoped_seqlock_read_irqsave(lock, s) \ + for (struct { bool lockless; int seq; unsigned long flags; } \ + s =3D { .lockless =3D true, .seq =3D read_seqbegin(lock) }; \ + s.lockless || __scoped_seqlock_read_retry(lock, &s.seq, &s.flags); \ + s.lockless =3D false) + +/** + * 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(s)) + +/** + * 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:41:58 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 BCD59246BC5 for ; Wed, 8 Oct 2025 12:32:24 +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=1759926746; cv=none; b=HLMbDVP1/4vYRV+mNPI4D+HLhozkyZ9zYGXf5NIgTyTfka4tqxW3xIYQaHVO0HfChIDpTQLL0pLZA5gG7CE5whld7JCpI1P0NgPJXWmLnlaI5H0nW6CauxlpH9GB3ci9WHT+T3ENPsKj8gi59mdkjMHqx0OKq522pSNtrqjcl90= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759926746; 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=ERaNeDJJ3iwDgGnTUvpRss5Vgd6H3y5/oKHvqGo5DtD9KWx94NfloLaxiGdWENAiVOp71v39/Kk3l0I36S/jhyh8KNljIRkVhAYqEsJxHMS2pzMYr8gHcRfo4BVPX0kA3hTFRfOaw0N+ipXZQmJDyZ7+kMrKhVg9A5NAW9zp+sY= 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=fNf2EpEh; 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="fNf2EpEh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1759926743; 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=fNf2EpEhR1+8/PfJgJeqmxufq9pQEqxkMUqAtmOLEnclPx/atZn20X7K57q8jXU8AzFU0I aw8fymwMOmi3nVWtO3sMuzqIGOKzn/HdiyH2on5CyJG2ANXcyJbD6wJn7fhAl3nO24ysio 2HMvIJqKLLCA92xYU0Jgm4kjgeKrBDM= Received: from mx-prod-mc-04.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-127-rmSgDHOlPuK4WyHm3pXA4w-1; Wed, 08 Oct 2025 08:32:20 -0400 X-MC-Unique: rmSgDHOlPuK4WyHm3pXA4w-1 X-Mimecast-MFC-AGG-ID: rmSgDHOlPuK4WyHm3pXA4w_1759926739 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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 102DC19560AF; Wed, 8 Oct 2025 12:32:19 +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 982151800452; Wed, 8 Oct 2025 12:32:14 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Wed, 8 Oct 2025 14:30:58 +0200 (CEST) Date: Wed, 8 Oct 2025 14:30:52 +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 v2 2/4] seqlock: change thread_group_cputime() to use scoped_seqlock_read_irqsave() Message-ID: <20251008123052.GA20443@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: <20251008123014.GA20413@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. 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:41:58 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 D2CE923D7C2 for ; Wed, 8 Oct 2025 12:32:30 +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=1759926752; cv=none; b=R10W8rL7LJX/jTqqAmlYfbxyAxzyQ006Jcib+ikX2H5IV0p3BLgi+Xs0JS94uf+1xRaJU6NIbCJ/j1lqp68Oh+NWacMAXJvLkxFqbSlA8XXQAX44Xg4rW7QXyAtmBn+6iPhYHKl9GQqSlU3rgJOnhHgI/Nb2/v97BsHEZ3KIJ7c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759926752; 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=agJ0F7+iMFGSu6gfQKmsM2iLBUFzeFY+azSRfGdavAVm8MWJ4Wtf/SkMZjvd8/a0N+NYtzH6TYBm/mVBomKIsgniUnLbI9Ve9zvAY0LXQ+2eS/QDdOqgCDHF5SjBPS7/PQ9TS/lWXGF8j/1EGffKFS7rQ9PQVQug3GDAFFu1Jd8= 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=iqKMo9q6; 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="iqKMo9q6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1759926749; 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=iqKMo9q6XWiZM7m3g+dVLdHInLGxHNZFJ5XJr95dhe9TX2j4tNTG1JVBCxpq/H8pH1YL5+ LgjC/gK4+KPvev/ljJ+uyosPGikX/ayZigSq0Uzyd8o7dL0he95oob1RTUak+n+4vJ4yup 6p8RSpzeaeVaLoGt16DHlgAQ3N7FOk0= 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-297-gUfwxYsVMNelBSQXP_haUw-1; Wed, 08 Oct 2025 08:32:26 -0400 X-MC-Unique: gUfwxYsVMNelBSQXP_haUw-1 X-Mimecast-MFC-AGG-ID: gUfwxYsVMNelBSQXP_haUw_1759926745 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 4C81519560A7; Wed, 8 Oct 2025 12:32:25 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.227.6]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 5D1F219560A2; Wed, 8 Oct 2025 12:32:20 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Wed, 8 Oct 2025 14:31:04 +0200 (CEST) Date: Wed, 8 Oct 2025 14:30:59 +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 v2 3/4] seqlock: change do_task_stat() to use scoped_seqlock_read_irqsave() Message-ID: <20251008123059.GA20446@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: <20251008123014.GA20413@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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:41:58 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 8166535966 for ; Wed, 8 Oct 2025 12:32:35 +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=1759926757; cv=none; b=pxrXSHZbXtaPLXNffVWyimh2vs9Z9H4iugLQIperMZ53dvOxt/PCGfijeojTmDsStlnEd1RW+sNsXvIYGJEd2J10QJ6h/8sCc67+58m2y/y8mq8jjUVqdbyWrn1Nmz/lELMNEonNrUBEoFyoP2kIehG0fwbMAn9CDxOrDOlZ/PA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759926757; c=relaxed/simple; bh=BbNmQemkRXT0PPX4T4yxdzIGVzZNni1zIWvxlTMEN54=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=Qdbygd/bGlTDa/7SBiJhGIFw5jFGBV3t7Qh54T3kX7uvV03uEKTiNXV34keaMtWfJVg3A3Lc9D0zPNRjRLw6YZQfv1MBoZuEt/tzGK649Wajkm0QPLuZMU2ujr52NrJ6J9pXkj3SCaWo+oRh5UkF43N4pcibvSh+6eC+EeGH3SM= 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=RFRHUhLS; 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="RFRHUhLS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1759926754; 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=RFRHUhLScq37EZGpDRWPtiKFpBqw/eLT+gSUyjCv7YSa8WKH1s+PpgOnOGdSdnQEiwvE2D +5tFq8UwXYZEIIdYmBCeTzOfP2JURp2mOexwTcO5yQTQgqOj6qZbdILagk7E5/O4Sp4jhI vWzgwgHP8Ra7VqLKgi90mdSFlsPIn+M= 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-37-beVTel1LMU6LMlCra8z7dQ-1; Wed, 08 Oct 2025 08:32:33 -0400 X-MC-Unique: beVTel1LMU6LMlCra8z7dQ-1 X-Mimecast-MFC-AGG-ID: beVTel1LMU6LMlCra8z7dQ_1759926752 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 BA65419560A1; Wed, 8 Oct 2025 12:32:31 +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 7FB2B180047F; Wed, 8 Oct 2025 12:32:27 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Wed, 8 Oct 2025 14:31:11 +0200 (CEST) Date: Wed, 8 Oct 2025 14:31:05 +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 v2 4/4] seqlock: change do_io_accounting() to use scoped_seqlock_read_irqsave() Message-ID: <20251008123105.GA20449@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: <20251008123014.GA20413@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