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, David Hildenbrand <david@redhat.com>,
	Eric Farman <farman@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>
Subject: [PATCH 5.16 10/28] KVM: s390: Clarify SIGP orders versus STOP/RESTART
Date: Tue, 18 Jan 2022 17:06:05 +0100	[thread overview]
Message-ID: <20220118160452.750105506@linuxfoundation.org> (raw)
In-Reply-To: <20220118160452.384322748@linuxfoundation.org>

From: Eric Farman <farman@linux.ibm.com>

commit 812de04661c4daa7ac385c0dfd62594540538034 upstream.

With KVM_CAP_S390_USER_SIGP, there are only five Signal Processor
orders (CONDITIONAL EMERGENCY SIGNAL, EMERGENCY SIGNAL, EXTERNAL CALL,
SENSE, and SENSE RUNNING STATUS) which are intended for frequent use
and thus are processed in-kernel. The remainder are sent to userspace
with the KVM_CAP_S390_USER_SIGP capability. Of those, three orders
(RESTART, STOP, and STOP AND STORE STATUS) have the potential to
inject work back into the kernel, and thus are asynchronous.

Let's look for those pending IRQs when processing one of the in-kernel
SIGP orders, and return BUSY (CC2) if one is in process. This is in
agreement with the Principles of Operation, which states that only one
order can be "active" on a CPU at a time.

Cc: stable@vger.kernel.org
Suggested-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Eric Farman <farman@linux.ibm.com>
Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com>
Acked-by: David Hildenbrand <david@redhat.com>
Link: https://lore.kernel.org/r/20211213210550.856213-2-farman@linux.ibm.com
[borntraeger@linux.ibm.com: add stable tag]
Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 arch/s390/kvm/interrupt.c |    7 +++++++
 arch/s390/kvm/kvm-s390.c  |    9 +++++++--
 arch/s390/kvm/kvm-s390.h  |    1 +
 arch/s390/kvm/sigp.c      |   28 ++++++++++++++++++++++++++++
 4 files changed, 43 insertions(+), 2 deletions(-)

--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -2115,6 +2115,13 @@ int kvm_s390_is_stop_irq_pending(struct
 	return test_bit(IRQ_PEND_SIGP_STOP, &li->pending_irqs);
 }
 
+int kvm_s390_is_restart_irq_pending(struct kvm_vcpu *vcpu)
+{
+	struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
+
+	return test_bit(IRQ_PEND_RESTART, &li->pending_irqs);
+}
+
 void kvm_s390_clear_stop_irq(struct kvm_vcpu *vcpu)
 {
 	struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -4645,10 +4645,15 @@ int kvm_s390_vcpu_stop(struct kvm_vcpu *
 		}
 	}
 
-	/* SIGP STOP and SIGP STOP AND STORE STATUS has been fully processed */
+	/*
+	 * Set the VCPU to STOPPED and THEN clear the interrupt flag,
+	 * now that the SIGP STOP and SIGP STOP AND STORE STATUS orders
+	 * have been fully processed. This will ensure that the VCPU
+	 * is kept BUSY if another VCPU is inquiring with SIGP SENSE.
+	 */
+	kvm_s390_set_cpuflags(vcpu, CPUSTAT_STOPPED);
 	kvm_s390_clear_stop_irq(vcpu);
 
-	kvm_s390_set_cpuflags(vcpu, CPUSTAT_STOPPED);
 	__disable_ibs_on_vcpu(vcpu);
 
 	for (i = 0; i < online_vcpus; i++) {
--- a/arch/s390/kvm/kvm-s390.h
+++ b/arch/s390/kvm/kvm-s390.h
@@ -427,6 +427,7 @@ void kvm_s390_destroy_adapters(struct kv
 int kvm_s390_ext_call_pending(struct kvm_vcpu *vcpu);
 extern struct kvm_device_ops kvm_flic_ops;
 int kvm_s390_is_stop_irq_pending(struct kvm_vcpu *vcpu);
+int kvm_s390_is_restart_irq_pending(struct kvm_vcpu *vcpu);
 void kvm_s390_clear_stop_irq(struct kvm_vcpu *vcpu);
 int kvm_s390_set_irq_state(struct kvm_vcpu *vcpu,
 			   void __user *buf, int len);
--- a/arch/s390/kvm/sigp.c
+++ b/arch/s390/kvm/sigp.c
@@ -276,6 +276,34 @@ static int handle_sigp_dst(struct kvm_vc
 	if (!dst_vcpu)
 		return SIGP_CC_NOT_OPERATIONAL;
 
+	/*
+	 * SIGP RESTART, SIGP STOP, and SIGP STOP AND STORE STATUS orders
+	 * are processed asynchronously. Until the affected VCPU finishes
+	 * its work and calls back into KVM to clear the (RESTART or STOP)
+	 * interrupt, we need to return any new non-reset orders "busy".
+	 *
+	 * This is important because a single VCPU could issue:
+	 *  1) SIGP STOP $DESTINATION
+	 *  2) SIGP SENSE $DESTINATION
+	 *
+	 * If the SIGP SENSE would not be rejected as "busy", it could
+	 * return an incorrect answer as to whether the VCPU is STOPPED
+	 * or OPERATING.
+	 */
+	if (order_code != SIGP_INITIAL_CPU_RESET &&
+	    order_code != SIGP_CPU_RESET) {
+		/*
+		 * Lockless check. Both SIGP STOP and SIGP (RE)START
+		 * properly synchronize everything while processing
+		 * their orders, while the guest cannot observe a
+		 * difference when issuing other orders from two
+		 * different VCPUs.
+		 */
+		if (kvm_s390_is_stop_irq_pending(dst_vcpu) ||
+		    kvm_s390_is_restart_irq_pending(dst_vcpu))
+			return SIGP_CC_BUSY;
+	}
+
 	switch (order_code) {
 	case SIGP_SENSE:
 		vcpu->stat.instruction_sigp_sense++;



  parent reply	other threads:[~2022-01-18 16:12 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-18 16:05 [PATCH 5.16 00/28] 5.16.2-rc1 review Greg Kroah-Hartman
2022-01-18 16:05 ` [PATCH 5.16 01/28] devtmpfs regression fix: reconfigure on each mount Greg Kroah-Hartman
2022-01-18 16:05 ` [PATCH 5.16 02/28] drm/amd/display: explicitly set is_dsc_supported to false before use Greg Kroah-Hartman
2022-01-18 16:05 ` [PATCH 5.16 03/28] orangefs: Fix the size of a memory allocation in orangefs_bufmap_alloc() Greg Kroah-Hartman
2022-01-18 16:05 ` [PATCH 5.16 04/28] remoteproc: qcom: pil_info: Dont memcpy_toio more than is provided Greg Kroah-Hartman
2022-01-18 16:06 ` [PATCH 5.16 05/28] vfs: fs_context: fix up param length parsing in legacy_parse_param Greg Kroah-Hartman
2022-01-18 16:06 ` [PATCH 5.16 06/28] perf: Protect perf_guest_cbs with RCU Greg Kroah-Hartman
2022-01-18 16:06 ` [PATCH 5.16 07/28] KVM: x86: Register perf callbacks after calling vendors hardware_setup() Greg Kroah-Hartman
2022-01-18 16:06 ` [PATCH 5.16 08/28] KVM: x86: Register Processor Trace interrupt hook iff PT enabled in guest Greg Kroah-Hartman
2022-01-18 16:06 ` [PATCH 5.16 09/28] KVM: x86: dont print when fail to read/write pv eoi memory Greg Kroah-Hartman
2022-01-18 16:06 ` Greg Kroah-Hartman [this message]
2022-01-18 16:06 ` [PATCH 5.16 11/28] remoteproc: qcom: pas: Add missing power-domain "mxc" for CDSP Greg Kroah-Hartman
2022-01-18 16:06 ` [PATCH 5.16 12/28] NFSD: Fix zero-length NFSv3 WRITEs Greg Kroah-Hartman
2022-01-18 16:06 ` [PATCH 5.16 13/28] 9p: only copy valid iattrs in 9P2000.L setattr implementation Greg Kroah-Hartman
2022-01-18 16:06 ` [PATCH 5.16 14/28] 9p: fix enodata when reading growing file Greg Kroah-Hartman
2022-01-18 16:06 ` [PATCH 5.16 15/28] video: vga16fb: Only probe for EGA and VGA 16 color graphic cards Greg Kroah-Hartman
2022-01-18 16:06 ` [PATCH 5.16 16/28] media: uvcvideo: fix division by zero at stream start Greg Kroah-Hartman
2022-01-18 16:06 ` [PATCH 5.16 17/28] rtlwifi: rtl8192cu: Fix WARNING when calling local_irq_restore() with interrupts enabled Greg Kroah-Hartman
2022-01-18 16:06 ` [PATCH 5.16 18/28] firmware: qemu_fw_cfg: fix sysfs information leak Greg Kroah-Hartman
2022-01-18 16:06 ` [PATCH 5.16 19/28] firmware: qemu_fw_cfg: fix NULL-pointer deref on duplicate entries Greg Kroah-Hartman
2022-01-18 16:06 ` [PATCH 5.16 20/28] firmware: qemu_fw_cfg: fix kobject leak in probe error path Greg Kroah-Hartman
2022-01-18 16:06 ` [PATCH 5.16 21/28] perf annotate: Avoid TUI crash when navigating in the annotation of recursive functions Greg Kroah-Hartman
2022-01-18 16:06 ` [PATCH 5.16 22/28] ALSA: hda/realtek: Add speaker fixup for some Yoga 15ITL5 devices Greg Kroah-Hartman
2022-01-18 16:06 ` [PATCH 5.16 23/28] ALSA: hda/realtek: Use ALC285_FIXUP_HP_GPIO_LED on another HP laptop Greg Kroah-Hartman
2022-01-18 16:06 ` [PATCH 5.16 24/28] ALSA: hda/realtek - Fix silent output on Gigabyte X570 Aorus Master after reboot from Windows Greg Kroah-Hartman
2022-01-18 16:06 ` [PATCH 5.16 25/28] ALSA: hda: ALC287: Add Lenovo IdeaPad Slim 9i 14ITL5 speaker quirk Greg Kroah-Hartman
2022-01-18 16:06 ` [PATCH 5.16 26/28] ALSA: hda/tegra: Fix Tegra194 HDA reset failure Greg Kroah-Hartman
2022-01-18 16:06 ` [PATCH 5.16 27/28] ALSA: hda/realtek: Add quirk for Legion Y9000X 2020 Greg Kroah-Hartman
2022-01-18 16:06 ` [PATCH 5.16 28/28] ALSA: hda/realtek: Re-order quirk entries for Lenovo Greg Kroah-Hartman
2022-01-18 17:38 ` [PATCH 5.16 00/28] 5.16.2-rc1 review Jeffrin Jose T
2022-01-18 19:54 ` Florian Fainelli
2022-01-18 20:49 ` Jon Hunter
2022-01-18 22:23 ` Shuah Khan
2022-01-19  1:24 ` Zan Aziz
2022-01-19  7:30 ` Naresh Kamboju
2022-01-19  7:53   ` Linus Torvalds
2022-01-19 15:55     ` Guenter Roeck
2022-01-19 17:14     ` Anders Roxell
2022-01-19 11:08 ` Ron Economos
2022-01-19 12:20 ` Rudi Heitbaum
2022-01-19 12:41 ` Naresh Kamboju
2022-01-20  0:44 ` Guenter Roeck

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=20220118160452.750105506@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=borntraeger@linux.ibm.com \
    --cc=david@redhat.com \
    --cc=farman@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.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 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).