RE: [PATCH RESEND v9 2/2] x86/tdx: Support vmalloc() for tdx_enc_status_changed()

From: Dexuan Cui
Date: Fri Aug 11 2023 - 15:08:29 EST


> From: Dave Hansen <dave.hansen@xxxxxxxxx>
> Sent: Friday, August 11, 2023 7:10 AM
> [...]
> This creates two different paths for vmalloc() and the direct map.
> There are two different ways to do va=>pa conversion, for instance.
> Here's a single loop that works for both cases:
>
> unsigned long step = end - start;
> unsigned long addr;
>
> /* Step through page-by-page for vmalloc() mappings: */
> if (is_vmalloc_addr((void *)vaddr))
> step = PAGE_SIZE;
>
> for (addr = start; addr < end; addr += step) {
> phys_addr_t start_pa = slow_virt_to_phys(addr);
> phys_addr_t end_pa = start_pa + step;
>
> if (!tdx_enc_status_changed_phys(start_pa, end_pa, enc))
> return false;
> }
>
> Note that this also doesn't abuse 'start' by making it a loop variable.
> It also, uh, uses a for() loop.
>
> The only downside is that it costs a page table walk for direct map
> virt=>phys conversion. I can live with that.

Your version is concise and more readable.
Thanks for improving the patch! I'll use this in v10 shortly.