While reading the code, I noticed that we don't set CF in our interrupt handler
stubs. The guest kernel may think the interrupt handler succeeded depending on
whether or not it has set CF by itself (or whether BIOS code set it by chance).

While at it, fix INT 10h handler to clear CF to make sure the guest kernel
knows the interrupt handler succeeded.

Acked-by: Cyrill Gorcunov <gorcu...@gmail.com>
Cc: Ingo Molnar <mi...@elte.hu>
Cc: Sasha Levin <levinsasha...@gmail.com>
Signed-off-by: Pekka Enberg <penb...@kernel.org>
---
 tools/kvm/bios/bios.S |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/tools/kvm/bios/bios.S b/tools/kvm/bios/bios.S
index 1ddc461..4f82126 100644
--- a/tools/kvm/bios/bios.S
+++ b/tools/kvm/bios/bios.S
@@ -10,10 +10,19 @@
 
 #include "macro.S"
 
+#define EFLAGS_CF      (1 << 0)
+
 /*
  * fake interrupt handler, nothing can be faster ever
  */
 ENTRY(bios_intfake)
+       /*
+        * Set CF to indicate failure. We don't want callers to think that the
+        * interrupt handler succeeded and then treat the return values in
+        * registers as valid data.
+        */
+       orl     $EFLAGS_CF, 0x4(%esp)
+
        IRET
 ENTRY_END(bios_intfake)
 
@@ -48,11 +57,12 @@ ENTRY(bios_int10)
        popl    %es
        popw    %fs
 
+       /* Clear CF to indicate success.  */
+       andl    $~EFLAGS_CF, 0x4(%esp)
+
        IRET
 ENTRY_END(bios_int10)
 
-#define EFLAGS_CF      (1 << 0)
-
 ENTRY(bios_int15)
        cmp $0xE820, %eax
        jne 1f
@@ -76,7 +86,7 @@ ENTRY(bios_int15)
 
        popw    %fs
 
-       /* Clear CF */
+       /* Clear CF to indicate success.  */
        andl    $~EFLAGS_CF, 0x4(%esp)
 1:
        IRET
-- 
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to