From: Sean Christopherson <seanjc@google.com>
To: David Woodhouse <dwmw2@infradead.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>, kvm@vger.kernel.org, mhal@rbox.co
Subject: Re: [PATCH 2/4] KVM: x86/xen: Compatibility fixes for shared runstate area
Date: Wed, 23 Nov 2022 19:32:11 +0000 [thread overview]
Message-ID: <Y351Oz8mrGcaAUMg@google.com> (raw)
In-Reply-To: <176c0c26fda9481a4e04c99289bb240a9b3c1ccd.camel@infradead.org>
On Wed, Nov 23, 2022, David Woodhouse wrote:
> On Wed, 2022-11-23 at 18:21 +0000, Sean Christopherson wrote:
> > On Sat, Nov 19, 2022, David Woodhouse wrote:
> ...
> /* When invoked from kvm_sched_out() we cannot sleep */
> if (atomic)
> return;
> ...
> > > + /*
> > > + * Use kvm_gpc_activate() here because if the runstate
> > > + * area was configured in 32-bit mode and only extends
> > > + * to the second page now because the guest changed to
> > > + * 64-bit mode, the second GPC won't have been set up.
> > > + */
> > > + if (kvm_gpc_activate(v->kvm, gpc2, NULL, KVM_HOST_USES_PFN,
> > > + gpc1->gpa + user_len1, user_len2))
> >
> > I believe kvm_gpc_activate() needs to be converted from write_lock_irq() to
> > write_lock_irqsave() for this to be safe.
>
> Hm, not sure I concur. You're only permitted to call kvm_gpc_activate()
> in a context where you can sleep. Interrupts had better not be disabled
> already, and it had better not need write_lock_irqsave().
>
> In this particular context, we do drop all locks before calling
> kvm_gpc_activate(), and we don't call it at all in the scheduling-out
> case when we aren't permitted to sleep.
Oh, duh, there's an "if (atomic)" check right above this.
> > Side topic, why do all of these flows disable IRQs?
>
> The gpc->lock is permitted to be taken in IRQ context by the users of
> the GPC. For example we do this for the shared_info and vcpu_info when
> passing interrupts directly through to the guest via
> kvm_arch_set_irq_inatomic() → kvm_xen_set_evtchn_fast().
>
> The code path is fairly convoluted but I do believe we get there
> directly from the VFIO IRQ handler, via the custom wakeup handler on
> the irqfd's waitqueue (irqfd_wakeup).
Yeah, I remember finding that flow.
> Now, perhaps a GPC user which knows that *it* is not going to use its
> GPC from IRQ context, could refrain from bothering to disable
> interrupts when taking its own gpc->lock. And that's probably true for
> the runstate area.
This is effectively what I was asking about.
> The generic GPC code still needs to disable interrupts when taking a
> gpc->lock though, unless we want to add yet another flag to control
> that behaviour.
Right. Might be worth adding a comment at some point to call out that disabling
IRQs may not be strictly required for all users, but it's done for simplicity.
Ah, if/when we add kvm_gpc_lock(), that would be the perfect place to document
the behavior.
Thanks!
next prev parent reply other threads:[~2022-11-23 19:32 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-19 9:46 [PATCH 1/4] MAINTAINERS: Add KVM x86/xen maintainer list David Woodhouse
2022-11-19 9:46 ` [PATCH 2/4] KVM: x86/xen: Compatibility fixes for shared runstate area David Woodhouse
2022-11-19 11:38 ` Durrant, Paul
2022-11-19 11:46 ` David Woodhouse
2022-11-22 18:39 ` Sean Christopherson
2022-11-22 23:04 ` David Woodhouse
2022-11-23 17:17 ` Sean Christopherson
2022-11-23 17:58 ` David Woodhouse
2022-11-23 18:16 ` Sean Christopherson
2022-11-23 18:48 ` David Woodhouse
2022-11-22 23:46 ` Michal Luczaj
2022-11-23 0:03 ` David Woodhouse
2022-11-23 18:21 ` Sean Christopherson
2022-11-23 19:22 ` David Woodhouse
2022-11-23 19:32 ` Sean Christopherson [this message]
2022-11-23 20:07 ` David Woodhouse
2022-11-23 20:26 ` Sean Christopherson
2022-11-19 9:46 ` [PATCH 3/4] KVM: Update gfn_to_pfn_cache khva when it moves within the same page David Woodhouse
2022-11-19 11:40 ` Durrant, Paul
2022-11-22 16:23 ` Sean Christopherson
2022-11-22 16:49 ` Paul Durrant
2022-11-22 17:02 ` David Woodhouse
2022-11-22 19:09 ` Sean Christopherson
2022-11-22 23:13 ` David Woodhouse
2022-11-24 0:31 ` Paolo Bonzini
2022-11-24 0:45 ` David Woodhouse
2022-11-24 0:54 ` David Woodhouse
2022-11-24 1:11 ` Paolo Bonzini
2022-11-24 10:41 ` David Woodhouse
2022-11-24 11:30 ` David Woodhouse
2022-11-19 9:46 ` [PATCH 4/4] KVM: x86/xen: Add runstate tests for 32-bit mode and crossing page boundary David Woodhouse
2022-11-19 11:42 ` Durrant, Paul
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=Y351Oz8mrGcaAUMg@google.com \
--to=seanjc@google.com \
--cc=dwmw2@infradead.org \
--cc=kvm@vger.kernel.org \
--cc=mhal@rbox.co \
--cc=pbonzini@redhat.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.