* [PATCH] vhost: Run TIF_NOTIFY_RESUME work in the vhost_task loop
@ 2026-10-31 1:33 Aamir Ahmed
2026-10-31 19:05 ` Shakeel Butt
2026-11-02 22:09 ` Michael S. Tsirkin
0 siblings, 2 replies; 4+ messages in thread
From: Aamir Ahmed @ 2026-10-31 1:33 UTC (permalink / raw)
To: Michael S. Tsirkin, Jason Wang, Eugenio Pérez
Cc: Valentin Schneider, Aaron Lu, Peter Zijlstra, kvm, virtualization,
netdev, linux-kernel, Aamir Ahmed, stable
Since commit e1fad12dcb66 ("sched/fair: Switch to task based throttle
model"), a throttled task is only dequeued when TWA_RESUME task_work
runs on its way back to user mode.
vhost workers never return to user mode, and vhost_task_fn() only runs
task_work via get_signal() when a signal is pending. A busy vhost worker
therefore ignores its cgroup's cpu.max, while its runtime is still
charged to the group, throttling the group's other tasks (typically the
VM's vCPUs) harder.
Run pending notify-resume work at the top of the worker loop, as io-wq
does in io_run_task_work(). Commit 12013e3d4695 ("KVM: powerpc: Use
generic xfer to guest work function") fixed the same problem for KVM.
Fixes: e1fad12dcb66 ("sched/fair: Switch to task based throttle model")
Cc: stable@vger.kernel.org # 6.18+
Assisted-by: LLM
Signed-off-by: Aamir Ahmed <elb12345@hotmail.co.uk>
---
Tested on x86_64 with a vhost_task-based reproducer: in a 0.2-CPU cgroup
a busy worker drops from 100% to 19% of a CPU. Reproducer available on
request.
kernel/vhost_task.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/kernel/vhost_task.c b/kernel/vhost_task.c
index 3717885a599..7fa96e1b85b 100644
--- a/kernel/vhost_task.c
+++ b/kernel/vhost_task.c
@@ -6,6 +6,7 @@
#include <linux/completion.h>
#include <linux/sched/task.h>
#include <linux/sched/vhost_task.h>
+#include <linux/resume_user_mode.h>
#include <linux/sched/signal.h>
enum vhost_task_flags {
@@ -31,6 +32,14 @@ static int vhost_task_fn(void *data)
for (;;) {
bool did_work;
+ /*
+ * We never return to user mode, so TWA_RESUME task_work (e.g. CFS
+ * bandwidth throttling) would otherwise never run. Run it here,
+ * where no locks are held, like io-wq workers do.
+ */
+ if (test_thread_flag(TIF_NOTIFY_RESUME))
+ resume_user_mode_work(NULL);
+
if (signal_pending(current)) {
struct ksignal ksig;
base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] vhost: Run TIF_NOTIFY_RESUME work in the vhost_task loop
2026-10-31 1:33 [PATCH] vhost: Run TIF_NOTIFY_RESUME work in the vhost_task loop Aamir Ahmed
@ 2026-10-31 19:05 ` Shakeel Butt
2026-11-02 22:09 ` Michael S. Tsirkin
1 sibling, 0 replies; 4+ messages in thread
From: Shakeel Butt @ 2026-10-31 19:05 UTC (permalink / raw)
To: Aamir Ahmed
Cc: Michael S. Tsirkin, Jason Wang, Eugenio Pérez,
Valentin Schneider, Aaron Lu, Peter Zijlstra, kvm, virtualization,
netdev, linux-kernel, stable
On Sat, Oct 31, 2026 at 01:33:13AM +0000, Aamir Ahmed wrote:
> Since commit e1fad12dcb66 ("sched/fair: Switch to task based throttle
> model"), a throttled task is only dequeued when TWA_RESUME task_work
> runs on its way back to user mode.
>
> vhost workers never return to user mode, and vhost_task_fn() only runs
> task_work via get_signal() when a signal is pending. A busy vhost worker
> therefore ignores its cgroup's cpu.max, while its runtime is still
> charged to the group, throttling the group's other tasks (typically the
> VM's vCPUs) harder.
>
> Run pending notify-resume work at the top of the worker loop, as io-wq
> does in io_run_task_work(). Commit 12013e3d4695 ("KVM: powerpc: Use
> generic xfer to guest work function") fixed the same problem for KVM.
>
> Fixes: e1fad12dcb66 ("sched/fair: Switch to task based throttle model")
> Cc: stable@vger.kernel.org # 6.18+
> Assisted-by: LLM
> Signed-off-by: Aamir Ahmed <elb12345@hotmail.co.uk>
I have this (almost) same patch but for different reasons i.e. memory.high and
block throtlling.
http://lore.kernel.org/20261031181004.4193627-1-shakeel.butt@linux.dev
If you don't mind, can you update the commit message to also include that it
will fix memory.high and cgroup block throttling as well?
You can add:
Reviewed-by: Shakeel Butt <shakeel.butt@linux.dev>
Tested-by: Shakeel Butt <shakeel.butt@linux.dev>
BTW there is a similar issue with io_uring SQPOLL thread which I am fixing
(testing at the moment), you might be interested.
thanks,
Shakeel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] vhost: Run TIF_NOTIFY_RESUME work in the vhost_task loop
2026-10-31 1:33 [PATCH] vhost: Run TIF_NOTIFY_RESUME work in the vhost_task loop Aamir Ahmed
2026-10-31 19:05 ` Shakeel Butt
@ 2026-11-02 22:09 ` Michael S. Tsirkin
2026-11-03 10:13 ` Aamir Ahmed
1 sibling, 1 reply; 4+ messages in thread
From: Michael S. Tsirkin @ 2026-11-02 22:09 UTC (permalink / raw)
To: Aamir Ahmed
Cc: Jason Wang, Eugenio Pérez, Valentin Schneider, Aaron Lu,
Peter Zijlstra, kvm, virtualization, netdev, linux-kernel, stable
On Sat, Oct 31, 2026 at 01:33:13AM +0000, Aamir Ahmed wrote:
> Since commit e1fad12dcb66 ("sched/fair: Switch to task based throttle
> model"), a throttled task is only dequeued when TWA_RESUME task_work
> runs on its way back to user mode.
>
> vhost workers never return to user mode, and vhost_task_fn() only runs
> task_work via get_signal() when a signal is pending. A busy vhost worker
> therefore ignores its cgroup's cpu.max, while its runtime is still
> charged to the group, throttling the group's other tasks (typically the
> VM's vCPUs) harder.
>
> Run pending notify-resume work at the top of the worker loop, as io-wq
> does in io_run_task_work(). Commit 12013e3d4695 ("KVM: powerpc: Use
> generic xfer to guest work function") fixed the same problem for KVM.
>
> Fixes: e1fad12dcb66 ("sched/fair: Switch to task based throttle model")
> Cc: stable@vger.kernel.org # 6.18+
> Assisted-by: LLM
> Signed-off-by: Aamir Ahmed <elb12345@hotmail.co.uk>
Could you pls respond to Sashiko's review?
> ---
> Tested on x86_64 with a vhost_task-based reproducer: in a 0.2-CPU cgroup
> a busy worker drops from 100% to 19% of a CPU. Reproducer available on
> request.
>
> kernel/vhost_task.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/kernel/vhost_task.c b/kernel/vhost_task.c
> index 3717885a599..7fa96e1b85b 100644
> --- a/kernel/vhost_task.c
> +++ b/kernel/vhost_task.c
> @@ -6,6 +6,7 @@
> #include <linux/completion.h>
> #include <linux/sched/task.h>
> #include <linux/sched/vhost_task.h>
> +#include <linux/resume_user_mode.h>
> #include <linux/sched/signal.h>
>
> enum vhost_task_flags {
> @@ -31,6 +32,14 @@ static int vhost_task_fn(void *data)
> for (;;) {
> bool did_work;
>
> + /*
> + * We never return to user mode, so TWA_RESUME task_work (e.g. CFS
> + * bandwidth throttling) would otherwise never run. Run it here,
> + * where no locks are held, like io-wq workers do.
> + */
> + if (test_thread_flag(TIF_NOTIFY_RESUME))
> + resume_user_mode_work(NULL);
> +
> if (signal_pending(current)) {
> struct ksignal ksig;
>
>
> base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222
> --
> 2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] vhost: Run TIF_NOTIFY_RESUME work in the vhost_task loop
2026-11-02 22:09 ` Michael S. Tsirkin
@ 2026-11-03 10:13 ` Aamir Ahmed
0 siblings, 0 replies; 4+ messages in thread
From: Aamir Ahmed @ 2026-11-03 10:13 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Shakeel Butt, Jason Wang, Eugenio Pérez, Valentin Schneider,
Aaron Lu, Peter Zijlstra, kvm, virtualization, netdev,
linux-kernel, stable
On Mon, Nov 02, 2026 at 05:09:42PM -0500, Michael S. Tsirkin wrote:
> Could you pls respond to Sashiko's review?
On review, Sashiko's points don't seem to hold:
1. throttle_cfs_rq_work() runs from task_work_run(), which calls
cond_resched() after each work item:
do {
next = work->next;
work->func(work);
work = next;
cond_resched();
} while (work);
throttle_cfs_rq_work() has already called resched_curr(), so with
preempt=none/voluntary the worker is switched out at that
cond_resched(). With preempt=full/lazy it is switched out earlier,
at the rq unlock. Either way this happens inside
resume_user_mode_work(), before vtsk->fn(), with no locks held.
Traced on 6.18 with preempt=none: each throttle switch-out was in
__cond_resched() called from task_work_run().
2. Depends on fn() running while throttled, which per 1 doesn't
happen.
3. Re-armed throttle work is queued at pick time and run by
task_work_run() before it returns. Anything armed later is handled
at the next loop top, which is normal deferred throttling.
Will raise a v2 now with Shakeel's previous points.
Kind Regards
Aamir
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-03 10:13 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-31 1:33 [PATCH] vhost: Run TIF_NOTIFY_RESUME work in the vhost_task loop Aamir Ahmed
2026-10-31 19:05 ` Shakeel Butt
2026-11-02 22:09 ` Michael S. Tsirkin
2026-11-03 10:13 ` Aamir Ahmed
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox