Re: [edk2] KVM: MTRR: fix memory type handling if MTRR is completely disabled
Janusz, Could you please try this: $ git diff diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 185fc16..bdd564f 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4957,12 +4957,14 @@ static int handle_emulation_failure(struct kvm_vcpu *vcpu) ++vcpu->stat.insn_emulation_fail; trace_kvm_emulate_insn_failed(vcpu); +#if 0 if (!is_guest_mode(vcpu) && kvm_x86_ops->get_cpl(vcpu) == 0) { vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR; vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION; vcpu->run->internal.ndata = 0; r = EMULATE_FAIL; } +#endif kvm_queue_exception(vcpu, UD_VECTOR); return r; To see if the issue still there? On 10/02/2015 10:38 PM, Janusz wrote: W dniu 01.10.2015 o 16:18, Paolo Bonzini pisze: On 01/10/2015 16:12, Janusz wrote: Now, I can also add, that the problem is only when I allow VM to use more than one core, so with option for example: -smp 8,cores=4,threads=2,sockets=1 and other combinations like -smp 4,threads=1 its not working, and without it I am always running VM without problems Any ideas what can it be? or any idea what would help to find out what is causing this? I am going to send a revert of the patch tomorrow. Paolo Thanks, but revert patch doesn't help, so something else is wrong here -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [Qemu-devel] [PATCH v3 00/32] implement vNVDIMM
On 10/13/2015 02:36 PM, Dan Williams wrote: On Mon, Oct 12, 2015 at 10:49 PM, Xiao Guangrongwrote: On 10/13/2015 11:38 AM, Dan Williams wrote: On Mon, Oct 12, 2015 at 8:14 PM, Xiao Guangrong wrote: On 10/13/2015 12:36 AM, Dan Williams wrote: Static namespaces can be emitted without a label. Linux needs this to support existing "label-less" bare metal NVDIMMs. This is Linux specific? As i did not see it has been documented in the spec... I expect most NVDIMMs, especially existing ones available today, do not have a label area. This is not Linux specific and ACPI 6 does not specify a label area, only the Intel DSM Interface Example. Yup, label data is accessed via DSM interface, the spec I mentioned is Intel DSM Interface Example. However, IIRC Linux NVDIMM driver refused to use the device if no DSM GET_LABEL support, are you going to update it? Label-less DIMMs are tested as part of the unit test [1] and the "memmap=nn!ss" kernel parameter that registers a persistent-memory address range without a DIMM. What error do you see when label support is disabled? [1]: https://github.com/pmem/ndctl/blob/master/README.md After revert my commits on NVDIMM driver, yeah, it works. Okay, i will drop the namespace part and make it as label-less instead. Thank you, Dan! -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [Qemu-devel] [PATCH v3 00/32] implement vNVDIMM
On Mon, Oct 12, 2015 at 10:49 PM, Xiao Guangrongwrote: > > > On 10/13/2015 11:38 AM, Dan Williams wrote: >> >> On Mon, Oct 12, 2015 at 8:14 PM, Xiao Guangrong >> wrote: >>> >>> On 10/13/2015 12:36 AM, Dan Williams wrote: Static namespaces can be emitted without a label. Linux needs this to support existing "label-less" bare metal NVDIMMs. >>> >>> >>> >>> This is Linux specific? As i did not see it has been documented in the >>> spec... >> >> >> I expect most NVDIMMs, especially existing ones available today, do >> not have a label area. This is not Linux specific and ACPI 6 does not >> specify a label area, only the Intel DSM Interface Example. >> > > Yup, label data is accessed via DSM interface, the spec I mentioned > is Intel DSM Interface Example. > > However, IIRC Linux NVDIMM driver refused to use the device if no > DSM GET_LABEL support, are you going to update it? Label-less DIMMs are tested as part of the unit test [1] and the "memmap=nn!ss" kernel parameter that registers a persistent-memory address range without a DIMM. What error do you see when label support is disabled? [1]: https://github.com/pmem/ndctl/blob/master/README.md -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] KVM: arm/arm64: Fix vGIC documentation
Correct some old mistakes in the API documentation: 1. VCPU is identified by index (using kvm_get_vcpu() function), but "cpu id" can be mistaken for affinity ID. 2. Some error codes are wrong. Signed-off-by: Pavel Fedin--- This is a small extraction from my vGICv3 live migration series. These changes actually bring the documentation into correspondence with the code, so they do not depend on any changes and can be applied right now (including stable kernels, if you think it's appropriate). --- Documentation/virtual/kvm/devices/arm-vgic.txt | 18 ++ 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Documentation/virtual/kvm/devices/arm-vgic.txt b/Documentation/virtual/kvm/devices/arm-vgic.txt index 3fb9054..9766b1e 100644 --- a/Documentation/virtual/kvm/devices/arm-vgic.txt +++ b/Documentation/virtual/kvm/devices/arm-vgic.txt @@ -44,28 +44,29 @@ Groups: Attributes: The attr field of kvm_device_attr encodes two values: bits: | 63 40 | 39 .. 32 | 31 0 | -values: |reserved | cpu id | offset | +values: |reserved | vcpu_index | offset | All distributor regs are (rw, 32-bit) The offset is relative to the "Distributor base address" as defined in the GICv2 specs. Getting or setting such a register has the same effect as -reading or writing the register on the actual hardware from the cpu -specified with cpu id field. Note that most distributor fields are not -banked, but return the same value regardless of the cpu id used to access -the register. +reading or writing the register on the actual hardware from the cpu whose +index is specified with vcpu_index field. Note that most distributor fields +are not banked, but return the same value regardless of the VCPU index used +to access the register. Limitations: - Priorities are not implemented, and registers are RAZ/WI - Currently only implemented for KVM_DEV_TYPE_ARM_VGIC_V2. Errors: --ENODEV: Getting or setting this register is not yet supported +-ENXIO: Getting or setting this register is not yet supported -EBUSY: One or more VCPUs are running +-EINVAL: Invalid CPU index supplied KVM_DEV_ARM_VGIC_GRP_CPU_REGS Attributes: The attr field of kvm_device_attr encodes two values: bits: | 63 40 | 39 .. 32 | 31 0 | -values: |reserved | cpu id | offset | +values: |reserved | vcpu_index | offset | All CPU interface regs are (rw, 32-bit) @@ -91,8 +92,9 @@ Groups: - Priorities are not implemented, and registers are RAZ/WI - Currently only implemented for KVM_DEV_TYPE_ARM_VGIC_V2. Errors: --ENODEV: Getting or setting this register is not yet supported +-ENXIO: Getting or setting this register is not yet supported -EBUSY: One or more VCPUs are running +-EINVAL: Invalid CPU index supplied KVM_DEV_ARM_VGIC_GRP_NR_IRQS Attributes: -- 2.4.4 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[Bug 105841] "KVM: x86: apply guest MTRR virtualization on host reserved pages" causes kernel to panic on boot
https://bugzilla.kernel.org/show_bug.cgi?id=105841 Paolo Bonzinichanged: What|Removed |Added Status|NEW |RESOLVED CC||bonz...@gnu.org Resolution|--- |CODE_FIX --- Comment #3 from Paolo Bonzini --- The three have been reverted already (and commit 549283037017, "KVM: svm: handle KVM_X86_QUIRK_CD_NW_CLEARED in svm_get_mt_mask", has been reverted as well) and the reverts are marked for stable. -- You are receiving this mail because: You are watching the assignee of the bug. -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 1/2] KVM: x86: clean up kvm_arch_vcpu_runnable
Split the huge conditional in two functions. Fixes: 64d6067057d9658acb8675afcfba549abdb7fc16 Cc: sta...@vger.kernel.org Signed-off-by: Paolo Bonzini--- arch/x86/kvm/x86.c | 39 +-- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index e1bc11d8e4bd..ad82420761dd 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6453,6 +6453,12 @@ static inline int vcpu_block(struct kvm *kvm, struct kvm_vcpu *vcpu) return 1; } +static inline bool kvm_vcpu_running(struct kvm_vcpu *vcpu) +{ + return (vcpu->arch.mp_state == KVM_MP_STATE_RUNNABLE && + !vcpu->arch.apf.halted); +} + static int vcpu_run(struct kvm_vcpu *vcpu) { int r; @@ -6461,8 +6467,7 @@ static int vcpu_run(struct kvm_vcpu *vcpu) vcpu->srcu_idx = srcu_read_lock(>srcu); for (;;) { - if (vcpu->arch.mp_state == KVM_MP_STATE_RUNNABLE && - !vcpu->arch.apf.halted) + if (kvm_vcpu_running(vcpu)) r = vcpu_enter_guest(vcpu); else r = vcpu_block(kvm, vcpu); @@ -7762,19 +7767,33 @@ void kvm_arch_flush_shadow_memslot(struct kvm *kvm, kvm_mmu_invalidate_zap_all_pages(kvm); } +static inline bool kvm_vcpu_has_events(struct kvm_vcpu *vcpu) +{ + if (!list_empty_careful(>async_pf.done)) + return true; + + if (kvm_apic_has_events(vcpu)) + return true; + + if (vcpu->arch.pv.pv_unhalted) + return true; + + if (atomic_read(>arch.nmi_queued)) + return true; + + if (kvm_arch_interrupt_allowed(vcpu) && + kvm_cpu_has_interrupt(vcpu)) + return true; + + return false; +} + int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu) { if (is_guest_mode(vcpu) && kvm_x86_ops->check_nested_events) kvm_x86_ops->check_nested_events(vcpu, false); - return (vcpu->arch.mp_state == KVM_MP_STATE_RUNNABLE && - !vcpu->arch.apf.halted) - || !list_empty_careful(>async_pf.done) - || kvm_apic_has_events(vcpu) - || vcpu->arch.pv.pv_unhalted - || atomic_read(>arch.nmi_queued) || - (kvm_arch_interrupt_allowed(vcpu) && -kvm_cpu_has_interrupt(vcpu)); + return kvm_vcpu_running(vcpu) || kvm_vcpu_has_events(vcpu); } int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu) -- 1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 0/2] KVM: x86: fix deliver of SMIs to halted VCPUs
While SeaBIOS only uses synchronous SMI delivery through port 0xb2, OVMF also uses APIC delivery, and it is buggy. This is enough to run OVMF with SMM enabled and multiple processors, up to a UEFI shell, but it literally takes minutes to get there. However, the same behavior is visible with KVM disabled, so it may be a firmware bug instead. Paolo Paolo Bonzini (2): KVM: x86: clean up kvm_arch_vcpu_runnable KVM: x86: fix SMI to halted VCPU arch/x86/kvm/x86.c | 42 -- 1 file changed, 32 insertions(+), 10 deletions(-) -- 1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 2/2] KVM: x86: fix SMI to halted VCPU
An SMI to a halted VCPU must wake it up, hence a VCPU with a pending SMI must be considered runnable. Fixes: 64d6067057d9658acb8675afcfba549abdb7fc16 Cc: sta...@vger.kernel.org Signed-off-by: Paolo Bonzini--- arch/x86/kvm/x86.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index ad82420761dd..7b481470602a 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -7781,6 +7781,9 @@ static inline bool kvm_vcpu_has_events(struct kvm_vcpu *vcpu) if (atomic_read(>arch.nmi_queued)) return true; + if (test_bit(KVM_REQ_SMI, >requests)) + return true; + if (kvm_arch_interrupt_allowed(vcpu) && kvm_cpu_has_interrupt(vcpu)) return true; -- 1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 04/32] acpi: add aml_mutex, aml_acquire, aml_release
On Sun, 11 Oct 2015 11:52:36 +0800 Xiao Guangrongwrote: > Implement Mutex, Acquire and Release terms which are used by NVDIMM _DSM > method > in later patch > > Signed-off-by: Xiao Guangrong > --- > hw/acpi/aml-build.c | 32 > include/hw/acpi/aml-build.h | 3 +++ > 2 files changed, 35 insertions(+) > > diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c > index 9fe5e7b..ab52692 100644 > --- a/hw/acpi/aml-build.c > +++ b/hw/acpi/aml-build.c > @@ -1164,6 +1164,38 @@ Aml *aml_create_field(Aml *srcbuf, Aml *index, Aml > *len, const char *name) > return var; > } > > +/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefMutex */ > +Aml *aml_mutex(const char *name, uint8_t flags) s/flags/sync_level/ > +{ > +Aml *var = aml_alloc(); > +build_append_byte(var->buf, 0x5B); /* ExtOpPrefix */ > +build_append_byte(var->buf, 0x01); /* MutexOp */ > +build_append_namestring(var->buf, "%s", name); add assert here to check that reserved bits are 0 > +build_append_byte(var->buf, flags); > +return var; > +} > + > +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefAcquire */ > +Aml *aml_acquire(Aml *mutex, uint16_t timeout) > +{ > +Aml *var = aml_alloc(); > +build_append_byte(var->buf, 0x5B); /* ExtOpPrefix */ > +build_append_byte(var->buf, 0x23); /* AcquireOp */ > +aml_append(var, mutex); > +build_append_int_noprefix(var->buf, timeout, sizeof(timeout)); > +return var; > +} > + > +/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefRelease */ > +Aml *aml_release(Aml *mutex) > +{ > +Aml *var = aml_alloc(); > +build_append_byte(var->buf, 0x5B); /* ExtOpPrefix */ > +build_append_byte(var->buf, 0x27); /* ReleaseOp */ > +aml_append(var, mutex); > +return var; > +} > + > void > build_header(GArray *linker, GArray *table_data, > AcpiTableHeader *h, const char *sig, int len, uint8_t rev) > diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h > index 7e1c43b..d494c0c 100644 > --- a/include/hw/acpi/aml-build.h > +++ b/include/hw/acpi/aml-build.h > @@ -277,6 +277,9 @@ Aml *aml_unicode(const char *str); > Aml *aml_derefof(Aml *arg); > Aml *aml_sizeof(Aml *arg); > Aml *aml_create_field(Aml *srcbuf, Aml *index, Aml *len, const char *name); > +Aml *aml_mutex(const char *name, uint8_t flags); > +Aml *aml_acquire(Aml *mutex, uint16_t timeout); > +Aml *aml_release(Aml *mutex); > > void > build_header(GArray *linker, GArray *table_data, -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[GIT PULL 03/10] KVM: s390: set interception requests for all floating irqs
From: David HildenbrandNo need to separate pending and floating irqs when setting interception requests. Let's do it for all equally. Reviewed-by: Christian Borntraeger Signed-off-by: David Hildenbrand Signed-off-by: Christian Borntraeger --- arch/s390/kvm/interrupt.c | 19 +++ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c index 1058240..4f05520 100644 --- a/arch/s390/kvm/interrupt.c +++ b/arch/s390/kvm/interrupt.c @@ -107,14 +107,10 @@ static inline u8 int_word_to_isc(u32 int_word) return (int_word & 0x3800) >> 27; } -static inline unsigned long pending_floating_irqs(struct kvm_vcpu *vcpu) +static inline unsigned long pending_irqs(struct kvm_vcpu *vcpu) { - return vcpu->kvm->arch.float_int.pending_irqs; -} - -static inline unsigned long pending_local_irqs(struct kvm_vcpu *vcpu) -{ - return vcpu->arch.local_int.pending_irqs; + return vcpu->kvm->arch.float_int.pending_irqs | + vcpu->arch.local_int.pending_irqs; } static unsigned long disable_iscs(struct kvm_vcpu *vcpu, @@ -133,8 +129,7 @@ static unsigned long deliverable_irqs(struct kvm_vcpu *vcpu) { unsigned long active_mask; - active_mask = pending_local_irqs(vcpu); - active_mask |= pending_floating_irqs(vcpu); + active_mask = pending_irqs(vcpu); if (!active_mask) return 0; @@ -202,7 +197,7 @@ static void __set_cpuflag(struct kvm_vcpu *vcpu, u32 flag) static void set_intercept_indicators_io(struct kvm_vcpu *vcpu) { - if (!(pending_floating_irqs(vcpu) & IRQ_PEND_IO_MASK)) + if (!(pending_irqs(vcpu) & IRQ_PEND_IO_MASK)) return; else if (psw_ioint_disabled(vcpu)) __set_cpuflag(vcpu, CPUSTAT_IO_INT); @@ -212,7 +207,7 @@ static void set_intercept_indicators_io(struct kvm_vcpu *vcpu) static void set_intercept_indicators_ext(struct kvm_vcpu *vcpu) { - if (!(pending_local_irqs(vcpu) & IRQ_PEND_EXT_MASK)) + if (!(pending_irqs(vcpu) & IRQ_PEND_EXT_MASK)) return; if (psw_extint_disabled(vcpu)) __set_cpuflag(vcpu, CPUSTAT_EXT_INT); @@ -222,7 +217,7 @@ static void set_intercept_indicators_ext(struct kvm_vcpu *vcpu) static void set_intercept_indicators_mchk(struct kvm_vcpu *vcpu) { - if (!(pending_local_irqs(vcpu) & IRQ_PEND_MCHK_MASK)) + if (!(pending_irqs(vcpu) & IRQ_PEND_MCHK_MASK)) return; if (psw_mchk_disabled(vcpu)) vcpu->arch.sie_block->ictl |= ICTL_LPSW; -- 2.4.3 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[GIT PULL 01/10] KVM: s390: remove unused variable in __inject_vm
the float int structure is no longer used in __inject_vm. Acked-by: Cornelia HuckSigned-off-by: Christian Borntraeger --- arch/s390/kvm/interrupt.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c index 5c2c169..ab9f525 100644 --- a/arch/s390/kvm/interrupt.c +++ b/arch/s390/kvm/interrupt.c @@ -1390,12 +1390,9 @@ static void __floating_irq_kick(struct kvm *kvm, u64 type) static int __inject_vm(struct kvm *kvm, struct kvm_s390_interrupt_info *inti) { - struct kvm_s390_float_interrupt *fi; u64 type = READ_ONCE(inti->type); int rc; - fi = >arch.float_int; - switch (type) { case KVM_S390_MCHK: rc = __inject_float_mchk(kvm, inti); -- 2.4.3 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[GIT PULL 09/10] KVM: s390: factor out and fix setting of guest TOD clock
From: David HildenbrandLet's move that whole logic into one function. We now always use unsigned values when calculating the epoch (to avoid over/underflow defined). Also, we always have to get all VCPUs out of SIE before doing the update to avoid running differing VCPUs with different TODs. Acked-by: Christian Borntraeger Signed-off-by: David Hildenbrand Signed-off-by: Christian Borntraeger --- arch/s390/kvm/kvm-s390.c | 28 +--- arch/s390/kvm/kvm-s390.h | 1 + arch/s390/kvm/priv.c | 15 +++ 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index a090779..87bd602 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -521,22 +521,12 @@ static int kvm_s390_set_tod_high(struct kvm *kvm, struct kvm_device_attr *attr) static int kvm_s390_set_tod_low(struct kvm *kvm, struct kvm_device_attr *attr) { - struct kvm_vcpu *cur_vcpu; - unsigned int vcpu_idx; u64 gtod; if (copy_from_user(, (void __user *)attr->addr, sizeof(gtod))) return -EFAULT; - mutex_lock(>lock); - preempt_disable(); - kvm->arch.epoch = gtod - get_tod_clock(); - kvm_s390_vcpu_block_all(kvm); - kvm_for_each_vcpu(vcpu_idx, cur_vcpu, kvm) - cur_vcpu->arch.sie_block->epoch = kvm->arch.epoch; - kvm_s390_vcpu_unblock_all(kvm); - preempt_enable(); - mutex_unlock(>lock); + kvm_s390_set_tod_clock(kvm, gtod); VM_EVENT(kvm, 3, "SET: TOD base: 0x%llx\n", gtod); return 0; } @@ -1906,6 +1896,22 @@ retry: return 0; } +void kvm_s390_set_tod_clock(struct kvm *kvm, u64 tod) +{ + struct kvm_vcpu *vcpu; + int i; + + mutex_lock(>lock); + preempt_disable(); + kvm->arch.epoch = tod - get_tod_clock(); + kvm_s390_vcpu_block_all(kvm); + kvm_for_each_vcpu(i, vcpu, kvm) + vcpu->arch.sie_block->epoch = kvm->arch.epoch; + kvm_s390_vcpu_unblock_all(kvm); + preempt_enable(); + mutex_unlock(>lock); +} + /** * kvm_arch_fault_in_page - fault-in guest page if necessary * @vcpu: The corresponding virtual cpu diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h index 3a368d2..cc15ea3 100644 --- a/arch/s390/kvm/kvm-s390.h +++ b/arch/s390/kvm/kvm-s390.h @@ -231,6 +231,7 @@ int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu); int kvm_s390_handle_sigp_pei(struct kvm_vcpu *vcpu); /* implemented in kvm-s390.c */ +void kvm_s390_set_tod_clock(struct kvm *kvm, u64 tod); long kvm_arch_fault_in_page(struct kvm_vcpu *vcpu, gpa_t gpa, int writable); int kvm_s390_store_status_unloaded(struct kvm_vcpu *vcpu, unsigned long addr); int kvm_s390_store_adtl_status_unloaded(struct kvm_vcpu *vcpu, diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c index b253de5..77191b8 100644 --- a/arch/s390/kvm/priv.c +++ b/arch/s390/kvm/priv.c @@ -33,11 +33,9 @@ /* Handle SCK (SET CLOCK) interception */ static int handle_set_clock(struct kvm_vcpu *vcpu) { - struct kvm_vcpu *cpup; - s64 val; - int i, rc; + int rc; ar_t ar; - u64 op2; + u64 op2, val; if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); @@ -50,14 +48,7 @@ static int handle_set_clock(struct kvm_vcpu *vcpu) return kvm_s390_inject_prog_cond(vcpu, rc); VCPU_EVENT(vcpu, 3, "SCK: setting guest TOD to 0x%llx", val); - - mutex_lock(>kvm->lock); - preempt_disable(); - val = (val - get_tod_clock()) & ~0x3fUL; - kvm_for_each_vcpu(i, cpup, vcpu->kvm) - cpup->arch.sie_block->epoch = val; - preempt_enable(); - mutex_unlock(>kvm->lock); + kvm_s390_set_tod_clock(vcpu->kvm, val); kvm_s390_set_psw_cc(vcpu, 0); return 0; -- 2.4.3 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[GIT PULL 05/10] KVM: s390: drop out early in kvm_s390_has_irq()
From: David HildenbrandLet's get rid of the local variable and exit directly if we found any pending interrupt. This is not only faster, but also better readable. Reviewed-by: Christian Borntraeger Signed-off-by: David Hildenbrand Signed-off-by: Christian Borntraeger --- arch/s390/kvm/interrupt.c | 20 +--- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c index 1260f8c..10a0e8b 100644 --- a/arch/s390/kvm/interrupt.c +++ b/arch/s390/kvm/interrupt.c @@ -808,23 +808,21 @@ int kvm_s390_ext_call_pending(struct kvm_vcpu *vcpu) int kvm_s390_vcpu_has_irq(struct kvm_vcpu *vcpu, int exclude_stop) { - int rc; + if (deliverable_irqs(vcpu)) + return 1; - rc = !!deliverable_irqs(vcpu); - - if (!rc && kvm_cpu_has_pending_timer(vcpu)) - rc = 1; + if (kvm_cpu_has_pending_timer(vcpu)) + return 1; /* external call pending and deliverable */ - if (!rc && kvm_s390_ext_call_pending(vcpu) && + if (kvm_s390_ext_call_pending(vcpu) && !psw_extint_disabled(vcpu) && (vcpu->arch.sie_block->gcr[0] & 0x2000ul)) - rc = 1; + return 1; - if (!rc && !exclude_stop && kvm_s390_is_stop_irq_pending(vcpu)) - rc = 1; - - return rc; + if (!exclude_stop && kvm_s390_is_stop_irq_pending(vcpu)) + return 1; + return 0; } int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu) -- 2.4.3 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[GIT PULL 00/10] KVM: s390: Fixes for 4.4
Paolo, The following changes since commit 9ffecb10283508260936b96022d4ee43a7798b4c: Linux 4.3-rc3 (2015-09-27 07:50:08 -0400) are available in the git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git tags/kvm-s390-next-20151013 for you to fetch changes up to 60417fcc2b0235dfe3dcd589c56dbe3ea1a64c54: KVM: s390: factor out reading of the guest TOD clock (2015-10-13 15:50:35 +0200) KVM: s390: Fixes for 4.4 A bunch of fixes and optimizations for interrupt and time handling. No fix is important enough to qualify for 4.3 or stable. Christian Borntraeger (1): KVM: s390: remove unused variable in __inject_vm David Hildenbrand (9): KVM: s390: disabled wait cares about machine checks, not PER KVM: s390: set interception requests for all floating irqs KVM: s390: kvm_arch_vcpu_runnable already cares about timer interrupts KVM: s390: drop out early in kvm_s390_has_irq() KVM: s390: simplify in-kernel program irq injection KVM: s390: correctly handle injection of pgm irqs and per events KVM: s390: switch to get_tod_clock() and fix STP sync races KVM: s390: factor out and fix setting of guest TOD clock KVM: s390: factor out reading of the guest TOD clock arch/s390/kvm/interrupt.c | 116 +- arch/s390/kvm/kvm-s390.c | 46 -- arch/s390/kvm/kvm-s390.h | 35 -- arch/s390/kvm/priv.c | 19 ++-- 4 files changed, 97 insertions(+), 119 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[GIT PULL 04/10] KVM: s390: kvm_arch_vcpu_runnable already cares about timer interrupts
From: David HildenbrandWe can remove that double check. Reviewed-by: Christian Borntraeger Signed-off-by: David Hildenbrand Signed-off-by: Christian Borntraeger --- arch/s390/kvm/interrupt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c index 4f05520..1260f8c 100644 --- a/arch/s390/kvm/interrupt.c +++ b/arch/s390/kvm/interrupt.c @@ -839,7 +839,7 @@ int kvm_s390_handle_wait(struct kvm_vcpu *vcpu) vcpu->stat.exit_wait_state++; /* fast path */ - if (kvm_cpu_has_pending_timer(vcpu) || kvm_arch_vcpu_runnable(vcpu)) + if (kvm_arch_vcpu_runnable(vcpu)) return 0; if (psw_interrupts_disabled(vcpu)) { -- 2.4.3 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[GIT PULL 10/10] KVM: s390: factor out reading of the guest TOD clock
From: David HildenbrandLet's factor this out and always use get_tod_clock_fast() when reading the guest TOD. STORE CLOCK FAST does not do serialization and, therefore, might result in some fuzziness between different processors in a way that subsequent calls on different CPUs might have time stamps that are earlier. This semantics is fine though for all KVM use cases. To make it obvious that the new function has STORE CLOCK FAST semantics we name it kvm_s390_get_tod_clock_fast. With this patch, we only have a handful of places were we have to care about STP sync (using preempt_disable() logic). Reviewed-by: Christian Borntraeger Signed-off-by: David Hildenbrand Signed-off-by: Christian Borntraeger --- arch/s390/kvm/interrupt.c | 15 +++ arch/s390/kvm/kvm-s390.c | 4 +--- arch/s390/kvm/kvm-s390.h | 10 ++ 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c index a8be542..373e323 100644 --- a/arch/s390/kvm/interrupt.c +++ b/arch/s390/kvm/interrupt.c @@ -69,13 +69,8 @@ static int ckc_interrupts_enabled(struct kvm_vcpu *vcpu) static int ckc_irq_pending(struct kvm_vcpu *vcpu) { - preempt_disable(); - if (!(vcpu->arch.sie_block->ckc < - get_tod_clock_fast() + vcpu->arch.sie_block->epoch)) { - preempt_enable(); + if (vcpu->arch.sie_block->ckc >= kvm_s390_get_tod_clock_fast(vcpu->kvm)) return 0; - } - preempt_enable(); return ckc_interrupts_enabled(vcpu); } @@ -851,9 +846,7 @@ int kvm_s390_handle_wait(struct kvm_vcpu *vcpu) goto no_timer; } - preempt_disable(); - now = get_tod_clock_fast() + vcpu->arch.sie_block->epoch; - preempt_enable(); + now = kvm_s390_get_tod_clock_fast(vcpu->kvm); sltime = tod_to_ns(vcpu->arch.sie_block->ckc - now); /* underflow */ @@ -892,9 +885,7 @@ enum hrtimer_restart kvm_s390_idle_wakeup(struct hrtimer *timer) u64 now, sltime; vcpu = container_of(timer, struct kvm_vcpu, arch.ckc_timer); - preempt_disable(); - now = get_tod_clock_fast() + vcpu->arch.sie_block->epoch; - preempt_enable(); + now = kvm_s390_get_tod_clock_fast(vcpu->kvm); sltime = tod_to_ns(vcpu->arch.sie_block->ckc - now); /* diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index 87bd602..618c854 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -568,9 +568,7 @@ static int kvm_s390_get_tod_low(struct kvm *kvm, struct kvm_device_attr *attr) { u64 gtod; - preempt_disable(); - gtod = get_tod_clock() + kvm->arch.epoch; - preempt_enable(); + gtod = kvm_s390_get_tod_clock_fast(kvm); if (copy_to_user((void __user *)attr->addr, , sizeof(gtod))) return -EFAULT; VM_EVENT(kvm, 3, "QUERY: TOD base: 0x%llx\n", gtod); diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h index cc15ea3..1e70e00 100644 --- a/arch/s390/kvm/kvm-s390.h +++ b/arch/s390/kvm/kvm-s390.h @@ -271,6 +271,16 @@ static inline void kvm_s390_vcpu_unblock_all(struct kvm *kvm) kvm_s390_vcpu_unblock(vcpu); } +static inline u64 kvm_s390_get_tod_clock_fast(struct kvm *kvm) +{ + u64 rc; + + preempt_disable(); + rc = get_tod_clock_fast() + kvm->arch.epoch; + preempt_enable(); + return rc; +} + /** * kvm_s390_inject_prog_cond - conditionally inject a program check * @vcpu: virtual cpu -- 2.4.3 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[GIT PULL 02/10] KVM: s390: disabled wait cares about machine checks, not PER
From: David HildenbrandWe don't care about program event recording irqs (synchronous program irqs) but asynchronous irqs when checking for disabled wait. Machine checks were missing. Let's directly switch to the functions we have for that purpose instead of testing once again for magic bits. Reviewed-by: Christian Borntraeger Signed-off-by: David Hildenbrand Signed-off-by: Christian Borntraeger --- arch/s390/kvm/interrupt.c | 8 +++- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c index ab9f525..1058240 100644 --- a/arch/s390/kvm/interrupt.c +++ b/arch/s390/kvm/interrupt.c @@ -51,11 +51,9 @@ static int psw_mchk_disabled(struct kvm_vcpu *vcpu) static int psw_interrupts_disabled(struct kvm_vcpu *vcpu) { - if ((vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PER) || - (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_IO) || - (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_EXT)) - return 0; - return 1; + return psw_extint_disabled(vcpu) && + psw_ioint_disabled(vcpu) && + psw_mchk_disabled(vcpu); } static int ckc_interrupts_enabled(struct kvm_vcpu *vcpu) -- 2.4.3 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[GIT PULL 08/10] KVM: s390: switch to get_tod_clock() and fix STP sync races
From: David HildenbrandNobody except early.c makes use of store_tod_clock() to handle the cc. So if we would get a cc != 0, we would be in more trouble. Let's replace all users with get_tod_clock(). Returning a cc on an ioctl sounded strange either way. We can now also easily move the get_tod_clock() call into the preempt_disable() section. This is in fact necessary to make the STP sync work as expected. Otherwise the host TOD could change and we would end up with a wrong epoch calculation. Reviewed-by: Christian Borntraeger Signed-off-by: David Hildenbrand Signed-off-by: Christian Borntraeger --- arch/s390/kvm/kvm-s390.c | 18 -- arch/s390/kvm/priv.c | 8 ++-- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index 0a67c40..a090779 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -523,19 +523,14 @@ static int kvm_s390_set_tod_low(struct kvm *kvm, struct kvm_device_attr *attr) { struct kvm_vcpu *cur_vcpu; unsigned int vcpu_idx; - u64 host_tod, gtod; - int r; + u64 gtod; if (copy_from_user(, (void __user *)attr->addr, sizeof(gtod))) return -EFAULT; - r = store_tod_clock(_tod); - if (r) - return r; - mutex_lock(>lock); preempt_disable(); - kvm->arch.epoch = gtod - host_tod; + kvm->arch.epoch = gtod - get_tod_clock(); kvm_s390_vcpu_block_all(kvm); kvm_for_each_vcpu(vcpu_idx, cur_vcpu, kvm) cur_vcpu->arch.sie_block->epoch = kvm->arch.epoch; @@ -581,15 +576,10 @@ static int kvm_s390_get_tod_high(struct kvm *kvm, struct kvm_device_attr *attr) static int kvm_s390_get_tod_low(struct kvm *kvm, struct kvm_device_attr *attr) { - u64 host_tod, gtod; - int r; - - r = store_tod_clock(_tod); - if (r) - return r; + u64 gtod; preempt_disable(); - gtod = host_tod + kvm->arch.epoch; + gtod = get_tod_clock() + kvm->arch.epoch; preempt_enable(); if (copy_to_user((void __user *)attr->addr, , sizeof(gtod))) return -EFAULT; diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c index 4d21dc4..b253de5 100644 --- a/arch/s390/kvm/priv.c +++ b/arch/s390/kvm/priv.c @@ -34,7 +34,7 @@ static int handle_set_clock(struct kvm_vcpu *vcpu) { struct kvm_vcpu *cpup; - s64 hostclk, val; + s64 val; int i, rc; ar_t ar; u64 op2; @@ -49,15 +49,11 @@ static int handle_set_clock(struct kvm_vcpu *vcpu) if (rc) return kvm_s390_inject_prog_cond(vcpu, rc); - if (store_tod_clock()) { - kvm_s390_set_psw_cc(vcpu, 3); - return 0; - } VCPU_EVENT(vcpu, 3, "SCK: setting guest TOD to 0x%llx", val); - val = (val - hostclk) & ~0x3fUL; mutex_lock(>kvm->lock); preempt_disable(); + val = (val - get_tod_clock()) & ~0x3fUL; kvm_for_each_vcpu(i, cpup, vcpu->kvm) cpup->arch.sie_block->epoch = val; preempt_enable(); -- 2.4.3 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[GIT PULL 07/10] KVM: s390: correctly handle injection of pgm irqs and per events
From: David HildenbrandPER events can always co-exist with other program interrupts. For now, we always overwrite all program interrupt parameters when injecting any type of program interrupt. Let's handle that correctly by only overwriting the relevant portion of the program interrupt parameters. Therefore we can now inject PER events and ordinary program interrupts concurrently, resulting in no loss of program interrupts. This will especially by helpful when manually detecting PER events later - as both types might be triggered during one SIE exit. Reviewed-by: Christian Borntraeger Signed-off-by: David Hildenbrand Signed-off-by: Christian Borntraeger --- arch/s390/kvm/interrupt.c | 21 - 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c index f603bac..a8be542 100644 --- a/arch/s390/kvm/interrupt.c +++ b/arch/s390/kvm/interrupt.c @@ -972,7 +972,26 @@ static int __inject_prog(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_PROGRAM_INT, irq->u.pgm.code, 0); - li->irq.pgm = irq->u.pgm; + if (irq->u.pgm.code == PGM_PER) { + li->irq.pgm.code |= PGM_PER; + /* only modify PER related information */ + li->irq.pgm.per_address = irq->u.pgm.per_address; + li->irq.pgm.per_code = irq->u.pgm.per_code; + li->irq.pgm.per_atmid = irq->u.pgm.per_atmid; + li->irq.pgm.per_access_id = irq->u.pgm.per_access_id; + } else if (!(irq->u.pgm.code & PGM_PER)) { + li->irq.pgm.code = (li->irq.pgm.code & PGM_PER) | + irq->u.pgm.code; + /* only modify non-PER information */ + li->irq.pgm.trans_exc_code = irq->u.pgm.trans_exc_code; + li->irq.pgm.mon_code = irq->u.pgm.mon_code; + li->irq.pgm.data_exc_code = irq->u.pgm.data_exc_code; + li->irq.pgm.mon_class_nr = irq->u.pgm.mon_class_nr; + li->irq.pgm.exc_access_id = irq->u.pgm.exc_access_id; + li->irq.pgm.op_access_id = irq->u.pgm.op_access_id; + } else { + li->irq.pgm = irq->u.pgm; + } set_bit(IRQ_PEND_PROG, >pending_irqs); return 0; } -- 2.4.3 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[GIT PULL 06/10] KVM: s390: simplify in-kernel program irq injection
From: David HildenbrandThe main reason to keep program injection in kernel separated until now was that we were able to do some checking, if really only the owning thread injects program interrupts (via waitqueue_active(li->wq)). This BUG_ON was never triggered and the chances of really hitting it, if another thread injected a program irq to another vcpu, were very small. Let's drop this check and turn kvm_s390_inject_program_int() and kvm_s390_inject_prog_irq() into simple inline functions that makes use of kvm_s390_inject_vcpu(). __must_check can be dropped as they are implicitely given by kvm_s390_inject_vcpu(), to avoid ugly long function prototypes. Reviewed-by: Jens Freimann Acked-by: Cornelia Huck Reviewed-by: Christian Borntraeger Signed-off-by: David Hildenbrand Signed-off-by: Christian Borntraeger --- arch/s390/kvm/interrupt.c | 28 arch/s390/kvm/kvm-s390.h | 24 2 files changed, 20 insertions(+), 32 deletions(-) diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c index 10a0e8b..f603bac 100644 --- a/arch/s390/kvm/interrupt.c +++ b/arch/s390/kvm/interrupt.c @@ -977,34 +977,6 @@ static int __inject_prog(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) return 0; } -int kvm_s390_inject_program_int(struct kvm_vcpu *vcpu, u16 code) -{ - struct kvm_s390_local_interrupt *li = >arch.local_int; - struct kvm_s390_irq irq; - - spin_lock(>lock); - irq.u.pgm.code = code; - __inject_prog(vcpu, ); - BUG_ON(waitqueue_active(li->wq)); - spin_unlock(>lock); - return 0; -} - -int kvm_s390_inject_prog_irq(struct kvm_vcpu *vcpu, -struct kvm_s390_pgm_info *pgm_info) -{ - struct kvm_s390_local_interrupt *li = >arch.local_int; - struct kvm_s390_irq irq; - int rc; - - spin_lock(>lock); - irq.u.pgm = *pgm_info; - rc = __inject_prog(vcpu, ); - BUG_ON(waitqueue_active(li->wq)); - spin_unlock(>lock); - return rc; -} - static int __inject_pfault_init(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) { struct kvm_s390_local_interrupt *li = >arch.local_int; diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h index c446aab..3a368d2 100644 --- a/arch/s390/kvm/kvm-s390.h +++ b/arch/s390/kvm/kvm-s390.h @@ -175,6 +175,7 @@ static inline int kvm_s390_user_cpu_state_ctrl(struct kvm *kvm) return kvm->arch.user_cpu_state_ctrl != 0; } +/* implemented in interrupt.c */ int kvm_s390_handle_wait(struct kvm_vcpu *vcpu); void kvm_s390_vcpu_wakeup(struct kvm_vcpu *vcpu); enum hrtimer_restart kvm_s390_idle_wakeup(struct hrtimer *timer); @@ -185,7 +186,25 @@ int __must_check kvm_s390_inject_vm(struct kvm *kvm, struct kvm_s390_interrupt *s390int); int __must_check kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq); -int __must_check kvm_s390_inject_program_int(struct kvm_vcpu *vcpu, u16 code); +static inline int kvm_s390_inject_prog_irq(struct kvm_vcpu *vcpu, + struct kvm_s390_pgm_info *pgm_info) +{ + struct kvm_s390_irq irq = { + .type = KVM_S390_PROGRAM_INT, + .u.pgm = *pgm_info, + }; + + return kvm_s390_inject_vcpu(vcpu, ); +} +static inline int kvm_s390_inject_program_int(struct kvm_vcpu *vcpu, u16 code) +{ + struct kvm_s390_irq irq = { + .type = KVM_S390_PROGRAM_INT, + .u.pgm.code = code, + }; + + return kvm_s390_inject_vcpu(vcpu, ); +} struct kvm_s390_interrupt_info *kvm_s390_get_io_int(struct kvm *kvm, u64 isc_mask, u32 schid); int kvm_s390_reinject_io_int(struct kvm *kvm, @@ -231,9 +250,6 @@ extern unsigned long kvm_s390_fac_list_mask[]; /* implemented in diag.c */ int kvm_s390_handle_diag(struct kvm_vcpu *vcpu); -/* implemented in interrupt.c */ -int kvm_s390_inject_prog_irq(struct kvm_vcpu *vcpu, -struct kvm_s390_pgm_info *pgm_info); static inline void kvm_s390_vcpu_block_all(struct kvm *kvm) { -- 2.4.3 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 02/32] acpi: add aml_sizeof
On Sun, 11 Oct 2015 11:52:34 +0800 Xiao Guangrongwrote: > Implement SizeOf term which is used by NVDIMM _DSM method in later patch > > Signed-off-by: Xiao Guangrong Reviewed-by: Igor Mammedov > --- > hw/acpi/aml-build.c | 8 > include/hw/acpi/aml-build.h | 1 + > 2 files changed, 9 insertions(+) > > diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c > index cbd53f4..a72214d 100644 > --- a/hw/acpi/aml-build.c > +++ b/hw/acpi/aml-build.c > @@ -1143,6 +1143,14 @@ Aml *aml_derefof(Aml *arg) > return var; > } > > +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefSizeOf */ > +Aml *aml_sizeof(Aml *arg) > +{ > +Aml *var = aml_opcode(0x87 /* SizeOfOp */); > +aml_append(var, arg); > +return var; > +} > + > void > build_header(GArray *linker, GArray *table_data, > AcpiTableHeader *h, const char *sig, int len, uint8_t rev) > diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h > index 5a03d33..7296efb 100644 > --- a/include/hw/acpi/aml-build.h > +++ b/include/hw/acpi/aml-build.h > @@ -275,6 +275,7 @@ Aml *aml_varpackage(uint32_t num_elements); > Aml *aml_touuid(const char *uuid); > Aml *aml_unicode(const char *str); > Aml *aml_derefof(Aml *arg); > +Aml *aml_sizeof(Aml *arg); > > void > build_header(GArray *linker, GArray *table_data, -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 0/2] KVM: x86: fix deliver of SMIs to halted VCPUs
On 13/10/2015 12:34, Paolo Bonzini wrote: > While SeaBIOS only uses synchronous SMI delivery through port 0xb2, > OVMF also uses APIC delivery, and it is buggy. > > This is enough to run OVMF with SMM enabled and multiple processors, > up to a UEFI shell, but it literally takes minutes to get there. > However, the same behavior is visible with KVM disabled, so it may > be a firmware bug instead. Which it was. :) http://permalink.gmane.org/gmane.comp.bios.edk2.devel/2899 Paolo -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [Qemu-devel] [PATCH v3 11/32] hostmem-file: use whole file size if possible
On 11.10.2015 06:52, Xiao Guangrong wrote: Use the whole file size if @size is not specified which is useful if we want to directly pass a file to guest Signed-off-by: Xiao Guangrong--- backends/hostmem-file.c | 47 +++ 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c index 9097a57..adf2835 100644 --- a/backends/hostmem-file.c +++ b/backends/hostmem-file.c @@ -9,6 +9,9 @@ * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory. */ +#include +#include + #include "qemu-common.h" #include "sysemu/hostmem.h" #include "sysemu/sysemu.h" @@ -33,20 +36,56 @@ struct HostMemoryBackendFile { char *mem_path; }; +static uint64_t get_file_size(const char *file) +{ +struct stat stat_buf; +uint64_t size = 0; +int fd; + +fd = open(file, O_RDONLY); +if (fd < 0) { +return 0; +} + +if (stat(file, _buf) < 0) { +goto exit; +} + +if ((S_ISBLK(stat_buf.st_mode)) && !ioctl(fd, BLKGETSIZE64, )) { +goto exit; +} + +size = lseek(fd, 0, SEEK_END); +if (size == -1) { +size = 0; +} +exit: +close(fd); +return size; +} + static void file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) { HostMemoryBackendFile *fb = MEMORY_BACKEND_FILE(backend); -if (!backend->size) { -error_setg(errp, "can't create backend with size 0"); -return; -} if (!fb->mem_path) { error_setg(errp, "mem-path property not set"); return; } +if (!backend->size) { +/* + * use the whole file size if @size is not specified. + */ +backend->size = get_file_size(fb->mem_path); +} + +if (!backend->size) { +error_setg(errp, "can't create backend with size 0"); +return; +} in case of any error in get_file_size (open, stat, lseek) it will write about "backend with size 0" which may be not appropriate.. + backend->force_prealloc = mem_prealloc; memory_region_init_ram_from_file(>mr, OBJECT(backend), object_get_canonical_path(OBJECT(backend)), -- Best regards, Vladimir * now, @virtuozzo.com instead of @parallels.com. Sorry for this inconvenience. -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 03/32] acpi: add aml_create_field
On Sun, 11 Oct 2015 11:52:35 +0800 Xiao Guangrongwrote: > Implement CreateField term which is used by NVDIMM _DSM method in later patch > > Signed-off-by: Xiao Guangrong > --- > hw/acpi/aml-build.c | 13 + > include/hw/acpi/aml-build.h | 1 + > 2 files changed, 14 insertions(+) > > diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c > index a72214d..9fe5e7b 100644 > --- a/hw/acpi/aml-build.c > +++ b/hw/acpi/aml-build.c > @@ -1151,6 +1151,19 @@ Aml *aml_sizeof(Aml *arg) > return var; > } > > +/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefCreateField */ > +Aml *aml_create_field(Aml *srcbuf, Aml *index, Aml *len, const char *name) you haven't addressed v2 comment wrt index, len https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg00435.html > +{ > +Aml *var = aml_alloc(); > +build_append_byte(var->buf, 0x5B); /* ExtOpPrefix */ > +build_append_byte(var->buf, 0x13); /* CreateFieldOp */ > +aml_append(var, srcbuf); > +aml_append(var, index); > +aml_append(var, len); > +build_append_namestring(var->buf, "%s", name); > +return var; > +} > + > void > build_header(GArray *linker, GArray *table_data, > AcpiTableHeader *h, const char *sig, int len, uint8_t rev) > diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h > index 7296efb..7e1c43b 100644 > --- a/include/hw/acpi/aml-build.h > +++ b/include/hw/acpi/aml-build.h > @@ -276,6 +276,7 @@ Aml *aml_touuid(const char *uuid); > Aml *aml_unicode(const char *str); > Aml *aml_derefof(Aml *arg); > Aml *aml_sizeof(Aml *arg); > +Aml *aml_create_field(Aml *srcbuf, Aml *index, Aml *len, const char *name); > > void > build_header(GArray *linker, GArray *table_data, -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 01/32] acpi: add aml_derefof
On Sun, 11 Oct 2015 11:52:33 +0800 Xiao Guangrongwrote: > Implement DeRefOf term which is used by NVDIMM _DSM method in later patch > > Signed-off-by: Xiao Guangrong Reviewed-by: Igor Mammedov > --- > hw/acpi/aml-build.c | 8 > include/hw/acpi/aml-build.h | 1 + > 2 files changed, 9 insertions(+) > > diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c > index 0d4b324..cbd53f4 100644 > --- a/hw/acpi/aml-build.c > +++ b/hw/acpi/aml-build.c > @@ -1135,6 +1135,14 @@ Aml *aml_unicode(const char *str) > return var; > } > > +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefDerefOf */ > +Aml *aml_derefof(Aml *arg) > +{ > +Aml *var = aml_opcode(0x83 /* DerefOfOp */); > +aml_append(var, arg); > +return var; > +} > + > void > build_header(GArray *linker, GArray *table_data, > AcpiTableHeader *h, const char *sig, int len, uint8_t rev) > diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h > index 1b632dc..5a03d33 100644 > --- a/include/hw/acpi/aml-build.h > +++ b/include/hw/acpi/aml-build.h > @@ -274,6 +274,7 @@ Aml *aml_create_dword_field(Aml *srcbuf, Aml *index, > const char *name); > Aml *aml_varpackage(uint32_t num_elements); > Aml *aml_touuid(const char *uuid); > Aml *aml_unicode(const char *str); > +Aml *aml_derefof(Aml *arg); > > void > build_header(GArray *linker, GArray *table_data, -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 5/5] KVM: nVMX: expose VPID capability to L1
On 08/10/2015 07:57, Wanpeng Li wrote: > Expose VPID capability to L1. For nested guests, we don't do anything > specific for single context invalidation. Hence, only advertise support > for global context invalidation. The major benefit of nested VPID comes > from having separate vpids when switching between L1 and L2, and also > when L2's vCPUs not sched in/out on L1. > > Reviewed-by: Wincy Van> Signed-off-by: Wanpeng Li > --- > arch/x86/kvm/vmx.c | 36 > 1 file changed, 24 insertions(+), 12 deletions(-) > > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index 31d272e..22b4dc7 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -442,7 +442,7 @@ struct nested_vmx { > u32 nested_vmx_true_entry_ctls_low; > u32 nested_vmx_misc_low; > u32 nested_vmx_misc_high; > - u32 nested_vmx_ept_caps; > + u64 nested_vmx_ept_vpid_caps; Considering that all VMX_VPID_ constants are off by 32, perhaps it's simpler to have separate variables for nested_vmx_ept_caps and nested_vmx_vpid_caps, and only rejoin them when reading the MSR. It will make this patch smaller too. You can add the new field to struct nested_vmx in patch 3 (leaving it initialized to 0, of course). Paolo > }; > > #define POSTED_INTR_ON 0 > @@ -2489,18 +2489,22 @@ static void nested_vmx_setup_ctls_msrs(struct > vcpu_vmx *vmx) > /* nested EPT: emulate EPT also to L1 */ > vmx->nested.nested_vmx_secondary_ctls_high |= > SECONDARY_EXEC_ENABLE_EPT; > - vmx->nested.nested_vmx_ept_caps = VMX_EPT_PAGE_WALK_4_BIT | > + vmx->nested.nested_vmx_ept_vpid_caps = VMX_EPT_PAGE_WALK_4_BIT | >VMX_EPTP_WB_BIT | VMX_EPT_2MB_PAGE_BIT | >VMX_EPT_INVEPT_BIT; > - vmx->nested.nested_vmx_ept_caps &= vmx_capability.ept; > + vmx->nested.nested_vmx_ept_vpid_caps &= vmx_capability.ept; > /* >* For nested guests, we don't do anything specific >* for single context invalidation. Hence, only advertise >* support for global context invalidation. >*/ > - vmx->nested.nested_vmx_ept_caps |= VMX_EPT_EXTENT_GLOBAL_BIT; > + vmx->nested.nested_vmx_ept_vpid_caps |= > VMX_EPT_EXTENT_GLOBAL_BIT; > } else > - vmx->nested.nested_vmx_ept_caps = 0; > + vmx->nested.nested_vmx_ept_vpid_caps = 0; > + > + if (enable_vpid) > + vmx->nested.nested_vmx_ept_vpid_caps |= (VMX_VPID_INVVPID_BIT | > + VMX_VPID_EXTENT_GLOBAL_CONTEXT_BIT) << 32; > > if (enable_unrestricted_guest) > vmx->nested.nested_vmx_secondary_ctls_high |= > @@ -2616,8 +2620,7 @@ static int vmx_get_vmx_msr(struct kvm_vcpu *vcpu, u32 > msr_index, u64 *pdata) > vmx->nested.nested_vmx_secondary_ctls_high); > break; > case MSR_IA32_VMX_EPT_VPID_CAP: > - /* Currently, no nested vpid support */ > - *pdata = vmx->nested.nested_vmx_ept_caps; > + *pdata = vmx->nested.nested_vmx_ept_vpid_caps; > break; > default: > return 1; > @@ -7152,7 +7155,7 @@ static int handle_invept(struct kvm_vcpu *vcpu) > > if (!(vmx->nested.nested_vmx_secondary_ctls_high & > SECONDARY_EXEC_ENABLE_EPT) || > - !(vmx->nested.nested_vmx_ept_caps & VMX_EPT_INVEPT_BIT)) { > + !(vmx->nested.nested_vmx_ept_vpid_caps & VMX_EPT_INVEPT_BIT)) { > kvm_queue_exception(vcpu, UD_VECTOR); > return 1; > } > @@ -7168,7 +7171,7 @@ static int handle_invept(struct kvm_vcpu *vcpu) > vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO); > type = kvm_register_readl(vcpu, (vmx_instruction_info >> 28) & 0xf); > > - types = (vmx->nested.nested_vmx_ept_caps >> VMX_EPT_EXTENT_SHIFT) & 6; > + types = (vmx->nested.nested_vmx_ept_vpid_caps >> VMX_EPT_EXTENT_SHIFT) > & 6; > > if (!(types & (1UL << type))) { > nested_vmx_failValid(vcpu, > @@ -7207,14 +7210,15 @@ static int handle_invept(struct kvm_vcpu *vcpu) > static int handle_invvpid(struct kvm_vcpu *vcpu) > { > struct vcpu_vmx *vmx = to_vmx(vcpu); > - u32 vmx_instruction_info; > + u32 vmx_instruction_info, types; > unsigned long type; > gva_t gva; > struct x86_exception e; > int vpid; > > if (!(vmx->nested.nested_vmx_secondary_ctls_high & > - SECONDARY_EXEC_ENABLE_VPID)) { > + SECONDARY_EXEC_ENABLE_VPID) || > + !(vmx->nested.nested_vmx_ept_vpid_caps & (VMX_VPID_INVVPID_BIT > << 32))) { > kvm_queue_exception(vcpu, UD_VECTOR); > return 1; > } > @@ -7225,6 +7229,14 @@ static int handle_invvpid(struct kvm_vcpu *vcpu) >
Re: [Qemu-devel] [PATCH v3 25/32] nvdimm: build ACPI nvdimm devices
On Sun, 11 Oct 2015 11:52:57 +0800 Xiao Guangrongwrote: > NVDIMM devices is defined in ACPI 6.0 9.20 NVDIMM Devices > > There is a root device under \_SB and specified NVDIMM devices are under the > root device. Each NVDIMM device has _ADR which returns its handle used to > associate MEMDEV structure in NFIT > > We reserve handle 0 for root device. In this patch, we save handle, arg0, > arg1 and arg2. Arg3 is conditionally saved in later patch > > Signed-off-by: Xiao Guangrong > --- > hw/mem/nvdimm/acpi.c | 203 > +++ > 1 file changed, 203 insertions(+) > > diff --git a/hw/mem/nvdimm/acpi.c b/hw/mem/nvdimm/acpi.c I'd suggest to put ACPI parts to hw/acpi/nvdimm.c file so that ACPI maintainers won't miss changes to this files. > index 1450a6a..d9fa0fd 100644 > --- a/hw/mem/nvdimm/acpi.c > +++ b/hw/mem/nvdimm/acpi.c > @@ -308,15 +308,38 @@ static void build_nfit(void *fit, GSList *device_list, > GArray *table_offsets, > "NFIT", table_data->len - nfit_start, 1); > } > > +#define NOTIFY_VALUE 0x99 > + > +struct dsm_in { > +uint32_t handle; > +uint8_t arg0[16]; > +uint32_t arg1; > +uint32_t arg2; > + /* the remaining size in the page is used by arg3. */ > +uint8_t arg3[0]; > +} QEMU_PACKED; > +typedef struct dsm_in dsm_in; > + > +struct dsm_out { > +/* the size of buffer filled by QEMU. */ > +uint16_t len; > +uint8_t data[0]; > +} QEMU_PACKED; > +typedef struct dsm_out dsm_out; > + > static uint64_t dsm_read(void *opaque, hwaddr addr, > unsigned size) > { > +fprintf(stderr, "BUG: we never read DSM notification MMIO.\n"); > return 0; > } > > static void dsm_write(void *opaque, hwaddr addr, >uint64_t val, unsigned size) > { > +if (val != NOTIFY_VALUE) { > +fprintf(stderr, "BUG: unexepected notify value 0x%" PRIx64, val); > +} > } > > static const MemoryRegionOps dsm_ops = { > @@ -372,6 +395,183 @@ static MemoryRegion *build_dsm_memory(NVDIMMState > *state) > return dsm_fit_mr; > } > > +#define BUILD_STA_METHOD(_dev_, _method_) \ > +do { \ > +_method_ = aml_method("_STA", 0); \ > +aml_append(_method_, aml_return(aml_int(0x0f))); \ > +aml_append(_dev_, _method_); \ > +} while (0) > + > +#define SAVE_ARG012_HANDLE_LOCK(_method_, _handle_)\ > +do { \ > +aml_append(_method_, aml_acquire(aml_name("NLCK"), 0x)); \ how about making method serialized, then you could drop explicit lock/unlock logic for that you'd need to extend existing aml_method() to something like this: aml_method("FOO", 3/*count*/, AML_SERIALIZED, 0 /* sync_level */) > +aml_append(_method_, aml_store(_handle_, aml_name("HDLE"))); \ > +aml_append(_method_, aml_store(aml_arg(0), aml_name("ARG0"))); \ Could you describe QEMU<->ASL interface in a separate spec file (for example like: docs/specs/acpi_mem_hotplug.txt), it will help to with review process as there will be something to compare patches with. Once that is finalized/agreed upon, it should be easy to review and probably to write corresponding patches. Also I'd try to minimize QEMU<->ASL interface and implement as much as possible of ASL logic in AML instead of pushing it in hardware (QEMU). For example there isn't really any need to tell QEMU ARG0 (UUID), _DSM method could just compare UUIDs itself and execute a corresponding branch. Probably something else could be optimized as well but that we can find out during discussion over QEMU<->ASL interface spec. > +aml_append(_method_, aml_store(aml_arg(1), aml_name("ARG1"))); \ > +aml_append(_method_, aml_store(aml_arg(2), aml_name("ARG2"))); \ > +} while (0) > + > +#define NOTIFY_AND_RETURN_UNLOCK(_method_) \ > +do { \ > +aml_append(_method_, aml_store(aml_int(NOTIFY_VALUE), \ > + aml_name("NOTI"))); \ > +aml_append(_method_, aml_store(aml_name("RLEN"), aml_local(6))); \ > +aml_append(_method_, aml_store(aml_shiftleft(aml_local(6), \ > + aml_int(3)), aml_local(6))); \ > +aml_append(_method_, aml_create_field(aml_name("ODAT"), aml_int(0),\ > + aml_local(6) , "OBUF")); \ > +aml_append(_method_, aml_name_decl("ZBUF", aml_buffer(0, NULL))); \ > +aml_append(_method_,
Re: [GIT PULL 00/10] KVM: s390: Fixes for 4.4
On 13/10/2015 16:05, Christian Borntraeger wrote: > Paolo, > > The following changes since commit 9ffecb10283508260936b96022d4ee43a7798b4c: > > Linux 4.3-rc3 (2015-09-27 07:50:08 -0400) > > are available in the git repository at: > > git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git > tags/kvm-s390-next-20151013 > > for you to fetch changes up to 60417fcc2b0235dfe3dcd589c56dbe3ea1a64c54: > > KVM: s390: factor out reading of the guest TOD clock (2015-10-13 15:50:35 > +0200) > > > KVM: s390: Fixes for 4.4 > > A bunch of fixes and optimizations for interrupt and time > handling. No fix is important enough to qualify for 4.3 or > stable. > > > Christian Borntraeger (1): > KVM: s390: remove unused variable in __inject_vm > > David Hildenbrand (9): > KVM: s390: disabled wait cares about machine checks, not PER > KVM: s390: set interception requests for all floating irqs > KVM: s390: kvm_arch_vcpu_runnable already cares about timer interrupts > KVM: s390: drop out early in kvm_s390_has_irq() > KVM: s390: simplify in-kernel program irq injection > KVM: s390: correctly handle injection of pgm irqs and per events > KVM: s390: switch to get_tod_clock() and fix STP sync races > KVM: s390: factor out and fix setting of guest TOD clock > KVM: s390: factor out reading of the guest TOD clock > > arch/s390/kvm/interrupt.c | 116 > +- > arch/s390/kvm/kvm-s390.c | 46 -- > arch/s390/kvm/kvm-s390.h | 35 -- > arch/s390/kvm/priv.c | 19 ++-- > 4 files changed, 97 insertions(+), 119 deletions(-) > Pulled, thanks. Paolo -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 3/5] KVM: nVMX: emulate the INVVPID instruction
On 08/10/2015 07:57, Wanpeng Li wrote: > Add the INVVPID instruction emulation. > > Reviewed-by: Wincy Van> Signed-off-by: Wanpeng Li > --- > arch/x86/include/asm/vmx.h | 3 +++ > arch/x86/kvm/vmx.c | 49 > +- > 2 files changed, 51 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h > index 448b7ca..af5fdaf 100644 > --- a/arch/x86/include/asm/vmx.h > +++ b/arch/x86/include/asm/vmx.h > @@ -397,8 +397,10 @@ enum vmcs_field { > #define IDENTITY_PAGETABLE_PRIVATE_MEMSLOT (KVM_USER_MEM_SLOTS + 2) > > #define VMX_NR_VPIDS (1 << 16) > +#define VMX_VPID_EXTENT_INDIVIDUAL_ADDR 0 > #define VMX_VPID_EXTENT_SINGLE_CONTEXT 1 > #define VMX_VPID_EXTENT_ALL_CONTEXT 2 > +#define VMX_VPID_EXTENT_SHIFT40 This is not used. Comparing handle_invept with handle_invvpid, some differences are apparent: > static int handle_invvpid(struct kvm_vcpu *vcpu) > { > - kvm_queue_exception(vcpu, UD_VECTOR); > + struct vcpu_vmx *vmx = to_vmx(vcpu); > + u32 vmx_instruction_info; > + unsigned long type; > + gva_t gva; > + struct x86_exception e; > + int vpid; > + > + if (!(vmx->nested.nested_vmx_secondary_ctls_high & > + SECONDARY_EXEC_ENABLE_VPID)) { This lacks a check against VMX_VPID_INVVPID_BIT. > + kvm_queue_exception(vcpu, UD_VECTOR); > + return 1; > + } > + > + if (!nested_vmx_check_permission(vcpu)) > + return 1; > + > + vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO); > + type = kvm_register_readl(vcpu, (vmx_instruction_info >> 28) & 0xf); This is missing the equivalent of this invept code: types = (vmx->nested.nested_vmx_ept_caps >> VMX_EPT_EXTENT_SHIFT) & 6; if (!(types & (1UL << type))) { nested_vmx_failValid(vcpu, VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID); return 1; } > + /* according to the intel vmx instruction reference, the memory > + * operand is read even if it isn't needed (e.g., for type==global) > + */ > + if (get_vmx_mem_address(vcpu, vmcs_readl(EXIT_QUALIFICATION), > + vmx_instruction_info, false, )) > + return 1; > + if (kvm_read_guest_virt(>arch.emulate_ctxt, gva, , > + sizeof(u32), )) { > + kvm_inject_page_fault(vcpu, ); > + return 1; > + } > + > + switch (type) { > + case VMX_VPID_EXTENT_ALL_CONTEXT: > + if (get_vmcs12(vcpu)->virtual_processor_id == 0) { > + nested_vmx_failValid(vcpu, > + VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID); > + return 1; > + } > + vmx_flush_tlb(vcpu); > + nested_vmx_succeed(vcpu); > + break; > + default: > + /* Trap single context invalidation invvpid calls */ > + BUG_ON(1); ... which means that this BUG_ON(1) is guest triggerable. Unit tests would have caught this... :) Paolo > + break; > + } > + > + skip_emulated_instruction(vcpu); > return 1; > } > > -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/2] KVM: x86: build kvm_userspace_memory_region in x86_set_memory_region
2015-10-12 14:09+0200, Paolo Bonzini: > The next patch will make x86_set_memory_region fill the > userspace_addr. Since the struct is not used untouched > anymore, it makes sense to build it in x86_set_memory_region > directly; it also simplifies the callers. > > Reported-by: Alexandre DERUMIER> Cc: sta...@vger.kernel.org > Fixes: 9da0e4d5ac969909f6b435ce28ea28135a9cbd69 > Signed-off-by: Paolo Bonzini > --- > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > @@ -1199,9 +1199,7 @@ void kvm_complete_insn_gp(struct kvm_vcpu *vcpu, int > err); > -int __x86_set_memory_region(struct kvm *kvm, > - const struct kvm_userspace_memory_region *mem); > -int x86_set_memory_region(struct kvm *kvm, > - const struct kvm_userspace_memory_region *mem); > +int __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa, u32 size); > +int x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa, u32 size); kvm_userspace_memory_region has u64 size, but we only use this for few pages anyway and will hopefully get a warning from GCC if that changes. Patch makes the code much better, Reviewed-by: Radim Krčmář -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 13/15] arm64: kvm: Rewrite fake pgd handling
On Mon, Oct 12, 2015 at 10:55:24AM +0100, Suzuki K. Poulose wrote: > On 10/10/15 15:52, Christoffer Dall wrote: > >Hi Suzuki, > > Hi Christoffer, > > Thanks for being patient enough to review the code :-) without much of > the comments. I now realise there needs much more documentation than > what I have put in already. I am taking care of this in the next > revision already. > > >I had to refresh my mind a fair bit to be able to review this, so I > >thought it may be useful to just remind us all what the constraints of > >this whole thing is, and make sure we agree on this: > > > >1. We fix the IPA max width to 40 bits > >2. We don't support systems with a PARange smaller than 40 bits (do we > >check this anywhere or document this anywhere?) > > AFAIT, no we don't check it anywhere. May be we should. We could plug this > into my CPU feature infrastructure[1] and let the is_hype_mode_available() > use the info to decide if we can support 40bit IPA ? > If we support 40bit IPA or more, yes, I think that would be sane. Or at least put a comment somewhere, perhaps in Documenation. > >3. We always assume we are running on a system with PARange of 40 bits > >and we are therefore constrained to use concatination. > > > >As an implication of (3) above, this code will attempt to allocate 256K > >of physically contiguous memory for each VM on the system. That is > >probably ok, but I just wanted to point it out in case it raises any > >eyebrows for other people following this thread. > > Right, I will document this in a comment. > > >>level: 0 1 2 3 > >>bits : [47] [46 - 36] [35 - 25] [24 - 14] [13 - 0] > >> ^ ^ ^ > >> | | | > >>host entry| x stage-2 entry > >> | > >> IPA -x > > > >Isn't the stage-2 entry using bits [39:25], because you resolve > >more than 11 bits on the initial level of lookup when you concatenate > >tables? > > Yes, the stage-2 entry is just supposed to show the entry level (2). > I don't understand, the stage-2 entry level will be at bit 39, not 35? Thanks, -Christoffer -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/2] KVM: x86: map/unmap private slots in __x86_set_memory_region
2015-10-12 14:09+0200, Paolo Bonzini: > Otherwise, two copies (one of them never used and thus bogus) are > allocated for the regular and SMM address spaces. This breaks > SMM with EPT but without unrestricted guest support, because the > SMM copy of the identity page map is all zeros. (Have you found out why EPT+unrestricted didn't use the alternative SMM mapping as well?) > By moving the allocation to the caller we also remove the last > vestiges of kernel-allocated memory regions (not accessible anymore > in userspace since commit b74a07beed0e, "KVM: Remove kernel-allocated > memory regions", 2010-06-21); that is a nice bonus. > > Reported-by: Alexandre DERUMIER> Cc: sta...@vger.kernel.org > Fixes: 9da0e4d5ac969909f6b435ce28ea28135a9cbd69 > Signed-off-by: Paolo Bonzini > --- vm_mmap() leaks if __kvm_set_memory_region() fails. It's nothing new and following process termination should take care of it, Reviewed-by: Radim Krčmář > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > @@ -7717,23 +7717,53 @@ void kvm_arch_sync_events(struct kvm *kvm) > int __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa, u32 size) > { > int i, r; > + u64 hva; > + struct kvm_memslots *slots = kvm_memslots(kvm); > + struct kvm_memory_slot *slot, old; | [...] > + slot = >memslots[slots->id_to_index[id]]; This seems better written as slot = id_to_memslot(slots, id); (Made me remember that I want to refactor the memslot API ...) | [...] > + } else { > + if (!slot->npages) > + return 0; > + > + hva = 0; > + } > + > + old = *slot; (Assignment could be in the 'else' == !size branch, GCC would have fun.) | [...] > + if (!size) { > + r = vm_munmap(old.userspace_addr, old.npages * PAGE_SIZE); > + WARN_ON(r < 0); > + } -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/2] KVM: arm/arm64: Optimize away redundant LR tracking
On Mon, Oct 12, 2015 at 05:56:14PM +0100, Andre Przywara wrote: > Hi, > > On 02/10/15 15:44, Pavel Fedin wrote: > > Currently we use vgic_irq_lr_map in order to track which LRs hold which > > IRQs, and lr_used bitmap in order to track which LRs are used or free. > > > > vgic_irq_lr_map is actually used only for piggy-back optimization, and > > can be easily replaced by iteration over lr_used. This is good because in > > future, when LPI support is introduced, number of IRQs will grow up to at > > least 16384, while numbers from 1024 to 8192 are never going to be used. > > This would be a huge memory waste. > > > > In its turn, lr_used is also completely redundant since > > ae705930fca6322600690df9dc1c7d0516145a93 ("arm/arm64: KVM: Keep elrsr/aisr > > in sync with software model"), because together with lr_used we also update > > elrsr. This allows to easily replace lr_used with elrsr, inverting all > > conditions (because in elrsr '1' means 'free'). > > So this looks pretty good to me, probably a better (because less > intrusive) solution than my first two patches of the ITS emulation, > which have a very similar scope. > I will give this some testing on my boxes here to spot any regressions, > but I guess I will use these two patches as the base for my next version > of the ITS emulation series. > > Christoffer, Marc, do you consider these for 4.4 (since they are an > independent cleanup) or do you want them to be part of the ITS emulation > series since they make more sense in there? > I'll try to have a look at these tomorrow and I'll think about how to merge this after I've looked at them. Did you review these to the point where you can give your r-b tag here? Thanks, -Christoffer -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/2] KVM: x86: clean up kvm_arch_vcpu_runnable
2015-10-13 12:34+0200, Paolo Bonzini: > Split the huge conditional in two functions. > > Fixes: 64d6067057d9658acb8675afcfba549abdb7fc16 > Cc: sta...@vger.kernel.org > Signed-off-by: Paolo Bonzini> --- Thanks! Reviewed-by: Radim Krčmář -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH v3 00/16] KVM: arm64: GICv3 ITS emulation
Hello! I already suggested one bunch of fixes on top of vITS series, and here is another one. It reconciles it with spurious interrupt fix, and adds missing check in vgic_retire_disabled_irqs(), which was removed in original v3 series. --- >From bdbedc35a4dc9bc258b21792cf734aa3b2383dff Mon Sep 17 00:00:00 2001 From: Pavel FedinDate: Tue, 13 Oct 2015 15:24:19 +0300 Subject: [PATCH] KVM: arm/arm64: Fix LPI loss compute_pending_for_cpu() should return true if there's something pending on the given vCPU. This is used in order to correctly set dist->irq_pending_on_cpu flag. However, the function knows nothing about LPIs, this can contribute to LPI loss. This patch fixes it by introducing vits_check_lpis() function, which returns true if there's any pending LPI. Also, some refactoring done, wrapping some repeated checks into helper functions. Additionally, vgic_retire_disabled_irqs() is fixed to correctly skip LPIs. Signed-off-by: Pavel Fedin --- include/kvm/arm_vgic.h | 1 + virt/kvm/arm/its-emul.c | 46 +++-- virt/kvm/arm/its-emul.h | 1 + virt/kvm/arm/vgic-v3-emul.c | 1 + virt/kvm/arm/vgic.c | 19 +-- 5 files changed, 56 insertions(+), 12 deletions(-) diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h index 39113b9..21c8427 100644 --- a/include/kvm/arm_vgic.h +++ b/include/kvm/arm_vgic.h @@ -148,6 +148,7 @@ struct vgic_vm_ops { int (*map_resources)(struct kvm *, const struct vgic_params *); bool(*queue_lpis)(struct kvm_vcpu *); void(*unqueue_lpi)(struct kvm_vcpu *, int irq); + bool(*check_lpis)(struct kvm_vcpu *); int (*inject_msi)(struct kvm *, struct kvm_msi *); }; diff --git a/virt/kvm/arm/its-emul.c b/virt/kvm/arm/its-emul.c index b1d61df..2fcd844 100644 --- a/virt/kvm/arm/its-emul.c +++ b/virt/kvm/arm/its-emul.c @@ -381,6 +381,18 @@ out_unlock: return ret; } +static bool its_is_enabled(struct kvm *kvm) +{ + return vgic_has_its(kvm) && kvm->arch.vgic.its.enabled && + kvm->arch.vgic.lpis_enabled; +} + +static bool lpi_is_pending(struct its_itte *itte, u32 vcpu_id) +{ + return itte->enabled && test_bit(vcpu_id, itte->pending) && + itte->collection && (itte->collection->target_addr == vcpu_id); +} + /* * Find all enabled and pending LPIs and queue them into the list * registers. @@ -393,20 +405,12 @@ bool vits_queue_lpis(struct kvm_vcpu *vcpu) struct its_itte *itte; bool ret = true; - if (!vgic_has_its(vcpu->kvm)) - return true; - if (!its->enabled || !vcpu->kvm->arch.vgic.lpis_enabled) + if (!its_is_enabled(vcpu->kvm)) return true; spin_lock(>lock); for_each_lpi(device, itte, vcpu->kvm) { - if (!itte->enabled || !test_bit(vcpu->vcpu_id, itte->pending)) - continue; - - if (!itte->collection) - continue; - - if (itte->collection->target_addr != vcpu->vcpu_id) + if (!lpi_is_pending(itte, vcpu->vcpu_id)) continue; @@ -436,6 +440,28 @@ void vits_unqueue_lpi(struct kvm_vcpu *vcpu, int lpi) spin_unlock(>lock); } +bool vits_check_lpis(struct kvm_vcpu *vcpu) +{ + struct vgic_its *its = >kvm->arch.vgic.its; + struct its_device *device; + struct its_itte *itte; + bool ret = false; + + if (!its_is_enabled(vcpu->kvm)) + return false; + + spin_lock(>lock); + for_each_lpi(device, itte, vcpu->kvm) { + ret = lpi_is_pending(itte, vcpu->vcpu_id); + if (ret) + goto out; + } + +out: + spin_unlock(>lock); + return ret; +} + static void its_free_itte(struct its_itte *itte) { list_del(>itte_list); diff --git a/virt/kvm/arm/its-emul.h b/virt/kvm/arm/its-emul.h index 236f153..f7fa5f8 100644 --- a/virt/kvm/arm/its-emul.h +++ b/virt/kvm/arm/its-emul.h @@ -41,6 +41,7 @@ int vits_inject_msi(struct kvm *kvm, struct kvm_msi *msi); bool vits_queue_lpis(struct kvm_vcpu *vcpu); void vits_unqueue_lpi(struct kvm_vcpu *vcpu, int irq); +bool vits_check_lpis(struct kvm_vcpu *vcpu); #define E_ITS_MOVI_UNMAPPED_INTERRUPT 0x010107 #define E_ITS_MOVI_UNMAPPED_COLLECTION 0x010109 diff --git a/virt/kvm/arm/vgic-v3-emul.c b/virt/kvm/arm/vgic-v3-emul.c index 798f256..25463d0 100644 --- a/virt/kvm/arm/vgic-v3-emul.c +++ b/virt/kvm/arm/vgic-v3-emul.c @@ -966,6 +966,7 @@ void vgic_v3_init_emulation(struct kvm *kvm) dist->vm_ops.inject_msi = vits_inject_msi; dist->vm_ops.queue_lpis = vits_queue_lpis; dist->vm_ops.unqueue_lpi = vits_unqueue_lpi; + dist->vm_ops.check_lpis = vits_check_lpis; dist->vgic_dist_base = VGIC_ADDR_UNDEF; dist->vgic_redist_base = VGIC_ADDR_UNDEF; diff
Re: [PATCH 2/2] KVM: x86: fix SMI to halted VCPU
2015-10-13 12:34+0200, Paolo Bonzini: > An SMI to a halted VCPU must wake it up, hence a VCPU with a pending > SMI must be considered runnable. > > Fixes: 64d6067057d9658acb8675afcfba549abdb7fc16 > Cc: sta...@vger.kernel.org > Signed-off-by: Paolo Bonzini> --- Reviewed-by: Radim Krčmář > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > @@ -7781,6 +7781,9 @@ static inline bool kvm_vcpu_has_events(struct kvm_vcpu > *vcpu) > + if (test_bit(KVM_REQ_SMI, >requests)) (Ah, and refactoring of this API is also on my new TODO.) -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 04/32] acpi: add aml_mutex, aml_acquire, aml_release
On 10/13/2015 09:34 PM, Igor Mammedov wrote: On Sun, 11 Oct 2015 11:52:36 +0800 Xiao Guangrongwrote: Implement Mutex, Acquire and Release terms which are used by NVDIMM _DSM method in later patch Signed-off-by: Xiao Guangrong --- hw/acpi/aml-build.c | 32 include/hw/acpi/aml-build.h | 3 +++ 2 files changed, 35 insertions(+) diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index 9fe5e7b..ab52692 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -1164,6 +1164,38 @@ Aml *aml_create_field(Aml *srcbuf, Aml *index, Aml *len, const char *name) return var; } +/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefMutex */ +Aml *aml_mutex(const char *name, uint8_t flags) s/flags/sync_level/ Oops, will fix. +{ +Aml *var = aml_alloc(); +build_append_byte(var->buf, 0x5B); /* ExtOpPrefix */ +build_append_byte(var->buf, 0x01); /* MutexOp */ +build_append_namestring(var->buf, "%s", name); add assert here to check that reserved bits are 0 Good idea, will do. -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [Qemu-devel] [PATCH v3 25/32] nvdimm: build ACPI nvdimm devices
On 10/13/2015 10:39 PM, Igor Mammedov wrote: On Sun, 11 Oct 2015 11:52:57 +0800 Xiao Guangrongwrote: NVDIMM devices is defined in ACPI 6.0 9.20 NVDIMM Devices There is a root device under \_SB and specified NVDIMM devices are under the root device. Each NVDIMM device has _ADR which returns its handle used to associate MEMDEV structure in NFIT We reserve handle 0 for root device. In this patch, we save handle, arg0, arg1 and arg2. Arg3 is conditionally saved in later patch Signed-off-by: Xiao Guangrong --- hw/mem/nvdimm/acpi.c | 203 +++ 1 file changed, 203 insertions(+) diff --git a/hw/mem/nvdimm/acpi.c b/hw/mem/nvdimm/acpi.c I'd suggest to put ACPI parts to hw/acpi/nvdimm.c file so that ACPI maintainers won't miss changes to this files. Sounds reasonable to me. index 1450a6a..d9fa0fd 100644 --- a/hw/mem/nvdimm/acpi.c +++ b/hw/mem/nvdimm/acpi.c @@ -308,15 +308,38 @@ static void build_nfit(void *fit, GSList *device_list, GArray *table_offsets, "NFIT", table_data->len - nfit_start, 1); } +#define NOTIFY_VALUE 0x99 + +struct dsm_in { +uint32_t handle; +uint8_t arg0[16]; +uint32_t arg1; +uint32_t arg2; + /* the remaining size in the page is used by arg3. */ +uint8_t arg3[0]; +} QEMU_PACKED; +typedef struct dsm_in dsm_in; + +struct dsm_out { +/* the size of buffer filled by QEMU. */ +uint16_t len; +uint8_t data[0]; +} QEMU_PACKED; +typedef struct dsm_out dsm_out; + static uint64_t dsm_read(void *opaque, hwaddr addr, unsigned size) { +fprintf(stderr, "BUG: we never read DSM notification MMIO.\n"); return 0; } static void dsm_write(void *opaque, hwaddr addr, uint64_t val, unsigned size) { +if (val != NOTIFY_VALUE) { +fprintf(stderr, "BUG: unexepected notify value 0x%" PRIx64, val); +} } static const MemoryRegionOps dsm_ops = { @@ -372,6 +395,183 @@ static MemoryRegion *build_dsm_memory(NVDIMMState *state) return dsm_fit_mr; } +#define BUILD_STA_METHOD(_dev_, _method_) \ +do { \ +_method_ = aml_method("_STA", 0); \ +aml_append(_method_, aml_return(aml_int(0x0f))); \ +aml_append(_dev_, _method_); \ +} while (0) + +#define SAVE_ARG012_HANDLE_LOCK(_method_, _handle_)\ +do { \ +aml_append(_method_, aml_acquire(aml_name("NLCK"), 0x)); \ how about making method serialized, then you could drop explicit lock/unlock logic for that you'd need to extend existing aml_method() to something like this: aml_method("FOO", 3/*count*/, AML_SERIALIZED, 0 /* sync_level */) I am not sure if multiple methods under different namespace objects can be serialized, for example: Device("__D0") { Method("FOO", 3, AML_SERIALIZED, 0) { BUF = Arg0 } } Device("__D1") { Method("FOO", 3, AML_SERIALIZED, 0) { BUF = Arg0 } } __D0.FOO and __D1.FOO can be serialized? Your suggestion definitely valuable to me, i will abstract the access of shared-memory into one method as your comment below. +aml_append(_method_, aml_store(_handle_, aml_name("HDLE"))); \ +aml_append(_method_, aml_store(aml_arg(0), aml_name("ARG0"))); \ Could you describe QEMU<->ASL interface in a separate spec file (for example like: docs/specs/acpi_mem_hotplug.txt), it will help to with review process as there will be something to compare patches with. Once that is finalized/agreed upon, it should be easy to review and probably to write corresponding patches. Sure, i considered it too and was planing to make this kind of spec after this patchset is merged... I will document the interface in the next version. Also I'd try to minimize QEMU<->ASL interface and implement as much as possible of ASL logic in AML instead of pushing it in hardware (QEMU). Okay, i agree. Since ACPI ASL/AML is new knowledge to me, i did it using the opposite way - move the control to QEMU side as possible ... :) For example there isn't really any need to tell QEMU ARG0 (UUID), _DSM method could just compare UUIDs itself and execute a corresponding branch. Probably something else could be optimized as well but that we can find out during discussion over QEMU<->ASL interface spec. Okay. +aml_append(_method_, aml_store(aml_arg(1), aml_name("ARG1"))); \ +aml_append(_method_, aml_store(aml_arg(2), aml_name("ARG2"))); \ +} while (0) + +#define NOTIFY_AND_RETURN_UNLOCK(_method_) \ +do {
Re: [PATCH 2/2] KVM: x86: map/unmap private slots in __x86_set_memory_region
On 13/10/2015 17:39, Radim Krčmář wrote: > 2015-10-12 14:09+0200, Paolo Bonzini: >> Otherwise, two copies (one of them never used and thus bogus) are >> allocated for the regular and SMM address spaces. This breaks >> SMM with EPT but without unrestricted guest support, because the >> SMM copy of the identity page map is all zeros. > > (Have you found out why EPT+unrestricted didn't use the alternative SMM > mapping as well?) Yes, that I already knew; EPT+unrestricted uses CR0.PG=0 directly so it doesn't use the identity page at all. (CR0.PG=0 w/o unrestricted instead runs with CR0.PG=1. CR3 load and store exits are enabled, and the guest CR3 always points to the identity page map while the guest runs). >> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c >> @@ -7717,23 +7717,53 @@ void kvm_arch_sync_events(struct kvm *kvm) >> int __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa, u32 size) >> { >> int i, r; >> +u64 hva; >> +struct kvm_memslots *slots = kvm_memslots(kvm); >> +struct kvm_memory_slot *slot, old; > | [...] >> +slot = >memslots[slots->id_to_index[id]]; > > This seems better written as > > slot = id_to_memslot(slots, id); Gah, I could not recall the right API! I'll fix it. > (Made me remember that I want to refactor the memslot API ...) > > | [...] >> +} else { >> +if (!slot->npages) >> +return 0; >> + >> +hva = 0; >> +} >> + >> +old = *slot; > > (Assignment could be in the 'else' == !size branch, GCC would have fun.) It would have fun _and_ warn, which is why it's not in the else branch. :) Paolo -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [Qemu-devel] [PATCH v3 11/32] hostmem-file: use whole file size if possible
On 10/13/2015 07:50 PM, Vladimir Sementsov-Ogievskiy wrote: On 11.10.2015 06:52, Xiao Guangrong wrote: Use the whole file size if @size is not specified which is useful if we want to directly pass a file to guest Signed-off-by: Xiao Guangrong--- backends/hostmem-file.c | 47 +++ 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c index 9097a57..adf2835 100644 --- a/backends/hostmem-file.c +++ b/backends/hostmem-file.c @@ -9,6 +9,9 @@ * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory. */ +#include +#include + #include "qemu-common.h" #include "sysemu/hostmem.h" #include "sysemu/sysemu.h" @@ -33,20 +36,56 @@ struct HostMemoryBackendFile { char *mem_path; }; +static uint64_t get_file_size(const char *file) +{ +struct stat stat_buf; +uint64_t size = 0; +int fd; + +fd = open(file, O_RDONLY); +if (fd < 0) { +return 0; +} + +if (stat(file, _buf) < 0) { +goto exit; +} + +if ((S_ISBLK(stat_buf.st_mode)) && !ioctl(fd, BLKGETSIZE64, )) { +goto exit; +} + +size = lseek(fd, 0, SEEK_END); +if (size == -1) { +size = 0; +} +exit: +close(fd); +return size; +} + static void file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) { HostMemoryBackendFile *fb = MEMORY_BACKEND_FILE(backend); -if (!backend->size) { -error_setg(errp, "can't create backend with size 0"); -return; -} if (!fb->mem_path) { error_setg(errp, "mem-path property not set"); return; } +if (!backend->size) { +/* + * use the whole file size if @size is not specified. + */ +backend->size = get_file_size(fb->mem_path); +} + +if (!backend->size) { +error_setg(errp, "can't create backend with size 0"); +return; +} in case of any error in get_file_size (open, stat, lseek) it will write about "backend with size 0" which may be not appropriate.. Okay, i will change it to: ("failed to get file size for %s, can't create backend on it", mem_path); -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/2] KVM: x86: map/unmap private slots in __x86_set_memory_region
2015-10-13 18:28+0200, Paolo Bonzini: > On 13/10/2015 17:39, Radim Krčmář wrote: >> 2015-10-12 14:09+0200, Paolo Bonzini: >>> Otherwise, two copies (one of them never used and thus bogus) are >>> allocated for the regular and SMM address spaces. This breaks >>> SMM with EPT but without unrestricted guest support, because the >>> SMM copy of the identity page map is all zeros. >> >> (Have you found out why EPT+unrestricted didn't use the alternative SMM >> mapping as well?) > > Yes, that I already knew; EPT+unrestricted uses CR0.PG=0 directly so > it doesn't use the identity page at all. (CR0.PG=0 w/o unrestricted > instead runs with CR0.PG=1. CR3 load and store exits are enabled, > and the guest CR3 always points to the identity page map while the > guest runs). Thank you. >>> + } else { >>> + if (!slot->npages) >>> + return 0; >>> + >>> + hva = 0; >>> + } >>> + >>> + old = *slot; >> >> (Assignment could be in the 'else' == !size branch, GCC would have fun.) > > It would have fun _and_ warn, which is why it's not in the else branch. :) I wondered if its "used uninitialized" analyzer got any better :) -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 13/15] arm64: kvm: Rewrite fake pgd handling
On 13/10/15 16:39, Christoffer Dall wrote: On Mon, Oct 12, 2015 at 10:55:24AM +0100, Suzuki K. Poulose wrote: On 10/10/15 15:52, Christoffer Dall wrote: Hi Suzuki, Hi Christoffer, Thanks for being patient enough to review the code :-) without much of the comments. I now realise there needs much more documentation than what I have put in already. I am taking care of this in the next revision already. I had to refresh my mind a fair bit to be able to review this, so I thought it may be useful to just remind us all what the constraints of this whole thing is, and make sure we agree on this: 1. We fix the IPA max width to 40 bits 2. We don't support systems with a PARange smaller than 40 bits (do we check this anywhere or document this anywhere?) AFAIT, no we don't check it anywhere. May be we should. We could plug this into my CPU feature infrastructure[1] and let the is_hype_mode_available() use the info to decide if we can support 40bit IPA ? If we support 40bit IPA or more, yes, I think that would be sane. Or at least put a comment somewhere, perhaps in Documenation. OK 3. We always assume we are running on a system with PARange of 40 bits and we are therefore constrained to use concatination. As an implication of (3) above, this code will attempt to allocate 256K of physically contiguous memory for each VM on the system. That is probably ok, but I just wanted to point it out in case it raises any eyebrows for other people following this thread. Right, I will document this in a comment. level: 0 1 2 3 bits : [47] [46 - 36] [35 - 25] [24 - 14] [13 - 0] ^ ^ ^ | | | host entry| x stage-2 entry | IPA -x Isn't the stage-2 entry using bits [39:25], because you resolve more than 11 bits on the initial level of lookup when you concatenate tables? Yes, the stage-2 entry is just supposed to show the entry level (2). I don't understand, the stage-2 entry level will be at bit 39, not 35? That picture shows the 'level 2' at which the stage-2 translations begin, with 16 pages concatenated, which gives 39-25. The host kernel macros, normally only sees upto bit 35, which is fixed using the kvm_pgd_index() to pick the right PGD entry for a VA. Thanks Suzuki -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 03/32] acpi: add aml_create_field
On 10/13/2015 08:38 PM, Igor Mammedov wrote: On Sun, 11 Oct 2015 11:52:35 +0800 Xiao Guangrongwrote: Implement CreateField term which is used by NVDIMM _DSM method in later patch Signed-off-by: Xiao Guangrong --- hw/acpi/aml-build.c | 13 + include/hw/acpi/aml-build.h | 1 + 2 files changed, 14 insertions(+) diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index a72214d..9fe5e7b 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -1151,6 +1151,19 @@ Aml *aml_sizeof(Aml *arg) return var; } +/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefCreateField */ +Aml *aml_create_field(Aml *srcbuf, Aml *index, Aml *len, const char *name) you haven't addressed v2 comment wrt index, len https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg00435.html Ah, i forgot to mention that the index/len can be determined at runtime: aml_append(_method_, aml_create_field(aml_name("ODAT"), aml_int(0),\ aml_local(6) , "OBUF")); That why i kept these as "aml *" and sorry for i failed to log it in patch 0. -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[kvm:master 9/11] arch/x86/kvm/x86.c:7499:3: note: in expansion of macro 'if'
tree: https://git.kernel.org/pub/scm/virt/kvm/kvm.git master head: 73917739334c6509833b0403b81d4a04a8784bdf commit: f0d648bdf0a5bbc91da6099d5282f77996558ea4 [9/11] KVM: x86: map/unmap private slots in __x86_set_memory_region config: i386-randconfig-x000-10121721 (attached as .config) reproduce: git checkout f0d648bdf0a5bbc91da6099d5282f77996558ea4 # save the attached .config to linux build tree make ARCH=i386 All warnings (new ones prefixed by >>): In file included from include/uapi/linux/stddef.h:1:0, from include/linux/stddef.h:4, from include/uapi/linux/posix_types.h:4, from include/uapi/linux/types.h:13, from include/linux/types.h:5, from include/linux/kvm_host.h:9, from arch/x86/kvm/x86.c:22: arch/x86/kvm/x86.c: In function '__x86_set_memory_region': arch/x86/kvm/x86.c:7499:14: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] if (IS_ERR((void *)hva)) ^ include/linux/compiler.h:147:28: note: in definition of macro '__trace_if' if (__builtin_constant_p((cond)) ? !!(cond) : \ ^ >> arch/x86/kvm/x86.c:7499:3: note: in expansion of macro 'if' if (IS_ERR((void *)hva)) ^ arch/x86/kvm/x86.c:7499:14: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] if (IS_ERR((void *)hva)) ^ include/linux/compiler.h:147:40: note: in definition of macro '__trace_if' if (__builtin_constant_p((cond)) ? !!(cond) : \ ^ >> arch/x86/kvm/x86.c:7499:3: note: in expansion of macro 'if' if (IS_ERR((void *)hva)) ^ arch/x86/kvm/x86.c:7499:14: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] if (IS_ERR((void *)hva)) ^ include/linux/compiler.h:158:16: note: in definition of macro '__trace_if' __r = !!(cond); \ ^ >> arch/x86/kvm/x86.c:7499:3: note: in expansion of macro 'if' if (IS_ERR((void *)hva)) ^ arch/x86/kvm/x86.c:7500:19: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] return PTR_ERR((void *)hva); ^ vim +/if +7499 arch/x86/kvm/x86.c 7483 7484 /* Called with kvm->slots_lock held. */ 7485 if (WARN_ON(id >= KVM_MEM_SLOTS_NUM)) 7486 return -EINVAL; 7487 7488 slot = id_to_memslot(slots, id); 7489 if (size) { 7490 if (WARN_ON(slot->npages)) 7491 return -EEXIST; 7492 7493 /* 7494 * MAP_SHARED to prevent internal slot pages from being moved 7495 * by fork()/COW. 7496 */ 7497 hva = vm_mmap(NULL, 0, size, PROT_READ | PROT_WRITE, 7498MAP_SHARED | MAP_ANONYMOUS, 0); > 7499 if (IS_ERR((void *)hva)) 7500 return PTR_ERR((void *)hva); 7501 } else { 7502 if (!slot->npages) 7503 return 0; 7504 7505 hva = 0; 7506 } 7507 --- 0-DAY kernel test infrastructureOpen Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation .config.gz Description: Binary data
[kvm:master 9/11] arch/x86/kvm/x86.c:7499:14: warning: cast to pointer from integer of different size
tree: https://git.kernel.org/pub/scm/virt/kvm/kvm.git master head: 73917739334c6509833b0403b81d4a04a8784bdf commit: f0d648bdf0a5bbc91da6099d5282f77996558ea4 [9/11] KVM: x86: map/unmap private slots in __x86_set_memory_region config: i386-randconfig-s0-201541 (attached as .config) reproduce: git checkout f0d648bdf0a5bbc91da6099d5282f77996558ea4 # save the attached .config to linux build tree make ARCH=i386 All warnings (new ones prefixed by >>): arch/x86/kvm/x86.c: In function '__x86_set_memory_region': >> arch/x86/kvm/x86.c:7499:14: warning: cast to pointer from integer of >> different size [-Wint-to-pointer-cast] if (IS_ERR((void *)hva)) ^ arch/x86/kvm/x86.c:7500:19: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] return PTR_ERR((void *)hva); ^ vim +7499 arch/x86/kvm/x86.c 7483 7484 /* Called with kvm->slots_lock held. */ 7485 if (WARN_ON(id >= KVM_MEM_SLOTS_NUM)) 7486 return -EINVAL; 7487 7488 slot = id_to_memslot(slots, id); 7489 if (size) { 7490 if (WARN_ON(slot->npages)) 7491 return -EEXIST; 7492 7493 /* 7494 * MAP_SHARED to prevent internal slot pages from being moved 7495 * by fork()/COW. 7496 */ 7497 hva = vm_mmap(NULL, 0, size, PROT_READ | PROT_WRITE, 7498MAP_SHARED | MAP_ANONYMOUS, 0); > 7499 if (IS_ERR((void *)hva)) 7500 return PTR_ERR((void *)hva); 7501 } else { 7502 if (!slot->npages) 7503 return 0; 7504 7505 hva = 0; 7506 } 7507 --- 0-DAY kernel test infrastructureOpen Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation .config.gz Description: Binary data
Re: [PATCH v2 5/5] KVM: nVMX: expose VPID capability to L1
On 10/13/15 10:44 PM, Paolo Bonzini wrote: On 08/10/2015 07:57, Wanpeng Li wrote: Expose VPID capability to L1. For nested guests, we don't do anything specific for single context invalidation. Hence, only advertise support for global context invalidation. The major benefit of nested VPID comes from having separate vpids when switching between L1 and L2, and also when L2's vCPUs not sched in/out on L1. Reviewed-by: Wincy VanSigned-off-by: Wanpeng Li --- arch/x86/kvm/vmx.c | 36 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 31d272e..22b4dc7 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -442,7 +442,7 @@ struct nested_vmx { u32 nested_vmx_true_entry_ctls_low; u32 nested_vmx_misc_low; u32 nested_vmx_misc_high; - u32 nested_vmx_ept_caps; + u64 nested_vmx_ept_vpid_caps; Considering that all VMX_VPID_ constants are off by 32, perhaps it's simpler to have separate variables for nested_vmx_ept_caps and nested_vmx_vpid_caps, and only rejoin them when reading the MSR. It will make this patch smaller too. You can add the new field to struct nested_vmx in patch 3 (leaving it initialized to 0, of course). Good point. I will do it after the new travel recently. :-) Regards, Wanpeng Li -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 23/32] nvdimm: build ACPI NFIT table
On 10/13/2015 01:42 PM, Michael S. Tsirkin wrote: On Tue, Oct 13, 2015 at 01:13:18PM +0800, Xiao Guangrong wrote: #endif This header is too small to be worth it. nvdimm_get_built_list seems to be the only interface - just stick it in the header you have under include. Other functions are introudced and included into it in later patches, it includes the internal things shared between nvdimm device, nvdimm ACPI, nvdimm namespace. Furthermore, this is a internal include file, it is not bad i think. Each time we do this, this seems to invite abuse where people add APIs without documenting them. Understood. I guess I could buy this if you add nvdimm_defs.h with just internal things such as layout of the buffer used for communication between ACPI and hardware. Okay, i will rename internel.h to nvdimm_defs.h and carefully document everything (definitions, function prototypes, etc.) in this file. :) -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 23/32] nvdimm: build ACPI NFIT table
On Tue, Oct 13, 2015 at 01:17:20PM +0800, Xiao Guangrong wrote: > >Would it worth including / copying the ACPICA header files directly? > > > >https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/acpi/actbl1.h > >https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/acpi/acuuid.h > > Good point, Dan. > > These files are not exported under uapi/ so that it is not good to directly > include it, i will learn the definition and adjust it to QEMU's code style > in the next version. > > Thanks! > You can talk to acpica guys to try to move acuuid.h to uapi if you like. But there's not a lot there that we need, I'm not sure it's worth it. -- MST -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html