aMa
aMa

Reputation: 649

How to convert physical address to kernel page structure inside kernel module (x86-64)?

How do I convert physical address to kernel page structure inside kernel module? (only for x86-64 arch).

following is what I have so far:

void *kernel_logical_address = phys_to_virt(physical_address);

Now, how do I get struct page for this kernel_logical_address?

Why do I need it?

In the kernel module I am working on, it maintains a list of free pages

 struct page *pages

I want to add this special page (the one points to physical_address) to this particular list. How do I do this?

Upvotes: 0

Views: 512

Answers (2)

Alex Hoppus
Alex Hoppus

Reputation: 3935

Use pfn_to_page(pfn_num) macro. Pfn num == phys_addr >> 12

Upvotes: 2

Zang MingJie
Zang MingJie

Reputation: 5285

No, you can't. there is no trivial way other than lock and traversal all mapped pages.

Because the same page may be mapped multiple time at different linear address or isn't mapped at all.

Upvotes: 1

Related Questions