From: Brian Cain <brian.cain@oss.qualcomm.com>
To: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>,
qemu-devel@nongnu.org
Cc: Laurent Vivier <laurent@vivier.eu>, Helge Deller <deller@gmx.de>,
Richard Henderson <richard.henderson@linaro.org>
Subject: Re: [PATCH 01/11] target/hexagon: align exceptions for user/sysemu
Date: Sat, 22 Aug 2026 10:46:45 -0500 [thread overview]
Message-ID: <b505808e-e703-4d8d-99ec-35713179e33a@oss.qualcomm.com> (raw)
In-Reply-To: <dc805d66-fdf2-48be-a643-295ece2d2acf@oss.qualcomm.com>
On 8/21/2026 11:37 AM, Pierrick Bouvier wrote:
> On 8/20/2026 12:02 PM, Brian Cain wrote:
>> On 8/20/2026 1:40 PM, Pierrick Bouvier wrote:
>>> On 8/18/2026 6:31 PM, Brian Cain wrote:
>>>> System mode reports an exception as cs->exception_index = HEX_EVENT_*
>>>> plus
>>>> env->cause_code = HEX_CAUSE_*, but translated code in user mode put
>>>> the cause
>>>> code straight into exception_index, so cpu_loop() was decoding both
>>>> forms.
>>>> gen_exception_decode_fail() and the misaligned-PC check used the raw
>>>> form
>>>> unconditionally, so in system mode the cause code was misread as an
>>>> event
>>>> number.
>>>>
>>>> Use the {event, cause} everywhere and drop the duplicated cases
>>>> from cpu_loop(), which fixes HEX_CAUSE_PRIV_USER_NO_SINSN and
>>>> HEX_CAUSE_PRIV_USER_NO_GINSN. The misaligned PC is no longer zeroed
>>>> on its way out either, so it reaches the signal frame as si_addr instead
>>>> of whatever r31 held.
>>>>
>>>> Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
>>>> ---
>>>> target/hexagon/translate.h | 2 +-
>>>> linux-user/hexagon/cpu_loop.c | 30 +++++++++++-------------------
>>>> target/hexagon/cpu.c | 3 ++-
>>>> target/hexagon/translate.c | 27 +++++++++------------------
>>>> 4 files changed, 23 insertions(+), 39 deletions(-)
>>>>
>>>> diff --git a/target/hexagon/translate.h b/target/hexagon/translate.h
>>>> index 3c5773e2c73..00de2b0d2ec 100644
>>>> --- a/target/hexagon/translate.h
>>>> +++ b/target/hexagon/translate.h
>>>> @@ -330,7 +330,7 @@ extern TCGv_i32 hex_t_sreg[NUM_SREGS];
>>>> #endif
>>>> -void hex_gen_exception_end_tb(DisasContext *ctx, int excp);
>>>> +void hex_gen_exception_end_tb(DisasContext *ctx, int cause);
>>>> void process_store(DisasContext *ctx, int slot_num);
>>>> diff --git a/linux-user/hexagon/cpu_loop.c b/linux-user/hexagon/
>>>> cpu_loop.c
>>>> index d7f73439dbc..e4ef97a1184 100644
>>>> --- a/linux-user/hexagon/cpu_loop.c
>>>> +++ b/linux-user/hexagon/cpu_loop.c
>>>> @@ -66,21 +66,22 @@ void cpu_loop(CPUHexagonState *env)
>>>> case HEX_CAUSE_FETCH_NO_UPAGE:
>>>> case HEX_CAUSE_PRIV_NO_UREAD:
>>>> case HEX_CAUSE_PRIV_NO_UWRITE:
>>>> - force_sig_fault(TARGET_SIGSEGV, TARGET_SEGV_MAPERR,
>>>> - env->gpr[HEX_REG_PC]);
>>>> -
>>>> - break;
>>>> + force_sig_fault(TARGET_SIGSEGV, TARGET_SEGV_MAPERR,
>>>> + env->gpr[HEX_REG_PC]);
>>>> + break;
>>>> case HEX_CAUSE_PRIV_USER_NO_GINSN:
>>>> case HEX_CAUSE_PRIV_USER_NO_SINSN:
>>>> case HEX_CAUSE_INVALID_PACKET:
>>>> - force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC,
>>>> - env->gpr[HEX_REG_PC]);
>>>> - break;
>>>> + case HEX_CAUSE_REG_WRITE_CONFLICT:
>>>> + force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC,
>>>> + env->gpr[HEX_REG_PC]);
>>>> + break;
>>>> case HEX_CAUSE_MISALIGNED_LOAD:
>>>> case HEX_CAUSE_MISALIGNED_STORE:
>>>> - force_sig_fault(TARGET_SIGBUS, TARGET_BUS_ADRALN,
>>>> - env->gpr[HEX_REG_PC]);
>>>> - break;
>>>> + case HEX_CAUSE_PC_NOT_ALIGNED:
>>>> + force_sig_fault(TARGET_SIGBUS, TARGET_BUS_ADRALN,
>>>> + env->gpr[HEX_REG_PC]);
>>>> + break;
>>>> default:
>>>> EXCP_DUMP(env, "\nqemu: unhandled CPU precise
>>>> exception "
>>>> "cause code 0x%x - aborting\n",
>>>> @@ -88,15 +89,6 @@ void cpu_loop(CPUHexagonState *env)
>>>> exit(EXIT_FAILURE);
>>>> }
>>>> break;
>>>> - case HEX_CAUSE_PC_NOT_ALIGNED:
>>>> - force_sig_fault(TARGET_SIGBUS, TARGET_BUS_ADRALN,
>>>> - env->gpr[HEX_REG_R31]);
>>>> - break;
>>>> - case HEX_CAUSE_INVALID_PACKET:
>>>> - case HEX_CAUSE_REG_WRITE_CONFLICT:
>>>> - force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC,
>>>> - env->gpr[HEX_REG_PC]);
>>>> - break;
>>>> case EXCP_ATOMIC:
>>>> cpu_exec_step_atomic(cs);
>>>> break;
>>>> diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c
>>>> index 7067e5b70f7..0bbefc2fb87 100644
>>>> --- a/target/hexagon/cpu.c
>>>> +++ b/target/hexagon/cpu.c
>>>> @@ -323,7 +323,8 @@ static TCGTBCPUState
>>>> hexagon_get_tb_cpu_state(CPUState *cs)
>>>> hex_flags = FIELD_DP32(hex_flags, TB_FLAGS, IS_TIGHT_LOOP, 1);
>>>> }
>>>> if (pc & PCALIGN_MASK) {
>>>> - hexagon_raise_exception_err(env, HEX_CAUSE_PC_NOT_ALIGNED, 0);
>>>> + env->cause_code = HEX_CAUSE_PC_NOT_ALIGNED;
>>>> + hexagon_raise_exception_err(env, HEX_EVENT_PRECISE, pc);
>>>> }
>>>> #ifndef CONFIG_USER_ONLY
>>>> diff --git a/target/hexagon/translate.c b/target/hexagon/translate.c
>>>> index 06a8159d283..5cfa60ca302 100644
>>>> --- a/target/hexagon/translate.c
>>>> +++ b/target/hexagon/translate.c
>>>> @@ -73,8 +73,8 @@ TCGv hex_vstore_pending[VSTORES_MAX];
>>>> #ifndef CONFIG_USER_ONLY
>>>> TCGv_i32 hex_greg[NUM_GREGS];
>>>> TCGv_i32 hex_t_sreg[NUM_SREGS];
>>>> -TCGv_i32 hex_cause_code;
>>>> #endif
>>>> +static TCGv_i32 hex_cause_code;
>>>>
>>> Shouldn't this be part of CPUState?
>>> What if multiple cpus trigger an exception at the same time?
>> The cause_code is part of CPUState. This TCGv is a reference to that
>> state member for use with translation. We take advantage of the single-
>> threaded nature of translation with all of these file-global TCGv values.
>>
> Thinking twice about it, please note that this is true only for
> qemu-user (when tb_gen_code runs with mmap_lock), or qemu-system without
> MTTCG, which is what we have at the moment.
I had intended to claim that it was the case that translation was
single-threaded even in MTTCG. But I see now that I was mistaken about
that.
I arrived at this belief somewhat backwards, I guess - the file-scope
TCGv's used by other architectures who do support MTTCG already, and our
results using file-scope TCGv's on qemu-system-hexagon with MTTCG in a
downstream fork.
But after digging a bit I think it's still safe/appropriate to have
file-scope TCGv's concurrently accessed by multiple translation
threads. Because they are merely a reference to the state data and not
the data itself. The state data is modified by the TCG instructions
generated by translation. The TCGv - the reference itself - is probably
immutable, meaning it couldn't be made to refer to anything else. Or
certainly shouldn't.
> However, using qemu-system with MTTCG, translation can happen
> concurrently, and those variables should be part of DisasContext instead.
>
> Regards,
> Pierrick
next prev parent reply other threads:[~2026-08-22 15:47 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-19 1:31 [PATCH 00/11] Hexagon: exception, interrupt, system reg fixes Brian Cain
2026-08-19 1:31 ` [PATCH 01/11] target/hexagon: align exceptions for user/sysemu Brian Cain
2026-08-20 18:40 ` Pierrick Bouvier
2026-08-20 19:02 ` Brian Cain
2026-08-20 19:32 ` Pierrick Bouvier
2026-08-21 16:37 ` Pierrick Bouvier
2026-08-22 15:46 ` Brian Cain [this message]
2026-08-19 1:31 ` [PATCH 02/11] tests/tcg/hexagon: check priv instructions raise SIGILL Brian Cain
2026-08-20 18:41 ` Pierrick Bouvier
2026-08-19 1:31 ` [PATCH 03/11] hw/intc: clear pending bit on l2vic de-assertion Brian Cain
2026-08-20 18:41 ` Pierrick Bouvier
2026-08-19 1:31 ` [PATCH 04/11] target/hexagon: guard writes to unimplemented guest registers Brian Cain
2026-08-20 18:44 ` Pierrick Bouvier
2026-08-22 15:59 ` Brian Cain
2026-08-19 1:31 ` [PATCH 05/11] target/hexagon: take BQL when reading the system pcycle count Brian Cain
2026-08-20 18:45 ` Pierrick Bouvier
2026-08-19 1:31 ` [PATCH 06/11] target/hexagon: gate GPCYCLE guest register reads on SSR:CE Brian Cain
2026-08-20 18:46 ` Pierrick Bouvier
2026-08-19 1:31 ` [PATCH 07/11] target/hexagon: read UTIMERLO/UTIMERHI from the global timer Brian Cain
2026-08-20 18:48 ` Pierrick Bouvier
2026-08-19 1:31 ` [PATCH 08/11] target/hexagon: raise imprecise exception on multi-TLB match Brian Cain
2026-08-20 18:54 ` Pierrick Bouvier
2026-08-19 1:31 ` [PATCH 09/11] target/hexagon: implement direct-to-guest interrupt delivery Brian Cain
2026-08-20 18:57 ` Pierrick Bouvier
2026-08-20 21:59 ` Brian Cain
2026-08-21 16:22 ` Pierrick Bouvier
2026-08-19 1:31 ` [PATCH 10/11] target/hexagon: fix iassign{r,w} to cover all threads Brian Cain
2026-08-20 18:59 ` Pierrick Bouvier
2026-08-19 1:31 ` [PATCH 11/11] tests/functional/hexagon: update to v0.2.12, +test_{interrupts, sys_regs} Brian Cain via qemu development
2026-08-20 18:59 ` [PATCH 11/11] tests/functional/hexagon: update to v0.2.12, +test_{interrupts,sys_regs} Pierrick Bouvier
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=b505808e-e703-4d8d-99ec-35713179e33a@oss.qualcomm.com \
--to=brian.cain@oss.qualcomm.com \
--cc=deller@gmx.de \
--cc=laurent@vivier.eu \
--cc=pierrick.bouvier@oss.qualcomm.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.