* [patch 0/4] Fixes for kvm-s390
@ 2011-10-18 10:27 Christian Borntraeger
2011-10-18 10:27 ` [patch 1/4] kvm-s390: check cpu_id prior to using it Christian Borntraeger
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Christian Borntraeger @ 2011-10-18 10:27 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tossati
Cc: Carsten Otte, Heiko Carstens, Martin Schwidefsky, KVM
Avi, Marcelo,
here are 4 fixes for kvm on s390:
1. check cpu_id prior to using it
2. fix return value of kvm_arch_init_vm
3. fix register setting
4. implement sigp external call
All patches have been tested in house and should be ok for the next
merge windows. Patch 1 fixes a potential index overrun, but stable
should be the right way to go so late in the release cycle.
Christian
^ permalink raw reply [flat|nested] 6+ messages in thread
* [patch 1/4] kvm-s390: check cpu_id prior to using it
2011-10-18 10:27 [patch 0/4] Fixes for kvm-s390 Christian Borntraeger
@ 2011-10-18 10:27 ` Christian Borntraeger
2011-10-18 10:27 ` [patch 2/4] kvm-s390: fix return value of kvm_arch_init_vm Christian Borntraeger
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Christian Borntraeger @ 2011-10-18 10:27 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tossati
Cc: Carsten Otte, Heiko Carstens, Martin Schwidefsky, KVM, stable,
Christian Borntraeger
[-- Attachment #1: 500-kvm-check-cpuid.diff --]
[-- Type: text/plain, Size: 1262 bytes --]
From: Carsten Otte <cotte@de.ibm.com>
We use the cpu id provided by userspace as array index here. Thus we
clearly need to check it first. Ooops.
CC: <stable@vger.kernel.org>
Signed-off-by: Carsten Otte <cotte@de.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
arch/s390/kvm/kvm-s390.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
Index: b/arch/s390/kvm/kvm-s390.c
===================================================================
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -312,11 +312,17 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu
struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm,
unsigned int id)
{
- struct kvm_vcpu *vcpu = kzalloc(sizeof(struct kvm_vcpu), GFP_KERNEL);
- int rc = -ENOMEM;
+ struct kvm_vcpu *vcpu;
+ int rc = -EINVAL;
+ if (id >= KVM_MAX_VCPUS)
+ goto out;
+
+ rc = -ENOMEM;
+
+ vcpu = kzalloc(sizeof(struct kvm_vcpu), GFP_KERNEL);
if (!vcpu)
- goto out_nomem;
+ goto out;
vcpu->arch.sie_block = (struct kvm_s390_sie_block *)
get_zeroed_page(GFP_KERNEL);
@@ -352,7 +358,7 @@ out_free_sie_block:
free_page((unsigned long)(vcpu->arch.sie_block));
out_free_cpu:
kfree(vcpu);
-out_nomem:
+out:
return ERR_PTR(rc);
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* [patch 2/4] kvm-s390: fix return value of kvm_arch_init_vm
2011-10-18 10:27 [patch 0/4] Fixes for kvm-s390 Christian Borntraeger
2011-10-18 10:27 ` [patch 1/4] kvm-s390: check cpu_id prior to using it Christian Borntraeger
@ 2011-10-18 10:27 ` Christian Borntraeger
2011-10-18 10:27 ` [patch 3/4] kvm-s390: fix register setting Christian Borntraeger
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Christian Borntraeger @ 2011-10-18 10:27 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tossati
Cc: Carsten Otte, Heiko Carstens, Martin Schwidefsky, KVM,
Christian Borntraeger
[-- Attachment #1: 501-kvm-arch_init_vm.diff --]
[-- Type: text/plain, Size: 695 bytes --]
From: Carsten Otte <cotte@de.ibm.com>
This patch fixes the return value of kvm_arch_init_vm in case a memory
allocation goes wrong.
Signed-off-by: Carsten Otte <cotte@de.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
arch/s390/kvm/kvm-s390.c | 2 ++
1 file changed, 2 insertions(+)
Index: b/arch/s390/kvm/kvm-s390.c
===================================================================
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -175,6 +175,8 @@ int kvm_arch_init_vm(struct kvm *kvm)
if (rc)
goto out_err;
+ rc = -ENOMEM;
+
kvm->arch.sca = (struct sca_block *) get_zeroed_page(GFP_KERNEL);
if (!kvm->arch.sca)
goto out_err;
^ permalink raw reply [flat|nested] 6+ messages in thread
* [patch 3/4] kvm-s390: fix register setting
2011-10-18 10:27 [patch 0/4] Fixes for kvm-s390 Christian Borntraeger
2011-10-18 10:27 ` [patch 1/4] kvm-s390: check cpu_id prior to using it Christian Borntraeger
2011-10-18 10:27 ` [patch 2/4] kvm-s390: fix return value of kvm_arch_init_vm Christian Borntraeger
@ 2011-10-18 10:27 ` Christian Borntraeger
2011-10-18 10:27 ` [patch 4/4] kvm-s390: implement sigp external call Christian Borntraeger
2011-10-19 16:21 ` [patch 0/4] Fixes for kvm-s390 Marcelo Tosatti
4 siblings, 0 replies; 6+ messages in thread
From: Christian Borntraeger @ 2011-10-18 10:27 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tossati
Cc: Carsten Otte, Heiko Carstens, Martin Schwidefsky, KVM,
Christian Borntraeger
[-- Attachment #1: 502-kvm-register-setting.diff --]
[-- Type: text/plain, Size: 1686 bytes --]
From: Carsten Otte <cotte@de.ibm.com>
KVM common code does vcpu_load prior to calling our arch ioctls and
vcpu_put after we're done here. Via the kvm_arch_vcpu_load/put
callbacks we do load the fpu and access register state into the
processor, which saves us moving the state on every SIE exit the
kernel handles. However this breaks register setting from userspace,
because of the following sequence:
1a. vcpu load stores userspace register content
1b. vcpu load loads guest register content
2. kvm_arch_vcpu_ioctl_set_fpu/sregs updates saved guest register content
3a. vcpu put stores the guest registers and overwrites the new content
3b. vcpu put loads the userspace register set again
This patch loads the new guest register state into the cpu, so that the correct
(new) set of guest registers will be stored in step 3a.
Signed-off-by: Carsten Otte <cotte@de.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
arch/s390/kvm/kvm-s390.c | 2 ++
1 file changed, 2 insertions(+)
Index: b/arch/s390/kvm/kvm-s390.c
===================================================================
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -394,6 +394,7 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct
{
memcpy(&vcpu->arch.guest_acrs, &sregs->acrs, sizeof(sregs->acrs));
memcpy(&vcpu->arch.sie_block->gcr, &sregs->crs, sizeof(sregs->crs));
+ restore_access_regs(vcpu->arch.guest_acrs);
return 0;
}
@@ -409,6 +410,7 @@ int kvm_arch_vcpu_ioctl_set_fpu(struct k
{
memcpy(&vcpu->arch.guest_fpregs.fprs, &fpu->fprs, sizeof(fpu->fprs));
vcpu->arch.guest_fpregs.fpc = fpu->fpc;
+ restore_fp_regs(&vcpu->arch.guest_fpregs);
return 0;
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* [patch 4/4] kvm-s390: implement sigp external call
2011-10-18 10:27 [patch 0/4] Fixes for kvm-s390 Christian Borntraeger
` (2 preceding siblings ...)
2011-10-18 10:27 ` [patch 3/4] kvm-s390: fix register setting Christian Borntraeger
@ 2011-10-18 10:27 ` Christian Borntraeger
2011-10-19 16:21 ` [patch 0/4] Fixes for kvm-s390 Marcelo Tosatti
4 siblings, 0 replies; 6+ messages in thread
From: Christian Borntraeger @ 2011-10-18 10:27 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tossati
Cc: Carsten Otte, Heiko Carstens, Martin Schwidefsky, KVM,
Christian Ehrhardt, Christian Borntraeger
[-- Attachment #1: 503-kvm-external-call.diff --]
[-- Type: text/plain, Size: 7668 bytes --]
From: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
Implement sigp external call, which might be required for guests that
issue an external call instead of an emergency signal for IPI.
This fixes an issue with "KVM: unknown SIGP: 0x02" when booting
such an SMP guest.
Signed-off-by: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
---
arch/s390/include/asm/kvm_host.h | 7 ++++++
arch/s390/kvm/interrupt.c | 30 ++++++++++++++++++++++++++
arch/s390/kvm/kvm-s390.c | 2 +
arch/s390/kvm/sigp.c | 45 ++++++++++++++++++++++++++++++++++++++-
include/linux/kvm.h | 1
5 files changed, 84 insertions(+), 1 deletion(-)
Index: b/arch/s390/include/asm/kvm_host.h
===================================================================
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -119,6 +119,7 @@ struct kvm_vcpu_stat {
u32 instruction_lctlg;
u32 exit_program_interruption;
u32 exit_instr_and_program;
+ u32 deliver_external_call;
u32 deliver_emergency_signal;
u32 deliver_service_signal;
u32 deliver_virtio_interrupt;
@@ -138,6 +139,7 @@ struct kvm_vcpu_stat {
u32 instruction_stfl;
u32 instruction_tprot;
u32 instruction_sigp_sense;
+ u32 instruction_sigp_external_call;
u32 instruction_sigp_emergency;
u32 instruction_sigp_stop;
u32 instruction_sigp_arch;
@@ -174,6 +176,10 @@ struct kvm_s390_prefix_info {
__u32 address;
};
+struct kvm_s390_extcall_info {
+ __u16 code;
+};
+
struct kvm_s390_emerg_info {
__u16 code;
};
@@ -186,6 +192,7 @@ struct kvm_s390_interrupt_info {
struct kvm_s390_ext_info ext;
struct kvm_s390_pgm_info pgm;
struct kvm_s390_emerg_info emerg;
+ struct kvm_s390_extcall_info extcall;
struct kvm_s390_prefix_info prefix;
};
};
Index: b/arch/s390/kvm/interrupt.c
===================================================================
--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -38,6 +38,11 @@ static int __interrupt_is_deliverable(st
struct kvm_s390_interrupt_info *inti)
{
switch (inti->type) {
+ case KVM_S390_INT_EXTERNAL_CALL:
+ if (psw_extint_disabled(vcpu))
+ return 0;
+ if (vcpu->arch.sie_block->gcr[0] & 0x2000ul)
+ return 1;
case KVM_S390_INT_EMERGENCY:
if (psw_extint_disabled(vcpu))
return 0;
@@ -98,6 +103,7 @@ static void __set_intercept_indicator(st
struct kvm_s390_interrupt_info *inti)
{
switch (inti->type) {
+ case KVM_S390_INT_EXTERNAL_CALL:
case KVM_S390_INT_EMERGENCY:
case KVM_S390_INT_SERVICE:
case KVM_S390_INT_VIRTIO:
@@ -143,6 +149,28 @@ static void __do_deliver_interrupt(struc
exception = 1;
break;
+ case KVM_S390_INT_EXTERNAL_CALL:
+ VCPU_EVENT(vcpu, 4, "%s", "interrupt: sigp ext call");
+ vcpu->stat.deliver_external_call++;
+ rc = put_guest_u16(vcpu, __LC_EXT_INT_CODE, 0x1202);
+ if (rc == -EFAULT)
+ exception = 1;
+
+ rc = put_guest_u16(vcpu, __LC_CPU_ADDRESS, inti->extcall.code);
+ if (rc == -EFAULT)
+ exception = 1;
+
+ rc = copy_to_guest(vcpu, __LC_EXT_OLD_PSW,
+ &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
+ if (rc == -EFAULT)
+ exception = 1;
+
+ rc = copy_from_guest(vcpu, &vcpu->arch.sie_block->gpsw,
+ __LC_EXT_NEW_PSW, sizeof(psw_t));
+ if (rc == -EFAULT)
+ exception = 1;
+ break;
+
case KVM_S390_INT_SERVICE:
VCPU_EVENT(vcpu, 4, "interrupt: sclp parm:%x",
inti->ext.ext_params);
@@ -522,6 +550,7 @@ int kvm_s390_inject_vm(struct kvm *kvm,
break;
case KVM_S390_PROGRAM_INT:
case KVM_S390_SIGP_STOP:
+ case KVM_S390_INT_EXTERNAL_CALL:
case KVM_S390_INT_EMERGENCY:
default:
kfree(inti);
@@ -581,6 +610,7 @@ int kvm_s390_inject_vcpu(struct kvm_vcpu
break;
case KVM_S390_SIGP_STOP:
case KVM_S390_RESTART:
+ case KVM_S390_INT_EXTERNAL_CALL:
case KVM_S390_INT_EMERGENCY:
VCPU_EVENT(vcpu, 3, "inject: type %x", s390int->type);
inti->type = s390int->type;
Index: b/arch/s390/kvm/kvm-s390.c
===================================================================
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -46,6 +46,7 @@ struct kvm_stats_debugfs_item debugfs_en
{ "instruction_lctlg", VCPU_STAT(instruction_lctlg) },
{ "instruction_lctl", VCPU_STAT(instruction_lctl) },
{ "deliver_emergency_signal", VCPU_STAT(deliver_emergency_signal) },
+ { "deliver_external_call", VCPU_STAT(deliver_external_call) },
{ "deliver_service_signal", VCPU_STAT(deliver_service_signal) },
{ "deliver_virtio_interrupt", VCPU_STAT(deliver_virtio_interrupt) },
{ "deliver_stop_signal", VCPU_STAT(deliver_stop_signal) },
@@ -64,6 +65,7 @@ struct kvm_stats_debugfs_item debugfs_en
{ "instruction_stfl", VCPU_STAT(instruction_stfl) },
{ "instruction_tprot", VCPU_STAT(instruction_tprot) },
{ "instruction_sigp_sense", VCPU_STAT(instruction_sigp_sense) },
+ { "instruction_sigp_external_call", VCPU_STAT(instruction_sigp_external_call) },
{ "instruction_sigp_emergency", VCPU_STAT(instruction_sigp_emergency) },
{ "instruction_sigp_stop", VCPU_STAT(instruction_sigp_stop) },
{ "instruction_sigp_set_arch", VCPU_STAT(instruction_sigp_arch) },
Index: b/arch/s390/kvm/sigp.c
===================================================================
--- a/arch/s390/kvm/sigp.c
+++ b/arch/s390/kvm/sigp.c
@@ -87,6 +87,7 @@ static int __sigp_emergency(struct kvm_v
return -ENOMEM;
inti->type = KVM_S390_INT_EMERGENCY;
+ inti->emerg.code = vcpu->vcpu_id;
spin_lock(&fi->lock);
li = fi->local_int[cpu_addr];
@@ -103,9 +104,47 @@ static int __sigp_emergency(struct kvm_v
wake_up_interruptible(&li->wq);
spin_unlock_bh(&li->lock);
rc = 0; /* order accepted */
+ VCPU_EVENT(vcpu, 4, "sent sigp emerg to cpu %x", cpu_addr);
+unlock:
+ spin_unlock(&fi->lock);
+ return rc;
+}
+
+static int __sigp_external_call(struct kvm_vcpu *vcpu, u16 cpu_addr)
+{
+ struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int;
+ struct kvm_s390_local_interrupt *li;
+ struct kvm_s390_interrupt_info *inti;
+ int rc;
+
+ if (cpu_addr >= KVM_MAX_VCPUS)
+ return 3; /* not operational */
+
+ inti = kzalloc(sizeof(*inti), GFP_KERNEL);
+ if (!inti)
+ return -ENOMEM;
+
+ inti->type = KVM_S390_INT_EXTERNAL_CALL;
+ inti->extcall.code = vcpu->vcpu_id;
+
+ spin_lock(&fi->lock);
+ li = fi->local_int[cpu_addr];
+ if (li == NULL) {
+ rc = 3; /* not operational */
+ kfree(inti);
+ goto unlock;
+ }
+ spin_lock_bh(&li->lock);
+ list_add_tail(&inti->list, &li->list);
+ atomic_set(&li->active, 1);
+ atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags);
+ if (waitqueue_active(&li->wq))
+ wake_up_interruptible(&li->wq);
+ spin_unlock_bh(&li->lock);
+ rc = 0; /* order accepted */
+ VCPU_EVENT(vcpu, 4, "sent sigp ext call to cpu %x", cpu_addr);
unlock:
spin_unlock(&fi->lock);
- VCPU_EVENT(vcpu, 4, "sent sigp emerg to cpu %x", cpu_addr);
return rc;
}
@@ -267,6 +306,10 @@ int kvm_s390_handle_sigp(struct kvm_vcpu
rc = __sigp_sense(vcpu, cpu_addr,
&vcpu->arch.guest_gprs[r1]);
break;
+ case SIGP_EXTERNAL_CALL:
+ vcpu->stat.instruction_sigp_external_call++;
+ rc = __sigp_external_call(vcpu, cpu_addr);
+ break;
case SIGP_EMERGENCY:
vcpu->stat.instruction_sigp_emergency++;
rc = __sigp_emergency(vcpu, cpu_addr);
Index: b/include/linux/kvm.h
===================================================================
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -371,6 +371,7 @@ struct kvm_s390_psw {
#define KVM_S390_INT_VIRTIO 0xffff2603u
#define KVM_S390_INT_SERVICE 0xffff2401u
#define KVM_S390_INT_EMERGENCY 0xffff1201u
+#define KVM_S390_INT_EXTERNAL_CALL 0xffff1202u
struct kvm_s390_interrupt {
__u32 type;
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch 0/4] Fixes for kvm-s390
2011-10-18 10:27 [patch 0/4] Fixes for kvm-s390 Christian Borntraeger
` (3 preceding siblings ...)
2011-10-18 10:27 ` [patch 4/4] kvm-s390: implement sigp external call Christian Borntraeger
@ 2011-10-19 16:21 ` Marcelo Tosatti
4 siblings, 0 replies; 6+ messages in thread
From: Marcelo Tosatti @ 2011-10-19 16:21 UTC (permalink / raw)
To: Christian Borntraeger
Cc: Avi Kivity, Carsten Otte, Heiko Carstens, Martin Schwidefsky, KVM
On Tue, Oct 18, 2011 at 12:27:11PM +0200, Christian Borntraeger wrote:
> Avi, Marcelo,
>
> here are 4 fixes for kvm on s390:
> 1. check cpu_id prior to using it
> 2. fix return value of kvm_arch_init_vm
> 3. fix register setting
> 4. implement sigp external call
>
> All patches have been tested in house and should be ok for the next
> merge windows. Patch 1 fixes a potential index overrun, but stable
> should be the right way to go so late in the release cycle.
>
> Christian
Applied, thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-10-19 17:28 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-18 10:27 [patch 0/4] Fixes for kvm-s390 Christian Borntraeger
2011-10-18 10:27 ` [patch 1/4] kvm-s390: check cpu_id prior to using it Christian Borntraeger
2011-10-18 10:27 ` [patch 2/4] kvm-s390: fix return value of kvm_arch_init_vm Christian Borntraeger
2011-10-18 10:27 ` [patch 3/4] kvm-s390: fix register setting Christian Borntraeger
2011-10-18 10:27 ` [patch 4/4] kvm-s390: implement sigp external call Christian Borntraeger
2011-10-19 16:21 ` [patch 0/4] Fixes for kvm-s390 Marcelo Tosatti
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).