From nobody Sun Apr 12 05:55:56 2026 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=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1770951445; cv=none; d=zohomail.com; s=zohoarc; b=BJ1ildNBokRZB7oM6VL7hQ4/neJ8LcpJ5FlL98jm6SnM3WEeyGDisFy+OUD4tdJuGlmTBKOPrFOGdhWYefZzBVA8Pg7yIR3ubs42pIIkjONbmqXf2qkYl79X7Uw9T8dSoW2ygkGAsYh7DI3nILKw36DK4mtA6TPGdEQf9t0QcQc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770951445; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=52a52quB+EV04dt3+SopD5+MKUMQjmvEO2kX71lappA=; b=ef+ICwcUHXWr1XS4LjV2OTXo7CMXxONpQMa1oxPQ52gjcD2KEHC0PD2IeJXecyb0OI5zz3dfIxs8SM2QCH+7Qq81YBJb20QiwnItyTp6QGN+1Zg/EtU4CNduQLZaXngvXOyNE8Y5LoaTnIa4fJTKf9phwesJPsOgWzMZ7n5Wk5o= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770951445705487.3802999541549; Thu, 12 Feb 2026 18:57:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqjLh-0006F5-0Q; Thu, 12 Feb 2026 21:56:05 -0500 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 1vqjLb-0006Cn-MN for qemu-devel@nongnu.org; Thu, 12 Feb 2026 21:55:59 -0500 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqjLY-0005Dx-9d for qemu-devel@nongnu.org; Thu, 12 Feb 2026 21:55:59 -0500 Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 61CLRYwL332319 for ; Fri, 13 Feb 2026 02:55:53 GMT Received: from mail-dy1-f197.google.com (mail-dy1-f197.google.com [74.125.82.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4c9cyab81e-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 13 Feb 2026 02:55:53 +0000 (GMT) Received: by mail-dy1-f197.google.com with SMTP id 5a478bee46e88-2ba8013a9e3so581979eec.0 for ; Thu, 12 Feb 2026 18:55:53 -0800 (PST) Received: from hu-bcain-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2ba9dbd5d3esm4500943eec.10.2026.02.12.18.55.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Feb 2026 18:55:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= 52a52quB+EV04dt3+SopD5+MKUMQjmvEO2kX71lappA=; b=LT15paIBkoaINqtK A/cvYdb/CmpO9CpqL/e3q5sPsQTghHmtT1qxNhpujJ8IIihCr4tDPVhmx+0SUwDa 3a/Y13kVukBxVHth5Wvz1tsB4kzzDjKHaK1cT1WyN6uxhZUdxt5pWYlawcvl7i+j Mx21eHFyHEb35mhlYm6CRPFTZebwEH5zDnAXx8VigQHZrtQTY7y97AFbMQpO9Bin if8rPIxFwUR8IU0QbcN+uzAj4fh1r+FT8GpSVEdkMzDJkii9N5Kxnl5Oynia6YIE sd4b/nj1T1vovutnV39ogkbBeVu0iFLU9KePxisPlEK95EoXjZM3Orbn3+vRo/HS cmBfKA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1770951352; x=1771556152; darn=nongnu.org; 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=52a52quB+EV04dt3+SopD5+MKUMQjmvEO2kX71lappA=; b=DO3CVwSZoJmR1hyMNG7YT9QXc5QWLs6eHh75UTu6XCErpHyvNUB29HhwRaZbftYb9l Ph1K5CvrD5UcVYQEKIUu7ewcXS+8BwMNLVDsC8mA3+3Non114/I/DH3CuphVtUxt8hMF kZlxvd1kadekzbZFtvMRPUbekTlXsPtgV/uSDoPzgmSoMNNGZ7t5XjjFT2mcmDJglqpY vRb4Jzei64j11BZcnfIeUC2sWr43WDKcIHzJ0ak8qJcBacADszdlAGXqPcHXExxiR4Fx V+B1HPIS5wh8QeszUbP/wlpcXnVX2lhjWBgXF0ONU2Cl3qPpZ9U3IZZX/5qX5rs3rtRx gVGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770951352; x=1771556152; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=52a52quB+EV04dt3+SopD5+MKUMQjmvEO2kX71lappA=; b=TJju43vLEnG+ImPC1MH4eTXeNzNe3s/a722leMNKvu0FhjGWGFZc3V7Q8rKlQWG2ze U7qlZTEgil6J4wdeBFmrEGTzNdVmzy7svJ08brVAlLHlUBxl+nDQhm6sxTRuvA2zhYYB fKH3jLiNugMljhtr07e0q5numYNC29Rc/1mbwYye0xYfj32/km/K/g6pePbC8aVQ5TYd aI4PvjZ34Qjek+OeCoUhYoxpt4sCIRUKhNdf1GICJdJfq0h+ArRhhzFOWbsQx0FyNBw2 0slGphxmVPxGFcey/7t2r9EpzNVakkeRsKMef2god8RBbIL7ImGki8T0ub3GpZ5p817p 4k1w== X-Gm-Message-State: AOJu0YwMWAGMqwXbBO1R8f2kZq0ztvozWnCv8pbKT9a7RH6CLrXxa63p AEn34Y/aDsccTSB7LukHSyuZN3TcVJ/HVzziwC48po1d4YR73d9a87tpKLUk7ktXadoWWXKGrTx TJReLpL6JwNADRhsIs6CDJdWvgbxhcR4fiG9tTCTis8X3lZiBdI+Ht6eSqcfeaXVaEA== X-Gm-Gg: AZuq6aI3Kanf6w+K8LBBlqBKfyFb9n+qHXcTeTSdbVCaO47fCp1n1SZexjgQkK3PvbZ aZdVq9diEcNFg+yeEyc8SMLdzijoeIyxgpx00QtjT+10usI1xxcPoor7IkYf7E7e1mTSywHQiOj hgoKN+dZ8B6apSZrlEcfrrcIBXclaoleJ9NllEO4j/loCdMt57ruKk6HZlkyMTgJ/6TGJWBxX5a imG5WZmPCPVcIjFICK4hVXdQ9Dh94kRq7k7JnAYrv15wyVUDHhFkbFZepYdNuz4/I62CPIL7r0n IpWj/Qg+34dWiskW+X3nt93S+dakFDBeS3W14Tn88ReYYgf0SVO06O1+eaBuAFOhXH2fLEbY3S4 rpcjR/rXkPJVFGgqXhRDuFpJPhVC6hnaZE2OQ+oD5zebhaPt4YqxLjGwJvxq7q26FK3bXeA== X-Received: by 2002:a05:7301:3808:b0:2ba:a4dc:5c21 with SMTP id 5a478bee46e88-2babc53a854mr149335eec.27.1770951352256; Thu, 12 Feb 2026 18:55:52 -0800 (PST) X-Received: by 2002:a05:7301:3808:b0:2ba:a4dc:5c21 with SMTP id 5a478bee46e88-2babc53a854mr149327eec.27.1770951351687; Thu, 12 Feb 2026 18:55:51 -0800 (PST) From: Brian Cain To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: brian.cain@oss.qualcomm.com, ltaylorsimpson@gmail.com, Pierrick Bouvier , Laurent Vivier Subject: [PULL 1/7] target/hexagon: Fix invalid duplex decoding Date: Thu, 12 Feb 2026 18:55:38 -0800 Message-Id: <20260213025544.2497992-2-brian.cain@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260213025544.2497992-1-brian.cain@oss.qualcomm.com> References: <20260213025544.2497992-1-brian.cain@oss.qualcomm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: PsUDmJr_qy_MfTiT9nw_EfkGFBkuUv92 X-Authority-Analysis: v=2.4 cv=OrBCCi/t c=1 sm=1 tr=0 ts=698e92b9 cx=c_pps a=Uww141gWH0fZj/3QKPojxA==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=IkcTkHD0fZMA:10 a=HzLeVaNsDn8A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=Mpw57Om8IfrbqaoTuvik:22 a=GgsMoib0sEa3-_RKJdDe:22 a=p0WdMEafAAAA:8 a=KKAkSRfTAAAA:8 a=pGLkceISAAAA:8 a=EUspDBNiAAAA:8 a=OCWrEZw6VeUBrM89gJgA:9 a=QEXdDO2ut3YA:10 a=PxkB5W3o20Ba91AHUih5:22 a=cvBusfyB2V15izCimMoJ:22 X-Proofpoint-ORIG-GUID: PsUDmJr_qy_MfTiT9nw_EfkGFBkuUv92 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMjEzMDAyMCBTYWx0ZWRfX39/WJ5Ri8TS6 7aUWC3NT+9m5+4Tn4pVHfEKDqVirNsWelTlSyLEzhjemkcJWVYur50UC+4S/AuUhxFwWbgZ9DKM OCMcV2asfekgR0VV+Scy3fzwAK+S2tcKaw/PLpua6/pscHLvYcHlBRdhGGZKyjF/hvQroUdVrYL 2VZloyqHUS8fKvsIpvn2v6kgLdHadkL79zXt/AzpxwvIToXkOUwoEH0eJiT8mrnumdd+i0SVXZq JRVXL7oMiH3iTCAlS+7sHRV/s2mTH7nHBIqCH4QReznWDdCFSgoNpjqDLvc80eUFqa7c6W29JK1 6h875NtV9SrEmUFfN61rFpmCMSSHigmEyBdRuuWnGxKUt0bXwzRRjMHWclWZ8KMdRZlCJLNdSM5 NTibg5kJYBQprJ1UNGSk9TGTyz1UQdG2KQ7nQ2NsLmBEXyAtD7dLwobVq1++s2kv2aLD7CW41QJ 9w6q0FwRTFsIeZXwZYg== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-02-12_05,2026-02-12_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 impostorscore=0 malwarescore=0 phishscore=0 lowpriorityscore=0 priorityscore=1501 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2602130020 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=205.220.180.131; envelope-from=brian.cain@oss.qualcomm.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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.29 Precedence: list List-Id: qemu development 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 @qualcomm.com) X-ZM-MESSAGEID: 1770951446956154100 When decoding a duplex instruction, if the slot0 sub-instruction fails to decode after slot1 succeeds, QEMU was leaving the packet in a partially-decoded state. This allowed invalid duplex encodings (where one sub-instruction doesn't match any valid pattern) to be executed incorrectly. Fix by resetting the decoder state when slot0 fails, returning an empty instruction that triggers an exception. Add gen_exception_decode_fail() for raising exceptions when decode fails before ctx->next_PC is initialized. This keeps gen_exception_end_tb() semantics unchanged (it continues to use ctx->next_PC for the exception PC after successful decode). Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3291 Reviewed-by: Pierrick Bouvier Reviewed-by: Taylor Simpson Signed-off-by: Brian Cain --- linux-user/hexagon/cpu_loop.c | 4 ++ target/hexagon/decode.c | 13 ++++- target/hexagon/translate.c | 18 ++++++- tests/tcg/hexagon/invalid-encoding.c | 81 ++++++++++++++++++++++++++++ tests/tcg/hexagon/Makefile.target | 1 + 5 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 tests/tcg/hexagon/invalid-encoding.c diff --git a/linux-user/hexagon/cpu_loop.c b/linux-user/hexagon/cpu_loop.c index 1941f4c9c1..c0e1098e3f 100644 --- a/linux-user/hexagon/cpu_loop.c +++ b/linux-user/hexagon/cpu_loop.c @@ -64,6 +64,10 @@ void cpu_loop(CPUHexagonState *env) force_sig_fault(TARGET_SIGBUS, TARGET_BUS_ADRALN, env->gpr[HEX_REG_R31]); break; + case HEX_CAUSE_INVALID_PACKET: + force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC, + env->gpr[HEX_REG_PC]); + break; case EXCP_ATOMIC: cpu_exec_step_atomic(cs); break; diff --git a/target/hexagon/decode.c b/target/hexagon/decode.c index b5ece60450..69ba1ec96c 100644 --- a/target/hexagon/decode.c +++ b/target/hexagon/decode.c @@ -509,8 +509,14 @@ decode_insns(DisasContext *ctx, Insn *insn, uint32_t e= ncoding) insn->iclass =3D iclass_bits(encoding); return 2; } + /* + * Slot0 decode failed after slot1 succeeded. This is an inval= id + * duplex encoding (both sub-instructions must be valid). + */ + ctx->insn =3D --insn; } - g_assert_not_reached(); + /* Invalid duplex encoding - return 0 to signal failure */ + return 0; } } =20 @@ -674,7 +680,10 @@ int decode_packet(DisasContext *ctx, int max_words, co= nst uint32_t *words, encoding32 =3D words[words_read]; end_of_packet =3D is_packet_end(encoding32); new_insns =3D decode_insns(ctx, insn, encoding32); - g_assert(new_insns > 0); + if (new_insns =3D=3D 0) { + /* Invalid instruction encoding */ + return 0; + } /* * If we saw an extender, mark next word extended so immediate * decode works diff --git a/target/hexagon/translate.c b/target/hexagon/translate.c index e88e19cc1a..7fe8b35351 100644 --- a/target/hexagon/translate.c +++ b/target/hexagon/translate.c @@ -195,7 +195,21 @@ static void gen_exception_end_tb(DisasContext *ctx, in= t excp) tcg_gen_movi_tl(hex_gpr[HEX_REG_PC], ctx->next_PC); gen_exception_raw(excp); ctx->base.is_jmp =3D DISAS_NORETURN; +} =20 +/* + * Generate exception for decode failures. Unlike gen_exception_end_tb, + * this is used when decode fails before ctx->next_PC is initialized. + */ +static void gen_exception_decode_fail(DisasContext *ctx, int nwords, int e= xcp) +{ + target_ulong fail_pc =3D ctx->base.pc_next + nwords * sizeof(uint32_t); + + gen_exec_counters(ctx); + tcg_gen_movi_tl(hex_gpr[HEX_REG_PC], fail_pc); + gen_exception_raw(excp); + ctx->base.is_jmp =3D DISAS_NORETURN; + ctx->base.pc_next =3D fail_pc; } =20 static int read_packet_words(CPUHexagonState *env, DisasContext *ctx, @@ -935,7 +949,7 @@ static void decode_and_translate_packet(CPUHexagonState= *env, DisasContext *ctx) =20 nwords =3D read_packet_words(env, ctx, words); if (!nwords) { - gen_exception_end_tb(ctx, HEX_CAUSE_INVALID_PACKET); + gen_exception_decode_fail(ctx, 0, HEX_CAUSE_INVALID_PACKET); return; } =20 @@ -950,7 +964,7 @@ static void decode_and_translate_packet(CPUHexagonState= *env, DisasContext *ctx) gen_commit_packet(ctx); ctx->base.pc_next +=3D pkt.encod_pkt_size_in_bytes; } else { - gen_exception_end_tb(ctx, HEX_CAUSE_INVALID_PACKET); + gen_exception_decode_fail(ctx, nwords, HEX_CAUSE_INVALID_PACKET); } } =20 diff --git a/tests/tcg/hexagon/invalid-encoding.c b/tests/tcg/hexagon/inval= id-encoding.c new file mode 100644 index 0000000000..010a5eb741 --- /dev/null +++ b/tests/tcg/hexagon/invalid-encoding.c @@ -0,0 +1,81 @@ +/* + * Test that invalid instruction encodings are properly rejected. + * + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include +#include +#include +#include +#include + +static void *resume_pc; + +static void handle_sigill(int sig, siginfo_t *info, void *puc) +{ + ucontext_t *uc =3D (ucontext_t *)puc; + + if (sig !=3D SIGILL) { + _exit(EXIT_FAILURE); + } + + uc->uc_mcontext.r0 =3D SIGILL; + uc->uc_mcontext.pc =3D (unsigned long)resume_pc; +} + +/* + * Each test function: + * - Sets r0 to something other than SIGILL + * - Stores the resume address into resume_pc + * - Executes the invalid encoding + * - The handler sets r0 =3D SIGILL and resumes after the faulting packet + * - Returns the value in r0 + */ + +/* + * Invalid duplex encoding (issue #3291): + * - Word 0: 0x0fff6fff =3D immext(#0xfffbffc0), parse bits =3D 01 + * - Word 1: 0x600237b0 =3D duplex with: + * - slot0 =3D 0x17b0 (invalid S2 subinstruction encoding) + * - slot1 =3D 0x0002 (valid SA1_addi) + * - duplex iclass =3D 7 (S2 for slot0, A for slot1) + * + * Since slot0 doesn't decode to any valid S2 subinstruction, this packet + * should be rejected and raise SIGILL. + */ +static int test_invalid_duplex(void) +{ + int sig; + + asm volatile( + "r0 =3D #0\n" + "r1 =3D ##1f\n" + "memw(%1) =3D r1\n" + ".word 0x0fff6fff\n" /* immext(#0xfffbffc0), parse=3D01 */ + ".word 0x600237b0\n" /* duplex: slot0=3D0x17b0 (invalid) */ + "1:\n" + "%0 =3D r0\n" + : "=3Dr"(sig) + : "r"(&resume_pc) + : "r0", "r1", "memory"); + + return sig; +} + +int main() +{ + struct sigaction act; + + memset(&act, 0, sizeof(act)); + act.sa_sigaction =3D handle_sigill; + act.sa_flags =3D SA_SIGINFO; + assert(sigaction(SIGILL, &act, NULL) =3D=3D 0); + + assert(test_invalid_duplex() =3D=3D SIGILL); + + puts("PASS"); + return EXIT_SUCCESS; +} diff --git a/tests/tcg/hexagon/Makefile.target b/tests/tcg/hexagon/Makefile= .target index e5182c01d8..16669e04a8 100644 --- a/tests/tcg/hexagon/Makefile.target +++ b/tests/tcg/hexagon/Makefile.target @@ -51,6 +51,7 @@ HEX_TESTS +=3D scatter_gather HEX_TESTS +=3D hvx_misc HEX_TESTS +=3D hvx_histogram HEX_TESTS +=3D invalid-slots +HEX_TESTS +=3D invalid-encoding HEX_TESTS +=3D unaligned_pc =20 run-and-check-exception =3D $(call run-test,$2,$3 2>$2.stderr; \ --=20 2.34.1