All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 10/10] seqlock: Add do_read_seqcount_retry() in front of seqcount_lockdep_reader_access() in read_seqbegin()
@ 2021-09-02  3:37 jiasheng
  0 siblings, 0 replies; 3+ messages in thread
From: jiasheng @ 2021-09-02  3:37 UTC (permalink / raw)
  To: linux-kernel; +Cc: jiasheng

We have found that in the complied files seqcount_lockdep_reader_access()
appear more than 20 times, and under at least 90% circumstances
that do_read_seqcount_retry() and seqcount_lockdep_reader_access()
appear in pairs.
For example, they appear together in the irqfd_wakeup()
of the file complie from 'virt/kvm/eventfd.c'.
But we have found that in the read_seqbegin(), there is only
seqcount_lockdep_reader_access() instead of the pair.
Therefore, we consider that the do_read_seqcount_retry()
might be forgotten.

Signed-off-by: jiasheng <jiasheng@iscas.ac.cn>
---
 include/linux/seqlock.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h
index f61e34f..14169ce 100644
--- a/include/linux/seqlock.h
+++ b/include/linux/seqlock.h
@@ -837,8 +837,10 @@ typedef struct {
  */
 static inline unsigned read_seqbegin(const seqlock_t *sl)
 {
-	unsigned ret = read_seqcount_begin(&sl->seqcount);
-
+	unsigned int ret = 0;
+
+	if (read_seqcount_retry(&sl->seqcount, ret))
+		ret = read_seqcount_begin(&sl->seqcount);
 	kcsan_atomic_next(0);  /* non-raw usage, assume closing read_seqretry() */
 	kcsan_flat_atomic_begin();
 	return ret;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 10/10] seqlock: Add do_read_seqcount_retry() in front of seqcount_lockdep_reader_access() in read_seqbegin()
  2021-09-02  2:16 jiasheng
@ 2021-09-02  2:28 ` Eric Dumazet
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2021-09-02  2:28 UTC (permalink / raw)
  To: jiasheng, linux-kernel



On 9/1/21 7:16 PM, jiasheng wrote:
> We have found that in the complied files seqcount_lockdep_reader_access()
> appear more than 20 times, and under at least 90% circumstances
> that do_read_seqcount_retry() and seqcount_lockdep_reader_access()
> appear in pairs.
> For example, they appear together in the irqfd_wakeup()
> of the file complie from 'virt/kvm/eventfd.c'.
> But we have found that in the read_seqbegin(), there is only
> seqcount_lockdep_reader_access() instead of the pair.
> Therefore, we consider that the do_read_seqcount_retry()
> might be forgotten.
> 
> Signed-off-by: jiasheng <jiasheng@iscas.ac.cn>
> ---
>  include/linux/seqlock.h | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h
> index f61e34f..14169ce 100644
> --- a/include/linux/seqlock.h
> +++ b/include/linux/seqlock.h
> @@ -837,8 +837,10 @@ typedef struct {
>   */
>  static inline unsigned read_seqbegin(const seqlock_t *sl)
>  {
> -	unsigned ret = read_seqcount_begin(&sl->seqcount);
> -
> +	unsigned int ret;

ret contains garbage at this point.

Calling read_seqcount_retry() with garbage is not going to fly.

Have you really compiled and tested this patch ?

A sane compiler would have complained.

> +
> +	if (read_seqcount_retry(&sl->seqcount, ret))
> +		ret = read_seqcount_begin(&sl->seqcount);
>  	kcsan_atomic_next(0);  /* non-raw usage, assume closing read_seqretry() */
>  	kcsan_flat_atomic_begin();
>  	return ret;
> 



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 10/10] seqlock: Add do_read_seqcount_retry() in front of seqcount_lockdep_reader_access() in read_seqbegin()
@ 2021-09-02  2:16 jiasheng
  2021-09-02  2:28 ` Eric Dumazet
  0 siblings, 1 reply; 3+ messages in thread
From: jiasheng @ 2021-09-02  2:16 UTC (permalink / raw)
  To: linux-kernel; +Cc: jiasheng

We have found that in the complied files seqcount_lockdep_reader_access()
appear more than 20 times, and under at least 90% circumstances
that do_read_seqcount_retry() and seqcount_lockdep_reader_access()
appear in pairs.
For example, they appear together in the irqfd_wakeup()
of the file complie from 'virt/kvm/eventfd.c'.
But we have found that in the read_seqbegin(), there is only
seqcount_lockdep_reader_access() instead of the pair.
Therefore, we consider that the do_read_seqcount_retry()
might be forgotten.

Signed-off-by: jiasheng <jiasheng@iscas.ac.cn>
---
 include/linux/seqlock.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h
index f61e34f..14169ce 100644
--- a/include/linux/seqlock.h
+++ b/include/linux/seqlock.h
@@ -837,8 +837,10 @@ typedef struct {
  */
 static inline unsigned read_seqbegin(const seqlock_t *sl)
 {
-	unsigned ret = read_seqcount_begin(&sl->seqcount);
-
+	unsigned int ret;
+
+	if (read_seqcount_retry(&sl->seqcount, ret))
+		ret = read_seqcount_begin(&sl->seqcount);
 	kcsan_atomic_next(0);  /* non-raw usage, assume closing read_seqretry() */
 	kcsan_flat_atomic_begin();
 	return ret;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-02  3:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-02  3:37 [PATCH 10/10] seqlock: Add do_read_seqcount_retry() in front of seqcount_lockdep_reader_access() in read_seqbegin() jiasheng
  -- strict thread matches above, loose matches on Subject: below --
2021-09-02  2:16 jiasheng
2021-09-02  2:28 ` Eric Dumazet

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.