x86/boot: Fix boot following c/s b6c2c7f48a
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 11 Jan 2018 23:38:40 +0000 (23:38 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 12 Jan 2018 11:22:54 +0000 (11:22 +0000)
c/s b6c2c7f48a unfortunately broke booting on affected systems.  Most of the
time, ioemul_handle_quirk() doesn't write a custom stub, and the redundant
call was depending on the seemingly-pointless writing of the default stub.

Alter the ioemul_handle_quirk() API to return a boolean if a custom stub was
written, allowing its caller to know whether it should write a default stub
instead.

Finally, adjust the /* Regular stubs */ comment to make it clearer that the 16
refers to the length of the emul stub opcode.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/ioport_emulate.c
xen/arch/x86/pv/emul-priv-op.c
xen/arch/x86/traps.c
xen/include/asm-x86/io.h

index 1f6f7948f23be16c1cb5431d9a0b0b8670795fbf..e80993acc944ab9f158dc09924d8c23c813d7a08 100644 (file)
@@ -8,14 +8,14 @@
 #include <xen/sched.h>
 #include <xen/dmi.h>
 
-static void ioemul_handle_proliant_quirk(
+static bool ioemul_handle_proliant_quirk(
     u8 opcode, char *io_emul_stub, struct cpu_user_regs *regs)
 {
     uint16_t port = regs->dx;
     uint8_t value = regs->al;
 
     if ( (opcode != 0xee) || (port != 0xcd4) || !(value & 0x80) )
-        return;
+        return false;
 
     /*    pushf */
     io_emul_stub[0] = 0x9c;
@@ -37,6 +37,8 @@ static void ioemul_handle_proliant_quirk(
     io_emul_stub[9] = 0xc3;
 
     BUILD_BUG_ON(IOEMUL_QUIRK_STUB_BYTES < 10);
+
+    return true;
 }
 
 static int __init proliant_quirk(struct dmi_system_id *d)
index 4087cf2ffb09c8717d9748ae2dfe3a4d01c52491..ebd6dc19b03b1969b6196561bc91b6bb61b690e1 100644 (file)
@@ -76,6 +76,8 @@ typedef void io_emul_stub_t(struct cpu_user_regs *);
 static io_emul_stub_t *io_emul_stub_setup(struct priv_op_ctxt *ctxt, u8 opcode,
                                           unsigned int port, unsigned int bytes)
 {
+    bool use_quirk_stub = false;
+
     if ( !ctxt->io_emul_stub )
         ctxt->io_emul_stub = map_domain_page(_mfn(this_cpu(stubs.mfn))) +
                                              (this_cpu(stubs.addr) &
@@ -90,7 +92,11 @@ static io_emul_stub_t *io_emul_stub_setup(struct priv_op_ctxt *ctxt, u8 opcode,
     ctxt->io_emul_stub[10] = 0xff;
     ctxt->io_emul_stub[11] = 0xd1;
 
-    if ( likely(!ioemul_handle_quirk) )
+    if ( unlikely(ioemul_handle_quirk) )
+        use_quirk_stub = ioemul_handle_quirk(opcode, &ctxt->io_emul_stub[12],
+                                             ctxt->ctxt.regs);
+
+    if ( !use_quirk_stub )
     {
         /* data16 or nop */
         ctxt->io_emul_stub[12] = (bytes != 2) ? 0x90 : 0x66;
@@ -101,10 +107,8 @@ static io_emul_stub_t *io_emul_stub_setup(struct priv_op_ctxt *ctxt, u8 opcode,
         /* ret (jumps to guest_to_host_gpr_switch) */
         ctxt->io_emul_stub[15] = 0xc3;
     }
-    else
-        ioemul_handle_quirk(opcode, &ctxt->io_emul_stub[12], ctxt->ctxt.regs);
 
-    BUILD_BUG_ON(STUB_BUF_SIZE / 2 < MAX(16, /* Regular stubs */
+    BUILD_BUG_ON(STUB_BUF_SIZE / 2 < MAX(16, /* Default emul stub */
                                          12 + IOEMUL_QUIRK_STUB_BYTES));
 
     /* Handy function-typed pointer to the stub. */
index db16a4441731273c7484d6397f5938e7be467202..2509ea7b1a01da1657228954bdf664b294a9bb59 100644 (file)
@@ -107,7 +107,7 @@ idt_entry_t idt_table[IDT_ENTRIES];
 /* Pointer to the IDT of every CPU. */
 idt_entry_t *idt_tables[NR_CPUS] __read_mostly;
 
-void (*ioemul_handle_quirk)(
+bool (*ioemul_handle_quirk)(
     u8 opcode, char *io_emul_stub, struct cpu_user_regs *regs);
 
 static int debug_stack_lines = 20;
index e6bb20cb2fb035b0b17296ea42ba2ed898534494..4d2064ed0482e6d7568255b374653914d803cb92 100644 (file)
@@ -52,7 +52,7 @@ extern void (*pv_post_outb_hook)(unsigned int port, u8 value);
 
 /* Function pointer used to handle platform specific I/O port emulation. */
 #define IOEMUL_QUIRK_STUB_BYTES 10
-extern void (*ioemul_handle_quirk)(
+extern bool (*ioemul_handle_quirk)(
     u8 opcode, char *io_emul_stub, struct cpu_user_regs *regs);
 
 #endif