[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87a6bmx5lt.ffs@tglx>
Date: Thu, 12 May 2022 15:06:38 +0200
From: Thomas Gleixner <tglx@...utronix.de>
To: "Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>,
Dave Hansen <dave.hansen@...ux.intel.com>,
Andy Lutomirski <luto@...nel.org>,
Peter Zijlstra <peterz@...radead.org>
Cc: 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,
"Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>
Subject: Re: [RFCv2 05/10] x86/mm: Provide untagged_addr() helper
On Wed, May 11 2022 at 05:27, Kirill A. Shutemov wrote:
> +#define __untagged_addr(addr, n) \
> + ((__force __typeof__(addr))sign_extend64((__force u64)(addr), n))
How is this supposed to be correct? This sign extends based on bit 47
resp. 56, i.e. the topmost bit of the userspace address space for the
LAM mode.
So if that bit _is_ set, then the result has bit 48-63 resp. 57-63 set
as well. Not really what you want, right?
This has to mask out bit 48-62 resp. 57-62 and leave all other bits
alone.
> +#define untagged_addr(addr) ({ \
> + u64 __addr = (__force u64)(addr); \
> + if (__addr >> 63 == 0) { \
> + if (current->thread.features & X86_THREAD_LAM_U57) \
> + __addr &= __untagged_addr(__addr, 56); \
> + else if (current->thread.features & X86_THREAD_LAM_U48) \
> + __addr &= __untagged_addr(__addr, 47); \
> + } \
> + (__force __typeof__(addr))__addr; \
> +})
So this wants something like this:
#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.
Thanks,
tglx
Powered by blists - more mailing lists