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] [day] [month] [year] [list]
Date:   Mon, 22 May 2017 22:26:31 +0000
From:   <Woojung.Huh@...rochip.com>
To:     <andrew@...n.ch>
CC:     <f.fainelli@...il.com>, <vivien.didelot@...oirfairelinux.com>,
        <sergei.shtylyov@...entembedded.com>, <netdev@...r.kernel.org>,
        <davem@...emloft.net>, <UNGLinuxDriver@...rochip.com>
Subject: RE: [PATCH v3 net-next 3/5] dsa: add DSA switch driver for
 Microchip KSZ9477

> > > > +static int get_vlan_table(struct dsa_switch *ds, u16 vid, u32
> *vlan_table)
> > > > +{
> > > > +	struct ksz_device *dev = ds->priv;
> > > > +	u8 data;
> > > > +	int timeout = 1000;
> > > > +
> > > > +	ksz_write16(dev, REG_SW_VLAN_ENTRY_INDEX__2, vid &
> > > VLAN_INDEX_M);
> > > > +	ksz_write8(dev, REG_SW_VLAN_CTRL, VLAN_READ | VLAN_START);
> > > > +
> > > > +	/* wait to be cleared */
> > > > +	data = 0;
> > > > +	do {
> > > > +		ksz_read8(dev, REG_SW_VLAN_CTRL, &data);
> > > > +		if (!(data & VLAN_START))
> > > > +			break;
> > > > +		usleep_range(1, 10);
> > > > +	} while (timeout-- > 0);
> > > > +
> > > > +	if (!timeout)
> > > > +		return -ETIMEDOUT;
> > > > +
> > > > +	ksz_read32(dev, REG_SW_VLAN_ENTRY__4, &vlan_table[0]);
> > > > +	ksz_read32(dev, REG_SW_VLAN_ENTRY_UNTAG__4,
> > > &vlan_table[1]);
> > > > +	ksz_read32(dev, REG_SW_VLAN_ENTRY_PORTS__4, &vlan_table[2]);
> > > > +
> > > > +	ksz_write8(dev, REG_SW_VLAN_CTRL, 0);
> > > > +
> > > > +	return 0;
> > > > +}
> > > > +
> > > > +static int set_vlan_table(struct dsa_switch *ds, u16 vid, u32
> *vlan_table)
> > > > +{
> > > > +	struct ksz_device *dev = ds->priv;
> > > > +	u8 data;
> > > > +	int timeout = 1000;
> > > > +
> > > > +	ksz_write32(dev, REG_SW_VLAN_ENTRY__4, vlan_table[0]);
> > > > +	ksz_write32(dev, REG_SW_VLAN_ENTRY_UNTAG__4, vlan_table[1]);
> > > > +	ksz_write32(dev, REG_SW_VLAN_ENTRY_PORTS__4, vlan_table[2]);
> > > > +
> > > > +	ksz_write16(dev, REG_SW_VLAN_ENTRY_INDEX__2, vid &
> > > VLAN_INDEX_M);
> > > > +	ksz_write8(dev, REG_SW_VLAN_CTRL, VLAN_START | VLAN_WRITE);
> > > > +
> > > > +	do {
> > > > +		ksz_read8(dev, REG_SW_VLAN_CTRL, &data);
> > > > +		if (!(data & VLAN_START))
> > > > +			break;
> > > > +		usleep_range(1, 10);
> > > > +	} while (timeout-- > 0);
> > > > +
> > > > +	if (!timeout)
> > > > +		return -ETIMEDOUT;
> > > > +
> > > > +	ksz_write8(dev, REG_SW_VLAN_CTRL, 0);
> > > > +
> > > > +	mutex_lock(&dev->vlancache_mutex);
> > >
> > > Humm. I think this is wrong. Shouldn't you hold the mutex while you
> > > change the hardware as well as the cache. Otherwise there is a risk
> > > your cache could be different to the hardware when you get a race
> > > between two threads?
> > Thanks for pointing this out.
> > Rather than two separate mutex (H/W and vlancache), will put one HW
> access mutex
> > around get_vlan_table and set_vlan_table to cover vlancache access too.
> Even though
> > little bit overhead. How do you think?
> 
> I would move the mutex_lock(&dev->vlancache_mutex) to be beginning of
> the function. It then protects both the hardware and the vlan cache,
> and keeps them synchronised.
> 
Andrew,

I believe mutex is needed in get_vlan_table() too.
vlancache_mutex doesn't match exactly what it does, I would change name to
vlan_mutex.

Thanks.
- Woojung

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ