<feed xmlns='http://www.w3.org/2005/Atom'>
<title>lwn.git/net/tipc/subscr.c, branch docs-for-linus</title>
<subtitle>Linux kernel documentation tree maintained by Jonathan Corbet</subtitle>
<id>http://mirrors.hust.edu.cn/git/lwn.git/atom?h=docs-for-linus</id>
<link rel='self' href='http://mirrors.hust.edu.cn/git/lwn.git/atom?h=docs-for-linus'/>
<link rel='alternate' type='text/html' href='http://mirrors.hust.edu.cn/git/lwn.git/'/>
<updated>2016-04-28T20:54:12+00:00</updated>
<entry>
<title>tipc: remove an unnecessary NULL check</title>
<updated>2016-04-28T20:54:12+00:00</updated>
<author>
<name>Dan Carpenter</name>
<email>dan.carpenter@oracle.com</email>
</author>
<published>2016-04-27T08:05:28+00:00</published>
<link rel='alternate' type='text/html' href='http://mirrors.hust.edu.cn/git/lwn.git/commit/?id=b43586576e54609f7970096478cf4113de18a4db'/>
<id>urn:sha1:b43586576e54609f7970096478cf4113de18a4db</id>
<content type='text'>
This is never called with a NULL "buf" and anyway, we dereference 's' on
the lines before so it would Oops before we reach the check.

Signed-off-by: Dan Carpenter &lt;dan.carpenter@oracle.com&gt;
Acked-by: Ying Xue &lt;ying.xue@windriver.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>tipc: fix a race condition leading to subscriber refcnt bug</title>
<updated>2016-04-14T20:46:46+00:00</updated>
<author>
<name>Parthasarathy Bhuvaragan</name>
<email>parthasarathy.bhuvaragan@ericsson.com</email>
</author>
<published>2016-04-12T11:05:21+00:00</published>
<link rel='alternate' type='text/html' href='http://mirrors.hust.edu.cn/git/lwn.git/commit/?id=333f796235a52727db7e0a13888045f3aa3d5335'/>
<id>urn:sha1:333f796235a52727db7e0a13888045f3aa3d5335</id>
<content type='text'>
Until now, the requests sent to topology server are queued
to a workqueue by the generic server framework.
These messages are processed by worker threads and trigger the
registered callbacks.
To reduce latency on uniprocessor systems, explicit rescheduling
is performed using cond_resched() after MAX_RECV_MSG_COUNT(25)
messages.

This implementation on SMP systems leads to an subscriber refcnt
error as described below:
When a worker thread yields by calling cond_resched() in a SMP
system, a new worker is created on another CPU to process the
pending workitem. Sometimes the sleeping thread wakes up before
the new thread finishes execution.
This breaks the assumption on ordering and being single threaded.
The fault is more frequent when MAX_RECV_MSG_COUNT is lowered.

If the first thread was processing subscription create and the
second thread processing close(), the close request will free
the subscriber and the create request oops as follows:

[31.224137] WARNING: CPU: 2 PID: 266 at include/linux/kref.h:46 tipc_subscrb_rcv_cb+0x317/0x380         [tipc]
[31.228143] CPU: 2 PID: 266 Comm: kworker/u8:1 Not tainted 4.5.0+ #97
[31.228377] Workqueue: tipc_rcv tipc_recv_work [tipc]
[...]
[31.228377] Call Trace:
[31.228377]  [&lt;ffffffff812fbb6b&gt;] dump_stack+0x4d/0x72
[31.228377]  [&lt;ffffffff8105a311&gt;] __warn+0xd1/0xf0
[31.228377]  [&lt;ffffffff8105a3fd&gt;] warn_slowpath_null+0x1d/0x20
[31.228377]  [&lt;ffffffffa0098067&gt;] tipc_subscrb_rcv_cb+0x317/0x380 [tipc]
[31.228377]  [&lt;ffffffffa00a4984&gt;] tipc_receive_from_sock+0xd4/0x130 [tipc]
[31.228377]  [&lt;ffffffffa00a439b&gt;] tipc_recv_work+0x2b/0x50 [tipc]
[31.228377]  [&lt;ffffffff81071925&gt;] process_one_work+0x145/0x3d0
[31.246554] ---[ end trace c3882c9baa05a4fd ]---
[31.248327] BUG: spinlock bad magic on CPU#2, kworker/u8:1/266
[31.249119] BUG: unable to handle kernel NULL pointer dereference at 0000000000000428
[31.249323] IP: [&lt;ffffffff81099d0c&gt;] spin_dump+0x5c/0xe0
[31.249323] PGD 0
[31.249323] Oops: 0000 [#1] SMP

In this commit, we
- rename tipc_conn_shutdown() to tipc_conn_release().
- move connection release callback execution from tipc_close_conn()
  to a new function tipc_sock_release(), which is executed before
  we free the connection.
Thus we release the subscriber during connection release procedure
rather than connection shutdown procedure.

Signed-off-by: Parthasarathy Bhuvaragan &lt;parthasarathy.bhuvaragan@ericsson.com&gt;
Acked-by: Ying Xue &lt;ying.xue@windriver.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net</title>
<updated>2016-03-08T17:34:12+00:00</updated>
<author>
<name>David S. Miller</name>
<email>davem@davemloft.net</email>
</author>
<published>2016-03-08T17:34:12+00:00</published>
<link rel='alternate' type='text/html' href='http://mirrors.hust.edu.cn/git/lwn.git/commit/?id=810813c47a564416f6306ae214e2661366c987a7'/>
<id>urn:sha1:810813c47a564416f6306ae214e2661366c987a7</id>
<content type='text'>
Several cases of overlapping changes, as well as one instance
(vxlan) of a bug fix in 'net' overlapping with code movement
in 'net-next'.

Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>tipc: fix nullptr crash during subscription cancel</title>
<updated>2016-03-07T04:00:08+00:00</updated>
<author>
<name>Parthasarathy Bhuvaragan</name>
<email>parthasarathy.bhuvaragan@ericsson.com</email>
</author>
<published>2016-03-03T16:54:54+00:00</published>
<link rel='alternate' type='text/html' href='http://mirrors.hust.edu.cn/git/lwn.git/commit/?id=4de13d7ed6ffdcbb34317acaa9236f121176f5f8'/>
<id>urn:sha1:4de13d7ed6ffdcbb34317acaa9236f121176f5f8</id>
<content type='text'>
commit 4d5cfcba2f6e ('tipc: fix connection abort during subscription
cancel'), removes the check for a valid subscription before calling
tipc_nametbl_subscribe().

This will lead to a nullptr exception when we process a
subscription cancel request. For a cancel request, a null
subscription is passed to tipc_nametbl_subscribe() resulting
in exception.

In this commit, we call tipc_nametbl_subscribe() only for
a valid subscription.

Fixes: 4d5cfcba2f6e ('tipc: fix connection abort during subscription cancel')
Reported-by: Anders Widell &lt;anders.widell@ericsson.com&gt;
Signed-off-by: Parthasarathy Bhuvaragan &lt;parthasarathy.bhuvaragan@ericsson.com&gt;
Acked-by: Jon Maloy &lt;jon.maloy@ericsson.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>tipc: donot create timers if subscription timeout = TIPC_WAIT_FOREVER</title>
<updated>2016-02-06T08:41:58+00:00</updated>
<author>
<name>Parthasarathy Bhuvaragan</name>
<email>parthasarathy.bhuvaragan@ericsson.com</email>
</author>
<published>2016-02-02T09:52:16+00:00</published>
<link rel='alternate' type='text/html' href='http://mirrors.hust.edu.cn/git/lwn.git/commit/?id=ae245557f87fffe2e1c39ba07524024e650e822b'/>
<id>urn:sha1:ae245557f87fffe2e1c39ba07524024e650e822b</id>
<content type='text'>
Until now, we create timers even for the subscription requests
with timeout = TIPC_WAIT_FOREVER.
This can be improved by avoiding timer creation when the timeout
is set to TIPC_WAIT_FOREVER.

In this commit, we introduce a check to creates timers only
when timeout != TIPC_WAIT_FOREVER.

Acked-by: Ying Xue &lt;ying.xue@windriver.com&gt;
Reviewed-by: Jon Maloy &lt;jon.maloy@ericsson.com&gt;
Signed-off-by: Parthasarathy Bhuvaragan &lt;parthasarathy.bhuvaragan@ericsson.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>tipc: protect tipc_subscrb_get() with subscriber spin lock</title>
<updated>2016-02-06T08:41:58+00:00</updated>
<author>
<name>Parthasarathy Bhuvaragan</name>
<email>parthasarathy.bhuvaragan@ericsson.com</email>
</author>
<published>2016-02-02T09:52:15+00:00</published>
<link rel='alternate' type='text/html' href='http://mirrors.hust.edu.cn/git/lwn.git/commit/?id=f3ad288c56d21e3b8ec77e13ab9aa06dbbfa3577'/>
<id>urn:sha1:f3ad288c56d21e3b8ec77e13ab9aa06dbbfa3577</id>
<content type='text'>
Until now, during subscription creation the mod_time() &amp;
tipc_subscrb_get() are called after releasing the subscriber
spin lock.

In a SMP system when performing a subscription creation, if the
subscription timeout occurs simultaneously (the timer is
scheduled to run on another CPU) then the timer thread
might decrement the subscribers refcount before the create
thread increments the refcount.

This can be simulated by creating subscription with timeout=0 and
sometimes the timeout occurs before the create request is complete.
This leads to the following message:
[30.702949] BUG: spinlock bad magic on CPU#1, kworker/u8:3/87
[30.703834] general protection fault: 0000 [#1] SMP
[30.704826] CPU: 1 PID: 87 Comm: kworker/u8:3 Not tainted 4.4.0-rc8+ #18
[30.704826] Workqueue: tipc_rcv tipc_recv_work [tipc]
[30.704826] task: ffff88003f878600 ti: ffff88003fae0000 task.ti: ffff88003fae0000
[30.704826] RIP: 0010:[&lt;ffffffff8109196c&gt;]  [&lt;ffffffff8109196c&gt;] spin_dump+0x5c/0xe0
[...]
[30.704826] Call Trace:
[30.704826]  [&lt;ffffffff81091a16&gt;] spin_bug+0x26/0x30
[30.704826]  [&lt;ffffffff81091b75&gt;] do_raw_spin_lock+0xe5/0x120
[30.704826]  [&lt;ffffffff81684439&gt;] _raw_spin_lock_bh+0x19/0x20
[30.704826]  [&lt;ffffffffa0096f10&gt;] tipc_subscrb_rcv_cb+0x1d0/0x330 [tipc]
[30.704826]  [&lt;ffffffffa00a37b1&gt;] tipc_receive_from_sock+0xc1/0x150 [tipc]
[30.704826]  [&lt;ffffffffa00a31df&gt;] tipc_recv_work+0x3f/0x80 [tipc]
[30.704826]  [&lt;ffffffff8106a739&gt;] process_one_work+0x149/0x3c0
[30.704826]  [&lt;ffffffff8106aa16&gt;] worker_thread+0x66/0x460
[30.704826]  [&lt;ffffffff8106a9b0&gt;] ? process_one_work+0x3c0/0x3c0
[30.704826]  [&lt;ffffffff8106a9b0&gt;] ? process_one_work+0x3c0/0x3c0
[30.704826]  [&lt;ffffffff8107029d&gt;] kthread+0xed/0x110
[30.704826]  [&lt;ffffffff810701b0&gt;] ? kthread_create_on_node+0x190/0x190
[30.704826]  [&lt;ffffffff81684bdf&gt;] ret_from_fork+0x3f/0x70

In this commit,
1. we remove the check for the return code for mod_timer()
2. we protect tipc_subscrb_get() using the subscriber spin lock.
   We increment the subscriber's refcount as soon as we add the
   subscription to subscriber's subscription list.

Acked-by: Ying Xue &lt;ying.xue@windriver.com&gt;
Reviewed-by: Jon Maloy &lt;jon.maloy@ericsson.com&gt;
Signed-off-by: Parthasarathy Bhuvaragan &lt;parthasarathy.bhuvaragan@ericsson.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>tipc: hold subscriber-&gt;lock for tipc_nametbl_subscribe()</title>
<updated>2016-02-06T08:41:58+00:00</updated>
<author>
<name>Parthasarathy Bhuvaragan</name>
<email>parthasarathy.bhuvaragan@ericsson.com</email>
</author>
<published>2016-02-02T09:52:14+00:00</published>
<link rel='alternate' type='text/html' href='http://mirrors.hust.edu.cn/git/lwn.git/commit/?id=d4091899c9bbfd6695449c6b09517ceb45bb379d'/>
<id>urn:sha1:d4091899c9bbfd6695449c6b09517ceb45bb379d</id>
<content type='text'>
Until now, while creating a subscription the subscriber lock
protects only the subscribers subscription list and not the
nametable. The call to tipc_nametbl_subscribe() is outside
the lock. However, at subscription timeout and cancel both
the subscribers subscription list and the nametable are
protected by the subscriber lock.

This asymmetric locking mechanism leads to the following problem:
In a SMP system, the timer can be fire on another core before
the create request is complete.
When the timer thread calls tipc_nametbl_unsubscribe() before create
thread calls tipc_nametbl_subscribe(), we get a nullptr exception.

This can be simulated by creating subscription with timeout=0 and
sometimes the timeout occurs before the create request is complete.

The following is the oops:
[57.569661] BUG: unable to handle kernel NULL pointer dereference at (null)
[57.577498] IP: [&lt;ffffffffa02135aa&gt;] tipc_nametbl_unsubscribe+0x8a/0x120 [tipc]
[57.584820] PGD 0
[57.586834] Oops: 0002 [#1] SMP
[57.685506] CPU: 14 PID: 10077 Comm: kworker/u40:1 Tainted: P OENX 3.12.48-52.27.1.     9688.1.PTF-default #1
[57.703637] Workqueue: tipc_rcv tipc_recv_work [tipc]
[57.708697] task: ffff88064c7f00c0 ti: ffff880629ef4000 task.ti: ffff880629ef4000
[57.716181] RIP: 0010:[&lt;ffffffffa02135aa&gt;]  [&lt;ffffffffa02135aa&gt;] tipc_nametbl_unsubscribe+0x8a/   0x120 [tipc]
[...]
[57.812327] Call Trace:
[57.814806]  [&lt;ffffffffa0211c77&gt;] tipc_subscrp_delete+0x37/0x90 [tipc]
[57.821357]  [&lt;ffffffffa0211e2f&gt;] tipc_subscrp_timeout+0x3f/0x70 [tipc]
[57.827982]  [&lt;ffffffff810618c1&gt;] call_timer_fn+0x31/0x100
[57.833490]  [&lt;ffffffff81062709&gt;] run_timer_softirq+0x1f9/0x2b0
[57.839414]  [&lt;ffffffff8105a795&gt;] __do_softirq+0xe5/0x230
[57.844827]  [&lt;ffffffff81520d1c&gt;] call_softirq+0x1c/0x30
[57.850150]  [&lt;ffffffff81004665&gt;] do_softirq+0x55/0x90
[57.855285]  [&lt;ffffffff8105aa35&gt;] irq_exit+0x95/0xa0
[57.860290]  [&lt;ffffffff815215b5&gt;] smp_apic_timer_interrupt+0x45/0x60
[57.866644]  [&lt;ffffffff8152005d&gt;] apic_timer_interrupt+0x6d/0x80
[57.872686]  [&lt;ffffffffa02121c5&gt;] tipc_subscrb_rcv_cb+0x2a5/0x3f0 [tipc]
[57.879425]  [&lt;ffffffffa021c65f&gt;] tipc_receive_from_sock+0x9f/0x100 [tipc]
[57.886324]  [&lt;ffffffffa021c826&gt;] tipc_recv_work+0x26/0x60 [tipc]
[57.892463]  [&lt;ffffffff8106fb22&gt;] process_one_work+0x172/0x420
[57.898309]  [&lt;ffffffff8107079a&gt;] worker_thread+0x11a/0x3c0
[57.903871]  [&lt;ffffffff81077114&gt;] kthread+0xb4/0xc0
[57.908751]  [&lt;ffffffff8151f318&gt;] ret_from_fork+0x58/0x90

In this commit, we do the following at subscription creation:
1. set the subscription's subscriber pointer before performing
   tipc_nametbl_subscribe(), as this value is required further in
   the call chain ex: by tipc_subscrp_send_event().
2. move tipc_nametbl_subscribe() under the scope of subscriber lock

Acked-by: Ying Xue &lt;ying.xue@windriver.com&gt;
Reviewed-by: Jon Maloy &lt;jon.maloy@ericsson.com&gt;
Signed-off-by: Parthasarathy Bhuvaragan &lt;parthasarathy.bhuvaragan@ericsson.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>tipc: fix connection abort when receiving invalid cancel request</title>
<updated>2016-02-06T08:41:58+00:00</updated>
<author>
<name>Parthasarathy Bhuvaragan</name>
<email>parthasarathy.bhuvaragan@ericsson.com</email>
</author>
<published>2016-02-02T09:52:13+00:00</published>
<link rel='alternate' type='text/html' href='http://mirrors.hust.edu.cn/git/lwn.git/commit/?id=cb01c7c8701a35866479753fe78d04bd9826dd1b'/>
<id>urn:sha1:cb01c7c8701a35866479753fe78d04bd9826dd1b</id>
<content type='text'>
Until now, the subscribers endianness for a subscription
create/cancel request is determined as:
    swap = !(s-&gt;filter &amp; (TIPC_SUB_PORTS | TIPC_SUB_SERVICE))
The checks are performed only for port/service subscriptions.

The swap calculation is incorrect if the filter in the subscription
cancellation request is set to TIPC_SUB_CANCEL (it's a malformed
cancel request, as the corresponding subscription create filter
is missing).
Thus, the check if the request is for cancellation fails and the
request is treated as a subscription create request. The
subscription creation fails as the request is illegal, which
terminates this connection.

In this commit we determine the endianness by including
TIPC_SUB_CANCEL, which will set swap correctly and the
request is processed as a cancellation request.

Acked-by: Ying Xue &lt;ying.xue@windriver.com&gt;
Reviewed-by: Jon Maloy &lt;jon.maloy@ericsson.com&gt;
Signed-off-by: Parthasarathy Bhuvaragan &lt;parthasarathy.bhuvaragan@ericsson.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>tipc: fix connection abort during subscription cancellation</title>
<updated>2016-02-06T08:41:58+00:00</updated>
<author>
<name>Parthasarathy Bhuvaragan</name>
<email>parthasarathy.bhuvaragan@ericsson.com</email>
</author>
<published>2016-02-02T09:52:12+00:00</published>
<link rel='alternate' type='text/html' href='http://mirrors.hust.edu.cn/git/lwn.git/commit/?id=c8beccc67c833db4a01c621cbc6eb0a577286806'/>
<id>urn:sha1:c8beccc67c833db4a01c621cbc6eb0a577286806</id>
<content type='text'>
In 'commit 7fe8097cef5f ("tipc: fix nullpointer bug when subscribing
to events")', we terminate the connection if the subscription
creation fails.
In the same commit, the subscription creation result was based on
the value of subscription pointer (set in the function) instead of
the return code.

Unfortunately, the same function also handles subscription
cancellation request. For a subscription cancellation request,
the subscription pointer cannot be set. Thus the connection is
terminated during cancellation request.

In this commit, we move the subcription cancel check outside
of tipc_subscrp_create(). Hence,
- tipc_subscrp_create() will create a subscripton
- tipc_subscrb_rcv_cb() will subscribe or cancel a subscription.

Fixes: 'commit 7fe8097cef5f ("tipc: fix nullpointer bug when subscribing to events")'

Acked-by: Ying Xue &lt;ying.xue@windriver.com&gt;
Reviewed-by: Jon Maloy &lt;jon.maloy@ericsson.com&gt;
Signed-off-by: Parthasarathy Bhuvaragan &lt;parthasarathy.bhuvaragan@ericsson.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>tipc: introduce tipc_subscrb_subscribe() routine</title>
<updated>2016-02-06T08:41:57+00:00</updated>
<author>
<name>Parthasarathy Bhuvaragan</name>
<email>parthasarathy.bhuvaragan@ericsson.com</email>
</author>
<published>2016-02-02T09:52:11+00:00</published>
<link rel='alternate' type='text/html' href='http://mirrors.hust.edu.cn/git/lwn.git/commit/?id=7c13c6224123a6424bd3bc60ef982759754501e9'/>
<id>urn:sha1:7c13c6224123a6424bd3bc60ef982759754501e9</id>
<content type='text'>
In this commit, we split tipc_subscrp_create() into two:
1. tipc_subscrp_create() creates a subscription
2. A new function tipc_subscrp_subscribe() adds the
   subscription to the subscriber subscription list,
   activates the subscription timer and subscribes to
   the nametable updates.

In future commits, the purpose of tipc_subscrb_rcv_cb() will
be to either subscribe or cancel a subscription.

There is no functional change in this commit.

Acked-by: Ying Xue &lt;ying.xue@windriver.com&gt;
Reviewed-by: Jon Maloy &lt;jon.maloy@ericsson.com&gt;
Signed-off-by: Parthasarathy Bhuvaragan &lt;parthasarathy.bhuvaragan@ericsson.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
</feed>
