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:   Fri, 3 May 2019 13:23:28 +0200
From:   Joergen Andreasen <joergen.andreasen@...rochip.com>
To:     Andrew Lunn <andrew@...n.ch>
CC:     <netdev@...r.kernel.org>, Jamal Hadi Salim <jhs@...atatu.com>,
        Cong Wang <xiyou.wangcong@...il.com>,
        Jiri Pirko <jiri@...nulli.us>,
        Alexandre Belloni <alexandre.belloni@...tlin.com>,
        Microchip Linux Driver Support <UNGLinuxDriver@...rochip.com>,
        "David S. Miller" <davem@...emloft.net>,
        "Ralf Baechle" <ralf@...ux-mips.org>,
        Paul Burton <paul.burton@...s.com>,
        "James Hogan" <jhogan@...nel.org>, <linux-mips@...r.kernel.org>,
        <linux-kernel@...r.kernel.org>,
        Joergen Andreasen <joergen.andreasen@...rochip.com>
Subject: Re: [PATCH net-next 2/3] net: mscc: ocelot: Implement port policers
 via tc command

Hi Andrew,

The 05/02/2019 14:32, Andrew Lunn wrote:
> External E-Mail
> 
> 
> Hi Joergen
> 
> > +
> > +#define MSCC_RC(expr)				\
> > +	do {					\
> > +		int __rc__ = (expr);		\
> > +		if (__rc__ < 0)			\
> > +			return __rc__;		\
> > +	}					\
> > +	while (0)
> 
> I'm sure checkpatch warned about this. A return inside a macros is a
> bad idea. I inherited code doing this, and broke it when adding
> locking, because it was not obvious there was a return.
>

I saw the warning but I assumed that it wasn't a problem in this small context.
The macro will be removed in v2.

> > +
> > +/* The following two functions do the same as in iproute2 */
> > +#define TIME_UNITS_PER_SEC	1000000
> > +static unsigned int tc_core_tick2time(unsigned int tick)
> > +{
> > +	return (tick * (u32)PSCHED_TICKS2NS(1)) / 1000;
> > +}
> > +
> > +static unsigned int tc_calc_xmitsize(u64 rate, unsigned int ticks)
> > +{
> > +	return div_u64(rate * tc_core_tick2time(ticks), TIME_UNITS_PER_SEC);
> > +}
> 
> Should these but put somewhere others can use them?
>

It would be nice to put them in a more public place, but I am in doubt where to
put them and what to call them.

Maybe they belong in the new file: include/net/tc_act/tc_police.h.
Would that be ok?

> > +
> > +enum mscc_qos_rate_mode {
> > +	MSCC_QOS_RATE_MODE_DISABLED, /* Policer/shaper disabled */
> > +	MSCC_QOS_RATE_MODE_LINE, /* Measure line rate in kbps incl. IPG */
> > +	MSCC_QOS_RATE_MODE_DATA, /* Measures data rate in kbps excl. IPG */
> > +	MSCC_QOS_RATE_MODE_FRAME, /* Measures frame rate in fps */
> > +	__MSCC_QOS_RATE_MODE_END,
> > +	NUM_MSCC_QOS_RATE_MODE = __MSCC_QOS_RATE_MODE_END,
> > +	MSCC_QOS_RATE_MODE_MAX = __MSCC_QOS_RATE_MODE_END - 1,
> > +};
> > +
> > +/* Round x divided by y to nearest integer. x and y are integers */
> > +#define MSCC_ROUNDING_DIVISION(x, y) (((x) + ((y) / 2)) / (y))
> 
> linux/kernel.h defines DIV_ROUND_UP(). Maybe add DIV_ROUND_DOWN()?
>

This macro is currently not used and I will remove it in v2.

> > +
> > +/* Round x divided by y to nearest higher integer. x and y are integers */
> > +#define MSCC_DIV_ROUND_UP(x, y) (((x) + (y) - 1) / (y))
> 
> DIV_ROUND_UP() ?
>

I will use DIV_ROUND_UP() in v2.

> > +	/* Limit to maximum values */
> > +	pir = min_t(u32, GENMASK(15, 0), pir);
> > +	cir = min_t(u32, GENMASK(15, 0), cir);
> > +	pbs = min_t(u32, pbs_max, pbs);
> > +	cbs = min_t(u32, cbs_max, cbs);
> 
> If it does need to limit, maybe return -EOPNOTSUPP?
>

It seems fine to return -EOPBITSUPP here.
I will do that in v2.

> > +int ocelot_port_policer_add(struct ocelot_port *port,
> > +			    struct tcf_police *p)
> > +{
> > +	struct ocelot *ocelot = port->ocelot;
> > +	struct qos_policer_conf pp;
> > +
> > +	if (!p)
> > +		return -EINVAL;
> > +
> > +	netdev_dbg(port->dev,
> > +		   "result %d ewma_rate %u burst %lld mtu %u mtu_pktoks %lld\n",
> > +		   p->params->tcfp_result,
> > +		   p->params->tcfp_ewma_rate,
> > +		   p->params->tcfp_burst,
> > +		   p->params->tcfp_mtu,
> > +		   p->params->tcfp_mtu_ptoks);
> > +
> > +	if (p->params->rate_present)
> > +		netdev_dbg(port->dev,
> > +			   "rate: rate %llu mult %u over %u link %u shift %u\n",
> > +			   p->params->rate.rate_bytes_ps,
> > +			   p->params->rate.mult,
> > +			   p->params->rate.overhead,
> > +			   p->params->rate.linklayer,
> > +			   p->params->rate.shift);
> > +
> > +	if (p->params->peak_present)
> > +		netdev_dbg(port->dev,
> > +			   "peak: rate %llu mult %u over %u link %u shift %u\n",
> > +			   p->params->peak.rate_bytes_ps,
> > +			   p->params->peak.mult,
> > +			   p->params->peak.overhead,
> > +			   p->params->peak.linklayer,
> > +			   p->params->peak.shift);
> > +
> > +	memset(&pp, 0, sizeof(pp));
> 
> Rather than memset, you can do:
> 
> 	struct qos_policer_conf pp = { 0 };
>

I will do as you suggest in v2.

> 	Andrew
> 

-- 
Joergen Andreasen, Microchip

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ