Aaron Campbell
ab8ed95108
connector: fix out-of-order cn_proc netlink message delivery
...
The proc connector messages include a sequence number, allowing userspace
programs to detect lost messages. However, performing this detection is
currently more difficult than necessary, since netlink messages can be
delivered to the application out-of-order. To fix this, leave pre-emption
disabled during cn_netlink_send(), and use GFP_NOWAIT.
The following was written as a test case. Building the kernel w/ make -j32
proved a reliable way to generate out-of-order cn_proc messages.
int
main(int argc, char *argv[])
{
static uint32_t last_seq[CPU_SETSIZE], seq;
int cpu, fd;
struct sockaddr_nl sa;
struct __attribute__((aligned(NLMSG_ALIGNTO))) {
struct nlmsghdr nl_hdr;
struct __attribute__((__packed__)) {
struct cn_msg cn_msg;
struct proc_event cn_proc;
};
} rmsg;
struct __attribute__((aligned(NLMSG_ALIGNTO))) {
struct nlmsghdr nl_hdr;
struct __attribute__((__packed__)) {
struct cn_msg cn_msg;
enum proc_cn_mcast_op cn_mcast;
};
} smsg;
fd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR);
if (fd < 0) {
perror("socket");
}
sa.nl_family = AF_NETLINK;
sa.nl_groups = CN_IDX_PROC;
sa.nl_pid = getpid();
if (bind(fd, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
perror("bind");
}
memset(&smsg, 0, sizeof(smsg));
smsg.nl_hdr.nlmsg_len = sizeof(smsg);
smsg.nl_hdr.nlmsg_pid = getpid();
smsg.nl_hdr.nlmsg_type = NLMSG_DONE;
smsg.cn_msg.id.idx = CN_IDX_PROC;
smsg.cn_msg.id.val = CN_VAL_PROC;
smsg.cn_msg.len = sizeof(enum proc_cn_mcast_op);
smsg.cn_mcast = PROC_CN_MCAST_LISTEN;
if (send(fd, &smsg, sizeof(smsg), 0) != sizeof(smsg)) {
perror("send");
}
while (recv(fd, &rmsg, sizeof(rmsg), 0) == sizeof(rmsg)) {
cpu = rmsg.cn_proc.cpu;
if (cpu < 0) {
continue;
}
seq = rmsg.cn_msg.seq;
if ((last_seq[cpu] != 0) && (seq != last_seq[cpu] + 1)) {
printf("out-of-order seq=%d on cpu=%d\n", seq, cpu);
}
last_seq[cpu] = seq;
}
/* NOTREACHED */
perror("recv");
return -1;
}
Signed-off-by: Aaron Campbell <aaron@monkey.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-06-28 08:48:33 -04:00
..
2016-06-09 23:48:54 +02:00
2016-05-05 19:00:40 +01:00
2016-05-27 15:26:11 -07:00
2016-05-31 11:52:59 -07:00
2016-05-25 15:29:21 -07:00
2016-05-24 11:00:20 -07:00
2016-05-26 19:34:26 -07:00
2016-05-13 16:54:59 +02:00
2016-05-19 10:02:26 -07:00
2016-05-20 22:31:33 -07:00
2016-06-01 15:14:06 -07:00
2016-05-19 11:27:09 -07:00
2016-06-28 08:48:33 -04:00
2016-06-09 23:49:16 +02:00
2016-05-18 02:48:37 +02:00
2016-05-30 15:20:18 -07:00
2016-05-20 22:02:55 -07:00
2016-05-27 15:26:11 -07:00
2016-05-31 22:17:05 +05:30
2016-06-03 17:28:21 +02:00
2016-05-20 21:26:15 -07:00
2016-05-30 17:11:59 +02:00
2016-06-10 12:17:46 +10:00
2016-05-17 12:42:27 +02:00
2016-05-09 22:45:18 +02:00
2016-05-26 09:48:23 -07:00
2016-05-20 17:58:30 -07:00
2016-05-20 21:20:31 -07:00
2016-05-28 17:37:42 +02:00
2016-05-20 22:20:48 -07:00
2016-06-07 10:49:48 -04:00
2016-05-27 19:14:35 -07:00
2016-05-27 15:26:11 -07:00
2016-06-02 18:03:50 +01:00
2016-05-20 20:57:27 -07:00
2016-05-25 10:40:15 -07:00
2016-05-06 12:51:10 -06:00
2016-05-08 22:44:46 +05:30
2016-05-27 14:28:09 -07:00
2016-05-28 16:15:25 -07:00
2016-05-24 11:00:20 -07:00
2016-05-23 17:04:14 -07:00
2016-05-18 16:38:59 -07:00
2016-05-27 15:26:11 -07:00
2016-05-20 21:20:31 -07:00
2016-06-02 10:40:20 +02:00
2016-05-27 18:49:29 -07:00
2016-06-28 05:17:38 -04:00
2016-05-10 00:01:47 +02:00
2016-05-26 19:34:26 -07:00
2016-05-17 17:14:21 -06:00
2016-05-27 15:26:11 -07:00
2016-05-24 11:00:20 -07:00
2016-05-20 21:20:31 -07:00
2016-06-03 10:16:21 +01:00
2016-05-20 21:12:25 -07:00
2016-05-31 10:13:45 +02:00
2016-05-28 12:32:01 -07:00
2016-05-20 21:26:15 -07:00
2016-05-20 14:06:21 -07:00
2016-05-16 19:17:22 -07:00
2016-05-29 22:32:27 -07:00
2016-05-25 10:40:15 -07:00
2016-05-05 17:38:53 -07:00
2016-05-17 14:45:02 +02:00
2016-05-12 15:50:19 -07:00
2016-05-06 11:08:58 -07:00
2016-05-21 17:07:17 +02:00
2016-05-26 19:34:26 -07:00
2016-05-20 18:33:37 -07:00
2016-05-29 13:28:39 -07:00
2016-05-19 15:20:24 +02:00
2016-05-28 12:23:12 -07:00
2016-05-28 11:04:16 -07:00
2016-05-28 12:04:17 -07:00
2016-06-03 22:35:05 +02:00
2016-06-05 10:36:01 -07:00
2016-05-28 12:04:17 -07:00
2016-05-31 21:25:52 -06:00
2016-05-10 01:19:26 -07:00
2016-05-31 08:20:43 +03:00
2016-05-22 19:44:13 +03:00
2016-05-25 10:19:17 -07:00
2016-05-28 12:04:17 -07:00
2016-05-23 11:18:01 -07:00
2016-05-20 22:02:53 -07:00