[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <08338619-6aa1-4905-bdf8-bf1a90857307@intel.com>
Date: Wed, 1 Oct 2025 13:50:13 -0700
From: Dave Hansen <dave.hansen@...el.com>
To: Brendan Jackman <jackmanb@...gle.com>, Andy Lutomirski <luto@...nel.org>,
Lorenzo Stoakes <lorenzo.stoakes@...cle.com>,
"Liam R. Howlett" <Liam.Howlett@...cle.com>,
Suren Baghdasaryan <surenb@...gle.com>, Michal Hocko <mhocko@...e.com>,
Johannes Weiner <hannes@...xchg.org>, Zi Yan <ziy@...dia.com>,
Axel Rasmussen <axelrasmussen@...gle.com>, Yuanchu Xie <yuanchu@...gle.com>,
Roman Gushchin <roman.gushchin@...ux.dev>
Cc: peterz@...radead.org, bp@...en8.de, dave.hansen@...ux.intel.com,
mingo@...hat.com, tglx@...utronix.de, akpm@...ux-foundation.org,
david@...hat.com, derkling@...gle.com, junaids@...gle.com,
linux-kernel@...r.kernel.org, linux-mm@...ck.org, reijiw@...gle.com,
rientjes@...gle.com, rppt@...nel.org, vbabka@...e.cz, x86@...nel.org,
Yosry Ahmed <yosry.ahmed@...ux.dev>
Subject: Re: [PATCH 05/21] x86/mm/pat: mirror direct map changes to ASI
On 9/24/25 07:59, Brendan Jackman wrote:
> ASI has a separate PGD for the physmap, which needs to be kept in sync
> with the unrestricted physmap with respect to permissions.
So that leads to another thing... What about vmalloc()? Why doesn't it
need to be in the ASI pgd?
> +static inline bool is_direct_map(unsigned long vaddr)
> +{
> + return within(vaddr, PAGE_OFFSET,
> + PAGE_OFFSET + (max_pfn_mapped << PAGE_SHIFT));
> +}
>
> static int __cpa_process_fault(struct cpa_data *cpa, unsigned long vaddr,
> int primary)
> @@ -1808,8 +1814,7 @@ static int __cpa_process_fault(struct cpa_data *cpa, unsigned long vaddr,
> * one virtual address page and its pfn. TBD: numpages can be set based
> * on the initial value and the level returned by lookup_address().
> */
> - if (within(vaddr, PAGE_OFFSET,
> - PAGE_OFFSET + (max_pfn_mapped << PAGE_SHIFT))) {
> + if (is_direct_map(vaddr)) {
> cpa->numpages = 1;
> cpa->pfn = __pa(vaddr) >> PAGE_SHIFT;
> return 0;
> @@ -1981,6 +1986,27 @@ static int cpa_process_alias(struct cpa_data *cpa)
> return 0;
> }
>
> +/*
> + * Having updated the unrestricted PGD, reflect this change in the ASI
> + * restricted address space too.
> + */
> +static inline int mirror_asi_direct_map(struct cpa_data *cpa, int primary)
> +{
> + struct cpa_data asi_cpa = *cpa;
> +
> + if (!asi_enabled_static())
> + return 0;
> +
> + /* Only need to do this for the real unrestricted direct map. */
> + if ((cpa->pgd && cpa->pgd != init_mm.pgd) || !is_direct_map(*cpa->vaddr))
> + return 0;
> + VM_WARN_ON_ONCE(!is_direct_map(*cpa->vaddr + (cpa->numpages * PAGE_SIZE)));
> +
> + asi_cpa.pgd = asi_nonsensitive_pgd;
> + asi_cpa.curpage = 0;
Please document what functionality this curpage=0 has. It's not clear.
> + return __change_page_attr(cpa, primary);
> +}
But let's say someone is doing something silly like:
set_memory_np(addr, size);
set_memory_p(addr, size);
Won't that end up in here and make the "unrestricted PGD" have
_PAGE_PRESENT==1 entries?
Also, could we try and make the nomenclature consistent? We've got
"unrestricted direct map" and "asi_nonsensitive_pgd" being used (at
least). Could the terminology be made more consistent?
One subtle thing here is that it's OK to allocate memory here when
mirroring changes into 'asi_nonsensitive_pgd'. It's just not OK when
flipping sensitivity. That seems worth a comment.
> static int __change_page_attr_set_clr(struct cpa_data *cpa, int primary)
> {
> unsigned long numpages = cpa->numpages;
> @@ -2007,6 +2033,8 @@ static int __change_page_attr_set_clr(struct cpa_data *cpa, int primary)
> if (!debug_pagealloc_enabled())
> spin_lock(&cpa_lock);
> ret = __change_page_attr(cpa, primary);
> + if (!ret)
> + ret = mirror_asi_direct_map(cpa, primary);
> if (!debug_pagealloc_enabled())
> spin_unlock(&cpa_lock);
> if (ret)
>
Is cpa->pgd ever have any values other than NULL or init_mm->pgd? I
didn't see anything in a quick grep.
Powered by blists - more mailing lists