From patchwork Wed Sep 27 11:25:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 145356 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp2599116vqu; Wed, 27 Sep 2023 05:41:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHBSd1WKTgYhqkfi5uuDKp8DmXDs/uweIX0nTNizTE80BtdzNa7cGW6junmt4/QLfpjuApU X-Received: by 2002:a17:90b:204:b0:276:cab8:4863 with SMTP id fy4-20020a17090b020400b00276cab84863mr1239059pjb.49.1695818513791; Wed, 27 Sep 2023 05:41:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695818513; cv=none; d=google.com; s=arc-20160816; b=XjXw8xqoy427rvhHXjZ5xLOiCMdlQO+5cQEWs6FyBXVA2mASt1EFG3AvRG8LTcgXw9 zZzcwOVHZJodpQ8EGBFs3jasQk9HLLSJpovvGTDjbV7oNKErNpq+ayfJLIc61kDsyBb8 qpSr2lz9jUZry2VjeXIsngLQfEA6e/6xSw49hIC+CtDaUuREM7qH2kHZCh3BF0chWOVl +6orRvPpGWBxexaepdrsADWjW5mQRc60lQzFNIOrWI8dixYFazexj65Lvno+WqXDKkn0 2pXmF1Lrlh+3WPM9j2AQs5xZZOq6pJeAuTceX2862J4lBkqywaF3mRFmi1exVrGcVjTr haYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=5Tv2IK7z2ajFi0YhiZDVE+zhN0ISgLY/5ARrffKbsHA=; fh=yikR9HT1wx5LLj7DvfR9kbE/RatD/mnQgNUS++qRsJM=; b=y6JiDXHuNWEmkSjIvfmqVoXnGU2RnWWC+3lIBL6mEIDqtOf85Qx+Yy4GRUqufnqOzK GOv+8XRbWmIRoj3ToeyBm3lucXdUu6zZ25MJiBn746tbkG7poz3UXNq8j/Q21ggYnUdF jMrHLl33J0zUd8UGniAL91yyntA/WBg2fnPtMHDNKnvd8kiZqeqgSp+2u/se0y/Kvc3F 4gcfhFMNOhX5oGnV7k36jh19GOGcMfklzqBImocLEDJfjg+iokNzih3cjVsfq/Lu3qk4 CgXyCD0dEoFgJs3czdChF3a0wpxoKXRF2bGdPnI5rsZYtwzcixXY57iUSDKwspoWiZTM dVhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=1t+jj6q1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id oo12-20020a17090b1c8c00b0027769e8672fsi7420957pjb.119.2023.09.27.05.41.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 05:41:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=1t+jj6q1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 8118B808725B; Wed, 27 Sep 2023 04:26:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231442AbjI0LZt (ORCPT + 22 others); Wed, 27 Sep 2023 07:25:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231421AbjI0LZm (ORCPT ); Wed, 27 Sep 2023 07:25:42 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9183193 for ; Wed, 27 Sep 2023 04:25:39 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-59c0dd156e5so225157097b3.3 for ; Wed, 27 Sep 2023 04:25:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695813939; x=1696418739; darn=vger.kernel.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=5Tv2IK7z2ajFi0YhiZDVE+zhN0ISgLY/5ARrffKbsHA=; b=1t+jj6q1rMULN+6RMDJ2zZ1RmegvWfSuj2LTud07sjd67JkgWJYg1mXfLoJQNeX5LU zeAmrhOmxUpeXfkjuU32ua1Ilp9S+hZ4rzI07fJEnYkW6bvnMz4PQo4aVoLnaEtPzpsK fQYSNwIji9RI6HervDR9/5SjFUoPXIBRtDwoqppevz2xqqn8tPUnlPEWzeMZ03D0fxy8 A+ok45lAP3ZszgYQYdVg8I+f8a1d/ac2GXGzH5Ihg3zNAAJbSOAXA8pdPgl+AMdBS8l6 O0p78XhF6nYdkOIl9VBn0GxLEH+BnRu5BUd8vPhzbSLtDn54oTs56AzOywWcH4mKfkkG RSxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695813939; x=1696418739; 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=5Tv2IK7z2ajFi0YhiZDVE+zhN0ISgLY/5ARrffKbsHA=; b=mtrdukr1ukilEWetwek8gVUKNgP3Ln4oGIJbQUARXdyknq/ReyR+3LJ3Cvsn27OFlU k0b7VyWAVykLQ/PqclNJQZWocj303JqehD8Kzc+Gx/1N7uWG2dT1urZfz1Ic9CH0ZTjz GFkcGMMVGnQNGANmXBeXL23vB1v+i0H+1Y9VLX4NmYzlE+bR9IOXq3ma6oTvIXHGuAoJ e9AeJEkiufKDPN197EanTh9rYCWiw6i6rl36TYHJpIbw2580CSSbN5u5v9a8wdk+G7rh Mv3fuDcDdYcJLj/kjGoqBbt74Usl3DGt2rGCPqf7y1tYPJdARXrNwWkhcd8RV74YeeLC pU6w== X-Gm-Message-State: AOJu0YyBSnBoGu3BSkgG7VtEadzu6EqAupoip3Czp5VkvHeTGlt9/Wew DJYPKiJsnJqzTgZ5fBtq6WT12q3SgL3RosTBbp9OxHksdQBt3vGRVn29mIUzBB2SKNtTxJ9wsB1 5wtZdJi5m4whQsCJsBrLBPPgYfx9wckeaov4kOl2FyP4ekG9Rt+7qSP6SXBnk+fKoyWvBWEnpc2 zbA9WV9x1OCg== X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:a25:2416:0:b0:d7a:c85c:725b with SMTP id k22-20020a252416000000b00d7ac85c725bmr21171ybk.7.1695813938717; Wed, 27 Sep 2023 04:25:38 -0700 (PDT) Date: Wed, 27 Sep 2023 11:25:07 +0000 In-Reply-To: <20230927112517.2631674-1-sebastianene@google.com> Mime-Version: 1.0 References: <20230927112517.2631674-1-sebastianene@google.com> X-Mailer: git-send-email 2.42.0.515.g380fc7ccd1-goog Message-ID: <20230927112517.2631674-2-sebastianene@google.com> Subject: [PATCH 01/11] KVM: arm64: Add snap shooting the host stage-2 pagetables From: Sebastian Ene To: linux-kernel@vger.kernel.org Cc: kernel-team@android.com, will@kernel.org, ryan.roberts@arm.com, mark.rutland@arm.com, maz@kernel.org, vdonnefort@google.com, Sebastian Ene X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 27 Sep 2023 04:26:19 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778194593756448415 X-GMAIL-MSGID: 1778194593756448415 Introduce a new HVC that allows the caller to snap shoot the stage-2 pagetables under NVHE debug configuration. The caller specifies the location where the pagetables are copied and must ensure that the memory is accessible by the hypervisor. The memory where the pagetables are copied has to be allocated by the caller and shared with the hypervisor. Signed-off-by: Sebastian Ene --- arch/arm64/include/asm/kvm_asm.h | 1 + arch/arm64/include/asm/kvm_pgtable.h | 36 ++++++ arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 1 + arch/arm64/kvm/hyp/nvhe/hyp-main.c | 18 +++ arch/arm64/kvm/hyp/nvhe/mem_protect.c | 103 ++++++++++++++++++ arch/arm64/kvm/hyp/pgtable.c | 56 ++++++++++ 6 files changed, 215 insertions(+) diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h index 24b5e6b23417..99145a24c0f6 100644 --- a/arch/arm64/include/asm/kvm_asm.h +++ b/arch/arm64/include/asm/kvm_asm.h @@ -81,6 +81,7 @@ enum __kvm_host_smccc_func { __KVM_HOST_SMCCC_FUNC___pkvm_init_vm, __KVM_HOST_SMCCC_FUNC___pkvm_init_vcpu, __KVM_HOST_SMCCC_FUNC___pkvm_teardown_vm, + __KVM_HOST_SMCCC_FUNC___pkvm_copy_host_stage2, }; #define DECLARE_KVM_VHE_SYM(sym) extern char sym[] diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h index d3e354bb8351..be615700f8ac 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -10,6 +10,7 @@ #include #include #include +#include #define KVM_PGTABLE_MAX_LEVELS 4U @@ -351,6 +352,21 @@ struct kvm_pgtable { kvm_pgtable_force_pte_cb_t force_pte_cb; }; +/** + * struct kvm_pgtable_snapshot - Snapshot page-table wrapper. + * @pgtable: The page-table configuration. + * @mc: Memcache used for pagetable pages allocation. + * @pgd_hva: Host virtual address of a physically contiguous buffer + * used for storing the PGD. + * @pgd_len: The size of the phyisically contiguous buffer in bytes. + */ +struct kvm_pgtable_snapshot { + struct kvm_pgtable pgtable; + struct kvm_hyp_memcache mc; + void *pgd_hva; + size_t pgd_len; +}; + /** * kvm_pgtable_hyp_init() - Initialise a hypervisor stage-1 page-table. * @pgt: Uninitialised page-table structure to initialise. @@ -756,4 +772,24 @@ enum kvm_pgtable_prot kvm_pgtable_hyp_pte_prot(kvm_pte_t pte); */ void kvm_tlb_flush_vmid_range(struct kvm_s2_mmu *mmu, phys_addr_t addr, size_t size); + +#ifdef CONFIG_NVHE_EL2_DEBUG +/** + * kvm_pgtable_stage2_copy() - Snapshot the pagetable + * + * @to_pgt: Destination pagetable + * @from_pgt: Source pagetable. The caller must lock the pagetables first + * @mc: The memcache where we allocate the destination pagetables from + */ +int kvm_pgtable_stage2_copy(struct kvm_pgtable *to_pgt, + const struct kvm_pgtable *from_pgt, + void *mc); +#else +static inline int kvm_pgtable_stage2_copy(struct kvm_pgtable *to_pgt, + const struct kvm_pgtable *from_pgt, + void *mc) +{ + return -EPERM; +} +#endif /* CONFIG_NVHE_EL2_DEBUG */ #endif /* __ARM64_KVM_PGTABLE_H__ */ diff --git a/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h b/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h index 0972faccc2af..9cfb35d68850 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h +++ b/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h @@ -69,6 +69,7 @@ int __pkvm_host_donate_hyp(u64 pfn, u64 nr_pages); int __pkvm_hyp_donate_host(u64 pfn, u64 nr_pages); int __pkvm_host_share_ffa(u64 pfn, u64 nr_pages); int __pkvm_host_unshare_ffa(u64 pfn, u64 nr_pages); +int __pkvm_host_stage2_prepare_copy(struct kvm_pgtable_snapshot *snapshot); bool addr_is_memory(phys_addr_t phys); int host_stage2_idmap_locked(phys_addr_t addr, u64 size, enum kvm_pgtable_prot prot); diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c index 2385fd03ed87..0d9b56c31cf2 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -314,6 +314,23 @@ static void handle___pkvm_teardown_vm(struct kvm_cpu_context *host_ctxt) cpu_reg(host_ctxt, 1) = __pkvm_teardown_vm(handle); } +static void handle___pkvm_copy_host_stage2(struct kvm_cpu_context *host_ctxt) +{ + int ret = -EPERM; +#ifdef CONFIG_NVHE_EL2_DEBUG + DECLARE_REG(struct kvm_pgtable_snapshot *, snapshot, host_ctxt, 1); + kvm_pteref_t pgd; + + snapshot = kern_hyp_va(snapshot); + ret = __pkvm_host_stage2_prepare_copy(snapshot); + if (!ret) { + pgd = snapshot->pgtable.pgd; + snapshot->pgtable.pgd = (kvm_pteref_t)__hyp_pa(pgd); + } +#endif + cpu_reg(host_ctxt, 1) = ret; +} + typedef void (*hcall_t)(struct kvm_cpu_context *); #define HANDLE_FUNC(x) [__KVM_HOST_SMCCC_FUNC_##x] = (hcall_t)handle_##x @@ -348,6 +365,7 @@ static const hcall_t host_hcall[] = { HANDLE_FUNC(__pkvm_init_vm), HANDLE_FUNC(__pkvm_init_vcpu), HANDLE_FUNC(__pkvm_teardown_vm), + HANDLE_FUNC(__pkvm_copy_host_stage2), }; static void handle_host_hcall(struct kvm_cpu_context *host_ctxt) diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c index 9d703441278b..fe1a6dbd6d31 100644 --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c @@ -266,6 +266,109 @@ int kvm_guest_prepare_stage2(struct pkvm_hyp_vm *vm, void *pgd) return 0; } +#ifdef CONFIG_NVHE_EL2_DEBUG +static struct hyp_pool snapshot_pool = {0}; +static DEFINE_HYP_SPINLOCK(snapshot_pool_lock); + +static void *snapshot_zalloc_pages_exact(size_t size) +{ + void *addr = hyp_alloc_pages(&snapshot_pool, get_order(size)); + + hyp_split_page(hyp_virt_to_page(addr)); + + /* + * The size of concatenated PGDs is always a power of two of PAGE_SIZE, + * so there should be no need to free any of the tail pages to make the + * allocation exact. + */ + WARN_ON(size != (PAGE_SIZE << get_order(size))); + + return addr; +} + +static void snapshot_get_page(void *addr) +{ + hyp_get_page(&snapshot_pool, addr); +} + +static void *snapshot_zalloc_page(void *mc) +{ + struct hyp_page *p; + void *addr; + + addr = hyp_alloc_pages(&snapshot_pool, 0); + if (addr) + return addr; + + addr = pop_hyp_memcache(mc, hyp_phys_to_virt); + if (!addr) + return addr; + + memset(addr, 0, PAGE_SIZE); + p = hyp_virt_to_page(addr); + memset(p, 0, sizeof(*p)); + p->refcount = 1; + + return addr; +} + +static void snapshot_s2_free_pages_exact(void *addr, unsigned long size) +{ + u8 order = get_order(size); + unsigned int i; + struct hyp_page *p; + + for (i = 0; i < (1 << order); i++) { + p = hyp_virt_to_page(addr + (i * PAGE_SIZE)); + hyp_page_ref_dec_and_test(p); + } +} + +int __pkvm_host_stage2_prepare_copy(struct kvm_pgtable_snapshot *snapshot) +{ + size_t required_pgd_len; + struct kvm_pgtable_mm_ops mm_ops = {0}; + struct kvm_pgtable *to_pgt, *from_pgt = &host_mmu.pgt; + struct kvm_hyp_memcache *memcache = &snapshot->mc; + int ret; + void *pgd; + u64 nr_pages; + + required_pgd_len = kvm_pgtable_stage2_pgd_size(host_mmu.arch.vtcr); + if (snapshot->pgd_len < required_pgd_len) + return -ENOMEM; + + to_pgt = &snapshot->pgtable; + nr_pages = snapshot->pgd_len / PAGE_SIZE; + pgd = kern_hyp_va(snapshot->pgd_hva); + + hyp_spin_lock(&snapshot_pool_lock); + hyp_pool_init(&snapshot_pool, hyp_virt_to_pfn(pgd), + required_pgd_len / PAGE_SIZE, 0); + + mm_ops.zalloc_pages_exact = snapshot_zalloc_pages_exact; + mm_ops.zalloc_page = snapshot_zalloc_page; + mm_ops.free_pages_exact = snapshot_s2_free_pages_exact; + mm_ops.get_page = snapshot_get_page; + mm_ops.phys_to_virt = hyp_phys_to_virt; + mm_ops.virt_to_phys = hyp_virt_to_phys; + mm_ops.page_count = hyp_page_count; + + to_pgt->ia_bits = from_pgt->ia_bits; + to_pgt->start_level = from_pgt->start_level; + to_pgt->flags = from_pgt->flags; + to_pgt->mm_ops = &mm_ops; + + host_lock_component(); + ret = kvm_pgtable_stage2_copy(to_pgt, from_pgt, memcache); + host_unlock_component(); + + hyp_spin_unlock(&snapshot_pool_lock); + + return ret; +} +#endif /* CONFIG_NVHE_EL2_DEBUG */ + void reclaim_guest_pages(struct pkvm_hyp_vm *vm, struct kvm_hyp_memcache *mc) { void *addr; diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index f155b8c9e98c..256654b89c1e 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -1598,3 +1598,59 @@ void kvm_pgtable_stage2_free_unlinked(struct kvm_pgtable_mm_ops *mm_ops, void *p WARN_ON(mm_ops->page_count(pgtable) != 1); mm_ops->put_page(pgtable); } + +#ifdef CONFIG_NVHE_EL2_DEBUG +static int stage2_copy_walker(const struct kvm_pgtable_visit_ctx *ctx, + enum kvm_pgtable_walk_flags visit) +{ + struct kvm_pgtable_mm_ops *mm_ops = ctx->mm_ops; + void *copy_table, *original_addr; + kvm_pte_t new = ctx->old; + + if (!stage2_pte_is_counted(ctx->old)) + return 0; + + if (kvm_pte_table(ctx->old, ctx->level)) { + copy_table = mm_ops->zalloc_page(ctx->arg); + if (!copy_table) + return -ENOMEM; + + original_addr = kvm_pte_follow(ctx->old, mm_ops); + + memcpy(copy_table, original_addr, PAGE_SIZE); + new = kvm_init_table_pte(copy_table, mm_ops); + } + + *ctx->ptep = new; + + return 0; +} + +int kvm_pgtable_stage2_copy(struct kvm_pgtable *to_pgt, + const struct kvm_pgtable *from_pgt, + void *mc) +{ + int ret; + size_t pgd_sz; + struct kvm_pgtable_mm_ops *mm_ops = to_pgt->mm_ops; + struct kvm_pgtable_walker walker = { + .cb = stage2_copy_walker, + .flags = KVM_PGTABLE_WALK_LEAF | + KVM_PGTABLE_WALK_TABLE_PRE, + .arg = mc + }; + + pgd_sz = kvm_pgd_pages(to_pgt->ia_bits, to_pgt->start_level) * + PAGE_SIZE; + to_pgt->pgd = (kvm_pteref_t)mm_ops->zalloc_pages_exact(pgd_sz); + if (!to_pgt->pgd) + return -ENOMEM; + + memcpy(to_pgt->pgd, from_pgt->pgd, pgd_sz); + + ret = kvm_pgtable_walk(to_pgt, 0, BIT(to_pgt->ia_bits), &walker); + mm_ops->free_pages_exact(to_pgt->pgd, pgd_sz); + + return ret; +} +#endif /* CONFIG_NVHE_EL2_DEBUG */ From patchwork Wed Sep 27 11:25:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 145512 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp2813655vqu; Wed, 27 Sep 2023 11:18:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEwxy2VlVlZ+PQwisNo1po0rKo5rWQ3ZItFxgPlXm1R0Y9nnBsbk/zSUanHUVfVqNyoXJzx X-Received: by 2002:a17:903:268c:b0:1c0:d7a9:1c48 with SMTP id jf12-20020a170903268c00b001c0d7a91c48mr2599560plb.49.1695838694583; Wed, 27 Sep 2023 11:18:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695838694; cv=none; d=google.com; s=arc-20160816; b=a3f1Q6gQJZ2BI9AvzJXI9G4tnPFs44PAIVRoB/5kWPQPeub6uiRWgDZ2W9Hot+CYcl eVazfyztjrNH2KBRQFIW1SH5eiB70XB2OwproPVjVLvUx++l0UM7iDDMfoZ165cxEV0n a2gxKej6ek9T++AnG1jdFxPecJmOe4Y1hKsBdj7dfnYNMcITvufmxScNsy0J0IRNm3xT Vk4orQBgCyTeYI3fhddZjwDASrKobmHd2tjEZvXTtBDQvbm8nU8UDp9rccgKKaUd6Pz3 dRa0YRAr3sKlAc25OClXQZmRKoV3XfF/3q/oBU7kJ2VKqyUcPKKKFHiVlb6wS22nLw1w qQ9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=yFhKKi5b0kZOlGKtkzEc+xU7GiAAYZeYNUbkjyCvZbk=; fh=yikR9HT1wx5LLj7DvfR9kbE/RatD/mnQgNUS++qRsJM=; b=HazayE8+Ps0HNlpnJB92UfZUEwnnPvHXs1p+za6/iO+O7UYu5v78GD8RiwPKCr3fwt M5lkiQT6mkItoL++nCZMtXMvF6sCs4E6/m9Fh9fzEwM5jDwT1rl/R+Sc34OdnC2UyvNO dRzQ13Sb7MTsTczWwQaRMklOjoqKIDsCL73pNSfcV23wZF1XMZOFkNbM91a0mUXPARyM f81LO9PrtBaaD1MSPB3itNEdtTYSxNlVIdBwLOvpHV13kcYMfesQuclA5qYmPHacudYn d+V5C23o2S2uEzHknggzdnRYbhc9TAajX85DMSARj9zZT0laklu2cNfqfkeKocSr3Uol coAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=eddof2vA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id m1-20020a170902d18100b001b83767e879si14887729plb.266.2023.09.27.11.18.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 11:18:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=eddof2vA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 1D68D80266BE; Wed, 27 Sep 2023 04:26:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231501AbjI0LZ4 (ORCPT + 22 others); Wed, 27 Sep 2023 07:25:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231339AbjI0LZo (ORCPT ); Wed, 27 Sep 2023 07:25:44 -0400 Received: from mail-wr1-x449.google.com (mail-wr1-x449.google.com [IPv6:2a00:1450:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C65A3196 for ; Wed, 27 Sep 2023 04:25:42 -0700 (PDT) Received: by mail-wr1-x449.google.com with SMTP id ffacd0b85a97d-321726b0238so7932156f8f.2 for ; Wed, 27 Sep 2023 04:25:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695813941; x=1696418741; darn=vger.kernel.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=yFhKKi5b0kZOlGKtkzEc+xU7GiAAYZeYNUbkjyCvZbk=; b=eddof2vAUlqPkEr0fgFU+VyV/kH9YKQrI6vugFkq2P7bvCTTgESwfHGFil4bzhtMl0 KrH9kuV8IY3X2d80TCPVBiKOK+tYv/+lqKeXfiTyefIppllUELvK6FvVZNimyg31Olic jdlqZ7ewidZClJDrDt3nJb/zs+CMd38QsKccdiqiKIRkmyqybZsF3Uy1zj2pQ+jfnvdk t8uCZQhTgzzC2CljsWnD0F8UgT7xmiRRXJqVg97d4XWY3LEivnBYGP3UEIjtYgUBUA29 tHTwe3KFfmT/7jHelg5PKKdU13b4rLKSw+AWsK1nJlw96JUAGsSJkMqiv+Ic+SLMza5y LDGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695813941; x=1696418741; 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=yFhKKi5b0kZOlGKtkzEc+xU7GiAAYZeYNUbkjyCvZbk=; b=e1OAHmETGbhjyjcgq/kXPq4DI2Mbnzex/n2U76u4uSVONzax9Cpnf3z3GKua/KiUk0 DMxifo5NV8RLHbzNZr+QkZFRM7rf2jxXM6zMfbh3K+nqpdZDWy9lVFemkDFHrFaNi01o Cw5Cc3hoNAUqSj7C99oO/ZMFBN9/cpLxzla7kL6bMgtAW0US1/W3aVx3VAQxe8GTDVAD UxgEPGqTl0eLJeTjZARN0apN2L3zv72U6ArRnabMruIUxurS2TrXysWq/uwZ3ArwdePb djB07UrlpwSE5HaxJJYqEcpFxFOilygpHG792lRe+2vF2/f/XuFDZhE69eQpqLgSWSqP bfpQ== X-Gm-Message-State: AOJu0YzfrDlwopyu03AdTjsGvXTO9TZvshseCIIVzvk+AAv+an2e3WB/ fEwVaWVoOBx6OsqhA6GS8E1k3SQX7SDl0yB8QBPdBsV749lufbE0x3YZTr5oz/Wy0ViU6HVrhj9 ce/2McXpeNtzF6tkpVRPy1mebj7Tl8ijUb8OkGF2UzV6xgzuUbj/Ak1tqSLv08MONayviwNtjlq tV96y6o343Pw== X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:a5d:6142:0:b0:321:6a06:8d1c with SMTP id y2-20020a5d6142000000b003216a068d1cmr7122wrt.1.1695813941137; Wed, 27 Sep 2023 04:25:41 -0700 (PDT) Date: Wed, 27 Sep 2023 11:25:08 +0000 In-Reply-To: <20230927112517.2631674-1-sebastianene@google.com> Mime-Version: 1.0 References: <20230927112517.2631674-1-sebastianene@google.com> X-Mailer: git-send-email 2.42.0.515.g380fc7ccd1-goog Message-ID: <20230927112517.2631674-3-sebastianene@google.com> Subject: [PATCH 02/11] arm64: ptdump: Use the mask from the state structure From: Sebastian Ene To: linux-kernel@vger.kernel.org Cc: kernel-team@android.com, will@kernel.org, ryan.roberts@arm.com, mark.rutland@arm.com, maz@kernel.org, vdonnefort@google.com, Sebastian Ene X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 27 Sep 2023 04:26:20 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778215755243882257 X-GMAIL-MSGID: 1778215755243882257 Printing the descriptor attributes requires accessing a mask which has a different set of attributes for stage-2. In preparation for adding support for the stage-2 pagetables dumping, use the mask from the local context and not from the globally defined pg_level array. Store a pointer to the pg_level array in the ptdump state structure. This will allow us to extract the mask which is wrapped in the pg_level array and use it for descriptor parsing in the note_page. Signed-off-by: Sebastian Ene --- arch/arm64/mm/ptdump.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index e305b6593c4e..8761a70f916f 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -75,6 +75,7 @@ static struct addr_marker address_markers[] = { struct pg_state { struct ptdump_state ptdump; struct seq_file *seq; + struct pg_level *pg_level; const struct addr_marker *marker; unsigned long start_address; int level; @@ -252,11 +253,12 @@ static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, u64 val) { struct pg_state *st = container_of(pt_st, struct pg_state, ptdump); + struct pg_level *pg_info = st->pg_level; static const char units[] = "KMGTPE"; u64 prot = 0; if (level >= 0) - prot = val & pg_level[level].mask; + prot = val & pg_info[level].mask; if (st->level == -1) { st->level = level; @@ -282,10 +284,10 @@ static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, unit++; } pt_dump_seq_printf(st->seq, "%9lu%c %s", delta, *unit, - pg_level[st->level].name); - if (st->current_prot && pg_level[st->level].bits) - dump_prot(st, pg_level[st->level].bits, - pg_level[st->level].num); + pg_info[st->level].name); + if (st->current_prot && pg_info[st->level].bits) + dump_prot(st, pg_info[st->level].bits, + pg_info[st->level].num); pt_dump_seq_puts(st->seq, "\n"); if (addr >= st->marker[1].start_address) { @@ -316,6 +318,7 @@ void ptdump_walk(struct seq_file *s, struct ptdump_info *info) st = (struct pg_state){ .seq = s, .marker = info->markers, + .pg_level = &pg_level[0], .level = -1, .ptdump = { .note_page = note_page, @@ -353,6 +356,7 @@ void ptdump_check_wx(void) { 0, NULL}, { -1, NULL}, }, + .pg_level = &pg_level[0], .level = -1, .check_wx = true, .ptdump = { From patchwork Wed Sep 27 11:25:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 145423 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp2711258vqu; Wed, 27 Sep 2023 08:32:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHSX/eGqhsi5JP6MomEDzvK1yLneOH88QF7CNoDpa8Ijhnx2laIIuHF62Rg0FA3C6+Bnn/a X-Received: by 2002:a05:6a00:10c6:b0:692:b429:390 with SMTP id d6-20020a056a0010c600b00692b4290390mr2424135pfu.29.1695828749971; Wed, 27 Sep 2023 08:32:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695828749; cv=none; d=google.com; s=arc-20160816; b=gjQVLU1//NFJrp7c+TcRd/As8q6KwBbNtpkMYHDHKzDX/nqx2y8exjVGdbQystx4al +Aul1+bQIwrbziXbHlA51S6WSRs6Ett5cYBeo+IZySTII24lcqe09e2iavl3h9NJcvmB soili0ntglXW1/FnTh7sdyelpg709aLV6Dapf6D2Q0Ypoxfy5sdkUSHkeDVl8co8ydhG lQ/mU4NRJUGrb4HIj0IyYeyhZSY31Eykl5mxYPdeuH4Ydh3nBEHeo92h3rHujCjnJu76 +cxjlhIRccifO9Y8prw9cTTPfcyA0HLAaD7XHG+DawpzwoPM3XN3fRh3PrQ6/5kv/lth C6tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=U2wy+Fu981b0iBfz2jBuvwB+Vk21Fc177L9d68PfARs=; fh=yikR9HT1wx5LLj7DvfR9kbE/RatD/mnQgNUS++qRsJM=; b=bN4f4MaG+gpRUMLcG3QGiRPt/rMXPCUsKs/K9LPq8KiS7716Q5La+Ij9Xx7Y887rMM V0ranME0jR0eS3AJoUbetLHkpYuwr/Jrg3cJhkCJCUMRTS31ty7Or35f/5LizwUswDV8 ssII38NJWd8zVHKLBsu1R/0L7ZXFQr9sYHcS1X4r5La253TTRD0BlaBNbfjVTE5yQMTZ uKd3Hia7qCspuyAr9Blidz/EVZAbXbUPiuonwUIURfWI0ehsxtKPc9h7IRrynGpcRfa2 DrFsLTkZXofrCK3WV5VPPHcIxQqzsLnprt5nnSZ7XPrp3TxUK/4RVjsysJsR1nNMJt9v 55MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=BAZ0KFt1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id cv7-20020a056a0044c700b00690d00d52efsi16249837pfb.264.2023.09.27.08.32.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 08:32:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=BAZ0KFt1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id A0DB8809E883; Wed, 27 Sep 2023 04:26:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231462AbjI0LZw (ORCPT + 22 others); Wed, 27 Sep 2023 07:25:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231451AbjI0LZp (ORCPT ); Wed, 27 Sep 2023 07:25:45 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E2A719A for ; Wed, 27 Sep 2023 04:25:44 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d86766bba9fso13150854276.1 for ; Wed, 27 Sep 2023 04:25:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695813943; x=1696418743; darn=vger.kernel.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=U2wy+Fu981b0iBfz2jBuvwB+Vk21Fc177L9d68PfARs=; b=BAZ0KFt1EM8ivr1Y5hQhqP/nypHmW1fCzekhJ9EaoBpOHR1z7Fh9PfVxIQqPzqOi+f gybmrPQZLQkvFCPQ5iiM/TGjXJwlvoZmo38Ob5KXiz72aRBQO/xeV+PDV/bWzsBW6laA XnMoWA6a3q1tfrMDEziOHwE/tXq8Q2koOPTGiKfbPSz9o+FplMl1jmLkTh3Xvjbbtsc1 8iv7gDk0+iSDDmUOfnI43a4x6TdAtZZ7h1XswwWBACabmwXqgr+69/o2ruomcuXU9zoD ahOKIKtFOef49E6C6v8tpJ6exYPqvuTJEZ7J+fvm/Shiu8Gaz+abvrkgfNnn7LBBBYbD T2wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695813943; x=1696418743; 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=U2wy+Fu981b0iBfz2jBuvwB+Vk21Fc177L9d68PfARs=; b=ECkytPrT+/Ka1vLbjXe47yL7xTM7Gec2Nylr7lBmUXflJjZoT2ahaYhRSgvVYoepAI qAOuuEJqeCxzUuqEtAhCPlq/AalcoGePOQ88Upt5H2p/GNd64UEb52YSfJj6+pSV32Dq lxxfFlBRb3ZgY2hGQsWfzgeS+Ucve6xHWh0IQA5eSDFuT2nsMPwLZSsI+2Fjhix5QAq5 cqcY2hjUaMjqjq8dQ3ez1YkJPNehhsr3wb72OaCdOtDJgVGXLi2hCCMkS1qtyIK1wNHM kFRnRhOa+O8zP+SBmWsm4P+HfuZ0okzl5ATav0xEkazM3iTLQhf54ag191x0iKjo4qP0 GZGQ== X-Gm-Message-State: AOJu0YxOuhX2Yz4sOS0HSt9kiHfT/HbFE8dxup1DLpW95YTvo/ssMLS9 8yYxj/5Fa7MpoE9EOz4mDYmrr8VZ0MFg5l+5x4wa9UPQRtGit4ty94KwTOiNY3Mu7Hc7gDzn5jp BI1f0AG1rQbmQn7p4HRzb/+wcNzFKC62XnfpoRPwhn8bvyryuTLmIFFWSVL5zw+tn+6CT4V2A5i ZKbqWWXN3pfw== X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:a25:ac89:0:b0:d86:5500:7dba with SMTP id x9-20020a25ac89000000b00d8655007dbamr22642ybi.13.1695813943422; Wed, 27 Sep 2023 04:25:43 -0700 (PDT) Date: Wed, 27 Sep 2023 11:25:09 +0000 In-Reply-To: <20230927112517.2631674-1-sebastianene@google.com> Mime-Version: 1.0 References: <20230927112517.2631674-1-sebastianene@google.com> X-Mailer: git-send-email 2.42.0.515.g380fc7ccd1-goog Message-ID: <20230927112517.2631674-4-sebastianene@google.com> Subject: [PATCH 03/11] arm64: ptdump: Add the walker function to the ptdump info structure From: Sebastian Ene To: linux-kernel@vger.kernel.org Cc: kernel-team@android.com, will@kernel.org, ryan.roberts@arm.com, mark.rutland@arm.com, maz@kernel.org, vdonnefort@google.com, Sebastian Ene X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 27 Sep 2023 04:26:11 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778205327505954717 X-GMAIL-MSGID: 1778205327505954717 Stage-2 needs a dedicated walk function to be able to parse concatenated pagetables. The ptdump info structure is used to hold different configuration options for the walker. This structure is registered with the debugfs entry and is stored in the argument for the debugfs file. Hence, in preparation for parsing the stage-2 pagetables add the walk function as an argument for the debugfs file. Signed-off-by: Sebastian Ene --- arch/arm64/include/asm/ptdump.h | 1 + arch/arm64/mm/ptdump.c | 1 + arch/arm64/mm/ptdump_debugfs.c | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h index 581caac525b0..1f6e0aabf16a 100644 --- a/arch/arm64/include/asm/ptdump.h +++ b/arch/arm64/include/asm/ptdump.h @@ -19,6 +19,7 @@ struct ptdump_info { struct mm_struct *mm; const struct addr_marker *markers; unsigned long base_addr; + void (*ptdump_walk)(struct seq_file *s, struct ptdump_info *info); }; void ptdump_walk(struct seq_file *s, struct ptdump_info *info); diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 8761a70f916f..d531e24ea0b2 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -346,6 +346,7 @@ static struct ptdump_info kernel_ptdump_info = { .mm = &init_mm, .markers = address_markers, .base_addr = PAGE_OFFSET, + .ptdump_walk = &ptdump_walk, }; void ptdump_check_wx(void) diff --git a/arch/arm64/mm/ptdump_debugfs.c b/arch/arm64/mm/ptdump_debugfs.c index 68bf1a125502..7564519db1e6 100644 --- a/arch/arm64/mm/ptdump_debugfs.c +++ b/arch/arm64/mm/ptdump_debugfs.c @@ -10,7 +10,8 @@ static int ptdump_show(struct seq_file *m, void *v) struct ptdump_info *info = m->private; get_online_mems(); - ptdump_walk(m, info); + if (info->ptdump_walk) + info->ptdump_walk(m, info); put_online_mems(); return 0; } From patchwork Wed Sep 27 11:25:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 146662 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp4141074vqu; Fri, 29 Sep 2023 09:04:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGU9RDecKxy/y40BzL4ojS4pigheJ4FTMhDtFs7EK6mvK2gBAfnRn4UsUND2yQmxzQAYmww X-Received: by 2002:a05:6358:722:b0:143:7d73:6e63 with SMTP id e34-20020a056358072200b001437d736e63mr4435992rwj.2.1696003448109; Fri, 29 Sep 2023 09:04:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696003448; cv=none; d=google.com; s=arc-20160816; b=JpKHfN/fawXZ74C1NsZWoSGi0hdHfW4nB4gfT5ND6Yy2t1bJZ4kQn20QP52et2eBTa gK4tJHm1TuVnyheo2rHhLoU56jBgEaY+MikaJr306LyI+NsS8KDK5iHfxHfa2RTZ8uCj xUbin7JxPh5fP4yenbR2Y2aN8oHOI9aq4t8hgdryfPT3SQSxUxsb+clxc10IYWpW+BPw 9CZEZ8+3MVJ3vyugoqeWt/g7BECzRC8JhzF4brOQn7dLilAS4/VSrI8xf/APy/TF9aLh N9dnwPD3v4I2nE38pPwn/G123RlKXgA5DH5vKW/tK3r2/nQGVWLh3Ilf4ro/W1ZfSV/6 ljaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=pCmgpMBJwGuXO7/jIj16/rriK8J2TUjW9FV16THuDL4=; fh=yikR9HT1wx5LLj7DvfR9kbE/RatD/mnQgNUS++qRsJM=; b=rOLGGyOqiYDxcIzEgEEUy21h5eYFflkVvqAiTzLdlaD0KkON8KkCHFIfcfSc71uZw8 x3wtj7kDn5svk+al5ves2w41R9U6V00kvT9gccnEdqSOdMHkfMRNfprRSpW5acutOv/G VXLFWjrJBevwYapdW/muW9JNWsHapW8ULTqQAy3Snac1BZMS07pwp2Erio/ZRy+tC4aX 9wlUCRVDPvwRloCooLGfPWmm0yWRP1FxmSlzOx6mzwkdiqgY8F9KQZXwc/JdbN38tUbT 6rZ7k4dvN0oDkD+R6FF50xZv442oP04l9SnaeRPSjaSyr7I2Sex4olv88pvzEzebnz5l CPnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=xvYwAFWg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id j2-20020a63e742000000b00577646e2b6bsi21362813pgk.206.2023.09.29.09.04.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 09:04:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=xvYwAFWg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id C0B338033356; Wed, 27 Sep 2023 04:26:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231548AbjI0L0F (ORCPT + 22 others); Wed, 27 Sep 2023 07:26:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231488AbjI0LZv (ORCPT ); Wed, 27 Sep 2023 07:25:51 -0400 Received: from mail-wr1-x449.google.com (mail-wr1-x449.google.com [IPv6:2a00:1450:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3F90193 for ; Wed, 27 Sep 2023 04:25:47 -0700 (PDT) Received: by mail-wr1-x449.google.com with SMTP id ffacd0b85a97d-31f3cfe7269so8348442f8f.2 for ; Wed, 27 Sep 2023 04:25:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695813945; x=1696418745; darn=vger.kernel.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=pCmgpMBJwGuXO7/jIj16/rriK8J2TUjW9FV16THuDL4=; b=xvYwAFWgBOpMZn2A/TQ/TPaARJvAlsz+gsbyM13hZEcknjHq1/AVWslOBv+4i93X0m GPuXiF/PeXKaxmP4geuPMPHmMAKYfqj2u97qBZVweCtX3gesXTGVdTOUs23VM7VopKXP lAz2m8kt/n08eql+fEGXstU9fZcQtfY1p3afSfX2kJ4zJWL6j9snvD41EtbkHmr03lSZ 2SnYpQhHTG6ZgUCkbKQfAGDnbPC2YjL+6+Ut3TGpOnFOy2B/qst/pzcqe8lnnE4zzD6X D5nhr6Mt7LnIGr1lkZKvWLmOrQtHXfXPZYUe7L/eXrSudHXSa5o8O8SqU35D5e6mv3lg nHzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695813945; x=1696418745; 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=pCmgpMBJwGuXO7/jIj16/rriK8J2TUjW9FV16THuDL4=; b=MYfyDtjd1i7CT7hbmARlkV9QOSWcmPci4vZTBowdRi4/mDK926cGNsIqFCmA9IH0UV rg2cLwah0cHlRDB8U3JXe8Pb+3oEn6OsoSdjnktWZAt1mdHoCNP1Z1uwQKp4onNue/CP aXd85QFD+4EGM3qCL/8pw+yVRjw4mzqTnGsLRVky2OFiqG3Dk/ltxA+ebM2mzWHNRCLl cx08ELHKrMtDB5Fidsl79BY7BBb0DGui0qY7i7Kx8g9jw6qhM8cU7dhImjOfkZVb9z2R vnn9jJvGyUUghjktvS9Tn827mSdYNdLB7bjKCqweDXNMK/rLb5aa16ANiJbDlkxCc+3F Eh+A== X-Gm-Message-State: AOJu0YxgHRBooQKAoQ4jEMKeVtAl+w8IKga02IRQWjhlGXMJu4KobBE6 FlvrD3Nny2mySjDNoIh1CCgDaZKZJkhc4o6dWJjz0X2v99Oo6LRioEalhiOznae19YLBtBSzyai FcaxoYwZkPryimZCLXYammcd1kAx6CRwE/UraiB3rkpwjOZIu4j4wUo1h3/rDrYrnbvQ4AueG3T 0EOAlwp4YSXg== X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:adf:e7c7:0:b0:31f:97e2:a930 with SMTP id e7-20020adfe7c7000000b0031f97e2a930mr7475wrn.1.1695813945480; Wed, 27 Sep 2023 04:25:45 -0700 (PDT) Date: Wed, 27 Sep 2023 11:25:10 +0000 In-Reply-To: <20230927112517.2631674-1-sebastianene@google.com> Mime-Version: 1.0 References: <20230927112517.2631674-1-sebastianene@google.com> X-Mailer: git-send-email 2.42.0.515.g380fc7ccd1-goog Message-ID: <20230927112517.2631674-5-sebastianene@google.com> Subject: [PATCH 04/11] KVM: arm64: Move pagetable definitions to common header From: Sebastian Ene To: linux-kernel@vger.kernel.org Cc: kernel-team@android.com, will@kernel.org, ryan.roberts@arm.com, mark.rutland@arm.com, maz@kernel.org, vdonnefort@google.com, Sebastian Ene X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 27 Sep 2023 04:26:25 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778388511331078572 X-GMAIL-MSGID: 1778388511331078572 In preparation for using the stage-2 definitions in ptdump, move some of these macros in the common header. Signed-off-by: Sebastian Ene --- arch/arm64/include/asm/kvm_pgtable.h | 42 ++++++++++++++++++++++++++++ arch/arm64/kvm/hyp/pgtable.c | 42 ---------------------------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h index be615700f8ac..913f34d75b29 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -45,6 +45,48 @@ typedef u64 kvm_pte_t; #define KVM_PHYS_INVALID (-1ULL) +#define KVM_PTE_LEAF_ATTR_LO GENMASK(11, 2) + +#define KVM_PTE_LEAF_ATTR_LO_S1_ATTRIDX GENMASK(4, 2) +#define KVM_PTE_LEAF_ATTR_LO_S1_AP GENMASK(7, 6) +#define KVM_PTE_LEAF_ATTR_LO_S1_AP_RO \ + ({ cpus_have_final_cap(ARM64_KVM_HVHE) ? 2 : 3; }) +#define KVM_PTE_LEAF_ATTR_LO_S1_AP_RW \ + ({ cpus_have_final_cap(ARM64_KVM_HVHE) ? 0 : 1; }) +#define KVM_PTE_LEAF_ATTR_LO_S1_SH GENMASK(9, 8) +#define KVM_PTE_LEAF_ATTR_LO_S1_SH_IS 3 +#define KVM_PTE_LEAF_ATTR_LO_S1_AF BIT(10) + +#define KVM_PTE_LEAF_ATTR_LO_S2_MEMATTR GENMASK(5, 2) +#define KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R BIT(6) +#define KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W BIT(7) +#define KVM_PTE_LEAF_ATTR_LO_S2_SH GENMASK(9, 8) +#define KVM_PTE_LEAF_ATTR_LO_S2_SH_IS 3 +#define KVM_PTE_LEAF_ATTR_LO_S2_AF BIT(10) + +#define KVM_PTE_LEAF_ATTR_HI GENMASK(63, 50) + +#define KVM_PTE_LEAF_ATTR_HI_SW GENMASK(58, 55) + +#define KVM_PTE_LEAF_ATTR_HI_S1_XN BIT(54) + +#define KVM_PTE_LEAF_ATTR_HI_S2_XN BIT(54) + +#define KVM_PTE_LEAF_ATTR_HI_S1_GP BIT(50) + +#define KVM_PTE_LEAF_ATTR_S2_PERMS (KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R | \ + KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W | \ + KVM_PTE_LEAF_ATTR_HI_S2_XN) + +#define KVM_INVALID_PTE_OWNER_MASK GENMASK(9, 2) +#define KVM_MAX_OWNER_ID 1 + +/* + * Used to indicate a pte for which a 'break-before-make' sequence is in + * progress. + */ +#define KVM_INVALID_PTE_LOCKED BIT(10) + static inline bool kvm_pte_valid(kvm_pte_t pte) { return pte & KVM_PTE_VALID; diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 256654b89c1e..67fa122c6028 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -17,48 +17,6 @@ #define KVM_PTE_TYPE_PAGE 1 #define KVM_PTE_TYPE_TABLE 1 -#define KVM_PTE_LEAF_ATTR_LO GENMASK(11, 2) - -#define KVM_PTE_LEAF_ATTR_LO_S1_ATTRIDX GENMASK(4, 2) -#define KVM_PTE_LEAF_ATTR_LO_S1_AP GENMASK(7, 6) -#define KVM_PTE_LEAF_ATTR_LO_S1_AP_RO \ - ({ cpus_have_final_cap(ARM64_KVM_HVHE) ? 2 : 3; }) -#define KVM_PTE_LEAF_ATTR_LO_S1_AP_RW \ - ({ cpus_have_final_cap(ARM64_KVM_HVHE) ? 0 : 1; }) -#define KVM_PTE_LEAF_ATTR_LO_S1_SH GENMASK(9, 8) -#define KVM_PTE_LEAF_ATTR_LO_S1_SH_IS 3 -#define KVM_PTE_LEAF_ATTR_LO_S1_AF BIT(10) - -#define KVM_PTE_LEAF_ATTR_LO_S2_MEMATTR GENMASK(5, 2) -#define KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R BIT(6) -#define KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W BIT(7) -#define KVM_PTE_LEAF_ATTR_LO_S2_SH GENMASK(9, 8) -#define KVM_PTE_LEAF_ATTR_LO_S2_SH_IS 3 -#define KVM_PTE_LEAF_ATTR_LO_S2_AF BIT(10) - -#define KVM_PTE_LEAF_ATTR_HI GENMASK(63, 50) - -#define KVM_PTE_LEAF_ATTR_HI_SW GENMASK(58, 55) - -#define KVM_PTE_LEAF_ATTR_HI_S1_XN BIT(54) - -#define KVM_PTE_LEAF_ATTR_HI_S2_XN BIT(54) - -#define KVM_PTE_LEAF_ATTR_HI_S1_GP BIT(50) - -#define KVM_PTE_LEAF_ATTR_S2_PERMS (KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R | \ - KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W | \ - KVM_PTE_LEAF_ATTR_HI_S2_XN) - -#define KVM_INVALID_PTE_OWNER_MASK GENMASK(9, 2) -#define KVM_MAX_OWNER_ID 1 - -/* - * Used to indicate a pte for which a 'break-before-make' sequence is in - * progress. - */ -#define KVM_INVALID_PTE_LOCKED BIT(10) - struct kvm_pgtable_walk_data { struct kvm_pgtable_walker *walker; From patchwork Wed Sep 27 11:25:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 145333 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp2562447vqu; Wed, 27 Sep 2023 04:37:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHuCUvbDRaiM6No0Xtm2CS/QAMCNir6PFKQ3U57cH6RMfUvt6RlnQE2l8dkAYVs0Lud2fGm X-Received: by 2002:a05:6358:991e:b0:13f:2833:bf41 with SMTP id w30-20020a056358991e00b0013f2833bf41mr2141568rwa.23.1695814647367; Wed, 27 Sep 2023 04:37:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695814647; cv=none; d=google.com; s=arc-20160816; b=n8r5k28Z0ubZRiSHouRKzlj5atgApkDlRaWAxupzlrVouRlTdGApI/hknX/IRXmLNV 9EQddrDHjEa7Rg7/9hZqjlEDVO2PufUFfDhuFG34kiPbfDQhW7EzGMnv6weG/zcjF+sd rXVJPydAEP9MvddcD8cWswKErhPF6Q9jQFFnjsMdDVRIaQtY/+Rv6RlZow2RRcKCLV+O ebTP8T5w8QsogeCCHvC9CNQl+q2KEWEc0YRJqBOy5S6XYISOjTYue2IOqaGJjuEp6YkN NPB3ImYy1sjYSIKeUw3Z+lkorrliYwHkHpELyrUHEQZHowsZcUFdkulF9aGIziZBQa84 Zz5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=sg+l4AZqIjzZdAaAwEVRBA1XU/OEUMwb2p3CABcyD1c=; fh=yikR9HT1wx5LLj7DvfR9kbE/RatD/mnQgNUS++qRsJM=; b=bPLtXD2VvWhteMfzL3vVrYilPkHDlzczGN1LU+7MGWnOZjVVUC3OtgW+vfKrXuFNB8 ld7HWUSRmDYb7zDg3Iz2673aRU3ujELNFoo9wbxI45zb5GN5upANoiX6dBJBMjlnAcum hYOSZvra7a6YntIiA5mbnhyhd3iKIRQLzpjUU4+NL/FBSHjFaODLnSiMz5PPowseOP27 934s5ELRIGoY9XU5v4MJbrDfMPJfCbfZ4GGG3g3wKfSuPh8djDUTiEFT1HDcoQKZRqka l2P/POrVCiN5geQHzeg+iNbheo2eR5kC254qdbmSfS+D6i0ALPommxUZ0o0hW8F1HQuS pR8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=jOKDwqBt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id s16-20020a656450000000b0056c4189d6d9si15396015pgv.836.2023.09.27.04.37.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 04:37:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=jOKDwqBt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 01A5180AF25A; Wed, 27 Sep 2023 04:26:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231520AbjI0L0J (ORCPT + 22 others); Wed, 27 Sep 2023 07:26:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231477AbjI0LZx (ORCPT ); Wed, 27 Sep 2023 07:25:53 -0400 Received: from mail-wr1-x44a.google.com (mail-wr1-x44a.google.com [IPv6:2a00:1450:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 505B71B6 for ; Wed, 27 Sep 2023 04:25:49 -0700 (PDT) Received: by mail-wr1-x44a.google.com with SMTP id ffacd0b85a97d-3200597bfc5so8329904f8f.2 for ; Wed, 27 Sep 2023 04:25:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695813947; x=1696418747; darn=vger.kernel.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=sg+l4AZqIjzZdAaAwEVRBA1XU/OEUMwb2p3CABcyD1c=; b=jOKDwqBtMbeCeYiTjWu4QKR1urFyjADm+DhAq3yU9D4EPymCSj0CyrZ5D8ZeCsHRSA rcu+dZD9uWUoVPRF0V80XsleivemJAe3tu/OirdbOXXT75G4bNTChWBfD61VpjKvs7r/ ThOb/17hfeG1Y9KFoNxIUILqtoby/UwdjCGGWeskQ0IYnRNZOhCTiR1EXTQ9+YoDLkVv tZkD5qyC/PI3kROAvBY9hu2edJV1JdvnXp3WPgwUnwSZOp6+00QgjCF3VjFCa1+XP1nY 4huVFdcllD21Hej5vR0zo6TywNjcRWXhXilFx+To1A6mjVby2/WAN2MV22hAe6NrkzAw 9+bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695813947; x=1696418747; 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=sg+l4AZqIjzZdAaAwEVRBA1XU/OEUMwb2p3CABcyD1c=; b=KHNW3sMgZQEvPrWuHMQgZmdpuqBv2pS3hIJoddPirBoQ3EwjFAlNUIrVJyfvvAnkxR VnmDX4vWCNjj2dTH2RcETmIXb0SB1/CA+ps0hBA8ZGlv2/Zh3GKq9hFriVQx3brwE4dU k6pl+SpWrCXoIFSBHHs7tkwZRbPTZC8vQ18lRDjg8VE8eT7S0eJxD73rFdwDzzWb5Bqc g/Uk1vhGHD9ufAItKyoRtjJ0qo5BNwB6wslsKkYCGdLto6Fo59GiOPMB/xRPE+dk3w4T OnFBFqT3kztB2Ljgq+wMaS5YMPTix2kPO7PwPMu7fMhqIUBIfu4IXqrl/XenKeLqMRB5 NAgw== X-Gm-Message-State: AOJu0YzGNb6Hg7diXHR5M536fxTsBkBBuPCG49/nmS771rXnarY27l3W tS3bd3AiiAcsiH2INhhLYgdoYmL+HBlBTxU/Xcsw0aFhyXtNHCX16zpT0jiuYuwHmG0oAuox5nB qs+Ig5mhwySuADWB4al/AbxqKJUq29eTIbKgZwdqsaKBn9Tv/nZWEy9pPVeoYO9kJsK+SfSrBat KSJwjg1KFV3Q== X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:a5d:4145:0:b0:31f:f72b:520c with SMTP id c5-20020a5d4145000000b0031ff72b520cmr7783wrq.6.1695813947441; Wed, 27 Sep 2023 04:25:47 -0700 (PDT) Date: Wed, 27 Sep 2023 11:25:11 +0000 In-Reply-To: <20230927112517.2631674-1-sebastianene@google.com> Mime-Version: 1.0 References: <20230927112517.2631674-1-sebastianene@google.com> X-Mailer: git-send-email 2.42.0.515.g380fc7ccd1-goog Message-ID: <20230927112517.2631674-6-sebastianene@google.com> Subject: [PATCH 05/11] arm64: ptdump: Introduce stage-2 pagetables format description From: Sebastian Ene To: linux-kernel@vger.kernel.org Cc: kernel-team@android.com, will@kernel.org, ryan.roberts@arm.com, mark.rutland@arm.com, maz@kernel.org, vdonnefort@google.com, Sebastian Ene X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 27 Sep 2023 04:26:38 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778190539797660512 X-GMAIL-MSGID: 1778190539797660512 Add an array which holds human readable information about the format of a stage-2 descriptor. The array is then used by the descriptor parser to extract information about the memory attributes. Signed-off-by: Sebastian Ene --- arch/arm64/mm/ptdump.c | 91 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index d531e24ea0b2..8c4f06ca622a 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -24,6 +24,7 @@ #include #include #include +#include enum address_markers_idx { @@ -171,6 +172,66 @@ static const struct prot_bits pte_bits[] = { } }; +static const struct prot_bits stage2_pte_bits[] = { + { + .mask = PTE_VALID, + .val = PTE_VALID, + .set = " ", + .clear = "F", + }, { + .mask = KVM_PTE_LEAF_ATTR_HI_S2_XN, + .val = KVM_PTE_LEAF_ATTR_HI_S2_XN, + .set = "XN", + .clear = " ", + }, { + .mask = KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R, + .val = KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R, + .set = "R", + .clear = " ", + }, { + .mask = KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W, + .val = KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W, + .set = "W", + .clear = " ", + }, { + .mask = KVM_PTE_LEAF_ATTR_LO_S2_AF, + .val = KVM_PTE_LEAF_ATTR_LO_S2_AF, + .set = "AF", + .clear = " ", + }, { + .mask = PTE_NG, + .val = PTE_NG, + .set = "FnXS", + .clear = " ", + }, { + .mask = PTE_CONT, + .val = PTE_CONT, + .set = "CON", + .clear = " ", + }, { + .mask = PTE_TABLE_BIT, + .val = PTE_TABLE_BIT, + .set = " ", + .clear = "BLK", + }, { + .mask = KVM_PGTABLE_PROT_SW0, + .val = KVM_PGTABLE_PROT_SW0, + .set = "SW0", /* PKVM_PAGE_SHARED_OWNED */ + }, { + .mask = KVM_PGTABLE_PROT_SW1, + .val = KVM_PGTABLE_PROT_SW1, + .set = "SW1", /* PKVM_PAGE_SHARED_BORROWED */ + }, { + .mask = KVM_PGTABLE_PROT_SW2, + .val = KVM_PGTABLE_PROT_SW2, + .set = "SW2", + }, { + .mask = KVM_PGTABLE_PROT_SW3, + .val = KVM_PGTABLE_PROT_SW3, + .set = "SW3", + }, +}; + struct pg_level { const struct prot_bits *bits; const char *name; @@ -202,6 +263,30 @@ static struct pg_level pg_level[] = { }, }; +static struct pg_level stage2_pg_level[] = { + { /* pgd */ + .name = "PGD", + .bits = stage2_pte_bits, + .num = ARRAY_SIZE(stage2_pte_bits), + }, { /* p4d */ + .name = "P4D", + .bits = stage2_pte_bits, + .num = ARRAY_SIZE(stage2_pte_bits), + }, { /* pud */ + .name = (CONFIG_PGTABLE_LEVELS > 3) ? "PUD" : "PGD", + .bits = stage2_pte_bits, + .num = ARRAY_SIZE(stage2_pte_bits), + }, { /* pmd */ + .name = (CONFIG_PGTABLE_LEVELS > 2) ? "PMD" : "PGD", + .bits = stage2_pte_bits, + .num = ARRAY_SIZE(stage2_pte_bits), + }, { /* pte */ + .name = "PTE", + .bits = stage2_pte_bits, + .num = ARRAY_SIZE(stage2_pte_bits), + }, +}; + static void dump_prot(struct pg_state *st, const struct prot_bits *bits, size_t num) { @@ -340,6 +425,12 @@ static void __init ptdump_initialize(void) if (pg_level[i].bits) for (j = 0; j < pg_level[i].num; j++) pg_level[i].mask |= pg_level[i].bits[j].mask; + + for (i = 0; i < ARRAY_SIZE(stage2_pg_level); i++) + if (stage2_pg_level[i].bits) + for (j = 0; j < stage2_pg_level[i].num; j++) + stage2_pg_level[i].mask |= + stage2_pg_level[i].bits[j].mask; } static struct ptdump_info kernel_ptdump_info = { From patchwork Wed Sep 27 11:25:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 145366 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp2607498vqu; Wed, 27 Sep 2023 05:58:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH3EBxSa6MmM0dY8AezZsHBvZou0mX4HyVLRar4lajeFmhhKJt7YXQmlco+I6wVzMDKCIub X-Received: by 2002:a05:6830:18cb:b0:6bc:f6d0:87d9 with SMTP id v11-20020a05683018cb00b006bcf6d087d9mr2146357ote.5.1695819503449; Wed, 27 Sep 2023 05:58:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695819503; cv=none; d=google.com; s=arc-20160816; b=yaB+8cH9S22JECGYBMQzO43mh3lhEFZhfrBmGPJP6rEvVXa2sx2DIf9Cja2Kp2icSC hFHz1KNMQSCdD0XRmNudVSQcrfYcZSPQU+2QJN0+4IdHFb/EYxoZStkWEFzoBzjP7hJW tlY4ZP0B0MazSdt6YDpgkylHTYCj193xTszLJJgVV8ZRDjHX0lry+3r2uCb7fdkD0sw7 E+Ws02uCAddW/mHdqp3VfcEUfa4UdIFcfQ8t0uPBcWMk7TPWlgfnNUgsoPl+1O4ly6Dl MfeAG40AOrEQVvY2F//SS8mROomPXBKTOLjbdeewWmVSPV4a0qqkaXAL/s5cP5icHhfK 3kgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=fj32EN9jrUIkb2wzfxrKtc2Y3Ax+u71fUp4xcpv8B/Q=; fh=yikR9HT1wx5LLj7DvfR9kbE/RatD/mnQgNUS++qRsJM=; b=ZughfvjKiXUn2KMf08kF71/3NfpZWaRwMRZ0Nbe/LdKd3lbmWzNkbwMgRb90ABf7kA TAgULe1jmCzJsZKLoLvE4kO3vIS8yHGK9JDUUDicW5Uoo7b/lqMQZsHRli9X63fU45qM foyV8tpdI0DSYnXmjGQMxwKTWvT2lZJBxnuHaElTbVCoKOs9uzo0PbhJJUh1yiTZbkcf MtKg5Z28HbpahXD3ZghGIYZljs5Y4m62LUeF0KUT7VdbmZKPk6l8RAssjphDPJ1J/F2i mW44RPknl24HUZDrlhUB7GyXMAhcg9/O6ks3RxrcEyHy17AT/QFWxyqkLsyQ4QlRcgk2 be1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Tdvtmnog; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id o8-20020a056a001bc800b00690d02ac9acsi15118888pfw.77.2023.09.27.05.58.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 05:58:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Tdvtmnog; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 3E81080ECFA3; Wed, 27 Sep 2023 04:26:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231574AbjI0L0L (ORCPT + 22 others); Wed, 27 Sep 2023 07:26:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231460AbjI0L0C (ORCPT ); Wed, 27 Sep 2023 07:26:02 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FA0B1B5 for ; Wed, 27 Sep 2023 04:25:51 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a1eb48d346so60705237b3.3 for ; Wed, 27 Sep 2023 04:25:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695813950; x=1696418750; darn=vger.kernel.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=fj32EN9jrUIkb2wzfxrKtc2Y3Ax+u71fUp4xcpv8B/Q=; b=TdvtmnogFqxrm62pBVa4QdvHDHxnVRzB/GlMjAWwqwnZZTdDgOaDI7tacsyk7xHbxU 19UIChUc5KojmO2Rt5T9vKlTqnKnmtkujA+dM2qR+HGQ7V5aX8v9qdV5jnXMkYFCp7h0 Hh3BMApEE3XfQcr645tLOxcN/y+McWep0y0FslgjCT4Xddu9Dhui6j2w9DsY4Pz9L2tJ xfj13VwHgqKHR2XHQ8YKx1pRDLfo89qGYV7+N/q8zVH9HYEiIiiX/zCQGZIV8KbXhCZK IaplWuAW7zUjrf7cXcwHBYvxwGoZzF8nKlu225z/Zndn4slHsbs+v4s2CXACOqoSwhU4 twAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695813950; x=1696418750; 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=fj32EN9jrUIkb2wzfxrKtc2Y3Ax+u71fUp4xcpv8B/Q=; b=gi7dP/HjdSqShHIYW76FREHHkbKAHXuRVfaV6a5r1UkV/YfVnRB/DMQlpfrtj7uezJ GObcWTgg9afrv6r83nx/SIBSz8JIUebA2l4obbyo6qYpkvxq3z9zkgd6cXQf60nMmdYt dJf2qdWSPwvh2saVd+LdzKLgfqe6uKCJnp+jaIiTLLWN1zbKxP+VGuo4mewEwKSctVc9 omXcF6blILMwlgZf+dddPyJNmlqLltJ08ZfcWlfQavHTbrSoMDxyVDe8mzPmC8erAehN X+XsMdFTy1f3mqX3OpWKQUdxaR1cBUT/HrO+Uukx7TN8fH+e/JhMM6jsjI/3WyoiJc6k 4qBg== X-Gm-Message-State: AOJu0Yxh8w7lMXhUIoscXO52//E3qHDH1Vhyme4oX1IqUiIpCpWlWPze qBFQENYF08qA98ovOJMYMgNmO5aZ5+YmlDIMFqJ/AepO2HP0XH4D7JKV0KwCnQa6vdBo9yJ9p0K 6nmY7Aq2L0UZeQchoWEu2+QAanVEQ1KPqQte2rL07XjMotd2pTb4JcUXaAzCRCRsULPTYhQLiag TcMUx+lWV+uA== X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:a05:6902:1613:b0:d80:ff9:d19e with SMTP id bw19-20020a056902161300b00d800ff9d19emr23618ybb.9.1695813950463; Wed, 27 Sep 2023 04:25:50 -0700 (PDT) Date: Wed, 27 Sep 2023 11:25:12 +0000 In-Reply-To: <20230927112517.2631674-1-sebastianene@google.com> Mime-Version: 1.0 References: <20230927112517.2631674-1-sebastianene@google.com> X-Mailer: git-send-email 2.42.0.515.g380fc7ccd1-goog Message-ID: <20230927112517.2631674-7-sebastianene@google.com> Subject: [PATCH 06/11] arm64: ptdump: Register a debugfs entry for the host stage-2 page-tables From: Sebastian Ene To: linux-kernel@vger.kernel.org Cc: kernel-team@android.com, will@kernel.org, ryan.roberts@arm.com, mark.rutland@arm.com, maz@kernel.org, vdonnefort@google.com, Sebastian Ene X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 27 Sep 2023 04:26:51 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778195631452277382 X-GMAIL-MSGID: 1778195631452277382 Initialize the structures used to keep the state of the stage-2 ptdump walker. To satisfy the ptdump API for parsing no VMA regions, initialize a memory structure. Since we are going to parse a snapshot of the host stage-2 paget-tables we don't rely on the locking from the memory structure. Signed-off-by: Sebastian Ene --- arch/arm64/kvm/Kconfig | 12 ++++++++++++ arch/arm64/mm/ptdump.c | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/arch/arm64/kvm/Kconfig b/arch/arm64/kvm/Kconfig index 83c1e09be42e..2974bb5c4838 100644 --- a/arch/arm64/kvm/Kconfig +++ b/arch/arm64/kvm/Kconfig @@ -71,4 +71,16 @@ config PROTECTED_NVHE_STACKTRACE If unsure, or not using protected nVHE (pKVM), say N. +config NVHE_EL2_PTDUMP_DEBUGFS + bool "Present the stage-2 pagetables to debugfs" + depends on NVHE_EL2_DEBUG && PTDUMP_DEBUGFS + help + Say Y here if you want to show the pKVM host stage-2 kernel pagetable + layout in a debugfs file. This information is only useful for kernel developers + who are working in architecture specific areas of the kernel. + It is probably not a good idea to enable this feature in a production + kernel. + + If in doubt, say N. + endif # VIRTUALIZATION diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 8c4f06ca622a..25c0640e82aa 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -469,6 +469,21 @@ void ptdump_check_wx(void) pr_info("Checked W+X mappings: passed, no W+X pages found\n"); } +#ifdef CONFIG_NVHE_EL2_PTDUMP_DEBUGFS +static struct ptdump_info stage2_kernel_ptdump_info; +static struct addr_marker ipa_address_markers[] = { + { 0, "IPA start"}, + { -1, "IPA end"}, + { -1, NULL}, +}; + +/* Initialize a memory structure used by ptdump to walk the no-VMA region */ +static struct mm_struct ipa_init_mm = { + .mm_mt = MTREE_INIT_EXT(mm_mt, MM_MT_FLAGS, + ipa_init_mm.mmap_lock), +}; +#endif /* CONFIG_NVHE_EL2_PTDUMP_DEBUGFS */ + static int __init ptdump_init(void) { address_markers[PAGE_END_NR].start_address = PAGE_END; @@ -477,6 +492,17 @@ static int __init ptdump_init(void) #endif ptdump_initialize(); ptdump_debugfs_register(&kernel_ptdump_info, "kernel_page_tables"); + +#ifdef CONFIG_NVHE_EL2_PTDUMP_DEBUGFS + stage2_kernel_ptdump_info = (struct ptdump_info) { + .markers = ipa_address_markers, + .mm = &ipa_init_mm, + }; + + init_rwsem(&ipa_init_mm.mmap_lock); + ptdump_debugfs_register(&stage2_kernel_ptdump_info, + "host_stage2_kernel_page_tables"); +#endif return 0; } device_initcall(ptdump_init); From patchwork Wed Sep 27 11:25:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 145334 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp2562528vqu; Wed, 27 Sep 2023 04:37:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IENfmE/8hQ4IAIFjn2Qt1sJc6wSo56OGeGUfAUKifPcdEaa2HoD/O4bn1GTooOH1dw7PoRc X-Received: by 2002:a05:6871:79f:b0:1d5:bda7:130e with SMTP id o31-20020a056871079f00b001d5bda7130emr2028266oap.18.1695814654699; Wed, 27 Sep 2023 04:37:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695814654; cv=none; d=google.com; s=arc-20160816; b=xTH/Dww7Mg2nAXcZJPv4T5tI3Uh1fg7xWzFgbzue0eqbJqJ7hZdTYP/dBY5w0Ebt/8 ArhA6wdQAZyoybwfehr+UfHmGWo4K0OgKPUw+dW9OFf3WDfBer+z1+70VdNb13riDELk e2rhxKkyhgmB3nWDvSCQuDKoO503pqqXPtp/peZWQZs8o+BjdxiDuZEYOnd4WcWS77Ph 4uZiKGDza4bk89f0m6vzM1fVujk8rrpO8EOgNseRL6PmicCSIEa2thJxj/hGjqjpsqDB PJa3egB8RGBA74PpAUvOHDTMXMb8prrpp3JfEjjZS+MaJKaHVDRlIU/w5vK2v5a9fLnb cecQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=SQzoJulYm3NuHJDD1oClvJ2axH95rZ3WpVD9Pkot9xI=; fh=yikR9HT1wx5LLj7DvfR9kbE/RatD/mnQgNUS++qRsJM=; b=fljWUIEn9aNLQv3A4CRE+fLU3boepxC7ar0m2bZjjQ9WpluRy4w5+uROFmmBPG3p2g SJCy2QtYECoy4Aqol6kMFpGYL5DjmSPUtE3RVKKcLTat92c5LaY8Gstr22htqLUfbVFy tHXKuWEiWcrvdmybcFOE2hEE6WCnivsZHlzmTXVwav2dWLWGuIuzZnsdQNMUmvBQCeTj kr5/Ys0UvAPLC+IAu+D9ZysRa+J6VV4rV3HrkkOJ02YmVrRVlyArveOzJnI7mvAaRIZb hBBd5Fpu1xRgjTa86wiSx5nhjak0s16qvzwSsKnJfJc6bLwN7DRTqZ6ysFVfjQM2N7nz z4hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=e+wc4G9j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id i67-20020a639d46000000b0057c3103bf15si14688096pgd.277.2023.09.27.04.37.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 04:37:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=e+wc4G9j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 835A9803D593; Wed, 27 Sep 2023 04:26:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231500AbjI0L0O (ORCPT + 22 others); Wed, 27 Sep 2023 07:26:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231521AbjI0L0D (ORCPT ); Wed, 27 Sep 2023 07:26:03 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8B31CDF for ; Wed, 27 Sep 2023 04:25:53 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-59f7d4bbfc7so132690907b3.3 for ; Wed, 27 Sep 2023 04:25:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695813953; x=1696418753; darn=vger.kernel.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=SQzoJulYm3NuHJDD1oClvJ2axH95rZ3WpVD9Pkot9xI=; b=e+wc4G9jv5/mzBgU/i3OKBcFlMeumBaluQUbWN9e76K3ffHxVWZpo4Vycp4VsxsrGv Uiz0k1VfJmCn96tvXEvRbQ/eyLk6l4fscmkWGcTF2TstZfIg1vq/avIHnzOCRSmWucob M9MUmEbKreJf5pkm7Z5VPsw2CWuiveAd46TzLKbba3/IieTsELwbzqAbqkNbJ13WsoB6 fwTC2jDvnfqHFR8GzkmtNPRLzfgL4CjARkb0MjBYKJySzcWqB8rSkpg9kUjKl/lrlFS9 0eaD19L0Ruzr3hxPkASbmIMBVAG4iZT0r4DMTgiCz2lZPIlm5pAAlXYZ4lEgUtaknFcR 8p1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695813953; x=1696418753; 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=SQzoJulYm3NuHJDD1oClvJ2axH95rZ3WpVD9Pkot9xI=; b=geQYsFoH+NN7ZXuZLxKEnpgrp/1e4MLCIiG7ivSWWCbDgRCbWkY4+WLyPzNVeRF2XI ITzIeXCHXgtPtS9TQIVTAM/XXRllPQXeM3b49k5WBTkLpvjpaEbQyeMSyKwHWw0bFrIW TaUzx6esZKpCGGi6p2fSNPe9JTmqbHnTMm2ukbpm95SC7kY12ApY9wZ1RUQY5hHDUXt0 6LVPZuWjnWf1+NKtQ5+8rMvEdFL+Vt7Jx1tI+mxZy3NP9r5oHGOSSeaWdSEL6M81pPfH c5ilQU0pU44trSOyXaV3hJ9/nbho9v5RleNL++j3qWD3eFMrbBiLxhjjDlemVtH/o9PN T50A== X-Gm-Message-State: AOJu0Yzok7RiL6lqqeSJIDTJgPDuGdq015PZQkwR/uLAVDlBxcfbSCqh AMjSRct508iDpkL4tOTta3CZ5nVI18xL6HTPPqRs+bIGKH9JbiC3r4zn+7dms+abolK0nDnP4YM Ak25YxFltiFz04uwqMNLzoax6aMA0kEggVAl0ulGyPdK56nh1K1oGXkgq5aevx+oiLt7FFWDmUL OJPozvJIVsRQ== X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:a81:b709:0:b0:59b:f138:c835 with SMTP id v9-20020a81b709000000b0059bf138c835mr26425ywh.5.1695813952895; Wed, 27 Sep 2023 04:25:52 -0700 (PDT) Date: Wed, 27 Sep 2023 11:25:13 +0000 In-Reply-To: <20230927112517.2631674-1-sebastianene@google.com> Mime-Version: 1.0 References: <20230927112517.2631674-1-sebastianene@google.com> X-Mailer: git-send-email 2.42.0.515.g380fc7ccd1-goog Message-ID: <20230927112517.2631674-8-sebastianene@google.com> Subject: [PATCH 07/11] arm64: ptdump: Snapshot the host stage-2 pagetables From: Sebastian Ene To: linux-kernel@vger.kernel.org Cc: kernel-team@android.com, will@kernel.org, ryan.roberts@arm.com, mark.rutland@arm.com, maz@kernel.org, vdonnefort@google.com, Sebastian Ene X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 27 Sep 2023 04:26:56 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778190547644662161 X-GMAIL-MSGID: 1778190547644662161 Introduce callbacks invoked when the debugfs entry is accessed from the userspace and store them in the ptdump state structure. Call these functions when the ptdump registered entry with debugfs is open/closed. When we open the entry we allocate memory for the host stage-2 snapshot, we share it with the hypervisor and then we issue the hvc to copy the page-tables to the shared buffer. When we close the debugfs entry we release the associated memory resources and we unshare the memory from the hypervisor. Signed-off-by: Sebastian Ene --- arch/arm64/include/asm/ptdump.h | 5 ++ arch/arm64/mm/ptdump.c | 143 +++++++++++++++++++++++++++++++- arch/arm64/mm/ptdump_debugfs.c | 34 +++++++- 3 files changed, 179 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h index 1f6e0aabf16a..35b883524462 100644 --- a/arch/arm64/include/asm/ptdump.h +++ b/arch/arm64/include/asm/ptdump.h @@ -19,7 +19,12 @@ struct ptdump_info { struct mm_struct *mm; const struct addr_marker *markers; unsigned long base_addr; + void (*ptdump_prepare_walk)(struct ptdump_info *info); void (*ptdump_walk)(struct seq_file *s, struct ptdump_info *info); + void (*ptdump_end_walk)(struct ptdump_info *info); + struct mutex file_lock; + size_t mc_len; + void *priv; }; void ptdump_walk(struct seq_file *s, struct ptdump_info *info); diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 25c0640e82aa..7d57fa9be724 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -24,6 +24,7 @@ #include #include #include +#include #include @@ -482,6 +483,139 @@ static struct mm_struct ipa_init_mm = { .mm_mt = MTREE_INIT_EXT(mm_mt, MM_MT_FLAGS, ipa_init_mm.mmap_lock), }; + +static phys_addr_t ptdump_host_pa(void *addr) +{ + return __pa(addr); +} + +static void *ptdump_host_va(phys_addr_t phys) +{ + return __va(phys); +} + +static size_t stage2_get_pgd_len(void) +{ + u64 mmfr0, mmfr1, vtcr; + u32 phys_shift = get_kvm_ipa_limit(); + + mmfr0 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1); + mmfr1 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR1_EL1); + vtcr = kvm_get_vtcr(mmfr0, mmfr1, phys_shift); + + return kvm_pgtable_stage2_pgd_size(vtcr); +} + +static void stage2_ptdump_prepare_walk(struct ptdump_info *info) +{ + struct kvm_pgtable_snapshot *snapshot; + int ret, pgd_index, mc_index, pgd_pages_sz; + void *page_hva; + + snapshot = alloc_pages_exact(PAGE_SIZE, GFP_KERNEL_ACCOUNT); + if (!snapshot) + return; + + memset(snapshot, 0, PAGE_SIZE); + ret = kvm_call_hyp_nvhe(__pkvm_host_share_hyp, virt_to_pfn(snapshot)); + if (ret) + goto free_snapshot; + + snapshot->pgd_len = stage2_get_pgd_len(); + pgd_pages_sz = snapshot->pgd_len / PAGE_SIZE; + snapshot->pgd_hva = alloc_pages_exact(snapshot->pgd_len, + GFP_KERNEL_ACCOUNT); + if (!snapshot->pgd_hva) + goto unshare_snapshot; + + for (pgd_index = 0; pgd_index < pgd_pages_sz; pgd_index++) { + page_hva = snapshot->pgd_hva + pgd_index * PAGE_SIZE; + ret = kvm_call_hyp_nvhe(__pkvm_host_share_hyp, + virt_to_pfn(page_hva)); + if (ret) + goto unshare_pgd_pages; + } + + for (mc_index = 0; mc_index < info->mc_len; mc_index++) { + page_hva = alloc_pages_exact(PAGE_SIZE, GFP_KERNEL_ACCOUNT); + if (!page_hva) + goto free_memcache_pages; + + push_hyp_memcache(&snapshot->mc, page_hva, ptdump_host_pa); + ret = kvm_call_hyp_nvhe(__pkvm_host_share_hyp, + virt_to_pfn(page_hva)); + if (ret) { + pop_hyp_memcache(&snapshot->mc, ptdump_host_va); + free_pages_exact(page_hva, PAGE_SIZE); + goto free_memcache_pages; + } + } + + ret = kvm_call_hyp_nvhe(__pkvm_copy_host_stage2, snapshot); + if (ret) + goto free_memcache_pages; + + info->priv = snapshot; + return; + +free_memcache_pages: + page_hva = pop_hyp_memcache(&snapshot->mc, ptdump_host_va); + while (page_hva) { + ret = kvm_call_hyp_nvhe(__pkvm_host_unshare_hyp, + virt_to_pfn(page_hva)); + WARN_ON(ret); + free_pages_exact(page_hva, PAGE_SIZE); + page_hva = pop_hyp_memcache(&snapshot->mc, ptdump_host_va); + } +unshare_pgd_pages: + pgd_index = pgd_index - 1; + for (; pgd_index >= 0; pgd_index--) { + page_hva = snapshot->pgd_hva + pgd_index * PAGE_SIZE; + ret = kvm_call_hyp_nvhe(__pkvm_host_unshare_hyp, + virt_to_pfn(page_hva)); + WARN_ON(ret); + } + free_pages_exact(snapshot->pgd_hva, snapshot->pgd_len); +unshare_snapshot: + WARN_ON(kvm_call_hyp_nvhe(__pkvm_host_unshare_hyp, + virt_to_pfn(snapshot))); +free_snapshot: + free_pages_exact(snapshot, PAGE_SIZE); + info->priv = NULL; +} + +static void stage2_ptdump_end_walk(struct ptdump_info *info) +{ + struct kvm_pgtable_snapshot *snapshot = info->priv; + void *page_hva; + int pgd_index, ret, pgd_pages_sz; + + if (!snapshot) + return; + + page_hva = pop_hyp_memcache(&snapshot->mc, ptdump_host_va); + while (page_hva) { + ret = kvm_call_hyp_nvhe(__pkvm_host_unshare_hyp, + virt_to_pfn(page_hva)); + WARN_ON(ret); + free_pages_exact(page_hva, PAGE_SIZE); + page_hva = pop_hyp_memcache(&snapshot->mc, ptdump_host_va); + } + + pgd_pages_sz = snapshot->pgd_len / PAGE_SIZE; + for (pgd_index = 0; pgd_index < pgd_pages_sz; pgd_index++) { + page_hva = snapshot->pgd_hva + pgd_index * PAGE_SIZE; + ret = kvm_call_hyp_nvhe(__pkvm_host_unshare_hyp, + virt_to_pfn(page_hva)); + WARN_ON(ret); + } + + free_pages_exact(snapshot->pgd_hva, snapshot->pgd_len); + WARN_ON(kvm_call_hyp_nvhe(__pkvm_host_unshare_hyp, + virt_to_pfn(snapshot))); + free_pages_exact(snapshot, PAGE_SIZE); + info->priv = NULL; +} #endif /* CONFIG_NVHE_EL2_PTDUMP_DEBUGFS */ static int __init ptdump_init(void) @@ -495,11 +629,16 @@ static int __init ptdump_init(void) #ifdef CONFIG_NVHE_EL2_PTDUMP_DEBUGFS stage2_kernel_ptdump_info = (struct ptdump_info) { - .markers = ipa_address_markers, - .mm = &ipa_init_mm, + .markers = ipa_address_markers, + .mm = &ipa_init_mm, + .mc_len = host_s2_pgtable_pages(), + .ptdump_prepare_walk = stage2_ptdump_prepare_walk, + .ptdump_end_walk = stage2_ptdump_end_walk, }; init_rwsem(&ipa_init_mm.mmap_lock); + mutex_init(&stage2_kernel_ptdump_info.file_lock); + ptdump_debugfs_register(&stage2_kernel_ptdump_info, "host_stage2_kernel_page_tables"); #endif diff --git a/arch/arm64/mm/ptdump_debugfs.c b/arch/arm64/mm/ptdump_debugfs.c index 7564519db1e6..14619452dd8d 100644 --- a/arch/arm64/mm/ptdump_debugfs.c +++ b/arch/arm64/mm/ptdump_debugfs.c @@ -15,7 +15,39 @@ static int ptdump_show(struct seq_file *m, void *v) put_online_mems(); return 0; } -DEFINE_SHOW_ATTRIBUTE(ptdump); + +static int ptdump_open(struct inode *inode, struct file *file) +{ + int ret; + struct ptdump_info *info = inode->i_private; + + ret = single_open(file, ptdump_show, inode->i_private); + if (!ret && info->ptdump_prepare_walk) { + mutex_lock(&info->file_lock); + info->ptdump_prepare_walk(info); + } + return ret; +} + +static int ptdump_release(struct inode *inode, struct file *file) +{ + struct ptdump_info *info = inode->i_private; + + if (info->ptdump_end_walk) { + info->ptdump_end_walk(info); + mutex_unlock(&info->file_lock); + } + + return single_release(inode, file); +} + +static const struct file_operations ptdump_fops = { + .owner = THIS_MODULE, + .open = ptdump_open, + .read = seq_read, + .llseek = seq_lseek, + .release = ptdump_release, +}; void __init ptdump_debugfs_register(struct ptdump_info *info, const char *name) { From patchwork Wed Sep 27 11:25:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 145393 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp2654513vqu; Wed, 27 Sep 2023 07:07:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEkRMtcB2bEMWrYUjdQyiaUXE3g70U9NJn3C6q2r801VfrTFsFztzeXYcPkunxCkfKojmFH X-Received: by 2002:a17:903:2581:b0:1c3:dbad:52d4 with SMTP id jb1-20020a170903258100b001c3dbad52d4mr1298918plb.33.1695823621260; Wed, 27 Sep 2023 07:07:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695823621; cv=none; d=google.com; s=arc-20160816; b=KjvxhEK4yvWVRoNPXjXNvmHBH9Bj00ZSlPMfnjrd2NZL3OmWask7ZyRYjsAi/vngX7 Vt1vpWSycugdcBETPpqEnHoDrBUYroPpLgSwFxM7iEehZ45KNm3x7HWk2oOX/4JOo7jA gNiyEdGypmqd9CXwrbHiSolBV7ZBY+KEWCWT7HNvZ+M44F5nz2z0tJC1kdntvatJBGlv dQRiuLqCPjty6XKa5L6T+A+TEbIYRxrqgRfhfltsYTm0Ib+XtjW3cu+9oFVtHoMJNDcr FQA1KMKURi1mxDSlhhYPKw94gsZoRu/ZGJ0RGga4gJaO43B504SDwPE9I7MQVSksZk3K FKlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=jN3lkJwQH7CcPgPrstq/ICC5W9G0uqc/IaOXXHWKors=; fh=yikR9HT1wx5LLj7DvfR9kbE/RatD/mnQgNUS++qRsJM=; b=h4C4l604AQZQqSFnnwQkLos138mKmCy1nGUY5m2BiQ29y4CLC085QphXX2jvyYNpTB 3zYgEGyJpW3GiOCOrNA9xmyhjVlXM7qaQkjZI4x8XAyrIJNxXs8mHGNIsKmWPQRxazdx b4zb0PtscuTew1+Rd3d45i9h64ykjIL3Y5eU/wbTQXqePd/VuSD0fhINNZMFu/YynKV4 THJYEb9C+9T5haX+BFpvkjvcI11oigtG4zEsC4v16ivmIJw6veSIzECoSTYR/Ws1Q9qm tYwRSpSPgAmQAbnUNpaMbgDrfMCTOzUur1xEYSDApNKRsEPDz6/55lzRREafwKFNWHV2 qk0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=DxTCiJis; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id q7-20020a170902dac700b001c44c0f8d96si10546291plx.251.2023.09.27.07.07.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 07:07:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=DxTCiJis; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 09BD682224D7; Wed, 27 Sep 2023 04:26:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231376AbjI0L0b (ORCPT + 22 others); Wed, 27 Sep 2023 07:26:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231543AbjI0L0F (ORCPT ); Wed, 27 Sep 2023 07:26:05 -0400 Received: from mail-wr1-x449.google.com (mail-wr1-x449.google.com [IPv6:2a00:1450:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0574CFB for ; Wed, 27 Sep 2023 04:25:56 -0700 (PDT) Received: by mail-wr1-x449.google.com with SMTP id ffacd0b85a97d-3200597bfc5so8330093f8f.2 for ; Wed, 27 Sep 2023 04:25:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695813955; x=1696418755; darn=vger.kernel.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=jN3lkJwQH7CcPgPrstq/ICC5W9G0uqc/IaOXXHWKors=; b=DxTCiJis/AcQO8gAQpI86m+UiwbN46965ejxBx2PWsrdb+yxy4TuLbIlT4SW5p/Ga1 kjR4GogANb+jCAnbGFSHqmYP408FsAcpEZqL5SVatcnIlSUDISGtsmZL64Q5TGMrq9ZB rM+LJ1ss4Up9KoVM6bZ52KR+MFJutCA4BLUlsLlFS3hQLbNkcfuBCBj2X2Whp8u/ASOl T82OsLTkwU4HWhFd+1pFRivw9dg392DlMX9YqZ/hN0i7j6XNdhQy/J7utvWXfpw4HE1C sSRfCu+b06TNVDrzrOiWPPjfBv8FTVexuKdxZSa7TP0jLwoQFG5WyGGyoW1J2mfLNdpl Xpfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695813955; x=1696418755; 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=jN3lkJwQH7CcPgPrstq/ICC5W9G0uqc/IaOXXHWKors=; b=wmXo/ZTokViqGCiP2DcGaFuUdwN0NxbPU/yJIC1v+1AV8wbO/ybnnXhii7XeZc14VJ JwK3l6D0kAG4iYkV30mAYVHli3yhACH0S2RMgDGYdGnXDf+4dDH7ZQnymKm+zKM3Rykl gyIe4Z9H70nIbnxO15Dwt1MejRn3X+wxafl6FqBjBt3J7AalrBfO7KIP3BQnHqBkYuUO LYCiFLZNx/wtZaAOp5HxrNeAPGfxAURzXhRnGtqTh8uqsKxddhXLIBTdKKpbTBOIWTpf oNz72VWTbD0Q+eC5sUNo8WivWJ6Ks2ZKRy5eRfAr+mGNpbGDpLK0EiZuuE+1PusZdiu1 BSyQ== X-Gm-Message-State: AOJu0Yz4lxkdBjt67yBNrgzlCBexReKLOoBAyWWj9c5rmXwtMAqIx8j9 l9RFUmrTcipfcATBjt3jkBZs5XWl5aGf80UNBvA3HfNtjruIkLV4wqXxrRdJQVOESnUILNRQWxi wi/7sUof84hk4MUUQj9yWYLbeeqyXL20WANqnHGElhcx5TyZ2R4c4pHK2KKX71DqetpqzKJp7eU cC///coXX//w== X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:a5d:4203:0:b0:321:9ba4:1d78 with SMTP id n3-20020a5d4203000000b003219ba41d78mr7707wrq.4.1695813954971; Wed, 27 Sep 2023 04:25:54 -0700 (PDT) Date: Wed, 27 Sep 2023 11:25:14 +0000 In-Reply-To: <20230927112517.2631674-1-sebastianene@google.com> Mime-Version: 1.0 References: <20230927112517.2631674-1-sebastianene@google.com> X-Mailer: git-send-email 2.42.0.515.g380fc7ccd1-goog Message-ID: <20230927112517.2631674-9-sebastianene@google.com> Subject: [PATCH 08/11] arm64: ptdump: Parse the host stage-2 page-tables from the snapshot From: Sebastian Ene To: linux-kernel@vger.kernel.org Cc: kernel-team@android.com, will@kernel.org, ryan.roberts@arm.com, mark.rutland@arm.com, maz@kernel.org, vdonnefort@google.com, Sebastian Ene X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 27 Sep 2023 04:26:47 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778199949758423093 X-GMAIL-MSGID: 1778199949758423093 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 | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 7d57fa9be724..c0e7a80992f4 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -616,6 +616,58 @@ static void stage2_ptdump_end_walk(struct ptdump_info *info) free_pages_exact(snapshot, PAGE_SIZE); info->priv = NULL; } + +static u32 stage2_get_max_pgd_index(u32 ipa_bits, u32 start_level) +{ + u64 end_ipa = BIT(ipa_bits) - 1; + u32 shift = ARM64_HW_PGTABLE_LEVEL_SHIFT(start_level - 1); + + return end_ipa >> shift; +} + +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; + u32 pgd_index, pgd_pages, pgd_shift; + u64 start_ipa = 0, end_ipa; + pgd_t *pgd; + + if (snapshot == NULL || !snapshot->pgtable.pgd) + return; + + pgtable = &snapshot->pgtable; + info->mm->pgd = phys_to_virt((phys_addr_t)pgtable->pgd); + pgd_shift = ARM64_HW_PGTABLE_LEVEL_SHIFT(pgtable->start_level - 1); + pgd_pages = stage2_get_max_pgd_index(pgtable->ia_bits, + pgtable->start_level); + + for (pgd_index = 0; pgd_index <= pgd_pages; pgd_index++) { + end_ipa = start_ipa + (1UL << pgd_shift); + + st = (struct pg_state) { + .seq = s, + .marker = info->markers, + .level = pgtable->start_level, + .pg_level = &stage2_pg_level[0], + .ptdump = { + .note_page = note_page, + .range = (struct ptdump_range[]) { + {start_ipa, end_ipa}, + {0, 0}, + }, + }, + }; + + ipa_address_markers[0].start_address = start_ipa; + ipa_address_markers[1].start_address = end_ipa; + + pgd = &info->mm->pgd[pgd_index * PTRS_PER_PTE]; + ptdump_walk_pgd(&st.ptdump, info->mm, pgd); + start_ipa = end_ipa; + } +} #endif /* CONFIG_NVHE_EL2_PTDUMP_DEBUGFS */ static int __init ptdump_init(void) @@ -634,6 +686,7 @@ static int __init ptdump_init(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, }; init_rwsem(&ipa_init_mm.mmap_lock); From patchwork Wed Sep 27 11:25:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 145496 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp2790227vqu; Wed, 27 Sep 2023 10:37:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEbrD9Z5aFsu5W7hADY3qtQoOcwyNjaBsoviZCpfpEQ3S4z4ndKX84YsMTgfYFU+fDe7Qeg X-Received: by 2002:a05:6a00:3a10:b0:68f:e121:b37c with SMTP id fj16-20020a056a003a1000b0068fe121b37cmr2824252pfb.4.1695836251969; Wed, 27 Sep 2023 10:37:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695836251; cv=none; d=google.com; s=arc-20160816; b=gMfR9tfFk3McH33/KTSSeeFL13cj0M2GcvzSzpUQltP4h28lEpx+uVSh+WNDHPT3pO lZBZTZQuTFVlBZGmFiKJ9gyvsAI18//Y/qq4XILCNE/eWdV9TyIsMycdGe6RxTiFPnZd NL/0eJmfHVpNRPocVm8eY29FEKBRMiSY0+VApqSDPTjy+qMI6TCZ4BH/wq200yuJ1d6v HLLxFTYMdhIKwrg6luDtcyVELlkaJqSHojBCWMwVdOmceO4j0t5LCMIBI3EIYfkyBtDg Xa4Npg+G740cGnZ99yqatvijnXfelrqLdy0hsBOC0AuNQhy+PkmZIXGqsjikCErPLySr gvHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=0aTzF9ImfQCjyHb9gICzxGcnOKx1R67tU4HaWRcwYMY=; fh=yikR9HT1wx5LLj7DvfR9kbE/RatD/mnQgNUS++qRsJM=; b=NtC29yYI9zug1SllFgPQxja8OHLRLqZAVYgWFRMl4my9qj2Qnj5mIIw7iJs4mjcHue nbBjYKRDucg3zSmqTbLRLMNkGScI7U9AGzdLdToyf8HgU67toK9cZYPDrXNPlQKdtxfk oCZA3OzBHrNEspjLP71zzv6Ch7c21qh0KIFy/d4VaHj9HWq0rgykTi+T9KsIPxBv4AhB zl1hfrzG3A2z7G+wTq8eTd25jzk3hKkPi2RH6cc/KZSZrb7fv8bC4KtZjm9iiZfC3gDk NHoVMa3TSFCA8NpjWZRv1SdYrRZ0J0tmmFzaFTiDTfMDmUn6jBIlJzEs2QpgjXMTuhwk FVqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=0vyhyX5E; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id cp5-20020a056a00348500b006910a45a234si16473528pfb.202.2023.09.27.10.37.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 10:37:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=0vyhyX5E; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id A598D802911E; Wed, 27 Sep 2023 04:26:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231524AbjI0L0f (ORCPT + 22 others); Wed, 27 Sep 2023 07:26:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231455AbjI0L0G (ORCPT ); Wed, 27 Sep 2023 07:26:06 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AD2810C8 for ; Wed, 27 Sep 2023 04:25:58 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d865f1447a2so14060895276.2 for ; Wed, 27 Sep 2023 04:25:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695813957; x=1696418757; darn=vger.kernel.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=0aTzF9ImfQCjyHb9gICzxGcnOKx1R67tU4HaWRcwYMY=; b=0vyhyX5EwdaNG5zIrkHU5B+gC8s+5XjJoQ7458GnxzwxAOnB+HUse+BSWI8BggZhRQ 8MWj9rnWzjShBQKHLpT0Fv7Svoj5GpjJ/P4QNs5tVDWtuldkbZGpY5B+gHxrOEXeFsXw y8s7XdounxB1fDCGAjU4/jla/g2GUCtewPqNGNNP5dBNbbrlLSY4SqcCVdf3KYnKbkJv 45OY7jd37i8/eri3YW/P4NYldkzcMOKZ5j3dq+ldB/RW3ABWOqsMDszkC38dySLCh+dV LQ6YvI2fQsqBSY2a/B9dK5RpTsl1phFO7FnLjbaAJM2K022Ev8bQGvXGysDgMqdS/kpf MeCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695813957; x=1696418757; 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=0aTzF9ImfQCjyHb9gICzxGcnOKx1R67tU4HaWRcwYMY=; b=UmxbL6zzSjydvPwYUTNCUCNYsgutfPG9lPoIxtDzo6ar6pquX0Oo/gDEPkx8JoYdkI m2nqqa6fpqlb9l3X4o/FJzg9FGziGOsRGJzaH2lOzUbiygDryv9IhHgs8hhXHWapvsVD 7r2gFG+HYYiqc2okVzAwE0w9/KjQubSdXnwuJ6EaUhzYr1Z+3RbhuB7LS7DtWjy615eh iOGjyBx8a607RM+3AYuqaTK2wleEMBcj3cGJL0aAe9+9qZtjiNTNwYjxGrZX0hRYFbSN 6cCwTT2wDL5N7ZhpTO8tjV0bNzPGMAxPRlURUghyeopoP7rnwy6u0N0jRl2M92g/u/ib k21g== X-Gm-Message-State: AOJu0Yzv8TXs3iR8WiJ0Y/sLQk6ePqBbFGaoGrDRYYL0817N0dbr3SYD a62P25z6AdV74R2B6LaEuVqA8JpYbtHNPSrks+gpPrKB/dLAFN0b8SeZtnrT/8SUPsu5AGcNV+Q BwJdlNwepm6xb3y3UzMbPif4s6QozbdmNQzX0bt7HZLcfpEH2aKhE4t+pnjRNdaH+KDg+95FJWE XBULo1y3aqDw== X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:a25:320c:0:b0:d7b:9830:c172 with SMTP id y12-20020a25320c000000b00d7b9830c172mr23368yby.0.1695813957189; Wed, 27 Sep 2023 04:25:57 -0700 (PDT) Date: Wed, 27 Sep 2023 11:25:15 +0000 In-Reply-To: <20230927112517.2631674-1-sebastianene@google.com> Mime-Version: 1.0 References: <20230927112517.2631674-1-sebastianene@google.com> X-Mailer: git-send-email 2.42.0.515.g380fc7ccd1-goog Message-ID: <20230927112517.2631674-10-sebastianene@google.com> Subject: [PATCH 09/11] arm64: ptdump: Interpret memory attributes based on runtime configuration From: Sebastian Ene To: linux-kernel@vger.kernel.org Cc: kernel-team@android.com, will@kernel.org, ryan.roberts@arm.com, mark.rutland@arm.com, maz@kernel.org, vdonnefort@google.com, Sebastian Ene X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 27 Sep 2023 04:26:55 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778213193498737575 X-GMAIL-MSGID: 1778213193498737575 When FWB is used the memory attributes stored in the descriptors have a different bitfield layout. Introduce two callbacks that verify the current runtime configuration before parsing the attribute fields. Add support for parsing the memory attribute fields from the page table descriptors. Signed-off-by: Sebastian Ene --- arch/arm64/mm/ptdump.c | 67 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index c0e7a80992f4..964758d5e76d 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -85,13 +85,22 @@ struct pg_state { bool check_wx; unsigned long wx_pages; unsigned long uxn_pages; + struct ptdump_info *info; }; +/* + * This callback checks the runtime configuration before interpreting the + * attributes defined in the prot_bits. + */ +typedef bool (*is_feature_cb)(const void *ctx); + struct prot_bits { u64 mask; u64 val; const char *set; const char *clear; + is_feature_cb feature_on; /* bit ignored if the callback returns false */ + is_feature_cb feature_off; /* bit ignored if the callback returns true */ }; static const struct prot_bits pte_bits[] = { @@ -173,6 +182,34 @@ static const struct prot_bits pte_bits[] = { } }; +static bool is_fwb_enabled(const void *ctx) +{ + const struct pg_state *st = ctx; + const struct ptdump_info *info = st->info; + struct kvm_pgtable_snapshot *snapshot = info->priv; + struct kvm_pgtable *pgtable = &snapshot->pgtable; + + bool fwb_enabled = false; + + if (cpus_have_const_cap(ARM64_HAS_STAGE2_FWB)) + fwb_enabled = !(pgtable->flags & KVM_PGTABLE_S2_NOFWB); + + return fwb_enabled; +} + +static bool is_table_bit_ignored(const void *ctx) +{ + const struct pg_state *st = ctx; + + if (!(st->current_prot & PTE_VALID)) + return true; + + if (st->level == CONFIG_PGTABLE_LEVELS) + return true; + + return false; +} + static const struct prot_bits stage2_pte_bits[] = { { .mask = PTE_VALID, @@ -214,6 +251,27 @@ static const struct prot_bits stage2_pte_bits[] = { .val = PTE_TABLE_BIT, .set = " ", .clear = "BLK", + .feature_off = is_table_bit_ignored, + }, { + .mask = KVM_PTE_LEAF_ATTR_LO_S2_MEMATTR | PTE_VALID, + .val = PTE_S2_MEMATTR(MT_S2_DEVICE_nGnRE) | PTE_VALID, + .set = "DEVICE/nGnRE", + .feature_off = is_fwb_enabled, + }, { + .mask = KVM_PTE_LEAF_ATTR_LO_S2_MEMATTR | PTE_VALID, + .val = PTE_S2_MEMATTR(MT_S2_FWB_DEVICE_nGnRE) | PTE_VALID, + .set = "DEVICE/nGnRE FWB", + .feature_on = is_fwb_enabled, + }, { + .mask = KVM_PTE_LEAF_ATTR_LO_S2_MEMATTR | PTE_VALID, + .val = PTE_S2_MEMATTR(MT_S2_NORMAL) | PTE_VALID, + .set = "MEM/NORMAL", + .feature_off = is_fwb_enabled, + }, { + .mask = KVM_PTE_LEAF_ATTR_LO_S2_MEMATTR | PTE_VALID, + .val = PTE_S2_MEMATTR(MT_S2_FWB_NORMAL) | PTE_VALID, + .set = "MEM/NORMAL FWB", + .feature_on = is_fwb_enabled, }, { .mask = KVM_PGTABLE_PROT_SW0, .val = KVM_PGTABLE_PROT_SW0, @@ -289,13 +347,19 @@ static struct pg_level stage2_pg_level[] = { }; static void dump_prot(struct pg_state *st, const struct prot_bits *bits, - size_t num) + size_t num) { unsigned i; for (i = 0; i < num; i++, bits++) { const char *s; + if (bits->feature_on && !bits->feature_on(st)) + continue; + + if (bits->feature_off && bits->feature_off(st)) + continue; + if ((st->current_prot & bits->mask) == bits->val) s = bits->set; else @@ -651,6 +715,7 @@ static void stage2_ptdump_walk(struct seq_file *s, struct ptdump_info *info) .marker = info->markers, .level = pgtable->start_level, .pg_level = &stage2_pg_level[0], + .info = info, .ptdump = { .note_page = note_page, .range = (struct ptdump_range[]) { From patchwork Wed Sep 27 11:25:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 145394 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp2657754vqu; Wed, 27 Sep 2023 07:10:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHmWsU7PY+1tNOHJGEq7TUeVKPKdh7pf2eyqJ0d6leyJ0zlhe6LkulbHR5/Vs0EL8yWDIEB X-Received: by 2002:a05:6808:9a2:b0:3ae:8a9:e44a with SMTP id e2-20020a05680809a200b003ae08a9e44amr2483975oig.31.1695823854789; Wed, 27 Sep 2023 07:10:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695823854; cv=none; d=google.com; s=arc-20160816; b=uBApondUAwO8/m5l58aVPsn0GmVmq9P2UQsvuIsdByEY/XQyr/9UW6gRWI0adu/avw FXuxvh9Rsh64sZk4lhqCUxVOBqTafi3tH8a5w5Ap1M6U1hu8UFUAY+GdyqQSBTHcK25/ ryNnyNnzn+4HAdT4iUYDZ6h9HOm/OM4eiRrBFyGSx4MLTmyf1tDxxx7hsxN7I0eBVBu+ wJUauf+EKN9ni/t+4KAtaPsas9K6e2r+cW1Q7qaP92Sr4CsqKkbNL2JAIUvV+YyEBpTM dA53iF/3EFZigZEO+ZvRS0rCPCe9/HgjcThrkkQBzaykYzRbpSBzEjPf/q9jq/EEg6vD x2hA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=LxbnVeeBsmxebuYPX9n5F7ayQvPWmM0quJncxxttJX8=; fh=yikR9HT1wx5LLj7DvfR9kbE/RatD/mnQgNUS++qRsJM=; b=oGaNvmeMowZiS+/Oi5MwZ9CdKT16dTN+kl+BF67ZYKScmAxRxQyskYfSLb+2s/vzi1 WSbunGWNz9idxIS9G4ll9oO98LKFxIJ1pwDuNqlw+Ky3MH8a233U5ZD6Y76LLMaTHrxc tv8PqnsRMGE4Xn771TRo6UapcpnKxbosFUCF9VTGcD98vVpaeXCusUqm6B0D0Oih3yRw A8esDFX0XjHV8d0joNHoSFSLY9HnQov9Yxk08upI9Y8KX6o6nyfzFp3w74n1i1mlXLfW otBQ1mlkhr7PgWBy3elXnLRlRo+iBcahiozX8dBDIC2ECwLhnbEzgDjc773OS9LGjgHU vR6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=cORnPyxn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id f20-20020a63f114000000b00565db2812a0si16232017pgi.60.2023.09.27.07.10.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 07:10:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=cORnPyxn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id E834F804C611; Wed, 27 Sep 2023 04:26:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231521AbjI0L0j (ORCPT + 22 others); Wed, 27 Sep 2023 07:26:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231516AbjI0L0J (ORCPT ); Wed, 27 Sep 2023 07:26:09 -0400 Received: from mail-wr1-x44a.google.com (mail-wr1-x44a.google.com [IPv6:2a00:1450:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 652AECC9 for ; Wed, 27 Sep 2023 04:26:01 -0700 (PDT) Received: by mail-wr1-x44a.google.com with SMTP id ffacd0b85a97d-32323283257so5369910f8f.2 for ; Wed, 27 Sep 2023 04:26:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695813960; x=1696418760; darn=vger.kernel.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=LxbnVeeBsmxebuYPX9n5F7ayQvPWmM0quJncxxttJX8=; b=cORnPyxnYUUDBEx8bFQsUJFhOFPxcisp5LuuwGrzGxDZYmQlbYb2sp29gySnKTpzqQ WZAE3x0kIcTFCrbRRXEZpeprCNaPrvHa7Kul4Vlh+gKKdp3fWzrgMpXWlvuEHJ9cK8rb GXH6Ax6RiiOXxZ3nKhGbEA4K+GWp4B192o2hrNfUzNvBiLCi7lb+RKzQP4jXcwhX7MSX aqQ7CLQeH4tvYIJVKoOeo3x4SJvALRIFNWc45igJw/gNCOZr9ntfV8yfbBoE4WRdIvcn k+lFfUzez+fx27EcTC3HD4D3YNruPFxaA2J7rISMCOKn5lNr75xWf48hmpySDJrDR+Hl HBHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695813960; x=1696418760; 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=LxbnVeeBsmxebuYPX9n5F7ayQvPWmM0quJncxxttJX8=; b=C/7XUlqw6PKK4BITEeJVBMKHD+sCeyWT5XMnXPs4Gi0ypQJLPjwnTLHKWXXSkRhDGk bMp3Fg4O14vSI4+VB9hk7NqCU6IzADiLDlY/YeN0xxk8yd5weAzvr+NjHP3DB90llQbE dYtsCzWOEtRvE8nVMcTQouKgj2Yl2h9PRfXRTmaosg4U9fLtvJC5xby0sIbiOYcat1ZM b1UH7Ew8XdZYpgHoEHF/8aA54h+sDl0p6vHJ/9n+0DOdQS2hVS9gF6wzHckz+mQKRQEc pOJFO6TLD53dkV0mS813Ya/6ahUVR9CoMA8vkgLZf4mYYRZtt2Kg2MyXu6W0PHNPzWNS wudQ== X-Gm-Message-State: AOJu0Yws4SWiteOGieqTK0XUF05mVKbzEcARqsBM95m4P0cFEmNl1V/A QHp7aO+kSeDY3mw5BokU8KZlolwABqkYGp7j1jAKXU99SdUVQKTUm846ppHMO0rBSVVLrWeSRDo YXOjcY/T155RJ1qoneP/MpHGsUQVTJs0qLYvcjP5h7oNBhR0UDdwfAG4sklD72MzyB4CR5TE+7R YDCiRfZBefEw== X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:adf:ed84:0:b0:317:6e79:423c with SMTP id c4-20020adfed84000000b003176e79423cmr7347wro.3.1695813959676; Wed, 27 Sep 2023 04:25:59 -0700 (PDT) Date: Wed, 27 Sep 2023 11:25:16 +0000 In-Reply-To: <20230927112517.2631674-1-sebastianene@google.com> Mime-Version: 1.0 References: <20230927112517.2631674-1-sebastianene@google.com> X-Mailer: git-send-email 2.42.0.515.g380fc7ccd1-goog Message-ID: <20230927112517.2631674-11-sebastianene@google.com> Subject: [PATCH 10/11] arm64: ptdump: Interpret pKVM ownership annotations From: Sebastian Ene To: linux-kernel@vger.kernel.org Cc: kernel-team@android.com, will@kernel.org, ryan.roberts@arm.com, mark.rutland@arm.com, maz@kernel.org, vdonnefort@google.com, Sebastian Ene X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 27 Sep 2023 04:26:58 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778200194568144496 X-GMAIL-MSGID: 1778200194568144496 Add support for interpretting pKVM invalid stage-2 descriptors that hold ownership information. We use these descriptors to keep track of the memory donations from the host side. Signed-off-by: Sebastian Ene --- arch/arm64/include/asm/kvm_pgtable.h | 7 +++++++ arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 7 ------- arch/arm64/mm/ptdump.c | 10 ++++++++++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h index 913f34d75b29..938baffa7d4d 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -87,6 +87,13 @@ typedef u64 kvm_pte_t; */ #define KVM_INVALID_PTE_LOCKED BIT(10) +/* This corresponds to page-table locking order */ +enum pkvm_component_id { + PKVM_ID_HOST, + PKVM_ID_HYP, + PKVM_ID_FFA, +}; + static inline bool kvm_pte_valid(kvm_pte_t pte) { return pte & KVM_PTE_VALID; diff --git a/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h b/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h index 9cfb35d68850..cc2c439ffe75 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h +++ b/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h @@ -53,13 +53,6 @@ struct host_mmu { }; extern struct host_mmu host_mmu; -/* This corresponds to page-table locking order */ -enum pkvm_component_id { - PKVM_ID_HOST, - PKVM_ID_HYP, - PKVM_ID_FFA, -}; - extern unsigned long hyp_nr_cpus; int __pkvm_prot_finalize(void); diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 964758d5e76d..45ff4ebae01a 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -272,6 +272,16 @@ static const struct prot_bits stage2_pte_bits[] = { .val = PTE_S2_MEMATTR(MT_S2_FWB_NORMAL) | PTE_VALID, .set = "MEM/NORMAL FWB", .feature_on = is_fwb_enabled, + }, { + .mask = KVM_INVALID_PTE_OWNER_MASK | PTE_VALID, + .val = FIELD_PREP_CONST(KVM_INVALID_PTE_OWNER_MASK, + PKVM_ID_HYP), + .set = "HYP", + }, { + .mask = KVM_INVALID_PTE_OWNER_MASK | PTE_VALID, + .val = FIELD_PREP_CONST(KVM_INVALID_PTE_OWNER_MASK, + PKVM_ID_FFA), + .set = "FF-A", }, { .mask = KVM_PGTABLE_PROT_SW0, .val = KVM_PGTABLE_PROT_SW0, From patchwork Wed Sep 27 11:25:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 145551 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp2851450vqu; Wed, 27 Sep 2023 12:24:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHD65wlZi07sGX0Q35FIR1GM2xQJWCcDxuz7weKSS810+K5FEB0WhI+BkkT39D5+1sh9vxw X-Received: by 2002:a17:903:244a:b0:1c3:64f9:45ad with SMTP id l10-20020a170903244a00b001c364f945admr3337691pls.48.1695842672803; Wed, 27 Sep 2023 12:24:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695842672; cv=none; d=google.com; s=arc-20160816; b=uXTDMGWUZ8mB/BGsdhXfMl+tE6otXur/5WNfRRqRg7F9/fLeswZN8eAcn8wX9i0k+q kb1afoAcxIimm7FB5OMMyAS5hewSr/7F4Pia1k7qcVyJMAbwXvP8WS7Q/k1yLimBsRNB hfAalpvVzH0Qu+ICS4R9uNgZew3d4zu6JJVQQkO7KoZAFT2dMASTyyUuqtyeC8HV+Yxs CKoIYn7dOMsb4CM6NwNcON9B6Kep+XhJ8kCXBUvYRtAakP1zyVZpRq7vr2jjJSYbPx49 VthO+DBGduL2noCUgZYIJIxjFTxXkV2MiNvddw97eqUmk+WfwTZM/cTN0kEnNvutdDG9 fmHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=Dqe/ezm7v7eNq2euMQ5a609PLiY6TU1HkFiIjMU1CM4=; fh=yikR9HT1wx5LLj7DvfR9kbE/RatD/mnQgNUS++qRsJM=; b=nHvqcNVFyCqXVeFITw3F6yZyg11vQdYVwTD+lmq0tKJnV6paA96ThrdwGkH1nfpyp5 iqTqrCKR3jMUnbKo+kNR5CjNmm5xDYum55yvYa00I3MWcnNHw7mRkoc4izN3UftB6wN2 FJ6T4xEjbgZMH8DNFTnJVoI6ZIvPJBNOitqBjeMm1uXcJ/o0VvFKnL4syd/ZJjA/BgB4 jP9nmoX0YxzIqxNSRB60v+Vc7tKtdwfgkiNSA76lEeF5xOGdANnAQzbUkvlafwWsFb98 saBfWeiWY+pddCGzVg98WlDBuISL/9QKZsh2U7k8OIgJgD4V+u8CeTReL6n1Or6Ybjtd Md8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KkB4ZFEh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id i1-20020a170902c94100b001ab089f7329si4724487pla.73.2023.09.27.12.24.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 12:24:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KkB4ZFEh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id BA2D782224EA; Wed, 27 Sep 2023 04:26:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231532AbjI0L0n (ORCPT + 22 others); Wed, 27 Sep 2023 07:26:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231600AbjI0L0T (ORCPT ); Wed, 27 Sep 2023 07:26:19 -0400 Received: from mail-wr1-x44a.google.com (mail-wr1-x44a.google.com [IPv6:2a00:1450:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8445FFC for ; Wed, 27 Sep 2023 04:26:04 -0700 (PDT) Received: by mail-wr1-x44a.google.com with SMTP id ffacd0b85a97d-3217fdf913dso8219068f8f.3 for ; Wed, 27 Sep 2023 04:26:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695813962; x=1696418762; darn=vger.kernel.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=Dqe/ezm7v7eNq2euMQ5a609PLiY6TU1HkFiIjMU1CM4=; b=KkB4ZFEheuhGY2DHzNuQc0kEk8mD8RxGAjNExd8epS2wc0Lq/nI1h84MjdzURP/zri FlbrcRN9BjbU14sidG8Di1TblvEIDNVSFWs/5k9bzwYf0//eL6Xf8nMPVGoMI5xHOtmA FNxl2iXd808FQ6Voj9RPlJT+6ZvgTwsi1XA9Q8My22gGNLxLWpF7hWiDW23NB2GsCmMo Fax8BIo2r8iTVGp1vTgXCGc/SByl11yWg/niy0HkGJYveM/TV208+D/BFisszpDtk4Az S04xvlbaJV8fm2dgYAN2ZuetdjG9zXv8CVY04yXLI2g01lZkerwcRmM/jF9n6WrGGnUi A92Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695813962; x=1696418762; 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=Dqe/ezm7v7eNq2euMQ5a609PLiY6TU1HkFiIjMU1CM4=; b=uH2WnPJVYGZflHS8lcecTakcSJ1eYIkXBl0IeMvA33oUoLd8Y2A72tHvBeLPjusItG Ir/FdNF2ScYdZb0mx6PHmUCwNaRo+uKot9Jcf9l0NNqpxV/7n8DH5N/t2JENfkHUoqKB gTA/ub83JqlpjX99L3iZAShvqLi93ZDlRJI84PGtW/8PXSlV5wiFB632m+IPJtpfhzEl YP29HDD6PTigJoE1Szjesi0taCRctssgjVjFb7OvJ2gE8fZDMTV48QeieCL/BRra15l9 jQbt6XDMnRQwE+E1PNDWgw3jyso7czcNTHQ7BmO+yPLRby7IS5H3WvgEDmB9YdLBwTby oYsQ== X-Gm-Message-State: AOJu0Yx55LOveDESdlkr7ux6E6/HHXQzT24S2NrJ/XOlvZiXk20K8Ytv E/MqvXnW00nVHfXKVlGoBbiwAtFqBRUs+VDIexvFHTU83//70lwj4TLAh3BtaDn1RYFD4Ysae0r 7Gfh073U0HoGAX2XDS4SCOWVIxDzUGlOviGhOU0TcHu3C/ANWUVXfP7wuy40xNJs3lSAHszNNMZ mPF2pgWG/A0Q== X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:adf:ed84:0:b0:317:6e79:423c with SMTP id c4-20020adfed84000000b003176e79423cmr7349wro.3.1695813962239; Wed, 27 Sep 2023 04:26:02 -0700 (PDT) Date: Wed, 27 Sep 2023 11:25:17 +0000 In-Reply-To: <20230927112517.2631674-1-sebastianene@google.com> Mime-Version: 1.0 References: <20230927112517.2631674-1-sebastianene@google.com> X-Mailer: git-send-email 2.42.0.515.g380fc7ccd1-goog Message-ID: <20230927112517.2631674-12-sebastianene@google.com> Subject: [PATCH 11/11] arm64: ptdump: Fix format output during stage-2 pagetable dumping From: Sebastian Ene To: linux-kernel@vger.kernel.org Cc: kernel-team@android.com, will@kernel.org, ryan.roberts@arm.com, mark.rutland@arm.com, maz@kernel.org, vdonnefort@google.com, Sebastian Ene X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 27 Sep 2023 04:26:57 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778219926373914381 X-GMAIL-MSGID: 1778219926373914381 Fix two issues where the printed address range from debugfs was not showing out correctly when trying to read from /sys/kernel/debug/host_stage2_kernel_page_tables entry. The first issue was printing to debugfs the following: 0x0000010000000000-0x0000000000000000 16777215T PGD If the st->start_address was larger than the current addr the delta variable used to display the size of the address range was overflowing. The second issue was printing the following wrong IPA range: 0x0000000000000000-0x0000000000000000 0E PGD Validate the current address range before printing it from the debugfs entry. Signed-off-by: Sebastian Ene --- arch/arm64/mm/ptdump.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 45ff4ebae01a..2c21ba9b47d1 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -430,6 +430,9 @@ static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, const char *unit = units; unsigned long delta; + if (st->start_address >= addr) + goto update_state; + if (st->current_prot) { note_prot_uxn(st, addr); note_prot_wx(st, addr); @@ -455,6 +458,7 @@ static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, pt_dump_seq_printf(st->seq, "---[ %s ]---\n", st->marker->name); } +update_state: st->start_address = addr; st->current_prot = prot; st->level = level;