From patchwork Thu Jan 28 22:41:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 372637 Delivered-To: patch@linaro.org Received: by 2002:a02:a60d:0:0:0:0:0 with SMTP id c13csp1669055jam; Thu, 28 Jan 2021 14:55:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJwV7ZZF3QOA2jZjibGryKY2C34s5MfZ6c2YvAtc314Vw7yFWbGE56xRNfO+ZvMMS/gN9Vpd X-Received: by 2002:a25:ac5a:: with SMTP id r26mr2236423ybd.336.1611874545532; Thu, 28 Jan 2021 14:55:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611874545; cv=none; d=google.com; s=arc-20160816; b=OIHy+ezQ/Bjq0JD4Ef5y+Y/C4IzylEMAfuogyzXTD2VqU+jPm90SwBTP/r2HCeJg/R W6BQ86noZMbn3LiarnrxlhzgQQMm78+su38z+Z9L2TjBsNv0ApRWYMyJQctVBJvHLgvP f5uvCETTIDc7ATxeyE4aVmyB9vFD7kVfDpWV6Vc1XD3SN9/pshhvuge7G2PfdZidjy7l 9mSNVR6xgfZJ/8ra2wE8828RbZvR4+lXzsIyhYV1qym7OeBDL51ZCpa5BSQgnkSIDguC JqY6Og1BVkPvRpBt+KYjGt4g+c/dCAJQy1ugajU5AH9qOjsyeydYeYb8J6UNEv6wrx0o LgAw== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=5bvrCnDcElA75br2YmmksQwg8lUlxPa22qY4Fj6h+lg=; b=iN+SLHb1uv2xTemkXjWAohub//z970ipNnkojd15uJfkgQiiucW+/BvxK/yYOrC0jm YYdl73gSB7/FL5Hma0KYfvYDj4ewI/7ENnG8hI0d4F1AyLXEzxDM5rgupC+0cTvXrcLw vE5QDRa0qqiPZFrZrWkMC6T6BdjaiXJ29sMIBXGPCFbxcU7xlmKRlFKtHKyCG5Boybzk 66jWQ7V50ZdT3IXmOcwq1b0nn8cVOydlXTjMZlhfJCj1M0OodO4zr4efrqRG3N/K7UAd SwVXGPPo/r9zRYcU32cMk+rdpk08JufwuvPy5pzMV8yoPc0gy2kS4opEjKTBN9l6E2fP pXwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=M0SbjigO; 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 a7si6861605ybi.4.2021.01.28.14.55.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Jan 2021 14:55:45 -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=M0SbjigO; 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 ([::1]:49222 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5GCX-00034Y-1K for patch@linaro.org; Thu, 28 Jan 2021 17:55:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33318) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l5Fze-0005hy-4e for qemu-devel@nongnu.org; Thu, 28 Jan 2021 17:42:26 -0500 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]:40928) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l5FzP-0008BO-OF for qemu-devel@nongnu.org; Thu, 28 Jan 2021 17:42:25 -0500 Received: by mail-pg1-x52c.google.com with SMTP id b21so5277259pgk.7 for ; Thu, 28 Jan 2021 14:42:10 -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 :mime-version:content-transfer-encoding; bh=5bvrCnDcElA75br2YmmksQwg8lUlxPa22qY4Fj6h+lg=; b=M0SbjigOnaVcix0YSJ9WpeivyMKfPUPSwXYyLXDBI4l6ARdj1qYWsQgn23n8/xgCkl EhW/1W58NUhWiKOLTavHBp5kplKDyi6rN+mozKwK3teETJ/andTw5UMaJuQn424lcFBa Whyj98QH2XRPMoYRKOscRyvzXK8HZPG/HJTEhgFbZVLhXosP0QhuChjL1Ze2b83CUafa HgSNRZn85T9mPtHrFtnsm6zUWDD/00HJQp4Oy7ezq16zihRJkvVO1pjgBpiQKdsBO6S1 UzUgyaifN74wizJ83ZSX4OQ+SKYCqoaLNdg5J6TSkGyyeXhRWvEQRi38yNfDSjANJ/UT wdQg== 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:mime-version:content-transfer-encoding; bh=5bvrCnDcElA75br2YmmksQwg8lUlxPa22qY4Fj6h+lg=; b=XDGm9DFmvEQ3wlJd2c6wiC3vQv9JLWD9g2t6z9ReduQmCmbFdeRmJNtdEhMP1d5OYG 1466qae5BZGjg5pQlvMF078SHUqsbp0n4fMfZ/oK9E7+z7qDY+SakszHYRNl6vVN/OZP c//Hr3+8XvbgJrhYhJiykm1R//WsHzAwk4D6WjP/eBToHFIAR++DI5PstCB7emBxhDZ4 3GZ3BhYB5Z62tN1Ch0AZAqplulYj6QlkywUV+0ifqWJzlkGJo5zgFk8vSEbQwMfTym1N jJUIxs4Qw1vKr2MwLljJRZDIBsmlZ8HOb9itZ6MpqswLilYWiLcDHn34k9lWjiMjyXyU jhuQ== X-Gm-Message-State: AOAM53101b+pEN0CKF8ksjkgzKf9kETH4pM3CGTMKGeUZzoFOFcmiZde tPmew/EHa5iJVUWrEQK7FiogxaL36Li55NQP X-Received: by 2002:a63:c441:: with SMTP id m1mr1512364pgg.353.1611873729575; Thu, 28 Jan 2021 14:42:09 -0800 (PST) Received: from localhost.localdomain (cpe-66-27-222-29.hawaii.res.rr.com. [66.27.222.29]) by smtp.gmail.com with ESMTPSA id m10sm6042358pjs.25.2021.01.28.14.42.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Jan 2021 14:42:08 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v4 15/23] linux-user/aarch64: Implement PR_MTE_TCF and PR_MTE_TAG Date: Thu, 28 Jan 2021 12:41:33 -1000 Message-Id: <20210128224141.638790-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210128224141.638790-1-richard.henderson@linaro.org> References: <20210128224141.638790-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52c; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" These prctl fields are required for the function of MTE. Signed-off-by: Richard Henderson --- linux-user/aarch64/target_syscall.h | 9 ++++++ linux-user/syscall.c | 43 +++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) -- 2.25.1 Reviewed-by: Peter Maydell diff --git a/linux-user/aarch64/target_syscall.h b/linux-user/aarch64/target_syscall.h index 820601dfcc..76f6c3391d 100644 --- a/linux-user/aarch64/target_syscall.h +++ b/linux-user/aarch64/target_syscall.h @@ -33,5 +33,14 @@ struct target_pt_regs { #define TARGET_PR_SET_TAGGED_ADDR_CTRL 55 #define TARGET_PR_GET_TAGGED_ADDR_CTRL 56 # define TARGET_PR_TAGGED_ADDR_ENABLE (1UL << 0) +/* MTE tag check fault modes */ +# define TARGET_PR_MTE_TCF_SHIFT 1 +# define TARGET_PR_MTE_TCF_NONE (0UL << TARGET_PR_MTE_TCF_SHIFT) +# define TARGET_PR_MTE_TCF_SYNC (1UL << TARGET_PR_MTE_TCF_SHIFT) +# define TARGET_PR_MTE_TCF_ASYNC (2UL << TARGET_PR_MTE_TCF_SHIFT) +# define TARGET_PR_MTE_TCF_MASK (3UL << TARGET_PR_MTE_TCF_SHIFT) +/* MTE tag inclusion mask */ +# define TARGET_PR_MTE_TAG_SHIFT 3 +# define TARGET_PR_MTE_TAG_MASK (0xffffUL << TARGET_PR_MTE_TAG_SHIFT) #endif /* AARCH64_TARGET_SYSCALL_H */ diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 46526f50b0..d645eb8f44 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -10967,17 +10967,53 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, { abi_ulong valid_mask = TARGET_PR_TAGGED_ADDR_ENABLE; CPUARMState *env = cpu_env; + ARMCPU *cpu = env_archcpu(env); + + if (cpu_isar_feature(aa64_mte, cpu)) { + valid_mask |= TARGET_PR_MTE_TCF_MASK; + valid_mask |= TARGET_PR_MTE_TAG_MASK; + } if ((arg2 & ~valid_mask) || arg3 || arg4 || arg5) { return -TARGET_EINVAL; } env->tagged_addr_enable = arg2 & TARGET_PR_TAGGED_ADDR_ENABLE; + + if (cpu_isar_feature(aa64_mte, cpu)) { + switch (arg2 & TARGET_PR_MTE_TCF_MASK) { + case TARGET_PR_MTE_TCF_NONE: + case TARGET_PR_MTE_TCF_SYNC: + case TARGET_PR_MTE_TCF_ASYNC: + break; + default: + return -EINVAL; + } + + /* + * Write PR_MTE_TCF to SCTLR_EL1[TCF0]. + * Note that the syscall values are consistent with hw. + */ + env->cp15.sctlr_el[1] = + deposit64(env->cp15.sctlr_el[1], 38, 2, + arg2 >> TARGET_PR_MTE_TCF_SHIFT); + + /* + * Write PR_MTE_TAG to GCR_EL1[Exclude]. + * Note that the syscall uses an include mask, + * and hardware uses an exclude mask -- invert. + */ + env->cp15.gcr_el1 = + deposit64(env->cp15.gcr_el1, 0, 16, + ~arg2 >> TARGET_PR_MTE_TAG_SHIFT); + arm_rebuild_hflags(env); + } return 0; } case TARGET_PR_GET_TAGGED_ADDR_CTRL: { abi_long ret = 0; CPUARMState *env = cpu_env; + ARMCPU *cpu = env_archcpu(env); if (arg2 || arg3 || arg4 || arg5) { return -TARGET_EINVAL; @@ -10985,6 +11021,13 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, if (env->tagged_addr_enable) { ret |= TARGET_PR_TAGGED_ADDR_ENABLE; } + if (cpu_isar_feature(aa64_mte, cpu)) { + /* See above. */ + ret |= (extract64(env->cp15.sctlr_el[1], 38, 2) + << TARGET_PR_MTE_TCF_SHIFT); + ret = deposit64(ret, TARGET_PR_MTE_TAG_SHIFT, 16, + ~env->cp15.gcr_el1); + } return ret; } #endif /* AARCH64 */