From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 85678C00140 for ; Mon, 8 Aug 2022 17:12:51 +0000 (UTC) Received: from localhost ([::1]:41028 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oL6J8-0005wK-Ib for qemu-devel@archiver.kernel.org; Mon, 08 Aug 2022 13:12:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59634) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oL6H9-0003rX-DK; Mon, 08 Aug 2022 13:10:47 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:17716 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 1oL6H6-00036P-EI; Mon, 08 Aug 2022 13:10:47 -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 278GII15011356; Mon, 8 Aug 2022 17:10:31 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=eGc9K0Ieu+64YFvK3mpVcBSY6DHM2+SIgXWz26O5nYA=; b=hFL5gko93HznRftrJrNxVkdMzfPE19sbMqZw5ErBgQ6cSlNA83DOqt7GXOxclDSAbHMK 5irR45y9TMG58bg+R6NDYCE1XY8fkViyyLGfTzhPLmtjrNR2g/ne+Y7L2KPMSCxU0JYy q+0v+cz9lxne9KhXbxK7bW0DIHwcCYgWXzvio4hsfxjGGZ+TI0AZHLJ5s+lwHIW7qbnn w3NzFG/q3RRNwHZUDyNI4wNIT0Voqtkl9hDR2amYwym6YUaM5rSBdOMKz1U3KCC90Cr8 ZIbA9v4vqfGv7f+OMRknrnnzl1HMCLiI6YAQanYzDyVHIDThdmYfMNEgT9qhnEgjBci7 8A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3hu5w0hj10-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 Aug 2022 17:10:31 +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 278GvBfL017752; Mon, 8 Aug 2022 17:10:30 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3hu5w0hhyy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 Aug 2022 17:10:30 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 278Go3LG024121; Mon, 8 Aug 2022 17:10:28 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma03ams.nl.ibm.com with ESMTP id 3hsfx8tgcq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 Aug 2022 17:10:28 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 278HAP6Q31457720 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 8 Aug 2022 17:10:25 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 193BFA4055; Mon, 8 Aug 2022 17:10:25 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7C2B2A4040; Mon, 8 Aug 2022 17:10:24 +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:24 +0000 (GMT) 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 1/4] accel/tcg: Invalidate translations when clearing PAGE_EXEC Date: Mon, 8 Aug 2022 19:10:19 +0200 Message-Id: <20220808171022.49439-2-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: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: N90wiIKYpBGAgn8AyvlJ80RKtWfkopLA X-Proofpoint-ORIG-GUID: 08u9zBpUMjX1mSSffBCFoAFP1uJUaPMP 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_10,2022-08-08_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 phishscore=0 spamscore=0 lowpriorityscore=0 mlxlogscore=999 priorityscore=1501 adultscore=0 mlxscore=0 suspectscore=0 malwarescore=0 impostorscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2208080079 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" After mprotect(addr, PROT_NONE), addr can still be executed if there are cached translations. Drop them. Signed-off-by: Ilya Leoshkevich --- accel/tcg/translate-all.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index ef62a199c7..32ea5f0adf 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -2295,12 +2295,19 @@ void page_set_flags(target_ulong start, target_ulong end, int flags) len != 0; len -= TARGET_PAGE_SIZE, addr += TARGET_PAGE_SIZE) { PageDesc *p = page_find_alloc(addr >> TARGET_PAGE_BITS, 1); + bool write_set, exec_cleared; - /* If the write protection bit is set, then we invalidate - the code inside. */ - if (!(p->flags & PAGE_WRITE) && - (flags & PAGE_WRITE) && - p->first_tb) { + /* + * If the write protection bit is set, then we invalidate the code + * inside. + */ + write_set = !(p->flags & PAGE_WRITE) && (flags & PAGE_WRITE); + /* + * If PAGE_EXEC is cleared, we also need to invalidate the code in + * order to force a fault when trying to run it. + */ + exec_cleared = (p->flags & PAGE_EXEC) && !(flags & PAGE_EXEC); + if ((write_set || exec_cleared) && p->first_tb) { tb_invalidate_phys_page(addr, 0); } if (reset_target_data) { -- 2.37.1