[00/11] arm64: ptdump: View the host stage-2 page-tables

Message ID 20230927112517.2631674-1-sebastianene@google.com
Headers
Series arm64: ptdump: View the host stage-2 page-tables |

Message

Sebastian Ene Sept. 27, 2023, 11:25 a.m. UTC
  Hi,

This can be used as a debugging tool for dumping the host stage-2
page-tables under pKVM envinronment.

When CONFIG_NVHE_EL2_PTDUMP_DEBUGFS is enabled, ptdump registers the
'host_stage2_kernel_page_tables' entry with debugfs and this allows us
to dump the host stage-2 page-tables with the following command:
cat /sys/kernel/debug/host_stage2_kernel_page_tables

The output is showing the entries in the following format:
<IPA range> <size> <descriptor type> <access permissions> <mem_attributes>

The tool interprets the pKVM ownership annotation stored in the invalid
entries and dumps to the console the ownership information. To be able
to access the host stage-2 page-tables from the kernel, a new hypervisor
call was introduced which allows us to snapshot the page-tables in a host
provided buffer. The hypervisor call is hidden behind CONFIG_NVHE_EL2_DEBUG
as this should be used under debugging environment.

I verified this series with Qemu and Pixel 6 both using kvm-arm.mode=protected.

Thanks,

Sebastian Ene (11):
  KVM: arm64: Add snap shooting the host stage-2 pagetables
  arm64: ptdump: Use the mask from the state structure
  arm64: ptdump: Add the walker function to the ptdump info structure
  KVM: arm64: Move pagetable definitions to common header
  arm64: ptdump: Introduce stage-2 pagetables format description
  arm64: ptdump: Register a debugfs entry for the host stage-2
    page-tables
  arm64: ptdump: Snapshot the host stage-2 pagetables
  arm64: ptdump: Parse the host stage-2 page-tables from the snapshot
  arm64: ptdump: Interpret memory attributes based on runtime
    configuration
  arm64: ptdump: Interpret pKVM ownership annotations
  arm64: ptdump: Fix format output during stage-2 pagetable dumping

 arch/arm64/include/asm/kvm_asm.h              |   1 +
 arch/arm64/include/asm/kvm_pgtable.h          |  85 ++++
 arch/arm64/include/asm/ptdump.h               |   6 +
 arch/arm64/kvm/Kconfig                        |  12 +
 arch/arm64/kvm/hyp/include/nvhe/mem_protect.h |   8 +-
 arch/arm64/kvm/hyp/nvhe/hyp-main.c            |  18 +
 arch/arm64/kvm/hyp/nvhe/mem_protect.c         | 103 +++++
 arch/arm64/kvm/hyp/pgtable.c                  |  98 +++--
 arch/arm64/mm/ptdump.c                        | 405 +++++++++++++++++-
 arch/arm64/mm/ptdump_debugfs.c                |  37 +-
 10 files changed, 716 insertions(+), 57 deletions(-)
  

Comments

Marc Zyngier Sept. 29, 2023, 1:11 p.m. UTC | #1
Hi Sebastian,

On Wed, 27 Sep 2023 12:25:06 +0100,
Sebastian Ene <sebastianene@google.com> wrote:
> 
> Hi,
> 
> This can be used as a debugging tool for dumping the host stage-2
> page-tables under pKVM envinronment.

Why only pKVM? Why only the host? Dumping page tables shouldn't be
reserved to this corner case. Specially considering that pKVM is still
really far away from being remotely useful upstream.

I'd really expect this sort of debugging information to be fully
available for both host and guest, for all modes (nVHE, VHE, hVHE,
protected, nested), without limitations other than the configuration
option.

Also, please Cc the relevant parties (I'm the only one Cc'd on the KVM
side...)

Thanks,

	M.
  
Sebastian Ene Sept. 30, 2023, 4:31 p.m. UTC | #2
On Fri, Sep 29, 2023 at 02:11:23PM +0100, Marc Zyngier wrote:

Hello Marc,

Thanks for having a look.

> Hi Sebastian,
> 
> On Wed, 27 Sep 2023 12:25:06 +0100,
> Sebastian Ene <sebastianene@google.com> wrote:
> > 
> > Hi,
> > 
> > This can be used as a debugging tool for dumping the host stage-2
> > page-tables under pKVM envinronment.
> 
> Why only pKVM? Why only the host? Dumping page tables shouldn't be
> reserved to this corner case. Specially considering that pKVM is still
> really far away from being remotely useful upstream.
>

I wanted to publish the initial series which adds support for the host
and then extend it to guest VMs. 

> I'd really expect this sort of debugging information to be fully
> available for both host and guest, for all modes (nVHE, VHE, hVHE,
> protected, nested), without limitations other than the configuration
> option.

I agree, let me re-spin the series and add support for non-protected as
well.

> 
> Also, please Cc the relevant parties (I'm the only one Cc'd on the KVM
> side...)
>

Thanks,

Sebastian

> Thanks,
> 
> 	M.
> 
> -- 
> Without deviation from the norm, progress is not possible.