All of lore.kernel.org
 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, Paul Mackerras <paulus@ozlabs.org>
Subject: [PATCH 4.11 20/58] KVM: PPC: Book3S HV: Cope with host using large decrementer mode
Date: Tue, 27 Jun 2017 16:12:23 +0200	[thread overview]
Message-ID: <20170627141114.224566979@linuxfoundation.org> (raw)
In-Reply-To: <20170627141113.402913097@linuxfoundation.org>

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

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

From: Paul Mackerras <paulus@ozlabs.org>

commit 2f2724630f7a8d582470f03ee56b96746767d270 upstream.

POWER9 introduces a new mode for the decrementer register, called
large decrementer mode, in which the decrementer counter is 56 bits
wide rather than 32, and reads are sign-extended rather than
zero-extended.  For the decrementer, this new mode is optional and
controlled by a bit in the LPCR.  The hypervisor decrementer (HDEC)
is 56 bits wide on POWER9 and has no mode control.

Since KVM code reads and writes the decrementer and hypervisor
decrementer registers in a few places, it needs to be aware of the
need to treat the decrementer value as a 64-bit quantity, and only do
a 32-bit sign extension when large decrementer mode is not in effect.
Similarly, the HDEC should always be treated as a 64-bit quantity on
POWER9.  We define a new EXTEND_HDEC macro to encapsulate the feature
test for POWER9 and the sign extension.

To enable the sign extension to be removed in large decrementer mode,
we test the LPCR_LD bit in the host LPCR image stored in the struct
kvm for the guest.  If is set then large decrementer mode is enabled
and the sign extension should be skipped.

This is partly based on an earlier patch by Oliver O'Halloran.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 arch/powerpc/kvm/book3s_hv_interrupts.S |   12 +++++++++++-
 arch/powerpc/kvm/book3s_hv_rmhandlers.S |   23 +++++++++++++++++------
 2 files changed, 28 insertions(+), 7 deletions(-)

--- a/arch/powerpc/kvm/book3s_hv_interrupts.S
+++ b/arch/powerpc/kvm/book3s_hv_interrupts.S
@@ -121,10 +121,20 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
 	 * Put whatever is in the decrementer into the
 	 * hypervisor decrementer.
 	 */
+BEGIN_FTR_SECTION
+	ld	r5, HSTATE_KVM_VCORE(r13)
+	ld	r6, VCORE_KVM(r5)
+	ld	r9, KVM_HOST_LPCR(r6)
+	andis.	r9, r9, LPCR_LD@h
+END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
 	mfspr	r8,SPRN_DEC
 	mftb	r7
-	mtspr	SPRN_HDEC,r8
+BEGIN_FTR_SECTION
+	/* On POWER9, don't sign-extend if host LPCR[LD] bit is set */
+	bne	32f
+END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
 	extsw	r8,r8
+32:	mtspr	SPRN_HDEC,r8
 	add	r8,r8,r7
 	std	r8,HSTATE_DECEXP(r13)
 
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -31,6 +31,12 @@
 #include <asm/tm.h>
 #include <asm/opal.h>
 
+/* Sign-extend HDEC if not on POWER9 */
+#define EXTEND_HDEC(reg)			\
+BEGIN_FTR_SECTION;				\
+	extsw	reg, reg;			\
+END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_300)
+
 #define VCPU_GPRS_TM(reg) (((reg) * ULONG_SIZE) + VCPU_GPR_TM)
 
 /* Values in HSTATE_NAPPING(r13) */
@@ -213,6 +219,8 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
 kvmppc_primary_no_guest:
 	/* We handle this much like a ceded vcpu */
 	/* put the HDEC into the DEC, since HDEC interrupts don't wake us */
+	/* HDEC may be larger than DEC for arch >= v3.00, but since the */
+	/* HDEC value came from DEC in the first place, it will fit */
 	mfspr	r3, SPRN_HDEC
 	mtspr	SPRN_DEC, r3
 	/*
@@ -294,8 +302,9 @@ kvm_novcpu_wakeup:
 
 	/* See if our timeslice has expired (HDEC is negative) */
 	mfspr	r0, SPRN_HDEC
+	EXTEND_HDEC(r0)
 	li	r12, BOOK3S_INTERRUPT_HV_DECREMENTER
-	cmpwi	r0, 0
+	cmpdi	r0, 0
 	blt	kvm_novcpu_exit
 
 	/* Got an IPI but other vcpus aren't yet exiting, must be a latecomer */
@@ -389,8 +398,8 @@ kvm_secondary_got_guest:
 	lbz	r4, HSTATE_PTID(r13)
 	cmpwi	r4, 0
 	bne	63f
-	lis	r6, 0x7fff
-	ori	r6, r6, 0xffff
+	LOAD_REG_ADDR(r6, decrementer_max)
+	ld	r6, 0(r6)
 	mtspr	SPRN_HDEC, r6
 	/* and set per-LPAR registers, if doing dynamic micro-threading */
 	ld	r6, HSTATE_SPLIT_MODE(r13)
@@ -967,7 +976,8 @@ ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_3
 
 	/* Check if HDEC expires soon */
 	mfspr	r3, SPRN_HDEC
-	cmpwi	r3, 512		/* 1 microsecond */
+	EXTEND_HDEC(r3)
+	cmpdi	r3, 512		/* 1 microsecond */
 	blt	hdec_soon
 
 deliver_guest_interrupt:
@@ -2308,12 +2318,13 @@ END_FTR_SECTION_IFSET(CPU_FTR_TM)
 	mfspr	r3, SPRN_DEC
 	mfspr	r4, SPRN_HDEC
 	mftb	r5
-	cmpw	r3, r4
+	extsw	r3, r3
+	EXTEND_HDEC(r4)
+	cmpd	r3, r4
 	ble	67f
 	mtspr	SPRN_DEC, r4
 67:
 	/* save expiry time of guest decrementer */
-	extsw	r3, r3
 	add	r3, r3, r5
 	ld	r4, HSTATE_KVM_VCPU(r13)
 	ld	r5, HSTATE_KVM_VCORE(r13)

  parent reply	other threads:[~2017-06-27 14:17 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-27 14:12 [PATCH 4.11 00/58] 4.11.8-stable review Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 01/58] clk: sunxi-ng: a31: Correct lcd1-ch1 clock register offset Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 02/58] clk: sunxi-ng: v3s: Fix usb otg device reset bit Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 03/58] clk: sunxi-ng: sun5i: Fix ahb_bist_clk definition Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 05/58] xen-blkback: dont leak stack data via response ring Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 06/58] ALSA: firewire-lib: Fix stall of process context at packet error Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 07/58] ALSA: pcm: Dont treat NULL chmap as a fatal error Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 08/58] ALSA: hda - Add Coffelake PCI ID Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 09/58] ALSA: hda - Apply quirks to Broxton-T, too Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 10/58] fs/exec.c: account for argv/envp pointers Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 11/58] powerpc/perf: Fix oops when kthread execs user process Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 12/58] autofs: sanity check status reported with AUTOFS_DEV_IOCTL_FAIL Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 13/58] fs/dax.c: fix inefficiency in dax_writeback_mapping_range() Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 14/58] lib/cmdline.c: fix get_options() overflow while parsing ranges Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 15/58] perf/x86/intel: Add 1G DTLB load/store miss support for SKL Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 19/58] KVM: s390: gaccess: fix real-space designation asce handling for gmap shadows Greg Kroah-Hartman
2017-06-27 14:12 ` Greg Kroah-Hartman [this message]
2017-06-27 14:12 ` [PATCH 4.11 21/58] KVM: PPC: Book3S HV: Preserve userspace HTM state properly Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 22/58] KVM: PPC: Book3S HV: Ignore timebase offset on POWER9 DD1 Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 23/58] KVM: PPC: Book3S HV: Context-switch EBB registers properly Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 24/58] KVM: PPC: Book3S HV: Restore critical SPRs to host values on guest exit Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 25/58] KVM: PPC: Book3S HV: Save/restore host values of debug registers Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 26/58] CIFS: Improve readdir verbosity Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 27/58] CIFS: Fix some return values in case of error in crypt_message Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 28/58] cxgb4: notify uP to route ctrlq compl to rdma rspq Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 29/58] HID: Add quirk for Dell PIXART OEM mouse Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 30/58] random: silence compiler warnings and fix race Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 31/58] signal: Only reschedule timers on signals timers have sent Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 32/58] powerpc/kprobes: Pause function_graph tracing during jprobes handling Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 33/58] powerpc/64s: Handle data breakpoints in Radix mode Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 34/58] Input: i8042 - add Fujitsu Lifebook AH544 to notimeout list Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 35/58] brcmfmac: add parameter to pass error code in firmware callback Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 36/58] brcmfmac: use firmware callback upon failure to load Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 37/58] brcmfmac: unbind all devices upon failure in firmware callback Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 38/58] time: Fix clock->read(clock) race around clocksource changes Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 39/58] time: Fix CLOCK_MONOTONIC_RAW sub-nanosecond accounting Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 40/58] arm64/vdso: Fix nsec handling for CLOCK_MONOTONIC_RAW Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 41/58] target: Fix kref->refcount underflow in transport_cmd_finish_abort Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 42/58] iscsi-target: Fix delayed logout processing greater than SECONDS_FOR_LOGOUT_COMP Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 43/58] iscsi-target: Reject immediate data underflow larger than SCSI transfer length Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 44/58] drm/radeon: add a PX quirk for another K53TK variant Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 45/58] drm/radeon: add a quirk for Toshiba Satellite L20-183 Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 48/58] drm/amdgpu: add Polaris12 DID Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 49/58] ACPI / scan: Apply default enumeration to devices with ACPI drivers Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 50/58] ACPI / scan: Fix enumeration for special SPI and I2C devices Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 52/58] drm: Fix GETCONNECTOR regression Greg Kroah-Hartman
2017-06-27 14:12   ` Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 53/58] usb: gadget: f_fs: avoid out of bounds access on comp_desc Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 54/58] spi: double time out tolerance Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 55/58] net: phy: fix marvell phy status reading Greg Kroah-Hartman
2017-06-27 14:12 ` [PATCH 4.11 56/58] netfilter: xtables: zero padding in data_to_user Greg Kroah-Hartman
2017-06-27 14:13 ` [PATCH 4.11 57/58] netfilter: xtables: fix build failure from COMPAT_XT_ALIGN outside CONFIG_COMPAT Greg Kroah-Hartman
2017-06-27 14:13 ` [PATCH 4.11 58/58] brcmfmac: fix uninitialized warning in brcmf_usb_probe_phase2() Greg Kroah-Hartman
2017-06-27 19:04 ` [PATCH 4.11 00/58] 4.11.8-stable review Guenter Roeck
2017-06-28 12:03   ` Greg Kroah-Hartman
2017-06-28 13:53 ` Shuah Khan
2017-06-28 15:22   ` 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=20170627141114.224566979@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulus@ozlabs.org \
    --cc=stable@vger.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 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.