From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: elver@google.com, icb@rice.edu, qemu-arm@nongnu.org
Subject: [PATCH v3 2/3] target/arm: Add allocation tag storage for user mode
Date: Tue, 15 Oct 2019 09:35:06 -0700 [thread overview]
Message-ID: <20191015163507.12153-3-richard.henderson@linaro.org> (raw)
In-Reply-To: <20191015163507.12153-1-richard.henderson@linaro.org>
Control this with x-tagged-pages, which is off by default.
The limitation to non-shared pages is not part of a future kernel API,
but a limitation of linux-user not being able to map virtual pages back
to physical pages.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
v2: Add the x-tagged-pages cpu property
---
target/arm/cpu.h | 4 ++++
target/arm/cpu64.c | 20 ++++++++++++++++++++
target/arm/mte_helper.c | 35 +++++++++++++++++++++++++++++++++--
3 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index c3609ef9d5..272df43d3c 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -912,6 +912,10 @@ struct ARMCPU {
*/
bool cfgend;
+#ifdef CONFIG_USER_ONLY
+ bool tagged_pages;
+#endif
+
QLIST_HEAD(, ARMELChangeHook) pre_el_change_hooks;
QLIST_HEAD(, ARMELChangeHook) el_change_hooks;
diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c
index ac1e2dc2c4..4bf498f778 100644
--- a/target/arm/cpu64.c
+++ b/target/arm/cpu64.c
@@ -279,6 +279,20 @@ static void cpu_max_set_sve_vq(Object *obj, Visitor *v, const char *name,
error_propagate(errp, err);
}
+#ifdef CONFIG_USER_ONLY
+static bool aarch64_cpu_get_tagged_pages(Object *obj, Error **errp)
+{
+ ARMCPU *cpu = ARM_CPU(obj);
+ return cpu->tagged_pages;
+}
+
+static void aarch64_cpu_set_tagged_pages(Object *obj, bool val, Error **errp)
+{
+ ARMCPU *cpu = ARM_CPU(obj);
+ cpu->tagged_pages = val;
+}
+#endif
+
/* -cpu max: if KVM is enabled, like -cpu host (best possible with this host);
* otherwise, a CPU with as many features enabled as our emulation supports.
* The version of '-cpu max' for qemu-system-arm is defined in cpu.c;
@@ -389,6 +403,12 @@ static void aarch64_max_initfn(Object *obj)
*/
cpu->ctr = 0x80038003; /* 32 byte I and D cacheline size, VIPT icache */
cpu->dcz_blocksize = 7; /* 512 bytes */
+
+ object_property_add_bool(obj, "x-tagged-pages",
+ aarch64_cpu_get_tagged_pages,
+ aarch64_cpu_set_tagged_pages, NULL);
+ object_property_set_description(obj, "x-tagged-pages",
+ "Set on/off MemAttr Tagged for all pages", NULL);
#endif
cpu->sve_max_vq = ARM_MAX_VQ;
diff --git a/target/arm/mte_helper.c b/target/arm/mte_helper.c
index 657383ba0e..797c6229ab 100644
--- a/target/arm/mte_helper.c
+++ b/target/arm/mte_helper.c
@@ -29,8 +29,39 @@ static uint8_t *allocation_tag_mem(CPUARMState *env, uint64_t ptr,
bool write, uintptr_t ra)
{
#ifdef CONFIG_USER_ONLY
- /* Tag storage not implemented. */
- return NULL;
+ ARMCPU *cpu = env_archcpu(env);
+ uint8_t *tags;
+ uintptr_t index;
+ int flags;
+
+ flags = page_get_flags(ptr);
+
+ if (!(flags & PAGE_VALID) || !(flags & (write ? PAGE_WRITE : PAGE_READ))) {
+ /* SIGSEGV */
+ env->exception.vaddress = ptr;
+ cpu_restore_state(CPU(cpu), ra, true);
+ raise_exception(env, EXCP_DATA_ABORT, 0, 1);
+ }
+
+ if (!cpu->tagged_pages) {
+ /* Tag storage is disabled. */
+ return NULL;
+ }
+ if (flags & PAGE_SHARED) {
+ /* There may be multiple mappings; pretend not implemented. */
+ return NULL;
+ }
+
+ tags = page_get_target_data(ptr);
+ if (tags == NULL) {
+ size_t alloc_size = TARGET_PAGE_SIZE >> (LOG2_TAG_GRANULE + 1);
+ tags = page_alloc_target_data(ptr, alloc_size);
+ assert(tags != NULL);
+ }
+
+ index = extract32(ptr, LOG2_TAG_GRANULE + 1,
+ TARGET_PAGE_BITS - LOG2_TAG_GRANULE - 1);
+ return tags + index;
#else
CPUState *cs = env_cpu(env);
uintptr_t index;
--
2.17.1
next prev parent reply other threads:[~2019-10-15 16:59 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-15 16:35 [PATCH 0/3] target/arm: Implement ARMv8.5-MemTag, user mode Richard Henderson
2019-10-15 16:35 ` [PATCH v3 1/3] tcg: Introduce target-specific page data for user-only Richard Henderson
2019-10-15 16:35 ` Richard Henderson [this message]
2019-10-15 16:35 ` [PATCH v3 3/3] tests/tcg/aarch64: Add mte smoke tests Richard Henderson
2019-12-06 13:23 ` [PATCH 0/3] target/arm: Implement ARMv8.5-MemTag, user mode Peter Maydell
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=20191015163507.12153-3-richard.henderson@linaro.org \
--to=richard.henderson@linaro.org \
--cc=elver@google.com \
--cc=icb@rice.edu \
--cc=qemu-arm@nongnu.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).