[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZsM4MacbOe7GLIKl@google.com>
Date: Mon, 19 Aug 2024 12:18:57 +0000
From: Sebastian Ene <sebastianene@...gle.com>
To: Vincent Donnefort <vdonnefort@...gle.com>
Cc: akpm@...ux-foundation.org, alexghiti@...osinc.com, ankita@...dia.com,
ardb@...nel.org, catalin.marinas@....com,
christophe.leroy@...roup.eu, james.morse@....com,
mark.rutland@....com, maz@...nel.org, oliver.upton@...ux.dev,
rananta@...gle.com, ryan.roberts@....com, shahuang@...hat.com,
suzuki.poulose@....com, will@...nel.org, yuzenghui@...wei.com,
kvmarm@...ts.linux.dev, linux-arm-kernel@...ts.infradead.org,
linux-kernel@...r.kernel.org, kernel-team@...roid.com
Subject: Re: [PATCH v8 5/6] KVM: arm64: Initialize the ptdump parser with
stage-2 attributes
On Mon, Aug 19, 2024 at 11:28:19AM +0100, Vincent Donnefort wrote:
>
> [...]
>
> > +static int kvm_ptdump_build_levels(struct ptdump_pg_level *level, u32 start_lvl)
> > +{
> > + static const char * const level_names[] = {"PGD", "PUD", "PMD", "PTE"};
> > + u32 i = 0;
> > + u64 mask = 0;
> > +
> > + if (start_lvl > 2) {
> > + pr_err("invalid start_lvl %u\n", start_lvl);
> > + return -EINVAL;
> > + }
>
> It looks like a duplicate of the if below.
I will drop this.
>
> > +
> > + if (WARN_ON_ONCE(start_lvl >= KVM_PGTABLE_LAST_LEVEL))
> > + return -EINVAL;
> > +
> > + for (i = 0; i < ARRAY_SIZE(stage2_pte_bits); i++)
> > + mask |= stage2_pte_bits[i].mask;
> > +
> > + for (i = start_lvl; i < KVM_PGTABLE_MAX_LEVELS; i++) {
> > + strscpy(level[i].name, level_names[i], sizeof(level[i].name));
> > +
> > + level[i].num = ARRAY_SIZE(stage2_pte_bits);
> > + level[i].bits = stage2_pte_bits;
> > + level[i].mask = mask;
> > + }
> > +
> > + if (start_lvl > 0)
> > + strscpy(level[start_lvl].name, "PGD", sizeof(level[start_lvl].name));
> > +
> > + return 0;
> > +}
> > +
> > +static struct kvm_ptdump_guest_state
> > +*kvm_ptdump_parser_init(struct kvm *kvm)
>
> nit: I guess it's more a "create" than an "init" as we allocate the memory.
Yes, that should work as well.
>
> > +{
> > + struct kvm_ptdump_guest_state *st;
> > + struct kvm_s2_mmu *mmu = &kvm->arch.mmu;
> > + struct kvm_pgtable *pgtable = mmu->pgt;
> > + int ret;
> > +
> > + st = kzalloc(sizeof(struct kvm_ptdump_guest_state), GFP_KERNEL_ACCOUNT);
> > + if (!st)
> > + return NULL;
>
> return ERR_PTR(-ENOMEM); ?
Yep, we can encode the ENOMEM in the ptr.
>
> > +
> > + ret = kvm_ptdump_build_levels(&st->level[0], pgtable->start_level);
> > + if (ret) {
> > + kfree(st);
> > + return ERR_PTR(ret);
> > + }
> > +
> > + st->ipa_marker[0].name = "Guest IPA";
> > + st->ipa_marker[1].start_address = BIT(pgtable->ia_bits);
> > + st->range[0].end = BIT(pgtable->ia_bits);
> > +
> > + st->kvm = kvm;
> > + st->parser_state = (struct ptdump_pg_state) {
> > + .marker = &st->ipa_marker[0],
> > + .level = -1,
> > + .pg_level = &st->level[0],
> > + .ptdump.range = &st->range[0],
> > + };
> > +
> > + return st;
> > +}
> > +
>
> [...]
Thanks,
Seb
Powered by blists - more mailing lists