linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* kmalloc() question - migration/remap of kmalloc()'ed pages
@ 2024-04-25  9:21 Mounesh Badiger
  2024-04-25  9:36 ` David Hildenbrand
  0 siblings, 1 reply; 4+ messages in thread
From: Mounesh Badiger @ 2024-04-25  9:21 UTC (permalink / raw)
  To: linux-mm

[-- Attachment #1: Type: text/plain, Size: 440 bytes --]

Hi,

We have a device driver that allocates physical pages using kmalloc() and
these pages are mapped to the userspace process via mmap.

Does the kmalloc()'ed memory mapped to userspace can migrate or get
remapped due to any of kernel mm operations?

we are looking to keep VA->PA mapping intact from a userspace process point
of view.

-- 
Mounesh Badiger
Support for education
Visit*: www.vidyaposhak.org <http://www.vidyaposhak.org/> *

[-- Attachment #2: Type: text/html, Size: 967 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: kmalloc() question - migration/remap of kmalloc()'ed pages
  2024-04-25  9:21 kmalloc() question - migration/remap of kmalloc()'ed pages Mounesh Badiger
@ 2024-04-25  9:36 ` David Hildenbrand
  2024-04-25  9:48   ` Mounesh Badiger
  0 siblings, 1 reply; 4+ messages in thread
From: David Hildenbrand @ 2024-04-25  9:36 UTC (permalink / raw)
  To: Mounesh Badiger, linux-mm

On 25.04.24 11:21, Mounesh Badiger wrote:
> Hi,

Hi,

> 
> We have a device driver that allocates physical pages using kmalloc() 
> and these pages are mapped to the userspace process via mmap.

Which interface are you using for inserting these pages into the page 
tables?

remap_pfn_range? vm_insert_page() ? ...

Using kmalloc sound weird ... why not simply alloc_pages()?

> 
> Does the kmalloc()'ed memory mapped to userspace can migrate or get 
> remapped due to any of kernel mm operations?

No.

> 
> we are looking to keep VA->PA mapping intact from a 
> userspace process point of view.

That will work.

-- 
Cheers,

David / dhildenb



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: kmalloc() question - migration/remap of kmalloc()'ed pages
  2024-04-25  9:36 ` David Hildenbrand
@ 2024-04-25  9:48   ` Mounesh Badiger
  2024-04-25  9:51     ` David Hildenbrand
  0 siblings, 1 reply; 4+ messages in thread
From: Mounesh Badiger @ 2024-04-25  9:48 UTC (permalink / raw)
  To: David Hildenbrand; +Cc: linux-mm

[-- Attachment #1: Type: text/plain, Size: 1026 bytes --]

Thanks for the confirmation.
I am using remap_pfn_range(). I can use alloc_pages() instead of kmalloc().

On Thu, Apr 25, 2024 at 3:06 PM David Hildenbrand <david@redhat.com> wrote:

> On 25.04.24 11:21, Mounesh Badiger wrote:
> > Hi,
>
> Hi,
>
> >
> > We have a device driver that allocates physical pages using kmalloc()
> > and these pages are mapped to the userspace process via mmap.
>
> Which interface are you using for inserting these pages into the page
> tables?
>
> remap_pfn_range? vm_insert_page() ? ...
>
> Using kmalloc sound weird ... why not simply alloc_pages()?
>
> >
> > Does the kmalloc()'ed memory mapped to userspace can migrate or get
> > remapped due to any of kernel mm operations?
>
> No.
>
> >
> > we are looking to keep VA->PA mapping intact from a
> > userspace process point of view.
>
> That will work.
>
> --
> Cheers,
>
> David / dhildenb
>
>

-- 
Mounesh Badiger
Support for education
Visit*: www.vidyaposhak.org <http://www.vidyaposhak.org/> *

[-- Attachment #2: Type: text/html, Size: 1822 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: kmalloc() question - migration/remap of kmalloc()'ed pages
  2024-04-25  9:48   ` Mounesh Badiger
@ 2024-04-25  9:51     ` David Hildenbrand
  0 siblings, 0 replies; 4+ messages in thread
From: David Hildenbrand @ 2024-04-25  9:51 UTC (permalink / raw)
  To: Mounesh Badiger; +Cc: linux-mm

On 25.04.24 11:48, Mounesh Badiger wrote:
> Thanks for the confirmation.
> I am using remap_pfn_range(). I can use alloc_pages() instead of kmalloc().
> 

Okay, for remap_pfn_range() it doesn't matter, because we'll never touch 
the "struct page" metadata (pages are considered not refcounted).

vm_insert_page() would likely have refused the kmalloc'ed pages because 
validate_page_before_insert() would refuse mapping any slab folios.

Should be working for you as expected.

-- 
Cheers,

David / dhildenb



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-04-25  9:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-25  9:21 kmalloc() question - migration/remap of kmalloc()'ed pages Mounesh Badiger
2024-04-25  9:36 ` David Hildenbrand
2024-04-25  9:48   ` Mounesh Badiger
2024-04-25  9:51     ` David Hildenbrand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox