All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leonardo Bras <leo.bras@arm.com>
To: sashiko-reviews@lists.linux.dev
Cc: Leonardo Bras <leo.bras@arm.com>,
	kvmarm@lists.linux.dev, Oliver Upton <oupton@kernel.org>,
	Marc Zyngier <maz@kernel.org>
Subject: Re: [PATCH v3 2/3] KVM: arm64: Introduce KVM_PGTABLE_WALK_SKIP_LEVEL* walk flags
Date: Wed,  8 Jul 2026 16:49:01 +0100	[thread overview]
Message-ID: <ak5xbWIh4U3hbbx8@LeoBrasDK> (raw)
In-Reply-To: <20260708135012.3B21A1F000E9@smtp.kernel.org>

On Wed, Jul 08, 2026 at 01:50:11PM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] KVM_PGTABLE_WALK_SKIP_LEVEL* flags fail to skip the starting root level of the page table walk.
> --
> 
> --- Patch [2]: [PATCH v3 2/3] KVM: arm64: Introduce KVM_PGTABLE_WALK_SKIP_LEVEL* walk flags ---
> commit 5ddf63ba492be8c2a84af0b81cf00790fc72767a
> Author: Leonardo Bras <leo.bras@arm.com>
> 
> KVM: arm64: Introduce KVM_PGTABLE_WALK_SKIP_LEVEL* walk flags
> 
> This commit adds new walking flags that tell kvm_pgtable_walk() to skip
> lower levels when traversing page tables.
> 
> > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c
> > index 4be1d51a6ac58..b9a2078efc519 100644
> > --- a/arch/arm64/kvm/hyp/pgtable.c
> > +++ b/arch/arm64/kvm/hyp/pgtable.c
> 
> [ ... ]
> 
> > @@ -192,7 +205,7 @@ static inline int __kvm_pgtable_visit(struct kvm_pgtable_walk_data *data,
> >  	if (!kvm_pgtable_walk_continue(data->walker, ret))
> >  		return ret;
> >  
> > -	if (!table) {
> > +	if (!table || kvm_pgtable_skip_level(level + 1, ctx.flags)) {
> 
> [Severity: Medium]
> Does this fail to skip the starting level of the page table walk if that
> initial level matches the skip criteria?
> 
> Looking at __kvm_pgtable_visit() in arch/arm64/kvm/hyp/pgtable.c, the visitor
> callbacks are executed unconditionally for the current level before we reach
> this skip check:
> 
> 	if (table && (ctx.flags & KVM_PGTABLE_WALK_TABLE_PRE)) {
> 		ret = kvm_pgtable_visitor_cb(data, &ctx, KVM_PGTABLE_WALK_TABLE_PRE);
> 		reload = true;
> 	}
> 
> 	if (!table && (ctx.flags & KVM_PGTABLE_WALK_LEAF)) {
> 		ret = kvm_pgtable_visitor_cb(data, &ctx, KVM_PGTABLE_WALK_LEAF);
> 		reload = true;
> 	}
> 
> Since the skip condition here only evaluates level + 1 to prevent descending
> further, if a caller begins a walk at a level that should be skipped (for
> example, starting at level 2 with KVM_PGTABLE_WALK_SKIP_LEVEL2), the callbacks
> for that root level will still execute. 
> 
> Should the current level also be checked against the skip flags before
> executing the pre-table or leaf visitor callbacks?

Yes, we do execute the callback at least in the root we are given, which 
can have bad results in some scenario. That being said, testing here is not 
the best place, as this function will be called a lot.

If we want to avoid that scenario, I suggest we do that test before 
starting the walk, which would be on  _kvm_pgtable_walk(), except that both
kvm_pgtable_stage2_create_unlinked(), and 
kvm_pgtable_stage2_free_unlinked()
will call _kvm_pgtable_walk() directly.

(although they don't use skip_level paramters, yet)

Will take a look on that.

Thanks!
Leo

  reply	other threads:[~2026-07-08 15:49 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-08 13:40 [PATCH v3 0/3] Optimize S2 page splitting Leonardo Bras
2026-07-08 13:40 ` [PATCH v3 1/3] KVM: arm64: Avoid re-testing walk_continue Leonardo Bras
2026-07-08 16:41   ` Marc Zyngier
2026-07-08 17:00     ` Leonardo Bras
2026-07-08 13:40 ` [PATCH v3 2/3] KVM: arm64: Introduce KVM_PGTABLE_WALK_SKIP_LEVEL* walk flags Leonardo Bras
2026-07-08 13:50   ` sashiko-bot
2026-07-08 15:49     ` Leonardo Bras [this message]
2026-07-08 16:16       ` Leonardo Bras
2026-07-08 17:17   ` Marc Zyngier
2026-07-09 14:25     ` Leonardo Bras
2026-07-11  5:53   ` Wei-Lin Chang
2026-07-13 10:14     ` Leonardo Bras
2026-07-14  5:41       ` Wei-Lin Chang
2026-07-14 10:13         ` Leonardo Bras
2026-07-08 13:40 ` [PATCH v3 3/3] KVM: arm64: Make stage2_split_walker() skip unnecessary walks Leonardo Bras
2026-07-08 15:25 ` [PATCH v3 0/3] Optimize S2 page splitting Leonardo Bras
2026-07-12 14:50 ` Dev Jain
2026-07-13 10:08   ` Leonardo Bras

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=ak5xbWIh4U3hbbx8@LeoBrasDK \
    --to=leo.bras@arm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.