From: "Alex Bennée" <alex.bennee@linaro.org>
To: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru>
Cc: pbonzini@redhat.com, richard.henderson@linaro.org,
qemu-devel@nongnu.org, peterx@redhat.com, david@redhat.com
Subject: Re: [PATCH v2 1/3] icount: preserve cflags when custom tb is about to execute
Date: Tue, 16 Nov 2021 10:57:12 +0000 [thread overview]
Message-ID: <87pmr0wc5k.fsf@linaro.org> (raw)
In-Reply-To: <b7bcea58-0f1f-d641-06ae-72d47e8f2318@ispras.ru>
Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru> writes:
> On 11.11.2021 15:20, Alex Bennée wrote:
>> Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru> writes:
>>
>>> 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 2d14d02f6c..df12452b8f 100644
>>> --- a/accel/tcg/cpu-exec.c
>>> +++ b/accel/tcg/cpu-exec.c
>>> @@ -846,6 +846,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
Can cpu->cflags_next_tb ever be anything else? It is consumed in
cpu_exec() and it can only be reset if we have executed some
instructions which resulted in some sort of helper call that set it for
the next TB.
>>> + && (!use_icount || !(tb->cflags & CF_USE_ICOUNT)
>> Why check use_icount here? The cflags should always have
>> CF_USE_ICOUNT
>> set when icount is enabled. Lets not over complicate the inverted ||
>> tests we have here.
>
> Not really.
Right this is were the logic gets complicated to follow. Are we dealing
with icount cases or non-icount cases or some mixture of both?
> Sometimes we use non-icount blocks in icount mode.
> But AFAIR they are used only for triggering the exeptions, but not for
> real execution.
Right so tcg_cpu_init_cflags ensures CF_USE_ICOUNT is set for all blocks
when use_icount() in enabled except the one special case during
exception replay where we suppress it:
#ifndef CONFIG_USER_ONLY
if (replay_has_exception()
&& cpu_neg(cpu)->icount_decr.u16.low + cpu->icount_extra == 0) {
/* Execute just one insn to trigger exception pending in the log */
cpu->cflags_next_tb = (curr_cflags(cpu) & ~CF_USE_ICOUNT) | 1;
}
#endif
which still slightly scrambles my brain because does that affect the
final updating of icount_get_executed() or do we "loose" the instruction
in that case.
>
>>
>>> + || cpu_neg(cpu)->icount_decr.u16.low >= tb->icount))
>>> {
>> Is u16.low ever set when icount isn't enabled?
>
> This condition is checked for icount mode only.
> u16.low is not used without 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;
Technically this isn't what cpu->cflags_next_tb used to be because the
eventual tb->cflags might get tweaked by various conditions in
tb_gen_code().
It seems to me what we really need is a clear unambiguous indication from
cpu_tb_exec() that the we have executed nothing apart from the initial
preamble generated by gen_tb_start(). If we have advanced beyond that
point it would never be valid to restore the cflag state form the TB.
Richard, what do you think?
--
Alex Bennée
next prev parent reply other threads:[~2021-11-16 11:54 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-11 9:55 [PATCH v2 0/3] Some watchpoint-related patches Pavel Dovgalyuk
2021-11-11 9:55 ` [PATCH v2 1/3] icount: preserve cflags when custom tb is about to execute Pavel Dovgalyuk
2021-11-11 12:20 ` Alex Bennée
2021-11-16 7:40 ` Pavel Dovgalyuk
2021-11-16 10:57 ` Alex Bennée [this message]
2021-11-17 9:47 ` Alex Bennée
2021-11-17 10:03 ` Richard Henderson
2021-11-17 10:29 ` Alex Bennée
2021-11-17 11:29 ` Richard Henderson
2021-11-18 11:05 ` Pavel Dovgalyuk
2021-11-11 9:55 ` [PATCH v2 2/3] softmmu: fix watchpoint-interrupt races Pavel Dovgalyuk
2021-11-11 13:15 ` Alex Bennée
2021-11-12 10:10 ` David Hildenbrand
2021-11-11 9:55 ` [PATCH v2 3/3] softmmu: fix watchpoints on memory used by vCPU internals Pavel Dovgalyuk
2021-11-11 10:48 ` [PATCH v2 0/3] Some watchpoint-related patches David Hildenbrand
2021-11-11 10:50 ` Pavel Dovgalyuk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87pmr0wc5k.fsf@linaro.org \
--to=alex.bennee@linaro.org \
--cc=david@redhat.com \
--cc=pavel.dovgalyuk@ispras.ru \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.