From patchwork Fri Jan 25 22:57:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 156652 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp920439jaa; Fri, 25 Jan 2019 15:21:35 -0800 (PST) X-Google-Smtp-Source: ALg8bN6dRF8ktKnR3uNtl7FLDfMC2hLLzS0/+lto4fNEb7ghp+5gzCPZX91Zj2kvknx08G55FnFp X-Received: by 2002:a1c:7706:: with SMTP id t6mr8025277wmi.57.1548458495540; Fri, 25 Jan 2019 15:21:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548458495; cv=none; d=google.com; s=arc-20160816; b=kD3ZU7tnPMKthFo7YPx092r4k7e1FfY0q/CbKh5LXqu46tRlzqTz15hvNfVVq8/om5 M687SUwAD6UR2NTc5rSBdshbaZW2PL0q/dW4htb5XvtLaIsatZgfwSHuSE8ORLjZT17p JGVUvzwbWnWYMS8W4/f5sxudKNBxs02X0VIqlSK66Pg9L1Jq/VQboxU0AY/Xd2+PkeGV VLNfMjEwd0H0H7QThnCOLUm3IM45IKJfM2xCuE+9cG2tNy2fe8TycxtLsmbwpvrmM4At uX+2z3WmjrlRWs4Ot1GshalopGlB/7SzBP07Vmm6FdXhmsmG9vfWkS5496Toq/IgljxP gwiA== 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=FuRe0FUWyPAaj4JfHybaq6PMizO+TXX2VIZzLmK06sE=; b=vcNbeJ7fSCWeE7oJMPvt0nRl4F/Ge3RAkeOVGwY/0k0INNz9uz+ebV2AK3m19h1Z8k iWX1P+naK8AL03hw2L56J/AAlCtcXkpdvk1+GlP6P9OJ9Q0q66KOUD7laIUh6ppt31wU 0BRQr7B1RKCEYey33R133TWb4DR7MIuyihtLNj1Yx+gkT4l+0J4MQe2qyEmO3GaV0lJl E4ca5PHI2wt+QMYWmMg0bHi8EAUFmInfmUw612M7yMjkroZATTwKiRLDG8NYxhdGJln0 rA043sh46W1wbN96jVOsp1dsPbqtPpGKywWcyOETvQhyLwd+PovaxVntt1laGkZAOX/6 fBxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=d0BQnnup; 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 f196si44252384wme.198.2019.01.25.15.21.35 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 25 Jan 2019 15:21:35 -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=d0BQnnup; 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]:52322 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gnAn0-0002Ow-Hc for patch@linaro.org; Fri, 25 Jan 2019 18:21:34 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37822) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gnAe7-0005QF-Rg for qemu-devel@nongnu.org; Fri, 25 Jan 2019 18:12:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gnAPc-0005NL-Iu for qemu-devel@nongnu.org; Fri, 25 Jan 2019 17:57:25 -0500 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:35029) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gnAPc-0005MS-6r for qemu-devel@nongnu.org; Fri, 25 Jan 2019 17:57:24 -0500 Received: by mail-pl1-x644.google.com with SMTP id p8so5208196plo.2 for ; Fri, 25 Jan 2019 14:57:24 -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=FuRe0FUWyPAaj4JfHybaq6PMizO+TXX2VIZzLmK06sE=; b=d0BQnnupPDyXVes3guxFslEsJ+tcEGkPoE4viIOnk20+q1JThQMNjx45+sr8mNNifM ZaXv5Ja0wrfpTlmyf+vltkalWwxkAOgrettFgHrio7wh0h2x975Vh0QUN3OaIMqy3uBB eI+/kWoRm2lNdgngus9QuPXVleKF6zSlhq/aY= 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=FuRe0FUWyPAaj4JfHybaq6PMizO+TXX2VIZzLmK06sE=; b=Fv/LA5H9iW6w0Ppk8T3Yt2W2YPgZLjwLRcSL1nZf2VIBbvolmtC0ebAHc9ax1htLm+ OQatsbMqMXVbpTUa/cTs4A5gfxpxu7+cn/ZWdGQNftonqOmvNkrpZAy5sllYgOmGFIw9 NvRe4js0hfiRa7FWH77d98WrNahd3WKzCEy4tKg+l6NPjb3DGcZi8+UH4XP0AXXPqvzb mnCoLUcH4cBaOz0RApCBAqDochbvu9aFgHejqSB256kZbp+043sxYgHgtzDm/GyiIQwr 4+hLslkp7BdS0fXUH0xMCqTsgl9GggB+Q5EHmz64wiyfvxUdLDys+zGWv6oL/FvS7mRQ 8F+A== X-Gm-Message-State: AJcUukeqoEgPASMsmIFDzUooeG1/+UDI86brvb+APCFyCgtNRk3JLi1k giHFrU2difA4pIpyI7JGduwsoPyQUJc= X-Received: by 2002:a17:902:a601:: with SMTP id u1mr12883280plq.77.1548457042891; Fri, 25 Jan 2019 14:57:22 -0800 (PST) Received: from cloudburst.twiddle.net (97-126-115-157.tukw.qwest.net. [97.126.115.157]) by smtp.gmail.com with ESMTPSA id c7sm39148321pfh.18.2019.01.25.14.57.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 25 Jan 2019 14:57:22 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 25 Jan 2019 14:57:12 -0800 Message-Id: <20190125225714.10234-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190125225714.10234-1-richard.henderson@linaro.org> References: <20190125225714.10234-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 4/6] linux-user: Initialize aarch64 pac keys 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 Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Initialize the keys to a non-zero value on process start. Signed-off-by: Richard Henderson --- linux-user/aarch64/target_syscall.h | 2 ++ linux-user/aarch64/cpu_loop.c | 31 +++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) -- 2.17.2 diff --git a/linux-user/aarch64/target_syscall.h b/linux-user/aarch64/target_syscall.h index 205265e619..937fd7989e 100644 --- a/linux-user/aarch64/target_syscall.h +++ b/linux-user/aarch64/target_syscall.h @@ -22,4 +22,6 @@ struct target_pt_regs { #define TARGET_PR_SVE_SET_VL 50 #define TARGET_PR_SVE_GET_VL 51 +void arm_init_pauth_key(ARMPACKey *key); + #endif /* AARCH64_TARGET_SYSCALL_H */ diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c index 65d815f030..d75fd9d3e2 100644 --- a/linux-user/aarch64/cpu_loop.c +++ b/linux-user/aarch64/cpu_loop.c @@ -147,10 +147,29 @@ void cpu_loop(CPUARMState *env) } } +static uint64_t arm_rand64(void) +{ + int shift = 64 - clz64(RAND_MAX); + int i, n = 64 / shift + (64 % shift != 0); + uint64_t ret = 0; + + for (i = 0; i < n; i++) { + ret = (ret << shift) | rand(); + } + return ret; +} + +void arm_init_pauth_key(ARMPACKey *key) +{ + key->lo = arm_rand64(); + key->hi = arm_rand64(); +} + void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) { - CPUState *cpu = ENV_GET_CPU(env); - TaskState *ts = cpu->opaque; + ARMCPU *cpu = arm_env_get_cpu(env); + CPUState *cs = CPU(cpu); + TaskState *ts = cs->opaque; struct image_info *info = ts->info; int i; @@ -172,6 +191,14 @@ void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) } #endif + if (cpu_isar_feature(aa64_pauth, cpu)) { + arm_init_pauth_key(&env->apia_key); + arm_init_pauth_key(&env->apib_key); + arm_init_pauth_key(&env->apda_key); + arm_init_pauth_key(&env->apdb_key); + arm_init_pauth_key(&env->apga_key); + } + ts->stack_base = info->start_stack; ts->heap_base = info->brk; /* This will be filled in on the first SYS_HEAPINFO call. */