drivers/firmware/dmi_scan.c:405:41: warning: taking address of packed member 'handle' of class or structure 'dmi_header' may result in an unaligned pointer value

From: kernel test robot
Date: Sun Feb 28 2021 - 21:10:40 EST


Hi Thomas,

First bad commit (maybe != root cause):

tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: fe07bfda2fb9cdef8a4d4008a409bb02f35f1bd8
commit: ba15533275dd70238b523417d222d43fb40dac9d Merge tag 'v5.6' into mips-next
date: 11 months ago
config: mips-randconfig-r011-20210301 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project b077d82b00d81934c7c27ac89dd8b0e7f448bded)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install mips cross compiling tool for clang build
# apt-get install binutils-mips-linux-gnu
# https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ba15533275dd70238b523417d222d43fb40dac9d
git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git fetch --no-tags linus master
git checkout ba15533275dd70238b523417d222d43fb40dac9d
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=mips

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>

All warnings (new ones prefixed by >>):

In file included from drivers/firmware/dmi_scan.c:5:
In file included from include/linux/module.h:16:
In file included from include/linux/kmod.h:9:
In file included from include/linux/umh.h:4:
In file included from include/linux/gfp.h:9:
include/linux/topology.h:119:9: error: implicit declaration of function 'cpu_logical_map' [-Werror,-Wimplicit-function-declaration]
return cpu_to_node(raw_smp_processor_id());
^
arch/mips/include/asm/mach-loongson64/topology.h:7:27: note: expanded from macro 'cpu_to_node'
#define cpu_to_node(cpu) (cpu_logical_map(cpu) >> 2)
^
In file included from drivers/firmware/dmi_scan.c:5:
In file included from include/linux/module.h:16:
In file included from include/linux/kmod.h:9:
In file included from include/linux/umh.h:4:
In file included from include/linux/gfp.h:9:
include/linux/topology.h:193:9: error: implicit declaration of function 'cpu_logical_map' [-Werror,-Wimplicit-function-declaration]
return cpu_to_node(cpu);
^
arch/mips/include/asm/mach-loongson64/topology.h:7:27: note: expanded from macro 'cpu_to_node'
#define cpu_to_node(cpu) (cpu_logical_map(cpu) >> 2)
^
In file included from drivers/firmware/dmi_scan.c:5:
In file included from include/linux/module.h:16:
In file included from include/linux/kmod.h:9:
In file included from include/linux/umh.h:4:
In file included from include/linux/gfp.h:9:
include/linux/topology.h:227:25: error: implicit declaration of function 'cpu_logical_map' [-Werror,-Wimplicit-function-declaration]
return cpumask_of_node(cpu_to_node(cpu));
^
arch/mips/include/asm/mach-loongson64/topology.h:7:27: note: expanded from macro 'cpu_to_node'
#define cpu_to_node(cpu) (cpu_logical_map(cpu) >> 2)
^
>> drivers/firmware/dmi_scan.c:405:41: warning: taking address of packed member 'handle' of class or structure 'dmi_header' may result in an unaligned pointer value [-Waddress-of-packed-member]
dmi_memdev[nr].handle = get_unaligned(&dm->handle);
^~~~~~~~~~
include/asm-generic/unaligned.h:22:24: note: expanded from macro 'get_unaligned'
# define get_unaligned __get_unaligned_le
^
include/linux/unaligned/generic.h:11:52: note: expanded from macro '__get_unaligned_le'
#define __get_unaligned_le(ptr) ((__force typeof(*(ptr)))({ \
^~~
>> drivers/firmware/dmi_scan.c:405:41: warning: taking address of packed member 'handle' of class or structure 'dmi_header' may result in an unaligned pointer value [-Waddress-of-packed-member]
dmi_memdev[nr].handle = get_unaligned(&dm->handle);
^~~~~~~~~~
include/asm-generic/unaligned.h:22:24: note: expanded from macro 'get_unaligned'
# define get_unaligned __get_unaligned_le
^
include/linux/unaligned/generic.h:12:33: note: expanded from macro '__get_unaligned_le'
__builtin_choose_expr(sizeof(*(ptr)) == 1, *(ptr), \
^~~
>> drivers/firmware/dmi_scan.c:405:41: warning: taking address of packed member 'handle' of class or structure 'dmi_header' may result in an unaligned pointer value [-Waddress-of-packed-member]
dmi_memdev[nr].handle = get_unaligned(&dm->handle);
^~~~~~~~~~
include/asm-generic/unaligned.h:22:24: note: expanded from macro 'get_unaligned'
# define get_unaligned __get_unaligned_le
^
include/linux/unaligned/generic.h:12:47: note: expanded from macro '__get_unaligned_le'
__builtin_choose_expr(sizeof(*(ptr)) == 1, *(ptr), \
^~~
>> drivers/firmware/dmi_scan.c:405:41: warning: taking address of packed member 'handle' of class or structure 'dmi_header' may result in an unaligned pointer value [-Waddress-of-packed-member]
dmi_memdev[nr].handle = get_unaligned(&dm->handle);
^~~~~~~~~~
include/asm-generic/unaligned.h:22:24: note: expanded from macro 'get_unaligned'
# define get_unaligned __get_unaligned_le
^
include/linux/unaligned/generic.h:13:33: note: expanded from macro '__get_unaligned_le'
__builtin_choose_expr(sizeof(*(ptr)) == 2, get_unaligned_le16((ptr)), \
^~~
>> drivers/firmware/dmi_scan.c:405:41: warning: taking address of packed member 'handle' of class or structure 'dmi_header' may result in an unaligned pointer value [-Waddress-of-packed-member]
dmi_memdev[nr].handle = get_unaligned(&dm->handle);
^~~~~~~~~~
include/asm-generic/unaligned.h:22:24: note: expanded from macro 'get_unaligned'
# define get_unaligned __get_unaligned_le
^
include/linux/unaligned/generic.h:14:33: note: expanded from macro '__get_unaligned_le'
__builtin_choose_expr(sizeof(*(ptr)) == 4, get_unaligned_le32((ptr)), \
^~~
>> drivers/firmware/dmi_scan.c:405:41: warning: taking address of packed member 'handle' of class or structure 'dmi_header' may result in an unaligned pointer value [-Waddress-of-packed-member]
dmi_memdev[nr].handle = get_unaligned(&dm->handle);
^~~~~~~~~~
include/asm-generic/unaligned.h:22:24: note: expanded from macro 'get_unaligned'
# define get_unaligned __get_unaligned_le
^
include/linux/unaligned/generic.h:14:65: note: expanded from macro '__get_unaligned_le'
__builtin_choose_expr(sizeof(*(ptr)) == 4, get_unaligned_le32((ptr)), \
^~~
>> drivers/firmware/dmi_scan.c:405:41: warning: taking address of packed member 'handle' of class or structure 'dmi_header' may result in an unaligned pointer value [-Waddress-of-packed-member]
dmi_memdev[nr].handle = get_unaligned(&dm->handle);
^~~~~~~~~~
include/asm-generic/unaligned.h:22:24: note: expanded from macro 'get_unaligned'
# define get_unaligned __get_unaligned_le
^
include/linux/unaligned/generic.h:15:33: note: expanded from macro '__get_unaligned_le'
__builtin_choose_expr(sizeof(*(ptr)) == 8, get_unaligned_le64((ptr)), \
^~~
>> drivers/firmware/dmi_scan.c:405:41: warning: taking address of packed member 'handle' of class or structure 'dmi_header' may result in an unaligned pointer value [-Waddress-of-packed-member]
dmi_memdev[nr].handle = get_unaligned(&dm->handle);
^~~~~~~~~~
include/asm-generic/unaligned.h:22:24: note: expanded from macro 'get_unaligned'
# define get_unaligned __get_unaligned_le
^
include/linux/unaligned/generic.h:15:65: note: expanded from macro '__get_unaligned_le'
__builtin_choose_expr(sizeof(*(ptr)) == 8, get_unaligned_le64((ptr)), \
^~~
8 warnings and 3 errors generated.


vim +405 drivers/firmware/dmi_scan.c

dd6dad4288cb93 Chen, Gong 2013-10-18 391
dd6dad4288cb93 Chen, Gong 2013-10-18 392 static void __init save_mem_devices(const struct dmi_header *dm, void *v)
dd6dad4288cb93 Chen, Gong 2013-10-18 393 {
dd6dad4288cb93 Chen, Gong 2013-10-18 394 const char *d = (const char *)dm;
dd6dad4288cb93 Chen, Gong 2013-10-18 395 static int nr;
6deae96b42eb1f Tony Luck 2018-03-12 396 u64 bytes;
6deae96b42eb1f Tony Luck 2018-03-12 397 u16 size;
dd6dad4288cb93 Chen, Gong 2013-10-18 398
9e0afe3910ff7e Jean Delvare 2019-12-03 399 if (dm->type != DMI_ENTRY_MEM_DEVICE || dm->length < 0x13)
dd6dad4288cb93 Chen, Gong 2013-10-18 400 return;
dd6dad4288cb93 Chen, Gong 2013-10-18 401 if (nr >= dmi_memdev_nr) {
dd6dad4288cb93 Chen, Gong 2013-10-18 402 pr_warn(FW_BUG "Too many DIMM entries in SMBIOS table\n");
dd6dad4288cb93 Chen, Gong 2013-10-18 403 return;
dd6dad4288cb93 Chen, Gong 2013-10-18 404 }
0841c04d65937a Tony Luck 2013-11-01 @405 dmi_memdev[nr].handle = get_unaligned(&dm->handle);
dd6dad4288cb93 Chen, Gong 2013-10-18 406 dmi_memdev[nr].device = dmi_string(dm, d[0x10]);
dd6dad4288cb93 Chen, Gong 2013-10-18 407 dmi_memdev[nr].bank = dmi_string(dm, d[0x11]);
9e0afe3910ff7e Jean Delvare 2019-12-03 408 dmi_memdev[nr].type = d[0x12];
6deae96b42eb1f Tony Luck 2018-03-12 409
6deae96b42eb1f Tony Luck 2018-03-12 410 size = get_unaligned((u16 *)&d[0xC]);
6deae96b42eb1f Tony Luck 2018-03-12 411 if (size == 0)
6deae96b42eb1f Tony Luck 2018-03-12 412 bytes = 0;
6deae96b42eb1f Tony Luck 2018-03-12 413 else if (size == 0xffff)
6deae96b42eb1f Tony Luck 2018-03-12 414 bytes = ~0ull;
6deae96b42eb1f Tony Luck 2018-03-12 415 else if (size & 0x8000)
6deae96b42eb1f Tony Luck 2018-03-12 416 bytes = (u64)(size & 0x7fff) << 10;
81dde26de9c08b Jean Delvare 2019-10-14 417 else if (size != 0x7fff || dm->length < 0x20)
6deae96b42eb1f Tony Luck 2018-03-12 418 bytes = (u64)size << 20;
6deae96b42eb1f Tony Luck 2018-03-12 419 else
6deae96b42eb1f Tony Luck 2018-03-12 420 bytes = (u64)get_unaligned((u32 *)&d[0x1C]) << 20;
6deae96b42eb1f Tony Luck 2018-03-12 421
6deae96b42eb1f Tony Luck 2018-03-12 422 dmi_memdev[nr].size = bytes;
dd6dad4288cb93 Chen, Gong 2013-10-18 423 nr++;
dd6dad4288cb93 Chen, Gong 2013-10-18 424 }
dd6dad4288cb93 Chen, Gong 2013-10-18 425

:::::: The code at line 405 was first introduced by commit
:::::: 0841c04d65937ad2808f59c43cb54a92473c8f0e dmi: Avoid unaligned memory access in save_mem_devices()

:::::: TO: Luck, Tony <tony.luck@xxxxxxxxx>
:::::: CC: Ingo Molnar <mingo@xxxxxxxxxx>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx

Attachment: .config.gz
Description: application/gzip