From patchwork Wed Aug 12 06:53:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 247628 Delivered-To: patch@linaro.org Received: by 2002:a92:cc90:0:0:0:0:0 with SMTP id x16csp97306ilo; Tue, 11 Aug 2020 23:54:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwYe5wBMPinD8dYvbtLOkAk8aiNeS9GJG6nJwqiPSTbQGjD6tVqmRB/0h9S3ilqufVo4/Ro X-Received: by 2002:a25:1683:: with SMTP id 125mr47086862ybw.145.1597215268045; Tue, 11 Aug 2020 23:54:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597215268; cv=none; d=google.com; s=arc-20160816; b=ZLo5G7ea04boB6i19GS8YQ2IoF+xYf5x4aEHi3EH1dcB1PVeELuczHnlQQj5RHd9+F oYE1kxISa0f7vY9tNPS7O/w5OL9vnZRm9ZyOki8KcCVi4d+rh4ktmQtz1Q/xVLZqEVMh ElKp20cTC1LBOtZjylY6hFXe1Awz3o7ckb1yzMkfm8PluGOiQHE480FVHaLvyoyaFRgz o6YU/WROmv408GbgAGIbpSvHVTj4nlXbdwv6rbVRljN1T5f1AARiwyug4eG/DT9nay6V Ib+kCvzNtiszr9kk4efo8+BaXblZF1TUplnTu8nFpze2ZCOfLw/TvK+FnY4UBDlD94xj 94yA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=j39crPjYqJGwIgrM7ErljlkD2SFiNa9r8wEicsqELGI=; b=J0l6WY+KB2YyUWOrUevEEbMX//g8H0Q4o8Ekhjwr3g+qbvQEbNh8wa2Bd+DvzAzvvj pT67vdbhuqlAN+A6RFHN0/lSFX4k4rk3ytIofkXVDK39EP7FJ+HJj/i15pDff+vhgmkX ew2QKlIeQ5MnGaf+dD94QzlEbX+pr/7JoL0PtykSZrZQPxekaM+ow0y7lh5Jm+zL7rDD 1EEQjlc8vyYeVd6M+mbAvha4RLMn3IPBHI7+DDkZoY3RdTHlDXYZkwpIrV/OJxMsJpEc V29SrmRXnBITcWiMzMAiWXwHNgUve/f62YHhQ8VxEO03r7WUxDG9KIOw42UmYA0Eu1gM huHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=LT5I2t6Q; 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 j82si1468992ybb.148.2020.08.11.23.54.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Aug 2020 23:54:28 -0700 (PDT) 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=LT5I2t6Q; 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 ([::1]:34612 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k5keZ-0005FV-HP for patch@linaro.org; Wed, 12 Aug 2020 02:54:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33790) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k5kdt-0005Dw-V1 for qemu-devel@nongnu.org; Wed, 12 Aug 2020 02:53:45 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:43301) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k5kds-00041C-BQ for qemu-devel@nongnu.org; Wed, 12 Aug 2020 02:53:45 -0400 Received: by mail-pg1-x542.google.com with SMTP id d19so535065pgl.10 for ; Tue, 11 Aug 2020 23:53:43 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=j39crPjYqJGwIgrM7ErljlkD2SFiNa9r8wEicsqELGI=; b=LT5I2t6QfsNhm/Zmcw9Uw/LJBuiQz3Yv/l2hdyAlCVLO+tu3HLrsJjMffUkFfat3n8 AznUmX8Mxnvexxtoc6aOsRpZqEQmvmaf1LZQyv5AIR8O1wCjEuHgGUti1+B1A0aNRo/w TIBwoYI9eFX3k3aC/2hfClf8o5YuHEjilka0pOPk7VBs8iTSJtlxm6oWfLWOgcXtuzat 2O+me+06Vo5jxwo60jkmjdg5UQ+t1AYXiMscCOOKpYg3jb8u6HhaDxSzJKAAxlGJjYwa 3aAPEaZWi2VuAeyZCoUp2cEtEzxMvQnia7V7MAHh00/oKFPW6scLapQS4s05iB50BIF1 jgfA== 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:mime-version:content-transfer-encoding; bh=j39crPjYqJGwIgrM7ErljlkD2SFiNa9r8wEicsqELGI=; b=pgFiXnT0vi7wQoCSIlV+AkX0bDWHrJbvIjNNe/tmaSsOmirzoa+dRoYV8GGfk0Gxoo /I9igjYBFNNGuwPog8LYk6yiKfPqqIUSFA8pa/S5nVswQzdF+ho8nF6ds7GpORfNZwFJ ZtP0iuXdICNR9yMPyPbhqvMRz/Yuwzypu7rqqRMDspkuIITRf4he39jvQwPpBsehZaWS 50RbcuF//kaRJVMuyZZ6WZBTV94QmGCgfzYFm+KH7wtpqTCMuluTiVPYGsPZJpsVNNSI BwB6Xo/uNO1JoqNlLB9RW9NtLidWFYNn45fNS0ihx5ur0ujxkTmlAMqobI4qsRhDcnbj 0Zfg== X-Gm-Message-State: AOAM532AHTrPoTwZ9/6SIVtm6YvOc151yk3SB+GzMmIgIWAfvTz68r88 8aevSlDBWpKHTTSouYRW/6nkbMPr/Iw= X-Received: by 2002:a65:4183:: with SMTP id a3mr3762192pgq.448.1597215222467; Tue, 11 Aug 2020 23:53:42 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id b26sm1242781pff.54.2020.08.11.23.53.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2020 23:53:41 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 1/2] target/arm: Add cpu property to control pauth Date: Tue, 11 Aug 2020 23:53:38 -0700 Message-Id: <20200812065339.2030527-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200812065339.2030527-1-richard.henderson@linaro.org> References: <20200812065339.2030527-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::542; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x542.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, peter.maydell@linaro.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The crypto overhead of emulating pauth can be significant for some workloads. Add an enumeration property that allows the feature to be turned off, on with the architected algorithm, or on with an implementation defined algorithm. The architected algorithm is quite expensive to emulate; using another algorithm may allow hardware acceleration. Signed-off-by: Richard Henderson --- target/arm/cpu64.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) -- 2.25.1 diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index dd696183df..3181d0e2f8 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -572,6 +572,69 @@ void aarch64_add_sve_properties(Object *obj) } } +static const char * const pauth_names[] = { + "off", "impdef", "arch" +}; + +static const QEnumLookup pauth_lookup = { + .array = pauth_names, + .size = ARRAY_SIZE(pauth_names) +}; + +static int cpu_arm_get_pauth(Object *obj, Error **errp) +{ + ARMCPU *cpu = ARM_CPU(obj); + int value; + + /* We will always set GPA+APA and GPI+API to the same value. */ + if (FIELD_EX64(cpu->isar.id_aa64isar1, ID_AA64ISAR1, APA)) { + value = 2; + } else if (FIELD_EX64(cpu->isar.id_aa64isar1, ID_AA64ISAR1, API)) { + value = 1; + } else { + value = 0; + } + return value; +} + +static void cpu_arm_set_pauth(Object *obj, int value, Error **errp) +{ + ARMCPU *cpu = ARM_CPU(obj); + uint64_t t; + + /* TODO: Handle HaveEnhancedPAC, HaveEnhancedPAC2, HaveFPAC. */ + t = cpu->isar.id_aa64isar1; + switch (value) { + case 0: + t = FIELD_DP64(t, ID_AA64ISAR1, APA, 0); + t = FIELD_DP64(t, ID_AA64ISAR1, API, 0); + t = FIELD_DP64(t, ID_AA64ISAR1, GPA, 0); + t = FIELD_DP64(t, ID_AA64ISAR1, GPI, 0); + break; + case 1: + t = FIELD_DP64(t, ID_AA64ISAR1, APA, 0); + t = FIELD_DP64(t, ID_AA64ISAR1, API, 1); + t = FIELD_DP64(t, ID_AA64ISAR1, GPA, 0); + t = FIELD_DP64(t, ID_AA64ISAR1, GPI, 1); + break; + case 2: + t = FIELD_DP64(t, ID_AA64ISAR1, APA, 1); + t = FIELD_DP64(t, ID_AA64ISAR1, API, 0); + t = FIELD_DP64(t, ID_AA64ISAR1, GPA, 1); + t = FIELD_DP64(t, ID_AA64ISAR1, GPI, 0); + break; + default: + g_assert_not_reached(); + } + cpu->isar.id_aa64isar1 = t; +} + +static void aarch64_add_pauth_properties(Object *obj) +{ + object_property_add_enum(obj, "pauth", "ARMPauthKind", &pauth_lookup, + cpu_arm_get_pauth, cpu_arm_set_pauth); +} + /* -cpu max: if KVM is enabled, like -cpu host (best possible with this host); * otherwise, a CPU with as many features enabled as our emulation supports. * The version of '-cpu max' for qemu-system-arm is defined in cpu.c; @@ -720,6 +783,7 @@ static void aarch64_max_initfn(Object *obj) #endif } + aarch64_add_pauth_properties(obj); aarch64_add_sve_properties(obj); object_property_add(obj, "sve-max-vq", "uint32", cpu_max_get_sve_max_vq, cpu_max_set_sve_max_vq, NULL, NULL); From patchwork Wed Aug 12 06:53:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 247629 Delivered-To: patch@linaro.org Received: by 2002:a92:cc90:0:0:0:0:0 with SMTP id x16csp97823ilo; Tue, 11 Aug 2020 23:55:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGphuKyOjCnuUHjZxgY2F6+TMWNvX69OqCck2nHM9M6QprtfodUtz+3d1RJMPmFdGFtP9P X-Received: by 2002:a25:782:: with SMTP id 124mr55600016ybh.280.1597215327706; Tue, 11 Aug 2020 23:55:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597215327; cv=none; d=google.com; s=arc-20160816; b=doL/cNG9+mMdNP6aO6kBBGShONsvoMxveJId4lFpa5Cu+r5xY2/AmHhSoUirJCHP6L HFWYU2VLDEieIyBkmFrT4XPSx0cNLN8RxIowRTE5L+g324fQUv1/Fdow+Q6utgpICyxB yXZpXyACnZZJ28ha1YNLTu/Aqix8YW/Ld6Uh2mmoM5HVCl/NQ1ywhhor+ydIlokHKRmU bCoB3eHXKVZ3D8B2GMcXiVR2uZrArJORpKBZdm/mI8Nanca7ygkO1Zg3SsH7nudVwYqF a1MGDzYKjMYWB+0YQ7Ohp5IsMxkPimxaR3eyi7NSINePurnZeqjoLe5bT7k5i87hg5Ze XDlA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=x+CUNWxmdwpnm0VPcjEokAjthjrI6ArpKh4ph7vyRmQ=; b=zP2C5oI+Zm34k8PbkMMOFOggoXXpXvQZn38tbghOs8QM8i+7t4Xhju6GeT5AGvu1Yo z7jo0dRHMIjW2FTgsqPlOe1Lbjz5QdmuiJtL3P+RHufnOMawiAK1RInZOvCs3hbQNg6d n9iYHc9AuVdBOpjyZMdELu5g1Wf82bBUGqt4s3JR5PAiTIN5KRNLT9fsC2XeDqB1bOm/ 3nUuQ/V3jvoxtzw4utphgJKFue3/C0uY4UAAz5MjSQ+yl7XXWYUUaWPVGSohPN9opnAB SQ545n5hYd5QaSsHBRzKcHNu1TLA5Wv6kbE/2uAd8OF7+D/B4wl50KKMpi1MV7vkZZxa QNsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="n/O4ms78"; 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 r5si1309245ybs.360.2020.08.11.23.55.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Aug 2020 23:55:27 -0700 (PDT) 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="n/O4ms78"; 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 ([::1]:38834 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k5kfX-0006z3-7y for patch@linaro.org; Wed, 12 Aug 2020 02:55:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33804) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k5kdv-0005Ea-Ao for qemu-devel@nongnu.org; Wed, 12 Aug 2020 02:53:47 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]:40114) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k5kdt-00041H-CJ for qemu-devel@nongnu.org; Wed, 12 Aug 2020 02:53:46 -0400 Received: by mail-pf1-x42b.google.com with SMTP id k18so530367pfp.7 for ; Tue, 11 Aug 2020 23:53:45 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=x+CUNWxmdwpnm0VPcjEokAjthjrI6ArpKh4ph7vyRmQ=; b=n/O4ms78CjwxGMaoAtJnso/7mOl9+MmCYRd6naB25F8FsdUnmPoVu82Rofqkbpnun1 7r5PKR8jNxVuqnFS1c7k8F1D3t9rWk5ppuE7H8DTUlr2xMhADnsu7AoQ8vnXJCy7yuar ggOv0QeNEoHekcVMgNCxINfnqiQ8+0wLT915h3KQE2rrOwpmYcbgswXSj1qq8inLjSyU P7r1jshZnczsSzUEPGga6tjCO/1JwPo5gU2NII1+yttlV3YtQP8lc3BFgWzszoX8thMv aQpV2ogXk5t0Wf0r9wfENmDo2nzrCYnHpL5fFf1GXWNuO5M+EzQ3BVDXDqBh+ObCvDo3 +Epw== 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:mime-version:content-transfer-encoding; bh=x+CUNWxmdwpnm0VPcjEokAjthjrI6ArpKh4ph7vyRmQ=; b=TmzqXNXSI+niJgXW9rBopWZrMNTC9eFxbubOHH2Glb5kC19RkI1HKBtraItQa3sMoO aGWineUo1sBlfn27Uxf8DTk46Pvwqiw1tNnz5483Nkhwdzu2UUOeO4xVgqz1+4aFN+hP UXMLUJh5W5SE32TRa1N8wj9rZWusay1B3RVSr4aT1dgKHTl4AVjMgWBEvHGcNYofAPTU SbTHDIitf/SRshL0nm4ZZNAk0cd5+SOLcAw80b5kExKD64UCvvMkPsQOBc4WHDaizHvF FPG1/51OgcTEXN93dVLMmyvIZkx84MdKcGxPpLoPrRdyMNpTb5lIQgqn7k4VwaaUMywE e/XA== X-Gm-Message-State: AOAM530x9xqcZg3mIKLnL1ZHudfWGyIhZvdvd0NZtozlVgM2bpTDdKJr vjEzFQDMoLE/5kdvH9mou1HG/E83MyU= X-Received: by 2002:a62:4e07:: with SMTP id c7mr9186715pfb.10.1597215223619; Tue, 11 Aug 2020 23:53:43 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id b26sm1242781pff.54.2020.08.11.23.53.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2020 23:53:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 2/2] target/arm: Implement an IMPDEF pauth algorithm Date: Tue, 11 Aug 2020 23:53:39 -0700 Message-Id: <20200812065339.2030527-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200812065339.2030527-1-richard.henderson@linaro.org> References: <20200812065339.2030527-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42b.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, peter.maydell@linaro.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Without hardware acceleration, a cryptographically strong algorithm is too expensive for pauth_computepac. Even with hardware accel, we are not currently expecting to link the linux-user binaries to any crypto libraries, and doing so would generally make the --static build fail. So choose XXH64 as a reasonably quick and decent hash. Signed-off-by: Richard Henderson --- target/arm/pauth_helper.c | 75 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 5 deletions(-) -- 2.25.1 diff --git a/target/arm/pauth_helper.c b/target/arm/pauth_helper.c index 6dbab03768..f1a4389465 100644 --- a/target/arm/pauth_helper.c +++ b/target/arm/pauth_helper.c @@ -207,8 +207,8 @@ static uint64_t tweak_inv_shuffle(uint64_t i) return o; } -static uint64_t pauth_computepac(uint64_t data, uint64_t modifier, - ARMPACKey key) +static uint64_t __attribute__((noinline)) +pauth_computepac_architected(uint64_t data, uint64_t modifier, ARMPACKey key) { static const uint64_t RC[5] = { 0x0000000000000000ull, @@ -272,6 +272,71 @@ static uint64_t pauth_computepac(uint64_t data, uint64_t modifier, return workingval; } +/* + * The XXH64 algorithm from + * https://github.com/Cyan4973/xxHash/blob/v0.8.0/xxhash.h + */ +#define PRIME64_1 0x9E3779B185EBCA87ULL +#define PRIME64_2 0xC2B2AE3D27D4EB4FULL +#define PRIME64_3 0x165667B19E3779F9ULL +#define PRIME64_4 0x85EBCA77C2B2AE63ULL +#define PRIME64_5 0x27D4EB2F165667C5ULL + +static inline uint64_t XXH64_round(uint64_t acc, uint64_t input) +{ + return rol64(acc + input * PRIME64_2, 31) * PRIME64_1; +} + +static inline uint64_t XXH64_mergeround(uint64_t acc, uint64_t val) +{ + return (acc ^ XXH64_round(0, val)) * PRIME64_1 + PRIME64_4; +} + +static inline uint64_t XXH64_avalanche(uint64_t h64) +{ + h64 ^= h64 >> 33; + h64 *= PRIME64_2; + h64 ^= h64 >> 29; + h64 *= PRIME64_3; + /* h64 ^= h64 >> 32; -- does not affect high 64 for pauth */ + return h64; +} + +static uint64_t __attribute__((noinline)) +pauth_computepac_impdef(uint64_t data, uint64_t modifier, ARMPACKey key) +{ + uint64_t v1 = 1 + PRIME64_1 + PRIME64_2; + uint64_t v2 = 1 + PRIME64_2; + uint64_t v3 = 1 + 0; + uint64_t v4 = 1 - PRIME64_1; + uint64_t h64; + + v1 = XXH64_round(v1, data); + v2 = XXH64_round(v2, modifier); + v3 = XXH64_round(v3, key.lo); + v4 = XXH64_round(v4, key.hi); + + h64 = rol64(v1, 1) + rol64(v2, 7) + rol64(v3, 12) + rol64(v4, 18); + h64 = XXH64_mergeround(h64, v1); + h64 = XXH64_mergeround(h64, v2); + h64 = XXH64_mergeround(h64, v3); + h64 = XXH64_mergeround(h64, v4); + + return XXH64_avalanche(h64); +} + +static uint64_t pauth_computepac(CPUARMState *env, uint64_t data, + uint64_t modifier, ARMPACKey key) +{ + ARMCPU *cpu = env_archcpu(env); + + if (FIELD_EX64(cpu->isar.id_aa64isar1, ID_AA64ISAR1, APA)) { + return pauth_computepac_architected(data, modifier, key); + } else { + return pauth_computepac_impdef(data, modifier, key); + } +} + static uint64_t pauth_addpac(CPUARMState *env, uint64_t ptr, uint64_t modifier, ARMPACKey *key, bool data) { @@ -292,7 +357,7 @@ static uint64_t pauth_addpac(CPUARMState *env, uint64_t ptr, uint64_t modifier, bot_bit = 64 - param.tsz; ext_ptr = deposit64(ptr, bot_bit, top_bit - bot_bit, ext); - pac = pauth_computepac(ext_ptr, modifier, *key); + pac = pauth_computepac(env, ext_ptr, modifier, *key); /* * Check if the ptr has good extension bits and corrupt the @@ -341,7 +406,7 @@ static uint64_t pauth_auth(CPUARMState *env, uint64_t ptr, uint64_t modifier, uint64_t pac, orig_ptr, test; orig_ptr = pauth_original_ptr(ptr, param); - pac = pauth_computepac(orig_ptr, modifier, *key); + pac = pauth_computepac(env, orig_ptr, modifier, *key); bot_bit = 64 - param.tsz; top_bit = 64 - 8 * param.tbi; @@ -442,7 +507,7 @@ uint64_t HELPER(pacga)(CPUARMState *env, uint64_t x, uint64_t y) uint64_t pac; pauth_check_trap(env, arm_current_el(env), GETPC()); - pac = pauth_computepac(x, y, env->keys.apga); + pac = pauth_computepac(env, x, y, env->keys.apga); return pac & 0xffffffff00000000ull; }