Skip to contentSkip to conversation

s390x/kvm: call cpu_synchronize_state() on every kvm_arch_handle_exit()

PATCH In review David Hildenbrand 4 participants 6 messages Apr 6, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 s390x/kvm: call cpu_synchronize_state() on every kvm_arch_handle_exit()

Manually having to use cpu_synchronize_state() is error prone. And as Christian Borntraeger discovered, e.g. handle_diag() is currently missing a cpu_synchronize_state(), as decode_basedisp_s() uses a general purpose register value internally.

So let's do an overall cpu_synchronize_state(), which fixes at least the one mentioned BUG. We will clean up the superfluous cpu_synchronize_state() calls later.

We now also call it (although maybe not neded) for
- KVM_EXIT_S390_RESET -> s390_reipl_request()
- KVM_EXIT_DEBUG -> kvm_arch_handle_debug_exit()
- unmanagable/unimplemented intercepts
- ICPT_CPU_STOP -> do_stop_interrupt() -> cpu gets halted
- Scenarios where we inject an operation exception
- handle_stsi()

I don't think any of these are performance critical. Especially as we have all information directly contained in kvm_run, there are no additional IOCTLs to issue on modern kernels.

---
 target/s390x/kvm.c | 2 ++
 1 file changed, 2 insertions(+)
target/s390x/kvm.c +2 -0
index f570896dc1..fb59d92def 100644
@@ -1778,6 +1778,8 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
 
     qemu_mutex_lock_iothread();
 
+    cpu_synchronize_state(cs);
+
     switch (run->exit_reason) {
         case KVM_EXIT_S390_SIEIC:
             ret = handle_intercept(cpu);
Signature · 1 line
2.14.3
#1 lore raw
Quoted 31 lines · David Hildenbrand

Manually having to use cpu_synchronize_state() is error prone. And as Christian Borntraeger discovered, e.g. handle_diag() is currently missing a cpu_synchronize_state(), as decode_basedisp_s() uses a general purpose register value internally.

So let's do an overall cpu_synchronize_state(), which fixes at least the one mentioned BUG. We will clean up the superfluous cpu_synchronize_state() calls later.

We now also call it (although maybe not neded) for
- KVM_EXIT_S390_RESET -> s390_reipl_request()
- KVM_EXIT_DEBUG -> kvm_arch_handle_debug_exit()
- unmanagable/unimplemented intercepts
- ICPT_CPU_STOP -> do_stop_interrupt() -> cpu gets halted
- Scenarios where we inject an operation exception
- handle_stsi()

I don't think any of these are performance critical. Especially as we have all information directly contained in kvm_run, there are no additional IOCTLs to issue on modern kernels.

---
 target/s390x/kvm.c | 2 ++
 1 file changed, 2 insertions(+)
target/s390x/kvm.c +0 -0
index f570896dc1..fb59d92def 100644

target/s390x/kvm.c int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) · line 1781

Quoted 4 lines
target/s390x/kvm.c +1 -0
@@ -1778,6 +1778,8 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
 
     qemu_mutex_lock_iothread();
 
+    cpu_synchronize_state(cs);

Since we're in kvm.c here, maybe rather call kvm_cpu_synchronize_state() directly to avoid the wrapper function?

Thomas

#2 lore raw
Quoted 33 lines · Thomas Huth
Quoted 32 lines · David Hildenbrand

Manually having to use cpu_synchronize_state() is error prone. And as Christian Borntraeger discovered, e.g. handle_diag() is currently missing a cpu_synchronize_state(), as decode_basedisp_s() uses a general purpose register value internally.

So let's do an overall cpu_synchronize_state(), which fixes at least the one mentioned BUG. We will clean up the superfluous cpu_synchronize_state() calls later.

We now also call it (although maybe not neded) for
- KVM_EXIT_S390_RESET -> s390_reipl_request()
- KVM_EXIT_DEBUG -> kvm_arch_handle_debug_exit()
- unmanagable/unimplemented intercepts
- ICPT_CPU_STOP -> do_stop_interrupt() -> cpu gets halted
- Scenarios where we inject an operation exception
- handle_stsi()

I don't think any of these are performance critical. Especially as we have all information directly contained in kvm_run, there are no additional IOCTLs to issue on modern kernels.

---
 target/s390x/kvm.c | 2 ++
 1 file changed, 2 insertions(+)
target/s390x/kvm.c +0 -0
index f570896dc1..fb59d92def 100644
@@ -1778,6 +1778,8 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
 
Quoted 9 lines

target/s390x/kvm.c int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) · line 1781

Quoted 3 lines
target/s390x/kvm.c +1 -0
     qemu_mutex_lock_iothread();
 
+    cpu_synchronize_state(cs);

Since we're in kvm.c here, maybe rather call kvm_cpu_synchronize_state() directly to avoid the wrapper function?

Thomas

No strong opinion. I can see that kvm_cpu_synchronize_state()
- is not used in target/s390x/kvm.c yet
- is very rarely used in kvm code in general

Signature · 3 lines
Thanks,

David / dhildenb
#3 lore raw
Quoted 41 lines · On Fri, 6 Apr 2018 11:46:22 +0200 David Hildenbrand <[email protected]> wrote:
Quoted 40 lines · Thomas Huth
Quoted 31 lines · David Hildenbrand

Manually having to use cpu_synchronize_state() is error prone. And as Christian Borntraeger discovered, e.g. handle_diag() is currently missing a cpu_synchronize_state(), as decode_basedisp_s() uses a general purpose register value internally.

So let's do an overall cpu_synchronize_state(), which fixes at least the one mentioned BUG. We will clean up the superfluous cpu_synchronize_state() calls later.

We now also call it (although maybe not neded) for
- KVM_EXIT_S390_RESET -> s390_reipl_request()
- KVM_EXIT_DEBUG -> kvm_arch_handle_debug_exit()
- unmanagable/unimplemented intercepts
- ICPT_CPU_STOP -> do_stop_interrupt() -> cpu gets halted
- Scenarios where we inject an operation exception
- handle_stsi()

I don't think any of these are performance critical. Especially as we have all information directly contained in kvm_run, there are no additional IOCTLs to issue on modern kernels.

---
 target/s390x/kvm.c | 2 ++
 1 file changed, 2 insertions(+)
target/s390x/kvm.c +0 -0
index f570896dc1..fb59d92def 100644

target/s390x/kvm.c int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) · line 1781

Quoted 4 lines
target/s390x/kvm.c +1 -0
@@ -1778,6 +1778,8 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
 
     qemu_mutex_lock_iothread();
 
+    cpu_synchronize_state(cs);  

Since we're in kvm.c here, maybe rather call kvm_cpu_synchronize_state() directly to avoid the wrapper function?

Quoted 7 lines
Quoted 2 lines

Thomas

No strong opinion. I can see that kvm_cpu_synchronize_state()
- is not used in target/s390x/kvm.c yet
- is very rarely used in kvm code in general

Let's just go with this one for 2.12? If we want to switch to the kvm_* variant, we can still do it for 2.13.

Acked-by on v1 1/1
#4 lore raw
In reply to David Hildenbrand
Quoted 17 lines · David Hildenbrand

Manually having to use cpu_synchronize_state() is error prone. And as Christian Borntraeger discovered, e.g. handle_diag() is currently missing a cpu_synchronize_state(), as decode_basedisp_s() uses a general purpose register value internally.

So let's do an overall cpu_synchronize_state(), which fixes at least the one mentioned BUG. We will clean up the superfluous cpu_synchronize_state() calls later.

We now also call it (although maybe not neded) for
- KVM_EXIT_S390_RESET -> s390_reipl_request()
- KVM_EXIT_DEBUG -> kvm_arch_handle_debug_exit()
- unmanagable/unimplemented intercepts
- ICPT_CPU_STOP -> do_stop_interrupt() -> cpu gets halted
- Scenarios where we inject an operation exception
- handle_stsi()

Quoted 5 lines

I don't think any of these are performance critical. Especially as we have all information directly contained in kvm_run, there are no additional IOCTLs to issue on modern kernels.

ok for 2.12.

Quoted 18 lines
---
 target/s390x/kvm.c | 2 ++
 1 file changed, 2 insertions(+)
target/s390x/kvm.c +2 -0
index f570896dc1..fb59d92def 100644
@@ -1778,6 +1778,8 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
 
     qemu_mutex_lock_iothread();
 
+    cpu_synchronize_state(cs);
+
     switch (run->exit_reason) {
         case KVM_EXIT_S390_SIEIC:
             ret = handle_intercept(cpu);
#5 lore raw
In reply to David Hildenbrand
Quoted 31 lines · On Fri, 6 Apr 2018 11:35:52 +0200 David Hildenbrand <[email protected]> wrote:

Manually having to use cpu_synchronize_state() is error prone. And as Christian Borntraeger discovered, e.g. handle_diag() is currently missing a cpu_synchronize_state(), as decode_basedisp_s() uses a general purpose register value internally.

So let's do an overall cpu_synchronize_state(), which fixes at least the one mentioned BUG. We will clean up the superfluous cpu_synchronize_state() calls later.

We now also call it (although maybe not neded) for
- KVM_EXIT_S390_RESET -> s390_reipl_request()
- KVM_EXIT_DEBUG -> kvm_arch_handle_debug_exit()
- unmanagable/unimplemented intercepts
- ICPT_CPU_STOP -> do_stop_interrupt() -> cpu gets halted
- Scenarios where we inject an operation exception
- handle_stsi()

I don't think any of these are performance critical. Especially as we have all information directly contained in kvm_run, there are no additional IOCTLs to issue on modern kernels.

---
 target/s390x/kvm.c | 2 ++
 1 file changed, 2 insertions(+)
target/s390x/kvm.c +0 -0
index f570896dc1..fb59d92def 100644

target/s390x/kvm.c int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) · line 1785

Quoted 8 lines
target/s390x/kvm.c +2 -0
@@ -1778,6 +1778,8 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
 
     qemu_mutex_lock_iothread();
 
+    cpu_synchronize_state(cs);
+
     switch (run->exit_reason) {
         case KVM_EXIT_S390_SIEIC:
             ret = handle_intercept(cpu);

Thanks, queued to s390-fixes.