Re: [edk2] apparent SMBASE relocation issue with noexec enabled [was: MdeModulePkg DxeIpl: Add stack NX support]

2015-08-07 Thread Laszlo Ersek
On 08/07/15 12:38, Paolo Bonzini wrote: On 07/08/2015 01:02, Laszlo Ersek wrote: The trace covers the full lifetime of the guest (I started tracing before launching the guest, and I passed -no-reboot to qemu, so when the guest crashed, QEMU exited.) This was on 3.10.0-299.el7.x86_64. I

Re: [PATCH] kvm:powerpc:Fix error handling in the function mpic_set_default_irq_routing

2015-08-07 Thread Paolo Bonzini
On 07/08/2015 15:47, Nicholas Krause wrote: - kvm_set_irq_routing(opp-kvm, routing, 0, 0); + ret = kvm_set_irq_routing(opp-kvm, routing, 0, 0); + if (ret) { + kfree(routing); + return ret; + } kfree(routing); return 0; You could

Re: [PATCH] kvm:powerpc:Fix error handling in the function mpic_set_default_irq_routing

2015-08-07 Thread Paolo Bonzini
On 07/08/2015 15:47, Nicholas Krause wrote: - kvm_set_irq_routing(opp-kvm, routing, 0, 0); + ret = kvm_set_irq_routing(opp-kvm, routing, 0, 0); + if (ret) { + kfree(routing); + return ret; + } kfree(routing); return 0; You could

[KVM x86 vPMU Patch 2/2] KVM: x86/vPMU: Fix unnecessary signed extension for AMD PERFCTRn

2015-08-07 Thread Wei Huang
According to AMD programmer's manual, AMD PERFCTRn is 64-bit MSR which, unlike Intel perf counters, doesn't require signed extension. This patch removes the unnecessary conversion in SVM vPMU code when PERFCTRn is being updated. Signed-off-by: Wei Huang w...@redhat.com --- arch/x86/kvm/pmu_amd.c

RE: [PATCH 8/9] KVM: x86: Add EOI exit bitmap inference

2015-08-07 Thread Wu, Feng
-Original Message- From: Paolo Bonzini [mailto:paolo.bonz...@gmail.com] On Behalf Of Paolo Bonzini Sent: Friday, August 07, 2015 6:17 PM To: Wu, Feng; linux-ker...@vger.kernel.org; kvm@vger.kernel.org Cc: Steve Rutherford; rkrc...@redhat.com Subject: Re: [PATCH 8/9] KVM: x86: Add

RE: [PATCH 8/9] KVM: x86: Add EOI exit bitmap inference

2015-08-07 Thread Wu, Feng
-Original Message- From: kvm-ow...@vger.kernel.org [mailto:kvm-ow...@vger.kernel.org] On Behalf Of Paolo Bonzini Sent: Wednesday, August 05, 2015 11:24 PM To: linux-ker...@vger.kernel.org; kvm@vger.kernel.org Cc: Steve Rutherford; rkrc...@redhat.com Subject: [PATCH 8/9] KVM: x86:

Re: [PATCH v3 09/11] KVM: arm/arm64: vgic: Prevent userspace injection of a mapped interrupt

2015-08-07 Thread Marc Zyngier
On 07/08/15 08:05, Eric Auger wrote: Hi Marc, On 08/06/2015 06:44 PM, Marc Zyngier wrote: On 05/08/15 14:47, Christoffer Dall wrote: On Wed, Aug 05, 2015 at 01:47:27PM +0200, Eric Auger wrote: On 08/05/2015 12:53 PM, Christoffer Dall wrote: On Wed, Aug 05, 2015 at 10:44:09AM +0100, Marc

Re: [PATCH] kvm:s390:Fix assumption that kvm_set_irq_routing is always run successfully

2015-08-07 Thread Christian Borntraeger
Am 06.08.2015 um 19:05 schrieb Nicholas Krause: This fixes the assumption that kvm_set_irq_routing is always run successfully by instead making it equal to the variable r which we use for returning in the function kvm_arch_vm_ioctl instead of making r equal to zero when calling this particular

Re: [PATCH v3 09/11] KVM: arm/arm64: vgic: Prevent userspace injection of a mapped interrupt

2015-08-07 Thread Eric Auger
Hi Marc, On 08/06/2015 06:44 PM, Marc Zyngier wrote: On 05/08/15 14:47, Christoffer Dall wrote: On Wed, Aug 05, 2015 at 01:47:27PM +0200, Eric Auger wrote: On 08/05/2015 12:53 PM, Christoffer Dall wrote: On Wed, Aug 05, 2015 at 10:44:09AM +0100, Marc Zyngier wrote: On 05/08/15 08:32, Eric

Re: [PATCH 8/9] KVM: x86: Add EOI exit bitmap inference

2015-08-07 Thread Paolo Bonzini
On 07/08/2015 07:43, Wu, Feng wrote: +#ifdef CONFIG_HAVE_KVM_IRQCHIP +struct kvm_irq_routing_table { + int chip[KVM_NR_IRQCHIPS][KVM_IRQCHIP_NUM_PINS]; + struct kvm_kernel_irq_routing_entry *rt_entries; This filed doesn't exist anymore. In fact, this changes is also in my VT-d PI

Re: [kvm-unit-tests PATCH 3/3] arm/run: use ACCEL to choose between kvm and tcg

2015-08-07 Thread Andrew Jones
On Thu, Aug 06, 2015 at 07:29:00PM +0100, Alex Bennée wrote: Andrew Jones drjo...@redhat.com writes: Inspired by a patch by Alex Bennée. This version uses a new unittests.cfg variable and includes support for DRYRUN. Signed-off-by: Andrew Jones drjo...@redhat.com --- Another

Re: [RTF] kvm:x86:Fix error checking in the function pf_interception

2015-08-07 Thread Joerg Roedel
On Thu, Aug 06, 2015 at 10:10:23PM -0400, Nicholas Krause wrote: This fixes error checking in the function pf_interception by checking if the call to kvm_mmu_unprotect_page_virt returns zero to indicate the function has failed internally and if this occurs we must return immediately to the

Re: [PATCH] kvm:x86:Call BUG_ON marco if calls to x86_set_memory_region fail in kvm_arch_destroy

2015-08-07 Thread Paolo Bonzini
On 06/08/2015 16:13, Nicholas Krause wrote: This fixes the calls to x86_memory_region to trigger a kernel oopes for tracing if a bug arises in the function kvm_arch_destroy due to the failing of any of its internal calls to x86_set_memory_region. Signed-off-by: Nicholas Krause

Re: [PATCH] kvm:s390:Fix assumption that kvm_set_irq_routing is always run successfully

2015-08-07 Thread Paolo Bonzini
On 06/08/2015 19:05, Nicholas Krause wrote: This fixes the assumption that kvm_set_irq_routing is always run successfully by instead making it equal to the variable r which we use for returning in the function kvm_arch_vm_ioctl instead of making r equal to zero when calling this particular

[PATCH] KVM: x86: zero IDT limit on entry to SMM

2015-08-07 Thread Paolo Bonzini
The recent BlackHat 2015 presentation The Memory Sinkhole mentions that the IDT limit is zeroed on entry to SMM. This is not documented, and must have changed some time after 2010 (see http://www.ssi.gouv.fr/uploads/IMG/pdf/IT_Defense_2010_final.pdf). KVM was not doing it, but the fix is easy.

Re: [PATCH] kvm:powerpc:Fix error handling in the function mpic_set_default_irq_routing

2015-08-07 Thread Paolo Bonzini
On 06/08/2015 19:13, Nicholas Krause wrote: diff --git a/arch/powerpc/kvm/mpic.c b/arch/powerpc/kvm/mpic.c index 6249cdc..5a18859 100644 --- a/arch/powerpc/kvm/mpic.c +++ b/arch/powerpc/kvm/mpic.c @@ -1641,13 +1641,16 @@ static void mpic_destroy(struct kvm_device *dev) static int

Re: [PATCH] kvm:powerpc:Fix error handling in the function mpic_set_default_irq_routing

2015-08-07 Thread Paolo Bonzini
On 06/08/2015 19:13, Nicholas Krause wrote: diff --git a/arch/powerpc/kvm/mpic.c b/arch/powerpc/kvm/mpic.c index 6249cdc..5a18859 100644 --- a/arch/powerpc/kvm/mpic.c +++ b/arch/powerpc/kvm/mpic.c @@ -1641,13 +1641,16 @@ static void mpic_destroy(struct kvm_device *dev) static int

Re: [edk2] apparent SMBASE relocation issue with noexec enabled [was: MdeModulePkg DxeIpl: Add stack NX support]

2015-08-07 Thread Paolo Bonzini
On 07/08/2015 01:02, Laszlo Ersek wrote: The trace covers the full lifetime of the guest (I started tracing before launching the guest, and I passed -no-reboot to qemu, so when the guest crashed, QEMU exited.) This was on 3.10.0-299.el7.x86_64. I repeated the test with EPT off. The

Re: [patch -rt 1/2] KVM: use simple waitqueue for vcpu-wq

2015-08-07 Thread Peter Zijlstra
On Fri, Aug 07, 2015 at 12:57:38PM +0200, Peter Zijlstra wrote: +void __finish_swait(struct swait_queue_head *q, struct swait_queue *wait) this one has no users the __ suggests that it is locked edition. Maybe it is for the completions… Yeah, who knows, I certainly do not anymore ;-)

Re: [PATCH] KVM: x86: Use adjustment in guest cycles when handling MSR_IA32_TSC_ADJUST

2015-08-07 Thread Paolo Bonzini
On 07/08/2015 05:24, Haozhong Zhang wrote: When kvm_set_msr_common() handles a guest's write to MSR_IA32_TSC_ADJUST, it will calcuate an adjustment based on the data written by guest and then use it to adjust TSC offset by calling a call-back adjust_tsc_offset(). The 3rd parameter of

Re: [PATCH 8/9] KVM: x86: Add EOI exit bitmap inference

2015-08-07 Thread Paolo Bonzini
On 07/08/2015 09:46, Wu, Feng wrote: If I understand it correctly, here you reserve the low part of the routing table, and insert entries with KVM_IRQ_ROUTING_MSI type in them, then you use this as a hint to KVM to set the EOI bit map. I have two concerns: - Currently, GSI 2 is used for

Re: [patch -rt 1/2] KVM: use simple waitqueue for vcpu-wq

2015-08-07 Thread Peter Zijlstra
On Wed, Feb 25, 2015 at 10:02:50PM +0100, Sebastian Andrzej Siewior wrote: +static inline int swait_active(struct swait_queue_head *q) +{ +return !list_empty(q-task_list); In RT there was a smp_mb() which you dropped and I assume you had reasons for it. Yeah, RT didn't have a reason

[PATCH v2 2/4] KVM: arm/arm64: check power_off in kvm_arch_vcpu_runnable

2015-08-07 Thread Eric Auger
kvm_arch_vcpu_runnable now also checks whether the power_off flag is set. Signed-off-by: Eric Auger eric.au...@linaro.org --- arch/arm/kvm/arm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index 3ac6b4c..4f50be3 100644 ---

[PATCH v2 1/4] KVM: arm/arm64: rename pause into power_off

2015-08-07 Thread Eric Auger
The kvm_vcpu_arch pause field is renamed into power_off to prepare for the introduction of a new pause field. Also vcpu_pause is renamed into vcpu_sleep since we will sleep until both power_off and pause are false. Signed-off-by: Eric Auger eric.au...@linaro.org --- v1 - v2: - rename pause in

[PATCH v2 0/4] KVM: arm/arm64: guest synchronous halt/resume

2015-08-07 Thread Eric Auger
This series introduces the capability to synchronously exit the guest and prevent it from being re-entered. This modality will be used by IRQ forwarding series when changing the state of the IRQ. Former pause flag used when starting the vcpu in KVM_ARM_VCPU_POWER_OFF state, in PSCI calls and in

Re: [PATCH kvmtool] kvm__emulate_io: Don't call br_read_unlock() twice on IO error

2015-08-07 Thread Will Deacon
On Thu, Aug 06, 2015 at 07:39:44PM +0100, Josh Triplett wrote: The IO error path in kvm__emulate_io would call br_read_unlock(), then goto error, which would call br_read_unlock() again. Refactor the control flow to have only one exit path and one call to br_read_unlock(). Thanks, Josh. I

[PATCH v4 06/11] KVM: arm/arm64: vgic: Allow dynamic mapping of physical/virtual interrupts

2015-08-07 Thread Marc Zyngier
In order to be able to feed physical interrupts to a guest, we need to be able to establish the virtual-physical mapping between the two worlds. The mappings are kept in a set of RCU lists, indexed by virtual interrupts. Signed-off-by: Marc Zyngier marc.zyng...@arm.com --- arch/arm/kvm/arm.c

[PATCH v4 01/11] arm/arm64: KVM: Fix ordering of timer/GIC on guest entry

2015-08-07 Thread Marc Zyngier
As we now inject the timer interrupt when we're about to enter the guest, it makes a lot more sense to make sure this happens before the vgic code queues the pending interrupts. Otherwise, we get the interrupt on the following exit, which is not great for latency (and leads to all kind of bizarre

[PATCH v4 04/11] KVM: arm/arm64: vgic: Allow HW irq to be encoded in LR

2015-08-07 Thread Marc Zyngier
Now that struct vgic_lr supports the LR_HW bit and carries a hwirq field, we can encode that information into the list registers. This patch provides implementations for both GICv2 and GICv3. Reviewed-by: Christoffer Dall christoffer.d...@linaro.org Signed-off-by: Marc Zyngier

[PATCH v2 4/4] KVM: arm/arm64: implement kvm_arm_[halt,resume]_guest

2015-08-07 Thread Eric Auger
We introduce kvm_arm_halt_guest and resume functions. They will be used for IRQ forward state change. Halt is synchronous and prevents the guest from being re-entered. We use the same mechanism put in place for PSCI former pause, now renamed power_off. A new flag is introduced in arch vcpu state,

[PATCH v2 3/4] KVM: arm/arm64: check power_off in critical section before VCPU run

2015-08-07 Thread Eric Auger
In case KVM_SET_MP_STATE ioctl is called just after we executed the vcpu_sleep check, we can enter the guest although KVM_MP_STATE_STOPPED is set. Let's check the power_off state in the critical section, just before entering the guest. Signed-off-by: Eric Auger eric.au...@linaro.org Reported-by:

[PATCH v4 05/11] KVM: arm/arm64: vgic: Relax vgic_can_sample_irq for edge IRQs

2015-08-07 Thread Marc Zyngier
We only set the irq_queued flag for level interrupts, meaning that !vgic_irq_is_queued(vcpu, irq) is a good enough predicate for all interrupts. This will allow us to inject edge HW interrupts, for which the state ACTIVE+PENDING is not allowed. Reviewed-by: Christoffer Dall

[PATCH v4 08/11] KVM: arm/arm64: vgic: Add vgic_{get,set}_phys_irq_active

2015-08-07 Thread Marc Zyngier
In order to control the active state of an interrupt, introduce a pair of accessors allowing the state to be set/queried. This only affects the logical state, and the HW state will only be applied at world-switch time. Acked-by: Christoffer Dall christoffer.d...@linaro.org Signed-off-by: Marc

[PATCH v4 00/11] arm/arm64: KVM: Active interrupt state switching for shared devices

2015-08-07 Thread Marc Zyngier
From day 1, our timer code has been using a terrible hack: whenever the guest is scheduled with a timer interrupt pending (i.e. the HW timer has expired), we restore the timer state with the MASK bit set, in order to avoid the physical interrupt to fire again. And again. And again... This is

[PATCH v4 09/11] KVM: arm/arm64: vgic: Prevent userspace injection of a mapped interrupt

2015-08-07 Thread Marc Zyngier
Virtual interrupts mapped to a HW interrupt should only be triggered from inside the kernel. Otherwise, you could end up confusing the kernel (and the GIC's) state machine. Rearrange the injection path so that kvm_vgic_inject_irq is used for non-mapped interrupts, and kvm_vgic_inject_mapped_irq

[PATCH v4 07/11] KVM: arm/arm64: vgic: Allow HW interrupts to be queued to a guest

2015-08-07 Thread Marc Zyngier
To allow a HW interrupt to be injected into a guest, we lookup the guest virtual interrupt in the irq_phys_map list, and if we have a match, encode both interrupts in the LR. We also mark the interrupt as active at the host distributor level. On guest EOI on the virtual interrupt, the host

[PATCH v4 02/11] arm/arm64: KVM: Move vgic handling to a non-preemptible section

2015-08-07 Thread Marc Zyngier
As we're about to introduce some serious GIC-poking to the vgic code, it is important to make sure that we're going to poke the part of the GIC that belongs to the CPU we're about to run on (otherwise, we'd end up with some unexpected interrupts firing)... Introducing a non-preemptible section in

[PATCH v4 11/11] KVM: arm/arm64: vgic: Allow HW interrupts for non-shared devices

2015-08-07 Thread Marc Zyngier
So far, the only use of the HW interrupt facility is the timer, implying that the active state is context-switched for each vcpu, as the device is is shared across all vcpus. This does not work for a device that has been assigned to a VM, as the guest is entierely in control of that device (the

[PATCH v4 10/11] KVM: arm/arm64: timer: Allow the timer to control the active state

2015-08-07 Thread Marc Zyngier
In order to remove the crude hack where we sneak the masked bit into the timer's control register, make use of the phys_irq_map API control the active state of the interrupt. This causes some limited changes to allow for potential error propagation. Reviewed-by: Christoffer Dall

[PATCH v4 03/11] KVM: arm/arm64: vgic: Convert struct vgic_lr to use bitfields

2015-08-07 Thread Marc Zyngier
As we're about to cram more information in the vgic_lr structure (HW interrupt number and additional state information), we switch to a layout similar to the HW's: - use bitfields to save space (we don't need more than 10 bits to represent the irq numbers) - source CPU and HW interrupt can

Re: [patch -rt 1/2] KVM: use simple waitqueue for vcpu-wq

2015-08-07 Thread Christoph Hellwig
On Fri, Aug 07, 2015 at 01:14:15PM +0200, Peter Zijlstra wrote: On that, we cannot convert completions to swait. Because swait wake_all must not happen from IRQ context, and complete_all() typically is used from just that. If swait queues aren't useable from IRQ context they will be fairly

Re: [patch -rt 1/2] KVM: use simple waitqueue for vcpu-wq

2015-08-07 Thread Peter Zijlstra
On Fri, Aug 07, 2015 at 09:41:31AM -0700, Christoph Hellwig wrote: On Fri, Aug 07, 2015 at 01:14:15PM +0200, Peter Zijlstra wrote: On that, we cannot convert completions to swait. Because swait wake_all must not happen from IRQ context, and complete_all() typically is used from just that.

Re: [PATCH v4 5/5] KVM: eventfd: add irq bypass consumer management

2015-08-07 Thread Alex Williamson
On Mon, 2015-08-03 at 19:20 +0200, Eric Auger wrote: This patch adds the registration/unregistration of an irq_bypass_consumer on irqfd assignment/deassignment. Signed-off-by: Eric Auger eric.au...@linaro.org Signed-off-by: Feng Wu feng...@intel.com --- v2 - v3 (Feng Wu): - Use

[KVM x86 vPMU Patch 0/2] Two vPMU Trivial Patches

2015-08-07 Thread Wei Huang
These two trivial patches are related to x86 vPMU code. They were actually suggested by Andrew Jones while he was reviewing the last big vPMU patch set. These patches have been compiled and tested on AMD system using a 64-bit guest VM with various perf commands (e.g. bench, test, top, stat). No

[KVM x86 vPMU Patch 1/2] KVM: x86/vPMU: Move the definition of kvm_pmu_ops to arch-specific files

2015-08-07 Thread Wei Huang
Instead of being defined in a common header file, the kvm_pmu_ops struct is arch (vmx/svm) specific. This trivial patch relocates two extern variable definition to their arch-specific files. Signed-off-by: Wei Huang w...@redhat.com --- arch/x86/kvm/pmu.h | 2 -- arch/x86/kvm/svm.c | 1 +

Re: [PATCH v4 4/5] KVM: introduce kvm_arch functions for IRQ bypass

2015-08-07 Thread Alex Williamson
On Mon, 2015-08-03 at 19:20 +0200, Eric Auger wrote: This patch introduces - kvm_arch_irq_bypass_add_producer - kvm_arch_irq_bypass_del_producer - kvm_arch_irq_bypass_stop - kvm_arch_irq_bypass_start They make possible to specialize the KVM IRQ bypass consumer in case

rdtsc() in kvm-unit-tests on x86

2015-08-07 Thread Jintack Lim
Hi all, While I was looking at rdtsc() code in kvm-unit-tests (e.g. x86/vmexit.c), I was getting curious that out-of-order execution on the processor may make rdtsc() executed not in the place we expect. Referring to this document from intel,