Re: [PATCH v2 11/25] x86/sev: Adjust directmap to avoid inadvertant RMP faults

Borislav Petkov
2024-01-27T11:42:54Z

On Fri, Jan 26, 2024 at 05:54:20PM -0600, Michael Roth wrote:
> Is something like this close to what you're thinking? I've re-tested with
> SNP guests and it seems to work as expected.
>
> diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c
> index 846e9e53dff0..c09497487c08 100644
> --- a/arch/x86/virt/svm/sev.c
> +++ b/arch/x86/virt/svm/sev.c
> @@ -421,7 +421,12 @@ static int adjust_direct_map(u64 pfn, int rmp_level)
> if (WARN_ON_ONCE(rmp_level > PG_LEVEL_2M))
> return -EINVAL;
>
> - if (WARN_ON_ONCE(rmp_level == PG_LEVEL_2M && !IS_ALIGNED(pfn, PTRS_PER_PMD)))
> + if (!pfn_valid(pfn))

_text at VA 0xffffffff81000000 is also a valid pfn so no, this is not
enough.

Either this function should not have "direct map" in the name as it
converts *any* valid pfn not just the direct map ones or it should check
whether the pfn belongs to the direct map range.

Thx.

--
Regards/Gruss,
Boris.