From patchwork Tue Jan 8 22:31:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 155028 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp42902jaa; Tue, 8 Jan 2019 14:48:34 -0800 (PST) X-Google-Smtp-Source: ALg8bN5j4xOoQQqEaoUzE9GfoQ02pXIkLP40MN1h50Aya7vpHgtqQ3D82pWxAV2yCmJoHXOU44HS X-Received: by 2002:a1c:c87:: with SMTP id 129mr3008479wmm.116.1546987713946; Tue, 08 Jan 2019 14:48:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546987713; cv=none; d=google.com; s=arc-20160816; b=MTDd5l0JXSY5WmRUBBmk/DkzsWBJkuKitsSzAdb8trnFdTdyc1BFWjQRLDZbSS0o/V ZQbY7mlD04ihkw05EFKzCjxaXbovM420+BJ2Yqw/GhL5339PiYsxt92Pi9LMLdz9q7m+ sqbSfwz9/9Ri/tNf8wLVnPooKeJxdS/qdpx0OtPJaASeS8XYgTNPmGKCC3Fo1YqqVxS3 Toeg/xoo5tM4HssGio3jbzzSKijgUJQ2ty+LX6wbYEOdzu5GLqFKByTAeaWJLlgu2nKj Rd72dY7yVsh42vUZTwDrloEhJ0EWuQkkH5LqykHWrjnQTSaxeRSntBbnU34HmThW8lV8 4AYg== 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=m+Zcu5dZ/zmIPm21/MzZiFGJp7J+d+OfEJPTnePaGgs=; b=Bfbm1DP97akZvTyIcZw2ARrLvIv2W5PYm6ZX9VsNqb/fkPfFWCKWj7q+u3FptkdaBK 0M3CH3a74+gW52s4UAS3amo+sZzSse55ddCWJJnjdubp+N6mKXMtE0NVeXAo0AkJg8VJ kjeIsbLrHGGsB5dNtryC7lIAlsA9Rg+Rwt2cLR9MDKvHaY7iW4O5hxI4O+hYJhz8EIsB cvIHTnwhxFOL4r+BtT+k8eOWCygk7T74V9mz4pQtZTgEiqUCd4KvSbFOUCswrmFxlM2I A2XhBFN1sI8/kUJtdZRIsjMfez4qURn18zPPFczQefresl3qf+ma91MnXWIBAiyXpAIp U6DA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="F+F+/Iry"; 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 r16si34037202wrr.211.2019.01.08.14.48.33 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 08 Jan 2019 14:48:33 -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="F+F+/Iry"; 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]:43564 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gh0Ai-000649-Ne for patch@linaro.org; Tue, 08 Jan 2019 17:48:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:53050) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ggzvX-0000gq-IY for qemu-devel@nongnu.org; Tue, 08 Jan 2019 17:32:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ggzvU-0005IM-30 for qemu-devel@nongnu.org; Tue, 08 Jan 2019 17:32:49 -0500 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]:44978) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ggzvS-0005Ee-MJ for qemu-devel@nongnu.org; Tue, 08 Jan 2019 17:32:46 -0500 Received: by mail-pl1-x62b.google.com with SMTP id e11so2559099plt.11 for ; Tue, 08 Jan 2019 14:32:45 -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=m+Zcu5dZ/zmIPm21/MzZiFGJp7J+d+OfEJPTnePaGgs=; b=F+F+/Iry66hFS6DrVr0R1IQXHTWtE3wetOnVMr+DytvwsAK/RtXaBh+CzsgJZG1uG6 n+M97TaXIhQ3jyx1vS40/i2S0/6/8y7u4EaRVYa376PETDIZnaW1O9DzN5fBuh16FMVB H8uYn3KTknfIjY9J8gLR8ywer/FN3iH35droo= 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=m+Zcu5dZ/zmIPm21/MzZiFGJp7J+d+OfEJPTnePaGgs=; b=lUNOE/pylAJZ42tTX3AXs6qQF7ulO1TnnH6d+DusDuitDmli5NBxQNYjgPnBt30ZsA ngs1AfrkyXtuji17rcTOut9fNd/o8esKtwl4Bl9DeykW6YsHRT+SCAOmJRL5P7zuNF2z 30gjEW9NMGS2zS5KsJfQODIZOHpy7dUkjMJnfZqP6MN7Haul3ZXZPscx8+YgyEW29dd1 MMsE6r23ECeuZ0UDZaZFznEFG4w1NGw3y2JOYS8UZNsAxOHKj7sh+j7jkwRSi7++YbNA Fm1l+65sXgB0FDavrjw1E3P03928uuzFiB4/49nHNvj281jFiRA1pJsp9iRuFWgSwd4Z RyNQ== X-Gm-Message-State: AJcUukfMclEQMOxWVw3BoQ3JWl2CMAAIDAO2VlfrvxiygtRMqSQ+tS92 xWaH1gJuRnnCvbCvYadWNomoFR167SQ= X-Received: by 2002:a17:902:f24:: with SMTP id 33mr3614190ply.65.1546986763736; Tue, 08 Jan 2019 14:32:43 -0800 (PST) Received: from cloudburst.lan (2001-44b8-2176-c800-8cc6-2630-7d99-5ef1.static.ipv6.internode.on.net. [2001:44b8:2176:c800:8cc6:2630:7d99:5ef1]) by smtp.gmail.com with ESMTPSA id w128sm100686177pfw.79.2019.01.08.14.32.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Jan 2019 14:32:43 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 9 Jan 2019 08:31:24 +1000 Message-Id: <20190108223129.5570-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190108223129.5570-1-richard.henderson@linaro.org> References: <20190108223129.5570-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::62b Subject: [Qemu-devel] [PATCH v3 26/31] 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 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. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson ---- v3: Use MAKE_64BIT_MASK one more place. --- target/arm/pauth_helper.c | 42 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) -- 2.17.2 diff --git a/target/arm/pauth_helper.c b/target/arm/pauth_helper.c index fa7707e0bf..bc89dd8c11 100644 --- a/target/arm/pauth_helper.c +++ b/target/arm/pauth_helper.c @@ -35,7 +35,47 @@ static uint64_t pauth_computepac(uint64_t data, uint64_t modifier, static uint64_t pauth_addpac(CPUARMState *env, uint64_t ptr, uint64_t modifier, ARMPACKey *key, bool data) { - g_assert_not_reached(); /* FIXME */ + ARMMMUIdx mmu_idx = arm_stage1_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); + + /* + * 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 ^= MAKE_64BIT_MASK(top_bit - 1, 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 + 1); + pac &= MAKE_64BIT_MASK(bot_bit, 54 - bot_bit + 1); + } else { + ptr &= MAKE_64BIT_MASK(0, bot_bit); + pac &= ~(MAKE_64BIT_MASK(55, 1) | MAKE_64BIT_MASK(0, bot_bit)); + } + ext &= MAKE_64BIT_MASK(55, 1); + return pac | ext | ptr; } static uint64_t pauth_original_ptr(uint64_t ptr, ARMVAParameters param)