From patchwork Fri Feb 1 16:06:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 157269 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp635039jaa; Fri, 1 Feb 2019 08:20:56 -0800 (PST) X-Google-Smtp-Source: ALg8bN60LrYCaVDQoCxVz031fTn7DP5disVSGE9YUN0sdHbF1rci9dks+DB6r2+PzNy5Q6L7RhM3 X-Received: by 2002:a5b:4e:: with SMTP id e14mr28161747ybp.421.1549038056853; Fri, 01 Feb 2019 08:20:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549038056; cv=none; d=google.com; s=arc-20160816; b=zRUO4qIRQw4YJbYFAvAY+HPGFErHKkIhjvHHCAaVsrbCgNtGNAo8QrzGAB8AcXtBJd McyrNYss2uZH2yKbh5quV/OERQgNqug0QjPXwTzLS+pVx/xjtm29q1OByL0nF6Nn6kDx aKpSWJy6YaynQ3tunn4q4cL+T7FxvwAJlcmW6XjX5rLpE/7S6ACjuNYA/Lbt5bAKhvhp a+NIPxjOHR9oyQX/Za/IRGn9g3IJVViDJRE3RaFyL0jgRmVQEmaxWlw3ca+OcC6x6j+s 336KCS+eE5YZMzvbfmvG4P67EMeF8DIYF3BSyyjgeTxcMxs+l4aao4zzN081JF0QzRgO M9oQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=S9FUP9pGHebXl7sDn0I1mEibMvbmCvvZtXtOqE6gWBM=; b=orvtJ8wOTZaHDwGiixA00fC4xlN1Uaaz12iHamZf8KkRnja3cnp5nUsUFoEIfEJNVK 2Q3npaWL6pKesPXFGRMolAUntRAon0RdDG9MviNWO9WjQ8+SCc3mDjCfT2Vf+K5I9eVI QmLA0krVeu83wsufhSNbHqQF8HGLHoIsyhqqPwr7jCcF8Fw040NwuzBBIud2WF5ocVfr n0lyaOaiOZKtM3zHhZtj+j22IfDMloHJTdk+NGVweGmuy9hPsJQQn313EyPuqJZOzOE+ HWie7/Chm1Qdo6uBmSdnBLz6rrA4UxTG4tokIeU5zCwSsnka1gqwmJigyTXe0w1E86mz Zk9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=GiBoDwsj; 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 p8si4912782yba.223.2019.02.01.08.20.56 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 01 Feb 2019 08:20:56 -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=GiBoDwsj; 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]:57403 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpbYm-0001eK-42 for patch@linaro.org; Fri, 01 Feb 2019 11:20:56 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58908) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpbMB-0008E7-5A for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:07:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpbM9-0003go-Bz for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:07:55 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:53733) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gpbM8-0003ew-Vp for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:07:53 -0500 Received: by mail-wm1-x343.google.com with SMTP id d15so6671851wmb.3 for ; Fri, 01 Feb 2019 08:07:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=S9FUP9pGHebXl7sDn0I1mEibMvbmCvvZtXtOqE6gWBM=; b=GiBoDwsj9OlyvGF6jztvTL9lZmAf8QXiZ5KOP0wbKcjkwUCPkeBSw1jT57bSzbHzKM QaXQQft6O0h+BLs/tKkCjEHqiGsjgSz8DDwQn+jEMe0iVhXOfyRAHilRmOMlkZ5VZTtQ Jn1GMdcO/T6JfuLCwO6EFU+0IcZQtYVrPV5O8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=S9FUP9pGHebXl7sDn0I1mEibMvbmCvvZtXtOqE6gWBM=; b=UX0mGVnLaRcuVsbq567St6Ebj7idGBvXCvOnUZ9ERrpkI1GwpN6ZRMEuVLtaRNaROv fcHHbqIDrxRQGTiL+x5UjqhQt4BeJT1OpOOx5N2pcmqzu1LofDJuObPGkFU0n/NfGjXd F7rs5O54pDRiZ/TJcK6et9Gamjz/VwtlPrAbsBnF6uuB13Po25mEuO3/HJnRK4cnAfPc WQpcOVBgX3ahg2fE75iwaX5A77X5FY+9n9RnLnM6zJ1P6vKXIexl+OBWwZE9IjACXFWh 0mzT0i73oEbiGqPstjTh4UIw2GGRRl8TDzvso75hJjYf2GKJRlCOG5JWsNQeDLp2v1uj +9Sg== X-Gm-Message-State: AHQUAuYuPdH9jhVeSCseuGOZPDTXmH5O+D0QSGbqZufnia1BGNW0KKTy +3BRWwZzWlyDFMEM4twOxx+jVRRY4QpuHw== X-Received: by 2002:a1c:f909:: with SMTP id x9mr3035548wmh.108.1549037268782; Fri, 01 Feb 2019 08:07:48 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id n6sm2847250wmk.9.2019.02.01.08.07.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Feb 2019 08:07:47 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 1 Feb 2019 16:06:48 +0000 Message-Id: <20190201160653.13829-43-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190201160653.13829-1-peter.maydell@linaro.org> References: <20190201160653.13829-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 Subject: [Qemu-devel] [PULL 42/47] 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Initialize the keys to a non-zero value on process start. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- linux-user/aarch64/target_syscall.h | 2 ++ linux-user/aarch64/cpu_loop.c | 31 +++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) -- 2.20.1 diff --git a/linux-user/aarch64/target_syscall.h b/linux-user/aarch64/target_syscall.h index 205265e619e..937fd7989e7 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 65d815f0300..d75fd9d3e24 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. */