* [PATCH 0/4] Some watchpoint-related patches
@ 2021-10-28 11:47 Pavel Dovgalyuk
2021-10-28 11:48 ` [PATCH 1/4] softmmu: fix watchpoint processing in icount mode Pavel Dovgalyuk
` (4 more replies)
0 siblings, 5 replies; 12+ messages in thread
From: Pavel Dovgalyuk @ 2021-10-28 11:47 UTC (permalink / raw)
To: qemu-devel
Cc: pavel.dovgalyuk, david, richard.henderson, peterx, pbonzini, alex.bennee
The series includes several watchpoint-related patches.
---
Pavel Dovgalyuk (4):
softmmu: fix watchpoint processing in icount mode
softmmu: remove useless condition in watchpoint check
softmmu: fix for "after access" watchpoints
icount: preserve cflags when custom tb is about to execute
accel/tcg/cpu-exec.c | 10 ++++++++++
softmmu/physmem.c | 41 ++++++++++++++++++++---------------------
2 files changed, 30 insertions(+), 21 deletions(-)
--
Pavel Dovgalyuk
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 1/4] softmmu: fix watchpoint processing in icount mode
2021-10-28 11:47 [PATCH 0/4] Some watchpoint-related patches Pavel Dovgalyuk
@ 2021-10-28 11:48 ` Pavel Dovgalyuk
2021-10-28 19:09 ` Richard Henderson
2021-10-28 11:48 ` [PATCH 2/4] softmmu: remove useless condition in watchpoint check Pavel Dovgalyuk
` (3 subsequent siblings)
4 siblings, 1 reply; 12+ messages in thread
From: Pavel Dovgalyuk @ 2021-10-28 11:48 UTC (permalink / raw)
To: qemu-devel
Cc: pavel.dovgalyuk, david, richard.henderson, peterx, pbonzini, alex.bennee
Watchpoint processing code restores vCPU state twice:
in tb_check_watchpoint and in cpu_loop_exit_restore/cpu_restore_state.
Normally it does not affect anything, but in icount mode instruction
counter is incremented twice and becomes incorrect.
This patch eliminates unneeded CPU state restore.
Signed-off-by: Pavel Dovgalyuk <Pavel.Dovgalyuk@ispras.ru>
Reviewed-by: David Hildenbrand <david@redhat.com>
---
softmmu/physmem.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index f67ad29981..fd1b3b2088 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -938,18 +938,16 @@ void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len,
cpu->watchpoint_hit = wp;
mmap_lock();
+ /* This call also restores vCPU state */
tb_check_watchpoint(cpu, ra);
if (wp->flags & BP_STOP_BEFORE_ACCESS) {
cpu->exception_index = EXCP_DEBUG;
mmap_unlock();
- cpu_loop_exit_restore(cpu, ra);
+ cpu_loop_exit(cpu);
} else {
/* Force execution of one insn next time. */
cpu->cflags_next_tb = 1 | curr_cflags(cpu);
mmap_unlock();
- if (ra) {
- cpu_restore_state(cpu, ra, true);
- }
cpu_loop_exit_noexc(cpu);
}
}
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 2/4] softmmu: remove useless condition in watchpoint check
2021-10-28 11:47 [PATCH 0/4] Some watchpoint-related patches Pavel Dovgalyuk
2021-10-28 11:48 ` [PATCH 1/4] softmmu: fix watchpoint processing in icount mode Pavel Dovgalyuk
@ 2021-10-28 11:48 ` Pavel Dovgalyuk
2021-10-28 19:10 ` Richard Henderson
2021-10-28 11:48 ` [PATCH 3/4] softmmu: fix for "after access" watchpoints Pavel Dovgalyuk
` (2 subsequent siblings)
4 siblings, 1 reply; 12+ messages in thread
From: Pavel Dovgalyuk @ 2021-10-28 11:48 UTC (permalink / raw)
To: qemu-devel
Cc: pavel.dovgalyuk, david, richard.henderson, peterx, pbonzini, alex.bennee
cpu_check_watchpoint function checks cpu->watchpoint_hit at the entry.
But then it also does the same in the middle of the function,
while this field can't change.
That is why this patch removes this useless condition.
Signed-off-by: Pavel Dovgalyuk <Pavel.Dovgalyuk@ispras.ru>
---
softmmu/physmem.c | 41 ++++++++++++++++++++---------------------
1 file changed, 20 insertions(+), 21 deletions(-)
diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index fd1b3b2088..94eda44459 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -929,27 +929,26 @@ void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len,
}
wp->hitaddr = MAX(addr, wp->vaddr);
wp->hitattrs = attrs;
- if (!cpu->watchpoint_hit) {
- if (wp->flags & BP_CPU && cc->tcg_ops->debug_check_watchpoint &&
- !cc->tcg_ops->debug_check_watchpoint(cpu, wp)) {
- wp->flags &= ~BP_WATCHPOINT_HIT;
- continue;
- }
- cpu->watchpoint_hit = wp;
-
- mmap_lock();
- /* This call also restores vCPU state */
- tb_check_watchpoint(cpu, ra);
- if (wp->flags & BP_STOP_BEFORE_ACCESS) {
- cpu->exception_index = EXCP_DEBUG;
- mmap_unlock();
- cpu_loop_exit(cpu);
- } else {
- /* Force execution of one insn next time. */
- cpu->cflags_next_tb = 1 | curr_cflags(cpu);
- mmap_unlock();
- cpu_loop_exit_noexc(cpu);
- }
+
+ if (wp->flags & BP_CPU && cc->tcg_ops->debug_check_watchpoint &&
+ !cc->tcg_ops->debug_check_watchpoint(cpu, wp)) {
+ wp->flags &= ~BP_WATCHPOINT_HIT;
+ continue;
+ }
+ cpu->watchpoint_hit = wp;
+
+ mmap_lock();
+ /* This call also restores vCPU state */
+ tb_check_watchpoint(cpu, ra);
+ if (wp->flags & BP_STOP_BEFORE_ACCESS) {
+ cpu->exception_index = EXCP_DEBUG;
+ mmap_unlock();
+ cpu_loop_exit(cpu);
+ } else {
+ /* Force execution of one insn next time. */
+ cpu->cflags_next_tb = 1 | curr_cflags(cpu);
+ mmap_unlock();
+ cpu_loop_exit_noexc(cpu);
}
} else {
wp->flags &= ~BP_WATCHPOINT_HIT;
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 3/4] softmmu: fix for "after access" watchpoints
2021-10-28 11:47 [PATCH 0/4] Some watchpoint-related patches Pavel Dovgalyuk
2021-10-28 11:48 ` [PATCH 1/4] softmmu: fix watchpoint processing in icount mode Pavel Dovgalyuk
2021-10-28 11:48 ` [PATCH 2/4] softmmu: remove useless condition in watchpoint check Pavel Dovgalyuk
@ 2021-10-28 11:48 ` Pavel Dovgalyuk
2021-10-28 19:13 ` Richard Henderson
2021-10-28 11:48 ` [PATCH 4/4] icount: preserve cflags when custom tb is about to execute Pavel Dovgalyuk
2021-10-28 19:29 ` [PATCH 0/4] Some watchpoint-related patches Richard Henderson
4 siblings, 1 reply; 12+ messages in thread
From: Pavel Dovgalyuk @ 2021-10-28 11:48 UTC (permalink / raw)
To: qemu-devel
Cc: pavel.dovgalyuk, david, richard.henderson, peterx, pbonzini, alex.bennee
Watchpoints that should fire after the memory access
break an execution of the current block, try to
translate current instruction into the separate block,
which then causes debug interrupt.
But cpu_interrupt can't be called in such block when
icount is enabled, because interrupts muse be allowed
explicitly.
This patch sets CF_LAST_IO flag for retranslated block,
allowing interrupt request for the last instruction.
Signed-off-by: Pavel Dovgalyuk <Pavel.Dovgalyuk@ispras.ru>
---
softmmu/physmem.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index 94eda44459..482d80708f 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -946,7 +946,7 @@ void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len,
cpu_loop_exit(cpu);
} else {
/* Force execution of one insn next time. */
- cpu->cflags_next_tb = 1 | curr_cflags(cpu);
+ cpu->cflags_next_tb = 1 | CF_LAST_IO | curr_cflags(cpu);
mmap_unlock();
cpu_loop_exit_noexc(cpu);
}
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 4/4] icount: preserve cflags when custom tb is about to execute
2021-10-28 11:47 [PATCH 0/4] Some watchpoint-related patches Pavel Dovgalyuk
` (2 preceding siblings ...)
2021-10-28 11:48 ` [PATCH 3/4] softmmu: fix for "after access" watchpoints Pavel Dovgalyuk
@ 2021-10-28 11:48 ` Pavel Dovgalyuk
2021-10-28 19:26 ` Richard Henderson
2021-10-28 19:29 ` [PATCH 0/4] Some watchpoint-related patches Richard Henderson
4 siblings, 1 reply; 12+ messages in thread
From: Pavel Dovgalyuk @ 2021-10-28 11:48 UTC (permalink / raw)
To: qemu-devel
Cc: pavel.dovgalyuk, david, richard.henderson, peterx, pbonzini, alex.bennee
When debugging with the watchpoints, qemu may need to create
TB with single instruction. This is achieved by setting cpu->cflags_next_tb.
But when this block is about to execute, it may be interrupted by another
thread. In this case cflags will be lost and next executed TB will not
be the special one.
This patch checks TB exit reason and restores cflags_next_tb to allow
finding the interrupted block.
Signed-off-by: Pavel Dovgalyuk <Pavel.Dovgalyuk@ispras.ru>
---
accel/tcg/cpu-exec.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
index c9764c1325..af1c6e6ba3 100644
--- a/accel/tcg/cpu-exec.c
+++ b/accel/tcg/cpu-exec.c
@@ -842,6 +842,16 @@ static inline void cpu_loop_exec_tb(CPUState *cpu, TranslationBlock *tb,
* cpu_handle_interrupt. cpu_handle_interrupt will also
* clear cpu->icount_decr.u16.high.
*/
+ if (cpu->cflags_next_tb == -1
+ && (!use_icount || !(tb->cflags & CF_USE_ICOUNT)
+ || cpu_neg(cpu)->icount_decr.u16.low >= tb->icount)) {
+ /*
+ * icount is disabled or there are enough instructions
+ * in the budget, do not retranslate this block with
+ * different parameters.
+ */
+ cpu->cflags_next_tb = tb->cflags;
+ }
return;
}
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 1/4] softmmu: fix watchpoint processing in icount mode
2021-10-28 11:48 ` [PATCH 1/4] softmmu: fix watchpoint processing in icount mode Pavel Dovgalyuk
@ 2021-10-28 19:09 ` Richard Henderson
0 siblings, 0 replies; 12+ messages in thread
From: Richard Henderson @ 2021-10-28 19:09 UTC (permalink / raw)
To: Pavel Dovgalyuk, qemu-devel; +Cc: pbonzini, alex.bennee, peterx, david
On 10/28/21 4:48 AM, Pavel Dovgalyuk wrote:
> Watchpoint processing code restores vCPU state twice:
> in tb_check_watchpoint and in cpu_loop_exit_restore/cpu_restore_state.
> Normally it does not affect anything, but in icount mode instruction
> counter is incremented twice and becomes incorrect.
> This patch eliminates unneeded CPU state restore.
>
> Signed-off-by: Pavel Dovgalyuk<Pavel.Dovgalyuk@ispras.ru>
> Reviewed-by: David Hildenbrand<david@redhat.com>
> ---
> softmmu/physmem.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/4] softmmu: remove useless condition in watchpoint check
2021-10-28 11:48 ` [PATCH 2/4] softmmu: remove useless condition in watchpoint check Pavel Dovgalyuk
@ 2021-10-28 19:10 ` Richard Henderson
0 siblings, 0 replies; 12+ messages in thread
From: Richard Henderson @ 2021-10-28 19:10 UTC (permalink / raw)
To: Pavel Dovgalyuk, qemu-devel; +Cc: pbonzini, alex.bennee, peterx, david
On 10/28/21 4:48 AM, Pavel Dovgalyuk wrote:
> cpu_check_watchpoint function checks cpu->watchpoint_hit at the entry.
> But then it also does the same in the middle of the function,
> while this field can't change.
> That is why this patch removes this useless condition.
>
> Signed-off-by: Pavel Dovgalyuk<Pavel.Dovgalyuk@ispras.ru>
> ---
> softmmu/physmem.c | 41 ++++++++++++++++++++---------------------
> 1 file changed, 20 insertions(+), 21 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 3/4] softmmu: fix for "after access" watchpoints
2021-10-28 11:48 ` [PATCH 3/4] softmmu: fix for "after access" watchpoints Pavel Dovgalyuk
@ 2021-10-28 19:13 ` Richard Henderson
0 siblings, 0 replies; 12+ messages in thread
From: Richard Henderson @ 2021-10-28 19:13 UTC (permalink / raw)
To: Pavel Dovgalyuk, qemu-devel; +Cc: pbonzini, alex.bennee, peterx, david
On 10/28/21 4:48 AM, Pavel Dovgalyuk wrote:
> Watchpoints that should fire after the memory access
> break an execution of the current block, try to
> translate current instruction into the separate block,
> which then causes debug interrupt.
> But cpu_interrupt can't be called in such block when
> icount is enabled, because interrupts muse be allowed
> explicitly.
> This patch sets CF_LAST_IO flag for retranslated block,
> allowing interrupt request for the last instruction.
>
> Signed-off-by: Pavel Dovgalyuk<Pavel.Dovgalyuk@ispras.ru>
> ---
> softmmu/physmem.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Indeed, the other such assignment, about 30 lines up, already does this.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 4/4] icount: preserve cflags when custom tb is about to execute
2021-10-28 11:48 ` [PATCH 4/4] icount: preserve cflags when custom tb is about to execute Pavel Dovgalyuk
@ 2021-10-28 19:26 ` Richard Henderson
2021-11-03 8:44 ` Pavel Dovgalyuk
2021-11-11 9:56 ` Pavel Dovgalyuk
0 siblings, 2 replies; 12+ messages in thread
From: Richard Henderson @ 2021-10-28 19:26 UTC (permalink / raw)
To: Pavel Dovgalyuk, qemu-devel; +Cc: pbonzini, alex.bennee, peterx, david
On 10/28/21 4:48 AM, Pavel Dovgalyuk wrote:
> + if (cpu->cflags_next_tb == -1
> + && (!use_icount || !(tb->cflags & CF_USE_ICOUNT)
> + || cpu_neg(cpu)->icount_decr.u16.low >= tb->icount)) {
> + /*
> + * icount is disabled or there are enough instructions
> + * in the budget, do not retranslate this block with
> + * different parameters.
> + */
> + cpu->cflags_next_tb = tb->cflags;
> + }
I can't see that this will work.
We've been asked to exit to the main loop; probably for an interrupt. The next thing
that's likely to happen is that cpu_cc->do_interrupt will adjust cpu state to continue in
the guest interrupt handler. The cflags_next_tb flag that you're setting up is not
relevant to that context.
This seems related to Phil's reported problem
https://gitlab.com/qemu-project/qemu/-/issues/245
in which an interrupt arrives before we finish processing the watchpoint.
I *think* we need to make cflags_next_tb != -1 be treated like any other interrupt disable
bit, and delay delivery of the interrupt. Which also means that we should not check for
exit_tb at the beginning of any TB we generate for the watchpoint step.
I simply haven't taken the time to investigate this properly.
r~
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 0/4] Some watchpoint-related patches
2021-10-28 11:47 [PATCH 0/4] Some watchpoint-related patches Pavel Dovgalyuk
` (3 preceding siblings ...)
2021-10-28 11:48 ` [PATCH 4/4] icount: preserve cflags when custom tb is about to execute Pavel Dovgalyuk
@ 2021-10-28 19:29 ` Richard Henderson
4 siblings, 0 replies; 12+ messages in thread
From: Richard Henderson @ 2021-10-28 19:29 UTC (permalink / raw)
To: Pavel Dovgalyuk, qemu-devel; +Cc: pbonzini, alex.bennee, peterx, david
On 10/28/21 4:47 AM, Pavel Dovgalyuk wrote:
>
> Pavel Dovgalyuk (4):
> softmmu: fix watchpoint processing in icount mode
> softmmu: remove useless condition in watchpoint check
> softmmu: fix for "after access" watchpoints
> icount: preserve cflags when custom tb is about to execute
I'm going to queue the first 3 patches to tcg-next.
r~
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 4/4] icount: preserve cflags when custom tb is about to execute
2021-10-28 19:26 ` Richard Henderson
@ 2021-11-03 8:44 ` Pavel Dovgalyuk
2021-11-11 9:56 ` Pavel Dovgalyuk
1 sibling, 0 replies; 12+ messages in thread
From: Pavel Dovgalyuk @ 2021-11-03 8:44 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: pbonzini, alex.bennee, peterx, david
On 28.10.2021 22:26, Richard Henderson wrote:
> On 10/28/21 4:48 AM, Pavel Dovgalyuk wrote:
>> + if (cpu->cflags_next_tb == -1
>> + && (!use_icount || !(tb->cflags & CF_USE_ICOUNT)
>> + || cpu_neg(cpu)->icount_decr.u16.low >= tb->icount)) {
>> + /*
>> + * icount is disabled or there are enough instructions
>> + * in the budget, do not retranslate this block with
>> + * different parameters.
>> + */
>> + cpu->cflags_next_tb = tb->cflags;
>> + }
>
> I can't see that this will work.
The issue was the following:
- icount is enabled
- watchpoint hit
- next block should contain a single instruction to stop the execution
after memory access
- tb with one instruction is translated, cflags_next_tb is reset
- main loop breaks the execution for some reason
- after resuming the execution, we are trying to find new tb without any
filter in cflags
- tb with multiple instructions is executed (instead of previously
generated)
>
> We've been asked to exit to the main loop; probably for an interrupt.
> The next thing that's likely to happen is that cpu_cc->do_interrupt will
> adjust cpu state to continue in the guest interrupt handler. The
> cflags_next_tb flag that you're setting up is not relevant to that context.
>
> This seems related to Phil's reported problem
>
> https://gitlab.com/qemu-project/qemu/-/issues/245
>
> in which an interrupt arrives before we finish processing the watchpoint.
Right, this is similar.
>
> I *think* we need to make cflags_next_tb != -1 be treated like any other
> interrupt disable bit, and delay delivery of the interrupt. Which also
> means that we should not check for exit_tb at the beginning of any TB we
> generate for the watchpoint step.
>
> I simply haven't taken the time to investigate this properly.
>
>
> r~
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 4/4] icount: preserve cflags when custom tb is about to execute
2021-10-28 19:26 ` Richard Henderson
2021-11-03 8:44 ` Pavel Dovgalyuk
@ 2021-11-11 9:56 ` Pavel Dovgalyuk
1 sibling, 0 replies; 12+ messages in thread
From: Pavel Dovgalyuk @ 2021-11-11 9:56 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: pbonzini, alex.bennee, peterx, david
On 28.10.2021 22:26, Richard Henderson wrote:
> On 10/28/21 4:48 AM, Pavel Dovgalyuk wrote:
>> + if (cpu->cflags_next_tb == -1
>> + && (!use_icount || !(tb->cflags & CF_USE_ICOUNT)
>> + || cpu_neg(cpu)->icount_decr.u16.low >= tb->icount)) {
>> + /*
>> + * icount is disabled or there are enough instructions
>> + * in the budget, do not retranslate this block with
>> + * different parameters.
>> + */
>> + cpu->cflags_next_tb = tb->cflags;
>> + }
>
> I can't see that this will work.
>
> We've been asked to exit to the main loop; probably for an interrupt.
> The next thing that's likely to happen is that cpu_cc->do_interrupt will
> adjust cpu state to continue in the guest interrupt handler. The
> cflags_next_tb flag that you're setting up is not relevant to that context.
>
> This seems related to Phil's reported problem
>
> https://gitlab.com/qemu-project/qemu/-/issues/245
>
> in which an interrupt arrives before we finish processing the watchpoint.
>
> I *think* we need to make cflags_next_tb != -1 be treated like any other
> interrupt disable bit, and delay delivery of the interrupt. Which also
> means that we should not check for exit_tb at the beginning of any TB we
> generate for the watchpoint step.
>
> I simply haven't taken the time to investigate this properly.
Please check the new series, it probably solves the problem described in
that issue.
Pavel Dovgalyuk
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2021-11-11 9:59 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-28 11:47 [PATCH 0/4] Some watchpoint-related patches Pavel Dovgalyuk
2021-10-28 11:48 ` [PATCH 1/4] softmmu: fix watchpoint processing in icount mode Pavel Dovgalyuk
2021-10-28 19:09 ` Richard Henderson
2021-10-28 11:48 ` [PATCH 2/4] softmmu: remove useless condition in watchpoint check Pavel Dovgalyuk
2021-10-28 19:10 ` Richard Henderson
2021-10-28 11:48 ` [PATCH 3/4] softmmu: fix for "after access" watchpoints Pavel Dovgalyuk
2021-10-28 19:13 ` Richard Henderson
2021-10-28 11:48 ` [PATCH 4/4] icount: preserve cflags when custom tb is about to execute Pavel Dovgalyuk
2021-10-28 19:26 ` Richard Henderson
2021-11-03 8:44 ` Pavel Dovgalyuk
2021-11-11 9:56 ` Pavel Dovgalyuk
2021-10-28 19:29 ` [PATCH 0/4] Some watchpoint-related patches Richard Henderson
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.