[PATCH RFC 10/18] x86/mm/pat: move the large page size calculation to should_split_large_page
Mike Rapoport (Microsoft)
rppt at kernel.org
Tue Jul 21 09:23:33 PDT 2026
The calculation of large page size and mask and the update to
cpa->numpages use generic helpers and can be reused by common code.
The upcoming changes that will make should_split_large_page() available
in common code and __should_split_large_page() will become the basis of x86
specific implementation.
In preparation to moving core parts of change_page_attr() to common
code, move the generic calculations from __should_split_large_page() to
should_split_large_page().
No functional change intended.
Assisted-by: Copilot:claude-opus-4.8
Signed-off-by: Mike Rapoport (Microsoft) <rppt at kernel.org>
---
arch/x86/mm/pat/set_memory.c | 34 +++++++++++++++++++++-------------
1 file changed, 21 insertions(+), 13 deletions(-)
diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
index ef206ba6e254..56676d4cf510 100644
--- a/arch/x86/mm/pat/set_memory.c
+++ b/arch/x86/mm/pat/set_memory.c
@@ -58,6 +58,8 @@ struct cpa_data {
*/
struct cpa_split_data {
unsigned long address;
+ unsigned long psize;
+ unsigned long pmask;
pte_t *kpte;
struct ptdesc *ptdesc;
enum pgtable_level level;
@@ -884,10 +886,12 @@ static pgprot_t pgprot_clear_protnone_bits(pgprot_t prot)
static int __should_split_large_page(struct cpa_data *cpa,
struct cpa_split_data *sd)
{
- unsigned long numpages, pmask, psize, lpaddr, pfn, old_pfn;
pgprot_t old_prot, new_prot, req_prot, chk_prot;
+ unsigned long numpages, lpaddr, pfn, old_pfn;
enum pgtable_level level = sd->level;
unsigned long address = sd->address;
+ unsigned long psize = sd->psize;
+ unsigned long pmask = sd->pmask;
pte_t *kpte = sd->kpte;
bool nx = sd->nx;
bool rw = sd->rw;
@@ -908,18 +912,6 @@ static int __should_split_large_page(struct cpa_data *cpa,
return -EINVAL;
}
- psize = pgtable_level_size(level);
- pmask = pgtable_level_mask(level);
-
- /*
- * Calculate the number of pages, which fit into this large
- * page starting at address:
- */
- lpaddr = (address + psize) & pmask;
- numpages = (lpaddr - address) >> PAGE_SHIFT;
- if (numpages < cpa->numpages)
- cpa->numpages = numpages;
-
/*
* We are safe now. Check whether the new pgprot is the same:
* Convert protection attributes to 4k-format, as cpa->mask* are set
@@ -1026,9 +1018,25 @@ static int __should_split_large_page(struct cpa_data *cpa,
static int should_split_large_page(struct cpa_data *cpa,
struct cpa_split_data *sd)
{
+ enum pgtable_level level = sd->level;
+ unsigned long address = sd->address;
+ unsigned long numpages, lpaddr;
+
if (cpa->force_split)
return 1;
+ sd->psize = pgtable_level_size(level);
+ sd->pmask = pgtable_level_mask(level);
+
+ /*
+ * Calculate the number of pages, which fit into this large
+ * page starting at address:
+ */
+ lpaddr = (address + sd->psize) & sd->pmask;
+ numpages = (lpaddr - address) >> PAGE_SHIFT;
+ if (numpages < cpa->numpages)
+ cpa->numpages = numpages;
+
return __should_split_large_page(cpa, sd);
}
--
2.53.0
More information about the linux-riscv
mailing list