From nobody Sun Feb 8 04:33:59 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=none dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1659979247; cv=none; d=zohomail.com; s=zohoarc; b=aG1Gbkp0tX2KBgwMln2MD2a2NjgnAVwvfYKauHkpURyUqlz8bA6qTEpKpICCSmH9Z9hQKcOIQWXak6AbUhsfmPyWIt2ehSzJJL0k7694z9uB0iTXDI4fncCk9QeW2PweTXLpY6U7QQkFWP72JSydfTJR6AitV4zNG0hpN2TjaR0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659979247; 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=rrw+mp9TzS2pJn58f64ODmg0k/jxtExk7TaSxjITx1M=; b=QDS7mzZ7pYp97SewO/W9F8HzMuvKmAdf+rCHgU+2jzdfob3uECVgdRKO50sPWOpQ8kfmEG/cZKvw56W57qJfnY5Y1h8Qxf1QiCaMh/li4Y7UBV6axOFog2P/b6M9FoxPTFWa6dIGafhZJqidvfDn3kOZs3tZhYxLTAYk1AprAo8= 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 1659979247462500.45743446255597; Mon, 8 Aug 2022 10:20:47 -0700 (PDT) Received: from localhost ([::1]:50604 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oL6Qo-0004DJ-6z for importer@patchew.org; Mon, 08 Aug 2022 13:20:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59676) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oL6HB-0003tQ-9S; Mon, 08 Aug 2022 13:10:49 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:4734) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oL6H9-00036k-DB; Mon, 08 Aug 2022 13:10:49 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 278GrmV0018381; Mon, 8 Aug 2022 17:10:33 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3hu6dpgj3b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 Aug 2022 17:10:33 +0000 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 278GsLS5024160; Mon, 8 Aug 2022 17:10:32 GMT Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3hu6dpgj1s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 Aug 2022 17:10:32 +0000 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 278GoS9V014217; Mon, 8 Aug 2022 17:10:30 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma04fra.de.ibm.com with ESMTP id 3hsfx8suad-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 Aug 2022 17:10:30 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 278HAQps5767536 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 8 Aug 2022 17:10:26 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7A2ABA404D; Mon, 8 Aug 2022 17:10:26 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D9D2DA4040; Mon, 8 Aug 2022 17:10:25 +0000 (GMT) Received: from heavy.ibmuc.com (unknown [9.171.43.253]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 8 Aug 2022 17:10:25 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=rrw+mp9TzS2pJn58f64ODmg0k/jxtExk7TaSxjITx1M=; b=o2BhAm6drHxjZ1t52fy9MxWv8pq1wVu1BnNtRIGHCW6AzQNxTCeCOIFYNDOWnAMLe0zx L3L0tAI1Vz6ajBLRzIeuR4yLEIdwlJYVvn9z1mWgYUGbzD2d+tn21wgEpwsUbhiVsVqM uZOfWez9sfS60k1mIaJ0U59BpAh8PishbFB47PuzexxRt53WUEBuZGnTP7433ZEWcggq Q2ixYywLGQwmW5hPHsbLa6WLHaQklb+ovUAU8p5MmBzYDTzJy9nsP+1RMvgjc0inOV+/ cGXeqBC3eaI0b8WfxNgfVfOctnTMeRy4As5Snrb2cm9adml4SDSRatZdg91YICk8xjen Zg== From: Ilya Leoshkevich To: Laurent Vivier , Eduardo Habkost , Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Richard Henderson , Paolo Bonzini , David Hildenbrand , Peter Maydell Cc: qemu-devel@nongnu.org, qemu-s390x@nongnu.org, Christian Borntraeger , Ilya Leoshkevich Subject: [PATCH v3 3/4] target/i386: Make translator stop before the end of a page Date: Mon, 8 Aug 2022 19:10:21 +0200 Message-Id: <20220808171022.49439-4-iii@linux.ibm.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220808171022.49439-1-iii@linux.ibm.com> References: <20220808171022.49439-1-iii@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: OxjS7kEghouYutZNFsnMHVlquJnzOq2V X-Proofpoint-GUID: PLDfh15eonEqly0R4-iDJjBJFrSiOHzU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-08_11,2022-08-08_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 priorityscore=1501 impostorscore=0 mlxscore=0 spamscore=0 phishscore=0 lowpriorityscore=0 clxscore=1015 bulkscore=0 malwarescore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2208080080 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=148.163.156.1; envelope-from=iii@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1659979249123100001 Content-Type: text/plain; charset="utf-8" Right now translator stops right *after* the end of a page, which breaks reporting of fault locations when the last instruction of a multi-insn translation block crosses a page boundary. An implementation, like the one arm and s390x have, would require an i386 length disassembler, which is burdensome to maintain. Another alternative would be to single-step at the end of a guest page, but this may come with a performance impact. Fix by snapshotting disassembly state and restoring it after we figure out we crossed a page boundary. This includes rolling back cc_op updates and emitted ops. Even though i386 is the only architecture that does rollback, split it into common and architecture-dependent parts to improve readability. Signed-off-by: Ilya Leoshkevich --- accel/tcg/translator.c | 8 ++++++++ include/exec/translator.h | 3 +++ target/i386/tcg/translate.c | 21 ++++++++++++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index fe7af9b943..2c4dd09df8 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -56,6 +56,7 @@ void translator_loop(const TranslatorOps *ops, DisasConte= xtBase *db, { uint32_t cflags =3D tb_cflags(tb); bool plugin_enabled; + TCGOp *last_op; =20 /* Initialize DisasContext */ db->tb =3D tb; @@ -82,6 +83,7 @@ void translator_loop(const TranslatorOps *ops, DisasConte= xtBase *db, =20 while (true) { db->num_insns++; + last_op =3D tcg_last_op(); ops->insn_start(db, cpu); tcg_debug_assert(db->is_jmp =3D=3D DISAS_NEXT); /* no early exit = */ =20 @@ -103,6 +105,12 @@ void translator_loop(const TranslatorOps *ops, DisasCo= ntextBase *db, ops->translate_insn(db, cpu); } =20 + if (db->is_jmp =3D=3D DISAS_TOO_MANY_UNDO) { + db->num_insns--; + tcg_remove_ops_after(last_op); + db->is_jmp =3D DISAS_TOO_MANY; + } + /* Stop translation if translate_insn so indicated. */ if (db->is_jmp !=3D DISAS_NEXT) { break; diff --git a/include/exec/translator.h b/include/exec/translator.h index d27f8c33b6..e1533aee87 100644 --- a/include/exec/translator.h +++ b/include/exec/translator.h @@ -31,6 +31,8 @@ * DisasJumpType: * @DISAS_NEXT: Next instruction in program order. * @DISAS_TOO_MANY: Too many instructions translated. + * @DISAS_TOO_MANY_UNDO: Too many instructions translated. Everything that= was + * done for the current instruction must be undone. * @DISAS_NORETURN: Following code is dead. * @DISAS_TARGET_*: Start of target-specific conditions. * @@ -39,6 +41,7 @@ typedef enum DisasJumpType { DISAS_NEXT, DISAS_TOO_MANY, + DISAS_TOO_MANY_UNDO, DISAS_NORETURN, DISAS_TARGET_0, DISAS_TARGET_1, diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index b7972f0ff5..14d4ed1412 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -2008,6 +2008,12 @@ static uint64_t advance_pc(CPUX86State *env, DisasCo= ntext *s, int num_bytes) { uint64_t pc =3D s->pc; =20 + /* This is a subsequent insn that crosses a page boundary. */ + if (s->base.num_insns > 1 && + !is_same_page(&s->base, s->pc + num_bytes - 1)) { + siglongjmp(s->jmpbuf, 2); + } + s->pc +=3D num_bytes; if (unlikely(s->pc - s->pc_start > X86_MAX_INSN_LENGTH)) { /* If the instruction's 16th byte is on a different page than the = 1st, a @@ -4556,6 +4562,8 @@ static target_ulong disas_insn(DisasContext *s, CPUSt= ate *cpu) int modrm, reg, rm, mod, op, opreg, val; target_ulong next_eip, tval; target_ulong pc_start =3D s->base.pc_next; + bool orig_cc_op_dirty =3D s->cc_op_dirty; + CCOp orig_cc_op =3D s->cc_op; =20 s->pc_start =3D s->pc =3D pc_start; s->override =3D -1; @@ -4568,9 +4576,20 @@ static target_ulong disas_insn(DisasContext *s, CPUS= tate *cpu) s->rip_offset =3D 0; /* for relative ip address */ s->vex_l =3D 0; s->vex_v =3D 0; - if (sigsetjmp(s->jmpbuf, 0) !=3D 0) { + switch (sigsetjmp(s->jmpbuf, 0)) { + case 0: + break; + case 1: gen_exception_gpf(s); return s->pc; + case 2: + /* Restore state that may affect the next instruction. */ + s->cc_op_dirty =3D orig_cc_op_dirty; + s->cc_op =3D orig_cc_op; + s->base.is_jmp =3D DISAS_TOO_MANY_UNDO; + return pc_start; + default: + g_assert_not_reached(); } =20 prefixes =3D 0; --=20 2.37.1