2016-08-13 00:16:11

by Petri Gynther

[permalink] [raw]
Subject: [PATCH] Modify is_zero_ether_addr() to handle byte-aligned addresses

$ iwconfig mlan0 essid MySSID
[ 36.930000] Path: /sbin/iwconfig
[ 36.930000] CPU: 0 PID: 203 Comm: iwconfig Not tainted 4.7.0 #2
[ 36.940000] task: 866f83a0 ti: 866a6000 task.ti: 866a6000
[ 36.940000]
[ECR ]: 0x00230400 => Misaligned r/w from 0x8677f403
[ 36.960000] [EFA ]: 0x8677f403
[ 36.960000] [BLINK ]: mwifiex_scan_networks+0x17a/0x198c [mwifiex]
[ 36.960000] [ERET ]: mwifiex_scan_networks+0x18a/0x198c [mwifiex]
[ 36.980000] [STAT32]: 0x00000206 : K E2 E1
[ 36.980000] BTA: 0x700736e2 SP: 0x866a7d0c FP: 0x5faddc84
[ 37.000000] LPS: 0x806a37ec LPE: 0x806a37fa LPC: 0x00000000
[ 37.000000] r00: 0x8677f401 r01: 0x8668aa08 r02: 0x00000001
r03: 0x00000000 r04: 0x8668b600 r05: 0x8677f406
r06: 0x8702b600 r07: 0x00000000 r08: 0x8702b600
r09: 0x00000000 r10: 0x870b3b00 r11: 0x00000000
r12: 0x00000000
[ 37.040000]
[ 37.040000] Stack Trace:
[ 37.040000] mwifiex_scan_networks+0x18a/0x198c [mwifiex]

Root cause:
mwifiex driver calls is_zero_ether_addr() against byte-aligned address:

drivers/net/wireless/marvell/mwifiex/fw.h:
struct mwifiex_scan_cmd_config {
/*
* BSS mode to be sent in the firmware command
*/
u8 bss_mode;

/* Specific BSSID used to filter scan results in the firmware */
u8 specific_bssid[ETH_ALEN];

...
} __packed;

drivers/net/wireless/marvell/mwifiex/scan.c:
mwifiex_config_scan(..., struct mwifiex_scan_cmd_config *scan_cfg_out, ...)
...
if (adapter->ext_scan &&
!is_zero_ether_addr(scan_cfg_out->specific_bssid)) {
...
}

Since firmware-related struct mwifiex_scan_cmd_config cannot be changed,
modify is_zero_ether_addr() to handle byte-aligned addresses.

Cc: Kalle Valo <[email protected]>
Cc: David S. Miller <[email protected]>
Cc: Joe Perches <[email protected]>
Cc: Amitkumar Karwar <[email protected]>
Signed-off-by: Petri Gynther <[email protected]>
---
include/linux/etherdevice.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h
index 37ff4a6..0cfd243 100644
--- a/include/linux/etherdevice.h
+++ b/include/linux/etherdevice.h
@@ -90,11 +90,13 @@ static inline bool is_link_local_ether_addr(const u8 *addr)
* @addr: Pointer to a six-byte array containing the Ethernet address
*
* Return true if the address is all zeroes.
- *
- * Please note: addr must be aligned to u16.
*/
static inline bool is_zero_ether_addr(const u8 *addr)
{
+ if ((u32)addr & 0x1)
+ return (addr[0] | addr[1] | addr[2] | addr[3] | addr[4] |
+ addr[5]) == 0;
+
#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
return ((*(const u32 *)addr) | (*(const u16 *)(addr + 4))) == 0;
#else
--
2.8.0.rc3.226.g39d4020



2016-08-13 04:05:42

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] Modify is_zero_ether_addr() to handle byte-aligned addresses

From: Joe Perches <[email protected]>
Date: Fri, 12 Aug 2016 21:00:27 -0700

> One solution might be to copy a hardware interface structure
> to another struct with appropriate alignment.

Right, especially if this is a slow path that would be an appropriate
way to handle this.

2016-08-13 02:27:18

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] Modify is_zero_ether_addr() to handle byte-aligned addresses

Hi Petri,

[auto build test ERROR on net-next/master]
[also build test ERROR on v4.8-rc1 next-20160812]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Petri-Gynther/Modify-is_zero_ether_addr-to-handle-byte-aligned-addresses/20160813-081835
config: powerpc-defconfig (attached as .config)
compiler: powerpc64-linux-gnu-gcc (Debian 5.4.0-6) 5.4.0 20160609
reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=powerpc

All errors (new ones prefixed by >>):

In file included from arch/powerpc/kernel/prom_parse.c:6:0:
include/linux/etherdevice.h: In function 'is_zero_ether_addr':
>> include/linux/etherdevice.h:96:6: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
if ((u32)addr & 0x1)
^
cc1: all warnings being treated as errors

vim +96 include/linux/etherdevice.h

90 * @addr: Pointer to a six-byte array containing the Ethernet address
91 *
92 * Return true if the address is all zeroes.
93 */
94 static inline bool is_zero_ether_addr(const u8 *addr)
95 {
> 96 if ((u32)addr & 0x1)
97 return (addr[0] | addr[1] | addr[2] | addr[3] | addr[4] |
98 addr[5]) == 0;
99

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation


Attachments:
(No filename) (1.59 kB)
.config.gz (21.88 kB)
Download all attachments

2016-08-13 00:28:15

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH] Modify is_zero_ether_addr() to handle byte-aligned addresses

On Fri, 2016-08-12 at 17:15 -0700, Petri Gynther wrote:
> $ iwconfig mlan0 essid MySSID
> [???36.930000] Path: /sbin/iwconfig
> [???36.930000] CPU: 0 PID: 203 Comm: iwconfig Not tainted 4.7.0 #2
> [???36.940000] task: 866f83a0 ti: 866a6000 task.ti: 866a6000
> [???36.940000]
> [ECR???]: 0x00230400 => Misaligned r/w from 0x8677f403
> [???36.960000] [EFA???]: 0x8677f403
> [???36.960000] [BLINK ]: mwifiex_scan_networks+0x17a/0x198c [mwifiex]
> [???36.960000] [ERET??]: mwifiex_scan_networks+0x18a/0x198c [mwifiex]
> [???36.980000] [STAT32]: 0x00000206 : K?????????E2 E1
> [???36.980000] BTA: 0x700736e2???SP: 0x866a7d0c??FP: 0x5faddc84
> [???37.000000] LPS: 0x806a37ec??LPE: 0x806a37fa LPC: 0x00000000
> [???37.000000] r00: 0x8677f401??r01: 0x8668aa08 r02: 0x00000001
> r03: 0x00000000 r04: 0x8668b600 r05: 0x8677f406
> r06: 0x8702b600 r07: 0x00000000 r08: 0x8702b600
> r09: 0x00000000 r10: 0x870b3b00 r11: 0x00000000
> r12: 0x00000000
> [???37.040000]
> [???37.040000] Stack Trace:
> [???37.040000]???mwifiex_scan_networks+0x18a/0x198c [mwifiex]
>
> Root cause:
> mwifiex driver calls is_zero_ether_addr() against byte-aligned address:
>
> drivers/net/wireless/marvell/mwifiex/fw.h:
> struct mwifiex_scan_cmd_config {
> ????????/*
> ?????????*??BSS mode to be sent in the firmware command
> ?????????*/
> ????????u8 bss_mode;
>
> ????????/* Specific BSSID used to filter scan results in the firmware */
> ????????u8 specific_bssid[ETH_ALEN];
>
> ????????...
> } __packed;
>
> drivers/net/wireless/marvell/mwifiex/scan.c:
> mwifiex_config_scan(..., struct mwifiex_scan_cmd_config *scan_cfg_out, ...)
> ????????...
> ????????if (adapter->ext_scan &&
> ????????????!is_zero_ether_addr(scan_cfg_out->specific_bssid)) {
> ????????????...
> ????????}
>
> Since firmware-related struct mwifiex_scan_cmd_config cannot be changed,
> modify is_zero_ether_addr() to handle byte-aligned addresses.

Or add is_zero_ether_addr_unaligned and use it here.

> Cc: Kalle Valo <[email protected]>
> Cc: David S. Miller <[email protected]>
> Cc: Joe Perches <[email protected]>
> Cc: Amitkumar Karwar <[email protected]>
> Signed-off-by: Petri Gynther <[email protected]>
> ---
> ?include/linux/etherdevice.h | 6 ++++--
> ?1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h
> index 37ff4a6..0cfd243 100644
> --- a/include/linux/etherdevice.h
> +++ b/include/linux/etherdevice.h
> @@ -90,11 +90,13 @@ static inline bool is_link_local_ether_addr(const u8 *addr)
> ? * @addr: Pointer to a six-byte array containing the Ethernet address
> ? *
> ? * Return true if the address is all zeroes.
> - *
> - * Please note: addr must be aligned to u16.
> ? */
> ?static inline bool is_zero_ether_addr(const u8 *addr)
> ?{
> + if ((u32)addr & 0x1)
> + return (addr[0] | addr[1] | addr[2] | addr[3] | addr[4] |
> + addr[5]) == 0;
> +

So why skip the CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
optimization below?

> ?#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
> ? return ((*(const u32 *)addr) | (*(const u16 *)(addr + 4))) == 0;
> ?#else

How about adding:

static inline bool is_zero_ether_addr_unaligned(const u8 *addr)
{
#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
return is_zero_ether_addr(addr);
#else
return addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5];
#endif
}


2016-08-13 03:44:12

by Petri Gynther

[permalink] [raw]
Subject: Re: [PATCH] Modify is_zero_ether_addr() to handle byte-aligned addresses

On Fri, Aug 12, 2016 at 8:26 PM, David Miller <[email protected]> wrote:
> From: Petri Gynther <[email protected]>
> Date: Fri, 12 Aug 2016 17:15:30 -0700
>
>> Root cause:
>> mwifiex driver calls is_zero_ether_addr() against byte-aligned address:
>
> MAC addresses really must be 16-bit aligned to be used with any of the
> ethernet address manipulation and test interfaces.
>
> Therefore this driver should do whatever it takes to avoid passing
> a byte-aligned MAC address anywhere.
>
> We _SHOULD NOT_ add support for byte aligned addresses to these
> interfaces, nor add routines which by-name can handle them.
>

ether_addr_equal_unaligned() exists.

commit 73eaef87e98a96fe8b8a586f916b2721bf512efa
Author: Joe Perches <[email protected]>
Date: Fri Dec 6 14:21:01 2013 -0800

etherdevice: Add ether_addr_equal_unaligned

Add a generic routine to test if possibly unaligned
to u16 Ethernet addresses are equal.

If CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS is set,
this uses the slightly faster generic routine
ether_addr_equal, otherwise this uses memcmp.

Signed-off-by: Joe Perches <[email protected]>
Signed-off-by: David S. Miller <[email protected]>

> Fix this driver instead of polluting out common interfaces
> unnecessarily.
>

Amitkumar -- is this fixable in mwifiex driver and firmware? It looks
like your firmware expects u8 specific_bssid[ETH_ALEN] at byte offset
1, per struct mwifiex_scan_cmd_config definition.

I'll let Marvell take it from here.

> Thanks.

2016-08-13 01:48:45

by Petri Gynther

[permalink] [raw]
Subject: Re: [PATCH] Modify is_zero_ether_addr() to handle byte-aligned addresses

Hi Joe,

On Fri, Aug 12, 2016 at 5:28 PM, Joe Perches <[email protected]> wrote:
> On Fri, 2016-08-12 at 17:15 -0700, Petri Gynther wrote:
>> $ iwconfig mlan0 essid MySSID
>> [ 36.930000] Path: /sbin/iwconfig
>> [ 36.930000] CPU: 0 PID: 203 Comm: iwconfig Not tainted 4.7.0 #2
>> [ 36.940000] task: 866f83a0 ti: 866a6000 task.ti: 866a6000
>> [ 36.940000]
>> [ECR ]: 0x00230400 => Misaligned r/w from 0x8677f403
>> [ 36.960000] [EFA ]: 0x8677f403
>> [ 36.960000] [BLINK ]: mwifiex_scan_networks+0x17a/0x198c [mwifiex]
>> [ 36.960000] [ERET ]: mwifiex_scan_networks+0x18a/0x198c [mwifiex]
>> [ 36.980000] [STAT32]: 0x00000206 : K E2 E1
>> [ 36.980000] BTA: 0x700736e2 SP: 0x866a7d0c FP: 0x5faddc84
>> [ 37.000000] LPS: 0x806a37ec LPE: 0x806a37fa LPC: 0x00000000
>> [ 37.000000] r00: 0x8677f401 r01: 0x8668aa08 r02: 0x00000001
>> r03: 0x00000000 r04: 0x8668b600 r05: 0x8677f406
>> r06: 0x8702b600 r07: 0x00000000 r08: 0x8702b600
>> r09: 0x00000000 r10: 0x870b3b00 r11: 0x00000000
>> r12: 0x00000000
>> [ 37.040000]
>> [ 37.040000] Stack Trace:
>> [ 37.040000] mwifiex_scan_networks+0x18a/0x198c [mwifiex]
>>
>> Root cause:
>> mwifiex driver calls is_zero_ether_addr() against byte-aligned address:
>>
>> drivers/net/wireless/marvell/mwifiex/fw.h:
>> struct mwifiex_scan_cmd_config {
>> /*
>> * BSS mode to be sent in the firmware command
>> */
>> u8 bss_mode;
>>
>> /* Specific BSSID used to filter scan results in the firmware */
>> u8 specific_bssid[ETH_ALEN];
>>
>> ...
>> } __packed;
>>
>> drivers/net/wireless/marvell/mwifiex/scan.c:
>> mwifiex_config_scan(..., struct mwifiex_scan_cmd_config *scan_cfg_out, ...)
>> ...
>> if (adapter->ext_scan &&
>> !is_zero_ether_addr(scan_cfg_out->specific_bssid)) {
>> ...
>> }
>>
>> Since firmware-related struct mwifiex_scan_cmd_config cannot be changed,
>> modify is_zero_ether_addr() to handle byte-aligned addresses.
>
> Or add is_zero_ether_addr_unaligned and use it here.
>
>> Cc: Kalle Valo <[email protected]>
>> Cc: David S. Miller <[email protected]>
>> Cc: Joe Perches <[email protected]>
>> Cc: Amitkumar Karwar <[email protected]>
>> Signed-off-by: Petri Gynther <[email protected]>
>> ---
>> include/linux/etherdevice.h | 6 ++++--
>> 1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h
>> index 37ff4a6..0cfd243 100644
>> --- a/include/linux/etherdevice.h
>> +++ b/include/linux/etherdevice.h
>> @@ -90,11 +90,13 @@ static inline bool is_link_local_ether_addr(const u8 *addr)
>> * @addr: Pointer to a six-byte array containing the Ethernet address
>> *
>> * Return true if the address is all zeroes.
>> - *
>> - * Please note: addr must be aligned to u16.
>> */
>> static inline bool is_zero_ether_addr(const u8 *addr)
>> {
>> + if ((u32)addr & 0x1)
>> + return (addr[0] | addr[1] | addr[2] | addr[3] | addr[4] |
>> + addr[5]) == 0;
>> +
>
> So why skip the CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
> optimization below?
>
>> #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
>> return ((*(const u32 *)addr) | (*(const u16 *)(addr + 4))) == 0;
>> #else
>
> How about adding:
>
> static inline bool is_zero_ether_addr_unaligned(const u8 *addr)
> {
> #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
> return is_zero_ether_addr(addr);
> #else
> return addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5];
> #endif
> }
>

I like your idea. I'll add is_zero_ether_addr_unaligned() and use it
in mwifiex driver.

2016-08-13 03:26:17

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] Modify is_zero_ether_addr() to handle byte-aligned addresses

From: Petri Gynther <[email protected]>
Date: Fri, 12 Aug 2016 17:15:30 -0700

> Root cause:
> mwifiex driver calls is_zero_ether_addr() against byte-aligned address:

MAC addresses really must be 16-bit aligned to be used with any of the
ethernet address manipulation and test interfaces.

Therefore this driver should do whatever it takes to avoid passing
a byte-aligned MAC address anywhere.

We _SHOULD NOT_ add support for byte aligned addresses to these
interfaces, nor add routines which by-name can handle them.

Fix this driver instead of polluting out common interfaces
unnecessarily.

Thanks.

2016-08-13 02:03:56

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] Modify is_zero_ether_addr() to handle byte-aligned addresses

Hi Petri,

[auto build test WARNING on net-next/master]
[also build test WARNING on v4.8-rc1 next-20160812]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Petri-Gynther/Modify-is_zero_ether_addr-to-handle-byte-aligned-addresses/20160813-081835
config: x86_64-randconfig-n0-08130925 (attached as .config)
compiler: gcc-6 (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64

All warnings (new ones prefixed by >>):

In file included from include/asm-generic/bug.h:4:0,
from arch/x86/include/asm/bug.h:35,
from include/linux/bug.h:4,
from include/linux/mmdebug.h:4,
from include/linux/gfp.h:4,
from net/llc/llc_if.c:14:
include/linux/etherdevice.h: In function 'is_zero_ether_addr':
include/linux/etherdevice.h:96:6: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
if ((u32)addr & 0x1)
^
include/linux/compiler.h:149:30: note: in definition of macro '__trace_if'
if (__builtin_constant_p(!!(cond)) ? !!(cond) : \
^~~~
>> include/linux/etherdevice.h:96:2: note: in expansion of macro 'if'
if ((u32)addr & 0x1)
^~
include/linux/etherdevice.h:96:6: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
if ((u32)addr & 0x1)
^
include/linux/compiler.h:149:42: note: in definition of macro '__trace_if'
if (__builtin_constant_p(!!(cond)) ? !!(cond) : \
^~~~
>> include/linux/etherdevice.h:96:2: note: in expansion of macro 'if'
if ((u32)addr & 0x1)
^~
include/linux/etherdevice.h:96:6: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
if ((u32)addr & 0x1)
^
include/linux/compiler.h:160:16: note: in definition of macro '__trace_if'
______r = !!(cond); \
^~~~
>> include/linux/etherdevice.h:96:2: note: in expansion of macro 'if'
if ((u32)addr & 0x1)
^~

vim +/if +96 include/linux/etherdevice.h

80 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
81 return (((*(const u32 *)addr) ^ (*(const u32 *)b)) |
82 (__force int)((a[2] ^ b[2]) & m)) == 0;
83 #else
84 return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | ((a[2] ^ b[2]) & m)) == 0;
85 #endif
86 }
87
88 /**
89 * is_zero_ether_addr - Determine if give Ethernet address is all zeros.
90 * @addr: Pointer to a six-byte array containing the Ethernet address
91 *
92 * Return true if the address is all zeroes.
93 */
94 static inline bool is_zero_ether_addr(const u8 *addr)
95 {
> 96 if ((u32)addr & 0x1)
97 return (addr[0] | addr[1] | addr[2] | addr[3] | addr[4] |
98 addr[5]) == 0;
99
100 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
101 return ((*(const u32 *)addr) | (*(const u16 *)(addr + 4))) == 0;
102 #else
103 return (*(const u16 *)(addr + 0) |
104 *(const u16 *)(addr + 2) |

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation


Attachments:
(No filename) (3.30 kB)
.config.gz (25.10 kB)
Download all attachments

2016-08-13 04:00:37

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH] Modify is_zero_ether_addr() to handle byte-aligned addresses

On Fri, 2016-08-12 at 20:26 -0700, David Miller wrote:
> From: Petri Gynther <[email protected]>
> Date: Fri, 12 Aug 2016 17:15:30 -0700
>
> > Root cause:
> > mwifiex driver calls is_zero_ether_addr() against byte-aligned address:
>
> MAC addresses really must be 16-bit aligned to be used with any of the
> ethernet address manipulation and test interfaces.
>
> Therefore this driver should do whatever it takes to avoid passing
> a byte-aligned MAC address anywhere.
>
> We _SHOULD NOT_ add support for byte aligned addresses to these
> interfaces, nor add routines which by-name can handle them.

My recollection is that batman uses unaligned addresses
and some form of _unaligned tests are required there.

It seems that other wireless drivers also use _unaligned
in various forms.

> Fix this driver instead of polluting out common interfaces
> unnecessarily.

One solution might be to copy a hardware interface structure
to another struct with appropriate alignment.