Q:

NETLINK input function in kernel

When we invoke sendmsg API call from user process, input function is invoked and we have sent message to kernel.  Ok, but when we call recvmsg API call, is input function invoked again?  I saw this on example that I can not comment because I don't have reputations.  Title of that post is: "How to use netlink socket to communicate with a kernel module?"  So, could anyone see that example and tell me how to distinguish things between writing to kernel socket and reading from it. 

A:

Why would the input function be invoked again?  sendmsg() sends and recvmsg() receives.  The hello_nl_recv_msg() is only executed when the kernel module receives a message. 
In that example, the userspace program sends message A to the kernel using the sendmsg() function. 
Message A arrives to the kernel.  The kernel calls hello_nl_recv_msg().  Message A is encapsulated in the argument, skb. 
The kernel module chooses to send a response to the process whose process ID is the one that sent skb.  It creates message B. The kernel module sends message B to userspace using the nlmsg_unicast() function. 
Message B appears in userspace during the recvmsg() function. ( Because the process ID of the userspace program is the same the kernel module wrote to.) 
recvmsg() sleeps until a message to the kernel is received, so you don't have to worry whether the kernel has already answered or not before you call that function.