From patchwork Fri Dec 7 10:36:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 153123 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp343591ljp; Fri, 7 Dec 2018 02:48:26 -0800 (PST) X-Google-Smtp-Source: AFSGD/WKVlZnDAZCIiNNwlxvhk6du2RZR9pyV8tyvZQR/H7fZ0wX5ELHT0TeSj9j1GcEU/xzW3gO X-Received: by 2002:a37:654b:: with SMTP id z72mr1349409qkb.226.1544179706134; Fri, 07 Dec 2018 02:48:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544179706; cv=none; d=google.com; s=arc-20160816; b=OYGYJkPUcPgsEE+96v7QwAb/K7yv7JvptTkE67BkuINmF0X2V/P9AtNT8DWpmq0WHo oGVcb/jWfLkNbZCb32qNNY+v+Q95StRSG+wIRb6DSaqEVFhLQfsMTgKkMipbBC1GENjA 8rcE1/wIuhAjwI2HNyODegFB0fCMjHVNXqNZ1nVsrWfrISAfgsC9sExNqsMGrvUyxgai whsKkrYeQyiAx9Q85q2ZcinU7iXtiv66z//M0V00kPAGeDYUNAzk26zkNnQYW3UAVqw/ t7V495jXTZTu3xzmZZxqahDk90rZXShPA9gCN6G28QFeiwrSS579X4nxp9JkCXUArU6T o/7g== 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=mluYwWpzbSidK6xqnbY4fc6xxXyLqYViTVIwxlRneVs=; b=SYfksjFBQdPSoECgfzJM34qxj3xU2AgQGMAAuOaTI0Z+PhlNAtV+QOGWxizOYK0byr iIhimIEgz8ik3L7ZdRz6GZbr5IPDY9sdFIrLRGMbiY3CdU17IKPzXiKlvj0CXF8tAszK 5qy0FpXKsAMzHD+KJd3elZ7kL3mraUqKFqgETgosB2h53tRvkEc4EO57slqZGxdqRJgZ Nv0+CjLp8JiqZFH6D4sKK7DUwGlVA5V2tdxKeAV8nIBn27OYIM8l0lWahIWeeNRH/vFR Lb40WJL91gYwr17GfvD7j9MEeAt2+gkXKaoa5wXySB3q4mQmWhboEh+56RRqJYWiP/xu BtSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=VERZwzWN; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id n83si1962297qkl.183.2018.12.07.02.48.25 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 07 Dec 2018 02:48:26 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=VERZwzWN; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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]:45313 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gVDgH-0005R9-JB for patch@linaro.org; Fri, 07 Dec 2018 05:48:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59299) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gVDVP-0008Mu-3h for qemu-devel@nongnu.org; Fri, 07 Dec 2018 05:37:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gVDVN-0007xm-6V for qemu-devel@nongnu.org; Fri, 07 Dec 2018 05:37:10 -0500 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]:41787) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gVDVM-0007vI-V5 for qemu-devel@nongnu.org; Fri, 07 Dec 2018 05:37:09 -0500 Received: by mail-oi1-x22b.google.com with SMTP id j21so2985213oii.8 for ; Fri, 07 Dec 2018 02:37:07 -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=mluYwWpzbSidK6xqnbY4fc6xxXyLqYViTVIwxlRneVs=; b=VERZwzWNIYP3tKJNbCIpC+sVX+JmL6s2Hcu87dpx3NNjUBqYeZywF1WvAglL5zMXUf o/92TZaoM9MufJVb5JgcUsbeoKQjNJ1kc6UHzT88IOTJ5Y5o6h7sKua5T+frcMlyz/VT Li1J+iKM8sg1D7tK8KigrSGIgVFAKh5sbaQr8= 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=mluYwWpzbSidK6xqnbY4fc6xxXyLqYViTVIwxlRneVs=; b=Ba4HgaHRe7NdMZlW4+T144nijBLhTAOTJobk5SqjimqtqQsLQ6FfkB6xTuA3EpM2T6 SR7UTmgTij/kbqVkDPLGe+8bQiOmtPFDTvcRXfiC35QbMNK4jjNyq0byqtzfw8ZpxqNT QbMHOw2S5qGQM+BQTZgO5/eJUlrFlsyWWl1qfaMb02H1YJakGeo3iWYCIrI7M52u0H6a 3fp0fBc/afxLnnALhWbcGozrdNps6ISjcPuaJUTJhjG9YZstYRqLcEKXDGsP5ENhYbBg 3BmEj8C39NJu2WylUJ5g6HToLF7pb1dftsHOcq/ea7NH12guP0BKsQrfi5ThHnVzQfut eoRQ== X-Gm-Message-State: AA+aEWYtePdOTzvefGGo5tayFeQhwSI6JB2cg1gA0UrccuTuWnJGJHHk AmLW13d1x3e+9gz/b9UsLS2oB6noSw4= X-Received: by 2002:aca:53cd:: with SMTP id h196mr959337oib.355.1544179026640; Fri, 07 Dec 2018 02:37:06 -0800 (PST) Received: from cloudburst.twiddle.net (172.189-204-159.bestel.com.mx. [189.204.159.172]) by smtp.gmail.com with ESMTPSA id c19sm2037594otl.16.2018.12.07.02.37.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Dec 2018 02:37:06 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 7 Dec 2018 04:36:26 -0600 Message-Id: <20181207103631.28193-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181207103631.28193-1-richard.henderson@linaro.org> References: <20181207103631.28193-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::22b Subject: [Qemu-devel] [PATCH 21/26] target/arm: Implement pauth_addpac 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, ramana.radhakrishnan@arm.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This is not really functional yet, because the crypto is not yet implemented. This, however follows the AddPAC pseudo function. Signed-off-by: Richard Henderson --- target/arm/helper-a64.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) -- 2.17.2 diff --git a/target/arm/helper-a64.c b/target/arm/helper-a64.c index 2c14a71f03..28bdf6f0b2 100644 --- a/target/arm/helper-a64.c +++ b/target/arm/helper-a64.c @@ -1066,7 +1066,45 @@ static uint64_t pauth_computepac(uint64_t data, uint64_t modifier, static uint64_t pauth_addpac(CPUARMState *env, uint64_t ptr, uint64_t modifier, uint64_t *key, bool data) { - g_assert_not_reached(); /* FIXME */ + ARMMMUIdx mmu_idx = arm_mmu_idx(env); + ARMVAParameters param = aa64_va_parameters(env, ptr, mmu_idx, data); + uint64_t pac, ext_ptr, ext, test; + int bot_bit, top_bit; + + /* If tagged pointers are in use, use ptr<55>, otherwise ptr<63>. */ + if (param.tbi) { + ext = sextract64(ptr, 55, 1); + } else { + ext = sextract64(ptr, 63, 1); + } + + /* Build a pointer with known good extension bits. */ + top_bit = 64 - 8 * param.tbi; + bot_bit = 64 - param.tsz; + ext_ptr = deposit64(ptr, bot_bit, top_bit - bot_bit, ext); + + pac = pauth_computepac(ext_ptr, modifier, key[1], key[0]); + + /* Check if the ptr has good extension bits and corrupt the + * pointer authentication code if not. + */ + test = sextract64(ptr, bot_bit, top_bit - bot_bit); + if (test != 0 && test != -1) { + pac ^= 1ull << (top_bit - 1); + } + + /* Preserve the determination between upper and lower at bit 55, + * and insert pointer authentication code. + */ + if (param.tbi) { + ptr &= ~MAKE_64BIT_MASK(bot_bit, 55 - bot_bit); + pac &= MAKE_64BIT_MASK(bot_bit, 54 - bot_bit); + } else { + ptr &= MAKE_64BIT_MASK(0, bot_bit - 1); + pac &= ~(MAKE_64BIT_MASK(55, 1) | MAKE_64BIT_MASK(0, bot_bit - 1)); + } + ext &= MAKE_64BIT_MASK(55, 1); + return pac | ext | ptr; } static uint64_t pauth_original_ptr(uint64_t ptr, ARMVAParameters param)