target-i386: SMM improvements and partial support under KVM
cover target-i386: SMM improvements and partial support under KVM
These patches implement almost everything that is needed for SMM support in OVMF and KVM. The only missing bit is support for SMRAM regions in KVM, but it need not block review of these ones, and possibly inclusion of the first 26.
There are many small parts in this patches, but I am posting them together because each small part alone adds very little.
Patch 1 comes from mst's pull request.
Patches 2-6 are target-i386 patches. They add support for memory attributes in target-i386, enabling the "secure" attribute whenever the CPU is in system management mode. They also fix two SMM bugs found while working on KVM support.
Patches 7-9 add support for secure access to parallel flash. If enabled, parallel flash behaves as ROM unless the "secure" memory transaction attribute is set.
Patches 10-12 are general infrastructure patches that didn't fit elsewhere. Note that patch 10 introduces new command-line syntax.
Patches 13-16 rewrite the SMRAM handling in TCG mode, so that the SMRAM setup is done just once using the memory API, and then enabled/disabled by the CPU without intervention from the chipset. The resulting chipset code is simpler and...
... patches 17-23 then rely on this to implement support for more q35 SMI features, in particular high SMRAM, TSEG and SMI_LOCK. This part was done almost entirely by Gerd.
Patches 24-26 are for q35 feature parity with PIIX4. They are from Laszlo and they are included just because they conflict with the next few.
Patches 27 and 28 implement KVM support for SMM. Note that this support is not yet upstream (will be in Linux 4.2); these patches will be rebased after the updated KVM headers are taken from kvm.git.
Patches 29-31 add a "-machine smm=on|off|auto" option (QOM property) that can be used to hide SMM or make it available on any accelerator. The compat gunk makes it available by default on TCG but not on KVM.
That's it. Go ahead and review.
Paolo
Gerd Hoffmann (6):
q35: fix ESMRAMC default
q35: add config space wmask for SMRAM and ESMRAMC
q35: implement SMRAM.D_LCK
q35: add test for SMRAM.D_LCK
q35: implement TSEG
ich9: implement SMI_LOCK
Jason Wang (1):
pc: add 2.4 machine types
Laszlo Ersek (3):
hw/acpi: acpi_pm1_cnt_init(): take "disable_s3" and "disable_s4" hw/acpi: move "etc/system-states" fw_cfg file from PIIX4 to core hw/acpi: piix4_pm_init(): take fw_cfg object no more
Paolo Bonzini (21):
target-i386: introduce cpu_get_mem_attrs
target-i386: Use correct memory attributes for memory accesses
target-i386: Use correct memory attributes for ioport accesses
target-i386: mask NMIs on entry to SMM
target-i386: set G=1 in SMM big real mode selectors
pflash_cfi01: change big-endian property to BIT type
pflash_cfi01: change to new-style MMIO accessors
pflash_cfi01: add secure property
vl: allow full-blown QemuOpts syntax for -global
qom: add object_property_add_const_link
vl: run "late" notifiers immediately
target-i386: create a separate AddressSpace for each CPU hw/i386: add a separate region that tracks the SMRAME bit
target-i386: use memory API to implement SMRAM hw/i386: remove smram_update
q35: implement high SMRAM
target-i386: add support for SMBASE MSR and SMIs
vga: disable chain4_alias if KVM supports SMRAM
pc_piix: rename kvm_enabled to smm_enabled
ich9: add smm_enabled field and arguments
pc: add SMM property
bsd-user/main.c | 4 - hw/acpi/core.c | 15 +- hw/acpi/ich9.c | 12 +- hw/acpi/piix4.c | 21 +-- hw/block/pflash_cfi01.c | 204 +++++++++++---------------- hw/display/vga.c | 8 +- hw/display/vga_int.h | 1 + hw/i386/pc.c | 72 +++++++--- hw/i386/pc_piix.c | 53 +++++-- hw/i386/pc_q35.c | 33 ++++- hw/isa/lpc_ich9.c | 23 ++- hw/isa/vt82c686.c | 2 +- hw/mips/mips_malta.c | 2 +- hw/pci-host/pam.c | 20 --- hw/pci-host/piix.c | 39 +++--- hw/pci-host/q35.c | 137 ++++++++++++++++-- include/exec/memattrs.h | 4 +- include/hw/acpi/acpi.h | 3 +- include/hw/acpi/ich9.h | 4 +- include/hw/i386/ich9.h | 8 +- include/hw/i386/pc.h | 7 +- include/hw/pci-host/pam.h | 4 - include/hw/pci-host/q35.h | 36 +++-- include/qom/object.h | 18 +++ include/sysemu/kvm.h | 1 + kvm-all.c | 5 + kvm-stub.c | 5 + linux-headers/asm-x86/kvm.h | 11 +- linux-headers/linux/kvm.h | 5 +- linux-user/main.c | 4 - qdev-monitor.c | 18 ++- qemu-options.hx | 7 +- qom/object.c | 16 +++ target-i386/Makefile.objs | 2 - target-i386/cpu-qom.h | 3 + target-i386/cpu.c | 43 ++++++ target-i386/cpu.h | 41 ++++-- target-i386/helper.c | 135 +++++++++++++++--- target-i386/helper.h | 12 +- target-i386/ioport-user.c | 60 -------- target-i386/kvm.c | 75 ++++++++-- target-i386/machine.c | 3 + target-i386/misc_helper.c | 59 ++++++-- target-i386/seg_helper.c | 12 +- target-i386/smm_helper.c | 331 +++++++++++++++++++++++--------------------- target-i386/svm_helper.c | 230 +++++++++++++++--------------- target-i386/translate.c | 12 +- tests/Makefile | 2 + tests/smram-test.c | 80 +++++++++++ vl.c | 6 + 50 files changed, 1220 insertions(+), 688 deletions(-) delete mode 100644 target-i386/ioport-user.c create mode 100644 tests/smram-test.c
Signature · 1 line
1.8.3.1
PATCH 1/31 pc: add 2.4 machine types
From: Jason Wang <[email protected]>
The following patches will limit the following things to legacy machine type:
- maximum number of virtqueues for virtio-pci were limited to 64
- auto msix bar size for virtio-net-pci were disabled by default
--- hw/i386/pc_piix.c | 29 +++++++++++++++++++++++++---- hw/i386/pc_q35.c | 26 +++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 7 deletions(-)
hw/i386/pc_piix.c +25 -4
@@ -310,8 +310,13 @@ static void pc_init_pci(MachineState *machine)pc_init1 (machine,1 ,1 ); } +static void pc_compat_2_3 (MachineState *machine) +{ +} +static void pc_compat_2_2 (MachineState *machine) { +pc_compat_2_3 (machine); rsdp_in_ram = false;x86_cpu_compat_set_features ("kvm64" ,FEAT_1_EDX ,0 ,CPUID_VME );x86_cpu_compat_set_features ("kvm32" ,FEAT_1_EDX ,0 ,CPUID_VME );
@@ -413,6 +418,12 @@ static void pc_compat_1_2(MachineState *machine)x86_cpu_compat_kvm_no_autoenable (FEAT_KVM ,1 <<KVM_FEATURE_PV_EOI ); } +static void pc_init_pci_2_3 (MachineState *machine) +{ +pc_compat_2_3 (machine); +pc_init_pci (machine); +} +static void pc_init_pci_2_2 (MachineState *machine) {pc_compat_2_2 (machine);
@@ -512,19 +523,28 @@ static void pc_xen_hvm_init(MachineState *machine) .desc = "Standard PC (i440FX + PIIX, 1996)", \ .hot_add_cpu = pc_hot_add_cpu -#define PC_I440FX_2_3_MACHINE_OPTIONS \ +#define PC_I440FX_2_4_MACHINE_OPTIONS \ PC_I440FX_MACHINE_OPTIONS, \ .default_machine_opts = "firmware=bios-256k.bin", \ .default_display = "std" -static QEMUMachine pc_i440fx_machine_v2_3 = { -PC_I440FX_2_3_MACHINE_OPTIONS , - .name ="pc-i440fx-2.3" , + +static QEMUMachine pc_i440fx_machine_v2_4 = { +PC_I440FX_2_4_MACHINE_OPTIONS , + .name ="pc-i440fx-2.4" , .alias ="pc" , .init = pc_init_pci, .is_default =1 , }; +#define PC_I440FX_2_3_MACHINE_OPTIONS PC_I440FX_2_4_MACHINE_OPTIONS + +static QEMUMachine pc_i440fx_machine_v2_3 = { +PC_I440FX_2_3_MACHINE_OPTIONS , + .name ="pc-i440fx-2.3" , + .init = pc_init_pci_2_3, +}; +#define PC_I440FX_2_2_MACHINE_OPTIONS PC_I440FX_2_3_MACHINE_OPTIONSstatic QEMUMachine pc_i440fx_machine_v2_2 = {
@@ -970,6 +990,7 @@ static QEMUMachine xenfv_machine = {static void pc_machine_init (void ) { +qemu_register_pc_machine (&pc_i440fx_machine_v2_4);qemu_register_pc_machine (&pc_i440fx_machine_v2_3);qemu_register_pc_machine (&pc_i440fx_machine_v2_2);qemu_register_pc_machine (&pc_i440fx_machine_v2_1);
hw/i386/pc_q35.c +23 -3
@@ -289,8 +289,13 @@ static void pc_q35_init(MachineState *machine) } } +static void pc_compat_2_3 (MachineState *machine) +{ +} +static void pc_compat_2_2 (MachineState *machine) { +pc_compat_2_3 (machine); rsdp_in_ram = false;x86_cpu_compat_set_features ("kvm64" ,FEAT_1_EDX ,0 ,CPUID_VME );x86_cpu_compat_set_features ("kvm32" ,FEAT_1_EDX ,0 ,CPUID_VME );
@@ -361,6 +366,12 @@ static void pc_compat_1_4(MachineState *machine)x86_cpu_compat_set_features ("Westmere" ,FEAT_1_ECX ,0 ,CPUID_EXT_PCLMULQDQ ); } +static void pc_q35_init_2_3 (MachineState *machine) +{ +pc_compat_2_3 (machine); +pc_q35_init (machine); +} +static void pc_q35_init_2_2 (MachineState *machine) {pc_compat_2_2 (machine);
@@ -410,16 +421,24 @@ static void pc_q35_init_1_4(MachineState *machine) .hot_add_cpu = pc_hot_add_cpu, \ .units_per_default_bus = 1 -#define PC_Q35_2_3_MACHINE_OPTIONS \ +#define PC_Q35_2_4_MACHINE_OPTIONS \ PC_Q35_MACHINE_OPTIONS, \ .default_machine_opts = "firmware=bios-256k.bin", \ .default_display = "std" +static QEMUMachine pc_q35_machine_v2_4 = { +PC_Q35_2_4_MACHINE_OPTIONS , + .name ="pc-q35-2.4" , + .alias ="q35" , + .init = pc_q35_init, +}; + +#define PC_Q35_2_3_MACHINE_OPTIONS PC_Q35_2_4_MACHINE_OPTIONS +static QEMUMachine pc_q35_machine_v2_3 = {PC_Q35_2_3_MACHINE_OPTIONS , .name ="pc-q35-2.3" , - .alias ="q35" , - .init = pc_q35_init, + .init = pc_q35_init_2_3, };#define PC_Q35_2_2_MACHINE_OPTIONS PC_Q35_2_3_MACHINE_OPTIONS
@@ -506,6 +525,7 @@ static QEMUMachine pc_q35_machine_v1_4 = {static void pc_q35_machine_init (void ) { +qemu_register_pc_machine (&pc_q35_machine_v2_4);qemu_register_pc_machine (&pc_q35_machine_v2_3);qemu_register_pc_machine (&pc_q35_machine_v2_2);qemu_register_pc_machine (&pc_q35_machine_v2_1);
Signature · 1 line
1.8.3.1
PATCH 2/31 target-i386: introduce cpu_get_mem_attrs
In reply to Paolo Bonzini--- include/exec/memattrs.h | 4 +++- target-i386/cpu.h | 5 +++++ target-i386/helper.c | 3 ++- target-i386/kvm.c | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-)
include/exec/memattrs.h +3 -1
@@ -29,7 +29,9 @@ typedef struct MemTxAttrs {* "didn't specify" if necessary. */ unsigned int unspecified:1; -/* ARM/AMBA TrustZone Secure access */ +/* ARM/AMBA: TrustZone Secure access +* x86: System Management Mode access +*/ unsigned int secure:1;/* Memory access is usermode (unprivileged) */ unsigned int user:1;
target-i386/cpu.h +5 -0
@@ -1292,6 +1292,11 @@ static inline void cpu_load_efer(CPUX86State *env, uint64_t val) } } +static inline MemTxAttrs cpu_get_mem_attrs (CPUX86State *env) +{ +return ((MemTxAttrs ) { .secure = (env->hflags &HF_SMM_MASK ) !=0 }); +} +/* fpu_helper.c */ void cpu_set_mxcsr (CPUX86State *env,uint32_t val);void cpu_set_fpuc (CPUX86State *env,uint16_t val);
target-i386/helper.c +2 -1
@@ -771,7 +771,8 @@ do_check_protect_pse36: page_offset = vaddr & (page_size -1 ); paddr = pte + page_offset; -tlb_set_page (cs, vaddr, paddr, prot, mmu_idx, page_size); +tlb_set_page_with_attrs (cs, vaddr, paddr,cpu_get_mem_attrs (env), + prot, mmu_idx, page_size);return 0 ; do_fault_rsvd: error_code |=PG_ERROR_RSVD_MASK ;
target-i386/kvm.c +1 -1
@@ -2259,7 +2259,7 @@ MemTxAttrs kvm_arch_post_run(CPUState *cpu, struct kvm_run *run) }cpu_set_apic_tpr (x86_cpu->apic_state, run->cr8);cpu_set_apic_base (x86_cpu->apic_state, run->apic_base); -return MEMTXATTRS_UNSPECIFIED ; +return cpu_get_mem_attrs (env); }int kvm_arch_process_async_events (CPUState *cs)
Signature · 1 line
1.8.3.1
PATCH 3/31 target-i386: Use correct memory attributes for memory accesses
In reply to Paolo BonziniThese include page table walks, SVM accesses and SMM state save accesses.
The bulk of the patch is obtained with
sed -i 's/\(\<[a-z_]*_phys\(_notdirty\)\?\>(cs\)->as,/x86_\1,/'
--- target-i386/cpu.h | 12 ++ target-i386/helper.c | 132 +++++++++++++++++---- target-i386/seg_helper.c | 12 +- target-i386/smm_helper.c | 298 +++++++++++++++++++++++------------------------ target-i386/svm_helper.c | 230 ++++++++++++++++++------------------ 5 files changed, 394 insertions(+), 290 deletions(-)
target-i386/cpu.h +12 -0
@@ -1105,6 +1105,18 @@ int x86_cpu_handle_mmu_fault(CPUState *cpu, vaddr addr, int is_write, int mmu_idx);void x86_cpu_set_a20 (X86CPU *cpu,int a20_state); +#ifndef CONFIG_USER_ONLY +uint8_t x86_ldub_phys (CPUState *cs,hwaddr addr); +uint32_t x86_lduw_phys (CPUState *cs,hwaddr addr); +uint32_t x86_ldl_phys (CPUState *cs,hwaddr addr); +uint64_t x86_ldq_phys (CPUState *cs,hwaddr addr); +void x86_stb_phys (CPUState *cs,hwaddr addr,uint8_t val); +void x86_stl_phys_notdirty (CPUState *cs,hwaddr addr,uint32_t val); +void x86_stw_phys (CPUState *cs,hwaddr addr,uint32_t val); +void x86_stl_phys (CPUState *cs,hwaddr addr,uint32_t val); +void x86_stq_phys (CPUState *cs,hwaddr addr,uint64_t val); +#endif +static inline bool hw_local_breakpoint_enabled (unsigned long dr7,int index) {return (dr7 >> (index *2 )) &1 ;
target-i386/helper.c +112 -20
248 lines not on this page · raw message
target-i386/seg_helper.c +6 -6
@@ -1144,7 +1144,7 @@ static void handle_even_inj(CPUX86State *env, int intno, int is_int, int error_code, int is_hw, int rm) { CPUState *cs = CPU(x86_env_get_cpu(env)); -uint32_t event_inj =ldl_phys (cs->as, env->vm_vmcb + offsetof(struct vmcb , +uint32_t event_inj =x86_ldl_phys (cs, env->vm_vmcb + offsetof(struct vmcb , control.event_inj));if (!(event_inj &SVM_EVTINJ_VALID )) {
@@ -1158,11 +1158,11 @@ static void handle_even_inj(CPUX86State *env, int intno, int is_int, event_inj = intno | type |SVM_EVTINJ_VALID ;if (!rm &&exception_has_error_code (intno)) { event_inj |=SVM_EVTINJ_VALID_ERR ; -stl_phys (cs->as, env->vm_vmcb + offsetof(struct vmcb , +x86_stl_phys (cs, env->vm_vmcb + offsetof(struct vmcb , control.event_inj_err), error_code); } -stl_phys (cs->as, +x86_stl_phys (cs, env->vm_vmcb + offsetof(struct vmcb, control.event_inj), event_inj); }
@@ -1240,11 +1240,11 @@ static void do_interrupt_all(X86CPU *cpu, int intno, int is_int,#if !defined(CONFIG_USER_ONLY )if (env->hflags &HF_SVMI_MASK ) {CPUState *cs =CPU (cpu); -uint32_t event_inj =ldl_phys (cs->as, env->vm_vmcb + +uint32_t event_inj =x86_ldl_phys (cs, env->vm_vmcb + offsetof(struct vmcb , control.event_inj)); -stl_phys (cs->as, +x86_stl_phys (cs, env->vm_vmcb + offsetof(struct vmcb, control.event_inj), event_inj & ~SVM_EVTINJ_VALID ); }
@@ -1339,7 +1339,7 @@ bool x86_cpu_exec_interrupt(CPUState *cs, int interrupt_request)int intno;/* FIXME: this should respect TPR */ cpu_svm_check_intercept_param (env,SVM_EXIT_VINTR ,0 ); - intno =ldl_phys (cs->as, env->vm_vmcb + intno =x86_ldl_phys (cs, env->vm_vmcb + offsetof(struct vmcb, control.int_vector));qemu_log_mask (CPU_LOG_TB_IN_ASM ,"Servicing virtual hardware INT=0x%02x\n" , intno);
target-i386/smm_helper.c +149 -149
356 lines not on this page · raw message
target-i386/svm_helper.c +115 -115
488 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 4/31 target-i386: Use correct memory attributes for ioport accesses
In reply to Paolo BonziniIn order to do this, stop using the cpu_in*/out* helpers, and instead access address_space_io directly.
cpu_in* and cpu_out* remain for usage in the monitor, in qtest, and in Xen.
--- target-i386/Makefile.objs | 2 -- target-i386/helper.h | 12 +++++----- target-i386/ioport-user.c | 60 ----------------------------------------------- target-i386/misc_helper.c | 59 ++++++++++++++++++++++++++++++++++++---------- target-i386/translate.c | 12 +++++----- 5 files changed, 58 insertions(+), 87 deletions(-) delete mode 100644 target-i386/ioport-user.c
target-i386/Makefile.objs +0 -2
@@ -5,5 +5,3 @@ obj-y += gdbstub.o obj-$(CONFIG_SOFTMMU) += machine.o arch_memory_mapping.o arch_dump.o obj-$(CONFIG_KVM) += kvm.o obj-$(call lnot,$(CONFIG_KVM)) += kvm-stub.o -obj-$(CONFIG_LINUX_USER) += ioport-user.o -obj-$(CONFIG_BSD_USER) += ioport-user.o
target-i386/helper.h +6 -6
@@ -86,12 +86,12 @@ DEF_HELPER_1(wrmsr, void, env) DEF_HELPER_2(check_iob, void, env, i32) DEF_HELPER_2(check_iow, void, env, i32) DEF_HELPER_2(check_iol, void, env, i32) -DEF_HELPER_2(outb, void, i32, i32) -DEF_HELPER_1(inb, tl, i32) -DEF_HELPER_2(outw, void, i32, i32) -DEF_HELPER_1(inw, tl, i32) -DEF_HELPER_2(outl, void, i32, i32) -DEF_HELPER_1(inl, tl, i32) +DEF_HELPER_3(outb, void, env, i32, i32) +DEF_HELPER_2(inb, tl, env, i32) +DEF_HELPER_3(outw, void, env, i32, i32) +DEF_HELPER_2(inw, tl, env, i32) +DEF_HELPER_3(outl, void, env, i32, i32) +DEF_HELPER_2(inl, tl, env, i32) DEF_HELPER_3(svm_check_intercept_param, void, env, i32, i64)DEF_HELPER_3 (vmexit, void, env, i32, i64)
target-i386/ioport-user.c deleted +0 -60
60 lines not on this page · raw message
target-i386/misc_helper.c +46 -13
84 lines not on this page · raw message
target-i386/translate.c +6 -6
@@ -631,13 +631,13 @@ static void gen_helper_in_func(TCGMemOp ot, TCGv v, TCGv_i32 n) {switch (ot) {case MO_8 : -gen_helper_inb (v, n); +gen_helper_inb (v, cpu_env, n);break ;case MO_16 : -gen_helper_inw (v, n); +gen_helper_inw (v, cpu_env, n);break ;case MO_32 : -gen_helper_inl (v, n); +gen_helper_inl (v, cpu_env, n);break ;default :tcg_abort ();
@@ -648,13 +648,13 @@ static void gen_helper_out_func(TCGMemOp ot, TCGv_i32 v, TCGv_i32 n) {switch (ot) {case MO_8 : -gen_helper_outb (v, n); +gen_helper_outb (cpu_env, v, n);break ;case MO_16 : -gen_helper_outw (v, n); +gen_helper_outw (cpu_env, v, n);break ;case MO_32 : -gen_helper_outl (v, n); +gen_helper_outl (cpu_env, v, n);break ;default :tcg_abort ();
Signature · 1 line
1.8.3.1
PATCH 5/31 target-i386: mask NMIs on entry to SMM
In reply to Paolo BonziniQEMU is not blocking NMIs on entry to SMM. Implementing this has to cover a few corner cases, because:
- NMIs can then be enabled by an IRET instruction and there is no mechanism to _set_ the "NMIs masked" flag on exit from SMM:
"A special case can occur if an SMI handler nests inside an NMI handler and then another NMI occurs. [...] When the processor enters SMM while executing an NMI handler, the processor saves the SMRAM state save map but does not save the attribute to keep NMI interrupts disabled.
- However, there is some hidden state, because "If NMIs were blocked before the SMI occurred [and no IRET is executed while in SMM], they are blocked after execution of RSM." This is represented by the new HF2_SMM_INSIDE_NMI_MASK bit. If it is zero, NMIs are _unblocked_ on exit from RSM.
--- target-i386/cpu.h | 20 +++++++++++--------- target-i386/smm_helper.c | 9 +++++++++ 2 files changed, 20 insertions(+), 9 deletions(-)
target-i386/cpu.h +11 -9
@@ -180,15 +180,17 @@/* hflags2 */ -#define HF2_GIF_SHIFT 0/* if set CPU takes interrupts */ -#define HF2_HIF_SHIFT 1/* value of IF_MASK when entering SVM */ -#define HF2_NMI_SHIFT 2/* CPU serving NMI */ -#define HF2_VINTR_SHIFT 3/* value of V_INTR_MASKING bit */ - -#define HF2_GIF_MASK (1 << HF2_GIF_SHIFT) -#define HF2_HIF_MASK (1 << HF2_HIF_SHIFT) -#define HF2_NMI_MASK (1 << HF2_NMI_SHIFT) -#define HF2_VINTR_MASK (1 << HF2_VINTR_SHIFT) +#define HF2_GIF_SHIFT 0/* if set CPU takes interrupts */ +#define HF2_HIF_SHIFT 1/* value of IF_MASK when entering SVM */ +#define HF2_NMI_SHIFT 2/* CPU serving NMI */ +#define HF2_VINTR_SHIFT 3/* value of V_INTR_MASKING bit */ +#define HF2_SMM_INSIDE_NMI_SHIFT 4/* CPU serving SMI nested inside NMI */ + +#define HF2_GIF_MASK (1 << HF2_GIF_SHIFT) +#define HF2_HIF_MASK (1 << HF2_HIF_SHIFT) +#define HF2_NMI_MASK (1 << HF2_NMI_SHIFT) +#define HF2_VINTR_MASK (1 << HF2_VINTR_SHIFT) +#define HF2_SMM_INSIDE_NMI_MASK (1 << HF2_SMM_INSIDE_NMI_SHIFT)#define CR0_PE_SHIFT 0#define CR0_MP_SHIFT 1
target-i386/smm_helper.c +9 -0
@@ -52,6 +52,11 @@ void do_smm_enter(X86CPU *cpu)log_cpu_state_mask (CPU_LOG_INT ,CPU (cpu),CPU_DUMP_CCOP ); env->hflags |=HF_SMM_MASK ; +if (env->hflags2 &HF2_NMI_MASK ) { + env->hflags2 |=HF2_SMM_INSIDE_NMI_MASK ; + }else { + env->hflags2 |=HF2_NMI_MASK ; + }cpu_smm_update (env); sm_state = env->smbase +0x8000 ;
@@ -307,6 +312,10 @@ void helper_rsm(CPUX86State *env) env->smbase = x86_ldl_phys(cs, sm_state + 0x7ef8) & ~0x7fff; }#endif +if ((env->hflags2 &HF2_SMM_INSIDE_NMI_MASK ) ==0 ) { + env->hflags2 &= ~HF2_NMI_MASK ; + } + env->hflags2 &= ~HF2_SMM_INSIDE_NMI_MASK ; env->hflags &= ~HF_SMM_MASK ;cpu_smm_update (env);
Signature · 1 line
1.8.3.1
PATCH 6/31 target-i386: set G=1 in SMM big real mode selectors
In reply to Paolo BonziniBecause the limit field's bits 31:20 is 1, G should be 1. VMX actually enforces this, let's do it for completeness in QEMU as well.
--- target-i386/smm_helper.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
target-i386/smm_helper.c +6 -6
@@ -177,22 +177,22 @@ void do_smm_enter(X86CPU *cpu)cpu_x86_load_seg_cache (env,R_CS , (env->smbase >>4 ) &0xffff , env->smbase,0xffffffff ,DESC_P_MASK |DESC_S_MASK |DESC_W_MASK | -DESC_A_MASK ); +DESC_G_MASK |DESC_A_MASK );cpu_x86_load_seg_cache (env,R_DS ,0 ,0 ,0xffffffff ,DESC_P_MASK |DESC_S_MASK |DESC_W_MASK | -DESC_A_MASK ); +DESC_G_MASK |DESC_A_MASK );cpu_x86_load_seg_cache (env,R_ES ,0 ,0 ,0xffffffff ,DESC_P_MASK |DESC_S_MASK |DESC_W_MASK | -DESC_A_MASK ); +DESC_G_MASK |DESC_A_MASK );cpu_x86_load_seg_cache (env,R_SS ,0 ,0 ,0xffffffff ,DESC_P_MASK |DESC_S_MASK |DESC_W_MASK | -DESC_A_MASK ); +DESC_G_MASK |DESC_A_MASK );cpu_x86_load_seg_cache (env,R_FS ,0 ,0 ,0xffffffff ,DESC_P_MASK |DESC_S_MASK |DESC_W_MASK | -DESC_A_MASK ); +DESC_G_MASK |DESC_A_MASK );cpu_x86_load_seg_cache (env,R_GS ,0 ,0 ,0xffffffff ,DESC_P_MASK |DESC_S_MASK |DESC_W_MASK | -DESC_A_MASK ); +DESC_G_MASK |DESC_A_MASK ); }void helper_rsm (CPUX86State *env)
Signature · 1 line
1.8.3.1
PATCH 7/31 pflash_cfi01: change big-endian property to BIT type
In reply to Paolo BonziniMake this consistent with the secure property, added in the next patch.
--- hw/block/pflash_cfi01.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
hw/block/pflash_cfi01.c +7 -4
@@ -64,6 +64,8 @@ do { \#define TYPE_CFI_PFLASH01 "cfi.pflash01"#define CFI_PFLASH01 (obj) OBJECT_CHECK(pflash_t, (obj), TYPE_CFI_PFLASH01) +#define PFLASH_BE 0 +struct pflash_t {/*< private >*/ SysBusDevice parent_obj;
@@ -75,7 +77,7 @@ struct pflash_t {uint8_t bank_width;uint8_t device_width;/* If 0, device width not specified. */ uint8_t max_device_width;/* max device width in bytes */ -uint8_t be; +uint32_t features;uint8_t wcycle;/* if 0, the flash is read normally */ int ro;uint8_t cmd;
@@ -773,7 +775,8 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp)memory_region_init_rom_device ( &pfl->mem,OBJECT (dev), - pfl->be ? &pflash_cfi01_ops_be : &pflash_cfi01_ops_le, pfl, + pfl->features & (1 <<PFLASH_BE ) ? &pflash_cfi01_ops_be : &pflash_cfi01_ops_le, + pfl, pfl->name, total_len, &local_err);if (local_err) {error_propagate (errp, local_err);
@@ -925,7 +928,7 @@ static Property pflash_cfi01_properties[] = { DEFINE_PROP_UINT8("width", struct pflash_t, bank_width, 0), DEFINE_PROP_UINT8("device-width", struct pflash_t, device_width, 0), DEFINE_PROP_UINT8("max-device-width", struct pflash_t, max_device_width, 0), - DEFINE_PROP_UINT8("big-endian", struct pflash_t, be, 0), + DEFINE_PROP_BIT("big-endian", struct pflash_t, features, PFLASH_BE, 0), DEFINE_PROP_UINT16("id0", struct pflash_t, ident0, 0), DEFINE_PROP_UINT16("id1", struct pflash_t, ident1, 0), DEFINE_PROP_UINT16("id2", struct pflash_t, ident2, 0),
@@ -975,7 +978,7 @@ pflash_t *pflash_cfi01_register(hwaddr base,qdev_prop_set_uint32 (dev,"num-blocks" , nb_blocs);qdev_prop_set_uint64 (dev,"sector-length" , sector_len);qdev_prop_set_uint8 (dev,"width" , bank_width); -qdev_prop_set_uint8 (dev,"big-endian" , !!be); +qdev_prop_set_bit (dev,"big-endian" , !!be);qdev_prop_set_uint16 (dev,"id0" , id0);qdev_prop_set_uint16 (dev,"id1" , id1);qdev_prop_set_uint16 (dev,"id2" , id2);
Signature · 1 line
1.8.3.1
PATCH 8/31 pflash_cfi01: change to new-style MMIO accessors
In reply to Paolo BonziniThis is a required step to implement read_with_attrs and write_with_attrs.
--- hw/block/pflash_cfi01.c | 96 ++++++------------------------------------------- 1 file changed, 10 insertions(+), 86 deletions(-)
hw/block/pflash_cfi01.c +10 -86
@@ -650,101 +650,25 @@ static void pflash_write(pflash_t *pfl, hwaddr offset, } -static uint32_t pflash_readb_be (void *opaque,hwaddr addr) -{ -return pflash_read (opaque, addr,1 ,1 ); -} - -static uint32_t pflash_readb_le (void *opaque,hwaddr addr) -{ -return pflash_read (opaque, addr,1 ,0 ); -} - -static uint32_t pflash_readw_be (void *opaque,hwaddr addr) +static uint64_t pflash_mem_read (void *opaque,hwaddr addr,unsigned len) {pflash_t *pfl = opaque; +bool be = !!(pfl->features & (1 <<PFLASH_BE )); -return pflash_read (pfl, addr,2 ,1 ); +return pflash_read (pfl, addr, len, be); } -static uint32_t pflash_readw_le (void *opaque,hwaddr addr) +static void pflash_mem_write (void *opaque,hwaddr addr,uint64_t value,unsigned len) {pflash_t *pfl = opaque; +bool be = !!(pfl->features & (1 <<PFLASH_BE )); -return pflash_read (pfl, addr,2 ,0 ); +pflash_write (pfl, addr, value, len, be); } -static uint32_t pflash_readl_be (void *opaque,hwaddr addr) -{ -pflash_t *pfl = opaque; - -return pflash_read (pfl, addr,4 ,1 ); -} - -static uint32_t pflash_readl_le (void *opaque,hwaddr addr) -{ -pflash_t *pfl = opaque; - -return pflash_read (pfl, addr,4 ,0 ); -} - -static void pflash_writeb_be (void *opaque,hwaddr addr, -uint32_t value) -{ -pflash_write (opaque, addr, value,1 ,1 ); -} - -static void pflash_writeb_le (void *opaque,hwaddr addr, -uint32_t value) -{ -pflash_write (opaque, addr, value,1 ,0 ); -} - -static void pflash_writew_be (void *opaque,hwaddr addr, -uint32_t value) -{ -pflash_t *pfl = opaque; - -pflash_write (pfl, addr, value,2 ,1 ); -} - -static void pflash_writew_le (void *opaque,hwaddr addr, -uint32_t value) -{ -pflash_t *pfl = opaque; - -pflash_write (pfl, addr, value,2 ,0 ); -} - -static void pflash_writel_be (void *opaque,hwaddr addr, -uint32_t value) -{ -pflash_t *pfl = opaque; - -pflash_write (pfl, addr, value,4 ,1 ); -} - -static void pflash_writel_le (void *opaque,hwaddr addr, -uint32_t value) -{ -pflash_t *pfl = opaque; - -pflash_write (pfl, addr, value,4 ,0 ); -} - -static const MemoryRegionOps pflash_cfi01_ops_be = { - .old_mmio = { - .read = { pflash_readb_be, pflash_readw_be, pflash_readl_be, }, - .write = { pflash_writeb_be, pflash_writew_be, pflash_writel_be, }, - }, - .endianness =DEVICE_NATIVE_ENDIAN , -}; - -static const MemoryRegionOps pflash_cfi01_ops_le = { - .old_mmio = { - .read = { pflash_readb_le, pflash_readw_le, pflash_readl_le, }, - .write = { pflash_writeb_le, pflash_writew_le, pflash_writel_le, }, - }, +static const MemoryRegionOps pflash_cfi01_ops = { + .read = pflash_mem_read, + .write = pflash_mem_write, .endianness =DEVICE_NATIVE_ENDIAN , };
@@ -775,7 +699,7 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp)memory_region_init_rom_device ( &pfl->mem,OBJECT (dev), - pfl->features & (1 <<PFLASH_BE ) ? &pflash_cfi01_ops_be : &pflash_cfi01_ops_le, + &pflash_cfi01_ops, pfl, pfl->name, total_len, &local_err);if (local_err) {
Signature · 1 line
1.8.3.1
PATCH 9/31 pflash_cfi01: add secure property
In reply to Paolo BonziniWhen this property is set, MMIO accesses are only allowed with the MEMTXATTRS_SECURE attribute. This is used for secure access to UEFI variables stored in flash.
--- hw/block/pflash_cfi01.c | 111 +++++++++++++++++++++++++++++------------------- 1 file changed, 67 insertions(+), 44 deletions(-)
hw/block/pflash_cfi01.c +67 -44
@@ -65,6 +65,7 @@ do { \#define CFI_PFLASH01 (obj) OBJECT_CHECK(pflash_t, (obj), TYPE_CFI_PFLASH01)#define PFLASH_BE 0 +#define PFLASH_SECURE 1struct pflash_t {/*< private >*/
@@ -237,12 +238,57 @@ static uint32_t pflash_devid_query(pflash_t *pfl, hwaddr offset)return resp; } +static uint32_t pflash_data_read (pflash_t *pfl,hwaddr offset, +int width,int be) +{ +uint8_t *p; +uint32_t ret; + + p = pfl->storage; +switch (width) { +case 1 : + ret = p[offset]; +DPRINTF ("%s: data offset " TARGET_FMT_plx" %02x\n" , + __func__, offset, ret); +break ; +case 2 : +if (be) { + ret = p[offset] <<8 ; + ret |= p[offset +1 ]; + }else { + ret = p[offset]; + ret |= p[offset +1 ] <<8 ; + } +DPRINTF ("%s: data offset " TARGET_FMT_plx" %04x\n" , + __func__, offset, ret); +break ; +case 4 : +if (be) { + ret = p[offset] <<24 ; + ret |= p[offset +1 ] <<16 ; + ret |= p[offset +2 ] <<8 ; + ret |= p[offset +3 ]; + }else { + ret = p[offset]; + ret |= p[offset +1 ] <<8 ; + ret |= p[offset +2 ] <<16 ; + ret |= p[offset +3 ] <<24 ; + } +DPRINTF ("%s: data offset " TARGET_FMT_plx" %08x\n" , + __func__, offset, ret); +break ; +default : +DPRINTF ("BUG in %s\n" , __func__); +abort (); + } +return ret; +} +static uint32_t pflash_read (pflash_t *pfl,hwaddr offset,int width,int be) {hwaddr boff;uint32_t ret; -uint8_t *p; ret =-1 ;
@@ -259,43 +305,7 @@ static uint32_t pflash_read (pflash_t *pfl, hwaddr offset,/* fall through to read code */ case 0x00 :/* Flash area read */ - p = pfl->storage; -switch (width) { -case 1 : - ret = p[offset]; -DPRINTF ("%s: data offset " TARGET_FMT_plx" %02x\n" , - __func__, offset, ret); -break ; -case 2 : -if (be) { - ret = p[offset] <<8 ; - ret |= p[offset +1 ]; - }else { - ret = p[offset]; - ret |= p[offset +1 ] <<8 ; - } -DPRINTF ("%s: data offset " TARGET_FMT_plx" %04x\n" , - __func__, offset, ret); -break ; -case 4 : -if (be) { - ret = p[offset] <<24 ; - ret |= p[offset +1 ] <<16 ; - ret |= p[offset +2 ] <<8 ; - ret |= p[offset +3 ]; - }else { - ret = p[offset]; - ret |= p[offset +1 ] <<8 ; - ret |= p[offset +2 ] <<16 ; - ret |= p[offset +3 ] <<24 ; - } -DPRINTF ("%s: data offset " TARGET_FMT_plx" %08x\n" , - __func__, offset, ret); -break ; -default : -DPRINTF ("BUG in %s\n" , __func__); - } - + ret =pflash_data_read (pfl, offset, width, be);break ;case 0x10 :/* Single byte program */ case 0x20 :/* Block erase */
@@ -650,25 +660,37 @@ static void pflash_write(pflash_t *pfl, hwaddr offset, } -static uint64_t pflash_mem_read (void *opaque,hwaddr addr,unsigned len) +static MemTxResult pflash_mem_read_with_attrs (void *opaque,hwaddr addr,uint64_t *value, +unsigned len,MemTxAttrs attrs) {pflash_t *pfl = opaque;bool be = !!(pfl->features & (1 <<PFLASH_BE )); -return pflash_read (pfl, addr, len, be); +if ((pfl->features & (1 <<PFLASH_SECURE )) && !attrs.secure) { + *value =pflash_data_read (opaque, addr, len, be); + }else { + *value =pflash_read (opaque, addr, len, be); + } +return MEMTX_OK ; } -static void pflash_mem_write (void *opaque,hwaddr addr,uint64_t value,unsigned len) +static MemTxResult pflash_mem_write_with_attrs (void *opaque,hwaddr addr,uint64_t value, +unsigned len,MemTxAttrs attrs) {pflash_t *pfl = opaque;bool be = !!(pfl->features & (1 <<PFLASH_BE )); -pflash_write (pfl, addr, value, len, be); +if ((pfl->features & (1 <<PFLASH_SECURE )) && !attrs.secure) { +return MEMTX_ERROR ; + }else { +pflash_write (opaque, addr, value, len, be); +return MEMTX_OK ; + } }static const MemoryRegionOps pflash_cfi01_ops = { - .read = pflash_mem_read, - .write = pflash_mem_write, + .read_with_attrs = pflash_mem_read_with_attrs, + .write_with_attrs = pflash_mem_write_with_attrs, .endianness =DEVICE_NATIVE_ENDIAN , };
@@ -853,6 +875,7 @@ static Property pflash_cfi01_properties[] = { DEFINE_PROP_UINT8("device-width", struct pflash_t, device_width, 0), DEFINE_PROP_UINT8("max-device-width", struct pflash_t, max_device_width, 0), DEFINE_PROP_BIT("big-endian", struct pflash_t, features, PFLASH_BE, 0), + DEFINE_PROP_BIT("secure", struct pflash_t, features, PFLASH_SECURE, 0), DEFINE_PROP_UINT16("id0", struct pflash_t, ident0, 0), DEFINE_PROP_UINT16("id1", struct pflash_t, ident1, 0), DEFINE_PROP_UINT16("id2", struct pflash_t, ident2, 0),
Signature · 1 line
1.8.3.1
PATCH 10/31 vl: allow full-blown QemuOpts syntax for -global
In reply to Paolo Bonzini-global does not work for drivers that have a dot in their name, such as cfi.pflash01. This is just a parsing limitation, because such globals can be declared easily inside a -readconfig file.
To allow this usage, support the full QemuOpts key/value syntax for -global too, for example "-global driver=cfi.pflash01,property=secure,value=on". The two formats do not conflict, because the key/value syntax does not have a period before the first equal sign.
--- qdev-monitor.c | 18 +++++++++++------- qemu-options.hx | 7 ++++++- 2 files changed, 17 insertions(+), 8 deletions(-)
qdev-monitor.c +11 -7
@@ -822,15 +822,19 @@ int qemu_global_option(const char *str)QemuOpts *opts;int rc, offset; - rc =sscanf (str,"%63[^.].%63[^=]%n" , driver, property, &offset); -if (rc <2 || str[offset] !='=' ) { -error_report ("can't parse: \"%s\"" , str); + rc =sscanf (str,"%63[^.=].%63[^=]%n" , driver, property, &offset); +if (rc ==2 && str[offset] =='=' ) { + opts =qemu_opts_create (&qemu_global_opts,NULL ,0 , &error_abort); +qemu_opt_set (opts,"driver" , driver, &error_abort); +qemu_opt_set (opts,"property" , property, &error_abort); +qemu_opt_set (opts,"value" , str + offset +1 , &error_abort); +return 0 ; + } + + opts =qemu_opts_parse (&qemu_global_opts, str, false); +if (!opts) {return -1 ; } - opts =qemu_opts_create (&qemu_global_opts,NULL ,0 , &error_abort); -qemu_opt_set (opts,"driver" , driver, &error_abort); -qemu_opt_set (opts,"property" , property, &error_abort); -qemu_opt_set (opts,"value" , str + offset +1 , &error_abort);return 0 ; }
qemu-options.hx +6 -1
@@ -171,11 +171,13 @@ Set parameter @var{arg} for item @var{id} of type @var{group}\n" ETEXI DEF("global", HAS_ARG, QEMU_OPTION_global, - "-global driver.prop=value\n" + "-global driver.property=value\n" + "-global driver=driver,property=property,value=value\n" " set a global default for a driver property\n", QEMU_ARCH_ALL) STEXI @item -global @var{driver}.@var{prop}=@var{value} +@itemx -global driver=@var{driver},property=@var{property},value=@var{value} @findex -global Set default value of @var{driver}'s property @var{prop} to @var{value}, e.g.:
@@ -186,6 +188,9 @@ qemu-system-i386 -global ide-drive.physical_block_size=4096 -drive file=file,if= In particular, you can use this to set driver properties for devices which are created automatically by the machine model. To create a device which is not created automatically and set properties on it, use -@option{device}. + +The two syntaxes are equivalent. The longer one works for drivers whose name +contains a dot. ETEXI DEF("boot", HAS_ARG, QEMU_OPTION_boot,
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 10/31] vl: allow full-blown QemuOpts syntax for -global
Markus, can you review this one?
Thanks,
Paolo
Quoted 76 lines · Paolo Bonzini
-global does not work for drivers that have a dot in their name, such as cfi.pflash01. This is just a parsing limitation, because such globals can be declared easily inside a -readconfig file.
To allow this usage, support the full QemuOpts key/value syntax for -global too, for example "-global driver=cfi.pflash01,property=secure,value=on". The two formats do not conflict, because the key/value syntax does not have a period before the first equal sign.
Signed-off-by Paolo Bonzini <[email protected]>--- qdev-monitor.c | 18 +++++++++++------- qemu-options.hx | 7 ++++++- 2 files changed, 17 insertions(+), 8 deletions(-)qdev-monitor.c +11
-7@@ -822,15 +822,19 @@ int qemu_global_option(const char *str)QemuOpts *opts;int rc, offset; - rc =sscanf (str,"%63[^.].%63[^=]%n" , driver, property, &offset); -if (rc <2 || str[offset] !='=' ) { -error_report ("can't parse: \"%s\"" , str); + rc =sscanf (str,"%63[^.=].%63[^=]%n" , driver, property, &offset); +if (rc ==2 && str[offset] =='=' ) { + opts =qemu_opts_create (&qemu_global_opts,NULL ,0 , &error_abort); +qemu_opt_set (opts,"driver" , driver, &error_abort); +qemu_opt_set (opts,"property" , property, &error_abort); +qemu_opt_set (opts,"value" , str + offset +1 , &error_abort); +return 0 ; + } + + opts =qemu_opts_parse (&qemu_global_opts, str, false); +if (!opts) {return -1 ; } - opts =qemu_opts_create (&qemu_global_opts,NULL ,0 , &error_abort); -qemu_opt_set (opts,"driver" , driver, &error_abort); -qemu_opt_set (opts,"property" , property, &error_abort); -qemu_opt_set (opts,"value" , str + offset +1 , &error_abort);return 0 ; }qemu-options.hx +6
-1@@ -171,11 +171,13 @@ Set parameter @var{arg} for item @var{id} of type @var{group}\n" ETEXI DEF("global", HAS_ARG, QEMU_OPTION_global, - "-global driver.prop=value\n" + "-global driver.property=value\n" + "-global driver=driver,property=property,value=value\n" " set a global default for a driver property\n", QEMU_ARCH_ALL) STEXI @item -global @var{driver}.@var{prop}=@var{value} +@itemx -global driver=@var{driver},property=@var{property},value=@var{value} @findex -global Set default value of @var{driver}'s property @var{prop} to @var{value}, e.g.:@@ -186,6 +188,9 @@ qemu-system-i386 -global ide-drive.physical_block_size=4096 -drive file=file,if= In particular, you can use this to set driver properties for devices which are created automatically by the machine model. To create a device which is not created automatically and set properties on it, use -@option{device}. + +The two syntaxes are equivalent. The longer one works for drivers whose name +contains a dot. ETEXI DEF("boot", HAS_ARG, QEMU_OPTION_boot,
Re: [Qemu-devel] [PATCH 10/31] vl: allow full-blown QemuOpts syntax for -global
Quoted 1 line · Paolo Bonzini
Markus, can you review this one?
Okay.
Re: [Qemu-devel] [PATCH 10/31] vl: allow full-blown QemuOpts syntax for -global
In reply to Paolo BonziniQuoted 8 lines · Paolo Bonzini
-global does not work for drivers that have a dot in their name, such as cfi.pflash01. This is just a parsing limitation, because such globals can be declared easily inside a -readconfig file.
To allow this usage, support the full QemuOpts key/value syntax for -global too, for example "-global driver=cfi.pflash01,property=secure,value=on". The two formats do not conflict, because the key/value syntax does not have a period before the first equal sign.
Overloading syntax isn't exactly pretty, but I guess it's the best we can do.
Quoted 27 lines
Signed-off-by Paolo Bonzini <[email protected]>--- qdev-monitor.c | 18 +++++++++++------- qemu-options.hx | 7 ++++++- 2 files changed, 17 insertions(+), 8 deletions(-)qdev-monitor.c +10
-3@@ -822,15 +822,19 @@ int qemu_global_option(const char *str)QemuOpts *opts;int rc, offset; - rc =sscanf (str,"%63[^.].%63[^=]%n" , driver, property, &offset); -if (rc <2 || str[offset] !='=' ) { -error_report ("can't parse: \"%s\"" , str); + rc =sscanf (str,"%63[^.=].%63[^=]%n" , driver, property, &offset); +if (rc ==2 && str[offset] =='=' ) { + opts =qemu_opts_create (&qemu_global_opts,NULL ,0 , &error_abort); +qemu_opt_set (opts,"driver" , driver, &error_abort); +qemu_opt_set (opts,"property" , property, &error_abort); +qemu_opt_set (opts,"value" , str + offset +1 , &error_abort); +return 0 ; + } + + opts =qemu_opts_parse (&qemu_global_opts, str, false);
qdev-monitor.c int qemu_global_option(const char *str) · line 840
Quoted 10 lines
qdev-monitor.c +1
-4+if (!opts) {return -1 ; } - opts =qemu_opts_create (&qemu_global_opts,NULL ,0 , &error_abort); -qemu_opt_set (opts,"driver" , driver, &error_abort); -qemu_opt_set (opts,"property" , property, &error_abort); -qemu_opt_set (opts,"value" , str + offset +1 , &error_abort);return 0 ; }
Restrictions on driver and property names in the shorthand syntax driver.property=value before the patch:
* Both are at most 63 characters long, no whitespace
* Driver name cannot contain '.'
* Property name cannot contain '='
After the patch, we additionally have:
* Driver name cannot contain '='.
Okay as long as no such driver name exists. Have you checked?
Please spell out the new restriction in the commit message.
In the new longhand syntax, driver name, property name and value all appear in QemuOpts value position, and as such are restricted to at most 1023 characters long (see opts_do_parse()). Okay.
I feel we should reject anti-social names for the same reasons we reject anti-social IDs. But that's out of scope for this patch.
Quoted 9 lines
qemu-options.hx +0
-1@@ -171,11 +171,13 @@ Set parameter @var{arg} for item @var{id} of type @var{group}\n" ETEXI DEF("global", HAS_ARG, QEMU_OPTION_global, - "-global driver.prop=value\n"
qemu-options.hx Set parameter @var{arg} for item @var{id} of type @var{group}\n" · line 183
Quoted 10 lines
qemu-options.hx +3
-0+ "-global driver.property=value\n" + "-global driver=driver,property=property,value=value\n" " set a global default for a driver property\n", QEMU_ARCH_ALL) STEXI @item -global @var{driver}.@var{prop}=@var{value} +@itemx -global driver=@var{driver},property=@var{property},value=@var{value} @findex -global Set default value of @var{driver}'s property @var{prop} to @var{value}, e.g.:
Aside: I had to look up @itemx. There are a few @item in this file that should really be @itemx.
qemu-options.hx qemu-system-i386 -global ide-drive.physical_block_size=4096 -drive file=file,if= · line 196
Quoted 10 lines
qemu-options.hx +3
-0@@ -186,6 +188,9 @@ qemu-system-i386 -global ide-drive.physical_block_size=4096 -drive file=file,if= In particular, you can use this to set driver properties for devices which are created automatically by the machine model. To create a device which is not created automatically and set properties on it, use -@option{device}. + +The two syntaxes are equivalent. The longer one works for drivers whose name +contains a dot. ETEXI DEF("boot", HAS_ARG, QEMU_OPTION_boot,
I'd explain this as follows:
-global @var{driver}.@var{prop}=@var{value} is shorthand for -global driver=@var{driver},property=@var{prop},value=@var{value}. The longhand syntax works even when @var{driver} contains a dot.
But I can accept your version.
Re: [Qemu-devel] [PATCH 10/31] vl: allow full-blown QemuOpts syntax for -global
Quoted 7 lines · Markus Armbruster
Restrictions on driver and property names in the shorthand syntax driver.property=value before the patch:
* Both are at most 63 characters long, no whitespace
* Driver name cannot contain '.'
Quoted 7 lines
* Property name cannot contain '='
After the patch, we additionally have:
* Driver name cannot contain '='.
Okay as long as no such driver name exists. Have you checked?
Good catch! I now have.
I've grepped for
- \\..*\".*=.*\",
- TYPE_.*\".*=.*\"
with no hits.
Quoted 1 line
Please spell out the new restriction in the commit message.
Will do.
Quoted 9 lines
Quoted 9 lines
qemu-options.hx +3
-0@@ -186,6 +188,9 @@ qemu-system-i386 -global ide-drive.physical_block_size=4096 -drive file=file,if= In particular, you can use this to set driver properties for devices which are created automatically by the machine model. To create a device which is not created automatically and set properties on it, use -@option{device}. + +The two syntaxes are equivalent. The longer one works for drivers whose name +contains a dot. ETEXI
Quoted 7 lines
qemu-options.hx qemu-system-i386 -global ide-drive.physical_block_size=4096 -drive file=file,if= · line 196
Quoted 1 line
qemu-options.hx +0
-0DEF("boot", HAS_ARG, QEMU_OPTION_boot,I'd explain this as follows:
-global @var{driver}.@var{prop}=@var{value} is shorthand for -global driver=@var{driver},property=@var{prop},value=@var{value}. The longhand syntax works even when @var{driver} contains a dot.
Will do.
Paolo
Re: [Qemu-devel] [PATCH 10/31] vl: allow full-blown QemuOpts syntax for -global
Quoted 22 lines · Paolo Bonzini
Quoted 7 lines · Markus Armbruster
Restrictions on driver and property names in the shorthand syntax driver.property=value before the patch:
* Both are at most 63 characters long, no whitespace
* Driver name cannot contain '.'
Quoted 7 lines
* Property name cannot contain '='
After the patch, we additionally have:
* Driver name cannot contain '='.
Okay as long as no such driver name exists. Have you checked?
Good catch! I now have.
I've grepped for
- \\..*\".*=.*\",
Quoted 7 lines
- TYPE_.*\".*=.*\"
with no hits.
Quoted 1 line
Please spell out the new restriction in the commit message.
Will do.
I'm afraid you didn't.
Quoted 16 lines
Quoted 16 lines
Quoted 12 lines
(quoted diff) +0
-0@@ -186,6 +188,9 @@ qemu-system-i386 -globalide-drive.physical_block_size=4096 -drive file=file,if=
In particular, you can use this to set driver properties for
devices which are
created automatically by the machine model. To create a device which is not created automatically and set properties on it, use -@option{device}.(quoted diff) +2
-0+ +The two syntaxes are equivalent. The longer one works for driverswhose name
+contains a dot.
ETEXIQuoted 1 line
DEF("boot",
HAS_ARG,QEMU_OPTION_boot,I'd explain this as follows:
Quoted 5 lines
Quoted 3 lines
-global @var{driver}.@var{prop}=@var{value} is shorthand for -global driver=@var{driver},property=@var{prop},value=@var{value}. The longhand syntax works even when @var{driver} contains a dot.
Will do.
I'm afraid you didn't. I'll post a follow-up patch.
PATCH 11/31 qom: add object_property_add_const_link
In reply to Paolo Bonzini--- include/qom/object.h | 18 ++++++++++++++++++ qom/object.c | 16 ++++++++++++++++ 2 files changed, 34 insertions(+)
include/qom/object.h +18 -0
@@ -1290,6 +1290,24 @@ void object_property_add_alias(Object *obj, const char *name, Error **errp);/** +* object_property_add_const_link: +* @obj: the object to add a property to +* @name: the name of the property +* @target: the object to be referred by the link +* @errp: if an error occurs, a pointer to an area to store the error +* +* Add an unmodifiable link for a property on an object. This function will +* add a property of type link<TYPE> where TYPE is the type of @target. +* +* The caller must ensure that @target stays alive as long as +* this property exists. In the case @target is a child of @obj, +* this will be the case. Otherwise, the caller is responsible for +* taking a reference. +*/ +void object_property_add_const_link (Object *obj,const char *name, +Object *target,Error **errp); + +/** * object_property_set_description: * @obj: the object owning the property * @name: the name of the property
qom/object.c +16 -0
@@ -1266,6 +1266,22 @@ out:g_free (full_type); } +void object_property_add_const_link (Object *obj,const char *name, +Object *target,Error **errp) +{ +char *link_type; +ObjectProperty *op; + + link_type =g_strdup_printf ("link<%s>" ,object_get_typename (target)); + op =object_property_add (obj, name, link_type, + object_get_child_property,NULL , +NULL , target, errp); +if (op !=NULL ) { + op->resolve = object_resolve_child_property; + } +g_free (link_type); +} +gchar *object_get_canonical_path_component (Object *obj) {ObjectProperty *prop =NULL ;
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 11/31] qom: add object_property_add_const_link
Quoted 41 lines · Paolo Bonzini
Suggested-by Eduardo Habkost <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- include/qom/object.h | 18 ++++++++++++++++++ qom/object.c | 16 ++++++++++++++++ 2 files changed, 34 insertions(+)include/qom/object.h +18
-0@@ -1290,6 +1290,24 @@ void object_property_add_alias(Object *obj, const char *name, Error **errp);/** +* object_property_add_const_link: +* @obj: the object to add a property to +* @name: the name of the property +* @target: the object to be referred by the link +* @errp: if an error occurs, a pointer to an area to store the error +* +* Add an unmodifiable link for a property on an object. This function will +* add a property of type link<TYPE> where TYPE is the type of @target. +* +* The caller must ensure that @target stays alive as long as +* this property exists. In the case @target is a child of @obj, +* this will be the case. Otherwise, the caller is responsible for +* taking a reference. +*/ +void object_property_add_const_link (Object *obj,const char *name, +Object *target,Error **errp); + +/** * object_property_set_description: * @obj: the object owning the property * @name: the name of the property qom/object.c +0
-0
qom/object.c out: · line 1274
Quoted 9 lines
qom/object.c +6
-0@@ -1266,6 +1266,22 @@ out:g_free (full_type); } +void object_property_add_const_link (Object *obj,const char *name, +Object *target,Error **errp) +{ +char *link_type; +ObjectProperty *op; +
git-am complained about trailing whitespace on the line above.
(Sorry that's all I can "contribute" now; I'll start using the series for developing OVMF further on.)
Thanks
Laszlo
Quoted 14 lines
qom/object.c +10
-0+ link_type =g_strdup_printf ("link<%s>" ,object_get_typename (target)); + op =object_property_add (obj, name, link_type, + object_get_child_property,NULL , +NULL , target, errp); +if (op !=NULL ) { + op->resolve = object_resolve_child_property; + } +g_free (link_type); +} +gchar *object_get_canonical_path_component (Object *obj) {ObjectProperty *prop =NULL ;
Re: [Qemu-devel] [PATCH 11/31] qom: add object_property_add_const_link
In reply to Paolo BonziniAndreas, Eduardo,
can you review and ack this one?
Quoted 64 lines · Paolo Bonzini
Suggested-by Eduardo Habkost <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- include/qom/object.h | 18 ++++++++++++++++++ qom/object.c | 16 ++++++++++++++++ 2 files changed, 34 insertions(+)include/qom/object.h +18
-0@@ -1290,6 +1290,24 @@ void object_property_add_alias(Object *obj, const char *name, Error **errp);/** +* object_property_add_const_link: +* @obj: the object to add a property to +* @name: the name of the property +* @target: the object to be referred by the link +* @errp: if an error occurs, a pointer to an area to store the error +* +* Add an unmodifiable link for a property on an object. This function will +* add a property of type link<TYPE> where TYPE is the type of @target. +* +* The caller must ensure that @target stays alive as long as +* this property exists. In the case @target is a child of @obj, +* this will be the case. Otherwise, the caller is responsible for +* taking a reference. +*/ +void object_property_add_const_link (Object *obj,const char *name, +Object *target,Error **errp); + +/** * object_property_set_description: * @obj: the object owning the property * @name: the name of the property qom/object.c +16
-0@@ -1266,6 +1266,22 @@ out:g_free (full_type); } +void object_property_add_const_link (Object *obj,const char *name, +Object *target,Error **errp) +{ +char *link_type; +ObjectProperty *op; + + link_type =g_strdup_printf ("link<%s>" ,object_get_typename (target)); + op =object_property_add (obj, name, link_type, + object_get_child_property,NULL , +NULL , target, errp); +if (op !=NULL ) { + op->resolve = object_resolve_child_property; + } +g_free (link_type); +} +gchar *object_get_canonical_path_component (Object *obj) {ObjectProperty *prop =NULL ;
Re: [Qemu-devel] [PATCH 11/31] qom: add object_property_add_const_link
In reply to Paolo BonziniQuoted 2 lines · Paolo Bonzini
Suggested-by Eduardo Habkost <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>
Assuming that the whitespace warning Laszlo pointed out will be fixed:
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH 11/31] qom: add object_property_add_const_link
Am 19.05.2015 um 21:14 schrieb Eduardo Habkost:
Quoted 7 lines · Paolo Bonzini
Quoted 2 lines
Suggested-by Eduardo Habkost <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>Assuming that the whitespace warning Laszlo pointed out will be fixed:
Reviewed-by Eduardo Habkost <[email protected]>
Three spaces deleted and commit message extended, applied to qom-next:
https://github.com/afaerber/qemu-cpu/commits/qom-next
Thanks,
Andreas
Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Felix Imendörffer, Jane Smithard, Dilip Upmanyu, Graham Norton; HRB 21284 (AG Nürnberg)
PATCH 12/31 vl: run "late" notifiers immediately
In reply to Paolo BonziniIf a machine_init_done notifier is added late, as part of a hot-plugged device, run it immediately.
--- vl.c | 6 ++++++ 1 file changed, 6 insertions(+)
vl.c +6 -0
@@ -2501,14 +2501,20 @@ static void qemu_run_exit_notifiers(void)notifier_list_notify (&exit_notifiers,NULL ); } +static bool machine_init_done; +void qemu_add_machine_init_done_notifier (Notifier *notify) {notifier_list_add (&machine_init_done_notifiers, notify); +if (machine_init_done) { + notify->notify (notify,NULL ); + } }static void qemu_run_machine_init_done_notifiers (void ) {notifier_list_notify (&machine_init_done_notifiers,NULL ); + machine_init_done = true; } static const QEMUOption *lookup_opt(int argc, char **argv,
Signature · 1 line
1.8.3.1
PATCH 13/31 target-i386: create a separate AddressSpace for each CPU
In reply to Paolo BonziniDifferent CPUs can be in SMM or not at the same time, thus they will see different things where the chipset places SMRAM.
--- target-i386/cpu-qom.h | 1 + target-i386/cpu.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+)
target-i386/cpu-qom.h +1 -0
@@ -111,6 +111,7 @@ typedef struct X86CPU {/* in order to simplify APIC support, we leave this pointer to the user */ struct DeviceState *apic_state; +struct MemoryRegion *cpu_as_root; }X86CPU ;static inline X86CPU *x86_env_get_cpu (CPUX86State *env)
target-i386/cpu.c +14 -0
@@ -44,6 +44,7 @@#include "hw/qdev-properties.h" #include "hw/cpu/icc_bus.h" #ifndef CONFIG_USER_ONLY +#include "exec/address-spaces.h" #include "hw/xen/xen.h" #include "hw/i386/apic_internal.h" #endif
@@ -2811,6 +2812,18 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)#endif mce_init (cpu); + +#ifndef CONFIG_USER_ONLY +if (tcg_enabled ()) { + cpu->cpu_as_root =g_new (MemoryRegion,1 ); + cs->as =g_new (AddressSpace,1 ); +memory_region_init_alias (cpu->cpu_as_root,OBJECT (cpu),"memory" , +get_system_memory (),0 , ~0ull ); +memory_region_set_enabled (cpu->cpu_as_root, true); +address_space_init (cs->as, cpu->cpu_as_root,"CPU" ); + } +#endif +qemu_init_vcpu (cs);/* Only Intel CPUs support hyperthreading. Even though QEMU fixes this
@@ -2834,6 +2847,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)cpu_reset (cs); xcc->parent_realize (dev, &local_err); + out:if (local_err !=NULL ) {error_propagate (errp, local_err);
Signature · 1 line
1.8.3.1
PATCH 14/31 hw/i386: add a separate region that tracks the SMRAME bit
In reply to Paolo BonziniThis region is exported at /machine/smram. It is "empty" if SMRAME=0 and points to SMRAM if SMRAME=1. The CPU will enable/disable it as it enters or exits SMRAM.
--- hw/pci-host/piix.c | 15 +++++++++++++++ hw/pci-host/q35.c | 15 ++++++++++++++- include/hw/pci-host/q35.h | 1 + 3 files changed, 30 insertions(+), 1 deletion(-)
hw/pci-host/piix.c +15 -0
@@ -105,6 +105,7 @@ struct PCII440FXState {MemoryRegion *ram_memory;PAMMemoryRegion pam_regions[13 ];MemoryRegion smram_region; +MemoryRegion smram, low_smram;uint8_t smm_enabled; };
@@ -139,6 +140,8 @@ static void i440fx_update_memory_mappings(PCII440FXState *d) pd->config[I440FX_PAM + ((i + 1) / 2)]); }smram_update (&d->smram_region, pd->config[I440FX_SMRAM ], d->smm_enabled); +memory_region_set_enabled (&d->smram, + pd->config[I440FX_SMRAM ] &SMRAM_G_SMRAME );memory_region_transaction_commit (); }
@@ -346,11 +349,23 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,pc_pci_as_mapping_init (OBJECT (f), f->system_memory, f->pci_address_space); +/* if *disabled* show SMRAM to all CPUs */ memory_region_init_alias (&f->smram_region,OBJECT (d),"smram-region" , f->pci_address_space,0xa0000 ,0x20000 );memory_region_add_subregion_overlap (f->system_memory,0xa0000 , &f->smram_region,1 );memory_region_set_enabled (&f->smram_region, false); + +/* smram, as seen by SMM CPUs */ +memory_region_init (&f->smram,OBJECT (d),"smram" ,1ull <<32 ); +memory_region_set_enabled (&f->smram, true); +memory_region_init_alias (&f->low_smram,OBJECT (d),"smram-low" , + f->system_memory,0xa0000 ,0x20000 ); +memory_region_set_enabled (&f->low_smram, true); +memory_region_add_subregion (&f->smram,0xa0000 , &f->low_smram); +object_property_add_alias (qdev_get_machine (),"smram" , +OBJECT (&f->smram),"." ,NULL ); +init_pam (dev, f->ram_memory, f->system_memory, f->pci_address_space, &f->pam_regions[0 ],PAM_BIOS_BASE ,PAM_BIOS_SIZE );for (i =0 ; i <12 ; ++i) {
hw/pci-host/q35.c +14 -1
@@ -270,6 +270,8 @@ static void mch_update_smram(MCHPCIState *mch)memory_region_transaction_begin ();smram_update (&mch->smram_region, pd->config[MCH_HOST_BRIDGE_SMRAM ], mch->smm_enabled); +memory_region_set_enabled (&mch->smram, + pd->config[MCH_HOST_BRIDGE_SMRAM ] &SMRAM_G_SMRAME );memory_region_transaction_commit (); }
@@ -399,13 +401,24 @@ static void mch_realize(PCIDevice *d, Error **errp)pc_pci_as_mapping_init (OBJECT (mch), mch->system_memory, mch->pci_address_space); -/* smram */ +/* if *disabled* show SMRAM to all CPUs */ cpu_smm_register (&mch_set_smm, mch);memory_region_init_alias (&mch->smram_region,OBJECT (mch),"smram-region" , mch->pci_address_space,0xa0000 ,0x20000 );memory_region_add_subregion_overlap (mch->system_memory,0xa0000 , &mch->smram_region,1 );memory_region_set_enabled (&mch->smram_region, false); + +/* smram, as seen by SMM CPUs */ +memory_region_init (&mch->smram,OBJECT (mch),"smram" ,1ull <<32 ); +memory_region_set_enabled (&mch->smram, true); +memory_region_init_alias (&mch->low_smram,OBJECT (mch),"smram-low" , + mch->system_memory,0xa0000 ,0x20000 ); +memory_region_set_enabled (&mch->low_smram, true); +memory_region_add_subregion (&mch->smram,0xa0000 , &mch->low_smram); +object_property_add_const_link (qdev_get_machine (),"smram" , +OBJECT (&mch->smram), &error_abort); +init_pam (DEVICE (mch), mch->ram_memory, mch->system_memory, mch->pci_address_space, &mch->pam_regions[0 ],PAM_BIOS_BASE ,PAM_BIOS_SIZE );
include/hw/pci-host/q35.h +1 -0
@@ -53,6 +53,7 @@ typedef struct MCHPCIState {MemoryRegion *address_space_io;PAMMemoryRegion pam_regions[13 ];MemoryRegion smram_region; +MemoryRegion smram, low_smram;PcPciInfo pci_info;uint8_t smm_enabled;ram_addr_t below_4g_mem_size;
Signature · 1 line
1.8.3.1
PATCH 15/31 target-i386: use memory API to implement SMRAM
In reply to Paolo BonziniRemove cpu_smm_register and cpu_smm_update. Instead, each CPU address space gets an extra region which is an alias of /machine/smram. This extra region is enabled or disabled as the CPU enters/exits SMM.
--- bsd-user/main.c | 4 ---- hw/i386/pc.c | 21 --------------------- hw/pci-host/pam.c | 18 ++---------------- hw/pci-host/piix.c | 25 +++++-------------------- hw/pci-host/q35.c | 19 +++---------------- include/hw/i386/pc.h | 1 - include/hw/pci-host/pam.h | 5 +---- include/hw/pci-host/q35.h | 1 - linux-user/main.c | 4 ---- target-i386/cpu-qom.h | 4 +++- target-i386/cpu.c | 33 +++++++++++++++++++++++++++++++-- target-i386/cpu.h | 3 ++- target-i386/machine.c | 3 +++ target-i386/smm_helper.c | 12 ++++++++++-- 14 files changed, 60 insertions(+), 93 deletions(-)
bsd-user/main.c +0 -4
@@ -108,10 +108,6 @@ void cpu_list_unlock(void)/***********************************************************/ /* CPUX86 core interface */ -void cpu_smm_update (CPUX86State *env) -{ -} -uint64_t cpu_get_tsc (CPUX86State *env) {return cpu_get_real_ticks ();
hw/i386/pc.c +0 -21
@@ -163,27 +163,6 @@ uint64_t cpu_get_tsc(CPUX86State *env)return cpu_get_ticks (); } -/* SMM support */ - -static cpu_set_smm_t smm_set; -static void *smm_arg; - -void cpu_smm_register (cpu_set_smm_t callback,void *arg) -{ -assert (smm_set ==NULL ); -assert (smm_arg ==NULL ); - smm_set = callback; - smm_arg = arg; -} - -void cpu_smm_update (CPUX86State *env) -{ -if (smm_set && smm_arg &&CPU (x86_env_get_cpu (env)) == first_cpu) { -smm_set (!!(env->hflags &HF_SMM_MASK ), smm_arg); - } -} - -/* IRQ handling */ int cpu_get_pic_interrupt (CPUX86State *env) {
hw/pci-host/pam.c +2 -16
@@ -31,26 +31,12 @@#include "sysemu/sysemu.h" #include "hw/pci-host/pam.h" -void smram_update (MemoryRegion *smram_region,uint8_t smram, -uint8_t smm_enabled) +void smram_update (MemoryRegion *smram_region,uint8_t smram) { -bool smram_enabled; - - smram_enabled = ((smm_enabled && (smram &SMRAM_G_SMRAME )) || - (smram &SMRAM_D_OPEN )); +bool smram_enabled = (smram &SMRAM_D_OPEN );memory_region_set_enabled (smram_region, !smram_enabled); } -void smram_set_smm (uint8_t *host_smm_enabled,int smm,uint8_t smram, -MemoryRegion *smram_region) -{ -uint8_t smm_enabled = (smm !=0 ); -if (*host_smm_enabled != smm_enabled) { - *host_smm_enabled = smm_enabled; -smram_update (smram_region, smram, *host_smm_enabled); - } -} -void init_pam (DeviceState *dev,MemoryRegion *ram_memory,MemoryRegion *system_memory,MemoryRegion *pci_address_space,PAMMemoryRegion *mem,uint32_t start,uint32_t size)
hw/pci-host/piix.c +5 -20
@@ -106,7 +106,6 @@ struct PCII440FXState {PAMMemoryRegion pam_regions[13 ];MemoryRegion smram_region;MemoryRegion smram, low_smram; -uint8_t smm_enabled; };
@@ -139,23 +138,12 @@ static void i440fx_update_memory_mappings(PCII440FXState *d)pam_update (&d->pam_regions[i], i, pd->config[I440FX_PAM + ((i +1 ) /2 )]); } -smram_update (&d->smram_region, pd->config[I440FX_SMRAM ], d->smm_enabled); +smram_update (&d->smram_region, pd->config[I440FX_SMRAM ]);memory_region_set_enabled (&d->smram, pd->config[I440FX_SMRAM ] &SMRAM_G_SMRAME );memory_region_transaction_commit (); } -static void i440fx_set_smm (int val,void *arg) -{ -PCII440FXState *d = arg; -PCIDevice *pd =PCI_DEVICE (d); - -memory_region_transaction_begin (); -smram_set_smm (&d->smm_enabled, val, pd->config[I440FX_SMRAM ], - &d->smram_region); -memory_region_transaction_commit (); -} -static void i440fx_write_config (PCIDevice *dev,uint32_t address,uint32_t val,int len)
@@ -175,12 +163,13 @@ static int i440fx_load_old(QEMUFile* f, void *opaque, int version_id)PCII440FXState *d = opaque;PCIDevice *pd =PCI_DEVICE (d);int ret, i; +uint8_t smm_enabled; ret =pci_device_load (pd, f);if (ret <0 )return ret;i440fx_update_memory_mappings (d); -qemu_get_8s (f, &d->smm_enabled); +qemu_get_8s (f, &smm_enabled);if (version_id ==2 ) {for (i =0 ; i <PIIX_NUM_PIRQS ; i++) {
@@ -208,7 +197,7 @@ static const VMStateDescription vmstate_i440fx = { .post_load = i440fx_post_load, .fields = (VMStateField []) {VMSTATE_PCI_DEVICE (parent_obj, PCII440FXState), -VMSTATE_UINT8 (smm_enabled, PCII440FXState), +VMSTATE_UNUSED (1 ),VMSTATE_END_OF_LIST () } };
@@ -300,11 +289,7 @@ static void i440fx_pcihost_realize(DeviceState *dev, Error **errp)static void i440fx_realize (PCIDevice *dev,Error **errp) { -PCII440FXState *d =I440FX_PCI_DEVICE (dev); - dev->config[I440FX_SMRAM ] =0x02 ; - -cpu_smm_register (&i440fx_set_smm, d); } PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
@@ -360,7 +345,7 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,memory_region_init (&f->smram,OBJECT (d),"smram" ,1ull <<32 );memory_region_set_enabled (&f->smram, true);memory_region_init_alias (&f->low_smram,OBJECT (d),"smram-low" , - f->system_memory,0xa0000 ,0x20000 ); + f->ram_memory,0xa0000 ,0x20000 );memory_region_set_enabled (&f->low_smram, true);memory_region_add_subregion (&f->smram,0xa0000 , &f->low_smram); object_property_add_alias(qdev_get_machine(), "smram",
hw/pci-host/q35.c +3 -16
@@ -268,24 +268,12 @@ static void mch_update_smram(MCHPCIState *mch)PCIDevice *pd =PCI_DEVICE (mch);memory_region_transaction_begin (); -smram_update (&mch->smram_region, pd->config[MCH_HOST_BRIDGE_SMRAM ], - mch->smm_enabled); +smram_update (&mch->smram_region, pd->config[MCH_HOST_BRIDGE_SMRAM ]);memory_region_set_enabled (&mch->smram, pd->config[MCH_HOST_BRIDGE_SMRAM ] &SMRAM_G_SMRAME );memory_region_transaction_commit (); } -static void mch_set_smm (int smm,void *arg) -{ -MCHPCIState *mch = arg; -PCIDevice *pd =PCI_DEVICE (mch); - -memory_region_transaction_begin (); -smram_set_smm (&mch->smm_enabled, smm, pd->config[MCH_HOST_BRIDGE_SMRAM ], - &mch->smram_region); -memory_region_transaction_commit (); -} -static void mch_write_config (PCIDevice *d,uint32_t address,uint32_t val,int len) {
@@ -331,7 +319,7 @@ static const VMStateDescription vmstate_mch = { .post_load = mch_post_load, .fields = (VMStateField []) {VMSTATE_PCI_DEVICE (parent_obj, MCHPCIState), -VMSTATE_UINT8 (smm_enabled, MCHPCIState), +VMSTATE_UNUSED (1 ),VMSTATE_END_OF_LIST () } };
@@ -402,7 +390,6 @@ static void mch_realize(PCIDevice *d, Error **errp) mch->pci_address_space);/* if *disabled* show SMRAM to all CPUs */ -cpu_smm_register (&mch_set_smm, mch);memory_region_init_alias (&mch->smram_region,OBJECT (mch),"smram-region" , mch->pci_address_space,0xa0000 ,0x20000 ); memory_region_add_subregion_overlap(mch->system_memory, 0xa0000,
@@ -413,7 +400,7 @@ static void mch_realize(PCIDevice *d, Error **errp)memory_region_init (&mch->smram,OBJECT (mch),"smram" ,1ull <<32 );memory_region_set_enabled (&mch->smram, true);memory_region_init_alias (&mch->low_smram,OBJECT (mch),"smram-low" , - mch->system_memory,0xa0000 ,0x20000 ); + mch->ram_memory,0xa0000 ,0x20000 );memory_region_set_enabled (&mch->low_smram, true);memory_region_add_subregion (&mch->smram,0xa0000 , &mch->low_smram); object_property_add_const_link(qdev_get_machine(), "smram",
include/hw/i386/pc.h +0 -1
@@ -211,7 +211,6 @@ void pc_nic_init(ISABus *isa_bus, PCIBus *pci_bus);void pc_pci_device_init (PCIBus *pci_bus);typedef void (*cpu_set_smm_t )(int smm,void *arg); -void cpu_smm_register (cpu_set_smm_t callback,void *arg);void ioapic_init_gsi (GSIState *gsi_state,const char *parent_name);
include/hw/pci-host/pam.h +1 -4
@@ -86,10 +86,7 @@ typedef struct PAMMemoryRegion {unsigned current; } PAMMemoryRegion; -void smram_update (MemoryRegion *smram_region,uint8_t smram, -uint8_t smm_enabled); -void smram_set_smm (uint8_t *host_smm_enabled,int smm,uint8_t smram, -MemoryRegion *smram_region); +void smram_update (MemoryRegion *smram_region,uint8_t smram);void init_pam (DeviceState *dev,MemoryRegion *ram,MemoryRegion *system,MemoryRegion *pci,PAMMemoryRegion *mem,uint32_t start,uint32_t size);void pam_update (PAMMemoryRegion *mem,int idx,uint8_t val);
include/hw/pci-host/q35.h +0 -1
@@ -55,7 +55,6 @@ typedef struct MCHPCIState {MemoryRegion smram_region;MemoryRegion smram, low_smram;PcPciInfo pci_info; -uint8_t smm_enabled;ram_addr_t below_4g_mem_size;ram_addr_t above_4g_mem_size;uint64_t pci_hole64_size;
linux-user/main.c +0 -4
@@ -215,10 +215,6 @@ void cpu_list_unlock(void)/***********************************************************/ /* CPUX86 core interface */ -void cpu_smm_update (CPUX86State *env) -{ -} -uint64_t cpu_get_tsc (CPUX86State *env) {return cpu_get_real_ticks ();
target-i386/cpu-qom.h +3 -1
@@ -23,6 +23,7 @@#include "qom/cpu.h" #include "cpu.h" #include "qapi/error.h" +#include "qemu/notify.h" #ifdef TARGET_X86_64 #define TYPE_X86_CPU "x86_64-cpu"
@@ -111,7 +112,8 @@ typedef struct X86CPU {/* in order to simplify APIC support, we leave this pointer to the user */ struct DeviceState *apic_state; -struct MemoryRegion *cpu_as_root; +struct MemoryRegion *cpu_as_root, *cpu_as_mem, *smram; +Notifier machine_done; }X86CPU ;static inline X86CPU *x86_env_get_cpu (CPUX86State *env)
target-i386/cpu.c +31 -2
@@ -2751,6 +2751,21 @@ static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)object_property_set_bool (OBJECT (cpu->apic_state), true,"realized" , errp); } + +static void x86_cpu_machine_done (Notifier *n,void *unused) +{ +X86CPU *cpu =container_of (n,X86CPU , machine_done); +MemoryRegion *smram = + (MemoryRegion *)object_resolve_path ("/machine/smram" ,NULL ); + +if (smram) { + cpu->smram =g_new (MemoryRegion,1 ); +memory_region_init_alias (cpu->smram,OBJECT (cpu),"smram" , + smram,0 ,1ull <<32 ); +memory_region_set_enabled (cpu->smram, false); +memory_region_add_subregion_overlap (cpu->cpu_as_root,0 , cpu->smram,1 ); + } +}#else static void x86_cpu_apic_realize (X86CPU *cpu,Error **errp) {
@@ -2815,12 +2830,26 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)#ifndef CONFIG_USER_ONLY if (tcg_enabled ()) { + cpu->cpu_as_mem =g_new (MemoryRegion,1 ); cpu->cpu_as_root =g_new (MemoryRegion,1 ); cs->as =g_new (AddressSpace,1 ); -memory_region_init_alias (cpu->cpu_as_root,OBJECT (cpu),"memory" , -get_system_memory (),0 , ~0ull ); + +/* Outer container... */ +memory_region_init (cpu->cpu_as_root,OBJECT (cpu),"memory" , ~0ull );memory_region_set_enabled (cpu->cpu_as_root, true); + +/* ... with two regions inside: normal system memory with low +* priority, and... +*/ +memory_region_init_alias (cpu->cpu_as_mem,OBJECT (cpu),"memory" , +get_system_memory (),0 , ~0ull ); +memory_region_add_subregion_overlap (cpu->cpu_as_root,0 , cpu->cpu_as_mem,0 ); +memory_region_set_enabled (cpu->cpu_as_mem, true);address_space_init (cs->as, cpu->cpu_as_root,"CPU" ); + +/* ... SMRAM with higher priority, linked from /machine/smram. */ + cpu->machine_done.notify = x86_cpu_machine_done; +qemu_add_machine_init_done_notifier (&cpu->machine_done); }#endif
target-i386/cpu.h +2 -1
@@ -1157,7 +1157,6 @@ void cpu_x86_update_cr3(CPUX86State *env, target_ulong new_cr3);void cpu_x86_update_cr4 (CPUX86State *env,uint32_t new_cr4);/* hw/pc.c */ -void cpu_smm_update (CPUX86State *env);uint64_t cpu_get_tsc (CPUX86State *env);#define TARGET_PAGE_BITS 12
@@ -1323,7 +1322,9 @@ void cpu_vmexit(CPUX86State *nenv, uint32_t exit_code, uint64_t exit_info_1);/* seg_helper.c */ void do_interrupt_x86_hardirq (CPUX86State *env,int intno,int is_hw); +/* smm_helper.c */ void do_smm_enter (X86CPU *cpu); +void cpu_smm_update (X86CPU *cpu);void cpu_report_tpr_access (CPUX86State *env,TPRAccess access);
target-i386/machine.c +3 -0
@@ -372,6 +372,9 @@ static int cpu_post_load(void *opaque, int version_id) }tlb_flush (cs,1 ); +if (tcg_enabled ()) { +cpu_smm_update (cpu); + }return 0 ; }
target-i386/smm_helper.c +10 -2
@@ -40,6 +40,14 @@ void helper_rsm(CPUX86State *env)#define SMM_REVISION_ID 0x00020000#endif +void cpu_smm_update (X86CPU *cpu) +{ +CPUX86State *env = &cpu->env; +bool smm_enabled = (env->hflags &HF_SMM_MASK ); + +memory_region_set_enabled (cpu->smram, smm_enabled); +} +void do_smm_enter (X86CPU *cpu) {CPUX86State *env = &cpu->env;
@@ -57,7 +65,7 @@ void do_smm_enter(X86CPU *cpu) }else { env->hflags2 |=HF2_NMI_MASK ; } -cpu_smm_update (env); +cpu_smm_update (cpu); sm_state = env->smbase +0x8000 ;
@@ -317,7 +325,7 @@ void helper_rsm(CPUX86State *env) } env->hflags2 &= ~HF2_SMM_INSIDE_NMI_MASK ; env->hflags &= ~HF_SMM_MASK ; -cpu_smm_update (env); +cpu_smm_update (cpu);qemu_log_mask (CPU_LOG_INT ,"SMM: after RSM\n" );log_cpu_state_mask (CPU_LOG_INT ,CPU (cpu),CPU_DUMP_CCOP );
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 15/31] target-i386: use memory API to implement SMRAM
Quoted 156 lines · Paolo Bonzini
Remove
cpu_smm_registerandcpu_smm_update. Instead, each CPU address space gets an extra region which is an alias of /machine/smram. This extra region is enabled or disabled as the CPU enters/exits SMM.Signed-off-by Paolo Bonzini <[email protected]>--- bsd-user/main.c | 4 ---- hw/i386/pc.c | 21 --------------------- hw/pci-host/pam.c | 18 ++---------------- hw/pci-host/piix.c | 25 +++++-------------------- hw/pci-host/q35.c | 19 +++---------------- include/hw/i386/pc.h | 1 - include/hw/pci-host/pam.h | 5 +---- include/hw/pci-host/q35.h | 1 - linux-user/main.c | 4 ---- target-i386/cpu-qom.h | 4 +++- target-i386/cpu.c | 33 +++++++++++++++++++++++++++++++-- target-i386/cpu.h | 3 ++- target-i386/machine.c | 3 +++ target-i386/smm_helper.c | 12 ++++++++++-- 14 files changed, 60 insertions(+), 93 deletions(-)bsd-user/main.c +0
-4@@ -108,10 +108,6 @@ void cpu_list_unlock(void)/***********************************************************/ /* CPUX86 core interface */ -void cpu_smm_update (CPUX86State *env) -{ -} -uint64_t cpu_get_tsc (CPUX86State *env) {return cpu_get_real_ticks ();hw/i386/pc.c +0
-21@@ -163,27 +163,6 @@ uint64_t cpu_get_tsc(CPUX86State *env)return cpu_get_ticks (); } -/* SMM support */ - -static cpu_set_smm_t smm_set; -static void *smm_arg; - -void cpu_smm_register (cpu_set_smm_t callback,void *arg) -{ -assert (smm_set ==NULL ); -assert (smm_arg ==NULL ); - smm_set = callback; - smm_arg = arg; -} - -void cpu_smm_update (CPUX86State *env) -{ -if (smm_set && smm_arg &&CPU (x86_env_get_cpu (env)) == first_cpu) { -smm_set (!!(env->hflags &HF_SMM_MASK ), smm_arg); - } -} - -/* IRQ handling */ int cpu_get_pic_interrupt (CPUX86State *env) {hw/pci-host/pam.c +2
-16@@ -31,26 +31,12 @@#include "sysemu/sysemu.h" #include "hw/pci-host/pam.h" -void smram_update (MemoryRegion *smram_region,uint8_t smram, -uint8_t smm_enabled) +void smram_update (MemoryRegion *smram_region,uint8_t smram) { -bool smram_enabled; - - smram_enabled = ((smm_enabled && (smram &SMRAM_G_SMRAME )) || - (smram &SMRAM_D_OPEN )); +bool smram_enabled = (smram &SMRAM_D_OPEN );memory_region_set_enabled (smram_region, !smram_enabled); } -void smram_set_smm (uint8_t *host_smm_enabled,int smm,uint8_t smram, -MemoryRegion *smram_region) -{ -uint8_t smm_enabled = (smm !=0 ); -if (*host_smm_enabled != smm_enabled) { - *host_smm_enabled = smm_enabled; -smram_update (smram_region, smram, *host_smm_enabled); - } -} -void init_pam (DeviceState *dev,MemoryRegion *ram_memory,MemoryRegion *system_memory,MemoryRegion *pci_address_space,PAMMemoryRegion *mem,uint32_t start,uint32_t size)hw/pci-host/piix.c +3
-14@@ -106,7 +106,6 @@ struct PCII440FXState {PAMMemoryRegion pam_regions[13 ];MemoryRegion smram_region;MemoryRegion smram, low_smram; -uint8_t smm_enabled; };@@ -139,23 +138,12 @@ static void i440fx_update_memory_mappings(PCII440FXState *d)pam_update (&d->pam_regions[i], i, pd->config[I440FX_PAM + ((i +1 ) /2 )]); } -smram_update (&d->smram_region, pd->config[I440FX_SMRAM ], d->smm_enabled); +smram_update (&d->smram_region, pd->config[I440FX_SMRAM ]);memory_region_set_enabled (&d->smram, pd->config[I440FX_SMRAM ] &SMRAM_G_SMRAME );memory_region_transaction_commit (); } -static void i440fx_set_smm (int val,void *arg) -{ -PCII440FXState *d = arg; -PCIDevice *pd =PCI_DEVICE (d); - -memory_region_transaction_begin (); -smram_set_smm (&d->smm_enabled, val, pd->config[I440FX_SMRAM ], - &d->smram_region); -memory_region_transaction_commit (); -} -static void i440fx_write_config (PCIDevice *dev,uint32_t address,uint32_t val,int len)@@ -175,12 +163,13 @@ static int i440fx_load_old(QEMUFile* f, void *opaque, int version_id)PCII440FXState *d = opaque;PCIDevice *pd =PCI_DEVICE (d);int ret, i; +uint8_t smm_enabled; ret =pci_device_load (pd, f);if (ret <0 )return ret;i440fx_update_memory_mappings (d); -qemu_get_8s (f, &d->smm_enabled); +qemu_get_8s (f, &smm_enabled);if (version_id ==2 ) {for (i =0 ; i <PIIX_NUM_PIRQS ; i++) {
hw/pci-host/piix.c static const VMStateDescription vmstate_i440fx = { · line 203
Quoted 8 lines
hw/pci-host/piix.c +1
-1@@ -208,7 +197,7 @@ static const VMStateDescription vmstate_i440fx = { .post_load = i440fx_post_load, .fields = (VMStateField []) {VMSTATE_PCI_DEVICE (parent_obj, PCII440FXState), -VMSTATE_UINT8 (smm_enabled, PCII440FXState), +VMSTATE_UNUSED (1 ),VMSTATE_END_OF_LIST () } };
Won't this cause problems for cross-version migration? Old qemu receiving this will think smm is enabled, unconditionally.
Quoted 285 lines
hw/pci-host/piix.c +1
-5@@ -300,11 +289,7 @@ static void i440fx_pcihost_realize(DeviceState *dev, Error **errp)static void i440fx_realize (PCIDevice *dev,Error **errp) { -PCII440FXState *d =I440FX_PCI_DEVICE (dev); - dev->config[I440FX_SMRAM ] =0x02 ; - -cpu_smm_register (&i440fx_set_smm, d); } PCIBus *i440fx_init(PCII440FXState **pi440fx_state,@@ -360,7 +345,7 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,memory_region_init (&f->smram,OBJECT (d),"smram" ,1ull <<32 );memory_region_set_enabled (&f->smram, true);memory_region_init_alias (&f->low_smram,OBJECT (d),"smram-low" , - f->system_memory,0xa0000 ,0x20000 ); + f->ram_memory,0xa0000 ,0x20000 );memory_region_set_enabled (&f->low_smram, true);memory_region_add_subregion (&f->smram,0xa0000 , &f->low_smram); object_property_add_alias(qdev_get_machine(), "smram",hw/pci-host/q35.c +3
-16@@ -268,24 +268,12 @@ static void mch_update_smram(MCHPCIState *mch)PCIDevice *pd =PCI_DEVICE (mch);memory_region_transaction_begin (); -smram_update (&mch->smram_region, pd->config[MCH_HOST_BRIDGE_SMRAM ], - mch->smm_enabled); +smram_update (&mch->smram_region, pd->config[MCH_HOST_BRIDGE_SMRAM ]);memory_region_set_enabled (&mch->smram, pd->config[MCH_HOST_BRIDGE_SMRAM ] &SMRAM_G_SMRAME );memory_region_transaction_commit (); } -static void mch_set_smm (int smm,void *arg) -{ -MCHPCIState *mch = arg; -PCIDevice *pd =PCI_DEVICE (mch); - -memory_region_transaction_begin (); -smram_set_smm (&mch->smm_enabled, smm, pd->config[MCH_HOST_BRIDGE_SMRAM ], - &mch->smram_region); -memory_region_transaction_commit (); -} -static void mch_write_config (PCIDevice *d,uint32_t address,uint32_t val,int len) {@@ -331,7 +319,7 @@ static const VMStateDescription vmstate_mch = { .post_load = mch_post_load, .fields = (VMStateField []) {VMSTATE_PCI_DEVICE (parent_obj, MCHPCIState), -VMSTATE_UINT8 (smm_enabled, MCHPCIState), +VMSTATE_UNUSED (1 ),VMSTATE_END_OF_LIST () } };@@ -402,7 +390,6 @@ static void mch_realize(PCIDevice *d, Error **errp) mch->pci_address_space);/* if *disabled* show SMRAM to all CPUs */ -cpu_smm_register (&mch_set_smm, mch);memory_region_init_alias (&mch->smram_region,OBJECT (mch),"smram-region" , mch->pci_address_space,0xa0000 ,0x20000 ); memory_region_add_subregion_overlap(mch->system_memory, 0xa0000,@@ -413,7 +400,7 @@ static void mch_realize(PCIDevice *d, Error **errp)memory_region_init (&mch->smram,OBJECT (mch),"smram" ,1ull <<32 );memory_region_set_enabled (&mch->smram, true);memory_region_init_alias (&mch->low_smram,OBJECT (mch),"smram-low" , - mch->system_memory,0xa0000 ,0x20000 ); + mch->ram_memory,0xa0000 ,0x20000 );memory_region_set_enabled (&mch->low_smram, true);memory_region_add_subregion (&mch->smram,0xa0000 , &mch->low_smram); object_property_add_const_link(qdev_get_machine(), "smram",include/hw/i386/pc.h +0
-1@@ -211,7 +211,6 @@ void pc_nic_init(ISABus *isa_bus, PCIBus *pci_bus);void pc_pci_device_init (PCIBus *pci_bus);typedef void (*cpu_set_smm_t )(int smm,void *arg); -void cpu_smm_register (cpu_set_smm_t callback,void *arg);void ioapic_init_gsi (GSIState *gsi_state,const char *parent_name);include/hw/pci-host/pam.h +1
-4@@ -86,10 +86,7 @@ typedef struct PAMMemoryRegion {unsigned current; } PAMMemoryRegion; -void smram_update (MemoryRegion *smram_region,uint8_t smram, -uint8_t smm_enabled); -void smram_set_smm (uint8_t *host_smm_enabled,int smm,uint8_t smram, -MemoryRegion *smram_region); +void smram_update (MemoryRegion *smram_region,uint8_t smram);void init_pam (DeviceState *dev,MemoryRegion *ram,MemoryRegion *system,MemoryRegion *pci,PAMMemoryRegion *mem,uint32_t start,uint32_t size);void pam_update (PAMMemoryRegion *mem,int idx,uint8_t val);include/hw/pci-host/q35.h +0
-1@@ -55,7 +55,6 @@ typedef struct MCHPCIState {MemoryRegion smram_region;MemoryRegion smram, low_smram;PcPciInfo pci_info; -uint8_t smm_enabled;ram_addr_t below_4g_mem_size;ram_addr_t above_4g_mem_size;uint64_t pci_hole64_size;linux-user/main.c +0
-4@@ -215,10 +215,6 @@ void cpu_list_unlock(void)/***********************************************************/ /* CPUX86 core interface */ -void cpu_smm_update (CPUX86State *env) -{ -} -uint64_t cpu_get_tsc (CPUX86State *env) {return cpu_get_real_ticks ();target-i386/cpu-qom.h +3
-1@@ -23,6 +23,7 @@#include "qom/cpu.h" #include "cpu.h" #include "qapi/error.h" +#include "qemu/notify.h" #ifdef TARGET_X86_64 #define TYPE_X86_CPU "x86_64-cpu"@@ -111,7 +112,8 @@ typedef struct X86CPU {/* in order to simplify APIC support, we leave this pointer to the user */ struct DeviceState *apic_state; -struct MemoryRegion *cpu_as_root; +struct MemoryRegion *cpu_as_root, *cpu_as_mem, *smram; +Notifier machine_done; }X86CPU ;static inline X86CPU *x86_env_get_cpu (CPUX86State *env)target-i386/cpu.c +31
-2@@ -2751,6 +2751,21 @@ static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)object_property_set_bool (OBJECT (cpu->apic_state), true,"realized" , errp); } + +static void x86_cpu_machine_done (Notifier *n,void *unused) +{ +X86CPU *cpu =container_of (n,X86CPU , machine_done); +MemoryRegion *smram = + (MemoryRegion *)object_resolve_path ("/machine/smram" ,NULL ); + +if (smram) { + cpu->smram =g_new (MemoryRegion,1 ); +memory_region_init_alias (cpu->smram,OBJECT (cpu),"smram" , + smram,0 ,1ull <<32 ); +memory_region_set_enabled (cpu->smram, false); +memory_region_add_subregion_overlap (cpu->cpu_as_root,0 , cpu->smram,1 ); + } +}#else static void x86_cpu_apic_realize (X86CPU *cpu,Error **errp) {@@ -2815,12 +2830,26 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)#ifndef CONFIG_USER_ONLY if (tcg_enabled ()) { + cpu->cpu_as_mem =g_new (MemoryRegion,1 ); cpu->cpu_as_root =g_new (MemoryRegion,1 ); cs->as =g_new (AddressSpace,1 ); -memory_region_init_alias (cpu->cpu_as_root,OBJECT (cpu),"memory" , -get_system_memory (),0 , ~0ull ); + +/* Outer container... */ +memory_region_init (cpu->cpu_as_root,OBJECT (cpu),"memory" , ~0ull );memory_region_set_enabled (cpu->cpu_as_root, true); + +/* ... with two regions inside: normal system memory with low +* priority, and... +*/ +memory_region_init_alias (cpu->cpu_as_mem,OBJECT (cpu),"memory" , +get_system_memory (),0 , ~0ull ); +memory_region_add_subregion_overlap (cpu->cpu_as_root,0 , cpu->cpu_as_mem,0 ); +memory_region_set_enabled (cpu->cpu_as_mem, true);address_space_init (cs->as, cpu->cpu_as_root,"CPU" ); + +/* ... SMRAM with higher priority, linked from /machine/smram. */ + cpu->machine_done.notify = x86_cpu_machine_done; +qemu_add_machine_init_done_notifier (&cpu->machine_done); }#endif target-i386/cpu.h +2
-1@@ -1157,7 +1157,6 @@ void cpu_x86_update_cr3(CPUX86State *env, target_ulong new_cr3);void cpu_x86_update_cr4 (CPUX86State *env,uint32_t new_cr4);/* hw/pc.c */ -void cpu_smm_update (CPUX86State *env);uint64_t cpu_get_tsc (CPUX86State *env);#define TARGET_PAGE_BITS 12@@ -1323,7 +1322,9 @@ void cpu_vmexit(CPUX86State *nenv, uint32_t exit_code, uint64_t exit_info_1);/* seg_helper.c */ void do_interrupt_x86_hardirq (CPUX86State *env,int intno,int is_hw); +/* smm_helper.c */ void do_smm_enter (X86CPU *cpu); +void cpu_smm_update (X86CPU *cpu);void cpu_report_tpr_access (CPUX86State *env,TPRAccess access);target-i386/machine.c +3
-0@@ -372,6 +372,9 @@ static int cpu_post_load(void *opaque, int version_id) }tlb_flush (cs,1 ); +if (tcg_enabled ()) { +cpu_smm_update (cpu); + }return 0 ; }target-i386/smm_helper.c +10
-2@@ -40,6 +40,14 @@ void helper_rsm(CPUX86State *env)#define SMM_REVISION_ID 0x00020000#endif +void cpu_smm_update (X86CPU *cpu) +{ +CPUX86State *env = &cpu->env; +bool smm_enabled = (env->hflags &HF_SMM_MASK ); + +memory_region_set_enabled (cpu->smram, smm_enabled); +} +void do_smm_enter (X86CPU *cpu) {CPUX86State *env = &cpu->env;@@ -57,7 +65,7 @@ void do_smm_enter(X86CPU *cpu) }else { env->hflags2 |=HF2_NMI_MASK ; } -cpu_smm_update (env); +cpu_smm_update (cpu); sm_state = env->smbase +0x8000 ;@@ -317,7 +325,7 @@ void helper_rsm(CPUX86State *env) } env->hflags2 &= ~HF2_SMM_INSIDE_NMI_MASK ; env->hflags &= ~HF_SMM_MASK ; -cpu_smm_update (env); +cpu_smm_update (cpu);qemu_log_mask (CPU_LOG_INT ,"SMM: after RSM\n" );log_cpu_state_mask (CPU_LOG_INT ,CPU (cpu),CPU_DUMP_CCOP );Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 15/31] target-i386: use memory API to implement SMRAM
Quoted 154 lines · Michael S. Tsirkin
Quoted 153 lines · Paolo Bonzini
Remove
cpu_smm_registerandcpu_smm_update. Instead, each CPU address space gets an extra region which is an alias of /machine/smram. This extra region is enabled or disabled as the CPU enters/exits SMM.Signed-off-by Paolo Bonzini <[email protected]>--- bsd-user/main.c | 4 ---- hw/i386/pc.c | 21 --------------------- hw/pci-host/pam.c | 18 ++---------------- hw/pci-host/piix.c | 25 +++++-------------------- hw/pci-host/q35.c | 19 +++---------------- include/hw/i386/pc.h | 1 - include/hw/pci-host/pam.h | 5 +---- include/hw/pci-host/q35.h | 1 - linux-user/main.c | 4 ---- target-i386/cpu-qom.h | 4 +++- target-i386/cpu.c | 33 +++++++++++++++++++++++++++++++-- target-i386/cpu.h | 3 ++- target-i386/machine.c | 3 +++ target-i386/smm_helper.c | 12 ++++++++++-- 14 files changed, 60 insertions(+), 93 deletions(-)bsd-user/main.c +0
-4@@ -108,10 +108,6 @@ void cpu_list_unlock(void)/***********************************************************/ /* CPUX86 core interface */ -void cpu_smm_update (CPUX86State *env) -{ -} -uint64_t cpu_get_tsc (CPUX86State *env) {return cpu_get_real_ticks ();hw/i386/pc.c +0
-21@@ -163,27 +163,6 @@ uint64_t cpu_get_tsc(CPUX86State *env)return cpu_get_ticks (); } -/* SMM support */ - -static cpu_set_smm_t smm_set; -static void *smm_arg; - -void cpu_smm_register (cpu_set_smm_t callback,void *arg) -{ -assert (smm_set ==NULL ); -assert (smm_arg ==NULL ); - smm_set = callback; - smm_arg = arg; -} - -void cpu_smm_update (CPUX86State *env) -{ -if (smm_set && smm_arg &&CPU (x86_env_get_cpu (env)) == first_cpu) { -smm_set (!!(env->hflags &HF_SMM_MASK ), smm_arg); - } -} - -/* IRQ handling */ int cpu_get_pic_interrupt (CPUX86State *env) {hw/pci-host/pam.c +2
-16@@ -31,26 +31,12 @@#include "sysemu/sysemu.h" #include "hw/pci-host/pam.h" -void smram_update (MemoryRegion *smram_region,uint8_t smram, -uint8_t smm_enabled) +void smram_update (MemoryRegion *smram_region,uint8_t smram) { -bool smram_enabled; - - smram_enabled = ((smm_enabled && (smram &SMRAM_G_SMRAME )) || - (smram &SMRAM_D_OPEN )); +bool smram_enabled = (smram &SMRAM_D_OPEN );memory_region_set_enabled (smram_region, !smram_enabled); } -void smram_set_smm (uint8_t *host_smm_enabled,int smm,uint8_t smram, -MemoryRegion *smram_region) -{ -uint8_t smm_enabled = (smm !=0 ); -if (*host_smm_enabled != smm_enabled) { - *host_smm_enabled = smm_enabled; -smram_update (smram_region, smram, *host_smm_enabled); - } -} -void init_pam (DeviceState *dev,MemoryRegion *ram_memory,MemoryRegion *system_memory,MemoryRegion *pci_address_space,PAMMemoryRegion *mem,uint32_t start,uint32_t size)hw/pci-host/piix.c +3
-14@@ -106,7 +106,6 @@ struct PCII440FXState {PAMMemoryRegion pam_regions[13 ];MemoryRegion smram_region;MemoryRegion smram, low_smram; -uint8_t smm_enabled; };@@ -139,23 +138,12 @@ static void i440fx_update_memory_mappings(PCII440FXState *d)pam_update (&d->pam_regions[i], i, pd->config[I440FX_PAM + ((i +1 ) /2 )]); } -smram_update (&d->smram_region, pd->config[I440FX_SMRAM ], d->smm_enabled); +smram_update (&d->smram_region, pd->config[I440FX_SMRAM ]);memory_region_set_enabled (&d->smram, pd->config[I440FX_SMRAM ] &SMRAM_G_SMRAME );memory_region_transaction_commit (); } -static void i440fx_set_smm (int val,void *arg) -{ -PCII440FXState *d = arg; -PCIDevice *pd =PCI_DEVICE (d); - -memory_region_transaction_begin (); -smram_set_smm (&d->smm_enabled, val, pd->config[I440FX_SMRAM ], - &d->smram_region); -memory_region_transaction_commit (); -} -static void i440fx_write_config (PCIDevice *dev,uint32_t address,uint32_t val,int len)@@ -175,12 +163,13 @@ static int i440fx_load_old(QEMUFile* f, void *opaque, int version_id)PCII440FXState *d = opaque;PCIDevice *pd =PCI_DEVICE (d);int ret, i; +uint8_t smm_enabled; ret =pci_device_load (pd, f);if (ret <0 )return ret;i440fx_update_memory_mappings (d); -qemu_get_8s (f, &d->smm_enabled); +qemu_get_8s (f, &smm_enabled);
Quoted 15 lines
hw/pci-host/piix.c static const VMStateDescription vmstate_i440fx = { · line 203
Quoted 11 lines
hw/pci-host/piix.c +1
-1if (version_id ==2 ) {for (i =0 ; i <PIIX_NUM_PIRQS ; i++) {@@ -208,7 +197,7 @@ static const VMStateDescription vmstate_i440fx = { .post_load = i440fx_post_load, .fields = (VMStateField []) {VMSTATE_PCI_DEVICE (parent_obj, PCII440FXState), -VMSTATE_UINT8 (smm_enabled, PCII440FXState), +VMSTATE_UNUSED (1 ),VMSTATE_END_OF_LIST () } };Won't this cause problems for cross-version migration? Old qemu receiving this will think smm is enabled, unconditionally.
UNUSED is written as zeroes, so it will think SMM is _disabled_, unconditionally. Note that d->smram_region is backwards: it aliases to VRAM, so it is enabled when SMRAM is closed and disabled when SMRAM is open.
This is correct for KVM, though not for TCG. Backwards migration is not supported officially upstream, and I think we can agree it is even less supported for TCG.
Paolo
Quoted 288 lines
Quoted 286 lines
hw/pci-host/piix.c +1
-5@@ -300,11 +289,7 @@ static void i440fx_pcihost_realize(DeviceState *dev, Error **errp)static void i440fx_realize (PCIDevice *dev,Error **errp) { -PCII440FXState *d =I440FX_PCI_DEVICE (dev); - dev->config[I440FX_SMRAM ] =0x02 ; - -cpu_smm_register (&i440fx_set_smm, d); } PCIBus *i440fx_init(PCII440FXState **pi440fx_state,@@ -360,7 +345,7 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,memory_region_init (&f->smram,OBJECT (d),"smram" ,1ull <<32 );memory_region_set_enabled (&f->smram, true);memory_region_init_alias (&f->low_smram,OBJECT (d),"smram-low" , - f->system_memory,0xa0000 ,0x20000 ); + f->ram_memory,0xa0000 ,0x20000 );memory_region_set_enabled (&f->low_smram, true);memory_region_add_subregion (&f->smram,0xa0000 , &f->low_smram); object_property_add_alias(qdev_get_machine(), "smram",hw/pci-host/q35.c +3
-16@@ -268,24 +268,12 @@ static void mch_update_smram(MCHPCIState *mch)PCIDevice *pd =PCI_DEVICE (mch);memory_region_transaction_begin (); -smram_update (&mch->smram_region, pd->config[MCH_HOST_BRIDGE_SMRAM ], - mch->smm_enabled); +smram_update (&mch->smram_region, pd->config[MCH_HOST_BRIDGE_SMRAM ]);memory_region_set_enabled (&mch->smram, pd->config[MCH_HOST_BRIDGE_SMRAM ] &SMRAM_G_SMRAME );memory_region_transaction_commit (); } -static void mch_set_smm (int smm,void *arg) -{ -MCHPCIState *mch = arg; -PCIDevice *pd =PCI_DEVICE (mch); - -memory_region_transaction_begin (); -smram_set_smm (&mch->smm_enabled, smm, pd->config[MCH_HOST_BRIDGE_SMRAM ], - &mch->smram_region); -memory_region_transaction_commit (); -} -static void mch_write_config (PCIDevice *d,uint32_t address,uint32_t val,int len) {@@ -331,7 +319,7 @@ static const VMStateDescription vmstate_mch = { .post_load = mch_post_load, .fields = (VMStateField []) {VMSTATE_PCI_DEVICE (parent_obj, MCHPCIState), -VMSTATE_UINT8 (smm_enabled, MCHPCIState), +VMSTATE_UNUSED (1 ),VMSTATE_END_OF_LIST () } };@@ -402,7 +390,6 @@ static void mch_realize(PCIDevice *d, Error **errp) mch->pci_address_space);/* if *disabled* show SMRAM to all CPUs */ -cpu_smm_register (&mch_set_smm, mch);memory_region_init_alias (&mch->smram_region,OBJECT (mch),"smram-region" , mch->pci_address_space,0xa0000 ,0x20000 ); memory_region_add_subregion_overlap(mch->system_memory, 0xa0000,@@ -413,7 +400,7 @@ static void mch_realize(PCIDevice *d, Error **errp)memory_region_init (&mch->smram,OBJECT (mch),"smram" ,1ull <<32 );memory_region_set_enabled (&mch->smram, true);memory_region_init_alias (&mch->low_smram,OBJECT (mch),"smram-low" , - mch->system_memory,0xa0000 ,0x20000 ); + mch->ram_memory,0xa0000 ,0x20000 );memory_region_set_enabled (&mch->low_smram, true);memory_region_add_subregion (&mch->smram,0xa0000 , &mch->low_smram); object_property_add_const_link(qdev_get_machine(), "smram",include/hw/i386/pc.h +0
-1@@ -211,7 +211,6 @@ void pc_nic_init(ISABus *isa_bus, PCIBus *pci_bus);void pc_pci_device_init (PCIBus *pci_bus);typedef void (*cpu_set_smm_t )(int smm,void *arg); -void cpu_smm_register (cpu_set_smm_t callback,void *arg);void ioapic_init_gsi (GSIState *gsi_state,const char *parent_name);include/hw/pci-host/pam.h +1
-4@@ -86,10 +86,7 @@ typedef struct PAMMemoryRegion {unsigned current; } PAMMemoryRegion; -void smram_update (MemoryRegion *smram_region,uint8_t smram, -uint8_t smm_enabled); -void smram_set_smm (uint8_t *host_smm_enabled,int smm,uint8_t smram, -MemoryRegion *smram_region); +void smram_update (MemoryRegion *smram_region,uint8_t smram);void init_pam (DeviceState *dev,MemoryRegion *ram,MemoryRegion *system,MemoryRegion *pci,PAMMemoryRegion *mem,uint32_t start,uint32_t size);void pam_update (PAMMemoryRegion *mem,int idx,uint8_t val);include/hw/pci-host/q35.h +0
-1@@ -55,7 +55,6 @@ typedef struct MCHPCIState {MemoryRegion smram_region;MemoryRegion smram, low_smram;PcPciInfo pci_info; -uint8_t smm_enabled;ram_addr_t below_4g_mem_size;ram_addr_t above_4g_mem_size;uint64_t pci_hole64_size;linux-user/main.c +0
-4@@ -215,10 +215,6 @@ void cpu_list_unlock(void)/***********************************************************/ /* CPUX86 core interface */ -void cpu_smm_update (CPUX86State *env) -{ -} -uint64_t cpu_get_tsc (CPUX86State *env) {return cpu_get_real_ticks ();target-i386/cpu-qom.h +3
-1@@ -23,6 +23,7 @@#include "qom/cpu.h" #include "cpu.h" #include "qapi/error.h" +#include "qemu/notify.h" #ifdef TARGET_X86_64 #define TYPE_X86_CPU "x86_64-cpu"@@ -111,7 +112,8 @@ typedef struct X86CPU {/* in order to simplify APIC support, we leave this pointer to the user */ struct DeviceState *apic_state; -struct MemoryRegion *cpu_as_root; +struct MemoryRegion *cpu_as_root, *cpu_as_mem, *smram; +Notifier machine_done; }X86CPU ;static inline X86CPU *x86_env_get_cpu (CPUX86State *env)target-i386/cpu.c +31
-2@@ -2751,6 +2751,21 @@ static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)object_property_set_bool (OBJECT (cpu->apic_state), true,"realized" , errp); } + +static void x86_cpu_machine_done (Notifier *n,void *unused) +{ +X86CPU *cpu =container_of (n,X86CPU , machine_done); +MemoryRegion *smram = + (MemoryRegion *)object_resolve_path ("/machine/smram" ,NULL ); + +if (smram) { + cpu->smram =g_new (MemoryRegion,1 ); +memory_region_init_alias (cpu->smram,OBJECT (cpu),"smram" , + smram,0 ,1ull <<32 ); +memory_region_set_enabled (cpu->smram, false); +memory_region_add_subregion_overlap (cpu->cpu_as_root,0 , cpu->smram,1 ); + } +}#else static void x86_cpu_apic_realize (X86CPU *cpu,Error **errp) {@@ -2815,12 +2830,26 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)#ifndef CONFIG_USER_ONLY if (tcg_enabled ()) { + cpu->cpu_as_mem =g_new (MemoryRegion,1 ); cpu->cpu_as_root =g_new (MemoryRegion,1 ); cs->as =g_new (AddressSpace,1 ); -memory_region_init_alias (cpu->cpu_as_root,OBJECT (cpu),"memory" , -get_system_memory (),0 , ~0ull ); + +/* Outer container... */ +memory_region_init (cpu->cpu_as_root,OBJECT (cpu),"memory" , ~0ull );memory_region_set_enabled (cpu->cpu_as_root, true); + +/* ... with two regions inside: normal system memory with low +* priority, and... +*/ +memory_region_init_alias (cpu->cpu_as_mem,OBJECT (cpu),"memory" , +get_system_memory (),0 , ~0ull ); +memory_region_add_subregion_overlap (cpu->cpu_as_root,0 , cpu->cpu_as_mem,0 ); +memory_region_set_enabled (cpu->cpu_as_mem, true);address_space_init (cs->as, cpu->cpu_as_root,"CPU" ); + +/* ... SMRAM with higher priority, linked from /machine/smram. */ + cpu->machine_done.notify = x86_cpu_machine_done; +qemu_add_machine_init_done_notifier (&cpu->machine_done); }#endif target-i386/cpu.h +2
-1@@ -1157,7 +1157,6 @@ void cpu_x86_update_cr3(CPUX86State *env, target_ulong new_cr3);void cpu_x86_update_cr4 (CPUX86State *env,uint32_t new_cr4);/* hw/pc.c */ -void cpu_smm_update (CPUX86State *env);uint64_t cpu_get_tsc (CPUX86State *env);#define TARGET_PAGE_BITS 12@@ -1323,7 +1322,9 @@ void cpu_vmexit(CPUX86State *nenv, uint32_t exit_code, uint64_t exit_info_1);/* seg_helper.c */ void do_interrupt_x86_hardirq (CPUX86State *env,int intno,int is_hw); +/* smm_helper.c */ void do_smm_enter (X86CPU *cpu); +void cpu_smm_update (X86CPU *cpu);void cpu_report_tpr_access (CPUX86State *env,TPRAccess access);target-i386/machine.c +3
-0@@ -372,6 +372,9 @@ static int cpu_post_load(void *opaque, int version_id) }tlb_flush (cs,1 ); +if (tcg_enabled ()) { +cpu_smm_update (cpu); + }return 0 ; }target-i386/smm_helper.c +10
-2@@ -40,6 +40,14 @@ void helper_rsm(CPUX86State *env)#define SMM_REVISION_ID 0x00020000#endif +void cpu_smm_update (X86CPU *cpu) +{ +CPUX86State *env = &cpu->env; +bool smm_enabled = (env->hflags &HF_SMM_MASK ); + +memory_region_set_enabled (cpu->smram, smm_enabled); +} +void do_smm_enter (X86CPU *cpu) {CPUX86State *env = &cpu->env;@@ -57,7 +65,7 @@ void do_smm_enter(X86CPU *cpu) }else { env->hflags2 |=HF2_NMI_MASK ; } -cpu_smm_update (env); +cpu_smm_update (cpu); sm_state = env->smbase +0x8000 ;@@ -317,7 +325,7 @@ void helper_rsm(CPUX86State *env) } env->hflags2 &= ~HF2_SMM_INSIDE_NMI_MASK ; env->hflags &= ~HF_SMM_MASK ; -cpu_smm_update (env); +cpu_smm_update (cpu);qemu_log_mask (CPU_LOG_INT ,"SMM: after RSM\n" );log_cpu_state_mask (CPU_LOG_INT ,CPU (cpu),CPU_DUMP_CCOP );Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 15/31] target-i386: use memory API to implement SMRAM
Quoted 177 lines · Paolo Bonzini
Quoted 154 lines · Michael S. Tsirkin
Quoted 153 lines · Paolo Bonzini
Remove
cpu_smm_registerandcpu_smm_update. Instead, each CPU address space gets an extra region which is an alias of /machine/smram. This extra region is enabled or disabled as the CPU enters/exits SMM.Signed-off-by Paolo Bonzini <[email protected]>--- bsd-user/main.c | 4 ---- hw/i386/pc.c | 21 --------------------- hw/pci-host/pam.c | 18 ++---------------- hw/pci-host/piix.c | 25 +++++-------------------- hw/pci-host/q35.c | 19 +++---------------- include/hw/i386/pc.h | 1 - include/hw/pci-host/pam.h | 5 +---- include/hw/pci-host/q35.h | 1 - linux-user/main.c | 4 ---- target-i386/cpu-qom.h | 4 +++- target-i386/cpu.c | 33 +++++++++++++++++++++++++++++++-- target-i386/cpu.h | 3 ++- target-i386/machine.c | 3 +++ target-i386/smm_helper.c | 12 ++++++++++-- 14 files changed, 60 insertions(+), 93 deletions(-)bsd-user/main.c +0
-4@@ -108,10 +108,6 @@ void cpu_list_unlock(void)/***********************************************************/ /* CPUX86 core interface */ -void cpu_smm_update (CPUX86State *env) -{ -} -uint64_t cpu_get_tsc (CPUX86State *env) {return cpu_get_real_ticks ();hw/i386/pc.c +0
-21@@ -163,27 +163,6 @@ uint64_t cpu_get_tsc(CPUX86State *env)return cpu_get_ticks (); } -/* SMM support */ - -static cpu_set_smm_t smm_set; -static void *smm_arg; - -void cpu_smm_register (cpu_set_smm_t callback,void *arg) -{ -assert (smm_set ==NULL ); -assert (smm_arg ==NULL ); - smm_set = callback; - smm_arg = arg; -} - -void cpu_smm_update (CPUX86State *env) -{ -if (smm_set && smm_arg &&CPU (x86_env_get_cpu (env)) == first_cpu) { -smm_set (!!(env->hflags &HF_SMM_MASK ), smm_arg); - } -} - -/* IRQ handling */ int cpu_get_pic_interrupt (CPUX86State *env) {hw/pci-host/pam.c +2
-16@@ -31,26 +31,12 @@#include "sysemu/sysemu.h" #include "hw/pci-host/pam.h" -void smram_update (MemoryRegion *smram_region,uint8_t smram, -uint8_t smm_enabled) +void smram_update (MemoryRegion *smram_region,uint8_t smram) { -bool smram_enabled; - - smram_enabled = ((smm_enabled && (smram &SMRAM_G_SMRAME )) || - (smram &SMRAM_D_OPEN )); +bool smram_enabled = (smram &SMRAM_D_OPEN );memory_region_set_enabled (smram_region, !smram_enabled); } -void smram_set_smm (uint8_t *host_smm_enabled,int smm,uint8_t smram, -MemoryRegion *smram_region) -{ -uint8_t smm_enabled = (smm !=0 ); -if (*host_smm_enabled != smm_enabled) { - *host_smm_enabled = smm_enabled; -smram_update (smram_region, smram, *host_smm_enabled); - } -} -void init_pam (DeviceState *dev,MemoryRegion *ram_memory,MemoryRegion *system_memory,MemoryRegion *pci_address_space,PAMMemoryRegion *mem,uint32_t start,uint32_t size)hw/pci-host/piix.c +3
-14@@ -106,7 +106,6 @@ struct PCII440FXState {PAMMemoryRegion pam_regions[13 ];MemoryRegion smram_region;MemoryRegion smram, low_smram; -uint8_t smm_enabled; };@@ -139,23 +138,12 @@ static void i440fx_update_memory_mappings(PCII440FXState *d)pam_update (&d->pam_regions[i], i, pd->config[I440FX_PAM + ((i +1 ) /2 )]); } -smram_update (&d->smram_region, pd->config[I440FX_SMRAM ], d->smm_enabled); +smram_update (&d->smram_region, pd->config[I440FX_SMRAM ]);memory_region_set_enabled (&d->smram, pd->config[I440FX_SMRAM ] &SMRAM_G_SMRAME );memory_region_transaction_commit (); } -static void i440fx_set_smm (int val,void *arg) -{ -PCII440FXState *d = arg; -PCIDevice *pd =PCI_DEVICE (d); - -memory_region_transaction_begin (); -smram_set_smm (&d->smm_enabled, val, pd->config[I440FX_SMRAM ], - &d->smram_region); -memory_region_transaction_commit (); -} -static void i440fx_write_config (PCIDevice *dev,uint32_t address,uint32_t val,int len)@@ -175,12 +163,13 @@ static int i440fx_load_old(QEMUFile* f, void *opaque, int version_id)PCII440FXState *d = opaque;PCIDevice *pd =PCI_DEVICE (d);int ret, i; +uint8_t smm_enabled; ret =pci_device_load (pd, f);if (ret <0 )return ret;i440fx_update_memory_mappings (d); -qemu_get_8s (f, &d->smm_enabled); +qemu_get_8s (f, &smm_enabled);Quoted 15 lines
hw/pci-host/piix.c static const VMStateDescription vmstate_i440fx = { · line 203
Quoted 11 lines
hw/pci-host/piix.c +1
-1if (version_id ==2 ) {for (i =0 ; i <PIIX_NUM_PIRQS ; i++) {@@ -208,7 +197,7 @@ static const VMStateDescription vmstate_i440fx = { .post_load = i440fx_post_load, .fields = (VMStateField []) {VMSTATE_PCI_DEVICE (parent_obj, PCII440FXState), -VMSTATE_UINT8 (smm_enabled, PCII440FXState), +VMSTATE_UNUSED (1 ),VMSTATE_END_OF_LIST () } };Won't this cause problems for cross-version migration? Old qemu receiving this will think smm is enabled, unconditionally.
UNUSED is written as zeroes, so it will think SMM is _disabled_, unconditionally. Note that
d->smram_regionis backwards: it aliases to VRAM, so it is enabled when SMRAM is closed and disabled when SMRAM is open.
Quoted 5 lines
This is correct for KVM, though not for TCG. Backwards migration is not supported officially upstream, and I think we can agree it is even less supported for TCG.
Paolo
Generally backwards migration is nice to have to test cross-version migration properly by doing ping-pong.
Looks like we only need to set smm_enabled correctly before save, and it'll work cleanly.
No?
Quoted 288 lines
Quoted 288 lines
Quoted 286 lines
hw/pci-host/piix.c +1
-5@@ -300,11 +289,7 @@ static void i440fx_pcihost_realize(DeviceState *dev, Error **errp)static void i440fx_realize (PCIDevice *dev,Error **errp) { -PCII440FXState *d =I440FX_PCI_DEVICE (dev); - dev->config[I440FX_SMRAM ] =0x02 ; - -cpu_smm_register (&i440fx_set_smm, d); } PCIBus *i440fx_init(PCII440FXState **pi440fx_state,@@ -360,7 +345,7 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,memory_region_init (&f->smram,OBJECT (d),"smram" ,1ull <<32 );memory_region_set_enabled (&f->smram, true);memory_region_init_alias (&f->low_smram,OBJECT (d),"smram-low" , - f->system_memory,0xa0000 ,0x20000 ); + f->ram_memory,0xa0000 ,0x20000 );memory_region_set_enabled (&f->low_smram, true);memory_region_add_subregion (&f->smram,0xa0000 , &f->low_smram); object_property_add_alias(qdev_get_machine(), "smram",hw/pci-host/q35.c +3
-16@@ -268,24 +268,12 @@ static void mch_update_smram(MCHPCIState *mch)PCIDevice *pd =PCI_DEVICE (mch);memory_region_transaction_begin (); -smram_update (&mch->smram_region, pd->config[MCH_HOST_BRIDGE_SMRAM ], - mch->smm_enabled); +smram_update (&mch->smram_region, pd->config[MCH_HOST_BRIDGE_SMRAM ]);memory_region_set_enabled (&mch->smram, pd->config[MCH_HOST_BRIDGE_SMRAM ] &SMRAM_G_SMRAME );memory_region_transaction_commit (); } -static void mch_set_smm (int smm,void *arg) -{ -MCHPCIState *mch = arg; -PCIDevice *pd =PCI_DEVICE (mch); - -memory_region_transaction_begin (); -smram_set_smm (&mch->smm_enabled, smm, pd->config[MCH_HOST_BRIDGE_SMRAM ], - &mch->smram_region); -memory_region_transaction_commit (); -} -static void mch_write_config (PCIDevice *d,uint32_t address,uint32_t val,int len) {@@ -331,7 +319,7 @@ static const VMStateDescription vmstate_mch = { .post_load = mch_post_load, .fields = (VMStateField []) {VMSTATE_PCI_DEVICE (parent_obj, MCHPCIState), -VMSTATE_UINT8 (smm_enabled, MCHPCIState), +VMSTATE_UNUSED (1 ),VMSTATE_END_OF_LIST () } };@@ -402,7 +390,6 @@ static void mch_realize(PCIDevice *d, Error **errp) mch->pci_address_space);/* if *disabled* show SMRAM to all CPUs */ -cpu_smm_register (&mch_set_smm, mch);memory_region_init_alias (&mch->smram_region,OBJECT (mch),"smram-region" , mch->pci_address_space,0xa0000 ,0x20000 ); memory_region_add_subregion_overlap(mch->system_memory, 0xa0000,@@ -413,7 +400,7 @@ static void mch_realize(PCIDevice *d, Error **errp)memory_region_init (&mch->smram,OBJECT (mch),"smram" ,1ull <<32 );memory_region_set_enabled (&mch->smram, true);memory_region_init_alias (&mch->low_smram,OBJECT (mch),"smram-low" , - mch->system_memory,0xa0000 ,0x20000 ); + mch->ram_memory,0xa0000 ,0x20000 );memory_region_set_enabled (&mch->low_smram, true);memory_region_add_subregion (&mch->smram,0xa0000 , &mch->low_smram); object_property_add_const_link(qdev_get_machine(), "smram",include/hw/i386/pc.h +0
-1@@ -211,7 +211,6 @@ void pc_nic_init(ISABus *isa_bus, PCIBus *pci_bus);void pc_pci_device_init (PCIBus *pci_bus);typedef void (*cpu_set_smm_t )(int smm,void *arg); -void cpu_smm_register (cpu_set_smm_t callback,void *arg);void ioapic_init_gsi (GSIState *gsi_state,const char *parent_name);include/hw/pci-host/pam.h +1
-4@@ -86,10 +86,7 @@ typedef struct PAMMemoryRegion {unsigned current; } PAMMemoryRegion; -void smram_update (MemoryRegion *smram_region,uint8_t smram, -uint8_t smm_enabled); -void smram_set_smm (uint8_t *host_smm_enabled,int smm,uint8_t smram, -MemoryRegion *smram_region); +void smram_update (MemoryRegion *smram_region,uint8_t smram);void init_pam (DeviceState *dev,MemoryRegion *ram,MemoryRegion *system,MemoryRegion *pci,PAMMemoryRegion *mem,uint32_t start,uint32_t size);void pam_update (PAMMemoryRegion *mem,int idx,uint8_t val);include/hw/pci-host/q35.h +0
-1@@ -55,7 +55,6 @@ typedef struct MCHPCIState {MemoryRegion smram_region;MemoryRegion smram, low_smram;PcPciInfo pci_info; -uint8_t smm_enabled;ram_addr_t below_4g_mem_size;ram_addr_t above_4g_mem_size;uint64_t pci_hole64_size;linux-user/main.c +0
-4@@ -215,10 +215,6 @@ void cpu_list_unlock(void)/***********************************************************/ /* CPUX86 core interface */ -void cpu_smm_update (CPUX86State *env) -{ -} -uint64_t cpu_get_tsc (CPUX86State *env) {return cpu_get_real_ticks ();target-i386/cpu-qom.h +3
-1@@ -23,6 +23,7 @@#include "qom/cpu.h" #include "cpu.h" #include "qapi/error.h" +#include "qemu/notify.h" #ifdef TARGET_X86_64 #define TYPE_X86_CPU "x86_64-cpu"@@ -111,7 +112,8 @@ typedef struct X86CPU {/* in order to simplify APIC support, we leave this pointer to the user */ struct DeviceState *apic_state; -struct MemoryRegion *cpu_as_root; +struct MemoryRegion *cpu_as_root, *cpu_as_mem, *smram; +Notifier machine_done; }X86CPU ;static inline X86CPU *x86_env_get_cpu (CPUX86State *env)target-i386/cpu.c +31
-2@@ -2751,6 +2751,21 @@ static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)object_property_set_bool (OBJECT (cpu->apic_state), true,"realized" , errp); } + +static void x86_cpu_machine_done (Notifier *n,void *unused) +{ +X86CPU *cpu =container_of (n,X86CPU , machine_done); +MemoryRegion *smram = + (MemoryRegion *)object_resolve_path ("/machine/smram" ,NULL ); + +if (smram) { + cpu->smram =g_new (MemoryRegion,1 ); +memory_region_init_alias (cpu->smram,OBJECT (cpu),"smram" , + smram,0 ,1ull <<32 ); +memory_region_set_enabled (cpu->smram, false); +memory_region_add_subregion_overlap (cpu->cpu_as_root,0 , cpu->smram,1 ); + } +}#else static void x86_cpu_apic_realize (X86CPU *cpu,Error **errp) {@@ -2815,12 +2830,26 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)#ifndef CONFIG_USER_ONLY if (tcg_enabled ()) { + cpu->cpu_as_mem =g_new (MemoryRegion,1 ); cpu->cpu_as_root =g_new (MemoryRegion,1 ); cs->as =g_new (AddressSpace,1 ); -memory_region_init_alias (cpu->cpu_as_root,OBJECT (cpu),"memory" , -get_system_memory (),0 , ~0ull ); + +/* Outer container... */ +memory_region_init (cpu->cpu_as_root,OBJECT (cpu),"memory" , ~0ull );memory_region_set_enabled (cpu->cpu_as_root, true); + +/* ... with two regions inside: normal system memory with low +* priority, and... +*/ +memory_region_init_alias (cpu->cpu_as_mem,OBJECT (cpu),"memory" , +get_system_memory (),0 , ~0ull ); +memory_region_add_subregion_overlap (cpu->cpu_as_root,0 , cpu->cpu_as_mem,0 ); +memory_region_set_enabled (cpu->cpu_as_mem, true);address_space_init (cs->as, cpu->cpu_as_root,"CPU" ); + +/* ... SMRAM with higher priority, linked from /machine/smram. */ + cpu->machine_done.notify = x86_cpu_machine_done; +qemu_add_machine_init_done_notifier (&cpu->machine_done); }#endif target-i386/cpu.h +2
-1@@ -1157,7 +1157,6 @@ void cpu_x86_update_cr3(CPUX86State *env, target_ulong new_cr3);void cpu_x86_update_cr4 (CPUX86State *env,uint32_t new_cr4);/* hw/pc.c */ -void cpu_smm_update (CPUX86State *env);uint64_t cpu_get_tsc (CPUX86State *env);#define TARGET_PAGE_BITS 12@@ -1323,7 +1322,9 @@ void cpu_vmexit(CPUX86State *nenv, uint32_t exit_code, uint64_t exit_info_1);/* seg_helper.c */ void do_interrupt_x86_hardirq (CPUX86State *env,int intno,int is_hw); +/* smm_helper.c */ void do_smm_enter (X86CPU *cpu); +void cpu_smm_update (X86CPU *cpu);void cpu_report_tpr_access (CPUX86State *env,TPRAccess access);target-i386/machine.c +3
-0@@ -372,6 +372,9 @@ static int cpu_post_load(void *opaque, int version_id) }tlb_flush (cs,1 ); +if (tcg_enabled ()) { +cpu_smm_update (cpu); + }return 0 ; }target-i386/smm_helper.c +10
-2@@ -40,6 +40,14 @@ void helper_rsm(CPUX86State *env)#define SMM_REVISION_ID 0x00020000#endif +void cpu_smm_update (X86CPU *cpu) +{ +CPUX86State *env = &cpu->env; +bool smm_enabled = (env->hflags &HF_SMM_MASK ); + +memory_region_set_enabled (cpu->smram, smm_enabled); +} +void do_smm_enter (X86CPU *cpu) {CPUX86State *env = &cpu->env;@@ -57,7 +65,7 @@ void do_smm_enter(X86CPU *cpu) }else { env->hflags2 |=HF2_NMI_MASK ; } -cpu_smm_update (env); +cpu_smm_update (cpu); sm_state = env->smbase +0x8000 ;@@ -317,7 +325,7 @@ void helper_rsm(CPUX86State *env) } env->hflags2 &= ~HF2_SMM_INSIDE_NMI_MASK ; env->hflags &= ~HF_SMM_MASK ; -cpu_smm_update (env); +cpu_smm_update (cpu);qemu_log_mask (CPU_LOG_INT ,"SMM: after RSM\n" );log_cpu_state_mask (CPU_LOG_INT ,CPU (cpu),CPU_DUMP_CCOP );Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 15/31] target-i386: use memory API to implement SMRAM
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines
UNUSED is written as zeroes, so it will think SMM is _disabled_, unconditionally. Note that
d->smram_regionis backwards: it aliases to VRAM, so it is enabled when SMRAM is closed and disabled when SMRAM is open.This is correct for KVM, though not for TCG. Backwards migration is not supported officially upstream, and I think we can agree it is even less supported for TCG.
Quoted 5 lines
Generally backwards migration is nice to have to test cross-version migration properly by doing ping-pong.
Looks like we only need to setsmm_enabledcorrectly before save, and it'll work cleanly.
No?
Sort of. Old QEMU is not able to handle the case where some CPUs are in SMM and some are not. It is also a layering violation to compute smm_enabled from the CPUs.
Old SeaBIOS never uses SMM after POST, and executes a dozen instructions or so inside SMRAM. New SeaBIOS does use SMM after POST (e.g. during grub), but it _literally_ executes two instructions inside SMRAM and then jumps to the F-segment, so even if you do not migrate smm_enabled the chance that something break is basically zero.
This is why I decided that it wasn't worth the complication (and the layering violation).
Paolo
Re: [Qemu-devel] [PATCH 15/31] target-i386: use memory API to implement SMRAM
Quoted 17 lines · Paolo Bonzini
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines
UNUSED is written as zeroes, so it will think SMM is _disabled_, unconditionally. Note that
d->smram_regionis backwards: it aliases to VRAM, so it is enabled when SMRAM is closed and disabled when SMRAM is open.This is correct for KVM, though not for TCG. Backwards migration is not supported officially upstream, and I think we can agree it is even less supported for TCG.
Quoted 5 lines
Generally backwards migration is nice to have to test cross-version migration properly by doing ping-pong.
Looks like we only need to setsmm_enabledcorrectly before save, and it'll work cleanly.
No?
Quoted 3 lines
Sort of. Old QEMU is not able to handle the case where some CPUs are in SMM and some are not. It is also a layering violation to compute
smm_enabledfrom the CPUs.
Yes, I got that. But I guess typically only one CPU is running so something like smm_enabled_any will DTRT, without layering violations, right?
Quoted 10 lines
Old SeaBIOS never uses SMM after POST, and executes a dozen instructions or so inside SMRAM. New SeaBIOS does use SMM after POST (e.g. during grub), but it _literally_ executes two instructions inside SMRAM and then jumps to the F-segment, so even if you do not migrate
smm_enabledthe chance that something break is basically zero.This is why I decided that it wasn't worth the complication (and the layering violation).
Paolo
To me it seems easier to support than to explain why we don't have to, but if you are strongly against that, please add code comments explaining all this.
Signature · 1 line
MST
PATCH 16/31 hw/i386: remove smram_update
In reply to Paolo BonziniIt's easier to inline it now that most of its work is done by the CPU (rather than the chipset) through /machine/smram and the memory API.
--- hw/pci-host/pam.c | 6 ------ hw/pci-host/piix.c | 3 ++- hw/pci-host/q35.c | 3 ++- include/hw/pci-host/pam.h | 1 - 4 files changed, 4 insertions(+), 9 deletions(-)
hw/pci-host/pam.c +0 -6
@@ -31,12 +31,6 @@#include "sysemu/sysemu.h" #include "hw/pci-host/pam.h" -void smram_update (MemoryRegion *smram_region,uint8_t smram) -{ -bool smram_enabled = (smram &SMRAM_D_OPEN ); -memory_region_set_enabled (smram_region, !smram_enabled); -} -void init_pam (DeviceState *dev,MemoryRegion *ram_memory,MemoryRegion *system_memory,MemoryRegion *pci_address_space,PAMMemoryRegion *mem,uint32_t start,uint32_t size)
hw/pci-host/piix.c +2 -1
@@ -138,7 +138,8 @@ static void i440fx_update_memory_mappings(PCII440FXState *d)pam_update (&d->pam_regions[i], i, pd->config[I440FX_PAM + ((i +1 ) /2 )]); } -smram_update (&d->smram_region, pd->config[I440FX_SMRAM ]); +memory_region_set_enabled (&d->smram_region, + !(pd->config[I440FX_SMRAM ] &SMRAM_D_OPEN ));memory_region_set_enabled (&d->smram, pd->config[I440FX_SMRAM ] &SMRAM_G_SMRAME );memory_region_transaction_commit ();
hw/pci-host/q35.c +2 -1
@@ -268,7 +268,8 @@ static void mch_update_smram(MCHPCIState *mch)PCIDevice *pd =PCI_DEVICE (mch);memory_region_transaction_begin (); -smram_update (&mch->smram_region, pd->config[MCH_HOST_BRIDGE_SMRAM ]); +memory_region_set_enabled (&mch->smram_region, + !(pd->config[MCH_HOST_BRIDGE_SMRAM ] &SMRAM_D_OPEN ));memory_region_set_enabled (&mch->smram, pd->config[MCH_HOST_BRIDGE_SMRAM ] &SMRAM_G_SMRAME );memory_region_transaction_commit ();
include/hw/pci-host/pam.h +0 -1
@@ -86,7 +86,6 @@ typedef struct PAMMemoryRegion {unsigned current; } PAMMemoryRegion; -void smram_update (MemoryRegion *smram_region,uint8_t smram);void init_pam (DeviceState *dev,MemoryRegion *ram,MemoryRegion *system,MemoryRegion *pci,PAMMemoryRegion *mem,uint32_t start,uint32_t size);void pam_update (PAMMemoryRegion *mem,int idx,uint8_t val);
Signature · 1 line
1.8.3.1
PATCH 17/31 q35: implement high SMRAM
In reply to Paolo BonziniWhen H_SMRAME is 1, low memory at 0xa0000 is left alone by SMM, and instead the chipset maps the 0xa0000-0xbffff window at 0xfeda0000-0xfedbffff. This affects both the "non-SMM" view controlled by D_OPEN and the SMM view controlled by G_SMRAME, so add two new MemoryRegions and toggle the enabled/disabled state of all four in mch_update_smram.
--- hw/pci-host/q35.c | 35 +++++++++++++++++++++++++++++++---- include/hw/pci-host/q35.h | 16 ++++++++-------- 2 files changed, 39 insertions(+), 12 deletions(-)
hw/pci-host/q35.c +31 -4
@@ -266,12 +266,29 @@ static void mch_update_pam(MCHPCIState *mch)static void mch_update_smram (MCHPCIState *mch) {PCIDevice *pd =PCI_DEVICE (mch); +bool h_smrame = (pd->config[MCH_HOST_BRIDGE_ESMRAMC ] &MCH_HOST_BRIDGE_ESMRAMC_H_SMRAME );memory_region_transaction_begin (); -memory_region_set_enabled (&mch->smram_region, - !(pd->config[MCH_HOST_BRIDGE_SMRAM ] &SMRAM_D_OPEN )); -memory_region_set_enabled (&mch->smram, - pd->config[MCH_HOST_BRIDGE_SMRAM ] &SMRAM_G_SMRAME ); + +if (pd->config[MCH_HOST_BRIDGE_SMRAM ] &SMRAM_D_OPEN ) { +/* Hide (!) low SMRAM if H_SMRAME = 1 */ +memory_region_set_enabled (&mch->smram_region, h_smrame); +/* Show high SMRAM if H_SMRAME = 1 */ +memory_region_set_enabled (&mch->open_high_smram, h_smrame); + }else { +/* Hide high SMRAM and low SMRAM */ +memory_region_set_enabled (&mch->smram_region, true); +memory_region_set_enabled (&mch->open_high_smram, false); + } + +if (pd->config[MCH_HOST_BRIDGE_SMRAM ] &SMRAM_G_SMRAME ) { +memory_region_set_enabled (&mch->low_smram, !h_smrame); +memory_region_set_enabled (&mch->high_smram, h_smrame); + }else { +memory_region_set_enabled (&mch->low_smram, false); +memory_region_set_enabled (&mch->high_smram, false); + } +memory_region_transaction_commit (); }
@@ -397,6 +414,12 @@ static void mch_realize(PCIDevice *d, Error **errp) &mch->smram_region, 1);memory_region_set_enabled (&mch->smram_region, false); +memory_region_init_alias (&mch->open_high_smram,OBJECT (mch),"smram-open-high" , + mch->ram_memory,0xa0000 ,0x20000 ); +memory_region_add_subregion_overlap (mch->system_memory,0xfeda0000 , + &mch->open_high_smram,1 ); +memory_region_set_enabled (&mch->open_high_smram, false); +/* smram, as seen by SMM CPUs */ memory_region_init (&mch->smram,OBJECT (mch),"smram" ,1ull <<32 );memory_region_set_enabled (&mch->smram, true);
@@ -404,6 +427,10 @@ static void mch_realize(PCIDevice *d, Error **errp) mch->ram_memory, 0xa0000, 0x20000);memory_region_set_enabled (&mch->low_smram, true);memory_region_add_subregion (&mch->smram,0xa0000 , &mch->low_smram); +memory_region_init_alias (&mch->high_smram,OBJECT (mch),"smram-high" , + mch->ram_memory,0xa0000 ,0x20000 ); +memory_region_set_enabled (&mch->high_smram, true); +memory_region_add_subregion (&mch->smram,0xfeda0000 , &mch->high_smram);object_property_add_const_link (qdev_get_machine (),"smram" ,OBJECT (&mch->smram), &error_abort);
include/hw/pci-host/q35.h +8 -8
@@ -52,8 +52,8 @@ typedef struct MCHPCIState {MemoryRegion *system_memory;MemoryRegion *address_space_io;PAMMemoryRegion pam_regions[13 ]; -MemoryRegion smram_region; -MemoryRegion smram, low_smram; +MemoryRegion smram_region, open_high_smram; +MemoryRegion smram, low_smram, high_smram;PcPciInfo pci_info;ram_addr_t below_4g_mem_size;ram_addr_t above_4g_mem_size;
@@ -127,7 +127,7 @@ typedef struct Q35PCIHost {#define MCH_HOST_BRIDGE_PAM_MASK ((uint8_t)0x3)#define MCH_HOST_BRIDGE_SMRAM 0x9d -#define MCH_HOST_BRIDGE_SMRAM_SIZE 1 +#define MCH_HOST_BRIDGE_SMRAM_SIZE 2#define MCH_HOST_BRIDGE_SMRAM_DEFAULT ((uint8_t)0x2)#define MCH_HOST_BRIDGE_SMRAM_D_OPEN ((uint8_t)(1 << 6))#define MCH_HOST_BRIDGE_SMRAM_D_CLS ((uint8_t)(1 << 5))
@@ -141,11 +141,11 @@ typedef struct Q35PCIHost {#define MCH_HOST_BRIDGE_UPPER_SYSTEM_BIOS_END 0x100000#define MCH_HOST_BRIDGE_ESMRAMC 0x9e -#define MCH_HOST_BRIDGE_ESMRAMC_H_SMRAME ((uint8_t)(1 << 6)) -#define MCH_HOST_BRIDGE_ESMRAMC_E_SMERR ((uint8_t)(1 << 5)) -#define MCH_HOST_BRIDGE_ESMRAMC_SM_CACHE ((uint8_t)(1 << 4)) -#define MCH_HOST_BRIDGE_ESMRAMC_SM_L1 ((uint8_t)(1 << 3)) -#define MCH_HOST_BRIDGE_ESMRAMC_SM_L2 ((uint8_t)(1 << 2)) +#define MCH_HOST_BRIDGE_ESMRAMC_H_SMRAME ((uint8_t)(1 << 7)) +#define MCH_HOST_BRIDGE_ESMRAMC_E_SMERR ((uint8_t)(1 << 6)) +#define MCH_HOST_BRIDGE_ESMRAMC_SM_CACHE ((uint8_t)(1 << 5)) +#define MCH_HOST_BRIDGE_ESMRAMC_SM_L1 ((uint8_t)(1 << 4)) +#define MCH_HOST_BRIDGE_ESMRAMC_SM_L2 ((uint8_t)(1 << 3))#define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_MASK ((uint8_t)(0x3 << 1))#define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_1MB ((uint8_t)(0x0 << 1))#define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_2MB ((uint8_t)(0x1 << 1))
Signature · 1 line
1.8.3.1
PATCH 18/31 q35: fix ESMRAMC default
In reply to Paolo BonziniFrom: Gerd Hoffmann <[email protected]>
--- hw/pci-host/q35.c | 1 + include/hw/pci-host/q35.h | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-)
hw/pci-host/q35.c +1 -0
@@ -351,6 +351,7 @@ static void mch_reset(DeviceState *qdev) MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT); d->config[MCH_HOST_BRIDGE_SMRAM ] =MCH_HOST_BRIDGE_SMRAM_DEFAULT ; + d->config[MCH_HOST_BRIDGE_ESMRAMC ] =MCH_HOST_BRIDGE_ESMRAMC_DEFAULT ;mch_update (mch); }
include/hw/pci-host/q35.h +6 -1
@@ -128,7 +128,6 @@ typedef struct Q35PCIHost {#define MCH_HOST_BRIDGE_SMRAM 0x9d#define MCH_HOST_BRIDGE_SMRAM_SIZE 2 -#define MCH_HOST_BRIDGE_SMRAM_DEFAULT ((uint8_t)0x2)#define MCH_HOST_BRIDGE_SMRAM_D_OPEN ((uint8_t)(1 << 6))#define MCH_HOST_BRIDGE_SMRAM_D_CLS ((uint8_t)(1 << 5))#define MCH_HOST_BRIDGE_SMRAM_D_LCK ((uint8_t)(1 << 4))
@@ -139,6 +138,8 @@ typedef struct Q35PCIHost {#define MCH_HOST_BRIDGE_SMRAM_C_END 0xc0000#define MCH_HOST_BRIDGE_SMRAM_C_SIZE 0x20000#define MCH_HOST_BRIDGE_UPPER_SYSTEM_BIOS_END 0x100000 +#define MCH_HOST_BRIDGE_SMRAM_DEFAULT \ + MCH_HOST_BRIDGE_SMRAM_C_BASE_SEG#define MCH_HOST_BRIDGE_ESMRAMC 0x9e#define MCH_HOST_BRIDGE_ESMRAMC_H_SMRAME ((uint8_t)(1 << 7))
@@ -151,6 +152,10 @@ typedef struct Q35PCIHost {#define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_2MB ((uint8_t)(0x1 << 1))#define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_8MB ((uint8_t)(0x2 << 1))#define MCH_HOST_BRIDGE_ESMRAMC_T_EN ((uint8_t)1) +#define MCH_HOST_BRIDGE_ESMRAMC_DEFAULT \ + (MCH_HOST_BRIDGE_ESMRAMC_SM_CACHE | \ + MCH_HOST_BRIDGE_ESMRAMC_SM_L1 | \ + MCH_HOST_BRIDGE_ESMRAMC_SM_L2)/* D1:F0 PCIE* port*/ #define MCH_PCIE_DEV 1
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 18/31] q35: fix ESMRAMC default
Quoted 1 line · Paolo Bonzini
From: Gerd Hoffmann <[email protected]>
[ more verbose commit message for squashing in ]
The cache bits in ESMRAMC are hardcoded to 1 (=disabled) according to the q35 mch specs. Add and use a define with this default.
While being at it also update the SMRAM default to use the name (no code change, just makes things a bit more readable).
Quoted 51 lines
Signed-off-by Gerd Hoffmann <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- hw/pci-host/q35.c | 1 + include/hw/pci-host/q35.h | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-)hw/pci-host/q35.c +1
-0@@ -351,6 +351,7 @@ static void mch_reset(DeviceState *qdev) MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT); d->config[MCH_HOST_BRIDGE_SMRAM ] =MCH_HOST_BRIDGE_SMRAM_DEFAULT ; + d->config[MCH_HOST_BRIDGE_ESMRAMC ] =MCH_HOST_BRIDGE_ESMRAMC_DEFAULT ;mch_update (mch); }include/hw/pci-host/q35.h +6
-1@@ -128,7 +128,6 @@ typedef struct Q35PCIHost {#define MCH_HOST_BRIDGE_SMRAM 0x9d#define MCH_HOST_BRIDGE_SMRAM_SIZE 2 -#define MCH_HOST_BRIDGE_SMRAM_DEFAULT ((uint8_t)0x2)#define MCH_HOST_BRIDGE_SMRAM_D_OPEN ((uint8_t)(1 << 6))#define MCH_HOST_BRIDGE_SMRAM_D_CLS ((uint8_t)(1 << 5))#define MCH_HOST_BRIDGE_SMRAM_D_LCK ((uint8_t)(1 << 4))@@ -139,6 +138,8 @@ typedef struct Q35PCIHost {#define MCH_HOST_BRIDGE_SMRAM_C_END 0xc0000#define MCH_HOST_BRIDGE_SMRAM_C_SIZE 0x20000#define MCH_HOST_BRIDGE_UPPER_SYSTEM_BIOS_END 0x100000 +#define MCH_HOST_BRIDGE_SMRAM_DEFAULT \ + MCH_HOST_BRIDGE_SMRAM_C_BASE_SEG#define MCH_HOST_BRIDGE_ESMRAMC 0x9e#define MCH_HOST_BRIDGE_ESMRAMC_H_SMRAME ((uint8_t)(1 << 7))@@ -151,6 +152,10 @@ typedef struct Q35PCIHost {#define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_2MB ((uint8_t)(0x1 << 1))#define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_8MB ((uint8_t)(0x2 << 1))#define MCH_HOST_BRIDGE_ESMRAMC_T_EN ((uint8_t)1) +#define MCH_HOST_BRIDGE_ESMRAMC_DEFAULT \ + (MCH_HOST_BRIDGE_ESMRAMC_SM_CACHE | \ + MCH_HOST_BRIDGE_ESMRAMC_SM_L1 | \ + MCH_HOST_BRIDGE_ESMRAMC_SM_L2)/* D1:F0 PCIE* port*/ #define MCH_PCIE_DEV 1
PATCH 19/31 q35: add config space wmask for SMRAM and ESMRAMC
In reply to Paolo BonziniFrom: Gerd Hoffmann <[email protected]>
--- hw/pci-host/q35.c | 2 ++ include/hw/pci-host/q35.h | 9 +++++++++ 2 files changed, 11 insertions(+)
hw/pci-host/q35.c +2 -0
@@ -352,6 +352,8 @@ static void mch_reset(DeviceState *qdev) d->config[MCH_HOST_BRIDGE_SMRAM ] =MCH_HOST_BRIDGE_SMRAM_DEFAULT ; d->config[MCH_HOST_BRIDGE_ESMRAMC ] =MCH_HOST_BRIDGE_ESMRAMC_DEFAULT ; + d->wmask[MCH_HOST_BRIDGE_SMRAM ] =MCH_HOST_BRIDGE_SMRAM_WMASK ; + d->wmask[MCH_HOST_BRIDGE_ESMRAMC ] =MCH_HOST_BRIDGE_ESMRAMC_WMASK ;mch_update (mch); }
include/hw/pci-host/q35.h +9 -0
@@ -140,6 +140,11 @@ typedef struct Q35PCIHost {#define MCH_HOST_BRIDGE_UPPER_SYSTEM_BIOS_END 0x100000#define MCH_HOST_BRIDGE_SMRAM_DEFAULT \ MCH_HOST_BRIDGE_SMRAM_C_BASE_SEG +#define MCH_HOST_BRIDGE_SMRAM_WMASK \ + (MCH_HOST_BRIDGE_SMRAM_D_OPEN | \ + MCH_HOST_BRIDGE_SMRAM_D_CLS | \ + MCH_HOST_BRIDGE_SMRAM_D_LCK | \ + MCH_HOST_BRIDGE_SMRAM_G_SMRAME)#define MCH_HOST_BRIDGE_ESMRAMC 0x9e#define MCH_HOST_BRIDGE_ESMRAMC_H_SMRAME ((uint8_t)(1 << 7))
@@ -156,6 +161,10 @@ typedef struct Q35PCIHost { (MCH_HOST_BRIDGE_ESMRAMC_SM_CACHE | \MCH_HOST_BRIDGE_ESMRAMC_SM_L1 | \ MCH_HOST_BRIDGE_ESMRAMC_SM_L2) +#define MCH_HOST_BRIDGE_ESMRAMC_WMASK \ + (MCH_HOST_BRIDGE_ESMRAMC_H_SMRAME | \ + MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_MASK | \ + MCH_HOST_BRIDGE_ESMRAMC_T_EN)/* D1:F0 PCIE* port*/ #define MCH_PCIE_DEV 1
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 19/31] q35: add config space wmask for SMRAM and ESMRAMC
Quoted 1 line · Paolo Bonzini
From: Gerd Hoffmann <[email protected]>
[ more verbose commit message for squashing in ]
Not all bits in SMRAM and ESMRAMC can be changed by the guest. Add wmask defines accordingly and set them in mch_reset().
Quoted 47 lines
Signed-off-by Gerd Hoffmann <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- hw/pci-host/q35.c | 2 ++ include/hw/pci-host/q35.h | 9 +++++++++ 2 files changed, 11 insertions(+)hw/pci-host/q35.c +2
-0@@ -352,6 +352,8 @@ static void mch_reset(DeviceState *qdev) d->config[MCH_HOST_BRIDGE_SMRAM ] =MCH_HOST_BRIDGE_SMRAM_DEFAULT ; d->config[MCH_HOST_BRIDGE_ESMRAMC ] =MCH_HOST_BRIDGE_ESMRAMC_DEFAULT ; + d->wmask[MCH_HOST_BRIDGE_SMRAM ] =MCH_HOST_BRIDGE_SMRAM_WMASK ; + d->wmask[MCH_HOST_BRIDGE_ESMRAMC ] =MCH_HOST_BRIDGE_ESMRAMC_WMASK ;mch_update (mch); }include/hw/pci-host/q35.h +9
-0@@ -140,6 +140,11 @@ typedef struct Q35PCIHost {#define MCH_HOST_BRIDGE_UPPER_SYSTEM_BIOS_END 0x100000#define MCH_HOST_BRIDGE_SMRAM_DEFAULT \ MCH_HOST_BRIDGE_SMRAM_C_BASE_SEG +#define MCH_HOST_BRIDGE_SMRAM_WMASK \ + (MCH_HOST_BRIDGE_SMRAM_D_OPEN | \ + MCH_HOST_BRIDGE_SMRAM_D_CLS | \ + MCH_HOST_BRIDGE_SMRAM_D_LCK | \ + MCH_HOST_BRIDGE_SMRAM_G_SMRAME)#define MCH_HOST_BRIDGE_ESMRAMC 0x9e#define MCH_HOST_BRIDGE_ESMRAMC_H_SMRAME ((uint8_t)(1 << 7))@@ -156,6 +161,10 @@ typedef struct Q35PCIHost { (MCH_HOST_BRIDGE_ESMRAMC_SM_CACHE | \MCH_HOST_BRIDGE_ESMRAMC_SM_L1 | \ MCH_HOST_BRIDGE_ESMRAMC_SM_L2) +#define MCH_HOST_BRIDGE_ESMRAMC_WMASK \ + (MCH_HOST_BRIDGE_ESMRAMC_H_SMRAME | \ + MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_MASK | \ + MCH_HOST_BRIDGE_ESMRAMC_T_EN)/* D1:F0 PCIE* port*/ #define MCH_PCIE_DEV 1
PATCH 21/31 q35: add test for SMRAM.D_LCK
In reply to Paolo BonziniFrom: Gerd Hoffmann <[email protected]>
--- tests/Makefile | 2 ++ tests/smram-test.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 tests/smram-test.c
tests/Makefile +2 -0
@@ -174,6 +174,7 @@ gcov-files-i386-y += hw/usb/dev-storage.c check-qtest-i386-y += tests/usb-hcd-xhci-test$(EXESUF) gcov-files-i386-y += hw/usb/hcd-xhci.c check-qtest-i386-y += tests/pc-cpu-test$(EXESUF) +check-qtest-i386-y += tests/smram-test$(EXESUF) check-qtest-i386-$(CONFIG_LINUX) += tests/vhost-user-test$(EXESUF) check-qtest-x86_64-y = $(check-qtest-i386-y) gcov-files-i386-y += i386-softmmu/hw/timer/mc146818rtc.c
@@ -389,6 +390,7 @@ tests/usb-hcd-uhci-test$(EXESUF): tests/usb-hcd-uhci-test.o $(libqos-usb-obj-y) tests/usb-hcd-ehci-test$(EXESUF): tests/usb-hcd-ehci-test.o $(libqos-usb-obj-y) tests/usb-hcd-xhci-test$(EXESUF): tests/usb-hcd-xhci-test.o $(libqos-usb-obj-y) tests/pc-cpu-test$(EXESUF): tests/pc-cpu-test.o +tests/smram-test$(EXESUF): tests/smram-test.o $(libqos-pc-obj-y) tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o qemu-char.o qemu-timer.o $(qtest-obj-y) tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o libqemuutil.a libqemustub.a
tests/smram-test.c new file +80 -0
80 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 22/31 q35: implement TSEG
In reply to Paolo BonziniFrom: Gerd Hoffmann <[email protected]>
TSEG provides larger amounts of SMRAM than the 128 KB available with legacy SMRAM and high SMRAM.
Route access to tseg into nowhere when enabled, for both cpus and busmaster dma, and add tseg window to smram region, so cpus can access it in smm mode.
--- hw/pci-host/q35.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++- include/hw/pci-host/q35.h | 1 + 2 files changed, 72 insertions(+), 1 deletion(-)
hw/pci-host/q35.c +71 -1
@@ -198,6 +198,28 @@ static const TypeInfo q35_host_info = {* MCH D0:F0 */ +static uint64_t tseg_blackhole_read (void *ptr,hwaddr reg,unsigned size) +{ +return 0xffffffff ; +} + +static void tseg_blackhole_write (void *opaque,hwaddr addr,uint64_t val, +unsigned width) +{ +/* nothing */ +} + +static const MemoryRegionOps tseg_blackhole_ops = { + .read = tseg_blackhole_read, + .write = tseg_blackhole_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .valid.min_access_size =1 , + .valid.max_access_size =4 , + .impl.min_access_size =4 , + .impl.max_access_size =4 , + .endianness =DEVICE_LITTLE_ENDIAN , +}; +/* PCIe MMCFG */ static void mch_update_pciexbar (MCHPCIState *mch) {
@@ -267,6 +289,7 @@ static void mch_update_smram(MCHPCIState *mch) {PCIDevice *pd =PCI_DEVICE (mch);bool h_smrame = (pd->config[MCH_HOST_BRIDGE_ESMRAMC ] &MCH_HOST_BRIDGE_ESMRAMC_H_SMRAME ); +uint32_t tseg_size;/* implement SMRAM.D_LCK */ if (pd->config[MCH_HOST_BRIDGE_SMRAM ] &MCH_HOST_BRIDGE_SMRAM_D_LCK ) {
@@ -296,6 +319,39 @@ static void mch_update_smram(MCHPCIState *mch)memory_region_set_enabled (&mch->high_smram, false); } +if (pd->config[MCH_HOST_BRIDGE_ESMRAMC ] &MCH_HOST_BRIDGE_ESMRAMC_T_EN ) { +switch (pd->config[MCH_HOST_BRIDGE_ESMRAMC ] & +MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_MASK ) { +case MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_1MB : + tseg_size =1024 *1024 ; +break ; +case MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_2MB : + tseg_size =1024 *1024 *2 ; +break ; +case MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_8MB : + tseg_size =1024 *1024 *8 ; +break ; +default : + tseg_size =0 ; +break ; + } + }else { + tseg_size =0 ; + } +memory_region_del_subregion (mch->system_memory, &mch->tseg_blackhole); +memory_region_set_enabled (&mch->tseg_blackhole, tseg_size); +memory_region_set_size (&mch->tseg_blackhole, tseg_size); +memory_region_add_subregion_overlap (mch->system_memory, + mch->below_4g_mem_size - tseg_size, + &mch->tseg_blackhole,1 ); + +memory_region_set_enabled (&mch->tseg_window, tseg_size); +memory_region_set_size (&mch->tseg_window, tseg_size); +memory_region_set_address (&mch->tseg_window, + mch->below_4g_mem_size - tseg_size); +memory_region_set_alias_offset (&mch->tseg_window, + mch->below_4g_mem_size - tseg_size); +memory_region_transaction_commit (); }
@@ -440,9 +496,23 @@ static void mch_realize(PCIDevice *d, Error **errp) mch->ram_memory, 0xa0000, 0x20000);memory_region_set_enabled (&mch->high_smram, true);memory_region_add_subregion (&mch->smram,0xfeda0000 , &mch->high_smram); + +memory_region_init_io (&mch->tseg_blackhole,OBJECT (mch), + &tseg_blackhole_ops,NULL , +"tseg-blackhole" ,0 ); +memory_region_set_enabled (&mch->tseg_blackhole, false); +memory_region_add_subregion_overlap (mch->system_memory, + mch->below_4g_mem_size, + &mch->tseg_blackhole,1 ); + +memory_region_init_alias (&mch->tseg_window,OBJECT (mch),"tseg-window" , + mch->ram_memory, mch->below_4g_mem_size,0 ); +memory_region_set_enabled (&mch->tseg_window, false); +memory_region_add_subregion (&mch->smram, mch->below_4g_mem_size, + &mch->tseg_window); +object_property_add_const_link (qdev_get_machine (),"smram" ,OBJECT (&mch->smram), &error_abort); -init_pam (DEVICE (mch), mch->ram_memory, mch->system_memory, mch->pci_address_space, &mch->pam_regions[0 ],PAM_BIOS_BASE ,PAM_BIOS_SIZE );
include/hw/pci-host/q35.h +1 -0
@@ -54,6 +54,7 @@ typedef struct MCHPCIState {PAMMemoryRegion pam_regions[13 ];MemoryRegion smram_region, open_high_smram;MemoryRegion smram, low_smram, high_smram; +MemoryRegion tseg_blackhole, tseg_window;PcPciInfo pci_info;ram_addr_t below_4g_mem_size;ram_addr_t above_4g_mem_size;
Signature · 1 line
1.8.3.1
PATCH 23/31 ich9: implement SMI_LOCK
In reply to Paolo BonziniFrom: Gerd Hoffmann <[email protected]>
--- hw/acpi/ich9.c | 4 +++- hw/isa/lpc_ich9.c | 19 +++++++++++++++++++ include/hw/acpi/ich9.h | 1 + include/hw/i386/ich9.h | 6 ++++++ 4 files changed, 29 insertions(+), 1 deletion(-)
hw/acpi/ich9.c +3 -1
@@ -94,7 +94,8 @@ static void ich9_smi_writel(void *opaque, hwaddr addr, uint64_t val,ICH9LPCPMRegs *pm = opaque;switch (addr) {case 0 : - pm->smi_en = val; + pm->smi_en &= ~pm->smi_en_wmask; + pm->smi_en |= (val & pm->smi_en_wmask);break ; } }
@@ -198,6 +199,7 @@ static void pm_reset(void *opaque)* support SMM mode. */ pm->smi_en |=ICH9_PMIO_SMI_EN_APMC_EN ; } + pm->smi_en_wmask = ~0 ;acpi_update_sci (&pm->acpi_regs, pm->irq); }
hw/isa/lpc_ich9.c +19 -0
@@ -410,12 +410,28 @@ static void ich9_lpc_rcba_update(ICH9LPCState *lpc, uint32_t rbca_old) } } +/* config:GEN_PMCON* */ +static void +ich9_lpc_pmcon_update (ICH9LPCState *lpc) +{ +uint16_t gen_pmcon_1 =pci_get_word (lpc->d.config +ICH9_LPC_GEN_PMCON_1 ); +uint16_t wmask; + +if (gen_pmcon_1 &ICH9_LPC_GEN_PMCON_1_SMI_LOCK ) { + wmask =pci_get_word (lpc->d.wmask +ICH9_LPC_GEN_PMCON_1 ); + wmask &= ~ICH9_LPC_GEN_PMCON_1_SMI_LOCK ; +pci_set_word (lpc->d.wmask +ICH9_LPC_GEN_PMCON_1 , wmask); + lpc->pm.smi_en_wmask &= ~1 ; + } +} +static int ich9_lpc_post_load (void *opaque,int version_id) {ICH9LPCState *lpc = opaque;ich9_lpc_pmbase_update (lpc);ich9_lpc_rcba_update (lpc,0 /* disabled ICH9_LPC_RBCA_EN */ ); +ich9_lpc_pmcon_update (lpc);return 0 ; }
@@ -438,6 +454,9 @@ static void ich9_lpc_config_write(PCIDevice *d,if (ranges_overlap (addr, len,ICH9_LPC_PIRQE_ROUT ,4 )) {pci_bus_fire_intx_routing_notifier (lpc->d.bus); } +if (ranges_overlap (addr, len,ICH9_LPC_GEN_PMCON_1 ,8 )) { +ich9_lpc_pmcon_update (lpc); + } }static void ich9_lpc_reset (DeviceState *qdev)
include/hw/acpi/ich9.h +1 -0
@@ -39,6 +39,7 @@ typedef struct ICH9LPCPMRegs {MemoryRegion io_smi;uint32_t smi_en; +uint32_t smi_en_wmask;uint32_t smi_sts;qemu_irq irq;/* SCI */
include/hw/i386/ich9.h +6 -0
@@ -152,6 +152,12 @@ Object *ich9_lpc_find(void);#define ICH9_LPC_PIRQ_ROUT_MASK Q35_MASK(8, 3, 0)#define ICH9_LPC_PIRQ_ROUT_DEFAULT 0x80 +#define ICH9_LPC_GEN_PMCON_1 0xa0 +#define ICH9_LPC_GEN_PMCON_1_SMI_LOCK (1 << 4) +#define ICH9_LPC_GEN_PMCON_2 0xa2 +#define ICH9_LPC_GEN_PMCON_3 0xa4 +#define ICH9_LPC_GEN_PMCON_LOCK 0xa6 +#define ICH9_LPC_RCBA 0xf0#define ICH9_LPC_RCBA_BA_MASK Q35_MASK(32, 31, 14)#define ICH9_LPC_RCBA_EN 0x1
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 23/31] ich9: implement SMI_LOCK
Quoted 43 lines · Paolo Bonzini
From: Gerd Hoffmann <[email protected]>
Signed-off-by Gerd Hoffmann <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- hw/acpi/ich9.c | 4 +++- hw/isa/lpc_ich9.c | 19 +++++++++++++++++++ include/hw/acpi/ich9.h | 1 + include/hw/i386/ich9.h | 6 ++++++ 4 files changed, 29 insertions(+), 1 deletion(-)hw/acpi/ich9.c +3
-1@@ -94,7 +94,8 @@ static void ich9_smi_writel(void *opaque, hwaddr addr, uint64_t val,ICH9LPCPMRegs *pm = opaque;switch (addr) {case 0 : - pm->smi_en = val; + pm->smi_en &= ~pm->smi_en_wmask; + pm->smi_en |= (val & pm->smi_en_wmask);break ; } }@@ -198,6 +199,7 @@ static void pm_reset(void *opaque)* support SMM mode. */ pm->smi_en |=ICH9_PMIO_SMI_EN_APMC_EN ; } + pm->smi_en_wmask = ~0 ;acpi_update_sci (&pm->acpi_regs, pm->irq); }hw/isa/lpc_ich9.c +2
-0@@ -410,12 +410,28 @@ static void ich9_lpc_rcba_update(ICH9LPCState *lpc, uint32_t rbca_old) } } +/* config:GEN_PMCON* */ +static void
hw/isa/lpc_ich9.c static void ich9_lpc_rcba_update(ICH9LPCState *lpc, uint32_t rbca_old) · line 424
Quoted 10 lines
hw/isa/lpc_ich9.c +10
-0+ich9_lpc_pmcon_update(ICH9LPCState *lpc) +{ +uint16_t gen_pmcon_1 =pci_get_word (lpc->d.config +ICH9_LPC_GEN_PMCON_1 ); +uint16_t wmask; + +if (gen_pmcon_1 &ICH9_LPC_GEN_PMCON_1_SMI_LOCK ) { + wmask =pci_get_word (lpc->d.wmask +ICH9_LPC_GEN_PMCON_1 ); + wmask &= ~ICH9_LPC_GEN_PMCON_1_SMI_LOCK ; +pci_set_word (lpc->d.wmask +ICH9_LPC_GEN_PMCON_1 , wmask); + lpc->pm.smi_en_wmask &= ~1 ;
If I understand correctly, this makes SMI_LOCK lock down the GBL_SMI_EN bit (and my OVMF patch that relies on that / tests it is satisfied too).
But, it doesn't seem to lock down APMC_EN. According to the ICH9 spec, it doesn't need to -- however when we discussed this earlier (see
Message-Id: <[email protected]>), the idea was to lock down APMC_EN as well. (And I don't understand why the ICH9 spec / hw implementation doesn't lock APMC_EN; without that, APM_CNT won't necessarily trigger an SMI.)
Thanks!
Laszlo
Quoted 43 lines
hw/isa/lpc_ich9.c +7
-0+ } +} +static int ich9_lpc_post_load (void *opaque,int version_id) {ICH9LPCState *lpc = opaque;ich9_lpc_pmbase_update (lpc);ich9_lpc_rcba_update (lpc,0 /* disabled ICH9_LPC_RBCA_EN */ ); +ich9_lpc_pmcon_update (lpc);return 0 ; }@@ -438,6 +454,9 @@ static void ich9_lpc_config_write(PCIDevice *d,if (ranges_overlap (addr, len,ICH9_LPC_PIRQE_ROUT ,4 )) {pci_bus_fire_intx_routing_notifier (lpc->d.bus); } +if (ranges_overlap (addr, len,ICH9_LPC_GEN_PMCON_1 ,8 )) { +ich9_lpc_pmcon_update (lpc); + } }static void ich9_lpc_reset (DeviceState *qdev)include/hw/acpi/ich9.h +1
-0@@ -39,6 +39,7 @@ typedef struct ICH9LPCPMRegs {MemoryRegion io_smi;uint32_t smi_en; +uint32_t smi_en_wmask;uint32_t smi_sts;qemu_irq irq;/* SCI */ include/hw/i386/ich9.h +0
-0@@ -152,6 +152,12 @@ Object *ich9_lpc_find(void);#define ICH9_LPC_PIRQ_ROUT_MASK Q35_MASK(8, 3, 0)#define ICH9_LPC_PIRQ_ROUT_DEFAULT 0x80
include/hw/i386/ich9.h Object *ich9_lpc_find(void); · line 163
Quoted 10 lines
include/hw/i386/ich9.h +6
-0+#define ICH9_LPC_GEN_PMCON_1 0xa0 +#define ICH9_LPC_GEN_PMCON_1_SMI_LOCK (1 << 4) +#define ICH9_LPC_GEN_PMCON_2 0xa2 +#define ICH9_LPC_GEN_PMCON_3 0xa4 +#define ICH9_LPC_GEN_PMCON_LOCK 0xa6 +#define ICH9_LPC_RCBA 0xf0#define ICH9_LPC_RCBA_BA_MASK Q35_MASK(32, 31, 14)#define ICH9_LPC_RCBA_EN 0x1
Thanks
Laszlo
Re: [Qemu-devel] [PATCH 23/31] ich9: implement SMI_LOCK
Quoted 9 lines · Laszlo Ersek
If I understand correctly, this makes
SMI_LOCKlock down theGBL_SMI_ENbit (and my OVMF patch that relies on that / tests it is satisfied too).But, it doesn't seem to lock down
APMC_EN. According to the ICH9 spec, it doesn't need to -- however when we discussed this earlier (see
Message-Id: <[email protected]>), the idea was to lock downAPMC_ENas well. (And I don't understand why the ICH9 spec / hw implementation doesn't lockAPMC_EN; without that,APM_CNTwon't necessarily trigger an SMI.)
I don't think it should. See here
<https://lists.gnu.org/archive/html/qemu-devel/2015-04/msg02758.html>
where I wrote explicitly "Even if the OS tries to maliciously set APMC_EN to 0 (SMI_LOCK doesn't lock APMC_EN)...".
Paolo
Re: [Qemu-devel] [PATCH 23/31] ich9: implement SMI_LOCK
Quoted 13 lines · Paolo Bonzini
Quoted 9 lines · Laszlo Ersek
If I understand correctly, this makes
SMI_LOCKlock down theGBL_SMI_ENbit (and my OVMF patch that relies on that / tests it is satisfied too).But, it doesn't seem to lock down
APMC_EN. According to the ICH9 spec, it doesn't need to -- however when we discussed this earlier (see
Message-Id: <[email protected]>), the idea was to lock downAPMC_ENas well. (And I don't understand why the ICH9 spec / hw implementation doesn't lockAPMC_EN; without that,APM_CNTwon't necessarily trigger an SMI.)
Quoted 4 lines
I don't think it should. See here
<https://lists.gnu.org/archive/html/qemu-devel/2015-04/msg02758.html>
where I wrote explicitly "Even if the OS tries to maliciously setAPMC_ENto 0 (SMI_LOCKdoesn't lockAPMC_EN)...".
It's not about feature detection -- the question (from <[email protected]>) is whether I should set APMC_EN myself *every time* before writing to APM_CNT, in the EFI_SMM_CONTROL2_PROTOCOL.Trigger() method. That protocol is provided by a runtime DXE driver and would be exercised by eg. the non-privileged half of the runtime variable service driver.
It's no problem to set it, I have the code ready, I was just wondering if I should keep that hunk. (In fact it might not even matter: if the OS interferes and clears APMC_EN before the non-privileged half mentioned above manages to raise the SMI, then the call / transition to SMM will simply not happen, which is bad for the OS, and probably irrelevant for the firmware (... the security thereof).)
I guess I'll keep re-setting APMC_EN in the Trigger() method; it won't hurt.
Thanks
Laszlo
Re: [Qemu-devel] [PATCH 23/31] ich9: implement SMI_LOCK
Quoted 6 lines · Laszlo Ersek
It's not about feature detection -- the question (from <[email protected]>) is whether I should set
APMC_ENmyself *every time* before writing toAPM_CNT, in theEFI_SMM_CONTROL2_PROTOCOL.Trigger()method. That protocol is provided by a runtime DXE driver and would be exercised by eg. the non-privileged half of the runtime variable service driver.
Oh sorry, I couldn't find that message ID.
Quoted 6 lines
It's no problem to set it, I have the code ready, I was just wondering if I should keep that hunk. (In fact it might not even matter: if the OS interferes and clears
APMC_ENbefore the non-privileged half mentioned above manages to raise the SMI, then the call / transition to SMM will simply not happen, which is bad for the OS, and probably irrelevant for the firmware (... the security thereof).)
The OS can also race against you and clear APMC_EN, so it's even unnecessary to reset it.
Paolo
Re: [Qemu-devel] [PATCH 23/31] ich9: implement SMI_LOCK
In reply to Paolo BonziniQuoted 1 line · Paolo Bonzini
From: Gerd Hoffmann <[email protected]>
[ more verbose commit message for squashing in ]
Add write mask for the smi enable register, so we can disable write access to certain bits. Open all bits on reset. Disable write access to GBL_SMI_EN when SMI_LOCK (in ich9 lpc pci config space) is set. Write access to SMI_LOCK itself is disabled too.
Quoted 103 lines
Signed-off-by Gerd Hoffmann <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- hw/acpi/ich9.c | 4 +++- hw/isa/lpc_ich9.c | 19 +++++++++++++++++++ include/hw/acpi/ich9.h | 1 + include/hw/i386/ich9.h | 6 ++++++ 4 files changed, 29 insertions(+), 1 deletion(-)hw/acpi/ich9.c +3
-1@@ -94,7 +94,8 @@ static void ich9_smi_writel(void *opaque, hwaddr addr, uint64_t val,ICH9LPCPMRegs *pm = opaque;switch (addr) {case 0 : - pm->smi_en = val; + pm->smi_en &= ~pm->smi_en_wmask; + pm->smi_en |= (val & pm->smi_en_wmask);break ; } }@@ -198,6 +199,7 @@ static void pm_reset(void *opaque)* support SMM mode. */ pm->smi_en |=ICH9_PMIO_SMI_EN_APMC_EN ; } + pm->smi_en_wmask = ~0 ;acpi_update_sci (&pm->acpi_regs, pm->irq); }hw/isa/lpc_ich9.c +19
-0@@ -410,12 +410,28 @@ static void ich9_lpc_rcba_update(ICH9LPCState *lpc, uint32_t rbca_old) } } +/* config:GEN_PMCON* */ +static void +ich9_lpc_pmcon_update (ICH9LPCState *lpc) +{ +uint16_t gen_pmcon_1 =pci_get_word (lpc->d.config +ICH9_LPC_GEN_PMCON_1 ); +uint16_t wmask; + +if (gen_pmcon_1 &ICH9_LPC_GEN_PMCON_1_SMI_LOCK ) { + wmask =pci_get_word (lpc->d.wmask +ICH9_LPC_GEN_PMCON_1 ); + wmask &= ~ICH9_LPC_GEN_PMCON_1_SMI_LOCK ; +pci_set_word (lpc->d.wmask +ICH9_LPC_GEN_PMCON_1 , wmask); + lpc->pm.smi_en_wmask &= ~1 ; + } +} +static int ich9_lpc_post_load (void *opaque,int version_id) {ICH9LPCState *lpc = opaque;ich9_lpc_pmbase_update (lpc);ich9_lpc_rcba_update (lpc,0 /* disabled ICH9_LPC_RBCA_EN */ ); +ich9_lpc_pmcon_update (lpc);return 0 ; }@@ -438,6 +454,9 @@ static void ich9_lpc_config_write(PCIDevice *d,if (ranges_overlap (addr, len,ICH9_LPC_PIRQE_ROUT ,4 )) {pci_bus_fire_intx_routing_notifier (lpc->d.bus); } +if (ranges_overlap (addr, len,ICH9_LPC_GEN_PMCON_1 ,8 )) { +ich9_lpc_pmcon_update (lpc); + } }static void ich9_lpc_reset (DeviceState *qdev)include/hw/acpi/ich9.h +1
-0@@ -39,6 +39,7 @@ typedef struct ICH9LPCPMRegs {MemoryRegion io_smi;uint32_t smi_en; +uint32_t smi_en_wmask;uint32_t smi_sts;qemu_irq irq;/* SCI */ include/hw/i386/ich9.h +6
-0@@ -152,6 +152,12 @@ Object *ich9_lpc_find(void);#define ICH9_LPC_PIRQ_ROUT_MASK Q35_MASK(8, 3, 0)#define ICH9_LPC_PIRQ_ROUT_DEFAULT 0x80 +#define ICH9_LPC_GEN_PMCON_1 0xa0 +#define ICH9_LPC_GEN_PMCON_1_SMI_LOCK (1 << 4) +#define ICH9_LPC_GEN_PMCON_2 0xa2 +#define ICH9_LPC_GEN_PMCON_3 0xa4 +#define ICH9_LPC_GEN_PMCON_LOCK 0xa6 +#define ICH9_LPC_RCBA 0xf0#define ICH9_LPC_RCBA_BA_MASK Q35_MASK(32, 31, 14)#define ICH9_LPC_RCBA_EN 0x1
PATCH 24/31 hw/acpi: acpi_pm1_cnt_init(): take "disable_s3" and "disable_s4"
In reply to Paolo BonziniFrom: Laszlo Ersek <[email protected]>
This patch only modifies the function prototype and updates all chipset code that calls acpi_pm1_cnt_init() to pass in their own disable_s3 and disable_s4 settings. vt82c686 is assumed to be fixed "S3 and S4 enabled".
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1204696
--- hw/acpi/core.c | 3 ++- hw/acpi/ich9.c | 3 ++- hw/acpi/piix4.c | 2 +- hw/isa/vt82c686.c | 2 +- include/hw/acpi/acpi.h | 3 ++- 5 files changed, 8 insertions(+), 5 deletions(-)
hw/acpi/core.c +2 -1
@@ -592,7 +592,8 @@ static const MemoryRegionOps acpi_pm_cnt_ops = { .endianness = DEVICE_LITTLE_ENDIAN, }; -void acpi_pm1_cnt_init (ACPIREGS *ar,MemoryRegion *parent,uint8_t s4_val) +void acpi_pm1_cnt_init (ACPIREGS *ar,MemoryRegion *parent, +bool disable_s3,bool disable_s4,uint8_t s4_val) { ar->pm1.cnt.s4_val = s4_val; ar->wakeup.notify = acpi_notify_wakeup;
hw/acpi/ich9.c +2 -1
@@ -221,7 +221,8 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,acpi_pm_tmr_init (&pm->acpi_regs, ich9_pm_update_sci_fn, &pm->io);acpi_pm1_evt_init (&pm->acpi_regs, ich9_pm_update_sci_fn, &pm->io); -acpi_pm1_cnt_init (&pm->acpi_regs, &pm->io, pm->s4_val); +acpi_pm1_cnt_init (&pm->acpi_regs, &pm->io, pm->disable_s3, pm->disable_s4, + pm->s4_val);acpi_gpe_init (&pm->acpi_regs,ICH9_PMIO_GPE0_LEN ); memory_region_init_io(&pm->io_gpe, OBJECT(lpc_pci), &ich9_gpe_ops, pm,
hw/acpi/piix4.c +1 -1
@@ -464,7 +464,7 @@ static void piix4_pm_realize(PCIDevice *dev, Error **errp)acpi_pm_tmr_init (&s->ar, pm_tmr_timer, &s->io);acpi_pm1_evt_init (&s->ar, pm_tmr_timer, &s->io); -acpi_pm1_cnt_init (&s->ar, &s->io, s->s4_val); +acpi_pm1_cnt_init (&s->ar, &s->io, s->disable_s3, s->disable_s4, s->s4_val);acpi_gpe_init (&s->ar,GPE_LEN ); s->powerdown_notifier.notify = piix4_pm_powerdown_req;
hw/isa/vt82c686.c +1 -1
@@ -356,7 +356,7 @@ static void vt82c686b_pm_realize(PCIDevice *dev, Error **errp)acpi_pm_tmr_init (&s->ar, pm_tmr_timer, &s->io);acpi_pm1_evt_init (&s->ar, pm_tmr_timer, &s->io); -acpi_pm1_cnt_init (&s->ar, &s->io,2 ); +acpi_pm1_cnt_init (&s->ar, &s->io, false, false,2 ); } I2CBus *vt82c686b_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
include/hw/acpi/acpi.h +2 -1
@@ -160,7 +160,8 @@ void acpi_pm1_evt_init(ACPIREGS *ar, acpi_update_sci_fn update_sci, MemoryRegion *parent);/* PM1a_CNT: piix and ich9 don't implement PM1b CNT. */ -void acpi_pm1_cnt_init (ACPIREGS *ar,MemoryRegion *parent,uint8_t s4_val); +void acpi_pm1_cnt_init (ACPIREGS *ar,MemoryRegion *parent, +bool disable_s3,bool disable_s4,uint8_t s4_val);void acpi_pm1_cnt_update (ACPIREGS *ar,bool sci_enable,bool sci_disable);void acpi_pm1_cnt_reset (ACPIREGS *ar);
Signature · 1 line
1.8.3.1
PATCH 25/31 hw/acpi: move "etc/system-states" fw_cfg file from PIIX4 to core
In reply to Paolo BonziniFrom: Laszlo Ersek <[email protected]>
The acpi_pm1_cnt_init() core function is responsible for setting up the register block that will ultimately react to S3 and S4 requests (see acpi_pm1_cnt_write()). It makes sense to advertise this configuration to the guest firmware via an easy to parse fw_cfg file (ACPI is too complex for firmware to parse), and indeed PIIX4 does that. However, since acpi_pm1_cnt_init() is not specific to PIIX4, neither should be the fw_cfg file.
This patch makes "etc/system-states" appear on all chipsets modified in the previous patch, not just PIIX4 (assuming they have fw_cfg at all).
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1204696
--- hw/acpi/core.c | 12 ++++++++++++ hw/acpi/piix4.c | 8 -------- 2 files changed, 12 insertions(+), 8 deletions(-)
hw/acpi/core.c +12 -0
@@ -22,6 +22,7 @@#include "hw/hw.h" #include "hw/i386/pc.h" #include "hw/acpi/acpi.h" +#include "hw/nvram/fw_cfg.h" #include "qemu/config-file.h" #include "qapi/opts-visitor.h" #include "qapi/dealloc-visitor.h"
@@ -595,12 +596,23 @@ static const MemoryRegionOps acpi_pm_cnt_ops = {void acpi_pm1_cnt_init (ACPIREGS *ar,MemoryRegion *parent,bool disable_s3,bool disable_s4,uint8_t s4_val) { +FWCfgState *fw_cfg; + ar->pm1.cnt.s4_val = s4_val; ar->wakeup.notify = acpi_notify_wakeup;qemu_register_wakeup_notifier (&ar->wakeup);memory_region_init_io (&ar->pm1.cnt.io,memory_region_owner (parent), &acpi_pm_cnt_ops, ar,"acpi-cnt" ,2 );memory_region_add_subregion (parent,4 , &ar->pm1.cnt.io); + + fw_cfg =fw_cfg_find (); +if (fw_cfg) { +uint8_t suspend[6 ] = {128 ,0 ,0 ,129 ,128 ,128 }; + suspend[3 ] =1 | ((!disable_s3) <<7 ); + suspend[4 ] = s4_val | ((!disable_s4) <<7 ); + +fw_cfg_add_file (fw_cfg,"etc/system-states" ,g_memdup (suspend,6 ),6 ); + } }void acpi_pm1_cnt_reset (ACPIREGS *ar)
hw/acpi/piix4.c +0 -8
@@ -514,14 +514,6 @@ I2CBus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,qdev_init_nofail (dev); -if (fw_cfg) { -uint8_t suspend[6 ] = {128 ,0 ,0 ,129 ,128 ,128 }; - suspend[3 ] =1 | ((!s->disable_s3) <<7 ); - suspend[4 ] = s->s4_val | ((!s->disable_s4) <<7 ); - -fw_cfg_add_file (fw_cfg,"etc/system-states" ,g_memdup (suspend,6 ),6 ); - } -return s->smb.smbus; }
Signature · 1 line
1.8.3.1
PATCH 26/31 hw/acpi: piix4_pm_init(): take fw_cfg object no more
In reply to Paolo BonziniFrom: Laszlo Ersek <[email protected]>
This PIIX4 init function has no more reason to receive a pointer to the FwCfg object. Remove the parameter from the prototype, and update callers.
As a result, the pc_init1() function no longer needs to save the return value of pc_memory_init() and xen_load_linux(), which makes it more similar to pc_q35_init().
The return type & value of pc_memory_init() and xen_load_linux() are not changed themselves; maybe we'll need their return values sometime later.
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1204696
--- hw/acpi/piix4.c | 3 +-- hw/i386/pc_piix.c | 19 +++++++++---------- hw/mips/mips_malta.c | 2 +- include/hw/i386/pc.h | 3 +-- 4 files changed, 12 insertions(+), 15 deletions(-)
hw/acpi/piix4.c +1 -2
@@ -492,8 +492,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,FWCfgState *fw_cfg, -DeviceState **piix4_pm) +int kvm_enabled,DeviceState **piix4_pm) {DeviceState *dev;PIIX4PMState *s;
hw/i386/pc_piix.c +9 -10
@@ -99,7 +99,6 @@ static void pc_init1(MachineState *machine,MemoryRegion *pci_memory;MemoryRegion *rom_memory;DeviceState *icc_bridge; -FWCfgState *fw_cfg =NULL ;PcGuestInfo *guest_info;ram_addr_t lowmem;
@@ -180,16 +179,16 @@ static void pc_init1(MachineState *machine,/* allocate ram and load rom/bios */ if (!xen_enabled ()) { - fw_cfg =pc_memory_init (machine, system_memory, - below_4g_mem_size, above_4g_mem_size, - rom_memory, &ram_memory, guest_info); +pc_memory_init (machine, system_memory, + below_4g_mem_size, above_4g_mem_size, + rom_memory, &ram_memory, guest_info); }else if (machine->kernel_filename !=NULL ) {/* For xen HVM direct kernel boot, load linux here */ - fw_cfg =xen_load_linux (machine->kernel_filename, - machine->kernel_cmdline, - machine->initrd_filename, - below_4g_mem_size, - guest_info); +xen_load_linux (machine->kernel_filename, + machine->kernel_cmdline, + machine->initrd_filename, + below_4g_mem_size, + guest_info); } gsi_state =g_malloc0 (sizeof (*gsi_state));
@@ -288,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 (), fw_cfg, &piix4_pm); +kvm_enabled (), &piix4_pm);smbus_eeprom_init (smbus,8 ,NULL ,0 ); object_property_add_link(OBJECT(machine), PC_MACHINE_ACPI_DEVICE_PROP,
hw/mips/mips_malta.c +1 -1
@@ -1161,7 +1161,7 @@ void mips_malta_init(MachineState *machine)pci_piix4_ide_init (pci_bus, hd, piix4_devfn +1 );pci_create_simple (pci_bus, piix4_devfn +2 ,"piix4-usb-uhci" ); smbus =piix4_pm_init (pci_bus, piix4_devfn +3 ,0x1100 , -isa_get_irq (NULL ,9 ),NULL ,0 ,NULL ,NULL ); +isa_get_irq (NULL ,9 ),NULL ,0 ,NULL );smbus_eeprom_init (smbus,8 , smbus_eeprom_buf, smbus_eeprom_size);g_free (smbus_eeprom_buf); pit =pit_init (isa_bus,0x40 ,0 ,NULL );
include/hw/i386/pc.h +1 -2
@@ -218,8 +218,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,FWCfgState *fw_cfg, -DeviceState **piix4_pm); +int kvm_enabled,DeviceState **piix4_pm);void piix4_smbus_register_device (SMBusDevice *dev,uint8_t addr);/* hpet.c */
Signature · 1 line
1.8.3.1
PATCH 27/31 target-i386: add support for SMBASE MSR and SMIs
In reply to Paolo BonziniApart 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.
--- linux-headers/asm-x86/kvm.h | 11 ++++++- linux-headers/linux/kvm.h | 5 +++- target-i386/cpu.h | 1 + target-i386/kvm.c | 73 ++++++++++++++++++++++++++++++++++++++++----- 4 files changed, 81 insertions(+), 9 deletions(-)
linux-headers/asm-x86/kvm.h +10 -1
@@ -48,6 +48,8 @@/* Architectural interrupt line count. */ #define KVM_NR_INTERRUPTS 256 +#define KVM_RUN_X86_SMM (1 << 0) +struct kvm_memory_alias {__u32 slot;/* this has a different namespace than memory slots */ __u32 flags;
@@ -281,6 +283,7 @@ struct kvm_reinject_control {#define KVM_VCPUEVENT_VALID_NMI_PENDING 0x00000001#define KVM_VCPUEVENT_VALID_SIPI_VECTOR 0x00000002#define KVM_VCPUEVENT_VALID_SHADOW 0x00000004 +#define KVM_VCPUEVENT_VALID_SMM 0x00000008/* Interrupt shadow states */ #define KVM_X86_SHADOW_INT_MOV_SS 0x01
@@ -309,7 +312,13 @@ struct kvm_vcpu_events { } nmi;__u32 sipi_vector;__u32 flags; -__u32 reserved[10 ]; +struct { +__u8 smm; +__u8 pending; +__u8 smm_inside_nmi; +__u8 pad; + } smi; +__u32 reserved[9 ]; };/* for KVM_GET/SET_DEBUGREGS */
linux-headers/linux/kvm.h +4 -1
@@ -202,7 +202,7 @@ struct kvm_run {__u32 exit_reason;__u8 ready_for_interrupt_injection;__u8 if_flag; -__u8 padding2[2 ]; +__u16 flags;/* in (pre_kvm_run), out (post_kvm_run) */ __u64 cr8;
@@ -814,6 +814,7 @@ struct kvm_ppc_smmu_info {#define KVM_CAP_S390_INJECT_IRQ 113#define KVM_CAP_S390_IRQ_STATE 114#define KVM_CAP_PPC_HWRNG 115 +#define KVM_CAP_X86_SMM 116#ifdef KVM_CAP_IRQ_ROUTING
@@ -1199,6 +1200,8 @@ struct kvm_s390_ucas_mapping {/* Available with KVM_CAP_S390_IRQ_STATE */ #define KVM_S390_SET_IRQ_STATE _IOW(KVMIO, 0xb5, struct kvm_s390_irq_state)#define KVM_S390_GET_IRQ_STATE _IOW(KVMIO, 0xb6, struct kvm_s390_irq_state) +/* Available with KVM_CAP_X86_SMM */ +#define KVM_SMI _IO(KVMIO, 0xb7)#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)#define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1)
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 +66 -7
133 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 28/31 vga: disable chain4_alias if KVM supports SMRAM
In reply to Paolo BonziniKVM is okay with SMRAM overlapping an MMIO area underneath it, but it does not want to have two overlapping RAM slots for SMRAM and video RAM. Unfortunately, the chain4_alias optimization results in the latter situation. Disable it if KVM supports system management mode.
Note that the chain4_alias optimization is misguided, because it assumes that chain4 data is at VRAM address 0,1,2,3,4,5,6,7...16383. This is incorrect, because chain4 data is at VRAM address 0,1,2,3, 16,17,18,19, ..., 65523. But we cannot fix the VRAM format without breaking migration, so keep the optimization and just disable it if it gets in the way.
--- hw/display/vga.c | 8 ++++++-- hw/display/vga_int.h | 1 + include/sysemu/kvm.h | 1 + kvm-all.c | 5 +++++ kvm-stub.c | 5 +++++ 5 files changed, 18 insertions(+), 2 deletions(-)
hw/display/vga.c +6 -2
@@ -154,7 +154,8 @@ static void vga_update_memory_access(VGACommonState *s) s->has_chain4_alias = false; s->plane_updated =0xf ; } -if ((s->sr[VGA_SEQ_PLANE_WRITE ] &VGA_SR02_ALL_PLANES ) == +if (s->use_chain4_alias && + (s->sr[VGA_SEQ_PLANE_WRITE ] &VGA_SR02_ALL_PLANES ) ==VGA_SR02_ALL_PLANES && s->sr[VGA_SEQ_MEMORY_MODE ] &VGA_SR04_CHN_4M ) { offset =0 ;switch ((s->gr[VGA_GFX_MISC ] >>2 ) &3 ) {
@@ -2219,8 +2220,11 @@ void vga_init(VGACommonState *s, Object *obj, MemoryRegion *address_space,qemu_register_reset (vga_reset, s); - s->bank_offset =0 ; +if (!kvm_enabled () || !kvm_has_smm ()) { + s->use_chain4_alias = true; + } + s->bank_offset =0 ; s->legacy_address_space = address_space; vga_io_memory =vga_init_io (s, obj, &vga_ports, &vbe_ports);
hw/display/vga_int.h +1 -0
@@ -95,6 +95,7 @@ typedef struct VGACommonState {uint32_t vram_size_mb;/* property */ uint32_t vbe_size;uint32_t latch; +bool use_chain4_alias;bool has_chain4_alias;MemoryRegion chain4_alias;uint8_t sr_index;
include/sysemu/kvm.h +1 -0
@@ -186,6 +186,7 @@ int kvm_has_pit_state2(void);int kvm_has_many_ioeventfds (void );int kvm_has_gsi_routing (void );int kvm_has_intx_set_mask (void ); +int kvm_has_smm (void );int kvm_init_vcpu (CPUState *cpu);int kvm_cpu_exec (CPUState *cpu);
kvm-all.c +5 -0
@@ -1990,6 +1990,11 @@ int kvm_vm_check_attr(KVMState *s, uint32_t group, uint64_t attr)return ret ?0 :1 ; } +int kvm_has_smm (void ) +{ +return kvm_check_extension (kvm_state,KVM_CAP_X86_SMM ); +} +int kvm_has_sync_mmu (void ) {return kvm_check_extension (kvm_state,KVM_CAP_SYNC_MMU );
kvm-stub.c +5 -0
@@ -56,6 +56,11 @@ int kvm_cpu_exec(CPUState *cpu)abort (); } +int kvm_has_smm (void ) +{ +return 0 ; +} +int kvm_has_sync_mmu (void ) {return 0 ;
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 28/31] vga: disable chain4_alias if KVM supports SMRAM
This actually is not needed anymore in the latest incarnation of the kernel-side interface.
Paolo
Quoted 104 lines · Paolo Bonzini
KVM is okay with SMRAM overlapping an MMIO area underneath it, but it does not want to have two overlapping RAM slots for SMRAM and video RAM. Unfortunately, the
chain4_aliasoptimization results in the latter situation. Disable it if KVM supports system management mode.Note that the
chain4_aliasoptimization is misguided, because it assumes that chain4 data is at VRAM address 0,1,2,3,4,5,6,7...16383. This is incorrect, because chain4 data is at VRAM address 0,1,2,3, 16,17,18,19, ..., 65523. But we cannot fix the VRAM format without breaking migration, so keep the optimization and just disable it if it gets in the way.Signed-off-by Paolo Bonzini <[email protected]>--- hw/display/vga.c | 8 ++++++-- hw/display/vga_int.h | 1 + include/sysemu/kvm.h | 1 + kvm-all.c | 5 +++++ kvm-stub.c | 5 +++++ 5 files changed, 18 insertions(+), 2 deletions(-)hw/display/vga.c +6
-2@@ -154,7 +154,8 @@ static void vga_update_memory_access(VGACommonState *s) s->has_chain4_alias = false; s->plane_updated =0xf ; } -if ((s->sr[VGA_SEQ_PLANE_WRITE ] &VGA_SR02_ALL_PLANES ) == +if (s->use_chain4_alias && + (s->sr[VGA_SEQ_PLANE_WRITE ] &VGA_SR02_ALL_PLANES ) ==VGA_SR02_ALL_PLANES && s->sr[VGA_SEQ_MEMORY_MODE ] &VGA_SR04_CHN_4M ) { offset =0 ;switch ((s->gr[VGA_GFX_MISC ] >>2 ) &3 ) {@@ -2219,8 +2220,11 @@ void vga_init(VGACommonState *s, Object *obj, MemoryRegion *address_space,qemu_register_reset (vga_reset, s); - s->bank_offset =0 ; +if (!kvm_enabled () || !kvm_has_smm ()) { + s->use_chain4_alias = true; + } + s->bank_offset =0 ; s->legacy_address_space = address_space; vga_io_memory =vga_init_io (s, obj, &vga_ports, &vbe_ports);hw/display/vga_int.h +1
-0@@ -95,6 +95,7 @@ typedef struct VGACommonState {uint32_t vram_size_mb;/* property */ uint32_t vbe_size;uint32_t latch; +bool use_chain4_alias;bool has_chain4_alias;MemoryRegion chain4_alias;uint8_t sr_index;include/sysemu/kvm.h +1
-0@@ -186,6 +186,7 @@ int kvm_has_pit_state2(void);int kvm_has_many_ioeventfds (void );int kvm_has_gsi_routing (void );int kvm_has_intx_set_mask (void ); +int kvm_has_smm (void );int kvm_init_vcpu (CPUState *cpu);int kvm_cpu_exec (CPUState *cpu);kvm-all.c +5
-0@@ -1990,6 +1990,11 @@ int kvm_vm_check_attr(KVMState *s, uint32_t group, uint64_t attr)return ret ?0 :1 ; } +int kvm_has_smm (void ) +{ +return kvm_check_extension (kvm_state,KVM_CAP_X86_SMM ); +} +int kvm_has_sync_mmu (void ) {return kvm_check_extension (kvm_state,KVM_CAP_SYNC_MMU );kvm-stub.c +5
-0@@ -56,6 +56,11 @@ int kvm_cpu_exec(CPUState *cpu)abort (); } +int kvm_has_smm (void ) +{ +return 0 ; +} +int kvm_has_sync_mmu (void ) {return 0 ;
PATCH 29/31 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 +++++----- include/hw/i386/pc.h | 2 +- 2 files changed, 6 insertions(+), 6 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;
@@ -321,7 +321,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 ; }
@@ -441,7 +441,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 ;
@@ -492,7 +492,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;
@@ -506,7 +506,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; }
include/hw/i386/pc.h +1 -1
@@ -218,7 +218,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
PATCH 30/31 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 | 4 ++-- include/hw/acpi/ich9.h | 3 ++- include/hw/i386/ich9.h | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-)
hw/acpi/ich9.c +3 -2
@@ -194,7 +194,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 ;
@@ -211,7 +211,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 );
@@ -233,6 +233,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
@@ -254,7 +254,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 +2 -2
@@ -357,13 +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; sci_irq =qemu_allocate_irqs (ich9_set_sci, lpc,1 ); -ich9_pm_init (lpc_pci, &lpc->pm, sci_irq[0 ]); +ich9_pm_init (lpc_pci, &lpc->pm, smm_enabled, sci_irq[0 ]);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
PATCH 31/31 pc: add SMM property
In reply to Paolo Bonzini--- hw/i386/pc.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ hw/i386/pc_piix.c | 7 ++++++- hw/i386/pc_q35.c | 7 ++++++- include/hw/i386/pc.h | 3 +++ 4 files changed, 66 insertions(+), 2 deletions(-)
hw/i386/pc.c +51 -0
@@ -1790,6 +1790,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);
@@ -1814,6 +1856,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,
@@ -311,6 +312,10 @@ static void pc_init_pci(MachineState *machine)static void pc_compat_2_3 (MachineState *machine) { +PCMachineState *pcms =PC_MACHINE (machine); +if (kvm_enabled ()) { + pcms->smm =ON_OFF_AUTO_OFF ; + } }static void pc_compat_2_2 (MachineState *machine)
hw/i386/pc_q35.c +6 -1
@@ -254,7 +254,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,
@@ -291,6 +291,11 @@ static void pc_q35_init(MachineState *machine)static void pc_compat_2_3 (MachineState *machine) { +/* FIXME -> 2.3 */ +PCMachineState *pcms =PC_MACHINE (machine); +if (kvm_enabled ()) { + pcms->smm =ON_OFF_AUTO_OFF ; + } }static void pc_compat_2_2 (MachineState *machine)
include/hw/i386/pc.h +3 -0
@@ -40,6 +40,7 @@ struct PCMachineState {uint64_t max_ram_below_4g;OnOffAuto vmport; +OnOffAuto smm;bool enforce_aligned_dimm; };
@@ -47,6 +48,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"/**
@@ -160,6 +162,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
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [Qemu-devel] [PATCH 20/31] q35: implement SMRAM.D_LCK
Quoted 1 line · Paolo Bonzini
From: Gerd Hoffmann <[email protected]>
[ more verbose commit message for squashing in ]
Once the SMRAM.D_LCK bit has been set by the guest several bits in SMRAM and ESMRAMC become readonly until the next machine reset. Implement this by updating the wmask accordingly when the guest sets the lock bit. As the lock it itself is locked down too we don't need to worry about the guest clearing the lock bit.
Quoted 54 lines
Signed-off-by Gerd Hoffmann <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- hw/pci-host/q35.c | 8 +++++++- include/hw/pci-host/q35.h | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-)hw/pci-host/q35.c +7
-1@@ -268,6 +268,13 @@ static void mch_update_smram(MCHPCIState *mch)PCIDevice *pd =PCI_DEVICE (mch);bool h_smrame = (pd->config[MCH_HOST_BRIDGE_ESMRAMC ] &MCH_HOST_BRIDGE_ESMRAMC_H_SMRAME ); +/* implement SMRAM.D_LCK */ +if (pd->config[MCH_HOST_BRIDGE_SMRAM ] &MCH_HOST_BRIDGE_SMRAM_D_LCK ) { + pd->config[MCH_HOST_BRIDGE_SMRAM ] &= ~MCH_HOST_BRIDGE_SMRAM_D_OPEN ; + pd->wmask[MCH_HOST_BRIDGE_SMRAM ] =MCH_HOST_BRIDGE_SMRAM_WMASK_LCK ; + pd->wmask[MCH_HOST_BRIDGE_ESMRAMC ] =MCH_HOST_BRIDGE_ESMRAMC_WMASK_LCK ; + } +memory_region_transaction_begin ();if (pd->config[MCH_HOST_BRIDGE_SMRAM ] &SMRAM_D_OPEN ) {@@ -297,7 +304,6 @@ static void mch_write_config(PCIDevice *d, {MCHPCIState *mch =MCH_PCI_DEVICE (d); -/* XXX: implement SMRAM.D_LOCK */ pci_default_write_config (d, address, val, len); if (ranges_overlap(address, len, MCH_HOST_BRIDGE_PAM0,include/hw/pci-host/q35.h +3
-0@@ -145,6 +145,8 @@ typedef struct Q35PCIHost { MCH_HOST_BRIDGE_SMRAM_D_CLS | \ MCH_HOST_BRIDGE_SMRAM_D_LCK | \ MCH_HOST_BRIDGE_SMRAM_G_SMRAME) +#define MCH_HOST_BRIDGE_SMRAM_WMASK_LCK \ + MCH_HOST_BRIDGE_SMRAM_D_CLS#define MCH_HOST_BRIDGE_ESMRAMC 0x9e#define MCH_HOST_BRIDGE_ESMRAMC_H_SMRAME ((uint8_t)(1 << 7))@@ -165,6 +167,7 @@ typedef struct Q35PCIHost { (MCH_HOST_BRIDGE_ESMRAMC_H_SMRAME | \MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_MASK | \ MCH_HOST_BRIDGE_ESMRAMC_T_EN) +#define MCH_HOST_BRIDGE_ESMRAMC_WMASK_LCK 0/* D1:F0 PCIE* port*/ #define MCH_PCIE_DEV 1
Quoted 4 lines · Paolo Bonzini
These patches implement almost everything that is needed for SMM support in OVMF and KVM. The only missing bit is support for SMRAM regions in KVM, but it need not block review of these ones, and possibly inclusion of the first 26.
Overall this looks good to me.
Sent some comments, and IIUC there will v2 down the road?
Quoted 137 lines
There are many small parts in this patches, but I am posting them together because each small part alone adds very little.
Patch 1 comes from mst's pull request.
Patches 2-6 are target-i386 patches. They add support for memory attributes in target-i386, enabling the "secure" attribute whenever the CPU is in system management mode. They also fix two SMM bugs found while working on KVM support.
Patches 7-9 add support for secure access to parallel flash. If enabled, parallel flash behaves as ROM unless the "secure" memory transaction attribute is set.
Patches 10-12 are general infrastructure patches that didn't fit elsewhere. Note that patch 10 introduces new command-line syntax.
Patches 13-16 rewrite the SMRAM handling in TCG mode, so that the SMRAM setup is done just once using the memory API, and then enabled/disabled by the CPU without intervention from the chipset. The resulting chipset code is simpler and...
... patches 17-23 then rely on this to implement support for more q35 SMI features, in particular high SMRAM, TSEG and
SMI_LOCK. This part was done almost entirely by Gerd.Patches 24-26 are for q35 feature parity with PIIX4. They are from Laszlo and they are included just because they conflict with the next few.
Patches 27 and 28 implement KVM support for SMM. Note that this support is not yet upstream (will be in Linux 4.2); these patches will be rebased after the updated KVM headers are taken from kvm.git.
Patches 29-31 add a "-machine smm=on|off|auto" option (QOM property) that can be used to hide SMM or make it available on any accelerator. The compat gunk makes it available by default on TCG but not on KVM.
That's it. Go ahead and review.
Paolo
Gerd Hoffmann (6):
q35: fix ESMRAMC default
q35: add config space wmask for SMRAM and ESMRAMC
q35: implement SMRAM.D_LCK
q35: add test for SMRAM.D_LCK
q35: implement TSEG
ich9: implementSMI_LOCKJason Wang (1):
pc: add 2.4 machine typesLaszlo Ersek (3):
hw/acpi:acpi_pm1_cnt_init(): take "disable_s3" and "disable_s4" hw/acpi: move "etc/system-states"fw_cfgfile from PIIX4 to core hw/acpi:piix4_pm_init(): takefw_cfgobject no morePaolo Bonzini (21):
target-i386: introducecpu_get_mem_attrs
target-i386: Use correct memory attributes for memory accesses
target-i386: Use correct memory attributes for ioport accesses
target-i386: mask NMIs on entry to SMM
target-i386: set G=1 in SMM big real mode selectors
pflash_cfi01: change big-endian property to BIT type
pflash_cfi01: change to new-style MMIO accessors
pflash_cfi01: add secure property
vl: allow full-blown QemuOpts syntax for -global
qom: addobject_property_add_const_link
vl: run "late" notifiers immediately
target-i386: create a separate AddressSpace for each CPU hw/i386: add a separate region that tracks the SMRAME bit
target-i386: use memory API to implement SMRAM hw/i386: removesmram_update
q35: implement high SMRAM
target-i386: add support for SMBASE MSR and SMIs
vga: disablechain4_aliasif KVM supports SMRAM
pc_piix: renamekvm_enabledtosmm_enabled
ich9: addsmm_enabledfield and arguments
pc: add SMM propertybsd-user/main.c | 4 - hw/acpi/core.c | 15 +- hw/acpi/ich9.c | 12 +- hw/acpi/piix4.c | 21 +-- hw/block/pflash_cfi01.c | 204 +++++++++++---------------- hw/display/vga.c | 8 +- hw/display/vga_int.h | 1 + hw/i386/pc.c | 72 +++++++--- hw/i386/pc_piix.c | 53 +++++-- hw/i386/pc_q35.c | 33 ++++- hw/isa/lpc_ich9.c | 23 ++- hw/isa/vt82c686.c | 2 +- hw/mips/mips_malta.c | 2 +- hw/pci-host/pam.c | 20 --- hw/pci-host/piix.c | 39 +++--- hw/pci-host/q35.c | 137 ++++++++++++++++-- include/exec/memattrs.h | 4 +- include/hw/acpi/acpi.h | 3 +- include/hw/acpi/ich9.h | 4 +- include/hw/i386/ich9.h | 8 +- include/hw/i386/pc.h | 7 +- include/hw/pci-host/pam.h | 4 - include/hw/pci-host/q35.h | 36 +++-- include/qom/object.h | 18 +++ include/sysemu/kvm.h | 1 + kvm-all.c | 5 + kvm-stub.c | 5 + linux-headers/asm-x86/kvm.h | 11 +- linux-headers/linux/kvm.h | 5 +- linux-user/main.c | 4 - qdev-monitor.c | 18 ++- qemu-options.hx | 7 +- qom/object.c | 16 +++ target-i386/Makefile.objs | 2 - target-i386/cpu-qom.h | 3 + target-i386/cpu.c | 43 ++++++ target-i386/cpu.h | 41 ++++-- target-i386/helper.c | 135 +++++++++++++++--- target-i386/helper.h | 12 +- target-i386/ioport-user.c | 60 -------- target-i386/kvm.c | 75 ++++++++-- target-i386/machine.c | 3 + target-i386/misc_helper.c | 59 ++++++-- target-i386/seg_helper.c | 12 +- target-i386/smm_helper.c | 331 +++++++++++++++++++++++--------------------- target-i386/svm_helper.c | 230 +++++++++++++++--------------- target-i386/translate.c | 12 +- tests/Makefile | 2 + tests/smram-test.c | 80 +++++++++++ vl.c | 6 + 50 files changed, 1220 insertions(+), 688 deletions(-) delete mode 100644 target-i386/ioport-user.c create mode 100644 tests/smram-test.cSignature · 1 line
1.8.3.1
Quoted 8 lines · Michael S. Tsirkin
Quoted 4 lines · Paolo Bonzini
These patches implement almost everything that is needed for SMM support in OVMF and KVM. The only missing bit is support for SMRAM regions in KVM, but it need not block review of these ones, and possibly inclusion of the first 26.
Overall this looks good to me.
Sent some comments, and IIUC there will v2 down the road?
I would like to send a pull request for the non-KVM parts (up to patch
23) on Wednesday or Thursday. The remaining pieces have to wait for inclusion of KVM support in the kernel, and there will be a v2 with minimal changes posted during soft freeze.
Let me know, either now or after I post v2, if you want to merge them yourself or provide your Acked-by.
Paolo
Quoted 140 lines
Quoted 138 lines
There are many small parts in this patches, but I am posting them together because each small part alone adds very little.
Patch 1 comes from mst's pull request.
Patches 2-6 are target-i386 patches. They add support for memory attributes in target-i386, enabling the "secure" attribute whenever the CPU is in system management mode. They also fix two SMM bugs found while working on KVM support.
Patches 7-9 add support for secure access to parallel flash. If enabled, parallel flash behaves as ROM unless the "secure" memory transaction attribute is set.
Patches 10-12 are general infrastructure patches that didn't fit elsewhere. Note that patch 10 introduces new command-line syntax.
Patches 13-16 rewrite the SMRAM handling in TCG mode, so that the SMRAM setup is done just once using the memory API, and then enabled/disabled by the CPU without intervention from the chipset. The resulting chipset code is simpler and...
... patches 17-23 then rely on this to implement support for more q35 SMI features, in particular high SMRAM, TSEG and
SMI_LOCK. This part was done almost entirely by Gerd.Patches 24-26 are for q35 feature parity with PIIX4. They are from Laszlo and they are included just because they conflict with the next few.
Patches 27 and 28 implement KVM support for SMM. Note that this support is not yet upstream (will be in Linux 4.2); these patches will be rebased after the updated KVM headers are taken from kvm.git.
Patches 29-31 add a "-machine smm=on|off|auto" option (QOM property) that can be used to hide SMM or make it available on any accelerator. The compat gunk makes it available by default on TCG but not on KVM.
That's it. Go ahead and review.
Paolo
Gerd Hoffmann (6):
q35: fix ESMRAMC default
q35: add config space wmask for SMRAM and ESMRAMC
q35: implement SMRAM.D_LCK
q35: add test for SMRAM.D_LCK
q35: implement TSEG
ich9: implementSMI_LOCKJason Wang (1):
pc: add 2.4 machine typesLaszlo Ersek (3):
hw/acpi:acpi_pm1_cnt_init(): take "disable_s3" and "disable_s4" hw/acpi: move "etc/system-states"fw_cfgfile from PIIX4 to core hw/acpi:piix4_pm_init(): takefw_cfgobject no morePaolo Bonzini (21):
target-i386: introducecpu_get_mem_attrs
target-i386: Use correct memory attributes for memory accesses
target-i386: Use correct memory attributes for ioport accesses
target-i386: mask NMIs on entry to SMM
target-i386: set G=1 in SMM big real mode selectors
pflash_cfi01: change big-endian property to BIT type
pflash_cfi01: change to new-style MMIO accessors
pflash_cfi01: add secure property
vl: allow full-blown QemuOpts syntax for -global
qom: addobject_property_add_const_link
vl: run "late" notifiers immediately
target-i386: create a separate AddressSpace for each CPU hw/i386: add a separate region that tracks the SMRAME bit
target-i386: use memory API to implement SMRAM hw/i386: removesmram_update
q35: implement high SMRAM
target-i386: add support for SMBASE MSR and SMIs
vga: disablechain4_aliasif KVM supports SMRAM
pc_piix: renamekvm_enabledtosmm_enabled
ich9: addsmm_enabledfield and arguments
pc: add SMM propertybsd-user/main.c | 4 - hw/acpi/core.c | 15 +- hw/acpi/ich9.c | 12 +- hw/acpi/piix4.c | 21 +-- hw/block/pflash_cfi01.c | 204 +++++++++++---------------- hw/display/vga.c | 8 +- hw/display/vga_int.h | 1 + hw/i386/pc.c | 72 +++++++--- hw/i386/pc_piix.c | 53 +++++-- hw/i386/pc_q35.c | 33 ++++- hw/isa/lpc_ich9.c | 23 ++- hw/isa/vt82c686.c | 2 +- hw/mips/mips_malta.c | 2 +- hw/pci-host/pam.c | 20 --- hw/pci-host/piix.c | 39 +++--- hw/pci-host/q35.c | 137 ++++++++++++++++-- include/exec/memattrs.h | 4 +- include/hw/acpi/acpi.h | 3 +- include/hw/acpi/ich9.h | 4 +- include/hw/i386/ich9.h | 8 +- include/hw/i386/pc.h | 7 +- include/hw/pci-host/pam.h | 4 - include/hw/pci-host/q35.h | 36 +++-- include/qom/object.h | 18 +++ include/sysemu/kvm.h | 1 + kvm-all.c | 5 + kvm-stub.c | 5 + linux-headers/asm-x86/kvm.h | 11 +- linux-headers/linux/kvm.h | 5 +- linux-user/main.c | 4 - qdev-monitor.c | 18 ++- qemu-options.hx | 7 +- qom/object.c | 16 +++ target-i386/Makefile.objs | 2 - target-i386/cpu-qom.h | 3 + target-i386/cpu.c | 43 ++++++ target-i386/cpu.h | 41 ++++-- target-i386/helper.c | 135 +++++++++++++++--- target-i386/helper.h | 12 +- target-i386/ioport-user.c | 60 -------- target-i386/kvm.c | 75 ++++++++-- target-i386/machine.c | 3 + target-i386/misc_helper.c | 59 ++++++-- target-i386/seg_helper.c | 12 +- target-i386/smm_helper.c | 331 +++++++++++++++++++++++--------------------- target-i386/svm_helper.c | 230 +++++++++++++++--------------- target-i386/translate.c | 12 +- tests/Makefile | 2 + tests/smram-test.c | 80 +++++++++++ vl.c | 6 + 50 files changed, 1220 insertions(+), 688 deletions(-) delete mode 100644 target-i386/ioport-user.c create mode 100644 tests/smram-test.cSignature · 1 line
1.8.3.1
Quoted 17 lines · Paolo Bonzini
Quoted 8 lines · Michael S. Tsirkin
Quoted 4 lines · Paolo Bonzini
These patches implement almost everything that is needed for SMM support in OVMF and KVM. The only missing bit is support for SMRAM regions in KVM, but it need not block review of these ones, and possibly inclusion of the first 26.
Overall this looks good to me.
Sent some comments, and IIUC there will v2 down the road?I would like to send a pull request for the non-KVM parts (up to patch
23) on Wednesday or Thursday. The remaining pieces have to wait for inclusion of KVM support in the kernel, and there will be a v2 with minimal changes posted during soft freeze.
Quoted 4 lines
Let me know, either now or after I post v2, if you want to merge them yourself or provide your Acked-by.
Paolo
I think the pc tree makes sense for the non kvm parts, and will help avoid merge conflicts.
If you split non-kvm bits out anyway, then I'll merge it.
Quoted 140 lines
Quoted 140 lines
Quoted 138 lines
There are many small parts in this patches, but I am posting them together because each small part alone adds very little.
Patch 1 comes from mst's pull request.
Patches 2-6 are target-i386 patches. They add support for memory attributes in target-i386, enabling the "secure" attribute whenever the CPU is in system management mode. They also fix two SMM bugs found while working on KVM support.
Patches 7-9 add support for secure access to parallel flash. If enabled, parallel flash behaves as ROM unless the "secure" memory transaction attribute is set.
Patches 10-12 are general infrastructure patches that didn't fit elsewhere. Note that patch 10 introduces new command-line syntax.
Patches 13-16 rewrite the SMRAM handling in TCG mode, so that the SMRAM setup is done just once using the memory API, and then enabled/disabled by the CPU without intervention from the chipset. The resulting chipset code is simpler and...
... patches 17-23 then rely on this to implement support for more q35 SMI features, in particular high SMRAM, TSEG and
SMI_LOCK. This part was done almost entirely by Gerd.Patches 24-26 are for q35 feature parity with PIIX4. They are from Laszlo and they are included just because they conflict with the next few.
Patches 27 and 28 implement KVM support for SMM. Note that this support is not yet upstream (will be in Linux 4.2); these patches will be rebased after the updated KVM headers are taken from kvm.git.
Patches 29-31 add a "-machine smm=on|off|auto" option (QOM property) that can be used to hide SMM or make it available on any accelerator. The compat gunk makes it available by default on TCG but not on KVM.
That's it. Go ahead and review.
Paolo
Gerd Hoffmann (6):
q35: fix ESMRAMC default
q35: add config space wmask for SMRAM and ESMRAMC
q35: implement SMRAM.D_LCK
q35: add test for SMRAM.D_LCK
q35: implement TSEG
ich9: implementSMI_LOCKJason Wang (1):
pc: add 2.4 machine typesLaszlo Ersek (3):
hw/acpi:acpi_pm1_cnt_init(): take "disable_s3" and "disable_s4" hw/acpi: move "etc/system-states"fw_cfgfile from PIIX4 to core hw/acpi:piix4_pm_init(): takefw_cfgobject no morePaolo Bonzini (21):
target-i386: introducecpu_get_mem_attrs
target-i386: Use correct memory attributes for memory accesses
target-i386: Use correct memory attributes for ioport accesses
target-i386: mask NMIs on entry to SMM
target-i386: set G=1 in SMM big real mode selectors
pflash_cfi01: change big-endian property to BIT type
pflash_cfi01: change to new-style MMIO accessors
pflash_cfi01: add secure property
vl: allow full-blown QemuOpts syntax for -global
qom: addobject_property_add_const_link
vl: run "late" notifiers immediately
target-i386: create a separate AddressSpace for each CPU hw/i386: add a separate region that tracks the SMRAME bit
target-i386: use memory API to implement SMRAM hw/i386: removesmram_update
q35: implement high SMRAM
target-i386: add support for SMBASE MSR and SMIs
vga: disablechain4_aliasif KVM supports SMRAM
pc_piix: renamekvm_enabledtosmm_enabled
ich9: addsmm_enabledfield and arguments
pc: add SMM propertybsd-user/main.c | 4 - hw/acpi/core.c | 15 +- hw/acpi/ich9.c | 12 +- hw/acpi/piix4.c | 21 +-- hw/block/pflash_cfi01.c | 204 +++++++++++---------------- hw/display/vga.c | 8 +- hw/display/vga_int.h | 1 + hw/i386/pc.c | 72 +++++++--- hw/i386/pc_piix.c | 53 +++++-- hw/i386/pc_q35.c | 33 ++++- hw/isa/lpc_ich9.c | 23 ++- hw/isa/vt82c686.c | 2 +- hw/mips/mips_malta.c | 2 +- hw/pci-host/pam.c | 20 --- hw/pci-host/piix.c | 39 +++--- hw/pci-host/q35.c | 137 ++++++++++++++++-- include/exec/memattrs.h | 4 +- include/hw/acpi/acpi.h | 3 +- include/hw/acpi/ich9.h | 4 +- include/hw/i386/ich9.h | 8 +- include/hw/i386/pc.h | 7 +- include/hw/pci-host/pam.h | 4 - include/hw/pci-host/q35.h | 36 +++-- include/qom/object.h | 18 +++ include/sysemu/kvm.h | 1 + kvm-all.c | 5 + kvm-stub.c | 5 + linux-headers/asm-x86/kvm.h | 11 +- linux-headers/linux/kvm.h | 5 +- linux-user/main.c | 4 - qdev-monitor.c | 18 ++- qemu-options.hx | 7 +- qom/object.c | 16 +++ target-i386/Makefile.objs | 2 - target-i386/cpu-qom.h | 3 + target-i386/cpu.c | 43 ++++++ target-i386/cpu.h | 41 ++++-- target-i386/helper.c | 135 +++++++++++++++--- target-i386/helper.h | 12 +- target-i386/ioport-user.c | 60 -------- target-i386/kvm.c | 75 ++++++++-- target-i386/machine.c | 3 + target-i386/misc_helper.c | 59 ++++++-- target-i386/seg_helper.c | 12 +- target-i386/smm_helper.c | 331 +++++++++++++++++++++++--------------------- target-i386/svm_helper.c | 230 +++++++++++++++--------------- target-i386/translate.c | 12 +- tests/Makefile | 2 + tests/smram-test.c | 80 +++++++++++ vl.c | 6 + 50 files changed, 1220 insertions(+), 688 deletions(-) delete mode 100644 target-i386/ioport-user.c create mode 100644 tests/smram-test.cSignature · 1 line
1.8.3.1
Quoted 11 lines · Michael S. Tsirkin
Quoted 7 lines
I would like to send a pull request for the non-KVM parts (up to patch
23) on Wednesday or Thursday. The remaining pieces have to wait for inclusion of KVM support in the kernel, and there will be a v2 with minimal changes posted during soft freeze.Let me know, either now or after I post v2, if you want to merge them yourself or provide your Acked-by.
I think the pc tree makes sense for the non kvm parts, and will help avoid merge conflicts.
If you split non-kvm bits out anyway, then I'll merge it.
Are you still okay with me sending out non-PC, non-KVM parts (up to patch 23) on my own?
Note I'd happily pass you the KVM parts of patches >=24 too. It's just a couple of commits, there is no need to split the merge.
Paolo