From: Sebastian Ene <sebastianene@google.com>
To: will@kernel.org, Oliver Upton <oliver.upton@linux.dev>,
James Morse <james.morse@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
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
Subject: Re: [PATCH v4 10/10] arm64: ptdump: Add guest stage-2 pagetables dumping
Date: Tue, 19 Dec 2023 11:52:22 +0000 [thread overview]
Message-ID: <ZYGD9qWqHgICBCp8@google.com> (raw)
In-Reply-To: <20231218135859.2513568-12-sebastianene@google.com>
On Mon, Dec 18, 2023 at 01:59:00PM +0000, Sebastian Ene wrote:
> 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 <sebastianene@google.com>
> ---
> arch/arm64/kvm/debug.c | 6 ++++++
> arch/arm64/kvm/kvm_ptdump.h | 3 +++
> arch/arm64/kvm/ptdump.c | 35 ++++++++++++++++++++++++++++++++---
> 3 files changed, 41 insertions(+), 3 deletions(-)
>
> diff --git a/arch/arm64/kvm/debug.c b/arch/arm64/kvm/debug.c
> index 8725291cb..7c4c2902d 100644
> --- a/arch/arm64/kvm/debug.c
> +++ b/arch/arm64/kvm/debug.c
> @@ -13,6 +13,7 @@
> #include <asm/kvm_asm.h>
> #include <asm/kvm_arm.h>
> #include <asm/kvm_emulate.h>
> +#include <kvm_ptdump.h>
>
> #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 kvm_ptdump_register_guest(kvm);
> +}
> diff --git a/arch/arm64/kvm/kvm_ptdump.h b/arch/arm64/kvm/kvm_ptdump.h
> index 98b595ce8..5f5a455d0 100644
> --- a/arch/arm64/kvm/kvm_ptdump.h
> +++ b/arch/arm64/kvm/kvm_ptdump.h
> @@ -6,13 +6,16 @@
> #ifndef __KVM_PTDUMP_H
> #define __KVM_PTDUMP_H
>
> +#include <linux/kvm_host.h>
> #include <asm/ptdump.h>
>
>
> #ifdef CONFIG_PTDUMP_STAGE2_DEBUGFS
> void kvm_ptdump_register_host(void);
> +int kvm_ptdump_register_guest(struct kvm *kvm);
> #else
> static inline void kvm_ptdump_register_host(void) { }
> +static inline int kvm_ptdump_register_guest(struct kvm *kvm) { return -1; }
> #endif /* CONFIG_PTDUMP_STAGE2_DEBUGFS */
>
> #endif /* __KVM_PTDUMP_H */
> diff --git a/arch/arm64/kvm/ptdump.c b/arch/arm64/kvm/ptdump.c
> index 4296e739f..62a753d6b 100644
> --- a/arch/arm64/kvm/ptdump.c
> +++ b/arch/arm64/kvm/ptdump.c
> @@ -181,6 +181,8 @@ static int kvm_ptdump_open(struct inode *inode, struct file *file)
> info = reg->get_ptdump_info(reg);
> if (!info)
> return -ENOMEM;
> + } else {
> + info = inode->i_private;
FIXME: Don't call kvm_ptdump_release with this ^ argument.
> }
>
> if (!reg->show_ptdump_info)
> @@ -239,15 +241,14 @@ static int kvm_ptdump_visitor(const struct kvm_pgtable_visit_ctx *ctx,
> return 0;
> }
>
> -static int kvm_ptdump_show(struct seq_file *m, void *)
> +static int kvm_ptdump_show_common(struct seq_file *m,
> + struct kvm_pgtable *pgtable)
> {
> u64 ipa_size;
> char ipa_description[32];
> struct pg_state st;
> struct addr_marker ipa_addr_markers[3] = {0};
> struct pg_level pg_level_descr[KVM_PGTABLE_MAX_LEVELS] = {0};
> - struct kvm_pgtable_snapshot *snapshot = m->private;
> - struct kvm_pgtable *pgtable = &snapshot->pgtable;
> struct kvm_pgtable_walker walker = (struct kvm_pgtable_walker) {
> .cb = kvm_ptdump_visitor,
> .arg = &st,
> @@ -282,6 +283,26 @@ static int kvm_ptdump_show(struct seq_file *m, void *)
> return kvm_pgtable_walk(pgtable, 0, ipa_size, &walker);
> }
>
> +static int kvm_host_ptdump_show(struct seq_file *m, void *)
> +{
> + struct kvm_pgtable_snapshot *snapshot = m->private;
> +
> + return kvm_ptdump_show_common(m, &snapshot->pgtable);
> +}
> +
> +static int kvm_ptdump_show(struct seq_file *m, void *)
> +{
> + struct kvm *guest_kvm = m->private;
> + struct kvm_s2_mmu *mmu = &guest_kvm->arch.mmu;
> + int ret;
> +
> + write_lock(&guest_kvm->mmu_lock);
> + ret = kvm_ptdump_show_common(m, mmu->pgt);
> + write_unlock(&guest_kvm->mmu_lock);
> +
> + return ret;
> +}
> +
> static void kvm_ptdump_debugfs_register(struct kvm_ptdump_register *reg,
> const char *name, struct dentry *parent)
> {
> @@ -393,11 +414,19 @@ void kvm_ptdump_register_host(void)
>
> host_reg.get_ptdump_info = kvm_host_get_ptdump_info;
> host_reg.put_ptdump_info = kvm_host_put_ptdump_info;
> + host_reg.show_ptdump_info = kvm_host_ptdump_show;
>
> kvm_ptdump_debugfs_register(&host_reg, "host_page_tables",
> kvm_debugfs_dir);
> }
>
> +int kvm_ptdump_register_guest(struct kvm *kvm)
> +{
> + debugfs_create_file("stage2_page_tables", 0400, kvm->debugfs_dentry,
> + kvm, &kvm_ptdump_fops);
> + return 0;
> +}
> +
> static int __init kvm_host_ptdump_init(void)
> {
> host_reg.priv = (void *)host_s2_pgtable_pages();
> --
> 2.43.0.472.g3155946c3a-goog
>
WARNING: multiple messages have this Message-ID (diff)
From: Sebastian Ene <sebastianene@google.com>
To: will@kernel.org, Oliver Upton <oliver.upton@linux.dev>,
James Morse <james.morse@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
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
Subject: Re: [PATCH v4 10/10] arm64: ptdump: Add guest stage-2 pagetables dumping
Date: Tue, 19 Dec 2023 11:52:22 +0000 [thread overview]
Message-ID: <ZYGD9qWqHgICBCp8@google.com> (raw)
In-Reply-To: <20231218135859.2513568-12-sebastianene@google.com>
On Mon, Dec 18, 2023 at 01:59:00PM +0000, Sebastian Ene wrote:
> 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 <sebastianene@google.com>
> ---
> arch/arm64/kvm/debug.c | 6 ++++++
> arch/arm64/kvm/kvm_ptdump.h | 3 +++
> arch/arm64/kvm/ptdump.c | 35 ++++++++++++++++++++++++++++++++---
> 3 files changed, 41 insertions(+), 3 deletions(-)
>
> diff --git a/arch/arm64/kvm/debug.c b/arch/arm64/kvm/debug.c
> index 8725291cb..7c4c2902d 100644
> --- a/arch/arm64/kvm/debug.c
> +++ b/arch/arm64/kvm/debug.c
> @@ -13,6 +13,7 @@
> #include <asm/kvm_asm.h>
> #include <asm/kvm_arm.h>
> #include <asm/kvm_emulate.h>
> +#include <kvm_ptdump.h>
>
> #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 kvm_ptdump_register_guest(kvm);
> +}
> diff --git a/arch/arm64/kvm/kvm_ptdump.h b/arch/arm64/kvm/kvm_ptdump.h
> index 98b595ce8..5f5a455d0 100644
> --- a/arch/arm64/kvm/kvm_ptdump.h
> +++ b/arch/arm64/kvm/kvm_ptdump.h
> @@ -6,13 +6,16 @@
> #ifndef __KVM_PTDUMP_H
> #define __KVM_PTDUMP_H
>
> +#include <linux/kvm_host.h>
> #include <asm/ptdump.h>
>
>
> #ifdef CONFIG_PTDUMP_STAGE2_DEBUGFS
> void kvm_ptdump_register_host(void);
> +int kvm_ptdump_register_guest(struct kvm *kvm);
> #else
> static inline void kvm_ptdump_register_host(void) { }
> +static inline int kvm_ptdump_register_guest(struct kvm *kvm) { return -1; }
> #endif /* CONFIG_PTDUMP_STAGE2_DEBUGFS */
>
> #endif /* __KVM_PTDUMP_H */
> diff --git a/arch/arm64/kvm/ptdump.c b/arch/arm64/kvm/ptdump.c
> index 4296e739f..62a753d6b 100644
> --- a/arch/arm64/kvm/ptdump.c
> +++ b/arch/arm64/kvm/ptdump.c
> @@ -181,6 +181,8 @@ static int kvm_ptdump_open(struct inode *inode, struct file *file)
> info = reg->get_ptdump_info(reg);
> if (!info)
> return -ENOMEM;
> + } else {
> + info = inode->i_private;
FIXME: Don't call kvm_ptdump_release with this ^ argument.
> }
>
> if (!reg->show_ptdump_info)
> @@ -239,15 +241,14 @@ static int kvm_ptdump_visitor(const struct kvm_pgtable_visit_ctx *ctx,
> return 0;
> }
>
> -static int kvm_ptdump_show(struct seq_file *m, void *)
> +static int kvm_ptdump_show_common(struct seq_file *m,
> + struct kvm_pgtable *pgtable)
> {
> u64 ipa_size;
> char ipa_description[32];
> struct pg_state st;
> struct addr_marker ipa_addr_markers[3] = {0};
> struct pg_level pg_level_descr[KVM_PGTABLE_MAX_LEVELS] = {0};
> - struct kvm_pgtable_snapshot *snapshot = m->private;
> - struct kvm_pgtable *pgtable = &snapshot->pgtable;
> struct kvm_pgtable_walker walker = (struct kvm_pgtable_walker) {
> .cb = kvm_ptdump_visitor,
> .arg = &st,
> @@ -282,6 +283,26 @@ static int kvm_ptdump_show(struct seq_file *m, void *)
> return kvm_pgtable_walk(pgtable, 0, ipa_size, &walker);
> }
>
> +static int kvm_host_ptdump_show(struct seq_file *m, void *)
> +{
> + struct kvm_pgtable_snapshot *snapshot = m->private;
> +
> + return kvm_ptdump_show_common(m, &snapshot->pgtable);
> +}
> +
> +static int kvm_ptdump_show(struct seq_file *m, void *)
> +{
> + struct kvm *guest_kvm = m->private;
> + struct kvm_s2_mmu *mmu = &guest_kvm->arch.mmu;
> + int ret;
> +
> + write_lock(&guest_kvm->mmu_lock);
> + ret = kvm_ptdump_show_common(m, mmu->pgt);
> + write_unlock(&guest_kvm->mmu_lock);
> +
> + return ret;
> +}
> +
> static void kvm_ptdump_debugfs_register(struct kvm_ptdump_register *reg,
> const char *name, struct dentry *parent)
> {
> @@ -393,11 +414,19 @@ void kvm_ptdump_register_host(void)
>
> host_reg.get_ptdump_info = kvm_host_get_ptdump_info;
> host_reg.put_ptdump_info = kvm_host_put_ptdump_info;
> + host_reg.show_ptdump_info = kvm_host_ptdump_show;
>
> kvm_ptdump_debugfs_register(&host_reg, "host_page_tables",
> kvm_debugfs_dir);
> }
>
> +int kvm_ptdump_register_guest(struct kvm *kvm)
> +{
> + debugfs_create_file("stage2_page_tables", 0400, kvm->debugfs_dentry,
> + kvm, &kvm_ptdump_fops);
> + return 0;
> +}
> +
> static int __init kvm_host_ptdump_init(void)
> {
> host_reg.priv = (void *)host_s2_pgtable_pages();
> --
> 2.43.0.472.g3155946c3a-goog
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2023-12-19 11:52 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-18 13:58 [PATCH v4 00/10] arm64: ptdump: View the second stage page-tables Sebastian Ene
2023-12-18 13:58 ` Sebastian Ene
2023-12-18 13:58 ` [PATCH v4 01/10] KVM: arm64: Add snapshot interface for the host stage-2 pagetable Sebastian Ene
2023-12-18 13:58 ` Sebastian Ene
2023-12-19 11:44 ` Sebastian Ene
2023-12-19 11:44 ` Sebastian Ene
2023-12-18 13:58 ` [PATCH v4 02/10] KVM: arm64: Add ptdump registration with debugfs for the stage-2 pagetables Sebastian Ene
2023-12-18 13:58 ` Sebastian Ene
2023-12-19 11:47 ` Sebastian Ene
2023-12-19 11:47 ` Sebastian Ene
2023-12-21 18:14 ` Oliver Upton
2023-12-21 18:14 ` Oliver Upton
2024-02-01 11:20 ` Sebastian Ene
2024-02-01 11:20 ` Sebastian Ene
2024-02-05 13:14 ` Oliver Upton
2024-02-05 13:14 ` Oliver Upton
2024-02-05 16:05 ` Sebastian Ene
2024-02-05 16:05 ` Sebastian Ene
2023-12-18 13:58 ` [PATCH v4 03/10] KVM: arm64: Invoke the snapshot interface for the host stage-2 pagetable Sebastian Ene
2023-12-18 13:58 ` Sebastian Ene
2023-12-19 11:45 ` Sebastian Ene
2023-12-19 11:45 ` Sebastian Ene
2023-12-18 13:58 ` [PATCH v4 04/10] arm64: ptdump: Expose the attribute parsing functionality Sebastian Ene
2023-12-18 13:58 ` Sebastian Ene
2023-12-18 13:58 ` [PATCH v4 05/10] arm64: ptdump: Use the mask from the state structure Sebastian Ene
2023-12-18 13:58 ` Sebastian Ene
2023-12-18 13:58 ` [PATCH v4 06/10] KVM: arm64: Move pagetable definitions to common header Sebastian Ene
2023-12-18 13:58 ` Sebastian Ene
2023-12-18 13:58 ` [PATCH v4 07/10] KVM: arm64: Walk the pagetable snapshot and parse the ptdump descriptors Sebastian Ene
2023-12-18 13:58 ` Sebastian Ene
2023-12-18 13:58 ` [PATCH v4 08/10] arm64: ptdump: Interpret memory attributes based on the runtime config Sebastian Ene
2023-12-18 13:58 ` Sebastian Ene
2023-12-18 13:58 ` [PATCH v4 09/10] arm64: ptdump: Interpret pKVM ownership annotations Sebastian Ene
2023-12-18 13:58 ` Sebastian Ene
2023-12-18 13:59 ` [PATCH v4 10/10] arm64: ptdump: Add guest stage-2 pagetables dumping Sebastian Ene
2023-12-18 13:59 ` Sebastian Ene
2023-12-19 11:52 ` Sebastian Ene [this message]
2023-12-19 11:52 ` Sebastian Ene
2023-12-21 18:27 ` Oliver Upton
2023-12-21 18:27 ` Oliver Upton
2023-12-21 18:36 ` [PATCH v4 00/10] arm64: ptdump: View the second stage page-tables Oliver Upton
2023-12-21 18:36 ` Oliver Upton
2023-12-21 18:41 ` Sebastian Ene
2023-12-21 18:41 ` Sebastian Ene
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZYGD9qWqHgICBCp8@google.com \
--to=sebastianene@google.com \
--cc=akpm@linux-foundation.org \
--cc=catalin.marinas@arm.com \
--cc=james.morse@arm.com \
--cc=kernel-team@android.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=oliver.upton@linux.dev \
--cc=qperret@google.com \
--cc=smostafa@google.com \
--cc=suzuki.poulose@arm.com \
--cc=vdonnefort@google.com \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.