From nobody Fri May 3 00:35:12 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=1660749083; cv=none; d=zohomail.com; s=zohoarc; b=QvlM6gPvXoudVlr8504FGn493gVEjSJ/tspNEQWBmuLJeqsCxilxX4lEsl9tgDsYgbSsgnEAeNsdZ07uA2ormvJa7dy65dr7JmwGg2qtA4kT6B5EQ43I2kBsO9Kup7kM+qnuONyAucu7ATPpM5rmangkoBoqhB71rZVDP/pDVE0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660749083; 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=vqZRHJ9RxWAUXvKEyj3EOy8OvEHfmt8c6QT0ya1G7qY=; b=dscSoZR7zN8hjMnOShxke8k4jxluAFjRlWTZ4g5VF3jBonidlKF0RvQ+YrbwF9aY1yQeVjyUm7MeT7852GfGG1dXwkpnoaOal+vk3lbLH8eZRzcOIWWmIhUd9uNA5hmGIy42elAJCBhepLgh1ib7Zk+SSStaq0VKuzaF1cCDjyM= 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 1660749083248340.2585652694993; Wed, 17 Aug 2022 08:11:23 -0700 (PDT) Received: from localhost ([::1]:55696 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oOKhV-00026S-W8 for importer@patchew.org; Wed, 17 Aug 2022 11:11:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38658) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOKby-0007sE-OD; Wed, 17 Aug 2022 11:05:39 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:33316) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOKbw-00026E-FF; Wed, 17 Aug 2022 11:05:38 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27HEjwQ6030098; Wed, 17 Aug 2022 15:05:15 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3j12crru3u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 17 Aug 2022 15:05:15 +0000 Received: from m0098410.ppops.net (m0098410.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 27HEmxwg008470; Wed, 17 Aug 2022 15:05:15 GMT Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3j12crru0h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 17 Aug 2022 15:05:15 +0000 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 27HF58En018738; Wed, 17 Aug 2022 15:05:12 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma05fra.de.ibm.com with ESMTP id 3hyp8shy39-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 17 Aug 2022 15:05:12 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 27HF58On32506314 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Aug 2022 15:05:08 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D460811C04C; Wed, 17 Aug 2022 15:05:08 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1B29A11C04A; Wed, 17 Aug 2022 15:05:08 +0000 (GMT) Received: from heavy.ibmuc.com (unknown [9.171.21.185]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 17 Aug 2022 15:05:08 +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=vqZRHJ9RxWAUXvKEyj3EOy8OvEHfmt8c6QT0ya1G7qY=; b=DOoAYWNKDmNPS4PlMJkKT9s9c0REATlCwY623dFFkpW15dZ2VUVluDvlVgnEAdc3aaXN 2azOzG5a6CTxhk0eHsmlFGokI/op/ACRfBjTCIYd1pAFjs3loQJECihKjIXFSIyxgUQ7 qUy1RTr589mpJMW2JiGwvbhXzyKZJf0RL5ronL0yCirp8WQL2trBkbs+oOnFRJ3xh3/2 4SZvDabCRYuUQO7Z1WKEgqGpzwPwd+fGfXx+KM9gcp5TGQvz9kbkRZlKtIQA56EwYyKu J/s/dKQp2rrCJUaX13ch2tn2wOmVsRyaSxrkiXMeI+IJ6LYo+iMrfrTnY8RzTmCPgbDL Ag== 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 v5 1/4] linux-user: Clear tb_jmp_cache on mprotect() Date: Wed, 17 Aug 2022 17:05:03 +0200 Message-Id: <20220817150506.592862-2-iii@linux.ibm.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220817150506.592862-1-iii@linux.ibm.com> References: <20220817150506.592862-1-iii@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: iokxU9S0kiZc9FmY2N1ikAg0jRNYOYTi X-Proofpoint-ORIG-GUID: jCCC6zqe1IVqIX21kdRMkriSs9OxFpTi 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-17_09,2022-08-16_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 adultscore=0 suspectscore=0 lowpriorityscore=0 mlxlogscore=999 phishscore=0 malwarescore=0 impostorscore=0 mlxscore=0 spamscore=0 clxscore=1015 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208170058 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: 1660749085207100001 Content-Type: text/plain; charset="utf-8" Currently it's possible to execute pages that do not have PAGE_EXEC if there is an existing translation block. Fix by clearing tb_jmp_cache, which forces HELPER(lookup_tb_ptr)() to recheck permission bits the next time. Signed-off-by: Ilya Leoshkevich --- linux-user/mmap.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index bbc674311b..bd96c876ba 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -115,6 +115,7 @@ int target_mprotect(abi_ulong start, abi_ulong len, int= target_prot) { abi_ulong end, host_start, host_end, addr; int prot1, ret, page_flags, host_prot; + CPUState *cpu; =20 trace_target_mprotect(start, len, target_prot); =20 @@ -178,6 +179,19 @@ int target_mprotect(abi_ulong start, abi_ulong len, in= t target_prot) } } page_set_flags(start, start + len, page_flags); + + /* + * Unlike target_mmap(), target_munmap() and target_mremap(), we don't= need + * to call tb_invalidate_phys_range() here, since pages still hold the= same + * data. However, tb_jmp_cache needs to be cleared, otherwise after + * clearing PAGE_EXEC it would still be possible to jump to the existi= ng + * translation blocks. We just clear the whole cache here: mprotect()= is + * rare enough, so a more fine-grained approach is not necessary. + */ + CPU_FOREACH(cpu) { + cpu_tb_jmp_cache_clear(cpu); + } + mmap_unlock(); return 0; error: --=20 2.37.1 From nobody Fri May 3 00:35:12 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=1660748842; cv=none; d=zohomail.com; s=zohoarc; b=DP7mhQB3HSxbIzrlRVVeikxd/mtra4qg6Tq2obxux8L5Tsv/B7diG2A/UmvBdeFKGMmudob3AjIIAvJCRPyw+OW2FoXqdwZcNHhEz0EvEuiAZMj3T+mbYk9Y8tFbUgWNppcrUTpYLbdcwJkjKujK10lvNFJGuPGCLrG+CkiV3WM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660748842; 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=g81FIgYXaHl+iGThNW6R22wyo4rEyRKxqyq4te34rT4=; b=eY700WB8eI7u+lN5a2Zji+suxVGlodjV1DrrL4OLi2FEsLTURWf7TcDupl9uQXFGBX0XiqPBNYI6JI8Fx7PRA5EgQoTjyHfG8rUTErdZ9aBqSeSJV2gFAJw4WJM8QO7+GRZFzvK/iG7o2xzyAFxpsCO4fdvmECsk49q5L5VEOVI= 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 1660748842795936.4448155491899; Wed, 17 Aug 2022 08:07:22 -0700 (PDT) Received: from localhost ([::1]:52374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oOKdd-00023B-Q0 for importer@patchew.org; Wed, 17 Aug 2022 11:07:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38600) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOKbs-0007ph-SK; Wed, 17 Aug 2022 11:05:33 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:11184 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 1oOKbq-00023X-UL; Wed, 17 Aug 2022 11:05:32 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27HEpeHO014290; Wed, 17 Aug 2022 15:05:22 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3j12f58mat-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 17 Aug 2022 15:05:21 +0000 Received: from m0098420.ppops.net (m0098420.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 27HEqUXj021660; Wed, 17 Aug 2022 15:05:17 GMT Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3j12f58m4c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 17 Aug 2022 15:05:16 +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 27HEagqg003025; Wed, 17 Aug 2022 15:05:13 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma04fra.de.ibm.com with ESMTP id 3hx3k8uevw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 17 Aug 2022 15:05:13 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 27HF590P29360522 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Aug 2022 15:05:09 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 946A811C054; Wed, 17 Aug 2022 15:05:09 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EA44D11C04A; Wed, 17 Aug 2022 15:05:08 +0000 (GMT) Received: from heavy.ibmuc.com (unknown [9.171.21.185]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 17 Aug 2022 15:05:08 +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=g81FIgYXaHl+iGThNW6R22wyo4rEyRKxqyq4te34rT4=; b=QMWbNaturo+ZIFHT/1s+/L8aOiTdAbPbfrJUaI88tp8kgR3m2ePL6pDUsnRu4q0cN57V F1xOxp8NH8q3nOeYbcc76rdxTQ0YNUyRN0AkSaemls7acx36jmoWb6EFL3VoT8IeWfcL q4g71t7EHYGoodtQJ83fEsDFVd4B1uJ8Xz8FwG6TVpeINiG9KDBIvxASTUuZabj0fp7S HvpryOkQB3qOJRmVGWXQLGOfe60vVw0VydTBWzWNZJXpcaYqfRV44b6bm2mAbOg+lAuP 4O5ir2vJ90ShYtO2J133oIiNjPVE2nyzBB90YaCippYKH2N0DeoYgd5dD0/MLPfWgsbn dA== 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 v5 2/4] target/s390x: Make translator stop before the end of a page Date: Wed, 17 Aug 2022 17:05:04 +0200 Message-Id: <20220817150506.592862-3-iii@linux.ibm.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220817150506.592862-1-iii@linux.ibm.com> References: <20220817150506.592862-1-iii@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: M_rx0tnWC3E2VfEoUjJ-Ya8g7Dij4nUI X-Proofpoint-GUID: Orp9f9SUAgXBAtDPCITSZZidZhjDJUl4 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-17_09,2022-08-16_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 malwarescore=0 phishscore=0 clxscore=1015 priorityscore=1501 mlxlogscore=957 suspectscore=0 bulkscore=0 impostorscore=0 spamscore=0 lowpriorityscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208170058 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: -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: 1660748844568100001 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. Signed-off-by: Ilya Leoshkevich Reviewed-by: Richard Henderson --- target/s390x/tcg/translate.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/target/s390x/tcg/translate.c b/target/s390x/tcg/translate.c index d4c0b9b3a2..1d2dddab1c 100644 --- a/target/s390x/tcg/translate.c +++ b/target/s390x/tcg/translate.c @@ -6609,6 +6609,14 @@ static void s390x_tr_insn_start(DisasContextBase *dc= base, CPUState *cs) dc->insn_start =3D tcg_last_op(); } =20 +static target_ulong get_next_pc(CPUS390XState *env, DisasContext *s, + uint64_t pc) +{ + uint64_t insn =3D ld_code2(env, s, pc); + + return pc + get_ilen((insn >> 8) & 0xff); +} + static void s390x_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) { CPUS390XState *env =3D cs->env_ptr; @@ -6616,10 +6624,9 @@ static void s390x_tr_translate_insn(DisasContextBase= *dcbase, CPUState *cs) =20 dc->base.is_jmp =3D translate_one(env, dc); if (dc->base.is_jmp =3D=3D DISAS_NEXT) { - uint64_t page_start; - - page_start =3D dc->base.pc_first & TARGET_PAGE_MASK; - if (dc->base.pc_next - page_start >=3D TARGET_PAGE_SIZE || dc->ex_= value) { + if (!is_same_page(dcbase, dc->base.pc_next) || + !is_same_page(dcbase, get_next_pc(env, dc, dc->base.pc_next)) = || + dc->ex_value) { dc->base.is_jmp =3D DISAS_TOO_MANY; } } --=20 2.37.1 From nobody Fri May 3 00:35:12 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=1660749001; cv=none; d=zohomail.com; s=zohoarc; b=bMuHfmG8CuQmX++ZveZo0I5K3h/1kxqDj8oZUNoU3SBP/FWTodSwkNyOJ5fu6Y9M2WallbEh35n344XwfHKpLnXf4w53Y3rJL5YvIiKhz8tlWoWitZ5i2Kb4xKXASF0sOQg8sNIPOTBAJ1dDQxM7J0hdPmZM7xhrEIAAkmftRNg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660749001; 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=iR2QQVz/cAXSEAzYUyrrf40V7ErrfZIcNv9k84RlSWc=; b=Hd1USptjWWKKePA14WZ9btrxjp7kaCyWbfRY2/h6hqFoAH5/RWGuNt9PuMsflXPlrXvsVstS29CSnuXejaWJQkBRZDgpcgrxYHTiBW9CFYibJ4rUMGfM5/9f7Ts9Y8WGGovKhCegOS6eqjm0am1A0t1v2Ir9mLf7WjLWSFmE+v0= 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 1660749001147288.2966275037304; Wed, 17 Aug 2022 08:10:01 -0700 (PDT) Received: from localhost ([::1]:50138 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oOKgC-0007e0-51 for importer@patchew.org; Wed, 17 Aug 2022 11:10:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38632) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOKbw-0007rB-3z; Wed, 17 Aug 2022 11:05:36 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:51184 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 1oOKbu-00025k-CN; Wed, 17 Aug 2022 11:05:35 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27HEpeHD014290; Wed, 17 Aug 2022 15:05:20 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3j12f58maw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 17 Aug 2022 15:05:18 +0000 Received: from m0098420.ppops.net (m0098420.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 27HEq7cc017137; Wed, 17 Aug 2022 15:05:17 GMT Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3j12f58m45-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 17 Aug 2022 15:05:17 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 27HF5DgV003667; Wed, 17 Aug 2022 15:05:13 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma06fra.de.ibm.com with ESMTP id 3hx37j3ghe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 17 Aug 2022 15:05:13 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 27HF5TON32375228 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Aug 2022 15:05:29 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5011511C050; Wed, 17 Aug 2022 15:05:10 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AB24611C04A; Wed, 17 Aug 2022 15:05:09 +0000 (GMT) Received: from heavy.ibmuc.com (unknown [9.171.21.185]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 17 Aug 2022 15:05:09 +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 : content-transfer-encoding : mime-version; s=pp1; bh=iR2QQVz/cAXSEAzYUyrrf40V7ErrfZIcNv9k84RlSWc=; b=W5d8X/No8CUsMHxxs5lzeCGBK5mUAiE/ExRhlzmuSQy1u/T+nHbEqWzT1dkxLH5COonw DoefLrI+/vXEwOZE7s+2cN4uGLdDHa4awmwXxs/9Fzsvjka8KGAzhGIgJbVpk+Hm73Yi 33C85EXFp3/WdR5H7axFmxnV/JZe/07DwsQ2eJ9lwJmPQGOyDj5bi/k5nDdonYKGDiy4 aAn7QwGGmxCz0SsRJGfUzpY/wD5EB20ywrILKRcOZhBUxB87Q8+gJf3rBu5nrjM9QjAq iqloOX39s73zb2gmS8k+LBLLiB8gMBZZ6n4QRAvhd+0KG6GbeeImJygO4sNiEwnvrWLj mg== 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 v5 3/4] target/i386: Make translator stop before the end of a page Date: Wed, 17 Aug 2022 17:05:05 +0200 Message-Id: <20220817150506.592862-4-iii@linux.ibm.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220817150506.592862-1-iii@linux.ibm.com> References: <20220817150506.592862-1-iii@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 05nkpxxHxNgZSiiIfl4Wfju062vWpQ2R X-Proofpoint-GUID: JbNyG6dfkEu0vmt7nSXBMP1KDzmURVzt Content-Transfer-Encoding: quoted-printable X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 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-17_09,2022-08-16_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 malwarescore=0 phishscore=0 clxscore=1015 priorityscore=1501 mlxlogscore=999 suspectscore=0 bulkscore=0 impostorscore=0 spamscore=0 lowpriorityscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208170058 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: -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: 1660749003580100003 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. Signed-off-by: Ilya Leoshkevich Reviewed-by: Richard Henderson Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1143 --- target/i386/tcg/translate.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 4836c889e0..6481ae5c24 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -130,6 +130,7 @@ typedef struct DisasContext { TCGv_i64 tmp1_i64; =20 sigjmp_buf jmpbuf; + TCGOp *prev_insn_end; } DisasContext; =20 /* The environment in which user-only runs is constrained. */ @@ -2008,6 +2009,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 +4563,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 +4577,22 @@ 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.num_insns--; + tcg_remove_ops_after(s->prev_insn_end); + s->base.is_jmp =3D DISAS_TOO_MANY; + return pc_start; + default: + g_assert_not_reached(); } =20 prefixes =3D 0; @@ -8632,6 +8654,7 @@ static void i386_tr_insn_start(DisasContextBase *dcba= se, CPUState *cpu) { DisasContext *dc =3D container_of(dcbase, DisasContext, base); =20 + dc->prev_insn_end =3D tcg_last_op(); tcg_gen_insn_start(dc->base.pc_next, dc->cc_op); } =20 --=20 2.37.1 From nobody Fri May 3 00:35:12 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=1660748941; cv=none; d=zohomail.com; s=zohoarc; b=N+rhsptDGtOyRSXgXDtvUjQwkuyaYQhtdKvn+81fqbeolp4a57KLSNl2RWPBp38hH4Q02wkmbIg+uMfgxTJSBPsVOfQOhclpo58v2KU+7iuqeIgbAbREAJpDQS/vmMe082N9eliilTFhBv/CXdnOJSCYtruPHlzXl43N69hNyac= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660748941; 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=rtgOdwlKL84LDuedjqddt8Q60nUJ68iFlIH3jXbWdN4=; b=P38lCOHGpwEgFEEZTiUq+YsEP5JBpeLtXtCkejf5Lkt5jVeaQhpP3qXUnqCvw9AQuOREHiqiWojfE8pmngPBZ+MrB7E2r7W2hYIfNTz/rM9xyLea6syr0FWxC7Zh4KpDZDA8QE9Rtqd3rMzlqc4RYhr0B9/cF7Jd6Xm7MQYKlFk= 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 1660748941094913.6475747701097; Wed, 17 Aug 2022 08:09:01 -0700 (PDT) Received: from localhost ([::1]:34644 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oOKfC-00041f-Op for importer@patchew.org; Wed, 17 Aug 2022 11:08:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38646) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOKbx-0007rf-Gy; Wed, 17 Aug 2022 11:05:38 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:65488) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOKbu-00025t-Iv; Wed, 17 Aug 2022 11:05:36 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27HEqI3H007946; Wed, 17 Aug 2022 15:05:19 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3j12fr0ja1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 17 Aug 2022 15:05:18 +0000 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 27HEqxqn012578; Wed, 17 Aug 2022 15:05:18 GMT Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3j12fr0j48-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 17 Aug 2022 15:05:18 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 27HF58TJ003646; Wed, 17 Aug 2022 15:05:14 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma06fra.de.ibm.com with ESMTP id 3hx37j3ghf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 17 Aug 2022 15:05:14 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 27HF2PeY32506230 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Aug 2022 15:02:25 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1640511C052; Wed, 17 Aug 2022 15:05:11 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6901011C04A; Wed, 17 Aug 2022 15:05:10 +0000 (GMT) Received: from heavy.ibmuc.com (unknown [9.171.21.185]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 17 Aug 2022 15:05:10 +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=rtgOdwlKL84LDuedjqddt8Q60nUJ68iFlIH3jXbWdN4=; b=Sti8+ozV+tKtKRkIWucbclcdsvEZXstKlItvf4I7Jldtk53JO0IM6J4POt6gd9yPZz83 qVQ38NRqvvCaxjrY/1WIW37sGs3JpaEsFvX66hpZNgexY8/zl6KiKSKLVjSBXHx1WS8I 9p/dhM9Zl9y2cZAn19XfU31JshxE+jWVIAoYuZWzC5pIpzuS9dnnRCYr0ZFfS4Z7p/Dx KO6tJwEbkZVofcETF+smIRtp/IlLdL3YRrRIzWwjr0PU9GE1KihaPwgQtrPuLrdp8Rri q4wIhVBfvaU5bx60+VpOEpi3OM+4lxwR8mO3i3t+X/dM3/RaSUkF06HzNOuR3FWrjxlv /g== 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 v5 4/4] tests/tcg: Test siginfo_t contents when jumping to non-readable pages Date: Wed, 17 Aug 2022 17:05:06 +0200 Message-Id: <20220817150506.592862-5-iii@linux.ibm.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220817150506.592862-1-iii@linux.ibm.com> References: <20220817150506.592862-1-iii@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Uv9QjMz0alZG_KpkJJdgMoHKeOFYL6XS X-Proofpoint-ORIG-GUID: -TWtGWzXpMc9HxeFgSY2mR1N7pWGL-1e 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-17_09,2022-08-16_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 priorityscore=1501 suspectscore=0 lowpriorityscore=0 spamscore=0 mlxscore=0 clxscore=1015 impostorscore=0 phishscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208170058 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=mx0b-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: 1660748942960100001 Content-Type: text/plain; charset="utf-8" Add x86_64 and s390x tests to prevent regressions. Signed-off-by: Ilya Leoshkevich --- tests/tcg/multiarch/noexec.h | 114 ++++++++++++++++++++++++ tests/tcg/s390x/Makefile.target | 1 + tests/tcg/s390x/noexec.c | 145 +++++++++++++++++++++++++++++++ tests/tcg/x86_64/Makefile.target | 3 +- tests/tcg/x86_64/noexec.c | 116 +++++++++++++++++++++++++ 5 files changed, 378 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/multiarch/noexec.h create mode 100644 tests/tcg/s390x/noexec.c create mode 100644 tests/tcg/x86_64/noexec.c diff --git a/tests/tcg/multiarch/noexec.h b/tests/tcg/multiarch/noexec.h new file mode 100644 index 0000000000..a76e0aa9ea --- /dev/null +++ b/tests/tcg/multiarch/noexec.h @@ -0,0 +1,114 @@ +/* + * Common code for arch-specific MMU_INST_FETCH fault testing. + * + * Declare struct arch_noexec_test before including this file and define + * arch_check_mcontext() after that. + */ + +#include +#include +#include +#include +#include +#include +#include + +/* Forward declarations. */ + +static void arch_check_mcontext(const struct arch_noexec_test *test, + const mcontext_t *ctx); + +/* Utility functions. */ + +static void safe_print(const char *s) +{ + write(0, s, strlen(s)); +} + +static void safe_puts(const char *s) +{ + safe_print(s); + safe_print("\n"); +} + +#define PAGE_ALIGN(p) (void *)((unsigned long)(p) & ~0xfffUL) + +/* Testing infrastructure. */ + +struct noexec_test { + const char *name; + void (*func)(int); + void *page; + void *expected_si_addr; + struct arch_noexec_test arch; +}; + +static const struct noexec_test *current_noexec_test; + +static void handle_segv(int sig, siginfo_t *info, void *ucontext) +{ + int err; + + if (current_noexec_test =3D=3D NULL) { + safe_puts("[ FAILED ] unexpected SEGV"); + _exit(1); + } + + if (info->si_addr !=3D current_noexec_test->expected_si_addr) { + safe_puts("[ FAILED ] wrong si_addr"); + _exit(1); + } + + arch_check_mcontext(¤t_noexec_test->arch, + &((ucontext_t *)ucontext)->uc_mcontext); + + err =3D mprotect(current_noexec_test->page, 0x1000, PROT_READ | PROT_E= XEC); + if (err !=3D 0) { + safe_puts("[ FAILED ] mprotect() failed"); + _exit(1); + } + + current_noexec_test =3D NULL; +} + +static void test_noexec_1(const struct noexec_test *test) +{ + int ret; + + /* Trigger TB creation in order to test invalidation. */ + test->func(0); + + ret =3D mprotect(test->page, 0x1000, PROT_NONE); + assert(ret =3D=3D 0); + + /* Trigger SEGV and check that handle_segv() ran. */ + current_noexec_test =3D test; + test->func(0); + assert(current_noexec_test =3D=3D NULL); +} + +static int test_noexec(struct noexec_test *tests, size_t n_tests) +{ + struct sigaction act; + size_t i; + int err; + + memset(&act, 0, sizeof(act)); + act.sa_sigaction =3D handle_segv; + act.sa_flags =3D SA_SIGINFO; + err =3D sigaction(SIGSEGV, &act, NULL); + assert(err =3D=3D 0); + + for (i =3D 0; i < n_tests; i++) { + struct noexec_test *test =3D &tests[i]; + + safe_print("[ RUN ] "); + safe_puts(test->name); + test_noexec_1(test); + safe_puts("[ OK ]"); + } + + safe_puts("[ PASSED ]"); + + return EXIT_SUCCESS; +} diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.tar= get index 1a7a4a2f59..5e13a41c3f 100644 --- a/tests/tcg/s390x/Makefile.target +++ b/tests/tcg/s390x/Makefile.target @@ -16,6 +16,7 @@ TESTS+=3Dshift TESTS+=3Dtrap TESTS+=3Dsignals-s390x TESTS+=3Dbranch-relative-long +TESTS+=3Dnoexec =20 Z14_TESTS=3Dvfminmax vfminmax: LDFLAGS+=3D-lm diff --git a/tests/tcg/s390x/noexec.c b/tests/tcg/s390x/noexec.c new file mode 100644 index 0000000000..2dfc9ee817 --- /dev/null +++ b/tests/tcg/s390x/noexec.c @@ -0,0 +1,145 @@ +#define _GNU_SOURCE + +struct arch_noexec_test { + void *expected_pswa; + unsigned long expected_r2; +}; + +#include "../multiarch/noexec.h" + +static void arch_check_mcontext(const struct arch_noexec_test *test, + const mcontext_t *ctx) { + if (ctx->psw.addr !=3D (unsigned long)test->expected_pswa) { + safe_puts("[ FAILED ] wrong psw.addr"); + _exit(1); + } + + if (ctx->gregs[2] !=3D test->expected_r2) { + safe_puts("[ FAILED ] wrong r2"); + _exit(1); + } +} + +#define DEFINE_NX(name, offset) \ + void name ## _1(int); \ + void name ## _2(int); \ + void name ## _exrl(int); \ + extern const short name ## _end[]; \ + asm(/* Go to the specified page offset. */ \ + ".align 0x1000\n" \ + ".org .+" #offset "\n" \ + /* %r2 is 0 on entry, overwrite it with 1. */ \ + ".globl " #name "_1\n" \ + #name "_1:\n" \ + ".cfi_startproc\n" \ + "lgfi %r2,1\n" \ + /* Overwrite %2 with 2. */ \ + ".globl " #name "_2\n" \ + #name "_2:\n" \ + "lgfi %r2,2\n" \ + "br %r14\n" \ + /* End of code. */ \ + ".globl " #name "_end\n" \ + #name "_end:\n" \ + ".cfi_endproc\n" \ + /* Go to the next page. */ \ + ".align 0x1000\n" \ + /* Break alignment. */ \ + "nopr %r7\n" \ + ".globl " #name "_exrl\n" \ + #name "_exrl:\n" \ + ".cfi_startproc\n" \ + "exrl %r0," #name "_2\n" \ + "br %r14\n" \ + ".cfi_endproc"); + +/* noexec_1 is executable, noexec_2 is non-executable. */ +DEFINE_NX(noexec, 0xffa); + +/* + * noexec_cross_1 is executable, noexec_cross_2 crosses non-executable page + * boundary. + */ +DEFINE_NX(noexec_cross, 0xff8); + +/* noexec_full_1 and noexec_full_2 are non-executable. */ +DEFINE_NX(noexec_full, 0x322); + +int main(void) +{ + struct noexec_test noexec_tests[] =3D { + { + .name =3D "Fallthrough", + .func =3D noexec_1, + .page =3D noexec_2, + .expected_si_addr =3D noexec_2, + .arch =3D { + .expected_pswa =3D noexec_2, + .expected_r2 =3D 1, + }, + }, + { + .name =3D "Jump", + .func =3D noexec_2, + .page =3D noexec_2, + .expected_si_addr =3D noexec_2, + .arch =3D { + .expected_pswa =3D noexec_2, + .expected_r2 =3D 0, + }, + }, + { + .name =3D "EXRL", + .func =3D noexec_exrl, + .page =3D noexec_2, + .expected_si_addr =3D PAGE_ALIGN(noexec_end), + .arch =3D { + .expected_pswa =3D noexec_exrl, + .expected_r2 =3D 0, + }, + }, + { + .name =3D "Fallthrough [cross]", + .func =3D noexec_cross_1, + .page =3D PAGE_ALIGN(noexec_cross_end), + .expected_si_addr =3D PAGE_ALIGN(noexec_cross_end), + .arch =3D { + .expected_pswa =3D noexec_cross_2, + .expected_r2 =3D 1, + }, + }, + { + .name =3D "Jump [cross]", + .func =3D noexec_cross_2, + .page =3D PAGE_ALIGN(noexec_cross_end), + .expected_si_addr =3D PAGE_ALIGN(noexec_cross_end), + .arch =3D { + .expected_pswa =3D noexec_cross_2, + .expected_r2 =3D 0, + }, + }, + { + .name =3D "EXRL [cross]", + .func =3D noexec_cross_exrl, + .page =3D PAGE_ALIGN(noexec_cross_end), + .expected_si_addr =3D PAGE_ALIGN(noexec_cross_end), + .arch =3D { + .expected_pswa =3D noexec_cross_exrl, + .expected_r2 =3D 0, + }, + }, + { + .name =3D "Jump [full]", + .func =3D noexec_full_1, + .page =3D PAGE_ALIGN(noexec_full_1), + .expected_si_addr =3D PAGE_ALIGN(noexec_full_1), + .arch =3D { + .expected_pswa =3D noexec_full_1, + .expected_r2 =3D 0, + }, + }, + }; + + return test_noexec(noexec_tests, + sizeof(noexec_tests) / sizeof(noexec_tests[0])); +} diff --git a/tests/tcg/x86_64/Makefile.target b/tests/tcg/x86_64/Makefile.t= arget index b71a6bcd5e..c0e7e5b005 100644 --- a/tests/tcg/x86_64/Makefile.target +++ b/tests/tcg/x86_64/Makefile.target @@ -10,6 +10,7 @@ include $(SRC_PATH)/tests/tcg/i386/Makefile.target =20 ifeq ($(filter %-linux-user, $(TARGET)),$(TARGET)) X86_64_TESTS +=3D vsyscall +X86_64_TESTS +=3D noexec TESTS=3D$(MULTIARCH_TESTS) $(X86_64_TESTS) test-x86_64 else TESTS=3D$(MULTIARCH_TESTS) @@ -20,5 +21,5 @@ test-x86_64: LDFLAGS+=3D-lm -lc test-x86_64: test-i386.c test-i386.h test-i386-shift.h test-i386-muldiv.h $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS) =20 -vsyscall: $(SRC_PATH)/tests/tcg/x86_64/vsyscall.c +%: $(SRC_PATH)/tests/tcg/x86_64/%.c $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS) diff --git a/tests/tcg/x86_64/noexec.c b/tests/tcg/x86_64/noexec.c new file mode 100644 index 0000000000..ec07c9f0ba --- /dev/null +++ b/tests/tcg/x86_64/noexec.c @@ -0,0 +1,116 @@ +#define _GNU_SOURCE + +struct arch_noexec_test { + void *expected_rip; + unsigned long expected_rdi; +}; + +#include "../multiarch/noexec.h" + +static void arch_check_mcontext(const struct arch_noexec_test *test, + const mcontext_t *ctx) { + if (ctx->gregs[REG_RIP] !=3D (unsigned long)test->expected_rip) { + safe_puts("[ FAILED ] wrong rip"); + _exit(1); + } + + if (ctx->gregs[REG_RDI] !=3D test->expected_rdi) { + safe_puts("[ FAILED ] wrong rdi"); + _exit(1); + } +} + +#define DEFINE_NX(name, offset) \ + void name ## _1(int); \ + void name ## _2(int); \ + extern const short name ## _end[]; \ + asm(/* Go to the specified page offset. */ \ + ".align 0x1000\n" \ + ".org .+" #offset "\n" \ + /* %rdi is 0 on entry, overwrite it with 1. */ \ + ".globl " #name "_1\n" \ + #name "_1:\n" \ + ".cfi_startproc\n" \ + "movq $1,%rdi\n" \ + /* Overwrite %rdi with 2. */ \ + ".globl " #name "_2\n" \ + #name "_2:\n" \ + "movq $2,%rdi\n" \ + "ret\n" \ + /* End of code. */ \ + ".globl " #name "_end\n" \ + #name "_end:\n" \ + ".cfi_endproc\n" \ + /* Go to the next page. */ \ + ".align 0x1000"); + +/* noexec_1 is executable, noexec_2 is non-executable. */ +DEFINE_NX(noexec, 0xff9); + +/* + * noexec_cross_1 is executable, noexec_cross_2 crosses non-executable page + * boundary. + */ +DEFINE_NX(noexec_cross, 0xff8); + +/* noexec_full_1 and noexec_full_2 are non-executable. */ +DEFINE_NX(noexec_full, 0x321); + +int main(void) +{ + struct noexec_test noexec_tests[] =3D { + { + .name =3D "Fallthrough", + .func =3D noexec_1, + .page =3D noexec_2, + .expected_si_addr =3D noexec_2, + .arch =3D { + .expected_rip =3D noexec_2, + .expected_rdi =3D 1, + }, + }, + { + .name =3D "Jump", + .func =3D noexec_2, + .page =3D noexec_2, + .expected_si_addr =3D noexec_2, + .arch =3D { + .expected_rip =3D noexec_2, + .expected_rdi =3D 0, + }, + }, + { + .name =3D "Fallthrough [cross]", + .func =3D noexec_cross_1, + .page =3D PAGE_ALIGN(noexec_cross_end), + .expected_si_addr =3D PAGE_ALIGN(noexec_cross_end), + .arch =3D { + .expected_rip =3D noexec_cross_2, + .expected_rdi =3D 1, + }, + }, + { + .name =3D "Jump [cross]", + .func =3D noexec_cross_2, + .page =3D PAGE_ALIGN(noexec_cross_end), + .expected_si_addr =3D PAGE_ALIGN(noexec_cross_end), + .arch =3D { + .expected_rip =3D noexec_cross_2, + .expected_rdi =3D 0, + }, + }, + { + .name =3D "Jump [full]", + .func =3D noexec_full_1, + .page =3D PAGE_ALIGN(noexec_full_1), + .expected_si_addr =3D noexec_full_1, + .arch =3D { + .expected_rip =3D noexec_full_1, + .expected_rdi =3D 0, + }, + }, + }; + + return test_noexec(noexec_tests, + sizeof(noexec_tests) / sizeof(noexec_tests[0])); +} --=20 2.37.1