From patchwork Thu Oct 19 14:40:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 155611 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp432182vqb; Thu, 19 Oct 2023 07:41:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGklSZeknxBDc0GqXcsu4VVneDdI1C90p+gZmZ+Ynv578OmBkjJDnoC8L+5+QyjZqxlDvcT X-Received: by 2002:a17:902:e548:b0:1bc:3944:9391 with SMTP id n8-20020a170902e54800b001bc39449391mr3243603plf.25.1697726484636; Thu, 19 Oct 2023 07:41:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697726484; cv=none; d=google.com; s=arc-20160816; b=GyAx6nuK/EkwrBsFhA9uhov7VuCyqihV5CfnjqF6ceZhgOCNpcnUhAyvG0jsh2G87S kxTt9e42pt/uK8iNLA+QTutZ9t29nN29zj+YuGCALL//NUTTwqtdvPaT22F6R4++/1HM zZwgQAUveIdeVOZBgzT82wGQzGAsC/b0LcoGwrkf7afo2aXoJxX70cvL6b3RlqhmiY8E prDSFXgRbSxU4LjNZ52GxtLqET68tW7vG29jhRqqjKjFRUnXgBKyTsjAP/gJPii5V6sx 8IQwqXp2vx42dzy+Gb3llpzP6ef+F7n5+5LUTtSfD6x/qdRUMmznSoCCvYTkQY4Npsk7 X2IA== 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=MVLIzP3Q0iWxIWjFJBGtp/ww3MnoFI3IyjnW9dmr0o8=; fh=t9YKxUPg1Kt5PJ3n0c95aaxkMlch/EFXblRJVyulW1I=; b=IyPCJ0QLmcOsAuBoWbs0Otg3R4VdW9ilC5buTffAwbQY1ZUI++4jZDt2xRXXHbCBx6 HA5RkeTMhHhXjGY1buDFHzdBqaUEtBkc4uPUKzOEfws0JeDwFELIi4Wpnqau218fbEdj Ee+xeqPusoYmV9vyHNd02id4LREa7KKAcvlsZWA1RgeGPoVEU61MTpCqLfg0dvAQSWja EZiS06jbLifPJ3sk1azGihVu81KaB5Gj73pO0yObNkECoLJ2CzqDY4CbYSI41sE/fkIW kjbj24qR41cLzazFSmpFHZKicmvMgTAPkZLJEbMtUSselasic2R5+VVAANfweEV+HI5b 5WoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=wYi8TgPz; 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 u11-20020a17090282cb00b001c72c258f82si2276329plz.99.2023.10.19.07.41.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 07:41:24 -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=wYi8TgPz; 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 B3E4D81C19D2; Thu, 19 Oct 2023 07:41:18 -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 S1346178AbjJSOkx (ORCPT + 25 others); Thu, 19 Oct 2023 10:40:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346167AbjJSOkv (ORCPT ); Thu, 19 Oct 2023 10:40:51 -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 3E489185 for ; Thu, 19 Oct 2023 07:40:47 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a7e4745acdso125801737b3.3 for ; Thu, 19 Oct 2023 07:40:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697726447; x=1698331247; 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=MVLIzP3Q0iWxIWjFJBGtp/ww3MnoFI3IyjnW9dmr0o8=; b=wYi8TgPzGS+ykQ2VjcxHmbhsYANuNo51EhY0oZcuNNaWaemrbpOtW/GRjiGnKx1FlP J6sl9WKJd/vRUSQVje6RibgekjwV+VLGZEK91+5j7hwxtofwOYXLAhhOtGZ6bsmayAug nIVjHGhD9esmMY+KIauUctBNs9sAgsuOhaVz6NFt3MH4WqsGDk2qrbl1wkyw4nmBdnDN 8RQyd4nFv0jBp2pd7ckclDaEz3QNMJz/H6fRljs1276JcfyxiHkN/EkY7hVWKm+4PIzP cKS39WwFY4uG8q7tZb43IOZ9XAkSuWHGuz27VmNzk6PmxZq2y5QLWNb3UPPJlavbbJYq tnKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697726447; x=1698331247; 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=MVLIzP3Q0iWxIWjFJBGtp/ww3MnoFI3IyjnW9dmr0o8=; b=sUsP00VkVzzzuKmy14IYX86LOCtKkOjOdhuwO1UF7wn861vMl3VOeILzwi3QcjOaIh YYm01xJXS74vetQQUZQqXdrlz5I5EUpradZgJNwoMnipS+9oPpAa5u9FjKOpKitqfBtQ hh0/FjA/0M6A4nDr10+AB0DQbK9wHjS9KCIndQHCw2CV+h6n0+QfSLetg863Ql6OZodS J4AfSEMx6MG6TgETKym/Q0JIiQcnHqeM/ntme+TZ2C7wOFd44YsUkTsMBwAQguGXX4sU ZzXSEZLaKF0REh9pMyvKschFUbADzP3f+JkXaRjYYDa80dJKmfbLIVafV3fF/5ymeuDQ WcZg== X-Gm-Message-State: AOJu0YxFv2AqvJnsFiEhbFdbIkLqeYBfT2sLB98IGYQ3aTGjfl0JdpOq 789I/YQ2dmHDmLkvEWt8Ifk3FXyCU0n+qcbz/YM= X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:a81:4944:0:b0:58c:b45f:3e94 with SMTP id w65-20020a814944000000b0058cb45f3e94mr51348ywa.8.1697726447137; Thu, 19 Oct 2023 07:40:47 -0700 (PDT) Date: Thu, 19 Oct 2023 14:40:23 +0000 In-Reply-To: <20231019144032.2943044-1-sebastianene@google.com> Mime-Version: 1.0 References: <20231019144032.2943044-1-sebastianene@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231019144032.2943044-3-sebastianene@google.com> Subject: [PATCH v2 01/11] KVM: arm64: Add snap shooting the host stage-2 pagetables From: Sebastian Ene To: will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, vdonnefort@google.com, qperret@google.com, smostafa@google.com, Sebastian Ene X-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]); Thu, 19 Oct 2023 07:41:18 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780195246614635270 X-GMAIL-MSGID: 1780195246614635270 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 Thu Oct 19 14:40:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 155615 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp432350vqb; Thu, 19 Oct 2023 07:41:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE+NJ7x2lPYfC2EkOqImzLWRyI9Tp4W/yL+pt/NJpYBOkmgKhme8pfq1t7iuN7Mwo4TEBwN X-Received: by 2002:a17:902:f0d5:b0:1bd:d911:2a85 with SMTP id v21-20020a170902f0d500b001bdd9112a85mr2198950pla.12.1697726501721; Thu, 19 Oct 2023 07:41:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697726501; cv=none; d=google.com; s=arc-20160816; b=rkqJ1akF7kx+T1y7RLBvk0h/KmoABI+WXp8b5GA7ClyI33r7BHqYcwg+eFdH6Mcuv1 UXFbcVayVU9cbF1RC0q7Qmud9rX2kNW2tgreFv4vwbthtMm491NYYPrGbt7UJ0HbkaFs 0gkzwLLxez7hDaPfPRCZFQ89IWQzQOoXqOgpGsAytXROSdOovzc6SsNnWuyjtH1GJPGf LKAMlUUHCercKzqbRjhnXKw+RsiksUVzLtOU6OQyO+0gCVVnrRB9Ws4TzR/S0VJdK8hB pYtka3buI7V+7b1/ATJxvjZCxWPORBdCEZMKS72oAb7IncZlK2i23betBFks0YRHoU9Z rGww== 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=VveSIU8JYKB/5xEaudWcBTfyzaRnPWmMG3dfs8XdtD8=; fh=t9YKxUPg1Kt5PJ3n0c95aaxkMlch/EFXblRJVyulW1I=; b=FrqFBwoiiw6GI3VKWbhL6GDj0/SkjRreKsC9uU5Goc4rAn/+sRXu7NnamxajDHLJBq 87Fk1YpaF4uYqYcJRWj+YqmScp3pYeql80gZCO32+A0deWE0jCuKchw1EEi+pK/tJczd 4U3i7ruo9v96gYXC1zfZ4XVRZSCfpdSGMMMIh1hOgXOD4zh1mT4LsemUecxov7Zwr7XN 07S7JLm1vxdJYX1KXlNChP7erPpKINBokVkT5JXcSQ0JSJ09p3kI1LoQkOEvnxnx6s4p V1PkToXttYn3sjMrcZ7L9Jg6cHM8x3MOjQZDoK38L6yhRSWxx7+Uxplbb7xnL5Ru8qMl aiOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=0yf2MI1K; 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 l1-20020a170902eb0100b001c71eb782b0si2287065plb.94.2023.10.19.07.41.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 07:41:41 -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=0yf2MI1K; 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 EC67781C19E5; Thu, 19 Oct 2023 07:41: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 S1346206AbjJSOk7 (ORCPT + 25 others); Thu, 19 Oct 2023 10:40:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346147AbjJSOkx (ORCPT ); Thu, 19 Oct 2023 10:40:53 -0400 Received: from mail-wm1-x349.google.com (mail-wm1-x349.google.com [IPv6:2a00:1450:4864:20::349]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15B25138 for ; Thu, 19 Oct 2023 07:40:50 -0700 (PDT) Received: by mail-wm1-x349.google.com with SMTP id 5b1f17b1804b1-407da05ee50so19098955e9.0 for ; Thu, 19 Oct 2023 07:40:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697726449; x=1698331249; 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=VveSIU8JYKB/5xEaudWcBTfyzaRnPWmMG3dfs8XdtD8=; b=0yf2MI1KTBTaYixTt5PY5GTlUkMFURkHEySHpGCaAPdibV+69YujKo/7bkF08oSXYQ CaaLB6yMjA+UQU7KH5w2E0uAiXmIrs72D7plM23oY/v32YEWC3WO8anywFQKFy0YdkOG rUwH82R3dwle4oq/4qS9k0cye7KLjkWw3COQp46a1QPW2uo1Wx1QQFUPbiViJsgEPpHZ j/A3IUOdWD00OafltgrYSZSw/zuqAHTzT4KsFVDbVevU+fghPZunjnjK4uLUuGcH/XOU 7xrPU7wGgr0PiMYiaGQcvPon6+/nLoaWpDJka1D+H2S3lFQyJhw0JnDDK2H29ODFOVy/ X5CA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697726449; x=1698331249; 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=VveSIU8JYKB/5xEaudWcBTfyzaRnPWmMG3dfs8XdtD8=; b=nGCW7LNJL5qm6neAuGDRjn72xBMi4s1l28xwT/svW2Us7DxJkJZrrfTgSB1/eeHB7E zq960fOVtTneXUMJf+LOCKzDjpGTFEMckHLYPSK8jPeO7oTU3szTpEtY7PthU4LTGfQQ nJe1G3+Ocjr1nd+1WR6kzBae+gC6Dqi46s0v71XM3KPdzYe+dANTPQ4IiOtt8KbcmSQX g9SRpCD2SzHLeVeJCOvrDhLCIjVlLKRcNxEINoWQ0r4BHVkfatxRwJyWnzWSzawOVY3s WCfZWYG2cWkwISsREYvT2qCV1YFthP2meDFEy1tUGosNb8jYdOfcYTibMJUsUuax1IK/ tTBA== X-Gm-Message-State: AOJu0Yz8NiS2SkJSaQWmU0KCJlmkjVChJl+p26oyGWWKMnO7SyavHIok CsxQ4p3rIuE4BXot2wcYhLVavI/8fSLKW2buWKU= X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:a5d:54d0:0:b0:32d:9a30:4d79 with SMTP id x16-20020a5d54d0000000b0032d9a304d79mr20981wrv.3.1697726449420; Thu, 19 Oct 2023 07:40:49 -0700 (PDT) Date: Thu, 19 Oct 2023 14:40:24 +0000 In-Reply-To: <20231019144032.2943044-1-sebastianene@google.com> Mime-Version: 1.0 References: <20231019144032.2943044-1-sebastianene@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231019144032.2943044-4-sebastianene@google.com> Subject: [PATCH v2 02/11] arm64: ptdump: Use the mask from the state structure From: Sebastian Ene To: will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, vdonnefort@google.com, qperret@google.com, smostafa@google.com, Sebastian Ene X-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]); Thu, 19 Oct 2023 07:41:38 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780195264257905773 X-GMAIL-MSGID: 1780195264257905773 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 Thu Oct 19 14:40:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 155616 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp432363vqb; Thu, 19 Oct 2023 07:41:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHo6lOMf9i6YdvpYvCiSoJS1uXvjGXR24k+/zPCM2MAKknK0v753g8QDtTWVRLaSiFSqUqh X-Received: by 2002:a17:903:1c8:b0:1c9:e072:33a8 with SMTP id e8-20020a17090301c800b001c9e07233a8mr2762391plh.61.1697726502713; Thu, 19 Oct 2023 07:41:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697726502; cv=none; d=google.com; s=arc-20160816; b=C5mOCeMI4LYoF06KTzJlNxBBpPfpNP7ANPd2EQateNpqumSAK9AC/I0oI5HZztsheZ VJx3lPYxol4iL3pYbvHknsaOzUPn1XGxZHVU10kWcTgARuhegGnusvhbdLoZIcAZJuhY tX7Ivx4wihRxf5v2oedcwZRv70BR85x48/sBAcOi8egt7l+vjgq4edFzmeqqCXDmzVV/ 6nkgdNYUESsGItUrDJ4iXx6uGGaff3IwKr7VEkP7/v9hdQZoLlQNjjG9cDyiJbyq3ERh RfKxU2YghSP2sPgp+X/cezrUjOX+kKDHHB3VgG4Hl6x6iCNJLFuESA8N3/kCxFMOI9uR 7rJw== 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=4QoqI5aCHRTu5rG2YCshZg+f8V+cS7FPutmWA2GX1oY=; fh=t9YKxUPg1Kt5PJ3n0c95aaxkMlch/EFXblRJVyulW1I=; b=azKdu0pbvGMyTPqg48nlhqB4dLA6PiA27+vQCH6hatVF6dZHEraBLRkHqHeK1UVx0c FXgwPx2vyWgiEjTMe9yhZEY4U0jxBeCrWzTw5TuNijukcWQdSYXBiqdwipqPW5Ols4mM N3BRcixRS6/6AfkoOfl7wbzblZiNb6Y4usY/x8vusHzAok+ayK7eH6htssrJJRDUF2PW 3CfoD/aTb7WVI6vM2tpCG1hs+TjcbVgfbHm0eCmsL0ds8Tneiqf3rbDOAdRsgkBd/M49 28BL3tsqglXmiJnpFuswowb+r4o8vmRM9rQo2aaJHBJkvFdxFyDxhjew1LGtXlTXP8Vq UtVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=CnoX0fTE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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. [23.128.96.32]) by mx.google.com with ESMTPS id e6-20020a170902cf4600b001c613b5e778si2159177plg.557.2023.10.19.07.41.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 07:41:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=CnoX0fTE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 873148182EDC; Thu, 19 Oct 2023 07:41:38 -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 S1346182AbjJSOlD (ORCPT + 25 others); Thu, 19 Oct 2023 10:41:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346167AbjJSOkz (ORCPT ); Thu, 19 Oct 2023 10:40:55 -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 16D9E13A for ; Thu, 19 Oct 2023 07:40:53 -0700 (PDT) Received: by mail-wr1-x449.google.com with SMTP id ffacd0b85a97d-32da47641b5so3245201f8f.0 for ; Thu, 19 Oct 2023 07:40:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697726451; x=1698331251; 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=4QoqI5aCHRTu5rG2YCshZg+f8V+cS7FPutmWA2GX1oY=; b=CnoX0fTEBnM/8OTj/QVqlnOkPTcOGQr4L1iLLknd6Mb7P/koITPgsZkYdFsvGa2W4d dSVerc22hA1rbGpZwhd277KWm3JtPahF7+u6qW+p7Rt2ZNmcIMwq6gCTsb+sSAFb3yFM nC61os6QBkdTAuHe1MX0mzndQDHGJvaIWvXLUlt+dcJ4MGykUmuYl7gG77IN0zPpuUry t8GRysSHeHdmt1YfmzhctBlssDQA2+yUqfw/V6a9fUed3fv/QXgC3CHLl6p8CsBDwNMq vh/kMtr1B+V5Gvr1zYCBWTz4QA89aNSqzylemRU0pEix5bHntohbKUF1fC5N0Xe/k5Cg HZRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697726451; x=1698331251; 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=4QoqI5aCHRTu5rG2YCshZg+f8V+cS7FPutmWA2GX1oY=; b=tg+yGz9MVpzP8ZWkg30ciljd1vFaEOYvYsd1FkpziFdHeGDfhZjBJh9kBIzfx4au6U dJUJPny0Dr8gCSgZiQXIBBixnnWZcZRz1yuwEQqM5Q+JPQgWd0DkEpOgSTmi6oB6+Mo4 m/cXbs8S5GZll5I58CkU9Ru3pefbs2q9bV06G4VwYQTIQxmnm2UX3npIO9cNgFsPSmWW R6p7BNd9LCebHJSZ8qjUWHRfzuLXOxiPZtBy3eh5DhslThF+DTL8BOu/QOKId6FHKpgc 6D0jpPLnyavMLnWjZftzN1HZoKbEGxvV2TEiszslo72WoTkNsgx76WGYKpDrB5b+U1ai 7ysQ== X-Gm-Message-State: AOJu0YxfXpo0PyHAwm+kvrUwRcExQx4ijn1AjRT+1Nxj/k+p0ybJA7i0 gfqW5Et7/zfemmy7xjYl2Lib+s0J1qVsvVrvuLM= X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:adf:cd89:0:b0:32d:8a32:3b25 with SMTP id q9-20020adfcd89000000b0032d8a323b25mr20286wrj.5.1697726451553; Thu, 19 Oct 2023 07:40:51 -0700 (PDT) Date: Thu, 19 Oct 2023 14:40:25 +0000 In-Reply-To: <20231019144032.2943044-1-sebastianene@google.com> Mime-Version: 1.0 References: <20231019144032.2943044-1-sebastianene@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231019144032.2943044-5-sebastianene@google.com> Subject: [PATCH v2 03/11] arm64: ptdump: Add the walker function to the ptdump info structure From: Sebastian Ene To: will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, vdonnefort@google.com, qperret@google.com, smostafa@google.com, Sebastian Ene X-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]); Thu, 19 Oct 2023 07:41:38 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780195265102206608 X-GMAIL-MSGID: 1780195265102206608 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 Thu Oct 19 14:40:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 155612 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp432213vqb; Thu, 19 Oct 2023 07:41:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFm3tZZRvnAhuOhKmoLw/+p+DigqZJ37KkBM7CnJrCC3UI/CqcqcKvJc8rY3qgMrPlbWyPx X-Received: by 2002:a05:6358:f1c5:b0:168:a60d:42a1 with SMTP id kr5-20020a056358f1c500b00168a60d42a1mr1351388rwb.1.1697726487218; Thu, 19 Oct 2023 07:41:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697726487; cv=none; d=google.com; s=arc-20160816; b=Xq1OepUz4tqgmyTUdrzJFQs9PwNRgpEt4hfYWRwQFgQlB7A+sgqb677h9CLizh6IuZ FZSqGYe3N6LSKCuygu6j/EF3Ta9b5aOCESiIgtZyg/QFi1HvRD0qiyPp1msp/BTN/YGu YCc0rbzQwByhDeAIu0KXjsYqORq+7IHHT+44ShY+2c5K/HkyEgYcboFrvQsw53ZfR+gN qtFFA14D9lbezEKor2fq4H+p/PuNvapCdqKyeRd/qWndNOsmZ54y1LhTFkpUXNC9DYAI fKsTilbw3Vw3oTzu3o1mbp6FlWAgcsmCtzOFi7OrPYW9hKsBT/xSgNw60hft01TjUQfP RlHQ== 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=W058w3G2hIt8CMXfrmWr4+cXGEYq83hG+O1xXrw0XI4=; fh=t9YKxUPg1Kt5PJ3n0c95aaxkMlch/EFXblRJVyulW1I=; b=XoFioViG6SgI16sodtJCtiSeBeZOjM13/S5RM15CkOeGB8vk3OEWp6cyudtlCi4J7A FEMzZ4gQwLrIEF9+8WIAllzc0RRbxZilPwRuUZAluqa89epE8L07GFF4fWcHc1R3yzqN cwJ8nCw4jHr9Nk9vM2dOWOjo6sjQ0B+Lvmfy4Piw8ooOhPpQtVfJ4ZuSmP5VFiec+qoM 5Ln1n8PixG7gVRuYoByFAYG84t+5yzZJ9dAm0oUuZgFJ4+UfFXKnnNDVmNHiUq0Zrzs0 QK3ua+JPmrUXXlvpU3hGanTQSXf5yZxz88ixdCn9Nz40OtcksPIHha4jnBSIE91tJYkg V3Sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="CZ/8WLp0"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id k11-20020aa7972b000000b006be04b8c3basi6087988pfg.178.2023.10.19.07.41.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 07:41:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="CZ/8WLp0"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id CE96983B7AA0; Thu, 19 Oct 2023 07:41:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346259AbjJSOlG (ORCPT + 25 others); Thu, 19 Oct 2023 10:41:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346189AbjJSOk5 (ORCPT ); Thu, 19 Oct 2023 10:40:57 -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 B627318C for ; Thu, 19 Oct 2023 07:40:54 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d9a4cbdad3fso10715683276.2 for ; Thu, 19 Oct 2023 07:40:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697726454; x=1698331254; 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=W058w3G2hIt8CMXfrmWr4+cXGEYq83hG+O1xXrw0XI4=; b=CZ/8WLp0oJeltnEKqugx4cFMo1YWwYwIAHEUDbfnpkV7elfIWdXDlF2Tja8S2o+Hjl tirvwpuXiAJyHWaGYRa99wDhNZx7+8uKapjRkXCksRyTktTh8CVeIgKA6i4YF0bLZpNT T2p03e3KHDySMeixdf0vFSlwj6U/TSxITK3T7zDEJpPJkmtBA7kNTUYEDvEsFas3Ie83 KtClGCAE1RbSHwSFJ8y6vYXTYNiKtsrNCzviC67tY/YfDTer+7dFUYUUNHPcuCxmKdp0 wtCk45ALKhx+ElvOcRPJRiKlS2F1e1gtKW9gkiKmO6hyCd+Ywdj94o2mIZ6xl4nc9nfL Gp3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697726454; x=1698331254; 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=W058w3G2hIt8CMXfrmWr4+cXGEYq83hG+O1xXrw0XI4=; b=UzHkwYTsPNak6JnYj/anmh/lOvk/qlOaHEhCo+fE3xIAoBR09LjvjRVE9z4t2QmVzX utXe9n0fgKSrNCwcCPFTj37x/SeL87m6WkXY7MbhGve8IpnTJqelHntoZlMhE4B/uA5b Ivts32mmARsY7ZIWZadtIjTmZFNOUVbTATOJ/UAZLkMJKrNJCkNwYw3WGAfHg9U5IEFA PmqxbNVu0OGGQQV7LMIViJHUP75Dyz5/lTY9+soR+QAxtFcZf+x6Bb1JWQN56tUxnUaP vHHOoA9PYQrN8MZCaPpI7bOXFU2RvRxx31KLWGHiMXxf5u4vY4TxW3VEFvN/8/eWCQk0 Pccg== X-Gm-Message-State: AOJu0Yxb1KKgoNTdEQLvtc5DxItwM/P39N1t1TT/Swv57/290pb5a00B 1JXhd03eCS7y5qE5FxBqaXko6Iq7bKBV3qV37xs= X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:a25:9e86:0:b0:d9a:68de:16a1 with SMTP id p6-20020a259e86000000b00d9a68de16a1mr59829ybq.0.1697726453864; Thu, 19 Oct 2023 07:40:53 -0700 (PDT) Date: Thu, 19 Oct 2023 14:40:26 +0000 In-Reply-To: <20231019144032.2943044-1-sebastianene@google.com> Mime-Version: 1.0 References: <20231019144032.2943044-1-sebastianene@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231019144032.2943044-6-sebastianene@google.com> Subject: [PATCH v2 04/11] KVM: arm64: Move pagetable definitions to common header From: Sebastian Ene To: will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, vdonnefort@google.com, qperret@google.com, smostafa@google.com, Sebastian Ene X-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 fry.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 (fry.vger.email [0.0.0.0]); Thu, 19 Oct 2023 07:41:22 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780195249335967102 X-GMAIL-MSGID: 1780195249335967102 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 Thu Oct 19 14:40:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 155613 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp432229vqb; Thu, 19 Oct 2023 07:41:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFl0AGXc04uLgBTtwoB4YXO5oda4UG+kTZfFocN2x/dlU7pr0S+yg5+/Beo1YJdz24TZHOK X-Received: by 2002:a17:90b:1495:b0:27d:3d1e:1a98 with SMTP id js21-20020a17090b149500b0027d3d1e1a98mr3140004pjb.16.1697726489275; Thu, 19 Oct 2023 07:41:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697726489; cv=none; d=google.com; s=arc-20160816; b=i5yggXLmSoxv/uo0PmnQR6n3J7R4mSIw5A/Kj3c+pmSgELhfGWdyM4priY/o4NmCpO nGM444G3Yz1fvHxuhNhGrHEHyt7QupLDHjSSM/RYdyaA1S8XAFTAJT/29goJU2NJdRf8 AOrQ+9cFzKltrx/eLcXqnqdi+sbXEYUMBt+aVoiCWhkqSD0SNcznz/La9jwo5o/Ibwl5 t/GBOFtwsagUOs9kGfCouhcuziseIgLgMj2yMhnvKfmMbp8Epj5KjicXGf0er5oiVJ1u ZI4V5tNoRrxUZ1ON2EN3E6TG7+cevtxIUyQvkJtEfWxG0c/kAG/Wy2HA1FU8uskkIlkp IVCg== 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=irFQ7vIeF55X7D9u5W+RRcx8opaM8C3jS63aHLA7bAc=; fh=t9YKxUPg1Kt5PJ3n0c95aaxkMlch/EFXblRJVyulW1I=; b=0eZivtj73CwsnLXBYQn/txf7Wv1wfG+eIiBEiZaOMzDlhb+3bIQCam6AArymuYs4Xj UFTBXnpbZQC6kMqtSfCnzRluDh0kuJr5VU2+y/cJplQCC2l5ZG+O7J8vOdcyvZkT6IlR 8/6O2z6GN6ewACpJc7OSM4NaRFXSuws6Uhv+qF9/zHj5dKinmmlHoZQkkFHfHtY6ViUU TEcG/GAx02yDz5gWpSfC60pnO/4XEzuAbE7QX165LKQ+b38pLRwQkUrk2wX+ieWlsErH WSgyurNHr8JLkcO8/wDxxIhZaf4q21GVWLOfyT8plReAjzu5lG7acUojzoje2lAIbxl+ 7mPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=dw6M0l9V; 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 pi13-20020a17090b1e4d00b0027d37bb12a6si2269973pjb.49.2023.10.19.07.41.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 07:41:29 -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=dw6M0l9V; 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 B11D8831D008; Thu, 19 Oct 2023 07:41:26 -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 S1346184AbjJSOlU (ORCPT + 25 others); Thu, 19 Oct 2023 10:41:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346244AbjJSOlC (ORCPT ); Thu, 19 Oct 2023 10:41:02 -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 D767819F for ; Thu, 19 Oct 2023 07:40:58 -0700 (PDT) Received: by mail-wr1-x44a.google.com with SMTP id ffacd0b85a97d-32da47641b5so3245237f8f.0 for ; Thu, 19 Oct 2023 07:40:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697726456; x=1698331256; 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=irFQ7vIeF55X7D9u5W+RRcx8opaM8C3jS63aHLA7bAc=; b=dw6M0l9Vn5e5um04nwj+TMG74kz79Jt3XloJl1liicKmNTg4H9BmhepT/fTpiEY2m9 bM2cWQ4utXql0EGd5P6FP76FKn/6HjU7mtlZMwNPbARqBsR3Q/1HhmnbcoUwT+Kx7TqG L4WCyJFOIp7hNZYSyv12uLjYBPo5chFO0eemstPBzD9EKuHa+kR5uqrCllQgFSTYAVco BG1rryErxuVQRJBg2nl/eHFZA0nmE2ptzOAM5l3QKVVREHkd/M4+tO3fKswV7yaaFaOO 7Cnb1Ot4Vnjwst8T5kSZE/ZM9q9PawZqVK+1xHWiGYidTFF4nJq6+B5VqJqpu/52eIRa iPfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697726456; x=1698331256; 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=irFQ7vIeF55X7D9u5W+RRcx8opaM8C3jS63aHLA7bAc=; b=LTdER/fz5BgM/iIsoU4u2kL3he2XxsS+BYEj7KCefVPfogP+jrF8GG0nrDJDXXOOXG brV1/ZjQ6SQDXHJEvpLAQ6CBiDrDOjEPOXbBBv8Ja6NqLEDpkm/XEQ7oNbMgFptMSdRd dUfg92opHa2lJCUkhNaZyY8M1Du4t43GmuKFVQmcXagYNB8Spb4OWOSZQnuiI4XkJz7d 3ca88+VTRnyL93OWqyX0P6ZXQHChcwV82J+G8rFuVHPh6H2RZRsJW910c0V4bItVHGTF /I7BlOWMAHs3pnpVhQo0XsnT5ryp3dGiNxc5AmrzjyR70daAsjuz9D6QmGcLV0w3UQEQ jARw== X-Gm-Message-State: AOJu0Yxwh8KBbSEvCrjUjEGmJkXfDipwfzdyZBzEKEaCQI26wxvQzZTS IRmLNr1/W6b5lZnmzTcb1N0flnbxwqKYccHSnFE= X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:a05:6000:1372:b0:32d:a860:3257 with SMTP id q18-20020a056000137200b0032da8603257mr19560wrz.13.1697726456175; Thu, 19 Oct 2023 07:40:56 -0700 (PDT) Date: Thu, 19 Oct 2023 14:40:27 +0000 In-Reply-To: <20231019144032.2943044-1-sebastianene@google.com> Mime-Version: 1.0 References: <20231019144032.2943044-1-sebastianene@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231019144032.2943044-7-sebastianene@google.com> Subject: [PATCH v2 05/11] arm64: ptdump: Introduce stage-2 pagetables format description From: Sebastian Ene To: will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, vdonnefort@google.com, qperret@google.com, smostafa@google.com, Sebastian Ene X-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]); Thu, 19 Oct 2023 07:41:26 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780195251463238455 X-GMAIL-MSGID: 1780195251463238455 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 | 87 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index d531e24ea0b2..58a4ea975497 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,26 @@ 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), + }, { /* 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 +421,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 Thu Oct 19 14:40:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 155618 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp432438vqb; Thu, 19 Oct 2023 07:41:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGDK54F2ZK2AE6z2IWq6AxBRj/kZ74sJ/58XPEg5NQnbTzX8oXCyzhYRr+2Qs7M2szyG7xx X-Received: by 2002:a05:6a21:998e:b0:161:3120:e865 with SMTP id ve14-20020a056a21998e00b001613120e865mr2729452pzb.52.1697726507669; Thu, 19 Oct 2023 07:41:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697726507; cv=none; d=google.com; s=arc-20160816; b=Oxlz4ILwBk/ICnopPWkJW1m4ydZCbdddos/yBp1ugQOhDHsKMmFhHqZdCtS1Dau/Aj 5P7tiwPDFBiC9wX3JqLwMiFTzcHeIYe0W5GIC+lORotg9PgdvdKRxSkgeQrgGMpxB/J0 INZ/6q9g1JSuV6xuXmGrgytN+PlfoyYmijBAyIj15sbpnBb/LJFnlxy7ex/PlYKZar1U g+Ak8AzQrTaQGSkztOb2MK9XprRmZrbqMD1dKYmE89RRSod1EC03Cd4gYs4FIpcZU0ic SYATENBww8NJglYW0PqiSUYrjfaXg1/AakXqsNI8k8R1zWS8uJLINejmygs9863RZVHG eqeg== 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=xM59NTfupiUDLHnq4Q6FLBD9y4loLd8ebx5nbjkuBV4=; fh=t9YKxUPg1Kt5PJ3n0c95aaxkMlch/EFXblRJVyulW1I=; b=xtn133riNqOD28NzM0eaqclVmy2K3OGeRBK8Wr7ai5cyRFWk138x5kL4Gz4zB+0Lxk FBh78MaAY3EW7X7V5x/YmIekEcHwAtW2viB6xF1IsvZt3cWSlmShAr1trCQlq0L8P8rm TcMOeKyZCVdRoYFqKo9kiReYmZ5A0B0ofBPM0OuwuAcsMfY4k7jNwXPgwkeQy3YhArIx t1JmdMopESQXbj3PfS77uA9JcBFd2jU9R9Nky0yqAwPSc9+pdS6EvxIjuZOTvES1o3oc WJfaaWWkevCRxi+zj7ihAMFh9xjKL5RNKHJEqjJV7Ji/Lar6dILtdqAq/225VsmEEh8e YSQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=bz21T66u; 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 bv186-20020a632ec3000000b005ae4b3f4343si4236548pgb.126.2023.10.19.07.41.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 07:41:47 -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=bz21T66u; 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 BB56E831D018; Thu, 19 Oct 2023 07:41:44 -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 S1346275AbjJSOlX (ORCPT + 25 others); Thu, 19 Oct 2023 10:41:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346253AbjJSOlD (ORCPT ); Thu, 19 Oct 2023 10:41:03 -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 7834F1AC for ; Thu, 19 Oct 2023 07:40:59 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d9c4ae201e0so763923276.1 for ; Thu, 19 Oct 2023 07:40:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697726458; x=1698331258; 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=xM59NTfupiUDLHnq4Q6FLBD9y4loLd8ebx5nbjkuBV4=; b=bz21T66uxR9MeF2ke4RlDSoO4aD0YRWDmX9rcdXkXewElXhORVd+iwza0sYAqeIoR+ VU+ocHF590WqXTFOK0aYDaW5H9xKAaDG5oN0WjBLG+t7hAyUS9f9QtOyS7W6E2dMHVs7 KRmeG+BBPagPQEfMcK6vapvcjGVIpzwv/FoPt+xGnQJM66ullp1GMjhmr4+SMf02IbEC f6nBEryH3R8rQBZRH0aHAfpDIvAgCpUNWnNO8a7F/d0k7w/2BR9vxJ5wpBiW0G+jhW8O HQ52xUAFLlyPkOTrt77+JGsnJ10cAcrrI60HbgNjBoCOKiLbZTr5HJG69wNaOWTuWCkI Kc3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697726458; x=1698331258; 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=xM59NTfupiUDLHnq4Q6FLBD9y4loLd8ebx5nbjkuBV4=; b=PTV1DC6U8KUwC/ba9xVBES1R6W9G3BIYXI/PKfbWwwrQ3IbFCCDWQuaIOWksUTZ78w ck+UbdTtNcT93lujOq9opIZCL4K7V2Xok5VYI6/vjy0KAn2spxGGR6iDXUSwdVLCE62D 5CrSob3/n2uwxK/7jvkgr8qyPg/6SzYEsu+i5V30bTsyiXcPeAWY4hMXPvqBJZGTueNX TzHaVZ54lFgaeOdnso6UUpI/LKMGNNWtZxp1PbuAD9Iy3M2xQaTRa+L/Qh+SQ/0UIn14 nOSkIUrLgfn2vaaq5l4OLD89Td9WWnhit4HzAODR+nB+OB9NGnrcn/b6lL9gXcLRPx4m /pDw== X-Gm-Message-State: AOJu0YyfOnIBlUqilb78pOjjER7HqLjGcHv4o/fWSAY8cy78OoPxbIzr 9OwAnKit9bad5fp/x1BhPBBqBD+GLHN2iIEIME4= X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:a05:6902:691:b0:d9a:fd4d:d536 with SMTP id i17-20020a056902069100b00d9afd4dd536mr51027ybt.3.1697726458604; Thu, 19 Oct 2023 07:40:58 -0700 (PDT) Date: Thu, 19 Oct 2023 14:40:28 +0000 In-Reply-To: <20231019144032.2943044-1-sebastianene@google.com> Mime-Version: 1.0 References: <20231019144032.2943044-1-sebastianene@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231019144032.2943044-8-sebastianene@google.com> Subject: [PATCH v2 06/11] arm64: ptdump: Add hooks on debugfs file operations From: Sebastian Ene To: will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, vdonnefort@google.com, qperret@google.com, smostafa@google.com, Sebastian Ene X-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]); Thu, 19 Oct 2023 07:41:44 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780195270670698224 X-GMAIL-MSGID: 1780195270670698224 Introduce callbacks invoked when the debugfs entry is accessed from userspace. This hooks will allow us to allocate and prepare the memory resources used by ptdump when the debugfs file is opened/closed. Signed-off-by: Sebastian Ene --- arch/arm64/include/asm/ptdump.h | 3 +++ arch/arm64/mm/ptdump.c | 1 + arch/arm64/mm/ptdump_debugfs.c | 34 ++++++++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h index 1f6e0aabf16a..88dcab1dab97 100644 --- a/arch/arm64/include/asm/ptdump.h +++ b/arch/arm64/include/asm/ptdump.h @@ -19,7 +19,10 @@ 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; }; 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 58a4ea975497..fe239b9af50c 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -24,6 +24,7 @@ #include #include #include +#include #include 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 Thu Oct 19 14:40:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 155614 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp432322vqb; Thu, 19 Oct 2023 07:41:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEXHue9ttze5jRzMgYnWMxxEdkplIGOhjSnMQep6pIcYVvjz7o6/1ZY9jyp+CygmIbmqlF7 X-Received: by 2002:a05:6871:4c6:b0:1e9:dfe4:743d with SMTP id n6-20020a05687104c600b001e9dfe4743dmr2602345oai.16.1697726499442; Thu, 19 Oct 2023 07:41:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697726499; cv=none; d=google.com; s=arc-20160816; b=rw6fwrjoE+tk0eLPodI4K2eqki6SepFsWYbA7+DIjnoybQZjXdoTyIVmhsK+SQ/9La 8fFxLmX/2ZeXbkGaqrVGFXJuZiz+k9OtVLhmK6QQSBfq2JDVMdTDa2HA1HcinDir6gqO FYC6pw4/m7xq3+ERnUlMMlQX6Uqxig7PWDKJIhEHYxjNT7i9LjH2dxSLT1aAs7fGKz03 LDWYJ2ump6+dKS2e/8cE6vxhBlqxDNzWuY4G/JJroy+DxuCt8CeTJXFTe2VngtZZeuBp FG4Cg+8PT/LzCJYYoVBUVgJ7ZXuPbWa/u38QeBn6jvc/vfFhB66RpiE2cUq5KQdsEr/y yZVw== 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=UJmkGO5U4r+mD7otVz2tQyDmcZmvcXpFwejzcRHVYpw=; fh=t9YKxUPg1Kt5PJ3n0c95aaxkMlch/EFXblRJVyulW1I=; b=KsZXMqx/GxWbZmBT0Xp4uWVSc5SuBIDbmnuIAXPz7xaLcV7qYetqXQH9flJofFyDey SorrkCwg50cGLtr/AUcEHhRf+as34RA6Jh+exHhrPZaFqUxrHsSOvmCgfd4Fc+HCB72t skwSKAhQxOQkSxSLq6NgLyNI+1iJZkkC311oNsW7qzn4WsgyMSuNu52mTPFFBirkbH0g fX1L1M9m1PEW1zldQGfr+TNLj55pfVh1dA6dgh41iyQLwfJWwrY3mLz6TnqUWcl9SG8M tbIsk0YtCVp43XlMSBTHgt/Ew7dSTtNuBENPFWQdohz+S2dW2Ei80ZH5yhx/9z1dNTDa AD5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=WsJGL2Fs; 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 w25-20020a637b19000000b005b861478b70si838672pgc.341.2023.10.19.07.41.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 07:41:39 -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=WsJGL2Fs; 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 0529C831D01B; Thu, 19 Oct 2023 07:41:37 -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 S1346242AbjJSOl1 (ORCPT + 25 others); Thu, 19 Oct 2023 10:41:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346274AbjJSOlK (ORCPT ); Thu, 19 Oct 2023 10:41:10 -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 67E2E12A for ; Thu, 19 Oct 2023 07:41:02 -0700 (PDT) Received: by mail-wr1-x449.google.com with SMTP id ffacd0b85a97d-325a78c806eso4096892f8f.1 for ; Thu, 19 Oct 2023 07:41:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697726461; x=1698331261; 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=UJmkGO5U4r+mD7otVz2tQyDmcZmvcXpFwejzcRHVYpw=; b=WsJGL2Fswg/vOBaSm8tzcEvZ7jDyXFd/HRggbbWT7YqxQPHMllVIK88N/SfQEz9aHC ZumNc+IQr7fZ0RbgeUCzpTCOAGjPCF1IP2hQYEV6AuCVegvnswiydecUuq4h2Ib8Ru4C Z0SMFxrtxfzPyohvhCIMpuzrMYH/KML9iUX8Hi96mZPZcmFktx5Ga3ihBfj3j64VL51n pIF4COcMS+dIciDLaJRjVWab25/JcbYNiWrJUiN8SQ0HLZaFWEMKQcFW7TzlpohiPXVb VnJgZRkmN/p3AD6PR5/ReEW/admQocuoZIx544o+NQ8QtWw7jX0YcjdxFnZoZTlSmbBz qtsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697726461; x=1698331261; 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=UJmkGO5U4r+mD7otVz2tQyDmcZmvcXpFwejzcRHVYpw=; b=suFurHvKp/WiOwNHuH/EbwE3W33R/Cffmz1CoE6uR4eK5iReZuOI4EDhL732JDhiLD p9Y450bntDHC8hiGShgiNb3UDOXZ/eJqCZ6HWo2a37GGI5wyqJaZF8dG+TuvOZI0hs+G log6AM2mB1RSn+ldejPF1s6rshRxY90Xf/Or64emFzUDjhqcueKUhbeeAKsbTYQ515kK nDzj/xigxSSAE3kSXKxUqVOovxn84jiCxdtvjK4ns8HzpdASk0wk1K9ZPhWsvOCFpwep 0qIc/82BaFRAaN0eCSXkZvhmJLWf85iCEaEPyN1bs/wZdjVpuqzJvRC55j2+vzp8zZWK usSQ== X-Gm-Message-State: AOJu0Yzg9i/4jbKXCK0gjFjUZiWAAzIiMQ/vXu8ckWoRhltnL0mg1rRW letA1tO5Gxsswbn6aizdYdfB/QNW6N0owNX7KiI= X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:a5d:4e47:0:b0:32d:d785:e457 with SMTP id r7-20020a5d4e47000000b0032dd785e457mr20381wrt.8.1697726460839; Thu, 19 Oct 2023 07:41:00 -0700 (PDT) Date: Thu, 19 Oct 2023 14:40:29 +0000 In-Reply-To: <20231019144032.2943044-1-sebastianene@google.com> Mime-Version: 1.0 References: <20231019144032.2943044-1-sebastianene@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231019144032.2943044-9-sebastianene@google.com> Subject: [PATCH v2 07/11] arm64: ptdump: Register a debugfs entry for the host stage-2 page-tables From: Sebastian Ene To: will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, vdonnefort@google.com, qperret@google.com, smostafa@google.com, Sebastian Ene X-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]); Thu, 19 Oct 2023 07:41:37 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780195262246345823 X-GMAIL-MSGID: 1780195262246345823 Initialize a structures used to keep the state of the host stage-2 ptdump walker when pKVM is enabled. Create a new debugfs entry for the host stage-2 pagetables and hook the callbacks invoked when the entry is accessed. When the debugfs file is opened, allocate memory resources which will be shared with the hypervisor for saving the pagetable snapshot. On close release the associated memory and we unshare it from the hypervisor. Signed-off-by: Sebastian Ene --- arch/arm64/include/asm/ptdump.h | 2 + arch/arm64/kvm/Kconfig | 12 +++ arch/arm64/mm/ptdump.c | 161 ++++++++++++++++++++++++++++++++ 3 files changed, 175 insertions(+) diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h index 88dcab1dab97..35b883524462 100644 --- a/arch/arm64/include/asm/ptdump.h +++ b/arch/arm64/include/asm/ptdump.h @@ -23,6 +23,8 @@ struct ptdump_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/kvm/Kconfig b/arch/arm64/kvm/Kconfig index 83c1e09be42e..4b1847704bb3 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 && KVM + help + Say Y here if you want to show the stage-2 kernel pagetables + 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 fe239b9af50c..7c78b8994ca1 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -466,6 +466,165 @@ 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 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; + phys_addr_t pgd; + + 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; + + pgd = (phys_addr_t)snapshot->pgtable.pgd; + snapshot->pgtable.pgd = phys_to_virt(pgd); + 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 void __init ptdump_register_host_stage2(void) +{ +#ifdef CONFIG_NVHE_EL2_PTDUMP_DEBUGFS + if (!is_protected_kvm_enabled()) + return; + + stage2_kernel_ptdump_info = (struct ptdump_info) { + .mc_len = host_s2_pgtable_pages(), + .ptdump_prepare_walk = stage2_ptdump_prepare_walk, + .ptdump_end_walk = stage2_ptdump_end_walk, + }; + + mutex_init(&stage2_kernel_ptdump_info.file_lock); + + ptdump_debugfs_register(&stage2_kernel_ptdump_info, + "host_stage2_kernel_page_tables"); +#endif +} + static int __init ptdump_init(void) { address_markers[PAGE_END_NR].start_address = PAGE_END; @@ -474,6 +633,8 @@ static int __init ptdump_init(void) #endif ptdump_initialize(); ptdump_debugfs_register(&kernel_ptdump_info, "kernel_page_tables"); + ptdump_register_host_stage2(); + return 0; } device_initcall(ptdump_init); From patchwork Thu Oct 19 14:40:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 155617 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp432428vqb; Thu, 19 Oct 2023 07:41:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IERVqFaOmCTkbBJFgZZUUOkee0PyTKpnoEWcUw1pCASp2rB3eRet+83twippT8xu2ibs5QU X-Received: by 2002:a05:6a20:8412:b0:17b:3cd6:b1d7 with SMTP id c18-20020a056a20841200b0017b3cd6b1d7mr2829237pzd.43.1697726507214; Thu, 19 Oct 2023 07:41:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697726507; cv=none; d=google.com; s=arc-20160816; b=AhMQ8iSE9WKY7zuF6j2rqWKR1xZG6rMGqj8y9FOktVD+fsLdCvLAISvBmmIIqQk6+D NUF0Cb/uTfv8ivVIrzFaowBBtyB0zfyiEext9OS3iq4j3zGRSwtweiXalKYXsYt6QaLj F++bXCuorrwfy3gelc4F5dwWZzQUf3i69qi3bJOeww0W68tqXRKSSm7ddxLMroTHkuUe mt/B/U0wntPnyBbNG8T7TzntxNxeWbqCd2YIpVJE0tYUe7OmaMSOvxw+CpPf6porVL2Q /wHuJNHowbaIPohwSCrDaPR9xiYqeKTRE1+uzigweCULxKc3ylP8ngIdS1uyjqDEdtIW fiTQ== 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=ElJlMelae52OVNRK43EtmIQAIoa6GhddKrR2iq/azSI=; fh=t9YKxUPg1Kt5PJ3n0c95aaxkMlch/EFXblRJVyulW1I=; b=LXQSXhcAdnuiTHYKJq/Weh5YleEZiXJtnRJyg/5DaYMgqSgvzMx6FxwjMlaT77RpIu njpJX+rYrOlR5wzcHk/ooV5AX3Y8gzc4BUXfPXU8EsKS5j15aym+MPGEEi5P8ypfe/dT AV6JUtMHcsTbFnprMuPIT8NgwrqmqC385ccSanre8KAGUQM+zsrO7qr/wKtj+gMeozx0 ImQ9w3N+KC34mCIG/TDeX+sS4B8kLrZbtu64Ev/gf/Ts+I50kUWrMaTqA4TIiPIcUoBf evbtmB/JBiHtYaAiXo2yWUOmDwYaAhTax42SU7N7inTuEkndM6UQ8ihYOd0Z9hQIOg/a UjIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=asgdwzoj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id j185-20020a638bc2000000b0055391572218si4345120pge.26.2023.10.19.07.41.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 07:41:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=asgdwzoj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id 2BE4783B7AA8; Thu, 19 Oct 2023 07:41:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346351AbjJSOlf (ORCPT + 25 others); Thu, 19 Oct 2023 10:41:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346287AbjJSOlQ (ORCPT ); Thu, 19 Oct 2023 10:41:16 -0400 Received: from mail-wm1-x349.google.com (mail-wm1-x349.google.com [IPv6:2a00:1450:4864:20::349]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C664A189 for ; Thu, 19 Oct 2023 07:41:04 -0700 (PDT) Received: by mail-wm1-x349.google.com with SMTP id 5b1f17b1804b1-4084001846eso10849185e9.1 for ; Thu, 19 Oct 2023 07:41:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697726463; x=1698331263; darn=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=ElJlMelae52OVNRK43EtmIQAIoa6GhddKrR2iq/azSI=; b=asgdwzoj6F8aCVnehYiJONbUZcey9CWQSdwYN22UB3GvoKR7giqGJuq2b/fLZyKLfU TcL+yUN3hrSq2ZrR0VzDwaZLlHaXJ+XGuXQ4fKQHehQoXTtU/ci6CXmBrBY/78JNOhvJ QB5Dtpu46gXJRLi2Sbt5lsUUs3zDTyZGtn000xirVylu5hxrIfQeQdX+rqcNkZ7NkAmo AztzYPfHADfNu1lpJpKksaBj7lkP/cc39WX9Qeqt9uA1gp4wz+zpGN+TBFvn61YO2hNu f+VwrvttLpq8DYgp7XNNbZlfNVDnb7eezeOtJqhhziF8TlfDALi9E84nfKNsnappMyPD 7ILg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697726463; x=1698331263; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ElJlMelae52OVNRK43EtmIQAIoa6GhddKrR2iq/azSI=; b=SdbPv04nbMaoLE/Irzi+IbICwp1U5RoU5xB/AyCK20jOqYREbi4E7HzewdyyelP+Li cBHJH4JUL9eW5Txw8p+TsSMl2s4WtjdjP8yQdzdrTAZYYaTSYqlhEOksvVVOoxxMMwrC Mx2i3iq4oc91/cbtqskL/bVqVymeLSovsbKe5SRo+NfszwZxvxmS0ZaGzIq14V4JfNsn oOsZBYzQdlySXLkiHf6spafTgOu3cpoWFtGspeIcKi1c+l/WoMpqFKZE6lTejPlC3sLt Db+hPq0lgZ82IsGPFRESSvu053xZGzlt+tSK2O124PxESK95MbQbZYWDU2oyXo/Hd6DI Cozw== X-Gm-Message-State: AOJu0YxrHEbUztRTgVVfuHfGjG3bsJzIHPiNYw04BDZM1/leJsa4DP73 El5VUXFcvSOOGio+CxfTe3j8cPVudsfrRbCSN5o= X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:a5d:444f:0:b0:32d:83b1:338e with SMTP id x15-20020a5d444f000000b0032d83b1338emr19447wrr.4.1697726463195; Thu, 19 Oct 2023 07:41:03 -0700 (PDT) Date: Thu, 19 Oct 2023 14:40:30 +0000 In-Reply-To: <20231019144032.2943044-1-sebastianene@google.com> Mime-Version: 1.0 References: <20231019144032.2943044-1-sebastianene@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231019144032.2943044-10-sebastianene@google.com> Subject: [PATCH v2 08/11] arm64: ptdump: Parse the host stage-2 page-tables from the snapshot From: Sebastian Ene To: will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, vdonnefort@google.com, qperret@google.com, smostafa@google.com, Sebastian Ene X-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 fry.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 (fry.vger.email [0.0.0.0]); Thu, 19 Oct 2023 07:41:44 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780195270033154926 X-GMAIL-MSGID: 1780195270033154926 Add a walker function which configures ptdump to parse the page-tables from the snapshot. Convert the physical address of the pagetable's start address to a host virtual address and use the ptdump walker to parse the page-table descriptors. Signed-off-by: Sebastian Ene --- arch/arm64/mm/ptdump.c | 63 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 7c78b8994ca1..3ba4848272df 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -479,6 +479,11 @@ static void *ptdump_host_va(phys_addr_t phys) return __va(phys); } +static struct kvm_pgtable_mm_ops host_mmops = { + .phys_to_virt = ptdump_host_va, + .virt_to_phys = ptdump_host_pa, +}; + static size_t stage2_get_pgd_len(void) { u64 mmfr0, mmfr1, vtcr; @@ -604,6 +609,63 @@ static void stage2_ptdump_end_walk(struct ptdump_info *info) free_pages_exact(snapshot, PAGE_SIZE); info->priv = NULL; } + +static int stage2_ptdump_visitor(const struct kvm_pgtable_visit_ctx *ctx, + enum kvm_pgtable_walk_flags visit) +{ + struct pg_state *st = ctx->arg; + struct ptdump_state *pt_st = &st->ptdump; + + if (st->pg_level[ctx->level].mask & ctx->old) + pt_st->note_page(pt_st, ctx->addr, ctx->level, ctx->old); + + return 0; +} + +static void stage2_ptdump_walk(struct seq_file *s, struct ptdump_info *info) +{ + struct kvm_pgtable_snapshot *snapshot = info->priv; + struct pg_state st; + struct kvm_pgtable *pgtable; + u64 start_ipa = 0, end_ipa; + struct addr_marker ipa_address_markers[3]; + struct kvm_pgtable_walker walker = (struct kvm_pgtable_walker) { + .cb = stage2_ptdump_visitor, + .arg = &st, + .flags = KVM_PGTABLE_WALK_LEAF, + }; + + if (snapshot == NULL || !snapshot->pgtable.pgd) + return; + + pgtable = &snapshot->pgtable; + pgtable->mm_ops = &host_mmops; + end_ipa = BIT(pgtable->ia_bits) - 1; + + memset(&ipa_address_markers[0], 0, sizeof(ipa_address_markers)); + + ipa_address_markers[0].start_address = start_ipa; + ipa_address_markers[0].name = "IPA start"; + + ipa_address_markers[1].start_address = end_ipa; + ipa_address_markers[1].name = "IPA end"; + + st = (struct pg_state) { + .seq = s, + .marker = &ipa_address_markers[0], + .level = pgtable->start_level - 1, + .pg_level = &stage2_pg_level[0], + .ptdump = { + .note_page = note_page, + .range = (struct ptdump_range[]) { + {start_ipa, end_ipa}, + {0, 0}, + }, + }, + }; + + kvm_pgtable_walk(pgtable, start_ipa, end_ipa, &walker); +} #endif /* CONFIG_NVHE_EL2_PTDUMP_DEBUGFS */ static void __init ptdump_register_host_stage2(void) @@ -616,6 +678,7 @@ static void __init ptdump_register_host_stage2(void) .mc_len = host_s2_pgtable_pages(), .ptdump_prepare_walk = stage2_ptdump_prepare_walk, .ptdump_end_walk = stage2_ptdump_end_walk, + .ptdump_walk = stage2_ptdump_walk, }; mutex_init(&stage2_kernel_ptdump_info.file_lock); From patchwork Thu Oct 19 14:40:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 155619 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp432539vqb; Thu, 19 Oct 2023 07:41:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH28+J8xwPtYvYC3vElYqpQE+DowTUc8V9eSOiIStThir19beE/irvlJbfei2rILX6oEE0e X-Received: by 2002:a17:90a:d40b:b0:27d:28cd:2361 with SMTP id r11-20020a17090ad40b00b0027d28cd2361mr1800499pju.49.1697726517450; Thu, 19 Oct 2023 07:41:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697726517; cv=none; d=google.com; s=arc-20160816; b=J+s57A43HU6boESSpRYjzXnxnyjEpdfbjZhZFb0OvIoplIg0RUxATD32tKKDTXhO1M +dwCkZVP3u4tDDIIdtKKQc7crLulkXSsmFGrbSQ55ouf4uUfN+vWxGbWX6qapxhH5lc8 TB/eFlxMu2obc0wEVEA/qY7X0uKq/m7gnSql/kBqInzCzrgdemrCc9OHG49Cb/xTecjY Bj0P29KX5QVAfK6IkOMTjA5F932XSA4Urn+X4jjYE776p9aTI9/BIrKgu7CEOhgs6OY1 cwIyWjD8UwdeCt2uToj3US+6J0GOjYLre5ELe61YZ0OFjRy5ihRnDKb5lBUdpCaBcimZ 2PWg== 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=CvJdm3IKmCA+/1ICly/hVREi8jIoDHSAqzssbPm75pQ=; fh=t9YKxUPg1Kt5PJ3n0c95aaxkMlch/EFXblRJVyulW1I=; b=cby4eL5ydvfnpUxBpZmB4sqCJBpBN1dBsNLvLbU5qjdMvRIE4p8D15/MXXH9Bz7IUN FXIT3jXgoGFetlW35V8dljQ651j8ym2GHyBeHsWcAetyDJVP+J44eHB3k4fW7hklb6A5 efvEAjEaCn77ZVqNHomTkuDvW0a+uBtMslXoydzlkTIFkhNar2ypRcfc6S61q3rCtrc4 R0gb25YyHtsEIS+UAjZgSqPVH4/mHN8KBvACsloQpcw48bkQ6qaaev2j2SGWQh4A/8fQ INY7ZAMWyqNptAoHh+zwi76hSL5762zl9sgevvbkWLbvhnpC+0fNcUSPZ/gxzzxHC0hq w3YA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="dDAIq8h/"; 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 w63-20020a638242000000b005a9fde46fa0si4349073pgd.130.2023.10.19.07.41.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 07:41:57 -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="dDAIq8h/"; 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 356C8831D029; Thu, 19 Oct 2023 07:41: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 S1346350AbjJSOls (ORCPT + 25 others); Thu, 19 Oct 2023 10:41:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346243AbjJSOlS (ORCPT ); Thu, 19 Oct 2023 10:41:18 -0400 Received: from mail-wm1-x349.google.com (mail-wm1-x349.google.com [IPv6:2a00:1450:4864:20::349]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CACE0D5A for ; Thu, 19 Oct 2023 07:41:07 -0700 (PDT) Received: by mail-wm1-x349.google.com with SMTP id 5b1f17b1804b1-402cd372b8bso61292325e9.2 for ; Thu, 19 Oct 2023 07:41:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697726465; x=1698331265; 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=CvJdm3IKmCA+/1ICly/hVREi8jIoDHSAqzssbPm75pQ=; b=dDAIq8h/+/3ho6ZC27ZoaLy0jU9a/H5HL5xtg5uQd3lRos/+61yuivhjWSBkH3TN4o pVOSkfITXJ0OD9aZZVhew2L77Y3kDWySsFTPPg2A9QLJP9l1UYQGfZPyHlDSOazuOhfl 8a6qk/jvsCWfSkOHCTOnqDhiRCc3qGqRZ7TbMtSoITeq2ziYcdtQ7UXjMSvGJEqzOwSJ B4FKWdjzHx3ldcQKxG0EBlTGx9J/tN5W2NUt5Olo0q7jqTHdZUYRzp8anOoq4G5GXdcI D7V+Ztn660SDAMB2CKrRmPhCAvvrtMdWjDSbpThrDRUFAf+sa7OuSBReUTRgMZ89g1pX 4TZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697726465; x=1698331265; 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=CvJdm3IKmCA+/1ICly/hVREi8jIoDHSAqzssbPm75pQ=; b=uHdchPccjsYF54WE+jbIxL+30iVZIK+J7pQAsLETL9hT8s5UdlqFhSpOAvrDetF134 xctEwY3tXnHJPugr3C+nUZ704ViADWENUeL31LHTfqnriOJuPCOPzSFhnPahRQuSrSPP 33ri/WIab0hy5BGeSNE0s2nR8am8vMHsEASmBVVWnmS1B2DvUDtwYc/RBkZviKiPl9+n 5berMbk0X/pKijWEuADdV23nOgpl3hVyGdi/PbzvN3sMJxN6rn26bzWq2Y242nsnuvcI s0WoTKlsLE6+yLyYi7dArRtCxPIPUwkur8ljI0Ry79QDNOF8sjXiiS8qVo4spXrYth2e nwZg== X-Gm-Message-State: AOJu0YyWuAbGtdNVANpBwh5OA6amvlXHnPKceTjTmIQ9CIL0aX4CtYjN oDMguEkxKeDz3cczvRCTSI7ZDGsNeSgEJ48NQWU= X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:a5d:69c8:0:b0:32d:8188:6221 with SMTP id s8-20020a5d69c8000000b0032d81886221mr22460wrw.0.1697726465577; Thu, 19 Oct 2023 07:41:05 -0700 (PDT) Date: Thu, 19 Oct 2023 14:40:31 +0000 In-Reply-To: <20231019144032.2943044-1-sebastianene@google.com> Mime-Version: 1.0 References: <20231019144032.2943044-1-sebastianene@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231019144032.2943044-11-sebastianene@google.com> Subject: [PATCH v2 09/11] arm64: ptdump: Interpret memory attributes based on runtime configuration From: Sebastian Ene To: will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, vdonnefort@google.com, qperret@google.com, smostafa@google.com, Sebastian Ene X-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]); Thu, 19 Oct 2023 07:41:55 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780195280561635601 X-GMAIL-MSGID: 1780195280561635601 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 | 66 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 3ba4848272df..5f9a334b0f0c 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, @@ -285,13 +343,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 From patchwork Thu Oct 19 14:40:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 155620 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp432866vqb; Thu, 19 Oct 2023 07:42:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHeP6SP003wgBNFy1BiaLDk8FpSCI225qIEKYlcfWxM5ETYZoi6ItZl69dIWFwEUZPJF8W2 X-Received: by 2002:a17:903:11c9:b0:1c9:bca1:d70b with SMTP id q9-20020a17090311c900b001c9bca1d70bmr2826707plh.39.1697726532743; Thu, 19 Oct 2023 07:42:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697726532; cv=none; d=google.com; s=arc-20160816; b=rg8Phsl3Lv0BHGZxhsjtF1yMKzslAL/U363KGVfHpV5Tuz2MIjujB/PLNvTTmTKDS3 8PvHZA660kqB3yHFSOLjeaC4ZYsl5tzXZzvMdFfresZhjGV0r6WhJg8Qa3lDKtHcFPiW sime4WKGTRxC3qC+LkdIbL5B4qYIFopnnu3fCEWF/k+0JzHYQqW8p7QyO6UlJOZe2yH/ 2fbLDSTPSuHbB+vzgiAacM/37WmbY65iLW++hq+ngxlVFzTsdsEwbnXigKaBY4ggrRoL 9SVSPV6M/Sp1wkhKW7FajYb2BQXoW1Mcpd91/wooSLv3VB3oFdl62jMO4zMSu8UlKTEe UFCg== 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=xftGt32Kc2uJsZHB8ze2page16/hOUtIzMgZlEPPmoQ=; fh=t9YKxUPg1Kt5PJ3n0c95aaxkMlch/EFXblRJVyulW1I=; b=ZHtkQrqQwCj+F0kIODFN97JnlCDivpfj2hwoAX1LHKOT0DkEkrZfLk80r7I6U4SyCd MBYFjYdGXR4W50HGEIHZwlaWxJgCIp/oZDUa0qQC3IqRli8WRgF6U4+VaVWQjG9fSQp4 MsUGakbOD+WIyvJ/yvSCQYN6BbmWuPPa0kcUrG+EWcqvwmORSbsTGMiWaMtss44Z9FZD A3ZqXHS5ShrI/phjGh2HWhO4Z7C7iJt1iphIulf6hJOCPCGjrT6sa19rEoV+NAV3D+8r Mde/ekBZZwWggTBa0WaopS0H/6Hg92usZ0UdPVxuVsDfXrH1l7+xzPL8aScWmk/0csCv wU1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=cniTmtkY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id l7-20020a170902f68700b001c77674ea94si2492667plg.434.2023.10.19.07.42.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 07:42:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=cniTmtkY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 7242D832CBD9; Thu, 19 Oct 2023 07:42:10 -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 S1346142AbjJSOlw (ORCPT + 25 others); Thu, 19 Oct 2023 10:41:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346306AbjJSOlT (ORCPT ); Thu, 19 Oct 2023 10:41:19 -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 1F694D64 for ; Thu, 19 Oct 2023 07:41:08 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d9a541b720aso10723683276.0 for ; Thu, 19 Oct 2023 07:41:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697726468; x=1698331268; 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=xftGt32Kc2uJsZHB8ze2page16/hOUtIzMgZlEPPmoQ=; b=cniTmtkYJaLmH8pQJm+fcRprTpm/i6WMp3vQldgSG4jStMn+UFXEdJLYhSQj98pAP1 QQIxui+VmuyQGW4vURV+xTLy152T5sCDljuJD2L9+cF+LbSokfWPZvsQMn6owxr+VoHi 5VOWJB8IwXxPwYaovkzab+Zbdpt0hn/ZFzf96vlfHfPqBbY9an+y5fHQ+/D3sSyoyF5l onrle18wjchofwHE8RJBbWg9DgepCyLk/i8KbjhKHlkcNB0agtfjkWlOu9W64UHwZNeJ BprTo7nVpZ07W0vgV1B03Ct0lHKZOvWNNWt50ibfieKeb2lAZUb7Od+g1f3eNaN3v3Up yIBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697726468; x=1698331268; 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=xftGt32Kc2uJsZHB8ze2page16/hOUtIzMgZlEPPmoQ=; b=QyDzWGED+JglXOWK0Od44QO2FaSywaiXooWiZrKluanWufZJ9QAzh+ei6OyBwGErl9 dSzvZZGZ2YbEpnY3FzfjptyjivGRoy2QRPy8lr9Oyn4iLDaQfgt6pZioRmCsWjyvBhnQ XhPf9ENbON+0MricVAd7ZRPeQ7ms9AoQWccC2aACTECFCFbXdqwCtSLMRNg9BRDEhytl aYqJMbZA0u+SW3k5cR1GYFomJETHDNaYR3XLpp7If1afs4ybeoHaRhEQa2ldg7mh/geE XGZ8pmD0RLuUv8zvtS7jy4w/5NqRY5xKE74FJg9qDHy9bhYdQZyxQne3AXJ3x5kQJ8V3 uigA== X-Gm-Message-State: AOJu0YxeZ3hGTua/dCOgvCuCZTsily0Gd1ZCLUb0iQ4jWI5W4ABNFJC2 N7IVI9VGMLs+MsR21TKxnVtfXmIw9IgClt2dLXI= X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:a05:6902:1825:b0:d9a:d272:ee58 with SMTP id cf37-20020a056902182500b00d9ad272ee58mr55549ybb.9.1697726467984; Thu, 19 Oct 2023 07:41:07 -0700 (PDT) Date: Thu, 19 Oct 2023 14:40:32 +0000 In-Reply-To: <20231019144032.2943044-1-sebastianene@google.com> Mime-Version: 1.0 References: <20231019144032.2943044-1-sebastianene@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231019144032.2943044-12-sebastianene@google.com> Subject: [PATCH v2 10/11] arm64: ptdump: Interpret pKVM ownership annotations From: Sebastian Ene To: will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, vdonnefort@google.com, qperret@google.com, smostafa@google.com, Sebastian Ene X-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]); Thu, 19 Oct 2023 07:42:10 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780195297099121239 X-GMAIL-MSGID: 1780195297099121239 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 5f9a334b0f0c..4687840dcb69 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 Thu Oct 19 14:40:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 155621 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp432899vqb; Thu, 19 Oct 2023 07:42:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGP5z5FSc9BPorhbag5Oa4VFS/JEHQ/fcbm52UTK3Keoo5rxVxVMOo2R1iPa2c9ozoMX9PV X-Received: by 2002:a05:6a20:549b:b0:152:6b63:f1e7 with SMTP id i27-20020a056a20549b00b001526b63f1e7mr2628834pzk.1.1697726536554; Thu, 19 Oct 2023 07:42:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697726536; cv=none; d=google.com; s=arc-20160816; b=jwx0rTn/VmMR8eyHg6Knjak4mU/lsr8h/itWij2f2qAcbTzsvsUCDWQmuPteprJRSv w+FkVuOwRpdxtOZBOezGIC8ia/iixMt++ES4meIKhsNy71X7SMeMRvput7sWTPqpmkAr w+7QUXjBkjvQUdaIYz0mEAX5XeFwq2AKL4URxkNPIAXr4BLWKPnpX5ys/8s4SpUooSki XFz9CR5wM5pvussP/lP9NX99LDaCjnY57qZgsaq6xPzCaVjZR64mAT77+vnv82Hn9Yfm C3EaTQscWg865yaAZrF8FkwoAIhcnZ5AEdK/oCcGPIdQ03Siq02Ux4TIaQbtadt6WAKN F2sQ== 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=2ZQaWaMMDpRzuXNNy9jw27XP1P5ogxswbyoIw1t3Xt4=; fh=t9YKxUPg1Kt5PJ3n0c95aaxkMlch/EFXblRJVyulW1I=; b=K2wKQttTtEEuNusPg0CjL3L0wAdWMt4nyYXPzC/4jP/f/ZVg756DffrztHudTiiuG7 fqnRu6iboa5XQYVauJ6MFkg3vYjy10T0d+NakDuF6Al01GYJugOAnuwF+zyQSLq5J1XL 1R6XbOrA7NwoIcf4CrWF9yRaOO7DWni1fRwuNp9WSrE09UMAahee07yoIbXK+TXGhmOH FJRh8R+Dl442ecjpoMk+HopPfH/Zth4uOz0QNZMkmLRkD7OLIxv+k3Nying7jw9U+9NV ygFpX0rBNQWQStfGQiL9L/G/LtEgWMWgOGFY5ZTgcNxa0bLMTz/ChyjxWA6Z87pBaSKv 47mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=wYlX3HJS; 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 g69-20020a636b48000000b00569561773a6si4501279pgc.549.2023.10.19.07.42.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 07:42:16 -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=wYlX3HJS; 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 4E787831D01B; Thu, 19 Oct 2023 07:42:14 -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 S235438AbjJSOlz (ORCPT + 25 others); Thu, 19 Oct 2023 10:41:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346273AbjJSOlV (ORCPT ); Thu, 19 Oct 2023 10:41:21 -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 E0F5ED7F for ; Thu, 19 Oct 2023 07:41:11 -0700 (PDT) Received: by mail-wr1-x44a.google.com with SMTP id ffacd0b85a97d-32da87eac93so2996129f8f.2 for ; Thu, 19 Oct 2023 07:41:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697726470; x=1698331270; 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=2ZQaWaMMDpRzuXNNy9jw27XP1P5ogxswbyoIw1t3Xt4=; b=wYlX3HJSv4M5BAiaIToFrO8gL49ACGr+p6JRZGHahKem8y9TkvJJa8/KCeenosBogo ASDTS8+Av1785KGCSd4xXHGjcUz9A/j97FtfQRNAArCRqq1VkeVVRTjDwCXytTakPXcq HvGqli9E8X5Pzq19gVmTnESkni8n9l5e89aPx7tZMe67yVe1gpM8zCMt1W32yRh2att5 5Pg0zcOnq/WGfQasBfue7UEBM0bFfNv/f8ApBIo77SuoWCHjp7WY9FHBfJAOVSlFxgLK ak/9cOI8+WA9rafq5ZDWg+QFrNAza3VVWDoGn/cEG8MCE6hCAWK3pjYbQeRQjJ5rFoej VRpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697726470; x=1698331270; 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=2ZQaWaMMDpRzuXNNy9jw27XP1P5ogxswbyoIw1t3Xt4=; b=T3DC2/weKPniJc94Tt2VgzQNCcbCjEJ7mJmuB9S7zkG+b0UVeryNl6tnTGzh/TSTUH EPcGuibu4g5/zetuw4mIISha2qnxCMwrxFoIWSMgCcXKfuj0MAz1UDZMC12M2eHw0CND kd3WgO3QJTN19UIHdVgbm4CPIAX6RYA38BrzTojczZtvvo1NEuKxW+NvZLFN+gpLvWgh y6B1Zs37YnfLG5EGh5hUom0QYIX0CFoV+2rXb8gAhGBHKSFSIsOKUi2Qajq319Uu5ETL w7OZaV1/YjzIELhe3R7KROtdcd88cOKX2v/wdbposGf0eznPEgH3e4V9EydsGNTl+y82 A3ww== X-Gm-Message-State: AOJu0YxondQvNwuMyhnQLuDiV0ndZttdhzDrHRg+r3va9BeOqNO62KVb hS9gy4EMIA2y2W+D8CG+DKLUFnns/WQQvWYQXtM= X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:a05:6000:1b08:b0:32d:6e24:79e8 with SMTP id f8-20020a0560001b0800b0032d6e2479e8mr20116wrz.12.1697726470227; Thu, 19 Oct 2023 07:41:10 -0700 (PDT) Date: Thu, 19 Oct 2023 14:40:33 +0000 In-Reply-To: <20231019144032.2943044-1-sebastianene@google.com> Mime-Version: 1.0 References: <20231019144032.2943044-1-sebastianene@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231019144032.2943044-13-sebastianene@google.com> Subject: [PATCH v2 11/11] arm64: ptdump: Add support for guest stage-2 pagetables dumping From: Sebastian Ene To: will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, vdonnefort@google.com, qperret@google.com, smostafa@google.com, Sebastian Ene X-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]); Thu, 19 Oct 2023 07:42:14 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780195300739951726 X-GMAIL-MSGID: 1780195300739951726 Register a debugfs file on guest creation to be able to view their second translation tables with ptdump. This assumes that the host is in control of the guest stage-2 and has direct access to the pagetables. Signed-off-by: Sebastian Ene --- arch/arm64/include/asm/ptdump.h | 21 +++++++-- arch/arm64/kvm/mmu.c | 3 ++ arch/arm64/mm/ptdump.c | 84 +++++++++++++++++++++++++++++++++ arch/arm64/mm/ptdump_debugfs.c | 5 +- 4 files changed, 108 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h index 35b883524462..be86244d532b 100644 --- a/arch/arm64/include/asm/ptdump.h +++ b/arch/arm64/include/asm/ptdump.h @@ -5,6 +5,8 @@ #ifndef __ASM_PTDUMP_H #define __ASM_PTDUMP_H +#include + #ifdef CONFIG_PTDUMP_CORE #include @@ -30,14 +32,27 @@ struct ptdump_info { void ptdump_walk(struct seq_file *s, struct ptdump_info *info); #ifdef CONFIG_PTDUMP_DEBUGFS #define EFI_RUNTIME_MAP_END DEFAULT_MAP_WINDOW_64 -void __init ptdump_debugfs_register(struct ptdump_info *info, const char *name); +struct dentry *ptdump_debugfs_register(struct ptdump_info *info, + const char *name); #else -static inline void ptdump_debugfs_register(struct ptdump_info *info, - const char *name) { } +static inline struct dentry *ptdump_debugfs_register(struct ptdump_info *info, + const char *name) +{ + return NULL; +} #endif void ptdump_check_wx(void); #endif /* CONFIG_PTDUMP_CORE */ +#ifdef CONFIG_NVHE_EL2_PTDUMP_DEBUGFS +void ptdump_register_guest_stage2(struct kvm_pgtable *pgt, void *lock); +void ptdump_unregister_guest_stage2(struct kvm_pgtable *pgt); +#else +static inline void ptdump_register_guest_stage2(struct kvm_pgtable *pgt, + void *lock) { } +static inline void ptdump_unregister_guest_stage2(struct kvm_pgtable *pgt) { } +#endif /* CONFIG_NVHE_EL2_PTDUMP_DEBUGFS */ + #ifdef CONFIG_DEBUG_WX #define debug_checkwx() ptdump_check_wx() #else diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 482280fe22d7..e47988dba34d 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -908,6 +909,7 @@ int kvm_init_stage2_mmu(struct kvm *kvm, struct kvm_s2_mmu *mmu, unsigned long t if (err) goto out_free_pgtable; + ptdump_register_guest_stage2(pgt, &kvm->mmu_lock); mmu->last_vcpu_ran = alloc_percpu(typeof(*mmu->last_vcpu_ran)); if (!mmu->last_vcpu_ran) { err = -ENOMEM; @@ -1021,6 +1023,7 @@ void kvm_free_stage2_pgd(struct kvm_s2_mmu *mmu) write_unlock(&kvm->mmu_lock); if (pgt) { + ptdump_unregister_guest_stage2(pgt); kvm_pgtable_stage2_destroy(pgt); kfree(pgt); } diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 4687840dcb69..facfb15468f5 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -26,6 +26,7 @@ #include #include #include +#include enum address_markers_idx { @@ -543,6 +544,22 @@ void ptdump_check_wx(void) #ifdef CONFIG_NVHE_EL2_PTDUMP_DEBUGFS static struct ptdump_info stage2_kernel_ptdump_info; +#define GUEST_NAME_LEN (32U) + +struct ptdump_registered_guest { + struct list_head reg_list; + struct ptdump_info info; + struct mm_struct mem; + struct kvm_pgtable_snapshot snapshot; + struct dentry *dentry; + rwlock_t *lock; + char reg_name[GUEST_NAME_LEN]; +}; + +static LIST_HEAD(ptdump_guest_list); +static DEFINE_MUTEX(ptdump_list_lock); +static u16 guest_no; + static phys_addr_t ptdump_host_pa(void *addr) { return __pa(addr); @@ -740,6 +757,73 @@ static void stage2_ptdump_walk(struct seq_file *s, struct ptdump_info *info) kvm_pgtable_walk(pgtable, start_ipa, end_ipa, &walker); } + +static void guest_stage2_ptdump_walk(struct seq_file *s, + struct ptdump_info *info) +{ + struct kvm_pgtable_snapshot *snapshot = info->priv; + struct ptdump_registered_guest *guest; + + guest = container_of(snapshot, struct ptdump_registered_guest, + snapshot); + read_lock(guest->lock); + stage2_ptdump_walk(s, info); + read_unlock(guest->lock); +} + +void ptdump_register_guest_stage2(struct kvm_pgtable *pgt, void *lock) +{ + struct ptdump_registered_guest *guest; + struct dentry *d; + + if (pgt == NULL || lock == NULL) + return; + + guest = kzalloc(sizeof(struct ptdump_registered_guest), GFP_KERNEL); + if (!guest) + return; + + memcpy(&guest->snapshot.pgtable, pgt, sizeof(struct kvm_pgtable)); + guest->info = (struct ptdump_info) { + .ptdump_walk = guest_stage2_ptdump_walk, + .priv = &guest->snapshot + }; + + mutex_init(&guest->info.file_lock); + guest->lock = lock; + mutex_lock(&ptdump_list_lock); + snprintf(guest->reg_name, GUEST_NAME_LEN, + "%u_guest_stage2_page_tables", guest_no++); + d = ptdump_debugfs_register(&guest->info, guest->reg_name); + if (!d) { + mutex_unlock(&ptdump_list_lock); + goto free_entry; + } + + guest->dentry = d; + list_add(&guest->reg_list, &ptdump_guest_list); + mutex_unlock(&ptdump_list_lock); + return; + +free_entry: + kfree(guest); +} + +void ptdump_unregister_guest_stage2(struct kvm_pgtable *pgt) +{ + struct ptdump_registered_guest *guest; + + mutex_lock(&ptdump_list_lock); + list_for_each_entry(guest, &ptdump_guest_list, reg_list) { + if (guest->snapshot.pgtable.pgd == pgt->pgd) { + list_del(&guest->reg_list); + debugfs_remove(guest->dentry); + kfree(guest); + break; + } + } + mutex_unlock(&ptdump_list_lock); +} #endif /* CONFIG_NVHE_EL2_PTDUMP_DEBUGFS */ static void __init ptdump_register_host_stage2(void) diff --git a/arch/arm64/mm/ptdump_debugfs.c b/arch/arm64/mm/ptdump_debugfs.c index 14619452dd8d..356753e27dee 100644 --- a/arch/arm64/mm/ptdump_debugfs.c +++ b/arch/arm64/mm/ptdump_debugfs.c @@ -49,7 +49,8 @@ static const struct file_operations ptdump_fops = { .release = ptdump_release, }; -void __init ptdump_debugfs_register(struct ptdump_info *info, const char *name) +struct dentry *ptdump_debugfs_register(struct ptdump_info *info, + const char *name) { - debugfs_create_file(name, 0400, NULL, info, &ptdump_fops); + return debugfs_create_file(name, 0400, NULL, info, &ptdump_fops); }