public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: "oe-kbuild@lists.linux.dev" <oe-kbuild@lists.linux.dev>,
	Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	"lkp@intel.com" <lkp@intel.com>,
	"oe-kbuild-all@lists.linux.dev" <oe-kbuild-all@lists.linux.dev>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	Homura Akemi <a1134123566@gmail.com>
Subject: Re: [PATCH v3 24/28] usb: gadget: f_tcm: Check overlapped command
Date: Fri, 20 Dec 2024 02:31:20 +0000	[thread overview]
Message-ID: <20241220023105.ruvvhqbzd3m37ce4@synopsys.com> (raw)
In-Reply-To: <d9f6af01-7a20-45aa-b6f1-380711aaec92@stanley.mountain>

On Thu, Dec 19, 2024, Dan Carpenter wrote:
> Hi Thinh,
> 
> kernel test robot noticed the following build warnings:
> 
> url:    https://urldefense.com/v3/__https://github.com/intel-lab-lkp/linux/commits/Thinh-Nguyen/usb-gadget-f_tcm-Don-t-free-command-immediately/20241211-092317__;!!A4F2R9G_pg!YKeQa8JmJaKHAak1XzUO0sLWgipnVS9vCGr4PiZb8TEMwYAnaMG4XVSZ3aeoCV-54D_6YX6ylxj93-NYCMU04FiCU0xX$ 
> base:   d8d936c51388442f769a81e512b505dcf87c6a51
> patch link:    https://urldefense.com/v3/__https://lore.kernel.org/r/6bffc2903d0cd1e7c7afca837053a48e883d8903.1733876548.git.Thinh.Nguyen*40synopsys.com__;JQ!!A4F2R9G_pg!YKeQa8JmJaKHAak1XzUO0sLWgipnVS9vCGr4PiZb8TEMwYAnaMG4XVSZ3aeoCV-54D_6YX6ylxj93-NYCMU04BGCyVAg$ 
> patch subject: [PATCH v3 24/28] usb: gadget: f_tcm: Check overlapped command
> config: nios2-randconfig-r071-20241219 (https://urldefense.com/v3/__https://download.01.org/0day-ci/archive/20241219/202412192132.XB16SilM-lkp@intel.com/config__;!!A4F2R9G_pg!YKeQa8JmJaKHAak1XzUO0sLWgipnVS9vCGr4PiZb8TEMwYAnaMG4XVSZ3aeoCV-54D_6YX6ylxj93-NYCMU04JujRj-r$ )
> compiler: nios2-linux-gcc (GCC) 14.2.0
> 
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> | Closes: https://urldefense.com/v3/__https://lore.kernel.org/r/202412192132.XB16SilM-lkp@intel.com/__;!!A4F2R9G_pg!YKeQa8JmJaKHAak1XzUO0sLWgipnVS9vCGr4PiZb8TEMwYAnaMG4XVSZ3aeoCV-54D_6YX6ylxj93-NYCMU04FWUkKjj$ 
> 
> smatch warnings:
> drivers/usb/gadget/function/f_tcm.c:1308 usbg_cmd_work() error: we previously assumed 'active_cmd' could be null (see line 1265)
> 
> vim +/active_cmd +1308 drivers/usb/gadget/function/f_tcm.c
> 
> 287b3d115e5351 Thinh Nguyen          2024-12-11  1227  static void usbg_cmd_work(struct work_struct *work)
> 287b3d115e5351 Thinh Nguyen          2024-12-11  1228  {
> 287b3d115e5351 Thinh Nguyen          2024-12-11  1229  	struct usbg_cmd *cmd = container_of(work, struct usbg_cmd, work);
> 287b3d115e5351 Thinh Nguyen          2024-12-11  1230  
> 287b3d115e5351 Thinh Nguyen          2024-12-11  1231  	/*
> 287b3d115e5351 Thinh Nguyen          2024-12-11  1232  	 * Failure is detected by f_tcm here. Skip submitting the command to the
> 287b3d115e5351 Thinh Nguyen          2024-12-11  1233  	 * target core if we already know the failing response and send the usb
> 287b3d115e5351 Thinh Nguyen          2024-12-11  1234  	 * response to the host directly.
> 287b3d115e5351 Thinh Nguyen          2024-12-11  1235  	 */
> 287b3d115e5351 Thinh Nguyen          2024-12-11  1236  	if (cmd->tmr_rsp != RC_RESPONSE_UNKNOWN)
> 287b3d115e5351 Thinh Nguyen          2024-12-11  1237  		goto skip;
> 287b3d115e5351 Thinh Nguyen          2024-12-11  1238  
> 287b3d115e5351 Thinh Nguyen          2024-12-11  1239  	if (cmd->tmr_func)
> 287b3d115e5351 Thinh Nguyen          2024-12-11  1240  		usbg_submit_tmr(cmd);
> 287b3d115e5351 Thinh Nguyen          2024-12-11  1241  	else
> 287b3d115e5351 Thinh Nguyen          2024-12-11  1242  		usbg_submit_cmd(cmd);
> 287b3d115e5351 Thinh Nguyen          2024-12-11  1243  
> 287b3d115e5351 Thinh Nguyen          2024-12-11  1244  	return;
> 287b3d115e5351 Thinh Nguyen          2024-12-11  1245  
> 287b3d115e5351 Thinh Nguyen          2024-12-11  1246  skip:
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1247  	if (cmd->tmr_rsp == RC_OVERLAPPED_TAG) {
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1248  		struct f_uas *fu = cmd->fu;
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1249  		struct se_session *se_sess;
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1250  		struct uas_stream *stream = NULL;
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1251  		struct hlist_node *tmp;
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1252  		struct usbg_cmd *active_cmd = NULL;
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1253  
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1254  		se_sess = cmd->fu->tpg->tpg_nexus->tvn_se_sess;
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1255  
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1256  		hash_for_each_possible_safe(fu->stream_hash, stream, tmp, node, cmd->tag) {
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1257  			int i = stream - &fu->stream[0];
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1258  
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1259  			active_cmd = &((struct usbg_cmd *)se_sess->sess_cmd_map)[i];
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1260  			if (active_cmd->tag == cmd->tag)
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1261  				break;
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1262  		}
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1263  
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1264  		/* Sanity check */
> 7735c10c74d903 Thinh Nguyen          2024-12-11 @1265  		if (!stream || (active_cmd && active_cmd->tag != cmd->tag)) {
> 
> Testing for !stream is sufficient.  Another option would be to write this

Just testing for !stream is sufficient to know whether active_cmd is
NULL, but we still need to check for matching tag also.

> as:
> 	if (!stream || !active_cmd || active_cmd->tag != cmd->tag)) {

Perhaps we can just do this:

	if (!active_cmd || active_cmd->tag != cmd->tag)) {

If active_cmd is NULL, then the stream variable must also be NULL. This
may not be obvious.

> 
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1266  			usbg_submit_command(cmd->fu, cmd->req);
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1267  			return;
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1268  		}
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1269  
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1270  		reinit_completion(&stream->cmd_completion);
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1271  
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1272  		/*
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1273  		 * A UASP command consists of the command, data, and status
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1274  		 * stages, each operating sequentially from different endpoints.
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1275  		 *
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1276  		 * Each USB endpoint operates independently, and depending on
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1277  		 * hardware implementation, a completion callback for a transfer
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1278  		 * from one endpoint may not reflect the order of completion on
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1279  		 * the wire. This is particularly true for devices with
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1280  		 * endpoints that have independent interrupts and event buffers.
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1281  		 *
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1282  		 * The driver must still detect misbehaving hosts and respond
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1283  		 * with an overlap status. To reduce false overlap failures,
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1284  		 * allow the active and matching stream ID a brief 1ms to
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1285  		 * complete before responding with an overlap command failure.
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1286  		 * Overlap failure should be rare.
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1287  		 */
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1288  		wait_for_completion_timeout(&stream->cmd_completion, msecs_to_jiffies(1));
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1289  
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1290  		/* If the previous stream is completed, retry the command. */
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1291  		if (!hash_hashed(&stream->node)) {
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1292  			usbg_submit_command(cmd->fu, cmd->req);
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1293  			return;
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1294  		}
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1295  
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1296  		/*
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1297  		 * The command isn't submitted to the target core, so we're safe
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1298  		 * to remove the bitmap index from the session tag pool.
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1299  		 */
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1300  		sbitmap_queue_clear(&se_sess->sess_tag_pool,
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1301  				    cmd->se_cmd.map_tag,
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1302  				    cmd->se_cmd.map_cpu);
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1303  
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1304  		/*
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1305  		 * Overlap command tag detected. Cancel any pending transfer of
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1306  		 * the command submitted to target core.
> 7735c10c74d903 Thinh Nguyen          2024-12-11  1307  		 */
> 7735c10c74d903 Thinh Nguyen          2024-12-11 @1308  		active_cmd->tmr_rsp = RC_OVERLAPPED_TAG;
> 
> The inconsistent NULL check triggers a warning here.
> 

We already check for !stream prior, so I didn't check for active_cmd
here. This is more of a consistency issue. If possible and if needed, we
can make this more consistent after the merge?

Thanks,
Thinh

  reply	other threads:[~2024-12-20  2:31 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-11  0:31 [PATCH v3 00/28] usb: gadget: f_tcm: Enhance UASP driver Thinh Nguyen
2024-12-11  0:31 ` [PATCH v3 01/28] usb: gadget: f_tcm: Don't free command immediately Thinh Nguyen
2024-12-11  0:31 ` [PATCH v3 02/28] usb: gadget: f_tcm: Translate error to sense Thinh Nguyen
2024-12-11  0:31 ` [PATCH v3 03/28] usb: gadget: f_tcm: Decrement command ref count on cleanup Thinh Nguyen
2024-12-11  0:31 ` [PATCH v3 04/28] usb: gadget: f_tcm: Fix Get/SetInterface return value Thinh Nguyen
2024-12-11  0:32 ` [PATCH v3 05/28] usb: gadget: f_tcm: ep_autoconfig with fullspeed endpoint Thinh Nguyen
2024-12-11  0:32 ` [PATCH v3 06/28] usb: gadget: f_tcm: Don't prepare BOT write request twice Thinh Nguyen
2024-12-11  0:32 ` [PATCH v3 07/28] usb: gadget: f_tcm: Increase stream count Thinh Nguyen
2024-12-11  0:32 ` [PATCH v3 08/28] usb: gadget: f_tcm: Increase bMaxBurst Thinh Nguyen
2024-12-11  0:32 ` [PATCH v3 09/28] usb: gadget: f_tcm: Limit number of sessions Thinh Nguyen
2024-12-11  0:32 ` [PATCH v3 10/28] usb: gadget: f_tcm: Get stream by sbitmap number Thinh Nguyen
2024-12-11  0:32 ` [PATCH v3 11/28] usb: gadget: f_tcm: Don't set static stream_id Thinh Nguyen
2024-12-11  0:32 ` [PATCH v3 12/28] usb: gadget: f_tcm: Allocate matching number of commands to streams Thinh Nguyen
2024-12-11  0:32 ` [PATCH v3 13/28] usb: gadget: f_tcm: Handle multiple commands in parallel Thinh Nguyen
2024-12-11  0:32 ` [PATCH v3 14/28] usb: gadget: f_tcm: Use extra number of commands Thinh Nguyen
2024-12-11  0:33 ` [PATCH v3 15/28] usb: gadget: f_tcm: Return ATA cmd direction Thinh Nguyen
2024-12-11  0:33 ` [PATCH v3 16/28] usb: gadget: f_tcm: Execute command on write completion Thinh Nguyen
2024-12-11  0:33 ` [PATCH v3 17/28] usb: gadget: f_tcm: Minor cleanup redundant code Thinh Nguyen
2024-12-11  0:33 ` [PATCH v3 18/28] usb: gadget: f_tcm: Handle abort command Thinh Nguyen
2024-12-11  0:33 ` [PATCH v3 19/28] usb: gadget: f_tcm: Cleanup requests on ep disable Thinh Nguyen
2024-12-11  0:33 ` [PATCH v3 20/28] usb: gadget: f_tcm: Stop proceeding further on -ESHUTDOWN Thinh Nguyen
2024-12-11  0:33 ` [PATCH v3 21/28] usb: gadget: f_tcm: Save CPU ID per command Thinh Nguyen
2024-12-11  0:33 ` [PATCH v3 22/28] usb: gadget: f_tcm: Send sense on cancelled transfer Thinh Nguyen
2024-12-11  0:33 ` [PATCH v3 23/28] usb: gadget: f_tcm: Handle TASK_MANAGEMENT commands Thinh Nguyen
2024-12-11  0:33 ` [PATCH v3 24/28] usb: gadget: f_tcm: Check overlapped command Thinh Nguyen
2024-12-19 13:47   ` Dan Carpenter
2024-12-20  2:31     ` Thinh Nguyen [this message]
2025-01-06  8:01       ` Dan Carpenter
2024-12-11  0:34 ` [PATCH v3 25/28] usb: gadget: f_tcm: Stall on invalid CBW Thinh Nguyen
2024-12-11  0:34 ` [PATCH v3 26/28] usb: gadget: f_tcm: Requeue command request on error Thinh Nguyen
2024-12-11  0:34 ` [PATCH v3 27/28] usb: gadget: f_tcm: Track BOT command kref Thinh Nguyen
2024-12-11  0:34 ` [PATCH v3 28/28] usb: gadget: f_tcm: Refactor goto check_condition Thinh Nguyen
2024-12-11 10:42 ` [PATCH v3 00/28] usb: gadget: f_tcm: Enhance UASP driver Greg Kroah-Hartman
2024-12-11 17:11   ` Thinh Nguyen
2024-12-20 12:59 ` Homura Akemi
2024-12-20 20:14   ` Thinh Nguyen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241220023105.ruvvhqbzd3m37ce4@synopsys.com \
    --to=thinh.nguyen@synopsys.com \
    --cc=a1134123566@gmail.com \
    --cc=bigeasy@linutronix.de \
    --cc=dan.carpenter@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=oe-kbuild-all@lists.linux.dev \
    --cc=oe-kbuild@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox