From nobody Fri Nov 7 02:09:52 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1544766329326402.37189995921403; Thu, 13 Dec 2018 21:45:29 -0800 (PST) Received: from localhost ([::1]:59536 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXgHw-0005v7-DC for importer@patchew.org; Fri, 14 Dec 2018 00:45:28 -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) 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) 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-Google-Smtp-Source: AFSGD/WXYi//b8S3UJYKncD0J2Rdo6fG1nEkhIZATj+jXKeHr/qVuo1vmXRg+GMiGuLi/bF0uHFqrw== X-Received: by 2002:a05:6830:1584:: with SMTP id i4mr1089061otr.116.1544765077950; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Peter Maydell --- target/arm/helper-a64.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) 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, uint= 64_t modifier, static uint64_t pauth_addpac(CPUARMState *env, uint64_t ptr, uint64_t modi= fier, ARMPACKey *key, bool data) { - g_assert_not_reached(); /* FIXME */ + ARMMMUIdx mmu_idx =3D arm_stage1_mmu_idx(env); + ARMVAParameters param =3D 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 =3D sextract64(ptr, 55, 1); + } else { + ext =3D sextract64(ptr, 63, 1); + } + + /* Build a pointer with known good extension bits. */ + top_bit =3D 64 - 8 * param.tbi; + bot_bit =3D 64 - param.tsz; + ext_ptr =3D deposit64(ptr, bot_bit, top_bit - bot_bit, ext); + + pac =3D pauth_computepac(ext_ptr, modifier, *key); + + /* Check if the ptr has good extension bits and corrupt the + * pointer authentication code if not. + */ + test =3D sextract64(ptr, bot_bit, top_bit - bot_bit); + if (test !=3D 0 && test !=3D -1) { + pac ^=3D 1ull << (top_bit - 1); + } + + /* Preserve the determination between upper and lower at bit 55, + * and insert pointer authentication code. + */ + if (param.tbi) { + ptr &=3D ~MAKE_64BIT_MASK(bot_bit, 55 - bot_bit + 1); + pac &=3D MAKE_64BIT_MASK(bot_bit, 54 - bot_bit + 1); + } else { + ptr &=3D MAKE_64BIT_MASK(0, bot_bit); + pac &=3D ~(MAKE_64BIT_MASK(55, 1) | MAKE_64BIT_MASK(0, bot_bit)); + } + ext &=3D MAKE_64BIT_MASK(55, 1); + return pac | ext | ptr; } =20 static uint64_t pauth_original_ptr(uint64_t ptr, ARMVAParameters param) --=20 2.17.2