[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87sfpevl1g.ffs@tglx>
Date: Thu, 12 May 2022 17:16:11 +0200
From: Thomas Gleixner <tglx@...utronix.de>
To: Peter Zijlstra <peterz@...radead.org>
Cc: "Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>,
Dave Hansen <dave.hansen@...ux.intel.com>,
Andy Lutomirski <luto@...nel.org>, x86@...nel.org,
Andrey Ryabinin <aryabinin@...tuozzo.com>,
Alexander Potapenko <glider@...gle.com>,
Dmitry Vyukov <dvyukov@...gle.com>,
"H . J . Lu" <hjl.tools@...il.com>,
Andi Kleen <ak@...ux.intel.com>,
Rick Edgecombe <rick.p.edgecombe@...el.com>,
linux-mm@...ck.org, linux-kernel@...r.kernel.org
Subject: Re: [RFCv2 05/10] x86/mm: Provide untagged_addr() helper
On Thu, May 12 2022 at 16:23, Peter Zijlstra wrote:
> On Thu, May 12, 2022 at 03:06:38PM +0200, Thomas Gleixner wrote:
>
>> #define untagged_addr(addr) ({ \
>> u64 __addr = (__force u64)(addr); \
>> \
>> __addr &= current->thread.lam_untag_mask; \
>> (__force __typeof__(addr))__addr; \
>> })
>>
>> No conditionals, fast _and_ correct. Setting this untag mask up once
>> when LAM is enabled is not rocket science.
>
> But that goes wrong if someone ever wants to untag a kernel address and
> not use the result for access_ok().
>
> I'd feel better about something like:
>
> s64 __addr = (addr);
> s64 __sign = __addr;
>
> __sign >>= 63;
> __sign &= lam_untag_mask;
that needs to be
__sign &= ~lam_untag_mask;
> __addr &= lam_untag_mask;
> __addr |= __sign;
>
> __addr;
>
> Which simply extends bit 63 downwards -- although possibly there's an
> easier way to do that, this is pretty gross.
For the price of a conditional:
__addr &= lam_untag_mask;
if (__addr & BIT(63))
__addr |= ~lam_untag_mask;
Now you have the choice between gross and ugly.
Thanks,
tglx
Powered by blists - more mailing lists