lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <22caac00-7a4e-4bc3-969e-fa3655fd9a93@intel.com>
Date: Tue, 20 Feb 2024 15:30:07 +0100
From: Alexander Lobakin <aleksander.lobakin@...el.com>
To: Alan Brady <alan.brady@...el.com>
CC: <intel-wired-lan@...ts.osuosl.org>, <netdev@...r.kernel.org>,
	<willemdebruijn.kernel@...il.com>, <przemyslaw.kitszel@...el.com>,
	<igor.bagnucki@...el.com>, Joshua Hay <joshua.a.hay@...el.com>
Subject: Re: [PATCH v4 01/10 iwl-next] idpf: implement virtchnl transaction
 manager

From: Alan Brady <alan.brady@...el.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ