From: Richard Henderson <richard.henderson@linaro.org>
To: ~jhogberg <john.hogberg@ericsson.com>, qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org
Subject: Re: [PATCH qemu v4 1/2] target/arm: Handle IC IVAU to improve compatibility with JITs
Date: Mon, 26 Jun 2023 16:27:25 +0200 [thread overview]
Message-ID: <ba59ed3c-c530-aeab-1c20-0f37f35fafd6@linaro.org> (raw)
In-Reply-To: <168778890374.24232.3402138851538068785-1@git.sr.ht>
On 6/8/23 19:49, ~jhogberg wrote:
> From: John Högberg <john.hogberg@ericsson.com>
>
> Unlike architectures with precise self-modifying code semantics
> (e.g. x86) ARM processors do not maintain coherency for instruction
> execution and memory, requiring an instruction synchronization
> barrier on every core that will execute the new code, and on many
> models also the explicit use of cache management instructions.
>
> While this is required to make JITs work on actual hardware, QEMU
> has gotten away with not handling this since it does not emulate
> caches, and unconditionally invalidates code whenever the softmmu
> or the user-mode page protection logic detects that code has been
> modified.
>
> Unfortunately the latter does not work in the face of dual-mapped
> code (a common W^X workaround), where one page is executable and
> the other is writable: user-mode has no way to connect one with the
> other as that is only known to the kernel and the emulated
> application.
>
> This commit works around the issue by telling software that
> instruction cache invalidation is required by clearing the
> CPR_EL0.DIC flag (regardless of whether the emulated processor
> needs it), and then invalidating code in IC IVAU instructions.
>
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1034
>
> Co-authored-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: John Högberg <john.hogberg@ericsson.com>
> ---
> target/arm/cpu.c | 13 +++++++++++++
> target/arm/helper.c | 47 ++++++++++++++++++++++++++++++++++++++++++---
> 2 files changed, 57 insertions(+), 3 deletions(-)
>
> diff --git a/target/arm/cpu.c b/target/arm/cpu.c
> index 4d5bb57f07..b82fb46157 100644
> --- a/target/arm/cpu.c
> +++ b/target/arm/cpu.c
> @@ -1674,6 +1674,19 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
> return;
> }
>
> + /*
> + * User mode relies on IC IVAU instructions to catch modification of
> + * dual-mapped code.
> + *
> + * Clear CTR_EL0.DIC to ensure that software that honors these flags uses
> + * IC IVAU even if the emulated processor does not normally require it.
> + */
> +#ifdef CONFIG_USER_ONLY
> + if (arm_feature(env, ARM_FEATURE_AARCH64)) {
> + cpu->ctr = FIELD_DP64(cpu->ctr, CTR_EL0, DIC, 0);
> + }
> +#endif
No need to check for aarch64 -- the bit is present at the same location with the same
meaning in the v8 aarch32 view: "CTR". (Prior to v8, this bit was part of the Format
field, and had value 0 for v6 and v7, so still no need to check before writing this zero.)
Otherwise,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
next prev parent reply other threads:[~2023-06-26 14:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-26 14:15 [PATCH qemu v4 0/2] target/arm: Improve user-mode compatibility with JITs ~jhogberg
2023-06-08 17:49 ` [PATCH qemu v4 1/2] target/arm: Handle IC IVAU to improve " ~jhogberg
2023-06-26 14:27 ` Richard Henderson [this message]
2023-06-09 12:04 ` [PATCH qemu v4 2/2] tests/tcg/aarch64: Add testcases for IC IVAU and dual-mapped code ~jhogberg
2023-06-27 14:52 ` Peter Maydell
2023-06-27 15:02 ` [PATCH qemu v4 0/2] target/arm: Improve user-mode compatibility with JITs Peter Maydell
2023-06-27 15:23 ` John Högberg
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=ba59ed3c-c530-aeab-1c20-0f37f35fafd6@linaro.org \
--to=richard.henderson@linaro.org \
--cc=john.hogberg@ericsson.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).