* [PATCH 1/2] net: mvpp2: don't bring up on MAC address set
@ 2016-11-09 12:56 Baruch Siach
2016-11-09 12:56 ` [PATCH 2/2] net: mvpp2: simplify MAC address set code Baruch Siach
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Baruch Siach @ 2016-11-09 12:56 UTC (permalink / raw)
To: Marcin Wojtas; +Cc: netdev, Thomas Petazzoni, Gregory Clement, Baruch Siach
Current .ndo_set_mac_address implementation brings up the interface when revert
to original address after failure succeeds. Fix this.
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
---
Untested; I don't have the hardware.
---
drivers/net/ethernet/marvell/mvpp2.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/marvell/mvpp2.c b/drivers/net/ethernet/marvell/mvpp2.c
index 60227a3452a4..e427b4706726 100644
--- a/drivers/net/ethernet/marvell/mvpp2.c
+++ b/drivers/net/ethernet/marvell/mvpp2.c
@@ -5686,9 +5686,8 @@ static int mvpp2_set_mac_address(struct net_device *dev, void *p)
if (!err)
return 0;
/* Reconfigure parser to accept the original MAC address */
- err = mvpp2_prs_update_mac_da(dev, dev->dev_addr);
- if (err)
- goto error;
+ mvpp2_prs_update_mac_da(dev, dev->dev_addr);
+ goto error;
}
mvpp2_stop_dev(port);
@@ -5698,9 +5697,8 @@ static int mvpp2_set_mac_address(struct net_device *dev, void *p)
goto out_start;
/* Reconfigure parser accept the original MAC address */
- err = mvpp2_prs_update_mac_da(dev, dev->dev_addr);
- if (err)
- goto error;
+ mvpp2_prs_update_mac_da(dev, dev->dev_addr);
+ goto error;
out_start:
mvpp2_start_dev(port);
mvpp2_egress_enable(port);
--
2.10.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] net: mvpp2: simplify MAC address set code
2016-11-09 12:56 [PATCH 1/2] net: mvpp2: don't bring up on MAC address set Baruch Siach
@ 2016-11-09 12:56 ` Baruch Siach
2016-11-09 13:22 ` [PATCH 1/2] net: mvpp2: don't bring up on MAC address set Thomas Petazzoni
2016-11-10 16:57 ` David Miller
2 siblings, 0 replies; 6+ messages in thread
From: Baruch Siach @ 2016-11-09 12:56 UTC (permalink / raw)
To: Marcin Wojtas; +Cc: netdev, Thomas Petazzoni, Gregory Clement, Baruch Siach
Remove duplicated code for handling the !netif_running() case.
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
---
Build tested only.
---
drivers/net/ethernet/marvell/mvpp2.c | 26 +++++++++++---------------
1 file changed, 11 insertions(+), 15 deletions(-)
diff --git a/drivers/net/ethernet/marvell/mvpp2.c b/drivers/net/ethernet/marvell/mvpp2.c
index e427b4706726..64b7f985d517 100644
--- a/drivers/net/ethernet/marvell/mvpp2.c
+++ b/drivers/net/ethernet/marvell/mvpp2.c
@@ -5674,32 +5674,28 @@ static int mvpp2_set_mac_address(struct net_device *dev, void *p)
{
struct mvpp2_port *port = netdev_priv(dev);
const struct sockaddr *addr = p;
- int err;
+ int err, restart_dev = 0;
if (!is_valid_ether_addr(addr->sa_data)) {
err = -EADDRNOTAVAIL;
goto error;
}
- if (!netif_running(dev)) {
- err = mvpp2_prs_update_mac_da(dev, addr->sa_data);
- if (!err)
- return 0;
- /* Reconfigure parser to accept the original MAC address */
+ if (netif_running(dev)) {
+ mvpp2_stop_dev(port);
+ restart_dev = 1;
+ }
+
+ err = mvpp2_prs_update_mac_da(dev, addr->sa_data);
+ if (err) {
+ /* Reconfigure parser accept the original MAC address */
mvpp2_prs_update_mac_da(dev, dev->dev_addr);
goto error;
}
- mvpp2_stop_dev(port);
-
- err = mvpp2_prs_update_mac_da(dev, addr->sa_data);
- if (!err)
- goto out_start;
+ if (!restart_dev)
+ return 0;
- /* Reconfigure parser accept the original MAC address */
- mvpp2_prs_update_mac_da(dev, dev->dev_addr);
- goto error;
-out_start:
mvpp2_start_dev(port);
mvpp2_egress_enable(port);
mvpp2_ingress_enable(port);
--
2.10.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] net: mvpp2: don't bring up on MAC address set
2016-11-09 12:56 [PATCH 1/2] net: mvpp2: don't bring up on MAC address set Baruch Siach
2016-11-09 12:56 ` [PATCH 2/2] net: mvpp2: simplify MAC address set code Baruch Siach
@ 2016-11-09 13:22 ` Thomas Petazzoni
2016-11-09 18:49 ` Baruch Siach
2016-11-10 16:57 ` David Miller
2 siblings, 1 reply; 6+ messages in thread
From: Thomas Petazzoni @ 2016-11-09 13:22 UTC (permalink / raw)
To: Baruch Siach; +Cc: Marcin Wojtas, netdev, Gregory Clement
Hello,
On Wed, 9 Nov 2016 14:56:33 +0200, Baruch Siach wrote:
> Current .ndo_set_mac_address implementation brings up the interface when revert
> to original address after failure succeeds. Fix this.
>
> Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Indeed, this piece of code is not very smart.
> diff --git a/drivers/net/ethernet/marvell/mvpp2.c b/drivers/net/ethernet/marvell/mvpp2.c
> index 60227a3452a4..e427b4706726 100644
> --- a/drivers/net/ethernet/marvell/mvpp2.c
> +++ b/drivers/net/ethernet/marvell/mvpp2.c
> @@ -5686,9 +5686,8 @@ static int mvpp2_set_mac_address(struct net_device *dev, void *p)
> if (!err)
> return 0;
> /* Reconfigure parser to accept the original MAC address */
> - err = mvpp2_prs_update_mac_da(dev, dev->dev_addr);
> - if (err)
> - goto error;
> + mvpp2_prs_update_mac_da(dev, dev->dev_addr);
> + goto error;
Wouldn't it make more sense to call mvpp2_prs_update_mac_da() under
the error: goto label?
But if you think beyond that, it is a bit crazy that to handle the
error case of mvpp2_prs_update_mac_da(), we have to call
mvpp2_prs_update_mac_da(), which is exactly the same function...
Perhaps it would be interesting to investigate what are the various
conditions for which mvpp2_prs_update_mac_da() fails, and see if we can
avoid them.
Best regards,
Thomas
--
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] net: mvpp2: don't bring up on MAC address set
2016-11-09 13:22 ` [PATCH 1/2] net: mvpp2: don't bring up on MAC address set Thomas Petazzoni
@ 2016-11-09 18:49 ` Baruch Siach
0 siblings, 0 replies; 6+ messages in thread
From: Baruch Siach @ 2016-11-09 18:49 UTC (permalink / raw)
To: Thomas Petazzoni; +Cc: Marcin Wojtas, netdev, Gregory Clement
Hi Thomas,
On Wed, Nov 09, 2016 at 02:22:11PM +0100, Thomas Petazzoni wrote:
> On Wed, 9 Nov 2016 14:56:33 +0200, Baruch Siach wrote:
> > Current .ndo_set_mac_address implementation brings up the interface when revert
> > to original address after failure succeeds. Fix this.
> >
> > Signed-off-by: Baruch Siach <baruch@tkos.co.il>
>
> Indeed, this piece of code is not very smart.
>
> > diff --git a/drivers/net/ethernet/marvell/mvpp2.c b/drivers/net/ethernet/marvell/mvpp2.c
> > index 60227a3452a4..e427b4706726 100644
> > --- a/drivers/net/ethernet/marvell/mvpp2.c
> > +++ b/drivers/net/ethernet/marvell/mvpp2.c
> > @@ -5686,9 +5686,8 @@ static int mvpp2_set_mac_address(struct net_device *dev, void *p)
> > if (!err)
> > return 0;
> > /* Reconfigure parser to accept the original MAC address */
> > - err = mvpp2_prs_update_mac_da(dev, dev->dev_addr);
> > - if (err)
> > - goto error;
> > + mvpp2_prs_update_mac_da(dev, dev->dev_addr);
> > + goto error;
>
> Wouldn't it make more sense to call mvpp2_prs_update_mac_da() under
> the error: goto label?
An is_valid_ether_addr() failure also goes to the 'error' label, so a more
intrusive change would be needed.
> But if you think beyond that, it is a bit crazy that to handle the
> error case of mvpp2_prs_update_mac_da(), we have to call
> mvpp2_prs_update_mac_da(), which is exactly the same function...
I agree. This patch is only a minimal fix to the bug.
> Perhaps it would be interesting to investigate what are the various
> conditions for which mvpp2_prs_update_mac_da() fails, and see if we can
> avoid them.
mvpp2_prs_update_mac_da() calls mvpp2_prs_mac_da_accept() that in turn calls
kzalloc(). kzalloc() might theoretically fail (though it never fails in
practice). Getting rid of these would not be that easy.
Changing the MAC address in this driver is a rather complex process that
involves removing the previous header parser, and installing a new one. There
are many sanity and bound checks along the way.
baruch
--
http://baruch.siach.name/blog/ ~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch@tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] net: mvpp2: don't bring up on MAC address set
2016-11-09 12:56 [PATCH 1/2] net: mvpp2: don't bring up on MAC address set Baruch Siach
2016-11-09 12:56 ` [PATCH 2/2] net: mvpp2: simplify MAC address set code Baruch Siach
2016-11-09 13:22 ` [PATCH 1/2] net: mvpp2: don't bring up on MAC address set Thomas Petazzoni
@ 2016-11-10 16:57 ` David Miller
2016-11-10 18:08 ` Baruch Siach
2 siblings, 1 reply; 6+ messages in thread
From: David Miller @ 2016-11-10 16:57 UTC (permalink / raw)
To: baruch; +Cc: mw, netdev, thomas.petazzoni, gregory.clement
From: Baruch Siach <baruch@tkos.co.il>
Date: Wed, 9 Nov 2016 14:56:33 +0200
> Current .ndo_set_mac_address implementation brings up the interface when revert
> to original address after failure succeeds. Fix this.
>
> Signed-off-by: Baruch Siach <baruch@tkos.co.il>
> ---
> Untested; I don't have the hardware.
The code which updates the parser should keep the existing
state if any part of the update fails.
This means it must attempt all memory allocations and whatever other
resource acquisition is necessary, and only after all of those
operations succeed and no more error cases are possible should it
update the tables and release the old entry.
In other worse, this whole mechanism must move to a proper "prepare
--> commit" model of making changes.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] net: mvpp2: don't bring up on MAC address set
2016-11-10 16:57 ` David Miller
@ 2016-11-10 18:08 ` Baruch Siach
0 siblings, 0 replies; 6+ messages in thread
From: Baruch Siach @ 2016-11-10 18:08 UTC (permalink / raw)
To: David Miller; +Cc: mw, netdev, thomas.petazzoni, gregory.clement
Hi David,
On Thu, Nov 10, 2016 at 11:57:18AM -0500, David Miller wrote:
> From: Baruch Siach <baruch@tkos.co.il>
> Date: Wed, 9 Nov 2016 14:56:33 +0200
>
> > Current .ndo_set_mac_address implementation brings up the interface when revert
> > to original address after failure succeeds. Fix this.
> >
> > Signed-off-by: Baruch Siach <baruch@tkos.co.il>
> > ---
> > Untested; I don't have the hardware.
>
> The code which updates the parser should keep the existing
> state if any part of the update fails.
>
> This means it must attempt all memory allocations and whatever other
> resource acquisition is necessary, and only after all of those
> operations succeed and no more error cases are possible should it
> update the tables and release the old entry.
>
> In other worse, this whole mechanism must move to a proper "prepare
> --> commit" model of making changes.
Doing so is possible, but requires much larger changes in the driver code.
This patch makes the minimal fix to a clear bug. It should be an improvement
over the current state.
baruch
--
http://baruch.siach.name/blog/ ~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch@tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2016-11-10 18:08 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-09 12:56 [PATCH 1/2] net: mvpp2: don't bring up on MAC address set Baruch Siach
2016-11-09 12:56 ` [PATCH 2/2] net: mvpp2: simplify MAC address set code Baruch Siach
2016-11-09 13:22 ` [PATCH 1/2] net: mvpp2: don't bring up on MAC address set Thomas Petazzoni
2016-11-09 18:49 ` Baruch Siach
2016-11-10 16:57 ` David Miller
2016-11-10 18:08 ` Baruch Siach
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.