All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sebastian Ene <sebastianene@google.com>
To: Vincent Donnefort <vdonnefort@google.com>
Cc: akpm@linux-foundation.org, alexghiti@rivosinc.com,
	ankita@nvidia.com, ardb@kernel.org, catalin.marinas@arm.com,
	christophe.leroy@csgroup.eu, james.morse@arm.com,
	mark.rutland@arm.com, maz@kernel.org, oliver.upton@linux.dev,
	rananta@google.com, ryan.roberts@arm.com, shahuang@redhat.com,
	suzuki.poulose@arm.com, will@kernel.org, yuzenghui@huawei.com,
	kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, kernel-team@android.com
Subject: Re: [PATCH v8 5/6] KVM: arm64: Initialize the ptdump parser with stage-2 attributes
Date: Mon, 19 Aug 2024 12:18:57 +0000	[thread overview]
Message-ID: <ZsM4MacbOe7GLIKl@google.com> (raw)
In-Reply-To: <ZsMeQ8nAZLDhsBmA@google.com>

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

  reply	other threads:[~2024-08-19 12:19 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-16 12:39 [PATCH v8 0/6] arm64: ptdump: View the second stage page-tables Sebastian Ene
2024-08-16 12:39 ` [PATCH v8 1/6] KVM: arm64: Move pagetable definitions to common header Sebastian Ene
2024-08-16 12:39 ` [PATCH v8 2/6] arm64: ptdump: Expose the attribute parsing functionality Sebastian Ene
2024-08-16 12:39 ` [PATCH v8 3/6] arm64: ptdump: Use the mask from the state structure Sebastian Ene
2024-08-20 13:49   ` Marc Zyngier
2024-08-20 14:13     ` Sebastian Ene
2024-08-20 14:25       ` Marc Zyngier
2024-08-20 14:39         ` Sebastian Ene
2024-08-16 12:39 ` [PATCH v8 4/6] KVM: arm64: Register ptdump with debugfs on guest creation Sebastian Ene
2024-08-20 14:06   ` Marc Zyngier
2024-08-23 10:45     ` Sebastian Ene
2024-08-23 10:53     ` Sebastian Ene
2024-08-16 12:39 ` [PATCH v8 5/6] KVM: arm64: Initialize the ptdump parser with stage-2 attributes Sebastian Ene
2024-08-19 10:28   ` Vincent Donnefort
2024-08-19 12:18     ` Sebastian Ene [this message]
2024-08-20 14:20   ` Marc Zyngier
2024-08-22 16:15     ` Marc Zyngier
2024-08-23  5:21       ` Sebastian Ene
2024-08-16 12:39 ` [PATCH v8 6/6] KVM: arm64: Expose guest stage-2 pagetable config to debugfs 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=ZsM4MacbOe7GLIKl@google.com \
    --to=sebastianene@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=alexghiti@rivosinc.com \
    --cc=ankita@nvidia.com \
    --cc=ardb@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=christophe.leroy@csgroup.eu \
    --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=rananta@google.com \
    --cc=ryan.roberts@arm.com \
    --cc=shahuang@redhat.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.