Re: [PATCH v6 1/3] x86/mm: PUD VA support for physical mapping (x86_64)

From: Ingo Molnar
Date: Tue Jun 21 2016 - 04:30:01 EST



* Thomas Garnier <thgarnie@xxxxxxxxxx> wrote:

> > Secondly, and that's a new problem introduced by this patch:
> >
> >> + int i = pud_index((unsigned long)__va(addr));
> >> + pud_t *pud = pud_page + pud_index((unsigned long)__va(addr));
> >
> > ... beyond the repetition, using type casts is fragile. Type casts should be a red
> > flag to anyone involved in low level, security relevant code! So I'm pretty
> > unhappy about seeing such a problem in such a patch.
> >
> > This code should be doing something like:
> >
> > unsigned long vaddr_start = __va(paddr_start);
> >
> > ... which gets rid of the type cast, the repetition and documents the code much
> > better as well.
>
> Unfortunately, we can't do that because __va return a void*. We will
> get this warning on compile:
>
> arch/x86/mm/init_64.c:537:8: warning: assignment makes integer from
> pointer without a cast [enabled by default]
> vaddr = __va(paddr_start);
>
> If we used void*, we would need to type cast even more places. What do
> you think?

Hm, indeed, you are right - so I guess the type cast is OK.

Thanks,

Ingo