* [Qemu-devel] [PATCH 0/2] Pending MTTCG patches
@ 2017-06-29 7:11 Pranith Kumar
2017-06-29 7:11 ` [Qemu-devel] [PATCH v3 1/2] Revert "exec.c: Fix breakpoint invalidation race" Pranith Kumar
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Pranith Kumar @ 2017-06-29 7:11 UTC (permalink / raw)
To: alex.bennee; +Cc: qemu-devel, rth, pbonzini, ehabkost
Hello,
Please find these two pending MTTCG fixes I have in my repo.
I've reworked the async_safe_* patch according to pbonzini's suggestion.
Thanks,
Pranith Kumar (2):
Revert "exec.c: Fix breakpoint invalidation race"
mttcg/i386: Patch instruction using async_safe_* framework
exec.c | 25 ++++++++++++++-----
hw/i386/kvmvapic.c | 73 +++++++++++++++++++++++++++++++-----------------------
2 files changed, 61 insertions(+), 37 deletions(-)
--
2.13.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Qemu-devel] [PATCH v3 1/2] Revert "exec.c: Fix breakpoint invalidation race"
2017-06-29 7:11 [Qemu-devel] [PATCH 0/2] Pending MTTCG patches Pranith Kumar
@ 2017-06-29 7:11 ` Pranith Kumar
2017-06-29 7:11 ` [Qemu-devel] [PATCH v3 2/2] mttcg/i386: Patch instruction using async_safe_* framework Pranith Kumar
2017-07-06 23:49 ` [Qemu-devel] [PATCH 0/2] Pending MTTCG patches no-reply
2 siblings, 0 replies; 7+ messages in thread
From: Pranith Kumar @ 2017-06-29 7:11 UTC (permalink / raw)
To: alex.bennee; +Cc: qemu-devel, rth, pbonzini, ehabkost, Peter Maydell
Now that we have proper locking after MTTCG patches have landed, we
can revert the commit. This reverts commit
a9353fe897ca2687e5b3385ed39e3db3927a90e0.
CC: Peter Maydell <peter.maydell@linaro.org>
CC: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Pranith Kumar <bobby.prani@gmail.com>
---
exec.c | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/exec.c b/exec.c
index 42ad1eaedd..c8403baa46 100644
--- a/exec.c
+++ b/exec.c
@@ -770,15 +770,28 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp)
#endif
}
+#if defined(CONFIG_USER_ONLY)
static void breakpoint_invalidate(CPUState *cpu, target_ulong pc)
{
- /* Flush the whole TB as this will not have race conditions
- * even if we don't have proper locking yet.
- * Ideally we would just invalidate the TBs for the
- * specified PC.
- */
- tb_flush(cpu);
+ mmap_lock();
+ tb_lock();
+ tb_invalidate_phys_page_range(pc, pc + 1, 0);
+ tb_unlock();
+ mmap_unlock();
}
+#else
+static void breakpoint_invalidate(CPUState *cpu, target_ulong pc)
+{
+ MemTxAttrs attrs;
+ hwaddr phys = cpu_get_phys_page_attrs_debug(cpu, pc, &attrs);
+ int asidx = cpu_asidx_from_attrs(cpu, attrs);
+ if (phys != -1) {
+ /* Locks grabbed by tb_invalidate_phys_addr */
+ tb_invalidate_phys_addr(cpu->cpu_ases[asidx].as,
+ phys | (pc & ~TARGET_PAGE_MASK));
+ }
+}
+#endif
#if defined(CONFIG_USER_ONLY)
void cpu_watchpoint_remove_all(CPUState *cpu, int mask)
--
2.13.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [Qemu-devel] [PATCH v3 2/2] mttcg/i386: Patch instruction using async_safe_* framework
2017-06-29 7:11 [Qemu-devel] [PATCH 0/2] Pending MTTCG patches Pranith Kumar
2017-06-29 7:11 ` [Qemu-devel] [PATCH v3 1/2] Revert "exec.c: Fix breakpoint invalidation race" Pranith Kumar
@ 2017-06-29 7:11 ` Pranith Kumar
2017-07-07 10:02 ` Alex Bennée
2017-07-07 10:26 ` Paolo Bonzini
2017-07-06 23:49 ` [Qemu-devel] [PATCH 0/2] Pending MTTCG patches no-reply
2 siblings, 2 replies; 7+ messages in thread
From: Pranith Kumar @ 2017-06-29 7:11 UTC (permalink / raw)
To: alex.bennee; +Cc: qemu-devel, rth, pbonzini, ehabkost, Peter Maydell
In mttcg, calling pause_all_vcpus() during execution from the
generated TBs causes a deadlock if some vCPU is waiting for exclusive
execution in start_exclusive(). Fix this by using the aync_safe_*
framework instead of pausing vcpus for patching instructions.
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Pranith Kumar <bobby.prani@gmail.com>
---
hw/i386/kvmvapic.c | 73 +++++++++++++++++++++++++++++++-----------------------
1 file changed, 42 insertions(+), 31 deletions(-)
diff --git a/hw/i386/kvmvapic.c b/hw/i386/kvmvapic.c
index 82a49556af..5e0c8219b0 100644
--- a/hw/i386/kvmvapic.c
+++ b/hw/i386/kvmvapic.c
@@ -383,8 +383,7 @@ static void patch_byte(X86CPU *cpu, target_ulong addr, uint8_t byte)
cpu_memory_rw_debug(CPU(cpu), addr, &byte, 1, 1);
}
-static void patch_call(VAPICROMState *s, X86CPU *cpu, target_ulong ip,
- uint32_t target)
+static void patch_call(X86CPU *cpu, target_ulong ip, uint32_t target)
{
uint32_t offset;
@@ -393,23 +392,24 @@ static void patch_call(VAPICROMState *s, X86CPU *cpu, target_ulong ip,
cpu_memory_rw_debug(CPU(cpu), ip + 1, (void *)&offset, sizeof(offset), 1);
}
-static void patch_instruction(VAPICROMState *s, X86CPU *cpu, target_ulong ip)
+struct PatchInfo {
+ VAPICHandlers *handler;
+ target_ulong ip;
+};
+
+static void do_patch_instruction(CPUState *cs, run_on_cpu_data data)
{
- CPUState *cs = CPU(cpu);
- CPUX86State *env = &cpu->env;
- VAPICHandlers *handlers;
+ X86CPU *x86_cpu = X86_CPU(cs);
+ CPUX86State *env = &x86_cpu->env;
+ struct PatchInfo *info = (struct PatchInfo *) data.host_ptr;
+ VAPICHandlers *handlers = info->handler;
+ target_ulong ip = info->ip;
uint8_t opcode[2];
uint32_t imm32 = 0;
target_ulong current_pc = 0;
target_ulong current_cs_base = 0;
uint32_t current_flags = 0;
- if (smp_cpus == 1) {
- handlers = &s->rom_state.up;
- } else {
- handlers = &s->rom_state.mp;
- }
-
if (!kvm_enabled()) {
cpu_get_tb_cpu_state(env, ¤t_pc, ¤t_cs_base,
¤t_flags);
@@ -421,48 +421,59 @@ static void patch_instruction(VAPICROMState *s, X86CPU *cpu, target_ulong ip)
}
}
- pause_all_vcpus();
-
cpu_memory_rw_debug(cs, ip, opcode, sizeof(opcode), 0);
switch (opcode[0]) {
case 0x89: /* mov r32 to r/m32 */
- patch_byte(cpu, ip, 0x50 + modrm_reg(opcode[1])); /* push reg */
- patch_call(s, cpu, ip + 1, handlers->set_tpr);
+ patch_byte(x86_cpu, ip, 0x50 + modrm_reg(opcode[1])); /* push reg */
+ patch_call(x86_cpu, ip + 1, handlers->set_tpr);
break;
case 0x8b: /* mov r/m32 to r32 */
- patch_byte(cpu, ip, 0x90);
- patch_call(s, cpu, ip + 1, handlers->get_tpr[modrm_reg(opcode[1])]);
+ patch_byte(x86_cpu, ip, 0x90);
+ patch_call(x86_cpu, ip + 1, handlers->get_tpr[modrm_reg(opcode[1])]);
break;
case 0xa1: /* mov abs to eax */
- patch_call(s, cpu, ip, handlers->get_tpr[0]);
+ patch_call(x86_cpu, ip, handlers->get_tpr[0]);
break;
case 0xa3: /* mov eax to abs */
- patch_call(s, cpu, ip, handlers->set_tpr_eax);
+ patch_call(x86_cpu, ip, handlers->set_tpr_eax);
break;
case 0xc7: /* mov imm32, r/m32 (c7/0) */
- patch_byte(cpu, ip, 0x68); /* push imm32 */
+ patch_byte(x86_cpu, ip, 0x68); /* push imm32 */
cpu_memory_rw_debug(cs, ip + 6, (void *)&imm32, sizeof(imm32), 0);
cpu_memory_rw_debug(cs, ip + 1, (void *)&imm32, sizeof(imm32), 1);
- patch_call(s, cpu, ip + 5, handlers->set_tpr);
+ patch_call(x86_cpu, ip + 5, handlers->set_tpr);
break;
case 0xff: /* push r/m32 */
- patch_byte(cpu, ip, 0x50); /* push eax */
- patch_call(s, cpu, ip + 1, handlers->get_tpr_stack);
+ patch_byte(x86_cpu, ip, 0x50); /* push eax */
+ patch_call(x86_cpu, ip + 1, handlers->get_tpr_stack);
break;
default:
abort();
}
- resume_all_vcpus();
+ g_free(info);
+}
- if (!kvm_enabled()) {
- /* Both tb_lock and iothread_mutex will be reset when
- * longjmps back into the cpu_exec loop. */
- tb_lock();
- tb_gen_code(cs, current_pc, current_cs_base, current_flags, 1);
- cpu_loop_exit_noexc(cs);
+static void patch_instruction(VAPICROMState *s, X86CPU *cpu, target_ulong ip)
+{
+ CPUState *cs = CPU(cpu);
+ VAPICHandlers *handlers;
+ struct PatchInfo *info;
+ const run_on_cpu_func fn = do_patch_instruction;
+
+ if (smp_cpus == 1) {
+ handlers = &s->rom_state.up;
+ } else {
+ handlers = &s->rom_state.mp;
}
+
+ info = g_new(struct PatchInfo, 1);
+ info->handler = handlers;
+ info->ip = ip;
+
+ async_safe_run_on_cpu(cs, fn, RUN_ON_CPU_HOST_PTR(info));
+ cpu_exit(cs);
}
void vapic_report_tpr_access(DeviceState *dev, CPUState *cs, target_ulong ip,
--
2.13.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH 0/2] Pending MTTCG patches
2017-06-29 7:11 [Qemu-devel] [PATCH 0/2] Pending MTTCG patches Pranith Kumar
2017-06-29 7:11 ` [Qemu-devel] [PATCH v3 1/2] Revert "exec.c: Fix breakpoint invalidation race" Pranith Kumar
2017-06-29 7:11 ` [Qemu-devel] [PATCH v3 2/2] mttcg/i386: Patch instruction using async_safe_* framework Pranith Kumar
@ 2017-07-06 23:49 ` no-reply
2017-07-07 0:03 ` Fam Zheng
2 siblings, 1 reply; 7+ messages in thread
From: no-reply @ 2017-07-06 23:49 UTC (permalink / raw)
To: bobby.prani; +Cc: famz, alex.bennee, pbonzini, qemu-devel, ehabkost, rth
Hi,
This series seems to have some coding style problems. See output below for
more information:
Subject: [Qemu-devel] [PATCH 0/2] Pending MTTCG patches
Message-id: 20170629071129.29362-1-bobby.prani@gmail.com
Type: series
=== TEST SCRIPT BEGIN ===
#!/bin/bash
BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0
git config --local diff.renamelimit 0
git config --local diff.renames True
commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))
done
exit $failed
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
fatal: Cannot update paths and switch to branch 'test' at the same time.
Did you intend to checkout 'origin/patchew/20170629071129.29362-1-bobby.prani@gmail.com' which can not be resolved as commit?
Traceback (most recent call last):
File "/home/fam/bin/patchew", line 440, in test_one
git_clone_repo(clone, r["repo"], r["head"], logf)
File "/home/fam/bin/patchew", line 53, in git_clone_repo
cwd=clone)
File "/usr/lib64/python3.5/subprocess.py", line 271, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['git', 'checkout', 'origin/patchew/20170629071129.29362-1-bobby.prani@gmail.com', '-b', 'test']' returned non-zero exit status 128
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@freelists.org
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH 0/2] Pending MTTCG patches
2017-07-06 23:49 ` [Qemu-devel] [PATCH 0/2] Pending MTTCG patches no-reply
@ 2017-07-07 0:03 ` Fam Zheng
0 siblings, 0 replies; 7+ messages in thread
From: Fam Zheng @ 2017-07-07 0:03 UTC (permalink / raw)
To: qemu-devel; +Cc: bobby.prani, ehabkost, pbonzini, alex.bennee, rth
On Thu, 07/06 16:49, no-reply@patchew.org wrote:
> Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
> fatal: Cannot update paths and switch to branch 'test' at the same time.
> Did you intend to checkout 'origin/patchew/20170629071129.29362-1-bobby.prani@gmail.com' which can not be resolved as commit?
> Traceback (most recent call last):
> File "/home/fam/bin/patchew", line 440, in test_one
> git_clone_repo(clone, r["repo"], r["head"], logf)
> File "/home/fam/bin/patchew", line 53, in git_clone_repo
> cwd=clone)
> File "/usr/lib64/python3.5/subprocess.py", line 271, in check_call
> raise CalledProcessError(retcode, cmd)
> subprocess.CalledProcessError: Command '['git', 'checkout', 'origin/patchew/20170629071129.29362-1-bobby.prani@gmail.com', '-b', 'test']' returned non-zero exit status 128
Ignore this please, patchew is recovering from a bad state.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH v3 2/2] mttcg/i386: Patch instruction using async_safe_* framework
2017-06-29 7:11 ` [Qemu-devel] [PATCH v3 2/2] mttcg/i386: Patch instruction using async_safe_* framework Pranith Kumar
@ 2017-07-07 10:02 ` Alex Bennée
2017-07-07 10:26 ` Paolo Bonzini
1 sibling, 0 replies; 7+ messages in thread
From: Alex Bennée @ 2017-07-07 10:02 UTC (permalink / raw)
To: Pranith Kumar; +Cc: qemu-devel, rth, pbonzini, ehabkost, Peter Maydell
Pranith Kumar <bobby.prani@gmail.com> writes:
> In mttcg, calling pause_all_vcpus() during execution from the
> generated TBs causes a deadlock if some vCPU is waiting for exclusive
> execution in start_exclusive(). Fix this by using the aync_safe_*
> framework instead of pausing vcpus for patching instructions.
It looks like this needs to be re-based. Can you spin a new version and
then I'll pull it into my tree while I look at fixing:
https://lists.gnu.org/archive/html/qemu-devel/2017-07/msg01061.html
>
> CC: Paolo Bonzini <pbonzini@redhat.com>
> CC: Peter Maydell <peter.maydell@linaro.org>
> Reviewed-by: Richard Henderson <rth@twiddle.net>
> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
> Signed-off-by: Pranith Kumar <bobby.prani@gmail.com>
> ---
> hw/i386/kvmvapic.c | 73 +++++++++++++++++++++++++++++++-----------------------
> 1 file changed, 42 insertions(+), 31 deletions(-)
>
> diff --git a/hw/i386/kvmvapic.c b/hw/i386/kvmvapic.c
> index 82a49556af..5e0c8219b0 100644
> --- a/hw/i386/kvmvapic.c
> +++ b/hw/i386/kvmvapic.c
> @@ -383,8 +383,7 @@ static void patch_byte(X86CPU *cpu, target_ulong addr, uint8_t byte)
> cpu_memory_rw_debug(CPU(cpu), addr, &byte, 1, 1);
> }
>
> -static void patch_call(VAPICROMState *s, X86CPU *cpu, target_ulong ip,
> - uint32_t target)
> +static void patch_call(X86CPU *cpu, target_ulong ip, uint32_t target)
> {
> uint32_t offset;
>
> @@ -393,23 +392,24 @@ static void patch_call(VAPICROMState *s, X86CPU *cpu, target_ulong ip,
> cpu_memory_rw_debug(CPU(cpu), ip + 1, (void *)&offset, sizeof(offset), 1);
> }
>
> -static void patch_instruction(VAPICROMState *s, X86CPU *cpu, target_ulong ip)
> +struct PatchInfo {
> + VAPICHandlers *handler;
> + target_ulong ip;
> +};
> +
> +static void do_patch_instruction(CPUState *cs, run_on_cpu_data data)
> {
> - CPUState *cs = CPU(cpu);
> - CPUX86State *env = &cpu->env;
> - VAPICHandlers *handlers;
> + X86CPU *x86_cpu = X86_CPU(cs);
> + CPUX86State *env = &x86_cpu->env;
> + struct PatchInfo *info = (struct PatchInfo *) data.host_ptr;
> + VAPICHandlers *handlers = info->handler;
> + target_ulong ip = info->ip;
> uint8_t opcode[2];
> uint32_t imm32 = 0;
> target_ulong current_pc = 0;
> target_ulong current_cs_base = 0;
> uint32_t current_flags = 0;
>
> - if (smp_cpus == 1) {
> - handlers = &s->rom_state.up;
> - } else {
> - handlers = &s->rom_state.mp;
> - }
> -
> if (!kvm_enabled()) {
> cpu_get_tb_cpu_state(env, ¤t_pc, ¤t_cs_base,
> ¤t_flags);
> @@ -421,48 +421,59 @@ static void patch_instruction(VAPICROMState *s, X86CPU *cpu, target_ulong ip)
> }
> }
>
> - pause_all_vcpus();
> -
> cpu_memory_rw_debug(cs, ip, opcode, sizeof(opcode), 0);
>
> switch (opcode[0]) {
> case 0x89: /* mov r32 to r/m32 */
> - patch_byte(cpu, ip, 0x50 + modrm_reg(opcode[1])); /* push reg */
> - patch_call(s, cpu, ip + 1, handlers->set_tpr);
> + patch_byte(x86_cpu, ip, 0x50 + modrm_reg(opcode[1])); /* push reg */
> + patch_call(x86_cpu, ip + 1, handlers->set_tpr);
> break;
> case 0x8b: /* mov r/m32 to r32 */
> - patch_byte(cpu, ip, 0x90);
> - patch_call(s, cpu, ip + 1, handlers->get_tpr[modrm_reg(opcode[1])]);
> + patch_byte(x86_cpu, ip, 0x90);
> + patch_call(x86_cpu, ip + 1, handlers->get_tpr[modrm_reg(opcode[1])]);
> break;
> case 0xa1: /* mov abs to eax */
> - patch_call(s, cpu, ip, handlers->get_tpr[0]);
> + patch_call(x86_cpu, ip, handlers->get_tpr[0]);
> break;
> case 0xa3: /* mov eax to abs */
> - patch_call(s, cpu, ip, handlers->set_tpr_eax);
> + patch_call(x86_cpu, ip, handlers->set_tpr_eax);
> break;
> case 0xc7: /* mov imm32, r/m32 (c7/0) */
> - patch_byte(cpu, ip, 0x68); /* push imm32 */
> + patch_byte(x86_cpu, ip, 0x68); /* push imm32 */
> cpu_memory_rw_debug(cs, ip + 6, (void *)&imm32, sizeof(imm32), 0);
> cpu_memory_rw_debug(cs, ip + 1, (void *)&imm32, sizeof(imm32), 1);
> - patch_call(s, cpu, ip + 5, handlers->set_tpr);
> + patch_call(x86_cpu, ip + 5, handlers->set_tpr);
> break;
> case 0xff: /* push r/m32 */
> - patch_byte(cpu, ip, 0x50); /* push eax */
> - patch_call(s, cpu, ip + 1, handlers->get_tpr_stack);
> + patch_byte(x86_cpu, ip, 0x50); /* push eax */
> + patch_call(x86_cpu, ip + 1, handlers->get_tpr_stack);
> break;
> default:
> abort();
> }
>
> - resume_all_vcpus();
> + g_free(info);
> +}
>
> - if (!kvm_enabled()) {
> - /* Both tb_lock and iothread_mutex will be reset when
> - * longjmps back into the cpu_exec loop. */
> - tb_lock();
> - tb_gen_code(cs, current_pc, current_cs_base, current_flags, 1);
> - cpu_loop_exit_noexc(cs);
> +static void patch_instruction(VAPICROMState *s, X86CPU *cpu, target_ulong ip)
> +{
> + CPUState *cs = CPU(cpu);
> + VAPICHandlers *handlers;
> + struct PatchInfo *info;
> + const run_on_cpu_func fn = do_patch_instruction;
> +
> + if (smp_cpus == 1) {
> + handlers = &s->rom_state.up;
> + } else {
> + handlers = &s->rom_state.mp;
> }
> +
> + info = g_new(struct PatchInfo, 1);
> + info->handler = handlers;
> + info->ip = ip;
> +
> + async_safe_run_on_cpu(cs, fn, RUN_ON_CPU_HOST_PTR(info));
> + cpu_exit(cs);
> }
>
> void vapic_report_tpr_access(DeviceState *dev, CPUState *cs, target_ulong ip,
--
Alex Bennée
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH v3 2/2] mttcg/i386: Patch instruction using async_safe_* framework
2017-06-29 7:11 ` [Qemu-devel] [PATCH v3 2/2] mttcg/i386: Patch instruction using async_safe_* framework Pranith Kumar
2017-07-07 10:02 ` Alex Bennée
@ 2017-07-07 10:26 ` Paolo Bonzini
1 sibling, 0 replies; 7+ messages in thread
From: Paolo Bonzini @ 2017-07-07 10:26 UTC (permalink / raw)
To: Pranith Kumar, alex.bennee; +Cc: qemu-devel, rth, ehabkost, Peter Maydell
On 29/06/2017 09:11, Pranith Kumar wrote:
> In mttcg, calling pause_all_vcpus() during execution from the
> generated TBs causes a deadlock if some vCPU is waiting for exclusive
> execution in start_exclusive(). Fix this by using the aync_safe_*
> framework instead of pausing vcpus for patching instructions.
>
> CC: Paolo Bonzini <pbonzini@redhat.com>
> CC: Peter Maydell <peter.maydell@linaro.org>
> Reviewed-by: Richard Henderson <rth@twiddle.net>
> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
> Signed-off-by: Pranith Kumar <bobby.prani@gmail.com>
> ---
> hw/i386/kvmvapic.c | 73 +++++++++++++++++++++++++++++++-----------------------
> 1 file changed, 42 insertions(+), 31 deletions(-)
>
> diff --git a/hw/i386/kvmvapic.c b/hw/i386/kvmvapic.c
> index 82a49556af..5e0c8219b0 100644
> --- a/hw/i386/kvmvapic.c
> +++ b/hw/i386/kvmvapic.c
> @@ -383,8 +383,7 @@ static void patch_byte(X86CPU *cpu, target_ulong addr, uint8_t byte)
> cpu_memory_rw_debug(CPU(cpu), addr, &byte, 1, 1);
> }
>
> -static void patch_call(VAPICROMState *s, X86CPU *cpu, target_ulong ip,
> - uint32_t target)
> +static void patch_call(X86CPU *cpu, target_ulong ip, uint32_t target)
> {
> uint32_t offset;
>
> @@ -393,23 +392,24 @@ static void patch_call(VAPICROMState *s, X86CPU *cpu, target_ulong ip,
> cpu_memory_rw_debug(CPU(cpu), ip + 1, (void *)&offset, sizeof(offset), 1);
> }
>
> -static void patch_instruction(VAPICROMState *s, X86CPU *cpu, target_ulong ip)
> +struct PatchInfo {
> + VAPICHandlers *handler;
> + target_ulong ip;
> +};
> +
> +static void do_patch_instruction(CPUState *cs, run_on_cpu_data data)
> {
> - CPUState *cs = CPU(cpu);
> - CPUX86State *env = &cpu->env;
> - VAPICHandlers *handlers;
> + X86CPU *x86_cpu = X86_CPU(cs);
> + CPUX86State *env = &x86_cpu->env;
> + struct PatchInfo *info = (struct PatchInfo *) data.host_ptr;
> + VAPICHandlers *handlers = info->handler;
> + target_ulong ip = info->ip;
> uint8_t opcode[2];
> uint32_t imm32 = 0;
> target_ulong current_pc = 0;
> target_ulong current_cs_base = 0;
> uint32_t current_flags = 0;
>
> - if (smp_cpus == 1) {
> - handlers = &s->rom_state.up;
> - } else {
> - handlers = &s->rom_state.mp;
> - }
> -
> if (!kvm_enabled()) {
I think this "if" should stay in patch_instruction(), and...
> cpu_get_tb_cpu_state(env, ¤t_pc, ¤t_cs_base,
> ¤t_flags);
> @@ -421,48 +421,59 @@ static void patch_instruction(VAPICROMState *s, X86CPU *cpu, target_ulong ip)
> }
> }
>
> - pause_all_vcpus();
> -
> cpu_memory_rw_debug(cs, ip, opcode, sizeof(opcode), 0);
>
> switch (opcode[0]) {
> case 0x89: /* mov r32 to r/m32 */
> - patch_byte(cpu, ip, 0x50 + modrm_reg(opcode[1])); /* push reg */
> - patch_call(s, cpu, ip + 1, handlers->set_tpr);
> + patch_byte(x86_cpu, ip, 0x50 + modrm_reg(opcode[1])); /* push reg */
> + patch_call(x86_cpu, ip + 1, handlers->set_tpr);
> break;
> case 0x8b: /* mov r/m32 to r32 */
> - patch_byte(cpu, ip, 0x90);
> - patch_call(s, cpu, ip + 1, handlers->get_tpr[modrm_reg(opcode[1])]);
> + patch_byte(x86_cpu, ip, 0x90);
> + patch_call(x86_cpu, ip + 1, handlers->get_tpr[modrm_reg(opcode[1])]);
> break;
> case 0xa1: /* mov abs to eax */
> - patch_call(s, cpu, ip, handlers->get_tpr[0]);
> + patch_call(x86_cpu, ip, handlers->get_tpr[0]);
> break;
> case 0xa3: /* mov eax to abs */
> - patch_call(s, cpu, ip, handlers->set_tpr_eax);
> + patch_call(x86_cpu, ip, handlers->set_tpr_eax);
> break;
> case 0xc7: /* mov imm32, r/m32 (c7/0) */
> - patch_byte(cpu, ip, 0x68); /* push imm32 */
> + patch_byte(x86_cpu, ip, 0x68); /* push imm32 */
> cpu_memory_rw_debug(cs, ip + 6, (void *)&imm32, sizeof(imm32), 0);
> cpu_memory_rw_debug(cs, ip + 1, (void *)&imm32, sizeof(imm32), 1);
> - patch_call(s, cpu, ip + 5, handlers->set_tpr);
> + patch_call(x86_cpu, ip + 5, handlers->set_tpr);
> break;
> case 0xff: /* push r/m32 */
> - patch_byte(cpu, ip, 0x50); /* push eax */
> - patch_call(s, cpu, ip + 1, handlers->get_tpr_stack);
> + patch_byte(x86_cpu, ip, 0x50); /* push eax */
> + patch_call(x86_cpu, ip + 1, handlers->get_tpr_stack);
> break;
> default:
> abort();
> }
>
> - resume_all_vcpus();
> + g_free(info);
> +}
>
> - if (!kvm_enabled()) {
> - /* Both tb_lock and iothread_mutex will be reset when
> - * longjmps back into the cpu_exec loop. */
> - tb_lock();
> - tb_gen_code(cs, current_pc, current_cs_base, current_flags, 1);
> - cpu_loop_exit_noexc(cs);
> +static void patch_instruction(VAPICROMState *s, X86CPU *cpu, target_ulong ip)
> +{
> + CPUState *cs = CPU(cpu);
> + VAPICHandlers *handlers;
> + struct PatchInfo *info;
> + const run_on_cpu_func fn = do_patch_instruction;
> +
> + if (smp_cpus == 1) {
> + handlers = &s->rom_state.up;
> + } else {
> + handlers = &s->rom_state.mp;
> }
> +
> + info = g_new(struct PatchInfo, 1);
> + info->handler = handlers;
> + info->ip = ip;
> +
> + async_safe_run_on_cpu(cs, fn, RUN_ON_CPU_HOST_PTR(info));
> + cpu_exit(cs);
... this cpu_exit is not necessary, since it's already done via
async_safe_run_on_cpu->queue_work_on_cpu->qemu_cpu_kick.
Thanks,
Paolo
> }
>
> void vapic_report_tpr_access(DeviceState *dev, CPUState *cs, target_ulong ip,
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-07-07 10:27 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-29 7:11 [Qemu-devel] [PATCH 0/2] Pending MTTCG patches Pranith Kumar
2017-06-29 7:11 ` [Qemu-devel] [PATCH v3 1/2] Revert "exec.c: Fix breakpoint invalidation race" Pranith Kumar
2017-06-29 7:11 ` [Qemu-devel] [PATCH v3 2/2] mttcg/i386: Patch instruction using async_safe_* framework Pranith Kumar
2017-07-07 10:02 ` Alex Bennée
2017-07-07 10:26 ` Paolo Bonzini
2017-07-06 23:49 ` [Qemu-devel] [PATCH 0/2] Pending MTTCG patches no-reply
2017-07-07 0:03 ` Fam Zheng
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.