2

What is the difference between copying from user space buffer to kernel space buffer and, mapping user space buffer to kernel space buffer and then copying kernel space buffer to another kernel data structure?

What I meant to say is:

  1. The first method is copy_from_user() function.

  2. The second method is say, a user space buffer is mapped to kernel space and the kernel is passed with physical address(say using /proc/self/pagemap), then kernel space calls phys_to_virt() on the passed physical address to get it's corresponding kernel virtual address. Then kernel copies the data from one of its data structures say skb_buff to the kernel virtual address it got from the call to phys_to_virt() call.

    Note: phys_to_virt() adds an offset of 0xc0000000 to the passed physical address to get kernel virtual address, right?

The second method describes the functionality in DPDK for KNI module and they say in documentation that it eliminates the overhead of copying from user space to kernel space. Please explain me how.

Community
  • 1
  • 1

1 Answers1

0

It really depends on what you're trying to accomplish, but still some differences I can think about?

To begin with, copy_from_user has some built-in security checks that should be considered.

While mapping your data "manually" to kernel space enables you to read from it continuously, and maybe monitor something that the user process is doing to the data in that page, while using the copy_to_user method will require constantly calling it to be aware of changes.

Can you elaborate on what you are trying to do?

LITzman
  • 730
  • 1
  • 16