[PATCH v7 5/6] KVM: arm64: Initialize the ptdump parser with stage-2 attributes

Vincent Donnefort vdonnefort at google.com
Fri Jul 19 07:36:04 PDT 2024


On Fri, Jul 19, 2024 at 02:09:19PM +0000, Sebastian Ene wrote:
> On Tue, Jul 16, 2024 at 10:59:41AM +0100, Vincent Donnefort wrote:
> > On Mon, Jul 01, 2024 at 02:18:39PM +0000, Sebastian Ene wrote:
> > > On Mon, Jul 01, 2024 at 09:42:43AM +0100, Vincent Donnefort wrote:
> > > > O Fri, Jun 21, 2024 at 12:32:29PM +0000, 'Sebastian Ene' via kernel-team wrote:
> > > > > Define a set of attributes used by the ptdump parser to display the
> > > > > properties of a guest memory region covered by a pagetable descriptor.
> > > > > Build a description of the pagetable levels and initialize the parser
> > > > > with this configuration.
> > > > > 
> > > > > Signed-off-by: Sebastian Ene <sebastianene at google.com>
> > > > > ---
> > > > >  arch/arm64/kvm/ptdump.c | 143 ++++++++++++++++++++++++++++++++++++++--
> > > > >  1 file changed, 137 insertions(+), 6 deletions(-)
> > > > > 
> > > > > diff --git a/arch/arm64/kvm/ptdump.c b/arch/arm64/kvm/ptdump.c
> > > > > index 36dc7662729f..cc1d4fdddc6e 100644
> > > > > --- a/arch/arm64/kvm/ptdump.c
> > > > > +++ b/arch/arm64/kvm/ptdump.c
> > > > > @@ -14,6 +14,61 @@
> > > > >  #include <kvm_ptdump.h>
> > > > >  
> > > > >  
> > > > > +#define MARKERS_LEN		(2)
> > > > > +#define KVM_PGTABLE_MAX_LEVELS	(KVM_PGTABLE_LAST_LEVEL + 1)
> > > > > +
> > > > > +struct kvm_ptdump_guest_state {
> > > > > +	struct kvm		*kvm;
> > > > > +	struct pg_state		parser_state;
> > > > > +	struct addr_marker	ipa_marker[MARKERS_LEN];
> > > > > +	struct pg_level		level[KVM_PGTABLE_MAX_LEVELS];
> > > > > +	struct ptdump_range	range[MARKERS_LEN];
> > > > > +};
> > > > > +
> > > > > +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 | PTE_VALID,
> > > > > +		.val	= KVM_PTE_LEAF_ATTR_HI_S2_XN | PTE_VALID,
> > 
> > KVM_PTE_LEAF_ATTR_HI_S2_XN is actually a mask covering 
> 
> It is not a mask covering here but in the ACK kernel.

You're right, I should have double-checked upstream.

That said, how about we move this __after__ RW ? and just use "X" on .clear
so we can have something R W X ?

> 
> > 
> > KVM_PTE_LEAF_ATTR_HI_S2_XN_XN, KVM_PTE_LEAF_ATTR_HI_S2_XN_PXN and
> > KVM_PTE_LEAF_ATTR_HI_S2_XN_UXN. 
> > 
> > I believe here what we should do is something like?
> > 
> > .val = FIELD_PREP_CONST(KVM_PTE_LEAF_ATTR_HI_S2_XN,
> > 			KVM_PTE_LEAF_ATTR_HI_S2_XN_XN) | PTE_VALID
> > 
> > > > > +		.set	= "XN",
> > > > > +		.clear	= "  ",
> > > > > +	}, {
> > > > > +		.mask	= KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R | PTE_VALID,
> > > > > +		.val	= KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R | PTE_VALID,
> > > > > +		.set	= "R",
> > > > > +		.clear	= " ",
> > > > > +	}, {
> > 
> > [...]



More information about the linux-arm-kernel mailing list