Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Mauricio Faria de Oliveira <mfo@igalia.com>,
	Paul Durrant <paul@xen.org>,
	 Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Borislav Petkov <bp@alien8.de>,
	 Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	Clark Williams <clrkwllms@kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	 kernel-dev@igalia.com, kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org,  linux-rt-devel@lists.linux.dev,
	 syzbot+208f7f3e5f59c11aeb90@syzkaller.appspotmail.com
Subject: Re: [PATCH] KVM: x86/xen: bail in IRQ context on PREEMPT_RT in kvm_xen_set_evtchn_fast()
Date: Thu, 07 May 2026 14:43:20 +0100	[thread overview]
Message-ID: <e082f19aecf2d2acd30782ea9220aedac3d3f990.camel@infradead.org> (raw)
In-Reply-To: <20260507132115.w1nOBvlS@linutronix.de>

[-- Attachment #1: Type: text/plain, Size: 3218 bytes --]

On Thu, 2026-05-07 at 15:21 +0200, Sebastian Andrzej Siewior wrote:
> On 2026-05-07 14:00:49 [+0100], David Woodhouse wrote:
> > On Thu, 2026-05-07 at 09:12 +0200, Sebastian Andrzej Siewior wrote:
> > > 
> > > So the cited patch does not look bad. That read-trylock should be fine
> > > on RT (as in I don't see anything wrong with it). What did happen to it?
> > 
> > The read_trylock() may be fine... but does a read_unlock() try to
> > "re-enable" hardirqs?
> 
> Yes, I missed it while looking for it. This could become a _irqsave().
> 
> We do this already for spinlock_t/ rt_spin_lock()/ _unlock() because it
> is used during early boot where interrupts are disabled and locks are
> acquired. So it needs to preserve the state and since rwlock_t is not
> (yet) used during early boot it was not done/ observed.
> 
> The try-lock on the read lock just increments a counter in order to
> acquire the lock. This is it. The spinlock_t on the other hand records
> the current context as owner which can lead to a mess. Therefore a
> trylock on a spinlock_t from hardirq context is wrong but it should be
> doable for rwlock_t. I don't see anything wrong with it (except for this
> one thing can be corrected).

Thanks. Something like this?

From 7199173d543d25333418537bcf07d6b2fce18ff1 Mon Sep 17 00:00:00 2001
From: David Woodhouse <dwmw@amazon.co.uk>
Date: Thu, 7 May 2026 14:39:22 +0100
Subject: [PATCH] locking/rt: Use raw_spin_lock_irqsave() in
 __rwbase_read_unlock()

__rwbase_read_unlock() uses raw_spin_lock_irq()/raw_spin_unlock_irq()
which unconditionally disables and re-enables interrupts. When
read_unlock() is called from hardirq context (e.g. after a successful
read_trylock() in a timer callback), the raw_spin_unlock_irq()
incorrectly re-enables interrupts within the hardirq handler.

This causes lockdep warnings ('hardirqs_on_prepare' from hardirq
context) and can lead to IRQ state corruption.

Switch to raw_spin_lock_irqsave()/raw_spin_unlock_irqrestore() to
preserve the caller's IRQ state, matching the pattern already used
for rt_spin_lock/unlock.

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
 kernel/locking/rwbase_rt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/locking/rwbase_rt.c b/kernel/locking/rwbase_rt.c
index 82e078c0665a..25744862d627 100644
--- a/kernel/locking/rwbase_rt.c
+++ b/kernel/locking/rwbase_rt.c
@@ -153,8 +153,9 @@ static void __sched __rwbase_read_unlock(struct rwbase_rt *rwb,
 	struct rt_mutex_base *rtm = &rwb->rtmutex;
 	struct task_struct *owner;
 	DEFINE_RT_WAKE_Q(wqh);
+	unsigned long flags;
 
-	raw_spin_lock_irq(&rtm->wait_lock);
+	raw_spin_lock_irqsave(&rtm->wait_lock, flags);
 	/*
 	 * Wake the writer, i.e. the rtmutex owner. It might release the
 	 * rtmutex concurrently in the fast path (due to a signal), but to
@@ -167,7 +168,7 @@ static void __sched __rwbase_read_unlock(struct rwbase_rt *rwb,
 
 	/* Pairs with the preempt_enable in rt_mutex_wake_up_q() */
 	preempt_disable();
-	raw_spin_unlock_irq(&rtm->wait_lock);
+	raw_spin_unlock_irqrestore(&rtm->wait_lock, flags);
 	rt_mutex_wake_up_q(&wqh);
 }
 
-- 
2.43.0



[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5069 bytes --]

  reply	other threads:[~2026-05-07 13:43 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-07  2:36 [PATCH] KVM: x86/xen: bail in IRQ context on PREEMPT_RT in kvm_xen_set_evtchn_fast() Mauricio Faria de Oliveira
2026-05-07  6:58 ` David Woodhouse
2026-05-07  7:12   ` Sebastian Andrzej Siewior
2026-05-07  7:30     ` David Woodhouse
2026-05-07 13:00     ` David Woodhouse
2026-05-07 13:21       ` Sebastian Andrzej Siewior
2026-05-07 13:43         ` David Woodhouse [this message]
2026-05-07 14:54           ` Sebastian Andrzej Siewior
2026-05-07 14:56   ` Mauricio Faria de Oliveira
2026-05-07 15:22     ` David Woodhouse
2026-05-07 16:02       ` Mauricio Faria de Oliveira
2026-05-07 16:15         ` David Woodhouse
2026-05-07 16:34           ` Mauricio Faria de Oliveira
2026-05-07 17:45             ` David Woodhouse
2026-05-08 17:48         ` David Woodhouse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e082f19aecf2d2acd30782ea9220aedac3d3f990.camel@infradead.org \
    --to=dwmw2@infradead.org \
    --cc=bigeasy@linutronix.de \
    --cc=bp@alien8.de \
    --cc=clrkwllms@kernel.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=kernel-dev@igalia.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=mfo@igalia.com \
    --cc=mingo@redhat.com \
    --cc=paul@xen.org \
    --cc=pbonzini@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=seanjc@google.com \
    --cc=syzbot+208f7f3e5f59c11aeb90@syzkaller.appspotmail.com \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox