Intel-Wired-Lan Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Lobakin <aleksander.lobakin@intel.com>
To: Alan Brady <alan.brady@intel.com>
Cc: willemdebruijn.kernel@gmail.com, netdev@vger.kernel.org,
	Joshua Hay <joshua.a.hay@intel.com>,
	intel-wired-lan@lists.osuosl.org, przemyslaw.kitszel@intel.com,
	igor.bagnucki@intel.com
Subject: Re: [Intel-wired-lan] [PATCH v4 01/10 iwl-next] idpf: implement virtchnl transaction manager
Date: Tue, 20 Feb 2024 15:30:07 +0100	[thread overview]
Message-ID: <22caac00-7a4e-4bc3-969e-fa3655fd9a93@intel.com> (raw)
In-Reply-To: <20240206033804.1198416-2-alan.brady@intel.com>

From: Alan Brady <alan.brady@intel.com>
Date: Mon, 5 Feb 2024 19:37:55 -0800

> This starts refactoring how virtchnl messages are handled by adding a
> transaction manager (idpf_vc_xn_manager).

[...]

> +/**
> + * idpf_vc_xn_exec - Perform a send/recv virtchnl transaction
> + * @adapter: driver specific private structure with vcxn_mngr
> + * @params: parameters for this particular transaction including
> + *   -vc_op: virtchannel operation to send
> + *   -send_buf: kvec iov for send buf and len
> + *   -recv_buf: kvec iov for recv buf and len (ignored if NULL)
> + *   -timeout_ms: timeout waiting for a reply (milliseconds)
> + *   -async: don't wait for message reply, will lose caller context
> + *   -async_handler: callback to handle async replies
> + *
> + * @returns >= 0 for success, the size of the initial reply (may or may not be
> + * >= @recv_buf.iov_len, but we never overflow @@recv_buf_iov_base). < 0 for
> + * error.
> + */
> +static ssize_t idpf_vc_xn_exec(struct idpf_adapter *adapter,
> +			       struct idpf_vc_xn_params params)

Why do you pass @params by value, i.e. whole 56 bytes per each function
call instead of passing it by pointer -> 8 bytes per call?

> +{
> +	struct kvec *send_buf = &params.send_buf;
> +	struct idpf_vc_xn *xn;
> +	ssize_t retval;
> +	u16 cookie;
> +
> +	xn = idpf_vc_xn_pop_free(&adapter->vcxn_mngr);
> +	/* no free transactions available */
> +	if (!xn)
> +		return -ENOSPC;
> +
> +	idpf_vc_xn_lock(xn);
> +	if (xn->state == IDPF_VC_XN_SHUTDOWN) {
> +		retval = -ENXIO;
> +		goto only_unlock;
> +	} else if (xn->state != IDPF_VC_XN_IDLE) {
> +		/* We're just going to clobber this transaction even though
> +		 * it's not IDLE. If we don't reuse it we could theoretically
> +		 * eventually leak all the free transactions and not be able to
> +		 * send any messages. At least this way we make an attempt to
> +		 * remain functional even though something really bad is
> +		 * happening that's corrupting what was supposed to be free
> +		 * transactions.
> +		 */
> +		WARN_ONCE(1, "There should only be idle transactions in free list (idx %d op %d)\n",
> +			  xn->idx, xn->vc_op);
> +	}
> +
> +	xn->reply = params.recv_buf;
> +	xn->reply_sz = 0;
> +	xn->state = params.async ? IDPF_VC_XN_ASYNC : IDPF_VC_XN_WAITING;
> +	xn->vc_op = params.vc_op;
> +	xn->async_handler = params.async_handler;
> +	idpf_vc_xn_unlock(xn);
> +
> +	if (!params.async)
> +		reinit_completion(&xn->completed);
> +	cookie = FIELD_PREP(IDPF_VC_XN_SALT_M, xn->salt) |
> +		 FIELD_PREP(IDPF_VC_XN_IDX_M, xn->idx);
> +
> +	retval = idpf_send_mb_msg(adapter, params.vc_op,
> +				  send_buf->iov_len, send_buf->iov_base,
> +				  cookie);
> +	if (retval) {
> +		idpf_vc_xn_lock(xn);
> +		goto release_and_unlock;
> +	}
> +
> +	if (params.async)
> +		return 0;
> +
> +	wait_for_completion_timeout(&xn->completed,
> +				    msecs_to_jiffies(params.timeout_ms));
> +
> +	/* No need to check the return value; we check the final state of the
> +	 * transaction below. It's possible the transaction actually gets more
> +	 * timeout than specified if we get preempted here but after
> +	 * wait_for_completion_timeout returns. This should be non-issue
> +	 * however.
> +	 */
> +	idpf_vc_xn_lock(xn);
> +	switch (xn->state) {
> +	case IDPF_VC_XN_SHUTDOWN:
> +		retval = -ENXIO;
> +		goto only_unlock;
> +	case IDPF_VC_XN_WAITING:
> +		dev_notice_ratelimited(&adapter->pdev->dev, "Transaction timed-out (op %d, %dms)\n",
> +				       params.vc_op, params.timeout_ms);
> +		retval = -ETIME;
> +		break;
> +	case IDPF_VC_XN_COMPLETED_SUCCESS:
> +		retval = xn->reply_sz;
> +		break;
> +	case IDPF_VC_XN_COMPLETED_FAILED:
> +		dev_notice_ratelimited(&adapter->pdev->dev, "Transaction failed (op %d)\n",
> +				       params.vc_op);
> +		retval = -EIO;
> +		break;
> +	default:
> +		/* Invalid state. */
> +		WARN_ON_ONCE(1);
> +		retval = -EIO;
> +		break;
> +	}
> +
> +release_and_unlock:
> +	idpf_vc_xn_push_free(&adapter->vcxn_mngr, xn);
> +	/* If we receive a VC reply after here, it will be dropped. */
> +only_unlock:
> +	idpf_vc_xn_unlock(xn);
> +
> +	return retval;
> +}

[...]

Thanks,
Olek

  reply	other threads:[~2024-02-20 14:30 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-06  3:37 [Intel-wired-lan] [PATCH v4 00/10 iwl-next] idpf: refactor virtchnl messages Alan Brady
2024-02-06  3:37 ` [Intel-wired-lan] [PATCH v4 01/10 iwl-next] idpf: implement virtchnl transaction manager Alan Brady
2024-02-20 14:30   ` Alexander Lobakin [this message]
2024-02-20 16:23     ` Alan Brady
2024-02-06  3:37 ` [Intel-wired-lan] [PATCH v4 02/10 iwl-next] idpf: refactor vport virtchnl messages Alan Brady
2024-02-06  3:37 ` [Intel-wired-lan] [PATCH v4 03/10 iwl-next] idpf: refactor queue related " Alan Brady
2024-02-06  3:37 ` [Intel-wired-lan] [PATCH v4 04/10 iwl-next] idpf: refactor remaining " Alan Brady
2024-02-06  3:37 ` [Intel-wired-lan] [PATCH v4 05/10 iwl-next] idpf: add async_handler for MAC filter messages Alan Brady
2024-02-06  3:38 ` [Intel-wired-lan] [PATCH v4 06/10 iwl-next] idpf: refactor idpf_recv_mb_msg Alan Brady
2024-02-06  3:38 ` [Intel-wired-lan] [PATCH v4 07/10 iwl-next] idpf: cleanup virtchnl cruft Alan Brady
2024-02-06  3:38 ` [Intel-wired-lan] [PATCH v4 08/10 iwl-next] idpf: prevent deinit uninitialized virtchnl core Alan Brady
2024-02-06  3:38 ` [Intel-wired-lan] [PATCH v4 09/10 iwl-next] idpf: fix minor controlq issues Alan Brady
2024-02-06  3:38 ` [Intel-wired-lan] [PATCH v4 10/10 iwl-next] idpf: remove dealloc vector msg err in idpf_intr_rel Alan Brady
2024-02-06 17:02 ` [Intel-wired-lan] [PATCH v4 00/10 iwl-next] idpf: refactor virtchnl messages Alexander Lobakin
2024-02-14 14:49   ` Alexander Lobakin
2024-02-14 17:06     ` Alan Brady
2024-02-20 13:47     ` Alexander Lobakin
2024-02-06 18:57 ` Jakub Kicinski
2024-02-06 19:18   ` Alan Brady
2024-02-06 20:03     ` Jakub Kicinski
2024-02-06 22:50       ` Keller, Jacob E
2024-02-06 23:17         ` Jakub Kicinski

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=22caac00-7a4e-4bc3-969e-fa3655fd9a93@intel.com \
    --to=aleksander.lobakin@intel.com \
    --cc=alan.brady@intel.com \
    --cc=igor.bagnucki@intel.com \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=joshua.a.hay@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=przemyslaw.kitszel@intel.com \
    --cc=willemdebruijn.kernel@gmail.com \
    /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