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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 11 Sep 2023 14:00:51 +0200
From: Sabrina Dubroca <sd@...asysnail.net>
To: "Radu Pirea (NXP OSS)" <radu-nicolae.pirea@....nxp.com>
Cc: andrew@...n.ch, hkallweit1@...il.com, linux@...linux.org.uk,
	davem@...emloft.net, edumazet@...gle.com, kuba@...nel.org,
	pabeni@...hat.com, richardcochran@...il.com,
	sebastian.tobuschat@....com, netdev@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: Re: [RFC net-next v3 5/6] net: phy: nxp-c45-tja11xx: add MACsec
 statistics

2023-09-06, 19:01:33 +0300, Radu Pirea (NXP OSS) wrote:
> +static int nxp_c45_mdo_get_dev_stats(struct macsec_context *ctx)
> +{
> +	struct phy_device *phydev = ctx->phydev;
> +	struct nxp_c45_phy *priv = phydev->priv;
> +	struct macsec_dev_stats  *dev_stats;
> +	struct nxp_c45_secy *phy_secy;
> +	u32 reg = 0;
> +
> +	phy_secy = nxp_c45_find_secy(&priv->macsec->secy_list, ctx->secy->sci);
> +	if (IS_ERR(phy_secy))
> +		return PTR_ERR(phy_secy);
> +
> +	dev_stats = ctx->stats.dev_stats;
> +	nxp_c45_select_secy(phydev, phy_secy->secy_id);
> +
> +	nxp_c45_macsec_read(phydev, MACSEC_OPUS, &reg);
> +	dev_stats->OutPktsUntagged = reg;

Can you read directly into OutPktsUntagged? It would make the code a
little bit more readable.

It's a bit unfortunate that all those stats read turn into 2 (or 4 for
the 64b counters) reads. If the HW's value can be incremented while
we're reading it we'll see an inconsistent value :(


> +	nxp_c45_macsec_read(phydev, MACSEC_OPTLS, &reg);
> +	dev_stats->OutPktsTooLong = reg;
> +	nxp_c45_macsec_read(phydev, MACSEC_INPBTS, &reg);
> +	dev_stats->InPktsBadTag = reg;
> +
> +	nxp_c45_macsec_read(phydev, MACSEC_INPWTS, &reg);
> +	if (phy_secy->secy->validate_frames == MACSEC_VALIDATE_STRICT)
> +		dev_stats->InPktsNoTag += reg;
> +	else
> +		dev_stats->InPktsUntagged += reg;
> +
> +	nxp_c45_macsec_read(phydev, MACSEC_IPSNFS, &reg);
> +	if (phy_secy->secy->validate_frames == MACSEC_VALIDATE_STRICT)
> +		dev_stats->InPktsNoSCI += reg;
> +	else
> +		dev_stats->InPktsUnknownSCI += reg;
> +
> +	/* Always 0. */
> +	dev_stats->InPktsOverrun = 0;
> +
> +	return 0;
> +}
> +
> +static int nxp_c45_mdo_get_tx_sc_stats(struct macsec_context *ctx)
> +{
> +	struct phy_device *phydev = ctx->phydev;
> +	struct nxp_c45_phy *priv = phydev->priv;
> +	struct macsec_tx_sa_stats tx_sa_stats;
> +	struct macsec_tx_sc_stats *stats;
> +	struct nxp_c45_secy *phy_secy;
> +	struct nxp_c45_sa *pos, *tmp;
> +	u32 reg = 0;
> +
> +	phy_secy = nxp_c45_find_secy(&priv->macsec->secy_list, ctx->secy->sci);
> +	if (IS_ERR(phy_secy))
> +		return PTR_ERR(phy_secy);
> +
> +	stats = ctx->stats.tx_sc_stats;
> +	nxp_c45_select_secy(phydev, phy_secy->secy_id);
> +
> +	nxp_c45_macsec_read(phydev, MACSEC_OOE1HS, &reg);
> +	stats->OutOctetsEncrypted = (u64)reg << 32;
> +	nxp_c45_macsec_read(phydev, MACSEC_OOE2HS, &reg);
> +	stats->OutOctetsEncrypted |= reg;

Since you have a few 64b HW counters, I'd suggest a helper:

stats->OutOctetsEncrypted = nxp_c45_macsec_read64(phydev, MACSEC_OOE1HS, MACSEC_OOE2HS);


Or (more consistent with the 32b reads):

nxp_c45_macsec_read64(phydev, MACSEC_OOE1HS, MACSEC_OOE2HS, &stats->OutOctetsEncrypted);


-- 
Sabrina


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ