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]
Date:   Wed, 4 Mar 2020 08:59:26 +0100
From:   Michal Kubecek <mkubecek@...e.cz>
To:     Jakub Kicinski <kuba@...nel.org>
Cc:     davem@...emloft.net, thomas.lendacky@....com, benve@...co.com,
        _govind@....com, pkaustub@...co.com, peppe.cavallaro@...com,
        alexandre.torgue@...com, joabreu@...opsys.com, snelson@...sando.io,
        yisen.zhuang@...wei.com, salil.mehta@...wei.com,
        jeffrey.t.kirsher@...el.com, jacob.e.keller@...el.com,
        alexander.h.duyck@...ux.intel.com, michael.chan@...adcom.com,
        saeedm@...lanox.com, leon@...nel.org, netdev@...r.kernel.org
Subject: Re: [PATCH net-next v2 01/12] ethtool: add infrastructure for
 centralized checking of coalescing parameters

On Tue, Mar 03, 2020 at 08:33:43PM -0800, Jakub Kicinski wrote:
> Linux supports 22 different interrupt coalescing parameters.
> No driver implements them all. Some drivers just ignore the
> ones they don't support, while others have to carry a long
> list of checks to reject unsupported settings.
> 
> To simplify the drivers add the ability to specify inside
> ethtool_ops which parameters are supported and let the core
> reject attempts to set any other one.
> 
> This commit makes the mechanism an opt-in, only drivers which
> set ethtool_opts->coalesce_types to a non-zero value will have
> the checks enforced.
> 
> The same mask is used for global and per queue settings.
> 
> Signed-off-by: Jakub Kicinski <kuba@...nel.org>
> ---
[...]
> +static bool
> +ethtool_set_coalesce_supported(struct net_device *dev,
> +			       struct ethtool_coalesce *coalesce)
> +{
> +	u32 used_types = 0;
> +
> +	if (coalesce->rx_coalesce_usecs)
> +		used_types |= ETHTOOL_COALESCE_RX_USECS;
> +	if (coalesce->rx_max_coalesced_frames)
> +		used_types |= ETHTOOL_COALESCE_RX_MAX_FRAMES;
> +	if (coalesce->rx_coalesce_usecs_irq)
> +		used_types |= ETHTOOL_COALESCE_RX_USECS_IRQ;
> +	if (coalesce->rx_max_coalesced_frames_irq)
> +		used_types |= ETHTOOL_COALESCE_RX_MAX_FRAMES_IRQ;
> +	if (coalesce->tx_coalesce_usecs)
> +		used_types |= ETHTOOL_COALESCE_TX_USECS;
> +	if (coalesce->tx_max_coalesced_frames)
> +		used_types |= ETHTOOL_COALESCE_TX_MAX_FRAMES;
> +	if (coalesce->tx_coalesce_usecs_irq)
> +		used_types |= ETHTOOL_COALESCE_TX_USECS_IRQ;
> +	if (coalesce->tx_max_coalesced_frames_irq)
> +		used_types |= ETHTOOL_COALESCE_TX_MAX_FRAMES_IRQ;
> +	if (coalesce->stats_block_coalesce_usecs)
> +		used_types |= ETHTOOL_COALESCE_STATS_BLOCK_USECS;
> +	if (coalesce->use_adaptive_rx_coalesce)
> +		used_types |= ETHTOOL_COALESCE_USE_ADAPTIVE_RX;
> +	if (coalesce->use_adaptive_tx_coalesce)
> +		used_types |= ETHTOOL_COALESCE_USE_ADAPTIVE_TX;
> +	if (coalesce->pkt_rate_low)
> +		used_types |= ETHTOOL_COALESCE_PKT_RATE_LOW;
> +	if (coalesce->rx_coalesce_usecs_low)
> +		used_types |= ETHTOOL_COALESCE_RX_USECS_LOW;
> +	if (coalesce->rx_max_coalesced_frames_low)
> +		used_types |= ETHTOOL_COALESCE_RX_MAX_FRAMES_LOW;
> +	if (coalesce->tx_coalesce_usecs_low)
> +		used_types |= ETHTOOL_COALESCE_TX_USECS_LOW;
> +	if (coalesce->tx_max_coalesced_frames_low)
> +		used_types |= ETHTOOL_COALESCE_TX_MAX_FRAMES_LOW;
> +	if (coalesce->pkt_rate_high)
> +		used_types |= ETHTOOL_COALESCE_PKT_RATE_HIGH;
> +	if (coalesce->rx_coalesce_usecs_high)
> +		used_types |= ETHTOOL_COALESCE_RX_USECS_HIGH;
> +	if (coalesce->rx_max_coalesced_frames_high)
> +		used_types |= ETHTOOL_COALESCE_RX_MAX_FRAMES_HIGH;
> +	if (coalesce->tx_coalesce_usecs_high)
> +		used_types |= ETHTOOL_COALESCE_TX_USECS_HIGH;
> +	if (coalesce->tx_max_coalesced_frames_high)
> +		used_types |= ETHTOOL_COALESCE_TX_MAX_FRAMES_HIGH;
> +	if (coalesce->rate_sample_interval)
> +		used_types |= ETHTOOL_COALESCE_RATE_SAMPLE_INTERVAL;

Just an idea: perhaps we could use the fact that struct ethtool_coalesce
is de facto an array so that this block could be replaced by a loop like

	u32 supported_types = dev->ethtool_ops->coalesce_types;
	const u32 *values = &coalesce->rx_coalesce_usecs;

	for (i = 0; i < __ETHTOOL_COALESCE_COUNT; i++)
		if (values[i] && !(supported_types & BIT(i)))
			return false;

and to be sure, BUILD_BUG_ON() or static_assert() check that the offset
of ->rate_sample_interval matches ETHTOOL_COALESCE_RATE_SAMPLE_INTERVAL.

> +	return !dev->ethtool_ops->coalesce_types ||
> +		(dev->ethtool_ops->coalesce_types & used_types) == used_types;
> +}

I suggest to move the check for !dev->ethtool_ops->coalesce_types to the
beginning of the function so that we avoid calculating the bitmap if we
are not going to check it anyway.

Michal

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ