Skip to content

Commit ae67bd3

Browse files
trondmyamschuma-ntap
authored andcommitted
SUNRPC: Fix up task signalling
The RPC_TASK_KILLED flag should really not be set from another context because it can clobber data in the struct task when task->tk_flags is changed non-atomically. Let's therefore swap out RPC_TASK_KILLED with an atomic flag, and add a function to set that flag and safely wake up the task. Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
1 parent 085b775 commit ae67bd3

7 files changed

Lines changed: 40 additions & 26 deletions

File tree

‎fs/lockd/clntproc.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ static void nlmclnt_unlock_callback(struct rpc_task *task, void *data)
715715
struct nlm_rqst *req = data;
716716
u32 status = ntohl(req->a_res.status);
717717

718-
if (RPC_ASSASSINATED(task))
718+
if (RPC_SIGNALLED(task))
719719
goto die;
720720

721721
if (task->tk_status < 0) {
@@ -783,7 +783,7 @@ static void nlmclnt_cancel_callback(struct rpc_task *task, void *data)
783783
struct nlm_rqst *req = data;
784784
u32 status = ntohl(req->a_res.status);
785785

786-
if (RPC_ASSASSINATED(task))
786+
if (RPC_SIGNALLED(task))
787787
goto die;
788788

789789
if (task->tk_status < 0) {

‎fs/nfsd/nfs4callback.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ static bool nfsd4_cb_sequence_done(struct rpc_task *task, struct nfsd4_callback
10321032
* the submission code will error out, so we don't need to
10331033
* handle that case here.
10341034
*/
1035-
if (task->tk_flags & RPC_TASK_KILLED)
1035+
if (RPC_SIGNALLED(task))
10361036
goto need_restart;
10371037

10381038
return true;
@@ -1081,7 +1081,7 @@ static bool nfsd4_cb_sequence_done(struct rpc_task *task, struct nfsd4_callback
10811081
dprintk("%s: freed slot, new seqid=%d\n", __func__,
10821082
clp->cl_cb_session->se_cb_seq_nr);
10831083

1084-
if (task->tk_flags & RPC_TASK_KILLED)
1084+
if (RPC_SIGNALLED(task))
10851085
goto need_restart;
10861086
out:
10871087
return ret;

‎include/linux/sunrpc/sched.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ struct rpc_task_setup {
125125
#define RPC_CALL_MAJORSEEN 0x0020 /* major timeout seen */
126126
#define RPC_TASK_ROOTCREDS 0x0040 /* force root creds */
127127
#define RPC_TASK_DYNAMIC 0x0080 /* task was kmalloc'ed */
128-
#define RPC_TASK_KILLED 0x0100 /* task was killed */
129128
#define RPC_TASK_SOFT 0x0200 /* Use soft timeouts */
130129
#define RPC_TASK_SOFTCONN 0x0400 /* Fail if can't connect */
131130
#define RPC_TASK_SENT 0x0800 /* message was sent */
@@ -135,7 +134,6 @@ struct rpc_task_setup {
135134

136135
#define RPC_IS_ASYNC(t) ((t)->tk_flags & RPC_TASK_ASYNC)
137136
#define RPC_IS_SWAPPER(t) ((t)->tk_flags & RPC_TASK_SWAPPER)
138-
#define RPC_ASSASSINATED(t) ((t)->tk_flags & RPC_TASK_KILLED)
139137
#define RPC_IS_SOFT(t) ((t)->tk_flags & (RPC_TASK_SOFT|RPC_TASK_TIMEOUT))
140138
#define RPC_IS_SOFTCONN(t) ((t)->tk_flags & RPC_TASK_SOFTCONN)
141139
#define RPC_WAS_SENT(t) ((t)->tk_flags & RPC_TASK_SENT)
@@ -146,6 +144,7 @@ struct rpc_task_setup {
146144
#define RPC_TASK_NEED_XMIT 3
147145
#define RPC_TASK_NEED_RECV 4
148146
#define RPC_TASK_MSG_PIN_WAIT 5
147+
#define RPC_TASK_SIGNALLED 6
149148

150149
#define RPC_IS_RUNNING(t) test_bit(RPC_TASK_RUNNING, &(t)->tk_runstate)
151150
#define rpc_set_running(t) set_bit(RPC_TASK_RUNNING, &(t)->tk_runstate)
@@ -169,6 +168,8 @@ struct rpc_task_setup {
169168

170169
#define RPC_IS_ACTIVATED(t) test_bit(RPC_TASK_ACTIVE, &(t)->tk_runstate)
171170

171+
#define RPC_SIGNALLED(t) test_bit(RPC_TASK_SIGNALLED, &(t)->tk_runstate)
172+
172173
/*
173174
* Task priorities.
174175
* Note: if you change these, you must also change
@@ -217,6 +218,7 @@ struct rpc_task *rpc_run_task(const struct rpc_task_setup *);
217218
struct rpc_task *rpc_run_bc_task(struct rpc_rqst *req);
218219
void rpc_put_task(struct rpc_task *);
219220
void rpc_put_task_async(struct rpc_task *);
221+
void rpc_signal_task(struct rpc_task *);
220222
void rpc_exit_task(struct rpc_task *);
221223
void rpc_exit(struct rpc_task *, int);
222224
void rpc_release_calldata(const struct rpc_call_ops *, void *);

‎include/trace/events/sunrpc.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ TRACE_DEFINE_ENUM(RPC_TASK_SWAPPER);
8282
TRACE_DEFINE_ENUM(RPC_CALL_MAJORSEEN);
8383
TRACE_DEFINE_ENUM(RPC_TASK_ROOTCREDS);
8484
TRACE_DEFINE_ENUM(RPC_TASK_DYNAMIC);
85-
TRACE_DEFINE_ENUM(RPC_TASK_KILLED);
8685
TRACE_DEFINE_ENUM(RPC_TASK_SOFT);
8786
TRACE_DEFINE_ENUM(RPC_TASK_SOFTCONN);
8887
TRACE_DEFINE_ENUM(RPC_TASK_SENT);
@@ -97,7 +96,6 @@ TRACE_DEFINE_ENUM(RPC_TASK_NO_RETRANS_TIMEOUT);
9796
{ RPC_CALL_MAJORSEEN, "MAJORSEEN" }, \
9897
{ RPC_TASK_ROOTCREDS, "ROOTCREDS" }, \
9998
{ RPC_TASK_DYNAMIC, "DYNAMIC" }, \
100-
{ RPC_TASK_KILLED, "KILLED" }, \
10199
{ RPC_TASK_SOFT, "SOFT" }, \
102100
{ RPC_TASK_SOFTCONN, "SOFTCONN" }, \
103101
{ RPC_TASK_SENT, "SENT" }, \
@@ -111,6 +109,7 @@ TRACE_DEFINE_ENUM(RPC_TASK_ACTIVE);
111109
TRACE_DEFINE_ENUM(RPC_TASK_NEED_XMIT);
112110
TRACE_DEFINE_ENUM(RPC_TASK_NEED_RECV);
113111
TRACE_DEFINE_ENUM(RPC_TASK_MSG_PIN_WAIT);
112+
TRACE_DEFINE_ENUM(RPC_TASK_SIGNALLED);
114113

115114
#define rpc_show_runstate(flags) \
116115
__print_flags(flags, "|", \
@@ -119,7 +118,8 @@ TRACE_DEFINE_ENUM(RPC_TASK_MSG_PIN_WAIT);
119118
{ (1UL << RPC_TASK_ACTIVE), "ACTIVE" }, \
120119
{ (1UL << RPC_TASK_NEED_XMIT), "NEED_XMIT" }, \
121120
{ (1UL << RPC_TASK_NEED_RECV), "NEED_RECV" }, \
122-
{ (1UL << RPC_TASK_MSG_PIN_WAIT), "MSG_PIN_WAIT" })
121+
{ (1UL << RPC_TASK_MSG_PIN_WAIT), "MSG_PIN_WAIT" }, \
122+
{ (1UL << RPC_TASK_SIGNALLED), "SIGNALLED" })
123123

124124
DECLARE_EVENT_CLASS(rpc_task_running,
125125

‎net/sunrpc/clnt.c‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -827,14 +827,8 @@ void rpc_killall_tasks(struct rpc_clnt *clnt)
827827
* Spin lock all_tasks to prevent changes...
828828
*/
829829
spin_lock(&clnt->cl_lock);
830-
list_for_each_entry(rovr, &clnt->cl_tasks, tk_task) {
831-
if (!RPC_IS_ACTIVATED(rovr))
832-
continue;
833-
if (!(rovr->tk_flags & RPC_TASK_KILLED)) {
834-
rovr->tk_flags |= RPC_TASK_KILLED;
835-
rpc_exit(rovr, -EIO);
836-
}
837-
}
830+
list_for_each_entry(rovr, &clnt->cl_tasks, tk_task)
831+
rpc_signal_task(rovr);
838832
spin_unlock(&clnt->cl_lock);
839833
}
840834
EXPORT_SYMBOL_GPL(rpc_killall_tasks);
@@ -1477,8 +1471,6 @@ EXPORT_SYMBOL_GPL(rpc_force_rebind);
14771471
int
14781472
rpc_restart_call_prepare(struct rpc_task *task)
14791473
{
1480-
if (RPC_ASSASSINATED(task))
1481-
return 0;
14821474
task->tk_action = call_start;
14831475
task->tk_status = 0;
14841476
if (task->tk_ops->rpc_call_prepare != NULL)
@@ -1494,8 +1486,6 @@ EXPORT_SYMBOL_GPL(rpc_restart_call_prepare);
14941486
int
14951487
rpc_restart_call(struct rpc_task *task)
14961488
{
1497-
if (RPC_ASSASSINATED(task))
1498-
return 0;
14991489
task->tk_action = call_start;
15001490
task->tk_status = 0;
15011491
return 1;

‎net/sunrpc/sched.c‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -759,8 +759,7 @@ static void
759759
rpc_reset_task_statistics(struct rpc_task *task)
760760
{
761761
task->tk_timeouts = 0;
762-
task->tk_flags &= ~(RPC_CALL_MAJORSEEN|RPC_TASK_KILLED|RPC_TASK_SENT);
763-
762+
task->tk_flags &= ~(RPC_CALL_MAJORSEEN|RPC_TASK_SENT);
764763
rpc_init_task_statistics(task);
765764
}
766765

@@ -773,14 +772,26 @@ void rpc_exit_task(struct rpc_task *task)
773772
if (task->tk_ops->rpc_call_done != NULL) {
774773
task->tk_ops->rpc_call_done(task, task->tk_calldata);
775774
if (task->tk_action != NULL) {
776-
WARN_ON(RPC_ASSASSINATED(task));
777775
/* Always release the RPC slot and buffer memory */
778776
xprt_release(task);
779777
rpc_reset_task_statistics(task);
780778
}
781779
}
782780
}
783781

782+
void rpc_signal_task(struct rpc_task *task)
783+
{
784+
struct rpc_wait_queue *queue;
785+
786+
if (!RPC_IS_ACTIVATED(task))
787+
return;
788+
set_bit(RPC_TASK_SIGNALLED, &task->tk_runstate);
789+
smp_mb__after_atomic();
790+
queue = READ_ONCE(task->tk_waitqueue);
791+
if (queue)
792+
rpc_wake_up_queued_task_set_status(queue, task, -ERESTARTSYS);
793+
}
794+
784795
void rpc_exit(struct rpc_task *task, int status)
785796
{
786797
task->tk_status = status;
@@ -836,6 +847,13 @@ static void __rpc_execute(struct rpc_task *task)
836847
*/
837848
if (!RPC_IS_QUEUED(task))
838849
continue;
850+
851+
/*
852+
* Signalled tasks should exit rather than sleep.
853+
*/
854+
if (RPC_SIGNALLED(task))
855+
rpc_exit(task, -ERESTARTSYS);
856+
839857
/*
840858
* The queue->lock protects against races with
841859
* rpc_make_runnable().
@@ -861,15 +879,15 @@ static void __rpc_execute(struct rpc_task *task)
861879
status = out_of_line_wait_on_bit(&task->tk_runstate,
862880
RPC_TASK_QUEUED, rpc_wait_bit_killable,
863881
TASK_KILLABLE);
864-
if (status == -ERESTARTSYS) {
882+
if (status < 0) {
865883
/*
866884
* When a sync task receives a signal, it exits with
867885
* -ERESTARTSYS. In order to catch any callbacks that
868886
* clean up after sleeping on some queue, we don't
869887
* break the loop here, but go around once more.
870888
*/
871889
dprintk("RPC: %5u got signal\n", task->tk_pid);
872-
task->tk_flags |= RPC_TASK_KILLED;
890+
set_bit(RPC_TASK_SIGNALLED, &task->tk_runstate);
873891
rpc_exit(task, -ERESTARTSYS);
874892
}
875893
dprintk("RPC: %5u sync task resuming\n", task->tk_pid);

‎net/sunrpc/xprt.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,10 @@ xprt_request_transmit(struct rpc_rqst *req, struct rpc_task *snd_task)
13371337
if (status < 0)
13381338
goto out_dequeue;
13391339
}
1340+
if (RPC_SIGNALLED(task)) {
1341+
status = -ERESTARTSYS;
1342+
goto out_dequeue;
1343+
}
13401344
}
13411345

13421346
/*

0 commit comments

Comments
 (0)