From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Gustavo Romero <gustavo.romero@linaro.org>,
qemu-devel@nongnu.org, alex.bennee@linaro.org,
richard.henderson@linaro.org
Cc: peter.maydell@linaro.org
Subject: Re: [PATCH v4 6/9] target/arm: Factor out code for setting MTE TCF0 field
Date: Mon, 24 Jun 2024 09:48:10 +0200 [thread overview]
Message-ID: <c82c83b4-21f0-40e0-8a7c-e38205ae838b@linaro.org> (raw)
In-Reply-To: <20240624053046.221802-7-gustavo.romero@linaro.org>
On 24/6/24 07:30, Gustavo Romero wrote:
> Factor out the code used for setting the MTE TCF0 field from the prctl
> code into a convenient function. Other subsystems, like gdbstub, need to
> set this field as well, so keep it as a separate function to avoid
> duplication and ensure consistency in how this field is set across the
> board.
>
> Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
> ---
> linux-user/aarch64/mte_user_helper.h | 38 ++++++++++++++++++++++++++++
> linux-user/aarch64/target_prctl.h | 22 ++--------------
> 2 files changed, 40 insertions(+), 20 deletions(-)
> create mode 100644 linux-user/aarch64/mte_user_helper.h
>
> diff --git a/linux-user/aarch64/mte_user_helper.h b/linux-user/aarch64/mte_user_helper.h
> new file mode 100644
> index 0000000000..fd92e71c00
> --- /dev/null
> +++ b/linux-user/aarch64/mte_user_helper.h
> @@ -0,0 +1,38 @@
> +/*
> + * ARM MemTag convenience functions.
> + *
> + * This code is licensed under the GNU GPL v2 or later.
> + *
> + * SPDX-License-Identifier: LGPL-2.1-or-later
> + */
> +
> +#ifndef MTE_H
> +#define MTE_H
> +
> +#include "sys/prctl.h"
> +
> +static inline void arm_set_mte_tcf0(CPUArchState *env, abi_long value)
> +{
> + /*
> + * Write PR_MTE_TCF to SCTLR_EL1[TCF0].
> + *
> + * The kernel has a per-cpu configuration for the sysadmin,
> + * /sys/devices/system/cpu/cpu<N>/mte_tcf_preferred,
> + * which qemu does not implement.
> + *
> + * Because there is no performance difference between the modes, and
> + * because SYNC is most useful for debugging MTE errors, choose SYNC
> + * as the preferred mode. With this preference, and the way the API
> + * uses only two bits, there is no way for the program to select
> + * ASYMM mode.
> + */
> + unsigned tcf = 0;
> + if (value & PR_MTE_TCF_SYNC) {
> + tcf = 1;
> + } else if (value & PR_MTE_TCF_ASYNC) {
> + tcf = 2;
> + }
> + env->cp15.sctlr_el[1] = deposit64(env->cp15.sctlr_el[1], 38, 2, tcf);
Missing "qemu/bitops.h" header.
> +}
> +
> +#endif /* MTE_H */
> diff --git a/linux-user/aarch64/target_prctl.h b/linux-user/aarch64/target_prctl.h
> index aa8e203c15..ed75b9e4b5 100644
> --- a/linux-user/aarch64/target_prctl.h
> +++ b/linux-user/aarch64/target_prctl.h
> @@ -7,6 +7,7 @@
> #define AARCH64_TARGET_PRCTL_H
>
> #include "target/arm/cpu-features.h"
> +#include "mte_user_helper.h"
>
> static abi_long do_prctl_sve_get_vl(CPUArchState *env)
> {
> @@ -173,26 +174,7 @@ static abi_long do_prctl_set_tagged_addr_ctrl(CPUArchState *env, abi_long arg2)
> env->tagged_addr_enable = arg2 & PR_TAGGED_ADDR_ENABLE;
>
> if (cpu_isar_feature(aa64_mte, cpu)) {
> - /*
> - * Write PR_MTE_TCF to SCTLR_EL1[TCF0].
> - *
> - * The kernel has a per-cpu configuration for the sysadmin,
> - * /sys/devices/system/cpu/cpu<N>/mte_tcf_preferred,
> - * which qemu does not implement.
> - *
> - * Because there is no performance difference between the modes, and
> - * because SYNC is most useful for debugging MTE errors, choose SYNC
> - * as the preferred mode. With this preference, and the way the API
> - * uses only two bits, there is no way for the program to select
> - * ASYMM mode.
> - */
> - unsigned tcf = 0;
> - if (arg2 & PR_MTE_TCF_SYNC) {
> - tcf = 1;
> - } else if (arg2 & PR_MTE_TCF_ASYNC) {
> - tcf = 2;
> - }
> - env->cp15.sctlr_el[1] = deposit64(env->cp15.sctlr_el[1], 38, 2, tcf);
> + arm_set_mte_tcf0(env, arg2);
>
> /*
> * Write PR_MTE_TAG to GCR_EL1[Exclude].
next prev parent reply other threads:[~2024-06-24 7:48 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-24 5:30 [PATCH v4 0/9] Add MTE stubs for aarch64 user mode Gustavo Romero
2024-06-24 5:30 ` [PATCH v4 1/9] gdbstub: Clean up process_string_cmd Gustavo Romero
2024-06-24 5:30 ` [PATCH v4 2/9] gdbstub: Move GdbCmdParseEntry into a new header file Gustavo Romero
2024-06-24 5:30 ` [PATCH v4 3/9] gdbstub: Add support for target-specific stubs Gustavo Romero
2024-06-24 5:30 ` [PATCH v4 4/9] target/arm: Fix exception case in allocation_tag_mem_probe Gustavo Romero
2024-06-24 5:30 ` [PATCH v4 5/9] target/arm: Make some MTE helpers widely available Gustavo Romero
2024-06-24 7:47 ` Philippe Mathieu-Daudé
2024-06-25 14:14 ` Philippe Mathieu-Daudé
2024-06-27 4:42 ` Gustavo Romero
2024-06-24 5:30 ` [PATCH v4 6/9] target/arm: Factor out code for setting MTE TCF0 field Gustavo Romero
2024-06-24 7:48 ` Philippe Mathieu-Daudé [this message]
2024-06-24 5:30 ` [PATCH v4 7/9] gdbstub: Make get cpu and hex conversion functions non-internal Gustavo Romero
2024-06-24 5:30 ` [PATCH v4 8/9] gdbstub: Add support for MTE in user mode Gustavo Romero
2024-06-24 5:30 ` [PATCH v4 9/9] tests/tcg/aarch64: Add MTE gdbstub tests Gustavo Romero
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=c82c83b4-21f0-40e0-8a7c-e38205ae838b@linaro.org \
--to=philmd@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=gustavo.romero@linaro.org \
--cc=peter.maydell@linaro.org \
--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 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).