From nobody Sun May 19 07:31:44 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=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1618332871; cv=none; d=zohomail.com; s=zohoarc; b=jFveUcfJTs7grUrSQCi6Mf6Y9dfPjVXpF90umf6nzN38zL+yPxU8e1asJiabPnRKP7ESWYUBeJZXQTHFCfQmOm4BVfli3u+7I0c1ofXgv7fiYdkid94ZqBLvjuq4m7+ZUArdUKQari5BtyxFh36/N7pVXClLPgdsNgAeZyYiysw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618332871; h=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=N+3ciEoBskBkrrnE9PvWY3GtmyTchbQ1ArM7Sw8F8s4=; b=Mmdn4jnkmqNogPApEosIWGhLkXMYhBi8mFLHXlyib2dKExT7g5aZWcpdydUsZCddHPdyCH+3uyIffkaLclaGyC1jnVaYttWgXVz0XarwJ96HH4f0K0g88df8o3QCDkLYgJhMpElP4nH07UiflwW5S4wBy0F9cBI1RWSfkYM/W+M= 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) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1618332871833383.8397031596097; Tue, 13 Apr 2021 09:54:31 -0700 (PDT) Received: from localhost ([::1]:44192 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lWMJ4-0003Qt-2D for importer@patchew.org; Tue, 13 Apr 2021 12:54:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52744) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lWMHo-0002YB-3w; Tue, 13 Apr 2021 12:53:12 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:9240 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lWMHl-0002ko-Om; Tue, 13 Apr 2021 12:53:11 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13DGmYp9152126; Tue, 13 Apr 2021 12:53:07 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 37vtntekxb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 12:53:07 -0400 Received: from m0098420.ppops.net (m0098420.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 13DGmc8F152561; Tue, 13 Apr 2021 12:53:07 -0400 Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0b-001b2d01.pphosted.com with ESMTP id 37vtntekwp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 12:53:06 -0400 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 13DGqhxx000775; Tue, 13 Apr 2021 16:53:05 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma03fra.de.ibm.com with ESMTP id 37u3n89gex-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 16:53:04 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13DGqdup24969686 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Apr 2021 16:52:39 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 820164C040; Tue, 13 Apr 2021 16:53:01 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 018194C04A; Tue, 13 Apr 2021 16:53:01 +0000 (GMT) Received: from vm.lan (unknown [9.145.157.105]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 13 Apr 2021 16:53:00 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : content-transfer-encoding : mime-version; s=pp1; bh=N+3ciEoBskBkrrnE9PvWY3GtmyTchbQ1ArM7Sw8F8s4=; b=ih8/EfNLk7iodHX6P1c06vcZhVlpY9IVUCZkAAvzBxpTYYslIOzUbc/c3Os3nVyisgZE UNufbtyBfNypYfR3cV5n+yNLrMYDOgLJLwLcsF+dE0/RuL6xeecxQYI+0y0X17Gk+WeB IgK9XP6mE+Bi0LN60P9k9hmj/yFUHQ0tH7wWFQQuUlZnu+2N6qVcwA64FqjvAQoGyPZ1 BAMTcpLp5W+qm9ho+FoslzP+6iCnjcJ5/tJ6fpBQaggR9hIGO4eXy2edv5n17Z8OCg+I cnYyqjO/gCogNHKr1WO7q4Os1TY3aKlR5fY3HTUX0VModtgeddsO3CaPsLI5M8zPheuv Hw== From: Ilya Leoshkevich To: Cornelia Huck , Thomas Huth , Richard Henderson , David Hildenbrand , Paolo Bonzini Subject: [PATCH v2] target/s390x: Fix translation exception on illegal instruction Date: Tue, 13 Apr 2021 18:52:57 +0200 Message-Id: <20210413165257.21426-1-iii@linux.ibm.com> X-Mailer: git-send-email 2.29.2 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 4VJHiqpVA1yiwPtvEQEeDlwkU0zf3Ffg X-Proofpoint-ORIG-GUID: qKFiUzyPrAJ-QhRW1w_-33s7Az4m16jh Content-Transfer-Encoding: quoted-printable X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-04-13_09:2021-04-13, 2021-04-13 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 mlxscore=0 impostorscore=0 clxscore=1011 mlxlogscore=999 bulkscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104130111 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.158.5; envelope-from=iii@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Christian Borntraeger , qemu-s390x@nongnu.org, qemu-devel@nongnu.org, Ilya Leoshkevich Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @ibm.com) Content-Type: text/plain; charset="utf-8" Hitting an uretprobe in a s390x TCG guest causes a SIGSEGV. What happens is: * uretprobe maps a userspace page containing an invalid instruction. * uretprobe replaces the target function's return address with the address of that page. * When tb_gen_code() is called on that page, tb->size ends up being 0 (because the page starts with the invalid instruction), which causes virt_page2 to point to the previous page. * The previous page is not mapped, so this causes a spurious translation exception. The bug is that tb->size must never be 0: even if there is an illegal instruction, the instruction bytes that have been looked at must count towards tb->size. So adjust s390x's translate_one() to act this way for both illegal instructions and instructions that are known to generate exceptions. Also add an assertion to tb_gen_code() in order to detect such situations in future. Signed-off-by: Ilya Leoshkevich Reviewed-by: David Hildenbrand Reviewed-by: Richard Henderson --- v1: https://lists.nongnu.org/archive/html/qemu-devel/2021-04/msg02037.html v1 -> v2: Fix target/s390x instead of trying to tolerate tb->size =3D=3D 0 in tb_gen_code(). accel/tcg/translate-all.c | 1 + target/s390x/translate.c | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index ba6ab09790..93b2dae112 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1913,6 +1913,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, =20 tcg_ctx->cpu =3D env_cpu(env); gen_intermediate_code(cpu, tb, max_insns); + assert(tb->size !=3D 0); tcg_ctx->cpu =3D NULL; max_insns =3D tb->icount; =20 diff --git a/target/s390x/translate.c b/target/s390x/translate.c index 4f953ddfba..e243624d2a 100644 --- a/target/s390x/translate.c +++ b/target/s390x/translate.c @@ -6412,7 +6412,8 @@ static DisasJumpType translate_one(CPUS390XState *env= , DisasContext *s) qemu_log_mask(LOG_UNIMP, "unimplemented opcode 0x%02x%02x\n", s->fields.op, s->fields.op2); gen_illegal_opcode(s); - return DISAS_NORETURN; + ret =3D DISAS_NORETURN; + goto out; } =20 #ifndef CONFIG_USER_ONLY @@ -6428,7 +6429,8 @@ static DisasJumpType translate_one(CPUS390XState *env= , DisasContext *s) /* privileged instruction */ if ((s->base.tb->flags & FLAG_MASK_PSTATE) && (insn->flags & IF_PR= IV)) { gen_program_exception(s, PGM_PRIVILEGED); - return DISAS_NORETURN; + ret =3D DISAS_NORETURN; + goto out; } =20 /* if AFP is not enabled, instructions and registers are forbidden= */ @@ -6455,7 +6457,8 @@ static DisasJumpType translate_one(CPUS390XState *env= , DisasContext *s) } if (dxc) { gen_data_exception(dxc); - return DISAS_NORETURN; + ret =3D DISAS_NORETURN; + goto out; } } =20 @@ -6463,7 +6466,8 @@ static DisasJumpType translate_one(CPUS390XState *env= , DisasContext *s) if (insn->flags & IF_VEC) { if (!((s->base.tb->flags & FLAG_MASK_VECTOR))) { gen_data_exception(0xfe); - return DISAS_NORETURN; + ret =3D DISAS_NORETURN; + goto out; } } =20 @@ -6484,7 +6488,8 @@ static DisasJumpType translate_one(CPUS390XState *env= , DisasContext *s) (insn->spec & SPEC_r1_f128 && !is_fp_pair(get_field(s, r1))) || (insn->spec & SPEC_r2_f128 && !is_fp_pair(get_field(s, r2)))) { gen_program_exception(s, PGM_SPECIFICATION); - return DISAS_NORETURN; + ret =3D DISAS_NORETURN; + goto out; } } =20 @@ -6544,6 +6549,7 @@ static DisasJumpType translate_one(CPUS390XState *env= , DisasContext *s) } #endif =20 +out: /* Advance to the next instruction. */ s->base.pc_next =3D s->pc_tmp; return ret; --=20 2.29.2