Skip to content

Commit a9e4e6e

Browse files
committed
Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending
* 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending: tcm_fc: Handle DDP/SW fc_frame_payload_get failures in ft_recv_write_data target: Fix bug for transport_generic_wait_for_tasks with direct operation target: iscsi_target depends on NET target: Fix WRITE_SAME_16 lba assignment breakage MAINTAINERS: Add target-devel list for drivers/target/ iscsi-target: Fix CONFIG_SMP=n and CONFIG_MODULES=n build failure iscsi-target: Fix snprintf usage with MAX_PORTAL_LEN iscsi-target: Fix uninitialized usage of cmd->pad_bytes iscsi-target: strlen() doesn't count the terminator iscsi-target: Fix NULL dereference on allocation failure
2 parents 27665ff + dcd998c commit a9e4e6e

9 files changed

Lines changed: 122 additions & 59 deletions

File tree

‎MAINTAINERS‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6319,6 +6319,7 @@ F: include/linux/sysv_fs.h
63196319
TARGET SUBSYSTEM
63206320
M: Nicholas A. Bellinger <nab@linux-iscsi.org>
63216321
L: linux-scsi@vger.kernel.org
6322+
L: target-devel@vger.kernel.org
63226323
L: http://groups.google.com/group/linux-iscsi-target-dev
63236324
W: http://www.linux-iscsi.org
63246325
T: git git://git.kernel.org/pub/scm/linux/kernel/git/nab/lio-core-2.6.git master

‎drivers/target/iscsi/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
config ISCSI_TARGET
22
tristate "Linux-iSCSI.org iSCSI Target Mode Stack"
3+
depends on NET
34
select CRYPTO
45
select CRYPTO_CRC32C
56
select CRYPTO_CRC32C_INTEL if X86

‎drivers/target/iscsi/iscsi_target.c‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ struct iscsi_tiqn *iscsit_add_tiqn(unsigned char *buf)
120120
struct iscsi_tiqn *tiqn = NULL;
121121
int ret;
122122

123-
if (strlen(buf) > ISCSI_IQN_LEN) {
123+
if (strlen(buf) >= ISCSI_IQN_LEN) {
124124
pr_err("Target IQN exceeds %d bytes\n",
125125
ISCSI_IQN_LEN);
126126
return ERR_PTR(-EINVAL);
@@ -1857,7 +1857,7 @@ static int iscsit_handle_text_cmd(
18571857
char *text_ptr, *text_in;
18581858
int cmdsn_ret, niov = 0, rx_got, rx_size;
18591859
u32 checksum = 0, data_crc = 0, payload_length;
1860-
u32 padding = 0, text_length = 0;
1860+
u32 padding = 0, pad_bytes = 0, text_length = 0;
18611861
struct iscsi_cmd *cmd;
18621862
struct kvec iov[3];
18631863
struct iscsi_text *hdr;
@@ -1896,7 +1896,7 @@ static int iscsit_handle_text_cmd(
18961896

18971897
padding = ((-payload_length) & 3);
18981898
if (padding != 0) {
1899-
iov[niov].iov_base = cmd->pad_bytes;
1899+
iov[niov].iov_base = &pad_bytes;
19001900
iov[niov++].iov_len = padding;
19011901
rx_size += padding;
19021902
pr_debug("Receiving %u additional bytes"
@@ -1917,7 +1917,7 @@ static int iscsit_handle_text_cmd(
19171917
if (conn->conn_ops->DataDigest) {
19181918
iscsit_do_crypto_hash_buf(&conn->conn_rx_hash,
19191919
text_in, text_length,
1920-
padding, cmd->pad_bytes,
1920+
padding, (u8 *)&pad_bytes,
19211921
(u8 *)&data_crc);
19221922

19231923
if (checksum != data_crc) {
@@ -3468,7 +3468,12 @@ static inline void iscsit_thread_check_cpumask(
34683468
}
34693469

34703470
#else
3471-
#define iscsit_thread_get_cpumask(X) ({})
3471+
3472+
void iscsit_thread_get_cpumask(struct iscsi_conn *conn)
3473+
{
3474+
return;
3475+
}
3476+
34723477
#define iscsit_thread_check_cpumask(X, Y, Z) ({})
34733478
#endif /* CONFIG_SMP */
34743479

‎drivers/target/iscsi/iscsi_target_configfs.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ struct se_tpg_np *lio_target_call_addnptotpg(
181181
return ERR_PTR(-EOVERFLOW);
182182
}
183183
memset(buf, 0, MAX_PORTAL_LEN + 1);
184-
snprintf(buf, MAX_PORTAL_LEN, "%s", name);
184+
snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name);
185185

186186
memset(&sockaddr, 0, sizeof(struct __kernel_sockaddr_storage));
187187

‎drivers/target/iscsi/iscsi_target_nego.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ struct iscsi_login *iscsi_target_init_negotiation(
978978
pr_err("Unable to allocate memory for struct iscsi_login.\n");
979979
iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
980980
ISCSI_LOGIN_STATUS_NO_RESOURCES);
981-
goto out;
981+
return NULL;
982982
}
983983

984984
login->req = kzalloc(ISCSI_HDR_LEN, GFP_KERNEL);

‎drivers/target/target_core_transport.c‎

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,13 +1747,17 @@ int transport_generic_handle_cdb(
17471747
}
17481748
EXPORT_SYMBOL(transport_generic_handle_cdb);
17491749

1750+
static void transport_generic_request_failure(struct se_cmd *,
1751+
struct se_device *, int, int);
17501752
/*
17511753
* Used by fabric module frontends to queue tasks directly.
17521754
* Many only be used from process context only
17531755
*/
17541756
int transport_handle_cdb_direct(
17551757
struct se_cmd *cmd)
17561758
{
1759+
int ret;
1760+
17571761
if (!cmd->se_lun) {
17581762
dump_stack();
17591763
pr_err("cmd->se_lun is NULL\n");
@@ -1765,8 +1769,31 @@ int transport_handle_cdb_direct(
17651769
" from interrupt context\n");
17661770
return -EINVAL;
17671771
}
1768-
1769-
return transport_generic_new_cmd(cmd);
1772+
/*
1773+
* Set TRANSPORT_NEW_CMD state and cmd->t_transport_active=1 following
1774+
* transport_generic_handle_cdb*() -> transport_add_cmd_to_queue()
1775+
* in existing usage to ensure that outstanding descriptors are handled
1776+
* correctly during shutdown via transport_generic_wait_for_tasks()
1777+
*
1778+
* Also, we don't take cmd->t_state_lock here as we only expect
1779+
* this to be called for initial descriptor submission.
1780+
*/
1781+
cmd->t_state = TRANSPORT_NEW_CMD;
1782+
atomic_set(&cmd->t_transport_active, 1);
1783+
/*
1784+
* transport_generic_new_cmd() is already handling QUEUE_FULL,
1785+
* so follow TRANSPORT_NEW_CMD processing thread context usage
1786+
* and call transport_generic_request_failure() if necessary..
1787+
*/
1788+
ret = transport_generic_new_cmd(cmd);
1789+
if (ret == -EAGAIN)
1790+
return 0;
1791+
else if (ret < 0) {
1792+
cmd->transport_error_status = ret;
1793+
transport_generic_request_failure(cmd, NULL, 0,
1794+
(cmd->data_direction != DMA_TO_DEVICE));
1795+
}
1796+
return 0;
17701797
}
17711798
EXPORT_SYMBOL(transport_handle_cdb_direct);
17721799

@@ -3324,7 +3351,7 @@ static int transport_generic_cmd_sequencer(
33243351
goto out_invalid_cdb_field;
33253352
}
33263353

3327-
cmd->t_task_lba = get_unaligned_be16(&cdb[2]);
3354+
cmd->t_task_lba = get_unaligned_be64(&cdb[2]);
33283355
passthrough = (dev->transport->transport_type ==
33293356
TRANSPORT_PLUGIN_PHBA_PDEV);
33303357
/*

‎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
@@ -213,62 +213,49 @@ void ft_recv_write_data(struct ft_cmd *cmd, struct fc_frame *fp)
213213
if (!(ntoh24(fh->fh_f_ctl) & FC_FC_REL_OFF))
214214
goto drop;
215215

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

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

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

0 commit comments

Comments
 (0)