* [PATCH] KVM: x86/xen: defer timer event delivery on PREEMPT_RT
@ 2026-12-03 9:18 Yang Luohan
2026-12-03 9:35 ` sashiko-bot
2026-12-03 11:00 ` [PATCH v2] " Yang Luohan
0 siblings, 2 replies; 6+ messages in thread
From: Yang Luohan @ 2026-12-03 9:18 UTC (permalink / raw)
To: kvm
Cc: David Woodhouse, Paul Durrant, Sean Christopherson, Paolo Bonzini,
linux-kernel
xen_timer_callback() runs from an hrtimer, so it executes with interrupts
disabled. It calls kvm_xen_set_evtchn_fast(), which acquires gpc->lock with
read_lock_irqsave(). On PREEMPT_RT rwlock_t is a sleeping lock, and taking
it in that context reports:
BUG: sleeping function called from invalid context at
kernel/locking/spinlock_rt.c:248
in_atomic(): 1, irqs_disabled(): 1
kvm_xen_set_evtchn_fast
xen_timer_callback
The callback already handles -EWOULDBLOCK by recording the pending timer
and raising KVM_REQ_UNBLOCK, and the delivery is then completed from
vCPU context by kvm_xen_inject_timer_irqs(). On PREEMPT_RT, skip the
fast path and let that deferred path run instead of taking a sleeping
lock from hardirq context.
Signed-off-by: Yang Luohan <ylh440104@gmail.com>
---
arch/x86/kvm/xen.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c
index 6aa00f7..5440b96 100644
--- a/arch/x86/kvm/xen.c
+++ b/arch/x86/kvm/xen.c
@@ -136,7 +136,11 @@ static enum hrtimer_restart xen_timer_callback(struct hrtimer *timer)
e.port = vcpu->arch.xen.timer_virq;
e.priority = KVM_IRQ_ROUTING_XEN_EVTCHN_PRIO_2LEVEL;
- rc = kvm_xen_set_evtchn_fast(&e, vcpu->kvm);
+ if (IS_ENABLED(CONFIG_PREEMPT_RT) && !preemptible())
+ rc = -EWOULDBLOCK;
+ else
+ rc = kvm_xen_set_evtchn_fast(&e, vcpu->kvm);
+
if (rc != -EWOULDBLOCK) {
vcpu->arch.xen.timer_expires = 0;
return HRTIMER_NORESTART;
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] KVM: x86/xen: defer timer event delivery on PREEMPT_RT
2026-12-03 9:18 [PATCH] KVM: x86/xen: defer timer event delivery on PREEMPT_RT Yang Luohan
@ 2026-12-03 9:35 ` sashiko-bot
2026-12-03 11:00 ` [PATCH v2] " Yang Luohan
1 sibling, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-12-03 9:35 UTC (permalink / raw)
To: Yang Luohan, kvm
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] KVM: x86/xen: missing Fixes trailer for commit 77c9b9dea4fb
--
commit 21cb04c9f920ff2e2b8066f225f0bcf72b648f06
Author: Yang Luohan <ylh440104@gmail.com>
> KVM: x86/xen: defer timer event delivery on PREEMPT_RT
>
> xen_timer_callback() runs from an hrtimer, so it executes with interrupts
> disabled. It calls kvm_xen_set_evtchn_fast(), which acquires gpc->lock with
> read_lock_irqsave(). On PREEMPT_RT rwlock_t is a sleeping lock, and taking
> it in that context reports:
>
> BUG: sleeping function called from invalid context at
> kernel/locking/spinlock_rt.c:248
> in_atomic(): 1, irqs_disabled(): 1
> kvm_xen_set_evtchn_fast
> xen_timer_callback
>
> The callback already handles -EWOULDBLOCK by recording the pending timer
> and raising KVM_REQ_UNBLOCK, and the delivery is then completed from
> vCPU context by kvm_xen_inject_timer_irqs(). On PREEMPT_RT, skip the
> fast path and let that deferred path run instead of taking a sleeping
> lock from hardirq context.
>
> Signed-off-by: Yang Luohan <ylh440104@gmail.com>
[Severity: Low]
This fixes a sleeping-in-invalid-context bug on PREEMPT_RT introduced
when xen_timer_callback() started calling kvm_xen_set_evtchn_fast().
Should this include:
Fixes: 77c9b9dea4fb ("KVM: x86/xen: Use fast path for Xen timer delivery")
--
Sashiko AI review · https://sashiko.dev/#/patchset/179628948570.2061.8987479680072097733@gmail.com?part=1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] KVM: x86/xen: defer timer event delivery on PREEMPT_RT
2026-12-03 9:18 [PATCH] KVM: x86/xen: defer timer event delivery on PREEMPT_RT Yang Luohan
2026-12-03 9:35 ` sashiko-bot
@ 2026-12-03 11:00 ` Yang Luohan
2026-12-03 15:13 ` Sean Christopherson
1 sibling, 1 reply; 6+ messages in thread
From: Yang Luohan @ 2026-12-03 11:00 UTC (permalink / raw)
To: kvm
Cc: David Woodhouse, Paul Durrant, Sean Christopherson, Paolo Bonzini,
linux-kernel
xen_timer_callback() runs from an hrtimer, so it executes with interrupts
disabled. It calls kvm_xen_set_evtchn_fast(), which acquires gpc->lock with
read_lock_irqsave(). On PREEMPT_RT rwlock_t is a sleeping lock, and taking
it in that context reports:
BUG: sleeping function called from invalid context at
kernel/locking/spinlock_rt.c:248
in_atomic(): 1, irqs_disabled(): 1
kvm_xen_set_evtchn_fast
xen_timer_callback
The callback already handles -EWOULDBLOCK by recording the pending timer
and raising KVM_REQ_UNBLOCK, and the delivery is then completed from
vCPU context by kvm_xen_inject_timer_irqs(). On PREEMPT_RT, skip the
fast path and let that deferred path run instead of taking a sleeping
lock from hardirq context.
Fixes: 77c9b9dea4fb ("KVM: x86/xen: Use fast path for Xen timer delivery")
Signed-off-by: Yang Luohan <ylh440104@gmail.com>
---
arch/x86/kvm/xen.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c
index 6aa00f7..5440b96 100644
--- a/arch/x86/kvm/xen.c
+++ b/arch/x86/kvm/xen.c
@@ -136,7 +136,11 @@ static enum hrtimer_restart xen_timer_callback(struct hrtimer *timer)
e.port = vcpu->arch.xen.timer_virq;
e.priority = KVM_IRQ_ROUTING_XEN_EVTCHN_PRIO_2LEVEL;
- rc = kvm_xen_set_evtchn_fast(&e, vcpu->kvm);
+ if (IS_ENABLED(CONFIG_PREEMPT_RT) && !preemptible())
+ rc = -EWOULDBLOCK;
+ else
+ rc = kvm_xen_set_evtchn_fast(&e, vcpu->kvm);
+
if (rc != -EWOULDBLOCK) {
vcpu->arch.xen.timer_expires = 0;
return HRTIMER_NORESTART;
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2] KVM: x86/xen: defer timer event delivery on PREEMPT_RT
2026-12-03 11:00 ` [PATCH v2] " Yang Luohan
@ 2026-12-03 15:13 ` Sean Christopherson
2026-12-03 15:20 ` David Woodhouse
0 siblings, 1 reply; 6+ messages in thread
From: Sean Christopherson @ 2026-12-03 15:13 UTC (permalink / raw)
To: Yang Luohan
Cc: kvm, David Woodhouse, Paul Durrant, Paolo Bonzini, linux-kernel
On Thu, Dec 03, 2026, Yang Luohan wrote:
> xen_timer_callback() runs from an hrtimer, so it executes with interrupts
> disabled. It calls kvm_xen_set_evtchn_fast(), which acquires gpc->lock with
> read_lock_irqsave(). On PREEMPT_RT rwlock_t is a sleeping lock, and taking
> it in that context reports:
>
> BUG: sleeping function called from invalid context at
> kernel/locking/spinlock_rt.c:248
> in_atomic(): 1, irqs_disabled(): 1
> kvm_xen_set_evtchn_fast
> xen_timer_callback
>
> The callback already handles -EWOULDBLOCK by recording the pending timer
> and raising KVM_REQ_UNBLOCK, and the delivery is then completed from
> vCPU context by kvm_xen_inject_timer_irqs(). On PREEMPT_RT, skip the
> fast path and let that deferred path run instead of taking a sleeping
> lock from hardirq context.
>
> Fixes: 77c9b9dea4fb ("KVM: x86/xen: Use fast path for Xen timer delivery")
> Signed-off-by: Yang Luohan <ylh440104@gmail.com>
> ---
> arch/x86/kvm/xen.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c
> index 6aa00f7..5440b96 100644
> --- a/arch/x86/kvm/xen.c
> +++ b/arch/x86/kvm/xen.c
> @@ -136,7 +136,11 @@ static enum hrtimer_restart xen_timer_callback(struct hrtimer *timer)
> e.port = vcpu->arch.xen.timer_virq;
> e.priority = KVM_IRQ_ROUTING_XEN_EVTCHN_PRIO_2LEVEL;
>
> - rc = kvm_xen_set_evtchn_fast(&e, vcpu->kvm);
> + if (IS_ENABLED(CONFIG_PREEMPT_RT) && !preemptible())
> + rc = -EWOULDBLOCK;
> + else
> + rc = kvm_xen_set_evtchn_fast(&e, vcpu->kvm);
> +
This is a long-known issue, and is being addressed by switching away from rwlocks
entirely.
Thanks!
https://lore.kernel.org/all/20261105020104.2507083-9-dwmw2@infradead.org
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] KVM: x86/xen: defer timer event delivery on PREEMPT_RT
2026-12-03 15:13 ` Sean Christopherson
@ 2026-12-03 15:20 ` David Woodhouse
2026-12-03 21:08 ` Sean Christopherson
0 siblings, 1 reply; 6+ messages in thread
From: David Woodhouse @ 2026-12-03 15:20 UTC (permalink / raw)
To: Sean Christopherson, Yang Luohan
Cc: kvm, Paul Durrant, Paolo Bonzini, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 2109 bytes --]
On Thu, 2026-12-03 at 07:13 -0800, Sean Christopherson wrote:
> On Thu, Dec 03, 2026, Yang Luohan wrote:
> > xen_timer_callback() runs from an hrtimer, so it executes with interrupts
> > disabled. It calls kvm_xen_set_evtchn_fast(), which acquires gpc->lock with
> > read_lock_irqsave(). On PREEMPT_RT rwlock_t is a sleeping lock, and taking
> > it in that context reports:
> >
> > BUG: sleeping function called from invalid context at
> > kernel/locking/spinlock_rt.c:248
> > in_atomic(): 1, irqs_disabled(): 1
> > kvm_xen_set_evtchn_fast
> > xen_timer_callback
> >
> > The callback already handles -EWOULDBLOCK by recording the pending timer
> > and raising KVM_REQ_UNBLOCK, and the delivery is then completed from
> > vCPU context by kvm_xen_inject_timer_irqs(). On PREEMPT_RT, skip the
> > fast path and let that deferred path run instead of taking a sleeping
> > lock from hardirq context.
> >
> > Fixes: 77c9b9dea4fb ("KVM: x86/xen: Use fast path for Xen timer delivery")
> > Signed-off-by: Yang Luohan <ylh440104@gmail.com>
> > ---
> > arch/x86/kvm/xen.c | 6 +++++-
> > 1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c
> > index 6aa00f7..5440b96 100644
> > --- a/arch/x86/kvm/xen.c
> > +++ b/arch/x86/kvm/xen.c
> > @@ -136,7 +136,11 @@ static enum hrtimer_restart xen_timer_callback(struct hrtimer *timer)
> > e.port = vcpu->arch.xen.timer_virq;
> > e.priority = KVM_IRQ_ROUTING_XEN_EVTCHN_PRIO_2LEVEL;
> >
> > - rc = kvm_xen_set_evtchn_fast(&e, vcpu->kvm);
> > + if (IS_ENABLED(CONFIG_PREEMPT_RT) && !preemptible())
> > + rc = -EWOULDBLOCK;
> > + else
> > + rc = kvm_xen_set_evtchn_fast(&e, vcpu->kvm);
> > +
>
> This is a long-known issue, and is being addressed by switching away from rwlocks
> entirely.
>
> Thanks!
>
> https://lore.kernel.org/all/20261105020104.2507083-9-dwmw2@infradead.org
We said you'd pick up patches 1-9 of that series as-is, and I'd keep on
with refining the nested stuff in the latter half of the series later,
yes?
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6179 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] KVM: x86/xen: defer timer event delivery on PREEMPT_RT
2026-12-03 15:20 ` David Woodhouse
@ 2026-12-03 21:08 ` Sean Christopherson
0 siblings, 0 replies; 6+ messages in thread
From: Sean Christopherson @ 2026-12-03 21:08 UTC (permalink / raw)
To: David Woodhouse
Cc: Yang Luohan, kvm, Paul Durrant, Paolo Bonzini, linux-kernel
On Thu, Dec 03, 2026, David Woodhouse wrote:
> On Thu, 2026-12-03 at 07:13 -0800, Sean Christopherson wrote:
> > On Thu, Dec 03, 2026, Yang Luohan wrote:
> > > xen_timer_callback() runs from an hrtimer, so it executes with interrupts
> > > disabled. It calls kvm_xen_set_evtchn_fast(), which acquires gpc->lock with
> > > read_lock_irqsave(). On PREEMPT_RT rwlock_t is a sleeping lock, and taking
> > > it in that context reports:
> > >
> > > BUG: sleeping function called from invalid context at
> > > kernel/locking/spinlock_rt.c:248
> > > in_atomic(): 1, irqs_disabled(): 1
> > > kvm_xen_set_evtchn_fast
> > > xen_timer_callback
> > >
> > > The callback already handles -EWOULDBLOCK by recording the pending timer
> > > and raising KVM_REQ_UNBLOCK, and the delivery is then completed from
> > > vCPU context by kvm_xen_inject_timer_irqs(). On PREEMPT_RT, skip the
> > > fast path and let that deferred path run instead of taking a sleeping
> > > lock from hardirq context.
> > >
> > > Fixes: 77c9b9dea4fb ("KVM: x86/xen: Use fast path for Xen timer delivery")
> > > Signed-off-by: Yang Luohan <ylh440104@gmail.com>
> > > ---
> > > arch/x86/kvm/xen.c | 6 +++++-
> > > 1 file changed, 5 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c
> > > index 6aa00f7..5440b96 100644
> > > --- a/arch/x86/kvm/xen.c
> > > +++ b/arch/x86/kvm/xen.c
> > > @@ -136,7 +136,11 @@ static enum hrtimer_restart xen_timer_callback(struct hrtimer *timer)
> > > e.port = vcpu->arch.xen.timer_virq;
> > > e.priority = KVM_IRQ_ROUTING_XEN_EVTCHN_PRIO_2LEVEL;
> > >
> > > - rc = kvm_xen_set_evtchn_fast(&e, vcpu->kvm);
> > > + if (IS_ENABLED(CONFIG_PREEMPT_RT) && !preemptible())
> > > + rc = -EWOULDBLOCK;
> > > + else
> > > + rc = kvm_xen_set_evtchn_fast(&e, vcpu->kvm);
> > > +
> >
> > This is a long-known issue, and is being addressed by switching away from rwlocks
> > entirely.
> >
> > Thanks!
> >
> > https://lore.kernel.org/all/20261105020104.2507083-9-dwmw2@infradead.org
>
> We said you'd pick up patches 1-9 of that series as-is, and I'd keep on
> with refining the nested stuff in the latter half of the series later,
> yes?
Yep, I'm trying to get there.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-12-03 21:08 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 9:18 [PATCH] KVM: x86/xen: defer timer event delivery on PREEMPT_RT Yang Luohan
2026-12-03 9:35 ` sashiko-bot
2026-12-03 11:00 ` [PATCH v2] " Yang Luohan
2026-12-03 15:13 ` Sean Christopherson
2026-12-03 15:20 ` David Woodhouse
2026-12-03 21:08 ` Sean Christopherson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox