From nobody Mon Nov 25 09:41:59 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=cs.unc.edu ARC-Seal: i=1; a=rsa-sha256; t=1716570598; cv=none; d=zohomail.com; s=zohoarc; b=Qf516/Hcy1sy+jAaUiTlNTItlS5say7gtMbRT1DtVp/EhPB0zTNsjSK1TYJpAgeKQWslxE9H85W0aoNUG7bLdUAqqjZDC9mP+1AYJ2WeLlC0FB/wJnJ0PfZiVXSAh+m/EeLZdjAnynb3HrKJQcxjkxVoO0ZcvNSXtEy+1oKvtag= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716570598; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=QRwvTY+4XhYfL9PJXxknJUGay/i87It9LQZF1nGxs/4=; b=jUdVm49GXD6zr0oCo3R3KAaeAZPrHJquYHFouDu6hGgZyKBRWUDo40UW+UIc9G5JxkjEsgE43C+yQJEAwalyYzK7fZ4t/xS6RN5a5XeemJJI3s/SMe/SXBpHYGyUfH4nYCyW0SZxLyX/IhiHLqtsKs+Bl7/9jknMqK5opBksIgI= 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 1716570598524758.6206125900336; Fri, 24 May 2024 10:09:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sAYPD-00089s-Qr; Fri, 24 May 2024 13:08:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sAYP9-00089B-12 for qemu-devel@nongnu.org; Fri, 24 May 2024 13:08:31 -0400 Received: from mail-qk1-x735.google.com ([2607:f8b0:4864:20::735]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sAYOt-0007Yu-Ef for qemu-devel@nongnu.org; Fri, 24 May 2024 13:08:29 -0400 Received: by mail-qk1-x735.google.com with SMTP id af79cd13be357-792d65cd7a8so380449285a.1 for ; Fri, 24 May 2024 10:08:15 -0700 (PDT) Received: from kermit.cs.unc.edu (kermit.cs.unc.edu. [152.2.133.133]) by smtp.gmail.com with ESMTPSA id af79cd13be357-794abcc0f0fsm79816585a.38.2024.05.24.10.08.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 10:08:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.unc.edu; s=google; t=1716570494; x=1717175294; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QRwvTY+4XhYfL9PJXxknJUGay/i87It9LQZF1nGxs/4=; b=Hg80qQqG67dsyRBxV/lf7GsXMQwykBP0qTxRPW/cHkf9DNg9rOBmsmbmv4ewLS47ND +3QH0PqH7clsgtLxJZw+GnZHZf6NOdNhO7N/wYYcW43QNegBiarD0WMnYhOp7zhofnTl S8iCKgFGBfRFME0BBdU4Vmnxoxqsn+pPUQmVb9E7+iiFAxOC3eTLtwB42oRFNRCfrLSe 86HtMTx4EuCx8+IYz+q1Hys+vkmUsNr7FZFqdRZYCvDdBcPnRsfeE220KIOD+GW5pdc2 lUATNXskiXvFrUvFaBQevaY+lMO2sJvvR9lS81mMa/JXtWC4Z5BU/IGjEaRhAhHKenge Hilg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716570494; x=1717175294; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QRwvTY+4XhYfL9PJXxknJUGay/i87It9LQZF1nGxs/4=; b=w1kIStM7FPZk621DpIfALxNaTJ5WEOB76sRzCHEAISYXI/UFUtm6fBPSRcMRvJXe56 xBqzTQRXVSDyFeGe4986SzfY53QAx+K+5pP3bk9KZ9i/UVKEIGum38krPkeZyeIyy4pB BcQeGGkwlOknUvjSghCM9eQlus8Hz70hazsJ+f7jss947N3fvaFeW2uYeI5n/tplD5DT ZkVJK0dcVyJUSbK1WraGjBxqNMcdUnKZCeVbblmLqN4NtAE+eDGNsAMg/QyYWpVVBBJn xaIjTio3ju+KZuiDl5MFLijRUdaisT2f/ViBDm3UIoFzM3pqFpIB7eEqjAChHUsgdIjv oIXQ== X-Gm-Message-State: AOJu0Yz1s4/uo1YUsQWYD2EBegR7adq6FDf37kA0UnE0xEysMQlHNCDU /fqyd3oy56z2dCoCRaTRSznBFy6BilDZBFmHAUJGBsvHgTo/Sx3O3zqHlLfbQi6c85b8WMNyLXu KJkhbtb6qc76LFOXCDjmP3uLJ3qSHEiSuBVgOtamOwgdywqs9WmM4m0tWny/RHpvoXY/qcQfK8/ bRjdgiVAXKRRxLDb7dooUwh+ZgFzOC X-Google-Smtp-Source: AGHT+IFY6hIDYWYldWjie0/4Tks4TyE+9UgFA29j6DigoUyS9kq5piLySzanGCRQDH0icKdsLVAmQw== X-Received: by 2002:a05:620a:460e:b0:790:f696:2eb0 with SMTP id af79cd13be357-794ab1125ccmr339374285a.75.1716570493738; Fri, 24 May 2024 10:08:13 -0700 (PDT) From: Don Porter To: qemu-devel@nongnu.org Cc: dave@treblig.org, peter.maydell@linaro.org, nadav.amit@gmail.com, richard.henderson@linaro.org, Don Porter Subject: [PATCH v2 2/6] Convert 'info tlb' to use generic iterator Date: Fri, 24 May 2024 13:07:44 -0400 Message-Id: <20240524170748.1842030-3-porter@cs.unc.edu> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240524170748.1842030-1-porter@cs.unc.edu> References: <20240524170748.1842030-1-porter@cs.unc.edu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::735; envelope-from=porter@cs.unc.edu; helo=mail-qk1-x735.google.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_AU=-0.1, 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.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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @cs.unc.edu) X-ZM-MESSAGEID: 1716570599350100006 Content-Type: text/plain; charset="utf-8" Signed-off-by: Don Porter --- target/i386/monitor.c | 203 ++++++------------------------------------ 1 file changed, 28 insertions(+), 175 deletions(-) diff --git a/target/i386/monitor.c b/target/i386/monitor.c index d7aae99c73..adf95edfb4 100644 --- a/target/i386/monitor.c +++ b/target/i386/monitor.c @@ -430,201 +430,54 @@ void hmp_info_pg(Monitor *mon, const QDict *qdict) } =20 static void print_pte(Monitor *mon, CPUArchState *env, hwaddr addr, - hwaddr pte, hwaddr mask) + hwaddr pte) { - addr =3D addr_canonical(env, addr); - - monitor_printf(mon, HWADDR_FMT_plx ": " HWADDR_FMT_plx - " %c%c%c%c%c%c%c%c%c\n", - addr, - pte & mask, - pte & PG_NX_MASK ? 'X' : '-', - pte & PG_GLOBAL_MASK ? 'G' : '-', - pte & PG_PSE_MASK ? 'P' : '-', - pte & PG_DIRTY_MASK ? 'D' : '-', - pte & PG_ACCESSED_MASK ? 'A' : '-', - pte & PG_PCD_MASK ? 'C' : '-', - pte & PG_PWT_MASK ? 'T' : '-', - pte & PG_USER_MASK ? 'U' : '-', - pte & PG_RW_MASK ? 'W' : '-'); -} + char buf[128]; + char *pos =3D buf; =20 -static void tlb_info_32(Monitor *mon, CPUArchState *env) -{ - unsigned int l1, l2; - uint32_t pgd, pde, pte; + addr =3D addr_canonical(env, addr); =20 - pgd =3D env->cr[3] & ~0xfff; - for(l1 =3D 0; l1 < 1024; l1++) { - cpu_physical_memory_read(pgd + l1 * 4, &pde, 4); - pde =3D le32_to_cpu(pde); - if (pde & PG_PRESENT_MASK) { - if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) { - /* 4M pages */ - print_pte(mon, env, (l1 << 22), pde, ~((1 << 21) - 1)); - } else { - for(l2 =3D 0; l2 < 1024; l2++) { - cpu_physical_memory_read((pde & ~0xfff) + l2 * 4, &pte= , 4); - pte =3D le32_to_cpu(pte); - if (pte & PG_PRESENT_MASK) { - print_pte(mon, env, (l1 << 22) + (l2 << 12), - pte & ~PG_PSE_MASK, - ~0xfff); - } - } - } - } - } -} + pos +=3D sprintf(pos, HWADDR_FMT_plx ": " HWADDR_FMT_plx " ", addr, + (hwaddr) (pte & PG_ADDRESS_MASK)); =20 -static void tlb_info_pae32(Monitor *mon, CPUArchState *env) -{ - unsigned int l1, l2, l3; - uint64_t pdpe, pde, pte; - uint64_t pdp_addr, pd_addr, pt_addr; + pos +=3D sprintf(pos, " %s", pg_bits(pte)); =20 - pdp_addr =3D env->cr[3] & ~0x1f; - for (l1 =3D 0; l1 < 4; l1++) { - cpu_physical_memory_read(pdp_addr + l1 * 8, &pdpe, 8); - pdpe =3D le64_to_cpu(pdpe); - if (pdpe & PG_PRESENT_MASK) { - pd_addr =3D pdpe & 0x3fffffffff000ULL; - for (l2 =3D 0; l2 < 512; l2++) { - cpu_physical_memory_read(pd_addr + l2 * 8, &pde, 8); - pde =3D le64_to_cpu(pde); - if (pde & PG_PRESENT_MASK) { - if (pde & PG_PSE_MASK) { - /* 2M pages with PAE, CR4.PSE is ignored */ - print_pte(mon, env, (l1 << 30) + (l2 << 21), pde, - ~((hwaddr)(1 << 20) - 1)); - } else { - pt_addr =3D pde & 0x3fffffffff000ULL; - for (l3 =3D 0; l3 < 512; l3++) { - cpu_physical_memory_read(pt_addr + l3 * 8, &pt= e, 8); - pte =3D le64_to_cpu(pte); - if (pte & PG_PRESENT_MASK) { - print_pte(mon, env, (l1 << 30) + (l2 << 21) - + (l3 << 12), - pte & ~PG_PSE_MASK, - ~(hwaddr)0xfff); - } - } - } - } - } - } + /* Trim line to fit screen */ + if (pos - buf > 79) { + strcpy(buf + 77, ".."); } -} =20 -#ifdef TARGET_X86_64 -static void tlb_info_la48(Monitor *mon, CPUArchState *env, - uint64_t l0, uint64_t pml4_addr) -{ - uint64_t l1, l2, l3, l4; - uint64_t pml4e, pdpe, pde, pte; - uint64_t pdp_addr, pd_addr, pt_addr; - - for (l1 =3D 0; l1 < 512; l1++) { - cpu_physical_memory_read(pml4_addr + l1 * 8, &pml4e, 8); - pml4e =3D le64_to_cpu(pml4e); - if (!(pml4e & PG_PRESENT_MASK)) { - continue; - } - - pdp_addr =3D pml4e & 0x3fffffffff000ULL; - for (l2 =3D 0; l2 < 512; l2++) { - cpu_physical_memory_read(pdp_addr + l2 * 8, &pdpe, 8); - pdpe =3D le64_to_cpu(pdpe); - if (!(pdpe & PG_PRESENT_MASK)) { - continue; - } - - if (pdpe & PG_PSE_MASK) { - /* 1G pages, CR4.PSE is ignored */ - print_pte(mon, env, (l0 << 48) + (l1 << 39) + (l2 << 30), - pdpe, 0x3ffffc0000000ULL); - continue; - } - - pd_addr =3D pdpe & 0x3fffffffff000ULL; - for (l3 =3D 0; l3 < 512; l3++) { - cpu_physical_memory_read(pd_addr + l3 * 8, &pde, 8); - pde =3D le64_to_cpu(pde); - if (!(pde & PG_PRESENT_MASK)) { - continue; - } - - if (pde & PG_PSE_MASK) { - /* 2M pages, CR4.PSE is ignored */ - print_pte(mon, env, (l0 << 48) + (l1 << 39) + (l2 << 3= 0) + - (l3 << 21), pde, 0x3ffffffe00000ULL); - continue; - } - - pt_addr =3D pde & 0x3fffffffff000ULL; - for (l4 =3D 0; l4 < 512; l4++) { - cpu_physical_memory_read(pt_addr - + l4 * 8, - &pte, 8); - pte =3D le64_to_cpu(pte); - if (pte & PG_PRESENT_MASK) { - print_pte(mon, env, (l0 << 48) + (l1 << 39) + - (l2 << 30) + (l3 << 21) + (l4 << 12), - pte & ~PG_PSE_MASK, 0x3fffffffff000ULL); - } - } - } - } - } + monitor_printf(mon, "%s\n", buf); } =20 -static void tlb_info_la57(Monitor *mon, CPUArchState *env) +static +int mem_print_tlb(CPUState *cs, void *data, PTE_t *pte, + target_ulong vaddr, int height, int offset) { - uint64_t l0; - uint64_t pml5e; - uint64_t pml5_addr; - - pml5_addr =3D env->cr[3] & 0x3fffffffff000ULL; - for (l0 =3D 0; l0 < 512; l0++) { - cpu_physical_memory_read(pml5_addr + l0 * 8, &pml5e, 8); - pml5e =3D le64_to_cpu(pml5e); - if (pml5e & PG_PRESENT_MASK) { - tlb_info_la48(mon, env, l0, pml5e & 0x3fffffffff000ULL); - } - } + struct mem_print_state *state =3D (struct mem_print_state *) data; + print_pte(state->mon, state->env, vaddr, pte->pte64_t); + return 0; } -#endif /* TARGET_X86_64 */ =20 void hmp_info_tlb(Monitor *mon, const QDict *qdict) { - CPUArchState *env; + struct mem_print_state state; =20 - env =3D mon_get_cpu_env(mon); - if (!env) { - monitor_printf(mon, "No CPU available\n"); + CPUState *cs =3D mon_get_cpu(mon); + if (!cs) { + monitor_printf(mon, "Unable to get CPUState. Internal error\n"); return; } =20 - if (!(env->cr[0] & CR0_PG_MASK)) { - monitor_printf(mon, "PG disabled\n"); + if (!init_iterator(mon, &state)) { return; } - if (env->cr[4] & CR4_PAE_MASK) { -#ifdef TARGET_X86_64 - if (env->hflags & HF_LMA_MASK) { - if (env->cr[4] & CR4_LA57_MASK) { - tlb_info_la57(mon, env); - } else { - tlb_info_la48(mon, env, 0, env->cr[3] & 0x3fffffffff000ULL= ); - } - } else -#endif - { - tlb_info_pae32(mon, env); - } - } else { - tlb_info_32(mon, env); - } + + /** + * 'info tlb' visits only leaf PTEs marked present. + * It does not check other protection bits. + */ + for_each_pte(cs, &mem_print_tlb, &state, false, false); } =20 static void mem_print(Monitor *mon, CPUArchState *env, --=20 2.34.1