Skip to content

Commit dcd998c

Browse files
kapatilNicholas Bellinger
authored andcommitted
tcm_fc: Handle DDP/SW fc_frame_payload_get failures in ft_recv_write_data
Problem: HW DDP context was not invalidated in case of ABORTS, etc... This leads to the problem where memory pages which are used for DDP as user descriptor could get reused for some other purpose (such as to satisfy new memory allocation request either by kernel or user mode threads) and since HW DDP context was not invalidated, HW continue to write to those pages, hence causing memory corruption. Fix: Either on incoming ABORTS or due to exchange time out, allowed the target to cleanup HW DDP context if it was setup for respective ft_cmd. Added new function to perform this cleanup, furthur it can be enhanced for other cleanup activity. Fix ft_recv_write_data() to properly handle fc_frame_payload_get to return pointer to payload if it exist. If there is no payload which is most common case (+ve case in case if DDP is working as expected, it will return NULL. Yes, scope of buf is limited to printk. Invalidation of HW context (which is done inside ft_invl_hw_context() is necessary in SUCCESS and FAILURE case of DDP. Hence invalidation is DONE as long as there was DDP setup (whether it worked correctly or not, NOTE: For some reason, if there is any error w.r.t DDP such as out of order packet reception, HW simply post the full packet in rx queue. Signed-off-by: Kiran Patil <kiran.patil@intel.com> Cc: Robert W Love <robert.w.love@intel.com> Signed-off-by: Nicholas A. Bellinger <nab@linux-iscsi.org>
1 parent dd8ae59 commit dcd998c

3 files changed

Lines changed: 78 additions & 49 deletions

File tree

‎drivers/target/tcm_fc/tcm_fc.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,9 @@ void ft_dump_cmd(struct ft_cmd *, const char *caller);
187187

188188
ssize_t ft_format_wwn(char *, size_t, u64);
189189

190+
/*
191+
* Underlying HW specific helper function
192+
*/
193+
void ft_invl_hw_context(struct ft_cmd *);
194+
190195
#endif /* __TCM_FC_H__ */

‎drivers/target/tcm_fc/tfc_cmd.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ static void ft_recv_seq(struct fc_seq *sp, struct fc_frame *fp, void *arg)
320320
default:
321321
pr_debug("%s: unhandled frame r_ctl %x\n",
322322
__func__, fh->fh_r_ctl);
323+
ft_invl_hw_context(cmd);
323324
fc_frame_free(fp);
324325
transport_generic_free_cmd(&cmd->se_cmd, 0, 0);
325326
break;

‎drivers/target/tcm_fc/tfc_io.c‎

Lines changed: 72 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -214,62 +214,49 @@ void ft_recv_write_data(struct ft_cmd *cmd, struct fc_frame *fp)
214214
if (!(ntoh24(fh->fh_f_ctl) & FC_FC_REL_OFF))
215215
goto drop;
216216

217+
f_ctl = ntoh24(fh->fh_f_ctl);
218+
ep = fc_seq_exch(seq);
219+
lport = ep->lp;
220+
if (cmd->was_ddp_setup) {
221+
BUG_ON(!ep);
222+
BUG_ON(!lport);
223+
}
224+
217225
/*
218-
* Doesn't expect even single byte of payload. Payload
226+
* Doesn't expect payload if DDP is setup. Payload
219227
* is expected to be copied directly to user buffers
220-
* due to DDP (Large Rx offload) feature, hence
221-
* BUG_ON if BUF is non-NULL
228+
* due to DDP (Large Rx offload),
222229
*/
223230
buf = fc_frame_payload_get(fp, 1);
224-
if (cmd->was_ddp_setup && buf) {
225-
pr_debug("%s: When DDP was setup, not expected to"
226-
"receive frame with payload, Payload shall be"
227-
"copied directly to buffer instead of coming "
228-
"via. legacy receive queues\n", __func__);
229-
BUG_ON(buf);
230-
}
231+
if (buf)
232+
pr_err("%s: xid 0x%x, f_ctl 0x%x, cmd->sg %p, "
233+
"cmd->sg_cnt 0x%x. DDP was setup"
234+
" hence not expected to receive frame with "
235+
"payload, Frame will be dropped if "
236+
"'Sequence Initiative' bit in f_ctl is "
237+
"not set\n", __func__, ep->xid, f_ctl,
238+
cmd->sg, cmd->sg_cnt);
239+
/*
240+
* Invalidate HW DDP context if it was setup for respective
241+
* command. Invalidation of HW DDP context is requited in both
242+
* situation (success and error).
243+
*/
244+
ft_invl_hw_context(cmd);
231245

232246
/*
233-
* If ft_cmd indicated 'ddp_setup', in that case only the last frame
234-
* should come with 'TSI bit being set'. If 'TSI bit is not set and if
235-
* data frame appears here, means error condition. In both the cases
236-
* release the DDP context (ddp_put) and in error case, as well
237-
* initiate error recovery mechanism.
247+
* If "Sequence Initiative (TSI)" bit set in f_ctl, means last
248+
* write data frame is received successfully where payload is
249+
* posted directly to user buffer and only the last frame's
250+
* header is posted in receive queue.
251+
*
252+
* If "Sequence Initiative (TSI)" bit is not set, means error
253+
* condition w.r.t. DDP, hence drop the packet and let explict
254+
* ABORTS from other end of exchange timer trigger the recovery.
238255
*/
239-
ep = fc_seq_exch(seq);
240-
if (cmd->was_ddp_setup) {
241-
BUG_ON(!ep);
242-
lport = ep->lp;
243-
BUG_ON(!lport);
244-
}
245-
if (cmd->was_ddp_setup && ep->xid != FC_XID_UNKNOWN) {
246-
f_ctl = ntoh24(fh->fh_f_ctl);
247-
/*
248-
* If TSI bit set in f_ctl, means last write data frame is
249-
* received successfully where payload is posted directly
250-
* to user buffer and only the last frame's header is posted
251-
* in legacy receive queue
252-
*/
253-
if (f_ctl & FC_FC_SEQ_INIT) { /* TSI bit set in FC frame */
254-
cmd->write_data_len = lport->tt.ddp_done(lport,
255-
ep->xid);
256-
goto last_frame;
257-
} else {
258-
/*
259-
* Updating the write_data_len may be meaningless at
260-
* this point, but just in case if required in future
261-
* for debugging or any other purpose
262-
*/
263-
pr_err("%s: Received frame with TSI bit not"
264-
" being SET, dropping the frame, "
265-
"cmd->sg <%p>, cmd->sg_cnt <0x%x>\n",
266-
__func__, cmd->sg, cmd->sg_cnt);
267-
cmd->write_data_len = lport->tt.ddp_done(lport,
268-
ep->xid);
269-
lport->tt.seq_exch_abort(cmd->seq, 0);
270-
goto drop;
271-
}
272-
}
256+
if (f_ctl & FC_FC_SEQ_INIT)
257+
goto last_frame;
258+
else
259+
goto drop;
273260

274261
rel_off = ntohl(fh->fh_parm_offset);
275262
frame_len = fr_len(fp);
@@ -332,3 +319,39 @@ void ft_recv_write_data(struct ft_cmd *cmd, struct fc_frame *fp)
332319
drop:
333320
fc_frame_free(fp);
334321
}
322+
323+
/*
324+
* Handle and cleanup any HW specific resources if
325+
* received ABORTS, errors, timeouts.
326+
*/
327+
void ft_invl_hw_context(struct ft_cmd *cmd)
328+
{
329+
struct fc_seq *seq = cmd->seq;
330+
struct fc_exch *ep = NULL;
331+
struct fc_lport *lport = NULL;
332+
333+
BUG_ON(!cmd);
334+
335+
/* Cleanup the DDP context in HW if DDP was setup */
336+
if (cmd->was_ddp_setup && seq) {
337+
ep = fc_seq_exch(seq);
338+
if (ep) {
339+
lport = ep->lp;
340+
if (lport && (ep->xid <= lport->lro_xid))
341+
/*
342+
* "ddp_done" trigger invalidation of HW
343+
* specific DDP context
344+
*/
345+
cmd->write_data_len = lport->tt.ddp_done(lport,
346+
ep->xid);
347+
348+
/*
349+
* Resetting same variable to indicate HW's
350+
* DDP context has been invalidated to avoid
351+
* re_invalidation of same context (context is
352+
* identified using ep->xid)
353+
*/
354+
cmd->was_ddp_setup = 0;
355+
}
356+
}
357+
}

0 commit comments

Comments
 (0)