From patchwork Thu Oct 19 14:40:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 13429346 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 A47E0CDB465 for ; Thu, 19 Oct 2023 14:41:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=1PhuDLZI54HgwlLr5xArJ7wilQnwhNflObskdjfILic=; b=relQuGc+oYRk7leyQVuaZRJAPR YeAJ+CKzPHOTy4kAFL3iK5kNGDRP00XXKE4Tu3MUyiiGg7F1hMvEOBMgC9YHHRMsz2y4ZXf+cG959 hLz8uV3G8hyyfFe/4af2ljdsKX21Yo6euSg4DCfsXfWahqE3q3SXq5MqtYkeBXrzj9m+ddTCOQ33R tdlSHAQGDVNw59WcuXwjPDFuiVxbyb+cZsRCS87rO582bsn0oKS70bGPmZ3lYBdeO/DySbbRN3mI6 FNF/G+Z7MTYAJH6Xnk15E1aGiYhfdUKTAgsFBMJb7EzZzRcflGBMD4YAb/3a7Vt/6dgOdWtNcdGiy 5C8AGBRg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qtUDA-0006Tr-2g; Thu, 19 Oct 2023 14:41:20 +0000 Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qtUCv-0006LG-1x for linux-arm-kernel@lists.infradead.org; Thu, 19 Oct 2023 14:41:07 +0000 Received: by mail-wm1-x349.google.com with SMTP id 5b1f17b1804b1-40570ccc497so61536815e9.3 for ; Thu, 19 Oct 2023 07:41:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697726463; x=1698331263; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ElJlMelae52OVNRK43EtmIQAIoa6GhddKrR2iq/azSI=; b=0DekaTEvYPMC54vB/F7Nahd3tDNb4NG9CAmrgIaSw0i9NKVmyzIhIZEpCDOOuX7tPD MRJETGZQgaFbQ9EbFb5shEbQzI7TFwJlJ24k4K8YSZTeNsHzPG3e8sF4DC0ZUjepNXFj kuPqHww4CPW+Vmv5eOnTzdOfomeT0lrC93IpIx1yB6jacU5i3xm22MGAE+VGduUdHmFE OeB/0I3ZNh2YRWIKVO360DHfeJRfYTS0W2xTw//R75LSC73fgo4YiCCiNj2YANbZ80jv plLkz6u/rNs+l5h4iMpR8ZKs+ddfJBr1q6OCC7StCKyUBPLHWY+ZlOv7mTzWz/Osjn7Y v9nQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697726463; x=1698331263; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ElJlMelae52OVNRK43EtmIQAIoa6GhddKrR2iq/azSI=; b=nf0TXo23XI2CEUyD/Ix/EmkVEs471kFNEUIhLgU3o7tBhDQinKSuLvNiPYeukVVBXU nGlaS8bEAWR9zlj6qdf1M1sr7aQypA1pTw4D9J4y9P5J9/esAC6FWZ7MU3MBFAT2X9Gu KPRvvF0zmhIdtaliVvTIho9UTLAi+u+p7y8zKXKXReNQ6ECv6y1nACs8JuKCbSOpHK77 E+40WgBmStkNyZuHj1+H90BjjgFUwtwL89fRzCvjzu61G/VmA246LUw/9JbDGiG4aIQH 9oyBz44d7L67A80lmcHowrPO6vFKIBQVO9p1aGEel2aJMf+Bkq5jM3qU0K+J/gHiZ+k8 28Lw== X-Gm-Message-State: AOJu0YwXvU0yVrBA5llz/yl9z9YuAWu1Xcc9ab0OYs7yQzV/kkS8hwjb myPyjNqAh5RO5UJMrUEfIiX5CcE+X4RWZ/XJKQU= X-Google-Smtp-Source: AGHT+IFElnKsIi5dp2Ye8EDvnioIdKetK6LFJeeZwO4G65IWaMiQONCNVsOjqqbZrwPzyvGEqMqVtHvUbDt0zDruZF8= X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:a5d:444f:0:b0:32d:83b1:338e with SMTP id x15-20020a5d444f000000b0032d83b1338emr19447wrr.4.1697726463195; Thu, 19 Oct 2023 07:41:03 -0700 (PDT) Date: Thu, 19 Oct 2023 14:40:30 +0000 In-Reply-To: <20231019144032.2943044-1-sebastianene@google.com> Mime-Version: 1.0 References: <20231019144032.2943044-1-sebastianene@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231019144032.2943044-10-sebastianene@google.com> Subject: [PATCH v2 08/11] arm64: ptdump: Parse the host stage-2 page-tables from the snapshot From: Sebastian Ene To: will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, vdonnefort@google.com, qperret@google.com, smostafa@google.com, Sebastian Ene X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231019_074105_665068_3D7C919C X-CRM114-Status: GOOD ( 14.03 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add a walker function which configures ptdump to parse the page-tables from the snapshot. Convert the physical address of the pagetable's start address to a host virtual address and use the ptdump walker to parse the page-table descriptors. Signed-off-by: Sebastian Ene --- arch/arm64/mm/ptdump.c | 63 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 7c78b8994ca1..3ba4848272df 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -479,6 +479,11 @@ static void *ptdump_host_va(phys_addr_t phys) return __va(phys); } +static struct kvm_pgtable_mm_ops host_mmops = { + .phys_to_virt = ptdump_host_va, + .virt_to_phys = ptdump_host_pa, +}; + static size_t stage2_get_pgd_len(void) { u64 mmfr0, mmfr1, vtcr; @@ -604,6 +609,63 @@ static void stage2_ptdump_end_walk(struct ptdump_info *info) free_pages_exact(snapshot, PAGE_SIZE); info->priv = NULL; } + +static int stage2_ptdump_visitor(const struct kvm_pgtable_visit_ctx *ctx, + enum kvm_pgtable_walk_flags visit) +{ + struct pg_state *st = ctx->arg; + struct ptdump_state *pt_st = &st->ptdump; + + if (st->pg_level[ctx->level].mask & ctx->old) + pt_st->note_page(pt_st, ctx->addr, ctx->level, ctx->old); + + return 0; +} + +static void stage2_ptdump_walk(struct seq_file *s, struct ptdump_info *info) +{ + struct kvm_pgtable_snapshot *snapshot = info->priv; + struct pg_state st; + struct kvm_pgtable *pgtable; + u64 start_ipa = 0, end_ipa; + struct addr_marker ipa_address_markers[3]; + struct kvm_pgtable_walker walker = (struct kvm_pgtable_walker) { + .cb = stage2_ptdump_visitor, + .arg = &st, + .flags = KVM_PGTABLE_WALK_LEAF, + }; + + if (snapshot == NULL || !snapshot->pgtable.pgd) + return; + + pgtable = &snapshot->pgtable; + pgtable->mm_ops = &host_mmops; + end_ipa = BIT(pgtable->ia_bits) - 1; + + memset(&ipa_address_markers[0], 0, sizeof(ipa_address_markers)); + + ipa_address_markers[0].start_address = start_ipa; + ipa_address_markers[0].name = "IPA start"; + + ipa_address_markers[1].start_address = end_ipa; + ipa_address_markers[1].name = "IPA end"; + + st = (struct pg_state) { + .seq = s, + .marker = &ipa_address_markers[0], + .level = pgtable->start_level - 1, + .pg_level = &stage2_pg_level[0], + .ptdump = { + .note_page = note_page, + .range = (struct ptdump_range[]) { + {start_ipa, end_ipa}, + {0, 0}, + }, + }, + }; + + kvm_pgtable_walk(pgtable, start_ipa, end_ipa, &walker); +} #endif /* CONFIG_NVHE_EL2_PTDUMP_DEBUGFS */ static void __init ptdump_register_host_stage2(void) @@ -616,6 +678,7 @@ static void __init ptdump_register_host_stage2(void) .mc_len = host_s2_pgtable_pages(), .ptdump_prepare_walk = stage2_ptdump_prepare_walk, .ptdump_end_walk = stage2_ptdump_end_walk, + .ptdump_walk = stage2_ptdump_walk, }; mutex_init(&stage2_kernel_ptdump_info.file_lock);