From cd7074a7f949c9d94ab87e8cd1c8f391ebb7a235 Mon Sep 17 00:00:00 2001 From: Dariusz Sosnowski Date: Wed, 12 Aug 2020 00:38:53 +0000 Subject: [PATCH 1/6] Adds 'dummy' support for iolp() syscall --- src/syscalls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/syscalls.py b/src/syscalls.py index 7b008e0d57c..231b8ababc3 100644 --- a/src/syscalls.py +++ b/src/syscalls.py @@ -570,7 +570,7 @@ def __init__(self, **kwargs): lstat = EmulatedSyscall(x86=107, x64=6, arg2="struct Arch::stat") fstat = EmulatedSyscall(x86=108, x64=5, generic=80, arg2="struct Arch::stat") olduname = UnsupportedSyscall(x86=109) -iopl = UnsupportedSyscall(x86=110, x64=172) +iopl = EmulatedSyscall(x86=110, x64=172) vhangup = UnsupportedSyscall(x86=111, x64=153, generic=58) idle = UnsupportedSyscall(x86=112) vm86old = UnsupportedSyscall(x86=113) From 03956515d2b3f083158e825dec38757850e3a8dc Mon Sep 17 00:00:00 2001 From: Dariusz Sosnowski Date: Sun, 16 Aug 2020 20:52:45 +0200 Subject: [PATCH 2/6] record_syscall: Adds missing ioctls I would name this, __very Work in Progress__. This commit: - `0xc0181b01` is a RDMA_VERBS_IOCTL `ioctl` command used internally by libibverbs, which is used by mlx5 DPDK PMD. - `76` is an ETHTOOL subcommand used by mlx5 PMD. --- src/record_syscall.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/record_syscall.cc b/src/record_syscall.cc index 4872f1f69ea..1adb427a0d1 100644 --- a/src/record_syscall.cc +++ b/src/record_syscall.cc @@ -1570,6 +1570,9 @@ template void prepare_ethtool_ioctl(RecordTask* t, TaskSyscallSt case ETHTOOL_SPAUSEPARAM: case ETHTOOL_SFEATURES: break; + // Expected EINVAL for 'ioctl' but got result 0 (errno SUCCESS); unknown ETHTOOL command 76 + case 76: + break; default: LOG(debug) << "Unknown ETHTOOL cmd " << cmd; syscall_state.expect_errno = EINVAL; @@ -1746,6 +1749,9 @@ static Switchable prepare_ioctl(RecordTask* t, syscall_state.reg_parameter(3); return PREVENT_SWITCH; + case 0xc0181b01: + return PREVENT_SWITCH; + case SG_IO: auto argsp = syscall_state.reg_parameter(3, IN_OUT); auto args = t->read_mem(argsp); From f5250b7c5c5382a5d4da305ed476a680caff8913 Mon Sep 17 00:00:00 2001 From: Dariusz Sosnowski Date: Tue, 18 Aug 2020 02:04:47 +0200 Subject: [PATCH 3/6] record_syscall: Use RDMA_VERBS_IOCTL from kernel headers --- src/record_syscall.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/record_syscall.cc b/src/record_syscall.cc index 1adb427a0d1..9a51cfb8445 100644 --- a/src/record_syscall.cc +++ b/src/record_syscall.cc @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -1749,7 +1750,11 @@ static Switchable prepare_ioctl(RecordTask* t, syscall_state.reg_parameter(3); return PREVENT_SWITCH; - case 0xc0181b01: + /* RDMA_VERBS_IOCTL ioctl request used in libibverbs. + * net_mlx5 PMD is linked against libibverbs and these ioctls + * are called during probing. + */ + case RDMA_VERBS_IOCTL: return PREVENT_SWITCH; case SG_IO: From 040d59bb7d7206d96f9d4825534b9ef781f924ab Mon Sep 17 00:00:00 2001 From: Dariusz Sosnowski Date: Tue, 18 Aug 2020 02:15:58 +0200 Subject: [PATCH 4/6] record_syscall: Mark RDMA_VERBS_IOCTL arg as memory parameter --- src/kernel_abi.h | 49 +++++++++++++++++++++++++++++++++++++++++++ src/record_syscall.cc | 2 ++ 2 files changed, 51 insertions(+) diff --git a/src/kernel_abi.h b/src/kernel_abi.h index ce7704b228f..744623f9746 100644 --- a/src/kernel_abi.h +++ b/src/kernel_abi.h @@ -1666,6 +1666,55 @@ struct BaseArch : public wordsize, ptr r_map; // More fields we don't need (and are potentially libc specific) }; + + /* Based on: + * - https://github.com/linux-rdma/rdma-core/blob/e336086ec6649fbcace511b54419dcac0ae040b7/libibverbs/cmd_ioctl.h + * - https://github.com/torvalds/linux/blob/494c5580aa6721874a6d9d62dac1c94e83e79302/include/uapi/rdma/rdma_user_ioctl_cmds.h + * + * TODO: Is it possible to use `using` to expose kernel structs in this namespace? + */ + struct ib_uverbs_attr { + uint16_t attr_id; /* command specific type attribute */ + uint16_t len; /* only for pointers and IDRs array */ + uint16_t flags; /* combination of UVERBS_ATTR_F_XXXX */ + union { + struct { + uint8_t elem_id; + uint8_t reserved; + } enum_data; + uint16_t reserved; + } attr_data; + union { + /* + * ptr to command, inline data, idr/fd or + * ptr to __u32 array of IDRs + */ + uint64_t __attribute__((aligned(8))) data; + /* Used by FD_IN and FD_OUT */ + int64_t data_s64; + }; + }; + + /* Argument object passed to RDMA_VERBS_IOCTL ioctl request. + * NOTE: sizeof(T) will return an incorrect value because of VLA at the end + * of the struct. + * + * Based on: + * - https://github.com/linux-rdma/rdma-core/blob/e336086ec6649fbcace511b54419dcac0ae040b7/libibverbs/cmd_ioctl.h + * - https://github.com/torvalds/linux/blob/494c5580aa6721874a6d9d62dac1c94e83e79302/include/uapi/rdma/rdma_user_ioctl_cmds.h + * + * TODO: Is it possible to use `using` to expose kernel structs in this namespace? + */ + struct ib_uverbs_ioctl_hdr { + uint16_t length; + uint16_t object_id; + uint16_t method_id; + uint16_t num_attrs; + uint64_t __attribute__((aligned(8))) reserved1; + uint32_t driver_id; + uint32_t reserved2; + struct ib_uverbs_attr attrs[0]; + }; }; struct X64Arch : public BaseArch { diff --git a/src/record_syscall.cc b/src/record_syscall.cc index 9a51cfb8445..40ecf563bb1 100644 --- a/src/record_syscall.cc +++ b/src/record_syscall.cc @@ -1755,6 +1755,8 @@ static Switchable prepare_ioctl(RecordTask* t, * are called during probing. */ case RDMA_VERBS_IOCTL: + // TODO: ioctl argument size is dynamically calculated. How to do this in rr? + syscall_state.reg_parameter(3); return PREVENT_SWITCH; case SG_IO: From 6607bdfcef93367bc8a31bb8057dc94e50f23a65 Mon Sep 17 00:00:00 2001 From: Dariusz Sosnowski Date: Mon, 31 Aug 2020 23:47:30 +0200 Subject: [PATCH 5/6] record_syscall: Dummy handler for ETHTOOL_GSTATS For now just handle the ETHTOOL_GSTATS command. Does not do anything useful. --- src/record_syscall.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/record_syscall.cc b/src/record_syscall.cc index 40ecf563bb1..b7468957393 100644 --- a/src/record_syscall.cc +++ b/src/record_syscall.cc @@ -1573,6 +1573,11 @@ template void prepare_ethtool_ioctl(RecordTask* t, TaskSyscallSt break; // Expected EINVAL for 'ioctl' but got result 0 (errno SUCCESS); unknown ETHTOOL command 76 case 76: + // TODO(sodar): Handle it somehow? + break; + // Expected EINVAL for 'ioctl' but got result 0 (errno SUCCESS); unknown ETHTOOL command 29 + case ETHTOOL_GSTATS: + // TODO(sodar): Handle it somehow? break; default: LOG(debug) << "Unknown ETHTOOL cmd " << cmd; From 9a8118101291205e7af202a87aef95ba70a5286a Mon Sep 17 00:00:00 2001 From: Dariusz Sosnowski Date: Mon, 31 Aug 2020 23:52:57 +0200 Subject: [PATCH 6/6] record_syscall: References unknown ETHTOOL cmd by name --- src/record_syscall.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/record_syscall.cc b/src/record_syscall.cc index b7468957393..4e40a1d5f3e 100644 --- a/src/record_syscall.cc +++ b/src/record_syscall.cc @@ -1572,7 +1572,7 @@ template void prepare_ethtool_ioctl(RecordTask* t, TaskSyscallSt case ETHTOOL_SFEATURES: break; // Expected EINVAL for 'ioctl' but got result 0 (errno SUCCESS); unknown ETHTOOL command 76 - case 76: + case ETHTOOL_GLINKSETTINGS: // TODO(sodar): Handle it somehow? break; // Expected EINVAL for 'ioctl' but got result 0 (errno SUCCESS); unknown ETHTOOL command 29