Skip to content

Commit 792230c

Browse files
jgross1David Vrabel
authored andcommitted
x86: Introduce function to get pmd entry pointer
Introduces lookup_pmd_address() to get the address of the pmd entry related to a virtual address in the current address space. This function is needed for support of a virtual mapped sparse p2m list in xen pv domains, as we need the address of the pmd entry, not the one of the pte in that case. Signed-off-by: Juergen Gross <jgross@suse.com> Signed-off-by: David Vrabel <david.vrabel@citrix.com>
1 parent 5b8e7d8 commit 792230c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

arch/x86/include/asm/pgtable_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ static inline void update_page_count(int level, unsigned long pages) { }
396396
extern pte_t *lookup_address(unsigned long address, unsigned int *level);
397397
extern pte_t *lookup_address_in_pgd(pgd_t *pgd, unsigned long address,
398398
unsigned int *level);
399+
extern pmd_t *lookup_pmd_address(unsigned long address);
399400
extern phys_addr_t slow_virt_to_phys(void *__address);
400401
extern int kernel_map_pages_in_pgd(pgd_t *pgd, u64 pfn, unsigned long address,
401402
unsigned numpages, unsigned long page_flags);

arch/x86/mm/pageattr.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,26 @@ static pte_t *_lookup_address_cpa(struct cpa_data *cpa, unsigned long address,
383383
return lookup_address(address, level);
384384
}
385385

386+
/*
387+
* Lookup the PMD entry for a virtual address. Return a pointer to the entry
388+
* or NULL if not present.
389+
*/
390+
pmd_t *lookup_pmd_address(unsigned long address)
391+
{
392+
pgd_t *pgd;
393+
pud_t *pud;
394+
395+
pgd = pgd_offset_k(address);
396+
if (pgd_none(*pgd))
397+
return NULL;
398+
399+
pud = pud_offset(pgd, address);
400+
if (pud_none(*pud) || pud_large(*pud) || !pud_present(*pud))
401+
return NULL;
402+
403+
return pmd_offset(pud, address);
404+
}
405+
386406
/*
387407
* This is necessary because __pa() does not work on some
388408
* kinds of memory, like vmalloc() or the alloc_remap()

0 commit comments

Comments
 (0)