Re: [RFC][PATCH 6/8] x86/mm: add vsyscall address helper

From: Jann Horn
Date: Fri Sep 07 2018 - 20:59:38 EST


On Sat, Sep 8, 2018 at 2:25 AM Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx> wrote:
> We will shortly be using this check in two locations. Put it in
> a helper before we do so.
[...]
> +/*
> + * The (legacy) vsyscall page is the long page in the kernel portion
> + * of the address space that has user-accessible permissions.
> + */
> +static bool is_vsyscall_vaddr(unsigned long vaddr)
> +{
> + return (vaddr & ~0xfff) == VSYSCALL_ADDR;
> +}

<bikeshed>
Since you're touching this code anyway: Would it make sense to change
that constant to a more explicit "~0xfffUL" (or alternatively
PAGE_MASK)? I tend to end up staring at code like this forever, trying
to figure out whether the upper 32 bits of the constant end up being
set or clear. As a reader, looking at the current code, it's quite
annoying to see what actually happens - first there's a signed 32-bit
literal 0xfff, then a 32-bit negation happens, and then the number is
converted to 64 bits with sign extension.
</bikeshed>