Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MIPS support #29

Open
urjaman opened this issue Jun 16, 2019 · 2 comments
Open

MIPS support #29

urjaman opened this issue Jun 16, 2019 · 2 comments

Comments

@urjaman
Copy link

urjaman commented Jun 16, 2019

Hi, I'm trying to squeeze a 4.14 kernel (+initramfs) onto quite the small flash router, and decided to try LTO'ing the kernel. I based my work on the lto-415-2 branch.

My current attempt ends up like this:

/home/urjaman/openwrt-w268r-2019/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_uClibc/lib/gcc/mipsel-openwrt-linux-uclibc/7.4.0/../../../../mipsel-openwrt-linux-uclibc/bin/ld: ./ccclqfYP.ltrans0.ltrans.o: in function `__sys_fork':
<artificial>:(.text+0x20): undefined reference to `sys_fork'
/home/urjaman/openwrt-w268r-2019/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_uClibc/lib/gcc/mipsel-openwrt-linux-uclibc/7.4.0/../../../../mipsel-openwrt-linux-uclibc/bin/ld: ./ccclqfYP.ltrans0.ltrans.o: in function `__sys_clone':
<artificial>:(.text+0x48): undefined reference to `sys_clone'
/home/urjaman/openwrt-w268r-2019/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_uClibc/lib/gcc/mipsel-openwrt-linux-uclibc/7.4.0/../../../../mipsel-openwrt-linux-uclibc/bin/ld: ./ccclqfYP.ltrans0.ltrans.o: in function `__sys_sysmips':
<artificial>:(.text+0x70): undefined reference to `sys_sysmips'
/home/urjaman/openwrt-w268r-2019/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_uClibc/lib/gcc/mipsel-openwrt-linux-uclibc/7.4.0/../../../../mipsel-openwrt-linux-uclibc/bin/ld: ./ccclqfYP.ltrans3.ltrans.o: in function `pty_resize':
<artificial>:(.text+0xa8d8): undefined reference to `memcmp'
/home/urjaman/openwrt-w268r-2019/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_uClibc/lib/gcc/mipsel-openwrt-linux-uclibc/7.4.0/../../../../mipsel-openwrt-linux-uclibc/bin/ld: ./ccclqfYP.ltrans3.ltrans.o: in function `param_setup_earlycon':
<artificial>:(.init.text+0x8ec): undefined reference to `memcmp'
/home/urjaman/openwrt-w268r-2019/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_uClibc/lib/gcc/mipsel-openwrt-linux-uclibc/7.4.0/../../../../mipsel-openwrt-linux-uclibc/bin/ld: ./ccclqfYP.ltrans4.ltrans.o: in function `nla_strcmp':
<artificial>:(.text+0x6d64): undefined reference to `memcmp'
/home/urjaman/openwrt-w268r-2019/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_uClibc/lib/gcc/mipsel-openwrt-linux-uclibc/7.4.0/../../../../mipsel-openwrt-linux-uclibc/bin/ld: ./ccclqfYP.ltrans4.ltrans.o: in function `rhashtable_lookup_one':
<artificial>:(.text+0x7f40): undefined reference to `memcmp'
/home/urjaman/openwrt-w268r-2019/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_uClibc/lib/gcc/mipsel-openwrt-linux-uclibc/7.4.0/../../../../mipsel-openwrt-linux-uclibc/bin/ld: ./ccclqfYP.ltrans4.ltrans.o: in function `tty_ioctl':
<artificial>:(.text+0xb8f0): undefined reference to `memcmp'
/home/urjaman/openwrt-w268r-2019/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_uClibc/lib/gcc/mipsel-openwrt-linux-uclibc/7.4.0/../../../../mipsel-openwrt-linux-uclibc/bin/ld: ./ccclqfYP.ltrans5.ltrans.o:<artificial>:(.text+0x3b40): more undefined references to `memcmp' follow
/home/urjaman/openwrt-w268r-2019/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_uClibc/lib/gcc/mipsel-openwrt-linux-uclibc/7.4.0/../../../../mipsel-openwrt-linux-uclibc/bin/ld: arch/mips/kernel/scall32-o32.o: in function `einval':
(.text+0x31c): undefined reference to `sys_alarm'
/home/urjaman/openwrt-w268r-2019/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_uClibc/lib/gcc/mipsel-openwrt-linux-uclibc/7.4.0/../../../../mipsel-openwrt-linux-uclibc/bin/ld: (.text+0x450): undefined reference to `sys_setitimer'
/home/urjaman/openwrt-w268r-2019/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_uClibc/lib/gcc/mipsel-openwrt-linux-uclibc/7.4.0/../../../../mipsel-openwrt-linux-uclibc/bin/ld: (.text+0x454): undefined reference to `sys_getitimer'
/home/urjaman/openwrt-w268r-2019/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_uClibc/lib/gcc/mipsel-openwrt-linux-uclibc/7.4.0/../../../../mipsel-openwrt-linux-uclibc/bin/ld: (.text+0x6b4): undefined reference to `sys_timer_create'
/home/urjaman/openwrt-w268r-2019/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_uClibc/lib/gcc/mipsel-openwrt-linux-uclibc/7.4.0/../../../../mipsel-openwrt-linux-uclibc/bin/ld: (.text+0x6b8): undefined reference to `sys_timer_settime'
/home/urjaman/openwrt-w268r-2019/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_uClibc/lib/gcc/mipsel-openwrt-linux-uclibc/7.4.0/../../../../mipsel-openwrt-linux-uclibc/bin/ld: (.text+0x6bc): undefined reference to `sys_timer_gettime'
/home/urjaman/openwrt-w268r-2019/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_uClibc/lib/gcc/mipsel-openwrt-linux-uclibc/7.4.0/../../../../mipsel-openwrt-linux-uclibc/bin/ld: (.text+0x6c0): undefined reference to `sys_timer_getoverrun'
/home/urjaman/openwrt-w268r-2019/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_uClibc/lib/gcc/mipsel-openwrt-linux
/ld: (.text+0x6c4): undefined reference to `sys_timer_delete'
/home/urjaman/openwrt-w268r-2019/staging_dir/toolchain-mipsel_24kc_gcc-7.4.0_uClibc/lib/gcc/mipsel-openwrt-linux
/ld: (.text+0x804): undefined reference to `sys_clock_adjtime'
collect2: error: ld returned 1 exit status

I assume these are to do with the syscall table... tho the memcmp ones confuse me.

Anyways the point i was going for was that a very old pdf somewhere told me this was tested on MIPS but my quick lookaround didnt find any patches, so pointers/hints appreciated, and of course anyone who has patches for MIPS support is welcome to point me at them too :)

@urjaman
Copy link
Author

urjaman commented Jun 19, 2019

So, I ended up just flaffing around until it compiled (and pulled one patch from the 4.20 branch that moved the head file to the front of the kernel binary), and the end result works but is not pretty -- if you really need it is in my openwrt-w268r repo.

Anyways the memcmp maybe had something to do with the weird special casing of that under MIPS (there was an identical version of memcmp from the generic one, but only for MIPS... disabled that), and those timer-related syscalls were actually disabled yet needed by the kernel itself (?) so i guess disabling the posix timers is not a good idea, i just re-enabled them.

@ytrezq
Copy link

ytrezq commented May 26, 2020

are you sure your toolchain can build other kernels?

andikleen pushed a commit that referenced this issue Mar 28, 2021
In case devlink reload failed, it is possible to trigger a
use-after-free when querying the kernel for device info via 'devlink dev
info' [1].

This happens because as part of the reload error path the PCI command
interface is de-initialized and its mailboxes are freed. When the
devlink '->info_get()' callback is invoked the device is queried via the
command interface and the freed mailboxes are accessed.

Fix this by initializing the command interface once during probe and not
during every reload.

This is consistent with the other bus used by mlxsw (i.e., 'mlxsw_i2c')
and also allows user space to query the running firmware version (for
example) from the device after a failed reload.

[1]
BUG: KASAN: use-after-free in memcpy include/linux/string.h:406 [inline]
BUG: KASAN: use-after-free in mlxsw_pci_cmd_exec+0x177/0xa60 drivers/net/ethernet/mellanox/mlxsw/pci.c:1675
Write of size 4096 at addr ffff88810ae32000 by task syz-executor.1/2355

CPU: 1 PID: 2355 Comm: syz-executor.1 Not tainted 5.8.0-rc2+ #29
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.1-0-ga5cab58e9a3f-prebuilt.qemu.org 04/01/2014
Call Trace:
 __dump_stack lib/dump_stack.c:77 [inline]
 dump_stack+0xf6/0x16e lib/dump_stack.c:118
 print_address_description.constprop.0+0x1c/0x250 mm/kasan/report.c:383
 __kasan_report mm/kasan/report.c:513 [inline]
 kasan_report.cold+0x1f/0x37 mm/kasan/report.c:530
 check_memory_region_inline mm/kasan/generic.c:186 [inline]
 check_memory_region+0x14e/0x1b0 mm/kasan/generic.c:192
 memcpy+0x39/0x60 mm/kasan/common.c:106
 memcpy include/linux/string.h:406 [inline]
 mlxsw_pci_cmd_exec+0x177/0xa60 drivers/net/ethernet/mellanox/mlxsw/pci.c:1675
 mlxsw_cmd_exec+0x249/0x550 drivers/net/ethernet/mellanox/mlxsw/core.c:2335
 mlxsw_cmd_access_reg drivers/net/ethernet/mellanox/mlxsw/cmd.h:859 [inline]
 mlxsw_core_reg_access_cmd drivers/net/ethernet/mellanox/mlxsw/core.c:1938 [inline]
 mlxsw_core_reg_access+0x2f6/0x540 drivers/net/ethernet/mellanox/mlxsw/core.c:1985
 mlxsw_reg_query drivers/net/ethernet/mellanox/mlxsw/core.c:2000 [inline]
 mlxsw_devlink_info_get+0x17f/0x6e0 drivers/net/ethernet/mellanox/mlxsw/core.c:1090
 devlink_nl_info_fill.constprop.0+0x13c/0x2d0 net/core/devlink.c:4588
 devlink_nl_cmd_info_get_dumpit+0x246/0x460 net/core/devlink.c:4648
 genl_lock_dumpit+0x85/0xc0 net/netlink/genetlink.c:575
 netlink_dump+0x515/0xe50 net/netlink/af_netlink.c:2245
 __netlink_dump_start+0x53d/0x830 net/netlink/af_netlink.c:2353
 genl_family_rcv_msg_dumpit.isra.0+0x296/0x300 net/netlink/genetlink.c:638
 genl_family_rcv_msg net/netlink/genetlink.c:733 [inline]
 genl_rcv_msg+0x78d/0x9d0 net/netlink/genetlink.c:753
 netlink_rcv_skb+0x152/0x440 net/netlink/af_netlink.c:2469
 genl_rcv+0x24/0x40 net/netlink/genetlink.c:764
 netlink_unicast_kernel net/netlink/af_netlink.c:1303 [inline]
 netlink_unicast+0x53a/0x750 net/netlink/af_netlink.c:1329
 netlink_sendmsg+0x850/0xd90 net/netlink/af_netlink.c:1918
 sock_sendmsg_nosec net/socket.c:652 [inline]
 sock_sendmsg+0x150/0x190 net/socket.c:672
 ____sys_sendmsg+0x6d8/0x840 net/socket.c:2363
 ___sys_sendmsg+0xff/0x170 net/socket.c:2417
 __sys_sendmsg+0xe5/0x1b0 net/socket.c:2450
 do_syscall_64+0x56/0xa0 arch/x86/entry/common.c:359
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

Fixes: a9c8336 ("mlxsw: core: Add support for devlink info command")
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Reviewed-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
andikleen pushed a commit that referenced this issue Mar 28, 2021
The commit cited below removed the RCU read-side critical section from
rtnl_fdb_dump() which means that the ndo_fdb_dump() callback is invoked
without RCU protection.

This results in the following warning [1] in the VXLAN driver, which
relied on the callback being invoked from an RCU read-side critical
section.

Fix this by calling rcu_read_lock() in the VXLAN driver, as already done
in the bridge driver.

[1]
WARNING: suspicious RCU usage
5.8.0-rc4-custom-01521-g481007553ce6 #29 Not tainted
-----------------------------
drivers/net/vxlan.c:1379 RCU-list traversed in non-reader section!!

other info that might help us debug this:

rcu_scheduler_active = 2, debug_locks = 1
1 lock held by bridge/166:
 #0: ffffffff85a27850 (rtnl_mutex){+.+.}-{3:3}, at: netlink_dump+0xea/0x1090

stack backtrace:
CPU: 1 PID: 166 Comm: bridge Not tainted 5.8.0-rc4-custom-01521-g481007553ce6 #29
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-2.fc32 04/01/2014
Call Trace:
 dump_stack+0x100/0x184
 lockdep_rcu_suspicious+0x153/0x15d
 vxlan_fdb_dump+0x51e/0x6d0
 rtnl_fdb_dump+0x4dc/0xad0
 netlink_dump+0x540/0x1090
 __netlink_dump_start+0x695/0x950
 rtnetlink_rcv_msg+0x802/0xbd0
 netlink_rcv_skb+0x17a/0x480
 rtnetlink_rcv+0x22/0x30
 netlink_unicast+0x5ae/0x890
 netlink_sendmsg+0x98a/0xf40
 __sys_sendto+0x279/0x3b0
 __x64_sys_sendto+0xe6/0x1a0
 do_syscall_64+0x54/0xa0
 entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x7fe14fa2ade0
Code: Bad RIP value.
RSP: 002b:00007fff75bb5b88 EFLAGS: 00000246 ORIG_RAX: 000000000000002c
RAX: ffffffffffffffda RBX: 00005614b1ba0020 RCX: 00007fe14fa2ade0
RDX: 000000000000011c RSI: 00007fff75bb5b90 RDI: 0000000000000003
RBP: 00007fff75bb5b90 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00005614b1b89160
R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000

Fixes: 5e6d243 ("bridge: netlink dump interface at par with brctl")
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Reviewed-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants