KVM patches (SMM implementation) for 2015-07-06
The following changes since commit 261ccf426a6df854ba398be92413476919dd67f9:
Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20150706' into staging (2015-07-06 11:04:54 +0100)
are available in the git repository at:
git://github.com/bonzini/qemu.git tags/for-upstream-smm
for you to fetch changes up to 1a685f55a5a23c7644c6f5ce51285cfbe3f7ca96:
pc: add SMM property (2015-07-06 14:47:07 +0200)
----------------------------------------------------------------
This series implements KVM support for SMM, and lets you enable/disable it through the "smm" property of x86 machine types.
----------------------------------------------------------------
Same as previously posted.
Alexey Kardashevskiy (1):
linux-headers: Update to 4.2-rc1
Andrew Jones (1):
kvm-all: put kvm_mem_flags to more work
Paolo Bonzini (11):
piix4/ich9: do not raise SMI on ACPI enable/disable commands
target-i386: add support for SMBASE MSR and SMIs
kvm-all: remove useless typedef
kvm-all: move internal types to kvm_int.h
kvm-all: make KVM's memory listener more generic
kvm-all: add support for multiple address spaces
kvm-all: kvm_irqchip_create is not expected to fail
target-i386: register a separate KVM address space including SMRAM regions
pc_piix: rename kvm_enabled to smm_enabled
ich9: add smm_enabled field and arguments
pc: add SMM property
hw/acpi/ich9.c | 5 +- hw/acpi/piix4.c | 13 +- hw/i386/pc.c | 51 +++++ hw/i386/pc_piix.c | 7 +- hw/i386/pc_q35.c | 6 +- hw/isa/lpc_ich9.c | 9 +- include/hw/acpi/ich9.h | 3 +- include/hw/i386/ich9.h | 2 +- include/hw/i386/pc.h | 5 +- include/standard-headers/linux/input.h | 10 +- include/standard-headers/linux/virtio_balloon.h | 1 + include/standard-headers/linux/virtio_gpu.h | 2 + include/sysemu/kvm_int.h | 39 ++++ kvm-all.c | 243 ++++++++++++------------ linux-headers/asm-x86/hyperv.h | 11 ++ linux-headers/linux/kvm.h | 2 +- linux-headers/linux/vfio.h | 102 +++++++++- linux-headers/linux/virtio_pci.h | 192 ------------------- target-i386/cpu.h | 1 + target-i386/kvm.c | 139 +++++++++++++- 20 files changed, 502 insertions(+), 341 deletions(-) create mode 100644 include/sysemu/kvm_int.h delete mode 100644 linux-headers/linux/virtio_pci.h
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 03/13] target-i386: add support for SMBASE MSR and SMIs
Apart from the MSR, the smi field of struct kvm_vcpu_events has to be translated into the corresponding CPUX86State fields. Also, memory transaction flags depend on SMM state, so pull it from struct kvm_run on every exit from KVM to userspace.
--- target-i386/cpu.h | 1 + target-i386/kvm.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 90 insertions(+), 9 deletions(-)
target-i386/cpu.h +1 -0
@@ -314,6 +314,7 @@#define MSR_P6_PERFCTR0 0xc1 +#define MSR_IA32_SMBASE 0x9e#define MSR_MTRRcap 0xfe#define MSR_MTRRcap_VCNT 8#define MSR_MTRRcap_FIXRANGE_SUPPORT (1 << 8)
target-i386/kvm.c +89 -9
176 lines not on this page · raw message
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 01/13] linux-headers: Update to 4.2-rc1
In reply to Paolo BonziniFrom: Alexey Kardashevskiy <[email protected]>
This updates linux-headers against master 4.2-rc1 (commit d770e558e21961ad6cfdf0ff7df0eb5d7d4f0754). This is the result of ./scripts/update-linux-headers.sh work.
--- include/standard-headers/linux/input.h | 10 +- include/standard-headers/linux/virtio_balloon.h | 1 + include/standard-headers/linux/virtio_gpu.h | 2 + linux-headers/asm-x86/hyperv.h | 11 ++ linux-headers/linux/kvm.h | 2 +- linux-headers/linux/vfio.h | 102 ++++++++++++- linux-headers/linux/virtio_pci.h | 192 ------------------------ 7 files changed, 121 insertions(+), 199 deletions(-) delete mode 100644 linux-headers/linux/virtio_pci.h
include/standard-headers/linux/input.h +8 -2
@@ -367,7 +367,8 @@ struct input_keymap_entry {#define KEY_MSDOS 151#define KEY_COFFEE 152/* AL Terminal Lock/Screensaver */ #define KEY_SCREENLOCK KEY_COFFEE -#define KEY_DIRECTION 153 +#define KEY_ROTATE_DISPLAY 153/* Display orientation for e.g. tablets */ +#define KEY_DIRECTION KEY_ROTATE_DISPLAY#define KEY_CYCLEWINDOWS 154#define KEY_MAIL 155#define KEY_BOOKMARKS 156/* AC Bookmarks */
@@ -700,6 +701,10 @@ struct input_keymap_entry {#define KEY_NUMERIC_9 0x209#define KEY_NUMERIC_STAR 0x20a#define KEY_NUMERIC_POUND 0x20b +#define KEY_NUMERIC_A 0x20c/* Phone key A - HUT Telephony 0xb9 */ +#define KEY_NUMERIC_B 0x20d +#define KEY_NUMERIC_C 0x20e +#define KEY_NUMERIC_D 0x20f#define KEY_CAMERA_FOCUS 0x210#define KEY_WPS_BUTTON 0x211/* WiFi Protected Setup key */
@@ -971,7 +976,8 @@ struct input_keymap_entry {*/ #define MT_TOOL_FINGER 0#define MT_TOOL_PEN 1 -#define MT_TOOL_MAX 1 +#define MT_TOOL_PALM 2 +#define MT_TOOL_MAX 2/* * Values describing the status of a force-feedback effect
include/standard-headers/linux/virtio_balloon.h +1 -0
@@ -26,6 +26,7 @@* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include "standard-headers/linux/types.h" +#include "standard-headers/linux/virtio_types.h" #include "standard-headers/linux/virtio_ids.h" #include "standard-headers/linux/virtio_config.h"
include/standard-headers/linux/virtio_gpu.h +2 -0
@@ -38,6 +38,8 @@#ifndef VIRTIO_GPU_HW_H #define VIRTIO_GPU_HW_H +#include "standard-headers/linux/types.h" +enum virtio_gpu_ctrl_type { VIRTIO_GPU_UNDEFINED = 0,
linux-headers/asm-x86/hyperv.h +11 -0
@@ -199,6 +199,17 @@#define HV_X64_MSR_STIMER3_CONFIG 0x400000B6#define HV_X64_MSR_STIMER3_COUNT 0x400000B7 +/* Hyper-V guest crash notification MSR's */ +#define HV_X64_MSR_CRASH_P0 0x40000100 +#define HV_X64_MSR_CRASH_P1 0x40000101 +#define HV_X64_MSR_CRASH_P2 0x40000102 +#define HV_X64_MSR_CRASH_P3 0x40000103 +#define HV_X64_MSR_CRASH_P4 0x40000104 +#define HV_X64_MSR_CRASH_CTL 0x40000105 +#define HV_X64_MSR_CRASH_CTL_NOTIFY (1ULL << 63) +#define HV_X64_MSR_CRASH_PARAMS \ + (1 + (HV_X64_MSR_CRASH_P4 - HV_X64_MSR_CRASH_P0)) +#define HV_X64_MSR_HYPERCALL_ENABLE 0x00000001#define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT 12#define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_MASK \
linux-headers/linux/kvm.h +1 -1
@@ -897,7 +897,7 @@ struct kvm_xen_hvm_config {* * KVM_IRQFD_FLAG_RESAMPLE indicates resamplefd is valid and specifies * the irqfd to operate in resampling mode for level triggered interrupt -* emlation. See Documentation/virtual/kvm/api.txt. +* emulation. See Documentation/virtual/kvm/api.txt. */ #define KVM_IRQFD_FLAG_RESAMPLE (1 << 1)
linux-headers/linux/vfio.h +98 -4
145 lines not on this page · raw message
linux-headers/linux/virtio_pci.h deleted +0 -192
192 lines not on this page · raw message
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 04/13] kvm-all: put kvm_mem_flags to more work
In reply to Paolo BonziniFrom: Andrew Jones <[email protected]>
Currently kvm_mem_flags just translates bools to bits, let's make it also determine the bools first. This avoids its parameter list growing each time we add a flag.
--- kvm-all.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-)
kvm-all.c +20 -22
@@ -291,45 +291,47 @@ err:* dirty pages logging control */ -static int kvm_mem_flags (KVMState *s,bool log_dirty,bool readonly) +static int kvm_mem_flags (MemoryRegion *mr) { +bool readonly = mr->readonly ||memory_region_is_romd (mr);int flags =0 ; - flags = log_dirty ?KVM_MEM_LOG_DIRTY_PAGES :0 ; + +if (memory_region_get_dirty_log_mask (mr) !=0 ) { + flags |=KVM_MEM_LOG_DIRTY_PAGES ; + }if (readonly && kvm_readonly_mem_allowed) { flags |=KVM_MEM_READONLY ; }return flags; } -static int kvm_slot_dirty_pages_log_change (KVMSlot *mem,bool log_dirty) +static int kvm_slot_update_flags (KVMSlot *mem,MemoryRegion *mr) {KVMState *s = kvm_state; -int flags, mask =KVM_MEM_LOG_DIRTY_PAGES ;int old_flags; old_flags = mem->flags; - - flags = (mem->flags & ~mask) |kvm_mem_flags (s, log_dirty, false); - mem->flags = flags; + mem->flags =kvm_mem_flags (mr);/* If nothing changed effectively, no need to issue ioctl */ -if (flags == old_flags) { +if (mem->flags == old_flags) {return 0 ; }return kvm_set_user_memory_region (s, mem); } -static int kvm_dirty_pages_log_change (hwaddr phys_addr, -ram_addr_t size,bool log_dirty) +static int kvm_section_update_flags (MemoryRegionSection *section) {KVMState *s = kvm_state; +hwaddr phys_addr = section->offset_within_address_space; +ram_addr_t size =int128_get64 (section->size);KVMSlot *mem =kvm_lookup_matching_slot (s, phys_addr, phys_addr + size);if (mem ==NULL ) {return 0 ; }else { -return kvm_slot_dirty_pages_log_change (mem, log_dirty); +return kvm_slot_update_flags (mem, section->mr); } }
@@ -343,8 +345,7 @@ static void kvm_log_start(MemoryListener *listener,return ; } - r =kvm_dirty_pages_log_change (section->offset_within_address_space, -int128_get64 (section->size), true); + r =kvm_section_update_flags (section);if (r <0 ) {abort (); }
@@ -360,8 +361,7 @@ static void kvm_log_stop(MemoryListener *listener,return ; } - r =kvm_dirty_pages_log_change (section->offset_within_address_space, -int128_get64 (section->size), false); + r =kvm_section_update_flags (section);if (r <0 ) {abort (); }
@@ -638,9 +638,7 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, bool add)KVMSlot *mem, old;int err;MemoryRegion *mr = section->mr; -bool log_dirty =memory_region_get_dirty_log_mask (mr) !=0 ;bool writeable = !mr->readonly && !mr->rom_device; -bool readonly_flag = mr->readonly ||memory_region_is_romd (mr);hwaddr start_addr = section->offset_within_address_space;ram_addr_t size =int128_get64 (section->size);void *ram =NULL ;
@@ -684,7 +682,7 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, bool add) (ram - start_addr == mem->ram - mem->start_addr)) {/* The new slot fits into the existing one and comes with * identical parameters - update flags and done. */ -kvm_slot_dirty_pages_log_change (mem, log_dirty); +kvm_slot_update_flags (mem, mr);return ; }
@@ -717,7 +715,7 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, bool add) mem->memory_size = old.memory_size; mem->start_addr = old.start_addr; mem->ram = old.ram; - mem->flags =kvm_mem_flags (s, log_dirty, readonly_flag); + mem->flags =kvm_mem_flags (mr); err =kvm_set_user_memory_region (s, mem);if (err) {
@@ -738,7 +736,7 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, bool add) mem->memory_size = start_addr - old.start_addr; mem->start_addr = old.start_addr; mem->ram = old.ram; - mem->flags =kvm_mem_flags (s, log_dirty, readonly_flag); + mem->flags =kvm_mem_flags (mr); err =kvm_set_user_memory_region (s, mem);if (err) {
@@ -762,7 +760,7 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, bool add) size_delta = mem->start_addr - old.start_addr; mem->memory_size = old.memory_size - size_delta; mem->ram = old.ram + size_delta; - mem->flags =kvm_mem_flags (s, log_dirty, readonly_flag); + mem->flags =kvm_mem_flags (mr); err =kvm_set_user_memory_region (s, mem);if (err) {
@@ -784,7 +782,7 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, bool add) mem->memory_size = size; mem->start_addr = start_addr; mem->ram = ram; - mem->flags =kvm_mem_flags (s, log_dirty, readonly_flag); + mem->flags =kvm_mem_flags (mr); err =kvm_set_user_memory_region (s, mem);if (err) {
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 02/13] piix4/ich9: do not raise SMI on ACPI enable/disable commands
In reply to Paolo BonziniThese commands are handled entirely by QEMU. Do not raise an SMI when they happen, because Windows (at least 2008r2) expects these commands to work and (depending on the value of APMC_EN at startup) the firmware might not have installed an SMI handler.
When this happens (e.g. the kernel supports SMIs, or you are using TCG, but you have used "-machine smm=off") RIP is moved to 0x38000 where there is no code to execute.
--- hw/acpi/piix4.c | 3 +++ hw/isa/lpc_ich9.c | 3 +++ 2 files changed, 6 insertions(+)
hw/acpi/piix4.c +3 -0
@@ -112,6 +112,9 @@ static void apm_ctrl_changed(uint32_t val, void *arg)/* ACPI specs 3.0, 4.7.2.5 */ acpi_pm1_cnt_update (&s->ar, val ==ACPI_ENABLE , val ==ACPI_DISABLE ); +if (val ==ACPI_ENABLE || val ==ACPI_DISABLE ) { +return ; + }if (d->config[0x5b ] & (1 <<1 )) {if (s->smi_irq) {
hw/isa/lpc_ich9.c +3 -0
@@ -375,6 +375,9 @@ static void ich9_apm_ctrl_changed(uint32_t val, void *arg)acpi_pm1_cnt_update (&lpc->pm.acpi_regs, val ==ICH9_APM_ACPI_ENABLE , val ==ICH9_APM_ACPI_DISABLE ); +if (val ==ICH9_APM_ACPI_ENABLE || val ==ICH9_APM_ACPI_DISABLE ) { +return ; + }/* SMI_EN = PMBASE + 30. SMI control and enable register */ if (lpc->pm.smi_en &ICH9_PMIO_SMI_EN_APMC_EN ) {
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 05/13] kvm-all: remove useless typedef
In reply to Paolo Bonzini--- kvm-all.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
kvm-all.c +1 -3
@@ -69,8 +69,6 @@ typedef struct KVMSlotint flags; } KVMSlot; -typedef struct kvm_dirty_log KVMDirtyLog ; -struct KVMState {AccelState parent_obj;
@@ -393,7 +391,7 @@ static int kvm_physical_sync_dirty_bitmap(MemoryRegionSection *section) {KVMState *s = kvm_state;unsigned long size, allocated_size =0 ; -KVMDirtyLog d = {}; +struct kvm_dirty_log d = {};KVMSlot *mem;int ret =0 ;hwaddr start_addr = section->offset_within_address_space;
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 09/13] kvm-all: kvm_irqchip_create is not expected to fail
In reply to Paolo BonziniKVM_CREATE_IRQCHIP should never fail, and so should its userspace wrapper kvm_irqchip_create. The function does not do anything if the irqchip capability is not available, as is the case for PPC.
With this patch, kvm_arch_init can allocate memory and it will not be leaked.
--- kvm-all.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-)
kvm-all.c +18 -17
@@ -1342,27 +1342,31 @@ int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq) false); } -static int kvm_irqchip_create (MachineState *machine,KVMState *s) +static void kvm_irqchip_create (MachineState *machine,KVMState *s) {int ret; -if (!machine_kernel_irqchip_allowed (machine) || - (!kvm_check_extension (s,KVM_CAP_IRQCHIP ) && - (kvm_vm_enable_cap (s,KVM_CAP_S390_IRQCHIP ,0 ) <0 ))) { -return 0 ; +if (kvm_check_extension (s,KVM_CAP_IRQCHIP )) { + ; + }else if (kvm_check_extension (s,KVM_CAP_S390_IRQCHIP )) { + ret =kvm_vm_enable_cap (s,KVM_CAP_S390_IRQCHIP ,0 ); +if (ret <0 ) { +fprintf (stderr,"Enable kernel irqchip failed: %s\n" ,strerror (-ret)); +exit (1 ); + } + }else { +return ; }/* First probe and see if there's a arch-specific hook to create the * in-kernel irqchip for us */ ret =kvm_arch_irqchip_create (s); -if (ret <0 ) { -return ret; - }else if (ret ==0 ) { +if (ret ==0 ) { ret =kvm_vm_ioctl (s,KVM_CREATE_IRQCHIP ); -if (ret <0 ) { -fprintf (stderr,"Create kernel irqchip failed\n" ); -return ret; - } + } +if (ret <0 ) { +fprintf (stderr,"Create kernel irqchip failed: %s\n" ,strerror (-ret)); +exit (1 ); } kvm_kernel_irqchip = true;
@@ -1373,8 +1377,6 @@ static int kvm_irqchip_create(MachineState *machine, KVMState *s) kvm_halt_in_kernel_allowed = true;kvm_init_irq_routing (s); - -return 0 ; }/* Find number of supported CPUs using the recommended
@@ -1591,9 +1593,8 @@ static int kvm_init(MachineState *ms) goto err; } - ret =kvm_irqchip_create (ms, s); -if (ret <0 ) { - goto err; +if (machine_kernel_irqchip_allowed (ms)) { +kvm_irqchip_create (ms, s); } kvm_state = s;
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 06/13] kvm-all: move internal types to kvm_int.h
In reply to Paolo Bonzinii386 code will have to define a different KVMMemoryListener. Create an internal header so that KVMSlot is not exposed outside.
--- include/sysemu/kvm_int.h | 30 ++++++++++++++++++++++++++++++ kvm-all.c | 18 +----------------- 2 files changed, 31 insertions(+), 17 deletions(-) create mode 100644 include/sysemu/kvm_int.h
include/sysemu/kvm_int.h new file +30 -0
@@ -0,0 +1,30 @@ +/* +* Internal definitions for a target's KVM support +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +* +*/ + +#ifndef QEMU_KVM_INT_H +#define QEMU_KVM_INT_H + +#include "sysemu/sysemu.h" +#include "sysemu/accel.h" +#include "sysemu/kvm.h" + +typedef struct KVMSlot +{ +hwaddr start_addr; +ram_addr_t memory_size; +void *ram; +int slot; +int flags; +}KVMSlot ; + +#define TYPE_KVM_ACCEL ACCEL_CLASS_NAME("kvm") + +#define KVM_STATE (obj) \ + OBJECT_CHECK(KVMState, (obj), TYPE_KVM_ACCEL) + +#endif
kvm-all.c +1 -17
@@ -24,13 +24,11 @@#include "qemu/atomic.h" #include "qemu/option.h" #include "qemu/config-file.h" -#include "sysemu/sysemu.h" -#include "sysemu/accel.h" #include "hw/hw.h" #include "hw/pci/msi.h" #include "hw/s390x/adapter.h" #include "exec/gdbstub.h" -#include "sysemu/kvm.h" +#include "sysemu/kvm_int.h" #include "qemu/bswap.h" #include "exec/memory.h" #include "exec/ram_addr.h"
@@ -60,15 +58,6 @@#define KVM_MSI_HASHTAB_SIZE 256 -typedef struct KVMSlot -{ -hwaddr start_addr; -ram_addr_t memory_size; -void *ram; -int slot; -int flags; -}KVMSlot ; -struct KVMState {AccelState parent_obj;
@@ -106,11 +95,6 @@ struct KVMState#endif }; -#define TYPE_KVM_ACCEL ACCEL_CLASS_NAME("kvm") - -#define KVM_STATE (obj) \ - OBJECT_CHECK(KVMState, (obj), TYPE_KVM_ACCEL) -KVMState *kvm_state;bool kvm_kernel_irqchip;bool kvm_async_interrupts_allowed;
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 08/13] kvm-all: add support for multiple address spaces
In reply to Paolo BonziniMake kvm_memory_listener_register public, and assign a kernel address space id to each KVMMemoryListener.
--- include/sysemu/kvm_int.h | 4 ++++ kvm-all.c | 13 ++++++------- 2 files changed, 10 insertions(+), 7 deletions(-)
include/sysemu/kvm_int.h +4 -0
@@ -25,6 +25,7 @@ typedef struct KVMSlottypedef struct KVMMemoryListener {MemoryListener listener;KVMSlot *slots; +int as_id; }KVMMemoryListener ;#define TYPE_KVM_ACCEL ACCEL_CLASS_NAME("kvm")
@@ -32,4 +33,7 @@ typedef struct KVMMemoryListener {#define KVM_STATE (obj) \ OBJECT_CHECK(KVMState, (obj), TYPE_KVM_ACCEL) +void kvm_memory_listener_register (KVMState *s,KVMMemoryListener *kml, +AddressSpace *as,int as_id); +#endif
kvm-all.c +6 -7
@@ -218,7 +218,7 @@ static int kvm_set_user_memory_region(KVMMemoryListener *kml, KVMSlot *slot)KVMState *s = kvm_state;struct kvm_userspace_memory_region mem; - mem.slot = slot->slot; + mem.slot = slot->slot | (kml->as_id <<16 ); mem.guest_phys_addr = slot->start_addr; mem.userspace_addr = (unsigned long )slot->ram; mem.flags = slot->flags;
@@ -420,8 +420,7 @@ static int kvm_physical_sync_dirty_bitmap(KVMMemoryListener *kml, allocated_size = size;memset (d.dirty_bitmap,0 , allocated_size); - d.slot = mem->slot; - + d.slot = mem->slot | (kml->as_id <<16 );if (kvm_vm_ioctl (s,KVM_GET_DIRTY_LOG , &d) ==-1 ) {DPRINTF ("ioctl failed %d\n" , errno); ret =-1 ;
@@ -884,13 +883,13 @@ static void kvm_io_ioeventfd_del(MemoryListener *listener, } } -static void kvm_memory_listener_register (KVMState *s, -KVMMemoryListener *kml, -AddressSpace *as) +void kvm_memory_listener_register (KVMState *s,KVMMemoryListener *kml, +AddressSpace *as,int as_id) {int i; kml->slots =g_malloc0 (s->nr_slots *sizeof (KVMSlot)); + kml->as_id = as_id;for (i =0 ; i < s->nr_slots; i++) { kml->slots[i].slot = i;
@@ -1605,7 +1604,7 @@ static int kvm_init(MachineState *ms) s->memory_listener.listener.coalesced_mmio_del = kvm_uncoalesce_mmio_region;kvm_memory_listener_register (s, &s->memory_listener, - &address_space_memory); + &address_space_memory,0 );memory_listener_register (&kvm_io_listener, &address_space_io);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 07/13] kvm-all: make KVM's memory listener more generic
In reply to Paolo BonziniNo semantic change, but s->slots moves into a new struct KVMMemoryListener. KVM's memory listener becomes a member of struct KVMState, and becomes of type KVMMemoryListener.
--- include/sysemu/kvm_int.h | 5 ++ kvm-all.c | 151 ++++++++++++++++++++++++++++------------------- 2 files changed, 94 insertions(+), 62 deletions(-)
include/sysemu/kvm_int.h +5 -0
@@ -22,6 +22,11 @@ typedef struct KVMSlotint flags; } KVMSlot; +typedef struct KVMMemoryListener { +MemoryListener listener; +KVMSlot *slots; +}KVMMemoryListener ; +#define TYPE_KVM_ACCEL ACCEL_CLASS_NAME("kvm")#define KVM_STATE (obj) \
kvm-all.c +89 -62
404 lines not on this page · raw message
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 11/13] pc_piix: rename kvm_enabled to smm_enabled
In reply to Paolo BonziniWe will enable SMM even if KVM is in use. Rename the field and arguments.
--- hw/acpi/piix4.c | 10 +++++----- hw/i386/pc_piix.c | 2 +- include/hw/i386/pc.h | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-)
hw/acpi/piix4.c +5 -5
@@ -72,7 +72,7 @@ typedef struct PIIX4PMState {qemu_irq irq;qemu_irq smi_irq; -int kvm_enabled; +int smm_enabled;Notifier machine_ready;Notifier powerdown_notifier;
@@ -322,7 +322,7 @@ static void piix4_reset(void *opaque) pci_conf[0x40 ] =0x01 ;/* PM io base read only bit */ pci_conf[0x80 ] =0 ; -if (s->kvm_enabled) { +if (!s->smm_enabled) {/* Mark SMM as already inited (until KVM supports SMM). */ pci_conf[0x5B ] =0x02 ; }
@@ -453,7 +453,7 @@ static void piix4_pm_realize(PCIDevice *dev, Error **errp)/* APM */ apm_init (dev, &s->apm, apm_ctrl_changed, s); -if (s->kvm_enabled) { +if (!s->smm_enabled) {/* Mark SMM as already inited to prevent SMM from running. KVM does not * support SMM mode. */ pci_conf[0x5B ] =0x02 ;
@@ -504,7 +504,7 @@ Object *piix4_pm_find(void)I2CBus *piix4_pm_init (PCIBus *bus,int devfn,uint32_t smb_io_base,qemu_irq sci_irq,qemu_irq smi_irq, -int kvm_enabled,DeviceState **piix4_pm) +int smm_enabled,DeviceState **piix4_pm) {DeviceState *dev;PIIX4PMState *s;
@@ -518,7 +518,7 @@ I2CBus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base, s =PIIX4_PM (dev); s->irq = sci_irq; s->smi_irq = smi_irq; - s->kvm_enabled = kvm_enabled; + s->smm_enabled = smm_enabled;if (xen_enabled ()) { s->use_acpi_pci_hotplug = false; }
hw/i386/pc_piix.c +1 -1
@@ -287,7 +287,7 @@ static void pc_init1(MachineState *machine)/* TODO: Populate SPD eeprom data. */ smbus =piix4_pm_init (pci_bus, piix3_devfn +3 ,0xb100 , gsi[9 ], smi_irq, -kvm_enabled (), &piix4_pm); + !kvm_enabled (), &piix4_pm);smbus_eeprom_init (smbus,8 ,NULL ,0 ); object_property_add_link(OBJECT(machine), PC_MACHINE_ACPI_DEVICE_PROP,
include/hw/i386/pc.h +1 -1
@@ -214,7 +214,7 @@ void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name);I2CBus *piix4_pm_init (PCIBus *bus,int devfn,uint32_t smb_io_base,qemu_irq sci_irq,qemu_irq smi_irq, -int kvm_enabled,DeviceState **piix4_pm); +int smm_enabled,DeviceState **piix4_pm);void piix4_smbus_register_device (SMBusDevice *dev,uint8_t addr);/* hpet.c */
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 12/13] ich9: add smm_enabled field and arguments
In reply to Paolo BonziniQ35's ACPI device is hard-coding SMM availability to KVM. Place the logic where the board is created instead, so that it will be possible to override it.
--- hw/acpi/ich9.c | 5 +++-- hw/i386/pc_q35.c | 2 +- hw/isa/lpc_ich9.c | 6 ++++-- include/hw/acpi/ich9.h | 3 ++- include/hw/i386/ich9.h | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-)
hw/acpi/ich9.c +3 -2
@@ -192,7 +192,7 @@ static void pm_reset(void *opaque)acpi_pm_tmr_reset (&pm->acpi_regs);acpi_gpe_reset (&pm->acpi_regs); -if (kvm_enabled ()) { +if (!pm->smm_enabled) {/* Mark SMM as already inited to prevent SMM from running. KVM does not * support SMM mode. */ pm->smi_en |=ICH9_PMIO_SMI_EN_APMC_EN ;
@@ -209,7 +209,7 @@ static void pm_powerdown_req(Notifier *n, void *opaque)acpi_pm1_evt_power_down (&pm->acpi_regs); } -void ich9_pm_init (PCIDevice *lpc_pci,ICH9LPCPMRegs *pm, +void ich9_pm_init (PCIDevice *lpc_pci,ICH9LPCPMRegs *pm,bool smm_enabled,qemu_irq sci_irq) {memory_region_init (&pm->io,OBJECT (lpc_pci),"ich9-pm" ,ICH9_PMIO_SIZE );
@@ -231,6 +231,7 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm, "acpi-smi", 8);memory_region_add_subregion (&pm->io,ICH9_PMIO_SMI_EN , &pm->io_smi); + pm->smm_enabled = smm_enabled; pm->irq = sci_irq;qemu_register_reset (pm_reset, pm); pm->powerdown_notifier.notify = pm_powerdown_req;
hw/i386/pc_q35.c +1 -1
@@ -253,7 +253,7 @@ static void pc_q35_init(MachineState *machine) (pc_machine->vmport != ON_OFF_AUTO_ON), 0xff0104);/* connect pm stuff to lpc */ -ich9_lpc_pm_init (lpc); +ich9_lpc_pm_init (lpc, !kvm_enabled ());/* ahci and SATA device, for q35 1 ahci controller is built-in */ ahci = pci_create_simple_multifunction(host_bus,
hw/isa/lpc_ich9.c +4 -2
@@ -357,11 +357,13 @@ static void ich9_set_sci(void *opaque, int irq_num, int level) } } -void ich9_lpc_pm_init (PCIDevice *lpc_pci) +void ich9_lpc_pm_init (PCIDevice *lpc_pci,bool smm_enabled) {ICH9LPCState *lpc =ICH9_LPC_DEVICE (lpc_pci); +qemu_irq sci_irq; -ich9_pm_init (lpc_pci, &lpc->pm,qemu_allocate_irq (ich9_set_sci, lpc,0 )); + sci_irq =qemu_allocate_irq (ich9_set_sci, lpc,0 ); +ich9_pm_init (lpc_pci, &lpc->pm, smm_enabled, sci_irq);ich9_lpc_reset (&lpc->d.qdev); }
include/hw/acpi/ich9.h +2 -1
@@ -54,10 +54,11 @@ typedef struct ICH9LPCPMRegs {uint8_t disable_s3;uint8_t disable_s4;uint8_t s4_val; +uint8_t smm_enabled; } ICH9LPCPMRegs;void ich9_pm_init (PCIDevice *lpc_pci,ICH9LPCPMRegs *pm, -qemu_irq sci_irq); +bool smm_enabled,qemu_irq sci_irq);void ich9_pm_iospace_update (ICH9LPCPMRegs *pm,uint32_t pm_io_base);extern const VMStateDescription vmstate_ich9_pm;
include/hw/i386/ich9.h +1 -1
@@ -17,7 +17,7 @@void ich9_lpc_set_irq (void *opaque,int irq_num,int level);int ich9_lpc_map_irq (PCIDevice *pci_dev,int intx);PCIINTxRoute ich9_route_intx_pin_to_irq (void *opaque,int pirq_pin); -void ich9_lpc_pm_init (PCIDevice *pci_lpc); +void ich9_lpc_pm_init (PCIDevice *pci_lpc,bool smm_enabled);I2CBus *ich9_smb_init (PCIBus *bus,int devfn,uint32_t smb_io_base);#define ICH9_CC_SIZE (16 * 1024)/* 16KB */
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 13/13] pc: add SMM property
In reply to Paolo BonziniThe property can take values on, off or auto. The default is "off" for KVM and pre-2.4 machines, otherwise "auto" (which makes it available on TCG or on new-enough kernels).
--- hw/i386/pc.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ hw/i386/pc_piix.c | 7 ++++++- hw/i386/pc_q35.c | 6 +++++- include/hw/i386/pc.h | 3 +++ 4 files changed, 65 insertions(+), 2 deletions(-)
hw/i386/pc.c +51 -0
@@ -1768,6 +1768,48 @@ static void pc_machine_set_vmport(Object *obj, Visitor *v, void *opaque,visit_type_OnOffAuto (v, &pcms->vmport, name, errp); } +bool pc_machine_is_smm_enabled (PCMachineState *pcms) +{ +bool smm_available = false; + +if (pcms->smm ==ON_OFF_AUTO_OFF ) { +return false; + } + +if (tcg_enabled () ||qtest_enabled ()) { + smm_available = true; + }else if (kvm_enabled ()) { + smm_available =kvm_check_extension (kvm_state,KVM_CAP_X86_SMM ); + } + +if (smm_available) { +return true; + } + +if (pcms->smm ==ON_OFF_AUTO_ON ) { +error_report ("System Management Mode not supported by this hypervisor." ); +exit (1 ); + } +return false; +} + +static void pc_machine_get_smm (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +PCMachineState *pcms =PC_MACHINE (obj); +OnOffAuto smm = pcms->smm; + +visit_type_OnOffAuto (v, &smm, name, errp); +} + +static void pc_machine_set_smm (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +PCMachineState *pcms =PC_MACHINE (obj); + +visit_type_OnOffAuto (v, &pcms->smm, name, errp); +} +static bool pc_machine_get_aligned_dimm (Object *obj,Error **errp) {PCMachineState *pcms =PC_MACHINE (obj);
@@ -1792,6 +1834,15 @@ static void pc_machine_initfn(Object *obj)"Maximum ram below the 4G boundary (32bit boundary)" , NULL); + pcms->smm =ON_OFF_AUTO_AUTO ; +object_property_add (obj,PC_MACHINE_SMM ,"OnOffAuto" , + pc_machine_get_smm, + pc_machine_set_smm, +NULL ,NULL ,NULL ); +object_property_set_description (obj,PC_MACHINE_SMM , +"Enable SMM (pc & q35)" , +NULL ); + pcms->vmport =ON_OFF_AUTO_AUTO ; object_property_add(obj, PC_MACHINE_VMPORT, "OnOffAuto", pc_machine_get_vmport,
hw/i386/pc_piix.c +6 -1
@@ -287,7 +287,8 @@ static void pc_init1(MachineState *machine)/* TODO: Populate SPD eeprom data. */ smbus =piix4_pm_init (pci_bus, piix3_devfn +3 ,0xb100 , gsi[9 ], smi_irq, - !kvm_enabled (), &piix4_pm); +pc_machine_is_smm_enabled (pc_machine), + &piix4_pm);smbus_eeprom_init (smbus,8 ,NULL ,0 ); object_property_add_link(OBJECT(machine), PC_MACHINE_ACPI_DEVICE_PROP,
@@ -306,7 +307,11 @@ static void pc_init1(MachineState *machine)static void pc_compat_2_3 (MachineState *machine) { +PCMachineState *pcms =PC_MACHINE (machine);savevm_skip_section_footers (); +if (kvm_enabled ()) { + pcms->smm =ON_OFF_AUTO_OFF ; + } }static void pc_compat_2_2 (MachineState *machine)
hw/i386/pc_q35.c +5 -1
@@ -253,7 +253,7 @@ static void pc_q35_init(MachineState *machine) (pc_machine->vmport != ON_OFF_AUTO_ON), 0xff0104);/* connect pm stuff to lpc */ -ich9_lpc_pm_init (lpc, !kvm_enabled ()); +ich9_lpc_pm_init (lpc,pc_machine_is_smm_enabled (pc_machine));/* ahci and SATA device, for q35 1 ahci controller is built-in */ ahci = pci_create_simple_multifunction(host_bus,
@@ -290,7 +290,11 @@ static void pc_q35_init(MachineState *machine)static void pc_compat_2_3 (MachineState *machine) { +PCMachineState *pcms =PC_MACHINE (machine);savevm_skip_section_footers (); +if (kvm_enabled ()) { + pcms->smm =ON_OFF_AUTO_OFF ; + } }static void pc_compat_2_2 (MachineState *machine)
include/hw/i386/pc.h +3 -0
@@ -37,6 +37,7 @@ struct PCMachineState {uint64_t max_ram_below_4g;OnOffAuto vmport; +OnOffAuto smm;bool enforce_aligned_dimm; };
@@ -44,6 +45,7 @@ struct PCMachineState {#define PC_MACHINE_MEMHP_REGION_SIZE "hotplug-memory-region-size"#define PC_MACHINE_MAX_RAM_BELOW_4G "max-ram-below-4g"#define PC_MACHINE_VMPORT "vmport" +#define PC_MACHINE_SMM "smm"#define PC_MACHINE_ENFORCE_ALIGNED_DIMM "enforce-aligned-dimm"/**
@@ -155,6 +157,7 @@ void i8042_setup_a20_line(ISADevice *dev, qemu_irq *a20_out);/* pc.c */ extern int fd_bootchk; +bool pc_machine_is_smm_enabled (PCMachineState *pcms);void pc_register_ferr_irq (qemu_irq irq);void pc_acpi_smi_interrupt (void *opaque,int irq,int level);
Signature · 1 line
1.8.3.1
[Qemu-devel] [PULL 10/13] target-i386: register a separate KVM address space including SMRAM regions
In reply to Paolo Bonzini--- target-i386/kvm.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-)
target-i386/kvm.c +40 -1
@@ -22,7 +22,7 @@#include "qemu-common.h" #include "sysemu/sysemu.h" -#include "sysemu/kvm.h" +#include "sysemu/kvm_int.h" #include "kvm_i386.h" #include "cpu.h" #include "exec/gdbstub.h"
@@ -845,6 +845,40 @@ static int kvm_get_supported_msrs(KVMState *s)return ret; } +static Notifier smram_machine_done; +static KVMMemoryListener smram_listener; +static AddressSpace smram_address_space; +static MemoryRegion smram_as_root; +static MemoryRegion smram_as_mem; + +static void register_smram_listener (Notifier *n,void *unused) +{ +MemoryRegion *smram = + (MemoryRegion *)object_resolve_path ("/machine/smram" ,NULL ); + +/* Outer container... */ +memory_region_init (&smram_as_root,OBJECT (kvm_state),"mem-container-smram" , ~0ull ); +memory_region_set_enabled (&smram_as_root, true); + +/* ... with two regions inside: normal system memory with low +* priority, and... +*/ +memory_region_init_alias (&smram_as_mem,OBJECT (kvm_state),"mem-smram" , +get_system_memory (),0 , ~0ull ); +memory_region_add_subregion_overlap (&smram_as_root,0 , &smram_as_mem,0 ); +memory_region_set_enabled (&smram_as_mem, true); + +if (smram) { +/* ... SMRAM with higher priority */ +memory_region_add_subregion_overlap (&smram_as_root,0 , smram,10 ); +memory_region_set_enabled (smram, true); + } + +address_space_init (&smram_address_space, &smram_as_root,"KVM-SMRAM" ); +kvm_memory_listener_register (kvm_state, &smram_listener, + &smram_address_space,1 ); +} +int kvm_arch_init (MachineState *ms,KVMState *s) {uint64_t identity_base =0xfffbc000 ;
@@ -903,6 +937,11 @@ int kvm_arch_init(MachineState *ms, KVMState *s)return ret; } } + +if (kvm_check_extension (s,KVM_CAP_X86_SMM )) { + smram_machine_done.notify = register_smram_listener; +qemu_add_machine_init_done_notifier (&smram_machine_done); + }return 0 ; }
Signature · 1 line
1.8.3.1