From patchwork Fri Dec 14 05:24:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 153764 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1683023ljp; Thu, 13 Dec 2018 21:44:52 -0800 (PST) X-Google-Smtp-Source: AFSGD/WzdlTFV9zqsNb9aBHvq0mZust5xKHRgeVBf5fj1x0pertH+kzIHbcH7QIAkho0IHcK4Mo/ X-Received: by 2002:ac8:278a:: with SMTP id w10mr1528659qtw.149.1544766291971; Thu, 13 Dec 2018 21:44:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544766291; cv=none; d=google.com; s=arc-20160816; b=XbTcdcm2FDvWFircwnVmejC225XRafhNf1SgXoFAYLNRW9npoKJGg87vnK0BDo1QZF bki6LebULa0D2LdY/+mn7SFkXII3aHk9eviNYeWssQlNHAQGz7QxYNkL/HRoKuyOE02h IxBwdZVhbdS7a7Zo2cf6gy6gy0z4IeWpKQ7/e+YcQiWIHr9Jc4T2hYNNI78m5eItVxZJ /O83+PdwDuarImAsMac4XaqHz7XCkuF3/SgQ82t7+3JZmUXn3NMqd4jD4Ahl7DOA0WaF gpiYvpo3aztq3G+cKVOIQ4w1Ur2kpokNYCs6RUgrRLcz2JsONM1uLKhprt+Jz5RcPMGY 5HAg== 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=D0KeTZX6NEE2gCU4mzJT7v+AQLT+zWTV0IKozs79+gI=; b=o3KVuwFSevfknFJ/j84j4eGk7279XjQbS7vHJJi9lBERoortEA1ROyfPG7axJs+i5h 1WDjcGbBpZcMBPBASkwoL+qKHOdETr631RFs+WaLTYXugX8N1fZJa6c2ujHd40FxYbPu T97Cbd4ow0pV7fqqcELBcepGrR1YoTNWP47FILZTjshhX/+xUWzRg3p7pFEJTDQTCi/p jqzfVih2sRinCnSEeNg+SjzqUJA5peHrlfm4Gt9Q8iD07A1Tuehstjux7+xrapSGImR6 pc8ws7udTafqNllTh+9Gb7QsiU14jwmdclh7JkEaBNUABThR1LTsZ5dn+pmC4fz5CQ+z HmHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=HIkc+LLx; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.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. [208.118.235.17]) by mx.google.com with ESMTPS id o14si982234qtb.200.2018.12.13.21.44.51 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 13 Dec 2018 21:44:51 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=HIkc+LLx; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.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]:59533 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXgHL-0005E6-IF for patch@linaro.org; Fri, 14 Dec 2018 00:44:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55886) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXfxu-0004me-6U for qemu-devel@nongnu.org; Fri, 14 Dec 2018 00:24:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gXfxq-0005VA-Bw for qemu-devel@nongnu.org; Fri, 14 Dec 2018 00:24:46 -0500 Received: from mail-ot1-x344.google.com ([2607:f8b0:4864:20::344]:38618) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gXfxp-0005TQ-00 for qemu-devel@nongnu.org; Fri, 14 Dec 2018 00:24:41 -0500 Received: by mail-ot1-x344.google.com with SMTP id e12so4318454otl.5 for ; Thu, 13 Dec 2018 21:24:38 -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=D0KeTZX6NEE2gCU4mzJT7v+AQLT+zWTV0IKozs79+gI=; b=HIkc+LLxgdmXub+WxKLrtRj6FZ3wU8VNZOJmDLd9Z1N9fp9KuS/Xj6rI0zjgaGv4x2 Fd/SVW2kVTjCEHHqVJA+cTvfdgwBZfRDlpouwhn6W9lCROmMRXOUspKkdkCBUjuFNA8o rJfA8l7cONIscYnjwc5ARC4qumLOZmq8EEO7c= 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=D0KeTZX6NEE2gCU4mzJT7v+AQLT+zWTV0IKozs79+gI=; b=X2CwV21RuNriY+j/TnesNXnB6tW7K7zYhz9kVVVtPsdb1ruB1Ty1ZpIdl3wkb9y/OM gCTcourozaAU7PnZInhet/HpqDwo3YRPBkIl/LhjteUVzW4SVQmNYr/MUV817GwTzT8Q JQ/fVHDI60lwSm79q3DAOwj+i/4cRdNdK0aixdw9G8S5dYabzoo0MGqK8veoflfaxe7g h2o9to5jTXclAMx7KAiTwa2n2eLmv+Xw4Zx9/bbDaS9din/sCClBIH0IMxHhJj+ZUcCU KTtavwiSVc9oJQUQ8q8qgCvztIyZMdTCOY771xWCG5F4+/xq7H0Ix2jGGXR2B2s3xqCa q4cQ== X-Gm-Message-State: AA+aEWbplZI8O9MYwH5zQy8APMFVye7x1lfK/ZZCgyLQBJg1rXFTj3pw +D2QXCE5wshVOLPc2iBjFK26/kw1m9Qi5w== X-Received: by 2002:a05:6830:1584:: with SMTP id i4mr1089061otr.116.1544765077950; Thu, 13 Dec 2018 21:24:37 -0800 (PST) Received: from cloudburst.twiddle.net ([187.217.227.243]) by smtp.gmail.com with ESMTPSA id r1sm1845379oti.44.2018.12.13.21.24.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Dec 2018 21:24:37 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 13 Dec 2018 23:24:05 -0600 Message-Id: <20181214052410.11863-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181214052410.11863-1-richard.henderson@linaro.org> References: <20181214052410.11863-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::344 Subject: [Qemu-devel] [PATCH v2 22/27] 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. Signed-off-by: Richard Henderson --- target/arm/helper-a64.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) -- 2.17.2 Reviewed-by: Peter Maydell diff --git a/target/arm/helper-a64.c b/target/arm/helper-a64.c index 87cff7d96a..19486b9677 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, 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 ^= 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 + 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)