[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a7imdoiu4dpypmw2rp25j3vmmuvvzhg6bcx5wtt2dgukg5u7cz@nuyvc77cdmvb>
Date: Wed, 9 Apr 2025 09:36:32 +0200
From: Maciej Wieczor-Retman <maciej.wieczor-retman@...el.com>
To: Dave Hansen <dave.hansen@...el.com>
CC: <hpa@...or.com>, <hch@...radead.org>, <nick.desaulniers+lkml@...il.com>,
<kuan-ying.lee@...onical.com>, <masahiroy@...nel.org>,
<samuel.holland@...ive.com>, <mingo@...hat.com>, <corbet@....net>,
<ryabinin.a.a@...il.com>, <guoweikang.kernel@...il.com>,
<jpoimboe@...nel.org>, <ardb@...nel.org>, <vincenzo.frascino@....com>,
<glider@...gle.com>, <kirill.shutemov@...ux.intel.com>, <apopple@...dia.com>,
<samitolvanen@...gle.com>, <kaleshsingh@...gle.com>, <jgross@...e.com>,
<andreyknvl@...il.com>, <scott@...amperecomputing.com>,
<tony.luck@...el.com>, <dvyukov@...gle.com>, <pasha.tatashin@...een.com>,
<ziy@...dia.com>, <broonie@...nel.org>, <gatlin.newhouse@...il.com>,
<jackmanb@...gle.com>, <wangkefeng.wang@...wei.com>,
<thiago.bauermann@...aro.org>, <tglx@...utronix.de>, <kees@...nel.org>,
<akpm@...ux-foundation.org>, <jason.andryuk@....com>, <snovitoll@...il.com>,
<xin@...or.com>, <jan.kiszka@...mens.com>, <bp@...en8.de>, <rppt@...nel.org>,
<peterz@...radead.org>, <pankaj.gupta@....com>, <thuth@...hat.com>,
<andriy.shevchenko@...ux.intel.com>, <joel.granados@...nel.org>,
<kbingham@...nel.org>, <nicolas@...sle.eu>, <mark.rutland@....com>,
<surenb@...gle.com>, <catalin.marinas@....com>, <morbo@...gle.com>,
<justinstitt@...gle.com>, <ubizjak@...il.com>, <jhubbard@...dia.com>,
<urezki@...il.com>, <dave.hansen@...ux.intel.com>, <bhe@...hat.com>,
<luto@...nel.org>, <baohua@...nel.org>, <nathan@...nel.org>,
<will@...nel.org>, <brgerst@...il.com>, <llvm@...ts.linux.dev>,
<linux-mm@...ck.org>, <linux-doc@...r.kernel.org>,
<linux-arm-kernel@...ts.infradead.org>, <linux-kbuild@...r.kernel.org>,
<linux-kernel@...r.kernel.org>, <kasan-dev@...glegroups.com>,
<x86@...nel.org>
Subject: Re: [PATCH v3 05/14] x86: Reset tag for virtual to physical address
conversions
On 2025-04-04 at 09:42:55 -0700, Dave Hansen wrote:
>On 4/4/25 06:14, Maciej Wieczor-Retman wrote:
>> +#ifdef CONFIG_KASAN_SW_TAGS
>> +#define page_to_virt(x) ({ \
>> + __typeof__(x) __page = x; \
>> + void *__addr = __va(page_to_pfn((__typeof__(x))__tag_reset(__page)) << PAGE_SHIFT); \
>> + (void *)__tag_set((const void *)__addr, page_kasan_tag(__page)); \
>> +})
>> +#endif
>
>Is this #ifdef needed?
>
>I thought there were stub versions of all of those tag functions. So it
>should be harmless to use this page_to_virt() implementation with or
>without KASAN. Right?
>
>I'm also confused by the implementation. This is one reason why I rather
>dislike macros. Why does this act like the type of 'x' is variable?
>Isn't it always a 'struct page *'? If so, then why all of the
>__typeof__()'s?
>
>Are struct page pointers _ever_ tagged? If they are, then doesn't
>page_to_pfn() need to handle untagging as well? If they aren't, then
>there's no reason to __tag_reset() in here.
>
>What was the thinking behind this cast:
>
> (const void *)__addr
>
>?
>
>Are any of these casts _doing_ anything? I'm struggling to find anything
>wrong with:
>
>#define page_to_virt(x) ({
> void *__addr = __va(page_to_pfn(__page) << PAGE_SHIFT);
> __tag_set(__addr, page_kasan_tag(x))
>})
>
>... which made me look back at:
>
> static inline const void *__tag_set(const void *addr, u8 tag)
>
>from patch 3. I don't think the 'const' makes any sense on the return
>value here. Surely the memory pointed at by a tagged pointer doesn't
>need to be const. Why should the tag setting function be returning a
>const pointer?
>
>I can see why it would *take* a const pointer since it's not modifying
>the memory, but I don't see why it is returning one.
>
Right, yes, both your page_to_virt() and removing the const from __tag_set()
return seem to be working just fine. Thanks for pointing it out.
With the macros I was trying to do what the arm64 implementation did assuming it
had some significance that wasn't written down anywhere.
I recall lack of the const thing was giving me a compilation error a while
back but now it's gone. And I didn't think much of it since arm had the same
thing.
If Andrey Konovalov is reading this: is there a reason the __tag_set() on arm64
returns a const pointer? And the page_to_virt() does the __typeof__()?
--
Kind regards
Maciej Wieczór-Retman
Powered by blists - more mailing lists