kvm tools, bios: Setup CF after returning from interrupt handler
PATCH 1/8 kvm tools, bios: Setup CF after returning from interrupt handler
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.
--- tools/kvm/bios/bios.S | 16 +++++++++++++--- 1 files changed, 13 insertions(+), 3 deletions(-)
tools/kvm/bios/bios.S +13 -3
@@ -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
Signature · 1 line
1.7.0.4
PATCH 2/8 kvm tools, bios: Rename struct int10_args to struct biosregs
This patch renames struct int10_args to struct biosregs in preparation for unifying interrupt handler code.
--- tools/kvm/bios/int10.c | 22 +++++----------------- tools/kvm/include/kvm/bios.h | 16 ++++++++++++++++ tools/kvm/include/kvm/vesa.h | 4 ++-- 3 files changed, 23 insertions(+), 19 deletions(-)
tools/kvm/bios/int10.c +5 -17
@@ -6,18 +6,6 @@#define VESA_MAGIC ('V' + ('E' << 8) + ('S' << 16) + ('A' << 24)) -struct int10_args { -u32 eax; -u32 ebx; -u32 ecx; -u32 edx; -u32 esp; -u32 ebp; -u32 esi; -u32 edi; -u32 es; -}; -/* VESA General Information table */ struct vesa_general_info {u32 signature;/* 0 Magic number = "VESA" */
@@ -79,14 +67,14 @@ static inline void outb(unsigned short port, unsigned char val)* It's probably much more useful to make this print to the serial * line rather than print to a non-displayed VGA memory */ -static inline void int10_putchar (struct int10_args *args) +static inline void int10_putchar (struct biosregs *args) {u8 al = args->eax &0xFF ;outb (0x3f8 , al); } -static void vbe_get_mode (struct int10_args *args) +static void vbe_get_mode (struct biosregs *args) {struct vminfo *info = (struct vminfo *) args->edi;
@@ -109,7 +97,7 @@ static void vbe_get_mode(struct int10_args *args) }; } -static void vbe_get_info (struct int10_args *args) +static void vbe_get_info (struct biosregs *args) {struct vesa_general_info *info = (struct vesa_general_info *) args->edi;
@@ -127,7 +115,7 @@ static void vbe_get_info(struct int10_args *args)#define VBE_STATUS_OK 0x004F -static void int10_vesa (struct int10_args *args) +static void int10_vesa (struct biosregs *args) {u8 al;
@@ -145,7 +133,7 @@ static void int10_vesa(struct int10_args *args) args->eax =VBE_STATUS_OK ; } -bioscall void int10_handler(struct int10_args *args) +bioscall void int10_handler(struct biosregs *args) {u8 ah;
tools/kvm/include/kvm/bios.h +16 -0
@@ -56,4 +56,20 @@*/ #define bioscall __attribute__((regparm(3))) +#ifndef __ASSEMBLER__ + +struct biosregs { +u32 eax; +u32 ebx; +u32 ecx; +u32 edx; +u32 esp; +u32 ebp; +u32 esi; +u32 edi; +u32 es; +}; + +#endif +#endif /* BIOS_H_ */
tools/kvm/include/kvm/vesa.h +2 -2
@@ -11,9 +11,9 @@#define VESA_BPP 32struct kvm ; -struct int10_args ; +struct biosregs ;struct framebuffer *vesa__init (struct kvm *self); -void int10_handler (struct int10_args *args); +void int10_handler (struct biosregs *args);#endif
Signature · 1 line
1.7.0.4
PATCH 3/8 kvm tools, bios: Add macros for BIOS registers
In reply to Pekka EnbergThis patch adds SAVE_BIOSREGS and RESTORE_BIOSREGS macros in preparation for using struct biosregs in E820 code.
--- tools/kvm/bios/bios.S | 51 ++++++++++++++++++++++++++++-------------------- 1 files changed, 30 insertions(+), 21 deletions(-)
tools/kvm/bios/bios.S +30 -21
@@ -8,9 +8,36 @@ .org 0 .code16gcc +#define EFLAGS_CF (1 << 0) + #include "macro.S" -#define EFLAGS_CF (1 << 0) +/* If you change these macros, remember to update 'struct biosregs' */ +.macro SAVE_BIOSREGS + pushw %fs + pushl %es + pushl %edi + pushl %esi + pushl %ebp + pushl %esp + pushl %edx + pushl %ecx + pushl %ebx + pushl %eax +.endm + +.macro RESTORE_BIOSREGS + popl %eax + popl %ebx + popl %ecx + popl %edx + popl %esp + popl %ebp + popl %esi + popl %edi + popl %es + popw %fs +.endm /* * fake interrupt handler, nothing can be faster ever
@@ -30,32 +57,14 @@ ENTRY_END(bios_intfake) * int 10 - video - service */ ENTRY(bios_int10) - pushw %fs - pushl %es - pushl %edi - pushl %esi - pushl %ebp - pushl %esp - pushl %edx - pushl %ecx - pushl %ebx - pushl %eax + SAVE_BIOSREGS movl %esp, %eax /* this is way easier than doing it in assembly */ /* just push all the regs and jump to a C handler */ call int10_handler - popl %eax - popl %ebx - popl %ecx - popl %edx - popl %esp - popl %ebp - popl %esi - popl %edi - popl %es - popw %fs + RESTORE_BIOSREGS /* Clear CF to indicate success. */ andl $~EFLAGS_CF, 0x4(%esp)
Signature · 1 line
1.7.0.4
PATCH 4/8 kvm tools, bios: Add EIP and EFLAGS to 'struct biosregs'
In reply to Pekka EnbergThis patch adds EIP and EFLAGS to 'struct biosregs' in preparation for converting int15 handler into C code.
--- tools/kvm/bios/bios.S | 4 ++-- tools/kvm/include/kvm/bios.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-)
tools/kvm/bios/bios.S +2 -2
@@ -14,7 +14,7 @@ /* If you change these macros, remember to update 'struct biosregs' */ .macro SAVE_BIOSREGS - pushw %fs + pushl %fs pushl %es pushl %edi pushl %esi
@@ -36,7 +36,7 @@ popl %esi popl %edi popl %es - popw %fs + popl %fs .endm /*
tools/kvm/include/kvm/bios.h +3 -0
@@ -68,6 +68,9 @@ struct biosregs {u32 esi;u32 edi;u32 es; +u32 fs; +u32 eip; + u32 eflags; };#endif
Signature · 1 line
1.7.0.4
PATCH 5/8 kvm tools, bios: Use struct biosregs in E820 code
In reply to Pekka EnbergThis patch converts the E820 code to use 'struct biosregs' and {SAVE,RESTORE}_BIOSREGS macros.
--- tools/kvm/bios/bios.S | 16 ++-------------- tools/kvm/bios/e820.c | 14 +++++++------- tools/kvm/include/kvm/e820.h | 10 ++-------- 3 files changed, 11 insertions(+), 29 deletions(-)
tools/kvm/bios/bios.S +2 -14
@@ -76,24 +76,12 @@ ENTRY(bios_int15) cmp $0xE820, %eax jne 1f - pushw %fs - - pushl %edx - pushl %ecx - pushl %edi - pushl %ebx - pushl %eax + SAVE_BIOSREGS movl %esp, %eax # it's bioscall case call e820_query_map - popl %eax - popl %ebx - popl %edi - popl %ecx - popl %edx - - popw %fs + RESTORE_BIOSREGS /* Clear CF to indicate success. */ andl $~EFLAGS_CF, 0x4(%esp)
tools/kvm/bios/e820.c +7 -7
@@ -29,7 +29,7 @@ static inline u32 rdfs32(unsigned long addr)return v; } -bioscall void e820_query_map(struct e820_query *query) +bioscall void e820_query_map(struct biosregs *regs) {struct e820map *e820;u32 map_size;
@@ -40,7 +40,7 @@ bioscall void e820_query_map(struct e820_query *query) fs_seg =flat_to_seg16 (E820_MAP_START );set_fs (fs_seg); - ndx = query->ebx; + ndx = regs->ebx; map_size =rdfs32 (flat_to_off16 ((u32)&e820->nr_map, fs_seg));
@@ -54,16 +54,16 @@ bioscall void e820_query_map(struct e820_query *query) start = (u32)&e820->map[ndx]; - p = (void *) query->edi; + p = (void *) regs->edi;for (i =0 ; i <sizeof (struct e820entry ); i++) *p++ =rdfs8 (flat_to_off16 (start + i, fs_seg)); } - query->eax =SMAP ; - query->ecx =sizeof (struct e820entry ); - query->ebx = ++ndx; + regs->eax =SMAP ; + regs->ecx =sizeof (struct e820entry ); + regs->ebx = ++ndx;if (ndx >= map_size) - query->ebx =0 ;/* end of map */ + regs->ebx =0 ;/* end of map */ }
tools/kvm/include/kvm/e820.h +2 -8
@@ -5,14 +5,8 @@#define SMAP 0x534d4150/* ASCII "SMAP" */ -struct e820_query { -u32 eax; -u32 ebx; -u32 edi; -u32 ecx; -u32 edx; -}; +struct biosregs ; -void e820_query_map (struct e820_query *query); +void e820_query_map (struct biosregs *regs);#endif /* KVM_E820_H */
Signature · 1 line
1.7.0.4
PATCH 6/8 kvm tools, bios: Move CF clearing to e820_query_map()
In reply to Pekka EnbergIn preparation for converting the int15 handler into C, move CF clearing to e820_query_map().
--- tools/kvm/bios/bios.S | 3 --- tools/kvm/bios/e820.c | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-)
tools/kvm/bios/bios.S +0 -3
@@ -82,9 +82,6 @@ ENTRY(bios_int15) call e820_query_map RESTORE_BIOSREGS - - /* Clear CF to indicate success. */ - andl $~EFLAGS_CF, 0x4(%esp) 1: IRET ENTRY_END(bios_int15)
tools/kvm/bios/e820.c +4 -0
@@ -4,6 +4,7 @@#include "kvm/bios.h" #include "kvm/util.h" +#include <asm/processor-flags.h> #include <asm/e820.h> static inline void set_fs (u16 seg)
@@ -64,6 +65,9 @@ bioscall void e820_query_map(struct biosregs *regs) regs->ecx =sizeof (struct e820entry ); regs->ebx = ++ndx; +/* Clear CF to indicate success. */ + regs->eflags &= ~X86_EFLAGS_CF ; +if (ndx >= map_size) regs->ebx =0 ;/* end of map */ }
Signature · 1 line
1.7.0.4
PATCH 7/8 kvm tools, bios: Convert int15 code to C
In reply to Pekka EnbergThis patch convert the int15 interrupt handler code into C.
--- tools/kvm/Makefile | 6 ++++-- tools/kvm/bios/bios.S | 9 +++------ tools/kvm/bios/int15.c | 12 ++++++++++++ tools/kvm/include/kvm/bios.h | 5 +++++ tools/kvm/include/kvm/vesa.h | 1 - 5 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 tools/kvm/bios/int15.c
tools/kvm/Makefile +4 -2
@@ -199,15 +199,17 @@ BIOS_CFLAGS += -mregparm=3 bios.o: bios/bios.bin bios/bios-rom.h -bios/bios.bin.elf: bios/bios.S bios/e820.c bios/int10.c bios/rom.ld.S +bios/bios.bin.elf: bios/bios.S bios/e820.c bios/int10.c bios/int15.c bios/rom.ld.S $(E) " CC bios/e820.o" $(Q) $(CC) -include code16gcc.h $(CFLAGS) $(BIOS_CFLAGS) -c -s bios/e820.c -o bios/e820.o $(E) " CC bios/int10.o" $(Q) $(CC) -include code16gcc.h $(CFLAGS) $(BIOS_CFLAGS) -c -s bios/int10.c -o bios/int10.o + $(E) " CC bios/int15.o" + $(Q) $(CC) -include code16gcc.h $(CFLAGS) $(BIOS_CFLAGS) -c -s bios/int15.c -o bios/int15.o $(E) " CC bios/bios.o" $(Q) $(CC) $(CFLAGS) $(BIOS_CFLAGS) -c -s bios/bios.S -o bios/bios.o $(E) " LD " $@ - $(Q) ld -T bios/rom.ld.S -o bios/bios.bin.elf bios/bios.o bios/e820.o bios/int10.o + $(Q) ld -T bios/rom.ld.S -o bios/bios.bin.elf bios/bios.o bios/e820.o bios/int10.o bios/int15.o bios/bios.bin: bios/bios.bin.elf $(E) " OBJCOPY " $@
tools/kvm/bios/bios.S +3 -6
@@ -73,16 +73,13 @@ ENTRY(bios_int10) ENTRY_END(bios_int10) ENTRY(bios_int15) - cmp $0xE820, %eax - jne 1f - SAVE_BIOSREGS - movl %esp, %eax # it's bioscall case - call e820_query_map + movl %esp, %eax + call int15_handler RESTORE_BIOSREGS -1: + IRET ENTRY_END(bios_int15)
tools/kvm/bios/int15.c new file +12 -0
@@ -0,0 +1,12 @@ +#include "kvm/bios.h" + +#include "kvm/e820.h" + +bioscall void int15_handler(struct biosregs *regs) +{ +switch (regs->eax) { +case 0xe820 : +e820_query_map (regs); +break ; + } +}
tools/kvm/include/kvm/bios.h +5 -0
@@ -58,6 +58,8 @@ #ifndef __ASSEMBLER__ +#include <linux/types.h> + struct biosregs { u32 eax; u32 ebx;
@@ -73,6 +75,9 @@ struct biosregs {u32 eflags; }; +void int10_handler (struct biosregs *regs); +void int15_handler (struct biosregs *regs); +#endif #endif /* BIOS_H_ */
tools/kvm/include/kvm/vesa.h +0 -1
@@ -14,6 +14,5 @@ struct kvm;struct biosregs ;struct framebuffer *vesa__init (struct kvm *self); -void int10_handler (struct biosregs *args);#endif
Signature · 1 line
1.7.0.4
PATCH 8/8 kvm tools, bios: Set CF for non-supported services
In reply to Pekka EnbergDon't mislead callers into thinking that a non-implemented int15 service succeeded.
--- tools/kvm/bios/int15.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
tools/kvm/bios/int15.c +6 -0
@@ -2,11 +2,17 @@#include "kvm/e820.h" +#include <asm/processor-flags.h> + bioscall void int15_handler(struct biosregs *regs) {switch (regs->eax) {case 0xe820 :e820_query_map (regs);break ; +default : +/* Set CF to indicate failure. */ + regs->eflags |=X86_EFLAGS_CF ; +break ; } }
Signature · 1 line
1.7.0.4