Skip to contentSkip to conversation

x86/hvm: Improve error information in handle_pio()

PATCH In review Andrew Cooper 3 participants 5 messages May 28, 2020 – May 29, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/hvm: Improve error information in handle_pio()

domain_crash() should always have a message which emitted even in release builds, so something more useful than this is presented.

(XEN) domain_crash called from io.c:171
(XEN) domain_crash called from io.c:171
(XEN) domain_crash called from io.c:171
...

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Marek Marczykowski-Górecki <[email protected]>

Part of a bug reported by Marek. Something else is wonky in the IO emulation state, and preventing us from yielding to the scheduler so the domain can progress with being shut down.

---
 xen/arch/x86/hvm/io.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/io.c +3 -1
index a5b0a23f06..4e468bfb6b 100644
@@ -167,7 +167,9 @@ bool handle_pio(uint16_t port, unsigned int size, int dir)
         break;
 
     default:
-        gdprintk(XENLOG_ERR, "Weird HVM ioemulation status %d.\n", rc);
+        gprintk(XENLOG_ERR, "Unexpected PIO status %d, port %#x %s 0x%0*lx\n",
+                rc, port, dir == IOREQ_WRITE ? "write" : "read",
+                size * 2, data & ((1ul << (size * 8)) - 1));
         domain_crash(curr->domain);
         return false;
     }
Signature · 1 line
2.11.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Andrew Cooper

domain_crash() should always have a message which emitted even in release builds, so something more useful than this is presented.

(XEN) domain_crash called from io.c:171
(XEN) domain_crash called from io.c:171
(XEN) domain_crash called from io.c:171
...

Quoted 19 lines

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Marek Marczykowski-Górecki <[email protected]>

Part of a bug reported by Marek. Something else is wonky in the IO emulation state, and preventing us from yielding to the scheduler so the domain can progress with being shut down.

---
 xen/arch/x86/hvm/io.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/io.c +0 -0
index a5b0a23f06..4e468bfb6b 100644

xen/arch/x86/hvm/io.c bool handle_pio(uint16_t port, unsigned int size, int dir) · line 172

Quoted 7 lines
xen/arch/x86/hvm/io.c +3 -1
@@ -167,7 +167,9 @@ bool handle_pio(uint16_t port, unsigned int size, int dir)
         break;
 
     default:
-        gdprintk(XENLOG_ERR, "Weird HVM ioemulation status %d.\n", rc);
+        gprintk(XENLOG_ERR, "Unexpected PIO status %d, port %#x %s 0x%0*lx\n",
+                rc, port, dir == IOREQ_WRITE ? "write" : "read",
+                size * 2, data & ((1ul << (size * 8)) - 1));

I wonder, should data be initialized to 0 in order to prevent writing garbage here if the buffer is not filled in the read case?

Note sure it's better to print garbage or just 0 in that case, as in both cases it won't be possible to figure out if it's real data or just the emulation didn't get to fill it (unless the specific error path is checked).

Thanks, Roger.

Acked-by on v1 1/1
#2 lore raw
In reply to Andrew Cooper
Quoted 9 lines · Andrew Cooper

domain_crash() should always have a message which emitted even in release builds, so something more useful than this is presented.

(XEN) domain_crash called from io.c:171
(XEN) domain_crash called from io.c:171
(XEN) domain_crash called from io.c:171
...

xen/arch/x86/hvm/io.c bool handle_pio(uint16_t port, unsigned int size, int dir) · line 172

Quoted 10 lines
xen/arch/x86/hvm/io.c +3 -1
@@ -167,7 +167,9 @@ bool handle_pio(uint16_t port, unsigned int size, int dir)
         break;
 
     default:
-        gdprintk(XENLOG_ERR, "Weird HVM ioemulation status %d.\n", rc);
+        gprintk(XENLOG_ERR, "Unexpected PIO status %d, port %#x %s 0x%0*lx\n",
+                rc, port, dir == IOREQ_WRITE ? "write" : "read",
+                size * 2, data & ((1ul << (size * 8)) - 1));

I agree with Roger that potentially logging rubbish for IOREQ_READ may be confusing, so initializing "data" might end up being better. Perhaps simply drop (or put in a comment) the
"if ( dir == IOREQ_WRITE )" at the top of the function? (As an aside, it's also odd for "data" to be "unsigned long" rather than just "unsigned int" or, less preferable, "uint32_t".)

Jan

#3 lore raw
In reply to Andrew Cooper
Quoted 1 line · Andrew Cooper

domain_crash() should always have a message which emitted even in release

Oh, forgot to say: The wording here looks somewhat strange (and thus unclear) to me.

Quoted 8 lines

builds, so something more useful than this is presented.

(XEN) domain_crash called from io.c:171
(XEN) domain_crash called from io.c:171
(XEN) domain_crash called from io.c:171
...

#4 lore raw
Quoted 4 lines · Jan Beulich
Quoted 1 line · Andrew Cooper

domain_crash() should always have a message which emitted even in release

Oh, forgot to say: The wording here looks somewhat strange (and thus unclear) to me.

It should read "which is emitted", but this is basically a stopgap fix seeing as I still haven't adjusted domain_crash() to force a message to be provided.

~Andrew