linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] virtio_net: fix lockdep warning on 32 bit
@ 2020-05-06  0:01 Michael S. Tsirkin
  2020-05-06  5:28 ` Jason Wang
  2020-05-06 20:42 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Michael S. Tsirkin @ 2020-05-06  0:01 UTC (permalink / raw)
  To: linux-kernel
  Cc: Thomas Gleixner, Eric Dumazet, Jason Wang, David S. Miller,
	virtualization, netdev

When we fill up a receive VQ, try_fill_recv currently tries to count
kicks using a 64 bit stats counter. Turns out, on a 32 bit kernel that
uses a seqcount. sequence counts are "lock" constructs where you need to
make sure that writers are serialized.

In turn, this means that we mustn't run two try_fill_recv concurrently.
Which of course we don't. We do run try_fill_recv sometimes from a fully
preemptible context and sometimes from a softirq (napi) context.

However, when it comes to the seqcount, lockdep is trying to enforce
the rule that the same lock isn't accessed from preemptible
and softirq context. This causes a false-positive warning:

WARNING: inconsistent lock state
...
inconsistent {SOFTIRQ-ON-W} -> {IN-SOFTIRQ-W} usage.

As a work around, shut down the warning by switching
to u64_stats_update_begin_irqsave - that works by disabling
interrupts on 32 bit only, is a NOP on 64 bit.

Reported-by: Thomas Gleixner <tglx@linutronix.de>
Suggested-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---

I'm not thrilled about this but this seems the best we can do for now.

Completely untested.


Thomas, can you pls let me know the config I need to trigger the warning
in question?


 drivers/net/virtio_net.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 6594aab4910e..95393b61187f 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -1243,9 +1243,11 @@ static bool try_fill_recv(struct virtnet_info *vi, struct receive_queue *rq,
 			break;
 	} while (rq->vq->num_free);
 	if (virtqueue_kick_prepare(rq->vq) && virtqueue_notify(rq->vq)) {
-		u64_stats_update_begin(&rq->stats.syncp);
+		unsigned long flags;
+
+		flags = u64_stats_update_begin_irqsave(&rq->stats.syncp);
 		rq->stats.kicks++;
-		u64_stats_update_end(&rq->stats.syncp);
+		u64_stats_update_end_irqrestore(&rq->stats.syncp);
 	}
 
 	return !oom;
-- 
MST


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

* Re: [PATCH] virtio_net: fix lockdep warning on 32 bit
  2020-05-06  0:01 [PATCH] virtio_net: fix lockdep warning on 32 bit Michael S. Tsirkin
@ 2020-05-06  5:28 ` Jason Wang
  2020-05-06 20:42 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Jason Wang @ 2020-05-06  5:28 UTC (permalink / raw)
  To: Michael S. Tsirkin, linux-kernel
  Cc: Thomas Gleixner, Eric Dumazet, David S. Miller, virtualization, netdev


On 2020/5/6 上午8:01, Michael S. Tsirkin wrote:
> When we fill up a receive VQ, try_fill_recv currently tries to count
> kicks using a 64 bit stats counter. Turns out, on a 32 bit kernel that
> uses a seqcount. sequence counts are "lock" constructs where you need to
> make sure that writers are serialized.
>
> In turn, this means that we mustn't run two try_fill_recv concurrently.
> Which of course we don't. We do run try_fill_recv sometimes from a fully
> preemptible context and sometimes from a softirq (napi) context.
>
> However, when it comes to the seqcount, lockdep is trying to enforce
> the rule that the same lock isn't accessed from preemptible
> and softirq context. This causes a false-positive warning:
>
> WARNING: inconsistent lock state
> ...
> inconsistent {SOFTIRQ-ON-W} -> {IN-SOFTIRQ-W} usage.
>
> As a work around, shut down the warning by switching
> to u64_stats_update_begin_irqsave - that works by disabling
> interrupts on 32 bit only, is a NOP on 64 bit.
>
> Reported-by: Thomas Gleixner <tglx@linutronix.de>
> Suggested-by: Eric Dumazet <eric.dumazet@gmail.com>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>
> I'm not thrilled about this but this seems the best we can do for now.
>
> Completely untested.
>
>
> Thomas, can you pls let me know the config I need to trigger the warning
> in question?
>
>
>   drivers/net/virtio_net.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 6594aab4910e..95393b61187f 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -1243,9 +1243,11 @@ static bool try_fill_recv(struct virtnet_info *vi, struct receive_queue *rq,
>   			break;
>   	} while (rq->vq->num_free);
>   	if (virtqueue_kick_prepare(rq->vq) && virtqueue_notify(rq->vq)) {
> -		u64_stats_update_begin(&rq->stats.syncp);
> +		unsigned long flags;
> +
> +		flags = u64_stats_update_begin_irqsave(&rq->stats.syncp);
>   		rq->stats.kicks++;
> -		u64_stats_update_end(&rq->stats.syncp);
> +		u64_stats_update_end_irqrestore(&rq->stats.syncp);
>   	}
>   
>   	return !oom;


Acked-by: Jason Wang <jasowang@redhat.com>




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

* Re: [PATCH] virtio_net: fix lockdep warning on 32 bit
  2020-05-06  0:01 [PATCH] virtio_net: fix lockdep warning on 32 bit Michael S. Tsirkin
  2020-05-06  5:28 ` Jason Wang
@ 2020-05-06 20:42 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2020-05-06 20:42 UTC (permalink / raw)
  To: mst; +Cc: linux-kernel, tglx, eric.dumazet, jasowang, virtualization, netdev

From: "Michael S. Tsirkin" <mst@redhat.com>
Date: Tue, 5 May 2020 20:01:31 -0400

> -		u64_stats_update_end(&rq->stats.syncp);
> +		u64_stats_update_end_irqrestore(&rq->stats.syncp);

Need to pass flags to this function.

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

end of thread, other threads:[~2020-05-06 20:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-06  0:01 [PATCH] virtio_net: fix lockdep warning on 32 bit Michael S. Tsirkin
2020-05-06  5:28 ` Jason Wang
2020-05-06 20:42 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).