stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Vikram Sethi <vikrams@codeaurora.org>,
	Marc Zyngier <marc.zyngier@arm.com>
Subject: [PATCH 4.1 34/56] arm: KVM: force execution of HCPTR access on VM exit
Date: Wed,  8 Jul 2015 00:35:23 -0700	[thread overview]
Message-ID: <20150708073239.706089539@linuxfoundation.org> (raw)
In-Reply-To: <20150708073237.780280770@linuxfoundation.org>

4.1-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Marc Zyngier <marc.zyngier@arm.com>

commit 85e84ba31039595995dae80b277378213602891b upstream.

On VM entry, we disable access to the VFP registers in order to
perform a lazy save/restore of these registers.

On VM exit, we restore access, test if we did enable them before,
and save/restore the guest/host registers if necessary. In this
sequence, the FPEXC register is always accessed, irrespective
of the trapping configuration.

If the guest didn't touch the VFP registers, then the HCPTR access
has now enabled such access, but we're missing a barrier to ensure
architectural execution of the new HCPTR configuration. If the HCPTR
access has been delayed/reordered, the subsequent access to FPEXC
will cause a trap, which we aren't prepared to handle at all.

The same condition exists when trapping to enable VFP for the guest.

The fix is to introduce a barrier after enabling VFP access. In the
vmexit case, it can be relaxed to only takes place if the guest hasn't
accessed its view of the VFP registers, making the access to FPEXC safe.

The set_hcptr macro is modified to deal with both vmenter/vmexit and
vmtrap operations, and now takes an optional label that is branched to
when the guest hasn't touched the VFP registers.

Reported-by: Vikram Sethi <vikrams@codeaurora.org>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 arch/arm/kvm/interrupts.S      |   10 ++++------
 arch/arm/kvm/interrupts_head.S |   20 ++++++++++++++++++--
 2 files changed, 22 insertions(+), 8 deletions(-)

--- a/arch/arm/kvm/interrupts.S
+++ b/arch/arm/kvm/interrupts.S
@@ -170,13 +170,9 @@ __kvm_vcpu_return:
 	@ Don't trap coprocessor accesses for host kernel
 	set_hstr vmexit
 	set_hdcr vmexit
-	set_hcptr vmexit, (HCPTR_TTA | HCPTR_TCP(10) | HCPTR_TCP(11))
+	set_hcptr vmexit, (HCPTR_TTA | HCPTR_TCP(10) | HCPTR_TCP(11)), after_vfp_restore
 
 #ifdef CONFIG_VFPv3
-	@ Save floating point registers we if let guest use them.
-	tst	r2, #(HCPTR_TCP(10) | HCPTR_TCP(11))
-	bne	after_vfp_restore
-
 	@ Switch VFP/NEON hardware state to the host's
 	add	r7, vcpu, #VCPU_VFP_GUEST
 	store_vfp_state r7
@@ -188,6 +184,8 @@ after_vfp_restore:
 	@ Restore FPEXC_EN which we clobbered on entry
 	pop	{r2}
 	VFPFMXR FPEXC, r2
+#else
+after_vfp_restore:
 #endif
 
 	@ Reset Hyp-role
@@ -483,7 +481,7 @@ switch_to_guest_vfp:
 	push	{r3-r7}
 
 	@ NEON/VFP used.  Turn on VFP access.
-	set_hcptr vmexit, (HCPTR_TCP(10) | HCPTR_TCP(11))
+	set_hcptr vmtrap, (HCPTR_TCP(10) | HCPTR_TCP(11))
 
 	@ Switch VFP/NEON hardware state to the guest's
 	add	r7, r0, #VCPU_VFP_HOST
--- a/arch/arm/kvm/interrupts_head.S
+++ b/arch/arm/kvm/interrupts_head.S
@@ -591,8 +591,13 @@ ARM_BE8(rev	r6, r6  )
 .endm
 
 /* Configures the HCPTR (Hyp Coprocessor Trap Register) on entry/return
- * (hardware reset value is 0). Keep previous value in r2. */
-.macro set_hcptr operation, mask
+ * (hardware reset value is 0). Keep previous value in r2.
+ * An ISB is emited on vmexit/vmtrap, but executed on vmexit only if
+ * VFP wasn't already enabled (always executed on vmtrap).
+ * If a label is specified with vmexit, it is branched to if VFP wasn't
+ * enabled.
+ */
+.macro set_hcptr operation, mask, label = none
 	mrc	p15, 4, r2, c1, c1, 2
 	ldr	r3, =\mask
 	.if \operation == vmentry
@@ -601,6 +606,17 @@ ARM_BE8(rev	r6, r6  )
 	bic	r3, r2, r3		@ Don't trap defined coproc-accesses
 	.endif
 	mcr	p15, 4, r3, c1, c1, 2
+	.if \operation != vmentry
+	.if \operation == vmexit
+	tst	r2, #(HCPTR_TCP(10) | HCPTR_TCP(11))
+	beq	1f
+	.endif
+	isb
+	.if \label != none
+	b	\label
+	.endif
+1:
+	.endif
 .endm
 
 /* Configures the HDCR (Hyp Debug Configuration Register) on entry/return



  parent reply	other threads:[~2015-07-08  7:37 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-08  7:34 [PATCH 4.1 00/56] 4.1.2-stable review Greg Kroah-Hartman
2015-07-08  7:34 ` [PATCH 4.1 01/56] ARM: dts: sunxi: Adjust touchscreen compatible for sun5i and later Greg Kroah-Hartman
2015-07-08  7:34 ` [PATCH 4.1 02/56] ARM: clk-imx6q: refine satas parent Greg Kroah-Hartman
2015-07-08  7:34 ` [PATCH 4.1 03/56] KVM: nSVM: Check for NRIPS support before updating control field Greg Kroah-Hartman
2015-07-08  7:34 ` [PATCH 4.1 04/56] can: fix loss of CAN frames in raw_rcv Greg Kroah-Hartman
2015-07-08  7:34 ` [PATCH 4.1 05/56] sctp: fix ASCONF list handling Greg Kroah-Hartman
2015-07-08  7:34 ` [PATCH 4.1 06/56] bridge: fix br_stp_set_bridge_priority race conditions Greg Kroah-Hartman
2015-07-08  7:34 ` [PATCH 4.1 07/56] packet: read num_members once in packet_rcv_fanout() Greg Kroah-Hartman
2015-07-08  7:34 ` [PATCH 4.1 08/56] packet: avoid out of bounds read in round robin fanout Greg Kroah-Hartman
2015-07-08  7:34 ` [PATCH 4.1 09/56] neigh: do not modify unlinked entries Greg Kroah-Hartman
2015-07-08  7:34 ` [PATCH 4.1 10/56] mac80211: fix locking in update_vlan_tailroom_need_count() Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 11/56] mvneta: add forgotten initialization of autonegotiation bits Greg Kroah-Hartman
2015-07-08 17:10   ` Stas Sergeev
2015-07-08 17:36     ` Greg Kroah-Hartman
2015-07-08 18:36       ` Stas Sergeev
2015-07-08 19:36         ` Arnaud Ebalard
2015-07-08 20:15           ` Stas Sergeev
2015-07-08 21:31         ` Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 12/56] tcp: Do not call tcp_fastopen_reset_cipher from interrupt context Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 13/56] xen-netback: fix a BUG() during initialization Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 14/56] ip: report the original address of ICMP messages Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 15/56] net/mlx4_en: Release TX QP when destroying TX ring Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 16/56] net/mlx4_en: Wake TX queues only when theres enough room Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 17/56] net/mlx4_en: Fix wrong csum complete report when rxvlan offload is disabled Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 18/56] mlx4: Disable HA for SRIOV PF RoCE devices Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 19/56] net: phy: fix phy link up when limiting speed via device tree Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 20/56] bnx2x: fix lockdep splat Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 21/56] sctp: Fix race between OOTB responce and route removal Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 22/56] amd-xgbe: Add the __GFP_NOWARN flag to Rx buffer allocation Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 23/56] net: mvneta: introduce compatible string "marvell, armada-xp-neta" Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 24/56] ARM: mvebu: update Ethernet compatible string for Armada XP Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 25/56] net: mvneta: disable IP checksum with jumbo frames for Armada 370 Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 26/56] usb: gadget: f_fs: add extra check before unregister_gadget_item Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 27/56] crypto: talitos - avoid memleak in talitos_alg_alloc() Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 28/56] Revert "crypto: talitos - convert to use be16_add_cpu()" Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 29/56] iommu/arm-smmu: Fix broken ATOS check Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 30/56] iommu/amd: Handle large pages correctly in free_pagetable Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 31/56] mmc: sdhci: fix low memory corruption Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 32/56] intel_pstate: set BYT MSR with wrmsrl_on_cpu() Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 33/56] selinux: fix setting of security labels on NFS Greg Kroah-Hartman
2015-07-08  7:35 ` Greg Kroah-Hartman [this message]
2015-07-08  7:35 ` [PATCH 4.1 35/56] ARM: kvm: psci: fix handling of unimplemented functions Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 36/56] ARM: tegra20: Store CPU "resettable" status in IRAM Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 37/56] ARM: mvebu: fix suspend to RAM on big-endian configurations Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 38/56] tick/idle/powerpc: Do not register idle states with CPUIDLE_FLAG_TIMER_STOP set in periodic mode Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 39/56] powerpc/perf: Fix book3s kernel to userspace backtraces Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 40/56] x86/PCI: Use host bridge _CRS info on systems with >32 bit addressing Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 41/56] x86/PCI: Use host bridge _CRS info on Foxconn K8M890-8237A Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 42/56] KVM: mips: use id_to_memslot correctly Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 43/56] MIPS: Fix KVM guest fixmap address Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 44/56] KVM: s390: fix external call injection without sigp interpretation Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 45/56] KVM: s390: clear floating interrupt bitmap and parameters Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 46/56] s390/bpf: Fix backward jumps Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 47/56] s390/kdump: fix REGSET_VX_LOW vector register ELF notes Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 48/56] KVM: s390: virtio-ccw: dont overwrite config space values Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 49/56] KVM: arm/arm64: vgic: Avoid injecting reserved IRQ numbers Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 52/56] fs: Fix S_NOSEC handling Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 53/56] fs/ufs: revert "ufs: fix deadlocks introduced by sb mutex merge" Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 54/56] fs/ufs: restore s_lock mutex Greg Kroah-Hartman
2015-07-08 16:28   ` Fabian Frederick
2015-07-08 17:32     ` Greg Kroah-Hartman
2015-07-08 21:32       ` Greg Kroah-Hartman
2015-07-09 14:37         ` Luis Henriques
2015-07-10 17:38           ` Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 55/56] vfs: Remove incorrect debugging WARN in prepend_path Greg Kroah-Hartman
2015-07-08  7:35 ` [PATCH 4.1 56/56] vfs: Ignore unlocked mounts in fs_fully_visible Greg Kroah-Hartman
2015-07-08 14:11 ` [PATCH 4.1 00/56] 4.1.2-stable review Guenter Roeck
2015-07-10 17:30   ` Greg Kroah-Hartman
2015-07-08 16:34 ` Shuah Khan
2015-07-10 17:30   ` Greg Kroah-Hartman
2015-07-09  4:57 ` Sudip Mukherjee
2015-07-10 17:31   ` Greg Kroah-Hartman
2015-07-10 16:08 ` Kevin Hilman
2015-07-10 17:33   ` Greg Kroah-Hartman

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=20150708073239.706089539@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marc.zyngier@arm.com \
    --cc=stable@vger.kernel.org \
    --cc=vikrams@codeaurora.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;
as well as URLs for NNTP newsgroup(s).