qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH for-4.2] xics/kvm: Convert assert() to error_setg()
@ 2019-07-03 17:50 Greg Kurz
  2019-07-03 23:30 ` no-reply
  2019-07-04  0:23 ` David Gibson
  0 siblings, 2 replies; 6+ messages in thread
From: Greg Kurz @ 2019-07-03 17:50 UTC (permalink / raw)
  To: David Gibson, Cédric Le Goater; +Cc: qemu-ppc, qemu-devel

ics_set_kvm_state_one() is called either during reset, in which case
both 'saved priority' and 'current priority' are equal to 0xff, or
during migration. In the latter case, 'saved priority' may differ
from 'current priority' only if the interrupt had been masked with
the ibm,int-off RTAS call. Instead of aborting QEMU, print out an
error and exit.

Based-on: <156217454083.559957.7359208229523652842.stgit@bahia.lan>
Signed-off-by: Greg Kurz <groug@kaod.org>
---

This isn't a bugfix, hence targetting 4.2, but it depends on an actual
fix for 4.1, as mentionned in the Based-on tag.
---
 hw/intc/xics_kvm.c |   17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/hw/intc/xics_kvm.c b/hw/intc/xics_kvm.c
index 2df1f3e92c7e..f8758b928250 100644
--- a/hw/intc/xics_kvm.c
+++ b/hw/intc/xics_kvm.c
@@ -255,8 +255,21 @@ int ics_set_kvm_state_one(ICSState *ics, int srcno, Error **errp)
     state = irq->server;
     state |= (uint64_t)(irq->saved_priority & KVM_XICS_PRIORITY_MASK)
         << KVM_XICS_PRIORITY_SHIFT;
-    if (irq->priority != irq->saved_priority) {
-        assert(irq->priority == 0xff);
+
+    /*
+     * An interrupt can be masked either because the ICS is resetting, in
+     * which case we expect 'current priority' and 'saved priority' to be
+     * equal to 0xff, or because the guest has called the ibm,int-off RTAS
+     * call, in which case we we have recorded the priority the interrupt
+     * had before it was masked in 'saved priority'. If the interrupt isn't
+     * masked, 'saved priority' and 'current priority' are equal (see
+     * ics_get_kvm_state()). Make sure we restore a sane state, otherwise
+     * fail migration.
+     */
+    if (irq->priority != irq->saved_priority && irq->priority != 0xff) {
+        error_setg(errp, "Corrupted state detected for interrupt source %d",
+                   srcno);
+        return -EINVAL;
     }
 
     if (irq->priority == 0xff) {



^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-07-05 13:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-03 17:50 [Qemu-devel] [PATCH for-4.2] xics/kvm: Convert assert() to error_setg() Greg Kurz
2019-07-03 23:30 ` no-reply
2019-07-04  0:23 ` David Gibson
2019-07-04  8:12   ` Greg Kurz
2019-07-05  4:56     ` David Gibson
2019-07-05 13:40       ` Greg Kurz

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).