mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: sashiko-bot@kernel.org,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	 Mauricio Faria de Oliveira	 <mfo@igalia.com>
Cc: seanjc@google.com, pbonzini@redhat.com, tglx@kernel.org,
	mingo@redhat.com, 	bp@alien8.de, dave.hansen@linux.intel.com,
	x86@kernel.org, hpa@zytor.com, 	kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org, 	sashiko-reviews@lists.linux.dev,
	stollmc@amazon.com
Subject: Re: [PATCH v2 20/20] KVM: x86: Use gfn_to_pfn_cache for record_steal_time
Date: Mon, 20 Jul 2026 18:05:16 +0100	[thread overview]
Message-ID: <68c461ea922df8878a1cfa8a914906372a012e30.camel@infradead.org> (raw)
In-Reply-To: <3291d47ea5fdd6ee2f284cadb518473130954cfc.camel@infradead.org>

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

On Tue, 2026-06-02 at 13:29 +0100, David Woodhouse wrote:
> 
> > [Severity: High]
> > Can this cause an ABBA deadlock in the scheduler on PREEMPT_RT?
> > 
> > kvm_steal_time_set_preempted() is called during a vCPU context switch
> > via kvm_sched_out(), which is a preempt notifier hook. This runs with
> > the local CPUs runqueue lock (rq->lock) held.
> > 
> > While the code correctly uses a trylock to avoid sleeping when acquiring
> > the lock, the CLASS macro destructor will implicitly call read_unlock()
> > at the end of the function. On PREEMPT_RT kernels, unlocking an rt_rwlock
> > can wake up a waiting writer, such as a concurrent kvm_gpc_refresh().
> 
> This one is more fun, and the problem already exists on RT for the Xen
> runstate update so it's not even really new with this patch.
> 
> I think the gpc lock needs to be a raw_rwlock_t, so that it remains a
> true spinning lock even on PREEMPT_RT. The writer side
> (kvm_gpc_refresh) only holds the lock briefly to swap in the new
> pfn/khva after doing the heavyweight work, so it should be fine as a
> raw lock.

Alternatively, since *most* uses of GPC are per-vCPU, a spinlock might
suffice. The exception is the Xen shared_info page, which is accessed
by all vCPUs.

We probably *could* turn that into a GPC per vCPU all pointing at the
same GFN, I suppose... but as someone pointed out fairly recently,
rwlocks don't scale that well as all the readers contend on the same
cache line anyway, so a spinlock might not turn out to be that much
worse even for the shared_info page.

Or maybe we should do a KVM_GPC_LOCK along the lines of KVM_MMU_LOCK,
which selects between rwlock_t and spinlock_t based on PREEMPT_RT?

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

  parent reply	other threads:[~2026-07-20 17:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260530061932.7849D1F00893@smtp.kernel.org>
2026-06-02 12:29 ` David Woodhouse
2026-06-09  0:45   ` Sean Christopherson
2026-08-05 21:51     ` David Woodhouse
2026-07-20 17:05   ` David Woodhouse [this message]
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: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=68c461ea922df8878a1cfa8a914906372a012e30.camel@infradead.org \
    --to=dwmw2@infradead.org \
    --cc=bigeasy@linutronix.de \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mfo@igalia.com \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=sashiko-bot@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=seanjc@google.com \
    --cc=stollmc@amazon.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

all inboxes | Powered by JetHome®