Skip to contentSkip to conversation

hmp command IO- and Local APIC dump state

PATCH Superseded Denis V. Lunev 3 participants 13 messages Sep 21, 2015 – Sep 22, 2015

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover hmp command IO- and Local APIC dump state

Added the hmp command to query IO- and Local APIC registers state, it can be very useful to identify problems related to the emulation devices.

(qemu) info lapic
dumping local APIC state for CPU 0

LVT0     0x00010700 active-hi edge  masked                      ExtINT (vec 0)
LVT1     0x00000400 active-hi edge                              NMI
LVTPC    0x00010000 active-hi edge  masked                      Fixed  (vec 0)
LVTERR   0x000000fe active-hi edge                              Fixed  (vec 254)
LVTTHMR  0x00010000 active-hi edge  masked                      Fixed  (vec 0)
LVTT     0x000000ef active-hi edge                 one-shot     Fixed  (vec 239)
Timer    DCR=0x3 (divide by 16) initial_count = 62278
SPIV     0x000001ff APIC enabled, focus=off, spurious vec 255
ICR      0x000000fd physical edge de-assert no
ICR2     0x00000001 cpu 1 (X2APIC ID)
ESR      0x00000000

ISR
IRR 239

APR 0x00 TPR 0x00 DFR 0x0f LDR 0x00 PPR 0x00

(qemu) info ioapic
ioapic id=0x00 sel=0x2e (redir[15])

pin 0  0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 1  0x0000000000000031 dest=0 vec=49  active-hi edge         fixed  physical
pin 2  0x0000000000000030 dest=0 vec=48  active-hi edge         fixed  physical
pin 3  0x0000000000000033 dest=0 vec=51  active-hi edge         fixed  physical
pin 4  0x0000000000010034 dest=0 vec=52  active-hi edge  masked fixed  physical
pin 5  0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 6  0x0000000000000036 dest=0 vec=54  active-hi edge         fixed  physical
pin 7  0x0000000000000037 dest=0 vec=55  active-hi edge         fixed  physical
pin 8  0x0000000000000038 dest=0 vec=56  active-hi edge         fixed  physical
pin 9  0x0000000000018041 dest=0 vec=65  active-hi level masked fixed  physical
pin 10 0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 11 0x0300000000008081 dest=3 vec=129 active-hi level        fixed  physical
pin 12 0x000000000000003c dest=0 vec=60  active-hi edge         fixed  physical
pin 13 0x000000000000003d dest=0 vec=61  active-hi edge         fixed  physical
pin 14 0x000000000000003e dest=0 vec=62  active-hi edge         fixed  physical
pin 15 0x000000000000003f dest=0 vec=63  active-hi edge         fixed  physical
pin 16 0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 17 0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 18 0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 19 0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 20 0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 21 0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 22 0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 23 0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical

IRR (none)

Changes from v1:
- implementation of hmp commands moved to the target-i386 part
- the cpu_dump_apic_local_state interface moved to the target-i386 part

Changes from v2:
- lapic and ioapic format dump are fixed for more human readable view

Pavel Butsykin (9):
apic_internal.h: make some apic_get_* functions externally visible apic_internal.h: rename ESR_ILLEGAL_ADDRESS to
APIC_ESR_ILLEGAL_ADDRESS
apic_internal.h: added more constants
apic_internal.h: fix formatting and drop unused consts
monitor: make monitor_fprintf and mon_get_cpu externally visible
hmp: added local apic dump state
ioapic_internal.h: added more constants
hmp: added io apic dump state
hmp: implemented io apic dump state for TCG

 disas.c                           |  10 --
 hmp-commands-info.hx              |  32 +++++++
 hw/i386/kvm/ioapic.c              |  10 ++
 hw/intc/apic.c                    |  22 +----
 hw/intc/ioapic.c                  |  12 +++
 hw/intc/ioapic_common.c           |  37 ++++++++
 include/hw/i386/apic_internal.h   |  96 ++++++++++++++++---
 include/hw/i386/ioapic_internal.h |   7 ++
 include/hw/i386/pc.h              |   5 +
 include/monitor/hmp-target.h      |   3 +
 include/monitor/monitor.h         |   1 +
 monitor.c                         |   5 +-
 target-i386/cpu.h                 |   3 +
 target-i386/helper.c              | 190 ++++++++++++++++++++++++++++++++++++++
 target-i386/monitor.c             |  17 ++++
 15 files changed, 407 insertions(+), 43 deletions(-)
Signature · 1 line
2.1.4
#1 lore raw

PATCH v3 1/9 apic_internal.h: make some apic_get_* functions externally visible

From: Pavel Butsykin <[email protected]>

Move apic_get_bit(), apic_set_bit() to apic_internal.h, make the apic_get_ppr symbol external. It's necessary to work with isr, tmr, irr and ppr outside hw/intc/apic.c

---
 hw/intc/apic.c                  | 18 +-----------------
 include/hw/i386/apic_internal.h | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 17 deletions(-)
hw/intc/apic.c +1 -17
index 77b639c..52ac8b2 100644
@@ -51,14 +51,6 @@ static int apic_ffs_bit(uint32_t value)
     return ctz32(value);
 }
 
-static inline void apic_set_bit(uint32_t *tab, int index)
-{
-    int i, mask;
-    i = index >> 5;
-    mask = 1 << (index & 0x1f);
-    tab[i] |= mask;
-}
-
 static inline void apic_reset_bit(uint32_t *tab, int index)
 {
     int i, mask;
@@ -67,14 +59,6 @@ static inline void apic_reset_bit(uint32_t *tab, int index)
     tab[i] &= ~mask;
 }
 
-static inline int apic_get_bit(uint32_t *tab, int index)
-{
-    int i, mask;
-    i = index >> 5;
-    mask = 1 << (index & 0x1f);
-    return !!(tab[i] & mask);
-}
-
 /* return -1 if no bit is set */
 static int get_highest_priority_int(uint32_t *tab)
 {
@@ -318,7 +302,7 @@ static uint8_t apic_get_tpr(APICCommonState *s)
     return s->tpr >> 4;
 }
 
-static int apic_get_ppr(APICCommonState *s)
+int apic_get_ppr(APICCommonState *s)
 {
     int tpr, isrv, ppr;
 
include/hw/i386/apic_internal.h +18 -0
index 26632ac..5a213bc 100644
@@ -147,4 +147,22 @@ void apic_enable_vapic(DeviceState *d, hwaddr paddr);
 void vapic_report_tpr_access(DeviceState *dev, CPUState *cpu, target_ulong ip,
                              TPRAccess access);
 
+int apic_get_ppr(APICCommonState *s);
+
+static inline void apic_set_bit(uint32_t *tab, int index)
+{
+    int i, mask;
+    i = index >> 5;
+    mask = 1 << (index & 0x1f);
+    tab[i] |= mask;
+}
+
+static inline int apic_get_bit(uint32_t *tab, int index)
+{
+    int i, mask;
+    i = index >> 5;
+    mask = 1 << (index & 0x1f);
+    return !!(tab[i] & mask);
+}
+
 #endif /* !QEMU_APIC_INTERNAL_H */
Signature · 1 line
2.1.4
#2 lore raw

PATCH v3 2/9 apic_internal.h: rename ESR_ILLEGAL_ADDRESS to APIC_ESR_ILLEGAL_ADDRESS

In reply to Denis V. Lunev

From: Pavel Butsykin <[email protected]>

Added prefix APIC_ for determining the constant of a particular subsystem, improve the overall readability and match other constant names.

---
 hw/intc/apic.c                  | 4 ++--
 include/hw/i386/apic_internal.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
hw/intc/apic.c +2 -2
index 52ac8b2..0a840b8 100644
@@ -723,7 +723,7 @@ static uint32_t apic_mem_readl(void *opaque, hwaddr addr)
         val = s->divide_conf;
         break;
     default:
-        s->esr |= ESR_ILLEGAL_ADDRESS;
+        s->esr |= APIC_ESR_ILLEGAL_ADDRESS;
         val = 0;
         break;
     }
@@ -836,7 +836,7 @@ static void apic_mem_writel(void *opaque, hwaddr addr, uint32_t val)
         }
         break;
     default:
-        s->esr |= ESR_ILLEGAL_ADDRESS;
+        s->esr |= APIC_ESR_ILLEGAL_ADDRESS;
         break;
     }
 }
include/hw/i386/apic_internal.h +1 -1
index 5a213bc..188131c 100644
@@ -57,7 +57,7 @@
 #define APIC_INPUT_POLARITY             (1<<13)
 #define APIC_SEND_PENDING               (1<<12)
 
-#define ESR_ILLEGAL_ADDRESS (1 << 7)
+#define APIC_ESR_ILLEGAL_ADDRESS        (1 << 7)
 
 #define APIC_SV_DIRECTED_IO             (1<<12)
 #define APIC_SV_ENABLE                  (1<<8)
Signature · 1 line
2.1.4
#3 lore raw

PATCH v3 3/9 apic_internal.h: added more constants

In reply to Denis V. Lunev

From: Pavel Butsykin <[email protected]>

These constants are needed for optimal access to bit fields local apic registers without magic numbers.

---
 include/hw/i386/apic_internal.h | 58 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)
include/hw/i386/apic_internal.h +58 -0
index 188131c..a1db16e 100644
@@ -50,14 +50,72 @@
 #define APIC_TRIGGER_EDGE               0
 #define APIC_TRIGGER_LEVEL              1
 
+#define APIC_VECTOR_MASK                0xff
+#define APIC_DCR_MASK                   0xf
+
+#define APIC_LVT_TIMER_SHIFT            17
+#define APIC_LVT_MASKED_SHIFT           16
+#define APIC_LVT_LEVEL_TRIGGER_SHIFT    15
+#define APIC_LVT_REMOTE_IRR_SHIFT       14
+#define APIC_LVT_INT_POLARITY_SHIFT     13
+#define APIC_LVT_DELIV_STS_SHIFT        12
+#define APIC_LVT_DELIV_MOD_SHIFT        8
+
+#define APIC_LVT_TIMER_TSCDEADLINE      (2 << APIC_LVT_TIMER_SHIFT)
 #define APIC_LVT_TIMER_PERIODIC         (1<<17)
 #define APIC_LVT_MASKED                 (1<<16)
 #define APIC_LVT_LEVEL_TRIGGER          (1<<15)
 #define APIC_LVT_REMOTE_IRR             (1<<14)
 #define APIC_INPUT_POLARITY             (1<<13)
 #define APIC_SEND_PENDING               (1<<12)
+#define APIC_LVT_INT_POLARITY           (1 << APIC_LVT_INT_POLARITY_SHIFT)
+#define APIC_LVT_DELIV_STS              (1 << APIC_LVT_DELIV_STS_SHIFT)
+#define APIC_LVT_DELIV_MOD              (7 << APIC_LVT_DELIV_MOD_SHIFT)
+
+#define APIC_ESR_ILL_ADDRESS_SHIFT      7
+#define APIC_ESR_RECV_ILL_VECT_SHIFT    6
+#define APIC_ESR_SEND_ILL_VECT_SHIFT    5
+#define APIC_ESR_RECV_ACCEPT_SHIFT      3
+#define APIC_ESR_SEND_ACCEPT_SHIFT      2
+#define APIC_ESR_RECV_CHECK_SUM_SHIFT   1
 
 #define APIC_ESR_ILLEGAL_ADDRESS        (1 << 7)
+#define APIC_ESR_RECV_ILLEGAL_VECT      (1 << APIC_ESR_RECV_ILL_VECT_SHIFT)
+#define APIC_ESR_SEND_ILLEGAL_VECT      (1 << APIC_ESR_SEND_ILL_VECT_SHIFT)
+#define APIC_ESR_RECV_ACCEPT            (1 << APIC_ESR_RECV_ACCEPT_SHIFT)
+#define APIC_ESR_SEND_ACCEPT            (1 << APIC_ESR_SEND_ACCEPT_SHIFT)
+#define APIC_ESR_RECV_CHECK_SUM         (1 << APIC_ESR_RECV_CHECK_SUM_SHIFT)
+#define APIC_ESR_SEND_CHECK_SUM         1
+
+#define APIC_ICR_DEST_SHIFT             24
+#define APIC_ICR_DEST_SHORT_SHIFT       18
+#define APIC_ICR_TRIGGER_MOD_SHIFT      15
+#define APIC_ICR_LEVEL_SHIFT            14
+#define APIC_ICR_DELIV_STS_SHIFT        12
+#define APIC_ICR_DEST_MOD_SHIFT         11
+#define APIC_ICR_DELIV_MOD_SHIFT        8
+
+#define APIC_ICR_DEST_SHORT             (3 << APIC_ICR_DEST_SHORT_SHIFT)
+#define APIC_ICR_TRIGGER_MOD            (1 << APIC_ICR_TRIGGER_MOD_SHIFT)
+#define APIC_ICR_LEVEL                  (1 << APIC_ICR_LEVEL_SHIFT)
+#define APIC_ICR_DELIV_STS              (1 << APIC_ICR_DELIV_STS_SHIFT)
+#define APIC_ICR_DEST_MOD               (1 << APIC_ICR_DEST_MOD_SHIFT)
+#define APIC_ICR_DELIV_MOD              (7 << APIC_ICR_DELIV_MOD_SHIFT)
+
+#define APIC_PR_CLASS_SHIFT             4
+#define APIC_PR_SUB_CLASS               0xf
+
+#define APIC_LOGDEST_XAPIC_SHIFT        4
+#define APIC_LOGDEST_XAPIC_ID           0xf
+
+#define APIC_LOGDEST_X2APIC_SHIFT       16
+#define APIC_LOGDEST_X2APIC_ID          0xffff
+
+#define APIC_SPURIO_FOCUS_SHIFT         9
+#define APIC_SPURIO_ENABLED_SHIFT       8
+
+#define APIC_SPURIO_FOCUS               (1 << APIC_SPURIO_FOCUS_SHIFT)
+#define APIC_SPURIO_ENABLED             (1 << APIC_SPURIO_ENABLED_SHIFT)
 
 #define APIC_SV_DIRECTED_IO             (1<<12)
 #define APIC_SV_ENABLE                  (1<<8)
Signature · 1 line
2.1.4
#4 lore raw

PATCH v3 4/9 apic_internal.h: fix formatting and drop unused consts

In reply to Denis V. Lunev

From: Pavel Butsykin <[email protected]>

Fix formatting of local apic definitions and drop unused constant APIC_INPUT_POLARITY, APIC_SEND_PENDING. Magic numbers in shifts are replaced with constants defined just above.

---
 include/hw/i386/apic_internal.h | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
include/hw/i386/apic_internal.h +7 -9
index a1db16e..7813396 100644
@@ -62,12 +62,10 @@
 #define APIC_LVT_DELIV_MOD_SHIFT        8
 
 #define APIC_LVT_TIMER_TSCDEADLINE      (2 << APIC_LVT_TIMER_SHIFT)
-#define APIC_LVT_TIMER_PERIODIC         (1<<17)
-#define APIC_LVT_MASKED                 (1<<16)
-#define APIC_LVT_LEVEL_TRIGGER          (1<<15)
-#define APIC_LVT_REMOTE_IRR             (1<<14)
-#define APIC_INPUT_POLARITY             (1<<13)
-#define APIC_SEND_PENDING               (1<<12)
+#define APIC_LVT_TIMER_PERIODIC         (1 << APIC_LVT_TIMER_SHIFT)
+#define APIC_LVT_MASKED                 (1 << APIC_LVT_MASKED_SHIFT)
+#define APIC_LVT_LEVEL_TRIGGER          (1 << APIC_LVT_LEVEL_TRIGGER_SHIFT)
+#define APIC_LVT_REMOTE_IRR             (1 << APIC_LVT_REMOTE_IRR_SHIFT)
 #define APIC_LVT_INT_POLARITY           (1 << APIC_LVT_INT_POLARITY_SHIFT)
 #define APIC_LVT_DELIV_STS              (1 << APIC_LVT_DELIV_STS_SHIFT)
 #define APIC_LVT_DELIV_MOD              (7 << APIC_LVT_DELIV_MOD_SHIFT)
@@ -79,7 +77,7 @@
 #define APIC_ESR_SEND_ACCEPT_SHIFT      2
 #define APIC_ESR_RECV_CHECK_SUM_SHIFT   1
 
-#define APIC_ESR_ILLEGAL_ADDRESS        (1 << 7)
+#define APIC_ESR_ILLEGAL_ADDRESS        (1 << APIC_ESR_ILL_ADDRESS_SHIFT)
 #define APIC_ESR_RECV_ILLEGAL_VECT      (1 << APIC_ESR_RECV_ILL_VECT_SHIFT)
 #define APIC_ESR_SEND_ILLEGAL_VECT      (1 << APIC_ESR_SEND_ILL_VECT_SHIFT)
 #define APIC_ESR_RECV_ACCEPT            (1 << APIC_ESR_RECV_ACCEPT_SHIFT)
@@ -117,8 +115,8 @@
 #define APIC_SPURIO_FOCUS               (1 << APIC_SPURIO_FOCUS_SHIFT)
 #define APIC_SPURIO_ENABLED             (1 << APIC_SPURIO_ENABLED_SHIFT)
 
-#define APIC_SV_DIRECTED_IO             (1<<12)
-#define APIC_SV_ENABLE                  (1<<8)
+#define APIC_SV_DIRECTED_IO             (1 << 12)
+#define APIC_SV_ENABLE                  (1 << 8)
 
 #define VAPIC_ENABLE_BIT                0
 #define VAPIC_ENABLE_MASK               (1 << VAPIC_ENABLE_BIT)
Signature · 1 line
2.1.4
#5 lore raw

PATCH v3 5/9 monitor: make monitor_fprintf and mon_get_cpu externally visible

In reply to Denis V. Lunev

From: Pavel Butsykin <[email protected]>

monitor_fprintf and mon_get_cpu will be used in the target-specific monitor, so it is advisable to make it external.

---
 disas.c                      | 10 ----------
 include/monitor/hmp-target.h |  1 +
 include/monitor/monitor.h    |  1 +
 monitor.c                    |  5 ++---
 4 files changed, 4 insertions(+), 13 deletions(-)
disas.c +0 -10
index 0ae70c2..45878fa 100644
@@ -392,16 +392,6 @@ monitor_read_memory (bfd_vma memaddr, bfd_byte *myaddr, int length,
     return 0;
 }
 
-static int GCC_FMT_ATTR(2, 3)
-monitor_fprintf(FILE *stream, const char *fmt, ...)
-{
-    va_list ap;
-    va_start(ap, fmt);
-    monitor_vprintf((Monitor *)stream, fmt, ap);
-    va_end(ap);
-    return 0;
-}
-
 /* Disassembler for the monitor.
    See target_disas for a description of flags. */
 void monitor_disas(Monitor *mon, CPUState *cpu,
include/monitor/hmp-target.h +1 -0
index 611541d..c64f523 100644
@@ -37,6 +37,7 @@ struct MonitorDef {
 const MonitorDef *target_monitor_defs(void);
 
 CPUArchState *mon_get_cpu_env(void);
+CPUState *mon_get_cpu(void);
 
 void hmp_info_mem(Monitor *mon, const QDict *qdict);
 void hmp_info_tlb(Monitor *mon, const QDict *qdict);
include/monitor/monitor.h +1 -0
index 9aff47e..f95a384 100644
@@ -34,6 +34,7 @@ int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp);
 void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
     GCC_FMT_ATTR(2, 0);
 void monitor_printf(Monitor *mon, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
+int monitor_fprintf(FILE *stream, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
 void monitor_flush(Monitor *mon);
 int monitor_set_cpu(int cpu_index);
 int monitor_get_cpu_index(void);
monitor.c +2 -3
index 1f43263..d303579 100644
@@ -371,8 +371,7 @@ void monitor_printf(Monitor *mon, const char *fmt, ...)
     va_end(ap);
 }
 
-static int GCC_FMT_ATTR(2, 3) monitor_fprintf(FILE *stream,
-                                              const char *fmt, ...)
+int monitor_fprintf(FILE *stream, const char *fmt, ...)
 {
     va_list ap;
     va_start(ap, fmt);
@@ -941,7 +940,7 @@ int monitor_set_cpu(int cpu_index)
     return 0;
 }
 
-static CPUState *mon_get_cpu(void)
+CPUState *mon_get_cpu(void)
 {
     if (!cur_mon->mon_cpu) {
         monitor_set_cpu(0);
Signature · 1 line
2.1.4
#6 lore raw

PATCH v3 6/9 hmp: added local apic dump state

In reply to Denis V. Lunev

From: Pavel Butsykin <[email protected]>

Added the hmp command to query local apic registers state, may be usefull after guest crashes to understand IRQ routing in guest.

(qemu) info lapic
dumping local APIC state for CPU 0

LVT0     0x00010700 active-hi edge  masked                      ExtINT (vec 0)
LVT1     0x00000400 active-hi edge                              NMI
LVTPC    0x00010000 active-hi edge  masked                      Fixed  (vec 0)
LVTERR   0x000000fe active-hi edge                              Fixed  (vec 254)
LVTTHMR  0x00010000 active-hi edge  masked                      Fixed  (vec 0)
LVTT     0x000000ef active-hi edge                 one-shot     Fixed  (vec 239)
Timer    DCR=0x3 (divide by 16) initial_count = 62278
SPIV     0x000001ff APIC enabled, focus=off, spurious vec 255
ICR      0x000000fd physical edge de-assert no
ICR2     0x00000001 cpu 1 (X2APIC ID)
ESR      0x00000000

ISR
IRR 239

APR 0x00 TPR 0x00 DFR 0x0f LDR 0x00 PPR 0x00

---
 hmp-commands-info.hx         |  16 ++++
 include/monitor/hmp-target.h |   1 +
 target-i386/cpu.h            |   3 +
 target-i386/helper.c         | 190 +++++++++++++++++++++++++++++++++++++++++++
 target-i386/monitor.c        |   6 ++
 5 files changed, 216 insertions(+)
hmp-commands-info.hx +16 -0
index 9f5a158..dba7839 100644
@@ -112,6 +112,22 @@ STEXI
 Show the cpu registers.
 ETEXI
 
+#if defined(TARGET_I386)
+    {
+        .name       = "lapic",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show local apic state",
+        .mhandler.cmd = hmp_info_local_apic,
+    },
+#endif
+
+STEXI
+@item info lapic
+@findex lapic
+Show local APIC state
+ETEXI
+
     {
         .name       = "cpus",
         .args_type  = "",
include/monitor/hmp-target.h +1 -0
index c64f523..be50577 100644
@@ -42,5 +42,6 @@ CPUState *mon_get_cpu(void);
 void hmp_info_mem(Monitor *mon, const QDict *qdict);
 void hmp_info_tlb(Monitor *mon, const QDict *qdict);
 void hmp_mce(Monitor *mon, const QDict *qdict);
+void hmp_info_local_apic(Monitor *mon, const QDict *qdict);
 
 #endif /* MONITOR_COMMON */
target-i386/cpu.h +3 -0
index 5231e8c..527eb99 100644
@@ -1353,4 +1353,7 @@ void enable_compat_apic_id_mode(void);
 #define APIC_DEFAULT_ADDRESS 0xfee00000
 #define APIC_SPACE_SIZE      0x100000
 
+void x86_cpu_dump_local_apic_state(CPUState *cs, FILE *f,
+                                   fprintf_function cpu_fprintf, int flags);
+
 #endif /* CPU_I386_H */
target-i386/helper.c +190 -0

202 lines not on this page · raw message

target-i386/monitor.c +6 -0
index 6ac8636..9479a77 100644
@@ -492,3 +492,9 @@ const MonitorDef *target_monitor_defs(void)
 {
     return monitor_defs;
 }
+
+void hmp_info_local_apic(Monitor *mon, const QDict *qdict)
+{
+    x86_cpu_dump_local_apic_state(mon_get_cpu(), (FILE *)mon, monitor_fprintf,
+                                  CPU_DUMP_FPU);
+}
Signature · 1 line
2.1.4
#7 lore raw

PATCH v3 7/9 ioapic_internal.h: added more constants

In reply to Denis V. Lunev

From: Pavel Butsykin <[email protected]>

Added the masks for easy access to fields of the redirection table entry

---
 include/hw/i386/ioapic_internal.h | 5 +++++
 1 file changed, 5 insertions(+)
include/hw/i386/ioapic_internal.h +5 -0
index 3be3352..4f7764e 100644
@@ -40,7 +40,12 @@
 #define IOAPIC_LVT_DELIV_MODE_SHIFT     8
 
 #define IOAPIC_LVT_MASKED               (1 << IOAPIC_LVT_MASKED_SHIFT)
+#define IOAPIC_LVT_TRIGGER_MODE         (1 << IOAPIC_LVT_TRIGGER_MODE_SHIFT)
 #define IOAPIC_LVT_REMOTE_IRR           (1 << IOAPIC_LVT_REMOTE_IRR_SHIFT)
+#define IOAPIC_LVT_POLARITY             (1 << IOAPIC_LVT_POLARITY_SHIFT)
+#define IOAPIC_LVT_DELIV_STATUS         (1 << IOAPIC_LVT_DELIV_STATUS_SHIFT)
+#define IOAPIC_LVT_DEST_MODE            (1 << IOAPIC_LVT_DEST_MODE_SHIFT)
+#define IOAPIC_LVT_DELIV_MODE           (7 << IOAPIC_LVT_DELIV_MODE_SHIFT)
 
 #define IOAPIC_TRIGGER_EDGE             0
 #define IOAPIC_TRIGGER_LEVEL            1
Signature · 1 line
2.1.4
#8 lore raw

PATCH v3 8/9 hmp: added io apic dump state

In reply to Denis V. Lunev

From: Pavel Butsykin <[email protected]>

Added the hmp command to query io apic state, may be usefull after guest crashes to understand IRQ routing in guest.

Implementation is only for kvm here. The dump will look like (qemu) info ioapic
ioapic id=0x00 sel=0x2e (redir[15])

pin 0  0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 1  0x0000000000000031 dest=0 vec=49  active-hi edge         fixed  physical

...
pin 23 0x0000000000010000 dest=0 vec=0 active-hi edge masked fixed physical
IRR (none)

---
 hmp-commands-info.hx              | 16 ++++++++++++++++
 hw/i386/kvm/ioapic.c              | 10 ++++++++++
 hw/intc/ioapic_common.c           | 37 +++++++++++++++++++++++++++++++++++++
 include/hw/i386/ioapic_internal.h |  2 ++
 include/hw/i386/pc.h              |  4 ++++
 include/monitor/hmp-target.h      |  1 +
 target-i386/monitor.c             |  9 +++++++++
 7 files changed, 79 insertions(+)
hmp-commands-info.hx +16 -0
index dba7839..b346fd1 100644
@@ -128,6 +128,22 @@ STEXI
 Show local APIC state
 ETEXI
 
+#if defined(TARGET_I386)
+    {
+        .name       = "ioapic",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show io apic state",
+        .mhandler.cmd = hmp_info_io_apic,
+    },
+#endif
+
+STEXI
+@item info ioapic
+@findex ioapic
+Show io APIC state
+ETEXI
+
     {
         .name       = "cpus",
         .args_type  = "",
hw/i386/kvm/ioapic.c +10 -0
index d2a6c4c..b7390ca 100644
@@ -10,6 +10,7 @@
  * See the COPYING file in the top-level directory.
  */
 
+#include "monitor/monitor.h"
 #include "hw/i386/pc.h"
 #include "hw/i386/ioapic_internal.h"
 #include "hw/i386/apic_internal.h"
@@ -110,6 +111,15 @@ static void kvm_ioapic_put(IOAPICCommonState *s)
     }
 }
 
+void kvm_ioapic_dump_state(Monitor *mon, const QDict *qdict)
+{
+    IOAPICCommonState s;
+
+    kvm_ioapic_get(&s);
+
+    ioapic_print_redtbl(mon, &s);
+}
+
 static void kvm_ioapic_reset(DeviceState *dev)
 {
     IOAPICCommonState *s = IOAPIC_COMMON(dev);
hw/intc/ioapic_common.c +37 -0
index 8b7d118..762cfc9 100644
@@ -19,6 +19,7 @@
  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "monitor/monitor.h"
 #include "hw/i386/ioapic.h"
 #include "hw/i386/ioapic_internal.h"
 #include "hw/sysbus.h"
@@ -31,6 +32,42 @@
  */
 int ioapic_no;
 
+void ioapic_print_redtbl(Monitor *mon, IOAPICCommonState *s)
+{
+    static const char *delm_str[] = {
+        "fixed", "lowest", "SMI", "...", "NMI", "INIT", "...", "extINT"};
+    int i;
+
+    monitor_printf(mon, "ioapic id=0x%02x sel=0x%02x", s->id, s->ioregsel);
+    if (s->ioregsel) {
+        monitor_printf(mon, " (redir[%u])\n",
+                       (s->ioregsel - IOAPIC_REG_REDTBL_BASE) >> 1);
+    } else {
+        monitor_printf(mon, "\n");
+    }
+    for (i = 0; i < IOAPIC_NUM_PINS; i++) {
+        uint64_t entry = s->ioredtbl[i];
+        uint32_t delm = (uint32_t)((entry & IOAPIC_LVT_DELIV_MODE) >>
+                                   IOAPIC_LVT_DELIV_MODE_SHIFT);
+        monitor_printf(mon, "pin %-2u 0x%016jx dest=%jx vec=%-3lu "
+                       "%s %-5s %-6s %-6s %s\n",
+                       i, entry,
+                       (entry >> IOAPIC_LVT_DEST_SHIFT) &
+                            (entry & IOAPIC_LVT_DEST_MODE ? 0xff : 0xf),
+                       entry & IOAPIC_VECTOR_MASK,
+                       entry & IOAPIC_LVT_POLARITY ? "active-lo" : "active-hi",
+                       entry & IOAPIC_LVT_TRIGGER_MODE ? "level" : "edge",
+                       entry & IOAPIC_LVT_MASKED ? "masked" : "",
+                       delm_str[delm],
+                       entry & IOAPIC_LVT_DEST_MODE ? "logical" : "physical");
+    }
+    if (s->irr == 0) {
+        monitor_printf(mon, "IRR (none)\n");
+    } else {
+        monitor_printf(mon, "IRR %08x\n", s->irr);
+    }
+}
+
 void ioapic_reset_common(DeviceState *dev)
 {
     IOAPICCommonState *s = IOAPIC_COMMON(dev);
include/hw/i386/ioapic_internal.h +2 -0
index 4f7764e..797ed47 100644
@@ -105,4 +105,6 @@ struct IOAPICCommonState {
 
 void ioapic_reset_common(DeviceState *dev);
 
+void ioapic_print_redtbl(Monitor *mon, IOAPICCommonState *s);
+
 #endif /* !QEMU_IOAPIC_INTERNAL_H */
include/hw/i386/pc.h +4 -0
index 3e002c9..539cf64 100644
@@ -123,6 +123,10 @@ int pic_get_output(DeviceState *d);
 void hmp_info_pic(Monitor *mon, const QDict *qdict);
 void hmp_info_irq(Monitor *mon, const QDict *qdict);
 
+/* ioapic.c */
+
+void kvm_ioapic_dump_state(Monitor *mon, const QDict *qdict);
+
 /* Global System Interrupts */
 
 #define GSI_NUM_PINS IOAPIC_NUM_PINS
include/monitor/hmp-target.h +1 -0
index be50577..213566c 100644
@@ -43,5 +43,6 @@ void hmp_info_mem(Monitor *mon, const QDict *qdict);
 void hmp_info_tlb(Monitor *mon, const QDict *qdict);
 void hmp_mce(Monitor *mon, const QDict *qdict);
 void hmp_info_local_apic(Monitor *mon, const QDict *qdict);
+void hmp_info_io_apic(Monitor *mon, const QDict *qdict);
 
 #endif /* MONITOR_COMMON */
target-i386/monitor.c +9 -0
index 9479a77..829fff9 100644
@@ -24,6 +24,8 @@
 #include "cpu.h"
 #include "monitor/monitor.h"
 #include "monitor/hmp-target.h"
+#include "hw/i386/pc.h"
+#include "sysemu/kvm.h"
 #include "hmp.h"
 
 
@@ -498,3 +500,10 @@ void hmp_info_local_apic(Monitor *mon, const QDict *qdict)
     x86_cpu_dump_local_apic_state(mon_get_cpu(), (FILE *)mon, monitor_fprintf,
                                   CPU_DUMP_FPU);
 }
+
+void hmp_info_io_apic(Monitor *mon, const QDict *qdict)
+{
+    if (kvm_irqchip_in_kernel()) {
+        kvm_ioapic_dump_state(mon, qdict);
+    }
+}
Signature · 1 line
2.1.4
#9 lore raw

PATCH v3 9/9 hmp: implemented io apic dump state for TCG

In reply to Denis V. Lunev

From: Pavel Butsykin <[email protected]>

Added support emulator for the hmp command "info ioapic"

---
 hw/intc/ioapic.c      | 12 ++++++++++++
 include/hw/i386/pc.h  |  1 +
 target-i386/monitor.c |  2 ++
 3 files changed, 15 insertions(+)
hw/intc/ioapic.c +12 -0
index b527932..8c3aeae 100644
@@ -20,6 +20,7 @@
  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "monitor/monitor.h"
 #include "hw/hw.h"
 #include "hw/i386/pc.h"
 #include "hw/i386/ioapic.h"
@@ -137,6 +138,17 @@ void ioapic_eoi_broadcast(int vector)
     }
 }
 
+void ioapic_dump_state(Monitor *mon, const QDict *qdict)
+{
+    int i;
+
+    for (i = 0; i < MAX_IOAPICS; i++) {
+        if (ioapics[i] != 0) {
+            ioapic_print_redtbl(mon, ioapics[i]);
+        }
+    }
+}
+
 static uint64_t
 ioapic_mem_read(void *opaque, hwaddr addr, unsigned int size)
 {
include/hw/i386/pc.h +1 -0
index 539cf64..7c9f3a5 100644
@@ -126,6 +126,7 @@ void hmp_info_irq(Monitor *mon, const QDict *qdict);
 /* ioapic.c */
 
 void kvm_ioapic_dump_state(Monitor *mon, const QDict *qdict);
+void ioapic_dump_state(Monitor *mon, const QDict *qdict);
 
 /* Global System Interrupts */
 
target-i386/monitor.c +2 -0
index 829fff9..aac6b1b 100644
@@ -505,5 +505,7 @@ void hmp_info_io_apic(Monitor *mon, const QDict *qdict)
 {
     if (kvm_irqchip_in_kernel()) {
         kvm_ioapic_dump_state(mon, qdict);
+    } else {
+        ioapic_dump_state(mon, qdict);
     }
 }
Signature · 1 line
2.1.4
#10 lore raw
In reply to Denis V. Lunev
Quoted 6 lines · Denis V. Lunev

Added the hmp command to query IO- and Local APIC registers state, it can be very useful to identify problems related to the emulation devices.

(qemu) info lapic
dumping local APIC state for CPU 0

Quoted 9 lines
LVT0     0x00010700 active-hi edge  masked                      ExtINT (vec 0)
LVT1     0x00000400 active-hi edge                              NMI
LVTPC    0x00010000 active-hi edge  masked                      Fixed  (vec 0)
LVTERR   0x000000fe active-hi edge                              Fixed  (vec 254)
LVTTHMR  0x00010000 active-hi edge  masked                      Fixed  (vec 0)
LVTT     0x000000ef active-hi edge                 one-shot     Fixed  (vec 239)
Timer    DCR=0x3 (divide by 16) initial_count = 62278
SPIV     0x000001ff APIC enabled, focus=off, spurious vec 255
ICR      0x000000fd physical edge de-assert no

s/no/no-shorthand/ or similar.

Quoted 3 lines

ICR2 0x00000001 cpu 1 (X2APIC ID)
ESR 0x00000000
ISR

Adding a "(none)" here would be nice.

Quoted 30 lines

IRR 239

APR 0x00 TPR 0x00 DFR 0x0f LDR 0x00 PPR 0x00

(qemu) info ioapic
ioapic id=0x00 sel=0x2e (redir[15])

pin 0  0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 1  0x0000000000000031 dest=0 vec=49  active-hi edge         fixed  physical
pin 2  0x0000000000000030 dest=0 vec=48  active-hi edge         fixed  physical
pin 3  0x0000000000000033 dest=0 vec=51  active-hi edge         fixed  physical
pin 4  0x0000000000010034 dest=0 vec=52  active-hi edge  masked fixed  physical
pin 5  0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 6  0x0000000000000036 dest=0 vec=54  active-hi edge         fixed  physical
pin 7  0x0000000000000037 dest=0 vec=55  active-hi edge         fixed  physical
pin 8  0x0000000000000038 dest=0 vec=56  active-hi edge         fixed  physical
pin 9  0x0000000000018041 dest=0 vec=65  active-hi level masked fixed  physical
pin 10 0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 11 0x0300000000008081 dest=3 vec=129 active-hi level        fixed  physical
pin 12 0x000000000000003c dest=0 vec=60  active-hi edge         fixed  physical
pin 13 0x000000000000003d dest=0 vec=61  active-hi edge         fixed  physical
pin 14 0x000000000000003e dest=0 vec=62  active-hi edge         fixed  physical
pin 15 0x000000000000003f dest=0 vec=63  active-hi edge         fixed  physical
pin 16 0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 17 0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 18 0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 19 0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 20 0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 21 0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 22 0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 23 0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
Quoted 1 line

IRR (none)

I would print IRR as a bitmap here, like ISR/IRR in the local APIC dump.
Similarly, it would be nice to print the "Remote IRR" bits of the
redirection table (printing them as a bitmap with the same format).

Quoted 5 lines

Changes from v1:
- implementation of hmp commands moved to the target-i386 part
- the cpu_dump_apic_local_state interface moved to the target-i386 part

Quoted 7 lines

Changes from v2:
- lapic and ioapic format dump are fixed for more human readable view

I would like a second look at the HMP code.

Paolo

Quoted 29 lines

Pavel Butsykin (9):
apic_internal.h: make some apic_get_* functions externally visible apic_internal.h: rename ESR_ILLEGAL_ADDRESS to
APIC_ESR_ILLEGAL_ADDRESS
apic_internal.h: added more constants
apic_internal.h: fix formatting and drop unused consts
monitor: make monitor_fprintf and mon_get_cpu externally visible
hmp: added local apic dump state
ioapic_internal.h: added more constants
hmp: added io apic dump state
hmp: implemented io apic dump state for TCG

 disas.c                           |  10 --
 hmp-commands-info.hx              |  32 +++++++
 hw/i386/kvm/ioapic.c              |  10 ++
 hw/intc/apic.c                    |  22 +----
 hw/intc/ioapic.c                  |  12 +++
 hw/intc/ioapic_common.c           |  37 ++++++++
 include/hw/i386/apic_internal.h   |  96 ++++++++++++++++---
 include/hw/i386/ioapic_internal.h |   7 ++
 include/hw/i386/pc.h              |   5 +
 include/monitor/hmp-target.h      |   3 +
 include/monitor/monitor.h         |   1 +
 monitor.c                         |   5 +-
 target-i386/cpu.h                 |   3 +
 target-i386/helper.c              | 190 ++++++++++++++++++++++++++++++++++++++
 target-i386/monitor.c             |  17 ++++
 15 files changed, 407 insertions(+), 43 deletions(-)
#11 lore raw
Quoted 34 lines · Paolo Bonzini
Quoted 30 lines

IRR 239

APR 0x00 TPR 0x00 DFR 0x0f LDR 0x00 PPR 0x00

(qemu) info ioapic
ioapic id=0x00 sel=0x2e (redir[15])

pin 0  0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 1  0x0000000000000031 dest=0 vec=49  active-hi edge         fixed  physical
pin 2  0x0000000000000030 dest=0 vec=48  active-hi edge         fixed  physical
pin 3  0x0000000000000033 dest=0 vec=51  active-hi edge         fixed  physical
pin 4  0x0000000000010034 dest=0 vec=52  active-hi edge  masked fixed  physical
pin 5  0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 6  0x0000000000000036 dest=0 vec=54  active-hi edge         fixed  physical
pin 7  0x0000000000000037 dest=0 vec=55  active-hi edge         fixed  physical
pin 8  0x0000000000000038 dest=0 vec=56  active-hi edge         fixed  physical
pin 9  0x0000000000018041 dest=0 vec=65  active-hi level masked fixed  physical
pin 10 0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 11 0x0300000000008081 dest=3 vec=129 active-hi level        fixed  physical
pin 12 0x000000000000003c dest=0 vec=60  active-hi edge         fixed  physical
pin 13 0x000000000000003d dest=0 vec=61  active-hi edge         fixed  physical
pin 14 0x000000000000003e dest=0 vec=62  active-hi edge         fixed  physical
pin 15 0x000000000000003f dest=0 vec=63  active-hi edge         fixed  physical
pin 16 0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 17 0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 18 0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 19 0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 20 0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 21 0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 22 0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
pin 23 0x0000000000010000 dest=0 vec=0   active-hi edge  masked fixed  physical
Quoted 1 line

IRR (none)

I would print IRR as a bitmap here, like ISR/IRR in the local APIC dump.
Similarly, it would be nice to print the "Remote IRR" bits of the
redirection table (printing them as a bitmap with the same format).

...

pin 9  0x0000000000018041 dest=0 vec=65  active-hi level IRR(0) masked fixed  physical
pin 10 0x0000000000010000 dest=0 vec=0   active-hi edge         masked fixed  physical
pin 11 0x0300000000008081 dest=3 vec=129 active-hi level IRR(0)        fixed  physical
pin 12 0x000000000000003c dest=0 vec=60  active-hi edge                fixed  physical

...
IRR 2 17

Do I understand you right?

#12 lore raw
Quoted 6 lines · Pavel Butsykin
Quoted 4 lines
Quoted 1 line

I would print IRR as a bitmap here, like ISR/IRR in the local APIC dump.
Similarly, it would be nice to print the "Remote IRR" bits of the
redirection table (printing them as a bitmap with the same format).

...

Quoted 10 lines

pin 9 0x0000000000018041 dest=0 vec=65 active-hi level IRR(0) masked fixed physical
pin 10 0x0000000000010000 dest=0 vec=0 active-hi edge masked
fixed physical
pin 11 0x0300000000008081 dest=3 vec=129 active-hi level IRR(0) fixed physical
pin 12 0x000000000000003c dest=0 vec=60 active-hi edge fixed physical
...
IRR 2 17

I was thinking more like:

pin 9 0x0000000000018041 dest=0 vec=65 active-hi level masked fixed physical
pin 10 0x0000000000010000 dest=0 vec=0 active-hi edge masked fixed
physical
pin 11 0x030000000000c081 dest=3 vec=129 active-hi level fixed
physical
pin 12 0x000000000000003c dest=0 vec=60 active-hi edge fixed
physical
...
IRR 2 17
Remote IRR 11

Paolo