mbox series

[v5.4,0/3] KVM: arm64: Fix AT instruction handling

Message ID 20200901094923.52486-1-andre.przywara@arm.com
Headers show
Series KVM: arm64: Fix AT instruction handling | expand

Message

Andre Przywara Sept. 1, 2020, 9:49 a.m. UTC
In some architectural corner cases, AT instructions can generate an
exception, which KVM is not really ready to handle properly.
Teach the code to handle this situation gracefully.

This is a backport of the respective upstream patches to v5.4(.61).
James prepared these already, but we were lacking the upstream commit ID.
I am sending this on his behalf, since he is off this week.

The last two of the patches were tagged Cc: stable already, but did
not apply cleanly, hence this specific backport.

Cheers,
Andre.

James Morse (3):
  KVM: arm64: Add kvm_extable for vaxoricism code
  KVM: arm64: Survive synchronous exceptions caused by AT instructions
  KVM: arm64: Set HCR_EL2.PTW to prevent AT taking synchronous exception

 arch/arm64/include/asm/kvm_arm.h |  3 +-
 arch/arm64/include/asm/kvm_asm.h | 43 +++++++++++++++++++++
 arch/arm64/kernel/vmlinux.lds.S  |  8 ++++
 arch/arm64/kvm/hyp/entry.S       | 15 +++++---
 arch/arm64/kvm/hyp/hyp-entry.S   | 65 ++++++++++++++++++++------------
 arch/arm64/kvm/hyp/switch.c      | 39 +++++++++++++++++--
 6 files changed, 138 insertions(+), 35 deletions(-)

Comments

Catalin Marinas Sept. 1, 2020, 11:16 a.m. UTC | #1
On Tue, Sep 01, 2020 at 12:12:57PM +0100, Marc Zyngier wrote:
> On 2020-09-01 10:49, Andre Przywara wrote:
> > From: James Morse <james.morse@arm.com>
> > 
> > commit e9ee186bb735bfc17fa81dbc9aebf268aee5b41e upstream.
> > 
> > KVM has a one instruction window where it will allow an SError exception
> > to be consumed by the hypervisor without treating it as a hypervisor
> > bug.
> > This is used to consume asynchronous external abort that were caused by
> > the guest.
> > 
> > As we are about to add another location that survives unexpected
> > exceptions,
> > generalise this code to make it behave like the host's extable.
> > 
> > KVM's version has to be mapped to EL2 to be accessible on nVHE systems.
> > 
> > The SError vaxorcism code is a one instruction window, so has two
> > entries
> > in the extable. Because the KVM code is copied for VHE and nVHE, we end
> > up
> > with four entries, half of which correspond with code that isn't mapped.
> > 
> > Cc: <stable@vger.kernel.org> # 5.4.x
> > Cc: Marc Zyngier <maz@kernel.org>
> > Signed-off-by: James Morse <james.morse@arm.com>
> > Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> 
> Can you make sure these patches do carry the sign-off chain as we have
> in mainline? In particular, this is missing:
> 
>     Reviewed-by: Marc Zyngier <maz@kernel.org>
>     Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
> 
> You can add your own SoB after this.

Good point. James prepared the backports before we merged the patches
into mainline.

BTW, I also corrected a subject typo: s/vaxoricism/vaxorcism/ (not that
this is a real word ;)).
Marc Zyngier Sept. 1, 2020, 11:54 a.m. UTC | #2
On 2020-09-01 12:17, André Przywara wrote:
> On 01/09/2020 12:12, Marc Zyngier wrote:
>> Hi Andre,
>> 
>> On 2020-09-01 10:49, Andre Przywara wrote:
>>> From: James Morse <james.morse@arm.com>
>>> 
>>> commit e9ee186bb735bfc17fa81dbc9aebf268aee5b41e upstream.
>>> 
>>> KVM has a one instruction window where it will allow an SError 
>>> exception
>>> to be consumed by the hypervisor without treating it as a hypervisor 
>>> bug.
>>> This is used to consume asynchronous external abort that were caused 
>>> by
>>> the guest.
>>> 
>>> As we are about to add another location that survives unexpected
>>> exceptions,
>>> generalise this code to make it behave like the host's extable.
>>> 
>>> KVM's version has to be mapped to EL2 to be accessible on nVHE 
>>> systems.
>>> 
>>> The SError vaxorcism code is a one instruction window, so has two 
>>> entries
>>> in the extable. Because the KVM code is copied for VHE and nVHE, we
>>> end up
>>> with four entries, half of which correspond with code that isn't 
>>> mapped.
>>> 
>>> Cc: <stable@vger.kernel.org> # 5.4.x
>>> Cc: Marc Zyngier <maz@kernel.org>
>>> Signed-off-by: James Morse <james.morse@arm.com>
>>> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
>> 
>> Can you make sure these patches do carry the sign-off chain as we have
>> in mainline? In particular, this is missing:
>> 
>>     Reviewed-by: Marc Zyngier <maz@kernel.org>
>>     Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
>> 
>> You can add your own SoB after this.
> 
> Sure, I wasn't sure your review would apply to this version as well. I
> took the backports from James' kernel.org repo, where they were lacking
> any of those tags.
> So shall I copy all the tags from mainline to all backport versions? Or
> only to those where the changes were trivial? The backports to before
> 5.3 seem to be more involved.

My understanding is that the commit log should stay as close to the
original as possible, with potential additions to indicate deviations
from the upstream patch.

I'm happy to *add* another RB once I have reviewed the patch, just
like I add another SoB when I backport a patch on which I signed-off
the first place.

Thanks,

         M.
Greg KH Sept. 1, 2020, 3:03 p.m. UTC | #3
On Tue, Sep 01, 2020 at 12:17:54PM +0100, André Przywara wrote:
> On 01/09/2020 12:12, Marc Zyngier wrote:
> > Hi Andre,
> > 
> > On 2020-09-01 10:49, Andre Przywara wrote:
> >> From: James Morse <james.morse@arm.com>
> >>
> >> commit e9ee186bb735bfc17fa81dbc9aebf268aee5b41e upstream.
> >>
> >> KVM has a one instruction window where it will allow an SError exception
> >> to be consumed by the hypervisor without treating it as a hypervisor bug.
> >> This is used to consume asynchronous external abort that were caused by
> >> the guest.
> >>
> >> As we are about to add another location that survives unexpected
> >> exceptions,
> >> generalise this code to make it behave like the host's extable.
> >>
> >> KVM's version has to be mapped to EL2 to be accessible on nVHE systems.
> >>
> >> The SError vaxorcism code is a one instruction window, so has two entries
> >> in the extable. Because the KVM code is copied for VHE and nVHE, we
> >> end up
> >> with four entries, half of which correspond with code that isn't mapped.
> >>
> >> Cc: <stable@vger.kernel.org> # 5.4.x
> >> Cc: Marc Zyngier <maz@kernel.org>
> >> Signed-off-by: James Morse <james.morse@arm.com>
> >> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> > 
> > Can you make sure these patches do carry the sign-off chain as we have
> > in mainline? In particular, this is missing:
> > 
> >     Reviewed-by: Marc Zyngier <maz@kernel.org>
> >     Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
> > 
> > You can add your own SoB after this.
> 
> Sure, I wasn't sure your review would apply to this version as well. I
> took the backports from James' kernel.org repo, where they were lacking
> any of those tags.
> So shall I copy all the tags from mainline to all backport versions?

Yes.

thanks,

greg k-h