From: Sebastian Ene <sebastianene@google.com>
To: Oliver Upton <oliver.upton@linux.dev>
Cc: will@kernel.org, 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,
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 v3 10/10] arm64: ptdump: Add support for guest stage-2 pagetables dumping
Date: Thu, 23 Nov 2023 10:58:20 +0000 [thread overview]
Message-ID: <ZV8wTMtuztSdzPaI@google.com> (raw)
In-Reply-To: <ZV6QXSV_SrYjjoE_@linux.dev>
On Wed, Nov 22, 2023 at 11:35:57PM +0000, Oliver Upton wrote:
> On Wed, Nov 15, 2023 at 05:16:40PM +0000, Sebastian Ene wrote:
> > +struct ptdump_registered_guest {
> > + struct list_head reg_list;
> > + struct ptdump_info info;
> > + struct kvm_pgtable_snapshot snapshot;
> > + rwlock_t *lock;
> > +};
>
> Why can't we just store a pointer directly to struct kvm in ::private?
I don't think it will work unless we expect a struct kvm_pgtable
in stage2_ptdump_walk file_priv field. I think it is a good ideea and will
simplify things a little bit dropping kvm_pgtable_snapshot from here.
The current code has some fileds that are reduntant (the priv pointers)
because I also made this to work with protected guests where we can't
access their pagetables directly.
> Also, shouldn't you take a reference on struct kvm when the file is
> opened to protect against VM teardown?
>
I am not sure about the need could you please elaborate a bit ? On VM
teardown we expect ptdump_unregister_guest_stage2 to be invoked.
> > +static LIST_HEAD(ptdump_guest_list);
> > +static DEFINE_MUTEX(ptdump_list_lock);
>
> What is the list for?
>
I am keeping a list of registered guests with ptdump and the lock should
protect the list against concurent VM teardowns.
> > 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);
>
> Taking the mmu lock for read allows other table walkers to add new
> mappings and adjust the granularity of existing ones. Should this
> instead take the mmu lock for write?
>
Thanks for pointing our, this is exactly what I was trying to avoid,
so yes I should use the write mmu lock in this case.
> > +}
> > +
> > +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);
>
> You want GFP_KERNEL_ACCOUNT here.
>
Right, thanks this is because it is an untrusted allocation triggered from
userspace.
> --
> Thanks,
> Oliver
Thank you,
Seb
WARNING: multiple messages have this Message-ID (diff)
From: Sebastian Ene <sebastianene@google.com>
To: Oliver Upton <oliver.upton@linux.dev>
Cc: will@kernel.org, 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,
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 v3 10/10] arm64: ptdump: Add support for guest stage-2 pagetables dumping
Date: Thu, 23 Nov 2023 10:58:20 +0000 [thread overview]
Message-ID: <ZV8wTMtuztSdzPaI@google.com> (raw)
In-Reply-To: <ZV6QXSV_SrYjjoE_@linux.dev>
On Wed, Nov 22, 2023 at 11:35:57PM +0000, Oliver Upton wrote:
> On Wed, Nov 15, 2023 at 05:16:40PM +0000, Sebastian Ene wrote:
> > +struct ptdump_registered_guest {
> > + struct list_head reg_list;
> > + struct ptdump_info info;
> > + struct kvm_pgtable_snapshot snapshot;
> > + rwlock_t *lock;
> > +};
>
> Why can't we just store a pointer directly to struct kvm in ::private?
I don't think it will work unless we expect a struct kvm_pgtable
in stage2_ptdump_walk file_priv field. I think it is a good ideea and will
simplify things a little bit dropping kvm_pgtable_snapshot from here.
The current code has some fileds that are reduntant (the priv pointers)
because I also made this to work with protected guests where we can't
access their pagetables directly.
> Also, shouldn't you take a reference on struct kvm when the file is
> opened to protect against VM teardown?
>
I am not sure about the need could you please elaborate a bit ? On VM
teardown we expect ptdump_unregister_guest_stage2 to be invoked.
> > +static LIST_HEAD(ptdump_guest_list);
> > +static DEFINE_MUTEX(ptdump_list_lock);
>
> What is the list for?
>
I am keeping a list of registered guests with ptdump and the lock should
protect the list against concurent VM teardowns.
> > 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);
>
> Taking the mmu lock for read allows other table walkers to add new
> mappings and adjust the granularity of existing ones. Should this
> instead take the mmu lock for write?
>
Thanks for pointing our, this is exactly what I was trying to avoid,
so yes I should use the write mmu lock in this case.
> > +}
> > +
> > +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);
>
> You want GFP_KERNEL_ACCOUNT here.
>
Right, thanks this is because it is an untrusted allocation triggered from
userspace.
> --
> Thanks,
> Oliver
Thank you,
Seb
_______________________________________________
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-11-23 10:58 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-15 17:16 [PATCH v3 00/10] arm64: ptdump: View the second stage page-tables Sebastian Ene
2023-11-15 17:16 ` Sebastian Ene
2023-11-15 17:16 ` [PATCH v3 01/10] KVM: arm64: Add snap shooting the host stage-2 pagetables Sebastian Ene
2023-11-15 17:16 ` Sebastian Ene
2023-11-21 14:12 ` Vincent Donnefort
2023-11-21 14:12 ` Vincent Donnefort
2023-11-23 14:40 ` Sebastian Ene
2023-11-23 14:40 ` Sebastian Ene
2023-11-15 17:16 ` [PATCH v3 02/10] arm64: ptdump: Use the mask from the state structure Sebastian Ene
2023-11-15 17:16 ` Sebastian Ene
2023-11-15 17:16 ` [PATCH v3 03/10] arm64: ptdump: Add the walker function to the ptdump info structure Sebastian Ene
2023-11-15 17:16 ` Sebastian Ene
2023-11-15 17:16 ` [PATCH v3 04/10] KVM: arm64: Move pagetable definitions to common header Sebastian Ene
2023-11-15 17:16 ` Sebastian Ene
2023-11-15 17:16 ` [PATCH v3 05/10] arm64: ptdump: Add hooks on debugfs file operations Sebastian Ene
2023-11-15 17:16 ` Sebastian Ene
2023-11-22 14:36 ` Vincent Donnefort
2023-11-22 14:36 ` Vincent Donnefort
2023-11-15 17:16 ` [PATCH v3 06/10] arm64: ptdump: Register a debugfs entry for the host stage-2 tables Sebastian Ene
2023-11-15 17:16 ` Sebastian Ene
2023-11-21 17:13 ` Vincent Donnefort
2023-11-21 17:13 ` Vincent Donnefort
2023-11-23 14:48 ` Sebastian Ene
2023-11-23 14:48 ` Sebastian Ene
2023-11-15 17:16 ` [PATCH v3 07/10] arm64: ptdump: Parse the host stage-2 page-tables from the snapshot Sebastian Ene
2023-11-15 17:16 ` Sebastian Ene
2023-11-15 21:57 ` kernel test robot
2023-11-15 21:57 ` kernel test robot
2023-11-18 22:39 ` kernel test robot
2023-11-18 22:39 ` kernel test robot
2023-11-15 17:16 ` [PATCH v3 08/10] arm64: ptdump: Interpret memory attributes based on runtime configuration Sebastian Ene
2023-11-15 17:16 ` Sebastian Ene
2023-11-15 17:16 ` [PATCH v3 09/10] arm64: ptdump: Interpret pKVM ownership annotations Sebastian Ene
2023-11-15 17:16 ` Sebastian Ene
2023-11-15 17:16 ` [PATCH v3 10/10] arm64: ptdump: Add support for guest stage-2 pagetables dumping Sebastian Ene
2023-11-15 17:16 ` Sebastian Ene
2023-11-22 23:35 ` Oliver Upton
2023-11-22 23:35 ` Oliver Upton
2023-11-23 10:58 ` Sebastian Ene [this message]
2023-11-23 10:58 ` Sebastian Ene
2023-11-22 23:18 ` [PATCH v3 00/10] arm64: ptdump: View the second stage page-tables Oliver Upton
2023-11-22 23:18 ` Oliver Upton
2023-11-23 9:49 ` Sebastian Ene
2023-11-23 9:49 ` 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=ZV8wTMtuztSdzPaI@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.