LKML Archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] fixup potential cpu stall
@ 2023-06-09 13:18 Xianting Tian
  2023-06-09 13:18 ` [PATCH 1/3] virtio-crypto: fixup potential cpu stall when free unused bufs Xianting Tian
                   ` (4 more replies)
  0 siblings, 5 replies; 19+ messages in thread
From: Xianting Tian @ 2023-06-09 13:18 UTC (permalink / raw)
  To: arei.gonglei, mst, jasowang, xuanzhuo, herbert, davem, amit, arnd,
	gregkh, marcel, johan.hedberg, luiz.dentz
  Cc: linux-bluetooth, virtualization, linux-crypto, linux-kernel,
	Xianting Tian

Cpu stall issue may happen if device is configured with multi queues
and large queue depth, so fix it.

Xianting Tian (3):
  virtio-crypto: fixup potential cpu stall when free unused bufs
  virtio_console: fixup potential cpu stall when free unused bufs
  virtio_bt: fixup potential cpu stall when free unused bufs

 drivers/bluetooth/virtio_bt.c              | 1 +
 drivers/char/virtio_console.c              | 1 +
 drivers/crypto/virtio/virtio_crypto_core.c | 1 +
 3 files changed, 3 insertions(+)

-- 
2.17.1


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

* [PATCH 1/3] virtio-crypto: fixup potential cpu stall when free unused bufs
  2023-06-09 13:18 [PATCH 0/3] fixup potential cpu stall Xianting Tian
@ 2023-06-09 13:18 ` Xianting Tian
  2023-06-09 13:39   ` Greg KH
                     ` (2 more replies)
  2023-06-09 13:18 ` [PATCH 2/3] virtio_console: " Xianting Tian
                   ` (3 subsequent siblings)
  4 siblings, 3 replies; 19+ messages in thread
From: Xianting Tian @ 2023-06-09 13:18 UTC (permalink / raw)
  To: arei.gonglei, mst, jasowang, xuanzhuo, herbert, davem, amit, arnd,
	gregkh, marcel, johan.hedberg, luiz.dentz
  Cc: linux-bluetooth, virtualization, linux-crypto, linux-kernel,
	Xianting Tian, Xianting Tian

From: Xianting Tian <tianxianting.txt@alibaba-inc.com>

Cpu stall issue may happen if device is configured with multi queues
and large queue depth, so fix it.

Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
---
 drivers/crypto/virtio/virtio_crypto_core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/crypto/virtio/virtio_crypto_core.c b/drivers/crypto/virtio/virtio_crypto_core.c
index 1198bd306365..94849fa3bd74 100644
--- a/drivers/crypto/virtio/virtio_crypto_core.c
+++ b/drivers/crypto/virtio/virtio_crypto_core.c
@@ -480,6 +480,7 @@ static void virtcrypto_free_unused_reqs(struct virtio_crypto *vcrypto)
 			kfree(vc_req->req_data);
 			kfree(vc_req->sgs);
 		}
+		cond_resched();
 	}
 }
 
-- 
2.17.1


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

* [PATCH 2/3] virtio_console: fixup potential cpu stall when free unused bufs
  2023-06-09 13:18 [PATCH 0/3] fixup potential cpu stall Xianting Tian
  2023-06-09 13:18 ` [PATCH 1/3] virtio-crypto: fixup potential cpu stall when free unused bufs Xianting Tian
@ 2023-06-09 13:18 ` Xianting Tian
  2023-06-09 16:05   ` Michael S. Tsirkin
  2023-06-09 13:18 ` [PATCH 3/3] virtio_bt: " Xianting Tian
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 19+ messages in thread
From: Xianting Tian @ 2023-06-09 13:18 UTC (permalink / raw)
  To: arei.gonglei, mst, jasowang, xuanzhuo, herbert, davem, amit, arnd,
	gregkh, marcel, johan.hedberg, luiz.dentz
  Cc: linux-bluetooth, virtualization, linux-crypto, linux-kernel,
	Xianting Tian

Cpu stall issue may happen if device is configured with multi queues
and large queue depth, so fix it.

Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
---
 drivers/char/virtio_console.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index b65c809a4e97..5ec4cf4ea919 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -1935,6 +1935,7 @@ static void remove_vqs(struct ports_device *portdev)
 		flush_bufs(vq, true);
 		while ((buf = virtqueue_detach_unused_buf(vq)))
 			free_buf(buf, true);
+		cond_resched();
 	}
 	portdev->vdev->config->del_vqs(portdev->vdev);
 	kfree(portdev->in_vqs);
-- 
2.17.1


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

* [PATCH 3/3] virtio_bt: fixup potential cpu stall when free unused bufs
  2023-06-09 13:18 [PATCH 0/3] fixup potential cpu stall Xianting Tian
  2023-06-09 13:18 ` [PATCH 1/3] virtio-crypto: fixup potential cpu stall when free unused bufs Xianting Tian
  2023-06-09 13:18 ` [PATCH 2/3] virtio_console: " Xianting Tian
@ 2023-06-09 13:18 ` Xianting Tian
  2023-06-22 11:59 ` [PATCH 0/3] fixup potential cpu stall Michael S. Tsirkin
  2023-07-06 20:10 ` patchwork-bot+bluetooth
  4 siblings, 0 replies; 19+ messages in thread
From: Xianting Tian @ 2023-06-09 13:18 UTC (permalink / raw)
  To: arei.gonglei, mst, jasowang, xuanzhuo, herbert, davem, amit, arnd,
	gregkh, marcel, johan.hedberg, luiz.dentz
  Cc: linux-bluetooth, virtualization, linux-crypto, linux-kernel,
	Xianting Tian

Cpu stall issue may happen if device is configured with multi queues
and large queue depth, so fix it.

Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
---
 drivers/bluetooth/virtio_bt.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/bluetooth/virtio_bt.c b/drivers/bluetooth/virtio_bt.c
index c570c45d1480..2ac70b560c46 100644
--- a/drivers/bluetooth/virtio_bt.c
+++ b/drivers/bluetooth/virtio_bt.c
@@ -79,6 +79,7 @@ static int virtbt_close_vdev(struct virtio_bluetooth *vbt)
 
 		while ((skb = virtqueue_detach_unused_buf(vq)))
 			kfree_skb(skb);
+		cond_resched();
 	}
 
 	return 0;
-- 
2.17.1


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

* Re: [PATCH 1/3] virtio-crypto: fixup potential cpu stall when free unused bufs
  2023-06-09 13:18 ` [PATCH 1/3] virtio-crypto: fixup potential cpu stall when free unused bufs Xianting Tian
@ 2023-06-09 13:39   ` Greg KH
  2023-06-09 13:41     ` Greg KH
  2023-06-09 15:57   ` Michael S. Tsirkin
  2023-06-09 15:58   ` Michael S. Tsirkin
  2 siblings, 1 reply; 19+ messages in thread
From: Greg KH @ 2023-06-09 13:39 UTC (permalink / raw)
  To: Xianting Tian
  Cc: arei.gonglei, mst, jasowang, xuanzhuo, herbert, davem, amit, arnd,
	marcel, johan.hedberg, luiz.dentz, linux-bluetooth,
	virtualization, linux-crypto, linux-kernel, Xianting Tian

On Fri, Jun 09, 2023 at 09:18:15PM +0800, Xianting Tian wrote:
> From: Xianting Tian <tianxianting.txt@alibaba-inc.com>
> 
> Cpu stall issue may happen if device is configured with multi queues
> and large queue depth, so fix it.
> 
> Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
> ---
>  drivers/crypto/virtio/virtio_crypto_core.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/crypto/virtio/virtio_crypto_core.c b/drivers/crypto/virtio/virtio_crypto_core.c
> index 1198bd306365..94849fa3bd74 100644
> --- a/drivers/crypto/virtio/virtio_crypto_core.c
> +++ b/drivers/crypto/virtio/virtio_crypto_core.c
> @@ -480,6 +480,7 @@ static void virtcrypto_free_unused_reqs(struct virtio_crypto *vcrypto)
>  			kfree(vc_req->req_data);
>  			kfree(vc_req->sgs);
>  		}
> +		cond_resched();

that's not "fixing a stall", it is "call the scheduler because we are
taking too long".  The CPU isn't stalled at all, just busy.

Are you sure this isn't just a bug in the code?  Why is this code taking
so long that you have to force the scheduler to run?  This is almost
always a sign that something else needs to be fixed instead.

thanks,

greg k-h

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

* Re: [PATCH 1/3] virtio-crypto: fixup potential cpu stall when free unused bufs
  2023-06-09 13:39   ` Greg KH
@ 2023-06-09 13:41     ` Greg KH
  2023-06-09 13:49       ` Xianting Tian
  0 siblings, 1 reply; 19+ messages in thread
From: Greg KH @ 2023-06-09 13:41 UTC (permalink / raw)
  To: Xianting Tian
  Cc: arei.gonglei, mst, jasowang, xuanzhuo, herbert, davem, amit, arnd,
	marcel, johan.hedberg, luiz.dentz, linux-bluetooth,
	virtualization, linux-crypto, linux-kernel, Xianting Tian

On Fri, Jun 09, 2023 at 03:39:24PM +0200, Greg KH wrote:
> On Fri, Jun 09, 2023 at 09:18:15PM +0800, Xianting Tian wrote:
> > From: Xianting Tian <tianxianting.txt@alibaba-inc.com>
> > 
> > Cpu stall issue may happen if device is configured with multi queues
> > and large queue depth, so fix it.
> > 
> > Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
> > ---
> >  drivers/crypto/virtio/virtio_crypto_core.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/drivers/crypto/virtio/virtio_crypto_core.c b/drivers/crypto/virtio/virtio_crypto_core.c
> > index 1198bd306365..94849fa3bd74 100644
> > --- a/drivers/crypto/virtio/virtio_crypto_core.c
> > +++ b/drivers/crypto/virtio/virtio_crypto_core.c
> > @@ -480,6 +480,7 @@ static void virtcrypto_free_unused_reqs(struct virtio_crypto *vcrypto)
> >  			kfree(vc_req->req_data);
> >  			kfree(vc_req->sgs);
> >  		}
> > +		cond_resched();
> 
> that's not "fixing a stall", it is "call the scheduler because we are
> taking too long".  The CPU isn't stalled at all, just busy.
> 
> Are you sure this isn't just a bug in the code?  Why is this code taking
> so long that you have to force the scheduler to run?  This is almost
> always a sign that something else needs to be fixed instead.

And same comment on the other 2 patches, please fix this properly.

Also, this is a tight loop that is just freeing memory, why is it taking
so long?  Why do you want it to take longer (which is what you are doing
here), ideally it would be faster, not slower, so you are now slowing
down the system overall with this patchset, right?

thanks,

greg k-h

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

* Re: [PATCH 1/3] virtio-crypto: fixup potential cpu stall when free unused bufs
  2023-06-09 13:41     ` Greg KH
@ 2023-06-09 13:49       ` Xianting Tian
  2023-06-09 14:05         ` Greg KH
  0 siblings, 1 reply; 19+ messages in thread
From: Xianting Tian @ 2023-06-09 13:49 UTC (permalink / raw)
  To: Greg KH
  Cc: arei.gonglei, mst, jasowang, xuanzhuo, herbert, davem, amit, arnd,
	marcel, johan.hedberg, luiz.dentz, linux-bluetooth,
	virtualization, linux-crypto, linux-kernel, Xianting Tian


在 2023/6/9 下午9:41, Greg KH 写道:
> On Fri, Jun 09, 2023 at 03:39:24PM +0200, Greg KH wrote:
>> On Fri, Jun 09, 2023 at 09:18:15PM +0800, Xianting Tian wrote:
>>> From: Xianting Tian <tianxianting.txt@alibaba-inc.com>
>>>
>>> Cpu stall issue may happen if device is configured with multi queues
>>> and large queue depth, so fix it.
>>>
>>> Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
>>> ---
>>>   drivers/crypto/virtio/virtio_crypto_core.c | 1 +
>>>   1 file changed, 1 insertion(+)
>>>
>>> diff --git a/drivers/crypto/virtio/virtio_crypto_core.c b/drivers/crypto/virtio/virtio_crypto_core.c
>>> index 1198bd306365..94849fa3bd74 100644
>>> --- a/drivers/crypto/virtio/virtio_crypto_core.c
>>> +++ b/drivers/crypto/virtio/virtio_crypto_core.c
>>> @@ -480,6 +480,7 @@ static void virtcrypto_free_unused_reqs(struct virtio_crypto *vcrypto)
>>>   			kfree(vc_req->req_data);
>>>   			kfree(vc_req->sgs);
>>>   		}
>>> +		cond_resched();
>> that's not "fixing a stall", it is "call the scheduler because we are
>> taking too long".  The CPU isn't stalled at all, just busy.
>>
>> Are you sure this isn't just a bug in the code?  Why is this code taking
>> so long that you have to force the scheduler to run?  This is almost
>> always a sign that something else needs to be fixed instead.
> And same comment on the other 2 patches, please fix this properly.
>
> Also, this is a tight loop that is just freeing memory, why is it taking
> so long?  Why do you want it to take longer (which is what you are doing
> here), ideally it would be faster, not slower, so you are now slowing
> down the system overall with this patchset, right?

yes, it is the similar fix with one for virtio-net

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/net/virtio_net.c?h=v6.4-rc5&id=f8bb5104394560e29017c25bcade4c6b7aabd108 
<https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/net/virtio_net.c?h=v6.4-rc5&id=f8bb5104394560e29017c25bcade4c6b7aabd108>

>
> thanks,
>
> greg k-h

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

* Re: [PATCH 1/3] virtio-crypto: fixup potential cpu stall when free unused bufs
  2023-06-09 13:49       ` Xianting Tian
@ 2023-06-09 14:05         ` Greg KH
  2023-06-09 14:25           ` Xianting Tian
  2023-06-09 16:02           ` Michael S. Tsirkin
  0 siblings, 2 replies; 19+ messages in thread
From: Greg KH @ 2023-06-09 14:05 UTC (permalink / raw)
  To: Xianting Tian
  Cc: arei.gonglei, mst, jasowang, xuanzhuo, herbert, davem, amit, arnd,
	marcel, johan.hedberg, luiz.dentz, linux-bluetooth,
	virtualization, linux-crypto, linux-kernel, Xianting Tian

On Fri, Jun 09, 2023 at 09:49:39PM +0800, Xianting Tian wrote:
> 
> 在 2023/6/9 下午9:41, Greg KH 写道:
> > On Fri, Jun 09, 2023 at 03:39:24PM +0200, Greg KH wrote:
> > > On Fri, Jun 09, 2023 at 09:18:15PM +0800, Xianting Tian wrote:
> > > > From: Xianting Tian <tianxianting.txt@alibaba-inc.com>
> > > > 
> > > > Cpu stall issue may happen if device is configured with multi queues
> > > > and large queue depth, so fix it.
> > > > 
> > > > Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
> > > > ---
> > > >   drivers/crypto/virtio/virtio_crypto_core.c | 1 +
> > > >   1 file changed, 1 insertion(+)
> > > > 
> > > > diff --git a/drivers/crypto/virtio/virtio_crypto_core.c b/drivers/crypto/virtio/virtio_crypto_core.c
> > > > index 1198bd306365..94849fa3bd74 100644
> > > > --- a/drivers/crypto/virtio/virtio_crypto_core.c
> > > > +++ b/drivers/crypto/virtio/virtio_crypto_core.c
> > > > @@ -480,6 +480,7 @@ static void virtcrypto_free_unused_reqs(struct virtio_crypto *vcrypto)
> > > >   			kfree(vc_req->req_data);
> > > >   			kfree(vc_req->sgs);
> > > >   		}
> > > > +		cond_resched();
> > > that's not "fixing a stall", it is "call the scheduler because we are
> > > taking too long".  The CPU isn't stalled at all, just busy.
> > > 
> > > Are you sure this isn't just a bug in the code?  Why is this code taking
> > > so long that you have to force the scheduler to run?  This is almost
> > > always a sign that something else needs to be fixed instead.
> > And same comment on the other 2 patches, please fix this properly.
> > 
> > Also, this is a tight loop that is just freeing memory, why is it taking
> > so long?  Why do you want it to take longer (which is what you are doing
> > here), ideally it would be faster, not slower, so you are now slowing
> > down the system overall with this patchset, right?
> 
> yes, it is the similar fix with one for virtio-net
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/net/virtio_net.c?h=v6.4-rc5&id=f8bb5104394560e29017c25bcade4c6b7aabd108 <https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/net/virtio_net.c?h=v6.4-rc5&id=f8bb5104394560e29017c25bcade4c6b7aabd108>

I would argue that this too is incorrect, because why does freeing
memory take so long?  And again, you are making it take longer, is that
ok?

thanks,

greg k-h

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

* Re: [PATCH 1/3] virtio-crypto: fixup potential cpu stall when free unused bufs
  2023-06-09 14:05         ` Greg KH
@ 2023-06-09 14:25           ` Xianting Tian
  2023-06-09 16:02           ` Michael S. Tsirkin
  1 sibling, 0 replies; 19+ messages in thread
From: Xianting Tian @ 2023-06-09 14:25 UTC (permalink / raw)
  To: Greg KH
  Cc: arei.gonglei, mst, jasowang, xuanzhuo, herbert, davem, amit, arnd,
	marcel, johan.hedberg, luiz.dentz, linux-bluetooth,
	virtualization, linux-crypto, linux-kernel, Xianting Tian


在 2023/6/9 下午10:05, Greg KH 写道:
> On Fri, Jun 09, 2023 at 09:49:39PM +0800, Xianting Tian wrote:
>> 在 2023/6/9 下午9:41, Greg KH 写道:
>>> On Fri, Jun 09, 2023 at 03:39:24PM +0200, Greg KH wrote:
>>>> On Fri, Jun 09, 2023 at 09:18:15PM +0800, Xianting Tian wrote:
>>>>> From: Xianting Tian <tianxianting.txt@alibaba-inc.com>
>>>>>
>>>>> Cpu stall issue may happen if device is configured with multi queues
>>>>> and large queue depth, so fix it.
>>>>>
>>>>> Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
>>>>> ---
>>>>>    drivers/crypto/virtio/virtio_crypto_core.c | 1 +
>>>>>    1 file changed, 1 insertion(+)
>>>>>
>>>>> diff --git a/drivers/crypto/virtio/virtio_crypto_core.c b/drivers/crypto/virtio/virtio_crypto_core.c
>>>>> index 1198bd306365..94849fa3bd74 100644
>>>>> --- a/drivers/crypto/virtio/virtio_crypto_core.c
>>>>> +++ b/drivers/crypto/virtio/virtio_crypto_core.c
>>>>> @@ -480,6 +480,7 @@ static void virtcrypto_free_unused_reqs(struct virtio_crypto *vcrypto)
>>>>>    			kfree(vc_req->req_data);
>>>>>    			kfree(vc_req->sgs);
>>>>>    		}
>>>>> +		cond_resched();
>>>> that's not "fixing a stall", it is "call the scheduler because we are
>>>> taking too long".  The CPU isn't stalled at all, just busy.
>>>>
>>>> Are you sure this isn't just a bug in the code?  Why is this code taking
>>>> so long that you have to force the scheduler to run?  This is almost
>>>> always a sign that something else needs to be fixed instead.
>>> And same comment on the other 2 patches, please fix this properly.
>>>
>>> Also, this is a tight loop that is just freeing memory, why is it taking
>>> so long?  Why do you want it to take longer (which is what you are doing
>>> here), ideally it would be faster, not slower, so you are now slowing
>>> down the system overall with this patchset, right?
>> yes, it is the similar fix with one for virtio-net
>>
>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/net/virtio_net.c?h=v6.4-rc5&id=f8bb5104394560e29017c25bcade4c6b7aabd108 <https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/net/virtio_net.c?h=v6.4-rc5&id=f8bb5104394560e29017c25bcade4c6b7aabd108>
> I would argue that this too is incorrect, because why does freeing
> memory take so long?  And again, you are making it take longer, is that
> ok?

Yes, it may take longer, but I think it's no harms.

As the queue numbers and queue's depth are uncertain, it depends on 
user's configuration. It may take more times in kernel space to free all 
queues without schedule, so it has the risk to cause other task starve


>
> thanks,
>
> greg k-h

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

* Re: [PATCH 1/3] virtio-crypto: fixup potential cpu stall when free unused bufs
  2023-06-09 13:18 ` [PATCH 1/3] virtio-crypto: fixup potential cpu stall when free unused bufs Xianting Tian
  2023-06-09 13:39   ` Greg KH
@ 2023-06-09 15:57   ` Michael S. Tsirkin
  2023-06-10  3:20     ` Xianting Tian
  2023-06-09 15:58   ` Michael S. Tsirkin
  2 siblings, 1 reply; 19+ messages in thread
From: Michael S. Tsirkin @ 2023-06-09 15:57 UTC (permalink / raw)
  To: Xianting Tian
  Cc: arei.gonglei, jasowang, xuanzhuo, herbert, davem, amit, arnd,
	gregkh, marcel, johan.hedberg, luiz.dentz, linux-bluetooth,
	virtualization, linux-crypto, linux-kernel, Xianting Tian

On Fri, Jun 09, 2023 at 09:18:15PM +0800, Xianting Tian wrote:
> From: Xianting Tian <tianxianting.txt@alibaba-inc.com>
> 
> Cpu stall issue may happen if device is configured with multi queues
> and large queue depth, so fix it.

What does "may happen" imply exactly?
was this observed?

> Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
> ---
>  drivers/crypto/virtio/virtio_crypto_core.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/crypto/virtio/virtio_crypto_core.c b/drivers/crypto/virtio/virtio_crypto_core.c
> index 1198bd306365..94849fa3bd74 100644
> --- a/drivers/crypto/virtio/virtio_crypto_core.c
> +++ b/drivers/crypto/virtio/virtio_crypto_core.c
> @@ -480,6 +480,7 @@ static void virtcrypto_free_unused_reqs(struct virtio_crypto *vcrypto)
>  			kfree(vc_req->req_data);
>  			kfree(vc_req->sgs);
>  		}
> +		cond_resched();
>  	}
>  }
>  
> -- 
> 2.17.1


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

* Re: [PATCH 1/3] virtio-crypto: fixup potential cpu stall when free unused bufs
  2023-06-09 13:18 ` [PATCH 1/3] virtio-crypto: fixup potential cpu stall when free unused bufs Xianting Tian
  2023-06-09 13:39   ` Greg KH
  2023-06-09 15:57   ` Michael S. Tsirkin
@ 2023-06-09 15:58   ` Michael S. Tsirkin
  2 siblings, 0 replies; 19+ messages in thread
From: Michael S. Tsirkin @ 2023-06-09 15:58 UTC (permalink / raw)
  To: Xianting Tian
  Cc: arei.gonglei, jasowang, xuanzhuo, herbert, davem, amit, arnd,
	gregkh, marcel, johan.hedberg, luiz.dentz, linux-bluetooth,
	virtualization, linux-crypto, linux-kernel, Xianting Tian

On Fri, Jun 09, 2023 at 09:18:15PM +0800, Xianting Tian wrote:
> From: Xianting Tian <tianxianting.txt@alibaba-inc.com>
> 
> Cpu stall issue may happen if device is configured with multi queues
> and large queue depth, so fix it.
> 
> Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>

include a Fixes tag?

> ---
>  drivers/crypto/virtio/virtio_crypto_core.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/crypto/virtio/virtio_crypto_core.c b/drivers/crypto/virtio/virtio_crypto_core.c
> index 1198bd306365..94849fa3bd74 100644
> --- a/drivers/crypto/virtio/virtio_crypto_core.c
> +++ b/drivers/crypto/virtio/virtio_crypto_core.c
> @@ -480,6 +480,7 @@ static void virtcrypto_free_unused_reqs(struct virtio_crypto *vcrypto)
>  			kfree(vc_req->req_data);
>  			kfree(vc_req->sgs);
>  		}
> +		cond_resched();
>  	}
>  }
>  
> -- 
> 2.17.1


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

* Re: [PATCH 1/3] virtio-crypto: fixup potential cpu stall when free unused bufs
  2023-06-09 14:05         ` Greg KH
  2023-06-09 14:25           ` Xianting Tian
@ 2023-06-09 16:02           ` Michael S. Tsirkin
  1 sibling, 0 replies; 19+ messages in thread
From: Michael S. Tsirkin @ 2023-06-09 16:02 UTC (permalink / raw)
  To: Greg KH
  Cc: Xianting Tian, arei.gonglei, jasowang, xuanzhuo, herbert, davem,
	amit, arnd, marcel, johan.hedberg, luiz.dentz, linux-bluetooth,
	virtualization, linux-crypto, linux-kernel, Xianting Tian

On Fri, Jun 09, 2023 at 04:05:57PM +0200, Greg KH wrote:
> On Fri, Jun 09, 2023 at 09:49:39PM +0800, Xianting Tian wrote:
> > 
> > 在 2023/6/9 下午9:41, Greg KH 写道:
> > > On Fri, Jun 09, 2023 at 03:39:24PM +0200, Greg KH wrote:
> > > > On Fri, Jun 09, 2023 at 09:18:15PM +0800, Xianting Tian wrote:
> > > > > From: Xianting Tian <tianxianting.txt@alibaba-inc.com>
> > > > > 
> > > > > Cpu stall issue may happen if device is configured with multi queues
> > > > > and large queue depth, so fix it.
> > > > > 
> > > > > Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
> > > > > ---
> > > > >   drivers/crypto/virtio/virtio_crypto_core.c | 1 +
> > > > >   1 file changed, 1 insertion(+)
> > > > > 
> > > > > diff --git a/drivers/crypto/virtio/virtio_crypto_core.c b/drivers/crypto/virtio/virtio_crypto_core.c
> > > > > index 1198bd306365..94849fa3bd74 100644
> > > > > --- a/drivers/crypto/virtio/virtio_crypto_core.c
> > > > > +++ b/drivers/crypto/virtio/virtio_crypto_core.c
> > > > > @@ -480,6 +480,7 @@ static void virtcrypto_free_unused_reqs(struct virtio_crypto *vcrypto)
> > > > >   			kfree(vc_req->req_data);
> > > > >   			kfree(vc_req->sgs);
> > > > >   		}
> > > > > +		cond_resched();
> > > > that's not "fixing a stall", it is "call the scheduler because we are
> > > > taking too long".  The CPU isn't stalled at all, just busy.
> > > > 
> > > > Are you sure this isn't just a bug in the code?  Why is this code taking
> > > > so long that you have to force the scheduler to run?  This is almost
> > > > always a sign that something else needs to be fixed instead.
> > > And same comment on the other 2 patches, please fix this properly.
> > > 
> > > Also, this is a tight loop that is just freeing memory, why is it taking
> > > so long?  Why do you want it to take longer (which is what you are doing
> > > here), ideally it would be faster, not slower, so you are now slowing
> > > down the system overall with this patchset, right?
> > 
> > yes, it is the similar fix with one for virtio-net
> > 
> > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/net/virtio_net.c?h=v6.4-rc5&id=f8bb5104394560e29017c25bcade4c6b7aabd108 <https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/net/virtio_net.c?h=v6.4-rc5&id=f8bb5104394560e29017c25bcade4c6b7aabd108>

Well that one actually at least describes the configuration:


	For multi-queue and large ring-size use case, the following error
	occurred when free_unused_bufs:
	rcu: INFO: rcu_sched self-detected stall on CPU.

So a similar fix but not a similar commit log, this one lacks Fixes tag and
description of what the problem is and when does it trigger.

> I would argue that this too is incorrect, because why does freeing
> memory take so long?

You are correct that even that one lacks detailed explanation
why does the patch help.

And the explanation why it takes so long is exactly that
we have very deep queues and a very large number of queues.
What the patch does is gives scheduler a chance
to do some work between the queues.





>  And again, you are making it take longer, is that
> ok?
> 
> thanks,
> 
> greg k-h


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

* Re: [PATCH 2/3] virtio_console: fixup potential cpu stall when free unused bufs
  2023-06-09 13:18 ` [PATCH 2/3] virtio_console: " Xianting Tian
@ 2023-06-09 16:05   ` Michael S. Tsirkin
  2023-06-10  3:19     ` Xianting Tian
  0 siblings, 1 reply; 19+ messages in thread
From: Michael S. Tsirkin @ 2023-06-09 16:05 UTC (permalink / raw)
  To: Xianting Tian
  Cc: arei.gonglei, jasowang, xuanzhuo, herbert, davem, amit, arnd,
	gregkh, marcel, johan.hedberg, luiz.dentz, linux-bluetooth,
	virtualization, linux-crypto, linux-kernel

On Fri, Jun 09, 2023 at 09:18:16PM +0800, Xianting Tian wrote:
> Cpu stall issue may happen if device is configured with multi queues
> and large queue depth, so fix it.

"may happen" is ambigous.

So is this: "for virtio-net we were getting
stall on CPU was observed message, this driver is similar
so theoretically the same logic applies"

or is this

"the following error occured: ..... "

?


> Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
> ---
>  drivers/char/virtio_console.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
> index b65c809a4e97..5ec4cf4ea919 100644
> --- a/drivers/char/virtio_console.c
> +++ b/drivers/char/virtio_console.c
> @@ -1935,6 +1935,7 @@ static void remove_vqs(struct ports_device *portdev)
>  		flush_bufs(vq, true);
>  		while ((buf = virtqueue_detach_unused_buf(vq)))
>  			free_buf(buf, true);
> +		cond_resched();
>  	}
>  	portdev->vdev->config->del_vqs(portdev->vdev);
>  	kfree(portdev->in_vqs);
> -- 
> 2.17.1


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

* Re: [PATCH 2/3] virtio_console: fixup potential cpu stall when free unused bufs
  2023-06-09 16:05   ` Michael S. Tsirkin
@ 2023-06-10  3:19     ` Xianting Tian
  0 siblings, 0 replies; 19+ messages in thread
From: Xianting Tian @ 2023-06-10  3:19 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: arei.gonglei, jasowang, xuanzhuo, herbert, davem, amit, arnd,
	gregkh, marcel, johan.hedberg, luiz.dentz, linux-bluetooth,
	virtualization, linux-crypto, linux-kernel


在 2023/6/10 上午12:05, Michael S. Tsirkin 写道:
> On Fri, Jun 09, 2023 at 09:18:16PM +0800, Xianting Tian wrote:
>> Cpu stall issue may happen if device is configured with multi queues
>> and large queue depth, so fix it.
> "may happen" is ambigous.
>
> So is this: "for virtio-net we were getting
> stall on CPU was observed message, this driver is similar
> so theoretically the same logic applies"

It is this one

  “this driver is similar so theoretically the same logic applies”

>
> or is this
>
> "the following error occured: ....."
>
> ?
>
>
>> Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
>> ---
>>   drivers/char/virtio_console.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
>> index b65c809a4e97..5ec4cf4ea919 100644
>> --- a/drivers/char/virtio_console.c
>> +++ b/drivers/char/virtio_console.c
>> @@ -1935,6 +1935,7 @@ static void remove_vqs(struct ports_device *portdev)
>>   		flush_bufs(vq, true);
>>   		while ((buf = virtqueue_detach_unused_buf(vq)))
>>   			free_buf(buf, true);
>> +		cond_resched();
>>   	}
>>   	portdev->vdev->config->del_vqs(portdev->vdev);
>>   	kfree(portdev->in_vqs);
>> -- 
>> 2.17.1

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

* Re: [PATCH 1/3] virtio-crypto: fixup potential cpu stall when free unused bufs
  2023-06-09 15:57   ` Michael S. Tsirkin
@ 2023-06-10  3:20     ` Xianting Tian
  2023-06-10  6:51       ` Greg KH
  0 siblings, 1 reply; 19+ messages in thread
From: Xianting Tian @ 2023-06-10  3:20 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: arei.gonglei, jasowang, xuanzhuo, herbert, davem, amit, arnd,
	gregkh, marcel, johan.hedberg, luiz.dentz, linux-bluetooth,
	virtualization, linux-crypto, linux-kernel, Xianting Tian


在 2023/6/9 下午11:57, Michael S. Tsirkin 写道:
> On Fri, Jun 09, 2023 at 09:18:15PM +0800, Xianting Tian wrote:
>> From: Xianting Tian <tianxianting.txt@alibaba-inc.com>
>>
>> Cpu stall issue may happen if device is configured with multi queues
>> and large queue depth, so fix it.
> What does "may happen" imply exactly?
> was this observed?
I didn't met such issue, this patch set just a theoretical fix.
>
>> Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
>> ---
>>   drivers/crypto/virtio/virtio_crypto_core.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/crypto/virtio/virtio_crypto_core.c b/drivers/crypto/virtio/virtio_crypto_core.c
>> index 1198bd306365..94849fa3bd74 100644
>> --- a/drivers/crypto/virtio/virtio_crypto_core.c
>> +++ b/drivers/crypto/virtio/virtio_crypto_core.c
>> @@ -480,6 +480,7 @@ static void virtcrypto_free_unused_reqs(struct virtio_crypto *vcrypto)
>>   			kfree(vc_req->req_data);
>>   			kfree(vc_req->sgs);
>>   		}
>> +		cond_resched();
>>   	}
>>   }
>>   
>> -- 
>> 2.17.1

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

* Re: [PATCH 1/3] virtio-crypto: fixup potential cpu stall when free unused bufs
  2023-06-10  3:20     ` Xianting Tian
@ 2023-06-10  6:51       ` Greg KH
  0 siblings, 0 replies; 19+ messages in thread
From: Greg KH @ 2023-06-10  6:51 UTC (permalink / raw)
  To: Xianting Tian
  Cc: Michael S. Tsirkin, arei.gonglei, jasowang, xuanzhuo, herbert,
	davem, amit, arnd, marcel, johan.hedberg, luiz.dentz,
	linux-bluetooth, virtualization, linux-crypto, linux-kernel,
	Xianting Tian

On Sat, Jun 10, 2023 at 11:20:49AM +0800, Xianting Tian wrote:
> 
> 在 2023/6/9 下午11:57, Michael S. Tsirkin 写道:
> > On Fri, Jun 09, 2023 at 09:18:15PM +0800, Xianting Tian wrote:
> > > From: Xianting Tian <tianxianting.txt@alibaba-inc.com>
> > > 
> > > Cpu stall issue may happen if device is configured with multi queues
> > > and large queue depth, so fix it.
> > What does "may happen" imply exactly?
> > was this observed?
> I didn't met such issue, this patch set just a theoretical fix.

Then I would not recommend adding it at this time, as you just slowed
down the kernel for something that no one has reported :(

thanks,

greg k-h

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

* Re: [PATCH 0/3] fixup potential cpu stall
  2023-06-09 13:18 [PATCH 0/3] fixup potential cpu stall Xianting Tian
                   ` (2 preceding siblings ...)
  2023-06-09 13:18 ` [PATCH 3/3] virtio_bt: " Xianting Tian
@ 2023-06-22 11:59 ` Michael S. Tsirkin
  2023-06-23  0:58   ` Xianting Tian
  2023-07-06 20:10 ` patchwork-bot+bluetooth
  4 siblings, 1 reply; 19+ messages in thread
From: Michael S. Tsirkin @ 2023-06-22 11:59 UTC (permalink / raw)
  To: Xianting Tian
  Cc: arei.gonglei, jasowang, xuanzhuo, herbert, davem, amit, arnd,
	gregkh, marcel, johan.hedberg, luiz.dentz, linux-bluetooth,
	virtualization, linux-crypto, linux-kernel

On Fri, Jun 09, 2023 at 09:18:14PM +0800, Xianting Tian wrote:
> Cpu stall issue may happen if device is configured with multi queues
> and large queue depth, so fix it.


I applied this after tweaking commit log to address Greg's comments.
In the future I expect you guys to do such tweaks yourself.

> Xianting Tian (3):
>   virtio-crypto: fixup potential cpu stall when free unused bufs
>   virtio_console: fixup potential cpu stall when free unused bufs
>   virtio_bt: fixup potential cpu stall when free unused bufs
> 
>  drivers/bluetooth/virtio_bt.c              | 1 +
>  drivers/char/virtio_console.c              | 1 +
>  drivers/crypto/virtio/virtio_crypto_core.c | 1 +
>  3 files changed, 3 insertions(+)
> 
> -- 
> 2.17.1


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

* Re: [PATCH 0/3] fixup potential cpu stall
  2023-06-22 11:59 ` [PATCH 0/3] fixup potential cpu stall Michael S. Tsirkin
@ 2023-06-23  0:58   ` Xianting Tian
  0 siblings, 0 replies; 19+ messages in thread
From: Xianting Tian @ 2023-06-23  0:58 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: arei.gonglei, jasowang, xuanzhuo, herbert, davem, amit, arnd,
	gregkh, marcel, johan.hedberg, luiz.dentz, linux-bluetooth,
	virtualization, linux-crypto, linux-kernel


在 2023/6/22 下午7:59, Michael S. Tsirkin 写道:
> On Fri, Jun 09, 2023 at 09:18:14PM +0800, Xianting Tian wrote:
>> Cpu stall issue may happen if device is configured with multi queues
>> and large queue depth, so fix it.
>
> I applied this after tweaking commit log to address Greg's comments.
> In the future I expect you guys to do such tweaks yourself.
thanks.
>
>> Xianting Tian (3):
>>    virtio-crypto: fixup potential cpu stall when free unused bufs
>>    virtio_console: fixup potential cpu stall when free unused bufs
>>    virtio_bt: fixup potential cpu stall when free unused bufs
>>
>>   drivers/bluetooth/virtio_bt.c              | 1 +
>>   drivers/char/virtio_console.c              | 1 +
>>   drivers/crypto/virtio/virtio_crypto_core.c | 1 +
>>   3 files changed, 3 insertions(+)
>>
>> -- 
>> 2.17.1

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

* Re: [PATCH 0/3] fixup potential cpu stall
  2023-06-09 13:18 [PATCH 0/3] fixup potential cpu stall Xianting Tian
                   ` (3 preceding siblings ...)
  2023-06-22 11:59 ` [PATCH 0/3] fixup potential cpu stall Michael S. Tsirkin
@ 2023-07-06 20:10 ` patchwork-bot+bluetooth
  4 siblings, 0 replies; 19+ messages in thread
From: patchwork-bot+bluetooth @ 2023-07-06 20:10 UTC (permalink / raw)
  To: Xianting Tian
  Cc: arei.gonglei, mst, jasowang, xuanzhuo, herbert, davem, amit, arnd,
	gregkh, marcel, johan.hedberg, luiz.dentz, linux-bluetooth,
	virtualization, linux-crypto, linux-kernel

Hello:

This series was applied to bluetooth/bluetooth-next.git (master)
by Michael S. Tsirkin <mst@redhat.com>:

On Fri,  9 Jun 2023 21:18:14 +0800 you wrote:
> Cpu stall issue may happen if device is configured with multi queues
> and large queue depth, so fix it.
> 
> Xianting Tian (3):
>   virtio-crypto: fixup potential cpu stall when free unused bufs
>   virtio_console: fixup potential cpu stall when free unused bufs
>   virtio_bt: fixup potential cpu stall when free unused bufs
> 
> [...]

Here is the summary with links:
  - [1/3] virtio-crypto: fixup potential cpu stall when free unused bufs
    https://git.kernel.org/bluetooth/bluetooth-next/c/7a5103b81a96
  - [2/3] virtio_console: fixup potential cpu stall when free unused bufs
    https://git.kernel.org/bluetooth/bluetooth-next/c/56b5e65efe00
  - [3/3] virtio_bt: fixup potential cpu stall when free unused bufs
    https://git.kernel.org/bluetooth/bluetooth-next/c/3845308fc8b0

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2023-07-06 20:10 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-09 13:18 [PATCH 0/3] fixup potential cpu stall Xianting Tian
2023-06-09 13:18 ` [PATCH 1/3] virtio-crypto: fixup potential cpu stall when free unused bufs Xianting Tian
2023-06-09 13:39   ` Greg KH
2023-06-09 13:41     ` Greg KH
2023-06-09 13:49       ` Xianting Tian
2023-06-09 14:05         ` Greg KH
2023-06-09 14:25           ` Xianting Tian
2023-06-09 16:02           ` Michael S. Tsirkin
2023-06-09 15:57   ` Michael S. Tsirkin
2023-06-10  3:20     ` Xianting Tian
2023-06-10  6:51       ` Greg KH
2023-06-09 15:58   ` Michael S. Tsirkin
2023-06-09 13:18 ` [PATCH 2/3] virtio_console: " Xianting Tian
2023-06-09 16:05   ` Michael S. Tsirkin
2023-06-10  3:19     ` Xianting Tian
2023-06-09 13:18 ` [PATCH 3/3] virtio_bt: " Xianting Tian
2023-06-22 11:59 ` [PATCH 0/3] fixup potential cpu stall Michael S. Tsirkin
2023-06-23  0:58   ` Xianting Tian
2023-07-06 20:10 ` patchwork-bot+bluetooth

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 read-only IMAP folder(s) and NNTP newsgroup(s).