From nobody Sun May 5 02:01:21 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1621863029; cv=none; d=zohomail.com; s=zohoarc; b=lqLtyqThoIhKydKCFlg/xg5oeEK6hbb5ZX/mBMl3mWBlMU1qkQHqAx2VjcdzPL6ksRXQ491A+HIUnwU33e5jl85gn6aqdgajZ5k2HXLLoxwzBBlc+7gQl0eG3NBmnUpa4QFSmqbLicahuyuRfMRPlZuJq+0VzgiLc9ZKxuLn34w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621863029; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=J9DK0Dbta1o4so8aXK5OOwR7RIp1mZfpNmlASzwGyvw=; b=EoYOyEuXQvoIR5YNbCruTkXf2ZCymLVTKDbhyARpjx5zCKa/GAjM3z0j7Jy+QuF9V4/C/dyl7vWzK+klosbKojwMdjGEXeBNvXIUiJ8ikIGyurcHH4082KqKWhhfNf4ozON7cqZWp1uXXPvAsedb3JfEbA0zDmFhfHDh97c+MHU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1621863029292135.56891735788213; Mon, 24 May 2021 06:30:29 -0700 (PDT) Received: from localhost ([::1]:42770 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1llAf5-0005Fz-5G for importer2@patchew.org; Mon, 24 May 2021 09:30:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51654) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ll6A8-0001OF-4n for qemu-devel@nongnu.org; Mon, 24 May 2021 04:42:12 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]:44897) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ll6A5-0003Ic-EC for qemu-devel@nongnu.org; Mon, 24 May 2021 04:42:11 -0400 Received: by mail-wr1-x42b.google.com with SMTP id i17so27625942wrq.11 for ; Mon, 24 May 2021 01:42:05 -0700 (PDT) Received: from localhost ([82.44.17.50]) by smtp.gmail.com with ESMTPSA id m9sm13749052wrs.36.2021.05.24.01.42.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 May 2021 01:42:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nuviainc-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=J9DK0Dbta1o4so8aXK5OOwR7RIp1mZfpNmlASzwGyvw=; b=rucD0xV0Y3209kjBK4gIa3Hgg4CSa7F2DyY4QOUMtZrniYnBx575w4lj/eLQOmZuh1 Vet3m/sgi8ZI9Pl+1QuzYsBqSzbz+pqZqoIc5DVPg7Qb/rRPLDGrsKd54PTnXQXRmdQ0 s5Jj4qAnU6D7+zOs8YqG9A2AfZ4tb9kq84P1U2Vk7KLiVrcxMiypTaaTQTrMXYEyZ9O+ XlbKka3NuUz85mgeLc9VEEqKJyKqUkiaPUe0Ku59vc1Qwvr8qak+Vkk1zU4SN6DkCcxe 26BVBNAZON81c/i6av+fZP71EHGRfUYH/OkucDJDxIQbhkvsfLr8wM9ZLO6rDSG/C7EZ lvUw== 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:mime-version :content-transfer-encoding; bh=J9DK0Dbta1o4so8aXK5OOwR7RIp1mZfpNmlASzwGyvw=; b=Cht10rfRpnYq5y1T8DI3Ls0zVBa++UluUonJiTK16ziV/iXIeNBz8v5g+QQJMdSKHn KhKJ8eD0p4cLmZ8etDdIf/ph2TkQwoNfBx/HSTS6tNYMhwvkCLiLYyEdLtj0UbgpyQDC s9YWWXby+IeO4HUn0u9YPrDLsXq2+lu7imc3dGpVShLSDrYg8eVcjHZsO+PzsBm4yqIz dFilWS3Et57ftaL2oIrNHONbm3L7b70ANHyQEASzD+CZ5Sxdy/AhchFfgTGn42QnoMlD irxlWVNsbrptKZCwkngwYhZIqWLAw3z2Ch/ZjAa/+PbAKBngWYXm06Q7HMsyfYvhanu2 w88Q== X-Gm-Message-State: AOAM531OOgzk2MlsmZ8zo19ctIvGJctxAlyBchV5CagkVu7R+1b5OCkD xnTBXjGoLABFLjrlwOUQoITOPA== X-Google-Smtp-Source: ABdhPJzFapF6IDYh64b7xhRyxJu8tjsNzvcfyuEOtXc5WoXYZr0h/HjW8Cb2eaH3PZJQ6AjZAxfn2A== X-Received: by 2002:adf:fe49:: with SMTP id m9mr21290175wrs.125.1621845724468; Mon, 24 May 2021 01:42:04 -0700 (PDT) From: Jamie Iles To: qemu-arm@nongnu.org Subject: [PATCH] target/arm: fix missing exception class Date: Mon, 24 May 2021 09:42:01 +0100 Message-Id: <20210524084201.1665973-1-jamie@nuviainc.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=jamie@nuviainc.com; helo=mail-wr1-x42b.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-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-Mailman-Approved-At: Mon, 24 May 2021 09:27:40 -0400 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: Peter Maydell , Jamie Iles , Richard Henderson , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) The DAIF and PAC checks used raise_exception_ra to raise an exception and unwind CPU state but raise_exception_ra is currently designed for handling data aborts as the syndrome is partially precomputed and encoded in the TB and then merged in merge_syn_data_abort when handling the data abort. Using raise_exception_ra for DAIF and PAC checks results in an empty syndrome being retrieved from data[2] in restore_state_to_opc and setting ESR to 0. This manifested as: kvm [571]: Unknown exception class: esr: 0x000000 =E2=80=93 Unknown/Uncategorized when launching a KVM guest when the host qemu used a CPU supporting EL2+pointer authentication and enabling pointer authentication in the guest. As the syndrome and exception class is not encoded in the TB, use cpu_restore_state and raise_exception to restore the CPU state and raise the exception with the correct syndrome. Fixes: 0d43e1a2d29a ("target/arm: Add PAuth helpers") Cc: Richard Henderson Cc: Peter Maydell Signed-off-by: Jamie Iles --- target/arm/helper-a64.c | 12 +++++++----- target/arm/pauth_helper.c | 4 +++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/target/arm/helper-a64.c b/target/arm/helper-a64.c index 9cc3b066e28b..83991d783fc1 100644 --- a/target/arm/helper-a64.c +++ b/target/arm/helper-a64.c @@ -72,11 +72,13 @@ static void daif_check(CPUARMState *env, uint32_t op, { /* DAIF update to PSTATE. This is OK from EL0 only if UMA is set. */ if (arm_current_el(env) =3D=3D 0 && !(arm_sctlr(env, 0) & SCTLR_UMA)) { - raise_exception_ra(env, EXCP_UDEF, - syn_aa64_sysregtrap(0, extract32(op, 0, 3), - extract32(op, 3, 3), 4, - imm, 0x1f, 0), - exception_target_el(env), ra); + CPUState *cs =3D env_cpu(env); + cpu_restore_state(cs, ra, true); + raise_exception(env, EXCP_UDEF, + syn_aa64_sysregtrap(0, extract32(op, 0, 3), + extract32(op, 3, 3), 4, + imm, 0x1f, 0), + exception_target_el(env)); } } =20 diff --git a/target/arm/pauth_helper.c b/target/arm/pauth_helper.c index cd6df18150bf..c90a3f765b9c 100644 --- a/target/arm/pauth_helper.c +++ b/target/arm/pauth_helper.c @@ -385,7 +385,9 @@ static uint64_t pauth_strip(CPUARMState *env, uint64_t = ptr, bool data) static void QEMU_NORETURN pauth_trap(CPUARMState *env, int target_el, uintptr_t ra) { - raise_exception_ra(env, EXCP_UDEF, syn_pactrap(), target_el, ra); + CPUState *cs =3D env_cpu(env); + cpu_restore_state(cs, ra, true); + raise_exception(env, EXCP_UDEF, syn_pactrap(), target_el); } =20 static void pauth_check_trap(CPUARMState *env, int el, uintptr_t ra) --=20 2.30.2