Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cd40b7d3 authored by Denis V. Lunev's avatar Denis V. Lunev Committed by David S. Miller
Browse files

[NET]: make netlink user -> kernel interface synchronious



This patch make processing netlink user -> kernel messages synchronious.
This change was inspired by the talk with Alexey Kuznetsov about current
netlink messages processing. He says that he was badly wrong when introduced 
asynchronious user -> kernel communication.

The call netlink_unicast is the only path to send message to the kernel
netlink socket. But, unfortunately, it is also used to send data to the
user.

Before this change the user message has been attached to the socket queue
and sk->sk_data_ready was called. The process has been blocked until all
pending messages were processed. The bad thing is that this processing
may occur in the arbitrary process context.

This patch changes nlk->data_ready callback to get 1 skb and force packet
processing right in the netlink_unicast.

Kernel -> user path in netlink_unicast remains untouched.

EINTR processing for in netlink_run_queue was changed. It forces rtnl_lock
drop, but the process remains in the cycle until the message will be fully
processed. So, there is no need to use this kludges now.

Signed-off-by: default avatarDenis V. Lunev <den@openvz.org>
Acked-by: default avatarAlexey Kuznetsov <kuznet@ms2.inr.ac.ru>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent aed81560
Loading
Loading
Loading
Loading
+1 −13
Original line number Original line Diff line number Diff line
@@ -234,18 +234,6 @@ static void cn_rx_skb(struct sk_buff *__skb)
	kfree_skb(__skb);
	kfree_skb(__skb);
}
}


/*
 * Netlink socket input callback - dequeues the skbs and calls the
 * main netlink receiving function.
 */
static void cn_input(struct sock *sk, int len)
{
	struct sk_buff *skb;

	while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL)
		cn_rx_skb(skb);
}

/*
/*
 * Notification routing.
 * Notification routing.
 *
 *
@@ -442,7 +430,7 @@ static int __devinit cn_init(void)
	struct cn_dev *dev = &cdev;
	struct cn_dev *dev = &cdev;
	int err;
	int err;


	dev->input = cn_input;
	dev->input = cn_rx_skb;
	dev->id.idx = cn_idx;
	dev->id.idx = cn_idx;
	dev->id.val = cn_val;
	dev->id.val = cn_val;


+2 −23
Original line number Original line Diff line number Diff line
@@ -64,7 +64,7 @@ scsi_nl_rcv_msg(struct sk_buff *skb)


		if (nlh->nlmsg_type != SCSI_TRANSPORT_MSG) {
		if (nlh->nlmsg_type != SCSI_TRANSPORT_MSG) {
			err = -EBADMSG;
			err = -EBADMSG;
			goto next_msg;
			return;
		}
		}


		hdr = NLMSG_DATA(nlh);
		hdr = NLMSG_DATA(nlh);
@@ -98,27 +98,6 @@ scsi_nl_rcv_msg(struct sk_buff *skb)
}
}




/**
 * scsi_nl_rcv_msg -
 *    Receive handler for a socket. Extracts a received message buffer from
 *    the socket, and starts message processing.
 *
 * @sk:		socket
 * @len:	unused
 *
 **/
static void
scsi_nl_rcv(struct sock *sk, int len)
{
	struct sk_buff *skb;

	while ((skb = skb_dequeue(&sk->sk_receive_queue))) {
		scsi_nl_rcv_msg(skb);
		kfree_skb(skb);
	}
}


/**
/**
 * scsi_nl_rcv_event -
 * scsi_nl_rcv_event -
 *    Event handler for a netlink socket.
 *    Event handler for a netlink socket.
@@ -168,7 +147,7 @@ scsi_netlink_init(void)
	}
	}


	scsi_nl_sock = netlink_kernel_create(&init_net, NETLINK_SCSITRANSPORT,
	scsi_nl_sock = netlink_kernel_create(&init_net, NETLINK_SCSITRANSPORT,
				SCSI_NL_GRP_CNT, scsi_nl_rcv, NULL,
				SCSI_NL_GRP_CNT, scsi_nl_rcv_msg, NULL,
				THIS_MODULE);
				THIS_MODULE);
	if (!scsi_nl_sock) {
	if (!scsi_nl_sock) {
		printk(KERN_ERR "%s: register of recieve handler failed\n",
		printk(KERN_ERR "%s: register of recieve handler failed\n",
+35 −47
Original line number Original line Diff line number Diff line
@@ -1097,22 +1097,13 @@ iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
}
}


/*
/*
 * Get message from skb (based on rtnetlink_rcv_skb).  Each message is
 * Get message from skb.  Each message is processed by iscsi_if_recv_msg.
 * processed by iscsi_if_recv_msg.  Malformed skbs with wrong lengths or
 * Malformed skbs with wrong lengths or invalid creds are not processed.
 * invalid creds are discarded silently.
 */
 */
static void
static void
iscsi_if_rx(struct sock *sk, int len)
iscsi_if_rx(struct sk_buff *skb)
{
{
	struct sk_buff *skb;

	mutex_lock(&rx_queue_mutex);
	mutex_lock(&rx_queue_mutex);
	while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) {
		if (NETLINK_CREDS(skb)->uid) {
			skb_pull(skb, skb->len);
			goto free_skb;
		}

	while (skb->len >= NLMSG_SPACE(0)) {
	while (skb->len >= NLMSG_SPACE(0)) {
		int err;
		int err;
		uint32_t rlen;
		uint32_t rlen;
@@ -1150,9 +1141,6 @@ iscsi_if_rx(struct sock *sk, int len)
		} while (err < 0 && err != -ECONNREFUSED);
		} while (err < 0 && err != -ECONNREFUSED);
		skb_pull(skb, rlen);
		skb_pull(skb, rlen);
	}
	}
free_skb:
		kfree_skb(skb);
	}
	mutex_unlock(&rx_queue_mutex);
	mutex_unlock(&rx_queue_mutex);
}
}


+1 −13
Original line number Original line Diff line number Diff line
@@ -165,22 +165,10 @@ static int ecryptfs_process_nl_quit(struct sk_buff *skb)
 * it to its desired netlink context element and wake up the process
 * it to its desired netlink context element and wake up the process
 * that is waiting for a response.
 * that is waiting for a response.
 */
 */
static void ecryptfs_receive_nl_message(struct sock *sk, int len)
static void ecryptfs_receive_nl_message(struct sk_buff *skb)
{
{
	struct sk_buff *skb;
	struct nlmsghdr *nlh;
	struct nlmsghdr *nlh;
	int rc = 0;	/* skb_recv_datagram requires this */


receive:
	skb = skb_recv_datagram(sk, 0, 0, &rc);
	if (rc == -EINTR)
		goto receive;
	else if (rc < 0) {
		ecryptfs_printk(KERN_ERR, "Error occurred while "
				"receiving eCryptfs netlink message; "
				"rc = [%d]\n", rc);
		return;
	}
	nlh = nlmsg_hdr(skb);
	nlh = nlmsg_hdr(skb);
	if (!NLMSG_OK(nlh, skb->len)) {
	if (!NLMSG_OK(nlh, skb->len)) {
		ecryptfs_printk(KERN_ERR, "Received corrupt netlink "
		ecryptfs_printk(KERN_ERR, "Received corrupt netlink "
+1 −1
Original line number Original line Diff line number Diff line
@@ -153,7 +153,7 @@ struct cn_dev {


	u32 seq, groups;
	u32 seq, groups;
	struct sock *nls;
	struct sock *nls;
	void (*input) (struct sock * sk, int len);
	void (*input) (struct sk_buff *skb);


	struct cn_queue_dev *cbdev;
	struct cn_queue_dev *cbdev;
};
};
Loading