From nobody Sun May 5 17:13:35 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oth-regensburg.de Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650751231384487.27265670920906; Sat, 23 Apr 2022 15:00:31 -0700 (PDT) Received: from localhost ([::1]:55852 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1niNnq-0004Iv-Cd for importer2@patchew.org; Sat, 23 Apr 2022 18:00:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33210) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1niNmv-0003Uo-Ub; Sat, 23 Apr 2022 17:59:34 -0400 Received: from mta02.hs-regensburg.de ([194.95.104.12]:57166) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1niNmt-0005Bi-7B; Sat, 23 Apr 2022 17:59:33 -0400 Received: from E16S03.hs-regensburg.de (e16s03.hs-regensburg.de [IPv6:2001:638:a01:8013::93]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "E16S03", Issuer "E16S03" (not verified)) by mta02.hs-regensburg.de (Postfix) with ESMTPS id 4Km4tY6CVMzxyt; Sat, 23 Apr 2022 23:59:17 +0200 (CEST) Received: from atlantis.binary.kitchen (194.95.106.138) by E16S03.hs-regensburg.de (2001:638:a01:8013::93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 23 Apr 2022 23:59:17 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oth-regensburg.de; s=mta02-20211122; t=1650751157; bh=fwL+0LSi3R14yw+D5NEr6SNX6TFNKy8AHZpYgNWJCu0=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=dACR+22jM6IV74GReKBxqi9YtcqLlSSFCfYmXih+l/oQeSM3GzA375/gjYTvxzNrm VH/oorbBru28d1hXjplTRu1NWLJHUoiLWh5eJ03euRfGAAmLH9d1pkMym19UjBI66q 3hWkZMnDhnvbjbYJjJmtvc38y/ORyBLdOvL+gnvNl5TVUEHzHDlRT0wDtoU05n8VbS VE33htekVO3SimMd+awPvVsevwk/6DzSCW39RwAPdMJSRATAuvpsYQFs0bhMd2fKdn +sZwW1s0oxqA6ZAg6T7vJx9r4f7CMV2JNeAhZovPxd56bXLH/kodlCSmVVT5WMeXM2 l5x8ZcLP+dQMw== From: Ralf Ramsauer To: Bin Meng , Alistair Francis , , , Stefan Huber Subject: [PATCH v3] target/riscv: Fix incorrect PTE merge in walk_pte Date: Sat, 23 Apr 2022 23:59:07 +0200 Message-ID: <20220423215907.673663-1-ralf.ramsauer@oth-regensburg.de> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [194.95.106.138] X-ClientProxiedBy: E16S01.hs-regensburg.de (2001:638:a01:8013::91) To E16S03.hs-regensburg.de (2001:638:a01:8013::93) 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=194.95.104.12; envelope-from=ralf.ramsauer@oth-regensburg.de; helo=mta02.hs-regensburg.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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: , Cc: Konrad Schwarz , Richard Henderson , Ralf Ramsauer Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650751233466100001 Content-Type: text/plain; charset="utf-8" Two non-subsequent PTEs can be mapped to subsequent paddrs. In this case, walk_pte will erroneously merge them. Enforce the split up, by tracking the virtual base address. Let's say we have the mapping: 0x81200000 -> 0x89623000 (4K) 0x8120f000 -> 0x89624000 (4K) Before, walk_pte would have shown: vaddr paddr size attr Reviewed-by: Alistair Francis Reviewed-by: Bin Meng ---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000002000 rwxu-ad as it only checks for subsequent paddrs. With this patch, it becomes: vaddr paddr size attr ---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000001000 rwxu-ad 000000008120f000 0000000089624000 0000000000001000 rwxu-ad Signed-off-by: Ralf Ramsauer --- [since v2: Adjust comment, rebased to latest master] target/riscv/monitor.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/target/riscv/monitor.c b/target/riscv/monitor.c index 7efb4b62c1..17e63fab00 100644 --- a/target/riscv/monitor.c +++ b/target/riscv/monitor.c @@ -84,6 +84,7 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ul= ong start, { hwaddr pte_addr; hwaddr paddr; + target_ulong last_start =3D -1; target_ulong pgsize; target_ulong pte; int ptshift; @@ -111,12 +112,13 @@ static void walk_pte(Monitor *mon, hwaddr base, targe= t_ulong start, * A leaf PTE has been found * * If current PTE's permission bits differ from the last o= ne, - * or current PTE's ppn does not make a contiguous physical - * address block together with the last one, print out the= last - * contiguous mapped block details. + * or the current PTE breaks up a contiguous virtual or + * physical mapping, address block together with the last = one, + * print out the last contiguous mapped block details. */ if ((*last_attr !=3D attr) || - (*last_paddr + *last_size !=3D paddr)) { + (*last_paddr + *last_size !=3D paddr) || + (last_start + *last_size !=3D start)) { print_pte(mon, va_bits, *vbase, *pbase, *last_paddr + *last_size - *pbase, *last_att= r); =20 @@ -125,6 +127,7 @@ static void walk_pte(Monitor *mon, hwaddr base, target_= ulong start, *last_attr =3D attr; } =20 + last_start =3D start; *last_paddr =3D paddr; *last_size =3D pgsize; } else { --=20 2.36.0