From: David Woodhouse <dwmw2@infradead.org>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Sean Christopherson <seanjc@google.com>,
Peter Zijlstra <peterz@infradead.org>,
Paul Durrant <paul@xen.org>, Ingo Molnar <mingo@redhat.com>,
Will Deacon <will@kernel.org>, Boqun Feng <boqun@kernel.org>,
Waiman Long <longman@redhat.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
syzbot+208f7f3e5f59c11aeb90@syzkaller.appspotmail.com,
Carsten Stollmaier <stollmc@amazon.com>
Subject: Re: [PATCH v2 01/20] locking/rt: Use raw_spin_lock_irqsave() in __rwbase_read_unlock()
Date: Mon, 01 Jun 2026 14:01:07 +0100 [thread overview]
Message-ID: <787aa26cf62dfd361eea8ed19f384fc517892501.camel@infradead.org> (raw)
In-Reply-To: <14442dbf1e6d758fdd4756f2ed5c8cb2738582fb.camel@infradead.org>
[-- Attachment #1: Type: text/plain, Size: 5674 bytes --]
On Mon, 2026-06-01 at 11:52 +0100, David Woodhouse wrote:
> On Sat, 2026-05-30 at 16:40 +0200, Paolo Bonzini wrote:
> > On Sat, May 30, 2026 at 3:04 PM David Woodhouse <dwmw2@infradead.org> wrote:
> > >
> > > On Sat, 2026-05-30 at 12:26 +0200, Paolo Bonzini wrote:
> > > >
> > > > Yeah, I think so.
> > > >
> > > > The write side needs kvm->srcu so it would have to be yet another SRCU.
> > > > I initially thought that sucks for the code that calls kvm_gpc_check(),
> > > > but maybe not because it simply replaces read_lock/read_unlock.
> > > >
> > > > By using a seqcount for the data, SRCU only needs to be synchronized in
> > > > gpc_unmap(). So, something like this:
> > >
> > > It isn't just gpc_unmap() which does the invalidation. We also
> > > invalidate from the MMU notifier in gfn_to_pfn_cache_invalidate_start()
> > > which would also have to synchronize, wouldn't it?
> >
> > You're right, the write_lock_irq() there drains the readers and that
> > is needed because khva is not pinned, only kmap()-ed.
> >
> > That is already broken for the OOM case under PREEMPT_RT, where
> > rwlock_t becomes sleepable. But using SRCU would break it on
> > !PREEMPT_RT as well.
>
> I don't think 'sleepable' is the problem per se, is it? *Why* does the
> OOM killer use mmu_notifier_invalidate_range_start_nonblock()?
>
> Commit 93065ac753e4 ("mm, oom: distinguish blockable mode for mmu
> notifiers") did say:
>
> There are several blockable mmu notifiers which might sleep in
> mmu_notifier_invalidate_range_start and that is a problem for the
> oom_reaper because it needs to guarantee a forward progress so it cannot
> depend on any sleepable locks.
>
> But that was in 2018, when mmap_lock was an rw_semaphore.
>
> Is "sleepable" still a problem even when PREEMPT_RT where almost
> *everything* is now strictly sleepable? Wouldn't that mean drivers
> aren't even allowed to take their own spinlocks?
Yeah, this is *already* hosed by PREEMPT_RT's "haha let's make things
sleepable that nobody ever expected to be" approach.
It's hard to trigger as not only do you have to get the KVM process to
OOM, it also has to be *slow* to die. I ended up doing this:
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1278,6 +1278,10 @@ void exit_mmap(struct mm_struct *mm)
VMA_ITERATOR(vmi, mm, 0);
struct unmap_desc unmap;
+ if (!strcmp(current->comm, "kvm_oom_test")) {
+ pr_info("exit_mmap: delaying before mmu_notifier_release for kvm_oom_test\n");
+ schedule_timeout_uninterruptible(3*HZ);
+ }
/* mm's last user has gone, and its about to be pulled down */
mmu_notifier_release(mm);
And then we see it even when taking kvm->mn_invalidate_lock:
kvm_mmu_notifier_invalidate_range_start+0xac
0xffffffff8132732c is in kvm_mmu_notifier_invalidate_range_start (arch/x86/kvm/../../../virt/kvm/kvm_main.c:745).
740 * adjustments will be imbalanced.
741 *
742 * Pairs with the decrement in range_end().
743 */
744 spin_lock(&kvm->mn_invalidate_lock);
745 kvm->mn_active_invalidate_count++;
746 if (!mmu_notifier_range_blockable(range))
747 pr_info("KVM: non-blockable invalidate_range_start, non_block_count=%d\n", current->non_block_count);
748 spin_unlock(&kvm->mn_invalidate_lock);
749
[ 427.919969] mmap: exit_mmap: delaying before mmu_notifier_release for kvm_oom_test
[ 429.926972] BUG: sleeping function called from invalid context at kernel/locking/spinlock_rt.c:48
[ 429.926978] in_atomic(): 0, irqs_disabled(): 0, non_block: 1, pid: 280, name: oom_reaper
[ 429.926982] preempt_count: 0, expected: 0
[ 429.926984] RCU nest depth: 0, expected: 0
[ 429.926986] 4 locks held by oom_reaper/280:
[ 429.926989] #0: ffff8a61da779cb0 (&mm->mmap_lock){....}-{3:3}, at: oom_reaper+0x150/0x520
[ 429.927006] #1: ffffffffa0934f20 (mmu_notifier_invalidate_range_start){....}-{0:0}, at: zap_vma_for_reaping+0xb7/0x1d0
[ 429.927019] #2: ffffffffa0934f78 (srcu){....}-{0:0}, at: __mmu_notifier_invalidate_range_start+0xae/0x340
[ 429.927029] #3: ffff8a6240295360 (&kvm->mn_invalidate_lock){....}-{2:2}, at: kvm_mmu_notifier_invalidate_range_start+0xac/0x4b0
[ 429.927044] CPU: 26 UID: 0 PID: 280 Comm: oom_reaper Tainted: G S I 7.1.0-rc2+ #2460 PREEMPT_{RT,(lazy)}
[ 429.927051] Tainted: [S]=CPU_OUT_OF_SPEC, [I]=FIRMWARE_WORKAROUND
[ 429.927053] Hardware name: Intel Corporation S2600CW/S2600CW, BIOS SE5C610.86B.01.01.0008.021120151325 02/11/2015
[ 429.927055] Call Trace:
[ 429.927058] <TASK>
[ 429.927062] dump_stack_lvl+0x6e/0xa0
[ 429.927074] __might_resched.cold+0xeb/0x100
[ 429.927084] rt_spin_lock+0x6c/0x1a0
[ 429.927092] ? kvm_mmu_notifier_invalidate_range_start+0xac/0x4b0
[ 429.927102] kvm_mmu_notifier_invalidate_range_start+0xac/0x4b0
[ 429.927110] ? sched_update_numa+0xa0/0x270
[ 429.927129] __mmu_notifier_invalidate_range_start+0x129/0x340
[ 429.927138] ? __pfx_oom_reaper+0x10/0x10
[ 429.927144] zap_vma_for_reaping+0x186/0x1d0
[ 429.927150] ? zap_vma_for_reaping+0xb7/0x1d0
[ 429.927155] ? zap_vma_for_reaping+0xb7/0x1d0
[ 429.927176] __oom_reap_task_mm+0xbf/0x100
[ 429.927191] oom_reaper+0xeb/0x520
[ 429.927199] ? __pfx_autoremove_wake_function+0x10/0x10
[ 429.927212] kthread+0xf5/0x130
[ 429.927217] ? __pfx_kthread+0x10/0x10
[ 429.927224] ret_from_fork+0x286/0x310
[ 429.927232] ? __pfx_kthread+0x10/0x10
[ 429.927236] ret_from_fork_asm+0x1a/0x30
[ 429.927257] </TASK>
[ 429.927260] KVM: non-blockable invalidate_range_start, non_block_count=1
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5069 bytes --]
next prev parent reply other threads:[~2026-06-01 13:01 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-29 16:50 [PATCH v2 00/20] KVM: x86/xen: Fix Xen/GP/PREEMPT_RT issues with rwlock_t Sean Christopherson
2026-05-29 16:50 ` [PATCH v2 01/20] locking/rt: Use raw_spin_lock_irqsave() in __rwbase_read_unlock() Sean Christopherson
2026-05-29 19:32 ` Peter Zijlstra
2026-05-29 19:34 ` Peter Zijlstra
2026-05-29 20:05 ` Sean Christopherson
2026-05-29 20:13 ` Peter Zijlstra
2026-05-29 20:38 ` Peter Zijlstra
2026-05-30 0:54 ` Sean Christopherson
2026-05-30 10:26 ` Paolo Bonzini
2026-05-30 12:47 ` David Woodhouse
2026-05-30 14:40 ` Paolo Bonzini
2026-06-01 10:52 ` David Woodhouse
2026-06-01 13:01 ` David Woodhouse [this message]
2026-06-01 13:40 ` Sebastian Andrzej Siewior
2026-06-01 13:53 ` David Woodhouse
2026-06-01 14:47 ` Sebastian Andrzej Siewior
2026-06-01 15:11 ` David Woodhouse
2026-08-04 12:22 ` David Woodhouse
2026-06-01 9:40 ` Peter Zijlstra
2026-06-01 10:04 ` David Woodhouse
2026-05-30 13:02 ` Paolo Bonzini
2026-06-01 8:40 ` Peter Zijlstra
2026-06-01 11:11 ` Sebastian Andrzej Siewior
2026-06-01 11:40 ` Peter Zijlstra
2026-06-01 19:13 ` Paolo Bonzini
2026-06-02 7:34 ` Sebastian Andrzej Siewior
2026-06-04 23:58 ` David Woodhouse
2026-05-29 16:50 ` [PATCH v2 02/20] KVM: x86/xen: Use read_trylock() for GPC locks in hardirq/atomic paths Sean Christopherson
2026-05-29 23:28 ` Hillf Danton
2026-05-29 16:50 ` [PATCH v2 03/20] KVM: x86/xen: Remove unnecessary irqsave from GPC lock usage in xen.c Sean Christopherson
2026-05-29 16:50 ` [PATCH v2 04/20] KVM: x86: Remove unnecessary irqsave from kvm_setup_guest_pvclock() Sean Christopherson
2026-05-29 16:50 ` [PATCH v2 05/20] KVM: Remove unnecessary IRQ disabling from GPC lock in pfncache.c Sean Christopherson
2026-05-29 16:51 ` [PATCH v2 06/20] KVM: x86/xen: Use guard() to grab kvm->srcu around gpc critical sections Sean Christopherson
2026-05-29 16:51 ` [PATCH v2 07/20] KVM: x86/xen: Extract delivery of event to vCPU into a separate helper Sean Christopherson
2026-05-29 16:51 ` [PATCH v2 08/20] KVM: x86/xen: Explicitly tag "shared info" page as never being dirty tracked Sean Christopherson
2026-05-29 16:51 ` [PATCH v2 09/20] KVM: x86/xen: Don't dirty track "vCPU info" page Sean Christopherson
2026-05-29 16:51 ` [PATCH v2 10/20] KVM: Move {g,p}fn <=> {g,h}pa conversion helpers to kvm_types.h Sean Christopherson
2026-05-29 16:51 ` [PATCH v2 11/20] KVM: Add CLASS() constructs to automagically handle lock+check of gpc Sean Christopherson
2026-05-29 16:51 ` [PATCH v2 12/20] KVM: x86/xen: Convert kvm_xen_shared_info_init() to gpc's CLASS() APIs Sean Christopherson
2026-05-29 16:51 ` [PATCH v2 13/20] KVM: x86/xen: Don't bother waiting on gpc->lock in SCHEDOP_poll Sean Christopherson
2026-05-29 16:51 ` [PATCH v2 14/20] KVM: x86/xen: Convert wait_pending_event() to gpc's CLASS() APIs Sean Christopherson
2026-05-29 16:51 ` [PATCH v2 15/20] KVM: x86/xen: Convert kvm_xen_set_evtchn_fast() " Sean Christopherson
2026-05-29 16:51 ` [PATCH v2 16/20] KVM: x86/xen: Convert xen_get_guest_pvclock() " Sean Christopherson
2026-05-29 16:51 ` [PATCH v2 17/20] KVM: x86/xen: Drop local "kick_vcpu" from __kvm_xen_set_evtchn_fast() Sean Christopherson
2026-05-29 16:51 ` [PATCH v2 18/20] KVM: x86/xen: Convert event injection to gpc's CLASS() APIs Sean Christopherson
2026-05-29 16:51 ` [PATCH v2 19/20] KVM: Add "extended" gpc CLASS() APIs for sometimes-atomic cases Sean Christopherson
2026-05-29 16:51 ` [PATCH v2 20/20] KVM: x86: Use gfn_to_pfn_cache for record_steal_time Sean Christopherson
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=787aa26cf62dfd361eea8ed19f384fc517892501.camel@infradead.org \
--to=dwmw2@infradead.org \
--cc=bigeasy@linutronix.de \
--cc=boqun@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--cc=paul@xen.org \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=seanjc@google.com \
--cc=stollmc@amazon.com \
--cc=syzbot+208f7f3e5f59c11aeb90@syzkaller.appspotmail.com \
--cc=will@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
all inboxes | Powered by JetHome®