From nobody Sun Apr 28 11:37:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1556024854; cv=none; d=zoho.com; s=zohoarc; b=YD0ea/GbyGm39J6G+a88uXlIbhwzVlm/PLvDI8FbLJqG2eZqKt+Ze/Zl2wIUy5glCWVMteZ7rTWDody96ALPEV06eCP7uH8Lbnm2SY2JTFPEXewgU50Jz4DbRj4bEvlrTHLs8qZ4Kilr96Hd+emRQQ2H4m7V6zm+N6in2NS4LL0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556024854; h=Content-Type: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:ARC-Authentication-Results; bh=v1q4uzbPRZUs/BbKXKu7UtRSCYONf41Ahikc23O1IqM=; b=NCAGRbUgowRcccSOO7AVMWLcnppjjhywElMA3fArmoFGiJE2X2CGVCihIqNkjk4WocqqMgmGzNwm84kg33/oM1DpbE8oNt5/48vhXRBbo3ZInyDfOyrT4Ou20wNYs6C9tixBCl/RVnFXXACKlfNBzAC3tG1HR+5WKvW4lxHYmSE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556024854164990.0483435469174; Tue, 23 Apr 2019 06:07:34 -0700 (PDT) Received: from localhost ([127.0.0.1]:53625 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hIv8x-00020i-Rg for importer@patchew.org; Tue, 23 Apr 2019 09:07:27 -0400 Received: from eggs.gnu.org ([209.51.188.92]:38696) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hIsJm-0004bx-Jo for qemu-devel@nongnu.org; Tue, 23 Apr 2019 06:06:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hIsFj-0000S2-LI for qemu-devel@nongnu.org; Tue, 23 Apr 2019 06:02:16 -0400 Received: from [93.153.64.87] (port=40118 helo=gorgo) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hIsFj-0000JY-2V for qemu-devel@nongnu.org; Tue, 23 Apr 2019 06:02:15 -0400 Received: from gorgo (localhost.localdomain [127.0.0.1]) by gorgo (8.15.2/8.15.2) with ESMTPS id x3N9Re501254771 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 23 Apr 2019 11:27:40 +0200 Received: (from jermar@localhost) by gorgo (8.15.2/8.15.2/Submit) id x3N9ReLw1254733; Tue, 23 Apr 2019 11:27:40 +0200 From: =?UTF-8?q?Jakub=20Jerm=C3=A1=C5=99?= To: qemu-devel@nongnu.org Date: Tue, 23 Apr 2019 11:26:02 +0200 Message-Id: <20190423092602.1254515-1-jakub.jermar@kernkonzept.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by gorgo id x3N9Re501254771 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 93.153.64.87 X-Mailman-Approved-At: Tue, 23 Apr 2019 09:04:25 -0400 Subject: [Qemu-devel] [PATCH] mips: Decide to map PAGE_EXEC in map_address X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Jakub=20Jerm=C3=A1=C5=99?= , Aleksandar Rikalo , Aleksandar Markovic , Aurelien Jarno Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This commit addresses QEMU Bug #1825311: mips_cpu_handle_mmu_fault renders all accessed pages executable It allows finer-grained control over whether the accessed page should be executable by moving the decision to the underlying map_address function, which has more information for this. As a result, pages that have the XI bit set in the TLB and are accessed for read/write, don't suddenly end up being executable. Signed-off-by: Jakub Jerm=C3=A1=C5=99 --- target/mips/helper.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/target/mips/helper.c b/target/mips/helper.c index c44cdca3b5..f182935fcf 100644 --- a/target/mips/helper.c +++ b/target/mips/helper.c @@ -43,7 +43,7 @@ int no_mmu_map_address (CPUMIPSState *env, hwaddr *physic= al, int *prot, target_ulong address, int rw, int access_type) { *physical =3D address; - *prot =3D PAGE_READ | PAGE_WRITE; + *prot =3D PAGE_READ | PAGE_WRITE | PAGE_EXEC; return TLBRET_MATCH; } =20 @@ -61,7 +61,7 @@ int fixed_mmu_map_address (CPUMIPSState *env, hwaddr *phy= sical, int *prot, else *physical =3D address; =20 - *prot =3D PAGE_READ | PAGE_WRITE; + *prot =3D PAGE_READ | PAGE_WRITE | PAGE_EXEC; return TLBRET_MATCH; } =20 @@ -101,6 +101,8 @@ int r4k_map_address (CPUMIPSState *env, hwaddr *physica= l, int *prot, *prot =3D PAGE_READ; if (n ? tlb->D1 : tlb->D0) *prot |=3D PAGE_WRITE; + if (!(n ? tlb->XI1 : tlb->XI0)) + *prot |=3D PAGE_EXEC; return TLBRET_MATCH; } return TLBRET_DIRTY; @@ -182,7 +184,7 @@ static int get_seg_physical_address(CPUMIPSState *env, = hwaddr *physical, } else { /* The segment is unmapped */ *physical =3D physical_base | (real_address & segmask); - *prot =3D PAGE_READ | PAGE_WRITE; + *prot =3D PAGE_READ | PAGE_WRITE | PAGE_EXEC; return TLBRET_MATCH; } } @@ -913,8 +915,8 @@ int mips_cpu_handle_mmu_fault(CPUState *cs, vaddr addre= ss, int size, int rw, } if (ret =3D=3D TLBRET_MATCH) { tlb_set_page(cs, address & TARGET_PAGE_MASK, - physical & TARGET_PAGE_MASK, prot | PAGE_EXEC, - mmu_idx, TARGET_PAGE_SIZE); + physical & TARGET_PAGE_MASK, prot, mmu_idx, + TARGET_PAGE_SIZE); ret =3D 0; } else if (ret < 0) #endif @@ -936,8 +938,8 @@ int mips_cpu_handle_mmu_fault(CPUState *cs, vaddr addre= ss, int size, int rw, address, rw, access_type, mmu_i= dx); if (ret =3D=3D TLBRET_MATCH) { tlb_set_page(cs, address & TARGET_PAGE_MASK, - physical & TARGET_PAGE_MASK, prot | PAGE_EXEC, - mmu_idx, TARGET_PAGE_SIZE); + physical & TARGET_PAGE_MASK, prot, mmu_idx, + TARGET_PAGE_SIZE); ret =3D 0; return ret; } --=20 2.20.1