Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Mark Rutland <mark.rutland@arm.com>
To: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: linux-kernel@vger.kernel.org, aleksandar.qemu.devel@gmail.com,
	alexandru.elisei@arm.com, anup.patel@wdc.com,
	aou@eecs.berkeley.edu, atish.patra@wdc.com,
	benh@kernel.crashing.org, bp@alien8.de, catalin.marinas@arm.com,
	chenhuacai@kernel.org, dave.hansen@linux.intel.com,
	david@redhat.com, frankja@linux.ibm.com, frederic@kernel.org,
	gor@linux.ibm.com, hca@linux.ibm.com, imbrenda@linux.ibm.com,
	james.morse@arm.com, jmattson@google.com, joro@8bytes.org,
	kvm@vger.kernel.org, maz@kernel.org, mingo@redhat.com,
	mpe@ellerman.id.au, nsaenzju@redhat.com, palmer@dabbelt.com,
	paulmck@kernel.org, paulus@samba.org, paul.walmsley@sifive.com,
	pbonzini@redhat.com, seanjc@google.com, suzuki.poulose@arm.com,
	tglx@linutronix.de, tsbogend@alpha.franken.de,
	vkuznets@redhat.com, wanpengli@tencent.com, will@kernel.org
Subject: Re: [PATCH 0/5] kvm: fix latent guest entry/exit bugs
Date: Fri, 14 Jan 2022 15:19:59 +0000	[thread overview]
Message-ID: <YeGUnwhbSvwJz5pD@FVFF77S0Q05N> (raw)
In-Reply-To: <b66c4856-7826-9cff-83f3-007d7ed5635c@linux.ibm.com>

On Fri, Jan 14, 2022 at 02:51:38PM +0100, Christian Borntraeger wrote:
> Am 14.01.22 um 14:32 schrieb Mark Rutland:
> > On Fri, Jan 14, 2022 at 01:29:46PM +0100, Christian Borntraeger wrote:
> > > Am 14.01.22 um 13:19 schrieb Mark Rutland:
> > > > On Thu, Jan 13, 2022 at 04:20:07PM +0100, Christian Borntraeger wrote:
> > > > > Am 11.01.22 um 16:35 schrieb Mark Rutland:

[...]

> > > > One major thing I wasn't sure about for s390 is the sequence:
> > > > 
> > > > 	guest_enter_irqoff();	// Enters an RCU EQS
> > > > 	...
> > > > 	local_irq_enable();
> > > > 	...
> > > > 	sie64a(...);
> > > > 	...
> > > > 	local_irq_disable();
> > > > 	...
> > > > 	guest_exit_irqoff();	// Exits an RCU EQS
> > > > 
> > > > ... since if an IRQ is taken between local_irq_{enable,disable}(), RCU won't be
> > > > watching, and I couldn't spot whether your regular IRQ entry logic would wake
> > > > RCU in this case, or whether there was something else I'm missing that saves
> > > > you here.
> > > > 
> > > > For other architectures, including x86 and arm64, we enter the guest with IRQs
> > > > masked and return from the guest with IRQs masked, and don't actually take IRQs
> > > > until we unmask them in the host, after the guest_exit_*() logic has woken RCU
> > > > and so on.
> > > > 
> > > > I wasn't able to find documentation on the semantics of SIE, so I couldn't spot
> > > > whether the local_irq_{enable,disable}() calls were necessary, or could be
> > > > removed.
> > > 
> > > We run the SIE instruction with interrupts enabled. SIE is interruptible.
> > > The disable/enable pairs are just because  guest_enter/exit_irqoff() require them.
> > 
> > What I was trying to figure out was when an interrupt is taken between
> > guest_enter_irqoff() and guest_exit_irqoff(), where is RCU woken? I couldn't
> > spot that in the s390 entry code (probably simply because I'm not familiar with
> > it), and so AFAICT that means IRQ code could run without RCU watching, which
> > would cause things to explode.
> > 
> > On other architectures that problem is avoided because IRQs asserted during the
> > guest cause a specific guest exit rather than a regular IRQ exception, and the
> > HW enables/disables IRQs when entering/exiting the guest, so the host can leave
> > IRQs masked across guest_enter_irqoff()..guest_exit_irqoff().
> > 
> > Am I right in understanding that SIE itself won't enable (host) interrupts
> > while running the guest, and so it *needs* to be run with interrupts already
> > enabled?
> 
> yes
> 
> > > One thing to be aware of: in our entry.S - after an interrupt - we leave SIE by
> > > setting the return address of the interrupt after the sie instruction so that we
> > > get back into this __vcpu_run loop to check for signals and so.
> > 
> > Just to check, that's after the IRQ handler runs, right?
> 
> and yes.

Thanks for confirming! 

IIUC as above, that means there's a latent RCU bug on s390, and to fix that
we'll need to add something to the IRQ entry logic to wake RCU for any IRQ
taken in the EQS between guest_enter_irqoff() and guest_exit_irqoff(), similar
to what is done for IRQs taken from an idle EQS.

I see s390 uses the common irqentry_{enter,exit}(), so perhaps we could extend
the logic there to check something in addition to is_idle_task()? e.g. add a
noinstr helper to check kvm_running_vcpu, Or add a thread flag that says we're
in this guest EQS.

I also think there is another issue here. When an IRQ is taken from SIE, will
user_mode(regs) always be false, or could it be true if the guest userspace is
running? If it can be true I think tha context tracking checks can complain,
and it *might* be possible to trigger a panic().

In irqentry_enter(), if user_mode(regs) == true, we call
irqentry_enter_from_user_mode -> __enter_from_user_mode(). There we check that
the context is CONTEXT_USER, but IIUC that will be CONTEXT_GUEST at this point.
We also call arch_check_user_regs(), and IIUC this might permit a malicious
guest to trigger a host panic by way of debug_user_asce(), but I may have
misunderstood and that might not be possible.

Thanks,
Mark.

  reply	other threads:[~2022-01-14 15:20 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-11 15:35 [PATCH 0/5] kvm: fix latent guest entry/exit bugs Mark Rutland
2022-01-11 15:35 ` [PATCH 1/5] kvm: add exit_to_guest_mode() and enter_from_guest_mode() Mark Rutland
2022-01-11 17:54   ` Marc Zyngier
2022-01-13 11:01     ` Mark Rutland
2022-01-13 11:55       ` Marc Zyngier
2022-01-13 13:01         ` Mark Rutland
2022-01-13 20:32   ` Sean Christopherson
2022-01-14 11:48     ` Mark Rutland
2022-01-14 16:11       ` Sean Christopherson
2022-01-18 13:01         ` Mark Rutland
2022-01-11 15:35 ` [PATCH 2/5] kvm/arm64: rework guest entry logic Mark Rutland
2022-01-11 17:55   ` Marc Zyngier
2022-01-13 11:17     ` Mark Rutland
2022-01-13 11:43       ` Marc Zyngier
2022-01-13 12:58         ` Mark Rutland
2022-01-11 15:35 ` [PATCH 3/5] kvm/mips: " Mark Rutland
2022-01-11 15:35 ` [PATCH 4/5] kvm/riscv: " Mark Rutland
2022-01-11 15:35 ` [PATCH 5/5] kvm/x86: " Mark Rutland
2022-01-13 20:50   ` Sean Christopherson
2022-01-14 12:05     ` Mark Rutland
2022-01-14 16:49       ` Sean Christopherson
2022-01-11 18:47 ` [PATCH 0/5] kvm: fix latent guest entry/exit bugs Palmer Dabbelt
2022-01-13 15:20 ` Christian Borntraeger
2022-01-14 12:19   ` Mark Rutland
2022-01-14 12:29     ` Christian Borntraeger
2022-01-14 13:32       ` Mark Rutland
2022-01-14 13:51         ` Christian Borntraeger
2022-01-14 15:19           ` Mark Rutland [this message]
2022-01-17 17:45             ` Paolo Bonzini
2022-01-18 12:02               ` Mark Rutland
2022-01-18 12:08                 ` Christian Borntraeger
2022-01-18 12:42                 ` Christian Borntraeger
2022-01-18 13:12                   ` Mark Rutland
2022-01-18 14:15                     ` Christian Borntraeger
2022-01-18 15:43                       ` Mark Rutland
2022-01-18 16:09                     ` Sven Schnelle
2022-01-18 17:50                       ` Mark Rutland
2022-01-18 18:12                         ` Mark Rutland
2022-01-19  6:41                         ` Sven Schnelle

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=YeGUnwhbSvwJz5pD@FVFF77S0Q05N \
    --to=mark.rutland@arm.com \
    --cc=aleksandar.qemu.devel@gmail.com \
    --cc=alexandru.elisei@arm.com \
    --cc=anup.patel@wdc.com \
    --cc=aou@eecs.berkeley.edu \
    --cc=atish.patra@wdc.com \
    --cc=benh@kernel.crashing.org \
    --cc=borntraeger@linux.ibm.com \
    --cc=bp@alien8.de \
    --cc=catalin.marinas@arm.com \
    --cc=chenhuacai@kernel.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=david@redhat.com \
    --cc=frankja@linux.ibm.com \
    --cc=frederic@kernel.org \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=james.morse@arm.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=mingo@redhat.com \
    --cc=mpe@ellerman.id.au \
    --cc=nsaenzju@redhat.com \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    --cc=paulmck@kernel.org \
    --cc=paulus@samba.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=suzuki.poulose@arm.com \
    --cc=tglx@linutronix.de \
    --cc=tsbogend@alpha.franken.de \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.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