kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PULL 0/4] KVM: s390: last fixes for next merge window
@ 2014-03-25 13:35 Christian Borntraeger
  2014-03-25 13:35 ` [PULL 1/4] KVM: s390: randomize sca address Christian Borntraeger
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Christian Borntraeger @ 2014-03-25 13:35 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: KVM, linux-s390, Cornelia Huck, Christian Borntraeger

Paolo,

The following changes since commit 94b3ffcd41a90d2cb0b32ca23aa58a01111d5dc0:

  Merge tag 'kvm-s390-20140317' of git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux into HEAD (2014-03-17 12:21:35 +0100)

are available in the git repository at:


  git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git tags/kvm-s390-20140325

for you to fetch changes up to 2ed10cc15e7edf2daf22ce807a877a1266e97711:

  KVM: s390: clear local interrupts at cpu initial reset (2014-03-25 13:27:12 +0100)

I have verfied that there is no merge conflict with the irqfd
patches from Cornelia.

Christian

----------------------------------------------------------------
3 fixes
- memory leak on certain SIGP conditions
- wrong size for idle bitmap (always too big)
- clear local interrupts on initial CPU reset

1 performance improvement
- improve performance with many guests on certain workloads

----------------------------------------------------------------
Christian Borntraeger (1):
      KVM: s390: randomize sca address

Jens Freimann (2):
      KVM: s390: fix calculation of idle_mask array size
      KVM: s390: clear local interrupts at cpu initial reset

Thomas Huth (1):
      KVM: s390: Fix possible memory leak in SIGP functions

 arch/s390/include/asm/kvm_host.h |  3 +--
 arch/s390/kvm/interrupt.c        | 14 ++++++++++++++
 arch/s390/kvm/kvm-s390.c         |  6 ++++++
 arch/s390/kvm/kvm-s390.h         |  1 +
 arch/s390/kvm/sigp.c             | 14 ++++++--------
 5 files changed, 28 insertions(+), 10 deletions(-)


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PULL 1/4] KVM: s390: randomize sca address
  2014-03-25 13:35 [PULL 0/4] KVM: s390: last fixes for next merge window Christian Borntraeger
@ 2014-03-25 13:35 ` Christian Borntraeger
  2014-03-25 13:53   ` Paolo Bonzini
  2014-03-25 13:35 ` [PULL 2/4] KVM: s390: fix calculation of idle_mask array size Christian Borntraeger
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 13+ messages in thread
From: Christian Borntraeger @ 2014-03-25 13:35 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: KVM, linux-s390, Cornelia Huck, Christian Borntraeger

We allocate a page for the 2k sca, so lets use the space to improve
hit rate of some internal cpu caches. No need to change the freeing
of the page, as this will shift away the page offset bits anyway.

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
---
 arch/s390/kvm/kvm-s390.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 7337c57..a02979f 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -215,6 +215,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
 {
 	int rc;
 	char debug_name[16];
+	static unsigned long sca_offset;
 
 	rc = -EINVAL;
 #ifdef CONFIG_KVM_S390_UCONTROL
@@ -236,6 +237,10 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
 	kvm->arch.sca = (struct sca_block *) get_zeroed_page(GFP_KERNEL);
 	if (!kvm->arch.sca)
 		goto out_err;
+	spin_lock(&kvm_lock);
+	sca_offset = (sca_offset + 16) & 0x7f0;
+	kvm->arch.sca = (struct sca_block *) ((char *) kvm->arch.sca + sca_offset);
+	spin_unlock(&kvm_lock);
 
 	sprintf(debug_name, "kvm-%u", current->pid);
 
-- 
1.8.4.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PULL 2/4] KVM: s390: fix calculation of idle_mask array size
  2014-03-25 13:35 [PULL 0/4] KVM: s390: last fixes for next merge window Christian Borntraeger
  2014-03-25 13:35 ` [PULL 1/4] KVM: s390: randomize sca address Christian Borntraeger
@ 2014-03-25 13:35 ` Christian Borntraeger
  2014-03-25 13:55   ` Paolo Bonzini
  2014-03-25 13:35 ` [PULL 3/4] KVM: s390: Fix possible memory leak in SIGP functions Christian Borntraeger
  2014-03-25 13:35 ` [PULL 4/4] KVM: s390: clear local interrupts at cpu initial reset Christian Borntraeger
  3 siblings, 1 reply; 13+ messages in thread
From: Christian Borntraeger @ 2014-03-25 13:35 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: KVM, linux-s390, Cornelia Huck, Jens Freimann,
	Christian Borntraeger

From: Jens Freimann <jfrei@linux.vnet.ibm.com>

We need BITS_TO_LONGS, not sizeof(long) to calculate
the correct size.

idle_mask is a bitmask, each bit representing the state
of a cpu. The desired outcome is an array of unsigned long
fields that can fit KVM_MAX_VCPUS bits. We should not use
sizeof(long) which returnes the size in bytes, but BITS_TO_LONGS

Signed-off-by: Jens Freimann <jfrei@linux.vnet.ibm.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 arch/s390/include/asm/kvm_host.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index 734d302..c36cd35 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -213,8 +213,7 @@ struct kvm_s390_float_interrupt {
 	struct list_head list;
 	atomic_t active;
 	int next_rr_cpu;
-	unsigned long idle_mask[(KVM_MAX_VCPUS + sizeof(long) - 1)
-				/ sizeof(long)];
+	unsigned long idle_mask[BITS_TO_LONGS(KVM_MAX_VCPUS)];
 	unsigned int irq_count;
 };
 
-- 
1.8.4.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PULL 3/4] KVM: s390: Fix possible memory leak in SIGP functions
  2014-03-25 13:35 [PULL 0/4] KVM: s390: last fixes for next merge window Christian Borntraeger
  2014-03-25 13:35 ` [PULL 1/4] KVM: s390: randomize sca address Christian Borntraeger
  2014-03-25 13:35 ` [PULL 2/4] KVM: s390: fix calculation of idle_mask array size Christian Borntraeger
@ 2014-03-25 13:35 ` Christian Borntraeger
  2014-03-25 14:02   ` Paolo Bonzini
  2014-03-25 13:35 ` [PULL 4/4] KVM: s390: clear local interrupts at cpu initial reset Christian Borntraeger
  3 siblings, 1 reply; 13+ messages in thread
From: Christian Borntraeger @ 2014-03-25 13:35 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: KVM, linux-s390, Cornelia Huck, Thomas Huth,
	Christian Borntraeger

From: Thomas Huth <thuth@linux.vnet.ibm.com>

When kvm_get_vcpu() returned NULL for the destination CPU in
__sigp_emergency() or __sigp_external_call(), the memory for the
"inti" structure was not released anymore. This patch fixes this
issue by moving the check for !dst_vcpu before the kzalloc() call.

Signed-off-by: Thomas Huth <thuth@linux.vnet.ibm.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 arch/s390/kvm/sigp.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/arch/s390/kvm/sigp.c b/arch/s390/kvm/sigp.c
index 3fe44c4..26caeb5 100644
--- a/arch/s390/kvm/sigp.c
+++ b/arch/s390/kvm/sigp.c
@@ -58,7 +58,9 @@ static int __sigp_emergency(struct kvm_vcpu *vcpu, u16 cpu_addr)
 	struct kvm_s390_interrupt_info *inti;
 	struct kvm_vcpu *dst_vcpu = NULL;
 
-	if (cpu_addr >= KVM_MAX_VCPUS)
+	if (cpu_addr < KVM_MAX_VCPUS)
+		dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr);
+	if (!dst_vcpu)
 		return SIGP_CC_NOT_OPERATIONAL;
 
 	inti = kzalloc(sizeof(*inti), GFP_KERNEL);
@@ -68,9 +70,6 @@ static int __sigp_emergency(struct kvm_vcpu *vcpu, u16 cpu_addr)
 	inti->type = KVM_S390_INT_EMERGENCY;
 	inti->emerg.code = vcpu->vcpu_id;
 
-	dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr);
-	if (!dst_vcpu)
-		return SIGP_CC_NOT_OPERATIONAL;
 	li = &dst_vcpu->arch.local_int;
 	spin_lock_bh(&li->lock);
 	list_add_tail(&inti->list, &li->list);
@@ -121,7 +120,9 @@ static int __sigp_external_call(struct kvm_vcpu *vcpu, u16 cpu_addr)
 	struct kvm_s390_interrupt_info *inti;
 	struct kvm_vcpu *dst_vcpu = NULL;
 
-	if (cpu_addr >= KVM_MAX_VCPUS)
+	if (cpu_addr < KVM_MAX_VCPUS)
+		dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr);
+	if (!dst_vcpu)
 		return SIGP_CC_NOT_OPERATIONAL;
 
 	inti = kzalloc(sizeof(*inti), GFP_KERNEL);
@@ -131,9 +132,6 @@ static int __sigp_external_call(struct kvm_vcpu *vcpu, u16 cpu_addr)
 	inti->type = KVM_S390_INT_EXTERNAL_CALL;
 	inti->extcall.code = vcpu->vcpu_id;
 
-	dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr);
-	if (!dst_vcpu)
-		return SIGP_CC_NOT_OPERATIONAL;
 	li = &dst_vcpu->arch.local_int;
 	spin_lock_bh(&li->lock);
 	list_add_tail(&inti->list, &li->list);
-- 
1.8.4.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PULL 4/4] KVM: s390: clear local interrupts at cpu initial reset
  2014-03-25 13:35 [PULL 0/4] KVM: s390: last fixes for next merge window Christian Borntraeger
                   ` (2 preceding siblings ...)
  2014-03-25 13:35 ` [PULL 3/4] KVM: s390: Fix possible memory leak in SIGP functions Christian Borntraeger
@ 2014-03-25 13:35 ` Christian Borntraeger
  2014-03-25 13:56   ` Paolo Bonzini
  3 siblings, 1 reply; 13+ messages in thread
From: Christian Borntraeger @ 2014-03-25 13:35 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: KVM, linux-s390, Cornelia Huck, Jens Freimann,
	Christian Borntraeger

From: Jens Freimann <jfrei@linux.vnet.ibm.com>

Empty list of local interrupts when vcpu goes through initial reset
to provide a clean state

Signed-off-by: Jens Freimann <jfrei@linux.vnet.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
 arch/s390/kvm/interrupt.c | 14 ++++++++++++++
 arch/s390/kvm/kvm-s390.c  |  1 +
 arch/s390/kvm/kvm-s390.h  |  1 +
 3 files changed, 16 insertions(+)

diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
index 79d2e4f..05bffd7 100644
--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -509,6 +509,20 @@ enum hrtimer_restart kvm_s390_idle_wakeup(struct hrtimer *timer)
 	return HRTIMER_NORESTART;
 }
 
+void kvm_s390_clear_local_irqs(struct kvm_vcpu *vcpu)
+{
+	struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
+	struct kvm_s390_interrupt_info  *n, *inti = NULL;
+
+	spin_lock_bh(&li->lock);
+	list_for_each_entry_safe(inti, n, &li->list, list) {
+		list_del(&inti->list);
+		kfree(inti);
+	}
+	atomic_set(&li->active, 0);
+	spin_unlock_bh(&li->lock);
+}
+
 void kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu)
 {
 	struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index a02979f..83b7944 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -395,6 +395,7 @@ static void kvm_s390_vcpu_initial_reset(struct kvm_vcpu *vcpu)
 	vcpu->arch.pfault_token = KVM_S390_PFAULT_TOKEN_INVALID;
 	kvm_clear_async_pf_completion_queue(vcpu);
 	atomic_set_mask(CPUSTAT_STOPPED, &vcpu->arch.sie_block->cpuflags);
+	kvm_s390_clear_local_irqs(vcpu);
 }
 
 int kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h
index ed4750a..6311170 100644
--- a/arch/s390/kvm/kvm-s390.h
+++ b/arch/s390/kvm/kvm-s390.h
@@ -129,6 +129,7 @@ enum hrtimer_restart kvm_s390_idle_wakeup(struct hrtimer *timer);
 void kvm_s390_tasklet(unsigned long parm);
 void kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu);
 void kvm_s390_deliver_pending_machine_checks(struct kvm_vcpu *vcpu);
+void kvm_s390_clear_local_irqs(struct kvm_vcpu *vcpu);
 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,
-- 
1.8.4.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PULL 1/4] KVM: s390: randomize sca address
  2014-03-25 13:35 ` [PULL 1/4] KVM: s390: randomize sca address Christian Borntraeger
@ 2014-03-25 13:53   ` Paolo Bonzini
  2014-03-25 14:04     ` Christian Borntraeger
  0 siblings, 1 reply; 13+ messages in thread
From: Paolo Bonzini @ 2014-03-25 13:53 UTC (permalink / raw)
  To: Christian Borntraeger; +Cc: KVM, linux-s390, Cornelia Huck

Il 25/03/2014 14:35, Christian Borntraeger ha scritto:
> We allocate a page for the 2k sca, so lets use the space to improve
> hit rate of some internal cpu caches. No need to change the freeing
> of the page, as this will shift away the page offset bits anyway.
>
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
> ---
>  arch/s390/kvm/kvm-s390.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
> index 7337c57..a02979f 100644
> --- a/arch/s390/kvm/kvm-s390.c
> +++ b/arch/s390/kvm/kvm-s390.c
> @@ -215,6 +215,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
>  {
>  	int rc;
>  	char debug_name[16];
> +	static unsigned long sca_offset;
>
>  	rc = -EINVAL;
>  #ifdef CONFIG_KVM_S390_UCONTROL
> @@ -236,6 +237,10 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
>  	kvm->arch.sca = (struct sca_block *) get_zeroed_page(GFP_KERNEL);
>  	if (!kvm->arch.sca)
>  		goto out_err;
> +	spin_lock(&kvm_lock);
> +	sca_offset = (sca_offset + 16) & 0x7f0;
> +	kvm->arch.sca = (struct sca_block *) ((char *) kvm->arch.sca + sca_offset);
> +	spin_unlock(&kvm_lock);
>
>  	sprintf(debug_name, "kvm-%u", current->pid);
>
>

Does this have to remain the same across migration?

Paolo

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PULL 2/4] KVM: s390: fix calculation of idle_mask array size
  2014-03-25 13:35 ` [PULL 2/4] KVM: s390: fix calculation of idle_mask array size Christian Borntraeger
@ 2014-03-25 13:55   ` Paolo Bonzini
  0 siblings, 0 replies; 13+ messages in thread
From: Paolo Bonzini @ 2014-03-25 13:55 UTC (permalink / raw)
  To: Christian Borntraeger; +Cc: KVM, linux-s390, Cornelia Huck, Jens Freimann

Il 25/03/2014 14:35, Christian Borntraeger ha scritto:
> From: Jens Freimann <jfrei@linux.vnet.ibm.com>
>
> We need BITS_TO_LONGS, not sizeof(long) to calculate
> the correct size.
>
> idle_mask is a bitmask, each bit representing the state
> of a cpu. The desired outcome is an array of unsigned long
> fields that can fit KVM_MAX_VCPUS bits. We should not use
> sizeof(long) which returnes the size in bytes, but BITS_TO_LONGS
>
> Signed-off-by: Jens Freimann <jfrei@linux.vnet.ibm.com>
> Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> ---
>  arch/s390/include/asm/kvm_host.h | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
> index 734d302..c36cd35 100644
> --- a/arch/s390/include/asm/kvm_host.h
> +++ b/arch/s390/include/asm/kvm_host.h
> @@ -213,8 +213,7 @@ struct kvm_s390_float_interrupt {
>  	struct list_head list;
>  	atomic_t active;
>  	int next_rr_cpu;
> -	unsigned long idle_mask[(KVM_MAX_VCPUS + sizeof(long) - 1)
> -				/ sizeof(long)];
> +	unsigned long idle_mask[BITS_TO_LONGS(KVM_MAX_VCPUS)];
>  	unsigned int irq_count;
>  };
>
>

Perhaps you can also use DECLARE_BITMAP, since you use 
find_first_bit/set_bit/clear_bit on idle_mask.

Paolo

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PULL 4/4] KVM: s390: clear local interrupts at cpu initial reset
  2014-03-25 13:35 ` [PULL 4/4] KVM: s390: clear local interrupts at cpu initial reset Christian Borntraeger
@ 2014-03-25 13:56   ` Paolo Bonzini
  2014-03-25 14:18     ` Christian Borntraeger
  0 siblings, 1 reply; 13+ messages in thread
From: Paolo Bonzini @ 2014-03-25 13:56 UTC (permalink / raw)
  To: Christian Borntraeger; +Cc: KVM, linux-s390, Cornelia Huck, Jens Freimann

Il 25/03/2014 14:35, Christian Borntraeger ha scritto:
> +	spin_lock_bh(&li->lock);
> +	list_for_each_entry_safe(inti, n, &li->list, list) {
> +		list_del(&inti->list);
> +		kfree(inti);
> +	}
> +	atomic_set(&li->active, 0);
> +	spin_unlock_bh(&li->lock);
> +}

Out of curiosity, why the _bh?

Paolo


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PULL 3/4] KVM: s390: Fix possible memory leak in SIGP functions
  2014-03-25 13:35 ` [PULL 3/4] KVM: s390: Fix possible memory leak in SIGP functions Christian Borntraeger
@ 2014-03-25 14:02   ` Paolo Bonzini
  2014-03-25 14:39     ` Christian Borntraeger
  0 siblings, 1 reply; 13+ messages in thread
From: Paolo Bonzini @ 2014-03-25 14:02 UTC (permalink / raw)
  To: Christian Borntraeger; +Cc: KVM, linux-s390, Cornelia Huck, Thomas Huth

Il 25/03/2014 14:35, Christian Borntraeger ha scritto:
> From: Thomas Huth <thuth@linux.vnet.ibm.com>
>
> When kvm_get_vcpu() returned NULL for the destination CPU in
> __sigp_emergency() or __sigp_external_call(), the memory for the
> "inti" structure was not released anymore. This patch fixes this
> issue by moving the check for !dst_vcpu before the kzalloc() call.
>
> Signed-off-by: Thomas Huth <thuth@linux.vnet.ibm.com>
> Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>

Should patch 2 and this one have a Cc: stable?

Paolo

> ---
>  arch/s390/kvm/sigp.c | 14 ++++++--------
>  1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/arch/s390/kvm/sigp.c b/arch/s390/kvm/sigp.c
> index 3fe44c4..26caeb5 100644
> --- a/arch/s390/kvm/sigp.c
> +++ b/arch/s390/kvm/sigp.c
> @@ -58,7 +58,9 @@ static int __sigp_emergency(struct kvm_vcpu *vcpu, u16 cpu_addr)
>  	struct kvm_s390_interrupt_info *inti;
>  	struct kvm_vcpu *dst_vcpu = NULL;
>
> -	if (cpu_addr >= KVM_MAX_VCPUS)
> +	if (cpu_addr < KVM_MAX_VCPUS)
> +		dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr);
> +	if (!dst_vcpu)
>  		return SIGP_CC_NOT_OPERATIONAL;
>
>  	inti = kzalloc(sizeof(*inti), GFP_KERNEL);
> @@ -68,9 +70,6 @@ static int __sigp_emergency(struct kvm_vcpu *vcpu, u16 cpu_addr)
>  	inti->type = KVM_S390_INT_EMERGENCY;
>  	inti->emerg.code = vcpu->vcpu_id;
>
> -	dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr);
> -	if (!dst_vcpu)
> -		return SIGP_CC_NOT_OPERATIONAL;
>  	li = &dst_vcpu->arch.local_int;
>  	spin_lock_bh(&li->lock);
>  	list_add_tail(&inti->list, &li->list);
> @@ -121,7 +120,9 @@ static int __sigp_external_call(struct kvm_vcpu *vcpu, u16 cpu_addr)
>  	struct kvm_s390_interrupt_info *inti;
>  	struct kvm_vcpu *dst_vcpu = NULL;
>
> -	if (cpu_addr >= KVM_MAX_VCPUS)
> +	if (cpu_addr < KVM_MAX_VCPUS)
> +		dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr);
> +	if (!dst_vcpu)
>  		return SIGP_CC_NOT_OPERATIONAL;
>
>  	inti = kzalloc(sizeof(*inti), GFP_KERNEL);
> @@ -131,9 +132,6 @@ static int __sigp_external_call(struct kvm_vcpu *vcpu, u16 cpu_addr)
>  	inti->type = KVM_S390_INT_EXTERNAL_CALL;
>  	inti->extcall.code = vcpu->vcpu_id;
>
> -	dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr);
> -	if (!dst_vcpu)
> -		return SIGP_CC_NOT_OPERATIONAL;
>  	li = &dst_vcpu->arch.local_int;
>  	spin_lock_bh(&li->lock);
>  	list_add_tail(&inti->list, &li->list);
>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PULL 1/4] KVM: s390: randomize sca address
  2014-03-25 13:53   ` Paolo Bonzini
@ 2014-03-25 14:04     ` Christian Borntraeger
  0 siblings, 0 replies; 13+ messages in thread
From: Christian Borntraeger @ 2014-03-25 14:04 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: KVM, linux-s390, Cornelia Huck

On 25/03/14 14:53, Paolo Bonzini wrote:
> Il 25/03/2014 14:35, Christian Borntraeger ha scritto:
>> We allocate a page for the 2k sca, so lets use the space to improve
>> hit rate of some internal cpu caches. No need to change the freeing
>> of the page, as this will shift away the page offset bits anyway.
>>
>> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
>> Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
>> ---
>>  arch/s390/kvm/kvm-s390.c | 5 +++++
>>  1 file changed, 5 insertions(+)
>>
>> diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
>> index 7337c57..a02979f 100644
>> --- a/arch/s390/kvm/kvm-s390.c
>> +++ b/arch/s390/kvm/kvm-s390.c
>> @@ -215,6 +215,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
>>  {
>>      int rc;
>>      char debug_name[16];
>> +    static unsigned long sca_offset;
>>
>>      rc = -EINVAL;
>>  #ifdef CONFIG_KVM_S390_UCONTROL
>> @@ -236,6 +237,10 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
>>      kvm->arch.sca = (struct sca_block *) get_zeroed_page(GFP_KERNEL);
>>      if (!kvm->arch.sca)
>>          goto out_err;
>> +    spin_lock(&kvm_lock);
>> +    sca_offset = (sca_offset + 16) & 0x7f0;
>> +    kvm->arch.sca = (struct sca_block *) ((char *) kvm->arch.sca + sca_offset);
>> +    spin_unlock(&kvm_lock);
>>
>>      sprintf(debug_name, "kvm-%u", current->pid);
>>
>>
> 
> Does this have to remain the same across migration?

Nope, the sca address is just an internal _host_ detail and does not belong/influence
the guest.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PULL 4/4] KVM: s390: clear local interrupts at cpu initial reset
  2014-03-25 13:56   ` Paolo Bonzini
@ 2014-03-25 14:18     ` Christian Borntraeger
  0 siblings, 0 replies; 13+ messages in thread
From: Christian Borntraeger @ 2014-03-25 14:18 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: KVM, linux-s390, Cornelia Huck, Jens Freimann

On 25/03/14 14:56, Paolo Bonzini wrote:
> Il 25/03/2014 14:35, Christian Borntraeger ha scritto:
>> +    spin_lock_bh(&li->lock);
>> +    list_for_each_entry_safe(inti, n, &li->list, list) {
>> +        list_del(&inti->list);
>> +        kfree(inti);
>> +    }
>> +    atomic_set(&li->active, 0);
>> +    spin_unlock_bh(&li->lock);
>> +}
> 
> Out of curiosity, why the _bh?

Probably just copied from all other accesses. We normally protect against the hrtimer 
wakeup bottom half(see kvm_s390_tasklet). For normal guests/userspace this should not
happen, (after all we are resetting the CPU only on startup or during reset when the vCPUS
are nor running) but the KVM interface allows to trigger this while the CPU is waiting
for a timer.

In fact I think your question just made me realize that this code needs some more
fixes, e.g. resetting the timer on initial reset and getting the CPU out of wait.
Will investigate.

Christian



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PULL 3/4] KVM: s390: Fix possible memory leak in SIGP functions
  2014-03-25 14:02   ` Paolo Bonzini
@ 2014-03-25 14:39     ` Christian Borntraeger
  2014-03-25 14:43       ` Paolo Bonzini
  0 siblings, 1 reply; 13+ messages in thread
From: Christian Borntraeger @ 2014-03-25 14:39 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: KVM, linux-s390, Cornelia Huck, Thomas Huth

On 25/03/14 15:02, Paolo Bonzini wrote:
> Il 25/03/2014 14:35, Christian Borntraeger ha scritto:
>> From: Thomas Huth <thuth@linux.vnet.ibm.com>
>>
>> When kvm_get_vcpu() returned NULL for the destination CPU in
>> __sigp_emergency() or __sigp_external_call(), the memory for the
>> "inti" structure was not released anymore. This patch fixes this
>> issue by moving the check for !dst_vcpu before the kzalloc() call.
>>
>> Signed-off-by: Thomas Huth <thuth@linux.vnet.ibm.com>
>> Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
>> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> 
> Should patch 2 and this one have a Cc: stable?

This bug is not yet in 3.14-rc
It is only in kvm/next via commit  1ee0bc559dc34fe36a29494faf7b7c91533bd31c ( KVM: s390: get rid of local_int array)
So no need for stable.
patch 2 just reduces the memory usage from 64 bytes to 8 bytes.
Dont think we should use the stable folks for that.

Christian


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PULL 3/4] KVM: s390: Fix possible memory leak in SIGP functions
  2014-03-25 14:39     ` Christian Borntraeger
@ 2014-03-25 14:43       ` Paolo Bonzini
  0 siblings, 0 replies; 13+ messages in thread
From: Paolo Bonzini @ 2014-03-25 14:43 UTC (permalink / raw)
  To: Christian Borntraeger; +Cc: KVM, linux-s390, Cornelia Huck, Thomas Huth

Il 25/03/2014 15:39, Christian Borntraeger ha scritto:
> This bug is not yet in 3.14-rc
> It is only in kvm/next via commit  1ee0bc559dc34fe36a29494faf7b7c91533bd31c ( KVM: s390: get rid of local_int array)
> So no need for stable.
> patch 2 just reduces the memory usage from 64 bytes to 8 bytes.
> Dont think we should use the stable folks for that.

Ok.  Then I can apply this pull request!  Thanks for explaining it to me.

Paolo

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2014-03-25 19:05 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-25 13:35 [PULL 0/4] KVM: s390: last fixes for next merge window Christian Borntraeger
2014-03-25 13:35 ` [PULL 1/4] KVM: s390: randomize sca address Christian Borntraeger
2014-03-25 13:53   ` Paolo Bonzini
2014-03-25 14:04     ` Christian Borntraeger
2014-03-25 13:35 ` [PULL 2/4] KVM: s390: fix calculation of idle_mask array size Christian Borntraeger
2014-03-25 13:55   ` Paolo Bonzini
2014-03-25 13:35 ` [PULL 3/4] KVM: s390: Fix possible memory leak in SIGP functions Christian Borntraeger
2014-03-25 14:02   ` Paolo Bonzini
2014-03-25 14:39     ` Christian Borntraeger
2014-03-25 14:43       ` Paolo Bonzini
2014-03-25 13:35 ` [PULL 4/4] KVM: s390: clear local interrupts at cpu initial reset Christian Borntraeger
2014-03-25 13:56   ` Paolo Bonzini
2014-03-25 14:18     ` Christian Borntraeger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).