From patchwork Fri Jan 18 14:57:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 155965 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3373625jaa; Fri, 18 Jan 2019 07:18:06 -0800 (PST) X-Google-Smtp-Source: ALg8bN6mgHzqw/7M05IwikVwnpkQPa8HI/t4XRE+mAfGWVcb9zom62LKwQLPzNlohtztRcDm7szK X-Received: by 2002:adf:f5d1:: with SMTP id k17mr18166244wrp.59.1547824686530; Fri, 18 Jan 2019 07:18:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547824686; cv=none; d=google.com; s=arc-20160816; b=a/V0lPkvZbziUI0OUdG907zC4k4uM+iGwYWu0vpFhEXDPqF+Wi1wnXoyGkkcHwA+6y mUmlgwPefk93YRJFuqpPsY01MVPIjvPR/wm3HurGA6gXrlDkEdZ0yW6e375qqO6RYTsw pAWmhm8CkFnZxncuSajqitQlabPnnpv32RkXSDhsymK8VGmMySudqIr8qj8K3xFGE0at 0KiUmoR9D87zbU2T1uul03r6NgxospftDaN21qEfZFPbQCq2qQvj55rO4XuL9sifn1Jj qwnqOu0dCX8UEnCX/jXrdQpJNcBBk14BzDEc1u+kWbwAmJif9Wi69d0jkqIR4AJ7wbE6 +lYg== 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=FgN4KxnXYSzYBlJdGlmsaKmMQ4A6TeXX6S1LT2yE+Eo=; b=M5QYO+3YxTrdHfWVlkkbf07UO2EELX99dqry6wxkph2AM35/WABIIBgPPDjJcQfCfL XNn/d/SSu37gmmgVprG6A32rGuD3T0O0A6uPo6rnGvBf5Z13Gzd5Q6b5LMr6/ZNlbZZK 68UI/5fyl+kszYAILEsQrYjVmQcDKPo1wmMYZfflCGYxeL8+rDZ28vpB2b2SRUkxD6pI PV7ARfDiIwaIWUib140wkq1fmT9BYTUGWWOqqtkSqNSkB+RIKZfI+2xiLQ1HOy7MLMON MHZsto2SCO9XyaEM9JVPBG1tv41rDGUlrZzcHfGIw1joTyLOUjXpK6FjtVyh7sqdtAs5 brgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=SVUKt+Vn; 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 c189si27184304wmd.73.2019.01.18.07.18.06 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 18 Jan 2019 07:18:06 -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=SVUKt+Vn; 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]:41262 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkVuH-00019D-Ea for patch@linaro.org; Fri, 18 Jan 2019 10:18:05 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43171) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkVba-0002qS-06 for qemu-devel@nongnu.org; Fri, 18 Jan 2019 09:58:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gkVbX-0007TH-3Y for qemu-devel@nongnu.org; Fri, 18 Jan 2019 09:58:45 -0500 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]:46685) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gkVbW-0007Sb-PN for qemu-devel@nongnu.org; Fri, 18 Jan 2019 09:58:42 -0500 Received: by mail-wr1-x42f.google.com with SMTP id l9so15349112wrt.13 for ; Fri, 18 Jan 2019 06:58:42 -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=FgN4KxnXYSzYBlJdGlmsaKmMQ4A6TeXX6S1LT2yE+Eo=; b=SVUKt+Vn9CnQRCbDqWudYGBi1ZdH8BgcQ8Imp1w6OoWYRikZ9EoFn9RPV6PvpR+PMV sJ8pvS2Tw340pArr3ujCP+rITB15rWNMT6o8uQZr2PAgDRVBOrcAmPob2E4ss3fOEnYG dhOyFThqWV1ygUmIxvpAu2NQydqIqK7+NwfYw= 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=FgN4KxnXYSzYBlJdGlmsaKmMQ4A6TeXX6S1LT2yE+Eo=; b=RQcfG88pN2w7AKsV7S91MzCYfoK9CTjSUE1+uAUuJomo5OG426Pjm6O7y3UzM1bYDy L2W4IcroSOfXOdFjJLLtDyarSrZAcVFMe0u4kmDxaaJsEwXf+mcXJrmJaztL6DNKh9bF khGZBbI27sypGIeKnU8bhzWZ2N3klGQQSzJEWO2Zq3dgFFtxNEwsNz6N1hgzpahu/V2H xPN5VPGZzrCBvfQyo+fSQps+ir0sGyoJ8+AAa/QNYjmzABlu+vVPBp6kPzBlZIpkjK6h SNndozr/iAxzl+obBV50WAxsf/dXrcvQoNVMndWafzbjlWakSBi1zmm4NdRx6KE9430Y kMPA== X-Gm-Message-State: AJcUukd8kD4HchgOqrOKhhBQRa8+7SZvr3eZ2xaTopM6Ifzw/jUbrCAT 5tG435uMvnGSXqdDRDo1M9gcp21aFrAM1g== X-Received: by 2002:adf:bb44:: with SMTP id x4mr17524497wrg.24.1547823521414; Fri, 18 Jan 2019 06:58:41 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id e27sm92094561wra.67.2019.01.18.06.58.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 18 Jan 2019 06:58:40 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 18 Jan 2019 14:57:46 +0000 Message-Id: <20190118145805.6852-31-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190118145805.6852-1-peter.maydell@linaro.org> References: <20190118145805.6852-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::42f Subject: [Qemu-devel] [PULL 30/49] 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson 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 Message-id: 20190108223129.5570-27-richard.henderson@linaro.org Signed-off-by: Peter Maydell --- target/arm/pauth_helper.c | 42 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) -- 2.20.1 diff --git a/target/arm/pauth_helper.c b/target/arm/pauth_helper.c index fa7707e0bfc..bc89dd8c111 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)