Netdev List
 help / color / mirror / Atom feed
* [PATCH 6/8] Phonet: provide pipe socket option to retrieve the pipe identifier
From: Rémi Denis-Courmont @ 2011-03-04 10:00 UTC (permalink / raw)
  To: netdev
In-Reply-To: <201103031322.37184.remi.denis-courmont@nokia.com>

User-space sometimes needs this information.

Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
 Documentation/networking/phonet.txt |    7 ++++---
 include/linux/phonet.h              |    2 +-
 net/phonet/pep.c                    |   15 +++++++--------
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/Documentation/networking/phonet.txt b/Documentation/networking/phonet.txt
index 24ad2ad..cacac96 100644
--- a/Documentation/networking/phonet.txt
+++ b/Documentation/networking/phonet.txt
@@ -181,6 +181,10 @@ The pipe protocol provides two socket options at the SOL_PNPIPE level:
     interface index of the network interface created by PNPIPE_ENCAP,
     or zero if encapsulation is off.
 
+  PNPIPE_HANDLE is a read-only integer value. It contains the underlying
+    identifier ("pipe handle") of the pipe. This is only defined for
+    socket descriptors that are already connected or being connected.
+
 
 Phonet Pipe-controller Implementation
 -------------------------------------
@@ -199,9 +203,6 @@ between itself and a remote pipe-end point (e.g. modem).
 
 The implementation adds socket options at SOL_PNPIPE level:
 
- PNPIPE_PIPE_HANDLE
-	It accepts an integer argument for setting value of pipe handle.
-
   PNPIPE_ENABLE accepts one integer value (int). If set to zero, the pipe
     is disabled. If the value is non-zero, the pipe is enabled. If the pipe
     is not (yet) connected, ENOTCONN is error is returned.
diff --git a/include/linux/phonet.h b/include/linux/phonet.h
index 26c8df7..32a0965 100644
--- a/include/linux/phonet.h
+++ b/include/linux/phonet.h
@@ -36,7 +36,7 @@
 /* Socket options for SOL_PNPIPE level */
 #define PNPIPE_ENCAP		1
 #define PNPIPE_IFINDEX		2
-#define PNPIPE_PIPE_HANDLE	3
+#define PNPIPE_HANDLE		3
 #define PNPIPE_ENABLE           4
 /* unused slot */
 
diff --git a/net/phonet/pep.c b/net/phonet/pep.c
index c0fab4c..abfb795 100644
--- a/net/phonet/pep.c
+++ b/net/phonet/pep.c
@@ -853,6 +853,7 @@ static int pep_sock_connect(struct sock *sk, struct sockaddr *addr, int len)
 
 	pn->pn_sk.dobject = pn_sockaddr_get_object(spn);
 	pn->pn_sk.resource = pn_sockaddr_get_resource(spn);
+	pn->pipe_handle = 1; /* anything but INVALID_HANDLE */
 	return pipe_handler_request(sk, PNS_PEP_CONNECT_REQ,
 					PN_PIPE_DISABLE, data, 4);
 }
@@ -909,14 +910,6 @@ static int pep_setsockopt(struct sock *sk, int level, int optname,
 
 	lock_sock(sk);
 	switch (optname) {
-#ifdef CONFIG_PHONET_PIPECTRLR
-	case PNPIPE_PIPE_HANDLE:
-		if (val) {
-			pn->pipe_handle = val;
-			break;
-		}
-#endif
-
 	case PNPIPE_ENCAP:
 		if (val && val != PNPIPE_ENCAP_IP) {
 			err = -EINVAL;
@@ -982,6 +975,12 @@ static int pep_getsockopt(struct sock *sk, int level, int optname,
 		val = pn->ifindex;
 		break;
 
+	case PNPIPE_HANDLE:
+		val = pn->pipe_handle;
+		if (val == PN_PIPE_INVALID_HANDLE)
+			return -EINVAL;
+		break;
+
 #ifdef CONFIG_PHONET_PIPECTRLR
 	case PNPIPE_ENABLE:
 		val = sk->sk_state == TCP_ESTABLISHED;
-- 
1.7.1


^ permalink raw reply related

* [PATCH 7/8] Phonet: support active connection without pipe controller on modem
From: Rémi Denis-Courmont @ 2011-03-04 10:00 UTC (permalink / raw)
  To: netdev
In-Reply-To: <201103031322.37184.remi.denis-courmont@nokia.com>

This provides support for newer ISI modems with no need for the
earlier experimental compile-time alternative choice. This also fixes
a number of remaining bugs in the old ST-E code.

Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
 Documentation/networking/phonet.txt |   53 +++++------
 net/phonet/pep.c                    |  172 ++++++++++++++++++++--------------
 net/phonet/socket.c                 |  102 ++++++++-------------
 3 files changed, 165 insertions(+), 162 deletions(-)

diff --git a/Documentation/networking/phonet.txt b/Documentation/networking/phonet.txt
index cacac96..3d12779 100644
--- a/Documentation/networking/phonet.txt
+++ b/Documentation/networking/phonet.txt
@@ -154,9 +154,28 @@ connections, one per accept()'d socket.
     write(cfd, msg, msglen);
   }
 
-Connections are established between two endpoints by a "third party"
-application. This means that both endpoints are passive; so connect()
-is not possible.
+Connections are traditionally established between two endpoints by a
+"third party" application. This means that both endpoints are passive.
+
+
+As of Linux kernel version 2.6.39, it is also possible to connect
+two endpoints directly, using connect() on the active side. This is
+intended to support the newer Nokia Wireless Modem API, as found in
+e.g. the Nokia Slim Modem in the ST-Ericsson U8500 platform:
+
+  struct sockaddr_spn spn;
+  int fd;
+
+  fd = socket(PF_PHONET, SOCK_SEQPACKET, PN_PROTO_PIPE);
+  memset(&spn, 0, sizeof(spn));
+  spn.spn_family = AF_PHONET;
+  spn.spn_obj = ...;
+  spn.spn_dev = ...;
+  spn.spn_resource = 0xD9;
+  connect(fd, (struct sockaddr *)&spn, sizeof(spn));
+  /* normal I/O here ... */
+  close(fd);
+
 
 WARNING:
 When polling a connected pipe socket for writability, there is an
@@ -189,17 +208,8 @@ The pipe protocol provides two socket options at the SOL_PNPIPE level:
 Phonet Pipe-controller Implementation
 -------------------------------------
 
-Phonet Pipe-controller is enabled by selecting the CONFIG_PHONET_PIPECTRLR Kconfig
-option. It is useful when communicating with those Nokia Modems which do not
-implement Pipe controller in them e.g. Nokia Slim Modem used in ST-Ericsson
-U8500 platform.
-
-The implementation is based on the Data Connection Establishment Sequence
-depicted in 'Nokia Wireless Modem API - Wireless_modem_user_guide.pdf'
-document.
-
-It allows a phonet sequenced socket (host-pep) to initiate a Pipe connection
-between itself and a remote pipe-end point (e.g. modem).
+Phonet Pipe-controller is enabled by selecting the CONFIG_PHONET_PIPECTRLR
+Kconfig option.
 
 The implementation adds socket options at SOL_PNPIPE level:
 
@@ -207,21 +217,6 @@ The implementation adds socket options at SOL_PNPIPE level:
     is disabled. If the value is non-zero, the pipe is enabled. If the pipe
     is not (yet) connected, ENOTCONN is error is returned.
 
-The implementation also adds socket 'connect'. On calling the 'connect', pipe
-will be created between the source socket and the destination, and the pipe
-state will be set to PIPE_DISABLED.
-
-After a pipe has been created and enabled successfully, the Pipe data can be
-exchanged between the host-pep and remote-pep (modem).
-
-User-space would typically follow below sequence with Pipe controller:-
--socket
--bind
--setsockopt for PNPIPE_PIPE_HANDLE
--connect
--setsockopt for PNPIPE_ENCAP_IP
--setsockopt for PNPIPE_ENABLE
-
 
 Authors
 -------
diff --git a/net/phonet/pep.c b/net/phonet/pep.c
index abfb795..671effb 100644
--- a/net/phonet/pep.c
+++ b/net/phonet/pep.c
@@ -136,7 +136,6 @@ static int pep_indicate(struct sock *sk, u8 id, u8 code,
 
 #define PAD 0x00
 
-#ifdef CONFIG_PHONET_PIPECTRLR
 static int pipe_handler_request(struct sock *sk, u8 id, u8 code,
 				const void *data, int len)
 {
@@ -168,11 +167,7 @@ static int pipe_handler_send_created_ind(struct sock *sk)
 				data, 4, GFP_ATOMIC);
 }
 
-static int pipe_handler_send_ind(struct sock *sk, u8 id)
-{
-	return pep_indicate(sk, id, PAD, NULL, 0, GFP_ATOMIC);
-}
-
+#ifdef CONFIG_PHONET_PIPECTRLR
 static int pipe_handler_enable_pipe(struct sock *sk, int enable)
 {
 	u8 id = enable ? PNS_PEP_ENABLE_REQ : PNS_PEP_DISABLE_REQ;
@@ -376,32 +371,11 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
 			sk->sk_state_change(sk);
 		break;
 
-#ifdef CONFIG_PHONET_PIPECTRLR
-	case PNS_PEP_DISCONNECT_RESP:
-		sk->sk_state = TCP_CLOSE;
-		break;
-#endif
-
 	case PNS_PEP_ENABLE_REQ:
 		/* Wait for PNS_PIPE_(ENABLED|REDIRECTED)_IND */
 		pep_reply(sk, skb, PN_PIPE_NO_ERROR, NULL, 0, GFP_ATOMIC);
 		break;
 
-#ifdef CONFIG_PHONET_PIPECTRLR
-	case PNS_PEP_ENABLE_RESP:
-		pipe_handler_send_ind(sk, PNS_PIPE_ENABLED_IND);
-
-		if (!pn_flow_safe(pn->tx_fc)) {
-			atomic_set(&pn->tx_credits, 1);
-			sk->sk_write_space(sk);
-		}
-		if (sk->sk_state == TCP_ESTABLISHED)
-			break; /* Nothing to do */
-		sk->sk_state = TCP_ESTABLISHED;
-		pipe_grant_credits(sk, GFP_ATOMIC);
-		break;
-#endif
-
 	case PNS_PEP_RESET_REQ:
 		switch (hdr->state_after_reset) {
 		case PN_PIPE_DISABLE:
@@ -420,15 +394,6 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
 		pep_reply(sk, skb, PN_PIPE_NO_ERROR, NULL, 0, GFP_ATOMIC);
 		break;
 
-#ifdef CONFIG_PHONET_PIPECTRLR
-	case PNS_PEP_DISABLE_RESP:
-		atomic_set(&pn->tx_credits, 0);
-		pipe_handler_send_ind(sk, PNS_PIPE_DISABLED_IND);
-		sk->sk_state = TCP_SYN_RECV;
-		pn->rx_credits = 0;
-		break;
-#endif
-
 	case PNS_PEP_CTRL_REQ:
 		if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
 			atomic_inc(&sk->sk_drops);
@@ -521,7 +486,6 @@ static void pipe_destruct(struct sock *sk)
 	skb_queue_purge(&pn->ctrlreq_queue);
 }
 
-#ifdef CONFIG_PHONET_PIPECTRLR
 static u8 pipe_negotiate_fc(const u8 *fcs, unsigned n)
 {
 	unsigned i;
@@ -546,6 +510,8 @@ static int pep_connresp_rcv(struct sock *sk, struct sk_buff *skb)
 		return -EINVAL;
 
 	hdr = pnp_hdr(skb);
+	if (hdr->error_code != PN_PIPE_NO_ERROR)
+		return -ECONNREFUSED;
 
 	/* Parse sub-blocks */
 	n_sb = hdr->data[4];
@@ -573,14 +539,74 @@ static int pep_connresp_rcv(struct sock *sk, struct sk_buff *skb)
 		n_sb--;
 	}
 
-	sk->sk_state = TCP_SYN_RECV;
-	sk->sk_backlog_rcv = pipe_do_rcv;
-	pn->rx_credits = 0;
-	sk->sk_state_change(sk);
-
 	return pipe_handler_send_created_ind(sk);
 }
-#endif
+
+/* Queue an skb to an actively connected sock.
+ * Socket lock must be held. */
+static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
+{
+	struct pep_sock *pn = pep_sk(sk);
+	struct pnpipehdr *hdr = pnp_hdr(skb);
+	int err = NET_RX_SUCCESS;
+
+	switch (hdr->message_id) {
+	case PNS_PIPE_ALIGNED_DATA:
+		__skb_pull(skb, 1);
+		/* fall through */
+	case PNS_PIPE_DATA:
+		__skb_pull(skb, 3); /* Pipe data header */
+		if (!pn_flow_safe(pn->rx_fc)) {
+			err = sock_queue_rcv_skb(sk, skb);
+			if (!err)
+				return NET_RX_SUCCESS;
+			err = NET_RX_DROP;
+			break;
+		}
+
+		if (pn->rx_credits == 0) {
+			atomic_inc(&sk->sk_drops);
+			err = NET_RX_DROP;
+			break;
+		}
+		pn->rx_credits--;
+		skb->dev = NULL;
+		skb_set_owner_r(skb, sk);
+		err = skb->len;
+		skb_queue_tail(&sk->sk_receive_queue, skb);
+		if (!sock_flag(sk, SOCK_DEAD))
+			sk->sk_data_ready(sk, err);
+		return NET_RX_SUCCESS;
+
+	case PNS_PEP_CONNECT_RESP:
+		if (sk->sk_state != TCP_SYN_SENT)
+			break;
+		if (!sock_flag(sk, SOCK_DEAD))
+			sk->sk_state_change(sk);
+		if (pep_connresp_rcv(sk, skb)) {
+			sk->sk_state = TCP_CLOSE_WAIT;
+			break;
+		}
+
+		sk->sk_state = TCP_ESTABLISHED;
+		if (!pn_flow_safe(pn->tx_fc)) {
+			atomic_set(&pn->tx_credits, 1);
+			sk->sk_write_space(sk);
+		}
+		pipe_grant_credits(sk, GFP_ATOMIC);
+		break;
+
+	case PNS_PEP_DISCONNECT_RESP:
+		/* sock should already be dead, nothing to do */
+		break;
+
+	case PNS_PEP_STATUS_IND:
+		pipe_rcv_status(sk, skb);
+		break;
+	}
+	kfree_skb(skb);
+	return err;
+}
 
 /* Listening sock must be locked */
 static struct sock *pep_find_pipe(const struct hlist_head *hlist,
@@ -649,12 +675,6 @@ static int pep_do_rcv(struct sock *sk, struct sk_buff *skb)
 			sk->sk_data_ready(sk, 0);
 		return NET_RX_SUCCESS;
 
-#ifdef CONFIG_PHONET_PIPECTRLR
-	case PNS_PEP_CONNECT_RESP:
-		pep_connresp_rcv(sk, skb);
-		break;
-#endif
-
 	case PNS_PEP_DISCONNECT_REQ:
 		pep_reply(sk, skb, PN_PIPE_NO_ERROR, NULL, 0, GFP_ATOMIC);
 		break;
@@ -667,15 +687,19 @@ static int pep_do_rcv(struct sock *sk, struct sk_buff *skb)
 	case PNS_PEP_ENABLE_REQ:
 	case PNS_PEP_DISABLE_REQ:
 		/* invalid handle is not even allowed here! */
-	default:
 		break;
+
+	default:
+		if ((1 << sk->sk_state)
+				& ~(TCPF_CLOSE|TCPF_LISTEN|TCPF_CLOSE_WAIT))
+			/* actively connected socket */
+			return pipe_handler_do_rcv(sk, skb);
 	}
 drop:
 	kfree_skb(skb);
 	return NET_RX_SUCCESS;
 }
 
-#ifndef CONFIG_PHONET_PIPECTRLR
 static int pipe_do_remove(struct sock *sk)
 {
 	struct pep_sock *pn = pep_sk(sk);
@@ -693,7 +717,6 @@ static int pipe_do_remove(struct sock *sk)
 	ph->data[0] = PAD;
 	return pn_skb_send(sk, skb, NULL);
 }
-#endif
 
 /* associated socket ceases to exist */
 static void pep_sock_close(struct sock *sk, long timeout)
@@ -706,13 +729,12 @@ static void pep_sock_close(struct sock *sk, long timeout)
 
 	lock_sock(sk);
 	if ((1 << sk->sk_state) & (TCPF_SYN_RECV|TCPF_ESTABLISHED)) {
-#ifndef CONFIG_PHONET_PIPECTRLR
-		/* Forcefully remove dangling Phonet pipe */
-		pipe_do_remove(sk);
-#else
-		/* send pep disconnect request */
-		pipe_handler_request(sk, PNS_PEP_DISCONNECT_REQ, PAD, NULL, 0);
-#endif
+		if (sk->sk_backlog_rcv == pipe_do_rcv)
+			/* Forcefully remove dangling Phonet pipe */
+			pipe_do_remove(sk);
+		else
+			pipe_handler_request(sk, PNS_PEP_DISCONNECT_REQ, PAD,
+						NULL, 0);
 	}
 	sk->sk_state = TCP_CLOSE;
 
@@ -844,20 +866,22 @@ drop:
 	return newsk;
 }
 
-#ifdef CONFIG_PHONET_PIPECTRLR
 static int pep_sock_connect(struct sock *sk, struct sockaddr *addr, int len)
 {
 	struct pep_sock *pn = pep_sk(sk);
-	const struct sockaddr_pn *spn = (struct sockaddr_pn *)addr;
+	int err;
 	u8 data[4] = { 0 /* sub-blocks */, PAD, PAD, PAD };
 
-	pn->pn_sk.dobject = pn_sockaddr_get_object(spn);
-	pn->pn_sk.resource = pn_sockaddr_get_resource(spn);
 	pn->pipe_handle = 1; /* anything but INVALID_HANDLE */
-	return pipe_handler_request(sk, PNS_PEP_CONNECT_REQ,
-					PN_PIPE_DISABLE, data, 4);
+	err = pipe_handler_request(sk, PNS_PEP_CONNECT_REQ,
+					PN_PIPE_ENABLE, data, 4);
+	if (err) {
+		pn->pipe_handle = PN_PIPE_INVALID_HANDLE;
+		return err;
+	}
+	sk->sk_state = TCP_SYN_SENT;
+	return 0;
 }
-#endif
 
 static int pep_ioctl(struct sock *sk, int cmd, unsigned long arg)
 {
@@ -890,8 +914,16 @@ static int pep_init(struct sock *sk)
 
 	sk->sk_destruct = pipe_destruct;
 	INIT_HLIST_HEAD(&pn->hlist);
+	pn->listener = NULL;
 	skb_queue_head_init(&pn->ctrlreq_queue);
+	atomic_set(&pn->tx_credits, 0);
+	pn->ifindex = 0;
+	pn->peer_type = 0;
 	pn->pipe_handle = PN_PIPE_INVALID_HANDLE;
+	pn->rx_credits = 0;
+	pn->rx_fc = pn->tx_fc = PN_LEGACY_FLOW_CONTROL;
+	pn->init_enable = 1;
+	pn->aligned = 0;
 	return 0;
 }
 
@@ -1219,9 +1251,9 @@ static void pep_sock_unhash(struct sock *sk)
 
 	lock_sock(sk);
 
-#ifndef CONFIG_PHONET_PIPECTRLR
-	if ((1 << sk->sk_state) & ~(TCPF_CLOSE|TCPF_LISTEN)) {
+	if (pn->listener != NULL) {
 		skparent = pn->listener;
+		pn->listener = NULL;
 		release_sock(sk);
 
 		pn = pep_sk(skparent);
@@ -1229,7 +1261,7 @@ static void pep_sock_unhash(struct sock *sk)
 		sk_del_node_init(sk);
 		sk = skparent;
 	}
-#endif
+
 	/* Unhash a listening sock only when it is closed
 	 * and all of its active connected pipes are closed. */
 	if (hlist_empty(&pn->hlist))
@@ -1243,9 +1275,7 @@ static void pep_sock_unhash(struct sock *sk)
 static struct proto pep_proto = {
 	.close		= pep_sock_close,
 	.accept		= pep_sock_accept,
-#ifdef CONFIG_PHONET_PIPECTRLR
 	.connect	= pep_sock_connect,
-#endif
 	.ioctl		= pep_ioctl,
 	.init		= pep_init,
 	.setsockopt	= pep_setsockopt,
diff --git a/net/phonet/socket.c b/net/phonet/socket.c
index 1eccfc3..b1adafa 100644
--- a/net/phonet/socket.c
+++ b/net/phonet/socket.c
@@ -225,15 +225,18 @@ static int pn_socket_autobind(struct socket *sock)
 	return 0; /* socket was already bound */
 }
 
-#ifdef CONFIG_PHONET_PIPECTRLR
 static int pn_socket_connect(struct socket *sock, struct sockaddr *addr,
 		int len, int flags)
 {
 	struct sock *sk = sock->sk;
+	struct pn_sock *pn = pn_sk(sk);
 	struct sockaddr_pn *spn = (struct sockaddr_pn *)addr;
-	long timeo;
+	struct task_struct *tsk = current;
+	long timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);
 	int err;
 
+	if (pn_socket_autobind(sock))
+		return -ENOBUFS;
 	if (len < sizeof(struct sockaddr_pn))
 		return -EINVAL;
 	if (spn->spn_family != AF_PHONET)
@@ -243,82 +246,61 @@ static int pn_socket_connect(struct socket *sock, struct sockaddr *addr,
 
 	switch (sock->state) {
 	case SS_UNCONNECTED:
-		sk->sk_state = TCP_CLOSE;
-		break;
-	case SS_CONNECTING:
-		switch (sk->sk_state) {
-		case TCP_SYN_RECV:
-			sock->state = SS_CONNECTED;
-			err = -EISCONN;
-			goto out;
-		case TCP_CLOSE:
-			err = -EALREADY;
-			if (flags & O_NONBLOCK)
-				goto out;
-			goto wait_connect;
-		}
-		break;
-	case SS_CONNECTED:
-		switch (sk->sk_state) {
-		case TCP_SYN_RECV:
+		if (sk->sk_state != TCP_CLOSE) {
 			err = -EISCONN;
 			goto out;
-		case TCP_CLOSE:
-			sock->state = SS_UNCONNECTED;
-			break;
 		}
 		break;
-	case SS_DISCONNECTING:
-	case SS_FREE:
-		break;
+	case SS_CONNECTING:
+		err = -EALREADY;
+		goto out;
+	default:
+		err = -EISCONN;
+		goto out;
 	}
-	sk->sk_state = TCP_CLOSE;
-	sk_stream_kill_queues(sk);
 
+	pn->dobject = pn_sockaddr_get_object(spn);
+	pn->resource = pn_sockaddr_get_resource(spn);
 	sock->state = SS_CONNECTING;
+
 	err = sk->sk_prot->connect(sk, addr, len);
-	if (err < 0) {
+	if (err) {
 		sock->state = SS_UNCONNECTED;
-		sk->sk_state = TCP_CLOSE;
+		pn->dobject = 0;
 		goto out;
 	}
 
-	err = -EINPROGRESS;
-wait_connect:
-	if (sk->sk_state != TCP_SYN_RECV && (flags & O_NONBLOCK))
-		goto out;
-
-	timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
-	release_sock(sk);
+	while (sk->sk_state == TCP_SYN_SENT) {
+		DEFINE_WAIT(wait);
 
-	err = -ERESTARTSYS;
-	timeo = wait_event_interruptible_timeout(*sk_sleep(sk),
-			sk->sk_state != TCP_CLOSE,
-			timeo);
-
-	lock_sock(sk);
-	if (timeo < 0)
-		goto out; /* -ERESTARTSYS */
-
-	err = -ETIMEDOUT;
-	if (timeo == 0 && sk->sk_state != TCP_SYN_RECV)
-		goto out;
+		if (!timeo) {
+			err = -EINPROGRESS;
+			goto out;
+		}
+		if (signal_pending(tsk)) {
+			err = sock_intr_errno(timeo);
+			goto out;
+		}
 
-	if (sk->sk_state != TCP_SYN_RECV) {
-		sock->state = SS_UNCONNECTED;
-		err = sock_error(sk);
-		if (!err)
-			err = -ECONNREFUSED;
-		goto out;
+		prepare_to_wait_exclusive(sk_sleep(sk), &wait,
+						TASK_INTERRUPTIBLE);
+		release_sock(sk);
+		timeo = schedule_timeout(timeo);
+		lock_sock(sk);
+		finish_wait(sk_sleep(sk), &wait);
 	}
-	sock->state = SS_CONNECTED;
-	err = 0;
 
+	if ((1 << sk->sk_state) & (TCPF_SYN_RECV|TCPF_ESTABLISHED))
+		err = 0;
+	else if (sk->sk_state == TCP_CLOSE_WAIT)
+		err = -ECONNRESET;
+	else
+		err = -ECONNREFUSED;
+	sock->state = err ? SS_UNCONNECTED : SS_CONNECTED;
 out:
 	release_sock(sk);
 	return err;
 }
-#endif
 
 static int pn_socket_accept(struct socket *sock, struct socket *newsock,
 				int flags)
@@ -486,11 +468,7 @@ const struct proto_ops phonet_stream_ops = {
 	.owner		= THIS_MODULE,
 	.release	= pn_socket_release,
 	.bind		= pn_socket_bind,
-#ifdef CONFIG_PHONET_PIPECTRLR
 	.connect	= pn_socket_connect,
-#else
-	.connect	= sock_no_connect,
-#endif
 	.socketpair	= sock_no_socketpair,
 	.accept		= pn_socket_accept,
 	.getname	= pn_socket_getname,
-- 
1.7.1


^ permalink raw reply related

* [PATCH 8/8] Phonet: kill the ST-Ericsson pipe controller Kconfig
From: Rémi Denis-Courmont @ 2011-03-04 10:00 UTC (permalink / raw)
  To: netdev
In-Reply-To: <201103031322.37184.remi.denis-courmont@nokia.com>

This is now a run-time choice so that a single kernel can support both
old and new generation ISI modems.

Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
 Documentation/networking/phonet.txt |   13 -------------
 include/linux/phonet.h              |    2 --
 net/phonet/Kconfig                  |   12 ------------
 net/phonet/pep.c                    |   25 -------------------------
 4 files changed, 0 insertions(+), 52 deletions(-)

diff --git a/Documentation/networking/phonet.txt b/Documentation/networking/phonet.txt
index 3d12779..8100358 100644
--- a/Documentation/networking/phonet.txt
+++ b/Documentation/networking/phonet.txt
@@ -205,19 +205,6 @@ The pipe protocol provides two socket options at the SOL_PNPIPE level:
     socket descriptors that are already connected or being connected.
 
 
-Phonet Pipe-controller Implementation
--------------------------------------
-
-Phonet Pipe-controller is enabled by selecting the CONFIG_PHONET_PIPECTRLR
-Kconfig option.
-
-The implementation adds socket options at SOL_PNPIPE level:
-
-  PNPIPE_ENABLE accepts one integer value (int). If set to zero, the pipe
-    is disabled. If the value is non-zero, the pipe is enabled. If the pipe
-    is not (yet) connected, ENOTCONN is error is returned.
-
-
 Authors
 -------
 
diff --git a/include/linux/phonet.h b/include/linux/phonet.h
index 32a0965..6fb1384 100644
--- a/include/linux/phonet.h
+++ b/include/linux/phonet.h
@@ -37,8 +37,6 @@
 #define PNPIPE_ENCAP		1
 #define PNPIPE_IFINDEX		2
 #define PNPIPE_HANDLE		3
-#define PNPIPE_ENABLE           4
-/* unused slot */
 
 #define PNADDR_ANY		0
 #define PNADDR_BROADCAST	0xFC
diff --git a/net/phonet/Kconfig b/net/phonet/Kconfig
index 0d9b8a2..6ec7d55 100644
--- a/net/phonet/Kconfig
+++ b/net/phonet/Kconfig
@@ -14,15 +14,3 @@ config PHONET
 
 	  To compile this driver as a module, choose M here: the module
 	  will be called phonet. If unsure, say N.
-
-config PHONET_PIPECTRLR
-	bool "Phonet Pipe Controller (EXPERIMENTAL)"
-	depends on PHONET && EXPERIMENTAL
-	default N
-	help
-	  The Pipe Controller implementation in Phonet stack to support Pipe
-	  data with Nokia Slim modems like WG2.5 used on ST-Ericsson U8500
-	  platform.
-
-	  This option is incompatible with older Nokia modems.
-	  Say N here unless you really know what you are doing.
diff --git a/net/phonet/pep.c b/net/phonet/pep.c
index 671effb..68e635f 100644
--- a/net/phonet/pep.c
+++ b/net/phonet/pep.c
@@ -167,15 +167,6 @@ static int pipe_handler_send_created_ind(struct sock *sk)
 				data, 4, GFP_ATOMIC);
 }
 
-#ifdef CONFIG_PHONET_PIPECTRLR
-static int pipe_handler_enable_pipe(struct sock *sk, int enable)
-{
-	u8 id = enable ? PNS_PEP_ENABLE_REQ : PNS_PEP_DISABLE_REQ;
-
-	return pipe_handler_request(sk, id, PAD, NULL, 0);
-}
-#endif
-
 static int pep_accept_conn(struct sock *sk, struct sk_buff *skb)
 {
 	static const u8 data[20] = {
@@ -968,16 +959,6 @@ static int pep_setsockopt(struct sock *sk, int level, int optname,
 		}
 		goto out_norel;
 
-#ifdef CONFIG_PHONET_PIPECTRLR
-	case PNPIPE_ENABLE:
-		if ((1 << sk->sk_state) & ~(TCPF_SYN_RECV|TCPF_ESTABLISHED)) {
-			err = -ENOTCONN;
-			break;
-		}
-		err = pipe_handler_enable_pipe(sk, val);
-		break;
-#endif
-
 	default:
 		err = -ENOPROTOOPT;
 	}
@@ -1013,12 +994,6 @@ static int pep_getsockopt(struct sock *sk, int level, int optname,
 			return -EINVAL;
 		break;
 
-#ifdef CONFIG_PHONET_PIPECTRLR
-	case PNPIPE_ENABLE:
-		val = sk->sk_state == TCP_ESTABLISHED;
-		break;
-#endif
-
 	default:
 		return -ENOPROTOOPT;
 	}
-- 
1.7.1


^ permalink raw reply related

* [PATCH 5/8] Phonet: allocate sock from accept syscall rather than soft IRQ
From: Rémi Denis-Courmont @ 2011-03-04 10:00 UTC (permalink / raw)
  To: netdev
In-Reply-To: <201103031322.37184.remi.denis-courmont@nokia.com>

This moves most of the accept logic to process context, and simplifies
the code a bit at the same time.

Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
 include/net/phonet/pep.h |    1 -
 net/phonet/pep.c         |  284 +++++++++++++++++++---------------------------
 net/phonet/socket.c      |   10 +-
 3 files changed, 121 insertions(+), 174 deletions(-)

diff --git a/include/net/phonet/pep.h b/include/net/phonet/pep.h
index 38eed1b..b669fe6 100644
--- a/include/net/phonet/pep.h
+++ b/include/net/phonet/pep.h
@@ -28,7 +28,6 @@ struct pep_sock {
 
 	/* XXX: union-ify listening vs connected stuff ? */
 	/* Listening socket stuff: */
-	struct hlist_head	ackq;
 	struct hlist_head	hlist;
 
 	/* Connected socket stuff: */
diff --git a/net/phonet/pep.c b/net/phonet/pep.c
index 610794a..c0fab4c 100644
--- a/net/phonet/pep.c
+++ b/net/phonet/pep.c
@@ -42,7 +42,7 @@
  * TCP_ESTABLISHED	connected pipe in enabled state
  *
  * pep_sock locking:
- *  - sk_state, ackq, hlist: sock lock needed
+ *  - sk_state, hlist: sock lock needed
  *  - listener: read only
  *  - pipe_handle: read only
  */
@@ -202,11 +202,12 @@ static int pep_accept_conn(struct sock *sk, struct sk_buff *skb)
 				GFP_KERNEL);
 }
 
-static int pep_reject_conn(struct sock *sk, struct sk_buff *skb, u8 code)
+static int pep_reject_conn(struct sock *sk, struct sk_buff *skb, u8 code,
+				gfp_t priority)
 {
 	static const u8 data[4] = { PAD, PAD, PAD, 0 /* sub-blocks */ };
 	WARN_ON(code == PN_PIPE_NO_ERROR);
-	return pep_reply(sk, skb, code, data, sizeof(data), GFP_ATOMIC);
+	return pep_reply(sk, skb, code, data, sizeof(data), priority);
 }
 
 /* Control requests are not sent by the pipe service and have a specific
@@ -365,7 +366,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
 
 	switch (hdr->message_id) {
 	case PNS_PEP_CONNECT_REQ:
-		pep_reject_conn(sk, skb, PN_PIPE_ERR_PEP_IN_USE);
+		pep_reject_conn(sk, skb, PN_PIPE_ERR_PEP_IN_USE, GFP_ATOMIC);
 		break;
 
 	case PNS_PEP_DISCONNECT_REQ:
@@ -574,7 +575,6 @@ static int pep_connresp_rcv(struct sock *sk, struct sk_buff *skb)
 
 	sk->sk_state = TCP_SYN_RECV;
 	sk->sk_backlog_rcv = pipe_do_rcv;
-	sk->sk_destruct = pipe_destruct;
 	pn->rx_credits = 0;
 	sk->sk_state_change(sk);
 
@@ -582,96 +582,6 @@ static int pep_connresp_rcv(struct sock *sk, struct sk_buff *skb)
 }
 #endif
 
-static int pep_connreq_rcv(struct sock *sk, struct sk_buff *skb)
-{
-	struct sock *newsk;
-	struct pep_sock *newpn, *pn = pep_sk(sk);
-	struct pnpipehdr *hdr;
-	struct sockaddr_pn dst, src;
-	u16 peer_type;
-	u8 pipe_handle, enabled, n_sb;
-	u8 aligned = 0;
-
-	if (!pskb_pull(skb, sizeof(*hdr) + 4))
-		return -EINVAL;
-
-	hdr = pnp_hdr(skb);
-	pipe_handle = hdr->pipe_handle;
-	switch (hdr->state_after_connect) {
-	case PN_PIPE_DISABLE:
-		enabled = 0;
-		break;
-	case PN_PIPE_ENABLE:
-		enabled = 1;
-		break;
-	default:
-		pep_reject_conn(sk, skb, PN_PIPE_ERR_INVALID_PARAM);
-		return -EINVAL;
-	}
-	peer_type = hdr->other_pep_type << 8;
-
-	/* Parse sub-blocks (options) */
-	n_sb = hdr->data[4];
-	while (n_sb > 0) {
-		u8 type, buf[1], len = sizeof(buf);
-		const u8 *data = pep_get_sb(skb, &type, &len, buf);
-
-		if (data == NULL)
-			return -EINVAL;
-		switch (type) {
-		case PN_PIPE_SB_CONNECT_REQ_PEP_SUB_TYPE:
-			if (len < 1)
-				return -EINVAL;
-			peer_type = (peer_type & 0xff00) | data[0];
-			break;
-		case PN_PIPE_SB_ALIGNED_DATA:
-			aligned = data[0] != 0;
-			break;
-		}
-		n_sb--;
-	}
-
-	skb = skb_clone(skb, GFP_ATOMIC);
-	if (!skb)
-		return -ENOMEM;
-
-	/* Create a new to-be-accepted sock */
-	newsk = sk_alloc(sock_net(sk), PF_PHONET, GFP_ATOMIC, sk->sk_prot);
-	if (!newsk) {
-		kfree_skb(skb);
-		return -ENOMEM;
-	}
-	sock_init_data(NULL, newsk);
-	newsk->sk_state = TCP_SYN_RECV;
-	newsk->sk_backlog_rcv = pipe_do_rcv;
-	newsk->sk_protocol = sk->sk_protocol;
-	newsk->sk_destruct = pipe_destruct;
-
-	newpn = pep_sk(newsk);
-	pn_skb_get_dst_sockaddr(skb, &dst);
-	pn_skb_get_src_sockaddr(skb, &src);
-	newpn->pn_sk.sobject = pn_sockaddr_get_object(&dst);
-	newpn->pn_sk.dobject = pn_sockaddr_get_object(&src);
-	newpn->pn_sk.resource = pn_sockaddr_get_resource(&dst);
-	skb_queue_head_init(&newpn->ctrlreq_queue);
-	newpn->pipe_handle = pipe_handle;
-	atomic_set(&newpn->tx_credits, 0);
-	newpn->peer_type = peer_type;
-	newpn->rx_credits = 0;
-	newpn->rx_fc = newpn->tx_fc = PN_LEGACY_FLOW_CONTROL;
-	newpn->init_enable = enabled;
-	newpn->aligned = aligned;
-
-	BUG_ON(!skb_queue_empty(&newsk->sk_receive_queue));
-	skb_queue_head(&newsk->sk_receive_queue, skb);
-	if (!sock_flag(sk, SOCK_DEAD))
-		sk->sk_data_ready(sk, 0);
-
-	sk_acceptq_added(sk);
-	sk_add_node(newsk, &pn->ackq);
-	return 0;
-}
-
 /* Listening sock must be locked */
 static struct sock *pep_find_pipe(const struct hlist_head *hlist,
 					const struct sockaddr_pn *dst,
@@ -726,22 +636,18 @@ static int pep_do_rcv(struct sock *sk, struct sk_buff *skb)
 	if (sknode)
 		return sk_receive_skb(sknode, skb, 1);
 
-	/* Look for a pipe handle pending accept */
-	sknode = pep_find_pipe(&pn->ackq, &dst, pipe_handle);
-	if (sknode) {
-		sock_put(sknode);
-		if (net_ratelimit())
-			printk(KERN_WARNING"Phonet unconnected PEP ignored");
-		goto drop;
-	}
-
 	switch (hdr->message_id) {
 	case PNS_PEP_CONNECT_REQ:
-		if (sk->sk_state == TCP_LISTEN && !sk_acceptq_is_full(sk))
-			pep_connreq_rcv(sk, skb);
-		else
-			pep_reject_conn(sk, skb, PN_PIPE_ERR_PEP_IN_USE);
-		break;
+		if (sk->sk_state != TCP_LISTEN || sk_acceptq_is_full(sk)) {
+			pep_reject_conn(sk, skb, PN_PIPE_ERR_PEP_IN_USE,
+					GFP_ATOMIC);
+			break;
+		}
+		skb_queue_head(&sk->sk_receive_queue, skb);
+		sk_acceptq_added(sk);
+		if (!sock_flag(sk, SOCK_DEAD))
+			sk->sk_data_ready(sk, 0);
+		return NET_RX_SUCCESS;
 
 #ifdef CONFIG_PHONET_PIPECTRLR
 	case PNS_PEP_CONNECT_RESP:
@@ -799,24 +705,16 @@ static void pep_sock_close(struct sock *sk, long timeout)
 	sk_common_release(sk);
 
 	lock_sock(sk);
-	if (sk->sk_state == TCP_LISTEN) {
-		/* Destroy the listen queue */
-		struct sock *sknode;
-		struct hlist_node *p, *n;
-
-		sk_for_each_safe(sknode, p, n, &pn->ackq)
-			sk_del_node_init(sknode);
-		sk->sk_state = TCP_CLOSE;
-	} else if ((1 << sk->sk_state) & (TCPF_SYN_RECV|TCPF_ESTABLISHED)) {
+	if ((1 << sk->sk_state) & (TCPF_SYN_RECV|TCPF_ESTABLISHED)) {
 #ifndef CONFIG_PHONET_PIPECTRLR
 		/* Forcefully remove dangling Phonet pipe */
 		pipe_do_remove(sk);
 #else
 		/* send pep disconnect request */
 		pipe_handler_request(sk, PNS_PEP_DISCONNECT_REQ, PAD, NULL, 0);
-		sk->sk_state = TCP_CLOSE;
 #endif
 	}
+	sk->sk_state = TCP_CLOSE;
 
 	ifindex = pn->ifindex;
 	pn->ifindex = 0;
@@ -827,69 +725,121 @@ static void pep_sock_close(struct sock *sk, long timeout)
 	sock_put(sk);
 }
 
-static int pep_wait_connreq(struct sock *sk, int noblock)
+static struct sock *pep_sock_accept(struct sock *sk, int flags, int *errp)
 {
-	struct task_struct *tsk = current;
-	struct pep_sock *pn = pep_sk(sk);
-	long timeo = sock_rcvtimeo(sk, noblock);
-
-	for (;;) {
-		DEFINE_WAIT(wait);
+	struct pep_sock *pn = pep_sk(sk), *newpn;
+	struct sock *newsk = NULL;
+	struct sk_buff *skb;
+	struct pnpipehdr *hdr;
+	struct sockaddr_pn dst, src;
+	int err;
+	u16 peer_type;
+	u8 pipe_handle, enabled, n_sb;
+	u8 aligned = 0;
 
-		if (sk->sk_state != TCP_LISTEN)
-			return -EINVAL;
-		if (!hlist_empty(&pn->ackq))
-			break;
-		if (!timeo)
-			return -EWOULDBLOCK;
-		if (signal_pending(tsk))
-			return sock_intr_errno(timeo);
+	skb = skb_recv_datagram(sk, 0, flags & O_NONBLOCK, errp);
+	if (!skb)
+		return NULL;
 
-		prepare_to_wait_exclusive(sk_sleep(sk), &wait,
-						TASK_INTERRUPTIBLE);
-		release_sock(sk);
-		timeo = schedule_timeout(timeo);
-		lock_sock(sk);
-		finish_wait(sk_sleep(sk), &wait);
+	lock_sock(sk);
+	if (sk->sk_state != TCP_LISTEN) {
+		err = -EINVAL;
+		goto drop;
 	}
+	sk_acceptq_removed(sk);
 
-	return 0;
-}
+	err = -EPROTO;
+	if (!pskb_may_pull(skb, sizeof(*hdr) + 4))
+		goto drop;
 
-static struct sock *pep_sock_accept(struct sock *sk, int flags, int *errp)
-{
-	struct pep_sock *pn = pep_sk(sk);
-	struct sock *newsk = NULL;
-	struct sk_buff *oskb;
-	int err;
+	hdr = pnp_hdr(skb);
+	pipe_handle = hdr->pipe_handle;
+	switch (hdr->state_after_connect) {
+	case PN_PIPE_DISABLE:
+		enabled = 0;
+		break;
+	case PN_PIPE_ENABLE:
+		enabled = 1;
+		break;
+	default:
+		pep_reject_conn(sk, skb, PN_PIPE_ERR_INVALID_PARAM,
+				GFP_KERNEL);
+		goto drop;
+	}
+	peer_type = hdr->other_pep_type << 8;
 
-	lock_sock(sk);
-	err = pep_wait_connreq(sk, flags & O_NONBLOCK);
-	if (err)
-		goto out;
+	/* Parse sub-blocks (options) */
+	n_sb = hdr->data[4];
+	while (n_sb > 0) {
+		u8 type, buf[1], len = sizeof(buf);
+		const u8 *data = pep_get_sb(skb, &type, &len, buf);
 
-	newsk = __sk_head(&pn->ackq);
+		if (data == NULL)
+			goto drop;
+		switch (type) {
+		case PN_PIPE_SB_CONNECT_REQ_PEP_SUB_TYPE:
+			if (len < 1)
+				goto drop;
+			peer_type = (peer_type & 0xff00) | data[0];
+			break;
+		case PN_PIPE_SB_ALIGNED_DATA:
+			aligned = data[0] != 0;
+			break;
+		}
+		n_sb--;
+	}
 
-	oskb = skb_dequeue(&newsk->sk_receive_queue);
-	err = pep_accept_conn(newsk, oskb);
-	if (err) {
-		skb_queue_head(&newsk->sk_receive_queue, oskb);
+	/* Check for duplicate pipe handle */
+	newsk = pep_find_pipe(&pn->hlist, &dst, pipe_handle);
+	if (unlikely(newsk)) {
+		__sock_put(newsk);
 		newsk = NULL;
-		goto out;
+		pep_reject_conn(sk, skb, PN_PIPE_ERR_PEP_IN_USE, GFP_KERNEL);
+		goto drop;
+	}
+
+	/* Create a new to-be-accepted sock */
+	newsk = sk_alloc(sock_net(sk), PF_PHONET, GFP_KERNEL, sk->sk_prot);
+	if (!newsk) {
+		pep_reject_conn(sk, skb, PN_PIPE_ERR_OVERLOAD, GFP_KERNEL);
+		err = -ENOBUFS;
+		goto drop;
 	}
-	kfree_skb(oskb);
 
+	sock_init_data(NULL, newsk);
+	newsk->sk_state = TCP_SYN_RECV;
+	newsk->sk_backlog_rcv = pipe_do_rcv;
+	newsk->sk_protocol = sk->sk_protocol;
+	newsk->sk_destruct = pipe_destruct;
+
+	newpn = pep_sk(newsk);
+	pn_skb_get_dst_sockaddr(skb, &dst);
+	pn_skb_get_src_sockaddr(skb, &src);
+	newpn->pn_sk.sobject = pn_sockaddr_get_object(&dst);
+	newpn->pn_sk.dobject = pn_sockaddr_get_object(&src);
+	newpn->pn_sk.resource = pn_sockaddr_get_resource(&dst);
 	sock_hold(sk);
-	pep_sk(newsk)->listener = sk;
+	newpn->listener = sk;
+	skb_queue_head_init(&newpn->ctrlreq_queue);
+	newpn->pipe_handle = pipe_handle;
+	atomic_set(&newpn->tx_credits, 0);
+	newpn->ifindex = 0;
+	newpn->peer_type = peer_type;
+	newpn->rx_credits = 0;
+	newpn->rx_fc = newpn->tx_fc = PN_LEGACY_FLOW_CONTROL;
+	newpn->init_enable = enabled;
+	newpn->aligned = aligned;
 
-	sock_hold(newsk);
-	sk_del_node_init(newsk);
-	sk_acceptq_removed(sk);
+	err = pep_accept_conn(newsk, skb);
+	if (err) {
+		sock_put(newsk);
+		newsk = NULL;
+		goto drop;
+	}
 	sk_add_node(newsk, &pn->hlist);
-	__sock_put(newsk);
-
-out:
+drop:
 	release_sock(sk);
+	kfree_skb(skb);
 	*errp = err;
 	return newsk;
 }
@@ -937,7 +887,7 @@ static int pep_init(struct sock *sk)
 {
 	struct pep_sock *pn = pep_sk(sk);
 
-	INIT_HLIST_HEAD(&pn->ackq);
+	sk->sk_destruct = pipe_destruct;
 	INIT_HLIST_HEAD(&pn->hlist);
 	skb_queue_head_init(&pn->ctrlreq_queue);
 	pn->pipe_handle = PN_PIPE_INVALID_HANDLE;
diff --git a/net/phonet/socket.c b/net/phonet/socket.c
index 65a0333..1eccfc3 100644
--- a/net/phonet/socket.c
+++ b/net/phonet/socket.c
@@ -327,6 +327,9 @@ static int pn_socket_accept(struct socket *sock, struct socket *newsock,
 	struct sock *newsk;
 	int err;
 
+	if (unlikely(sk->sk_state != TCP_LISTEN))
+		return -EINVAL;
+
 	newsk = sk->sk_prot->accept(sk, flags, &err);
 	if (!newsk)
 		return err;
@@ -363,13 +366,8 @@ static unsigned int pn_socket_poll(struct file *file, struct socket *sock,
 
 	poll_wait(file, sk_sleep(sk), wait);
 
-	switch (sk->sk_state) {
-	case TCP_LISTEN:
-		return hlist_empty(&pn->ackq) ? 0 : POLLIN;
-	case TCP_CLOSE:
+	if (sk->sk_state == TCP_CLOSE)
 		return POLLERR;
-	}
-
 	if (!skb_queue_empty(&sk->sk_receive_queue))
 		mask |= POLLIN | POLLRDNORM;
 	if (!skb_queue_empty(&pn->ctrlreq_queue))
-- 
1.7.1


^ permalink raw reply related

* [PATCH 4/8] Phonet: factor common code to send control messages
From: Rémi Denis-Courmont @ 2011-03-04 10:00 UTC (permalink / raw)
  To: netdev
In-Reply-To: <201103031322.37184.remi.denis-courmont@nokia.com>

Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
 net/phonet/pep.c |  225 ++++++++++++++++++------------------------------------
 1 files changed, 73 insertions(+), 152 deletions(-)

diff --git a/net/phonet/pep.c b/net/phonet/pep.c
index 40952c7..610794a 100644
--- a/net/phonet/pep.c
+++ b/net/phonet/pep.c
@@ -77,24 +77,34 @@ static unsigned char *pep_get_sb(struct sk_buff *skb, u8 *ptype, u8 *plen,
 	return data;
 }
 
-static int pep_reply(struct sock *sk, struct sk_buff *oskb,
-			u8 code, const void *data, int len, gfp_t priority)
+static struct sk_buff *pep_alloc_skb(struct sock *sk, const void *payload,
+					int len, gfp_t priority)
+{
+	struct sk_buff *skb = alloc_skb(MAX_PNPIPE_HEADER + len, priority);
+	if (!skb)
+		return NULL;
+	skb_set_owner_w(skb, sk);
+
+	skb_reserve(skb, MAX_PNPIPE_HEADER);
+	__skb_put(skb, len);
+	skb_copy_to_linear_data(skb, payload, len);
+	__skb_push(skb, sizeof(struct pnpipehdr));
+	skb_reset_transport_header(skb);
+	return skb;
+}
+
+static int pep_reply(struct sock *sk, struct sk_buff *oskb, u8 code,
+			const void *data, int len, gfp_t priority)
 {
 	const struct pnpipehdr *oph = pnp_hdr(oskb);
 	struct pnpipehdr *ph;
 	struct sk_buff *skb;
 	struct sockaddr_pn peer;
 
-	skb = alloc_skb(MAX_PNPIPE_HEADER + len, priority);
+	skb = pep_alloc_skb(sk, data, len, priority);
 	if (!skb)
 		return -ENOMEM;
-	skb_set_owner_w(skb, sk);
 
-	skb_reserve(skb, MAX_PNPIPE_HEADER);
-	__skb_put(skb, len);
-	skb_copy_to_linear_data(skb, data, len);
-	__skb_push(skb, sizeof(*ph));
-	skb_reset_transport_header(skb);
 	ph = pnp_hdr(skb);
 	ph->utid = oph->utid;
 	ph->message_id = oph->message_id + 1; /* REQ -> RESP */
@@ -105,135 +115,69 @@ static int pep_reply(struct sock *sk, struct sk_buff *oskb,
 	return pn_skb_send(sk, skb, &peer);
 }
 
-#define PAD 0x00
-
-#ifdef CONFIG_PHONET_PIPECTRLR
-static int pipe_handler_send_req(struct sock *sk, u8 msg_id, gfp_t priority)
+static int pep_indicate(struct sock *sk, u8 id, u8 code,
+			const void *data, int len, gfp_t priority)
 {
-	int len;
+	struct pep_sock *pn = pep_sk(sk);
 	struct pnpipehdr *ph;
 	struct sk_buff *skb;
-	struct pep_sock *pn = pep_sk(sk);
-
-	static const u8 data[4] = {
-		PAD, PAD, PAD, PAD,
-	};
 
-	switch (msg_id) {
-	case PNS_PEP_CONNECT_REQ:
-		len = sizeof(data);
-		break;
-
-	case PNS_PEP_DISCONNECT_REQ:
-	case PNS_PEP_ENABLE_REQ:
-	case PNS_PEP_DISABLE_REQ:
-		len = 0;
-		break;
-
-	default:
-		return -EINVAL;
-	}
-
-	skb = alloc_skb(MAX_PNPIPE_HEADER + len, priority);
+	skb = pep_alloc_skb(sk, data, len, priority);
 	if (!skb)
 		return -ENOMEM;
-	skb_set_owner_w(skb, sk);
 
-	skb_reserve(skb, MAX_PNPIPE_HEADER);
-	if (len) {
-		__skb_put(skb, len);
-		skb_copy_to_linear_data(skb, data, len);
-	}
-	__skb_push(skb, sizeof(*ph));
-	skb_reset_transport_header(skb);
 	ph = pnp_hdr(skb);
-	ph->utid = msg_id; /* whatever */
-	ph->message_id = msg_id;
+	ph->utid = 0;
+	ph->message_id = id;
 	ph->pipe_handle = pn->pipe_handle;
-	ph->error_code = PN_PIPE_NO_ERROR;
-
+	ph->data[0] = code;
 	return pn_skb_send(sk, skb, NULL);
 }
 
-static int pipe_handler_send_created_ind(struct sock *sk, u8 msg_id)
+#define PAD 0x00
+
+#ifdef CONFIG_PHONET_PIPECTRLR
+static int pipe_handler_request(struct sock *sk, u8 id, u8 code,
+				const void *data, int len)
 {
-	int err_code;
+	struct pep_sock *pn = pep_sk(sk);
 	struct pnpipehdr *ph;
 	struct sk_buff *skb;
 
-	struct pep_sock *pn = pep_sk(sk);
-	static u8 data[4] = {
-		0x03, 0x04,
-	};
-	data[2] = pn->tx_fc;
-	data[3] = pn->rx_fc;
-
-	/*
-	 * actually, below is number of sub-blocks and not error code.
-	 * Pipe_created_ind message format does not have any
-	 * error code field. However, the Phonet stack will always send
-	 * an error code as part of pnpipehdr. So, use that err_code to
-	 * specify the number of sub-blocks.
-	 */
-	err_code = 0x01;
-
-	skb = alloc_skb(MAX_PNPIPE_HEADER + sizeof(data), GFP_ATOMIC);
+	skb = pep_alloc_skb(sk, data, len, GFP_KERNEL);
 	if (!skb)
 		return -ENOMEM;
-	skb_set_owner_w(skb, sk);
 
-	skb_reserve(skb, MAX_PNPIPE_HEADER);
-	__skb_put(skb, sizeof(data));
-	skb_copy_to_linear_data(skb, data, sizeof(data));
-	__skb_push(skb, sizeof(*ph));
-	skb_reset_transport_header(skb);
 	ph = pnp_hdr(skb);
-	ph->utid = 0;
-	ph->message_id = msg_id;
+	ph->utid = id; /* whatever */
+	ph->message_id = id;
 	ph->pipe_handle = pn->pipe_handle;
-	ph->error_code = err_code;
-
+	ph->data[0] = code;
 	return pn_skb_send(sk, skb, NULL);
 }
 
-static int pipe_handler_send_ind(struct sock *sk, u8 msg_id)
+static int pipe_handler_send_created_ind(struct sock *sk)
 {
-	int err_code;
-	struct pnpipehdr *ph;
-	struct sk_buff *skb;
 	struct pep_sock *pn = pep_sk(sk);
+	u8 data[4] = {
+		PN_PIPE_SB_NEGOTIATED_FC, pep_sb_size(2),
+		pn->tx_fc, pn->rx_fc,
+	};
 
-	/*
-	 * actually, below is a filler.
-	 * Pipe_enabled/disabled_ind message format does not have any
-	 * error code field. However, the Phonet stack will always send
-	 * an error code as part of pnpipehdr. So, use that err_code to
-	 * specify the filler value.
-	 */
-	err_code = 0x0;
-
-	skb = alloc_skb(MAX_PNPIPE_HEADER, GFP_ATOMIC);
-	if (!skb)
-		return -ENOMEM;
-	skb_set_owner_w(skb, sk);
-
-	skb_reserve(skb, MAX_PNPIPE_HEADER);
-	__skb_push(skb, sizeof(*ph));
-	skb_reset_transport_header(skb);
-	ph = pnp_hdr(skb);
-	ph->utid = 0;
-	ph->message_id = msg_id;
-	ph->pipe_handle = pn->pipe_handle;
-	ph->error_code = err_code;
+	return pep_indicate(sk, PNS_PIPE_CREATED_IND, 1 /* sub-blocks */,
+				data, 4, GFP_ATOMIC);
+}
 
-	return pn_skb_send(sk, skb, NULL);
+static int pipe_handler_send_ind(struct sock *sk, u8 id)
+{
+	return pep_indicate(sk, id, PAD, NULL, 0, GFP_ATOMIC);
 }
 
 static int pipe_handler_enable_pipe(struct sock *sk, int enable)
 {
 	u8 id = enable ? PNS_PEP_ENABLE_REQ : PNS_PEP_DISABLE_REQ;
 
-	return pipe_handler_send_req(sk, id, GFP_KERNEL);
+	return pipe_handler_request(sk, id, PAD, NULL, 0);
 }
 #endif
 
@@ -274,23 +218,21 @@ static int pep_ctrlreq_error(struct sock *sk, struct sk_buff *oskb, u8 code,
 	struct sk_buff *skb;
 	struct pnpipehdr *ph;
 	struct sockaddr_pn dst;
+	u8 data[4] = {
+		oph->data[0], /* PEP type */
+		code, /* error code, at an unusual offset */
+		PAD, PAD,
+	};
 
-	skb = alloc_skb(MAX_PNPIPE_HEADER + 4, priority);
+	skb = pep_alloc_skb(sk, data, 4, priority);
 	if (!skb)
 		return -ENOMEM;
-	skb_set_owner_w(skb, sk);
-
-	skb_reserve(skb, MAX_PHONET_HEADER);
-	ph = (struct pnpipehdr *)skb_put(skb, sizeof(*ph) + 4);
 
+	ph = pnp_hdr(skb);
 	ph->utid = oph->utid;
 	ph->message_id = PNS_PEP_CTRL_RESP;
 	ph->pipe_handle = oph->pipe_handle;
 	ph->data[0] = oph->data[1]; /* CTRL id */
-	ph->data[1] = oph->data[0]; /* PEP type */
-	ph->data[2] = code; /* error code, at an usual offset */
-	ph->data[3] = PAD;
-	ph->data[4] = PAD;
 
 	pn_skb_get_src_sockaddr(oskb, &dst);
 	return pn_skb_send(sk, skb, &dst);
@@ -298,34 +240,15 @@ static int pep_ctrlreq_error(struct sock *sk, struct sk_buff *oskb, u8 code,
 
 static int pipe_snd_status(struct sock *sk, u8 type, u8 status, gfp_t priority)
 {
-	struct pep_sock *pn = pep_sk(sk);
-	struct pnpipehdr *ph;
-	struct sk_buff *skb;
+	u8 data[4] = { type, PAD, PAD, status };
 
-	skb = alloc_skb(MAX_PNPIPE_HEADER + 4, priority);
-	if (!skb)
-		return -ENOMEM;
-	skb_set_owner_w(skb, sk);
-
-	skb_reserve(skb, MAX_PNPIPE_HEADER + 4);
-	__skb_push(skb, sizeof(*ph) + 4);
-	skb_reset_transport_header(skb);
-	ph = pnp_hdr(skb);
-	ph->utid = 0;
-	ph->message_id = PNS_PEP_STATUS_IND;
-	ph->pipe_handle = pn->pipe_handle;
-	ph->pep_type = PN_PEP_TYPE_COMMON;
-	ph->data[1] = type;
-	ph->data[2] = PAD;
-	ph->data[3] = PAD;
-	ph->data[4] = status;
-
-	return pn_skb_send(sk, skb, NULL);
+	return pep_indicate(sk, PNS_PEP_STATUS_IND, PN_PEP_TYPE_COMMON,
+				data, 4, priority);
 }
 
 /* Send our RX flow control information to the sender.
  * Socket must be locked. */
-static void pipe_grant_credits(struct sock *sk)
+static void pipe_grant_credits(struct sock *sk, gfp_t priority)
 {
 	struct pep_sock *pn = pep_sk(sk);
 
@@ -335,16 +258,16 @@ static void pipe_grant_credits(struct sock *sk)
 	case PN_LEGACY_FLOW_CONTROL: /* TODO */
 		break;
 	case PN_ONE_CREDIT_FLOW_CONTROL:
-		pipe_snd_status(sk, PN_PEP_IND_FLOW_CONTROL,
-				PEP_IND_READY, GFP_ATOMIC);
-		pn->rx_credits = 1;
+		if (pipe_snd_status(sk, PN_PEP_IND_FLOW_CONTROL,
+					PEP_IND_READY, priority) == 0)
+			pn->rx_credits = 1;
 		break;
 	case PN_MULTI_CREDIT_FLOW_CONTROL:
 		if ((pn->rx_credits + CREDITS_THR) > CREDITS_MAX)
 			break;
 		if (pipe_snd_status(sk, PN_PEP_IND_ID_MCFC_GRANT_CREDITS,
 					CREDITS_MAX - pn->rx_credits,
-					GFP_ATOMIC) == 0)
+					priority) == 0)
 			pn->rx_credits = CREDITS_MAX;
 		break;
 	}
@@ -474,7 +397,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
 		if (sk->sk_state == TCP_ESTABLISHED)
 			break; /* Nothing to do */
 		sk->sk_state = TCP_ESTABLISHED;
-		pipe_grant_credits(sk);
+		pipe_grant_credits(sk, GFP_ATOMIC);
 		break;
 #endif
 
@@ -561,7 +484,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
 		if (sk->sk_state == TCP_ESTABLISHED)
 			break; /* Nothing to do */
 		sk->sk_state = TCP_ESTABLISHED;
-		pipe_grant_credits(sk);
+		pipe_grant_credits(sk, GFP_ATOMIC);
 		break;
 
 	case PNS_PIPE_DISABLED_IND:
@@ -655,7 +578,7 @@ static int pep_connresp_rcv(struct sock *sk, struct sk_buff *skb)
 	pn->rx_credits = 0;
 	sk->sk_state_change(sk);
 
-	return pipe_handler_send_created_ind(sk, PNS_PIPE_CREATED_IND);
+	return pipe_handler_send_created_ind(sk);
 }
 #endif
 
@@ -853,19 +776,15 @@ static int pipe_do_remove(struct sock *sk)
 	struct pnpipehdr *ph;
 	struct sk_buff *skb;
 
-	skb = alloc_skb(MAX_PNPIPE_HEADER, GFP_KERNEL);
+	skb = pep_alloc_skb(sk, NULL, 0, GFP_KERNEL);
 	if (!skb)
 		return -ENOMEM;
 
-	skb_reserve(skb, MAX_PNPIPE_HEADER);
-	__skb_push(skb, sizeof(*ph));
-	skb_reset_transport_header(skb);
 	ph = pnp_hdr(skb);
 	ph->utid = 0;
 	ph->message_id = PNS_PIPE_REMOVE_REQ;
 	ph->pipe_handle = pn->pipe_handle;
 	ph->data[0] = PAD;
-
 	return pn_skb_send(sk, skb, NULL);
 }
 #endif
@@ -894,7 +813,7 @@ static void pep_sock_close(struct sock *sk, long timeout)
 		pipe_do_remove(sk);
 #else
 		/* send pep disconnect request */
-		pipe_handler_send_req(sk, PNS_PEP_DISCONNECT_REQ, GFP_KERNEL);
+		pipe_handler_request(sk, PNS_PEP_DISCONNECT_REQ, PAD, NULL, 0);
 		sk->sk_state = TCP_CLOSE;
 #endif
 	}
@@ -980,10 +899,12 @@ static int pep_sock_connect(struct sock *sk, struct sockaddr *addr, int len)
 {
 	struct pep_sock *pn = pep_sk(sk);
 	const struct sockaddr_pn *spn = (struct sockaddr_pn *)addr;
+	u8 data[4] = { 0 /* sub-blocks */, PAD, PAD, PAD };
 
 	pn->pn_sk.dobject = pn_sockaddr_get_object(spn);
 	pn->pn_sk.resource = pn_sockaddr_get_resource(spn);
-	return pipe_handler_send_req(sk, PNS_PEP_CONNECT_REQ, GFP_KERNEL);
+	return pipe_handler_request(sk, PNS_PEP_CONNECT_REQ,
+					PN_PIPE_DISABLE, data, 4);
 }
 #endif
 
@@ -1280,7 +1201,7 @@ struct sk_buff *pep_read(struct sock *sk)
 	struct sk_buff *skb = skb_dequeue(&sk->sk_receive_queue);
 
 	if (sk->sk_state == TCP_ESTABLISHED)
-		pipe_grant_credits(sk);
+		pipe_grant_credits(sk, GFP_ATOMIC);
 	return skb;
 }
 
@@ -1325,7 +1246,7 @@ static int pep_recvmsg(struct kiocb *iocb, struct sock *sk,
 	}
 
 	if (sk->sk_state == TCP_ESTABLISHED)
-		pipe_grant_credits(sk);
+		pipe_grant_credits(sk, GFP_KERNEL);
 	release_sock(sk);
 copy:
 	msg->msg_flags |= MSG_EOR;
-- 
1.7.1


^ permalink raw reply related

* [PATCH 3/8] Phonet: fix backlog callback return value
From: Rémi Denis-Courmont @ 2011-03-04 10:00 UTC (permalink / raw)
  To: netdev
In-Reply-To: <201103031322.37184.remi.denis-courmont@nokia.com>

Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
 net/phonet/pep.c |   25 +++++++++++--------------
 1 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/net/phonet/pep.c b/net/phonet/pep.c
index 875e86c..40952c7 100644
--- a/net/phonet/pep.c
+++ b/net/phonet/pep.c
@@ -522,7 +522,8 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
 		if (!pn_flow_safe(pn->rx_fc)) {
 			err = sock_queue_rcv_skb(sk, skb);
 			if (!err)
-				return 0;
+				return NET_RX_SUCCESS;
+			err = -ENOBUFS;
 			break;
 		}
 
@@ -575,7 +576,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
 	}
 out:
 	kfree_skb(skb);
-	return err;
+	return (err == -ENOBUFS) ? NET_RX_DROP : NET_RX_SUCCESS;
 
 queue:
 	skb->dev = NULL;
@@ -584,7 +585,7 @@ queue:
 	skb_queue_tail(queue, skb);
 	if (!sock_flag(sk, SOCK_DEAD))
 		sk->sk_data_ready(sk, err);
-	return 0;
+	return NET_RX_SUCCESS;
 }
 
 /* Destroy connected sock. */
@@ -686,11 +687,6 @@ static int pep_connreq_rcv(struct sock *sk, struct sk_buff *skb)
 	}
 	peer_type = hdr->other_pep_type << 8;
 
-	if (unlikely(sk->sk_state != TCP_LISTEN) || sk_acceptq_is_full(sk)) {
-		pep_reject_conn(sk, skb, PN_PIPE_ERR_PEP_IN_USE);
-		return -ENOBUFS;
-	}
-
 	/* Parse sub-blocks (options) */
 	n_sb = hdr->data[4];
 	while (n_sb > 0) {
@@ -790,7 +786,6 @@ static int pep_do_rcv(struct sock *sk, struct sk_buff *skb)
 	struct sock *sknode;
 	struct pnpipehdr *hdr;
 	struct sockaddr_pn dst;
-	int err = NET_RX_SUCCESS;
 	u8 pipe_handle;
 
 	if (!pskb_may_pull(skb, sizeof(*hdr)))
@@ -814,18 +809,20 @@ static int pep_do_rcv(struct sock *sk, struct sk_buff *skb)
 		sock_put(sknode);
 		if (net_ratelimit())
 			printk(KERN_WARNING"Phonet unconnected PEP ignored");
-		err = NET_RX_DROP;
 		goto drop;
 	}
 
 	switch (hdr->message_id) {
 	case PNS_PEP_CONNECT_REQ:
-		err = pep_connreq_rcv(sk, skb);
+		if (sk->sk_state == TCP_LISTEN && !sk_acceptq_is_full(sk))
+			pep_connreq_rcv(sk, skb);
+		else
+			pep_reject_conn(sk, skb, PN_PIPE_ERR_PEP_IN_USE);
 		break;
 
 #ifdef CONFIG_PHONET_PIPECTRLR
 	case PNS_PEP_CONNECT_RESP:
-		err = pep_connresp_rcv(sk, skb);
+		pep_connresp_rcv(sk, skb);
 		break;
 #endif
 
@@ -842,11 +839,11 @@ static int pep_do_rcv(struct sock *sk, struct sk_buff *skb)
 	case PNS_PEP_DISABLE_REQ:
 		/* invalid handle is not even allowed here! */
 	default:
-		err = NET_RX_DROP;
+		break;
 	}
 drop:
 	kfree_skb(skb);
-	return err;
+	return NET_RX_SUCCESS;
 }
 
 #ifndef CONFIG_PHONET_PIPECTRLR
-- 
1.7.1


^ permalink raw reply related

* [PATCH 2/8] Phonet: return an error when TX fails
From: Rémi Denis-Courmont @ 2011-03-04 10:00 UTC (permalink / raw)
  To: netdev
In-Reply-To: <201103031322.37184.remi.denis-courmont@nokia.com>

Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
 net/phonet/af_phonet.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
index 4706b77..c6fffd9 100644
--- a/net/phonet/af_phonet.c
+++ b/net/phonet/af_phonet.c
@@ -195,11 +195,7 @@ static int pn_send(struct sk_buff *skb, struct net_device *dev,
 	if (skb->pkt_type == PACKET_LOOPBACK) {
 		skb_reset_mac_header(skb);
 		skb_orphan(skb);
-		if (irq)
-			netif_rx(skb);
-		else
-			netif_rx_ni(skb);
-		err = 0;
+		err = (irq ? netif_rx(skb) : netif_rx_ni(skb)) ? -ENOBUFS : 0;
 	} else {
 		err = dev_hard_header(skb, dev, ntohs(skb->protocol),
 					NULL, NULL, skb->len);
@@ -208,6 +204,8 @@ static int pn_send(struct sk_buff *skb, struct net_device *dev,
 			goto drop;
 		}
 		err = dev_queue_xmit(skb);
+		if (unlikely(err > 0))
+			err = net_xmit_errno(err);
 	}
 
 	return err;
-- 
1.7.1


^ permalink raw reply related

* [PATCH 1/8] Phonet: fix NULL-deref in previous patch series
From: Rémi Denis-Courmont @ 2011-03-04 10:00 UTC (permalink / raw)
  To: netdev
In-Reply-To: <201103031322.37184.remi.denis-courmont@nokia.com>

Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
 net/phonet/af_phonet.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
index 30cc676..4706b77 100644
--- a/net/phonet/af_phonet.c
+++ b/net/phonet/af_phonet.c
@@ -262,10 +262,9 @@ int pn_skb_send(struct sock *sk, struct sk_buff *skb,
 	else if (phonet_address_lookup(net, daddr) == 0) {
 		dev = phonet_device_get(net);
 		skb->pkt_type = PACKET_LOOPBACK;
-	} else if (pn_sockaddr_get_object(target) == 0) {
+	} else if (dst == 0) {
 		/* Resource routing (small race until phonet_rcv()) */
-		struct sock *sk = pn_find_sock_by_res(net,
-							target->spn_resource);
+		struct sock *sk = pn_find_sock_by_res(net, res);
 		if (sk)	{
 			sock_put(sk);
 			dev = phonet_device_get(net);
-- 
1.7.1


^ permalink raw reply related

* Re: [PATCH resent] tcp: ioctl type SIOCOUTQNSD returns amount of data not sent
From: Arnd Bergmann @ 2011-03-04  9:57 UTC (permalink / raw)
  To: Steffen Sledz
  Cc: David Miller, netdev, linux-kernel, kuznet, pekkas, jmorris,
	yoshfuji, kaber, m.schuknecht
In-Reply-To: <4D70B621.7020307@dresearch.de>

On Friday 04 March 2011 10:51:29 Steffen Sledz wrote:
> Am 04.03.2011 10:04, schrieb David Miller:

> > Hitting only asm-generic/ioctls.h is insufficient, many architectures do
> > not make use of this file and the build will fail for them with your patch
> > applied.
> 
> That's not fully clear to me.
> 
> We made the define similar to the existing TIOCOUTQ. What other files should be hit?
> 

These ones:

$ git grep TIOCOUTQ arch/*/include/
arch/alpha/include/asm/ioctls.h:#define TIOCOUTQ        _IOR('t', 115, int)     /* output queue size */
arch/mips/include/asm/ioctls.h:#define TIOCOUTQ 0x7472          /* output queue size */
arch/parisc/include/asm/ioctls.h:#define TIOCOUTQ       0x5411
arch/powerpc/include/asm/ioctls.h:#define TIOCOUTQ        _IOR('t', 115, int)     /* output queue size */
arch/sh/include/asm/ioctls.h:#define TIOCOUTQ        _IOR('t', 115, int)     /* output queue size */
arch/sparc/include/asm/ioctls.h:#define TIOCOUTQ        _IOR('t', 115, int)
arch/xtensa/include/asm/ioctls.h:#define TIOCOUTQ        _IOR('t', 115, int)     /* output queue size */

	Arnd

^ permalink raw reply

* Re: [PATCH resent] tcp: ioctl type SIOCOUTQNSD returns amount of data not sent
From: Steffen Sledz @ 2011-03-04  9:51 UTC (permalink / raw)
  To: David Miller
  Cc: netdev, linux-kernel, kuznet, pekkas, jmorris, yoshfuji, kaber,
	m.schuknecht
In-Reply-To: <20110304.010428.71127798.davem@davemloft.net>

Am 04.03.2011 10:04, schrieb David Miller:
> From: Steffen Sledz <sledz@dresearch.de>
> Date: Fri,  4 Mar 2011 09:48:17 +0100
> 
>> diff --git a/include/asm-generic/ioctls.h b/include/asm-generic/ioctls.h
>> index 199975f..ef2be0b 100644
>> --- a/include/asm-generic/ioctls.h
>> +++ b/include/asm-generic/ioctls.h
>> @@ -74,6 +74,7 @@
>>  #define TCSETXW		0x5435
>>  #define TIOCSIG		_IOW('T', 0x36, int)  /* pty: generate signal */
>>  #define TIOCVHANGUP	0x5437
>> +#define TIOCOUTQNSD	0x5438
>>  
>>  #define FIONCLEX	0x5450
>>  #define FIOCLEX		0x5451
> 
> Hitting only asm-generic/ioctls.h is insufficient, many architectures do
> not make use of this file and the build will fail for them with your patch
> applied.

That's not fully clear to me.

We made the define similar to the existing TIOCOUTQ. What other files should be hit?

Steffen Sledz

-- 
DResearch Fahrzeugelektronik GmbH
Otto-Schmirgal-Str. 3, 10319 Berlin, Germany
Tel: +49 30 515932-237 mailto:sledz@DResearch.de
Fax: +49 30 515932-299
Geschäftsführer: Dr. Michael Weber, Werner Mögle;
Amtsgericht Berlin Charlottenburg; HRB 130120 B;
Ust.-IDNr. DE273952058

^ permalink raw reply

* Re: Bug inkvm_set_irq
From: Jean-Philippe Menil @ 2011-03-04  9:39 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: netdev, kvm, virtualization
In-Reply-To: <20110304093500.GA31844@redhat.com>

Le 04/03/2011 10:35, Michael S. Tsirkin a écrit :
> On Fri, Mar 04, 2011 at 10:22:03AM +0100, Jean-Philippe Menil wrote:
>> Le 03/03/2011 16:55, Michael S. Tsirkin a écrit :
>>> On Thu, Mar 03, 2011 at 04:26:11PM +0100, Jean-Philippe Menil wrote:
>>>> Le 03/03/2011 15:47, Michael S. Tsirkin a écrit :
>>>>> On Tue, Mar 01, 2011 at 03:39:12PM +0100, Jean-Philippe Menil wrote:
>>>>>> so this time the bug is:
>>>>>>
>>>>>> [17882.612303] BUG: unable to handle kernel paging request at
>>>>>> 0000000000002458
>>>>>> [17882.612342] IP: [<ffffffffa03898a0>] kvm_set_irq+0x30/0x140 [kvm]
>>>>>>
>>>>>> markup_oops give me this:
>>>>>>
>>>>>> root@ayrshire:~# cat bug-0103.txt | perl markup_oops.pl -m
>>>>>> /lib/modules/2.6.37.2-dsiun-110105+/kernel/arch/x86/kvm/kvm.ko
>>>>>> /boot/vmlinuz-2.6.37.2-dsiun-110105+
>>>>>> vmaoffset = 18446744072102621184 ffffffffa0389871:	48 89 e5   	mov
>>>>>> %rsp,%rbp
>>>>>>   ffffffffa0389874:	41 57                	push   %r15
>>>>>>   ffffffffa0389876:	41 89 cf             	mov    %ecx,%r15d  |  %r15
>>>>>> =>    1  %ecx = 1
>>>>>>   ffffffffa0389879:	41 56                	push   %r14        |  %r14
>>>>>> =>    ffffffffa038aad0
>>>>>>   ffffffffa038987b:	41 55                	push   %r13
>>>>>>   ffffffffa038987d:	49 89 fd             	mov    %rdi,%r13   |  %edi
>>>>>> = 0  %r13 =>    0
>>>>>>   ffffffffa0389880:	41 54                	push   %r12        |  %r12 =>    0
>>>>>>   ffffffffa0389882:	53                   	push   %rbx
>>>>>>   ffffffffa0389883:	89 d3                	mov    %edx,%ebx   |  %ebx =>    1a
>>>>>>   ffffffffa0389885:	48 81 ec a8 00 00 00 	sub    $0xa8,%rsp
>>>>>>   ffffffffa038988c:	8b 15 00 00 00 00    	mov    0x0(%rip),%edx
>>>>>> # ffffffffa0389892<kvm_set_irq+0x22>
>>>>>>   ffffffffa0389892:	89 b5 3c ff ff ff    	mov    %esi,-0xc4(%rbp) |
>>>>>> %esi = 0
>>>>>>   ffffffffa0389898:	85 d2                	test   %edx,%edx   |  %edx =>    0
>>>>>>   ffffffffa038989a:	0f 85 d5 00 00 00    	jne    ffffffffa0389975
>>>>>> <kvm_set_irq+0x105>
>>>>>> *ffffffffa03898a0:	49 8b 85 58 24 00 00 	mov    0x2458(%r13),%rax |
>>>>>> %eax = 0  %r13 = 0<--- faulting instruction
>>>>>>   ffffffffa03898a7:	3b 98 28 01 00 00    	cmp    0x128(%rax),%ebx
>>>>>>   ffffffffa03898ad:	73 61                	jae    ffffffffa0389910
>>>>>> <kvm_set_irq+0xa0>
>>>>>>   ffffffffa03898af:	89 db                	mov    %ebx,%ebx
>>>>>>   ffffffffa03898b1:	48 8b 84 d8 30 01 00 	mov    0x130(%rax,%rbx,8),%rax
>>>>>>   ffffffffa03898b8:	00
>>>>>>   ffffffffa03898b9:	48 85 c0             	test   %rax,%rax
>>>>>>   ffffffffa03898bc:	74 52                	je     ffffffffa0389910
>>>>>> <kvm_set_irq+0xa0>
>>>>>>   ffffffffa03898be:	48 8d 95 40 ff ff ff 	lea    -0xc0(%rbp),%rdx
>>>>>>   ffffffffa03898c5:	31 db                	xor    %ebx,%ebx
>>>>>>   ffffffffa03898c7:	48 8b 08             	mov    (%rax),%rcx
>>>>>>   ffffffffa03898ca:	83 c3 01             	add    $0x1,%ebx
>>>>>>   ffffffffa03898cd:	0f 18 09             	prefetcht0 (%rcx)
>>>>>>   ffffffffa03898d0:	48 8b 48 e0          	mov    -0x20(%rax),%rcx
>>>>>>   ffffffffa03898d4:	48 89 0a             	mov    %rcx,(%rdx)
>>>>>>   ffffffffa03898d7:	48 8b 48 e8          	mov    -0x18(%rax),%rcx
>>>>>>   ffffffffa03898db:	48 89 4a 08          	mov    %rcx,0x8(%rdx)
>>>>>>   ffffffffa03898df:	48 8b 48 f0          	mov    -0x10(%rax),%rcx
>>>>>>   ffffffffa03898e3:	48 89 4a 10          	mov    %rcx,0x10(%rdx)
>>>>>>   ffffffffa03898e7:	48 8b 48 f8          	mov    -0x8(%rax),%rcx
>>>>>>   ffffffffa03898eb:	48 89 4a 18          	mov    %rcx,0x18(%rdx)
>>>>>>
>>>>>> wich correspond to offset 68a0 (from objdump):
>>>>>>
>>>>>> kvm_set_irq():
>>>>>> /usr/src/GIT/linux-2.6-stable/arch/x86/kvm/../../../virt/kvm/irq_comm.c:161
>>>>>>      68a0:       49 8b 85 58 24 00 00    mov    0x2458(%r13),%rax
>>>>>> /usr/src/GIT/linux-2.6-stable/arch/x86/kvm/../../../virt/kvm/irq_comm.c:162
>>>>>>      68a7:       3b 98 28 01 00 00       cmp    0x128(%rax),%ebx
>>>>>>
>>>>>> root@ayrshire:~# addr2line -e
>>>>>> /lib/modules/2.6.37.2-dsiun-110105+/kernel/arch/x86/kvm/kvm.ko
>>>>>> 0x68a0
>>>>>> /usr/src/GIT/linux-2.6-stable/arch/x86/kvm/../../../virt/kvm/irq_comm.c:161
>>>>>>
>>>>>> So here kvm->irq_routing is null.
>>>>>>
>>>>>> How can it be?
>>>>>>
>>>>>> Regards.
>>>>> Not null, this seems to be invalid.
>>>>> I suspect use after free where the kvm pointer is
>>>>> pointing at some random memory. Use after free?
>>>>> Could you please try enabling a slab debugger,
>>>>> recompile and rerun the test?
>>>>>
>>>> Hi,
>>>>
>>>> I'm not sure to activate the right thing.
>>>> Is that what you want?
>>>>
>>>> CONFIG_SLAB=y
>>>> CONFIG_SLABINFO=y
>>>> CONFIG_DEBUG_SLAB=y
>>>> CONFIG_DEBUG_SLAB_LEAK=y
>>>>
>>>> Regards.
>>> Yes, maybe disable SLAB_LEAK.
>>>
>>>> -- 
>>>> Jean-Philippe Menil - Pôle réseau Service IRTS
>>>> DSI Université de Nantes
>>>> jean-philippe.menil@univ-nantes.fr
>>>> Tel : 02.53.48.49.27 - Fax : 02.53.48.49.09
>>> --
>>> To unsubscribe from this list: send the line "unsubscribe kvm" in
>>> the body of a message to majordomo@vger.kernel.org
>>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>> Hi,
>>
>> so this time, here is what markup_oops says:
>>
>> root@ayrshire:~# cat oops-0403.txt | perl markup_oops.pl -m
>> /lib/modules/2.6.37.2.999-dsiun-110105+/kernel/arch/x86/kvm/kvm.ko
>> /boot/vmlinuz-2.6.37.2.999-dsiun-110105+
>> vmaoffset = 18446744072102948864 ffffffffa03d9811:    48 89 e5
>> mov    %rsp,%rbp
>>   ffffffffa03d9814:    41 57                    push   %r15
>>   ffffffffa03d9816:    41 89 cf                 mov    %ecx,%r15d  |
>> %r15 =>  1  %ecx = 1
>>   ffffffffa03d9819:    41 56                    push   %r14        |
>> %r14 =>  ffffffffa03daa50
>>   ffffffffa03d981b:    41 55                    push   %r13
>>   ffffffffa03d981d:    49 89 fd                 mov    %rdi,%r13   |
>> %edi = 6b6b6b6b6b6b6b6b  %r13 =>  6b6b6b6b6b6b6b6b
>>   ffffffffa03d9820:    41 54                    push   %r12        |
>> %r12 =>  6b6b6b6b6b6b6b6b
>>   ffffffffa03d9822:    53                       push   %rbx
>>   ffffffffa03d9823:    89 d3                    mov    %edx,%ebx   |
>> %ebx =>  6b6b6b6b
>>   ffffffffa03d9825:    48 81 ec a8 00 00 00     sub    $0xa8,%rsp
>>   ffffffffa03d982c:    8b 15 00 00 00 00        mov    0x0(%rip),%edx
>> # ffffffffa03d9832<kvm_set_irq+0x22>
>>   ffffffffa03d9832:    89 b5 3c ff ff ff        mov
>> %esi,-0xc4(%rbp) |  %esi = 0
>>   ffffffffa03d9838:    85 d2                    test   %edx,%edx   |
>> %edx =>  0
>>   ffffffffa03d983a:    0f 85 d5 00 00 00        jne
>> ffffffffa03d9915<kvm_set_irq+0x105>
>> *ffffffffa03d9840:    49 8b 85 58 24 00 00     mov
>> 0x2458(%r13),%rax |  %eax = 0  %r13 = 6b6b6b6b6b6b6b6b<--- faulting
>> instruction
>>   ffffffffa03d9847:    3b 98 28 01 00 00        cmp    0x128(%rax),%ebx
>>   ffffffffa03d984d:    73 61                    jae
>> ffffffffa03d98b0<kvm_set_irq+0xa0>
>>   ffffffffa03d984f:    89 db                    mov    %ebx,%ebx
>>   ffffffffa03d9851:    48 8b 84 d8 30 01 00     mov
>> 0x130(%rax,%rbx,8),%rax
>>   ffffffffa03d9858:    00
>>   ffffffffa03d9859:    48 85 c0                 test   %rax,%rax
>>   ffffffffa03d985c:    74 52                    je
>> ffffffffa03d98b0<kvm_set_irq+0xa0>
>>   ffffffffa03d985e:    48 8d 95 40 ff ff ff     lea    -0xc0(%rbp),%rdx
>>   ffffffffa03d9865:    31 db                    xor    %ebx,%ebx
>>   ffffffffa03d9867:    48 8b 08                 mov    (%rax),%rcx
>>   ffffffffa03d986a:    83 c3 01                 add    $0x1,%ebx
>>   ffffffffa03d986d:    0f 18 09                 prefetcht0 (%rcx)
>>   ffffffffa03d9870:    48 8b 48 e0              mov    -0x20(%rax),%rcx
>>   ffffffffa03d9874:    48 89 0a                 mov    %rcx,(%rdx)
>>   ffffffffa03d9877:    48 8b 48 e8              mov    -0x18(%rax),%rcx
>>   ffffffffa03d987b:    48 89 4a 08              mov    %rcx,0x8(%rdx)
>>   ffffffffa03d987f:    48 8b 48 f0              mov    -0x10(%rax),%rcx
>>   ffffffffa03d9883:    48 89 4a 10              mov    %rcx,0x10(%rdx)
>>   ffffffffa03d9887:    48 8b 48 f8              mov    -0x8(%rax),%rcx
>>   ffffffffa03d988b:    48 89 4a 18              mov    %rcx,0x18(%rdx)
>>
>>
>> Is that you wanted, the "6b6b6b6b6b6b6b6b" ?
>>
>> Regards.
> Yes, excellent. So now we can detect the problem by comparing
> kvm with 6b6b6b6b6b6b6b6b, and print out stuff to understand where
> this comes from.
> I will prepare such a debugging patch.
>
> For that, could you please tell me which kernel version, exactly, are
> you using?
>
>
Yes, it's a 2.6.37.2 kernel.

Thanks a lot.


-- 
Jean-Philippe Menil - Pôle réseau Service IRTS
DSI Université de Nantes
jean-philippe.menil@univ-nantes.fr
Tel : 02.53.48.49.27 - Fax : 02.53.48.49.09


^ permalink raw reply

* Re: KIND
From: Mr.David Gurupatham @ 2011-03-04  1:10 UTC (permalink / raw)
  To: netdev@vger.kernel.org

My name is David Gurupatham a legal practitioner with David Gurupatham  & Associates

in Kuala Lumpur Msia.

I found your contact/profile some where over the Internet and it gave me the

greatest joy, that you are the one I have been looking for. Whom I strongly believe could

execute this project with me. Kindly get back to me for more information



Best regards,

Mr David Gurupatham{Esq}




^ permalink raw reply

* Re: tun: Failed to create tun sysfs files
From: Jiri Slaby @ 2011-03-04  9:37 UTC (permalink / raw)
  To: David Miller; +Cc: jslaby, linux-kernel, akpm, mm-commits, netdev, maxk, vtun
In-Reply-To: <20110304.010603.104076956.davem@davemloft.net>

On 03/04/2011 10:06 AM, David Miller wrote:
> From: Jiri Slaby <jslaby@suse.cz>
> Date: Fri, 04 Mar 2011 09:56:09 +0100
> 
>> On 03/03/2011 01:52 AM, akpm@linux-foundation.org wrote:
>>> The mm-of-the-moment snapshot 2011-03-02-16-52 has been uploaded to
>>
>> Hi, I'm seeing this with tun (also with earlier versions):
> 
> The name of the attribute was changed to netdev_group in order to
> fix this problem, in fact quite some time ago.
> 
> See the last entry of the net_class_attributes array in
> net/core/net-sysfs.c, if it isn't called "netdev_group"
> something is awry.

<idiocy>
Aha, sorry for the noise, I booted the old kernel.
</idiocy>

thanks,
-- 
js

^ permalink raw reply

* [PATCH] net: Enter net/ipv6/ even if CONFIG_IPV6=n
From: Thomas Graf @ 2011-03-04  9:35 UTC (permalink / raw)
  To: davem; +Cc: Patrick McHardy, Stephen Rothwell, netdev, linux-next,
	Randy Dunlap
In-Reply-To: <20110303135414.bfcabb2a.randy.dunlap@oracle.com>

exthdrs_core.c and addrconf_core.c in net/ipv6/ contain bits which
must be made available even if IPv6 is disabled.

net/ipv6/Makefile already correctly includes them if CONFIG_IPV6=n
but net/Makefile prevents entering the subdirectory.

Signed-off-by: Thomas Graf <tgraf@infradead.org>

diff --git a/net/Makefile b/net/Makefile
index a3330eb..a51d946 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -19,9 +19,7 @@ obj-$(CONFIG_NETFILTER)		+= netfilter/
 obj-$(CONFIG_INET)		+= ipv4/
 obj-$(CONFIG_XFRM)		+= xfrm/
 obj-$(CONFIG_UNIX)		+= unix/
-ifneq ($(CONFIG_IPV6),)
-obj-y				+= ipv6/
-endif
+obj-$(CONFIG_NET)		+= ipv6/
 obj-$(CONFIG_PACKET)		+= packet/
 obj-$(CONFIG_NET_KEY)		+= key/
 obj-$(CONFIG_BRIDGE)		+= bridge/

^ permalink raw reply related

* Re: Bug inkvm_set_irq
From: Michael S. Tsirkin @ 2011-03-04  9:35 UTC (permalink / raw)
  To: Jean-Philippe Menil; +Cc: netdev, kvm, virtualization
In-Reply-To: <4D70AF3B.5080007@univ-nantes.fr>

On Fri, Mar 04, 2011 at 10:22:03AM +0100, Jean-Philippe Menil wrote:
> Le 03/03/2011 16:55, Michael S. Tsirkin a écrit :
> >On Thu, Mar 03, 2011 at 04:26:11PM +0100, Jean-Philippe Menil wrote:
> >>Le 03/03/2011 15:47, Michael S. Tsirkin a écrit :
> >>>On Tue, Mar 01, 2011 at 03:39:12PM +0100, Jean-Philippe Menil wrote:
> >>>>so this time the bug is:
> >>>>
> >>>>[17882.612303] BUG: unable to handle kernel paging request at
> >>>>0000000000002458
> >>>>[17882.612342] IP: [<ffffffffa03898a0>] kvm_set_irq+0x30/0x140 [kvm]
> >>>>
> >>>>markup_oops give me this:
> >>>>
> >>>>root@ayrshire:~# cat bug-0103.txt | perl markup_oops.pl -m
> >>>>/lib/modules/2.6.37.2-dsiun-110105+/kernel/arch/x86/kvm/kvm.ko
> >>>>/boot/vmlinuz-2.6.37.2-dsiun-110105+
> >>>>vmaoffset = 18446744072102621184 ffffffffa0389871:	48 89 e5   	mov
> >>>>%rsp,%rbp
> >>>>  ffffffffa0389874:	41 57                	push   %r15
> >>>>  ffffffffa0389876:	41 89 cf             	mov    %ecx,%r15d  |  %r15
> >>>>=>   1  %ecx = 1
> >>>>  ffffffffa0389879:	41 56                	push   %r14        |  %r14
> >>>>=>   ffffffffa038aad0
> >>>>  ffffffffa038987b:	41 55                	push   %r13
> >>>>  ffffffffa038987d:	49 89 fd             	mov    %rdi,%r13   |  %edi
> >>>>= 0  %r13 =>   0
> >>>>  ffffffffa0389880:	41 54                	push   %r12        |  %r12 =>   0
> >>>>  ffffffffa0389882:	53                   	push   %rbx
> >>>>  ffffffffa0389883:	89 d3                	mov    %edx,%ebx   |  %ebx =>   1a
> >>>>  ffffffffa0389885:	48 81 ec a8 00 00 00 	sub    $0xa8,%rsp
> >>>>  ffffffffa038988c:	8b 15 00 00 00 00    	mov    0x0(%rip),%edx
> >>>># ffffffffa0389892<kvm_set_irq+0x22>
> >>>>  ffffffffa0389892:	89 b5 3c ff ff ff    	mov    %esi,-0xc4(%rbp) |
> >>>>%esi = 0
> >>>>  ffffffffa0389898:	85 d2                	test   %edx,%edx   |  %edx =>   0
> >>>>  ffffffffa038989a:	0f 85 d5 00 00 00    	jne    ffffffffa0389975
> >>>><kvm_set_irq+0x105>
> >>>>*ffffffffa03898a0:	49 8b 85 58 24 00 00 	mov    0x2458(%r13),%rax |
> >>>>%eax = 0  %r13 = 0<--- faulting instruction
> >>>>  ffffffffa03898a7:	3b 98 28 01 00 00    	cmp    0x128(%rax),%ebx
> >>>>  ffffffffa03898ad:	73 61                	jae    ffffffffa0389910
> >>>><kvm_set_irq+0xa0>
> >>>>  ffffffffa03898af:	89 db                	mov    %ebx,%ebx
> >>>>  ffffffffa03898b1:	48 8b 84 d8 30 01 00 	mov    0x130(%rax,%rbx,8),%rax
> >>>>  ffffffffa03898b8:	00
> >>>>  ffffffffa03898b9:	48 85 c0             	test   %rax,%rax
> >>>>  ffffffffa03898bc:	74 52                	je     ffffffffa0389910
> >>>><kvm_set_irq+0xa0>
> >>>>  ffffffffa03898be:	48 8d 95 40 ff ff ff 	lea    -0xc0(%rbp),%rdx
> >>>>  ffffffffa03898c5:	31 db                	xor    %ebx,%ebx
> >>>>  ffffffffa03898c7:	48 8b 08             	mov    (%rax),%rcx
> >>>>  ffffffffa03898ca:	83 c3 01             	add    $0x1,%ebx
> >>>>  ffffffffa03898cd:	0f 18 09             	prefetcht0 (%rcx)
> >>>>  ffffffffa03898d0:	48 8b 48 e0          	mov    -0x20(%rax),%rcx
> >>>>  ffffffffa03898d4:	48 89 0a             	mov    %rcx,(%rdx)
> >>>>  ffffffffa03898d7:	48 8b 48 e8          	mov    -0x18(%rax),%rcx
> >>>>  ffffffffa03898db:	48 89 4a 08          	mov    %rcx,0x8(%rdx)
> >>>>  ffffffffa03898df:	48 8b 48 f0          	mov    -0x10(%rax),%rcx
> >>>>  ffffffffa03898e3:	48 89 4a 10          	mov    %rcx,0x10(%rdx)
> >>>>  ffffffffa03898e7:	48 8b 48 f8          	mov    -0x8(%rax),%rcx
> >>>>  ffffffffa03898eb:	48 89 4a 18          	mov    %rcx,0x18(%rdx)
> >>>>
> >>>>wich correspond to offset 68a0 (from objdump):
> >>>>
> >>>>kvm_set_irq():
> >>>>/usr/src/GIT/linux-2.6-stable/arch/x86/kvm/../../../virt/kvm/irq_comm.c:161
> >>>>     68a0:       49 8b 85 58 24 00 00    mov    0x2458(%r13),%rax
> >>>>/usr/src/GIT/linux-2.6-stable/arch/x86/kvm/../../../virt/kvm/irq_comm.c:162
> >>>>     68a7:       3b 98 28 01 00 00       cmp    0x128(%rax),%ebx
> >>>>
> >>>>root@ayrshire:~# addr2line -e
> >>>>/lib/modules/2.6.37.2-dsiun-110105+/kernel/arch/x86/kvm/kvm.ko
> >>>>0x68a0
> >>>>/usr/src/GIT/linux-2.6-stable/arch/x86/kvm/../../../virt/kvm/irq_comm.c:161
> >>>>
> >>>>So here kvm->irq_routing is null.
> >>>>
> >>>>How can it be?
> >>>>
> >>>>Regards.
> >>>Not null, this seems to be invalid.
> >>>I suspect use after free where the kvm pointer is
> >>>pointing at some random memory. Use after free?
> >>>Could you please try enabling a slab debugger,
> >>>recompile and rerun the test?
> >>>
> >>Hi,
> >>
> >>I'm not sure to activate the right thing.
> >>Is that what you want?
> >>
> >>CONFIG_SLAB=y
> >>CONFIG_SLABINFO=y
> >>CONFIG_DEBUG_SLAB=y
> >>CONFIG_DEBUG_SLAB_LEAK=y
> >>
> >>Regards.
> >Yes, maybe disable SLAB_LEAK.
> >
> >>-- 
> >>Jean-Philippe Menil - Pôle réseau Service IRTS
> >>DSI Université de Nantes
> >>jean-philippe.menil@univ-nantes.fr
> >>Tel : 02.53.48.49.27 - Fax : 02.53.48.49.09
> >--
> >To unsubscribe from this list: send the line "unsubscribe kvm" in
> >the body of a message to majordomo@vger.kernel.org
> >More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Hi,
> 
> so this time, here is what markup_oops says:
> 
> root@ayrshire:~# cat oops-0403.txt | perl markup_oops.pl -m
> /lib/modules/2.6.37.2.999-dsiun-110105+/kernel/arch/x86/kvm/kvm.ko
> /boot/vmlinuz-2.6.37.2.999-dsiun-110105+
> vmaoffset = 18446744072102948864 ffffffffa03d9811:    48 89 e5
> mov    %rsp,%rbp
>  ffffffffa03d9814:    41 57                    push   %r15
>  ffffffffa03d9816:    41 89 cf                 mov    %ecx,%r15d  |
> %r15 => 1  %ecx = 1
>  ffffffffa03d9819:    41 56                    push   %r14        |
> %r14 => ffffffffa03daa50
>  ffffffffa03d981b:    41 55                    push   %r13
>  ffffffffa03d981d:    49 89 fd                 mov    %rdi,%r13   |
> %edi = 6b6b6b6b6b6b6b6b  %r13 => 6b6b6b6b6b6b6b6b
>  ffffffffa03d9820:    41 54                    push   %r12        |
> %r12 => 6b6b6b6b6b6b6b6b
>  ffffffffa03d9822:    53                       push   %rbx
>  ffffffffa03d9823:    89 d3                    mov    %edx,%ebx   |
> %ebx => 6b6b6b6b
>  ffffffffa03d9825:    48 81 ec a8 00 00 00     sub    $0xa8,%rsp
>  ffffffffa03d982c:    8b 15 00 00 00 00        mov    0x0(%rip),%edx
> # ffffffffa03d9832 <kvm_set_irq+0x22>
>  ffffffffa03d9832:    89 b5 3c ff ff ff        mov
> %esi,-0xc4(%rbp) |  %esi = 0
>  ffffffffa03d9838:    85 d2                    test   %edx,%edx   |
> %edx => 0
>  ffffffffa03d983a:    0f 85 d5 00 00 00        jne
> ffffffffa03d9915 <kvm_set_irq+0x105>
> *ffffffffa03d9840:    49 8b 85 58 24 00 00     mov
> 0x2458(%r13),%rax |  %eax = 0  %r13 = 6b6b6b6b6b6b6b6b <--- faulting
> instruction
>  ffffffffa03d9847:    3b 98 28 01 00 00        cmp    0x128(%rax),%ebx
>  ffffffffa03d984d:    73 61                    jae
> ffffffffa03d98b0 <kvm_set_irq+0xa0>
>  ffffffffa03d984f:    89 db                    mov    %ebx,%ebx
>  ffffffffa03d9851:    48 8b 84 d8 30 01 00     mov
> 0x130(%rax,%rbx,8),%rax
>  ffffffffa03d9858:    00
>  ffffffffa03d9859:    48 85 c0                 test   %rax,%rax
>  ffffffffa03d985c:    74 52                    je
> ffffffffa03d98b0 <kvm_set_irq+0xa0>
>  ffffffffa03d985e:    48 8d 95 40 ff ff ff     lea    -0xc0(%rbp),%rdx
>  ffffffffa03d9865:    31 db                    xor    %ebx,%ebx
>  ffffffffa03d9867:    48 8b 08                 mov    (%rax),%rcx
>  ffffffffa03d986a:    83 c3 01                 add    $0x1,%ebx
>  ffffffffa03d986d:    0f 18 09                 prefetcht0 (%rcx)
>  ffffffffa03d9870:    48 8b 48 e0              mov    -0x20(%rax),%rcx
>  ffffffffa03d9874:    48 89 0a                 mov    %rcx,(%rdx)
>  ffffffffa03d9877:    48 8b 48 e8              mov    -0x18(%rax),%rcx
>  ffffffffa03d987b:    48 89 4a 08              mov    %rcx,0x8(%rdx)
>  ffffffffa03d987f:    48 8b 48 f0              mov    -0x10(%rax),%rcx
>  ffffffffa03d9883:    48 89 4a 10              mov    %rcx,0x10(%rdx)
>  ffffffffa03d9887:    48 8b 48 f8              mov    -0x8(%rax),%rcx
>  ffffffffa03d988b:    48 89 4a 18              mov    %rcx,0x18(%rdx)
> 
> 
> Is that you wanted, the "6b6b6b6b6b6b6b6b" ?
> 
> Regards.

Yes, excellent. So now we can detect the problem by comparing
kvm with 6b6b6b6b6b6b6b6b, and print out stuff to understand where
this comes from.
I will prepare such a debugging patch.

For that, could you please tell me which kernel version, exactly, are
you using?


-- 
MST

^ permalink raw reply

* Re: Bug inkvm_set_irq
From: Jean-Philippe Menil @ 2011-03-04  9:22 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: netdev, kvm, virtualization
In-Reply-To: <20110303155533.GA13310@redhat.com>

Le 03/03/2011 16:55, Michael S. Tsirkin a écrit :
> On Thu, Mar 03, 2011 at 04:26:11PM +0100, Jean-Philippe Menil wrote:
>> Le 03/03/2011 15:47, Michael S. Tsirkin a écrit :
>>> On Tue, Mar 01, 2011 at 03:39:12PM +0100, Jean-Philippe Menil wrote:
>>>> so this time the bug is:
>>>>
>>>> [17882.612303] BUG: unable to handle kernel paging request at
>>>> 0000000000002458
>>>> [17882.612342] IP: [<ffffffffa03898a0>] kvm_set_irq+0x30/0x140 [kvm]
>>>>
>>>> markup_oops give me this:
>>>>
>>>> root@ayrshire:~# cat bug-0103.txt | perl markup_oops.pl -m
>>>> /lib/modules/2.6.37.2-dsiun-110105+/kernel/arch/x86/kvm/kvm.ko
>>>> /boot/vmlinuz-2.6.37.2-dsiun-110105+
>>>> vmaoffset = 18446744072102621184 ffffffffa0389871:	48 89 e5   	mov
>>>> %rsp,%rbp
>>>>   ffffffffa0389874:	41 57                	push   %r15
>>>>   ffffffffa0389876:	41 89 cf             	mov    %ecx,%r15d  |  %r15
>>>> =>   1  %ecx = 1
>>>>   ffffffffa0389879:	41 56                	push   %r14        |  %r14
>>>> =>   ffffffffa038aad0
>>>>   ffffffffa038987b:	41 55                	push   %r13
>>>>   ffffffffa038987d:	49 89 fd             	mov    %rdi,%r13   |  %edi
>>>> = 0  %r13 =>   0
>>>>   ffffffffa0389880:	41 54                	push   %r12        |  %r12 =>   0
>>>>   ffffffffa0389882:	53                   	push   %rbx
>>>>   ffffffffa0389883:	89 d3                	mov    %edx,%ebx   |  %ebx =>   1a
>>>>   ffffffffa0389885:	48 81 ec a8 00 00 00 	sub    $0xa8,%rsp
>>>>   ffffffffa038988c:	8b 15 00 00 00 00    	mov    0x0(%rip),%edx
>>>> # ffffffffa0389892<kvm_set_irq+0x22>
>>>>   ffffffffa0389892:	89 b5 3c ff ff ff    	mov    %esi,-0xc4(%rbp) |
>>>> %esi = 0
>>>>   ffffffffa0389898:	85 d2                	test   %edx,%edx   |  %edx =>   0
>>>>   ffffffffa038989a:	0f 85 d5 00 00 00    	jne    ffffffffa0389975
>>>> <kvm_set_irq+0x105>
>>>> *ffffffffa03898a0:	49 8b 85 58 24 00 00 	mov    0x2458(%r13),%rax |
>>>> %eax = 0  %r13 = 0<--- faulting instruction
>>>>   ffffffffa03898a7:	3b 98 28 01 00 00    	cmp    0x128(%rax),%ebx
>>>>   ffffffffa03898ad:	73 61                	jae    ffffffffa0389910
>>>> <kvm_set_irq+0xa0>
>>>>   ffffffffa03898af:	89 db                	mov    %ebx,%ebx
>>>>   ffffffffa03898b1:	48 8b 84 d8 30 01 00 	mov    0x130(%rax,%rbx,8),%rax
>>>>   ffffffffa03898b8:	00
>>>>   ffffffffa03898b9:	48 85 c0             	test   %rax,%rax
>>>>   ffffffffa03898bc:	74 52                	je     ffffffffa0389910
>>>> <kvm_set_irq+0xa0>
>>>>   ffffffffa03898be:	48 8d 95 40 ff ff ff 	lea    -0xc0(%rbp),%rdx
>>>>   ffffffffa03898c5:	31 db                	xor    %ebx,%ebx
>>>>   ffffffffa03898c7:	48 8b 08             	mov    (%rax),%rcx
>>>>   ffffffffa03898ca:	83 c3 01             	add    $0x1,%ebx
>>>>   ffffffffa03898cd:	0f 18 09             	prefetcht0 (%rcx)
>>>>   ffffffffa03898d0:	48 8b 48 e0          	mov    -0x20(%rax),%rcx
>>>>   ffffffffa03898d4:	48 89 0a             	mov    %rcx,(%rdx)
>>>>   ffffffffa03898d7:	48 8b 48 e8          	mov    -0x18(%rax),%rcx
>>>>   ffffffffa03898db:	48 89 4a 08          	mov    %rcx,0x8(%rdx)
>>>>   ffffffffa03898df:	48 8b 48 f0          	mov    -0x10(%rax),%rcx
>>>>   ffffffffa03898e3:	48 89 4a 10          	mov    %rcx,0x10(%rdx)
>>>>   ffffffffa03898e7:	48 8b 48 f8          	mov    -0x8(%rax),%rcx
>>>>   ffffffffa03898eb:	48 89 4a 18          	mov    %rcx,0x18(%rdx)
>>>>
>>>> wich correspond to offset 68a0 (from objdump):
>>>>
>>>> kvm_set_irq():
>>>> /usr/src/GIT/linux-2.6-stable/arch/x86/kvm/../../../virt/kvm/irq_comm.c:161
>>>>      68a0:       49 8b 85 58 24 00 00    mov    0x2458(%r13),%rax
>>>> /usr/src/GIT/linux-2.6-stable/arch/x86/kvm/../../../virt/kvm/irq_comm.c:162
>>>>      68a7:       3b 98 28 01 00 00       cmp    0x128(%rax),%ebx
>>>>
>>>> root@ayrshire:~# addr2line -e
>>>> /lib/modules/2.6.37.2-dsiun-110105+/kernel/arch/x86/kvm/kvm.ko
>>>> 0x68a0
>>>> /usr/src/GIT/linux-2.6-stable/arch/x86/kvm/../../../virt/kvm/irq_comm.c:161
>>>>
>>>> So here kvm->irq_routing is null.
>>>>
>>>> How can it be?
>>>>
>>>> Regards.
>>> Not null, this seems to be invalid.
>>> I suspect use after free where the kvm pointer is
>>> pointing at some random memory. Use after free?
>>> Could you please try enabling a slab debugger,
>>> recompile and rerun the test?
>>>
>> Hi,
>>
>> I'm not sure to activate the right thing.
>> Is that what you want?
>>
>> CONFIG_SLAB=y
>> CONFIG_SLABINFO=y
>> CONFIG_DEBUG_SLAB=y
>> CONFIG_DEBUG_SLAB_LEAK=y
>>
>> Regards.
> Yes, maybe disable SLAB_LEAK.
>
>> -- 
>> Jean-Philippe Menil - Pôle réseau Service IRTS
>> DSI Université de Nantes
>> jean-philippe.menil@univ-nantes.fr
>> Tel : 02.53.48.49.27 - Fax : 02.53.48.49.09
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
Hi,

so this time, here is what markup_oops says:

root@ayrshire:~# cat oops-0403.txt | perl markup_oops.pl -m 
/lib/modules/2.6.37.2.999-dsiun-110105+/kernel/arch/x86/kvm/kvm.ko 
/boot/vmlinuz-2.6.37.2.999-dsiun-110105+
vmaoffset = 18446744072102948864 ffffffffa03d9811:    48 89 
e5                 mov    %rsp,%rbp
  ffffffffa03d9814:    41 57                    push   %r15
  ffffffffa03d9816:    41 89 cf                 mov    %ecx,%r15d  |  
%r15 => 1  %ecx = 1
  ffffffffa03d9819:    41 56                    push   %r14        |  
%r14 => ffffffffa03daa50
  ffffffffa03d981b:    41 55                    push   %r13
  ffffffffa03d981d:    49 89 fd                 mov    %rdi,%r13   |  
%edi = 6b6b6b6b6b6b6b6b  %r13 => 6b6b6b6b6b6b6b6b
  ffffffffa03d9820:    41 54                    push   %r12        |  
%r12 => 6b6b6b6b6b6b6b6b
  ffffffffa03d9822:    53                       push   %rbx
  ffffffffa03d9823:    89 d3                    mov    %edx,%ebx   |  
%ebx => 6b6b6b6b
  ffffffffa03d9825:    48 81 ec a8 00 00 00     sub    $0xa8,%rsp
  ffffffffa03d982c:    8b 15 00 00 00 00        mov    
0x0(%rip),%edx        # ffffffffa03d9832 <kvm_set_irq+0x22>
  ffffffffa03d9832:    89 b5 3c ff ff ff        mov    %esi,-0xc4(%rbp) 
|  %esi = 0
  ffffffffa03d9838:    85 d2                    test   %edx,%edx   |  
%edx => 0
  ffffffffa03d983a:    0f 85 d5 00 00 00        jne    ffffffffa03d9915 
<kvm_set_irq+0x105>
*ffffffffa03d9840:    49 8b 85 58 24 00 00     mov    0x2458(%r13),%rax 
|  %eax = 0  %r13 = 6b6b6b6b6b6b6b6b <--- faulting instruction
  ffffffffa03d9847:    3b 98 28 01 00 00        cmp    0x128(%rax),%ebx
  ffffffffa03d984d:    73 61                    jae    ffffffffa03d98b0 
<kvm_set_irq+0xa0>
  ffffffffa03d984f:    89 db                    mov    %ebx,%ebx
  ffffffffa03d9851:    48 8b 84 d8 30 01 00     mov    
0x130(%rax,%rbx,8),%rax
  ffffffffa03d9858:    00
  ffffffffa03d9859:    48 85 c0                 test   %rax,%rax
  ffffffffa03d985c:    74 52                    je     ffffffffa03d98b0 
<kvm_set_irq+0xa0>
  ffffffffa03d985e:    48 8d 95 40 ff ff ff     lea    -0xc0(%rbp),%rdx
  ffffffffa03d9865:    31 db                    xor    %ebx,%ebx
  ffffffffa03d9867:    48 8b 08                 mov    (%rax),%rcx
  ffffffffa03d986a:    83 c3 01                 add    $0x1,%ebx
  ffffffffa03d986d:    0f 18 09                 prefetcht0 (%rcx)
  ffffffffa03d9870:    48 8b 48 e0              mov    -0x20(%rax),%rcx
  ffffffffa03d9874:    48 89 0a                 mov    %rcx,(%rdx)
  ffffffffa03d9877:    48 8b 48 e8              mov    -0x18(%rax),%rcx
  ffffffffa03d987b:    48 89 4a 08              mov    %rcx,0x8(%rdx)
  ffffffffa03d987f:    48 8b 48 f0              mov    -0x10(%rax),%rcx
  ffffffffa03d9883:    48 89 4a 10              mov    %rcx,0x10(%rdx)
  ffffffffa03d9887:    48 8b 48 f8              mov    -0x8(%rax),%rcx
  ffffffffa03d988b:    48 89 4a 18              mov    %rcx,0x18(%rdx)


Is that you wanted, the "6b6b6b6b6b6b6b6b" ?

Regards.

-- 
Jean-Philippe Menil - Pôle réseau Service IRTS
DSI Université de Nantes
jean-philippe.menil@univ-nantes.fr
Tel : 02.53.48.49.27 - Fax : 02.53.48.49.09


^ permalink raw reply

* Re: [Patch] bonding: move procfs into bond_procfs.c
From: Cong Wang @ 2011-03-04  9:08 UTC (permalink / raw)
  To: David Miller; +Cc: linux-kernel, fubar, netdev
In-Reply-To: <20110302.221707.260068518.davem@davemloft.net>

于 2011年03月03日 14:17, David Miller 写道:
> From: Amerigo Wang<amwang@redhat.com>
> Date: Mon, 28 Feb 2011 20:30:04 +0800
>
>> bond_main.c is bloating, separate the procfs code out,
>> move them to bond_procfs.c
>>
>> Signed-off-by: WANG Cong<amwang@redhat.com>
>
> Please use Makefile rules to conditionally compile the new bond_procfs.o
> file, instead of wrapping almost the entire file with an ifdef.
>
> Put the dummy no-PROC_FS function stubs, as inlines, in bonding.h
>

Ok, will do it in the next update.

Thanks!

^ permalink raw reply

* Re: tun: Failed to create tun sysfs files
From: David Miller @ 2011-03-04  9:06 UTC (permalink / raw)
  To: jslaby; +Cc: linux-kernel, akpm, mm-commits, jirislaby, netdev, maxk, vtun
In-Reply-To: <4D70A929.4010900@suse.cz>

From: Jiri Slaby <jslaby@suse.cz>
Date: Fri, 04 Mar 2011 09:56:09 +0100

> On 03/03/2011 01:52 AM, akpm@linux-foundation.org wrote:
>> The mm-of-the-moment snapshot 2011-03-02-16-52 has been uploaded to
> 
> Hi, I'm seeing this with tun (also with earlier versions):

The name of the attribute was changed to netdev_group in order to
fix this problem, in fact quite some time ago.

See the last entry of the net_class_attributes array in
net/core/net-sysfs.c, if it isn't called "netdev_group"
something is awry.

^ permalink raw reply

* Re: [PATCH resent] tcp: ioctl type SIOCOUTQNSD returns amount of data not sent
From: David Miller @ 2011-03-04  9:04 UTC (permalink / raw)
  To: sledz
  Cc: netdev, linux-kernel, kuznet, pekkas, jmorris, yoshfuji, kaber,
	m.schuknecht
In-Reply-To: <1299228497-21246-1-git-send-email-sledz@dresearch.de>

From: Steffen Sledz <sledz@dresearch.de>
Date: Fri,  4 Mar 2011 09:48:17 +0100

> diff --git a/include/asm-generic/ioctls.h b/include/asm-generic/ioctls.h
> index 199975f..ef2be0b 100644
> --- a/include/asm-generic/ioctls.h
> +++ b/include/asm-generic/ioctls.h
> @@ -74,6 +74,7 @@
>  #define TCSETXW		0x5435
>  #define TIOCSIG		_IOW('T', 0x36, int)  /* pty: generate signal */
>  #define TIOCVHANGUP	0x5437
> +#define TIOCOUTQNSD	0x5438
>  
>  #define FIONCLEX	0x5450
>  #define FIOCLEX		0x5451

Hitting only asm-generic/ioctls.h is insufficient, many architectures do
not make use of this file and the build will fail for them with your patch
applied.

^ permalink raw reply

* tun: Failed to create tun sysfs files [was: mmotm 2011-03-02-16-52 uploaded]
From: Jiri Slaby @ 2011-03-04  8:56 UTC (permalink / raw)
  To: linux-kernel; +Cc: akpm, mm-commits, Jiri Slaby, ML netdev, maxk, vtun
In-Reply-To: <201103030127.p231ReNl012841@imap1.linux-foundation.org>

On 03/03/2011 01:52 AM, akpm@linux-foundation.org wrote:
> The mm-of-the-moment snapshot 2011-03-02-16-52 has been uploaded to

Hi, I'm seeing this with tun (also with earlier versions):
WARNING: at fs/sysfs/dir.c:455 sysfs_add_one+0xb8/0xe0()
Hardware name: To Be Filled By O.E.M.
sysfs: cannot create duplicate filename '/devices/virtual/net/tun0/group'
Modules linked in: microcode dvb_usb_af9015 tda18271 af9013 dvb_usb dvb_core
Pid: 3840, comm: openvpn Not tainted 2.6.38-rc4-mm1_64+ #1390
Call Trace:
 [<ffffffff8106d61a>] ? warn_slowpath_common+0x7a/0xb0
 [<ffffffff8106d6f1>] ? warn_slowpath_fmt+0x41/0x50
 [<ffffffff81176638>] ? sysfs_add_one+0xb8/0xe0
 [<ffffffff8117570d>] ? sysfs_add_file_mode+0x5d/0xa0
 [<ffffffff8117575c>] ? sysfs_add_file+0xc/0x10
 [<ffffffff81175841>] ? sysfs_create_file+0x21/0x40
 [<ffffffff813609d4>] ? device_create_file+0x14/0x20
 [<ffffffff813e0256>] ? tun_set_iff+0x3f6/0x4a0
 [<ffffffff813e05fe>] ? __tun_chr_ioctl+0x12e/0x5d0
 [<ffffffff8126c5c2>] ? __strncpy_from_user+0x22/0x60
 [<ffffffff813e0ade>] ? tun_chr_ioctl+0xe/0x10
 [<ffffffff811274ed>] ? do_vfs_ioctl+0x8d/0x300
 [<ffffffff811277aa>] ? sys_ioctl+0x4a/0x80
 [<ffffffff81030dbb>] ? system_call_fastpath+0x16/0x1b

It's because these devices already contain 'group' in the sysfs dir.

regards,
-- 
js
suse labs

^ permalink raw reply

* [PATCH resent] tcp: ioctl type SIOCOUTQNSD returns amount of data not sent
From: Steffen Sledz @ 2011-03-04  8:48 UTC (permalink / raw)
  To: netdev, linux-kernel
  Cc: David S. Miller, Alexey Kuznetsov, Pekka Savola (ipv6),
	James Morris, Hideaki YOSHIFUJI, Patrick McHardy,
	Mario Schuknecht, Steffen Sledz

From: Mario Schuknecht <m.schuknecht@dresearch.de>

In contrast to SIOCOUTQ which returns the amount of data sent
but not yet acknowledged plus data not yet sent this patch only
returns the data not sent.

For various methods of live streaming bitrate control it may
be helpful to know how much data are in the tcp outqueue are
not sent yet.

Signed-off-by: Mario Schuknecht <m.schuknecht@dresearch.de>
Signed-off-by: Steffen Sledz <sledz@dresearch.de>
---
 include/asm-generic/ioctls.h |    1 +
 include/linux/sockios.h      |    1 +
 net/ipv4/tcp.c               |    9 +++++++++
 3 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/include/asm-generic/ioctls.h b/include/asm-generic/ioctls.h
index 199975f..ef2be0b 100644
--- a/include/asm-generic/ioctls.h
+++ b/include/asm-generic/ioctls.h
@@ -74,6 +74,7 @@
 #define TCSETXW		0x5435
 #define TIOCSIG		_IOW('T', 0x36, int)  /* pty: generate signal */
 #define TIOCVHANGUP	0x5437
+#define TIOCOUTQNSD	0x5438
 
 #define FIONCLEX	0x5450
 #define FIOCLEX		0x5451
diff --git a/include/linux/sockios.h b/include/linux/sockios.h
index 241f179..4c5ca47 100644
--- a/include/linux/sockios.h
+++ b/include/linux/sockios.h
@@ -23,6 +23,7 @@
 /* Linux-specific socket ioctls */
 #define SIOCINQ		FIONREAD
 #define SIOCOUTQ	TIOCOUTQ
+#define SIOCOUTQNSD	TIOCOUTQNSD
 
 /* Routing table calls. */
 #define SIOCADDRT	0x890B		/* add routing table entry	*/
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index a17a5a7..b22d450 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -505,6 +505,15 @@ int tcp_ioctl(struct sock *sk, int cmd, unsigned long arg)
 		else
 			answ = tp->write_seq - tp->snd_una;
 		break;
+	case SIOCOUTQNSD:
+		if (sk->sk_state == TCP_LISTEN)
+			return -EINVAL;
+
+		if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV))
+			answ = 0;
+		else
+			answ = tp->write_seq - tp->snd_nxt;
+		break;
 	default:
 		return -ENOIOCTLCMD;
 	}
-- 
1.7.1

^ permalink raw reply related

* Re: [BUG] VPN broken in net-next
From: Julian Anastasov @ 2011-03-04  8:39 UTC (permalink / raw)
  To: David Miller; +Cc: shemminger, netdev
In-Reply-To: <20110303.112328.59677094.davem@davemloft.net>


 	Hello,

On Thu, 3 Mar 2011, David Miller wrote:

> I suspect that even if we need to handle prefixes, we can still use
> the hash for optimistic lookup, and fallback to a local table FIB
> inspection if that fails.

 	Yes, as ip_route_output_slow uses __ip_dev_find for
fl4_src there should be some kind of fallback to local table,
so that traffic from 127.0.0.2 to 127.0.0.3 or other local
subnets on loopback can work. Another option is to use
inet_addr_onlink but I suspect people can add many addresses
on loopback: inet_addr_onlink(loopback_indev, addr, 0)

Regards

--
Julian Anastasov <ja@ssi.bg>

^ permalink raw reply

* Re: [PATCH] e1000: power off PHY after reset when interface is down
From: Jeff Kirsher @ 2011-03-04  8:19 UTC (permalink / raw)
  To: prasanna.panchamukhi@riverbed.com
  Cc: Allan, Bruce W, Pieper, Jeffrey E,
	e1000-devel@lists.sourceforge.net, netdev@vger.kernel.org
In-Reply-To: <1298505765.25453.17.camel@jtkirshe-linux>

On Wed, Feb 23, 2011 at 16:02, Jeff Kirsher <jeffrey.t.kirsher@intel.com> wrote:
> On Tue, 2011-02-22 at 17:25 -0800, prasanna.panchamukhi@riverbed.com
> wrote:
>> From: Prasanna S. Panchamukhi <prasanna.panchamukhi@riverbed.com>
>>
>> Some Phys supported by the e1000 driver do not remain powered off
>> across
>> a reset of the device when the interface is down, e.g. on 82546.
>> This patch powers down (only when WoL is disabled) the PHY after reset
>> if
>> the interface is down and ethtool diagnostics are not currently
>> running.
>>
>> Similar problem was see on 82571 controller and was fixed in e1000e
>> driver
>> by Bruce Allan.
>> Please refer commit 31dbe5b4ac6fca72dec946e4d0fa7f0913f1d9b1 for
>> details.
>>
>> Signed-off-by: Prasanna S. Panchamukhi
>> <prasanna.panchamukhi@riverbed.com>
>> ---
>>  drivers/net/e1000/e1000_ethtool.c |   27 +++++++++++++++++++--------
>>  drivers/net/e1000/e1000_main.c    |    7 +++++++
>>  2 files changed, 26 insertions(+), 8 deletions(-)
>
> Thanks Prasanna!  I have added the patch to my queue of e1000 patches.
>

Prasanna-
Here is what we found during validating your patch:

The behavior of 82546 device(s) seems to be identical with/without this patch
applied. 82546GB (LOM), dev_id 1079 powers down (with wol disabled) after
ifdown, but powers back up after approx. 10 seconds. 82546EB (NIC), dev_id
1010 powers down (with wol disabled) after ifdown. Both of the above
behaviors are the same with and without the patch applied. Also, if this patch
DID work as expected, it should print a message after a reset, such as "Cannot
restart autonegotiation: Resource temporarily unavailable", which would mirror
the behavior of e1000e.

-- 
Cheers,
Jeff

^ permalink raw reply

* [PATCH 2/2] bonding 802.3ad: Rename rx_machine_lock to state_machine_lock
From: Nils Carlson @ 2011-03-04  8:09 UTC (permalink / raw)
  To: Jay Vosburgh, Andy Gospodarek; +Cc: netdev, Nils Carlson
In-Reply-To: <1299226152-23578-1-git-send-email-nils.carlson@ericsson.com>

Rename the rx_machine_lock to state_machine_lock as this makes more
sense in light of it now protecting all the state machines against
concurrency.

Signed-off-by: Nils Carlson <nils.carlson@ericsson.com>
---
 drivers/net/bonding/bond_3ad.c |   24 ++++++++++++------------
 drivers/net/bonding/bond_3ad.h |    3 ++-
 2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c
index de30c8d..a5d5d0b 100644
--- a/drivers/net/bonding/bond_3ad.c
+++ b/drivers/net/bonding/bond_3ad.c
@@ -281,23 +281,23 @@ static inline int __check_agg_selection_timer(struct port *port)
 }
 
 /**
- * __get_rx_machine_lock - lock the port's RX machine
+ * __get_state_machine_lock - lock the port's state machines
  * @port: the port we're looking at
  *
  */
-static inline void __get_rx_machine_lock(struct port *port)
+static inline void __get_state_machine_lock(struct port *port)
 {
-	spin_lock_bh(&(SLAVE_AD_INFO(port->slave).rx_machine_lock));
+	spin_lock_bh(&(SLAVE_AD_INFO(port->slave).state_machine_lock));
 }
 
 /**
- * __release_rx_machine_lock - unlock the port's RX machine
+ * __release_state_machine_lock - unlock the port's state machines
  * @port: the port we're looking at
  *
  */
-static inline void __release_rx_machine_lock(struct port *port)
+static inline void __release_state_machine_lock(struct port *port)
 {
-	spin_unlock_bh(&(SLAVE_AD_INFO(port->slave).rx_machine_lock));
+	spin_unlock_bh(&(SLAVE_AD_INFO(port->slave).state_machine_lock));
 }
 
 /**
@@ -388,14 +388,14 @@ static u8 __get_duplex(struct port *port)
 }
 
 /**
- * __initialize_port_locks - initialize a port's RX machine spinlock
+ * __initialize_port_locks - initialize a port's STATE machine spinlock
  * @port: the port we're looking at
  *
  */
 static inline void __initialize_port_locks(struct port *port)
 {
 	// make sure it isn't called twice
-	spin_lock_init(&(SLAVE_AD_INFO(port->slave).rx_machine_lock));
+	spin_lock_init(&(SLAVE_AD_INFO(port->slave).state_machine_lock));
 }
 
 //conversions
@@ -2154,7 +2154,7 @@ void bond_3ad_state_machine_handler(struct work_struct *work)
 		 * by all (e.g., port->sm_vars).  ad_rx_machine may run
 		 * concurrently due to incoming LACPDU.
 		 */
-		__get_rx_machine_lock(port);
+		__get_state_machine_lock(port);
 
 		ad_rx_machine(NULL, port);
 		ad_periodic_machine(port);
@@ -2166,7 +2166,7 @@ void bond_3ad_state_machine_handler(struct work_struct *work)
 		if (port->sm_vars & AD_PORT_BEGIN)
 			port->sm_vars &= ~AD_PORT_BEGIN;
 
-		__release_rx_machine_lock(port);
+		__release_state_machine_lock(port);
 	}
 
 re_arm:
@@ -2204,9 +2204,9 @@ static void bond_3ad_rx_indication(struct lacpdu *lacpdu, struct slave *slave, u
 			pr_debug("Received LACPDU on port %d\n",
 				 port->actor_port_number);
 			/* Protect against concurrent state machines */
-			__get_rx_machine_lock(port);
+			__get_state_machine_lock(port);
 			ad_rx_machine(lacpdu, port);
-			__release_rx_machine_lock(port);
+			__release_state_machine_lock(port);
 			break;
 
 		case AD_TYPE_MARKER:
diff --git a/drivers/net/bonding/bond_3ad.h b/drivers/net/bonding/bond_3ad.h
index 2c46a15..b28baff 100644
--- a/drivers/net/bonding/bond_3ad.h
+++ b/drivers/net/bonding/bond_3ad.h
@@ -264,7 +264,8 @@ struct ad_bond_info {
 struct ad_slave_info {
 	struct aggregator aggregator;	    // 802.3ad aggregator structure
 	struct port port;		    // 802.3ad port structure
-	spinlock_t rx_machine_lock; // To avoid race condition between callback and receive interrupt
+	spinlock_t state_machine_lock; /* mutex state machines vs.
+					  incoming LACPDU */
 	u16 id;
 };
 
-- 
1.7.1


^ permalink raw reply related

* [PATCH 1/2] bonding 802.3ad: Fix the state machine locking v2
From: Nils Carlson @ 2011-03-04  8:09 UTC (permalink / raw)
  To: Jay Vosburgh, Andy Gospodarek; +Cc: netdev, Nils Carlson

Changes since v1:
* Clarify an unclear comment
* Move a (possible) name change to a separate patch

The ad_rx_machine, ad_periodic_machine and ad_port_selection_logic
functions all inspect and alter common fields within the port structure.
Previous to this patch, only the ad_rx_machines were mutexed, and the
periodic and port_selection could run unmutexed against an ad_rx_machine
trigged by an arriving LACPDU.

This patch remedies the situation by protecting all the state machines
from concurrency. This is accomplished by locking around all the state
machines for a given port, which are executed at regular intervals; and
the ad_rx_machine when handling an incoming LACPDU.

Signed-off-by: Nils Carlson <nils.carlson@ericsson.com>
---
 drivers/net/bonding/bond_3ad.c |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c
index 1024ae1..de30c8d 100644
--- a/drivers/net/bonding/bond_3ad.c
+++ b/drivers/net/bonding/bond_3ad.c
@@ -1025,9 +1025,6 @@ static void ad_rx_machine(struct lacpdu *lacpdu, struct port *port)
 {
 	rx_states_t last_state;
 
-	// Lock to prevent 2 instances of this function to run simultaneously(rx interrupt and periodic machine callback)
-	__get_rx_machine_lock(port);
-
 	// keep current State Machine state to compare later if it was changed
 	last_state = port->sm_rx_state;
 
@@ -1133,7 +1130,6 @@ static void ad_rx_machine(struct lacpdu *lacpdu, struct port *port)
 				pr_err("%s: An illegal loopback occurred on adapter (%s).\n"
 				       "Check the configuration to verify that all adapters are connected to 802.3ad compliant switch ports\n",
 				       port->slave->dev->master->name, port->slave->dev->name);
-				__release_rx_machine_lock(port);
 				return;
 			}
 			__update_selected(lacpdu, port);
@@ -1153,7 +1149,6 @@ static void ad_rx_machine(struct lacpdu *lacpdu, struct port *port)
 			break;
 		}
 	}
-	__release_rx_machine_lock(port);
 }
 
 /**
@@ -2155,6 +2150,12 @@ void bond_3ad_state_machine_handler(struct work_struct *work)
 			goto re_arm;
 		}
 
+		/* Lock around state machines to protect data accessed
+		 * by all (e.g., port->sm_vars).  ad_rx_machine may run
+		 * concurrently due to incoming LACPDU.
+		 */
+		__get_rx_machine_lock(port);
+
 		ad_rx_machine(NULL, port);
 		ad_periodic_machine(port);
 		ad_port_selection_logic(port);
@@ -2164,6 +2165,8 @@ void bond_3ad_state_machine_handler(struct work_struct *work)
 		// turn off the BEGIN bit, since we already handled it
 		if (port->sm_vars & AD_PORT_BEGIN)
 			port->sm_vars &= ~AD_PORT_BEGIN;
+
+		__release_rx_machine_lock(port);
 	}
 
 re_arm:
@@ -2200,7 +2203,10 @@ static void bond_3ad_rx_indication(struct lacpdu *lacpdu, struct slave *slave, u
 		case AD_TYPE_LACPDU:
 			pr_debug("Received LACPDU on port %d\n",
 				 port->actor_port_number);
+			/* Protect against concurrent state machines */
+			__get_rx_machine_lock(port);
 			ad_rx_machine(lacpdu, port);
+			__release_rx_machine_lock(port);
 			break;
 
 		case AD_TYPE_MARKER:
-- 
1.7.1


^ permalink raw reply related


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