kvm-tool: ARM: set interrupt priority mask in secondary boot path
PATCH 1/3 kvm-tool: ARM: set interrupt priority mask in secondary boot path
From: Marc Zyngier <[email protected]>
A bug in the KVM GIC init code set the priority mask to the highest possible value, while the reset value should be zero.
Now that the kernel bug is fixed, kvm-tool must properly configure its GIC CPU interface in order to receive the boot IPI. Just set the GICC_PMR register to the maximum value (0xff), and it "just works".
--- tools/kvm/arm/aarch32/smp-pen.S | 4 ++++ tools/kvm/arm/include/arm-common/gic.h | 3 +++ 2 files changed, 7 insertions(+)
tools/kvm/arm/aarch32/smp-pen.S +4 -0
@@ -17,6 +17,10 @@ smp_pen_start: mov r1, #GIC_CPUI_CTLR_EN str r1, [r0] + @ Set the priority mask to accept any interrupt + mov r1, #GIC_CPUI_PMR_MIN_PRIO + str r1, [r0, #GIC_CPUI_OFF_PMR] + @ Now wait for the primary to poke us adr r0, smp_jump_addr ldr r1, =AARCH32_SMP_BAD_MAGIC
tools/kvm/arm/include/arm-common/gic.h +3 -0
@@ -19,6 +19,9 @@#define GIC_FDT_IRQ_PPI_CPU_MASK (0xff << GIC_FDT_IRQ_PPI_CPU_SHIFT)#define GIC_CPUI_CTLR_EN (1 << 0) +#define GIC_CPUI_PMR_MIN_PRIO 0xff + +#define GIC_CPUI_OFF_PMR 4#define GIC_MAX_CPUS 8#define GIC_MAX_IRQ 255
Signature · 1 line
1.8.0
PATCH 2/3 kvm tools: arm: fixup pre-processor guards for kvm-cpu-arch.h
Cosmetic patch to correct the pre-processor guards for arm in kvm-cpu-arch.h. It's not something to lose sleep over but I find it incredibly irritating!
--- tools/kvm/arm/include/kvm/kvm-cpu-arch.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/kvm/arm/include/kvm/kvm-cpu-arch.h +3 -3
@@ -1,5 +1,5 @@ -#ifndef ARM_COMMON__KVM_CPU_ARCH_H -#define ARM_COMMON__KVM_CPU_ARCH_H +#ifndef KVM__KVM_CPU_ARCH_H +#define KVM__KVM_CPU_ARCH_H #include <linux/kvm.h> #include <pthread.h>
@@ -43,4 +43,4 @@ static inline bool kvm_cpu__emulate_io(struct kvm *kvm, u16 port, void *data,bool kvm_cpu__emulate_mmio (struct kvm *kvm,u64 phys_addr,u8 *data,u32 len,u8 is_write); -#endif /* ARM_COMMON__KVM_CPU_ARCH_H */ +#endif /* KVM__KVM_CPU_ARCH_H */
Signature · 1 line
1.8.0
PATCH 3/3 kvm tools: allow arch's to provide their own command-line options
In reply to Will DeaconCurrently, only x86 has architecture command-line options (for setting the BIOS video mode) however this is likely to become more common in the future.
This patch adds some simple macros and a struct definition to allow architectures to augment the command-line options with private definitions. The BIOS video mode option (--vidmode) is also migrated to the new framework.
--- tools/kvm/arm/fdt.c | 4 ++-- tools/kvm/arm/include/kvm/kvm-config-arch.h | 7 +++++++ tools/kvm/builtin-run.c | 21 ++++++--------------- tools/kvm/include/kvm/kvm-config.h | 3 ++- tools/kvm/include/kvm/kvm.h | 4 ++-- tools/kvm/include/kvm/parse-options.h | 3 +++ tools/kvm/kvm.c | 6 +++--- tools/kvm/powerpc/include/kvm/kvm-config-arch.h | 7 +++++++ tools/kvm/powerpc/kvm.c | 4 ++-- tools/kvm/x86/include/kvm/kvm-config-arch.h | 15 +++++++++++++++ tools/kvm/x86/kvm.c | 16 ++++++++++++++-- 11 files changed, 63 insertions(+), 27 deletions(-) create mode 100644 tools/kvm/arm/include/kvm/kvm-config-arch.h create mode 100644 tools/kvm/powerpc/include/kvm/kvm-config-arch.h create mode 100644 tools/kvm/x86/include/kvm/kvm-config-arch.h
tools/kvm/arm/fdt.c +2 -2
@@ -258,8 +258,8 @@ int load_flat_binary(struct kvm *kvm, int fd_kernel, int fd_initrd,return true; } -bool load_bzimage (struct kvm *kvm,int fd_kernel, -int fd_initrd,const char *kernel_cmdline,u16 vidmode) +bool load_bzimage (struct kvm *kvm,int fd_kernel,int fd_initrd, +const char *kernel_cmdline) {/* To b or not to b? That is the zImage. */ return false;
tools/kvm/arm/include/kvm/kvm-config-arch.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef KVM__KVM_CONFIG_ARCH_H +#define KVM__KVM_CONFIG_ARCH_H + +struct kvm_config_arch { +}; + +#endif /* KVM__KVM_CONFIG_ARCH_H */
tools/kvm/builtin-run.c +6 -15
@@ -90,6 +90,10 @@ void kvm_run_set_wrapper_sandbox(void) kvm_run_wrapper =KVM_RUN_SANDBOX ; } +#ifndef OPT_ARCH_RUN +#define OPT_ARCH_RUN (...) +#endif +#define BUILD_OPTIONS (name, cfg, kvm) \ struct option name[] = { \ OPT_GROUP("Basic options:"), \
@@ -144,10 +148,6 @@ void kvm_run_set_wrapper_sandbox(void)OPT_BOOLEAN ('\0' ,"no-dhcp" , &(cfg)->no_dhcp,"Disable kernel" \" DHCP in rootfs mode" ), \ \ -OPT_GROUP ("BIOS options:" ), \ -OPT_INTEGER ('\0' ,"vidmode" , &(cfg)->vidmode, \ -"Video mode" ), \ - \OPT_GROUP ("Debug options:" ), \OPT_BOOLEAN ('\0' ,"debug" , &do_debug_print, \ "Enable debug messages"), \
@@ -159,6 +159,8 @@ void kvm_run_set_wrapper_sandbox(void) "Enable MMIO debugging"), \OPT_INTEGER ('\0' ,"debug-iodelay" , &(cfg)->debug_iodelay, \"Delay IO by millisecond" ), \ + \ + OPT_ARCH(RUN, cfg) \ OPT_END() \ };
@@ -598,17 +600,6 @@ static struct kvm *kvm_cmd_run_init(int argc, const char **argv)if (!kvm->cfg.script) kvm->cfg.script =DEFAULT_SCRIPT ; -if (!kvm->cfg.vidmode) - kvm->cfg.vidmode =-1 ; - -/* vidmode should be either specified or set by default */ -if (kvm->cfg.vnc || kvm->cfg.sdl) { -if (kvm->cfg.vidmode ==-1 ) - kvm->cfg.vidmode =0x312 ; - }else { - kvm->cfg.vidmode =0 ; - } -if (!kvm->cfg.network) kvm->cfg.network =DEFAULT_NETWORK ;
tools/kvm/include/kvm/kvm-config.h +2 -1
@@ -2,6 +2,7 @@#define KVM_CONFIG_H_ #include "kvm/disk-image.h" +#include "kvm/kvm-config-arch.h" #define DEFAULT_KVM_DEV "/dev/kvm"#define DEFAULT_CONSOLE "serial"
@@ -17,6 +18,7 @@#define MIN_RAM_SIZE_BYTE (MIN_RAM_SIZE_MB << MB_SHIFT)struct kvm_config { +struct kvm_config_arch arch;struct disk_image_params disk_image[MAX_DISK_IMAGES ];u64 ram_size;u8 image_count;
@@ -25,7 +27,6 @@ struct kvm_config {int active_console;int debug_iodelay;int nrcpus; -int vidmode;const char *kernel_cmdline;const char *kernel_filename;const char *vmlinux_filename;
tools/kvm/include/kvm/kvm.h +2 -2
@@ -78,7 +78,7 @@ void kvm__init_ram(struct kvm *kvm);int kvm__exit (struct kvm *kvm);bool kvm__load_firmware (struct kvm *kvm,const char *firmware_filename);bool kvm__load_kernel (struct kvm *kvm,const char *kernel_filename, -const char *initrd_filename,const char *kernel_cmdline,u16 vidmode); +const char *initrd_filename,const char *kernel_cmdline);int kvm_timer__init (struct kvm *kvm);int kvm_timer__exit (struct kvm *kvm);void kvm__irq_line (struct kvm *kvm,int irq,int level);
@@ -109,7 +109,7 @@ void *guest_flat_to_host(struct kvm *kvm, u64 offset);u64 host_to_guest_flat (struct kvm *kvm,void *ptr);int load_flat_binary (struct kvm *kvm,int fd_kernel,int fd_initrd,const char *kernel_cmdline); -bool load_bzimage (struct kvm *kvm,int fd_kernel,int fd_initrd,const char *kernel_cmdline,u16 vidmode); +bool load_bzimage (struct kvm *kvm,int fd_kernel,int fd_initrd,const char *kernel_cmdline);/* * Debugging
tools/kvm/include/kvm/parse-options.h +3 -0
@@ -191,6 +191,9 @@ struct option {#define OPT_END () { .type = OPTION_END } +#define OPT_ARCH (cmd, cfg) \ + OPT_ARCH_##cmd(OPT_GROUP("Arch-specific options:"), &(cfg)->arch) +enum {PARSE_OPT_HELP =-1 ,PARSE_OPT_DONE ,
tools/kvm/kvm.c +3 -3
@@ -303,7 +303,7 @@ int kvm__init(struct kvm *kvm)if (!kvm->cfg.firmware_filename) {if (!kvm__load_kernel (kvm, kvm->cfg.kernel_filename, - kvm->cfg.initrd_filename, kvm->cfg.real_cmdline, kvm->cfg.vidmode)) + kvm->cfg.initrd_filename, kvm->cfg.real_cmdline))die ("unable to load kernel %s" , kvm->cfg.kernel_filename); }
@@ -349,7 +349,7 @@ static bool initrd_check(int fd) }bool kvm__load_kernel (struct kvm *kvm,const char *kernel_filename, -const char *initrd_filename,const char *kernel_cmdline,u16 vidmode) +const char *initrd_filename,const char *kernel_cmdline) {bool ret;int fd_kernel =-1 , fd_initrd =-1 ;
@@ -367,7 +367,7 @@ bool kvm__load_kernel(struct kvm *kvm, const char *kernel_filename,die ("%s is not an initrd" , initrd_filename); } - ret =load_bzimage (kvm, fd_kernel, fd_initrd, kernel_cmdline, vidmode); + ret =load_bzimage (kvm, fd_kernel, fd_initrd, kernel_cmdline);if (ret) goto found_kernel;
tools/kvm/powerpc/include/kvm/kvm-config-arch.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef KVM__KVM_CONFIG_ARCH_H +#define KVM__KVM_CONFIG_ARCH_H + +struct kvm_config_arch { +}; + +#endif /* KVM__KVM_CONFIG_ARCH_H */
tools/kvm/powerpc/kvm.c +2 -2
@@ -204,8 +204,8 @@ int load_flat_binary(struct kvm *kvm, int fd_kernel, int fd_initrd, const char *return true; } -bool load_bzimage (struct kvm *kvm,int fd_kernel, -int fd_initrd,const char *kernel_cmdline,u16 vidmode) +bool load_bzimage (struct kvm *kvm,int fd_kernel,int fd_initrd, +const char *kernel_cmdline) {/* We don't support bzImages. */ return false;
tools/kvm/x86/include/kvm/kvm-config-arch.h new file +15 -0
@@ -0,0 +1,15 @@ +#ifndef KVM__KVM_CONFIG_ARCH_H +#define KVM__KVM_CONFIG_ARCH_H + +#include "kvm/parse-options.h" + +struct kvm_config_arch { +int vidmode; +}; + +#define OPT_ARCH_RUN (pfx, cfg) \ + pfx, \ + OPT_GROUP("BIOS options:"), \ + OPT_INTEGER('\0', "vidmode", &(cfg)->vidmode, "Video mode"), + +#endif /* KVM__KVM_CONFIG_ARCH_H */
tools/kvm/x86/kvm.c +14 -2
@@ -235,8 +235,8 @@ int load_flat_binary(struct kvm *kvm, int fd_kernel, int fd_initrd, const char *static const char *BZIMAGE_MAGIC ="HdrS" ; -bool load_bzimage (struct kvm *kvm,int fd_kernel, -int fd_initrd,const char *kernel_cmdline,u16 vidmode) +bool load_bzimage (struct kvm *kvm,int fd_kernel,int fd_initrd, +const char *kernel_cmdline) {struct boot_params *kern_boot;unsigned long setup_sects;
@@ -245,6 +245,7 @@ bool load_bzimage(struct kvm *kvm, int fd_kernel,ssize_t setup_size;void *p;int nr; +u16 vidmode;/* * See Documentation/x86/boot.txt for details no bzImage on-disk and
@@ -293,6 +294,17 @@ bool load_bzimage(struct kvm *kvm, int fd_kernel,memcpy (p, kernel_cmdline, cmdline_size -1 ); } +if (!kvm->cfg.arch.vidmode) + vidmode =-1 ; + +/* vidmode should be either specified or set by default */ +if (kvm->cfg.vnc || kvm->cfg.sdl) { +if (vidmode ==-1 ) + vidmode =0x312 ; + }else { + vidmode =0 ; + } + kern_boot =guest_real_to_host (kvm,BOOT_LOADER_SELECTOR ,0x00 ); kern_boot->hdr.cmd_line_ptr =BOOT_CMDLINE_OFFSET ;
Signature · 1 line
1.8.0
Pekka Enberg
AppliedQuoted 5 lines · Will Deacon
From: Marc Zyngier <[email protected]>
A bug in the KVM GIC init code set the priority mask to the highest possible value, while the reset value should be zero.
Quoted 8 lines
Now that the kernel bug is fixed, kvm-tool must properly configure its GIC CPU interface in order to receive the boot IPI. Just set the
GICC_PMRregister to the maximum value (0xff), and it "just works".Cc Pekka Enberg <[email protected]>Signed-off-by Marc Zyngier <[email protected]>[will: added #define for PMR offset]Signed-off-by Will Deacon <[email protected]>
Applied all three patches, thanks Will!