kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* kernel_thread() causes segfault
@ 2016-03-22 10:14 Manoj Nayak
  2016-03-22 11:21 ` Shashank Khasare
  0 siblings, 1 reply; 5+ messages in thread
From: Manoj Nayak @ 2016-03-22 10:14 UTC (permalink / raw)
  To: kernelnewbies

What is the usecase here ? Do we need to share the entire process address
space to a kernel thread ?

If address space sharing between userspace thread and kernel thread space
is the whole idea then we can mmap process address space and do
get_user_pages() to allocate physcial page and pin it.
kernel thread can do kmap() and  kumap() to use the pages from process
address space.

http://lxr.free-electrons.com/source/fs/aio.c?v=3.8#L99

Regards
Manoj Nayak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160322/e025e14b/attachment.html 

^ permalink raw reply	[flat|nested] 5+ messages in thread
* kernel_thread() causes segfault
@ 2016-03-22 13:45 Manoj Nayak
  0 siblings, 0 replies; 5+ messages in thread
From: Manoj Nayak @ 2016-03-22 13:45 UTC (permalink / raw)
  To: kernelnewbies

Process has files_struct and fs_struct in task_struct.

Two thread's  task_struct can point to same files_struct and fs_struct if
we do the changes through a new system call.

Please check the following URL.

http://lxr.free-electrons.com/source/kernel/fork.c#L993

Regards
Manoj Nayak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160322/687ef0ce/attachment.html 

^ permalink raw reply	[flat|nested] 5+ messages in thread
* kernel_thread() causes segfault
@ 2016-03-21  6:16 Shashank Khasare
  0 siblings, 0 replies; 5+ messages in thread
From: Shashank Khasare @ 2016-03-21  6:16 UTC (permalink / raw)
  To: kernelnewbies

Hi,

I want to write a new syscall in which caller process would create kernel
thread which shares the process address space, file descriptor table,
parent pid etc.
The new kernel thread would be clone of current thread but it would never
execute any userspace code.

The kernel_thread() function with following arguments would be ideal to
achieve this task:
kernel_thread(some_function, some_args, CLONE_FS | CLONE_FILES |
CLONE_PARENT)

In latest kernels (v3.1x), this function causes segmentation fault in the
user process.
However same code works perfectly in older kernels (v2.6).

According to this link
<https://groups.google.com/forum/#%21searchin/linux.kernel/kernel_thread%28%29/linux.kernel/LPWuY2DMMuA/L2hv1x23YqQJ>,
and this code
<http://lxr.free-electrons.com/source/arch/x86/kernel/process_64.c?v=3.16#L177>
(call chain: kernel_thread -> do_fork -> copy_process -> copy_thread), it
looks like only the kernel thread can spawn another kernel thread. (I tried
to set PF_KTHREAD flag in current->flags before calling kernel_thread
function, but the system crashed.)

Is there any clean way of creating kernel thread that shares process
address space, file descriptor table, parent pid etc?


Thanks,
Shashank Khasare
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160321/9a074fde/attachment.html 

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

end of thread, other threads:[~2016-03-22 17:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-22 10:14 kernel_thread() causes segfault Manoj Nayak
2016-03-22 11:21 ` Shashank Khasare
2016-03-22 17:13   ` Valdis.Kletnieks at vt.edu
  -- strict thread matches above, loose matches on Subject: below --
2016-03-22 13:45 Manoj Nayak
2016-03-21  6:16 Shashank Khasare

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).