[PATCH RESEND v4 1/3] KVM: arm64: Avoid re-testing walk_continue

Suzuki K Poulose suzuki.poulose at arm.com
Fri Nov 6 08:59:05 PST 2026


On 06/11/2026 16:12, Leonardo Bras wrote:
> __kvm_pgtable_visit() performs a bunch of calls to
> kvm_pgtable_walk_continue() to find out whether the walk can continue
> further, and if not, 'goto out', which retests the possibility of
> continuing the walk before exiting.
> 
> Given that it's testing the same ret variable again, there is no reason
> the result of kvm_pgtable_walk_continue() would have changed since the
> previous check. So turn this goto into an early return, simplifying the
> code and paving the way for further rework."

Looks sensible to me.

Reviewed-by: Suzuki K Poulose <suzuki.poulose at arm.com>


> 
> Signed-off-by: Leonardo Bras <leo.bras at arm.com>
> ---
>   arch/arm64/kvm/hyp/pgtable.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c
> index b74dd5ce1efd..7a51f78b6446 100644
> --- a/arch/arm64/kvm/hyp/pgtable.c
> +++ b/arch/arm64/kvm/hyp/pgtable.c
> @@ -183,32 +183,32 @@ static inline int __kvm_pgtable_visit(struct kvm_pgtable_walk_data *data,
>   	 * Reload the page table after invoking the walker callback for leaf
>   	 * entries or after pre-order traversal, to allow the walker to descend
>   	 * into a newly installed or replaced table.
>   	 */
>   	if (reload) {
>   		ctx.old = READ_ONCE(*ptep);
>   		table = kvm_pte_table(ctx.old, level);
>   	}
>   
>   	if (!kvm_pgtable_walk_continue(data->walker, ret))
> -		goto out;
> +		return ret;
>   
>   	if (!table) {
>   		data->addr = ALIGN_DOWN(data->addr, kvm_granule_size(level));
>   		data->addr += kvm_granule_size(level);
>   		goto out;
>   	}
>   
>   	childp = (kvm_pteref_t)kvm_pte_follow(ctx.old, mm_ops);
>   	ret = __kvm_pgtable_walk(data, mm_ops, childp, level + 1);
>   	if (!kvm_pgtable_walk_continue(data->walker, ret))
> -		goto out;
> +		return ret;
>   
>   	if (ctx.flags & KVM_PGTABLE_WALK_TABLE_POST)
>   		ret = kvm_pgtable_visitor_cb(data, &ctx, KVM_PGTABLE_WALK_TABLE_POST);
>   
>   out:
>   	if (kvm_pgtable_walk_continue(data->walker, ret))
>   		return 0;
>   
>   	return ret;
>   }




More information about the linux-arm-kernel mailing list