From patchwork Wed Nov 15 17:16: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: 165517 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp2687199vqg; Wed, 15 Nov 2023 09:17:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IFgE9oaO9fHQ5S0mkA0ExHh1Wil+i7XwB529fHOcKevRJsq/lU+o9MqKGViay2M7L8ALedz X-Received: by 2002:a17:902:7881:b0:1ce:33b2:a1e0 with SMTP id q1-20020a170902788100b001ce33b2a1e0mr6145470pll.33.1700068655118; Wed, 15 Nov 2023 09:17:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700068655; cv=none; d=google.com; s=arc-20160816; b=UB5+mKduhkbKggb/SFu4IKJhddNzOfJC5fNQvW3aw41mBmhoJT+nD36+bST8z5ZIdU s3BGAbfTTbgisffCOmXQsN3pw6ZQau0WBLNHgnfHVPYZn7JjiYZrT53MZM+eOAB9jKxJ ZvH7+yAq2yTwgH+afXRPMJaeo3z4h5LDIp5okHlyflEHprH+s9Xa9lhVKiI847E0e4B9 q0wutuQBaBzJn/K1V87hkYPnPmheXwLfT0zyuQd+qbsKr/V0nva4x4oP2A4CNN9icJNp kapKbz7Hr4nI93a4rVdCtvpXphffEMdb6MvMxf2teNQSq4KVpfuul/qP3sUZF1Bg4VON CR0A== 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=f5DtLWt2DkvfdlATtfwZgDQwlHPVgdWgrcJSLVV+crY=; fh=4RXM1FFjr/2FDx2f50K7N78eRirWaG15JMQkQwGVT00=; b=vw9j2a/01EytWzOcuwOuPyB+gr6cSCTZ8A8EnPKud1Q5K1W+jupbD0STZHkcaokoHM FR7zajrDYSaj0rHBUvGEQiRpsPzpJlvK2hEHLetwM1lqAaZAugzVbWq8TS6hTtJiX8mg crVwmdQ/Zl4vP02Ua369UaZ6yh228j0lBwpdDwXEWJ5WCw6Ium+2hibul7X1yhA7mTe2 u5jI/Wau9LJzUWChYs1LDoML2vPAxh9K3tNK8B0u5HaE33WBfxIJQBBpT1JcV54hCIav qR32fb9sJNlh7KswIFMNTGubpMKKgGCwnpTD5+v2hgVi+aPGZIs4b9Z4Suf4OWv21dPz LIBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="Qs/k86bC"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id jd10-20020a170903260a00b001cc330e48e5si9848118plb.103.2023.11.15.09.17.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 09:17:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="Qs/k86bC"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 98CC3801E682; Wed, 15 Nov 2023 09:17:24 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232109AbjKORRC (ORCPT + 29 others); Wed, 15 Nov 2023 12:17:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229570AbjKORRA (ORCPT ); Wed, 15 Nov 2023 12:17:00 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8587318E for ; Wed, 15 Nov 2023 09:16:56 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-da0737dcb26so8902941276.3 for ; Wed, 15 Nov 2023 09:16:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700068616; x=1700673416; 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=f5DtLWt2DkvfdlATtfwZgDQwlHPVgdWgrcJSLVV+crY=; b=Qs/k86bCvV/sNdn0I2TdLDIjYZHDATuitssoYONhKO1kRX0QLpJFal7696tJAULrPr i8j0er8mh0V8JUR7UaOUTwOO+BZAQoa4CXZzIg6BfHjJZj7xTMrBVIrIkq8f3j9zr+NS GWJmi0R9Em8EltI1rIua4HOtIUftYUMZrwKUsHj+ULxZEVoSRVxtY5xz3ZPh8y8PCyea vv+LTePu59i132i91q+WJ5EgK95u3w0t4grF9gzw2jwaeO0oz1U/MgbejzSCzPPHJ7qs OayedwyIMP2ad4QsqzvM4GFsHjfTmeI2CnZ+UQLaIO8inqOHGRucPnAqfkyEtDO0GIX6 +crQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700068616; x=1700673416; 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=f5DtLWt2DkvfdlATtfwZgDQwlHPVgdWgrcJSLVV+crY=; b=fzHvQfWjzsOMIruYpS0EBdocQxCSCMBT+CV500kmK9fgBYdnz46qeoC900KeNz21p/ 7f8+srcvLXS2azmnKjESYaSMB2GMttuA8Td4Ao+xphDnWE41rxax7hqjutSPjNiFDuKL Tzori0Y3jiLNykTHs4qNtiQWr028ArRTQpbd13gfhalejFpuj7Go+xj2z6JXGJLgt9BB PS3pHc/0pHPbY4F0Jpjv/pvFjHLaM+vhWwBSn4/THzZx5B3FJpnGuAnxRhnSQs5OC42A LeNpVjr34/QOOLhQWQXIOjBdruTxbX+gRmJGE4fABF+sMm+xY8e9I+jWlAgVXW09JDXq wM/A== X-Gm-Message-State: AOJu0Yydx2H2HZ68xq3hrBLxkKn41q9N8QoxBE7n2vKCg6dflqvckyv/ oaAQpQSbEkOwFKGxzkpY/Fl0Q2jPLxaCqhSaguI= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a05:6902:182:b0:d9a:ec95:9687 with SMTP id t2-20020a056902018200b00d9aec959687mr332837ybh.11.1700068615713; Wed, 15 Nov 2023 09:16:55 -0800 (PST) Date: Wed, 15 Nov 2023 17:16:31 +0000 In-Reply-To: <20231115171639.2852644-2-sebastianene@google.com> Mime-Version: 1.0 References: <20231115171639.2852644-2-sebastianene@google.com> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog Message-ID: <20231115171639.2852644-3-sebastianene@google.com> Subject: [PATCH v3 01/10] KVM: arm64: Add snap shooting the host stage-2 pagetables From: Sebastian Ene To: will@kernel.org, Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: kvmarm@lists.linux.dev, 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,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 15 Nov 2023 09:17:24 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782651189603255535 X-GMAIL-MSGID: 1782651189603255535 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 | 20 ++++ arch/arm64/kvm/hyp/nvhe/mem_protect.c | 102 ++++++++++++++++++ arch/arm64/kvm/hyp/pgtable.c | 56 ++++++++++ 6 files changed, 216 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..98646cc67497 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -314,6 +314,25 @@ 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) +{ +#ifdef CONFIG_NVHE_EL2_DEBUG + int ret = -EPERM; + 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); + } + cpu_reg(host_ctxt, 1) = ret; +#else + cpu_reg(host_ctxt, 0) = SMCCC_RET_NOT_SUPPORTED; +#endif +} + typedef void (*hcall_t)(struct kvm_cpu_context *); #define HANDLE_FUNC(x) [__KVM_HOST_SMCCC_FUNC_##x] = (hcall_t)handle_##x @@ -348,6 +367,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 8d0a5834e883..1c3ab5ac9110 100644 --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c @@ -266,6 +266,108 @@ 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_s2_mmu *mmu = &host_mmu.arch.mmu; + struct kvm_pgtable *to_pgt, *from_pgt = &host_mmu.pgt; + struct kvm_hyp_memcache *memcache = &snapshot->mc; + int ret; + void *pgd; + + required_pgd_len = kvm_pgtable_stage2_pgd_size(mmu->vtcr); + if (snapshot->pgd_len < required_pgd_len) + return -ENOMEM; + + to_pgt = &snapshot->pgtable; + 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 1966fdee740e..46b15d74118f 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -1598,3 +1598,59 @@ void kvm_pgtable_stage2_free_unlinked(struct kvm_pgtable_mm_ops *mm_ops, void *p WARN_ON(mm_ops->page_count(pgtable) != 1); mm_ops->put_page(pgtable); } + +#ifdef CONFIG_NVHE_EL2_DEBUG +static int stage2_copy_walker(const struct kvm_pgtable_visit_ctx *ctx, + enum kvm_pgtable_walk_flags visit) +{ + struct kvm_pgtable_mm_ops *mm_ops = ctx->mm_ops; + void *copy_table, *original_addr; + kvm_pte_t new = ctx->old; + + if (!stage2_pte_is_counted(ctx->old)) + return 0; + + if (kvm_pte_table(ctx->old, ctx->level)) { + copy_table = mm_ops->zalloc_page(ctx->arg); + if (!copy_table) + return -ENOMEM; + + original_addr = kvm_pte_follow(ctx->old, mm_ops); + + memcpy(copy_table, original_addr, PAGE_SIZE); + new = kvm_init_table_pte(copy_table, mm_ops); + } + + *ctx->ptep = new; + + return 0; +} + +int kvm_pgtable_stage2_copy(struct kvm_pgtable *to_pgt, + const struct kvm_pgtable *from_pgt, + void *mc) +{ + int ret; + size_t pgd_sz; + struct kvm_pgtable_mm_ops *mm_ops = to_pgt->mm_ops; + struct kvm_pgtable_walker walker = { + .cb = stage2_copy_walker, + .flags = KVM_PGTABLE_WALK_LEAF | + KVM_PGTABLE_WALK_TABLE_PRE, + .arg = mc + }; + + pgd_sz = kvm_pgd_pages(to_pgt->ia_bits, to_pgt->start_level) * + PAGE_SIZE; + to_pgt->pgd = (kvm_pteref_t)mm_ops->zalloc_pages_exact(pgd_sz); + if (!to_pgt->pgd) + return -ENOMEM; + + memcpy(to_pgt->pgd, from_pgt->pgd, pgd_sz); + + ret = kvm_pgtable_walk(to_pgt, 0, BIT(to_pgt->ia_bits), &walker); + mm_ops->free_pages_exact(to_pgt->pgd, pgd_sz); + + return ret; +} +#endif /* CONFIG_NVHE_EL2_DEBUG */ From patchwork Wed Nov 15 17:16: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: 165518 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp2687217vqg; Wed, 15 Nov 2023 09:17:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IHfDiBCfCDsppUvSSC0sERyLpd7zkfxSiZVaW6ZTRSi0TFl+n0HFMWkPMZm7J+FufLFDPvJ X-Received: by 2002:a05:6a21:6d96:b0:186:4430:5d16 with SMTP id wl22-20020a056a216d9600b0018644305d16mr14071345pzb.61.1700068657071; Wed, 15 Nov 2023 09:17:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700068657; cv=none; d=google.com; s=arc-20160816; b=dhCEjknvNUpmTlVRkOKG90QnI8RWaHjRUM/S+iAx+nTEOeYyS73wrgGL+5hE17uhzM hOoLkmmZ9fmFtK6Jgat4aqg89TWMY80O/n8lVGghJPioQRmeadhREZO966aTUZ1zAVEp nRCfNqopjFarpMso3XzmXvuXzsu/YFx6ExHFskuKNj6i//bRvLl/CyXMEEbPA0zIwD/e n2IrvPfGHeaUVgT+MQv9fwCbNCPXDFBLzJ+NOdp9H2nGv5DaVeLnrODDkM3tCRxyGPic eyQHuWDM7Mab/f1F3neVj5D996/nTp4+68Ogepwb7LijPJaox/FMtNn5EOEgzJ8jWhoW fjFw== 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=y0A/JzsGt28jdcT80BavCxCwKvAhE81Bu7nGud0PArE=; fh=4RXM1FFjr/2FDx2f50K7N78eRirWaG15JMQkQwGVT00=; b=GsdOg845ZLm+phGijcaziIgDfFd55c8w1DEEOQYaYUjABuDc6Jr/5pl+Pqjx8hCaF5 +P4c2DpC/kWRIJmbJoYw/cJVfQylXDayOhwzuQb7iwXMytrVqs/rpBXH8noIurCzl5zN hMgTd4kuPT3GvT9rktHsQ92igoxxqjyMgsC6Dl4GuIhYsv62EKUREKz0u2B7D+A4OFL7 ZK04gxI09wG95ajtB8BzLm1sNin+rfYFoNtmSa5cEjc4bDPB71HeYSBcgjPLtdzvCHSA aaIkK9ss43Ae0eUChBC8vkf0sEhKMy2RB782OKK4fYZsQa2R97UTJHSY+2o2qEDKB2ev Al/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=WWo5FwtP; 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 k184-20020a6384c1000000b005be0a705478si10416387pgd.89.2023.11.15.09.17.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 09:17:37 -0800 (PST) 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=WWo5FwtP; 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 C0B1E816EBD7; Wed, 15 Nov 2023 09:17:29 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232401AbjKORRE (ORCPT + 29 others); Wed, 15 Nov 2023 12:17:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231856AbjKORRC (ORCPT ); Wed, 15 Nov 2023 12:17:02 -0500 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 3E715127 for ; Wed, 15 Nov 2023 09:16:59 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-da307fb7752so8929774276.0 for ; Wed, 15 Nov 2023 09:16:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700068618; x=1700673418; 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=y0A/JzsGt28jdcT80BavCxCwKvAhE81Bu7nGud0PArE=; b=WWo5FwtPlJqJm5DvQ3UAKpvrkNXOxnLvErKLqK7nAaEjDyqK8WG2nKPnBsRgUWWgk4 JJpqpr8+5NvPaLXK3spIW68zcfV6GMVb4KXgzggr/PR0pw3eU9XgSmH9XdNRoCmZiang vIVhuLhmMeOJMpFnaCg1Nw2A4D6yJYS/7ytD7+WVWxZ+55c9eQZPQffjEO1NamHYwcJw SHGwQDizgPSSemTLQk31jv++6LlXuh8nAUrIyCEXFwxWBceg4ThWfrlh8e0TVBq0JRDP DP0sStsjpLIK3rSDeNBFycQwAFKguEJDiVsdAPR3slmHrdppj+ewIz08DV6E/5vgp+8v OlKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700068618; x=1700673418; 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=y0A/JzsGt28jdcT80BavCxCwKvAhE81Bu7nGud0PArE=; b=dXeAOqdBOYt+JxEH23fnVA1viHuzqe/XBtkGwal5Ga8k5kKPklJJ2Rr/sAcsfduVmN 7BvhtRtkpMw9WBP1FLq8UchjpG5Te4ykETohV331DttW/zo+jVt/mPIXJ6vzGV2wtH+l 94vkZevMNrrQXBj0B3IgHVUtsEcBQB0GekP0Qzq08f5Dcq7m5DJ37ofeJftKcaYvHqhQ 5/BVNV6aldVqTHM6VYl2Y/k4a8I4nUoC8hMfJHEP2udheQEdF0S+PBcmggRUB6FLgTgk tbGI8g69vFINF5vz0gmTlDMcq0iPr/hxVQJVtwNM6ek0DefJa7fdq3VG5XafIQWH9MwR Xvww== X-Gm-Message-State: AOJu0Yx13j9EKTDqRPZgvXtf3Xn3BaLAhESYnoN8/3/nxXsIks0VNsfc rjEhCRNBwnvuWqxj/9ArT0DI5xlYdxv+jUhCbgQ= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a25:3206:0:b0:da0:3da9:ce08 with SMTP id y6-20020a253206000000b00da03da9ce08mr324716yby.10.1700068618426; Wed, 15 Nov 2023 09:16:58 -0800 (PST) Date: Wed, 15 Nov 2023 17:16:32 +0000 In-Reply-To: <20231115171639.2852644-2-sebastianene@google.com> Mime-Version: 1.0 References: <20231115171639.2852644-2-sebastianene@google.com> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog Message-ID: <20231115171639.2852644-4-sebastianene@google.com> Subject: [PATCH v3 02/10] arm64: ptdump: Use the mask from the state structure From: Sebastian Ene To: will@kernel.org, Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: kvmarm@lists.linux.dev, 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,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 15 Nov 2023 09:17:29 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782651191979198528 X-GMAIL-MSGID: 1782651191979198528 Printing the descriptor attributes requires accessing a mask which has a different set of attributes for stage-2. In preparation for adding support for the stage-2 pagetables dumping, use the mask from the local context and not from the globally defined pg_level array. Store a pointer to the pg_level array in the ptdump state structure. This will allow us to extract the mask which is wrapped in the pg_level array and use it for descriptor parsing in the note_page. Signed-off-by: Sebastian Ene --- arch/arm64/mm/ptdump.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index e305b6593c4e..8761a70f916f 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -75,6 +75,7 @@ static struct addr_marker address_markers[] = { struct pg_state { struct ptdump_state ptdump; struct seq_file *seq; + struct pg_level *pg_level; const struct addr_marker *marker; unsigned long start_address; int level; @@ -252,11 +253,12 @@ static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, u64 val) { struct pg_state *st = container_of(pt_st, struct pg_state, ptdump); + struct pg_level *pg_info = st->pg_level; static const char units[] = "KMGTPE"; u64 prot = 0; if (level >= 0) - prot = val & pg_level[level].mask; + prot = val & pg_info[level].mask; if (st->level == -1) { st->level = level; @@ -282,10 +284,10 @@ static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, unit++; } pt_dump_seq_printf(st->seq, "%9lu%c %s", delta, *unit, - pg_level[st->level].name); - if (st->current_prot && pg_level[st->level].bits) - dump_prot(st, pg_level[st->level].bits, - pg_level[st->level].num); + pg_info[st->level].name); + if (st->current_prot && pg_info[st->level].bits) + dump_prot(st, pg_info[st->level].bits, + pg_info[st->level].num); pt_dump_seq_puts(st->seq, "\n"); if (addr >= st->marker[1].start_address) { @@ -316,6 +318,7 @@ void ptdump_walk(struct seq_file *s, struct ptdump_info *info) st = (struct pg_state){ .seq = s, .marker = info->markers, + .pg_level = &pg_level[0], .level = -1, .ptdump = { .note_page = note_page, @@ -353,6 +356,7 @@ void ptdump_check_wx(void) { 0, NULL}, { -1, NULL}, }, + .pg_level = &pg_level[0], .level = -1, .check_wx = true, .ptdump = { From patchwork Wed Nov 15 17:16: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: 165514 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp2686914vqg; Wed, 15 Nov 2023 09:17:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IF1m+Jotf5oISecNVCKkY9SNhHgNAJBx8SqVArvIILaDvFi5BJ6/e2dkNM44X9OFkpVdkaP X-Received: by 2002:a05:6a20:2584:b0:187:636d:a61e with SMTP id k4-20020a056a20258400b00187636da61emr2205460pzd.42.1700068633059; Wed, 15 Nov 2023 09:17:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700068633; cv=none; d=google.com; s=arc-20160816; b=LMQ/UIzCbFX45KryA3OWu+/eIz9e6k4bRL6cz9yTzp1C5dS76aUxDWjubV7/th+EXe T/wip6a6zJsqSfJl5r0TAoz+/gIvnx2M7vgJOG4jmdBckGKoDQYV1UnggHJrPhQpRWpB vFOEpVznGn7qifIRRaG1sVMTlqEyZvcPjS2NQ5FL1dhWYBPBiGy/BFYrRYZ5FCHVQ5+e Sb/A2Z/R2PG0WV3uRsb4hyTfbfaxKvckwEBhXIPz+TImRZ1Hpl4lBi13lBZJnGWtvxsv SVspWZoi5yosmuozA79sywbMTD+wv8xZqBkAGY4z2P+pZwydN75iVuO3RBSGg5/HqST5 VVrQ== 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=ancG5BntywgLYEtvolLfMGCRB6TUL9+Qsz3r5K1PW+Y=; fh=4RXM1FFjr/2FDx2f50K7N78eRirWaG15JMQkQwGVT00=; b=E9LGJE7LkzvsBpIRrwXNG0rL+ugPitLaupO8AiVb2aUD6s/u7S4FwZ/Rr0GmTDKe7C tCAt67DBwHf4LRuVsR0uMbnX4V59K/Kj1ePCJe3Fh2FXX+q87ud0ffTub5DYIBVmq8C2 y6Pa5jcHtGcqU3gssnh408uLvaCxO13nT6dtK/whF+CnvEIVfczoeTfQ61EiTRawSkFL M274ipYGG06pT9OILoQUBewwS3h41A4seV4AJeb0aiY5WrAjTD8K85PQ3mrBLOJu9r9E X6Qukhknp/yFrjp0maJKYNGxQvTqi3l4nHyAmEcx7ji0qoftqbsIDjt+EbBtEOU+wkGy cgmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=xrWsTiyC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id m14-20020a056a00080e00b006b70c01a08dsi10479587pfk.161.2023.11.15.09.17.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 09:17:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=xrWsTiyC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 354D98218232; Wed, 15 Nov 2023 09:17:12 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232552AbjKORRJ (ORCPT + 29 others); Wed, 15 Nov 2023 12:17:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232470AbjKORRF (ORCPT ); Wed, 15 Nov 2023 12:17:05 -0500 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 81E75197 for ; Wed, 15 Nov 2023 09:17:01 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-da2b8af7e89so8334817276.1 for ; Wed, 15 Nov 2023 09:17:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700068620; x=1700673420; 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=ancG5BntywgLYEtvolLfMGCRB6TUL9+Qsz3r5K1PW+Y=; b=xrWsTiyCHBiwz7mSj9bK7ctp7FaEseGHYVltxpTbsvsJ4EkO8ejqyPyA25FFtQ2kPC lRc8zKpqCSq+dTp7K8XgCFgIQbiAy7lRV11KtDDlqqCKU1NPlqKA/Ex6FySx8Oh1Cbrm w6OCt/xSgzdSrD6NgF59v7NEjkcVirfui50mPgdly6Rc04JPt2Qh750gsWJLhZ95G5/S AoA4LsXGCkRAKalKlnkEylI/d0o/N5spOyjtWl4Ep6cFNNOBhvKj0DmRiNn9e1+m7rvR nswgOvw0vuM8IOJFPwVptBjK8HiKiGkJdGGbsNktRhNhnG0SUw2M2MMTI7YW9/BPGtOl vCqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700068620; x=1700673420; 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=ancG5BntywgLYEtvolLfMGCRB6TUL9+Qsz3r5K1PW+Y=; b=IHydyqEkdiRytYXIMG4hOmlBVCjtA5UWYSEzDiKleE2LucU+yRXUDSahb3LTwBT/FQ ppUZ1r7/lbQiiCKoeU1+zwaxaGI1yEKP55Ow7Rh2PCKRr8IlCMEFJHXl7JLTvowVkVFp qBgSg5u7mjZE8bld222iF84bnTAcw2Mb9Ue+OOLO+Z6siXgP1OwbJG0s5NSRUsRAuzA5 9vcl20WceH4c6j5ZSAcEOLjV7bcUuXgQUV6e3oyUNHZ+noZHexI9YbeCTgWEGSu1hXCU HzQ1330uzXuChkgdUsO0lX0OB0VbrHevNyfUystqzX/8gicmVKhffzM6qw1YKO6RQdu5 EsqA== X-Gm-Message-State: AOJu0Yy3RXBYuJxjolvlNyxsZVUkNbcPA1W9wVn2+FFag4Id+kqBrtPy 5YWRXY7yBGmCkUa4wYnaBLwMaeZ+MxyWAlDOdaA= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a25:dcc3:0:b0:d9a:4fb2:16a2 with SMTP id y186-20020a25dcc3000000b00d9a4fb216a2mr310123ybe.12.1700068620695; Wed, 15 Nov 2023 09:17:00 -0800 (PST) Date: Wed, 15 Nov 2023 17:16:33 +0000 In-Reply-To: <20231115171639.2852644-2-sebastianene@google.com> Mime-Version: 1.0 References: <20231115171639.2852644-2-sebastianene@google.com> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog Message-ID: <20231115171639.2852644-5-sebastianene@google.com> Subject: [PATCH v3 03/10] arm64: ptdump: Add the walker function to the ptdump info structure From: Sebastian Ene To: will@kernel.org, Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: kvmarm@lists.linux.dev, 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=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 15 Nov 2023 09:17:12 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782651166868887459 X-GMAIL-MSGID: 1782651166868887459 Stage-2 needs a dedicated walk function to be able to parse concatenated pagetables. The ptdump info structure is used to hold different configuration options for the walker. This structure is registered with the debugfs entry and is stored in the argument for the debugfs file. Hence, in preparation for parsing the stage-2 pagetables add the walk function as an argument for the debugfs file. Signed-off-by: Sebastian Ene --- arch/arm64/include/asm/ptdump.h | 1 + arch/arm64/mm/ptdump.c | 1 + arch/arm64/mm/ptdump_debugfs.c | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h index 581caac525b0..1f6e0aabf16a 100644 --- a/arch/arm64/include/asm/ptdump.h +++ b/arch/arm64/include/asm/ptdump.h @@ -19,6 +19,7 @@ struct ptdump_info { struct mm_struct *mm; const struct addr_marker *markers; unsigned long base_addr; + void (*ptdump_walk)(struct seq_file *s, struct ptdump_info *info); }; void ptdump_walk(struct seq_file *s, struct ptdump_info *info); diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 8761a70f916f..d531e24ea0b2 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -346,6 +346,7 @@ static struct ptdump_info kernel_ptdump_info = { .mm = &init_mm, .markers = address_markers, .base_addr = PAGE_OFFSET, + .ptdump_walk = &ptdump_walk, }; void ptdump_check_wx(void) diff --git a/arch/arm64/mm/ptdump_debugfs.c b/arch/arm64/mm/ptdump_debugfs.c index 68bf1a125502..7564519db1e6 100644 --- a/arch/arm64/mm/ptdump_debugfs.c +++ b/arch/arm64/mm/ptdump_debugfs.c @@ -10,7 +10,8 @@ static int ptdump_show(struct seq_file *m, void *v) struct ptdump_info *info = m->private; get_online_mems(); - ptdump_walk(m, info); + if (info->ptdump_walk) + info->ptdump_walk(m, info); put_online_mems(); return 0; } From patchwork Wed Nov 15 17:16:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 165515 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp2686984vqg; Wed, 15 Nov 2023 09:17:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IEMNM+EKHhxTfUxjLoKCkZpJt5EIkqutx6JCZhLaHLCHtZRTNn5F+Fk5SL07mpW0B9v1Qoe X-Received: by 2002:a05:6a20:729a:b0:187:8bd4:e1ba with SMTP id o26-20020a056a20729a00b001878bd4e1bamr1452607pzk.37.1700068637946; Wed, 15 Nov 2023 09:17:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700068637; cv=none; d=google.com; s=arc-20160816; b=s6XC9TFabmPfuuZcGhVBc+jPWpWIiGCfqlPYd+9xs2c899Z9a5m97EYq/DpG/O+TJd B1xTlLd8D/ZbYNUa6hpF9kHZYyCx8YQvVR+8MvfSAC9Ew1YJeTTwHDLrS5v0MIWddOjZ KxA+Rj8sE7uDZvf1mj+31Fgqgm3fjPAMKmB3ZgACTmfqpbJTWpBmXnPTA78/omyBtgf1 vW8mQ+rkjH66dM7HWQikvvTc5EpkQHYmj5rkJhPXH8nYpQiA+7q5VfSUM8bh/arxVdmS YUYgHVhO11cWGm+lMo/AB8ihGpNhfixTMr3nyIB2LcpOgn8tyAfRme1JNvrBbqBECfys tWTQ== 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=tpT/Xyb5t7NIpC61c+cv5rhl4HgoVPgdS5jOtCH656U=; fh=4RXM1FFjr/2FDx2f50K7N78eRirWaG15JMQkQwGVT00=; b=YNzhmicFeGuIN+CuUoxyB12ETLVOBKS/y82WhclMlJ/TyYQJjRP157LD1pc+QQ67dH AhJsAwT3L+ETDT3T0xpROuXVIDYw+80zTzQibcKx5tBqroHmolwqPhagfqTABTNcNjFx DkeaAcMbtNr0MkMU7v1gUgs1XEb962tj7eAE7R3Rgw0EKahAdDdcbrW62UbLbEZvzKVz duJi0d2PZ5nIaExpYTMJJsT/vuI0R9ib1RktwMmJnwcvQU+t2OulVGdWnPOJlSXyN8k4 PHyLuMMmT2wqx+2+S2wwhQlukUU4LbmvY4egJhj9QK5mhyK0cAMkNZGMC3+5pXymoRy2 zgCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Gph+mQQo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id j191-20020a6380c8000000b005be1ee5ef0dsi10658788pgd.15.2023.11.15.09.17.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 09:17:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Gph+mQQo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id DF9B28218E54; Wed, 15 Nov 2023 09:17:16 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232555AbjKORRL (ORCPT + 29 others); Wed, 15 Nov 2023 12:17:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232616AbjKORRI (ORCPT ); Wed, 15 Nov 2023 12:17:08 -0500 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 DEAD4194 for ; Wed, 15 Nov 2023 09:17:03 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-da04776a869so8171333276.0 for ; Wed, 15 Nov 2023 09:17:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700068623; x=1700673423; 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=tpT/Xyb5t7NIpC61c+cv5rhl4HgoVPgdS5jOtCH656U=; b=Gph+mQQoND5MQPj23PzD8UIK16A1pJ/KynEsR9CrHIgRcATUO0fvRf04CeLqzetKjH 5rqukNqkIZspbs2PmMMaBt1KAUSOazH4odIDDPmE4xzDdBCXXjDZm4M1JbVSWw2oPvfh 70H1I9tIawUBTHDbOLYvCGConxERmHL6e6MI6iaQlmeSUoIi9lDItSZLkRFCB0xYnupX QbEye8mzNMwkLYq4u/Lc//vjsazuMb5iCe18Fl20RCIqPE1Fy71j0RJOs9fc92I4+c8E dBSwxxu8mNEmbZHWyC1i4RQEYubzfiJ+bUvz1uS11ONZoRUAdq6ihMgyQkh3AbUI7Dbx oqeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700068623; x=1700673423; 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=tpT/Xyb5t7NIpC61c+cv5rhl4HgoVPgdS5jOtCH656U=; b=Ru68Vdj3BqCi6VmV/NgEacgWNpSubn+RbujXJ8It4OCR4azLv1BLwMrY2Jrgkn3cA3 nR7Q9+I+eh8DTgqAqQ5GYw0yAEIU0NLYTcCagidme5ge/OnjmBAc45iSUK4D3jq2SEaC kbGfFjDc7zsDxE9DV3Jnv5NiXU1Ix4RV3Wz3VfEyOBDuMj/VIhdCwnsJYhy9ayu+Eq9j SHqWCJUpyg9ZkNhWMfZBsI/K65HvrOAct98YjPgI/1HFV6ilZoM7EsX7m08pdpkCMJiM t8EUztxvdiAycC2emCwZbzrhx8F8IkR0CCtnPwlymx3/WGQvf+2BbcP7KK7v0TekxxtH fKaw== X-Gm-Message-State: AOJu0Yw37l2cjet+JiJnX31PNZfgNSgS7wLXMHUKKwmeT0jVN9PpeIML nCNZWp2aq2QIk1X/j6/EMccb47Tinugv61rrKfE= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a25:4016:0:b0:da3:b880:180e with SMTP id n22-20020a254016000000b00da3b880180emr311035yba.2.1700068623070; Wed, 15 Nov 2023 09:17:03 -0800 (PST) Date: Wed, 15 Nov 2023 17:16:34 +0000 In-Reply-To: <20231115171639.2852644-2-sebastianene@google.com> Mime-Version: 1.0 References: <20231115171639.2852644-2-sebastianene@google.com> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog Message-ID: <20231115171639.2852644-6-sebastianene@google.com> Subject: [PATCH v3 04/10] KVM: arm64: Move pagetable definitions to common header From: Sebastian Ene To: will@kernel.org, Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: kvmarm@lists.linux.dev, 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=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 15 Nov 2023 09:17:16 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782651172205496274 X-GMAIL-MSGID: 1782651172205496274 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 46b15d74118f..65643320a6bb 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -17,48 +17,6 @@ #define KVM_PTE_TYPE_PAGE 1 #define KVM_PTE_TYPE_TABLE 1 -#define KVM_PTE_LEAF_ATTR_LO GENMASK(11, 2) - -#define KVM_PTE_LEAF_ATTR_LO_S1_ATTRIDX GENMASK(4, 2) -#define KVM_PTE_LEAF_ATTR_LO_S1_AP GENMASK(7, 6) -#define KVM_PTE_LEAF_ATTR_LO_S1_AP_RO \ - ({ cpus_have_final_cap(ARM64_KVM_HVHE) ? 2 : 3; }) -#define KVM_PTE_LEAF_ATTR_LO_S1_AP_RW \ - ({ cpus_have_final_cap(ARM64_KVM_HVHE) ? 0 : 1; }) -#define KVM_PTE_LEAF_ATTR_LO_S1_SH GENMASK(9, 8) -#define KVM_PTE_LEAF_ATTR_LO_S1_SH_IS 3 -#define KVM_PTE_LEAF_ATTR_LO_S1_AF BIT(10) - -#define KVM_PTE_LEAF_ATTR_LO_S2_MEMATTR GENMASK(5, 2) -#define KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R BIT(6) -#define KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W BIT(7) -#define KVM_PTE_LEAF_ATTR_LO_S2_SH GENMASK(9, 8) -#define KVM_PTE_LEAF_ATTR_LO_S2_SH_IS 3 -#define KVM_PTE_LEAF_ATTR_LO_S2_AF BIT(10) - -#define KVM_PTE_LEAF_ATTR_HI GENMASK(63, 50) - -#define KVM_PTE_LEAF_ATTR_HI_SW GENMASK(58, 55) - -#define KVM_PTE_LEAF_ATTR_HI_S1_XN BIT(54) - -#define KVM_PTE_LEAF_ATTR_HI_S2_XN BIT(54) - -#define KVM_PTE_LEAF_ATTR_HI_S1_GP BIT(50) - -#define KVM_PTE_LEAF_ATTR_S2_PERMS (KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R | \ - KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W | \ - KVM_PTE_LEAF_ATTR_HI_S2_XN) - -#define KVM_INVALID_PTE_OWNER_MASK GENMASK(9, 2) -#define KVM_MAX_OWNER_ID 1 - -/* - * Used to indicate a pte for which a 'break-before-make' sequence is in - * progress. - */ -#define KVM_INVALID_PTE_LOCKED BIT(10) - struct kvm_pgtable_walk_data { struct kvm_pgtable_walker *walker; From patchwork Wed Nov 15 17:16:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 165519 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp2687307vqg; Wed, 15 Nov 2023 09:17:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IH3D+DiffLkHHoBhnpfAL3F13GPluCsJIr9I7q4yz7p6Hci2UTypFeHNFCjQFEQnRy9kJAt X-Received: by 2002:a17:90b:4f45:b0:280:2935:af23 with SMTP id pj5-20020a17090b4f4500b002802935af23mr12280099pjb.5.1700068665953; Wed, 15 Nov 2023 09:17:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700068665; cv=none; d=google.com; s=arc-20160816; b=wHOCo85RkTJKxS9zMZ6Vaf8M3h/B6SNDNXTQL9/+e9YO3yaNDDdqHb5VM19KrNNxUo HpHbny34OzTGNEfYk8C1wycRjEy2fZRJiZuUk2t8ftds8hXHkNlcLpP+GO5gLxq93kRo r6DPKVpfAiTrqg/m7HL2wa7NyspVmCYXqQZWA3QXcMAIxR8Y08rRmMeE6bj4xQuYeFXp E7gLajkhhdUmL8L9Ku983JAV1tyJEz9f5ypK8oPgGc07kM7uNDGokgxgANeWUX/45nmr xlXtr83kKdcX89rUXh3jEG3N7iimkmvwqltS0Q+MCU34n3GKPMQHyrjQReMZ8/ECzMT5 TAcA== 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=jRY8TG/l5J/FMDXcrN4aaEldbJZIXmAxT86BWF/4hG4=; fh=4RXM1FFjr/2FDx2f50K7N78eRirWaG15JMQkQwGVT00=; b=zyBKqATJPAQ+ZBUlzp5wG7J5PFiMNnjgyCDnbfIgh1zEYShJdXx74fFQuJ7NLjHyQk J0cSa+uDHaMlwgHPGzyDyF44pejP4Dx8OxURFIDMx5geP7pnk/cf1QnP37+9DneTAMKr Gt3/l9cVNOtp1B8YduxaHxlSBKO6MK3AMH1P88dDuoE8W5GhrAFuxXvUgBx4twk7SL0d q6B3GKIajxTrmUCqAeP0g5FGrqcVxOovmpLdtNrTMItwIPlKu/ln2pPRGFNCdG1QBgcj ikqVYnjIkbmXtUByaJm0pxJXnjoPhdyVeo0S9+YtoDfGR5VjE8Ajz7Q7/c7B231+WkKE I8zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=a0jOtR2b; 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 sf12-20020a17090b51cc00b0027d3ed58c04si140740pjb.173.2023.11.15.09.17.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 09:17:45 -0800 (PST) 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=a0jOtR2b; 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 6D2B2816EBE0; Wed, 15 Nov 2023 09:17:38 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232755AbjKORRS (ORCPT + 29 others); Wed, 15 Nov 2023 12:17:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232470AbjKORRL (ORCPT ); Wed, 15 Nov 2023 12:17:11 -0500 Received: from mail-ed1-x54a.google.com (mail-ed1-x54a.google.com [IPv6:2a00:1450:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 149EE1A3 for ; Wed, 15 Nov 2023 09:17:07 -0800 (PST) Received: by mail-ed1-x54a.google.com with SMTP id 4fb4d7f45d1cf-5411a36a37fso1451452a12.0 for ; Wed, 15 Nov 2023 09:17:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700068625; x=1700673425; 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=jRY8TG/l5J/FMDXcrN4aaEldbJZIXmAxT86BWF/4hG4=; b=a0jOtR2bW8gSOXR1RXl5TD9xOBl1EvWCCofjk7dwO2AalM+bJLbX/SVx8Ym+PamlBv o+Iwt9X0GtX0UOYg8xG0IxmsquBHaRAPmJePkE/NrjtB6z5HPOflU1yZCfNXOZ1iWqvD k0lC5KWC6hcxGr234sDhKWc2pXI9Oru6xoMfd+j3K6WjrbUzCSAsNCeZj8NTNwV2yDI0 WFppN48oTZe+U4iXcVHN9vK2Ag10WopDhr3P7WFqyZaD3fyrPxR5ttd369xN8ZuDzmaV rZdCDAA/NwL5uEjNxYitwDBi8dyu2/sBTMQaenWKUQVh7V9zQ2gMESt41kKpj6Q+Pfmd GEMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700068625; x=1700673425; 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=jRY8TG/l5J/FMDXcrN4aaEldbJZIXmAxT86BWF/4hG4=; b=HjQ6JoxzfA0b7ZpgZgGYAQrQQPCIRgpThpT2y8E2Q8/Snpm6DVUpL82tIGJ7QqxjtU fRYZHFX1Hu0k9IGCYgKkZulUWfzQMwLfTdfM6XuRisI2bvfhtFQQ9MqCXqIFDRD4H+FU pi3s4s47yeBoPlNqBjudINOV0XSUiBrNN/DwGSHIIiphJsrxwo1WSw/Qwh6wDbZ+pT7P ajWU7XCPJwAQiCgic0pDC1q/Bx4ilCT7cwjAs+wssGTQkYxb8wvJvl8bpBJWOiEkwEMn IGtLgQmVYoe0lINCEGqyB3ThI4N8rSc+ENONyVa0oBmImflYd60sQuJRLOaMcAd3KbYZ N42Q== X-Gm-Message-State: AOJu0Ywo798dA7xwnlWbmqOAxqq/LqN8jQjqiDvjwRZF49z/MskjK5Iw 8msVS7uI2VbhDPhwSWk7HgyQ7F4+GPB2kWchuk8= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a05:6402:156:b0:53d:ad8a:b0bd with SMTP id s22-20020a056402015600b0053dad8ab0bdmr104536edu.3.1700068625280; Wed, 15 Nov 2023 09:17:05 -0800 (PST) Date: Wed, 15 Nov 2023 17:16:35 +0000 In-Reply-To: <20231115171639.2852644-2-sebastianene@google.com> Mime-Version: 1.0 References: <20231115171639.2852644-2-sebastianene@google.com> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog Message-ID: <20231115171639.2852644-7-sebastianene@google.com> Subject: [PATCH v3 05/10] arm64: ptdump: Add hooks on debugfs file operations From: Sebastian Ene To: will@kernel.org, Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: kvmarm@lists.linux.dev, 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,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 15 Nov 2023 09:17:38 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782651201790086709 X-GMAIL-MSGID: 1782651201790086709 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 | 7 +++++ arch/arm64/mm/ptdump_debugfs.c | 53 +++++++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h index 1f6e0aabf16a..9b2bebfcefbe 100644 --- a/arch/arm64/include/asm/ptdump.h +++ b/arch/arm64/include/asm/ptdump.h @@ -20,9 +20,16 @@ struct ptdump_info { const struct addr_marker *markers; unsigned long base_addr; void (*ptdump_walk)(struct seq_file *s, struct ptdump_info *info); + int (*ptdump_prepare_walk)(void *file_priv); + void (*ptdump_end_walk)(void *file_priv); }; void ptdump_walk(struct seq_file *s, struct ptdump_info *info); + +struct ptdump_info_file_priv { + struct ptdump_info info; + void *file_priv; +}; #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); diff --git a/arch/arm64/mm/ptdump_debugfs.c b/arch/arm64/mm/ptdump_debugfs.c index 7564519db1e6..3bf5de51e8c3 100644 --- a/arch/arm64/mm/ptdump_debugfs.c +++ b/arch/arm64/mm/ptdump_debugfs.c @@ -7,7 +7,8 @@ static int ptdump_show(struct seq_file *m, void *v) { - struct ptdump_info *info = m->private; + struct ptdump_info_file_priv *f_priv = m->private; + struct ptdump_info *info = &f_priv->info; get_online_mems(); if (info->ptdump_walk) @@ -15,7 +16,55 @@ 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; + struct ptdump_info_file_priv *f_priv; + + f_priv = kzalloc(sizeof(struct ptdump_info_file_priv), GFP_KERNEL); + if (!f_priv) + return -ENOMEM; + + memcpy(&f_priv->info, info, sizeof(*info)); + + ret = single_open(file, ptdump_show, f_priv); + if (ret) { + kfree(f_priv); + return ret; + } + + if (info->ptdump_prepare_walk) { + ret = info->ptdump_prepare_walk(f_priv); + if (ret) + kfree(f_priv); + } + + return ret; +} + +static int ptdump_release(struct inode *inode, struct file *file) +{ + struct seq_file *f = file->private_data; + struct ptdump_info_file_priv *f_priv = f->private; + struct ptdump_info *info = &f_priv->info; + + if (info->ptdump_end_walk) + info->ptdump_end_walk(f_priv); + + kfree(f_priv); + + return single_release(inode, file); +} + +static const struct file_operations ptdump_fops = { + .owner = THIS_MODULE, + .open = ptdump_open, + .read = seq_read, + .llseek = seq_lseek, + .release = ptdump_release, +}; void __init ptdump_debugfs_register(struct ptdump_info *info, const char *name) { From patchwork Wed Nov 15 17:16:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 165523 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp2687707vqg; Wed, 15 Nov 2023 09:18:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IGKiMXbWiHwFOSEaVvbtPMQELjVbMLQ61I2rNKgvnt5DthmjqOwAhHJtdEdXjfHQt2gb3Ii X-Received: by 2002:a17:902:7e88:b0:1cc:65bd:b453 with SMTP id z8-20020a1709027e8800b001cc65bdb453mr6241448pla.32.1700068697333; Wed, 15 Nov 2023 09:18:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700068697; cv=none; d=google.com; s=arc-20160816; b=IC0VB+k2QLGWQ0kES9G55s1l+1rWxnHbhnMJSgxBMmGD7eNHlAAtUeAO9tMvvOaYZ7 6rybN8IImwylQ/y6O6U71f8t/QGGBN+oxE+hXs8SztFHzuAqtFeQdn/c4TAmHsCP/sBV EvahaIFjP9gGOUwK1JAdGNZnHKLEBWx3F7ReDGfuBjz0KRl914WAWI+LCAyGaW6pUEVU 5jwQp0KOD0tF3iJmb5rS5NV6jMlb24zC7qbkP+/qE3fsn5ATkA8cCPnLlJFkl2iG0FBw gtg/TMG1tAC0+NS+LrXqhQpdjGGYDArkzpssHPC1trOeKQVLgmr+XEQV8CDlykOwF/H4 GEYg== 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=YQSSCNEgEIVwDuGH6x1IyDnQkcpfK9nBZRdIMr0v9JQ=; fh=4RXM1FFjr/2FDx2f50K7N78eRirWaG15JMQkQwGVT00=; b=wqrRT0x+c/bzS0okYpCdfyFSijTkoPZpjpxx6TeVekWnuD/gj2rx6/GRTTN03s7PRU GfG5Pc0hcwbFUz41G2CtT1UgLXX4kynwYzeJxEdsvsQ6UzH46IH+TUEYk/5UA4OlQiAk Mdum1Ey25ENOXZzitEjR40c1V3l4s3qqyivZNj6I9/lmrrxGulANJ9SzQ/pazM48cXgP 2atLIXCWIV/waokPNwR7Wr8+/XYzarrFfYV9WdADKo911oFGE+jxzUNa8/maPQV2vt+X ypjng1+UjBLEiK87X12AoMgckJTObP8RwFi7glThH6+RWOBfOIjTPhmzS7Cejtinz8zw KrhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Qu3DLHb3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id bn21-20020a056a02031500b005bd42f65dc5si10952680pgb.285.2023.11.15.09.18.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 09:18:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Qu3DLHb3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 1584A801E6A3; Wed, 15 Nov 2023 09:18:14 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232814AbjKORRW (ORCPT + 29 others); Wed, 15 Nov 2023 12:17:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232731AbjKORRS (ORCPT ); Wed, 15 Nov 2023 12:17:18 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CE44D41 for ; Wed, 15 Nov 2023 09:17:09 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d9a541b720aso8346234276.0 for ; Wed, 15 Nov 2023 09:17:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700068628; x=1700673428; 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=YQSSCNEgEIVwDuGH6x1IyDnQkcpfK9nBZRdIMr0v9JQ=; b=Qu3DLHb3ouHpCg8U+1oU+w8cAfai7IpygHBgCzatM4m0rI3MWezdGkBtvFq35ziLkU 9aEHW+L753bqjWflWVZqVVR/khUcKv4g//0CtIw9ONMd6W0BYiQIDZKf7hD0LTbN/UZZ 7wfOe5Kkxt251KoHYKJILmE7RV2EuYGp1LpfZ4NxSnvrE9Luw6FTU/i/ob6YyDskb62j e3+zY3qxz4DeK4Y1UyUJgTwzOBWvPX/jNeEhEqgJsCDKrDoG+FkGfgh8PNQsXqWJIs4X h2tEpxt6nZcpvTNK/x7SYm9AK7OeVJDEX4eGGctIR6f6/Z2eP5pOCalLVUBEapbsR4+O N1Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700068628; x=1700673428; 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=YQSSCNEgEIVwDuGH6x1IyDnQkcpfK9nBZRdIMr0v9JQ=; b=G8Q8MeWVeBS+vsdx4StiIKfyu5c6Enovp94m2+rLCZI86mWW50ec6XZYv1jXABkXqg pJfcu3eVKD6WpYUV6vIov0L+YDi20U4gXB4IMWxA4Ea1mQjs+OZteB1G9z1wou3eLs5x HwmJMrV2fgdv8aMS7tVmauT+TnPdTYw2RKlcAfp3ay+bRzdn2m/AytMkuTzrATTu1B5c yLDRMGg0lAgceEmIqmbXhkx+HmD/WYD94PLG6D0UHXnEDusWLI7WgfIGiNbNoKBiSYzH GYdnImqarT7TNacko1+HfU1G6hKGoKKpuNiaVxY+bt32nOe+uLufi4ulPLoiWKf0fwk2 j//A== X-Gm-Message-State: AOJu0Yxe3A/+pQQfyRAQvvJJpjSLGan5XBFUJtnRnE+eDhYeoVP2WH6B VytYiVaI/u0qS086a77I29bzx+CR0fHRJG6qLt0= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a05:6902:4:b0:d9a:68de:16a1 with SMTP id l4-20020a056902000400b00d9a68de16a1mr369425ybh.0.1700068628077; Wed, 15 Nov 2023 09:17:08 -0800 (PST) Date: Wed, 15 Nov 2023 17:16:36 +0000 In-Reply-To: <20231115171639.2852644-2-sebastianene@google.com> Mime-Version: 1.0 References: <20231115171639.2852644-2-sebastianene@google.com> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog Message-ID: <20231115171639.2852644-8-sebastianene@google.com> Subject: [PATCH v3 06/10] arm64: ptdump: Register a debugfs entry for the host stage-2 tables From: Sebastian Ene To: will@kernel.org, Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: kvmarm@lists.linux.dev, 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,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 15 Nov 2023 09:18:14 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782651234602419880 X-GMAIL-MSGID: 1782651234602419880 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 | 12 +++ arch/arm64/kvm/Kconfig | 13 +++ arch/arm64/kvm/arm.c | 2 + arch/arm64/mm/ptdump.c | 168 ++++++++++++++++++++++++++++++++ arch/arm64/mm/ptdump_debugfs.c | 8 +- 5 files changed, 202 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h index 9b2bebfcefbe..de5a5a0c0ecf 100644 --- a/arch/arm64/include/asm/ptdump.h +++ b/arch/arm64/include/asm/ptdump.h @@ -22,6 +22,7 @@ struct ptdump_info { void (*ptdump_walk)(struct seq_file *s, struct ptdump_info *info); int (*ptdump_prepare_walk)(void *file_priv); void (*ptdump_end_walk)(void *file_priv); + size_t mc_len; }; void ptdump_walk(struct seq_file *s, struct ptdump_info *info); @@ -33,13 +34,24 @@ struct ptdump_info_file_priv { #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); +void ptdump_debugfs_kvm_register(struct ptdump_info *info, const char *name, + struct dentry *d_entry); #else static inline void ptdump_debugfs_register(struct ptdump_info *info, const char *name) { } +static inline void ptdump_debugfs_kvm_register(struct ptdump_info *info, + const char *name, + struct dentry *d_entry) { } #endif void ptdump_check_wx(void); #endif /* CONFIG_PTDUMP_CORE */ +#ifdef CONFIG_PTDUMP_STAGE2_DEBUGFS +void ptdump_register_host_stage2(void); +#else +static inline void ptdump_register_host_stage2(void) { } +#endif /* CONFIG_PTDUMP_STAGE2_DEBUGFS */ + #ifdef CONFIG_DEBUG_WX #define debug_checkwx() ptdump_check_wx() #else diff --git a/arch/arm64/kvm/Kconfig b/arch/arm64/kvm/Kconfig index 83c1e09be42e..cf5b7f06b152 100644 --- a/arch/arm64/kvm/Kconfig +++ b/arch/arm64/kvm/Kconfig @@ -71,4 +71,17 @@ config PROTECTED_NVHE_STACKTRACE If unsure, or not using protected nVHE (pKVM), say N. +config PTDUMP_STAGE2_DEBUGFS + bool "Present the stage-2 pagetables to debugfs" + depends on NVHE_EL2_DEBUG && PTDUMP_DEBUGFS && KVM + default n + 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/kvm/arm.c b/arch/arm64/kvm/arm.c index e5f75f1f1085..987683650576 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -2592,6 +2593,7 @@ static __init int kvm_arm_init(void) if (err) goto out_subs; + ptdump_register_host_stage2(); kvm_arm_initialised = true; return 0; diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index d531e24ea0b2..0b4cb54e43ff 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -24,6 +24,9 @@ #include #include #include +#include +#include +#include enum address_markers_idx { @@ -378,6 +381,170 @@ void ptdump_check_wx(void) pr_info("Checked W+X mappings: passed, no W+X pages found\n"); } +#ifdef CONFIG_PTDUMP_STAGE2_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 int stage2_ptdump_prepare_walk(void *file_priv) +{ + struct ptdump_info_file_priv *f_priv = file_priv; + struct ptdump_info *info = &f_priv->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 -ENOMEM; + + 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) { + ret = -ENOMEM; + 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) { + ret = -ENOMEM; + 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); + f_priv->file_priv = snapshot; + return 0; + +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); + f_priv->file_priv = NULL; + return ret; +} + +static void stage2_ptdump_end_walk(void *file_priv) +{ + struct ptdump_info_file_priv *f_priv = file_priv; + struct kvm_pgtable_snapshot *snapshot = f_priv->file_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); + f_priv->file_priv = NULL; +} + +void ptdump_register_host_stage2(void) +{ + 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, + }; + + ptdump_debugfs_kvm_register(&stage2_kernel_ptdump_info, + "host_stage2_page_tables", + kvm_debugfs_dir); +} +#endif /* CONFIG_PTDUMP_STAGE2_DEBUGFS */ + static int __init ptdump_init(void) { address_markers[PAGE_END_NR].start_address = PAGE_END; @@ -386,6 +553,7 @@ static int __init ptdump_init(void) #endif ptdump_initialize(); ptdump_debugfs_register(&kernel_ptdump_info, "kernel_page_tables"); + return 0; } device_initcall(ptdump_init); diff --git a/arch/arm64/mm/ptdump_debugfs.c b/arch/arm64/mm/ptdump_debugfs.c index 3bf5de51e8c3..4821dbef784c 100644 --- a/arch/arm64/mm/ptdump_debugfs.c +++ b/arch/arm64/mm/ptdump_debugfs.c @@ -68,5 +68,11 @@ static const struct file_operations ptdump_fops = { void __init ptdump_debugfs_register(struct ptdump_info *info, const char *name) { - debugfs_create_file(name, 0400, NULL, info, &ptdump_fops); + ptdump_debugfs_kvm_register(info, name, NULL); +} + +void ptdump_debugfs_kvm_register(struct ptdump_info *info, const char *name, + struct dentry *d_entry) +{ + debugfs_create_file(name, 0400, d_entry, info, &ptdump_fops); } From patchwork Wed Nov 15 17:16:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 165516 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp2687161vqg; Wed, 15 Nov 2023 09:17:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IHRQoSHa5oU67lKJ81k45TYUYxdYSijUNQOjdPS0ms+2xkACmIcgMHKk4ZJcjpH57faZXui X-Received: by 2002:a05:6a20:548b:b0:181:9599:6957 with SMTP id i11-20020a056a20548b00b0018195996957mr18651315pzk.43.1700068652615; Wed, 15 Nov 2023 09:17:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700068652; cv=none; d=google.com; s=arc-20160816; b=U6R24VstA/KJO2tjw/r9CPmPd7LPdwl5M+RMNI1PoMxDv75yt5f2yWnG3wWjbPkrH2 AukELyJhyiPnIA3sXam0oYe5Bwc68o0xjc2ZEs8kjHYdYdPKOqH7lYpE+GxyfqVY3pVS T6RVnRz2JXxGl6TUqc2IH5qdqfCJZf1QAJs9pPZ7stt1owVIDhbYij4BjcZWztcBUb+Z Nl6lrZkZeIdmUi2sDjFDvMsuFhc9YeI8g3mRn0T5c04gdEhoep6ZVaaGdbOhsR3whpvF XU7j6769u8H+b6a9cLio9OfWljCqxFAFSsX2WrEKcVCSxd4w2dmH8JmvQz9w8u6yaIVc Z2fA== 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=zCmrW40F76i5JztVQV1SbSI81TwYB1s24Z+PnC9WnV4=; fh=4RXM1FFjr/2FDx2f50K7N78eRirWaG15JMQkQwGVT00=; b=MSX/76yQPb2oVsMR671hOjjaccMaBeGyEDWG3Ro5044p2Bbw7uCTmolwSNQz5tQZLW BR2kFhyWMiNCktfoY5VAMBNN82H/pBUvLtKPfx3/GYW0jcgFngANgGWGmyfX3z0cRxhz v8ahADg/oA1IsWAWJz/Jp79+U/DttOajJYu3kb2HfL4Lyrwoi+DnebUQDH66I/FiIXxS 0Gt09dcuPTUpz2kyTdA3Be5ccDzhQE6SV4QQ4vcO0g6p7jeNeiKMhisbEHt/neW9dhpX U4CLTeow+NTTezPw6Gwua/whVN+S/Lr817bQONBwPEjOskYi9UOiY1ZNmYRHumP/K1ju 25Sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=AmeChbNh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id j63-20020a638b42000000b005b884a11fdcsi10031853pge.28.2023.11.15.09.17.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 09:17:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=AmeChbNh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 461DB8218E56; Wed, 15 Nov 2023 09:17:31 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232758AbjKORR0 (ORCPT + 29 others); Wed, 15 Nov 2023 12:17:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231856AbjKORRS (ORCPT ); Wed, 15 Nov 2023 12:17:18 -0500 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 3E12FD50 for ; Wed, 15 Nov 2023 09:17:11 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5b59662ff67so9158107b3.0 for ; Wed, 15 Nov 2023 09:17:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700068630; x=1700673430; 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=zCmrW40F76i5JztVQV1SbSI81TwYB1s24Z+PnC9WnV4=; b=AmeChbNhKTm7edLxYyybawjHEfRVGxssTYS7nlSs0KTrolwJr3y4U0YvxftxoF1w+E q1zfrGEezUieTaUS7jKRfH7AFh8zP5jc25bnqIouAWfrHLARh6jP8n3ndhTnu9/WK1Jc 2j//Oarqec4ngFM1/hq54pI0KrjCYazSQ8Wn3qyw08jywLDRq9BeFLVtJp9JlnVdbS+l JgqTNWz6/djAsJtts0P3BpnG2XMD16NcWAaZb3lLMeq5vJtxMXadTpZuxlamnyheL87t hi6M2AaQyNOzjF8a7/RthaAwKQirBO+UAfx3l2MX8gvmjl7Pnroo5KoZ6C+wZ4iBS90n 2OYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700068630; x=1700673430; 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=zCmrW40F76i5JztVQV1SbSI81TwYB1s24Z+PnC9WnV4=; b=rUwh5SFSAYkQVoTdKI+s5OtE7wwlHDOGH6iP4AZkP5UcvB6ecEbYurMlhif30ZzgoQ wm5XDl0Dq7PwM0sxW5wQArQdoRKiTQ+kBcHk/WlFU7Lbs64EXDg13f3u6VXFXAmRX+WV wd4BCp3WWu+6fXbZAlHFURnQJrEym01hqszd89m4/iO6XsN4dM/TTXYb9WLJvwY+M1Vm Se33xQgBSNThiu/ANFRbt8vvjaQeb3LaUUQbwWQk/l1vrLmV0msQ/IklpiJxwdF8VR73 HrgfR32lLkzoycDeAog0Dl0wOawzux0YNR0eaNSQSi3/VH5OJFEWY0TTwncc+auLXlr6 bBsA== X-Gm-Message-State: AOJu0YzqjhF0F1Bbl3M4tnEMD+BhxmWpuRBHXPB5iIB8i5sf4ss8mFHU 3GDi9pjSM6Y8LOnV3Vf869NDo5lAcl/ijxuwSu4= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a0d:c046:0:b0:5be:9742:cc3e with SMTP id b67-20020a0dc046000000b005be9742cc3emr200344ywd.2.1700068630474; Wed, 15 Nov 2023 09:17:10 -0800 (PST) Date: Wed, 15 Nov 2023 17:16:37 +0000 In-Reply-To: <20231115171639.2852644-2-sebastianene@google.com> Mime-Version: 1.0 References: <20231115171639.2852644-2-sebastianene@google.com> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog Message-ID: <20231115171639.2852644-9-sebastianene@google.com> Subject: [PATCH v3 07/10] arm64: ptdump: Parse the host stage-2 page-tables from the snapshot From: Sebastian Ene To: will@kernel.org, Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: kvmarm@lists.linux.dev, 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=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 15 Nov 2023 09:17:31 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782651187922844751 X-GMAIL-MSGID: 1782651187922844751 Add a walker function which configures ptdump to parse the page-tables from the snapshot. Define the attributes used by the stage-2 parser and build a description of an array which holds the name of the level. Walk the entire address space configured in the pagetable and parse the attribute descriptors. Signed-off-by: Sebastian Ene --- arch/arm64/mm/ptdump.c | 157 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 0b4cb54e43ff..9f88542d5312 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -86,6 +86,7 @@ struct pg_state { bool check_wx; unsigned long wx_pages; unsigned long uxn_pages; + struct ptdump_info_file_priv *f_priv; }; struct prot_bits { @@ -174,6 +175,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; @@ -286,6 +347,7 @@ static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, delta >>= 10; unit++; } + pt_dump_seq_printf(st->seq, "%9lu%c %s", delta, *unit, pg_info[st->level].name); if (st->current_prot && pg_info[st->level].bits) @@ -394,6 +456,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; @@ -528,6 +595,95 @@ static void stage2_ptdump_end_walk(void *file_priv) f_priv->file_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; + + pt_st->note_page(pt_st, ctx->addr, ctx->level, ctx->old); + + return 0; +} + +static void stage2_ptdump_build_levels(struct pg_level *level, + size_t num_levels, + unsigned int start_level) +{ + static const char * const lvl_names[] = {"PGD", "PUD", "PMD", "PTE"}; + int i, j, name_index; + + if (num_levels > KVM_PGTABLE_MAX_LEVELS && start_level > 2) { + pr_warn("invalid configuration %lu levels start_lvl %u\n", + num_levels, start_level); + return; + } + + for (i = start_level; i < num_levels; i++) { + name_index = i - start_level; + name_index = name_index * start_level + name_index; + + level[i].name = lvl_names[name_index]; + level[i].num = ARRAY_SIZE(stage2_pte_bits); + level[i].bits = stage2_pte_bits; + + for (j = 0; j < level[i].num; j++) + level[i].mask |= level[i].bits[j].mask; + } +} + +static void stage2_ptdump_walk(struct seq_file *s, struct ptdump_info *info) +{ + struct ptdump_info_file_priv *f_priv = + container_of(info, struct ptdump_info_file_priv, info); + struct kvm_pgtable_snapshot *snapshot = f_priv->file_priv; + struct pg_state st; + struct kvm_pgtable *pgtable; + u64 start_ipa = 0, end_ipa; + struct addr_marker ipa_address_markers[3]; + struct pg_level stage2_pg_level[KVM_PGTABLE_MAX_LEVELS] = {0}; + 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"; + + stage2_ptdump_build_levels(stage2_pg_level, KVM_PGTABLE_MAX_LEVELS, + pgtable->start_level); + + st = (struct pg_state) { + .seq = s, + .marker = &ipa_address_markers[0], + .level = -1, + .pg_level = &stage2_pg_level[0], + .f_priv = f_priv, + .ptdump = { + .note_page = note_page, + .range = (struct ptdump_range[]) { + {start_ipa, end_ipa}, + {0, 0}, + }, + }, + }; + + kvm_pgtable_walk(pgtable, start_ipa, end_ipa, &walker); +} + void ptdump_register_host_stage2(void) { if (!is_protected_kvm_enabled()) @@ -537,6 +693,7 @@ void 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, }; ptdump_debugfs_kvm_register(&stage2_kernel_ptdump_info, From patchwork Wed Nov 15 17:16:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 165522 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp2687594vqg; Wed, 15 Nov 2023 09:18:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IF09BUDkHNJ736ecZPbAFJMRt58KtIP41jMdtbmsdvYJRU5/NiXxfybelQ4oT/wyhoH61WL X-Received: by 2002:a05:6a00:348d:b0:6c0:4006:4195 with SMTP id cp13-20020a056a00348d00b006c040064195mr18038120pfb.0.1700068688349; Wed, 15 Nov 2023 09:18:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700068688; cv=none; d=google.com; s=arc-20160816; b=0R/ZUnHiq3Sx9x4TsOggORGSuIQ+rMAmACCqUcLFnmMECZpKjiD/IBoDEOVo0030qh 7kpC3PXSJiCjrd4h3+sqHMmP3bFtaPBwHg5m4VXOuwuAVP7BasxrfxHZJZJV35zYSlC7 VC2SyKoarFe3TBFN7b+/1V4ZJDAYXwRovXvlDRYgKNw/he9sy3ZgZuwYJUjg0hKTQgrG Ah/eYe4ufLELP0L21FL4l3PjM6RTsVQgiUEasejFqtYXswXKNxYj7dxwT4TNV2cSlog7 mvHasBwMSYCZahvk11eLaef6nlApVbs2NcvMWYZmIe5/B0/VzK3lcnHHEz9Sm5BVQCTh ulbQ== 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=Qy3zX0s6ALtK+DaG4wUXBjQ8F6aHRpWpiFcWV1cr/U0=; fh=4RXM1FFjr/2FDx2f50K7N78eRirWaG15JMQkQwGVT00=; b=jZk2N6UPZEK3xoALCCyS3e+SXqErUdTl+4GLLTLMkaBSH+DmX/MewPYL8EA6Thnbmt Bkbmd+O2Y/ON/223GBrpDsakHHCKvttxSxq7zKTm7VVNsxwYq7/GTFlPtkzeExI9s+eh 4j5JQ8/ZVl4heUaGtU0Vzdp99d/0KYRxBBNyffSXlb4cWcpZScZXgW51JLz4QoPoWzNk N4xuB89gBCGpzY5zgoeIIEEYL1slZCtdPSybChAh7cFmPAnr8yvdrmcoIyqg3F3JBkWn 9VNOrpvYJ28fGeeLFnpQdzDeZmK/hkX3MXc6EEadMMus0tJJeHNu5HwhO36hD8DCm/mR t1TQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="nR6PK/+0"; 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 k20-20020a056a00135400b006c34028e37dsi10597895pfu.219.2023.11.15.09.18.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 09:18:08 -0800 (PST) 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="nR6PK/+0"; 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 E22E5816EBD1; Wed, 15 Nov 2023 09:18:05 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232401AbjKORRe (ORCPT + 29 others); Wed, 15 Nov 2023 12:17:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232740AbjKORRU (ORCPT ); Wed, 15 Nov 2023 12:17:20 -0500 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 1326AD6D for ; Wed, 15 Nov 2023 09:17:13 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5afa071d100so148844227b3.1 for ; Wed, 15 Nov 2023 09:17:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700068633; x=1700673433; 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=Qy3zX0s6ALtK+DaG4wUXBjQ8F6aHRpWpiFcWV1cr/U0=; b=nR6PK/+008SAq1seEfnKT0/2+xngpAiBhIDUKWLk9c1hrMWjUTVQYqYRgJPk4tVW2X izvzNx860G2ZjZzxR0ovojefWBqeKkw/Xb38sxkommQqbLg0oLn1R6Pe4ktjQ0igd5ny X9iSg79JjqQII7PDb8NorG8pxLRsl/ieLWAtGaetNLzdyiLB+55rUvJyH7GRZCjkD1wG J3U+DHc2ngwQ5MHrTmAu+z1qGuMymab3Bni8qMG0Lm376qooO7uV/cOps0YK90h0KXUi FJSkFrS5qM3jXwktXZORAD8rzUAV7KhHNFoT/IXxBvWM+nydqE5Ozcn8w5zZEnBXQbly VYjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700068633; x=1700673433; 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=Qy3zX0s6ALtK+DaG4wUXBjQ8F6aHRpWpiFcWV1cr/U0=; b=LCqowOE5zxCwDybV+7YiLP6yQr7fyMdepqrmRImy75iQYxiz66mgXA8DDid2/JqYER w2BZCtYArvj0Ed3gycXbuceR6lpvF6a5uxfqKo/2+zOUGp9KERFYvw4hqpHfM/5dMqCd pZm2x8cozquyDU4r4Z0paXoZRqmkv7fq/lv20y7OXOcvYfO7B/e9jXcEncJa25gvWsMi OLqW8md3dN7m5wKuo92qR3D1VPM+wGCACnntEtKUsQHJ5qt3In6Pgz9VuEj9wRvGXafJ cGBs8jaZtkMoc0EfU46Ke/TM9/Qa+5bV9hkCfHtk/LpQwPfNmEVgrAziAVSPLaC4yB6l 0KFw== X-Gm-Message-State: AOJu0YxoQZ7ElQGQ6IW1XEF+/WagcK1h/Q83A21friVyG4SXYfrC95Tq 0g/G+3NL3A2XvprZ6FF6vQtKq7E/FSHk+2fpb7w= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a0d:d7c3:0:b0:5a7:b672:4d88 with SMTP id z186-20020a0dd7c3000000b005a7b6724d88mr356731ywd.0.1700068633096; Wed, 15 Nov 2023 09:17:13 -0800 (PST) Date: Wed, 15 Nov 2023 17:16:38 +0000 In-Reply-To: <20231115171639.2852644-2-sebastianene@google.com> Mime-Version: 1.0 References: <20231115171639.2852644-2-sebastianene@google.com> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog Message-ID: <20231115171639.2852644-10-sebastianene@google.com> Subject: [PATCH v3 08/10] arm64: ptdump: Interpret memory attributes based on runtime configuration From: Sebastian Ene To: will@kernel.org, Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: kvmarm@lists.linux.dev, 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,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 15 Nov 2023 09:18:05 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782651224665090306 X-GMAIL-MSGID: 1782651224665090306 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 | 65 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 9f88542d5312..ec7f6430f6d7 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -89,11 +89,19 @@ struct pg_state { struct ptdump_info_file_priv *f_priv; }; +/* + * 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[] = { @@ -175,6 +183,34 @@ static const struct prot_bits pte_bits[] = { } }; +static bool is_fwb_enabled(const void *ctx) +{ + const struct pg_state *st = ctx; + struct ptdump_info_file_priv *f_priv = st->f_priv; + struct kvm_pgtable_snapshot *snapshot = f_priv->file_priv; + struct kvm_pgtable *pgtable = &snapshot->pgtable; + + bool fwb_enabled = false; + + if (cpus_have_final_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, @@ -216,6 +252,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, @@ -267,13 +324,19 @@ static struct pg_level 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 Wed Nov 15 17:16:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 165521 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp2687464vqg; Wed, 15 Nov 2023 09:17:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IHQxy/F4npoFI5Ph+jNnMxTPzphNPBVR5CWnNvLWQa5HAAPg0TaH2IGmgvfsbmCbMr0OZG0 X-Received: by 2002:a05:6a00:1394:b0:6c6:1648:5ac6 with SMTP id t20-20020a056a00139400b006c616485ac6mr13801363pfg.5.1700068666988; Wed, 15 Nov 2023 09:17:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700068666; cv=none; d=google.com; s=arc-20160816; b=l6ONqzCUHJWWxajQ+67YdxtK1saW/qy3Lq8kSxcOZQgMs3yi4W0U1KVW2TXhPht17O /1ir80CRP9qj9gOZvBEljfZU+6DNSaI0MF5m8I0msfdmq1nEI7HQhgR2H/oRqRdkyPLw XCukQccALL71zKWA+p3klFUcmSockgiIdvnGbHXlgcEu1Q8sRfQaFliEccf80DMExWX0 H3NPh/3H1tAu+rvUTz7TfTTvHBDaab/UueKKzIjHtLpnLDtZn8ifFvYcgbF30cQR4cDB pBHOMZNFc+QSWahCRzqEGZJmp2/7+W+zGahgf4rF52Ec4uCjSHrZJkqVJ2QMxwBcmDYU oxGg== 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=cTRruPNWl9dydwy1RolnY7MN//AZ8WOLTxliFM7mi1c=; fh=4RXM1FFjr/2FDx2f50K7N78eRirWaG15JMQkQwGVT00=; b=mJQhPs1Jfxw4+sJp369T8EdpDr+ax/dH8T+JejEzm8YZ3uBYKE3tcD9Ez4MVOphw96 nCgRz3brgos/Aq65z9Dw/KymKhL+6oR0AE26HBRCrFZZdl3bDrwcPVQFSohK1A3Wehpy bijEqE8pLnSBvYPr90q0nV7Lp2HejJXnRj2zYFmATIylKkLWewepM+UwjF8ze+9GzV7M 9DVX5JyXfW++G7GGWV6GxLOpzC58KoodW0A9kS1iXOQWS2Y0/SwkUEYuDv63XHFToExj +25N0sugUmd1K2N6K9AOmTJasucWKa8Vv1ZbxlOjMOeqAmzIXNjS1aHO7kL+XtpMyDsR 8h/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Ee4aX3M0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id f20-20020a056a00239400b006cab3f87536si401966pfc.389.2023.11.15.09.17.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 09:17:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Ee4aX3M0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 295438218E68; Wed, 15 Nov 2023 09:17:46 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232727AbjKORRi (ORCPT + 29 others); Wed, 15 Nov 2023 12:17:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232690AbjKORRZ (ORCPT ); Wed, 15 Nov 2023 12:17:25 -0500 Received: from mail-ed1-x54a.google.com (mail-ed1-x54a.google.com [IPv6:2a00:1450:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12F871BE for ; Wed, 15 Nov 2023 09:17:16 -0800 (PST) Received: by mail-ed1-x54a.google.com with SMTP id 4fb4d7f45d1cf-547c18fce15so804734a12.2 for ; Wed, 15 Nov 2023 09:17:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700068635; x=1700673435; 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=cTRruPNWl9dydwy1RolnY7MN//AZ8WOLTxliFM7mi1c=; b=Ee4aX3M0Cz10ArioXTmvE8wNns63vmFuKJ/gPkllXdcBGxkbLd1QQJG2HGxEIpHWxg DOj/0+3mUGT4SWnJRIg7ZoTJOoXlofm0+HCkkkstmXJ3Wx8pkm1PYRbgemSvs8nyxYqY v6S39B3wXFOoh11qvG/k7hRMHckt3iEv6asthjBkZRX3IiGHbKHeQ/gUcvM/kdW9lGRz IMIkIpyzsUfkt/K0rF5XtpstMkDogZntS8WNP62n55aODy6r0qVd+pm+gaVBQvIiUu5n 11Zi64X0sPjSckPp/d8emfJlWTEQT3LTBr5VODcuvaisIRLIdt+8SS0jTpoWj0V7kNW/ pV9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700068635; x=1700673435; 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=cTRruPNWl9dydwy1RolnY7MN//AZ8WOLTxliFM7mi1c=; b=XAKkMdwRmHHjH8BIu0pNzHD52FyHD0I4GTKXP2gn+aEU9lZhrJ1GzDip+ABtdrf7io oRTKEHFO+jFXMKyJCfdIZUaDVmnuJnojsvuLUravP3TOOy8LPTO+qGiKYZK2Tc6iq+tR gaxuajJ+7yLqKxHf1+eK1BW6Z8MpsF0WV1z5etwg0q7pnmBGVHh3oMCFAm1HLXqA7r8N FzSf5UrVQqx9AkLlVifbiNrcbf3HnQOwJaykT/ezi2pHtM01tx1xrBzX5+P19exvbxhs KdBXiBVxfhLJJO0+jLpHHfVEuJqxRGVkjVtG6j7d3NWCAJYVxTS+CvAXfXjC7gjihL6X PK5w== X-Gm-Message-State: AOJu0Yz5AP8ILNPNsxK5EBF/YeLcrl5TROR+aIkg0eYj1mcIgRjs2pkg PyeIuTiJ7Cm1H9AdZ5enmzoEa6pyXLhUFp63lbs= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a17:906:6bc9:b0:9c4:1dfa:de9 with SMTP id t9-20020a1709066bc900b009c41dfa0de9mr121012ejs.10.1700068635336; Wed, 15 Nov 2023 09:17:15 -0800 (PST) Date: Wed, 15 Nov 2023 17:16:39 +0000 In-Reply-To: <20231115171639.2852644-2-sebastianene@google.com> Mime-Version: 1.0 References: <20231115171639.2852644-2-sebastianene@google.com> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog Message-ID: <20231115171639.2852644-11-sebastianene@google.com> Subject: [PATCH v3 09/10] arm64: ptdump: Interpret pKVM ownership annotations From: Sebastian Ene To: will@kernel.org, Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: kvmarm@lists.linux.dev, 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=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 15 Nov 2023 09:17:46 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782651202485710891 X-GMAIL-MSGID: 1782651202485710891 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 ec7f6430f6d7..ffb87237078b 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -273,6 +273,16 @@ static const struct prot_bits stage2_pte_bits[] = { .val = PTE_S2_MEMATTR(MT_S2_FWB_NORMAL) | PTE_VALID, .set = "MEM/NORMAL FWB", .feature_on = is_fwb_enabled, + }, { + .mask = KVM_INVALID_PTE_OWNER_MASK | PTE_VALID, + .val = FIELD_PREP_CONST(KVM_INVALID_PTE_OWNER_MASK, + PKVM_ID_HYP), + .set = "HYP", + }, { + .mask = KVM_INVALID_PTE_OWNER_MASK | PTE_VALID, + .val = FIELD_PREP_CONST(KVM_INVALID_PTE_OWNER_MASK, + PKVM_ID_FFA), + .set = "FF-A", }, { .mask = KVM_PGTABLE_PROT_SW0, .val = KVM_PGTABLE_PROT_SW0, From patchwork Wed Nov 15 17:16:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 165520 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp2687388vqg; Wed, 15 Nov 2023 09:17:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IHLSys3+1fe8NAO+AJZTtOpSyfObypaZRZJhK2o3mIoHU+lfiU/NxPS3ObXGyhTfnmY+kIh X-Received: by 2002:a05:6a20:9183:b0:160:97a3:cae9 with SMTP id v3-20020a056a20918300b0016097a3cae9mr15669959pzd.54.1700068671873; Wed, 15 Nov 2023 09:17:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700068671; cv=none; d=google.com; s=arc-20160816; b=uNTxQwGl7E+K+15AM1gHR8k8Lxf3YbsJnuOYd7VS6Iit0v4PKfQlM7sG0sBAraTQ+n mrXi9AVa4NpI5hkHo5oDFKAlDKv5LV+tJtU8LVLXDoWTBFAt7hBTfxaptlEilZBrRAp2 zr9MABbPqMy1MpzhIoKAJkQGmrzI01nSiMOmPQ5fOCZcg2rpuYddWvezC1GsvNq3J4W/ 59NpTiFgHzBWG3WEOuHVvO1banba2ylpR3BfIjIi2PNpP8kIW0XnYLAiRlUtkYX5IZDb dJ7NDOOQstTdpzl7XH9p28H4Xn6CF1Jt6RJT6VR17mh23invAtqskD3A+mnr2Wd+W1H5 dm+Q== 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=MrwZCdoLZEaizVhQil7JgumATiKs+C+flcugI0w/XAk=; fh=4RXM1FFjr/2FDx2f50K7N78eRirWaG15JMQkQwGVT00=; b=ZKghhsHWCndDdWLsh41caZq6FF3ja9WSKKnxaby4QB8QCzeDqWtxkWeWSmauXWTYUg orAIjZ/lw6fWED5+Fn2A0x1TmQFzVxxv1QCrXh/tG1aSWuwubp3YylpSPSs5I9NJRC/G hWVcU3rG9Bahaa7Y84EwrATLGerjWGlzu3/aILRJFd92Rlsm29ENOWiFlu6SatdwPNSN xlkTD7nlbGQdt+JRhm9OoA1bNpldweVJ56cpPeD035cj3MUdwFkpAxDKTjpIRRXBTAAf aNcsfJD27a6IanTF/gWpQi4rcNwZqmofNaUIh/V4fHNrWnP0vol+jiPgNaxB1J+GtAfo XXBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ilaHSqDQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id n4-20020a62e504000000b0068a590d8043si10064112pff.375.2023.11.15.09.17.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 09:17:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ilaHSqDQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id C1F5A8218E6D; Wed, 15 Nov 2023 09:17:50 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232718AbjKORRr (ORCPT + 29 others); Wed, 15 Nov 2023 12:17:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232882AbjKORRa (ORCPT ); Wed, 15 Nov 2023 12:17:30 -0500 Received: from mail-ej1-x64a.google.com (mail-ej1-x64a.google.com [IPv6:2a00:1450:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2DA11B5 for ; Wed, 15 Nov 2023 09:17:19 -0800 (PST) Received: by mail-ej1-x64a.google.com with SMTP id a640c23a62f3a-9e5e190458dso38646566b.1 for ; Wed, 15 Nov 2023 09:17:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700068637; x=1700673437; 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=MrwZCdoLZEaizVhQil7JgumATiKs+C+flcugI0w/XAk=; b=ilaHSqDQ5bh0Ymcf6aEog7jgYtJflF17F5Juuav/YzOzQEn1y7Z5C/2bDzQPbsgFWD TXapbLxAth4ruLN5P7kBZezRU5Io6lMb83N+ed/48kKSNCRvq0PM65DWNTzTOvQSpkWA 6vu7ftwE6fOnLXU9VfdHFQeZgfSTnn8oBVFGRG1XkO1yaPN39pOaZLqK3Z/ut3kXoLqe 1LEFbKSxPsZsgcGV/dQcoNboMiwqdgHq4v+ELt0akb6HQTfVISixxyq3nS+HKRRzcwiW /G2sTi4GR5YT9x0zZWzuK1knRARU5TLSwRn6iwD60h6PBCSNchMXObMGKEf2jTyU/FaZ a79A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700068637; x=1700673437; 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=MrwZCdoLZEaizVhQil7JgumATiKs+C+flcugI0w/XAk=; b=oKG8Yyovtcde3w8zPgvDZUSZJ4Wn76dltr8kCSSoLRsVmtiKqFMWao+lp8wlqWdXCP 9OI4tkb3pHGtziY0PoQs1dJSDOrrpavXuQFYGtV1xwl2hqAfRpiu8clc9ZpmdPzp1WPR wVwFfZfJ2xjcUju9IkL/UBRWSEO/tvHcoSn5pDhCMmO3dg7//bUysCgKzRVY7Ie3OVk9 RBZLuXiQUdRHbdZwd8pJNCjDfANvNQpwpwPtp9RcBQcDWuYN/iFGoTJmwPSGhPyBYnXf SKgdsiC3tX91PUfqLz8EmT24/eCjLroAxf/wXEz0nfFd6gjXt3c+EV+8ke7QIF1dybOk z5hw== X-Gm-Message-State: AOJu0YzrEw+Wag1KmSxd18KBNosEMZoCQ1Gu8EKFv/9uf//Nil+lMjTU QMPVGCR7qgohNXqn0kESrgrDxjqbU9O/WyX2Mjs= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a17:906:a00f:b0:9f3:6556:bc79 with SMTP id p15-20020a170906a00f00b009f36556bc79mr19663ejy.0.1700068637537; Wed, 15 Nov 2023 09:17:17 -0800 (PST) Date: Wed, 15 Nov 2023 17:16:40 +0000 In-Reply-To: <20231115171639.2852644-2-sebastianene@google.com> Mime-Version: 1.0 References: <20231115171639.2852644-2-sebastianene@google.com> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog Message-ID: <20231115171639.2852644-12-sebastianene@google.com> Subject: [PATCH v3 10/10] arm64: ptdump: Add support for guest stage-2 pagetables dumping From: Sebastian Ene To: will@kernel.org, Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: kvmarm@lists.linux.dev, 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=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 15 Nov 2023 09:17:50 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782651207354480844 X-GMAIL-MSGID: 1782651207354480844 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 | 7 ++++ arch/arm64/kvm/debug.c | 6 +++ arch/arm64/kvm/mmu.c | 2 + arch/arm64/mm/ptdump.c | 68 +++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+) diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h index de5a5a0c0ecf..21b281715d27 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 @@ -23,6 +25,7 @@ struct ptdump_info { int (*ptdump_prepare_walk)(void *file_priv); void (*ptdump_end_walk)(void *file_priv); size_t mc_len; + void *priv; }; void ptdump_walk(struct seq_file *s, struct ptdump_info *info); @@ -48,8 +51,12 @@ void ptdump_check_wx(void); #ifdef CONFIG_PTDUMP_STAGE2_DEBUGFS void ptdump_register_host_stage2(void); +int ptdump_register_guest_stage2(struct kvm *kvm); +void ptdump_unregister_guest_stage2(struct kvm_pgtable *pgt); #else static inline void ptdump_register_host_stage2(void) { } +static inline int ptdump_register_guest_stage2(struct kvm *kvm) { return 0; } +static inline void ptdump_unregister_guest_stage2(struct kvm_pgtable *pgt) { } #endif /* CONFIG_PTDUMP_STAGE2_DEBUGFS */ #ifdef CONFIG_DEBUG_WX diff --git a/arch/arm64/kvm/debug.c b/arch/arm64/kvm/debug.c index 8725291cb00a..555d022f8ad9 100644 --- a/arch/arm64/kvm/debug.c +++ b/arch/arm64/kvm/debug.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "trace.h" @@ -342,3 +343,8 @@ void kvm_arch_vcpu_put_debug_state_flags(struct kvm_vcpu *vcpu) vcpu_clear_flag(vcpu, DEBUG_STATE_SAVE_SPE); vcpu_clear_flag(vcpu, DEBUG_STATE_SAVE_TRBE); } + +int kvm_arch_create_vm_debugfs(struct kvm *kvm) +{ + return ptdump_register_guest_stage2(kvm); +} diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index d87c8fcc4c24..da45050596e6 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -1021,6 +1022,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 ffb87237078b..741764cff105 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -27,6 +27,7 @@ #include #include #include +#include enum address_markers_idx { @@ -519,6 +520,16 @@ void ptdump_check_wx(void) #ifdef CONFIG_PTDUMP_STAGE2_DEBUGFS static struct ptdump_info stage2_kernel_ptdump_info; +struct ptdump_registered_guest { + struct list_head reg_list; + struct ptdump_info info; + struct kvm_pgtable_snapshot snapshot; + rwlock_t *lock; +}; + +static LIST_HEAD(ptdump_guest_list); +static DEFINE_MUTEX(ptdump_list_lock); + static phys_addr_t ptdump_host_pa(void *addr) { return __pa(addr); @@ -757,6 +768,63 @@ 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 ptdump_info_file_priv *f_priv = + container_of(info, struct ptdump_info_file_priv, info); + struct ptdump_registered_guest *guest = info->priv; + + f_priv->file_priv = &guest->snapshot; + + read_lock(guest->lock); + stage2_ptdump_walk(s, info); + read_unlock(guest->lock); +} + +int ptdump_register_guest_stage2(struct kvm *kvm) +{ + struct ptdump_registered_guest *guest; + struct kvm_s2_mmu *mmu = &kvm->arch.mmu; + struct kvm_pgtable *pgt = mmu->pgt; + + guest = kzalloc(sizeof(struct ptdump_registered_guest), GFP_KERNEL); + if (!guest) + return -ENOMEM; + + memcpy(&guest->snapshot.pgtable, pgt, sizeof(struct kvm_pgtable)); + guest->info = (struct ptdump_info) { + .ptdump_walk = guest_stage2_ptdump_walk, + }; + + guest->info.priv = guest; + guest->lock = &kvm->mmu_lock; + mutex_lock(&ptdump_list_lock); + + ptdump_debugfs_kvm_register(&guest->info, "stage2_page_tables", + kvm->debugfs_dentry); + + list_add(&guest->reg_list, &ptdump_guest_list); + mutex_unlock(&ptdump_list_lock); + + return 0; +} + +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); + kfree(guest); + break; + } + } + mutex_unlock(&ptdump_list_lock); +} + void ptdump_register_host_stage2(void) { if (!is_protected_kvm_enabled())