Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/2195794/?format=api
{ "id": 2195794, "url": "http://patchwork.ozlabs.org/api/patches/2195794/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260211221953.4099441-5-brian.cain@oss.qualcomm.com/", "project": { "id": 14, "url": "http://patchwork.ozlabs.org/api/projects/14/?format=api", "name": "QEMU Development", "link_name": "qemu-devel", "list_id": "qemu-devel.nongnu.org", "list_email": "qemu-devel@nongnu.org", "web_url": "", "scm_url": "", "webscm_url": "", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20260211221953.4099441-5-brian.cain@oss.qualcomm.com>", "list_archive_url": null, "date": "2026-02-11T22:19:53", "name": "[v4,4/4] target/hexagon: Detect register write conflicts", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "a6378c44a3c98bc12d2bfc935472f0ba41430ab3", "submitter": { "id": 89839, "url": "http://patchwork.ozlabs.org/api/people/89839/?format=api", "name": "Brian Cain", "email": "brian.cain@oss.qualcomm.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260211221953.4099441-5-brian.cain@oss.qualcomm.com/mbox/", "series": [ { "id": 491915, "url": "http://patchwork.ozlabs.org/api/series/491915/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=491915", "date": "2026-02-11T22:19:52", "name": "Handle some invalid encodings", "version": 4, "mbox": "http://patchwork.ozlabs.org/series/491915/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2195794/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2195794/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>", "X-Original-To": "incoming@patchwork.ozlabs.org", "Delivered-To": "patchwork-incoming@legolas.ozlabs.org", "Authentication-Results": [ "legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256\n header.s=qcppdkim1 header.b=Kn4ZjDZy;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com\n header.a=rsa-sha256 header.s=google header.b=Hm7oJ+Dx;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)" ], "Received": [ "from lists.gnu.org (lists.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fBCZ34FvVz1xwL\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 12 Feb 2026 09:20:59 +1100 (AEDT)", "from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1vqIZH-0005O6-UX; Wed, 11 Feb 2026 17:20:19 -0500", "from eggs.gnu.org ([2001:470:142:3::10])\n by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <brian.cain@oss.qualcomm.com>)\n id 1vqIZ6-0005LV-NH\n for qemu-devel@nongnu.org; Wed, 11 Feb 2026 17:20:10 -0500", "from mx0a-0031df01.pphosted.com ([205.220.168.131])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <brian.cain@oss.qualcomm.com>)\n id 1vqIZ3-000584-Dj\n for qemu-devel@nongnu.org; Wed, 11 Feb 2026 17:20:08 -0500", "from pps.filterd (m0279866.ppops.net [127.0.0.1])\n by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id\n 61BKsb7b519173\n for <qemu-devel@nongnu.org>; Wed, 11 Feb 2026 22:20:04 GMT", "from mail-dl1-f70.google.com (mail-dl1-f70.google.com\n [74.125.82.70])\n by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4c8sup9vp5-1\n (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT)\n for <qemu-devel@nongnu.org>; Wed, 11 Feb 2026 22:20:04 +0000 (GMT)", "by mail-dl1-f70.google.com with SMTP id\n a92af1059eb24-1270878c3fdso7109358c88.1\n for <qemu-devel@nongnu.org>; Wed, 11 Feb 2026 14:20:04 -0800 (PST)", "from hu-bcain-lv.qualcomm.com (Global_NAT1.qualcomm.com.\n [129.46.96.20]) by smtp.gmail.com with ESMTPSA id\n 5a478bee46e88-2ba9dbe123asm2588379eec.13.2026.02.11.14.20.01\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Wed, 11 Feb 2026 14:20:01 -0800 (PST)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h=\n cc:content-transfer-encoding:content-type:date:from:in-reply-to\n :message-id:mime-version:references:subject:to; s=qcppdkim1; bh=\n yw6tKRnOp3N144RB9s7s38SD2PNdjLOlfuEnat2PGzw=; b=Kn4ZjDZyVan+vpIA\n POBxLtJdahAHRo17FDYZJPZxqr+PVcc+geR5klINchzfwB0cfZfKyzEGhG5qLBXC\n 3N60WTqKfkndmA4K0h9QzRtGIVInNkPcNrLbUr43hRoBHaaeNsCDEr/NYD3dnyFT\n lURjzgkh9nxwJNvsVR9QwNTRlESsGao023nZMpgVSfE1bb+xaZuUNbM1WE1BERcz\n +CcAoxw3mMj7+YglmBbYnciSKWrOQk+13iXxVH1/e6A+ni0iqMT8Anlxml6Ht5Xq\n s27ebUOHENTy8d/3AUbG2dE2kRXinZqCAqcOMDI5sIVyLimYoItGbuy39JOYwVhq\n 8qaMsw==", "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=oss.qualcomm.com; s=google; t=1770848403; x=1771453203; darn=nongnu.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=yw6tKRnOp3N144RB9s7s38SD2PNdjLOlfuEnat2PGzw=;\n b=Hm7oJ+DxN1a+VtBVR+vnOSqTj/SzJSoAV72CujcgYNAYud4tpRXL5TGQrJ0shCfDOl\n 6vhVKSCiNMzw26+XqltKw6HB+Vm7pvBGSPxwKcTQBhV5oc5rOEVEpsFZ3PxuGTM3oPMd\n yMHpYP0YmBwBVUQuqidMSrNA8WouTPhMdL+UFEHzSRsPaqUlZlrRXIl3ctDFMMLyfMER\n bR14rUZ5H5dMmNg9PwhLVzAu0S4HQq5qQYHa4fFGzw1fCSLx7n4w9mI92zD1azKzYx0t\n cKTWAnxfi0YsrbPkImoqh4Uzzbl53TrlbXZgJucz0ZUEVgr9gGDVKa5XaLVCQZPtijjq\n kCog==" ], "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20230601; t=1770848403; x=1771453203;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=yw6tKRnOp3N144RB9s7s38SD2PNdjLOlfuEnat2PGzw=;\n b=Mh68PXo76wDkY8PNgowf3e8fSd9z5YTm5zwuJnkugpaEpVa/NLPJzpUEgUsDUvCDbZ\n MpMVS3GG5c7rs2BvmDqghmuO2+nYzdrNwhkTpjtOl+N0wSWXDuB46ptCOJfdVp6pEIlu\n xxk2WaqNUQXzPG9JaKhMvO1FzifqjPoU7a6MA8KUL6hXaQSYya+hPKJlLtqC2iU0rcrO\n ZH1dH9657W+XXdp9wwjXyZMjU1o4Bab4EeBNZ2vrBaU7oGkRzeoAuYg8igpbf3fyxoq7\n 56fVF7ei40R+CoF7VnhBI3lJqIdW4f0HPAPTSPyU3oCYabIeky101Znk9+LDq9AizExF\n eOnA==", "X-Gm-Message-State": "AOJu0Yw7wYwmmM+l8lI+sbC9gArhTY6Xp6FRFBiScM/HjyXiuc8DHLA2\n 1adofKfywbxtjPzilj1f6tdXqkMJDfYPMw0c+1VfJURSwnMlGQwtVPJiANv2pxsH6Enm+BcAPGG\n 8Bxj+J1M+3eMD4EJrtzLmgUPd40Zz/um3CZEeXt70UDR0FkkZt7nMLyCwyGjTLT02bA==", "X-Gm-Gg": "AZuq6aIV7qIvF5mfjCW8U6ZKIqk3HRIfdVM4yQ8UuKqWGykegNlWF8fPDXFbUMk6ZrP\n KZQWTv5U28qaF3M4XHJi+gKHW5TEt8rq4gm0VAo3hLIP6i0eIUgssDLjTUo6iV1Nr4n+XRXJkjr\n 5svZOUf2fpD5h8Jhd3eZyrEwmksg1olh449/07Vu+WVBy1VP7o9NlY9HQvmOztTNuHZ4WlhE4sk\n KAMTfynMrVB3G9Re/FxCQe3bZeZqfNGxppJvghDgqZ1HSfgkEZSjE0KxCBeGgp+S8KJa6n2XKSO\n nyFa92vnRs0sOkEoAREoMhVY0vIuOwLMCgK745nUgDDfDwKrkSXkQgLjyfrNGhqFKGLvPiQdYeY\n DIWfIFduChqHbSJYEEynHabOaU604BPkhYw9RjiIfnpmZ44QoTEPQssQNb0vodEOHyqOvBA==", "X-Received": [ "by 2002:a05:7022:238d:b0:11f:2c9e:87f8 with SMTP id\n a92af1059eb24-1272f7a13e8mr325304c88.34.1770848403088;\n Wed, 11 Feb 2026 14:20:03 -0800 (PST)", "by 2002:a05:7022:238d:b0:11f:2c9e:87f8 with SMTP id\n a92af1059eb24-1272f7a13e8mr325289c88.34.1770848402318;\n Wed, 11 Feb 2026 14:20:02 -0800 (PST)" ], "From": "Brian Cain <brian.cain@oss.qualcomm.com>", "To": "qemu-devel@nongnu.org", "Cc": "brian.cain@oss.qualcomm.com, ltaylorsimpson@gmail.com, alex@alexrp.com", "Subject": "[PATCH v4 4/4] target/hexagon: Detect register write conflicts", "Date": "Wed, 11 Feb 2026 14:19:53 -0800", "Message-Id": "<20260211221953.4099441-5-brian.cain@oss.qualcomm.com>", "X-Mailer": "git-send-email 2.34.1", "In-Reply-To": "<20260211221953.4099441-1-brian.cain@oss.qualcomm.com>", "References": "<20260211221953.4099441-1-brian.cain@oss.qualcomm.com>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=\"utf-8\"", "Content-Transfer-Encoding": "8bit", "X-Proofpoint-Spam-Details-Enc": "AW1haW4tMjYwMjExMDE3MSBTYWx0ZWRfX/v0gy2yjnwDX\n umYtMDkjhS9UyCbFtkQM4ib+Wgbzk0S0ZwM1TPavaHoSEfiHVudwQAJU0gp8PM5h7txfGiyy9ig\n 1zEgJi59jY3YuEfHaQoj4Z8HcvuA4lJKtB6iozpcl3FWkbsyh6CgE3rIr+5vc5LcYhPpDBqHsMN\n tkitWZRf06nO2h+ALajKJCHlR+VPNS1tLY3k2Kd0f1vo4p1/VnKff9nmKXEZK6T6MgdyrzbgJkv\n jgXDosJaFdo0X6wSTbSkb8xnbpRZxDVKxUdMta6Z6OPwo/GYyaz9z9wQNF8/sQpZ08S2EHDIocZ\n ELqvhBMrD4cAkmPSbT+7vAL80vgTI5/zE1StmoCaJ3dJqOqq+CK/eKDkmE/UTAPb3DP9vkfJF/a\n tTSx4dd/mtZojd2szlsQORVw14g3u2P+Q1hc6/sD6kn2SxWGdF1czw4eH21Ir4Do+e51g/Q4iBW\n Y0gMH8UkIu6uALiqP7g==", "X-Proofpoint-GUID": "CTHuzx62QJsretE6Stx2_8Z-VyHf8sv7", "X-Authority-Analysis": "v=2.4 cv=Uslu9uwB c=1 sm=1 tr=0 ts=698d0094 cx=c_pps\n a=SvEPeNj+VMjHSW//kvnxuw==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17\n a=IkcTkHD0fZMA:10 a=HzLeVaNsDn8A:10 a=s4-Qcg_JpJYA:10\n a=VkNPw1HP01LnGYTKEx00:22 a=Mpw57Om8IfrbqaoTuvik:22 a=GgsMoib0sEa3-_RKJdDe:22\n a=p0WdMEafAAAA:8 a=EUspDBNiAAAA:8 a=y1hdNQ4epmxxkZQEW8sA:9 a=QEXdDO2ut3YA:10\n a=Kq8ClHjjuc5pcCNDwlU0:22", "X-Proofpoint-ORIG-GUID": "CTHuzx62QJsretE6Stx2_8Z-VyHf8sv7", "X-Proofpoint-Virus-Version": "vendor=baseguard\n engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.51,FMLib:17.12.100.49\n definitions=2026-02-11_03,2026-02-11_04,2025-10-01_01", "X-Proofpoint-Spam-Details": "rule=outbound_notspam policy=outbound score=0\n spamscore=0 adultscore=0 malwarescore=0 phishscore=0 impostorscore=0\n bulkscore=0 suspectscore=0 clxscore=1015 priorityscore=1501\n lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc=\n route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000\n definitions=main-2602110171", "Received-SPF": "pass client-ip=205.220.168.131;\n envelope-from=brian.cain@oss.qualcomm.com; helo=mx0a-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,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001,\n RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001,\n 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 <qemu-devel.nongnu.org>", "List-Unsubscribe": "<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>", "List-Archive": "<https://lists.nongnu.org/archive/html/qemu-devel>", "List-Post": "<mailto:qemu-devel@nongnu.org>", "List-Help": "<mailto:qemu-devel-request@nongnu.org?subject=help>", "List-Subscribe": "<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>", "Errors-To": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org", "Sender": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org" }, "content": "A conflict exists when any GPR is written by multiple instructions and\nat least one write is unconditional. This catches (1) two unconditional\nwrites to the same GPR and (2) an unconditional write combined with a\npredicated write.\n\nAdd HEX_CAUSE_REG_WRITE_CONFLICT and map it to SIGILL.\n\nResolves: https://gitlab.com/qemu-project/qemu/-/issues/2696\nSigned-off-by: Brian Cain <brian.cain@oss.qualcomm.com>\n---\n linux-user/hexagon/cpu_loop.c | 1 +\n target/hexagon/cpu_bits.h | 1 +\n target/hexagon/decode.c | 54 +++++++++\n target/hexagon/gen_trans_funcs.py | 10 ++\n target/hexagon/insn.h | 4 +\n target/hexagon/translate.c | 10 +-\n tests/tcg/hexagon/Makefile.target | 1 +\n tests/tcg/hexagon/multiple-writes.c | 169 ++++++++++++++++++++++++++++\n 8 files changed, 248 insertions(+), 2 deletions(-)\n create mode 100644 tests/tcg/hexagon/multiple-writes.c", "diff": "diff --git a/linux-user/hexagon/cpu_loop.c b/linux-user/hexagon/cpu_loop.c\nindex c0e1098e3f..5711055aff 100644\n--- a/linux-user/hexagon/cpu_loop.c\n+++ b/linux-user/hexagon/cpu_loop.c\n@@ -65,6 +65,7 @@ void cpu_loop(CPUHexagonState *env)\n env->gpr[HEX_REG_R31]);\n break;\n case HEX_CAUSE_INVALID_PACKET:\n+ case HEX_CAUSE_REG_WRITE_CONFLICT:\n force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPC,\n env->gpr[HEX_REG_PC]);\n break;\ndiff --git a/target/hexagon/cpu_bits.h b/target/hexagon/cpu_bits.h\nindex ff596e2a94..19beca81c0 100644\n--- a/target/hexagon/cpu_bits.h\n+++ b/target/hexagon/cpu_bits.h\n@@ -34,6 +34,7 @@ enum hex_cause {\n HEX_CAUSE_FETCH_NO_UPAGE = 0x012,\n HEX_CAUSE_INVALID_PACKET = 0x015,\n HEX_CAUSE_INVALID_OPCODE = 0x015,\n+ HEX_CAUSE_REG_WRITE_CONFLICT = 0x01d,\n HEX_CAUSE_PC_NOT_ALIGNED = 0x01e,\n HEX_CAUSE_PRIV_NO_UREAD = 0x024,\n HEX_CAUSE_PRIV_NO_UWRITE = 0x025,\ndiff --git a/target/hexagon/decode.c b/target/hexagon/decode.c\nindex 33ad60c5b4..00d4a79a95 100644\n--- a/target/hexagon/decode.c\n+++ b/target/hexagon/decode.c\n@@ -655,6 +655,55 @@ decode_set_slot_number(Packet *pkt)\n return has_valid_slot_assignment(pkt);\n }\n \n+/*\n+ * Check for GPR write conflicts in the packet.\n+ * A conflict exists when a register is written by more than one instruction\n+ * and at least one of those writes is unconditional.\n+ *\n+ * TODO: handle the more general case of any\n+ * packet w/multiple-register-write operands.\n+ */\n+static bool pkt_has_write_conflict(Packet *pkt)\n+{\n+ DECLARE_BITMAP(all_dest_gprs, 32) = { 0 };\n+ DECLARE_BITMAP(wreg_mult_gprs, 32) = { 0 };\n+ DECLARE_BITMAP(uncond_wreg_gprs, 32) = { 0 };\n+ DECLARE_BITMAP(conflict, 32);\n+\n+ for (int i = 0; i < pkt->num_insns; i++) {\n+ Insn *insn = &pkt->insn[i];\n+ int dest = insn->dest_idx;\n+\n+ if (dest < 0 || !insn->dest_is_gpr) {\n+ continue;\n+ }\n+\n+ int rnum = insn->regno[dest];\n+ bool is_uncond = !GET_ATTRIB(insn->opcode, A_CONDEXEC);\n+\n+ if (test_bit(rnum, all_dest_gprs)) {\n+ set_bit(rnum, wreg_mult_gprs);\n+ }\n+ set_bit(rnum, all_dest_gprs);\n+ if (is_uncond) {\n+ set_bit(rnum, uncond_wreg_gprs);\n+ }\n+\n+ if (insn->dest_is_pair) {\n+ if (test_bit(rnum + 1, all_dest_gprs)) {\n+ set_bit(rnum + 1, wreg_mult_gprs);\n+ }\n+ set_bit(rnum + 1, all_dest_gprs);\n+ if (is_uncond) {\n+ set_bit(rnum + 1, uncond_wreg_gprs);\n+ }\n+ }\n+ }\n+\n+ bitmap_and(conflict, wreg_mult_gprs, uncond_wreg_gprs, 32);\n+ return !bitmap_empty(conflict, 32);\n+}\n+\n /*\n * decode_packet\n * Decodes packet with given words\n@@ -674,6 +723,10 @@ int decode_packet(DisasContext *ctx, int max_words, const uint32_t *words,\n \n /* Initialize */\n memset(pkt, 0, sizeof(*pkt));\n+ for (i = 0; i < INSTRUCTIONS_MAX; i++) {\n+ pkt->insn[i].dest_idx = -1;\n+ pkt->insn[i].new_read_idx = -1;\n+ }\n /* Try to build packet */\n while (!end_of_packet && (words_read < max_words)) {\n Insn *insn = &pkt->insn[num_insns];\n@@ -737,6 +790,7 @@ int decode_packet(DisasContext *ctx, int max_words, const uint32_t *words,\n /* Invalid packet */\n return 0;\n }\n+ pkt->pkt_has_write_conflict = pkt_has_write_conflict(pkt);\n }\n decode_fill_newvalue_regno(pkt);\n \ndiff --git a/target/hexagon/gen_trans_funcs.py b/target/hexagon/gen_trans_funcs.py\nindex 45da1b7b5d..19c1f9fdea 100755\n--- a/target/hexagon/gen_trans_funcs.py\n+++ b/target/hexagon/gen_trans_funcs.py\n@@ -91,6 +91,8 @@ def gen_trans_funcs(f):\n new_read_idx = -1\n dest_idx = -1\n dest_idx_reg_id = None\n+ dest_is_pair = \"false\"\n+ dest_is_gpr = \"false\"\n has_pred_dest = \"false\"\n for regno, (reg_type, reg_id, *_) in enumerate(regs):\n reg = hex_common.get_register(tag, reg_type, reg_id)\n@@ -104,6 +106,12 @@ def gen_trans_funcs(f):\n if dest_idx_reg_id is None or reg_id < dest_idx_reg_id:\n dest_idx = regno\n dest_idx_reg_id = reg_id\n+ dest_is_pair = (\"true\"\n+ if isinstance(reg, hex_common.Pair)\n+ else \"false\")\n+ dest_is_gpr = (\"true\"\n+ if reg_type == \"R\"\n+ else \"false\")\n if reg_type == \"P\" and reg.is_written() and not reg.is_read():\n has_pred_dest = \"true\"\n \n@@ -129,6 +137,8 @@ def gen_trans_funcs(f):\n f.write(code_fmt(f\"\"\"\\\n insn->new_read_idx = {new_read_idx};\n insn->dest_idx = {dest_idx};\n+ insn->dest_is_pair = {dest_is_pair};\n+ insn->dest_is_gpr = {dest_is_gpr};\n insn->has_pred_dest = {has_pred_dest};\n \"\"\"))\n f.write(textwrap.dedent(f\"\"\"\\\ndiff --git a/target/hexagon/insn.h b/target/hexagon/insn.h\nindex 5d59430da9..835b1c954e 100644\n--- a/target/hexagon/insn.h\n+++ b/target/hexagon/insn.h\n@@ -41,6 +41,8 @@ struct Instruction {\n uint32_t new_value_producer_slot:4;\n int32_t new_read_idx;\n int32_t dest_idx;\n+ bool dest_is_pair;\n+ bool dest_is_gpr;\n bool has_pred_dest;\n \n bool part1; /*\n@@ -72,6 +74,8 @@ struct Packet {\n bool pkt_has_hvx;\n Insn *vhist_insn;\n \n+ bool pkt_has_write_conflict;\n+\n Insn insn[INSTRUCTIONS_MAX];\n };\n \ndiff --git a/target/hexagon/translate.c b/target/hexagon/translate.c\nindex 7fe8b35351..0234bbf15d 100644\n--- a/target/hexagon/translate.c\n+++ b/target/hexagon/translate.c\n@@ -943,7 +943,7 @@ static void gen_commit_packet(DisasContext *ctx)\n static void decode_and_translate_packet(CPUHexagonState *env, DisasContext *ctx)\n {\n uint32_t words[PACKET_WORDS_MAX];\n- int nwords;\n+ int nwords, words_read;\n Packet pkt;\n int i;\n \n@@ -954,8 +954,14 @@ static void decode_and_translate_packet(CPUHexagonState *env, DisasContext *ctx)\n }\n \n ctx->pkt = &pkt;\n- if (decode_packet(ctx, nwords, words, &pkt, false) > 0) {\n+ words_read = decode_packet(ctx, nwords, words, &pkt, false);\n+ if (words_read > 0) {\n pkt.pc = ctx->base.pc_next;\n+ if (pkt.pkt_has_write_conflict) {\n+ gen_exception_decode_fail(ctx, words_read,\n+ HEX_CAUSE_REG_WRITE_CONFLICT);\n+ return;\n+ }\n gen_start_packet(ctx);\n for (i = 0; i < pkt.num_insns; i++) {\n ctx->insn = &pkt.insn[i];\ndiff --git a/tests/tcg/hexagon/Makefile.target b/tests/tcg/hexagon/Makefile.target\nindex d64aeba090..f86f02bb31 100644\n--- a/tests/tcg/hexagon/Makefile.target\n+++ b/tests/tcg/hexagon/Makefile.target\n@@ -52,6 +52,7 @@ HEX_TESTS += hvx_misc\n HEX_TESTS += hvx_histogram\n HEX_TESTS += invalid-slots\n HEX_TESTS += invalid-encoding\n+HEX_TESTS += multiple-writes\n HEX_TESTS += unaligned_pc\n \n HEX_TESTS += test_abs\ndiff --git a/tests/tcg/hexagon/multiple-writes.c b/tests/tcg/hexagon/multiple-writes.c\nnew file mode 100644\nindex 0000000000..8686317fdc\n--- /dev/null\n+++ b/tests/tcg/hexagon/multiple-writes.c\n@@ -0,0 +1,169 @@\n+/*\n+ * Test detection of multiple writes to the same register.\n+ *\n+ * Ported from the system test (tests/tcg/hexagon/system/multiple_writes.c).\n+ * In linux-user mode, duplicate GPR writes are detected at translate time\n+ * and raise SIGILL when at least one conflicting write is unconditional.\n+ * Purely predicated duplicate writes (e.g., complementary if/if-not) are\n+ * legal and are not flagged statically.\n+ *\n+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.\n+ * SPDX-License-Identifier: GPL-2.0-or-later\n+ */\n+\n+#include <assert.h>\n+#include <signal.h>\n+#include <stdio.h>\n+#include <stdlib.h>\n+#include <string.h>\n+#include <unistd.h>\n+\n+static void *resume_pc;\n+\n+static void handle_sigill(int sig, siginfo_t *info, void *puc)\n+{\n+ ucontext_t *uc = (ucontext_t *)puc;\n+\n+ if (sig != SIGILL) {\n+ _exit(EXIT_FAILURE);\n+ }\n+\n+ uc->uc_mcontext.r0 = SIGILL;\n+ uc->uc_mcontext.pc = (unsigned long)resume_pc;\n+}\n+\n+/*\n+ * Unconditional pair write overlapping a single write:\n+ * { r1:0 = add(r3:2, r3:2); r1 = add(r0, r1) }\n+ * R1 is written by both instructions. This is invalid and must raise SIGILL.\n+ */\n+static int test_static_pair_overlap(void)\n+{\n+ int sig;\n+\n+ asm volatile(\n+ \"r0 = #0\\n\"\n+ \"r1 = ##1f\\n\"\n+ \"memw(%1) = r1\\n\"\n+ \".word 0xd30242e0\\n\" /* r1:0 = add(r3:2, r3:2), parse=01 */\n+ \".word 0xf300c101\\n\" /* r1 = add(r0, r1), parse=11 (end) */\n+ \"1:\\n\"\n+ \"%0 = r0\\n\"\n+ : \"=r\"(sig)\n+ : \"r\"(&resume_pc)\n+ : \"r0\", \"r1\", \"memory\");\n+\n+ return sig;\n+}\n+\n+/*\n+ * Two predicated writes under complementary predicates:\n+ * { if (p0) r0 = r2; if (!p0) r0 = r3 }\n+ * This is architecturally valid: only one write executes at runtime.\n+ * Must NOT raise SIGILL; the result should reflect the executed branch.\n+ */\n+static int test_legal_predicated(void)\n+{\n+ int result;\n+\n+ asm volatile(\n+ \"r0 = #0\\n\"\n+ \"r1 = ##1f\\n\"\n+ \"memw(%1) = r1\\n\"\n+ \"r2 = #7\\n\"\n+ \"r3 = #13\\n\"\n+ \"p0 = cmp.eq(r2, r2)\\n\"\n+ \"{\\n\"\n+ \" if (p0) r0 = r2\\n\"\n+ \" if (!p0) r0 = r3\\n\"\n+ \"}\\n\"\n+ \"1:\\n\"\n+ \"%0 = r0\\n\"\n+ : \"=r\"(result)\n+ : \"r\"(&resume_pc)\n+ : \"r0\", \"r1\", \"r2\", \"r3\", \"p0\", \"memory\");\n+\n+ return result;\n+}\n+\n+/*\n+ * Mixed: unconditional + predicated writes to the same register:\n+ * { if (p0) r1 = add(r0, #0); if (!p0) r1 = add(r0, #0);\n+ * r1 = add(r0, #0) }\n+ * The unconditional write always conflicts with the predicated writes.\n+ * Must raise SIGILL.\n+ */\n+static int test_mixed_writes(void)\n+{\n+ int sig;\n+\n+ asm volatile(\n+ \"r0 = #0\\n\"\n+ \"r1 = ##1f\\n\"\n+ \"memw(%1) = r1\\n\"\n+ \"p0 = cmp.eq(r0, r0)\\n\"\n+ \".word 0x7e204021\\n\" /* if (p0) r1 = add(r0, #0), parse=01 */\n+ \".word 0x7ea04021\\n\" /* if (!p0) r1 = add(r0, #0), parse=01 */\n+ \".word 0x7800c021\\n\" /* r1 = add(r0, #0), parse=11 (end) */\n+ \"1:\\n\"\n+ \"%0 = r0\\n\"\n+ : \"=r\"(sig)\n+ : \"r\"(&resume_pc)\n+ : \"r0\", \"r1\", \"p0\", \"memory\");\n+\n+ return sig;\n+}\n+\n+/*\n+ * Zero encoding (issue #2696):\n+ * The encoding 0x00000000 decodes as a duplex with parse bits\n+ * [15:14] = 0b00:\n+ * slot1: SL1_loadri_io R0 = memw(R0+#0x0)\n+ * slot0: SL1_loadri_io R0 = memw(R0+#0x0)\n+ *\n+ * Both sub-instructions write R0 unconditionally, which is an invalid\n+ * packet. This tests what happens when we jump to zeroed memory.\n+ * Must raise SIGILL.\n+ */\n+static int test_zero(void)\n+{\n+ int sig;\n+\n+ asm volatile(\n+ \"r0 = #0\\n\"\n+ \"r1 = ##1f\\n\"\n+ \"memw(%1) = r1\\n\"\n+ \".word 0x00000000\\n\"\n+ \"1:\\n\"\n+ \"%0 = r0\\n\"\n+ : \"=r\"(sig)\n+ : \"r\"(&resume_pc)\n+ : \"r0\", \"r1\", \"memory\");\n+\n+ return sig;\n+}\n+\n+int main()\n+{\n+ struct sigaction act;\n+\n+ memset(&act, 0, sizeof(act));\n+ act.sa_sigaction = handle_sigill;\n+ act.sa_flags = SA_SIGINFO;\n+ assert(sigaction(SIGILL, &act, NULL) == 0);\n+\n+ /* Legal: complementary predicated writes must not raise SIGILL */\n+ assert(test_legal_predicated() == 7);\n+\n+ /* Illegal: unconditional pair + single overlap must raise SIGILL */\n+ assert(test_static_pair_overlap() == SIGILL);\n+\n+ /* Illegal: unconditional + predicated writes to same reg must SIGILL */\n+ assert(test_mixed_writes() == SIGILL);\n+\n+ /* Illegal: zero encoding = duplex with duplicate dest R0 */\n+ assert(test_zero() == SIGILL);\n+\n+ puts(\"PASS\");\n+ return EXIT_SUCCESS;\n+}\n", "prefixes": [ "v4", "4/4" ] }