Skip to contentSkip to conversation

Modify is_zero_ether_addr() to handle byte-aligned addresses

PATCH In review Petri Gynther 4 participants 9 messages Aug 13, 2016 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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]>
---
 include/linux/etherdevice.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
include/linux/etherdevice.h +4 -2
index 37ff4a6..0cfd243 100644
@@ -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
Signature · 1 line
2.8.0.rc3.226.g39d4020
#1 lore raw
Quoted 45 lines · Petri Gynther
$ 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)) {
            ...
        }

Quoted 2 lines

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.

Quoted 16 lines
Cc Kalle Valo <[email protected]>
Cc David S. Miller <[email protected]>
Cc Joe Perches <[email protected]>
Cc Amitkumar Karwar <[email protected]>

---
 include/linux/etherdevice.h | 6 ++++--

 1 file changed, 4 insertions(+), 2 deletions(-)
include/linux/etherdevice.h +0 -0
index 37ff4a6..0cfd243 100644
@@ -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
   *

include/linux/etherdevice.h static inline bool is_link_local_ether_addr(const u8 *addr) · line 99

Quoted 10 lines
include/linux/etherdevice.h +4 -2
   * 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?

include/linux/etherdevice.h static inline bool is_link_local_ether_addr(const u8 *addr) · line 102

Quoted 3 lines
include/linux/etherdevice.h +0 -0
  #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
}

#2 lore raw

Hi Joe,

Quoted 87 lines · Joe Perches
Quoted 39 lines · Petri Gynther
$ 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, ...)

Quoted 8 lines
        ...
        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.

Quoted 16 lines
Cc Kalle Valo <[email protected]>
Cc David S. Miller <[email protected]>
Cc Joe Perches <[email protected]>
Cc Amitkumar Karwar <[email protected]>
---
 include/linux/etherdevice.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
include/linux/etherdevice.h +0 -0
index 37ff4a6..0cfd243 100644
@@ -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
  *

include/linux/etherdevice.h static inline bool is_link_local_ether_addr(const u8 *addr) · line 99

Quoted 10 lines
include/linux/etherdevice.h +4 -2
  * 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?

include/linux/etherdevice.h static inline bool is_link_local_ether_addr(const u8 *addr) · line 102

Quoted 3 lines
include/linux/etherdevice.h +0 -0
 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
      return ((*(const u32 *)addr) | (*(const u16 *)(addr + 4))) == 0;
 #else

How about adding:

Quoted 9 lines

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.

#3 lore raw
In reply to Petri Gynther
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)…

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

#4 lore raw
In reply to Petri Gynther
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…

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

maintainer
#5 lore raw
In reply to Petri Gynther

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

Quoted 2 lines

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.

#6 lore raw
Quoted 6 lines · David Miller

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

Quoted 2 lines

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

Quoted 9 lines

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.

Quoted 3 lines

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.

Quoted 1 line

Thanks.

#7 lore raw
In reply to David Miller
Quoted 6 lines · David Miller

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

Quoted 2 lines

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

Quoted 8 lines

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.

Quoted 2 lines

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.

maintainer
#8 lore raw

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

Quoted 2 lines

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.