From patchwork Mon Feb 11 01:08:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 157965 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp2070265jaa; Sun, 10 Feb 2019 17:33:18 -0800 (PST) X-Google-Smtp-Source: AHgI3IYs0yp0uCZ9WyhmX3CZqcxxkESJ5UFKGJ7eVSYEWD+Z3QB8Wcj0rEyJCB9UgqHsS0buVvjx X-Received: by 2002:adf:f8cf:: with SMTP id f15mr25086955wrq.265.1549848797957; Sun, 10 Feb 2019 17:33:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549848797; cv=none; d=google.com; s=arc-20160816; b=woaxxcoC/YmMNPUPRsGJEVJOnsZPtTV0EpWI1oo9+WtBa2FSdPjs4sBIvbyvDQDfsd McyNayQfTMRktPJZftBmFcOU10jga8hthxqWtsl8Afd1RZfOIHJlaQHHXA1elKDzr3PY nSJj/2G2LdhneGLQRRxLuB719wZFs73B3DzL1oiW+ScOs0kZGuB2/pFfvR/SJLsw88wd F/JpYi6nwcKcjKnmYObITTjNHJ/kvfRM/dgjynohfzuRUZKyPKto/8iVXacNRDKbC2H+ K/RyLsuR6+0KA1wrvNnmx3fCFZUJpAV8YpWCejSDJTVb51QnFfDRkHIkfLmLit2+jBSd UtVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=ymaxv9zbXnQNBLMQJfCDWxjmtO7rlV16zaXGdm7o62o=; b=bzerg8rS0io1tlUCIp5tvfCMNexNq0zoKW0fXvj3GNsUV0DdvfibYubU0Aiu5C2sB3 FE5UIILSflQQbRqnWRjpB4peMYRpjGmbU2K2jYqzX3d2m6AiOE+2wnWXxBFuQWtxNnKi GRVHSRNfi81ZIX4UGevsbRJBjr0hLgJX+2ti0+Kdcl7/Vcfnf/Oc1LlX8ZJdgm4jJvZ8 C5CijUHz9XnFJL0nlz3p5sAAz2NHk49a8hUT6Q67msogu8JaxwAqmeOhXGo6JQyCcIvD Uc5mZG279CVqEMgeULMEahrypbeUZZ445gDaHfrlFOajZCSIWxVITESuJK5pXxrU0kMg JPRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=kNaBYver; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q25si6084629wmc.48.2019.02.10.17.33.17 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 10 Feb 2019 17:33:17 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=kNaBYver; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:42446 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gt0TE-00074C-U7 for patch@linaro.org; Sun, 10 Feb 2019 20:33:16 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37687) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gt05w-0005yF-Ol for qemu-devel@nongnu.org; Sun, 10 Feb 2019 20:09:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gt05t-0000AQ-3g for qemu-devel@nongnu.org; Sun, 10 Feb 2019 20:09:12 -0500 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:40716) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gt05s-0008SA-Lv for qemu-devel@nongnu.org; Sun, 10 Feb 2019 20:09:08 -0500 Received: by mail-pl1-x644.google.com with SMTP id bj4so1844967plb.7 for ; Sun, 10 Feb 2019 17:09:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ymaxv9zbXnQNBLMQJfCDWxjmtO7rlV16zaXGdm7o62o=; b=kNaBYver4RNr8omJ21XVp6ZSme5iGL970KWHu2CoT+glEsMAkV6h5hIRVJ7kbVkM3S viIp5DXCvmMY1hIisoEvU7VKw5hYuUtAM14aFV+ws3Fv2C6/3rM0B1GLKSB0wuxEhlrk MEM+fCaDhxmyv/5M2WOE4mNa4H1WlbzXpfOtOWagL3Ya5YiYX2dMNfDUWIJ9HOeCB15L SWiUDgSdvVZ04ZJtaefPTTv7IMRsy75jOL/YFfe/fhziGTuP1/+RVFlf8CAA9pVNXUy7 mtXE9jsqsqkkokDUkEHuTUsqu115+UyC8ZdDIomeWJeseAEv7JtAlp7RZoi+poGdHfde zsPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ymaxv9zbXnQNBLMQJfCDWxjmtO7rlV16zaXGdm7o62o=; b=Z4Is3wndvKa6CMNmQnicxXU7WYsC6kp1h14BdKfJJpQwoVVwFHMzCQl3mlWT2xLctf vWm8DortLFYc4r15/f7wWN/KDbihu2sL38AHamWpGFcX6jlhFrnb23t8lseewJrrxSsM xhRUYoj5tdz1HdGhcTnm981+zb0SP4aeQO+XUqKy7HxhzGR6bOfC/qrpCNnu5TwWEJaM LEsqosqFerULiqtUcst/awVJ2hhpWnHv3WOXlceulOmCIoxCVRGbxGYxhDU0HjFt9h5o Guf769YKUAyZqvPyvtmAnDvIzJmBiuPe8xN2JHGpDALpb8YoGHuWwx/3uso+E4+FsjbD srVQ== X-Gm-Message-State: AHQUAubKMQnockvYj/AGZvknzqFvOnOQbNILvfBfieLlhREe3OFdK4dx PmRi686Mvsl0vCNziBkuZeuVAr0fGm8= X-Received: by 2002:a17:902:bd0b:: with SMTP id p11mr35123162pls.259.1549847341514; Sun, 10 Feb 2019 17:09:01 -0800 (PST) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id g14sm17177630pfg.27.2019.02.10.17.09.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 10 Feb 2019 17:09:00 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sun, 10 Feb 2019 17:08:26 -0800 Message-Id: <20190211010829.29869-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190211010829.29869-1-richard.henderson@linaro.org> References: <20190211010829.29869-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::644 Subject: [Qemu-devel] [PATCH v2 23/26] target/arm: Add allocation tag storage for user mode X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- v2: Add the x-tagged-pages cpu property --- target/arm/cpu.h | 1 + target/arm/cpu64.c | 18 ++++++++++++++++++ target/arm/mte_helper.c | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) -- 2.17.2 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 2626af4a9c..ec5ddfbacc 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -910,6 +910,7 @@ struct ARMCPU { #ifdef CONFIG_USER_ONLY bool guarded_pages; + bool tagged_pages; #endif QLIST_HEAD(, ARMELChangeHook) pre_el_change_hooks; diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index c5675fe7d1..53a7d92c95 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -293,6 +293,18 @@ static void aarch64_cpu_set_guarded_pages(Object *obj, bool val, Error **errp) ARMCPU *cpu = ARM_CPU(obj); cpu->guarded_pages = val; } + +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); @@ -380,6 +392,12 @@ static void aarch64_max_initfn(Object *obj) aarch64_cpu_set_guarded_pages, NULL); object_property_set_description(obj, "x-guarded-pages", "Set on/off GuardPage bit for all pages", NULL); + + 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 93f7cccee2..ad2902472d 100644 --- a/target/arm/mte_helper.c +++ b/target/arm/mte_helper.c @@ -53,8 +53,45 @@ static uint64_t strip_tbi(CPUARMState *env, uint64_t ptr) static uint8_t *allocation_tag_mem(CPUARMState *env, uint64_t ptr, bool write, uintptr_t ra) { +#ifdef CONFIG_USER_ONLY + ARMCPU *cpu = arm_env_get_cpu(env); + uint64_t clean_ptr = strip_tbi(env, ptr); + uint8_t *tags; + uintptr_t index; + int flags; + + flags = page_get_flags(clean_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(clean_ptr); + if (tags == NULL) { + size_t alloc_size = TARGET_PAGE_SIZE >> (LOG2_TAG_GRANULE + 1); + tags = page_alloc_target_data(clean_ptr, alloc_size); + assert(tags != NULL); + } + + index = extract32(clean_ptr, LOG2_TAG_GRANULE + 1, + TARGET_PAGE_BITS - LOG2_TAG_GRANULE - 1); + return tags + index; +#else /* Tag storage not implemented. */ return NULL; +#endif } static int get_allocation_tag(CPUARMState *env, uint64_t ptr, uintptr_t ra)