From nobody Thu Nov 28 12:38:20 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1692723765; cv=none; d=zohomail.com; s=zohoarc; b=ZTLKeHcCYkYxnZEqG1Pllw/GvVs/XmqAlV9dCyqZZvCDE8J/+NOw/8Y5Ydo5gQq393aGYaIKh7XQlvQStbHh+hHabVlhWc6SIT4PlHM+2O4JVu8KM6yVAs94duc/6X/TZkiazMDFak3VmOjbuZPJEC/oafNQdMwah/WFmgKyEAU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692723765; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WtbxWpkqRs8uhBP9ntrNj0PDPLSc0E50BaiAIV/fKrE=; b=eNnzAWcXCFgdVvJBMSdN2Z2xVQqkRCi3WgtdFrPzNoYsFQ8uGG2CT2DQhJb+dnzQT2aVld7zmiVSudWVouMFGI5FQtye6U80ZXMbTx9N06U1Vtn1cBTOfUVbImvPzcnf+vAyxAiiIRH4jjXs77zJFX3GXw5lsg2b3QTbdMnRpl8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1692723765158281.48747641581895; Tue, 22 Aug 2023 10:02:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYUls-00008s-NV; Tue, 22 Aug 2023 13:02:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qYUlo-0008Oe-8F for qemu-devel@nongnu.org; Tue, 22 Aug 2023 13:02:20 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYUlk-0002Kq-1O for qemu-devel@nongnu.org; Tue, 22 Aug 2023 13:02:20 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-68a1af910e0so2182574b3a.2 for ; Tue, 22 Aug 2023 10:02:15 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:4e3c:f4a4:b92a:b5ab]) by smtp.gmail.com with ESMTPSA id 27-20020a17090a031b00b00264040322desm8761121pje.40.2023.08.22.10.02.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Aug 2023 10:02:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692723734; x=1693328534; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WtbxWpkqRs8uhBP9ntrNj0PDPLSc0E50BaiAIV/fKrE=; b=pxAWm1bhjnUv47l+4NiL/g0E8FPIh8B7RFTGlGDQAOLjCP0Cvv8IBPmduyHQJC3vn1 bKgjUHx0n/J+Q3BJabLrwvezQPUm3yF7c1WcPagV6d7r250tqNW5eCc37dFretT8O2Wx JLlTIzvkI5qWBYgb4GiBBRXiQZwwY18On3PYSkFgtJAW//xR+jFBxXU3HBQkbWWn61Hm MO9UYwf4NBaHWsHxU0R8pzmsjXtZAWS9ALwFiVzdH501Auur+lrs0MbnRk4sBQeP9DBd Y1fEXHdnHavYJrp1vw46jI1ugMQ+mTnPR6bnGn1DHzFtywBtOZRkms5vhWoXNOZvmLnU c4hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692723734; x=1693328534; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WtbxWpkqRs8uhBP9ntrNj0PDPLSc0E50BaiAIV/fKrE=; b=QaVCph3ExmkmX5rIJkYQ50gfVfEHSLYwKMaBD6z1hcxFZZat7ombRn16tHFa/nCm7k BovE0J9GjbUMN4yNGiTbgC4dVdgaIWj42+x4HOe0Ks8pz7Z+/OZXUFM+6BsE6iQHGZSZ 5Gny9oNcVpG7gv98y8ti8tC6dqTjhHrR0ckEsYzlIgjQ5jgfeoPE+AdvjdsCPE5DHM5I N7rV8ThOv/+rdsbAG0nfidIWk7kq17Av6umXtfjNShNROH2EQki7GqFAz3MLpZsG6D2v fYOgsrPUtxMhI6F+P5U/jVA0bBc1jH/PCGpiglwNiymvAQvkl3MdCmNZqyUuq2YqHk1T E96w== X-Gm-Message-State: AOJu0YytxXswwTw9bv/MIF0vFkwzg40N4yy5QdlAleeeAcASK97im6Fy unCU84A70q+1F1b/PyRCmjFK44nT0DuaR1o/rpw= X-Google-Smtp-Source: AGHT+IHeJBztbYQIrkoB+uCz6JDrez/Cyin6MKp5CkcMoXU+chQ8sgo9jTWo99VSLHuwF4o3mn0BIQ== X-Received: by 2002:a17:90a:854c:b0:26d:1201:a8c4 with SMTP id a12-20020a17090a854c00b0026d1201a8c4mr7659567pjw.13.1692723733890; Tue, 22 Aug 2023 10:02:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH 3/3] linux-user/aarch64: Add ESR signal frame for PACFAIL Date: Tue, 22 Aug 2023 10:02:09 -0700 Message-Id: <20230822170209.1130173-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230822170209.1130173-1-richard.henderson@linaro.org> References: <20230822170209.1130173-1-richard.henderson@linaro.org> MIME-Version: 1.0 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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::434; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x434.google.com 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=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1692723796070100001 Content-Type: text/plain; charset="utf-8" The PACFAIL fault uses ILL_ILLOPN and includes ESR. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- linux-user/aarch64/cpu_loop.c | 7 ++++++- linux-user/aarch64/signal.c | 6 ++++++ tests/tcg/aarch64/pauth-2.c | 25 ++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c index 22c9789326..5af17e8724 100644 --- a/linux-user/aarch64/cpu_loop.c +++ b/linux-user/aarch64/cpu_loop.c @@ -110,7 +110,12 @@ void cpu_loop(CPUARMState *env) /* just indicate that signals should be handled asap */ break; case EXCP_UDEF: - force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->pc); + /* See kernel's do_el0_fpac, and our need_save_esr(). */ + if (syn_get_ec(env->exception.syndrome) =3D=3D EC_PACFAIL) { + force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPN, env->pc); + } else { + force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, env->pc); + } break; case EXCP_PREFETCH_ABORT: case EXCP_DATA_ABORT: diff --git a/linux-user/aarch64/signal.c b/linux-user/aarch64/signal.c index b2280fa9e3..bcdd796cc2 100644 --- a/linux-user/aarch64/signal.c +++ b/linux-user/aarch64/signal.c @@ -582,6 +582,7 @@ static bool need_save_esr(target_siginfo_t *info, CPUAR= MState *env) { int sig =3D info->si_signo; int type =3D info->si_code >> 16; + int code =3D info->si_code & 0xffff; =20 if (type !=3D QEMU_SI_FAULT) { return false; @@ -592,6 +593,11 @@ static bool need_save_esr(target_siginfo_t *info, CPUA= RMState *env) return true; } =20 + /* See arch/arm64/kernel/traps.c, do_el0_fpac, and our cpu_loop(). */ + if (sig =3D=3D TARGET_SIGILL && code =3D=3D TARGET_ILL_ILLOPN) { + return true; + } + return false; } =20 diff --git a/tests/tcg/aarch64/pauth-2.c b/tests/tcg/aarch64/pauth-2.c index d498d7dd8b..62b39af3d0 100644 --- a/tests/tcg/aarch64/pauth-2.c +++ b/tests/tcg/aarch64/pauth-2.c @@ -4,14 +4,37 @@ #include #include =20 +static inline struct _aarch64_ctx *first_ctx(ucontext_t *uc) +{ + return (struct _aarch64_ctx *)&uc->uc_mcontext.__reserved; +} + +static inline struct _aarch64_ctx *next_ctx(struct _aarch64_ctx *hdr) +{ + return (struct _aarch64_ctx *)((char *)hdr + hdr->size); +} + static void sigill(int sig, siginfo_t *info, void *vuc) { ucontext_t *uc =3D vuc; - uint64_t test; + struct _aarch64_ctx *hdr; + struct esr_context *ec; + uint64_t test, esr; =20 /* There is only one insn below that is allowed to fault. */ asm volatile("adr %0, auth2_insn" : "=3Dr"(test)); assert(test =3D=3D uc->uc_mcontext.pc); + + /* Find the esr_context. */ + for (hdr =3D first_ctx(uc); hdr->magic !=3D ESR_MAGIC; hdr =3D next_ct= x(hdr)) { + assert(hdr->magic !=3D 0); + } + + ec =3D (struct esr_context *)hdr; + esr =3D ec->esr; + + assert((esr >> 26) =3D=3D 0x1c); /* EC_PACFAIL */ + assert((esr & 3) =3D=3D 2); /* AUTDA: data=3D1 key=3D0 */ exit(0); } =20 --=20 2.34.1